Annotation of loncom/interface/loncommon.pm, revision 1.1360
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1360 ! raeburn 4: # $Id: loncommon.pm,v 1.1359 2021/06/07 03:32:02 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1108 raeburn 70: use Apache::lonuserutils();
1.1110 raeburn 71: use Apache::lonuserstate();
1.1182 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.1280 raeburn 74: use LONCAPA::LWPReq;
1.1328 raeburn 75: use HTTP::Request;
1.657 raeburn 76: use DateTime::TimeZone;
1.1241 raeburn 77: use DateTime::Locale;
1.1220 raeburn 78: use Encode();
1.1091 foxr 79: use Text::Aspell;
1.1094 raeburn 80: use Authen::Captcha;
81: use Captcha::reCAPTCHA;
1.1234 raeburn 82: use JSON::DWIW;
1.1174 raeburn 83: use Crypt::DES;
84: use DynaLoader; # for Crypt::DES version
1.1223 musolffc 85: use MIME::Lite;
86: use MIME::Types;
1.1292 raeburn 87: use File::Copy();
1.1300 raeburn 88: use File::Path();
1.1309 raeburn 89: use String::CRC32();
90: use Short::URL();
1.117 www 91:
1.517 raeburn 92: # ---------------------------------------------- Designs
93: use vars qw(%defaultdesign);
94:
1.22 www 95: my $readit;
96:
1.517 raeburn 97:
1.157 matthew 98: ##
99: ## Global Variables
100: ##
1.46 matthew 101:
1.643 foxr 102:
103: # ----------------------------------------------- SSI with retries:
104: #
105:
106: =pod
107:
1.648 raeburn 108: =head1 Server Side include with retries:
1.643 foxr 109:
110: =over 4
111:
1.648 raeburn 112: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 113:
114: Performs an ssi with some number of retries. Retries continue either
115: until the result is ok or until the retry count supplied by the
116: caller is exhausted.
117:
118: Inputs:
1.648 raeburn 119:
120: =over 4
121:
1.643 foxr 122: resource - Identifies the resource to insert.
1.648 raeburn 123:
1.643 foxr 124: retries - Count of the number of retries allowed.
1.648 raeburn 125:
1.643 foxr 126: form - Hash that identifies the rendering options.
127:
1.648 raeburn 128: =back
129:
130: Returns:
131:
132: =over 4
133:
1.643 foxr 134: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 135:
1.643 foxr 136: response - The response from the last attempt (which may or may not have been successful.
137:
1.648 raeburn 138: =back
139:
140: =back
141:
1.643 foxr 142: =cut
143:
144: sub ssi_with_retries {
145: my ($resource, $retries, %form) = @_;
146:
147:
148: my $ok = 0; # True if we got a good response.
149: my $content;
150: my $response;
151:
152: # Try to get the ssi done. within the retries count:
153:
154: do {
155: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
156: $ok = $response->is_success;
1.650 www 157: if (!$ok) {
158: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
159: }
1.643 foxr 160: $retries--;
161: } while (!$ok && ($retries > 0));
162:
163: if (!$ok) {
164: $content = ''; # On error return an empty content.
165: }
166: return ($content, $response);
167:
168: }
169:
170:
171:
1.20 www 172: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 173: my %language;
1.124 www 174: my %supported_language;
1.1088 foxr 175: my %supported_codes;
1.1048 foxr 176: my %latex_language; # For choosing hyphenation in <transl..>
177: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 178: my %cprtag;
1.192 taceyjo1 179: my %scprtag;
1.351 www 180: my %fe; my %fd; my %fm;
1.41 ng 181: my %category_extensions;
1.12 harris41 182:
1.46 matthew 183: # ---------------------------------------------- Thesaurus variables
1.144 matthew 184: #
185: # %Keywords:
186: # A hash used by &keyword to determine if a word is considered a keyword.
187: # $thesaurus_db_file
188: # Scalar containing the full path to the thesaurus database.
1.46 matthew 189:
190: my %Keywords;
191: my $thesaurus_db_file;
192:
1.144 matthew 193: #
194: # Initialize values from language.tab, copyright.tab, filetypes.tab,
195: # thesaurus.tab, and filecategories.tab.
196: #
1.18 www 197: BEGIN {
1.46 matthew 198: # Variable initialization
199: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
200: #
1.22 www 201: unless ($readit) {
1.12 harris41 202: # ------------------------------------------------------------------- languages
203: {
1.158 raeburn 204: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
205: '/language.tab';
1.1317 raeburn 206: if ( open(my $fh,'<',$langtabfile) ) {
1.356 albertel 207: while (my $line = <$fh>) {
208: next if ($line=~/^\#/);
209: chomp($line);
1.1088 foxr 210: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 211: $language{$key}=$val.' - '.$enc;
212: if ($sup) {
213: $supported_language{$key}=$sup;
1.1088 foxr 214: $supported_codes{$key} = $code;
1.158 raeburn 215: }
1.1048 foxr 216: if ($latex) {
217: $latex_language_bykey{$key} = $latex;
1.1088 foxr 218: $latex_language{$code} = $latex;
1.1048 foxr 219: }
1.158 raeburn 220: }
221: close($fh);
222: }
1.12 harris41 223: }
224: # ------------------------------------------------------------------ copyrights
225: {
1.158 raeburn 226: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
227: '/copyright.tab';
1.1317 raeburn 228: if ( open (my $fh,'<',$copyrightfile) ) {
1.356 albertel 229: while (my $line = <$fh>) {
230: next if ($line=~/^\#/);
231: chomp($line);
232: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 233: $cprtag{$key}=$val;
234: }
235: close($fh);
236: }
1.12 harris41 237: }
1.351 www 238: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 239: {
240: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
241: '/source_copyright.tab';
1.1317 raeburn 242: if ( open (my $fh,'<',$sourcecopyrightfile) ) {
1.356 albertel 243: while (my $line = <$fh>) {
244: next if ($line =~ /^\#/);
245: chomp($line);
246: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 247: $scprtag{$key}=$val;
248: }
249: close($fh);
250: }
251: }
1.63 www 252:
1.517 raeburn 253: # -------------------------------------------------------------- default domain designs
1.63 www 254: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 255: my $designfile = $designdir.'/default.tab';
1.1317 raeburn 256: if ( open (my $fh,'<',$designfile) ) {
1.517 raeburn 257: while (my $line = <$fh>) {
258: next if ($line =~ /^\#/);
259: chomp($line);
260: my ($key,$val)=(split(/\=/,$line));
261: if ($val) { $defaultdesign{$key}=$val; }
262: }
263: close($fh);
1.63 www 264: }
265:
1.15 harris41 266: # ------------------------------------------------------------- file categories
267: {
1.158 raeburn 268: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
269: '/filecategories.tab';
1.1317 raeburn 270: if ( open (my $fh,'<',$categoryfile) ) {
1.356 albertel 271: while (my $line = <$fh>) {
272: next if ($line =~ /^\#/);
273: chomp($line);
274: my ($extension,$category)=(split(/\s+/,$line,2));
1.1263 raeburn 275: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 276: }
277: close($fh);
278: }
279:
1.15 harris41 280: }
1.12 harris41 281: # ------------------------------------------------------------------ file types
282: {
1.158 raeburn 283: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
284: '/filetypes.tab';
1.1317 raeburn 285: if ( open (my $fh,'<',$typesfile) ) {
1.356 albertel 286: while (my $line = <$fh>) {
287: next if ($line =~ /^\#/);
288: chomp($line);
289: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 290: if ($descr ne '') {
291: $fe{$ending}=lc($emb);
292: $fd{$ending}=$descr;
1.351 www 293: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 294: }
295: }
296: close($fh);
297: }
1.12 harris41 298: }
1.22 www 299: &Apache::lonnet::logthis(
1.705 tempelho 300: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 301: $readit=1;
1.46 matthew 302: } # end of unless($readit)
1.32 matthew 303:
304: }
1.112 bowersj2 305:
1.42 matthew 306: ###############################################################
307: ## HTML and Javascript Helper Functions ##
308: ###############################################################
309:
310: =pod
311:
1.112 bowersj2 312: =head1 HTML and Javascript Functions
1.42 matthew 313:
1.112 bowersj2 314: =over 4
315:
1.648 raeburn 316: =item * &browser_and_searcher_javascript()
1.112 bowersj2 317:
318: X<browsing, javascript>X<searching, javascript>Returns a string
319: containing javascript with two functions, C<openbrowser> and
320: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
321: tags.
1.42 matthew 322:
1.648 raeburn 323: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 324:
325: inputs: formname, elementname, only, omit
326:
327: formname and elementname indicate the name of the html form and name of
328: the element that the results of the browsing selection are to be placed in.
329:
330: Specifying 'only' will restrict the browser to displaying only files
1.185 www 331: with the given extension. Can be a comma separated list.
1.42 matthew 332:
333: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 334: with the given extension. Can be a comma separated list.
1.42 matthew 335:
1.648 raeburn 336: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 337:
338: Inputs: formname, elementname
339:
340: formname and elementname specify the name of the html form and the name
341: of the element the selection from the search results will be placed in.
1.542 raeburn 342:
1.42 matthew 343: =cut
344:
345: sub browser_and_searcher_javascript {
1.199 albertel 346: my ($mode)=@_;
347: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 348: my $resurl=&escape_single(&lastresurl());
1.42 matthew 349: return <<END;
1.219 albertel 350: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 351: var editbrowser = null;
1.135 albertel 352: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 353: var url = '$resurl/?';
1.42 matthew 354: if (editbrowser == null) {
355: url += 'launch=1&';
356: }
357: url += 'catalogmode=interactive&';
1.199 albertel 358: url += 'mode=$mode&';
1.611 albertel 359: url += 'inhibitmenu=yes&';
1.42 matthew 360: url += 'form=' + formname + '&';
361: if (only != null) {
362: url += 'only=' + only + '&';
1.217 albertel 363: } else {
364: url += 'only=&';
365: }
1.42 matthew 366: if (omit != null) {
367: url += 'omit=' + omit + '&';
1.217 albertel 368: } else {
369: url += 'omit=&';
370: }
1.135 albertel 371: if (titleelement != null) {
372: url += 'titleelement=' + titleelement + '&';
1.217 albertel 373: } else {
374: url += 'titleelement=&';
375: }
1.42 matthew 376: url += 'element=' + elementname + '';
377: var title = 'Browser';
1.435 albertel 378: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 379: options += ',width=700,height=600';
380: editbrowser = open(url,title,options,'1');
381: editbrowser.focus();
382: }
383: var editsearcher;
1.135 albertel 384: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 385: var url = '/adm/searchcat?';
386: if (editsearcher == null) {
387: url += 'launch=1&';
388: }
389: url += 'catalogmode=interactive&';
1.199 albertel 390: url += 'mode=$mode&';
1.42 matthew 391: url += 'form=' + formname + '&';
1.135 albertel 392: if (titleelement != null) {
393: url += 'titleelement=' + titleelement + '&';
1.217 albertel 394: } else {
395: url += 'titleelement=&';
396: }
1.42 matthew 397: url += 'element=' + elementname + '';
398: var title = 'Search';
1.435 albertel 399: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 400: options += ',width=700,height=600';
401: editsearcher = open(url,title,options,'1');
402: editsearcher.focus();
403: }
1.219 albertel 404: // END LON-CAPA Internal -->
1.42 matthew 405: END
1.170 www 406: }
407:
408: sub lastresurl {
1.258 albertel 409: if ($env{'environment.lastresurl'}) {
410: return $env{'environment.lastresurl'}
1.170 www 411: } else {
412: return '/res';
413: }
414: }
415:
416: sub storeresurl {
417: my $resurl=&Apache::lonnet::clutter(shift);
418: unless ($resurl=~/^\/res/) { return 0; }
419: $resurl=~s/\/$//;
420: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 421: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 422: return 1;
1.42 matthew 423: }
424:
1.74 www 425: sub studentbrowser_javascript {
1.111 www 426: unless (
1.258 albertel 427: (($env{'request.course.id'}) &&
1.302 albertel 428: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
429: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
430: '/'.$env{'request.course.sec'})
431: ))
1.258 albertel 432: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 433: ) { return ''; }
1.74 www 434: return (<<'ENDSTDBRW');
1.776 bisitz 435: <script type="text/javascript" language="Javascript">
1.824 bisitz 436: // <![CDATA[
1.74 www 437: var stdeditbrowser;
1.1337 raeburn 438: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadv) {
1.74 www 439: var url = '/adm/pickstudent?';
440: var filter;
1.558 albertel 441: if (!ignorefilter) {
442: eval('filter=document.'+formname+'.'+uname+'.value;');
443: }
1.74 www 444: if (filter != null) {
445: if (filter != '') {
446: url += 'filter='+filter+'&';
447: }
448: }
449: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 450: '&udomelement='+udom+
451: '&clicker='+clicker;
1.111 www 452: if (roleflag) { url+="&roles=1"; }
1.1337 raeburn 453: if (courseadv == 'condition') {
454: if (document.getElementById('courseadv')) {
455: courseadv = document.getElementById('courseadv').value;
456: }
457: }
458: if ((courseadv == 'only') || (courseadv == 'none')) { url+="&courseadv="+courseadv; }
1.102 www 459: var title = 'Student_Browser';
1.74 www 460: var options = 'scrollbars=1,resizable=1,menubar=0';
461: options += ',width=700,height=600';
462: stdeditbrowser = open(url,title,options,'1');
463: stdeditbrowser.focus();
464: }
1.824 bisitz 465: // ]]>
1.74 www 466: </script>
467: ENDSTDBRW
468: }
1.42 matthew 469:
1.1003 www 470: sub resourcebrowser_javascript {
471: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 472: return (<<'ENDRESBRW');
1.1003 www 473: <script type="text/javascript" language="Javascript">
474: // <![CDATA[
475: var reseditbrowser;
1.1004 www 476: function openresbrowser(formname,reslink) {
1.1005 www 477: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 478: var title = 'Resource_Browser';
479: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 480: options += ',width=700,height=500';
1.1004 www 481: reseditbrowser = open(url,title,options,'1');
482: reseditbrowser.focus();
1.1003 www 483: }
484: // ]]>
485: </script>
1.1004 www 486: ENDRESBRW
1.1003 www 487: }
488:
1.74 www 489: sub selectstudent_link {
1.1337 raeburn 490: my ($form,$unameele,$udomele,$courseadv,$clickerid)=@_;
1.999 www 491: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
492: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
493: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 494: if ($env{'request.course.id'}) {
1.302 albertel 495: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
496: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
497: '/'.$env{'request.course.sec'})) {
1.111 www 498: return '';
499: }
1.999 www 500: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.1337 raeburn 501: if ($courseadv eq 'only') {
502: $callargs .= ",'',1,'$courseadv'";
503: } elsif ($courseadv eq 'none') {
504: $callargs .= ",'','','$courseadv'";
505: } elsif ($courseadv eq 'condition') {
506: $callargs .= ",'','','$courseadv'";
1.793 raeburn 507: }
508: return '<span class="LC_nobreak">'.
509: '<a href="javascript:openstdbrowser('.$callargs.');">'.
510: &mt('Select User').'</a></span>';
1.74 www 511: }
1.258 albertel 512: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 513: $callargs .= ",'',1";
1.793 raeburn 514: return '<span class="LC_nobreak">'.
515: '<a href="javascript:openstdbrowser('.$callargs.');">'.
516: &mt('Select User').'</a></span>';
1.111 www 517: }
518: return '';
1.91 www 519: }
520:
1.1004 www 521: sub selectresource_link {
522: my ($form,$reslink,$arg)=@_;
523:
524: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
525: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
526: unless ($env{'request.course.id'}) { return $arg; }
527: return '<span class="LC_nobreak">'.
528: '<a href="javascript:openresbrowser('.$callargs.');">'.
529: $arg.'</a></span>';
530: }
531:
532:
533:
1.653 raeburn 534: sub authorbrowser_javascript {
535: return <<"ENDAUTHORBRW";
1.776 bisitz 536: <script type="text/javascript" language="JavaScript">
1.824 bisitz 537: // <![CDATA[
1.653 raeburn 538: var stdeditbrowser;
539:
540: function openauthorbrowser(formname,udom) {
541: var url = '/adm/pickauthor?';
542: url += 'form='+formname+'&roledom='+udom;
543: var title = 'Author_Browser';
544: var options = 'scrollbars=1,resizable=1,menubar=0';
545: options += ',width=700,height=600';
546: stdeditbrowser = open(url,title,options,'1');
547: stdeditbrowser.focus();
548: }
549:
1.824 bisitz 550: // ]]>
1.653 raeburn 551: </script>
552: ENDAUTHORBRW
553: }
554:
1.91 www 555: sub coursebrowser_javascript {
1.1116 raeburn 556: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1221 raeburn 557: $credits_element,$instcode) = @_;
1.932 raeburn 558: my $wintitle = 'Course_Browser';
1.931 raeburn 559: if ($crstype eq 'Community') {
1.932 raeburn 560: $wintitle = 'Community_Browser';
1.909 raeburn 561: }
1.876 raeburn 562: my $id_functions = &javascript_index_functions();
563: my $output = '
1.776 bisitz 564: <script type="text/javascript" language="JavaScript">
1.824 bisitz 565: // <![CDATA[
1.468 raeburn 566: var stdeditbrowser;'."\n";
1.876 raeburn 567:
568: $output .= <<"ENDSTDBRW";
1.909 raeburn 569: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 570: var url = '/adm/pickcourse?';
1.895 raeburn 571: var formid = getFormIdByName(formname);
1.876 raeburn 572: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 573: if (domainfilter != null) {
574: if (domainfilter != '') {
575: url += 'domainfilter='+domainfilter+'&';
576: }
577: }
1.91 www 578: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 579: '&cdomelement='+udom+
580: '&cnameelement='+desc;
1.468 raeburn 581: if (extra_element !=null && extra_element != '') {
1.594 raeburn 582: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 583: url += '&roleelement='+extra_element;
584: if (domainfilter == null || domainfilter == '') {
585: url += '&domainfilter='+extra_element;
586: }
1.234 raeburn 587: }
1.468 raeburn 588: else {
589: if (formname == 'portform') {
590: url += '&setroles='+extra_element;
1.800 raeburn 591: } else {
592: if (formname == 'rules') {
593: url += '&fixeddom='+extra_element;
594: }
1.468 raeburn 595: }
596: }
1.230 raeburn 597: }
1.909 raeburn 598: if (type != null && type != '') {
599: url += '&type='+type;
600: }
601: if (type_elem != null && type_elem != '') {
602: url += '&typeelement='+type_elem;
603: }
1.872 raeburn 604: if (formname == 'ccrs') {
605: var ownername = document.forms[formid].ccuname.value;
606: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1238 raeburn 607: url += '&cloner='+ownername+':'+ownerdom;
608: if (type == 'Course') {
609: url += '&crscode='+document.forms[formid].crscode.value;
610: }
1.1221 raeburn 611: }
612: if (formname == 'requestcrs') {
613: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 614: }
1.293 raeburn 615: if (multflag !=null && multflag != '') {
616: url += '&multiple='+multflag;
617: }
1.909 raeburn 618: var title = '$wintitle';
1.91 www 619: var options = 'scrollbars=1,resizable=1,menubar=0';
620: options += ',width=700,height=600';
621: stdeditbrowser = open(url,title,options,'1');
622: stdeditbrowser.focus();
623: }
1.876 raeburn 624: $id_functions
625: ENDSTDBRW
1.1116 raeburn 626: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
627: $output .= &setsec_javascript($sec_element,$formname,$role_element,
628: $credits_element);
1.876 raeburn 629: }
630: $output .= '
631: // ]]>
632: </script>';
633: return $output;
634: }
635:
636: sub javascript_index_functions {
637: return <<"ENDJS";
638:
639: function getFormIdByName(formname) {
640: for (var i=0;i<document.forms.length;i++) {
641: if (document.forms[i].name == formname) {
642: return i;
643: }
644: }
645: return -1;
646: }
647:
648: function getIndexByName(formid,item) {
649: for (var i=0;i<document.forms[formid].elements.length;i++) {
650: if (document.forms[formid].elements[i].name == item) {
651: return i;
652: }
653: }
654: return -1;
655: }
1.468 raeburn 656:
1.876 raeburn 657: function getDomainFromSelectbox(formname,udom) {
658: var userdom;
659: var formid = getFormIdByName(formname);
660: if (formid > -1) {
661: var domid = getIndexByName(formid,udom);
662: if (domid > -1) {
663: if (document.forms[formid].elements[domid].type == 'select-one') {
664: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
665: }
666: if (document.forms[formid].elements[domid].type == 'hidden') {
667: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 668: }
669: }
670: }
1.876 raeburn 671: return userdom;
672: }
673:
674: ENDJS
1.468 raeburn 675:
1.876 raeburn 676: }
677:
1.1017 raeburn 678: sub javascript_array_indexof {
1.1018 raeburn 679: return <<ENDJS;
1.1017 raeburn 680: <script type="text/javascript" language="JavaScript">
681: // <![CDATA[
682:
683: if (!Array.prototype.indexOf) {
684: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
685: "use strict";
686: if (this === void 0 || this === null) {
687: throw new TypeError();
688: }
689: var t = Object(this);
690: var len = t.length >>> 0;
691: if (len === 0) {
692: return -1;
693: }
694: var n = 0;
695: if (arguments.length > 0) {
696: n = Number(arguments[1]);
1.1088 foxr 697: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 698: n = 0;
699: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
700: n = (n > 0 || -1) * Math.floor(Math.abs(n));
701: }
702: }
703: if (n >= len) {
704: return -1;
705: }
706: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
707: for (; k < len; k++) {
708: if (k in t && t[k] === searchElement) {
709: return k;
710: }
711: }
712: return -1;
713: }
714: }
715:
716: // ]]>
717: </script>
718:
719: ENDJS
720:
721: }
722:
1.876 raeburn 723: sub userbrowser_javascript {
724: my $id_functions = &javascript_index_functions();
725: return <<"ENDUSERBRW";
726:
1.888 raeburn 727: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 728: var url = '/adm/pickuser?';
729: var userdom = getDomainFromSelectbox(formname,udom);
730: if (userdom != null) {
731: if (userdom != '') {
732: url += 'srchdom='+userdom+'&';
733: }
734: }
735: url += 'form=' + formname + '&unameelement='+uname+
736: '&udomelement='+udom+
737: '&ulastelement='+ulast+
738: '&ufirstelement='+ufirst+
739: '&uemailelement='+uemail+
1.881 raeburn 740: '&hideudomelement='+hideudom+
741: '&coursedom='+crsdom;
1.888 raeburn 742: if ((caller != null) && (caller != undefined)) {
743: url += '&caller='+caller;
744: }
1.876 raeburn 745: var title = 'User_Browser';
746: var options = 'scrollbars=1,resizable=1,menubar=0';
747: options += ',width=700,height=600';
748: var stdeditbrowser = open(url,title,options,'1');
749: stdeditbrowser.focus();
750: }
751:
1.888 raeburn 752: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 753: var formid = getFormIdByName(formname);
754: if (formid > -1) {
1.888 raeburn 755: var unameid = getIndexByName(formid,uname);
1.876 raeburn 756: var domid = getIndexByName(formid,udom);
757: var hidedomid = getIndexByName(formid,origdom);
758: if (hidedomid > -1) {
759: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 760: var unameval = document.forms[formid].elements[unameid].value;
761: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
762: if (domid > -1) {
763: var slct = document.forms[formid].elements[domid];
764: if (slct.type == 'select-one') {
765: var i;
766: for (i=0;i<slct.length;i++) {
767: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
768: }
769: }
770: if (slct.type == 'hidden') {
771: slct.value = fixeddom;
1.876 raeburn 772: }
773: }
1.468 raeburn 774: }
775: }
776: }
1.876 raeburn 777: return;
778: }
779:
780: $id_functions
781: ENDUSERBRW
1.468 raeburn 782: }
783:
784: sub setsec_javascript {
1.1116 raeburn 785: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 786: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
787: $communityrolestr);
788: if ($role_element ne '') {
789: my @allroles = ('st','ta','ep','in','ad');
790: foreach my $crstype ('Course','Community') {
791: if ($crstype eq 'Community') {
792: foreach my $role (@allroles) {
793: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
794: }
795: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
796: } else {
797: foreach my $role (@allroles) {
798: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
799: }
800: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
801: }
802: }
803: $rolestr = '"'.join('","',@allroles).'"';
804: $courserolestr = '"'.join('","',@courserolenames).'"';
805: $communityrolestr = '"'.join('","',@communityrolenames).'"';
806: }
1.468 raeburn 807: my $setsections = qq|
808: function setSect(sectionlist) {
1.629 raeburn 809: var sectionsArray = new Array();
810: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
811: sectionsArray = sectionlist.split(",");
812: }
1.468 raeburn 813: var numSections = sectionsArray.length;
814: document.$formname.$sec_element.length = 0;
815: if (numSections == 0) {
816: document.$formname.$sec_element.multiple=false;
817: document.$formname.$sec_element.size=1;
818: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
819: } else {
820: if (numSections == 1) {
821: document.$formname.$sec_element.multiple=false;
822: document.$formname.$sec_element.size=1;
823: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
824: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
825: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
826: } else {
827: for (var i=0; i<numSections; i++) {
828: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
829: }
830: document.$formname.$sec_element.multiple=true
831: if (numSections < 3) {
832: document.$formname.$sec_element.size=numSections;
833: } else {
834: document.$formname.$sec_element.size=3;
835: }
836: document.$formname.$sec_element.options[0].selected = false
837: }
838: }
1.91 www 839: }
1.905 raeburn 840:
841: function setRole(crstype) {
1.468 raeburn 842: |;
1.905 raeburn 843: if ($role_element eq '') {
844: $setsections .= ' return;
845: }
846: ';
847: } else {
848: $setsections .= qq|
849: var elementLength = document.$formname.$role_element.length;
850: var allroles = Array($rolestr);
851: var courserolenames = Array($courserolestr);
852: var communityrolenames = Array($communityrolestr);
853: if (elementLength != undefined) {
854: if (document.$formname.$role_element.options[5].value == 'cc') {
855: if (crstype == 'Course') {
856: return;
857: } else {
858: allroles[5] = 'co';
859: for (var i=0; i<6; i++) {
860: document.$formname.$role_element.options[i].value = allroles[i];
861: document.$formname.$role_element.options[i].text = communityrolenames[i];
862: }
863: }
864: } else {
865: if (crstype == 'Community') {
866: return;
867: } else {
868: allroles[5] = 'cc';
869: for (var i=0; i<6; i++) {
870: document.$formname.$role_element.options[i].value = allroles[i];
871: document.$formname.$role_element.options[i].text = courserolenames[i];
872: }
873: }
874: }
875: }
876: return;
877: }
878: |;
879: }
1.1116 raeburn 880: if ($credits_element) {
881: $setsections .= qq|
882: function setCredits(defaultcredits) {
883: document.$formname.$credits_element.value = defaultcredits;
884: return;
885: }
886: |;
887: }
1.468 raeburn 888: return $setsections;
889: }
890:
1.91 www 891: sub selectcourse_link {
1.909 raeburn 892: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
893: $typeelement) = @_;
894: my $type = $selecttype;
1.871 raeburn 895: my $linktext = &mt('Select Course');
896: if ($selecttype eq 'Community') {
1.909 raeburn 897: $linktext = &mt('Select Community');
1.1239 raeburn 898: } elsif ($selecttype eq 'Placement') {
899: $linktext = &mt('Select Placement Test');
1.906 raeburn 900: } elsif ($selecttype eq 'Course/Community') {
901: $linktext = &mt('Select Course/Community');
1.909 raeburn 902: $type = '';
1.1019 raeburn 903: } elsif ($selecttype eq 'Select') {
904: $linktext = &mt('Select');
905: $type = '';
1.871 raeburn 906: }
1.787 bisitz 907: return '<span class="LC_nobreak">'
908: ."<a href='"
909: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
910: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 911: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 912: ."'>".$linktext.'</a>'
1.787 bisitz 913: .'</span>';
1.74 www 914: }
1.42 matthew 915:
1.653 raeburn 916: sub selectauthor_link {
917: my ($form,$udom)=@_;
918: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
919: &mt('Select Author').'</a>';
920: }
921:
1.876 raeburn 922: sub selectuser_link {
1.881 raeburn 923: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 924: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 925: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 926: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 927: ');">'.$linktext.'</a>';
1.876 raeburn 928: }
929:
1.273 raeburn 930: sub check_uncheck_jscript {
931: my $jscript = <<"ENDSCRT";
932: function checkAll(field) {
933: if (field.length > 0) {
934: for (i = 0; i < field.length; i++) {
1.1093 raeburn 935: if (!field[i].disabled) {
936: field[i].checked = true;
937: }
1.273 raeburn 938: }
939: } else {
1.1093 raeburn 940: if (!field.disabled) {
941: field.checked = true;
942: }
1.273 raeburn 943: }
944: }
945:
946: function uncheckAll(field) {
947: if (field.length > 0) {
948: for (i = 0; i < field.length; i++) {
949: field[i].checked = false ;
1.543 albertel 950: }
951: } else {
1.273 raeburn 952: field.checked = false ;
953: }
954: }
955: ENDSCRT
956: return $jscript;
957: }
958:
1.656 www 959: sub select_timezone {
1.1256 raeburn 960: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
961: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 962: if ($includeempty) {
963: $output .= '<option value=""';
964: if (($selected eq '') || ($selected eq 'local')) {
965: $output .= ' selected="selected" ';
966: }
967: $output .= '> </option>';
968: }
1.657 raeburn 969: my @timezones = DateTime::TimeZone->all_names;
970: foreach my $tzone (@timezones) {
971: $output.= '<option value="'.$tzone.'"';
972: if ($tzone eq $selected) {
973: $output.=' selected="selected"';
974: }
975: $output.=">$tzone</option>\n";
1.656 www 976: }
977: $output.="</select>";
978: return $output;
979: }
1.273 raeburn 980:
1.687 raeburn 981: sub select_datelocale {
1.1256 raeburn 982: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
983: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 984: if ($includeempty) {
985: $output .= '<option value=""';
986: if ($selected eq '') {
987: $output .= ' selected="selected" ';
988: }
989: $output .= '> </option>';
990: }
1.1241 raeburn 991: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 992: my (@possibles,%locale_names);
1.1241 raeburn 993: my @locales = DateTime::Locale->ids();
994: foreach my $id (@locales) {
995: if ($id ne '') {
996: my ($en_terr,$native_terr);
997: my $loc = DateTime::Locale->load($id);
998: if (ref($loc)) {
999: $en_terr = $loc->name();
1000: $native_terr = $loc->native_name();
1.687 raeburn 1001: if (grep(/^en$/,@languages) || !@languages) {
1002: if ($en_terr ne '') {
1003: $locale_names{$id} = '('.$en_terr.')';
1004: } elsif ($native_terr ne '') {
1005: $locale_names{$id} = $native_terr;
1006: }
1007: } else {
1008: if ($native_terr ne '') {
1009: $locale_names{$id} = $native_terr.' ';
1010: } elsif ($en_terr ne '') {
1011: $locale_names{$id} = '('.$en_terr.')';
1012: }
1013: }
1.1220 raeburn 1014: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1241 raeburn 1015: push(@possibles,$id);
1016: }
1.687 raeburn 1017: }
1018: }
1019: foreach my $item (sort(@possibles)) {
1020: $output.= '<option value="'.$item.'"';
1021: if ($item eq $selected) {
1022: $output.=' selected="selected"';
1023: }
1024: $output.=">$item";
1025: if ($locale_names{$item} ne '') {
1.1220 raeburn 1026: $output.=' '.$locale_names{$item};
1.687 raeburn 1027: }
1028: $output.="</option>\n";
1029: }
1030: $output.="</select>";
1031: return $output;
1032: }
1033:
1.792 raeburn 1034: sub select_language {
1.1256 raeburn 1035: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1036: my %langchoices;
1037: if ($includeempty) {
1.1117 raeburn 1038: %langchoices = ('' => 'No language preference');
1.792 raeburn 1039: }
1040: foreach my $id (&languageids()) {
1041: my $code = &supportedlanguagecode($id);
1042: if ($code) {
1043: $langchoices{$code} = &plainlanguagedescription($id);
1044: }
1045: }
1.1117 raeburn 1046: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1256 raeburn 1047: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1048: }
1049:
1.42 matthew 1050: =pod
1.36 matthew 1051:
1.1088 foxr 1052:
1053: =item * &list_languages()
1054:
1055: Returns an array reference that is suitable for use in language prompters.
1056: Each array element is itself a two element array. The first element
1057: is the language code. The second element a descsriptiuon of the
1058: language itself. This is suitable for use in e.g.
1059: &Apache::edit::select_arg (once dereferenced that is).
1060:
1061: =cut
1062:
1063: sub list_languages {
1064: my @lang_choices;
1065:
1066: foreach my $id (&languageids()) {
1067: my $code = &supportedlanguagecode($id);
1068: if ($code) {
1069: my $selector = $supported_codes{$id};
1070: my $description = &plainlanguagedescription($id);
1.1263 raeburn 1071: push(@lang_choices, [$selector, $description]);
1.1088 foxr 1072: }
1073: }
1074: return \@lang_choices;
1075: }
1076:
1077: =pod
1078:
1.648 raeburn 1079: =item * &linked_select_forms(...)
1.36 matthew 1080:
1081: linked_select_forms returns a string containing a <script></script> block
1082: and html for two <select> menus. The select menus will be linked in that
1083: changing the value of the first menu will result in new values being placed
1084: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1085: order unless a defined order is provided.
1.36 matthew 1086:
1087: linked_select_forms takes the following ordered inputs:
1088:
1089: =over 4
1090:
1.112 bowersj2 1091: =item * $formname, the name of the <form> tag
1.36 matthew 1092:
1.112 bowersj2 1093: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1094:
1.112 bowersj2 1095: =item * $firstdefault, the default value for the first menu
1.36 matthew 1096:
1.112 bowersj2 1097: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1098:
1.112 bowersj2 1099: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1100:
1.112 bowersj2 1101: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1102:
1.609 raeburn 1103: =item * $menuorder, the order of values in the first menu
1104:
1.1115 raeburn 1105: =item * $onchangefirst, additional javascript call to execute for an onchange
1106: event for the first <select> tag
1107:
1108: =item * $onchangesecond, additional javascript call to execute for an onchange
1109: event for the second <select> tag
1110:
1.1245 raeburn 1111: =item * $suffix, to differentiate separate uses of select2data javascript
1112: objects in a page.
1113:
1.41 ng 1114: =back
1115:
1.36 matthew 1116: Below is an example of such a hash. Only the 'text', 'default', and
1117: 'select2' keys must appear as stated. keys(%menu) are the possible
1118: values for the first select menu. The text that coincides with the
1.41 ng 1119: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1120: and text for the second menu are given in the hash pointed to by
1121: $menu{$choice1}->{'select2'}.
1122:
1.112 bowersj2 1123: my %menu = ( A1 => { text =>"Choice A1" ,
1124: default => "B3",
1125: select2 => {
1126: B1 => "Choice B1",
1127: B2 => "Choice B2",
1128: B3 => "Choice B3",
1129: B4 => "Choice B4"
1.609 raeburn 1130: },
1131: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1132: },
1133: A2 => { text =>"Choice A2" ,
1134: default => "C2",
1135: select2 => {
1136: C1 => "Choice C1",
1137: C2 => "Choice C2",
1138: C3 => "Choice C3"
1.609 raeburn 1139: },
1140: order => ['C2','C1','C3'],
1.112 bowersj2 1141: },
1142: A3 => { text =>"Choice A3" ,
1143: default => "D6",
1144: select2 => {
1145: D1 => "Choice D1",
1146: D2 => "Choice D2",
1147: D3 => "Choice D3",
1148: D4 => "Choice D4",
1149: D5 => "Choice D5",
1150: D6 => "Choice D6",
1151: D7 => "Choice D7"
1.609 raeburn 1152: },
1153: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1154: }
1155: );
1.36 matthew 1156:
1157: =cut
1158:
1159: sub linked_select_forms {
1160: my ($formname,
1161: $middletext,
1162: $firstdefault,
1163: $firstselectname,
1164: $secondselectname,
1.609 raeburn 1165: $hashref,
1166: $menuorder,
1.1115 raeburn 1167: $onchangefirst,
1.1245 raeburn 1168: $onchangesecond,
1169: $suffix
1.36 matthew 1170: ) = @_;
1171: my $second = "document.$formname.$secondselectname";
1172: my $first = "document.$formname.$firstselectname";
1173: # output the javascript to do the changing
1174: my $result = '';
1.776 bisitz 1175: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1176: $result.="// <![CDATA[\n";
1.1245 raeburn 1177: $result.="var select2data${suffix} = new Object();\n";
1.36 matthew 1178: $" = '","';
1179: my $debug = '';
1180: foreach my $s1 (sort(keys(%$hashref))) {
1.1245 raeburn 1181: $result.="select2data${suffix}['d_$s1'] = new Object();\n";
1182: $result.="select2data${suffix}['d_$s1'].def = new String('".
1.36 matthew 1183: $hashref->{$s1}->{'default'}."');\n";
1.1245 raeburn 1184: $result.="select2data${suffix}['d_$s1'].values = new Array(";
1.36 matthew 1185: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1186: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1187: @s2values = @{$hashref->{$s1}->{'order'}};
1188: }
1.36 matthew 1189: $result.="\"@s2values\");\n";
1.1245 raeburn 1190: $result.="select2data${suffix}['d_$s1'].texts = new Array(";
1.36 matthew 1191: my @s2texts;
1192: foreach my $value (@s2values) {
1.1263 raeburn 1193: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1194: }
1195: $result.="\"@s2texts\");\n";
1196: }
1197: $"=' ';
1198: $result.= <<"END";
1199:
1.1245 raeburn 1200: function select1${suffix}_changed() {
1.36 matthew 1201: // Determine new choice
1.1245 raeburn 1202: var newvalue = "d_" + $first.options[$first.selectedIndex].value;
1.36 matthew 1203: // update select2
1.1245 raeburn 1204: var values = select2data${suffix}[newvalue].values;
1205: var texts = select2data${suffix}[newvalue].texts;
1206: var select2def = select2data${suffix}[newvalue].def;
1.36 matthew 1207: var i;
1208: // out with the old
1.1245 raeburn 1209: $second.options.length = 0;
1210: // in with the new
1.36 matthew 1211: for (i=0;i<values.length; i++) {
1212: $second.options[i] = new Option(values[i]);
1.143 matthew 1213: $second.options[i].value = values[i];
1.36 matthew 1214: $second.options[i].text = texts[i];
1215: if (values[i] == select2def) {
1216: $second.options[i].selected = true;
1217: }
1218: }
1219: }
1.824 bisitz 1220: // ]]>
1.36 matthew 1221: </script>
1222: END
1223: # output the initial values for the selection lists
1.1245 raeburn 1224: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
1.609 raeburn 1225: my @order = sort(keys(%{$hashref}));
1226: if (ref($menuorder) eq 'ARRAY') {
1227: @order = @{$menuorder};
1228: }
1229: foreach my $value (@order) {
1.36 matthew 1230: $result.=" <option value=\"$value\" ";
1.253 albertel 1231: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1232: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1233: }
1234: $result .= "</select>\n";
1235: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1236: $result .= $middletext;
1.1115 raeburn 1237: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1238: if ($onchangesecond) {
1239: $result .= ' onchange="'.$onchangesecond.'"';
1240: }
1241: $result .= ">\n";
1.36 matthew 1242: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1243:
1244: my @secondorder = sort(keys(%select2));
1245: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1246: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1247: }
1248: foreach my $value (@secondorder) {
1.36 matthew 1249: $result.=" <option value=\"$value\" ";
1.253 albertel 1250: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1251: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1252: }
1253: $result .= "</select>\n";
1254: # return $debug;
1255: return $result;
1256: } # end of sub linked_select_forms {
1257:
1.45 matthew 1258: =pod
1.44 bowersj2 1259:
1.973 raeburn 1260: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1261:
1.112 bowersj2 1262: Returns a string corresponding to an HTML link to the given help
1263: $topic, where $topic corresponds to the name of a .tex file in
1264: /home/httpd/html/adm/help/tex, with underscores replaced by
1265: spaces.
1266:
1267: $text will optionally be linked to the same topic, allowing you to
1268: link text in addition to the graphic. If you do not want to link
1269: text, but wish to specify one of the later parameters, pass an
1270: empty string.
1271:
1272: $stayOnPage is a value that will be interpreted as a boolean. If true,
1273: the link will not open a new window. If false, the link will open
1274: a new window using Javascript. (Default is false.)
1275:
1276: $width and $height are optional numerical parameters that will
1277: override the width and height of the popped up window, which may
1.973 raeburn 1278: be useful for certain help topics with big pictures included.
1279:
1280: $imgid is the id of the img tag used for the help icon. This may be
1281: used in a javascript call to switch the image src. See
1282: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1283:
1284: =cut
1285:
1286: sub help_open_topic {
1.973 raeburn 1287: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1288: $text = "" if (not defined $text);
1.44 bowersj2 1289: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1290: $width = 500 if (not defined $width);
1.44 bowersj2 1291: $height = 400 if (not defined $height);
1292: my $filename = $topic;
1293: $filename =~ s/ /_/g;
1294:
1.48 bowersj2 1295: my $template = "";
1296: my $link;
1.572 banghart 1297:
1.159 www 1298: $topic=~s/\W/\_/g;
1.44 bowersj2 1299:
1.572 banghart 1300: if (!$stayOnPage) {
1.1033 www 1301: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1302: } elsif ($stayOnPage eq 'popup') {
1303: $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 1304: } else {
1.48 bowersj2 1305: $link = "/adm/help/${filename}.hlp";
1306: }
1307:
1308: # Add the text
1.1314 raeburn 1309: my $target = ' target="_top"';
1310: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1311: $target = '';
1312: }
1.755 neumanie 1313: if ($text ne "") {
1.763 bisitz 1314: $template.='<span class="LC_help_open_topic">'
1.1314 raeburn 1315: .'<a'.$target.' href="'.$link.'">'
1.763 bisitz 1316: .$text.'</a>';
1.48 bowersj2 1317: }
1318:
1.763 bisitz 1319: # (Always) Add the graphic
1.179 matthew 1320: my $title = &mt('Online Help');
1.667 raeburn 1321: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1322: if ($imgid ne '') {
1323: $imgid = ' id="'.$imgid.'"';
1324: }
1.1314 raeburn 1325: $template.=' <a'.$target.' href="'.$link.'" title="'.$title.'">'
1.763 bisitz 1326: .'<img src="'.$helpicon.'" border="0"'
1327: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1328: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1329: .' /></a>';
1330: if ($text ne "") {
1331: $template.='</span>';
1332: }
1.44 bowersj2 1333: return $template;
1334:
1.106 bowersj2 1335: }
1336:
1337: # This is a quicky function for Latex cheatsheet editing, since it
1338: # appears in at least four places
1339: sub helpLatexCheatsheet {
1.1037 www 1340: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1341: my $out;
1.106 bowersj2 1342: my $addOther = '';
1.732 raeburn 1343: if ($topic) {
1.1037 www 1344: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1345: }
1346: $out = '<span>' # Start cheatsheet
1347: .$addOther
1348: .'<span>'
1.1037 www 1349: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1350: .'</span> <span>'
1.1037 www 1351: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1352: .'</span>';
1.732 raeburn 1353: unless ($not_author) {
1.1186 kruse 1354: $out .= '<span>'
1355: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1356: .'</span> <span>'
1357: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1358: .'</span>';
1.732 raeburn 1359: }
1.763 bisitz 1360: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1361: return $out;
1.172 www 1362: }
1363:
1.430 albertel 1364: sub general_help {
1365: my $helptopic='Student_Intro';
1366: if ($env{'request.role'}=~/^(ca|au)/) {
1367: $helptopic='Authoring_Intro';
1.907 raeburn 1368: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1369: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1370: } elsif ($env{'request.role'}=~/^dc/) {
1371: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1372: }
1373: return $helptopic;
1374: }
1375:
1376: sub update_help_link {
1377: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1378: my $origurl = $ENV{'REQUEST_URI'};
1379: $origurl=~s|^/~|/priv/|;
1380: my $timestamp = time;
1381: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1382: $$datum = &escape($$datum);
1383: }
1384:
1385: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1386: my $output .= <<"ENDOUTPUT";
1387: <script type="text/javascript">
1.824 bisitz 1388: // <![CDATA[
1.430 albertel 1389: banner_link = '$banner_link';
1.824 bisitz 1390: // ]]>
1.430 albertel 1391: </script>
1392: ENDOUTPUT
1393: return $output;
1394: }
1395:
1396: # now just updates the help link and generates a blue icon
1.193 raeburn 1397: sub help_open_menu {
1.430 albertel 1398: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1399: = @_;
1.949 droeschl 1400: $stayOnPage = 1;
1.430 albertel 1401: my $output;
1402: if ($component_help) {
1403: if (!$text) {
1404: $output=&help_open_topic($component_help,undef,$stayOnPage,
1405: $width,$height);
1406: } else {
1407: my $help_text;
1408: $help_text=&unescape($topic);
1409: $output='<table><tr><td>'.
1410: &help_open_topic($component_help,$help_text,$stayOnPage,
1411: $width,$height).'</td></tr></table>';
1412: }
1413: }
1414: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1415: return $output.$banner_link;
1416: }
1417:
1418: sub top_nav_help {
1419: my ($text) = @_;
1.436 albertel 1420: $text = &mt($text);
1.949 droeschl 1421: my $stay_on_page = 1;
1422:
1.1168 raeburn 1423: my ($link,$banner_link);
1424: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1425: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1426: : "javascript:helpMenu('open')";
1427: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1428: }
1.201 raeburn 1429: my $title = &mt('Get help');
1.1168 raeburn 1430: if ($link) {
1431: return <<"END";
1.436 albertel 1432: $banner_link
1.1159 raeburn 1433: <a href="$link" title="$title">$text</a>
1.436 albertel 1434: END
1.1168 raeburn 1435: } else {
1436: return ' '.$text.' ';
1437: }
1.436 albertel 1438: }
1439:
1440: sub help_menu_js {
1.1154 raeburn 1441: my ($httphost) = @_;
1.949 droeschl 1442: my $stayOnPage = 1;
1.436 albertel 1443: my $width = 620;
1444: my $height = 600;
1.430 albertel 1445: my $helptopic=&general_help();
1.1154 raeburn 1446: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1447: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1448: my $start_page =
1449: &Apache::loncommon::start_page('Help Menu', undef,
1450: {'frameset' => 1,
1451: 'js_ready' => 1,
1.1154 raeburn 1452: 'use_absolute' => $httphost,
1.331 albertel 1453: 'add_entries' => {
1.1168 raeburn 1454: 'border' => '0',
1.579 raeburn 1455: 'rows' => "110,*",},});
1.331 albertel 1456: my $end_page =
1457: &Apache::loncommon::end_page({'frameset' => 1,
1458: 'js_ready' => 1,});
1459:
1.436 albertel 1460: my $template .= <<"ENDTEMPLATE";
1461: <script type="text/javascript">
1.877 bisitz 1462: // <![CDATA[
1.253 albertel 1463: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1464: var banner_link = '';
1.243 raeburn 1465: function helpMenu(target) {
1466: var caller = this;
1467: if (target == 'open') {
1468: var newWindow = null;
1469: try {
1.262 albertel 1470: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1471: }
1472: catch(error) {
1473: writeHelp(caller);
1474: return;
1475: }
1476: if (newWindow) {
1477: caller = newWindow;
1478: }
1.193 raeburn 1479: }
1.243 raeburn 1480: writeHelp(caller);
1481: return;
1482: }
1483: function writeHelp(caller) {
1.1168 raeburn 1484: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1485: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1486: caller.document.close();
1487: caller.focus();
1.193 raeburn 1488: }
1.877 bisitz 1489: // END LON-CAPA Internal -->
1.253 albertel 1490: // ]]>
1.436 albertel 1491: </script>
1.193 raeburn 1492: ENDTEMPLATE
1493: return $template;
1494: }
1495:
1.172 www 1496: sub help_open_bug {
1497: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1498: unless ($env{'user.adv'}) { return ''; }
1.172 www 1499: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1500: $text = "" if (not defined $text);
1501: $stayOnPage=1;
1.184 albertel 1502: $width = 600 if (not defined $width);
1503: $height = 600 if (not defined $height);
1.172 www 1504:
1505: $topic=~s/\W+/\+/g;
1506: my $link='';
1507: my $template='';
1.379 albertel 1508: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1509: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1510: if (!$stayOnPage)
1511: {
1512: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1513: }
1514: else
1515: {
1516: $link = $url;
1517: }
1.1314 raeburn 1518:
1519: my $target = ' target="_top"';
1520: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1521: $target = '';
1522: }
1.172 www 1523: # Add the text
1524: if ($text ne "")
1525: {
1526: $template .=
1527: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.1314 raeburn 1528: "<td bgcolor='#FF5555'><a".$target." href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1529: }
1530:
1531: # Add the graphic
1.179 matthew 1532: my $title = &mt('Report a Bug');
1.215 albertel 1533: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1534: $template .= <<"ENDTEMPLATE";
1.1314 raeburn 1535: <a$target href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1536: ENDTEMPLATE
1537: if ($text ne '') { $template.='</td></tr></table>' };
1538: return $template;
1539:
1540: }
1541:
1542: sub help_open_faq {
1543: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1544: unless ($env{'user.adv'}) { return ''; }
1.172 www 1545: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1546: $text = "" if (not defined $text);
1547: $stayOnPage=1;
1548: $width = 350 if (not defined $width);
1549: $height = 400 if (not defined $height);
1550:
1551: $topic=~s/\W+/\+/g;
1552: my $link='';
1553: my $template='';
1554: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1555: if (!$stayOnPage)
1556: {
1557: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1558: }
1559: else
1560: {
1561: $link = $url;
1562: }
1563:
1564: # Add the text
1565: if ($text ne "")
1566: {
1567: $template .=
1.173 www 1568: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1569: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1570: }
1571:
1572: # Add the graphic
1.179 matthew 1573: my $title = &mt('View the FAQ');
1.215 albertel 1574: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1575: $template .= <<"ENDTEMPLATE";
1.436 albertel 1576: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1577: ENDTEMPLATE
1578: if ($text ne '') { $template.='</td></tr></table>' };
1579: return $template;
1580:
1.44 bowersj2 1581: }
1.37 matthew 1582:
1.180 matthew 1583: ###############################################################
1584: ###############################################################
1585:
1.45 matthew 1586: =pod
1587:
1.648 raeburn 1588: =item * &change_content_javascript():
1.256 matthew 1589:
1590: This and the next function allow you to create small sections of an
1591: otherwise static HTML page that you can update on the fly with
1592: Javascript, even in Netscape 4.
1593:
1594: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1595: must be written to the HTML page once. It will prove the Javascript
1596: function "change(name, content)". Calling the change function with the
1597: name of the section
1598: you want to update, matching the name passed to C<changable_area>, and
1599: the new content you want to put in there, will put the content into
1600: that area.
1601:
1602: B<Note>: Netscape 4 only reserves enough space for the changable area
1603: to contain room for the original contents. You need to "make space"
1604: for whatever changes you wish to make, and be B<sure> to check your
1605: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1606: it's adequate for updating a one-line status display, but little more.
1607: This script will set the space to 100% width, so you only need to
1608: worry about height in Netscape 4.
1609:
1610: Modern browsers are much less limiting, and if you can commit to the
1611: user not using Netscape 4, this feature may be used freely with
1612: pretty much any HTML.
1613:
1614: =cut
1615:
1616: sub change_content_javascript {
1617: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1618: if ($env{'browser.type'} eq 'netscape' &&
1619: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1620: return (<<NETSCAPE4);
1621: function change(name, content) {
1622: doc = document.layers[name+"___escape"].layers[0].document;
1623: doc.open();
1624: doc.write(content);
1625: doc.close();
1626: }
1627: NETSCAPE4
1628: } else {
1629: # Otherwise, we need to use semi-standards-compliant code
1630: # (technically, "innerHTML" isn't standard but the equivalent
1631: # is really scary, and every useful browser supports it
1632: return (<<DOMBASED);
1633: function change(name, content) {
1634: element = document.getElementById(name);
1635: element.innerHTML = content;
1636: }
1637: DOMBASED
1638: }
1639: }
1640:
1641: =pod
1642:
1.648 raeburn 1643: =item * &changable_area($name,$origContent):
1.256 matthew 1644:
1645: This provides a "changable area" that can be modified on the fly via
1646: the Javascript code provided in C<change_content_javascript>. $name is
1647: the name you will use to reference the area later; do not repeat the
1648: same name on a given HTML page more then once. $origContent is what
1649: the area will originally contain, which can be left blank.
1650:
1651: =cut
1652:
1653: sub changable_area {
1654: my ($name, $origContent) = @_;
1655:
1.258 albertel 1656: if ($env{'browser.type'} eq 'netscape' &&
1657: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1658: # If this is netscape 4, we need to use the Layer tag
1659: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1660: } else {
1661: return "<span id='$name'>$origContent</span>";
1662: }
1663: }
1664:
1665: =pod
1666:
1.648 raeburn 1667: =item * &viewport_geometry_js
1.590 raeburn 1668:
1669: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1670:
1671: =cut
1672:
1673:
1674: sub viewport_geometry_js {
1675: return <<"GEOMETRY";
1676: var Geometry = {};
1677: function init_geometry() {
1678: if (Geometry.init) { return };
1679: Geometry.init=1;
1680: if (window.innerHeight) {
1681: Geometry.getViewportHeight = function() { return window.innerHeight; };
1682: Geometry.getViewportWidth = function() { return window.innerWidth; };
1683: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1684: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1685: }
1686: else if (document.documentElement && document.documentElement.clientHeight) {
1687: Geometry.getViewportHeight =
1688: function() { return document.documentElement.clientHeight; };
1689: Geometry.getViewportWidth =
1690: function() { return document.documentElement.clientWidth; };
1691:
1692: Geometry.getHorizontalScroll =
1693: function() { return document.documentElement.scrollLeft; };
1694: Geometry.getVerticalScroll =
1695: function() { return document.documentElement.scrollTop; };
1696: }
1697: else if (document.body.clientHeight) {
1698: Geometry.getViewportHeight =
1699: function() { return document.body.clientHeight; };
1700: Geometry.getViewportWidth =
1701: function() { return document.body.clientWidth; };
1702: Geometry.getHorizontalScroll =
1703: function() { return document.body.scrollLeft; };
1704: Geometry.getVerticalScroll =
1705: function() { return document.body.scrollTop; };
1706: }
1707: }
1708:
1709: GEOMETRY
1710: }
1711:
1712: =pod
1713:
1.648 raeburn 1714: =item * &viewport_size_js()
1.590 raeburn 1715:
1716: 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.
1717:
1718: =cut
1719:
1720: sub viewport_size_js {
1721: my $geometry = &viewport_geometry_js();
1722: return <<"DIMS";
1723:
1724: $geometry
1725:
1726: function getViewportDims(width,height) {
1727: init_geometry();
1728: width.value = Geometry.getViewportWidth();
1729: height.value = Geometry.getViewportHeight();
1730: return;
1731: }
1732:
1733: DIMS
1734: }
1735:
1736: =pod
1737:
1.648 raeburn 1738: =item * &resize_textarea_js()
1.565 albertel 1739:
1740: emits the needed javascript to resize a textarea to be as big as possible
1741:
1742: creates a function resize_textrea that takes two IDs first should be
1743: the id of the element to resize, second should be the id of a div that
1744: surrounds everything that comes after the textarea, this routine needs
1745: to be attached to the <body> for the onload and onresize events.
1746:
1.648 raeburn 1747: =back
1.565 albertel 1748:
1749: =cut
1750:
1751: sub resize_textarea_js {
1.590 raeburn 1752: my $geometry = &viewport_geometry_js();
1.565 albertel 1753: return <<"RESIZE";
1754: <script type="text/javascript">
1.824 bisitz 1755: // <![CDATA[
1.590 raeburn 1756: $geometry
1.565 albertel 1757:
1.588 albertel 1758: function getX(element) {
1759: var x = 0;
1760: while (element) {
1761: x += element.offsetLeft;
1762: element = element.offsetParent;
1763: }
1764: return x;
1765: }
1766: function getY(element) {
1767: var y = 0;
1768: while (element) {
1769: y += element.offsetTop;
1770: element = element.offsetParent;
1771: }
1772: return y;
1773: }
1774:
1775:
1.565 albertel 1776: function resize_textarea(textarea_id,bottom_id) {
1777: init_geometry();
1778: var textarea = document.getElementById(textarea_id);
1779: //alert(textarea);
1780:
1.588 albertel 1781: var textarea_top = getY(textarea);
1.565 albertel 1782: var textarea_height = textarea.offsetHeight;
1783: var bottom = document.getElementById(bottom_id);
1.588 albertel 1784: var bottom_top = getY(bottom);
1.565 albertel 1785: var bottom_height = bottom.offsetHeight;
1786: var window_height = Geometry.getViewportHeight();
1.588 albertel 1787: var fudge = 23;
1.565 albertel 1788: var new_height = window_height-fudge-textarea_top-bottom_height;
1789: if (new_height < 300) {
1790: new_height = 300;
1791: }
1792: textarea.style.height=new_height+'px';
1793: }
1.824 bisitz 1794: // ]]>
1.565 albertel 1795: </script>
1796: RESIZE
1797:
1798: }
1799:
1.1205 golterma 1800: sub colorfuleditor_js {
1.1248 raeburn 1801: my $browse_or_search;
1802: my $respath;
1803: my ($cnum,$cdom) = &crsauthor_url();
1804: if ($cnum) {
1805: $respath = "/res/$cdom/$cnum/";
1806: my %js_lt = &Apache::lonlocal::texthash(
1807: sunm => 'Sub-directory name',
1808: save => 'Save page to make this permanent',
1809: );
1810: &js_escape(\%js_lt);
1811: $browse_or_search = <<"END";
1812:
1813: function toggleChooser(form,element,titleid,only,search) {
1814: var disp = 'none';
1815: if (document.getElementById('chooser_'+element)) {
1816: var curr = document.getElementById('chooser_'+element).style.display;
1817: if (curr == 'none') {
1818: disp='inline';
1819: if (form.elements['chooser_'+element].length) {
1820: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1821: form.elements['chooser_'+element][i].checked = false;
1822: }
1823: }
1824: toggleResImport(form,element);
1825: }
1826: document.getElementById('chooser_'+element).style.display = disp;
1827: }
1828: }
1829:
1830: function toggleCrsFile(form,element,numdirs) {
1831: if (document.getElementById('chooser_'+element+'_crsres')) {
1832: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1833: if (curr == 'none') {
1834: if (numdirs) {
1835: form.elements['coursepath_'+element].selectedIndex = 0;
1836: if (numdirs > 1) {
1837: window['select1'+element+'_changed']();
1838: }
1839: }
1840: }
1841: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1842:
1843: }
1844: if (document.getElementById('chooser_'+element+'_upload')) {
1845: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1846: if (document.getElementById('uploadcrsres_'+element)) {
1847: document.getElementById('uploadcrsres_'+element).value = '';
1848: }
1849: }
1850: return;
1851: }
1852:
1853: function toggleCrsUpload(form,element,numcrsdirs) {
1854: if (document.getElementById('chooser_'+element+'_crsres')) {
1855: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1856: }
1857: if (document.getElementById('chooser_'+element+'_upload')) {
1858: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1859: if (curr == 'none') {
1860: if (numcrsdirs) {
1861: form.elements['crsauthorpath_'+element].selectedIndex = 0;
1862: form.elements['newsubdir_'+element][0].checked = true;
1863: toggleNewsubdir(form,element);
1864: }
1865: }
1866: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1867: }
1868: return;
1869: }
1870:
1871: function toggleResImport(form,element) {
1872: var choices = new Array('crsres','upload');
1873: for (var i=0; i<choices.length; i++) {
1874: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1875: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1876: }
1877: }
1878: }
1879:
1880: function toggleNewsubdir(form,element) {
1881: var newsub = form.elements['newsubdir_'+element];
1882: if (newsub) {
1883: if (newsub.length) {
1884: for (var j=0; j<newsub.length; j++) {
1885: if (newsub[j].checked) {
1886: if (document.getElementById('newsubdirname_'+element)) {
1887: if (newsub[j].value == '1') {
1888: document.getElementById('newsubdirname_'+element).type = "text";
1889: if (document.getElementById('newsubdir_'+element)) {
1890: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1891: }
1892: } else {
1893: document.getElementById('newsubdirname_'+element).type = "hidden";
1894: document.getElementById('newsubdirname_'+element).value = "";
1895: document.getElementById('newsubdir_'+element).innerHTML = "";
1896: }
1897: }
1898: break;
1899: }
1900: }
1901: }
1902: }
1903: }
1904:
1905: function updateCrsFile(form,element) {
1906: var directory = form.elements['coursepath_'+element];
1907: var filename = form.elements['coursefile_'+element];
1908: var path = directory.options[directory.selectedIndex].value;
1909: var file = filename.options[filename.selectedIndex].value;
1910: form.elements[element].value = '$respath';
1911: if (path == '/') {
1912: form.elements[element].value += file;
1913: } else {
1914: form.elements[element].value += path+'/'+file;
1915: }
1916: unClean();
1917: if (document.getElementById('previewimg_'+element)) {
1918: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1919: var newsrc = document.getElementById('previewimg_'+element).src;
1920: }
1921: if (document.getElementById('showimg_'+element)) {
1922: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1923: }
1924: toggleChooser(form,element);
1925: return;
1926: }
1927:
1928: function uploadDone(suffix,name) {
1929: if (name) {
1930: document.forms["lonhomework"].elements[suffix].value = name;
1931: unClean();
1932: toggleChooser(document.forms["lonhomework"],suffix);
1933: }
1934: }
1935:
1936: \$(document).ready(function(){
1937:
1938: \$(document).delegate('form :submit', 'click', function( event ) {
1939: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
1940: var buttonId = this.id;
1941: var suffix = buttonId.toString();
1942: suffix = suffix.replace(/^crsupload_/,'');
1943: event.preventDefault();
1944: document.lonhomework.target = 'crsupload_target_'+suffix;
1945: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
1946: \$(this.form).submit();
1947: document.lonhomework.target = '';
1948: if (document.getElementById('crsuploadto_'+suffix)) {
1949: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
1950: }
1951: return false;
1952: }
1953: });
1954: });
1955: END
1956: }
1.1205 golterma 1957: return <<"COLORFULEDIT"
1958: <script type="text/javascript">
1959: // <![CDATA[>
1960: function fold_box(curDepth, lastresource){
1961:
1962: // we need a list because there can be several blocks you need to fold in one tag
1963: var block = document.getElementsByName('foldblock_'+curDepth);
1964: // but there is only one folding button per tag
1965: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1966:
1967: if(block.item(0).style.display == 'none'){
1968:
1969: foldbutton.value = '@{[&mt("Hide")]}';
1970: for (i = 0; i < block.length; i++){
1971: block.item(i).style.display = '';
1972: }
1973: }else{
1974:
1975: foldbutton.value = '@{[&mt("Show")]}';
1976: for (i = 0; i < block.length; i++){
1977: // block.item(i).style.visibility = 'collapse';
1978: block.item(i).style.display = 'none';
1979: }
1980: };
1981: saveState(lastresource);
1982: }
1983:
1984: function saveState (lastresource) {
1985:
1986: var tag_list = getTagList();
1987: if(tag_list != null){
1988: var timestamp = new Date().getTime();
1989: var key = lastresource;
1990:
1991: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1992: // starting with timestamp
1993: var value = timestamp+';';
1994:
1995: // building the list of key-value pairs
1996: for(var i = 0; i < tag_list.length; i++){
1997: value += tag_list[i]+',';
1998: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1999: }
2000:
2001: // only iterate whole storage if nothing to override
2002: if(localStorage.getItem(key) == null){
2003:
2004: // prevent storage from growing large
2005: if(localStorage.length > 50){
2006: var regex_getTimestamp = /^(?:\d)+;/;
2007: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
2008: var oldest_key;
2009:
2010: for(var i = 1; i < localStorage.length; i++){
2011: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
2012: oldest_key = localStorage.key(i);
2013: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
2014: }
2015: }
2016: localStorage.removeItem(oldest_key);
2017: }
2018: }
2019: localStorage.setItem(key,value);
2020: }
2021: }
2022:
2023: // restore folding status of blocks (on page load)
2024: function restoreState (lastresource) {
2025: if(localStorage.getItem(lastresource) != null){
2026: var key = lastresource;
2027: var value = localStorage.getItem(key);
2028: var regex_delTimestamp = /^\d+;/;
2029:
2030: value.replace(regex_delTimestamp, '');
2031:
2032: var valueArr = value.split(';');
2033: var pairs;
2034: var elements;
2035: for (var i = 0; i < valueArr.length; i++){
2036: pairs = valueArr[i].split(',');
2037: elements = document.getElementsByName(pairs[0]);
2038:
2039: for (var j = 0; j < elements.length; j++){
2040: elements[j].style.display = pairs[1];
2041: if (pairs[1] == "none"){
2042: var regex_id = /([_\\d]+)\$/;
2043: regex_id.exec(pairs[0]);
2044: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2045: }
2046: }
2047: }
2048: }
2049: }
2050:
2051: function getTagList () {
2052:
2053: var stringToSearch = document.lonhomework.innerHTML;
2054:
2055: var ret = new Array();
2056: var regex_findBlock = /(foldblock_.*?)"/g;
2057: var tag_list = stringToSearch.match(regex_findBlock);
2058:
2059: if(tag_list != null){
2060: for(var i = 0; i < tag_list.length; i++){
2061: ret.push(tag_list[i].replace(/"/, ''));
2062: }
2063: }
2064: return ret;
2065: }
2066:
2067: function saveScrollPosition (resource) {
2068: var tag_list = getTagList();
2069:
2070: // we dont always want to jump to the first block
2071: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2072: if(\$(window).scrollTop() > 170){
2073: if(tag_list != null){
2074: var result;
2075: for(var i = 0; i < tag_list.length; i++){
2076: if(isElementInViewport(tag_list[i])){
2077: result += tag_list[i]+';';
2078: }
2079: }
2080: sessionStorage.setItem('anchor_'+resource, result);
2081: }
2082: } else {
2083: // we dont need to save zero, just delete the item to leave everything tidy
2084: sessionStorage.removeItem('anchor_'+resource);
2085: }
2086: }
2087:
2088: function restoreScrollPosition(resource){
2089:
2090: var elem = sessionStorage.getItem('anchor_'+resource);
2091: if(elem != null){
2092: var tag_list = elem.split(';');
2093: var elem_list;
2094:
2095: for(var i = 0; i < tag_list.length; i++){
2096: elem_list = document.getElementsByName(tag_list[i]);
2097:
2098: if(elem_list.length > 0){
2099: elem = elem_list[0];
2100: break;
2101: }
2102: }
2103: elem.scrollIntoView();
2104: }
2105: }
2106:
2107: function isElementInViewport(el) {
2108:
2109: // change to last element instead of first
2110: var elem = document.getElementsByName(el);
2111: var rect = elem[0].getBoundingClientRect();
2112:
2113: return (
2114: rect.top >= 0 &&
2115: rect.left >= 0 &&
2116: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2117: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2118: );
2119: }
2120:
2121: function autosize(depth){
2122: var cmInst = window['cm'+depth];
2123: var fitsizeButton = document.getElementById('fitsize'+depth);
2124:
2125: // is fixed size, switching to dynamic
2126: if (sessionStorage.getItem("autosized_"+depth) == null) {
2127: cmInst.setSize("","auto");
2128: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2129: sessionStorage.setItem("autosized_"+depth, "yes");
2130:
2131: // is dynamic size, switching to fixed
2132: } else {
2133: cmInst.setSize("","300px");
2134: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2135: sessionStorage.removeItem("autosized_"+depth);
2136: }
2137: }
2138:
1.1248 raeburn 2139: $browse_or_search
1.1205 golterma 2140:
2141: // ]]>
2142: </script>
2143: COLORFULEDIT
2144: }
2145:
2146: sub xmleditor_js {
2147: return <<XMLEDIT
2148: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2149: <script type="text/javascript">
2150: // <![CDATA[>
2151:
2152: function saveScrollPosition (resource) {
2153:
2154: var scrollPos = \$(window).scrollTop();
2155: sessionStorage.setItem(resource,scrollPos);
2156: }
2157:
2158: function restoreScrollPosition(resource){
2159:
2160: var scrollPos = sessionStorage.getItem(resource);
2161: \$(window).scrollTop(scrollPos);
2162: }
2163:
2164: // unless internet explorer
2165: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2166:
2167: \$(document).ready(function() {
2168: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2169: });
2170: }
2171:
2172: // inserts text at cursor position into codemirror (xml editor only)
2173: function insertText(text){
2174: cm.focus();
2175: var curPos = cm.getCursor();
2176: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2177: }
2178: // ]]>
2179: </script>
2180: XMLEDIT
2181: }
2182:
2183: sub insert_folding_button {
2184: my $curDepth = $Apache::lonxml::curdepth;
2185: my $lastresource = $env{'request.ambiguous'};
2186:
2187: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2188: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2189: }
2190:
1.1248 raeburn 2191: sub crsauthor_url {
2192: my ($url) = @_;
2193: if ($url eq '') {
2194: $url = $ENV{'REQUEST_URI'};
2195: }
2196: my ($cnum,$cdom);
2197: if ($env{'request.course.id'}) {
2198: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2199: if ($audom ne '' && $auname ne '') {
2200: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2201: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2202: $cnum = $auname;
2203: $cdom = $audom;
2204: }
2205: }
2206: }
2207: return ($cnum,$cdom);
2208: }
2209:
2210: sub import_crsauthor_form {
1.1265 raeburn 2211: my ($form,$firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2212: return (0) unless ($env{'request.course.id'});
2213: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2214: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2215: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2216: return (0) unless (($cnum ne '') && ($cdom ne ''));
2217: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
2218: my @ids=&Apache::lonnet::current_machine_ids();
2219: my ($output,$is_home,$relpath,%subdirs,%files,%selimport_menus);
2220:
2221: if (grep(/^\Q$crshome\E$/,@ids)) {
2222: $is_home = 1;
2223: }
2224: $relpath = "/priv/$cdom/$cnum";
2225: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$relpath,'',\%subdirs,\%files);
2226: my %lt = &Apache::lonlocal::texthash (
2227: fnam => 'Filename',
2228: dire => 'Directory',
2229: );
2230: my $numdirs = scalar(keys(%files));
2231: my (%possexts,$singledir,@singledirfiles);
2232: if ($only) {
2233: map { $possexts{$_} = 1; } split(/\s*,\s*/,$only);
2234: }
2235: my (%nonemptydirs,$possdirs);
2236: if ($numdirs > 1) {
2237: my @order;
2238: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
2239: if (ref($files{$key}) eq 'HASH') {
2240: my $shown = $key;
2241: if ($key eq '') {
2242: $shown = '/';
2243: }
2244: my @ordered = ();
2245: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$key}}))) {
1.1315 raeburn 2246: next if ($file =~ /\.rights$/);
1.1248 raeburn 2247: if ($only) {
2248: my ($ext) = ($file =~ /\.([^.]+)$/);
2249: unless ($possexts{lc($ext)}) {
2250: next;
2251: }
2252: }
2253: $selimport_menus{$key}->{'select2'}->{$file} = $file;
2254: push(@ordered,$file);
2255: }
2256: if (@ordered) {
2257: push(@order,$key);
2258: $nonemptydirs{$key} = 1;
2259: $selimport_menus{$key}->{'text'} = $shown;
2260: $selimport_menus{$key}->{'default'} = '';
2261: $selimport_menus{$key}->{'select2'}->{''} = '';
2262: $selimport_menus{$key}->{'order'} = \@ordered;
2263: }
2264: }
2265: }
2266: $possdirs = scalar(keys(%nonemptydirs));
2267: if ($possdirs > 1) {
2268: my @order = sort { lc($a) cmp lc($b) } (keys(%nonemptydirs));
2269: $output = $lt{'dire'}.
2270: &linked_select_forms($form,'<br />'.
2271: $lt{'fnam'},'',
2272: $firstselectname,$secondselectname,
2273: \%selimport_menus,\@order,
2274: $onchangefirst,'',$suffix).'<br />';
2275: } elsif ($possdirs == 1) {
2276: $singledir = (keys(%nonemptydirs))[0];
2277: if (ref($selimport_menus{$singledir}->{'order'}) eq 'ARRAY') {
2278: @singledirfiles = @{$selimport_menus{$singledir}->{'order'}};
2279: }
2280: delete($selimport_menus{$singledir});
2281: }
2282: } elsif ($numdirs == 1) {
2283: $singledir = (keys(%files))[0];
2284: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$singledir}}))) {
2285: if ($only) {
2286: my ($ext) = ($file =~ /\.([^.]+)$/);
2287: unless ($possexts{lc($ext)}) {
2288: next;
2289: }
1.1315 raeburn 2290: } else {
2291: next if ($file =~ /\.rights$/);
1.1248 raeburn 2292: }
2293: push(@singledirfiles,$file);
2294: }
2295: if (@singledirfiles) {
1.1315 raeburn 2296: $possdirs = 1;
1.1248 raeburn 2297: }
2298: }
2299: if (($possdirs == 1) && (@singledirfiles)) {
2300: my $showdir = $singledir;
2301: if ($singledir eq '') {
2302: $showdir = '/';
2303: }
2304: $output = $lt{'dire'}.
2305: '<select name="'.$firstselectname.'">'.
2306: '<option value="'.$singledir.'">'.$showdir.'</option>'."\n".
2307: '</select><br />'.
2308: $lt{'fnam'}.'<select name="'.$secondselectname.'">'."\n".
2309: '<option value="" selected="selected">'.$lt{'se'}.'</option>'."\n";
2310: foreach my $file (@singledirfiles) {
2311: $output .= '<option value="'.$file.'">'.$file.'</option>'."\n";
2312: }
2313: $output .= '</select><br />'."\n";
2314: }
2315: return ($possdirs,$output);
2316: }
2317:
1.565 albertel 2318: =pod
2319:
1.256 matthew 2320: =head1 Excel and CSV file utility routines
2321:
2322: =cut
2323:
2324: ###############################################################
2325: ###############################################################
2326:
2327: =pod
2328:
1.1162 raeburn 2329: =over 4
2330:
1.648 raeburn 2331: =item * &csv_translate($text)
1.37 matthew 2332:
1.185 www 2333: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2334: format.
2335:
2336: =cut
2337:
1.180 matthew 2338: ###############################################################
2339: ###############################################################
1.37 matthew 2340: sub csv_translate {
2341: my $text = shift;
2342: $text =~ s/\"/\"\"/g;
1.209 albertel 2343: $text =~ s/\n/ /g;
1.37 matthew 2344: return $text;
2345: }
1.180 matthew 2346:
2347: ###############################################################
2348: ###############################################################
2349:
2350: =pod
2351:
1.648 raeburn 2352: =item * &define_excel_formats()
1.180 matthew 2353:
2354: Define some commonly used Excel cell formats.
2355:
2356: Currently supported formats:
2357:
2358: =over 4
2359:
2360: =item header
2361:
2362: =item bold
2363:
2364: =item h1
2365:
2366: =item h2
2367:
2368: =item h3
2369:
1.256 matthew 2370: =item h4
2371:
2372: =item i
2373:
1.180 matthew 2374: =item date
2375:
2376: =back
2377:
2378: Inputs: $workbook
2379:
2380: Returns: $format, a hash reference.
2381:
1.1057 foxr 2382:
1.180 matthew 2383: =cut
2384:
2385: ###############################################################
2386: ###############################################################
2387: sub define_excel_formats {
2388: my ($workbook) = @_;
2389: my $format;
2390: $format->{'header'} = $workbook->add_format(bold => 1,
2391: bottom => 1,
2392: align => 'center');
2393: $format->{'bold'} = $workbook->add_format(bold=>1);
2394: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2395: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2396: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2397: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2398: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2399: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2400: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2401: return $format;
2402: }
2403:
2404: ###############################################################
2405: ###############################################################
1.113 bowersj2 2406:
2407: =pod
2408:
1.648 raeburn 2409: =item * &create_workbook()
1.255 matthew 2410:
2411: Create an Excel worksheet. If it fails, output message on the
2412: request object and return undefs.
2413:
2414: Inputs: Apache request object
2415:
2416: Returns (undef) on failure,
2417: Excel worksheet object, scalar with filename, and formats
2418: from &Apache::loncommon::define_excel_formats on success
2419:
2420: =cut
2421:
2422: ###############################################################
2423: ###############################################################
2424: sub create_workbook {
2425: my ($r) = @_;
2426: #
2427: # Create the excel spreadsheet
2428: my $filename = '/prtspool/'.
1.258 albertel 2429: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2430: time.'_'.rand(1000000000).'.xls';
2431: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2432: if (! defined($workbook)) {
2433: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2434: $r->print(
2435: '<p class="LC_error">'
2436: .&mt('Problems occurred in creating the new Excel file.')
2437: .' '.&mt('This error has been logged.')
2438: .' '.&mt('Please alert your LON-CAPA administrator.')
2439: .'</p>'
2440: );
1.255 matthew 2441: return (undef);
2442: }
2443: #
1.1014 foxr 2444: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2445: #
2446: my $format = &Apache::loncommon::define_excel_formats($workbook);
2447: return ($workbook,$filename,$format);
2448: }
2449:
2450: ###############################################################
2451: ###############################################################
2452:
2453: =pod
2454:
1.648 raeburn 2455: =item * &create_text_file()
1.113 bowersj2 2456:
1.542 raeburn 2457: Create a file to write to and eventually make available to the user.
1.256 matthew 2458: If file creation fails, outputs an error message on the request object and
2459: return undefs.
1.113 bowersj2 2460:
1.256 matthew 2461: Inputs: Apache request object, and file suffix
1.113 bowersj2 2462:
1.256 matthew 2463: Returns (undef) on failure,
2464: Filehandle and filename on success.
1.113 bowersj2 2465:
2466: =cut
2467:
1.256 matthew 2468: ###############################################################
2469: ###############################################################
2470: sub create_text_file {
2471: my ($r,$suffix) = @_;
2472: if (! defined($suffix)) { $suffix = 'txt'; };
2473: my $fh;
2474: my $filename = '/prtspool/'.
1.258 albertel 2475: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2476: time.'_'.rand(1000000000).'.'.$suffix;
2477: $fh = Apache::File->new('>/home/httpd'.$filename);
2478: if (! defined($fh)) {
2479: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2480: $r->print(
2481: '<p class="LC_error">'
2482: .&mt('Problems occurred in creating the output file.')
2483: .' '.&mt('This error has been logged.')
2484: .' '.&mt('Please alert your LON-CAPA administrator.')
2485: .'</p>'
2486: );
1.113 bowersj2 2487: }
1.256 matthew 2488: return ($fh,$filename)
1.113 bowersj2 2489: }
2490:
2491:
1.256 matthew 2492: =pod
1.113 bowersj2 2493:
2494: =back
2495:
2496: =cut
1.37 matthew 2497:
2498: ###############################################################
1.33 matthew 2499: ## Home server <option> list generating code ##
2500: ###############################################################
1.35 matthew 2501:
1.169 www 2502: # ------------------------------------------
2503:
2504: sub domain_select {
1.1289 raeburn 2505: my ($name,$value,$multiple,$incdoms,$excdoms)=@_;
2506: my @possdoms;
2507: if (ref($incdoms) eq 'ARRAY') {
2508: @possdoms = @{$incdoms};
2509: } else {
2510: @possdoms = &Apache::lonnet::all_domains();
2511: }
2512:
1.169 www 2513: my %domains=map {
1.514 albertel 2514: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.1289 raeburn 2515: } @possdoms;
2516:
2517: if ((ref($excdoms) eq 'ARRAY') && (@{$excdoms} > 0)) {
2518: foreach my $dom (@{$excdoms}) {
2519: delete($domains{$dom});
2520: }
2521: }
2522:
1.169 www 2523: if ($multiple) {
2524: $domains{''}=&mt('Any domain');
1.550 albertel 2525: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2526: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2527: } else {
1.550 albertel 2528: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2529: return &select_form($name,$value,\%domains);
1.169 www 2530: }
2531: }
2532:
1.282 albertel 2533: #-------------------------------------------
2534:
2535: =pod
2536:
1.519 raeburn 2537: =head1 Routines for form select boxes
2538:
2539: =over 4
2540:
1.648 raeburn 2541: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2542:
2543: Returns a string containing a <select> element int multiple mode
2544:
2545:
2546: Args:
2547: $name - name of the <select> element
1.506 raeburn 2548: $value - scalar or array ref of values that should already be selected
1.282 albertel 2549: $size - number of rows long the select element is
1.283 albertel 2550: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2551: (shown text should already have been &mt())
1.506 raeburn 2552: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2553:
1.282 albertel 2554: =cut
2555:
2556: #-------------------------------------------
1.169 www 2557: sub multiple_select_form {
1.284 albertel 2558: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2559: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2560: my $output='';
1.191 matthew 2561: if (! defined($size)) {
2562: $size = 4;
1.283 albertel 2563: if (scalar(keys(%$hash))<4) {
2564: $size = scalar(keys(%$hash));
1.191 matthew 2565: }
2566: }
1.734 bisitz 2567: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2568: my @order;
1.506 raeburn 2569: if (ref($order) eq 'ARRAY') {
2570: @order = @{$order};
2571: } else {
2572: @order = sort(keys(%$hash));
1.501 banghart 2573: }
2574: if (exists($$hash{'select_form_order'})) {
2575: @order = @{$$hash{'select_form_order'}};
2576: }
2577:
1.284 albertel 2578: foreach my $key (@order) {
1.356 albertel 2579: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2580: $output.='selected="selected" ' if ($selected{$key});
2581: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2582: }
2583: $output.="</select>\n";
2584: return $output;
2585: }
2586:
1.88 www 2587: #-------------------------------------------
2588:
2589: =pod
2590:
1.1254 raeburn 2591: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2592:
2593: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2594: allow a user to select options from a ref to a hash containing:
2595: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2596: a javascript onchange item, e.g., onchange="this.form.submit();".
2597: An optional arg -- $readonly -- if true will cause the select form
2598: to be disabled, e.g., for the case where an instructor has a section-
2599: specific role, and is viewing/modifying parameters.
1.970 raeburn 2600:
1.88 www 2601: See lonrights.pm for an example invocation and use.
2602:
2603: =cut
2604:
2605: #-------------------------------------------
2606: sub select_form {
1.1228 raeburn 2607: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2608: return unless (ref($hashref) eq 'HASH');
2609: if ($onchange) {
2610: $onchange = ' onchange="'.$onchange.'"';
2611: }
1.1228 raeburn 2612: my $disabled;
2613: if ($readonly) {
2614: $disabled = ' disabled="disabled"';
2615: }
2616: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2617: my @keys;
1.970 raeburn 2618: if (exists($hashref->{'select_form_order'})) {
2619: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2620: } else {
1.970 raeburn 2621: @keys=sort(keys(%{$hashref}));
1.128 albertel 2622: }
1.356 albertel 2623: foreach my $key (@keys) {
2624: $selectform.=
2625: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2626: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2627: ">".$hashref->{$key}."</option>\n";
1.88 www 2628: }
2629: $selectform.="</select>";
2630: return $selectform;
2631: }
2632:
1.475 www 2633: # For display filters
2634:
2635: sub display_filter {
1.1074 raeburn 2636: my ($context) = @_;
1.475 www 2637: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2638: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2639: my $phraseinput = 'hidden';
2640: my $includeinput = 'hidden';
2641: my ($checked,$includetypestext);
2642: if ($env{'form.displayfilter'} eq 'containing') {
2643: $phraseinput = 'text';
2644: if ($context eq 'parmslog') {
2645: $includeinput = 'checkbox';
2646: if ($env{'form.includetypes'}) {
2647: $checked = ' checked="checked"';
2648: }
2649: $includetypestext = &mt('Include parameter types');
2650: }
2651: } else {
2652: $includetypestext = ' ';
2653: }
2654: my ($additional,$secondid,$thirdid);
2655: if ($context eq 'parmslog') {
2656: $additional =
2657: '<label><input type="'.$includeinput.'" name="includetypes"'.
2658: $checked.' name="includetypes" value="1" id="includetypes" />'.
2659: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2660: '</label>';
2661: $secondid = 'includetypes';
2662: $thirdid = 'includetypestext';
2663: }
2664: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2665: '$secondid','$thirdid')";
2666: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2667: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2668: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2669: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2670: &mt('Filter: [_1]',
1.477 www 2671: &select_form($env{'form.displayfilter'},
2672: 'displayfilter',
1.970 raeburn 2673: {'currentfolder' => 'Current folder/page',
1.477 www 2674: 'containing' => 'Containing phrase',
1.1074 raeburn 2675: 'none' => 'None'},$onchange)).' '.
2676: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2677: &HTML::Entities::encode($env{'form.containingphrase'}).
2678: '" />'.$additional;
2679: }
2680:
2681: sub display_filter_js {
2682: my $includetext = &mt('Include parameter types');
2683: return <<"ENDJS";
2684:
2685: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2686: var firstType = 'hidden';
2687: if (setter.options[setter.selectedIndex].value == 'containing') {
2688: firstType = 'text';
2689: }
2690: firstObject = document.getElementById(firstid);
2691: if (typeof(firstObject) == 'object') {
2692: if (firstObject.type != firstType) {
2693: changeInputType(firstObject,firstType);
2694: }
2695: }
2696: if (context == 'parmslog') {
2697: var secondType = 'hidden';
2698: if (firstType == 'text') {
2699: secondType = 'checkbox';
2700: }
2701: secondObject = document.getElementById(secondid);
2702: if (typeof(secondObject) == 'object') {
2703: if (secondObject.type != secondType) {
2704: changeInputType(secondObject,secondType);
2705: }
2706: }
2707: var textItem = document.getElementById(thirdid);
2708: var currtext = textItem.innerHTML;
2709: var newtext;
2710: if (firstType == 'text') {
2711: newtext = '$includetext';
2712: } else {
2713: newtext = ' ';
2714: }
2715: if (currtext != newtext) {
2716: textItem.innerHTML = newtext;
2717: }
2718: }
2719: return;
2720: }
2721:
2722: function changeInputType(oldObject,newType) {
2723: var newObject = document.createElement('input');
2724: newObject.type = newType;
2725: if (oldObject.size) {
2726: newObject.size = oldObject.size;
2727: }
2728: if (oldObject.value) {
2729: newObject.value = oldObject.value;
2730: }
2731: if (oldObject.name) {
2732: newObject.name = oldObject.name;
2733: }
2734: if (oldObject.id) {
2735: newObject.id = oldObject.id;
2736: }
2737: oldObject.parentNode.replaceChild(newObject,oldObject);
2738: return;
2739: }
2740:
2741: ENDJS
1.475 www 2742: }
2743:
1.167 www 2744: sub gradeleveldescription {
2745: my $gradelevel=shift;
2746: my %gradelevels=(0 => 'Not specified',
2747: 1 => 'Grade 1',
2748: 2 => 'Grade 2',
2749: 3 => 'Grade 3',
2750: 4 => 'Grade 4',
2751: 5 => 'Grade 5',
2752: 6 => 'Grade 6',
2753: 7 => 'Grade 7',
2754: 8 => 'Grade 8',
2755: 9 => 'Grade 9',
2756: 10 => 'Grade 10',
2757: 11 => 'Grade 11',
2758: 12 => 'Grade 12',
2759: 13 => 'Grade 13',
2760: 14 => '100 Level',
2761: 15 => '200 Level',
2762: 16 => '300 Level',
2763: 17 => '400 Level',
2764: 18 => 'Graduate Level');
2765: return &mt($gradelevels{$gradelevel});
2766: }
2767:
1.163 www 2768: sub select_level_form {
2769: my ($deflevel,$name)=@_;
2770: unless ($deflevel) { $deflevel=0; }
1.167 www 2771: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2772: for (my $i=0; $i<=18; $i++) {
2773: $selectform.="<option value=\"$i\" ".
1.253 albertel 2774: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2775: ">".&gradeleveldescription($i)."</option>\n";
2776: }
2777: $selectform.="</select>";
2778: return $selectform;
1.163 www 2779: }
1.167 www 2780:
1.35 matthew 2781: #-------------------------------------------
2782:
1.45 matthew 2783: =pod
2784:
1.1256 raeburn 2785: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2786:
2787: Returns a string containing a <select name='$name' size='1'> form to
2788: allow a user to select the domain to preform an operation in.
2789: See loncreateuser.pm for an example invocation and use.
2790:
1.90 www 2791: If the $includeempty flag is set, it also includes an empty choice ("no domain
2792: selected");
2793:
1.743 raeburn 2794: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2795:
1.910 raeburn 2796: 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.
2797:
1.1121 raeburn 2798: The optional $incdoms is a reference to an array of domains which will be the only available options.
2799:
2800: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2801:
1.1256 raeburn 2802: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
2803:
1.35 matthew 2804: =cut
2805:
2806: #-------------------------------------------
1.34 matthew 2807: sub select_dom_form {
1.1256 raeburn 2808: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2809: if ($onchange) {
1.874 raeburn 2810: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2811: }
1.1256 raeburn 2812: if ($disabled) {
2813: $disabled = ' disabled="disabled"';
2814: }
1.1121 raeburn 2815: my (@domains,%exclude);
1.910 raeburn 2816: if (ref($incdoms) eq 'ARRAY') {
2817: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2818: } else {
2819: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2820: }
1.90 www 2821: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2822: if (ref($excdoms) eq 'ARRAY') {
2823: map { $exclude{$_} = 1; } @{$excdoms};
2824: }
1.1256 raeburn 2825: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2826: foreach my $dom (@domains) {
1.1121 raeburn 2827: next if ($exclude{$dom});
1.356 albertel 2828: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2829: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2830: if ($showdomdesc) {
2831: if ($dom ne '') {
2832: my $domdesc = &Apache::lonnet::domain($dom,'description');
2833: if ($domdesc ne '') {
2834: $selectdomain .= ' ('.$domdesc.')';
2835: }
2836: }
2837: }
2838: $selectdomain .= "</option>\n";
1.34 matthew 2839: }
2840: $selectdomain.="</select>";
2841: return $selectdomain;
2842: }
2843:
1.35 matthew 2844: #-------------------------------------------
2845:
1.45 matthew 2846: =pod
2847:
1.648 raeburn 2848: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2849:
1.586 raeburn 2850: input: 4 arguments (two required, two optional) -
2851: $domain - domain of new user
2852: $name - name of form element
2853: $default - Value of 'default' causes a default item to be first
2854: option, and selected by default.
2855: $hide - Value of 'hide' causes hiding of the name of the server,
2856: if 1 server found, or default, if 0 found.
1.594 raeburn 2857: output: returns 2 items:
1.586 raeburn 2858: (a) form element which contains either:
2859: (i) <select name="$name">
2860: <option value="$hostid1">$hostid $servers{$hostid}</option>
2861: <option value="$hostid2">$hostid $servers{$hostid}</option>
2862: </select>
2863: form item if there are multiple library servers in $domain, or
2864: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2865: if there is only one library server in $domain.
2866:
2867: (b) number of library servers found.
2868:
2869: See loncreateuser.pm for example of use.
1.35 matthew 2870:
2871: =cut
2872:
2873: #-------------------------------------------
1.586 raeburn 2874: sub home_server_form_item {
2875: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2876: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2877: my $result;
2878: my $numlib = keys(%servers);
2879: if ($numlib > 1) {
2880: $result .= '<select name="'.$name.'" />'."\n";
2881: if ($default) {
1.804 bisitz 2882: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2883: '</option>'."\n";
2884: }
2885: foreach my $hostid (sort(keys(%servers))) {
2886: $result.= '<option value="'.$hostid.'">'.
2887: $hostid.' '.$servers{$hostid}."</option>\n";
2888: }
2889: $result .= '</select>'."\n";
2890: } elsif ($numlib == 1) {
2891: my $hostid;
2892: foreach my $item (keys(%servers)) {
2893: $hostid = $item;
2894: }
2895: $result .= '<input type="hidden" name="'.$name.'" value="'.
2896: $hostid.'" />';
2897: if (!$hide) {
2898: $result .= $hostid.' '.$servers{$hostid};
2899: }
2900: $result .= "\n";
2901: } elsif ($default) {
2902: $result .= '<input type="hidden" name="'.$name.
2903: '" value="default" />';
2904: if (!$hide) {
2905: $result .= &mt('default');
2906: }
2907: $result .= "\n";
1.33 matthew 2908: }
1.586 raeburn 2909: return ($result,$numlib);
1.33 matthew 2910: }
1.112 bowersj2 2911:
2912: =pod
2913:
1.534 albertel 2914: =back
2915:
1.112 bowersj2 2916: =cut
1.87 matthew 2917:
2918: ###############################################################
1.112 bowersj2 2919: ## Decoding User Agent ##
1.87 matthew 2920: ###############################################################
2921:
2922: =pod
2923:
1.112 bowersj2 2924: =head1 Decoding the User Agent
2925:
2926: =over 4
2927:
2928: =item * &decode_user_agent()
1.87 matthew 2929:
2930: Inputs: $r
2931:
2932: Outputs:
2933:
2934: =over 4
2935:
1.112 bowersj2 2936: =item * $httpbrowser
1.87 matthew 2937:
1.112 bowersj2 2938: =item * $clientbrowser
1.87 matthew 2939:
1.112 bowersj2 2940: =item * $clientversion
1.87 matthew 2941:
1.112 bowersj2 2942: =item * $clientmathml
1.87 matthew 2943:
1.112 bowersj2 2944: =item * $clientunicode
1.87 matthew 2945:
1.112 bowersj2 2946: =item * $clientos
1.87 matthew 2947:
1.1137 raeburn 2948: =item * $clientmobile
2949:
1.1141 raeburn 2950: =item * $clientinfo
2951:
1.1194 raeburn 2952: =item * $clientosversion
2953:
1.87 matthew 2954: =back
2955:
1.157 matthew 2956: =back
2957:
1.87 matthew 2958: =cut
2959:
2960: ###############################################################
2961: ###############################################################
2962: sub decode_user_agent {
1.247 albertel 2963: my ($r)=@_;
1.87 matthew 2964: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2965: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2966: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2967: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2968: my $clientbrowser='unknown';
2969: my $clientversion='0';
2970: my $clientmathml='';
2971: my $clientunicode='0';
1.1137 raeburn 2972: my $clientmobile=0;
1.1194 raeburn 2973: my $clientosversion='';
1.87 matthew 2974: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2975: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2976: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2977: $clientbrowser=$bname;
2978: $httpbrowser=~/$vreg/i;
2979: $clientversion=$1;
2980: $clientmathml=($clientversion>=$minv);
2981: $clientunicode=($clientversion>=$univ);
2982: }
2983: }
2984: my $clientos='unknown';
1.1141 raeburn 2985: my $clientinfo;
1.87 matthew 2986: if (($httpbrowser=~/linux/i) ||
2987: ($httpbrowser=~/unix/i) ||
2988: ($httpbrowser=~/ux/i) ||
2989: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2990: if (($httpbrowser=~/vax/i) ||
2991: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2992: if ($httpbrowser=~/next/i) { $clientos='next'; }
2993: if (($httpbrowser=~/mac/i) ||
2994: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2995: if ($httpbrowser=~/win/i) {
2996: $clientos='win';
2997: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2998: $clientosversion = $1;
2999: }
3000: }
1.87 matthew 3001: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 3002: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
3003: $clientmobile=lc($1);
3004: }
1.1141 raeburn 3005: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
3006: $clientinfo = 'firefox-'.$1;
3007: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
3008: $clientinfo = 'chromeframe-'.$1;
3009: }
1.87 matthew 3010: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 3011: $clientunicode,$clientos,$clientmobile,$clientinfo,
3012: $clientosversion);
1.87 matthew 3013: }
3014:
1.32 matthew 3015: ###############################################################
3016: ## Authentication changing form generation subroutines ##
3017: ###############################################################
3018: ##
3019: ## All of the authform_xxxxxxx subroutines take their inputs in a
3020: ## hash, and have reasonable default values.
3021: ##
3022: ## formname = the name given in the <form> tag.
1.35 matthew 3023: #-------------------------------------------
3024:
1.45 matthew 3025: =pod
3026:
1.112 bowersj2 3027: =head1 Authentication Routines
3028:
3029: =over 4
3030:
1.648 raeburn 3031: =item * &authform_xxxxxx()
1.35 matthew 3032:
3033: The authform_xxxxxx subroutines provide javascript and html forms which
3034: handle some of the conveniences required for authentication forms.
3035: This is not an optimal method, but it works.
3036:
3037: =over 4
3038:
1.112 bowersj2 3039: =item * authform_header
1.35 matthew 3040:
1.112 bowersj2 3041: =item * authform_authorwarning
1.35 matthew 3042:
1.112 bowersj2 3043: =item * authform_nochange
1.35 matthew 3044:
1.112 bowersj2 3045: =item * authform_kerberos
1.35 matthew 3046:
1.112 bowersj2 3047: =item * authform_internal
1.35 matthew 3048:
1.112 bowersj2 3049: =item * authform_filesystem
1.35 matthew 3050:
1.1310 raeburn 3051: =item * authform_lti
3052:
1.35 matthew 3053: =back
3054:
1.648 raeburn 3055: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3056:
1.35 matthew 3057: =cut
3058:
3059: #-------------------------------------------
1.32 matthew 3060: sub authform_header{
3061: my %in = (
3062: formname => 'cu',
1.80 albertel 3063: kerb_def_dom => '',
1.32 matthew 3064: @_,
3065: );
3066: $in{'formname'} = 'document.' . $in{'formname'};
3067: my $result='';
1.80 albertel 3068:
3069: #---------------------------------------------- Code for upper case translation
3070: my $Javascript_toUpperCase;
3071: unless ($in{kerb_def_dom}) {
3072: $Javascript_toUpperCase =<<"END";
3073: switch (choice) {
3074: case 'krb': currentform.elements[choicearg].value =
3075: currentform.elements[choicearg].value.toUpperCase();
3076: break;
3077: default:
3078: }
3079: END
3080: } else {
3081: $Javascript_toUpperCase = "";
3082: }
3083:
1.165 raeburn 3084: my $radioval = "'nochange'";
1.591 raeburn 3085: if (defined($in{'curr_authtype'})) {
3086: if ($in{'curr_authtype'} ne '') {
3087: $radioval = "'".$in{'curr_authtype'}."arg'";
3088: }
1.174 matthew 3089: }
1.165 raeburn 3090: my $argfield = 'null';
1.591 raeburn 3091: if (defined($in{'mode'})) {
1.165 raeburn 3092: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3093: if (defined($in{'curr_autharg'})) {
3094: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3095: $argfield = "'$in{'curr_autharg'}'";
3096: }
3097: }
3098: }
3099: }
3100:
1.32 matthew 3101: $result.=<<"END";
3102: var current = new Object();
1.165 raeburn 3103: current.radiovalue = $radioval;
3104: current.argfield = $argfield;
1.32 matthew 3105:
3106: function changed_radio(choice,currentform) {
3107: var choicearg = choice + 'arg';
3108: // If a radio button in changed, we need to change the argfield
3109: if (current.radiovalue != choice) {
3110: current.radiovalue = choice;
3111: if (current.argfield != null) {
3112: currentform.elements[current.argfield].value = '';
3113: }
3114: if (choice == 'nochange') {
3115: current.argfield = null;
3116: } else {
3117: current.argfield = choicearg;
3118: switch(choice) {
3119: case 'krb':
3120: currentform.elements[current.argfield].value =
3121: "$in{'kerb_def_dom'}";
3122: break;
3123: default:
3124: break;
3125: }
3126: }
3127: }
3128: return;
3129: }
1.22 www 3130:
1.32 matthew 3131: function changed_text(choice,currentform) {
3132: var choicearg = choice + 'arg';
3133: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3134: $Javascript_toUpperCase
1.32 matthew 3135: // clear old field
3136: if ((current.argfield != choicearg) && (current.argfield != null)) {
3137: currentform.elements[current.argfield].value = '';
3138: }
3139: current.argfield = choicearg;
3140: }
3141: set_auth_radio_buttons(choice,currentform);
3142: return;
1.20 www 3143: }
1.32 matthew 3144:
3145: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3146: var numauthchoices = currentform.login.length;
3147: if (typeof numauthchoices == "undefined") {
3148: return;
3149: }
1.32 matthew 3150: var i=0;
1.986 raeburn 3151: while (i < numauthchoices) {
1.32 matthew 3152: if (currentform.login[i].value == newvalue) { break; }
3153: i++;
3154: }
1.986 raeburn 3155: if (i == numauthchoices) {
1.32 matthew 3156: return;
3157: }
3158: current.radiovalue = newvalue;
3159: currentform.login[i].checked = true;
3160: return;
3161: }
3162: END
3163: return $result;
3164: }
3165:
1.1106 raeburn 3166: sub authform_authorwarning {
1.32 matthew 3167: my $result='';
1.144 matthew 3168: $result='<i>'.
3169: &mt('As a general rule, only authors or co-authors should be '.
3170: 'filesystem authenticated '.
3171: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3172: return $result;
3173: }
3174:
1.1106 raeburn 3175: sub authform_nochange {
1.32 matthew 3176: my %in = (
3177: formname => 'document.cu',
3178: kerb_def_dom => 'MSU.EDU',
3179: @_,
3180: );
1.1106 raeburn 3181: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3182: my $result;
1.1104 raeburn 3183: if (!$authnum) {
1.1105 raeburn 3184: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3185: } else {
3186: $result = '<label>'.&mt('[_1] Do not change login data',
3187: '<input type="radio" name="login" value="nochange" '.
3188: 'checked="checked" onclick="'.
1.281 albertel 3189: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3190: '</label>';
1.586 raeburn 3191: }
1.32 matthew 3192: return $result;
3193: }
3194:
1.591 raeburn 3195: sub authform_kerberos {
1.32 matthew 3196: my %in = (
3197: formname => 'document.cu',
3198: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3199: kerb_def_auth => 'krb4',
1.32 matthew 3200: @_,
3201: );
1.586 raeburn 3202: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3203: $autharg,$jscall,$disabled);
1.1106 raeburn 3204: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3205: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3206: $check5 = ' checked="checked"';
1.80 albertel 3207: } else {
1.772 bisitz 3208: $check4 = ' checked="checked"';
1.80 albertel 3209: }
1.1259 raeburn 3210: if ($in{'readonly'}) {
3211: $disabled = ' disabled="disabled"';
3212: }
1.165 raeburn 3213: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3214: if (defined($in{'curr_authtype'})) {
3215: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3216: $krbcheck = ' checked="checked"';
1.623 raeburn 3217: if (defined($in{'mode'})) {
3218: if ($in{'mode'} eq 'modifyuser') {
3219: $krbcheck = '';
3220: }
3221: }
1.591 raeburn 3222: if (defined($in{'curr_kerb_ver'})) {
3223: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3224: $check5 = ' checked="checked"';
1.591 raeburn 3225: $check4 = '';
3226: } else {
1.772 bisitz 3227: $check4 = ' checked="checked"';
1.591 raeburn 3228: $check5 = '';
3229: }
1.586 raeburn 3230: }
1.591 raeburn 3231: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3232: $krbarg = $in{'curr_autharg'};
3233: }
1.586 raeburn 3234: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3235: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3236: $result =
3237: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3238: $in{'curr_autharg'},$krbver);
3239: } else {
3240: $result =
3241: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3242: }
3243: return $result;
3244: }
3245: }
3246: } else {
3247: if ($authnum == 1) {
1.784 bisitz 3248: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3249: }
3250: }
1.586 raeburn 3251: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3252: return;
1.587 raeburn 3253: } elsif ($authtype eq '') {
1.591 raeburn 3254: if (defined($in{'mode'})) {
1.587 raeburn 3255: if ($in{'mode'} eq 'modifycourse') {
3256: if ($authnum == 1) {
1.1259 raeburn 3257: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3258: }
3259: }
3260: }
1.586 raeburn 3261: }
3262: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3263: if ($authtype eq '') {
3264: $authtype = '<input type="radio" name="login" value="krb" '.
3265: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3266: $krbcheck.$disabled.' />';
1.586 raeburn 3267: }
3268: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3269: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3270: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3271: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3272: $in{'curr_authtype'} eq 'krb4')) {
3273: $result .= &mt
1.144 matthew 3274: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3275: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3276: '<label>'.$authtype,
1.281 albertel 3277: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3278: 'value="'.$krbarg.'" '.
1.1259 raeburn 3279: 'onchange="'.$jscall.'"'.$disabled.' />',
3280: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3281: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3282: '</label>');
1.586 raeburn 3283: } elsif ($can_assign{'krb4'}) {
3284: $result .= &mt
3285: ('[_1] Kerberos authenticated with domain [_2] '.
3286: '[_3] Version 4 [_4]',
3287: '<label>'.$authtype,
3288: '</label><input type="text" size="10" name="krbarg" '.
3289: 'value="'.$krbarg.'" '.
1.1259 raeburn 3290: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3291: '<label><input type="hidden" name="krbver" value="4" />',
3292: '</label>');
3293: } elsif ($can_assign{'krb5'}) {
3294: $result .= &mt
3295: ('[_1] Kerberos authenticated with domain [_2] '.
3296: '[_3] Version 5 [_4]',
3297: '<label>'.$authtype,
3298: '</label><input type="text" size="10" name="krbarg" '.
3299: 'value="'.$krbarg.'" '.
1.1259 raeburn 3300: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3301: '<label><input type="hidden" name="krbver" value="5" />',
3302: '</label>');
3303: }
1.32 matthew 3304: return $result;
3305: }
3306:
1.1106 raeburn 3307: sub authform_internal {
1.586 raeburn 3308: my %in = (
1.32 matthew 3309: formname => 'document.cu',
3310: kerb_def_dom => 'MSU.EDU',
3311: @_,
3312: );
1.1259 raeburn 3313: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3314: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3315: if ($in{'readonly'}) {
3316: $disabled = ' disabled="disabled"';
3317: }
1.591 raeburn 3318: if (defined($in{'curr_authtype'})) {
3319: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3320: if ($can_assign{'int'}) {
1.772 bisitz 3321: $intcheck = 'checked="checked" ';
1.623 raeburn 3322: if (defined($in{'mode'})) {
3323: if ($in{'mode'} eq 'modifyuser') {
3324: $intcheck = '';
3325: }
3326: }
1.591 raeburn 3327: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3328: $intarg = $in{'curr_autharg'};
3329: }
3330: } else {
3331: $result = &mt('Currently internally authenticated.');
3332: return $result;
1.165 raeburn 3333: }
3334: }
1.586 raeburn 3335: } else {
3336: if ($authnum == 1) {
1.784 bisitz 3337: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3338: }
3339: }
3340: if (!$can_assign{'int'}) {
3341: return;
1.587 raeburn 3342: } elsif ($authtype eq '') {
1.591 raeburn 3343: if (defined($in{'mode'})) {
1.587 raeburn 3344: if ($in{'mode'} eq 'modifycourse') {
3345: if ($authnum == 1) {
1.1259 raeburn 3346: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3347: }
3348: }
3349: }
1.165 raeburn 3350: }
1.586 raeburn 3351: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3352: if ($authtype eq '') {
3353: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3354: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3355: }
1.605 bisitz 3356: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3357: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3358: $result = &mt
1.144 matthew 3359: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3360: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3361: $result.='<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.intarg.type='."'text'".' } else { this.form.intarg.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>';
1.32 matthew 3362: return $result;
3363: }
3364:
1.1104 raeburn 3365: sub authform_local {
1.32 matthew 3366: my %in = (
3367: formname => 'document.cu',
3368: kerb_def_dom => 'MSU.EDU',
3369: @_,
3370: );
1.1259 raeburn 3371: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3372: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3373: if ($in{'readonly'}) {
3374: $disabled = ' disabled="disabled"';
3375: }
1.591 raeburn 3376: if (defined($in{'curr_authtype'})) {
3377: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3378: if ($can_assign{'loc'}) {
1.772 bisitz 3379: $loccheck = 'checked="checked" ';
1.623 raeburn 3380: if (defined($in{'mode'})) {
3381: if ($in{'mode'} eq 'modifyuser') {
3382: $loccheck = '';
3383: }
3384: }
1.591 raeburn 3385: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3386: $locarg = $in{'curr_autharg'};
3387: }
3388: } else {
3389: $result = &mt('Currently using local (institutional) authentication.');
3390: return $result;
1.165 raeburn 3391: }
3392: }
1.586 raeburn 3393: } else {
3394: if ($authnum == 1) {
1.784 bisitz 3395: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3396: }
3397: }
3398: if (!$can_assign{'loc'}) {
3399: return;
1.587 raeburn 3400: } elsif ($authtype eq '') {
1.591 raeburn 3401: if (defined($in{'mode'})) {
1.587 raeburn 3402: if ($in{'mode'} eq 'modifycourse') {
3403: if ($authnum == 1) {
1.1259 raeburn 3404: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3405: }
3406: }
3407: }
1.165 raeburn 3408: }
1.586 raeburn 3409: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3410: if ($authtype eq '') {
3411: $authtype = '<input type="radio" name="login" value="loc" '.
3412: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3413: $jscall.'"'.$disabled.' />';
1.586 raeburn 3414: }
3415: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3416: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3417: $result = &mt('[_1] Local Authentication with argument [_2]',
3418: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3419: return $result;
3420: }
3421:
1.1106 raeburn 3422: sub authform_filesystem {
1.32 matthew 3423: my %in = (
3424: formname => 'document.cu',
3425: kerb_def_dom => 'MSU.EDU',
3426: @_,
3427: );
1.1259 raeburn 3428: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3429: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3430: if ($in{'readonly'}) {
3431: $disabled = ' disabled="disabled"';
3432: }
1.591 raeburn 3433: if (defined($in{'curr_authtype'})) {
3434: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3435: if ($can_assign{'fsys'}) {
1.772 bisitz 3436: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3437: if (defined($in{'mode'})) {
3438: if ($in{'mode'} eq 'modifyuser') {
3439: $fsyscheck = '';
3440: }
3441: }
1.586 raeburn 3442: } else {
3443: $result = &mt('Currently Filesystem Authenticated.');
3444: return $result;
1.1259 raeburn 3445: }
1.586 raeburn 3446: }
3447: } else {
3448: if ($authnum == 1) {
1.784 bisitz 3449: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3450: }
3451: }
3452: if (!$can_assign{'fsys'}) {
3453: return;
1.587 raeburn 3454: } elsif ($authtype eq '') {
1.591 raeburn 3455: if (defined($in{'mode'})) {
1.587 raeburn 3456: if ($in{'mode'} eq 'modifycourse') {
3457: if ($authnum == 1) {
1.1259 raeburn 3458: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3459: }
3460: }
3461: }
1.586 raeburn 3462: }
3463: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3464: if ($authtype eq '') {
3465: $authtype = '<input type="radio" name="login" value="fsys" '.
3466: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3467: $jscall.'"'.$disabled.' />';
1.586 raeburn 3468: }
1.1310 raeburn 3469: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3470: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3471: $result = &mt
1.144 matthew 3472: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1310 raeburn 3473: '<label>'.$authtype,'</label>'.$autharg);
3474: return $result;
3475: }
3476:
3477: sub authform_lti {
3478: my %in = (
3479: formname => 'document.cu',
3480: kerb_def_dom => 'MSU.EDU',
3481: @_,
3482: );
3483: my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
3484: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
3485: if ($in{'readonly'}) {
3486: $disabled = ' disabled="disabled"';
3487: }
3488: if (defined($in{'curr_authtype'})) {
3489: if ($in{'curr_authtype'} eq 'lti') {
3490: if ($can_assign{'lti'}) {
3491: $lticheck = 'checked="checked" ';
3492: if (defined($in{'mode'})) {
3493: if ($in{'mode'} eq 'modifyuser') {
3494: $lticheck = '';
3495: }
3496: }
3497: } else {
3498: $result = &mt('Currently LTI Authenticated.');
3499: return $result;
3500: }
3501: }
3502: } else {
3503: if ($authnum == 1) {
3504: $authtype = '<input type="hidden" name="login" value="lti" />';
3505: }
3506: }
3507: if (!$can_assign{'lti'}) {
3508: return;
3509: } elsif ($authtype eq '') {
3510: if (defined($in{'mode'})) {
3511: if ($in{'mode'} eq 'modifycourse') {
3512: if ($authnum == 1) {
3513: $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';
3514: }
3515: }
3516: }
3517: }
3518: $jscall = "javascript:changed_radio('lti',$in{'formname'});";
3519: if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
3520: $authtype = '<input type="radio" name="login" value="lti" '.
3521: $lticheck.' onchange="'.$jscall.'" onclick="'.
3522: $jscall.'"'.$disabled.' />';
3523: }
3524: $autharg = '<input type="hidden" name="ltiarg" value="" />';
3525: if ($authtype) {
3526: $result = &mt('[_1] LTI Authenticated',
3527: '<label>'.$authtype.'</label>'.$autharg);
3528: } else {
3529: $result = '<b>'.&mt('LTI Authenticated').'</b>'.
3530: $autharg;
3531: }
1.32 matthew 3532: return $result;
3533: }
3534:
1.586 raeburn 3535: sub get_assignable_auth {
3536: my ($dom) = @_;
3537: if ($dom eq '') {
3538: $dom = $env{'request.role.domain'};
3539: }
3540: my %can_assign = (
3541: krb4 => 1,
3542: krb5 => 1,
3543: int => 1,
3544: loc => 1,
1.1310 raeburn 3545: lti => 1,
1.586 raeburn 3546: );
3547: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3548: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3549: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3550: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3551: my $context;
3552: if ($env{'request.role'} =~ /^au/) {
3553: $context = 'author';
1.1259 raeburn 3554: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3555: $context = 'domain';
3556: } elsif ($env{'request.course.id'}) {
3557: $context = 'course';
3558: }
3559: if ($context) {
3560: if (ref($authhash->{$context}) eq 'HASH') {
3561: %can_assign = %{$authhash->{$context}};
3562: }
3563: }
3564: }
3565: }
3566: my $authnum = 0;
3567: foreach my $key (keys(%can_assign)) {
3568: if ($can_assign{$key}) {
3569: $authnum ++;
3570: }
3571: }
3572: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3573: $authnum --;
3574: }
3575: return ($authnum,%can_assign);
3576: }
3577:
1.1331 raeburn 3578: sub check_passwd_rules {
3579: my ($domain,$plainpass) = @_;
3580: my %passwdconf = &Apache::lonnet::get_passwdconf($domain);
3581: my ($min,$max,@chars,@brokerule,$warning);
1.1333 raeburn 3582: $min = $Apache::lonnet::passwdmin;
1.1331 raeburn 3583: if (ref($passwdconf{'chars'}) eq 'ARRAY') {
3584: if ($passwdconf{'min'} =~ /^\d+$/) {
1.1333 raeburn 3585: if ($passwdconf{'min'} > $min) {
3586: $min = $passwdconf{'min'};
3587: }
1.1331 raeburn 3588: }
3589: if ($passwdconf{'max'} =~ /^\d+$/) {
3590: $max = $passwdconf{'max'};
3591: }
3592: @chars = @{$passwdconf{'chars'}};
3593: }
3594: if (($min) && (length($plainpass) < $min)) {
3595: push(@brokerule,'min');
3596: }
3597: if (($max) && (length($plainpass) > $max)) {
3598: push(@brokerule,'max');
3599: }
3600: if (@chars) {
3601: my %rules;
3602: map { $rules{$_} = 1; } @chars;
3603: if ($rules{'uc'}) {
3604: unless ($plainpass =~ /[A-Z]/) {
3605: push(@brokerule,'uc');
3606: }
3607: }
3608: if ($rules{'lc'}) {
1.1332 raeburn 3609: unless ($plainpass =~ /[a-z]/) {
1.1331 raeburn 3610: push(@brokerule,'lc');
3611: }
3612: }
3613: if ($rules{'num'}) {
3614: unless ($plainpass =~ /\d/) {
3615: push(@brokerule,'num');
3616: }
3617: }
3618: if ($rules{'spec'}) {
3619: unless ($plainpass =~ /[!"#$%&'()*+,\-.\/:;<=>?@[\\\]^_`{|}~]/) {
3620: push(@brokerule,'spec');
3621: }
3622: }
3623: }
3624: if (@brokerule) {
3625: my %rulenames = &Apache::lonlocal::texthash(
3626: uc => 'At least one upper case letter',
3627: lc => 'At least one lower case letter',
3628: num => 'At least one number',
3629: spec => 'At least one non-alphanumeric',
3630: );
3631: $rulenames{'uc'} .= ': ABCDEFGHIJKLMNOPQRSTUVWXYZ';
3632: $rulenames{'lc'} .= ': abcdefghijklmnopqrstuvwxyz';
3633: $rulenames{'num'} .= ': 0123456789';
3634: $rulenames{'spec'} .= ': !"\#$%&\'()*+,-./:;<=>?@[\]^_\`{|}~';
3635: $rulenames{'min'} = &mt('Minimum password length: [_1]',$min);
3636: $rulenames{'max'} = &mt('Maximum password length: [_1]',$max);
3637: $warning = &mt('Password did not satisfy the following:').'<ul>';
1.1336 raeburn 3638: foreach my $rule ('min','max','uc','lc','num','spec') {
1.1331 raeburn 3639: if (grep(/^$rule$/,@brokerule)) {
3640: $warning .= '<li>'.$rulenames{$rule}.'</li>';
3641: }
3642: }
3643: $warning .= '</ul>';
3644: }
1.1332 raeburn 3645: if (wantarray) {
3646: return @brokerule;
3647: }
1.1331 raeburn 3648: return $warning;
3649: }
3650:
1.80 albertel 3651: ###############################################################
3652: ## Get Kerberos Defaults for Domain ##
3653: ###############################################################
3654: ##
3655: ## Returns default kerberos version and an associated argument
3656: ## as listed in file domain.tab. If not listed, provides
3657: ## appropriate default domain and kerberos version.
3658: ##
3659: #-------------------------------------------
3660:
3661: =pod
3662:
1.648 raeburn 3663: =item * &get_kerberos_defaults()
1.80 albertel 3664:
3665: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3666: version and domain. If not found, it defaults to version 4 and the
3667: domain of the server.
1.80 albertel 3668:
1.648 raeburn 3669: =over 4
3670:
1.80 albertel 3671: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3672:
1.648 raeburn 3673: =back
3674:
3675: =back
3676:
1.80 albertel 3677: =cut
3678:
3679: #-------------------------------------------
3680: sub get_kerberos_defaults {
3681: my $domain=shift;
1.641 raeburn 3682: my ($krbdef,$krbdefdom);
3683: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3684: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3685: $krbdef = $domdefaults{'auth_def'};
3686: $krbdefdom = $domdefaults{'auth_arg_def'};
3687: } else {
1.80 albertel 3688: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3689: my $krbdefdom=$1;
3690: $krbdefdom=~tr/a-z/A-Z/;
3691: $krbdef = "krb4";
3692: }
3693: return ($krbdef,$krbdefdom);
3694: }
1.112 bowersj2 3695:
1.32 matthew 3696:
1.46 matthew 3697: ###############################################################
3698: ## Thesaurus Functions ##
3699: ###############################################################
1.20 www 3700:
1.46 matthew 3701: =pod
1.20 www 3702:
1.112 bowersj2 3703: =head1 Thesaurus Functions
3704:
3705: =over 4
3706:
1.648 raeburn 3707: =item * &initialize_keywords()
1.46 matthew 3708:
3709: Initializes the package variable %Keywords if it is empty. Uses the
3710: package variable $thesaurus_db_file.
3711:
3712: =cut
3713:
3714: ###################################################
3715:
3716: sub initialize_keywords {
3717: return 1 if (scalar keys(%Keywords));
3718: # If we are here, %Keywords is empty, so fill it up
3719: # Make sure the file we need exists...
3720: if (! -e $thesaurus_db_file) {
3721: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3722: " failed because it does not exist");
3723: return 0;
3724: }
3725: # Set up the hash as a database
3726: my %thesaurus_db;
3727: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3728: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3729: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3730: $thesaurus_db_file);
3731: return 0;
3732: }
3733: # Get the average number of appearances of a word.
3734: my $avecount = $thesaurus_db{'average.count'};
3735: # Put keywords (those that appear > average) into %Keywords
3736: while (my ($word,$data)=each (%thesaurus_db)) {
3737: my ($count,undef) = split /:/,$data;
3738: $Keywords{$word}++ if ($count > $avecount);
3739: }
3740: untie %thesaurus_db;
3741: # Remove special values from %Keywords.
1.356 albertel 3742: foreach my $value ('total.count','average.count') {
3743: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3744: }
1.46 matthew 3745: return 1;
3746: }
3747:
3748: ###################################################
3749:
3750: =pod
3751:
1.648 raeburn 3752: =item * &keyword($word)
1.46 matthew 3753:
3754: Returns true if $word is a keyword. A keyword is a word that appears more
3755: than the average number of times in the thesaurus database. Calls
3756: &initialize_keywords
3757:
3758: =cut
3759:
3760: ###################################################
1.20 www 3761:
3762: sub keyword {
1.46 matthew 3763: return if (!&initialize_keywords());
3764: my $word=lc(shift());
3765: $word=~s/\W//g;
3766: return exists($Keywords{$word});
1.20 www 3767: }
1.46 matthew 3768:
3769: ###############################################################
3770:
3771: =pod
1.20 www 3772:
1.648 raeburn 3773: =item * &get_related_words()
1.46 matthew 3774:
1.160 matthew 3775: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3776: an array of words. If the keyword is not in the thesaurus, an empty array
3777: will be returned. The order of the words returned is determined by the
3778: database which holds them.
3779:
3780: Uses global $thesaurus_db_file.
3781:
1.1057 foxr 3782:
1.46 matthew 3783: =cut
3784:
3785: ###############################################################
3786: sub get_related_words {
3787: my $keyword = shift;
3788: my %thesaurus_db;
3789: if (! -e $thesaurus_db_file) {
3790: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3791: "failed because the file does not exist");
3792: return ();
3793: }
3794: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3795: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3796: return ();
3797: }
3798: my @Words=();
1.429 www 3799: my $count=0;
1.46 matthew 3800: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3801: # The first element is the number of times
3802: # the word appears. We do not need it now.
1.429 www 3803: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3804: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3805: my $threshold=$mostfrequentcount/10;
3806: foreach my $possibleword (@RelatedWords) {
3807: my ($word,$wordcount)=split(/\,/,$possibleword);
3808: if ($wordcount>$threshold) {
3809: push(@Words,$word);
3810: $count++;
3811: if ($count>10) { last; }
3812: }
1.20 www 3813: }
3814: }
1.46 matthew 3815: untie %thesaurus_db;
3816: return @Words;
1.14 harris41 3817: }
1.1090 foxr 3818: ###############################################################
3819: #
3820: # Spell checking
3821: #
3822:
3823: =pod
3824:
1.1142 raeburn 3825: =back
3826:
1.1090 foxr 3827: =head1 Spell checking
3828:
3829: =over 4
3830:
3831: =item * &check_spelling($wordlist $language)
3832:
3833: Takes a string containing words and feeds it to an external
3834: spellcheck program via a pipeline. Returns a string containing
3835: them mis-spelled words.
3836:
3837: Parameters:
3838:
3839: =over 4
3840:
3841: =item - $wordlist
3842:
3843: String that will be fed into the spellcheck program.
3844:
3845: =item - $language
3846:
3847: Language string that specifies the language for which the spell
3848: check will be performed.
3849:
3850: =back
3851:
3852: =back
3853:
3854: Note: This sub assumes that aspell is installed.
3855:
3856:
3857: =cut
3858:
1.46 matthew 3859:
1.1090 foxr 3860: sub check_spelling {
3861: my ($wordlist, $language) = @_;
1.1091 foxr 3862: my @misspellings;
3863:
3864: # Generate the speller and set the langauge.
3865: # if explicitly selected:
1.1090 foxr 3866:
1.1091 foxr 3867: my $speller = Text::Aspell->new;
1.1090 foxr 3868: if ($language) {
1.1091 foxr 3869: $speller->set_option('lang', $language);
1.1090 foxr 3870: }
3871:
1.1091 foxr 3872: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3873:
1.1091 foxr 3874: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3875:
1.1091 foxr 3876: foreach my $word (@words) {
3877: if(! $speller->check($word)) {
3878: push(@misspellings, $word);
1.1090 foxr 3879: }
3880: }
1.1091 foxr 3881: return join(' ', @misspellings);
3882:
1.1090 foxr 3883: }
3884:
1.61 www 3885: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3886: =pod
3887:
1.112 bowersj2 3888: =head1 User Name Functions
3889:
3890: =over 4
3891:
1.648 raeburn 3892: =item * &plainname($uname,$udom,$first)
1.81 albertel 3893:
1.112 bowersj2 3894: Takes a users logon name and returns it as a string in
1.226 albertel 3895: "first middle last generation" form
3896: if $first is set to 'lastname' then it returns it as
3897: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3898:
3899: =cut
1.61 www 3900:
1.295 www 3901:
1.81 albertel 3902: ###############################################################
1.61 www 3903: sub plainname {
1.226 albertel 3904: my ($uname,$udom,$first)=@_;
1.537 albertel 3905: return if (!defined($uname) || !defined($udom));
1.295 www 3906: my %names=&getnames($uname,$udom);
1.226 albertel 3907: my $name=&Apache::lonnet::format_name($names{'firstname'},
3908: $names{'middlename'},
3909: $names{'lastname'},
3910: $names{'generation'},$first);
3911: $name=~s/^\s+//;
1.62 www 3912: $name=~s/\s+$//;
3913: $name=~s/\s+/ /g;
1.353 albertel 3914: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3915: return $name;
1.61 www 3916: }
1.66 www 3917:
3918: # -------------------------------------------------------------------- Nickname
1.81 albertel 3919: =pod
3920:
1.648 raeburn 3921: =item * &nickname($uname,$udom)
1.81 albertel 3922:
3923: Gets a users name and returns it as a string as
3924:
3925: ""nickname""
1.66 www 3926:
1.81 albertel 3927: if the user has a nickname or
3928:
3929: "first middle last generation"
3930:
3931: if the user does not
3932:
3933: =cut
1.66 www 3934:
3935: sub nickname {
3936: my ($uname,$udom)=@_;
1.537 albertel 3937: return if (!defined($uname) || !defined($udom));
1.295 www 3938: my %names=&getnames($uname,$udom);
1.68 albertel 3939: my $name=$names{'nickname'};
1.66 www 3940: if ($name) {
3941: $name='"'.$name.'"';
3942: } else {
3943: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3944: $names{'lastname'}.' '.$names{'generation'};
3945: $name=~s/\s+$//;
3946: $name=~s/\s+/ /g;
3947: }
3948: return $name;
3949: }
3950:
1.295 www 3951: sub getnames {
3952: my ($uname,$udom)=@_;
1.537 albertel 3953: return if (!defined($uname) || !defined($udom));
1.433 albertel 3954: if ($udom eq 'public' && $uname eq 'public') {
3955: return ('lastname' => &mt('Public'));
3956: }
1.295 www 3957: my $id=$uname.':'.$udom;
3958: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3959: if ($cached) {
3960: return %{$names};
3961: } else {
3962: my %loadnames=&Apache::lonnet::get('environment',
3963: ['firstname','middlename','lastname','generation','nickname'],
3964: $udom,$uname);
3965: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3966: return %loadnames;
3967: }
3968: }
1.61 www 3969:
1.542 raeburn 3970: # -------------------------------------------------------------------- getemails
1.648 raeburn 3971:
1.542 raeburn 3972: =pod
3973:
1.648 raeburn 3974: =item * &getemails($uname,$udom)
1.542 raeburn 3975:
3976: Gets a user's email information and returns it as a hash with keys:
3977: notification, critnotification, permanentemail
3978:
3979: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3980: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3981:
1.648 raeburn 3982:
1.542 raeburn 3983: =cut
3984:
1.648 raeburn 3985:
1.466 albertel 3986: sub getemails {
3987: my ($uname,$udom)=@_;
3988: if ($udom eq 'public' && $uname eq 'public') {
3989: return;
3990: }
1.467 www 3991: if (!$udom) { $udom=$env{'user.domain'}; }
3992: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3993: my $id=$uname.':'.$udom;
3994: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3995: if ($cached) {
3996: return %{$names};
3997: } else {
3998: my %loadnames=&Apache::lonnet::get('environment',
3999: ['notification','critnotification',
4000: 'permanentemail'],
4001: $udom,$uname);
4002: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
4003: return %loadnames;
4004: }
4005: }
4006:
1.551 albertel 4007: sub flush_email_cache {
4008: my ($uname,$udom)=@_;
4009: if (!$udom) { $udom =$env{'user.domain'}; }
4010: if (!$uname) { $uname=$env{'user.name'}; }
4011: return if ($udom eq 'public' && $uname eq 'public');
4012: my $id=$uname.':'.$udom;
4013: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
4014: }
4015:
1.728 raeburn 4016: # -------------------------------------------------------------------- getlangs
4017:
4018: =pod
4019:
4020: =item * &getlangs($uname,$udom)
4021:
4022: Gets a user's language preference and returns it as a hash with key:
4023: language.
4024:
4025: =cut
4026:
4027:
4028: sub getlangs {
4029: my ($uname,$udom) = @_;
4030: if (!$udom) { $udom =$env{'user.domain'}; }
4031: if (!$uname) { $uname=$env{'user.name'}; }
4032: my $id=$uname.':'.$udom;
4033: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
4034: if ($cached) {
4035: return %{$langs};
4036: } else {
4037: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
4038: $udom,$uname);
4039: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
4040: return %loadlangs;
4041: }
4042: }
4043:
4044: sub flush_langs_cache {
4045: my ($uname,$udom)=@_;
4046: if (!$udom) { $udom =$env{'user.domain'}; }
4047: if (!$uname) { $uname=$env{'user.name'}; }
4048: return if ($udom eq 'public' && $uname eq 'public');
4049: my $id=$uname.':'.$udom;
4050: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
4051: }
4052:
1.61 www 4053: # ------------------------------------------------------------------ Screenname
1.81 albertel 4054:
4055: =pod
4056:
1.648 raeburn 4057: =item * &screenname($uname,$udom)
1.81 albertel 4058:
4059: Gets a users screenname and returns it as a string
4060:
4061: =cut
1.61 www 4062:
4063: sub screenname {
4064: my ($uname,$udom)=@_;
1.258 albertel 4065: if ($uname eq $env{'user.name'} &&
4066: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 4067: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 4068: return $names{'screenname'};
1.62 www 4069: }
4070:
1.212 albertel 4071:
1.802 bisitz 4072: # ------------------------------------------------------------- Confirm Wrapper
4073: =pod
4074:
1.1142 raeburn 4075: =item * &confirmwrapper($message)
1.802 bisitz 4076:
4077: Wrap messages about completion of operation in box
4078:
4079: =cut
4080:
4081: sub confirmwrapper {
4082: my ($message)=@_;
4083: if ($message) {
4084: return "\n".'<div class="LC_confirm_box">'."\n"
4085: .$message."\n"
4086: .'</div>'."\n";
4087: } else {
4088: return $message;
4089: }
4090: }
4091:
1.62 www 4092: # ------------------------------------------------------------- Message Wrapper
4093:
4094: sub messagewrapper {
1.369 www 4095: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 4096: return
1.441 albertel 4097: '<a href="/adm/email?compose=individual&'.
4098: 'recname='.$username.'&recdom='.$domain.
4099: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 4100: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 4101: }
1.802 bisitz 4102:
1.74 www 4103: # --------------------------------------------------------------- Notes Wrapper
4104:
4105: sub noteswrapper {
4106: my ($link,$un,$do)=@_;
4107: return
1.896 amueller 4108: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 4109: }
1.802 bisitz 4110:
1.62 www 4111: # ------------------------------------------------------------- Aboutme Wrapper
4112:
4113: sub aboutmewrapper {
1.1070 raeburn 4114: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 4115: if (!defined($username) && !defined($domain)) {
4116: return;
4117: }
1.1096 raeburn 4118: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 4119: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 4120: }
4121:
4122: # ------------------------------------------------------------ Syllabus Wrapper
4123:
4124: sub syllabuswrapper {
1.707 bisitz 4125: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4126: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4127: }
1.14 harris41 4128:
1.802 bisitz 4129: # -----------------------------------------------------------------------------
4130:
1.208 matthew 4131: sub track_student_link {
1.887 raeburn 4132: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4133: my $link ="/adm/trackstudent?";
1.208 matthew 4134: my $title = 'View recent activity';
4135: if (defined($sname) && $sname !~ /^\s*$/ &&
4136: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4137: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4138: $title .= ' of this student';
1.268 albertel 4139: }
1.208 matthew 4140: if (defined($target) && $target !~ /^\s*$/) {
4141: $target = qq{target="$target"};
4142: } else {
4143: $target = '';
4144: }
1.268 albertel 4145: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4146: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4147: $title = &mt($title);
4148: $linktext = &mt($linktext);
1.448 albertel 4149: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4150: &help_open_topic('View_recent_activity');
1.208 matthew 4151: }
4152:
1.781 raeburn 4153: sub slot_reservations_link {
4154: my ($linktext,$sname,$sdom,$target) = @_;
4155: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4156: my $title = 'View slot reservation history';
4157: if (defined($sname) && $sname !~ /^\s*$/ &&
4158: defined($sdom) && $sdom !~ /^\s*$/) {
4159: $link .= "&uname=$sname&udom=$sdom";
4160: $title .= ' of this student';
4161: }
4162: if (defined($target) && $target !~ /^\s*$/) {
4163: $target = qq{target="$target"};
4164: } else {
4165: $target = '';
4166: }
4167: $title = &mt($title);
4168: $linktext = &mt($linktext);
4169: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4170: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4171:
4172: }
4173:
1.508 www 4174: # ===================================================== Display a student photo
4175:
4176:
1.509 albertel 4177: sub student_image_tag {
1.508 www 4178: my ($domain,$user)=@_;
4179: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4180: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4181: return '<img src="'.$imgsrc.'" align="right" />';
4182: } else {
4183: return '';
4184: }
4185: }
4186:
1.112 bowersj2 4187: =pod
4188:
4189: =back
4190:
4191: =head1 Access .tab File Data
4192:
4193: =over 4
4194:
1.648 raeburn 4195: =item * &languageids()
1.112 bowersj2 4196:
4197: returns list of all language ids
4198:
4199: =cut
4200:
1.14 harris41 4201: sub languageids {
1.16 harris41 4202: return sort(keys(%language));
1.14 harris41 4203: }
4204:
1.112 bowersj2 4205: =pod
4206:
1.648 raeburn 4207: =item * &languagedescription()
1.112 bowersj2 4208:
4209: returns description of a specified language id
4210:
4211: =cut
4212:
1.14 harris41 4213: sub languagedescription {
1.125 www 4214: my $code=shift;
4215: return ($supported_language{$code}?'* ':'').
4216: $language{$code}.
1.126 www 4217: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4218: }
4219:
1.1048 foxr 4220: =pod
4221:
4222: =item * &plainlanguagedescription
4223:
4224: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4225: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4226:
4227: =cut
4228:
1.145 www 4229: sub plainlanguagedescription {
4230: my $code=shift;
4231: return $language{$code};
4232: }
4233:
1.1048 foxr 4234: =pod
4235:
4236: =item * &supportedlanguagecode
4237:
4238: Returns the supported language code (e.g. sptutf maps to pt) given a language
4239: code.
4240:
4241: =cut
4242:
1.145 www 4243: sub supportedlanguagecode {
4244: my $code=shift;
4245: return $supported_language{$code};
1.97 www 4246: }
4247:
1.112 bowersj2 4248: =pod
4249:
1.1048 foxr 4250: =item * &latexlanguage()
4251:
4252: Given a language key code returns the correspondnig language to use
4253: to select the correct hyphenation on LaTeX printouts. This is undef if there
4254: is no supported hyphenation for the language code.
4255:
4256: =cut
4257:
4258: sub latexlanguage {
4259: my $code = shift;
4260: return $latex_language{$code};
4261: }
4262:
4263: =pod
4264:
4265: =item * &latexhyphenation()
4266:
4267: Same as above but what's supplied is the language as it might be stored
4268: in the metadata.
4269:
4270: =cut
4271:
4272: sub latexhyphenation {
4273: my $key = shift;
4274: return $latex_language_bykey{$key};
4275: }
4276:
4277: =pod
4278:
1.648 raeburn 4279: =item * ©rightids()
1.112 bowersj2 4280:
4281: returns list of all copyrights
4282:
4283: =cut
4284:
4285: sub copyrightids {
4286: return sort(keys(%cprtag));
4287: }
4288:
4289: =pod
4290:
1.648 raeburn 4291: =item * ©rightdescription()
1.112 bowersj2 4292:
4293: returns description of a specified copyright id
4294:
4295: =cut
4296:
4297: sub copyrightdescription {
1.166 www 4298: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4299: }
1.197 matthew 4300:
4301: =pod
4302:
1.648 raeburn 4303: =item * &source_copyrightids()
1.192 taceyjo1 4304:
4305: returns list of all source copyrights
4306:
4307: =cut
4308:
4309: sub source_copyrightids {
4310: return sort(keys(%scprtag));
4311: }
4312:
4313: =pod
4314:
1.648 raeburn 4315: =item * &source_copyrightdescription()
1.192 taceyjo1 4316:
4317: returns description of a specified source copyright id
4318:
4319: =cut
4320:
4321: sub source_copyrightdescription {
4322: return &mt($scprtag{shift(@_)});
4323: }
1.112 bowersj2 4324:
4325: =pod
4326:
1.648 raeburn 4327: =item * &filecategories()
1.112 bowersj2 4328:
4329: returns list of all file categories
4330:
4331: =cut
4332:
4333: sub filecategories {
4334: return sort(keys(%category_extensions));
4335: }
4336:
4337: =pod
4338:
1.648 raeburn 4339: =item * &filecategorytypes()
1.112 bowersj2 4340:
4341: returns list of file types belonging to a given file
4342: category
4343:
4344: =cut
4345:
4346: sub filecategorytypes {
1.356 albertel 4347: my ($cat) = @_;
1.1248 raeburn 4348: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4349: return @{$category_extensions{lc($cat)}};
4350: } else {
4351: return ();
4352: }
1.112 bowersj2 4353: }
4354:
4355: =pod
4356:
1.648 raeburn 4357: =item * &fileembstyle()
1.112 bowersj2 4358:
4359: returns embedding style for a specified file type
4360:
4361: =cut
4362:
4363: sub fileembstyle {
4364: return $fe{lc(shift(@_))};
1.169 www 4365: }
4366:
1.351 www 4367: sub filemimetype {
4368: return $fm{lc(shift(@_))};
4369: }
4370:
1.169 www 4371:
4372: sub filecategoryselect {
4373: my ($name,$value)=@_;
1.189 matthew 4374: return &select_form($value,$name,
1.970 raeburn 4375: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4376: }
4377:
4378: =pod
4379:
1.648 raeburn 4380: =item * &filedescription()
1.112 bowersj2 4381:
4382: returns description for a specified file type
4383:
4384: =cut
4385:
4386: sub filedescription {
1.188 matthew 4387: my $file_description = $fd{lc(shift())};
4388: $file_description =~ s:([\[\]]):~$1:g;
4389: return &mt($file_description);
1.112 bowersj2 4390: }
4391:
4392: =pod
4393:
1.648 raeburn 4394: =item * &filedescriptionex()
1.112 bowersj2 4395:
4396: returns description for a specified file type with
4397: extra formatting
4398:
4399: =cut
4400:
4401: sub filedescriptionex {
4402: my $ex=shift;
1.188 matthew 4403: my $file_description = $fd{lc($ex)};
4404: $file_description =~ s:([\[\]]):~$1:g;
4405: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4406: }
4407:
4408: # End of .tab access
4409: =pod
4410:
4411: =back
4412:
4413: =cut
4414:
4415: # ------------------------------------------------------------------ File Types
4416: sub fileextensions {
4417: return sort(keys(%fe));
4418: }
4419:
1.97 www 4420: # ----------------------------------------------------------- Display Languages
4421: # returns a hash with all desired display languages
4422: #
4423:
4424: sub display_languages {
4425: my %languages=();
1.695 raeburn 4426: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4427: $languages{$lang}=1;
1.97 www 4428: }
4429: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4430: if ($env{'form.displaylanguage'}) {
1.356 albertel 4431: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4432: $languages{$lang}=1;
1.97 www 4433: }
4434: }
4435: return %languages;
1.14 harris41 4436: }
4437:
1.582 albertel 4438: sub languages {
4439: my ($possible_langs) = @_;
1.695 raeburn 4440: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4441: if (!ref($possible_langs)) {
4442: if( wantarray ) {
4443: return @preferred_langs;
4444: } else {
4445: return $preferred_langs[0];
4446: }
4447: }
4448: my %possibilities = map { $_ => 1 } (@$possible_langs);
4449: my @preferred_possibilities;
4450: foreach my $preferred_lang (@preferred_langs) {
4451: if (exists($possibilities{$preferred_lang})) {
4452: push(@preferred_possibilities, $preferred_lang);
4453: }
4454: }
4455: if( wantarray ) {
4456: return @preferred_possibilities;
4457: }
4458: return $preferred_possibilities[0];
4459: }
4460:
1.742 raeburn 4461: sub user_lang {
4462: my ($touname,$toudom,$fromcid) = @_;
4463: my @userlangs;
4464: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4465: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4466: $env{'course.'.$fromcid.'.languages'}));
4467: } else {
4468: my %langhash = &getlangs($touname,$toudom);
4469: if ($langhash{'languages'} ne '') {
4470: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4471: } else {
4472: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4473: if ($domdefs{'lang_def'} ne '') {
4474: @userlangs = ($domdefs{'lang_def'});
4475: }
4476: }
4477: }
4478: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4479: my $user_lh = Apache::localize->get_handle(@languages);
4480: return $user_lh;
4481: }
4482:
4483:
1.112 bowersj2 4484: ###############################################################
4485: ## Student Answer Attempts ##
4486: ###############################################################
4487:
4488: =pod
4489:
4490: =head1 Alternate Problem Views
4491:
4492: =over 4
4493:
1.648 raeburn 4494: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4495: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4496:
4497: Return string with previous attempt on problem. Arguments:
4498:
4499: =over 4
4500:
4501: =item * $symb: Problem, including path
4502:
4503: =item * $username: username of the desired student
4504:
4505: =item * $domain: domain of the desired student
1.14 harris41 4506:
1.112 bowersj2 4507: =item * $course: Course ID
1.14 harris41 4508:
1.112 bowersj2 4509: =item * $getattempt: Leave blank for all attempts, otherwise put
4510: something
1.14 harris41 4511:
1.112 bowersj2 4512: =item * $regexp: if string matches this regexp, the string will be
4513: sent to $gradesub
1.14 harris41 4514:
1.112 bowersj2 4515: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4516:
1.1199 raeburn 4517: =item * $usec: section of the desired student
4518:
4519: =item * $identifier: counter for student (multiple students one problem) or
4520: problem (one student; whole sequence).
4521:
1.112 bowersj2 4522: =back
1.14 harris41 4523:
1.112 bowersj2 4524: The output string is a table containing all desired attempts, if any.
1.16 harris41 4525:
1.112 bowersj2 4526: =cut
1.1 albertel 4527:
4528: sub get_previous_attempt {
1.1199 raeburn 4529: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4530: my $prevattempts='';
1.43 ng 4531: no strict 'refs';
1.1 albertel 4532: if ($symb) {
1.3 albertel 4533: my (%returnhash)=
4534: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4535: if ($returnhash{'version'}) {
4536: my %lasthash=();
4537: my $version;
4538: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4539: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4540: if ($key =~ /\.rawrndseed$/) {
4541: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4542: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4543: } else {
4544: $lasthash{$key}=$returnhash{$version.':'.$key};
4545: }
1.19 harris41 4546: }
1.1 albertel 4547: }
1.596 albertel 4548: $prevattempts=&start_data_table().&start_data_table_header_row();
4549: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4550: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4551: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4552: foreach my $key (sort(keys(%lasthash))) {
4553: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4554: if ($#parts > 0) {
1.31 albertel 4555: my $data=$parts[-1];
1.989 raeburn 4556: next if ($data eq 'foilorder');
1.31 albertel 4557: pop(@parts);
1.1010 www 4558: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4559: if ($data eq 'type') {
4560: unless ($showsurv) {
4561: my $id = join(',',@parts);
4562: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4563: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4564: $lasthidden{$ign.'.'.$id} = 1;
4565: }
1.945 raeburn 4566: }
1.1199 raeburn 4567: if ($identifier ne '') {
4568: my $id = join(',',@parts);
4569: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4570: $domain,$username,$usec,undef,$course) =~ /^no/) {
4571: $hidestatus{$ign.'.'.$id} = 1;
4572: }
4573: }
4574: } elsif ($data eq 'regrader') {
4575: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4576: my $id = join(',',@parts);
4577: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4578: }
1.1010 www 4579: }
1.31 albertel 4580: } else {
1.41 ng 4581: if ($#parts == 0) {
4582: $prevattempts.='<th>'.$parts[0].'</th>';
4583: } else {
4584: $prevattempts.='<th>'.$ign.'</th>';
4585: }
1.31 albertel 4586: }
1.16 harris41 4587: }
1.596 albertel 4588: $prevattempts.=&end_data_table_header_row();
1.40 ng 4589: if ($getattempt eq '') {
1.1199 raeburn 4590: my (%solved,%resets,%probstatus);
1.1200 raeburn 4591: if (($identifier ne '') && (keys(%regraded) > 0)) {
4592: for ($version=1;$version<=$returnhash{'version'};$version++) {
4593: foreach my $id (keys(%regraded)) {
4594: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4595: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4596: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4597: push(@{$resets{$id}},$version);
1.1199 raeburn 4598: }
4599: }
4600: }
1.1200 raeburn 4601: }
4602: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4603: my (@hidden,@unsolved);
1.945 raeburn 4604: if (%typeparts) {
4605: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4606: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4607: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4608: push(@hidden,$id);
1.1199 raeburn 4609: } elsif ($identifier ne '') {
4610: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4611: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4612: ($hidestatus{$id})) {
1.1200 raeburn 4613: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4614: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4615: push(@{$solved{$id}},$version);
4616: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4617: (ref($solved{$id}) eq 'ARRAY')) {
4618: my $skip;
4619: if (ref($resets{$id}) eq 'ARRAY') {
4620: foreach my $reset (@{$resets{$id}}) {
4621: if ($reset > $solved{$id}[-1]) {
4622: $skip=1;
4623: last;
4624: }
4625: }
4626: }
4627: unless ($skip) {
4628: my ($ign,$partslist) = split(/\./,$id,2);
4629: push(@unsolved,$partslist);
4630: }
4631: }
4632: }
1.945 raeburn 4633: }
4634: }
4635: }
4636: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4637: '<td>'.&mt('Transaction [_1]',$version);
4638: if (@unsolved) {
4639: $prevattempts .= '<span class="LC_nobreak"><label>'.
4640: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4641: &mt('Hide').'</label></span>';
4642: }
4643: $prevattempts .= '</td>';
1.945 raeburn 4644: if (@hidden) {
4645: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4646: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4647: my $hide;
4648: foreach my $id (@hidden) {
4649: if ($key =~ /^\Q$id\E/) {
4650: $hide = 1;
4651: last;
4652: }
4653: }
4654: if ($hide) {
4655: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4656: if (($data eq 'award') || ($data eq 'awarddetail')) {
4657: my $value = &format_previous_attempt_value($key,
4658: $returnhash{$version.':'.$key});
1.1173 kruse 4659: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4660: } else {
4661: $prevattempts.='<td> </td>';
4662: }
4663: } else {
4664: if ($key =~ /\./) {
1.1212 raeburn 4665: my $value = $returnhash{$version.':'.$key};
4666: if ($key =~ /\.rndseed$/) {
4667: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4668: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4669: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4670: }
4671: }
4672: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4673: ' </td>';
1.945 raeburn 4674: } else {
4675: $prevattempts.='<td> </td>';
4676: }
4677: }
4678: }
4679: } else {
4680: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4681: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4682: my $value = $returnhash{$version.':'.$key};
4683: if ($key =~ /\.rndseed$/) {
4684: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4685: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4686: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4687: }
4688: }
4689: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4690: ' </td>';
1.945 raeburn 4691: }
4692: }
4693: $prevattempts.=&end_data_table_row();
1.40 ng 4694: }
1.1 albertel 4695: }
1.945 raeburn 4696: my @currhidden = keys(%lasthidden);
1.596 albertel 4697: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4698: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4699: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4700: if (%typeparts) {
4701: my $hidden;
4702: foreach my $id (@currhidden) {
4703: if ($key =~ /^\Q$id\E/) {
4704: $hidden = 1;
4705: last;
4706: }
4707: }
4708: if ($hidden) {
4709: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4710: if (($data eq 'award') || ($data eq 'awarddetail')) {
4711: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4712: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4713: $value = &$gradesub($value);
4714: }
1.1173 kruse 4715: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4716: } else {
4717: $prevattempts.='<td> </td>';
4718: }
4719: } else {
4720: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4721: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4722: $value = &$gradesub($value);
4723: }
1.1173 kruse 4724: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4725: }
4726: } else {
4727: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4728: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4729: $value = &$gradesub($value);
4730: }
1.1173 kruse 4731: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4732: }
1.16 harris41 4733: }
1.596 albertel 4734: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4735: } else {
1.1305 raeburn 4736: my $msg;
4737: if ($symb =~ /ext\.tool$/) {
4738: $msg = &mt('No grade passed back.');
4739: } else {
4740: $msg = &mt('Nothing submitted - no attempts.');
4741: }
1.596 albertel 4742: $prevattempts=
4743: &start_data_table().&start_data_table_row().
1.1305 raeburn 4744: '<td>'.$msg.'</td>'.
1.596 albertel 4745: &end_data_table_row().&end_data_table();
1.1 albertel 4746: }
4747: } else {
1.596 albertel 4748: $prevattempts=
4749: &start_data_table().&start_data_table_row().
4750: '<td>'.&mt('No data.').'</td>'.
4751: &end_data_table_row().&end_data_table();
1.1 albertel 4752: }
1.10 albertel 4753: }
4754:
1.581 albertel 4755: sub format_previous_attempt_value {
4756: my ($key,$value) = @_;
1.1011 www 4757: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4758: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4759: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4760: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4761: } elsif ($key =~ /answerstring$/) {
4762: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4763: my @answer = %answers;
4764: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4765: my @anskeys = sort(keys(%answers));
4766: if (@anskeys == 1) {
4767: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4768: if ($answer =~ m{\0}) {
4769: $answer =~ s{\0}{,}g;
1.988 raeburn 4770: }
4771: my $tag_internal_answer_name = 'INTERNAL';
4772: if ($anskeys[0] eq $tag_internal_answer_name) {
4773: $value = $answer;
4774: } else {
4775: $value = $anskeys[0].'='.$answer;
4776: }
4777: } else {
4778: foreach my $ans (@anskeys) {
4779: my $answer = $answers{$ans};
1.1001 raeburn 4780: if ($answer =~ m{\0}) {
4781: $answer =~ s{\0}{,}g;
1.988 raeburn 4782: }
4783: $value .= $ans.'='.$answer.'<br />';;
4784: }
4785: }
1.581 albertel 4786: } else {
1.1173 kruse 4787: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4788: }
4789: return $value;
4790: }
4791:
4792:
1.107 albertel 4793: sub relative_to_absolute {
4794: my ($url,$output)=@_;
4795: my $parser=HTML::TokeParser->new(\$output);
4796: my $token;
4797: my $thisdir=$url;
4798: my @rlinks=();
4799: while ($token=$parser->get_token) {
4800: if ($token->[0] eq 'S') {
4801: if ($token->[1] eq 'a') {
4802: if ($token->[2]->{'href'}) {
4803: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4804: }
4805: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4806: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4807: } elsif ($token->[1] eq 'base') {
4808: $thisdir=$token->[2]->{'href'};
4809: }
4810: }
4811: }
4812: $thisdir=~s-/[^/]*$--;
1.356 albertel 4813: foreach my $link (@rlinks) {
1.726 raeburn 4814: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4815: ($link=~/^\//) ||
4816: ($link=~/^javascript:/i) ||
4817: ($link=~/^mailto:/i) ||
4818: ($link=~/^\#/)) {
4819: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4820: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4821: }
4822: }
4823: # -------------------------------------------------- Deal with Applet codebases
4824: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4825: return $output;
4826: }
4827:
1.112 bowersj2 4828: =pod
4829:
1.648 raeburn 4830: =item * &get_student_view()
1.112 bowersj2 4831:
4832: show a snapshot of what student was looking at
4833:
4834: =cut
4835:
1.10 albertel 4836: sub get_student_view {
1.186 albertel 4837: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4838: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4839: my (%form);
1.10 albertel 4840: my @elements=('symb','courseid','domain','username');
4841: foreach my $element (@elements) {
1.186 albertel 4842: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4843: }
1.186 albertel 4844: if (defined($moreenv)) {
4845: %form=(%form,%{$moreenv});
4846: }
1.236 albertel 4847: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4848: $feedurl=&Apache::lonnet::clutter($feedurl);
1.1306 raeburn 4849: if (($feedurl =~ /ext\.tool$/) && ($target eq 'tex')) {
4850: $feedurl =~ s{^/adm/wrapper}{};
4851: }
1.650 www 4852: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4853: $userview=~s/\<body[^\>]*\>//gi;
4854: $userview=~s/\<\/body\>//gi;
4855: $userview=~s/\<html\>//gi;
4856: $userview=~s/\<\/html\>//gi;
4857: $userview=~s/\<head\>//gi;
4858: $userview=~s/\<\/head\>//gi;
4859: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4860: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4861: if (wantarray) {
4862: return ($userview,$response);
4863: } else {
4864: return $userview;
4865: }
4866: }
4867:
4868: sub get_student_view_with_retries {
4869: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4870:
4871: my $ok = 0; # True if we got a good response.
4872: my $content;
4873: my $response;
4874:
4875: # Try to get the student_view done. within the retries count:
4876:
4877: do {
4878: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4879: $ok = $response->is_success;
4880: if (!$ok) {
4881: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4882: }
4883: $retries--;
4884: } while (!$ok && ($retries > 0));
4885:
4886: if (!$ok) {
4887: $content = ''; # On error return an empty content.
4888: }
1.651 www 4889: if (wantarray) {
4890: return ($content, $response);
4891: } else {
4892: return $content;
4893: }
1.11 albertel 4894: }
4895:
1.1349 raeburn 4896: sub css_links {
4897: my ($currsymb,$level) = @_;
4898: my ($links,@symbs,%cssrefs,%httpref);
4899: if ($level eq 'map') {
4900: my $navmap = Apache::lonnavmaps::navmap->new();
4901: if (ref($navmap)) {
4902: my ($map,undef,$url)=&Apache::lonnet::decode_symb($currsymb);
4903: my @resources = $navmap->retrieveResources($map,sub { $_[0]->is_problem() },0,0);
4904: foreach my $res (@resources) {
4905: if (ref($res) && $res->symb()) {
4906: push(@symbs,$res->symb());
4907: }
4908: }
4909: }
4910: } else {
4911: @symbs = ($currsymb);
4912: }
4913: foreach my $symb (@symbs) {
4914: my $css_href = &Apache::lonnet::EXT('resource.0.cssfile',$symb);
4915: if ($css_href =~ /\S/) {
4916: unless ($css_href =~ m{https?://}) {
4917: my $url = (&Apache::lonnet::decode_symb($symb))[-1];
4918: my $proburl = &Apache::lonnet::clutter($url);
4919: my ($probdir) = ($proburl =~ m{(.+)/[^/]+$});
4920: unless ($css_href =~ m{^/}) {
4921: $css_href = &Apache::lonnet::hreflocation($probdir,$css_href);
4922: }
4923: if ($css_href =~ m{^/(res|uploaded)/}) {
4924: unless (($httpref{'httpref.'.$css_href}) ||
4925: (&Apache::lonnet::is_on_map($css_href))) {
4926: my $thisurl = $proburl;
4927: if ($env{'httpref.'.$proburl}) {
4928: $thisurl = $env{'httpref.'.$proburl};
4929: }
4930: $httpref{'httpref.'.$css_href} = $thisurl;
4931: }
4932: }
4933: }
4934: $cssrefs{$css_href} = 1;
4935: }
4936: }
4937: if (keys(%httpref)) {
4938: &Apache::lonnet::appenv(\%httpref);
4939: }
4940: if (keys(%cssrefs)) {
4941: foreach my $css_href (keys(%cssrefs)) {
4942: next unless ($css_href =~ m{^(/res/|/uploaded/|https?://)});
4943: $links .= '<link rel="stylesheet" type="text/css" href="'.$css_href.'" />'."\n";
4944: }
4945: }
4946: return $links;
4947: }
4948:
1.112 bowersj2 4949: =pod
4950:
1.648 raeburn 4951: =item * &get_student_answers()
1.112 bowersj2 4952:
4953: show a snapshot of how student was answering problem
4954:
4955: =cut
4956:
1.11 albertel 4957: sub get_student_answers {
1.100 sakharuk 4958: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4959: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4960: my (%moreenv);
1.11 albertel 4961: my @elements=('symb','courseid','domain','username');
4962: foreach my $element (@elements) {
1.186 albertel 4963: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4964: }
1.186 albertel 4965: $moreenv{'grade_target'}='answer';
4966: %moreenv=(%form,%moreenv);
1.497 raeburn 4967: $feedurl = &Apache::lonnet::clutter($feedurl);
4968: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4969: return $userview;
1.1 albertel 4970: }
1.116 albertel 4971:
4972: =pod
4973:
4974: =item * &submlink()
4975:
1.242 albertel 4976: Inputs: $text $uname $udom $symb $target
1.116 albertel 4977:
4978: Returns: A link to grades.pm such as to see the SUBM view of a student
4979:
4980: =cut
4981:
4982: ###############################################
4983: sub submlink {
1.242 albertel 4984: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4985: if (!($uname && $udom)) {
4986: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4987: &Apache::lonnet::whichuser($symb);
1.116 albertel 4988: if (!$symb) { $symb=$cursymb; }
4989: }
1.254 matthew 4990: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4991: $symb=&escape($symb);
1.960 bisitz 4992: if ($target) { $target=" target=\"$target\""; }
4993: return
4994: '<a href="/adm/grades?command=submission'.
4995: '&symb='.$symb.
4996: '&student='.$uname.
4997: '&userdom='.$udom.'"'.
4998: $target.'>'.$text.'</a>';
1.242 albertel 4999: }
5000: ##############################################
5001:
5002: =pod
5003:
5004: =item * &pgrdlink()
5005:
5006: Inputs: $text $uname $udom $symb $target
5007:
5008: Returns: A link to grades.pm such as to see the PGRD view of a student
5009:
5010: =cut
5011:
5012: ###############################################
5013: sub pgrdlink {
5014: my $link=&submlink(@_);
5015: $link=~s/(&command=submission)/$1&showgrading=yes/;
5016: return $link;
5017: }
5018: ##############################################
5019:
5020: =pod
5021:
5022: =item * &pprmlink()
5023:
5024: Inputs: $text $uname $udom $symb $target
5025:
5026: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 5027: student and a specific resource
1.242 albertel 5028:
5029: =cut
5030:
5031: ###############################################
5032: sub pprmlink {
5033: my ($text,$uname,$udom,$symb,$target)=@_;
5034: if (!($uname && $udom)) {
5035: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 5036: &Apache::lonnet::whichuser($symb);
1.242 albertel 5037: if (!$symb) { $symb=$cursymb; }
5038: }
1.254 matthew 5039: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 5040: $symb=&escape($symb);
1.242 albertel 5041: if ($target) { $target="target=\"$target\""; }
1.595 albertel 5042: return '<a href="/adm/parmset?command=set&'.
5043: 'symb='.$symb.'&uname='.$uname.
5044: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 5045: }
5046: ##############################################
1.37 matthew 5047:
1.112 bowersj2 5048: =pod
5049:
5050: =back
5051:
5052: =cut
5053:
1.37 matthew 5054: ###############################################
1.51 www 5055:
5056:
5057: sub timehash {
1.687 raeburn 5058: my ($thistime) = @_;
5059: my $timezone = &Apache::lonlocal::gettimezone();
5060: my $dt = DateTime->from_epoch(epoch => $thistime)
5061: ->set_time_zone($timezone);
5062: my $wday = $dt->day_of_week();
5063: if ($wday == 7) { $wday = 0; }
5064: return ( 'second' => $dt->second(),
5065: 'minute' => $dt->minute(),
5066: 'hour' => $dt->hour(),
5067: 'day' => $dt->day_of_month(),
5068: 'month' => $dt->month(),
5069: 'year' => $dt->year(),
5070: 'weekday' => $wday,
5071: 'dayyear' => $dt->day_of_year(),
5072: 'dlsav' => $dt->is_dst() );
1.51 www 5073: }
5074:
1.370 www 5075: sub utc_string {
5076: my ($date)=@_;
1.371 www 5077: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 5078: }
5079:
1.51 www 5080: sub maketime {
5081: my %th=@_;
1.687 raeburn 5082: my ($epoch_time,$timezone,$dt);
5083: $timezone = &Apache::lonlocal::gettimezone();
5084: eval {
5085: $dt = DateTime->new( year => $th{'year'},
5086: month => $th{'month'},
5087: day => $th{'day'},
5088: hour => $th{'hour'},
5089: minute => $th{'minute'},
5090: second => $th{'second'},
5091: time_zone => $timezone,
5092: );
5093: };
5094: if (!$@) {
5095: $epoch_time = $dt->epoch;
5096: if ($epoch_time) {
5097: return $epoch_time;
5098: }
5099: }
1.51 www 5100: return POSIX::mktime(
5101: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 5102: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 5103: }
5104:
5105: #########################################
1.51 www 5106:
5107: sub findallcourses {
1.482 raeburn 5108: my ($roles,$uname,$udom) = @_;
1.355 albertel 5109: my %roles;
5110: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 5111: my %courses;
1.51 www 5112: my $now=time;
1.482 raeburn 5113: if (!defined($uname)) {
5114: $uname = $env{'user.name'};
5115: }
5116: if (!defined($udom)) {
5117: $udom = $env{'user.domain'};
5118: }
5119: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 5120: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 5121: if (!%roles) {
5122: %roles = (
5123: cc => 1,
1.907 raeburn 5124: co => 1,
1.482 raeburn 5125: in => 1,
5126: ep => 1,
5127: ta => 1,
5128: cr => 1,
5129: st => 1,
5130: );
5131: }
5132: foreach my $entry (keys(%roleshash)) {
5133: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
5134: if ($trole =~ /^cr/) {
5135: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5136: } else {
5137: next if (!exists($roles{$trole}));
5138: }
5139: if ($tend) {
5140: next if ($tend < $now);
5141: }
5142: if ($tstart) {
5143: next if ($tstart > $now);
5144: }
1.1058 raeburn 5145: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5146: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5147: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5148: if ($secpart eq '') {
5149: ($cnum,$role) = split(/_/,$cnumpart);
5150: $sec = 'none';
1.1058 raeburn 5151: $value .= $cnum.'/';
1.482 raeburn 5152: } else {
5153: $cnum = $cnumpart;
5154: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5155: $value .= $cnum.'/'.$sec;
5156: }
5157: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5158: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5159: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5160: }
5161: } else {
5162: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5163: }
1.482 raeburn 5164: }
5165: } else {
5166: foreach my $key (keys(%env)) {
1.483 albertel 5167: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5168: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5169: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5170: next if ($role eq 'ca' || $role eq 'aa');
5171: next if (%roles && !exists($roles{$role}));
5172: my ($starttime,$endtime)=split(/\./,$env{$key});
5173: my $active=1;
5174: if ($starttime) {
5175: if ($now<$starttime) { $active=0; }
5176: }
5177: if ($endtime) {
5178: if ($now>$endtime) { $active=0; }
5179: }
5180: if ($active) {
1.1058 raeburn 5181: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5182: if ($sec eq '') {
5183: $sec = 'none';
1.1058 raeburn 5184: } else {
5185: $value .= $sec;
5186: }
5187: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5188: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5189: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5190: }
5191: } else {
5192: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5193: }
1.474 raeburn 5194: }
5195: }
1.51 www 5196: }
5197: }
1.474 raeburn 5198: return %courses;
1.51 www 5199: }
1.37 matthew 5200:
1.54 www 5201: ###############################################
1.474 raeburn 5202:
5203: sub blockcheck {
1.1347 raeburn 5204: my ($setters,$activity,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.490 raeburn 5205:
1.1189 raeburn 5206: if (defined($udom) && defined($uname)) {
5207: # If uname and udom are for a course, check for blocks in the course.
5208: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5209: my ($startblock,$endblock,$triggerblock) =
1.1347 raeburn 5210: &get_blocks($setters,$activity,$udom,$uname,$url,$symb,$caller);
1.1189 raeburn 5211: return ($startblock,$endblock,$triggerblock);
5212: }
5213: } else {
1.490 raeburn 5214: $udom = $env{'user.domain'};
5215: $uname = $env{'user.name'};
5216: }
5217:
1.502 raeburn 5218: my $startblock = 0;
5219: my $endblock = 0;
1.1062 raeburn 5220: my $triggerblock = '';
1.482 raeburn 5221: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 5222:
1.490 raeburn 5223: # If uname is for a user, and activity is course-specific, i.e.,
5224: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5225:
1.490 raeburn 5226: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5227: $activity eq 'groups' || $activity eq 'printout' ||
1.1346 raeburn 5228: $activity eq 'search' || $activity eq 'reinit' ||
5229: $activity eq 'alert') &&
1.1189 raeburn 5230: ($env{'request.course.id'})) {
1.490 raeburn 5231: foreach my $key (keys(%live_courses)) {
5232: if ($key ne $env{'request.course.id'}) {
5233: delete($live_courses{$key});
5234: }
5235: }
5236: }
5237:
5238: my $otheruser = 0;
5239: my %own_courses;
5240: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5241: # Resource belongs to user other than current user.
5242: $otheruser = 1;
5243: # Gather courses for current user
5244: %own_courses =
5245: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5246: }
5247:
5248: # Gather active course roles - course coordinator, instructor,
5249: # exam proctor, ta, student, or custom role.
1.474 raeburn 5250:
5251: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5252: my ($cdom,$cnum);
5253: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5254: $cdom = $env{'course.'.$course.'.domain'};
5255: $cnum = $env{'course.'.$course.'.num'};
5256: } else {
1.490 raeburn 5257: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5258: }
5259: my $no_ownblock = 0;
5260: my $no_userblock = 0;
1.533 raeburn 5261: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5262: # Check if current user has 'evb' priv for this
5263: if (defined($own_courses{$course})) {
5264: foreach my $sec (keys(%{$own_courses{$course}})) {
5265: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5266: if ($sec ne 'none') {
5267: $checkrole .= '/'.$sec;
5268: }
5269: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5270: $no_ownblock = 1;
5271: last;
5272: }
5273: }
5274: }
5275: # if they have 'evb' priv and are currently not playing student
5276: next if (($no_ownblock) &&
5277: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5278: }
1.474 raeburn 5279: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5280: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5281: if ($sec ne 'none') {
1.482 raeburn 5282: $checkrole .= '/'.$sec;
1.474 raeburn 5283: }
1.490 raeburn 5284: if ($otheruser) {
5285: # Resource belongs to user other than current user.
5286: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5287: my (%allroles,%userroles);
5288: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5289: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5290: my ($trole,$tdom,$tnum,$tsec);
5291: if ($entry =~ /^cr/) {
5292: ($trole,$tdom,$tnum,$tsec) =
5293: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5294: } else {
5295: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5296: }
5297: my ($spec,$area,$trest);
5298: $area = '/'.$tdom.'/'.$tnum;
5299: $trest = $tnum;
5300: if ($tsec ne '') {
5301: $area .= '/'.$tsec;
5302: $trest .= '/'.$tsec;
5303: }
5304: $spec = $trole.'.'.$area;
5305: if ($trole =~ /^cr/) {
5306: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5307: $tdom,$spec,$trest,$area);
5308: } else {
5309: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5310: $tdom,$spec,$trest,$area);
5311: }
5312: }
1.1276 raeburn 5313: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5314: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5315: if ($1) {
5316: $no_userblock = 1;
5317: last;
5318: }
1.486 raeburn 5319: }
5320: }
1.490 raeburn 5321: } else {
5322: # Resource belongs to current user
5323: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5324: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5325: $no_ownblock = 1;
5326: last;
5327: }
1.474 raeburn 5328: }
5329: }
5330: # if they have the evb priv and are currently not playing student
1.482 raeburn 5331: next if (($no_ownblock) &&
1.491 albertel 5332: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5333: next if ($no_userblock);
1.474 raeburn 5334:
1.1303 raeburn 5335: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5336: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5337:
1.1062 raeburn 5338: my ($start,$end,$trigger) =
1.1347 raeburn 5339: &get_blocks($setters,$activity,$cdom,$cnum,$url,$symb,$caller);
1.502 raeburn 5340: if (($start != 0) &&
5341: (($startblock == 0) || ($startblock > $start))) {
5342: $startblock = $start;
1.1062 raeburn 5343: if ($trigger ne '') {
5344: $triggerblock = $trigger;
5345: }
1.502 raeburn 5346: }
5347: if (($end != 0) &&
5348: (($endblock == 0) || ($endblock < $end))) {
5349: $endblock = $end;
1.1062 raeburn 5350: if ($trigger ne '') {
5351: $triggerblock = $trigger;
5352: }
1.502 raeburn 5353: }
1.490 raeburn 5354: }
1.1062 raeburn 5355: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5356: }
5357:
5358: sub get_blocks {
1.1347 raeburn 5359: my ($setters,$activity,$cdom,$cnum,$url,$symb,$caller) = @_;
1.490 raeburn 5360: my $startblock = 0;
5361: my $endblock = 0;
1.1062 raeburn 5362: my $triggerblock = '';
1.490 raeburn 5363: my $course = $cdom.'_'.$cnum;
5364: $setters->{$course} = {};
5365: $setters->{$course}{'staff'} = [];
5366: $setters->{$course}{'times'} = [];
1.1062 raeburn 5367: $setters->{$course}{'triggers'} = [];
5368: my (@blockers,%triggered);
5369: my $now = time;
5370: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5371: if ($activity eq 'docs') {
1.1348 raeburn 5372: my ($blocked,$nosymbcache,$noenccheck);
1.1347 raeburn 5373: if (($caller eq 'blockedaccess') || ($caller eq 'blockingstatus')) {
5374: $blocked = 1;
5375: $nosymbcache = 1;
1.1348 raeburn 5376: $noenccheck = 1;
1.1347 raeburn 5377: }
1.1348 raeburn 5378: @blockers = &Apache::lonnet::has_comm_blocking('bre',$symb,$url,$nosymbcache,$noenccheck,$blocked,\%commblocks);
1.1062 raeburn 5379: foreach my $block (@blockers) {
5380: if ($block =~ /^firstaccess____(.+)$/) {
5381: my $item = $1;
5382: my $type = 'map';
5383: my $timersymb = $item;
5384: if ($item eq 'course') {
5385: $type = 'course';
5386: } elsif ($item =~ /___\d+___/) {
5387: $type = 'resource';
5388: } else {
5389: $timersymb = &Apache::lonnet::symbread($item);
5390: }
5391: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5392: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5393: $triggered{$block} = {
5394: start => $start,
5395: end => $end,
5396: type => $type,
5397: };
5398: }
5399: }
5400: } else {
5401: foreach my $block (keys(%commblocks)) {
5402: if ($block =~ m/^(\d+)____(\d+)$/) {
5403: my ($start,$end) = ($1,$2);
5404: if ($start <= time && $end >= time) {
5405: if (ref($commblocks{$block}) eq 'HASH') {
5406: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5407: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5408: unless(grep(/^\Q$block\E$/,@blockers)) {
5409: push(@blockers,$block);
5410: }
5411: }
5412: }
5413: }
5414: }
5415: } elsif ($block =~ /^firstaccess____(.+)$/) {
5416: my $item = $1;
5417: my $timersymb = $item;
5418: my $type = 'map';
5419: if ($item eq 'course') {
5420: $type = 'course';
5421: } elsif ($item =~ /___\d+___/) {
5422: $type = 'resource';
5423: } else {
5424: $timersymb = &Apache::lonnet::symbread($item);
5425: }
5426: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5427: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5428: if ($start && $end) {
5429: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5430: if (ref($commblocks{$block}) eq 'HASH') {
5431: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5432: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5433: unless(grep(/^\Q$block\E$/,@blockers)) {
5434: push(@blockers,$block);
5435: $triggered{$block} = {
5436: start => $start,
5437: end => $end,
5438: type => $type,
5439: };
5440: }
5441: }
5442: }
1.1062 raeburn 5443: }
5444: }
1.490 raeburn 5445: }
1.1062 raeburn 5446: }
5447: }
5448: }
5449: foreach my $blocker (@blockers) {
5450: my ($staff_name,$staff_dom,$title,$blocks) =
5451: &parse_block_record($commblocks{$blocker});
5452: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5453: my ($start,$end,$triggertype);
5454: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5455: ($start,$end) = ($1,$2);
5456: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5457: $start = $triggered{$blocker}{'start'};
5458: $end = $triggered{$blocker}{'end'};
5459: $triggertype = $triggered{$blocker}{'type'};
5460: }
5461: if ($start) {
5462: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5463: if ($triggertype) {
5464: push(@{$$setters{$course}{'triggers'}},$triggertype);
5465: } else {
5466: push(@{$$setters{$course}{'triggers'}},0);
5467: }
5468: if ( ($startblock == 0) || ($startblock > $start) ) {
5469: $startblock = $start;
5470: if ($triggertype) {
5471: $triggerblock = $blocker;
1.474 raeburn 5472: }
5473: }
1.1062 raeburn 5474: if ( ($endblock == 0) || ($endblock < $end) ) {
5475: $endblock = $end;
5476: if ($triggertype) {
5477: $triggerblock = $blocker;
5478: }
5479: }
1.474 raeburn 5480: }
5481: }
1.1062 raeburn 5482: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5483: }
5484:
5485: sub parse_block_record {
5486: my ($record) = @_;
5487: my ($setuname,$setudom,$title,$blocks);
5488: if (ref($record) eq 'HASH') {
5489: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5490: $title = &unescape($record->{'event'});
5491: $blocks = $record->{'blocks'};
5492: } else {
5493: my @data = split(/:/,$record,3);
5494: if (scalar(@data) eq 2) {
5495: $title = $data[1];
5496: ($setuname,$setudom) = split(/@/,$data[0]);
5497: } else {
5498: ($setuname,$setudom,$title) = @data;
5499: }
5500: $blocks = { 'com' => 'on' };
5501: }
5502: return ($setuname,$setudom,$title,$blocks);
5503: }
5504:
1.854 kalberla 5505: sub blocking_status {
1.1347 raeburn 5506: my ($activity,$uname,$udom,$url,$is_course,$symb,$caller) = @_;
1.1061 raeburn 5507: my %setters;
1.890 droeschl 5508:
1.1061 raeburn 5509: # check for active blocking
1.1062 raeburn 5510: my ($startblock,$endblock,$triggerblock) =
1.1347 raeburn 5511: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course,$symb,$caller);
1.1062 raeburn 5512: my $blocked = 0;
5513: if ($startblock && $endblock) {
5514: $blocked = 1;
5515: }
1.890 droeschl 5516:
1.1061 raeburn 5517: # caller just wants to know whether a block is active
5518: if (!wantarray) { return $blocked; }
5519:
5520: # build a link to a popup window containing the details
5521: my $querystring = "?activity=$activity";
1.1351 raeburn 5522: # $uname and $udom decide whose portfolio (or information page) the user is trying to look at
5523: if (($activity eq 'port') || ($activity eq 'about') || ($activity eq 'passwd')) {
1.1232 raeburn 5524: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5525: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5526: } elsif ($activity eq 'docs') {
1.1347 raeburn 5527: my $showurl = &Apache::lonenc::check_encrypt($url);
5528: $querystring .= '&url='.&HTML::Entities::encode($showurl,'\'&"<>');
5529: if ($symb) {
5530: my $showsymb = &Apache::lonenc::check_encrypt($symb);
5531: $querystring .= '&symb='.&HTML::Entities::encode($showsymb,'\'&"<>');
5532: }
1.1062 raeburn 5533: }
1.1061 raeburn 5534:
5535: my $output .= <<'END_MYBLOCK';
5536: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5537: var options = "width=" + w + ",height=" + h + ",";
5538: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5539: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5540: var newWin = window.open(url, wdwName, options);
5541: newWin.focus();
5542: }
1.890 droeschl 5543: END_MYBLOCK
1.854 kalberla 5544:
1.1061 raeburn 5545: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5546:
1.1061 raeburn 5547: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5548: my $text = &mt('Communication Blocked');
1.1217 raeburn 5549: my $class = 'LC_comblock';
1.1062 raeburn 5550: if ($activity eq 'docs') {
5551: $text = &mt('Content Access Blocked');
1.1217 raeburn 5552: $class = '';
1.1063 raeburn 5553: } elsif ($activity eq 'printout') {
5554: $text = &mt('Printing Blocked');
1.1232 raeburn 5555: } elsif ($activity eq 'passwd') {
5556: $text = &mt('Password Changing Blocked');
1.1345 raeburn 5557: } elsif ($activity eq 'grades') {
5558: $text = &mt('Gradebook Blocked');
1.1346 raeburn 5559: } elsif ($activity eq 'search') {
5560: $text = &mt('Search Blocked');
1.1282 raeburn 5561: } elsif ($activity eq 'alert') {
5562: $text = &mt('Checking Critical Messages Blocked');
5563: } elsif ($activity eq 'reinit') {
5564: $text = &mt('Checking Course Update Blocked');
1.1351 raeburn 5565: } elsif ($activity eq 'about') {
5566: $text = &mt('Access to User Information Pages Blocked');
1.1062 raeburn 5567: }
1.1061 raeburn 5568: $output .= <<"END_BLOCK";
1.1217 raeburn 5569: <div class='$class'>
1.869 kalberla 5570: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5571: title='$text'>
5572: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5573: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5574: title='$text'>$text</a>
1.867 kalberla 5575: </div>
5576:
5577: END_BLOCK
1.474 raeburn 5578:
1.1061 raeburn 5579: return ($blocked, $output);
1.854 kalberla 5580: }
1.490 raeburn 5581:
1.60 matthew 5582: ###############################################
5583:
1.682 raeburn 5584: sub check_ip_acc {
1.1201 raeburn 5585: my ($acc,$clientip)=@_;
1.682 raeburn 5586: &Apache::lonxml::debug("acc is $acc");
5587: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5588: return 1;
5589: }
1.1339 raeburn 5590: my ($ip,$allowed);
5591: if (($ENV{'REMOTE_ADDR'} eq '127.0.0.1') ||
5592: ($ENV{'REMOTE_ADDR'} eq &Apache::lonnet::get_host_ip($Apache::lonnet::perlvar{'lonHostID'}))) {
5593: $ip = $env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
5594: } else {
1.1350 raeburn 5595: my $remote_ip = &Apache::lonnet::get_requestor_ip();
5596: $ip = $remote_ip || $env{'request.host'} || $clientip;
1.1339 raeburn 5597: }
1.682 raeburn 5598:
5599: my $name;
1.1219 raeburn 5600: my %access = (
5601: allowfrom => 1,
5602: denyfrom => 0,
5603: );
5604: my @allows;
5605: my @denies;
5606: foreach my $item (split(',',$acc)) {
5607: $item =~ s/^\s*//;
5608: $item =~ s/\s*$//;
5609: my $pattern;
5610: if ($item =~ /^\!(.+)$/) {
5611: push(@denies,$1);
5612: } else {
5613: push(@allows,$item);
5614: }
5615: }
5616: my $numdenies = scalar(@denies);
5617: my $numallows = scalar(@allows);
5618: my $count = 0;
5619: foreach my $pattern (@denies,@allows) {
5620: $count ++;
5621: my $acctype = 'allowfrom';
5622: if ($count <= $numdenies) {
5623: $acctype = 'denyfrom';
5624: }
1.682 raeburn 5625: if ($pattern =~ /\*$/) {
5626: #35.8.*
5627: $pattern=~s/\*//;
1.1219 raeburn 5628: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5629: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5630: #35.8.3.[34-56]
5631: my $low=$2;
5632: my $high=$3;
5633: $pattern=$1;
5634: if ($ip =~ /^\Q$pattern\E/) {
5635: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5636: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5637: }
5638: } elsif ($pattern =~ /^\*/) {
5639: #*.msu.edu
5640: $pattern=~s/\*//;
5641: if (!defined($name)) {
5642: use Socket;
5643: my $netaddr=inet_aton($ip);
5644: ($name)=gethostbyaddr($netaddr,AF_INET);
5645: }
1.1219 raeburn 5646: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5647: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5648: #127.0.0.1
1.1219 raeburn 5649: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5650: } else {
5651: #some.name.com
5652: if (!defined($name)) {
5653: use Socket;
5654: my $netaddr=inet_aton($ip);
5655: ($name)=gethostbyaddr($netaddr,AF_INET);
5656: }
1.1219 raeburn 5657: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5658: }
5659: if ($allowed =~ /^(0|1)$/) { last; }
5660: }
5661: if ($allowed eq '') {
5662: if ($numdenies && !$numallows) {
5663: $allowed = 1;
5664: } else {
5665: $allowed = 0;
1.682 raeburn 5666: }
5667: }
5668: return $allowed;
5669: }
5670:
5671: ###############################################
5672:
1.60 matthew 5673: =pod
5674:
1.112 bowersj2 5675: =head1 Domain Template Functions
5676:
5677: =over 4
5678:
5679: =item * &determinedomain()
1.60 matthew 5680:
5681: Inputs: $domain (usually will be undef)
5682:
1.63 www 5683: Returns: Determines which domain should be used for designs
1.60 matthew 5684:
5685: =cut
1.54 www 5686:
1.60 matthew 5687: ###############################################
1.63 www 5688: sub determinedomain {
5689: my $domain=shift;
1.531 albertel 5690: if (! $domain) {
1.60 matthew 5691: # Determine domain if we have not been given one
1.893 raeburn 5692: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5693: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5694: if ($env{'request.role.domain'}) {
5695: $domain=$env{'request.role.domain'};
1.60 matthew 5696: }
5697: }
1.63 www 5698: return $domain;
5699: }
5700: ###############################################
1.517 raeburn 5701:
1.518 albertel 5702: sub devalidate_domconfig_cache {
5703: my ($udom)=@_;
5704: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5705: }
5706:
5707: # ---------------------- Get domain configuration for a domain
5708: sub get_domainconf {
5709: my ($udom) = @_;
5710: my $cachetime=1800;
5711: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5712: if (defined($cached)) { return %{$result}; }
5713:
5714: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5715: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5716: my (%designhash,%legacy);
1.518 albertel 5717: if (keys(%domconfig) > 0) {
5718: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5719: if (keys(%{$domconfig{'login'}})) {
5720: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5721: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5722: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5723: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5724: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5725: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5726: if ($key eq 'loginvia') {
5727: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5728: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5729: $designhash{$udom.'.login.loginvia'} = $server;
5730: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5731:
5732: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5733: } else {
5734: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5735: }
1.948 raeburn 5736: }
1.1208 raeburn 5737: } elsif ($key eq 'headtag') {
5738: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5739: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5740: }
1.946 raeburn 5741: }
1.1208 raeburn 5742: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5743: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5744: }
1.946 raeburn 5745: }
5746: }
5747: }
5748: } else {
5749: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5750: $designhash{$udom.'.login.'.$key.'_'.$img} =
5751: $domconfig{'login'}{$key}{$img};
5752: }
1.699 raeburn 5753: }
5754: } else {
5755: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5756: }
1.632 raeburn 5757: }
5758: } else {
5759: $legacy{'login'} = 1;
1.518 albertel 5760: }
1.632 raeburn 5761: } else {
5762: $legacy{'login'} = 1;
1.518 albertel 5763: }
5764: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5765: if (keys(%{$domconfig{'rolecolors'}})) {
5766: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5767: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5768: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5769: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5770: }
1.518 albertel 5771: }
5772: }
1.632 raeburn 5773: } else {
5774: $legacy{'rolecolors'} = 1;
1.518 albertel 5775: }
1.632 raeburn 5776: } else {
5777: $legacy{'rolecolors'} = 1;
1.518 albertel 5778: }
1.948 raeburn 5779: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5780: if ($domconfig{'autoenroll'}{'co-owners'}) {
5781: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5782: }
5783: }
1.632 raeburn 5784: if (keys(%legacy) > 0) {
5785: my %legacyhash = &get_legacy_domconf($udom);
5786: foreach my $item (keys(%legacyhash)) {
5787: if ($item =~ /^\Q$udom\E\.login/) {
5788: if ($legacy{'login'}) {
5789: $designhash{$item} = $legacyhash{$item};
5790: }
5791: } else {
5792: if ($legacy{'rolecolors'}) {
5793: $designhash{$item} = $legacyhash{$item};
5794: }
1.518 albertel 5795: }
5796: }
5797: }
1.632 raeburn 5798: } else {
5799: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5800: }
5801: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5802: $cachetime);
5803: return %designhash;
5804: }
5805:
1.632 raeburn 5806: sub get_legacy_domconf {
5807: my ($udom) = @_;
5808: my %legacyhash;
5809: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5810: my $designfile = $designdir.'/'.$udom.'.tab';
5811: if (-e $designfile) {
1.1317 raeburn 5812: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5813: while (my $line = <$fh>) {
5814: next if ($line =~ /^\#/);
5815: chomp($line);
5816: my ($key,$val)=(split(/\=/,$line));
5817: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5818: }
5819: close($fh);
5820: }
5821: }
1.1026 raeburn 5822: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5823: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5824: }
5825: return %legacyhash;
5826: }
5827:
1.63 www 5828: =pod
5829:
1.112 bowersj2 5830: =item * &domainlogo()
1.63 www 5831:
5832: Inputs: $domain (usually will be undef)
5833:
5834: Returns: A link to a domain logo, if the domain logo exists.
5835: If the domain logo does not exist, a description of the domain.
5836:
5837: =cut
1.112 bowersj2 5838:
1.63 www 5839: ###############################################
5840: sub domainlogo {
1.517 raeburn 5841: my $domain = &determinedomain(shift);
1.518 albertel 5842: my %designhash = &get_domainconf($domain);
1.517 raeburn 5843: # See if there is a logo
5844: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5845: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5846: if ($imgsrc =~ m{^/(adm|res)/}) {
5847: if ($imgsrc =~ m{^/res/}) {
5848: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5849: &Apache::lonnet::repcopy($local_name);
5850: }
5851: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5852: }
5853: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5854: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5855: return &Apache::lonnet::domain($domain,'description');
1.59 www 5856: } else {
1.60 matthew 5857: return '';
1.59 www 5858: }
5859: }
1.63 www 5860: ##############################################
5861:
5862: =pod
5863:
1.112 bowersj2 5864: =item * &designparm()
1.63 www 5865:
5866: Inputs: $which parameter; $domain (usually will be undef)
5867:
5868: Returns: value of designparamter $which
5869:
5870: =cut
1.112 bowersj2 5871:
1.397 albertel 5872:
1.400 albertel 5873: ##############################################
1.397 albertel 5874: sub designparm {
5875: my ($which,$domain)=@_;
5876: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5877: return $env{'environment.color.'.$which};
1.96 www 5878: }
1.63 www 5879: $domain=&determinedomain($domain);
1.1016 raeburn 5880: my %domdesign;
5881: unless ($domain eq 'public') {
5882: %domdesign = &get_domainconf($domain);
5883: }
1.520 raeburn 5884: my $output;
1.517 raeburn 5885: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5886: $output = $domdesign{$domain.'.'.$which};
1.63 www 5887: } else {
1.520 raeburn 5888: $output = $defaultdesign{$which};
5889: }
5890: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5891: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5892: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5893: if ($output =~ m{^/res/}) {
5894: my $local_name = &Apache::lonnet::filelocation('',$output);
5895: &Apache::lonnet::repcopy($local_name);
5896: }
1.520 raeburn 5897: $output = &lonhttpdurl($output);
5898: }
1.63 www 5899: }
1.520 raeburn 5900: return $output;
1.63 www 5901: }
1.59 www 5902:
1.822 bisitz 5903: ##############################################
5904: =pod
5905:
1.832 bisitz 5906: =item * &authorspace()
5907:
1.1028 raeburn 5908: Inputs: $url (usually will be undef).
1.832 bisitz 5909:
1.1132 raeburn 5910: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5911: directory being viewed (or for which action is being taken).
5912: If $url is provided, and begins /priv/<domain>/<uname>
5913: the path will be that portion of the $context argument.
5914: Otherwise the path will be for the author space of the current
5915: user when the current role is author, or for that of the
5916: co-author/assistant co-author space when the current role
5917: is co-author or assistant co-author.
1.832 bisitz 5918:
5919: =cut
5920:
5921: sub authorspace {
1.1028 raeburn 5922: my ($url) = @_;
5923: if ($url ne '') {
5924: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5925: return $1;
5926: }
5927: }
1.832 bisitz 5928: my $caname = '';
1.1024 www 5929: my $cadom = '';
1.1028 raeburn 5930: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5931: ($cadom,$caname) =
1.832 bisitz 5932: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5933: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5934: $caname = $env{'user.name'};
1.1024 www 5935: $cadom = $env{'user.domain'};
1.832 bisitz 5936: }
1.1028 raeburn 5937: if (($caname ne '') && ($cadom ne '')) {
5938: return "/priv/$cadom/$caname/";
5939: }
5940: return;
1.832 bisitz 5941: }
5942:
5943: ##############################################
5944: =pod
5945:
1.822 bisitz 5946: =item * &head_subbox()
5947:
5948: Inputs: $content (contains HTML code with page functions, etc.)
5949:
5950: Returns: HTML div with $content
5951: To be included in page header
5952:
5953: =cut
5954:
5955: sub head_subbox {
5956: my ($content)=@_;
5957: my $output =
1.993 raeburn 5958: '<div class="LC_head_subbox">'
1.822 bisitz 5959: .$content
5960: .'</div>'
5961: }
5962:
5963: ##############################################
5964: =pod
5965:
5966: =item * &CSTR_pageheader()
5967:
1.1026 raeburn 5968: Input: (optional) filename from which breadcrumb trail is built.
5969: In most cases no input as needed, as $env{'request.filename'}
5970: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5971:
5972: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5973: To be included on Authoring Space pages
1.822 bisitz 5974:
5975: =cut
5976:
5977: sub CSTR_pageheader {
1.1026 raeburn 5978: my ($trailfile) = @_;
5979: if ($trailfile eq '') {
5980: $trailfile = $env{'request.filename'};
5981: }
5982:
5983: # this is for resources; directories have customtitle, and crumbs
5984: # and select recent are created in lonpubdir.pm
5985:
5986: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5987: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5988: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5989: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5990: $formaction =~ s{/+}{/}g;
1.822 bisitz 5991:
5992: my $parentpath = '';
5993: my $lastitem = '';
5994: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5995: $parentpath = $1;
5996: $lastitem = $2;
5997: } else {
5998: $lastitem = $thisdisfn;
5999: }
1.921 bisitz 6000:
1.1246 raeburn 6001: my ($crsauthor,$title);
6002: if (($env{'request.course.id'}) &&
6003: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 6004: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 6005: $crsauthor = 1;
6006: $title = &mt('Course Authoring Space');
6007: } else {
6008: $title = &mt('Authoring Space');
6009: }
6010:
1.1314 raeburn 6011: my ($target,$crumbtarget) = (' target="_top"','_top'); #FIXME lonpubdir: target="_parent"
1.1313 raeburn 6012: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 6013: $target = '';
6014: $crumbtarget = '';
1.1313 raeburn 6015: }
6016:
1.921 bisitz 6017: my $output =
1.822 bisitz 6018: '<div>'
6019: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 6020: .'<b>'.$title.'</b> '
1.1314 raeburn 6021: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
6022: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 6023:
6024: if ($lastitem) {
6025: $output .=
6026: '<span class="LC_filename">'
6027: .$lastitem
6028: .'</span>';
6029: }
1.1245 raeburn 6030:
1.1246 raeburn 6031: if ($crsauthor) {
6032: $output .= '</form>'.&Apache::lonmenu::constspaceform();
6033: } else {
6034: $output .=
6035: '<br />'
1.1314 raeburn 6036: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 6037: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
6038: .'</form>'
6039: .&Apache::lonmenu::constspaceform();
6040: }
6041: $output .= '</div>';
1.921 bisitz 6042:
6043: return $output;
1.822 bisitz 6044: }
6045:
1.60 matthew 6046: ###############################################
6047: ###############################################
6048:
6049: =pod
6050:
1.112 bowersj2 6051: =back
6052:
1.549 albertel 6053: =head1 HTML Helpers
1.112 bowersj2 6054:
6055: =over 4
6056:
6057: =item * &bodytag()
1.60 matthew 6058:
6059: Returns a uniform header for LON-CAPA web pages.
6060:
6061: Inputs:
6062:
1.112 bowersj2 6063: =over 4
6064:
6065: =item * $title, A title to be displayed on the page.
6066:
6067: =item * $function, the current role (can be undef).
6068:
6069: =item * $addentries, extra parameters for the <body> tag.
6070:
6071: =item * $bodyonly, if defined, only return the <body> tag.
6072:
6073: =item * $domain, if defined, force a given domain.
6074:
6075: =item * $forcereg, if page should register as content page (relevant for
1.86 www 6076: text interface only)
1.60 matthew 6077:
1.814 bisitz 6078: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
6079: navigational links
1.317 albertel 6080:
1.338 albertel 6081: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
6082:
1.460 albertel 6083: =item * $args, optional argument valid values are
6084: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 6085: use_absolute -> for external resource or syllabus, this will
6086: contain https://<hostname> if server uses
6087: https (as per hosts.tab), but request is for http
6088: hostname -> hostname, from $r->hostname().
1.460 albertel 6089:
1.1096 raeburn 6090: =item * $advtoolsref, optional argument, ref to an array containing
6091: inlineremote items to be added in "Functions" menu below
6092: breadcrumbs.
6093:
1.1316 raeburn 6094: =item * $ltiscope, optional argument, will be one of: resource, map or
6095: course, if LON-CAPA is in LTI Provider context. Value is
6096: the scope of use, i.e., launch was for access to a single, a map
6097: or the entire course.
6098:
6099: =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
6100: context, this will contain the URL for the landing item in
6101: the course, after launch from an LTI Consumer
6102:
1.1318 raeburn 6103: =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
6104: context, this will contain a reference to hash of items
6105: to be included in the page header and/or inline menu.
6106:
1.112 bowersj2 6107: =back
6108:
1.60 matthew 6109: Returns: A uniform header for LON-CAPA web pages.
6110: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
6111: If $bodyonly is undef or zero, an html string containing a <body> tag and
6112: other decorations will be returned.
6113:
6114: =cut
6115:
1.54 www 6116: sub bodytag {
1.831 bisitz 6117: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1359 raeburn 6118: $no_nav_bar,$bgcolor,$args,$advtoolsref,$ltiscope,$ltiuri,
6119: $ltimenu,$menucoll,$menuref)=@_;
1.339 albertel 6120:
1.954 raeburn 6121: my $public;
6122: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
6123: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
6124: $public = 1;
6125: }
1.460 albertel 6126: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 6127: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 6128: my $hostname = $args->{'hostname'};
1.339 albertel 6129:
1.183 matthew 6130: $function = &get_users_function() if (!$function);
1.339 albertel 6131: my $img = &designparm($function.'.img',$domain);
6132: my $font = &designparm($function.'.font',$domain);
6133: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
6134:
1.803 bisitz 6135: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 6136: 'bgcolor' => $pgbg,
1.339 albertel 6137: 'text' => $font,
6138: 'alink' => &designparm($function.'.alink',$domain),
6139: 'vlink' => &designparm($function.'.vlink',$domain),
6140: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 6141: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 6142:
1.63 www 6143: # role and realm
1.1178 raeburn 6144: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
6145: if ($realm) {
6146: $realm = '/'.$realm;
6147: }
1.1357 raeburn 6148: if ($role eq 'ca') {
1.479 albertel 6149: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 6150: $realm = &plainname($rname,$rdom);
1.378 raeburn 6151: }
1.55 www 6152: # realm
1.1357 raeburn 6153: my ($cid,$sec);
1.258 albertel 6154: if ($env{'request.course.id'}) {
1.1357 raeburn 6155: $cid = $env{'request.course.id'};
6156: if ($env{'request.course.sec'}) {
6157: $sec = $env{'request.course.sec'};
6158: }
6159: } elsif ($realm =~ m{^/($match_domain)/($match_courseid)(?:|/(\w+))$}) {
6160: if (&Apache::lonnet::is_course($1,$2)) {
6161: $cid = $1.'_'.$2;
6162: $sec = $3;
6163: }
6164: }
6165: if ($cid) {
1.378 raeburn 6166: if ($env{'request.role'} !~ /^cr/) {
6167: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 6168: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 6169: if ($env{'request.role.desc'}) {
6170: $role = $env{'request.role.desc'};
6171: } else {
6172: $role = &mt('Helpdesk[_1]',' '.$2);
6173: }
1.1257 raeburn 6174: } else {
6175: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6176: }
1.1357 raeburn 6177: if ($sec) {
6178: $role .= (' 'x2).'- '.&mt('section:').' '.$sec;
1.898 raeburn 6179: }
1.1357 raeburn 6180: $realm = $env{'course.'.$cid.'.description'};
1.378 raeburn 6181: } else {
6182: $role = &Apache::lonnet::plaintext($role);
1.54 www 6183: }
1.433 albertel 6184:
1.359 albertel 6185: if (!$realm) { $realm=' '; }
1.330 albertel 6186:
1.438 albertel 6187: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6188:
1.101 www 6189: # construct main body tag
1.359 albertel 6190: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6191: &Apache::lontexconvert::init_math_support();
1.252 albertel 6192:
1.1131 raeburn 6193: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6194:
1.1130 raeburn 6195: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6196: return $bodytag;
1.1130 raeburn 6197: }
1.359 albertel 6198:
1.954 raeburn 6199: if ($public) {
1.433 albertel 6200: undef($role);
6201: }
1.1318 raeburn 6202:
1.1359 raeburn 6203: my $showcrstitle = 1;
1.1357 raeburn 6204: if (($cid) && ($env{'request.lti.login'})) {
1.1318 raeburn 6205: if (ref($ltimenu) eq 'HASH') {
6206: unless ($ltimenu->{'role'}) {
6207: undef($role);
6208: }
6209: unless ($ltimenu->{'coursetitle'}) {
6210: $realm=' ';
1.1359 raeburn 6211: $showcrstitle = 0;
6212: }
6213: }
6214: } elsif (($cid) && ($menucoll)) {
6215: if (ref($menuref) eq 'HASH') {
6216: unless ($menuref->{'role'}) {
6217: undef($role);
6218: }
6219: unless ($menuref->{'crs'}) {
6220: $realm=' ';
6221: $showcrstitle = 0;
1.1318 raeburn 6222: }
6223: }
6224: }
6225:
1.762 bisitz 6226: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6227: #
6228: # Extra info if you are the DC
6229: my $dc_info = '';
1.1359 raeburn 6230: if (($env{'user.adv'}) && ($env{'request.course.id'}) && $showcrstitle &&
1.1357 raeburn 6231: (exists($env{'user.role.dc./'.$env{'course.'.$cid.'.domain'}.'/'}))) {
1.917 raeburn 6232: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6233: $dc_info =~ s/\s+$//;
1.359 albertel 6234: }
6235:
1.1237 raeburn 6236: my $crstype;
1.1357 raeburn 6237: if ($cid) {
6238: $crstype = $env{'course.'.$cid.'.type'};
1.1237 raeburn 6239: } elsif ($args->{'crstype'}) {
6240: $crstype = $args->{'crstype'};
6241: }
6242: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
6243: undef($role);
6244: } else {
1.1242 raeburn 6245: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 6246: }
1.853 droeschl 6247:
1.903 droeschl 6248: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6249:
6250: # if ($env{'request.state'} eq 'construct') {
6251: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6252: # }
6253:
1.1130 raeburn 6254: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 6255: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6256:
1.1318 raeburn 6257: unless ($args->{'no_primary_menu'}) {
1.1359 raeburn 6258: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu,$menucoll,$menuref);
1.359 albertel 6259:
1.1318 raeburn 6260: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6261: if ($dc_info) {
6262: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6263: }
6264: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6265: <em>$realm</em> $dc_info</div>|;
6266: return $bodytag;
6267: }
1.894 droeschl 6268:
1.1318 raeburn 6269: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6270: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6271: }
1.916 droeschl 6272:
1.1318 raeburn 6273: $bodytag .= $right;
1.852 droeschl 6274:
1.1318 raeburn 6275: if ($dc_info) {
6276: $dc_info = &dc_courseid_toggle($dc_info);
6277: }
6278: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6279: }
1.916 droeschl 6280:
1.1169 raeburn 6281: #if directed to not display the secondary menu, don't.
1.1168 raeburn 6282: if ($args->{'no_secondary_menu'}) {
6283: return $bodytag;
6284: }
1.1169 raeburn 6285: #don't show menus for public users
1.954 raeburn 6286: if (!$public){
1.1318 raeburn 6287: unless ($args->{'no_inline_menu'}) {
6288: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
1.1359 raeburn 6289: $args->{'no_primary_menu'},
6290: $menucoll,$menuref);
1.1318 raeburn 6291: }
1.903 droeschl 6292: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6293: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6294: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6295: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1316 raeburn 6296: $args->{'bread_crumbs'},'','',$hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6297: } elsif ($forcereg) {
6298: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 raeburn 6299: $args->{'group'},
1.1274 raeburn 6300: $args->{'hide_buttons'},
1.1316 raeburn 6301: $hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6302: } else {
6303: $bodytag .=
6304: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6305: $forcereg,$args->{'group'},
6306: $args->{'bread_crumbs'},
1.1274 raeburn 6307: $advtoolsref,'',$hostname);
1.920 raeburn 6308: }
1.903 droeschl 6309: }else{
6310: # this is to seperate menu from content when there's no secondary
6311: # menu. Especially needed for public accessible ressources.
6312: $bodytag .= '<hr style="clear:both" />';
6313: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6314: }
1.903 droeschl 6315:
1.235 raeburn 6316: return $bodytag;
1.182 matthew 6317: }
6318:
1.917 raeburn 6319: sub dc_courseid_toggle {
6320: my ($dc_info) = @_;
1.980 raeburn 6321: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6322: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6323: &mt('(More ...)').'</a></span>'.
6324: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6325: }
6326:
1.330 albertel 6327: sub make_attr_string {
6328: my ($register,$attr_ref) = @_;
6329:
6330: if ($attr_ref && !ref($attr_ref)) {
6331: die("addentries Must be a hash ref ".
6332: join(':',caller(1))." ".
6333: join(':',caller(0))." ");
6334: }
6335:
6336: if ($register) {
1.339 albertel 6337: my ($on_load,$on_unload);
6338: foreach my $key (keys(%{$attr_ref})) {
6339: if (lc($key) eq 'onload') {
6340: $on_load.=$attr_ref->{$key}.';';
6341: delete($attr_ref->{$key});
6342:
6343: } elsif (lc($key) eq 'onunload') {
6344: $on_unload.=$attr_ref->{$key}.';';
6345: delete($attr_ref->{$key});
6346: }
6347: }
1.953 droeschl 6348: $attr_ref->{'onload'} = $on_load;
6349: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6350: }
1.339 albertel 6351:
1.330 albertel 6352: my $attr_string;
1.1159 raeburn 6353: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6354: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6355: }
6356: return $attr_string;
6357: }
6358:
6359:
1.182 matthew 6360: ###############################################
1.251 albertel 6361: ###############################################
6362:
6363: =pod
6364:
6365: =item * &endbodytag()
6366:
6367: Returns a uniform footer for LON-CAPA web pages.
6368:
1.635 raeburn 6369: Inputs: 1 - optional reference to an args hash
6370: If in the hash, key for noredirectlink has a value which evaluates to true,
6371: a 'Continue' link is not displayed if the page contains an
6372: internal redirect in the <head></head> section,
6373: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6374:
6375: =cut
6376:
6377: sub endbodytag {
1.635 raeburn 6378: my ($args) = @_;
1.1080 raeburn 6379: my $endbodytag;
6380: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6381: $endbodytag='</body>';
6382: }
1.315 albertel 6383: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6384: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6385: $endbodytag=
6386: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6387: &mt('Continue').'</a>'.
6388: $endbodytag;
6389: }
1.315 albertel 6390: }
1.251 albertel 6391: return $endbodytag;
6392: }
6393:
1.352 albertel 6394: =pod
6395:
6396: =item * &standard_css()
6397:
6398: Returns a style sheet
6399:
6400: Inputs: (all optional)
6401: domain -> force to color decorate a page for a specific
6402: domain
6403: function -> force usage of a specific rolish color scheme
6404: bgcolor -> override the default page bgcolor
6405:
6406: =cut
6407:
1.343 albertel 6408: sub standard_css {
1.345 albertel 6409: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6410: $function = &get_users_function() if (!$function);
6411: my $img = &designparm($function.'.img', $domain);
6412: my $tabbg = &designparm($function.'.tabbg', $domain);
6413: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6414: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6415: #second colour for later usage
1.345 albertel 6416: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6417: my $pgbg_or_bgcolor =
6418: $bgcolor ||
1.352 albertel 6419: &designparm($function.'.pgbg', $domain);
1.382 albertel 6420: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6421: my $alink = &designparm($function.'.alink', $domain);
6422: my $vlink = &designparm($function.'.vlink', $domain);
6423: my $link = &designparm($function.'.link', $domain);
6424:
1.602 albertel 6425: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6426: my $mono = 'monospace';
1.850 bisitz 6427: my $data_table_head = $sidebg;
6428: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6429: my $data_table_dark = '#E0E0E0';
1.470 banghart 6430: my $data_table_darker = '#CCCCCC';
1.349 albertel 6431: my $data_table_highlight = '#FFFF00';
1.352 albertel 6432: my $mail_new = '#FFBB77';
6433: my $mail_new_hover = '#DD9955';
6434: my $mail_read = '#BBBB77';
6435: my $mail_read_hover = '#999944';
6436: my $mail_replied = '#AAAA88';
6437: my $mail_replied_hover = '#888855';
6438: my $mail_other = '#99BBBB';
6439: my $mail_other_hover = '#669999';
1.391 albertel 6440: my $table_header = '#DDDDDD';
1.489 raeburn 6441: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6442: my $lg_border_color = '#C8C8C8';
1.952 onken 6443: my $button_hover = '#BF2317';
1.392 albertel 6444:
1.608 albertel 6445: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6446: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6447: : '0 3px 0 4px';
1.448 albertel 6448:
1.523 albertel 6449:
1.343 albertel 6450: return <<END;
1.947 droeschl 6451:
6452: /* needed for iframe to allow 100% height in FF */
6453: body, html {
6454: margin: 0;
6455: padding: 0 0.5%;
6456: height: 99%; /* to avoid scrollbars */
6457: }
6458:
1.795 www 6459: body {
1.911 bisitz 6460: font-family: $sans;
6461: line-height:130%;
6462: font-size:0.83em;
6463: color:$font;
1.795 www 6464: }
6465:
1.959 onken 6466: a:focus,
6467: a:focus img {
1.795 www 6468: color: red;
6469: }
1.698 harmsja 6470:
1.911 bisitz 6471: form, .inline {
6472: display: inline;
1.795 www 6473: }
1.721 harmsja 6474:
1.795 www 6475: .LC_right {
1.911 bisitz 6476: text-align:right;
1.795 www 6477: }
6478:
6479: .LC_middle {
1.911 bisitz 6480: vertical-align:middle;
1.795 www 6481: }
1.721 harmsja 6482:
1.1130 raeburn 6483: .LC_floatleft {
6484: float: left;
6485: }
6486:
6487: .LC_floatright {
6488: float: right;
6489: }
6490:
1.911 bisitz 6491: .LC_400Box {
6492: width:400px;
6493: }
1.721 harmsja 6494:
1.947 droeschl 6495: .LC_iframecontainer {
6496: width: 98%;
6497: margin: 0;
6498: position: fixed;
6499: top: 8.5em;
6500: bottom: 0;
6501: }
6502:
6503: .LC_iframecontainer iframe{
6504: border: none;
6505: width: 100%;
6506: height: 100%;
6507: }
6508:
1.778 bisitz 6509: .LC_filename {
6510: font-family: $mono;
6511: white-space:pre;
1.921 bisitz 6512: font-size: 120%;
1.778 bisitz 6513: }
6514:
6515: .LC_fileicon {
6516: border: none;
6517: height: 1.3em;
6518: vertical-align: text-bottom;
6519: margin-right: 0.3em;
6520: text-decoration:none;
6521: }
6522:
1.1008 www 6523: .LC_setting {
6524: text-decoration:underline;
6525: }
6526:
1.350 albertel 6527: .LC_error {
6528: color: red;
6529: }
1.795 www 6530:
1.1097 bisitz 6531: .LC_warning {
6532: color: darkorange;
6533: }
6534:
1.457 albertel 6535: .LC_diff_removed {
1.733 bisitz 6536: color: red;
1.394 albertel 6537: }
1.532 albertel 6538:
6539: .LC_info,
1.457 albertel 6540: .LC_success,
6541: .LC_diff_added {
1.350 albertel 6542: color: green;
6543: }
1.795 www 6544:
1.802 bisitz 6545: div.LC_confirm_box {
6546: background-color: #FAFAFA;
6547: border: 1px solid $lg_border_color;
6548: margin-right: 0;
6549: padding: 5px;
6550: }
6551:
6552: div.LC_confirm_box .LC_error img,
6553: div.LC_confirm_box .LC_success img {
6554: vertical-align: middle;
6555: }
6556:
1.1242 raeburn 6557: .LC_maxwidth {
6558: max-width: 100%;
6559: height: auto;
6560: }
6561:
1.1243 raeburn 6562: .LC_textsize_mobile {
6563: \@media only screen and (max-device-width: 480px) {
6564: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6565: }
6566: }
6567:
1.440 albertel 6568: .LC_icon {
1.771 droeschl 6569: border: none;
1.790 droeschl 6570: vertical-align: middle;
1.771 droeschl 6571: }
6572:
1.543 albertel 6573: .LC_docs_spacer {
6574: width: 25px;
6575: height: 1px;
1.771 droeschl 6576: border: none;
1.543 albertel 6577: }
1.346 albertel 6578:
1.532 albertel 6579: .LC_internal_info {
1.735 bisitz 6580: color: #999999;
1.532 albertel 6581: }
6582:
1.794 www 6583: .LC_discussion {
1.1050 www 6584: background: $data_table_dark;
1.911 bisitz 6585: border: 1px solid black;
6586: margin: 2px;
1.794 www 6587: }
6588:
6589: .LC_disc_action_left {
1.1050 www 6590: background: $sidebg;
1.911 bisitz 6591: text-align: left;
1.1050 www 6592: padding: 4px;
6593: margin: 2px;
1.794 www 6594: }
6595:
6596: .LC_disc_action_right {
1.1050 www 6597: background: $sidebg;
1.911 bisitz 6598: text-align: right;
1.1050 www 6599: padding: 4px;
6600: margin: 2px;
1.794 www 6601: }
6602:
6603: .LC_disc_new_item {
1.911 bisitz 6604: background: white;
6605: border: 2px solid red;
1.1050 www 6606: margin: 4px;
6607: padding: 4px;
1.794 www 6608: }
6609:
6610: .LC_disc_old_item {
1.911 bisitz 6611: background: white;
1.1050 www 6612: margin: 4px;
6613: padding: 4px;
1.794 www 6614: }
6615:
1.458 albertel 6616: table.LC_pastsubmission {
6617: border: 1px solid black;
6618: margin: 2px;
6619: }
6620:
1.924 bisitz 6621: table#LC_menubuttons {
1.345 albertel 6622: width: 100%;
6623: background: $pgbg;
1.392 albertel 6624: border: 2px;
1.402 albertel 6625: border-collapse: separate;
1.803 bisitz 6626: padding: 0;
1.345 albertel 6627: }
1.392 albertel 6628:
1.801 tempelho 6629: table#LC_title_bar a {
6630: color: $fontmenu;
6631: }
1.836 bisitz 6632:
1.807 droeschl 6633: table#LC_title_bar {
1.819 tempelho 6634: clear: both;
1.836 bisitz 6635: display: none;
1.807 droeschl 6636: }
6637:
1.795 www 6638: table#LC_title_bar,
1.933 droeschl 6639: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6640: table#LC_title_bar.LC_with_remote {
1.359 albertel 6641: width: 100%;
1.392 albertel 6642: border-color: $pgbg;
6643: border-style: solid;
6644: border-width: $border;
1.379 albertel 6645: background: $pgbg;
1.801 tempelho 6646: color: $fontmenu;
1.392 albertel 6647: border-collapse: collapse;
1.803 bisitz 6648: padding: 0;
1.819 tempelho 6649: margin: 0;
1.359 albertel 6650: }
1.795 www 6651:
1.933 droeschl 6652: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6653: margin: 0;
6654: padding: 0;
1.933 droeschl 6655: position: relative;
6656: list-style: none;
1.913 droeschl 6657: }
1.933 droeschl 6658: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6659: display: inline;
6660: }
1.933 droeschl 6661:
6662: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6663: padding: 0;
1.933 droeschl 6664: margin: 0;
6665: float: left;
1.913 droeschl 6666: }
1.933 droeschl 6667: .LC_breadcrumb_tools_tools {
6668: padding: 0;
6669: margin: 0;
1.913 droeschl 6670: float: right;
6671: }
6672:
1.1240 raeburn 6673: .LC_placement_prog {
6674: padding-right: 20px;
6675: font-weight: bold;
6676: font-size: 90%;
6677: }
6678:
1.359 albertel 6679: table#LC_title_bar td {
6680: background: $tabbg;
6681: }
1.795 www 6682:
1.911 bisitz 6683: table#LC_menubuttons img {
1.803 bisitz 6684: border: none;
1.346 albertel 6685: }
1.795 www 6686:
1.842 droeschl 6687: .LC_breadcrumbs_component {
1.911 bisitz 6688: float: right;
6689: margin: 0 1em;
1.357 albertel 6690: }
1.842 droeschl 6691: .LC_breadcrumbs_component img {
1.911 bisitz 6692: vertical-align: middle;
1.777 tempelho 6693: }
1.795 www 6694:
1.1243 raeburn 6695: .LC_breadcrumbs_hoverable {
6696: background: $sidebg;
6697: }
6698:
1.383 albertel 6699: td.LC_table_cell_checkbox {
6700: text-align: center;
6701: }
1.795 www 6702:
6703: .LC_fontsize_small {
1.911 bisitz 6704: font-size: 70%;
1.705 tempelho 6705: }
6706:
1.844 bisitz 6707: #LC_breadcrumbs {
1.911 bisitz 6708: clear:both;
6709: background: $sidebg;
6710: border-bottom: 1px solid $lg_border_color;
6711: line-height: 2.5em;
1.933 droeschl 6712: overflow: hidden;
1.911 bisitz 6713: margin: 0;
6714: padding: 0;
1.995 raeburn 6715: text-align: left;
1.819 tempelho 6716: }
1.862 bisitz 6717:
1.1098 bisitz 6718: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6719: clear:both;
6720: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6721: border: 1px solid $sidebg;
1.1098 bisitz 6722: margin: 0 0 10px 0;
1.966 bisitz 6723: padding: 3px;
1.995 raeburn 6724: text-align: left;
1.822 bisitz 6725: }
6726:
1.795 www 6727: .LC_fontsize_medium {
1.911 bisitz 6728: font-size: 85%;
1.705 tempelho 6729: }
6730:
1.795 www 6731: .LC_fontsize_large {
1.911 bisitz 6732: font-size: 120%;
1.705 tempelho 6733: }
6734:
1.346 albertel 6735: .LC_menubuttons_inline_text {
6736: color: $font;
1.698 harmsja 6737: font-size: 90%;
1.701 harmsja 6738: padding-left:3px;
1.346 albertel 6739: }
6740:
1.934 droeschl 6741: .LC_menubuttons_inline_text img{
6742: vertical-align: middle;
6743: }
6744:
1.1051 www 6745: li.LC_menubuttons_inline_text img {
1.951 onken 6746: cursor:pointer;
1.1002 droeschl 6747: text-decoration: none;
1.951 onken 6748: }
6749:
1.526 www 6750: .LC_menubuttons_link {
6751: text-decoration: none;
6752: }
1.795 www 6753:
1.522 albertel 6754: .LC_menubuttons_category {
1.521 www 6755: color: $font;
1.526 www 6756: background: $pgbg;
1.521 www 6757: font-size: larger;
6758: font-weight: bold;
6759: }
6760:
1.346 albertel 6761: td.LC_menubuttons_text {
1.911 bisitz 6762: color: $font;
1.346 albertel 6763: }
1.706 harmsja 6764:
1.346 albertel 6765: .LC_current_location {
6766: background: $tabbg;
6767: }
1.795 www 6768:
1.1286 raeburn 6769: td.LC_zero_height {
6770: line-height: 0;
6771: cellpadding: 0;
6772: }
6773:
1.938 bisitz 6774: table.LC_data_table {
1.347 albertel 6775: border: 1px solid #000000;
1.402 albertel 6776: border-collapse: separate;
1.426 albertel 6777: border-spacing: 1px;
1.610 albertel 6778: background: $pgbg;
1.347 albertel 6779: }
1.795 www 6780:
1.422 albertel 6781: .LC_data_table_dense {
6782: font-size: small;
6783: }
1.795 www 6784:
1.507 raeburn 6785: table.LC_nested_outer {
6786: border: 1px solid #000000;
1.589 raeburn 6787: border-collapse: collapse;
1.803 bisitz 6788: border-spacing: 0;
1.507 raeburn 6789: width: 100%;
6790: }
1.795 www 6791:
1.879 raeburn 6792: table.LC_innerpickbox,
1.507 raeburn 6793: table.LC_nested {
1.803 bisitz 6794: border: none;
1.589 raeburn 6795: border-collapse: collapse;
1.803 bisitz 6796: border-spacing: 0;
1.507 raeburn 6797: width: 100%;
6798: }
1.795 www 6799:
1.911 bisitz 6800: table.LC_data_table tr th,
6801: table.LC_calendar tr th,
1.879 raeburn 6802: table.LC_prior_tries tr th,
6803: table.LC_innerpickbox tr th {
1.349 albertel 6804: font-weight: bold;
6805: background-color: $data_table_head;
1.801 tempelho 6806: color:$fontmenu;
1.701 harmsja 6807: font-size:90%;
1.347 albertel 6808: }
1.795 www 6809:
1.879 raeburn 6810: table.LC_innerpickbox tr th,
6811: table.LC_innerpickbox tr td {
6812: vertical-align: top;
6813: }
6814:
1.711 raeburn 6815: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6816: background-color: #CCCCCC;
1.711 raeburn 6817: font-weight: bold;
6818: text-align: left;
6819: }
1.795 www 6820:
1.912 bisitz 6821: table.LC_data_table tr.LC_odd_row > td {
6822: background-color: $data_table_light;
6823: padding: 2px;
6824: vertical-align: top;
6825: }
6826:
1.809 bisitz 6827: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6828: background-color: $data_table_light;
1.912 bisitz 6829: vertical-align: top;
6830: }
6831:
6832: table.LC_data_table tr.LC_even_row > td {
6833: background-color: $data_table_dark;
1.425 albertel 6834: padding: 2px;
1.900 bisitz 6835: vertical-align: top;
1.347 albertel 6836: }
1.795 www 6837:
1.809 bisitz 6838: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6839: background-color: $data_table_dark;
1.900 bisitz 6840: vertical-align: top;
1.347 albertel 6841: }
1.795 www 6842:
1.425 albertel 6843: table.LC_data_table tr.LC_data_table_highlight td {
6844: background-color: $data_table_darker;
6845: }
1.795 www 6846:
1.639 raeburn 6847: table.LC_data_table tr td.LC_leftcol_header {
6848: background-color: $data_table_head;
6849: font-weight: bold;
6850: }
1.795 www 6851:
1.451 albertel 6852: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6853: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6854: font-weight: bold;
6855: font-style: italic;
6856: text-align: center;
6857: padding: 8px;
1.347 albertel 6858: }
1.795 www 6859:
1.1114 raeburn 6860: table.LC_data_table tr.LC_empty_row td,
6861: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6862: background-color: $sidebg;
6863: }
6864:
6865: table.LC_nested tr.LC_empty_row td {
6866: background-color: #FFFFFF;
6867: }
6868:
1.890 droeschl 6869: table.LC_caption {
6870: }
6871:
1.507 raeburn 6872: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6873: padding: 4ex
6874: }
1.795 www 6875:
1.507 raeburn 6876: table.LC_nested_outer tr th {
6877: font-weight: bold;
1.801 tempelho 6878: color:$fontmenu;
1.507 raeburn 6879: background-color: $data_table_head;
1.701 harmsja 6880: font-size: small;
1.507 raeburn 6881: border-bottom: 1px solid #000000;
6882: }
1.795 www 6883:
1.507 raeburn 6884: table.LC_nested_outer tr td.LC_subheader {
6885: background-color: $data_table_head;
6886: font-weight: bold;
6887: font-size: small;
6888: border-bottom: 1px solid #000000;
6889: text-align: right;
1.451 albertel 6890: }
1.795 www 6891:
1.507 raeburn 6892: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6893: background-color: #CCCCCC;
1.451 albertel 6894: font-weight: bold;
6895: font-size: small;
1.507 raeburn 6896: text-align: center;
6897: }
1.795 www 6898:
1.589 raeburn 6899: table.LC_nested tr.LC_info_row td.LC_left_item,
6900: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6901: text-align: left;
1.451 albertel 6902: }
1.795 www 6903:
1.507 raeburn 6904: table.LC_nested td {
1.735 bisitz 6905: background-color: #FFFFFF;
1.451 albertel 6906: font-size: small;
1.507 raeburn 6907: }
1.795 www 6908:
1.507 raeburn 6909: table.LC_nested_outer tr th.LC_right_item,
6910: table.LC_nested tr.LC_info_row td.LC_right_item,
6911: table.LC_nested tr.LC_odd_row td.LC_right_item,
6912: table.LC_nested tr td.LC_right_item {
1.451 albertel 6913: text-align: right;
6914: }
6915:
1.507 raeburn 6916: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6917: background-color: #EEEEEE;
1.451 albertel 6918: }
6919:
1.473 raeburn 6920: table.LC_createuser {
6921: }
6922:
6923: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6924: font-size: small;
1.473 raeburn 6925: }
6926:
6927: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6928: background-color: #CCCCCC;
1.473 raeburn 6929: font-weight: bold;
6930: text-align: center;
6931: }
6932:
1.349 albertel 6933: table.LC_calendar {
6934: border: 1px solid #000000;
6935: border-collapse: collapse;
1.917 raeburn 6936: width: 98%;
1.349 albertel 6937: }
1.795 www 6938:
1.349 albertel 6939: table.LC_calendar_pickdate {
6940: font-size: xx-small;
6941: }
1.795 www 6942:
1.349 albertel 6943: table.LC_calendar tr td {
6944: border: 1px solid #000000;
6945: vertical-align: top;
1.917 raeburn 6946: width: 14%;
1.349 albertel 6947: }
1.795 www 6948:
1.349 albertel 6949: table.LC_calendar tr td.LC_calendar_day_empty {
6950: background-color: $data_table_dark;
6951: }
1.795 www 6952:
1.779 bisitz 6953: table.LC_calendar tr td.LC_calendar_day_current {
6954: background-color: $data_table_highlight;
1.777 tempelho 6955: }
1.795 www 6956:
1.938 bisitz 6957: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6958: background-color: $mail_new;
6959: }
1.795 www 6960:
1.938 bisitz 6961: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6962: background-color: $mail_new_hover;
6963: }
1.795 www 6964:
1.938 bisitz 6965: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6966: background-color: $mail_read;
6967: }
1.795 www 6968:
1.938 bisitz 6969: /*
6970: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6971: background-color: $mail_read_hover;
6972: }
1.938 bisitz 6973: */
1.795 www 6974:
1.938 bisitz 6975: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6976: background-color: $mail_replied;
6977: }
1.795 www 6978:
1.938 bisitz 6979: /*
6980: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6981: background-color: $mail_replied_hover;
6982: }
1.938 bisitz 6983: */
1.795 www 6984:
1.938 bisitz 6985: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6986: background-color: $mail_other;
6987: }
1.795 www 6988:
1.938 bisitz 6989: /*
6990: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6991: background-color: $mail_other_hover;
6992: }
1.938 bisitz 6993: */
1.494 raeburn 6994:
1.777 tempelho 6995: table.LC_data_table tr > td.LC_browser_file,
6996: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6997: background: #AAEE77;
1.389 albertel 6998: }
1.795 www 6999:
1.777 tempelho 7000: table.LC_data_table tr > td.LC_browser_file_locked,
7001: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 7002: background: #FFAA99;
1.387 albertel 7003: }
1.795 www 7004:
1.777 tempelho 7005: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 7006: background: #888888;
1.779 bisitz 7007: }
1.795 www 7008:
1.777 tempelho 7009: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 7010: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 7011: background: #F8F866;
1.777 tempelho 7012: }
1.795 www 7013:
1.696 bisitz 7014: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 7015: background: #E0E8FF;
1.387 albertel 7016: }
1.696 bisitz 7017:
1.707 bisitz 7018: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 7019: /* background: #77FF77; */
1.707 bisitz 7020: }
1.795 www 7021:
1.707 bisitz 7022: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 7023: border-right: 8px solid #FFFF77;
1.707 bisitz 7024: }
1.795 www 7025:
1.707 bisitz 7026: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 7027: border-right: 8px solid #FFAA77;
1.707 bisitz 7028: }
1.795 www 7029:
1.707 bisitz 7030: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 7031: border-right: 8px solid #FF7777;
1.707 bisitz 7032: }
1.795 www 7033:
1.707 bisitz 7034: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 7035: border-right: 8px solid #AAFF77;
1.707 bisitz 7036: }
1.795 www 7037:
1.707 bisitz 7038: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 7039: border-right: 8px solid #11CC55;
1.707 bisitz 7040: }
7041:
1.388 albertel 7042: span.LC_current_location {
1.701 harmsja 7043: font-size:larger;
1.388 albertel 7044: background: $pgbg;
7045: }
1.387 albertel 7046:
1.1029 www 7047: span.LC_current_nav_location {
7048: font-weight:bold;
7049: background: $sidebg;
7050: }
7051:
1.395 albertel 7052: span.LC_parm_menu_item {
7053: font-size: larger;
7054: }
1.795 www 7055:
1.395 albertel 7056: span.LC_parm_scope_all {
7057: color: red;
7058: }
1.795 www 7059:
1.395 albertel 7060: span.LC_parm_scope_folder {
7061: color: green;
7062: }
1.795 www 7063:
1.395 albertel 7064: span.LC_parm_scope_resource {
7065: color: orange;
7066: }
1.795 www 7067:
1.395 albertel 7068: span.LC_parm_part {
7069: color: blue;
7070: }
1.795 www 7071:
1.911 bisitz 7072: span.LC_parm_folder,
7073: span.LC_parm_symb {
1.395 albertel 7074: font-size: x-small;
7075: font-family: $mono;
7076: color: #AAAAAA;
7077: }
7078:
1.977 bisitz 7079: ul.LC_parm_parmlist li {
7080: display: inline-block;
7081: padding: 0.3em 0.8em;
7082: vertical-align: top;
7083: width: 150px;
7084: border-top:1px solid $lg_border_color;
7085: }
7086:
1.795 www 7087: td.LC_parm_overview_level_menu,
7088: td.LC_parm_overview_map_menu,
7089: td.LC_parm_overview_parm_selectors,
7090: td.LC_parm_overview_restrictions {
1.396 albertel 7091: border: 1px solid black;
7092: border-collapse: collapse;
7093: }
1.795 www 7094:
1.1285 raeburn 7095: span.LC_parm_recursive,
7096: td.LC_parm_recursive {
7097: font-weight: bold;
7098: font-size: smaller;
7099: }
7100:
1.396 albertel 7101: table.LC_parm_overview_restrictions td {
7102: border-width: 1px 4px 1px 4px;
7103: border-style: solid;
7104: border-color: $pgbg;
7105: text-align: center;
7106: }
1.795 www 7107:
1.396 albertel 7108: table.LC_parm_overview_restrictions th {
7109: background: $tabbg;
7110: border-width: 1px 4px 1px 4px;
7111: border-style: solid;
7112: border-color: $pgbg;
7113: }
1.795 www 7114:
1.398 albertel 7115: table#LC_helpmenu {
1.803 bisitz 7116: border: none;
1.398 albertel 7117: height: 55px;
1.803 bisitz 7118: border-spacing: 0;
1.398 albertel 7119: }
7120:
7121: table#LC_helpmenu fieldset legend {
7122: font-size: larger;
7123: }
1.795 www 7124:
1.397 albertel 7125: table#LC_helpmenu_links {
7126: width: 100%;
7127: border: 1px solid black;
7128: background: $pgbg;
1.803 bisitz 7129: padding: 0;
1.397 albertel 7130: border-spacing: 1px;
7131: }
1.795 www 7132:
1.397 albertel 7133: table#LC_helpmenu_links tr td {
7134: padding: 1px;
7135: background: $tabbg;
1.399 albertel 7136: text-align: center;
7137: font-weight: bold;
1.397 albertel 7138: }
1.396 albertel 7139:
1.795 www 7140: table#LC_helpmenu_links a:link,
7141: table#LC_helpmenu_links a:visited,
1.397 albertel 7142: table#LC_helpmenu_links a:active {
7143: text-decoration: none;
7144: color: $font;
7145: }
1.795 www 7146:
1.397 albertel 7147: table#LC_helpmenu_links a:hover {
7148: text-decoration: underline;
7149: color: $vlink;
7150: }
1.396 albertel 7151:
1.417 albertel 7152: .LC_chrt_popup_exists {
7153: border: 1px solid #339933;
7154: margin: -1px;
7155: }
1.795 www 7156:
1.417 albertel 7157: .LC_chrt_popup_up {
7158: border: 1px solid yellow;
7159: margin: -1px;
7160: }
1.795 www 7161:
1.417 albertel 7162: .LC_chrt_popup {
7163: border: 1px solid #8888FF;
7164: background: #CCCCFF;
7165: }
1.795 www 7166:
1.421 albertel 7167: table.LC_pick_box {
7168: border-collapse: separate;
7169: background: white;
7170: border: 1px solid black;
7171: border-spacing: 1px;
7172: }
1.795 www 7173:
1.421 albertel 7174: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 7175: background: $sidebg;
1.421 albertel 7176: font-weight: bold;
1.900 bisitz 7177: text-align: left;
1.740 bisitz 7178: vertical-align: top;
1.421 albertel 7179: width: 184px;
7180: padding: 8px;
7181: }
1.795 www 7182:
1.579 raeburn 7183: table.LC_pick_box td.LC_pick_box_value {
7184: text-align: left;
7185: padding: 8px;
7186: }
1.795 www 7187:
1.579 raeburn 7188: table.LC_pick_box td.LC_pick_box_select {
7189: text-align: left;
7190: padding: 8px;
7191: }
1.795 www 7192:
1.424 albertel 7193: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7194: padding: 0;
1.421 albertel 7195: height: 1px;
7196: background: black;
7197: }
1.795 www 7198:
1.421 albertel 7199: table.LC_pick_box td.LC_pick_box_submit {
7200: text-align: right;
7201: }
1.795 www 7202:
1.579 raeburn 7203: table.LC_pick_box td.LC_evenrow_value {
7204: text-align: left;
7205: padding: 8px;
7206: background-color: $data_table_light;
7207: }
1.795 www 7208:
1.579 raeburn 7209: table.LC_pick_box td.LC_oddrow_value {
7210: text-align: left;
7211: padding: 8px;
7212: background-color: $data_table_light;
7213: }
1.795 www 7214:
1.579 raeburn 7215: span.LC_helpform_receipt_cat {
7216: font-weight: bold;
7217: }
1.795 www 7218:
1.424 albertel 7219: table.LC_group_priv_box {
7220: background: white;
7221: border: 1px solid black;
7222: border-spacing: 1px;
7223: }
1.795 www 7224:
1.424 albertel 7225: table.LC_group_priv_box td.LC_pick_box_title {
7226: background: $tabbg;
7227: font-weight: bold;
7228: text-align: right;
7229: width: 184px;
7230: }
1.795 www 7231:
1.424 albertel 7232: table.LC_group_priv_box td.LC_groups_fixed {
7233: background: $data_table_light;
7234: text-align: center;
7235: }
1.795 www 7236:
1.424 albertel 7237: table.LC_group_priv_box td.LC_groups_optional {
7238: background: $data_table_dark;
7239: text-align: center;
7240: }
1.795 www 7241:
1.424 albertel 7242: table.LC_group_priv_box td.LC_groups_functionality {
7243: background: $data_table_darker;
7244: text-align: center;
7245: font-weight: bold;
7246: }
1.795 www 7247:
1.424 albertel 7248: table.LC_group_priv td {
7249: text-align: left;
1.803 bisitz 7250: padding: 0;
1.424 albertel 7251: }
7252:
7253: .LC_navbuttons {
7254: margin: 2ex 0ex 2ex 0ex;
7255: }
1.795 www 7256:
1.423 albertel 7257: .LC_topic_bar {
7258: font-weight: bold;
7259: background: $tabbg;
1.918 wenzelju 7260: margin: 1em 0em 1em 2em;
1.805 bisitz 7261: padding: 3px;
1.918 wenzelju 7262: font-size: 1.2em;
1.423 albertel 7263: }
1.795 www 7264:
1.423 albertel 7265: .LC_topic_bar span {
1.918 wenzelju 7266: left: 0.5em;
7267: position: absolute;
1.423 albertel 7268: vertical-align: middle;
1.918 wenzelju 7269: font-size: 1.2em;
1.423 albertel 7270: }
1.795 www 7271:
1.423 albertel 7272: table.LC_course_group_status {
7273: margin: 20px;
7274: }
1.795 www 7275:
1.423 albertel 7276: table.LC_status_selector td {
7277: vertical-align: top;
7278: text-align: center;
1.424 albertel 7279: padding: 4px;
7280: }
1.795 www 7281:
1.599 albertel 7282: div.LC_feedback_link {
1.616 albertel 7283: clear: both;
1.829 kalberla 7284: background: $sidebg;
1.779 bisitz 7285: width: 100%;
1.829 kalberla 7286: padding-bottom: 10px;
7287: border: 1px $tabbg solid;
1.833 kalberla 7288: height: 22px;
7289: line-height: 22px;
7290: padding-top: 5px;
7291: }
7292:
7293: div.LC_feedback_link img {
7294: height: 22px;
1.867 kalberla 7295: vertical-align:middle;
1.829 kalberla 7296: }
7297:
1.911 bisitz 7298: div.LC_feedback_link a {
1.829 kalberla 7299: text-decoration: none;
1.489 raeburn 7300: }
1.795 www 7301:
1.867 kalberla 7302: div.LC_comblock {
1.911 bisitz 7303: display:inline;
1.867 kalberla 7304: color:$font;
7305: font-size:90%;
7306: }
7307:
7308: div.LC_feedback_link div.LC_comblock {
7309: padding-left:5px;
7310: }
7311:
7312: div.LC_feedback_link div.LC_comblock a {
7313: color:$font;
7314: }
7315:
1.489 raeburn 7316: span.LC_feedback_link {
1.858 bisitz 7317: /* background: $feedback_link_bg; */
1.599 albertel 7318: font-size: larger;
7319: }
1.795 www 7320:
1.599 albertel 7321: span.LC_message_link {
1.858 bisitz 7322: /* background: $feedback_link_bg; */
1.599 albertel 7323: font-size: larger;
7324: position: absolute;
7325: right: 1em;
1.489 raeburn 7326: }
1.421 albertel 7327:
1.515 albertel 7328: table.LC_prior_tries {
1.524 albertel 7329: border: 1px solid #000000;
7330: border-collapse: separate;
7331: border-spacing: 1px;
1.515 albertel 7332: }
1.523 albertel 7333:
1.515 albertel 7334: table.LC_prior_tries td {
1.524 albertel 7335: padding: 2px;
1.515 albertel 7336: }
1.523 albertel 7337:
7338: .LC_answer_correct {
1.795 www 7339: background: lightgreen;
7340: color: darkgreen;
7341: padding: 6px;
1.523 albertel 7342: }
1.795 www 7343:
1.523 albertel 7344: .LC_answer_charged_try {
1.797 www 7345: background: #FFAAAA;
1.795 www 7346: color: darkred;
7347: padding: 6px;
1.523 albertel 7348: }
1.795 www 7349:
1.779 bisitz 7350: .LC_answer_not_charged_try,
1.523 albertel 7351: .LC_answer_no_grade,
7352: .LC_answer_late {
1.795 www 7353: background: lightyellow;
1.523 albertel 7354: color: black;
1.795 www 7355: padding: 6px;
1.523 albertel 7356: }
1.795 www 7357:
1.523 albertel 7358: .LC_answer_previous {
1.795 www 7359: background: lightblue;
7360: color: darkblue;
7361: padding: 6px;
1.523 albertel 7362: }
1.795 www 7363:
1.779 bisitz 7364: .LC_answer_no_message {
1.777 tempelho 7365: background: #FFFFFF;
7366: color: black;
1.795 www 7367: padding: 6px;
1.779 bisitz 7368: }
1.795 www 7369:
1.1334 raeburn 7370: .LC_answer_unknown,
7371: .LC_answer_warning {
1.779 bisitz 7372: background: orange;
7373: color: black;
1.795 www 7374: padding: 6px;
1.777 tempelho 7375: }
1.795 www 7376:
1.529 albertel 7377: span.LC_prior_numerical,
7378: span.LC_prior_string,
7379: span.LC_prior_custom,
7380: span.LC_prior_reaction,
7381: span.LC_prior_math {
1.925 bisitz 7382: font-family: $mono;
1.523 albertel 7383: white-space: pre;
7384: }
7385:
1.525 albertel 7386: span.LC_prior_string {
1.925 bisitz 7387: font-family: $mono;
1.525 albertel 7388: white-space: pre;
7389: }
7390:
1.523 albertel 7391: table.LC_prior_option {
7392: width: 100%;
7393: border-collapse: collapse;
7394: }
1.795 www 7395:
1.911 bisitz 7396: table.LC_prior_rank,
1.795 www 7397: table.LC_prior_match {
1.528 albertel 7398: border-collapse: collapse;
7399: }
1.795 www 7400:
1.528 albertel 7401: table.LC_prior_option tr td,
7402: table.LC_prior_rank tr td,
7403: table.LC_prior_match tr td {
1.524 albertel 7404: border: 1px solid #000000;
1.515 albertel 7405: }
7406:
1.855 bisitz 7407: .LC_nobreak {
1.544 albertel 7408: white-space: nowrap;
1.519 raeburn 7409: }
7410:
1.576 raeburn 7411: span.LC_cusr_emph {
7412: font-style: italic;
7413: }
7414:
1.633 raeburn 7415: span.LC_cusr_subheading {
7416: font-weight: normal;
7417: font-size: 85%;
7418: }
7419:
1.861 bisitz 7420: div.LC_docs_entry_move {
1.859 bisitz 7421: border: 1px solid #BBBBBB;
1.545 albertel 7422: background: #DDDDDD;
1.861 bisitz 7423: width: 22px;
1.859 bisitz 7424: padding: 1px;
7425: margin: 0;
1.545 albertel 7426: }
7427:
1.861 bisitz 7428: table.LC_data_table tr > td.LC_docs_entry_commands,
7429: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7430: font-size: x-small;
7431: }
1.795 www 7432:
1.861 bisitz 7433: .LC_docs_entry_parameter {
7434: white-space: nowrap;
7435: }
7436:
1.544 albertel 7437: .LC_docs_copy {
1.545 albertel 7438: color: #000099;
1.544 albertel 7439: }
1.795 www 7440:
1.544 albertel 7441: .LC_docs_cut {
1.545 albertel 7442: color: #550044;
1.544 albertel 7443: }
1.795 www 7444:
1.544 albertel 7445: .LC_docs_rename {
1.545 albertel 7446: color: #009900;
1.544 albertel 7447: }
1.795 www 7448:
1.544 albertel 7449: .LC_docs_remove {
1.545 albertel 7450: color: #990000;
7451: }
7452:
1.1284 raeburn 7453: .LC_docs_alias {
7454: color: #440055;
7455: }
7456:
1.1286 raeburn 7457: .LC_domprefs_email,
1.1284 raeburn 7458: .LC_docs_alias_name,
1.547 albertel 7459: .LC_docs_reinit_warn,
7460: .LC_docs_ext_edit {
7461: font-size: x-small;
7462: }
7463:
1.545 albertel 7464: table.LC_docs_adddocs td,
7465: table.LC_docs_adddocs th {
7466: border: 1px solid #BBBBBB;
7467: padding: 4px;
7468: background: #DDDDDD;
1.543 albertel 7469: }
7470:
1.584 albertel 7471: table.LC_sty_begin {
7472: background: #BBFFBB;
7473: }
1.795 www 7474:
1.584 albertel 7475: table.LC_sty_end {
7476: background: #FFBBBB;
7477: }
7478:
1.589 raeburn 7479: table.LC_double_column {
1.803 bisitz 7480: border-width: 0;
1.589 raeburn 7481: border-collapse: collapse;
7482: width: 100%;
7483: padding: 2px;
7484: }
7485:
7486: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7487: top: 2px;
1.589 raeburn 7488: left: 2px;
7489: width: 47%;
7490: vertical-align: top;
7491: }
7492:
7493: table.LC_double_column tr td.LC_right_col {
7494: top: 2px;
1.779 bisitz 7495: right: 2px;
1.589 raeburn 7496: width: 47%;
7497: vertical-align: top;
7498: }
7499:
1.591 raeburn 7500: div.LC_left_float {
7501: float: left;
7502: padding-right: 5%;
1.597 albertel 7503: padding-bottom: 4px;
1.591 raeburn 7504: }
7505:
7506: div.LC_clear_float_header {
1.597 albertel 7507: padding-bottom: 2px;
1.591 raeburn 7508: }
7509:
7510: div.LC_clear_float_footer {
1.597 albertel 7511: padding-top: 10px;
1.591 raeburn 7512: clear: both;
7513: }
7514:
1.597 albertel 7515: div.LC_grade_show_user {
1.941 bisitz 7516: /* border-left: 5px solid $sidebg; */
7517: border-top: 5px solid #000000;
7518: margin: 50px 0 0 0;
1.936 bisitz 7519: padding: 15px 0 5px 10px;
1.597 albertel 7520: }
1.795 www 7521:
1.936 bisitz 7522: div.LC_grade_show_user_odd_row {
1.941 bisitz 7523: /* border-left: 5px solid #000000; */
7524: }
7525:
7526: div.LC_grade_show_user div.LC_Box {
7527: margin-right: 50px;
1.597 albertel 7528: }
7529:
7530: div.LC_grade_submissions,
7531: div.LC_grade_message_center,
1.936 bisitz 7532: div.LC_grade_info_links {
1.597 albertel 7533: margin: 5px;
7534: width: 99%;
7535: background: #FFFFFF;
7536: }
1.795 www 7537:
1.597 albertel 7538: div.LC_grade_submissions_header,
1.936 bisitz 7539: div.LC_grade_message_center_header {
1.705 tempelho 7540: font-weight: bold;
7541: font-size: large;
1.597 albertel 7542: }
1.795 www 7543:
1.597 albertel 7544: div.LC_grade_submissions_body,
1.936 bisitz 7545: div.LC_grade_message_center_body {
1.597 albertel 7546: border: 1px solid black;
7547: width: 99%;
7548: background: #FFFFFF;
7549: }
1.795 www 7550:
1.613 albertel 7551: table.LC_scantron_action {
7552: width: 100%;
7553: }
1.795 www 7554:
1.613 albertel 7555: table.LC_scantron_action tr th {
1.698 harmsja 7556: font-weight:bold;
7557: font-style:normal;
1.613 albertel 7558: }
1.795 www 7559:
1.779 bisitz 7560: .LC_edit_problem_header,
1.614 albertel 7561: div.LC_edit_problem_footer {
1.705 tempelho 7562: font-weight: normal;
7563: font-size: medium;
1.602 albertel 7564: margin: 2px;
1.1060 bisitz 7565: background-color: $sidebg;
1.600 albertel 7566: }
1.795 www 7567:
1.600 albertel 7568: div.LC_edit_problem_header,
1.602 albertel 7569: div.LC_edit_problem_header div,
1.614 albertel 7570: div.LC_edit_problem_footer,
7571: div.LC_edit_problem_footer div,
1.602 albertel 7572: div.LC_edit_problem_editxml_header,
7573: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7574: z-index: 100;
1.600 albertel 7575: }
1.795 www 7576:
1.600 albertel 7577: div.LC_edit_problem_header_title {
1.705 tempelho 7578: font-weight: bold;
7579: font-size: larger;
1.602 albertel 7580: background: $tabbg;
7581: padding: 3px;
1.1060 bisitz 7582: margin: 0 0 5px 0;
1.602 albertel 7583: }
1.795 www 7584:
1.602 albertel 7585: table.LC_edit_problem_header_title {
7586: width: 100%;
1.600 albertel 7587: background: $tabbg;
1.602 albertel 7588: }
7589:
1.1205 golterma 7590: div.LC_edit_actionbar {
7591: background-color: $sidebg;
1.1218 droeschl 7592: margin: 0;
7593: padding: 0;
7594: line-height: 200%;
1.602 albertel 7595: }
1.795 www 7596:
1.1218 droeschl 7597: div.LC_edit_actionbar div{
7598: padding: 0;
7599: margin: 0;
7600: display: inline-block;
1.600 albertel 7601: }
1.795 www 7602:
1.1124 bisitz 7603: .LC_edit_opt {
7604: padding-left: 1em;
7605: white-space: nowrap;
7606: }
7607:
1.1152 golterma 7608: .LC_edit_problem_latexhelper{
7609: text-align: right;
7610: }
7611:
7612: #LC_edit_problem_colorful div{
7613: margin-left: 40px;
7614: }
7615:
1.1205 golterma 7616: #LC_edit_problem_codemirror div{
7617: margin-left: 0px;
7618: }
7619:
1.911 bisitz 7620: img.stift {
1.803 bisitz 7621: border-width: 0;
7622: vertical-align: middle;
1.677 riegler 7623: }
1.680 riegler 7624:
1.923 bisitz 7625: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7626: vertical-align: top;
1.777 tempelho 7627: }
1.795 www 7628:
1.716 raeburn 7629: div.LC_createcourse {
1.911 bisitz 7630: margin: 10px 10px 10px 10px;
1.716 raeburn 7631: }
7632:
1.917 raeburn 7633: .LC_dccid {
1.1130 raeburn 7634: float: right;
1.917 raeburn 7635: margin: 0.2em 0 0 0;
7636: padding: 0;
7637: font-size: 90%;
7638: display:none;
7639: }
7640:
1.897 wenzelju 7641: ol.LC_primary_menu a:hover,
1.721 harmsja 7642: ol#LC_MenuBreadcrumbs a:hover,
7643: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7644: ul#LC_secondary_menu a:hover,
1.721 harmsja 7645: .LC_FormSectionClearButton input:hover
1.795 www 7646: ul.LC_TabContent li:hover a {
1.952 onken 7647: color:$button_hover;
1.911 bisitz 7648: text-decoration:none;
1.693 droeschl 7649: }
7650:
1.779 bisitz 7651: h1 {
1.911 bisitz 7652: padding: 0;
7653: line-height:130%;
1.693 droeschl 7654: }
1.698 harmsja 7655:
1.911 bisitz 7656: h2,
7657: h3,
7658: h4,
7659: h5,
7660: h6 {
7661: margin: 5px 0 5px 0;
7662: padding: 0;
7663: line-height:130%;
1.693 droeschl 7664: }
1.795 www 7665:
7666: .LC_hcell {
1.911 bisitz 7667: padding:3px 15px 3px 15px;
7668: margin: 0;
7669: background-color:$tabbg;
7670: color:$fontmenu;
7671: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7672: }
1.795 www 7673:
1.840 bisitz 7674: .LC_Box > .LC_hcell {
1.911 bisitz 7675: margin: 0 -10px 10px -10px;
1.835 bisitz 7676: }
7677:
1.721 harmsja 7678: .LC_noBorder {
1.911 bisitz 7679: border: 0;
1.698 harmsja 7680: }
1.693 droeschl 7681:
1.721 harmsja 7682: .LC_FormSectionClearButton input {
1.911 bisitz 7683: background-color:transparent;
7684: border: none;
7685: cursor:pointer;
7686: text-decoration:underline;
1.693 droeschl 7687: }
1.763 bisitz 7688:
7689: .LC_help_open_topic {
1.911 bisitz 7690: color: #FFFFFF;
7691: background-color: #EEEEFF;
7692: margin: 1px;
7693: padding: 4px;
7694: border: 1px solid #000033;
7695: white-space: nowrap;
7696: /* vertical-align: middle; */
1.759 neumanie 7697: }
1.693 droeschl 7698:
1.911 bisitz 7699: dl,
7700: ul,
7701: div,
7702: fieldset {
7703: margin: 10px 10px 10px 0;
7704: /* overflow: hidden; */
1.693 droeschl 7705: }
1.795 www 7706:
1.1211 raeburn 7707: article.geogebraweb div {
7708: margin: 0;
7709: }
7710:
1.838 bisitz 7711: fieldset > legend {
1.911 bisitz 7712: font-weight: bold;
7713: padding: 0 5px 0 5px;
1.838 bisitz 7714: }
7715:
1.813 bisitz 7716: #LC_nav_bar {
1.911 bisitz 7717: float: left;
1.995 raeburn 7718: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7719: margin: 0 0 2px 0;
1.807 droeschl 7720: }
7721:
1.916 droeschl 7722: #LC_realm {
7723: margin: 0.2em 0 0 0;
7724: padding: 0;
7725: font-weight: bold;
7726: text-align: center;
1.995 raeburn 7727: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7728: }
7729:
1.911 bisitz 7730: #LC_nav_bar em {
7731: font-weight: bold;
7732: font-style: normal;
1.807 droeschl 7733: }
7734:
1.897 wenzelju 7735: ol.LC_primary_menu {
1.934 droeschl 7736: margin: 0;
1.1076 raeburn 7737: padding: 0;
1.807 droeschl 7738: }
7739:
1.852 droeschl 7740: ol#LC_PathBreadcrumbs {
1.911 bisitz 7741: margin: 0;
1.693 droeschl 7742: }
7743:
1.897 wenzelju 7744: ol.LC_primary_menu li {
1.1076 raeburn 7745: color: RGB(80, 80, 80);
7746: vertical-align: middle;
7747: text-align: left;
7748: list-style: none;
1.1205 golterma 7749: position: relative;
1.1076 raeburn 7750: float: left;
1.1205 golterma 7751: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7752: line-height: 1.5em;
1.1076 raeburn 7753: }
7754:
1.1205 golterma 7755: ol.LC_primary_menu li a,
7756: ol.LC_primary_menu li p {
1.1076 raeburn 7757: display: block;
7758: margin: 0;
7759: padding: 0 5px 0 10px;
7760: text-decoration: none;
7761: }
7762:
1.1205 golterma 7763: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7764: display: inline-block;
7765: width: 95%;
7766: text-align: left;
7767: }
7768:
7769: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7770: display: inline-block;
7771: width: 5%;
7772: float: right;
7773: text-align: right;
7774: font-size: 70%;
7775: }
7776:
7777: ol.LC_primary_menu ul {
1.1076 raeburn 7778: display: none;
1.1205 golterma 7779: width: 15em;
1.1076 raeburn 7780: background-color: $data_table_light;
1.1205 golterma 7781: position: absolute;
7782: top: 100%;
1.1076 raeburn 7783: }
7784:
1.1205 golterma 7785: ol.LC_primary_menu ul ul {
7786: left: 100%;
7787: top: 0;
7788: }
7789:
7790: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7791: display: block;
7792: position: absolute;
7793: margin: 0;
7794: padding: 0;
1.1078 raeburn 7795: z-index: 2;
1.1076 raeburn 7796: }
7797:
7798: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7799: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7800: font-size: 90%;
1.911 bisitz 7801: vertical-align: top;
1.1076 raeburn 7802: float: none;
1.1079 raeburn 7803: border-left: 1px solid black;
7804: border-right: 1px solid black;
1.1205 golterma 7805: /* A dark bottom border to visualize different menu options;
7806: overwritten in the create_submenu routine for the last border-bottom of the menu */
7807: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7808: }
7809:
1.1205 golterma 7810: ol.LC_primary_menu li li p:hover {
7811: color:$button_hover;
7812: text-decoration:none;
7813: background-color:$data_table_dark;
1.1076 raeburn 7814: }
7815:
7816: ol.LC_primary_menu li li a:hover {
7817: color:$button_hover;
7818: background-color:$data_table_dark;
1.693 droeschl 7819: }
7820:
1.1205 golterma 7821: /* Font-size equal to the size of the predecessors*/
7822: ol.LC_primary_menu li:hover li li {
7823: font-size: 100%;
7824: }
7825:
1.897 wenzelju 7826: ol.LC_primary_menu li img {
1.911 bisitz 7827: vertical-align: bottom;
1.934 droeschl 7828: height: 1.1em;
1.1077 raeburn 7829: margin: 0.2em 0 0 0;
1.693 droeschl 7830: }
7831:
1.897 wenzelju 7832: ol.LC_primary_menu a {
1.911 bisitz 7833: color: RGB(80, 80, 80);
7834: text-decoration: none;
1.693 droeschl 7835: }
1.795 www 7836:
1.949 droeschl 7837: ol.LC_primary_menu a.LC_new_message {
7838: font-weight:bold;
7839: color: darkred;
7840: }
7841:
1.975 raeburn 7842: ol.LC_docs_parameters {
7843: margin-left: 0;
7844: padding: 0;
7845: list-style: none;
7846: }
7847:
7848: ol.LC_docs_parameters li {
7849: margin: 0;
7850: padding-right: 20px;
7851: display: inline;
7852: }
7853:
1.976 raeburn 7854: ol.LC_docs_parameters li:before {
7855: content: "\\002022 \\0020";
7856: }
7857:
7858: li.LC_docs_parameters_title {
7859: font-weight: bold;
7860: }
7861:
7862: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7863: content: "";
7864: }
7865:
1.897 wenzelju 7866: ul#LC_secondary_menu {
1.1107 raeburn 7867: clear: right;
1.911 bisitz 7868: color: $fontmenu;
7869: background: $tabbg;
7870: list-style: none;
7871: padding: 0;
7872: margin: 0;
7873: width: 100%;
1.995 raeburn 7874: text-align: left;
1.1107 raeburn 7875: float: left;
1.808 droeschl 7876: }
7877:
1.897 wenzelju 7878: ul#LC_secondary_menu li {
1.911 bisitz 7879: font-weight: bold;
7880: line-height: 1.8em;
1.1107 raeburn 7881: border-right: 1px solid black;
7882: float: left;
7883: }
7884:
7885: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7886: background-color: $data_table_light;
7887: }
7888:
7889: ul#LC_secondary_menu li a {
1.911 bisitz 7890: padding: 0 0.8em;
1.1107 raeburn 7891: }
7892:
7893: ul#LC_secondary_menu li ul {
7894: display: none;
7895: }
7896:
7897: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7898: display: block;
7899: position: absolute;
7900: margin: 0;
7901: padding: 0;
7902: list-style:none;
7903: float: none;
7904: background-color: $data_table_light;
7905: z-index: 2;
7906: margin-left: -1px;
7907: }
7908:
7909: ul#LC_secondary_menu li ul li {
7910: font-size: 90%;
7911: vertical-align: top;
7912: border-left: 1px solid black;
1.911 bisitz 7913: border-right: 1px solid black;
1.1119 raeburn 7914: background-color: $data_table_light;
1.1107 raeburn 7915: list-style:none;
7916: float: none;
7917: }
7918:
7919: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7920: background-color: $data_table_dark;
1.807 droeschl 7921: }
7922:
1.847 tempelho 7923: ul.LC_TabContent {
1.911 bisitz 7924: display:block;
7925: background: $sidebg;
7926: border-bottom: solid 1px $lg_border_color;
7927: list-style:none;
1.1020 raeburn 7928: margin: -1px -10px 0 -10px;
1.911 bisitz 7929: padding: 0;
1.693 droeschl 7930: }
7931:
1.795 www 7932: ul.LC_TabContent li,
7933: ul.LC_TabContentBigger li {
1.911 bisitz 7934: float:left;
1.741 harmsja 7935: }
1.795 www 7936:
1.897 wenzelju 7937: ul#LC_secondary_menu li a {
1.911 bisitz 7938: color: $fontmenu;
7939: text-decoration: none;
1.693 droeschl 7940: }
1.795 www 7941:
1.721 harmsja 7942: ul.LC_TabContent {
1.952 onken 7943: min-height:20px;
1.721 harmsja 7944: }
1.795 www 7945:
7946: ul.LC_TabContent li {
1.911 bisitz 7947: vertical-align:middle;
1.959 onken 7948: padding: 0 16px 0 10px;
1.911 bisitz 7949: background-color:$tabbg;
7950: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7951: border-left: solid 1px $font;
1.721 harmsja 7952: }
1.795 www 7953:
1.847 tempelho 7954: ul.LC_TabContent .right {
1.911 bisitz 7955: float:right;
1.847 tempelho 7956: }
7957:
1.911 bisitz 7958: ul.LC_TabContent li a,
7959: ul.LC_TabContent li {
7960: color:rgb(47,47,47);
7961: text-decoration:none;
7962: font-size:95%;
7963: font-weight:bold;
1.952 onken 7964: min-height:20px;
7965: }
7966:
1.959 onken 7967: ul.LC_TabContent li a:hover,
7968: ul.LC_TabContent li a:focus {
1.952 onken 7969: color: $button_hover;
1.959 onken 7970: background:none;
7971: outline:none;
1.952 onken 7972: }
7973:
7974: ul.LC_TabContent li:hover {
7975: color: $button_hover;
7976: cursor:pointer;
1.721 harmsja 7977: }
1.795 www 7978:
1.911 bisitz 7979: ul.LC_TabContent li.active {
1.952 onken 7980: color: $font;
1.911 bisitz 7981: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7982: border-bottom:solid 1px #FFFFFF;
7983: cursor: default;
1.744 ehlerst 7984: }
1.795 www 7985:
1.959 onken 7986: ul.LC_TabContent li.active a {
7987: color:$font;
7988: background:#FFFFFF;
7989: outline: none;
7990: }
1.1047 raeburn 7991:
7992: ul.LC_TabContent li.goback {
7993: float: left;
7994: border-left: none;
7995: }
7996:
1.870 tempelho 7997: #maincoursedoc {
1.911 bisitz 7998: clear:both;
1.870 tempelho 7999: }
8000:
8001: ul.LC_TabContentBigger {
1.911 bisitz 8002: display:block;
8003: list-style:none;
8004: padding: 0;
1.870 tempelho 8005: }
8006:
1.795 www 8007: ul.LC_TabContentBigger li {
1.911 bisitz 8008: vertical-align:bottom;
8009: height: 30px;
8010: font-size:110%;
8011: font-weight:bold;
8012: color: #737373;
1.841 tempelho 8013: }
8014:
1.957 onken 8015: ul.LC_TabContentBigger li.active {
8016: position: relative;
8017: top: 1px;
8018: }
8019:
1.870 tempelho 8020: ul.LC_TabContentBigger li a {
1.911 bisitz 8021: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
8022: height: 30px;
8023: line-height: 30px;
8024: text-align: center;
8025: display: block;
8026: text-decoration: none;
1.958 onken 8027: outline: none;
1.741 harmsja 8028: }
1.795 www 8029:
1.870 tempelho 8030: ul.LC_TabContentBigger li.active a {
1.911 bisitz 8031: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
8032: color:$font;
1.744 ehlerst 8033: }
1.795 www 8034:
1.870 tempelho 8035: ul.LC_TabContentBigger li b {
1.911 bisitz 8036: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
8037: display: block;
8038: float: left;
8039: padding: 0 30px;
1.957 onken 8040: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 8041: }
8042:
1.956 onken 8043: ul.LC_TabContentBigger li:hover b {
8044: color:$button_hover;
8045: }
8046:
1.870 tempelho 8047: ul.LC_TabContentBigger li.active b {
1.911 bisitz 8048: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
8049: color:$font;
1.957 onken 8050: border: 0;
1.741 harmsja 8051: }
1.693 droeschl 8052:
1.870 tempelho 8053:
1.862 bisitz 8054: ul.LC_CourseBreadcrumbs {
8055: background: $sidebg;
1.1020 raeburn 8056: height: 2em;
1.862 bisitz 8057: padding-left: 10px;
1.1020 raeburn 8058: margin: 0;
1.862 bisitz 8059: list-style-position: inside;
8060: }
8061:
1.911 bisitz 8062: ol#LC_MenuBreadcrumbs,
1.862 bisitz 8063: ol#LC_PathBreadcrumbs {
1.911 bisitz 8064: padding-left: 10px;
8065: margin: 0;
1.933 droeschl 8066: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 8067: }
8068:
1.911 bisitz 8069: ol#LC_MenuBreadcrumbs li,
8070: ol#LC_PathBreadcrumbs li,
1.862 bisitz 8071: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 8072: display: inline;
1.933 droeschl 8073: white-space: normal;
1.693 droeschl 8074: }
8075:
1.823 bisitz 8076: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 8077: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 8078: text-decoration: none;
8079: font-size:90%;
1.693 droeschl 8080: }
1.795 www 8081:
1.969 droeschl 8082: ol#LC_MenuBreadcrumbs h1 {
8083: display: inline;
8084: font-size: 90%;
8085: line-height: 2.5em;
8086: margin: 0;
8087: padding: 0;
8088: }
8089:
1.795 www 8090: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 8091: text-decoration:none;
8092: font-size:100%;
8093: font-weight:bold;
1.693 droeschl 8094: }
1.795 www 8095:
1.840 bisitz 8096: .LC_Box {
1.911 bisitz 8097: border: solid 1px $lg_border_color;
8098: padding: 0 10px 10px 10px;
1.746 neumanie 8099: }
1.795 www 8100:
1.1020 raeburn 8101: .LC_DocsBox {
8102: border: solid 1px $lg_border_color;
8103: padding: 0 0 10px 10px;
8104: }
8105:
1.795 www 8106: .LC_AboutMe_Image {
1.911 bisitz 8107: float:left;
8108: margin-right:10px;
1.747 neumanie 8109: }
1.795 www 8110:
8111: .LC_Clear_AboutMe_Image {
1.911 bisitz 8112: clear:left;
1.747 neumanie 8113: }
1.795 www 8114:
1.721 harmsja 8115: dl.LC_ListStyleClean dt {
1.911 bisitz 8116: padding-right: 5px;
8117: display: table-header-group;
1.693 droeschl 8118: }
8119:
1.721 harmsja 8120: dl.LC_ListStyleClean dd {
1.911 bisitz 8121: display: table-row;
1.693 droeschl 8122: }
8123:
1.721 harmsja 8124: .LC_ListStyleClean,
8125: .LC_ListStyleSimple,
8126: .LC_ListStyleNormal,
1.795 www 8127: .LC_ListStyleSpecial {
1.911 bisitz 8128: /* display:block; */
8129: list-style-position: inside;
8130: list-style-type: none;
8131: overflow: hidden;
8132: padding: 0;
1.693 droeschl 8133: }
8134:
1.721 harmsja 8135: .LC_ListStyleSimple li,
8136: .LC_ListStyleSimple dd,
8137: .LC_ListStyleNormal li,
8138: .LC_ListStyleNormal dd,
8139: .LC_ListStyleSpecial li,
1.795 www 8140: .LC_ListStyleSpecial dd {
1.911 bisitz 8141: margin: 0;
8142: padding: 5px 5px 5px 10px;
8143: clear: both;
1.693 droeschl 8144: }
8145:
1.721 harmsja 8146: .LC_ListStyleClean li,
8147: .LC_ListStyleClean dd {
1.911 bisitz 8148: padding-top: 0;
8149: padding-bottom: 0;
1.693 droeschl 8150: }
8151:
1.721 harmsja 8152: .LC_ListStyleSimple dd,
1.795 www 8153: .LC_ListStyleSimple li {
1.911 bisitz 8154: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 8155: }
8156:
1.721 harmsja 8157: .LC_ListStyleSpecial li,
8158: .LC_ListStyleSpecial dd {
1.911 bisitz 8159: list-style-type: none;
8160: background-color: RGB(220, 220, 220);
8161: margin-bottom: 4px;
1.693 droeschl 8162: }
8163:
1.721 harmsja 8164: table.LC_SimpleTable {
1.911 bisitz 8165: margin:5px;
8166: border:solid 1px $lg_border_color;
1.795 www 8167: }
1.693 droeschl 8168:
1.721 harmsja 8169: table.LC_SimpleTable tr {
1.911 bisitz 8170: padding: 0;
8171: border:solid 1px $lg_border_color;
1.693 droeschl 8172: }
1.795 www 8173:
8174: table.LC_SimpleTable thead {
1.911 bisitz 8175: background:rgb(220,220,220);
1.693 droeschl 8176: }
8177:
1.721 harmsja 8178: div.LC_columnSection {
1.911 bisitz 8179: display: block;
8180: clear: both;
8181: overflow: hidden;
8182: margin: 0;
1.693 droeschl 8183: }
8184:
1.721 harmsja 8185: div.LC_columnSection>* {
1.911 bisitz 8186: float: left;
8187: margin: 10px 20px 10px 0;
8188: overflow:hidden;
1.693 droeschl 8189: }
1.721 harmsja 8190:
1.795 www 8191: table em {
1.911 bisitz 8192: font-weight: bold;
8193: font-style: normal;
1.748 schulted 8194: }
1.795 www 8195:
1.779 bisitz 8196: table.LC_tableBrowseRes,
1.795 www 8197: table.LC_tableOfContent {
1.911 bisitz 8198: border:none;
8199: border-spacing: 1px;
8200: padding: 3px;
8201: background-color: #FFFFFF;
8202: font-size: 90%;
1.753 droeschl 8203: }
1.789 droeschl 8204:
1.911 bisitz 8205: table.LC_tableOfContent {
8206: border-collapse: collapse;
1.789 droeschl 8207: }
8208:
1.771 droeschl 8209: table.LC_tableBrowseRes a,
1.768 schulted 8210: table.LC_tableOfContent a {
1.911 bisitz 8211: background-color: transparent;
8212: text-decoration: none;
1.753 droeschl 8213: }
8214:
1.795 www 8215: table.LC_tableOfContent img {
1.911 bisitz 8216: border: none;
8217: height: 1.3em;
8218: vertical-align: text-bottom;
8219: margin-right: 0.3em;
1.753 droeschl 8220: }
1.757 schulted 8221:
1.795 www 8222: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8223: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8224: }
8225:
1.795 www 8226: a#LC_content_toolbar_everything {
1.911 bisitz 8227: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8228: }
8229:
1.795 www 8230: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8231: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8232: }
8233:
1.795 www 8234: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8235: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8236: }
8237:
1.795 www 8238: a#LC_content_toolbar_changefolder {
1.911 bisitz 8239: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8240: }
8241:
1.795 www 8242: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8243: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8244: }
8245:
1.1043 raeburn 8246: a#LC_content_toolbar_edittoplevel {
8247: background-image:url(/res/adm/pages/edittoplevel.gif);
8248: }
8249:
1.795 www 8250: ul#LC_toolbar li a:hover {
1.911 bisitz 8251: background-position: bottom center;
1.757 schulted 8252: }
8253:
1.795 www 8254: ul#LC_toolbar {
1.911 bisitz 8255: padding: 0;
8256: margin: 2px;
8257: list-style:none;
8258: position:relative;
8259: background-color:white;
1.1082 raeburn 8260: overflow: auto;
1.757 schulted 8261: }
8262:
1.795 www 8263: ul#LC_toolbar li {
1.911 bisitz 8264: border:1px solid white;
8265: padding: 0;
8266: margin: 0;
8267: float: left;
8268: display:inline;
8269: vertical-align:middle;
1.1082 raeburn 8270: white-space: nowrap;
1.911 bisitz 8271: }
1.757 schulted 8272:
1.783 amueller 8273:
1.795 www 8274: a.LC_toolbarItem {
1.911 bisitz 8275: display:block;
8276: padding: 0;
8277: margin: 0;
8278: height: 32px;
8279: width: 32px;
8280: color:white;
8281: border: none;
8282: background-repeat:no-repeat;
8283: background-color:transparent;
1.757 schulted 8284: }
8285:
1.915 droeschl 8286: ul.LC_funclist {
8287: margin: 0;
8288: padding: 0.5em 1em 0.5em 0;
8289: }
8290:
1.933 droeschl 8291: ul.LC_funclist > li:first-child {
8292: font-weight:bold;
8293: margin-left:0.8em;
8294: }
8295:
1.915 droeschl 8296: ul.LC_funclist + ul.LC_funclist {
8297: /*
8298: left border as a seperator if we have more than
8299: one list
8300: */
8301: border-left: 1px solid $sidebg;
8302: /*
8303: this hides the left border behind the border of the
8304: outer box if element is wrapped to the next 'line'
8305: */
8306: margin-left: -1px;
8307: }
8308:
1.843 bisitz 8309: ul.LC_funclist li {
1.915 droeschl 8310: display: inline;
1.782 bisitz 8311: white-space: nowrap;
1.915 droeschl 8312: margin: 0 0 0 25px;
8313: line-height: 150%;
1.782 bisitz 8314: }
8315:
1.974 wenzelju 8316: .LC_hidden {
8317: display: none;
8318: }
8319:
1.1030 www 8320: .LCmodal-overlay {
8321: position:fixed;
8322: top:0;
8323: right:0;
8324: bottom:0;
8325: left:0;
8326: height:100%;
8327: width:100%;
8328: margin:0;
8329: padding:0;
8330: background:#999;
8331: opacity:.75;
8332: filter: alpha(opacity=75);
8333: -moz-opacity: 0.75;
8334: z-index:101;
8335: }
8336:
8337: * html .LCmodal-overlay {
8338: position: absolute;
8339: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8340: }
8341:
8342: .LCmodal-window {
8343: position:fixed;
8344: top:50%;
8345: left:50%;
8346: margin:0;
8347: padding:0;
8348: z-index:102;
8349: }
8350:
8351: * html .LCmodal-window {
8352: position:absolute;
8353: }
8354:
8355: .LCclose-window {
8356: position:absolute;
8357: width:32px;
8358: height:32px;
8359: right:8px;
8360: top:8px;
8361: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8362: text-indent:-99999px;
8363: overflow:hidden;
8364: cursor:pointer;
8365: }
8366:
1.1335 raeburn 8367: pre.LC_wordwrap {
8368: white-space: pre-wrap;
8369: white-space: -moz-pre-wrap;
8370: white-space: -pre-wrap;
8371: white-space: -o-pre-wrap;
8372: word-wrap: break-word;
8373: }
8374:
1.1100 raeburn 8375: /*
1.1231 damieng 8376: styles used for response display
8377: */
8378: div.LC_radiofoil, div.LC_rankfoil {
8379: margin: .5em 0em .5em 0em;
8380: }
8381: table.LC_itemgroup {
8382: margin-top: 1em;
8383: }
8384:
8385: /*
1.1100 raeburn 8386: styles used by TTH when "Default set of options to pass to tth/m
8387: when converting TeX" in course settings has been set
8388:
8389: option passed: -t
8390:
8391: */
8392:
8393: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8394: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8395: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8396: td div.norm {line-height:normal;}
8397:
8398: /*
8399: option passed -y3
8400: */
8401:
8402: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8403: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8404: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8405:
1.1230 damieng 8406: /*
8407: sections with roles, for content only
8408: */
8409: section[class^="role-"] {
8410: padding-left: 10px;
8411: padding-right: 5px;
8412: margin-top: 8px;
8413: margin-bottom: 8px;
8414: border: 1px solid #2A4;
8415: border-radius: 5px;
8416: box-shadow: 0px 1px 1px #BBB;
8417: }
8418: section[class^="role-"]>h1 {
8419: position: relative;
8420: margin: 0px;
8421: padding-top: 10px;
8422: padding-left: 40px;
8423: }
8424: section[class^="role-"]>h1:before {
8425: position: absolute;
8426: left: -5px;
8427: top: 5px;
8428: }
8429: section.role-activity>h1:before {
8430: content:url('/adm/daxe/images/section_icons/activity.png');
8431: }
8432: section.role-advice>h1:before {
8433: content:url('/adm/daxe/images/section_icons/advice.png');
8434: }
8435: section.role-bibliography>h1:before {
8436: content:url('/adm/daxe/images/section_icons/bibliography.png');
8437: }
8438: section.role-citation>h1:before {
8439: content:url('/adm/daxe/images/section_icons/citation.png');
8440: }
8441: section.role-conclusion>h1:before {
8442: content:url('/adm/daxe/images/section_icons/conclusion.png');
8443: }
8444: section.role-definition>h1:before {
8445: content:url('/adm/daxe/images/section_icons/definition.png');
8446: }
8447: section.role-demonstration>h1:before {
8448: content:url('/adm/daxe/images/section_icons/demonstration.png');
8449: }
8450: section.role-example>h1:before {
8451: content:url('/adm/daxe/images/section_icons/example.png');
8452: }
8453: section.role-explanation>h1:before {
8454: content:url('/adm/daxe/images/section_icons/explanation.png');
8455: }
8456: section.role-introduction>h1:before {
8457: content:url('/adm/daxe/images/section_icons/introduction.png');
8458: }
8459: section.role-method>h1:before {
8460: content:url('/adm/daxe/images/section_icons/method.png');
8461: }
8462: section.role-more_information>h1:before {
8463: content:url('/adm/daxe/images/section_icons/more_information.png');
8464: }
8465: section.role-objectives>h1:before {
8466: content:url('/adm/daxe/images/section_icons/objectives.png');
8467: }
8468: section.role-prerequisites>h1:before {
8469: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8470: }
8471: section.role-remark>h1:before {
8472: content:url('/adm/daxe/images/section_icons/remark.png');
8473: }
8474: section.role-reminder>h1:before {
8475: content:url('/adm/daxe/images/section_icons/reminder.png');
8476: }
8477: section.role-summary>h1:before {
8478: content:url('/adm/daxe/images/section_icons/summary.png');
8479: }
8480: section.role-syntax>h1:before {
8481: content:url('/adm/daxe/images/section_icons/syntax.png');
8482: }
8483: section.role-warning>h1:before {
8484: content:url('/adm/daxe/images/section_icons/warning.png');
8485: }
8486:
1.1269 raeburn 8487: #LC_minitab_header {
8488: float:left;
8489: width:100%;
8490: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8491: font-size:93%;
8492: line-height:normal;
8493: margin: 0.5em 0 0.5em 0;
8494: }
8495: #LC_minitab_header ul {
8496: margin:0;
8497: padding:10px 10px 0;
8498: list-style:none;
8499: }
8500: #LC_minitab_header li {
8501: float:left;
8502: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8503: margin:0;
8504: padding:0 0 0 9px;
8505: }
8506: #LC_minitab_header a {
8507: display:block;
8508: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8509: padding:5px 15px 4px 6px;
8510: }
8511: #LC_minitab_header #LC_current_minitab {
8512: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8513: }
8514: #LC_minitab_header #LC_current_minitab a {
8515: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8516: padding-bottom:5px;
8517: }
8518:
8519:
1.343 albertel 8520: END
8521: }
8522:
1.306 albertel 8523: =pod
8524:
8525: =item * &headtag()
8526:
8527: Returns a uniform footer for LON-CAPA web pages.
8528:
1.307 albertel 8529: Inputs: $title - optional title for the head
8530: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8531: $args - optional arguments
1.319 albertel 8532: force_register - if is true call registerurl so the remote is
8533: informed
1.415 albertel 8534: redirect -> array ref of
8535: 1- seconds before redirect occurs
8536: 2- url to redirect to
8537: 3- whether the side effect should occur
1.315 albertel 8538: (side effect of setting
8539: $env{'internal.head.redirect'} to the url
8540: redirected too)
1.352 albertel 8541: domain -> force to color decorate a page for a specific
8542: domain
8543: function -> force usage of a specific rolish color scheme
8544: bgcolor -> override the default page bgcolor
1.460 albertel 8545: no_auto_mt_title
8546: -> prevent &mt()ing the title arg
1.464 albertel 8547:
1.306 albertel 8548: =cut
8549:
8550: sub headtag {
1.313 albertel 8551: my ($title,$head_extra,$args) = @_;
1.306 albertel 8552:
1.363 albertel 8553: my $function = $args->{'function'} || &get_users_function();
8554: my $domain = $args->{'domain'} || &determinedomain();
8555: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8556: my $httphost = $args->{'use_absolute'};
1.418 albertel 8557: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8558: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8559: #time(),
1.418 albertel 8560: $env{'environment.color.timestamp'},
1.363 albertel 8561: $function,$domain,$bgcolor);
8562:
1.369 www 8563: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8564:
1.308 albertel 8565: my $result =
8566: '<head>'.
1.1160 raeburn 8567: &font_settings($args);
1.319 albertel 8568:
1.1188 raeburn 8569: my $inhibitprint;
8570: if ($args->{'print_suppress'}) {
8571: $inhibitprint = &print_suppression();
8572: }
1.1064 raeburn 8573:
1.461 albertel 8574: if (!$args->{'frameset'}) {
8575: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8576: }
1.962 droeschl 8577: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8578: $result .= Apache::lonxml::display_title();
1.319 albertel 8579: }
1.436 albertel 8580: if (!$args->{'no_nav_bar'}
8581: && !$args->{'only_body'}
8582: && !$args->{'frameset'}) {
1.1154 raeburn 8583: $result .= &help_menu_js($httphost);
1.1032 www 8584: $result.=&modal_window();
1.1038 www 8585: $result.=&togglebox_script();
1.1034 www 8586: $result.=&wishlist_window();
1.1041 www 8587: $result.=&LCprogressbarUpdate_script();
1.1034 www 8588: } else {
8589: if ($args->{'add_modal'}) {
8590: $result.=&modal_window();
8591: }
8592: if ($args->{'add_wishlist'}) {
8593: $result.=&wishlist_window();
8594: }
1.1038 www 8595: if ($args->{'add_togglebox'}) {
8596: $result.=&togglebox_script();
8597: }
1.1041 www 8598: if ($args->{'add_progressbar'}) {
8599: $result.=&LCprogressbarUpdate_script();
8600: }
1.436 albertel 8601: }
1.314 albertel 8602: if (ref($args->{'redirect'})) {
1.414 albertel 8603: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8604: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8605: if (!$inhibit_continue) {
8606: $env{'internal.head.redirect'} = $url;
8607: }
1.313 albertel 8608: $result.=<<ADDMETA
8609: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8610: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8611: ADDMETA
1.1210 raeburn 8612: } else {
8613: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8614: my $requrl = $env{'request.uri'};
8615: if ($requrl eq '') {
8616: $requrl = $ENV{'REQUEST_URI'};
8617: $requrl =~ s/\?.+$//;
8618: }
8619: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8620: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8621: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8622: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8623: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8624: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
1.1340 raeburn 8625: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
1.1352 raeburn 8626: my ($offload,$offloadoth);
1.1210 raeburn 8627: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8628: if ($domdefs{'offloadnow'}{$lonhost}) {
1.1340 raeburn 8629: $offload = 1;
1.1353 raeburn 8630: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8631: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8632: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8633: $offloadoth = 1;
8634: $dom_in_use = $env{'user.domain'};
8635: }
8636: }
1.1340 raeburn 8637: }
8638: }
8639: unless ($offload) {
8640: if (ref($domdefs{'offloadoth'}) eq 'HASH') {
8641: if ($domdefs{'offloadoth'}{$lonhost}) {
8642: if (($env{'user.domain'} ne '') && ($env{'user.domain'} ne $dom_in_use) &&
8643: (!(($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public')))) {
8644: unless (&Apache::lonnet::shared_institution($env{'user.domain'})) {
8645: $offload = 1;
1.1352 raeburn 8646: $offloadoth = 1;
1.1340 raeburn 8647: $dom_in_use = $env{'user.domain'};
8648: }
1.1210 raeburn 8649: }
1.1340 raeburn 8650: }
8651: }
8652: }
8653: if ($offload) {
1.1358 raeburn 8654: my $newserver = &Apache::lonnet::spareserver(undef,30000,undef,1,$dom_in_use);
1.1352 raeburn 8655: if (($newserver eq '') && ($offloadoth)) {
8656: my @domains = &Apache::lonnet::current_machine_domains();
8657: if (($dom_in_use ne '') && (!grep(/^\Q$dom_in_use\E$/,@domains))) {
8658: ($newserver) = &Apache::lonnet::choose_server($dom_in_use);
8659: }
8660: }
1.1340 raeburn 8661: if (($newserver) && ($newserver ne $lonhost)) {
8662: my $numsec = 5;
8663: my $timeout = $numsec * 1000;
8664: my ($newurl,$locknum,%locks,$msg);
8665: if ($env{'request.role.adv'}) {
8666: ($locknum,%locks) = &Apache::lonnet::get_locks();
8667: }
8668: my $disable_submit = 0;
8669: if ($requrl =~ /$LONCAPA::assess_re/) {
8670: $disable_submit = 1;
8671: }
8672: if ($locknum) {
8673: my @lockinfo = sort(values(%locks));
1.1354 raeburn 8674: $msg = &mt('Once the following tasks are complete:')." \n".
1.1340 raeburn 8675: join(", ",sort(values(%locks)))."\n";
8676: if (&show_course()) {
8677: $msg .= &mt('your session will be transferred to a different server, after you click "Courses".');
8678: } else {
8679: $msg .= &mt('your session will be transferred to a different server, after you click "Roles".');
1.1210 raeburn 8680: }
1.1340 raeburn 8681: } else {
8682: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8683: $msg = &mt('Your LON-CAPA submission has been recorded')."\n";
8684: }
8685: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8686: $newurl = '/adm/switchserver?otherserver='.$newserver;
8687: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8688: $newurl .= '&role='.$env{'request.role'};
8689: }
8690: if ($env{'request.symb'}) {
8691: my $shownsymb = &Apache::lonenc::check_encrypt($env{'request.symb'});
8692: if ($shownsymb =~ m{^/enc/}) {
8693: my $reqdmajor = 2;
8694: my $reqdminor = 11;
8695: my $reqdsubminor = 3;
8696: my $newserverrev = &Apache::lonnet::get_server_loncaparev('',$newserver);
8697: my $remoterev = &Apache::lonnet::get_server_loncaparev(undef,$newserver);
8698: my ($major,$minor,$subminor) = ($remoterev =~ /^\'?(\d+)\.(\d+)\.(\d+|)[\w.\-]+\'?$/);
8699: if (($major eq '' && $minor eq '') ||
8700: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)) ||
8701: (($reqdmajor == $major) && ($reqdminor == $minor) && (($subminor eq '') ||
8702: ($reqdsubminor > $subminor))))) {
8703: undef($shownsymb);
8704: }
1.1210 raeburn 8705: }
1.1340 raeburn 8706: if ($shownsymb) {
8707: &js_escape(\$shownsymb);
8708: $newurl .= '&symb='.$shownsymb;
1.1210 raeburn 8709: }
1.1340 raeburn 8710: } else {
8711: my $shownurl = &Apache::lonenc::check_encrypt($requrl);
8712: &js_escape(\$shownurl);
8713: $newurl .= '&origurl='.$shownurl;
1.1210 raeburn 8714: }
1.1340 raeburn 8715: }
8716: &js_escape(\$msg);
8717: $result.=<<OFFLOAD
1.1210 raeburn 8718: <meta http-equiv="pragma" content="no-cache" />
8719: <script type="text/javascript">
1.1215 raeburn 8720: // <![CDATA[
1.1210 raeburn 8721: function LC_Offload_Now() {
8722: var dest = "$newurl";
8723: if (dest != '') {
8724: window.location.href="$newurl";
8725: }
8726: }
1.1214 raeburn 8727: \$(document).ready(function () {
8728: window.alert('$msg');
8729: if ($disable_submit) {
1.1210 raeburn 8730: \$(".LC_hwk_submit").prop("disabled", true);
8731: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8732: }
8733: setTimeout('LC_Offload_Now()', $timeout);
8734: });
1.1215 raeburn 8735: // ]]>
1.1210 raeburn 8736: </script>
8737: OFFLOAD
8738: }
8739: }
8740: }
8741: }
8742: }
1.313 albertel 8743: }
1.306 albertel 8744: if (!defined($title)) {
8745: $title = 'The LearningOnline Network with CAPA';
8746: }
1.460 albertel 8747: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8748: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8749: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8750: if (!$args->{'frameset'}) {
8751: $result .= ' /';
8752: }
8753: $result .= '>'
1.1064 raeburn 8754: .$inhibitprint
1.414 albertel 8755: .$head_extra;
1.1242 raeburn 8756: my $clientmobile;
8757: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8758: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8759: } else {
8760: $clientmobile = $env{'browser.mobile'};
8761: }
8762: if ($clientmobile) {
1.1137 raeburn 8763: $result .= '
8764: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8765: <meta name="apple-mobile-web-app-capable" content="yes" />';
8766: }
1.1278 raeburn 8767: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8768: return $result.'</head>';
1.306 albertel 8769: }
8770:
8771: =pod
8772:
1.340 albertel 8773: =item * &font_settings()
8774:
8775: Returns neccessary <meta> to set the proper encoding
8776:
1.1160 raeburn 8777: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8778:
8779: =cut
8780:
8781: sub font_settings {
1.1160 raeburn 8782: my ($args) = @_;
1.340 albertel 8783: my $headerstring='';
1.1160 raeburn 8784: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8785: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8786: $headerstring.=
8787: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8788: if (!$args->{'frameset'}) {
8789: $headerstring.= ' /';
8790: }
8791: $headerstring .= '>'."\n";
1.340 albertel 8792: }
8793: return $headerstring;
8794: }
8795:
1.341 albertel 8796: =pod
8797:
1.1064 raeburn 8798: =item * &print_suppression()
8799:
8800: In course context returns css which causes the body to be blank when media="print",
8801: if printout generation is unavailable for the current resource.
8802:
8803: This could be because:
8804:
8805: (a) printstartdate is in the future
8806:
8807: (b) printenddate is in the past
8808:
8809: (c) there is an active exam block with "printout"
8810: functionality blocked
8811:
8812: Users with pav, pfo or evb privileges are exempt.
8813:
8814: Inputs: none
8815:
8816: =cut
8817:
8818:
8819: sub print_suppression {
8820: my $noprint;
8821: if ($env{'request.course.id'}) {
8822: my $scope = $env{'request.course.id'};
8823: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8824: (&Apache::lonnet::allowed('pfo',$scope))) {
8825: return;
8826: }
8827: if ($env{'request.course.sec'} ne '') {
8828: $scope .= "/$env{'request.course.sec'}";
8829: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8830: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8831: return;
1.1064 raeburn 8832: }
8833: }
8834: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8835: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8836: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8837: if ($blocked) {
8838: my $checkrole = "cm./$cdom/$cnum";
8839: if ($env{'request.course.sec'} ne '') {
8840: $checkrole .= "/$env{'request.course.sec'}";
8841: }
8842: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8843: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8844: $noprint = 1;
8845: }
8846: }
8847: unless ($noprint) {
8848: my $symb = &Apache::lonnet::symbread();
8849: if ($symb ne '') {
8850: my $navmap = Apache::lonnavmaps::navmap->new();
8851: if (ref($navmap)) {
8852: my $res = $navmap->getBySymb($symb);
8853: if (ref($res)) {
8854: if (!$res->resprintable()) {
8855: $noprint = 1;
8856: }
8857: }
8858: }
8859: }
8860: }
8861: if ($noprint) {
8862: return <<"ENDSTYLE";
8863: <style type="text/css" media="print">
8864: body { display:none }
8865: </style>
8866: ENDSTYLE
8867: }
8868: }
8869: return;
8870: }
8871:
8872: =pod
8873:
1.341 albertel 8874: =item * &xml_begin()
8875:
8876: Returns the needed doctype and <html>
8877:
8878: Inputs: none
8879:
8880: =cut
8881:
8882: sub xml_begin {
1.1168 raeburn 8883: my ($is_frameset) = @_;
1.341 albertel 8884: my $output='';
8885:
8886: if ($env{'browser.mathml'}) {
8887: $output='<?xml version="1.0"?>'
8888: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8889: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8890:
8891: # .'<!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">] >'
8892: .'<!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">'
8893: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8894: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8895: } elsif ($is_frameset) {
8896: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8897: '<html>'."\n";
1.341 albertel 8898: } else {
1.1168 raeburn 8899: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8900: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8901: }
8902: return $output;
8903: }
1.340 albertel 8904:
8905: =pod
8906:
1.306 albertel 8907: =item * &start_page()
8908:
8909: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8910:
1.648 raeburn 8911: Inputs:
8912:
8913: =over 4
8914:
8915: $title - optional title for the page
8916:
8917: $head_extra - optional extra HTML to incude inside the <head>
8918:
8919: $args - additional optional args supported are:
8920:
8921: =over 8
8922:
8923: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8924: arg on
1.814 bisitz 8925: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8926: add_entries -> additional attributes to add to the <body>
8927: domain -> force to color decorate a page for a
1.317 albertel 8928: specific domain
1.648 raeburn 8929: function -> force usage of a specific rolish color
1.317 albertel 8930: scheme
1.648 raeburn 8931: redirect -> see &headtag()
8932: bgcolor -> override the default page bg color
8933: js_ready -> return a string ready for being used in
1.317 albertel 8934: a javascript writeln
1.648 raeburn 8935: html_encode -> return a string ready for being used in
1.320 albertel 8936: a html attribute
1.648 raeburn 8937: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8938: $forcereg arg
1.648 raeburn 8939: frameset -> if true will start with a <frameset>
1.330 albertel 8940: rather than <body>
1.648 raeburn 8941: skip_phases -> hash ref of
1.338 albertel 8942: head -> skip the <html><head> generation
8943: body -> skip all <body> generation
1.648 raeburn 8944: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8945: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8946: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 8947: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8948: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 8949: group -> includes the current group, if page is for a
1.1274 raeburn 8950: specific group
8951: use_absolute -> for request for external resource or syllabus, this
8952: will contain https://<hostname> if server uses
8953: https (as per hosts.tab), but request is for http
8954: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8955:
1.648 raeburn 8956: =back
1.460 albertel 8957:
1.648 raeburn 8958: =back
1.562 albertel 8959:
1.306 albertel 8960: =cut
8961:
8962: sub start_page {
1.309 albertel 8963: my ($title,$head_extra,$args) = @_;
1.318 albertel 8964: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8965:
1.315 albertel 8966: $env{'internal.start_page'}++;
1.1359 raeburn 8967: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu,$menucoll,%menu);
1.964 droeschl 8968:
1.338 albertel 8969: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8970: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8971: }
1.1316 raeburn 8972:
8973: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 8974: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
8975: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
8976: $args->{'no_primary_menu'} = 1;
8977: }
8978: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
8979: $args->{'no_inline_menu'} = 1;
8980: }
8981: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
8982: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
8983: }
8984: } else {
8985: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8986: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
8987: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
8988: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
8989: $args->{'no_primary_menu'} = 1;
8990: }
8991: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
8992: $args->{'no_inline_menu'} = 1;
8993: }
8994: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
8995: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
8996: }
8997: }
8998: }
1.1316 raeburn 8999: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
9000: $env{'course.'.$env{'request.course.id'}.'.domain'},
9001: $env{'course.'.$env{'request.course.id'}.'.num'});
1.1359 raeburn 9002: } elsif ($env{'request.course.id'}) {
9003: my $expiretime=600;
9004: if ((time-$env{'course.'.$env{'request.course.id'}.'.last_cache'}) > $expiretime) {
9005: &Apache::lonnet::coursedescription($env{'request.course.id'},{'freshen_cache' => 1});
9006: }
9007: my ($deeplinkmenu,$menuref);
9008: ($menucoll,$deeplinkmenu,$menuref) = &menucoll_in_effect();
9009: if ($menucoll) {
9010: if (ref($menuref) eq 'HASH') {
9011: %menu = %{$menuref};
9012: }
9013: if ($menu{'top'} eq 'n') {
9014: $args->{'no_primary_menu'} = 1;
9015: }
9016: if ($menu{'inline'} eq 'n') {
9017: unless (&Apache::lonnet::allowed('opa')) {
9018: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9019: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
9020: my $crstype = &course_type();
9021: my $now = time;
9022: my $ccrole;
9023: if ($crstype eq 'Community') {
9024: $ccrole = 'co';
9025: } else {
9026: $ccrole = 'cc';
9027: }
9028: if ($env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum}) {
9029: my ($start,$end) = split(/\./,$env{'user.role.'.$ccrole.'./'.$cdom.'/'.$cnum});
9030: if ((($start) && ($start<0)) ||
9031: (($end) && ($end<$now)) ||
9032: (($start) && ($now<$start))) {
9033: $args->{'no_inline_menu'} = 1;
9034: }
9035: } else {
9036: $args->{'no_inline_menu'} = 1;
9037: }
9038: }
9039: }
9040: }
1.1316 raeburn 9041: }
1.1359 raeburn 9042:
1.338 albertel 9043: if (! exists($args->{'skip_phases'}{'body'}) ) {
9044: if ($args->{'frameset'}) {
9045: my $attr_string = &make_attr_string($args->{'force_register'},
9046: $args->{'add_entries'});
9047: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 9048: } else {
9049: $result .=
9050: &bodytag($title,
9051: $args->{'function'}, $args->{'add_entries'},
9052: $args->{'only_body'}, $args->{'domain'},
9053: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 9054: $args->{'bgcolor'}, $args,
1.1359 raeburn 9055: \@advtools,$ltiscope,$ltiuri,\%ltimenu,$menucoll,\%menu);
1.831 bisitz 9056: }
1.330 albertel 9057: }
1.338 albertel 9058:
1.315 albertel 9059: if ($args->{'js_ready'}) {
1.713 kaisler 9060: $result = &js_ready($result);
1.315 albertel 9061: }
1.320 albertel 9062: if ($args->{'html_encode'}) {
1.713 kaisler 9063: $result = &html_encode($result);
9064: }
9065:
1.813 bisitz 9066: # Preparation for new and consistent functionlist at top of screen
9067: # if ($args->{'functionlist'}) {
9068: # $result .= &build_functionlist();
9069: #}
9070:
1.964 droeschl 9071: # Don't add anything more if only_body wanted or in const space
9072: return $result if $args->{'only_body'}
9073: || $env{'request.state'} eq 'construct';
1.813 bisitz 9074:
9075: #Breadcrumbs
1.758 kaisler 9076: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
9077: &Apache::lonhtmlcommon::clear_breadcrumbs();
9078: #if any br links exists, add them to the breadcrumbs
9079: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
9080: foreach my $crumb (@{$args->{'bread_crumbs'}}){
9081: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
9082: }
9083: }
1.1096 raeburn 9084: # if @advtools array contains items add then to the breadcrumbs
9085: if (@advtools > 0) {
9086: &Apache::lonmenu::advtools_crumbs(@advtools);
9087: }
1.1272 raeburn 9088: my $menulink;
9089: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
9090: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 9091: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 9092: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
9093: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
9094: (!$env{'request.role.adv'}))) {
9095: $menulink = 0;
9096: } else {
9097: undef($menulink);
9098: }
1.758 kaisler 9099: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
9100: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 9101: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 9102: } else {
1.1272 raeburn 9103: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 9104: }
1.320 albertel 9105: }
1.315 albertel 9106: return $result;
1.306 albertel 9107: }
9108:
9109: sub end_page {
1.315 albertel 9110: my ($args) = @_;
9111: $env{'internal.end_page'}++;
1.330 albertel 9112: my $result;
1.335 albertel 9113: if ($args->{'discussion'}) {
9114: my ($target,$parser);
9115: if (ref($args->{'discussion'})) {
9116: ($target,$parser) =($args->{'discussion'}{'target'},
9117: $args->{'discussion'}{'parser'});
9118: }
9119: $result .= &Apache::lonxml::xmlend($target,$parser);
9120: }
1.330 albertel 9121: if ($args->{'frameset'}) {
9122: $result .= '</frameset>';
9123: } else {
1.635 raeburn 9124: $result .= &endbodytag($args);
1.330 albertel 9125: }
1.1080 raeburn 9126: unless ($args->{'notbody'}) {
9127: $result .= "\n</html>";
9128: }
1.330 albertel 9129:
1.315 albertel 9130: if ($args->{'js_ready'}) {
1.317 albertel 9131: $result = &js_ready($result);
1.315 albertel 9132: }
1.335 albertel 9133:
1.320 albertel 9134: if ($args->{'html_encode'}) {
9135: $result = &html_encode($result);
9136: }
1.335 albertel 9137:
1.315 albertel 9138: return $result;
9139: }
9140:
1.1359 raeburn 9141: sub menucoll_in_effect {
9142: my ($menucoll,$deeplinkmenu,%menu);
9143: if ($env{'request.course.id'}) {
9144: $menucoll = $env{'course.'.$env{'request.course.id'}.'.menudefault'};
9145: if (($env{'request.deeplink.login'}) &&
9146: ($env{'request.noversionuri'} =~ m{^/(res|uploaded)/})) {
1.1360 ! raeburn 9147: my $deeplink = &Apache::lonnet::EXT('resource.0.deeplink');
1.1359 raeburn 9148: if ($deeplink ne '') {
9149: my ($listed,$scope,$access,$display) = split(/,/,$deeplink);
9150: if ($display =~ /^\d+$/) {
9151: $deeplinkmenu = 1;
9152: $menucoll = $display;
9153: }
9154: }
9155: }
9156: if ($menucoll) {
9157: %menu = &page_menu($env{'course.'.$env{'request.course.id'}.'.menucollections'},$menucoll);
9158: }
9159: }
9160: return ($menucoll,$deeplinkmenu,\%menu);
9161: }
9162:
1.1034 www 9163: sub wishlist_window {
9164: return(<<'ENDWISHLIST');
1.1046 raeburn 9165: <script type="text/javascript">
1.1034 www 9166: // <![CDATA[
9167: // <!-- BEGIN LON-CAPA Internal
9168: function set_wishlistlink(title, path) {
9169: if (!title) {
9170: title = document.title;
9171: title = title.replace(/^LON-CAPA /,'');
9172: }
1.1175 raeburn 9173: title = encodeURIComponent(title);
1.1203 raeburn 9174: title = title.replace("'","\\\'");
1.1034 www 9175: if (!path) {
9176: path = location.pathname;
9177: }
1.1175 raeburn 9178: path = encodeURIComponent(path);
1.1203 raeburn 9179: path = path.replace("'","\\\'");
1.1034 www 9180: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
9181: 'wishlistNewLink','width=560,height=350,scrollbars=0');
9182: }
9183: // END LON-CAPA Internal -->
9184: // ]]>
9185: </script>
9186: ENDWISHLIST
9187: }
9188:
1.1030 www 9189: sub modal_window {
9190: return(<<'ENDMODAL');
1.1046 raeburn 9191: <script type="text/javascript">
1.1030 www 9192: // <![CDATA[
9193: // <!-- BEGIN LON-CAPA Internal
9194: var modalWindow = {
9195: parent:"body",
9196: windowId:null,
9197: content:null,
9198: width:null,
9199: height:null,
9200: close:function()
9201: {
9202: $(".LCmodal-window").remove();
9203: $(".LCmodal-overlay").remove();
9204: },
9205: open:function()
9206: {
9207: var modal = "";
9208: modal += "<div class=\"LCmodal-overlay\"></div>";
9209: 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;\">";
9210: modal += this.content;
9211: modal += "</div>";
9212:
9213: $(this.parent).append(modal);
9214:
9215: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
9216: $(".LCclose-window").click(function(){modalWindow.close();});
9217: $(".LCmodal-overlay").click(function(){modalWindow.close();});
9218: }
9219: };
1.1140 raeburn 9220: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 9221: {
1.1266 raeburn 9222: source = source.replace(/'/g,"'");
1.1030 www 9223: modalWindow.windowId = "myModal";
9224: modalWindow.width = width;
9225: modalWindow.height = height;
1.1196 raeburn 9226: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 9227: modalWindow.open();
1.1208 raeburn 9228: };
1.1030 www 9229: // END LON-CAPA Internal -->
9230: // ]]>
9231: </script>
9232: ENDMODAL
9233: }
9234:
9235: sub modal_link {
1.1140 raeburn 9236: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 9237: unless ($width) { $width=480; }
9238: unless ($height) { $height=400; }
1.1031 www 9239: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 9240: unless ($transparency) { $transparency='true'; }
9241:
1.1074 raeburn 9242: my $target_attr;
9243: if (defined($target)) {
9244: $target_attr = 'target="'.$target.'"';
9245: }
9246: return <<"ENDLINK";
1.1336 raeburn 9247: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">$linktext</a>
1.1074 raeburn 9248: ENDLINK
1.1030 www 9249: }
9250:
1.1032 www 9251: sub modal_adhoc_script {
9252: my ($funcname,$width,$height,$content)=@_;
9253: return (<<ENDADHOC);
1.1046 raeburn 9254: <script type="text/javascript">
1.1032 www 9255: // <![CDATA[
9256: var $funcname = function()
9257: {
9258: modalWindow.windowId = "myModal";
9259: modalWindow.width = $width;
9260: modalWindow.height = $height;
9261: modalWindow.content = '$content';
9262: modalWindow.open();
9263: };
9264: // ]]>
9265: </script>
9266: ENDADHOC
9267: }
9268:
1.1041 www 9269: sub modal_adhoc_inner {
9270: my ($funcname,$width,$height,$content)=@_;
9271: my $innerwidth=$width-20;
9272: $content=&js_ready(
1.1140 raeburn 9273: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
9274: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
9275: $content.
1.1041 www 9276: &end_scrollbox().
1.1140 raeburn 9277: &end_page()
1.1041 www 9278: );
9279: return &modal_adhoc_script($funcname,$width,$height,$content);
9280: }
9281:
9282: sub modal_adhoc_window {
9283: my ($funcname,$width,$height,$content,$linktext)=@_;
9284: return &modal_adhoc_inner($funcname,$width,$height,$content).
9285: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
9286: }
9287:
9288: sub modal_adhoc_launch {
9289: my ($funcname,$width,$height,$content)=@_;
9290: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
9291: <script type="text/javascript">
9292: // <![CDATA[
9293: $funcname();
9294: // ]]>
9295: </script>
9296: ENDLAUNCH
9297: }
9298:
9299: sub modal_adhoc_close {
9300: return (<<ENDCLOSE);
9301: <script type="text/javascript">
9302: // <![CDATA[
9303: modalWindow.close();
9304: // ]]>
9305: </script>
9306: ENDCLOSE
9307: }
9308:
1.1038 www 9309: sub togglebox_script {
9310: return(<<ENDTOGGLE);
9311: <script type="text/javascript">
9312: // <![CDATA[
9313: function LCtoggleDisplay(id,hidetext,showtext) {
9314: link = document.getElementById(id + "link").childNodes[0];
9315: with (document.getElementById(id).style) {
9316: if (display == "none" ) {
9317: display = "inline";
9318: link.nodeValue = hidetext;
9319: } else {
9320: display = "none";
9321: link.nodeValue = showtext;
9322: }
9323: }
9324: }
9325: // ]]>
9326: </script>
9327: ENDTOGGLE
9328: }
9329:
1.1039 www 9330: sub start_togglebox {
9331: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9332: unless ($heading) { $heading=''; } else { $heading.=' '; }
9333: unless ($showtext) { $showtext=&mt('show'); }
9334: unless ($hidetext) { $hidetext=&mt('hide'); }
9335: unless ($headerbg) { $headerbg='#FFFFFF'; }
9336: return &start_data_table().
9337: &start_data_table_header_row().
9338: '<td bgcolor="'.$headerbg.'">'.$heading.
9339: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9340: $showtext.'\')">'.$showtext.'</a>]</td>'.
9341: &end_data_table_header_row().
9342: '<tr id="'.$id.'" style="display:none""><td>';
9343: }
9344:
9345: sub end_togglebox {
9346: return '</td></tr>'.&end_data_table();
9347: }
9348:
1.1041 www 9349: sub LCprogressbar_script {
1.1302 raeburn 9350: my ($id,$number_to_do)=@_;
9351: if ($number_to_do) {
9352: return(<<ENDPROGRESS);
1.1041 www 9353: <script type="text/javascript">
9354: // <![CDATA[
1.1045 www 9355: \$('#progressbar$id').progressbar({
1.1041 www 9356: value: 0,
9357: change: function(event, ui) {
9358: var newVal = \$(this).progressbar('option', 'value');
9359: \$('.pblabel', this).text(LCprogressTxt);
9360: }
9361: });
9362: // ]]>
9363: </script>
9364: ENDPROGRESS
1.1302 raeburn 9365: } else {
9366: return(<<ENDPROGRESS);
9367: <script type="text/javascript">
9368: // <![CDATA[
9369: \$('#progressbar$id').progressbar({
9370: value: false,
9371: create: function(event, ui) {
9372: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9373: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9374: }
9375: });
9376: // ]]>
9377: </script>
9378: ENDPROGRESS
9379: }
1.1041 www 9380: }
9381:
9382: sub LCprogressbarUpdate_script {
9383: return(<<ENDPROGRESSUPDATE);
9384: <style type="text/css">
9385: .ui-progressbar { position:relative; }
1.1302 raeburn 9386: .progress-label {position: absolute; width: 100%; text-align: center; top: 1px; font-weight: bold; text-shadow: 1px 1px 0 #fff;margin: 0; line-height: 200%; }
1.1041 www 9387: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9388: </style>
9389: <script type="text/javascript">
9390: // <![CDATA[
1.1045 www 9391: var LCprogressTxt='---';
9392:
1.1302 raeburn 9393: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9394: LCprogressTxt=progresstext;
1.1302 raeburn 9395: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9396: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9397: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 9398: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9399: } else {
9400: \$('#progressbar'+id).progressbar('value',percent);
9401: }
1.1041 www 9402: }
9403: // ]]>
9404: </script>
9405: ENDPROGRESSUPDATE
9406: }
9407:
1.1042 www 9408: my $LClastpercent;
1.1045 www 9409: my $LCidcnt;
9410: my $LCcurrentid;
1.1042 www 9411:
1.1041 www 9412: sub LCprogressbar {
1.1302 raeburn 9413: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9414: $LClastpercent=0;
1.1045 www 9415: $LCidcnt++;
9416: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 9417: my ($starting,$content);
9418: if ($number_to_do) {
9419: $starting=&mt('Starting');
9420: $content=(<<ENDPROGBAR);
9421: $preamble
1.1045 www 9422: <div id="progressbar$LCcurrentid">
1.1041 www 9423: <span class="pblabel">$starting</span>
9424: </div>
9425: ENDPROGBAR
1.1302 raeburn 9426: } else {
9427: $starting=&mt('Loading...');
9428: $LClastpercent='false';
9429: $content=(<<ENDPROGBAR);
9430: $preamble
9431: <div id="progressbar$LCcurrentid">
9432: <div class="progress-label">$starting</div>
9433: </div>
9434: ENDPROGBAR
9435: }
9436: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9437: }
9438:
9439: sub LCprogressbarUpdate {
1.1302 raeburn 9440: my ($r,$val,$text,$number_to_do)=@_;
9441: if ($number_to_do) {
9442: unless ($val) {
9443: if ($LClastpercent) {
9444: $val=$LClastpercent;
9445: } else {
9446: $val=0;
9447: }
9448: }
9449: if ($val<0) { $val=0; }
9450: if ($val>100) { $val=0; }
9451: $LClastpercent=$val;
9452: unless ($text) { $text=$val.'%'; }
9453: } else {
9454: $val = 'false';
1.1042 www 9455: }
1.1041 www 9456: $text=&js_ready($text);
1.1044 www 9457: &r_print($r,<<ENDUPDATE);
1.1041 www 9458: <script type="text/javascript">
9459: // <![CDATA[
1.1302 raeburn 9460: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9461: // ]]>
9462: </script>
9463: ENDUPDATE
1.1035 www 9464: }
9465:
1.1042 www 9466: sub LCprogressbarClose {
9467: my ($r)=@_;
9468: $LClastpercent=0;
1.1044 www 9469: &r_print($r,<<ENDCLOSE);
1.1042 www 9470: <script type="text/javascript">
9471: // <![CDATA[
1.1045 www 9472: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9473: // ]]>
9474: </script>
9475: ENDCLOSE
1.1044 www 9476: }
9477:
9478: sub r_print {
9479: my ($r,$to_print)=@_;
9480: if ($r) {
9481: $r->print($to_print);
9482: $r->rflush();
9483: } else {
9484: print($to_print);
9485: }
1.1042 www 9486: }
9487:
1.320 albertel 9488: sub html_encode {
9489: my ($result) = @_;
9490:
1.322 albertel 9491: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9492:
9493: return $result;
9494: }
1.1044 www 9495:
1.317 albertel 9496: sub js_ready {
9497: my ($result) = @_;
9498:
1.323 albertel 9499: $result =~ s/[\n\r]/ /xmsg;
9500: $result =~ s/\\/\\\\/xmsg;
9501: $result =~ s/'/\\'/xmsg;
1.372 albertel 9502: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9503:
9504: return $result;
9505: }
9506:
1.315 albertel 9507: sub validate_page {
9508: if ( exists($env{'internal.start_page'})
1.316 albertel 9509: && $env{'internal.start_page'} > 1) {
9510: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9511: $env{'internal.start_page'}.' '.
1.316 albertel 9512: $ENV{'request.filename'});
1.315 albertel 9513: }
9514: if ( exists($env{'internal.end_page'})
1.316 albertel 9515: && $env{'internal.end_page'} > 1) {
9516: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9517: $env{'internal.end_page'}.' '.
1.316 albertel 9518: $env{'request.filename'});
1.315 albertel 9519: }
9520: if ( exists($env{'internal.start_page'})
9521: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9522: &Apache::lonnet::logthis('start_page called without end_page '.
9523: $env{'request.filename'});
1.315 albertel 9524: }
9525: if ( ! exists($env{'internal.start_page'})
9526: && exists($env{'internal.end_page'})) {
1.316 albertel 9527: &Apache::lonnet::logthis('end_page called without start_page'.
9528: $env{'request.filename'});
1.315 albertel 9529: }
1.306 albertel 9530: }
1.315 albertel 9531:
1.996 www 9532:
9533: sub start_scrollbox {
1.1140 raeburn 9534: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9535: unless ($outerwidth) { $outerwidth='520px'; }
9536: unless ($width) { $width='500px'; }
9537: unless ($height) { $height='200px'; }
1.1075 raeburn 9538: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9539: if ($id ne '') {
1.1140 raeburn 9540: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9541: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9542: }
1.1075 raeburn 9543: if ($bgcolor ne '') {
9544: $tdcol = "background-color: $bgcolor;";
9545: }
1.1137 raeburn 9546: my $nicescroll_js;
9547: if ($env{'browser.mobile'}) {
1.1140 raeburn 9548: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9549: }
9550: return <<"END";
9551: $nicescroll_js
9552:
9553: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9554: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9555: END
9556: }
9557:
9558: sub end_scrollbox {
9559: return '</div></td></tr></table>';
9560: }
9561:
9562: sub nicescroll_javascript {
9563: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9564: my %options;
9565: if (ref($cursor) eq 'HASH') {
9566: %options = %{$cursor};
9567: }
9568: unless ($options{'railalign'} =~ /^left|right$/) {
9569: $options{'railalign'} = 'left';
9570: }
9571: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9572: my $function = &get_users_function();
9573: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9574: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9575: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9576: }
1.1140 raeburn 9577: }
9578: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9579: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9580: $options{'cursoropacity'}='1.0';
9581: }
1.1140 raeburn 9582: } else {
9583: $options{'cursoropacity'}='1.0';
9584: }
9585: if ($options{'cursorfixedheight'} eq 'none') {
9586: delete($options{'cursorfixedheight'});
9587: } else {
9588: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9589: }
9590: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9591: delete($options{'railoffset'});
9592: }
9593: my @niceoptions;
9594: while (my($key,$value) = each(%options)) {
9595: if ($value =~ /^\{.+\}$/) {
9596: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9597: } else {
1.1140 raeburn 9598: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9599: }
1.1140 raeburn 9600: }
9601: my $nicescroll_js = '
1.1137 raeburn 9602: $(document).ready(
1.1140 raeburn 9603: function() {
9604: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9605: }
1.1137 raeburn 9606: );
9607: ';
1.1140 raeburn 9608: if ($framecheck) {
9609: $nicescroll_js .= '
9610: function expand_div(caller) {
9611: if (top === self) {
9612: document.getElementById("'.$id.'").style.width = "auto";
9613: document.getElementById("'.$id.'").style.height = "auto";
9614: } else {
9615: try {
9616: if (parent.frames) {
9617: if (parent.frames.length > 1) {
9618: var framesrc = parent.frames[1].location.href;
9619: var currsrc = framesrc.replace(/\#.*$/,"");
9620: if ((caller == "search") || (currsrc == "'.$location.'")) {
9621: document.getElementById("'.$id.'").style.width = "auto";
9622: document.getElementById("'.$id.'").style.height = "auto";
9623: }
9624: }
9625: }
9626: } catch (e) {
9627: return;
9628: }
1.1137 raeburn 9629: }
1.1140 raeburn 9630: return;
1.996 www 9631: }
1.1140 raeburn 9632: ';
9633: }
9634: if ($needjsready) {
9635: $nicescroll_js = '
9636: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9637: } else {
9638: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9639: }
9640: return $nicescroll_js;
1.996 www 9641: }
9642:
1.318 albertel 9643: sub simple_error_page {
1.1150 bisitz 9644: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 9645: my %displayargs;
1.1151 raeburn 9646: if (ref($args) eq 'HASH') {
9647: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 9648: if ($args->{'only_body'}) {
9649: $displayargs{'only_body'} = 1;
9650: }
9651: if ($args->{'no_nav_bar'}) {
9652: $displayargs{'no_nav_bar'} = 1;
9653: }
1.1151 raeburn 9654: } else {
9655: $msg = &mt($msg);
9656: }
1.1150 bisitz 9657:
1.318 albertel 9658: my $page =
1.1304 raeburn 9659: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 9660: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9661: &Apache::loncommon::end_page();
9662: if (ref($r)) {
9663: $r->print($page);
1.327 albertel 9664: return;
1.318 albertel 9665: }
9666: return $page;
9667: }
1.347 albertel 9668:
9669: {
1.610 albertel 9670: my @row_count;
1.961 onken 9671:
9672: sub start_data_table_count {
9673: unshift(@row_count, 0);
9674: return;
9675: }
9676:
9677: sub end_data_table_count {
9678: shift(@row_count);
9679: return;
9680: }
9681:
1.347 albertel 9682: sub start_data_table {
1.1018 raeburn 9683: my ($add_class,$id) = @_;
1.422 albertel 9684: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9685: my $table_id;
9686: if (defined($id)) {
9687: $table_id = ' id="'.$id.'"';
9688: }
1.961 onken 9689: &start_data_table_count();
1.1018 raeburn 9690: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9691: }
9692:
9693: sub end_data_table {
1.961 onken 9694: &end_data_table_count();
1.389 albertel 9695: return '</table>'."\n";;
1.347 albertel 9696: }
9697:
9698: sub start_data_table_row {
1.974 wenzelju 9699: my ($add_class, $id) = @_;
1.610 albertel 9700: $row_count[0]++;
9701: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9702: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9703: $id = (' id="'.$id.'"') unless ($id eq '');
9704: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9705: }
1.471 banghart 9706:
9707: sub continue_data_table_row {
1.974 wenzelju 9708: my ($add_class, $id) = @_;
1.610 albertel 9709: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9710: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9711: $id = (' id="'.$id.'"') unless ($id eq '');
9712: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9713: }
1.347 albertel 9714:
9715: sub end_data_table_row {
1.389 albertel 9716: return '</tr>'."\n";;
1.347 albertel 9717: }
1.367 www 9718:
1.421 albertel 9719: sub start_data_table_empty_row {
1.707 bisitz 9720: # $row_count[0]++;
1.421 albertel 9721: return '<tr class="LC_empty_row" >'."\n";;
9722: }
9723:
9724: sub end_data_table_empty_row {
9725: return '</tr>'."\n";;
9726: }
9727:
1.367 www 9728: sub start_data_table_header_row {
1.389 albertel 9729: return '<tr class="LC_header_row">'."\n";;
1.367 www 9730: }
9731:
9732: sub end_data_table_header_row {
1.389 albertel 9733: return '</tr>'."\n";;
1.367 www 9734: }
1.890 droeschl 9735:
9736: sub data_table_caption {
9737: my $caption = shift;
9738: return "<caption class=\"LC_caption\">$caption</caption>";
9739: }
1.347 albertel 9740: }
9741:
1.548 albertel 9742: =pod
9743:
9744: =item * &inhibit_menu_check($arg)
9745:
9746: Checks for a inhibitmenu state and generates output to preserve it
9747:
9748: Inputs: $arg - can be any of
9749: - undef - in which case the return value is a string
9750: to add into arguments list of a uri
9751: - 'input' - in which case the return value is a HTML
9752: <form> <input> field of type hidden to
9753: preserve the value
9754: - a url - in which case the return value is the url with
9755: the neccesary cgi args added to preserve the
9756: inhibitmenu state
9757: - a ref to a url - no return value, but the string is
9758: updated to include the neccessary cgi
9759: args to preserve the inhibitmenu state
9760:
9761: =cut
9762:
9763: sub inhibit_menu_check {
9764: my ($arg) = @_;
9765: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9766: if ($arg eq 'input') {
9767: if ($env{'form.inhibitmenu'}) {
9768: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9769: } else {
9770: return
9771: }
9772: }
9773: if ($env{'form.inhibitmenu'}) {
9774: if (ref($arg)) {
9775: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9776: } elsif ($arg eq '') {
9777: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9778: } else {
9779: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9780: }
9781: }
9782: if (!ref($arg)) {
9783: return $arg;
9784: }
9785: }
9786:
1.251 albertel 9787: ###############################################
1.182 matthew 9788:
9789: =pod
9790:
1.549 albertel 9791: =back
9792:
9793: =head1 User Information Routines
9794:
9795: =over 4
9796:
1.405 albertel 9797: =item * &get_users_function()
1.182 matthew 9798:
9799: Used by &bodytag to determine the current users primary role.
9800: Returns either 'student','coordinator','admin', or 'author'.
9801:
9802: =cut
9803:
9804: ###############################################
9805: sub get_users_function {
1.815 tempelho 9806: my $function = 'norole';
1.818 tempelho 9807: if ($env{'request.role'}=~/^(st)/) {
9808: $function='student';
9809: }
1.907 raeburn 9810: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9811: $function='coordinator';
9812: }
1.258 albertel 9813: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9814: $function='admin';
9815: }
1.826 bisitz 9816: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9817: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9818: $function='author';
9819: }
9820: return $function;
1.54 www 9821: }
1.99 www 9822:
9823: ###############################################
9824:
1.233 raeburn 9825: =pod
9826:
1.821 raeburn 9827: =item * &show_course()
9828:
9829: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9830: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9831:
9832: Inputs:
9833: None
9834:
9835: Outputs:
9836: Scalar: 1 if 'Course' to be used, 0 otherwise.
9837:
9838: =cut
9839:
9840: ###############################################
9841: sub show_course {
9842: my $course = !$env{'user.adv'};
9843: if (!$env{'user.adv'}) {
9844: foreach my $env (keys(%env)) {
9845: next if ($env !~ m/^user\.priv\./);
9846: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9847: $course = 0;
9848: last;
9849: }
9850: }
9851: }
9852: return $course;
9853: }
9854:
9855: ###############################################
9856:
9857: =pod
9858:
1.542 raeburn 9859: =item * &check_user_status()
1.274 raeburn 9860:
9861: Determines current status of supplied role for a
9862: specific user. Roles can be active, previous or future.
9863:
9864: Inputs:
9865: user's domain, user's username, course's domain,
1.375 raeburn 9866: course's number, optional section ID.
1.274 raeburn 9867:
9868: Outputs:
9869: role status: active, previous or future.
9870:
9871: =cut
9872:
9873: sub check_user_status {
1.412 raeburn 9874: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9875: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9876: my @uroles = keys(%userinfo);
1.274 raeburn 9877: my $srchstr;
9878: my $active_chk = 'none';
1.412 raeburn 9879: my $now = time;
1.274 raeburn 9880: if (@uroles > 0) {
1.908 raeburn 9881: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9882: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9883: } else {
1.412 raeburn 9884: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9885: }
9886: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9887: my $role_end = 0;
9888: my $role_start = 0;
9889: $active_chk = 'active';
1.412 raeburn 9890: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9891: $role_end = $1;
9892: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9893: $role_start = $1;
1.274 raeburn 9894: }
9895: }
9896: if ($role_start > 0) {
1.412 raeburn 9897: if ($now < $role_start) {
1.274 raeburn 9898: $active_chk = 'future';
9899: }
9900: }
9901: if ($role_end > 0) {
1.412 raeburn 9902: if ($now > $role_end) {
1.274 raeburn 9903: $active_chk = 'previous';
9904: }
9905: }
9906: }
9907: }
9908: return $active_chk;
9909: }
9910:
9911: ###############################################
9912:
9913: =pod
9914:
1.405 albertel 9915: =item * &get_sections()
1.233 raeburn 9916:
9917: Determines all the sections for a course including
9918: sections with students and sections containing other roles.
1.419 raeburn 9919: Incoming parameters:
9920:
9921: 1. domain
9922: 2. course number
9923: 3. reference to array containing roles for which sections should
9924: be gathered (optional).
9925: 4. reference to array containing status types for which sections
9926: should be gathered (optional).
9927:
9928: If the third argument is undefined, sections are gathered for any role.
9929: If the fourth argument is undefined, sections are gathered for any status.
9930: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9931:
1.374 raeburn 9932: Returns section hash (keys are section IDs, values are
9933: number of users in each section), subject to the
1.419 raeburn 9934: optional roles filter, optional status filter
1.233 raeburn 9935:
9936: =cut
9937:
9938: ###############################################
9939: sub get_sections {
1.419 raeburn 9940: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9941: if (!defined($cdom) || !defined($cnum)) {
9942: my $cid = $env{'request.course.id'};
9943:
9944: return if (!defined($cid));
9945:
9946: $cdom = $env{'course.'.$cid.'.domain'};
9947: $cnum = $env{'course.'.$cid.'.num'};
9948: }
9949:
9950: my %sectioncount;
1.419 raeburn 9951: my $now = time;
1.240 albertel 9952:
1.1118 raeburn 9953: my $check_students = 1;
9954: my $only_students = 0;
9955: if (ref($possible_roles) eq 'ARRAY') {
9956: if (grep(/^st$/,@{$possible_roles})) {
9957: if (@{$possible_roles} == 1) {
9958: $only_students = 1;
9959: }
9960: } else {
9961: $check_students = 0;
9962: }
9963: }
9964:
9965: if ($check_students) {
1.276 albertel 9966: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9967: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9968: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9969: my $start_index = &Apache::loncoursedata::CL_START();
9970: my $end_index = &Apache::loncoursedata::CL_END();
9971: my $status;
1.366 albertel 9972: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9973: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9974: $data->[$status_index],
9975: $data->[$start_index],
9976: $data->[$end_index]);
9977: if ($stu_status eq 'Active') {
9978: $status = 'active';
9979: } elsif ($end < $now) {
9980: $status = 'previous';
9981: } elsif ($start > $now) {
9982: $status = 'future';
9983: }
9984: if ($section ne '-1' && $section !~ /^\s*$/) {
9985: if ((!defined($possible_status)) || (($status ne '') &&
9986: (grep/^\Q$status\E$/,@{$possible_status}))) {
9987: $sectioncount{$section}++;
9988: }
1.240 albertel 9989: }
9990: }
9991: }
1.1118 raeburn 9992: if ($only_students) {
9993: return %sectioncount;
9994: }
1.240 albertel 9995: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9996: foreach my $user (sort(keys(%courseroles))) {
9997: if ($user !~ /^(\w{2})/) { next; }
9998: my ($role) = ($user =~ /^(\w{2})/);
9999: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 10000: my ($section,$status);
1.240 albertel 10001: if ($role eq 'cr' &&
10002: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
10003: $section=$1;
10004: }
10005: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
10006: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 10007: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
10008: if ($end == -1 && $start == -1) {
10009: next; #deleted role
10010: }
10011: if (!defined($possible_status)) {
10012: $sectioncount{$section}++;
10013: } else {
10014: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
10015: $status = 'active';
10016: } elsif ($end < $now) {
10017: $status = 'future';
10018: } elsif ($start > $now) {
10019: $status = 'previous';
10020: }
10021: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
10022: $sectioncount{$section}++;
10023: }
10024: }
1.233 raeburn 10025: }
1.366 albertel 10026: return %sectioncount;
1.233 raeburn 10027: }
10028:
1.274 raeburn 10029: ###############################################
1.294 raeburn 10030:
10031: =pod
1.405 albertel 10032:
10033: =item * &get_course_users()
10034:
1.275 raeburn 10035: Retrieves usernames:domains for users in the specified course
10036: with specific role(s), and access status.
10037:
10038: Incoming parameters:
1.277 albertel 10039: 1. course domain
10040: 2. course number
10041: 3. access status: users must have - either active,
1.275 raeburn 10042: previous, future, or all.
1.277 albertel 10043: 4. reference to array of permissible roles
1.288 raeburn 10044: 5. reference to array of section restrictions (optional)
10045: 6. reference to results object (hash of hashes).
10046: 7. reference to optional userdata hash
1.609 raeburn 10047: 8. reference to optional statushash
1.630 raeburn 10048: 9. flag if privileged users (except those set to unhide in
10049: course settings) should be excluded
1.609 raeburn 10050: Keys of top level results hash are roles.
1.275 raeburn 10051: Keys of inner hashes are username:domain, with
10052: values set to access type.
1.288 raeburn 10053: Optional userdata hash returns an array with arguments in the
10054: same order as loncoursedata::get_classlist() for student data.
10055:
1.609 raeburn 10056: Optional statushash returns
10057:
1.288 raeburn 10058: Entries for end, start, section and status are blank because
10059: of the possibility of multiple values for non-student roles.
10060:
1.275 raeburn 10061: =cut
1.405 albertel 10062:
1.275 raeburn 10063: ###############################################
1.405 albertel 10064:
1.275 raeburn 10065: sub get_course_users {
1.630 raeburn 10066: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 10067: my %idx = ();
1.419 raeburn 10068: my %seclists;
1.288 raeburn 10069:
10070: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
10071: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
10072: $idx{end} = &Apache::loncoursedata::CL_END();
10073: $idx{start} = &Apache::loncoursedata::CL_START();
10074: $idx{id} = &Apache::loncoursedata::CL_ID();
10075: $idx{section} = &Apache::loncoursedata::CL_SECTION();
10076: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
10077: $idx{status} = &Apache::loncoursedata::CL_STATUS();
10078:
1.290 albertel 10079: if (grep(/^st$/,@{$roles})) {
1.276 albertel 10080: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 10081: my $now = time;
1.277 albertel 10082: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 10083: my $match = 0;
1.412 raeburn 10084: my $secmatch = 0;
1.419 raeburn 10085: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 10086: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 10087: if ($section eq '') {
10088: $section = 'none';
10089: }
1.291 albertel 10090: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10091: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10092: $secmatch = 1;
10093: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 10094: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10095: $secmatch = 1;
10096: }
10097: } else {
1.419 raeburn 10098: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 10099: $secmatch = 1;
10100: }
1.290 albertel 10101: }
1.412 raeburn 10102: if (!$secmatch) {
10103: next;
10104: }
1.419 raeburn 10105: }
1.275 raeburn 10106: if (defined($$types{'active'})) {
1.288 raeburn 10107: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 10108: push(@{$$users{st}{$student}},'active');
1.288 raeburn 10109: $match = 1;
1.275 raeburn 10110: }
10111: }
10112: if (defined($$types{'previous'})) {
1.609 raeburn 10113: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 10114: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 10115: $match = 1;
1.275 raeburn 10116: }
10117: }
10118: if (defined($$types{'future'})) {
1.609 raeburn 10119: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 10120: push(@{$$users{st}{$student}},'future');
1.288 raeburn 10121: $match = 1;
1.275 raeburn 10122: }
10123: }
1.609 raeburn 10124: if ($match) {
10125: push(@{$seclists{$student}},$section);
10126: if (ref($userdata) eq 'HASH') {
10127: $$userdata{$student} = $$classlist{$student};
10128: }
10129: if (ref($statushash) eq 'HASH') {
10130: $statushash->{$student}{'st'}{$section} = $status;
10131: }
1.288 raeburn 10132: }
1.275 raeburn 10133: }
10134: }
1.412 raeburn 10135: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 10136: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10137: my $now = time;
1.609 raeburn 10138: my %displaystatus = ( previous => 'Expired',
10139: active => 'Active',
10140: future => 'Future',
10141: );
1.1121 raeburn 10142: my (%nothide,@possdoms);
1.630 raeburn 10143: if ($hidepriv) {
10144: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
10145: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
10146: if ($user !~ /:/) {
10147: $nothide{join(':',split(/[\@]/,$user))}=1;
10148: } else {
10149: $nothide{$user} = 1;
10150: }
10151: }
1.1121 raeburn 10152: my @possdoms = ($cdom);
10153: if ($coursehash{'checkforpriv'}) {
10154: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
10155: }
1.630 raeburn 10156: }
1.439 raeburn 10157: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 10158: my $match = 0;
1.412 raeburn 10159: my $secmatch = 0;
1.439 raeburn 10160: my $status;
1.412 raeburn 10161: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 10162: $user =~ s/:$//;
1.439 raeburn 10163: my ($end,$start) = split(/:/,$coursepersonnel{$person});
10164: if ($end == -1 || $start == -1) {
10165: next;
10166: }
10167: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
10168: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 10169: my ($uname,$udom) = split(/:/,$user);
10170: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 10171: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 10172: $secmatch = 1;
10173: } elsif ($usec eq '') {
1.420 albertel 10174: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 10175: $secmatch = 1;
10176: }
10177: } else {
10178: if (grep(/^\Q$usec\E$/,@{$sections})) {
10179: $secmatch = 1;
10180: }
10181: }
10182: if (!$secmatch) {
10183: next;
10184: }
1.288 raeburn 10185: }
1.419 raeburn 10186: if ($usec eq '') {
10187: $usec = 'none';
10188: }
1.275 raeburn 10189: if ($uname ne '' && $udom ne '') {
1.630 raeburn 10190: if ($hidepriv) {
1.1121 raeburn 10191: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 10192: (!$nothide{$uname.':'.$udom})) {
10193: next;
10194: }
10195: }
1.503 raeburn 10196: if ($end > 0 && $end < $now) {
1.439 raeburn 10197: $status = 'previous';
10198: } elsif ($start > $now) {
10199: $status = 'future';
10200: } else {
10201: $status = 'active';
10202: }
1.277 albertel 10203: foreach my $type (keys(%{$types})) {
1.275 raeburn 10204: if ($status eq $type) {
1.420 albertel 10205: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 10206: push(@{$$users{$role}{$user}},$type);
10207: }
1.288 raeburn 10208: $match = 1;
10209: }
10210: }
1.419 raeburn 10211: if (($match) && (ref($userdata) eq 'HASH')) {
10212: if (!exists($$userdata{$uname.':'.$udom})) {
10213: &get_user_info($udom,$uname,\%idx,$userdata);
10214: }
1.420 albertel 10215: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 10216: push(@{$seclists{$uname.':'.$udom}},$usec);
10217: }
1.609 raeburn 10218: if (ref($statushash) eq 'HASH') {
10219: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
10220: }
1.275 raeburn 10221: }
10222: }
10223: }
10224: }
1.290 albertel 10225: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 10226: if ((defined($cdom)) && (defined($cnum))) {
10227: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
10228: if ( defined($csettings{'internal.courseowner'}) ) {
10229: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 10230: next if ($owner eq '');
10231: my ($ownername,$ownerdom);
10232: if ($owner =~ /^([^:]+):([^:]+)$/) {
10233: $ownername = $1;
10234: $ownerdom = $2;
10235: } else {
10236: $ownername = $owner;
10237: $ownerdom = $cdom;
10238: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 10239: }
10240: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 10241: if (defined($userdata) &&
1.609 raeburn 10242: !exists($$userdata{$owner})) {
10243: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
10244: if (!grep(/^none$/,@{$seclists{$owner}})) {
10245: push(@{$seclists{$owner}},'none');
10246: }
10247: if (ref($statushash) eq 'HASH') {
10248: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 10249: }
1.290 albertel 10250: }
1.279 raeburn 10251: }
10252: }
10253: }
1.419 raeburn 10254: foreach my $user (keys(%seclists)) {
10255: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
10256: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
10257: }
1.275 raeburn 10258: }
10259: return;
10260: }
10261:
1.288 raeburn 10262: sub get_user_info {
10263: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 10264: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
10265: &plainname($uname,$udom,'lastname');
1.291 albertel 10266: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 10267: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 10268: my %idhash = &Apache::lonnet::idrget($udom,($uname));
10269: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 10270: return;
10271: }
1.275 raeburn 10272:
1.472 raeburn 10273: ###############################################
10274:
10275: =pod
10276:
10277: =item * &get_user_quota()
10278:
1.1134 raeburn 10279: Retrieves quota assigned for storage of user files.
10280: Default is to report quota for portfolio files.
1.472 raeburn 10281:
10282: Incoming parameters:
10283: 1. user's username
10284: 2. user's domain
1.1134 raeburn 10285: 3. quota name - portfolio, author, or course
1.1136 raeburn 10286: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 10287: 4. crstype - official, unofficial, textbook, placement or community,
10288: if quota name is course
1.472 raeburn 10289:
10290: Returns:
1.1163 raeburn 10291: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 10292: 2. (Optional) Type of setting: custom or default
10293: (individually assigned or default for user's
10294: institutional status).
10295: 3. (Optional) - User's institutional status (e.g., faculty, staff
10296: or student - types as defined in localenroll::inst_usertypes
10297: for user's domain, which determines default quota for user.
10298: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 10299:
10300: If a value has been stored in the user's environment,
1.536 raeburn 10301: it will return that, otherwise it returns the maximal default
1.1134 raeburn 10302: defined for the user's institutional status(es) in the domain.
1.472 raeburn 10303:
10304: =cut
10305:
10306: ###############################################
10307:
10308:
10309: sub get_user_quota {
1.1136 raeburn 10310: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10311: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10312: if (!defined($udom)) {
10313: $udom = $env{'user.domain'};
10314: }
10315: if (!defined($uname)) {
10316: $uname = $env{'user.name'};
10317: }
10318: if (($udom eq '' || $uname eq '') ||
10319: ($udom eq 'public') && ($uname eq 'public')) {
10320: $quota = 0;
1.536 raeburn 10321: $quotatype = 'default';
10322: $defquota = 0;
1.472 raeburn 10323: } else {
1.536 raeburn 10324: my $inststatus;
1.1134 raeburn 10325: if ($quotaname eq 'course') {
10326: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10327: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10328: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10329: } else {
10330: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10331: $quota = $cenv{'internal.uploadquota'};
10332: }
1.536 raeburn 10333: } else {
1.1134 raeburn 10334: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10335: if ($quotaname eq 'author') {
10336: $quota = $env{'environment.authorquota'};
10337: } else {
10338: $quota = $env{'environment.portfolioquota'};
10339: }
10340: $inststatus = $env{'environment.inststatus'};
10341: } else {
10342: my %userenv =
10343: &Apache::lonnet::get('environment',['portfolioquota',
10344: 'authorquota','inststatus'],$udom,$uname);
10345: my ($tmp) = keys(%userenv);
10346: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10347: if ($quotaname eq 'author') {
10348: $quota = $userenv{'authorquota'};
10349: } else {
10350: $quota = $userenv{'portfolioquota'};
10351: }
10352: $inststatus = $userenv{'inststatus'};
10353: } else {
10354: undef(%userenv);
10355: }
10356: }
10357: }
10358: if ($quota eq '' || wantarray) {
10359: if ($quotaname eq 'course') {
10360: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 10361: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 10362: ($crstype eq 'community') || ($crstype eq 'textbook') ||
10363: ($crstype eq 'placement')) {
1.1136 raeburn 10364: $defquota = $domdefs{$crstype.'quota'};
10365: }
10366: if ($defquota eq '') {
10367: $defquota = 500;
10368: }
1.1134 raeburn 10369: } else {
10370: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10371: }
10372: if ($quota eq '') {
10373: $quota = $defquota;
10374: $quotatype = 'default';
10375: } else {
10376: $quotatype = 'custom';
10377: }
1.472 raeburn 10378: }
10379: }
1.536 raeburn 10380: if (wantarray) {
10381: return ($quota,$quotatype,$settingstatus,$defquota);
10382: } else {
10383: return $quota;
10384: }
1.472 raeburn 10385: }
10386:
10387: ###############################################
10388:
10389: =pod
10390:
10391: =item * &default_quota()
10392:
1.536 raeburn 10393: Retrieves default quota assigned for storage of user portfolio files,
10394: given an (optional) user's institutional status.
1.472 raeburn 10395:
10396: Incoming parameters:
1.1142 raeburn 10397:
1.472 raeburn 10398: 1. domain
1.536 raeburn 10399: 2. (Optional) institutional status(es). This is a : separated list of
10400: status types (e.g., faculty, staff, student etc.)
10401: which apply to the user for whom the default is being retrieved.
10402: If the institutional status string in undefined, the domain
1.1134 raeburn 10403: default quota will be returned.
10404: 3. quota name - portfolio, author, or course
10405: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10406:
10407: Returns:
1.1142 raeburn 10408:
1.1163 raeburn 10409: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10410: 2. (Optional) institutional type which determined the value of the
10411: default quota.
1.472 raeburn 10412:
10413: If a value has been stored in the domain's configuration db,
10414: it will return that, otherwise it returns 20 (for backwards
10415: compatibility with domains which have not set up a configuration
1.1163 raeburn 10416: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10417:
1.536 raeburn 10418: If the user's status includes multiple types (e.g., staff and student),
10419: the largest default quota which applies to the user determines the
10420: default quota returned.
10421:
1.472 raeburn 10422: =cut
10423:
10424: ###############################################
10425:
10426:
10427: sub default_quota {
1.1134 raeburn 10428: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10429: my ($defquota,$settingstatus);
10430: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10431: ['quotas'],$udom);
1.1134 raeburn 10432: my $key = 'defaultquota';
10433: if ($quotaname eq 'author') {
10434: $key = 'authorquota';
10435: }
1.622 raeburn 10436: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10437: if ($inststatus ne '') {
1.765 raeburn 10438: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10439: foreach my $item (@statuses) {
1.1134 raeburn 10440: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10441: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10442: if ($defquota eq '') {
1.1134 raeburn 10443: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10444: $settingstatus = $item;
1.1134 raeburn 10445: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10446: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10447: $settingstatus = $item;
10448: }
10449: }
1.1134 raeburn 10450: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10451: if ($quotahash{'quotas'}{$item} ne '') {
10452: if ($defquota eq '') {
10453: $defquota = $quotahash{'quotas'}{$item};
10454: $settingstatus = $item;
10455: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10456: $defquota = $quotahash{'quotas'}{$item};
10457: $settingstatus = $item;
10458: }
1.536 raeburn 10459: }
10460: }
10461: }
10462: }
10463: if ($defquota eq '') {
1.1134 raeburn 10464: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10465: $defquota = $quotahash{'quotas'}{$key}{'default'};
10466: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10467: $defquota = $quotahash{'quotas'}{'default'};
10468: }
1.536 raeburn 10469: $settingstatus = 'default';
1.1139 raeburn 10470: if ($defquota eq '') {
10471: if ($quotaname eq 'author') {
10472: $defquota = 500;
10473: }
10474: }
1.536 raeburn 10475: }
10476: } else {
10477: $settingstatus = 'default';
1.1134 raeburn 10478: if ($quotaname eq 'author') {
10479: $defquota = 500;
10480: } else {
10481: $defquota = 20;
10482: }
1.536 raeburn 10483: }
10484: if (wantarray) {
10485: return ($defquota,$settingstatus);
1.472 raeburn 10486: } else {
1.536 raeburn 10487: return $defquota;
1.472 raeburn 10488: }
10489: }
10490:
1.1135 raeburn 10491: ###############################################
10492:
10493: =pod
10494:
1.1136 raeburn 10495: =item * &excess_filesize_warning()
1.1135 raeburn 10496:
10497: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 10498: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 10499: space to be exceeded.
1.1136 raeburn 10500:
10501: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 10502: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 10503:
1.1165 raeburn 10504: Inputs: 7
1.1136 raeburn 10505: 1. username or coursenum
1.1135 raeburn 10506: 2. domain
1.1136 raeburn 10507: 3. context ('author' or 'course')
1.1135 raeburn 10508: 4. filename of file for which action is being requested
10509: 5. filesize (kB) of file
10510: 6. action being taken: copy or upload.
1.1237 raeburn 10511: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 10512:
10513: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 10514: otherwise return null.
10515:
10516: =back
1.1135 raeburn 10517:
10518: =cut
10519:
1.1136 raeburn 10520: sub excess_filesize_warning {
1.1165 raeburn 10521: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 10522: my $current_disk_usage = 0;
1.1165 raeburn 10523: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 10524: if ($context eq 'author') {
10525: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10526: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10527: } else {
10528: foreach my $subdir ('docs','supplemental') {
10529: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10530: }
10531: }
1.1135 raeburn 10532: $disk_quota = int($disk_quota * 1000);
10533: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 10534: return '<p class="LC_warning">'.
1.1135 raeburn 10535: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 10536: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10537: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 10538: $disk_quota,$current_disk_usage).
10539: '</p>';
10540: }
10541: return;
10542: }
10543:
10544: ###############################################
10545:
10546:
1.1136 raeburn 10547:
10548:
1.384 raeburn 10549: sub get_secgrprole_info {
10550: my ($cdom,$cnum,$needroles,$type) = @_;
10551: my %sections_count = &get_sections($cdom,$cnum);
10552: my @sections = (sort {$a <=> $b} keys(%sections_count));
10553: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10554: my @groups = sort(keys(%curr_groups));
10555: my $allroles = [];
10556: my $rolehash;
10557: my $accesshash = {
10558: active => 'Currently has access',
10559: future => 'Will have future access',
10560: previous => 'Previously had access',
10561: };
10562: if ($needroles) {
10563: $rolehash = {'all' => 'all'};
1.385 albertel 10564: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10565: if (&Apache::lonnet::error(%user_roles)) {
10566: undef(%user_roles);
10567: }
10568: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10569: my ($role)=split(/\:/,$item,2);
10570: if ($role eq 'cr') { next; }
10571: if ($role =~ /^cr/) {
10572: $$rolehash{$role} = (split('/',$role))[3];
10573: } else {
10574: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10575: }
10576: }
10577: foreach my $key (sort(keys(%{$rolehash}))) {
10578: push(@{$allroles},$key);
10579: }
10580: push (@{$allroles},'st');
10581: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10582: }
10583: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10584: }
10585:
1.555 raeburn 10586: sub user_picker {
1.1279 raeburn 10587: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10588: my $currdom = $dom;
1.1253 raeburn 10589: my @alldoms = &Apache::lonnet::all_domains();
10590: if (@alldoms == 1) {
10591: my %domsrch = &Apache::lonnet::get_dom('configuration',
10592: ['directorysrch'],$alldoms[0]);
10593: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10594: my $showdom = $domdesc;
10595: if ($showdom eq '') {
10596: $showdom = $dom;
10597: }
10598: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10599: if ((!$domsrch{'directorysrch'}{'available'}) &&
10600: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10601: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10602: }
10603: }
10604: }
1.555 raeburn 10605: my %curr_selected = (
10606: srchin => 'dom',
1.580 raeburn 10607: srchby => 'lastname',
1.555 raeburn 10608: );
10609: my $srchterm;
1.625 raeburn 10610: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10611: if ($srch->{'srchby'} ne '') {
10612: $curr_selected{'srchby'} = $srch->{'srchby'};
10613: }
10614: if ($srch->{'srchin'} ne '') {
10615: $curr_selected{'srchin'} = $srch->{'srchin'};
10616: }
10617: if ($srch->{'srchtype'} ne '') {
10618: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10619: }
10620: if ($srch->{'srchdomain'} ne '') {
10621: $currdom = $srch->{'srchdomain'};
10622: }
10623: $srchterm = $srch->{'srchterm'};
10624: }
1.1222 damieng 10625: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10626: 'usr' => 'Search criteria',
1.563 raeburn 10627: 'doma' => 'Domain/institution to search',
1.558 albertel 10628: 'uname' => 'username',
10629: 'lastname' => 'last name',
1.555 raeburn 10630: 'lastfirst' => 'last name, first name',
1.558 albertel 10631: 'crs' => 'in this course',
1.576 raeburn 10632: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10633: 'alc' => 'all LON-CAPA',
1.573 raeburn 10634: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10635: 'exact' => 'is',
10636: 'contains' => 'contains',
1.569 raeburn 10637: 'begins' => 'begins with',
1.1222 damieng 10638: );
10639: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10640: 'youm' => "You must include some text to search for.",
10641: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10642: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10643: 'yomc' => "You must choose a domain when using an institutional directory search.",
10644: 'ymcd' => "You must choose a domain when using a domain search.",
10645: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10646: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10647: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10648: );
1.1222 damieng 10649: &html_escape(\%html_lt);
10650: &js_escape(\%js_lt);
1.1255 raeburn 10651: my $domform;
1.1277 raeburn 10652: my $allow_blank = 1;
1.1255 raeburn 10653: if ($fixeddom) {
1.1277 raeburn 10654: $allow_blank = 0;
10655: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10656: } else {
1.1287 raeburn 10657: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 10658: my ($trusted,$untrusted);
1.1287 raeburn 10659: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 10660: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 10661: } elsif ($context eq 'author') {
1.1288 raeburn 10662: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 10663: } elsif ($context eq 'domain') {
1.1288 raeburn 10664: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 10665: }
1.1288 raeburn 10666: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 10667: }
1.563 raeburn 10668: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10669:
10670: my @srchins = ('crs','dom','alc','instd');
10671:
10672: foreach my $option (@srchins) {
10673: # FIXME 'alc' option unavailable until
10674: # loncreateuser::print_user_query_page()
10675: # has been completed.
10676: next if ($option eq 'alc');
1.880 raeburn 10677: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10678: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 10679: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10680: if ($curr_selected{'srchin'} eq $option) {
10681: $srchinsel .= '
1.1222 damieng 10682: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10683: } else {
10684: $srchinsel .= '
1.1222 damieng 10685: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10686: }
1.555 raeburn 10687: }
1.563 raeburn 10688: $srchinsel .= "\n </select>\n";
1.555 raeburn 10689:
10690: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10691: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10692: if ($curr_selected{'srchby'} eq $option) {
10693: $srchbysel .= '
1.1222 damieng 10694: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10695: } else {
10696: $srchbysel .= '
1.1222 damieng 10697: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10698: }
10699: }
10700: $srchbysel .= "\n </select>\n";
10701:
10702: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10703: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10704: if ($curr_selected{'srchtype'} eq $option) {
10705: $srchtypesel .= '
1.1222 damieng 10706: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10707: } else {
10708: $srchtypesel .= '
1.1222 damieng 10709: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10710: }
10711: }
10712: $srchtypesel .= "\n </select>\n";
10713:
1.558 albertel 10714: my ($newuserscript,$new_user_create);
1.994 raeburn 10715: my $context_dom = $env{'request.role.domain'};
10716: if ($context eq 'requestcrs') {
10717: if ($env{'form.coursedom'} ne '') {
10718: $context_dom = $env{'form.coursedom'};
10719: }
10720: }
1.556 raeburn 10721: if ($forcenewuser) {
1.576 raeburn 10722: if (ref($srch) eq 'HASH') {
1.994 raeburn 10723: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10724: if ($cancreate) {
10725: $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>';
10726: } else {
1.799 bisitz 10727: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10728: my %usertypetext = (
10729: official => 'institutional',
10730: unofficial => 'non-institutional',
10731: );
1.799 bisitz 10732: $new_user_create = '<p class="LC_warning">'
10733: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10734: .' '
10735: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10736: ,'<a href="'.$helplink.'">','</a>')
10737: .'</p><br />';
1.627 raeburn 10738: }
1.576 raeburn 10739: }
10740: }
10741:
1.556 raeburn 10742: $newuserscript = <<"ENDSCRIPT";
10743:
1.570 raeburn 10744: function setSearch(createnew,callingForm) {
1.556 raeburn 10745: if (createnew == 1) {
1.570 raeburn 10746: for (var i=0; i<callingForm.srchby.length; i++) {
10747: if (callingForm.srchby.options[i].value == 'uname') {
10748: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10749: }
10750: }
1.570 raeburn 10751: for (var i=0; i<callingForm.srchin.length; i++) {
10752: if ( callingForm.srchin.options[i].value == 'dom') {
10753: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10754: }
10755: }
1.570 raeburn 10756: for (var i=0; i<callingForm.srchtype.length; i++) {
10757: if (callingForm.srchtype.options[i].value == 'exact') {
10758: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10759: }
10760: }
1.570 raeburn 10761: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10762: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10763: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10764: }
10765: }
10766: }
10767: }
10768: ENDSCRIPT
1.558 albertel 10769:
1.556 raeburn 10770: }
10771:
1.555 raeburn 10772: my $output = <<"END_BLOCK";
1.556 raeburn 10773: <script type="text/javascript">
1.824 bisitz 10774: // <![CDATA[
1.570 raeburn 10775: function validateEntry(callingForm) {
1.558 albertel 10776:
1.556 raeburn 10777: var checkok = 1;
1.558 albertel 10778: var srchin;
1.570 raeburn 10779: for (var i=0; i<callingForm.srchin.length; i++) {
10780: if ( callingForm.srchin[i].checked ) {
10781: srchin = callingForm.srchin[i].value;
1.558 albertel 10782: }
10783: }
10784:
1.570 raeburn 10785: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10786: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10787: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10788: var srchterm = callingForm.srchterm.value;
10789: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10790: var msg = "";
10791:
10792: if (srchterm == "") {
10793: checkok = 0;
1.1222 damieng 10794: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10795: }
10796:
1.569 raeburn 10797: if (srchtype== 'begins') {
10798: if (srchterm.length < 2) {
10799: checkok = 0;
1.1222 damieng 10800: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10801: }
10802: }
10803:
1.556 raeburn 10804: if (srchtype== 'contains') {
10805: if (srchterm.length < 3) {
10806: checkok = 0;
1.1222 damieng 10807: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10808: }
10809: }
10810: if (srchin == 'instd') {
10811: if (srchdomain == '') {
10812: checkok = 0;
1.1222 damieng 10813: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10814: }
10815: }
10816: if (srchin == 'dom') {
10817: if (srchdomain == '') {
10818: checkok = 0;
1.1222 damieng 10819: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10820: }
10821: }
10822: if (srchby == 'lastfirst') {
10823: if (srchterm.indexOf(",") == -1) {
10824: checkok = 0;
1.1222 damieng 10825: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10826: }
10827: if (srchterm.indexOf(",") == srchterm.length -1) {
10828: checkok = 0;
1.1222 damieng 10829: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10830: }
10831: }
10832: if (checkok == 0) {
1.1222 damieng 10833: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10834: return;
10835: }
10836: if (checkok == 1) {
1.570 raeburn 10837: callingForm.submit();
1.556 raeburn 10838: }
10839: }
10840:
10841: $newuserscript
10842:
1.824 bisitz 10843: // ]]>
1.556 raeburn 10844: </script>
1.558 albertel 10845:
10846: $new_user_create
10847:
1.555 raeburn 10848: END_BLOCK
1.558 albertel 10849:
1.876 raeburn 10850: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10851: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10852: $domform.
10853: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10854: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10855: $srchbysel.
10856: $srchtypesel.
10857: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10858: $srchinsel.
10859: &Apache::lonhtmlcommon::row_closure(1).
10860: &Apache::lonhtmlcommon::end_pick_box().
10861: '<br />';
1.1253 raeburn 10862: return ($output,1);
1.555 raeburn 10863: }
10864:
1.612 raeburn 10865: sub user_rule_check {
1.615 raeburn 10866: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10867: my ($response,%inst_response);
1.612 raeburn 10868: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10869: if (keys(%{$usershash}) > 1) {
10870: my (%by_username,%by_id,%userdoms);
10871: my $checkid;
10872: if (ref($checks) eq 'HASH') {
10873: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10874: $checkid = 1;
10875: }
10876: }
10877: foreach my $user (keys(%{$usershash})) {
10878: my ($uname,$udom) = split(/:/,$user);
10879: if ($checkid) {
10880: if (ref($usershash->{$user}) eq 'HASH') {
10881: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10882: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10883: $userdoms{$udom} = 1;
1.1227 raeburn 10884: if (ref($inst_results) eq 'HASH') {
10885: $inst_results->{$uname.':'.$udom} = {};
10886: }
1.1226 raeburn 10887: }
10888: }
10889: } else {
10890: $by_username{$udom}{$uname} = 1;
10891: $userdoms{$udom} = 1;
1.1227 raeburn 10892: if (ref($inst_results) eq 'HASH') {
10893: $inst_results->{$uname.':'.$udom} = {};
10894: }
1.1226 raeburn 10895: }
10896: }
10897: foreach my $udom (keys(%userdoms)) {
10898: if (!$got_rules->{$udom}) {
10899: my %domconfig = &Apache::lonnet::get_dom('configuration',
10900: ['usercreation'],$udom);
10901: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10902: foreach my $item ('username','id') {
10903: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10904: $$curr_rules{$udom}{$item} =
10905: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10906: }
10907: }
10908: }
10909: $got_rules->{$udom} = 1;
10910: }
1.612 raeburn 10911: }
1.1226 raeburn 10912: if ($checkid) {
10913: foreach my $udom (keys(%by_id)) {
10914: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10915: if ($outcome eq 'ok') {
1.1227 raeburn 10916: foreach my $id (keys(%{$by_id{$udom}})) {
10917: my $uname = $by_id{$udom}{$id};
10918: $inst_response{$uname.':'.$udom} = $outcome;
10919: }
1.1226 raeburn 10920: if (ref($results) eq 'HASH') {
10921: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10922: if (exists($inst_response{$uname.':'.$udom})) {
10923: $inst_response{$uname.':'.$udom} = $outcome;
10924: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10925: }
1.1226 raeburn 10926: }
10927: }
10928: }
1.612 raeburn 10929: }
1.615 raeburn 10930: } else {
1.1226 raeburn 10931: foreach my $udom (keys(%by_username)) {
10932: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10933: if ($outcome eq 'ok') {
1.1227 raeburn 10934: foreach my $uname (keys(%{$by_username{$udom}})) {
10935: $inst_response{$uname.':'.$udom} = $outcome;
10936: }
1.1226 raeburn 10937: if (ref($results) eq 'HASH') {
10938: foreach my $uname (keys(%{$results})) {
10939: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10940: }
10941: }
10942: }
10943: }
1.612 raeburn 10944: }
1.1226 raeburn 10945: } elsif (keys(%{$usershash}) == 1) {
10946: my $user = (keys(%{$usershash}))[0];
10947: my ($uname,$udom) = split(/:/,$user);
10948: if (($udom ne '') && ($uname ne '')) {
10949: if (ref($usershash->{$user}) eq 'HASH') {
10950: if (ref($checks) eq 'HASH') {
10951: if (defined($checks->{'username'})) {
10952: ($inst_response{$user},%{$inst_results->{$user}}) =
10953: &Apache::lonnet::get_instuser($udom,$uname);
10954: } elsif (defined($checks->{'id'})) {
10955: if ($usershash->{$user}->{'id'} ne '') {
10956: ($inst_response{$user},%{$inst_results->{$user}}) =
10957: &Apache::lonnet::get_instuser($udom,undef,
10958: $usershash->{$user}->{'id'});
10959: } else {
10960: ($inst_response{$user},%{$inst_results->{$user}}) =
10961: &Apache::lonnet::get_instuser($udom,$uname);
10962: }
1.585 raeburn 10963: }
1.1226 raeburn 10964: } else {
10965: ($inst_response{$user},%{$inst_results->{$user}}) =
10966: &Apache::lonnet::get_instuser($udom,$uname);
10967: return;
10968: }
10969: if (!$got_rules->{$udom}) {
10970: my %domconfig = &Apache::lonnet::get_dom('configuration',
10971: ['usercreation'],$udom);
10972: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10973: foreach my $item ('username','id') {
10974: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10975: $$curr_rules{$udom}{$item} =
10976: $domconfig{'usercreation'}{$item.'_rule'};
10977: }
10978: }
10979: }
10980: $got_rules->{$udom} = 1;
1.585 raeburn 10981: }
10982: }
1.1226 raeburn 10983: } else {
10984: return;
10985: }
10986: } else {
10987: return;
10988: }
10989: foreach my $user (keys(%{$usershash})) {
10990: my ($uname,$udom) = split(/:/,$user);
10991: next if (($udom eq '') || ($uname eq ''));
10992: my $id;
1.1227 raeburn 10993: if (ref($inst_results) eq 'HASH') {
10994: if (ref($inst_results->{$user}) eq 'HASH') {
10995: $id = $inst_results->{$user}->{'id'};
10996: }
10997: }
10998: if ($id eq '') {
10999: if (ref($usershash->{$user})) {
11000: $id = $usershash->{$user}->{'id'};
11001: }
1.585 raeburn 11002: }
1.612 raeburn 11003: foreach my $item (keys(%{$checks})) {
11004: if (ref($$curr_rules{$udom}) eq 'HASH') {
11005: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
11006: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 11007: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
11008: $$curr_rules{$udom}{$item});
1.612 raeburn 11009: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
11010: if ($rule_check{$rule}) {
11011: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 11012: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 11013: if (ref($inst_results) eq 'HASH') {
11014: if (ref($inst_results->{$user}) eq 'HASH') {
11015: if (keys(%{$inst_results->{$user}}) == 0) {
11016: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 11017: } elsif ($item eq 'id') {
11018: if ($inst_results->{$user}->{'id'} eq '') {
11019: $$alerts{$item}{$udom}{$uname} = 1;
11020: }
1.615 raeburn 11021: }
1.612 raeburn 11022: }
11023: }
1.615 raeburn 11024: }
11025: last;
1.585 raeburn 11026: }
11027: }
11028: }
11029: }
11030: }
11031: }
11032: }
11033: }
1.612 raeburn 11034: return;
11035: }
11036:
11037: sub user_rule_formats {
11038: my ($domain,$domdesc,$curr_rules,$check) = @_;
11039: my %text = (
11040: 'username' => 'Usernames',
11041: 'id' => 'IDs',
11042: );
11043: my $output;
11044: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
11045: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
11046: if (@{$ruleorder} > 0) {
1.1102 raeburn 11047: $output = '<br />'.
11048: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
11049: '<span class="LC_cusr_emph">','</span>',$domdesc).
11050: ' <ul>';
1.612 raeburn 11051: foreach my $rule (@{$ruleorder}) {
11052: if (ref($curr_rules) eq 'ARRAY') {
11053: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
11054: if (ref($rules->{$rule}) eq 'HASH') {
11055: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
11056: $rules->{$rule}{'desc'}.'</li>';
11057: }
11058: }
11059: }
11060: }
11061: $output .= '</ul>';
11062: }
11063: }
11064: return $output;
11065: }
11066:
11067: sub instrule_disallow_msg {
1.615 raeburn 11068: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 11069: my $response;
11070: my %text = (
11071: item => 'username',
11072: items => 'usernames',
11073: match => 'matches',
11074: do => 'does',
11075: action => 'a username',
11076: one => 'one',
11077: );
11078: if ($count > 1) {
11079: $text{'item'} = 'usernames';
11080: $text{'match'} ='match';
11081: $text{'do'} = 'do';
11082: $text{'action'} = 'usernames',
11083: $text{'one'} = 'ones';
11084: }
11085: if ($checkitem eq 'id') {
11086: $text{'items'} = 'IDs';
11087: $text{'item'} = 'ID';
11088: $text{'action'} = 'an ID';
1.615 raeburn 11089: if ($count > 1) {
11090: $text{'item'} = 'IDs';
11091: $text{'action'} = 'IDs';
11092: }
1.612 raeburn 11093: }
1.674 bisitz 11094: $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 11095: if ($mode eq 'upload') {
11096: if ($checkitem eq 'username') {
11097: $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'}.");
11098: } elsif ($checkitem eq 'id') {
1.674 bisitz 11099: $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 11100: }
1.669 raeburn 11101: } elsif ($mode eq 'selfcreate') {
11102: if ($checkitem eq 'id') {
11103: $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.");
11104: }
1.615 raeburn 11105: } else {
11106: if ($checkitem eq 'username') {
11107: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
11108: } elsif ($checkitem eq 'id') {
11109: $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.");
11110: }
1.612 raeburn 11111: }
11112: return $response;
1.585 raeburn 11113: }
11114:
1.624 raeburn 11115: sub personal_data_fieldtitles {
11116: my %fieldtitles = &Apache::lonlocal::texthash (
11117: id => 'Student/Employee ID',
11118: permanentemail => 'E-mail address',
11119: lastname => 'Last Name',
11120: firstname => 'First Name',
11121: middlename => 'Middle Name',
11122: generation => 'Generation',
11123: gen => 'Generation',
1.765 raeburn 11124: inststatus => 'Affiliation',
1.624 raeburn 11125: );
11126: return %fieldtitles;
11127: }
11128:
1.642 raeburn 11129: sub sorted_inst_types {
11130: my ($dom) = @_;
1.1185 raeburn 11131: my ($usertypes,$order);
11132: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
11133: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
11134: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
11135: $order = $domdefaults{'inststatus'}{'inststatusorder'};
11136: } else {
11137: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
11138: }
1.642 raeburn 11139: my $othertitle = &mt('All users');
11140: if ($env{'request.course.id'}) {
1.668 raeburn 11141: $othertitle = &mt('Any users');
1.642 raeburn 11142: }
11143: my @types;
11144: if (ref($order) eq 'ARRAY') {
11145: @types = @{$order};
11146: }
11147: if (@types == 0) {
11148: if (ref($usertypes) eq 'HASH') {
11149: @types = sort(keys(%{$usertypes}));
11150: }
11151: }
11152: if (keys(%{$usertypes}) > 0) {
11153: $othertitle = &mt('Other users');
11154: }
11155: return ($othertitle,$usertypes,\@types);
11156: }
11157:
1.645 raeburn 11158: sub get_institutional_codes {
11159: my ($settings,$allcourses,$LC_code) = @_;
11160: # Get complete list of course sections to update
11161: my @currsections = ();
11162: my @currxlists = ();
11163: my $coursecode = $$settings{'internal.coursecode'};
11164:
11165: if ($$settings{'internal.sectionnums'} ne '') {
11166: @currsections = split(/,/,$$settings{'internal.sectionnums'});
11167: }
11168:
11169: if ($$settings{'internal.crosslistings'} ne '') {
11170: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
11171: }
11172:
11173: if (@currxlists > 0) {
11174: foreach (@currxlists) {
11175: if (m/^([^:]+):(\w*)$/) {
11176: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 11177: push(@{$allcourses},$1);
1.645 raeburn 11178: $$LC_code{$1} = $2;
11179: }
11180: }
11181: }
11182: }
11183:
11184: if (@currsections > 0) {
11185: foreach (@currsections) {
11186: if (m/^(\w+):(\w*)$/) {
11187: my $sec = $coursecode.$1;
11188: my $lc_sec = $2;
11189: unless (grep/^$sec$/,@{$allcourses}) {
1.1263 raeburn 11190: push(@{$allcourses},$sec);
1.645 raeburn 11191: $$LC_code{$sec} = $lc_sec;
11192: }
11193: }
11194: }
11195: }
11196: return;
11197: }
11198:
1.971 raeburn 11199: sub get_standard_codeitems {
11200: return ('Year','Semester','Department','Number','Section');
11201: }
11202:
1.112 bowersj2 11203: =pod
11204:
1.780 raeburn 11205: =head1 Slot Helpers
11206:
11207: =over 4
11208:
11209: =item * sorted_slots()
11210:
1.1040 raeburn 11211: Sorts an array of slot names in order of an optional sort key,
11212: default sort is by slot start time (earliest first).
1.780 raeburn 11213:
11214: Inputs:
11215:
11216: =over 4
11217:
11218: slotsarr - Reference to array of unsorted slot names.
11219:
11220: slots - Reference to hash of hash, where outer hash keys are slot names.
11221:
1.1040 raeburn 11222: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
11223:
1.549 albertel 11224: =back
11225:
1.780 raeburn 11226: Returns:
11227:
11228: =over 4
11229:
1.1040 raeburn 11230: sorted - An array of slot names sorted by a specified sort key
11231: (default sort key is start time of the slot).
1.780 raeburn 11232:
11233: =back
11234:
11235: =cut
11236:
11237:
11238: sub sorted_slots {
1.1040 raeburn 11239: my ($slotsarr,$slots,$sortkey) = @_;
11240: if ($sortkey eq '') {
11241: $sortkey = 'starttime';
11242: }
1.780 raeburn 11243: my @sorted;
11244: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
11245: @sorted =
11246: sort {
11247: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 11248: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 11249: }
11250: if (ref($slots->{$a})) { return -1;}
11251: if (ref($slots->{$b})) { return 1;}
11252: return 0;
11253: } @{$slotsarr};
11254: }
11255: return @sorted;
11256: }
11257:
1.1040 raeburn 11258: =pod
11259:
11260: =item * get_future_slots()
11261:
11262: Inputs:
11263:
11264: =over 4
11265:
11266: cnum - course number
11267:
11268: cdom - course domain
11269:
11270: now - current UNIX time
11271:
11272: symb - optional symb
11273:
11274: =back
11275:
11276: Returns:
11277:
11278: =over 4
11279:
11280: sorted_reservable - ref to array of student_schedulable slots currently
11281: reservable, ordered by end date of reservation period.
11282:
11283: reservable_now - ref to hash of student_schedulable slots currently
11284: reservable.
11285:
11286: Keys in inner hash are:
11287: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11288: (b) endreserve: end date of reservation period.
11289: (c) uniqueperiod: start,end dates when slot is to be uniquely
11290: selected.
1.1040 raeburn 11291:
11292: sorted_future - ref to array of student_schedulable slots reservable in
11293: the future, ordered by start date of reservation period.
11294:
11295: future_reservable - ref to hash of student_schedulable slots reservable
11296: in the future.
11297:
11298: Keys in inner hash are:
11299: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 11300: (b) startreserve: start date of reservation period.
11301: (c) uniqueperiod: start,end dates when slot is to be uniquely
11302: selected.
1.1040 raeburn 11303:
11304: =back
11305:
11306: =cut
11307:
11308: sub get_future_slots {
11309: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 11310: my $map;
11311: if ($symb) {
11312: ($map) = &Apache::lonnet::decode_symb($symb);
11313: }
1.1040 raeburn 11314: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11315: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11316: foreach my $slot (keys(%slots)) {
11317: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11318: if ($symb) {
1.1229 raeburn 11319: if ($slots{$slot}->{'symb'} ne '') {
11320: my $canuse;
11321: my %oksymbs;
11322: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
11323: map { $oksymbs{$_} = 1; } @slotsymbs;
11324: if ($oksymbs{$symb}) {
11325: $canuse = 1;
11326: } else {
11327: foreach my $item (@slotsymbs) {
11328: if ($item =~ /\.(page|sequence)$/) {
11329: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
11330: if (($map ne '') && ($map eq $sloturl)) {
11331: $canuse = 1;
11332: last;
11333: }
11334: }
11335: }
11336: }
11337: next unless ($canuse);
11338: }
1.1040 raeburn 11339: }
11340: if (($slots{$slot}->{'starttime'} > $now) &&
11341: ($slots{$slot}->{'endtime'} > $now)) {
11342: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11343: my $userallowed = 0;
11344: if ($slots{$slot}->{'allowedsections'}) {
11345: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11346: if (!defined($env{'request.role.sec'})
11347: && grep(/^No section assigned$/,@allowed_sec)) {
11348: $userallowed=1;
11349: } else {
11350: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11351: $userallowed=1;
11352: }
11353: }
11354: unless ($userallowed) {
11355: if (defined($env{'request.course.groups'})) {
11356: my @groups = split(/:/,$env{'request.course.groups'});
11357: foreach my $group (@groups) {
11358: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11359: $userallowed=1;
11360: last;
11361: }
11362: }
11363: }
11364: }
11365: }
11366: if ($slots{$slot}->{'allowedusers'}) {
11367: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11368: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11369: if (grep(/^\Q$user\E$/,@allowed_users)) {
11370: $userallowed = 1;
11371: }
11372: }
11373: next unless($userallowed);
11374: }
11375: my $startreserve = $slots{$slot}->{'startreserve'};
11376: my $endreserve = $slots{$slot}->{'endreserve'};
11377: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 11378: my $uniqueperiod;
11379: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11380: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11381: }
1.1040 raeburn 11382: if (($startreserve < $now) &&
11383: (!$endreserve || $endreserve > $now)) {
11384: my $lastres = $endreserve;
11385: if (!$lastres) {
11386: $lastres = $slots{$slot}->{'starttime'};
11387: }
11388: $reservable_now{$slot} = {
11389: symb => $symb,
1.1250 raeburn 11390: endreserve => $lastres,
11391: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11392: };
11393: } elsif (($startreserve > $now) &&
11394: (!$endreserve || $endreserve > $startreserve)) {
11395: $future_reservable{$slot} = {
11396: symb => $symb,
1.1250 raeburn 11397: startreserve => $startreserve,
11398: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11399: };
11400: }
11401: }
11402: }
11403: my @unsorted_reservable = keys(%reservable_now);
11404: if (@unsorted_reservable > 0) {
11405: @sorted_reservable =
11406: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11407: }
11408: my @unsorted_future = keys(%future_reservable);
11409: if (@unsorted_future > 0) {
11410: @sorted_future =
11411: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11412: }
11413: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11414: }
1.780 raeburn 11415:
11416: =pod
11417:
1.1057 foxr 11418: =back
11419:
1.549 albertel 11420: =head1 HTTP Helpers
11421:
11422: =over 4
11423:
1.648 raeburn 11424: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11425:
1.258 albertel 11426: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11427: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11428: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11429:
11430: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11431: $possible_names is an ref to an array of form element names. As an example:
11432: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11433: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11434:
11435: =cut
1.1 albertel 11436:
1.6 albertel 11437: sub get_unprocessed_cgi {
1.25 albertel 11438: my ($query,$possible_names)= @_;
1.26 matthew 11439: # $Apache::lonxml::debug=1;
1.356 albertel 11440: foreach my $pair (split(/&/,$query)) {
11441: my ($name, $value) = split(/=/,$pair);
1.369 www 11442: $name = &unescape($name);
1.25 albertel 11443: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11444: $value =~ tr/+/ /;
11445: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11446: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11447: }
1.16 harris41 11448: }
1.6 albertel 11449: }
11450:
1.112 bowersj2 11451: =pod
11452:
1.648 raeburn 11453: =item * &cacheheader()
1.112 bowersj2 11454:
11455: returns cache-controlling header code
11456:
11457: =cut
11458:
1.7 albertel 11459: sub cacheheader {
1.258 albertel 11460: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11461: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11462: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11463: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11464: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11465: return $output;
1.7 albertel 11466: }
11467:
1.112 bowersj2 11468: =pod
11469:
1.648 raeburn 11470: =item * &no_cache($r)
1.112 bowersj2 11471:
11472: specifies header code to not have cache
11473:
11474: =cut
11475:
1.9 albertel 11476: sub no_cache {
1.216 albertel 11477: my ($r) = @_;
11478: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11479: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11480: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11481: $r->no_cache(1);
11482: $r->header_out("Expires" => $date);
11483: $r->header_out("Pragma" => "no-cache");
1.123 www 11484: }
11485:
11486: sub content_type {
1.181 albertel 11487: my ($r,$type,$charset) = @_;
1.299 foxr 11488: if ($r) {
11489: # Note that printout.pl calls this with undef for $r.
11490: &no_cache($r);
11491: }
1.258 albertel 11492: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11493: unless ($charset) {
11494: $charset=&Apache::lonlocal::current_encoding;
11495: }
11496: if ($charset) { $type.='; charset='.$charset; }
11497: if ($r) {
11498: $r->content_type($type);
11499: } else {
11500: print("Content-type: $type\n\n");
11501: }
1.9 albertel 11502: }
1.25 albertel 11503:
1.112 bowersj2 11504: =pod
11505:
1.648 raeburn 11506: =item * &add_to_env($name,$value)
1.112 bowersj2 11507:
1.258 albertel 11508: adds $name to the %env hash with value
1.112 bowersj2 11509: $value, if $name already exists, the entry is converted to an array
11510: reference and $value is added to the array.
11511:
11512: =cut
11513:
1.25 albertel 11514: sub add_to_env {
11515: my ($name,$value)=@_;
1.258 albertel 11516: if (defined($env{$name})) {
11517: if (ref($env{$name})) {
1.25 albertel 11518: #already have multiple values
1.258 albertel 11519: push(@{ $env{$name} },$value);
1.25 albertel 11520: } else {
11521: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11522: my $first=$env{$name};
11523: undef($env{$name});
11524: push(@{ $env{$name} },$first,$value);
1.25 albertel 11525: }
11526: } else {
1.258 albertel 11527: $env{$name}=$value;
1.25 albertel 11528: }
1.31 albertel 11529: }
1.149 albertel 11530:
11531: =pod
11532:
1.648 raeburn 11533: =item * &get_env_multiple($name)
1.149 albertel 11534:
1.258 albertel 11535: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11536: values may be defined and end up as an array ref.
11537:
11538: returns an array of values
11539:
11540: =cut
11541:
11542: sub get_env_multiple {
11543: my ($name) = @_;
11544: my @values;
1.258 albertel 11545: if (defined($env{$name})) {
1.149 albertel 11546: # exists is it an array
1.258 albertel 11547: if (ref($env{$name})) {
11548: @values=@{ $env{$name} };
1.149 albertel 11549: } else {
1.258 albertel 11550: $values[0]=$env{$name};
1.149 albertel 11551: }
11552: }
11553: return(@values);
11554: }
11555:
1.1249 damieng 11556: # Looks at given dependencies, and returns something depending on the context.
11557: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11558: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11559: # For all other contexts, returns ($output, $counter, $numpathchg).
11560: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11561: # $counter: integer with the number of existing dependencies when no HTML output is returned, and the number of missing dependencies when an HTML output is returned.
11562: # $numpathchg: integer with the number of cleaned up dependency paths.
11563: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11564: # \%mapping: hash reference clean path -> original path for all dependencies.
11565: # @param {string} actionurl - The path to the handler, indicative of the context.
11566: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11567: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11568: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11569: # @param {hash reference} args - More parameters ! Possible keys: error_on_invalid_names (boolean), ignore_remote_references (boolean), current_path (string), docs_url (string), docs_title (string), context (string)
11570: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11571: sub ask_for_embedded_content {
1.1249 damieng 11572: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11573: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11574: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11575: %currsubfile,%unused,$rem);
1.1071 raeburn 11576: my $counter = 0;
11577: my $numnew = 0;
1.987 raeburn 11578: my $numremref = 0;
11579: my $numinvalid = 0;
11580: my $numpathchg = 0;
11581: my $numexisting = 0;
1.1071 raeburn 11582: my $numunused = 0;
11583: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11584: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11585: my $heading = &mt('Upload embedded files');
11586: my $buttontext = &mt('Upload');
11587:
1.1249 damieng 11588: # fills these variables based on the context:
11589: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11590: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11591: if ($env{'request.course.id'}) {
1.1123 raeburn 11592: if ($actionurl eq '/adm/dependencies') {
11593: $navmap = Apache::lonnavmaps::navmap->new();
11594: }
11595: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11596: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11597: }
1.1123 raeburn 11598: if (($actionurl eq '/adm/portfolio') ||
11599: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11600: my $current_path='/';
11601: if ($env{'form.currentpath'}) {
11602: $current_path = $env{'form.currentpath'};
11603: }
11604: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11605: $udom = $cdom;
11606: $uname = $cnum;
1.984 raeburn 11607: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11608: } else {
11609: $udom = $env{'user.domain'};
11610: $uname = $env{'user.name'};
11611: $url = '/userfiles/portfolio';
11612: }
1.987 raeburn 11613: $toplevel = $url.'/';
1.984 raeburn 11614: $url .= $current_path;
11615: $getpropath = 1;
1.987 raeburn 11616: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11617: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11618: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11619: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11620: $toplevel = $url;
1.984 raeburn 11621: if ($rest ne '') {
1.987 raeburn 11622: $url .= $rest;
11623: }
11624: } elsif ($actionurl eq '/adm/coursedocs') {
11625: if (ref($args) eq 'HASH') {
1.1071 raeburn 11626: $url = $args->{'docs_url'};
11627: $toplevel = $url;
1.1084 raeburn 11628: if ($args->{'context'} eq 'paste') {
11629: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11630: ($path) =
11631: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11632: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11633: $fileloc =~ s{^/}{};
11634: }
1.1071 raeburn 11635: }
1.1084 raeburn 11636: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11637: if ($env{'request.course.id'} ne '') {
11638: if (ref($args) eq 'HASH') {
11639: $url = $args->{'docs_url'};
11640: $title = $args->{'docs_title'};
1.1126 raeburn 11641: $toplevel = $url;
11642: unless ($toplevel =~ m{^/}) {
11643: $toplevel = "/$url";
11644: }
1.1085 raeburn 11645: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11646: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11647: $path = $1;
11648: } else {
11649: ($path) =
11650: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11651: }
1.1195 raeburn 11652: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11653: $fileloc = $toplevel;
11654: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11655: my ($udom,$uname,$fname) =
11656: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11657: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11658: } else {
11659: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11660: }
1.1071 raeburn 11661: $fileloc =~ s{^/}{};
11662: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11663: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11664: }
1.987 raeburn 11665: }
1.1123 raeburn 11666: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11667: $udom = $cdom;
11668: $uname = $cnum;
11669: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11670: $toplevel = $url;
11671: $path = $url;
11672: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11673: $fileloc =~ s{^/}{};
1.987 raeburn 11674: }
1.1249 damieng 11675:
11676: # parses the dependency paths to get some info
11677: # fills $newfiles, $mapping, $subdependencies, $dependencies
11678: # $newfiles: hash URL -> 1 for new files or external URLs
11679: # (will be completed later)
11680: # $mapping:
11681: # for external URLs: external URL -> external URL
11682: # for relative paths: clean path -> original path
11683: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11684: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11685: foreach my $file (keys(%{$allfiles})) {
11686: my $embed_file;
11687: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11688: $embed_file = $1;
11689: } else {
11690: $embed_file = $file;
11691: }
1.1158 raeburn 11692: my ($absolutepath,$cleaned_file);
11693: if ($embed_file =~ m{^\w+://}) {
11694: $cleaned_file = $embed_file;
1.1147 raeburn 11695: $newfiles{$cleaned_file} = 1;
11696: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11697: } else {
1.1158 raeburn 11698: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11699: if ($embed_file =~ m{^/}) {
11700: $absolutepath = $embed_file;
11701: }
1.1147 raeburn 11702: if ($cleaned_file =~ m{/}) {
11703: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11704: $path = &check_for_traversal($path,$url,$toplevel);
11705: my $item = $fname;
11706: if ($path ne '') {
11707: $item = $path.'/'.$fname;
11708: $subdependencies{$path}{$fname} = 1;
11709: } else {
11710: $dependencies{$item} = 1;
11711: }
11712: if ($absolutepath) {
11713: $mapping{$item} = $absolutepath;
11714: } else {
11715: $mapping{$item} = $embed_file;
11716: }
11717: } else {
11718: $dependencies{$embed_file} = 1;
11719: if ($absolutepath) {
1.1147 raeburn 11720: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11721: } else {
1.1147 raeburn 11722: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11723: }
11724: }
1.984 raeburn 11725: }
11726: }
1.1249 damieng 11727:
11728: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11729: # and lists
11730: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11731: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11732: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11733: # the path had to be cleaned up
11734: # $existing: hash clean path -> 1 if the file exists
11735: # $numexisting: number of keys in $existing
11736: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11737: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11738: # dependency subdirectories that are
11739: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11740: my $dirptr = 16384;
1.984 raeburn 11741: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11742: $currsubfile{$path} = {};
1.1123 raeburn 11743: if (($actionurl eq '/adm/portfolio') ||
11744: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11745: my ($sublistref,$listerror) =
11746: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11747: if (ref($sublistref) eq 'ARRAY') {
11748: foreach my $line (@{$sublistref}) {
11749: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11750: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11751: }
1.984 raeburn 11752: }
1.987 raeburn 11753: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11754: if (opendir(my $dir,$url.'/'.$path)) {
11755: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11756: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11757: }
1.1084 raeburn 11758: } elsif (($actionurl eq '/adm/dependencies') ||
11759: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11760: ($args->{'context'} eq 'paste')) ||
11761: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11762: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11763: my $dir;
11764: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11765: $dir = $fileloc;
11766: } else {
11767: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11768: }
1.1071 raeburn 11769: if ($dir ne '') {
11770: my ($sublistref,$listerror) =
11771: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11772: if (ref($sublistref) eq 'ARRAY') {
11773: foreach my $line (@{$sublistref}) {
11774: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11775: undef,$mtime)=split(/\&/,$line,12);
11776: unless (($testdir&$dirptr) ||
11777: ($file_name =~ /^\.\.?$/)) {
11778: $currsubfile{$path}{$file_name} = [$size,$mtime];
11779: }
11780: }
11781: }
11782: }
1.984 raeburn 11783: }
11784: }
11785: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11786: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11787: my $item = $path.'/'.$file;
11788: unless ($mapping{$item} eq $item) {
11789: $pathchanges{$item} = 1;
11790: }
11791: $existing{$item} = 1;
11792: $numexisting ++;
11793: } else {
11794: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11795: }
11796: }
1.1071 raeburn 11797: if ($actionurl eq '/adm/dependencies') {
11798: foreach my $path (keys(%currsubfile)) {
11799: if (ref($currsubfile{$path}) eq 'HASH') {
11800: foreach my $file (keys(%{$currsubfile{$path}})) {
11801: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11802: next if (($rem ne '') &&
11803: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11804: (ref($navmap) &&
11805: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11806: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11807: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11808: $unused{$path.'/'.$file} = 1;
11809: }
11810: }
11811: }
11812: }
11813: }
1.984 raeburn 11814: }
1.1249 damieng 11815:
11816: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11817: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11818: my %currfile;
1.1123 raeburn 11819: if (($actionurl eq '/adm/portfolio') ||
11820: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11821: my ($dirlistref,$listerror) =
11822: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11823: if (ref($dirlistref) eq 'ARRAY') {
11824: foreach my $line (@{$dirlistref}) {
11825: my ($file_name,$rest) = split(/\&/,$line,2);
11826: $currfile{$file_name} = 1;
11827: }
1.984 raeburn 11828: }
1.987 raeburn 11829: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11830: if (opendir(my $dir,$url)) {
1.987 raeburn 11831: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11832: map {$currfile{$_} = 1;} @dir_list;
11833: }
1.1084 raeburn 11834: } elsif (($actionurl eq '/adm/dependencies') ||
11835: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11836: ($args->{'context'} eq 'paste')) ||
11837: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11838: if ($env{'request.course.id'} ne '') {
11839: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11840: if ($dir ne '') {
11841: my ($dirlistref,$listerror) =
11842: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11843: if (ref($dirlistref) eq 'ARRAY') {
11844: foreach my $line (@{$dirlistref}) {
11845: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11846: $size,undef,$mtime)=split(/\&/,$line,12);
11847: unless (($testdir&$dirptr) ||
11848: ($file_name =~ /^\.\.?$/)) {
11849: $currfile{$file_name} = [$size,$mtime];
11850: }
11851: }
11852: }
11853: }
11854: }
1.984 raeburn 11855: }
1.1249 damieng 11856: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11857: # are not in subdirectories, using $currfile
1.984 raeburn 11858: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11859: if (exists($currfile{$file})) {
1.987 raeburn 11860: unless ($mapping{$file} eq $file) {
11861: $pathchanges{$file} = 1;
11862: }
11863: $existing{$file} = 1;
11864: $numexisting ++;
11865: } else {
1.984 raeburn 11866: $newfiles{$file} = 1;
11867: }
11868: }
1.1071 raeburn 11869: foreach my $file (keys(%currfile)) {
11870: unless (($file eq $filename) ||
11871: ($file eq $filename.'.bak') ||
11872: ($dependencies{$file})) {
1.1085 raeburn 11873: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11874: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11875: next if (($rem ne '') &&
11876: (($env{"httpref.$rem".$file} ne '') ||
11877: (ref($navmap) &&
11878: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11879: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11880: ($navmap->getResourceByUrl($rem.$1)))))));
11881: }
1.1085 raeburn 11882: }
1.1071 raeburn 11883: $unused{$file} = 1;
11884: }
11885: }
1.1249 damieng 11886:
11887: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11888: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11889: ($args->{'context'} eq 'paste')) {
11890: $counter = scalar(keys(%existing));
11891: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11892: return ($output,$counter,$numpathchg,\%existing);
11893: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11894: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11895: $counter = scalar(keys(%existing));
11896: $numpathchg = scalar(keys(%pathchanges));
11897: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11898: }
1.1249 damieng 11899:
11900: # returns HTML otherwise, with dependency results and to ask for more uploads
11901:
11902: # $upload_output: missing dependencies (with upload form)
11903: # $modify_output: uploaded dependencies (in use)
11904: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11905: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11906: if ($actionurl eq '/adm/dependencies') {
11907: next if ($embed_file =~ m{^\w+://});
11908: }
1.660 raeburn 11909: $upload_output .= &start_data_table_row().
1.1123 raeburn 11910: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11911: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11912: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11913: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11914: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11915: }
1.1123 raeburn 11916: $upload_output .= '</td>';
1.1071 raeburn 11917: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11918: $upload_output.='<td align="right">'.
11919: '<span class="LC_info LC_fontsize_medium">'.
11920: &mt("URL points to web address").'</span>';
1.987 raeburn 11921: $numremref++;
1.660 raeburn 11922: } elsif ($args->{'error_on_invalid_names'}
11923: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11924: $upload_output.='<td align="right"><span class="LC_warning">'.
11925: &mt('Invalid characters').'</span>';
1.987 raeburn 11926: $numinvalid++;
1.660 raeburn 11927: } else {
1.1123 raeburn 11928: $upload_output .= '<td>'.
11929: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11930: $embed_file,\%mapping,
1.1071 raeburn 11931: $allfiles,$codebase,'upload');
11932: $counter ++;
11933: $numnew ++;
1.987 raeburn 11934: }
11935: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11936: }
11937: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11938: if ($actionurl eq '/adm/dependencies') {
11939: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11940: $modify_output .= &start_data_table_row().
11941: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11942: '<img src="'.&icon($embed_file).'" border="0" />'.
11943: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11944: '<td>'.$size.'</td>'.
11945: '<td>'.$mtime.'</td>'.
11946: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11947: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11948: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11949: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11950: &embedded_file_element('upload_embedded',$counter,
11951: $embed_file,\%mapping,
11952: $allfiles,$codebase,'modify').
11953: '</div></td>'.
11954: &end_data_table_row()."\n";
11955: $counter ++;
11956: } else {
11957: $upload_output .= &start_data_table_row().
1.1123 raeburn 11958: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11959: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11960: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11961: &Apache::loncommon::end_data_table_row()."\n";
11962: }
11963: }
11964: my $delidx = $counter;
11965: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11966: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11967: $delete_output .= &start_data_table_row().
11968: '<td><img src="'.&icon($oldfile).'" />'.
11969: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11970: '<td>'.$size.'</td>'.
11971: '<td>'.$mtime.'</td>'.
11972: '<td><label><input type="checkbox" name="del_upload_dep" '.
11973: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11974: &embedded_file_element('upload_embedded',$delidx,
11975: $oldfile,\%mapping,$allfiles,
11976: $codebase,'delete').'</td>'.
11977: &end_data_table_row()."\n";
11978: $numunused ++;
11979: $delidx ++;
1.987 raeburn 11980: }
11981: if ($upload_output) {
11982: $upload_output = &start_data_table().
11983: $upload_output.
11984: &end_data_table()."\n";
11985: }
1.1071 raeburn 11986: if ($modify_output) {
11987: $modify_output = &start_data_table().
11988: &start_data_table_header_row().
11989: '<th>'.&mt('File').'</th>'.
11990: '<th>'.&mt('Size (KB)').'</th>'.
11991: '<th>'.&mt('Modified').'</th>'.
11992: '<th>'.&mt('Upload replacement?').'</th>'.
11993: &end_data_table_header_row().
11994: $modify_output.
11995: &end_data_table()."\n";
11996: }
11997: if ($delete_output) {
11998: $delete_output = &start_data_table().
11999: &start_data_table_header_row().
12000: '<th>'.&mt('File').'</th>'.
12001: '<th>'.&mt('Size (KB)').'</th>'.
12002: '<th>'.&mt('Modified').'</th>'.
12003: '<th>'.&mt('Delete?').'</th>'.
12004: &end_data_table_header_row().
12005: $delete_output.
12006: &end_data_table()."\n";
12007: }
1.987 raeburn 12008: my $applies = 0;
12009: if ($numremref) {
12010: $applies ++;
12011: }
12012: if ($numinvalid) {
12013: $applies ++;
12014: }
12015: if ($numexisting) {
12016: $applies ++;
12017: }
1.1071 raeburn 12018: if ($counter || $numunused) {
1.987 raeburn 12019: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
12020: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 12021: $state.'<h3>'.$heading.'</h3>';
12022: if ($actionurl eq '/adm/dependencies') {
12023: if ($numnew) {
12024: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
12025: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
12026: $upload_output.'<br />'."\n";
12027: }
12028: if ($numexisting) {
12029: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
12030: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
12031: $modify_output.'<br />'."\n";
12032: $buttontext = &mt('Save changes');
12033: }
12034: if ($numunused) {
12035: $output .= '<h4>'.&mt('Unused files').'</h4>'.
12036: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
12037: $delete_output.'<br />'."\n";
12038: $buttontext = &mt('Save changes');
12039: }
12040: } else {
12041: $output .= $upload_output.'<br />'."\n";
12042: }
12043: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
12044: $counter.'" />'."\n";
12045: if ($actionurl eq '/adm/dependencies') {
12046: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
12047: $numnew.'" />'."\n";
12048: } elsif ($actionurl eq '') {
1.987 raeburn 12049: $output .= '<input type="hidden" name="phase" value="three" />';
12050: }
12051: } elsif ($applies) {
12052: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
12053: if ($applies > 1) {
12054: $output .=
1.1123 raeburn 12055: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 12056: if ($numremref) {
12057: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
12058: }
12059: if ($numinvalid) {
12060: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
12061: }
12062: if ($numexisting) {
12063: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
12064: }
12065: $output .= '</ul><br />';
12066: } elsif ($numremref) {
12067: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
12068: } elsif ($numinvalid) {
12069: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
12070: } elsif ($numexisting) {
12071: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
12072: }
12073: $output .= $upload_output.'<br />';
12074: }
12075: my ($pathchange_output,$chgcount);
1.1071 raeburn 12076: $chgcount = $counter;
1.987 raeburn 12077: if (keys(%pathchanges) > 0) {
12078: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 12079: if ($counter) {
1.987 raeburn 12080: $output .= &embedded_file_element('pathchange',$chgcount,
12081: $embed_file,\%mapping,
1.1071 raeburn 12082: $allfiles,$codebase,'change');
1.987 raeburn 12083: } else {
12084: $pathchange_output .=
12085: &start_data_table_row().
12086: '<td><input type ="checkbox" name="namechange" value="'.
12087: $chgcount.'" checked="checked" /></td>'.
12088: '<td>'.$mapping{$embed_file}.'</td>'.
12089: '<td>'.$embed_file.
12090: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 12091: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 12092: '</td>'.&end_data_table_row();
1.660 raeburn 12093: }
1.987 raeburn 12094: $numpathchg ++;
12095: $chgcount ++;
1.660 raeburn 12096: }
12097: }
1.1127 raeburn 12098: if (($counter) || ($numunused)) {
1.987 raeburn 12099: if ($numpathchg) {
12100: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
12101: $numpathchg.'" />'."\n";
12102: }
12103: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
12104: ($actionurl eq '/adm/imsimport')) {
12105: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
12106: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
12107: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 12108: } elsif ($actionurl eq '/adm/dependencies') {
12109: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 12110: }
1.1123 raeburn 12111: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 12112: } elsif ($numpathchg) {
12113: my %pathchange = ();
12114: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
12115: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12116: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 12117: }
1.987 raeburn 12118: }
1.1071 raeburn 12119: return ($output,$counter,$numpathchg);
1.987 raeburn 12120: }
12121:
1.1147 raeburn 12122: =pod
12123:
12124: =item * clean_path($name)
12125:
12126: Performs clean-up of directories, subdirectories and filename in an
12127: embedded object, referenced in an HTML file which is being uploaded
12128: to a course or portfolio, where
12129: "Upload embedded images/multimedia files if HTML file" checkbox was
12130: checked.
12131:
12132: Clean-up is similar to replacements in lonnet::clean_filename()
12133: except each / between sub-directory and next level is preserved.
12134:
12135: =cut
12136:
12137: sub clean_path {
12138: my ($embed_file) = @_;
12139: $embed_file =~s{^/+}{};
12140: my @contents;
12141: if ($embed_file =~ m{/}) {
12142: @contents = split(/\//,$embed_file);
12143: } else {
12144: @contents = ($embed_file);
12145: }
12146: my $lastidx = scalar(@contents)-1;
12147: for (my $i=0; $i<=$lastidx; $i++) {
12148: $contents[$i]=~s{\\}{/}g;
12149: $contents[$i]=~s/\s+/\_/g;
12150: $contents[$i]=~s{[^/\w\.\-]}{}g;
12151: if ($i == $lastidx) {
12152: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
12153: }
12154: }
12155: if ($lastidx > 0) {
12156: return join('/',@contents);
12157: } else {
12158: return $contents[0];
12159: }
12160: }
12161:
1.987 raeburn 12162: sub embedded_file_element {
1.1071 raeburn 12163: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 12164: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
12165: (ref($codebase) eq 'HASH'));
12166: my $output;
1.1071 raeburn 12167: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 12168: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
12169: }
12170: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
12171: &escape($embed_file).'" />';
12172: unless (($context eq 'upload_embedded') &&
12173: ($mapping->{$embed_file} eq $embed_file)) {
12174: $output .='
12175: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
12176: }
12177: my $attrib;
12178: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
12179: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
12180: }
12181: $output .=
12182: "\n\t\t".
12183: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
12184: $attrib.'" />';
12185: if (exists($codebase->{$mapping->{$embed_file}})) {
12186: $output .=
12187: "\n\t\t".
12188: '<input name="codebase_'.$num.'" type="hidden" value="'.
12189: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 12190: }
1.987 raeburn 12191: return $output;
1.660 raeburn 12192: }
12193:
1.1071 raeburn 12194: sub get_dependency_details {
12195: my ($currfile,$currsubfile,$embed_file) = @_;
12196: my ($size,$mtime,$showsize,$showmtime);
12197: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
12198: if ($embed_file =~ m{/}) {
12199: my ($path,$fname) = split(/\//,$embed_file);
12200: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
12201: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
12202: }
12203: } else {
12204: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
12205: ($size,$mtime) = @{$currfile->{$embed_file}};
12206: }
12207: }
12208: $showsize = $size/1024.0;
12209: $showsize = sprintf("%.1f",$showsize);
12210: if ($mtime > 0) {
12211: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
12212: }
12213: }
12214: return ($showsize,$showmtime);
12215: }
12216:
12217: sub ask_embedded_js {
12218: return <<"END";
12219: <script type="text/javascript"">
12220: // <![CDATA[
12221: function toggleBrowse(counter) {
12222: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
12223: var fileid = document.getElementById('embedded_item_'+counter);
12224: var uploaddivid = document.getElementById('moduploaddep_'+counter);
12225: if (chkboxid.checked == true) {
12226: uploaddivid.style.display='block';
12227: } else {
12228: uploaddivid.style.display='none';
12229: fileid.value = '';
12230: }
12231: }
12232: // ]]>
12233: </script>
12234:
12235: END
12236: }
12237:
1.661 raeburn 12238: sub upload_embedded {
12239: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 12240: $current_disk_usage,$hiddenstate,$actionurl) = @_;
12241: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 12242: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
12243: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
12244: my $orig_uploaded_filename =
12245: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 12246: foreach my $type ('orig','ref','attrib','codebase') {
12247: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
12248: $env{'form.embedded_'.$type.'_'.$i} =
12249: &unescape($env{'form.embedded_'.$type.'_'.$i});
12250: }
12251: }
1.661 raeburn 12252: my ($path,$fname) =
12253: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
12254: # no path, whole string is fname
12255: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
12256: $fname = &Apache::lonnet::clean_filename($fname);
12257: # See if there is anything left
12258: next if ($fname eq '');
12259:
12260: # Check if file already exists as a file or directory.
12261: my ($state,$msg);
12262: if ($context eq 'portfolio') {
12263: my $port_path = $dirpath;
12264: if ($group ne '') {
12265: $port_path = "groups/$group/$port_path";
12266: }
1.987 raeburn 12267: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
12268: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 12269: $dir_root,$port_path,$disk_quota,
12270: $current_disk_usage,$uname,$udom);
12271: if ($state eq 'will_exceed_quota'
1.984 raeburn 12272: || $state eq 'file_locked') {
1.661 raeburn 12273: $output .= $msg;
12274: next;
12275: }
12276: } elsif (($context eq 'author') || ($context eq 'testbank')) {
12277: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
12278: if ($state eq 'exists') {
12279: $output .= $msg;
12280: next;
12281: }
12282: }
12283: # Check if extension is valid
12284: if (($fname =~ /\.(\w+)$/) &&
12285: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 12286: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
12287: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 12288: next;
12289: } elsif (($fname =~ /\.(\w+)$/) &&
12290: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 12291: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 12292: next;
12293: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 12294: $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 12295: next;
12296: }
12297: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 12298: my $subdir = $path;
12299: $subdir =~ s{/+$}{};
1.661 raeburn 12300: if ($context eq 'portfolio') {
1.984 raeburn 12301: my $result;
12302: if ($state eq 'existingfile') {
12303: $result=
12304: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 12305: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 12306: } else {
1.984 raeburn 12307: $result=
12308: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12309: $dirpath.
1.1123 raeburn 12310: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12311: if ($result !~ m|^/uploaded/|) {
12312: $output .= '<span class="LC_error">'
12313: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12314: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12315: .'</span><br />';
12316: next;
12317: } else {
1.987 raeburn 12318: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12319: $path.$fname.'</span>').'<br />';
1.984 raeburn 12320: }
1.661 raeburn 12321: }
1.1123 raeburn 12322: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 12323: my $extendedsubdir = $dirpath.'/'.$subdir;
12324: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12325: my $result =
1.1126 raeburn 12326: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12327: if ($result !~ m|^/uploaded/|) {
12328: $output .= '<span class="LC_error">'
12329: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12330: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12331: .'</span><br />';
12332: next;
12333: } else {
12334: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12335: $path.$fname.'</span>').'<br />';
1.1125 raeburn 12336: if ($context eq 'syllabus') {
12337: &Apache::lonnet::make_public_indefinitely($result);
12338: }
1.987 raeburn 12339: }
1.661 raeburn 12340: } else {
12341: # Save the file
12342: my $target = $env{'form.embedded_item_'.$i};
12343: my $fullpath = $dir_root.$dirpath.'/'.$path;
12344: my $dest = $fullpath.$fname;
12345: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12346: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12347: my $count;
12348: my $filepath = $dir_root;
1.1027 raeburn 12349: foreach my $subdir (@parts) {
12350: $filepath .= "/$subdir";
12351: if (!-e $filepath) {
1.661 raeburn 12352: mkdir($filepath,0770);
12353: }
12354: }
12355: my $fh;
12356: if (!open($fh,'>'.$dest)) {
12357: &Apache::lonnet::logthis('Failed to create '.$dest);
12358: $output .= '<span class="LC_error">'.
1.1071 raeburn 12359: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12360: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12361: '</span><br />';
12362: } else {
12363: if (!print $fh $env{'form.embedded_item_'.$i}) {
12364: &Apache::lonnet::logthis('Failed to write to '.$dest);
12365: $output .= '<span class="LC_error">'.
1.1071 raeburn 12366: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12367: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12368: '</span><br />';
12369: } else {
1.987 raeburn 12370: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12371: $url.'</span>').'<br />';
12372: unless ($context eq 'testbank') {
12373: $footer .= &mt('View embedded file: [_1]',
12374: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12375: }
12376: }
12377: close($fh);
12378: }
12379: }
12380: if ($env{'form.embedded_ref_'.$i}) {
12381: $pathchange{$i} = 1;
12382: }
12383: }
12384: if ($output) {
12385: $output = '<p>'.$output.'</p>';
12386: }
12387: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12388: $returnflag = 'ok';
1.1071 raeburn 12389: my $numpathchgs = scalar(keys(%pathchange));
12390: if ($numpathchgs > 0) {
1.987 raeburn 12391: if ($context eq 'portfolio') {
12392: $output .= '<p>'.&mt('or').'</p>';
12393: } elsif ($context eq 'testbank') {
1.1071 raeburn 12394: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12395: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12396: $returnflag = 'modify_orightml';
12397: }
12398: }
1.1071 raeburn 12399: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12400: }
12401:
12402: sub modify_html_form {
12403: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12404: my $end = 0;
12405: my $modifyform;
12406: if ($context eq 'upload_embedded') {
12407: return unless (ref($pathchange) eq 'HASH');
12408: if ($env{'form.number_embedded_items'}) {
12409: $end += $env{'form.number_embedded_items'};
12410: }
12411: if ($env{'form.number_pathchange_items'}) {
12412: $end += $env{'form.number_pathchange_items'};
12413: }
12414: if ($end) {
12415: for (my $i=0; $i<$end; $i++) {
12416: if ($i < $env{'form.number_embedded_items'}) {
12417: next unless($pathchange->{$i});
12418: }
12419: $modifyform .=
12420: &start_data_table_row().
12421: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12422: 'checked="checked" /></td>'.
12423: '<td>'.$env{'form.embedded_ref_'.$i}.
12424: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12425: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12426: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12427: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12428: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12429: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12430: '<td>'.$env{'form.embedded_orig_'.$i}.
12431: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12432: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12433: &end_data_table_row();
1.1071 raeburn 12434: }
1.987 raeburn 12435: }
12436: } else {
12437: $modifyform = $pathchgtable;
12438: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12439: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12440: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12441: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12442: }
12443: }
12444: if ($modifyform) {
1.1071 raeburn 12445: if ($actionurl eq '/adm/dependencies') {
12446: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12447: }
1.987 raeburn 12448: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12449: '<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".
12450: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12451: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12452: '</ol></p>'."\n".'<p>'.
12453: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12454: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12455: &start_data_table()."\n".
12456: &start_data_table_header_row().
12457: '<th>'.&mt('Change?').'</th>'.
12458: '<th>'.&mt('Current reference').'</th>'.
12459: '<th>'.&mt('Required reference').'</th>'.
12460: &end_data_table_header_row()."\n".
12461: $modifyform.
12462: &end_data_table().'<br />'."\n".$hiddenstate.
12463: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12464: '</form>'."\n";
12465: }
12466: return;
12467: }
12468:
12469: sub modify_html_refs {
1.1123 raeburn 12470: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12471: my $container;
12472: if ($context eq 'portfolio') {
12473: $container = $env{'form.container'};
12474: } elsif ($context eq 'coursedoc') {
12475: $container = $env{'form.primaryurl'};
1.1071 raeburn 12476: } elsif ($context eq 'manage_dependencies') {
12477: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12478: $container = "/$container";
1.1123 raeburn 12479: } elsif ($context eq 'syllabus') {
12480: $container = $url;
1.987 raeburn 12481: } else {
1.1027 raeburn 12482: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12483: }
12484: my (%allfiles,%codebase,$output,$content);
12485: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 12486: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12487: if (wantarray) {
12488: return ('',0,0);
12489: } else {
12490: return;
12491: }
12492: }
12493: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12494: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12495: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12496: if (wantarray) {
12497: return ('',0,0);
12498: } else {
12499: return;
12500: }
12501: }
1.987 raeburn 12502: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12503: if ($content eq '-1') {
12504: if (wantarray) {
12505: return ('',0,0);
12506: } else {
12507: return;
12508: }
12509: }
1.987 raeburn 12510: } else {
1.1071 raeburn 12511: unless ($container =~ /^\Q$dir_root\E/) {
12512: if (wantarray) {
12513: return ('',0,0);
12514: } else {
12515: return;
12516: }
12517: }
1.1317 raeburn 12518: if (open(my $fh,'<',$container)) {
1.987 raeburn 12519: $content = join('', <$fh>);
12520: close($fh);
12521: } else {
1.1071 raeburn 12522: if (wantarray) {
12523: return ('',0,0);
12524: } else {
12525: return;
12526: }
1.987 raeburn 12527: }
12528: }
12529: my ($count,$codebasecount) = (0,0);
12530: my $mm = new File::MMagic;
12531: my $mime_type = $mm->checktype_contents($content);
12532: if ($mime_type eq 'text/html') {
12533: my $parse_result =
12534: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12535: \%codebase,\$content);
12536: if ($parse_result eq 'ok') {
12537: foreach my $i (@changes) {
12538: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12539: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12540: if ($allfiles{$ref}) {
12541: my $newname = $orig;
12542: my ($attrib_regexp,$codebase);
1.1006 raeburn 12543: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12544: if ($attrib_regexp =~ /:/) {
12545: $attrib_regexp =~ s/\:/|/g;
12546: }
12547: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12548: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12549: $count += $numchg;
1.1123 raeburn 12550: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12551: delete($allfiles{$ref});
1.987 raeburn 12552: }
12553: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12554: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12555: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12556: $codebasecount ++;
12557: }
12558: }
12559: }
1.1123 raeburn 12560: my $skiprewrites;
1.987 raeburn 12561: if ($count || $codebasecount) {
12562: my $saveresult;
1.1071 raeburn 12563: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12564: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12565: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12566: if ($url eq $container) {
12567: my ($fname) = ($container =~ m{/([^/]+)$});
12568: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12569: $count,'<span class="LC_filename">'.
1.1071 raeburn 12570: $fname.'</span>').'</p>';
1.987 raeburn 12571: } else {
12572: $output = '<p class="LC_error">'.
12573: &mt('Error: update failed for: [_1].',
12574: '<span class="LC_filename">'.
12575: $container.'</span>').'</p>';
12576: }
1.1123 raeburn 12577: if ($context eq 'syllabus') {
12578: unless ($saveresult eq 'ok') {
12579: $skiprewrites = 1;
12580: }
12581: }
1.987 raeburn 12582: } else {
1.1317 raeburn 12583: if (open(my $fh,'>',$container)) {
1.987 raeburn 12584: print $fh $content;
12585: close($fh);
12586: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12587: $count,'<span class="LC_filename">'.
12588: $container.'</span>').'</p>';
1.661 raeburn 12589: } else {
1.987 raeburn 12590: $output = '<p class="LC_error">'.
12591: &mt('Error: could not update [_1].',
12592: '<span class="LC_filename">'.
12593: $container.'</span>').'</p>';
1.661 raeburn 12594: }
12595: }
12596: }
1.1123 raeburn 12597: if (($context eq 'syllabus') && (!$skiprewrites)) {
12598: my ($actionurl,$state);
12599: $actionurl = "/public/$udom/$uname/syllabus";
12600: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12601: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12602: \%codebase,
12603: {'context' => 'rewrites',
12604: 'ignore_remote_references' => 1,});
12605: if (ref($mapping) eq 'HASH') {
12606: my $rewrites = 0;
12607: foreach my $key (keys(%{$mapping})) {
12608: next if ($key =~ m{^https?://});
12609: my $ref = $mapping->{$key};
12610: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12611: my $attrib;
12612: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12613: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12614: }
12615: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12616: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12617: $rewrites += $numchg;
12618: }
12619: }
12620: if ($rewrites) {
12621: my $saveresult;
12622: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12623: if ($url eq $container) {
12624: my ($fname) = ($container =~ m{/([^/]+)$});
12625: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12626: $count,'<span class="LC_filename">'.
12627: $fname.'</span>').'</p>';
12628: } else {
12629: $output .= '<p class="LC_error">'.
12630: &mt('Error: could not update links in [_1].',
12631: '<span class="LC_filename">'.
12632: $container.'</span>').'</p>';
12633:
12634: }
12635: }
12636: }
12637: }
1.987 raeburn 12638: } else {
12639: &logthis('Failed to parse '.$container.
12640: ' to modify references: '.$parse_result);
1.661 raeburn 12641: }
12642: }
1.1071 raeburn 12643: if (wantarray) {
12644: return ($output,$count,$codebasecount);
12645: } else {
12646: return $output;
12647: }
1.661 raeburn 12648: }
12649:
12650: sub check_for_existing {
12651: my ($path,$fname,$element) = @_;
12652: my ($state,$msg);
12653: if (-d $path.'/'.$fname) {
12654: $state = 'exists';
12655: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12656: } elsif (-e $path.'/'.$fname) {
12657: $state = 'exists';
12658: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12659: }
12660: if ($state eq 'exists') {
12661: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12662: }
12663: return ($state,$msg);
12664: }
12665:
12666: sub check_for_upload {
12667: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12668: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12669: my $filesize = length($env{'form.'.$element});
12670: if (!$filesize) {
12671: my $msg = '<span class="LC_error">'.
12672: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12673: '<span class="LC_filename">'.$fname.'</span>',
12674: $filesize).'<br />'.
1.1007 raeburn 12675: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12676: '</span>';
12677: return ('zero_bytes',$msg);
12678: }
12679: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12680: my $getpropath = 1;
1.1021 raeburn 12681: my ($dirlistref,$listerror) =
12682: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12683: my $found_file = 0;
12684: my $locked_file = 0;
1.991 raeburn 12685: my @lockers;
12686: my $navmap;
12687: if ($env{'request.course.id'}) {
12688: $navmap = Apache::lonnavmaps::navmap->new();
12689: }
1.1021 raeburn 12690: if (ref($dirlistref) eq 'ARRAY') {
12691: foreach my $line (@{$dirlistref}) {
12692: my ($file_name,$rest)=split(/\&/,$line,2);
12693: if ($file_name eq $fname){
12694: $file_name = $path.$file_name;
12695: if ($group ne '') {
12696: $file_name = $group.$file_name;
12697: }
12698: $found_file = 1;
12699: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12700: foreach my $lock (@lockers) {
12701: if (ref($lock) eq 'ARRAY') {
12702: my ($symb,$crsid) = @{$lock};
12703: if ($crsid eq $env{'request.course.id'}) {
12704: if (ref($navmap)) {
12705: my $res = $navmap->getBySymb($symb);
12706: foreach my $part (@{$res->parts()}) {
12707: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12708: unless (($slot_status == $res->RESERVED) ||
12709: ($slot_status == $res->RESERVED_LOCATION)) {
12710: $locked_file = 1;
12711: }
1.991 raeburn 12712: }
1.1021 raeburn 12713: } else {
12714: $locked_file = 1;
1.991 raeburn 12715: }
12716: } else {
12717: $locked_file = 1;
12718: }
12719: }
1.1021 raeburn 12720: }
12721: } else {
12722: my @info = split(/\&/,$rest);
12723: my $currsize = $info[6]/1000;
12724: if ($currsize < $filesize) {
12725: my $extra = $filesize - $currsize;
12726: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12727: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12728: &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 12729: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12730: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12731: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12732: return ('will_exceed_quota',$msg);
12733: }
1.984 raeburn 12734: }
12735: }
1.661 raeburn 12736: }
12737: }
12738: }
12739: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12740: my $msg = '<p class="LC_warning">'.
12741: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12742: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12743: return ('will_exceed_quota',$msg);
12744: } elsif ($found_file) {
12745: if ($locked_file) {
1.1179 bisitz 12746: my $msg = '<p class="LC_warning">';
1.661 raeburn 12747: $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 12748: $msg .= '</p>';
1.661 raeburn 12749: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12750: return ('file_locked',$msg);
12751: } else {
1.1179 bisitz 12752: my $msg = '<p class="LC_error">';
1.984 raeburn 12753: $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 12754: $msg .= '</p>';
1.984 raeburn 12755: return ('existingfile',$msg);
1.661 raeburn 12756: }
12757: }
12758: }
12759:
1.987 raeburn 12760: sub check_for_traversal {
12761: my ($path,$url,$toplevel) = @_;
12762: my @parts=split(/\//,$path);
12763: my $cleanpath;
12764: my $fullpath = $url;
12765: for (my $i=0;$i<@parts;$i++) {
12766: next if ($parts[$i] eq '.');
12767: if ($parts[$i] eq '..') {
12768: $fullpath =~ s{([^/]+/)$}{};
12769: } else {
12770: $fullpath .= $parts[$i].'/';
12771: }
12772: }
12773: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12774: $cleanpath = $1;
12775: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12776: my $curr_toprel = $1;
12777: my @parts = split(/\//,$curr_toprel);
12778: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12779: my @urlparts = split(/\//,$url_toprel);
12780: my $doubledots;
12781: my $startdiff = -1;
12782: for (my $i=0; $i<@urlparts; $i++) {
12783: if ($startdiff == -1) {
12784: unless ($urlparts[$i] eq $parts[$i]) {
12785: $startdiff = $i;
12786: $doubledots .= '../';
12787: }
12788: } else {
12789: $doubledots .= '../';
12790: }
12791: }
12792: if ($startdiff > -1) {
12793: $cleanpath = $doubledots;
12794: for (my $i=$startdiff; $i<@parts; $i++) {
12795: $cleanpath .= $parts[$i].'/';
12796: }
12797: }
12798: }
12799: $cleanpath =~ s{(/)$}{};
12800: return $cleanpath;
12801: }
1.31 albertel 12802:
1.1053 raeburn 12803: sub is_archive_file {
12804: my ($mimetype) = @_;
12805: if (($mimetype eq 'application/octet-stream') ||
12806: ($mimetype eq 'application/x-stuffit') ||
12807: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12808: return 1;
12809: }
12810: return;
12811: }
12812:
12813: sub decompress_form {
1.1065 raeburn 12814: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12815: my %lt = &Apache::lonlocal::texthash (
12816: this => 'This file is an archive file.',
1.1067 raeburn 12817: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12818: itsc => 'Its contents are as follows:',
1.1053 raeburn 12819: youm => 'You may wish to extract its contents.',
12820: extr => 'Extract contents',
1.1067 raeburn 12821: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12822: proa => 'Process automatically?',
1.1053 raeburn 12823: yes => 'Yes',
12824: no => 'No',
1.1067 raeburn 12825: fold => 'Title for folder containing movie',
12826: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12827: );
1.1065 raeburn 12828: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12829: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12830: my $info = &list_archive_contents($fileloc,\@paths);
12831: if (@paths) {
12832: foreach my $path (@paths) {
12833: $path =~ s{^/}{};
1.1067 raeburn 12834: if ($path =~ m{^([^/]+)/$}) {
12835: $topdir = $1;
12836: }
1.1065 raeburn 12837: if ($path =~ m{^([^/]+)/}) {
12838: $toplevel{$1} = $path;
12839: } else {
12840: $toplevel{$path} = $path;
12841: }
12842: }
12843: }
1.1067 raeburn 12844: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12845: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12846: "$topdir/media/",
12847: "$topdir/media/$topdir.mp4",
12848: "$topdir/media/FirstFrame.png",
12849: "$topdir/media/player.swf",
12850: "$topdir/media/swfobject.js",
12851: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12852: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12853: "$topdir/$topdir.mp4",
12854: "$topdir/$topdir\_config.xml",
12855: "$topdir/$topdir\_controller.swf",
12856: "$topdir/$topdir\_embed.css",
12857: "$topdir/$topdir\_First_Frame.png",
12858: "$topdir/$topdir\_player.html",
12859: "$topdir/$topdir\_Thumbnails.png",
12860: "$topdir/playerProductInstall.swf",
12861: "$topdir/scripts/",
12862: "$topdir/scripts/config_xml.js",
12863: "$topdir/scripts/handlebars.js",
12864: "$topdir/scripts/jquery-1.7.1.min.js",
12865: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12866: "$topdir/scripts/modernizr.js",
12867: "$topdir/scripts/player-min.js",
12868: "$topdir/scripts/swfobject.js",
12869: "$topdir/skins/",
12870: "$topdir/skins/configuration_express.xml",
12871: "$topdir/skins/express_show/",
12872: "$topdir/skins/express_show/player-min.css",
12873: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12874: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12875: "$topdir/$topdir.mp4",
12876: "$topdir/$topdir\_config.xml",
12877: "$topdir/$topdir\_controller.swf",
12878: "$topdir/$topdir\_embed.css",
12879: "$topdir/$topdir\_First_Frame.png",
12880: "$topdir/$topdir\_player.html",
12881: "$topdir/$topdir\_Thumbnails.png",
12882: "$topdir/playerProductInstall.swf",
12883: "$topdir/scripts/",
12884: "$topdir/scripts/config_xml.js",
12885: "$topdir/scripts/techsmith-smart-player.min.js",
12886: "$topdir/skins/",
12887: "$topdir/skins/configuration_express.xml",
12888: "$topdir/skins/express_show/",
12889: "$topdir/skins/express_show/spritesheet.min.css",
12890: "$topdir/skins/express_show/spritesheet.png",
12891: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12892: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12893: if (@diffs == 0) {
1.1164 raeburn 12894: $is_camtasia = 6;
12895: } else {
1.1197 raeburn 12896: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12897: if (@diffs == 0) {
12898: $is_camtasia = 8;
1.1197 raeburn 12899: } else {
12900: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12901: if (@diffs == 0) {
12902: $is_camtasia = 8;
12903: }
1.1164 raeburn 12904: }
1.1067 raeburn 12905: }
12906: }
12907: my $output;
12908: if ($is_camtasia) {
12909: $output = <<"ENDCAM";
12910: <script type="text/javascript" language="Javascript">
12911: // <![CDATA[
12912:
12913: function camtasiaToggle() {
12914: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12915: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12916: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12917: document.getElementById('camtasia_titles').style.display='block';
12918: } else {
12919: document.getElementById('camtasia_titles').style.display='none';
12920: }
12921: }
12922: }
12923: return;
12924: }
12925:
12926: // ]]>
12927: </script>
12928: <p>$lt{'camt'}</p>
12929: ENDCAM
1.1065 raeburn 12930: } else {
1.1067 raeburn 12931: $output = '<p>'.$lt{'this'};
12932: if ($info eq '') {
12933: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12934: } else {
12935: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12936: '<div><pre>'.$info.'</pre></div>';
12937: }
1.1065 raeburn 12938: }
1.1067 raeburn 12939: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12940: my $duplicates;
12941: my $num = 0;
12942: if (ref($dirlist) eq 'ARRAY') {
12943: foreach my $item (@{$dirlist}) {
12944: if (ref($item) eq 'ARRAY') {
12945: if (exists($toplevel{$item->[0]})) {
12946: $duplicates .=
12947: &start_data_table_row().
12948: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12949: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12950: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12951: 'value="1" />'.&mt('Yes').'</label>'.
12952: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12953: '<td>'.$item->[0].'</td>';
12954: if ($item->[2]) {
12955: $duplicates .= '<td>'.&mt('Directory').'</td>';
12956: } else {
12957: $duplicates .= '<td>'.&mt('File').'</td>';
12958: }
12959: $duplicates .= '<td>'.$item->[3].'</td>'.
12960: '<td>'.
12961: &Apache::lonlocal::locallocaltime($item->[4]).
12962: '</td>'.
12963: &end_data_table_row();
12964: $num ++;
12965: }
12966: }
12967: }
12968: }
12969: my $itemcount;
12970: if (@paths > 0) {
12971: $itemcount = scalar(@paths);
12972: } else {
12973: $itemcount = 1;
12974: }
1.1067 raeburn 12975: if ($is_camtasia) {
12976: $output .= $lt{'auto'}.'<br />'.
12977: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12978: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12979: $lt{'yes'}.'</label> <label>'.
12980: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12981: $lt{'no'}.'</label></span><br />'.
12982: '<div id="camtasia_titles" style="display:block">'.
12983: &Apache::lonhtmlcommon::start_pick_box().
12984: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12985: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12986: &Apache::lonhtmlcommon::row_closure().
12987: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12988: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12989: &Apache::lonhtmlcommon::row_closure(1).
12990: &Apache::lonhtmlcommon::end_pick_box().
12991: '</div>';
12992: }
1.1065 raeburn 12993: $output .=
12994: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12995: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12996: "\n";
1.1065 raeburn 12997: if ($duplicates ne '') {
12998: $output .= '<p><span class="LC_warning">'.
12999: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
13000: &start_data_table().
13001: &start_data_table_header_row().
13002: '<th>'.&mt('Overwrite?').'</th>'.
13003: '<th>'.&mt('Name').'</th>'.
13004: '<th>'.&mt('Type').'</th>'.
13005: '<th>'.&mt('Size').'</th>'.
13006: '<th>'.&mt('Last modified').'</th>'.
13007: &end_data_table_header_row().
13008: $duplicates.
13009: &end_data_table().
13010: '</p>';
13011: }
1.1067 raeburn 13012: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 13013: if (ref($hiddenelements) eq 'HASH') {
13014: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
13015: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
13016: }
13017: }
13018: $output .= <<"END";
1.1067 raeburn 13019: <br />
1.1053 raeburn 13020: <input type="submit" name="decompress" value="$lt{'extr'}" />
13021: </form>
13022: $noextract
13023: END
13024: return $output;
13025: }
13026:
1.1065 raeburn 13027: sub decompression_utility {
13028: my ($program) = @_;
13029: my @utilities = ('tar','gunzip','bunzip2','unzip');
13030: my $location;
13031: if (grep(/^\Q$program\E$/,@utilities)) {
13032: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
13033: '/usr/sbin/') {
13034: if (-x $dir.$program) {
13035: $location = $dir.$program;
13036: last;
13037: }
13038: }
13039: }
13040: return $location;
13041: }
13042:
13043: sub list_archive_contents {
13044: my ($file,$pathsref) = @_;
13045: my (@cmd,$output);
13046: my $needsregexp;
13047: if ($file =~ /\.zip$/) {
13048: @cmd = (&decompression_utility('unzip'),"-l");
13049: $needsregexp = 1;
13050: } elsif (($file =~ m/\.tar\.gz$/) ||
13051: ($file =~ /\.tgz$/)) {
13052: @cmd = (&decompression_utility('tar'),"-ztf");
13053: } elsif ($file =~ /\.tar\.bz2$/) {
13054: @cmd = (&decompression_utility('tar'),"-jtf");
13055: } elsif ($file =~ m|\.tar$|) {
13056: @cmd = (&decompression_utility('tar'),"-tf");
13057: }
13058: if (@cmd) {
13059: undef($!);
13060: undef($@);
13061: if (open(my $fh,"-|", @cmd, $file)) {
13062: while (my $line = <$fh>) {
13063: $output .= $line;
13064: chomp($line);
13065: my $item;
13066: if ($needsregexp) {
13067: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
13068: } else {
13069: $item = $line;
13070: }
13071: if ($item ne '') {
13072: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
13073: push(@{$pathsref},$item);
13074: }
13075: }
13076: }
13077: close($fh);
13078: }
13079: }
13080: return $output;
13081: }
13082:
1.1053 raeburn 13083: sub decompress_uploaded_file {
13084: my ($file,$dir) = @_;
13085: &Apache::lonnet::appenv({'cgi.file' => $file});
13086: &Apache::lonnet::appenv({'cgi.dir' => $dir});
13087: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
13088: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
13089: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
13090: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
13091: my $decompressed = $env{'cgi.decompressed'};
13092: &Apache::lonnet::delenv('cgi.file');
13093: &Apache::lonnet::delenv('cgi.dir');
13094: &Apache::lonnet::delenv('cgi.decompressed');
13095: return ($decompressed,$result);
13096: }
13097:
1.1055 raeburn 13098: sub process_decompression {
13099: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 13100: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
13101: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13102: &mt('Unexpected file path.').'</p>'."\n";
13103: }
13104: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
13105: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13106: &mt('Unexpected course context.').'</p>'."\n";
13107: }
1.1293 raeburn 13108: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 13109: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13110: &mt('Filename contained unexpected characters.').'</p>'."\n";
13111: }
1.1055 raeburn 13112: my ($dir,$error,$warning,$output);
1.1180 raeburn 13113: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 13114: $error = &mt('Filename not a supported archive file type.').
13115: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 13116: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
13117: } else {
13118: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13119: if ($docuhome eq 'no_host') {
13120: $error = &mt('Could not determine home server for course.');
13121: } else {
13122: my @ids=&Apache::lonnet::current_machine_ids();
13123: my $currdir = "$dir_root/$destination";
13124: if (grep(/^\Q$docuhome\E$/,@ids)) {
13125: $dir = &LONCAPA::propath($docudom,$docuname).
13126: "$dir_root/$destination";
13127: } else {
13128: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
13129: "$dir_root/$docudom/$docuname/$destination";
13130: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
13131: $error = &mt('Archive file not found.');
13132: }
13133: }
1.1065 raeburn 13134: my (@to_overwrite,@to_skip);
13135: if ($env{'form.archive_overwrite_total'} > 0) {
13136: my $total = $env{'form.archive_overwrite_total'};
13137: for (my $i=0; $i<$total; $i++) {
13138: if ($env{'form.archive_overwrite_'.$i} == 1) {
13139: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
13140: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
13141: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
13142: }
13143: }
13144: }
13145: my $numskip = scalar(@to_skip);
1.1292 raeburn 13146: my $numoverwrite = scalar(@to_overwrite);
13147: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 13148: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
13149: } elsif ($dir eq '') {
1.1055 raeburn 13150: $error = &mt('Directory containing archive file unavailable.');
13151: } elsif (!$error) {
1.1065 raeburn 13152: my ($decompressed,$display);
1.1292 raeburn 13153: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 13154: my $tempdir = time.'_'.$$.int(rand(10000));
13155: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 13156: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
13157: ($decompressed,$display) =
13158: &decompress_uploaded_file($file,"$dir/$tempdir");
13159: foreach my $item (@to_skip) {
13160: if (($item ne '') && ($item !~ /\.\./)) {
13161: if (-f "$dir/$tempdir/$item") {
13162: unlink("$dir/$tempdir/$item");
13163: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 13164: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 13165: }
13166: }
13167: }
13168: foreach my $item (@to_overwrite) {
13169: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
13170: if (($item ne '') && ($item !~ /\.\./)) {
13171: if (-f "$dir/$item") {
13172: unlink("$dir/$item");
13173: } elsif (-d "$dir/$item") {
1.1300 raeburn 13174: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 13175: }
13176: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
13177: }
1.1065 raeburn 13178: }
13179: }
1.1292 raeburn 13180: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 13181: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 13182: }
1.1065 raeburn 13183: }
13184: } else {
13185: ($decompressed,$display) =
13186: &decompress_uploaded_file($file,$dir);
13187: }
1.1055 raeburn 13188: if ($decompressed eq 'ok') {
1.1065 raeburn 13189: $output = '<p class="LC_info">'.
13190: &mt('Files extracted successfully from archive.').
13191: '</p>'."\n";
1.1055 raeburn 13192: my ($warning,$result,@contents);
13193: my ($newdirlistref,$newlisterror) =
13194: &Apache::lonnet::dirlist($currdir,$docudom,
13195: $docuname,1);
13196: my (%is_dir,%changes,@newitems);
13197: my $dirptr = 16384;
1.1065 raeburn 13198: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 13199: foreach my $dir_line (@{$newdirlistref}) {
13200: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 13201: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 13202: push(@newitems,$item);
13203: if ($dirptr&$testdir) {
13204: $is_dir{$item} = 1;
13205: }
13206: $changes{$item} = 1;
13207: }
13208: }
13209: }
13210: if (keys(%changes) > 0) {
13211: foreach my $item (sort(@newitems)) {
13212: if ($changes{$item}) {
13213: push(@contents,$item);
13214: }
13215: }
13216: }
13217: if (@contents > 0) {
1.1067 raeburn 13218: my $wantform;
13219: unless ($env{'form.autoextract_camtasia'}) {
13220: $wantform = 1;
13221: }
1.1056 raeburn 13222: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 13223: my ($count,$datatable) = &get_extracted($docudom,$docuname,
13224: $currdir,\%is_dir,
13225: \%children,\%parent,
1.1056 raeburn 13226: \@contents,\%dirorder,
13227: \%titles,$wantform);
1.1055 raeburn 13228: if ($datatable ne '') {
13229: $output .= &archive_options_form('decompressed',$datatable,
13230: $count,$hiddenelem);
1.1065 raeburn 13231: my $startcount = 6;
1.1055 raeburn 13232: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 13233: \%titles,\%children);
1.1055 raeburn 13234: }
1.1067 raeburn 13235: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 13236: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 13237: my %displayed;
13238: my $total = 1;
13239: $env{'form.archive_directory'} = [];
13240: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
13241: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
13242: $path =~ s{/$}{};
13243: my $item;
13244: if ($path ne '') {
13245: $item = "$path/$titles{$i}";
13246: } else {
13247: $item = $titles{$i};
13248: }
13249: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
13250: if ($item eq $contents[0]) {
13251: push(@{$env{'form.archive_directory'}},$i);
13252: $env{'form.archive_'.$i} = 'display';
13253: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
13254: $displayed{'folder'} = $i;
1.1164 raeburn 13255: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
13256: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 13257: $env{'form.archive_'.$i} = 'display';
13258: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
13259: $displayed{'web'} = $i;
13260: } else {
1.1164 raeburn 13261: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
13262: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
13263: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 13264: push(@{$env{'form.archive_directory'}},$i);
13265: }
13266: $env{'form.archive_'.$i} = 'dependency';
13267: }
13268: $total ++;
13269: }
13270: for (my $i=1; $i<$total; $i++) {
13271: next if ($i == $displayed{'web'});
13272: next if ($i == $displayed{'folder'});
13273: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
13274: }
13275: $env{'form.phase'} = 'decompress_cleanup';
13276: $env{'form.archivedelete'} = 1;
13277: $env{'form.archive_count'} = $total-1;
13278: $output .=
13279: &process_extracted_files('coursedocs',$docudom,
13280: $docuname,$destination,
13281: $dir_root,$hiddenelem);
13282: }
1.1055 raeburn 13283: } else {
13284: $warning = &mt('No new items extracted from archive file.');
13285: }
13286: } else {
13287: $output = $display;
13288: $error = &mt('An error occurred during extraction from the archive file.');
13289: }
13290: }
13291: }
13292: }
13293: if ($error) {
13294: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13295: $error.'</p>'."\n";
13296: }
13297: if ($warning) {
13298: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13299: }
13300: return $output;
13301: }
13302:
13303: sub get_extracted {
1.1056 raeburn 13304: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
13305: $titles,$wantform) = @_;
1.1055 raeburn 13306: my $count = 0;
13307: my $depth = 0;
13308: my $datatable;
1.1056 raeburn 13309: my @hierarchy;
1.1055 raeburn 13310: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13311: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13312: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13313: foreach my $item (@{$contents}) {
13314: $count ++;
1.1056 raeburn 13315: @{$dirorder->{$count}} = @hierarchy;
13316: $titles->{$count} = $item;
1.1055 raeburn 13317: &archive_hierarchy($depth,$count,$parent,$children);
13318: if ($wantform) {
13319: $datatable .= &archive_row($is_dir->{$item},$item,
13320: $currdir,$depth,$count);
13321: }
13322: if ($is_dir->{$item}) {
13323: $depth ++;
1.1056 raeburn 13324: push(@hierarchy,$count);
13325: $parent->{$depth} = $count;
1.1055 raeburn 13326: $datatable .=
13327: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13328: \$depth,\$count,\@hierarchy,$dirorder,
13329: $children,$parent,$titles,$wantform);
1.1055 raeburn 13330: $depth --;
1.1056 raeburn 13331: pop(@hierarchy);
1.1055 raeburn 13332: }
13333: }
13334: return ($count,$datatable);
13335: }
13336:
13337: sub recurse_extracted_archive {
1.1056 raeburn 13338: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13339: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13340: my $result='';
1.1056 raeburn 13341: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13342: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13343: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13344: return $result;
13345: }
13346: my $dirptr = 16384;
13347: my ($newdirlistref,$newlisterror) =
13348: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13349: if (ref($newdirlistref) eq 'ARRAY') {
13350: foreach my $dir_line (@{$newdirlistref}) {
13351: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13352: unless ($item =~ /^\.+$/) {
13353: $$count ++;
1.1056 raeburn 13354: @{$dirorder->{$$count}} = @{$hierarchy};
13355: $titles->{$$count} = $item;
1.1055 raeburn 13356: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13357:
1.1055 raeburn 13358: my $is_dir;
13359: if ($dirptr&$testdir) {
13360: $is_dir = 1;
13361: }
13362: if ($wantform) {
13363: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13364: }
13365: if ($is_dir) {
13366: $$depth ++;
1.1056 raeburn 13367: push(@{$hierarchy},$$count);
13368: $parent->{$$depth} = $$count;
1.1055 raeburn 13369: $result .=
13370: &recurse_extracted_archive("$currdir/$item",$docudom,
13371: $docuname,$depth,$count,
1.1056 raeburn 13372: $hierarchy,$dirorder,$children,
13373: $parent,$titles,$wantform);
1.1055 raeburn 13374: $$depth --;
1.1056 raeburn 13375: pop(@{$hierarchy});
1.1055 raeburn 13376: }
13377: }
13378: }
13379: }
13380: return $result;
13381: }
13382:
13383: sub archive_hierarchy {
13384: my ($depth,$count,$parent,$children) =@_;
13385: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13386: if (exists($parent->{$depth})) {
13387: $children->{$parent->{$depth}} .= $count.':';
13388: }
13389: }
13390: return;
13391: }
13392:
13393: sub archive_row {
13394: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13395: my ($name) = ($item =~ m{([^/]+)$});
13396: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13397: 'display' => 'Add as file',
1.1055 raeburn 13398: 'dependency' => 'Include as dependency',
13399: 'discard' => 'Discard',
13400: );
13401: if ($is_dir) {
1.1059 raeburn 13402: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13403: }
1.1056 raeburn 13404: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13405: my $offset = 0;
1.1055 raeburn 13406: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13407: $offset ++;
1.1065 raeburn 13408: if ($action ne 'display') {
13409: $offset ++;
13410: }
1.1055 raeburn 13411: $output .= '<td><span class="LC_nobreak">'.
13412: '<label><input type="radio" name="archive_'.$count.
13413: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13414: my $text = $choices{$action};
13415: if ($is_dir) {
13416: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13417: if ($action eq 'display') {
1.1059 raeburn 13418: $text = &mt('Add as folder');
1.1055 raeburn 13419: }
1.1056 raeburn 13420: } else {
13421: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13422:
13423: }
13424: $output .= ' /> '.$choices{$action}.'</label></span>';
13425: if ($action eq 'dependency') {
13426: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13427: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13428: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13429: '<option value=""></option>'."\n".
13430: '</select>'."\n".
13431: '</div>';
1.1059 raeburn 13432: } elsif ($action eq 'display') {
13433: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13434: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13435: '</div>';
1.1055 raeburn 13436: }
1.1056 raeburn 13437: $output .= '</td>';
1.1055 raeburn 13438: }
13439: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13440: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13441: for (my $i=0; $i<$depth; $i++) {
13442: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13443: }
13444: if ($is_dir) {
13445: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13446: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13447: } else {
13448: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13449: }
13450: $output .= ' '.$name.'</td>'."\n".
13451: &end_data_table_row();
13452: return $output;
13453: }
13454:
13455: sub archive_options_form {
1.1065 raeburn 13456: my ($form,$display,$count,$hiddenelem) = @_;
13457: my %lt = &Apache::lonlocal::texthash(
13458: perm => 'Permanently remove archive file?',
13459: hows => 'How should each extracted item be incorporated in the course?',
13460: cont => 'Content actions for all',
13461: addf => 'Add as folder/file',
13462: incd => 'Include as dependency for a displayed file',
13463: disc => 'Discard',
13464: no => 'No',
13465: yes => 'Yes',
13466: save => 'Save',
13467: );
13468: my $output = <<"END";
13469: <form name="$form" method="post" action="">
13470: <p><span class="LC_nobreak">$lt{'perm'}
13471: <label>
13472: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13473: </label>
13474:
13475: <label>
13476: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13477: </span>
13478: </p>
13479: <input type="hidden" name="phase" value="decompress_cleanup" />
13480: <br />$lt{'hows'}
13481: <div class="LC_columnSection">
13482: <fieldset>
13483: <legend>$lt{'cont'}</legend>
13484: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13485: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13486: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13487: </fieldset>
13488: </div>
13489: END
13490: return $output.
1.1055 raeburn 13491: &start_data_table()."\n".
1.1065 raeburn 13492: $display."\n".
1.1055 raeburn 13493: &end_data_table()."\n".
13494: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13495: $hiddenelem.
1.1065 raeburn 13496: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13497: '</form>';
13498: }
13499:
13500: sub archive_javascript {
1.1056 raeburn 13501: my ($startcount,$numitems,$titles,$children) = @_;
13502: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13503: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13504: my $scripttag = <<START;
13505: <script type="text/javascript">
13506: // <![CDATA[
13507:
13508: function checkAll(form,prefix) {
13509: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13510: for (var i=0; i < form.elements.length; i++) {
13511: var id = form.elements[i].id;
13512: if ((id != '') && (id != undefined)) {
13513: if (idstr.test(id)) {
13514: if (form.elements[i].type == 'radio') {
13515: form.elements[i].checked = true;
1.1056 raeburn 13516: var nostart = i-$startcount;
1.1059 raeburn 13517: var offset = nostart%7;
13518: var count = (nostart-offset)/7;
1.1056 raeburn 13519: dependencyCheck(form,count,offset);
1.1055 raeburn 13520: }
13521: }
13522: }
13523: }
13524: }
13525:
13526: function propagateCheck(form,count) {
13527: if (count > 0) {
1.1059 raeburn 13528: var startelement = $startcount + ((count-1) * 7);
13529: for (var j=1; j<6; j++) {
13530: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13531: var item = startelement + j;
13532: if (form.elements[item].type == 'radio') {
13533: if (form.elements[item].checked) {
13534: containerCheck(form,count,j);
13535: break;
13536: }
1.1055 raeburn 13537: }
13538: }
13539: }
13540: }
13541: }
13542:
13543: numitems = $numitems
1.1056 raeburn 13544: var titles = new Array(numitems);
13545: var parents = new Array(numitems);
1.1055 raeburn 13546: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13547: parents[i] = new Array;
1.1055 raeburn 13548: }
1.1059 raeburn 13549: var maintitle = '$maintitle';
1.1055 raeburn 13550:
13551: START
13552:
1.1056 raeburn 13553: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13554: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13555: for (my $i=0; $i<@contents; $i ++) {
13556: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13557: }
13558: }
13559:
1.1056 raeburn 13560: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13561: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13562: }
13563:
1.1055 raeburn 13564: $scripttag .= <<END;
13565:
13566: function containerCheck(form,count,offset) {
13567: if (count > 0) {
1.1056 raeburn 13568: dependencyCheck(form,count,offset);
1.1059 raeburn 13569: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13570: form.elements[item].checked = true;
13571: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13572: if (parents[count].length > 0) {
13573: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13574: containerCheck(form,parents[count][j],offset);
13575: }
13576: }
13577: }
13578: }
13579: }
13580:
13581: function dependencyCheck(form,count,offset) {
13582: if (count > 0) {
1.1059 raeburn 13583: var chosen = (offset+$startcount)+7*(count-1);
13584: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13585: var currtype = form.elements[depitem].type;
13586: if (form.elements[chosen].value == 'dependency') {
13587: document.getElementById('arc_depon_'+count).style.display='block';
13588: form.elements[depitem].options.length = 0;
13589: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13590: for (var i=1; i<=numitems; i++) {
13591: if (i == count) {
13592: continue;
13593: }
1.1059 raeburn 13594: var startelement = $startcount + (i-1) * 7;
13595: for (var j=1; j<6; j++) {
13596: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13597: var item = startelement + j;
13598: if (form.elements[item].type == 'radio') {
13599: if (form.elements[item].checked) {
13600: if (form.elements[item].value == 'display') {
13601: var n = form.elements[depitem].options.length;
13602: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13603: }
13604: }
13605: }
13606: }
13607: }
13608: }
13609: } else {
13610: document.getElementById('arc_depon_'+count).style.display='none';
13611: form.elements[depitem].options.length = 0;
13612: form.elements[depitem].options[0] = new Option('Select','',true,true);
13613: }
1.1059 raeburn 13614: titleCheck(form,count,offset);
1.1056 raeburn 13615: }
13616: }
13617:
13618: function propagateSelect(form,count,offset) {
13619: if (count > 0) {
1.1065 raeburn 13620: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13621: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13622: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13623: if (parents[count].length > 0) {
13624: for (var j=0; j<parents[count].length; j++) {
13625: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13626: }
13627: }
13628: }
13629: }
13630: }
1.1056 raeburn 13631:
13632: function containerSelect(form,count,offset,picked) {
13633: if (count > 0) {
1.1065 raeburn 13634: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13635: if (form.elements[item].type == 'radio') {
13636: if (form.elements[item].value == 'dependency') {
13637: if (form.elements[item+1].type == 'select-one') {
13638: for (var i=0; i<form.elements[item+1].options.length; i++) {
13639: if (form.elements[item+1].options[i].value == picked) {
13640: form.elements[item+1].selectedIndex = i;
13641: break;
13642: }
13643: }
13644: }
13645: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13646: if (parents[count].length > 0) {
13647: for (var j=0; j<parents[count].length; j++) {
13648: containerSelect(form,parents[count][j],offset,picked);
13649: }
13650: }
13651: }
13652: }
13653: }
13654: }
13655: }
13656:
1.1059 raeburn 13657: function titleCheck(form,count,offset) {
13658: if (count > 0) {
13659: var chosen = (offset+$startcount)+7*(count-1);
13660: var depitem = $startcount + ((count-1) * 7) + 2;
13661: var currtype = form.elements[depitem].type;
13662: if (form.elements[chosen].value == 'display') {
13663: document.getElementById('arc_title_'+count).style.display='block';
13664: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13665: document.getElementById('archive_title_'+count).value=maintitle;
13666: }
13667: } else {
13668: document.getElementById('arc_title_'+count).style.display='none';
13669: if (currtype == 'text') {
13670: document.getElementById('archive_title_'+count).value='';
13671: }
13672: }
13673: }
13674: return;
13675: }
13676:
1.1055 raeburn 13677: // ]]>
13678: </script>
13679: END
13680: return $scripttag;
13681: }
13682:
13683: sub process_extracted_files {
1.1067 raeburn 13684: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13685: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 13686: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13687: my @ids=&Apache::lonnet::current_machine_ids();
13688: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13689: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13690: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13691: if (grep(/^\Q$docuhome\E$/,@ids)) {
13692: $prefix = &LONCAPA::propath($docudom,$docuname);
13693: $pathtocheck = "$dir_root/$destination";
13694: $dir = $dir_root;
13695: $ishome = 1;
13696: } else {
13697: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13698: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 13699: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13700: }
13701: my $currdir = "$dir_root/$destination";
13702: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13703: if ($env{'form.folderpath'}) {
13704: my @items = split('&',$env{'form.folderpath'});
13705: $folders{'0'} = $items[-2];
1.1099 raeburn 13706: if ($env{'form.folderpath'} =~ /\:1$/) {
13707: $containers{'0'}='page';
13708: } else {
13709: $containers{'0'}='sequence';
13710: }
1.1055 raeburn 13711: }
13712: my @archdirs = &get_env_multiple('form.archive_directory');
13713: if ($numitems) {
13714: for (my $i=1; $i<=$numitems; $i++) {
13715: my $path = $env{'form.archive_content_'.$i};
13716: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13717: my $item = $1;
13718: $toplevelitems{$item} = $i;
13719: if (grep(/^\Q$i\E$/,@archdirs)) {
13720: $is_dir{$item} = 1;
13721: }
13722: }
13723: }
13724: }
1.1067 raeburn 13725: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13726: if (keys(%toplevelitems) > 0) {
13727: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13728: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13729: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13730: }
1.1066 raeburn 13731: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13732: if ($numitems) {
13733: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13734: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13735: my $path = $env{'form.archive_content_'.$i};
13736: if ($path =~ /^\Q$pathtocheck\E/) {
13737: if ($env{'form.archive_'.$i} eq 'discard') {
13738: if ($prefix ne '' && $path ne '') {
13739: if (-e $prefix.$path) {
1.1066 raeburn 13740: if ((@archdirs > 0) &&
13741: (grep(/^\Q$i\E$/,@archdirs))) {
13742: $todeletedir{$prefix.$path} = 1;
13743: } else {
13744: $todelete{$prefix.$path} = 1;
13745: }
1.1055 raeburn 13746: }
13747: }
13748: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13749: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13750: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13751: $docstitle = $env{'form.archive_title_'.$i};
13752: if ($docstitle eq '') {
13753: $docstitle = $title;
13754: }
1.1055 raeburn 13755: $outer = 0;
1.1056 raeburn 13756: if (ref($dirorder{$i}) eq 'ARRAY') {
13757: if (@{$dirorder{$i}} > 0) {
13758: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13759: if ($env{'form.archive_'.$item} eq 'display') {
13760: $outer = $item;
13761: last;
13762: }
13763: }
13764: }
13765: }
13766: my ($errtext,$fatal) =
13767: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13768: '/'.$folders{$outer}.'.'.
13769: $containers{$outer});
13770: next if ($fatal);
13771: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13772: if ($context eq 'coursedocs') {
1.1056 raeburn 13773: $mapinner{$i} = time;
1.1055 raeburn 13774: $folders{$i} = 'default_'.$mapinner{$i};
13775: $containers{$i} = 'sequence';
13776: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13777: $folders{$i}.'.'.$containers{$i};
13778: my $newidx = &LONCAPA::map::getresidx();
13779: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13780: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13781: push(@LONCAPA::map::order,$newidx);
13782: my ($outtext,$errtext) =
13783: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13784: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13785: '.'.$containers{$outer},1,1);
1.1056 raeburn 13786: $newseqid{$i} = $newidx;
1.1067 raeburn 13787: unless ($errtext) {
1.1294 raeburn 13788: $result .= '<li>'.&mt('Folder: [_1] added to course',
13789: &HTML::Entities::encode($docstitle,'<>&"')).
13790: '</li>'."\n";
1.1067 raeburn 13791: }
1.1055 raeburn 13792: }
13793: } else {
13794: if ($context eq 'coursedocs') {
13795: my $newidx=&LONCAPA::map::getresidx();
13796: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13797: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13798: $title;
1.1294 raeburn 13799: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
13800: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13801: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13802: }
13803: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13804: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13805: }
13806: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13807: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13808: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13809: unless ($ishome) {
13810: my $fetch = "$newdest{$i}/$title";
13811: $fetch =~ s/^\Q$prefix$dir\E//;
13812: $prompttofetch{$fetch} = 1;
13813: }
1.1292 raeburn 13814: }
1.1067 raeburn 13815: }
1.1294 raeburn 13816: $LONCAPA::map::resources[$newidx]=
13817: $docstitle.':'.$url.':false:normal:res';
13818: push(@LONCAPA::map::order, $newidx);
13819: my ($outtext,$errtext)=
13820: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13821: $docuname.'/'.$folders{$outer}.
13822: '.'.$containers{$outer},1,1);
13823: unless ($errtext) {
13824: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13825: $result .= '<li>'.&mt('File: [_1] added to course',
13826: &HTML::Entities::encode($docstitle,'<>&"')).
13827: '</li>'."\n";
13828: }
1.1067 raeburn 13829: }
1.1294 raeburn 13830: } else {
13831: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13832: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 13833: }
1.1055 raeburn 13834: }
13835: }
1.1086 raeburn 13836: }
13837: } else {
1.1294 raeburn 13838: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13839: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 13840: }
13841: }
13842: for (my $i=1; $i<=$numitems; $i++) {
13843: next unless ($env{'form.archive_'.$i} eq 'dependency');
13844: my $path = $env{'form.archive_content_'.$i};
13845: if ($path =~ /^\Q$pathtocheck\E/) {
13846: my ($title) = ($path =~ m{/([^/]+)$});
13847: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13848: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13849: if (ref($dirorder{$i}) eq 'ARRAY') {
13850: my ($itemidx,$fullpath,$relpath);
13851: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13852: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13853: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13854: if ($dirorder{$i}->[$j] eq $container) {
13855: $itemidx = $j;
1.1056 raeburn 13856: }
13857: }
1.1086 raeburn 13858: }
13859: if ($itemidx eq '') {
13860: $itemidx = 0;
13861: }
13862: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13863: if ($mapinner{$referrer{$i}}) {
13864: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13865: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13866: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13867: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13868: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13869: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13870: if (!-e $fullpath) {
13871: mkdir($fullpath,0755);
1.1056 raeburn 13872: }
13873: }
1.1086 raeburn 13874: } else {
13875: last;
1.1056 raeburn 13876: }
1.1086 raeburn 13877: }
13878: }
13879: } elsif ($newdest{$referrer{$i}}) {
13880: $fullpath = $newdest{$referrer{$i}};
13881: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13882: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13883: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13884: last;
13885: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13886: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13887: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13888: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13889: if (!-e $fullpath) {
13890: mkdir($fullpath,0755);
1.1056 raeburn 13891: }
13892: }
1.1086 raeburn 13893: } else {
13894: last;
1.1056 raeburn 13895: }
1.1055 raeburn 13896: }
13897: }
1.1086 raeburn 13898: if ($fullpath ne '') {
13899: if (-e "$prefix$path") {
1.1292 raeburn 13900: unless (rename("$prefix$path","$fullpath/$title")) {
13901: $warning .= &mt('Failed to rename dependency').'<br />';
13902: }
1.1086 raeburn 13903: }
13904: if (-e "$fullpath/$title") {
13905: my $showpath;
13906: if ($relpath ne '') {
13907: $showpath = "$relpath/$title";
13908: } else {
13909: $showpath = "/$title";
13910: }
1.1294 raeburn 13911: $result .= '<li>'.&mt('[_1] included as a dependency',
13912: &HTML::Entities::encode($showpath,'<>&"')).
13913: '</li>'."\n";
1.1292 raeburn 13914: unless ($ishome) {
13915: my $fetch = "$fullpath/$title";
13916: $fetch =~ s/^\Q$prefix$dir\E//;
13917: $prompttofetch{$fetch} = 1;
13918: }
1.1086 raeburn 13919: }
13920: }
1.1055 raeburn 13921: }
1.1086 raeburn 13922: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13923: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 13924: &HTML::Entities::encode($path,'<>&"'),
13925: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13926: '<br />';
1.1055 raeburn 13927: }
13928: } else {
1.1294 raeburn 13929: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 13930: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13931: }
13932: }
13933: if (keys(%todelete)) {
13934: foreach my $key (keys(%todelete)) {
13935: unlink($key);
1.1066 raeburn 13936: }
13937: }
13938: if (keys(%todeletedir)) {
13939: foreach my $key (keys(%todeletedir)) {
13940: rmdir($key);
13941: }
13942: }
13943: foreach my $dir (sort(keys(%is_dir))) {
13944: if (($pathtocheck ne '') && ($dir ne '')) {
13945: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13946: }
13947: }
1.1067 raeburn 13948: if ($result ne '') {
13949: $output .= '<ul>'."\n".
13950: $result."\n".
13951: '</ul>';
13952: }
13953: unless ($ishome) {
13954: my $replicationfail;
13955: foreach my $item (keys(%prompttofetch)) {
13956: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13957: unless ($fetchresult eq 'ok') {
13958: $replicationfail .= '<li>'.$item.'</li>'."\n";
13959: }
13960: }
13961: if ($replicationfail) {
13962: $output .= '<p class="LC_error">'.
13963: &mt('Course home server failed to retrieve:').'<ul>'.
13964: $replicationfail.
13965: '</ul></p>';
13966: }
13967: }
1.1055 raeburn 13968: } else {
13969: $warning = &mt('No items found in archive.');
13970: }
13971: if ($error) {
13972: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13973: $error.'</p>'."\n";
13974: }
13975: if ($warning) {
13976: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13977: }
13978: return $output;
13979: }
13980:
1.1066 raeburn 13981: sub cleanup_empty_dirs {
13982: my ($path) = @_;
13983: if (($path ne '') && (-d $path)) {
13984: if (opendir(my $dirh,$path)) {
13985: my @dircontents = grep(!/^\./,readdir($dirh));
13986: my $numitems = 0;
13987: foreach my $item (@dircontents) {
13988: if (-d "$path/$item") {
1.1111 raeburn 13989: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13990: if (-e "$path/$item") {
13991: $numitems ++;
13992: }
13993: } else {
13994: $numitems ++;
13995: }
13996: }
13997: if ($numitems == 0) {
13998: rmdir($path);
13999: }
14000: closedir($dirh);
14001: }
14002: }
14003: return;
14004: }
14005:
1.41 ng 14006: =pod
1.45 matthew 14007:
1.1162 raeburn 14008: =item * &get_folder_hierarchy()
1.1068 raeburn 14009:
14010: Provides hierarchy of names of folders/sub-folders containing the current
14011: item,
14012:
14013: Inputs: 3
14014: - $navmap - navmaps object
14015:
14016: - $map - url for map (either the trigger itself, or map containing
14017: the resource, which is the trigger).
14018:
14019: - $showitem - 1 => show title for map itself; 0 => do not show.
14020:
14021: Outputs: 1 @pathitems - array of folder/subfolder names.
14022:
14023: =cut
14024:
14025: sub get_folder_hierarchy {
14026: my ($navmap,$map,$showitem) = @_;
14027: my @pathitems;
14028: if (ref($navmap)) {
14029: my $mapres = $navmap->getResourceByUrl($map);
14030: if (ref($mapres)) {
14031: my $pcslist = $mapres->map_hierarchy();
14032: if ($pcslist ne '') {
14033: my @pcs = split(/,/,$pcslist);
14034: foreach my $pc (@pcs) {
14035: if ($pc == 1) {
1.1129 raeburn 14036: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 14037: } else {
14038: my $res = $navmap->getByMapPc($pc);
14039: if (ref($res)) {
14040: my $title = $res->compTitle();
14041: $title =~ s/\W+/_/g;
14042: if ($title ne '') {
14043: push(@pathitems,$title);
14044: }
14045: }
14046: }
14047: }
14048: }
1.1071 raeburn 14049: if ($showitem) {
14050: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 14051: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 14052: } else {
14053: my $maptitle = $mapres->compTitle();
14054: $maptitle =~ s/\W+/_/g;
14055: if ($maptitle ne '') {
14056: push(@pathitems,$maptitle);
14057: }
1.1068 raeburn 14058: }
14059: }
14060: }
14061: }
14062: return @pathitems;
14063: }
14064:
14065: =pod
14066:
1.1015 raeburn 14067: =item * &get_turnedin_filepath()
14068:
14069: Determines path in a user's portfolio file for storage of files uploaded
14070: to a specific essayresponse or dropbox item.
14071:
14072: Inputs: 3 required + 1 optional.
14073: $symb is symb for resource, $uname and $udom are for current user (required).
14074: $caller is optional (can be "submission", if routine is called when storing
14075: an upoaded file when "Submit Answer" button was pressed).
14076:
14077: Returns array containing $path and $multiresp.
14078: $path is path in portfolio. $multiresp is 1 if this resource contains more
14079: than one file upload item. Callers of routine should append partid as a
14080: subdirectory to $path in cases where $multiresp is 1.
14081:
14082: Called by: homework/essayresponse.pm and homework/structuretags.pm
14083:
14084: =cut
14085:
14086: sub get_turnedin_filepath {
14087: my ($symb,$uname,$udom,$caller) = @_;
14088: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
14089: my $turnindir;
14090: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
14091: $turnindir = $userhash{'turnindir'};
14092: my ($path,$multiresp);
14093: if ($turnindir eq '') {
14094: if ($caller eq 'submission') {
14095: $turnindir = &mt('turned in');
14096: $turnindir =~ s/\W+/_/g;
14097: my %newhash = (
14098: 'turnindir' => $turnindir,
14099: );
14100: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
14101: }
14102: }
14103: if ($turnindir ne '') {
14104: $path = '/'.$turnindir.'/';
14105: my ($multipart,$turnin,@pathitems);
14106: my $navmap = Apache::lonnavmaps::navmap->new();
14107: if (defined($navmap)) {
14108: my $mapres = $navmap->getResourceByUrl($map);
14109: if (ref($mapres)) {
14110: my $pcslist = $mapres->map_hierarchy();
14111: if ($pcslist ne '') {
14112: foreach my $pc (split(/,/,$pcslist)) {
14113: my $res = $navmap->getByMapPc($pc);
14114: if (ref($res)) {
14115: my $title = $res->compTitle();
14116: $title =~ s/\W+/_/g;
14117: if ($title ne '') {
1.1149 raeburn 14118: if (($pc > 1) && (length($title) > 12)) {
14119: $title = substr($title,0,12);
14120: }
1.1015 raeburn 14121: push(@pathitems,$title);
14122: }
14123: }
14124: }
14125: }
14126: my $maptitle = $mapres->compTitle();
14127: $maptitle =~ s/\W+/_/g;
14128: if ($maptitle ne '') {
1.1149 raeburn 14129: if (length($maptitle) > 12) {
14130: $maptitle = substr($maptitle,0,12);
14131: }
1.1015 raeburn 14132: push(@pathitems,$maptitle);
14133: }
14134: unless ($env{'request.state'} eq 'construct') {
14135: my $res = $navmap->getBySymb($symb);
14136: if (ref($res)) {
14137: my $partlist = $res->parts();
14138: my $totaluploads = 0;
14139: if (ref($partlist) eq 'ARRAY') {
14140: foreach my $part (@{$partlist}) {
14141: my @types = $res->responseType($part);
14142: my @ids = $res->responseIds($part);
14143: for (my $i=0; $i < scalar(@ids); $i++) {
14144: if ($types[$i] eq 'essay') {
14145: my $partid = $part.'_'.$ids[$i];
14146: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
14147: $totaluploads ++;
14148: }
14149: }
14150: }
14151: }
14152: if ($totaluploads > 1) {
14153: $multiresp = 1;
14154: }
14155: }
14156: }
14157: }
14158: } else {
14159: return;
14160: }
14161: } else {
14162: return;
14163: }
14164: my $restitle=&Apache::lonnet::gettitle($symb);
14165: $restitle =~ s/\W+/_/g;
14166: if ($restitle eq '') {
14167: $restitle = ($resurl =~ m{/[^/]+$});
14168: if ($restitle eq '') {
14169: $restitle = time;
14170: }
14171: }
1.1149 raeburn 14172: if (length($restitle) > 12) {
14173: $restitle = substr($restitle,0,12);
14174: }
1.1015 raeburn 14175: push(@pathitems,$restitle);
14176: $path .= join('/',@pathitems);
14177: }
14178: return ($path,$multiresp);
14179: }
14180:
14181: =pod
14182:
1.464 albertel 14183: =back
1.41 ng 14184:
1.112 bowersj2 14185: =head1 CSV Upload/Handling functions
1.38 albertel 14186:
1.41 ng 14187: =over 4
14188:
1.648 raeburn 14189: =item * &upfile_store($r)
1.41 ng 14190:
14191: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 14192: needs $env{'form.upfile'}
1.41 ng 14193: returns $datatoken to be put into hidden field
14194:
14195: =cut
1.31 albertel 14196:
14197: sub upfile_store {
14198: my $r=shift;
1.258 albertel 14199: $env{'form.upfile'}=~s/\r/\n/gs;
14200: $env{'form.upfile'}=~s/\f/\n/gs;
14201: $env{'form.upfile'}=~s/\n+/\n/gs;
14202: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 14203:
1.1299 raeburn 14204: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
14205: '_enroll_'.$env{'request.course.id'}.'_'.
14206: time.'_'.$$);
14207: return if ($datatoken eq '');
14208:
1.31 albertel 14209: {
1.158 raeburn 14210: my $datafile = $r->dir_config('lonDaemons').
14211: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14212: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 14213: print $fh $env{'form.upfile'};
1.158 raeburn 14214: close($fh);
14215: }
1.31 albertel 14216: }
14217: return $datatoken;
14218: }
14219:
1.56 matthew 14220: =pod
14221:
1.1290 raeburn 14222: =item * &load_tmp_file($r,$datatoken)
1.41 ng 14223:
14224: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 14225: $datatoken is the name to assign to the temporary file.
1.258 albertel 14226: sets $env{'form.upfile'} to the contents of the file
1.41 ng 14227:
14228: =cut
1.31 albertel 14229:
14230: sub load_tmp_file {
1.1290 raeburn 14231: my ($r,$datatoken) = @_;
14232: return if ($datatoken eq '');
1.31 albertel 14233: my @studentdata=();
14234: {
1.158 raeburn 14235: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 14236: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 14237: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 14238: @studentdata=<$fh>;
14239: close($fh);
14240: }
1.31 albertel 14241: }
1.258 albertel 14242: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 14243: }
14244:
1.1290 raeburn 14245: sub valid_datatoken {
14246: my ($datatoken) = @_;
1.1325 raeburn 14247: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_(|$match_domain\_$match_courseid)\_\d+_\d+$/) {
1.1290 raeburn 14248: return $datatoken;
14249: }
14250: return;
14251: }
14252:
1.56 matthew 14253: =pod
14254:
1.648 raeburn 14255: =item * &upfile_record_sep()
1.41 ng 14256:
14257: Separate uploaded file into records
14258: returns array of records,
1.258 albertel 14259: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 14260:
14261: =cut
1.31 albertel 14262:
14263: sub upfile_record_sep {
1.258 albertel 14264: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 14265: } else {
1.248 albertel 14266: my @records;
1.258 albertel 14267: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 14268: if ($line=~/^\s*$/) { next; }
14269: push(@records,$line);
14270: }
14271: return @records;
1.31 albertel 14272: }
14273: }
14274:
1.56 matthew 14275: =pod
14276:
1.648 raeburn 14277: =item * &record_sep($record)
1.41 ng 14278:
1.258 albertel 14279: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 14280:
14281: =cut
14282:
1.263 www 14283: sub takeleft {
14284: my $index=shift;
14285: return substr('0000'.$index,-4,4);
14286: }
14287:
1.31 albertel 14288: sub record_sep {
14289: my $record=shift;
14290: my %components=();
1.258 albertel 14291: if ($env{'form.upfiletype'} eq 'xml') {
14292: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 14293: my $i=0;
1.356 albertel 14294: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 14295: $field=~s/^(\"|\')//;
14296: $field=~s/(\"|\')$//;
1.263 www 14297: $components{&takeleft($i)}=$field;
1.31 albertel 14298: $i++;
14299: }
1.258 albertel 14300: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 14301: my $i=0;
1.356 albertel 14302: foreach my $field (split(/\t/,$record)) {
1.31 albertel 14303: $field=~s/^(\"|\')//;
14304: $field=~s/(\"|\')$//;
1.263 www 14305: $components{&takeleft($i)}=$field;
1.31 albertel 14306: $i++;
14307: }
14308: } else {
1.561 www 14309: my $separator=',';
1.480 banghart 14310: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14311: $separator=';';
1.480 banghart 14312: }
1.31 albertel 14313: my $i=0;
1.561 www 14314: # the character we are looking for to indicate the end of a quote or a record
14315: my $looking_for=$separator;
14316: # do not add the characters to the fields
14317: my $ignore=0;
14318: # we just encountered a separator (or the beginning of the record)
14319: my $just_found_separator=1;
14320: # store the field we are working on here
14321: my $field='';
14322: # work our way through all characters in record
14323: foreach my $character ($record=~/(.)/g) {
14324: if ($character eq $looking_for) {
14325: if ($character ne $separator) {
14326: # Found the end of a quote, again looking for separator
14327: $looking_for=$separator;
14328: $ignore=1;
14329: } else {
14330: # Found a separator, store away what we got
14331: $components{&takeleft($i)}=$field;
14332: $i++;
14333: $just_found_separator=1;
14334: $ignore=0;
14335: $field='';
14336: }
14337: next;
14338: }
14339: # single or double quotation marks after a separator indicate beginning of a quote
14340: # we are now looking for the end of the quote and need to ignore separators
14341: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14342: $looking_for=$character;
14343: next;
14344: }
14345: # ignore would be true after we reached the end of a quote
14346: if ($ignore) { next; }
14347: if (($just_found_separator) && ($character=~/\s/)) { next; }
14348: $field.=$character;
14349: $just_found_separator=0;
1.31 albertel 14350: }
1.561 www 14351: # catch the very last entry, since we never encountered the separator
14352: $components{&takeleft($i)}=$field;
1.31 albertel 14353: }
14354: return %components;
14355: }
14356:
1.144 matthew 14357: ######################################################
14358: ######################################################
14359:
1.56 matthew 14360: =pod
14361:
1.648 raeburn 14362: =item * &upfile_select_html()
1.41 ng 14363:
1.144 matthew 14364: Return HTML code to select a file from the users machine and specify
14365: the file type.
1.41 ng 14366:
14367: =cut
14368:
1.144 matthew 14369: ######################################################
14370: ######################################################
1.31 albertel 14371: sub upfile_select_html {
1.144 matthew 14372: my %Types = (
14373: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14374: semisv => &mt('Semicolon separated values'),
1.144 matthew 14375: space => &mt('Space separated'),
14376: tab => &mt('Tabulator separated'),
14377: # xml => &mt('HTML/XML'),
14378: );
14379: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14380: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14381: foreach my $type (sort(keys(%Types))) {
14382: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14383: }
14384: $Str .= "</select>\n";
14385: return $Str;
1.31 albertel 14386: }
14387:
1.301 albertel 14388: sub get_samples {
14389: my ($records,$toget) = @_;
14390: my @samples=({});
14391: my $got=0;
14392: foreach my $rec (@$records) {
14393: my %temp = &record_sep($rec);
14394: if (! grep(/\S/, values(%temp))) { next; }
14395: if (%temp) {
14396: $samples[$got]=\%temp;
14397: $got++;
14398: if ($got == $toget) { last; }
14399: }
14400: }
14401: return \@samples;
14402: }
14403:
1.144 matthew 14404: ######################################################
14405: ######################################################
14406:
1.56 matthew 14407: =pod
14408:
1.648 raeburn 14409: =item * &csv_print_samples($r,$records)
1.41 ng 14410:
14411: Prints a table of sample values from each column uploaded $r is an
14412: Apache Request ref, $records is an arrayref from
14413: &Apache::loncommon::upfile_record_sep
14414:
14415: =cut
14416:
1.144 matthew 14417: ######################################################
14418: ######################################################
1.31 albertel 14419: sub csv_print_samples {
14420: my ($r,$records) = @_;
1.662 bisitz 14421: my $samples = &get_samples($records,5);
1.301 albertel 14422:
1.594 raeburn 14423: $r->print(&mt('Samples').'<br />'.&start_data_table().
14424: &start_data_table_header_row());
1.356 albertel 14425: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14426: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14427: $r->print(&end_data_table_header_row());
1.301 albertel 14428: foreach my $hash (@$samples) {
1.594 raeburn 14429: $r->print(&start_data_table_row());
1.356 albertel 14430: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14431: $r->print('<td>');
1.356 albertel 14432: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14433: $r->print('</td>');
14434: }
1.594 raeburn 14435: $r->print(&end_data_table_row());
1.31 albertel 14436: }
1.594 raeburn 14437: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14438: }
14439:
1.144 matthew 14440: ######################################################
14441: ######################################################
14442:
1.56 matthew 14443: =pod
14444:
1.648 raeburn 14445: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14446:
14447: Prints a table to create associations between values and table columns.
1.144 matthew 14448:
1.41 ng 14449: $r is an Apache Request ref,
14450: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14451: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14452:
14453: =cut
14454:
1.144 matthew 14455: ######################################################
14456: ######################################################
1.31 albertel 14457: sub csv_print_select_table {
14458: my ($r,$records,$d) = @_;
1.301 albertel 14459: my $i=0;
14460: my $samples = &get_samples($records,1);
1.144 matthew 14461: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14462: &start_data_table().&start_data_table_header_row().
1.144 matthew 14463: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14464: '<th>'.&mt('Column').'</th>'.
14465: &end_data_table_header_row()."\n");
1.356 albertel 14466: foreach my $array_ref (@$d) {
14467: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14468: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14469:
1.875 bisitz 14470: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14471: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14472: $r->print('<option value="none"></option>');
1.356 albertel 14473: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14474: $r->print('<option value="'.$sample.'"'.
14475: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14476: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14477: }
1.594 raeburn 14478: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14479: $i++;
14480: }
1.594 raeburn 14481: $r->print(&end_data_table());
1.31 albertel 14482: $i--;
14483: return $i;
14484: }
1.56 matthew 14485:
1.144 matthew 14486: ######################################################
14487: ######################################################
14488:
1.56 matthew 14489: =pod
1.31 albertel 14490:
1.648 raeburn 14491: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14492:
14493: Prints a table of sample values from the upload and can make associate samples to internal names.
14494:
14495: $r is an Apache Request ref,
14496: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14497: $d is an array of 2 element arrays (internal name, displayed name)
14498:
14499: =cut
14500:
1.144 matthew 14501: ######################################################
14502: ######################################################
1.31 albertel 14503: sub csv_samples_select_table {
14504: my ($r,$records,$d) = @_;
14505: my $i=0;
1.144 matthew 14506: #
1.662 bisitz 14507: my $max_samples = 5;
14508: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14509: $r->print(&start_data_table().
14510: &start_data_table_header_row().'<th>'.
14511: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14512: &end_data_table_header_row());
1.301 albertel 14513:
14514: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14515: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14516: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14517: foreach my $option (@$d) {
14518: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14519: $r->print('<option value="'.$value.'"'.
1.253 albertel 14520: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14521: $display.'</option>');
1.31 albertel 14522: }
14523: $r->print('</select></td><td>');
1.662 bisitz 14524: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14525: if (defined($samples->[$line]{$key})) {
14526: $r->print($samples->[$line]{$key}."<br />\n");
14527: }
14528: }
1.594 raeburn 14529: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14530: $i++;
14531: }
1.594 raeburn 14532: $r->print(&end_data_table());
1.31 albertel 14533: $i--;
14534: return($i);
1.115 matthew 14535: }
14536:
1.144 matthew 14537: ######################################################
14538: ######################################################
14539:
1.115 matthew 14540: =pod
14541:
1.648 raeburn 14542: =item * &clean_excel_name($name)
1.115 matthew 14543:
14544: Returns a replacement for $name which does not contain any illegal characters.
14545:
14546: =cut
14547:
1.144 matthew 14548: ######################################################
14549: ######################################################
1.115 matthew 14550: sub clean_excel_name {
14551: my ($name) = @_;
14552: $name =~ s/[:\*\?\/\\]//g;
14553: if (length($name) > 31) {
14554: $name = substr($name,0,31);
14555: }
14556: return $name;
1.25 albertel 14557: }
1.84 albertel 14558:
1.85 albertel 14559: =pod
14560:
1.648 raeburn 14561: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14562:
14563: Returns either 1 or undef
14564:
14565: 1 if the part is to be hidden, undef if it is to be shown
14566:
14567: Arguments are:
14568:
14569: $id the id of the part to be checked
14570: $symb, optional the symb of the resource to check
14571: $udom, optional the domain of the user to check for
14572: $uname, optional the username of the user to check for
14573:
14574: =cut
1.84 albertel 14575:
14576: sub check_if_partid_hidden {
14577: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14578: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14579: $symb,$udom,$uname);
1.141 albertel 14580: my $truth=1;
14581: #if the string starts with !, then the list is the list to show not hide
14582: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14583: my @hiddenlist=split(/,/,$hiddenparts);
14584: foreach my $checkid (@hiddenlist) {
1.141 albertel 14585: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14586: }
1.141 albertel 14587: return !$truth;
1.84 albertel 14588: }
1.127 matthew 14589:
1.138 matthew 14590:
14591: ############################################################
14592: ############################################################
14593:
14594: =pod
14595:
1.157 matthew 14596: =back
14597:
1.138 matthew 14598: =head1 cgi-bin script and graphing routines
14599:
1.157 matthew 14600: =over 4
14601:
1.648 raeburn 14602: =item * &get_cgi_id()
1.138 matthew 14603:
14604: Inputs: none
14605:
14606: Returns an id which can be used to pass environment variables
14607: to various cgi-bin scripts. These environment variables will
14608: be removed from the users environment after a given time by
14609: the routine &Apache::lonnet::transfer_profile_to_env.
14610:
14611: =cut
14612:
14613: ############################################################
14614: ############################################################
1.152 albertel 14615: my $uniq=0;
1.136 matthew 14616: sub get_cgi_id {
1.154 albertel 14617: $uniq=($uniq+1)%100000;
1.280 albertel 14618: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14619: }
14620:
1.127 matthew 14621: ############################################################
14622: ############################################################
14623:
14624: =pod
14625:
1.648 raeburn 14626: =item * &DrawBarGraph()
1.127 matthew 14627:
1.138 matthew 14628: Facilitates the plotting of data in a (stacked) bar graph.
14629: Puts plot definition data into the users environment in order for
14630: graph.png to plot it. Returns an <img> tag for the plot.
14631: The bars on the plot are labeled '1','2',...,'n'.
14632:
14633: Inputs:
14634:
14635: =over 4
14636:
14637: =item $Title: string, the title of the plot
14638:
14639: =item $xlabel: string, text describing the X-axis of the plot
14640:
14641: =item $ylabel: string, text describing the Y-axis of the plot
14642:
14643: =item $Max: scalar, the maximum Y value to use in the plot
14644: If $Max is < any data point, the graph will not be rendered.
14645:
1.140 matthew 14646: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14647: they are plotted. If undefined, default values will be used.
14648:
1.178 matthew 14649: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14650:
1.138 matthew 14651: =item @Values: An array of array references. Each array reference holds data
14652: to be plotted in a stacked bar chart.
14653:
1.239 matthew 14654: =item If the final element of @Values is a hash reference the key/value
14655: pairs will be added to the graph definition.
14656:
1.138 matthew 14657: =back
14658:
14659: Returns:
14660:
14661: An <img> tag which references graph.png and the appropriate identifying
14662: information for the plot.
14663:
1.127 matthew 14664: =cut
14665:
14666: ############################################################
14667: ############################################################
1.134 matthew 14668: sub DrawBarGraph {
1.178 matthew 14669: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14670: #
14671: if (! defined($colors)) {
14672: $colors = ['#33ff00',
14673: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14674: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14675: ];
14676: }
1.228 matthew 14677: my $extra_settings = {};
14678: if (ref($Values[-1]) eq 'HASH') {
14679: $extra_settings = pop(@Values);
14680: }
1.127 matthew 14681: #
1.136 matthew 14682: my $identifier = &get_cgi_id();
14683: my $id = 'cgi.'.$identifier;
1.129 matthew 14684: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14685: return '';
14686: }
1.225 matthew 14687: #
14688: my @Labels;
14689: if (defined($labels)) {
14690: @Labels = @$labels;
14691: } else {
14692: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14693: push(@Labels,$i+1);
1.225 matthew 14694: }
14695: }
14696: #
1.129 matthew 14697: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14698: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14699: my %ValuesHash;
14700: my $NumSets=1;
14701: foreach my $array (@Values) {
14702: next if (! ref($array));
1.136 matthew 14703: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14704: join(',',@$array);
1.129 matthew 14705: }
1.127 matthew 14706: #
1.136 matthew 14707: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14708: if ($NumBars < 3) {
14709: $width = 120+$NumBars*32;
1.220 matthew 14710: $xskip = 1;
1.225 matthew 14711: $bar_width = 30;
14712: } elsif ($NumBars < 5) {
14713: $width = 120+$NumBars*20;
14714: $xskip = 1;
14715: $bar_width = 20;
1.220 matthew 14716: } elsif ($NumBars < 10) {
1.136 matthew 14717: $width = 120+$NumBars*15;
14718: $xskip = 1;
14719: $bar_width = 15;
14720: } elsif ($NumBars <= 25) {
14721: $width = 120+$NumBars*11;
14722: $xskip = 5;
14723: $bar_width = 8;
14724: } elsif ($NumBars <= 50) {
14725: $width = 120+$NumBars*8;
14726: $xskip = 5;
14727: $bar_width = 4;
14728: } else {
14729: $width = 120+$NumBars*8;
14730: $xskip = 5;
14731: $bar_width = 4;
14732: }
14733: #
1.137 matthew 14734: $Max = 1 if ($Max < 1);
14735: if ( int($Max) < $Max ) {
14736: $Max++;
14737: $Max = int($Max);
14738: }
1.127 matthew 14739: $Title = '' if (! defined($Title));
14740: $xlabel = '' if (! defined($xlabel));
14741: $ylabel = '' if (! defined($ylabel));
1.369 www 14742: $ValuesHash{$id.'.title'} = &escape($Title);
14743: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14744: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14745: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14746: $ValuesHash{$id.'.NumBars'} = $NumBars;
14747: $ValuesHash{$id.'.NumSets'} = $NumSets;
14748: $ValuesHash{$id.'.PlotType'} = 'bar';
14749: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14750: $ValuesHash{$id.'.height'} = $height;
14751: $ValuesHash{$id.'.width'} = $width;
14752: $ValuesHash{$id.'.xskip'} = $xskip;
14753: $ValuesHash{$id.'.bar_width'} = $bar_width;
14754: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14755: #
1.228 matthew 14756: # Deal with other parameters
14757: while (my ($key,$value) = each(%$extra_settings)) {
14758: $ValuesHash{$id.'.'.$key} = $value;
14759: }
14760: #
1.646 raeburn 14761: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14762: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14763: }
14764:
14765: ############################################################
14766: ############################################################
14767:
14768: =pod
14769:
1.648 raeburn 14770: =item * &DrawXYGraph()
1.137 matthew 14771:
1.138 matthew 14772: Facilitates the plotting of data in an XY graph.
14773: Puts plot definition data into the users environment in order for
14774: graph.png to plot it. Returns an <img> tag for the plot.
14775:
14776: Inputs:
14777:
14778: =over 4
14779:
14780: =item $Title: string, the title of the plot
14781:
14782: =item $xlabel: string, text describing the X-axis of the plot
14783:
14784: =item $ylabel: string, text describing the Y-axis of the plot
14785:
14786: =item $Max: scalar, the maximum Y value to use in the plot
14787: If $Max is < any data point, the graph will not be rendered.
14788:
14789: =item $colors: Array ref containing the hex color codes for the data to be
14790: plotted in. If undefined, default values will be used.
14791:
14792: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14793:
14794: =item $Ydata: Array ref containing Array refs.
1.185 www 14795: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14796:
14797: =item %Values: hash indicating or overriding any default values which are
14798: passed to graph.png.
14799: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14800:
14801: =back
14802:
14803: Returns:
14804:
14805: An <img> tag which references graph.png and the appropriate identifying
14806: information for the plot.
14807:
1.137 matthew 14808: =cut
14809:
14810: ############################################################
14811: ############################################################
14812: sub DrawXYGraph {
14813: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14814: #
14815: # Create the identifier for the graph
14816: my $identifier = &get_cgi_id();
14817: my $id = 'cgi.'.$identifier;
14818: #
14819: $Title = '' if (! defined($Title));
14820: $xlabel = '' if (! defined($xlabel));
14821: $ylabel = '' if (! defined($ylabel));
14822: my %ValuesHash =
14823: (
1.369 www 14824: $id.'.title' => &escape($Title),
14825: $id.'.xlabel' => &escape($xlabel),
14826: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14827: $id.'.y_max_value'=> $Max,
14828: $id.'.labels' => join(',',@$Xlabels),
14829: $id.'.PlotType' => 'XY',
14830: );
14831: #
14832: if (defined($colors) && ref($colors) eq 'ARRAY') {
14833: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14834: }
14835: #
14836: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14837: return '';
14838: }
14839: my $NumSets=1;
1.138 matthew 14840: foreach my $array (@{$Ydata}){
1.137 matthew 14841: next if (! ref($array));
14842: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14843: }
1.138 matthew 14844: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14845: #
14846: # Deal with other parameters
14847: while (my ($key,$value) = each(%Values)) {
14848: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14849: }
14850: #
1.646 raeburn 14851: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14852: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14853: }
14854:
14855: ############################################################
14856: ############################################################
14857:
14858: =pod
14859:
1.648 raeburn 14860: =item * &DrawXYYGraph()
1.138 matthew 14861:
14862: Facilitates the plotting of data in an XY graph with two Y axes.
14863: Puts plot definition data into the users environment in order for
14864: graph.png to plot it. Returns an <img> tag for the plot.
14865:
14866: Inputs:
14867:
14868: =over 4
14869:
14870: =item $Title: string, the title of the plot
14871:
14872: =item $xlabel: string, text describing the X-axis of the plot
14873:
14874: =item $ylabel: string, text describing the Y-axis of the plot
14875:
14876: =item $colors: Array ref containing the hex color codes for the data to be
14877: plotted in. If undefined, default values will be used.
14878:
14879: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14880:
14881: =item $Ydata1: The first data set
14882:
14883: =item $Min1: The minimum value of the left Y-axis
14884:
14885: =item $Max1: The maximum value of the left Y-axis
14886:
14887: =item $Ydata2: The second data set
14888:
14889: =item $Min2: The minimum value of the right Y-axis
14890:
14891: =item $Max2: The maximum value of the left Y-axis
14892:
14893: =item %Values: hash indicating or overriding any default values which are
14894: passed to graph.png.
14895: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14896:
14897: =back
14898:
14899: Returns:
14900:
14901: An <img> tag which references graph.png and the appropriate identifying
14902: information for the plot.
1.136 matthew 14903:
14904: =cut
14905:
14906: ############################################################
14907: ############################################################
1.137 matthew 14908: sub DrawXYYGraph {
14909: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14910: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14911: #
14912: # Create the identifier for the graph
14913: my $identifier = &get_cgi_id();
14914: my $id = 'cgi.'.$identifier;
14915: #
14916: $Title = '' if (! defined($Title));
14917: $xlabel = '' if (! defined($xlabel));
14918: $ylabel = '' if (! defined($ylabel));
14919: my %ValuesHash =
14920: (
1.369 www 14921: $id.'.title' => &escape($Title),
14922: $id.'.xlabel' => &escape($xlabel),
14923: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14924: $id.'.labels' => join(',',@$Xlabels),
14925: $id.'.PlotType' => 'XY',
14926: $id.'.NumSets' => 2,
1.137 matthew 14927: $id.'.two_axes' => 1,
14928: $id.'.y1_max_value' => $Max1,
14929: $id.'.y1_min_value' => $Min1,
14930: $id.'.y2_max_value' => $Max2,
14931: $id.'.y2_min_value' => $Min2,
1.136 matthew 14932: );
14933: #
1.137 matthew 14934: if (defined($colors) && ref($colors) eq 'ARRAY') {
14935: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14936: }
14937: #
14938: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14939: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14940: return '';
14941: }
14942: my $NumSets=1;
1.137 matthew 14943: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14944: next if (! ref($array));
14945: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14946: }
14947: #
14948: # Deal with other parameters
14949: while (my ($key,$value) = each(%Values)) {
14950: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14951: }
14952: #
1.646 raeburn 14953: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14954: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14955: }
14956:
14957: ############################################################
14958: ############################################################
14959:
14960: =pod
14961:
1.157 matthew 14962: =back
14963:
1.139 matthew 14964: =head1 Statistics helper routines?
14965:
14966: Bad place for them but what the hell.
14967:
1.157 matthew 14968: =over 4
14969:
1.648 raeburn 14970: =item * &chartlink()
1.139 matthew 14971:
14972: Returns a link to the chart for a specific student.
14973:
14974: Inputs:
14975:
14976: =over 4
14977:
14978: =item $linktext: The text of the link
14979:
14980: =item $sname: The students username
14981:
14982: =item $sdomain: The students domain
14983:
14984: =back
14985:
1.157 matthew 14986: =back
14987:
1.139 matthew 14988: =cut
14989:
14990: ############################################################
14991: ############################################################
14992: sub chartlink {
14993: my ($linktext, $sname, $sdomain) = @_;
14994: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14995: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14996: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14997: '">'.$linktext.'</a>';
1.153 matthew 14998: }
14999:
15000: #######################################################
15001: #######################################################
15002:
15003: =pod
15004:
15005: =head1 Course Environment Routines
1.157 matthew 15006:
15007: =over 4
1.153 matthew 15008:
1.648 raeburn 15009: =item * &restore_course_settings()
1.153 matthew 15010:
1.648 raeburn 15011: =item * &store_course_settings()
1.153 matthew 15012:
15013: Restores/Store indicated form parameters from the course environment.
15014: Will not overwrite existing values of the form parameters.
15015:
15016: Inputs:
15017: a scalar describing the data (e.g. 'chart', 'problem_analysis')
15018:
15019: a hash ref describing the data to be stored. For example:
15020:
15021: %Save_Parameters = ('Status' => 'scalar',
15022: 'chartoutputmode' => 'scalar',
15023: 'chartoutputdata' => 'scalar',
15024: 'Section' => 'array',
1.373 raeburn 15025: 'Group' => 'array',
1.153 matthew 15026: 'StudentData' => 'array',
15027: 'Maps' => 'array');
15028:
15029: Returns: both routines return nothing
15030:
1.631 raeburn 15031: =back
15032:
1.153 matthew 15033: =cut
15034:
15035: #######################################################
15036: #######################################################
15037: sub store_course_settings {
1.496 albertel 15038: return &store_settings($env{'request.course.id'},@_);
15039: }
15040:
15041: sub store_settings {
1.153 matthew 15042: # save to the environment
15043: # appenv the same items, just to be safe
1.300 albertel 15044: my $udom = $env{'user.domain'};
15045: my $uname = $env{'user.name'};
1.496 albertel 15046: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15047: my %SaveHash;
15048: my %AppHash;
15049: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 15050: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 15051: my $envname = 'environment.'.$basename;
1.258 albertel 15052: if (exists($env{'form.'.$setting})) {
1.153 matthew 15053: # Save this value away
15054: if ($type eq 'scalar' &&
1.258 albertel 15055: (! exists($env{$envname}) ||
15056: $env{$envname} ne $env{'form.'.$setting})) {
15057: $SaveHash{$basename} = $env{'form.'.$setting};
15058: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 15059: } elsif ($type eq 'array') {
15060: my $stored_form;
1.258 albertel 15061: if (ref($env{'form.'.$setting})) {
1.153 matthew 15062: $stored_form = join(',',
15063: map {
1.369 www 15064: &escape($_);
1.258 albertel 15065: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 15066: } else {
15067: $stored_form =
1.369 www 15068: &escape($env{'form.'.$setting});
1.153 matthew 15069: }
15070: # Determine if the array contents are the same.
1.258 albertel 15071: if ($stored_form ne $env{$envname}) {
1.153 matthew 15072: $SaveHash{$basename} = $stored_form;
15073: $AppHash{$envname} = $stored_form;
15074: }
15075: }
15076: }
15077: }
15078: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 15079: $udom,$uname);
1.153 matthew 15080: if ($put_result !~ /^(ok|delayed)/) {
15081: &Apache::lonnet::logthis('unable to save form parameters, '.
15082: 'got error:'.$put_result);
15083: }
15084: # Make sure these settings stick around in this session, too
1.646 raeburn 15085: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 15086: return;
15087: }
15088:
15089: sub restore_course_settings {
1.499 albertel 15090: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 15091: }
15092:
15093: sub restore_settings {
15094: my ($context,$prefix,$Settings) = @_;
1.153 matthew 15095: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 15096: next if (exists($env{'form.'.$setting}));
1.496 albertel 15097: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 15098: '.'.$setting;
1.258 albertel 15099: if (exists($env{$envname})) {
1.153 matthew 15100: if ($type eq 'scalar') {
1.258 albertel 15101: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 15102: } elsif ($type eq 'array') {
1.258 albertel 15103: $env{'form.'.$setting} = [
1.153 matthew 15104: map {
1.369 www 15105: &unescape($_);
1.258 albertel 15106: } split(',',$env{$envname})
1.153 matthew 15107: ];
15108: }
15109: }
15110: }
1.127 matthew 15111: }
15112:
1.618 raeburn 15113: #######################################################
15114: #######################################################
15115:
15116: =pod
15117:
15118: =head1 Domain E-mail Routines
15119:
15120: =over 4
15121:
1.648 raeburn 15122: =item * &build_recipient_list()
1.618 raeburn 15123:
1.1144 raeburn 15124: Build recipient lists for following types of e-mail:
1.766 raeburn 15125: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 15126: (d) Help requests, (e) Course requests needing approval, (f) loncapa
15127: module change checking, student/employee ID conflict checks, as
15128: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
15129: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 15130:
15131: Inputs:
1.619 raeburn 15132: defmail (scalar - email address of default recipient),
1.1144 raeburn 15133: mailing type (scalar: errormail, packagesmail, helpdeskmail,
15134: requestsmail, updatesmail, or idconflictsmail).
15135:
1.619 raeburn 15136: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 15137:
1.619 raeburn 15138: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 15139: i.e., predates configuration by DC via domainprefs.pm
15140:
15141: $requname username of requester (if mailing type is helpdeskmail)
15142:
15143: $requdom domain of requester (if mailing type is helpdeskmail)
15144:
15145: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
15146:
1.618 raeburn 15147:
1.655 raeburn 15148: Returns: comma separated list of addresses to which to send e-mail.
15149:
15150: =back
1.618 raeburn 15151:
15152: =cut
15153:
15154: ############################################################
15155: ############################################################
15156: sub build_recipient_list {
1.1297 raeburn 15157: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 15158: my @recipients;
1.1270 raeburn 15159: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 15160: my %domconfig =
1.1270 raeburn 15161: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 15162: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 15163: if (exists($domconfig{'contacts'}{$mailing})) {
15164: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
15165: my @contacts = ('adminemail','supportemail');
15166: foreach my $item (@contacts) {
15167: if ($domconfig{'contacts'}{$mailing}{$item}) {
15168: my $addr = $domconfig{'contacts'}{$item};
15169: if (!grep(/^\Q$addr\E$/,@recipients)) {
15170: push(@recipients,$addr);
15171: }
1.619 raeburn 15172: }
1.1270 raeburn 15173: }
15174: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
15175: if ($mailing eq 'helpdeskmail') {
15176: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
15177: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
15178: my @ok_bccs;
15179: foreach my $bcc (@bccs) {
15180: $bcc =~ s/^\s+//g;
15181: $bcc =~ s/\s+$//g;
15182: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15183: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15184: push(@ok_bccs,$bcc);
15185: }
15186: }
15187: }
15188: if (@ok_bccs > 0) {
15189: $allbcc = join(', ',@ok_bccs);
15190: }
15191: }
15192: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 15193: }
15194: }
1.766 raeburn 15195: } elsif ($origmail ne '') {
1.1270 raeburn 15196: $lastresort = $origmail;
1.618 raeburn 15197: }
1.1297 raeburn 15198: if ($mailing eq 'helpdeskmail') {
15199: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
15200: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
15201: my ($inststatus,$inststatus_checked);
15202: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
15203: ($env{'user.domain'} ne 'public')) {
15204: $inststatus_checked = 1;
15205: $inststatus = $env{'environment.inststatus'};
15206: }
15207: unless ($inststatus_checked) {
15208: if (($requname ne '') && ($requdom ne '')) {
15209: if (($requname =~ /^$match_username$/) &&
15210: ($requdom =~ /^$match_domain$/) &&
15211: (&Apache::lonnet::domain($requdom))) {
15212: my $requhome = &Apache::lonnet::homeserver($requname,
15213: $requdom);
15214: unless ($requhome eq 'no_host') {
15215: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
15216: $inststatus = $userenv{'inststatus'};
15217: $inststatus_checked = 1;
15218: }
15219: }
15220: }
15221: }
15222: unless ($inststatus_checked) {
15223: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
15224: my %srch = (srchby => 'email',
15225: srchdomain => $defdom,
15226: srchterm => $reqemail,
15227: srchtype => 'exact');
15228: my %srch_results = &Apache::lonnet::usersearch(\%srch);
15229: foreach my $uname (keys(%srch_results)) {
15230: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15231: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15232: $inststatus_checked = 1;
15233: last;
15234: }
15235: }
15236: unless ($inststatus_checked) {
15237: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
15238: if ($dirsrchres eq 'ok') {
15239: foreach my $uname (keys(%srch_results)) {
15240: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
15241: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
15242: $inststatus_checked = 1;
15243: last;
15244: }
15245: }
15246: }
15247: }
15248: }
15249: }
15250: if ($inststatus ne '') {
15251: foreach my $status (split(/\:/,$inststatus)) {
15252: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
15253: my @contacts = ('adminemail','supportemail');
15254: foreach my $item (@contacts) {
15255: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
15256: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
15257: if (!grep(/^\Q$addr\E$/,@recipients)) {
15258: push(@recipients,$addr);
15259: }
15260: }
15261: }
15262: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
15263: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
15264: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
15265: my @ok_bccs;
15266: foreach my $bcc (@bccs) {
15267: $bcc =~ s/^\s+//g;
15268: $bcc =~ s/\s+$//g;
15269: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15270: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15271: push(@ok_bccs,$bcc);
15272: }
15273: }
15274: }
15275: if (@ok_bccs > 0) {
15276: $allbcc = join(', ',@ok_bccs);
15277: }
15278: }
15279: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
15280: last;
15281: }
15282: }
15283: }
15284: }
15285: }
1.619 raeburn 15286: } elsif ($origmail ne '') {
1.1270 raeburn 15287: $lastresort = $origmail;
15288: }
1.1297 raeburn 15289: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 15290: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
15291: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
15292: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
15293: my %what = (
15294: perlvar => 1,
15295: );
15296: my $primary = &Apache::lonnet::domain($defdom,'primary');
15297: if ($primary) {
15298: my $gotaddr;
15299: my ($result,$returnhash) =
15300: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
15301: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
15302: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
15303: $lastresort = $returnhash->{'lonSupportEMail'};
15304: $gotaddr = 1;
15305: }
15306: }
15307: unless ($gotaddr) {
15308: my $uintdom = &Apache::lonnet::internet_dom($primary);
15309: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15310: unless ($uintdom eq $intdom) {
15311: my %domconfig =
15312: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15313: if (ref($domconfig{'contacts'}) eq 'HASH') {
15314: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15315: my @contacts = ('adminemail','supportemail');
15316: foreach my $item (@contacts) {
15317: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15318: my $addr = $domconfig{'contacts'}{$item};
15319: if (!grep(/^\Q$addr\E$/,@recipients)) {
15320: push(@recipients,$addr);
15321: }
15322: }
15323: }
15324: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15325: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15326: }
15327: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15328: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15329: my @ok_bccs;
15330: foreach my $bcc (@bccs) {
15331: $bcc =~ s/^\s+//g;
15332: $bcc =~ s/\s+$//g;
15333: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15334: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15335: push(@ok_bccs,$bcc);
15336: }
15337: }
15338: }
15339: if (@ok_bccs > 0) {
15340: $allbcc = join(', ',@ok_bccs);
15341: }
15342: }
15343: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15344: }
15345: }
15346: }
15347: }
15348: }
15349: }
1.618 raeburn 15350: }
1.688 raeburn 15351: if (defined($defmail)) {
15352: if ($defmail ne '') {
15353: push(@recipients,$defmail);
15354: }
1.618 raeburn 15355: }
15356: if ($otheremails) {
1.619 raeburn 15357: my @others;
15358: if ($otheremails =~ /,/) {
15359: @others = split(/,/,$otheremails);
1.618 raeburn 15360: } else {
1.619 raeburn 15361: push(@others,$otheremails);
15362: }
15363: foreach my $addr (@others) {
15364: if (!grep(/^\Q$addr\E$/,@recipients)) {
15365: push(@recipients,$addr);
15366: }
1.618 raeburn 15367: }
15368: }
1.1298 raeburn 15369: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 15370: if ((!@recipients) && ($lastresort ne '')) {
15371: push(@recipients,$lastresort);
15372: }
15373: } elsif ($lastresort ne '') {
15374: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15375: push(@recipients,$lastresort);
15376: }
15377: }
1.1271 raeburn 15378: my $recipientlist = join(',',@recipients);
1.1270 raeburn 15379: if (wantarray) {
15380: return ($recipientlist,$allbcc,$addtext);
15381: } else {
15382: return $recipientlist;
15383: }
1.618 raeburn 15384: }
15385:
1.127 matthew 15386: ############################################################
15387: ############################################################
1.154 albertel 15388:
1.655 raeburn 15389: =pod
15390:
1.1224 musolffc 15391: =over 4
15392:
1.1223 musolffc 15393: =item * &mime_email()
15394:
15395: Sends an email with a possible attachment
15396:
15397: Inputs:
15398:
15399: =over 4
15400:
15401: from - Sender's email address
15402:
1.1343 raeburn 15403: replyto - Reply-To email address
15404:
1.1223 musolffc 15405: to - Email address of recipient
15406:
15407: subject - Subject of email
15408:
15409: body - Body of email
15410:
15411: cc_string - Carbon copy email address
15412:
15413: bcc - Blind carbon copy email address
15414:
15415: attachment_path - Path of file to be attached
15416:
15417: file_name - Name of file to be attached
15418:
15419: attachment_text - The body of an attachment of type "TEXT"
15420:
15421: =back
15422:
15423: =back
15424:
15425: =cut
15426:
15427: ############################################################
15428: ############################################################
15429:
15430: sub mime_email {
1.1343 raeburn 15431: my ($from,$replyto,$to,$subject,$body,$cc_string,$bcc,$attachment_path,
15432: $file_name,$attachment_text) = @_;
15433:
1.1223 musolffc 15434: my $msg = MIME::Lite->new(
15435: From => $from,
15436: To => $to,
15437: Subject => $subject,
15438: Type =>'TEXT',
15439: Data => $body,
15440: );
1.1343 raeburn 15441: if ($replyto ne '') {
15442: $msg->add("Reply-To" => $replyto);
15443: }
1.1223 musolffc 15444: if ($cc_string ne '') {
15445: $msg->add("Cc" => $cc_string);
15446: }
15447: if ($bcc ne '') {
15448: $msg->add("Bcc" => $bcc);
15449: }
15450: $msg->attr("content-type" => "text/plain");
15451: $msg->attr("content-type.charset" => "UTF-8");
15452: # Attach file if given
15453: if ($attachment_path) {
15454: unless ($file_name) {
15455: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
15456: }
15457: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
15458: $msg->attach(Type => $type,
15459: Path => $attachment_path,
15460: Filename => $file_name
15461: );
15462: # Otherwise attach text if given
15463: } elsif ($attachment_text) {
15464: $msg->attach(Type => 'TEXT',
15465: Data => $attachment_text);
15466: }
15467: # Send it
15468: $msg->send('sendmail');
15469: }
15470:
15471: ############################################################
15472: ############################################################
15473:
15474: =pod
15475:
1.655 raeburn 15476: =head1 Course Catalog Routines
15477:
15478: =over 4
15479:
15480: =item * &gather_categories()
15481:
15482: Converts category definitions - keys of categories hash stored in
15483: coursecategories in configuration.db on the primary library server in a
15484: domain - to an array. Also generates javascript and idx hash used to
15485: generate Domain Coordinator interface for editing Course Categories.
15486:
15487: Inputs:
1.663 raeburn 15488:
1.655 raeburn 15489: categories (reference to hash of category definitions).
1.663 raeburn 15490:
1.655 raeburn 15491: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15492: categories and subcategories).
1.663 raeburn 15493:
1.655 raeburn 15494: idx (reference to hash of counters used in Domain Coordinator interface for
15495: editing Course Categories).
1.663 raeburn 15496:
1.655 raeburn 15497: jsarray (reference to array of categories used to create Javascript arrays for
15498: Domain Coordinator interface for editing Course Categories).
15499:
15500: Returns: nothing
15501:
15502: Side effects: populates cats, idx and jsarray.
15503:
15504: =cut
15505:
15506: sub gather_categories {
15507: my ($categories,$cats,$idx,$jsarray) = @_;
15508: my %counters;
15509: my $num = 0;
15510: foreach my $item (keys(%{$categories})) {
15511: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15512: if ($container eq '' && $depth == 0) {
15513: $cats->[$depth][$categories->{$item}] = $cat;
15514: } else {
15515: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15516: }
15517: my ($escitem,$tail) = split(/:/,$item,2);
15518: if ($counters{$tail} eq '') {
15519: $counters{$tail} = $num;
15520: $num ++;
15521: }
15522: if (ref($idx) eq 'HASH') {
15523: $idx->{$item} = $counters{$tail};
15524: }
15525: if (ref($jsarray) eq 'ARRAY') {
15526: push(@{$jsarray->[$counters{$tail}]},$item);
15527: }
15528: }
15529: return;
15530: }
15531:
15532: =pod
15533:
15534: =item * &extract_categories()
15535:
15536: Used to generate breadcrumb trails for course categories.
15537:
15538: Inputs:
1.663 raeburn 15539:
1.655 raeburn 15540: categories (reference to hash of category definitions).
1.663 raeburn 15541:
1.655 raeburn 15542: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15543: categories and subcategories).
1.663 raeburn 15544:
1.655 raeburn 15545: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15546:
1.655 raeburn 15547: allitems (reference to hash - key is category key
15548: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15549:
1.655 raeburn 15550: idx (reference to hash of counters used in Domain Coordinator interface for
15551: editing Course Categories).
1.663 raeburn 15552:
1.655 raeburn 15553: jsarray (reference to array of categories used to create Javascript arrays for
15554: Domain Coordinator interface for editing Course Categories).
15555:
1.665 raeburn 15556: subcats (reference to hash of arrays containing all subcategories within each
15557: category, -recursive)
15558:
1.1321 raeburn 15559: maxd (reference to hash used to hold max depth for all top-level categories).
15560:
1.655 raeburn 15561: Returns: nothing
15562:
15563: Side effects: populates trails and allitems hash references.
15564:
15565: =cut
15566:
15567: sub extract_categories {
1.1321 raeburn 15568: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15569: if (ref($categories) eq 'HASH') {
15570: &gather_categories($categories,$cats,$idx,$jsarray);
15571: if (ref($cats->[0]) eq 'ARRAY') {
15572: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15573: my $name = $cats->[0][$i];
15574: my $item = &escape($name).'::0';
15575: my $trailstr;
15576: if ($name eq 'instcode') {
15577: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15578: } elsif ($name eq 'communities') {
15579: $trailstr = &mt('Communities');
1.1239 raeburn 15580: } elsif ($name eq 'placement') {
15581: $trailstr = &mt('Placement Tests');
1.655 raeburn 15582: } else {
15583: $trailstr = $name;
15584: }
15585: if ($allitems->{$item} eq '') {
15586: push(@{$trails},$trailstr);
15587: $allitems->{$item} = scalar(@{$trails})-1;
15588: }
15589: my @parents = ($name);
15590: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15591: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15592: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15593: if (ref($subcats) eq 'HASH') {
15594: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15595: }
1.1321 raeburn 15596: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15597: }
15598: } else {
15599: if (ref($subcats) eq 'HASH') {
15600: $subcats->{$item} = [];
1.655 raeburn 15601: }
1.1321 raeburn 15602: if (ref($maxd) eq 'HASH') {
15603: $maxd->{$name} = 1;
15604: }
1.655 raeburn 15605: }
15606: }
15607: }
15608: }
15609: return;
15610: }
15611:
15612: =pod
15613:
1.1162 raeburn 15614: =item * &recurse_categories()
1.655 raeburn 15615:
15616: Recursively used to generate breadcrumb trails for course categories.
15617:
15618: Inputs:
1.663 raeburn 15619:
1.655 raeburn 15620: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15621: categories and subcategories).
1.663 raeburn 15622:
1.655 raeburn 15623: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15624:
15625: category (current course category, for which breadcrumb trail is being generated).
15626:
15627: trails (reference to array of breadcrumb trails for each category).
15628:
1.655 raeburn 15629: allitems (reference to hash - key is category key
15630: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15631:
1.655 raeburn 15632: parents (array containing containers directories for current category,
15633: back to top level).
15634:
15635: Returns: nothing
15636:
15637: Side effects: populates trails and allitems hash references
15638:
15639: =cut
15640:
15641: sub recurse_categories {
1.1321 raeburn 15642: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 15643: my $shallower = $depth - 1;
15644: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
15645: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
15646: my $name = $cats->[$depth]{$category}[$k];
15647: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15648: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15649: if ($allitems->{$item} eq '') {
15650: push(@{$trails},$trailstr);
15651: $allitems->{$item} = scalar(@{$trails})-1;
15652: }
15653: my $deeper = $depth+1;
15654: push(@{$parents},$category);
1.665 raeburn 15655: if (ref($subcats) eq 'HASH') {
15656: my $subcat = &escape($name).':'.$category.':'.$depth;
15657: for (my $j=@{$parents}; $j>=0; $j--) {
15658: my $higher;
15659: if ($j > 0) {
15660: $higher = &escape($parents->[$j]).':'.
15661: &escape($parents->[$j-1]).':'.$j;
15662: } else {
15663: $higher = &escape($parents->[$j]).'::'.$j;
15664: }
15665: push(@{$subcats->{$higher}},$subcat);
15666: }
15667: }
15668: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 15669: $subcats,$maxd);
1.655 raeburn 15670: pop(@{$parents});
15671: }
15672: } else {
15673: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15674: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15675: if ($allitems->{$item} eq '') {
15676: push(@{$trails},$trailstr);
15677: $allitems->{$item} = scalar(@{$trails})-1;
15678: }
1.1321 raeburn 15679: if (ref($maxd) eq 'HASH') {
15680: if ($depth > $maxd->{$parents->[0]}) {
15681: $maxd->{$parents->[0]} = $depth;
15682: }
15683: }
1.655 raeburn 15684: }
15685: return;
15686: }
15687:
1.663 raeburn 15688: =pod
15689:
1.1162 raeburn 15690: =item * &assign_categories_table()
1.663 raeburn 15691:
15692: Create a datatable for display of hierarchical categories in a domain,
15693: with checkboxes to allow a course to be categorized.
15694:
15695: Inputs:
15696:
15697: cathash - reference to hash of categories defined for the domain (from
15698: configuration.db)
15699:
15700: currcat - scalar with an & separated list of categories assigned to a course.
15701:
1.919 raeburn 15702: type - scalar contains course type (Course or Community).
15703:
1.1260 raeburn 15704: disabled - scalar (optional) contains disabled="disabled" if input elements are
15705: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15706:
1.663 raeburn 15707: Returns: $output (markup to be displayed)
15708:
15709: =cut
15710:
15711: sub assign_categories_table {
1.1259 raeburn 15712: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15713: my $output;
15714: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 15715: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
15716: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 15717: $maxdepth = scalar(@cats);
15718: if (@cats > 0) {
15719: my $itemcount = 0;
15720: if (ref($cats[0]) eq 'ARRAY') {
15721: my @currcategories;
15722: if ($currcat ne '') {
15723: @currcategories = split('&',$currcat);
15724: }
1.919 raeburn 15725: my $table;
1.663 raeburn 15726: for (my $i=0; $i<@{$cats[0]}; $i++) {
15727: my $parent = $cats[0][$i];
1.919 raeburn 15728: next if ($parent eq 'instcode');
15729: if ($type eq 'Community') {
15730: next unless ($parent eq 'communities');
1.1239 raeburn 15731: } elsif ($type eq 'Placement') {
15732: next unless ($parent eq 'placement');
1.919 raeburn 15733: } else {
1.1239 raeburn 15734: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15735: }
1.663 raeburn 15736: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15737: my $item = &escape($parent).'::0';
15738: my $checked = '';
15739: if (@currcategories > 0) {
15740: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15741: $checked = ' checked="checked"';
1.663 raeburn 15742: }
15743: }
1.919 raeburn 15744: my $parent_title = $parent;
15745: if ($parent eq 'communities') {
15746: $parent_title = &mt('Communities');
1.1239 raeburn 15747: } elsif ($parent eq 'placement') {
15748: $parent_title = &mt('Placement Tests');
1.919 raeburn 15749: }
15750: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15751: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15752: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15753: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15754: my $depth = 1;
15755: push(@path,$parent);
1.1259 raeburn 15756: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15757: pop(@path);
1.919 raeburn 15758: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15759: $itemcount ++;
15760: }
1.919 raeburn 15761: if ($itemcount) {
15762: $output = &Apache::loncommon::start_data_table().
15763: $table.
15764: &Apache::loncommon::end_data_table();
15765: }
1.663 raeburn 15766: }
15767: }
15768: }
15769: return $output;
15770: }
15771:
15772: =pod
15773:
1.1162 raeburn 15774: =item * &assign_category_rows()
1.663 raeburn 15775:
15776: Create a datatable row for display of nested categories in a domain,
15777: with checkboxes to allow a course to be categorized,called recursively.
15778:
15779: Inputs:
15780:
15781: itemcount - track row number for alternating colors
15782:
15783: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15784: categories and subcategories.
15785:
15786: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15787:
15788: parent - parent of current category item
15789:
15790: path - Array containing all categories back up through the hierarchy from the
15791: current category to the top level.
15792:
15793: currcategories - reference to array of current categories assigned to the course
15794:
1.1260 raeburn 15795: disabled - scalar (optional) contains disabled="disabled" if input elements are
15796: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15797:
1.663 raeburn 15798: Returns: $output (markup to be displayed).
15799:
15800: =cut
15801:
15802: sub assign_category_rows {
1.1259 raeburn 15803: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15804: my ($text,$name,$item,$chgstr);
15805: if (ref($cats) eq 'ARRAY') {
15806: my $maxdepth = scalar(@{$cats});
15807: if (ref($cats->[$depth]) eq 'HASH') {
15808: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15809: my $numchildren = @{$cats->[$depth]{$parent}};
15810: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 15811: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15812: for (my $j=0; $j<$numchildren; $j++) {
15813: $name = $cats->[$depth]{$parent}[$j];
15814: $item = &escape($name).':'.&escape($parent).':'.$depth;
15815: my $deeper = $depth+1;
15816: my $checked = '';
15817: if (ref($currcategories) eq 'ARRAY') {
15818: if (@{$currcategories} > 0) {
15819: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15820: $checked = ' checked="checked"';
1.663 raeburn 15821: }
15822: }
15823: }
1.664 raeburn 15824: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15825: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15826: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15827: '<input type="hidden" name="catname" value="'.$name.'" />'.
15828: '</td><td>';
1.663 raeburn 15829: if (ref($path) eq 'ARRAY') {
15830: push(@{$path},$name);
1.1259 raeburn 15831: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15832: pop(@{$path});
15833: }
15834: $text .= '</td></tr>';
15835: }
15836: $text .= '</table></td>';
15837: }
15838: }
15839: }
15840: return $text;
15841: }
15842:
1.1181 raeburn 15843: =pod
15844:
15845: =back
15846:
15847: =cut
15848:
1.655 raeburn 15849: ############################################################
15850: ############################################################
15851:
15852:
1.443 albertel 15853: sub commit_customrole {
1.664 raeburn 15854: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15855: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15856: ($start?', '.&mt('starting').' '.localtime($start):'').
15857: ($end?', ending '.localtime($end):'').': <b>'.
15858: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15859: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15860: '</b><br />';
15861: return $output;
15862: }
15863:
15864: sub commit_standardrole {
1.1116 raeburn 15865: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15866: my ($output,$logmsg,$linefeed);
15867: if ($context eq 'auto') {
15868: $linefeed = "\n";
15869: } else {
15870: $linefeed = "<br />\n";
15871: }
1.443 albertel 15872: if ($three eq 'st') {
1.541 raeburn 15873: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 15874: $one,$two,$sec,$context,$credits);
1.541 raeburn 15875: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15876: ($result eq 'unknown_course') || ($result eq 'refused')) {
15877: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15878: } else {
1.541 raeburn 15879: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15880: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15881: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15882: if ($context eq 'auto') {
15883: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15884: } else {
15885: $output .= '<b>'.$result.'</b>'.$linefeed.
15886: &mt('Add to classlist').': <b>ok</b>';
15887: }
15888: $output .= $linefeed;
1.443 albertel 15889: }
15890: } else {
15891: $output = &mt('Assigning').' '.$three.' in '.$url.
15892: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15893: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15894: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15895: if ($context eq 'auto') {
15896: $output .= $result.$linefeed;
15897: } else {
15898: $output .= '<b>'.$result.'</b>'.$linefeed;
15899: }
1.443 albertel 15900: }
15901: return $output;
15902: }
15903:
15904: sub commit_studentrole {
1.1116 raeburn 15905: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15906: $credits) = @_;
1.626 raeburn 15907: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15908: if ($context eq 'auto') {
15909: $linefeed = "\n";
15910: } else {
15911: $linefeed = '<br />'."\n";
15912: }
1.443 albertel 15913: if (defined($one) && defined($two)) {
15914: my $cid=$one.'_'.$two;
15915: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15916: my $secchange = 0;
15917: my $expire_role_result;
15918: my $modify_section_result;
1.628 raeburn 15919: if ($oldsec ne '-1') {
15920: if ($oldsec ne $sec) {
1.443 albertel 15921: $secchange = 1;
1.628 raeburn 15922: my $now = time;
1.443 albertel 15923: my $uurl='/'.$cid;
15924: $uurl=~s/\_/\//g;
15925: if ($oldsec) {
15926: $uurl.='/'.$oldsec;
15927: }
1.626 raeburn 15928: $oldsecurl = $uurl;
1.628 raeburn 15929: $expire_role_result =
1.652 raeburn 15930: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15931: if ($env{'request.course.sec'} ne '') {
15932: if ($expire_role_result eq 'refused') {
15933: my @roles = ('st');
15934: my @statuses = ('previous');
15935: my @roledoms = ($one);
15936: my $withsec = 1;
15937: my %roleshash =
15938: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15939: \@statuses,\@roles,\@roledoms,$withsec);
15940: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15941: my ($oldstart,$oldend) =
15942: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15943: if ($oldend > 0 && $oldend <= $now) {
15944: $expire_role_result = 'ok';
15945: }
15946: }
15947: }
15948: }
1.443 albertel 15949: $result = $expire_role_result;
15950: }
15951: }
15952: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15953: $modify_section_result =
15954: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15955: undef,undef,undef,$sec,
15956: $end,$start,'','',$cid,
15957: '',$context,$credits);
1.443 albertel 15958: if ($modify_section_result =~ /^ok/) {
15959: if ($secchange == 1) {
1.628 raeburn 15960: if ($sec eq '') {
15961: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15962: } else {
15963: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15964: }
1.443 albertel 15965: } elsif ($oldsec eq '-1') {
1.628 raeburn 15966: if ($sec eq '') {
15967: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15968: } else {
15969: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15970: }
1.443 albertel 15971: } else {
1.628 raeburn 15972: if ($sec eq '') {
15973: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15974: } else {
15975: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15976: }
1.443 albertel 15977: }
15978: } else {
1.1115 raeburn 15979: if ($secchange) {
1.628 raeburn 15980: $$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;
15981: } else {
15982: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15983: }
1.443 albertel 15984: }
15985: $result = $modify_section_result;
15986: } elsif ($secchange == 1) {
1.628 raeburn 15987: if ($oldsec eq '') {
1.1103 raeburn 15988: $$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 15989: } else {
15990: $$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;
15991: }
1.626 raeburn 15992: if ($expire_role_result eq 'refused') {
15993: my $newsecurl = '/'.$cid;
15994: $newsecurl =~ s/\_/\//g;
15995: if ($sec ne '') {
15996: $newsecurl.='/'.$sec;
15997: }
15998: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15999: if ($sec eq '') {
16000: $$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;
16001: } else {
16002: $$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;
16003: }
16004: }
16005: }
1.443 albertel 16006: }
16007: } else {
1.626 raeburn 16008: $$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 16009: $result = "error: incomplete course id\n";
16010: }
16011: return $result;
16012: }
16013:
1.1108 raeburn 16014: sub show_role_extent {
16015: my ($scope,$context,$role) = @_;
16016: $scope =~ s{^/}{};
16017: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
16018: push(@courseroles,'co');
16019: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
16020: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
16021: $scope =~ s{/}{_};
16022: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
16023: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
16024: my ($audom,$auname) = split(/\//,$scope);
16025: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
16026: &Apache::loncommon::plainname($auname,$audom).'</span>');
16027: } else {
16028: $scope =~ s{/$}{};
16029: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
16030: &Apache::lonnet::domain($scope,'description').'</span>');
16031: }
16032: }
16033:
1.443 albertel 16034: ############################################################
16035: ############################################################
16036:
1.566 albertel 16037: sub check_clone {
1.578 raeburn 16038: my ($args,$linefeed) = @_;
1.566 albertel 16039: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
16040: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
16041: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
1.1344 raeburn 16042: my $clonetitle;
16043: my @clonemsg;
1.566 albertel 16044: my $can_clone = 0;
1.944 raeburn 16045: my $lctype = lc($args->{'crstype'});
1.908 raeburn 16046: if ($lctype ne 'community') {
16047: $lctype = 'course';
16048: }
1.566 albertel 16049: if ($clonehome eq 'no_host') {
1.944 raeburn 16050: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16051: push(@clonemsg,({
16052: mt => 'No new community created.',
16053: args => [],
16054: },
16055: {
16056: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',
16057: args => [$args->{'clonedomain'}.':'.$args->{'clonedomain'}],
16058: }));
1.908 raeburn 16059: } else {
1.1344 raeburn 16060: push(@clonemsg,({
16061: mt => 'No new course created.',
16062: args => [],
16063: },
16064: {
16065: mt => 'A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',
16066: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16067: }));
16068: }
1.566 albertel 16069: } else {
16070: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.1344 raeburn 16071: $clonetitle = $clonedesc{'description'};
1.944 raeburn 16072: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 16073: if ($clonedesc{'type'} ne 'Community') {
1.1344 raeburn 16074: push(@clonemsg,({
16075: mt => 'No new community created.',
16076: args => [],
16077: },
16078: {
16079: mt => 'A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',
16080: args => [$args->{'clonecourse'}.':'.$args->{'clonedomain'}],
16081: }));
16082: return ($can_clone,\@clonemsg,$cloneid,$clonehome);
1.908 raeburn 16083: }
16084: }
1.1262 raeburn 16085: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 16086: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 16087: $can_clone = 1;
16088: } else {
1.1221 raeburn 16089: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 16090: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 16091: if ($clonehash{'cloners'} eq '') {
16092: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
16093: if ($domdefs{'canclone'}) {
16094: unless ($domdefs{'canclone'} eq 'none') {
16095: if ($domdefs{'canclone'} eq 'domain') {
16096: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
16097: $can_clone = 1;
16098: }
16099: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16100: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
16101: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
16102: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
16103: $can_clone = 1;
16104: }
16105: }
16106: }
16107: }
1.578 raeburn 16108: } else {
1.1221 raeburn 16109: my @cloners = split(/,/,$clonehash{'cloners'});
16110: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 16111: $can_clone = 1;
1.1221 raeburn 16112: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 16113: $can_clone = 1;
1.1225 raeburn 16114: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
16115: $can_clone = 1;
1.1221 raeburn 16116: }
16117: unless ($can_clone) {
1.1225 raeburn 16118: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
16119: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 16120: my (%gotdomdefaults,%gotcodedefaults);
16121: foreach my $cloner (@cloners) {
16122: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
16123: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
16124: my (%codedefaults,@code_order);
16125: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
16126: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
16127: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
16128: }
16129: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
16130: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
16131: }
16132: } else {
16133: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
16134: \%codedefaults,
16135: \@code_order);
16136: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
16137: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
16138: }
16139: if (@code_order > 0) {
16140: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
16141: $cloner,$clonehash{'internal.coursecode'},
16142: $args->{'crscode'})) {
16143: $can_clone = 1;
16144: last;
16145: }
16146: }
16147: }
16148: }
16149: }
1.1225 raeburn 16150: }
16151: }
16152: unless ($can_clone) {
16153: my $ccrole = 'cc';
16154: if ($args->{'crstype'} eq 'Community') {
16155: $ccrole = 'co';
16156: }
16157: my %roleshash =
16158: &Apache::lonnet::get_my_roles($args->{'ccuname'},
16159: $args->{'ccdomain'},
16160: 'userroles',['active'],[$ccrole],
16161: [$args->{'clonedomain'}]);
16162: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
16163: $can_clone = 1;
16164: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
16165: $args->{'ccuname'},$args->{'ccdomain'})) {
16166: $can_clone = 1;
1.1221 raeburn 16167: }
16168: }
16169: unless ($can_clone) {
16170: if ($args->{'crstype'} eq 'Community') {
1.1344 raeburn 16171: push(@clonemsg,({
16172: mt => 'No new community created.',
16173: args => [],
16174: },
16175: {
16176: 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]).',
16177: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16178: }));
1.942 raeburn 16179: } else {
1.1344 raeburn 16180: push(@clonemsg,({
16181: mt => 'No new course created.',
16182: args => [],
16183: },
16184: {
16185: 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]).',
16186: args => [$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'}],
16187: }));
1.1221 raeburn 16188: }
1.566 albertel 16189: }
1.578 raeburn 16190: }
1.566 albertel 16191: }
1.1344 raeburn 16192: return ($can_clone,\@clonemsg,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16193: }
16194:
1.444 albertel 16195: sub construct_course {
1.1262 raeburn 16196: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
1.1344 raeburn 16197: $cnum,$category,$coderef,$callercontext,$user_lh) = @_;
16198: my ($outcome,$msgref,$clonemsgref);
1.541 raeburn 16199: my $linefeed = '<br />'."\n";
16200: if ($context eq 'auto') {
16201: $linefeed = "\n";
16202: }
1.566 albertel 16203:
16204: #
16205: # Are we cloning?
16206: #
1.1344 raeburn 16207: my ($can_clone,$cloneid,$clonehome,$clonetitle);
1.566 albertel 16208: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.1344 raeburn 16209: ($can_clone,$clonemsgref,$cloneid,$clonehome,$clonetitle) = &check_clone($args,$linefeed);
1.566 albertel 16210: if (!$can_clone) {
1.1344 raeburn 16211: return (0,$outcome,$clonemsgref);
1.566 albertel 16212: }
16213: }
16214:
1.444 albertel 16215: #
16216: # Open course
16217: #
1.1239 raeburn 16218: my $showncrstype;
16219: if ($args->{'crstype'} eq 'Placement') {
16220: $showncrstype = 'placement test';
16221: } else {
16222: $showncrstype = lc($args->{'crstype'});
16223: }
1.444 albertel 16224: my %cenv=();
16225: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
16226: $args->{'cdescr'},
16227: $args->{'curl'},
16228: $args->{'course_home'},
16229: $args->{'nonstandard'},
16230: $args->{'crscode'},
16231: $args->{'ccuname'}.':'.
16232: $args->{'ccdomain'},
1.882 raeburn 16233: $args->{'crstype'},
1.1344 raeburn 16234: $cnum,$context,$category,
16235: $callercontext);
1.444 albertel 16236:
16237: # Note: The testing routines depend on this being output; see
16238: # Utils::Course. This needs to at least be output as a comment
16239: # if anyone ever decides to not show this, and Utils::Course::new
16240: # will need to be suitably modified.
1.1344 raeburn 16241: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16242: $outcome .= &mt_user($user_lh,'New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16243: } else {
16244: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
16245: }
1.943 raeburn 16246: if ($$courseid =~ /^error:/) {
1.1344 raeburn 16247: return (0,$outcome,$clonemsgref);
1.943 raeburn 16248: }
16249:
1.444 albertel 16250: #
16251: # Check if created correctly
16252: #
1.479 albertel 16253: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 16254: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 16255: if ($crsuhome eq 'no_host') {
1.1344 raeburn 16256: if (($callercontext eq 'auto') && ($user_lh ne '')) {
16257: $outcome .= &mt_user($user_lh,
16258: 'Course creation failed, unrecognized course home server.');
16259: } else {
16260: $outcome .= &mt('Course creation failed, unrecognized course home server.');
16261: }
16262: $outcome .= $linefeed;
16263: return (0,$outcome,$clonemsgref);
1.943 raeburn 16264: }
1.541 raeburn 16265: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 16266:
1.444 albertel 16267: #
1.566 albertel 16268: # Do the cloning
16269: #
1.1344 raeburn 16270: my @clonemsg;
1.566 albertel 16271: if ($can_clone && $cloneid) {
1.1344 raeburn 16272: push(@clonemsg,
16273: {
16274: mt => 'Created [_1] by cloning from [_2]',
16275: args => [$showncrstype,$clonetitle],
16276: });
1.566 albertel 16277: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 16278: # Copy all files
1.1344 raeburn 16279: my @info =
16280: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},
16281: $args->{'dateshift'},$args->{'crscode'},
16282: $args->{'ccuname'}.':'.$args->{'ccdomain'},
16283: $args->{'tinyurls'});
16284: if (@info) {
16285: push(@clonemsg,@info);
16286: }
1.444 albertel 16287: # Restore URL
1.566 albertel 16288: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 16289: # Restore title
1.566 albertel 16290: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 16291: # Restore creation date, creator and creation context.
16292: $cenv{'internal.created'}=$oldcenv{'internal.created'};
16293: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
16294: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 16295: # Mark as cloned
1.566 albertel 16296: $cenv{'clonedfrom'}=$cloneid;
1.638 www 16297: # Need to clone grading mode
16298: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
16299: $cenv{'grading'}=$newenv{'grading'};
16300: # Do not clone these environment entries
16301: &Apache::lonnet::del('environment',
16302: ['default_enrollment_start_date',
16303: 'default_enrollment_end_date',
16304: 'question.email',
16305: 'policy.email',
16306: 'comment.email',
16307: 'pch.users.denied',
1.725 raeburn 16308: 'plc.users.denied',
16309: 'hidefromcat',
1.1121 raeburn 16310: 'checkforpriv',
1.1355 raeburn 16311: 'categories'],
1.638 www 16312: $$crsudom,$$crsunum);
1.1170 raeburn 16313: if ($args->{'textbook'}) {
16314: $cenv{'internal.textbook'} = $args->{'textbook'};
16315: }
1.444 albertel 16316: }
1.566 albertel 16317:
1.444 albertel 16318: #
16319: # Set environment (will override cloned, if existing)
16320: #
16321: my @sections = ();
16322: my @xlists = ();
16323: if ($args->{'crstype'}) {
16324: $cenv{'type'}=$args->{'crstype'};
16325: }
16326: if ($args->{'crsid'}) {
16327: $cenv{'courseid'}=$args->{'crsid'};
16328: }
16329: if ($args->{'crscode'}) {
16330: $cenv{'internal.coursecode'}=$args->{'crscode'};
16331: }
16332: if ($args->{'crsquota'} ne '') {
16333: $cenv{'internal.coursequota'}=$args->{'crsquota'};
16334: } else {
16335: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
16336: }
16337: if ($args->{'ccuname'}) {
16338: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
16339: ':'.$args->{'ccdomain'};
16340: } else {
16341: $cenv{'internal.courseowner'} = $args->{'curruser'};
16342: }
1.1116 raeburn 16343: if ($args->{'defaultcredits'}) {
16344: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
16345: }
1.444 albertel 16346: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
16347: if ($args->{'crssections'}) {
16348: $cenv{'internal.sectionnums'} = '';
16349: if ($args->{'crssections'} =~ m/,/) {
16350: @sections = split/,/,$args->{'crssections'};
16351: } else {
16352: $sections[0] = $args->{'crssections'};
16353: }
16354: if (@sections > 0) {
16355: foreach my $item (@sections) {
16356: my ($sec,$gp) = split/:/,$item;
16357: my $class = $args->{'crscode'}.$sec;
16358: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16359: $cenv{'internal.sectionnums'} .= $item.',';
16360: unless ($addcheck eq 'ok') {
1.1263 raeburn 16361: push(@badclasses,$class);
1.444 albertel 16362: }
16363: }
16364: $cenv{'internal.sectionnums'} =~ s/,$//;
16365: }
16366: }
16367: # do not hide course coordinator from staff listing,
16368: # even if privileged
16369: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 16370: # add course coordinator's domain to domains to check for privileged users
16371: # if different to course domain
16372: if ($$crsudom ne $args->{'ccdomain'}) {
16373: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16374: }
1.444 albertel 16375: # add crosslistings
16376: if ($args->{'crsxlist'}) {
16377: $cenv{'internal.crosslistings'}='';
16378: if ($args->{'crsxlist'} =~ m/,/) {
16379: @xlists = split/,/,$args->{'crsxlist'};
16380: } else {
16381: $xlists[0] = $args->{'crsxlist'};
16382: }
16383: if (@xlists > 0) {
16384: foreach my $item (@xlists) {
16385: my ($xl,$gp) = split/:/,$item;
16386: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16387: $cenv{'internal.crosslistings'} .= $item.',';
16388: unless ($addcheck eq 'ok') {
1.1263 raeburn 16389: push(@badclasses,$xl);
1.444 albertel 16390: }
16391: }
16392: $cenv{'internal.crosslistings'} =~ s/,$//;
16393: }
16394: }
16395: if ($args->{'autoadds'}) {
16396: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16397: }
16398: if ($args->{'autodrops'}) {
16399: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16400: }
16401: # check for notification of enrollment changes
16402: my @notified = ();
16403: if ($args->{'notify_owner'}) {
16404: if ($args->{'ccuname'} ne '') {
16405: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16406: }
16407: }
16408: if ($args->{'notify_dc'}) {
16409: if ($uname ne '') {
1.630 raeburn 16410: push(@notified,$uname.':'.$udom);
1.444 albertel 16411: }
16412: }
16413: if (@notified > 0) {
16414: my $notifylist;
16415: if (@notified > 1) {
16416: $notifylist = join(',',@notified);
16417: } else {
16418: $notifylist = $notified[0];
16419: }
16420: $cenv{'internal.notifylist'} = $notifylist;
16421: }
16422: if (@badclasses > 0) {
16423: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 16424: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16425: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16426: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16427: );
1.1264 raeburn 16428: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16429: &mt('That is because the user identified as the course owner ([_1]) does not have rights to access enrollment in these classes, as determined by the policies of your institution on access to official classlists',$cenv{'internal.courseowner'}).$linefeed.$lt{'itis'};
1.541 raeburn 16430: if ($context eq 'auto') {
16431: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 16432: } else {
1.566 albertel 16433: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 16434: }
16435: foreach my $item (@badclasses) {
1.541 raeburn 16436: if ($context eq 'auto') {
1.1261 raeburn 16437: $outcome .= " - $item\n";
1.541 raeburn 16438: } else {
1.1261 raeburn 16439: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16440: }
1.1261 raeburn 16441: }
16442: if ($context eq 'auto') {
16443: $outcome .= $linefeed;
16444: } else {
16445: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 16446: }
1.444 albertel 16447: }
16448: if ($args->{'no_end_date'}) {
16449: $args->{'endaccess'} = 0;
16450: }
16451: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16452: $cenv{'internal.autoend'}=$args->{'enrollend'};
16453: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16454: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16455: if ($args->{'showphotos'}) {
16456: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16457: }
16458: $cenv{'internal.authtype'} = $args->{'authtype'};
16459: $cenv{'internal.autharg'} = $args->{'autharg'};
16460: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16461: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16462: 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');
16463: if ($context eq 'auto') {
16464: $outcome .= $krb_msg;
16465: } else {
1.566 albertel 16466: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16467: }
16468: $outcome .= $linefeed;
1.444 albertel 16469: }
16470: }
16471: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16472: if ($args->{'setpolicy'}) {
16473: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16474: }
16475: if ($args->{'setcontent'}) {
16476: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16477: }
1.1251 raeburn 16478: if ($args->{'setcomment'}) {
16479: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16480: }
1.444 albertel 16481: }
16482: if ($args->{'reshome'}) {
16483: $cenv{'reshome'}=$args->{'reshome'}.'/';
16484: $cenv{'reshome'}=~s/\/+$/\//;
16485: }
16486: #
16487: # course has keyed access
16488: #
16489: if ($args->{'setkeys'}) {
16490: $cenv{'keyaccess'}='yes';
16491: }
16492: # if specified, key authority is not course, but user
16493: # only active if keyaccess is yes
16494: if ($args->{'keyauth'}) {
1.487 albertel 16495: my ($user,$domain) = split(':',$args->{'keyauth'});
16496: $user = &LONCAPA::clean_username($user);
16497: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16498: if ($user ne '' && $domain ne '') {
1.487 albertel 16499: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16500: }
16501: }
16502:
1.1166 raeburn 16503: #
1.1167 raeburn 16504: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 16505: #
16506: if ($args->{'uniquecode'}) {
16507: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16508: if ($code) {
16509: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 16510: my %crsinfo =
16511: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16512: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16513: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16514: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16515: }
1.1166 raeburn 16516: if (ref($coderef)) {
16517: $$coderef = $code;
16518: }
16519: }
16520: }
16521:
1.444 albertel 16522: if ($args->{'disresdis'}) {
16523: $cenv{'pch.roles.denied'}='st';
16524: }
16525: if ($args->{'disablechat'}) {
16526: $cenv{'plc.roles.denied'}='st';
16527: }
16528:
16529: # Record we've not yet viewed the Course Initialization Helper for this
16530: # course
16531: $cenv{'course.helper.not.run'} = 1;
16532: #
16533: # Use new Randomseed
16534: #
16535: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16536: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16537: #
16538: # The encryption code and receipt prefix for this course
16539: #
16540: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16541: $cenv{'internal.encpref'}=100+int(9*rand(99));
16542: #
16543: # By default, use standard grading
16544: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16545:
1.541 raeburn 16546: $outcome .= $linefeed.&mt('Setting environment').': '.
16547: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16548: #
16549: # Open all assignments
16550: #
16551: if ($args->{'openall'}) {
1.1341 raeburn 16552: my $opendate = time;
16553: if ($args->{'openallfrom'} =~ /^\d+$/) {
16554: $opendate = $args->{'openallfrom'};
16555: }
1.444 albertel 16556: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
1.1341 raeburn 16557: my %storecontent = ($storeunder => $opendate,
1.444 albertel 16558: $storeunder.'.type' => 'date_start');
1.1341 raeburn 16559: $outcome .= &mt('All assignments open starting [_1]',
16560: &Apache::lonlocal::locallocaltime($opendate)).': '.
16561: &Apache::lonnet::cput
16562: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16563: }
16564: #
16565: # Set first page
16566: #
16567: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16568: || ($cloneid)) {
1.445 albertel 16569: use LONCAPA::map;
1.444 albertel 16570: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16571:
16572: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16573: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16574:
1.444 albertel 16575: $outcome .= ($fatal?$errtext:'read ok').' - ';
16576: my $title; my $url;
16577: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16578: $title=&mt('Syllabus');
1.444 albertel 16579: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16580: } else {
1.963 raeburn 16581: $title=&mt('Table of Contents');
1.444 albertel 16582: $url='/adm/navmaps';
16583: }
1.445 albertel 16584:
16585: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16586: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16587:
16588: if ($errtext) { $fatal=2; }
1.541 raeburn 16589: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16590: }
1.566 albertel 16591:
1.1237 raeburn 16592: #
16593: # Set params for Placement Tests
16594: #
1.1239 raeburn 16595: if ($args->{'crstype'} eq 'Placement') {
16596: my %storecontent;
16597: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
16598: my %defaults = (
16599: buttonshide => { value => 'yes',
16600: type => 'string_yesno',},
16601: type => { value => 'randomizetry',
16602: type => 'string_questiontype',},
16603: maxtries => { value => 1,
16604: type => 'int_pos',},
16605: problemstatus => { value => 'no',
16606: type => 'string_problemstatus',},
16607: );
16608: foreach my $key (keys(%defaults)) {
16609: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
16610: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
16611: }
1.1237 raeburn 16612: &Apache::lonnet::cput
16613: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
16614: }
16615:
1.1344 raeburn 16616: return (1,$outcome,\@clonemsg);
1.444 albertel 16617: }
16618:
1.1166 raeburn 16619: sub make_unique_code {
16620: my ($cdom,$cnum) = @_;
16621: # get lock on uniquecodes db
16622: my $lockhash = {
16623: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16624: ':'.$env{'user.domain'},
16625: };
16626: my $tries = 0;
16627: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16628: my ($code,$error);
16629:
16630: while (($gotlock ne 'ok') && ($tries<3)) {
16631: $tries ++;
16632: sleep 1;
16633: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16634: }
16635: if ($gotlock eq 'ok') {
16636: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16637: my $gotcode;
16638: my $attempts = 0;
16639: while ((!$gotcode) && ($attempts < 100)) {
16640: $code = &generate_code();
16641: if (!exists($currcodes{$code})) {
16642: $gotcode = 1;
16643: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
16644: $error = 'nostore';
16645: }
16646: }
16647: $attempts ++;
16648: }
16649: my @del_lock = ($cnum."\0".'uniquecodes');
16650: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
16651: } else {
16652: $error = 'nolock';
16653: }
16654: return ($code,$error);
16655: }
16656:
16657: sub generate_code {
16658: my $code;
16659: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
16660: for (my $i=0; $i<6; $i++) {
16661: my $lettnum = int (rand 2);
16662: my $item = '';
16663: if ($lettnum) {
16664: $item = $letts[int( rand(18) )];
16665: } else {
16666: $item = 1+int( rand(8) );
16667: }
16668: $code .= $item;
16669: }
16670: return $code;
16671: }
16672:
1.444 albertel 16673: ############################################################
16674: ############################################################
16675:
1.1237 raeburn 16676: # Community, Course and Placement Test
1.378 raeburn 16677: sub course_type {
16678: my ($cid) = @_;
16679: if (!defined($cid)) {
16680: $cid = $env{'request.course.id'};
16681: }
1.404 albertel 16682: if (defined($env{'course.'.$cid.'.type'})) {
16683: return $env{'course.'.$cid.'.type'};
1.378 raeburn 16684: } else {
16685: return 'Course';
1.377 raeburn 16686: }
16687: }
1.156 albertel 16688:
1.406 raeburn 16689: sub group_term {
16690: my $crstype = &course_type();
16691: my %names = (
16692: 'Course' => 'group',
1.865 raeburn 16693: 'Community' => 'group',
1.1237 raeburn 16694: 'Placement' => 'group',
1.406 raeburn 16695: );
16696: return $names{$crstype};
16697: }
16698:
1.902 raeburn 16699: sub course_types {
1.1310 raeburn 16700: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 16701: my %typename = (
16702: official => 'Official course',
16703: unofficial => 'Unofficial course',
16704: community => 'Community',
1.1165 raeburn 16705: textbook => 'Textbook course',
1.1237 raeburn 16706: placement => 'Placement test',
1.1310 raeburn 16707: lti => 'LTI provider',
1.902 raeburn 16708: );
16709: return (\@types,\%typename);
16710: }
16711:
1.156 albertel 16712: sub icon {
16713: my ($file)=@_;
1.505 albertel 16714: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 16715: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 16716: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 16717: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
16718: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
16719: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16720: $curfext.".gif") {
16721: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16722: $curfext.".gif";
16723: }
16724: }
1.249 albertel 16725: return &lonhttpdurl($iconname);
1.154 albertel 16726: }
1.84 albertel 16727:
1.575 albertel 16728: sub lonhttpdurl {
1.692 www 16729: #
16730: # Had been used for "small fry" static images on separate port 8080.
16731: # Modify here if lightweight http functionality desired again.
16732: # Currently eliminated due to increasing firewall issues.
16733: #
1.575 albertel 16734: my ($url)=@_;
1.692 www 16735: return $url;
1.215 albertel 16736: }
16737:
1.213 albertel 16738: sub connection_aborted {
16739: my ($r)=@_;
16740: $r->print(" ");$r->rflush();
16741: my $c = $r->connection;
16742: return $c->aborted();
16743: }
16744:
1.221 foxr 16745: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16746: # strings as 'strings'.
16747: sub escape_single {
1.221 foxr 16748: my ($input) = @_;
1.223 albertel 16749: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16750: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16751: return $input;
16752: }
1.223 albertel 16753:
1.222 foxr 16754: # Same as escape_single, but escape's "'s This
16755: # can be used for "strings"
16756: sub escape_double {
16757: my ($input) = @_;
16758: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16759: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16760: return $input;
16761: }
1.223 albertel 16762:
1.222 foxr 16763: # Escapes the last element of a full URL.
16764: sub escape_url {
16765: my ($url) = @_;
1.238 raeburn 16766: my @urlslices = split(/\//, $url,-1);
1.369 www 16767: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 16768: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16769: }
1.462 albertel 16770:
1.820 raeburn 16771: sub compare_arrays {
16772: my ($arrayref1,$arrayref2) = @_;
16773: my (@difference,%count);
16774: @difference = ();
16775: %count = ();
16776: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16777: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16778: foreach my $element (keys(%count)) {
16779: if ($count{$element} == 1) {
16780: push(@difference,$element);
16781: }
16782: }
16783: }
16784: return @difference;
16785: }
16786:
1.1322 raeburn 16787: sub lon_status_items {
16788: my %defaults = (
16789: E => 100,
16790: W => 4,
16791: N => 1,
1.1324 raeburn 16792: U => 5,
1.1322 raeburn 16793: threshold => 200,
16794: sysmail => 2500,
16795: );
16796: my %names = (
16797: E => 'Errors',
16798: W => 'Warnings',
16799: N => 'Notices',
1.1324 raeburn 16800: U => 'Unsent',
1.1322 raeburn 16801: );
16802: return (\%defaults,\%names);
16803: }
16804:
1.817 bisitz 16805: # -------------------------------------------------------- Initialize user login
1.462 albertel 16806: sub init_user_environment {
1.463 albertel 16807: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16808: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16809:
16810: my $public=($username eq 'public' && $domain eq 'public');
16811:
1.1062 raeburn 16812: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16813: my $now=time;
16814:
16815: if ($public) {
16816: my $max_public=100;
16817: my $oldest;
16818: my $oldest_time=0;
16819: for(my $next=1;$next<=$max_public;$next++) {
16820: if (-e $lonids."/publicuser_$next.id") {
16821: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16822: if ($mtime<$oldest_time || !$oldest_time) {
16823: $oldest_time=$mtime;
16824: $oldest=$next;
16825: }
16826: } else {
16827: $cookie="publicuser_$next";
16828: last;
16829: }
16830: }
16831: if (!$cookie) { $cookie="publicuser_$oldest"; }
16832: } else {
1.1275 raeburn 16833: # See if old ID present, if so, remove if this isn't a robot,
16834: # killing any existing non-robot sessions
1.463 albertel 16835: if (!$args->{'robot'}) {
16836: opendir(DIR,$lonids);
16837: while ($filename=readdir(DIR)) {
16838: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 16839: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
16840: &GDBM_READER(),0640)) {
1.1295 raeburn 16841: my $linkedfile;
1.1320 raeburn 16842: if (exists($oldenv{'user.linkedenv'})) {
16843: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 16844: }
1.1320 raeburn 16845: untie(%oldenv);
16846: if (unlink("$lonids/$filename")) {
16847: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
16848: if (-l "$lonids/$linkedfile.id") {
16849: unlink("$lonids/$linkedfile.id");
16850: }
1.1295 raeburn 16851: }
16852: }
16853: } else {
16854: unlink($lonids.'/'.$filename);
16855: }
1.463 albertel 16856: }
1.462 albertel 16857: }
1.463 albertel 16858: closedir(DIR);
1.1204 raeburn 16859: # If there is a undeleted lockfile for the user's paste buffer remove it.
16860: my $namespace = 'nohist_courseeditor';
16861: my $lockingkey = 'paste'."\0".'locked_num';
16862: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16863: $domain,$username);
16864: if (exists($lockhash{$lockingkey})) {
16865: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16866: unless ($delresult eq 'ok') {
16867: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16868: }
16869: }
1.462 albertel 16870: }
16871: # Give them a new cookie
1.463 albertel 16872: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16873: : $now.$$.int(rand(10000)));
1.463 albertel 16874: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16875:
16876: # Initialize roles
16877:
1.1062 raeburn 16878: ($userroles,$firstaccenv,$timerintenv) =
16879: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16880: }
16881: # ------------------------------------ Check browser type and MathML capability
16882:
1.1194 raeburn 16883: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16884: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16885:
16886: # ------------------------------------------------------------- Get environment
16887:
16888: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16889: my ($tmp) = keys(%userenv);
1.1275 raeburn 16890: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 16891: undef(%userenv);
16892: }
16893: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16894: $form->{'interface'}=$userenv{'interface'};
16895: }
16896: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16897:
16898: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16899: foreach my $option ('interface','localpath','localres') {
16900: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16901: }
16902: # --------------------------------------------------------- Write first profile
16903:
16904: {
1.1350 raeburn 16905: my $ip = &Apache::lonnet::get_requestor_ip($r);
1.462 albertel 16906: my %initial_env =
16907: ("user.name" => $username,
16908: "user.domain" => $domain,
16909: "user.home" => $authhost,
16910: "browser.type" => $clientbrowser,
16911: "browser.version" => $clientversion,
16912: "browser.mathml" => $clientmathml,
16913: "browser.unicode" => $clientunicode,
16914: "browser.os" => $clientos,
1.1137 raeburn 16915: "browser.mobile" => $clientmobile,
1.1141 raeburn 16916: "browser.info" => $clientinfo,
1.1194 raeburn 16917: "browser.osversion" => $clientosversion,
1.462 albertel 16918: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16919: "request.course.fn" => '',
16920: "request.course.uri" => '',
16921: "request.course.sec" => '',
16922: "request.role" => 'cm',
16923: "request.role.adv" => $env{'user.adv'},
1.1350 raeburn 16924: "request.host" => $ip,);
1.462 albertel 16925:
16926: if ($form->{'localpath'}) {
16927: $initial_env{"browser.localpath"} = $form->{'localpath'};
16928: $initial_env{"browser.localres"} = $form->{'localres'};
16929: }
16930:
16931: if ($form->{'interface'}) {
16932: $form->{'interface'}=~s/\W//gs;
16933: $initial_env{"browser.interface"} = $form->{'interface'};
16934: $env{'browser.interface'}=$form->{'interface'};
16935: }
16936:
1.1157 raeburn 16937: if ($form->{'iptoken'}) {
16938: my $lonhost = $r->dir_config('lonHostID');
16939: $initial_env{"user.noloadbalance"} = $lonhost;
16940: $env{'user.noloadbalance'} = $lonhost;
16941: }
16942:
1.1268 raeburn 16943: if ($form->{'noloadbalance'}) {
16944: my @hosts = &Apache::lonnet::current_machine_ids();
16945: my $hosthere = $form->{'noloadbalance'};
16946: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16947: $initial_env{"user.noloadbalance"} = $hosthere;
16948: $env{'user.noloadbalance'} = $hosthere;
16949: }
16950: }
16951:
1.1016 raeburn 16952: unless ($domain eq 'public') {
1.1273 raeburn 16953: my %is_adv = ( is_adv => $env{'user.adv'} );
16954: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
16955:
16956: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16957: $userenv{'availabletools.'.$tool} =
16958: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16959: undef,\%userenv,\%domdef,\%is_adv);
16960: }
1.980 raeburn 16961:
1.1311 raeburn 16962: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 16963: $userenv{'canrequest.'.$crstype} =
16964: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16965: 'reload','requestcourses',
16966: \%userenv,\%domdef,\%is_adv);
16967: }
1.724 raeburn 16968:
1.1273 raeburn 16969: $userenv{'canrequest.author'} =
16970: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16971: 'reload','requestauthor',
1.980 raeburn 16972: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 16973: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16974: $domain,$username);
16975: my $reqstatus = $reqauthor{'author_status'};
16976: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16977: if (ref($reqauthor{'author'}) eq 'HASH') {
16978: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16979: $reqauthor{'author'}{'timestamp'};
16980: }
1.1092 raeburn 16981: }
1.1287 raeburn 16982: my ($types,$typename) = &course_types();
16983: if (ref($types) eq 'ARRAY') {
16984: my @options = ('approval','validate','autolimit');
16985: my $optregex = join('|',@options);
16986: my (%willtrust,%trustchecked);
16987: foreach my $type (@{$types}) {
16988: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
16989: if ($dom_str ne '') {
16990: my $updatedstr = '';
16991: my @possdomains = split(',',$dom_str);
16992: foreach my $entry (@possdomains) {
16993: my ($extdom,$extopt) = split(':',$entry);
16994: unless ($trustchecked{$extdom}) {
16995: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
16996: $trustchecked{$extdom} = 1;
16997: }
16998: if ($willtrust{$extdom}) {
16999: $updatedstr .= $entry.',';
17000: }
17001: }
17002: $updatedstr =~ s/,$//;
17003: if ($updatedstr) {
17004: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
17005: } else {
17006: delete($userenv{'reqcrsotherdom.'.$type});
17007: }
17008: }
17009: }
17010: }
1.1092 raeburn 17011: }
1.462 albertel 17012: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 17013:
1.462 albertel 17014: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
17015: &GDBM_WRCREAT(),0640)) {
17016: &_add_to_env(\%disk_env,\%initial_env);
17017: &_add_to_env(\%disk_env,\%userenv,'environment.');
17018: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 17019: if (ref($firstaccenv) eq 'HASH') {
17020: &_add_to_env(\%disk_env,$firstaccenv);
17021: }
17022: if (ref($timerintenv) eq 'HASH') {
17023: &_add_to_env(\%disk_env,$timerintenv);
17024: }
1.463 albertel 17025: if (ref($args->{'extra_env'})) {
17026: &_add_to_env(\%disk_env,$args->{'extra_env'});
17027: }
1.462 albertel 17028: untie(%disk_env);
17029: } else {
1.705 tempelho 17030: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
17031: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 17032: return 'error: '.$!;
17033: }
17034: }
17035: $env{'request.role'}='cm';
17036: $env{'request.role.adv'}=$env{'user.adv'};
17037: $env{'browser.type'}=$clientbrowser;
17038:
17039: return $cookie;
17040:
17041: }
17042:
17043: sub _add_to_env {
17044: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 17045: if (ref($env_data) eq 'HASH') {
17046: while (my ($key,$value) = each(%$env_data)) {
17047: $idf->{$prefix.$key} = $value;
17048: $env{$prefix.$key} = $value;
17049: }
1.462 albertel 17050: }
17051: }
17052:
1.685 tempelho 17053: # --- Get the symbolic name of a problem and the url
17054: sub get_symb {
17055: my ($request,$silent) = @_;
1.726 raeburn 17056: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 17057: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
17058: if ($symb eq '') {
17059: if (!$silent) {
1.1071 raeburn 17060: if (ref($request)) {
17061: $request->print("Unable to handle ambiguous references:$url:.");
17062: }
1.685 tempelho 17063: return ();
17064: }
17065: }
17066: &Apache::lonenc::check_decrypt(\$symb);
17067: return ($symb);
17068: }
17069:
17070: # --------------------------------------------------------------Get annotation
17071:
17072: sub get_annotation {
17073: my ($symb,$enc) = @_;
17074:
17075: my $key = $symb;
17076: if (!$enc) {
17077: $key =
17078: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
17079: }
17080: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
17081: return $annotation{$key};
17082: }
17083:
17084: sub clean_symb {
1.731 raeburn 17085: my ($symb,$delete_enc) = @_;
1.685 tempelho 17086:
17087: &Apache::lonenc::check_decrypt(\$symb);
17088: my $enc = $env{'request.enc'};
1.731 raeburn 17089: if ($delete_enc) {
1.730 raeburn 17090: delete($env{'request.enc'});
17091: }
1.685 tempelho 17092:
17093: return ($symb,$enc);
17094: }
1.462 albertel 17095:
1.1181 raeburn 17096: ############################################################
17097: ############################################################
17098:
17099: =pod
17100:
17101: =head1 Routines for building display used to search for courses
17102:
17103:
17104: =over 4
17105:
17106: =item * &build_filters()
17107:
17108: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 17109: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
17110: and quotacheck.pl
17111:
1.1181 raeburn 17112:
17113: Inputs:
17114:
17115: filterlist - anonymous array of fields to include as potential filters
17116:
17117: crstype - course type
17118:
17119: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
17120: to pop-open a course selector (will contain "extra element").
17121:
17122: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
17123:
17124: filter - anonymous hash of criteria and their values
17125:
17126: action - form action
17127:
17128: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
17129:
1.1182 raeburn 17130: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 17131:
17132: cloneruname - username of owner of new course who wants to clone
17133:
17134: clonerudom - domain of owner of new course who wants to clone
17135:
17136: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
17137:
17138: codetitlesref - reference to array of titles of components in institutional codes (official courses)
17139:
17140: codedom - domain
17141:
17142: formname - value of form element named "form".
17143:
17144: fixeddom - domain, if fixed.
17145:
17146: prevphase - value to assign to form element named "phase" when going back to the previous screen
17147:
17148: cnameelement - name of form element in form on opener page which will receive title of selected course
17149:
17150: cnumelement - name of form element in form on opener page which will receive courseID of selected course
17151:
17152: cdomelement - name of form element in form on opener page which will receive domain of selected course
17153:
17154: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
17155:
17156: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
17157:
17158: clonewarning - warning message about missing information for intended course owner when DC creates a course
17159:
1.1182 raeburn 17160:
1.1181 raeburn 17161: Returns: $output - HTML for display of search criteria, and hidden form elements.
17162:
1.1182 raeburn 17163:
1.1181 raeburn 17164: Side Effects: None
17165:
17166: =cut
17167:
17168: # ---------------------------------------------- search for courses based on last activity etc.
17169:
17170: sub build_filters {
17171: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
17172: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
17173: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
17174: $cnameelement,$cnumelement,$cdomelement,$setroles,
17175: $clonetext,$clonewarning) = @_;
1.1182 raeburn 17176: my ($list,$jscript);
1.1181 raeburn 17177: my $onchange = 'javascript:updateFilters(this)';
17178: my ($domainselectform,$sincefilterform,$createdfilterform,
17179: $ownerdomselectform,$persondomselectform,$instcodeform,
17180: $typeselectform,$instcodetitle);
17181: if ($formname eq '') {
17182: $formname = $caller;
17183: }
17184: foreach my $item (@{$filterlist}) {
17185: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
17186: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
17187: if ($item eq 'domainfilter') {
17188: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
17189: } elsif ($item eq 'coursefilter') {
17190: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
17191: } elsif ($item eq 'ownerfilter') {
17192: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17193: } elsif ($item eq 'ownerdomfilter') {
17194: $filter->{'ownerdomfilter'} =
17195: &LONCAPA::clean_domain($filter->{$item});
17196: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
17197: 'ownerdomfilter',1);
17198: } elsif ($item eq 'personfilter') {
17199: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
17200: } elsif ($item eq 'persondomfilter') {
17201: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
17202: 'persondomfilter',1);
17203: } else {
17204: $filter->{$item} =~ s/\W//g;
17205: }
17206: if (!$filter->{$item}) {
17207: $filter->{$item} = '';
17208: }
17209: }
17210: if ($item eq 'domainfilter') {
17211: my $allow_blank = 1;
17212: if ($formname eq 'portform') {
17213: $allow_blank=0;
17214: } elsif ($formname eq 'studentform') {
17215: $allow_blank=0;
17216: }
17217: if ($fixeddom) {
17218: $domainselectform = '<input type="hidden" name="domainfilter"'.
17219: ' value="'.$codedom.'" />'.
17220: &Apache::lonnet::domain($codedom,'description');
17221: } else {
17222: $domainselectform = &select_dom_form($filter->{$item},
17223: 'domainfilter',
17224: $allow_blank,'',$onchange);
17225: }
17226: } else {
17227: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
17228: }
17229: }
17230:
17231: # last course activity filter and selection
17232: $sincefilterform = &timebased_select_form('sincefilter',$filter);
17233:
17234: # course created filter and selection
17235: if (exists($filter->{'createdfilter'})) {
17236: $createdfilterform = &timebased_select_form('createdfilter',$filter);
17237: }
17238:
1.1239 raeburn 17239: my $prefix = $crstype;
17240: if ($crstype eq 'Placement') {
17241: $prefix = 'Placement Test'
17242: }
1.1181 raeburn 17243: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 17244: 'cac' => "$prefix Activity",
17245: 'ccr' => "$prefix Created",
17246: 'cde' => "$prefix Title",
17247: 'cdo' => "$prefix Domain",
1.1181 raeburn 17248: 'ins' => 'Institutional Code',
17249: 'inc' => 'Institutional Categorization',
1.1239 raeburn 17250: 'cow' => "$prefix Owner/Co-owner",
17251: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 17252: 'cog' => 'Type',
17253: );
17254:
17255: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17256: my $typeval = 'Course';
17257: if ($crstype eq 'Community') {
17258: $typeval = 'Community';
1.1239 raeburn 17259: } elsif ($crstype eq 'Placement') {
17260: $typeval = 'Placement';
1.1181 raeburn 17261: }
17262: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
17263: } else {
17264: $typeselectform = '<select name="type" size="1"';
17265: if ($onchange) {
17266: $typeselectform .= ' onchange="'.$onchange.'"';
17267: }
17268: $typeselectform .= '>'."\n";
1.1237 raeburn 17269: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 17270: my $shown;
17271: if ($posstype eq 'Placement') {
17272: $shown = &mt('Placement Test');
17273: } else {
17274: $shown = &mt($posstype);
17275: }
1.1181 raeburn 17276: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 17277: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 17278: }
17279: $typeselectform.="</select>";
17280: }
17281:
17282: my ($cloneableonlyform,$cloneabletitle);
17283: if (exists($filter->{'cloneableonly'})) {
17284: my $cloneableon = '';
17285: my $cloneableoff = ' checked="checked"';
17286: if ($filter->{'cloneableonly'}) {
17287: $cloneableon = $cloneableoff;
17288: $cloneableoff = '';
17289: }
17290: $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>';
17291: if ($formname eq 'ccrs') {
1.1187 bisitz 17292: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 17293: } else {
17294: $cloneabletitle = &mt('Cloneable by you');
17295: }
17296: }
17297: my $officialjs;
17298: if ($crstype eq 'Course') {
17299: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 17300: # if (($fixeddom) || ($formname eq 'requestcrs') ||
17301: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
17302: if ($codedom) {
1.1181 raeburn 17303: $officialjs = 1;
17304: ($instcodeform,$jscript,$$numtitlesref) =
17305: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
17306: $officialjs,$codetitlesref);
17307: if ($jscript) {
1.1182 raeburn 17308: $jscript = '<script type="text/javascript">'."\n".
17309: '// <![CDATA['."\n".
17310: $jscript."\n".
17311: '// ]]>'."\n".
17312: '</script>'."\n";
1.1181 raeburn 17313: }
17314: }
17315: if ($instcodeform eq '') {
17316: $instcodeform =
17317: '<input type="text" name="instcodefilter" size="10" value="'.
17318: $list->{'instcodefilter'}.'" />';
17319: $instcodetitle = $lt{'ins'};
17320: } else {
17321: $instcodetitle = $lt{'inc'};
17322: }
17323: if ($fixeddom) {
17324: $instcodetitle .= '<br />('.$codedom.')';
17325: }
17326: }
17327: }
17328: my $output = qq|
17329: <form method="post" name="filterpicker" action="$action">
17330: <input type="hidden" name="form" value="$formname" />
17331: |;
17332: if ($formname eq 'modifycourse') {
17333: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
17334: '<input type="hidden" name="prevphase" value="'.
17335: $prevphase.'" />'."\n";
1.1198 musolffc 17336: } elsif ($formname eq 'quotacheck') {
17337: $output .= qq|
17338: <input type="hidden" name="sortby" value="" />
17339: <input type="hidden" name="sortorder" value="" />
17340: |;
17341: } else {
1.1181 raeburn 17342: my $name_input;
17343: if ($cnameelement ne '') {
17344: $name_input = '<input type="hidden" name="cnameelement" value="'.
17345: $cnameelement.'" />';
17346: }
17347: $output .= qq|
1.1182 raeburn 17348: <input type="hidden" name="cnumelement" value="$cnumelement" />
17349: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 17350: $name_input
17351: $roleelement
17352: $multelement
17353: $typeelement
17354: |;
17355: if ($formname eq 'portform') {
17356: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
17357: }
17358: }
17359: if ($fixeddom) {
17360: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
17361: }
17362: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
17363: if ($sincefilterform) {
17364: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
17365: .$sincefilterform
17366: .&Apache::lonhtmlcommon::row_closure();
17367: }
17368: if ($createdfilterform) {
17369: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17370: .$createdfilterform
17371: .&Apache::lonhtmlcommon::row_closure();
17372: }
17373: if ($domainselectform) {
17374: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17375: .$domainselectform
17376: .&Apache::lonhtmlcommon::row_closure();
17377: }
17378: if ($typeselectform) {
17379: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17380: $output .= $typeselectform;
17381: } else {
17382: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17383: .$typeselectform
17384: .&Apache::lonhtmlcommon::row_closure();
17385: }
17386: }
17387: if ($instcodeform) {
17388: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17389: .$instcodeform
17390: .&Apache::lonhtmlcommon::row_closure();
17391: }
17392: if (exists($filter->{'ownerfilter'})) {
17393: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17394: '<table><tr><td>'.&mt('Username').'<br />'.
17395: '<input type="text" name="ownerfilter" size="20" value="'.
17396: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17397: $ownerdomselectform.'</td></tr></table>'.
17398: &Apache::lonhtmlcommon::row_closure();
17399: }
17400: if (exists($filter->{'personfilter'})) {
17401: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17402: '<table><tr><td>'.&mt('Username').'<br />'.
17403: '<input type="text" name="personfilter" size="20" value="'.
17404: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17405: $persondomselectform.'</td></tr></table>'.
17406: &Apache::lonhtmlcommon::row_closure();
17407: }
17408: if (exists($filter->{'coursefilter'})) {
17409: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17410: .'<input type="text" name="coursefilter" size="25" value="'
17411: .$list->{'coursefilter'}.'" />'
17412: .&Apache::lonhtmlcommon::row_closure();
17413: }
17414: if ($cloneableonlyform) {
17415: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17416: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17417: }
17418: if (exists($filter->{'descriptfilter'})) {
17419: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17420: .'<input type="text" name="descriptfilter" size="40" value="'
17421: .$list->{'descriptfilter'}.'" />'
17422: .&Apache::lonhtmlcommon::row_closure(1);
17423: }
17424: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17425: '<input type="hidden" name="updater" value="" />'."\n".
17426: '<input type="submit" name="gosearch" value="'.
17427: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17428: return $jscript.$clonewarning.$output;
17429: }
17430:
17431: =pod
17432:
17433: =item * &timebased_select_form()
17434:
1.1182 raeburn 17435: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 17436: filter e.g., Course Activity, Course Created, when searching for courses
17437: or communities
17438:
17439: Inputs:
17440:
17441: item - name of form element (sincefilter or createdfilter)
17442:
17443: filter - anonymous hash of criteria and their values
17444:
17445: Returns: HTML for a select box contained a blank, then six time selections,
17446: with value set in incoming form variables currently selected.
17447:
17448: Side Effects: None
17449:
17450: =cut
17451:
17452: sub timebased_select_form {
17453: my ($item,$filter) = @_;
17454: if (ref($filter) eq 'HASH') {
17455: $filter->{$item} =~ s/[^\d-]//g;
17456: if (!$filter->{$item}) { $filter->{$item}=-1; }
17457: return &select_form(
17458: $filter->{$item},
17459: $item,
17460: { '-1' => '',
17461: '86400' => &mt('today'),
17462: '604800' => &mt('last week'),
17463: '2592000' => &mt('last month'),
17464: '7776000' => &mt('last three months'),
17465: '15552000' => &mt('last six months'),
17466: '31104000' => &mt('last year'),
17467: 'select_form_order' =>
17468: ['-1','86400','604800','2592000','7776000',
17469: '15552000','31104000']});
17470: }
17471: }
17472:
17473: =pod
17474:
17475: =item * &js_changer()
17476:
17477: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 17478: when course type or domain is changed, and also to hide 'Searching ...' on
17479: page load completion for page showing search result.
1.1181 raeburn 17480:
17481: Inputs: None
17482:
1.1183 raeburn 17483: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 17484:
17485: Side Effects: None
17486:
17487: =cut
17488:
17489: sub js_changer {
17490: return <<ENDJS;
17491: <script type="text/javascript">
17492: // <![CDATA[
17493: function updateFilters(caller) {
17494: if (typeof(caller) != "undefined") {
17495: document.filterpicker.updater.value = caller.name;
17496: }
17497: document.filterpicker.submit();
17498: }
1.1183 raeburn 17499:
17500: function hideSearching() {
17501: if (document.getElementById('searching')) {
17502: document.getElementById('searching').style.display = 'none';
17503: }
17504: return;
17505: }
17506:
1.1181 raeburn 17507: // ]]>
17508: </script>
17509:
17510: ENDJS
17511: }
17512:
17513: =pod
17514:
1.1182 raeburn 17515: =item * &search_courses()
17516:
17517: Process selected filters form course search form and pass to lonnet::courseiddump
17518: to retrieve a hash for which keys are courseIDs which match the selected filters.
17519:
17520: Inputs:
17521:
17522: dom - domain being searched
17523:
17524: type - course type ('Course' or 'Community' or '.' if any).
17525:
17526: filter - anonymous hash of criteria and their values
17527:
17528: numtitles - for institutional codes - number of categories
17529:
17530: cloneruname - optional username of new course owner
17531:
17532: clonerudom - optional domain of new course owner
17533:
1.1221 raeburn 17534: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 17535: (used when DC is using course creation form)
17536:
17537: codetitles - reference to array of titles of components in institutional codes (official courses).
17538:
1.1221 raeburn 17539: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17540: (and so can clone automatically)
17541:
17542: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17543:
17544: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17545: courses to clone
1.1182 raeburn 17546:
17547: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17548:
17549:
17550: Side Effects: None
17551:
17552: =cut
17553:
17554:
17555: sub search_courses {
1.1221 raeburn 17556: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17557: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 17558: my (%courses,%showcourses,$cloner);
17559: if (($filter->{'ownerfilter'} ne '') ||
17560: ($filter->{'ownerdomfilter'} ne '')) {
17561: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17562: $filter->{'ownerdomfilter'};
17563: }
17564: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17565: if (!$filter->{$item}) {
17566: $filter->{$item}='.';
17567: }
17568: }
17569: my $now = time;
17570: my $timefilter =
17571: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17572: my ($createdbefore,$createdafter);
17573: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17574: $createdbefore = $now;
17575: $createdafter = $now-$filter->{'createdfilter'};
17576: }
17577: my ($instcodefilter,$regexpok);
17578: if ($numtitles) {
17579: if ($env{'form.official'} eq 'on') {
17580: $instcodefilter =
17581: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17582: $regexpok = 1;
17583: } elsif ($env{'form.official'} eq 'off') {
17584: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17585: unless ($instcodefilter eq '') {
17586: $regexpok = -1;
17587: }
17588: }
17589: } else {
17590: $instcodefilter = $filter->{'instcodefilter'};
17591: }
17592: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17593: if ($type eq '') { $type = '.'; }
17594:
17595: if (($clonerudom ne '') && ($cloneruname ne '')) {
17596: $cloner = $cloneruname.':'.$clonerudom;
17597: }
17598: %courses = &Apache::lonnet::courseiddump($dom,
17599: $filter->{'descriptfilter'},
17600: $timefilter,
17601: $instcodefilter,
17602: $filter->{'combownerfilter'},
17603: $filter->{'coursefilter'},
17604: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 17605: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 17606: $filter->{'cloneableonly'},
17607: $createdbefore,$createdafter,undef,
1.1221 raeburn 17608: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 17609: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17610: my $ccrole;
17611: if ($type eq 'Community') {
17612: $ccrole = 'co';
17613: } else {
17614: $ccrole = 'cc';
17615: }
17616: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17617: $filter->{'persondomfilter'},
17618: 'userroles',undef,
17619: [$ccrole,'in','ad','ep','ta','cr'],
17620: $dom);
17621: foreach my $role (keys(%rolehash)) {
17622: my ($cnum,$cdom,$courserole) = split(':',$role);
17623: my $cid = $cdom.'_'.$cnum;
17624: if (exists($courses{$cid})) {
17625: if (ref($courses{$cid}) eq 'HASH') {
17626: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17627: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 17628: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 17629: }
17630: } else {
17631: $courses{$cid}{roles} = [$courserole];
17632: }
17633: $showcourses{$cid} = $courses{$cid};
17634: }
17635: }
17636: }
17637: %courses = %showcourses;
17638: }
17639: return %courses;
17640: }
17641:
17642: =pod
17643:
1.1181 raeburn 17644: =back
17645:
1.1207 raeburn 17646: =head1 Routines for version requirements for current course.
17647:
17648: =over 4
17649:
17650: =item * &check_release_required()
17651:
17652: Compares required LON-CAPA version with version on server, and
17653: if required version is newer looks for a server with the required version.
17654:
17655: Looks first at servers in user's owen domain; if none suitable, looks at
17656: servers in course's domain are permitted to host sessions for user's domain.
17657:
17658: Inputs:
17659:
17660: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17661:
17662: $courseid - Course ID of current course
17663:
17664: $rolecode - User's current role in course (for switchserver query string).
17665:
17666: $required - LON-CAPA version needed by course (format: Major.Minor).
17667:
17668:
17669: Returns:
17670:
17671: $switchserver - query string tp append to /adm/switchserver call (if
17672: current server's LON-CAPA version is too old.
17673:
17674: $warning - Message is displayed if no suitable server could be found.
17675:
17676: =cut
17677:
17678: sub check_release_required {
17679: my ($loncaparev,$courseid,$rolecode,$required) = @_;
17680: my ($switchserver,$warning);
17681: if ($required ne '') {
17682: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
17683: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17684: if ($reqdmajor ne '' && $reqdminor ne '') {
17685: my $otherserver;
17686: if (($major eq '' && $minor eq '') ||
17687: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
17688: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
17689: my $switchlcrev =
17690: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
17691: $userdomserver);
17692: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17693: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
17694: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
17695: my $cdom = $env{'course.'.$courseid.'.domain'};
17696: if ($cdom ne $env{'user.domain'}) {
17697: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
17698: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
17699: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17700: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
17701: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
17702: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
17703: my $canhost =
17704: &Apache::lonnet::can_host_session($env{'user.domain'},
17705: $coursedomserver,
17706: $remoterev,
17707: $udomdefaults{'remotesessions'},
17708: $defdomdefaults{'hostedsessions'});
17709:
17710: if ($canhost) {
17711: $otherserver = $coursedomserver;
17712: } else {
17713: $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.");
17714: }
17715: } else {
17716: $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).");
17717: }
17718: } else {
17719: $otherserver = $userdomserver;
17720: }
17721: }
17722: if ($otherserver ne '') {
17723: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
17724: }
17725: }
17726: }
17727: return ($switchserver,$warning);
17728: }
17729:
17730: =pod
17731:
17732: =item * &check_release_result()
17733:
17734: Inputs:
17735:
17736: $switchwarning - Warning message if no suitable server found to host session.
17737:
17738: $switchserver - query string to append to /adm/switchserver containing lonHostID
17739: and current role.
17740:
17741: Returns: HTML to display with information about requirement to switch server.
17742: Either displaying warning with link to Roles/Courses screen or
17743: display link to switchserver.
17744:
1.1181 raeburn 17745: =cut
17746:
1.1207 raeburn 17747: sub check_release_result {
17748: my ($switchwarning,$switchserver) = @_;
17749: my $output = &start_page('Selected course unavailable on this server').
17750: '<p class="LC_warning">';
17751: if ($switchwarning) {
17752: $output .= $switchwarning.'<br /><a href="/adm/roles">';
17753: if (&show_course()) {
17754: $output .= &mt('Display courses');
17755: } else {
17756: $output .= &mt('Display roles');
17757: }
17758: $output .= '</a>';
17759: } elsif ($switchserver) {
17760: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
17761: '<br />'.
17762: '<a href="/adm/switchserver?'.$switchserver.'">'.
17763: &mt('Switch Server').
17764: '</a>';
17765: }
17766: $output .= '</p>'.&end_page();
17767: return $output;
17768: }
17769:
17770: =pod
17771:
17772: =item * &needs_coursereinit()
17773:
17774: Determine if course contents stored for user's session needs to be
17775: refreshed, because content has changed since "Big Hash" last tied.
17776:
17777: Check for change is made if time last checked is more than 10 minutes ago
17778: (by default).
17779:
17780: Inputs:
17781:
17782: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17783:
17784: $interval (optional) - Time which may elapse (in s) between last check for content
17785: change in current course. (default: 600 s).
17786:
17787: Returns: an array; first element is:
17788:
17789: =over 4
17790:
17791: 'switch' - if content updates mean user's session
17792: needs to be switched to a server running a newer LON-CAPA version
17793:
17794: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
17795: on current server hosting user's session
17796:
17797: '' - if no action required.
17798:
17799: =back
17800:
17801: If first item element is 'switch':
17802:
17803: second item is $switchwarning - Warning message if no suitable server found to host session.
17804:
17805: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
17806: and current role.
17807:
17808: otherwise: no other elements returned.
17809:
17810: =back
17811:
17812: =cut
17813:
17814: sub needs_coursereinit {
17815: my ($loncaparev,$interval) = @_;
17816: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17817: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17818: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17819: my $now = time;
17820: if ($interval eq '') {
17821: $interval = 600;
17822: }
17823: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 17824: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1283 raeburn 17825: my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1);
1.1282 raeburn 17826: if ($blocked) {
17827: return ();
17828: }
1.1207 raeburn 17829: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17830: if ($lastchange > $env{'request.course.tied'}) {
17831: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17832: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17833: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17834: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17835: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17836: $curr_reqd_hash{'internal.releaserequired'}});
17837: my ($switchserver,$switchwarning) =
17838: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17839: $curr_reqd_hash{'internal.releaserequired'});
17840: if ($switchwarning ne '' || $switchserver ne '') {
17841: return ('switch',$switchwarning,$switchserver);
17842: }
17843: }
17844: }
17845: return ('update');
17846: }
17847: }
17848: return ();
17849: }
1.1181 raeburn 17850:
1.1083 raeburn 17851: sub update_content_constraints {
1.1326 raeburn 17852: my ($cdom,$cnum,$chome,$cid,$keeporder) = @_;
1.1083 raeburn 17853: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17854: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 17855: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 17856: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 17857: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 17858: if ($item eq 'resourcetag') {
17859: if ($name eq 'responsetype') {
17860: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17861: }
1.1307 raeburn 17862: } elsif ($item eq 'course') {
17863: if ($name eq 'courserestype') {
17864: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
17865: }
1.1083 raeburn 17866: }
17867: }
17868: my $navmap = Apache::lonnavmaps::navmap->new();
17869: if (defined($navmap)) {
1.1307 raeburn 17870: my (%allresponses,%allcrsrestypes);
17871: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
17872: if ($res->is_tool()) {
17873: if ($allcrsrestypes{'exttool'}) {
17874: $allcrsrestypes{'exttool'} ++;
17875: } else {
17876: $allcrsrestypes{'exttool'} = 1;
17877: }
17878: next;
17879: }
1.1083 raeburn 17880: my %responses = $res->responseTypes();
17881: foreach my $key (keys(%responses)) {
17882: next unless(exists($checkresponsetypes{$key}));
17883: $allresponses{$key} += $responses{$key};
17884: }
17885: }
17886: foreach my $key (keys(%allresponses)) {
17887: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17888: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17889: ($reqdmajor,$reqdminor) = ($major,$minor);
17890: }
17891: }
1.1307 raeburn 17892: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 17893: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 17894: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17895: ($reqdmajor,$reqdminor) = ($major,$minor);
17896: }
17897: }
1.1083 raeburn 17898: undef($navmap);
17899: }
1.1326 raeburn 17900: my (@resources,@order,@resparms,@zombies);
17901: if ($keeporder) {
17902: use LONCAPA::map;
17903: @resources = @LONCAPA::map::resources;
17904: @order = @LONCAPA::map::order;
17905: @resparms = @LONCAPA::map::resparms;
17906: @zombies = @LONCAPA::map::zombies;
17907: }
1.1308 raeburn 17908: my $suppmap = 'supplemental.sequence';
17909: my ($suppcount,$supptools,$errors) = (0,0,0);
17910: ($suppcount,$supptools,$errors) = &recurse_supplemental($cnum,$cdom,$suppmap,
17911: $suppcount,$supptools,$errors);
1.1326 raeburn 17912: if ($keeporder) {
17913: @LONCAPA::map::resources = @resources;
17914: @LONCAPA::map::order = @order;
17915: @LONCAPA::map::resparms = @resparms;
17916: @LONCAPA::map::zombies = @zombies;
17917: }
1.1308 raeburn 17918: if ($supptools) {
17919: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
17920: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17921: ($reqdmajor,$reqdminor) = ($major,$minor);
17922: }
17923: }
1.1083 raeburn 17924: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17925: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17926: }
17927: return;
17928: }
17929:
1.1110 raeburn 17930: sub allmaps_incourse {
17931: my ($cdom,$cnum,$chome,$cid) = @_;
17932: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17933: $cid = $env{'request.course.id'};
17934: $cdom = $env{'course.'.$cid.'.domain'};
17935: $cnum = $env{'course.'.$cid.'.num'};
17936: $chome = $env{'course.'.$cid.'.home'};
17937: }
17938: my %allmaps = ();
17939: my $lastchange =
17940: &Apache::lonnet::get_coursechange($cdom,$cnum);
17941: if ($lastchange > $env{'request.course.tied'}) {
17942: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17943: unless ($ferr) {
1.1326 raeburn 17944: &update_content_constraints($cdom,$cnum,$chome,$cid,1);
1.1110 raeburn 17945: }
17946: }
17947: my $navmap = Apache::lonnavmaps::navmap->new();
17948: if (defined($navmap)) {
17949: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17950: $allmaps{$res->src()} = 1;
17951: }
17952: }
17953: return \%allmaps;
17954: }
17955:
1.1083 raeburn 17956: sub parse_supplemental_title {
17957: my ($title) = @_;
17958:
17959: my ($foldertitle,$renametitle);
17960: if ($title =~ /&&&/) {
17961: $title = &HTML::Entites::decode($title);
17962: }
17963: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17964: $renametitle=$4;
17965: my ($time,$uname,$udom) = ($1,$2,$3);
17966: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17967: my $name = &plainname($uname,$udom);
17968: $name = &HTML::Entities::encode($name,'"<>&\'');
17969: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17970: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17971: $name.': <br />'.$foldertitle;
17972: }
17973: if (wantarray) {
17974: return ($title,$foldertitle,$renametitle);
17975: }
17976: return $title;
17977: }
17978:
1.1143 raeburn 17979: sub recurse_supplemental {
1.1308 raeburn 17980: my ($cnum,$cdom,$suppmap,$numfiles,$numexttools,$errors) = @_;
1.1143 raeburn 17981: if ($suppmap) {
17982: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17983: if ($fatal) {
17984: $errors ++;
17985: } else {
17986: if ($#LONCAPA::map::resources > 0) {
17987: foreach my $res (@LONCAPA::map::resources) {
17988: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17989: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 17990: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1308 raeburn 17991: ($numfiles,$numexttools,$errors) = &recurse_supplemental($cnum,$cdom,$1,
17992: $numfiles,$numexttools,$errors);
1.1143 raeburn 17993: } else {
1.1308 raeburn 17994: if ($src =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
17995: $numexttools ++;
17996: }
1.1143 raeburn 17997: $numfiles ++;
17998: }
17999: }
18000: }
18001: }
18002: }
18003: }
1.1308 raeburn 18004: return ($numfiles,$numexttools,$errors);
1.1143 raeburn 18005: }
18006:
1.1101 raeburn 18007: sub symb_to_docspath {
1.1267 raeburn 18008: my ($symb,$navmapref) = @_;
18009: return unless ($symb && ref($navmapref));
1.1101 raeburn 18010: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
18011: if ($resurl=~/\.(sequence|page)$/) {
18012: $mapurl=$resurl;
18013: } elsif ($resurl eq 'adm/navmaps') {
18014: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
18015: }
18016: my $mapresobj;
1.1267 raeburn 18017: unless (ref($$navmapref)) {
18018: $$navmapref = Apache::lonnavmaps::navmap->new();
18019: }
18020: if (ref($$navmapref)) {
18021: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 18022: }
18023: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
18024: my $type=$2;
18025: my $path;
18026: if (ref($mapresobj)) {
18027: my $pcslist = $mapresobj->map_hierarchy();
18028: if ($pcslist ne '') {
18029: foreach my $pc (split(/,/,$pcslist)) {
18030: next if ($pc <= 1);
1.1267 raeburn 18031: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 18032: if (ref($res)) {
18033: my $thisurl = $res->src();
18034: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
18035: my $thistitle = $res->title();
18036: $path .= '&'.
18037: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 18038: &escape($thistitle).
1.1101 raeburn 18039: ':'.$res->randompick().
18040: ':'.$res->randomout().
18041: ':'.$res->encrypted().
18042: ':'.$res->randomorder().
18043: ':'.$res->is_page();
18044: }
18045: }
18046: }
18047: $path =~ s/^\&//;
18048: my $maptitle = $mapresobj->title();
18049: if ($mapurl eq 'default') {
1.1129 raeburn 18050: $maptitle = 'Main Content';
1.1101 raeburn 18051: }
18052: $path .= (($path ne '')? '&' : '').
18053: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 18054: &escape($maptitle).
1.1101 raeburn 18055: ':'.$mapresobj->randompick().
18056: ':'.$mapresobj->randomout().
18057: ':'.$mapresobj->encrypted().
18058: ':'.$mapresobj->randomorder().
18059: ':'.$mapresobj->is_page();
18060: } else {
18061: my $maptitle = &Apache::lonnet::gettitle($mapurl);
18062: my $ispage = (($type eq 'page')? 1 : '');
18063: if ($mapurl eq 'default') {
1.1129 raeburn 18064: $maptitle = 'Main Content';
1.1101 raeburn 18065: }
18066: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 18067: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 18068: }
18069: unless ($mapurl eq 'default') {
18070: $path = 'default&'.
1.1146 raeburn 18071: &escape('Main Content').
1.1101 raeburn 18072: ':::::&'.$path;
18073: }
18074: return $path;
18075: }
18076:
1.1094 raeburn 18077: sub captcha_display {
1.1327 raeburn 18078: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 18079: my ($output,$error);
1.1234 raeburn 18080: my ($captcha,$pubkey,$privkey,$version) =
1.1327 raeburn 18081: &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 18082: if ($captcha eq 'original') {
1.1094 raeburn 18083: $output = &create_captcha();
18084: unless ($output) {
1.1172 raeburn 18085: $error = 'captcha';
1.1094 raeburn 18086: }
18087: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 18088: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 18089: unless ($output) {
1.1172 raeburn 18090: $error = 'recaptcha';
1.1094 raeburn 18091: }
18092: }
1.1234 raeburn 18093: return ($output,$error,$captcha,$version);
1.1094 raeburn 18094: }
18095:
18096: sub captcha_response {
1.1327 raeburn 18097: my ($context,$lonhost,$defdom) = @_;
1.1094 raeburn 18098: my ($captcha_chk,$captcha_error);
1.1327 raeburn 18099: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost,$defdom);
1.1095 raeburn 18100: if ($captcha eq 'original') {
1.1094 raeburn 18101: ($captcha_chk,$captcha_error) = &check_captcha();
18102: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 18103: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 18104: } else {
18105: $captcha_chk = 1;
18106: }
18107: return ($captcha_chk,$captcha_error);
18108: }
18109:
18110: sub get_captcha_config {
1.1327 raeburn 18111: my ($context,$lonhost,$dom_in_effect) = @_;
1.1234 raeburn 18112: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 18113: my $hostname = &Apache::lonnet::hostname($lonhost);
18114: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
18115: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 18116: if ($context eq 'usercreation') {
18117: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
18118: if (ref($domconfig{$context}) eq 'HASH') {
18119: $hashtocheck = $domconfig{$context}{'cancreate'};
18120: if (ref($hashtocheck) eq 'HASH') {
18121: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
18122: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
18123: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
18124: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
18125: }
18126: if ($privkey && $pubkey) {
18127: $captcha = 'recaptcha';
1.1234 raeburn 18128: $version = $hashtocheck->{'recaptchaversion'};
18129: if ($version ne '2') {
18130: $version = 1;
18131: }
1.1095 raeburn 18132: } else {
18133: $captcha = 'original';
18134: }
18135: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
18136: $captcha = 'original';
18137: }
1.1094 raeburn 18138: }
1.1095 raeburn 18139: } else {
18140: $captcha = 'captcha';
18141: }
18142: } elsif ($context eq 'login') {
18143: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
18144: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
18145: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
18146: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 18147: if ($privkey && $pubkey) {
18148: $captcha = 'recaptcha';
1.1234 raeburn 18149: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
18150: if ($version ne '2') {
18151: $version = 1;
18152: }
1.1095 raeburn 18153: } else {
18154: $captcha = 'original';
1.1094 raeburn 18155: }
1.1095 raeburn 18156: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
18157: $captcha = 'original';
1.1094 raeburn 18158: }
1.1327 raeburn 18159: } elsif ($context eq 'passwords') {
18160: if ($dom_in_effect) {
18161: my %passwdconf = &Apache::lonnet::get_passwdconf($dom_in_effect);
18162: if ($passwdconf{'captcha'} eq 'recaptcha') {
18163: if (ref($passwdconf{'recaptchakeys'}) eq 'HASH') {
18164: $pubkey = $passwdconf{'recaptchakeys'}{'public'};
18165: $privkey = $passwdconf{'recaptchakeys'}{'private'};
18166: }
18167: if ($privkey && $pubkey) {
18168: $captcha = 'recaptcha';
18169: $version = $passwdconf{'recaptchaversion'};
18170: if ($version ne '2') {
18171: $version = 1;
18172: }
18173: } else {
18174: $captcha = 'original';
18175: }
18176: } elsif ($passwdconf{'captcha'} ne 'notused') {
18177: $captcha = 'original';
18178: }
18179: }
18180: }
1.1234 raeburn 18181: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 18182: }
18183:
18184: sub create_captcha {
18185: my %captcha_params = &captcha_settings();
18186: my ($output,$maxtries,$tries) = ('',10,0);
18187: while ($tries < $maxtries) {
18188: $tries ++;
18189: my $captcha = Authen::Captcha->new (
18190: output_folder => $captcha_params{'output_dir'},
18191: data_folder => $captcha_params{'db_dir'},
18192: );
18193: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
18194:
18195: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
18196: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
18197: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 18198: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
18199: '<br />'.
18200: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 18201: last;
18202: }
18203: }
1.1323 raeburn 18204: if ($output eq '') {
18205: &Apache::lonnet::logthis("Failed to create Captcha code after $tries attempts.");
18206: }
1.1094 raeburn 18207: return $output;
18208: }
18209:
18210: sub captcha_settings {
18211: my %captcha_params = (
18212: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
18213: www_output_dir => "/captchaspool",
18214: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
18215: numchars => '5',
18216: );
18217: return %captcha_params;
18218: }
18219:
18220: sub check_captcha {
18221: my ($captcha_chk,$captcha_error);
18222: my $code = $env{'form.code'};
18223: my $md5sum = $env{'form.crypt'};
18224: my %captcha_params = &captcha_settings();
18225: my $captcha = Authen::Captcha->new(
18226: output_folder => $captcha_params{'output_dir'},
18227: data_folder => $captcha_params{'db_dir'},
18228: );
1.1109 raeburn 18229: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 18230: my %captcha_hash = (
18231: 0 => 'Code not checked (file error)',
18232: -1 => 'Failed: code expired',
18233: -2 => 'Failed: invalid code (not in database)',
18234: -3 => 'Failed: invalid code (code does not match crypt)',
18235: );
18236: if ($captcha_chk != 1) {
18237: $captcha_error = $captcha_hash{$captcha_chk}
18238: }
18239: return ($captcha_chk,$captcha_error);
18240: }
18241:
18242: sub create_recaptcha {
1.1234 raeburn 18243: my ($pubkey,$version) = @_;
18244: if ($version >= 2) {
18245: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
18246: } else {
18247: my $use_ssl;
18248: if ($ENV{'SERVER_PORT'} == 443) {
18249: $use_ssl = 1;
18250: }
18251: my $captcha = Captcha::reCAPTCHA->new;
18252: return $captcha->get_options_setter({theme => 'white'})."\n".
18253: $captcha->get_html($pubkey,undef,$use_ssl).
18254: &mt('If the text is hard to read, [_1] will replace them.',
18255: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
18256: '<br /><br />';
18257: }
1.1094 raeburn 18258: }
18259:
18260: sub check_recaptcha {
1.1234 raeburn 18261: my ($privkey,$version) = @_;
1.1094 raeburn 18262: my $captcha_chk;
1.1350 raeburn 18263: my $ip = &Apache::lonnet::get_requestor_ip();
1.1234 raeburn 18264: if ($version >= 2) {
18265: my %info = (
18266: secret => $privkey,
18267: response => $env{'form.g-recaptcha-response'},
1.1350 raeburn 18268: remoteip => $ip,
1.1234 raeburn 18269: );
1.1280 raeburn 18270: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
18271: $request->content(join('&',map {
18272: my $name = escape($_);
18273: "$name=" . ( ref($info{$_}) eq 'ARRAY'
18274: ? join("&$name=", map {escape($_) } @{$info{$_}})
18275: : &escape($info{$_}) );
18276: } keys(%info)));
18277: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 18278: if ($response->is_success) {
18279: my $data = JSON::DWIW->from_json($response->decoded_content);
18280: if (ref($data) eq 'HASH') {
18281: if ($data->{'success'}) {
18282: $captcha_chk = 1;
18283: }
18284: }
18285: }
18286: } else {
18287: my $captcha = Captcha::reCAPTCHA->new;
18288: my $captcha_result =
18289: $captcha->check_answer(
18290: $privkey,
1.1350 raeburn 18291: $ip,
1.1234 raeburn 18292: $env{'form.recaptcha_challenge_field'},
18293: $env{'form.recaptcha_response_field'},
18294: );
18295: if ($captcha_result->{is_valid}) {
18296: $captcha_chk = 1;
18297: }
1.1094 raeburn 18298: }
18299: return $captcha_chk;
18300: }
18301:
1.1174 raeburn 18302: sub emailusername_info {
1.1244 raeburn 18303: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 18304: my %titles = &Apache::lonlocal::texthash (
18305: lastname => 'Last Name',
18306: firstname => 'First Name',
18307: institution => 'School/college/university',
18308: location => "School's city, state/province, country",
18309: web => "School's web address",
18310: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 18311: id => 'Student/Employee ID',
1.1174 raeburn 18312: );
18313: return (\@fields,\%titles);
18314: }
18315:
1.1161 raeburn 18316: sub cleanup_html {
18317: my ($incoming) = @_;
18318: my $outgoing;
18319: if ($incoming ne '') {
18320: $outgoing = $incoming;
18321: $outgoing =~ s/;/;/g;
18322: $outgoing =~ s/\#/#/g;
18323: $outgoing =~ s/\&/&/g;
18324: $outgoing =~ s/</</g;
18325: $outgoing =~ s/>/>/g;
18326: $outgoing =~ s/\(/(/g;
18327: $outgoing =~ s/\)/)/g;
18328: $outgoing =~ s/"/"/g;
18329: $outgoing =~ s/'/'/g;
18330: $outgoing =~ s/\$/$/g;
18331: $outgoing =~ s{/}{/}g;
18332: $outgoing =~ s/=/=/g;
18333: $outgoing =~ s/\\/\/g
18334: }
18335: return $outgoing;
18336: }
18337:
1.1190 musolffc 18338: # Checks for critical messages and returns a redirect url if one exists.
18339: # $interval indicates how often to check for messages.
1.1282 raeburn 18340: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 18341: sub critical_redirect {
1.1282 raeburn 18342: my ($interval,$context) = @_;
1.1356 raeburn 18343: unless (($env{'user.domain'} ne '') && ($env{'user.name'} ne '')) {
18344: return ();
18345: }
1.1190 musolffc 18346: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 18347: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
18348: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
18349: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
18350: my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
18351: if ($blocked) {
18352: my $checkrole = "cm./$cdom/$cnum";
18353: if ($env{'request.course.sec'} ne '') {
18354: $checkrole .= "/$env{'request.course.sec'}";
18355: }
18356: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
18357: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
18358: return;
18359: }
18360: }
18361: }
1.1190 musolffc 18362: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
18363: $env{'user.name'});
18364: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 18365: my $redirecturl;
1.1190 musolffc 18366: if ($what[0]) {
1.1356 raeburn 18367: if (($what[0] ne 'con_lost') && ($what[0] ne 'no_such_host') && ($what[0]!~/^error\:/)) {
1.1190 musolffc 18368: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 18369: my $url=&Apache::lonnet::absolute_url().$redirecturl;
18370: return (1, $url);
1.1190 musolffc 18371: }
1.1191 raeburn 18372: }
18373: }
18374: return ();
1.1190 musolffc 18375: }
18376:
1.1174 raeburn 18377: # Use:
18378: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
18379: #
18380: ##################################################
18381: # password associated functions #
18382: ##################################################
18383: sub des_keys {
18384: # Make a new key for DES encryption.
18385: # Each key has two parts which are returned separately.
18386: # Please note: Each key must be passed through the &hex function
18387: # before it is output to the web browser. The hex versions cannot
18388: # be used to decrypt.
18389: my @hexstr=('0','1','2','3','4','5','6','7',
18390: '8','9','a','b','c','d','e','f');
18391: my $lkey='';
18392: for (0..7) {
18393: $lkey.=$hexstr[rand(15)];
18394: }
18395: my $ukey='';
18396: for (0..7) {
18397: $ukey.=$hexstr[rand(15)];
18398: }
18399: return ($lkey,$ukey);
18400: }
18401:
18402: sub des_decrypt {
18403: my ($key,$cyphertext) = @_;
18404: my $keybin=pack("H16",$key);
18405: my $cypher;
18406: if ($Crypt::DES::VERSION>=2.03) {
18407: $cypher=new Crypt::DES $keybin;
18408: } else {
18409: $cypher=new DES $keybin;
18410: }
1.1233 raeburn 18411: my $plaintext='';
18412: my $cypherlength = length($cyphertext);
18413: my $numchunks = int($cypherlength/32);
18414: for (my $j=0; $j<$numchunks; $j++) {
18415: my $start = $j*32;
18416: my $cypherblock = substr($cyphertext,$start,32);
18417: my $chunk =
18418: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18419: $chunk .=
18420: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18421: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18422: $plaintext .= $chunk;
18423: }
1.1174 raeburn 18424: return $plaintext;
18425: }
18426:
1.1344 raeburn 18427: sub get_requested_shorturls {
1.1309 raeburn 18428: my ($cdom,$cnum,$navmap) = @_;
18429: return unless (ref($navmap));
1.1344 raeburn 18430: my ($numnew,$errors);
1.1309 raeburn 18431: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18432: if (@toshorten) {
18433: my (%maps,%resources,%titles);
18434: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18435: 'shorturls',$cdom,$cnum);
18436: if (keys(%resources)) {
1.1344 raeburn 18437: my %tocreate;
1.1309 raeburn 18438: foreach my $item (sort {$a <=> $b} (@toshorten)) {
18439: my $symb = $resources{$item};
18440: if ($symb) {
18441: $tocreate{$cnum.'&'.$symb} = 1;
18442: }
18443: }
1.1344 raeburn 18444: if (keys(%tocreate)) {
18445: ($numnew,$errors) = &make_short_symbs($cdom,$cnum,
18446: \%tocreate);
18447: }
1.1309 raeburn 18448: }
1.1344 raeburn 18449: }
18450: return ($numnew,$errors);
18451: }
18452:
18453: sub make_short_symbs {
18454: my ($cdom,$cnum,$tocreateref,$lockuser) = @_;
18455: my ($numnew,@errors);
18456: if (ref($tocreateref) eq 'HASH') {
18457: my %tocreate = %{$tocreateref};
1.1309 raeburn 18458: if (keys(%tocreate)) {
18459: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18460: my $su = Short::URL->new(no_vowels => 1);
18461: my $init = '';
18462: my (%newunique,%addcourse,%courseonly,%failed);
18463: # get lock on tiny db
18464: my $now = time;
1.1344 raeburn 18465: if ($lockuser eq '') {
18466: $lockuser = $env{'user.name'}.':'.$env{'user.domain'};
18467: }
1.1309 raeburn 18468: my $lockhash = {
1.1344 raeburn 18469: "lock\0$now" => $lockuser,
1.1309 raeburn 18470: };
18471: my $tries = 0;
18472: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18473: my ($code,$error);
18474: while (($gotlock ne 'ok') && ($tries<3)) {
18475: $tries ++;
18476: sleep 1;
1.1319 raeburn 18477: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 18478: }
18479: if ($gotlock eq 'ok') {
18480: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
18481: \%addcourse,\%courseonly,\%failed);
18482: if (keys(%failed)) {
18483: my $numfailed = scalar(keys(%failed));
18484: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
18485: }
18486: if (keys(%newunique)) {
18487: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
18488: if ($putres eq 'ok') {
18489: $numnew = scalar(keys(%newunique));
18490: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
18491: unless ($newputres eq 'ok') {
18492: push(@errors,&mt('error: could not store course look-up of short URLs'));
18493: }
18494: } else {
18495: push(@errors,&mt('error: could not store unique six character URLs'));
18496: }
18497: }
18498: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
18499: unless ($dellockres eq 'ok') {
18500: push(@errors,&mt('error: could not release lockfile'));
18501: }
18502: } else {
18503: push(@errors,&mt('error: could not obtain lockfile'));
18504: }
18505: if (keys(%courseonly)) {
18506: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
18507: if ($result ne 'ok') {
18508: push(@errors,&mt('error: could not update course look-up of short URLs'));
18509: }
18510: }
18511: }
18512: }
18513: return ($numnew,\@errors);
18514: }
18515:
18516: sub shorten_symbs {
18517: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
18518: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
18519: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
18520: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
18521: my (%possibles,%collisions);
18522: foreach my $key (keys(%{$tocreate})) {
18523: my $num = String::CRC32::crc32($key);
18524: my $tiny = $su->encode($num,$init);
18525: if ($tiny) {
18526: $possibles{$tiny} = $key;
18527: }
18528: }
18529: if (!$init) {
18530: $init = 1;
18531: } else {
18532: $init ++;
18533: }
18534: if (keys(%possibles)) {
18535: my @posstiny = keys(%possibles);
18536: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18537: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18538: if (keys(%currtiny)) {
18539: foreach my $key (keys(%currtiny)) {
18540: next if ($currtiny{$key} eq '');
18541: if ($currtiny{$key} eq $possibles{$key}) {
18542: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18543: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18544: $courseonly->{$tsymb} = $key;
18545: }
18546: } else {
18547: $collisions{$possibles{$key}} = 1;
18548: }
18549: delete($possibles{$key});
18550: }
18551: }
18552: foreach my $key (keys(%possibles)) {
18553: $newunique->{$key} = $possibles{$key};
18554: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18555: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18556: $addcourse->{$tsymb} = $key;
18557: }
18558: }
18559: }
18560: if (keys(%collisions)) {
18561: if ($init <5) {
18562: if (!$init) {
18563: $init = 1;
18564: } else {
18565: $init ++;
18566: }
18567: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
18568: $newunique,$addcourse,$courseonly,$failed);
18569: } else {
18570: foreach my $key (keys(%collisions)) {
18571: $failed->{$key} = 1;
18572: }
18573: }
18574: }
18575: return $init;
18576: }
18577:
1.1328 raeburn 18578: sub is_nonframeable {
1.1329 raeburn 18579: my ($url,$absolute,$hostname,$ip,$nocache) = @_;
18580: my ($remprotocol,$remhost) = ($url =~ m{^(https?)\://(([a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})}i);
1.1330 raeburn 18581: return if (($remprotocol eq '') || ($remhost eq ''));
1.1329 raeburn 18582:
18583: $remprotocol = lc($remprotocol);
18584: $remhost = lc($remhost);
18585: my $remport = 80;
18586: if ($remprotocol eq 'https') {
18587: $remport = 443;
18588: }
1.1330 raeburn 18589: my ($result,$cached) = &Apache::lonnet::is_cached_new('noiframe',$remhost.':'.$remport);
1.1329 raeburn 18590: if ($cached) {
18591: unless ($nocache) {
18592: if ($result) {
18593: return 1;
18594: } else {
18595: return 0;
18596: }
18597: }
18598: }
1.1328 raeburn 18599: my $uselink;
18600: my $request = new HTTP::Request('HEAD',$url);
18601: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',5);
18602: if ($response->is_success()) {
18603: my $secpolicy = lc($response->header('content-security-policy'));
18604: my $xframeop = lc($response->header('x-frame-options'));
18605: $secpolicy =~ s/^\s+|\s+$//g;
18606: $xframeop =~ s/^\s+|\s+$//g;
18607: if (($secpolicy ne '') || ($xframeop ne '')) {
1.1329 raeburn 18608: my $remotehost = $remprotocol.'://'.$remhost;
1.1328 raeburn 18609: my ($origin,$protocol,$port);
18610: if ($ENV{'SERVER_PORT'} =~/^\d+$/) {
18611: $port = $ENV{'SERVER_PORT'};
18612: } else {
18613: $port = 80;
18614: }
18615: if ($absolute eq '') {
18616: $protocol = 'http:';
18617: if ($port == 443) {
18618: $protocol = 'https:';
18619: }
18620: $origin = $protocol.'//'.lc($hostname);
18621: } else {
18622: $origin = lc($absolute);
18623: ($protocol,$hostname) = ($absolute =~ m{^(https?:)//([^/]+)$});
18624: }
18625: if (($secpolicy) && ($secpolicy =~ /\Qframe-ancestors\E([^;]*)(;|$)/)) {
18626: my $framepolicy = $1;
18627: $framepolicy =~ s/^\s+|\s+$//g;
18628: my @policies = split(/\s+/,$framepolicy);
18629: if (@policies) {
18630: if (grep(/^\Q'none'\E$/,@policies)) {
18631: $uselink = 1;
18632: } else {
18633: $uselink = 1;
18634: if ((grep(/^\Q*\E$/,@policies)) || (grep(/^\Q$protocol\E$/,@policies)) ||
18635: (($origin ne '') && (grep(/^\Q$origin\E$/,@policies))) ||
18636: (($ip ne '') && (grep(/^\Q$ip\E$/,@policies)))) {
18637: undef($uselink);
18638: }
18639: if ($uselink) {
18640: if (grep(/^\Q'self'\E$/,@policies)) {
18641: if (($origin ne '') && ($remotehost eq $origin)) {
18642: undef($uselink);
18643: }
18644: }
18645: }
18646: if ($uselink) {
18647: my @possok;
18648: if ($ip ne '') {
18649: push(@possok,$ip);
18650: }
18651: my $hoststr = '';
18652: foreach my $part (reverse(split(/\./,$hostname))) {
18653: if ($hoststr eq '') {
18654: $hoststr = $part;
18655: } else {
18656: $hoststr = "$part.$hoststr";
18657: }
18658: if ($hoststr eq $hostname) {
18659: push(@possok,$hostname);
18660: } else {
18661: push(@possok,"*.$hoststr");
18662: }
18663: }
18664: if (@possok) {
18665: foreach my $poss (@possok) {
18666: last if (!$uselink);
18667: foreach my $policy (@policies) {
18668: if ($policy =~ m{^(\Q$protocol\E//|)\Q$poss\E(\Q:$port\E|)$}) {
18669: undef($uselink);
18670: last;
18671: }
18672: }
18673: }
18674: }
18675: }
18676: }
18677: }
18678: } elsif ($xframeop ne '') {
18679: $uselink = 1;
18680: my @policies = split(/\s*,\s*/,$xframeop);
18681: if (@policies) {
18682: unless (grep(/^deny$/,@policies)) {
18683: if ($origin ne '') {
18684: if (grep(/^sameorigin$/,@policies)) {
18685: if ($remotehost eq $origin) {
18686: undef($uselink);
18687: }
18688: }
18689: if ($uselink) {
18690: foreach my $policy (@policies) {
18691: if ($policy =~ /^allow-from\s*(.+)$/) {
18692: my $allowfrom = $1;
18693: if (($allowfrom ne '') && ($allowfrom eq $origin)) {
18694: undef($uselink);
18695: last;
18696: }
18697: }
18698: }
18699: }
18700: }
18701: }
18702: }
18703: }
18704: }
18705: }
1.1329 raeburn 18706: if ($nocache) {
18707: if ($cached) {
18708: my $devalidate;
18709: if ($uselink && !$result) {
18710: $devalidate = 1;
18711: } elsif (!$uselink && $result) {
18712: $devalidate = 1;
18713: }
18714: if ($devalidate) {
18715: &Apache::lonnet::devalidate_cache_new('noiframe',$remhost.':'.$remport);
18716: }
18717: }
18718: } else {
18719: if ($uselink) {
18720: $result = 1;
18721: } else {
18722: $result = 0;
18723: }
18724: &Apache::lonnet::do_cache_new('noiframe',$remhost.':'.$remport,$result,3600);
18725: }
1.1328 raeburn 18726: return $uselink;
18727: }
18728:
1.1359 raeburn 18729: sub page_menu {
18730: my ($menucolls,$menunum) = @_;
18731: my %menu;
18732: foreach my $item (split(/;/,$menucolls)) {
18733: my ($num,$value) = split(/\%/,$item);
18734: if ($num eq $menunum) {
18735: my @entries = split(/\&/,$value);
18736: foreach my $entry (@entries) {
18737: my ($name,$fields) = split(/=/,$entry);
18738: if (($name eq 'top') || ($name eq 'inline') || ($name eq 'main')) {
18739: $menu{$name} = $fields;
18740: } else {
18741: my @shown;
18742: if ($fields =~ /,/) {
18743: @shown = split(/,/,$fields);
18744: } else {
18745: @shown = ($fields);
18746: }
18747: if (@shown) {
18748: foreach my $field (@shown) {
18749: next if ($field eq '');
18750: $menu{$field} = 1;
18751: }
18752: }
18753: }
18754: }
18755: }
18756: }
18757: return %menu;
18758: }
18759:
1.112 bowersj2 18760: 1;
18761: __END__;
1.41 ng 18762:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>