Annotation of loncom/interface/loncommon.pm, revision 1.1232
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1232 ! raeburn 4: # $Id: loncommon.pm,v 1.1231 2016/01/22 22:42:47 damieng Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1108 raeburn 70: use Apache::lonuserutils();
1.1110 raeburn 71: use Apache::lonuserstate();
1.1182 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 74: use DateTime::TimeZone;
1.687 raeburn 75: use DateTime::Locale::Catalog;
1.1220 raeburn 76: use Encode();
1.1091 foxr 77: use Text::Aspell;
1.1094 raeburn 78: use Authen::Captcha;
79: use Captcha::reCAPTCHA;
1.1174 raeburn 80: use Crypt::DES;
81: use DynaLoader; # for Crypt::DES version
1.1223 musolffc 82: use MIME::Lite;
83: use MIME::Types;
1.117 www 84:
1.517 raeburn 85: # ---------------------------------------------- Designs
86: use vars qw(%defaultdesign);
87:
1.22 www 88: my $readit;
89:
1.517 raeburn 90:
1.157 matthew 91: ##
92: ## Global Variables
93: ##
1.46 matthew 94:
1.643 foxr 95:
96: # ----------------------------------------------- SSI with retries:
97: #
98:
99: =pod
100:
1.648 raeburn 101: =head1 Server Side include with retries:
1.643 foxr 102:
103: =over 4
104:
1.648 raeburn 105: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 106:
107: Performs an ssi with some number of retries. Retries continue either
108: until the result is ok or until the retry count supplied by the
109: caller is exhausted.
110:
111: Inputs:
1.648 raeburn 112:
113: =over 4
114:
1.643 foxr 115: resource - Identifies the resource to insert.
1.648 raeburn 116:
1.643 foxr 117: retries - Count of the number of retries allowed.
1.648 raeburn 118:
1.643 foxr 119: form - Hash that identifies the rendering options.
120:
1.648 raeburn 121: =back
122:
123: Returns:
124:
125: =over 4
126:
1.643 foxr 127: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 128:
1.643 foxr 129: response - The response from the last attempt (which may or may not have been successful.
130:
1.648 raeburn 131: =back
132:
133: =back
134:
1.643 foxr 135: =cut
136:
137: sub ssi_with_retries {
138: my ($resource, $retries, %form) = @_;
139:
140:
141: my $ok = 0; # True if we got a good response.
142: my $content;
143: my $response;
144:
145: # Try to get the ssi done. within the retries count:
146:
147: do {
148: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
149: $ok = $response->is_success;
1.650 www 150: if (!$ok) {
151: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
152: }
1.643 foxr 153: $retries--;
154: } while (!$ok && ($retries > 0));
155:
156: if (!$ok) {
157: $content = ''; # On error return an empty content.
158: }
159: return ($content, $response);
160:
161: }
162:
163:
164:
1.20 www 165: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 166: my %language;
1.124 www 167: my %supported_language;
1.1088 foxr 168: my %supported_codes;
1.1048 foxr 169: my %latex_language; # For choosing hyphenation in <transl..>
170: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 171: my %cprtag;
1.192 taceyjo1 172: my %scprtag;
1.351 www 173: my %fe; my %fd; my %fm;
1.41 ng 174: my %category_extensions;
1.12 harris41 175:
1.46 matthew 176: # ---------------------------------------------- Thesaurus variables
1.144 matthew 177: #
178: # %Keywords:
179: # A hash used by &keyword to determine if a word is considered a keyword.
180: # $thesaurus_db_file
181: # Scalar containing the full path to the thesaurus database.
1.46 matthew 182:
183: my %Keywords;
184: my $thesaurus_db_file;
185:
1.144 matthew 186: #
187: # Initialize values from language.tab, copyright.tab, filetypes.tab,
188: # thesaurus.tab, and filecategories.tab.
189: #
1.18 www 190: BEGIN {
1.46 matthew 191: # Variable initialization
192: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
193: #
1.22 www 194: unless ($readit) {
1.12 harris41 195: # ------------------------------------------------------------------- languages
196: {
1.158 raeburn 197: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
198: '/language.tab';
199: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 200: while (my $line = <$fh>) {
201: next if ($line=~/^\#/);
202: chomp($line);
1.1088 foxr 203: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 204: $language{$key}=$val.' - '.$enc;
205: if ($sup) {
206: $supported_language{$key}=$sup;
1.1088 foxr 207: $supported_codes{$key} = $code;
1.158 raeburn 208: }
1.1048 foxr 209: if ($latex) {
210: $latex_language_bykey{$key} = $latex;
1.1088 foxr 211: $latex_language{$code} = $latex;
1.1048 foxr 212: }
1.158 raeburn 213: }
214: close($fh);
215: }
1.12 harris41 216: }
217: # ------------------------------------------------------------------ copyrights
218: {
1.158 raeburn 219: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
220: '/copyright.tab';
221: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 222: while (my $line = <$fh>) {
223: next if ($line=~/^\#/);
224: chomp($line);
225: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 226: $cprtag{$key}=$val;
227: }
228: close($fh);
229: }
1.12 harris41 230: }
1.351 www 231: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 232: {
233: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
234: '/source_copyright.tab';
235: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 236: while (my $line = <$fh>) {
237: next if ($line =~ /^\#/);
238: chomp($line);
239: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 240: $scprtag{$key}=$val;
241: }
242: close($fh);
243: }
244: }
1.63 www 245:
1.517 raeburn 246: # -------------------------------------------------------------- default domain designs
1.63 www 247: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 248: my $designfile = $designdir.'/default.tab';
249: if ( open (my $fh,"<$designfile") ) {
250: while (my $line = <$fh>) {
251: next if ($line =~ /^\#/);
252: chomp($line);
253: my ($key,$val)=(split(/\=/,$line));
254: if ($val) { $defaultdesign{$key}=$val; }
255: }
256: close($fh);
1.63 www 257: }
258:
1.15 harris41 259: # ------------------------------------------------------------- file categories
260: {
1.158 raeburn 261: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
262: '/filecategories.tab';
263: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 264: while (my $line = <$fh>) {
265: next if ($line =~ /^\#/);
266: chomp($line);
267: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 268: push @{$category_extensions{lc($category)}},$extension;
269: }
270: close($fh);
271: }
272:
1.15 harris41 273: }
1.12 harris41 274: # ------------------------------------------------------------------ file types
275: {
1.158 raeburn 276: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
277: '/filetypes.tab';
278: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 279: while (my $line = <$fh>) {
280: next if ($line =~ /^\#/);
281: chomp($line);
282: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 283: if ($descr ne '') {
284: $fe{$ending}=lc($emb);
285: $fd{$ending}=$descr;
1.351 www 286: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 287: }
288: }
289: close($fh);
290: }
1.12 harris41 291: }
1.22 www 292: &Apache::lonnet::logthis(
1.705 tempelho 293: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 294: $readit=1;
1.46 matthew 295: } # end of unless($readit)
1.32 matthew 296:
297: }
1.112 bowersj2 298:
1.42 matthew 299: ###############################################################
300: ## HTML and Javascript Helper Functions ##
301: ###############################################################
302:
303: =pod
304:
1.112 bowersj2 305: =head1 HTML and Javascript Functions
1.42 matthew 306:
1.112 bowersj2 307: =over 4
308:
1.648 raeburn 309: =item * &browser_and_searcher_javascript()
1.112 bowersj2 310:
311: X<browsing, javascript>X<searching, javascript>Returns a string
312: containing javascript with two functions, C<openbrowser> and
313: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
314: tags.
1.42 matthew 315:
1.648 raeburn 316: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 317:
318: inputs: formname, elementname, only, omit
319:
320: formname and elementname indicate the name of the html form and name of
321: the element that the results of the browsing selection are to be placed in.
322:
323: Specifying 'only' will restrict the browser to displaying only files
1.185 www 324: with the given extension. Can be a comma separated list.
1.42 matthew 325:
326: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 327: with the given extension. Can be a comma separated list.
1.42 matthew 328:
1.648 raeburn 329: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 330:
331: Inputs: formname, elementname
332:
333: formname and elementname specify the name of the html form and the name
334: of the element the selection from the search results will be placed in.
1.542 raeburn 335:
1.42 matthew 336: =cut
337:
338: sub browser_and_searcher_javascript {
1.199 albertel 339: my ($mode)=@_;
340: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 341: my $resurl=&escape_single(&lastresurl());
1.42 matthew 342: return <<END;
1.219 albertel 343: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 344: var editbrowser = null;
1.135 albertel 345: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 346: var url = '$resurl/?';
1.42 matthew 347: if (editbrowser == null) {
348: url += 'launch=1&';
349: }
350: url += 'catalogmode=interactive&';
1.199 albertel 351: url += 'mode=$mode&';
1.611 albertel 352: url += 'inhibitmenu=yes&';
1.42 matthew 353: url += 'form=' + formname + '&';
354: if (only != null) {
355: url += 'only=' + only + '&';
1.217 albertel 356: } else {
357: url += 'only=&';
358: }
1.42 matthew 359: if (omit != null) {
360: url += 'omit=' + omit + '&';
1.217 albertel 361: } else {
362: url += 'omit=&';
363: }
1.135 albertel 364: if (titleelement != null) {
365: url += 'titleelement=' + titleelement + '&';
1.217 albertel 366: } else {
367: url += 'titleelement=&';
368: }
1.42 matthew 369: url += 'element=' + elementname + '';
370: var title = 'Browser';
1.435 albertel 371: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 372: options += ',width=700,height=600';
373: editbrowser = open(url,title,options,'1');
374: editbrowser.focus();
375: }
376: var editsearcher;
1.135 albertel 377: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 378: var url = '/adm/searchcat?';
379: if (editsearcher == null) {
380: url += 'launch=1&';
381: }
382: url += 'catalogmode=interactive&';
1.199 albertel 383: url += 'mode=$mode&';
1.42 matthew 384: url += 'form=' + formname + '&';
1.135 albertel 385: if (titleelement != null) {
386: url += 'titleelement=' + titleelement + '&';
1.217 albertel 387: } else {
388: url += 'titleelement=&';
389: }
1.42 matthew 390: url += 'element=' + elementname + '';
391: var title = 'Search';
1.435 albertel 392: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 393: options += ',width=700,height=600';
394: editsearcher = open(url,title,options,'1');
395: editsearcher.focus();
396: }
1.219 albertel 397: // END LON-CAPA Internal -->
1.42 matthew 398: END
1.170 www 399: }
400:
401: sub lastresurl {
1.258 albertel 402: if ($env{'environment.lastresurl'}) {
403: return $env{'environment.lastresurl'}
1.170 www 404: } else {
405: return '/res';
406: }
407: }
408:
409: sub storeresurl {
410: my $resurl=&Apache::lonnet::clutter(shift);
411: unless ($resurl=~/^\/res/) { return 0; }
412: $resurl=~s/\/$//;
413: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 414: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 415: return 1;
1.42 matthew 416: }
417:
1.74 www 418: sub studentbrowser_javascript {
1.111 www 419: unless (
1.258 albertel 420: (($env{'request.course.id'}) &&
1.302 albertel 421: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
422: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
423: '/'.$env{'request.course.sec'})
424: ))
1.258 albertel 425: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 426: ) { return ''; }
1.74 www 427: return (<<'ENDSTDBRW');
1.776 bisitz 428: <script type="text/javascript" language="Javascript">
1.824 bisitz 429: // <![CDATA[
1.74 www 430: var stdeditbrowser;
1.999 www 431: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 432: var url = '/adm/pickstudent?';
433: var filter;
1.558 albertel 434: if (!ignorefilter) {
435: eval('filter=document.'+formname+'.'+uname+'.value;');
436: }
1.74 www 437: if (filter != null) {
438: if (filter != '') {
439: url += 'filter='+filter+'&';
440: }
441: }
442: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 443: '&udomelement='+udom+
444: '&clicker='+clicker;
1.111 www 445: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 446: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 447: var title = 'Student_Browser';
1.74 www 448: var options = 'scrollbars=1,resizable=1,menubar=0';
449: options += ',width=700,height=600';
450: stdeditbrowser = open(url,title,options,'1');
451: stdeditbrowser.focus();
452: }
1.824 bisitz 453: // ]]>
1.74 www 454: </script>
455: ENDSTDBRW
456: }
1.42 matthew 457:
1.1003 www 458: sub resourcebrowser_javascript {
459: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 460: return (<<'ENDRESBRW');
1.1003 www 461: <script type="text/javascript" language="Javascript">
462: // <![CDATA[
463: var reseditbrowser;
1.1004 www 464: function openresbrowser(formname,reslink) {
1.1005 www 465: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 466: var title = 'Resource_Browser';
467: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 468: options += ',width=700,height=500';
1.1004 www 469: reseditbrowser = open(url,title,options,'1');
470: reseditbrowser.focus();
1.1003 www 471: }
472: // ]]>
473: </script>
1.1004 www 474: ENDRESBRW
1.1003 www 475: }
476:
1.74 www 477: sub selectstudent_link {
1.999 www 478: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
479: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
480: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
481: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 482: if ($env{'request.course.id'}) {
1.302 albertel 483: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
484: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
485: '/'.$env{'request.course.sec'})) {
1.111 www 486: return '';
487: }
1.999 www 488: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 489: if ($courseadvonly) {
490: $callargs .= ",'',1,1";
491: }
492: return '<span class="LC_nobreak">'.
493: '<a href="javascript:openstdbrowser('.$callargs.');">'.
494: &mt('Select User').'</a></span>';
1.74 www 495: }
1.258 albertel 496: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 497: $callargs .= ",'',1";
1.793 raeburn 498: return '<span class="LC_nobreak">'.
499: '<a href="javascript:openstdbrowser('.$callargs.');">'.
500: &mt('Select User').'</a></span>';
1.111 www 501: }
502: return '';
1.91 www 503: }
504:
1.1004 www 505: sub selectresource_link {
506: my ($form,$reslink,$arg)=@_;
507:
508: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
509: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
510: unless ($env{'request.course.id'}) { return $arg; }
511: return '<span class="LC_nobreak">'.
512: '<a href="javascript:openresbrowser('.$callargs.');">'.
513: $arg.'</a></span>';
514: }
515:
516:
517:
1.653 raeburn 518: sub authorbrowser_javascript {
519: return <<"ENDAUTHORBRW";
1.776 bisitz 520: <script type="text/javascript" language="JavaScript">
1.824 bisitz 521: // <![CDATA[
1.653 raeburn 522: var stdeditbrowser;
523:
524: function openauthorbrowser(formname,udom) {
525: var url = '/adm/pickauthor?';
526: url += 'form='+formname+'&roledom='+udom;
527: var title = 'Author_Browser';
528: var options = 'scrollbars=1,resizable=1,menubar=0';
529: options += ',width=700,height=600';
530: stdeditbrowser = open(url,title,options,'1');
531: stdeditbrowser.focus();
532: }
533:
1.824 bisitz 534: // ]]>
1.653 raeburn 535: </script>
536: ENDAUTHORBRW
537: }
538:
1.91 www 539: sub coursebrowser_javascript {
1.1116 raeburn 540: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1221 raeburn 541: $credits_element,$instcode) = @_;
1.932 raeburn 542: my $wintitle = 'Course_Browser';
1.931 raeburn 543: if ($crstype eq 'Community') {
1.932 raeburn 544: $wintitle = 'Community_Browser';
1.909 raeburn 545: }
1.876 raeburn 546: my $id_functions = &javascript_index_functions();
547: my $output = '
1.776 bisitz 548: <script type="text/javascript" language="JavaScript">
1.824 bisitz 549: // <![CDATA[
1.468 raeburn 550: var stdeditbrowser;'."\n";
1.876 raeburn 551:
552: $output .= <<"ENDSTDBRW";
1.909 raeburn 553: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 554: var url = '/adm/pickcourse?';
1.895 raeburn 555: var formid = getFormIdByName(formname);
1.876 raeburn 556: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 557: if (domainfilter != null) {
558: if (domainfilter != '') {
559: url += 'domainfilter='+domainfilter+'&';
560: }
561: }
1.91 www 562: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 563: '&cdomelement='+udom+
564: '&cnameelement='+desc;
1.468 raeburn 565: if (extra_element !=null && extra_element != '') {
1.594 raeburn 566: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 567: url += '&roleelement='+extra_element;
568: if (domainfilter == null || domainfilter == '') {
569: url += '&domainfilter='+extra_element;
570: }
1.234 raeburn 571: }
1.468 raeburn 572: else {
573: if (formname == 'portform') {
574: url += '&setroles='+extra_element;
1.800 raeburn 575: } else {
576: if (formname == 'rules') {
577: url += '&fixeddom='+extra_element;
578: }
1.468 raeburn 579: }
580: }
1.230 raeburn 581: }
1.909 raeburn 582: if (type != null && type != '') {
583: url += '&type='+type;
584: }
585: if (type_elem != null && type_elem != '') {
586: url += '&typeelement='+type_elem;
587: }
1.872 raeburn 588: if (formname == 'ccrs') {
589: var ownername = document.forms[formid].ccuname.value;
590: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1221 raeburn 591: url += '&cloner='+ownername+':'+ownerdom+'&crscode='+document.forms[formid].crscode.value;
592: }
593: if (formname == 'requestcrs') {
594: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 595: }
1.293 raeburn 596: if (multflag !=null && multflag != '') {
597: url += '&multiple='+multflag;
598: }
1.909 raeburn 599: var title = '$wintitle';
1.91 www 600: var options = 'scrollbars=1,resizable=1,menubar=0';
601: options += ',width=700,height=600';
602: stdeditbrowser = open(url,title,options,'1');
603: stdeditbrowser.focus();
604: }
1.876 raeburn 605: $id_functions
606: ENDSTDBRW
1.1116 raeburn 607: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
608: $output .= &setsec_javascript($sec_element,$formname,$role_element,
609: $credits_element);
1.876 raeburn 610: }
611: $output .= '
612: // ]]>
613: </script>';
614: return $output;
615: }
616:
617: sub javascript_index_functions {
618: return <<"ENDJS";
619:
620: function getFormIdByName(formname) {
621: for (var i=0;i<document.forms.length;i++) {
622: if (document.forms[i].name == formname) {
623: return i;
624: }
625: }
626: return -1;
627: }
628:
629: function getIndexByName(formid,item) {
630: for (var i=0;i<document.forms[formid].elements.length;i++) {
631: if (document.forms[formid].elements[i].name == item) {
632: return i;
633: }
634: }
635: return -1;
636: }
1.468 raeburn 637:
1.876 raeburn 638: function getDomainFromSelectbox(formname,udom) {
639: var userdom;
640: var formid = getFormIdByName(formname);
641: if (formid > -1) {
642: var domid = getIndexByName(formid,udom);
643: if (domid > -1) {
644: if (document.forms[formid].elements[domid].type == 'select-one') {
645: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
646: }
647: if (document.forms[formid].elements[domid].type == 'hidden') {
648: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 649: }
650: }
651: }
1.876 raeburn 652: return userdom;
653: }
654:
655: ENDJS
1.468 raeburn 656:
1.876 raeburn 657: }
658:
1.1017 raeburn 659: sub javascript_array_indexof {
1.1018 raeburn 660: return <<ENDJS;
1.1017 raeburn 661: <script type="text/javascript" language="JavaScript">
662: // <![CDATA[
663:
664: if (!Array.prototype.indexOf) {
665: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
666: "use strict";
667: if (this === void 0 || this === null) {
668: throw new TypeError();
669: }
670: var t = Object(this);
671: var len = t.length >>> 0;
672: if (len === 0) {
673: return -1;
674: }
675: var n = 0;
676: if (arguments.length > 0) {
677: n = Number(arguments[1]);
1.1088 foxr 678: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 679: n = 0;
680: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
681: n = (n > 0 || -1) * Math.floor(Math.abs(n));
682: }
683: }
684: if (n >= len) {
685: return -1;
686: }
687: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
688: for (; k < len; k++) {
689: if (k in t && t[k] === searchElement) {
690: return k;
691: }
692: }
693: return -1;
694: }
695: }
696:
697: // ]]>
698: </script>
699:
700: ENDJS
701:
702: }
703:
1.876 raeburn 704: sub userbrowser_javascript {
705: my $id_functions = &javascript_index_functions();
706: return <<"ENDUSERBRW";
707:
1.888 raeburn 708: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 709: var url = '/adm/pickuser?';
710: var userdom = getDomainFromSelectbox(formname,udom);
711: if (userdom != null) {
712: if (userdom != '') {
713: url += 'srchdom='+userdom+'&';
714: }
715: }
716: url += 'form=' + formname + '&unameelement='+uname+
717: '&udomelement='+udom+
718: '&ulastelement='+ulast+
719: '&ufirstelement='+ufirst+
720: '&uemailelement='+uemail+
1.881 raeburn 721: '&hideudomelement='+hideudom+
722: '&coursedom='+crsdom;
1.888 raeburn 723: if ((caller != null) && (caller != undefined)) {
724: url += '&caller='+caller;
725: }
1.876 raeburn 726: var title = 'User_Browser';
727: var options = 'scrollbars=1,resizable=1,menubar=0';
728: options += ',width=700,height=600';
729: var stdeditbrowser = open(url,title,options,'1');
730: stdeditbrowser.focus();
731: }
732:
1.888 raeburn 733: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 734: var formid = getFormIdByName(formname);
735: if (formid > -1) {
1.888 raeburn 736: var unameid = getIndexByName(formid,uname);
1.876 raeburn 737: var domid = getIndexByName(formid,udom);
738: var hidedomid = getIndexByName(formid,origdom);
739: if (hidedomid > -1) {
740: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 741: var unameval = document.forms[formid].elements[unameid].value;
742: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
743: if (domid > -1) {
744: var slct = document.forms[formid].elements[domid];
745: if (slct.type == 'select-one') {
746: var i;
747: for (i=0;i<slct.length;i++) {
748: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
749: }
750: }
751: if (slct.type == 'hidden') {
752: slct.value = fixeddom;
1.876 raeburn 753: }
754: }
1.468 raeburn 755: }
756: }
757: }
1.876 raeburn 758: return;
759: }
760:
761: $id_functions
762: ENDUSERBRW
1.468 raeburn 763: }
764:
765: sub setsec_javascript {
1.1116 raeburn 766: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 767: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
768: $communityrolestr);
769: if ($role_element ne '') {
770: my @allroles = ('st','ta','ep','in','ad');
771: foreach my $crstype ('Course','Community') {
772: if ($crstype eq 'Community') {
773: foreach my $role (@allroles) {
774: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
775: }
776: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
777: } else {
778: foreach my $role (@allroles) {
779: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
780: }
781: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
782: }
783: }
784: $rolestr = '"'.join('","',@allroles).'"';
785: $courserolestr = '"'.join('","',@courserolenames).'"';
786: $communityrolestr = '"'.join('","',@communityrolenames).'"';
787: }
1.468 raeburn 788: my $setsections = qq|
789: function setSect(sectionlist) {
1.629 raeburn 790: var sectionsArray = new Array();
791: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
792: sectionsArray = sectionlist.split(",");
793: }
1.468 raeburn 794: var numSections = sectionsArray.length;
795: document.$formname.$sec_element.length = 0;
796: if (numSections == 0) {
797: document.$formname.$sec_element.multiple=false;
798: document.$formname.$sec_element.size=1;
799: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
800: } else {
801: if (numSections == 1) {
802: document.$formname.$sec_element.multiple=false;
803: document.$formname.$sec_element.size=1;
804: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
805: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
806: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
807: } else {
808: for (var i=0; i<numSections; i++) {
809: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
810: }
811: document.$formname.$sec_element.multiple=true
812: if (numSections < 3) {
813: document.$formname.$sec_element.size=numSections;
814: } else {
815: document.$formname.$sec_element.size=3;
816: }
817: document.$formname.$sec_element.options[0].selected = false
818: }
819: }
1.91 www 820: }
1.905 raeburn 821:
822: function setRole(crstype) {
1.468 raeburn 823: |;
1.905 raeburn 824: if ($role_element eq '') {
825: $setsections .= ' return;
826: }
827: ';
828: } else {
829: $setsections .= qq|
830: var elementLength = document.$formname.$role_element.length;
831: var allroles = Array($rolestr);
832: var courserolenames = Array($courserolestr);
833: var communityrolenames = Array($communityrolestr);
834: if (elementLength != undefined) {
835: if (document.$formname.$role_element.options[5].value == 'cc') {
836: if (crstype == 'Course') {
837: return;
838: } else {
839: allroles[5] = 'co';
840: for (var i=0; i<6; i++) {
841: document.$formname.$role_element.options[i].value = allroles[i];
842: document.$formname.$role_element.options[i].text = communityrolenames[i];
843: }
844: }
845: } else {
846: if (crstype == 'Community') {
847: return;
848: } else {
849: allroles[5] = 'cc';
850: for (var i=0; i<6; i++) {
851: document.$formname.$role_element.options[i].value = allroles[i];
852: document.$formname.$role_element.options[i].text = courserolenames[i];
853: }
854: }
855: }
856: }
857: return;
858: }
859: |;
860: }
1.1116 raeburn 861: if ($credits_element) {
862: $setsections .= qq|
863: function setCredits(defaultcredits) {
864: document.$formname.$credits_element.value = defaultcredits;
865: return;
866: }
867: |;
868: }
1.468 raeburn 869: return $setsections;
870: }
871:
1.91 www 872: sub selectcourse_link {
1.909 raeburn 873: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
874: $typeelement) = @_;
875: my $type = $selecttype;
1.871 raeburn 876: my $linktext = &mt('Select Course');
877: if ($selecttype eq 'Community') {
1.909 raeburn 878: $linktext = &mt('Select Community');
1.906 raeburn 879: } elsif ($selecttype eq 'Course/Community') {
880: $linktext = &mt('Select Course/Community');
1.909 raeburn 881: $type = '';
1.1019 raeburn 882: } elsif ($selecttype eq 'Select') {
883: $linktext = &mt('Select');
884: $type = '';
1.871 raeburn 885: }
1.787 bisitz 886: return '<span class="LC_nobreak">'
887: ."<a href='"
888: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
889: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 890: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 891: ."'>".$linktext.'</a>'
1.787 bisitz 892: .'</span>';
1.74 www 893: }
1.42 matthew 894:
1.653 raeburn 895: sub selectauthor_link {
896: my ($form,$udom)=@_;
897: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
898: &mt('Select Author').'</a>';
899: }
900:
1.876 raeburn 901: sub selectuser_link {
1.881 raeburn 902: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 903: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 904: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 905: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 906: ');">'.$linktext.'</a>';
1.876 raeburn 907: }
908:
1.273 raeburn 909: sub check_uncheck_jscript {
910: my $jscript = <<"ENDSCRT";
911: function checkAll(field) {
912: if (field.length > 0) {
913: for (i = 0; i < field.length; i++) {
1.1093 raeburn 914: if (!field[i].disabled) {
915: field[i].checked = true;
916: }
1.273 raeburn 917: }
918: } else {
1.1093 raeburn 919: if (!field.disabled) {
920: field.checked = true;
921: }
1.273 raeburn 922: }
923: }
924:
925: function uncheckAll(field) {
926: if (field.length > 0) {
927: for (i = 0; i < field.length; i++) {
928: field[i].checked = false ;
1.543 albertel 929: }
930: } else {
1.273 raeburn 931: field.checked = false ;
932: }
933: }
934: ENDSCRT
935: return $jscript;
936: }
937:
1.656 www 938: sub select_timezone {
1.659 raeburn 939: my ($name,$selected,$onchange,$includeempty)=@_;
940: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
941: if ($includeempty) {
942: $output .= '<option value=""';
943: if (($selected eq '') || ($selected eq 'local')) {
944: $output .= ' selected="selected" ';
945: }
946: $output .= '> </option>';
947: }
1.657 raeburn 948: my @timezones = DateTime::TimeZone->all_names;
949: foreach my $tzone (@timezones) {
950: $output.= '<option value="'.$tzone.'"';
951: if ($tzone eq $selected) {
952: $output.=' selected="selected"';
953: }
954: $output.=">$tzone</option>\n";
1.656 www 955: }
956: $output.="</select>";
957: return $output;
958: }
1.273 raeburn 959:
1.687 raeburn 960: sub select_datelocale {
961: my ($name,$selected,$onchange,$includeempty)=@_;
962: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
963: if ($includeempty) {
964: $output .= '<option value=""';
965: if ($selected eq '') {
966: $output .= ' selected="selected" ';
967: }
968: $output .= '> </option>';
969: }
970: my (@possibles,%locale_names);
971: my @locales = DateTime::Locale::Catalog::Locales;
972: foreach my $locale (@locales) {
973: if (ref($locale) eq 'HASH') {
974: my $id = $locale->{'id'};
975: if ($id ne '') {
976: my $en_terr = $locale->{'en_territory'};
977: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 978: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 979: if (grep(/^en$/,@languages) || !@languages) {
980: if ($en_terr ne '') {
981: $locale_names{$id} = '('.$en_terr.')';
982: } elsif ($native_terr ne '') {
983: $locale_names{$id} = $native_terr;
984: }
985: } else {
986: if ($native_terr ne '') {
987: $locale_names{$id} = $native_terr.' ';
988: } elsif ($en_terr ne '') {
989: $locale_names{$id} = '('.$en_terr.')';
990: }
991: }
1.1220 raeburn 992: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.687 raeburn 993: push (@possibles,$id);
994: }
995: }
996: }
997: foreach my $item (sort(@possibles)) {
998: $output.= '<option value="'.$item.'"';
999: if ($item eq $selected) {
1000: $output.=' selected="selected"';
1001: }
1002: $output.=">$item";
1003: if ($locale_names{$item} ne '') {
1.1220 raeburn 1004: $output.=' '.$locale_names{$item};
1.687 raeburn 1005: }
1006: $output.="</option>\n";
1007: }
1008: $output.="</select>";
1009: return $output;
1010: }
1011:
1.792 raeburn 1012: sub select_language {
1013: my ($name,$selected,$includeempty) = @_;
1014: my %langchoices;
1015: if ($includeempty) {
1.1117 raeburn 1016: %langchoices = ('' => 'No language preference');
1.792 raeburn 1017: }
1018: foreach my $id (&languageids()) {
1019: my $code = &supportedlanguagecode($id);
1020: if ($code) {
1021: $langchoices{$code} = &plainlanguagedescription($id);
1022: }
1023: }
1.1117 raeburn 1024: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.970 raeburn 1025: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 1026: }
1027:
1.42 matthew 1028: =pod
1.36 matthew 1029:
1.1088 foxr 1030:
1031: =item * &list_languages()
1032:
1033: Returns an array reference that is suitable for use in language prompters.
1034: Each array element is itself a two element array. The first element
1035: is the language code. The second element a descsriptiuon of the
1036: language itself. This is suitable for use in e.g.
1037: &Apache::edit::select_arg (once dereferenced that is).
1038:
1039: =cut
1040:
1041: sub list_languages {
1042: my @lang_choices;
1043:
1044: foreach my $id (&languageids()) {
1045: my $code = &supportedlanguagecode($id);
1046: if ($code) {
1047: my $selector = $supported_codes{$id};
1048: my $description = &plainlanguagedescription($id);
1049: push (@lang_choices, [$selector, $description]);
1050: }
1051: }
1052: return \@lang_choices;
1053: }
1054:
1055: =pod
1056:
1.648 raeburn 1057: =item * &linked_select_forms(...)
1.36 matthew 1058:
1059: linked_select_forms returns a string containing a <script></script> block
1060: and html for two <select> menus. The select menus will be linked in that
1061: changing the value of the first menu will result in new values being placed
1062: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1063: order unless a defined order is provided.
1.36 matthew 1064:
1065: linked_select_forms takes the following ordered inputs:
1066:
1067: =over 4
1068:
1.112 bowersj2 1069: =item * $formname, the name of the <form> tag
1.36 matthew 1070:
1.112 bowersj2 1071: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1072:
1.112 bowersj2 1073: =item * $firstdefault, the default value for the first menu
1.36 matthew 1074:
1.112 bowersj2 1075: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1076:
1.112 bowersj2 1077: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1078:
1.112 bowersj2 1079: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1080:
1.609 raeburn 1081: =item * $menuorder, the order of values in the first menu
1082:
1.1115 raeburn 1083: =item * $onchangefirst, additional javascript call to execute for an onchange
1084: event for the first <select> tag
1085:
1086: =item * $onchangesecond, additional javascript call to execute for an onchange
1087: event for the second <select> tag
1088:
1.41 ng 1089: =back
1090:
1.36 matthew 1091: Below is an example of such a hash. Only the 'text', 'default', and
1092: 'select2' keys must appear as stated. keys(%menu) are the possible
1093: values for the first select menu. The text that coincides with the
1.41 ng 1094: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1095: and text for the second menu are given in the hash pointed to by
1096: $menu{$choice1}->{'select2'}.
1097:
1.112 bowersj2 1098: my %menu = ( A1 => { text =>"Choice A1" ,
1099: default => "B3",
1100: select2 => {
1101: B1 => "Choice B1",
1102: B2 => "Choice B2",
1103: B3 => "Choice B3",
1104: B4 => "Choice B4"
1.609 raeburn 1105: },
1106: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1107: },
1108: A2 => { text =>"Choice A2" ,
1109: default => "C2",
1110: select2 => {
1111: C1 => "Choice C1",
1112: C2 => "Choice C2",
1113: C3 => "Choice C3"
1.609 raeburn 1114: },
1115: order => ['C2','C1','C3'],
1.112 bowersj2 1116: },
1117: A3 => { text =>"Choice A3" ,
1118: default => "D6",
1119: select2 => {
1120: D1 => "Choice D1",
1121: D2 => "Choice D2",
1122: D3 => "Choice D3",
1123: D4 => "Choice D4",
1124: D5 => "Choice D5",
1125: D6 => "Choice D6",
1126: D7 => "Choice D7"
1.609 raeburn 1127: },
1128: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1129: }
1130: );
1.36 matthew 1131:
1132: =cut
1133:
1134: sub linked_select_forms {
1135: my ($formname,
1136: $middletext,
1137: $firstdefault,
1138: $firstselectname,
1139: $secondselectname,
1.609 raeburn 1140: $hashref,
1141: $menuorder,
1.1115 raeburn 1142: $onchangefirst,
1143: $onchangesecond
1.36 matthew 1144: ) = @_;
1145: my $second = "document.$formname.$secondselectname";
1146: my $first = "document.$formname.$firstselectname";
1147: # output the javascript to do the changing
1148: my $result = '';
1.776 bisitz 1149: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1150: $result.="// <![CDATA[\n";
1.36 matthew 1151: $result.="var select2data = new Object();\n";
1152: $" = '","';
1153: my $debug = '';
1154: foreach my $s1 (sort(keys(%$hashref))) {
1155: $result.="select2data.d_$s1 = new Object();\n";
1156: $result.="select2data.d_$s1.def = new String('".
1157: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1158: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1159: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1160: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1161: @s2values = @{$hashref->{$s1}->{'order'}};
1162: }
1.36 matthew 1163: $result.="\"@s2values\");\n";
1164: $result.="select2data.d_$s1.texts = new Array(";
1165: my @s2texts;
1166: foreach my $value (@s2values) {
1167: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1168: }
1169: $result.="\"@s2texts\");\n";
1170: }
1171: $"=' ';
1172: $result.= <<"END";
1173:
1174: function select1_changed() {
1175: // Determine new choice
1176: var newvalue = "d_" + $first.value;
1177: // update select2
1178: var values = select2data[newvalue].values;
1179: var texts = select2data[newvalue].texts;
1180: var select2def = select2data[newvalue].def;
1181: var i;
1182: // out with the old
1183: for (i = 0; i < $second.options.length; i++) {
1184: $second.options[i] = null;
1185: }
1186: // in with the nuclear
1187: for (i=0;i<values.length; i++) {
1188: $second.options[i] = new Option(values[i]);
1.143 matthew 1189: $second.options[i].value = values[i];
1.36 matthew 1190: $second.options[i].text = texts[i];
1191: if (values[i] == select2def) {
1192: $second.options[i].selected = true;
1193: }
1194: }
1195: }
1.824 bisitz 1196: // ]]>
1.36 matthew 1197: </script>
1198: END
1199: # output the initial values for the selection lists
1.1115 raeburn 1200: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1201: my @order = sort(keys(%{$hashref}));
1202: if (ref($menuorder) eq 'ARRAY') {
1203: @order = @{$menuorder};
1204: }
1205: foreach my $value (@order) {
1.36 matthew 1206: $result.=" <option value=\"$value\" ";
1.253 albertel 1207: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1208: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1209: }
1210: $result .= "</select>\n";
1211: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1212: $result .= $middletext;
1.1115 raeburn 1213: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1214: if ($onchangesecond) {
1215: $result .= ' onchange="'.$onchangesecond.'"';
1216: }
1217: $result .= ">\n";
1.36 matthew 1218: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1219:
1220: my @secondorder = sort(keys(%select2));
1221: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1222: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1223: }
1224: foreach my $value (@secondorder) {
1.36 matthew 1225: $result.=" <option value=\"$value\" ";
1.253 albertel 1226: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1227: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1228: }
1229: $result .= "</select>\n";
1230: # return $debug;
1231: return $result;
1232: } # end of sub linked_select_forms {
1233:
1.45 matthew 1234: =pod
1.44 bowersj2 1235:
1.973 raeburn 1236: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1237:
1.112 bowersj2 1238: Returns a string corresponding to an HTML link to the given help
1239: $topic, where $topic corresponds to the name of a .tex file in
1240: /home/httpd/html/adm/help/tex, with underscores replaced by
1241: spaces.
1242:
1243: $text will optionally be linked to the same topic, allowing you to
1244: link text in addition to the graphic. If you do not want to link
1245: text, but wish to specify one of the later parameters, pass an
1246: empty string.
1247:
1248: $stayOnPage is a value that will be interpreted as a boolean. If true,
1249: the link will not open a new window. If false, the link will open
1250: a new window using Javascript. (Default is false.)
1251:
1252: $width and $height are optional numerical parameters that will
1253: override the width and height of the popped up window, which may
1.973 raeburn 1254: be useful for certain help topics with big pictures included.
1255:
1256: $imgid is the id of the img tag used for the help icon. This may be
1257: used in a javascript call to switch the image src. See
1258: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1259:
1260: =cut
1261:
1262: sub help_open_topic {
1.973 raeburn 1263: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1264: $text = "" if (not defined $text);
1.44 bowersj2 1265: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1266: $width = 500 if (not defined $width);
1.44 bowersj2 1267: $height = 400 if (not defined $height);
1268: my $filename = $topic;
1269: $filename =~ s/ /_/g;
1270:
1.48 bowersj2 1271: my $template = "";
1272: my $link;
1.572 banghart 1273:
1.159 www 1274: $topic=~s/\W/\_/g;
1.44 bowersj2 1275:
1.572 banghart 1276: if (!$stayOnPage) {
1.1033 www 1277: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1278: } elsif ($stayOnPage eq 'popup') {
1279: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1.572 banghart 1280: } else {
1.48 bowersj2 1281: $link = "/adm/help/${filename}.hlp";
1282: }
1283:
1284: # Add the text
1.755 neumanie 1285: if ($text ne "") {
1.763 bisitz 1286: $template.='<span class="LC_help_open_topic">'
1287: .'<a target="_top" href="'.$link.'">'
1288: .$text.'</a>';
1.48 bowersj2 1289: }
1290:
1.763 bisitz 1291: # (Always) Add the graphic
1.179 matthew 1292: my $title = &mt('Online Help');
1.667 raeburn 1293: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1294: if ($imgid ne '') {
1295: $imgid = ' id="'.$imgid.'"';
1296: }
1.763 bisitz 1297: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1298: .'<img src="'.$helpicon.'" border="0"'
1299: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1300: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1301: .' /></a>';
1302: if ($text ne "") {
1303: $template.='</span>';
1304: }
1.44 bowersj2 1305: return $template;
1306:
1.106 bowersj2 1307: }
1308:
1309: # This is a quicky function for Latex cheatsheet editing, since it
1310: # appears in at least four places
1311: sub helpLatexCheatsheet {
1.1037 www 1312: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1313: my $out;
1.106 bowersj2 1314: my $addOther = '';
1.732 raeburn 1315: if ($topic) {
1.1037 www 1316: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1317: }
1318: $out = '<span>' # Start cheatsheet
1319: .$addOther
1320: .'<span>'
1.1037 www 1321: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1322: .'</span> <span>'
1.1037 www 1323: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1324: .'</span>';
1.732 raeburn 1325: unless ($not_author) {
1.1186 kruse 1326: $out .= '<span>'
1327: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1328: .'</span> <span>'
1329: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1330: .'</span>';
1.732 raeburn 1331: }
1.763 bisitz 1332: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1333: return $out;
1.172 www 1334: }
1335:
1.430 albertel 1336: sub general_help {
1337: my $helptopic='Student_Intro';
1338: if ($env{'request.role'}=~/^(ca|au)/) {
1339: $helptopic='Authoring_Intro';
1.907 raeburn 1340: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1341: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1342: } elsif ($env{'request.role'}=~/^dc/) {
1343: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1344: }
1345: return $helptopic;
1346: }
1347:
1348: sub update_help_link {
1349: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1350: my $origurl = $ENV{'REQUEST_URI'};
1351: $origurl=~s|^/~|/priv/|;
1352: my $timestamp = time;
1353: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1354: $$datum = &escape($$datum);
1355: }
1356:
1357: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1358: my $output .= <<"ENDOUTPUT";
1359: <script type="text/javascript">
1.824 bisitz 1360: // <![CDATA[
1.430 albertel 1361: banner_link = '$banner_link';
1.824 bisitz 1362: // ]]>
1.430 albertel 1363: </script>
1364: ENDOUTPUT
1365: return $output;
1366: }
1367:
1368: # now just updates the help link and generates a blue icon
1.193 raeburn 1369: sub help_open_menu {
1.430 albertel 1370: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1371: = @_;
1.949 droeschl 1372: $stayOnPage = 1;
1.430 albertel 1373: my $output;
1374: if ($component_help) {
1375: if (!$text) {
1376: $output=&help_open_topic($component_help,undef,$stayOnPage,
1377: $width,$height);
1378: } else {
1379: my $help_text;
1380: $help_text=&unescape($topic);
1381: $output='<table><tr><td>'.
1382: &help_open_topic($component_help,$help_text,$stayOnPage,
1383: $width,$height).'</td></tr></table>';
1384: }
1385: }
1386: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1387: return $output.$banner_link;
1388: }
1389:
1390: sub top_nav_help {
1391: my ($text) = @_;
1.436 albertel 1392: $text = &mt($text);
1.949 droeschl 1393: my $stay_on_page = 1;
1394:
1.1168 raeburn 1395: my ($link,$banner_link);
1396: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1397: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1398: : "javascript:helpMenu('open')";
1399: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1400: }
1.201 raeburn 1401: my $title = &mt('Get help');
1.1168 raeburn 1402: if ($link) {
1403: return <<"END";
1.436 albertel 1404: $banner_link
1.1159 raeburn 1405: <a href="$link" title="$title">$text</a>
1.436 albertel 1406: END
1.1168 raeburn 1407: } else {
1408: return ' '.$text.' ';
1409: }
1.436 albertel 1410: }
1411:
1412: sub help_menu_js {
1.1154 raeburn 1413: my ($httphost) = @_;
1.949 droeschl 1414: my $stayOnPage = 1;
1.436 albertel 1415: my $width = 620;
1416: my $height = 600;
1.430 albertel 1417: my $helptopic=&general_help();
1.1154 raeburn 1418: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1419: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1420: my $start_page =
1421: &Apache::loncommon::start_page('Help Menu', undef,
1422: {'frameset' => 1,
1423: 'js_ready' => 1,
1.1154 raeburn 1424: 'use_absolute' => $httphost,
1.331 albertel 1425: 'add_entries' => {
1.1168 raeburn 1426: 'border' => '0',
1.579 raeburn 1427: 'rows' => "110,*",},});
1.331 albertel 1428: my $end_page =
1429: &Apache::loncommon::end_page({'frameset' => 1,
1430: 'js_ready' => 1,});
1431:
1.436 albertel 1432: my $template .= <<"ENDTEMPLATE";
1433: <script type="text/javascript">
1.877 bisitz 1434: // <![CDATA[
1.253 albertel 1435: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1436: var banner_link = '';
1.243 raeburn 1437: function helpMenu(target) {
1438: var caller = this;
1439: if (target == 'open') {
1440: var newWindow = null;
1441: try {
1.262 albertel 1442: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1443: }
1444: catch(error) {
1445: writeHelp(caller);
1446: return;
1447: }
1448: if (newWindow) {
1449: caller = newWindow;
1450: }
1.193 raeburn 1451: }
1.243 raeburn 1452: writeHelp(caller);
1453: return;
1454: }
1455: function writeHelp(caller) {
1.1168 raeburn 1456: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1457: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1458: caller.document.close();
1459: caller.focus();
1.193 raeburn 1460: }
1.877 bisitz 1461: // END LON-CAPA Internal -->
1.253 albertel 1462: // ]]>
1.436 albertel 1463: </script>
1.193 raeburn 1464: ENDTEMPLATE
1465: return $template;
1466: }
1467:
1.172 www 1468: sub help_open_bug {
1469: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1470: unless ($env{'user.adv'}) { return ''; }
1.172 www 1471: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1472: $text = "" if (not defined $text);
1473: $stayOnPage=1;
1.184 albertel 1474: $width = 600 if (not defined $width);
1475: $height = 600 if (not defined $height);
1.172 www 1476:
1477: $topic=~s/\W+/\+/g;
1478: my $link='';
1479: my $template='';
1.379 albertel 1480: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1481: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1482: if (!$stayOnPage)
1483: {
1484: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1485: }
1486: else
1487: {
1488: $link = $url;
1489: }
1490: # Add the text
1491: if ($text ne "")
1492: {
1493: $template .=
1494: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1495: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1496: }
1497:
1498: # Add the graphic
1.179 matthew 1499: my $title = &mt('Report a Bug');
1.215 albertel 1500: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1501: $template .= <<"ENDTEMPLATE";
1.436 albertel 1502: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1503: ENDTEMPLATE
1504: if ($text ne '') { $template.='</td></tr></table>' };
1505: return $template;
1506:
1507: }
1508:
1509: sub help_open_faq {
1510: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1511: unless ($env{'user.adv'}) { return ''; }
1.172 www 1512: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1513: $text = "" if (not defined $text);
1514: $stayOnPage=1;
1515: $width = 350 if (not defined $width);
1516: $height = 400 if (not defined $height);
1517:
1518: $topic=~s/\W+/\+/g;
1519: my $link='';
1520: my $template='';
1521: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1522: if (!$stayOnPage)
1523: {
1524: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1525: }
1526: else
1527: {
1528: $link = $url;
1529: }
1530:
1531: # Add the text
1532: if ($text ne "")
1533: {
1534: $template .=
1.173 www 1535: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1536: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1537: }
1538:
1539: # Add the graphic
1.179 matthew 1540: my $title = &mt('View the FAQ');
1.215 albertel 1541: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1542: $template .= <<"ENDTEMPLATE";
1.436 albertel 1543: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1544: ENDTEMPLATE
1545: if ($text ne '') { $template.='</td></tr></table>' };
1546: return $template;
1547:
1.44 bowersj2 1548: }
1.37 matthew 1549:
1.180 matthew 1550: ###############################################################
1551: ###############################################################
1552:
1.45 matthew 1553: =pod
1554:
1.648 raeburn 1555: =item * &change_content_javascript():
1.256 matthew 1556:
1557: This and the next function allow you to create small sections of an
1558: otherwise static HTML page that you can update on the fly with
1559: Javascript, even in Netscape 4.
1560:
1561: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1562: must be written to the HTML page once. It will prove the Javascript
1563: function "change(name, content)". Calling the change function with the
1564: name of the section
1565: you want to update, matching the name passed to C<changable_area>, and
1566: the new content you want to put in there, will put the content into
1567: that area.
1568:
1569: B<Note>: Netscape 4 only reserves enough space for the changable area
1570: to contain room for the original contents. You need to "make space"
1571: for whatever changes you wish to make, and be B<sure> to check your
1572: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1573: it's adequate for updating a one-line status display, but little more.
1574: This script will set the space to 100% width, so you only need to
1575: worry about height in Netscape 4.
1576:
1577: Modern browsers are much less limiting, and if you can commit to the
1578: user not using Netscape 4, this feature may be used freely with
1579: pretty much any HTML.
1580:
1581: =cut
1582:
1583: sub change_content_javascript {
1584: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1585: if ($env{'browser.type'} eq 'netscape' &&
1586: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1587: return (<<NETSCAPE4);
1588: function change(name, content) {
1589: doc = document.layers[name+"___escape"].layers[0].document;
1590: doc.open();
1591: doc.write(content);
1592: doc.close();
1593: }
1594: NETSCAPE4
1595: } else {
1596: # Otherwise, we need to use semi-standards-compliant code
1597: # (technically, "innerHTML" isn't standard but the equivalent
1598: # is really scary, and every useful browser supports it
1599: return (<<DOMBASED);
1600: function change(name, content) {
1601: element = document.getElementById(name);
1602: element.innerHTML = content;
1603: }
1604: DOMBASED
1605: }
1606: }
1607:
1608: =pod
1609:
1.648 raeburn 1610: =item * &changable_area($name,$origContent):
1.256 matthew 1611:
1612: This provides a "changable area" that can be modified on the fly via
1613: the Javascript code provided in C<change_content_javascript>. $name is
1614: the name you will use to reference the area later; do not repeat the
1615: same name on a given HTML page more then once. $origContent is what
1616: the area will originally contain, which can be left blank.
1617:
1618: =cut
1619:
1620: sub changable_area {
1621: my ($name, $origContent) = @_;
1622:
1.258 albertel 1623: if ($env{'browser.type'} eq 'netscape' &&
1624: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1625: # If this is netscape 4, we need to use the Layer tag
1626: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1627: } else {
1628: return "<span id='$name'>$origContent</span>";
1629: }
1630: }
1631:
1632: =pod
1633:
1.648 raeburn 1634: =item * &viewport_geometry_js
1.590 raeburn 1635:
1636: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1637:
1638: =cut
1639:
1640:
1641: sub viewport_geometry_js {
1642: return <<"GEOMETRY";
1643: var Geometry = {};
1644: function init_geometry() {
1645: if (Geometry.init) { return };
1646: Geometry.init=1;
1647: if (window.innerHeight) {
1648: Geometry.getViewportHeight = function() { return window.innerHeight; };
1649: Geometry.getViewportWidth = function() { return window.innerWidth; };
1650: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1651: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1652: }
1653: else if (document.documentElement && document.documentElement.clientHeight) {
1654: Geometry.getViewportHeight =
1655: function() { return document.documentElement.clientHeight; };
1656: Geometry.getViewportWidth =
1657: function() { return document.documentElement.clientWidth; };
1658:
1659: Geometry.getHorizontalScroll =
1660: function() { return document.documentElement.scrollLeft; };
1661: Geometry.getVerticalScroll =
1662: function() { return document.documentElement.scrollTop; };
1663: }
1664: else if (document.body.clientHeight) {
1665: Geometry.getViewportHeight =
1666: function() { return document.body.clientHeight; };
1667: Geometry.getViewportWidth =
1668: function() { return document.body.clientWidth; };
1669: Geometry.getHorizontalScroll =
1670: function() { return document.body.scrollLeft; };
1671: Geometry.getVerticalScroll =
1672: function() { return document.body.scrollTop; };
1673: }
1674: }
1675:
1676: GEOMETRY
1677: }
1678:
1679: =pod
1680:
1.648 raeburn 1681: =item * &viewport_size_js()
1.590 raeburn 1682:
1683: Provides a javascript function to set values of two form elements - width and height (elements are passed in as arguments to the javascript function) to the dimensions of the user's browser window.
1684:
1685: =cut
1686:
1687: sub viewport_size_js {
1688: my $geometry = &viewport_geometry_js();
1689: return <<"DIMS";
1690:
1691: $geometry
1692:
1693: function getViewportDims(width,height) {
1694: init_geometry();
1695: width.value = Geometry.getViewportWidth();
1696: height.value = Geometry.getViewportHeight();
1697: return;
1698: }
1699:
1700: DIMS
1701: }
1702:
1703: =pod
1704:
1.648 raeburn 1705: =item * &resize_textarea_js()
1.565 albertel 1706:
1707: emits the needed javascript to resize a textarea to be as big as possible
1708:
1709: creates a function resize_textrea that takes two IDs first should be
1710: the id of the element to resize, second should be the id of a div that
1711: surrounds everything that comes after the textarea, this routine needs
1712: to be attached to the <body> for the onload and onresize events.
1713:
1.648 raeburn 1714: =back
1.565 albertel 1715:
1716: =cut
1717:
1718: sub resize_textarea_js {
1.590 raeburn 1719: my $geometry = &viewport_geometry_js();
1.565 albertel 1720: return <<"RESIZE";
1721: <script type="text/javascript">
1.824 bisitz 1722: // <![CDATA[
1.590 raeburn 1723: $geometry
1.565 albertel 1724:
1.588 albertel 1725: function getX(element) {
1726: var x = 0;
1727: while (element) {
1728: x += element.offsetLeft;
1729: element = element.offsetParent;
1730: }
1731: return x;
1732: }
1733: function getY(element) {
1734: var y = 0;
1735: while (element) {
1736: y += element.offsetTop;
1737: element = element.offsetParent;
1738: }
1739: return y;
1740: }
1741:
1742:
1.565 albertel 1743: function resize_textarea(textarea_id,bottom_id) {
1744: init_geometry();
1745: var textarea = document.getElementById(textarea_id);
1746: //alert(textarea);
1747:
1.588 albertel 1748: var textarea_top = getY(textarea);
1.565 albertel 1749: var textarea_height = textarea.offsetHeight;
1750: var bottom = document.getElementById(bottom_id);
1.588 albertel 1751: var bottom_top = getY(bottom);
1.565 albertel 1752: var bottom_height = bottom.offsetHeight;
1753: var window_height = Geometry.getViewportHeight();
1.588 albertel 1754: var fudge = 23;
1.565 albertel 1755: var new_height = window_height-fudge-textarea_top-bottom_height;
1756: if (new_height < 300) {
1757: new_height = 300;
1758: }
1759: textarea.style.height=new_height+'px';
1760: }
1.824 bisitz 1761: // ]]>
1.565 albertel 1762: </script>
1763: RESIZE
1764:
1765: }
1766:
1.1205 golterma 1767: sub colorfuleditor_js {
1768: return <<"COLORFULEDIT"
1769: <script type="text/javascript">
1770: // <![CDATA[>
1771: function fold_box(curDepth, lastresource){
1772:
1773: // we need a list because there can be several blocks you need to fold in one tag
1774: var block = document.getElementsByName('foldblock_'+curDepth);
1775: // but there is only one folding button per tag
1776: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1777:
1778: if(block.item(0).style.display == 'none'){
1779:
1780: foldbutton.value = '@{[&mt("Hide")]}';
1781: for (i = 0; i < block.length; i++){
1782: block.item(i).style.display = '';
1783: }
1784: }else{
1785:
1786: foldbutton.value = '@{[&mt("Show")]}';
1787: for (i = 0; i < block.length; i++){
1788: // block.item(i).style.visibility = 'collapse';
1789: block.item(i).style.display = 'none';
1790: }
1791: };
1792: saveState(lastresource);
1793: }
1794:
1795: function saveState (lastresource) {
1796:
1797: var tag_list = getTagList();
1798: if(tag_list != null){
1799: var timestamp = new Date().getTime();
1800: var key = lastresource;
1801:
1802: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1803: // starting with timestamp
1804: var value = timestamp+';';
1805:
1806: // building the list of key-value pairs
1807: for(var i = 0; i < tag_list.length; i++){
1808: value += tag_list[i]+',';
1809: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1810: }
1811:
1812: // only iterate whole storage if nothing to override
1813: if(localStorage.getItem(key) == null){
1814:
1815: // prevent storage from growing large
1816: if(localStorage.length > 50){
1817: var regex_getTimestamp = /^(?:\d)+;/;
1818: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1819: var oldest_key;
1820:
1821: for(var i = 1; i < localStorage.length; i++){
1822: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1823: oldest_key = localStorage.key(i);
1824: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1825: }
1826: }
1827: localStorage.removeItem(oldest_key);
1828: }
1829: }
1830: localStorage.setItem(key,value);
1831: }
1832: }
1833:
1834: // restore folding status of blocks (on page load)
1835: function restoreState (lastresource) {
1836: if(localStorage.getItem(lastresource) != null){
1837: var key = lastresource;
1838: var value = localStorage.getItem(key);
1839: var regex_delTimestamp = /^\d+;/;
1840:
1841: value.replace(regex_delTimestamp, '');
1842:
1843: var valueArr = value.split(';');
1844: var pairs;
1845: var elements;
1846: for (var i = 0; i < valueArr.length; i++){
1847: pairs = valueArr[i].split(',');
1848: elements = document.getElementsByName(pairs[0]);
1849:
1850: for (var j = 0; j < elements.length; j++){
1851: elements[j].style.display = pairs[1];
1852: if (pairs[1] == "none"){
1853: var regex_id = /([_\\d]+)\$/;
1854: regex_id.exec(pairs[0]);
1855: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
1856: }
1857: }
1858: }
1859: }
1860: }
1861:
1862: function getTagList () {
1863:
1864: var stringToSearch = document.lonhomework.innerHTML;
1865:
1866: var ret = new Array();
1867: var regex_findBlock = /(foldblock_.*?)"/g;
1868: var tag_list = stringToSearch.match(regex_findBlock);
1869:
1870: if(tag_list != null){
1871: for(var i = 0; i < tag_list.length; i++){
1872: ret.push(tag_list[i].replace(/"/, ''));
1873: }
1874: }
1875: return ret;
1876: }
1877:
1878: function saveScrollPosition (resource) {
1879: var tag_list = getTagList();
1880:
1881: // we dont always want to jump to the first block
1882: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
1883: if(\$(window).scrollTop() > 170){
1884: if(tag_list != null){
1885: var result;
1886: for(var i = 0; i < tag_list.length; i++){
1887: if(isElementInViewport(tag_list[i])){
1888: result += tag_list[i]+';';
1889: }
1890: }
1891: sessionStorage.setItem('anchor_'+resource, result);
1892: }
1893: } else {
1894: // we dont need to save zero, just delete the item to leave everything tidy
1895: sessionStorage.removeItem('anchor_'+resource);
1896: }
1897: }
1898:
1899: function restoreScrollPosition(resource){
1900:
1901: var elem = sessionStorage.getItem('anchor_'+resource);
1902: if(elem != null){
1903: var tag_list = elem.split(';');
1904: var elem_list;
1905:
1906: for(var i = 0; i < tag_list.length; i++){
1907: elem_list = document.getElementsByName(tag_list[i]);
1908:
1909: if(elem_list.length > 0){
1910: elem = elem_list[0];
1911: break;
1912: }
1913: }
1914: elem.scrollIntoView();
1915: }
1916: }
1917:
1918: function isElementInViewport(el) {
1919:
1920: // change to last element instead of first
1921: var elem = document.getElementsByName(el);
1922: var rect = elem[0].getBoundingClientRect();
1923:
1924: return (
1925: rect.top >= 0 &&
1926: rect.left >= 0 &&
1927: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1928: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1929: );
1930: }
1931:
1932: function autosize(depth){
1933: var cmInst = window['cm'+depth];
1934: var fitsizeButton = document.getElementById('fitsize'+depth);
1935:
1936: // is fixed size, switching to dynamic
1937: if (sessionStorage.getItem("autosized_"+depth) == null) {
1938: cmInst.setSize("","auto");
1939: fitsizeButton.value = "@{[&mt('Fixed size')]}";
1940: sessionStorage.setItem("autosized_"+depth, "yes");
1941:
1942: // is dynamic size, switching to fixed
1943: } else {
1944: cmInst.setSize("","300px");
1945: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
1946: sessionStorage.removeItem("autosized_"+depth);
1947: }
1948: }
1949:
1950:
1951:
1952: // ]]>
1953: </script>
1954: COLORFULEDIT
1955: }
1956:
1957: sub xmleditor_js {
1958: return <<XMLEDIT
1959: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
1960: <script type="text/javascript">
1961: // <![CDATA[>
1962:
1963: function saveScrollPosition (resource) {
1964:
1965: var scrollPos = \$(window).scrollTop();
1966: sessionStorage.setItem(resource,scrollPos);
1967: }
1968:
1969: function restoreScrollPosition(resource){
1970:
1971: var scrollPos = sessionStorage.getItem(resource);
1972: \$(window).scrollTop(scrollPos);
1973: }
1974:
1975: // unless internet explorer
1976: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
1977:
1978: \$(document).ready(function() {
1979: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
1980: });
1981: }
1982:
1983: // inserts text at cursor position into codemirror (xml editor only)
1984: function insertText(text){
1985: cm.focus();
1986: var curPos = cm.getCursor();
1987: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
1988: }
1989: // ]]>
1990: </script>
1991: XMLEDIT
1992: }
1993:
1994: sub insert_folding_button {
1995: my $curDepth = $Apache::lonxml::curdepth;
1996: my $lastresource = $env{'request.ambiguous'};
1997:
1998: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
1999: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2000: }
2001:
1.565 albertel 2002: =pod
2003:
1.256 matthew 2004: =head1 Excel and CSV file utility routines
2005:
2006: =cut
2007:
2008: ###############################################################
2009: ###############################################################
2010:
2011: =pod
2012:
1.1162 raeburn 2013: =over 4
2014:
1.648 raeburn 2015: =item * &csv_translate($text)
1.37 matthew 2016:
1.185 www 2017: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2018: format.
2019:
2020: =cut
2021:
1.180 matthew 2022: ###############################################################
2023: ###############################################################
1.37 matthew 2024: sub csv_translate {
2025: my $text = shift;
2026: $text =~ s/\"/\"\"/g;
1.209 albertel 2027: $text =~ s/\n/ /g;
1.37 matthew 2028: return $text;
2029: }
1.180 matthew 2030:
2031: ###############################################################
2032: ###############################################################
2033:
2034: =pod
2035:
1.648 raeburn 2036: =item * &define_excel_formats()
1.180 matthew 2037:
2038: Define some commonly used Excel cell formats.
2039:
2040: Currently supported formats:
2041:
2042: =over 4
2043:
2044: =item header
2045:
2046: =item bold
2047:
2048: =item h1
2049:
2050: =item h2
2051:
2052: =item h3
2053:
1.256 matthew 2054: =item h4
2055:
2056: =item i
2057:
1.180 matthew 2058: =item date
2059:
2060: =back
2061:
2062: Inputs: $workbook
2063:
2064: Returns: $format, a hash reference.
2065:
1.1057 foxr 2066:
1.180 matthew 2067: =cut
2068:
2069: ###############################################################
2070: ###############################################################
2071: sub define_excel_formats {
2072: my ($workbook) = @_;
2073: my $format;
2074: $format->{'header'} = $workbook->add_format(bold => 1,
2075: bottom => 1,
2076: align => 'center');
2077: $format->{'bold'} = $workbook->add_format(bold=>1);
2078: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2079: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2080: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2081: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2082: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2083: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2084: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2085: return $format;
2086: }
2087:
2088: ###############################################################
2089: ###############################################################
1.113 bowersj2 2090:
2091: =pod
2092:
1.648 raeburn 2093: =item * &create_workbook()
1.255 matthew 2094:
2095: Create an Excel worksheet. If it fails, output message on the
2096: request object and return undefs.
2097:
2098: Inputs: Apache request object
2099:
2100: Returns (undef) on failure,
2101: Excel worksheet object, scalar with filename, and formats
2102: from &Apache::loncommon::define_excel_formats on success
2103:
2104: =cut
2105:
2106: ###############################################################
2107: ###############################################################
2108: sub create_workbook {
2109: my ($r) = @_;
2110: #
2111: # Create the excel spreadsheet
2112: my $filename = '/prtspool/'.
1.258 albertel 2113: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2114: time.'_'.rand(1000000000).'.xls';
2115: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2116: if (! defined($workbook)) {
2117: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2118: $r->print(
2119: '<p class="LC_error">'
2120: .&mt('Problems occurred in creating the new Excel file.')
2121: .' '.&mt('This error has been logged.')
2122: .' '.&mt('Please alert your LON-CAPA administrator.')
2123: .'</p>'
2124: );
1.255 matthew 2125: return (undef);
2126: }
2127: #
1.1014 foxr 2128: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2129: #
2130: my $format = &Apache::loncommon::define_excel_formats($workbook);
2131: return ($workbook,$filename,$format);
2132: }
2133:
2134: ###############################################################
2135: ###############################################################
2136:
2137: =pod
2138:
1.648 raeburn 2139: =item * &create_text_file()
1.113 bowersj2 2140:
1.542 raeburn 2141: Create a file to write to and eventually make available to the user.
1.256 matthew 2142: If file creation fails, outputs an error message on the request object and
2143: return undefs.
1.113 bowersj2 2144:
1.256 matthew 2145: Inputs: Apache request object, and file suffix
1.113 bowersj2 2146:
1.256 matthew 2147: Returns (undef) on failure,
2148: Filehandle and filename on success.
1.113 bowersj2 2149:
2150: =cut
2151:
1.256 matthew 2152: ###############################################################
2153: ###############################################################
2154: sub create_text_file {
2155: my ($r,$suffix) = @_;
2156: if (! defined($suffix)) { $suffix = 'txt'; };
2157: my $fh;
2158: my $filename = '/prtspool/'.
1.258 albertel 2159: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2160: time.'_'.rand(1000000000).'.'.$suffix;
2161: $fh = Apache::File->new('>/home/httpd'.$filename);
2162: if (! defined($fh)) {
2163: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2164: $r->print(
2165: '<p class="LC_error">'
2166: .&mt('Problems occurred in creating the output file.')
2167: .' '.&mt('This error has been logged.')
2168: .' '.&mt('Please alert your LON-CAPA administrator.')
2169: .'</p>'
2170: );
1.113 bowersj2 2171: }
1.256 matthew 2172: return ($fh,$filename)
1.113 bowersj2 2173: }
2174:
2175:
1.256 matthew 2176: =pod
1.113 bowersj2 2177:
2178: =back
2179:
2180: =cut
1.37 matthew 2181:
2182: ###############################################################
1.33 matthew 2183: ## Home server <option> list generating code ##
2184: ###############################################################
1.35 matthew 2185:
1.169 www 2186: # ------------------------------------------
2187:
2188: sub domain_select {
2189: my ($name,$value,$multiple)=@_;
2190: my %domains=map {
1.514 albertel 2191: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2192: } &Apache::lonnet::all_domains();
1.169 www 2193: if ($multiple) {
2194: $domains{''}=&mt('Any domain');
1.550 albertel 2195: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2196: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2197: } else {
1.550 albertel 2198: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2199: return &select_form($name,$value,\%domains);
1.169 www 2200: }
2201: }
2202:
1.282 albertel 2203: #-------------------------------------------
2204:
2205: =pod
2206:
1.519 raeburn 2207: =head1 Routines for form select boxes
2208:
2209: =over 4
2210:
1.648 raeburn 2211: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2212:
2213: Returns a string containing a <select> element int multiple mode
2214:
2215:
2216: Args:
2217: $name - name of the <select> element
1.506 raeburn 2218: $value - scalar or array ref of values that should already be selected
1.282 albertel 2219: $size - number of rows long the select element is
1.283 albertel 2220: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2221: (shown text should already have been &mt())
1.506 raeburn 2222: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2223:
1.282 albertel 2224: =cut
2225:
2226: #-------------------------------------------
1.169 www 2227: sub multiple_select_form {
1.284 albertel 2228: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2229: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2230: my $output='';
1.191 matthew 2231: if (! defined($size)) {
2232: $size = 4;
1.283 albertel 2233: if (scalar(keys(%$hash))<4) {
2234: $size = scalar(keys(%$hash));
1.191 matthew 2235: }
2236: }
1.734 bisitz 2237: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2238: my @order;
1.506 raeburn 2239: if (ref($order) eq 'ARRAY') {
2240: @order = @{$order};
2241: } else {
2242: @order = sort(keys(%$hash));
1.501 banghart 2243: }
2244: if (exists($$hash{'select_form_order'})) {
2245: @order = @{$$hash{'select_form_order'}};
2246: }
2247:
1.284 albertel 2248: foreach my $key (@order) {
1.356 albertel 2249: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2250: $output.='selected="selected" ' if ($selected{$key});
2251: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2252: }
2253: $output.="</select>\n";
2254: return $output;
2255: }
2256:
1.88 www 2257: #-------------------------------------------
2258:
2259: =pod
2260:
1.970 raeburn 2261: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 2262:
2263: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2264: allow a user to select options from a ref to a hash containing:
2265: option_name => displayed text. An optional $onchange can include
2266: a javascript onchange item, e.g., onchange="this.form.submit();"
2267:
1.88 www 2268: See lonrights.pm for an example invocation and use.
2269:
2270: =cut
2271:
2272: #-------------------------------------------
2273: sub select_form {
1.1228 raeburn 2274: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2275: return unless (ref($hashref) eq 'HASH');
2276: if ($onchange) {
2277: $onchange = ' onchange="'.$onchange.'"';
2278: }
1.1228 raeburn 2279: my $disabled;
2280: if ($readonly) {
2281: $disabled = ' disabled="disabled"';
2282: }
2283: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2284: my @keys;
1.970 raeburn 2285: if (exists($hashref->{'select_form_order'})) {
2286: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2287: } else {
1.970 raeburn 2288: @keys=sort(keys(%{$hashref}));
1.128 albertel 2289: }
1.356 albertel 2290: foreach my $key (@keys) {
2291: $selectform.=
2292: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2293: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2294: ">".$hashref->{$key}."</option>\n";
1.88 www 2295: }
2296: $selectform.="</select>";
2297: return $selectform;
2298: }
2299:
1.475 www 2300: # For display filters
2301:
2302: sub display_filter {
1.1074 raeburn 2303: my ($context) = @_;
1.475 www 2304: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2305: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2306: my $phraseinput = 'hidden';
2307: my $includeinput = 'hidden';
2308: my ($checked,$includetypestext);
2309: if ($env{'form.displayfilter'} eq 'containing') {
2310: $phraseinput = 'text';
2311: if ($context eq 'parmslog') {
2312: $includeinput = 'checkbox';
2313: if ($env{'form.includetypes'}) {
2314: $checked = ' checked="checked"';
2315: }
2316: $includetypestext = &mt('Include parameter types');
2317: }
2318: } else {
2319: $includetypestext = ' ';
2320: }
2321: my ($additional,$secondid,$thirdid);
2322: if ($context eq 'parmslog') {
2323: $additional =
2324: '<label><input type="'.$includeinput.'" name="includetypes"'.
2325: $checked.' name="includetypes" value="1" id="includetypes" />'.
2326: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2327: '</label>';
2328: $secondid = 'includetypes';
2329: $thirdid = 'includetypestext';
2330: }
2331: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2332: '$secondid','$thirdid')";
2333: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2334: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2335: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2336: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2337: &mt('Filter: [_1]',
1.477 www 2338: &select_form($env{'form.displayfilter'},
2339: 'displayfilter',
1.970 raeburn 2340: {'currentfolder' => 'Current folder/page',
1.477 www 2341: 'containing' => 'Containing phrase',
1.1074 raeburn 2342: 'none' => 'None'},$onchange)).' '.
2343: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2344: &HTML::Entities::encode($env{'form.containingphrase'}).
2345: '" />'.$additional;
2346: }
2347:
2348: sub display_filter_js {
2349: my $includetext = &mt('Include parameter types');
2350: return <<"ENDJS";
2351:
2352: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2353: var firstType = 'hidden';
2354: if (setter.options[setter.selectedIndex].value == 'containing') {
2355: firstType = 'text';
2356: }
2357: firstObject = document.getElementById(firstid);
2358: if (typeof(firstObject) == 'object') {
2359: if (firstObject.type != firstType) {
2360: changeInputType(firstObject,firstType);
2361: }
2362: }
2363: if (context == 'parmslog') {
2364: var secondType = 'hidden';
2365: if (firstType == 'text') {
2366: secondType = 'checkbox';
2367: }
2368: secondObject = document.getElementById(secondid);
2369: if (typeof(secondObject) == 'object') {
2370: if (secondObject.type != secondType) {
2371: changeInputType(secondObject,secondType);
2372: }
2373: }
2374: var textItem = document.getElementById(thirdid);
2375: var currtext = textItem.innerHTML;
2376: var newtext;
2377: if (firstType == 'text') {
2378: newtext = '$includetext';
2379: } else {
2380: newtext = ' ';
2381: }
2382: if (currtext != newtext) {
2383: textItem.innerHTML = newtext;
2384: }
2385: }
2386: return;
2387: }
2388:
2389: function changeInputType(oldObject,newType) {
2390: var newObject = document.createElement('input');
2391: newObject.type = newType;
2392: if (oldObject.size) {
2393: newObject.size = oldObject.size;
2394: }
2395: if (oldObject.value) {
2396: newObject.value = oldObject.value;
2397: }
2398: if (oldObject.name) {
2399: newObject.name = oldObject.name;
2400: }
2401: if (oldObject.id) {
2402: newObject.id = oldObject.id;
2403: }
2404: oldObject.parentNode.replaceChild(newObject,oldObject);
2405: return;
2406: }
2407:
2408: ENDJS
1.475 www 2409: }
2410:
1.167 www 2411: sub gradeleveldescription {
2412: my $gradelevel=shift;
2413: my %gradelevels=(0 => 'Not specified',
2414: 1 => 'Grade 1',
2415: 2 => 'Grade 2',
2416: 3 => 'Grade 3',
2417: 4 => 'Grade 4',
2418: 5 => 'Grade 5',
2419: 6 => 'Grade 6',
2420: 7 => 'Grade 7',
2421: 8 => 'Grade 8',
2422: 9 => 'Grade 9',
2423: 10 => 'Grade 10',
2424: 11 => 'Grade 11',
2425: 12 => 'Grade 12',
2426: 13 => 'Grade 13',
2427: 14 => '100 Level',
2428: 15 => '200 Level',
2429: 16 => '300 Level',
2430: 17 => '400 Level',
2431: 18 => 'Graduate Level');
2432: return &mt($gradelevels{$gradelevel});
2433: }
2434:
1.163 www 2435: sub select_level_form {
2436: my ($deflevel,$name)=@_;
2437: unless ($deflevel) { $deflevel=0; }
1.167 www 2438: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2439: for (my $i=0; $i<=18; $i++) {
2440: $selectform.="<option value=\"$i\" ".
1.253 albertel 2441: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2442: ">".&gradeleveldescription($i)."</option>\n";
2443: }
2444: $selectform.="</select>";
2445: return $selectform;
1.163 www 2446: }
1.167 www 2447:
1.35 matthew 2448: #-------------------------------------------
2449:
1.45 matthew 2450: =pod
2451:
1.1121 raeburn 2452: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35 matthew 2453:
2454: Returns a string containing a <select name='$name' size='1'> form to
2455: allow a user to select the domain to preform an operation in.
2456: See loncreateuser.pm for an example invocation and use.
2457:
1.90 www 2458: If the $includeempty flag is set, it also includes an empty choice ("no domain
2459: selected");
2460:
1.743 raeburn 2461: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2462:
1.910 raeburn 2463: The optional $onchange argument specifies what should occur if the domain selector is changed, e.g., 'this.form.submit()' if the form is to be automatically submitted.
2464:
1.1121 raeburn 2465: The optional $incdoms is a reference to an array of domains which will be the only available options.
2466:
2467: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2468:
1.35 matthew 2469: =cut
2470:
2471: #-------------------------------------------
1.34 matthew 2472: sub select_dom_form {
1.1121 raeburn 2473: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2474: if ($onchange) {
1.874 raeburn 2475: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2476: }
1.1121 raeburn 2477: my (@domains,%exclude);
1.910 raeburn 2478: if (ref($incdoms) eq 'ARRAY') {
2479: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2480: } else {
2481: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2482: }
1.90 www 2483: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2484: if (ref($excdoms) eq 'ARRAY') {
2485: map { $exclude{$_} = 1; } @{$excdoms};
2486: }
1.743 raeburn 2487: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2488: foreach my $dom (@domains) {
1.1121 raeburn 2489: next if ($exclude{$dom});
1.356 albertel 2490: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2491: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2492: if ($showdomdesc) {
2493: if ($dom ne '') {
2494: my $domdesc = &Apache::lonnet::domain($dom,'description');
2495: if ($domdesc ne '') {
2496: $selectdomain .= ' ('.$domdesc.')';
2497: }
2498: }
2499: }
2500: $selectdomain .= "</option>\n";
1.34 matthew 2501: }
2502: $selectdomain.="</select>";
2503: return $selectdomain;
2504: }
2505:
1.35 matthew 2506: #-------------------------------------------
2507:
1.45 matthew 2508: =pod
2509:
1.648 raeburn 2510: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2511:
1.586 raeburn 2512: input: 4 arguments (two required, two optional) -
2513: $domain - domain of new user
2514: $name - name of form element
2515: $default - Value of 'default' causes a default item to be first
2516: option, and selected by default.
2517: $hide - Value of 'hide' causes hiding of the name of the server,
2518: if 1 server found, or default, if 0 found.
1.594 raeburn 2519: output: returns 2 items:
1.586 raeburn 2520: (a) form element which contains either:
2521: (i) <select name="$name">
2522: <option value="$hostid1">$hostid $servers{$hostid}</option>
2523: <option value="$hostid2">$hostid $servers{$hostid}</option>
2524: </select>
2525: form item if there are multiple library servers in $domain, or
2526: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2527: if there is only one library server in $domain.
2528:
2529: (b) number of library servers found.
2530:
2531: See loncreateuser.pm for example of use.
1.35 matthew 2532:
2533: =cut
2534:
2535: #-------------------------------------------
1.586 raeburn 2536: sub home_server_form_item {
2537: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2538: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2539: my $result;
2540: my $numlib = keys(%servers);
2541: if ($numlib > 1) {
2542: $result .= '<select name="'.$name.'" />'."\n";
2543: if ($default) {
1.804 bisitz 2544: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2545: '</option>'."\n";
2546: }
2547: foreach my $hostid (sort(keys(%servers))) {
2548: $result.= '<option value="'.$hostid.'">'.
2549: $hostid.' '.$servers{$hostid}."</option>\n";
2550: }
2551: $result .= '</select>'."\n";
2552: } elsif ($numlib == 1) {
2553: my $hostid;
2554: foreach my $item (keys(%servers)) {
2555: $hostid = $item;
2556: }
2557: $result .= '<input type="hidden" name="'.$name.'" value="'.
2558: $hostid.'" />';
2559: if (!$hide) {
2560: $result .= $hostid.' '.$servers{$hostid};
2561: }
2562: $result .= "\n";
2563: } elsif ($default) {
2564: $result .= '<input type="hidden" name="'.$name.
2565: '" value="default" />';
2566: if (!$hide) {
2567: $result .= &mt('default');
2568: }
2569: $result .= "\n";
1.33 matthew 2570: }
1.586 raeburn 2571: return ($result,$numlib);
1.33 matthew 2572: }
1.112 bowersj2 2573:
2574: =pod
2575:
1.534 albertel 2576: =back
2577:
1.112 bowersj2 2578: =cut
1.87 matthew 2579:
2580: ###############################################################
1.112 bowersj2 2581: ## Decoding User Agent ##
1.87 matthew 2582: ###############################################################
2583:
2584: =pod
2585:
1.112 bowersj2 2586: =head1 Decoding the User Agent
2587:
2588: =over 4
2589:
2590: =item * &decode_user_agent()
1.87 matthew 2591:
2592: Inputs: $r
2593:
2594: Outputs:
2595:
2596: =over 4
2597:
1.112 bowersj2 2598: =item * $httpbrowser
1.87 matthew 2599:
1.112 bowersj2 2600: =item * $clientbrowser
1.87 matthew 2601:
1.112 bowersj2 2602: =item * $clientversion
1.87 matthew 2603:
1.112 bowersj2 2604: =item * $clientmathml
1.87 matthew 2605:
1.112 bowersj2 2606: =item * $clientunicode
1.87 matthew 2607:
1.112 bowersj2 2608: =item * $clientos
1.87 matthew 2609:
1.1137 raeburn 2610: =item * $clientmobile
2611:
1.1141 raeburn 2612: =item * $clientinfo
2613:
1.1194 raeburn 2614: =item * $clientosversion
2615:
1.87 matthew 2616: =back
2617:
1.157 matthew 2618: =back
2619:
1.87 matthew 2620: =cut
2621:
2622: ###############################################################
2623: ###############################################################
2624: sub decode_user_agent {
1.247 albertel 2625: my ($r)=@_;
1.87 matthew 2626: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2627: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2628: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2629: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2630: my $clientbrowser='unknown';
2631: my $clientversion='0';
2632: my $clientmathml='';
2633: my $clientunicode='0';
1.1137 raeburn 2634: my $clientmobile=0;
1.1194 raeburn 2635: my $clientosversion='';
1.87 matthew 2636: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2637: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2638: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2639: $clientbrowser=$bname;
2640: $httpbrowser=~/$vreg/i;
2641: $clientversion=$1;
2642: $clientmathml=($clientversion>=$minv);
2643: $clientunicode=($clientversion>=$univ);
2644: }
2645: }
2646: my $clientos='unknown';
1.1141 raeburn 2647: my $clientinfo;
1.87 matthew 2648: if (($httpbrowser=~/linux/i) ||
2649: ($httpbrowser=~/unix/i) ||
2650: ($httpbrowser=~/ux/i) ||
2651: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2652: if (($httpbrowser=~/vax/i) ||
2653: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2654: if ($httpbrowser=~/next/i) { $clientos='next'; }
2655: if (($httpbrowser=~/mac/i) ||
2656: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2657: if ($httpbrowser=~/win/i) {
2658: $clientos='win';
2659: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2660: $clientosversion = $1;
2661: }
2662: }
1.87 matthew 2663: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2664: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2665: $clientmobile=lc($1);
2666: }
1.1141 raeburn 2667: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2668: $clientinfo = 'firefox-'.$1;
2669: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2670: $clientinfo = 'chromeframe-'.$1;
2671: }
1.87 matthew 2672: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 2673: $clientunicode,$clientos,$clientmobile,$clientinfo,
2674: $clientosversion);
1.87 matthew 2675: }
2676:
1.32 matthew 2677: ###############################################################
2678: ## Authentication changing form generation subroutines ##
2679: ###############################################################
2680: ##
2681: ## All of the authform_xxxxxxx subroutines take their inputs in a
2682: ## hash, and have reasonable default values.
2683: ##
2684: ## formname = the name given in the <form> tag.
1.35 matthew 2685: #-------------------------------------------
2686:
1.45 matthew 2687: =pod
2688:
1.112 bowersj2 2689: =head1 Authentication Routines
2690:
2691: =over 4
2692:
1.648 raeburn 2693: =item * &authform_xxxxxx()
1.35 matthew 2694:
2695: The authform_xxxxxx subroutines provide javascript and html forms which
2696: handle some of the conveniences required for authentication forms.
2697: This is not an optimal method, but it works.
2698:
2699: =over 4
2700:
1.112 bowersj2 2701: =item * authform_header
1.35 matthew 2702:
1.112 bowersj2 2703: =item * authform_authorwarning
1.35 matthew 2704:
1.112 bowersj2 2705: =item * authform_nochange
1.35 matthew 2706:
1.112 bowersj2 2707: =item * authform_kerberos
1.35 matthew 2708:
1.112 bowersj2 2709: =item * authform_internal
1.35 matthew 2710:
1.112 bowersj2 2711: =item * authform_filesystem
1.35 matthew 2712:
2713: =back
2714:
1.648 raeburn 2715: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2716:
1.35 matthew 2717: =cut
2718:
2719: #-------------------------------------------
1.32 matthew 2720: sub authform_header{
2721: my %in = (
2722: formname => 'cu',
1.80 albertel 2723: kerb_def_dom => '',
1.32 matthew 2724: @_,
2725: );
2726: $in{'formname'} = 'document.' . $in{'formname'};
2727: my $result='';
1.80 albertel 2728:
2729: #---------------------------------------------- Code for upper case translation
2730: my $Javascript_toUpperCase;
2731: unless ($in{kerb_def_dom}) {
2732: $Javascript_toUpperCase =<<"END";
2733: switch (choice) {
2734: case 'krb': currentform.elements[choicearg].value =
2735: currentform.elements[choicearg].value.toUpperCase();
2736: break;
2737: default:
2738: }
2739: END
2740: } else {
2741: $Javascript_toUpperCase = "";
2742: }
2743:
1.165 raeburn 2744: my $radioval = "'nochange'";
1.591 raeburn 2745: if (defined($in{'curr_authtype'})) {
2746: if ($in{'curr_authtype'} ne '') {
2747: $radioval = "'".$in{'curr_authtype'}."arg'";
2748: }
1.174 matthew 2749: }
1.165 raeburn 2750: my $argfield = 'null';
1.591 raeburn 2751: if (defined($in{'mode'})) {
1.165 raeburn 2752: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2753: if (defined($in{'curr_autharg'})) {
2754: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2755: $argfield = "'$in{'curr_autharg'}'";
2756: }
2757: }
2758: }
2759: }
2760:
1.32 matthew 2761: $result.=<<"END";
2762: var current = new Object();
1.165 raeburn 2763: current.radiovalue = $radioval;
2764: current.argfield = $argfield;
1.32 matthew 2765:
2766: function changed_radio(choice,currentform) {
2767: var choicearg = choice + 'arg';
2768: // If a radio button in changed, we need to change the argfield
2769: if (current.radiovalue != choice) {
2770: current.radiovalue = choice;
2771: if (current.argfield != null) {
2772: currentform.elements[current.argfield].value = '';
2773: }
2774: if (choice == 'nochange') {
2775: current.argfield = null;
2776: } else {
2777: current.argfield = choicearg;
2778: switch(choice) {
2779: case 'krb':
2780: currentform.elements[current.argfield].value =
2781: "$in{'kerb_def_dom'}";
2782: break;
2783: default:
2784: break;
2785: }
2786: }
2787: }
2788: return;
2789: }
1.22 www 2790:
1.32 matthew 2791: function changed_text(choice,currentform) {
2792: var choicearg = choice + 'arg';
2793: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2794: $Javascript_toUpperCase
1.32 matthew 2795: // clear old field
2796: if ((current.argfield != choicearg) && (current.argfield != null)) {
2797: currentform.elements[current.argfield].value = '';
2798: }
2799: current.argfield = choicearg;
2800: }
2801: set_auth_radio_buttons(choice,currentform);
2802: return;
1.20 www 2803: }
1.32 matthew 2804:
2805: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2806: var numauthchoices = currentform.login.length;
2807: if (typeof numauthchoices == "undefined") {
2808: return;
2809: }
1.32 matthew 2810: var i=0;
1.986 raeburn 2811: while (i < numauthchoices) {
1.32 matthew 2812: if (currentform.login[i].value == newvalue) { break; }
2813: i++;
2814: }
1.986 raeburn 2815: if (i == numauthchoices) {
1.32 matthew 2816: return;
2817: }
2818: current.radiovalue = newvalue;
2819: currentform.login[i].checked = true;
2820: return;
2821: }
2822: END
2823: return $result;
2824: }
2825:
1.1106 raeburn 2826: sub authform_authorwarning {
1.32 matthew 2827: my $result='';
1.144 matthew 2828: $result='<i>'.
2829: &mt('As a general rule, only authors or co-authors should be '.
2830: 'filesystem authenticated '.
2831: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2832: return $result;
2833: }
2834:
1.1106 raeburn 2835: sub authform_nochange {
1.32 matthew 2836: my %in = (
2837: formname => 'document.cu',
2838: kerb_def_dom => 'MSU.EDU',
2839: @_,
2840: );
1.1106 raeburn 2841: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2842: my $result;
1.1104 raeburn 2843: if (!$authnum) {
1.1105 raeburn 2844: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2845: } else {
2846: $result = '<label>'.&mt('[_1] Do not change login data',
2847: '<input type="radio" name="login" value="nochange" '.
2848: 'checked="checked" onclick="'.
1.281 albertel 2849: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2850: '</label>';
1.586 raeburn 2851: }
1.32 matthew 2852: return $result;
2853: }
2854:
1.591 raeburn 2855: sub authform_kerberos {
1.32 matthew 2856: my %in = (
2857: formname => 'document.cu',
2858: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2859: kerb_def_auth => 'krb4',
1.32 matthew 2860: @_,
2861: );
1.586 raeburn 2862: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2863: $autharg,$jscall);
1.1106 raeburn 2864: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2865: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2866: $check5 = ' checked="checked"';
1.80 albertel 2867: } else {
1.772 bisitz 2868: $check4 = ' checked="checked"';
1.80 albertel 2869: }
1.165 raeburn 2870: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2871: if (defined($in{'curr_authtype'})) {
2872: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2873: $krbcheck = ' checked="checked"';
1.623 raeburn 2874: if (defined($in{'mode'})) {
2875: if ($in{'mode'} eq 'modifyuser') {
2876: $krbcheck = '';
2877: }
2878: }
1.591 raeburn 2879: if (defined($in{'curr_kerb_ver'})) {
2880: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2881: $check5 = ' checked="checked"';
1.591 raeburn 2882: $check4 = '';
2883: } else {
1.772 bisitz 2884: $check4 = ' checked="checked"';
1.591 raeburn 2885: $check5 = '';
2886: }
1.586 raeburn 2887: }
1.591 raeburn 2888: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2889: $krbarg = $in{'curr_autharg'};
2890: }
1.586 raeburn 2891: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2892: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2893: $result =
2894: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2895: $in{'curr_autharg'},$krbver);
2896: } else {
2897: $result =
2898: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2899: }
2900: return $result;
2901: }
2902: }
2903: } else {
2904: if ($authnum == 1) {
1.784 bisitz 2905: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2906: }
2907: }
1.586 raeburn 2908: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2909: return;
1.587 raeburn 2910: } elsif ($authtype eq '') {
1.591 raeburn 2911: if (defined($in{'mode'})) {
1.587 raeburn 2912: if ($in{'mode'} eq 'modifycourse') {
2913: if ($authnum == 1) {
1.1104 raeburn 2914: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2915: }
2916: }
2917: }
1.586 raeburn 2918: }
2919: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2920: if ($authtype eq '') {
2921: $authtype = '<input type="radio" name="login" value="krb" '.
2922: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2923: $krbcheck.' />';
2924: }
2925: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 2926: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2927: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 2928: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2929: $in{'curr_authtype'} eq 'krb4')) {
2930: $result .= &mt
1.144 matthew 2931: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2932: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2933: '<label>'.$authtype,
1.281 albertel 2934: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2935: 'value="'.$krbarg.'" '.
1.144 matthew 2936: 'onchange="'.$jscall.'" />',
1.281 albertel 2937: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2938: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2939: '</label>');
1.586 raeburn 2940: } elsif ($can_assign{'krb4'}) {
2941: $result .= &mt
2942: ('[_1] Kerberos authenticated with domain [_2] '.
2943: '[_3] Version 4 [_4]',
2944: '<label>'.$authtype,
2945: '</label><input type="text" size="10" name="krbarg" '.
2946: 'value="'.$krbarg.'" '.
2947: 'onchange="'.$jscall.'" />',
2948: '<label><input type="hidden" name="krbver" value="4" />',
2949: '</label>');
2950: } elsif ($can_assign{'krb5'}) {
2951: $result .= &mt
2952: ('[_1] Kerberos authenticated with domain [_2] '.
2953: '[_3] Version 5 [_4]',
2954: '<label>'.$authtype,
2955: '</label><input type="text" size="10" name="krbarg" '.
2956: 'value="'.$krbarg.'" '.
2957: 'onchange="'.$jscall.'" />',
2958: '<label><input type="hidden" name="krbver" value="5" />',
2959: '</label>');
2960: }
1.32 matthew 2961: return $result;
2962: }
2963:
1.1106 raeburn 2964: sub authform_internal {
1.586 raeburn 2965: my %in = (
1.32 matthew 2966: formname => 'document.cu',
2967: kerb_def_dom => 'MSU.EDU',
2968: @_,
2969: );
1.586 raeburn 2970: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2971: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2972: if (defined($in{'curr_authtype'})) {
2973: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2974: if ($can_assign{'int'}) {
1.772 bisitz 2975: $intcheck = 'checked="checked" ';
1.623 raeburn 2976: if (defined($in{'mode'})) {
2977: if ($in{'mode'} eq 'modifyuser') {
2978: $intcheck = '';
2979: }
2980: }
1.591 raeburn 2981: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2982: $intarg = $in{'curr_autharg'};
2983: }
2984: } else {
2985: $result = &mt('Currently internally authenticated.');
2986: return $result;
1.165 raeburn 2987: }
2988: }
1.586 raeburn 2989: } else {
2990: if ($authnum == 1) {
1.784 bisitz 2991: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2992: }
2993: }
2994: if (!$can_assign{'int'}) {
2995: return;
1.587 raeburn 2996: } elsif ($authtype eq '') {
1.591 raeburn 2997: if (defined($in{'mode'})) {
1.587 raeburn 2998: if ($in{'mode'} eq 'modifycourse') {
2999: if ($authnum == 1) {
1.1104 raeburn 3000: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 3001: }
3002: }
3003: }
1.165 raeburn 3004: }
1.586 raeburn 3005: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3006: if ($authtype eq '') {
3007: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
3008: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
3009: }
1.605 bisitz 3010: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 3011: $intarg.'" onchange="'.$jscall.'" />';
3012: $result = &mt
1.144 matthew 3013: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3014: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 3015: $result.="<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 3016: return $result;
3017: }
3018:
1.1104 raeburn 3019: sub authform_local {
1.32 matthew 3020: my %in = (
3021: formname => 'document.cu',
3022: kerb_def_dom => 'MSU.EDU',
3023: @_,
3024: );
1.586 raeburn 3025: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 3026: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 3027: if (defined($in{'curr_authtype'})) {
3028: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3029: if ($can_assign{'loc'}) {
1.772 bisitz 3030: $loccheck = 'checked="checked" ';
1.623 raeburn 3031: if (defined($in{'mode'})) {
3032: if ($in{'mode'} eq 'modifyuser') {
3033: $loccheck = '';
3034: }
3035: }
1.591 raeburn 3036: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3037: $locarg = $in{'curr_autharg'};
3038: }
3039: } else {
3040: $result = &mt('Currently using local (institutional) authentication.');
3041: return $result;
1.165 raeburn 3042: }
3043: }
1.586 raeburn 3044: } else {
3045: if ($authnum == 1) {
1.784 bisitz 3046: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3047: }
3048: }
3049: if (!$can_assign{'loc'}) {
3050: return;
1.587 raeburn 3051: } elsif ($authtype eq '') {
1.591 raeburn 3052: if (defined($in{'mode'})) {
1.587 raeburn 3053: if ($in{'mode'} eq 'modifycourse') {
3054: if ($authnum == 1) {
1.1104 raeburn 3055: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 3056: }
3057: }
3058: }
1.165 raeburn 3059: }
1.586 raeburn 3060: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3061: if ($authtype eq '') {
3062: $authtype = '<input type="radio" name="login" value="loc" '.
3063: $loccheck.' onchange="'.$jscall.'" onclick="'.
3064: $jscall.'" />';
3065: }
3066: $autharg = '<input type="text" size="10" name="locarg" value="'.
3067: $locarg.'" onchange="'.$jscall.'" />';
3068: $result = &mt('[_1] Local Authentication with argument [_2]',
3069: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3070: return $result;
3071: }
3072:
1.1106 raeburn 3073: sub authform_filesystem {
1.32 matthew 3074: my %in = (
3075: formname => 'document.cu',
3076: kerb_def_dom => 'MSU.EDU',
3077: @_,
3078: );
1.586 raeburn 3079: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 3080: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 3081: if (defined($in{'curr_authtype'})) {
3082: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3083: if ($can_assign{'fsys'}) {
1.772 bisitz 3084: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3085: if (defined($in{'mode'})) {
3086: if ($in{'mode'} eq 'modifyuser') {
3087: $fsyscheck = '';
3088: }
3089: }
1.586 raeburn 3090: } else {
3091: $result = &mt('Currently Filesystem Authenticated.');
3092: return $result;
3093: }
3094: }
3095: } else {
3096: if ($authnum == 1) {
1.784 bisitz 3097: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3098: }
3099: }
3100: if (!$can_assign{'fsys'}) {
3101: return;
1.587 raeburn 3102: } elsif ($authtype eq '') {
1.591 raeburn 3103: if (defined($in{'mode'})) {
1.587 raeburn 3104: if ($in{'mode'} eq 'modifycourse') {
3105: if ($authnum == 1) {
1.1104 raeburn 3106: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 3107: }
3108: }
3109: }
1.586 raeburn 3110: }
3111: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3112: if ($authtype eq '') {
3113: $authtype = '<input type="radio" name="login" value="fsys" '.
3114: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
3115: $jscall.'" />';
3116: }
3117: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
3118: ' onchange="'.$jscall.'" />';
3119: $result = &mt
1.144 matthew 3120: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 3121: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 3122: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 3123: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 3124: 'onchange="'.$jscall.'" />');
1.32 matthew 3125: return $result;
3126: }
3127:
1.586 raeburn 3128: sub get_assignable_auth {
3129: my ($dom) = @_;
3130: if ($dom eq '') {
3131: $dom = $env{'request.role.domain'};
3132: }
3133: my %can_assign = (
3134: krb4 => 1,
3135: krb5 => 1,
3136: int => 1,
3137: loc => 1,
3138: );
3139: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3140: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3141: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3142: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3143: my $context;
3144: if ($env{'request.role'} =~ /^au/) {
3145: $context = 'author';
3146: } elsif ($env{'request.role'} =~ /^dc/) {
3147: $context = 'domain';
3148: } elsif ($env{'request.course.id'}) {
3149: $context = 'course';
3150: }
3151: if ($context) {
3152: if (ref($authhash->{$context}) eq 'HASH') {
3153: %can_assign = %{$authhash->{$context}};
3154: }
3155: }
3156: }
3157: }
3158: my $authnum = 0;
3159: foreach my $key (keys(%can_assign)) {
3160: if ($can_assign{$key}) {
3161: $authnum ++;
3162: }
3163: }
3164: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3165: $authnum --;
3166: }
3167: return ($authnum,%can_assign);
3168: }
3169:
1.80 albertel 3170: ###############################################################
3171: ## Get Kerberos Defaults for Domain ##
3172: ###############################################################
3173: ##
3174: ## Returns default kerberos version and an associated argument
3175: ## as listed in file domain.tab. If not listed, provides
3176: ## appropriate default domain and kerberos version.
3177: ##
3178: #-------------------------------------------
3179:
3180: =pod
3181:
1.648 raeburn 3182: =item * &get_kerberos_defaults()
1.80 albertel 3183:
3184: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3185: version and domain. If not found, it defaults to version 4 and the
3186: domain of the server.
1.80 albertel 3187:
1.648 raeburn 3188: =over 4
3189:
1.80 albertel 3190: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3191:
1.648 raeburn 3192: =back
3193:
3194: =back
3195:
1.80 albertel 3196: =cut
3197:
3198: #-------------------------------------------
3199: sub get_kerberos_defaults {
3200: my $domain=shift;
1.641 raeburn 3201: my ($krbdef,$krbdefdom);
3202: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3203: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3204: $krbdef = $domdefaults{'auth_def'};
3205: $krbdefdom = $domdefaults{'auth_arg_def'};
3206: } else {
1.80 albertel 3207: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3208: my $krbdefdom=$1;
3209: $krbdefdom=~tr/a-z/A-Z/;
3210: $krbdef = "krb4";
3211: }
3212: return ($krbdef,$krbdefdom);
3213: }
1.112 bowersj2 3214:
1.32 matthew 3215:
1.46 matthew 3216: ###############################################################
3217: ## Thesaurus Functions ##
3218: ###############################################################
1.20 www 3219:
1.46 matthew 3220: =pod
1.20 www 3221:
1.112 bowersj2 3222: =head1 Thesaurus Functions
3223:
3224: =over 4
3225:
1.648 raeburn 3226: =item * &initialize_keywords()
1.46 matthew 3227:
3228: Initializes the package variable %Keywords if it is empty. Uses the
3229: package variable $thesaurus_db_file.
3230:
3231: =cut
3232:
3233: ###################################################
3234:
3235: sub initialize_keywords {
3236: return 1 if (scalar keys(%Keywords));
3237: # If we are here, %Keywords is empty, so fill it up
3238: # Make sure the file we need exists...
3239: if (! -e $thesaurus_db_file) {
3240: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3241: " failed because it does not exist");
3242: return 0;
3243: }
3244: # Set up the hash as a database
3245: my %thesaurus_db;
3246: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3247: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3248: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3249: $thesaurus_db_file);
3250: return 0;
3251: }
3252: # Get the average number of appearances of a word.
3253: my $avecount = $thesaurus_db{'average.count'};
3254: # Put keywords (those that appear > average) into %Keywords
3255: while (my ($word,$data)=each (%thesaurus_db)) {
3256: my ($count,undef) = split /:/,$data;
3257: $Keywords{$word}++ if ($count > $avecount);
3258: }
3259: untie %thesaurus_db;
3260: # Remove special values from %Keywords.
1.356 albertel 3261: foreach my $value ('total.count','average.count') {
3262: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3263: }
1.46 matthew 3264: return 1;
3265: }
3266:
3267: ###################################################
3268:
3269: =pod
3270:
1.648 raeburn 3271: =item * &keyword($word)
1.46 matthew 3272:
3273: Returns true if $word is a keyword. A keyword is a word that appears more
3274: than the average number of times in the thesaurus database. Calls
3275: &initialize_keywords
3276:
3277: =cut
3278:
3279: ###################################################
1.20 www 3280:
3281: sub keyword {
1.46 matthew 3282: return if (!&initialize_keywords());
3283: my $word=lc(shift());
3284: $word=~s/\W//g;
3285: return exists($Keywords{$word});
1.20 www 3286: }
1.46 matthew 3287:
3288: ###############################################################
3289:
3290: =pod
1.20 www 3291:
1.648 raeburn 3292: =item * &get_related_words()
1.46 matthew 3293:
1.160 matthew 3294: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3295: an array of words. If the keyword is not in the thesaurus, an empty array
3296: will be returned. The order of the words returned is determined by the
3297: database which holds them.
3298:
3299: Uses global $thesaurus_db_file.
3300:
1.1057 foxr 3301:
1.46 matthew 3302: =cut
3303:
3304: ###############################################################
3305: sub get_related_words {
3306: my $keyword = shift;
3307: my %thesaurus_db;
3308: if (! -e $thesaurus_db_file) {
3309: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3310: "failed because the file does not exist");
3311: return ();
3312: }
3313: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3314: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3315: return ();
3316: }
3317: my @Words=();
1.429 www 3318: my $count=0;
1.46 matthew 3319: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3320: # The first element is the number of times
3321: # the word appears. We do not need it now.
1.429 www 3322: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3323: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3324: my $threshold=$mostfrequentcount/10;
3325: foreach my $possibleword (@RelatedWords) {
3326: my ($word,$wordcount)=split(/\,/,$possibleword);
3327: if ($wordcount>$threshold) {
3328: push(@Words,$word);
3329: $count++;
3330: if ($count>10) { last; }
3331: }
1.20 www 3332: }
3333: }
1.46 matthew 3334: untie %thesaurus_db;
3335: return @Words;
1.14 harris41 3336: }
1.1090 foxr 3337: ###############################################################
3338: #
3339: # Spell checking
3340: #
3341:
3342: =pod
3343:
1.1142 raeburn 3344: =back
3345:
1.1090 foxr 3346: =head1 Spell checking
3347:
3348: =over 4
3349:
3350: =item * &check_spelling($wordlist $language)
3351:
3352: Takes a string containing words and feeds it to an external
3353: spellcheck program via a pipeline. Returns a string containing
3354: them mis-spelled words.
3355:
3356: Parameters:
3357:
3358: =over 4
3359:
3360: =item - $wordlist
3361:
3362: String that will be fed into the spellcheck program.
3363:
3364: =item - $language
3365:
3366: Language string that specifies the language for which the spell
3367: check will be performed.
3368:
3369: =back
3370:
3371: =back
3372:
3373: Note: This sub assumes that aspell is installed.
3374:
3375:
3376: =cut
3377:
1.46 matthew 3378:
1.1090 foxr 3379: sub check_spelling {
3380: my ($wordlist, $language) = @_;
1.1091 foxr 3381: my @misspellings;
3382:
3383: # Generate the speller and set the langauge.
3384: # if explicitly selected:
1.1090 foxr 3385:
1.1091 foxr 3386: my $speller = Text::Aspell->new;
1.1090 foxr 3387: if ($language) {
1.1091 foxr 3388: $speller->set_option('lang', $language);
1.1090 foxr 3389: }
3390:
1.1091 foxr 3391: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3392:
1.1091 foxr 3393: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3394:
1.1091 foxr 3395: foreach my $word (@words) {
3396: if(! $speller->check($word)) {
3397: push(@misspellings, $word);
1.1090 foxr 3398: }
3399: }
1.1091 foxr 3400: return join(' ', @misspellings);
3401:
1.1090 foxr 3402: }
3403:
1.61 www 3404: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3405: =pod
3406:
1.112 bowersj2 3407: =head1 User Name Functions
3408:
3409: =over 4
3410:
1.648 raeburn 3411: =item * &plainname($uname,$udom,$first)
1.81 albertel 3412:
1.112 bowersj2 3413: Takes a users logon name and returns it as a string in
1.226 albertel 3414: "first middle last generation" form
3415: if $first is set to 'lastname' then it returns it as
3416: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3417:
3418: =cut
1.61 www 3419:
1.295 www 3420:
1.81 albertel 3421: ###############################################################
1.61 www 3422: sub plainname {
1.226 albertel 3423: my ($uname,$udom,$first)=@_;
1.537 albertel 3424: return if (!defined($uname) || !defined($udom));
1.295 www 3425: my %names=&getnames($uname,$udom);
1.226 albertel 3426: my $name=&Apache::lonnet::format_name($names{'firstname'},
3427: $names{'middlename'},
3428: $names{'lastname'},
3429: $names{'generation'},$first);
3430: $name=~s/^\s+//;
1.62 www 3431: $name=~s/\s+$//;
3432: $name=~s/\s+/ /g;
1.353 albertel 3433: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3434: return $name;
1.61 www 3435: }
1.66 www 3436:
3437: # -------------------------------------------------------------------- Nickname
1.81 albertel 3438: =pod
3439:
1.648 raeburn 3440: =item * &nickname($uname,$udom)
1.81 albertel 3441:
3442: Gets a users name and returns it as a string as
3443:
3444: ""nickname""
1.66 www 3445:
1.81 albertel 3446: if the user has a nickname or
3447:
3448: "first middle last generation"
3449:
3450: if the user does not
3451:
3452: =cut
1.66 www 3453:
3454: sub nickname {
3455: my ($uname,$udom)=@_;
1.537 albertel 3456: return if (!defined($uname) || !defined($udom));
1.295 www 3457: my %names=&getnames($uname,$udom);
1.68 albertel 3458: my $name=$names{'nickname'};
1.66 www 3459: if ($name) {
3460: $name='"'.$name.'"';
3461: } else {
3462: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3463: $names{'lastname'}.' '.$names{'generation'};
3464: $name=~s/\s+$//;
3465: $name=~s/\s+/ /g;
3466: }
3467: return $name;
3468: }
3469:
1.295 www 3470: sub getnames {
3471: my ($uname,$udom)=@_;
1.537 albertel 3472: return if (!defined($uname) || !defined($udom));
1.433 albertel 3473: if ($udom eq 'public' && $uname eq 'public') {
3474: return ('lastname' => &mt('Public'));
3475: }
1.295 www 3476: my $id=$uname.':'.$udom;
3477: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3478: if ($cached) {
3479: return %{$names};
3480: } else {
3481: my %loadnames=&Apache::lonnet::get('environment',
3482: ['firstname','middlename','lastname','generation','nickname'],
3483: $udom,$uname);
3484: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3485: return %loadnames;
3486: }
3487: }
1.61 www 3488:
1.542 raeburn 3489: # -------------------------------------------------------------------- getemails
1.648 raeburn 3490:
1.542 raeburn 3491: =pod
3492:
1.648 raeburn 3493: =item * &getemails($uname,$udom)
1.542 raeburn 3494:
3495: Gets a user's email information and returns it as a hash with keys:
3496: notification, critnotification, permanentemail
3497:
3498: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3499: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3500:
1.648 raeburn 3501:
1.542 raeburn 3502: =cut
3503:
1.648 raeburn 3504:
1.466 albertel 3505: sub getemails {
3506: my ($uname,$udom)=@_;
3507: if ($udom eq 'public' && $uname eq 'public') {
3508: return;
3509: }
1.467 www 3510: if (!$udom) { $udom=$env{'user.domain'}; }
3511: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3512: my $id=$uname.':'.$udom;
3513: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3514: if ($cached) {
3515: return %{$names};
3516: } else {
3517: my %loadnames=&Apache::lonnet::get('environment',
3518: ['notification','critnotification',
3519: 'permanentemail'],
3520: $udom,$uname);
3521: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3522: return %loadnames;
3523: }
3524: }
3525:
1.551 albertel 3526: sub flush_email_cache {
3527: my ($uname,$udom)=@_;
3528: if (!$udom) { $udom =$env{'user.domain'}; }
3529: if (!$uname) { $uname=$env{'user.name'}; }
3530: return if ($udom eq 'public' && $uname eq 'public');
3531: my $id=$uname.':'.$udom;
3532: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3533: }
3534:
1.728 raeburn 3535: # -------------------------------------------------------------------- getlangs
3536:
3537: =pod
3538:
3539: =item * &getlangs($uname,$udom)
3540:
3541: Gets a user's language preference and returns it as a hash with key:
3542: language.
3543:
3544: =cut
3545:
3546:
3547: sub getlangs {
3548: my ($uname,$udom) = @_;
3549: if (!$udom) { $udom =$env{'user.domain'}; }
3550: if (!$uname) { $uname=$env{'user.name'}; }
3551: my $id=$uname.':'.$udom;
3552: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3553: if ($cached) {
3554: return %{$langs};
3555: } else {
3556: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3557: $udom,$uname);
3558: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3559: return %loadlangs;
3560: }
3561: }
3562:
3563: sub flush_langs_cache {
3564: my ($uname,$udom)=@_;
3565: if (!$udom) { $udom =$env{'user.domain'}; }
3566: if (!$uname) { $uname=$env{'user.name'}; }
3567: return if ($udom eq 'public' && $uname eq 'public');
3568: my $id=$uname.':'.$udom;
3569: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3570: }
3571:
1.61 www 3572: # ------------------------------------------------------------------ Screenname
1.81 albertel 3573:
3574: =pod
3575:
1.648 raeburn 3576: =item * &screenname($uname,$udom)
1.81 albertel 3577:
3578: Gets a users screenname and returns it as a string
3579:
3580: =cut
1.61 www 3581:
3582: sub screenname {
3583: my ($uname,$udom)=@_;
1.258 albertel 3584: if ($uname eq $env{'user.name'} &&
3585: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3586: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3587: return $names{'screenname'};
1.62 www 3588: }
3589:
1.212 albertel 3590:
1.802 bisitz 3591: # ------------------------------------------------------------- Confirm Wrapper
3592: =pod
3593:
1.1142 raeburn 3594: =item * &confirmwrapper($message)
1.802 bisitz 3595:
3596: Wrap messages about completion of operation in box
3597:
3598: =cut
3599:
3600: sub confirmwrapper {
3601: my ($message)=@_;
3602: if ($message) {
3603: return "\n".'<div class="LC_confirm_box">'."\n"
3604: .$message."\n"
3605: .'</div>'."\n";
3606: } else {
3607: return $message;
3608: }
3609: }
3610:
1.62 www 3611: # ------------------------------------------------------------- Message Wrapper
3612:
3613: sub messagewrapper {
1.369 www 3614: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3615: return
1.441 albertel 3616: '<a href="/adm/email?compose=individual&'.
3617: 'recname='.$username.'&recdom='.$domain.
3618: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3619: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3620: }
1.802 bisitz 3621:
1.74 www 3622: # --------------------------------------------------------------- Notes Wrapper
3623:
3624: sub noteswrapper {
3625: my ($link,$un,$do)=@_;
3626: return
1.896 amueller 3627: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3628: }
1.802 bisitz 3629:
1.62 www 3630: # ------------------------------------------------------------- Aboutme Wrapper
3631:
3632: sub aboutmewrapper {
1.1070 raeburn 3633: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3634: if (!defined($username) && !defined($domain)) {
3635: return;
3636: }
1.1096 raeburn 3637: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3638: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3639: }
3640:
3641: # ------------------------------------------------------------ Syllabus Wrapper
3642:
3643: sub syllabuswrapper {
1.707 bisitz 3644: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3645: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3646: }
1.14 harris41 3647:
1.802 bisitz 3648: # -----------------------------------------------------------------------------
3649:
1.208 matthew 3650: sub track_student_link {
1.887 raeburn 3651: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3652: my $link ="/adm/trackstudent?";
1.208 matthew 3653: my $title = 'View recent activity';
3654: if (defined($sname) && $sname !~ /^\s*$/ &&
3655: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3656: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3657: $title .= ' of this student';
1.268 albertel 3658: }
1.208 matthew 3659: if (defined($target) && $target !~ /^\s*$/) {
3660: $target = qq{target="$target"};
3661: } else {
3662: $target = '';
3663: }
1.268 albertel 3664: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3665: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3666: $title = &mt($title);
3667: $linktext = &mt($linktext);
1.448 albertel 3668: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3669: &help_open_topic('View_recent_activity');
1.208 matthew 3670: }
3671:
1.781 raeburn 3672: sub slot_reservations_link {
3673: my ($linktext,$sname,$sdom,$target) = @_;
3674: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3675: my $title = 'View slot reservation history';
3676: if (defined($sname) && $sname !~ /^\s*$/ &&
3677: defined($sdom) && $sdom !~ /^\s*$/) {
3678: $link .= "&uname=$sname&udom=$sdom";
3679: $title .= ' of this student';
3680: }
3681: if (defined($target) && $target !~ /^\s*$/) {
3682: $target = qq{target="$target"};
3683: } else {
3684: $target = '';
3685: }
3686: $title = &mt($title);
3687: $linktext = &mt($linktext);
3688: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3689: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3690:
3691: }
3692:
1.508 www 3693: # ===================================================== Display a student photo
3694:
3695:
1.509 albertel 3696: sub student_image_tag {
1.508 www 3697: my ($domain,$user)=@_;
3698: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3699: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3700: return '<img src="'.$imgsrc.'" align="right" />';
3701: } else {
3702: return '';
3703: }
3704: }
3705:
1.112 bowersj2 3706: =pod
3707:
3708: =back
3709:
3710: =head1 Access .tab File Data
3711:
3712: =over 4
3713:
1.648 raeburn 3714: =item * &languageids()
1.112 bowersj2 3715:
3716: returns list of all language ids
3717:
3718: =cut
3719:
1.14 harris41 3720: sub languageids {
1.16 harris41 3721: return sort(keys(%language));
1.14 harris41 3722: }
3723:
1.112 bowersj2 3724: =pod
3725:
1.648 raeburn 3726: =item * &languagedescription()
1.112 bowersj2 3727:
3728: returns description of a specified language id
3729:
3730: =cut
3731:
1.14 harris41 3732: sub languagedescription {
1.125 www 3733: my $code=shift;
3734: return ($supported_language{$code}?'* ':'').
3735: $language{$code}.
1.126 www 3736: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3737: }
3738:
1.1048 foxr 3739: =pod
3740:
3741: =item * &plainlanguagedescription
3742:
3743: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3744: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3745:
3746: =cut
3747:
1.145 www 3748: sub plainlanguagedescription {
3749: my $code=shift;
3750: return $language{$code};
3751: }
3752:
1.1048 foxr 3753: =pod
3754:
3755: =item * &supportedlanguagecode
3756:
3757: Returns the supported language code (e.g. sptutf maps to pt) given a language
3758: code.
3759:
3760: =cut
3761:
1.145 www 3762: sub supportedlanguagecode {
3763: my $code=shift;
3764: return $supported_language{$code};
1.97 www 3765: }
3766:
1.112 bowersj2 3767: =pod
3768:
1.1048 foxr 3769: =item * &latexlanguage()
3770:
3771: Given a language key code returns the correspondnig language to use
3772: to select the correct hyphenation on LaTeX printouts. This is undef if there
3773: is no supported hyphenation for the language code.
3774:
3775: =cut
3776:
3777: sub latexlanguage {
3778: my $code = shift;
3779: return $latex_language{$code};
3780: }
3781:
3782: =pod
3783:
3784: =item * &latexhyphenation()
3785:
3786: Same as above but what's supplied is the language as it might be stored
3787: in the metadata.
3788:
3789: =cut
3790:
3791: sub latexhyphenation {
3792: my $key = shift;
3793: return $latex_language_bykey{$key};
3794: }
3795:
3796: =pod
3797:
1.648 raeburn 3798: =item * ©rightids()
1.112 bowersj2 3799:
3800: returns list of all copyrights
3801:
3802: =cut
3803:
3804: sub copyrightids {
3805: return sort(keys(%cprtag));
3806: }
3807:
3808: =pod
3809:
1.648 raeburn 3810: =item * ©rightdescription()
1.112 bowersj2 3811:
3812: returns description of a specified copyright id
3813:
3814: =cut
3815:
3816: sub copyrightdescription {
1.166 www 3817: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3818: }
1.197 matthew 3819:
3820: =pod
3821:
1.648 raeburn 3822: =item * &source_copyrightids()
1.192 taceyjo1 3823:
3824: returns list of all source copyrights
3825:
3826: =cut
3827:
3828: sub source_copyrightids {
3829: return sort(keys(%scprtag));
3830: }
3831:
3832: =pod
3833:
1.648 raeburn 3834: =item * &source_copyrightdescription()
1.192 taceyjo1 3835:
3836: returns description of a specified source copyright id
3837:
3838: =cut
3839:
3840: sub source_copyrightdescription {
3841: return &mt($scprtag{shift(@_)});
3842: }
1.112 bowersj2 3843:
3844: =pod
3845:
1.648 raeburn 3846: =item * &filecategories()
1.112 bowersj2 3847:
3848: returns list of all file categories
3849:
3850: =cut
3851:
3852: sub filecategories {
3853: return sort(keys(%category_extensions));
3854: }
3855:
3856: =pod
3857:
1.648 raeburn 3858: =item * &filecategorytypes()
1.112 bowersj2 3859:
3860: returns list of file types belonging to a given file
3861: category
3862:
3863: =cut
3864:
3865: sub filecategorytypes {
1.356 albertel 3866: my ($cat) = @_;
3867: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3868: }
3869:
3870: =pod
3871:
1.648 raeburn 3872: =item * &fileembstyle()
1.112 bowersj2 3873:
3874: returns embedding style for a specified file type
3875:
3876: =cut
3877:
3878: sub fileembstyle {
3879: return $fe{lc(shift(@_))};
1.169 www 3880: }
3881:
1.351 www 3882: sub filemimetype {
3883: return $fm{lc(shift(@_))};
3884: }
3885:
1.169 www 3886:
3887: sub filecategoryselect {
3888: my ($name,$value)=@_;
1.189 matthew 3889: return &select_form($value,$name,
1.970 raeburn 3890: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3891: }
3892:
3893: =pod
3894:
1.648 raeburn 3895: =item * &filedescription()
1.112 bowersj2 3896:
3897: returns description for a specified file type
3898:
3899: =cut
3900:
3901: sub filedescription {
1.188 matthew 3902: my $file_description = $fd{lc(shift())};
3903: $file_description =~ s:([\[\]]):~$1:g;
3904: return &mt($file_description);
1.112 bowersj2 3905: }
3906:
3907: =pod
3908:
1.648 raeburn 3909: =item * &filedescriptionex()
1.112 bowersj2 3910:
3911: returns description for a specified file type with
3912: extra formatting
3913:
3914: =cut
3915:
3916: sub filedescriptionex {
3917: my $ex=shift;
1.188 matthew 3918: my $file_description = $fd{lc($ex)};
3919: $file_description =~ s:([\[\]]):~$1:g;
3920: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3921: }
3922:
3923: # End of .tab access
3924: =pod
3925:
3926: =back
3927:
3928: =cut
3929:
3930: # ------------------------------------------------------------------ File Types
3931: sub fileextensions {
3932: return sort(keys(%fe));
3933: }
3934:
1.97 www 3935: # ----------------------------------------------------------- Display Languages
3936: # returns a hash with all desired display languages
3937: #
3938:
3939: sub display_languages {
3940: my %languages=();
1.695 raeburn 3941: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3942: $languages{$lang}=1;
1.97 www 3943: }
3944: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3945: if ($env{'form.displaylanguage'}) {
1.356 albertel 3946: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3947: $languages{$lang}=1;
1.97 www 3948: }
3949: }
3950: return %languages;
1.14 harris41 3951: }
3952:
1.582 albertel 3953: sub languages {
3954: my ($possible_langs) = @_;
1.695 raeburn 3955: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3956: if (!ref($possible_langs)) {
3957: if( wantarray ) {
3958: return @preferred_langs;
3959: } else {
3960: return $preferred_langs[0];
3961: }
3962: }
3963: my %possibilities = map { $_ => 1 } (@$possible_langs);
3964: my @preferred_possibilities;
3965: foreach my $preferred_lang (@preferred_langs) {
3966: if (exists($possibilities{$preferred_lang})) {
3967: push(@preferred_possibilities, $preferred_lang);
3968: }
3969: }
3970: if( wantarray ) {
3971: return @preferred_possibilities;
3972: }
3973: return $preferred_possibilities[0];
3974: }
3975:
1.742 raeburn 3976: sub user_lang {
3977: my ($touname,$toudom,$fromcid) = @_;
3978: my @userlangs;
3979: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3980: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3981: $env{'course.'.$fromcid.'.languages'}));
3982: } else {
3983: my %langhash = &getlangs($touname,$toudom);
3984: if ($langhash{'languages'} ne '') {
3985: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3986: } else {
3987: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3988: if ($domdefs{'lang_def'} ne '') {
3989: @userlangs = ($domdefs{'lang_def'});
3990: }
3991: }
3992: }
3993: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3994: my $user_lh = Apache::localize->get_handle(@languages);
3995: return $user_lh;
3996: }
3997:
3998:
1.112 bowersj2 3999: ###############################################################
4000: ## Student Answer Attempts ##
4001: ###############################################################
4002:
4003: =pod
4004:
4005: =head1 Alternate Problem Views
4006:
4007: =over 4
4008:
1.648 raeburn 4009: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4010: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4011:
4012: Return string with previous attempt on problem. Arguments:
4013:
4014: =over 4
4015:
4016: =item * $symb: Problem, including path
4017:
4018: =item * $username: username of the desired student
4019:
4020: =item * $domain: domain of the desired student
1.14 harris41 4021:
1.112 bowersj2 4022: =item * $course: Course ID
1.14 harris41 4023:
1.112 bowersj2 4024: =item * $getattempt: Leave blank for all attempts, otherwise put
4025: something
1.14 harris41 4026:
1.112 bowersj2 4027: =item * $regexp: if string matches this regexp, the string will be
4028: sent to $gradesub
1.14 harris41 4029:
1.112 bowersj2 4030: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4031:
1.1199 raeburn 4032: =item * $usec: section of the desired student
4033:
4034: =item * $identifier: counter for student (multiple students one problem) or
4035: problem (one student; whole sequence).
4036:
1.112 bowersj2 4037: =back
1.14 harris41 4038:
1.112 bowersj2 4039: The output string is a table containing all desired attempts, if any.
1.16 harris41 4040:
1.112 bowersj2 4041: =cut
1.1 albertel 4042:
4043: sub get_previous_attempt {
1.1199 raeburn 4044: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4045: my $prevattempts='';
1.43 ng 4046: no strict 'refs';
1.1 albertel 4047: if ($symb) {
1.3 albertel 4048: my (%returnhash)=
4049: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4050: if ($returnhash{'version'}) {
4051: my %lasthash=();
4052: my $version;
4053: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4054: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4055: if ($key =~ /\.rawrndseed$/) {
4056: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4057: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4058: } else {
4059: $lasthash{$key}=$returnhash{$version.':'.$key};
4060: }
1.19 harris41 4061: }
1.1 albertel 4062: }
1.596 albertel 4063: $prevattempts=&start_data_table().&start_data_table_header_row();
4064: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4065: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4066: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4067: foreach my $key (sort(keys(%lasthash))) {
4068: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4069: if ($#parts > 0) {
1.31 albertel 4070: my $data=$parts[-1];
1.989 raeburn 4071: next if ($data eq 'foilorder');
1.31 albertel 4072: pop(@parts);
1.1010 www 4073: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4074: if ($data eq 'type') {
4075: unless ($showsurv) {
4076: my $id = join(',',@parts);
4077: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4078: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4079: $lasthidden{$ign.'.'.$id} = 1;
4080: }
1.945 raeburn 4081: }
1.1199 raeburn 4082: if ($identifier ne '') {
4083: my $id = join(',',@parts);
4084: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4085: $domain,$username,$usec,undef,$course) =~ /^no/) {
4086: $hidestatus{$ign.'.'.$id} = 1;
4087: }
4088: }
4089: } elsif ($data eq 'regrader') {
4090: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4091: my $id = join(',',@parts);
4092: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4093: }
1.1010 www 4094: }
1.31 albertel 4095: } else {
1.41 ng 4096: if ($#parts == 0) {
4097: $prevattempts.='<th>'.$parts[0].'</th>';
4098: } else {
4099: $prevattempts.='<th>'.$ign.'</th>';
4100: }
1.31 albertel 4101: }
1.16 harris41 4102: }
1.596 albertel 4103: $prevattempts.=&end_data_table_header_row();
1.40 ng 4104: if ($getattempt eq '') {
1.1199 raeburn 4105: my (%solved,%resets,%probstatus);
1.1200 raeburn 4106: if (($identifier ne '') && (keys(%regraded) > 0)) {
4107: for ($version=1;$version<=$returnhash{'version'};$version++) {
4108: foreach my $id (keys(%regraded)) {
4109: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4110: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4111: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4112: push(@{$resets{$id}},$version);
1.1199 raeburn 4113: }
4114: }
4115: }
1.1200 raeburn 4116: }
4117: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4118: my (@hidden,@unsolved);
1.945 raeburn 4119: if (%typeparts) {
4120: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4121: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4122: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4123: push(@hidden,$id);
1.1199 raeburn 4124: } elsif ($identifier ne '') {
4125: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4126: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4127: ($hidestatus{$id})) {
1.1200 raeburn 4128: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4129: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4130: push(@{$solved{$id}},$version);
4131: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4132: (ref($solved{$id}) eq 'ARRAY')) {
4133: my $skip;
4134: if (ref($resets{$id}) eq 'ARRAY') {
4135: foreach my $reset (@{$resets{$id}}) {
4136: if ($reset > $solved{$id}[-1]) {
4137: $skip=1;
4138: last;
4139: }
4140: }
4141: }
4142: unless ($skip) {
4143: my ($ign,$partslist) = split(/\./,$id,2);
4144: push(@unsolved,$partslist);
4145: }
4146: }
4147: }
1.945 raeburn 4148: }
4149: }
4150: }
4151: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4152: '<td>'.&mt('Transaction [_1]',$version);
4153: if (@unsolved) {
4154: $prevattempts .= '<span class="LC_nobreak"><label>'.
4155: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4156: &mt('Hide').'</label></span>';
4157: }
4158: $prevattempts .= '</td>';
1.945 raeburn 4159: if (@hidden) {
4160: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4161: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4162: my $hide;
4163: foreach my $id (@hidden) {
4164: if ($key =~ /^\Q$id\E/) {
4165: $hide = 1;
4166: last;
4167: }
4168: }
4169: if ($hide) {
4170: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4171: if (($data eq 'award') || ($data eq 'awarddetail')) {
4172: my $value = &format_previous_attempt_value($key,
4173: $returnhash{$version.':'.$key});
1.1173 kruse 4174: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4175: } else {
4176: $prevattempts.='<td> </td>';
4177: }
4178: } else {
4179: if ($key =~ /\./) {
1.1212 raeburn 4180: my $value = $returnhash{$version.':'.$key};
4181: if ($key =~ /\.rndseed$/) {
4182: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4183: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4184: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4185: }
4186: }
4187: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4188: ' </td>';
1.945 raeburn 4189: } else {
4190: $prevattempts.='<td> </td>';
4191: }
4192: }
4193: }
4194: } else {
4195: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4196: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4197: my $value = $returnhash{$version.':'.$key};
4198: if ($key =~ /\.rndseed$/) {
4199: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4200: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4201: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4202: }
4203: }
4204: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4205: ' </td>';
1.945 raeburn 4206: }
4207: }
4208: $prevattempts.=&end_data_table_row();
1.40 ng 4209: }
1.1 albertel 4210: }
1.945 raeburn 4211: my @currhidden = keys(%lasthidden);
1.596 albertel 4212: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4213: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4214: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4215: if (%typeparts) {
4216: my $hidden;
4217: foreach my $id (@currhidden) {
4218: if ($key =~ /^\Q$id\E/) {
4219: $hidden = 1;
4220: last;
4221: }
4222: }
4223: if ($hidden) {
4224: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4225: if (($data eq 'award') || ($data eq 'awarddetail')) {
4226: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4227: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4228: $value = &$gradesub($value);
4229: }
1.1173 kruse 4230: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4231: } else {
4232: $prevattempts.='<td> </td>';
4233: }
4234: } else {
4235: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4236: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4237: $value = &$gradesub($value);
4238: }
1.1173 kruse 4239: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4240: }
4241: } else {
4242: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4243: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4244: $value = &$gradesub($value);
4245: }
1.1173 kruse 4246: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4247: }
1.16 harris41 4248: }
1.596 albertel 4249: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4250: } else {
1.596 albertel 4251: $prevattempts=
4252: &start_data_table().&start_data_table_row().
4253: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4254: &end_data_table_row().&end_data_table();
1.1 albertel 4255: }
4256: } else {
1.596 albertel 4257: $prevattempts=
4258: &start_data_table().&start_data_table_row().
4259: '<td>'.&mt('No data.').'</td>'.
4260: &end_data_table_row().&end_data_table();
1.1 albertel 4261: }
1.10 albertel 4262: }
4263:
1.581 albertel 4264: sub format_previous_attempt_value {
4265: my ($key,$value) = @_;
1.1011 www 4266: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4267: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4268: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4269: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4270: } elsif ($key =~ /answerstring$/) {
4271: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4272: my @answer = %answers;
4273: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4274: my @anskeys = sort(keys(%answers));
4275: if (@anskeys == 1) {
4276: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4277: if ($answer =~ m{\0}) {
4278: $answer =~ s{\0}{,}g;
1.988 raeburn 4279: }
4280: my $tag_internal_answer_name = 'INTERNAL';
4281: if ($anskeys[0] eq $tag_internal_answer_name) {
4282: $value = $answer;
4283: } else {
4284: $value = $anskeys[0].'='.$answer;
4285: }
4286: } else {
4287: foreach my $ans (@anskeys) {
4288: my $answer = $answers{$ans};
1.1001 raeburn 4289: if ($answer =~ m{\0}) {
4290: $answer =~ s{\0}{,}g;
1.988 raeburn 4291: }
4292: $value .= $ans.'='.$answer.'<br />';;
4293: }
4294: }
1.581 albertel 4295: } else {
1.1173 kruse 4296: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4297: }
4298: return $value;
4299: }
4300:
4301:
1.107 albertel 4302: sub relative_to_absolute {
4303: my ($url,$output)=@_;
4304: my $parser=HTML::TokeParser->new(\$output);
4305: my $token;
4306: my $thisdir=$url;
4307: my @rlinks=();
4308: while ($token=$parser->get_token) {
4309: if ($token->[0] eq 'S') {
4310: if ($token->[1] eq 'a') {
4311: if ($token->[2]->{'href'}) {
4312: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4313: }
4314: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4315: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4316: } elsif ($token->[1] eq 'base') {
4317: $thisdir=$token->[2]->{'href'};
4318: }
4319: }
4320: }
4321: $thisdir=~s-/[^/]*$--;
1.356 albertel 4322: foreach my $link (@rlinks) {
1.726 raeburn 4323: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4324: ($link=~/^\//) ||
4325: ($link=~/^javascript:/i) ||
4326: ($link=~/^mailto:/i) ||
4327: ($link=~/^\#/)) {
4328: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4329: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4330: }
4331: }
4332: # -------------------------------------------------- Deal with Applet codebases
4333: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4334: return $output;
4335: }
4336:
1.112 bowersj2 4337: =pod
4338:
1.648 raeburn 4339: =item * &get_student_view()
1.112 bowersj2 4340:
4341: show a snapshot of what student was looking at
4342:
4343: =cut
4344:
1.10 albertel 4345: sub get_student_view {
1.186 albertel 4346: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4347: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4348: my (%form);
1.10 albertel 4349: my @elements=('symb','courseid','domain','username');
4350: foreach my $element (@elements) {
1.186 albertel 4351: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4352: }
1.186 albertel 4353: if (defined($moreenv)) {
4354: %form=(%form,%{$moreenv});
4355: }
1.236 albertel 4356: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4357: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4358: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4359: $userview=~s/\<body[^\>]*\>//gi;
4360: $userview=~s/\<\/body\>//gi;
4361: $userview=~s/\<html\>//gi;
4362: $userview=~s/\<\/html\>//gi;
4363: $userview=~s/\<head\>//gi;
4364: $userview=~s/\<\/head\>//gi;
4365: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4366: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4367: if (wantarray) {
4368: return ($userview,$response);
4369: } else {
4370: return $userview;
4371: }
4372: }
4373:
4374: sub get_student_view_with_retries {
4375: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4376:
4377: my $ok = 0; # True if we got a good response.
4378: my $content;
4379: my $response;
4380:
4381: # Try to get the student_view done. within the retries count:
4382:
4383: do {
4384: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4385: $ok = $response->is_success;
4386: if (!$ok) {
4387: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4388: }
4389: $retries--;
4390: } while (!$ok && ($retries > 0));
4391:
4392: if (!$ok) {
4393: $content = ''; # On error return an empty content.
4394: }
1.651 www 4395: if (wantarray) {
4396: return ($content, $response);
4397: } else {
4398: return $content;
4399: }
1.11 albertel 4400: }
4401:
1.112 bowersj2 4402: =pod
4403:
1.648 raeburn 4404: =item * &get_student_answers()
1.112 bowersj2 4405:
4406: show a snapshot of how student was answering problem
4407:
4408: =cut
4409:
1.11 albertel 4410: sub get_student_answers {
1.100 sakharuk 4411: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4412: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4413: my (%moreenv);
1.11 albertel 4414: my @elements=('symb','courseid','domain','username');
4415: foreach my $element (@elements) {
1.186 albertel 4416: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4417: }
1.186 albertel 4418: $moreenv{'grade_target'}='answer';
4419: %moreenv=(%form,%moreenv);
1.497 raeburn 4420: $feedurl = &Apache::lonnet::clutter($feedurl);
4421: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4422: return $userview;
1.1 albertel 4423: }
1.116 albertel 4424:
4425: =pod
4426:
4427: =item * &submlink()
4428:
1.242 albertel 4429: Inputs: $text $uname $udom $symb $target
1.116 albertel 4430:
4431: Returns: A link to grades.pm such as to see the SUBM view of a student
4432:
4433: =cut
4434:
4435: ###############################################
4436: sub submlink {
1.242 albertel 4437: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4438: if (!($uname && $udom)) {
4439: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4440: &Apache::lonnet::whichuser($symb);
1.116 albertel 4441: if (!$symb) { $symb=$cursymb; }
4442: }
1.254 matthew 4443: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4444: $symb=&escape($symb);
1.960 bisitz 4445: if ($target) { $target=" target=\"$target\""; }
4446: return
4447: '<a href="/adm/grades?command=submission'.
4448: '&symb='.$symb.
4449: '&student='.$uname.
4450: '&userdom='.$udom.'"'.
4451: $target.'>'.$text.'</a>';
1.242 albertel 4452: }
4453: ##############################################
4454:
4455: =pod
4456:
4457: =item * &pgrdlink()
4458:
4459: Inputs: $text $uname $udom $symb $target
4460:
4461: Returns: A link to grades.pm such as to see the PGRD view of a student
4462:
4463: =cut
4464:
4465: ###############################################
4466: sub pgrdlink {
4467: my $link=&submlink(@_);
4468: $link=~s/(&command=submission)/$1&showgrading=yes/;
4469: return $link;
4470: }
4471: ##############################################
4472:
4473: =pod
4474:
4475: =item * &pprmlink()
4476:
4477: Inputs: $text $uname $udom $symb $target
4478:
4479: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4480: student and a specific resource
1.242 albertel 4481:
4482: =cut
4483:
4484: ###############################################
4485: sub pprmlink {
4486: my ($text,$uname,$udom,$symb,$target)=@_;
4487: if (!($uname && $udom)) {
4488: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4489: &Apache::lonnet::whichuser($symb);
1.242 albertel 4490: if (!$symb) { $symb=$cursymb; }
4491: }
1.254 matthew 4492: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4493: $symb=&escape($symb);
1.242 albertel 4494: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4495: return '<a href="/adm/parmset?command=set&'.
4496: 'symb='.$symb.'&uname='.$uname.
4497: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4498: }
4499: ##############################################
1.37 matthew 4500:
1.112 bowersj2 4501: =pod
4502:
4503: =back
4504:
4505: =cut
4506:
1.37 matthew 4507: ###############################################
1.51 www 4508:
4509:
4510: sub timehash {
1.687 raeburn 4511: my ($thistime) = @_;
4512: my $timezone = &Apache::lonlocal::gettimezone();
4513: my $dt = DateTime->from_epoch(epoch => $thistime)
4514: ->set_time_zone($timezone);
4515: my $wday = $dt->day_of_week();
4516: if ($wday == 7) { $wday = 0; }
4517: return ( 'second' => $dt->second(),
4518: 'minute' => $dt->minute(),
4519: 'hour' => $dt->hour(),
4520: 'day' => $dt->day_of_month(),
4521: 'month' => $dt->month(),
4522: 'year' => $dt->year(),
4523: 'weekday' => $wday,
4524: 'dayyear' => $dt->day_of_year(),
4525: 'dlsav' => $dt->is_dst() );
1.51 www 4526: }
4527:
1.370 www 4528: sub utc_string {
4529: my ($date)=@_;
1.371 www 4530: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4531: }
4532:
1.51 www 4533: sub maketime {
4534: my %th=@_;
1.687 raeburn 4535: my ($epoch_time,$timezone,$dt);
4536: $timezone = &Apache::lonlocal::gettimezone();
4537: eval {
4538: $dt = DateTime->new( year => $th{'year'},
4539: month => $th{'month'},
4540: day => $th{'day'},
4541: hour => $th{'hour'},
4542: minute => $th{'minute'},
4543: second => $th{'second'},
4544: time_zone => $timezone,
4545: );
4546: };
4547: if (!$@) {
4548: $epoch_time = $dt->epoch;
4549: if ($epoch_time) {
4550: return $epoch_time;
4551: }
4552: }
1.51 www 4553: return POSIX::mktime(
4554: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4555: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4556: }
4557:
4558: #########################################
1.51 www 4559:
4560: sub findallcourses {
1.482 raeburn 4561: my ($roles,$uname,$udom) = @_;
1.355 albertel 4562: my %roles;
4563: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4564: my %courses;
1.51 www 4565: my $now=time;
1.482 raeburn 4566: if (!defined($uname)) {
4567: $uname = $env{'user.name'};
4568: }
4569: if (!defined($udom)) {
4570: $udom = $env{'user.domain'};
4571: }
4572: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4573: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4574: if (!%roles) {
4575: %roles = (
4576: cc => 1,
1.907 raeburn 4577: co => 1,
1.482 raeburn 4578: in => 1,
4579: ep => 1,
4580: ta => 1,
4581: cr => 1,
4582: st => 1,
4583: );
4584: }
4585: foreach my $entry (keys(%roleshash)) {
4586: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4587: if ($trole =~ /^cr/) {
4588: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4589: } else {
4590: next if (!exists($roles{$trole}));
4591: }
4592: if ($tend) {
4593: next if ($tend < $now);
4594: }
4595: if ($tstart) {
4596: next if ($tstart > $now);
4597: }
1.1058 raeburn 4598: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4599: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4600: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4601: if ($secpart eq '') {
4602: ($cnum,$role) = split(/_/,$cnumpart);
4603: $sec = 'none';
1.1058 raeburn 4604: $value .= $cnum.'/';
1.482 raeburn 4605: } else {
4606: $cnum = $cnumpart;
4607: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4608: $value .= $cnum.'/'.$sec;
4609: }
4610: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4611: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4612: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4613: }
4614: } else {
4615: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4616: }
1.482 raeburn 4617: }
4618: } else {
4619: foreach my $key (keys(%env)) {
1.483 albertel 4620: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4621: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4622: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4623: next if ($role eq 'ca' || $role eq 'aa');
4624: next if (%roles && !exists($roles{$role}));
4625: my ($starttime,$endtime)=split(/\./,$env{$key});
4626: my $active=1;
4627: if ($starttime) {
4628: if ($now<$starttime) { $active=0; }
4629: }
4630: if ($endtime) {
4631: if ($now>$endtime) { $active=0; }
4632: }
4633: if ($active) {
1.1058 raeburn 4634: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4635: if ($sec eq '') {
4636: $sec = 'none';
1.1058 raeburn 4637: } else {
4638: $value .= $sec;
4639: }
4640: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4641: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4642: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4643: }
4644: } else {
4645: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4646: }
1.474 raeburn 4647: }
4648: }
1.51 www 4649: }
4650: }
1.474 raeburn 4651: return %courses;
1.51 www 4652: }
1.37 matthew 4653:
1.54 www 4654: ###############################################
1.474 raeburn 4655:
4656: sub blockcheck {
1.1189 raeburn 4657: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4658:
1.1189 raeburn 4659: if (defined($udom) && defined($uname)) {
4660: # If uname and udom are for a course, check for blocks in the course.
4661: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4662: my ($startblock,$endblock,$triggerblock) =
4663: &get_blocks($setters,$activity,$udom,$uname,$url);
4664: return ($startblock,$endblock,$triggerblock);
4665: }
4666: } else {
1.490 raeburn 4667: $udom = $env{'user.domain'};
4668: $uname = $env{'user.name'};
4669: }
4670:
1.502 raeburn 4671: my $startblock = 0;
4672: my $endblock = 0;
1.1062 raeburn 4673: my $triggerblock = '';
1.482 raeburn 4674: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4675:
1.490 raeburn 4676: # If uname is for a user, and activity is course-specific, i.e.,
4677: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4678:
1.490 raeburn 4679: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1189 raeburn 4680: $activity eq 'groups' || $activity eq 'printout') &&
4681: ($env{'request.course.id'})) {
1.490 raeburn 4682: foreach my $key (keys(%live_courses)) {
4683: if ($key ne $env{'request.course.id'}) {
4684: delete($live_courses{$key});
4685: }
4686: }
4687: }
4688:
4689: my $otheruser = 0;
4690: my %own_courses;
4691: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4692: # Resource belongs to user other than current user.
4693: $otheruser = 1;
4694: # Gather courses for current user
4695: %own_courses =
4696: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4697: }
4698:
4699: # Gather active course roles - course coordinator, instructor,
4700: # exam proctor, ta, student, or custom role.
1.474 raeburn 4701:
4702: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4703: my ($cdom,$cnum);
4704: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4705: $cdom = $env{'course.'.$course.'.domain'};
4706: $cnum = $env{'course.'.$course.'.num'};
4707: } else {
1.490 raeburn 4708: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4709: }
4710: my $no_ownblock = 0;
4711: my $no_userblock = 0;
1.533 raeburn 4712: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4713: # Check if current user has 'evb' priv for this
4714: if (defined($own_courses{$course})) {
4715: foreach my $sec (keys(%{$own_courses{$course}})) {
4716: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4717: if ($sec ne 'none') {
4718: $checkrole .= '/'.$sec;
4719: }
4720: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4721: $no_ownblock = 1;
4722: last;
4723: }
4724: }
4725: }
4726: # if they have 'evb' priv and are currently not playing student
4727: next if (($no_ownblock) &&
4728: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4729: }
1.474 raeburn 4730: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4731: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4732: if ($sec ne 'none') {
1.482 raeburn 4733: $checkrole .= '/'.$sec;
1.474 raeburn 4734: }
1.490 raeburn 4735: if ($otheruser) {
4736: # Resource belongs to user other than current user.
4737: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4738: my (%allroles,%userroles);
4739: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4740: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4741: my ($trole,$tdom,$tnum,$tsec);
4742: if ($entry =~ /^cr/) {
4743: ($trole,$tdom,$tnum,$tsec) =
4744: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4745: } else {
4746: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4747: }
4748: my ($spec,$area,$trest);
4749: $area = '/'.$tdom.'/'.$tnum;
4750: $trest = $tnum;
4751: if ($tsec ne '') {
4752: $area .= '/'.$tsec;
4753: $trest .= '/'.$tsec;
4754: }
4755: $spec = $trole.'.'.$area;
4756: if ($trole =~ /^cr/) {
4757: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4758: $tdom,$spec,$trest,$area);
4759: } else {
4760: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4761: $tdom,$spec,$trest,$area);
4762: }
4763: }
4764: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4765: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4766: if ($1) {
4767: $no_userblock = 1;
4768: last;
4769: }
1.486 raeburn 4770: }
4771: }
1.490 raeburn 4772: } else {
4773: # Resource belongs to current user
4774: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4775: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4776: $no_ownblock = 1;
4777: last;
4778: }
1.474 raeburn 4779: }
4780: }
4781: # if they have the evb priv and are currently not playing student
1.482 raeburn 4782: next if (($no_ownblock) &&
1.491 albertel 4783: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4784: next if ($no_userblock);
1.474 raeburn 4785:
1.866 kalberla 4786: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4787: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4788:
1.1062 raeburn 4789: my ($start,$end,$trigger) =
4790: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4791: if (($start != 0) &&
4792: (($startblock == 0) || ($startblock > $start))) {
4793: $startblock = $start;
1.1062 raeburn 4794: if ($trigger ne '') {
4795: $triggerblock = $trigger;
4796: }
1.502 raeburn 4797: }
4798: if (($end != 0) &&
4799: (($endblock == 0) || ($endblock < $end))) {
4800: $endblock = $end;
1.1062 raeburn 4801: if ($trigger ne '') {
4802: $triggerblock = $trigger;
4803: }
1.502 raeburn 4804: }
1.490 raeburn 4805: }
1.1062 raeburn 4806: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4807: }
4808:
4809: sub get_blocks {
1.1062 raeburn 4810: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4811: my $startblock = 0;
4812: my $endblock = 0;
1.1062 raeburn 4813: my $triggerblock = '';
1.490 raeburn 4814: my $course = $cdom.'_'.$cnum;
4815: $setters->{$course} = {};
4816: $setters->{$course}{'staff'} = [];
4817: $setters->{$course}{'times'} = [];
1.1062 raeburn 4818: $setters->{$course}{'triggers'} = [];
4819: my (@blockers,%triggered);
4820: my $now = time;
4821: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4822: if ($activity eq 'docs') {
4823: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4824: foreach my $block (@blockers) {
4825: if ($block =~ /^firstaccess____(.+)$/) {
4826: my $item = $1;
4827: my $type = 'map';
4828: my $timersymb = $item;
4829: if ($item eq 'course') {
4830: $type = 'course';
4831: } elsif ($item =~ /___\d+___/) {
4832: $type = 'resource';
4833: } else {
4834: $timersymb = &Apache::lonnet::symbread($item);
4835: }
4836: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4837: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4838: $triggered{$block} = {
4839: start => $start,
4840: end => $end,
4841: type => $type,
4842: };
4843: }
4844: }
4845: } else {
4846: foreach my $block (keys(%commblocks)) {
4847: if ($block =~ m/^(\d+)____(\d+)$/) {
4848: my ($start,$end) = ($1,$2);
4849: if ($start <= time && $end >= time) {
4850: if (ref($commblocks{$block}) eq 'HASH') {
4851: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4852: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4853: unless(grep(/^\Q$block\E$/,@blockers)) {
4854: push(@blockers,$block);
4855: }
4856: }
4857: }
4858: }
4859: }
4860: } elsif ($block =~ /^firstaccess____(.+)$/) {
4861: my $item = $1;
4862: my $timersymb = $item;
4863: my $type = 'map';
4864: if ($item eq 'course') {
4865: $type = 'course';
4866: } elsif ($item =~ /___\d+___/) {
4867: $type = 'resource';
4868: } else {
4869: $timersymb = &Apache::lonnet::symbread($item);
4870: }
4871: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4872: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4873: if ($start && $end) {
4874: if (($start <= time) && ($end >= time)) {
4875: unless (grep(/^\Q$block\E$/,@blockers)) {
4876: push(@blockers,$block);
4877: $triggered{$block} = {
4878: start => $start,
4879: end => $end,
4880: type => $type,
4881: };
4882: }
4883: }
1.490 raeburn 4884: }
1.1062 raeburn 4885: }
4886: }
4887: }
4888: foreach my $blocker (@blockers) {
4889: my ($staff_name,$staff_dom,$title,$blocks) =
4890: &parse_block_record($commblocks{$blocker});
4891: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4892: my ($start,$end,$triggertype);
4893: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4894: ($start,$end) = ($1,$2);
4895: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4896: $start = $triggered{$blocker}{'start'};
4897: $end = $triggered{$blocker}{'end'};
4898: $triggertype = $triggered{$blocker}{'type'};
4899: }
4900: if ($start) {
4901: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4902: if ($triggertype) {
4903: push(@{$$setters{$course}{'triggers'}},$triggertype);
4904: } else {
4905: push(@{$$setters{$course}{'triggers'}},0);
4906: }
4907: if ( ($startblock == 0) || ($startblock > $start) ) {
4908: $startblock = $start;
4909: if ($triggertype) {
4910: $triggerblock = $blocker;
1.474 raeburn 4911: }
4912: }
1.1062 raeburn 4913: if ( ($endblock == 0) || ($endblock < $end) ) {
4914: $endblock = $end;
4915: if ($triggertype) {
4916: $triggerblock = $blocker;
4917: }
4918: }
1.474 raeburn 4919: }
4920: }
1.1062 raeburn 4921: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4922: }
4923:
4924: sub parse_block_record {
4925: my ($record) = @_;
4926: my ($setuname,$setudom,$title,$blocks);
4927: if (ref($record) eq 'HASH') {
4928: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4929: $title = &unescape($record->{'event'});
4930: $blocks = $record->{'blocks'};
4931: } else {
4932: my @data = split(/:/,$record,3);
4933: if (scalar(@data) eq 2) {
4934: $title = $data[1];
4935: ($setuname,$setudom) = split(/@/,$data[0]);
4936: } else {
4937: ($setuname,$setudom,$title) = @data;
4938: }
4939: $blocks = { 'com' => 'on' };
4940: }
4941: return ($setuname,$setudom,$title,$blocks);
4942: }
4943:
1.854 kalberla 4944: sub blocking_status {
1.1189 raeburn 4945: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 4946: my %setters;
1.890 droeschl 4947:
1.1061 raeburn 4948: # check for active blocking
1.1062 raeburn 4949: my ($startblock,$endblock,$triggerblock) =
1.1189 raeburn 4950: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 4951: my $blocked = 0;
4952: if ($startblock && $endblock) {
4953: $blocked = 1;
4954: }
1.890 droeschl 4955:
1.1061 raeburn 4956: # caller just wants to know whether a block is active
4957: if (!wantarray) { return $blocked; }
4958:
4959: # build a link to a popup window containing the details
4960: my $querystring = "?activity=$activity";
4961: # $uname and $udom decide whose portfolio the user is trying to look at
1.1232 ! raeburn 4962: if (($activity eq 'port') || ($activity eq 'passwd')) {
! 4963: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
! 4964: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 4965: } elsif ($activity eq 'docs') {
4966: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4967: }
1.1061 raeburn 4968:
4969: my $output .= <<'END_MYBLOCK';
4970: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4971: var options = "width=" + w + ",height=" + h + ",";
4972: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4973: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4974: var newWin = window.open(url, wdwName, options);
4975: newWin.focus();
4976: }
1.890 droeschl 4977: END_MYBLOCK
1.854 kalberla 4978:
1.1061 raeburn 4979: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4980:
1.1061 raeburn 4981: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4982: my $text = &mt('Communication Blocked');
1.1217 raeburn 4983: my $class = 'LC_comblock';
1.1062 raeburn 4984: if ($activity eq 'docs') {
4985: $text = &mt('Content Access Blocked');
1.1217 raeburn 4986: $class = '';
1.1063 raeburn 4987: } elsif ($activity eq 'printout') {
4988: $text = &mt('Printing Blocked');
1.1232 ! raeburn 4989: } elsif ($activity eq 'passwd') {
! 4990: $text = &mt('Password Changing Blocked');
1.1062 raeburn 4991: }
1.1061 raeburn 4992: $output .= <<"END_BLOCK";
1.1217 raeburn 4993: <div class='$class'>
1.869 kalberla 4994: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4995: title='$text'>
4996: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4997: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4998: title='$text'>$text</a>
1.867 kalberla 4999: </div>
5000:
5001: END_BLOCK
1.474 raeburn 5002:
1.1061 raeburn 5003: return ($blocked, $output);
1.854 kalberla 5004: }
1.490 raeburn 5005:
1.60 matthew 5006: ###############################################
5007:
1.682 raeburn 5008: sub check_ip_acc {
1.1201 raeburn 5009: my ($acc,$clientip)=@_;
1.682 raeburn 5010: &Apache::lonxml::debug("acc is $acc");
5011: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5012: return 1;
5013: }
1.1219 raeburn 5014: my $allowed;
1.1201 raeburn 5015: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
1.682 raeburn 5016:
5017: my $name;
1.1219 raeburn 5018: my %access = (
5019: allowfrom => 1,
5020: denyfrom => 0,
5021: );
5022: my @allows;
5023: my @denies;
5024: foreach my $item (split(',',$acc)) {
5025: $item =~ s/^\s*//;
5026: $item =~ s/\s*$//;
5027: my $pattern;
5028: if ($item =~ /^\!(.+)$/) {
5029: push(@denies,$1);
5030: } else {
5031: push(@allows,$item);
5032: }
5033: }
5034: my $numdenies = scalar(@denies);
5035: my $numallows = scalar(@allows);
5036: my $count = 0;
5037: foreach my $pattern (@denies,@allows) {
5038: $count ++;
5039: my $acctype = 'allowfrom';
5040: if ($count <= $numdenies) {
5041: $acctype = 'denyfrom';
5042: }
1.682 raeburn 5043: if ($pattern =~ /\*$/) {
5044: #35.8.*
5045: $pattern=~s/\*//;
1.1219 raeburn 5046: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5047: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5048: #35.8.3.[34-56]
5049: my $low=$2;
5050: my $high=$3;
5051: $pattern=$1;
5052: if ($ip =~ /^\Q$pattern\E/) {
5053: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5054: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5055: }
5056: } elsif ($pattern =~ /^\*/) {
5057: #*.msu.edu
5058: $pattern=~s/\*//;
5059: if (!defined($name)) {
5060: use Socket;
5061: my $netaddr=inet_aton($ip);
5062: ($name)=gethostbyaddr($netaddr,AF_INET);
5063: }
1.1219 raeburn 5064: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5065: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5066: #127.0.0.1
1.1219 raeburn 5067: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5068: } else {
5069: #some.name.com
5070: if (!defined($name)) {
5071: use Socket;
5072: my $netaddr=inet_aton($ip);
5073: ($name)=gethostbyaddr($netaddr,AF_INET);
5074: }
1.1219 raeburn 5075: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5076: }
5077: if ($allowed =~ /^(0|1)$/) { last; }
5078: }
5079: if ($allowed eq '') {
5080: if ($numdenies && !$numallows) {
5081: $allowed = 1;
5082: } else {
5083: $allowed = 0;
1.682 raeburn 5084: }
5085: }
5086: return $allowed;
5087: }
5088:
5089: ###############################################
5090:
1.60 matthew 5091: =pod
5092:
1.112 bowersj2 5093: =head1 Domain Template Functions
5094:
5095: =over 4
5096:
5097: =item * &determinedomain()
1.60 matthew 5098:
5099: Inputs: $domain (usually will be undef)
5100:
1.63 www 5101: Returns: Determines which domain should be used for designs
1.60 matthew 5102:
5103: =cut
1.54 www 5104:
1.60 matthew 5105: ###############################################
1.63 www 5106: sub determinedomain {
5107: my $domain=shift;
1.531 albertel 5108: if (! $domain) {
1.60 matthew 5109: # Determine domain if we have not been given one
1.893 raeburn 5110: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5111: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5112: if ($env{'request.role.domain'}) {
5113: $domain=$env{'request.role.domain'};
1.60 matthew 5114: }
5115: }
1.63 www 5116: return $domain;
5117: }
5118: ###############################################
1.517 raeburn 5119:
1.518 albertel 5120: sub devalidate_domconfig_cache {
5121: my ($udom)=@_;
5122: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5123: }
5124:
5125: # ---------------------- Get domain configuration for a domain
5126: sub get_domainconf {
5127: my ($udom) = @_;
5128: my $cachetime=1800;
5129: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5130: if (defined($cached)) { return %{$result}; }
5131:
5132: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5133: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5134: my (%designhash,%legacy);
1.518 albertel 5135: if (keys(%domconfig) > 0) {
5136: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5137: if (keys(%{$domconfig{'login'}})) {
5138: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5139: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5140: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5141: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5142: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5143: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5144: if ($key eq 'loginvia') {
5145: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5146: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5147: $designhash{$udom.'.login.loginvia'} = $server;
5148: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5149:
5150: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5151: } else {
5152: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5153: }
1.948 raeburn 5154: }
1.1208 raeburn 5155: } elsif ($key eq 'headtag') {
5156: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5157: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5158: }
1.946 raeburn 5159: }
1.1208 raeburn 5160: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5161: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5162: }
1.946 raeburn 5163: }
5164: }
5165: }
5166: } else {
5167: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5168: $designhash{$udom.'.login.'.$key.'_'.$img} =
5169: $domconfig{'login'}{$key}{$img};
5170: }
1.699 raeburn 5171: }
5172: } else {
5173: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5174: }
1.632 raeburn 5175: }
5176: } else {
5177: $legacy{'login'} = 1;
1.518 albertel 5178: }
1.632 raeburn 5179: } else {
5180: $legacy{'login'} = 1;
1.518 albertel 5181: }
5182: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5183: if (keys(%{$domconfig{'rolecolors'}})) {
5184: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5185: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5186: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5187: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5188: }
1.518 albertel 5189: }
5190: }
1.632 raeburn 5191: } else {
5192: $legacy{'rolecolors'} = 1;
1.518 albertel 5193: }
1.632 raeburn 5194: } else {
5195: $legacy{'rolecolors'} = 1;
1.518 albertel 5196: }
1.948 raeburn 5197: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5198: if ($domconfig{'autoenroll'}{'co-owners'}) {
5199: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5200: }
5201: }
1.632 raeburn 5202: if (keys(%legacy) > 0) {
5203: my %legacyhash = &get_legacy_domconf($udom);
5204: foreach my $item (keys(%legacyhash)) {
5205: if ($item =~ /^\Q$udom\E\.login/) {
5206: if ($legacy{'login'}) {
5207: $designhash{$item} = $legacyhash{$item};
5208: }
5209: } else {
5210: if ($legacy{'rolecolors'}) {
5211: $designhash{$item} = $legacyhash{$item};
5212: }
1.518 albertel 5213: }
5214: }
5215: }
1.632 raeburn 5216: } else {
5217: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5218: }
5219: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5220: $cachetime);
5221: return %designhash;
5222: }
5223:
1.632 raeburn 5224: sub get_legacy_domconf {
5225: my ($udom) = @_;
5226: my %legacyhash;
5227: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5228: my $designfile = $designdir.'/'.$udom.'.tab';
5229: if (-e $designfile) {
5230: if ( open (my $fh,"<$designfile") ) {
5231: while (my $line = <$fh>) {
5232: next if ($line =~ /^\#/);
5233: chomp($line);
5234: my ($key,$val)=(split(/\=/,$line));
5235: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5236: }
5237: close($fh);
5238: }
5239: }
1.1026 raeburn 5240: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5241: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5242: }
5243: return %legacyhash;
5244: }
5245:
1.63 www 5246: =pod
5247:
1.112 bowersj2 5248: =item * &domainlogo()
1.63 www 5249:
5250: Inputs: $domain (usually will be undef)
5251:
5252: Returns: A link to a domain logo, if the domain logo exists.
5253: If the domain logo does not exist, a description of the domain.
5254:
5255: =cut
1.112 bowersj2 5256:
1.63 www 5257: ###############################################
5258: sub domainlogo {
1.517 raeburn 5259: my $domain = &determinedomain(shift);
1.518 albertel 5260: my %designhash = &get_domainconf($domain);
1.517 raeburn 5261: # See if there is a logo
5262: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5263: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5264: if ($imgsrc =~ m{^/(adm|res)/}) {
5265: if ($imgsrc =~ m{^/res/}) {
5266: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5267: &Apache::lonnet::repcopy($local_name);
5268: }
5269: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5270: }
5271: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5272: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5273: return &Apache::lonnet::domain($domain,'description');
1.59 www 5274: } else {
1.60 matthew 5275: return '';
1.59 www 5276: }
5277: }
1.63 www 5278: ##############################################
5279:
5280: =pod
5281:
1.112 bowersj2 5282: =item * &designparm()
1.63 www 5283:
5284: Inputs: $which parameter; $domain (usually will be undef)
5285:
5286: Returns: value of designparamter $which
5287:
5288: =cut
1.112 bowersj2 5289:
1.397 albertel 5290:
1.400 albertel 5291: ##############################################
1.397 albertel 5292: sub designparm {
5293: my ($which,$domain)=@_;
5294: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5295: return $env{'environment.color.'.$which};
1.96 www 5296: }
1.63 www 5297: $domain=&determinedomain($domain);
1.1016 raeburn 5298: my %domdesign;
5299: unless ($domain eq 'public') {
5300: %domdesign = &get_domainconf($domain);
5301: }
1.520 raeburn 5302: my $output;
1.517 raeburn 5303: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5304: $output = $domdesign{$domain.'.'.$which};
1.63 www 5305: } else {
1.520 raeburn 5306: $output = $defaultdesign{$which};
5307: }
5308: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5309: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5310: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5311: if ($output =~ m{^/res/}) {
5312: my $local_name = &Apache::lonnet::filelocation('',$output);
5313: &Apache::lonnet::repcopy($local_name);
5314: }
1.520 raeburn 5315: $output = &lonhttpdurl($output);
5316: }
1.63 www 5317: }
1.520 raeburn 5318: return $output;
1.63 www 5319: }
1.59 www 5320:
1.822 bisitz 5321: ##############################################
5322: =pod
5323:
1.832 bisitz 5324: =item * &authorspace()
5325:
1.1028 raeburn 5326: Inputs: $url (usually will be undef).
1.832 bisitz 5327:
1.1132 raeburn 5328: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5329: directory being viewed (or for which action is being taken).
5330: If $url is provided, and begins /priv/<domain>/<uname>
5331: the path will be that portion of the $context argument.
5332: Otherwise the path will be for the author space of the current
5333: user when the current role is author, or for that of the
5334: co-author/assistant co-author space when the current role
5335: is co-author or assistant co-author.
1.832 bisitz 5336:
5337: =cut
5338:
5339: sub authorspace {
1.1028 raeburn 5340: my ($url) = @_;
5341: if ($url ne '') {
5342: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5343: return $1;
5344: }
5345: }
1.832 bisitz 5346: my $caname = '';
1.1024 www 5347: my $cadom = '';
1.1028 raeburn 5348: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5349: ($cadom,$caname) =
1.832 bisitz 5350: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5351: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5352: $caname = $env{'user.name'};
1.1024 www 5353: $cadom = $env{'user.domain'};
1.832 bisitz 5354: }
1.1028 raeburn 5355: if (($caname ne '') && ($cadom ne '')) {
5356: return "/priv/$cadom/$caname/";
5357: }
5358: return;
1.832 bisitz 5359: }
5360:
5361: ##############################################
5362: =pod
5363:
1.822 bisitz 5364: =item * &head_subbox()
5365:
5366: Inputs: $content (contains HTML code with page functions, etc.)
5367:
5368: Returns: HTML div with $content
5369: To be included in page header
5370:
5371: =cut
5372:
5373: sub head_subbox {
5374: my ($content)=@_;
5375: my $output =
1.993 raeburn 5376: '<div class="LC_head_subbox">'
1.822 bisitz 5377: .$content
5378: .'</div>'
5379: }
5380:
5381: ##############################################
5382: =pod
5383:
5384: =item * &CSTR_pageheader()
5385:
1.1026 raeburn 5386: Input: (optional) filename from which breadcrumb trail is built.
5387: In most cases no input as needed, as $env{'request.filename'}
5388: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5389:
5390: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5391: To be included on Authoring Space pages
1.822 bisitz 5392:
5393: =cut
5394:
5395: sub CSTR_pageheader {
1.1026 raeburn 5396: my ($trailfile) = @_;
5397: if ($trailfile eq '') {
5398: $trailfile = $env{'request.filename'};
5399: }
5400:
5401: # this is for resources; directories have customtitle, and crumbs
5402: # and select recent are created in lonpubdir.pm
5403:
5404: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5405: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5406: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5407: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5408: $formaction =~ s{/+}{/}g;
1.822 bisitz 5409:
5410: my $parentpath = '';
5411: my $lastitem = '';
5412: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5413: $parentpath = $1;
5414: $lastitem = $2;
5415: } else {
5416: $lastitem = $thisdisfn;
5417: }
1.921 bisitz 5418:
5419: my $output =
1.822 bisitz 5420: '<div>'
5421: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1132 raeburn 5422: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5423: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5424: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5425: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5426:
5427: if ($lastitem) {
5428: $output .=
5429: '<span class="LC_filename">'
5430: .$lastitem
5431: .'</span>';
5432: }
5433: $output .=
5434: '<br />'
1.822 bisitz 5435: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5436: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5437: .'</form>'
5438: .&Apache::lonmenu::constspaceform()
5439: .'</div>';
1.921 bisitz 5440:
5441: return $output;
1.822 bisitz 5442: }
5443:
1.60 matthew 5444: ###############################################
5445: ###############################################
5446:
5447: =pod
5448:
1.112 bowersj2 5449: =back
5450:
1.549 albertel 5451: =head1 HTML Helpers
1.112 bowersj2 5452:
5453: =over 4
5454:
5455: =item * &bodytag()
1.60 matthew 5456:
5457: Returns a uniform header for LON-CAPA web pages.
5458:
5459: Inputs:
5460:
1.112 bowersj2 5461: =over 4
5462:
5463: =item * $title, A title to be displayed on the page.
5464:
5465: =item * $function, the current role (can be undef).
5466:
5467: =item * $addentries, extra parameters for the <body> tag.
5468:
5469: =item * $bodyonly, if defined, only return the <body> tag.
5470:
5471: =item * $domain, if defined, force a given domain.
5472:
5473: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5474: text interface only)
1.60 matthew 5475:
1.814 bisitz 5476: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5477: navigational links
1.317 albertel 5478:
1.338 albertel 5479: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5480:
1.460 albertel 5481: =item * $args, optional argument valid values are
5482: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5483: inherit_jsmath -> when creating popup window in a page,
5484: should it have jsmath forced on by the
5485: current page
1.460 albertel 5486:
1.1096 raeburn 5487: =item * $advtoolsref, optional argument, ref to an array containing
5488: inlineremote items to be added in "Functions" menu below
5489: breadcrumbs.
5490:
1.112 bowersj2 5491: =back
5492:
1.60 matthew 5493: Returns: A uniform header for LON-CAPA web pages.
5494: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5495: If $bodyonly is undef or zero, an html string containing a <body> tag and
5496: other decorations will be returned.
5497:
5498: =cut
5499:
1.54 www 5500: sub bodytag {
1.831 bisitz 5501: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5502: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5503:
1.954 raeburn 5504: my $public;
5505: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5506: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5507: $public = 1;
5508: }
1.460 albertel 5509: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 5510: my $httphost = $args->{'use_absolute'};
1.339 albertel 5511:
1.183 matthew 5512: $function = &get_users_function() if (!$function);
1.339 albertel 5513: my $img = &designparm($function.'.img',$domain);
5514: my $font = &designparm($function.'.font',$domain);
5515: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5516:
1.803 bisitz 5517: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5518: 'bgcolor' => $pgbg,
1.339 albertel 5519: 'text' => $font,
5520: 'alink' => &designparm($function.'.alink',$domain),
5521: 'vlink' => &designparm($function.'.vlink',$domain),
5522: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5523: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5524:
1.63 www 5525: # role and realm
1.1178 raeburn 5526: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5527: if ($realm) {
5528: $realm = '/'.$realm;
5529: }
1.378 raeburn 5530: if ($role eq 'ca') {
1.479 albertel 5531: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5532: $realm = &plainname($rname,$rdom);
1.378 raeburn 5533: }
1.55 www 5534: # realm
1.258 albertel 5535: if ($env{'request.course.id'}) {
1.378 raeburn 5536: if ($env{'request.role'} !~ /^cr/) {
5537: $role = &Apache::lonnet::plaintext($role,&course_type());
5538: }
1.898 raeburn 5539: if ($env{'request.course.sec'}) {
5540: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5541: }
1.359 albertel 5542: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5543: } else {
5544: $role = &Apache::lonnet::plaintext($role);
1.54 www 5545: }
1.433 albertel 5546:
1.359 albertel 5547: if (!$realm) { $realm=' '; }
1.330 albertel 5548:
1.438 albertel 5549: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5550:
1.101 www 5551: # construct main body tag
1.359 albertel 5552: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5553: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5554:
1.1131 raeburn 5555: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5556:
1.1130 raeburn 5557: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5558: return $bodytag;
1.1130 raeburn 5559: }
1.359 albertel 5560:
1.954 raeburn 5561: if ($public) {
1.433 albertel 5562: undef($role);
5563: }
1.359 albertel 5564:
1.762 bisitz 5565: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5566: #
5567: # Extra info if you are the DC
5568: my $dc_info = '';
5569: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5570: $env{'course.'.$env{'request.course.id'}.
5571: '.domain'}.'/'})) {
5572: my $cid = $env{'request.course.id'};
1.917 raeburn 5573: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5574: $dc_info =~ s/\s+$//;
1.359 albertel 5575: }
5576:
1.898 raeburn 5577: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 5578:
1.903 droeschl 5579: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5580:
5581: # if ($env{'request.state'} eq 'construct') {
5582: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5583: # }
5584:
1.1130 raeburn 5585: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 5586: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5587:
1.1130 raeburn 5588: my ($left,$right) = Apache::lonmenu::primary_menu();
1.359 albertel 5589:
1.916 droeschl 5590: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5591: if ($dc_info) {
5592: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5593: }
1.1130 raeburn 5594: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 5595: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5596: return $bodytag;
5597: }
1.894 droeschl 5598:
1.927 raeburn 5599: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 5600: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5601: }
1.916 droeschl 5602:
1.1130 raeburn 5603: $bodytag .= $right;
1.852 droeschl 5604:
1.917 raeburn 5605: if ($dc_info) {
5606: $dc_info = &dc_courseid_toggle($dc_info);
5607: }
5608: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5609:
1.1169 raeburn 5610: #if directed to not display the secondary menu, don't.
1.1168 raeburn 5611: if ($args->{'no_secondary_menu'}) {
5612: return $bodytag;
5613: }
1.1169 raeburn 5614: #don't show menus for public users
1.954 raeburn 5615: if (!$public){
1.1154 raeburn 5616: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5617: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5618: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5619: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5620: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5621: $args->{'bread_crumbs'});
1.1096 raeburn 5622: } elsif ($forcereg) {
5623: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5624: $args->{'group'});
5625: } else {
5626: $bodytag .=
5627: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5628: $forcereg,$args->{'group'},
5629: $args->{'bread_crumbs'},
5630: $advtoolsref);
1.920 raeburn 5631: }
1.903 droeschl 5632: }else{
5633: # this is to seperate menu from content when there's no secondary
5634: # menu. Especially needed for public accessible ressources.
5635: $bodytag .= '<hr style="clear:both" />';
5636: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5637: }
1.903 droeschl 5638:
1.235 raeburn 5639: return $bodytag;
1.182 matthew 5640: }
5641:
1.917 raeburn 5642: sub dc_courseid_toggle {
5643: my ($dc_info) = @_;
1.980 raeburn 5644: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5645: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5646: &mt('(More ...)').'</a></span>'.
5647: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5648: }
5649:
1.330 albertel 5650: sub make_attr_string {
5651: my ($register,$attr_ref) = @_;
5652:
5653: if ($attr_ref && !ref($attr_ref)) {
5654: die("addentries Must be a hash ref ".
5655: join(':',caller(1))." ".
5656: join(':',caller(0))." ");
5657: }
5658:
5659: if ($register) {
1.339 albertel 5660: my ($on_load,$on_unload);
5661: foreach my $key (keys(%{$attr_ref})) {
5662: if (lc($key) eq 'onload') {
5663: $on_load.=$attr_ref->{$key}.';';
5664: delete($attr_ref->{$key});
5665:
5666: } elsif (lc($key) eq 'onunload') {
5667: $on_unload.=$attr_ref->{$key}.';';
5668: delete($attr_ref->{$key});
5669: }
5670: }
1.953 droeschl 5671: $attr_ref->{'onload'} = $on_load;
5672: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 5673: }
1.339 albertel 5674:
1.330 albertel 5675: my $attr_string;
1.1159 raeburn 5676: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5677: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5678: }
5679: return $attr_string;
5680: }
5681:
5682:
1.182 matthew 5683: ###############################################
1.251 albertel 5684: ###############################################
5685:
5686: =pod
5687:
5688: =item * &endbodytag()
5689:
5690: Returns a uniform footer for LON-CAPA web pages.
5691:
1.635 raeburn 5692: Inputs: 1 - optional reference to an args hash
5693: If in the hash, key for noredirectlink has a value which evaluates to true,
5694: a 'Continue' link is not displayed if the page contains an
5695: internal redirect in the <head></head> section,
5696: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5697:
5698: =cut
5699:
5700: sub endbodytag {
1.635 raeburn 5701: my ($args) = @_;
1.1080 raeburn 5702: my $endbodytag;
5703: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5704: $endbodytag='</body>';
5705: }
1.269 albertel 5706: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5707: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5708: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5709: $endbodytag=
5710: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5711: &mt('Continue').'</a>'.
5712: $endbodytag;
5713: }
1.315 albertel 5714: }
1.251 albertel 5715: return $endbodytag;
5716: }
5717:
1.352 albertel 5718: =pod
5719:
5720: =item * &standard_css()
5721:
5722: Returns a style sheet
5723:
5724: Inputs: (all optional)
5725: domain -> force to color decorate a page for a specific
5726: domain
5727: function -> force usage of a specific rolish color scheme
5728: bgcolor -> override the default page bgcolor
5729:
5730: =cut
5731:
1.343 albertel 5732: sub standard_css {
1.345 albertel 5733: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5734: $function = &get_users_function() if (!$function);
5735: my $img = &designparm($function.'.img', $domain);
5736: my $tabbg = &designparm($function.'.tabbg', $domain);
5737: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5738: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5739: #second colour for later usage
1.345 albertel 5740: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5741: my $pgbg_or_bgcolor =
5742: $bgcolor ||
1.352 albertel 5743: &designparm($function.'.pgbg', $domain);
1.382 albertel 5744: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5745: my $alink = &designparm($function.'.alink', $domain);
5746: my $vlink = &designparm($function.'.vlink', $domain);
5747: my $link = &designparm($function.'.link', $domain);
5748:
1.602 albertel 5749: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5750: my $mono = 'monospace';
1.850 bisitz 5751: my $data_table_head = $sidebg;
5752: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5753: my $data_table_dark = '#E0E0E0';
1.470 banghart 5754: my $data_table_darker = '#CCCCCC';
1.349 albertel 5755: my $data_table_highlight = '#FFFF00';
1.352 albertel 5756: my $mail_new = '#FFBB77';
5757: my $mail_new_hover = '#DD9955';
5758: my $mail_read = '#BBBB77';
5759: my $mail_read_hover = '#999944';
5760: my $mail_replied = '#AAAA88';
5761: my $mail_replied_hover = '#888855';
5762: my $mail_other = '#99BBBB';
5763: my $mail_other_hover = '#669999';
1.391 albertel 5764: my $table_header = '#DDDDDD';
1.489 raeburn 5765: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5766: my $lg_border_color = '#C8C8C8';
1.952 onken 5767: my $button_hover = '#BF2317';
1.392 albertel 5768:
1.608 albertel 5769: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5770: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5771: : '0 3px 0 4px';
1.448 albertel 5772:
1.523 albertel 5773:
1.343 albertel 5774: return <<END;
1.947 droeschl 5775:
5776: /* needed for iframe to allow 100% height in FF */
5777: body, html {
5778: margin: 0;
5779: padding: 0 0.5%;
5780: height: 99%; /* to avoid scrollbars */
5781: }
5782:
1.795 www 5783: body {
1.911 bisitz 5784: font-family: $sans;
5785: line-height:130%;
5786: font-size:0.83em;
5787: color:$font;
1.795 www 5788: }
5789:
1.959 onken 5790: a:focus,
5791: a:focus img {
1.795 www 5792: color: red;
5793: }
1.698 harmsja 5794:
1.911 bisitz 5795: form, .inline {
5796: display: inline;
1.795 www 5797: }
1.721 harmsja 5798:
1.795 www 5799: .LC_right {
1.911 bisitz 5800: text-align:right;
1.795 www 5801: }
5802:
5803: .LC_middle {
1.911 bisitz 5804: vertical-align:middle;
1.795 www 5805: }
1.721 harmsja 5806:
1.1130 raeburn 5807: .LC_floatleft {
5808: float: left;
5809: }
5810:
5811: .LC_floatright {
5812: float: right;
5813: }
5814:
1.911 bisitz 5815: .LC_400Box {
5816: width:400px;
5817: }
1.721 harmsja 5818:
1.947 droeschl 5819: .LC_iframecontainer {
5820: width: 98%;
5821: margin: 0;
5822: position: fixed;
5823: top: 8.5em;
5824: bottom: 0;
5825: }
5826:
5827: .LC_iframecontainer iframe{
5828: border: none;
5829: width: 100%;
5830: height: 100%;
5831: }
5832:
1.778 bisitz 5833: .LC_filename {
5834: font-family: $mono;
5835: white-space:pre;
1.921 bisitz 5836: font-size: 120%;
1.778 bisitz 5837: }
5838:
5839: .LC_fileicon {
5840: border: none;
5841: height: 1.3em;
5842: vertical-align: text-bottom;
5843: margin-right: 0.3em;
5844: text-decoration:none;
5845: }
5846:
1.1008 www 5847: .LC_setting {
5848: text-decoration:underline;
5849: }
5850:
1.350 albertel 5851: .LC_error {
5852: color: red;
5853: }
1.795 www 5854:
1.1097 bisitz 5855: .LC_warning {
5856: color: darkorange;
5857: }
5858:
1.457 albertel 5859: .LC_diff_removed {
1.733 bisitz 5860: color: red;
1.394 albertel 5861: }
1.532 albertel 5862:
5863: .LC_info,
1.457 albertel 5864: .LC_success,
5865: .LC_diff_added {
1.350 albertel 5866: color: green;
5867: }
1.795 www 5868:
1.802 bisitz 5869: div.LC_confirm_box {
5870: background-color: #FAFAFA;
5871: border: 1px solid $lg_border_color;
5872: margin-right: 0;
5873: padding: 5px;
5874: }
5875:
5876: div.LC_confirm_box .LC_error img,
5877: div.LC_confirm_box .LC_success img {
5878: vertical-align: middle;
5879: }
5880:
1.440 albertel 5881: .LC_icon {
1.771 droeschl 5882: border: none;
1.790 droeschl 5883: vertical-align: middle;
1.771 droeschl 5884: }
5885:
1.543 albertel 5886: .LC_docs_spacer {
5887: width: 25px;
5888: height: 1px;
1.771 droeschl 5889: border: none;
1.543 albertel 5890: }
1.346 albertel 5891:
1.532 albertel 5892: .LC_internal_info {
1.735 bisitz 5893: color: #999999;
1.532 albertel 5894: }
5895:
1.794 www 5896: .LC_discussion {
1.1050 www 5897: background: $data_table_dark;
1.911 bisitz 5898: border: 1px solid black;
5899: margin: 2px;
1.794 www 5900: }
5901:
5902: .LC_disc_action_left {
1.1050 www 5903: background: $sidebg;
1.911 bisitz 5904: text-align: left;
1.1050 www 5905: padding: 4px;
5906: margin: 2px;
1.794 www 5907: }
5908:
5909: .LC_disc_action_right {
1.1050 www 5910: background: $sidebg;
1.911 bisitz 5911: text-align: right;
1.1050 www 5912: padding: 4px;
5913: margin: 2px;
1.794 www 5914: }
5915:
5916: .LC_disc_new_item {
1.911 bisitz 5917: background: white;
5918: border: 2px solid red;
1.1050 www 5919: margin: 4px;
5920: padding: 4px;
1.794 www 5921: }
5922:
5923: .LC_disc_old_item {
1.911 bisitz 5924: background: white;
1.1050 www 5925: margin: 4px;
5926: padding: 4px;
1.794 www 5927: }
5928:
1.458 albertel 5929: table.LC_pastsubmission {
5930: border: 1px solid black;
5931: margin: 2px;
5932: }
5933:
1.924 bisitz 5934: table#LC_menubuttons {
1.345 albertel 5935: width: 100%;
5936: background: $pgbg;
1.392 albertel 5937: border: 2px;
1.402 albertel 5938: border-collapse: separate;
1.803 bisitz 5939: padding: 0;
1.345 albertel 5940: }
1.392 albertel 5941:
1.801 tempelho 5942: table#LC_title_bar a {
5943: color: $fontmenu;
5944: }
1.836 bisitz 5945:
1.807 droeschl 5946: table#LC_title_bar {
1.819 tempelho 5947: clear: both;
1.836 bisitz 5948: display: none;
1.807 droeschl 5949: }
5950:
1.795 www 5951: table#LC_title_bar,
1.933 droeschl 5952: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5953: table#LC_title_bar.LC_with_remote {
1.359 albertel 5954: width: 100%;
1.392 albertel 5955: border-color: $pgbg;
5956: border-style: solid;
5957: border-width: $border;
1.379 albertel 5958: background: $pgbg;
1.801 tempelho 5959: color: $fontmenu;
1.392 albertel 5960: border-collapse: collapse;
1.803 bisitz 5961: padding: 0;
1.819 tempelho 5962: margin: 0;
1.359 albertel 5963: }
1.795 www 5964:
1.933 droeschl 5965: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5966: margin: 0;
5967: padding: 0;
1.933 droeschl 5968: position: relative;
5969: list-style: none;
1.913 droeschl 5970: }
1.933 droeschl 5971: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5972: display: inline;
5973: }
1.933 droeschl 5974:
5975: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5976: padding: 0;
1.933 droeschl 5977: margin: 0;
5978: float: left;
1.913 droeschl 5979: }
1.933 droeschl 5980: .LC_breadcrumb_tools_tools {
5981: padding: 0;
5982: margin: 0;
1.913 droeschl 5983: float: right;
5984: }
5985:
1.359 albertel 5986: table#LC_title_bar td {
5987: background: $tabbg;
5988: }
1.795 www 5989:
1.911 bisitz 5990: table#LC_menubuttons img {
1.803 bisitz 5991: border: none;
1.346 albertel 5992: }
1.795 www 5993:
1.842 droeschl 5994: .LC_breadcrumbs_component {
1.911 bisitz 5995: float: right;
5996: margin: 0 1em;
1.357 albertel 5997: }
1.842 droeschl 5998: .LC_breadcrumbs_component img {
1.911 bisitz 5999: vertical-align: middle;
1.777 tempelho 6000: }
1.795 www 6001:
1.383 albertel 6002: td.LC_table_cell_checkbox {
6003: text-align: center;
6004: }
1.795 www 6005:
6006: .LC_fontsize_small {
1.911 bisitz 6007: font-size: 70%;
1.705 tempelho 6008: }
6009:
1.844 bisitz 6010: #LC_breadcrumbs {
1.911 bisitz 6011: clear:both;
6012: background: $sidebg;
6013: border-bottom: 1px solid $lg_border_color;
6014: line-height: 2.5em;
1.933 droeschl 6015: overflow: hidden;
1.911 bisitz 6016: margin: 0;
6017: padding: 0;
1.995 raeburn 6018: text-align: left;
1.819 tempelho 6019: }
1.862 bisitz 6020:
1.1098 bisitz 6021: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6022: clear:both;
6023: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6024: border: 1px solid $sidebg;
1.1098 bisitz 6025: margin: 0 0 10px 0;
1.966 bisitz 6026: padding: 3px;
1.995 raeburn 6027: text-align: left;
1.822 bisitz 6028: }
6029:
1.795 www 6030: .LC_fontsize_medium {
1.911 bisitz 6031: font-size: 85%;
1.705 tempelho 6032: }
6033:
1.795 www 6034: .LC_fontsize_large {
1.911 bisitz 6035: font-size: 120%;
1.705 tempelho 6036: }
6037:
1.346 albertel 6038: .LC_menubuttons_inline_text {
6039: color: $font;
1.698 harmsja 6040: font-size: 90%;
1.701 harmsja 6041: padding-left:3px;
1.346 albertel 6042: }
6043:
1.934 droeschl 6044: .LC_menubuttons_inline_text img{
6045: vertical-align: middle;
6046: }
6047:
1.1051 www 6048: li.LC_menubuttons_inline_text img {
1.951 onken 6049: cursor:pointer;
1.1002 droeschl 6050: text-decoration: none;
1.951 onken 6051: }
6052:
1.526 www 6053: .LC_menubuttons_link {
6054: text-decoration: none;
6055: }
1.795 www 6056:
1.522 albertel 6057: .LC_menubuttons_category {
1.521 www 6058: color: $font;
1.526 www 6059: background: $pgbg;
1.521 www 6060: font-size: larger;
6061: font-weight: bold;
6062: }
6063:
1.346 albertel 6064: td.LC_menubuttons_text {
1.911 bisitz 6065: color: $font;
1.346 albertel 6066: }
1.706 harmsja 6067:
1.346 albertel 6068: .LC_current_location {
6069: background: $tabbg;
6070: }
1.795 www 6071:
1.938 bisitz 6072: table.LC_data_table {
1.347 albertel 6073: border: 1px solid #000000;
1.402 albertel 6074: border-collapse: separate;
1.426 albertel 6075: border-spacing: 1px;
1.610 albertel 6076: background: $pgbg;
1.347 albertel 6077: }
1.795 www 6078:
1.422 albertel 6079: .LC_data_table_dense {
6080: font-size: small;
6081: }
1.795 www 6082:
1.507 raeburn 6083: table.LC_nested_outer {
6084: border: 1px solid #000000;
1.589 raeburn 6085: border-collapse: collapse;
1.803 bisitz 6086: border-spacing: 0;
1.507 raeburn 6087: width: 100%;
6088: }
1.795 www 6089:
1.879 raeburn 6090: table.LC_innerpickbox,
1.507 raeburn 6091: table.LC_nested {
1.803 bisitz 6092: border: none;
1.589 raeburn 6093: border-collapse: collapse;
1.803 bisitz 6094: border-spacing: 0;
1.507 raeburn 6095: width: 100%;
6096: }
1.795 www 6097:
1.911 bisitz 6098: table.LC_data_table tr th,
6099: table.LC_calendar tr th,
1.879 raeburn 6100: table.LC_prior_tries tr th,
6101: table.LC_innerpickbox tr th {
1.349 albertel 6102: font-weight: bold;
6103: background-color: $data_table_head;
1.801 tempelho 6104: color:$fontmenu;
1.701 harmsja 6105: font-size:90%;
1.347 albertel 6106: }
1.795 www 6107:
1.879 raeburn 6108: table.LC_innerpickbox tr th,
6109: table.LC_innerpickbox tr td {
6110: vertical-align: top;
6111: }
6112:
1.711 raeburn 6113: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6114: background-color: #CCCCCC;
1.711 raeburn 6115: font-weight: bold;
6116: text-align: left;
6117: }
1.795 www 6118:
1.912 bisitz 6119: table.LC_data_table tr.LC_odd_row > td {
6120: background-color: $data_table_light;
6121: padding: 2px;
6122: vertical-align: top;
6123: }
6124:
1.809 bisitz 6125: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6126: background-color: $data_table_light;
1.912 bisitz 6127: vertical-align: top;
6128: }
6129:
6130: table.LC_data_table tr.LC_even_row > td {
6131: background-color: $data_table_dark;
1.425 albertel 6132: padding: 2px;
1.900 bisitz 6133: vertical-align: top;
1.347 albertel 6134: }
1.795 www 6135:
1.809 bisitz 6136: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6137: background-color: $data_table_dark;
1.900 bisitz 6138: vertical-align: top;
1.347 albertel 6139: }
1.795 www 6140:
1.425 albertel 6141: table.LC_data_table tr.LC_data_table_highlight td {
6142: background-color: $data_table_darker;
6143: }
1.795 www 6144:
1.639 raeburn 6145: table.LC_data_table tr td.LC_leftcol_header {
6146: background-color: $data_table_head;
6147: font-weight: bold;
6148: }
1.795 www 6149:
1.451 albertel 6150: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6151: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6152: font-weight: bold;
6153: font-style: italic;
6154: text-align: center;
6155: padding: 8px;
1.347 albertel 6156: }
1.795 www 6157:
1.1114 raeburn 6158: table.LC_data_table tr.LC_empty_row td,
6159: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6160: background-color: $sidebg;
6161: }
6162:
6163: table.LC_nested tr.LC_empty_row td {
6164: background-color: #FFFFFF;
6165: }
6166:
1.890 droeschl 6167: table.LC_caption {
6168: }
6169:
1.507 raeburn 6170: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6171: padding: 4ex
6172: }
1.795 www 6173:
1.507 raeburn 6174: table.LC_nested_outer tr th {
6175: font-weight: bold;
1.801 tempelho 6176: color:$fontmenu;
1.507 raeburn 6177: background-color: $data_table_head;
1.701 harmsja 6178: font-size: small;
1.507 raeburn 6179: border-bottom: 1px solid #000000;
6180: }
1.795 www 6181:
1.507 raeburn 6182: table.LC_nested_outer tr td.LC_subheader {
6183: background-color: $data_table_head;
6184: font-weight: bold;
6185: font-size: small;
6186: border-bottom: 1px solid #000000;
6187: text-align: right;
1.451 albertel 6188: }
1.795 www 6189:
1.507 raeburn 6190: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6191: background-color: #CCCCCC;
1.451 albertel 6192: font-weight: bold;
6193: font-size: small;
1.507 raeburn 6194: text-align: center;
6195: }
1.795 www 6196:
1.589 raeburn 6197: table.LC_nested tr.LC_info_row td.LC_left_item,
6198: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6199: text-align: left;
1.451 albertel 6200: }
1.795 www 6201:
1.507 raeburn 6202: table.LC_nested td {
1.735 bisitz 6203: background-color: #FFFFFF;
1.451 albertel 6204: font-size: small;
1.507 raeburn 6205: }
1.795 www 6206:
1.507 raeburn 6207: table.LC_nested_outer tr th.LC_right_item,
6208: table.LC_nested tr.LC_info_row td.LC_right_item,
6209: table.LC_nested tr.LC_odd_row td.LC_right_item,
6210: table.LC_nested tr td.LC_right_item {
1.451 albertel 6211: text-align: right;
6212: }
6213:
1.507 raeburn 6214: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6215: background-color: #EEEEEE;
1.451 albertel 6216: }
6217:
1.473 raeburn 6218: table.LC_createuser {
6219: }
6220:
6221: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6222: font-size: small;
1.473 raeburn 6223: }
6224:
6225: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6226: background-color: #CCCCCC;
1.473 raeburn 6227: font-weight: bold;
6228: text-align: center;
6229: }
6230:
1.349 albertel 6231: table.LC_calendar {
6232: border: 1px solid #000000;
6233: border-collapse: collapse;
1.917 raeburn 6234: width: 98%;
1.349 albertel 6235: }
1.795 www 6236:
1.349 albertel 6237: table.LC_calendar_pickdate {
6238: font-size: xx-small;
6239: }
1.795 www 6240:
1.349 albertel 6241: table.LC_calendar tr td {
6242: border: 1px solid #000000;
6243: vertical-align: top;
1.917 raeburn 6244: width: 14%;
1.349 albertel 6245: }
1.795 www 6246:
1.349 albertel 6247: table.LC_calendar tr td.LC_calendar_day_empty {
6248: background-color: $data_table_dark;
6249: }
1.795 www 6250:
1.779 bisitz 6251: table.LC_calendar tr td.LC_calendar_day_current {
6252: background-color: $data_table_highlight;
1.777 tempelho 6253: }
1.795 www 6254:
1.938 bisitz 6255: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6256: background-color: $mail_new;
6257: }
1.795 www 6258:
1.938 bisitz 6259: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6260: background-color: $mail_new_hover;
6261: }
1.795 www 6262:
1.938 bisitz 6263: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6264: background-color: $mail_read;
6265: }
1.795 www 6266:
1.938 bisitz 6267: /*
6268: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6269: background-color: $mail_read_hover;
6270: }
1.938 bisitz 6271: */
1.795 www 6272:
1.938 bisitz 6273: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6274: background-color: $mail_replied;
6275: }
1.795 www 6276:
1.938 bisitz 6277: /*
6278: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6279: background-color: $mail_replied_hover;
6280: }
1.938 bisitz 6281: */
1.795 www 6282:
1.938 bisitz 6283: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6284: background-color: $mail_other;
6285: }
1.795 www 6286:
1.938 bisitz 6287: /*
6288: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6289: background-color: $mail_other_hover;
6290: }
1.938 bisitz 6291: */
1.494 raeburn 6292:
1.777 tempelho 6293: table.LC_data_table tr > td.LC_browser_file,
6294: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6295: background: #AAEE77;
1.389 albertel 6296: }
1.795 www 6297:
1.777 tempelho 6298: table.LC_data_table tr > td.LC_browser_file_locked,
6299: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6300: background: #FFAA99;
1.387 albertel 6301: }
1.795 www 6302:
1.777 tempelho 6303: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6304: background: #888888;
1.779 bisitz 6305: }
1.795 www 6306:
1.777 tempelho 6307: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6308: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6309: background: #F8F866;
1.777 tempelho 6310: }
1.795 www 6311:
1.696 bisitz 6312: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6313: background: #E0E8FF;
1.387 albertel 6314: }
1.696 bisitz 6315:
1.707 bisitz 6316: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6317: /* background: #77FF77; */
1.707 bisitz 6318: }
1.795 www 6319:
1.707 bisitz 6320: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6321: border-right: 8px solid #FFFF77;
1.707 bisitz 6322: }
1.795 www 6323:
1.707 bisitz 6324: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6325: border-right: 8px solid #FFAA77;
1.707 bisitz 6326: }
1.795 www 6327:
1.707 bisitz 6328: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6329: border-right: 8px solid #FF7777;
1.707 bisitz 6330: }
1.795 www 6331:
1.707 bisitz 6332: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6333: border-right: 8px solid #AAFF77;
1.707 bisitz 6334: }
1.795 www 6335:
1.707 bisitz 6336: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6337: border-right: 8px solid #11CC55;
1.707 bisitz 6338: }
6339:
1.388 albertel 6340: span.LC_current_location {
1.701 harmsja 6341: font-size:larger;
1.388 albertel 6342: background: $pgbg;
6343: }
1.387 albertel 6344:
1.1029 www 6345: span.LC_current_nav_location {
6346: font-weight:bold;
6347: background: $sidebg;
6348: }
6349:
1.395 albertel 6350: span.LC_parm_menu_item {
6351: font-size: larger;
6352: }
1.795 www 6353:
1.395 albertel 6354: span.LC_parm_scope_all {
6355: color: red;
6356: }
1.795 www 6357:
1.395 albertel 6358: span.LC_parm_scope_folder {
6359: color: green;
6360: }
1.795 www 6361:
1.395 albertel 6362: span.LC_parm_scope_resource {
6363: color: orange;
6364: }
1.795 www 6365:
1.395 albertel 6366: span.LC_parm_part {
6367: color: blue;
6368: }
1.795 www 6369:
1.911 bisitz 6370: span.LC_parm_folder,
6371: span.LC_parm_symb {
1.395 albertel 6372: font-size: x-small;
6373: font-family: $mono;
6374: color: #AAAAAA;
6375: }
6376:
1.977 bisitz 6377: ul.LC_parm_parmlist li {
6378: display: inline-block;
6379: padding: 0.3em 0.8em;
6380: vertical-align: top;
6381: width: 150px;
6382: border-top:1px solid $lg_border_color;
6383: }
6384:
1.795 www 6385: td.LC_parm_overview_level_menu,
6386: td.LC_parm_overview_map_menu,
6387: td.LC_parm_overview_parm_selectors,
6388: td.LC_parm_overview_restrictions {
1.396 albertel 6389: border: 1px solid black;
6390: border-collapse: collapse;
6391: }
1.795 www 6392:
1.396 albertel 6393: table.LC_parm_overview_restrictions td {
6394: border-width: 1px 4px 1px 4px;
6395: border-style: solid;
6396: border-color: $pgbg;
6397: text-align: center;
6398: }
1.795 www 6399:
1.396 albertel 6400: table.LC_parm_overview_restrictions th {
6401: background: $tabbg;
6402: border-width: 1px 4px 1px 4px;
6403: border-style: solid;
6404: border-color: $pgbg;
6405: }
1.795 www 6406:
1.398 albertel 6407: table#LC_helpmenu {
1.803 bisitz 6408: border: none;
1.398 albertel 6409: height: 55px;
1.803 bisitz 6410: border-spacing: 0;
1.398 albertel 6411: }
6412:
6413: table#LC_helpmenu fieldset legend {
6414: font-size: larger;
6415: }
1.795 www 6416:
1.397 albertel 6417: table#LC_helpmenu_links {
6418: width: 100%;
6419: border: 1px solid black;
6420: background: $pgbg;
1.803 bisitz 6421: padding: 0;
1.397 albertel 6422: border-spacing: 1px;
6423: }
1.795 www 6424:
1.397 albertel 6425: table#LC_helpmenu_links tr td {
6426: padding: 1px;
6427: background: $tabbg;
1.399 albertel 6428: text-align: center;
6429: font-weight: bold;
1.397 albertel 6430: }
1.396 albertel 6431:
1.795 www 6432: table#LC_helpmenu_links a:link,
6433: table#LC_helpmenu_links a:visited,
1.397 albertel 6434: table#LC_helpmenu_links a:active {
6435: text-decoration: none;
6436: color: $font;
6437: }
1.795 www 6438:
1.397 albertel 6439: table#LC_helpmenu_links a:hover {
6440: text-decoration: underline;
6441: color: $vlink;
6442: }
1.396 albertel 6443:
1.417 albertel 6444: .LC_chrt_popup_exists {
6445: border: 1px solid #339933;
6446: margin: -1px;
6447: }
1.795 www 6448:
1.417 albertel 6449: .LC_chrt_popup_up {
6450: border: 1px solid yellow;
6451: margin: -1px;
6452: }
1.795 www 6453:
1.417 albertel 6454: .LC_chrt_popup {
6455: border: 1px solid #8888FF;
6456: background: #CCCCFF;
6457: }
1.795 www 6458:
1.421 albertel 6459: table.LC_pick_box {
6460: border-collapse: separate;
6461: background: white;
6462: border: 1px solid black;
6463: border-spacing: 1px;
6464: }
1.795 www 6465:
1.421 albertel 6466: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6467: background: $sidebg;
1.421 albertel 6468: font-weight: bold;
1.900 bisitz 6469: text-align: left;
1.740 bisitz 6470: vertical-align: top;
1.421 albertel 6471: width: 184px;
6472: padding: 8px;
6473: }
1.795 www 6474:
1.579 raeburn 6475: table.LC_pick_box td.LC_pick_box_value {
6476: text-align: left;
6477: padding: 8px;
6478: }
1.795 www 6479:
1.579 raeburn 6480: table.LC_pick_box td.LC_pick_box_select {
6481: text-align: left;
6482: padding: 8px;
6483: }
1.795 www 6484:
1.424 albertel 6485: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6486: padding: 0;
1.421 albertel 6487: height: 1px;
6488: background: black;
6489: }
1.795 www 6490:
1.421 albertel 6491: table.LC_pick_box td.LC_pick_box_submit {
6492: text-align: right;
6493: }
1.795 www 6494:
1.579 raeburn 6495: table.LC_pick_box td.LC_evenrow_value {
6496: text-align: left;
6497: padding: 8px;
6498: background-color: $data_table_light;
6499: }
1.795 www 6500:
1.579 raeburn 6501: table.LC_pick_box td.LC_oddrow_value {
6502: text-align: left;
6503: padding: 8px;
6504: background-color: $data_table_light;
6505: }
1.795 www 6506:
1.579 raeburn 6507: span.LC_helpform_receipt_cat {
6508: font-weight: bold;
6509: }
1.795 www 6510:
1.424 albertel 6511: table.LC_group_priv_box {
6512: background: white;
6513: border: 1px solid black;
6514: border-spacing: 1px;
6515: }
1.795 www 6516:
1.424 albertel 6517: table.LC_group_priv_box td.LC_pick_box_title {
6518: background: $tabbg;
6519: font-weight: bold;
6520: text-align: right;
6521: width: 184px;
6522: }
1.795 www 6523:
1.424 albertel 6524: table.LC_group_priv_box td.LC_groups_fixed {
6525: background: $data_table_light;
6526: text-align: center;
6527: }
1.795 www 6528:
1.424 albertel 6529: table.LC_group_priv_box td.LC_groups_optional {
6530: background: $data_table_dark;
6531: text-align: center;
6532: }
1.795 www 6533:
1.424 albertel 6534: table.LC_group_priv_box td.LC_groups_functionality {
6535: background: $data_table_darker;
6536: text-align: center;
6537: font-weight: bold;
6538: }
1.795 www 6539:
1.424 albertel 6540: table.LC_group_priv td {
6541: text-align: left;
1.803 bisitz 6542: padding: 0;
1.424 albertel 6543: }
6544:
6545: .LC_navbuttons {
6546: margin: 2ex 0ex 2ex 0ex;
6547: }
1.795 www 6548:
1.423 albertel 6549: .LC_topic_bar {
6550: font-weight: bold;
6551: background: $tabbg;
1.918 wenzelju 6552: margin: 1em 0em 1em 2em;
1.805 bisitz 6553: padding: 3px;
1.918 wenzelju 6554: font-size: 1.2em;
1.423 albertel 6555: }
1.795 www 6556:
1.423 albertel 6557: .LC_topic_bar span {
1.918 wenzelju 6558: left: 0.5em;
6559: position: absolute;
1.423 albertel 6560: vertical-align: middle;
1.918 wenzelju 6561: font-size: 1.2em;
1.423 albertel 6562: }
1.795 www 6563:
1.423 albertel 6564: table.LC_course_group_status {
6565: margin: 20px;
6566: }
1.795 www 6567:
1.423 albertel 6568: table.LC_status_selector td {
6569: vertical-align: top;
6570: text-align: center;
1.424 albertel 6571: padding: 4px;
6572: }
1.795 www 6573:
1.599 albertel 6574: div.LC_feedback_link {
1.616 albertel 6575: clear: both;
1.829 kalberla 6576: background: $sidebg;
1.779 bisitz 6577: width: 100%;
1.829 kalberla 6578: padding-bottom: 10px;
6579: border: 1px $tabbg solid;
1.833 kalberla 6580: height: 22px;
6581: line-height: 22px;
6582: padding-top: 5px;
6583: }
6584:
6585: div.LC_feedback_link img {
6586: height: 22px;
1.867 kalberla 6587: vertical-align:middle;
1.829 kalberla 6588: }
6589:
1.911 bisitz 6590: div.LC_feedback_link a {
1.829 kalberla 6591: text-decoration: none;
1.489 raeburn 6592: }
1.795 www 6593:
1.867 kalberla 6594: div.LC_comblock {
1.911 bisitz 6595: display:inline;
1.867 kalberla 6596: color:$font;
6597: font-size:90%;
6598: }
6599:
6600: div.LC_feedback_link div.LC_comblock {
6601: padding-left:5px;
6602: }
6603:
6604: div.LC_feedback_link div.LC_comblock a {
6605: color:$font;
6606: }
6607:
1.489 raeburn 6608: span.LC_feedback_link {
1.858 bisitz 6609: /* background: $feedback_link_bg; */
1.599 albertel 6610: font-size: larger;
6611: }
1.795 www 6612:
1.599 albertel 6613: span.LC_message_link {
1.858 bisitz 6614: /* background: $feedback_link_bg; */
1.599 albertel 6615: font-size: larger;
6616: position: absolute;
6617: right: 1em;
1.489 raeburn 6618: }
1.421 albertel 6619:
1.515 albertel 6620: table.LC_prior_tries {
1.524 albertel 6621: border: 1px solid #000000;
6622: border-collapse: separate;
6623: border-spacing: 1px;
1.515 albertel 6624: }
1.523 albertel 6625:
1.515 albertel 6626: table.LC_prior_tries td {
1.524 albertel 6627: padding: 2px;
1.515 albertel 6628: }
1.523 albertel 6629:
6630: .LC_answer_correct {
1.795 www 6631: background: lightgreen;
6632: color: darkgreen;
6633: padding: 6px;
1.523 albertel 6634: }
1.795 www 6635:
1.523 albertel 6636: .LC_answer_charged_try {
1.797 www 6637: background: #FFAAAA;
1.795 www 6638: color: darkred;
6639: padding: 6px;
1.523 albertel 6640: }
1.795 www 6641:
1.779 bisitz 6642: .LC_answer_not_charged_try,
1.523 albertel 6643: .LC_answer_no_grade,
6644: .LC_answer_late {
1.795 www 6645: background: lightyellow;
1.523 albertel 6646: color: black;
1.795 www 6647: padding: 6px;
1.523 albertel 6648: }
1.795 www 6649:
1.523 albertel 6650: .LC_answer_previous {
1.795 www 6651: background: lightblue;
6652: color: darkblue;
6653: padding: 6px;
1.523 albertel 6654: }
1.795 www 6655:
1.779 bisitz 6656: .LC_answer_no_message {
1.777 tempelho 6657: background: #FFFFFF;
6658: color: black;
1.795 www 6659: padding: 6px;
1.779 bisitz 6660: }
1.795 www 6661:
1.779 bisitz 6662: .LC_answer_unknown {
6663: background: orange;
6664: color: black;
1.795 www 6665: padding: 6px;
1.777 tempelho 6666: }
1.795 www 6667:
1.529 albertel 6668: span.LC_prior_numerical,
6669: span.LC_prior_string,
6670: span.LC_prior_custom,
6671: span.LC_prior_reaction,
6672: span.LC_prior_math {
1.925 bisitz 6673: font-family: $mono;
1.523 albertel 6674: white-space: pre;
6675: }
6676:
1.525 albertel 6677: span.LC_prior_string {
1.925 bisitz 6678: font-family: $mono;
1.525 albertel 6679: white-space: pre;
6680: }
6681:
1.523 albertel 6682: table.LC_prior_option {
6683: width: 100%;
6684: border-collapse: collapse;
6685: }
1.795 www 6686:
1.911 bisitz 6687: table.LC_prior_rank,
1.795 www 6688: table.LC_prior_match {
1.528 albertel 6689: border-collapse: collapse;
6690: }
1.795 www 6691:
1.528 albertel 6692: table.LC_prior_option tr td,
6693: table.LC_prior_rank tr td,
6694: table.LC_prior_match tr td {
1.524 albertel 6695: border: 1px solid #000000;
1.515 albertel 6696: }
6697:
1.855 bisitz 6698: .LC_nobreak {
1.544 albertel 6699: white-space: nowrap;
1.519 raeburn 6700: }
6701:
1.576 raeburn 6702: span.LC_cusr_emph {
6703: font-style: italic;
6704: }
6705:
1.633 raeburn 6706: span.LC_cusr_subheading {
6707: font-weight: normal;
6708: font-size: 85%;
6709: }
6710:
1.861 bisitz 6711: div.LC_docs_entry_move {
1.859 bisitz 6712: border: 1px solid #BBBBBB;
1.545 albertel 6713: background: #DDDDDD;
1.861 bisitz 6714: width: 22px;
1.859 bisitz 6715: padding: 1px;
6716: margin: 0;
1.545 albertel 6717: }
6718:
1.861 bisitz 6719: table.LC_data_table tr > td.LC_docs_entry_commands,
6720: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6721: font-size: x-small;
6722: }
1.795 www 6723:
1.861 bisitz 6724: .LC_docs_entry_parameter {
6725: white-space: nowrap;
6726: }
6727:
1.544 albertel 6728: .LC_docs_copy {
1.545 albertel 6729: color: #000099;
1.544 albertel 6730: }
1.795 www 6731:
1.544 albertel 6732: .LC_docs_cut {
1.545 albertel 6733: color: #550044;
1.544 albertel 6734: }
1.795 www 6735:
1.544 albertel 6736: .LC_docs_rename {
1.545 albertel 6737: color: #009900;
1.544 albertel 6738: }
1.795 www 6739:
1.544 albertel 6740: .LC_docs_remove {
1.545 albertel 6741: color: #990000;
6742: }
6743:
1.547 albertel 6744: .LC_docs_reinit_warn,
6745: .LC_docs_ext_edit {
6746: font-size: x-small;
6747: }
6748:
1.545 albertel 6749: table.LC_docs_adddocs td,
6750: table.LC_docs_adddocs th {
6751: border: 1px solid #BBBBBB;
6752: padding: 4px;
6753: background: #DDDDDD;
1.543 albertel 6754: }
6755:
1.584 albertel 6756: table.LC_sty_begin {
6757: background: #BBFFBB;
6758: }
1.795 www 6759:
1.584 albertel 6760: table.LC_sty_end {
6761: background: #FFBBBB;
6762: }
6763:
1.589 raeburn 6764: table.LC_double_column {
1.803 bisitz 6765: border-width: 0;
1.589 raeburn 6766: border-collapse: collapse;
6767: width: 100%;
6768: padding: 2px;
6769: }
6770:
6771: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6772: top: 2px;
1.589 raeburn 6773: left: 2px;
6774: width: 47%;
6775: vertical-align: top;
6776: }
6777:
6778: table.LC_double_column tr td.LC_right_col {
6779: top: 2px;
1.779 bisitz 6780: right: 2px;
1.589 raeburn 6781: width: 47%;
6782: vertical-align: top;
6783: }
6784:
1.591 raeburn 6785: div.LC_left_float {
6786: float: left;
6787: padding-right: 5%;
1.597 albertel 6788: padding-bottom: 4px;
1.591 raeburn 6789: }
6790:
6791: div.LC_clear_float_header {
1.597 albertel 6792: padding-bottom: 2px;
1.591 raeburn 6793: }
6794:
6795: div.LC_clear_float_footer {
1.597 albertel 6796: padding-top: 10px;
1.591 raeburn 6797: clear: both;
6798: }
6799:
1.597 albertel 6800: div.LC_grade_show_user {
1.941 bisitz 6801: /* border-left: 5px solid $sidebg; */
6802: border-top: 5px solid #000000;
6803: margin: 50px 0 0 0;
1.936 bisitz 6804: padding: 15px 0 5px 10px;
1.597 albertel 6805: }
1.795 www 6806:
1.936 bisitz 6807: div.LC_grade_show_user_odd_row {
1.941 bisitz 6808: /* border-left: 5px solid #000000; */
6809: }
6810:
6811: div.LC_grade_show_user div.LC_Box {
6812: margin-right: 50px;
1.597 albertel 6813: }
6814:
6815: div.LC_grade_submissions,
6816: div.LC_grade_message_center,
1.936 bisitz 6817: div.LC_grade_info_links {
1.597 albertel 6818: margin: 5px;
6819: width: 99%;
6820: background: #FFFFFF;
6821: }
1.795 www 6822:
1.597 albertel 6823: div.LC_grade_submissions_header,
1.936 bisitz 6824: div.LC_grade_message_center_header {
1.705 tempelho 6825: font-weight: bold;
6826: font-size: large;
1.597 albertel 6827: }
1.795 www 6828:
1.597 albertel 6829: div.LC_grade_submissions_body,
1.936 bisitz 6830: div.LC_grade_message_center_body {
1.597 albertel 6831: border: 1px solid black;
6832: width: 99%;
6833: background: #FFFFFF;
6834: }
1.795 www 6835:
1.613 albertel 6836: table.LC_scantron_action {
6837: width: 100%;
6838: }
1.795 www 6839:
1.613 albertel 6840: table.LC_scantron_action tr th {
1.698 harmsja 6841: font-weight:bold;
6842: font-style:normal;
1.613 albertel 6843: }
1.795 www 6844:
1.779 bisitz 6845: .LC_edit_problem_header,
1.614 albertel 6846: div.LC_edit_problem_footer {
1.705 tempelho 6847: font-weight: normal;
6848: font-size: medium;
1.602 albertel 6849: margin: 2px;
1.1060 bisitz 6850: background-color: $sidebg;
1.600 albertel 6851: }
1.795 www 6852:
1.600 albertel 6853: div.LC_edit_problem_header,
1.602 albertel 6854: div.LC_edit_problem_header div,
1.614 albertel 6855: div.LC_edit_problem_footer,
6856: div.LC_edit_problem_footer div,
1.602 albertel 6857: div.LC_edit_problem_editxml_header,
6858: div.LC_edit_problem_editxml_header div {
1.1205 golterma 6859: z-index: 100;
1.600 albertel 6860: }
1.795 www 6861:
1.600 albertel 6862: div.LC_edit_problem_header_title {
1.705 tempelho 6863: font-weight: bold;
6864: font-size: larger;
1.602 albertel 6865: background: $tabbg;
6866: padding: 3px;
1.1060 bisitz 6867: margin: 0 0 5px 0;
1.602 albertel 6868: }
1.795 www 6869:
1.602 albertel 6870: table.LC_edit_problem_header_title {
6871: width: 100%;
1.600 albertel 6872: background: $tabbg;
1.602 albertel 6873: }
6874:
1.1205 golterma 6875: div.LC_edit_actionbar {
6876: background-color: $sidebg;
1.1218 droeschl 6877: margin: 0;
6878: padding: 0;
6879: line-height: 200%;
1.602 albertel 6880: }
1.795 www 6881:
1.1218 droeschl 6882: div.LC_edit_actionbar div{
6883: padding: 0;
6884: margin: 0;
6885: display: inline-block;
1.600 albertel 6886: }
1.795 www 6887:
1.1124 bisitz 6888: .LC_edit_opt {
6889: padding-left: 1em;
6890: white-space: nowrap;
6891: }
6892:
1.1152 golterma 6893: .LC_edit_problem_latexhelper{
6894: text-align: right;
6895: }
6896:
6897: #LC_edit_problem_colorful div{
6898: margin-left: 40px;
6899: }
6900:
1.1205 golterma 6901: #LC_edit_problem_codemirror div{
6902: margin-left: 0px;
6903: }
6904:
1.911 bisitz 6905: img.stift {
1.803 bisitz 6906: border-width: 0;
6907: vertical-align: middle;
1.677 riegler 6908: }
1.680 riegler 6909:
1.923 bisitz 6910: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6911: vertical-align: top;
1.777 tempelho 6912: }
1.795 www 6913:
1.716 raeburn 6914: div.LC_createcourse {
1.911 bisitz 6915: margin: 10px 10px 10px 10px;
1.716 raeburn 6916: }
6917:
1.917 raeburn 6918: .LC_dccid {
1.1130 raeburn 6919: float: right;
1.917 raeburn 6920: margin: 0.2em 0 0 0;
6921: padding: 0;
6922: font-size: 90%;
6923: display:none;
6924: }
6925:
1.897 wenzelju 6926: ol.LC_primary_menu a:hover,
1.721 harmsja 6927: ol#LC_MenuBreadcrumbs a:hover,
6928: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6929: ul#LC_secondary_menu a:hover,
1.721 harmsja 6930: .LC_FormSectionClearButton input:hover
1.795 www 6931: ul.LC_TabContent li:hover a {
1.952 onken 6932: color:$button_hover;
1.911 bisitz 6933: text-decoration:none;
1.693 droeschl 6934: }
6935:
1.779 bisitz 6936: h1 {
1.911 bisitz 6937: padding: 0;
6938: line-height:130%;
1.693 droeschl 6939: }
1.698 harmsja 6940:
1.911 bisitz 6941: h2,
6942: h3,
6943: h4,
6944: h5,
6945: h6 {
6946: margin: 5px 0 5px 0;
6947: padding: 0;
6948: line-height:130%;
1.693 droeschl 6949: }
1.795 www 6950:
6951: .LC_hcell {
1.911 bisitz 6952: padding:3px 15px 3px 15px;
6953: margin: 0;
6954: background-color:$tabbg;
6955: color:$fontmenu;
6956: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6957: }
1.795 www 6958:
1.840 bisitz 6959: .LC_Box > .LC_hcell {
1.911 bisitz 6960: margin: 0 -10px 10px -10px;
1.835 bisitz 6961: }
6962:
1.721 harmsja 6963: .LC_noBorder {
1.911 bisitz 6964: border: 0;
1.698 harmsja 6965: }
1.693 droeschl 6966:
1.721 harmsja 6967: .LC_FormSectionClearButton input {
1.911 bisitz 6968: background-color:transparent;
6969: border: none;
6970: cursor:pointer;
6971: text-decoration:underline;
1.693 droeschl 6972: }
1.763 bisitz 6973:
6974: .LC_help_open_topic {
1.911 bisitz 6975: color: #FFFFFF;
6976: background-color: #EEEEFF;
6977: margin: 1px;
6978: padding: 4px;
6979: border: 1px solid #000033;
6980: white-space: nowrap;
6981: /* vertical-align: middle; */
1.759 neumanie 6982: }
1.693 droeschl 6983:
1.911 bisitz 6984: dl,
6985: ul,
6986: div,
6987: fieldset {
6988: margin: 10px 10px 10px 0;
6989: /* overflow: hidden; */
1.693 droeschl 6990: }
1.795 www 6991:
1.1211 raeburn 6992: article.geogebraweb div {
6993: margin: 0;
6994: }
6995:
1.838 bisitz 6996: fieldset > legend {
1.911 bisitz 6997: font-weight: bold;
6998: padding: 0 5px 0 5px;
1.838 bisitz 6999: }
7000:
1.813 bisitz 7001: #LC_nav_bar {
1.911 bisitz 7002: float: left;
1.995 raeburn 7003: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7004: margin: 0 0 2px 0;
1.807 droeschl 7005: }
7006:
1.916 droeschl 7007: #LC_realm {
7008: margin: 0.2em 0 0 0;
7009: padding: 0;
7010: font-weight: bold;
7011: text-align: center;
1.995 raeburn 7012: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7013: }
7014:
1.911 bisitz 7015: #LC_nav_bar em {
7016: font-weight: bold;
7017: font-style: normal;
1.807 droeschl 7018: }
7019:
1.897 wenzelju 7020: ol.LC_primary_menu {
1.934 droeschl 7021: margin: 0;
1.1076 raeburn 7022: padding: 0;
1.807 droeschl 7023: }
7024:
1.852 droeschl 7025: ol#LC_PathBreadcrumbs {
1.911 bisitz 7026: margin: 0;
1.693 droeschl 7027: }
7028:
1.897 wenzelju 7029: ol.LC_primary_menu li {
1.1076 raeburn 7030: color: RGB(80, 80, 80);
7031: vertical-align: middle;
7032: text-align: left;
7033: list-style: none;
1.1205 golterma 7034: position: relative;
1.1076 raeburn 7035: float: left;
1.1205 golterma 7036: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7037: line-height: 1.5em;
1.1076 raeburn 7038: }
7039:
1.1205 golterma 7040: ol.LC_primary_menu li a,
7041: ol.LC_primary_menu li p {
1.1076 raeburn 7042: display: block;
7043: margin: 0;
7044: padding: 0 5px 0 10px;
7045: text-decoration: none;
7046: }
7047:
1.1205 golterma 7048: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7049: display: inline-block;
7050: width: 95%;
7051: text-align: left;
7052: }
7053:
7054: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7055: display: inline-block;
7056: width: 5%;
7057: float: right;
7058: text-align: right;
7059: font-size: 70%;
7060: }
7061:
7062: ol.LC_primary_menu ul {
1.1076 raeburn 7063: display: none;
1.1205 golterma 7064: width: 15em;
1.1076 raeburn 7065: background-color: $data_table_light;
1.1205 golterma 7066: position: absolute;
7067: top: 100%;
1.1076 raeburn 7068: }
7069:
1.1205 golterma 7070: ol.LC_primary_menu ul ul {
7071: left: 100%;
7072: top: 0;
7073: }
7074:
7075: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7076: display: block;
7077: position: absolute;
7078: margin: 0;
7079: padding: 0;
1.1078 raeburn 7080: z-index: 2;
1.1076 raeburn 7081: }
7082:
7083: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7084: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7085: font-size: 90%;
1.911 bisitz 7086: vertical-align: top;
1.1076 raeburn 7087: float: none;
1.1079 raeburn 7088: border-left: 1px solid black;
7089: border-right: 1px solid black;
1.1205 golterma 7090: /* A dark bottom border to visualize different menu options;
7091: overwritten in the create_submenu routine for the last border-bottom of the menu */
7092: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7093: }
7094:
1.1205 golterma 7095: ol.LC_primary_menu li li p:hover {
7096: color:$button_hover;
7097: text-decoration:none;
7098: background-color:$data_table_dark;
1.1076 raeburn 7099: }
7100:
7101: ol.LC_primary_menu li li a:hover {
7102: color:$button_hover;
7103: background-color:$data_table_dark;
1.693 droeschl 7104: }
7105:
1.1205 golterma 7106: /* Font-size equal to the size of the predecessors*/
7107: ol.LC_primary_menu li:hover li li {
7108: font-size: 100%;
7109: }
7110:
1.897 wenzelju 7111: ol.LC_primary_menu li img {
1.911 bisitz 7112: vertical-align: bottom;
1.934 droeschl 7113: height: 1.1em;
1.1077 raeburn 7114: margin: 0.2em 0 0 0;
1.693 droeschl 7115: }
7116:
1.897 wenzelju 7117: ol.LC_primary_menu a {
1.911 bisitz 7118: color: RGB(80, 80, 80);
7119: text-decoration: none;
1.693 droeschl 7120: }
1.795 www 7121:
1.949 droeschl 7122: ol.LC_primary_menu a.LC_new_message {
7123: font-weight:bold;
7124: color: darkred;
7125: }
7126:
1.975 raeburn 7127: ol.LC_docs_parameters {
7128: margin-left: 0;
7129: padding: 0;
7130: list-style: none;
7131: }
7132:
7133: ol.LC_docs_parameters li {
7134: margin: 0;
7135: padding-right: 20px;
7136: display: inline;
7137: }
7138:
1.976 raeburn 7139: ol.LC_docs_parameters li:before {
7140: content: "\\002022 \\0020";
7141: }
7142:
7143: li.LC_docs_parameters_title {
7144: font-weight: bold;
7145: }
7146:
7147: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7148: content: "";
7149: }
7150:
1.897 wenzelju 7151: ul#LC_secondary_menu {
1.1107 raeburn 7152: clear: right;
1.911 bisitz 7153: color: $fontmenu;
7154: background: $tabbg;
7155: list-style: none;
7156: padding: 0;
7157: margin: 0;
7158: width: 100%;
1.995 raeburn 7159: text-align: left;
1.1107 raeburn 7160: float: left;
1.808 droeschl 7161: }
7162:
1.897 wenzelju 7163: ul#LC_secondary_menu li {
1.911 bisitz 7164: font-weight: bold;
7165: line-height: 1.8em;
1.1107 raeburn 7166: border-right: 1px solid black;
7167: float: left;
7168: }
7169:
7170: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7171: background-color: $data_table_light;
7172: }
7173:
7174: ul#LC_secondary_menu li a {
1.911 bisitz 7175: padding: 0 0.8em;
1.1107 raeburn 7176: }
7177:
7178: ul#LC_secondary_menu li ul {
7179: display: none;
7180: }
7181:
7182: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7183: display: block;
7184: position: absolute;
7185: margin: 0;
7186: padding: 0;
7187: list-style:none;
7188: float: none;
7189: background-color: $data_table_light;
7190: z-index: 2;
7191: margin-left: -1px;
7192: }
7193:
7194: ul#LC_secondary_menu li ul li {
7195: font-size: 90%;
7196: vertical-align: top;
7197: border-left: 1px solid black;
1.911 bisitz 7198: border-right: 1px solid black;
1.1119 raeburn 7199: background-color: $data_table_light;
1.1107 raeburn 7200: list-style:none;
7201: float: none;
7202: }
7203:
7204: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7205: background-color: $data_table_dark;
1.807 droeschl 7206: }
7207:
1.847 tempelho 7208: ul.LC_TabContent {
1.911 bisitz 7209: display:block;
7210: background: $sidebg;
7211: border-bottom: solid 1px $lg_border_color;
7212: list-style:none;
1.1020 raeburn 7213: margin: -1px -10px 0 -10px;
1.911 bisitz 7214: padding: 0;
1.693 droeschl 7215: }
7216:
1.795 www 7217: ul.LC_TabContent li,
7218: ul.LC_TabContentBigger li {
1.911 bisitz 7219: float:left;
1.741 harmsja 7220: }
1.795 www 7221:
1.897 wenzelju 7222: ul#LC_secondary_menu li a {
1.911 bisitz 7223: color: $fontmenu;
7224: text-decoration: none;
1.693 droeschl 7225: }
1.795 www 7226:
1.721 harmsja 7227: ul.LC_TabContent {
1.952 onken 7228: min-height:20px;
1.721 harmsja 7229: }
1.795 www 7230:
7231: ul.LC_TabContent li {
1.911 bisitz 7232: vertical-align:middle;
1.959 onken 7233: padding: 0 16px 0 10px;
1.911 bisitz 7234: background-color:$tabbg;
7235: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7236: border-left: solid 1px $font;
1.721 harmsja 7237: }
1.795 www 7238:
1.847 tempelho 7239: ul.LC_TabContent .right {
1.911 bisitz 7240: float:right;
1.847 tempelho 7241: }
7242:
1.911 bisitz 7243: ul.LC_TabContent li a,
7244: ul.LC_TabContent li {
7245: color:rgb(47,47,47);
7246: text-decoration:none;
7247: font-size:95%;
7248: font-weight:bold;
1.952 onken 7249: min-height:20px;
7250: }
7251:
1.959 onken 7252: ul.LC_TabContent li a:hover,
7253: ul.LC_TabContent li a:focus {
1.952 onken 7254: color: $button_hover;
1.959 onken 7255: background:none;
7256: outline:none;
1.952 onken 7257: }
7258:
7259: ul.LC_TabContent li:hover {
7260: color: $button_hover;
7261: cursor:pointer;
1.721 harmsja 7262: }
1.795 www 7263:
1.911 bisitz 7264: ul.LC_TabContent li.active {
1.952 onken 7265: color: $font;
1.911 bisitz 7266: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7267: border-bottom:solid 1px #FFFFFF;
7268: cursor: default;
1.744 ehlerst 7269: }
1.795 www 7270:
1.959 onken 7271: ul.LC_TabContent li.active a {
7272: color:$font;
7273: background:#FFFFFF;
7274: outline: none;
7275: }
1.1047 raeburn 7276:
7277: ul.LC_TabContent li.goback {
7278: float: left;
7279: border-left: none;
7280: }
7281:
1.870 tempelho 7282: #maincoursedoc {
1.911 bisitz 7283: clear:both;
1.870 tempelho 7284: }
7285:
7286: ul.LC_TabContentBigger {
1.911 bisitz 7287: display:block;
7288: list-style:none;
7289: padding: 0;
1.870 tempelho 7290: }
7291:
1.795 www 7292: ul.LC_TabContentBigger li {
1.911 bisitz 7293: vertical-align:bottom;
7294: height: 30px;
7295: font-size:110%;
7296: font-weight:bold;
7297: color: #737373;
1.841 tempelho 7298: }
7299:
1.957 onken 7300: ul.LC_TabContentBigger li.active {
7301: position: relative;
7302: top: 1px;
7303: }
7304:
1.870 tempelho 7305: ul.LC_TabContentBigger li a {
1.911 bisitz 7306: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7307: height: 30px;
7308: line-height: 30px;
7309: text-align: center;
7310: display: block;
7311: text-decoration: none;
1.958 onken 7312: outline: none;
1.741 harmsja 7313: }
1.795 www 7314:
1.870 tempelho 7315: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7316: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7317: color:$font;
1.744 ehlerst 7318: }
1.795 www 7319:
1.870 tempelho 7320: ul.LC_TabContentBigger li b {
1.911 bisitz 7321: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7322: display: block;
7323: float: left;
7324: padding: 0 30px;
1.957 onken 7325: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7326: }
7327:
1.956 onken 7328: ul.LC_TabContentBigger li:hover b {
7329: color:$button_hover;
7330: }
7331:
1.870 tempelho 7332: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7333: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7334: color:$font;
1.957 onken 7335: border: 0;
1.741 harmsja 7336: }
1.693 droeschl 7337:
1.870 tempelho 7338:
1.862 bisitz 7339: ul.LC_CourseBreadcrumbs {
7340: background: $sidebg;
1.1020 raeburn 7341: height: 2em;
1.862 bisitz 7342: padding-left: 10px;
1.1020 raeburn 7343: margin: 0;
1.862 bisitz 7344: list-style-position: inside;
7345: }
7346:
1.911 bisitz 7347: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7348: ol#LC_PathBreadcrumbs {
1.911 bisitz 7349: padding-left: 10px;
7350: margin: 0;
1.933 droeschl 7351: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7352: }
7353:
1.911 bisitz 7354: ol#LC_MenuBreadcrumbs li,
7355: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7356: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7357: display: inline;
1.933 droeschl 7358: white-space: normal;
1.693 droeschl 7359: }
7360:
1.823 bisitz 7361: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7362: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7363: text-decoration: none;
7364: font-size:90%;
1.693 droeschl 7365: }
1.795 www 7366:
1.969 droeschl 7367: ol#LC_MenuBreadcrumbs h1 {
7368: display: inline;
7369: font-size: 90%;
7370: line-height: 2.5em;
7371: margin: 0;
7372: padding: 0;
7373: }
7374:
1.795 www 7375: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7376: text-decoration:none;
7377: font-size:100%;
7378: font-weight:bold;
1.693 droeschl 7379: }
1.795 www 7380:
1.840 bisitz 7381: .LC_Box {
1.911 bisitz 7382: border: solid 1px $lg_border_color;
7383: padding: 0 10px 10px 10px;
1.746 neumanie 7384: }
1.795 www 7385:
1.1020 raeburn 7386: .LC_DocsBox {
7387: border: solid 1px $lg_border_color;
7388: padding: 0 0 10px 10px;
7389: }
7390:
1.795 www 7391: .LC_AboutMe_Image {
1.911 bisitz 7392: float:left;
7393: margin-right:10px;
1.747 neumanie 7394: }
1.795 www 7395:
7396: .LC_Clear_AboutMe_Image {
1.911 bisitz 7397: clear:left;
1.747 neumanie 7398: }
1.795 www 7399:
1.721 harmsja 7400: dl.LC_ListStyleClean dt {
1.911 bisitz 7401: padding-right: 5px;
7402: display: table-header-group;
1.693 droeschl 7403: }
7404:
1.721 harmsja 7405: dl.LC_ListStyleClean dd {
1.911 bisitz 7406: display: table-row;
1.693 droeschl 7407: }
7408:
1.721 harmsja 7409: .LC_ListStyleClean,
7410: .LC_ListStyleSimple,
7411: .LC_ListStyleNormal,
1.795 www 7412: .LC_ListStyleSpecial {
1.911 bisitz 7413: /* display:block; */
7414: list-style-position: inside;
7415: list-style-type: none;
7416: overflow: hidden;
7417: padding: 0;
1.693 droeschl 7418: }
7419:
1.721 harmsja 7420: .LC_ListStyleSimple li,
7421: .LC_ListStyleSimple dd,
7422: .LC_ListStyleNormal li,
7423: .LC_ListStyleNormal dd,
7424: .LC_ListStyleSpecial li,
1.795 www 7425: .LC_ListStyleSpecial dd {
1.911 bisitz 7426: margin: 0;
7427: padding: 5px 5px 5px 10px;
7428: clear: both;
1.693 droeschl 7429: }
7430:
1.721 harmsja 7431: .LC_ListStyleClean li,
7432: .LC_ListStyleClean dd {
1.911 bisitz 7433: padding-top: 0;
7434: padding-bottom: 0;
1.693 droeschl 7435: }
7436:
1.721 harmsja 7437: .LC_ListStyleSimple dd,
1.795 www 7438: .LC_ListStyleSimple li {
1.911 bisitz 7439: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7440: }
7441:
1.721 harmsja 7442: .LC_ListStyleSpecial li,
7443: .LC_ListStyleSpecial dd {
1.911 bisitz 7444: list-style-type: none;
7445: background-color: RGB(220, 220, 220);
7446: margin-bottom: 4px;
1.693 droeschl 7447: }
7448:
1.721 harmsja 7449: table.LC_SimpleTable {
1.911 bisitz 7450: margin:5px;
7451: border:solid 1px $lg_border_color;
1.795 www 7452: }
1.693 droeschl 7453:
1.721 harmsja 7454: table.LC_SimpleTable tr {
1.911 bisitz 7455: padding: 0;
7456: border:solid 1px $lg_border_color;
1.693 droeschl 7457: }
1.795 www 7458:
7459: table.LC_SimpleTable thead {
1.911 bisitz 7460: background:rgb(220,220,220);
1.693 droeschl 7461: }
7462:
1.721 harmsja 7463: div.LC_columnSection {
1.911 bisitz 7464: display: block;
7465: clear: both;
7466: overflow: hidden;
7467: margin: 0;
1.693 droeschl 7468: }
7469:
1.721 harmsja 7470: div.LC_columnSection>* {
1.911 bisitz 7471: float: left;
7472: margin: 10px 20px 10px 0;
7473: overflow:hidden;
1.693 droeschl 7474: }
1.721 harmsja 7475:
1.795 www 7476: table em {
1.911 bisitz 7477: font-weight: bold;
7478: font-style: normal;
1.748 schulted 7479: }
1.795 www 7480:
1.779 bisitz 7481: table.LC_tableBrowseRes,
1.795 www 7482: table.LC_tableOfContent {
1.911 bisitz 7483: border:none;
7484: border-spacing: 1px;
7485: padding: 3px;
7486: background-color: #FFFFFF;
7487: font-size: 90%;
1.753 droeschl 7488: }
1.789 droeschl 7489:
1.911 bisitz 7490: table.LC_tableOfContent {
7491: border-collapse: collapse;
1.789 droeschl 7492: }
7493:
1.771 droeschl 7494: table.LC_tableBrowseRes a,
1.768 schulted 7495: table.LC_tableOfContent a {
1.911 bisitz 7496: background-color: transparent;
7497: text-decoration: none;
1.753 droeschl 7498: }
7499:
1.795 www 7500: table.LC_tableOfContent img {
1.911 bisitz 7501: border: none;
7502: height: 1.3em;
7503: vertical-align: text-bottom;
7504: margin-right: 0.3em;
1.753 droeschl 7505: }
1.757 schulted 7506:
1.795 www 7507: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7508: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7509: }
7510:
1.795 www 7511: a#LC_content_toolbar_everything {
1.911 bisitz 7512: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7513: }
7514:
1.795 www 7515: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7516: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7517: }
7518:
1.795 www 7519: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7520: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7521: }
7522:
1.795 www 7523: a#LC_content_toolbar_changefolder {
1.911 bisitz 7524: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7525: }
7526:
1.795 www 7527: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7528: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7529: }
7530:
1.1043 raeburn 7531: a#LC_content_toolbar_edittoplevel {
7532: background-image:url(/res/adm/pages/edittoplevel.gif);
7533: }
7534:
1.795 www 7535: ul#LC_toolbar li a:hover {
1.911 bisitz 7536: background-position: bottom center;
1.757 schulted 7537: }
7538:
1.795 www 7539: ul#LC_toolbar {
1.911 bisitz 7540: padding: 0;
7541: margin: 2px;
7542: list-style:none;
7543: position:relative;
7544: background-color:white;
1.1082 raeburn 7545: overflow: auto;
1.757 schulted 7546: }
7547:
1.795 www 7548: ul#LC_toolbar li {
1.911 bisitz 7549: border:1px solid white;
7550: padding: 0;
7551: margin: 0;
7552: float: left;
7553: display:inline;
7554: vertical-align:middle;
1.1082 raeburn 7555: white-space: nowrap;
1.911 bisitz 7556: }
1.757 schulted 7557:
1.783 amueller 7558:
1.795 www 7559: a.LC_toolbarItem {
1.911 bisitz 7560: display:block;
7561: padding: 0;
7562: margin: 0;
7563: height: 32px;
7564: width: 32px;
7565: color:white;
7566: border: none;
7567: background-repeat:no-repeat;
7568: background-color:transparent;
1.757 schulted 7569: }
7570:
1.915 droeschl 7571: ul.LC_funclist {
7572: margin: 0;
7573: padding: 0.5em 1em 0.5em 0;
7574: }
7575:
1.933 droeschl 7576: ul.LC_funclist > li:first-child {
7577: font-weight:bold;
7578: margin-left:0.8em;
7579: }
7580:
1.915 droeschl 7581: ul.LC_funclist + ul.LC_funclist {
7582: /*
7583: left border as a seperator if we have more than
7584: one list
7585: */
7586: border-left: 1px solid $sidebg;
7587: /*
7588: this hides the left border behind the border of the
7589: outer box if element is wrapped to the next 'line'
7590: */
7591: margin-left: -1px;
7592: }
7593:
1.843 bisitz 7594: ul.LC_funclist li {
1.915 droeschl 7595: display: inline;
1.782 bisitz 7596: white-space: nowrap;
1.915 droeschl 7597: margin: 0 0 0 25px;
7598: line-height: 150%;
1.782 bisitz 7599: }
7600:
1.974 wenzelju 7601: .LC_hidden {
7602: display: none;
7603: }
7604:
1.1030 www 7605: .LCmodal-overlay {
7606: position:fixed;
7607: top:0;
7608: right:0;
7609: bottom:0;
7610: left:0;
7611: height:100%;
7612: width:100%;
7613: margin:0;
7614: padding:0;
7615: background:#999;
7616: opacity:.75;
7617: filter: alpha(opacity=75);
7618: -moz-opacity: 0.75;
7619: z-index:101;
7620: }
7621:
7622: * html .LCmodal-overlay {
7623: position: absolute;
7624: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7625: }
7626:
7627: .LCmodal-window {
7628: position:fixed;
7629: top:50%;
7630: left:50%;
7631: margin:0;
7632: padding:0;
7633: z-index:102;
7634: }
7635:
7636: * html .LCmodal-window {
7637: position:absolute;
7638: }
7639:
7640: .LCclose-window {
7641: position:absolute;
7642: width:32px;
7643: height:32px;
7644: right:8px;
7645: top:8px;
7646: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7647: text-indent:-99999px;
7648: overflow:hidden;
7649: cursor:pointer;
7650: }
7651:
1.1100 raeburn 7652: /*
1.1231 damieng 7653: styles used for response display
7654: */
7655: div.LC_radiofoil, div.LC_rankfoil {
7656: margin: .5em 0em .5em 0em;
7657: }
7658: table.LC_itemgroup {
7659: margin-top: 1em;
7660: }
7661:
7662: /*
1.1100 raeburn 7663: styles used by TTH when "Default set of options to pass to tth/m
7664: when converting TeX" in course settings has been set
7665:
7666: option passed: -t
7667:
7668: */
7669:
7670: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7671: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7672: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7673: td div.norm {line-height:normal;}
7674:
7675: /*
7676: option passed -y3
7677: */
7678:
7679: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7680: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7681: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7682:
1.1230 damieng 7683: /*
7684: sections with roles, for content only
7685: */
7686: section[class^="role-"] {
7687: padding-left: 10px;
7688: padding-right: 5px;
7689: margin-top: 8px;
7690: margin-bottom: 8px;
7691: border: 1px solid #2A4;
7692: border-radius: 5px;
7693: box-shadow: 0px 1px 1px #BBB;
7694: }
7695: section[class^="role-"]>h1 {
7696: position: relative;
7697: margin: 0px;
7698: padding-top: 10px;
7699: padding-left: 40px;
7700: }
7701: section[class^="role-"]>h1:before {
7702: position: absolute;
7703: left: -5px;
7704: top: 5px;
7705: }
7706: section.role-activity>h1:before {
7707: content:url('/adm/daxe/images/section_icons/activity.png');
7708: }
7709: section.role-advice>h1:before {
7710: content:url('/adm/daxe/images/section_icons/advice.png');
7711: }
7712: section.role-bibliography>h1:before {
7713: content:url('/adm/daxe/images/section_icons/bibliography.png');
7714: }
7715: section.role-citation>h1:before {
7716: content:url('/adm/daxe/images/section_icons/citation.png');
7717: }
7718: section.role-conclusion>h1:before {
7719: content:url('/adm/daxe/images/section_icons/conclusion.png');
7720: }
7721: section.role-definition>h1:before {
7722: content:url('/adm/daxe/images/section_icons/definition.png');
7723: }
7724: section.role-demonstration>h1:before {
7725: content:url('/adm/daxe/images/section_icons/demonstration.png');
7726: }
7727: section.role-example>h1:before {
7728: content:url('/adm/daxe/images/section_icons/example.png');
7729: }
7730: section.role-explanation>h1:before {
7731: content:url('/adm/daxe/images/section_icons/explanation.png');
7732: }
7733: section.role-introduction>h1:before {
7734: content:url('/adm/daxe/images/section_icons/introduction.png');
7735: }
7736: section.role-method>h1:before {
7737: content:url('/adm/daxe/images/section_icons/method.png');
7738: }
7739: section.role-more_information>h1:before {
7740: content:url('/adm/daxe/images/section_icons/more_information.png');
7741: }
7742: section.role-objectives>h1:before {
7743: content:url('/adm/daxe/images/section_icons/objectives.png');
7744: }
7745: section.role-prerequisites>h1:before {
7746: content:url('/adm/daxe/images/section_icons/prerequisites.png');
7747: }
7748: section.role-remark>h1:before {
7749: content:url('/adm/daxe/images/section_icons/remark.png');
7750: }
7751: section.role-reminder>h1:before {
7752: content:url('/adm/daxe/images/section_icons/reminder.png');
7753: }
7754: section.role-summary>h1:before {
7755: content:url('/adm/daxe/images/section_icons/summary.png');
7756: }
7757: section.role-syntax>h1:before {
7758: content:url('/adm/daxe/images/section_icons/syntax.png');
7759: }
7760: section.role-warning>h1:before {
7761: content:url('/adm/daxe/images/section_icons/warning.png');
7762: }
7763:
1.343 albertel 7764: END
7765: }
7766:
1.306 albertel 7767: =pod
7768:
7769: =item * &headtag()
7770:
7771: Returns a uniform footer for LON-CAPA web pages.
7772:
1.307 albertel 7773: Inputs: $title - optional title for the head
7774: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7775: $args - optional arguments
1.319 albertel 7776: force_register - if is true call registerurl so the remote is
7777: informed
1.415 albertel 7778: redirect -> array ref of
7779: 1- seconds before redirect occurs
7780: 2- url to redirect to
7781: 3- whether the side effect should occur
1.315 albertel 7782: (side effect of setting
7783: $env{'internal.head.redirect'} to the url
7784: redirected too)
1.352 albertel 7785: domain -> force to color decorate a page for a specific
7786: domain
7787: function -> force usage of a specific rolish color scheme
7788: bgcolor -> override the default page bgcolor
1.460 albertel 7789: no_auto_mt_title
7790: -> prevent &mt()ing the title arg
1.464 albertel 7791:
1.306 albertel 7792: =cut
7793:
7794: sub headtag {
1.313 albertel 7795: my ($title,$head_extra,$args) = @_;
1.306 albertel 7796:
1.363 albertel 7797: my $function = $args->{'function'} || &get_users_function();
7798: my $domain = $args->{'domain'} || &determinedomain();
7799: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 7800: my $httphost = $args->{'use_absolute'};
1.418 albertel 7801: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7802: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7803: #time(),
1.418 albertel 7804: $env{'environment.color.timestamp'},
1.363 albertel 7805: $function,$domain,$bgcolor);
7806:
1.369 www 7807: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7808:
1.308 albertel 7809: my $result =
7810: '<head>'.
1.1160 raeburn 7811: &font_settings($args);
1.319 albertel 7812:
1.1188 raeburn 7813: my $inhibitprint;
7814: if ($args->{'print_suppress'}) {
7815: $inhibitprint = &print_suppression();
7816: }
1.1064 raeburn 7817:
1.461 albertel 7818: if (!$args->{'frameset'}) {
7819: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7820: }
1.962 droeschl 7821: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
7822: $result .= Apache::lonxml::display_title();
1.319 albertel 7823: }
1.436 albertel 7824: if (!$args->{'no_nav_bar'}
7825: && !$args->{'only_body'}
7826: && !$args->{'frameset'}) {
1.1154 raeburn 7827: $result .= &help_menu_js($httphost);
1.1032 www 7828: $result.=&modal_window();
1.1038 www 7829: $result.=&togglebox_script();
1.1034 www 7830: $result.=&wishlist_window();
1.1041 www 7831: $result.=&LCprogressbarUpdate_script();
1.1034 www 7832: } else {
7833: if ($args->{'add_modal'}) {
7834: $result.=&modal_window();
7835: }
7836: if ($args->{'add_wishlist'}) {
7837: $result.=&wishlist_window();
7838: }
1.1038 www 7839: if ($args->{'add_togglebox'}) {
7840: $result.=&togglebox_script();
7841: }
1.1041 www 7842: if ($args->{'add_progressbar'}) {
7843: $result.=&LCprogressbarUpdate_script();
7844: }
1.436 albertel 7845: }
1.314 albertel 7846: if (ref($args->{'redirect'})) {
1.414 albertel 7847: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7848: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7849: if (!$inhibit_continue) {
7850: $env{'internal.head.redirect'} = $url;
7851: }
1.313 albertel 7852: $result.=<<ADDMETA
7853: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7854: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7855: ADDMETA
1.1210 raeburn 7856: } else {
7857: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
7858: my $requrl = $env{'request.uri'};
7859: if ($requrl eq '') {
7860: $requrl = $ENV{'REQUEST_URI'};
7861: $requrl =~ s/\?.+$//;
7862: }
7863: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
7864: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
7865: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
7866: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
7867: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
7868: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
7869: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
7870: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7871: if ($domdefs{'offloadnow'}{$lonhost}) {
7872: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
7873: if (($newserver) && ($newserver ne $lonhost)) {
7874: my $numsec = 5;
7875: my $timeout = $numsec * 1000;
7876: my ($newurl,$locknum,%locks,$msg);
7877: if ($env{'request.role.adv'}) {
7878: ($locknum,%locks) = &Apache::lonnet::get_locks();
7879: }
7880: my $disable_submit = 0;
7881: if ($requrl =~ /$LONCAPA::assess_re/) {
7882: $disable_submit = 1;
7883: }
7884: if ($locknum) {
7885: my @lockinfo = sort(values(%locks));
7886: $msg = &mt('Once the following tasks are complete: ')."\\n".
7887: join(", ",sort(values(%locks)))."\\n".
7888: &mt('your session will be transferred to a different server, after you click "Roles".');
7889: } else {
7890: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
7891: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
7892: }
7893: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
7894: $newurl = '/adm/switchserver?otherserver='.$newserver;
7895: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
7896: $newurl .= '&role='.$env{'request.role'};
7897: }
7898: if ($env{'request.symb'}) {
7899: $newurl .= '&symb='.$env{'request.symb'};
7900: } else {
7901: $newurl .= '&origurl='.$requrl;
7902: }
7903: }
1.1222 damieng 7904: &js_escape(\$msg);
1.1210 raeburn 7905: $result.=<<OFFLOAD
7906: <meta http-equiv="pragma" content="no-cache" />
7907: <script type="text/javascript">
1.1215 raeburn 7908: // <![CDATA[
1.1210 raeburn 7909: function LC_Offload_Now() {
7910: var dest = "$newurl";
7911: if (dest != '') {
7912: window.location.href="$newurl";
7913: }
7914: }
1.1214 raeburn 7915: \$(document).ready(function () {
7916: window.alert('$msg');
7917: if ($disable_submit) {
1.1210 raeburn 7918: \$(".LC_hwk_submit").prop("disabled", true);
7919: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 7920: }
7921: setTimeout('LC_Offload_Now()', $timeout);
7922: });
1.1215 raeburn 7923: // ]]>
1.1210 raeburn 7924: </script>
7925: OFFLOAD
7926: }
7927: }
7928: }
7929: }
7930: }
7931: }
1.313 albertel 7932: }
1.306 albertel 7933: if (!defined($title)) {
7934: $title = 'The LearningOnline Network with CAPA';
7935: }
1.460 albertel 7936: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7937: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 7938: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7939: if (!$args->{'frameset'}) {
7940: $result .= ' /';
7941: }
7942: $result .= '>'
1.1064 raeburn 7943: .$inhibitprint
1.414 albertel 7944: .$head_extra;
1.1137 raeburn 7945: if ($env{'browser.mobile'}) {
7946: $result .= '
7947: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7948: <meta name="apple-mobile-web-app-capable" content="yes" />';
7949: }
1.962 droeschl 7950: return $result.'</head>';
1.306 albertel 7951: }
7952:
7953: =pod
7954:
1.340 albertel 7955: =item * &font_settings()
7956:
7957: Returns neccessary <meta> to set the proper encoding
7958:
1.1160 raeburn 7959: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7960:
7961: =cut
7962:
7963: sub font_settings {
1.1160 raeburn 7964: my ($args) = @_;
1.340 albertel 7965: my $headerstring='';
1.1160 raeburn 7966: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7967: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 7968: $headerstring.=
7969: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7970: if (!$args->{'frameset'}) {
7971: $headerstring.= ' /';
7972: }
7973: $headerstring .= '>'."\n";
1.340 albertel 7974: }
7975: return $headerstring;
7976: }
7977:
1.341 albertel 7978: =pod
7979:
1.1064 raeburn 7980: =item * &print_suppression()
7981:
7982: In course context returns css which causes the body to be blank when media="print",
7983: if printout generation is unavailable for the current resource.
7984:
7985: This could be because:
7986:
7987: (a) printstartdate is in the future
7988:
7989: (b) printenddate is in the past
7990:
7991: (c) there is an active exam block with "printout"
7992: functionality blocked
7993:
7994: Users with pav, pfo or evb privileges are exempt.
7995:
7996: Inputs: none
7997:
7998: =cut
7999:
8000:
8001: sub print_suppression {
8002: my $noprint;
8003: if ($env{'request.course.id'}) {
8004: my $scope = $env{'request.course.id'};
8005: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8006: (&Apache::lonnet::allowed('pfo',$scope))) {
8007: return;
8008: }
8009: if ($env{'request.course.sec'} ne '') {
8010: $scope .= "/$env{'request.course.sec'}";
8011: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8012: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8013: return;
1.1064 raeburn 8014: }
8015: }
8016: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8017: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8018: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8019: if ($blocked) {
8020: my $checkrole = "cm./$cdom/$cnum";
8021: if ($env{'request.course.sec'} ne '') {
8022: $checkrole .= "/$env{'request.course.sec'}";
8023: }
8024: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8025: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8026: $noprint = 1;
8027: }
8028: }
8029: unless ($noprint) {
8030: my $symb = &Apache::lonnet::symbread();
8031: if ($symb ne '') {
8032: my $navmap = Apache::lonnavmaps::navmap->new();
8033: if (ref($navmap)) {
8034: my $res = $navmap->getBySymb($symb);
8035: if (ref($res)) {
8036: if (!$res->resprintable()) {
8037: $noprint = 1;
8038: }
8039: }
8040: }
8041: }
8042: }
8043: if ($noprint) {
8044: return <<"ENDSTYLE";
8045: <style type="text/css" media="print">
8046: body { display:none }
8047: </style>
8048: ENDSTYLE
8049: }
8050: }
8051: return;
8052: }
8053:
8054: =pod
8055:
1.341 albertel 8056: =item * &xml_begin()
8057:
8058: Returns the needed doctype and <html>
8059:
8060: Inputs: none
8061:
8062: =cut
8063:
8064: sub xml_begin {
1.1168 raeburn 8065: my ($is_frameset) = @_;
1.341 albertel 8066: my $output='';
8067:
8068: if ($env{'browser.mathml'}) {
8069: $output='<?xml version="1.0"?>'
8070: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8071: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8072:
8073: # .'<!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">] >'
8074: .'<!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">'
8075: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8076: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8077: } elsif ($is_frameset) {
8078: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8079: '<html>'."\n";
1.341 albertel 8080: } else {
1.1168 raeburn 8081: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8082: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8083: }
8084: return $output;
8085: }
1.340 albertel 8086:
8087: =pod
8088:
1.306 albertel 8089: =item * &start_page()
8090:
8091: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8092:
1.648 raeburn 8093: Inputs:
8094:
8095: =over 4
8096:
8097: $title - optional title for the page
8098:
8099: $head_extra - optional extra HTML to incude inside the <head>
8100:
8101: $args - additional optional args supported are:
8102:
8103: =over 8
8104:
8105: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8106: arg on
1.814 bisitz 8107: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8108: add_entries -> additional attributes to add to the <body>
8109: domain -> force to color decorate a page for a
1.317 albertel 8110: specific domain
1.648 raeburn 8111: function -> force usage of a specific rolish color
1.317 albertel 8112: scheme
1.648 raeburn 8113: redirect -> see &headtag()
8114: bgcolor -> override the default page bg color
8115: js_ready -> return a string ready for being used in
1.317 albertel 8116: a javascript writeln
1.648 raeburn 8117: html_encode -> return a string ready for being used in
1.320 albertel 8118: a html attribute
1.648 raeburn 8119: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8120: $forcereg arg
1.648 raeburn 8121: frameset -> if true will start with a <frameset>
1.330 albertel 8122: rather than <body>
1.648 raeburn 8123: skip_phases -> hash ref of
1.338 albertel 8124: head -> skip the <html><head> generation
8125: body -> skip all <body> generation
1.648 raeburn 8126: no_auto_mt_title -> prevent &mt()ing the title arg
8127: inherit_jsmath -> when creating popup window in a page,
8128: should it have jsmath forced on by the
8129: current page
1.867 kalberla 8130: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8131: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1096 raeburn 8132: group -> includes the current group, if page is for a
8133: specific group
1.361 albertel 8134:
1.648 raeburn 8135: =back
1.460 albertel 8136:
1.648 raeburn 8137: =back
1.562 albertel 8138:
1.306 albertel 8139: =cut
8140:
8141: sub start_page {
1.309 albertel 8142: my ($title,$head_extra,$args) = @_;
1.318 albertel 8143: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8144:
1.315 albertel 8145: $env{'internal.start_page'}++;
1.1096 raeburn 8146: my ($result,@advtools);
1.964 droeschl 8147:
1.338 albertel 8148: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8149: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8150: }
8151:
8152: if (! exists($args->{'skip_phases'}{'body'}) ) {
8153: if ($args->{'frameset'}) {
8154: my $attr_string = &make_attr_string($args->{'force_register'},
8155: $args->{'add_entries'});
8156: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8157: } else {
8158: $result .=
8159: &bodytag($title,
8160: $args->{'function'}, $args->{'add_entries'},
8161: $args->{'only_body'}, $args->{'domain'},
8162: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8163: $args->{'bgcolor'}, $args,
8164: \@advtools);
1.831 bisitz 8165: }
1.330 albertel 8166: }
1.338 albertel 8167:
1.315 albertel 8168: if ($args->{'js_ready'}) {
1.713 kaisler 8169: $result = &js_ready($result);
1.315 albertel 8170: }
1.320 albertel 8171: if ($args->{'html_encode'}) {
1.713 kaisler 8172: $result = &html_encode($result);
8173: }
8174:
1.813 bisitz 8175: # Preparation for new and consistent functionlist at top of screen
8176: # if ($args->{'functionlist'}) {
8177: # $result .= &build_functionlist();
8178: #}
8179:
1.964 droeschl 8180: # Don't add anything more if only_body wanted or in const space
8181: return $result if $args->{'only_body'}
8182: || $env{'request.state'} eq 'construct';
1.813 bisitz 8183:
8184: #Breadcrumbs
1.758 kaisler 8185: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8186: &Apache::lonhtmlcommon::clear_breadcrumbs();
8187: #if any br links exists, add them to the breadcrumbs
8188: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8189: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8190: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8191: }
8192: }
1.1096 raeburn 8193: # if @advtools array contains items add then to the breadcrumbs
8194: if (@advtools > 0) {
8195: &Apache::lonmenu::advtools_crumbs(@advtools);
8196: }
1.758 kaisler 8197:
8198: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8199: if(exists($args->{'bread_crumbs_component'})){
8200: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
8201: }else{
8202: $result .= &Apache::lonhtmlcommon::breadcrumbs();
8203: }
1.320 albertel 8204: }
1.315 albertel 8205: return $result;
1.306 albertel 8206: }
8207:
8208: sub end_page {
1.315 albertel 8209: my ($args) = @_;
8210: $env{'internal.end_page'}++;
1.330 albertel 8211: my $result;
1.335 albertel 8212: if ($args->{'discussion'}) {
8213: my ($target,$parser);
8214: if (ref($args->{'discussion'})) {
8215: ($target,$parser) =($args->{'discussion'}{'target'},
8216: $args->{'discussion'}{'parser'});
8217: }
8218: $result .= &Apache::lonxml::xmlend($target,$parser);
8219: }
1.330 albertel 8220: if ($args->{'frameset'}) {
8221: $result .= '</frameset>';
8222: } else {
1.635 raeburn 8223: $result .= &endbodytag($args);
1.330 albertel 8224: }
1.1080 raeburn 8225: unless ($args->{'notbody'}) {
8226: $result .= "\n</html>";
8227: }
1.330 albertel 8228:
1.315 albertel 8229: if ($args->{'js_ready'}) {
1.317 albertel 8230: $result = &js_ready($result);
1.315 albertel 8231: }
1.335 albertel 8232:
1.320 albertel 8233: if ($args->{'html_encode'}) {
8234: $result = &html_encode($result);
8235: }
1.335 albertel 8236:
1.315 albertel 8237: return $result;
8238: }
8239:
1.1034 www 8240: sub wishlist_window {
8241: return(<<'ENDWISHLIST');
1.1046 raeburn 8242: <script type="text/javascript">
1.1034 www 8243: // <![CDATA[
8244: // <!-- BEGIN LON-CAPA Internal
8245: function set_wishlistlink(title, path) {
8246: if (!title) {
8247: title = document.title;
8248: title = title.replace(/^LON-CAPA /,'');
8249: }
1.1175 raeburn 8250: title = encodeURIComponent(title);
1.1203 raeburn 8251: title = title.replace("'","\\\'");
1.1034 www 8252: if (!path) {
8253: path = location.pathname;
8254: }
1.1175 raeburn 8255: path = encodeURIComponent(path);
1.1203 raeburn 8256: path = path.replace("'","\\\'");
1.1034 www 8257: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8258: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8259: }
8260: // END LON-CAPA Internal -->
8261: // ]]>
8262: </script>
8263: ENDWISHLIST
8264: }
8265:
1.1030 www 8266: sub modal_window {
8267: return(<<'ENDMODAL');
1.1046 raeburn 8268: <script type="text/javascript">
1.1030 www 8269: // <![CDATA[
8270: // <!-- BEGIN LON-CAPA Internal
8271: var modalWindow = {
8272: parent:"body",
8273: windowId:null,
8274: content:null,
8275: width:null,
8276: height:null,
8277: close:function()
8278: {
8279: $(".LCmodal-window").remove();
8280: $(".LCmodal-overlay").remove();
8281: },
8282: open:function()
8283: {
8284: var modal = "";
8285: modal += "<div class=\"LCmodal-overlay\"></div>";
8286: 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;\">";
8287: modal += this.content;
8288: modal += "</div>";
8289:
8290: $(this.parent).append(modal);
8291:
8292: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8293: $(".LCclose-window").click(function(){modalWindow.close();});
8294: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8295: }
8296: };
1.1140 raeburn 8297: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8298: {
1.1203 raeburn 8299: source = source.replace("'","'");
1.1030 www 8300: modalWindow.windowId = "myModal";
8301: modalWindow.width = width;
8302: modalWindow.height = height;
1.1196 raeburn 8303: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8304: modalWindow.open();
1.1208 raeburn 8305: };
1.1030 www 8306: // END LON-CAPA Internal -->
8307: // ]]>
8308: </script>
8309: ENDMODAL
8310: }
8311:
8312: sub modal_link {
1.1140 raeburn 8313: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8314: unless ($width) { $width=480; }
8315: unless ($height) { $height=400; }
1.1031 www 8316: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 8317: unless ($transparency) { $transparency='true'; }
8318:
1.1074 raeburn 8319: my $target_attr;
8320: if (defined($target)) {
8321: $target_attr = 'target="'.$target.'"';
8322: }
8323: return <<"ENDLINK";
1.1140 raeburn 8324: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8325: $linktext</a>
8326: ENDLINK
1.1030 www 8327: }
8328:
1.1032 www 8329: sub modal_adhoc_script {
8330: my ($funcname,$width,$height,$content)=@_;
8331: return (<<ENDADHOC);
1.1046 raeburn 8332: <script type="text/javascript">
1.1032 www 8333: // <![CDATA[
8334: var $funcname = function()
8335: {
8336: modalWindow.windowId = "myModal";
8337: modalWindow.width = $width;
8338: modalWindow.height = $height;
8339: modalWindow.content = '$content';
8340: modalWindow.open();
8341: };
8342: // ]]>
8343: </script>
8344: ENDADHOC
8345: }
8346:
1.1041 www 8347: sub modal_adhoc_inner {
8348: my ($funcname,$width,$height,$content)=@_;
8349: my $innerwidth=$width-20;
8350: $content=&js_ready(
1.1140 raeburn 8351: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
8352: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8353: $content.
1.1041 www 8354: &end_scrollbox().
1.1140 raeburn 8355: &end_page()
1.1041 www 8356: );
8357: return &modal_adhoc_script($funcname,$width,$height,$content);
8358: }
8359:
8360: sub modal_adhoc_window {
8361: my ($funcname,$width,$height,$content,$linktext)=@_;
8362: return &modal_adhoc_inner($funcname,$width,$height,$content).
8363: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8364: }
8365:
8366: sub modal_adhoc_launch {
8367: my ($funcname,$width,$height,$content)=@_;
8368: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8369: <script type="text/javascript">
8370: // <![CDATA[
8371: $funcname();
8372: // ]]>
8373: </script>
8374: ENDLAUNCH
8375: }
8376:
8377: sub modal_adhoc_close {
8378: return (<<ENDCLOSE);
8379: <script type="text/javascript">
8380: // <![CDATA[
8381: modalWindow.close();
8382: // ]]>
8383: </script>
8384: ENDCLOSE
8385: }
8386:
1.1038 www 8387: sub togglebox_script {
8388: return(<<ENDTOGGLE);
8389: <script type="text/javascript">
8390: // <![CDATA[
8391: function LCtoggleDisplay(id,hidetext,showtext) {
8392: link = document.getElementById(id + "link").childNodes[0];
8393: with (document.getElementById(id).style) {
8394: if (display == "none" ) {
8395: display = "inline";
8396: link.nodeValue = hidetext;
8397: } else {
8398: display = "none";
8399: link.nodeValue = showtext;
8400: }
8401: }
8402: }
8403: // ]]>
8404: </script>
8405: ENDTOGGLE
8406: }
8407:
1.1039 www 8408: sub start_togglebox {
8409: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8410: unless ($heading) { $heading=''; } else { $heading.=' '; }
8411: unless ($showtext) { $showtext=&mt('show'); }
8412: unless ($hidetext) { $hidetext=&mt('hide'); }
8413: unless ($headerbg) { $headerbg='#FFFFFF'; }
8414: return &start_data_table().
8415: &start_data_table_header_row().
8416: '<td bgcolor="'.$headerbg.'">'.$heading.
8417: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8418: $showtext.'\')">'.$showtext.'</a>]</td>'.
8419: &end_data_table_header_row().
8420: '<tr id="'.$id.'" style="display:none""><td>';
8421: }
8422:
8423: sub end_togglebox {
8424: return '</td></tr>'.&end_data_table();
8425: }
8426:
1.1041 www 8427: sub LCprogressbar_script {
1.1045 www 8428: my ($id)=@_;
1.1041 www 8429: return(<<ENDPROGRESS);
8430: <script type="text/javascript">
8431: // <![CDATA[
1.1045 www 8432: \$('#progressbar$id').progressbar({
1.1041 www 8433: value: 0,
8434: change: function(event, ui) {
8435: var newVal = \$(this).progressbar('option', 'value');
8436: \$('.pblabel', this).text(LCprogressTxt);
8437: }
8438: });
8439: // ]]>
8440: </script>
8441: ENDPROGRESS
8442: }
8443:
8444: sub LCprogressbarUpdate_script {
8445: return(<<ENDPROGRESSUPDATE);
8446: <style type="text/css">
8447: .ui-progressbar { position:relative; }
8448: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8449: </style>
8450: <script type="text/javascript">
8451: // <![CDATA[
1.1045 www 8452: var LCprogressTxt='---';
8453:
8454: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8455: LCprogressTxt=progresstext;
1.1045 www 8456: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8457: }
8458: // ]]>
8459: </script>
8460: ENDPROGRESSUPDATE
8461: }
8462:
1.1042 www 8463: my $LClastpercent;
1.1045 www 8464: my $LCidcnt;
8465: my $LCcurrentid;
1.1042 www 8466:
1.1041 www 8467: sub LCprogressbar {
1.1042 www 8468: my ($r)=(@_);
8469: $LClastpercent=0;
1.1045 www 8470: $LCidcnt++;
8471: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8472: my $starting=&mt('Starting');
8473: my $content=(<<ENDPROGBAR);
1.1045 www 8474: <div id="progressbar$LCcurrentid">
1.1041 www 8475: <span class="pblabel">$starting</span>
8476: </div>
8477: ENDPROGBAR
1.1045 www 8478: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8479: }
8480:
8481: sub LCprogressbarUpdate {
1.1042 www 8482: my ($r,$val,$text)=@_;
8483: unless ($val) {
8484: if ($LClastpercent) {
8485: $val=$LClastpercent;
8486: } else {
8487: $val=0;
8488: }
8489: }
1.1041 www 8490: if ($val<0) { $val=0; }
8491: if ($val>100) { $val=0; }
1.1042 www 8492: $LClastpercent=$val;
1.1041 www 8493: unless ($text) { $text=$val.'%'; }
8494: $text=&js_ready($text);
1.1044 www 8495: &r_print($r,<<ENDUPDATE);
1.1041 www 8496: <script type="text/javascript">
8497: // <![CDATA[
1.1045 www 8498: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8499: // ]]>
8500: </script>
8501: ENDUPDATE
1.1035 www 8502: }
8503:
1.1042 www 8504: sub LCprogressbarClose {
8505: my ($r)=@_;
8506: $LClastpercent=0;
1.1044 www 8507: &r_print($r,<<ENDCLOSE);
1.1042 www 8508: <script type="text/javascript">
8509: // <![CDATA[
1.1045 www 8510: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8511: // ]]>
8512: </script>
8513: ENDCLOSE
1.1044 www 8514: }
8515:
8516: sub r_print {
8517: my ($r,$to_print)=@_;
8518: if ($r) {
8519: $r->print($to_print);
8520: $r->rflush();
8521: } else {
8522: print($to_print);
8523: }
1.1042 www 8524: }
8525:
1.320 albertel 8526: sub html_encode {
8527: my ($result) = @_;
8528:
1.322 albertel 8529: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8530:
8531: return $result;
8532: }
1.1044 www 8533:
1.317 albertel 8534: sub js_ready {
8535: my ($result) = @_;
8536:
1.323 albertel 8537: $result =~ s/[\n\r]/ /xmsg;
8538: $result =~ s/\\/\\\\/xmsg;
8539: $result =~ s/'/\\'/xmsg;
1.372 albertel 8540: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8541:
8542: return $result;
8543: }
8544:
1.315 albertel 8545: sub validate_page {
8546: if ( exists($env{'internal.start_page'})
1.316 albertel 8547: && $env{'internal.start_page'} > 1) {
8548: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8549: $env{'internal.start_page'}.' '.
1.316 albertel 8550: $ENV{'request.filename'});
1.315 albertel 8551: }
8552: if ( exists($env{'internal.end_page'})
1.316 albertel 8553: && $env{'internal.end_page'} > 1) {
8554: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8555: $env{'internal.end_page'}.' '.
1.316 albertel 8556: $env{'request.filename'});
1.315 albertel 8557: }
8558: if ( exists($env{'internal.start_page'})
8559: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8560: &Apache::lonnet::logthis('start_page called without end_page '.
8561: $env{'request.filename'});
1.315 albertel 8562: }
8563: if ( ! exists($env{'internal.start_page'})
8564: && exists($env{'internal.end_page'})) {
1.316 albertel 8565: &Apache::lonnet::logthis('end_page called without start_page'.
8566: $env{'request.filename'});
1.315 albertel 8567: }
1.306 albertel 8568: }
1.315 albertel 8569:
1.996 www 8570:
8571: sub start_scrollbox {
1.1140 raeburn 8572: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8573: unless ($outerwidth) { $outerwidth='520px'; }
8574: unless ($width) { $width='500px'; }
8575: unless ($height) { $height='200px'; }
1.1075 raeburn 8576: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8577: if ($id ne '') {
1.1140 raeburn 8578: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 8579: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8580: }
1.1075 raeburn 8581: if ($bgcolor ne '') {
8582: $tdcol = "background-color: $bgcolor;";
8583: }
1.1137 raeburn 8584: my $nicescroll_js;
8585: if ($env{'browser.mobile'}) {
1.1140 raeburn 8586: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8587: }
8588: return <<"END";
8589: $nicescroll_js
8590:
8591: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
8592: <div style="overflow:auto; width:$width; height:$height;"$div_id>
8593: END
8594: }
8595:
8596: sub end_scrollbox {
8597: return '</div></td></tr></table>';
8598: }
8599:
8600: sub nicescroll_javascript {
8601: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8602: my %options;
8603: if (ref($cursor) eq 'HASH') {
8604: %options = %{$cursor};
8605: }
8606: unless ($options{'railalign'} =~ /^left|right$/) {
8607: $options{'railalign'} = 'left';
8608: }
8609: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8610: my $function = &get_users_function();
8611: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 8612: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 8613: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 8614: }
1.1140 raeburn 8615: }
8616: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8617: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 8618: $options{'cursoropacity'}='1.0';
8619: }
1.1140 raeburn 8620: } else {
8621: $options{'cursoropacity'}='1.0';
8622: }
8623: if ($options{'cursorfixedheight'} eq 'none') {
8624: delete($options{'cursorfixedheight'});
8625: } else {
8626: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8627: }
8628: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8629: delete($options{'railoffset'});
8630: }
8631: my @niceoptions;
8632: while (my($key,$value) = each(%options)) {
8633: if ($value =~ /^\{.+\}$/) {
8634: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 8635: } else {
1.1140 raeburn 8636: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 8637: }
1.1140 raeburn 8638: }
8639: my $nicescroll_js = '
1.1137 raeburn 8640: $(document).ready(
1.1140 raeburn 8641: function() {
8642: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8643: }
1.1137 raeburn 8644: );
8645: ';
1.1140 raeburn 8646: if ($framecheck) {
8647: $nicescroll_js .= '
8648: function expand_div(caller) {
8649: if (top === self) {
8650: document.getElementById("'.$id.'").style.width = "auto";
8651: document.getElementById("'.$id.'").style.height = "auto";
8652: } else {
8653: try {
8654: if (parent.frames) {
8655: if (parent.frames.length > 1) {
8656: var framesrc = parent.frames[1].location.href;
8657: var currsrc = framesrc.replace(/\#.*$/,"");
8658: if ((caller == "search") || (currsrc == "'.$location.'")) {
8659: document.getElementById("'.$id.'").style.width = "auto";
8660: document.getElementById("'.$id.'").style.height = "auto";
8661: }
8662: }
8663: }
8664: } catch (e) {
8665: return;
8666: }
1.1137 raeburn 8667: }
1.1140 raeburn 8668: return;
1.996 www 8669: }
1.1140 raeburn 8670: ';
8671: }
8672: if ($needjsready) {
8673: $nicescroll_js = '
8674: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8675: } else {
8676: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8677: }
8678: return $nicescroll_js;
1.996 www 8679: }
8680:
1.318 albertel 8681: sub simple_error_page {
1.1150 bisitz 8682: my ($r,$title,$msg,$args) = @_;
1.1151 raeburn 8683: if (ref($args) eq 'HASH') {
8684: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8685: } else {
8686: $msg = &mt($msg);
8687: }
1.1150 bisitz 8688:
1.318 albertel 8689: my $page =
8690: &Apache::loncommon::start_page($title).
1.1150 bisitz 8691: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8692: &Apache::loncommon::end_page();
8693: if (ref($r)) {
8694: $r->print($page);
1.327 albertel 8695: return;
1.318 albertel 8696: }
8697: return $page;
8698: }
1.347 albertel 8699:
8700: {
1.610 albertel 8701: my @row_count;
1.961 onken 8702:
8703: sub start_data_table_count {
8704: unshift(@row_count, 0);
8705: return;
8706: }
8707:
8708: sub end_data_table_count {
8709: shift(@row_count);
8710: return;
8711: }
8712:
1.347 albertel 8713: sub start_data_table {
1.1018 raeburn 8714: my ($add_class,$id) = @_;
1.422 albertel 8715: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8716: my $table_id;
8717: if (defined($id)) {
8718: $table_id = ' id="'.$id.'"';
8719: }
1.961 onken 8720: &start_data_table_count();
1.1018 raeburn 8721: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8722: }
8723:
8724: sub end_data_table {
1.961 onken 8725: &end_data_table_count();
1.389 albertel 8726: return '</table>'."\n";;
1.347 albertel 8727: }
8728:
8729: sub start_data_table_row {
1.974 wenzelju 8730: my ($add_class, $id) = @_;
1.610 albertel 8731: $row_count[0]++;
8732: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8733: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8734: $id = (' id="'.$id.'"') unless ($id eq '');
8735: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8736: }
1.471 banghart 8737:
8738: sub continue_data_table_row {
1.974 wenzelju 8739: my ($add_class, $id) = @_;
1.610 albertel 8740: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8741: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8742: $id = (' id="'.$id.'"') unless ($id eq '');
8743: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8744: }
1.347 albertel 8745:
8746: sub end_data_table_row {
1.389 albertel 8747: return '</tr>'."\n";;
1.347 albertel 8748: }
1.367 www 8749:
1.421 albertel 8750: sub start_data_table_empty_row {
1.707 bisitz 8751: # $row_count[0]++;
1.421 albertel 8752: return '<tr class="LC_empty_row" >'."\n";;
8753: }
8754:
8755: sub end_data_table_empty_row {
8756: return '</tr>'."\n";;
8757: }
8758:
1.367 www 8759: sub start_data_table_header_row {
1.389 albertel 8760: return '<tr class="LC_header_row">'."\n";;
1.367 www 8761: }
8762:
8763: sub end_data_table_header_row {
1.389 albertel 8764: return '</tr>'."\n";;
1.367 www 8765: }
1.890 droeschl 8766:
8767: sub data_table_caption {
8768: my $caption = shift;
8769: return "<caption class=\"LC_caption\">$caption</caption>";
8770: }
1.347 albertel 8771: }
8772:
1.548 albertel 8773: =pod
8774:
8775: =item * &inhibit_menu_check($arg)
8776:
8777: Checks for a inhibitmenu state and generates output to preserve it
8778:
8779: Inputs: $arg - can be any of
8780: - undef - in which case the return value is a string
8781: to add into arguments list of a uri
8782: - 'input' - in which case the return value is a HTML
8783: <form> <input> field of type hidden to
8784: preserve the value
8785: - a url - in which case the return value is the url with
8786: the neccesary cgi args added to preserve the
8787: inhibitmenu state
8788: - a ref to a url - no return value, but the string is
8789: updated to include the neccessary cgi
8790: args to preserve the inhibitmenu state
8791:
8792: =cut
8793:
8794: sub inhibit_menu_check {
8795: my ($arg) = @_;
8796: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8797: if ($arg eq 'input') {
8798: if ($env{'form.inhibitmenu'}) {
8799: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8800: } else {
8801: return
8802: }
8803: }
8804: if ($env{'form.inhibitmenu'}) {
8805: if (ref($arg)) {
8806: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8807: } elsif ($arg eq '') {
8808: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8809: } else {
8810: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8811: }
8812: }
8813: if (!ref($arg)) {
8814: return $arg;
8815: }
8816: }
8817:
1.251 albertel 8818: ###############################################
1.182 matthew 8819:
8820: =pod
8821:
1.549 albertel 8822: =back
8823:
8824: =head1 User Information Routines
8825:
8826: =over 4
8827:
1.405 albertel 8828: =item * &get_users_function()
1.182 matthew 8829:
8830: Used by &bodytag to determine the current users primary role.
8831: Returns either 'student','coordinator','admin', or 'author'.
8832:
8833: =cut
8834:
8835: ###############################################
8836: sub get_users_function {
1.815 tempelho 8837: my $function = 'norole';
1.818 tempelho 8838: if ($env{'request.role'}=~/^(st)/) {
8839: $function='student';
8840: }
1.907 raeburn 8841: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8842: $function='coordinator';
8843: }
1.258 albertel 8844: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8845: $function='admin';
8846: }
1.826 bisitz 8847: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8848: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8849: $function='author';
8850: }
8851: return $function;
1.54 www 8852: }
1.99 www 8853:
8854: ###############################################
8855:
1.233 raeburn 8856: =pod
8857:
1.821 raeburn 8858: =item * &show_course()
8859:
8860: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8861: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8862:
8863: Inputs:
8864: None
8865:
8866: Outputs:
8867: Scalar: 1 if 'Course' to be used, 0 otherwise.
8868:
8869: =cut
8870:
8871: ###############################################
8872: sub show_course {
8873: my $course = !$env{'user.adv'};
8874: if (!$env{'user.adv'}) {
8875: foreach my $env (keys(%env)) {
8876: next if ($env !~ m/^user\.priv\./);
8877: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8878: $course = 0;
8879: last;
8880: }
8881: }
8882: }
8883: return $course;
8884: }
8885:
8886: ###############################################
8887:
8888: =pod
8889:
1.542 raeburn 8890: =item * &check_user_status()
1.274 raeburn 8891:
8892: Determines current status of supplied role for a
8893: specific user. Roles can be active, previous or future.
8894:
8895: Inputs:
8896: user's domain, user's username, course's domain,
1.375 raeburn 8897: course's number, optional section ID.
1.274 raeburn 8898:
8899: Outputs:
8900: role status: active, previous or future.
8901:
8902: =cut
8903:
8904: sub check_user_status {
1.412 raeburn 8905: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8906: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 8907: my @uroles = keys(%userinfo);
1.274 raeburn 8908: my $srchstr;
8909: my $active_chk = 'none';
1.412 raeburn 8910: my $now = time;
1.274 raeburn 8911: if (@uroles > 0) {
1.908 raeburn 8912: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8913: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8914: } else {
1.412 raeburn 8915: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8916: }
8917: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8918: my $role_end = 0;
8919: my $role_start = 0;
8920: $active_chk = 'active';
1.412 raeburn 8921: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8922: $role_end = $1;
8923: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8924: $role_start = $1;
1.274 raeburn 8925: }
8926: }
8927: if ($role_start > 0) {
1.412 raeburn 8928: if ($now < $role_start) {
1.274 raeburn 8929: $active_chk = 'future';
8930: }
8931: }
8932: if ($role_end > 0) {
1.412 raeburn 8933: if ($now > $role_end) {
1.274 raeburn 8934: $active_chk = 'previous';
8935: }
8936: }
8937: }
8938: }
8939: return $active_chk;
8940: }
8941:
8942: ###############################################
8943:
8944: =pod
8945:
1.405 albertel 8946: =item * &get_sections()
1.233 raeburn 8947:
8948: Determines all the sections for a course including
8949: sections with students and sections containing other roles.
1.419 raeburn 8950: Incoming parameters:
8951:
8952: 1. domain
8953: 2. course number
8954: 3. reference to array containing roles for which sections should
8955: be gathered (optional).
8956: 4. reference to array containing status types for which sections
8957: should be gathered (optional).
8958:
8959: If the third argument is undefined, sections are gathered for any role.
8960: If the fourth argument is undefined, sections are gathered for any status.
8961: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8962:
1.374 raeburn 8963: Returns section hash (keys are section IDs, values are
8964: number of users in each section), subject to the
1.419 raeburn 8965: optional roles filter, optional status filter
1.233 raeburn 8966:
8967: =cut
8968:
8969: ###############################################
8970: sub get_sections {
1.419 raeburn 8971: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8972: if (!defined($cdom) || !defined($cnum)) {
8973: my $cid = $env{'request.course.id'};
8974:
8975: return if (!defined($cid));
8976:
8977: $cdom = $env{'course.'.$cid.'.domain'};
8978: $cnum = $env{'course.'.$cid.'.num'};
8979: }
8980:
8981: my %sectioncount;
1.419 raeburn 8982: my $now = time;
1.240 albertel 8983:
1.1118 raeburn 8984: my $check_students = 1;
8985: my $only_students = 0;
8986: if (ref($possible_roles) eq 'ARRAY') {
8987: if (grep(/^st$/,@{$possible_roles})) {
8988: if (@{$possible_roles} == 1) {
8989: $only_students = 1;
8990: }
8991: } else {
8992: $check_students = 0;
8993: }
8994: }
8995:
8996: if ($check_students) {
1.276 albertel 8997: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8998: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8999: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9000: my $start_index = &Apache::loncoursedata::CL_START();
9001: my $end_index = &Apache::loncoursedata::CL_END();
9002: my $status;
1.366 albertel 9003: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9004: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9005: $data->[$status_index],
9006: $data->[$start_index],
9007: $data->[$end_index]);
9008: if ($stu_status eq 'Active') {
9009: $status = 'active';
9010: } elsif ($end < $now) {
9011: $status = 'previous';
9012: } elsif ($start > $now) {
9013: $status = 'future';
9014: }
9015: if ($section ne '-1' && $section !~ /^\s*$/) {
9016: if ((!defined($possible_status)) || (($status ne '') &&
9017: (grep/^\Q$status\E$/,@{$possible_status}))) {
9018: $sectioncount{$section}++;
9019: }
1.240 albertel 9020: }
9021: }
9022: }
1.1118 raeburn 9023: if ($only_students) {
9024: return %sectioncount;
9025: }
1.240 albertel 9026: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9027: foreach my $user (sort(keys(%courseroles))) {
9028: if ($user !~ /^(\w{2})/) { next; }
9029: my ($role) = ($user =~ /^(\w{2})/);
9030: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9031: my ($section,$status);
1.240 albertel 9032: if ($role eq 'cr' &&
9033: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9034: $section=$1;
9035: }
9036: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9037: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9038: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9039: if ($end == -1 && $start == -1) {
9040: next; #deleted role
9041: }
9042: if (!defined($possible_status)) {
9043: $sectioncount{$section}++;
9044: } else {
9045: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9046: $status = 'active';
9047: } elsif ($end < $now) {
9048: $status = 'future';
9049: } elsif ($start > $now) {
9050: $status = 'previous';
9051: }
9052: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9053: $sectioncount{$section}++;
9054: }
9055: }
1.233 raeburn 9056: }
1.366 albertel 9057: return %sectioncount;
1.233 raeburn 9058: }
9059:
1.274 raeburn 9060: ###############################################
1.294 raeburn 9061:
9062: =pod
1.405 albertel 9063:
9064: =item * &get_course_users()
9065:
1.275 raeburn 9066: Retrieves usernames:domains for users in the specified course
9067: with specific role(s), and access status.
9068:
9069: Incoming parameters:
1.277 albertel 9070: 1. course domain
9071: 2. course number
9072: 3. access status: users must have - either active,
1.275 raeburn 9073: previous, future, or all.
1.277 albertel 9074: 4. reference to array of permissible roles
1.288 raeburn 9075: 5. reference to array of section restrictions (optional)
9076: 6. reference to results object (hash of hashes).
9077: 7. reference to optional userdata hash
1.609 raeburn 9078: 8. reference to optional statushash
1.630 raeburn 9079: 9. flag if privileged users (except those set to unhide in
9080: course settings) should be excluded
1.609 raeburn 9081: Keys of top level results hash are roles.
1.275 raeburn 9082: Keys of inner hashes are username:domain, with
9083: values set to access type.
1.288 raeburn 9084: Optional userdata hash returns an array with arguments in the
9085: same order as loncoursedata::get_classlist() for student data.
9086:
1.609 raeburn 9087: Optional statushash returns
9088:
1.288 raeburn 9089: Entries for end, start, section and status are blank because
9090: of the possibility of multiple values for non-student roles.
9091:
1.275 raeburn 9092: =cut
1.405 albertel 9093:
1.275 raeburn 9094: ###############################################
1.405 albertel 9095:
1.275 raeburn 9096: sub get_course_users {
1.630 raeburn 9097: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9098: my %idx = ();
1.419 raeburn 9099: my %seclists;
1.288 raeburn 9100:
9101: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9102: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9103: $idx{end} = &Apache::loncoursedata::CL_END();
9104: $idx{start} = &Apache::loncoursedata::CL_START();
9105: $idx{id} = &Apache::loncoursedata::CL_ID();
9106: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9107: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9108: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9109:
1.290 albertel 9110: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9111: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9112: my $now = time;
1.277 albertel 9113: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9114: my $match = 0;
1.412 raeburn 9115: my $secmatch = 0;
1.419 raeburn 9116: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9117: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9118: if ($section eq '') {
9119: $section = 'none';
9120: }
1.291 albertel 9121: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9122: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9123: $secmatch = 1;
9124: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9125: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9126: $secmatch = 1;
9127: }
9128: } else {
1.419 raeburn 9129: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9130: $secmatch = 1;
9131: }
1.290 albertel 9132: }
1.412 raeburn 9133: if (!$secmatch) {
9134: next;
9135: }
1.419 raeburn 9136: }
1.275 raeburn 9137: if (defined($$types{'active'})) {
1.288 raeburn 9138: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9139: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9140: $match = 1;
1.275 raeburn 9141: }
9142: }
9143: if (defined($$types{'previous'})) {
1.609 raeburn 9144: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9145: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9146: $match = 1;
1.275 raeburn 9147: }
9148: }
9149: if (defined($$types{'future'})) {
1.609 raeburn 9150: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9151: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9152: $match = 1;
1.275 raeburn 9153: }
9154: }
1.609 raeburn 9155: if ($match) {
9156: push(@{$seclists{$student}},$section);
9157: if (ref($userdata) eq 'HASH') {
9158: $$userdata{$student} = $$classlist{$student};
9159: }
9160: if (ref($statushash) eq 'HASH') {
9161: $statushash->{$student}{'st'}{$section} = $status;
9162: }
1.288 raeburn 9163: }
1.275 raeburn 9164: }
9165: }
1.412 raeburn 9166: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9167: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9168: my $now = time;
1.609 raeburn 9169: my %displaystatus = ( previous => 'Expired',
9170: active => 'Active',
9171: future => 'Future',
9172: );
1.1121 raeburn 9173: my (%nothide,@possdoms);
1.630 raeburn 9174: if ($hidepriv) {
9175: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9176: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9177: if ($user !~ /:/) {
9178: $nothide{join(':',split(/[\@]/,$user))}=1;
9179: } else {
9180: $nothide{$user} = 1;
9181: }
9182: }
1.1121 raeburn 9183: my @possdoms = ($cdom);
9184: if ($coursehash{'checkforpriv'}) {
9185: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9186: }
1.630 raeburn 9187: }
1.439 raeburn 9188: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9189: my $match = 0;
1.412 raeburn 9190: my $secmatch = 0;
1.439 raeburn 9191: my $status;
1.412 raeburn 9192: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9193: $user =~ s/:$//;
1.439 raeburn 9194: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9195: if ($end == -1 || $start == -1) {
9196: next;
9197: }
9198: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9199: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9200: my ($uname,$udom) = split(/:/,$user);
9201: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9202: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9203: $secmatch = 1;
9204: } elsif ($usec eq '') {
1.420 albertel 9205: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9206: $secmatch = 1;
9207: }
9208: } else {
9209: if (grep(/^\Q$usec\E$/,@{$sections})) {
9210: $secmatch = 1;
9211: }
9212: }
9213: if (!$secmatch) {
9214: next;
9215: }
1.288 raeburn 9216: }
1.419 raeburn 9217: if ($usec eq '') {
9218: $usec = 'none';
9219: }
1.275 raeburn 9220: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9221: if ($hidepriv) {
1.1121 raeburn 9222: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9223: (!$nothide{$uname.':'.$udom})) {
9224: next;
9225: }
9226: }
1.503 raeburn 9227: if ($end > 0 && $end < $now) {
1.439 raeburn 9228: $status = 'previous';
9229: } elsif ($start > $now) {
9230: $status = 'future';
9231: } else {
9232: $status = 'active';
9233: }
1.277 albertel 9234: foreach my $type (keys(%{$types})) {
1.275 raeburn 9235: if ($status eq $type) {
1.420 albertel 9236: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9237: push(@{$$users{$role}{$user}},$type);
9238: }
1.288 raeburn 9239: $match = 1;
9240: }
9241: }
1.419 raeburn 9242: if (($match) && (ref($userdata) eq 'HASH')) {
9243: if (!exists($$userdata{$uname.':'.$udom})) {
9244: &get_user_info($udom,$uname,\%idx,$userdata);
9245: }
1.420 albertel 9246: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9247: push(@{$seclists{$uname.':'.$udom}},$usec);
9248: }
1.609 raeburn 9249: if (ref($statushash) eq 'HASH') {
9250: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9251: }
1.275 raeburn 9252: }
9253: }
9254: }
9255: }
1.290 albertel 9256: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9257: if ((defined($cdom)) && (defined($cnum))) {
9258: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9259: if ( defined($csettings{'internal.courseowner'}) ) {
9260: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9261: next if ($owner eq '');
9262: my ($ownername,$ownerdom);
9263: if ($owner =~ /^([^:]+):([^:]+)$/) {
9264: $ownername = $1;
9265: $ownerdom = $2;
9266: } else {
9267: $ownername = $owner;
9268: $ownerdom = $cdom;
9269: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9270: }
9271: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9272: if (defined($userdata) &&
1.609 raeburn 9273: !exists($$userdata{$owner})) {
9274: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9275: if (!grep(/^none$/,@{$seclists{$owner}})) {
9276: push(@{$seclists{$owner}},'none');
9277: }
9278: if (ref($statushash) eq 'HASH') {
9279: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9280: }
1.290 albertel 9281: }
1.279 raeburn 9282: }
9283: }
9284: }
1.419 raeburn 9285: foreach my $user (keys(%seclists)) {
9286: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9287: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9288: }
1.275 raeburn 9289: }
9290: return;
9291: }
9292:
1.288 raeburn 9293: sub get_user_info {
9294: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9295: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9296: &plainname($uname,$udom,'lastname');
1.291 albertel 9297: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9298: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9299: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9300: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9301: return;
9302: }
1.275 raeburn 9303:
1.472 raeburn 9304: ###############################################
9305:
9306: =pod
9307:
9308: =item * &get_user_quota()
9309:
1.1134 raeburn 9310: Retrieves quota assigned for storage of user files.
9311: Default is to report quota for portfolio files.
1.472 raeburn 9312:
9313: Incoming parameters:
9314: 1. user's username
9315: 2. user's domain
1.1134 raeburn 9316: 3. quota name - portfolio, author, or course
1.1136 raeburn 9317: (if no quota name provided, defaults to portfolio).
1.1165 raeburn 9318: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1136 raeburn 9319: course
1.472 raeburn 9320:
9321: Returns:
1.1163 raeburn 9322: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9323: 2. (Optional) Type of setting: custom or default
9324: (individually assigned or default for user's
9325: institutional status).
9326: 3. (Optional) - User's institutional status (e.g., faculty, staff
9327: or student - types as defined in localenroll::inst_usertypes
9328: for user's domain, which determines default quota for user.
9329: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9330:
9331: If a value has been stored in the user's environment,
1.536 raeburn 9332: it will return that, otherwise it returns the maximal default
1.1134 raeburn 9333: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9334:
9335: =cut
9336:
9337: ###############################################
9338:
9339:
9340: sub get_user_quota {
1.1136 raeburn 9341: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9342: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9343: if (!defined($udom)) {
9344: $udom = $env{'user.domain'};
9345: }
9346: if (!defined($uname)) {
9347: $uname = $env{'user.name'};
9348: }
9349: if (($udom eq '' || $uname eq '') ||
9350: ($udom eq 'public') && ($uname eq 'public')) {
9351: $quota = 0;
1.536 raeburn 9352: $quotatype = 'default';
9353: $defquota = 0;
1.472 raeburn 9354: } else {
1.536 raeburn 9355: my $inststatus;
1.1134 raeburn 9356: if ($quotaname eq 'course') {
9357: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9358: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9359: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9360: } else {
9361: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9362: $quota = $cenv{'internal.uploadquota'};
9363: }
1.536 raeburn 9364: } else {
1.1134 raeburn 9365: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9366: if ($quotaname eq 'author') {
9367: $quota = $env{'environment.authorquota'};
9368: } else {
9369: $quota = $env{'environment.portfolioquota'};
9370: }
9371: $inststatus = $env{'environment.inststatus'};
9372: } else {
9373: my %userenv =
9374: &Apache::lonnet::get('environment',['portfolioquota',
9375: 'authorquota','inststatus'],$udom,$uname);
9376: my ($tmp) = keys(%userenv);
9377: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9378: if ($quotaname eq 'author') {
9379: $quota = $userenv{'authorquota'};
9380: } else {
9381: $quota = $userenv{'portfolioquota'};
9382: }
9383: $inststatus = $userenv{'inststatus'};
9384: } else {
9385: undef(%userenv);
9386: }
9387: }
9388: }
9389: if ($quota eq '' || wantarray) {
9390: if ($quotaname eq 'course') {
9391: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 9392: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9393: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1136 raeburn 9394: $defquota = $domdefs{$crstype.'quota'};
9395: }
9396: if ($defquota eq '') {
9397: $defquota = 500;
9398: }
1.1134 raeburn 9399: } else {
9400: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9401: }
9402: if ($quota eq '') {
9403: $quota = $defquota;
9404: $quotatype = 'default';
9405: } else {
9406: $quotatype = 'custom';
9407: }
1.472 raeburn 9408: }
9409: }
1.536 raeburn 9410: if (wantarray) {
9411: return ($quota,$quotatype,$settingstatus,$defquota);
9412: } else {
9413: return $quota;
9414: }
1.472 raeburn 9415: }
9416:
9417: ###############################################
9418:
9419: =pod
9420:
9421: =item * &default_quota()
9422:
1.536 raeburn 9423: Retrieves default quota assigned for storage of user portfolio files,
9424: given an (optional) user's institutional status.
1.472 raeburn 9425:
9426: Incoming parameters:
1.1142 raeburn 9427:
1.472 raeburn 9428: 1. domain
1.536 raeburn 9429: 2. (Optional) institutional status(es). This is a : separated list of
9430: status types (e.g., faculty, staff, student etc.)
9431: which apply to the user for whom the default is being retrieved.
9432: If the institutional status string in undefined, the domain
1.1134 raeburn 9433: default quota will be returned.
9434: 3. quota name - portfolio, author, or course
9435: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9436:
9437: Returns:
1.1142 raeburn 9438:
1.1163 raeburn 9439: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9440: 2. (Optional) institutional type which determined the value of the
9441: default quota.
1.472 raeburn 9442:
9443: If a value has been stored in the domain's configuration db,
9444: it will return that, otherwise it returns 20 (for backwards
9445: compatibility with domains which have not set up a configuration
1.1163 raeburn 9446: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9447:
1.536 raeburn 9448: If the user's status includes multiple types (e.g., staff and student),
9449: the largest default quota which applies to the user determines the
9450: default quota returned.
9451:
1.472 raeburn 9452: =cut
9453:
9454: ###############################################
9455:
9456:
9457: sub default_quota {
1.1134 raeburn 9458: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9459: my ($defquota,$settingstatus);
9460: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9461: ['quotas'],$udom);
1.1134 raeburn 9462: my $key = 'defaultquota';
9463: if ($quotaname eq 'author') {
9464: $key = 'authorquota';
9465: }
1.622 raeburn 9466: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9467: if ($inststatus ne '') {
1.765 raeburn 9468: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9469: foreach my $item (@statuses) {
1.1134 raeburn 9470: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9471: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9472: if ($defquota eq '') {
1.1134 raeburn 9473: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9474: $settingstatus = $item;
1.1134 raeburn 9475: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9476: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9477: $settingstatus = $item;
9478: }
9479: }
1.1134 raeburn 9480: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9481: if ($quotahash{'quotas'}{$item} ne '') {
9482: if ($defquota eq '') {
9483: $defquota = $quotahash{'quotas'}{$item};
9484: $settingstatus = $item;
9485: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9486: $defquota = $quotahash{'quotas'}{$item};
9487: $settingstatus = $item;
9488: }
1.536 raeburn 9489: }
9490: }
9491: }
9492: }
9493: if ($defquota eq '') {
1.1134 raeburn 9494: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9495: $defquota = $quotahash{'quotas'}{$key}{'default'};
9496: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9497: $defquota = $quotahash{'quotas'}{'default'};
9498: }
1.536 raeburn 9499: $settingstatus = 'default';
1.1139 raeburn 9500: if ($defquota eq '') {
9501: if ($quotaname eq 'author') {
9502: $defquota = 500;
9503: }
9504: }
1.536 raeburn 9505: }
9506: } else {
9507: $settingstatus = 'default';
1.1134 raeburn 9508: if ($quotaname eq 'author') {
9509: $defquota = 500;
9510: } else {
9511: $defquota = 20;
9512: }
1.536 raeburn 9513: }
9514: if (wantarray) {
9515: return ($defquota,$settingstatus);
1.472 raeburn 9516: } else {
1.536 raeburn 9517: return $defquota;
1.472 raeburn 9518: }
9519: }
9520:
1.1135 raeburn 9521: ###############################################
9522:
9523: =pod
9524:
1.1136 raeburn 9525: =item * &excess_filesize_warning()
1.1135 raeburn 9526:
9527: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 9528: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 9529: space to be exceeded.
1.1136 raeburn 9530:
9531: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 9532: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 9533:
1.1165 raeburn 9534: Inputs: 7
1.1136 raeburn 9535: 1. username or coursenum
1.1135 raeburn 9536: 2. domain
1.1136 raeburn 9537: 3. context ('author' or 'course')
1.1135 raeburn 9538: 4. filename of file for which action is being requested
9539: 5. filesize (kB) of file
9540: 6. action being taken: copy or upload.
1.1165 raeburn 9541: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1135 raeburn 9542:
9543: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 9544: otherwise return null.
9545:
9546: =back
1.1135 raeburn 9547:
9548: =cut
9549:
1.1136 raeburn 9550: sub excess_filesize_warning {
1.1165 raeburn 9551: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 9552: my $current_disk_usage = 0;
1.1165 raeburn 9553: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 9554: if ($context eq 'author') {
9555: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9556: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9557: } else {
9558: foreach my $subdir ('docs','supplemental') {
9559: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9560: }
9561: }
1.1135 raeburn 9562: $disk_quota = int($disk_quota * 1000);
9563: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 9564: return '<p class="LC_warning">'.
1.1135 raeburn 9565: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 9566: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9567: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 9568: $disk_quota,$current_disk_usage).
9569: '</p>';
9570: }
9571: return;
9572: }
9573:
9574: ###############################################
9575:
9576:
1.1136 raeburn 9577:
9578:
1.384 raeburn 9579: sub get_secgrprole_info {
9580: my ($cdom,$cnum,$needroles,$type) = @_;
9581: my %sections_count = &get_sections($cdom,$cnum);
9582: my @sections = (sort {$a <=> $b} keys(%sections_count));
9583: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9584: my @groups = sort(keys(%curr_groups));
9585: my $allroles = [];
9586: my $rolehash;
9587: my $accesshash = {
9588: active => 'Currently has access',
9589: future => 'Will have future access',
9590: previous => 'Previously had access',
9591: };
9592: if ($needroles) {
9593: $rolehash = {'all' => 'all'};
1.385 albertel 9594: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9595: if (&Apache::lonnet::error(%user_roles)) {
9596: undef(%user_roles);
9597: }
9598: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9599: my ($role)=split(/\:/,$item,2);
9600: if ($role eq 'cr') { next; }
9601: if ($role =~ /^cr/) {
9602: $$rolehash{$role} = (split('/',$role))[3];
9603: } else {
9604: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9605: }
9606: }
9607: foreach my $key (sort(keys(%{$rolehash}))) {
9608: push(@{$allroles},$key);
9609: }
9610: push (@{$allroles},'st');
9611: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9612: }
9613: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9614: }
9615:
1.555 raeburn 9616: sub user_picker {
1.994 raeburn 9617: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 9618: my $currdom = $dom;
9619: my %curr_selected = (
9620: srchin => 'dom',
1.580 raeburn 9621: srchby => 'lastname',
1.555 raeburn 9622: );
9623: my $srchterm;
1.625 raeburn 9624: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9625: if ($srch->{'srchby'} ne '') {
9626: $curr_selected{'srchby'} = $srch->{'srchby'};
9627: }
9628: if ($srch->{'srchin'} ne '') {
9629: $curr_selected{'srchin'} = $srch->{'srchin'};
9630: }
9631: if ($srch->{'srchtype'} ne '') {
9632: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9633: }
9634: if ($srch->{'srchdomain'} ne '') {
9635: $currdom = $srch->{'srchdomain'};
9636: }
9637: $srchterm = $srch->{'srchterm'};
9638: }
1.1222 damieng 9639: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9640: 'usr' => 'Search criteria',
1.563 raeburn 9641: 'doma' => 'Domain/institution to search',
1.558 albertel 9642: 'uname' => 'username',
9643: 'lastname' => 'last name',
1.555 raeburn 9644: 'lastfirst' => 'last name, first name',
1.558 albertel 9645: 'crs' => 'in this course',
1.576 raeburn 9646: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9647: 'alc' => 'all LON-CAPA',
1.573 raeburn 9648: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9649: 'exact' => 'is',
9650: 'contains' => 'contains',
1.569 raeburn 9651: 'begins' => 'begins with',
1.1222 damieng 9652: );
9653: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9654: 'youm' => "You must include some text to search for.",
9655: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9656: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9657: 'yomc' => "You must choose a domain when using an institutional directory search.",
9658: 'ymcd' => "You must choose a domain when using a domain search.",
9659: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9660: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9661: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9662: );
1.1222 damieng 9663: &html_escape(\%html_lt);
9664: &js_escape(\%js_lt);
1.563 raeburn 9665: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9666: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9667:
9668: my @srchins = ('crs','dom','alc','instd');
9669:
9670: foreach my $option (@srchins) {
9671: # FIXME 'alc' option unavailable until
9672: # loncreateuser::print_user_query_page()
9673: # has been completed.
9674: next if ($option eq 'alc');
1.880 raeburn 9675: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9676: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9677: if ($curr_selected{'srchin'} eq $option) {
9678: $srchinsel .= '
1.1222 damieng 9679: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 9680: } else {
9681: $srchinsel .= '
1.1222 damieng 9682: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 9683: }
1.555 raeburn 9684: }
1.563 raeburn 9685: $srchinsel .= "\n </select>\n";
1.555 raeburn 9686:
9687: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9688: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9689: if ($curr_selected{'srchby'} eq $option) {
9690: $srchbysel .= '
1.1222 damieng 9691: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9692: } else {
9693: $srchbysel .= '
1.1222 damieng 9694: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9695: }
9696: }
9697: $srchbysel .= "\n </select>\n";
9698:
9699: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9700: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9701: if ($curr_selected{'srchtype'} eq $option) {
9702: $srchtypesel .= '
1.1222 damieng 9703: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9704: } else {
9705: $srchtypesel .= '
1.1222 damieng 9706: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9707: }
9708: }
9709: $srchtypesel .= "\n </select>\n";
9710:
1.558 albertel 9711: my ($newuserscript,$new_user_create);
1.994 raeburn 9712: my $context_dom = $env{'request.role.domain'};
9713: if ($context eq 'requestcrs') {
9714: if ($env{'form.coursedom'} ne '') {
9715: $context_dom = $env{'form.coursedom'};
9716: }
9717: }
1.556 raeburn 9718: if ($forcenewuser) {
1.576 raeburn 9719: if (ref($srch) eq 'HASH') {
1.994 raeburn 9720: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9721: if ($cancreate) {
9722: $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>';
9723: } else {
1.799 bisitz 9724: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9725: my %usertypetext = (
9726: official => 'institutional',
9727: unofficial => 'non-institutional',
9728: );
1.799 bisitz 9729: $new_user_create = '<p class="LC_warning">'
9730: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9731: .' '
9732: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9733: ,'<a href="'.$helplink.'">','</a>')
9734: .'</p><br />';
1.627 raeburn 9735: }
1.576 raeburn 9736: }
9737: }
9738:
1.556 raeburn 9739: $newuserscript = <<"ENDSCRIPT";
9740:
1.570 raeburn 9741: function setSearch(createnew,callingForm) {
1.556 raeburn 9742: if (createnew == 1) {
1.570 raeburn 9743: for (var i=0; i<callingForm.srchby.length; i++) {
9744: if (callingForm.srchby.options[i].value == 'uname') {
9745: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9746: }
9747: }
1.570 raeburn 9748: for (var i=0; i<callingForm.srchin.length; i++) {
9749: if ( callingForm.srchin.options[i].value == 'dom') {
9750: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9751: }
9752: }
1.570 raeburn 9753: for (var i=0; i<callingForm.srchtype.length; i++) {
9754: if (callingForm.srchtype.options[i].value == 'exact') {
9755: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9756: }
9757: }
1.570 raeburn 9758: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9759: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9760: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9761: }
9762: }
9763: }
9764: }
9765: ENDSCRIPT
1.558 albertel 9766:
1.556 raeburn 9767: }
9768:
1.555 raeburn 9769: my $output = <<"END_BLOCK";
1.556 raeburn 9770: <script type="text/javascript">
1.824 bisitz 9771: // <![CDATA[
1.570 raeburn 9772: function validateEntry(callingForm) {
1.558 albertel 9773:
1.556 raeburn 9774: var checkok = 1;
1.558 albertel 9775: var srchin;
1.570 raeburn 9776: for (var i=0; i<callingForm.srchin.length; i++) {
9777: if ( callingForm.srchin[i].checked ) {
9778: srchin = callingForm.srchin[i].value;
1.558 albertel 9779: }
9780: }
9781:
1.570 raeburn 9782: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9783: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9784: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9785: var srchterm = callingForm.srchterm.value;
9786: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9787: var msg = "";
9788:
9789: if (srchterm == "") {
9790: checkok = 0;
1.1222 damieng 9791: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 9792: }
9793:
1.569 raeburn 9794: if (srchtype== 'begins') {
9795: if (srchterm.length < 2) {
9796: checkok = 0;
1.1222 damieng 9797: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 9798: }
9799: }
9800:
1.556 raeburn 9801: if (srchtype== 'contains') {
9802: if (srchterm.length < 3) {
9803: checkok = 0;
1.1222 damieng 9804: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 9805: }
9806: }
9807: if (srchin == 'instd') {
9808: if (srchdomain == '') {
9809: checkok = 0;
1.1222 damieng 9810: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 9811: }
9812: }
9813: if (srchin == 'dom') {
9814: if (srchdomain == '') {
9815: checkok = 0;
1.1222 damieng 9816: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 9817: }
9818: }
9819: if (srchby == 'lastfirst') {
9820: if (srchterm.indexOf(",") == -1) {
9821: checkok = 0;
1.1222 damieng 9822: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 9823: }
9824: if (srchterm.indexOf(",") == srchterm.length -1) {
9825: checkok = 0;
1.1222 damieng 9826: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 9827: }
9828: }
9829: if (checkok == 0) {
1.1222 damieng 9830: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 9831: return;
9832: }
9833: if (checkok == 1) {
1.570 raeburn 9834: callingForm.submit();
1.556 raeburn 9835: }
9836: }
9837:
9838: $newuserscript
9839:
1.824 bisitz 9840: // ]]>
1.556 raeburn 9841: </script>
1.558 albertel 9842:
9843: $new_user_create
9844:
1.555 raeburn 9845: END_BLOCK
1.558 albertel 9846:
1.876 raeburn 9847: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 9848: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 9849: $domform.
9850: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 9851: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 9852: $srchbysel.
9853: $srchtypesel.
9854: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9855: $srchinsel.
9856: &Apache::lonhtmlcommon::row_closure(1).
9857: &Apache::lonhtmlcommon::end_pick_box().
9858: '<br />';
1.555 raeburn 9859: return $output;
9860: }
9861:
1.612 raeburn 9862: sub user_rule_check {
1.615 raeburn 9863: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 9864: my ($response,%inst_response);
1.612 raeburn 9865: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 9866: if (keys(%{$usershash}) > 1) {
9867: my (%by_username,%by_id,%userdoms);
9868: my $checkid;
9869: if (ref($checks) eq 'HASH') {
9870: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
9871: $checkid = 1;
9872: }
9873: }
9874: foreach my $user (keys(%{$usershash})) {
9875: my ($uname,$udom) = split(/:/,$user);
9876: if ($checkid) {
9877: if (ref($usershash->{$user}) eq 'HASH') {
9878: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 9879: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 9880: $userdoms{$udom} = 1;
1.1227 raeburn 9881: if (ref($inst_results) eq 'HASH') {
9882: $inst_results->{$uname.':'.$udom} = {};
9883: }
1.1226 raeburn 9884: }
9885: }
9886: } else {
9887: $by_username{$udom}{$uname} = 1;
9888: $userdoms{$udom} = 1;
1.1227 raeburn 9889: if (ref($inst_results) eq 'HASH') {
9890: $inst_results->{$uname.':'.$udom} = {};
9891: }
1.1226 raeburn 9892: }
9893: }
9894: foreach my $udom (keys(%userdoms)) {
9895: if (!$got_rules->{$udom}) {
9896: my %domconfig = &Apache::lonnet::get_dom('configuration',
9897: ['usercreation'],$udom);
9898: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9899: foreach my $item ('username','id') {
9900: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 9901: $$curr_rules{$udom}{$item} =
9902: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 9903: }
9904: }
9905: }
9906: $got_rules->{$udom} = 1;
9907: }
1.612 raeburn 9908: }
1.1226 raeburn 9909: if ($checkid) {
9910: foreach my $udom (keys(%by_id)) {
9911: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
9912: if ($outcome eq 'ok') {
1.1227 raeburn 9913: foreach my $id (keys(%{$by_id{$udom}})) {
9914: my $uname = $by_id{$udom}{$id};
9915: $inst_response{$uname.':'.$udom} = $outcome;
9916: }
1.1226 raeburn 9917: if (ref($results) eq 'HASH') {
9918: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 9919: if (exists($inst_response{$uname.':'.$udom})) {
9920: $inst_response{$uname.':'.$udom} = $outcome;
9921: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9922: }
1.1226 raeburn 9923: }
9924: }
9925: }
1.612 raeburn 9926: }
1.615 raeburn 9927: } else {
1.1226 raeburn 9928: foreach my $udom (keys(%by_username)) {
9929: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
9930: if ($outcome eq 'ok') {
1.1227 raeburn 9931: foreach my $uname (keys(%{$by_username{$udom}})) {
9932: $inst_response{$uname.':'.$udom} = $outcome;
9933: }
1.1226 raeburn 9934: if (ref($results) eq 'HASH') {
9935: foreach my $uname (keys(%{$results})) {
9936: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9937: }
9938: }
9939: }
9940: }
1.612 raeburn 9941: }
1.1226 raeburn 9942: } elsif (keys(%{$usershash}) == 1) {
9943: my $user = (keys(%{$usershash}))[0];
9944: my ($uname,$udom) = split(/:/,$user);
9945: if (($udom ne '') && ($uname ne '')) {
9946: if (ref($usershash->{$user}) eq 'HASH') {
9947: if (ref($checks) eq 'HASH') {
9948: if (defined($checks->{'username'})) {
9949: ($inst_response{$user},%{$inst_results->{$user}}) =
9950: &Apache::lonnet::get_instuser($udom,$uname);
9951: } elsif (defined($checks->{'id'})) {
9952: if ($usershash->{$user}->{'id'} ne '') {
9953: ($inst_response{$user},%{$inst_results->{$user}}) =
9954: &Apache::lonnet::get_instuser($udom,undef,
9955: $usershash->{$user}->{'id'});
9956: } else {
9957: ($inst_response{$user},%{$inst_results->{$user}}) =
9958: &Apache::lonnet::get_instuser($udom,$uname);
9959: }
1.585 raeburn 9960: }
1.1226 raeburn 9961: } else {
9962: ($inst_response{$user},%{$inst_results->{$user}}) =
9963: &Apache::lonnet::get_instuser($udom,$uname);
9964: return;
9965: }
9966: if (!$got_rules->{$udom}) {
9967: my %domconfig = &Apache::lonnet::get_dom('configuration',
9968: ['usercreation'],$udom);
9969: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9970: foreach my $item ('username','id') {
9971: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9972: $$curr_rules{$udom}{$item} =
9973: $domconfig{'usercreation'}{$item.'_rule'};
9974: }
9975: }
9976: }
9977: $got_rules->{$udom} = 1;
1.585 raeburn 9978: }
9979: }
1.1226 raeburn 9980: } else {
9981: return;
9982: }
9983: } else {
9984: return;
9985: }
9986: foreach my $user (keys(%{$usershash})) {
9987: my ($uname,$udom) = split(/:/,$user);
9988: next if (($udom eq '') || ($uname eq ''));
9989: my $id;
1.1227 raeburn 9990: if (ref($inst_results) eq 'HASH') {
9991: if (ref($inst_results->{$user}) eq 'HASH') {
9992: $id = $inst_results->{$user}->{'id'};
9993: }
9994: }
9995: if ($id eq '') {
9996: if (ref($usershash->{$user})) {
9997: $id = $usershash->{$user}->{'id'};
9998: }
1.585 raeburn 9999: }
1.612 raeburn 10000: foreach my $item (keys(%{$checks})) {
10001: if (ref($$curr_rules{$udom}) eq 'HASH') {
10002: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10003: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10004: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10005: $$curr_rules{$udom}{$item});
1.612 raeburn 10006: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10007: if ($rule_check{$rule}) {
10008: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10009: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10010: if (ref($inst_results) eq 'HASH') {
10011: if (ref($inst_results->{$user}) eq 'HASH') {
10012: if (keys(%{$inst_results->{$user}}) == 0) {
10013: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10014: } elsif ($item eq 'id') {
10015: if ($inst_results->{$user}->{'id'} eq '') {
10016: $$alerts{$item}{$udom}{$uname} = 1;
10017: }
1.615 raeburn 10018: }
1.612 raeburn 10019: }
10020: }
1.615 raeburn 10021: }
10022: last;
1.585 raeburn 10023: }
10024: }
10025: }
10026: }
10027: }
10028: }
10029: }
10030: }
1.612 raeburn 10031: return;
10032: }
10033:
10034: sub user_rule_formats {
10035: my ($domain,$domdesc,$curr_rules,$check) = @_;
10036: my %text = (
10037: 'username' => 'Usernames',
10038: 'id' => 'IDs',
10039: );
10040: my $output;
10041: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10042: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10043: if (@{$ruleorder} > 0) {
1.1102 raeburn 10044: $output = '<br />'.
10045: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10046: '<span class="LC_cusr_emph">','</span>',$domdesc).
10047: ' <ul>';
1.612 raeburn 10048: foreach my $rule (@{$ruleorder}) {
10049: if (ref($curr_rules) eq 'ARRAY') {
10050: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10051: if (ref($rules->{$rule}) eq 'HASH') {
10052: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10053: $rules->{$rule}{'desc'}.'</li>';
10054: }
10055: }
10056: }
10057: }
10058: $output .= '</ul>';
10059: }
10060: }
10061: return $output;
10062: }
10063:
10064: sub instrule_disallow_msg {
1.615 raeburn 10065: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10066: my $response;
10067: my %text = (
10068: item => 'username',
10069: items => 'usernames',
10070: match => 'matches',
10071: do => 'does',
10072: action => 'a username',
10073: one => 'one',
10074: );
10075: if ($count > 1) {
10076: $text{'item'} = 'usernames';
10077: $text{'match'} ='match';
10078: $text{'do'} = 'do';
10079: $text{'action'} = 'usernames',
10080: $text{'one'} = 'ones';
10081: }
10082: if ($checkitem eq 'id') {
10083: $text{'items'} = 'IDs';
10084: $text{'item'} = 'ID';
10085: $text{'action'} = 'an ID';
1.615 raeburn 10086: if ($count > 1) {
10087: $text{'item'} = 'IDs';
10088: $text{'action'} = 'IDs';
10089: }
1.612 raeburn 10090: }
1.674 bisitz 10091: $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 10092: if ($mode eq 'upload') {
10093: if ($checkitem eq 'username') {
10094: $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'}.");
10095: } elsif ($checkitem eq 'id') {
1.674 bisitz 10096: $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 10097: }
1.669 raeburn 10098: } elsif ($mode eq 'selfcreate') {
10099: if ($checkitem eq 'id') {
10100: $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.");
10101: }
1.615 raeburn 10102: } else {
10103: if ($checkitem eq 'username') {
10104: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10105: } elsif ($checkitem eq 'id') {
10106: $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.");
10107: }
1.612 raeburn 10108: }
10109: return $response;
1.585 raeburn 10110: }
10111:
1.624 raeburn 10112: sub personal_data_fieldtitles {
10113: my %fieldtitles = &Apache::lonlocal::texthash (
10114: id => 'Student/Employee ID',
10115: permanentemail => 'E-mail address',
10116: lastname => 'Last Name',
10117: firstname => 'First Name',
10118: middlename => 'Middle Name',
10119: generation => 'Generation',
10120: gen => 'Generation',
1.765 raeburn 10121: inststatus => 'Affiliation',
1.624 raeburn 10122: );
10123: return %fieldtitles;
10124: }
10125:
1.642 raeburn 10126: sub sorted_inst_types {
10127: my ($dom) = @_;
1.1185 raeburn 10128: my ($usertypes,$order);
10129: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10130: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10131: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10132: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10133: } else {
10134: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10135: }
1.642 raeburn 10136: my $othertitle = &mt('All users');
10137: if ($env{'request.course.id'}) {
1.668 raeburn 10138: $othertitle = &mt('Any users');
1.642 raeburn 10139: }
10140: my @types;
10141: if (ref($order) eq 'ARRAY') {
10142: @types = @{$order};
10143: }
10144: if (@types == 0) {
10145: if (ref($usertypes) eq 'HASH') {
10146: @types = sort(keys(%{$usertypes}));
10147: }
10148: }
10149: if (keys(%{$usertypes}) > 0) {
10150: $othertitle = &mt('Other users');
10151: }
10152: return ($othertitle,$usertypes,\@types);
10153: }
10154:
1.645 raeburn 10155: sub get_institutional_codes {
10156: my ($settings,$allcourses,$LC_code) = @_;
10157: # Get complete list of course sections to update
10158: my @currsections = ();
10159: my @currxlists = ();
10160: my $coursecode = $$settings{'internal.coursecode'};
10161:
10162: if ($$settings{'internal.sectionnums'} ne '') {
10163: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10164: }
10165:
10166: if ($$settings{'internal.crosslistings'} ne '') {
10167: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10168: }
10169:
10170: if (@currxlists > 0) {
10171: foreach (@currxlists) {
10172: if (m/^([^:]+):(\w*)$/) {
10173: unless (grep/^$1$/,@{$allcourses}) {
10174: push @{$allcourses},$1;
10175: $$LC_code{$1} = $2;
10176: }
10177: }
10178: }
10179: }
10180:
10181: if (@currsections > 0) {
10182: foreach (@currsections) {
10183: if (m/^(\w+):(\w*)$/) {
10184: my $sec = $coursecode.$1;
10185: my $lc_sec = $2;
10186: unless (grep/^$sec$/,@{$allcourses}) {
10187: push @{$allcourses},$sec;
10188: $$LC_code{$sec} = $lc_sec;
10189: }
10190: }
10191: }
10192: }
10193: return;
10194: }
10195:
1.971 raeburn 10196: sub get_standard_codeitems {
10197: return ('Year','Semester','Department','Number','Section');
10198: }
10199:
1.112 bowersj2 10200: =pod
10201:
1.780 raeburn 10202: =head1 Slot Helpers
10203:
10204: =over 4
10205:
10206: =item * sorted_slots()
10207:
1.1040 raeburn 10208: Sorts an array of slot names in order of an optional sort key,
10209: default sort is by slot start time (earliest first).
1.780 raeburn 10210:
10211: Inputs:
10212:
10213: =over 4
10214:
10215: slotsarr - Reference to array of unsorted slot names.
10216:
10217: slots - Reference to hash of hash, where outer hash keys are slot names.
10218:
1.1040 raeburn 10219: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10220:
1.549 albertel 10221: =back
10222:
1.780 raeburn 10223: Returns:
10224:
10225: =over 4
10226:
1.1040 raeburn 10227: sorted - An array of slot names sorted by a specified sort key
10228: (default sort key is start time of the slot).
1.780 raeburn 10229:
10230: =back
10231:
10232: =cut
10233:
10234:
10235: sub sorted_slots {
1.1040 raeburn 10236: my ($slotsarr,$slots,$sortkey) = @_;
10237: if ($sortkey eq '') {
10238: $sortkey = 'starttime';
10239: }
1.780 raeburn 10240: my @sorted;
10241: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10242: @sorted =
10243: sort {
10244: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10245: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10246: }
10247: if (ref($slots->{$a})) { return -1;}
10248: if (ref($slots->{$b})) { return 1;}
10249: return 0;
10250: } @{$slotsarr};
10251: }
10252: return @sorted;
10253: }
10254:
1.1040 raeburn 10255: =pod
10256:
10257: =item * get_future_slots()
10258:
10259: Inputs:
10260:
10261: =over 4
10262:
10263: cnum - course number
10264:
10265: cdom - course domain
10266:
10267: now - current UNIX time
10268:
10269: symb - optional symb
10270:
10271: =back
10272:
10273: Returns:
10274:
10275: =over 4
10276:
10277: sorted_reservable - ref to array of student_schedulable slots currently
10278: reservable, ordered by end date of reservation period.
10279:
10280: reservable_now - ref to hash of student_schedulable slots currently
10281: reservable.
10282:
10283: Keys in inner hash are:
10284: (a) symb: either blank or symb to which slot use is restricted.
10285: (b) endreserve: end date of reservation period.
10286:
10287: sorted_future - ref to array of student_schedulable slots reservable in
10288: the future, ordered by start date of reservation period.
10289:
10290: future_reservable - ref to hash of student_schedulable slots reservable
10291: in the future.
10292:
10293: Keys in inner hash are:
10294: (a) symb: either blank or symb to which slot use is restricted.
10295: (b) startreserve: start date of reservation period.
10296:
10297: =back
10298:
10299: =cut
10300:
10301: sub get_future_slots {
10302: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 10303: my $map;
10304: if ($symb) {
10305: ($map) = &Apache::lonnet::decode_symb($symb);
10306: }
1.1040 raeburn 10307: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10308: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10309: foreach my $slot (keys(%slots)) {
10310: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10311: if ($symb) {
1.1229 raeburn 10312: if ($slots{$slot}->{'symb'} ne '') {
10313: my $canuse;
10314: my %oksymbs;
10315: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
10316: map { $oksymbs{$_} = 1; } @slotsymbs;
10317: if ($oksymbs{$symb}) {
10318: $canuse = 1;
10319: } else {
10320: foreach my $item (@slotsymbs) {
10321: if ($item =~ /\.(page|sequence)$/) {
10322: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
10323: if (($map ne '') && ($map eq $sloturl)) {
10324: $canuse = 1;
10325: last;
10326: }
10327: }
10328: }
10329: }
10330: next unless ($canuse);
10331: }
1.1040 raeburn 10332: }
10333: if (($slots{$slot}->{'starttime'} > $now) &&
10334: ($slots{$slot}->{'endtime'} > $now)) {
10335: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10336: my $userallowed = 0;
10337: if ($slots{$slot}->{'allowedsections'}) {
10338: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10339: if (!defined($env{'request.role.sec'})
10340: && grep(/^No section assigned$/,@allowed_sec)) {
10341: $userallowed=1;
10342: } else {
10343: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10344: $userallowed=1;
10345: }
10346: }
10347: unless ($userallowed) {
10348: if (defined($env{'request.course.groups'})) {
10349: my @groups = split(/:/,$env{'request.course.groups'});
10350: foreach my $group (@groups) {
10351: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10352: $userallowed=1;
10353: last;
10354: }
10355: }
10356: }
10357: }
10358: }
10359: if ($slots{$slot}->{'allowedusers'}) {
10360: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10361: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10362: if (grep(/^\Q$user\E$/,@allowed_users)) {
10363: $userallowed = 1;
10364: }
10365: }
10366: next unless($userallowed);
10367: }
10368: my $startreserve = $slots{$slot}->{'startreserve'};
10369: my $endreserve = $slots{$slot}->{'endreserve'};
10370: my $symb = $slots{$slot}->{'symb'};
10371: if (($startreserve < $now) &&
10372: (!$endreserve || $endreserve > $now)) {
10373: my $lastres = $endreserve;
10374: if (!$lastres) {
10375: $lastres = $slots{$slot}->{'starttime'};
10376: }
10377: $reservable_now{$slot} = {
10378: symb => $symb,
10379: endreserve => $lastres
10380: };
10381: } elsif (($startreserve > $now) &&
10382: (!$endreserve || $endreserve > $startreserve)) {
10383: $future_reservable{$slot} = {
10384: symb => $symb,
10385: startreserve => $startreserve
10386: };
10387: }
10388: }
10389: }
10390: my @unsorted_reservable = keys(%reservable_now);
10391: if (@unsorted_reservable > 0) {
10392: @sorted_reservable =
10393: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10394: }
10395: my @unsorted_future = keys(%future_reservable);
10396: if (@unsorted_future > 0) {
10397: @sorted_future =
10398: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10399: }
10400: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10401: }
1.780 raeburn 10402:
10403: =pod
10404:
1.1057 foxr 10405: =back
10406:
1.549 albertel 10407: =head1 HTTP Helpers
10408:
10409: =over 4
10410:
1.648 raeburn 10411: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10412:
1.258 albertel 10413: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10414: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10415: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10416:
10417: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10418: $possible_names is an ref to an array of form element names. As an example:
10419: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10420: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10421:
10422: =cut
1.1 albertel 10423:
1.6 albertel 10424: sub get_unprocessed_cgi {
1.25 albertel 10425: my ($query,$possible_names)= @_;
1.26 matthew 10426: # $Apache::lonxml::debug=1;
1.356 albertel 10427: foreach my $pair (split(/&/,$query)) {
10428: my ($name, $value) = split(/=/,$pair);
1.369 www 10429: $name = &unescape($name);
1.25 albertel 10430: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10431: $value =~ tr/+/ /;
10432: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10433: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10434: }
1.16 harris41 10435: }
1.6 albertel 10436: }
10437:
1.112 bowersj2 10438: =pod
10439:
1.648 raeburn 10440: =item * &cacheheader()
1.112 bowersj2 10441:
10442: returns cache-controlling header code
10443:
10444: =cut
10445:
1.7 albertel 10446: sub cacheheader {
1.258 albertel 10447: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10448: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10449: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10450: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10451: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10452: return $output;
1.7 albertel 10453: }
10454:
1.112 bowersj2 10455: =pod
10456:
1.648 raeburn 10457: =item * &no_cache($r)
1.112 bowersj2 10458:
10459: specifies header code to not have cache
10460:
10461: =cut
10462:
1.9 albertel 10463: sub no_cache {
1.216 albertel 10464: my ($r) = @_;
10465: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10466: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10467: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10468: $r->no_cache(1);
10469: $r->header_out("Expires" => $date);
10470: $r->header_out("Pragma" => "no-cache");
1.123 www 10471: }
10472:
10473: sub content_type {
1.181 albertel 10474: my ($r,$type,$charset) = @_;
1.299 foxr 10475: if ($r) {
10476: # Note that printout.pl calls this with undef for $r.
10477: &no_cache($r);
10478: }
1.258 albertel 10479: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10480: unless ($charset) {
10481: $charset=&Apache::lonlocal::current_encoding;
10482: }
10483: if ($charset) { $type.='; charset='.$charset; }
10484: if ($r) {
10485: $r->content_type($type);
10486: } else {
10487: print("Content-type: $type\n\n");
10488: }
1.9 albertel 10489: }
1.25 albertel 10490:
1.112 bowersj2 10491: =pod
10492:
1.648 raeburn 10493: =item * &add_to_env($name,$value)
1.112 bowersj2 10494:
1.258 albertel 10495: adds $name to the %env hash with value
1.112 bowersj2 10496: $value, if $name already exists, the entry is converted to an array
10497: reference and $value is added to the array.
10498:
10499: =cut
10500:
1.25 albertel 10501: sub add_to_env {
10502: my ($name,$value)=@_;
1.258 albertel 10503: if (defined($env{$name})) {
10504: if (ref($env{$name})) {
1.25 albertel 10505: #already have multiple values
1.258 albertel 10506: push(@{ $env{$name} },$value);
1.25 albertel 10507: } else {
10508: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10509: my $first=$env{$name};
10510: undef($env{$name});
10511: push(@{ $env{$name} },$first,$value);
1.25 albertel 10512: }
10513: } else {
1.258 albertel 10514: $env{$name}=$value;
1.25 albertel 10515: }
1.31 albertel 10516: }
1.149 albertel 10517:
10518: =pod
10519:
1.648 raeburn 10520: =item * &get_env_multiple($name)
1.149 albertel 10521:
1.258 albertel 10522: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10523: values may be defined and end up as an array ref.
10524:
10525: returns an array of values
10526:
10527: =cut
10528:
10529: sub get_env_multiple {
10530: my ($name) = @_;
10531: my @values;
1.258 albertel 10532: if (defined($env{$name})) {
1.149 albertel 10533: # exists is it an array
1.258 albertel 10534: if (ref($env{$name})) {
10535: @values=@{ $env{$name} };
1.149 albertel 10536: } else {
1.258 albertel 10537: $values[0]=$env{$name};
1.149 albertel 10538: }
10539: }
10540: return(@values);
10541: }
10542:
1.660 raeburn 10543: sub ask_for_embedded_content {
10544: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10545: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 10546: %currsubfile,%unused,$rem);
1.1071 raeburn 10547: my $counter = 0;
10548: my $numnew = 0;
1.987 raeburn 10549: my $numremref = 0;
10550: my $numinvalid = 0;
10551: my $numpathchg = 0;
10552: my $numexisting = 0;
1.1071 raeburn 10553: my $numunused = 0;
10554: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 10555: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10556: my $heading = &mt('Upload embedded files');
10557: my $buttontext = &mt('Upload');
10558:
1.1085 raeburn 10559: if ($env{'request.course.id'}) {
1.1123 raeburn 10560: if ($actionurl eq '/adm/dependencies') {
10561: $navmap = Apache::lonnavmaps::navmap->new();
10562: }
10563: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10564: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 10565: }
1.1123 raeburn 10566: if (($actionurl eq '/adm/portfolio') ||
10567: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10568: my $current_path='/';
10569: if ($env{'form.currentpath'}) {
10570: $current_path = $env{'form.currentpath'};
10571: }
10572: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 10573: $udom = $cdom;
10574: $uname = $cnum;
1.984 raeburn 10575: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10576: } else {
10577: $udom = $env{'user.domain'};
10578: $uname = $env{'user.name'};
10579: $url = '/userfiles/portfolio';
10580: }
1.987 raeburn 10581: $toplevel = $url.'/';
1.984 raeburn 10582: $url .= $current_path;
10583: $getpropath = 1;
1.987 raeburn 10584: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10585: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10586: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10587: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10588: $toplevel = $url;
1.984 raeburn 10589: if ($rest ne '') {
1.987 raeburn 10590: $url .= $rest;
10591: }
10592: } elsif ($actionurl eq '/adm/coursedocs') {
10593: if (ref($args) eq 'HASH') {
1.1071 raeburn 10594: $url = $args->{'docs_url'};
10595: $toplevel = $url;
1.1084 raeburn 10596: if ($args->{'context'} eq 'paste') {
10597: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10598: ($path) =
10599: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10600: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10601: $fileloc =~ s{^/}{};
10602: }
1.1071 raeburn 10603: }
1.1084 raeburn 10604: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 10605: if ($env{'request.course.id'} ne '') {
10606: if (ref($args) eq 'HASH') {
10607: $url = $args->{'docs_url'};
10608: $title = $args->{'docs_title'};
1.1126 raeburn 10609: $toplevel = $url;
10610: unless ($toplevel =~ m{^/}) {
10611: $toplevel = "/$url";
10612: }
1.1085 raeburn 10613: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 10614: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10615: $path = $1;
10616: } else {
10617: ($path) =
10618: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10619: }
1.1195 raeburn 10620: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10621: $fileloc = $toplevel;
10622: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10623: my ($udom,$uname,$fname) =
10624: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10625: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10626: } else {
10627: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10628: }
1.1071 raeburn 10629: $fileloc =~ s{^/}{};
10630: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10631: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10632: }
1.987 raeburn 10633: }
1.1123 raeburn 10634: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10635: $udom = $cdom;
10636: $uname = $cnum;
10637: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10638: $toplevel = $url;
10639: $path = $url;
10640: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10641: $fileloc =~ s{^/}{};
1.987 raeburn 10642: }
1.1126 raeburn 10643: foreach my $file (keys(%{$allfiles})) {
10644: my $embed_file;
10645: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10646: $embed_file = $1;
10647: } else {
10648: $embed_file = $file;
10649: }
1.1158 raeburn 10650: my ($absolutepath,$cleaned_file);
10651: if ($embed_file =~ m{^\w+://}) {
10652: $cleaned_file = $embed_file;
1.1147 raeburn 10653: $newfiles{$cleaned_file} = 1;
10654: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10655: } else {
1.1158 raeburn 10656: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10657: if ($embed_file =~ m{^/}) {
10658: $absolutepath = $embed_file;
10659: }
1.1147 raeburn 10660: if ($cleaned_file =~ m{/}) {
10661: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10662: $path = &check_for_traversal($path,$url,$toplevel);
10663: my $item = $fname;
10664: if ($path ne '') {
10665: $item = $path.'/'.$fname;
10666: $subdependencies{$path}{$fname} = 1;
10667: } else {
10668: $dependencies{$item} = 1;
10669: }
10670: if ($absolutepath) {
10671: $mapping{$item} = $absolutepath;
10672: } else {
10673: $mapping{$item} = $embed_file;
10674: }
10675: } else {
10676: $dependencies{$embed_file} = 1;
10677: if ($absolutepath) {
1.1147 raeburn 10678: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10679: } else {
1.1147 raeburn 10680: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10681: }
10682: }
1.984 raeburn 10683: }
10684: }
1.1071 raeburn 10685: my $dirptr = 16384;
1.984 raeburn 10686: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10687: $currsubfile{$path} = {};
1.1123 raeburn 10688: if (($actionurl eq '/adm/portfolio') ||
10689: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10690: my ($sublistref,$listerror) =
10691: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10692: if (ref($sublistref) eq 'ARRAY') {
10693: foreach my $line (@{$sublistref}) {
10694: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10695: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10696: }
1.984 raeburn 10697: }
1.987 raeburn 10698: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10699: if (opendir(my $dir,$url.'/'.$path)) {
10700: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10701: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10702: }
1.1084 raeburn 10703: } elsif (($actionurl eq '/adm/dependencies') ||
10704: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 10705: ($args->{'context'} eq 'paste')) ||
10706: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10707: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 10708: my $dir;
10709: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10710: $dir = $fileloc;
10711: } else {
10712: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10713: }
1.1071 raeburn 10714: if ($dir ne '') {
10715: my ($sublistref,$listerror) =
10716: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10717: if (ref($sublistref) eq 'ARRAY') {
10718: foreach my $line (@{$sublistref}) {
10719: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10720: undef,$mtime)=split(/\&/,$line,12);
10721: unless (($testdir&$dirptr) ||
10722: ($file_name =~ /^\.\.?$/)) {
10723: $currsubfile{$path}{$file_name} = [$size,$mtime];
10724: }
10725: }
10726: }
10727: }
1.984 raeburn 10728: }
10729: }
10730: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10731: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10732: my $item = $path.'/'.$file;
10733: unless ($mapping{$item} eq $item) {
10734: $pathchanges{$item} = 1;
10735: }
10736: $existing{$item} = 1;
10737: $numexisting ++;
10738: } else {
10739: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10740: }
10741: }
1.1071 raeburn 10742: if ($actionurl eq '/adm/dependencies') {
10743: foreach my $path (keys(%currsubfile)) {
10744: if (ref($currsubfile{$path}) eq 'HASH') {
10745: foreach my $file (keys(%{$currsubfile{$path}})) {
10746: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 10747: next if (($rem ne '') &&
10748: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10749: (ref($navmap) &&
10750: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10751: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10752: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10753: $unused{$path.'/'.$file} = 1;
10754: }
10755: }
10756: }
10757: }
10758: }
1.984 raeburn 10759: }
1.987 raeburn 10760: my %currfile;
1.1123 raeburn 10761: if (($actionurl eq '/adm/portfolio') ||
10762: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10763: my ($dirlistref,$listerror) =
10764: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10765: if (ref($dirlistref) eq 'ARRAY') {
10766: foreach my $line (@{$dirlistref}) {
10767: my ($file_name,$rest) = split(/\&/,$line,2);
10768: $currfile{$file_name} = 1;
10769: }
1.984 raeburn 10770: }
1.987 raeburn 10771: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10772: if (opendir(my $dir,$url)) {
1.987 raeburn 10773: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10774: map {$currfile{$_} = 1;} @dir_list;
10775: }
1.1084 raeburn 10776: } elsif (($actionurl eq '/adm/dependencies') ||
10777: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 10778: ($args->{'context'} eq 'paste')) ||
10779: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10780: if ($env{'request.course.id'} ne '') {
10781: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10782: if ($dir ne '') {
10783: my ($dirlistref,$listerror) =
10784: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10785: if (ref($dirlistref) eq 'ARRAY') {
10786: foreach my $line (@{$dirlistref}) {
10787: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10788: $size,undef,$mtime)=split(/\&/,$line,12);
10789: unless (($testdir&$dirptr) ||
10790: ($file_name =~ /^\.\.?$/)) {
10791: $currfile{$file_name} = [$size,$mtime];
10792: }
10793: }
10794: }
10795: }
10796: }
1.984 raeburn 10797: }
10798: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10799: if (exists($currfile{$file})) {
1.987 raeburn 10800: unless ($mapping{$file} eq $file) {
10801: $pathchanges{$file} = 1;
10802: }
10803: $existing{$file} = 1;
10804: $numexisting ++;
10805: } else {
1.984 raeburn 10806: $newfiles{$file} = 1;
10807: }
10808: }
1.1071 raeburn 10809: foreach my $file (keys(%currfile)) {
10810: unless (($file eq $filename) ||
10811: ($file eq $filename.'.bak') ||
10812: ($dependencies{$file})) {
1.1085 raeburn 10813: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 10814: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10815: next if (($rem ne '') &&
10816: (($env{"httpref.$rem".$file} ne '') ||
10817: (ref($navmap) &&
10818: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10819: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10820: ($navmap->getResourceByUrl($rem.$1)))))));
10821: }
1.1085 raeburn 10822: }
1.1071 raeburn 10823: $unused{$file} = 1;
10824: }
10825: }
1.1084 raeburn 10826: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10827: ($args->{'context'} eq 'paste')) {
10828: $counter = scalar(keys(%existing));
10829: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 10830: return ($output,$counter,$numpathchg,\%existing);
10831: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10832: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10833: $counter = scalar(keys(%existing));
10834: $numpathchg = scalar(keys(%pathchanges));
10835: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 10836: }
1.984 raeburn 10837: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10838: if ($actionurl eq '/adm/dependencies') {
10839: next if ($embed_file =~ m{^\w+://});
10840: }
1.660 raeburn 10841: $upload_output .= &start_data_table_row().
1.1123 raeburn 10842: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10843: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10844: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 10845: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10846: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10847: }
1.1123 raeburn 10848: $upload_output .= '</td>';
1.1071 raeburn 10849: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 10850: $upload_output.='<td align="right">'.
10851: '<span class="LC_info LC_fontsize_medium">'.
10852: &mt("URL points to web address").'</span>';
1.987 raeburn 10853: $numremref++;
1.660 raeburn 10854: } elsif ($args->{'error_on_invalid_names'}
10855: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 10856: $upload_output.='<td align="right"><span class="LC_warning">'.
10857: &mt('Invalid characters').'</span>';
1.987 raeburn 10858: $numinvalid++;
1.660 raeburn 10859: } else {
1.1123 raeburn 10860: $upload_output .= '<td>'.
10861: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10862: $embed_file,\%mapping,
1.1071 raeburn 10863: $allfiles,$codebase,'upload');
10864: $counter ++;
10865: $numnew ++;
1.987 raeburn 10866: }
10867: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10868: }
10869: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10870: if ($actionurl eq '/adm/dependencies') {
10871: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10872: $modify_output .= &start_data_table_row().
10873: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10874: '<img src="'.&icon($embed_file).'" border="0" />'.
10875: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10876: '<td>'.$size.'</td>'.
10877: '<td>'.$mtime.'</td>'.
10878: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10879: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10880: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10881: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10882: &embedded_file_element('upload_embedded',$counter,
10883: $embed_file,\%mapping,
10884: $allfiles,$codebase,'modify').
10885: '</div></td>'.
10886: &end_data_table_row()."\n";
10887: $counter ++;
10888: } else {
10889: $upload_output .= &start_data_table_row().
1.1123 raeburn 10890: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10891: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10892: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10893: &Apache::loncommon::end_data_table_row()."\n";
10894: }
10895: }
10896: my $delidx = $counter;
10897: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10898: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10899: $delete_output .= &start_data_table_row().
10900: '<td><img src="'.&icon($oldfile).'" />'.
10901: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10902: '<td>'.$size.'</td>'.
10903: '<td>'.$mtime.'</td>'.
10904: '<td><label><input type="checkbox" name="del_upload_dep" '.
10905: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10906: &embedded_file_element('upload_embedded',$delidx,
10907: $oldfile,\%mapping,$allfiles,
10908: $codebase,'delete').'</td>'.
10909: &end_data_table_row()."\n";
10910: $numunused ++;
10911: $delidx ++;
1.987 raeburn 10912: }
10913: if ($upload_output) {
10914: $upload_output = &start_data_table().
10915: $upload_output.
10916: &end_data_table()."\n";
10917: }
1.1071 raeburn 10918: if ($modify_output) {
10919: $modify_output = &start_data_table().
10920: &start_data_table_header_row().
10921: '<th>'.&mt('File').'</th>'.
10922: '<th>'.&mt('Size (KB)').'</th>'.
10923: '<th>'.&mt('Modified').'</th>'.
10924: '<th>'.&mt('Upload replacement?').'</th>'.
10925: &end_data_table_header_row().
10926: $modify_output.
10927: &end_data_table()."\n";
10928: }
10929: if ($delete_output) {
10930: $delete_output = &start_data_table().
10931: &start_data_table_header_row().
10932: '<th>'.&mt('File').'</th>'.
10933: '<th>'.&mt('Size (KB)').'</th>'.
10934: '<th>'.&mt('Modified').'</th>'.
10935: '<th>'.&mt('Delete?').'</th>'.
10936: &end_data_table_header_row().
10937: $delete_output.
10938: &end_data_table()."\n";
10939: }
1.987 raeburn 10940: my $applies = 0;
10941: if ($numremref) {
10942: $applies ++;
10943: }
10944: if ($numinvalid) {
10945: $applies ++;
10946: }
10947: if ($numexisting) {
10948: $applies ++;
10949: }
1.1071 raeburn 10950: if ($counter || $numunused) {
1.987 raeburn 10951: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10952: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10953: $state.'<h3>'.$heading.'</h3>';
10954: if ($actionurl eq '/adm/dependencies') {
10955: if ($numnew) {
10956: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10957: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10958: $upload_output.'<br />'."\n";
10959: }
10960: if ($numexisting) {
10961: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10962: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10963: $modify_output.'<br />'."\n";
10964: $buttontext = &mt('Save changes');
10965: }
10966: if ($numunused) {
10967: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10968: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10969: $delete_output.'<br />'."\n";
10970: $buttontext = &mt('Save changes');
10971: }
10972: } else {
10973: $output .= $upload_output.'<br />'."\n";
10974: }
10975: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10976: $counter.'" />'."\n";
10977: if ($actionurl eq '/adm/dependencies') {
10978: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10979: $numnew.'" />'."\n";
10980: } elsif ($actionurl eq '') {
1.987 raeburn 10981: $output .= '<input type="hidden" name="phase" value="three" />';
10982: }
10983: } elsif ($applies) {
10984: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10985: if ($applies > 1) {
10986: $output .=
1.1123 raeburn 10987: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10988: if ($numremref) {
10989: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10990: }
10991: if ($numinvalid) {
10992: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10993: }
10994: if ($numexisting) {
10995: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10996: }
10997: $output .= '</ul><br />';
10998: } elsif ($numremref) {
10999: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11000: } elsif ($numinvalid) {
11001: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11002: } elsif ($numexisting) {
11003: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11004: }
11005: $output .= $upload_output.'<br />';
11006: }
11007: my ($pathchange_output,$chgcount);
1.1071 raeburn 11008: $chgcount = $counter;
1.987 raeburn 11009: if (keys(%pathchanges) > 0) {
11010: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11011: if ($counter) {
1.987 raeburn 11012: $output .= &embedded_file_element('pathchange',$chgcount,
11013: $embed_file,\%mapping,
1.1071 raeburn 11014: $allfiles,$codebase,'change');
1.987 raeburn 11015: } else {
11016: $pathchange_output .=
11017: &start_data_table_row().
11018: '<td><input type ="checkbox" name="namechange" value="'.
11019: $chgcount.'" checked="checked" /></td>'.
11020: '<td>'.$mapping{$embed_file}.'</td>'.
11021: '<td>'.$embed_file.
11022: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11023: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11024: '</td>'.&end_data_table_row();
1.660 raeburn 11025: }
1.987 raeburn 11026: $numpathchg ++;
11027: $chgcount ++;
1.660 raeburn 11028: }
11029: }
1.1127 raeburn 11030: if (($counter) || ($numunused)) {
1.987 raeburn 11031: if ($numpathchg) {
11032: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11033: $numpathchg.'" />'."\n";
11034: }
11035: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11036: ($actionurl eq '/adm/imsimport')) {
11037: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11038: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11039: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11040: } elsif ($actionurl eq '/adm/dependencies') {
11041: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11042: }
1.1123 raeburn 11043: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11044: } elsif ($numpathchg) {
11045: my %pathchange = ();
11046: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11047: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11048: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11049: }
1.987 raeburn 11050: }
1.1071 raeburn 11051: return ($output,$counter,$numpathchg);
1.987 raeburn 11052: }
11053:
1.1147 raeburn 11054: =pod
11055:
11056: =item * clean_path($name)
11057:
11058: Performs clean-up of directories, subdirectories and filename in an
11059: embedded object, referenced in an HTML file which is being uploaded
11060: to a course or portfolio, where
11061: "Upload embedded images/multimedia files if HTML file" checkbox was
11062: checked.
11063:
11064: Clean-up is similar to replacements in lonnet::clean_filename()
11065: except each / between sub-directory and next level is preserved.
11066:
11067: =cut
11068:
11069: sub clean_path {
11070: my ($embed_file) = @_;
11071: $embed_file =~s{^/+}{};
11072: my @contents;
11073: if ($embed_file =~ m{/}) {
11074: @contents = split(/\//,$embed_file);
11075: } else {
11076: @contents = ($embed_file);
11077: }
11078: my $lastidx = scalar(@contents)-1;
11079: for (my $i=0; $i<=$lastidx; $i++) {
11080: $contents[$i]=~s{\\}{/}g;
11081: $contents[$i]=~s/\s+/\_/g;
11082: $contents[$i]=~s{[^/\w\.\-]}{}g;
11083: if ($i == $lastidx) {
11084: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11085: }
11086: }
11087: if ($lastidx > 0) {
11088: return join('/',@contents);
11089: } else {
11090: return $contents[0];
11091: }
11092: }
11093:
1.987 raeburn 11094: sub embedded_file_element {
1.1071 raeburn 11095: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11096: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11097: (ref($codebase) eq 'HASH'));
11098: my $output;
1.1071 raeburn 11099: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11100: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11101: }
11102: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11103: &escape($embed_file).'" />';
11104: unless (($context eq 'upload_embedded') &&
11105: ($mapping->{$embed_file} eq $embed_file)) {
11106: $output .='
11107: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11108: }
11109: my $attrib;
11110: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11111: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11112: }
11113: $output .=
11114: "\n\t\t".
11115: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11116: $attrib.'" />';
11117: if (exists($codebase->{$mapping->{$embed_file}})) {
11118: $output .=
11119: "\n\t\t".
11120: '<input name="codebase_'.$num.'" type="hidden" value="'.
11121: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11122: }
1.987 raeburn 11123: return $output;
1.660 raeburn 11124: }
11125:
1.1071 raeburn 11126: sub get_dependency_details {
11127: my ($currfile,$currsubfile,$embed_file) = @_;
11128: my ($size,$mtime,$showsize,$showmtime);
11129: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11130: if ($embed_file =~ m{/}) {
11131: my ($path,$fname) = split(/\//,$embed_file);
11132: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11133: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11134: }
11135: } else {
11136: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11137: ($size,$mtime) = @{$currfile->{$embed_file}};
11138: }
11139: }
11140: $showsize = $size/1024.0;
11141: $showsize = sprintf("%.1f",$showsize);
11142: if ($mtime > 0) {
11143: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11144: }
11145: }
11146: return ($showsize,$showmtime);
11147: }
11148:
11149: sub ask_embedded_js {
11150: return <<"END";
11151: <script type="text/javascript"">
11152: // <![CDATA[
11153: function toggleBrowse(counter) {
11154: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11155: var fileid = document.getElementById('embedded_item_'+counter);
11156: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11157: if (chkboxid.checked == true) {
11158: uploaddivid.style.display='block';
11159: } else {
11160: uploaddivid.style.display='none';
11161: fileid.value = '';
11162: }
11163: }
11164: // ]]>
11165: </script>
11166:
11167: END
11168: }
11169:
1.661 raeburn 11170: sub upload_embedded {
11171: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11172: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11173: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11174: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11175: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11176: my $orig_uploaded_filename =
11177: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11178: foreach my $type ('orig','ref','attrib','codebase') {
11179: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11180: $env{'form.embedded_'.$type.'_'.$i} =
11181: &unescape($env{'form.embedded_'.$type.'_'.$i});
11182: }
11183: }
1.661 raeburn 11184: my ($path,$fname) =
11185: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11186: # no path, whole string is fname
11187: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11188: $fname = &Apache::lonnet::clean_filename($fname);
11189: # See if there is anything left
11190: next if ($fname eq '');
11191:
11192: # Check if file already exists as a file or directory.
11193: my ($state,$msg);
11194: if ($context eq 'portfolio') {
11195: my $port_path = $dirpath;
11196: if ($group ne '') {
11197: $port_path = "groups/$group/$port_path";
11198: }
1.987 raeburn 11199: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11200: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11201: $dir_root,$port_path,$disk_quota,
11202: $current_disk_usage,$uname,$udom);
11203: if ($state eq 'will_exceed_quota'
1.984 raeburn 11204: || $state eq 'file_locked') {
1.661 raeburn 11205: $output .= $msg;
11206: next;
11207: }
11208: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11209: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11210: if ($state eq 'exists') {
11211: $output .= $msg;
11212: next;
11213: }
11214: }
11215: # Check if extension is valid
11216: if (($fname =~ /\.(\w+)$/) &&
11217: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 11218: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11219: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11220: next;
11221: } elsif (($fname =~ /\.(\w+)$/) &&
11222: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11223: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11224: next;
11225: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 11226: $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 11227: next;
11228: }
11229: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 11230: my $subdir = $path;
11231: $subdir =~ s{/+$}{};
1.661 raeburn 11232: if ($context eq 'portfolio') {
1.984 raeburn 11233: my $result;
11234: if ($state eq 'existingfile') {
11235: $result=
11236: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 11237: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11238: } else {
1.984 raeburn 11239: $result=
11240: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11241: $dirpath.
1.1123 raeburn 11242: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11243: if ($result !~ m|^/uploaded/|) {
11244: $output .= '<span class="LC_error">'
11245: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11246: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11247: .'</span><br />';
11248: next;
11249: } else {
1.987 raeburn 11250: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11251: $path.$fname.'</span>').'<br />';
1.984 raeburn 11252: }
1.661 raeburn 11253: }
1.1123 raeburn 11254: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 11255: my $extendedsubdir = $dirpath.'/'.$subdir;
11256: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11257: my $result =
1.1126 raeburn 11258: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11259: if ($result !~ m|^/uploaded/|) {
11260: $output .= '<span class="LC_error">'
11261: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11262: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11263: .'</span><br />';
11264: next;
11265: } else {
11266: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11267: $path.$fname.'</span>').'<br />';
1.1125 raeburn 11268: if ($context eq 'syllabus') {
11269: &Apache::lonnet::make_public_indefinitely($result);
11270: }
1.987 raeburn 11271: }
1.661 raeburn 11272: } else {
11273: # Save the file
11274: my $target = $env{'form.embedded_item_'.$i};
11275: my $fullpath = $dir_root.$dirpath.'/'.$path;
11276: my $dest = $fullpath.$fname;
11277: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11278: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11279: my $count;
11280: my $filepath = $dir_root;
1.1027 raeburn 11281: foreach my $subdir (@parts) {
11282: $filepath .= "/$subdir";
11283: if (!-e $filepath) {
1.661 raeburn 11284: mkdir($filepath,0770);
11285: }
11286: }
11287: my $fh;
11288: if (!open($fh,'>'.$dest)) {
11289: &Apache::lonnet::logthis('Failed to create '.$dest);
11290: $output .= '<span class="LC_error">'.
1.1071 raeburn 11291: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11292: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11293: '</span><br />';
11294: } else {
11295: if (!print $fh $env{'form.embedded_item_'.$i}) {
11296: &Apache::lonnet::logthis('Failed to write to '.$dest);
11297: $output .= '<span class="LC_error">'.
1.1071 raeburn 11298: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11299: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11300: '</span><br />';
11301: } else {
1.987 raeburn 11302: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11303: $url.'</span>').'<br />';
11304: unless ($context eq 'testbank') {
11305: $footer .= &mt('View embedded file: [_1]',
11306: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11307: }
11308: }
11309: close($fh);
11310: }
11311: }
11312: if ($env{'form.embedded_ref_'.$i}) {
11313: $pathchange{$i} = 1;
11314: }
11315: }
11316: if ($output) {
11317: $output = '<p>'.$output.'</p>';
11318: }
11319: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11320: $returnflag = 'ok';
1.1071 raeburn 11321: my $numpathchgs = scalar(keys(%pathchange));
11322: if ($numpathchgs > 0) {
1.987 raeburn 11323: if ($context eq 'portfolio') {
11324: $output .= '<p>'.&mt('or').'</p>';
11325: } elsif ($context eq 'testbank') {
1.1071 raeburn 11326: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11327: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11328: $returnflag = 'modify_orightml';
11329: }
11330: }
1.1071 raeburn 11331: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11332: }
11333:
11334: sub modify_html_form {
11335: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11336: my $end = 0;
11337: my $modifyform;
11338: if ($context eq 'upload_embedded') {
11339: return unless (ref($pathchange) eq 'HASH');
11340: if ($env{'form.number_embedded_items'}) {
11341: $end += $env{'form.number_embedded_items'};
11342: }
11343: if ($env{'form.number_pathchange_items'}) {
11344: $end += $env{'form.number_pathchange_items'};
11345: }
11346: if ($end) {
11347: for (my $i=0; $i<$end; $i++) {
11348: if ($i < $env{'form.number_embedded_items'}) {
11349: next unless($pathchange->{$i});
11350: }
11351: $modifyform .=
11352: &start_data_table_row().
11353: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11354: 'checked="checked" /></td>'.
11355: '<td>'.$env{'form.embedded_ref_'.$i}.
11356: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11357: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11358: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11359: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11360: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11361: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11362: '<td>'.$env{'form.embedded_orig_'.$i}.
11363: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11364: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11365: &end_data_table_row();
1.1071 raeburn 11366: }
1.987 raeburn 11367: }
11368: } else {
11369: $modifyform = $pathchgtable;
11370: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11371: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11372: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11373: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11374: }
11375: }
11376: if ($modifyform) {
1.1071 raeburn 11377: if ($actionurl eq '/adm/dependencies') {
11378: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11379: }
1.987 raeburn 11380: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11381: '<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".
11382: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11383: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11384: '</ol></p>'."\n".'<p>'.
11385: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11386: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11387: &start_data_table()."\n".
11388: &start_data_table_header_row().
11389: '<th>'.&mt('Change?').'</th>'.
11390: '<th>'.&mt('Current reference').'</th>'.
11391: '<th>'.&mt('Required reference').'</th>'.
11392: &end_data_table_header_row()."\n".
11393: $modifyform.
11394: &end_data_table().'<br />'."\n".$hiddenstate.
11395: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11396: '</form>'."\n";
11397: }
11398: return;
11399: }
11400:
11401: sub modify_html_refs {
1.1123 raeburn 11402: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11403: my $container;
11404: if ($context eq 'portfolio') {
11405: $container = $env{'form.container'};
11406: } elsif ($context eq 'coursedoc') {
11407: $container = $env{'form.primaryurl'};
1.1071 raeburn 11408: } elsif ($context eq 'manage_dependencies') {
11409: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11410: $container = "/$container";
1.1123 raeburn 11411: } elsif ($context eq 'syllabus') {
11412: $container = $url;
1.987 raeburn 11413: } else {
1.1027 raeburn 11414: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11415: }
11416: my (%allfiles,%codebase,$output,$content);
11417: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 11418: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11419: if (wantarray) {
11420: return ('',0,0);
11421: } else {
11422: return;
11423: }
11424: }
11425: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11426: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11427: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11428: if (wantarray) {
11429: return ('',0,0);
11430: } else {
11431: return;
11432: }
11433: }
1.987 raeburn 11434: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11435: if ($content eq '-1') {
11436: if (wantarray) {
11437: return ('',0,0);
11438: } else {
11439: return;
11440: }
11441: }
1.987 raeburn 11442: } else {
1.1071 raeburn 11443: unless ($container =~ /^\Q$dir_root\E/) {
11444: if (wantarray) {
11445: return ('',0,0);
11446: } else {
11447: return;
11448: }
11449: }
1.987 raeburn 11450: if (open(my $fh,"<$container")) {
11451: $content = join('', <$fh>);
11452: close($fh);
11453: } else {
1.1071 raeburn 11454: if (wantarray) {
11455: return ('',0,0);
11456: } else {
11457: return;
11458: }
1.987 raeburn 11459: }
11460: }
11461: my ($count,$codebasecount) = (0,0);
11462: my $mm = new File::MMagic;
11463: my $mime_type = $mm->checktype_contents($content);
11464: if ($mime_type eq 'text/html') {
11465: my $parse_result =
11466: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11467: \%codebase,\$content);
11468: if ($parse_result eq 'ok') {
11469: foreach my $i (@changes) {
11470: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11471: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11472: if ($allfiles{$ref}) {
11473: my $newname = $orig;
11474: my ($attrib_regexp,$codebase);
1.1006 raeburn 11475: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11476: if ($attrib_regexp =~ /:/) {
11477: $attrib_regexp =~ s/\:/|/g;
11478: }
11479: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11480: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11481: $count += $numchg;
1.1123 raeburn 11482: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 11483: delete($allfiles{$ref});
1.987 raeburn 11484: }
11485: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11486: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11487: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11488: $codebasecount ++;
11489: }
11490: }
11491: }
1.1123 raeburn 11492: my $skiprewrites;
1.987 raeburn 11493: if ($count || $codebasecount) {
11494: my $saveresult;
1.1071 raeburn 11495: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11496: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11497: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11498: if ($url eq $container) {
11499: my ($fname) = ($container =~ m{/([^/]+)$});
11500: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11501: $count,'<span class="LC_filename">'.
1.1071 raeburn 11502: $fname.'</span>').'</p>';
1.987 raeburn 11503: } else {
11504: $output = '<p class="LC_error">'.
11505: &mt('Error: update failed for: [_1].',
11506: '<span class="LC_filename">'.
11507: $container.'</span>').'</p>';
11508: }
1.1123 raeburn 11509: if ($context eq 'syllabus') {
11510: unless ($saveresult eq 'ok') {
11511: $skiprewrites = 1;
11512: }
11513: }
1.987 raeburn 11514: } else {
11515: if (open(my $fh,">$container")) {
11516: print $fh $content;
11517: close($fh);
11518: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11519: $count,'<span class="LC_filename">'.
11520: $container.'</span>').'</p>';
1.661 raeburn 11521: } else {
1.987 raeburn 11522: $output = '<p class="LC_error">'.
11523: &mt('Error: could not update [_1].',
11524: '<span class="LC_filename">'.
11525: $container.'</span>').'</p>';
1.661 raeburn 11526: }
11527: }
11528: }
1.1123 raeburn 11529: if (($context eq 'syllabus') && (!$skiprewrites)) {
11530: my ($actionurl,$state);
11531: $actionurl = "/public/$udom/$uname/syllabus";
11532: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11533: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11534: \%codebase,
11535: {'context' => 'rewrites',
11536: 'ignore_remote_references' => 1,});
11537: if (ref($mapping) eq 'HASH') {
11538: my $rewrites = 0;
11539: foreach my $key (keys(%{$mapping})) {
11540: next if ($key =~ m{^https?://});
11541: my $ref = $mapping->{$key};
11542: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11543: my $attrib;
11544: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11545: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11546: }
11547: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11548: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11549: $rewrites += $numchg;
11550: }
11551: }
11552: if ($rewrites) {
11553: my $saveresult;
11554: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11555: if ($url eq $container) {
11556: my ($fname) = ($container =~ m{/([^/]+)$});
11557: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11558: $count,'<span class="LC_filename">'.
11559: $fname.'</span>').'</p>';
11560: } else {
11561: $output .= '<p class="LC_error">'.
11562: &mt('Error: could not update links in [_1].',
11563: '<span class="LC_filename">'.
11564: $container.'</span>').'</p>';
11565:
11566: }
11567: }
11568: }
11569: }
1.987 raeburn 11570: } else {
11571: &logthis('Failed to parse '.$container.
11572: ' to modify references: '.$parse_result);
1.661 raeburn 11573: }
11574: }
1.1071 raeburn 11575: if (wantarray) {
11576: return ($output,$count,$codebasecount);
11577: } else {
11578: return $output;
11579: }
1.661 raeburn 11580: }
11581:
11582: sub check_for_existing {
11583: my ($path,$fname,$element) = @_;
11584: my ($state,$msg);
11585: if (-d $path.'/'.$fname) {
11586: $state = 'exists';
11587: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11588: } elsif (-e $path.'/'.$fname) {
11589: $state = 'exists';
11590: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11591: }
11592: if ($state eq 'exists') {
11593: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11594: }
11595: return ($state,$msg);
11596: }
11597:
11598: sub check_for_upload {
11599: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11600: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11601: my $filesize = length($env{'form.'.$element});
11602: if (!$filesize) {
11603: my $msg = '<span class="LC_error">'.
11604: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11605: '<span class="LC_filename">'.$fname.'</span>',
11606: $filesize).'<br />'.
1.1007 raeburn 11607: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11608: '</span>';
11609: return ('zero_bytes',$msg);
11610: }
11611: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11612: my $getpropath = 1;
1.1021 raeburn 11613: my ($dirlistref,$listerror) =
11614: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11615: my $found_file = 0;
11616: my $locked_file = 0;
1.991 raeburn 11617: my @lockers;
11618: my $navmap;
11619: if ($env{'request.course.id'}) {
11620: $navmap = Apache::lonnavmaps::navmap->new();
11621: }
1.1021 raeburn 11622: if (ref($dirlistref) eq 'ARRAY') {
11623: foreach my $line (@{$dirlistref}) {
11624: my ($file_name,$rest)=split(/\&/,$line,2);
11625: if ($file_name eq $fname){
11626: $file_name = $path.$file_name;
11627: if ($group ne '') {
11628: $file_name = $group.$file_name;
11629: }
11630: $found_file = 1;
11631: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11632: foreach my $lock (@lockers) {
11633: if (ref($lock) eq 'ARRAY') {
11634: my ($symb,$crsid) = @{$lock};
11635: if ($crsid eq $env{'request.course.id'}) {
11636: if (ref($navmap)) {
11637: my $res = $navmap->getBySymb($symb);
11638: foreach my $part (@{$res->parts()}) {
11639: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11640: unless (($slot_status == $res->RESERVED) ||
11641: ($slot_status == $res->RESERVED_LOCATION)) {
11642: $locked_file = 1;
11643: }
1.991 raeburn 11644: }
1.1021 raeburn 11645: } else {
11646: $locked_file = 1;
1.991 raeburn 11647: }
11648: } else {
11649: $locked_file = 1;
11650: }
11651: }
1.1021 raeburn 11652: }
11653: } else {
11654: my @info = split(/\&/,$rest);
11655: my $currsize = $info[6]/1000;
11656: if ($currsize < $filesize) {
11657: my $extra = $filesize - $currsize;
11658: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 11659: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11660: &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 11661: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11662: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11663: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11664: return ('will_exceed_quota',$msg);
11665: }
1.984 raeburn 11666: }
11667: }
1.661 raeburn 11668: }
11669: }
11670: }
11671: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 11672: my $msg = '<p class="LC_warning">'.
11673: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 11674: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11675: return ('will_exceed_quota',$msg);
11676: } elsif ($found_file) {
11677: if ($locked_file) {
1.1179 bisitz 11678: my $msg = '<p class="LC_warning">';
1.661 raeburn 11679: $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 11680: $msg .= '</p>';
1.661 raeburn 11681: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11682: return ('file_locked',$msg);
11683: } else {
1.1179 bisitz 11684: my $msg = '<p class="LC_error">';
1.984 raeburn 11685: $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 11686: $msg .= '</p>';
1.984 raeburn 11687: return ('existingfile',$msg);
1.661 raeburn 11688: }
11689: }
11690: }
11691:
1.987 raeburn 11692: sub check_for_traversal {
11693: my ($path,$url,$toplevel) = @_;
11694: my @parts=split(/\//,$path);
11695: my $cleanpath;
11696: my $fullpath = $url;
11697: for (my $i=0;$i<@parts;$i++) {
11698: next if ($parts[$i] eq '.');
11699: if ($parts[$i] eq '..') {
11700: $fullpath =~ s{([^/]+/)$}{};
11701: } else {
11702: $fullpath .= $parts[$i].'/';
11703: }
11704: }
11705: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11706: $cleanpath = $1;
11707: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11708: my $curr_toprel = $1;
11709: my @parts = split(/\//,$curr_toprel);
11710: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11711: my @urlparts = split(/\//,$url_toprel);
11712: my $doubledots;
11713: my $startdiff = -1;
11714: for (my $i=0; $i<@urlparts; $i++) {
11715: if ($startdiff == -1) {
11716: unless ($urlparts[$i] eq $parts[$i]) {
11717: $startdiff = $i;
11718: $doubledots .= '../';
11719: }
11720: } else {
11721: $doubledots .= '../';
11722: }
11723: }
11724: if ($startdiff > -1) {
11725: $cleanpath = $doubledots;
11726: for (my $i=$startdiff; $i<@parts; $i++) {
11727: $cleanpath .= $parts[$i].'/';
11728: }
11729: }
11730: }
11731: $cleanpath =~ s{(/)$}{};
11732: return $cleanpath;
11733: }
1.31 albertel 11734:
1.1053 raeburn 11735: sub is_archive_file {
11736: my ($mimetype) = @_;
11737: if (($mimetype eq 'application/octet-stream') ||
11738: ($mimetype eq 'application/x-stuffit') ||
11739: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11740: return 1;
11741: }
11742: return;
11743: }
11744:
11745: sub decompress_form {
1.1065 raeburn 11746: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11747: my %lt = &Apache::lonlocal::texthash (
11748: this => 'This file is an archive file.',
1.1067 raeburn 11749: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11750: itsc => 'Its contents are as follows:',
1.1053 raeburn 11751: youm => 'You may wish to extract its contents.',
11752: extr => 'Extract contents',
1.1067 raeburn 11753: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11754: proa => 'Process automatically?',
1.1053 raeburn 11755: yes => 'Yes',
11756: no => 'No',
1.1067 raeburn 11757: fold => 'Title for folder containing movie',
11758: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11759: );
1.1065 raeburn 11760: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11761: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11762: my $info = &list_archive_contents($fileloc,\@paths);
11763: if (@paths) {
11764: foreach my $path (@paths) {
11765: $path =~ s{^/}{};
1.1067 raeburn 11766: if ($path =~ m{^([^/]+)/$}) {
11767: $topdir = $1;
11768: }
1.1065 raeburn 11769: if ($path =~ m{^([^/]+)/}) {
11770: $toplevel{$1} = $path;
11771: } else {
11772: $toplevel{$path} = $path;
11773: }
11774: }
11775: }
1.1067 raeburn 11776: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 11777: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11778: "$topdir/media/",
11779: "$topdir/media/$topdir.mp4",
11780: "$topdir/media/FirstFrame.png",
11781: "$topdir/media/player.swf",
11782: "$topdir/media/swfobject.js",
11783: "$topdir/media/expressInstall.swf");
1.1197 raeburn 11784: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 11785: "$topdir/$topdir.mp4",
11786: "$topdir/$topdir\_config.xml",
11787: "$topdir/$topdir\_controller.swf",
11788: "$topdir/$topdir\_embed.css",
11789: "$topdir/$topdir\_First_Frame.png",
11790: "$topdir/$topdir\_player.html",
11791: "$topdir/$topdir\_Thumbnails.png",
11792: "$topdir/playerProductInstall.swf",
11793: "$topdir/scripts/",
11794: "$topdir/scripts/config_xml.js",
11795: "$topdir/scripts/handlebars.js",
11796: "$topdir/scripts/jquery-1.7.1.min.js",
11797: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11798: "$topdir/scripts/modernizr.js",
11799: "$topdir/scripts/player-min.js",
11800: "$topdir/scripts/swfobject.js",
11801: "$topdir/skins/",
11802: "$topdir/skins/configuration_express.xml",
11803: "$topdir/skins/express_show/",
11804: "$topdir/skins/express_show/player-min.css",
11805: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 11806: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11807: "$topdir/$topdir.mp4",
11808: "$topdir/$topdir\_config.xml",
11809: "$topdir/$topdir\_controller.swf",
11810: "$topdir/$topdir\_embed.css",
11811: "$topdir/$topdir\_First_Frame.png",
11812: "$topdir/$topdir\_player.html",
11813: "$topdir/$topdir\_Thumbnails.png",
11814: "$topdir/playerProductInstall.swf",
11815: "$topdir/scripts/",
11816: "$topdir/scripts/config_xml.js",
11817: "$topdir/scripts/techsmith-smart-player.min.js",
11818: "$topdir/skins/",
11819: "$topdir/skins/configuration_express.xml",
11820: "$topdir/skins/express_show/",
11821: "$topdir/skins/express_show/spritesheet.min.css",
11822: "$topdir/skins/express_show/spritesheet.png",
11823: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 11824: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11825: if (@diffs == 0) {
1.1164 raeburn 11826: $is_camtasia = 6;
11827: } else {
1.1197 raeburn 11828: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 11829: if (@diffs == 0) {
11830: $is_camtasia = 8;
1.1197 raeburn 11831: } else {
11832: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
11833: if (@diffs == 0) {
11834: $is_camtasia = 8;
11835: }
1.1164 raeburn 11836: }
1.1067 raeburn 11837: }
11838: }
11839: my $output;
11840: if ($is_camtasia) {
11841: $output = <<"ENDCAM";
11842: <script type="text/javascript" language="Javascript">
11843: // <![CDATA[
11844:
11845: function camtasiaToggle() {
11846: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11847: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 11848: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11849: document.getElementById('camtasia_titles').style.display='block';
11850: } else {
11851: document.getElementById('camtasia_titles').style.display='none';
11852: }
11853: }
11854: }
11855: return;
11856: }
11857:
11858: // ]]>
11859: </script>
11860: <p>$lt{'camt'}</p>
11861: ENDCAM
1.1065 raeburn 11862: } else {
1.1067 raeburn 11863: $output = '<p>'.$lt{'this'};
11864: if ($info eq '') {
11865: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11866: } else {
11867: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11868: '<div><pre>'.$info.'</pre></div>';
11869: }
1.1065 raeburn 11870: }
1.1067 raeburn 11871: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11872: my $duplicates;
11873: my $num = 0;
11874: if (ref($dirlist) eq 'ARRAY') {
11875: foreach my $item (@{$dirlist}) {
11876: if (ref($item) eq 'ARRAY') {
11877: if (exists($toplevel{$item->[0]})) {
11878: $duplicates .=
11879: &start_data_table_row().
11880: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11881: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11882: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11883: 'value="1" />'.&mt('Yes').'</label>'.
11884: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11885: '<td>'.$item->[0].'</td>';
11886: if ($item->[2]) {
11887: $duplicates .= '<td>'.&mt('Directory').'</td>';
11888: } else {
11889: $duplicates .= '<td>'.&mt('File').'</td>';
11890: }
11891: $duplicates .= '<td>'.$item->[3].'</td>'.
11892: '<td>'.
11893: &Apache::lonlocal::locallocaltime($item->[4]).
11894: '</td>'.
11895: &end_data_table_row();
11896: $num ++;
11897: }
11898: }
11899: }
11900: }
11901: my $itemcount;
11902: if (@paths > 0) {
11903: $itemcount = scalar(@paths);
11904: } else {
11905: $itemcount = 1;
11906: }
1.1067 raeburn 11907: if ($is_camtasia) {
11908: $output .= $lt{'auto'}.'<br />'.
11909: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 11910: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11911: $lt{'yes'}.'</label> <label>'.
11912: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11913: $lt{'no'}.'</label></span><br />'.
11914: '<div id="camtasia_titles" style="display:block">'.
11915: &Apache::lonhtmlcommon::start_pick_box().
11916: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11917: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11918: &Apache::lonhtmlcommon::row_closure().
11919: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11920: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11921: &Apache::lonhtmlcommon::row_closure(1).
11922: &Apache::lonhtmlcommon::end_pick_box().
11923: '</div>';
11924: }
1.1065 raeburn 11925: $output .=
11926: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11927: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11928: "\n";
1.1065 raeburn 11929: if ($duplicates ne '') {
11930: $output .= '<p><span class="LC_warning">'.
11931: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11932: &start_data_table().
11933: &start_data_table_header_row().
11934: '<th>'.&mt('Overwrite?').'</th>'.
11935: '<th>'.&mt('Name').'</th>'.
11936: '<th>'.&mt('Type').'</th>'.
11937: '<th>'.&mt('Size').'</th>'.
11938: '<th>'.&mt('Last modified').'</th>'.
11939: &end_data_table_header_row().
11940: $duplicates.
11941: &end_data_table().
11942: '</p>';
11943: }
1.1067 raeburn 11944: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11945: if (ref($hiddenelements) eq 'HASH') {
11946: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11947: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11948: }
11949: }
11950: $output .= <<"END";
1.1067 raeburn 11951: <br />
1.1053 raeburn 11952: <input type="submit" name="decompress" value="$lt{'extr'}" />
11953: </form>
11954: $noextract
11955: END
11956: return $output;
11957: }
11958:
1.1065 raeburn 11959: sub decompression_utility {
11960: my ($program) = @_;
11961: my @utilities = ('tar','gunzip','bunzip2','unzip');
11962: my $location;
11963: if (grep(/^\Q$program\E$/,@utilities)) {
11964: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11965: '/usr/sbin/') {
11966: if (-x $dir.$program) {
11967: $location = $dir.$program;
11968: last;
11969: }
11970: }
11971: }
11972: return $location;
11973: }
11974:
11975: sub list_archive_contents {
11976: my ($file,$pathsref) = @_;
11977: my (@cmd,$output);
11978: my $needsregexp;
11979: if ($file =~ /\.zip$/) {
11980: @cmd = (&decompression_utility('unzip'),"-l");
11981: $needsregexp = 1;
11982: } elsif (($file =~ m/\.tar\.gz$/) ||
11983: ($file =~ /\.tgz$/)) {
11984: @cmd = (&decompression_utility('tar'),"-ztf");
11985: } elsif ($file =~ /\.tar\.bz2$/) {
11986: @cmd = (&decompression_utility('tar'),"-jtf");
11987: } elsif ($file =~ m|\.tar$|) {
11988: @cmd = (&decompression_utility('tar'),"-tf");
11989: }
11990: if (@cmd) {
11991: undef($!);
11992: undef($@);
11993: if (open(my $fh,"-|", @cmd, $file)) {
11994: while (my $line = <$fh>) {
11995: $output .= $line;
11996: chomp($line);
11997: my $item;
11998: if ($needsregexp) {
11999: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12000: } else {
12001: $item = $line;
12002: }
12003: if ($item ne '') {
12004: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12005: push(@{$pathsref},$item);
12006: }
12007: }
12008: }
12009: close($fh);
12010: }
12011: }
12012: return $output;
12013: }
12014:
1.1053 raeburn 12015: sub decompress_uploaded_file {
12016: my ($file,$dir) = @_;
12017: &Apache::lonnet::appenv({'cgi.file' => $file});
12018: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12019: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12020: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12021: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12022: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12023: my $decompressed = $env{'cgi.decompressed'};
12024: &Apache::lonnet::delenv('cgi.file');
12025: &Apache::lonnet::delenv('cgi.dir');
12026: &Apache::lonnet::delenv('cgi.decompressed');
12027: return ($decompressed,$result);
12028: }
12029:
1.1055 raeburn 12030: sub process_decompression {
12031: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
12032: my ($dir,$error,$warning,$output);
1.1180 raeburn 12033: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12034: $error = &mt('Filename not a supported archive file type.').
12035: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12036: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12037: } else {
12038: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12039: if ($docuhome eq 'no_host') {
12040: $error = &mt('Could not determine home server for course.');
12041: } else {
12042: my @ids=&Apache::lonnet::current_machine_ids();
12043: my $currdir = "$dir_root/$destination";
12044: if (grep(/^\Q$docuhome\E$/,@ids)) {
12045: $dir = &LONCAPA::propath($docudom,$docuname).
12046: "$dir_root/$destination";
12047: } else {
12048: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12049: "$dir_root/$docudom/$docuname/$destination";
12050: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12051: $error = &mt('Archive file not found.');
12052: }
12053: }
1.1065 raeburn 12054: my (@to_overwrite,@to_skip);
12055: if ($env{'form.archive_overwrite_total'} > 0) {
12056: my $total = $env{'form.archive_overwrite_total'};
12057: for (my $i=0; $i<$total; $i++) {
12058: if ($env{'form.archive_overwrite_'.$i} == 1) {
12059: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12060: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12061: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12062: }
12063: }
12064: }
12065: my $numskip = scalar(@to_skip);
12066: if (($numskip > 0) &&
12067: ($numskip == $env{'form.archive_itemcount'})) {
12068: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12069: } elsif ($dir eq '') {
1.1055 raeburn 12070: $error = &mt('Directory containing archive file unavailable.');
12071: } elsif (!$error) {
1.1065 raeburn 12072: my ($decompressed,$display);
12073: if ($numskip > 0) {
12074: my $tempdir = time.'_'.$$.int(rand(10000));
12075: mkdir("$dir/$tempdir",0755);
12076: system("mv $dir/$file $dir/$tempdir/$file");
12077: ($decompressed,$display) =
12078: &decompress_uploaded_file($file,"$dir/$tempdir");
12079: foreach my $item (@to_skip) {
12080: if (($item ne '') && ($item !~ /\.\./)) {
12081: if (-f "$dir/$tempdir/$item") {
12082: unlink("$dir/$tempdir/$item");
12083: } elsif (-d "$dir/$tempdir/$item") {
12084: system("rm -rf $dir/$tempdir/$item");
12085: }
12086: }
12087: }
12088: system("mv $dir/$tempdir/* $dir");
12089: rmdir("$dir/$tempdir");
12090: } else {
12091: ($decompressed,$display) =
12092: &decompress_uploaded_file($file,$dir);
12093: }
1.1055 raeburn 12094: if ($decompressed eq 'ok') {
1.1065 raeburn 12095: $output = '<p class="LC_info">'.
12096: &mt('Files extracted successfully from archive.').
12097: '</p>'."\n";
1.1055 raeburn 12098: my ($warning,$result,@contents);
12099: my ($newdirlistref,$newlisterror) =
12100: &Apache::lonnet::dirlist($currdir,$docudom,
12101: $docuname,1);
12102: my (%is_dir,%changes,@newitems);
12103: my $dirptr = 16384;
1.1065 raeburn 12104: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12105: foreach my $dir_line (@{$newdirlistref}) {
12106: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 12107: unless (($item =~ /^\.+$/) || ($item eq $file) ||
12108: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 12109: push(@newitems,$item);
12110: if ($dirptr&$testdir) {
12111: $is_dir{$item} = 1;
12112: }
12113: $changes{$item} = 1;
12114: }
12115: }
12116: }
12117: if (keys(%changes) > 0) {
12118: foreach my $item (sort(@newitems)) {
12119: if ($changes{$item}) {
12120: push(@contents,$item);
12121: }
12122: }
12123: }
12124: if (@contents > 0) {
1.1067 raeburn 12125: my $wantform;
12126: unless ($env{'form.autoextract_camtasia'}) {
12127: $wantform = 1;
12128: }
1.1056 raeburn 12129: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12130: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12131: $currdir,\%is_dir,
12132: \%children,\%parent,
1.1056 raeburn 12133: \@contents,\%dirorder,
12134: \%titles,$wantform);
1.1055 raeburn 12135: if ($datatable ne '') {
12136: $output .= &archive_options_form('decompressed',$datatable,
12137: $count,$hiddenelem);
1.1065 raeburn 12138: my $startcount = 6;
1.1055 raeburn 12139: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12140: \%titles,\%children);
1.1055 raeburn 12141: }
1.1067 raeburn 12142: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 12143: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12144: my %displayed;
12145: my $total = 1;
12146: $env{'form.archive_directory'} = [];
12147: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12148: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12149: $path =~ s{/$}{};
12150: my $item;
12151: if ($path ne '') {
12152: $item = "$path/$titles{$i}";
12153: } else {
12154: $item = $titles{$i};
12155: }
12156: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12157: if ($item eq $contents[0]) {
12158: push(@{$env{'form.archive_directory'}},$i);
12159: $env{'form.archive_'.$i} = 'display';
12160: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12161: $displayed{'folder'} = $i;
1.1164 raeburn 12162: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12163: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12164: $env{'form.archive_'.$i} = 'display';
12165: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12166: $displayed{'web'} = $i;
12167: } else {
1.1164 raeburn 12168: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12169: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12170: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12171: push(@{$env{'form.archive_directory'}},$i);
12172: }
12173: $env{'form.archive_'.$i} = 'dependency';
12174: }
12175: $total ++;
12176: }
12177: for (my $i=1; $i<$total; $i++) {
12178: next if ($i == $displayed{'web'});
12179: next if ($i == $displayed{'folder'});
12180: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12181: }
12182: $env{'form.phase'} = 'decompress_cleanup';
12183: $env{'form.archivedelete'} = 1;
12184: $env{'form.archive_count'} = $total-1;
12185: $output .=
12186: &process_extracted_files('coursedocs',$docudom,
12187: $docuname,$destination,
12188: $dir_root,$hiddenelem);
12189: }
1.1055 raeburn 12190: } else {
12191: $warning = &mt('No new items extracted from archive file.');
12192: }
12193: } else {
12194: $output = $display;
12195: $error = &mt('An error occurred during extraction from the archive file.');
12196: }
12197: }
12198: }
12199: }
12200: if ($error) {
12201: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12202: $error.'</p>'."\n";
12203: }
12204: if ($warning) {
12205: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12206: }
12207: return $output;
12208: }
12209:
12210: sub get_extracted {
1.1056 raeburn 12211: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12212: $titles,$wantform) = @_;
1.1055 raeburn 12213: my $count = 0;
12214: my $depth = 0;
12215: my $datatable;
1.1056 raeburn 12216: my @hierarchy;
1.1055 raeburn 12217: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12218: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12219: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12220: foreach my $item (@{$contents}) {
12221: $count ++;
1.1056 raeburn 12222: @{$dirorder->{$count}} = @hierarchy;
12223: $titles->{$count} = $item;
1.1055 raeburn 12224: &archive_hierarchy($depth,$count,$parent,$children);
12225: if ($wantform) {
12226: $datatable .= &archive_row($is_dir->{$item},$item,
12227: $currdir,$depth,$count);
12228: }
12229: if ($is_dir->{$item}) {
12230: $depth ++;
1.1056 raeburn 12231: push(@hierarchy,$count);
12232: $parent->{$depth} = $count;
1.1055 raeburn 12233: $datatable .=
12234: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12235: \$depth,\$count,\@hierarchy,$dirorder,
12236: $children,$parent,$titles,$wantform);
1.1055 raeburn 12237: $depth --;
1.1056 raeburn 12238: pop(@hierarchy);
1.1055 raeburn 12239: }
12240: }
12241: return ($count,$datatable);
12242: }
12243:
12244: sub recurse_extracted_archive {
1.1056 raeburn 12245: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12246: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12247: my $result='';
1.1056 raeburn 12248: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12249: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12250: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12251: return $result;
12252: }
12253: my $dirptr = 16384;
12254: my ($newdirlistref,$newlisterror) =
12255: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12256: if (ref($newdirlistref) eq 'ARRAY') {
12257: foreach my $dir_line (@{$newdirlistref}) {
12258: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12259: unless ($item =~ /^\.+$/) {
12260: $$count ++;
1.1056 raeburn 12261: @{$dirorder->{$$count}} = @{$hierarchy};
12262: $titles->{$$count} = $item;
1.1055 raeburn 12263: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12264:
1.1055 raeburn 12265: my $is_dir;
12266: if ($dirptr&$testdir) {
12267: $is_dir = 1;
12268: }
12269: if ($wantform) {
12270: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12271: }
12272: if ($is_dir) {
12273: $$depth ++;
1.1056 raeburn 12274: push(@{$hierarchy},$$count);
12275: $parent->{$$depth} = $$count;
1.1055 raeburn 12276: $result .=
12277: &recurse_extracted_archive("$currdir/$item",$docudom,
12278: $docuname,$depth,$count,
1.1056 raeburn 12279: $hierarchy,$dirorder,$children,
12280: $parent,$titles,$wantform);
1.1055 raeburn 12281: $$depth --;
1.1056 raeburn 12282: pop(@{$hierarchy});
1.1055 raeburn 12283: }
12284: }
12285: }
12286: }
12287: return $result;
12288: }
12289:
12290: sub archive_hierarchy {
12291: my ($depth,$count,$parent,$children) =@_;
12292: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12293: if (exists($parent->{$depth})) {
12294: $children->{$parent->{$depth}} .= $count.':';
12295: }
12296: }
12297: return;
12298: }
12299:
12300: sub archive_row {
12301: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12302: my ($name) = ($item =~ m{([^/]+)$});
12303: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12304: 'display' => 'Add as file',
1.1055 raeburn 12305: 'dependency' => 'Include as dependency',
12306: 'discard' => 'Discard',
12307: );
12308: if ($is_dir) {
1.1059 raeburn 12309: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12310: }
1.1056 raeburn 12311: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12312: my $offset = 0;
1.1055 raeburn 12313: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12314: $offset ++;
1.1065 raeburn 12315: if ($action ne 'display') {
12316: $offset ++;
12317: }
1.1055 raeburn 12318: $output .= '<td><span class="LC_nobreak">'.
12319: '<label><input type="radio" name="archive_'.$count.
12320: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12321: my $text = $choices{$action};
12322: if ($is_dir) {
12323: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12324: if ($action eq 'display') {
1.1059 raeburn 12325: $text = &mt('Add as folder');
1.1055 raeburn 12326: }
1.1056 raeburn 12327: } else {
12328: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12329:
12330: }
12331: $output .= ' /> '.$choices{$action}.'</label></span>';
12332: if ($action eq 'dependency') {
12333: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12334: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12335: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12336: '<option value=""></option>'."\n".
12337: '</select>'."\n".
12338: '</div>';
1.1059 raeburn 12339: } elsif ($action eq 'display') {
12340: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12341: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12342: '</div>';
1.1055 raeburn 12343: }
1.1056 raeburn 12344: $output .= '</td>';
1.1055 raeburn 12345: }
12346: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12347: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12348: for (my $i=0; $i<$depth; $i++) {
12349: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12350: }
12351: if ($is_dir) {
12352: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12353: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12354: } else {
12355: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12356: }
12357: $output .= ' '.$name.'</td>'."\n".
12358: &end_data_table_row();
12359: return $output;
12360: }
12361:
12362: sub archive_options_form {
1.1065 raeburn 12363: my ($form,$display,$count,$hiddenelem) = @_;
12364: my %lt = &Apache::lonlocal::texthash(
12365: perm => 'Permanently remove archive file?',
12366: hows => 'How should each extracted item be incorporated in the course?',
12367: cont => 'Content actions for all',
12368: addf => 'Add as folder/file',
12369: incd => 'Include as dependency for a displayed file',
12370: disc => 'Discard',
12371: no => 'No',
12372: yes => 'Yes',
12373: save => 'Save',
12374: );
12375: my $output = <<"END";
12376: <form name="$form" method="post" action="">
12377: <p><span class="LC_nobreak">$lt{'perm'}
12378: <label>
12379: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12380: </label>
12381:
12382: <label>
12383: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12384: </span>
12385: </p>
12386: <input type="hidden" name="phase" value="decompress_cleanup" />
12387: <br />$lt{'hows'}
12388: <div class="LC_columnSection">
12389: <fieldset>
12390: <legend>$lt{'cont'}</legend>
12391: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12392: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12393: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12394: </fieldset>
12395: </div>
12396: END
12397: return $output.
1.1055 raeburn 12398: &start_data_table()."\n".
1.1065 raeburn 12399: $display."\n".
1.1055 raeburn 12400: &end_data_table()."\n".
12401: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12402: $hiddenelem.
1.1065 raeburn 12403: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12404: '</form>';
12405: }
12406:
12407: sub archive_javascript {
1.1056 raeburn 12408: my ($startcount,$numitems,$titles,$children) = @_;
12409: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12410: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12411: my $scripttag = <<START;
12412: <script type="text/javascript">
12413: // <![CDATA[
12414:
12415: function checkAll(form,prefix) {
12416: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12417: for (var i=0; i < form.elements.length; i++) {
12418: var id = form.elements[i].id;
12419: if ((id != '') && (id != undefined)) {
12420: if (idstr.test(id)) {
12421: if (form.elements[i].type == 'radio') {
12422: form.elements[i].checked = true;
1.1056 raeburn 12423: var nostart = i-$startcount;
1.1059 raeburn 12424: var offset = nostart%7;
12425: var count = (nostart-offset)/7;
1.1056 raeburn 12426: dependencyCheck(form,count,offset);
1.1055 raeburn 12427: }
12428: }
12429: }
12430: }
12431: }
12432:
12433: function propagateCheck(form,count) {
12434: if (count > 0) {
1.1059 raeburn 12435: var startelement = $startcount + ((count-1) * 7);
12436: for (var j=1; j<6; j++) {
12437: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12438: var item = startelement + j;
12439: if (form.elements[item].type == 'radio') {
12440: if (form.elements[item].checked) {
12441: containerCheck(form,count,j);
12442: break;
12443: }
1.1055 raeburn 12444: }
12445: }
12446: }
12447: }
12448: }
12449:
12450: numitems = $numitems
1.1056 raeburn 12451: var titles = new Array(numitems);
12452: var parents = new Array(numitems);
1.1055 raeburn 12453: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12454: parents[i] = new Array;
1.1055 raeburn 12455: }
1.1059 raeburn 12456: var maintitle = '$maintitle';
1.1055 raeburn 12457:
12458: START
12459:
1.1056 raeburn 12460: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12461: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12462: for (my $i=0; $i<@contents; $i ++) {
12463: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12464: }
12465: }
12466:
1.1056 raeburn 12467: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12468: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12469: }
12470:
1.1055 raeburn 12471: $scripttag .= <<END;
12472:
12473: function containerCheck(form,count,offset) {
12474: if (count > 0) {
1.1056 raeburn 12475: dependencyCheck(form,count,offset);
1.1059 raeburn 12476: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12477: form.elements[item].checked = true;
12478: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12479: if (parents[count].length > 0) {
12480: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12481: containerCheck(form,parents[count][j],offset);
12482: }
12483: }
12484: }
12485: }
12486: }
12487:
12488: function dependencyCheck(form,count,offset) {
12489: if (count > 0) {
1.1059 raeburn 12490: var chosen = (offset+$startcount)+7*(count-1);
12491: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12492: var currtype = form.elements[depitem].type;
12493: if (form.elements[chosen].value == 'dependency') {
12494: document.getElementById('arc_depon_'+count).style.display='block';
12495: form.elements[depitem].options.length = 0;
12496: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 12497: for (var i=1; i<=numitems; i++) {
12498: if (i == count) {
12499: continue;
12500: }
1.1059 raeburn 12501: var startelement = $startcount + (i-1) * 7;
12502: for (var j=1; j<6; j++) {
12503: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12504: var item = startelement + j;
12505: if (form.elements[item].type == 'radio') {
12506: if (form.elements[item].checked) {
12507: if (form.elements[item].value == 'display') {
12508: var n = form.elements[depitem].options.length;
12509: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12510: }
12511: }
12512: }
12513: }
12514: }
12515: }
12516: } else {
12517: document.getElementById('arc_depon_'+count).style.display='none';
12518: form.elements[depitem].options.length = 0;
12519: form.elements[depitem].options[0] = new Option('Select','',true,true);
12520: }
1.1059 raeburn 12521: titleCheck(form,count,offset);
1.1056 raeburn 12522: }
12523: }
12524:
12525: function propagateSelect(form,count,offset) {
12526: if (count > 0) {
1.1065 raeburn 12527: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12528: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12529: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12530: if (parents[count].length > 0) {
12531: for (var j=0; j<parents[count].length; j++) {
12532: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12533: }
12534: }
12535: }
12536: }
12537: }
1.1056 raeburn 12538:
12539: function containerSelect(form,count,offset,picked) {
12540: if (count > 0) {
1.1065 raeburn 12541: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12542: if (form.elements[item].type == 'radio') {
12543: if (form.elements[item].value == 'dependency') {
12544: if (form.elements[item+1].type == 'select-one') {
12545: for (var i=0; i<form.elements[item+1].options.length; i++) {
12546: if (form.elements[item+1].options[i].value == picked) {
12547: form.elements[item+1].selectedIndex = i;
12548: break;
12549: }
12550: }
12551: }
12552: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12553: if (parents[count].length > 0) {
12554: for (var j=0; j<parents[count].length; j++) {
12555: containerSelect(form,parents[count][j],offset,picked);
12556: }
12557: }
12558: }
12559: }
12560: }
12561: }
12562: }
12563:
1.1059 raeburn 12564: function titleCheck(form,count,offset) {
12565: if (count > 0) {
12566: var chosen = (offset+$startcount)+7*(count-1);
12567: var depitem = $startcount + ((count-1) * 7) + 2;
12568: var currtype = form.elements[depitem].type;
12569: if (form.elements[chosen].value == 'display') {
12570: document.getElementById('arc_title_'+count).style.display='block';
12571: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12572: document.getElementById('archive_title_'+count).value=maintitle;
12573: }
12574: } else {
12575: document.getElementById('arc_title_'+count).style.display='none';
12576: if (currtype == 'text') {
12577: document.getElementById('archive_title_'+count).value='';
12578: }
12579: }
12580: }
12581: return;
12582: }
12583:
1.1055 raeburn 12584: // ]]>
12585: </script>
12586: END
12587: return $scripttag;
12588: }
12589:
12590: sub process_extracted_files {
1.1067 raeburn 12591: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12592: my $numitems = $env{'form.archive_count'};
12593: return unless ($numitems);
12594: my @ids=&Apache::lonnet::current_machine_ids();
12595: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12596: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12597: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12598: if (grep(/^\Q$docuhome\E$/,@ids)) {
12599: $prefix = &LONCAPA::propath($docudom,$docuname);
12600: $pathtocheck = "$dir_root/$destination";
12601: $dir = $dir_root;
12602: $ishome = 1;
12603: } else {
12604: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12605: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
12606: $dir = "$dir_root/$docudom/$docuname";
12607: }
12608: my $currdir = "$dir_root/$destination";
12609: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12610: if ($env{'form.folderpath'}) {
12611: my @items = split('&',$env{'form.folderpath'});
12612: $folders{'0'} = $items[-2];
1.1099 raeburn 12613: if ($env{'form.folderpath'} =~ /\:1$/) {
12614: $containers{'0'}='page';
12615: } else {
12616: $containers{'0'}='sequence';
12617: }
1.1055 raeburn 12618: }
12619: my @archdirs = &get_env_multiple('form.archive_directory');
12620: if ($numitems) {
12621: for (my $i=1; $i<=$numitems; $i++) {
12622: my $path = $env{'form.archive_content_'.$i};
12623: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12624: my $item = $1;
12625: $toplevelitems{$item} = $i;
12626: if (grep(/^\Q$i\E$/,@archdirs)) {
12627: $is_dir{$item} = 1;
12628: }
12629: }
12630: }
12631: }
1.1067 raeburn 12632: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12633: if (keys(%toplevelitems) > 0) {
12634: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12635: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12636: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12637: }
1.1066 raeburn 12638: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12639: if ($numitems) {
12640: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 12641: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12642: my $path = $env{'form.archive_content_'.$i};
12643: if ($path =~ /^\Q$pathtocheck\E/) {
12644: if ($env{'form.archive_'.$i} eq 'discard') {
12645: if ($prefix ne '' && $path ne '') {
12646: if (-e $prefix.$path) {
1.1066 raeburn 12647: if ((@archdirs > 0) &&
12648: (grep(/^\Q$i\E$/,@archdirs))) {
12649: $todeletedir{$prefix.$path} = 1;
12650: } else {
12651: $todelete{$prefix.$path} = 1;
12652: }
1.1055 raeburn 12653: }
12654: }
12655: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12656: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12657: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12658: $docstitle = $env{'form.archive_title_'.$i};
12659: if ($docstitle eq '') {
12660: $docstitle = $title;
12661: }
1.1055 raeburn 12662: $outer = 0;
1.1056 raeburn 12663: if (ref($dirorder{$i}) eq 'ARRAY') {
12664: if (@{$dirorder{$i}} > 0) {
12665: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12666: if ($env{'form.archive_'.$item} eq 'display') {
12667: $outer = $item;
12668: last;
12669: }
12670: }
12671: }
12672: }
12673: my ($errtext,$fatal) =
12674: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12675: '/'.$folders{$outer}.'.'.
12676: $containers{$outer});
12677: next if ($fatal);
12678: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12679: if ($context eq 'coursedocs') {
1.1056 raeburn 12680: $mapinner{$i} = time;
1.1055 raeburn 12681: $folders{$i} = 'default_'.$mapinner{$i};
12682: $containers{$i} = 'sequence';
12683: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12684: $folders{$i}.'.'.$containers{$i};
12685: my $newidx = &LONCAPA::map::getresidx();
12686: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12687: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12688: push(@LONCAPA::map::order,$newidx);
12689: my ($outtext,$errtext) =
12690: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12691: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 12692: '.'.$containers{$outer},1,1);
1.1056 raeburn 12693: $newseqid{$i} = $newidx;
1.1067 raeburn 12694: unless ($errtext) {
12695: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
12696: }
1.1055 raeburn 12697: }
12698: } else {
12699: if ($context eq 'coursedocs') {
12700: my $newidx=&LONCAPA::map::getresidx();
12701: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12702: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12703: $title;
12704: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12705: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
12706: }
12707: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12708: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12709: }
12710: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12711: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 12712: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 12713: unless ($ishome) {
12714: my $fetch = "$newdest{$i}/$title";
12715: $fetch =~ s/^\Q$prefix$dir\E//;
12716: $prompttofetch{$fetch} = 1;
12717: }
1.1055 raeburn 12718: }
12719: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12720: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12721: push(@LONCAPA::map::order, $newidx);
12722: my ($outtext,$errtext)=
12723: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12724: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 12725: '.'.$containers{$outer},1,1);
1.1067 raeburn 12726: unless ($errtext) {
12727: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
12728: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
12729: }
12730: }
1.1055 raeburn 12731: }
12732: }
1.1086 raeburn 12733: }
12734: } else {
12735: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12736: }
12737: }
12738: for (my $i=1; $i<=$numitems; $i++) {
12739: next unless ($env{'form.archive_'.$i} eq 'dependency');
12740: my $path = $env{'form.archive_content_'.$i};
12741: if ($path =~ /^\Q$pathtocheck\E/) {
12742: my ($title) = ($path =~ m{/([^/]+)$});
12743: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12744: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12745: if (ref($dirorder{$i}) eq 'ARRAY') {
12746: my ($itemidx,$fullpath,$relpath);
12747: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12748: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12749: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 12750: if ($dirorder{$i}->[$j] eq $container) {
12751: $itemidx = $j;
1.1056 raeburn 12752: }
12753: }
1.1086 raeburn 12754: }
12755: if ($itemidx eq '') {
12756: $itemidx = 0;
12757: }
12758: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12759: if ($mapinner{$referrer{$i}}) {
12760: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12761: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12762: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12763: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12764: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12765: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12766: if (!-e $fullpath) {
12767: mkdir($fullpath,0755);
1.1056 raeburn 12768: }
12769: }
1.1086 raeburn 12770: } else {
12771: last;
1.1056 raeburn 12772: }
1.1086 raeburn 12773: }
12774: }
12775: } elsif ($newdest{$referrer{$i}}) {
12776: $fullpath = $newdest{$referrer{$i}};
12777: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12778: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12779: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12780: last;
12781: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12782: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12783: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12784: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12785: if (!-e $fullpath) {
12786: mkdir($fullpath,0755);
1.1056 raeburn 12787: }
12788: }
1.1086 raeburn 12789: } else {
12790: last;
1.1056 raeburn 12791: }
1.1055 raeburn 12792: }
12793: }
1.1086 raeburn 12794: if ($fullpath ne '') {
12795: if (-e "$prefix$path") {
12796: system("mv $prefix$path $fullpath/$title");
12797: }
12798: if (-e "$fullpath/$title") {
12799: my $showpath;
12800: if ($relpath ne '') {
12801: $showpath = "$relpath/$title";
12802: } else {
12803: $showpath = "/$title";
12804: }
12805: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12806: }
12807: unless ($ishome) {
12808: my $fetch = "$fullpath/$title";
12809: $fetch =~ s/^\Q$prefix$dir\E//;
12810: $prompttofetch{$fetch} = 1;
12811: }
12812: }
1.1055 raeburn 12813: }
1.1086 raeburn 12814: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12815: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12816: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12817: }
12818: } else {
12819: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12820: }
12821: }
12822: if (keys(%todelete)) {
12823: foreach my $key (keys(%todelete)) {
12824: unlink($key);
1.1066 raeburn 12825: }
12826: }
12827: if (keys(%todeletedir)) {
12828: foreach my $key (keys(%todeletedir)) {
12829: rmdir($key);
12830: }
12831: }
12832: foreach my $dir (sort(keys(%is_dir))) {
12833: if (($pathtocheck ne '') && ($dir ne '')) {
12834: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12835: }
12836: }
1.1067 raeburn 12837: if ($result ne '') {
12838: $output .= '<ul>'."\n".
12839: $result."\n".
12840: '</ul>';
12841: }
12842: unless ($ishome) {
12843: my $replicationfail;
12844: foreach my $item (keys(%prompttofetch)) {
12845: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12846: unless ($fetchresult eq 'ok') {
12847: $replicationfail .= '<li>'.$item.'</li>'."\n";
12848: }
12849: }
12850: if ($replicationfail) {
12851: $output .= '<p class="LC_error">'.
12852: &mt('Course home server failed to retrieve:').'<ul>'.
12853: $replicationfail.
12854: '</ul></p>';
12855: }
12856: }
1.1055 raeburn 12857: } else {
12858: $warning = &mt('No items found in archive.');
12859: }
12860: if ($error) {
12861: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12862: $error.'</p>'."\n";
12863: }
12864: if ($warning) {
12865: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12866: }
12867: return $output;
12868: }
12869:
1.1066 raeburn 12870: sub cleanup_empty_dirs {
12871: my ($path) = @_;
12872: if (($path ne '') && (-d $path)) {
12873: if (opendir(my $dirh,$path)) {
12874: my @dircontents = grep(!/^\./,readdir($dirh));
12875: my $numitems = 0;
12876: foreach my $item (@dircontents) {
12877: if (-d "$path/$item") {
1.1111 raeburn 12878: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12879: if (-e "$path/$item") {
12880: $numitems ++;
12881: }
12882: } else {
12883: $numitems ++;
12884: }
12885: }
12886: if ($numitems == 0) {
12887: rmdir($path);
12888: }
12889: closedir($dirh);
12890: }
12891: }
12892: return;
12893: }
12894:
1.41 ng 12895: =pod
1.45 matthew 12896:
1.1162 raeburn 12897: =item * &get_folder_hierarchy()
1.1068 raeburn 12898:
12899: Provides hierarchy of names of folders/sub-folders containing the current
12900: item,
12901:
12902: Inputs: 3
12903: - $navmap - navmaps object
12904:
12905: - $map - url for map (either the trigger itself, or map containing
12906: the resource, which is the trigger).
12907:
12908: - $showitem - 1 => show title for map itself; 0 => do not show.
12909:
12910: Outputs: 1 @pathitems - array of folder/subfolder names.
12911:
12912: =cut
12913:
12914: sub get_folder_hierarchy {
12915: my ($navmap,$map,$showitem) = @_;
12916: my @pathitems;
12917: if (ref($navmap)) {
12918: my $mapres = $navmap->getResourceByUrl($map);
12919: if (ref($mapres)) {
12920: my $pcslist = $mapres->map_hierarchy();
12921: if ($pcslist ne '') {
12922: my @pcs = split(/,/,$pcslist);
12923: foreach my $pc (@pcs) {
12924: if ($pc == 1) {
1.1129 raeburn 12925: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12926: } else {
12927: my $res = $navmap->getByMapPc($pc);
12928: if (ref($res)) {
12929: my $title = $res->compTitle();
12930: $title =~ s/\W+/_/g;
12931: if ($title ne '') {
12932: push(@pathitems,$title);
12933: }
12934: }
12935: }
12936: }
12937: }
1.1071 raeburn 12938: if ($showitem) {
12939: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 12940: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12941: } else {
12942: my $maptitle = $mapres->compTitle();
12943: $maptitle =~ s/\W+/_/g;
12944: if ($maptitle ne '') {
12945: push(@pathitems,$maptitle);
12946: }
1.1068 raeburn 12947: }
12948: }
12949: }
12950: }
12951: return @pathitems;
12952: }
12953:
12954: =pod
12955:
1.1015 raeburn 12956: =item * &get_turnedin_filepath()
12957:
12958: Determines path in a user's portfolio file for storage of files uploaded
12959: to a specific essayresponse or dropbox item.
12960:
12961: Inputs: 3 required + 1 optional.
12962: $symb is symb for resource, $uname and $udom are for current user (required).
12963: $caller is optional (can be "submission", if routine is called when storing
12964: an upoaded file when "Submit Answer" button was pressed).
12965:
12966: Returns array containing $path and $multiresp.
12967: $path is path in portfolio. $multiresp is 1 if this resource contains more
12968: than one file upload item. Callers of routine should append partid as a
12969: subdirectory to $path in cases where $multiresp is 1.
12970:
12971: Called by: homework/essayresponse.pm and homework/structuretags.pm
12972:
12973: =cut
12974:
12975: sub get_turnedin_filepath {
12976: my ($symb,$uname,$udom,$caller) = @_;
12977: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12978: my $turnindir;
12979: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12980: $turnindir = $userhash{'turnindir'};
12981: my ($path,$multiresp);
12982: if ($turnindir eq '') {
12983: if ($caller eq 'submission') {
12984: $turnindir = &mt('turned in');
12985: $turnindir =~ s/\W+/_/g;
12986: my %newhash = (
12987: 'turnindir' => $turnindir,
12988: );
12989: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12990: }
12991: }
12992: if ($turnindir ne '') {
12993: $path = '/'.$turnindir.'/';
12994: my ($multipart,$turnin,@pathitems);
12995: my $navmap = Apache::lonnavmaps::navmap->new();
12996: if (defined($navmap)) {
12997: my $mapres = $navmap->getResourceByUrl($map);
12998: if (ref($mapres)) {
12999: my $pcslist = $mapres->map_hierarchy();
13000: if ($pcslist ne '') {
13001: foreach my $pc (split(/,/,$pcslist)) {
13002: my $res = $navmap->getByMapPc($pc);
13003: if (ref($res)) {
13004: my $title = $res->compTitle();
13005: $title =~ s/\W+/_/g;
13006: if ($title ne '') {
1.1149 raeburn 13007: if (($pc > 1) && (length($title) > 12)) {
13008: $title = substr($title,0,12);
13009: }
1.1015 raeburn 13010: push(@pathitems,$title);
13011: }
13012: }
13013: }
13014: }
13015: my $maptitle = $mapres->compTitle();
13016: $maptitle =~ s/\W+/_/g;
13017: if ($maptitle ne '') {
1.1149 raeburn 13018: if (length($maptitle) > 12) {
13019: $maptitle = substr($maptitle,0,12);
13020: }
1.1015 raeburn 13021: push(@pathitems,$maptitle);
13022: }
13023: unless ($env{'request.state'} eq 'construct') {
13024: my $res = $navmap->getBySymb($symb);
13025: if (ref($res)) {
13026: my $partlist = $res->parts();
13027: my $totaluploads = 0;
13028: if (ref($partlist) eq 'ARRAY') {
13029: foreach my $part (@{$partlist}) {
13030: my @types = $res->responseType($part);
13031: my @ids = $res->responseIds($part);
13032: for (my $i=0; $i < scalar(@ids); $i++) {
13033: if ($types[$i] eq 'essay') {
13034: my $partid = $part.'_'.$ids[$i];
13035: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13036: $totaluploads ++;
13037: }
13038: }
13039: }
13040: }
13041: if ($totaluploads > 1) {
13042: $multiresp = 1;
13043: }
13044: }
13045: }
13046: }
13047: } else {
13048: return;
13049: }
13050: } else {
13051: return;
13052: }
13053: my $restitle=&Apache::lonnet::gettitle($symb);
13054: $restitle =~ s/\W+/_/g;
13055: if ($restitle eq '') {
13056: $restitle = ($resurl =~ m{/[^/]+$});
13057: if ($restitle eq '') {
13058: $restitle = time;
13059: }
13060: }
1.1149 raeburn 13061: if (length($restitle) > 12) {
13062: $restitle = substr($restitle,0,12);
13063: }
1.1015 raeburn 13064: push(@pathitems,$restitle);
13065: $path .= join('/',@pathitems);
13066: }
13067: return ($path,$multiresp);
13068: }
13069:
13070: =pod
13071:
1.464 albertel 13072: =back
1.41 ng 13073:
1.112 bowersj2 13074: =head1 CSV Upload/Handling functions
1.38 albertel 13075:
1.41 ng 13076: =over 4
13077:
1.648 raeburn 13078: =item * &upfile_store($r)
1.41 ng 13079:
13080: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13081: needs $env{'form.upfile'}
1.41 ng 13082: returns $datatoken to be put into hidden field
13083:
13084: =cut
1.31 albertel 13085:
13086: sub upfile_store {
13087: my $r=shift;
1.258 albertel 13088: $env{'form.upfile'}=~s/\r/\n/gs;
13089: $env{'form.upfile'}=~s/\f/\n/gs;
13090: $env{'form.upfile'}=~s/\n+/\n/gs;
13091: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13092:
1.258 albertel 13093: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
13094: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 13095: {
1.158 raeburn 13096: my $datafile = $r->dir_config('lonDaemons').
13097: '/tmp/'.$datatoken.'.tmp';
13098: if ( open(my $fh,">$datafile") ) {
1.258 albertel 13099: print $fh $env{'form.upfile'};
1.158 raeburn 13100: close($fh);
13101: }
1.31 albertel 13102: }
13103: return $datatoken;
13104: }
13105:
1.56 matthew 13106: =pod
13107:
1.648 raeburn 13108: =item * &load_tmp_file($r)
1.41 ng 13109:
13110: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 13111: needs $env{'form.datatoken'},
13112: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13113:
13114: =cut
1.31 albertel 13115:
13116: sub load_tmp_file {
13117: my $r=shift;
13118: my @studentdata=();
13119: {
1.158 raeburn 13120: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 13121: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 13122: if ( open(my $fh,"<$studentfile") ) {
13123: @studentdata=<$fh>;
13124: close($fh);
13125: }
1.31 albertel 13126: }
1.258 albertel 13127: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13128: }
13129:
1.56 matthew 13130: =pod
13131:
1.648 raeburn 13132: =item * &upfile_record_sep()
1.41 ng 13133:
13134: Separate uploaded file into records
13135: returns array of records,
1.258 albertel 13136: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13137:
13138: =cut
1.31 albertel 13139:
13140: sub upfile_record_sep {
1.258 albertel 13141: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13142: } else {
1.248 albertel 13143: my @records;
1.258 albertel 13144: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13145: if ($line=~/^\s*$/) { next; }
13146: push(@records,$line);
13147: }
13148: return @records;
1.31 albertel 13149: }
13150: }
13151:
1.56 matthew 13152: =pod
13153:
1.648 raeburn 13154: =item * &record_sep($record)
1.41 ng 13155:
1.258 albertel 13156: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13157:
13158: =cut
13159:
1.263 www 13160: sub takeleft {
13161: my $index=shift;
13162: return substr('0000'.$index,-4,4);
13163: }
13164:
1.31 albertel 13165: sub record_sep {
13166: my $record=shift;
13167: my %components=();
1.258 albertel 13168: if ($env{'form.upfiletype'} eq 'xml') {
13169: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13170: my $i=0;
1.356 albertel 13171: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13172: $field=~s/^(\"|\')//;
13173: $field=~s/(\"|\')$//;
1.263 www 13174: $components{&takeleft($i)}=$field;
1.31 albertel 13175: $i++;
13176: }
1.258 albertel 13177: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13178: my $i=0;
1.356 albertel 13179: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13180: $field=~s/^(\"|\')//;
13181: $field=~s/(\"|\')$//;
1.263 www 13182: $components{&takeleft($i)}=$field;
1.31 albertel 13183: $i++;
13184: }
13185: } else {
1.561 www 13186: my $separator=',';
1.480 banghart 13187: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13188: $separator=';';
1.480 banghart 13189: }
1.31 albertel 13190: my $i=0;
1.561 www 13191: # the character we are looking for to indicate the end of a quote or a record
13192: my $looking_for=$separator;
13193: # do not add the characters to the fields
13194: my $ignore=0;
13195: # we just encountered a separator (or the beginning of the record)
13196: my $just_found_separator=1;
13197: # store the field we are working on here
13198: my $field='';
13199: # work our way through all characters in record
13200: foreach my $character ($record=~/(.)/g) {
13201: if ($character eq $looking_for) {
13202: if ($character ne $separator) {
13203: # Found the end of a quote, again looking for separator
13204: $looking_for=$separator;
13205: $ignore=1;
13206: } else {
13207: # Found a separator, store away what we got
13208: $components{&takeleft($i)}=$field;
13209: $i++;
13210: $just_found_separator=1;
13211: $ignore=0;
13212: $field='';
13213: }
13214: next;
13215: }
13216: # single or double quotation marks after a separator indicate beginning of a quote
13217: # we are now looking for the end of the quote and need to ignore separators
13218: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13219: $looking_for=$character;
13220: next;
13221: }
13222: # ignore would be true after we reached the end of a quote
13223: if ($ignore) { next; }
13224: if (($just_found_separator) && ($character=~/\s/)) { next; }
13225: $field.=$character;
13226: $just_found_separator=0;
1.31 albertel 13227: }
1.561 www 13228: # catch the very last entry, since we never encountered the separator
13229: $components{&takeleft($i)}=$field;
1.31 albertel 13230: }
13231: return %components;
13232: }
13233:
1.144 matthew 13234: ######################################################
13235: ######################################################
13236:
1.56 matthew 13237: =pod
13238:
1.648 raeburn 13239: =item * &upfile_select_html()
1.41 ng 13240:
1.144 matthew 13241: Return HTML code to select a file from the users machine and specify
13242: the file type.
1.41 ng 13243:
13244: =cut
13245:
1.144 matthew 13246: ######################################################
13247: ######################################################
1.31 albertel 13248: sub upfile_select_html {
1.144 matthew 13249: my %Types = (
13250: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13251: semisv => &mt('Semicolon separated values'),
1.144 matthew 13252: space => &mt('Space separated'),
13253: tab => &mt('Tabulator separated'),
13254: # xml => &mt('HTML/XML'),
13255: );
13256: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13257: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13258: foreach my $type (sort(keys(%Types))) {
13259: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13260: }
13261: $Str .= "</select>\n";
13262: return $Str;
1.31 albertel 13263: }
13264:
1.301 albertel 13265: sub get_samples {
13266: my ($records,$toget) = @_;
13267: my @samples=({});
13268: my $got=0;
13269: foreach my $rec (@$records) {
13270: my %temp = &record_sep($rec);
13271: if (! grep(/\S/, values(%temp))) { next; }
13272: if (%temp) {
13273: $samples[$got]=\%temp;
13274: $got++;
13275: if ($got == $toget) { last; }
13276: }
13277: }
13278: return \@samples;
13279: }
13280:
1.144 matthew 13281: ######################################################
13282: ######################################################
13283:
1.56 matthew 13284: =pod
13285:
1.648 raeburn 13286: =item * &csv_print_samples($r,$records)
1.41 ng 13287:
13288: Prints a table of sample values from each column uploaded $r is an
13289: Apache Request ref, $records is an arrayref from
13290: &Apache::loncommon::upfile_record_sep
13291:
13292: =cut
13293:
1.144 matthew 13294: ######################################################
13295: ######################################################
1.31 albertel 13296: sub csv_print_samples {
13297: my ($r,$records) = @_;
1.662 bisitz 13298: my $samples = &get_samples($records,5);
1.301 albertel 13299:
1.594 raeburn 13300: $r->print(&mt('Samples').'<br />'.&start_data_table().
13301: &start_data_table_header_row());
1.356 albertel 13302: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13303: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13304: $r->print(&end_data_table_header_row());
1.301 albertel 13305: foreach my $hash (@$samples) {
1.594 raeburn 13306: $r->print(&start_data_table_row());
1.356 albertel 13307: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13308: $r->print('<td>');
1.356 albertel 13309: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13310: $r->print('</td>');
13311: }
1.594 raeburn 13312: $r->print(&end_data_table_row());
1.31 albertel 13313: }
1.594 raeburn 13314: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13315: }
13316:
1.144 matthew 13317: ######################################################
13318: ######################################################
13319:
1.56 matthew 13320: =pod
13321:
1.648 raeburn 13322: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13323:
13324: Prints a table to create associations between values and table columns.
1.144 matthew 13325:
1.41 ng 13326: $r is an Apache Request ref,
13327: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13328: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13329:
13330: =cut
13331:
1.144 matthew 13332: ######################################################
13333: ######################################################
1.31 albertel 13334: sub csv_print_select_table {
13335: my ($r,$records,$d) = @_;
1.301 albertel 13336: my $i=0;
13337: my $samples = &get_samples($records,1);
1.144 matthew 13338: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13339: &start_data_table().&start_data_table_header_row().
1.144 matthew 13340: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13341: '<th>'.&mt('Column').'</th>'.
13342: &end_data_table_header_row()."\n");
1.356 albertel 13343: foreach my $array_ref (@$d) {
13344: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13345: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13346:
1.875 bisitz 13347: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13348: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13349: $r->print('<option value="none"></option>');
1.356 albertel 13350: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13351: $r->print('<option value="'.$sample.'"'.
13352: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13353: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13354: }
1.594 raeburn 13355: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13356: $i++;
13357: }
1.594 raeburn 13358: $r->print(&end_data_table());
1.31 albertel 13359: $i--;
13360: return $i;
13361: }
1.56 matthew 13362:
1.144 matthew 13363: ######################################################
13364: ######################################################
13365:
1.56 matthew 13366: =pod
1.31 albertel 13367:
1.648 raeburn 13368: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13369:
13370: Prints a table of sample values from the upload and can make associate samples to internal names.
13371:
13372: $r is an Apache Request ref,
13373: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13374: $d is an array of 2 element arrays (internal name, displayed name)
13375:
13376: =cut
13377:
1.144 matthew 13378: ######################################################
13379: ######################################################
1.31 albertel 13380: sub csv_samples_select_table {
13381: my ($r,$records,$d) = @_;
13382: my $i=0;
1.144 matthew 13383: #
1.662 bisitz 13384: my $max_samples = 5;
13385: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13386: $r->print(&start_data_table().
13387: &start_data_table_header_row().'<th>'.
13388: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13389: &end_data_table_header_row());
1.301 albertel 13390:
13391: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13392: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13393: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13394: foreach my $option (@$d) {
13395: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13396: $r->print('<option value="'.$value.'"'.
1.253 albertel 13397: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13398: $display.'</option>');
1.31 albertel 13399: }
13400: $r->print('</select></td><td>');
1.662 bisitz 13401: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13402: if (defined($samples->[$line]{$key})) {
13403: $r->print($samples->[$line]{$key}."<br />\n");
13404: }
13405: }
1.594 raeburn 13406: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13407: $i++;
13408: }
1.594 raeburn 13409: $r->print(&end_data_table());
1.31 albertel 13410: $i--;
13411: return($i);
1.115 matthew 13412: }
13413:
1.144 matthew 13414: ######################################################
13415: ######################################################
13416:
1.115 matthew 13417: =pod
13418:
1.648 raeburn 13419: =item * &clean_excel_name($name)
1.115 matthew 13420:
13421: Returns a replacement for $name which does not contain any illegal characters.
13422:
13423: =cut
13424:
1.144 matthew 13425: ######################################################
13426: ######################################################
1.115 matthew 13427: sub clean_excel_name {
13428: my ($name) = @_;
13429: $name =~ s/[:\*\?\/\\]//g;
13430: if (length($name) > 31) {
13431: $name = substr($name,0,31);
13432: }
13433: return $name;
1.25 albertel 13434: }
1.84 albertel 13435:
1.85 albertel 13436: =pod
13437:
1.648 raeburn 13438: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13439:
13440: Returns either 1 or undef
13441:
13442: 1 if the part is to be hidden, undef if it is to be shown
13443:
13444: Arguments are:
13445:
13446: $id the id of the part to be checked
13447: $symb, optional the symb of the resource to check
13448: $udom, optional the domain of the user to check for
13449: $uname, optional the username of the user to check for
13450:
13451: =cut
1.84 albertel 13452:
13453: sub check_if_partid_hidden {
13454: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13455: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13456: $symb,$udom,$uname);
1.141 albertel 13457: my $truth=1;
13458: #if the string starts with !, then the list is the list to show not hide
13459: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13460: my @hiddenlist=split(/,/,$hiddenparts);
13461: foreach my $checkid (@hiddenlist) {
1.141 albertel 13462: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13463: }
1.141 albertel 13464: return !$truth;
1.84 albertel 13465: }
1.127 matthew 13466:
1.138 matthew 13467:
13468: ############################################################
13469: ############################################################
13470:
13471: =pod
13472:
1.157 matthew 13473: =back
13474:
1.138 matthew 13475: =head1 cgi-bin script and graphing routines
13476:
1.157 matthew 13477: =over 4
13478:
1.648 raeburn 13479: =item * &get_cgi_id()
1.138 matthew 13480:
13481: Inputs: none
13482:
13483: Returns an id which can be used to pass environment variables
13484: to various cgi-bin scripts. These environment variables will
13485: be removed from the users environment after a given time by
13486: the routine &Apache::lonnet::transfer_profile_to_env.
13487:
13488: =cut
13489:
13490: ############################################################
13491: ############################################################
1.152 albertel 13492: my $uniq=0;
1.136 matthew 13493: sub get_cgi_id {
1.154 albertel 13494: $uniq=($uniq+1)%100000;
1.280 albertel 13495: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13496: }
13497:
1.127 matthew 13498: ############################################################
13499: ############################################################
13500:
13501: =pod
13502:
1.648 raeburn 13503: =item * &DrawBarGraph()
1.127 matthew 13504:
1.138 matthew 13505: Facilitates the plotting of data in a (stacked) bar 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: The bars on the plot are labeled '1','2',...,'n'.
13509:
13510: Inputs:
13511:
13512: =over 4
13513:
13514: =item $Title: string, the title of the plot
13515:
13516: =item $xlabel: string, text describing the X-axis of the plot
13517:
13518: =item $ylabel: string, text describing the Y-axis of the plot
13519:
13520: =item $Max: scalar, the maximum Y value to use in the plot
13521: If $Max is < any data point, the graph will not be rendered.
13522:
1.140 matthew 13523: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13524: they are plotted. If undefined, default values will be used.
13525:
1.178 matthew 13526: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13527:
1.138 matthew 13528: =item @Values: An array of array references. Each array reference holds data
13529: to be plotted in a stacked bar chart.
13530:
1.239 matthew 13531: =item If the final element of @Values is a hash reference the key/value
13532: pairs will be added to the graph definition.
13533:
1.138 matthew 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.127 matthew 13541: =cut
13542:
13543: ############################################################
13544: ############################################################
1.134 matthew 13545: sub DrawBarGraph {
1.178 matthew 13546: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13547: #
13548: if (! defined($colors)) {
13549: $colors = ['#33ff00',
13550: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13551: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13552: ];
13553: }
1.228 matthew 13554: my $extra_settings = {};
13555: if (ref($Values[-1]) eq 'HASH') {
13556: $extra_settings = pop(@Values);
13557: }
1.127 matthew 13558: #
1.136 matthew 13559: my $identifier = &get_cgi_id();
13560: my $id = 'cgi.'.$identifier;
1.129 matthew 13561: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13562: return '';
13563: }
1.225 matthew 13564: #
13565: my @Labels;
13566: if (defined($labels)) {
13567: @Labels = @$labels;
13568: } else {
13569: for (my $i=0;$i<@{$Values[0]};$i++) {
13570: push (@Labels,$i+1);
13571: }
13572: }
13573: #
1.129 matthew 13574: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13575: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13576: my %ValuesHash;
13577: my $NumSets=1;
13578: foreach my $array (@Values) {
13579: next if (! ref($array));
1.136 matthew 13580: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13581: join(',',@$array);
1.129 matthew 13582: }
1.127 matthew 13583: #
1.136 matthew 13584: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13585: if ($NumBars < 3) {
13586: $width = 120+$NumBars*32;
1.220 matthew 13587: $xskip = 1;
1.225 matthew 13588: $bar_width = 30;
13589: } elsif ($NumBars < 5) {
13590: $width = 120+$NumBars*20;
13591: $xskip = 1;
13592: $bar_width = 20;
1.220 matthew 13593: } elsif ($NumBars < 10) {
1.136 matthew 13594: $width = 120+$NumBars*15;
13595: $xskip = 1;
13596: $bar_width = 15;
13597: } elsif ($NumBars <= 25) {
13598: $width = 120+$NumBars*11;
13599: $xskip = 5;
13600: $bar_width = 8;
13601: } elsif ($NumBars <= 50) {
13602: $width = 120+$NumBars*8;
13603: $xskip = 5;
13604: $bar_width = 4;
13605: } else {
13606: $width = 120+$NumBars*8;
13607: $xskip = 5;
13608: $bar_width = 4;
13609: }
13610: #
1.137 matthew 13611: $Max = 1 if ($Max < 1);
13612: if ( int($Max) < $Max ) {
13613: $Max++;
13614: $Max = int($Max);
13615: }
1.127 matthew 13616: $Title = '' if (! defined($Title));
13617: $xlabel = '' if (! defined($xlabel));
13618: $ylabel = '' if (! defined($ylabel));
1.369 www 13619: $ValuesHash{$id.'.title'} = &escape($Title);
13620: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13621: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13622: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13623: $ValuesHash{$id.'.NumBars'} = $NumBars;
13624: $ValuesHash{$id.'.NumSets'} = $NumSets;
13625: $ValuesHash{$id.'.PlotType'} = 'bar';
13626: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13627: $ValuesHash{$id.'.height'} = $height;
13628: $ValuesHash{$id.'.width'} = $width;
13629: $ValuesHash{$id.'.xskip'} = $xskip;
13630: $ValuesHash{$id.'.bar_width'} = $bar_width;
13631: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13632: #
1.228 matthew 13633: # Deal with other parameters
13634: while (my ($key,$value) = each(%$extra_settings)) {
13635: $ValuesHash{$id.'.'.$key} = $value;
13636: }
13637: #
1.646 raeburn 13638: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13639: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13640: }
13641:
13642: ############################################################
13643: ############################################################
13644:
13645: =pod
13646:
1.648 raeburn 13647: =item * &DrawXYGraph()
1.137 matthew 13648:
1.138 matthew 13649: Facilitates the plotting of data in an XY graph.
13650: Puts plot definition data into the users environment in order for
13651: graph.png to plot it. Returns an <img> tag for the plot.
13652:
13653: Inputs:
13654:
13655: =over 4
13656:
13657: =item $Title: string, the title of the plot
13658:
13659: =item $xlabel: string, text describing the X-axis of the plot
13660:
13661: =item $ylabel: string, text describing the Y-axis of the plot
13662:
13663: =item $Max: scalar, the maximum Y value to use in the plot
13664: If $Max is < any data point, the graph will not be rendered.
13665:
13666: =item $colors: Array ref containing the hex color codes for the data to be
13667: plotted in. If undefined, default values will be used.
13668:
13669: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13670:
13671: =item $Ydata: Array ref containing Array refs.
1.185 www 13672: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13673:
13674: =item %Values: hash indicating or overriding any default values which are
13675: passed to graph.png.
13676: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13677:
13678: =back
13679:
13680: Returns:
13681:
13682: An <img> tag which references graph.png and the appropriate identifying
13683: information for the plot.
13684:
1.137 matthew 13685: =cut
13686:
13687: ############################################################
13688: ############################################################
13689: sub DrawXYGraph {
13690: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13691: #
13692: # Create the identifier for the graph
13693: my $identifier = &get_cgi_id();
13694: my $id = 'cgi.'.$identifier;
13695: #
13696: $Title = '' if (! defined($Title));
13697: $xlabel = '' if (! defined($xlabel));
13698: $ylabel = '' if (! defined($ylabel));
13699: my %ValuesHash =
13700: (
1.369 www 13701: $id.'.title' => &escape($Title),
13702: $id.'.xlabel' => &escape($xlabel),
13703: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13704: $id.'.y_max_value'=> $Max,
13705: $id.'.labels' => join(',',@$Xlabels),
13706: $id.'.PlotType' => 'XY',
13707: );
13708: #
13709: if (defined($colors) && ref($colors) eq 'ARRAY') {
13710: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13711: }
13712: #
13713: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13714: return '';
13715: }
13716: my $NumSets=1;
1.138 matthew 13717: foreach my $array (@{$Ydata}){
1.137 matthew 13718: next if (! ref($array));
13719: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13720: }
1.138 matthew 13721: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13722: #
13723: # Deal with other parameters
13724: while (my ($key,$value) = each(%Values)) {
13725: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13726: }
13727: #
1.646 raeburn 13728: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13729: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13730: }
13731:
13732: ############################################################
13733: ############################################################
13734:
13735: =pod
13736:
1.648 raeburn 13737: =item * &DrawXYYGraph()
1.138 matthew 13738:
13739: Facilitates the plotting of data in an XY graph with two Y axes.
13740: Puts plot definition data into the users environment in order for
13741: graph.png to plot it. Returns an <img> tag for the plot.
13742:
13743: Inputs:
13744:
13745: =over 4
13746:
13747: =item $Title: string, the title of the plot
13748:
13749: =item $xlabel: string, text describing the X-axis of the plot
13750:
13751: =item $ylabel: string, text describing the Y-axis of the plot
13752:
13753: =item $colors: Array ref containing the hex color codes for the data to be
13754: plotted in. If undefined, default values will be used.
13755:
13756: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13757:
13758: =item $Ydata1: The first data set
13759:
13760: =item $Min1: The minimum value of the left Y-axis
13761:
13762: =item $Max1: The maximum value of the left Y-axis
13763:
13764: =item $Ydata2: The second data set
13765:
13766: =item $Min2: The minimum value of the right Y-axis
13767:
13768: =item $Max2: The maximum value of the left Y-axis
13769:
13770: =item %Values: hash indicating or overriding any default values which are
13771: passed to graph.png.
13772: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13773:
13774: =back
13775:
13776: Returns:
13777:
13778: An <img> tag which references graph.png and the appropriate identifying
13779: information for the plot.
1.136 matthew 13780:
13781: =cut
13782:
13783: ############################################################
13784: ############################################################
1.137 matthew 13785: sub DrawXYYGraph {
13786: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13787: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13788: #
13789: # Create the identifier for the graph
13790: my $identifier = &get_cgi_id();
13791: my $id = 'cgi.'.$identifier;
13792: #
13793: $Title = '' if (! defined($Title));
13794: $xlabel = '' if (! defined($xlabel));
13795: $ylabel = '' if (! defined($ylabel));
13796: my %ValuesHash =
13797: (
1.369 www 13798: $id.'.title' => &escape($Title),
13799: $id.'.xlabel' => &escape($xlabel),
13800: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13801: $id.'.labels' => join(',',@$Xlabels),
13802: $id.'.PlotType' => 'XY',
13803: $id.'.NumSets' => 2,
1.137 matthew 13804: $id.'.two_axes' => 1,
13805: $id.'.y1_max_value' => $Max1,
13806: $id.'.y1_min_value' => $Min1,
13807: $id.'.y2_max_value' => $Max2,
13808: $id.'.y2_min_value' => $Min2,
1.136 matthew 13809: );
13810: #
1.137 matthew 13811: if (defined($colors) && ref($colors) eq 'ARRAY') {
13812: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13813: }
13814: #
13815: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13816: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13817: return '';
13818: }
13819: my $NumSets=1;
1.137 matthew 13820: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13821: next if (! ref($array));
13822: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13823: }
13824: #
13825: # Deal with other parameters
13826: while (my ($key,$value) = each(%Values)) {
13827: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13828: }
13829: #
1.646 raeburn 13830: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13831: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13832: }
13833:
13834: ############################################################
13835: ############################################################
13836:
13837: =pod
13838:
1.157 matthew 13839: =back
13840:
1.139 matthew 13841: =head1 Statistics helper routines?
13842:
13843: Bad place for them but what the hell.
13844:
1.157 matthew 13845: =over 4
13846:
1.648 raeburn 13847: =item * &chartlink()
1.139 matthew 13848:
13849: Returns a link to the chart for a specific student.
13850:
13851: Inputs:
13852:
13853: =over 4
13854:
13855: =item $linktext: The text of the link
13856:
13857: =item $sname: The students username
13858:
13859: =item $sdomain: The students domain
13860:
13861: =back
13862:
1.157 matthew 13863: =back
13864:
1.139 matthew 13865: =cut
13866:
13867: ############################################################
13868: ############################################################
13869: sub chartlink {
13870: my ($linktext, $sname, $sdomain) = @_;
13871: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13872: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13873: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13874: '">'.$linktext.'</a>';
1.153 matthew 13875: }
13876:
13877: #######################################################
13878: #######################################################
13879:
13880: =pod
13881:
13882: =head1 Course Environment Routines
1.157 matthew 13883:
13884: =over 4
1.153 matthew 13885:
1.648 raeburn 13886: =item * &restore_course_settings()
1.153 matthew 13887:
1.648 raeburn 13888: =item * &store_course_settings()
1.153 matthew 13889:
13890: Restores/Store indicated form parameters from the course environment.
13891: Will not overwrite existing values of the form parameters.
13892:
13893: Inputs:
13894: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13895:
13896: a hash ref describing the data to be stored. For example:
13897:
13898: %Save_Parameters = ('Status' => 'scalar',
13899: 'chartoutputmode' => 'scalar',
13900: 'chartoutputdata' => 'scalar',
13901: 'Section' => 'array',
1.373 raeburn 13902: 'Group' => 'array',
1.153 matthew 13903: 'StudentData' => 'array',
13904: 'Maps' => 'array');
13905:
13906: Returns: both routines return nothing
13907:
1.631 raeburn 13908: =back
13909:
1.153 matthew 13910: =cut
13911:
13912: #######################################################
13913: #######################################################
13914: sub store_course_settings {
1.496 albertel 13915: return &store_settings($env{'request.course.id'},@_);
13916: }
13917:
13918: sub store_settings {
1.153 matthew 13919: # save to the environment
13920: # appenv the same items, just to be safe
1.300 albertel 13921: my $udom = $env{'user.domain'};
13922: my $uname = $env{'user.name'};
1.496 albertel 13923: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13924: my %SaveHash;
13925: my %AppHash;
13926: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13927: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13928: my $envname = 'environment.'.$basename;
1.258 albertel 13929: if (exists($env{'form.'.$setting})) {
1.153 matthew 13930: # Save this value away
13931: if ($type eq 'scalar' &&
1.258 albertel 13932: (! exists($env{$envname}) ||
13933: $env{$envname} ne $env{'form.'.$setting})) {
13934: $SaveHash{$basename} = $env{'form.'.$setting};
13935: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13936: } elsif ($type eq 'array') {
13937: my $stored_form;
1.258 albertel 13938: if (ref($env{'form.'.$setting})) {
1.153 matthew 13939: $stored_form = join(',',
13940: map {
1.369 www 13941: &escape($_);
1.258 albertel 13942: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13943: } else {
13944: $stored_form =
1.369 www 13945: &escape($env{'form.'.$setting});
1.153 matthew 13946: }
13947: # Determine if the array contents are the same.
1.258 albertel 13948: if ($stored_form ne $env{$envname}) {
1.153 matthew 13949: $SaveHash{$basename} = $stored_form;
13950: $AppHash{$envname} = $stored_form;
13951: }
13952: }
13953: }
13954: }
13955: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13956: $udom,$uname);
1.153 matthew 13957: if ($put_result !~ /^(ok|delayed)/) {
13958: &Apache::lonnet::logthis('unable to save form parameters, '.
13959: 'got error:'.$put_result);
13960: }
13961: # Make sure these settings stick around in this session, too
1.646 raeburn 13962: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13963: return;
13964: }
13965:
13966: sub restore_course_settings {
1.499 albertel 13967: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13968: }
13969:
13970: sub restore_settings {
13971: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13972: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13973: next if (exists($env{'form.'.$setting}));
1.496 albertel 13974: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13975: '.'.$setting;
1.258 albertel 13976: if (exists($env{$envname})) {
1.153 matthew 13977: if ($type eq 'scalar') {
1.258 albertel 13978: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13979: } elsif ($type eq 'array') {
1.258 albertel 13980: $env{'form.'.$setting} = [
1.153 matthew 13981: map {
1.369 www 13982: &unescape($_);
1.258 albertel 13983: } split(',',$env{$envname})
1.153 matthew 13984: ];
13985: }
13986: }
13987: }
1.127 matthew 13988: }
13989:
1.618 raeburn 13990: #######################################################
13991: #######################################################
13992:
13993: =pod
13994:
13995: =head1 Domain E-mail Routines
13996:
13997: =over 4
13998:
1.648 raeburn 13999: =item * &build_recipient_list()
1.618 raeburn 14000:
1.1144 raeburn 14001: Build recipient lists for following types of e-mail:
1.766 raeburn 14002: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14003: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14004: module change checking, student/employee ID conflict checks, as
14005: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14006: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14007:
14008: Inputs:
1.619 raeburn 14009: defmail (scalar - email address of default recipient),
1.1144 raeburn 14010: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14011: requestsmail, updatesmail, or idconflictsmail).
14012:
1.619 raeburn 14013: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14014:
1.619 raeburn 14015: origmail (scalar - email address of recipient from loncapa.conf,
14016: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14017:
1.655 raeburn 14018: Returns: comma separated list of addresses to which to send e-mail.
14019:
14020: =back
1.618 raeburn 14021:
14022: =cut
14023:
14024: ############################################################
14025: ############################################################
14026: sub build_recipient_list {
1.619 raeburn 14027: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 14028: my @recipients;
14029: my $otheremails;
14030: my %domconfig =
14031: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
14032: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14033: if (exists($domconfig{'contacts'}{$mailing})) {
14034: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14035: my @contacts = ('adminemail','supportemail');
14036: foreach my $item (@contacts) {
14037: if ($domconfig{'contacts'}{$mailing}{$item}) {
14038: my $addr = $domconfig{'contacts'}{$item};
14039: if (!grep(/^\Q$addr\E$/,@recipients)) {
14040: push(@recipients,$addr);
14041: }
1.619 raeburn 14042: }
1.766 raeburn 14043: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 14044: }
14045: }
1.766 raeburn 14046: } elsif ($origmail ne '') {
14047: push(@recipients,$origmail);
1.618 raeburn 14048: }
1.619 raeburn 14049: } elsif ($origmail ne '') {
14050: push(@recipients,$origmail);
1.618 raeburn 14051: }
1.688 raeburn 14052: if (defined($defmail)) {
14053: if ($defmail ne '') {
14054: push(@recipients,$defmail);
14055: }
1.618 raeburn 14056: }
14057: if ($otheremails) {
1.619 raeburn 14058: my @others;
14059: if ($otheremails =~ /,/) {
14060: @others = split(/,/,$otheremails);
1.618 raeburn 14061: } else {
1.619 raeburn 14062: push(@others,$otheremails);
14063: }
14064: foreach my $addr (@others) {
14065: if (!grep(/^\Q$addr\E$/,@recipients)) {
14066: push(@recipients,$addr);
14067: }
1.618 raeburn 14068: }
14069: }
1.619 raeburn 14070: my $recipientlist = join(',',@recipients);
1.618 raeburn 14071: return $recipientlist;
14072: }
14073:
1.127 matthew 14074: ############################################################
14075: ############################################################
1.154 albertel 14076:
1.655 raeburn 14077: =pod
14078:
1.1224 musolffc 14079: =over 4
14080:
1.1223 musolffc 14081: =item * &mime_email()
14082:
14083: Sends an email with a possible attachment
14084:
14085: Inputs:
14086:
14087: =over 4
14088:
14089: from - Sender's email address
14090:
14091: to - Email address of recipient
14092:
14093: subject - Subject of email
14094:
14095: body - Body of email
14096:
14097: cc_string - Carbon copy email address
14098:
14099: bcc - Blind carbon copy email address
14100:
14101: type - File type of attachment
14102:
14103: attachment_path - Path of file to be attached
14104:
14105: file_name - Name of file to be attached
14106:
14107: attachment_text - The body of an attachment of type "TEXT"
14108:
14109: =back
14110:
14111: =back
14112:
14113: =cut
14114:
14115: ############################################################
14116: ############################################################
14117:
14118: sub mime_email {
14119: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
14120: $file_name, $attachment_text) = @_;
14121: my $msg = MIME::Lite->new(
14122: From => $from,
14123: To => $to,
14124: Subject => $subject,
14125: Type =>'TEXT',
14126: Data => $body,
14127: );
14128: if ($cc_string ne '') {
14129: $msg->add("Cc" => $cc_string);
14130: }
14131: if ($bcc ne '') {
14132: $msg->add("Bcc" => $bcc);
14133: }
14134: $msg->attr("content-type" => "text/plain");
14135: $msg->attr("content-type.charset" => "UTF-8");
14136: # Attach file if given
14137: if ($attachment_path) {
14138: unless ($file_name) {
14139: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
14140: }
14141: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
14142: $msg->attach(Type => $type,
14143: Path => $attachment_path,
14144: Filename => $file_name
14145: );
14146: # Otherwise attach text if given
14147: } elsif ($attachment_text) {
14148: $msg->attach(Type => 'TEXT',
14149: Data => $attachment_text);
14150: }
14151: # Send it
14152: $msg->send('sendmail');
14153: }
14154:
14155: ############################################################
14156: ############################################################
14157:
14158: =pod
14159:
1.655 raeburn 14160: =head1 Course Catalog Routines
14161:
14162: =over 4
14163:
14164: =item * &gather_categories()
14165:
14166: Converts category definitions - keys of categories hash stored in
14167: coursecategories in configuration.db on the primary library server in a
14168: domain - to an array. Also generates javascript and idx hash used to
14169: generate Domain Coordinator interface for editing Course Categories.
14170:
14171: Inputs:
1.663 raeburn 14172:
1.655 raeburn 14173: categories (reference to hash of category definitions).
1.663 raeburn 14174:
1.655 raeburn 14175: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14176: categories and subcategories).
1.663 raeburn 14177:
1.655 raeburn 14178: idx (reference to hash of counters used in Domain Coordinator interface for
14179: editing Course Categories).
1.663 raeburn 14180:
1.655 raeburn 14181: jsarray (reference to array of categories used to create Javascript arrays for
14182: Domain Coordinator interface for editing Course Categories).
14183:
14184: Returns: nothing
14185:
14186: Side effects: populates cats, idx and jsarray.
14187:
14188: =cut
14189:
14190: sub gather_categories {
14191: my ($categories,$cats,$idx,$jsarray) = @_;
14192: my %counters;
14193: my $num = 0;
14194: foreach my $item (keys(%{$categories})) {
14195: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14196: if ($container eq '' && $depth == 0) {
14197: $cats->[$depth][$categories->{$item}] = $cat;
14198: } else {
14199: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14200: }
14201: my ($escitem,$tail) = split(/:/,$item,2);
14202: if ($counters{$tail} eq '') {
14203: $counters{$tail} = $num;
14204: $num ++;
14205: }
14206: if (ref($idx) eq 'HASH') {
14207: $idx->{$item} = $counters{$tail};
14208: }
14209: if (ref($jsarray) eq 'ARRAY') {
14210: push(@{$jsarray->[$counters{$tail}]},$item);
14211: }
14212: }
14213: return;
14214: }
14215:
14216: =pod
14217:
14218: =item * &extract_categories()
14219:
14220: Used to generate breadcrumb trails for course categories.
14221:
14222: Inputs:
1.663 raeburn 14223:
1.655 raeburn 14224: categories (reference to hash of category definitions).
1.663 raeburn 14225:
1.655 raeburn 14226: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14227: categories and subcategories).
1.663 raeburn 14228:
1.655 raeburn 14229: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14230:
1.655 raeburn 14231: allitems (reference to hash - key is category key
14232: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14233:
1.655 raeburn 14234: idx (reference to hash of counters used in Domain Coordinator interface for
14235: editing Course Categories).
1.663 raeburn 14236:
1.655 raeburn 14237: jsarray (reference to array of categories used to create Javascript arrays for
14238: Domain Coordinator interface for editing Course Categories).
14239:
1.665 raeburn 14240: subcats (reference to hash of arrays containing all subcategories within each
14241: category, -recursive)
14242:
1.655 raeburn 14243: Returns: nothing
14244:
14245: Side effects: populates trails and allitems hash references.
14246:
14247: =cut
14248:
14249: sub extract_categories {
1.665 raeburn 14250: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 14251: if (ref($categories) eq 'HASH') {
14252: &gather_categories($categories,$cats,$idx,$jsarray);
14253: if (ref($cats->[0]) eq 'ARRAY') {
14254: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14255: my $name = $cats->[0][$i];
14256: my $item = &escape($name).'::0';
14257: my $trailstr;
14258: if ($name eq 'instcode') {
14259: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14260: } elsif ($name eq 'communities') {
14261: $trailstr = &mt('Communities');
1.655 raeburn 14262: } else {
14263: $trailstr = $name;
14264: }
14265: if ($allitems->{$item} eq '') {
14266: push(@{$trails},$trailstr);
14267: $allitems->{$item} = scalar(@{$trails})-1;
14268: }
14269: my @parents = ($name);
14270: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14271: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14272: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14273: if (ref($subcats) eq 'HASH') {
14274: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14275: }
14276: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
14277: }
14278: } else {
14279: if (ref($subcats) eq 'HASH') {
14280: $subcats->{$item} = [];
1.655 raeburn 14281: }
14282: }
14283: }
14284: }
14285: }
14286: return;
14287: }
14288:
14289: =pod
14290:
1.1162 raeburn 14291: =item * &recurse_categories()
1.655 raeburn 14292:
14293: Recursively used to generate breadcrumb trails for course categories.
14294:
14295: Inputs:
1.663 raeburn 14296:
1.655 raeburn 14297: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14298: categories and subcategories).
1.663 raeburn 14299:
1.655 raeburn 14300: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14301:
14302: category (current course category, for which breadcrumb trail is being generated).
14303:
14304: trails (reference to array of breadcrumb trails for each category).
14305:
1.655 raeburn 14306: allitems (reference to hash - key is category key
14307: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14308:
1.655 raeburn 14309: parents (array containing containers directories for current category,
14310: back to top level).
14311:
14312: Returns: nothing
14313:
14314: Side effects: populates trails and allitems hash references
14315:
14316: =cut
14317:
14318: sub recurse_categories {
1.665 raeburn 14319: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 14320: my $shallower = $depth - 1;
14321: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14322: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14323: my $name = $cats->[$depth]{$category}[$k];
14324: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14325: my $trailstr = join(' -> ',(@{$parents},$category));
14326: if ($allitems->{$item} eq '') {
14327: push(@{$trails},$trailstr);
14328: $allitems->{$item} = scalar(@{$trails})-1;
14329: }
14330: my $deeper = $depth+1;
14331: push(@{$parents},$category);
1.665 raeburn 14332: if (ref($subcats) eq 'HASH') {
14333: my $subcat = &escape($name).':'.$category.':'.$depth;
14334: for (my $j=@{$parents}; $j>=0; $j--) {
14335: my $higher;
14336: if ($j > 0) {
14337: $higher = &escape($parents->[$j]).':'.
14338: &escape($parents->[$j-1]).':'.$j;
14339: } else {
14340: $higher = &escape($parents->[$j]).'::'.$j;
14341: }
14342: push(@{$subcats->{$higher}},$subcat);
14343: }
14344: }
14345: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
14346: $subcats);
1.655 raeburn 14347: pop(@{$parents});
14348: }
14349: } else {
14350: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14351: my $trailstr = join(' -> ',(@{$parents},$category));
14352: if ($allitems->{$item} eq '') {
14353: push(@{$trails},$trailstr);
14354: $allitems->{$item} = scalar(@{$trails})-1;
14355: }
14356: }
14357: return;
14358: }
14359:
1.663 raeburn 14360: =pod
14361:
1.1162 raeburn 14362: =item * &assign_categories_table()
1.663 raeburn 14363:
14364: Create a datatable for display of hierarchical categories in a domain,
14365: with checkboxes to allow a course to be categorized.
14366:
14367: Inputs:
14368:
14369: cathash - reference to hash of categories defined for the domain (from
14370: configuration.db)
14371:
14372: currcat - scalar with an & separated list of categories assigned to a course.
14373:
1.919 raeburn 14374: type - scalar contains course type (Course or Community).
14375:
1.663 raeburn 14376: Returns: $output (markup to be displayed)
14377:
14378: =cut
14379:
14380: sub assign_categories_table {
1.919 raeburn 14381: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 14382: my $output;
14383: if (ref($cathash) eq 'HASH') {
14384: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
14385: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
14386: $maxdepth = scalar(@cats);
14387: if (@cats > 0) {
14388: my $itemcount = 0;
14389: if (ref($cats[0]) eq 'ARRAY') {
14390: my @currcategories;
14391: if ($currcat ne '') {
14392: @currcategories = split('&',$currcat);
14393: }
1.919 raeburn 14394: my $table;
1.663 raeburn 14395: for (my $i=0; $i<@{$cats[0]}; $i++) {
14396: my $parent = $cats[0][$i];
1.919 raeburn 14397: next if ($parent eq 'instcode');
14398: if ($type eq 'Community') {
14399: next unless ($parent eq 'communities');
14400: } else {
14401: next if ($parent eq 'communities');
14402: }
1.663 raeburn 14403: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14404: my $item = &escape($parent).'::0';
14405: my $checked = '';
14406: if (@currcategories > 0) {
14407: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14408: $checked = ' checked="checked"';
1.663 raeburn 14409: }
14410: }
1.919 raeburn 14411: my $parent_title = $parent;
14412: if ($parent eq 'communities') {
14413: $parent_title = &mt('Communities');
14414: }
14415: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14416: '<input type="checkbox" name="usecategory" value="'.
14417: $item.'"'.$checked.' />'.$parent_title.'</span>'.
14418: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14419: my $depth = 1;
14420: push(@path,$parent);
1.919 raeburn 14421: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 14422: pop(@path);
1.919 raeburn 14423: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14424: $itemcount ++;
14425: }
1.919 raeburn 14426: if ($itemcount) {
14427: $output = &Apache::loncommon::start_data_table().
14428: $table.
14429: &Apache::loncommon::end_data_table();
14430: }
1.663 raeburn 14431: }
14432: }
14433: }
14434: return $output;
14435: }
14436:
14437: =pod
14438:
1.1162 raeburn 14439: =item * &assign_category_rows()
1.663 raeburn 14440:
14441: Create a datatable row for display of nested categories in a domain,
14442: with checkboxes to allow a course to be categorized,called recursively.
14443:
14444: Inputs:
14445:
14446: itemcount - track row number for alternating colors
14447:
14448: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14449: categories and subcategories.
14450:
14451: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14452:
14453: parent - parent of current category item
14454:
14455: path - Array containing all categories back up through the hierarchy from the
14456: current category to the top level.
14457:
14458: currcategories - reference to array of current categories assigned to the course
14459:
14460: Returns: $output (markup to be displayed).
14461:
14462: =cut
14463:
14464: sub assign_category_rows {
14465: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
14466: my ($text,$name,$item,$chgstr);
14467: if (ref($cats) eq 'ARRAY') {
14468: my $maxdepth = scalar(@{$cats});
14469: if (ref($cats->[$depth]) eq 'HASH') {
14470: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14471: my $numchildren = @{$cats->[$depth]{$parent}};
14472: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 14473: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14474: for (my $j=0; $j<$numchildren; $j++) {
14475: $name = $cats->[$depth]{$parent}[$j];
14476: $item = &escape($name).':'.&escape($parent).':'.$depth;
14477: my $deeper = $depth+1;
14478: my $checked = '';
14479: if (ref($currcategories) eq 'ARRAY') {
14480: if (@{$currcategories} > 0) {
14481: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14482: $checked = ' checked="checked"';
1.663 raeburn 14483: }
14484: }
14485: }
1.664 raeburn 14486: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14487: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 14488: $item.'"'.$checked.' />'.$name.'</label></span>'.
14489: '<input type="hidden" name="catname" value="'.$name.'" />'.
14490: '</td><td>';
1.663 raeburn 14491: if (ref($path) eq 'ARRAY') {
14492: push(@{$path},$name);
14493: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
14494: pop(@{$path});
14495: }
14496: $text .= '</td></tr>';
14497: }
14498: $text .= '</table></td>';
14499: }
14500: }
14501: }
14502: return $text;
14503: }
14504:
1.1181 raeburn 14505: =pod
14506:
14507: =back
14508:
14509: =cut
14510:
1.655 raeburn 14511: ############################################################
14512: ############################################################
14513:
14514:
1.443 albertel 14515: sub commit_customrole {
1.664 raeburn 14516: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14517: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14518: ($start?', '.&mt('starting').' '.localtime($start):'').
14519: ($end?', ending '.localtime($end):'').': <b>'.
14520: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14521: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14522: '</b><br />';
14523: return $output;
14524: }
14525:
14526: sub commit_standardrole {
1.1116 raeburn 14527: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14528: my ($output,$logmsg,$linefeed);
14529: if ($context eq 'auto') {
14530: $linefeed = "\n";
14531: } else {
14532: $linefeed = "<br />\n";
14533: }
1.443 albertel 14534: if ($three eq 'st') {
1.541 raeburn 14535: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 14536: $one,$two,$sec,$context,$credits);
1.541 raeburn 14537: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14538: ($result eq 'unknown_course') || ($result eq 'refused')) {
14539: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14540: } else {
1.541 raeburn 14541: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14542: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14543: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14544: if ($context eq 'auto') {
14545: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14546: } else {
14547: $output .= '<b>'.$result.'</b>'.$linefeed.
14548: &mt('Add to classlist').': <b>ok</b>';
14549: }
14550: $output .= $linefeed;
1.443 albertel 14551: }
14552: } else {
14553: $output = &mt('Assigning').' '.$three.' in '.$url.
14554: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14555: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 14556: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 14557: if ($context eq 'auto') {
14558: $output .= $result.$linefeed;
14559: } else {
14560: $output .= '<b>'.$result.'</b>'.$linefeed;
14561: }
1.443 albertel 14562: }
14563: return $output;
14564: }
14565:
14566: sub commit_studentrole {
1.1116 raeburn 14567: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
14568: $credits) = @_;
1.626 raeburn 14569: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 14570: if ($context eq 'auto') {
14571: $linefeed = "\n";
14572: } else {
14573: $linefeed = '<br />'."\n";
14574: }
1.443 albertel 14575: if (defined($one) && defined($two)) {
14576: my $cid=$one.'_'.$two;
14577: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
14578: my $secchange = 0;
14579: my $expire_role_result;
14580: my $modify_section_result;
1.628 raeburn 14581: if ($oldsec ne '-1') {
14582: if ($oldsec ne $sec) {
1.443 albertel 14583: $secchange = 1;
1.628 raeburn 14584: my $now = time;
1.443 albertel 14585: my $uurl='/'.$cid;
14586: $uurl=~s/\_/\//g;
14587: if ($oldsec) {
14588: $uurl.='/'.$oldsec;
14589: }
1.626 raeburn 14590: $oldsecurl = $uurl;
1.628 raeburn 14591: $expire_role_result =
1.652 raeburn 14592: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 14593: if ($env{'request.course.sec'} ne '') {
14594: if ($expire_role_result eq 'refused') {
14595: my @roles = ('st');
14596: my @statuses = ('previous');
14597: my @roledoms = ($one);
14598: my $withsec = 1;
14599: my %roleshash =
14600: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
14601: \@statuses,\@roles,\@roledoms,$withsec);
14602: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
14603: my ($oldstart,$oldend) =
14604: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
14605: if ($oldend > 0 && $oldend <= $now) {
14606: $expire_role_result = 'ok';
14607: }
14608: }
14609: }
14610: }
1.443 albertel 14611: $result = $expire_role_result;
14612: }
14613: }
14614: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 14615: $modify_section_result =
14616: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
14617: undef,undef,undef,$sec,
14618: $end,$start,'','',$cid,
14619: '',$context,$credits);
1.443 albertel 14620: if ($modify_section_result =~ /^ok/) {
14621: if ($secchange == 1) {
1.628 raeburn 14622: if ($sec eq '') {
14623: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
14624: } else {
14625: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
14626: }
1.443 albertel 14627: } elsif ($oldsec eq '-1') {
1.628 raeburn 14628: if ($sec eq '') {
14629: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
14630: } else {
14631: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14632: }
1.443 albertel 14633: } else {
1.628 raeburn 14634: if ($sec eq '') {
14635: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
14636: } else {
14637: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14638: }
1.443 albertel 14639: }
14640: } else {
1.1115 raeburn 14641: if ($secchange) {
1.628 raeburn 14642: $$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;
14643: } else {
14644: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
14645: }
1.443 albertel 14646: }
14647: $result = $modify_section_result;
14648: } elsif ($secchange == 1) {
1.628 raeburn 14649: if ($oldsec eq '') {
1.1103 raeburn 14650: $$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 14651: } else {
14652: $$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;
14653: }
1.626 raeburn 14654: if ($expire_role_result eq 'refused') {
14655: my $newsecurl = '/'.$cid;
14656: $newsecurl =~ s/\_/\//g;
14657: if ($sec ne '') {
14658: $newsecurl.='/'.$sec;
14659: }
14660: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
14661: if ($sec eq '') {
14662: $$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;
14663: } else {
14664: $$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;
14665: }
14666: }
14667: }
1.443 albertel 14668: }
14669: } else {
1.626 raeburn 14670: $$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 14671: $result = "error: incomplete course id\n";
14672: }
14673: return $result;
14674: }
14675:
1.1108 raeburn 14676: sub show_role_extent {
14677: my ($scope,$context,$role) = @_;
14678: $scope =~ s{^/}{};
14679: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
14680: push(@courseroles,'co');
14681: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
14682: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
14683: $scope =~ s{/}{_};
14684: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
14685: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
14686: my ($audom,$auname) = split(/\//,$scope);
14687: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
14688: &Apache::loncommon::plainname($auname,$audom).'</span>');
14689: } else {
14690: $scope =~ s{/$}{};
14691: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
14692: &Apache::lonnet::domain($scope,'description').'</span>');
14693: }
14694: }
14695:
1.443 albertel 14696: ############################################################
14697: ############################################################
14698:
1.566 albertel 14699: sub check_clone {
1.578 raeburn 14700: my ($args,$linefeed) = @_;
1.566 albertel 14701: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
14702: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
14703: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
14704: my $clonemsg;
14705: my $can_clone = 0;
1.944 raeburn 14706: my $lctype = lc($args->{'crstype'});
1.908 raeburn 14707: if ($lctype ne 'community') {
14708: $lctype = 'course';
14709: }
1.566 albertel 14710: if ($clonehome eq 'no_host') {
1.944 raeburn 14711: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14712: $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'});
14713: } else {
14714: $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'});
14715: }
1.566 albertel 14716: } else {
14717: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 14718: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14719: if ($clonedesc{'type'} ne 'Community') {
14720: $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'});
14721: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14722: }
14723: }
1.882 raeburn 14724: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
14725: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 14726: $can_clone = 1;
14727: } else {
1.1221 raeburn 14728: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 14729: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 14730: if ($clonehash{'cloners'} eq '') {
14731: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
14732: if ($domdefs{'canclone'}) {
14733: unless ($domdefs{'canclone'} eq 'none') {
14734: if ($domdefs{'canclone'} eq 'domain') {
14735: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
14736: $can_clone = 1;
14737: }
14738: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14739: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
14740: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
14741: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
14742: $can_clone = 1;
14743: }
14744: }
14745: }
14746: }
1.578 raeburn 14747: } else {
1.1221 raeburn 14748: my @cloners = split(/,/,$clonehash{'cloners'});
14749: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 14750: $can_clone = 1;
1.1221 raeburn 14751: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 14752: $can_clone = 1;
1.1225 raeburn 14753: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
14754: $can_clone = 1;
1.1221 raeburn 14755: }
14756: unless ($can_clone) {
1.1225 raeburn 14757: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14758: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 14759: my (%gotdomdefaults,%gotcodedefaults);
14760: foreach my $cloner (@cloners) {
14761: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
14762: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
14763: my (%codedefaults,@code_order);
14764: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
14765: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
14766: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
14767: }
14768: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
14769: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
14770: }
14771: } else {
14772: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
14773: \%codedefaults,
14774: \@code_order);
14775: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
14776: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
14777: }
14778: if (@code_order > 0) {
14779: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
14780: $cloner,$clonehash{'internal.coursecode'},
14781: $args->{'crscode'})) {
14782: $can_clone = 1;
14783: last;
14784: }
14785: }
14786: }
14787: }
14788: }
1.1225 raeburn 14789: }
14790: }
14791: unless ($can_clone) {
14792: my $ccrole = 'cc';
14793: if ($args->{'crstype'} eq 'Community') {
14794: $ccrole = 'co';
14795: }
14796: my %roleshash =
14797: &Apache::lonnet::get_my_roles($args->{'ccuname'},
14798: $args->{'ccdomain'},
14799: 'userroles',['active'],[$ccrole],
14800: [$args->{'clonedomain'}]);
14801: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
14802: $can_clone = 1;
14803: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
14804: $args->{'ccuname'},$args->{'ccdomain'})) {
14805: $can_clone = 1;
1.1221 raeburn 14806: }
14807: }
14808: unless ($can_clone) {
14809: if ($args->{'crstype'} eq 'Community') {
14810: $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 14811: } else {
1.1221 raeburn 14812: $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'});
14813: }
1.566 albertel 14814: }
1.578 raeburn 14815: }
1.566 albertel 14816: }
14817: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14818: }
14819:
1.444 albertel 14820: sub construct_course {
1.1166 raeburn 14821: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 14822: my $outcome;
1.541 raeburn 14823: my $linefeed = '<br />'."\n";
14824: if ($context eq 'auto') {
14825: $linefeed = "\n";
14826: }
1.566 albertel 14827:
14828: #
14829: # Are we cloning?
14830: #
14831: my ($can_clone, $clonemsg, $cloneid, $clonehome);
14832: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 14833: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 14834: if ($context ne 'auto') {
1.578 raeburn 14835: if ($clonemsg ne '') {
14836: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
14837: }
1.566 albertel 14838: }
14839: $outcome .= $clonemsg.$linefeed;
14840:
14841: if (!$can_clone) {
14842: return (0,$outcome);
14843: }
14844: }
14845:
1.444 albertel 14846: #
14847: # Open course
14848: #
14849: my $crstype = lc($args->{'crstype'});
14850: my %cenv=();
14851: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
14852: $args->{'cdescr'},
14853: $args->{'curl'},
14854: $args->{'course_home'},
14855: $args->{'nonstandard'},
14856: $args->{'crscode'},
14857: $args->{'ccuname'}.':'.
14858: $args->{'ccdomain'},
1.882 raeburn 14859: $args->{'crstype'},
1.885 raeburn 14860: $cnum,$context,$category);
1.444 albertel 14861:
14862: # Note: The testing routines depend on this being output; see
14863: # Utils::Course. This needs to at least be output as a comment
14864: # if anyone ever decides to not show this, and Utils::Course::new
14865: # will need to be suitably modified.
1.541 raeburn 14866: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 14867: if ($$courseid =~ /^error:/) {
14868: return (0,$outcome);
14869: }
14870:
1.444 albertel 14871: #
14872: # Check if created correctly
14873: #
1.479 albertel 14874: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 14875: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 14876: if ($crsuhome eq 'no_host') {
14877: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
14878: return (0,$outcome);
14879: }
1.541 raeburn 14880: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 14881:
1.444 albertel 14882: #
1.566 albertel 14883: # Do the cloning
14884: #
14885: if ($can_clone && $cloneid) {
14886: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
14887: if ($context ne 'auto') {
14888: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
14889: }
14890: $outcome .= $clonemsg.$linefeed;
14891: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 14892: # Copy all files
1.637 www 14893: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 14894: # Restore URL
1.566 albertel 14895: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 14896: # Restore title
1.566 albertel 14897: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 14898: # Restore creation date, creator and creation context.
14899: $cenv{'internal.created'}=$oldcenv{'internal.created'};
14900: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
14901: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 14902: # Mark as cloned
1.566 albertel 14903: $cenv{'clonedfrom'}=$cloneid;
1.638 www 14904: # Need to clone grading mode
14905: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
14906: $cenv{'grading'}=$newenv{'grading'};
14907: # Do not clone these environment entries
14908: &Apache::lonnet::del('environment',
14909: ['default_enrollment_start_date',
14910: 'default_enrollment_end_date',
14911: 'question.email',
14912: 'policy.email',
14913: 'comment.email',
14914: 'pch.users.denied',
1.725 raeburn 14915: 'plc.users.denied',
14916: 'hidefromcat',
1.1121 raeburn 14917: 'checkforpriv',
1.1166 raeburn 14918: 'categories',
14919: 'internal.uniquecode'],
1.638 www 14920: $$crsudom,$$crsunum);
1.1170 raeburn 14921: if ($args->{'textbook'}) {
14922: $cenv{'internal.textbook'} = $args->{'textbook'};
14923: }
1.444 albertel 14924: }
1.566 albertel 14925:
1.444 albertel 14926: #
14927: # Set environment (will override cloned, if existing)
14928: #
14929: my @sections = ();
14930: my @xlists = ();
14931: if ($args->{'crstype'}) {
14932: $cenv{'type'}=$args->{'crstype'};
14933: }
14934: if ($args->{'crsid'}) {
14935: $cenv{'courseid'}=$args->{'crsid'};
14936: }
14937: if ($args->{'crscode'}) {
14938: $cenv{'internal.coursecode'}=$args->{'crscode'};
14939: }
14940: if ($args->{'crsquota'} ne '') {
14941: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14942: } else {
14943: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14944: }
14945: if ($args->{'ccuname'}) {
14946: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14947: ':'.$args->{'ccdomain'};
14948: } else {
14949: $cenv{'internal.courseowner'} = $args->{'curruser'};
14950: }
1.1116 raeburn 14951: if ($args->{'defaultcredits'}) {
14952: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14953: }
1.444 albertel 14954: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14955: if ($args->{'crssections'}) {
14956: $cenv{'internal.sectionnums'} = '';
14957: if ($args->{'crssections'} =~ m/,/) {
14958: @sections = split/,/,$args->{'crssections'};
14959: } else {
14960: $sections[0] = $args->{'crssections'};
14961: }
14962: if (@sections > 0) {
14963: foreach my $item (@sections) {
14964: my ($sec,$gp) = split/:/,$item;
14965: my $class = $args->{'crscode'}.$sec;
14966: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14967: $cenv{'internal.sectionnums'} .= $item.',';
14968: unless ($addcheck eq 'ok') {
14969: push @badclasses, $class;
14970: }
14971: }
14972: $cenv{'internal.sectionnums'} =~ s/,$//;
14973: }
14974: }
14975: # do not hide course coordinator from staff listing,
14976: # even if privileged
14977: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 14978: # add course coordinator's domain to domains to check for privileged users
14979: # if different to course domain
14980: if ($$crsudom ne $args->{'ccdomain'}) {
14981: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14982: }
1.444 albertel 14983: # add crosslistings
14984: if ($args->{'crsxlist'}) {
14985: $cenv{'internal.crosslistings'}='';
14986: if ($args->{'crsxlist'} =~ m/,/) {
14987: @xlists = split/,/,$args->{'crsxlist'};
14988: } else {
14989: $xlists[0] = $args->{'crsxlist'};
14990: }
14991: if (@xlists > 0) {
14992: foreach my $item (@xlists) {
14993: my ($xl,$gp) = split/:/,$item;
14994: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14995: $cenv{'internal.crosslistings'} .= $item.',';
14996: unless ($addcheck eq 'ok') {
14997: push @badclasses, $xl;
14998: }
14999: }
15000: $cenv{'internal.crosslistings'} =~ s/,$//;
15001: }
15002: }
15003: if ($args->{'autoadds'}) {
15004: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15005: }
15006: if ($args->{'autodrops'}) {
15007: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15008: }
15009: # check for notification of enrollment changes
15010: my @notified = ();
15011: if ($args->{'notify_owner'}) {
15012: if ($args->{'ccuname'} ne '') {
15013: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15014: }
15015: }
15016: if ($args->{'notify_dc'}) {
15017: if ($uname ne '') {
1.630 raeburn 15018: push(@notified,$uname.':'.$udom);
1.444 albertel 15019: }
15020: }
15021: if (@notified > 0) {
15022: my $notifylist;
15023: if (@notified > 1) {
15024: $notifylist = join(',',@notified);
15025: } else {
15026: $notifylist = $notified[0];
15027: }
15028: $cenv{'internal.notifylist'} = $notifylist;
15029: }
15030: if (@badclasses > 0) {
15031: my %lt=&Apache::lonlocal::texthash(
15032: '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',
15033: 'dnhr' => 'does not have rights to access enrollment in these classes',
15034: 'adby' => 'as determined by the policies of your institution on access to official classlists'
15035: );
1.541 raeburn 15036: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
15037: ' ('.$lt{'adby'}.')';
15038: if ($context eq 'auto') {
15039: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 15040: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 15041: foreach my $item (@badclasses) {
15042: if ($context eq 'auto') {
15043: $outcome .= " - $item\n";
15044: } else {
15045: $outcome .= "<li>$item</li>\n";
15046: }
15047: }
15048: if ($context eq 'auto') {
15049: $outcome .= $linefeed;
15050: } else {
1.566 albertel 15051: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 15052: }
15053: }
1.444 albertel 15054: }
15055: if ($args->{'no_end_date'}) {
15056: $args->{'endaccess'} = 0;
15057: }
15058: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15059: $cenv{'internal.autoend'}=$args->{'enrollend'};
15060: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15061: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15062: if ($args->{'showphotos'}) {
15063: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15064: }
15065: $cenv{'internal.authtype'} = $args->{'authtype'};
15066: $cenv{'internal.autharg'} = $args->{'autharg'};
15067: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15068: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15069: 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');
15070: if ($context eq 'auto') {
15071: $outcome .= $krb_msg;
15072: } else {
1.566 albertel 15073: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15074: }
15075: $outcome .= $linefeed;
1.444 albertel 15076: }
15077: }
15078: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15079: if ($args->{'setpolicy'}) {
15080: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15081: }
15082: if ($args->{'setcontent'}) {
15083: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15084: }
15085: }
15086: if ($args->{'reshome'}) {
15087: $cenv{'reshome'}=$args->{'reshome'}.'/';
15088: $cenv{'reshome'}=~s/\/+$/\//;
15089: }
15090: #
15091: # course has keyed access
15092: #
15093: if ($args->{'setkeys'}) {
15094: $cenv{'keyaccess'}='yes';
15095: }
15096: # if specified, key authority is not course, but user
15097: # only active if keyaccess is yes
15098: if ($args->{'keyauth'}) {
1.487 albertel 15099: my ($user,$domain) = split(':',$args->{'keyauth'});
15100: $user = &LONCAPA::clean_username($user);
15101: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15102: if ($user ne '' && $domain ne '') {
1.487 albertel 15103: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15104: }
15105: }
15106:
1.1166 raeburn 15107: #
1.1167 raeburn 15108: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 15109: #
15110: if ($args->{'uniquecode'}) {
15111: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15112: if ($code) {
15113: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 15114: my %crsinfo =
15115: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15116: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15117: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15118: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15119: }
1.1166 raeburn 15120: if (ref($coderef)) {
15121: $$coderef = $code;
15122: }
15123: }
15124: }
15125:
1.444 albertel 15126: if ($args->{'disresdis'}) {
15127: $cenv{'pch.roles.denied'}='st';
15128: }
15129: if ($args->{'disablechat'}) {
15130: $cenv{'plc.roles.denied'}='st';
15131: }
15132:
15133: # Record we've not yet viewed the Course Initialization Helper for this
15134: # course
15135: $cenv{'course.helper.not.run'} = 1;
15136: #
15137: # Use new Randomseed
15138: #
15139: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15140: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15141: #
15142: # The encryption code and receipt prefix for this course
15143: #
15144: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15145: $cenv{'internal.encpref'}=100+int(9*rand(99));
15146: #
15147: # By default, use standard grading
15148: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15149:
1.541 raeburn 15150: $outcome .= $linefeed.&mt('Setting environment').': '.
15151: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15152: #
15153: # Open all assignments
15154: #
15155: if ($args->{'openall'}) {
15156: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15157: my %storecontent = ($storeunder => time,
15158: $storeunder.'.type' => 'date_start');
15159:
15160: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15161: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15162: }
15163: #
15164: # Set first page
15165: #
15166: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15167: || ($cloneid)) {
1.445 albertel 15168: use LONCAPA::map;
1.444 albertel 15169: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15170:
15171: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15172: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15173:
1.444 albertel 15174: $outcome .= ($fatal?$errtext:'read ok').' - ';
15175: my $title; my $url;
15176: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15177: $title=&mt('Syllabus');
1.444 albertel 15178: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15179: } else {
1.963 raeburn 15180: $title=&mt('Table of Contents');
1.444 albertel 15181: $url='/adm/navmaps';
15182: }
1.445 albertel 15183:
15184: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15185: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15186:
15187: if ($errtext) { $fatal=2; }
1.541 raeburn 15188: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15189: }
1.566 albertel 15190:
15191: return (1,$outcome);
1.444 albertel 15192: }
15193:
1.1166 raeburn 15194: sub make_unique_code {
15195: my ($cdom,$cnum) = @_;
15196: # get lock on uniquecodes db
15197: my $lockhash = {
15198: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15199: ':'.$env{'user.domain'},
15200: };
15201: my $tries = 0;
15202: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15203: my ($code,$error);
15204:
15205: while (($gotlock ne 'ok') && ($tries<3)) {
15206: $tries ++;
15207: sleep 1;
15208: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15209: }
15210: if ($gotlock eq 'ok') {
15211: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15212: my $gotcode;
15213: my $attempts = 0;
15214: while ((!$gotcode) && ($attempts < 100)) {
15215: $code = &generate_code();
15216: if (!exists($currcodes{$code})) {
15217: $gotcode = 1;
15218: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15219: $error = 'nostore';
15220: }
15221: }
15222: $attempts ++;
15223: }
15224: my @del_lock = ($cnum."\0".'uniquecodes');
15225: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15226: } else {
15227: $error = 'nolock';
15228: }
15229: return ($code,$error);
15230: }
15231:
15232: sub generate_code {
15233: my $code;
15234: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15235: for (my $i=0; $i<6; $i++) {
15236: my $lettnum = int (rand 2);
15237: my $item = '';
15238: if ($lettnum) {
15239: $item = $letts[int( rand(18) )];
15240: } else {
15241: $item = 1+int( rand(8) );
15242: }
15243: $code .= $item;
15244: }
15245: return $code;
15246: }
15247:
1.444 albertel 15248: ############################################################
15249: ############################################################
15250:
1.953 droeschl 15251: #SD
15252: # only Community and Course, or anything else?
1.378 raeburn 15253: sub course_type {
15254: my ($cid) = @_;
15255: if (!defined($cid)) {
15256: $cid = $env{'request.course.id'};
15257: }
1.404 albertel 15258: if (defined($env{'course.'.$cid.'.type'})) {
15259: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15260: } else {
15261: return 'Course';
1.377 raeburn 15262: }
15263: }
1.156 albertel 15264:
1.406 raeburn 15265: sub group_term {
15266: my $crstype = &course_type();
15267: my %names = (
15268: 'Course' => 'group',
1.865 raeburn 15269: 'Community' => 'group',
1.406 raeburn 15270: );
15271: return $names{$crstype};
15272: }
15273:
1.902 raeburn 15274: sub course_types {
1.1165 raeburn 15275: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15276: my %typename = (
15277: official => 'Official course',
15278: unofficial => 'Unofficial course',
15279: community => 'Community',
1.1165 raeburn 15280: textbook => 'Textbook course',
1.902 raeburn 15281: );
15282: return (\@types,\%typename);
15283: }
15284:
1.156 albertel 15285: sub icon {
15286: my ($file)=@_;
1.505 albertel 15287: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15288: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15289: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15290: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15291: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15292: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15293: $curfext.".gif") {
15294: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15295: $curfext.".gif";
15296: }
15297: }
1.249 albertel 15298: return &lonhttpdurl($iconname);
1.154 albertel 15299: }
1.84 albertel 15300:
1.575 albertel 15301: sub lonhttpdurl {
1.692 www 15302: #
15303: # Had been used for "small fry" static images on separate port 8080.
15304: # Modify here if lightweight http functionality desired again.
15305: # Currently eliminated due to increasing firewall issues.
15306: #
1.575 albertel 15307: my ($url)=@_;
1.692 www 15308: return $url;
1.215 albertel 15309: }
15310:
1.213 albertel 15311: sub connection_aborted {
15312: my ($r)=@_;
15313: $r->print(" ");$r->rflush();
15314: my $c = $r->connection;
15315: return $c->aborted();
15316: }
15317:
1.221 foxr 15318: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15319: # strings as 'strings'.
15320: sub escape_single {
1.221 foxr 15321: my ($input) = @_;
1.223 albertel 15322: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15323: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15324: return $input;
15325: }
1.223 albertel 15326:
1.222 foxr 15327: # Same as escape_single, but escape's "'s This
15328: # can be used for "strings"
15329: sub escape_double {
15330: my ($input) = @_;
15331: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15332: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15333: return $input;
15334: }
1.223 albertel 15335:
1.222 foxr 15336: # Escapes the last element of a full URL.
15337: sub escape_url {
15338: my ($url) = @_;
1.238 raeburn 15339: my @urlslices = split(/\//, $url,-1);
1.369 www 15340: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 15341: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15342: }
1.462 albertel 15343:
1.820 raeburn 15344: sub compare_arrays {
15345: my ($arrayref1,$arrayref2) = @_;
15346: my (@difference,%count);
15347: @difference = ();
15348: %count = ();
15349: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15350: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15351: foreach my $element (keys(%count)) {
15352: if ($count{$element} == 1) {
15353: push(@difference,$element);
15354: }
15355: }
15356: }
15357: return @difference;
15358: }
15359:
1.817 bisitz 15360: # -------------------------------------------------------- Initialize user login
1.462 albertel 15361: sub init_user_environment {
1.463 albertel 15362: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15363: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15364:
15365: my $public=($username eq 'public' && $domain eq 'public');
15366:
15367: # See if old ID present, if so, remove
15368:
1.1062 raeburn 15369: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15370: my $now=time;
15371:
15372: if ($public) {
15373: my $max_public=100;
15374: my $oldest;
15375: my $oldest_time=0;
15376: for(my $next=1;$next<=$max_public;$next++) {
15377: if (-e $lonids."/publicuser_$next.id") {
15378: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15379: if ($mtime<$oldest_time || !$oldest_time) {
15380: $oldest_time=$mtime;
15381: $oldest=$next;
15382: }
15383: } else {
15384: $cookie="publicuser_$next";
15385: last;
15386: }
15387: }
15388: if (!$cookie) { $cookie="publicuser_$oldest"; }
15389: } else {
1.463 albertel 15390: # if this isn't a robot, kill any existing non-robot sessions
15391: if (!$args->{'robot'}) {
15392: opendir(DIR,$lonids);
15393: while ($filename=readdir(DIR)) {
15394: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
15395: unlink($lonids.'/'.$filename);
15396: }
1.462 albertel 15397: }
1.463 albertel 15398: closedir(DIR);
1.1204 raeburn 15399: # If there is a undeleted lockfile for the user's paste buffer remove it.
15400: my $namespace = 'nohist_courseeditor';
15401: my $lockingkey = 'paste'."\0".'locked_num';
15402: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15403: $domain,$username);
15404: if (exists($lockhash{$lockingkey})) {
15405: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15406: unless ($delresult eq 'ok') {
15407: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15408: }
15409: }
1.462 albertel 15410: }
15411: # Give them a new cookie
1.463 albertel 15412: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15413: : $now.$$.int(rand(10000)));
1.463 albertel 15414: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15415:
15416: # Initialize roles
15417:
1.1062 raeburn 15418: ($userroles,$firstaccenv,$timerintenv) =
15419: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15420: }
15421: # ------------------------------------ Check browser type and MathML capability
15422:
1.1194 raeburn 15423: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15424: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15425:
15426: # ------------------------------------------------------------- Get environment
15427:
15428: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15429: my ($tmp) = keys(%userenv);
15430: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15431: } else {
15432: undef(%userenv);
15433: }
15434: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15435: $form->{'interface'}=$userenv{'interface'};
15436: }
15437: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15438:
15439: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15440: foreach my $option ('interface','localpath','localres') {
15441: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15442: }
15443: # --------------------------------------------------------- Write first profile
15444:
15445: {
15446: my %initial_env =
15447: ("user.name" => $username,
15448: "user.domain" => $domain,
15449: "user.home" => $authhost,
15450: "browser.type" => $clientbrowser,
15451: "browser.version" => $clientversion,
15452: "browser.mathml" => $clientmathml,
15453: "browser.unicode" => $clientunicode,
15454: "browser.os" => $clientos,
1.1137 raeburn 15455: "browser.mobile" => $clientmobile,
1.1141 raeburn 15456: "browser.info" => $clientinfo,
1.1194 raeburn 15457: "browser.osversion" => $clientosversion,
1.462 albertel 15458: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15459: "request.course.fn" => '',
15460: "request.course.uri" => '',
15461: "request.course.sec" => '',
15462: "request.role" => 'cm',
15463: "request.role.adv" => $env{'user.adv'},
15464: "request.host" => $ENV{'REMOTE_ADDR'},);
15465:
15466: if ($form->{'localpath'}) {
15467: $initial_env{"browser.localpath"} = $form->{'localpath'};
15468: $initial_env{"browser.localres"} = $form->{'localres'};
15469: }
15470:
15471: if ($form->{'interface'}) {
15472: $form->{'interface'}=~s/\W//gs;
15473: $initial_env{"browser.interface"} = $form->{'interface'};
15474: $env{'browser.interface'}=$form->{'interface'};
15475: }
15476:
1.1157 raeburn 15477: if ($form->{'iptoken'}) {
15478: my $lonhost = $r->dir_config('lonHostID');
15479: $initial_env{"user.noloadbalance"} = $lonhost;
15480: $env{'user.noloadbalance'} = $lonhost;
15481: }
15482:
1.981 raeburn 15483: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 15484: my %domdef;
15485: unless ($domain eq 'public') {
15486: %domdef = &Apache::lonnet::get_domain_defaults($domain);
15487: }
1.980 raeburn 15488:
1.1081 raeburn 15489: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 15490: $userenv{'availabletools.'.$tool} =
1.980 raeburn 15491: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15492: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 15493: }
15494:
1.1165 raeburn 15495: foreach my $crstype ('official','unofficial','community','textbook') {
1.765 raeburn 15496: $userenv{'canrequest.'.$crstype} =
15497: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 15498: 'reload','requestcourses',
15499: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 15500: }
15501:
1.1092 raeburn 15502: $userenv{'canrequest.author'} =
15503: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15504: 'reload','requestauthor',
15505: \%userenv,\%domdef,\%is_adv);
15506: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15507: $domain,$username);
15508: my $reqstatus = $reqauthor{'author_status'};
15509: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15510: if (ref($reqauthor{'author'}) eq 'HASH') {
15511: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15512: $reqauthor{'author'}{'timestamp'};
15513: }
15514: }
15515:
1.462 albertel 15516: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15517:
1.462 albertel 15518: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
15519: &GDBM_WRCREAT(),0640)) {
15520: &_add_to_env(\%disk_env,\%initial_env);
15521: &_add_to_env(\%disk_env,\%userenv,'environment.');
15522: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 15523: if (ref($firstaccenv) eq 'HASH') {
15524: &_add_to_env(\%disk_env,$firstaccenv);
15525: }
15526: if (ref($timerintenv) eq 'HASH') {
15527: &_add_to_env(\%disk_env,$timerintenv);
15528: }
1.463 albertel 15529: if (ref($args->{'extra_env'})) {
15530: &_add_to_env(\%disk_env,$args->{'extra_env'});
15531: }
1.462 albertel 15532: untie(%disk_env);
15533: } else {
1.705 tempelho 15534: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
15535: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 15536: return 'error: '.$!;
15537: }
15538: }
15539: $env{'request.role'}='cm';
15540: $env{'request.role.adv'}=$env{'user.adv'};
15541: $env{'browser.type'}=$clientbrowser;
15542:
15543: return $cookie;
15544:
15545: }
15546:
15547: sub _add_to_env {
15548: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 15549: if (ref($env_data) eq 'HASH') {
15550: while (my ($key,$value) = each(%$env_data)) {
15551: $idf->{$prefix.$key} = $value;
15552: $env{$prefix.$key} = $value;
15553: }
1.462 albertel 15554: }
15555: }
15556:
1.685 tempelho 15557: # --- Get the symbolic name of a problem and the url
15558: sub get_symb {
15559: my ($request,$silent) = @_;
1.726 raeburn 15560: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 15561: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
15562: if ($symb eq '') {
15563: if (!$silent) {
1.1071 raeburn 15564: if (ref($request)) {
15565: $request->print("Unable to handle ambiguous references:$url:.");
15566: }
1.685 tempelho 15567: return ();
15568: }
15569: }
15570: &Apache::lonenc::check_decrypt(\$symb);
15571: return ($symb);
15572: }
15573:
15574: # --------------------------------------------------------------Get annotation
15575:
15576: sub get_annotation {
15577: my ($symb,$enc) = @_;
15578:
15579: my $key = $symb;
15580: if (!$enc) {
15581: $key =
15582: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
15583: }
15584: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
15585: return $annotation{$key};
15586: }
15587:
15588: sub clean_symb {
1.731 raeburn 15589: my ($symb,$delete_enc) = @_;
1.685 tempelho 15590:
15591: &Apache::lonenc::check_decrypt(\$symb);
15592: my $enc = $env{'request.enc'};
1.731 raeburn 15593: if ($delete_enc) {
1.730 raeburn 15594: delete($env{'request.enc'});
15595: }
1.685 tempelho 15596:
15597: return ($symb,$enc);
15598: }
1.462 albertel 15599:
1.1181 raeburn 15600: ############################################################
15601: ############################################################
15602:
15603: =pod
15604:
15605: =head1 Routines for building display used to search for courses
15606:
15607:
15608: =over 4
15609:
15610: =item * &build_filters()
15611:
15612: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 15613: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
15614: and quotacheck.pl
15615:
1.1181 raeburn 15616:
15617: Inputs:
15618:
15619: filterlist - anonymous array of fields to include as potential filters
15620:
15621: crstype - course type
15622:
15623: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
15624: to pop-open a course selector (will contain "extra element").
15625:
15626: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
15627:
15628: filter - anonymous hash of criteria and their values
15629:
15630: action - form action
15631:
15632: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
15633:
1.1182 raeburn 15634: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 15635:
15636: cloneruname - username of owner of new course who wants to clone
15637:
15638: clonerudom - domain of owner of new course who wants to clone
15639:
15640: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
15641:
15642: codetitlesref - reference to array of titles of components in institutional codes (official courses)
15643:
15644: codedom - domain
15645:
15646: formname - value of form element named "form".
15647:
15648: fixeddom - domain, if fixed.
15649:
15650: prevphase - value to assign to form element named "phase" when going back to the previous screen
15651:
15652: cnameelement - name of form element in form on opener page which will receive title of selected course
15653:
15654: cnumelement - name of form element in form on opener page which will receive courseID of selected course
15655:
15656: cdomelement - name of form element in form on opener page which will receive domain of selected course
15657:
15658: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
15659:
15660: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
15661:
15662: clonewarning - warning message about missing information for intended course owner when DC creates a course
15663:
1.1182 raeburn 15664:
1.1181 raeburn 15665: Returns: $output - HTML for display of search criteria, and hidden form elements.
15666:
1.1182 raeburn 15667:
1.1181 raeburn 15668: Side Effects: None
15669:
15670: =cut
15671:
15672: # ---------------------------------------------- search for courses based on last activity etc.
15673:
15674: sub build_filters {
15675: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
15676: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
15677: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
15678: $cnameelement,$cnumelement,$cdomelement,$setroles,
15679: $clonetext,$clonewarning) = @_;
1.1182 raeburn 15680: my ($list,$jscript);
1.1181 raeburn 15681: my $onchange = 'javascript:updateFilters(this)';
15682: my ($domainselectform,$sincefilterform,$createdfilterform,
15683: $ownerdomselectform,$persondomselectform,$instcodeform,
15684: $typeselectform,$instcodetitle);
15685: if ($formname eq '') {
15686: $formname = $caller;
15687: }
15688: foreach my $item (@{$filterlist}) {
15689: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
15690: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
15691: if ($item eq 'domainfilter') {
15692: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
15693: } elsif ($item eq 'coursefilter') {
15694: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
15695: } elsif ($item eq 'ownerfilter') {
15696: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15697: } elsif ($item eq 'ownerdomfilter') {
15698: $filter->{'ownerdomfilter'} =
15699: &LONCAPA::clean_domain($filter->{$item});
15700: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
15701: 'ownerdomfilter',1);
15702: } elsif ($item eq 'personfilter') {
15703: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15704: } elsif ($item eq 'persondomfilter') {
15705: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
15706: 'persondomfilter',1);
15707: } else {
15708: $filter->{$item} =~ s/\W//g;
15709: }
15710: if (!$filter->{$item}) {
15711: $filter->{$item} = '';
15712: }
15713: }
15714: if ($item eq 'domainfilter') {
15715: my $allow_blank = 1;
15716: if ($formname eq 'portform') {
15717: $allow_blank=0;
15718: } elsif ($formname eq 'studentform') {
15719: $allow_blank=0;
15720: }
15721: if ($fixeddom) {
15722: $domainselectform = '<input type="hidden" name="domainfilter"'.
15723: ' value="'.$codedom.'" />'.
15724: &Apache::lonnet::domain($codedom,'description');
15725: } else {
15726: $domainselectform = &select_dom_form($filter->{$item},
15727: 'domainfilter',
15728: $allow_blank,'',$onchange);
15729: }
15730: } else {
15731: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
15732: }
15733: }
15734:
15735: # last course activity filter and selection
15736: $sincefilterform = &timebased_select_form('sincefilter',$filter);
15737:
15738: # course created filter and selection
15739: if (exists($filter->{'createdfilter'})) {
15740: $createdfilterform = &timebased_select_form('createdfilter',$filter);
15741: }
15742:
15743: my %lt = &Apache::lonlocal::texthash(
15744: 'cac' => "$crstype Activity",
15745: 'ccr' => "$crstype Created",
15746: 'cde' => "$crstype Title",
15747: 'cdo' => "$crstype Domain",
15748: 'ins' => 'Institutional Code',
15749: 'inc' => 'Institutional Categorization',
15750: 'cow' => "$crstype Owner/Co-owner",
15751: 'cop' => "$crstype Personnel Includes",
15752: 'cog' => 'Type',
15753: );
15754:
15755: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15756: my $typeval = 'Course';
15757: if ($crstype eq 'Community') {
15758: $typeval = 'Community';
15759: }
15760: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
15761: } else {
15762: $typeselectform = '<select name="type" size="1"';
15763: if ($onchange) {
15764: $typeselectform .= ' onchange="'.$onchange.'"';
15765: }
15766: $typeselectform .= '>'."\n";
15767: foreach my $posstype ('Course','Community') {
15768: $typeselectform.='<option value="'.$posstype.'"'.
15769: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
15770: }
15771: $typeselectform.="</select>";
15772: }
15773:
15774: my ($cloneableonlyform,$cloneabletitle);
15775: if (exists($filter->{'cloneableonly'})) {
15776: my $cloneableon = '';
15777: my $cloneableoff = ' checked="checked"';
15778: if ($filter->{'cloneableonly'}) {
15779: $cloneableon = $cloneableoff;
15780: $cloneableoff = '';
15781: }
15782: $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>';
15783: if ($formname eq 'ccrs') {
1.1187 bisitz 15784: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 15785: } else {
15786: $cloneabletitle = &mt('Cloneable by you');
15787: }
15788: }
15789: my $officialjs;
15790: if ($crstype eq 'Course') {
15791: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 15792: # if (($fixeddom) || ($formname eq 'requestcrs') ||
15793: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
15794: if ($codedom) {
1.1181 raeburn 15795: $officialjs = 1;
15796: ($instcodeform,$jscript,$$numtitlesref) =
15797: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
15798: $officialjs,$codetitlesref);
15799: if ($jscript) {
1.1182 raeburn 15800: $jscript = '<script type="text/javascript">'."\n".
15801: '// <![CDATA['."\n".
15802: $jscript."\n".
15803: '// ]]>'."\n".
15804: '</script>'."\n";
1.1181 raeburn 15805: }
15806: }
15807: if ($instcodeform eq '') {
15808: $instcodeform =
15809: '<input type="text" name="instcodefilter" size="10" value="'.
15810: $list->{'instcodefilter'}.'" />';
15811: $instcodetitle = $lt{'ins'};
15812: } else {
15813: $instcodetitle = $lt{'inc'};
15814: }
15815: if ($fixeddom) {
15816: $instcodetitle .= '<br />('.$codedom.')';
15817: }
15818: }
15819: }
15820: my $output = qq|
15821: <form method="post" name="filterpicker" action="$action">
15822: <input type="hidden" name="form" value="$formname" />
15823: |;
15824: if ($formname eq 'modifycourse') {
15825: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
15826: '<input type="hidden" name="prevphase" value="'.
15827: $prevphase.'" />'."\n";
1.1198 musolffc 15828: } elsif ($formname eq 'quotacheck') {
15829: $output .= qq|
15830: <input type="hidden" name="sortby" value="" />
15831: <input type="hidden" name="sortorder" value="" />
15832: |;
15833: } else {
1.1181 raeburn 15834: my $name_input;
15835: if ($cnameelement ne '') {
15836: $name_input = '<input type="hidden" name="cnameelement" value="'.
15837: $cnameelement.'" />';
15838: }
15839: $output .= qq|
1.1182 raeburn 15840: <input type="hidden" name="cnumelement" value="$cnumelement" />
15841: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 15842: $name_input
15843: $roleelement
15844: $multelement
15845: $typeelement
15846: |;
15847: if ($formname eq 'portform') {
15848: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
15849: }
15850: }
15851: if ($fixeddom) {
15852: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
15853: }
15854: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
15855: if ($sincefilterform) {
15856: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
15857: .$sincefilterform
15858: .&Apache::lonhtmlcommon::row_closure();
15859: }
15860: if ($createdfilterform) {
15861: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
15862: .$createdfilterform
15863: .&Apache::lonhtmlcommon::row_closure();
15864: }
15865: if ($domainselectform) {
15866: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
15867: .$domainselectform
15868: .&Apache::lonhtmlcommon::row_closure();
15869: }
15870: if ($typeselectform) {
15871: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15872: $output .= $typeselectform;
15873: } else {
15874: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
15875: .$typeselectform
15876: .&Apache::lonhtmlcommon::row_closure();
15877: }
15878: }
15879: if ($instcodeform) {
15880: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
15881: .$instcodeform
15882: .&Apache::lonhtmlcommon::row_closure();
15883: }
15884: if (exists($filter->{'ownerfilter'})) {
15885: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
15886: '<table><tr><td>'.&mt('Username').'<br />'.
15887: '<input type="text" name="ownerfilter" size="20" value="'.
15888: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15889: $ownerdomselectform.'</td></tr></table>'.
15890: &Apache::lonhtmlcommon::row_closure();
15891: }
15892: if (exists($filter->{'personfilter'})) {
15893: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
15894: '<table><tr><td>'.&mt('Username').'<br />'.
15895: '<input type="text" name="personfilter" size="20" value="'.
15896: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15897: $persondomselectform.'</td></tr></table>'.
15898: &Apache::lonhtmlcommon::row_closure();
15899: }
15900: if (exists($filter->{'coursefilter'})) {
15901: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
15902: .'<input type="text" name="coursefilter" size="25" value="'
15903: .$list->{'coursefilter'}.'" />'
15904: .&Apache::lonhtmlcommon::row_closure();
15905: }
15906: if ($cloneableonlyform) {
15907: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
15908: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
15909: }
15910: if (exists($filter->{'descriptfilter'})) {
15911: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
15912: .'<input type="text" name="descriptfilter" size="40" value="'
15913: .$list->{'descriptfilter'}.'" />'
15914: .&Apache::lonhtmlcommon::row_closure(1);
15915: }
15916: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
15917: '<input type="hidden" name="updater" value="" />'."\n".
15918: '<input type="submit" name="gosearch" value="'.
15919: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
15920: return $jscript.$clonewarning.$output;
15921: }
15922:
15923: =pod
15924:
15925: =item * &timebased_select_form()
15926:
1.1182 raeburn 15927: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 15928: filter e.g., Course Activity, Course Created, when searching for courses
15929: or communities
15930:
15931: Inputs:
15932:
15933: item - name of form element (sincefilter or createdfilter)
15934:
15935: filter - anonymous hash of criteria and their values
15936:
15937: Returns: HTML for a select box contained a blank, then six time selections,
15938: with value set in incoming form variables currently selected.
15939:
15940: Side Effects: None
15941:
15942: =cut
15943:
15944: sub timebased_select_form {
15945: my ($item,$filter) = @_;
15946: if (ref($filter) eq 'HASH') {
15947: $filter->{$item} =~ s/[^\d-]//g;
15948: if (!$filter->{$item}) { $filter->{$item}=-1; }
15949: return &select_form(
15950: $filter->{$item},
15951: $item,
15952: { '-1' => '',
15953: '86400' => &mt('today'),
15954: '604800' => &mt('last week'),
15955: '2592000' => &mt('last month'),
15956: '7776000' => &mt('last three months'),
15957: '15552000' => &mt('last six months'),
15958: '31104000' => &mt('last year'),
15959: 'select_form_order' =>
15960: ['-1','86400','604800','2592000','7776000',
15961: '15552000','31104000']});
15962: }
15963: }
15964:
15965: =pod
15966:
15967: =item * &js_changer()
15968:
15969: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 15970: when course type or domain is changed, and also to hide 'Searching ...' on
15971: page load completion for page showing search result.
1.1181 raeburn 15972:
15973: Inputs: None
15974:
1.1183 raeburn 15975: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 15976:
15977: Side Effects: None
15978:
15979: =cut
15980:
15981: sub js_changer {
15982: return <<ENDJS;
15983: <script type="text/javascript">
15984: // <![CDATA[
15985: function updateFilters(caller) {
15986: if (typeof(caller) != "undefined") {
15987: document.filterpicker.updater.value = caller.name;
15988: }
15989: document.filterpicker.submit();
15990: }
1.1183 raeburn 15991:
15992: function hideSearching() {
15993: if (document.getElementById('searching')) {
15994: document.getElementById('searching').style.display = 'none';
15995: }
15996: return;
15997: }
15998:
1.1181 raeburn 15999: // ]]>
16000: </script>
16001:
16002: ENDJS
16003: }
16004:
16005: =pod
16006:
1.1182 raeburn 16007: =item * &search_courses()
16008:
16009: Process selected filters form course search form and pass to lonnet::courseiddump
16010: to retrieve a hash for which keys are courseIDs which match the selected filters.
16011:
16012: Inputs:
16013:
16014: dom - domain being searched
16015:
16016: type - course type ('Course' or 'Community' or '.' if any).
16017:
16018: filter - anonymous hash of criteria and their values
16019:
16020: numtitles - for institutional codes - number of categories
16021:
16022: cloneruname - optional username of new course owner
16023:
16024: clonerudom - optional domain of new course owner
16025:
1.1221 raeburn 16026: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 16027: (used when DC is using course creation form)
16028:
16029: codetitles - reference to array of titles of components in institutional codes (official courses).
16030:
1.1221 raeburn 16031: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16032: (and so can clone automatically)
16033:
16034: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16035:
16036: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16037: courses to clone
1.1182 raeburn 16038:
16039: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16040:
16041:
16042: Side Effects: None
16043:
16044: =cut
16045:
16046:
16047: sub search_courses {
1.1221 raeburn 16048: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16049: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 16050: my (%courses,%showcourses,$cloner);
16051: if (($filter->{'ownerfilter'} ne '') ||
16052: ($filter->{'ownerdomfilter'} ne '')) {
16053: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16054: $filter->{'ownerdomfilter'};
16055: }
16056: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16057: if (!$filter->{$item}) {
16058: $filter->{$item}='.';
16059: }
16060: }
16061: my $now = time;
16062: my $timefilter =
16063: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16064: my ($createdbefore,$createdafter);
16065: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16066: $createdbefore = $now;
16067: $createdafter = $now-$filter->{'createdfilter'};
16068: }
16069: my ($instcodefilter,$regexpok);
16070: if ($numtitles) {
16071: if ($env{'form.official'} eq 'on') {
16072: $instcodefilter =
16073: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16074: $regexpok = 1;
16075: } elsif ($env{'form.official'} eq 'off') {
16076: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16077: unless ($instcodefilter eq '') {
16078: $regexpok = -1;
16079: }
16080: }
16081: } else {
16082: $instcodefilter = $filter->{'instcodefilter'};
16083: }
16084: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16085: if ($type eq '') { $type = '.'; }
16086:
16087: if (($clonerudom ne '') && ($cloneruname ne '')) {
16088: $cloner = $cloneruname.':'.$clonerudom;
16089: }
16090: %courses = &Apache::lonnet::courseiddump($dom,
16091: $filter->{'descriptfilter'},
16092: $timefilter,
16093: $instcodefilter,
16094: $filter->{'combownerfilter'},
16095: $filter->{'coursefilter'},
16096: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 16097: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 16098: $filter->{'cloneableonly'},
16099: $createdbefore,$createdafter,undef,
1.1221 raeburn 16100: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 16101: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16102: my $ccrole;
16103: if ($type eq 'Community') {
16104: $ccrole = 'co';
16105: } else {
16106: $ccrole = 'cc';
16107: }
16108: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16109: $filter->{'persondomfilter'},
16110: 'userroles',undef,
16111: [$ccrole,'in','ad','ep','ta','cr'],
16112: $dom);
16113: foreach my $role (keys(%rolehash)) {
16114: my ($cnum,$cdom,$courserole) = split(':',$role);
16115: my $cid = $cdom.'_'.$cnum;
16116: if (exists($courses{$cid})) {
16117: if (ref($courses{$cid}) eq 'HASH') {
16118: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16119: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
16120: push (@{$courses{$cid}{roles}},$courserole);
16121: }
16122: } else {
16123: $courses{$cid}{roles} = [$courserole];
16124: }
16125: $showcourses{$cid} = $courses{$cid};
16126: }
16127: }
16128: }
16129: %courses = %showcourses;
16130: }
16131: return %courses;
16132: }
16133:
16134: =pod
16135:
1.1181 raeburn 16136: =back
16137:
1.1207 raeburn 16138: =head1 Routines for version requirements for current course.
16139:
16140: =over 4
16141:
16142: =item * &check_release_required()
16143:
16144: Compares required LON-CAPA version with version on server, and
16145: if required version is newer looks for a server with the required version.
16146:
16147: Looks first at servers in user's owen domain; if none suitable, looks at
16148: servers in course's domain are permitted to host sessions for user's domain.
16149:
16150: Inputs:
16151:
16152: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16153:
16154: $courseid - Course ID of current course
16155:
16156: $rolecode - User's current role in course (for switchserver query string).
16157:
16158: $required - LON-CAPA version needed by course (format: Major.Minor).
16159:
16160:
16161: Returns:
16162:
16163: $switchserver - query string tp append to /adm/switchserver call (if
16164: current server's LON-CAPA version is too old.
16165:
16166: $warning - Message is displayed if no suitable server could be found.
16167:
16168: =cut
16169:
16170: sub check_release_required {
16171: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16172: my ($switchserver,$warning);
16173: if ($required ne '') {
16174: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16175: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16176: if ($reqdmajor ne '' && $reqdminor ne '') {
16177: my $otherserver;
16178: if (($major eq '' && $minor eq '') ||
16179: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16180: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16181: my $switchlcrev =
16182: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16183: $userdomserver);
16184: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16185: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16186: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16187: my $cdom = $env{'course.'.$courseid.'.domain'};
16188: if ($cdom ne $env{'user.domain'}) {
16189: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16190: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16191: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16192: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16193: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16194: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16195: my $canhost =
16196: &Apache::lonnet::can_host_session($env{'user.domain'},
16197: $coursedomserver,
16198: $remoterev,
16199: $udomdefaults{'remotesessions'},
16200: $defdomdefaults{'hostedsessions'});
16201:
16202: if ($canhost) {
16203: $otherserver = $coursedomserver;
16204: } else {
16205: $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.");
16206: }
16207: } else {
16208: $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).");
16209: }
16210: } else {
16211: $otherserver = $userdomserver;
16212: }
16213: }
16214: if ($otherserver ne '') {
16215: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16216: }
16217: }
16218: }
16219: return ($switchserver,$warning);
16220: }
16221:
16222: =pod
16223:
16224: =item * &check_release_result()
16225:
16226: Inputs:
16227:
16228: $switchwarning - Warning message if no suitable server found to host session.
16229:
16230: $switchserver - query string to append to /adm/switchserver containing lonHostID
16231: and current role.
16232:
16233: Returns: HTML to display with information about requirement to switch server.
16234: Either displaying warning with link to Roles/Courses screen or
16235: display link to switchserver.
16236:
1.1181 raeburn 16237: =cut
16238:
1.1207 raeburn 16239: sub check_release_result {
16240: my ($switchwarning,$switchserver) = @_;
16241: my $output = &start_page('Selected course unavailable on this server').
16242: '<p class="LC_warning">';
16243: if ($switchwarning) {
16244: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16245: if (&show_course()) {
16246: $output .= &mt('Display courses');
16247: } else {
16248: $output .= &mt('Display roles');
16249: }
16250: $output .= '</a>';
16251: } elsif ($switchserver) {
16252: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16253: '<br />'.
16254: '<a href="/adm/switchserver?'.$switchserver.'">'.
16255: &mt('Switch Server').
16256: '</a>';
16257: }
16258: $output .= '</p>'.&end_page();
16259: return $output;
16260: }
16261:
16262: =pod
16263:
16264: =item * &needs_coursereinit()
16265:
16266: Determine if course contents stored for user's session needs to be
16267: refreshed, because content has changed since "Big Hash" last tied.
16268:
16269: Check for change is made if time last checked is more than 10 minutes ago
16270: (by default).
16271:
16272: Inputs:
16273:
16274: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16275:
16276: $interval (optional) - Time which may elapse (in s) between last check for content
16277: change in current course. (default: 600 s).
16278:
16279: Returns: an array; first element is:
16280:
16281: =over 4
16282:
16283: 'switch' - if content updates mean user's session
16284: needs to be switched to a server running a newer LON-CAPA version
16285:
16286: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16287: on current server hosting user's session
16288:
16289: '' - if no action required.
16290:
16291: =back
16292:
16293: If first item element is 'switch':
16294:
16295: second item is $switchwarning - Warning message if no suitable server found to host session.
16296:
16297: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16298: and current role.
16299:
16300: otherwise: no other elements returned.
16301:
16302: =back
16303:
16304: =cut
16305:
16306: sub needs_coursereinit {
16307: my ($loncaparev,$interval) = @_;
16308: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16309: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16310: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16311: my $now = time;
16312: if ($interval eq '') {
16313: $interval = 600;
16314: }
16315: if (($now-$env{'request.course.timechecked'})>$interval) {
16316: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16317: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16318: if ($lastchange > $env{'request.course.tied'}) {
16319: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16320: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16321: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16322: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16323: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16324: $curr_reqd_hash{'internal.releaserequired'}});
16325: my ($switchserver,$switchwarning) =
16326: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16327: $curr_reqd_hash{'internal.releaserequired'});
16328: if ($switchwarning ne '' || $switchserver ne '') {
16329: return ('switch',$switchwarning,$switchserver);
16330: }
16331: }
16332: }
16333: return ('update');
16334: }
16335: }
16336: return ();
16337: }
1.1181 raeburn 16338:
1.1083 raeburn 16339: sub update_content_constraints {
16340: my ($cdom,$cnum,$chome,$cid) = @_;
16341: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16342: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16343: my %checkresponsetypes;
16344: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1219 raeburn 16345: my ($item,$name,$value,$valmatch) = split(/:/,$key);
1.1083 raeburn 16346: if ($item eq 'resourcetag') {
16347: if ($name eq 'responsetype') {
16348: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16349: }
16350: }
16351: }
16352: my $navmap = Apache::lonnavmaps::navmap->new();
16353: if (defined($navmap)) {
16354: my %allresponses;
16355: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16356: my %responses = $res->responseTypes();
16357: foreach my $key (keys(%responses)) {
16358: next unless(exists($checkresponsetypes{$key}));
16359: $allresponses{$key} += $responses{$key};
16360: }
16361: }
16362: foreach my $key (keys(%allresponses)) {
16363: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16364: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16365: ($reqdmajor,$reqdminor) = ($major,$minor);
16366: }
16367: }
16368: undef($navmap);
16369: }
16370: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16371: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16372: }
16373: return;
16374: }
16375:
1.1110 raeburn 16376: sub allmaps_incourse {
16377: my ($cdom,$cnum,$chome,$cid) = @_;
16378: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16379: $cid = $env{'request.course.id'};
16380: $cdom = $env{'course.'.$cid.'.domain'};
16381: $cnum = $env{'course.'.$cid.'.num'};
16382: $chome = $env{'course.'.$cid.'.home'};
16383: }
16384: my %allmaps = ();
16385: my $lastchange =
16386: &Apache::lonnet::get_coursechange($cdom,$cnum);
16387: if ($lastchange > $env{'request.course.tied'}) {
16388: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16389: unless ($ferr) {
16390: &update_content_constraints($cdom,$cnum,$chome,$cid);
16391: }
16392: }
16393: my $navmap = Apache::lonnavmaps::navmap->new();
16394: if (defined($navmap)) {
16395: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16396: $allmaps{$res->src()} = 1;
16397: }
16398: }
16399: return \%allmaps;
16400: }
16401:
1.1083 raeburn 16402: sub parse_supplemental_title {
16403: my ($title) = @_;
16404:
16405: my ($foldertitle,$renametitle);
16406: if ($title =~ /&&&/) {
16407: $title = &HTML::Entites::decode($title);
16408: }
16409: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16410: $renametitle=$4;
16411: my ($time,$uname,$udom) = ($1,$2,$3);
16412: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16413: my $name = &plainname($uname,$udom);
16414: $name = &HTML::Entities::encode($name,'"<>&\'');
16415: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16416: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16417: $name.': <br />'.$foldertitle;
16418: }
16419: if (wantarray) {
16420: return ($title,$foldertitle,$renametitle);
16421: }
16422: return $title;
16423: }
16424:
1.1143 raeburn 16425: sub recurse_supplemental {
16426: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16427: if ($suppmap) {
16428: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16429: if ($fatal) {
16430: $errors ++;
16431: } else {
16432: if ($#LONCAPA::map::resources > 0) {
16433: foreach my $res (@LONCAPA::map::resources) {
16434: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16435: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 16436: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16437: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1143 raeburn 16438: } else {
16439: $numfiles ++;
16440: }
16441: }
16442: }
16443: }
16444: }
16445: }
16446: return ($numfiles,$errors);
16447: }
16448:
1.1101 raeburn 16449: sub symb_to_docspath {
16450: my ($symb) = @_;
16451: return unless ($symb);
16452: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16453: if ($resurl=~/\.(sequence|page)$/) {
16454: $mapurl=$resurl;
16455: } elsif ($resurl eq 'adm/navmaps') {
16456: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
16457: }
16458: my $mapresobj;
16459: my $navmap = Apache::lonnavmaps::navmap->new();
16460: if (ref($navmap)) {
16461: $mapresobj = $navmap->getResourceByUrl($mapurl);
16462: }
16463: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
16464: my $type=$2;
16465: my $path;
16466: if (ref($mapresobj)) {
16467: my $pcslist = $mapresobj->map_hierarchy();
16468: if ($pcslist ne '') {
16469: foreach my $pc (split(/,/,$pcslist)) {
16470: next if ($pc <= 1);
16471: my $res = $navmap->getByMapPc($pc);
16472: if (ref($res)) {
16473: my $thisurl = $res->src();
16474: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
16475: my $thistitle = $res->title();
16476: $path .= '&'.
16477: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 16478: &escape($thistitle).
1.1101 raeburn 16479: ':'.$res->randompick().
16480: ':'.$res->randomout().
16481: ':'.$res->encrypted().
16482: ':'.$res->randomorder().
16483: ':'.$res->is_page();
16484: }
16485: }
16486: }
16487: $path =~ s/^\&//;
16488: my $maptitle = $mapresobj->title();
16489: if ($mapurl eq 'default') {
1.1129 raeburn 16490: $maptitle = 'Main Content';
1.1101 raeburn 16491: }
16492: $path .= (($path ne '')? '&' : '').
16493: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 16494: &escape($maptitle).
1.1101 raeburn 16495: ':'.$mapresobj->randompick().
16496: ':'.$mapresobj->randomout().
16497: ':'.$mapresobj->encrypted().
16498: ':'.$mapresobj->randomorder().
16499: ':'.$mapresobj->is_page();
16500: } else {
16501: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16502: my $ispage = (($type eq 'page')? 1 : '');
16503: if ($mapurl eq 'default') {
1.1129 raeburn 16504: $maptitle = 'Main Content';
1.1101 raeburn 16505: }
16506: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 16507: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 16508: }
16509: unless ($mapurl eq 'default') {
16510: $path = 'default&'.
1.1146 raeburn 16511: &escape('Main Content').
1.1101 raeburn 16512: ':::::&'.$path;
16513: }
16514: return $path;
16515: }
16516:
1.1094 raeburn 16517: sub captcha_display {
16518: my ($context,$lonhost) = @_;
16519: my ($output,$error);
16520: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 16521: if ($captcha eq 'original') {
1.1094 raeburn 16522: $output = &create_captcha();
16523: unless ($output) {
1.1172 raeburn 16524: $error = 'captcha';
1.1094 raeburn 16525: }
16526: } elsif ($captcha eq 'recaptcha') {
16527: $output = &create_recaptcha($pubkey);
16528: unless ($output) {
1.1172 raeburn 16529: $error = 'recaptcha';
1.1094 raeburn 16530: }
16531: }
1.1176 raeburn 16532: return ($output,$error,$captcha);
1.1094 raeburn 16533: }
16534:
16535: sub captcha_response {
16536: my ($context,$lonhost) = @_;
16537: my ($captcha_chk,$captcha_error);
16538: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 16539: if ($captcha eq 'original') {
1.1094 raeburn 16540: ($captcha_chk,$captcha_error) = &check_captcha();
16541: } elsif ($captcha eq 'recaptcha') {
16542: $captcha_chk = &check_recaptcha($privkey);
16543: } else {
16544: $captcha_chk = 1;
16545: }
16546: return ($captcha_chk,$captcha_error);
16547: }
16548:
16549: sub get_captcha_config {
16550: my ($context,$lonhost) = @_;
1.1095 raeburn 16551: my ($captcha,$pubkey,$privkey,$hashtocheck);
1.1094 raeburn 16552: my $hostname = &Apache::lonnet::hostname($lonhost);
16553: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
16554: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 16555: if ($context eq 'usercreation') {
16556: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
16557: if (ref($domconfig{$context}) eq 'HASH') {
16558: $hashtocheck = $domconfig{$context}{'cancreate'};
16559: if (ref($hashtocheck) eq 'HASH') {
16560: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
16561: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
16562: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
16563: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
16564: }
16565: if ($privkey && $pubkey) {
16566: $captcha = 'recaptcha';
16567: } else {
16568: $captcha = 'original';
16569: }
16570: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
16571: $captcha = 'original';
16572: }
1.1094 raeburn 16573: }
1.1095 raeburn 16574: } else {
16575: $captcha = 'captcha';
16576: }
16577: } elsif ($context eq 'login') {
16578: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
16579: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
16580: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
16581: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 16582: if ($privkey && $pubkey) {
16583: $captcha = 'recaptcha';
1.1095 raeburn 16584: } else {
16585: $captcha = 'original';
1.1094 raeburn 16586: }
1.1095 raeburn 16587: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
16588: $captcha = 'original';
1.1094 raeburn 16589: }
16590: }
16591: return ($captcha,$pubkey,$privkey);
16592: }
16593:
16594: sub create_captcha {
16595: my %captcha_params = &captcha_settings();
16596: my ($output,$maxtries,$tries) = ('',10,0);
16597: while ($tries < $maxtries) {
16598: $tries ++;
16599: my $captcha = Authen::Captcha->new (
16600: output_folder => $captcha_params{'output_dir'},
16601: data_folder => $captcha_params{'db_dir'},
16602: );
16603: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
16604:
16605: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
16606: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
16607: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 16608: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
16609: '<br />'.
16610: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 16611: last;
16612: }
16613: }
16614: return $output;
16615: }
16616:
16617: sub captcha_settings {
16618: my %captcha_params = (
16619: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
16620: www_output_dir => "/captchaspool",
16621: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
16622: numchars => '5',
16623: );
16624: return %captcha_params;
16625: }
16626:
16627: sub check_captcha {
16628: my ($captcha_chk,$captcha_error);
16629: my $code = $env{'form.code'};
16630: my $md5sum = $env{'form.crypt'};
16631: my %captcha_params = &captcha_settings();
16632: my $captcha = Authen::Captcha->new(
16633: output_folder => $captcha_params{'output_dir'},
16634: data_folder => $captcha_params{'db_dir'},
16635: );
1.1109 raeburn 16636: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 16637: my %captcha_hash = (
16638: 0 => 'Code not checked (file error)',
16639: -1 => 'Failed: code expired',
16640: -2 => 'Failed: invalid code (not in database)',
16641: -3 => 'Failed: invalid code (code does not match crypt)',
16642: );
16643: if ($captcha_chk != 1) {
16644: $captcha_error = $captcha_hash{$captcha_chk}
16645: }
16646: return ($captcha_chk,$captcha_error);
16647: }
16648:
16649: sub create_recaptcha {
16650: my ($pubkey) = @_;
1.1153 raeburn 16651: my $use_ssl;
16652: if ($ENV{'SERVER_PORT'} == 443) {
16653: $use_ssl = 1;
16654: }
1.1094 raeburn 16655: my $captcha = Captcha::reCAPTCHA->new;
16656: return $captcha->get_options_setter({theme => 'white'})."\n".
1.1153 raeburn 16657: $captcha->get_html($pubkey,undef,$use_ssl).
1.1213 raeburn 16658: &mt('If the text is hard to read, [_1] will replace them.',
1.1133 raeburn 16659: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1094 raeburn 16660: '<br /><br />';
16661: }
16662:
16663: sub check_recaptcha {
16664: my ($privkey) = @_;
16665: my $captcha_chk;
16666: my $captcha = Captcha::reCAPTCHA->new;
16667: my $captcha_result =
16668: $captcha->check_answer(
16669: $privkey,
16670: $ENV{'REMOTE_ADDR'},
16671: $env{'form.recaptcha_challenge_field'},
16672: $env{'form.recaptcha_response_field'},
16673: );
16674: if ($captcha_result->{is_valid}) {
16675: $captcha_chk = 1;
16676: }
16677: return $captcha_chk;
16678: }
16679:
1.1174 raeburn 16680: sub emailusername_info {
1.1177 raeburn 16681: my @fields = ('firstname','lastname','institution','web','location','officialemail');
1.1174 raeburn 16682: my %titles = &Apache::lonlocal::texthash (
16683: lastname => 'Last Name',
16684: firstname => 'First Name',
16685: institution => 'School/college/university',
16686: location => "School's city, state/province, country",
16687: web => "School's web address",
16688: officialemail => 'E-mail address at institution (if different)',
16689: );
16690: return (\@fields,\%titles);
16691: }
16692:
1.1161 raeburn 16693: sub cleanup_html {
16694: my ($incoming) = @_;
16695: my $outgoing;
16696: if ($incoming ne '') {
16697: $outgoing = $incoming;
16698: $outgoing =~ s/;/;/g;
16699: $outgoing =~ s/\#/#/g;
16700: $outgoing =~ s/\&/&/g;
16701: $outgoing =~ s/</</g;
16702: $outgoing =~ s/>/>/g;
16703: $outgoing =~ s/\(/(/g;
16704: $outgoing =~ s/\)/)/g;
16705: $outgoing =~ s/"/"/g;
16706: $outgoing =~ s/'/'/g;
16707: $outgoing =~ s/\$/$/g;
16708: $outgoing =~ s{/}{/}g;
16709: $outgoing =~ s/=/=/g;
16710: $outgoing =~ s/\\/\/g
16711: }
16712: return $outgoing;
16713: }
16714:
1.1190 musolffc 16715: # Checks for critical messages and returns a redirect url if one exists.
16716: # $interval indicates how often to check for messages.
16717: sub critical_redirect {
16718: my ($interval) = @_;
16719: if ((time-$env{'user.criticalcheck.time'})>$interval) {
16720: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
16721: $env{'user.name'});
16722: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 16723: my $redirecturl;
1.1190 musolffc 16724: if ($what[0]) {
16725: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
16726: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 16727: my $url=&Apache::lonnet::absolute_url().$redirecturl;
16728: return (1, $url);
1.1190 musolffc 16729: }
1.1191 raeburn 16730: }
16731: }
16732: return ();
1.1190 musolffc 16733: }
16734:
1.1174 raeburn 16735: # Use:
16736: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
16737: #
16738: ##################################################
16739: # password associated functions #
16740: ##################################################
16741: sub des_keys {
16742: # Make a new key for DES encryption.
16743: # Each key has two parts which are returned separately.
16744: # Please note: Each key must be passed through the &hex function
16745: # before it is output to the web browser. The hex versions cannot
16746: # be used to decrypt.
16747: my @hexstr=('0','1','2','3','4','5','6','7',
16748: '8','9','a','b','c','d','e','f');
16749: my $lkey='';
16750: for (0..7) {
16751: $lkey.=$hexstr[rand(15)];
16752: }
16753: my $ukey='';
16754: for (0..7) {
16755: $ukey.=$hexstr[rand(15)];
16756: }
16757: return ($lkey,$ukey);
16758: }
16759:
16760: sub des_decrypt {
16761: my ($key,$cyphertext) = @_;
16762: my $keybin=pack("H16",$key);
16763: my $cypher;
16764: if ($Crypt::DES::VERSION>=2.03) {
16765: $cypher=new Crypt::DES $keybin;
16766: } else {
16767: $cypher=new DES $keybin;
16768: }
16769: my $plaintext=
16770: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
16771: $plaintext.=
16772: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
16773: $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
16774: return $plaintext;
16775: }
16776:
1.112 bowersj2 16777: 1;
16778: __END__;
1.41 ng 16779:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>