Annotation of loncom/interface/loncommon.pm, revision 1.1322
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1322 ! raeburn 4: # $Id: loncommon.pm,v 1.1321 2018/09/18 02:18:43 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.657 raeburn 75: use DateTime::TimeZone;
1.1241 raeburn 76: use DateTime::Locale;
1.1220 raeburn 77: use Encode();
1.1091 foxr 78: use Text::Aspell;
1.1094 raeburn 79: use Authen::Captcha;
80: use Captcha::reCAPTCHA;
1.1234 raeburn 81: use JSON::DWIW;
82: use LWP::UserAgent;
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.999 www 438: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
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.793 raeburn 453: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 454: var title = 'Student_Browser';
1.74 www 455: var options = 'scrollbars=1,resizable=1,menubar=0';
456: options += ',width=700,height=600';
457: stdeditbrowser = open(url,title,options,'1');
458: stdeditbrowser.focus();
459: }
1.824 bisitz 460: // ]]>
1.74 www 461: </script>
462: ENDSTDBRW
463: }
1.42 matthew 464:
1.1003 www 465: sub resourcebrowser_javascript {
466: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 467: return (<<'ENDRESBRW');
1.1003 www 468: <script type="text/javascript" language="Javascript">
469: // <![CDATA[
470: var reseditbrowser;
1.1004 www 471: function openresbrowser(formname,reslink) {
1.1005 www 472: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 473: var title = 'Resource_Browser';
474: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 475: options += ',width=700,height=500';
1.1004 www 476: reseditbrowser = open(url,title,options,'1');
477: reseditbrowser.focus();
1.1003 www 478: }
479: // ]]>
480: </script>
1.1004 www 481: ENDRESBRW
1.1003 www 482: }
483:
1.74 www 484: sub selectstudent_link {
1.999 www 485: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
486: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
487: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
488: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 489: if ($env{'request.course.id'}) {
1.302 albertel 490: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
491: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
492: '/'.$env{'request.course.sec'})) {
1.111 www 493: return '';
494: }
1.999 www 495: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 496: if ($courseadvonly) {
497: $callargs .= ",'',1,1";
498: }
499: return '<span class="LC_nobreak">'.
500: '<a href="javascript:openstdbrowser('.$callargs.');">'.
501: &mt('Select User').'</a></span>';
1.74 www 502: }
1.258 albertel 503: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 504: $callargs .= ",'',1";
1.793 raeburn 505: return '<span class="LC_nobreak">'.
506: '<a href="javascript:openstdbrowser('.$callargs.');">'.
507: &mt('Select User').'</a></span>';
1.111 www 508: }
509: return '';
1.91 www 510: }
511:
1.1004 www 512: sub selectresource_link {
513: my ($form,$reslink,$arg)=@_;
514:
515: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
516: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
517: unless ($env{'request.course.id'}) { return $arg; }
518: return '<span class="LC_nobreak">'.
519: '<a href="javascript:openresbrowser('.$callargs.');">'.
520: $arg.'</a></span>';
521: }
522:
523:
524:
1.653 raeburn 525: sub authorbrowser_javascript {
526: return <<"ENDAUTHORBRW";
1.776 bisitz 527: <script type="text/javascript" language="JavaScript">
1.824 bisitz 528: // <![CDATA[
1.653 raeburn 529: var stdeditbrowser;
530:
531: function openauthorbrowser(formname,udom) {
532: var url = '/adm/pickauthor?';
533: url += 'form='+formname+'&roledom='+udom;
534: var title = 'Author_Browser';
535: var options = 'scrollbars=1,resizable=1,menubar=0';
536: options += ',width=700,height=600';
537: stdeditbrowser = open(url,title,options,'1');
538: stdeditbrowser.focus();
539: }
540:
1.824 bisitz 541: // ]]>
1.653 raeburn 542: </script>
543: ENDAUTHORBRW
544: }
545:
1.91 www 546: sub coursebrowser_javascript {
1.1116 raeburn 547: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1221 raeburn 548: $credits_element,$instcode) = @_;
1.932 raeburn 549: my $wintitle = 'Course_Browser';
1.931 raeburn 550: if ($crstype eq 'Community') {
1.932 raeburn 551: $wintitle = 'Community_Browser';
1.909 raeburn 552: }
1.876 raeburn 553: my $id_functions = &javascript_index_functions();
554: my $output = '
1.776 bisitz 555: <script type="text/javascript" language="JavaScript">
1.824 bisitz 556: // <![CDATA[
1.468 raeburn 557: var stdeditbrowser;'."\n";
1.876 raeburn 558:
559: $output .= <<"ENDSTDBRW";
1.909 raeburn 560: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 561: var url = '/adm/pickcourse?';
1.895 raeburn 562: var formid = getFormIdByName(formname);
1.876 raeburn 563: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 564: if (domainfilter != null) {
565: if (domainfilter != '') {
566: url += 'domainfilter='+domainfilter+'&';
567: }
568: }
1.91 www 569: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 570: '&cdomelement='+udom+
571: '&cnameelement='+desc;
1.468 raeburn 572: if (extra_element !=null && extra_element != '') {
1.594 raeburn 573: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 574: url += '&roleelement='+extra_element;
575: if (domainfilter == null || domainfilter == '') {
576: url += '&domainfilter='+extra_element;
577: }
1.234 raeburn 578: }
1.468 raeburn 579: else {
580: if (formname == 'portform') {
581: url += '&setroles='+extra_element;
1.800 raeburn 582: } else {
583: if (formname == 'rules') {
584: url += '&fixeddom='+extra_element;
585: }
1.468 raeburn 586: }
587: }
1.230 raeburn 588: }
1.909 raeburn 589: if (type != null && type != '') {
590: url += '&type='+type;
591: }
592: if (type_elem != null && type_elem != '') {
593: url += '&typeelement='+type_elem;
594: }
1.872 raeburn 595: if (formname == 'ccrs') {
596: var ownername = document.forms[formid].ccuname.value;
597: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1238 raeburn 598: url += '&cloner='+ownername+':'+ownerdom;
599: if (type == 'Course') {
600: url += '&crscode='+document.forms[formid].crscode.value;
601: }
1.1221 raeburn 602: }
603: if (formname == 'requestcrs') {
604: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 605: }
1.293 raeburn 606: if (multflag !=null && multflag != '') {
607: url += '&multiple='+multflag;
608: }
1.909 raeburn 609: var title = '$wintitle';
1.91 www 610: var options = 'scrollbars=1,resizable=1,menubar=0';
611: options += ',width=700,height=600';
612: stdeditbrowser = open(url,title,options,'1');
613: stdeditbrowser.focus();
614: }
1.876 raeburn 615: $id_functions
616: ENDSTDBRW
1.1116 raeburn 617: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
618: $output .= &setsec_javascript($sec_element,$formname,$role_element,
619: $credits_element);
1.876 raeburn 620: }
621: $output .= '
622: // ]]>
623: </script>';
624: return $output;
625: }
626:
627: sub javascript_index_functions {
628: return <<"ENDJS";
629:
630: function getFormIdByName(formname) {
631: for (var i=0;i<document.forms.length;i++) {
632: if (document.forms[i].name == formname) {
633: return i;
634: }
635: }
636: return -1;
637: }
638:
639: function getIndexByName(formid,item) {
640: for (var i=0;i<document.forms[formid].elements.length;i++) {
641: if (document.forms[formid].elements[i].name == item) {
642: return i;
643: }
644: }
645: return -1;
646: }
1.468 raeburn 647:
1.876 raeburn 648: function getDomainFromSelectbox(formname,udom) {
649: var userdom;
650: var formid = getFormIdByName(formname);
651: if (formid > -1) {
652: var domid = getIndexByName(formid,udom);
653: if (domid > -1) {
654: if (document.forms[formid].elements[domid].type == 'select-one') {
655: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
656: }
657: if (document.forms[formid].elements[domid].type == 'hidden') {
658: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 659: }
660: }
661: }
1.876 raeburn 662: return userdom;
663: }
664:
665: ENDJS
1.468 raeburn 666:
1.876 raeburn 667: }
668:
1.1017 raeburn 669: sub javascript_array_indexof {
1.1018 raeburn 670: return <<ENDJS;
1.1017 raeburn 671: <script type="text/javascript" language="JavaScript">
672: // <![CDATA[
673:
674: if (!Array.prototype.indexOf) {
675: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
676: "use strict";
677: if (this === void 0 || this === null) {
678: throw new TypeError();
679: }
680: var t = Object(this);
681: var len = t.length >>> 0;
682: if (len === 0) {
683: return -1;
684: }
685: var n = 0;
686: if (arguments.length > 0) {
687: n = Number(arguments[1]);
1.1088 foxr 688: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 689: n = 0;
690: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
691: n = (n > 0 || -1) * Math.floor(Math.abs(n));
692: }
693: }
694: if (n >= len) {
695: return -1;
696: }
697: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
698: for (; k < len; k++) {
699: if (k in t && t[k] === searchElement) {
700: return k;
701: }
702: }
703: return -1;
704: }
705: }
706:
707: // ]]>
708: </script>
709:
710: ENDJS
711:
712: }
713:
1.876 raeburn 714: sub userbrowser_javascript {
715: my $id_functions = &javascript_index_functions();
716: return <<"ENDUSERBRW";
717:
1.888 raeburn 718: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 719: var url = '/adm/pickuser?';
720: var userdom = getDomainFromSelectbox(formname,udom);
721: if (userdom != null) {
722: if (userdom != '') {
723: url += 'srchdom='+userdom+'&';
724: }
725: }
726: url += 'form=' + formname + '&unameelement='+uname+
727: '&udomelement='+udom+
728: '&ulastelement='+ulast+
729: '&ufirstelement='+ufirst+
730: '&uemailelement='+uemail+
1.881 raeburn 731: '&hideudomelement='+hideudom+
732: '&coursedom='+crsdom;
1.888 raeburn 733: if ((caller != null) && (caller != undefined)) {
734: url += '&caller='+caller;
735: }
1.876 raeburn 736: var title = 'User_Browser';
737: var options = 'scrollbars=1,resizable=1,menubar=0';
738: options += ',width=700,height=600';
739: var stdeditbrowser = open(url,title,options,'1');
740: stdeditbrowser.focus();
741: }
742:
1.888 raeburn 743: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 744: var formid = getFormIdByName(formname);
745: if (formid > -1) {
1.888 raeburn 746: var unameid = getIndexByName(formid,uname);
1.876 raeburn 747: var domid = getIndexByName(formid,udom);
748: var hidedomid = getIndexByName(formid,origdom);
749: if (hidedomid > -1) {
750: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 751: var unameval = document.forms[formid].elements[unameid].value;
752: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
753: if (domid > -1) {
754: var slct = document.forms[formid].elements[domid];
755: if (slct.type == 'select-one') {
756: var i;
757: for (i=0;i<slct.length;i++) {
758: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
759: }
760: }
761: if (slct.type == 'hidden') {
762: slct.value = fixeddom;
1.876 raeburn 763: }
764: }
1.468 raeburn 765: }
766: }
767: }
1.876 raeburn 768: return;
769: }
770:
771: $id_functions
772: ENDUSERBRW
1.468 raeburn 773: }
774:
775: sub setsec_javascript {
1.1116 raeburn 776: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 777: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
778: $communityrolestr);
779: if ($role_element ne '') {
780: my @allroles = ('st','ta','ep','in','ad');
781: foreach my $crstype ('Course','Community') {
782: if ($crstype eq 'Community') {
783: foreach my $role (@allroles) {
784: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
785: }
786: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
787: } else {
788: foreach my $role (@allroles) {
789: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
790: }
791: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
792: }
793: }
794: $rolestr = '"'.join('","',@allroles).'"';
795: $courserolestr = '"'.join('","',@courserolenames).'"';
796: $communityrolestr = '"'.join('","',@communityrolenames).'"';
797: }
1.468 raeburn 798: my $setsections = qq|
799: function setSect(sectionlist) {
1.629 raeburn 800: var sectionsArray = new Array();
801: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
802: sectionsArray = sectionlist.split(",");
803: }
1.468 raeburn 804: var numSections = sectionsArray.length;
805: document.$formname.$sec_element.length = 0;
806: if (numSections == 0) {
807: document.$formname.$sec_element.multiple=false;
808: document.$formname.$sec_element.size=1;
809: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
810: } else {
811: if (numSections == 1) {
812: document.$formname.$sec_element.multiple=false;
813: document.$formname.$sec_element.size=1;
814: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
815: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
816: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
817: } else {
818: for (var i=0; i<numSections; i++) {
819: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
820: }
821: document.$formname.$sec_element.multiple=true
822: if (numSections < 3) {
823: document.$formname.$sec_element.size=numSections;
824: } else {
825: document.$formname.$sec_element.size=3;
826: }
827: document.$formname.$sec_element.options[0].selected = false
828: }
829: }
1.91 www 830: }
1.905 raeburn 831:
832: function setRole(crstype) {
1.468 raeburn 833: |;
1.905 raeburn 834: if ($role_element eq '') {
835: $setsections .= ' return;
836: }
837: ';
838: } else {
839: $setsections .= qq|
840: var elementLength = document.$formname.$role_element.length;
841: var allroles = Array($rolestr);
842: var courserolenames = Array($courserolestr);
843: var communityrolenames = Array($communityrolestr);
844: if (elementLength != undefined) {
845: if (document.$formname.$role_element.options[5].value == 'cc') {
846: if (crstype == 'Course') {
847: return;
848: } else {
849: allroles[5] = 'co';
850: for (var i=0; i<6; i++) {
851: document.$formname.$role_element.options[i].value = allroles[i];
852: document.$formname.$role_element.options[i].text = communityrolenames[i];
853: }
854: }
855: } else {
856: if (crstype == 'Community') {
857: return;
858: } else {
859: allroles[5] = 'cc';
860: for (var i=0; i<6; i++) {
861: document.$formname.$role_element.options[i].value = allroles[i];
862: document.$formname.$role_element.options[i].text = courserolenames[i];
863: }
864: }
865: }
866: }
867: return;
868: }
869: |;
870: }
1.1116 raeburn 871: if ($credits_element) {
872: $setsections .= qq|
873: function setCredits(defaultcredits) {
874: document.$formname.$credits_element.value = defaultcredits;
875: return;
876: }
877: |;
878: }
1.468 raeburn 879: return $setsections;
880: }
881:
1.91 www 882: sub selectcourse_link {
1.909 raeburn 883: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
884: $typeelement) = @_;
885: my $type = $selecttype;
1.871 raeburn 886: my $linktext = &mt('Select Course');
887: if ($selecttype eq 'Community') {
1.909 raeburn 888: $linktext = &mt('Select Community');
1.1239 raeburn 889: } elsif ($selecttype eq 'Placement') {
890: $linktext = &mt('Select Placement Test');
1.906 raeburn 891: } elsif ($selecttype eq 'Course/Community') {
892: $linktext = &mt('Select Course/Community');
1.909 raeburn 893: $type = '';
1.1019 raeburn 894: } elsif ($selecttype eq 'Select') {
895: $linktext = &mt('Select');
896: $type = '';
1.871 raeburn 897: }
1.787 bisitz 898: return '<span class="LC_nobreak">'
899: ."<a href='"
900: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
901: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 902: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 903: ."'>".$linktext.'</a>'
1.787 bisitz 904: .'</span>';
1.74 www 905: }
1.42 matthew 906:
1.653 raeburn 907: sub selectauthor_link {
908: my ($form,$udom)=@_;
909: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
910: &mt('Select Author').'</a>';
911: }
912:
1.876 raeburn 913: sub selectuser_link {
1.881 raeburn 914: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 915: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 916: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 917: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 918: ');">'.$linktext.'</a>';
1.876 raeburn 919: }
920:
1.273 raeburn 921: sub check_uncheck_jscript {
922: my $jscript = <<"ENDSCRT";
923: function checkAll(field) {
924: if (field.length > 0) {
925: for (i = 0; i < field.length; i++) {
1.1093 raeburn 926: if (!field[i].disabled) {
927: field[i].checked = true;
928: }
1.273 raeburn 929: }
930: } else {
1.1093 raeburn 931: if (!field.disabled) {
932: field.checked = true;
933: }
1.273 raeburn 934: }
935: }
936:
937: function uncheckAll(field) {
938: if (field.length > 0) {
939: for (i = 0; i < field.length; i++) {
940: field[i].checked = false ;
1.543 albertel 941: }
942: } else {
1.273 raeburn 943: field.checked = false ;
944: }
945: }
946: ENDSCRT
947: return $jscript;
948: }
949:
1.656 www 950: sub select_timezone {
1.1256 raeburn 951: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
952: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 953: if ($includeempty) {
954: $output .= '<option value=""';
955: if (($selected eq '') || ($selected eq 'local')) {
956: $output .= ' selected="selected" ';
957: }
958: $output .= '> </option>';
959: }
1.657 raeburn 960: my @timezones = DateTime::TimeZone->all_names;
961: foreach my $tzone (@timezones) {
962: $output.= '<option value="'.$tzone.'"';
963: if ($tzone eq $selected) {
964: $output.=' selected="selected"';
965: }
966: $output.=">$tzone</option>\n";
1.656 www 967: }
968: $output.="</select>";
969: return $output;
970: }
1.273 raeburn 971:
1.687 raeburn 972: sub select_datelocale {
1.1256 raeburn 973: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
974: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 975: if ($includeempty) {
976: $output .= '<option value=""';
977: if ($selected eq '') {
978: $output .= ' selected="selected" ';
979: }
980: $output .= '> </option>';
981: }
1.1241 raeburn 982: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 983: my (@possibles,%locale_names);
1.1241 raeburn 984: my @locales = DateTime::Locale->ids();
985: foreach my $id (@locales) {
986: if ($id ne '') {
987: my ($en_terr,$native_terr);
988: my $loc = DateTime::Locale->load($id);
989: if (ref($loc)) {
990: $en_terr = $loc->name();
991: $native_terr = $loc->native_name();
1.687 raeburn 992: if (grep(/^en$/,@languages) || !@languages) {
993: if ($en_terr ne '') {
994: $locale_names{$id} = '('.$en_terr.')';
995: } elsif ($native_terr ne '') {
996: $locale_names{$id} = $native_terr;
997: }
998: } else {
999: if ($native_terr ne '') {
1000: $locale_names{$id} = $native_terr.' ';
1001: } elsif ($en_terr ne '') {
1002: $locale_names{$id} = '('.$en_terr.')';
1003: }
1004: }
1.1220 raeburn 1005: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1241 raeburn 1006: push(@possibles,$id);
1007: }
1.687 raeburn 1008: }
1009: }
1010: foreach my $item (sort(@possibles)) {
1011: $output.= '<option value="'.$item.'"';
1012: if ($item eq $selected) {
1013: $output.=' selected="selected"';
1014: }
1015: $output.=">$item";
1016: if ($locale_names{$item} ne '') {
1.1220 raeburn 1017: $output.=' '.$locale_names{$item};
1.687 raeburn 1018: }
1019: $output.="</option>\n";
1020: }
1021: $output.="</select>";
1022: return $output;
1023: }
1024:
1.792 raeburn 1025: sub select_language {
1.1256 raeburn 1026: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1027: my %langchoices;
1028: if ($includeempty) {
1.1117 raeburn 1029: %langchoices = ('' => 'No language preference');
1.792 raeburn 1030: }
1031: foreach my $id (&languageids()) {
1032: my $code = &supportedlanguagecode($id);
1033: if ($code) {
1034: $langchoices{$code} = &plainlanguagedescription($id);
1035: }
1036: }
1.1117 raeburn 1037: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1256 raeburn 1038: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1039: }
1040:
1.42 matthew 1041: =pod
1.36 matthew 1042:
1.1088 foxr 1043:
1044: =item * &list_languages()
1045:
1046: Returns an array reference that is suitable for use in language prompters.
1047: Each array element is itself a two element array. The first element
1048: is the language code. The second element a descsriptiuon of the
1049: language itself. This is suitable for use in e.g.
1050: &Apache::edit::select_arg (once dereferenced that is).
1051:
1052: =cut
1053:
1054: sub list_languages {
1055: my @lang_choices;
1056:
1057: foreach my $id (&languageids()) {
1058: my $code = &supportedlanguagecode($id);
1059: if ($code) {
1060: my $selector = $supported_codes{$id};
1061: my $description = &plainlanguagedescription($id);
1.1263 raeburn 1062: push(@lang_choices, [$selector, $description]);
1.1088 foxr 1063: }
1064: }
1065: return \@lang_choices;
1066: }
1067:
1068: =pod
1069:
1.648 raeburn 1070: =item * &linked_select_forms(...)
1.36 matthew 1071:
1072: linked_select_forms returns a string containing a <script></script> block
1073: and html for two <select> menus. The select menus will be linked in that
1074: changing the value of the first menu will result in new values being placed
1075: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1076: order unless a defined order is provided.
1.36 matthew 1077:
1078: linked_select_forms takes the following ordered inputs:
1079:
1080: =over 4
1081:
1.112 bowersj2 1082: =item * $formname, the name of the <form> tag
1.36 matthew 1083:
1.112 bowersj2 1084: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1085:
1.112 bowersj2 1086: =item * $firstdefault, the default value for the first menu
1.36 matthew 1087:
1.112 bowersj2 1088: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1089:
1.112 bowersj2 1090: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1091:
1.112 bowersj2 1092: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1093:
1.609 raeburn 1094: =item * $menuorder, the order of values in the first menu
1095:
1.1115 raeburn 1096: =item * $onchangefirst, additional javascript call to execute for an onchange
1097: event for the first <select> tag
1098:
1099: =item * $onchangesecond, additional javascript call to execute for an onchange
1100: event for the second <select> tag
1101:
1.1245 raeburn 1102: =item * $suffix, to differentiate separate uses of select2data javascript
1103: objects in a page.
1104:
1.41 ng 1105: =back
1106:
1.36 matthew 1107: Below is an example of such a hash. Only the 'text', 'default', and
1108: 'select2' keys must appear as stated. keys(%menu) are the possible
1109: values for the first select menu. The text that coincides with the
1.41 ng 1110: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1111: and text for the second menu are given in the hash pointed to by
1112: $menu{$choice1}->{'select2'}.
1113:
1.112 bowersj2 1114: my %menu = ( A1 => { text =>"Choice A1" ,
1115: default => "B3",
1116: select2 => {
1117: B1 => "Choice B1",
1118: B2 => "Choice B2",
1119: B3 => "Choice B3",
1120: B4 => "Choice B4"
1.609 raeburn 1121: },
1122: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1123: },
1124: A2 => { text =>"Choice A2" ,
1125: default => "C2",
1126: select2 => {
1127: C1 => "Choice C1",
1128: C2 => "Choice C2",
1129: C3 => "Choice C3"
1.609 raeburn 1130: },
1131: order => ['C2','C1','C3'],
1.112 bowersj2 1132: },
1133: A3 => { text =>"Choice A3" ,
1134: default => "D6",
1135: select2 => {
1136: D1 => "Choice D1",
1137: D2 => "Choice D2",
1138: D3 => "Choice D3",
1139: D4 => "Choice D4",
1140: D5 => "Choice D5",
1141: D6 => "Choice D6",
1142: D7 => "Choice D7"
1.609 raeburn 1143: },
1144: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1145: }
1146: );
1.36 matthew 1147:
1148: =cut
1149:
1150: sub linked_select_forms {
1151: my ($formname,
1152: $middletext,
1153: $firstdefault,
1154: $firstselectname,
1155: $secondselectname,
1.609 raeburn 1156: $hashref,
1157: $menuorder,
1.1115 raeburn 1158: $onchangefirst,
1.1245 raeburn 1159: $onchangesecond,
1160: $suffix
1.36 matthew 1161: ) = @_;
1162: my $second = "document.$formname.$secondselectname";
1163: my $first = "document.$formname.$firstselectname";
1164: # output the javascript to do the changing
1165: my $result = '';
1.776 bisitz 1166: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1167: $result.="// <![CDATA[\n";
1.1245 raeburn 1168: $result.="var select2data${suffix} = new Object();\n";
1.36 matthew 1169: $" = '","';
1170: my $debug = '';
1171: foreach my $s1 (sort(keys(%$hashref))) {
1.1245 raeburn 1172: $result.="select2data${suffix}['d_$s1'] = new Object();\n";
1173: $result.="select2data${suffix}['d_$s1'].def = new String('".
1.36 matthew 1174: $hashref->{$s1}->{'default'}."');\n";
1.1245 raeburn 1175: $result.="select2data${suffix}['d_$s1'].values = new Array(";
1.36 matthew 1176: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1177: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1178: @s2values = @{$hashref->{$s1}->{'order'}};
1179: }
1.36 matthew 1180: $result.="\"@s2values\");\n";
1.1245 raeburn 1181: $result.="select2data${suffix}['d_$s1'].texts = new Array(";
1.36 matthew 1182: my @s2texts;
1183: foreach my $value (@s2values) {
1.1263 raeburn 1184: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1185: }
1186: $result.="\"@s2texts\");\n";
1187: }
1188: $"=' ';
1189: $result.= <<"END";
1190:
1.1245 raeburn 1191: function select1${suffix}_changed() {
1.36 matthew 1192: // Determine new choice
1.1245 raeburn 1193: var newvalue = "d_" + $first.options[$first.selectedIndex].value;
1.36 matthew 1194: // update select2
1.1245 raeburn 1195: var values = select2data${suffix}[newvalue].values;
1196: var texts = select2data${suffix}[newvalue].texts;
1197: var select2def = select2data${suffix}[newvalue].def;
1.36 matthew 1198: var i;
1199: // out with the old
1.1245 raeburn 1200: $second.options.length = 0;
1201: // in with the new
1.36 matthew 1202: for (i=0;i<values.length; i++) {
1203: $second.options[i] = new Option(values[i]);
1.143 matthew 1204: $second.options[i].value = values[i];
1.36 matthew 1205: $second.options[i].text = texts[i];
1206: if (values[i] == select2def) {
1207: $second.options[i].selected = true;
1208: }
1209: }
1210: }
1.824 bisitz 1211: // ]]>
1.36 matthew 1212: </script>
1213: END
1214: # output the initial values for the selection lists
1.1245 raeburn 1215: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
1.609 raeburn 1216: my @order = sort(keys(%{$hashref}));
1217: if (ref($menuorder) eq 'ARRAY') {
1218: @order = @{$menuorder};
1219: }
1220: foreach my $value (@order) {
1.36 matthew 1221: $result.=" <option value=\"$value\" ";
1.253 albertel 1222: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1223: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1224: }
1225: $result .= "</select>\n";
1226: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1227: $result .= $middletext;
1.1115 raeburn 1228: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1229: if ($onchangesecond) {
1230: $result .= ' onchange="'.$onchangesecond.'"';
1231: }
1232: $result .= ">\n";
1.36 matthew 1233: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1234:
1235: my @secondorder = sort(keys(%select2));
1236: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1237: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1238: }
1239: foreach my $value (@secondorder) {
1.36 matthew 1240: $result.=" <option value=\"$value\" ";
1.253 albertel 1241: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1242: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1243: }
1244: $result .= "</select>\n";
1245: # return $debug;
1246: return $result;
1247: } # end of sub linked_select_forms {
1248:
1.45 matthew 1249: =pod
1.44 bowersj2 1250:
1.973 raeburn 1251: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1252:
1.112 bowersj2 1253: Returns a string corresponding to an HTML link to the given help
1254: $topic, where $topic corresponds to the name of a .tex file in
1255: /home/httpd/html/adm/help/tex, with underscores replaced by
1256: spaces.
1257:
1258: $text will optionally be linked to the same topic, allowing you to
1259: link text in addition to the graphic. If you do not want to link
1260: text, but wish to specify one of the later parameters, pass an
1261: empty string.
1262:
1263: $stayOnPage is a value that will be interpreted as a boolean. If true,
1264: the link will not open a new window. If false, the link will open
1265: a new window using Javascript. (Default is false.)
1266:
1267: $width and $height are optional numerical parameters that will
1268: override the width and height of the popped up window, which may
1.973 raeburn 1269: be useful for certain help topics with big pictures included.
1270:
1271: $imgid is the id of the img tag used for the help icon. This may be
1272: used in a javascript call to switch the image src. See
1273: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1274:
1275: =cut
1276:
1277: sub help_open_topic {
1.973 raeburn 1278: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1279: $text = "" if (not defined $text);
1.44 bowersj2 1280: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1281: $width = 500 if (not defined $width);
1.44 bowersj2 1282: $height = 400 if (not defined $height);
1283: my $filename = $topic;
1284: $filename =~ s/ /_/g;
1285:
1.48 bowersj2 1286: my $template = "";
1287: my $link;
1.572 banghart 1288:
1.159 www 1289: $topic=~s/\W/\_/g;
1.44 bowersj2 1290:
1.572 banghart 1291: if (!$stayOnPage) {
1.1033 www 1292: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1293: } elsif ($stayOnPage eq 'popup') {
1294: $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 1295: } else {
1.48 bowersj2 1296: $link = "/adm/help/${filename}.hlp";
1297: }
1298:
1299: # Add the text
1.1314 raeburn 1300: my $target = ' target="_top"';
1301: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1302: $target = '';
1303: }
1.755 neumanie 1304: if ($text ne "") {
1.763 bisitz 1305: $template.='<span class="LC_help_open_topic">'
1.1314 raeburn 1306: .'<a'.$target.' href="'.$link.'">'
1.763 bisitz 1307: .$text.'</a>';
1.48 bowersj2 1308: }
1309:
1.763 bisitz 1310: # (Always) Add the graphic
1.179 matthew 1311: my $title = &mt('Online Help');
1.667 raeburn 1312: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1313: if ($imgid ne '') {
1314: $imgid = ' id="'.$imgid.'"';
1315: }
1.1314 raeburn 1316: $template.=' <a'.$target.' href="'.$link.'" title="'.$title.'">'
1.763 bisitz 1317: .'<img src="'.$helpicon.'" border="0"'
1318: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1319: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1320: .' /></a>';
1321: if ($text ne "") {
1322: $template.='</span>';
1323: }
1.44 bowersj2 1324: return $template;
1325:
1.106 bowersj2 1326: }
1327:
1328: # This is a quicky function for Latex cheatsheet editing, since it
1329: # appears in at least four places
1330: sub helpLatexCheatsheet {
1.1037 www 1331: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1332: my $out;
1.106 bowersj2 1333: my $addOther = '';
1.732 raeburn 1334: if ($topic) {
1.1037 www 1335: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1336: }
1337: $out = '<span>' # Start cheatsheet
1338: .$addOther
1339: .'<span>'
1.1037 www 1340: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1341: .'</span> <span>'
1.1037 www 1342: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1343: .'</span>';
1.732 raeburn 1344: unless ($not_author) {
1.1186 kruse 1345: $out .= '<span>'
1346: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1347: .'</span> <span>'
1348: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1349: .'</span>';
1.732 raeburn 1350: }
1.763 bisitz 1351: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1352: return $out;
1.172 www 1353: }
1354:
1.430 albertel 1355: sub general_help {
1356: my $helptopic='Student_Intro';
1357: if ($env{'request.role'}=~/^(ca|au)/) {
1358: $helptopic='Authoring_Intro';
1.907 raeburn 1359: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1360: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1361: } elsif ($env{'request.role'}=~/^dc/) {
1362: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1363: }
1364: return $helptopic;
1365: }
1366:
1367: sub update_help_link {
1368: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1369: my $origurl = $ENV{'REQUEST_URI'};
1370: $origurl=~s|^/~|/priv/|;
1371: my $timestamp = time;
1372: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1373: $$datum = &escape($$datum);
1374: }
1375:
1376: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1377: my $output .= <<"ENDOUTPUT";
1378: <script type="text/javascript">
1.824 bisitz 1379: // <![CDATA[
1.430 albertel 1380: banner_link = '$banner_link';
1.824 bisitz 1381: // ]]>
1.430 albertel 1382: </script>
1383: ENDOUTPUT
1384: return $output;
1385: }
1386:
1387: # now just updates the help link and generates a blue icon
1.193 raeburn 1388: sub help_open_menu {
1.430 albertel 1389: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1390: = @_;
1.949 droeschl 1391: $stayOnPage = 1;
1.430 albertel 1392: my $output;
1393: if ($component_help) {
1394: if (!$text) {
1395: $output=&help_open_topic($component_help,undef,$stayOnPage,
1396: $width,$height);
1397: } else {
1398: my $help_text;
1399: $help_text=&unescape($topic);
1400: $output='<table><tr><td>'.
1401: &help_open_topic($component_help,$help_text,$stayOnPage,
1402: $width,$height).'</td></tr></table>';
1403: }
1404: }
1405: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1406: return $output.$banner_link;
1407: }
1408:
1409: sub top_nav_help {
1410: my ($text) = @_;
1.436 albertel 1411: $text = &mt($text);
1.949 droeschl 1412: my $stay_on_page = 1;
1413:
1.1168 raeburn 1414: my ($link,$banner_link);
1415: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1416: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1417: : "javascript:helpMenu('open')";
1418: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1419: }
1.201 raeburn 1420: my $title = &mt('Get help');
1.1168 raeburn 1421: if ($link) {
1422: return <<"END";
1.436 albertel 1423: $banner_link
1.1159 raeburn 1424: <a href="$link" title="$title">$text</a>
1.436 albertel 1425: END
1.1168 raeburn 1426: } else {
1427: return ' '.$text.' ';
1428: }
1.436 albertel 1429: }
1430:
1431: sub help_menu_js {
1.1154 raeburn 1432: my ($httphost) = @_;
1.949 droeschl 1433: my $stayOnPage = 1;
1.436 albertel 1434: my $width = 620;
1435: my $height = 600;
1.430 albertel 1436: my $helptopic=&general_help();
1.1154 raeburn 1437: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1438: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1439: my $start_page =
1440: &Apache::loncommon::start_page('Help Menu', undef,
1441: {'frameset' => 1,
1442: 'js_ready' => 1,
1.1154 raeburn 1443: 'use_absolute' => $httphost,
1.331 albertel 1444: 'add_entries' => {
1.1168 raeburn 1445: 'border' => '0',
1.579 raeburn 1446: 'rows' => "110,*",},});
1.331 albertel 1447: my $end_page =
1448: &Apache::loncommon::end_page({'frameset' => 1,
1449: 'js_ready' => 1,});
1450:
1.436 albertel 1451: my $template .= <<"ENDTEMPLATE";
1452: <script type="text/javascript">
1.877 bisitz 1453: // <![CDATA[
1.253 albertel 1454: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1455: var banner_link = '';
1.243 raeburn 1456: function helpMenu(target) {
1457: var caller = this;
1458: if (target == 'open') {
1459: var newWindow = null;
1460: try {
1.262 albertel 1461: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1462: }
1463: catch(error) {
1464: writeHelp(caller);
1465: return;
1466: }
1467: if (newWindow) {
1468: caller = newWindow;
1469: }
1.193 raeburn 1470: }
1.243 raeburn 1471: writeHelp(caller);
1472: return;
1473: }
1474: function writeHelp(caller) {
1.1168 raeburn 1475: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1476: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1477: caller.document.close();
1478: caller.focus();
1.193 raeburn 1479: }
1.877 bisitz 1480: // END LON-CAPA Internal -->
1.253 albertel 1481: // ]]>
1.436 albertel 1482: </script>
1.193 raeburn 1483: ENDTEMPLATE
1484: return $template;
1485: }
1486:
1.172 www 1487: sub help_open_bug {
1488: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1489: unless ($env{'user.adv'}) { return ''; }
1.172 www 1490: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1491: $text = "" if (not defined $text);
1492: $stayOnPage=1;
1.184 albertel 1493: $width = 600 if (not defined $width);
1494: $height = 600 if (not defined $height);
1.172 www 1495:
1496: $topic=~s/\W+/\+/g;
1497: my $link='';
1498: my $template='';
1.379 albertel 1499: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1500: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1501: if (!$stayOnPage)
1502: {
1503: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1504: }
1505: else
1506: {
1507: $link = $url;
1508: }
1.1314 raeburn 1509:
1510: my $target = ' target="_top"';
1511: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1512: $target = '';
1513: }
1.172 www 1514: # Add the text
1515: if ($text ne "")
1516: {
1517: $template .=
1518: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.1314 raeburn 1519: "<td bgcolor='#FF5555'><a".$target." href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1520: }
1521:
1522: # Add the graphic
1.179 matthew 1523: my $title = &mt('Report a Bug');
1.215 albertel 1524: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1525: $template .= <<"ENDTEMPLATE";
1.1314 raeburn 1526: <a$target href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1527: ENDTEMPLATE
1528: if ($text ne '') { $template.='</td></tr></table>' };
1529: return $template;
1530:
1531: }
1532:
1533: sub help_open_faq {
1534: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1535: unless ($env{'user.adv'}) { return ''; }
1.172 www 1536: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1537: $text = "" if (not defined $text);
1538: $stayOnPage=1;
1539: $width = 350 if (not defined $width);
1540: $height = 400 if (not defined $height);
1541:
1542: $topic=~s/\W+/\+/g;
1543: my $link='';
1544: my $template='';
1545: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1546: if (!$stayOnPage)
1547: {
1548: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1549: }
1550: else
1551: {
1552: $link = $url;
1553: }
1554:
1555: # Add the text
1556: if ($text ne "")
1557: {
1558: $template .=
1.173 www 1559: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1560: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1561: }
1562:
1563: # Add the graphic
1.179 matthew 1564: my $title = &mt('View the FAQ');
1.215 albertel 1565: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1566: $template .= <<"ENDTEMPLATE";
1.436 albertel 1567: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1568: ENDTEMPLATE
1569: if ($text ne '') { $template.='</td></tr></table>' };
1570: return $template;
1571:
1.44 bowersj2 1572: }
1.37 matthew 1573:
1.180 matthew 1574: ###############################################################
1575: ###############################################################
1576:
1.45 matthew 1577: =pod
1578:
1.648 raeburn 1579: =item * &change_content_javascript():
1.256 matthew 1580:
1581: This and the next function allow you to create small sections of an
1582: otherwise static HTML page that you can update on the fly with
1583: Javascript, even in Netscape 4.
1584:
1585: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1586: must be written to the HTML page once. It will prove the Javascript
1587: function "change(name, content)". Calling the change function with the
1588: name of the section
1589: you want to update, matching the name passed to C<changable_area>, and
1590: the new content you want to put in there, will put the content into
1591: that area.
1592:
1593: B<Note>: Netscape 4 only reserves enough space for the changable area
1594: to contain room for the original contents. You need to "make space"
1595: for whatever changes you wish to make, and be B<sure> to check your
1596: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1597: it's adequate for updating a one-line status display, but little more.
1598: This script will set the space to 100% width, so you only need to
1599: worry about height in Netscape 4.
1600:
1601: Modern browsers are much less limiting, and if you can commit to the
1602: user not using Netscape 4, this feature may be used freely with
1603: pretty much any HTML.
1604:
1605: =cut
1606:
1607: sub change_content_javascript {
1608: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1609: if ($env{'browser.type'} eq 'netscape' &&
1610: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1611: return (<<NETSCAPE4);
1612: function change(name, content) {
1613: doc = document.layers[name+"___escape"].layers[0].document;
1614: doc.open();
1615: doc.write(content);
1616: doc.close();
1617: }
1618: NETSCAPE4
1619: } else {
1620: # Otherwise, we need to use semi-standards-compliant code
1621: # (technically, "innerHTML" isn't standard but the equivalent
1622: # is really scary, and every useful browser supports it
1623: return (<<DOMBASED);
1624: function change(name, content) {
1625: element = document.getElementById(name);
1626: element.innerHTML = content;
1627: }
1628: DOMBASED
1629: }
1630: }
1631:
1632: =pod
1633:
1.648 raeburn 1634: =item * &changable_area($name,$origContent):
1.256 matthew 1635:
1636: This provides a "changable area" that can be modified on the fly via
1637: the Javascript code provided in C<change_content_javascript>. $name is
1638: the name you will use to reference the area later; do not repeat the
1639: same name on a given HTML page more then once. $origContent is what
1640: the area will originally contain, which can be left blank.
1641:
1642: =cut
1643:
1644: sub changable_area {
1645: my ($name, $origContent) = @_;
1646:
1.258 albertel 1647: if ($env{'browser.type'} eq 'netscape' &&
1648: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1649: # If this is netscape 4, we need to use the Layer tag
1650: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1651: } else {
1652: return "<span id='$name'>$origContent</span>";
1653: }
1654: }
1655:
1656: =pod
1657:
1.648 raeburn 1658: =item * &viewport_geometry_js
1.590 raeburn 1659:
1660: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1661:
1662: =cut
1663:
1664:
1665: sub viewport_geometry_js {
1666: return <<"GEOMETRY";
1667: var Geometry = {};
1668: function init_geometry() {
1669: if (Geometry.init) { return };
1670: Geometry.init=1;
1671: if (window.innerHeight) {
1672: Geometry.getViewportHeight = function() { return window.innerHeight; };
1673: Geometry.getViewportWidth = function() { return window.innerWidth; };
1674: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1675: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1676: }
1677: else if (document.documentElement && document.documentElement.clientHeight) {
1678: Geometry.getViewportHeight =
1679: function() { return document.documentElement.clientHeight; };
1680: Geometry.getViewportWidth =
1681: function() { return document.documentElement.clientWidth; };
1682:
1683: Geometry.getHorizontalScroll =
1684: function() { return document.documentElement.scrollLeft; };
1685: Geometry.getVerticalScroll =
1686: function() { return document.documentElement.scrollTop; };
1687: }
1688: else if (document.body.clientHeight) {
1689: Geometry.getViewportHeight =
1690: function() { return document.body.clientHeight; };
1691: Geometry.getViewportWidth =
1692: function() { return document.body.clientWidth; };
1693: Geometry.getHorizontalScroll =
1694: function() { return document.body.scrollLeft; };
1695: Geometry.getVerticalScroll =
1696: function() { return document.body.scrollTop; };
1697: }
1698: }
1699:
1700: GEOMETRY
1701: }
1702:
1703: =pod
1704:
1.648 raeburn 1705: =item * &viewport_size_js()
1.590 raeburn 1706:
1707: 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.
1708:
1709: =cut
1710:
1711: sub viewport_size_js {
1712: my $geometry = &viewport_geometry_js();
1713: return <<"DIMS";
1714:
1715: $geometry
1716:
1717: function getViewportDims(width,height) {
1718: init_geometry();
1719: width.value = Geometry.getViewportWidth();
1720: height.value = Geometry.getViewportHeight();
1721: return;
1722: }
1723:
1724: DIMS
1725: }
1726:
1727: =pod
1728:
1.648 raeburn 1729: =item * &resize_textarea_js()
1.565 albertel 1730:
1731: emits the needed javascript to resize a textarea to be as big as possible
1732:
1733: creates a function resize_textrea that takes two IDs first should be
1734: the id of the element to resize, second should be the id of a div that
1735: surrounds everything that comes after the textarea, this routine needs
1736: to be attached to the <body> for the onload and onresize events.
1737:
1.648 raeburn 1738: =back
1.565 albertel 1739:
1740: =cut
1741:
1742: sub resize_textarea_js {
1.590 raeburn 1743: my $geometry = &viewport_geometry_js();
1.565 albertel 1744: return <<"RESIZE";
1745: <script type="text/javascript">
1.824 bisitz 1746: // <![CDATA[
1.590 raeburn 1747: $geometry
1.565 albertel 1748:
1.588 albertel 1749: function getX(element) {
1750: var x = 0;
1751: while (element) {
1752: x += element.offsetLeft;
1753: element = element.offsetParent;
1754: }
1755: return x;
1756: }
1757: function getY(element) {
1758: var y = 0;
1759: while (element) {
1760: y += element.offsetTop;
1761: element = element.offsetParent;
1762: }
1763: return y;
1764: }
1765:
1766:
1.565 albertel 1767: function resize_textarea(textarea_id,bottom_id) {
1768: init_geometry();
1769: var textarea = document.getElementById(textarea_id);
1770: //alert(textarea);
1771:
1.588 albertel 1772: var textarea_top = getY(textarea);
1.565 albertel 1773: var textarea_height = textarea.offsetHeight;
1774: var bottom = document.getElementById(bottom_id);
1.588 albertel 1775: var bottom_top = getY(bottom);
1.565 albertel 1776: var bottom_height = bottom.offsetHeight;
1777: var window_height = Geometry.getViewportHeight();
1.588 albertel 1778: var fudge = 23;
1.565 albertel 1779: var new_height = window_height-fudge-textarea_top-bottom_height;
1780: if (new_height < 300) {
1781: new_height = 300;
1782: }
1783: textarea.style.height=new_height+'px';
1784: }
1.824 bisitz 1785: // ]]>
1.565 albertel 1786: </script>
1787: RESIZE
1788:
1789: }
1790:
1.1205 golterma 1791: sub colorfuleditor_js {
1.1248 raeburn 1792: my $browse_or_search;
1793: my $respath;
1794: my ($cnum,$cdom) = &crsauthor_url();
1795: if ($cnum) {
1796: $respath = "/res/$cdom/$cnum/";
1797: my %js_lt = &Apache::lonlocal::texthash(
1798: sunm => 'Sub-directory name',
1799: save => 'Save page to make this permanent',
1800: );
1801: &js_escape(\%js_lt);
1802: $browse_or_search = <<"END";
1803:
1804: function toggleChooser(form,element,titleid,only,search) {
1805: var disp = 'none';
1806: if (document.getElementById('chooser_'+element)) {
1807: var curr = document.getElementById('chooser_'+element).style.display;
1808: if (curr == 'none') {
1809: disp='inline';
1810: if (form.elements['chooser_'+element].length) {
1811: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1812: form.elements['chooser_'+element][i].checked = false;
1813: }
1814: }
1815: toggleResImport(form,element);
1816: }
1817: document.getElementById('chooser_'+element).style.display = disp;
1818: }
1819: }
1820:
1821: function toggleCrsFile(form,element,numdirs) {
1822: if (document.getElementById('chooser_'+element+'_crsres')) {
1823: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1824: if (curr == 'none') {
1825: if (numdirs) {
1826: form.elements['coursepath_'+element].selectedIndex = 0;
1827: if (numdirs > 1) {
1828: window['select1'+element+'_changed']();
1829: }
1830: }
1831: }
1832: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1833:
1834: }
1835: if (document.getElementById('chooser_'+element+'_upload')) {
1836: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1837: if (document.getElementById('uploadcrsres_'+element)) {
1838: document.getElementById('uploadcrsres_'+element).value = '';
1839: }
1840: }
1841: return;
1842: }
1843:
1844: function toggleCrsUpload(form,element,numcrsdirs) {
1845: if (document.getElementById('chooser_'+element+'_crsres')) {
1846: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1847: }
1848: if (document.getElementById('chooser_'+element+'_upload')) {
1849: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1850: if (curr == 'none') {
1851: if (numcrsdirs) {
1852: form.elements['crsauthorpath_'+element].selectedIndex = 0;
1853: form.elements['newsubdir_'+element][0].checked = true;
1854: toggleNewsubdir(form,element);
1855: }
1856: }
1857: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1858: }
1859: return;
1860: }
1861:
1862: function toggleResImport(form,element) {
1863: var choices = new Array('crsres','upload');
1864: for (var i=0; i<choices.length; i++) {
1865: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1866: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1867: }
1868: }
1869: }
1870:
1871: function toggleNewsubdir(form,element) {
1872: var newsub = form.elements['newsubdir_'+element];
1873: if (newsub) {
1874: if (newsub.length) {
1875: for (var j=0; j<newsub.length; j++) {
1876: if (newsub[j].checked) {
1877: if (document.getElementById('newsubdirname_'+element)) {
1878: if (newsub[j].value == '1') {
1879: document.getElementById('newsubdirname_'+element).type = "text";
1880: if (document.getElementById('newsubdir_'+element)) {
1881: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1882: }
1883: } else {
1884: document.getElementById('newsubdirname_'+element).type = "hidden";
1885: document.getElementById('newsubdirname_'+element).value = "";
1886: document.getElementById('newsubdir_'+element).innerHTML = "";
1887: }
1888: }
1889: break;
1890: }
1891: }
1892: }
1893: }
1894: }
1895:
1896: function updateCrsFile(form,element) {
1897: var directory = form.elements['coursepath_'+element];
1898: var filename = form.elements['coursefile_'+element];
1899: var path = directory.options[directory.selectedIndex].value;
1900: var file = filename.options[filename.selectedIndex].value;
1901: form.elements[element].value = '$respath';
1902: if (path == '/') {
1903: form.elements[element].value += file;
1904: } else {
1905: form.elements[element].value += path+'/'+file;
1906: }
1907: unClean();
1908: if (document.getElementById('previewimg_'+element)) {
1909: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1910: var newsrc = document.getElementById('previewimg_'+element).src;
1911: }
1912: if (document.getElementById('showimg_'+element)) {
1913: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1914: }
1915: toggleChooser(form,element);
1916: return;
1917: }
1918:
1919: function uploadDone(suffix,name) {
1920: if (name) {
1921: document.forms["lonhomework"].elements[suffix].value = name;
1922: unClean();
1923: toggleChooser(document.forms["lonhomework"],suffix);
1924: }
1925: }
1926:
1927: \$(document).ready(function(){
1928:
1929: \$(document).delegate('form :submit', 'click', function( event ) {
1930: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
1931: var buttonId = this.id;
1932: var suffix = buttonId.toString();
1933: suffix = suffix.replace(/^crsupload_/,'');
1934: event.preventDefault();
1935: document.lonhomework.target = 'crsupload_target_'+suffix;
1936: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
1937: \$(this.form).submit();
1938: document.lonhomework.target = '';
1939: if (document.getElementById('crsuploadto_'+suffix)) {
1940: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
1941: }
1942: return false;
1943: }
1944: });
1945: });
1946: END
1947: }
1.1205 golterma 1948: return <<"COLORFULEDIT"
1949: <script type="text/javascript">
1950: // <![CDATA[>
1951: function fold_box(curDepth, lastresource){
1952:
1953: // we need a list because there can be several blocks you need to fold in one tag
1954: var block = document.getElementsByName('foldblock_'+curDepth);
1955: // but there is only one folding button per tag
1956: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1957:
1958: if(block.item(0).style.display == 'none'){
1959:
1960: foldbutton.value = '@{[&mt("Hide")]}';
1961: for (i = 0; i < block.length; i++){
1962: block.item(i).style.display = '';
1963: }
1964: }else{
1965:
1966: foldbutton.value = '@{[&mt("Show")]}';
1967: for (i = 0; i < block.length; i++){
1968: // block.item(i).style.visibility = 'collapse';
1969: block.item(i).style.display = 'none';
1970: }
1971: };
1972: saveState(lastresource);
1973: }
1974:
1975: function saveState (lastresource) {
1976:
1977: var tag_list = getTagList();
1978: if(tag_list != null){
1979: var timestamp = new Date().getTime();
1980: var key = lastresource;
1981:
1982: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1983: // starting with timestamp
1984: var value = timestamp+';';
1985:
1986: // building the list of key-value pairs
1987: for(var i = 0; i < tag_list.length; i++){
1988: value += tag_list[i]+',';
1989: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1990: }
1991:
1992: // only iterate whole storage if nothing to override
1993: if(localStorage.getItem(key) == null){
1994:
1995: // prevent storage from growing large
1996: if(localStorage.length > 50){
1997: var regex_getTimestamp = /^(?:\d)+;/;
1998: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1999: var oldest_key;
2000:
2001: for(var i = 1; i < localStorage.length; i++){
2002: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
2003: oldest_key = localStorage.key(i);
2004: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
2005: }
2006: }
2007: localStorage.removeItem(oldest_key);
2008: }
2009: }
2010: localStorage.setItem(key,value);
2011: }
2012: }
2013:
2014: // restore folding status of blocks (on page load)
2015: function restoreState (lastresource) {
2016: if(localStorage.getItem(lastresource) != null){
2017: var key = lastresource;
2018: var value = localStorage.getItem(key);
2019: var regex_delTimestamp = /^\d+;/;
2020:
2021: value.replace(regex_delTimestamp, '');
2022:
2023: var valueArr = value.split(';');
2024: var pairs;
2025: var elements;
2026: for (var i = 0; i < valueArr.length; i++){
2027: pairs = valueArr[i].split(',');
2028: elements = document.getElementsByName(pairs[0]);
2029:
2030: for (var j = 0; j < elements.length; j++){
2031: elements[j].style.display = pairs[1];
2032: if (pairs[1] == "none"){
2033: var regex_id = /([_\\d]+)\$/;
2034: regex_id.exec(pairs[0]);
2035: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2036: }
2037: }
2038: }
2039: }
2040: }
2041:
2042: function getTagList () {
2043:
2044: var stringToSearch = document.lonhomework.innerHTML;
2045:
2046: var ret = new Array();
2047: var regex_findBlock = /(foldblock_.*?)"/g;
2048: var tag_list = stringToSearch.match(regex_findBlock);
2049:
2050: if(tag_list != null){
2051: for(var i = 0; i < tag_list.length; i++){
2052: ret.push(tag_list[i].replace(/"/, ''));
2053: }
2054: }
2055: return ret;
2056: }
2057:
2058: function saveScrollPosition (resource) {
2059: var tag_list = getTagList();
2060:
2061: // we dont always want to jump to the first block
2062: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2063: if(\$(window).scrollTop() > 170){
2064: if(tag_list != null){
2065: var result;
2066: for(var i = 0; i < tag_list.length; i++){
2067: if(isElementInViewport(tag_list[i])){
2068: result += tag_list[i]+';';
2069: }
2070: }
2071: sessionStorage.setItem('anchor_'+resource, result);
2072: }
2073: } else {
2074: // we dont need to save zero, just delete the item to leave everything tidy
2075: sessionStorage.removeItem('anchor_'+resource);
2076: }
2077: }
2078:
2079: function restoreScrollPosition(resource){
2080:
2081: var elem = sessionStorage.getItem('anchor_'+resource);
2082: if(elem != null){
2083: var tag_list = elem.split(';');
2084: var elem_list;
2085:
2086: for(var i = 0; i < tag_list.length; i++){
2087: elem_list = document.getElementsByName(tag_list[i]);
2088:
2089: if(elem_list.length > 0){
2090: elem = elem_list[0];
2091: break;
2092: }
2093: }
2094: elem.scrollIntoView();
2095: }
2096: }
2097:
2098: function isElementInViewport(el) {
2099:
2100: // change to last element instead of first
2101: var elem = document.getElementsByName(el);
2102: var rect = elem[0].getBoundingClientRect();
2103:
2104: return (
2105: rect.top >= 0 &&
2106: rect.left >= 0 &&
2107: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2108: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2109: );
2110: }
2111:
2112: function autosize(depth){
2113: var cmInst = window['cm'+depth];
2114: var fitsizeButton = document.getElementById('fitsize'+depth);
2115:
2116: // is fixed size, switching to dynamic
2117: if (sessionStorage.getItem("autosized_"+depth) == null) {
2118: cmInst.setSize("","auto");
2119: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2120: sessionStorage.setItem("autosized_"+depth, "yes");
2121:
2122: // is dynamic size, switching to fixed
2123: } else {
2124: cmInst.setSize("","300px");
2125: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2126: sessionStorage.removeItem("autosized_"+depth);
2127: }
2128: }
2129:
1.1248 raeburn 2130: $browse_or_search
1.1205 golterma 2131:
2132: // ]]>
2133: </script>
2134: COLORFULEDIT
2135: }
2136:
2137: sub xmleditor_js {
2138: return <<XMLEDIT
2139: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2140: <script type="text/javascript">
2141: // <![CDATA[>
2142:
2143: function saveScrollPosition (resource) {
2144:
2145: var scrollPos = \$(window).scrollTop();
2146: sessionStorage.setItem(resource,scrollPos);
2147: }
2148:
2149: function restoreScrollPosition(resource){
2150:
2151: var scrollPos = sessionStorage.getItem(resource);
2152: \$(window).scrollTop(scrollPos);
2153: }
2154:
2155: // unless internet explorer
2156: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2157:
2158: \$(document).ready(function() {
2159: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2160: });
2161: }
2162:
2163: // inserts text at cursor position into codemirror (xml editor only)
2164: function insertText(text){
2165: cm.focus();
2166: var curPos = cm.getCursor();
2167: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2168: }
2169: // ]]>
2170: </script>
2171: XMLEDIT
2172: }
2173:
2174: sub insert_folding_button {
2175: my $curDepth = $Apache::lonxml::curdepth;
2176: my $lastresource = $env{'request.ambiguous'};
2177:
2178: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2179: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2180: }
2181:
1.1248 raeburn 2182: sub crsauthor_url {
2183: my ($url) = @_;
2184: if ($url eq '') {
2185: $url = $ENV{'REQUEST_URI'};
2186: }
2187: my ($cnum,$cdom);
2188: if ($env{'request.course.id'}) {
2189: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2190: if ($audom ne '' && $auname ne '') {
2191: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2192: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2193: $cnum = $auname;
2194: $cdom = $audom;
2195: }
2196: }
2197: }
2198: return ($cnum,$cdom);
2199: }
2200:
2201: sub import_crsauthor_form {
1.1265 raeburn 2202: my ($form,$firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2203: return (0) unless ($env{'request.course.id'});
2204: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2205: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2206: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2207: return (0) unless (($cnum ne '') && ($cdom ne ''));
2208: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
2209: my @ids=&Apache::lonnet::current_machine_ids();
2210: my ($output,$is_home,$relpath,%subdirs,%files,%selimport_menus);
2211:
2212: if (grep(/^\Q$crshome\E$/,@ids)) {
2213: $is_home = 1;
2214: }
2215: $relpath = "/priv/$cdom/$cnum";
2216: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$relpath,'',\%subdirs,\%files);
2217: my %lt = &Apache::lonlocal::texthash (
2218: fnam => 'Filename',
2219: dire => 'Directory',
2220: );
2221: my $numdirs = scalar(keys(%files));
2222: my (%possexts,$singledir,@singledirfiles);
2223: if ($only) {
2224: map { $possexts{$_} = 1; } split(/\s*,\s*/,$only);
2225: }
2226: my (%nonemptydirs,$possdirs);
2227: if ($numdirs > 1) {
2228: my @order;
2229: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
2230: if (ref($files{$key}) eq 'HASH') {
2231: my $shown = $key;
2232: if ($key eq '') {
2233: $shown = '/';
2234: }
2235: my @ordered = ();
2236: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$key}}))) {
1.1315 raeburn 2237: next if ($file =~ /\.rights$/);
1.1248 raeburn 2238: if ($only) {
2239: my ($ext) = ($file =~ /\.([^.]+)$/);
2240: unless ($possexts{lc($ext)}) {
2241: next;
2242: }
2243: }
2244: $selimport_menus{$key}->{'select2'}->{$file} = $file;
2245: push(@ordered,$file);
2246: }
2247: if (@ordered) {
2248: push(@order,$key);
2249: $nonemptydirs{$key} = 1;
2250: $selimport_menus{$key}->{'text'} = $shown;
2251: $selimport_menus{$key}->{'default'} = '';
2252: $selimport_menus{$key}->{'select2'}->{''} = '';
2253: $selimport_menus{$key}->{'order'} = \@ordered;
2254: }
2255: }
2256: }
2257: $possdirs = scalar(keys(%nonemptydirs));
2258: if ($possdirs > 1) {
2259: my @order = sort { lc($a) cmp lc($b) } (keys(%nonemptydirs));
2260: $output = $lt{'dire'}.
2261: &linked_select_forms($form,'<br />'.
2262: $lt{'fnam'},'',
2263: $firstselectname,$secondselectname,
2264: \%selimport_menus,\@order,
2265: $onchangefirst,'',$suffix).'<br />';
2266: } elsif ($possdirs == 1) {
2267: $singledir = (keys(%nonemptydirs))[0];
2268: if (ref($selimport_menus{$singledir}->{'order'}) eq 'ARRAY') {
2269: @singledirfiles = @{$selimport_menus{$singledir}->{'order'}};
2270: }
2271: delete($selimport_menus{$singledir});
2272: }
2273: } elsif ($numdirs == 1) {
2274: $singledir = (keys(%files))[0];
2275: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$singledir}}))) {
2276: if ($only) {
2277: my ($ext) = ($file =~ /\.([^.]+)$/);
2278: unless ($possexts{lc($ext)}) {
2279: next;
2280: }
1.1315 raeburn 2281: } else {
2282: next if ($file =~ /\.rights$/);
1.1248 raeburn 2283: }
2284: push(@singledirfiles,$file);
2285: }
2286: if (@singledirfiles) {
1.1315 raeburn 2287: $possdirs = 1;
1.1248 raeburn 2288: }
2289: }
2290: if (($possdirs == 1) && (@singledirfiles)) {
2291: my $showdir = $singledir;
2292: if ($singledir eq '') {
2293: $showdir = '/';
2294: }
2295: $output = $lt{'dire'}.
2296: '<select name="'.$firstselectname.'">'.
2297: '<option value="'.$singledir.'">'.$showdir.'</option>'."\n".
2298: '</select><br />'.
2299: $lt{'fnam'}.'<select name="'.$secondselectname.'">'."\n".
2300: '<option value="" selected="selected">'.$lt{'se'}.'</option>'."\n";
2301: foreach my $file (@singledirfiles) {
2302: $output .= '<option value="'.$file.'">'.$file.'</option>'."\n";
2303: }
2304: $output .= '</select><br />'."\n";
2305: }
2306: return ($possdirs,$output);
2307: }
2308:
1.565 albertel 2309: =pod
2310:
1.256 matthew 2311: =head1 Excel and CSV file utility routines
2312:
2313: =cut
2314:
2315: ###############################################################
2316: ###############################################################
2317:
2318: =pod
2319:
1.1162 raeburn 2320: =over 4
2321:
1.648 raeburn 2322: =item * &csv_translate($text)
1.37 matthew 2323:
1.185 www 2324: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2325: format.
2326:
2327: =cut
2328:
1.180 matthew 2329: ###############################################################
2330: ###############################################################
1.37 matthew 2331: sub csv_translate {
2332: my $text = shift;
2333: $text =~ s/\"/\"\"/g;
1.209 albertel 2334: $text =~ s/\n/ /g;
1.37 matthew 2335: return $text;
2336: }
1.180 matthew 2337:
2338: ###############################################################
2339: ###############################################################
2340:
2341: =pod
2342:
1.648 raeburn 2343: =item * &define_excel_formats()
1.180 matthew 2344:
2345: Define some commonly used Excel cell formats.
2346:
2347: Currently supported formats:
2348:
2349: =over 4
2350:
2351: =item header
2352:
2353: =item bold
2354:
2355: =item h1
2356:
2357: =item h2
2358:
2359: =item h3
2360:
1.256 matthew 2361: =item h4
2362:
2363: =item i
2364:
1.180 matthew 2365: =item date
2366:
2367: =back
2368:
2369: Inputs: $workbook
2370:
2371: Returns: $format, a hash reference.
2372:
1.1057 foxr 2373:
1.180 matthew 2374: =cut
2375:
2376: ###############################################################
2377: ###############################################################
2378: sub define_excel_formats {
2379: my ($workbook) = @_;
2380: my $format;
2381: $format->{'header'} = $workbook->add_format(bold => 1,
2382: bottom => 1,
2383: align => 'center');
2384: $format->{'bold'} = $workbook->add_format(bold=>1);
2385: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2386: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2387: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2388: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2389: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2390: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2391: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2392: return $format;
2393: }
2394:
2395: ###############################################################
2396: ###############################################################
1.113 bowersj2 2397:
2398: =pod
2399:
1.648 raeburn 2400: =item * &create_workbook()
1.255 matthew 2401:
2402: Create an Excel worksheet. If it fails, output message on the
2403: request object and return undefs.
2404:
2405: Inputs: Apache request object
2406:
2407: Returns (undef) on failure,
2408: Excel worksheet object, scalar with filename, and formats
2409: from &Apache::loncommon::define_excel_formats on success
2410:
2411: =cut
2412:
2413: ###############################################################
2414: ###############################################################
2415: sub create_workbook {
2416: my ($r) = @_;
2417: #
2418: # Create the excel spreadsheet
2419: my $filename = '/prtspool/'.
1.258 albertel 2420: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2421: time.'_'.rand(1000000000).'.xls';
2422: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2423: if (! defined($workbook)) {
2424: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2425: $r->print(
2426: '<p class="LC_error">'
2427: .&mt('Problems occurred in creating the new Excel file.')
2428: .' '.&mt('This error has been logged.')
2429: .' '.&mt('Please alert your LON-CAPA administrator.')
2430: .'</p>'
2431: );
1.255 matthew 2432: return (undef);
2433: }
2434: #
1.1014 foxr 2435: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2436: #
2437: my $format = &Apache::loncommon::define_excel_formats($workbook);
2438: return ($workbook,$filename,$format);
2439: }
2440:
2441: ###############################################################
2442: ###############################################################
2443:
2444: =pod
2445:
1.648 raeburn 2446: =item * &create_text_file()
1.113 bowersj2 2447:
1.542 raeburn 2448: Create a file to write to and eventually make available to the user.
1.256 matthew 2449: If file creation fails, outputs an error message on the request object and
2450: return undefs.
1.113 bowersj2 2451:
1.256 matthew 2452: Inputs: Apache request object, and file suffix
1.113 bowersj2 2453:
1.256 matthew 2454: Returns (undef) on failure,
2455: Filehandle and filename on success.
1.113 bowersj2 2456:
2457: =cut
2458:
1.256 matthew 2459: ###############################################################
2460: ###############################################################
2461: sub create_text_file {
2462: my ($r,$suffix) = @_;
2463: if (! defined($suffix)) { $suffix = 'txt'; };
2464: my $fh;
2465: my $filename = '/prtspool/'.
1.258 albertel 2466: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2467: time.'_'.rand(1000000000).'.'.$suffix;
2468: $fh = Apache::File->new('>/home/httpd'.$filename);
2469: if (! defined($fh)) {
2470: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2471: $r->print(
2472: '<p class="LC_error">'
2473: .&mt('Problems occurred in creating the output file.')
2474: .' '.&mt('This error has been logged.')
2475: .' '.&mt('Please alert your LON-CAPA administrator.')
2476: .'</p>'
2477: );
1.113 bowersj2 2478: }
1.256 matthew 2479: return ($fh,$filename)
1.113 bowersj2 2480: }
2481:
2482:
1.256 matthew 2483: =pod
1.113 bowersj2 2484:
2485: =back
2486:
2487: =cut
1.37 matthew 2488:
2489: ###############################################################
1.33 matthew 2490: ## Home server <option> list generating code ##
2491: ###############################################################
1.35 matthew 2492:
1.169 www 2493: # ------------------------------------------
2494:
2495: sub domain_select {
1.1289 raeburn 2496: my ($name,$value,$multiple,$incdoms,$excdoms)=@_;
2497: my @possdoms;
2498: if (ref($incdoms) eq 'ARRAY') {
2499: @possdoms = @{$incdoms};
2500: } else {
2501: @possdoms = &Apache::lonnet::all_domains();
2502: }
2503:
1.169 www 2504: my %domains=map {
1.514 albertel 2505: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.1289 raeburn 2506: } @possdoms;
2507:
2508: if ((ref($excdoms) eq 'ARRAY') && (@{$excdoms} > 0)) {
2509: foreach my $dom (@{$excdoms}) {
2510: delete($domains{$dom});
2511: }
2512: }
2513:
1.169 www 2514: if ($multiple) {
2515: $domains{''}=&mt('Any domain');
1.550 albertel 2516: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2517: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2518: } else {
1.550 albertel 2519: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2520: return &select_form($name,$value,\%domains);
1.169 www 2521: }
2522: }
2523:
1.282 albertel 2524: #-------------------------------------------
2525:
2526: =pod
2527:
1.519 raeburn 2528: =head1 Routines for form select boxes
2529:
2530: =over 4
2531:
1.648 raeburn 2532: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2533:
2534: Returns a string containing a <select> element int multiple mode
2535:
2536:
2537: Args:
2538: $name - name of the <select> element
1.506 raeburn 2539: $value - scalar or array ref of values that should already be selected
1.282 albertel 2540: $size - number of rows long the select element is
1.283 albertel 2541: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2542: (shown text should already have been &mt())
1.506 raeburn 2543: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2544:
1.282 albertel 2545: =cut
2546:
2547: #-------------------------------------------
1.169 www 2548: sub multiple_select_form {
1.284 albertel 2549: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2550: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2551: my $output='';
1.191 matthew 2552: if (! defined($size)) {
2553: $size = 4;
1.283 albertel 2554: if (scalar(keys(%$hash))<4) {
2555: $size = scalar(keys(%$hash));
1.191 matthew 2556: }
2557: }
1.734 bisitz 2558: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2559: my @order;
1.506 raeburn 2560: if (ref($order) eq 'ARRAY') {
2561: @order = @{$order};
2562: } else {
2563: @order = sort(keys(%$hash));
1.501 banghart 2564: }
2565: if (exists($$hash{'select_form_order'})) {
2566: @order = @{$$hash{'select_form_order'}};
2567: }
2568:
1.284 albertel 2569: foreach my $key (@order) {
1.356 albertel 2570: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2571: $output.='selected="selected" ' if ($selected{$key});
2572: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2573: }
2574: $output.="</select>\n";
2575: return $output;
2576: }
2577:
1.88 www 2578: #-------------------------------------------
2579:
2580: =pod
2581:
1.1254 raeburn 2582: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2583:
2584: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2585: allow a user to select options from a ref to a hash containing:
2586: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2587: a javascript onchange item, e.g., onchange="this.form.submit();".
2588: An optional arg -- $readonly -- if true will cause the select form
2589: to be disabled, e.g., for the case where an instructor has a section-
2590: specific role, and is viewing/modifying parameters.
1.970 raeburn 2591:
1.88 www 2592: See lonrights.pm for an example invocation and use.
2593:
2594: =cut
2595:
2596: #-------------------------------------------
2597: sub select_form {
1.1228 raeburn 2598: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2599: return unless (ref($hashref) eq 'HASH');
2600: if ($onchange) {
2601: $onchange = ' onchange="'.$onchange.'"';
2602: }
1.1228 raeburn 2603: my $disabled;
2604: if ($readonly) {
2605: $disabled = ' disabled="disabled"';
2606: }
2607: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2608: my @keys;
1.970 raeburn 2609: if (exists($hashref->{'select_form_order'})) {
2610: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2611: } else {
1.970 raeburn 2612: @keys=sort(keys(%{$hashref}));
1.128 albertel 2613: }
1.356 albertel 2614: foreach my $key (@keys) {
2615: $selectform.=
2616: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2617: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2618: ">".$hashref->{$key}."</option>\n";
1.88 www 2619: }
2620: $selectform.="</select>";
2621: return $selectform;
2622: }
2623:
1.475 www 2624: # For display filters
2625:
2626: sub display_filter {
1.1074 raeburn 2627: my ($context) = @_;
1.475 www 2628: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2629: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2630: my $phraseinput = 'hidden';
2631: my $includeinput = 'hidden';
2632: my ($checked,$includetypestext);
2633: if ($env{'form.displayfilter'} eq 'containing') {
2634: $phraseinput = 'text';
2635: if ($context eq 'parmslog') {
2636: $includeinput = 'checkbox';
2637: if ($env{'form.includetypes'}) {
2638: $checked = ' checked="checked"';
2639: }
2640: $includetypestext = &mt('Include parameter types');
2641: }
2642: } else {
2643: $includetypestext = ' ';
2644: }
2645: my ($additional,$secondid,$thirdid);
2646: if ($context eq 'parmslog') {
2647: $additional =
2648: '<label><input type="'.$includeinput.'" name="includetypes"'.
2649: $checked.' name="includetypes" value="1" id="includetypes" />'.
2650: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2651: '</label>';
2652: $secondid = 'includetypes';
2653: $thirdid = 'includetypestext';
2654: }
2655: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2656: '$secondid','$thirdid')";
2657: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2658: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2659: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2660: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2661: &mt('Filter: [_1]',
1.477 www 2662: &select_form($env{'form.displayfilter'},
2663: 'displayfilter',
1.970 raeburn 2664: {'currentfolder' => 'Current folder/page',
1.477 www 2665: 'containing' => 'Containing phrase',
1.1074 raeburn 2666: 'none' => 'None'},$onchange)).' '.
2667: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2668: &HTML::Entities::encode($env{'form.containingphrase'}).
2669: '" />'.$additional;
2670: }
2671:
2672: sub display_filter_js {
2673: my $includetext = &mt('Include parameter types');
2674: return <<"ENDJS";
2675:
2676: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2677: var firstType = 'hidden';
2678: if (setter.options[setter.selectedIndex].value == 'containing') {
2679: firstType = 'text';
2680: }
2681: firstObject = document.getElementById(firstid);
2682: if (typeof(firstObject) == 'object') {
2683: if (firstObject.type != firstType) {
2684: changeInputType(firstObject,firstType);
2685: }
2686: }
2687: if (context == 'parmslog') {
2688: var secondType = 'hidden';
2689: if (firstType == 'text') {
2690: secondType = 'checkbox';
2691: }
2692: secondObject = document.getElementById(secondid);
2693: if (typeof(secondObject) == 'object') {
2694: if (secondObject.type != secondType) {
2695: changeInputType(secondObject,secondType);
2696: }
2697: }
2698: var textItem = document.getElementById(thirdid);
2699: var currtext = textItem.innerHTML;
2700: var newtext;
2701: if (firstType == 'text') {
2702: newtext = '$includetext';
2703: } else {
2704: newtext = ' ';
2705: }
2706: if (currtext != newtext) {
2707: textItem.innerHTML = newtext;
2708: }
2709: }
2710: return;
2711: }
2712:
2713: function changeInputType(oldObject,newType) {
2714: var newObject = document.createElement('input');
2715: newObject.type = newType;
2716: if (oldObject.size) {
2717: newObject.size = oldObject.size;
2718: }
2719: if (oldObject.value) {
2720: newObject.value = oldObject.value;
2721: }
2722: if (oldObject.name) {
2723: newObject.name = oldObject.name;
2724: }
2725: if (oldObject.id) {
2726: newObject.id = oldObject.id;
2727: }
2728: oldObject.parentNode.replaceChild(newObject,oldObject);
2729: return;
2730: }
2731:
2732: ENDJS
1.475 www 2733: }
2734:
1.167 www 2735: sub gradeleveldescription {
2736: my $gradelevel=shift;
2737: my %gradelevels=(0 => 'Not specified',
2738: 1 => 'Grade 1',
2739: 2 => 'Grade 2',
2740: 3 => 'Grade 3',
2741: 4 => 'Grade 4',
2742: 5 => 'Grade 5',
2743: 6 => 'Grade 6',
2744: 7 => 'Grade 7',
2745: 8 => 'Grade 8',
2746: 9 => 'Grade 9',
2747: 10 => 'Grade 10',
2748: 11 => 'Grade 11',
2749: 12 => 'Grade 12',
2750: 13 => 'Grade 13',
2751: 14 => '100 Level',
2752: 15 => '200 Level',
2753: 16 => '300 Level',
2754: 17 => '400 Level',
2755: 18 => 'Graduate Level');
2756: return &mt($gradelevels{$gradelevel});
2757: }
2758:
1.163 www 2759: sub select_level_form {
2760: my ($deflevel,$name)=@_;
2761: unless ($deflevel) { $deflevel=0; }
1.167 www 2762: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2763: for (my $i=0; $i<=18; $i++) {
2764: $selectform.="<option value=\"$i\" ".
1.253 albertel 2765: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2766: ">".&gradeleveldescription($i)."</option>\n";
2767: }
2768: $selectform.="</select>";
2769: return $selectform;
1.163 www 2770: }
1.167 www 2771:
1.35 matthew 2772: #-------------------------------------------
2773:
1.45 matthew 2774: =pod
2775:
1.1256 raeburn 2776: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2777:
2778: Returns a string containing a <select name='$name' size='1'> form to
2779: allow a user to select the domain to preform an operation in.
2780: See loncreateuser.pm for an example invocation and use.
2781:
1.90 www 2782: If the $includeempty flag is set, it also includes an empty choice ("no domain
2783: selected");
2784:
1.743 raeburn 2785: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2786:
1.910 raeburn 2787: 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.
2788:
1.1121 raeburn 2789: The optional $incdoms is a reference to an array of domains which will be the only available options.
2790:
2791: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2792:
1.1256 raeburn 2793: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
2794:
1.35 matthew 2795: =cut
2796:
2797: #-------------------------------------------
1.34 matthew 2798: sub select_dom_form {
1.1256 raeburn 2799: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2800: if ($onchange) {
1.874 raeburn 2801: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2802: }
1.1256 raeburn 2803: if ($disabled) {
2804: $disabled = ' disabled="disabled"';
2805: }
1.1121 raeburn 2806: my (@domains,%exclude);
1.910 raeburn 2807: if (ref($incdoms) eq 'ARRAY') {
2808: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2809: } else {
2810: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2811: }
1.90 www 2812: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2813: if (ref($excdoms) eq 'ARRAY') {
2814: map { $exclude{$_} = 1; } @{$excdoms};
2815: }
1.1256 raeburn 2816: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2817: foreach my $dom (@domains) {
1.1121 raeburn 2818: next if ($exclude{$dom});
1.356 albertel 2819: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2820: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2821: if ($showdomdesc) {
2822: if ($dom ne '') {
2823: my $domdesc = &Apache::lonnet::domain($dom,'description');
2824: if ($domdesc ne '') {
2825: $selectdomain .= ' ('.$domdesc.')';
2826: }
2827: }
2828: }
2829: $selectdomain .= "</option>\n";
1.34 matthew 2830: }
2831: $selectdomain.="</select>";
2832: return $selectdomain;
2833: }
2834:
1.35 matthew 2835: #-------------------------------------------
2836:
1.45 matthew 2837: =pod
2838:
1.648 raeburn 2839: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2840:
1.586 raeburn 2841: input: 4 arguments (two required, two optional) -
2842: $domain - domain of new user
2843: $name - name of form element
2844: $default - Value of 'default' causes a default item to be first
2845: option, and selected by default.
2846: $hide - Value of 'hide' causes hiding of the name of the server,
2847: if 1 server found, or default, if 0 found.
1.594 raeburn 2848: output: returns 2 items:
1.586 raeburn 2849: (a) form element which contains either:
2850: (i) <select name="$name">
2851: <option value="$hostid1">$hostid $servers{$hostid}</option>
2852: <option value="$hostid2">$hostid $servers{$hostid}</option>
2853: </select>
2854: form item if there are multiple library servers in $domain, or
2855: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2856: if there is only one library server in $domain.
2857:
2858: (b) number of library servers found.
2859:
2860: See loncreateuser.pm for example of use.
1.35 matthew 2861:
2862: =cut
2863:
2864: #-------------------------------------------
1.586 raeburn 2865: sub home_server_form_item {
2866: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2867: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2868: my $result;
2869: my $numlib = keys(%servers);
2870: if ($numlib > 1) {
2871: $result .= '<select name="'.$name.'" />'."\n";
2872: if ($default) {
1.804 bisitz 2873: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2874: '</option>'."\n";
2875: }
2876: foreach my $hostid (sort(keys(%servers))) {
2877: $result.= '<option value="'.$hostid.'">'.
2878: $hostid.' '.$servers{$hostid}."</option>\n";
2879: }
2880: $result .= '</select>'."\n";
2881: } elsif ($numlib == 1) {
2882: my $hostid;
2883: foreach my $item (keys(%servers)) {
2884: $hostid = $item;
2885: }
2886: $result .= '<input type="hidden" name="'.$name.'" value="'.
2887: $hostid.'" />';
2888: if (!$hide) {
2889: $result .= $hostid.' '.$servers{$hostid};
2890: }
2891: $result .= "\n";
2892: } elsif ($default) {
2893: $result .= '<input type="hidden" name="'.$name.
2894: '" value="default" />';
2895: if (!$hide) {
2896: $result .= &mt('default');
2897: }
2898: $result .= "\n";
1.33 matthew 2899: }
1.586 raeburn 2900: return ($result,$numlib);
1.33 matthew 2901: }
1.112 bowersj2 2902:
2903: =pod
2904:
1.534 albertel 2905: =back
2906:
1.112 bowersj2 2907: =cut
1.87 matthew 2908:
2909: ###############################################################
1.112 bowersj2 2910: ## Decoding User Agent ##
1.87 matthew 2911: ###############################################################
2912:
2913: =pod
2914:
1.112 bowersj2 2915: =head1 Decoding the User Agent
2916:
2917: =over 4
2918:
2919: =item * &decode_user_agent()
1.87 matthew 2920:
2921: Inputs: $r
2922:
2923: Outputs:
2924:
2925: =over 4
2926:
1.112 bowersj2 2927: =item * $httpbrowser
1.87 matthew 2928:
1.112 bowersj2 2929: =item * $clientbrowser
1.87 matthew 2930:
1.112 bowersj2 2931: =item * $clientversion
1.87 matthew 2932:
1.112 bowersj2 2933: =item * $clientmathml
1.87 matthew 2934:
1.112 bowersj2 2935: =item * $clientunicode
1.87 matthew 2936:
1.112 bowersj2 2937: =item * $clientos
1.87 matthew 2938:
1.1137 raeburn 2939: =item * $clientmobile
2940:
1.1141 raeburn 2941: =item * $clientinfo
2942:
1.1194 raeburn 2943: =item * $clientosversion
2944:
1.87 matthew 2945: =back
2946:
1.157 matthew 2947: =back
2948:
1.87 matthew 2949: =cut
2950:
2951: ###############################################################
2952: ###############################################################
2953: sub decode_user_agent {
1.247 albertel 2954: my ($r)=@_;
1.87 matthew 2955: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2956: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2957: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2958: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2959: my $clientbrowser='unknown';
2960: my $clientversion='0';
2961: my $clientmathml='';
2962: my $clientunicode='0';
1.1137 raeburn 2963: my $clientmobile=0;
1.1194 raeburn 2964: my $clientosversion='';
1.87 matthew 2965: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2966: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2967: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2968: $clientbrowser=$bname;
2969: $httpbrowser=~/$vreg/i;
2970: $clientversion=$1;
2971: $clientmathml=($clientversion>=$minv);
2972: $clientunicode=($clientversion>=$univ);
2973: }
2974: }
2975: my $clientos='unknown';
1.1141 raeburn 2976: my $clientinfo;
1.87 matthew 2977: if (($httpbrowser=~/linux/i) ||
2978: ($httpbrowser=~/unix/i) ||
2979: ($httpbrowser=~/ux/i) ||
2980: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2981: if (($httpbrowser=~/vax/i) ||
2982: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2983: if ($httpbrowser=~/next/i) { $clientos='next'; }
2984: if (($httpbrowser=~/mac/i) ||
2985: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2986: if ($httpbrowser=~/win/i) {
2987: $clientos='win';
2988: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2989: $clientosversion = $1;
2990: }
2991: }
1.87 matthew 2992: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2993: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2994: $clientmobile=lc($1);
2995: }
1.1141 raeburn 2996: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2997: $clientinfo = 'firefox-'.$1;
2998: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2999: $clientinfo = 'chromeframe-'.$1;
3000: }
1.87 matthew 3001: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 3002: $clientunicode,$clientos,$clientmobile,$clientinfo,
3003: $clientosversion);
1.87 matthew 3004: }
3005:
1.32 matthew 3006: ###############################################################
3007: ## Authentication changing form generation subroutines ##
3008: ###############################################################
3009: ##
3010: ## All of the authform_xxxxxxx subroutines take their inputs in a
3011: ## hash, and have reasonable default values.
3012: ##
3013: ## formname = the name given in the <form> tag.
1.35 matthew 3014: #-------------------------------------------
3015:
1.45 matthew 3016: =pod
3017:
1.112 bowersj2 3018: =head1 Authentication Routines
3019:
3020: =over 4
3021:
1.648 raeburn 3022: =item * &authform_xxxxxx()
1.35 matthew 3023:
3024: The authform_xxxxxx subroutines provide javascript and html forms which
3025: handle some of the conveniences required for authentication forms.
3026: This is not an optimal method, but it works.
3027:
3028: =over 4
3029:
1.112 bowersj2 3030: =item * authform_header
1.35 matthew 3031:
1.112 bowersj2 3032: =item * authform_authorwarning
1.35 matthew 3033:
1.112 bowersj2 3034: =item * authform_nochange
1.35 matthew 3035:
1.112 bowersj2 3036: =item * authform_kerberos
1.35 matthew 3037:
1.112 bowersj2 3038: =item * authform_internal
1.35 matthew 3039:
1.112 bowersj2 3040: =item * authform_filesystem
1.35 matthew 3041:
1.1310 raeburn 3042: =item * authform_lti
3043:
1.35 matthew 3044: =back
3045:
1.648 raeburn 3046: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3047:
1.35 matthew 3048: =cut
3049:
3050: #-------------------------------------------
1.32 matthew 3051: sub authform_header{
3052: my %in = (
3053: formname => 'cu',
1.80 albertel 3054: kerb_def_dom => '',
1.32 matthew 3055: @_,
3056: );
3057: $in{'formname'} = 'document.' . $in{'formname'};
3058: my $result='';
1.80 albertel 3059:
3060: #---------------------------------------------- Code for upper case translation
3061: my $Javascript_toUpperCase;
3062: unless ($in{kerb_def_dom}) {
3063: $Javascript_toUpperCase =<<"END";
3064: switch (choice) {
3065: case 'krb': currentform.elements[choicearg].value =
3066: currentform.elements[choicearg].value.toUpperCase();
3067: break;
3068: default:
3069: }
3070: END
3071: } else {
3072: $Javascript_toUpperCase = "";
3073: }
3074:
1.165 raeburn 3075: my $radioval = "'nochange'";
1.591 raeburn 3076: if (defined($in{'curr_authtype'})) {
3077: if ($in{'curr_authtype'} ne '') {
3078: $radioval = "'".$in{'curr_authtype'}."arg'";
3079: }
1.174 matthew 3080: }
1.165 raeburn 3081: my $argfield = 'null';
1.591 raeburn 3082: if (defined($in{'mode'})) {
1.165 raeburn 3083: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3084: if (defined($in{'curr_autharg'})) {
3085: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3086: $argfield = "'$in{'curr_autharg'}'";
3087: }
3088: }
3089: }
3090: }
3091:
1.32 matthew 3092: $result.=<<"END";
3093: var current = new Object();
1.165 raeburn 3094: current.radiovalue = $radioval;
3095: current.argfield = $argfield;
1.32 matthew 3096:
3097: function changed_radio(choice,currentform) {
3098: var choicearg = choice + 'arg';
3099: // If a radio button in changed, we need to change the argfield
3100: if (current.radiovalue != choice) {
3101: current.radiovalue = choice;
3102: if (current.argfield != null) {
3103: currentform.elements[current.argfield].value = '';
3104: }
3105: if (choice == 'nochange') {
3106: current.argfield = null;
3107: } else {
3108: current.argfield = choicearg;
3109: switch(choice) {
3110: case 'krb':
3111: currentform.elements[current.argfield].value =
3112: "$in{'kerb_def_dom'}";
3113: break;
3114: default:
3115: break;
3116: }
3117: }
3118: }
3119: return;
3120: }
1.22 www 3121:
1.32 matthew 3122: function changed_text(choice,currentform) {
3123: var choicearg = choice + 'arg';
3124: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3125: $Javascript_toUpperCase
1.32 matthew 3126: // clear old field
3127: if ((current.argfield != choicearg) && (current.argfield != null)) {
3128: currentform.elements[current.argfield].value = '';
3129: }
3130: current.argfield = choicearg;
3131: }
3132: set_auth_radio_buttons(choice,currentform);
3133: return;
1.20 www 3134: }
1.32 matthew 3135:
3136: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3137: var numauthchoices = currentform.login.length;
3138: if (typeof numauthchoices == "undefined") {
3139: return;
3140: }
1.32 matthew 3141: var i=0;
1.986 raeburn 3142: while (i < numauthchoices) {
1.32 matthew 3143: if (currentform.login[i].value == newvalue) { break; }
3144: i++;
3145: }
1.986 raeburn 3146: if (i == numauthchoices) {
1.32 matthew 3147: return;
3148: }
3149: current.radiovalue = newvalue;
3150: currentform.login[i].checked = true;
3151: return;
3152: }
3153: END
3154: return $result;
3155: }
3156:
1.1106 raeburn 3157: sub authform_authorwarning {
1.32 matthew 3158: my $result='';
1.144 matthew 3159: $result='<i>'.
3160: &mt('As a general rule, only authors or co-authors should be '.
3161: 'filesystem authenticated '.
3162: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3163: return $result;
3164: }
3165:
1.1106 raeburn 3166: sub authform_nochange {
1.32 matthew 3167: my %in = (
3168: formname => 'document.cu',
3169: kerb_def_dom => 'MSU.EDU',
3170: @_,
3171: );
1.1106 raeburn 3172: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3173: my $result;
1.1104 raeburn 3174: if (!$authnum) {
1.1105 raeburn 3175: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3176: } else {
3177: $result = '<label>'.&mt('[_1] Do not change login data',
3178: '<input type="radio" name="login" value="nochange" '.
3179: 'checked="checked" onclick="'.
1.281 albertel 3180: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3181: '</label>';
1.586 raeburn 3182: }
1.32 matthew 3183: return $result;
3184: }
3185:
1.591 raeburn 3186: sub authform_kerberos {
1.32 matthew 3187: my %in = (
3188: formname => 'document.cu',
3189: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3190: kerb_def_auth => 'krb4',
1.32 matthew 3191: @_,
3192: );
1.586 raeburn 3193: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3194: $autharg,$jscall,$disabled);
1.1106 raeburn 3195: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3196: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3197: $check5 = ' checked="checked"';
1.80 albertel 3198: } else {
1.772 bisitz 3199: $check4 = ' checked="checked"';
1.80 albertel 3200: }
1.1259 raeburn 3201: if ($in{'readonly'}) {
3202: $disabled = ' disabled="disabled"';
3203: }
1.165 raeburn 3204: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3205: if (defined($in{'curr_authtype'})) {
3206: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3207: $krbcheck = ' checked="checked"';
1.623 raeburn 3208: if (defined($in{'mode'})) {
3209: if ($in{'mode'} eq 'modifyuser') {
3210: $krbcheck = '';
3211: }
3212: }
1.591 raeburn 3213: if (defined($in{'curr_kerb_ver'})) {
3214: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3215: $check5 = ' checked="checked"';
1.591 raeburn 3216: $check4 = '';
3217: } else {
1.772 bisitz 3218: $check4 = ' checked="checked"';
1.591 raeburn 3219: $check5 = '';
3220: }
1.586 raeburn 3221: }
1.591 raeburn 3222: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3223: $krbarg = $in{'curr_autharg'};
3224: }
1.586 raeburn 3225: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3226: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3227: $result =
3228: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3229: $in{'curr_autharg'},$krbver);
3230: } else {
3231: $result =
3232: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3233: }
3234: return $result;
3235: }
3236: }
3237: } else {
3238: if ($authnum == 1) {
1.784 bisitz 3239: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3240: }
3241: }
1.586 raeburn 3242: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3243: return;
1.587 raeburn 3244: } elsif ($authtype eq '') {
1.591 raeburn 3245: if (defined($in{'mode'})) {
1.587 raeburn 3246: if ($in{'mode'} eq 'modifycourse') {
3247: if ($authnum == 1) {
1.1259 raeburn 3248: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3249: }
3250: }
3251: }
1.586 raeburn 3252: }
3253: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3254: if ($authtype eq '') {
3255: $authtype = '<input type="radio" name="login" value="krb" '.
3256: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3257: $krbcheck.$disabled.' />';
1.586 raeburn 3258: }
3259: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3260: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3261: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3262: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3263: $in{'curr_authtype'} eq 'krb4')) {
3264: $result .= &mt
1.144 matthew 3265: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3266: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3267: '<label>'.$authtype,
1.281 albertel 3268: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3269: 'value="'.$krbarg.'" '.
1.1259 raeburn 3270: 'onchange="'.$jscall.'"'.$disabled.' />',
3271: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3272: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3273: '</label>');
1.586 raeburn 3274: } elsif ($can_assign{'krb4'}) {
3275: $result .= &mt
3276: ('[_1] Kerberos authenticated with domain [_2] '.
3277: '[_3] Version 4 [_4]',
3278: '<label>'.$authtype,
3279: '</label><input type="text" size="10" name="krbarg" '.
3280: 'value="'.$krbarg.'" '.
1.1259 raeburn 3281: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3282: '<label><input type="hidden" name="krbver" value="4" />',
3283: '</label>');
3284: } elsif ($can_assign{'krb5'}) {
3285: $result .= &mt
3286: ('[_1] Kerberos authenticated with domain [_2] '.
3287: '[_3] Version 5 [_4]',
3288: '<label>'.$authtype,
3289: '</label><input type="text" size="10" name="krbarg" '.
3290: 'value="'.$krbarg.'" '.
1.1259 raeburn 3291: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3292: '<label><input type="hidden" name="krbver" value="5" />',
3293: '</label>');
3294: }
1.32 matthew 3295: return $result;
3296: }
3297:
1.1106 raeburn 3298: sub authform_internal {
1.586 raeburn 3299: my %in = (
1.32 matthew 3300: formname => 'document.cu',
3301: kerb_def_dom => 'MSU.EDU',
3302: @_,
3303: );
1.1259 raeburn 3304: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3305: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3306: if ($in{'readonly'}) {
3307: $disabled = ' disabled="disabled"';
3308: }
1.591 raeburn 3309: if (defined($in{'curr_authtype'})) {
3310: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3311: if ($can_assign{'int'}) {
1.772 bisitz 3312: $intcheck = 'checked="checked" ';
1.623 raeburn 3313: if (defined($in{'mode'})) {
3314: if ($in{'mode'} eq 'modifyuser') {
3315: $intcheck = '';
3316: }
3317: }
1.591 raeburn 3318: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3319: $intarg = $in{'curr_autharg'};
3320: }
3321: } else {
3322: $result = &mt('Currently internally authenticated.');
3323: return $result;
1.165 raeburn 3324: }
3325: }
1.586 raeburn 3326: } else {
3327: if ($authnum == 1) {
1.784 bisitz 3328: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3329: }
3330: }
3331: if (!$can_assign{'int'}) {
3332: return;
1.587 raeburn 3333: } elsif ($authtype eq '') {
1.591 raeburn 3334: if (defined($in{'mode'})) {
1.587 raeburn 3335: if ($in{'mode'} eq 'modifycourse') {
3336: if ($authnum == 1) {
1.1259 raeburn 3337: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3338: }
3339: }
3340: }
1.165 raeburn 3341: }
1.586 raeburn 3342: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3343: if ($authtype eq '') {
3344: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3345: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3346: }
1.605 bisitz 3347: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3348: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3349: $result = &mt
1.144 matthew 3350: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3351: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3352: $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 3353: return $result;
3354: }
3355:
1.1104 raeburn 3356: sub authform_local {
1.32 matthew 3357: my %in = (
3358: formname => 'document.cu',
3359: kerb_def_dom => 'MSU.EDU',
3360: @_,
3361: );
1.1259 raeburn 3362: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3363: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3364: if ($in{'readonly'}) {
3365: $disabled = ' disabled="disabled"';
3366: }
1.591 raeburn 3367: if (defined($in{'curr_authtype'})) {
3368: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3369: if ($can_assign{'loc'}) {
1.772 bisitz 3370: $loccheck = 'checked="checked" ';
1.623 raeburn 3371: if (defined($in{'mode'})) {
3372: if ($in{'mode'} eq 'modifyuser') {
3373: $loccheck = '';
3374: }
3375: }
1.591 raeburn 3376: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3377: $locarg = $in{'curr_autharg'};
3378: }
3379: } else {
3380: $result = &mt('Currently using local (institutional) authentication.');
3381: return $result;
1.165 raeburn 3382: }
3383: }
1.586 raeburn 3384: } else {
3385: if ($authnum == 1) {
1.784 bisitz 3386: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3387: }
3388: }
3389: if (!$can_assign{'loc'}) {
3390: return;
1.587 raeburn 3391: } elsif ($authtype eq '') {
1.591 raeburn 3392: if (defined($in{'mode'})) {
1.587 raeburn 3393: if ($in{'mode'} eq 'modifycourse') {
3394: if ($authnum == 1) {
1.1259 raeburn 3395: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3396: }
3397: }
3398: }
1.165 raeburn 3399: }
1.586 raeburn 3400: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3401: if ($authtype eq '') {
3402: $authtype = '<input type="radio" name="login" value="loc" '.
3403: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3404: $jscall.'"'.$disabled.' />';
1.586 raeburn 3405: }
3406: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3407: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3408: $result = &mt('[_1] Local Authentication with argument [_2]',
3409: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3410: return $result;
3411: }
3412:
1.1106 raeburn 3413: sub authform_filesystem {
1.32 matthew 3414: my %in = (
3415: formname => 'document.cu',
3416: kerb_def_dom => 'MSU.EDU',
3417: @_,
3418: );
1.1259 raeburn 3419: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3420: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3421: if ($in{'readonly'}) {
3422: $disabled = ' disabled="disabled"';
3423: }
1.591 raeburn 3424: if (defined($in{'curr_authtype'})) {
3425: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3426: if ($can_assign{'fsys'}) {
1.772 bisitz 3427: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3428: if (defined($in{'mode'})) {
3429: if ($in{'mode'} eq 'modifyuser') {
3430: $fsyscheck = '';
3431: }
3432: }
1.586 raeburn 3433: } else {
3434: $result = &mt('Currently Filesystem Authenticated.');
3435: return $result;
1.1259 raeburn 3436: }
1.586 raeburn 3437: }
3438: } else {
3439: if ($authnum == 1) {
1.784 bisitz 3440: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3441: }
3442: }
3443: if (!$can_assign{'fsys'}) {
3444: return;
1.587 raeburn 3445: } elsif ($authtype eq '') {
1.591 raeburn 3446: if (defined($in{'mode'})) {
1.587 raeburn 3447: if ($in{'mode'} eq 'modifycourse') {
3448: if ($authnum == 1) {
1.1259 raeburn 3449: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3450: }
3451: }
3452: }
1.586 raeburn 3453: }
3454: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3455: if ($authtype eq '') {
3456: $authtype = '<input type="radio" name="login" value="fsys" '.
3457: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3458: $jscall.'"'.$disabled.' />';
1.586 raeburn 3459: }
1.1310 raeburn 3460: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3461: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3462: $result = &mt
1.144 matthew 3463: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1310 raeburn 3464: '<label>'.$authtype,'</label>'.$autharg);
3465: return $result;
3466: }
3467:
3468: sub authform_lti {
3469: my %in = (
3470: formname => 'document.cu',
3471: kerb_def_dom => 'MSU.EDU',
3472: @_,
3473: );
3474: my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
3475: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
3476: if ($in{'readonly'}) {
3477: $disabled = ' disabled="disabled"';
3478: }
3479: if (defined($in{'curr_authtype'})) {
3480: if ($in{'curr_authtype'} eq 'lti') {
3481: if ($can_assign{'lti'}) {
3482: $lticheck = 'checked="checked" ';
3483: if (defined($in{'mode'})) {
3484: if ($in{'mode'} eq 'modifyuser') {
3485: $lticheck = '';
3486: }
3487: }
3488: } else {
3489: $result = &mt('Currently LTI Authenticated.');
3490: return $result;
3491: }
3492: }
3493: } else {
3494: if ($authnum == 1) {
3495: $authtype = '<input type="hidden" name="login" value="lti" />';
3496: }
3497: }
3498: if (!$can_assign{'lti'}) {
3499: return;
3500: } elsif ($authtype eq '') {
3501: if (defined($in{'mode'})) {
3502: if ($in{'mode'} eq 'modifycourse') {
3503: if ($authnum == 1) {
3504: $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';
3505: }
3506: }
3507: }
3508: }
3509: $jscall = "javascript:changed_radio('lti',$in{'formname'});";
3510: if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
3511: $authtype = '<input type="radio" name="login" value="lti" '.
3512: $lticheck.' onchange="'.$jscall.'" onclick="'.
3513: $jscall.'"'.$disabled.' />';
3514: }
3515: $autharg = '<input type="hidden" name="ltiarg" value="" />';
3516: if ($authtype) {
3517: $result = &mt('[_1] LTI Authenticated',
3518: '<label>'.$authtype.'</label>'.$autharg);
3519: } else {
3520: $result = '<b>'.&mt('LTI Authenticated').'</b>'.
3521: $autharg;
3522: }
1.32 matthew 3523: return $result;
3524: }
3525:
1.586 raeburn 3526: sub get_assignable_auth {
3527: my ($dom) = @_;
3528: if ($dom eq '') {
3529: $dom = $env{'request.role.domain'};
3530: }
3531: my %can_assign = (
3532: krb4 => 1,
3533: krb5 => 1,
3534: int => 1,
3535: loc => 1,
1.1310 raeburn 3536: lti => 1,
1.586 raeburn 3537: );
3538: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3539: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3540: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3541: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3542: my $context;
3543: if ($env{'request.role'} =~ /^au/) {
3544: $context = 'author';
1.1259 raeburn 3545: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3546: $context = 'domain';
3547: } elsif ($env{'request.course.id'}) {
3548: $context = 'course';
3549: }
3550: if ($context) {
3551: if (ref($authhash->{$context}) eq 'HASH') {
3552: %can_assign = %{$authhash->{$context}};
3553: }
3554: }
3555: }
3556: }
3557: my $authnum = 0;
3558: foreach my $key (keys(%can_assign)) {
3559: if ($can_assign{$key}) {
3560: $authnum ++;
3561: }
3562: }
3563: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3564: $authnum --;
3565: }
3566: return ($authnum,%can_assign);
3567: }
3568:
1.80 albertel 3569: ###############################################################
3570: ## Get Kerberos Defaults for Domain ##
3571: ###############################################################
3572: ##
3573: ## Returns default kerberos version and an associated argument
3574: ## as listed in file domain.tab. If not listed, provides
3575: ## appropriate default domain and kerberos version.
3576: ##
3577: #-------------------------------------------
3578:
3579: =pod
3580:
1.648 raeburn 3581: =item * &get_kerberos_defaults()
1.80 albertel 3582:
3583: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3584: version and domain. If not found, it defaults to version 4 and the
3585: domain of the server.
1.80 albertel 3586:
1.648 raeburn 3587: =over 4
3588:
1.80 albertel 3589: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3590:
1.648 raeburn 3591: =back
3592:
3593: =back
3594:
1.80 albertel 3595: =cut
3596:
3597: #-------------------------------------------
3598: sub get_kerberos_defaults {
3599: my $domain=shift;
1.641 raeburn 3600: my ($krbdef,$krbdefdom);
3601: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3602: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3603: $krbdef = $domdefaults{'auth_def'};
3604: $krbdefdom = $domdefaults{'auth_arg_def'};
3605: } else {
1.80 albertel 3606: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3607: my $krbdefdom=$1;
3608: $krbdefdom=~tr/a-z/A-Z/;
3609: $krbdef = "krb4";
3610: }
3611: return ($krbdef,$krbdefdom);
3612: }
1.112 bowersj2 3613:
1.32 matthew 3614:
1.46 matthew 3615: ###############################################################
3616: ## Thesaurus Functions ##
3617: ###############################################################
1.20 www 3618:
1.46 matthew 3619: =pod
1.20 www 3620:
1.112 bowersj2 3621: =head1 Thesaurus Functions
3622:
3623: =over 4
3624:
1.648 raeburn 3625: =item * &initialize_keywords()
1.46 matthew 3626:
3627: Initializes the package variable %Keywords if it is empty. Uses the
3628: package variable $thesaurus_db_file.
3629:
3630: =cut
3631:
3632: ###################################################
3633:
3634: sub initialize_keywords {
3635: return 1 if (scalar keys(%Keywords));
3636: # If we are here, %Keywords is empty, so fill it up
3637: # Make sure the file we need exists...
3638: if (! -e $thesaurus_db_file) {
3639: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3640: " failed because it does not exist");
3641: return 0;
3642: }
3643: # Set up the hash as a database
3644: my %thesaurus_db;
3645: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3646: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3647: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3648: $thesaurus_db_file);
3649: return 0;
3650: }
3651: # Get the average number of appearances of a word.
3652: my $avecount = $thesaurus_db{'average.count'};
3653: # Put keywords (those that appear > average) into %Keywords
3654: while (my ($word,$data)=each (%thesaurus_db)) {
3655: my ($count,undef) = split /:/,$data;
3656: $Keywords{$word}++ if ($count > $avecount);
3657: }
3658: untie %thesaurus_db;
3659: # Remove special values from %Keywords.
1.356 albertel 3660: foreach my $value ('total.count','average.count') {
3661: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3662: }
1.46 matthew 3663: return 1;
3664: }
3665:
3666: ###################################################
3667:
3668: =pod
3669:
1.648 raeburn 3670: =item * &keyword($word)
1.46 matthew 3671:
3672: Returns true if $word is a keyword. A keyword is a word that appears more
3673: than the average number of times in the thesaurus database. Calls
3674: &initialize_keywords
3675:
3676: =cut
3677:
3678: ###################################################
1.20 www 3679:
3680: sub keyword {
1.46 matthew 3681: return if (!&initialize_keywords());
3682: my $word=lc(shift());
3683: $word=~s/\W//g;
3684: return exists($Keywords{$word});
1.20 www 3685: }
1.46 matthew 3686:
3687: ###############################################################
3688:
3689: =pod
1.20 www 3690:
1.648 raeburn 3691: =item * &get_related_words()
1.46 matthew 3692:
1.160 matthew 3693: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3694: an array of words. If the keyword is not in the thesaurus, an empty array
3695: will be returned. The order of the words returned is determined by the
3696: database which holds them.
3697:
3698: Uses global $thesaurus_db_file.
3699:
1.1057 foxr 3700:
1.46 matthew 3701: =cut
3702:
3703: ###############################################################
3704: sub get_related_words {
3705: my $keyword = shift;
3706: my %thesaurus_db;
3707: if (! -e $thesaurus_db_file) {
3708: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3709: "failed because the file does not exist");
3710: return ();
3711: }
3712: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3713: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3714: return ();
3715: }
3716: my @Words=();
1.429 www 3717: my $count=0;
1.46 matthew 3718: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3719: # The first element is the number of times
3720: # the word appears. We do not need it now.
1.429 www 3721: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3722: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3723: my $threshold=$mostfrequentcount/10;
3724: foreach my $possibleword (@RelatedWords) {
3725: my ($word,$wordcount)=split(/\,/,$possibleword);
3726: if ($wordcount>$threshold) {
3727: push(@Words,$word);
3728: $count++;
3729: if ($count>10) { last; }
3730: }
1.20 www 3731: }
3732: }
1.46 matthew 3733: untie %thesaurus_db;
3734: return @Words;
1.14 harris41 3735: }
1.1090 foxr 3736: ###############################################################
3737: #
3738: # Spell checking
3739: #
3740:
3741: =pod
3742:
1.1142 raeburn 3743: =back
3744:
1.1090 foxr 3745: =head1 Spell checking
3746:
3747: =over 4
3748:
3749: =item * &check_spelling($wordlist $language)
3750:
3751: Takes a string containing words and feeds it to an external
3752: spellcheck program via a pipeline. Returns a string containing
3753: them mis-spelled words.
3754:
3755: Parameters:
3756:
3757: =over 4
3758:
3759: =item - $wordlist
3760:
3761: String that will be fed into the spellcheck program.
3762:
3763: =item - $language
3764:
3765: Language string that specifies the language for which the spell
3766: check will be performed.
3767:
3768: =back
3769:
3770: =back
3771:
3772: Note: This sub assumes that aspell is installed.
3773:
3774:
3775: =cut
3776:
1.46 matthew 3777:
1.1090 foxr 3778: sub check_spelling {
3779: my ($wordlist, $language) = @_;
1.1091 foxr 3780: my @misspellings;
3781:
3782: # Generate the speller and set the langauge.
3783: # if explicitly selected:
1.1090 foxr 3784:
1.1091 foxr 3785: my $speller = Text::Aspell->new;
1.1090 foxr 3786: if ($language) {
1.1091 foxr 3787: $speller->set_option('lang', $language);
1.1090 foxr 3788: }
3789:
1.1091 foxr 3790: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3791:
1.1091 foxr 3792: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3793:
1.1091 foxr 3794: foreach my $word (@words) {
3795: if(! $speller->check($word)) {
3796: push(@misspellings, $word);
1.1090 foxr 3797: }
3798: }
1.1091 foxr 3799: return join(' ', @misspellings);
3800:
1.1090 foxr 3801: }
3802:
1.61 www 3803: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3804: =pod
3805:
1.112 bowersj2 3806: =head1 User Name Functions
3807:
3808: =over 4
3809:
1.648 raeburn 3810: =item * &plainname($uname,$udom,$first)
1.81 albertel 3811:
1.112 bowersj2 3812: Takes a users logon name and returns it as a string in
1.226 albertel 3813: "first middle last generation" form
3814: if $first is set to 'lastname' then it returns it as
3815: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3816:
3817: =cut
1.61 www 3818:
1.295 www 3819:
1.81 albertel 3820: ###############################################################
1.61 www 3821: sub plainname {
1.226 albertel 3822: my ($uname,$udom,$first)=@_;
1.537 albertel 3823: return if (!defined($uname) || !defined($udom));
1.295 www 3824: my %names=&getnames($uname,$udom);
1.226 albertel 3825: my $name=&Apache::lonnet::format_name($names{'firstname'},
3826: $names{'middlename'},
3827: $names{'lastname'},
3828: $names{'generation'},$first);
3829: $name=~s/^\s+//;
1.62 www 3830: $name=~s/\s+$//;
3831: $name=~s/\s+/ /g;
1.353 albertel 3832: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3833: return $name;
1.61 www 3834: }
1.66 www 3835:
3836: # -------------------------------------------------------------------- Nickname
1.81 albertel 3837: =pod
3838:
1.648 raeburn 3839: =item * &nickname($uname,$udom)
1.81 albertel 3840:
3841: Gets a users name and returns it as a string as
3842:
3843: ""nickname""
1.66 www 3844:
1.81 albertel 3845: if the user has a nickname or
3846:
3847: "first middle last generation"
3848:
3849: if the user does not
3850:
3851: =cut
1.66 www 3852:
3853: sub nickname {
3854: my ($uname,$udom)=@_;
1.537 albertel 3855: return if (!defined($uname) || !defined($udom));
1.295 www 3856: my %names=&getnames($uname,$udom);
1.68 albertel 3857: my $name=$names{'nickname'};
1.66 www 3858: if ($name) {
3859: $name='"'.$name.'"';
3860: } else {
3861: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3862: $names{'lastname'}.' '.$names{'generation'};
3863: $name=~s/\s+$//;
3864: $name=~s/\s+/ /g;
3865: }
3866: return $name;
3867: }
3868:
1.295 www 3869: sub getnames {
3870: my ($uname,$udom)=@_;
1.537 albertel 3871: return if (!defined($uname) || !defined($udom));
1.433 albertel 3872: if ($udom eq 'public' && $uname eq 'public') {
3873: return ('lastname' => &mt('Public'));
3874: }
1.295 www 3875: my $id=$uname.':'.$udom;
3876: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3877: if ($cached) {
3878: return %{$names};
3879: } else {
3880: my %loadnames=&Apache::lonnet::get('environment',
3881: ['firstname','middlename','lastname','generation','nickname'],
3882: $udom,$uname);
3883: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3884: return %loadnames;
3885: }
3886: }
1.61 www 3887:
1.542 raeburn 3888: # -------------------------------------------------------------------- getemails
1.648 raeburn 3889:
1.542 raeburn 3890: =pod
3891:
1.648 raeburn 3892: =item * &getemails($uname,$udom)
1.542 raeburn 3893:
3894: Gets a user's email information and returns it as a hash with keys:
3895: notification, critnotification, permanentemail
3896:
3897: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3898: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3899:
1.648 raeburn 3900:
1.542 raeburn 3901: =cut
3902:
1.648 raeburn 3903:
1.466 albertel 3904: sub getemails {
3905: my ($uname,$udom)=@_;
3906: if ($udom eq 'public' && $uname eq 'public') {
3907: return;
3908: }
1.467 www 3909: if (!$udom) { $udom=$env{'user.domain'}; }
3910: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3911: my $id=$uname.':'.$udom;
3912: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3913: if ($cached) {
3914: return %{$names};
3915: } else {
3916: my %loadnames=&Apache::lonnet::get('environment',
3917: ['notification','critnotification',
3918: 'permanentemail'],
3919: $udom,$uname);
3920: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3921: return %loadnames;
3922: }
3923: }
3924:
1.551 albertel 3925: sub flush_email_cache {
3926: my ($uname,$udom)=@_;
3927: if (!$udom) { $udom =$env{'user.domain'}; }
3928: if (!$uname) { $uname=$env{'user.name'}; }
3929: return if ($udom eq 'public' && $uname eq 'public');
3930: my $id=$uname.':'.$udom;
3931: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3932: }
3933:
1.728 raeburn 3934: # -------------------------------------------------------------------- getlangs
3935:
3936: =pod
3937:
3938: =item * &getlangs($uname,$udom)
3939:
3940: Gets a user's language preference and returns it as a hash with key:
3941: language.
3942:
3943: =cut
3944:
3945:
3946: sub getlangs {
3947: my ($uname,$udom) = @_;
3948: if (!$udom) { $udom =$env{'user.domain'}; }
3949: if (!$uname) { $uname=$env{'user.name'}; }
3950: my $id=$uname.':'.$udom;
3951: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3952: if ($cached) {
3953: return %{$langs};
3954: } else {
3955: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3956: $udom,$uname);
3957: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3958: return %loadlangs;
3959: }
3960: }
3961:
3962: sub flush_langs_cache {
3963: my ($uname,$udom)=@_;
3964: if (!$udom) { $udom =$env{'user.domain'}; }
3965: if (!$uname) { $uname=$env{'user.name'}; }
3966: return if ($udom eq 'public' && $uname eq 'public');
3967: my $id=$uname.':'.$udom;
3968: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3969: }
3970:
1.61 www 3971: # ------------------------------------------------------------------ Screenname
1.81 albertel 3972:
3973: =pod
3974:
1.648 raeburn 3975: =item * &screenname($uname,$udom)
1.81 albertel 3976:
3977: Gets a users screenname and returns it as a string
3978:
3979: =cut
1.61 www 3980:
3981: sub screenname {
3982: my ($uname,$udom)=@_;
1.258 albertel 3983: if ($uname eq $env{'user.name'} &&
3984: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3985: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3986: return $names{'screenname'};
1.62 www 3987: }
3988:
1.212 albertel 3989:
1.802 bisitz 3990: # ------------------------------------------------------------- Confirm Wrapper
3991: =pod
3992:
1.1142 raeburn 3993: =item * &confirmwrapper($message)
1.802 bisitz 3994:
3995: Wrap messages about completion of operation in box
3996:
3997: =cut
3998:
3999: sub confirmwrapper {
4000: my ($message)=@_;
4001: if ($message) {
4002: return "\n".'<div class="LC_confirm_box">'."\n"
4003: .$message."\n"
4004: .'</div>'."\n";
4005: } else {
4006: return $message;
4007: }
4008: }
4009:
1.62 www 4010: # ------------------------------------------------------------- Message Wrapper
4011:
4012: sub messagewrapper {
1.369 www 4013: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 4014: return
1.441 albertel 4015: '<a href="/adm/email?compose=individual&'.
4016: 'recname='.$username.'&recdom='.$domain.
4017: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 4018: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 4019: }
1.802 bisitz 4020:
1.74 www 4021: # --------------------------------------------------------------- Notes Wrapper
4022:
4023: sub noteswrapper {
4024: my ($link,$un,$do)=@_;
4025: return
1.896 amueller 4026: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 4027: }
1.802 bisitz 4028:
1.62 www 4029: # ------------------------------------------------------------- Aboutme Wrapper
4030:
4031: sub aboutmewrapper {
1.1070 raeburn 4032: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 4033: if (!defined($username) && !defined($domain)) {
4034: return;
4035: }
1.1096 raeburn 4036: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 4037: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 4038: }
4039:
4040: # ------------------------------------------------------------ Syllabus Wrapper
4041:
4042: sub syllabuswrapper {
1.707 bisitz 4043: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4044: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4045: }
1.14 harris41 4046:
1.802 bisitz 4047: # -----------------------------------------------------------------------------
4048:
1.208 matthew 4049: sub track_student_link {
1.887 raeburn 4050: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4051: my $link ="/adm/trackstudent?";
1.208 matthew 4052: my $title = 'View recent activity';
4053: if (defined($sname) && $sname !~ /^\s*$/ &&
4054: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4055: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4056: $title .= ' of this student';
1.268 albertel 4057: }
1.208 matthew 4058: if (defined($target) && $target !~ /^\s*$/) {
4059: $target = qq{target="$target"};
4060: } else {
4061: $target = '';
4062: }
1.268 albertel 4063: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4064: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4065: $title = &mt($title);
4066: $linktext = &mt($linktext);
1.448 albertel 4067: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4068: &help_open_topic('View_recent_activity');
1.208 matthew 4069: }
4070:
1.781 raeburn 4071: sub slot_reservations_link {
4072: my ($linktext,$sname,$sdom,$target) = @_;
4073: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4074: my $title = 'View slot reservation history';
4075: if (defined($sname) && $sname !~ /^\s*$/ &&
4076: defined($sdom) && $sdom !~ /^\s*$/) {
4077: $link .= "&uname=$sname&udom=$sdom";
4078: $title .= ' of this student';
4079: }
4080: if (defined($target) && $target !~ /^\s*$/) {
4081: $target = qq{target="$target"};
4082: } else {
4083: $target = '';
4084: }
4085: $title = &mt($title);
4086: $linktext = &mt($linktext);
4087: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4088: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4089:
4090: }
4091:
1.508 www 4092: # ===================================================== Display a student photo
4093:
4094:
1.509 albertel 4095: sub student_image_tag {
1.508 www 4096: my ($domain,$user)=@_;
4097: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4098: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4099: return '<img src="'.$imgsrc.'" align="right" />';
4100: } else {
4101: return '';
4102: }
4103: }
4104:
1.112 bowersj2 4105: =pod
4106:
4107: =back
4108:
4109: =head1 Access .tab File Data
4110:
4111: =over 4
4112:
1.648 raeburn 4113: =item * &languageids()
1.112 bowersj2 4114:
4115: returns list of all language ids
4116:
4117: =cut
4118:
1.14 harris41 4119: sub languageids {
1.16 harris41 4120: return sort(keys(%language));
1.14 harris41 4121: }
4122:
1.112 bowersj2 4123: =pod
4124:
1.648 raeburn 4125: =item * &languagedescription()
1.112 bowersj2 4126:
4127: returns description of a specified language id
4128:
4129: =cut
4130:
1.14 harris41 4131: sub languagedescription {
1.125 www 4132: my $code=shift;
4133: return ($supported_language{$code}?'* ':'').
4134: $language{$code}.
1.126 www 4135: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4136: }
4137:
1.1048 foxr 4138: =pod
4139:
4140: =item * &plainlanguagedescription
4141:
4142: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4143: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4144:
4145: =cut
4146:
1.145 www 4147: sub plainlanguagedescription {
4148: my $code=shift;
4149: return $language{$code};
4150: }
4151:
1.1048 foxr 4152: =pod
4153:
4154: =item * &supportedlanguagecode
4155:
4156: Returns the supported language code (e.g. sptutf maps to pt) given a language
4157: code.
4158:
4159: =cut
4160:
1.145 www 4161: sub supportedlanguagecode {
4162: my $code=shift;
4163: return $supported_language{$code};
1.97 www 4164: }
4165:
1.112 bowersj2 4166: =pod
4167:
1.1048 foxr 4168: =item * &latexlanguage()
4169:
4170: Given a language key code returns the correspondnig language to use
4171: to select the correct hyphenation on LaTeX printouts. This is undef if there
4172: is no supported hyphenation for the language code.
4173:
4174: =cut
4175:
4176: sub latexlanguage {
4177: my $code = shift;
4178: return $latex_language{$code};
4179: }
4180:
4181: =pod
4182:
4183: =item * &latexhyphenation()
4184:
4185: Same as above but what's supplied is the language as it might be stored
4186: in the metadata.
4187:
4188: =cut
4189:
4190: sub latexhyphenation {
4191: my $key = shift;
4192: return $latex_language_bykey{$key};
4193: }
4194:
4195: =pod
4196:
1.648 raeburn 4197: =item * ©rightids()
1.112 bowersj2 4198:
4199: returns list of all copyrights
4200:
4201: =cut
4202:
4203: sub copyrightids {
4204: return sort(keys(%cprtag));
4205: }
4206:
4207: =pod
4208:
1.648 raeburn 4209: =item * ©rightdescription()
1.112 bowersj2 4210:
4211: returns description of a specified copyright id
4212:
4213: =cut
4214:
4215: sub copyrightdescription {
1.166 www 4216: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4217: }
1.197 matthew 4218:
4219: =pod
4220:
1.648 raeburn 4221: =item * &source_copyrightids()
1.192 taceyjo1 4222:
4223: returns list of all source copyrights
4224:
4225: =cut
4226:
4227: sub source_copyrightids {
4228: return sort(keys(%scprtag));
4229: }
4230:
4231: =pod
4232:
1.648 raeburn 4233: =item * &source_copyrightdescription()
1.192 taceyjo1 4234:
4235: returns description of a specified source copyright id
4236:
4237: =cut
4238:
4239: sub source_copyrightdescription {
4240: return &mt($scprtag{shift(@_)});
4241: }
1.112 bowersj2 4242:
4243: =pod
4244:
1.648 raeburn 4245: =item * &filecategories()
1.112 bowersj2 4246:
4247: returns list of all file categories
4248:
4249: =cut
4250:
4251: sub filecategories {
4252: return sort(keys(%category_extensions));
4253: }
4254:
4255: =pod
4256:
1.648 raeburn 4257: =item * &filecategorytypes()
1.112 bowersj2 4258:
4259: returns list of file types belonging to a given file
4260: category
4261:
4262: =cut
4263:
4264: sub filecategorytypes {
1.356 albertel 4265: my ($cat) = @_;
1.1248 raeburn 4266: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4267: return @{$category_extensions{lc($cat)}};
4268: } else {
4269: return ();
4270: }
1.112 bowersj2 4271: }
4272:
4273: =pod
4274:
1.648 raeburn 4275: =item * &fileembstyle()
1.112 bowersj2 4276:
4277: returns embedding style for a specified file type
4278:
4279: =cut
4280:
4281: sub fileembstyle {
4282: return $fe{lc(shift(@_))};
1.169 www 4283: }
4284:
1.351 www 4285: sub filemimetype {
4286: return $fm{lc(shift(@_))};
4287: }
4288:
1.169 www 4289:
4290: sub filecategoryselect {
4291: my ($name,$value)=@_;
1.189 matthew 4292: return &select_form($value,$name,
1.970 raeburn 4293: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4294: }
4295:
4296: =pod
4297:
1.648 raeburn 4298: =item * &filedescription()
1.112 bowersj2 4299:
4300: returns description for a specified file type
4301:
4302: =cut
4303:
4304: sub filedescription {
1.188 matthew 4305: my $file_description = $fd{lc(shift())};
4306: $file_description =~ s:([\[\]]):~$1:g;
4307: return &mt($file_description);
1.112 bowersj2 4308: }
4309:
4310: =pod
4311:
1.648 raeburn 4312: =item * &filedescriptionex()
1.112 bowersj2 4313:
4314: returns description for a specified file type with
4315: extra formatting
4316:
4317: =cut
4318:
4319: sub filedescriptionex {
4320: my $ex=shift;
1.188 matthew 4321: my $file_description = $fd{lc($ex)};
4322: $file_description =~ s:([\[\]]):~$1:g;
4323: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4324: }
4325:
4326: # End of .tab access
4327: =pod
4328:
4329: =back
4330:
4331: =cut
4332:
4333: # ------------------------------------------------------------------ File Types
4334: sub fileextensions {
4335: return sort(keys(%fe));
4336: }
4337:
1.97 www 4338: # ----------------------------------------------------------- Display Languages
4339: # returns a hash with all desired display languages
4340: #
4341:
4342: sub display_languages {
4343: my %languages=();
1.695 raeburn 4344: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4345: $languages{$lang}=1;
1.97 www 4346: }
4347: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4348: if ($env{'form.displaylanguage'}) {
1.356 albertel 4349: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4350: $languages{$lang}=1;
1.97 www 4351: }
4352: }
4353: return %languages;
1.14 harris41 4354: }
4355:
1.582 albertel 4356: sub languages {
4357: my ($possible_langs) = @_;
1.695 raeburn 4358: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4359: if (!ref($possible_langs)) {
4360: if( wantarray ) {
4361: return @preferred_langs;
4362: } else {
4363: return $preferred_langs[0];
4364: }
4365: }
4366: my %possibilities = map { $_ => 1 } (@$possible_langs);
4367: my @preferred_possibilities;
4368: foreach my $preferred_lang (@preferred_langs) {
4369: if (exists($possibilities{$preferred_lang})) {
4370: push(@preferred_possibilities, $preferred_lang);
4371: }
4372: }
4373: if( wantarray ) {
4374: return @preferred_possibilities;
4375: }
4376: return $preferred_possibilities[0];
4377: }
4378:
1.742 raeburn 4379: sub user_lang {
4380: my ($touname,$toudom,$fromcid) = @_;
4381: my @userlangs;
4382: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4383: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4384: $env{'course.'.$fromcid.'.languages'}));
4385: } else {
4386: my %langhash = &getlangs($touname,$toudom);
4387: if ($langhash{'languages'} ne '') {
4388: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4389: } else {
4390: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4391: if ($domdefs{'lang_def'} ne '') {
4392: @userlangs = ($domdefs{'lang_def'});
4393: }
4394: }
4395: }
4396: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4397: my $user_lh = Apache::localize->get_handle(@languages);
4398: return $user_lh;
4399: }
4400:
4401:
1.112 bowersj2 4402: ###############################################################
4403: ## Student Answer Attempts ##
4404: ###############################################################
4405:
4406: =pod
4407:
4408: =head1 Alternate Problem Views
4409:
4410: =over 4
4411:
1.648 raeburn 4412: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4413: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4414:
4415: Return string with previous attempt on problem. Arguments:
4416:
4417: =over 4
4418:
4419: =item * $symb: Problem, including path
4420:
4421: =item * $username: username of the desired student
4422:
4423: =item * $domain: domain of the desired student
1.14 harris41 4424:
1.112 bowersj2 4425: =item * $course: Course ID
1.14 harris41 4426:
1.112 bowersj2 4427: =item * $getattempt: Leave blank for all attempts, otherwise put
4428: something
1.14 harris41 4429:
1.112 bowersj2 4430: =item * $regexp: if string matches this regexp, the string will be
4431: sent to $gradesub
1.14 harris41 4432:
1.112 bowersj2 4433: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4434:
1.1199 raeburn 4435: =item * $usec: section of the desired student
4436:
4437: =item * $identifier: counter for student (multiple students one problem) or
4438: problem (one student; whole sequence).
4439:
1.112 bowersj2 4440: =back
1.14 harris41 4441:
1.112 bowersj2 4442: The output string is a table containing all desired attempts, if any.
1.16 harris41 4443:
1.112 bowersj2 4444: =cut
1.1 albertel 4445:
4446: sub get_previous_attempt {
1.1199 raeburn 4447: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4448: my $prevattempts='';
1.43 ng 4449: no strict 'refs';
1.1 albertel 4450: if ($symb) {
1.3 albertel 4451: my (%returnhash)=
4452: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4453: if ($returnhash{'version'}) {
4454: my %lasthash=();
4455: my $version;
4456: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4457: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4458: if ($key =~ /\.rawrndseed$/) {
4459: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4460: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4461: } else {
4462: $lasthash{$key}=$returnhash{$version.':'.$key};
4463: }
1.19 harris41 4464: }
1.1 albertel 4465: }
1.596 albertel 4466: $prevattempts=&start_data_table().&start_data_table_header_row();
4467: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4468: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4469: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4470: foreach my $key (sort(keys(%lasthash))) {
4471: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4472: if ($#parts > 0) {
1.31 albertel 4473: my $data=$parts[-1];
1.989 raeburn 4474: next if ($data eq 'foilorder');
1.31 albertel 4475: pop(@parts);
1.1010 www 4476: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4477: if ($data eq 'type') {
4478: unless ($showsurv) {
4479: my $id = join(',',@parts);
4480: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4481: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4482: $lasthidden{$ign.'.'.$id} = 1;
4483: }
1.945 raeburn 4484: }
1.1199 raeburn 4485: if ($identifier ne '') {
4486: my $id = join(',',@parts);
4487: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4488: $domain,$username,$usec,undef,$course) =~ /^no/) {
4489: $hidestatus{$ign.'.'.$id} = 1;
4490: }
4491: }
4492: } elsif ($data eq 'regrader') {
4493: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4494: my $id = join(',',@parts);
4495: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4496: }
1.1010 www 4497: }
1.31 albertel 4498: } else {
1.41 ng 4499: if ($#parts == 0) {
4500: $prevattempts.='<th>'.$parts[0].'</th>';
4501: } else {
4502: $prevattempts.='<th>'.$ign.'</th>';
4503: }
1.31 albertel 4504: }
1.16 harris41 4505: }
1.596 albertel 4506: $prevattempts.=&end_data_table_header_row();
1.40 ng 4507: if ($getattempt eq '') {
1.1199 raeburn 4508: my (%solved,%resets,%probstatus);
1.1200 raeburn 4509: if (($identifier ne '') && (keys(%regraded) > 0)) {
4510: for ($version=1;$version<=$returnhash{'version'};$version++) {
4511: foreach my $id (keys(%regraded)) {
4512: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4513: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4514: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4515: push(@{$resets{$id}},$version);
1.1199 raeburn 4516: }
4517: }
4518: }
1.1200 raeburn 4519: }
4520: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4521: my (@hidden,@unsolved);
1.945 raeburn 4522: if (%typeparts) {
4523: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4524: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4525: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4526: push(@hidden,$id);
1.1199 raeburn 4527: } elsif ($identifier ne '') {
4528: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4529: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4530: ($hidestatus{$id})) {
1.1200 raeburn 4531: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4532: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4533: push(@{$solved{$id}},$version);
4534: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4535: (ref($solved{$id}) eq 'ARRAY')) {
4536: my $skip;
4537: if (ref($resets{$id}) eq 'ARRAY') {
4538: foreach my $reset (@{$resets{$id}}) {
4539: if ($reset > $solved{$id}[-1]) {
4540: $skip=1;
4541: last;
4542: }
4543: }
4544: }
4545: unless ($skip) {
4546: my ($ign,$partslist) = split(/\./,$id,2);
4547: push(@unsolved,$partslist);
4548: }
4549: }
4550: }
1.945 raeburn 4551: }
4552: }
4553: }
4554: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4555: '<td>'.&mt('Transaction [_1]',$version);
4556: if (@unsolved) {
4557: $prevattempts .= '<span class="LC_nobreak"><label>'.
4558: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4559: &mt('Hide').'</label></span>';
4560: }
4561: $prevattempts .= '</td>';
1.945 raeburn 4562: if (@hidden) {
4563: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4564: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4565: my $hide;
4566: foreach my $id (@hidden) {
4567: if ($key =~ /^\Q$id\E/) {
4568: $hide = 1;
4569: last;
4570: }
4571: }
4572: if ($hide) {
4573: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4574: if (($data eq 'award') || ($data eq 'awarddetail')) {
4575: my $value = &format_previous_attempt_value($key,
4576: $returnhash{$version.':'.$key});
1.1173 kruse 4577: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4578: } else {
4579: $prevattempts.='<td> </td>';
4580: }
4581: } else {
4582: if ($key =~ /\./) {
1.1212 raeburn 4583: my $value = $returnhash{$version.':'.$key};
4584: if ($key =~ /\.rndseed$/) {
4585: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4586: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4587: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4588: }
4589: }
4590: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4591: ' </td>';
1.945 raeburn 4592: } else {
4593: $prevattempts.='<td> </td>';
4594: }
4595: }
4596: }
4597: } else {
4598: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4599: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4600: my $value = $returnhash{$version.':'.$key};
4601: if ($key =~ /\.rndseed$/) {
4602: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4603: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4604: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4605: }
4606: }
4607: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4608: ' </td>';
1.945 raeburn 4609: }
4610: }
4611: $prevattempts.=&end_data_table_row();
1.40 ng 4612: }
1.1 albertel 4613: }
1.945 raeburn 4614: my @currhidden = keys(%lasthidden);
1.596 albertel 4615: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4616: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4617: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4618: if (%typeparts) {
4619: my $hidden;
4620: foreach my $id (@currhidden) {
4621: if ($key =~ /^\Q$id\E/) {
4622: $hidden = 1;
4623: last;
4624: }
4625: }
4626: if ($hidden) {
4627: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4628: if (($data eq 'award') || ($data eq 'awarddetail')) {
4629: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4630: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4631: $value = &$gradesub($value);
4632: }
1.1173 kruse 4633: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4634: } else {
4635: $prevattempts.='<td> </td>';
4636: }
4637: } else {
4638: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4639: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4640: $value = &$gradesub($value);
4641: }
1.1173 kruse 4642: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4643: }
4644: } else {
4645: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4646: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4647: $value = &$gradesub($value);
4648: }
1.1173 kruse 4649: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4650: }
1.16 harris41 4651: }
1.596 albertel 4652: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4653: } else {
1.1305 raeburn 4654: my $msg;
4655: if ($symb =~ /ext\.tool$/) {
4656: $msg = &mt('No grade passed back.');
4657: } else {
4658: $msg = &mt('Nothing submitted - no attempts.');
4659: }
1.596 albertel 4660: $prevattempts=
4661: &start_data_table().&start_data_table_row().
1.1305 raeburn 4662: '<td>'.$msg.'</td>'.
1.596 albertel 4663: &end_data_table_row().&end_data_table();
1.1 albertel 4664: }
4665: } else {
1.596 albertel 4666: $prevattempts=
4667: &start_data_table().&start_data_table_row().
4668: '<td>'.&mt('No data.').'</td>'.
4669: &end_data_table_row().&end_data_table();
1.1 albertel 4670: }
1.10 albertel 4671: }
4672:
1.581 albertel 4673: sub format_previous_attempt_value {
4674: my ($key,$value) = @_;
1.1011 www 4675: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4676: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4677: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4678: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4679: } elsif ($key =~ /answerstring$/) {
4680: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4681: my @answer = %answers;
4682: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4683: my @anskeys = sort(keys(%answers));
4684: if (@anskeys == 1) {
4685: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4686: if ($answer =~ m{\0}) {
4687: $answer =~ s{\0}{,}g;
1.988 raeburn 4688: }
4689: my $tag_internal_answer_name = 'INTERNAL';
4690: if ($anskeys[0] eq $tag_internal_answer_name) {
4691: $value = $answer;
4692: } else {
4693: $value = $anskeys[0].'='.$answer;
4694: }
4695: } else {
4696: foreach my $ans (@anskeys) {
4697: my $answer = $answers{$ans};
1.1001 raeburn 4698: if ($answer =~ m{\0}) {
4699: $answer =~ s{\0}{,}g;
1.988 raeburn 4700: }
4701: $value .= $ans.'='.$answer.'<br />';;
4702: }
4703: }
1.581 albertel 4704: } else {
1.1173 kruse 4705: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4706: }
4707: return $value;
4708: }
4709:
4710:
1.107 albertel 4711: sub relative_to_absolute {
4712: my ($url,$output)=@_;
4713: my $parser=HTML::TokeParser->new(\$output);
4714: my $token;
4715: my $thisdir=$url;
4716: my @rlinks=();
4717: while ($token=$parser->get_token) {
4718: if ($token->[0] eq 'S') {
4719: if ($token->[1] eq 'a') {
4720: if ($token->[2]->{'href'}) {
4721: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4722: }
4723: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4724: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4725: } elsif ($token->[1] eq 'base') {
4726: $thisdir=$token->[2]->{'href'};
4727: }
4728: }
4729: }
4730: $thisdir=~s-/[^/]*$--;
1.356 albertel 4731: foreach my $link (@rlinks) {
1.726 raeburn 4732: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4733: ($link=~/^\//) ||
4734: ($link=~/^javascript:/i) ||
4735: ($link=~/^mailto:/i) ||
4736: ($link=~/^\#/)) {
4737: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4738: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4739: }
4740: }
4741: # -------------------------------------------------- Deal with Applet codebases
4742: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4743: return $output;
4744: }
4745:
1.112 bowersj2 4746: =pod
4747:
1.648 raeburn 4748: =item * &get_student_view()
1.112 bowersj2 4749:
4750: show a snapshot of what student was looking at
4751:
4752: =cut
4753:
1.10 albertel 4754: sub get_student_view {
1.186 albertel 4755: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4756: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4757: my (%form);
1.10 albertel 4758: my @elements=('symb','courseid','domain','username');
4759: foreach my $element (@elements) {
1.186 albertel 4760: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4761: }
1.186 albertel 4762: if (defined($moreenv)) {
4763: %form=(%form,%{$moreenv});
4764: }
1.236 albertel 4765: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4766: $feedurl=&Apache::lonnet::clutter($feedurl);
1.1306 raeburn 4767: if (($feedurl =~ /ext\.tool$/) && ($target eq 'tex')) {
4768: $feedurl =~ s{^/adm/wrapper}{};
4769: }
1.650 www 4770: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4771: $userview=~s/\<body[^\>]*\>//gi;
4772: $userview=~s/\<\/body\>//gi;
4773: $userview=~s/\<html\>//gi;
4774: $userview=~s/\<\/html\>//gi;
4775: $userview=~s/\<head\>//gi;
4776: $userview=~s/\<\/head\>//gi;
4777: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4778: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4779: if (wantarray) {
4780: return ($userview,$response);
4781: } else {
4782: return $userview;
4783: }
4784: }
4785:
4786: sub get_student_view_with_retries {
4787: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4788:
4789: my $ok = 0; # True if we got a good response.
4790: my $content;
4791: my $response;
4792:
4793: # Try to get the student_view done. within the retries count:
4794:
4795: do {
4796: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4797: $ok = $response->is_success;
4798: if (!$ok) {
4799: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4800: }
4801: $retries--;
4802: } while (!$ok && ($retries > 0));
4803:
4804: if (!$ok) {
4805: $content = ''; # On error return an empty content.
4806: }
1.651 www 4807: if (wantarray) {
4808: return ($content, $response);
4809: } else {
4810: return $content;
4811: }
1.11 albertel 4812: }
4813:
1.112 bowersj2 4814: =pod
4815:
1.648 raeburn 4816: =item * &get_student_answers()
1.112 bowersj2 4817:
4818: show a snapshot of how student was answering problem
4819:
4820: =cut
4821:
1.11 albertel 4822: sub get_student_answers {
1.100 sakharuk 4823: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4824: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4825: my (%moreenv);
1.11 albertel 4826: my @elements=('symb','courseid','domain','username');
4827: foreach my $element (@elements) {
1.186 albertel 4828: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4829: }
1.186 albertel 4830: $moreenv{'grade_target'}='answer';
4831: %moreenv=(%form,%moreenv);
1.497 raeburn 4832: $feedurl = &Apache::lonnet::clutter($feedurl);
4833: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4834: return $userview;
1.1 albertel 4835: }
1.116 albertel 4836:
4837: =pod
4838:
4839: =item * &submlink()
4840:
1.242 albertel 4841: Inputs: $text $uname $udom $symb $target
1.116 albertel 4842:
4843: Returns: A link to grades.pm such as to see the SUBM view of a student
4844:
4845: =cut
4846:
4847: ###############################################
4848: sub submlink {
1.242 albertel 4849: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4850: if (!($uname && $udom)) {
4851: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4852: &Apache::lonnet::whichuser($symb);
1.116 albertel 4853: if (!$symb) { $symb=$cursymb; }
4854: }
1.254 matthew 4855: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4856: $symb=&escape($symb);
1.960 bisitz 4857: if ($target) { $target=" target=\"$target\""; }
4858: return
4859: '<a href="/adm/grades?command=submission'.
4860: '&symb='.$symb.
4861: '&student='.$uname.
4862: '&userdom='.$udom.'"'.
4863: $target.'>'.$text.'</a>';
1.242 albertel 4864: }
4865: ##############################################
4866:
4867: =pod
4868:
4869: =item * &pgrdlink()
4870:
4871: Inputs: $text $uname $udom $symb $target
4872:
4873: Returns: A link to grades.pm such as to see the PGRD view of a student
4874:
4875: =cut
4876:
4877: ###############################################
4878: sub pgrdlink {
4879: my $link=&submlink(@_);
4880: $link=~s/(&command=submission)/$1&showgrading=yes/;
4881: return $link;
4882: }
4883: ##############################################
4884:
4885: =pod
4886:
4887: =item * &pprmlink()
4888:
4889: Inputs: $text $uname $udom $symb $target
4890:
4891: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4892: student and a specific resource
1.242 albertel 4893:
4894: =cut
4895:
4896: ###############################################
4897: sub pprmlink {
4898: my ($text,$uname,$udom,$symb,$target)=@_;
4899: if (!($uname && $udom)) {
4900: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4901: &Apache::lonnet::whichuser($symb);
1.242 albertel 4902: if (!$symb) { $symb=$cursymb; }
4903: }
1.254 matthew 4904: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4905: $symb=&escape($symb);
1.242 albertel 4906: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4907: return '<a href="/adm/parmset?command=set&'.
4908: 'symb='.$symb.'&uname='.$uname.
4909: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4910: }
4911: ##############################################
1.37 matthew 4912:
1.112 bowersj2 4913: =pod
4914:
4915: =back
4916:
4917: =cut
4918:
1.37 matthew 4919: ###############################################
1.51 www 4920:
4921:
4922: sub timehash {
1.687 raeburn 4923: my ($thistime) = @_;
4924: my $timezone = &Apache::lonlocal::gettimezone();
4925: my $dt = DateTime->from_epoch(epoch => $thistime)
4926: ->set_time_zone($timezone);
4927: my $wday = $dt->day_of_week();
4928: if ($wday == 7) { $wday = 0; }
4929: return ( 'second' => $dt->second(),
4930: 'minute' => $dt->minute(),
4931: 'hour' => $dt->hour(),
4932: 'day' => $dt->day_of_month(),
4933: 'month' => $dt->month(),
4934: 'year' => $dt->year(),
4935: 'weekday' => $wday,
4936: 'dayyear' => $dt->day_of_year(),
4937: 'dlsav' => $dt->is_dst() );
1.51 www 4938: }
4939:
1.370 www 4940: sub utc_string {
4941: my ($date)=@_;
1.371 www 4942: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4943: }
4944:
1.51 www 4945: sub maketime {
4946: my %th=@_;
1.687 raeburn 4947: my ($epoch_time,$timezone,$dt);
4948: $timezone = &Apache::lonlocal::gettimezone();
4949: eval {
4950: $dt = DateTime->new( year => $th{'year'},
4951: month => $th{'month'},
4952: day => $th{'day'},
4953: hour => $th{'hour'},
4954: minute => $th{'minute'},
4955: second => $th{'second'},
4956: time_zone => $timezone,
4957: );
4958: };
4959: if (!$@) {
4960: $epoch_time = $dt->epoch;
4961: if ($epoch_time) {
4962: return $epoch_time;
4963: }
4964: }
1.51 www 4965: return POSIX::mktime(
4966: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4967: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4968: }
4969:
4970: #########################################
1.51 www 4971:
4972: sub findallcourses {
1.482 raeburn 4973: my ($roles,$uname,$udom) = @_;
1.355 albertel 4974: my %roles;
4975: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4976: my %courses;
1.51 www 4977: my $now=time;
1.482 raeburn 4978: if (!defined($uname)) {
4979: $uname = $env{'user.name'};
4980: }
4981: if (!defined($udom)) {
4982: $udom = $env{'user.domain'};
4983: }
4984: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4985: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4986: if (!%roles) {
4987: %roles = (
4988: cc => 1,
1.907 raeburn 4989: co => 1,
1.482 raeburn 4990: in => 1,
4991: ep => 1,
4992: ta => 1,
4993: cr => 1,
4994: st => 1,
4995: );
4996: }
4997: foreach my $entry (keys(%roleshash)) {
4998: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4999: if ($trole =~ /^cr/) {
5000: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
5001: } else {
5002: next if (!exists($roles{$trole}));
5003: }
5004: if ($tend) {
5005: next if ($tend < $now);
5006: }
5007: if ($tstart) {
5008: next if ($tstart > $now);
5009: }
1.1058 raeburn 5010: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 5011: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5012: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5013: if ($secpart eq '') {
5014: ($cnum,$role) = split(/_/,$cnumpart);
5015: $sec = 'none';
1.1058 raeburn 5016: $value .= $cnum.'/';
1.482 raeburn 5017: } else {
5018: $cnum = $cnumpart;
5019: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5020: $value .= $cnum.'/'.$sec;
5021: }
5022: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5023: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5024: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5025: }
5026: } else {
5027: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5028: }
1.482 raeburn 5029: }
5030: } else {
5031: foreach my $key (keys(%env)) {
1.483 albertel 5032: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5033: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5034: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5035: next if ($role eq 'ca' || $role eq 'aa');
5036: next if (%roles && !exists($roles{$role}));
5037: my ($starttime,$endtime)=split(/\./,$env{$key});
5038: my $active=1;
5039: if ($starttime) {
5040: if ($now<$starttime) { $active=0; }
5041: }
5042: if ($endtime) {
5043: if ($now>$endtime) { $active=0; }
5044: }
5045: if ($active) {
1.1058 raeburn 5046: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5047: if ($sec eq '') {
5048: $sec = 'none';
1.1058 raeburn 5049: } else {
5050: $value .= $sec;
5051: }
5052: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5053: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5054: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5055: }
5056: } else {
5057: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5058: }
1.474 raeburn 5059: }
5060: }
1.51 www 5061: }
5062: }
1.474 raeburn 5063: return %courses;
1.51 www 5064: }
1.37 matthew 5065:
1.54 www 5066: ###############################################
1.474 raeburn 5067:
5068: sub blockcheck {
1.1189 raeburn 5069: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 5070:
1.1189 raeburn 5071: if (defined($udom) && defined($uname)) {
5072: # If uname and udom are for a course, check for blocks in the course.
5073: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5074: my ($startblock,$endblock,$triggerblock) =
5075: &get_blocks($setters,$activity,$udom,$uname,$url);
5076: return ($startblock,$endblock,$triggerblock);
5077: }
5078: } else {
1.490 raeburn 5079: $udom = $env{'user.domain'};
5080: $uname = $env{'user.name'};
5081: }
5082:
1.502 raeburn 5083: my $startblock = 0;
5084: my $endblock = 0;
1.1062 raeburn 5085: my $triggerblock = '';
1.482 raeburn 5086: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 5087:
1.490 raeburn 5088: # If uname is for a user, and activity is course-specific, i.e.,
5089: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5090:
1.490 raeburn 5091: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5092: $activity eq 'groups' || $activity eq 'printout' ||
5093: $activity eq 'reinit' || $activity eq 'alert') &&
1.1189 raeburn 5094: ($env{'request.course.id'})) {
1.490 raeburn 5095: foreach my $key (keys(%live_courses)) {
5096: if ($key ne $env{'request.course.id'}) {
5097: delete($live_courses{$key});
5098: }
5099: }
5100: }
5101:
5102: my $otheruser = 0;
5103: my %own_courses;
5104: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5105: # Resource belongs to user other than current user.
5106: $otheruser = 1;
5107: # Gather courses for current user
5108: %own_courses =
5109: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5110: }
5111:
5112: # Gather active course roles - course coordinator, instructor,
5113: # exam proctor, ta, student, or custom role.
1.474 raeburn 5114:
5115: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5116: my ($cdom,$cnum);
5117: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5118: $cdom = $env{'course.'.$course.'.domain'};
5119: $cnum = $env{'course.'.$course.'.num'};
5120: } else {
1.490 raeburn 5121: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5122: }
5123: my $no_ownblock = 0;
5124: my $no_userblock = 0;
1.533 raeburn 5125: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5126: # Check if current user has 'evb' priv for this
5127: if (defined($own_courses{$course})) {
5128: foreach my $sec (keys(%{$own_courses{$course}})) {
5129: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5130: if ($sec ne 'none') {
5131: $checkrole .= '/'.$sec;
5132: }
5133: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5134: $no_ownblock = 1;
5135: last;
5136: }
5137: }
5138: }
5139: # if they have 'evb' priv and are currently not playing student
5140: next if (($no_ownblock) &&
5141: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5142: }
1.474 raeburn 5143: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5144: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5145: if ($sec ne 'none') {
1.482 raeburn 5146: $checkrole .= '/'.$sec;
1.474 raeburn 5147: }
1.490 raeburn 5148: if ($otheruser) {
5149: # Resource belongs to user other than current user.
5150: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5151: my (%allroles,%userroles);
5152: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5153: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5154: my ($trole,$tdom,$tnum,$tsec);
5155: if ($entry =~ /^cr/) {
5156: ($trole,$tdom,$tnum,$tsec) =
5157: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5158: } else {
5159: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5160: }
5161: my ($spec,$area,$trest);
5162: $area = '/'.$tdom.'/'.$tnum;
5163: $trest = $tnum;
5164: if ($tsec ne '') {
5165: $area .= '/'.$tsec;
5166: $trest .= '/'.$tsec;
5167: }
5168: $spec = $trole.'.'.$area;
5169: if ($trole =~ /^cr/) {
5170: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5171: $tdom,$spec,$trest,$area);
5172: } else {
5173: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5174: $tdom,$spec,$trest,$area);
5175: }
5176: }
1.1276 raeburn 5177: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5178: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5179: if ($1) {
5180: $no_userblock = 1;
5181: last;
5182: }
1.486 raeburn 5183: }
5184: }
1.490 raeburn 5185: } else {
5186: # Resource belongs to current user
5187: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5188: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5189: $no_ownblock = 1;
5190: last;
5191: }
1.474 raeburn 5192: }
5193: }
5194: # if they have the evb priv and are currently not playing student
1.482 raeburn 5195: next if (($no_ownblock) &&
1.491 albertel 5196: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5197: next if ($no_userblock);
1.474 raeburn 5198:
1.1303 raeburn 5199: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5200: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5201:
1.1062 raeburn 5202: my ($start,$end,$trigger) =
5203: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 5204: if (($start != 0) &&
5205: (($startblock == 0) || ($startblock > $start))) {
5206: $startblock = $start;
1.1062 raeburn 5207: if ($trigger ne '') {
5208: $triggerblock = $trigger;
5209: }
1.502 raeburn 5210: }
5211: if (($end != 0) &&
5212: (($endblock == 0) || ($endblock < $end))) {
5213: $endblock = $end;
1.1062 raeburn 5214: if ($trigger ne '') {
5215: $triggerblock = $trigger;
5216: }
1.502 raeburn 5217: }
1.490 raeburn 5218: }
1.1062 raeburn 5219: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5220: }
5221:
5222: sub get_blocks {
1.1062 raeburn 5223: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 5224: my $startblock = 0;
5225: my $endblock = 0;
1.1062 raeburn 5226: my $triggerblock = '';
1.490 raeburn 5227: my $course = $cdom.'_'.$cnum;
5228: $setters->{$course} = {};
5229: $setters->{$course}{'staff'} = [];
5230: $setters->{$course}{'times'} = [];
1.1062 raeburn 5231: $setters->{$course}{'triggers'} = [];
5232: my (@blockers,%triggered);
5233: my $now = time;
5234: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5235: if ($activity eq 'docs') {
5236: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
5237: foreach my $block (@blockers) {
5238: if ($block =~ /^firstaccess____(.+)$/) {
5239: my $item = $1;
5240: my $type = 'map';
5241: my $timersymb = $item;
5242: if ($item eq 'course') {
5243: $type = 'course';
5244: } elsif ($item =~ /___\d+___/) {
5245: $type = 'resource';
5246: } else {
5247: $timersymb = &Apache::lonnet::symbread($item);
5248: }
5249: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5250: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5251: $triggered{$block} = {
5252: start => $start,
5253: end => $end,
5254: type => $type,
5255: };
5256: }
5257: }
5258: } else {
5259: foreach my $block (keys(%commblocks)) {
5260: if ($block =~ m/^(\d+)____(\d+)$/) {
5261: my ($start,$end) = ($1,$2);
5262: if ($start <= time && $end >= time) {
5263: if (ref($commblocks{$block}) eq 'HASH') {
5264: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5265: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5266: unless(grep(/^\Q$block\E$/,@blockers)) {
5267: push(@blockers,$block);
5268: }
5269: }
5270: }
5271: }
5272: }
5273: } elsif ($block =~ /^firstaccess____(.+)$/) {
5274: my $item = $1;
5275: my $timersymb = $item;
5276: my $type = 'map';
5277: if ($item eq 'course') {
5278: $type = 'course';
5279: } elsif ($item =~ /___\d+___/) {
5280: $type = 'resource';
5281: } else {
5282: $timersymb = &Apache::lonnet::symbread($item);
5283: }
5284: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5285: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5286: if ($start && $end) {
5287: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5288: if (ref($commblocks{$block}) eq 'HASH') {
5289: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5290: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5291: unless(grep(/^\Q$block\E$/,@blockers)) {
5292: push(@blockers,$block);
5293: $triggered{$block} = {
5294: start => $start,
5295: end => $end,
5296: type => $type,
5297: };
5298: }
5299: }
5300: }
1.1062 raeburn 5301: }
5302: }
1.490 raeburn 5303: }
1.1062 raeburn 5304: }
5305: }
5306: }
5307: foreach my $blocker (@blockers) {
5308: my ($staff_name,$staff_dom,$title,$blocks) =
5309: &parse_block_record($commblocks{$blocker});
5310: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5311: my ($start,$end,$triggertype);
5312: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5313: ($start,$end) = ($1,$2);
5314: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5315: $start = $triggered{$blocker}{'start'};
5316: $end = $triggered{$blocker}{'end'};
5317: $triggertype = $triggered{$blocker}{'type'};
5318: }
5319: if ($start) {
5320: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5321: if ($triggertype) {
5322: push(@{$$setters{$course}{'triggers'}},$triggertype);
5323: } else {
5324: push(@{$$setters{$course}{'triggers'}},0);
5325: }
5326: if ( ($startblock == 0) || ($startblock > $start) ) {
5327: $startblock = $start;
5328: if ($triggertype) {
5329: $triggerblock = $blocker;
1.474 raeburn 5330: }
5331: }
1.1062 raeburn 5332: if ( ($endblock == 0) || ($endblock < $end) ) {
5333: $endblock = $end;
5334: if ($triggertype) {
5335: $triggerblock = $blocker;
5336: }
5337: }
1.474 raeburn 5338: }
5339: }
1.1062 raeburn 5340: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5341: }
5342:
5343: sub parse_block_record {
5344: my ($record) = @_;
5345: my ($setuname,$setudom,$title,$blocks);
5346: if (ref($record) eq 'HASH') {
5347: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5348: $title = &unescape($record->{'event'});
5349: $blocks = $record->{'blocks'};
5350: } else {
5351: my @data = split(/:/,$record,3);
5352: if (scalar(@data) eq 2) {
5353: $title = $data[1];
5354: ($setuname,$setudom) = split(/@/,$data[0]);
5355: } else {
5356: ($setuname,$setudom,$title) = @data;
5357: }
5358: $blocks = { 'com' => 'on' };
5359: }
5360: return ($setuname,$setudom,$title,$blocks);
5361: }
5362:
1.854 kalberla 5363: sub blocking_status {
1.1189 raeburn 5364: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 5365: my %setters;
1.890 droeschl 5366:
1.1061 raeburn 5367: # check for active blocking
1.1062 raeburn 5368: my ($startblock,$endblock,$triggerblock) =
1.1189 raeburn 5369: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 5370: my $blocked = 0;
5371: if ($startblock && $endblock) {
5372: $blocked = 1;
5373: }
1.890 droeschl 5374:
1.1061 raeburn 5375: # caller just wants to know whether a block is active
5376: if (!wantarray) { return $blocked; }
5377:
5378: # build a link to a popup window containing the details
5379: my $querystring = "?activity=$activity";
5380: # $uname and $udom decide whose portfolio the user is trying to look at
1.1232 raeburn 5381: if (($activity eq 'port') || ($activity eq 'passwd')) {
5382: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5383: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5384: } elsif ($activity eq 'docs') {
5385: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
5386: }
1.1061 raeburn 5387:
5388: my $output .= <<'END_MYBLOCK';
5389: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5390: var options = "width=" + w + ",height=" + h + ",";
5391: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5392: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5393: var newWin = window.open(url, wdwName, options);
5394: newWin.focus();
5395: }
1.890 droeschl 5396: END_MYBLOCK
1.854 kalberla 5397:
1.1061 raeburn 5398: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5399:
1.1061 raeburn 5400: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5401: my $text = &mt('Communication Blocked');
1.1217 raeburn 5402: my $class = 'LC_comblock';
1.1062 raeburn 5403: if ($activity eq 'docs') {
5404: $text = &mt('Content Access Blocked');
1.1217 raeburn 5405: $class = '';
1.1063 raeburn 5406: } elsif ($activity eq 'printout') {
5407: $text = &mt('Printing Blocked');
1.1232 raeburn 5408: } elsif ($activity eq 'passwd') {
5409: $text = &mt('Password Changing Blocked');
1.1282 raeburn 5410: } elsif ($activity eq 'alert') {
5411: $text = &mt('Checking Critical Messages Blocked');
5412: } elsif ($activity eq 'reinit') {
5413: $text = &mt('Checking Course Update Blocked');
1.1062 raeburn 5414: }
1.1061 raeburn 5415: $output .= <<"END_BLOCK";
1.1217 raeburn 5416: <div class='$class'>
1.869 kalberla 5417: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5418: title='$text'>
5419: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5420: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5421: title='$text'>$text</a>
1.867 kalberla 5422: </div>
5423:
5424: END_BLOCK
1.474 raeburn 5425:
1.1061 raeburn 5426: return ($blocked, $output);
1.854 kalberla 5427: }
1.490 raeburn 5428:
1.60 matthew 5429: ###############################################
5430:
1.682 raeburn 5431: sub check_ip_acc {
1.1201 raeburn 5432: my ($acc,$clientip)=@_;
1.682 raeburn 5433: &Apache::lonxml::debug("acc is $acc");
5434: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5435: return 1;
5436: }
1.1219 raeburn 5437: my $allowed;
1.1252 raeburn 5438: my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682 raeburn 5439:
5440: my $name;
1.1219 raeburn 5441: my %access = (
5442: allowfrom => 1,
5443: denyfrom => 0,
5444: );
5445: my @allows;
5446: my @denies;
5447: foreach my $item (split(',',$acc)) {
5448: $item =~ s/^\s*//;
5449: $item =~ s/\s*$//;
5450: my $pattern;
5451: if ($item =~ /^\!(.+)$/) {
5452: push(@denies,$1);
5453: } else {
5454: push(@allows,$item);
5455: }
5456: }
5457: my $numdenies = scalar(@denies);
5458: my $numallows = scalar(@allows);
5459: my $count = 0;
5460: foreach my $pattern (@denies,@allows) {
5461: $count ++;
5462: my $acctype = 'allowfrom';
5463: if ($count <= $numdenies) {
5464: $acctype = 'denyfrom';
5465: }
1.682 raeburn 5466: if ($pattern =~ /\*$/) {
5467: #35.8.*
5468: $pattern=~s/\*//;
1.1219 raeburn 5469: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5470: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5471: #35.8.3.[34-56]
5472: my $low=$2;
5473: my $high=$3;
5474: $pattern=$1;
5475: if ($ip =~ /^\Q$pattern\E/) {
5476: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5477: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5478: }
5479: } elsif ($pattern =~ /^\*/) {
5480: #*.msu.edu
5481: $pattern=~s/\*//;
5482: if (!defined($name)) {
5483: use Socket;
5484: my $netaddr=inet_aton($ip);
5485: ($name)=gethostbyaddr($netaddr,AF_INET);
5486: }
1.1219 raeburn 5487: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5488: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5489: #127.0.0.1
1.1219 raeburn 5490: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5491: } else {
5492: #some.name.com
5493: if (!defined($name)) {
5494: use Socket;
5495: my $netaddr=inet_aton($ip);
5496: ($name)=gethostbyaddr($netaddr,AF_INET);
5497: }
1.1219 raeburn 5498: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5499: }
5500: if ($allowed =~ /^(0|1)$/) { last; }
5501: }
5502: if ($allowed eq '') {
5503: if ($numdenies && !$numallows) {
5504: $allowed = 1;
5505: } else {
5506: $allowed = 0;
1.682 raeburn 5507: }
5508: }
5509: return $allowed;
5510: }
5511:
5512: ###############################################
5513:
1.60 matthew 5514: =pod
5515:
1.112 bowersj2 5516: =head1 Domain Template Functions
5517:
5518: =over 4
5519:
5520: =item * &determinedomain()
1.60 matthew 5521:
5522: Inputs: $domain (usually will be undef)
5523:
1.63 www 5524: Returns: Determines which domain should be used for designs
1.60 matthew 5525:
5526: =cut
1.54 www 5527:
1.60 matthew 5528: ###############################################
1.63 www 5529: sub determinedomain {
5530: my $domain=shift;
1.531 albertel 5531: if (! $domain) {
1.60 matthew 5532: # Determine domain if we have not been given one
1.893 raeburn 5533: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5534: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5535: if ($env{'request.role.domain'}) {
5536: $domain=$env{'request.role.domain'};
1.60 matthew 5537: }
5538: }
1.63 www 5539: return $domain;
5540: }
5541: ###############################################
1.517 raeburn 5542:
1.518 albertel 5543: sub devalidate_domconfig_cache {
5544: my ($udom)=@_;
5545: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5546: }
5547:
5548: # ---------------------- Get domain configuration for a domain
5549: sub get_domainconf {
5550: my ($udom) = @_;
5551: my $cachetime=1800;
5552: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5553: if (defined($cached)) { return %{$result}; }
5554:
5555: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5556: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5557: my (%designhash,%legacy);
1.518 albertel 5558: if (keys(%domconfig) > 0) {
5559: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5560: if (keys(%{$domconfig{'login'}})) {
5561: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5562: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5563: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5564: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5565: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5566: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5567: if ($key eq 'loginvia') {
5568: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5569: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5570: $designhash{$udom.'.login.loginvia'} = $server;
5571: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5572:
5573: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5574: } else {
5575: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5576: }
1.948 raeburn 5577: }
1.1208 raeburn 5578: } elsif ($key eq 'headtag') {
5579: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5580: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5581: }
1.946 raeburn 5582: }
1.1208 raeburn 5583: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5584: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5585: }
1.946 raeburn 5586: }
5587: }
5588: }
5589: } else {
5590: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5591: $designhash{$udom.'.login.'.$key.'_'.$img} =
5592: $domconfig{'login'}{$key}{$img};
5593: }
1.699 raeburn 5594: }
5595: } else {
5596: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5597: }
1.632 raeburn 5598: }
5599: } else {
5600: $legacy{'login'} = 1;
1.518 albertel 5601: }
1.632 raeburn 5602: } else {
5603: $legacy{'login'} = 1;
1.518 albertel 5604: }
5605: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5606: if (keys(%{$domconfig{'rolecolors'}})) {
5607: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5608: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5609: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5610: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5611: }
1.518 albertel 5612: }
5613: }
1.632 raeburn 5614: } else {
5615: $legacy{'rolecolors'} = 1;
1.518 albertel 5616: }
1.632 raeburn 5617: } else {
5618: $legacy{'rolecolors'} = 1;
1.518 albertel 5619: }
1.948 raeburn 5620: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5621: if ($domconfig{'autoenroll'}{'co-owners'}) {
5622: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5623: }
5624: }
1.632 raeburn 5625: if (keys(%legacy) > 0) {
5626: my %legacyhash = &get_legacy_domconf($udom);
5627: foreach my $item (keys(%legacyhash)) {
5628: if ($item =~ /^\Q$udom\E\.login/) {
5629: if ($legacy{'login'}) {
5630: $designhash{$item} = $legacyhash{$item};
5631: }
5632: } else {
5633: if ($legacy{'rolecolors'}) {
5634: $designhash{$item} = $legacyhash{$item};
5635: }
1.518 albertel 5636: }
5637: }
5638: }
1.632 raeburn 5639: } else {
5640: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5641: }
5642: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5643: $cachetime);
5644: return %designhash;
5645: }
5646:
1.632 raeburn 5647: sub get_legacy_domconf {
5648: my ($udom) = @_;
5649: my %legacyhash;
5650: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5651: my $designfile = $designdir.'/'.$udom.'.tab';
5652: if (-e $designfile) {
1.1317 raeburn 5653: if ( open (my $fh,'<',$designfile) ) {
1.632 raeburn 5654: while (my $line = <$fh>) {
5655: next if ($line =~ /^\#/);
5656: chomp($line);
5657: my ($key,$val)=(split(/\=/,$line));
5658: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5659: }
5660: close($fh);
5661: }
5662: }
1.1026 raeburn 5663: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5664: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5665: }
5666: return %legacyhash;
5667: }
5668:
1.63 www 5669: =pod
5670:
1.112 bowersj2 5671: =item * &domainlogo()
1.63 www 5672:
5673: Inputs: $domain (usually will be undef)
5674:
5675: Returns: A link to a domain logo, if the domain logo exists.
5676: If the domain logo does not exist, a description of the domain.
5677:
5678: =cut
1.112 bowersj2 5679:
1.63 www 5680: ###############################################
5681: sub domainlogo {
1.517 raeburn 5682: my $domain = &determinedomain(shift);
1.518 albertel 5683: my %designhash = &get_domainconf($domain);
1.517 raeburn 5684: # See if there is a logo
5685: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5686: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5687: if ($imgsrc =~ m{^/(adm|res)/}) {
5688: if ($imgsrc =~ m{^/res/}) {
5689: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5690: &Apache::lonnet::repcopy($local_name);
5691: }
5692: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5693: }
5694: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5695: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5696: return &Apache::lonnet::domain($domain,'description');
1.59 www 5697: } else {
1.60 matthew 5698: return '';
1.59 www 5699: }
5700: }
1.63 www 5701: ##############################################
5702:
5703: =pod
5704:
1.112 bowersj2 5705: =item * &designparm()
1.63 www 5706:
5707: Inputs: $which parameter; $domain (usually will be undef)
5708:
5709: Returns: value of designparamter $which
5710:
5711: =cut
1.112 bowersj2 5712:
1.397 albertel 5713:
1.400 albertel 5714: ##############################################
1.397 albertel 5715: sub designparm {
5716: my ($which,$domain)=@_;
5717: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5718: return $env{'environment.color.'.$which};
1.96 www 5719: }
1.63 www 5720: $domain=&determinedomain($domain);
1.1016 raeburn 5721: my %domdesign;
5722: unless ($domain eq 'public') {
5723: %domdesign = &get_domainconf($domain);
5724: }
1.520 raeburn 5725: my $output;
1.517 raeburn 5726: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5727: $output = $domdesign{$domain.'.'.$which};
1.63 www 5728: } else {
1.520 raeburn 5729: $output = $defaultdesign{$which};
5730: }
5731: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5732: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5733: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5734: if ($output =~ m{^/res/}) {
5735: my $local_name = &Apache::lonnet::filelocation('',$output);
5736: &Apache::lonnet::repcopy($local_name);
5737: }
1.520 raeburn 5738: $output = &lonhttpdurl($output);
5739: }
1.63 www 5740: }
1.520 raeburn 5741: return $output;
1.63 www 5742: }
1.59 www 5743:
1.822 bisitz 5744: ##############################################
5745: =pod
5746:
1.832 bisitz 5747: =item * &authorspace()
5748:
1.1028 raeburn 5749: Inputs: $url (usually will be undef).
1.832 bisitz 5750:
1.1132 raeburn 5751: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5752: directory being viewed (or for which action is being taken).
5753: If $url is provided, and begins /priv/<domain>/<uname>
5754: the path will be that portion of the $context argument.
5755: Otherwise the path will be for the author space of the current
5756: user when the current role is author, or for that of the
5757: co-author/assistant co-author space when the current role
5758: is co-author or assistant co-author.
1.832 bisitz 5759:
5760: =cut
5761:
5762: sub authorspace {
1.1028 raeburn 5763: my ($url) = @_;
5764: if ($url ne '') {
5765: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5766: return $1;
5767: }
5768: }
1.832 bisitz 5769: my $caname = '';
1.1024 www 5770: my $cadom = '';
1.1028 raeburn 5771: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5772: ($cadom,$caname) =
1.832 bisitz 5773: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5774: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5775: $caname = $env{'user.name'};
1.1024 www 5776: $cadom = $env{'user.domain'};
1.832 bisitz 5777: }
1.1028 raeburn 5778: if (($caname ne '') && ($cadom ne '')) {
5779: return "/priv/$cadom/$caname/";
5780: }
5781: return;
1.832 bisitz 5782: }
5783:
5784: ##############################################
5785: =pod
5786:
1.822 bisitz 5787: =item * &head_subbox()
5788:
5789: Inputs: $content (contains HTML code with page functions, etc.)
5790:
5791: Returns: HTML div with $content
5792: To be included in page header
5793:
5794: =cut
5795:
5796: sub head_subbox {
5797: my ($content)=@_;
5798: my $output =
1.993 raeburn 5799: '<div class="LC_head_subbox">'
1.822 bisitz 5800: .$content
5801: .'</div>'
5802: }
5803:
5804: ##############################################
5805: =pod
5806:
5807: =item * &CSTR_pageheader()
5808:
1.1026 raeburn 5809: Input: (optional) filename from which breadcrumb trail is built.
5810: In most cases no input as needed, as $env{'request.filename'}
5811: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5812:
5813: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5814: To be included on Authoring Space pages
1.822 bisitz 5815:
5816: =cut
5817:
5818: sub CSTR_pageheader {
1.1026 raeburn 5819: my ($trailfile) = @_;
5820: if ($trailfile eq '') {
5821: $trailfile = $env{'request.filename'};
5822: }
5823:
5824: # this is for resources; directories have customtitle, and crumbs
5825: # and select recent are created in lonpubdir.pm
5826:
5827: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5828: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5829: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5830: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5831: $formaction =~ s{/+}{/}g;
1.822 bisitz 5832:
5833: my $parentpath = '';
5834: my $lastitem = '';
5835: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5836: $parentpath = $1;
5837: $lastitem = $2;
5838: } else {
5839: $lastitem = $thisdisfn;
5840: }
1.921 bisitz 5841:
1.1246 raeburn 5842: my ($crsauthor,$title);
5843: if (($env{'request.course.id'}) &&
5844: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 5845: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 5846: $crsauthor = 1;
5847: $title = &mt('Course Authoring Space');
5848: } else {
5849: $title = &mt('Authoring Space');
5850: }
5851:
1.1314 raeburn 5852: my ($target,$crumbtarget) = (' target="_top"','_top'); #FIXME lonpubdir: target="_parent"
1.1313 raeburn 5853: if (($env{'request.lti.login'}) && ($env{'request.lti.target'} eq 'iframe')) {
1.1314 raeburn 5854: $target = '';
5855: $crumbtarget = '';
1.1313 raeburn 5856: }
5857:
1.921 bisitz 5858: my $output =
1.822 bisitz 5859: '<div>'
5860: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 5861: .'<b>'.$title.'</b> '
1.1314 raeburn 5862: .'<form name="dirs" method="post" action="'.$formaction.'"'.$target.'>'
5863: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,$crumbtarget,'/priv/'.$udom,undef,undef);
1.921 bisitz 5864:
5865: if ($lastitem) {
5866: $output .=
5867: '<span class="LC_filename">'
5868: .$lastitem
5869: .'</span>';
5870: }
1.1245 raeburn 5871:
1.1246 raeburn 5872: if ($crsauthor) {
5873: $output .= '</form>'.&Apache::lonmenu::constspaceform();
5874: } else {
5875: $output .=
5876: '<br />'
1.1314 raeburn 5877: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/',$crumbtarget,'/priv','','+1',1)."</b></tt><br />"
1.1246 raeburn 5878: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5879: .'</form>'
5880: .&Apache::lonmenu::constspaceform();
5881: }
5882: $output .= '</div>';
1.921 bisitz 5883:
5884: return $output;
1.822 bisitz 5885: }
5886:
1.60 matthew 5887: ###############################################
5888: ###############################################
5889:
5890: =pod
5891:
1.112 bowersj2 5892: =back
5893:
1.549 albertel 5894: =head1 HTML Helpers
1.112 bowersj2 5895:
5896: =over 4
5897:
5898: =item * &bodytag()
1.60 matthew 5899:
5900: Returns a uniform header for LON-CAPA web pages.
5901:
5902: Inputs:
5903:
1.112 bowersj2 5904: =over 4
5905:
5906: =item * $title, A title to be displayed on the page.
5907:
5908: =item * $function, the current role (can be undef).
5909:
5910: =item * $addentries, extra parameters for the <body> tag.
5911:
5912: =item * $bodyonly, if defined, only return the <body> tag.
5913:
5914: =item * $domain, if defined, force a given domain.
5915:
5916: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5917: text interface only)
1.60 matthew 5918:
1.814 bisitz 5919: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5920: navigational links
1.317 albertel 5921:
1.338 albertel 5922: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5923:
1.460 albertel 5924: =item * $args, optional argument valid values are
5925: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 5926: use_absolute -> for external resource or syllabus, this will
5927: contain https://<hostname> if server uses
5928: https (as per hosts.tab), but request is for http
5929: hostname -> hostname, from $r->hostname().
1.460 albertel 5930:
1.1096 raeburn 5931: =item * $advtoolsref, optional argument, ref to an array containing
5932: inlineremote items to be added in "Functions" menu below
5933: breadcrumbs.
5934:
1.1316 raeburn 5935: =item * $ltiscope, optional argument, will be one of: resource, map or
5936: course, if LON-CAPA is in LTI Provider context. Value is
5937: the scope of use, i.e., launch was for access to a single, a map
5938: or the entire course.
5939:
5940: =item * $ltiuri, optional argument, if LON-CAPA is in LTI Provider
5941: context, this will contain the URL for the landing item in
5942: the course, after launch from an LTI Consumer
5943:
1.1318 raeburn 5944: =item * $ltimenu, optional argument, if LON-CAPA is in LTI Provider
5945: context, this will contain a reference to hash of items
5946: to be included in the page header and/or inline menu.
5947:
1.112 bowersj2 5948: =back
5949:
1.60 matthew 5950: Returns: A uniform header for LON-CAPA web pages.
5951: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5952: If $bodyonly is undef or zero, an html string containing a <body> tag and
5953: other decorations will be returned.
5954:
5955: =cut
5956:
1.54 www 5957: sub bodytag {
1.831 bisitz 5958: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1318 raeburn 5959: $no_nav_bar,$bgcolor,$args,$advtoolsref,$ltiscope,$ltiuri,$ltimenu)=@_;
1.339 albertel 5960:
1.954 raeburn 5961: my $public;
5962: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5963: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5964: $public = 1;
5965: }
1.460 albertel 5966: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 5967: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 5968: my $hostname = $args->{'hostname'};
1.339 albertel 5969:
1.183 matthew 5970: $function = &get_users_function() if (!$function);
1.339 albertel 5971: my $img = &designparm($function.'.img',$domain);
5972: my $font = &designparm($function.'.font',$domain);
5973: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5974:
1.803 bisitz 5975: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5976: 'bgcolor' => $pgbg,
1.339 albertel 5977: 'text' => $font,
5978: 'alink' => &designparm($function.'.alink',$domain),
5979: 'vlink' => &designparm($function.'.vlink',$domain),
5980: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5981: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5982:
1.63 www 5983: # role and realm
1.1178 raeburn 5984: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5985: if ($realm) {
5986: $realm = '/'.$realm;
5987: }
1.378 raeburn 5988: if ($role eq 'ca') {
1.479 albertel 5989: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5990: $realm = &plainname($rname,$rdom);
1.378 raeburn 5991: }
1.55 www 5992: # realm
1.258 albertel 5993: if ($env{'request.course.id'}) {
1.378 raeburn 5994: if ($env{'request.role'} !~ /^cr/) {
5995: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 5996: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 5997: if ($env{'request.role.desc'}) {
5998: $role = $env{'request.role.desc'};
5999: } else {
6000: $role = &mt('Helpdesk[_1]',' '.$2);
6001: }
1.1257 raeburn 6002: } else {
6003: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 6004: }
1.898 raeburn 6005: if ($env{'request.course.sec'}) {
6006: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
6007: }
1.359 albertel 6008: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 6009: } else {
6010: $role = &Apache::lonnet::plaintext($role);
1.54 www 6011: }
1.433 albertel 6012:
1.359 albertel 6013: if (!$realm) { $realm=' '; }
1.330 albertel 6014:
1.438 albertel 6015: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 6016:
1.101 www 6017: # construct main body tag
1.359 albertel 6018: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 6019: &Apache::lontexconvert::init_math_support();
1.252 albertel 6020:
1.1131 raeburn 6021: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
6022:
1.1130 raeburn 6023: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 6024: return $bodytag;
1.1130 raeburn 6025: }
1.359 albertel 6026:
1.954 raeburn 6027: if ($public) {
1.433 albertel 6028: undef($role);
6029: }
1.1318 raeburn 6030:
6031: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
6032: if (ref($ltimenu) eq 'HASH') {
6033: unless ($ltimenu->{'role'}) {
6034: undef($role);
6035: }
6036: unless ($ltimenu->{'coursetitle'}) {
6037: $realm=' ';
6038: }
6039: }
6040: }
6041:
1.762 bisitz 6042: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6043: #
6044: # Extra info if you are the DC
6045: my $dc_info = '';
6046: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
6047: $env{'course.'.$env{'request.course.id'}.
6048: '.domain'}.'/'})) {
6049: my $cid = $env{'request.course.id'};
1.917 raeburn 6050: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6051: $dc_info =~ s/\s+$//;
1.359 albertel 6052: }
6053:
1.1237 raeburn 6054: my $crstype;
6055: if ($env{'request.course.id'}) {
6056: $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
6057: } elsif ($args->{'crstype'}) {
6058: $crstype = $args->{'crstype'};
6059: }
6060: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
6061: undef($role);
6062: } else {
1.1242 raeburn 6063: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 6064: }
1.853 droeschl 6065:
1.903 droeschl 6066: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6067:
6068: # if ($env{'request.state'} eq 'construct') {
6069: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6070: # }
6071:
1.1130 raeburn 6072: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 6073: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6074:
1.1318 raeburn 6075: unless ($args->{'no_primary_menu'}) {
6076: my ($left,$right) = Apache::lonmenu::primary_menu($crstype,$ltimenu);
1.359 albertel 6077:
1.1318 raeburn 6078: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
6079: if ($dc_info) {
6080: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6081: }
6082: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
6083: <em>$realm</em> $dc_info</div>|;
6084: return $bodytag;
6085: }
1.894 droeschl 6086:
1.1318 raeburn 6087: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
6088: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
6089: }
1.916 droeschl 6090:
1.1318 raeburn 6091: $bodytag .= $right;
1.852 droeschl 6092:
1.1318 raeburn 6093: if ($dc_info) {
6094: $dc_info = &dc_courseid_toggle($dc_info);
6095: }
6096: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.917 raeburn 6097: }
1.916 droeschl 6098:
1.1169 raeburn 6099: #if directed to not display the secondary menu, don't.
1.1168 raeburn 6100: if ($args->{'no_secondary_menu'}) {
6101: return $bodytag;
6102: }
1.1169 raeburn 6103: #don't show menus for public users
1.954 raeburn 6104: if (!$public){
1.1318 raeburn 6105: unless ($args->{'no_inline_menu'}) {
6106: $bodytag .= Apache::lonmenu::secondary_menu($httphost,$ltiscope,$ltimenu,
6107: $args->{'no_primary_menu'});
6108: }
1.903 droeschl 6109: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6110: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6111: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6112: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1316 raeburn 6113: $args->{'bread_crumbs'},'','',$hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6114: } elsif ($forcereg) {
6115: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 raeburn 6116: $args->{'group'},
1.1274 raeburn 6117: $args->{'hide_buttons'},
1.1316 raeburn 6118: $hostname,$ltiscope,$ltiuri);
1.1096 raeburn 6119: } else {
6120: $bodytag .=
6121: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6122: $forcereg,$args->{'group'},
6123: $args->{'bread_crumbs'},
1.1274 raeburn 6124: $advtoolsref,'',$hostname);
1.920 raeburn 6125: }
1.903 droeschl 6126: }else{
6127: # this is to seperate menu from content when there's no secondary
6128: # menu. Especially needed for public accessible ressources.
6129: $bodytag .= '<hr style="clear:both" />';
6130: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6131: }
1.903 droeschl 6132:
1.235 raeburn 6133: return $bodytag;
1.182 matthew 6134: }
6135:
1.917 raeburn 6136: sub dc_courseid_toggle {
6137: my ($dc_info) = @_;
1.980 raeburn 6138: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6139: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6140: &mt('(More ...)').'</a></span>'.
6141: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6142: }
6143:
1.330 albertel 6144: sub make_attr_string {
6145: my ($register,$attr_ref) = @_;
6146:
6147: if ($attr_ref && !ref($attr_ref)) {
6148: die("addentries Must be a hash ref ".
6149: join(':',caller(1))." ".
6150: join(':',caller(0))." ");
6151: }
6152:
6153: if ($register) {
1.339 albertel 6154: my ($on_load,$on_unload);
6155: foreach my $key (keys(%{$attr_ref})) {
6156: if (lc($key) eq 'onload') {
6157: $on_load.=$attr_ref->{$key}.';';
6158: delete($attr_ref->{$key});
6159:
6160: } elsif (lc($key) eq 'onunload') {
6161: $on_unload.=$attr_ref->{$key}.';';
6162: delete($attr_ref->{$key});
6163: }
6164: }
1.953 droeschl 6165: $attr_ref->{'onload'} = $on_load;
6166: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6167: }
1.339 albertel 6168:
1.330 albertel 6169: my $attr_string;
1.1159 raeburn 6170: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6171: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6172: }
6173: return $attr_string;
6174: }
6175:
6176:
1.182 matthew 6177: ###############################################
1.251 albertel 6178: ###############################################
6179:
6180: =pod
6181:
6182: =item * &endbodytag()
6183:
6184: Returns a uniform footer for LON-CAPA web pages.
6185:
1.635 raeburn 6186: Inputs: 1 - optional reference to an args hash
6187: If in the hash, key for noredirectlink has a value which evaluates to true,
6188: a 'Continue' link is not displayed if the page contains an
6189: internal redirect in the <head></head> section,
6190: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6191:
6192: =cut
6193:
6194: sub endbodytag {
1.635 raeburn 6195: my ($args) = @_;
1.1080 raeburn 6196: my $endbodytag;
6197: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6198: $endbodytag='</body>';
6199: }
1.315 albertel 6200: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6201: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6202: $endbodytag=
6203: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6204: &mt('Continue').'</a>'.
6205: $endbodytag;
6206: }
1.315 albertel 6207: }
1.251 albertel 6208: return $endbodytag;
6209: }
6210:
1.352 albertel 6211: =pod
6212:
6213: =item * &standard_css()
6214:
6215: Returns a style sheet
6216:
6217: Inputs: (all optional)
6218: domain -> force to color decorate a page for a specific
6219: domain
6220: function -> force usage of a specific rolish color scheme
6221: bgcolor -> override the default page bgcolor
6222:
6223: =cut
6224:
1.343 albertel 6225: sub standard_css {
1.345 albertel 6226: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6227: $function = &get_users_function() if (!$function);
6228: my $img = &designparm($function.'.img', $domain);
6229: my $tabbg = &designparm($function.'.tabbg', $domain);
6230: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6231: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6232: #second colour for later usage
1.345 albertel 6233: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6234: my $pgbg_or_bgcolor =
6235: $bgcolor ||
1.352 albertel 6236: &designparm($function.'.pgbg', $domain);
1.382 albertel 6237: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6238: my $alink = &designparm($function.'.alink', $domain);
6239: my $vlink = &designparm($function.'.vlink', $domain);
6240: my $link = &designparm($function.'.link', $domain);
6241:
1.602 albertel 6242: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6243: my $mono = 'monospace';
1.850 bisitz 6244: my $data_table_head = $sidebg;
6245: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6246: my $data_table_dark = '#E0E0E0';
1.470 banghart 6247: my $data_table_darker = '#CCCCCC';
1.349 albertel 6248: my $data_table_highlight = '#FFFF00';
1.352 albertel 6249: my $mail_new = '#FFBB77';
6250: my $mail_new_hover = '#DD9955';
6251: my $mail_read = '#BBBB77';
6252: my $mail_read_hover = '#999944';
6253: my $mail_replied = '#AAAA88';
6254: my $mail_replied_hover = '#888855';
6255: my $mail_other = '#99BBBB';
6256: my $mail_other_hover = '#669999';
1.391 albertel 6257: my $table_header = '#DDDDDD';
1.489 raeburn 6258: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6259: my $lg_border_color = '#C8C8C8';
1.952 onken 6260: my $button_hover = '#BF2317';
1.392 albertel 6261:
1.608 albertel 6262: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6263: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6264: : '0 3px 0 4px';
1.448 albertel 6265:
1.523 albertel 6266:
1.343 albertel 6267: return <<END;
1.947 droeschl 6268:
6269: /* needed for iframe to allow 100% height in FF */
6270: body, html {
6271: margin: 0;
6272: padding: 0 0.5%;
6273: height: 99%; /* to avoid scrollbars */
6274: }
6275:
1.795 www 6276: body {
1.911 bisitz 6277: font-family: $sans;
6278: line-height:130%;
6279: font-size:0.83em;
6280: color:$font;
1.795 www 6281: }
6282:
1.959 onken 6283: a:focus,
6284: a:focus img {
1.795 www 6285: color: red;
6286: }
1.698 harmsja 6287:
1.911 bisitz 6288: form, .inline {
6289: display: inline;
1.795 www 6290: }
1.721 harmsja 6291:
1.795 www 6292: .LC_right {
1.911 bisitz 6293: text-align:right;
1.795 www 6294: }
6295:
6296: .LC_middle {
1.911 bisitz 6297: vertical-align:middle;
1.795 www 6298: }
1.721 harmsja 6299:
1.1130 raeburn 6300: .LC_floatleft {
6301: float: left;
6302: }
6303:
6304: .LC_floatright {
6305: float: right;
6306: }
6307:
1.911 bisitz 6308: .LC_400Box {
6309: width:400px;
6310: }
1.721 harmsja 6311:
1.947 droeschl 6312: .LC_iframecontainer {
6313: width: 98%;
6314: margin: 0;
6315: position: fixed;
6316: top: 8.5em;
6317: bottom: 0;
6318: }
6319:
6320: .LC_iframecontainer iframe{
6321: border: none;
6322: width: 100%;
6323: height: 100%;
6324: }
6325:
1.778 bisitz 6326: .LC_filename {
6327: font-family: $mono;
6328: white-space:pre;
1.921 bisitz 6329: font-size: 120%;
1.778 bisitz 6330: }
6331:
6332: .LC_fileicon {
6333: border: none;
6334: height: 1.3em;
6335: vertical-align: text-bottom;
6336: margin-right: 0.3em;
6337: text-decoration:none;
6338: }
6339:
1.1008 www 6340: .LC_setting {
6341: text-decoration:underline;
6342: }
6343:
1.350 albertel 6344: .LC_error {
6345: color: red;
6346: }
1.795 www 6347:
1.1097 bisitz 6348: .LC_warning {
6349: color: darkorange;
6350: }
6351:
1.457 albertel 6352: .LC_diff_removed {
1.733 bisitz 6353: color: red;
1.394 albertel 6354: }
1.532 albertel 6355:
6356: .LC_info,
1.457 albertel 6357: .LC_success,
6358: .LC_diff_added {
1.350 albertel 6359: color: green;
6360: }
1.795 www 6361:
1.802 bisitz 6362: div.LC_confirm_box {
6363: background-color: #FAFAFA;
6364: border: 1px solid $lg_border_color;
6365: margin-right: 0;
6366: padding: 5px;
6367: }
6368:
6369: div.LC_confirm_box .LC_error img,
6370: div.LC_confirm_box .LC_success img {
6371: vertical-align: middle;
6372: }
6373:
1.1242 raeburn 6374: .LC_maxwidth {
6375: max-width: 100%;
6376: height: auto;
6377: }
6378:
1.1243 raeburn 6379: .LC_textsize_mobile {
6380: \@media only screen and (max-device-width: 480px) {
6381: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6382: }
6383: }
6384:
1.440 albertel 6385: .LC_icon {
1.771 droeschl 6386: border: none;
1.790 droeschl 6387: vertical-align: middle;
1.771 droeschl 6388: }
6389:
1.543 albertel 6390: .LC_docs_spacer {
6391: width: 25px;
6392: height: 1px;
1.771 droeschl 6393: border: none;
1.543 albertel 6394: }
1.346 albertel 6395:
1.532 albertel 6396: .LC_internal_info {
1.735 bisitz 6397: color: #999999;
1.532 albertel 6398: }
6399:
1.794 www 6400: .LC_discussion {
1.1050 www 6401: background: $data_table_dark;
1.911 bisitz 6402: border: 1px solid black;
6403: margin: 2px;
1.794 www 6404: }
6405:
6406: .LC_disc_action_left {
1.1050 www 6407: background: $sidebg;
1.911 bisitz 6408: text-align: left;
1.1050 www 6409: padding: 4px;
6410: margin: 2px;
1.794 www 6411: }
6412:
6413: .LC_disc_action_right {
1.1050 www 6414: background: $sidebg;
1.911 bisitz 6415: text-align: right;
1.1050 www 6416: padding: 4px;
6417: margin: 2px;
1.794 www 6418: }
6419:
6420: .LC_disc_new_item {
1.911 bisitz 6421: background: white;
6422: border: 2px solid red;
1.1050 www 6423: margin: 4px;
6424: padding: 4px;
1.794 www 6425: }
6426:
6427: .LC_disc_old_item {
1.911 bisitz 6428: background: white;
1.1050 www 6429: margin: 4px;
6430: padding: 4px;
1.794 www 6431: }
6432:
1.458 albertel 6433: table.LC_pastsubmission {
6434: border: 1px solid black;
6435: margin: 2px;
6436: }
6437:
1.924 bisitz 6438: table#LC_menubuttons {
1.345 albertel 6439: width: 100%;
6440: background: $pgbg;
1.392 albertel 6441: border: 2px;
1.402 albertel 6442: border-collapse: separate;
1.803 bisitz 6443: padding: 0;
1.345 albertel 6444: }
1.392 albertel 6445:
1.801 tempelho 6446: table#LC_title_bar a {
6447: color: $fontmenu;
6448: }
1.836 bisitz 6449:
1.807 droeschl 6450: table#LC_title_bar {
1.819 tempelho 6451: clear: both;
1.836 bisitz 6452: display: none;
1.807 droeschl 6453: }
6454:
1.795 www 6455: table#LC_title_bar,
1.933 droeschl 6456: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6457: table#LC_title_bar.LC_with_remote {
1.359 albertel 6458: width: 100%;
1.392 albertel 6459: border-color: $pgbg;
6460: border-style: solid;
6461: border-width: $border;
1.379 albertel 6462: background: $pgbg;
1.801 tempelho 6463: color: $fontmenu;
1.392 albertel 6464: border-collapse: collapse;
1.803 bisitz 6465: padding: 0;
1.819 tempelho 6466: margin: 0;
1.359 albertel 6467: }
1.795 www 6468:
1.933 droeschl 6469: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6470: margin: 0;
6471: padding: 0;
1.933 droeschl 6472: position: relative;
6473: list-style: none;
1.913 droeschl 6474: }
1.933 droeschl 6475: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6476: display: inline;
6477: }
1.933 droeschl 6478:
6479: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6480: padding: 0;
1.933 droeschl 6481: margin: 0;
6482: float: left;
1.913 droeschl 6483: }
1.933 droeschl 6484: .LC_breadcrumb_tools_tools {
6485: padding: 0;
6486: margin: 0;
1.913 droeschl 6487: float: right;
6488: }
6489:
1.1240 raeburn 6490: .LC_placement_prog {
6491: padding-right: 20px;
6492: font-weight: bold;
6493: font-size: 90%;
6494: }
6495:
1.359 albertel 6496: table#LC_title_bar td {
6497: background: $tabbg;
6498: }
1.795 www 6499:
1.911 bisitz 6500: table#LC_menubuttons img {
1.803 bisitz 6501: border: none;
1.346 albertel 6502: }
1.795 www 6503:
1.842 droeschl 6504: .LC_breadcrumbs_component {
1.911 bisitz 6505: float: right;
6506: margin: 0 1em;
1.357 albertel 6507: }
1.842 droeschl 6508: .LC_breadcrumbs_component img {
1.911 bisitz 6509: vertical-align: middle;
1.777 tempelho 6510: }
1.795 www 6511:
1.1243 raeburn 6512: .LC_breadcrumbs_hoverable {
6513: background: $sidebg;
6514: }
6515:
1.383 albertel 6516: td.LC_table_cell_checkbox {
6517: text-align: center;
6518: }
1.795 www 6519:
6520: .LC_fontsize_small {
1.911 bisitz 6521: font-size: 70%;
1.705 tempelho 6522: }
6523:
1.844 bisitz 6524: #LC_breadcrumbs {
1.911 bisitz 6525: clear:both;
6526: background: $sidebg;
6527: border-bottom: 1px solid $lg_border_color;
6528: line-height: 2.5em;
1.933 droeschl 6529: overflow: hidden;
1.911 bisitz 6530: margin: 0;
6531: padding: 0;
1.995 raeburn 6532: text-align: left;
1.819 tempelho 6533: }
1.862 bisitz 6534:
1.1098 bisitz 6535: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6536: clear:both;
6537: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6538: border: 1px solid $sidebg;
1.1098 bisitz 6539: margin: 0 0 10px 0;
1.966 bisitz 6540: padding: 3px;
1.995 raeburn 6541: text-align: left;
1.822 bisitz 6542: }
6543:
1.795 www 6544: .LC_fontsize_medium {
1.911 bisitz 6545: font-size: 85%;
1.705 tempelho 6546: }
6547:
1.795 www 6548: .LC_fontsize_large {
1.911 bisitz 6549: font-size: 120%;
1.705 tempelho 6550: }
6551:
1.346 albertel 6552: .LC_menubuttons_inline_text {
6553: color: $font;
1.698 harmsja 6554: font-size: 90%;
1.701 harmsja 6555: padding-left:3px;
1.346 albertel 6556: }
6557:
1.934 droeschl 6558: .LC_menubuttons_inline_text img{
6559: vertical-align: middle;
6560: }
6561:
1.1051 www 6562: li.LC_menubuttons_inline_text img {
1.951 onken 6563: cursor:pointer;
1.1002 droeschl 6564: text-decoration: none;
1.951 onken 6565: }
6566:
1.526 www 6567: .LC_menubuttons_link {
6568: text-decoration: none;
6569: }
1.795 www 6570:
1.522 albertel 6571: .LC_menubuttons_category {
1.521 www 6572: color: $font;
1.526 www 6573: background: $pgbg;
1.521 www 6574: font-size: larger;
6575: font-weight: bold;
6576: }
6577:
1.346 albertel 6578: td.LC_menubuttons_text {
1.911 bisitz 6579: color: $font;
1.346 albertel 6580: }
1.706 harmsja 6581:
1.346 albertel 6582: .LC_current_location {
6583: background: $tabbg;
6584: }
1.795 www 6585:
1.1286 raeburn 6586: td.LC_zero_height {
6587: line-height: 0;
6588: cellpadding: 0;
6589: }
6590:
1.938 bisitz 6591: table.LC_data_table {
1.347 albertel 6592: border: 1px solid #000000;
1.402 albertel 6593: border-collapse: separate;
1.426 albertel 6594: border-spacing: 1px;
1.610 albertel 6595: background: $pgbg;
1.347 albertel 6596: }
1.795 www 6597:
1.422 albertel 6598: .LC_data_table_dense {
6599: font-size: small;
6600: }
1.795 www 6601:
1.507 raeburn 6602: table.LC_nested_outer {
6603: border: 1px solid #000000;
1.589 raeburn 6604: border-collapse: collapse;
1.803 bisitz 6605: border-spacing: 0;
1.507 raeburn 6606: width: 100%;
6607: }
1.795 www 6608:
1.879 raeburn 6609: table.LC_innerpickbox,
1.507 raeburn 6610: table.LC_nested {
1.803 bisitz 6611: border: none;
1.589 raeburn 6612: border-collapse: collapse;
1.803 bisitz 6613: border-spacing: 0;
1.507 raeburn 6614: width: 100%;
6615: }
1.795 www 6616:
1.911 bisitz 6617: table.LC_data_table tr th,
6618: table.LC_calendar tr th,
1.879 raeburn 6619: table.LC_prior_tries tr th,
6620: table.LC_innerpickbox tr th {
1.349 albertel 6621: font-weight: bold;
6622: background-color: $data_table_head;
1.801 tempelho 6623: color:$fontmenu;
1.701 harmsja 6624: font-size:90%;
1.347 albertel 6625: }
1.795 www 6626:
1.879 raeburn 6627: table.LC_innerpickbox tr th,
6628: table.LC_innerpickbox tr td {
6629: vertical-align: top;
6630: }
6631:
1.711 raeburn 6632: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6633: background-color: #CCCCCC;
1.711 raeburn 6634: font-weight: bold;
6635: text-align: left;
6636: }
1.795 www 6637:
1.912 bisitz 6638: table.LC_data_table tr.LC_odd_row > td {
6639: background-color: $data_table_light;
6640: padding: 2px;
6641: vertical-align: top;
6642: }
6643:
1.809 bisitz 6644: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6645: background-color: $data_table_light;
1.912 bisitz 6646: vertical-align: top;
6647: }
6648:
6649: table.LC_data_table tr.LC_even_row > td {
6650: background-color: $data_table_dark;
1.425 albertel 6651: padding: 2px;
1.900 bisitz 6652: vertical-align: top;
1.347 albertel 6653: }
1.795 www 6654:
1.809 bisitz 6655: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6656: background-color: $data_table_dark;
1.900 bisitz 6657: vertical-align: top;
1.347 albertel 6658: }
1.795 www 6659:
1.425 albertel 6660: table.LC_data_table tr.LC_data_table_highlight td {
6661: background-color: $data_table_darker;
6662: }
1.795 www 6663:
1.639 raeburn 6664: table.LC_data_table tr td.LC_leftcol_header {
6665: background-color: $data_table_head;
6666: font-weight: bold;
6667: }
1.795 www 6668:
1.451 albertel 6669: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6670: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6671: font-weight: bold;
6672: font-style: italic;
6673: text-align: center;
6674: padding: 8px;
1.347 albertel 6675: }
1.795 www 6676:
1.1114 raeburn 6677: table.LC_data_table tr.LC_empty_row td,
6678: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6679: background-color: $sidebg;
6680: }
6681:
6682: table.LC_nested tr.LC_empty_row td {
6683: background-color: #FFFFFF;
6684: }
6685:
1.890 droeschl 6686: table.LC_caption {
6687: }
6688:
1.507 raeburn 6689: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6690: padding: 4ex
6691: }
1.795 www 6692:
1.507 raeburn 6693: table.LC_nested_outer tr th {
6694: font-weight: bold;
1.801 tempelho 6695: color:$fontmenu;
1.507 raeburn 6696: background-color: $data_table_head;
1.701 harmsja 6697: font-size: small;
1.507 raeburn 6698: border-bottom: 1px solid #000000;
6699: }
1.795 www 6700:
1.507 raeburn 6701: table.LC_nested_outer tr td.LC_subheader {
6702: background-color: $data_table_head;
6703: font-weight: bold;
6704: font-size: small;
6705: border-bottom: 1px solid #000000;
6706: text-align: right;
1.451 albertel 6707: }
1.795 www 6708:
1.507 raeburn 6709: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6710: background-color: #CCCCCC;
1.451 albertel 6711: font-weight: bold;
6712: font-size: small;
1.507 raeburn 6713: text-align: center;
6714: }
1.795 www 6715:
1.589 raeburn 6716: table.LC_nested tr.LC_info_row td.LC_left_item,
6717: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6718: text-align: left;
1.451 albertel 6719: }
1.795 www 6720:
1.507 raeburn 6721: table.LC_nested td {
1.735 bisitz 6722: background-color: #FFFFFF;
1.451 albertel 6723: font-size: small;
1.507 raeburn 6724: }
1.795 www 6725:
1.507 raeburn 6726: table.LC_nested_outer tr th.LC_right_item,
6727: table.LC_nested tr.LC_info_row td.LC_right_item,
6728: table.LC_nested tr.LC_odd_row td.LC_right_item,
6729: table.LC_nested tr td.LC_right_item {
1.451 albertel 6730: text-align: right;
6731: }
6732:
1.507 raeburn 6733: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6734: background-color: #EEEEEE;
1.451 albertel 6735: }
6736:
1.473 raeburn 6737: table.LC_createuser {
6738: }
6739:
6740: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6741: font-size: small;
1.473 raeburn 6742: }
6743:
6744: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6745: background-color: #CCCCCC;
1.473 raeburn 6746: font-weight: bold;
6747: text-align: center;
6748: }
6749:
1.349 albertel 6750: table.LC_calendar {
6751: border: 1px solid #000000;
6752: border-collapse: collapse;
1.917 raeburn 6753: width: 98%;
1.349 albertel 6754: }
1.795 www 6755:
1.349 albertel 6756: table.LC_calendar_pickdate {
6757: font-size: xx-small;
6758: }
1.795 www 6759:
1.349 albertel 6760: table.LC_calendar tr td {
6761: border: 1px solid #000000;
6762: vertical-align: top;
1.917 raeburn 6763: width: 14%;
1.349 albertel 6764: }
1.795 www 6765:
1.349 albertel 6766: table.LC_calendar tr td.LC_calendar_day_empty {
6767: background-color: $data_table_dark;
6768: }
1.795 www 6769:
1.779 bisitz 6770: table.LC_calendar tr td.LC_calendar_day_current {
6771: background-color: $data_table_highlight;
1.777 tempelho 6772: }
1.795 www 6773:
1.938 bisitz 6774: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6775: background-color: $mail_new;
6776: }
1.795 www 6777:
1.938 bisitz 6778: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6779: background-color: $mail_new_hover;
6780: }
1.795 www 6781:
1.938 bisitz 6782: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6783: background-color: $mail_read;
6784: }
1.795 www 6785:
1.938 bisitz 6786: /*
6787: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6788: background-color: $mail_read_hover;
6789: }
1.938 bisitz 6790: */
1.795 www 6791:
1.938 bisitz 6792: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6793: background-color: $mail_replied;
6794: }
1.795 www 6795:
1.938 bisitz 6796: /*
6797: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6798: background-color: $mail_replied_hover;
6799: }
1.938 bisitz 6800: */
1.795 www 6801:
1.938 bisitz 6802: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6803: background-color: $mail_other;
6804: }
1.795 www 6805:
1.938 bisitz 6806: /*
6807: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6808: background-color: $mail_other_hover;
6809: }
1.938 bisitz 6810: */
1.494 raeburn 6811:
1.777 tempelho 6812: table.LC_data_table tr > td.LC_browser_file,
6813: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6814: background: #AAEE77;
1.389 albertel 6815: }
1.795 www 6816:
1.777 tempelho 6817: table.LC_data_table tr > td.LC_browser_file_locked,
6818: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6819: background: #FFAA99;
1.387 albertel 6820: }
1.795 www 6821:
1.777 tempelho 6822: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6823: background: #888888;
1.779 bisitz 6824: }
1.795 www 6825:
1.777 tempelho 6826: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6827: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6828: background: #F8F866;
1.777 tempelho 6829: }
1.795 www 6830:
1.696 bisitz 6831: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6832: background: #E0E8FF;
1.387 albertel 6833: }
1.696 bisitz 6834:
1.707 bisitz 6835: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6836: /* background: #77FF77; */
1.707 bisitz 6837: }
1.795 www 6838:
1.707 bisitz 6839: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6840: border-right: 8px solid #FFFF77;
1.707 bisitz 6841: }
1.795 www 6842:
1.707 bisitz 6843: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6844: border-right: 8px solid #FFAA77;
1.707 bisitz 6845: }
1.795 www 6846:
1.707 bisitz 6847: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6848: border-right: 8px solid #FF7777;
1.707 bisitz 6849: }
1.795 www 6850:
1.707 bisitz 6851: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6852: border-right: 8px solid #AAFF77;
1.707 bisitz 6853: }
1.795 www 6854:
1.707 bisitz 6855: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6856: border-right: 8px solid #11CC55;
1.707 bisitz 6857: }
6858:
1.388 albertel 6859: span.LC_current_location {
1.701 harmsja 6860: font-size:larger;
1.388 albertel 6861: background: $pgbg;
6862: }
1.387 albertel 6863:
1.1029 www 6864: span.LC_current_nav_location {
6865: font-weight:bold;
6866: background: $sidebg;
6867: }
6868:
1.395 albertel 6869: span.LC_parm_menu_item {
6870: font-size: larger;
6871: }
1.795 www 6872:
1.395 albertel 6873: span.LC_parm_scope_all {
6874: color: red;
6875: }
1.795 www 6876:
1.395 albertel 6877: span.LC_parm_scope_folder {
6878: color: green;
6879: }
1.795 www 6880:
1.395 albertel 6881: span.LC_parm_scope_resource {
6882: color: orange;
6883: }
1.795 www 6884:
1.395 albertel 6885: span.LC_parm_part {
6886: color: blue;
6887: }
1.795 www 6888:
1.911 bisitz 6889: span.LC_parm_folder,
6890: span.LC_parm_symb {
1.395 albertel 6891: font-size: x-small;
6892: font-family: $mono;
6893: color: #AAAAAA;
6894: }
6895:
1.977 bisitz 6896: ul.LC_parm_parmlist li {
6897: display: inline-block;
6898: padding: 0.3em 0.8em;
6899: vertical-align: top;
6900: width: 150px;
6901: border-top:1px solid $lg_border_color;
6902: }
6903:
1.795 www 6904: td.LC_parm_overview_level_menu,
6905: td.LC_parm_overview_map_menu,
6906: td.LC_parm_overview_parm_selectors,
6907: td.LC_parm_overview_restrictions {
1.396 albertel 6908: border: 1px solid black;
6909: border-collapse: collapse;
6910: }
1.795 www 6911:
1.1285 raeburn 6912: span.LC_parm_recursive,
6913: td.LC_parm_recursive {
6914: font-weight: bold;
6915: font-size: smaller;
6916: }
6917:
1.396 albertel 6918: table.LC_parm_overview_restrictions td {
6919: border-width: 1px 4px 1px 4px;
6920: border-style: solid;
6921: border-color: $pgbg;
6922: text-align: center;
6923: }
1.795 www 6924:
1.396 albertel 6925: table.LC_parm_overview_restrictions th {
6926: background: $tabbg;
6927: border-width: 1px 4px 1px 4px;
6928: border-style: solid;
6929: border-color: $pgbg;
6930: }
1.795 www 6931:
1.398 albertel 6932: table#LC_helpmenu {
1.803 bisitz 6933: border: none;
1.398 albertel 6934: height: 55px;
1.803 bisitz 6935: border-spacing: 0;
1.398 albertel 6936: }
6937:
6938: table#LC_helpmenu fieldset legend {
6939: font-size: larger;
6940: }
1.795 www 6941:
1.397 albertel 6942: table#LC_helpmenu_links {
6943: width: 100%;
6944: border: 1px solid black;
6945: background: $pgbg;
1.803 bisitz 6946: padding: 0;
1.397 albertel 6947: border-spacing: 1px;
6948: }
1.795 www 6949:
1.397 albertel 6950: table#LC_helpmenu_links tr td {
6951: padding: 1px;
6952: background: $tabbg;
1.399 albertel 6953: text-align: center;
6954: font-weight: bold;
1.397 albertel 6955: }
1.396 albertel 6956:
1.795 www 6957: table#LC_helpmenu_links a:link,
6958: table#LC_helpmenu_links a:visited,
1.397 albertel 6959: table#LC_helpmenu_links a:active {
6960: text-decoration: none;
6961: color: $font;
6962: }
1.795 www 6963:
1.397 albertel 6964: table#LC_helpmenu_links a:hover {
6965: text-decoration: underline;
6966: color: $vlink;
6967: }
1.396 albertel 6968:
1.417 albertel 6969: .LC_chrt_popup_exists {
6970: border: 1px solid #339933;
6971: margin: -1px;
6972: }
1.795 www 6973:
1.417 albertel 6974: .LC_chrt_popup_up {
6975: border: 1px solid yellow;
6976: margin: -1px;
6977: }
1.795 www 6978:
1.417 albertel 6979: .LC_chrt_popup {
6980: border: 1px solid #8888FF;
6981: background: #CCCCFF;
6982: }
1.795 www 6983:
1.421 albertel 6984: table.LC_pick_box {
6985: border-collapse: separate;
6986: background: white;
6987: border: 1px solid black;
6988: border-spacing: 1px;
6989: }
1.795 www 6990:
1.421 albertel 6991: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6992: background: $sidebg;
1.421 albertel 6993: font-weight: bold;
1.900 bisitz 6994: text-align: left;
1.740 bisitz 6995: vertical-align: top;
1.421 albertel 6996: width: 184px;
6997: padding: 8px;
6998: }
1.795 www 6999:
1.579 raeburn 7000: table.LC_pick_box td.LC_pick_box_value {
7001: text-align: left;
7002: padding: 8px;
7003: }
1.795 www 7004:
1.579 raeburn 7005: table.LC_pick_box td.LC_pick_box_select {
7006: text-align: left;
7007: padding: 8px;
7008: }
1.795 www 7009:
1.424 albertel 7010: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 7011: padding: 0;
1.421 albertel 7012: height: 1px;
7013: background: black;
7014: }
1.795 www 7015:
1.421 albertel 7016: table.LC_pick_box td.LC_pick_box_submit {
7017: text-align: right;
7018: }
1.795 www 7019:
1.579 raeburn 7020: table.LC_pick_box td.LC_evenrow_value {
7021: text-align: left;
7022: padding: 8px;
7023: background-color: $data_table_light;
7024: }
1.795 www 7025:
1.579 raeburn 7026: table.LC_pick_box td.LC_oddrow_value {
7027: text-align: left;
7028: padding: 8px;
7029: background-color: $data_table_light;
7030: }
1.795 www 7031:
1.579 raeburn 7032: span.LC_helpform_receipt_cat {
7033: font-weight: bold;
7034: }
1.795 www 7035:
1.424 albertel 7036: table.LC_group_priv_box {
7037: background: white;
7038: border: 1px solid black;
7039: border-spacing: 1px;
7040: }
1.795 www 7041:
1.424 albertel 7042: table.LC_group_priv_box td.LC_pick_box_title {
7043: background: $tabbg;
7044: font-weight: bold;
7045: text-align: right;
7046: width: 184px;
7047: }
1.795 www 7048:
1.424 albertel 7049: table.LC_group_priv_box td.LC_groups_fixed {
7050: background: $data_table_light;
7051: text-align: center;
7052: }
1.795 www 7053:
1.424 albertel 7054: table.LC_group_priv_box td.LC_groups_optional {
7055: background: $data_table_dark;
7056: text-align: center;
7057: }
1.795 www 7058:
1.424 albertel 7059: table.LC_group_priv_box td.LC_groups_functionality {
7060: background: $data_table_darker;
7061: text-align: center;
7062: font-weight: bold;
7063: }
1.795 www 7064:
1.424 albertel 7065: table.LC_group_priv td {
7066: text-align: left;
1.803 bisitz 7067: padding: 0;
1.424 albertel 7068: }
7069:
7070: .LC_navbuttons {
7071: margin: 2ex 0ex 2ex 0ex;
7072: }
1.795 www 7073:
1.423 albertel 7074: .LC_topic_bar {
7075: font-weight: bold;
7076: background: $tabbg;
1.918 wenzelju 7077: margin: 1em 0em 1em 2em;
1.805 bisitz 7078: padding: 3px;
1.918 wenzelju 7079: font-size: 1.2em;
1.423 albertel 7080: }
1.795 www 7081:
1.423 albertel 7082: .LC_topic_bar span {
1.918 wenzelju 7083: left: 0.5em;
7084: position: absolute;
1.423 albertel 7085: vertical-align: middle;
1.918 wenzelju 7086: font-size: 1.2em;
1.423 albertel 7087: }
1.795 www 7088:
1.423 albertel 7089: table.LC_course_group_status {
7090: margin: 20px;
7091: }
1.795 www 7092:
1.423 albertel 7093: table.LC_status_selector td {
7094: vertical-align: top;
7095: text-align: center;
1.424 albertel 7096: padding: 4px;
7097: }
1.795 www 7098:
1.599 albertel 7099: div.LC_feedback_link {
1.616 albertel 7100: clear: both;
1.829 kalberla 7101: background: $sidebg;
1.779 bisitz 7102: width: 100%;
1.829 kalberla 7103: padding-bottom: 10px;
7104: border: 1px $tabbg solid;
1.833 kalberla 7105: height: 22px;
7106: line-height: 22px;
7107: padding-top: 5px;
7108: }
7109:
7110: div.LC_feedback_link img {
7111: height: 22px;
1.867 kalberla 7112: vertical-align:middle;
1.829 kalberla 7113: }
7114:
1.911 bisitz 7115: div.LC_feedback_link a {
1.829 kalberla 7116: text-decoration: none;
1.489 raeburn 7117: }
1.795 www 7118:
1.867 kalberla 7119: div.LC_comblock {
1.911 bisitz 7120: display:inline;
1.867 kalberla 7121: color:$font;
7122: font-size:90%;
7123: }
7124:
7125: div.LC_feedback_link div.LC_comblock {
7126: padding-left:5px;
7127: }
7128:
7129: div.LC_feedback_link div.LC_comblock a {
7130: color:$font;
7131: }
7132:
1.489 raeburn 7133: span.LC_feedback_link {
1.858 bisitz 7134: /* background: $feedback_link_bg; */
1.599 albertel 7135: font-size: larger;
7136: }
1.795 www 7137:
1.599 albertel 7138: span.LC_message_link {
1.858 bisitz 7139: /* background: $feedback_link_bg; */
1.599 albertel 7140: font-size: larger;
7141: position: absolute;
7142: right: 1em;
1.489 raeburn 7143: }
1.421 albertel 7144:
1.515 albertel 7145: table.LC_prior_tries {
1.524 albertel 7146: border: 1px solid #000000;
7147: border-collapse: separate;
7148: border-spacing: 1px;
1.515 albertel 7149: }
1.523 albertel 7150:
1.515 albertel 7151: table.LC_prior_tries td {
1.524 albertel 7152: padding: 2px;
1.515 albertel 7153: }
1.523 albertel 7154:
7155: .LC_answer_correct {
1.795 www 7156: background: lightgreen;
7157: color: darkgreen;
7158: padding: 6px;
1.523 albertel 7159: }
1.795 www 7160:
1.523 albertel 7161: .LC_answer_charged_try {
1.797 www 7162: background: #FFAAAA;
1.795 www 7163: color: darkred;
7164: padding: 6px;
1.523 albertel 7165: }
1.795 www 7166:
1.779 bisitz 7167: .LC_answer_not_charged_try,
1.523 albertel 7168: .LC_answer_no_grade,
7169: .LC_answer_late {
1.795 www 7170: background: lightyellow;
1.523 albertel 7171: color: black;
1.795 www 7172: padding: 6px;
1.523 albertel 7173: }
1.795 www 7174:
1.523 albertel 7175: .LC_answer_previous {
1.795 www 7176: background: lightblue;
7177: color: darkblue;
7178: padding: 6px;
1.523 albertel 7179: }
1.795 www 7180:
1.779 bisitz 7181: .LC_answer_no_message {
1.777 tempelho 7182: background: #FFFFFF;
7183: color: black;
1.795 www 7184: padding: 6px;
1.779 bisitz 7185: }
1.795 www 7186:
1.779 bisitz 7187: .LC_answer_unknown {
7188: background: orange;
7189: color: black;
1.795 www 7190: padding: 6px;
1.777 tempelho 7191: }
1.795 www 7192:
1.529 albertel 7193: span.LC_prior_numerical,
7194: span.LC_prior_string,
7195: span.LC_prior_custom,
7196: span.LC_prior_reaction,
7197: span.LC_prior_math {
1.925 bisitz 7198: font-family: $mono;
1.523 albertel 7199: white-space: pre;
7200: }
7201:
1.525 albertel 7202: span.LC_prior_string {
1.925 bisitz 7203: font-family: $mono;
1.525 albertel 7204: white-space: pre;
7205: }
7206:
1.523 albertel 7207: table.LC_prior_option {
7208: width: 100%;
7209: border-collapse: collapse;
7210: }
1.795 www 7211:
1.911 bisitz 7212: table.LC_prior_rank,
1.795 www 7213: table.LC_prior_match {
1.528 albertel 7214: border-collapse: collapse;
7215: }
1.795 www 7216:
1.528 albertel 7217: table.LC_prior_option tr td,
7218: table.LC_prior_rank tr td,
7219: table.LC_prior_match tr td {
1.524 albertel 7220: border: 1px solid #000000;
1.515 albertel 7221: }
7222:
1.855 bisitz 7223: .LC_nobreak {
1.544 albertel 7224: white-space: nowrap;
1.519 raeburn 7225: }
7226:
1.576 raeburn 7227: span.LC_cusr_emph {
7228: font-style: italic;
7229: }
7230:
1.633 raeburn 7231: span.LC_cusr_subheading {
7232: font-weight: normal;
7233: font-size: 85%;
7234: }
7235:
1.861 bisitz 7236: div.LC_docs_entry_move {
1.859 bisitz 7237: border: 1px solid #BBBBBB;
1.545 albertel 7238: background: #DDDDDD;
1.861 bisitz 7239: width: 22px;
1.859 bisitz 7240: padding: 1px;
7241: margin: 0;
1.545 albertel 7242: }
7243:
1.861 bisitz 7244: table.LC_data_table tr > td.LC_docs_entry_commands,
7245: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7246: font-size: x-small;
7247: }
1.795 www 7248:
1.861 bisitz 7249: .LC_docs_entry_parameter {
7250: white-space: nowrap;
7251: }
7252:
1.544 albertel 7253: .LC_docs_copy {
1.545 albertel 7254: color: #000099;
1.544 albertel 7255: }
1.795 www 7256:
1.544 albertel 7257: .LC_docs_cut {
1.545 albertel 7258: color: #550044;
1.544 albertel 7259: }
1.795 www 7260:
1.544 albertel 7261: .LC_docs_rename {
1.545 albertel 7262: color: #009900;
1.544 albertel 7263: }
1.795 www 7264:
1.544 albertel 7265: .LC_docs_remove {
1.545 albertel 7266: color: #990000;
7267: }
7268:
1.1284 raeburn 7269: .LC_docs_alias {
7270: color: #440055;
7271: }
7272:
1.1286 raeburn 7273: .LC_domprefs_email,
1.1284 raeburn 7274: .LC_docs_alias_name,
1.547 albertel 7275: .LC_docs_reinit_warn,
7276: .LC_docs_ext_edit {
7277: font-size: x-small;
7278: }
7279:
1.545 albertel 7280: table.LC_docs_adddocs td,
7281: table.LC_docs_adddocs th {
7282: border: 1px solid #BBBBBB;
7283: padding: 4px;
7284: background: #DDDDDD;
1.543 albertel 7285: }
7286:
1.584 albertel 7287: table.LC_sty_begin {
7288: background: #BBFFBB;
7289: }
1.795 www 7290:
1.584 albertel 7291: table.LC_sty_end {
7292: background: #FFBBBB;
7293: }
7294:
1.589 raeburn 7295: table.LC_double_column {
1.803 bisitz 7296: border-width: 0;
1.589 raeburn 7297: border-collapse: collapse;
7298: width: 100%;
7299: padding: 2px;
7300: }
7301:
7302: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7303: top: 2px;
1.589 raeburn 7304: left: 2px;
7305: width: 47%;
7306: vertical-align: top;
7307: }
7308:
7309: table.LC_double_column tr td.LC_right_col {
7310: top: 2px;
1.779 bisitz 7311: right: 2px;
1.589 raeburn 7312: width: 47%;
7313: vertical-align: top;
7314: }
7315:
1.591 raeburn 7316: div.LC_left_float {
7317: float: left;
7318: padding-right: 5%;
1.597 albertel 7319: padding-bottom: 4px;
1.591 raeburn 7320: }
7321:
7322: div.LC_clear_float_header {
1.597 albertel 7323: padding-bottom: 2px;
1.591 raeburn 7324: }
7325:
7326: div.LC_clear_float_footer {
1.597 albertel 7327: padding-top: 10px;
1.591 raeburn 7328: clear: both;
7329: }
7330:
1.597 albertel 7331: div.LC_grade_show_user {
1.941 bisitz 7332: /* border-left: 5px solid $sidebg; */
7333: border-top: 5px solid #000000;
7334: margin: 50px 0 0 0;
1.936 bisitz 7335: padding: 15px 0 5px 10px;
1.597 albertel 7336: }
1.795 www 7337:
1.936 bisitz 7338: div.LC_grade_show_user_odd_row {
1.941 bisitz 7339: /* border-left: 5px solid #000000; */
7340: }
7341:
7342: div.LC_grade_show_user div.LC_Box {
7343: margin-right: 50px;
1.597 albertel 7344: }
7345:
7346: div.LC_grade_submissions,
7347: div.LC_grade_message_center,
1.936 bisitz 7348: div.LC_grade_info_links {
1.597 albertel 7349: margin: 5px;
7350: width: 99%;
7351: background: #FFFFFF;
7352: }
1.795 www 7353:
1.597 albertel 7354: div.LC_grade_submissions_header,
1.936 bisitz 7355: div.LC_grade_message_center_header {
1.705 tempelho 7356: font-weight: bold;
7357: font-size: large;
1.597 albertel 7358: }
1.795 www 7359:
1.597 albertel 7360: div.LC_grade_submissions_body,
1.936 bisitz 7361: div.LC_grade_message_center_body {
1.597 albertel 7362: border: 1px solid black;
7363: width: 99%;
7364: background: #FFFFFF;
7365: }
1.795 www 7366:
1.613 albertel 7367: table.LC_scantron_action {
7368: width: 100%;
7369: }
1.795 www 7370:
1.613 albertel 7371: table.LC_scantron_action tr th {
1.698 harmsja 7372: font-weight:bold;
7373: font-style:normal;
1.613 albertel 7374: }
1.795 www 7375:
1.779 bisitz 7376: .LC_edit_problem_header,
1.614 albertel 7377: div.LC_edit_problem_footer {
1.705 tempelho 7378: font-weight: normal;
7379: font-size: medium;
1.602 albertel 7380: margin: 2px;
1.1060 bisitz 7381: background-color: $sidebg;
1.600 albertel 7382: }
1.795 www 7383:
1.600 albertel 7384: div.LC_edit_problem_header,
1.602 albertel 7385: div.LC_edit_problem_header div,
1.614 albertel 7386: div.LC_edit_problem_footer,
7387: div.LC_edit_problem_footer div,
1.602 albertel 7388: div.LC_edit_problem_editxml_header,
7389: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7390: z-index: 100;
1.600 albertel 7391: }
1.795 www 7392:
1.600 albertel 7393: div.LC_edit_problem_header_title {
1.705 tempelho 7394: font-weight: bold;
7395: font-size: larger;
1.602 albertel 7396: background: $tabbg;
7397: padding: 3px;
1.1060 bisitz 7398: margin: 0 0 5px 0;
1.602 albertel 7399: }
1.795 www 7400:
1.602 albertel 7401: table.LC_edit_problem_header_title {
7402: width: 100%;
1.600 albertel 7403: background: $tabbg;
1.602 albertel 7404: }
7405:
1.1205 golterma 7406: div.LC_edit_actionbar {
7407: background-color: $sidebg;
1.1218 droeschl 7408: margin: 0;
7409: padding: 0;
7410: line-height: 200%;
1.602 albertel 7411: }
1.795 www 7412:
1.1218 droeschl 7413: div.LC_edit_actionbar div{
7414: padding: 0;
7415: margin: 0;
7416: display: inline-block;
1.600 albertel 7417: }
1.795 www 7418:
1.1124 bisitz 7419: .LC_edit_opt {
7420: padding-left: 1em;
7421: white-space: nowrap;
7422: }
7423:
1.1152 golterma 7424: .LC_edit_problem_latexhelper{
7425: text-align: right;
7426: }
7427:
7428: #LC_edit_problem_colorful div{
7429: margin-left: 40px;
7430: }
7431:
1.1205 golterma 7432: #LC_edit_problem_codemirror div{
7433: margin-left: 0px;
7434: }
7435:
1.911 bisitz 7436: img.stift {
1.803 bisitz 7437: border-width: 0;
7438: vertical-align: middle;
1.677 riegler 7439: }
1.680 riegler 7440:
1.923 bisitz 7441: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7442: vertical-align: top;
1.777 tempelho 7443: }
1.795 www 7444:
1.716 raeburn 7445: div.LC_createcourse {
1.911 bisitz 7446: margin: 10px 10px 10px 10px;
1.716 raeburn 7447: }
7448:
1.917 raeburn 7449: .LC_dccid {
1.1130 raeburn 7450: float: right;
1.917 raeburn 7451: margin: 0.2em 0 0 0;
7452: padding: 0;
7453: font-size: 90%;
7454: display:none;
7455: }
7456:
1.897 wenzelju 7457: ol.LC_primary_menu a:hover,
1.721 harmsja 7458: ol#LC_MenuBreadcrumbs a:hover,
7459: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7460: ul#LC_secondary_menu a:hover,
1.721 harmsja 7461: .LC_FormSectionClearButton input:hover
1.795 www 7462: ul.LC_TabContent li:hover a {
1.952 onken 7463: color:$button_hover;
1.911 bisitz 7464: text-decoration:none;
1.693 droeschl 7465: }
7466:
1.779 bisitz 7467: h1 {
1.911 bisitz 7468: padding: 0;
7469: line-height:130%;
1.693 droeschl 7470: }
1.698 harmsja 7471:
1.911 bisitz 7472: h2,
7473: h3,
7474: h4,
7475: h5,
7476: h6 {
7477: margin: 5px 0 5px 0;
7478: padding: 0;
7479: line-height:130%;
1.693 droeschl 7480: }
1.795 www 7481:
7482: .LC_hcell {
1.911 bisitz 7483: padding:3px 15px 3px 15px;
7484: margin: 0;
7485: background-color:$tabbg;
7486: color:$fontmenu;
7487: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7488: }
1.795 www 7489:
1.840 bisitz 7490: .LC_Box > .LC_hcell {
1.911 bisitz 7491: margin: 0 -10px 10px -10px;
1.835 bisitz 7492: }
7493:
1.721 harmsja 7494: .LC_noBorder {
1.911 bisitz 7495: border: 0;
1.698 harmsja 7496: }
1.693 droeschl 7497:
1.721 harmsja 7498: .LC_FormSectionClearButton input {
1.911 bisitz 7499: background-color:transparent;
7500: border: none;
7501: cursor:pointer;
7502: text-decoration:underline;
1.693 droeschl 7503: }
1.763 bisitz 7504:
7505: .LC_help_open_topic {
1.911 bisitz 7506: color: #FFFFFF;
7507: background-color: #EEEEFF;
7508: margin: 1px;
7509: padding: 4px;
7510: border: 1px solid #000033;
7511: white-space: nowrap;
7512: /* vertical-align: middle; */
1.759 neumanie 7513: }
1.693 droeschl 7514:
1.911 bisitz 7515: dl,
7516: ul,
7517: div,
7518: fieldset {
7519: margin: 10px 10px 10px 0;
7520: /* overflow: hidden; */
1.693 droeschl 7521: }
1.795 www 7522:
1.1211 raeburn 7523: article.geogebraweb div {
7524: margin: 0;
7525: }
7526:
1.838 bisitz 7527: fieldset > legend {
1.911 bisitz 7528: font-weight: bold;
7529: padding: 0 5px 0 5px;
1.838 bisitz 7530: }
7531:
1.813 bisitz 7532: #LC_nav_bar {
1.911 bisitz 7533: float: left;
1.995 raeburn 7534: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7535: margin: 0 0 2px 0;
1.807 droeschl 7536: }
7537:
1.916 droeschl 7538: #LC_realm {
7539: margin: 0.2em 0 0 0;
7540: padding: 0;
7541: font-weight: bold;
7542: text-align: center;
1.995 raeburn 7543: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7544: }
7545:
1.911 bisitz 7546: #LC_nav_bar em {
7547: font-weight: bold;
7548: font-style: normal;
1.807 droeschl 7549: }
7550:
1.897 wenzelju 7551: ol.LC_primary_menu {
1.934 droeschl 7552: margin: 0;
1.1076 raeburn 7553: padding: 0;
1.807 droeschl 7554: }
7555:
1.852 droeschl 7556: ol#LC_PathBreadcrumbs {
1.911 bisitz 7557: margin: 0;
1.693 droeschl 7558: }
7559:
1.897 wenzelju 7560: ol.LC_primary_menu li {
1.1076 raeburn 7561: color: RGB(80, 80, 80);
7562: vertical-align: middle;
7563: text-align: left;
7564: list-style: none;
1.1205 golterma 7565: position: relative;
1.1076 raeburn 7566: float: left;
1.1205 golterma 7567: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7568: line-height: 1.5em;
1.1076 raeburn 7569: }
7570:
1.1205 golterma 7571: ol.LC_primary_menu li a,
7572: ol.LC_primary_menu li p {
1.1076 raeburn 7573: display: block;
7574: margin: 0;
7575: padding: 0 5px 0 10px;
7576: text-decoration: none;
7577: }
7578:
1.1205 golterma 7579: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7580: display: inline-block;
7581: width: 95%;
7582: text-align: left;
7583: }
7584:
7585: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7586: display: inline-block;
7587: width: 5%;
7588: float: right;
7589: text-align: right;
7590: font-size: 70%;
7591: }
7592:
7593: ol.LC_primary_menu ul {
1.1076 raeburn 7594: display: none;
1.1205 golterma 7595: width: 15em;
1.1076 raeburn 7596: background-color: $data_table_light;
1.1205 golterma 7597: position: absolute;
7598: top: 100%;
1.1076 raeburn 7599: }
7600:
1.1205 golterma 7601: ol.LC_primary_menu ul ul {
7602: left: 100%;
7603: top: 0;
7604: }
7605:
7606: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7607: display: block;
7608: position: absolute;
7609: margin: 0;
7610: padding: 0;
1.1078 raeburn 7611: z-index: 2;
1.1076 raeburn 7612: }
7613:
7614: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7615: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7616: font-size: 90%;
1.911 bisitz 7617: vertical-align: top;
1.1076 raeburn 7618: float: none;
1.1079 raeburn 7619: border-left: 1px solid black;
7620: border-right: 1px solid black;
1.1205 golterma 7621: /* A dark bottom border to visualize different menu options;
7622: overwritten in the create_submenu routine for the last border-bottom of the menu */
7623: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7624: }
7625:
1.1205 golterma 7626: ol.LC_primary_menu li li p:hover {
7627: color:$button_hover;
7628: text-decoration:none;
7629: background-color:$data_table_dark;
1.1076 raeburn 7630: }
7631:
7632: ol.LC_primary_menu li li a:hover {
7633: color:$button_hover;
7634: background-color:$data_table_dark;
1.693 droeschl 7635: }
7636:
1.1205 golterma 7637: /* Font-size equal to the size of the predecessors*/
7638: ol.LC_primary_menu li:hover li li {
7639: font-size: 100%;
7640: }
7641:
1.897 wenzelju 7642: ol.LC_primary_menu li img {
1.911 bisitz 7643: vertical-align: bottom;
1.934 droeschl 7644: height: 1.1em;
1.1077 raeburn 7645: margin: 0.2em 0 0 0;
1.693 droeschl 7646: }
7647:
1.897 wenzelju 7648: ol.LC_primary_menu a {
1.911 bisitz 7649: color: RGB(80, 80, 80);
7650: text-decoration: none;
1.693 droeschl 7651: }
1.795 www 7652:
1.949 droeschl 7653: ol.LC_primary_menu a.LC_new_message {
7654: font-weight:bold;
7655: color: darkred;
7656: }
7657:
1.975 raeburn 7658: ol.LC_docs_parameters {
7659: margin-left: 0;
7660: padding: 0;
7661: list-style: none;
7662: }
7663:
7664: ol.LC_docs_parameters li {
7665: margin: 0;
7666: padding-right: 20px;
7667: display: inline;
7668: }
7669:
1.976 raeburn 7670: ol.LC_docs_parameters li:before {
7671: content: "\\002022 \\0020";
7672: }
7673:
7674: li.LC_docs_parameters_title {
7675: font-weight: bold;
7676: }
7677:
7678: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7679: content: "";
7680: }
7681:
1.897 wenzelju 7682: ul#LC_secondary_menu {
1.1107 raeburn 7683: clear: right;
1.911 bisitz 7684: color: $fontmenu;
7685: background: $tabbg;
7686: list-style: none;
7687: padding: 0;
7688: margin: 0;
7689: width: 100%;
1.995 raeburn 7690: text-align: left;
1.1107 raeburn 7691: float: left;
1.808 droeschl 7692: }
7693:
1.897 wenzelju 7694: ul#LC_secondary_menu li {
1.911 bisitz 7695: font-weight: bold;
7696: line-height: 1.8em;
1.1107 raeburn 7697: border-right: 1px solid black;
7698: float: left;
7699: }
7700:
7701: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7702: background-color: $data_table_light;
7703: }
7704:
7705: ul#LC_secondary_menu li a {
1.911 bisitz 7706: padding: 0 0.8em;
1.1107 raeburn 7707: }
7708:
7709: ul#LC_secondary_menu li ul {
7710: display: none;
7711: }
7712:
7713: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7714: display: block;
7715: position: absolute;
7716: margin: 0;
7717: padding: 0;
7718: list-style:none;
7719: float: none;
7720: background-color: $data_table_light;
7721: z-index: 2;
7722: margin-left: -1px;
7723: }
7724:
7725: ul#LC_secondary_menu li ul li {
7726: font-size: 90%;
7727: vertical-align: top;
7728: border-left: 1px solid black;
1.911 bisitz 7729: border-right: 1px solid black;
1.1119 raeburn 7730: background-color: $data_table_light;
1.1107 raeburn 7731: list-style:none;
7732: float: none;
7733: }
7734:
7735: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7736: background-color: $data_table_dark;
1.807 droeschl 7737: }
7738:
1.847 tempelho 7739: ul.LC_TabContent {
1.911 bisitz 7740: display:block;
7741: background: $sidebg;
7742: border-bottom: solid 1px $lg_border_color;
7743: list-style:none;
1.1020 raeburn 7744: margin: -1px -10px 0 -10px;
1.911 bisitz 7745: padding: 0;
1.693 droeschl 7746: }
7747:
1.795 www 7748: ul.LC_TabContent li,
7749: ul.LC_TabContentBigger li {
1.911 bisitz 7750: float:left;
1.741 harmsja 7751: }
1.795 www 7752:
1.897 wenzelju 7753: ul#LC_secondary_menu li a {
1.911 bisitz 7754: color: $fontmenu;
7755: text-decoration: none;
1.693 droeschl 7756: }
1.795 www 7757:
1.721 harmsja 7758: ul.LC_TabContent {
1.952 onken 7759: min-height:20px;
1.721 harmsja 7760: }
1.795 www 7761:
7762: ul.LC_TabContent li {
1.911 bisitz 7763: vertical-align:middle;
1.959 onken 7764: padding: 0 16px 0 10px;
1.911 bisitz 7765: background-color:$tabbg;
7766: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7767: border-left: solid 1px $font;
1.721 harmsja 7768: }
1.795 www 7769:
1.847 tempelho 7770: ul.LC_TabContent .right {
1.911 bisitz 7771: float:right;
1.847 tempelho 7772: }
7773:
1.911 bisitz 7774: ul.LC_TabContent li a,
7775: ul.LC_TabContent li {
7776: color:rgb(47,47,47);
7777: text-decoration:none;
7778: font-size:95%;
7779: font-weight:bold;
1.952 onken 7780: min-height:20px;
7781: }
7782:
1.959 onken 7783: ul.LC_TabContent li a:hover,
7784: ul.LC_TabContent li a:focus {
1.952 onken 7785: color: $button_hover;
1.959 onken 7786: background:none;
7787: outline:none;
1.952 onken 7788: }
7789:
7790: ul.LC_TabContent li:hover {
7791: color: $button_hover;
7792: cursor:pointer;
1.721 harmsja 7793: }
1.795 www 7794:
1.911 bisitz 7795: ul.LC_TabContent li.active {
1.952 onken 7796: color: $font;
1.911 bisitz 7797: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7798: border-bottom:solid 1px #FFFFFF;
7799: cursor: default;
1.744 ehlerst 7800: }
1.795 www 7801:
1.959 onken 7802: ul.LC_TabContent li.active a {
7803: color:$font;
7804: background:#FFFFFF;
7805: outline: none;
7806: }
1.1047 raeburn 7807:
7808: ul.LC_TabContent li.goback {
7809: float: left;
7810: border-left: none;
7811: }
7812:
1.870 tempelho 7813: #maincoursedoc {
1.911 bisitz 7814: clear:both;
1.870 tempelho 7815: }
7816:
7817: ul.LC_TabContentBigger {
1.911 bisitz 7818: display:block;
7819: list-style:none;
7820: padding: 0;
1.870 tempelho 7821: }
7822:
1.795 www 7823: ul.LC_TabContentBigger li {
1.911 bisitz 7824: vertical-align:bottom;
7825: height: 30px;
7826: font-size:110%;
7827: font-weight:bold;
7828: color: #737373;
1.841 tempelho 7829: }
7830:
1.957 onken 7831: ul.LC_TabContentBigger li.active {
7832: position: relative;
7833: top: 1px;
7834: }
7835:
1.870 tempelho 7836: ul.LC_TabContentBigger li a {
1.911 bisitz 7837: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7838: height: 30px;
7839: line-height: 30px;
7840: text-align: center;
7841: display: block;
7842: text-decoration: none;
1.958 onken 7843: outline: none;
1.741 harmsja 7844: }
1.795 www 7845:
1.870 tempelho 7846: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7847: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7848: color:$font;
1.744 ehlerst 7849: }
1.795 www 7850:
1.870 tempelho 7851: ul.LC_TabContentBigger li b {
1.911 bisitz 7852: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7853: display: block;
7854: float: left;
7855: padding: 0 30px;
1.957 onken 7856: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7857: }
7858:
1.956 onken 7859: ul.LC_TabContentBigger li:hover b {
7860: color:$button_hover;
7861: }
7862:
1.870 tempelho 7863: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7864: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7865: color:$font;
1.957 onken 7866: border: 0;
1.741 harmsja 7867: }
1.693 droeschl 7868:
1.870 tempelho 7869:
1.862 bisitz 7870: ul.LC_CourseBreadcrumbs {
7871: background: $sidebg;
1.1020 raeburn 7872: height: 2em;
1.862 bisitz 7873: padding-left: 10px;
1.1020 raeburn 7874: margin: 0;
1.862 bisitz 7875: list-style-position: inside;
7876: }
7877:
1.911 bisitz 7878: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7879: ol#LC_PathBreadcrumbs {
1.911 bisitz 7880: padding-left: 10px;
7881: margin: 0;
1.933 droeschl 7882: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7883: }
7884:
1.911 bisitz 7885: ol#LC_MenuBreadcrumbs li,
7886: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7887: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7888: display: inline;
1.933 droeschl 7889: white-space: normal;
1.693 droeschl 7890: }
7891:
1.823 bisitz 7892: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7893: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7894: text-decoration: none;
7895: font-size:90%;
1.693 droeschl 7896: }
1.795 www 7897:
1.969 droeschl 7898: ol#LC_MenuBreadcrumbs h1 {
7899: display: inline;
7900: font-size: 90%;
7901: line-height: 2.5em;
7902: margin: 0;
7903: padding: 0;
7904: }
7905:
1.795 www 7906: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7907: text-decoration:none;
7908: font-size:100%;
7909: font-weight:bold;
1.693 droeschl 7910: }
1.795 www 7911:
1.840 bisitz 7912: .LC_Box {
1.911 bisitz 7913: border: solid 1px $lg_border_color;
7914: padding: 0 10px 10px 10px;
1.746 neumanie 7915: }
1.795 www 7916:
1.1020 raeburn 7917: .LC_DocsBox {
7918: border: solid 1px $lg_border_color;
7919: padding: 0 0 10px 10px;
7920: }
7921:
1.795 www 7922: .LC_AboutMe_Image {
1.911 bisitz 7923: float:left;
7924: margin-right:10px;
1.747 neumanie 7925: }
1.795 www 7926:
7927: .LC_Clear_AboutMe_Image {
1.911 bisitz 7928: clear:left;
1.747 neumanie 7929: }
1.795 www 7930:
1.721 harmsja 7931: dl.LC_ListStyleClean dt {
1.911 bisitz 7932: padding-right: 5px;
7933: display: table-header-group;
1.693 droeschl 7934: }
7935:
1.721 harmsja 7936: dl.LC_ListStyleClean dd {
1.911 bisitz 7937: display: table-row;
1.693 droeschl 7938: }
7939:
1.721 harmsja 7940: .LC_ListStyleClean,
7941: .LC_ListStyleSimple,
7942: .LC_ListStyleNormal,
1.795 www 7943: .LC_ListStyleSpecial {
1.911 bisitz 7944: /* display:block; */
7945: list-style-position: inside;
7946: list-style-type: none;
7947: overflow: hidden;
7948: padding: 0;
1.693 droeschl 7949: }
7950:
1.721 harmsja 7951: .LC_ListStyleSimple li,
7952: .LC_ListStyleSimple dd,
7953: .LC_ListStyleNormal li,
7954: .LC_ListStyleNormal dd,
7955: .LC_ListStyleSpecial li,
1.795 www 7956: .LC_ListStyleSpecial dd {
1.911 bisitz 7957: margin: 0;
7958: padding: 5px 5px 5px 10px;
7959: clear: both;
1.693 droeschl 7960: }
7961:
1.721 harmsja 7962: .LC_ListStyleClean li,
7963: .LC_ListStyleClean dd {
1.911 bisitz 7964: padding-top: 0;
7965: padding-bottom: 0;
1.693 droeschl 7966: }
7967:
1.721 harmsja 7968: .LC_ListStyleSimple dd,
1.795 www 7969: .LC_ListStyleSimple li {
1.911 bisitz 7970: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7971: }
7972:
1.721 harmsja 7973: .LC_ListStyleSpecial li,
7974: .LC_ListStyleSpecial dd {
1.911 bisitz 7975: list-style-type: none;
7976: background-color: RGB(220, 220, 220);
7977: margin-bottom: 4px;
1.693 droeschl 7978: }
7979:
1.721 harmsja 7980: table.LC_SimpleTable {
1.911 bisitz 7981: margin:5px;
7982: border:solid 1px $lg_border_color;
1.795 www 7983: }
1.693 droeschl 7984:
1.721 harmsja 7985: table.LC_SimpleTable tr {
1.911 bisitz 7986: padding: 0;
7987: border:solid 1px $lg_border_color;
1.693 droeschl 7988: }
1.795 www 7989:
7990: table.LC_SimpleTable thead {
1.911 bisitz 7991: background:rgb(220,220,220);
1.693 droeschl 7992: }
7993:
1.721 harmsja 7994: div.LC_columnSection {
1.911 bisitz 7995: display: block;
7996: clear: both;
7997: overflow: hidden;
7998: margin: 0;
1.693 droeschl 7999: }
8000:
1.721 harmsja 8001: div.LC_columnSection>* {
1.911 bisitz 8002: float: left;
8003: margin: 10px 20px 10px 0;
8004: overflow:hidden;
1.693 droeschl 8005: }
1.721 harmsja 8006:
1.795 www 8007: table em {
1.911 bisitz 8008: font-weight: bold;
8009: font-style: normal;
1.748 schulted 8010: }
1.795 www 8011:
1.779 bisitz 8012: table.LC_tableBrowseRes,
1.795 www 8013: table.LC_tableOfContent {
1.911 bisitz 8014: border:none;
8015: border-spacing: 1px;
8016: padding: 3px;
8017: background-color: #FFFFFF;
8018: font-size: 90%;
1.753 droeschl 8019: }
1.789 droeschl 8020:
1.911 bisitz 8021: table.LC_tableOfContent {
8022: border-collapse: collapse;
1.789 droeschl 8023: }
8024:
1.771 droeschl 8025: table.LC_tableBrowseRes a,
1.768 schulted 8026: table.LC_tableOfContent a {
1.911 bisitz 8027: background-color: transparent;
8028: text-decoration: none;
1.753 droeschl 8029: }
8030:
1.795 www 8031: table.LC_tableOfContent img {
1.911 bisitz 8032: border: none;
8033: height: 1.3em;
8034: vertical-align: text-bottom;
8035: margin-right: 0.3em;
1.753 droeschl 8036: }
1.757 schulted 8037:
1.795 www 8038: a#LC_content_toolbar_firsthomework {
1.911 bisitz 8039: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 8040: }
8041:
1.795 www 8042: a#LC_content_toolbar_everything {
1.911 bisitz 8043: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 8044: }
8045:
1.795 www 8046: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8047: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8048: }
8049:
1.795 www 8050: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8051: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8052: }
8053:
1.795 www 8054: a#LC_content_toolbar_changefolder {
1.911 bisitz 8055: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8056: }
8057:
1.795 www 8058: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8059: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8060: }
8061:
1.1043 raeburn 8062: a#LC_content_toolbar_edittoplevel {
8063: background-image:url(/res/adm/pages/edittoplevel.gif);
8064: }
8065:
1.795 www 8066: ul#LC_toolbar li a:hover {
1.911 bisitz 8067: background-position: bottom center;
1.757 schulted 8068: }
8069:
1.795 www 8070: ul#LC_toolbar {
1.911 bisitz 8071: padding: 0;
8072: margin: 2px;
8073: list-style:none;
8074: position:relative;
8075: background-color:white;
1.1082 raeburn 8076: overflow: auto;
1.757 schulted 8077: }
8078:
1.795 www 8079: ul#LC_toolbar li {
1.911 bisitz 8080: border:1px solid white;
8081: padding: 0;
8082: margin: 0;
8083: float: left;
8084: display:inline;
8085: vertical-align:middle;
1.1082 raeburn 8086: white-space: nowrap;
1.911 bisitz 8087: }
1.757 schulted 8088:
1.783 amueller 8089:
1.795 www 8090: a.LC_toolbarItem {
1.911 bisitz 8091: display:block;
8092: padding: 0;
8093: margin: 0;
8094: height: 32px;
8095: width: 32px;
8096: color:white;
8097: border: none;
8098: background-repeat:no-repeat;
8099: background-color:transparent;
1.757 schulted 8100: }
8101:
1.915 droeschl 8102: ul.LC_funclist {
8103: margin: 0;
8104: padding: 0.5em 1em 0.5em 0;
8105: }
8106:
1.933 droeschl 8107: ul.LC_funclist > li:first-child {
8108: font-weight:bold;
8109: margin-left:0.8em;
8110: }
8111:
1.915 droeschl 8112: ul.LC_funclist + ul.LC_funclist {
8113: /*
8114: left border as a seperator if we have more than
8115: one list
8116: */
8117: border-left: 1px solid $sidebg;
8118: /*
8119: this hides the left border behind the border of the
8120: outer box if element is wrapped to the next 'line'
8121: */
8122: margin-left: -1px;
8123: }
8124:
1.843 bisitz 8125: ul.LC_funclist li {
1.915 droeschl 8126: display: inline;
1.782 bisitz 8127: white-space: nowrap;
1.915 droeschl 8128: margin: 0 0 0 25px;
8129: line-height: 150%;
1.782 bisitz 8130: }
8131:
1.974 wenzelju 8132: .LC_hidden {
8133: display: none;
8134: }
8135:
1.1030 www 8136: .LCmodal-overlay {
8137: position:fixed;
8138: top:0;
8139: right:0;
8140: bottom:0;
8141: left:0;
8142: height:100%;
8143: width:100%;
8144: margin:0;
8145: padding:0;
8146: background:#999;
8147: opacity:.75;
8148: filter: alpha(opacity=75);
8149: -moz-opacity: 0.75;
8150: z-index:101;
8151: }
8152:
8153: * html .LCmodal-overlay {
8154: position: absolute;
8155: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8156: }
8157:
8158: .LCmodal-window {
8159: position:fixed;
8160: top:50%;
8161: left:50%;
8162: margin:0;
8163: padding:0;
8164: z-index:102;
8165: }
8166:
8167: * html .LCmodal-window {
8168: position:absolute;
8169: }
8170:
8171: .LCclose-window {
8172: position:absolute;
8173: width:32px;
8174: height:32px;
8175: right:8px;
8176: top:8px;
8177: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8178: text-indent:-99999px;
8179: overflow:hidden;
8180: cursor:pointer;
8181: }
8182:
1.1100 raeburn 8183: /*
1.1231 damieng 8184: styles used for response display
8185: */
8186: div.LC_radiofoil, div.LC_rankfoil {
8187: margin: .5em 0em .5em 0em;
8188: }
8189: table.LC_itemgroup {
8190: margin-top: 1em;
8191: }
8192:
8193: /*
1.1100 raeburn 8194: styles used by TTH when "Default set of options to pass to tth/m
8195: when converting TeX" in course settings has been set
8196:
8197: option passed: -t
8198:
8199: */
8200:
8201: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8202: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8203: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8204: td div.norm {line-height:normal;}
8205:
8206: /*
8207: option passed -y3
8208: */
8209:
8210: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8211: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8212: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8213:
1.1230 damieng 8214: /*
8215: sections with roles, for content only
8216: */
8217: section[class^="role-"] {
8218: padding-left: 10px;
8219: padding-right: 5px;
8220: margin-top: 8px;
8221: margin-bottom: 8px;
8222: border: 1px solid #2A4;
8223: border-radius: 5px;
8224: box-shadow: 0px 1px 1px #BBB;
8225: }
8226: section[class^="role-"]>h1 {
8227: position: relative;
8228: margin: 0px;
8229: padding-top: 10px;
8230: padding-left: 40px;
8231: }
8232: section[class^="role-"]>h1:before {
8233: position: absolute;
8234: left: -5px;
8235: top: 5px;
8236: }
8237: section.role-activity>h1:before {
8238: content:url('/adm/daxe/images/section_icons/activity.png');
8239: }
8240: section.role-advice>h1:before {
8241: content:url('/adm/daxe/images/section_icons/advice.png');
8242: }
8243: section.role-bibliography>h1:before {
8244: content:url('/adm/daxe/images/section_icons/bibliography.png');
8245: }
8246: section.role-citation>h1:before {
8247: content:url('/adm/daxe/images/section_icons/citation.png');
8248: }
8249: section.role-conclusion>h1:before {
8250: content:url('/adm/daxe/images/section_icons/conclusion.png');
8251: }
8252: section.role-definition>h1:before {
8253: content:url('/adm/daxe/images/section_icons/definition.png');
8254: }
8255: section.role-demonstration>h1:before {
8256: content:url('/adm/daxe/images/section_icons/demonstration.png');
8257: }
8258: section.role-example>h1:before {
8259: content:url('/adm/daxe/images/section_icons/example.png');
8260: }
8261: section.role-explanation>h1:before {
8262: content:url('/adm/daxe/images/section_icons/explanation.png');
8263: }
8264: section.role-introduction>h1:before {
8265: content:url('/adm/daxe/images/section_icons/introduction.png');
8266: }
8267: section.role-method>h1:before {
8268: content:url('/adm/daxe/images/section_icons/method.png');
8269: }
8270: section.role-more_information>h1:before {
8271: content:url('/adm/daxe/images/section_icons/more_information.png');
8272: }
8273: section.role-objectives>h1:before {
8274: content:url('/adm/daxe/images/section_icons/objectives.png');
8275: }
8276: section.role-prerequisites>h1:before {
8277: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8278: }
8279: section.role-remark>h1:before {
8280: content:url('/adm/daxe/images/section_icons/remark.png');
8281: }
8282: section.role-reminder>h1:before {
8283: content:url('/adm/daxe/images/section_icons/reminder.png');
8284: }
8285: section.role-summary>h1:before {
8286: content:url('/adm/daxe/images/section_icons/summary.png');
8287: }
8288: section.role-syntax>h1:before {
8289: content:url('/adm/daxe/images/section_icons/syntax.png');
8290: }
8291: section.role-warning>h1:before {
8292: content:url('/adm/daxe/images/section_icons/warning.png');
8293: }
8294:
1.1269 raeburn 8295: #LC_minitab_header {
8296: float:left;
8297: width:100%;
8298: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8299: font-size:93%;
8300: line-height:normal;
8301: margin: 0.5em 0 0.5em 0;
8302: }
8303: #LC_minitab_header ul {
8304: margin:0;
8305: padding:10px 10px 0;
8306: list-style:none;
8307: }
8308: #LC_minitab_header li {
8309: float:left;
8310: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8311: margin:0;
8312: padding:0 0 0 9px;
8313: }
8314: #LC_minitab_header a {
8315: display:block;
8316: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8317: padding:5px 15px 4px 6px;
8318: }
8319: #LC_minitab_header #LC_current_minitab {
8320: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8321: }
8322: #LC_minitab_header #LC_current_minitab a {
8323: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8324: padding-bottom:5px;
8325: }
8326:
8327:
1.343 albertel 8328: END
8329: }
8330:
1.306 albertel 8331: =pod
8332:
8333: =item * &headtag()
8334:
8335: Returns a uniform footer for LON-CAPA web pages.
8336:
1.307 albertel 8337: Inputs: $title - optional title for the head
8338: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8339: $args - optional arguments
1.319 albertel 8340: force_register - if is true call registerurl so the remote is
8341: informed
1.415 albertel 8342: redirect -> array ref of
8343: 1- seconds before redirect occurs
8344: 2- url to redirect to
8345: 3- whether the side effect should occur
1.315 albertel 8346: (side effect of setting
8347: $env{'internal.head.redirect'} to the url
8348: redirected too)
1.352 albertel 8349: domain -> force to color decorate a page for a specific
8350: domain
8351: function -> force usage of a specific rolish color scheme
8352: bgcolor -> override the default page bgcolor
1.460 albertel 8353: no_auto_mt_title
8354: -> prevent &mt()ing the title arg
1.464 albertel 8355:
1.306 albertel 8356: =cut
8357:
8358: sub headtag {
1.313 albertel 8359: my ($title,$head_extra,$args) = @_;
1.306 albertel 8360:
1.363 albertel 8361: my $function = $args->{'function'} || &get_users_function();
8362: my $domain = $args->{'domain'} || &determinedomain();
8363: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8364: my $httphost = $args->{'use_absolute'};
1.418 albertel 8365: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8366: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8367: #time(),
1.418 albertel 8368: $env{'environment.color.timestamp'},
1.363 albertel 8369: $function,$domain,$bgcolor);
8370:
1.369 www 8371: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8372:
1.308 albertel 8373: my $result =
8374: '<head>'.
1.1160 raeburn 8375: &font_settings($args);
1.319 albertel 8376:
1.1188 raeburn 8377: my $inhibitprint;
8378: if ($args->{'print_suppress'}) {
8379: $inhibitprint = &print_suppression();
8380: }
1.1064 raeburn 8381:
1.461 albertel 8382: if (!$args->{'frameset'}) {
8383: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8384: }
1.962 droeschl 8385: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8386: $result .= Apache::lonxml::display_title();
1.319 albertel 8387: }
1.436 albertel 8388: if (!$args->{'no_nav_bar'}
8389: && !$args->{'only_body'}
8390: && !$args->{'frameset'}) {
1.1154 raeburn 8391: $result .= &help_menu_js($httphost);
1.1032 www 8392: $result.=&modal_window();
1.1038 www 8393: $result.=&togglebox_script();
1.1034 www 8394: $result.=&wishlist_window();
1.1041 www 8395: $result.=&LCprogressbarUpdate_script();
1.1034 www 8396: } else {
8397: if ($args->{'add_modal'}) {
8398: $result.=&modal_window();
8399: }
8400: if ($args->{'add_wishlist'}) {
8401: $result.=&wishlist_window();
8402: }
1.1038 www 8403: if ($args->{'add_togglebox'}) {
8404: $result.=&togglebox_script();
8405: }
1.1041 www 8406: if ($args->{'add_progressbar'}) {
8407: $result.=&LCprogressbarUpdate_script();
8408: }
1.436 albertel 8409: }
1.314 albertel 8410: if (ref($args->{'redirect'})) {
1.414 albertel 8411: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8412: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8413: if (!$inhibit_continue) {
8414: $env{'internal.head.redirect'} = $url;
8415: }
1.313 albertel 8416: $result.=<<ADDMETA
8417: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8418: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8419: ADDMETA
1.1210 raeburn 8420: } else {
8421: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8422: my $requrl = $env{'request.uri'};
8423: if ($requrl eq '') {
8424: $requrl = $ENV{'REQUEST_URI'};
8425: $requrl =~ s/\?.+$//;
8426: }
8427: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8428: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8429: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8430: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8431: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8432: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
8433: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8434: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
8435: if ($domdefs{'offloadnow'}{$lonhost}) {
8436: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
8437: if (($newserver) && ($newserver ne $lonhost)) {
8438: my $numsec = 5;
8439: my $timeout = $numsec * 1000;
8440: my ($newurl,$locknum,%locks,$msg);
8441: if ($env{'request.role.adv'}) {
8442: ($locknum,%locks) = &Apache::lonnet::get_locks();
8443: }
8444: my $disable_submit = 0;
8445: if ($requrl =~ /$LONCAPA::assess_re/) {
8446: $disable_submit = 1;
8447: }
8448: if ($locknum) {
8449: my @lockinfo = sort(values(%locks));
8450: $msg = &mt('Once the following tasks are complete: ')."\\n".
8451: join(", ",sort(values(%locks)))."\\n".
8452: &mt('your session will be transferred to a different server, after you click "Roles".');
8453: } else {
8454: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8455: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
8456: }
8457: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8458: $newurl = '/adm/switchserver?otherserver='.$newserver;
8459: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8460: $newurl .= '&role='.$env{'request.role'};
8461: }
8462: if ($env{'request.symb'}) {
8463: $newurl .= '&symb='.$env{'request.symb'};
8464: } else {
8465: $newurl .= '&origurl='.$requrl;
8466: }
8467: }
1.1222 damieng 8468: &js_escape(\$msg);
1.1210 raeburn 8469: $result.=<<OFFLOAD
8470: <meta http-equiv="pragma" content="no-cache" />
8471: <script type="text/javascript">
1.1215 raeburn 8472: // <![CDATA[
1.1210 raeburn 8473: function LC_Offload_Now() {
8474: var dest = "$newurl";
8475: if (dest != '') {
8476: window.location.href="$newurl";
8477: }
8478: }
1.1214 raeburn 8479: \$(document).ready(function () {
8480: window.alert('$msg');
8481: if ($disable_submit) {
1.1210 raeburn 8482: \$(".LC_hwk_submit").prop("disabled", true);
8483: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8484: }
8485: setTimeout('LC_Offload_Now()', $timeout);
8486: });
1.1215 raeburn 8487: // ]]>
1.1210 raeburn 8488: </script>
8489: OFFLOAD
8490: }
8491: }
8492: }
8493: }
8494: }
8495: }
1.313 albertel 8496: }
1.306 albertel 8497: if (!defined($title)) {
8498: $title = 'The LearningOnline Network with CAPA';
8499: }
1.460 albertel 8500: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8501: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8502: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8503: if (!$args->{'frameset'}) {
8504: $result .= ' /';
8505: }
8506: $result .= '>'
1.1064 raeburn 8507: .$inhibitprint
1.414 albertel 8508: .$head_extra;
1.1242 raeburn 8509: my $clientmobile;
8510: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8511: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8512: } else {
8513: $clientmobile = $env{'browser.mobile'};
8514: }
8515: if ($clientmobile) {
1.1137 raeburn 8516: $result .= '
8517: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8518: <meta name="apple-mobile-web-app-capable" content="yes" />';
8519: }
1.1278 raeburn 8520: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8521: return $result.'</head>';
1.306 albertel 8522: }
8523:
8524: =pod
8525:
1.340 albertel 8526: =item * &font_settings()
8527:
8528: Returns neccessary <meta> to set the proper encoding
8529:
1.1160 raeburn 8530: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8531:
8532: =cut
8533:
8534: sub font_settings {
1.1160 raeburn 8535: my ($args) = @_;
1.340 albertel 8536: my $headerstring='';
1.1160 raeburn 8537: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8538: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8539: $headerstring.=
8540: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8541: if (!$args->{'frameset'}) {
8542: $headerstring.= ' /';
8543: }
8544: $headerstring .= '>'."\n";
1.340 albertel 8545: }
8546: return $headerstring;
8547: }
8548:
1.341 albertel 8549: =pod
8550:
1.1064 raeburn 8551: =item * &print_suppression()
8552:
8553: In course context returns css which causes the body to be blank when media="print",
8554: if printout generation is unavailable for the current resource.
8555:
8556: This could be because:
8557:
8558: (a) printstartdate is in the future
8559:
8560: (b) printenddate is in the past
8561:
8562: (c) there is an active exam block with "printout"
8563: functionality blocked
8564:
8565: Users with pav, pfo or evb privileges are exempt.
8566:
8567: Inputs: none
8568:
8569: =cut
8570:
8571:
8572: sub print_suppression {
8573: my $noprint;
8574: if ($env{'request.course.id'}) {
8575: my $scope = $env{'request.course.id'};
8576: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8577: (&Apache::lonnet::allowed('pfo',$scope))) {
8578: return;
8579: }
8580: if ($env{'request.course.sec'} ne '') {
8581: $scope .= "/$env{'request.course.sec'}";
8582: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8583: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8584: return;
1.1064 raeburn 8585: }
8586: }
8587: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8588: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8589: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8590: if ($blocked) {
8591: my $checkrole = "cm./$cdom/$cnum";
8592: if ($env{'request.course.sec'} ne '') {
8593: $checkrole .= "/$env{'request.course.sec'}";
8594: }
8595: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8596: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8597: $noprint = 1;
8598: }
8599: }
8600: unless ($noprint) {
8601: my $symb = &Apache::lonnet::symbread();
8602: if ($symb ne '') {
8603: my $navmap = Apache::lonnavmaps::navmap->new();
8604: if (ref($navmap)) {
8605: my $res = $navmap->getBySymb($symb);
8606: if (ref($res)) {
8607: if (!$res->resprintable()) {
8608: $noprint = 1;
8609: }
8610: }
8611: }
8612: }
8613: }
8614: if ($noprint) {
8615: return <<"ENDSTYLE";
8616: <style type="text/css" media="print">
8617: body { display:none }
8618: </style>
8619: ENDSTYLE
8620: }
8621: }
8622: return;
8623: }
8624:
8625: =pod
8626:
1.341 albertel 8627: =item * &xml_begin()
8628:
8629: Returns the needed doctype and <html>
8630:
8631: Inputs: none
8632:
8633: =cut
8634:
8635: sub xml_begin {
1.1168 raeburn 8636: my ($is_frameset) = @_;
1.341 albertel 8637: my $output='';
8638:
8639: if ($env{'browser.mathml'}) {
8640: $output='<?xml version="1.0"?>'
8641: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8642: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8643:
8644: # .'<!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">] >'
8645: .'<!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">'
8646: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8647: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8648: } elsif ($is_frameset) {
8649: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8650: '<html>'."\n";
1.341 albertel 8651: } else {
1.1168 raeburn 8652: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8653: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8654: }
8655: return $output;
8656: }
1.340 albertel 8657:
8658: =pod
8659:
1.306 albertel 8660: =item * &start_page()
8661:
8662: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8663:
1.648 raeburn 8664: Inputs:
8665:
8666: =over 4
8667:
8668: $title - optional title for the page
8669:
8670: $head_extra - optional extra HTML to incude inside the <head>
8671:
8672: $args - additional optional args supported are:
8673:
8674: =over 8
8675:
8676: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8677: arg on
1.814 bisitz 8678: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8679: add_entries -> additional attributes to add to the <body>
8680: domain -> force to color decorate a page for a
1.317 albertel 8681: specific domain
1.648 raeburn 8682: function -> force usage of a specific rolish color
1.317 albertel 8683: scheme
1.648 raeburn 8684: redirect -> see &headtag()
8685: bgcolor -> override the default page bg color
8686: js_ready -> return a string ready for being used in
1.317 albertel 8687: a javascript writeln
1.648 raeburn 8688: html_encode -> return a string ready for being used in
1.320 albertel 8689: a html attribute
1.648 raeburn 8690: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8691: $forcereg arg
1.648 raeburn 8692: frameset -> if true will start with a <frameset>
1.330 albertel 8693: rather than <body>
1.648 raeburn 8694: skip_phases -> hash ref of
1.338 albertel 8695: head -> skip the <html><head> generation
8696: body -> skip all <body> generation
1.648 raeburn 8697: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8698: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8699: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 8700: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8701: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 8702: group -> includes the current group, if page is for a
1.1274 raeburn 8703: specific group
8704: use_absolute -> for request for external resource or syllabus, this
8705: will contain https://<hostname> if server uses
8706: https (as per hosts.tab), but request is for http
8707: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8708:
1.648 raeburn 8709: =back
1.460 albertel 8710:
1.648 raeburn 8711: =back
1.562 albertel 8712:
1.306 albertel 8713: =cut
8714:
8715: sub start_page {
1.309 albertel 8716: my ($title,$head_extra,$args) = @_;
1.318 albertel 8717: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8718:
1.315 albertel 8719: $env{'internal.start_page'}++;
1.1318 raeburn 8720: my ($result,@advtools,$ltiscope,$ltiuri,%ltimenu);
1.964 droeschl 8721:
1.338 albertel 8722: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8723: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8724: }
1.1316 raeburn 8725:
8726: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
1.1318 raeburn 8727: if ($env{'course.'.$env{'request.course.id'}.'.lti.override'}) {
8728: unless ($env{'course.'.$env{'request.course.id'}.'.lti.topmenu'}) {
8729: $args->{'no_primary_menu'} = 1;
8730: }
8731: unless ($env{'course.'.$env{'request.course.id'}.'.lti.inlinemenu'}) {
8732: $args->{'no_inline_menu'} = 1;
8733: }
8734: if ($env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'}) {
8735: map { $ltimenu{$_} = 1; } split(/,/,$env{'course.'.$env{'request.course.id'}.'.lti.lcmenu'});
8736: }
8737: } else {
8738: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8739: my %lti = &Apache::lonnet::get_domain_lti($cdom,'provider');
8740: if (ref($lti{$env{'request.lti.login'}}) eq 'HASH') {
8741: unless ($lti{$env{'request.lti.login'}}{'topmenu'}) {
8742: $args->{'no_primary_menu'} = 1;
8743: }
8744: unless ($lti{$env{'request.lti.login'}}{'inlinemenu'}) {
8745: $args->{'no_inline_menu'} = 1;
8746: }
8747: if (ref($lti{$env{'request.lti.login'}}{'lcmenu'}) eq 'ARRAY') {
8748: map { $ltimenu{$_} = 1; } @{$lti{$env{'request.lti.login'}}{'lcmenu'}};
8749: }
8750: }
8751: }
1.1316 raeburn 8752: ($ltiscope,$ltiuri) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},
8753: $env{'course.'.$env{'request.course.id'}.'.domain'},
8754: $env{'course.'.$env{'request.course.id'}.'.num'});
8755: }
1.338 albertel 8756:
8757: if (! exists($args->{'skip_phases'}{'body'}) ) {
8758: if ($args->{'frameset'}) {
8759: my $attr_string = &make_attr_string($args->{'force_register'},
8760: $args->{'add_entries'});
8761: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8762: } else {
8763: $result .=
8764: &bodytag($title,
8765: $args->{'function'}, $args->{'add_entries'},
8766: $args->{'only_body'}, $args->{'domain'},
8767: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8768: $args->{'bgcolor'}, $args,
1.1318 raeburn 8769: \@advtools,$ltiscope,$ltiuri,\%ltimenu);
1.831 bisitz 8770: }
1.330 albertel 8771: }
1.338 albertel 8772:
1.315 albertel 8773: if ($args->{'js_ready'}) {
1.713 kaisler 8774: $result = &js_ready($result);
1.315 albertel 8775: }
1.320 albertel 8776: if ($args->{'html_encode'}) {
1.713 kaisler 8777: $result = &html_encode($result);
8778: }
8779:
1.813 bisitz 8780: # Preparation for new and consistent functionlist at top of screen
8781: # if ($args->{'functionlist'}) {
8782: # $result .= &build_functionlist();
8783: #}
8784:
1.964 droeschl 8785: # Don't add anything more if only_body wanted or in const space
8786: return $result if $args->{'only_body'}
8787: || $env{'request.state'} eq 'construct';
1.813 bisitz 8788:
8789: #Breadcrumbs
1.758 kaisler 8790: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8791: &Apache::lonhtmlcommon::clear_breadcrumbs();
8792: #if any br links exists, add them to the breadcrumbs
8793: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8794: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8795: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8796: }
8797: }
1.1096 raeburn 8798: # if @advtools array contains items add then to the breadcrumbs
8799: if (@advtools > 0) {
8800: &Apache::lonmenu::advtools_crumbs(@advtools);
8801: }
1.1272 raeburn 8802: my $menulink;
8803: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8804: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 raeburn 8805: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 8806: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
8807: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
8808: (!$env{'request.role.adv'}))) {
8809: $menulink = 0;
8810: } else {
8811: undef($menulink);
8812: }
1.758 kaisler 8813: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8814: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 8815: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 8816: } else {
1.1272 raeburn 8817: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8818: }
1.320 albertel 8819: }
1.315 albertel 8820: return $result;
1.306 albertel 8821: }
8822:
8823: sub end_page {
1.315 albertel 8824: my ($args) = @_;
8825: $env{'internal.end_page'}++;
1.330 albertel 8826: my $result;
1.335 albertel 8827: if ($args->{'discussion'}) {
8828: my ($target,$parser);
8829: if (ref($args->{'discussion'})) {
8830: ($target,$parser) =($args->{'discussion'}{'target'},
8831: $args->{'discussion'}{'parser'});
8832: }
8833: $result .= &Apache::lonxml::xmlend($target,$parser);
8834: }
1.330 albertel 8835: if ($args->{'frameset'}) {
8836: $result .= '</frameset>';
8837: } else {
1.635 raeburn 8838: $result .= &endbodytag($args);
1.330 albertel 8839: }
1.1080 raeburn 8840: unless ($args->{'notbody'}) {
8841: $result .= "\n</html>";
8842: }
1.330 albertel 8843:
1.315 albertel 8844: if ($args->{'js_ready'}) {
1.317 albertel 8845: $result = &js_ready($result);
1.315 albertel 8846: }
1.335 albertel 8847:
1.320 albertel 8848: if ($args->{'html_encode'}) {
8849: $result = &html_encode($result);
8850: }
1.335 albertel 8851:
1.315 albertel 8852: return $result;
8853: }
8854:
1.1034 www 8855: sub wishlist_window {
8856: return(<<'ENDWISHLIST');
1.1046 raeburn 8857: <script type="text/javascript">
1.1034 www 8858: // <![CDATA[
8859: // <!-- BEGIN LON-CAPA Internal
8860: function set_wishlistlink(title, path) {
8861: if (!title) {
8862: title = document.title;
8863: title = title.replace(/^LON-CAPA /,'');
8864: }
1.1175 raeburn 8865: title = encodeURIComponent(title);
1.1203 raeburn 8866: title = title.replace("'","\\\'");
1.1034 www 8867: if (!path) {
8868: path = location.pathname;
8869: }
1.1175 raeburn 8870: path = encodeURIComponent(path);
1.1203 raeburn 8871: path = path.replace("'","\\\'");
1.1034 www 8872: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8873: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8874: }
8875: // END LON-CAPA Internal -->
8876: // ]]>
8877: </script>
8878: ENDWISHLIST
8879: }
8880:
1.1030 www 8881: sub modal_window {
8882: return(<<'ENDMODAL');
1.1046 raeburn 8883: <script type="text/javascript">
1.1030 www 8884: // <![CDATA[
8885: // <!-- BEGIN LON-CAPA Internal
8886: var modalWindow = {
8887: parent:"body",
8888: windowId:null,
8889: content:null,
8890: width:null,
8891: height:null,
8892: close:function()
8893: {
8894: $(".LCmodal-window").remove();
8895: $(".LCmodal-overlay").remove();
8896: },
8897: open:function()
8898: {
8899: var modal = "";
8900: modal += "<div class=\"LCmodal-overlay\"></div>";
8901: 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;\">";
8902: modal += this.content;
8903: modal += "</div>";
8904:
8905: $(this.parent).append(modal);
8906:
8907: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8908: $(".LCclose-window").click(function(){modalWindow.close();});
8909: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8910: }
8911: };
1.1140 raeburn 8912: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8913: {
1.1266 raeburn 8914: source = source.replace(/'/g,"'");
1.1030 www 8915: modalWindow.windowId = "myModal";
8916: modalWindow.width = width;
8917: modalWindow.height = height;
1.1196 raeburn 8918: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8919: modalWindow.open();
1.1208 raeburn 8920: };
1.1030 www 8921: // END LON-CAPA Internal -->
8922: // ]]>
8923: </script>
8924: ENDMODAL
8925: }
8926:
8927: sub modal_link {
1.1140 raeburn 8928: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8929: unless ($width) { $width=480; }
8930: unless ($height) { $height=400; }
1.1031 www 8931: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 8932: unless ($transparency) { $transparency='true'; }
8933:
1.1074 raeburn 8934: my $target_attr;
8935: if (defined($target)) {
8936: $target_attr = 'target="'.$target.'"';
8937: }
8938: return <<"ENDLINK";
1.1140 raeburn 8939: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8940: $linktext</a>
8941: ENDLINK
1.1030 www 8942: }
8943:
1.1032 www 8944: sub modal_adhoc_script {
8945: my ($funcname,$width,$height,$content)=@_;
8946: return (<<ENDADHOC);
1.1046 raeburn 8947: <script type="text/javascript">
1.1032 www 8948: // <![CDATA[
8949: var $funcname = function()
8950: {
8951: modalWindow.windowId = "myModal";
8952: modalWindow.width = $width;
8953: modalWindow.height = $height;
8954: modalWindow.content = '$content';
8955: modalWindow.open();
8956: };
8957: // ]]>
8958: </script>
8959: ENDADHOC
8960: }
8961:
1.1041 www 8962: sub modal_adhoc_inner {
8963: my ($funcname,$width,$height,$content)=@_;
8964: my $innerwidth=$width-20;
8965: $content=&js_ready(
1.1140 raeburn 8966: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
8967: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8968: $content.
1.1041 www 8969: &end_scrollbox().
1.1140 raeburn 8970: &end_page()
1.1041 www 8971: );
8972: return &modal_adhoc_script($funcname,$width,$height,$content);
8973: }
8974:
8975: sub modal_adhoc_window {
8976: my ($funcname,$width,$height,$content,$linktext)=@_;
8977: return &modal_adhoc_inner($funcname,$width,$height,$content).
8978: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8979: }
8980:
8981: sub modal_adhoc_launch {
8982: my ($funcname,$width,$height,$content)=@_;
8983: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8984: <script type="text/javascript">
8985: // <![CDATA[
8986: $funcname();
8987: // ]]>
8988: </script>
8989: ENDLAUNCH
8990: }
8991:
8992: sub modal_adhoc_close {
8993: return (<<ENDCLOSE);
8994: <script type="text/javascript">
8995: // <![CDATA[
8996: modalWindow.close();
8997: // ]]>
8998: </script>
8999: ENDCLOSE
9000: }
9001:
1.1038 www 9002: sub togglebox_script {
9003: return(<<ENDTOGGLE);
9004: <script type="text/javascript">
9005: // <![CDATA[
9006: function LCtoggleDisplay(id,hidetext,showtext) {
9007: link = document.getElementById(id + "link").childNodes[0];
9008: with (document.getElementById(id).style) {
9009: if (display == "none" ) {
9010: display = "inline";
9011: link.nodeValue = hidetext;
9012: } else {
9013: display = "none";
9014: link.nodeValue = showtext;
9015: }
9016: }
9017: }
9018: // ]]>
9019: </script>
9020: ENDTOGGLE
9021: }
9022:
1.1039 www 9023: sub start_togglebox {
9024: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
9025: unless ($heading) { $heading=''; } else { $heading.=' '; }
9026: unless ($showtext) { $showtext=&mt('show'); }
9027: unless ($hidetext) { $hidetext=&mt('hide'); }
9028: unless ($headerbg) { $headerbg='#FFFFFF'; }
9029: return &start_data_table().
9030: &start_data_table_header_row().
9031: '<td bgcolor="'.$headerbg.'">'.$heading.
9032: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
9033: $showtext.'\')">'.$showtext.'</a>]</td>'.
9034: &end_data_table_header_row().
9035: '<tr id="'.$id.'" style="display:none""><td>';
9036: }
9037:
9038: sub end_togglebox {
9039: return '</td></tr>'.&end_data_table();
9040: }
9041:
1.1041 www 9042: sub LCprogressbar_script {
1.1302 raeburn 9043: my ($id,$number_to_do)=@_;
9044: if ($number_to_do) {
9045: return(<<ENDPROGRESS);
1.1041 www 9046: <script type="text/javascript">
9047: // <![CDATA[
1.1045 www 9048: \$('#progressbar$id').progressbar({
1.1041 www 9049: value: 0,
9050: change: function(event, ui) {
9051: var newVal = \$(this).progressbar('option', 'value');
9052: \$('.pblabel', this).text(LCprogressTxt);
9053: }
9054: });
9055: // ]]>
9056: </script>
9057: ENDPROGRESS
1.1302 raeburn 9058: } else {
9059: return(<<ENDPROGRESS);
9060: <script type="text/javascript">
9061: // <![CDATA[
9062: \$('#progressbar$id').progressbar({
9063: value: false,
9064: create: function(event, ui) {
9065: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
9066: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
9067: }
9068: });
9069: // ]]>
9070: </script>
9071: ENDPROGRESS
9072: }
1.1041 www 9073: }
9074:
9075: sub LCprogressbarUpdate_script {
9076: return(<<ENDPROGRESSUPDATE);
9077: <style type="text/css">
9078: .ui-progressbar { position:relative; }
1.1302 raeburn 9079: .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 9080: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9081: </style>
9082: <script type="text/javascript">
9083: // <![CDATA[
1.1045 www 9084: var LCprogressTxt='---';
9085:
1.1302 raeburn 9086: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9087: LCprogressTxt=progresstext;
1.1302 raeburn 9088: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9089: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9090: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 9091: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9092: } else {
9093: \$('#progressbar'+id).progressbar('value',percent);
9094: }
1.1041 www 9095: }
9096: // ]]>
9097: </script>
9098: ENDPROGRESSUPDATE
9099: }
9100:
1.1042 www 9101: my $LClastpercent;
1.1045 www 9102: my $LCidcnt;
9103: my $LCcurrentid;
1.1042 www 9104:
1.1041 www 9105: sub LCprogressbar {
1.1302 raeburn 9106: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9107: $LClastpercent=0;
1.1045 www 9108: $LCidcnt++;
9109: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 9110: my ($starting,$content);
9111: if ($number_to_do) {
9112: $starting=&mt('Starting');
9113: $content=(<<ENDPROGBAR);
9114: $preamble
1.1045 www 9115: <div id="progressbar$LCcurrentid">
1.1041 www 9116: <span class="pblabel">$starting</span>
9117: </div>
9118: ENDPROGBAR
1.1302 raeburn 9119: } else {
9120: $starting=&mt('Loading...');
9121: $LClastpercent='false';
9122: $content=(<<ENDPROGBAR);
9123: $preamble
9124: <div id="progressbar$LCcurrentid">
9125: <div class="progress-label">$starting</div>
9126: </div>
9127: ENDPROGBAR
9128: }
9129: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9130: }
9131:
9132: sub LCprogressbarUpdate {
1.1302 raeburn 9133: my ($r,$val,$text,$number_to_do)=@_;
9134: if ($number_to_do) {
9135: unless ($val) {
9136: if ($LClastpercent) {
9137: $val=$LClastpercent;
9138: } else {
9139: $val=0;
9140: }
9141: }
9142: if ($val<0) { $val=0; }
9143: if ($val>100) { $val=0; }
9144: $LClastpercent=$val;
9145: unless ($text) { $text=$val.'%'; }
9146: } else {
9147: $val = 'false';
1.1042 www 9148: }
1.1041 www 9149: $text=&js_ready($text);
1.1044 www 9150: &r_print($r,<<ENDUPDATE);
1.1041 www 9151: <script type="text/javascript">
9152: // <![CDATA[
1.1302 raeburn 9153: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9154: // ]]>
9155: </script>
9156: ENDUPDATE
1.1035 www 9157: }
9158:
1.1042 www 9159: sub LCprogressbarClose {
9160: my ($r)=@_;
9161: $LClastpercent=0;
1.1044 www 9162: &r_print($r,<<ENDCLOSE);
1.1042 www 9163: <script type="text/javascript">
9164: // <![CDATA[
1.1045 www 9165: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9166: // ]]>
9167: </script>
9168: ENDCLOSE
1.1044 www 9169: }
9170:
9171: sub r_print {
9172: my ($r,$to_print)=@_;
9173: if ($r) {
9174: $r->print($to_print);
9175: $r->rflush();
9176: } else {
9177: print($to_print);
9178: }
1.1042 www 9179: }
9180:
1.320 albertel 9181: sub html_encode {
9182: my ($result) = @_;
9183:
1.322 albertel 9184: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9185:
9186: return $result;
9187: }
1.1044 www 9188:
1.317 albertel 9189: sub js_ready {
9190: my ($result) = @_;
9191:
1.323 albertel 9192: $result =~ s/[\n\r]/ /xmsg;
9193: $result =~ s/\\/\\\\/xmsg;
9194: $result =~ s/'/\\'/xmsg;
1.372 albertel 9195: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9196:
9197: return $result;
9198: }
9199:
1.315 albertel 9200: sub validate_page {
9201: if ( exists($env{'internal.start_page'})
1.316 albertel 9202: && $env{'internal.start_page'} > 1) {
9203: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9204: $env{'internal.start_page'}.' '.
1.316 albertel 9205: $ENV{'request.filename'});
1.315 albertel 9206: }
9207: if ( exists($env{'internal.end_page'})
1.316 albertel 9208: && $env{'internal.end_page'} > 1) {
9209: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9210: $env{'internal.end_page'}.' '.
1.316 albertel 9211: $env{'request.filename'});
1.315 albertel 9212: }
9213: if ( exists($env{'internal.start_page'})
9214: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9215: &Apache::lonnet::logthis('start_page called without end_page '.
9216: $env{'request.filename'});
1.315 albertel 9217: }
9218: if ( ! exists($env{'internal.start_page'})
9219: && exists($env{'internal.end_page'})) {
1.316 albertel 9220: &Apache::lonnet::logthis('end_page called without start_page'.
9221: $env{'request.filename'});
1.315 albertel 9222: }
1.306 albertel 9223: }
1.315 albertel 9224:
1.996 www 9225:
9226: sub start_scrollbox {
1.1140 raeburn 9227: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9228: unless ($outerwidth) { $outerwidth='520px'; }
9229: unless ($width) { $width='500px'; }
9230: unless ($height) { $height='200px'; }
1.1075 raeburn 9231: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9232: if ($id ne '') {
1.1140 raeburn 9233: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9234: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9235: }
1.1075 raeburn 9236: if ($bgcolor ne '') {
9237: $tdcol = "background-color: $bgcolor;";
9238: }
1.1137 raeburn 9239: my $nicescroll_js;
9240: if ($env{'browser.mobile'}) {
1.1140 raeburn 9241: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9242: }
9243: return <<"END";
9244: $nicescroll_js
9245:
9246: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9247: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9248: END
9249: }
9250:
9251: sub end_scrollbox {
9252: return '</div></td></tr></table>';
9253: }
9254:
9255: sub nicescroll_javascript {
9256: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9257: my %options;
9258: if (ref($cursor) eq 'HASH') {
9259: %options = %{$cursor};
9260: }
9261: unless ($options{'railalign'} =~ /^left|right$/) {
9262: $options{'railalign'} = 'left';
9263: }
9264: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9265: my $function = &get_users_function();
9266: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9267: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9268: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9269: }
1.1140 raeburn 9270: }
9271: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9272: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9273: $options{'cursoropacity'}='1.0';
9274: }
1.1140 raeburn 9275: } else {
9276: $options{'cursoropacity'}='1.0';
9277: }
9278: if ($options{'cursorfixedheight'} eq 'none') {
9279: delete($options{'cursorfixedheight'});
9280: } else {
9281: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9282: }
9283: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9284: delete($options{'railoffset'});
9285: }
9286: my @niceoptions;
9287: while (my($key,$value) = each(%options)) {
9288: if ($value =~ /^\{.+\}$/) {
9289: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9290: } else {
1.1140 raeburn 9291: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9292: }
1.1140 raeburn 9293: }
9294: my $nicescroll_js = '
1.1137 raeburn 9295: $(document).ready(
1.1140 raeburn 9296: function() {
9297: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9298: }
1.1137 raeburn 9299: );
9300: ';
1.1140 raeburn 9301: if ($framecheck) {
9302: $nicescroll_js .= '
9303: function expand_div(caller) {
9304: if (top === self) {
9305: document.getElementById("'.$id.'").style.width = "auto";
9306: document.getElementById("'.$id.'").style.height = "auto";
9307: } else {
9308: try {
9309: if (parent.frames) {
9310: if (parent.frames.length > 1) {
9311: var framesrc = parent.frames[1].location.href;
9312: var currsrc = framesrc.replace(/\#.*$/,"");
9313: if ((caller == "search") || (currsrc == "'.$location.'")) {
9314: document.getElementById("'.$id.'").style.width = "auto";
9315: document.getElementById("'.$id.'").style.height = "auto";
9316: }
9317: }
9318: }
9319: } catch (e) {
9320: return;
9321: }
1.1137 raeburn 9322: }
1.1140 raeburn 9323: return;
1.996 www 9324: }
1.1140 raeburn 9325: ';
9326: }
9327: if ($needjsready) {
9328: $nicescroll_js = '
9329: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9330: } else {
9331: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9332: }
9333: return $nicescroll_js;
1.996 www 9334: }
9335:
1.318 albertel 9336: sub simple_error_page {
1.1150 bisitz 9337: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 9338: my %displayargs;
1.1151 raeburn 9339: if (ref($args) eq 'HASH') {
9340: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 9341: if ($args->{'only_body'}) {
9342: $displayargs{'only_body'} = 1;
9343: }
9344: if ($args->{'no_nav_bar'}) {
9345: $displayargs{'no_nav_bar'} = 1;
9346: }
1.1151 raeburn 9347: } else {
9348: $msg = &mt($msg);
9349: }
1.1150 bisitz 9350:
1.318 albertel 9351: my $page =
1.1304 raeburn 9352: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 9353: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9354: &Apache::loncommon::end_page();
9355: if (ref($r)) {
9356: $r->print($page);
1.327 albertel 9357: return;
1.318 albertel 9358: }
9359: return $page;
9360: }
1.347 albertel 9361:
9362: {
1.610 albertel 9363: my @row_count;
1.961 onken 9364:
9365: sub start_data_table_count {
9366: unshift(@row_count, 0);
9367: return;
9368: }
9369:
9370: sub end_data_table_count {
9371: shift(@row_count);
9372: return;
9373: }
9374:
1.347 albertel 9375: sub start_data_table {
1.1018 raeburn 9376: my ($add_class,$id) = @_;
1.422 albertel 9377: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9378: my $table_id;
9379: if (defined($id)) {
9380: $table_id = ' id="'.$id.'"';
9381: }
1.961 onken 9382: &start_data_table_count();
1.1018 raeburn 9383: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9384: }
9385:
9386: sub end_data_table {
1.961 onken 9387: &end_data_table_count();
1.389 albertel 9388: return '</table>'."\n";;
1.347 albertel 9389: }
9390:
9391: sub start_data_table_row {
1.974 wenzelju 9392: my ($add_class, $id) = @_;
1.610 albertel 9393: $row_count[0]++;
9394: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9395: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9396: $id = (' id="'.$id.'"') unless ($id eq '');
9397: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9398: }
1.471 banghart 9399:
9400: sub continue_data_table_row {
1.974 wenzelju 9401: my ($add_class, $id) = @_;
1.610 albertel 9402: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9403: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9404: $id = (' id="'.$id.'"') unless ($id eq '');
9405: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9406: }
1.347 albertel 9407:
9408: sub end_data_table_row {
1.389 albertel 9409: return '</tr>'."\n";;
1.347 albertel 9410: }
1.367 www 9411:
1.421 albertel 9412: sub start_data_table_empty_row {
1.707 bisitz 9413: # $row_count[0]++;
1.421 albertel 9414: return '<tr class="LC_empty_row" >'."\n";;
9415: }
9416:
9417: sub end_data_table_empty_row {
9418: return '</tr>'."\n";;
9419: }
9420:
1.367 www 9421: sub start_data_table_header_row {
1.389 albertel 9422: return '<tr class="LC_header_row">'."\n";;
1.367 www 9423: }
9424:
9425: sub end_data_table_header_row {
1.389 albertel 9426: return '</tr>'."\n";;
1.367 www 9427: }
1.890 droeschl 9428:
9429: sub data_table_caption {
9430: my $caption = shift;
9431: return "<caption class=\"LC_caption\">$caption</caption>";
9432: }
1.347 albertel 9433: }
9434:
1.548 albertel 9435: =pod
9436:
9437: =item * &inhibit_menu_check($arg)
9438:
9439: Checks for a inhibitmenu state and generates output to preserve it
9440:
9441: Inputs: $arg - can be any of
9442: - undef - in which case the return value is a string
9443: to add into arguments list of a uri
9444: - 'input' - in which case the return value is a HTML
9445: <form> <input> field of type hidden to
9446: preserve the value
9447: - a url - in which case the return value is the url with
9448: the neccesary cgi args added to preserve the
9449: inhibitmenu state
9450: - a ref to a url - no return value, but the string is
9451: updated to include the neccessary cgi
9452: args to preserve the inhibitmenu state
9453:
9454: =cut
9455:
9456: sub inhibit_menu_check {
9457: my ($arg) = @_;
9458: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9459: if ($arg eq 'input') {
9460: if ($env{'form.inhibitmenu'}) {
9461: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9462: } else {
9463: return
9464: }
9465: }
9466: if ($env{'form.inhibitmenu'}) {
9467: if (ref($arg)) {
9468: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9469: } elsif ($arg eq '') {
9470: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9471: } else {
9472: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9473: }
9474: }
9475: if (!ref($arg)) {
9476: return $arg;
9477: }
9478: }
9479:
1.251 albertel 9480: ###############################################
1.182 matthew 9481:
9482: =pod
9483:
1.549 albertel 9484: =back
9485:
9486: =head1 User Information Routines
9487:
9488: =over 4
9489:
1.405 albertel 9490: =item * &get_users_function()
1.182 matthew 9491:
9492: Used by &bodytag to determine the current users primary role.
9493: Returns either 'student','coordinator','admin', or 'author'.
9494:
9495: =cut
9496:
9497: ###############################################
9498: sub get_users_function {
1.815 tempelho 9499: my $function = 'norole';
1.818 tempelho 9500: if ($env{'request.role'}=~/^(st)/) {
9501: $function='student';
9502: }
1.907 raeburn 9503: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9504: $function='coordinator';
9505: }
1.258 albertel 9506: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9507: $function='admin';
9508: }
1.826 bisitz 9509: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9510: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9511: $function='author';
9512: }
9513: return $function;
1.54 www 9514: }
1.99 www 9515:
9516: ###############################################
9517:
1.233 raeburn 9518: =pod
9519:
1.821 raeburn 9520: =item * &show_course()
9521:
9522: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9523: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9524:
9525: Inputs:
9526: None
9527:
9528: Outputs:
9529: Scalar: 1 if 'Course' to be used, 0 otherwise.
9530:
9531: =cut
9532:
9533: ###############################################
9534: sub show_course {
9535: my $course = !$env{'user.adv'};
9536: if (!$env{'user.adv'}) {
9537: foreach my $env (keys(%env)) {
9538: next if ($env !~ m/^user\.priv\./);
9539: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9540: $course = 0;
9541: last;
9542: }
9543: }
9544: }
9545: return $course;
9546: }
9547:
9548: ###############################################
9549:
9550: =pod
9551:
1.542 raeburn 9552: =item * &check_user_status()
1.274 raeburn 9553:
9554: Determines current status of supplied role for a
9555: specific user. Roles can be active, previous or future.
9556:
9557: Inputs:
9558: user's domain, user's username, course's domain,
1.375 raeburn 9559: course's number, optional section ID.
1.274 raeburn 9560:
9561: Outputs:
9562: role status: active, previous or future.
9563:
9564: =cut
9565:
9566: sub check_user_status {
1.412 raeburn 9567: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9568: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9569: my @uroles = keys(%userinfo);
1.274 raeburn 9570: my $srchstr;
9571: my $active_chk = 'none';
1.412 raeburn 9572: my $now = time;
1.274 raeburn 9573: if (@uroles > 0) {
1.908 raeburn 9574: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9575: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9576: } else {
1.412 raeburn 9577: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9578: }
9579: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9580: my $role_end = 0;
9581: my $role_start = 0;
9582: $active_chk = 'active';
1.412 raeburn 9583: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9584: $role_end = $1;
9585: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9586: $role_start = $1;
1.274 raeburn 9587: }
9588: }
9589: if ($role_start > 0) {
1.412 raeburn 9590: if ($now < $role_start) {
1.274 raeburn 9591: $active_chk = 'future';
9592: }
9593: }
9594: if ($role_end > 0) {
1.412 raeburn 9595: if ($now > $role_end) {
1.274 raeburn 9596: $active_chk = 'previous';
9597: }
9598: }
9599: }
9600: }
9601: return $active_chk;
9602: }
9603:
9604: ###############################################
9605:
9606: =pod
9607:
1.405 albertel 9608: =item * &get_sections()
1.233 raeburn 9609:
9610: Determines all the sections for a course including
9611: sections with students and sections containing other roles.
1.419 raeburn 9612: Incoming parameters:
9613:
9614: 1. domain
9615: 2. course number
9616: 3. reference to array containing roles for which sections should
9617: be gathered (optional).
9618: 4. reference to array containing status types for which sections
9619: should be gathered (optional).
9620:
9621: If the third argument is undefined, sections are gathered for any role.
9622: If the fourth argument is undefined, sections are gathered for any status.
9623: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9624:
1.374 raeburn 9625: Returns section hash (keys are section IDs, values are
9626: number of users in each section), subject to the
1.419 raeburn 9627: optional roles filter, optional status filter
1.233 raeburn 9628:
9629: =cut
9630:
9631: ###############################################
9632: sub get_sections {
1.419 raeburn 9633: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9634: if (!defined($cdom) || !defined($cnum)) {
9635: my $cid = $env{'request.course.id'};
9636:
9637: return if (!defined($cid));
9638:
9639: $cdom = $env{'course.'.$cid.'.domain'};
9640: $cnum = $env{'course.'.$cid.'.num'};
9641: }
9642:
9643: my %sectioncount;
1.419 raeburn 9644: my $now = time;
1.240 albertel 9645:
1.1118 raeburn 9646: my $check_students = 1;
9647: my $only_students = 0;
9648: if (ref($possible_roles) eq 'ARRAY') {
9649: if (grep(/^st$/,@{$possible_roles})) {
9650: if (@{$possible_roles} == 1) {
9651: $only_students = 1;
9652: }
9653: } else {
9654: $check_students = 0;
9655: }
9656: }
9657:
9658: if ($check_students) {
1.276 albertel 9659: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9660: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9661: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9662: my $start_index = &Apache::loncoursedata::CL_START();
9663: my $end_index = &Apache::loncoursedata::CL_END();
9664: my $status;
1.366 albertel 9665: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9666: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9667: $data->[$status_index],
9668: $data->[$start_index],
9669: $data->[$end_index]);
9670: if ($stu_status eq 'Active') {
9671: $status = 'active';
9672: } elsif ($end < $now) {
9673: $status = 'previous';
9674: } elsif ($start > $now) {
9675: $status = 'future';
9676: }
9677: if ($section ne '-1' && $section !~ /^\s*$/) {
9678: if ((!defined($possible_status)) || (($status ne '') &&
9679: (grep/^\Q$status\E$/,@{$possible_status}))) {
9680: $sectioncount{$section}++;
9681: }
1.240 albertel 9682: }
9683: }
9684: }
1.1118 raeburn 9685: if ($only_students) {
9686: return %sectioncount;
9687: }
1.240 albertel 9688: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9689: foreach my $user (sort(keys(%courseroles))) {
9690: if ($user !~ /^(\w{2})/) { next; }
9691: my ($role) = ($user =~ /^(\w{2})/);
9692: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9693: my ($section,$status);
1.240 albertel 9694: if ($role eq 'cr' &&
9695: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9696: $section=$1;
9697: }
9698: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9699: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9700: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9701: if ($end == -1 && $start == -1) {
9702: next; #deleted role
9703: }
9704: if (!defined($possible_status)) {
9705: $sectioncount{$section}++;
9706: } else {
9707: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9708: $status = 'active';
9709: } elsif ($end < $now) {
9710: $status = 'future';
9711: } elsif ($start > $now) {
9712: $status = 'previous';
9713: }
9714: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9715: $sectioncount{$section}++;
9716: }
9717: }
1.233 raeburn 9718: }
1.366 albertel 9719: return %sectioncount;
1.233 raeburn 9720: }
9721:
1.274 raeburn 9722: ###############################################
1.294 raeburn 9723:
9724: =pod
1.405 albertel 9725:
9726: =item * &get_course_users()
9727:
1.275 raeburn 9728: Retrieves usernames:domains for users in the specified course
9729: with specific role(s), and access status.
9730:
9731: Incoming parameters:
1.277 albertel 9732: 1. course domain
9733: 2. course number
9734: 3. access status: users must have - either active,
1.275 raeburn 9735: previous, future, or all.
1.277 albertel 9736: 4. reference to array of permissible roles
1.288 raeburn 9737: 5. reference to array of section restrictions (optional)
9738: 6. reference to results object (hash of hashes).
9739: 7. reference to optional userdata hash
1.609 raeburn 9740: 8. reference to optional statushash
1.630 raeburn 9741: 9. flag if privileged users (except those set to unhide in
9742: course settings) should be excluded
1.609 raeburn 9743: Keys of top level results hash are roles.
1.275 raeburn 9744: Keys of inner hashes are username:domain, with
9745: values set to access type.
1.288 raeburn 9746: Optional userdata hash returns an array with arguments in the
9747: same order as loncoursedata::get_classlist() for student data.
9748:
1.609 raeburn 9749: Optional statushash returns
9750:
1.288 raeburn 9751: Entries for end, start, section and status are blank because
9752: of the possibility of multiple values for non-student roles.
9753:
1.275 raeburn 9754: =cut
1.405 albertel 9755:
1.275 raeburn 9756: ###############################################
1.405 albertel 9757:
1.275 raeburn 9758: sub get_course_users {
1.630 raeburn 9759: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9760: my %idx = ();
1.419 raeburn 9761: my %seclists;
1.288 raeburn 9762:
9763: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9764: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9765: $idx{end} = &Apache::loncoursedata::CL_END();
9766: $idx{start} = &Apache::loncoursedata::CL_START();
9767: $idx{id} = &Apache::loncoursedata::CL_ID();
9768: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9769: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9770: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9771:
1.290 albertel 9772: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9773: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9774: my $now = time;
1.277 albertel 9775: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9776: my $match = 0;
1.412 raeburn 9777: my $secmatch = 0;
1.419 raeburn 9778: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9779: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9780: if ($section eq '') {
9781: $section = 'none';
9782: }
1.291 albertel 9783: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9784: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9785: $secmatch = 1;
9786: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9787: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9788: $secmatch = 1;
9789: }
9790: } else {
1.419 raeburn 9791: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9792: $secmatch = 1;
9793: }
1.290 albertel 9794: }
1.412 raeburn 9795: if (!$secmatch) {
9796: next;
9797: }
1.419 raeburn 9798: }
1.275 raeburn 9799: if (defined($$types{'active'})) {
1.288 raeburn 9800: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9801: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9802: $match = 1;
1.275 raeburn 9803: }
9804: }
9805: if (defined($$types{'previous'})) {
1.609 raeburn 9806: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9807: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9808: $match = 1;
1.275 raeburn 9809: }
9810: }
9811: if (defined($$types{'future'})) {
1.609 raeburn 9812: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9813: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9814: $match = 1;
1.275 raeburn 9815: }
9816: }
1.609 raeburn 9817: if ($match) {
9818: push(@{$seclists{$student}},$section);
9819: if (ref($userdata) eq 'HASH') {
9820: $$userdata{$student} = $$classlist{$student};
9821: }
9822: if (ref($statushash) eq 'HASH') {
9823: $statushash->{$student}{'st'}{$section} = $status;
9824: }
1.288 raeburn 9825: }
1.275 raeburn 9826: }
9827: }
1.412 raeburn 9828: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9829: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9830: my $now = time;
1.609 raeburn 9831: my %displaystatus = ( previous => 'Expired',
9832: active => 'Active',
9833: future => 'Future',
9834: );
1.1121 raeburn 9835: my (%nothide,@possdoms);
1.630 raeburn 9836: if ($hidepriv) {
9837: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9838: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9839: if ($user !~ /:/) {
9840: $nothide{join(':',split(/[\@]/,$user))}=1;
9841: } else {
9842: $nothide{$user} = 1;
9843: }
9844: }
1.1121 raeburn 9845: my @possdoms = ($cdom);
9846: if ($coursehash{'checkforpriv'}) {
9847: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9848: }
1.630 raeburn 9849: }
1.439 raeburn 9850: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9851: my $match = 0;
1.412 raeburn 9852: my $secmatch = 0;
1.439 raeburn 9853: my $status;
1.412 raeburn 9854: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9855: $user =~ s/:$//;
1.439 raeburn 9856: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9857: if ($end == -1 || $start == -1) {
9858: next;
9859: }
9860: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9861: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9862: my ($uname,$udom) = split(/:/,$user);
9863: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9864: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9865: $secmatch = 1;
9866: } elsif ($usec eq '') {
1.420 albertel 9867: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9868: $secmatch = 1;
9869: }
9870: } else {
9871: if (grep(/^\Q$usec\E$/,@{$sections})) {
9872: $secmatch = 1;
9873: }
9874: }
9875: if (!$secmatch) {
9876: next;
9877: }
1.288 raeburn 9878: }
1.419 raeburn 9879: if ($usec eq '') {
9880: $usec = 'none';
9881: }
1.275 raeburn 9882: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9883: if ($hidepriv) {
1.1121 raeburn 9884: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9885: (!$nothide{$uname.':'.$udom})) {
9886: next;
9887: }
9888: }
1.503 raeburn 9889: if ($end > 0 && $end < $now) {
1.439 raeburn 9890: $status = 'previous';
9891: } elsif ($start > $now) {
9892: $status = 'future';
9893: } else {
9894: $status = 'active';
9895: }
1.277 albertel 9896: foreach my $type (keys(%{$types})) {
1.275 raeburn 9897: if ($status eq $type) {
1.420 albertel 9898: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9899: push(@{$$users{$role}{$user}},$type);
9900: }
1.288 raeburn 9901: $match = 1;
9902: }
9903: }
1.419 raeburn 9904: if (($match) && (ref($userdata) eq 'HASH')) {
9905: if (!exists($$userdata{$uname.':'.$udom})) {
9906: &get_user_info($udom,$uname,\%idx,$userdata);
9907: }
1.420 albertel 9908: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9909: push(@{$seclists{$uname.':'.$udom}},$usec);
9910: }
1.609 raeburn 9911: if (ref($statushash) eq 'HASH') {
9912: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9913: }
1.275 raeburn 9914: }
9915: }
9916: }
9917: }
1.290 albertel 9918: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9919: if ((defined($cdom)) && (defined($cnum))) {
9920: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9921: if ( defined($csettings{'internal.courseowner'}) ) {
9922: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9923: next if ($owner eq '');
9924: my ($ownername,$ownerdom);
9925: if ($owner =~ /^([^:]+):([^:]+)$/) {
9926: $ownername = $1;
9927: $ownerdom = $2;
9928: } else {
9929: $ownername = $owner;
9930: $ownerdom = $cdom;
9931: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9932: }
9933: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9934: if (defined($userdata) &&
1.609 raeburn 9935: !exists($$userdata{$owner})) {
9936: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9937: if (!grep(/^none$/,@{$seclists{$owner}})) {
9938: push(@{$seclists{$owner}},'none');
9939: }
9940: if (ref($statushash) eq 'HASH') {
9941: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9942: }
1.290 albertel 9943: }
1.279 raeburn 9944: }
9945: }
9946: }
1.419 raeburn 9947: foreach my $user (keys(%seclists)) {
9948: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9949: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9950: }
1.275 raeburn 9951: }
9952: return;
9953: }
9954:
1.288 raeburn 9955: sub get_user_info {
9956: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9957: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9958: &plainname($uname,$udom,'lastname');
1.291 albertel 9959: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9960: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9961: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9962: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9963: return;
9964: }
1.275 raeburn 9965:
1.472 raeburn 9966: ###############################################
9967:
9968: =pod
9969:
9970: =item * &get_user_quota()
9971:
1.1134 raeburn 9972: Retrieves quota assigned for storage of user files.
9973: Default is to report quota for portfolio files.
1.472 raeburn 9974:
9975: Incoming parameters:
9976: 1. user's username
9977: 2. user's domain
1.1134 raeburn 9978: 3. quota name - portfolio, author, or course
1.1136 raeburn 9979: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 9980: 4. crstype - official, unofficial, textbook, placement or community,
9981: if quota name is course
1.472 raeburn 9982:
9983: Returns:
1.1163 raeburn 9984: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9985: 2. (Optional) Type of setting: custom or default
9986: (individually assigned or default for user's
9987: institutional status).
9988: 3. (Optional) - User's institutional status (e.g., faculty, staff
9989: or student - types as defined in localenroll::inst_usertypes
9990: for user's domain, which determines default quota for user.
9991: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9992:
9993: If a value has been stored in the user's environment,
1.536 raeburn 9994: it will return that, otherwise it returns the maximal default
1.1134 raeburn 9995: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9996:
9997: =cut
9998:
9999: ###############################################
10000:
10001:
10002: sub get_user_quota {
1.1136 raeburn 10003: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 10004: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 10005: if (!defined($udom)) {
10006: $udom = $env{'user.domain'};
10007: }
10008: if (!defined($uname)) {
10009: $uname = $env{'user.name'};
10010: }
10011: if (($udom eq '' || $uname eq '') ||
10012: ($udom eq 'public') && ($uname eq 'public')) {
10013: $quota = 0;
1.536 raeburn 10014: $quotatype = 'default';
10015: $defquota = 0;
1.472 raeburn 10016: } else {
1.536 raeburn 10017: my $inststatus;
1.1134 raeburn 10018: if ($quotaname eq 'course') {
10019: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
10020: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
10021: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
10022: } else {
10023: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
10024: $quota = $cenv{'internal.uploadquota'};
10025: }
1.536 raeburn 10026: } else {
1.1134 raeburn 10027: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
10028: if ($quotaname eq 'author') {
10029: $quota = $env{'environment.authorquota'};
10030: } else {
10031: $quota = $env{'environment.portfolioquota'};
10032: }
10033: $inststatus = $env{'environment.inststatus'};
10034: } else {
10035: my %userenv =
10036: &Apache::lonnet::get('environment',['portfolioquota',
10037: 'authorquota','inststatus'],$udom,$uname);
10038: my ($tmp) = keys(%userenv);
10039: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
10040: if ($quotaname eq 'author') {
10041: $quota = $userenv{'authorquota'};
10042: } else {
10043: $quota = $userenv{'portfolioquota'};
10044: }
10045: $inststatus = $userenv{'inststatus'};
10046: } else {
10047: undef(%userenv);
10048: }
10049: }
10050: }
10051: if ($quota eq '' || wantarray) {
10052: if ($quotaname eq 'course') {
10053: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 10054: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 10055: ($crstype eq 'community') || ($crstype eq 'textbook') ||
10056: ($crstype eq 'placement')) {
1.1136 raeburn 10057: $defquota = $domdefs{$crstype.'quota'};
10058: }
10059: if ($defquota eq '') {
10060: $defquota = 500;
10061: }
1.1134 raeburn 10062: } else {
10063: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
10064: }
10065: if ($quota eq '') {
10066: $quota = $defquota;
10067: $quotatype = 'default';
10068: } else {
10069: $quotatype = 'custom';
10070: }
1.472 raeburn 10071: }
10072: }
1.536 raeburn 10073: if (wantarray) {
10074: return ($quota,$quotatype,$settingstatus,$defquota);
10075: } else {
10076: return $quota;
10077: }
1.472 raeburn 10078: }
10079:
10080: ###############################################
10081:
10082: =pod
10083:
10084: =item * &default_quota()
10085:
1.536 raeburn 10086: Retrieves default quota assigned for storage of user portfolio files,
10087: given an (optional) user's institutional status.
1.472 raeburn 10088:
10089: Incoming parameters:
1.1142 raeburn 10090:
1.472 raeburn 10091: 1. domain
1.536 raeburn 10092: 2. (Optional) institutional status(es). This is a : separated list of
10093: status types (e.g., faculty, staff, student etc.)
10094: which apply to the user for whom the default is being retrieved.
10095: If the institutional status string in undefined, the domain
1.1134 raeburn 10096: default quota will be returned.
10097: 3. quota name - portfolio, author, or course
10098: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10099:
10100: Returns:
1.1142 raeburn 10101:
1.1163 raeburn 10102: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10103: 2. (Optional) institutional type which determined the value of the
10104: default quota.
1.472 raeburn 10105:
10106: If a value has been stored in the domain's configuration db,
10107: it will return that, otherwise it returns 20 (for backwards
10108: compatibility with domains which have not set up a configuration
1.1163 raeburn 10109: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10110:
1.536 raeburn 10111: If the user's status includes multiple types (e.g., staff and student),
10112: the largest default quota which applies to the user determines the
10113: default quota returned.
10114:
1.472 raeburn 10115: =cut
10116:
10117: ###############################################
10118:
10119:
10120: sub default_quota {
1.1134 raeburn 10121: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10122: my ($defquota,$settingstatus);
10123: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10124: ['quotas'],$udom);
1.1134 raeburn 10125: my $key = 'defaultquota';
10126: if ($quotaname eq 'author') {
10127: $key = 'authorquota';
10128: }
1.622 raeburn 10129: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10130: if ($inststatus ne '') {
1.765 raeburn 10131: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10132: foreach my $item (@statuses) {
1.1134 raeburn 10133: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10134: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10135: if ($defquota eq '') {
1.1134 raeburn 10136: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10137: $settingstatus = $item;
1.1134 raeburn 10138: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10139: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10140: $settingstatus = $item;
10141: }
10142: }
1.1134 raeburn 10143: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10144: if ($quotahash{'quotas'}{$item} ne '') {
10145: if ($defquota eq '') {
10146: $defquota = $quotahash{'quotas'}{$item};
10147: $settingstatus = $item;
10148: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10149: $defquota = $quotahash{'quotas'}{$item};
10150: $settingstatus = $item;
10151: }
1.536 raeburn 10152: }
10153: }
10154: }
10155: }
10156: if ($defquota eq '') {
1.1134 raeburn 10157: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10158: $defquota = $quotahash{'quotas'}{$key}{'default'};
10159: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10160: $defquota = $quotahash{'quotas'}{'default'};
10161: }
1.536 raeburn 10162: $settingstatus = 'default';
1.1139 raeburn 10163: if ($defquota eq '') {
10164: if ($quotaname eq 'author') {
10165: $defquota = 500;
10166: }
10167: }
1.536 raeburn 10168: }
10169: } else {
10170: $settingstatus = 'default';
1.1134 raeburn 10171: if ($quotaname eq 'author') {
10172: $defquota = 500;
10173: } else {
10174: $defquota = 20;
10175: }
1.536 raeburn 10176: }
10177: if (wantarray) {
10178: return ($defquota,$settingstatus);
1.472 raeburn 10179: } else {
1.536 raeburn 10180: return $defquota;
1.472 raeburn 10181: }
10182: }
10183:
1.1135 raeburn 10184: ###############################################
10185:
10186: =pod
10187:
1.1136 raeburn 10188: =item * &excess_filesize_warning()
1.1135 raeburn 10189:
10190: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 10191: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 10192: space to be exceeded.
1.1136 raeburn 10193:
10194: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 10195: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 10196:
1.1165 raeburn 10197: Inputs: 7
1.1136 raeburn 10198: 1. username or coursenum
1.1135 raeburn 10199: 2. domain
1.1136 raeburn 10200: 3. context ('author' or 'course')
1.1135 raeburn 10201: 4. filename of file for which action is being requested
10202: 5. filesize (kB) of file
10203: 6. action being taken: copy or upload.
1.1237 raeburn 10204: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 10205:
10206: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 10207: otherwise return null.
10208:
10209: =back
1.1135 raeburn 10210:
10211: =cut
10212:
1.1136 raeburn 10213: sub excess_filesize_warning {
1.1165 raeburn 10214: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 10215: my $current_disk_usage = 0;
1.1165 raeburn 10216: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 10217: if ($context eq 'author') {
10218: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10219: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10220: } else {
10221: foreach my $subdir ('docs','supplemental') {
10222: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10223: }
10224: }
1.1135 raeburn 10225: $disk_quota = int($disk_quota * 1000);
10226: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 10227: return '<p class="LC_warning">'.
1.1135 raeburn 10228: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 10229: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10230: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 10231: $disk_quota,$current_disk_usage).
10232: '</p>';
10233: }
10234: return;
10235: }
10236:
10237: ###############################################
10238:
10239:
1.1136 raeburn 10240:
10241:
1.384 raeburn 10242: sub get_secgrprole_info {
10243: my ($cdom,$cnum,$needroles,$type) = @_;
10244: my %sections_count = &get_sections($cdom,$cnum);
10245: my @sections = (sort {$a <=> $b} keys(%sections_count));
10246: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10247: my @groups = sort(keys(%curr_groups));
10248: my $allroles = [];
10249: my $rolehash;
10250: my $accesshash = {
10251: active => 'Currently has access',
10252: future => 'Will have future access',
10253: previous => 'Previously had access',
10254: };
10255: if ($needroles) {
10256: $rolehash = {'all' => 'all'};
1.385 albertel 10257: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10258: if (&Apache::lonnet::error(%user_roles)) {
10259: undef(%user_roles);
10260: }
10261: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10262: my ($role)=split(/\:/,$item,2);
10263: if ($role eq 'cr') { next; }
10264: if ($role =~ /^cr/) {
10265: $$rolehash{$role} = (split('/',$role))[3];
10266: } else {
10267: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10268: }
10269: }
10270: foreach my $key (sort(keys(%{$rolehash}))) {
10271: push(@{$allroles},$key);
10272: }
10273: push (@{$allroles},'st');
10274: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10275: }
10276: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10277: }
10278:
1.555 raeburn 10279: sub user_picker {
1.1279 raeburn 10280: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10281: my $currdom = $dom;
1.1253 raeburn 10282: my @alldoms = &Apache::lonnet::all_domains();
10283: if (@alldoms == 1) {
10284: my %domsrch = &Apache::lonnet::get_dom('configuration',
10285: ['directorysrch'],$alldoms[0]);
10286: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10287: my $showdom = $domdesc;
10288: if ($showdom eq '') {
10289: $showdom = $dom;
10290: }
10291: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10292: if ((!$domsrch{'directorysrch'}{'available'}) &&
10293: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10294: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10295: }
10296: }
10297: }
1.555 raeburn 10298: my %curr_selected = (
10299: srchin => 'dom',
1.580 raeburn 10300: srchby => 'lastname',
1.555 raeburn 10301: );
10302: my $srchterm;
1.625 raeburn 10303: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10304: if ($srch->{'srchby'} ne '') {
10305: $curr_selected{'srchby'} = $srch->{'srchby'};
10306: }
10307: if ($srch->{'srchin'} ne '') {
10308: $curr_selected{'srchin'} = $srch->{'srchin'};
10309: }
10310: if ($srch->{'srchtype'} ne '') {
10311: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10312: }
10313: if ($srch->{'srchdomain'} ne '') {
10314: $currdom = $srch->{'srchdomain'};
10315: }
10316: $srchterm = $srch->{'srchterm'};
10317: }
1.1222 damieng 10318: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10319: 'usr' => 'Search criteria',
1.563 raeburn 10320: 'doma' => 'Domain/institution to search',
1.558 albertel 10321: 'uname' => 'username',
10322: 'lastname' => 'last name',
1.555 raeburn 10323: 'lastfirst' => 'last name, first name',
1.558 albertel 10324: 'crs' => 'in this course',
1.576 raeburn 10325: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10326: 'alc' => 'all LON-CAPA',
1.573 raeburn 10327: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10328: 'exact' => 'is',
10329: 'contains' => 'contains',
1.569 raeburn 10330: 'begins' => 'begins with',
1.1222 damieng 10331: );
10332: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10333: 'youm' => "You must include some text to search for.",
10334: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10335: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10336: 'yomc' => "You must choose a domain when using an institutional directory search.",
10337: 'ymcd' => "You must choose a domain when using a domain search.",
10338: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10339: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10340: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10341: );
1.1222 damieng 10342: &html_escape(\%html_lt);
10343: &js_escape(\%js_lt);
1.1255 raeburn 10344: my $domform;
1.1277 raeburn 10345: my $allow_blank = 1;
1.1255 raeburn 10346: if ($fixeddom) {
1.1277 raeburn 10347: $allow_blank = 0;
10348: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10349: } else {
1.1287 raeburn 10350: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 10351: my ($trusted,$untrusted);
1.1287 raeburn 10352: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 10353: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 10354: } elsif ($context eq 'author') {
1.1288 raeburn 10355: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 10356: } elsif ($context eq 'domain') {
1.1288 raeburn 10357: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 10358: }
1.1288 raeburn 10359: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 10360: }
1.563 raeburn 10361: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10362:
10363: my @srchins = ('crs','dom','alc','instd');
10364:
10365: foreach my $option (@srchins) {
10366: # FIXME 'alc' option unavailable until
10367: # loncreateuser::print_user_query_page()
10368: # has been completed.
10369: next if ($option eq 'alc');
1.880 raeburn 10370: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10371: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 10372: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10373: if ($curr_selected{'srchin'} eq $option) {
10374: $srchinsel .= '
1.1222 damieng 10375: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10376: } else {
10377: $srchinsel .= '
1.1222 damieng 10378: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10379: }
1.555 raeburn 10380: }
1.563 raeburn 10381: $srchinsel .= "\n </select>\n";
1.555 raeburn 10382:
10383: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10384: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10385: if ($curr_selected{'srchby'} eq $option) {
10386: $srchbysel .= '
1.1222 damieng 10387: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10388: } else {
10389: $srchbysel .= '
1.1222 damieng 10390: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10391: }
10392: }
10393: $srchbysel .= "\n </select>\n";
10394:
10395: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10396: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10397: if ($curr_selected{'srchtype'} eq $option) {
10398: $srchtypesel .= '
1.1222 damieng 10399: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10400: } else {
10401: $srchtypesel .= '
1.1222 damieng 10402: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10403: }
10404: }
10405: $srchtypesel .= "\n </select>\n";
10406:
1.558 albertel 10407: my ($newuserscript,$new_user_create);
1.994 raeburn 10408: my $context_dom = $env{'request.role.domain'};
10409: if ($context eq 'requestcrs') {
10410: if ($env{'form.coursedom'} ne '') {
10411: $context_dom = $env{'form.coursedom'};
10412: }
10413: }
1.556 raeburn 10414: if ($forcenewuser) {
1.576 raeburn 10415: if (ref($srch) eq 'HASH') {
1.994 raeburn 10416: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10417: if ($cancreate) {
10418: $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>';
10419: } else {
1.799 bisitz 10420: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10421: my %usertypetext = (
10422: official => 'institutional',
10423: unofficial => 'non-institutional',
10424: );
1.799 bisitz 10425: $new_user_create = '<p class="LC_warning">'
10426: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10427: .' '
10428: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10429: ,'<a href="'.$helplink.'">','</a>')
10430: .'</p><br />';
1.627 raeburn 10431: }
1.576 raeburn 10432: }
10433: }
10434:
1.556 raeburn 10435: $newuserscript = <<"ENDSCRIPT";
10436:
1.570 raeburn 10437: function setSearch(createnew,callingForm) {
1.556 raeburn 10438: if (createnew == 1) {
1.570 raeburn 10439: for (var i=0; i<callingForm.srchby.length; i++) {
10440: if (callingForm.srchby.options[i].value == 'uname') {
10441: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10442: }
10443: }
1.570 raeburn 10444: for (var i=0; i<callingForm.srchin.length; i++) {
10445: if ( callingForm.srchin.options[i].value == 'dom') {
10446: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10447: }
10448: }
1.570 raeburn 10449: for (var i=0; i<callingForm.srchtype.length; i++) {
10450: if (callingForm.srchtype.options[i].value == 'exact') {
10451: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10452: }
10453: }
1.570 raeburn 10454: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10455: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10456: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10457: }
10458: }
10459: }
10460: }
10461: ENDSCRIPT
1.558 albertel 10462:
1.556 raeburn 10463: }
10464:
1.555 raeburn 10465: my $output = <<"END_BLOCK";
1.556 raeburn 10466: <script type="text/javascript">
1.824 bisitz 10467: // <![CDATA[
1.570 raeburn 10468: function validateEntry(callingForm) {
1.558 albertel 10469:
1.556 raeburn 10470: var checkok = 1;
1.558 albertel 10471: var srchin;
1.570 raeburn 10472: for (var i=0; i<callingForm.srchin.length; i++) {
10473: if ( callingForm.srchin[i].checked ) {
10474: srchin = callingForm.srchin[i].value;
1.558 albertel 10475: }
10476: }
10477:
1.570 raeburn 10478: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10479: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10480: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10481: var srchterm = callingForm.srchterm.value;
10482: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10483: var msg = "";
10484:
10485: if (srchterm == "") {
10486: checkok = 0;
1.1222 damieng 10487: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10488: }
10489:
1.569 raeburn 10490: if (srchtype== 'begins') {
10491: if (srchterm.length < 2) {
10492: checkok = 0;
1.1222 damieng 10493: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10494: }
10495: }
10496:
1.556 raeburn 10497: if (srchtype== 'contains') {
10498: if (srchterm.length < 3) {
10499: checkok = 0;
1.1222 damieng 10500: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10501: }
10502: }
10503: if (srchin == 'instd') {
10504: if (srchdomain == '') {
10505: checkok = 0;
1.1222 damieng 10506: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10507: }
10508: }
10509: if (srchin == 'dom') {
10510: if (srchdomain == '') {
10511: checkok = 0;
1.1222 damieng 10512: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10513: }
10514: }
10515: if (srchby == 'lastfirst') {
10516: if (srchterm.indexOf(",") == -1) {
10517: checkok = 0;
1.1222 damieng 10518: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10519: }
10520: if (srchterm.indexOf(",") == srchterm.length -1) {
10521: checkok = 0;
1.1222 damieng 10522: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10523: }
10524: }
10525: if (checkok == 0) {
1.1222 damieng 10526: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10527: return;
10528: }
10529: if (checkok == 1) {
1.570 raeburn 10530: callingForm.submit();
1.556 raeburn 10531: }
10532: }
10533:
10534: $newuserscript
10535:
1.824 bisitz 10536: // ]]>
1.556 raeburn 10537: </script>
1.558 albertel 10538:
10539: $new_user_create
10540:
1.555 raeburn 10541: END_BLOCK
1.558 albertel 10542:
1.876 raeburn 10543: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10544: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10545: $domform.
10546: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10547: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10548: $srchbysel.
10549: $srchtypesel.
10550: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10551: $srchinsel.
10552: &Apache::lonhtmlcommon::row_closure(1).
10553: &Apache::lonhtmlcommon::end_pick_box().
10554: '<br />';
1.1253 raeburn 10555: return ($output,1);
1.555 raeburn 10556: }
10557:
1.612 raeburn 10558: sub user_rule_check {
1.615 raeburn 10559: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10560: my ($response,%inst_response);
1.612 raeburn 10561: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10562: if (keys(%{$usershash}) > 1) {
10563: my (%by_username,%by_id,%userdoms);
10564: my $checkid;
10565: if (ref($checks) eq 'HASH') {
10566: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10567: $checkid = 1;
10568: }
10569: }
10570: foreach my $user (keys(%{$usershash})) {
10571: my ($uname,$udom) = split(/:/,$user);
10572: if ($checkid) {
10573: if (ref($usershash->{$user}) eq 'HASH') {
10574: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10575: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10576: $userdoms{$udom} = 1;
1.1227 raeburn 10577: if (ref($inst_results) eq 'HASH') {
10578: $inst_results->{$uname.':'.$udom} = {};
10579: }
1.1226 raeburn 10580: }
10581: }
10582: } else {
10583: $by_username{$udom}{$uname} = 1;
10584: $userdoms{$udom} = 1;
1.1227 raeburn 10585: if (ref($inst_results) eq 'HASH') {
10586: $inst_results->{$uname.':'.$udom} = {};
10587: }
1.1226 raeburn 10588: }
10589: }
10590: foreach my $udom (keys(%userdoms)) {
10591: if (!$got_rules->{$udom}) {
10592: my %domconfig = &Apache::lonnet::get_dom('configuration',
10593: ['usercreation'],$udom);
10594: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10595: foreach my $item ('username','id') {
10596: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10597: $$curr_rules{$udom}{$item} =
10598: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10599: }
10600: }
10601: }
10602: $got_rules->{$udom} = 1;
10603: }
1.612 raeburn 10604: }
1.1226 raeburn 10605: if ($checkid) {
10606: foreach my $udom (keys(%by_id)) {
10607: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10608: if ($outcome eq 'ok') {
1.1227 raeburn 10609: foreach my $id (keys(%{$by_id{$udom}})) {
10610: my $uname = $by_id{$udom}{$id};
10611: $inst_response{$uname.':'.$udom} = $outcome;
10612: }
1.1226 raeburn 10613: if (ref($results) eq 'HASH') {
10614: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10615: if (exists($inst_response{$uname.':'.$udom})) {
10616: $inst_response{$uname.':'.$udom} = $outcome;
10617: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10618: }
1.1226 raeburn 10619: }
10620: }
10621: }
1.612 raeburn 10622: }
1.615 raeburn 10623: } else {
1.1226 raeburn 10624: foreach my $udom (keys(%by_username)) {
10625: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10626: if ($outcome eq 'ok') {
1.1227 raeburn 10627: foreach my $uname (keys(%{$by_username{$udom}})) {
10628: $inst_response{$uname.':'.$udom} = $outcome;
10629: }
1.1226 raeburn 10630: if (ref($results) eq 'HASH') {
10631: foreach my $uname (keys(%{$results})) {
10632: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10633: }
10634: }
10635: }
10636: }
1.612 raeburn 10637: }
1.1226 raeburn 10638: } elsif (keys(%{$usershash}) == 1) {
10639: my $user = (keys(%{$usershash}))[0];
10640: my ($uname,$udom) = split(/:/,$user);
10641: if (($udom ne '') && ($uname ne '')) {
10642: if (ref($usershash->{$user}) eq 'HASH') {
10643: if (ref($checks) eq 'HASH') {
10644: if (defined($checks->{'username'})) {
10645: ($inst_response{$user},%{$inst_results->{$user}}) =
10646: &Apache::lonnet::get_instuser($udom,$uname);
10647: } elsif (defined($checks->{'id'})) {
10648: if ($usershash->{$user}->{'id'} ne '') {
10649: ($inst_response{$user},%{$inst_results->{$user}}) =
10650: &Apache::lonnet::get_instuser($udom,undef,
10651: $usershash->{$user}->{'id'});
10652: } else {
10653: ($inst_response{$user},%{$inst_results->{$user}}) =
10654: &Apache::lonnet::get_instuser($udom,$uname);
10655: }
1.585 raeburn 10656: }
1.1226 raeburn 10657: } else {
10658: ($inst_response{$user},%{$inst_results->{$user}}) =
10659: &Apache::lonnet::get_instuser($udom,$uname);
10660: return;
10661: }
10662: if (!$got_rules->{$udom}) {
10663: my %domconfig = &Apache::lonnet::get_dom('configuration',
10664: ['usercreation'],$udom);
10665: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10666: foreach my $item ('username','id') {
10667: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10668: $$curr_rules{$udom}{$item} =
10669: $domconfig{'usercreation'}{$item.'_rule'};
10670: }
10671: }
10672: }
10673: $got_rules->{$udom} = 1;
1.585 raeburn 10674: }
10675: }
1.1226 raeburn 10676: } else {
10677: return;
10678: }
10679: } else {
10680: return;
10681: }
10682: foreach my $user (keys(%{$usershash})) {
10683: my ($uname,$udom) = split(/:/,$user);
10684: next if (($udom eq '') || ($uname eq ''));
10685: my $id;
1.1227 raeburn 10686: if (ref($inst_results) eq 'HASH') {
10687: if (ref($inst_results->{$user}) eq 'HASH') {
10688: $id = $inst_results->{$user}->{'id'};
10689: }
10690: }
10691: if ($id eq '') {
10692: if (ref($usershash->{$user})) {
10693: $id = $usershash->{$user}->{'id'};
10694: }
1.585 raeburn 10695: }
1.612 raeburn 10696: foreach my $item (keys(%{$checks})) {
10697: if (ref($$curr_rules{$udom}) eq 'HASH') {
10698: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10699: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10700: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10701: $$curr_rules{$udom}{$item});
1.612 raeburn 10702: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10703: if ($rule_check{$rule}) {
10704: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10705: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10706: if (ref($inst_results) eq 'HASH') {
10707: if (ref($inst_results->{$user}) eq 'HASH') {
10708: if (keys(%{$inst_results->{$user}}) == 0) {
10709: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10710: } elsif ($item eq 'id') {
10711: if ($inst_results->{$user}->{'id'} eq '') {
10712: $$alerts{$item}{$udom}{$uname} = 1;
10713: }
1.615 raeburn 10714: }
1.612 raeburn 10715: }
10716: }
1.615 raeburn 10717: }
10718: last;
1.585 raeburn 10719: }
10720: }
10721: }
10722: }
10723: }
10724: }
10725: }
10726: }
1.612 raeburn 10727: return;
10728: }
10729:
10730: sub user_rule_formats {
10731: my ($domain,$domdesc,$curr_rules,$check) = @_;
10732: my %text = (
10733: 'username' => 'Usernames',
10734: 'id' => 'IDs',
10735: );
10736: my $output;
10737: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10738: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10739: if (@{$ruleorder} > 0) {
1.1102 raeburn 10740: $output = '<br />'.
10741: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10742: '<span class="LC_cusr_emph">','</span>',$domdesc).
10743: ' <ul>';
1.612 raeburn 10744: foreach my $rule (@{$ruleorder}) {
10745: if (ref($curr_rules) eq 'ARRAY') {
10746: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10747: if (ref($rules->{$rule}) eq 'HASH') {
10748: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10749: $rules->{$rule}{'desc'}.'</li>';
10750: }
10751: }
10752: }
10753: }
10754: $output .= '</ul>';
10755: }
10756: }
10757: return $output;
10758: }
10759:
10760: sub instrule_disallow_msg {
1.615 raeburn 10761: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10762: my $response;
10763: my %text = (
10764: item => 'username',
10765: items => 'usernames',
10766: match => 'matches',
10767: do => 'does',
10768: action => 'a username',
10769: one => 'one',
10770: );
10771: if ($count > 1) {
10772: $text{'item'} = 'usernames';
10773: $text{'match'} ='match';
10774: $text{'do'} = 'do';
10775: $text{'action'} = 'usernames',
10776: $text{'one'} = 'ones';
10777: }
10778: if ($checkitem eq 'id') {
10779: $text{'items'} = 'IDs';
10780: $text{'item'} = 'ID';
10781: $text{'action'} = 'an ID';
1.615 raeburn 10782: if ($count > 1) {
10783: $text{'item'} = 'IDs';
10784: $text{'action'} = 'IDs';
10785: }
1.612 raeburn 10786: }
1.674 bisitz 10787: $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 10788: if ($mode eq 'upload') {
10789: if ($checkitem eq 'username') {
10790: $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'}.");
10791: } elsif ($checkitem eq 'id') {
1.674 bisitz 10792: $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 10793: }
1.669 raeburn 10794: } elsif ($mode eq 'selfcreate') {
10795: if ($checkitem eq 'id') {
10796: $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.");
10797: }
1.615 raeburn 10798: } else {
10799: if ($checkitem eq 'username') {
10800: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10801: } elsif ($checkitem eq 'id') {
10802: $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.");
10803: }
1.612 raeburn 10804: }
10805: return $response;
1.585 raeburn 10806: }
10807:
1.624 raeburn 10808: sub personal_data_fieldtitles {
10809: my %fieldtitles = &Apache::lonlocal::texthash (
10810: id => 'Student/Employee ID',
10811: permanentemail => 'E-mail address',
10812: lastname => 'Last Name',
10813: firstname => 'First Name',
10814: middlename => 'Middle Name',
10815: generation => 'Generation',
10816: gen => 'Generation',
1.765 raeburn 10817: inststatus => 'Affiliation',
1.624 raeburn 10818: );
10819: return %fieldtitles;
10820: }
10821:
1.642 raeburn 10822: sub sorted_inst_types {
10823: my ($dom) = @_;
1.1185 raeburn 10824: my ($usertypes,$order);
10825: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10826: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10827: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10828: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10829: } else {
10830: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10831: }
1.642 raeburn 10832: my $othertitle = &mt('All users');
10833: if ($env{'request.course.id'}) {
1.668 raeburn 10834: $othertitle = &mt('Any users');
1.642 raeburn 10835: }
10836: my @types;
10837: if (ref($order) eq 'ARRAY') {
10838: @types = @{$order};
10839: }
10840: if (@types == 0) {
10841: if (ref($usertypes) eq 'HASH') {
10842: @types = sort(keys(%{$usertypes}));
10843: }
10844: }
10845: if (keys(%{$usertypes}) > 0) {
10846: $othertitle = &mt('Other users');
10847: }
10848: return ($othertitle,$usertypes,\@types);
10849: }
10850:
1.645 raeburn 10851: sub get_institutional_codes {
10852: my ($settings,$allcourses,$LC_code) = @_;
10853: # Get complete list of course sections to update
10854: my @currsections = ();
10855: my @currxlists = ();
10856: my $coursecode = $$settings{'internal.coursecode'};
10857:
10858: if ($$settings{'internal.sectionnums'} ne '') {
10859: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10860: }
10861:
10862: if ($$settings{'internal.crosslistings'} ne '') {
10863: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10864: }
10865:
10866: if (@currxlists > 0) {
10867: foreach (@currxlists) {
10868: if (m/^([^:]+):(\w*)$/) {
10869: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 10870: push(@{$allcourses},$1);
1.645 raeburn 10871: $$LC_code{$1} = $2;
10872: }
10873: }
10874: }
10875: }
10876:
10877: if (@currsections > 0) {
10878: foreach (@currsections) {
10879: if (m/^(\w+):(\w*)$/) {
10880: my $sec = $coursecode.$1;
10881: my $lc_sec = $2;
10882: unless (grep/^$sec$/,@{$allcourses}) {
1.1263 raeburn 10883: push(@{$allcourses},$sec);
1.645 raeburn 10884: $$LC_code{$sec} = $lc_sec;
10885: }
10886: }
10887: }
10888: }
10889: return;
10890: }
10891:
1.971 raeburn 10892: sub get_standard_codeitems {
10893: return ('Year','Semester','Department','Number','Section');
10894: }
10895:
1.112 bowersj2 10896: =pod
10897:
1.780 raeburn 10898: =head1 Slot Helpers
10899:
10900: =over 4
10901:
10902: =item * sorted_slots()
10903:
1.1040 raeburn 10904: Sorts an array of slot names in order of an optional sort key,
10905: default sort is by slot start time (earliest first).
1.780 raeburn 10906:
10907: Inputs:
10908:
10909: =over 4
10910:
10911: slotsarr - Reference to array of unsorted slot names.
10912:
10913: slots - Reference to hash of hash, where outer hash keys are slot names.
10914:
1.1040 raeburn 10915: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10916:
1.549 albertel 10917: =back
10918:
1.780 raeburn 10919: Returns:
10920:
10921: =over 4
10922:
1.1040 raeburn 10923: sorted - An array of slot names sorted by a specified sort key
10924: (default sort key is start time of the slot).
1.780 raeburn 10925:
10926: =back
10927:
10928: =cut
10929:
10930:
10931: sub sorted_slots {
1.1040 raeburn 10932: my ($slotsarr,$slots,$sortkey) = @_;
10933: if ($sortkey eq '') {
10934: $sortkey = 'starttime';
10935: }
1.780 raeburn 10936: my @sorted;
10937: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10938: @sorted =
10939: sort {
10940: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10941: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10942: }
10943: if (ref($slots->{$a})) { return -1;}
10944: if (ref($slots->{$b})) { return 1;}
10945: return 0;
10946: } @{$slotsarr};
10947: }
10948: return @sorted;
10949: }
10950:
1.1040 raeburn 10951: =pod
10952:
10953: =item * get_future_slots()
10954:
10955: Inputs:
10956:
10957: =over 4
10958:
10959: cnum - course number
10960:
10961: cdom - course domain
10962:
10963: now - current UNIX time
10964:
10965: symb - optional symb
10966:
10967: =back
10968:
10969: Returns:
10970:
10971: =over 4
10972:
10973: sorted_reservable - ref to array of student_schedulable slots currently
10974: reservable, ordered by end date of reservation period.
10975:
10976: reservable_now - ref to hash of student_schedulable slots currently
10977: reservable.
10978:
10979: Keys in inner hash are:
10980: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10981: (b) endreserve: end date of reservation period.
10982: (c) uniqueperiod: start,end dates when slot is to be uniquely
10983: selected.
1.1040 raeburn 10984:
10985: sorted_future - ref to array of student_schedulable slots reservable in
10986: the future, ordered by start date of reservation period.
10987:
10988: future_reservable - ref to hash of student_schedulable slots reservable
10989: in the future.
10990:
10991: Keys in inner hash are:
10992: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10993: (b) startreserve: start date of reservation period.
10994: (c) uniqueperiod: start,end dates when slot is to be uniquely
10995: selected.
1.1040 raeburn 10996:
10997: =back
10998:
10999: =cut
11000:
11001: sub get_future_slots {
11002: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 11003: my $map;
11004: if ($symb) {
11005: ($map) = &Apache::lonnet::decode_symb($symb);
11006: }
1.1040 raeburn 11007: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
11008: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
11009: foreach my $slot (keys(%slots)) {
11010: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
11011: if ($symb) {
1.1229 raeburn 11012: if ($slots{$slot}->{'symb'} ne '') {
11013: my $canuse;
11014: my %oksymbs;
11015: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
11016: map { $oksymbs{$_} = 1; } @slotsymbs;
11017: if ($oksymbs{$symb}) {
11018: $canuse = 1;
11019: } else {
11020: foreach my $item (@slotsymbs) {
11021: if ($item =~ /\.(page|sequence)$/) {
11022: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
11023: if (($map ne '') && ($map eq $sloturl)) {
11024: $canuse = 1;
11025: last;
11026: }
11027: }
11028: }
11029: }
11030: next unless ($canuse);
11031: }
1.1040 raeburn 11032: }
11033: if (($slots{$slot}->{'starttime'} > $now) &&
11034: ($slots{$slot}->{'endtime'} > $now)) {
11035: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
11036: my $userallowed = 0;
11037: if ($slots{$slot}->{'allowedsections'}) {
11038: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
11039: if (!defined($env{'request.role.sec'})
11040: && grep(/^No section assigned$/,@allowed_sec)) {
11041: $userallowed=1;
11042: } else {
11043: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
11044: $userallowed=1;
11045: }
11046: }
11047: unless ($userallowed) {
11048: if (defined($env{'request.course.groups'})) {
11049: my @groups = split(/:/,$env{'request.course.groups'});
11050: foreach my $group (@groups) {
11051: if (grep(/^\Q$group\E$/,@allowed_sec)) {
11052: $userallowed=1;
11053: last;
11054: }
11055: }
11056: }
11057: }
11058: }
11059: if ($slots{$slot}->{'allowedusers'}) {
11060: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
11061: my $user = $env{'user.name'}.':'.$env{'user.domain'};
11062: if (grep(/^\Q$user\E$/,@allowed_users)) {
11063: $userallowed = 1;
11064: }
11065: }
11066: next unless($userallowed);
11067: }
11068: my $startreserve = $slots{$slot}->{'startreserve'};
11069: my $endreserve = $slots{$slot}->{'endreserve'};
11070: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 11071: my $uniqueperiod;
11072: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11073: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11074: }
1.1040 raeburn 11075: if (($startreserve < $now) &&
11076: (!$endreserve || $endreserve > $now)) {
11077: my $lastres = $endreserve;
11078: if (!$lastres) {
11079: $lastres = $slots{$slot}->{'starttime'};
11080: }
11081: $reservable_now{$slot} = {
11082: symb => $symb,
1.1250 raeburn 11083: endreserve => $lastres,
11084: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11085: };
11086: } elsif (($startreserve > $now) &&
11087: (!$endreserve || $endreserve > $startreserve)) {
11088: $future_reservable{$slot} = {
11089: symb => $symb,
1.1250 raeburn 11090: startreserve => $startreserve,
11091: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11092: };
11093: }
11094: }
11095: }
11096: my @unsorted_reservable = keys(%reservable_now);
11097: if (@unsorted_reservable > 0) {
11098: @sorted_reservable =
11099: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11100: }
11101: my @unsorted_future = keys(%future_reservable);
11102: if (@unsorted_future > 0) {
11103: @sorted_future =
11104: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11105: }
11106: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11107: }
1.780 raeburn 11108:
11109: =pod
11110:
1.1057 foxr 11111: =back
11112:
1.549 albertel 11113: =head1 HTTP Helpers
11114:
11115: =over 4
11116:
1.648 raeburn 11117: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11118:
1.258 albertel 11119: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11120: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11121: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11122:
11123: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11124: $possible_names is an ref to an array of form element names. As an example:
11125: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11126: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11127:
11128: =cut
1.1 albertel 11129:
1.6 albertel 11130: sub get_unprocessed_cgi {
1.25 albertel 11131: my ($query,$possible_names)= @_;
1.26 matthew 11132: # $Apache::lonxml::debug=1;
1.356 albertel 11133: foreach my $pair (split(/&/,$query)) {
11134: my ($name, $value) = split(/=/,$pair);
1.369 www 11135: $name = &unescape($name);
1.25 albertel 11136: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11137: $value =~ tr/+/ /;
11138: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11139: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11140: }
1.16 harris41 11141: }
1.6 albertel 11142: }
11143:
1.112 bowersj2 11144: =pod
11145:
1.648 raeburn 11146: =item * &cacheheader()
1.112 bowersj2 11147:
11148: returns cache-controlling header code
11149:
11150: =cut
11151:
1.7 albertel 11152: sub cacheheader {
1.258 albertel 11153: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11154: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11155: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11156: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11157: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11158: return $output;
1.7 albertel 11159: }
11160:
1.112 bowersj2 11161: =pod
11162:
1.648 raeburn 11163: =item * &no_cache($r)
1.112 bowersj2 11164:
11165: specifies header code to not have cache
11166:
11167: =cut
11168:
1.9 albertel 11169: sub no_cache {
1.216 albertel 11170: my ($r) = @_;
11171: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11172: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11173: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11174: $r->no_cache(1);
11175: $r->header_out("Expires" => $date);
11176: $r->header_out("Pragma" => "no-cache");
1.123 www 11177: }
11178:
11179: sub content_type {
1.181 albertel 11180: my ($r,$type,$charset) = @_;
1.299 foxr 11181: if ($r) {
11182: # Note that printout.pl calls this with undef for $r.
11183: &no_cache($r);
11184: }
1.258 albertel 11185: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11186: unless ($charset) {
11187: $charset=&Apache::lonlocal::current_encoding;
11188: }
11189: if ($charset) { $type.='; charset='.$charset; }
11190: if ($r) {
11191: $r->content_type($type);
11192: } else {
11193: print("Content-type: $type\n\n");
11194: }
1.9 albertel 11195: }
1.25 albertel 11196:
1.112 bowersj2 11197: =pod
11198:
1.648 raeburn 11199: =item * &add_to_env($name,$value)
1.112 bowersj2 11200:
1.258 albertel 11201: adds $name to the %env hash with value
1.112 bowersj2 11202: $value, if $name already exists, the entry is converted to an array
11203: reference and $value is added to the array.
11204:
11205: =cut
11206:
1.25 albertel 11207: sub add_to_env {
11208: my ($name,$value)=@_;
1.258 albertel 11209: if (defined($env{$name})) {
11210: if (ref($env{$name})) {
1.25 albertel 11211: #already have multiple values
1.258 albertel 11212: push(@{ $env{$name} },$value);
1.25 albertel 11213: } else {
11214: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11215: my $first=$env{$name};
11216: undef($env{$name});
11217: push(@{ $env{$name} },$first,$value);
1.25 albertel 11218: }
11219: } else {
1.258 albertel 11220: $env{$name}=$value;
1.25 albertel 11221: }
1.31 albertel 11222: }
1.149 albertel 11223:
11224: =pod
11225:
1.648 raeburn 11226: =item * &get_env_multiple($name)
1.149 albertel 11227:
1.258 albertel 11228: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11229: values may be defined and end up as an array ref.
11230:
11231: returns an array of values
11232:
11233: =cut
11234:
11235: sub get_env_multiple {
11236: my ($name) = @_;
11237: my @values;
1.258 albertel 11238: if (defined($env{$name})) {
1.149 albertel 11239: # exists is it an array
1.258 albertel 11240: if (ref($env{$name})) {
11241: @values=@{ $env{$name} };
1.149 albertel 11242: } else {
1.258 albertel 11243: $values[0]=$env{$name};
1.149 albertel 11244: }
11245: }
11246: return(@values);
11247: }
11248:
1.1249 damieng 11249: # Looks at given dependencies, and returns something depending on the context.
11250: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11251: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11252: # For all other contexts, returns ($output, $counter, $numpathchg).
11253: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11254: # $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.
11255: # $numpathchg: integer with the number of cleaned up dependency paths.
11256: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11257: # \%mapping: hash reference clean path -> original path for all dependencies.
11258: # @param {string} actionurl - The path to the handler, indicative of the context.
11259: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11260: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11261: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11262: # @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)
11263: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11264: sub ask_for_embedded_content {
1.1249 damieng 11265: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11266: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11267: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11268: %currsubfile,%unused,$rem);
1.1071 raeburn 11269: my $counter = 0;
11270: my $numnew = 0;
1.987 raeburn 11271: my $numremref = 0;
11272: my $numinvalid = 0;
11273: my $numpathchg = 0;
11274: my $numexisting = 0;
1.1071 raeburn 11275: my $numunused = 0;
11276: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11277: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11278: my $heading = &mt('Upload embedded files');
11279: my $buttontext = &mt('Upload');
11280:
1.1249 damieng 11281: # fills these variables based on the context:
11282: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11283: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11284: if ($env{'request.course.id'}) {
1.1123 raeburn 11285: if ($actionurl eq '/adm/dependencies') {
11286: $navmap = Apache::lonnavmaps::navmap->new();
11287: }
11288: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11289: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11290: }
1.1123 raeburn 11291: if (($actionurl eq '/adm/portfolio') ||
11292: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11293: my $current_path='/';
11294: if ($env{'form.currentpath'}) {
11295: $current_path = $env{'form.currentpath'};
11296: }
11297: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11298: $udom = $cdom;
11299: $uname = $cnum;
1.984 raeburn 11300: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11301: } else {
11302: $udom = $env{'user.domain'};
11303: $uname = $env{'user.name'};
11304: $url = '/userfiles/portfolio';
11305: }
1.987 raeburn 11306: $toplevel = $url.'/';
1.984 raeburn 11307: $url .= $current_path;
11308: $getpropath = 1;
1.987 raeburn 11309: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11310: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11311: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11312: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11313: $toplevel = $url;
1.984 raeburn 11314: if ($rest ne '') {
1.987 raeburn 11315: $url .= $rest;
11316: }
11317: } elsif ($actionurl eq '/adm/coursedocs') {
11318: if (ref($args) eq 'HASH') {
1.1071 raeburn 11319: $url = $args->{'docs_url'};
11320: $toplevel = $url;
1.1084 raeburn 11321: if ($args->{'context'} eq 'paste') {
11322: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11323: ($path) =
11324: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11325: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11326: $fileloc =~ s{^/}{};
11327: }
1.1071 raeburn 11328: }
1.1084 raeburn 11329: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11330: if ($env{'request.course.id'} ne '') {
11331: if (ref($args) eq 'HASH') {
11332: $url = $args->{'docs_url'};
11333: $title = $args->{'docs_title'};
1.1126 raeburn 11334: $toplevel = $url;
11335: unless ($toplevel =~ m{^/}) {
11336: $toplevel = "/$url";
11337: }
1.1085 raeburn 11338: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11339: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11340: $path = $1;
11341: } else {
11342: ($path) =
11343: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11344: }
1.1195 raeburn 11345: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11346: $fileloc = $toplevel;
11347: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11348: my ($udom,$uname,$fname) =
11349: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11350: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11351: } else {
11352: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11353: }
1.1071 raeburn 11354: $fileloc =~ s{^/}{};
11355: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11356: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11357: }
1.987 raeburn 11358: }
1.1123 raeburn 11359: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11360: $udom = $cdom;
11361: $uname = $cnum;
11362: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11363: $toplevel = $url;
11364: $path = $url;
11365: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11366: $fileloc =~ s{^/}{};
1.987 raeburn 11367: }
1.1249 damieng 11368:
11369: # parses the dependency paths to get some info
11370: # fills $newfiles, $mapping, $subdependencies, $dependencies
11371: # $newfiles: hash URL -> 1 for new files or external URLs
11372: # (will be completed later)
11373: # $mapping:
11374: # for external URLs: external URL -> external URL
11375: # for relative paths: clean path -> original path
11376: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11377: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11378: foreach my $file (keys(%{$allfiles})) {
11379: my $embed_file;
11380: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11381: $embed_file = $1;
11382: } else {
11383: $embed_file = $file;
11384: }
1.1158 raeburn 11385: my ($absolutepath,$cleaned_file);
11386: if ($embed_file =~ m{^\w+://}) {
11387: $cleaned_file = $embed_file;
1.1147 raeburn 11388: $newfiles{$cleaned_file} = 1;
11389: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11390: } else {
1.1158 raeburn 11391: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11392: if ($embed_file =~ m{^/}) {
11393: $absolutepath = $embed_file;
11394: }
1.1147 raeburn 11395: if ($cleaned_file =~ m{/}) {
11396: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11397: $path = &check_for_traversal($path,$url,$toplevel);
11398: my $item = $fname;
11399: if ($path ne '') {
11400: $item = $path.'/'.$fname;
11401: $subdependencies{$path}{$fname} = 1;
11402: } else {
11403: $dependencies{$item} = 1;
11404: }
11405: if ($absolutepath) {
11406: $mapping{$item} = $absolutepath;
11407: } else {
11408: $mapping{$item} = $embed_file;
11409: }
11410: } else {
11411: $dependencies{$embed_file} = 1;
11412: if ($absolutepath) {
1.1147 raeburn 11413: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11414: } else {
1.1147 raeburn 11415: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11416: }
11417: }
1.984 raeburn 11418: }
11419: }
1.1249 damieng 11420:
11421: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11422: # and lists
11423: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11424: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11425: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11426: # the path had to be cleaned up
11427: # $existing: hash clean path -> 1 if the file exists
11428: # $numexisting: number of keys in $existing
11429: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11430: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11431: # dependency subdirectories that are
11432: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11433: my $dirptr = 16384;
1.984 raeburn 11434: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11435: $currsubfile{$path} = {};
1.1123 raeburn 11436: if (($actionurl eq '/adm/portfolio') ||
11437: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11438: my ($sublistref,$listerror) =
11439: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11440: if (ref($sublistref) eq 'ARRAY') {
11441: foreach my $line (@{$sublistref}) {
11442: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11443: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11444: }
1.984 raeburn 11445: }
1.987 raeburn 11446: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11447: if (opendir(my $dir,$url.'/'.$path)) {
11448: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11449: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11450: }
1.1084 raeburn 11451: } elsif (($actionurl eq '/adm/dependencies') ||
11452: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11453: ($args->{'context'} eq 'paste')) ||
11454: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11455: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11456: my $dir;
11457: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11458: $dir = $fileloc;
11459: } else {
11460: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11461: }
1.1071 raeburn 11462: if ($dir ne '') {
11463: my ($sublistref,$listerror) =
11464: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11465: if (ref($sublistref) eq 'ARRAY') {
11466: foreach my $line (@{$sublistref}) {
11467: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11468: undef,$mtime)=split(/\&/,$line,12);
11469: unless (($testdir&$dirptr) ||
11470: ($file_name =~ /^\.\.?$/)) {
11471: $currsubfile{$path}{$file_name} = [$size,$mtime];
11472: }
11473: }
11474: }
11475: }
1.984 raeburn 11476: }
11477: }
11478: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11479: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11480: my $item = $path.'/'.$file;
11481: unless ($mapping{$item} eq $item) {
11482: $pathchanges{$item} = 1;
11483: }
11484: $existing{$item} = 1;
11485: $numexisting ++;
11486: } else {
11487: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11488: }
11489: }
1.1071 raeburn 11490: if ($actionurl eq '/adm/dependencies') {
11491: foreach my $path (keys(%currsubfile)) {
11492: if (ref($currsubfile{$path}) eq 'HASH') {
11493: foreach my $file (keys(%{$currsubfile{$path}})) {
11494: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11495: next if (($rem ne '') &&
11496: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11497: (ref($navmap) &&
11498: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11499: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11500: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11501: $unused{$path.'/'.$file} = 1;
11502: }
11503: }
11504: }
11505: }
11506: }
1.984 raeburn 11507: }
1.1249 damieng 11508:
11509: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11510: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11511: my %currfile;
1.1123 raeburn 11512: if (($actionurl eq '/adm/portfolio') ||
11513: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11514: my ($dirlistref,$listerror) =
11515: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11516: if (ref($dirlistref) eq 'ARRAY') {
11517: foreach my $line (@{$dirlistref}) {
11518: my ($file_name,$rest) = split(/\&/,$line,2);
11519: $currfile{$file_name} = 1;
11520: }
1.984 raeburn 11521: }
1.987 raeburn 11522: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11523: if (opendir(my $dir,$url)) {
1.987 raeburn 11524: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11525: map {$currfile{$_} = 1;} @dir_list;
11526: }
1.1084 raeburn 11527: } elsif (($actionurl eq '/adm/dependencies') ||
11528: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11529: ($args->{'context'} eq 'paste')) ||
11530: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11531: if ($env{'request.course.id'} ne '') {
11532: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11533: if ($dir ne '') {
11534: my ($dirlistref,$listerror) =
11535: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11536: if (ref($dirlistref) eq 'ARRAY') {
11537: foreach my $line (@{$dirlistref}) {
11538: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11539: $size,undef,$mtime)=split(/\&/,$line,12);
11540: unless (($testdir&$dirptr) ||
11541: ($file_name =~ /^\.\.?$/)) {
11542: $currfile{$file_name} = [$size,$mtime];
11543: }
11544: }
11545: }
11546: }
11547: }
1.984 raeburn 11548: }
1.1249 damieng 11549: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11550: # are not in subdirectories, using $currfile
1.984 raeburn 11551: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11552: if (exists($currfile{$file})) {
1.987 raeburn 11553: unless ($mapping{$file} eq $file) {
11554: $pathchanges{$file} = 1;
11555: }
11556: $existing{$file} = 1;
11557: $numexisting ++;
11558: } else {
1.984 raeburn 11559: $newfiles{$file} = 1;
11560: }
11561: }
1.1071 raeburn 11562: foreach my $file (keys(%currfile)) {
11563: unless (($file eq $filename) ||
11564: ($file eq $filename.'.bak') ||
11565: ($dependencies{$file})) {
1.1085 raeburn 11566: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11567: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11568: next if (($rem ne '') &&
11569: (($env{"httpref.$rem".$file} ne '') ||
11570: (ref($navmap) &&
11571: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11572: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11573: ($navmap->getResourceByUrl($rem.$1)))))));
11574: }
1.1085 raeburn 11575: }
1.1071 raeburn 11576: $unused{$file} = 1;
11577: }
11578: }
1.1249 damieng 11579:
11580: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11581: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11582: ($args->{'context'} eq 'paste')) {
11583: $counter = scalar(keys(%existing));
11584: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11585: return ($output,$counter,$numpathchg,\%existing);
11586: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11587: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11588: $counter = scalar(keys(%existing));
11589: $numpathchg = scalar(keys(%pathchanges));
11590: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11591: }
1.1249 damieng 11592:
11593: # returns HTML otherwise, with dependency results and to ask for more uploads
11594:
11595: # $upload_output: missing dependencies (with upload form)
11596: # $modify_output: uploaded dependencies (in use)
11597: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11598: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11599: if ($actionurl eq '/adm/dependencies') {
11600: next if ($embed_file =~ m{^\w+://});
11601: }
1.660 raeburn 11602: $upload_output .= &start_data_table_row().
1.1123 raeburn 11603: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11604: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11605: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11606: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11607: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11608: }
1.1123 raeburn 11609: $upload_output .= '</td>';
1.1071 raeburn 11610: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11611: $upload_output.='<td align="right">'.
11612: '<span class="LC_info LC_fontsize_medium">'.
11613: &mt("URL points to web address").'</span>';
1.987 raeburn 11614: $numremref++;
1.660 raeburn 11615: } elsif ($args->{'error_on_invalid_names'}
11616: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11617: $upload_output.='<td align="right"><span class="LC_warning">'.
11618: &mt('Invalid characters').'</span>';
1.987 raeburn 11619: $numinvalid++;
1.660 raeburn 11620: } else {
1.1123 raeburn 11621: $upload_output .= '<td>'.
11622: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11623: $embed_file,\%mapping,
1.1071 raeburn 11624: $allfiles,$codebase,'upload');
11625: $counter ++;
11626: $numnew ++;
1.987 raeburn 11627: }
11628: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11629: }
11630: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11631: if ($actionurl eq '/adm/dependencies') {
11632: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11633: $modify_output .= &start_data_table_row().
11634: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11635: '<img src="'.&icon($embed_file).'" border="0" />'.
11636: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11637: '<td>'.$size.'</td>'.
11638: '<td>'.$mtime.'</td>'.
11639: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11640: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11641: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11642: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11643: &embedded_file_element('upload_embedded',$counter,
11644: $embed_file,\%mapping,
11645: $allfiles,$codebase,'modify').
11646: '</div></td>'.
11647: &end_data_table_row()."\n";
11648: $counter ++;
11649: } else {
11650: $upload_output .= &start_data_table_row().
1.1123 raeburn 11651: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11652: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11653: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11654: &Apache::loncommon::end_data_table_row()."\n";
11655: }
11656: }
11657: my $delidx = $counter;
11658: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11659: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11660: $delete_output .= &start_data_table_row().
11661: '<td><img src="'.&icon($oldfile).'" />'.
11662: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11663: '<td>'.$size.'</td>'.
11664: '<td>'.$mtime.'</td>'.
11665: '<td><label><input type="checkbox" name="del_upload_dep" '.
11666: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11667: &embedded_file_element('upload_embedded',$delidx,
11668: $oldfile,\%mapping,$allfiles,
11669: $codebase,'delete').'</td>'.
11670: &end_data_table_row()."\n";
11671: $numunused ++;
11672: $delidx ++;
1.987 raeburn 11673: }
11674: if ($upload_output) {
11675: $upload_output = &start_data_table().
11676: $upload_output.
11677: &end_data_table()."\n";
11678: }
1.1071 raeburn 11679: if ($modify_output) {
11680: $modify_output = &start_data_table().
11681: &start_data_table_header_row().
11682: '<th>'.&mt('File').'</th>'.
11683: '<th>'.&mt('Size (KB)').'</th>'.
11684: '<th>'.&mt('Modified').'</th>'.
11685: '<th>'.&mt('Upload replacement?').'</th>'.
11686: &end_data_table_header_row().
11687: $modify_output.
11688: &end_data_table()."\n";
11689: }
11690: if ($delete_output) {
11691: $delete_output = &start_data_table().
11692: &start_data_table_header_row().
11693: '<th>'.&mt('File').'</th>'.
11694: '<th>'.&mt('Size (KB)').'</th>'.
11695: '<th>'.&mt('Modified').'</th>'.
11696: '<th>'.&mt('Delete?').'</th>'.
11697: &end_data_table_header_row().
11698: $delete_output.
11699: &end_data_table()."\n";
11700: }
1.987 raeburn 11701: my $applies = 0;
11702: if ($numremref) {
11703: $applies ++;
11704: }
11705: if ($numinvalid) {
11706: $applies ++;
11707: }
11708: if ($numexisting) {
11709: $applies ++;
11710: }
1.1071 raeburn 11711: if ($counter || $numunused) {
1.987 raeburn 11712: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11713: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11714: $state.'<h3>'.$heading.'</h3>';
11715: if ($actionurl eq '/adm/dependencies') {
11716: if ($numnew) {
11717: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11718: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11719: $upload_output.'<br />'."\n";
11720: }
11721: if ($numexisting) {
11722: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11723: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11724: $modify_output.'<br />'."\n";
11725: $buttontext = &mt('Save changes');
11726: }
11727: if ($numunused) {
11728: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11729: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11730: $delete_output.'<br />'."\n";
11731: $buttontext = &mt('Save changes');
11732: }
11733: } else {
11734: $output .= $upload_output.'<br />'."\n";
11735: }
11736: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11737: $counter.'" />'."\n";
11738: if ($actionurl eq '/adm/dependencies') {
11739: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11740: $numnew.'" />'."\n";
11741: } elsif ($actionurl eq '') {
1.987 raeburn 11742: $output .= '<input type="hidden" name="phase" value="three" />';
11743: }
11744: } elsif ($applies) {
11745: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11746: if ($applies > 1) {
11747: $output .=
1.1123 raeburn 11748: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11749: if ($numremref) {
11750: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11751: }
11752: if ($numinvalid) {
11753: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11754: }
11755: if ($numexisting) {
11756: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11757: }
11758: $output .= '</ul><br />';
11759: } elsif ($numremref) {
11760: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11761: } elsif ($numinvalid) {
11762: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11763: } elsif ($numexisting) {
11764: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11765: }
11766: $output .= $upload_output.'<br />';
11767: }
11768: my ($pathchange_output,$chgcount);
1.1071 raeburn 11769: $chgcount = $counter;
1.987 raeburn 11770: if (keys(%pathchanges) > 0) {
11771: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11772: if ($counter) {
1.987 raeburn 11773: $output .= &embedded_file_element('pathchange',$chgcount,
11774: $embed_file,\%mapping,
1.1071 raeburn 11775: $allfiles,$codebase,'change');
1.987 raeburn 11776: } else {
11777: $pathchange_output .=
11778: &start_data_table_row().
11779: '<td><input type ="checkbox" name="namechange" value="'.
11780: $chgcount.'" checked="checked" /></td>'.
11781: '<td>'.$mapping{$embed_file}.'</td>'.
11782: '<td>'.$embed_file.
11783: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11784: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11785: '</td>'.&end_data_table_row();
1.660 raeburn 11786: }
1.987 raeburn 11787: $numpathchg ++;
11788: $chgcount ++;
1.660 raeburn 11789: }
11790: }
1.1127 raeburn 11791: if (($counter) || ($numunused)) {
1.987 raeburn 11792: if ($numpathchg) {
11793: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11794: $numpathchg.'" />'."\n";
11795: }
11796: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11797: ($actionurl eq '/adm/imsimport')) {
11798: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11799: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11800: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11801: } elsif ($actionurl eq '/adm/dependencies') {
11802: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11803: }
1.1123 raeburn 11804: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11805: } elsif ($numpathchg) {
11806: my %pathchange = ();
11807: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11808: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11809: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11810: }
1.987 raeburn 11811: }
1.1071 raeburn 11812: return ($output,$counter,$numpathchg);
1.987 raeburn 11813: }
11814:
1.1147 raeburn 11815: =pod
11816:
11817: =item * clean_path($name)
11818:
11819: Performs clean-up of directories, subdirectories and filename in an
11820: embedded object, referenced in an HTML file which is being uploaded
11821: to a course or portfolio, where
11822: "Upload embedded images/multimedia files if HTML file" checkbox was
11823: checked.
11824:
11825: Clean-up is similar to replacements in lonnet::clean_filename()
11826: except each / between sub-directory and next level is preserved.
11827:
11828: =cut
11829:
11830: sub clean_path {
11831: my ($embed_file) = @_;
11832: $embed_file =~s{^/+}{};
11833: my @contents;
11834: if ($embed_file =~ m{/}) {
11835: @contents = split(/\//,$embed_file);
11836: } else {
11837: @contents = ($embed_file);
11838: }
11839: my $lastidx = scalar(@contents)-1;
11840: for (my $i=0; $i<=$lastidx; $i++) {
11841: $contents[$i]=~s{\\}{/}g;
11842: $contents[$i]=~s/\s+/\_/g;
11843: $contents[$i]=~s{[^/\w\.\-]}{}g;
11844: if ($i == $lastidx) {
11845: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11846: }
11847: }
11848: if ($lastidx > 0) {
11849: return join('/',@contents);
11850: } else {
11851: return $contents[0];
11852: }
11853: }
11854:
1.987 raeburn 11855: sub embedded_file_element {
1.1071 raeburn 11856: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11857: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11858: (ref($codebase) eq 'HASH'));
11859: my $output;
1.1071 raeburn 11860: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11861: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11862: }
11863: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11864: &escape($embed_file).'" />';
11865: unless (($context eq 'upload_embedded') &&
11866: ($mapping->{$embed_file} eq $embed_file)) {
11867: $output .='
11868: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11869: }
11870: my $attrib;
11871: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11872: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11873: }
11874: $output .=
11875: "\n\t\t".
11876: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11877: $attrib.'" />';
11878: if (exists($codebase->{$mapping->{$embed_file}})) {
11879: $output .=
11880: "\n\t\t".
11881: '<input name="codebase_'.$num.'" type="hidden" value="'.
11882: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11883: }
1.987 raeburn 11884: return $output;
1.660 raeburn 11885: }
11886:
1.1071 raeburn 11887: sub get_dependency_details {
11888: my ($currfile,$currsubfile,$embed_file) = @_;
11889: my ($size,$mtime,$showsize,$showmtime);
11890: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11891: if ($embed_file =~ m{/}) {
11892: my ($path,$fname) = split(/\//,$embed_file);
11893: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11894: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11895: }
11896: } else {
11897: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11898: ($size,$mtime) = @{$currfile->{$embed_file}};
11899: }
11900: }
11901: $showsize = $size/1024.0;
11902: $showsize = sprintf("%.1f",$showsize);
11903: if ($mtime > 0) {
11904: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11905: }
11906: }
11907: return ($showsize,$showmtime);
11908: }
11909:
11910: sub ask_embedded_js {
11911: return <<"END";
11912: <script type="text/javascript"">
11913: // <![CDATA[
11914: function toggleBrowse(counter) {
11915: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11916: var fileid = document.getElementById('embedded_item_'+counter);
11917: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11918: if (chkboxid.checked == true) {
11919: uploaddivid.style.display='block';
11920: } else {
11921: uploaddivid.style.display='none';
11922: fileid.value = '';
11923: }
11924: }
11925: // ]]>
11926: </script>
11927:
11928: END
11929: }
11930:
1.661 raeburn 11931: sub upload_embedded {
11932: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11933: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11934: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11935: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11936: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11937: my $orig_uploaded_filename =
11938: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11939: foreach my $type ('orig','ref','attrib','codebase') {
11940: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11941: $env{'form.embedded_'.$type.'_'.$i} =
11942: &unescape($env{'form.embedded_'.$type.'_'.$i});
11943: }
11944: }
1.661 raeburn 11945: my ($path,$fname) =
11946: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11947: # no path, whole string is fname
11948: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11949: $fname = &Apache::lonnet::clean_filename($fname);
11950: # See if there is anything left
11951: next if ($fname eq '');
11952:
11953: # Check if file already exists as a file or directory.
11954: my ($state,$msg);
11955: if ($context eq 'portfolio') {
11956: my $port_path = $dirpath;
11957: if ($group ne '') {
11958: $port_path = "groups/$group/$port_path";
11959: }
1.987 raeburn 11960: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11961: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11962: $dir_root,$port_path,$disk_quota,
11963: $current_disk_usage,$uname,$udom);
11964: if ($state eq 'will_exceed_quota'
1.984 raeburn 11965: || $state eq 'file_locked') {
1.661 raeburn 11966: $output .= $msg;
11967: next;
11968: }
11969: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11970: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11971: if ($state eq 'exists') {
11972: $output .= $msg;
11973: next;
11974: }
11975: }
11976: # Check if extension is valid
11977: if (($fname =~ /\.(\w+)$/) &&
11978: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 11979: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11980: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11981: next;
11982: } elsif (($fname =~ /\.(\w+)$/) &&
11983: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11984: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11985: next;
11986: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 11987: $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 11988: next;
11989: }
11990: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 11991: my $subdir = $path;
11992: $subdir =~ s{/+$}{};
1.661 raeburn 11993: if ($context eq 'portfolio') {
1.984 raeburn 11994: my $result;
11995: if ($state eq 'existingfile') {
11996: $result=
11997: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 11998: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11999: } else {
1.984 raeburn 12000: $result=
12001: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 12002: $dirpath.
1.1123 raeburn 12003: $env{'form.currentpath'}.$subdir);
1.984 raeburn 12004: if ($result !~ m|^/uploaded/|) {
12005: $output .= '<span class="LC_error">'
12006: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12007: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12008: .'</span><br />';
12009: next;
12010: } else {
1.987 raeburn 12011: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12012: $path.$fname.'</span>').'<br />';
1.984 raeburn 12013: }
1.661 raeburn 12014: }
1.1123 raeburn 12015: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 12016: my $extendedsubdir = $dirpath.'/'.$subdir;
12017: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 12018: my $result =
1.1126 raeburn 12019: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 12020: if ($result !~ m|^/uploaded/|) {
12021: $output .= '<span class="LC_error">'
12022: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
12023: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
12024: .'</span><br />';
12025: next;
12026: } else {
12027: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12028: $path.$fname.'</span>').'<br />';
1.1125 raeburn 12029: if ($context eq 'syllabus') {
12030: &Apache::lonnet::make_public_indefinitely($result);
12031: }
1.987 raeburn 12032: }
1.661 raeburn 12033: } else {
12034: # Save the file
12035: my $target = $env{'form.embedded_item_'.$i};
12036: my $fullpath = $dir_root.$dirpath.'/'.$path;
12037: my $dest = $fullpath.$fname;
12038: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 12039: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 12040: my $count;
12041: my $filepath = $dir_root;
1.1027 raeburn 12042: foreach my $subdir (@parts) {
12043: $filepath .= "/$subdir";
12044: if (!-e $filepath) {
1.661 raeburn 12045: mkdir($filepath,0770);
12046: }
12047: }
12048: my $fh;
12049: if (!open($fh,'>'.$dest)) {
12050: &Apache::lonnet::logthis('Failed to create '.$dest);
12051: $output .= '<span class="LC_error">'.
1.1071 raeburn 12052: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
12053: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12054: '</span><br />';
12055: } else {
12056: if (!print $fh $env{'form.embedded_item_'.$i}) {
12057: &Apache::lonnet::logthis('Failed to write to '.$dest);
12058: $output .= '<span class="LC_error">'.
1.1071 raeburn 12059: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
12060: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 12061: '</span><br />';
12062: } else {
1.987 raeburn 12063: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
12064: $url.'</span>').'<br />';
12065: unless ($context eq 'testbank') {
12066: $footer .= &mt('View embedded file: [_1]',
12067: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
12068: }
12069: }
12070: close($fh);
12071: }
12072: }
12073: if ($env{'form.embedded_ref_'.$i}) {
12074: $pathchange{$i} = 1;
12075: }
12076: }
12077: if ($output) {
12078: $output = '<p>'.$output.'</p>';
12079: }
12080: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12081: $returnflag = 'ok';
1.1071 raeburn 12082: my $numpathchgs = scalar(keys(%pathchange));
12083: if ($numpathchgs > 0) {
1.987 raeburn 12084: if ($context eq 'portfolio') {
12085: $output .= '<p>'.&mt('or').'</p>';
12086: } elsif ($context eq 'testbank') {
1.1071 raeburn 12087: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12088: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12089: $returnflag = 'modify_orightml';
12090: }
12091: }
1.1071 raeburn 12092: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12093: }
12094:
12095: sub modify_html_form {
12096: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12097: my $end = 0;
12098: my $modifyform;
12099: if ($context eq 'upload_embedded') {
12100: return unless (ref($pathchange) eq 'HASH');
12101: if ($env{'form.number_embedded_items'}) {
12102: $end += $env{'form.number_embedded_items'};
12103: }
12104: if ($env{'form.number_pathchange_items'}) {
12105: $end += $env{'form.number_pathchange_items'};
12106: }
12107: if ($end) {
12108: for (my $i=0; $i<$end; $i++) {
12109: if ($i < $env{'form.number_embedded_items'}) {
12110: next unless($pathchange->{$i});
12111: }
12112: $modifyform .=
12113: &start_data_table_row().
12114: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12115: 'checked="checked" /></td>'.
12116: '<td>'.$env{'form.embedded_ref_'.$i}.
12117: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12118: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12119: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12120: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12121: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12122: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12123: '<td>'.$env{'form.embedded_orig_'.$i}.
12124: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12125: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12126: &end_data_table_row();
1.1071 raeburn 12127: }
1.987 raeburn 12128: }
12129: } else {
12130: $modifyform = $pathchgtable;
12131: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12132: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12133: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12134: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12135: }
12136: }
12137: if ($modifyform) {
1.1071 raeburn 12138: if ($actionurl eq '/adm/dependencies') {
12139: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12140: }
1.987 raeburn 12141: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12142: '<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".
12143: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12144: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12145: '</ol></p>'."\n".'<p>'.
12146: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12147: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12148: &start_data_table()."\n".
12149: &start_data_table_header_row().
12150: '<th>'.&mt('Change?').'</th>'.
12151: '<th>'.&mt('Current reference').'</th>'.
12152: '<th>'.&mt('Required reference').'</th>'.
12153: &end_data_table_header_row()."\n".
12154: $modifyform.
12155: &end_data_table().'<br />'."\n".$hiddenstate.
12156: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12157: '</form>'."\n";
12158: }
12159: return;
12160: }
12161:
12162: sub modify_html_refs {
1.1123 raeburn 12163: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12164: my $container;
12165: if ($context eq 'portfolio') {
12166: $container = $env{'form.container'};
12167: } elsif ($context eq 'coursedoc') {
12168: $container = $env{'form.primaryurl'};
1.1071 raeburn 12169: } elsif ($context eq 'manage_dependencies') {
12170: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12171: $container = "/$container";
1.1123 raeburn 12172: } elsif ($context eq 'syllabus') {
12173: $container = $url;
1.987 raeburn 12174: } else {
1.1027 raeburn 12175: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12176: }
12177: my (%allfiles,%codebase,$output,$content);
12178: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 12179: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12180: if (wantarray) {
12181: return ('',0,0);
12182: } else {
12183: return;
12184: }
12185: }
12186: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12187: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12188: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12189: if (wantarray) {
12190: return ('',0,0);
12191: } else {
12192: return;
12193: }
12194: }
1.987 raeburn 12195: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12196: if ($content eq '-1') {
12197: if (wantarray) {
12198: return ('',0,0);
12199: } else {
12200: return;
12201: }
12202: }
1.987 raeburn 12203: } else {
1.1071 raeburn 12204: unless ($container =~ /^\Q$dir_root\E/) {
12205: if (wantarray) {
12206: return ('',0,0);
12207: } else {
12208: return;
12209: }
12210: }
1.1317 raeburn 12211: if (open(my $fh,'<',$container)) {
1.987 raeburn 12212: $content = join('', <$fh>);
12213: close($fh);
12214: } else {
1.1071 raeburn 12215: if (wantarray) {
12216: return ('',0,0);
12217: } else {
12218: return;
12219: }
1.987 raeburn 12220: }
12221: }
12222: my ($count,$codebasecount) = (0,0);
12223: my $mm = new File::MMagic;
12224: my $mime_type = $mm->checktype_contents($content);
12225: if ($mime_type eq 'text/html') {
12226: my $parse_result =
12227: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12228: \%codebase,\$content);
12229: if ($parse_result eq 'ok') {
12230: foreach my $i (@changes) {
12231: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12232: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12233: if ($allfiles{$ref}) {
12234: my $newname = $orig;
12235: my ($attrib_regexp,$codebase);
1.1006 raeburn 12236: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12237: if ($attrib_regexp =~ /:/) {
12238: $attrib_regexp =~ s/\:/|/g;
12239: }
12240: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12241: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12242: $count += $numchg;
1.1123 raeburn 12243: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12244: delete($allfiles{$ref});
1.987 raeburn 12245: }
12246: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12247: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12248: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12249: $codebasecount ++;
12250: }
12251: }
12252: }
1.1123 raeburn 12253: my $skiprewrites;
1.987 raeburn 12254: if ($count || $codebasecount) {
12255: my $saveresult;
1.1071 raeburn 12256: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12257: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12258: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12259: if ($url eq $container) {
12260: my ($fname) = ($container =~ m{/([^/]+)$});
12261: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12262: $count,'<span class="LC_filename">'.
1.1071 raeburn 12263: $fname.'</span>').'</p>';
1.987 raeburn 12264: } else {
12265: $output = '<p class="LC_error">'.
12266: &mt('Error: update failed for: [_1].',
12267: '<span class="LC_filename">'.
12268: $container.'</span>').'</p>';
12269: }
1.1123 raeburn 12270: if ($context eq 'syllabus') {
12271: unless ($saveresult eq 'ok') {
12272: $skiprewrites = 1;
12273: }
12274: }
1.987 raeburn 12275: } else {
1.1317 raeburn 12276: if (open(my $fh,'>',$container)) {
1.987 raeburn 12277: print $fh $content;
12278: close($fh);
12279: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12280: $count,'<span class="LC_filename">'.
12281: $container.'</span>').'</p>';
1.661 raeburn 12282: } else {
1.987 raeburn 12283: $output = '<p class="LC_error">'.
12284: &mt('Error: could not update [_1].',
12285: '<span class="LC_filename">'.
12286: $container.'</span>').'</p>';
1.661 raeburn 12287: }
12288: }
12289: }
1.1123 raeburn 12290: if (($context eq 'syllabus') && (!$skiprewrites)) {
12291: my ($actionurl,$state);
12292: $actionurl = "/public/$udom/$uname/syllabus";
12293: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12294: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12295: \%codebase,
12296: {'context' => 'rewrites',
12297: 'ignore_remote_references' => 1,});
12298: if (ref($mapping) eq 'HASH') {
12299: my $rewrites = 0;
12300: foreach my $key (keys(%{$mapping})) {
12301: next if ($key =~ m{^https?://});
12302: my $ref = $mapping->{$key};
12303: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12304: my $attrib;
12305: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12306: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12307: }
12308: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12309: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12310: $rewrites += $numchg;
12311: }
12312: }
12313: if ($rewrites) {
12314: my $saveresult;
12315: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12316: if ($url eq $container) {
12317: my ($fname) = ($container =~ m{/([^/]+)$});
12318: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12319: $count,'<span class="LC_filename">'.
12320: $fname.'</span>').'</p>';
12321: } else {
12322: $output .= '<p class="LC_error">'.
12323: &mt('Error: could not update links in [_1].',
12324: '<span class="LC_filename">'.
12325: $container.'</span>').'</p>';
12326:
12327: }
12328: }
12329: }
12330: }
1.987 raeburn 12331: } else {
12332: &logthis('Failed to parse '.$container.
12333: ' to modify references: '.$parse_result);
1.661 raeburn 12334: }
12335: }
1.1071 raeburn 12336: if (wantarray) {
12337: return ($output,$count,$codebasecount);
12338: } else {
12339: return $output;
12340: }
1.661 raeburn 12341: }
12342:
12343: sub check_for_existing {
12344: my ($path,$fname,$element) = @_;
12345: my ($state,$msg);
12346: if (-d $path.'/'.$fname) {
12347: $state = 'exists';
12348: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12349: } elsif (-e $path.'/'.$fname) {
12350: $state = 'exists';
12351: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12352: }
12353: if ($state eq 'exists') {
12354: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12355: }
12356: return ($state,$msg);
12357: }
12358:
12359: sub check_for_upload {
12360: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12361: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12362: my $filesize = length($env{'form.'.$element});
12363: if (!$filesize) {
12364: my $msg = '<span class="LC_error">'.
12365: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12366: '<span class="LC_filename">'.$fname.'</span>',
12367: $filesize).'<br />'.
1.1007 raeburn 12368: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12369: '</span>';
12370: return ('zero_bytes',$msg);
12371: }
12372: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12373: my $getpropath = 1;
1.1021 raeburn 12374: my ($dirlistref,$listerror) =
12375: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12376: my $found_file = 0;
12377: my $locked_file = 0;
1.991 raeburn 12378: my @lockers;
12379: my $navmap;
12380: if ($env{'request.course.id'}) {
12381: $navmap = Apache::lonnavmaps::navmap->new();
12382: }
1.1021 raeburn 12383: if (ref($dirlistref) eq 'ARRAY') {
12384: foreach my $line (@{$dirlistref}) {
12385: my ($file_name,$rest)=split(/\&/,$line,2);
12386: if ($file_name eq $fname){
12387: $file_name = $path.$file_name;
12388: if ($group ne '') {
12389: $file_name = $group.$file_name;
12390: }
12391: $found_file = 1;
12392: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12393: foreach my $lock (@lockers) {
12394: if (ref($lock) eq 'ARRAY') {
12395: my ($symb,$crsid) = @{$lock};
12396: if ($crsid eq $env{'request.course.id'}) {
12397: if (ref($navmap)) {
12398: my $res = $navmap->getBySymb($symb);
12399: foreach my $part (@{$res->parts()}) {
12400: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12401: unless (($slot_status == $res->RESERVED) ||
12402: ($slot_status == $res->RESERVED_LOCATION)) {
12403: $locked_file = 1;
12404: }
1.991 raeburn 12405: }
1.1021 raeburn 12406: } else {
12407: $locked_file = 1;
1.991 raeburn 12408: }
12409: } else {
12410: $locked_file = 1;
12411: }
12412: }
1.1021 raeburn 12413: }
12414: } else {
12415: my @info = split(/\&/,$rest);
12416: my $currsize = $info[6]/1000;
12417: if ($currsize < $filesize) {
12418: my $extra = $filesize - $currsize;
12419: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12420: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12421: &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 12422: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12423: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12424: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12425: return ('will_exceed_quota',$msg);
12426: }
1.984 raeburn 12427: }
12428: }
1.661 raeburn 12429: }
12430: }
12431: }
12432: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12433: my $msg = '<p class="LC_warning">'.
12434: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12435: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12436: return ('will_exceed_quota',$msg);
12437: } elsif ($found_file) {
12438: if ($locked_file) {
1.1179 bisitz 12439: my $msg = '<p class="LC_warning">';
1.661 raeburn 12440: $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 12441: $msg .= '</p>';
1.661 raeburn 12442: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12443: return ('file_locked',$msg);
12444: } else {
1.1179 bisitz 12445: my $msg = '<p class="LC_error">';
1.984 raeburn 12446: $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 12447: $msg .= '</p>';
1.984 raeburn 12448: return ('existingfile',$msg);
1.661 raeburn 12449: }
12450: }
12451: }
12452:
1.987 raeburn 12453: sub check_for_traversal {
12454: my ($path,$url,$toplevel) = @_;
12455: my @parts=split(/\//,$path);
12456: my $cleanpath;
12457: my $fullpath = $url;
12458: for (my $i=0;$i<@parts;$i++) {
12459: next if ($parts[$i] eq '.');
12460: if ($parts[$i] eq '..') {
12461: $fullpath =~ s{([^/]+/)$}{};
12462: } else {
12463: $fullpath .= $parts[$i].'/';
12464: }
12465: }
12466: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12467: $cleanpath = $1;
12468: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12469: my $curr_toprel = $1;
12470: my @parts = split(/\//,$curr_toprel);
12471: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12472: my @urlparts = split(/\//,$url_toprel);
12473: my $doubledots;
12474: my $startdiff = -1;
12475: for (my $i=0; $i<@urlparts; $i++) {
12476: if ($startdiff == -1) {
12477: unless ($urlparts[$i] eq $parts[$i]) {
12478: $startdiff = $i;
12479: $doubledots .= '../';
12480: }
12481: } else {
12482: $doubledots .= '../';
12483: }
12484: }
12485: if ($startdiff > -1) {
12486: $cleanpath = $doubledots;
12487: for (my $i=$startdiff; $i<@parts; $i++) {
12488: $cleanpath .= $parts[$i].'/';
12489: }
12490: }
12491: }
12492: $cleanpath =~ s{(/)$}{};
12493: return $cleanpath;
12494: }
1.31 albertel 12495:
1.1053 raeburn 12496: sub is_archive_file {
12497: my ($mimetype) = @_;
12498: if (($mimetype eq 'application/octet-stream') ||
12499: ($mimetype eq 'application/x-stuffit') ||
12500: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12501: return 1;
12502: }
12503: return;
12504: }
12505:
12506: sub decompress_form {
1.1065 raeburn 12507: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12508: my %lt = &Apache::lonlocal::texthash (
12509: this => 'This file is an archive file.',
1.1067 raeburn 12510: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12511: itsc => 'Its contents are as follows:',
1.1053 raeburn 12512: youm => 'You may wish to extract its contents.',
12513: extr => 'Extract contents',
1.1067 raeburn 12514: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12515: proa => 'Process automatically?',
1.1053 raeburn 12516: yes => 'Yes',
12517: no => 'No',
1.1067 raeburn 12518: fold => 'Title for folder containing movie',
12519: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12520: );
1.1065 raeburn 12521: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12522: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12523: my $info = &list_archive_contents($fileloc,\@paths);
12524: if (@paths) {
12525: foreach my $path (@paths) {
12526: $path =~ s{^/}{};
1.1067 raeburn 12527: if ($path =~ m{^([^/]+)/$}) {
12528: $topdir = $1;
12529: }
1.1065 raeburn 12530: if ($path =~ m{^([^/]+)/}) {
12531: $toplevel{$1} = $path;
12532: } else {
12533: $toplevel{$path} = $path;
12534: }
12535: }
12536: }
1.1067 raeburn 12537: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12538: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12539: "$topdir/media/",
12540: "$topdir/media/$topdir.mp4",
12541: "$topdir/media/FirstFrame.png",
12542: "$topdir/media/player.swf",
12543: "$topdir/media/swfobject.js",
12544: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12545: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12546: "$topdir/$topdir.mp4",
12547: "$topdir/$topdir\_config.xml",
12548: "$topdir/$topdir\_controller.swf",
12549: "$topdir/$topdir\_embed.css",
12550: "$topdir/$topdir\_First_Frame.png",
12551: "$topdir/$topdir\_player.html",
12552: "$topdir/$topdir\_Thumbnails.png",
12553: "$topdir/playerProductInstall.swf",
12554: "$topdir/scripts/",
12555: "$topdir/scripts/config_xml.js",
12556: "$topdir/scripts/handlebars.js",
12557: "$topdir/scripts/jquery-1.7.1.min.js",
12558: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12559: "$topdir/scripts/modernizr.js",
12560: "$topdir/scripts/player-min.js",
12561: "$topdir/scripts/swfobject.js",
12562: "$topdir/skins/",
12563: "$topdir/skins/configuration_express.xml",
12564: "$topdir/skins/express_show/",
12565: "$topdir/skins/express_show/player-min.css",
12566: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12567: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12568: "$topdir/$topdir.mp4",
12569: "$topdir/$topdir\_config.xml",
12570: "$topdir/$topdir\_controller.swf",
12571: "$topdir/$topdir\_embed.css",
12572: "$topdir/$topdir\_First_Frame.png",
12573: "$topdir/$topdir\_player.html",
12574: "$topdir/$topdir\_Thumbnails.png",
12575: "$topdir/playerProductInstall.swf",
12576: "$topdir/scripts/",
12577: "$topdir/scripts/config_xml.js",
12578: "$topdir/scripts/techsmith-smart-player.min.js",
12579: "$topdir/skins/",
12580: "$topdir/skins/configuration_express.xml",
12581: "$topdir/skins/express_show/",
12582: "$topdir/skins/express_show/spritesheet.min.css",
12583: "$topdir/skins/express_show/spritesheet.png",
12584: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12585: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12586: if (@diffs == 0) {
1.1164 raeburn 12587: $is_camtasia = 6;
12588: } else {
1.1197 raeburn 12589: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12590: if (@diffs == 0) {
12591: $is_camtasia = 8;
1.1197 raeburn 12592: } else {
12593: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12594: if (@diffs == 0) {
12595: $is_camtasia = 8;
12596: }
1.1164 raeburn 12597: }
1.1067 raeburn 12598: }
12599: }
12600: my $output;
12601: if ($is_camtasia) {
12602: $output = <<"ENDCAM";
12603: <script type="text/javascript" language="Javascript">
12604: // <![CDATA[
12605:
12606: function camtasiaToggle() {
12607: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12608: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12609: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12610: document.getElementById('camtasia_titles').style.display='block';
12611: } else {
12612: document.getElementById('camtasia_titles').style.display='none';
12613: }
12614: }
12615: }
12616: return;
12617: }
12618:
12619: // ]]>
12620: </script>
12621: <p>$lt{'camt'}</p>
12622: ENDCAM
1.1065 raeburn 12623: } else {
1.1067 raeburn 12624: $output = '<p>'.$lt{'this'};
12625: if ($info eq '') {
12626: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12627: } else {
12628: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12629: '<div><pre>'.$info.'</pre></div>';
12630: }
1.1065 raeburn 12631: }
1.1067 raeburn 12632: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12633: my $duplicates;
12634: my $num = 0;
12635: if (ref($dirlist) eq 'ARRAY') {
12636: foreach my $item (@{$dirlist}) {
12637: if (ref($item) eq 'ARRAY') {
12638: if (exists($toplevel{$item->[0]})) {
12639: $duplicates .=
12640: &start_data_table_row().
12641: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12642: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12643: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12644: 'value="1" />'.&mt('Yes').'</label>'.
12645: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12646: '<td>'.$item->[0].'</td>';
12647: if ($item->[2]) {
12648: $duplicates .= '<td>'.&mt('Directory').'</td>';
12649: } else {
12650: $duplicates .= '<td>'.&mt('File').'</td>';
12651: }
12652: $duplicates .= '<td>'.$item->[3].'</td>'.
12653: '<td>'.
12654: &Apache::lonlocal::locallocaltime($item->[4]).
12655: '</td>'.
12656: &end_data_table_row();
12657: $num ++;
12658: }
12659: }
12660: }
12661: }
12662: my $itemcount;
12663: if (@paths > 0) {
12664: $itemcount = scalar(@paths);
12665: } else {
12666: $itemcount = 1;
12667: }
1.1067 raeburn 12668: if ($is_camtasia) {
12669: $output .= $lt{'auto'}.'<br />'.
12670: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12671: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12672: $lt{'yes'}.'</label> <label>'.
12673: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12674: $lt{'no'}.'</label></span><br />'.
12675: '<div id="camtasia_titles" style="display:block">'.
12676: &Apache::lonhtmlcommon::start_pick_box().
12677: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12678: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12679: &Apache::lonhtmlcommon::row_closure().
12680: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12681: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12682: &Apache::lonhtmlcommon::row_closure(1).
12683: &Apache::lonhtmlcommon::end_pick_box().
12684: '</div>';
12685: }
1.1065 raeburn 12686: $output .=
12687: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12688: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12689: "\n";
1.1065 raeburn 12690: if ($duplicates ne '') {
12691: $output .= '<p><span class="LC_warning">'.
12692: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12693: &start_data_table().
12694: &start_data_table_header_row().
12695: '<th>'.&mt('Overwrite?').'</th>'.
12696: '<th>'.&mt('Name').'</th>'.
12697: '<th>'.&mt('Type').'</th>'.
12698: '<th>'.&mt('Size').'</th>'.
12699: '<th>'.&mt('Last modified').'</th>'.
12700: &end_data_table_header_row().
12701: $duplicates.
12702: &end_data_table().
12703: '</p>';
12704: }
1.1067 raeburn 12705: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12706: if (ref($hiddenelements) eq 'HASH') {
12707: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12708: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12709: }
12710: }
12711: $output .= <<"END";
1.1067 raeburn 12712: <br />
1.1053 raeburn 12713: <input type="submit" name="decompress" value="$lt{'extr'}" />
12714: </form>
12715: $noextract
12716: END
12717: return $output;
12718: }
12719:
1.1065 raeburn 12720: sub decompression_utility {
12721: my ($program) = @_;
12722: my @utilities = ('tar','gunzip','bunzip2','unzip');
12723: my $location;
12724: if (grep(/^\Q$program\E$/,@utilities)) {
12725: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12726: '/usr/sbin/') {
12727: if (-x $dir.$program) {
12728: $location = $dir.$program;
12729: last;
12730: }
12731: }
12732: }
12733: return $location;
12734: }
12735:
12736: sub list_archive_contents {
12737: my ($file,$pathsref) = @_;
12738: my (@cmd,$output);
12739: my $needsregexp;
12740: if ($file =~ /\.zip$/) {
12741: @cmd = (&decompression_utility('unzip'),"-l");
12742: $needsregexp = 1;
12743: } elsif (($file =~ m/\.tar\.gz$/) ||
12744: ($file =~ /\.tgz$/)) {
12745: @cmd = (&decompression_utility('tar'),"-ztf");
12746: } elsif ($file =~ /\.tar\.bz2$/) {
12747: @cmd = (&decompression_utility('tar'),"-jtf");
12748: } elsif ($file =~ m|\.tar$|) {
12749: @cmd = (&decompression_utility('tar'),"-tf");
12750: }
12751: if (@cmd) {
12752: undef($!);
12753: undef($@);
12754: if (open(my $fh,"-|", @cmd, $file)) {
12755: while (my $line = <$fh>) {
12756: $output .= $line;
12757: chomp($line);
12758: my $item;
12759: if ($needsregexp) {
12760: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12761: } else {
12762: $item = $line;
12763: }
12764: if ($item ne '') {
12765: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12766: push(@{$pathsref},$item);
12767: }
12768: }
12769: }
12770: close($fh);
12771: }
12772: }
12773: return $output;
12774: }
12775:
1.1053 raeburn 12776: sub decompress_uploaded_file {
12777: my ($file,$dir) = @_;
12778: &Apache::lonnet::appenv({'cgi.file' => $file});
12779: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12780: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12781: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12782: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12783: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12784: my $decompressed = $env{'cgi.decompressed'};
12785: &Apache::lonnet::delenv('cgi.file');
12786: &Apache::lonnet::delenv('cgi.dir');
12787: &Apache::lonnet::delenv('cgi.decompressed');
12788: return ($decompressed,$result);
12789: }
12790:
1.1055 raeburn 12791: sub process_decompression {
12792: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 12793: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12794: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12795: &mt('Unexpected file path.').'</p>'."\n";
12796: }
12797: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12798: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12799: &mt('Unexpected course context.').'</p>'."\n";
12800: }
1.1293 raeburn 12801: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 12802: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12803: &mt('Filename contained unexpected characters.').'</p>'."\n";
12804: }
1.1055 raeburn 12805: my ($dir,$error,$warning,$output);
1.1180 raeburn 12806: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12807: $error = &mt('Filename not a supported archive file type.').
12808: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12809: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12810: } else {
12811: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12812: if ($docuhome eq 'no_host') {
12813: $error = &mt('Could not determine home server for course.');
12814: } else {
12815: my @ids=&Apache::lonnet::current_machine_ids();
12816: my $currdir = "$dir_root/$destination";
12817: if (grep(/^\Q$docuhome\E$/,@ids)) {
12818: $dir = &LONCAPA::propath($docudom,$docuname).
12819: "$dir_root/$destination";
12820: } else {
12821: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12822: "$dir_root/$docudom/$docuname/$destination";
12823: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12824: $error = &mt('Archive file not found.');
12825: }
12826: }
1.1065 raeburn 12827: my (@to_overwrite,@to_skip);
12828: if ($env{'form.archive_overwrite_total'} > 0) {
12829: my $total = $env{'form.archive_overwrite_total'};
12830: for (my $i=0; $i<$total; $i++) {
12831: if ($env{'form.archive_overwrite_'.$i} == 1) {
12832: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12833: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12834: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12835: }
12836: }
12837: }
12838: my $numskip = scalar(@to_skip);
1.1292 raeburn 12839: my $numoverwrite = scalar(@to_overwrite);
12840: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12841: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12842: } elsif ($dir eq '') {
1.1055 raeburn 12843: $error = &mt('Directory containing archive file unavailable.');
12844: } elsif (!$error) {
1.1065 raeburn 12845: my ($decompressed,$display);
1.1292 raeburn 12846: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12847: my $tempdir = time.'_'.$$.int(rand(10000));
12848: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 12849: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12850: ($decompressed,$display) =
12851: &decompress_uploaded_file($file,"$dir/$tempdir");
12852: foreach my $item (@to_skip) {
12853: if (($item ne '') && ($item !~ /\.\./)) {
12854: if (-f "$dir/$tempdir/$item") {
12855: unlink("$dir/$tempdir/$item");
12856: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 12857: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 12858: }
12859: }
12860: }
12861: foreach my $item (@to_overwrite) {
12862: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12863: if (($item ne '') && ($item !~ /\.\./)) {
12864: if (-f "$dir/$item") {
12865: unlink("$dir/$item");
12866: } elsif (-d "$dir/$item") {
1.1300 raeburn 12867: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 12868: }
12869: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12870: }
1.1065 raeburn 12871: }
12872: }
1.1292 raeburn 12873: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 12874: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 12875: }
1.1065 raeburn 12876: }
12877: } else {
12878: ($decompressed,$display) =
12879: &decompress_uploaded_file($file,$dir);
12880: }
1.1055 raeburn 12881: if ($decompressed eq 'ok') {
1.1065 raeburn 12882: $output = '<p class="LC_info">'.
12883: &mt('Files extracted successfully from archive.').
12884: '</p>'."\n";
1.1055 raeburn 12885: my ($warning,$result,@contents);
12886: my ($newdirlistref,$newlisterror) =
12887: &Apache::lonnet::dirlist($currdir,$docudom,
12888: $docuname,1);
12889: my (%is_dir,%changes,@newitems);
12890: my $dirptr = 16384;
1.1065 raeburn 12891: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12892: foreach my $dir_line (@{$newdirlistref}) {
12893: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 12894: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12895: push(@newitems,$item);
12896: if ($dirptr&$testdir) {
12897: $is_dir{$item} = 1;
12898: }
12899: $changes{$item} = 1;
12900: }
12901: }
12902: }
12903: if (keys(%changes) > 0) {
12904: foreach my $item (sort(@newitems)) {
12905: if ($changes{$item}) {
12906: push(@contents,$item);
12907: }
12908: }
12909: }
12910: if (@contents > 0) {
1.1067 raeburn 12911: my $wantform;
12912: unless ($env{'form.autoextract_camtasia'}) {
12913: $wantform = 1;
12914: }
1.1056 raeburn 12915: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12916: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12917: $currdir,\%is_dir,
12918: \%children,\%parent,
1.1056 raeburn 12919: \@contents,\%dirorder,
12920: \%titles,$wantform);
1.1055 raeburn 12921: if ($datatable ne '') {
12922: $output .= &archive_options_form('decompressed',$datatable,
12923: $count,$hiddenelem);
1.1065 raeburn 12924: my $startcount = 6;
1.1055 raeburn 12925: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12926: \%titles,\%children);
1.1055 raeburn 12927: }
1.1067 raeburn 12928: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 12929: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12930: my %displayed;
12931: my $total = 1;
12932: $env{'form.archive_directory'} = [];
12933: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12934: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12935: $path =~ s{/$}{};
12936: my $item;
12937: if ($path ne '') {
12938: $item = "$path/$titles{$i}";
12939: } else {
12940: $item = $titles{$i};
12941: }
12942: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12943: if ($item eq $contents[0]) {
12944: push(@{$env{'form.archive_directory'}},$i);
12945: $env{'form.archive_'.$i} = 'display';
12946: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12947: $displayed{'folder'} = $i;
1.1164 raeburn 12948: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12949: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12950: $env{'form.archive_'.$i} = 'display';
12951: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12952: $displayed{'web'} = $i;
12953: } else {
1.1164 raeburn 12954: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12955: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12956: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12957: push(@{$env{'form.archive_directory'}},$i);
12958: }
12959: $env{'form.archive_'.$i} = 'dependency';
12960: }
12961: $total ++;
12962: }
12963: for (my $i=1; $i<$total; $i++) {
12964: next if ($i == $displayed{'web'});
12965: next if ($i == $displayed{'folder'});
12966: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12967: }
12968: $env{'form.phase'} = 'decompress_cleanup';
12969: $env{'form.archivedelete'} = 1;
12970: $env{'form.archive_count'} = $total-1;
12971: $output .=
12972: &process_extracted_files('coursedocs',$docudom,
12973: $docuname,$destination,
12974: $dir_root,$hiddenelem);
12975: }
1.1055 raeburn 12976: } else {
12977: $warning = &mt('No new items extracted from archive file.');
12978: }
12979: } else {
12980: $output = $display;
12981: $error = &mt('An error occurred during extraction from the archive file.');
12982: }
12983: }
12984: }
12985: }
12986: if ($error) {
12987: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12988: $error.'</p>'."\n";
12989: }
12990: if ($warning) {
12991: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12992: }
12993: return $output;
12994: }
12995:
12996: sub get_extracted {
1.1056 raeburn 12997: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12998: $titles,$wantform) = @_;
1.1055 raeburn 12999: my $count = 0;
13000: my $depth = 0;
13001: my $datatable;
1.1056 raeburn 13002: my @hierarchy;
1.1055 raeburn 13003: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 13004: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
13005: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 13006: foreach my $item (@{$contents}) {
13007: $count ++;
1.1056 raeburn 13008: @{$dirorder->{$count}} = @hierarchy;
13009: $titles->{$count} = $item;
1.1055 raeburn 13010: &archive_hierarchy($depth,$count,$parent,$children);
13011: if ($wantform) {
13012: $datatable .= &archive_row($is_dir->{$item},$item,
13013: $currdir,$depth,$count);
13014: }
13015: if ($is_dir->{$item}) {
13016: $depth ++;
1.1056 raeburn 13017: push(@hierarchy,$count);
13018: $parent->{$depth} = $count;
1.1055 raeburn 13019: $datatable .=
13020: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 13021: \$depth,\$count,\@hierarchy,$dirorder,
13022: $children,$parent,$titles,$wantform);
1.1055 raeburn 13023: $depth --;
1.1056 raeburn 13024: pop(@hierarchy);
1.1055 raeburn 13025: }
13026: }
13027: return ($count,$datatable);
13028: }
13029:
13030: sub recurse_extracted_archive {
1.1056 raeburn 13031: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
13032: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 13033: my $result='';
1.1056 raeburn 13034: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
13035: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
13036: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 13037: return $result;
13038: }
13039: my $dirptr = 16384;
13040: my ($newdirlistref,$newlisterror) =
13041: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
13042: if (ref($newdirlistref) eq 'ARRAY') {
13043: foreach my $dir_line (@{$newdirlistref}) {
13044: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
13045: unless ($item =~ /^\.+$/) {
13046: $$count ++;
1.1056 raeburn 13047: @{$dirorder->{$$count}} = @{$hierarchy};
13048: $titles->{$$count} = $item;
1.1055 raeburn 13049: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 13050:
1.1055 raeburn 13051: my $is_dir;
13052: if ($dirptr&$testdir) {
13053: $is_dir = 1;
13054: }
13055: if ($wantform) {
13056: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
13057: }
13058: if ($is_dir) {
13059: $$depth ++;
1.1056 raeburn 13060: push(@{$hierarchy},$$count);
13061: $parent->{$$depth} = $$count;
1.1055 raeburn 13062: $result .=
13063: &recurse_extracted_archive("$currdir/$item",$docudom,
13064: $docuname,$depth,$count,
1.1056 raeburn 13065: $hierarchy,$dirorder,$children,
13066: $parent,$titles,$wantform);
1.1055 raeburn 13067: $$depth --;
1.1056 raeburn 13068: pop(@{$hierarchy});
1.1055 raeburn 13069: }
13070: }
13071: }
13072: }
13073: return $result;
13074: }
13075:
13076: sub archive_hierarchy {
13077: my ($depth,$count,$parent,$children) =@_;
13078: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13079: if (exists($parent->{$depth})) {
13080: $children->{$parent->{$depth}} .= $count.':';
13081: }
13082: }
13083: return;
13084: }
13085:
13086: sub archive_row {
13087: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13088: my ($name) = ($item =~ m{([^/]+)$});
13089: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13090: 'display' => 'Add as file',
1.1055 raeburn 13091: 'dependency' => 'Include as dependency',
13092: 'discard' => 'Discard',
13093: );
13094: if ($is_dir) {
1.1059 raeburn 13095: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13096: }
1.1056 raeburn 13097: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13098: my $offset = 0;
1.1055 raeburn 13099: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13100: $offset ++;
1.1065 raeburn 13101: if ($action ne 'display') {
13102: $offset ++;
13103: }
1.1055 raeburn 13104: $output .= '<td><span class="LC_nobreak">'.
13105: '<label><input type="radio" name="archive_'.$count.
13106: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13107: my $text = $choices{$action};
13108: if ($is_dir) {
13109: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13110: if ($action eq 'display') {
1.1059 raeburn 13111: $text = &mt('Add as folder');
1.1055 raeburn 13112: }
1.1056 raeburn 13113: } else {
13114: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13115:
13116: }
13117: $output .= ' /> '.$choices{$action}.'</label></span>';
13118: if ($action eq 'dependency') {
13119: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13120: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13121: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13122: '<option value=""></option>'."\n".
13123: '</select>'."\n".
13124: '</div>';
1.1059 raeburn 13125: } elsif ($action eq 'display') {
13126: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13127: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13128: '</div>';
1.1055 raeburn 13129: }
1.1056 raeburn 13130: $output .= '</td>';
1.1055 raeburn 13131: }
13132: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13133: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13134: for (my $i=0; $i<$depth; $i++) {
13135: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13136: }
13137: if ($is_dir) {
13138: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13139: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13140: } else {
13141: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13142: }
13143: $output .= ' '.$name.'</td>'."\n".
13144: &end_data_table_row();
13145: return $output;
13146: }
13147:
13148: sub archive_options_form {
1.1065 raeburn 13149: my ($form,$display,$count,$hiddenelem) = @_;
13150: my %lt = &Apache::lonlocal::texthash(
13151: perm => 'Permanently remove archive file?',
13152: hows => 'How should each extracted item be incorporated in the course?',
13153: cont => 'Content actions for all',
13154: addf => 'Add as folder/file',
13155: incd => 'Include as dependency for a displayed file',
13156: disc => 'Discard',
13157: no => 'No',
13158: yes => 'Yes',
13159: save => 'Save',
13160: );
13161: my $output = <<"END";
13162: <form name="$form" method="post" action="">
13163: <p><span class="LC_nobreak">$lt{'perm'}
13164: <label>
13165: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13166: </label>
13167:
13168: <label>
13169: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13170: </span>
13171: </p>
13172: <input type="hidden" name="phase" value="decompress_cleanup" />
13173: <br />$lt{'hows'}
13174: <div class="LC_columnSection">
13175: <fieldset>
13176: <legend>$lt{'cont'}</legend>
13177: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13178: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13179: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13180: </fieldset>
13181: </div>
13182: END
13183: return $output.
1.1055 raeburn 13184: &start_data_table()."\n".
1.1065 raeburn 13185: $display."\n".
1.1055 raeburn 13186: &end_data_table()."\n".
13187: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13188: $hiddenelem.
1.1065 raeburn 13189: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13190: '</form>';
13191: }
13192:
13193: sub archive_javascript {
1.1056 raeburn 13194: my ($startcount,$numitems,$titles,$children) = @_;
13195: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13196: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13197: my $scripttag = <<START;
13198: <script type="text/javascript">
13199: // <![CDATA[
13200:
13201: function checkAll(form,prefix) {
13202: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13203: for (var i=0; i < form.elements.length; i++) {
13204: var id = form.elements[i].id;
13205: if ((id != '') && (id != undefined)) {
13206: if (idstr.test(id)) {
13207: if (form.elements[i].type == 'radio') {
13208: form.elements[i].checked = true;
1.1056 raeburn 13209: var nostart = i-$startcount;
1.1059 raeburn 13210: var offset = nostart%7;
13211: var count = (nostart-offset)/7;
1.1056 raeburn 13212: dependencyCheck(form,count,offset);
1.1055 raeburn 13213: }
13214: }
13215: }
13216: }
13217: }
13218:
13219: function propagateCheck(form,count) {
13220: if (count > 0) {
1.1059 raeburn 13221: var startelement = $startcount + ((count-1) * 7);
13222: for (var j=1; j<6; j++) {
13223: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13224: var item = startelement + j;
13225: if (form.elements[item].type == 'radio') {
13226: if (form.elements[item].checked) {
13227: containerCheck(form,count,j);
13228: break;
13229: }
1.1055 raeburn 13230: }
13231: }
13232: }
13233: }
13234: }
13235:
13236: numitems = $numitems
1.1056 raeburn 13237: var titles = new Array(numitems);
13238: var parents = new Array(numitems);
1.1055 raeburn 13239: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13240: parents[i] = new Array;
1.1055 raeburn 13241: }
1.1059 raeburn 13242: var maintitle = '$maintitle';
1.1055 raeburn 13243:
13244: START
13245:
1.1056 raeburn 13246: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13247: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13248: for (my $i=0; $i<@contents; $i ++) {
13249: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13250: }
13251: }
13252:
1.1056 raeburn 13253: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13254: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13255: }
13256:
1.1055 raeburn 13257: $scripttag .= <<END;
13258:
13259: function containerCheck(form,count,offset) {
13260: if (count > 0) {
1.1056 raeburn 13261: dependencyCheck(form,count,offset);
1.1059 raeburn 13262: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13263: form.elements[item].checked = true;
13264: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13265: if (parents[count].length > 0) {
13266: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13267: containerCheck(form,parents[count][j],offset);
13268: }
13269: }
13270: }
13271: }
13272: }
13273:
13274: function dependencyCheck(form,count,offset) {
13275: if (count > 0) {
1.1059 raeburn 13276: var chosen = (offset+$startcount)+7*(count-1);
13277: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13278: var currtype = form.elements[depitem].type;
13279: if (form.elements[chosen].value == 'dependency') {
13280: document.getElementById('arc_depon_'+count).style.display='block';
13281: form.elements[depitem].options.length = 0;
13282: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13283: for (var i=1; i<=numitems; i++) {
13284: if (i == count) {
13285: continue;
13286: }
1.1059 raeburn 13287: var startelement = $startcount + (i-1) * 7;
13288: for (var j=1; j<6; j++) {
13289: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13290: var item = startelement + j;
13291: if (form.elements[item].type == 'radio') {
13292: if (form.elements[item].checked) {
13293: if (form.elements[item].value == 'display') {
13294: var n = form.elements[depitem].options.length;
13295: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13296: }
13297: }
13298: }
13299: }
13300: }
13301: }
13302: } else {
13303: document.getElementById('arc_depon_'+count).style.display='none';
13304: form.elements[depitem].options.length = 0;
13305: form.elements[depitem].options[0] = new Option('Select','',true,true);
13306: }
1.1059 raeburn 13307: titleCheck(form,count,offset);
1.1056 raeburn 13308: }
13309: }
13310:
13311: function propagateSelect(form,count,offset) {
13312: if (count > 0) {
1.1065 raeburn 13313: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13314: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13315: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13316: if (parents[count].length > 0) {
13317: for (var j=0; j<parents[count].length; j++) {
13318: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13319: }
13320: }
13321: }
13322: }
13323: }
1.1056 raeburn 13324:
13325: function containerSelect(form,count,offset,picked) {
13326: if (count > 0) {
1.1065 raeburn 13327: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13328: if (form.elements[item].type == 'radio') {
13329: if (form.elements[item].value == 'dependency') {
13330: if (form.elements[item+1].type == 'select-one') {
13331: for (var i=0; i<form.elements[item+1].options.length; i++) {
13332: if (form.elements[item+1].options[i].value == picked) {
13333: form.elements[item+1].selectedIndex = i;
13334: break;
13335: }
13336: }
13337: }
13338: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13339: if (parents[count].length > 0) {
13340: for (var j=0; j<parents[count].length; j++) {
13341: containerSelect(form,parents[count][j],offset,picked);
13342: }
13343: }
13344: }
13345: }
13346: }
13347: }
13348: }
13349:
1.1059 raeburn 13350: function titleCheck(form,count,offset) {
13351: if (count > 0) {
13352: var chosen = (offset+$startcount)+7*(count-1);
13353: var depitem = $startcount + ((count-1) * 7) + 2;
13354: var currtype = form.elements[depitem].type;
13355: if (form.elements[chosen].value == 'display') {
13356: document.getElementById('arc_title_'+count).style.display='block';
13357: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13358: document.getElementById('archive_title_'+count).value=maintitle;
13359: }
13360: } else {
13361: document.getElementById('arc_title_'+count).style.display='none';
13362: if (currtype == 'text') {
13363: document.getElementById('archive_title_'+count).value='';
13364: }
13365: }
13366: }
13367: return;
13368: }
13369:
1.1055 raeburn 13370: // ]]>
13371: </script>
13372: END
13373: return $scripttag;
13374: }
13375:
13376: sub process_extracted_files {
1.1067 raeburn 13377: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13378: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 13379: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13380: my @ids=&Apache::lonnet::current_machine_ids();
13381: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13382: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13383: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13384: if (grep(/^\Q$docuhome\E$/,@ids)) {
13385: $prefix = &LONCAPA::propath($docudom,$docuname);
13386: $pathtocheck = "$dir_root/$destination";
13387: $dir = $dir_root;
13388: $ishome = 1;
13389: } else {
13390: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13391: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 13392: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13393: }
13394: my $currdir = "$dir_root/$destination";
13395: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13396: if ($env{'form.folderpath'}) {
13397: my @items = split('&',$env{'form.folderpath'});
13398: $folders{'0'} = $items[-2];
1.1099 raeburn 13399: if ($env{'form.folderpath'} =~ /\:1$/) {
13400: $containers{'0'}='page';
13401: } else {
13402: $containers{'0'}='sequence';
13403: }
1.1055 raeburn 13404: }
13405: my @archdirs = &get_env_multiple('form.archive_directory');
13406: if ($numitems) {
13407: for (my $i=1; $i<=$numitems; $i++) {
13408: my $path = $env{'form.archive_content_'.$i};
13409: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13410: my $item = $1;
13411: $toplevelitems{$item} = $i;
13412: if (grep(/^\Q$i\E$/,@archdirs)) {
13413: $is_dir{$item} = 1;
13414: }
13415: }
13416: }
13417: }
1.1067 raeburn 13418: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13419: if (keys(%toplevelitems) > 0) {
13420: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13421: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13422: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13423: }
1.1066 raeburn 13424: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13425: if ($numitems) {
13426: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13427: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13428: my $path = $env{'form.archive_content_'.$i};
13429: if ($path =~ /^\Q$pathtocheck\E/) {
13430: if ($env{'form.archive_'.$i} eq 'discard') {
13431: if ($prefix ne '' && $path ne '') {
13432: if (-e $prefix.$path) {
1.1066 raeburn 13433: if ((@archdirs > 0) &&
13434: (grep(/^\Q$i\E$/,@archdirs))) {
13435: $todeletedir{$prefix.$path} = 1;
13436: } else {
13437: $todelete{$prefix.$path} = 1;
13438: }
1.1055 raeburn 13439: }
13440: }
13441: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13442: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13443: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13444: $docstitle = $env{'form.archive_title_'.$i};
13445: if ($docstitle eq '') {
13446: $docstitle = $title;
13447: }
1.1055 raeburn 13448: $outer = 0;
1.1056 raeburn 13449: if (ref($dirorder{$i}) eq 'ARRAY') {
13450: if (@{$dirorder{$i}} > 0) {
13451: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13452: if ($env{'form.archive_'.$item} eq 'display') {
13453: $outer = $item;
13454: last;
13455: }
13456: }
13457: }
13458: }
13459: my ($errtext,$fatal) =
13460: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13461: '/'.$folders{$outer}.'.'.
13462: $containers{$outer});
13463: next if ($fatal);
13464: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13465: if ($context eq 'coursedocs') {
1.1056 raeburn 13466: $mapinner{$i} = time;
1.1055 raeburn 13467: $folders{$i} = 'default_'.$mapinner{$i};
13468: $containers{$i} = 'sequence';
13469: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13470: $folders{$i}.'.'.$containers{$i};
13471: my $newidx = &LONCAPA::map::getresidx();
13472: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13473: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13474: push(@LONCAPA::map::order,$newidx);
13475: my ($outtext,$errtext) =
13476: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13477: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13478: '.'.$containers{$outer},1,1);
1.1056 raeburn 13479: $newseqid{$i} = $newidx;
1.1067 raeburn 13480: unless ($errtext) {
1.1294 raeburn 13481: $result .= '<li>'.&mt('Folder: [_1] added to course',
13482: &HTML::Entities::encode($docstitle,'<>&"')).
13483: '</li>'."\n";
1.1067 raeburn 13484: }
1.1055 raeburn 13485: }
13486: } else {
13487: if ($context eq 'coursedocs') {
13488: my $newidx=&LONCAPA::map::getresidx();
13489: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13490: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13491: $title;
1.1294 raeburn 13492: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
13493: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13494: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13495: }
13496: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13497: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13498: }
13499: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13500: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13501: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13502: unless ($ishome) {
13503: my $fetch = "$newdest{$i}/$title";
13504: $fetch =~ s/^\Q$prefix$dir\E//;
13505: $prompttofetch{$fetch} = 1;
13506: }
1.1292 raeburn 13507: }
1.1067 raeburn 13508: }
1.1294 raeburn 13509: $LONCAPA::map::resources[$newidx]=
13510: $docstitle.':'.$url.':false:normal:res';
13511: push(@LONCAPA::map::order, $newidx);
13512: my ($outtext,$errtext)=
13513: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13514: $docuname.'/'.$folders{$outer}.
13515: '.'.$containers{$outer},1,1);
13516: unless ($errtext) {
13517: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13518: $result .= '<li>'.&mt('File: [_1] added to course',
13519: &HTML::Entities::encode($docstitle,'<>&"')).
13520: '</li>'."\n";
13521: }
1.1067 raeburn 13522: }
1.1294 raeburn 13523: } else {
13524: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13525: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 13526: }
1.1055 raeburn 13527: }
13528: }
1.1086 raeburn 13529: }
13530: } else {
1.1294 raeburn 13531: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13532: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 13533: }
13534: }
13535: for (my $i=1; $i<=$numitems; $i++) {
13536: next unless ($env{'form.archive_'.$i} eq 'dependency');
13537: my $path = $env{'form.archive_content_'.$i};
13538: if ($path =~ /^\Q$pathtocheck\E/) {
13539: my ($title) = ($path =~ m{/([^/]+)$});
13540: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13541: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13542: if (ref($dirorder{$i}) eq 'ARRAY') {
13543: my ($itemidx,$fullpath,$relpath);
13544: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13545: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13546: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13547: if ($dirorder{$i}->[$j] eq $container) {
13548: $itemidx = $j;
1.1056 raeburn 13549: }
13550: }
1.1086 raeburn 13551: }
13552: if ($itemidx eq '') {
13553: $itemidx = 0;
13554: }
13555: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13556: if ($mapinner{$referrer{$i}}) {
13557: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13558: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13559: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13560: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13561: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13562: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13563: if (!-e $fullpath) {
13564: mkdir($fullpath,0755);
1.1056 raeburn 13565: }
13566: }
1.1086 raeburn 13567: } else {
13568: last;
1.1056 raeburn 13569: }
1.1086 raeburn 13570: }
13571: }
13572: } elsif ($newdest{$referrer{$i}}) {
13573: $fullpath = $newdest{$referrer{$i}};
13574: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13575: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13576: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13577: last;
13578: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13579: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13580: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13581: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13582: if (!-e $fullpath) {
13583: mkdir($fullpath,0755);
1.1056 raeburn 13584: }
13585: }
1.1086 raeburn 13586: } else {
13587: last;
1.1056 raeburn 13588: }
1.1055 raeburn 13589: }
13590: }
1.1086 raeburn 13591: if ($fullpath ne '') {
13592: if (-e "$prefix$path") {
1.1292 raeburn 13593: unless (rename("$prefix$path","$fullpath/$title")) {
13594: $warning .= &mt('Failed to rename dependency').'<br />';
13595: }
1.1086 raeburn 13596: }
13597: if (-e "$fullpath/$title") {
13598: my $showpath;
13599: if ($relpath ne '') {
13600: $showpath = "$relpath/$title";
13601: } else {
13602: $showpath = "/$title";
13603: }
1.1294 raeburn 13604: $result .= '<li>'.&mt('[_1] included as a dependency',
13605: &HTML::Entities::encode($showpath,'<>&"')).
13606: '</li>'."\n";
1.1292 raeburn 13607: unless ($ishome) {
13608: my $fetch = "$fullpath/$title";
13609: $fetch =~ s/^\Q$prefix$dir\E//;
13610: $prompttofetch{$fetch} = 1;
13611: }
1.1086 raeburn 13612: }
13613: }
1.1055 raeburn 13614: }
1.1086 raeburn 13615: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13616: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 13617: &HTML::Entities::encode($path,'<>&"'),
13618: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13619: '<br />';
1.1055 raeburn 13620: }
13621: } else {
1.1294 raeburn 13622: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 13623: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13624: }
13625: }
13626: if (keys(%todelete)) {
13627: foreach my $key (keys(%todelete)) {
13628: unlink($key);
1.1066 raeburn 13629: }
13630: }
13631: if (keys(%todeletedir)) {
13632: foreach my $key (keys(%todeletedir)) {
13633: rmdir($key);
13634: }
13635: }
13636: foreach my $dir (sort(keys(%is_dir))) {
13637: if (($pathtocheck ne '') && ($dir ne '')) {
13638: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13639: }
13640: }
1.1067 raeburn 13641: if ($result ne '') {
13642: $output .= '<ul>'."\n".
13643: $result."\n".
13644: '</ul>';
13645: }
13646: unless ($ishome) {
13647: my $replicationfail;
13648: foreach my $item (keys(%prompttofetch)) {
13649: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13650: unless ($fetchresult eq 'ok') {
13651: $replicationfail .= '<li>'.$item.'</li>'."\n";
13652: }
13653: }
13654: if ($replicationfail) {
13655: $output .= '<p class="LC_error">'.
13656: &mt('Course home server failed to retrieve:').'<ul>'.
13657: $replicationfail.
13658: '</ul></p>';
13659: }
13660: }
1.1055 raeburn 13661: } else {
13662: $warning = &mt('No items found in archive.');
13663: }
13664: if ($error) {
13665: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13666: $error.'</p>'."\n";
13667: }
13668: if ($warning) {
13669: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13670: }
13671: return $output;
13672: }
13673:
1.1066 raeburn 13674: sub cleanup_empty_dirs {
13675: my ($path) = @_;
13676: if (($path ne '') && (-d $path)) {
13677: if (opendir(my $dirh,$path)) {
13678: my @dircontents = grep(!/^\./,readdir($dirh));
13679: my $numitems = 0;
13680: foreach my $item (@dircontents) {
13681: if (-d "$path/$item") {
1.1111 raeburn 13682: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13683: if (-e "$path/$item") {
13684: $numitems ++;
13685: }
13686: } else {
13687: $numitems ++;
13688: }
13689: }
13690: if ($numitems == 0) {
13691: rmdir($path);
13692: }
13693: closedir($dirh);
13694: }
13695: }
13696: return;
13697: }
13698:
1.41 ng 13699: =pod
1.45 matthew 13700:
1.1162 raeburn 13701: =item * &get_folder_hierarchy()
1.1068 raeburn 13702:
13703: Provides hierarchy of names of folders/sub-folders containing the current
13704: item,
13705:
13706: Inputs: 3
13707: - $navmap - navmaps object
13708:
13709: - $map - url for map (either the trigger itself, or map containing
13710: the resource, which is the trigger).
13711:
13712: - $showitem - 1 => show title for map itself; 0 => do not show.
13713:
13714: Outputs: 1 @pathitems - array of folder/subfolder names.
13715:
13716: =cut
13717:
13718: sub get_folder_hierarchy {
13719: my ($navmap,$map,$showitem) = @_;
13720: my @pathitems;
13721: if (ref($navmap)) {
13722: my $mapres = $navmap->getResourceByUrl($map);
13723: if (ref($mapres)) {
13724: my $pcslist = $mapres->map_hierarchy();
13725: if ($pcslist ne '') {
13726: my @pcs = split(/,/,$pcslist);
13727: foreach my $pc (@pcs) {
13728: if ($pc == 1) {
1.1129 raeburn 13729: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13730: } else {
13731: my $res = $navmap->getByMapPc($pc);
13732: if (ref($res)) {
13733: my $title = $res->compTitle();
13734: $title =~ s/\W+/_/g;
13735: if ($title ne '') {
13736: push(@pathitems,$title);
13737: }
13738: }
13739: }
13740: }
13741: }
1.1071 raeburn 13742: if ($showitem) {
13743: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13744: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13745: } else {
13746: my $maptitle = $mapres->compTitle();
13747: $maptitle =~ s/\W+/_/g;
13748: if ($maptitle ne '') {
13749: push(@pathitems,$maptitle);
13750: }
1.1068 raeburn 13751: }
13752: }
13753: }
13754: }
13755: return @pathitems;
13756: }
13757:
13758: =pod
13759:
1.1015 raeburn 13760: =item * &get_turnedin_filepath()
13761:
13762: Determines path in a user's portfolio file for storage of files uploaded
13763: to a specific essayresponse or dropbox item.
13764:
13765: Inputs: 3 required + 1 optional.
13766: $symb is symb for resource, $uname and $udom are for current user (required).
13767: $caller is optional (can be "submission", if routine is called when storing
13768: an upoaded file when "Submit Answer" button was pressed).
13769:
13770: Returns array containing $path and $multiresp.
13771: $path is path in portfolio. $multiresp is 1 if this resource contains more
13772: than one file upload item. Callers of routine should append partid as a
13773: subdirectory to $path in cases where $multiresp is 1.
13774:
13775: Called by: homework/essayresponse.pm and homework/structuretags.pm
13776:
13777: =cut
13778:
13779: sub get_turnedin_filepath {
13780: my ($symb,$uname,$udom,$caller) = @_;
13781: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13782: my $turnindir;
13783: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13784: $turnindir = $userhash{'turnindir'};
13785: my ($path,$multiresp);
13786: if ($turnindir eq '') {
13787: if ($caller eq 'submission') {
13788: $turnindir = &mt('turned in');
13789: $turnindir =~ s/\W+/_/g;
13790: my %newhash = (
13791: 'turnindir' => $turnindir,
13792: );
13793: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13794: }
13795: }
13796: if ($turnindir ne '') {
13797: $path = '/'.$turnindir.'/';
13798: my ($multipart,$turnin,@pathitems);
13799: my $navmap = Apache::lonnavmaps::navmap->new();
13800: if (defined($navmap)) {
13801: my $mapres = $navmap->getResourceByUrl($map);
13802: if (ref($mapres)) {
13803: my $pcslist = $mapres->map_hierarchy();
13804: if ($pcslist ne '') {
13805: foreach my $pc (split(/,/,$pcslist)) {
13806: my $res = $navmap->getByMapPc($pc);
13807: if (ref($res)) {
13808: my $title = $res->compTitle();
13809: $title =~ s/\W+/_/g;
13810: if ($title ne '') {
1.1149 raeburn 13811: if (($pc > 1) && (length($title) > 12)) {
13812: $title = substr($title,0,12);
13813: }
1.1015 raeburn 13814: push(@pathitems,$title);
13815: }
13816: }
13817: }
13818: }
13819: my $maptitle = $mapres->compTitle();
13820: $maptitle =~ s/\W+/_/g;
13821: if ($maptitle ne '') {
1.1149 raeburn 13822: if (length($maptitle) > 12) {
13823: $maptitle = substr($maptitle,0,12);
13824: }
1.1015 raeburn 13825: push(@pathitems,$maptitle);
13826: }
13827: unless ($env{'request.state'} eq 'construct') {
13828: my $res = $navmap->getBySymb($symb);
13829: if (ref($res)) {
13830: my $partlist = $res->parts();
13831: my $totaluploads = 0;
13832: if (ref($partlist) eq 'ARRAY') {
13833: foreach my $part (@{$partlist}) {
13834: my @types = $res->responseType($part);
13835: my @ids = $res->responseIds($part);
13836: for (my $i=0; $i < scalar(@ids); $i++) {
13837: if ($types[$i] eq 'essay') {
13838: my $partid = $part.'_'.$ids[$i];
13839: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13840: $totaluploads ++;
13841: }
13842: }
13843: }
13844: }
13845: if ($totaluploads > 1) {
13846: $multiresp = 1;
13847: }
13848: }
13849: }
13850: }
13851: } else {
13852: return;
13853: }
13854: } else {
13855: return;
13856: }
13857: my $restitle=&Apache::lonnet::gettitle($symb);
13858: $restitle =~ s/\W+/_/g;
13859: if ($restitle eq '') {
13860: $restitle = ($resurl =~ m{/[^/]+$});
13861: if ($restitle eq '') {
13862: $restitle = time;
13863: }
13864: }
1.1149 raeburn 13865: if (length($restitle) > 12) {
13866: $restitle = substr($restitle,0,12);
13867: }
1.1015 raeburn 13868: push(@pathitems,$restitle);
13869: $path .= join('/',@pathitems);
13870: }
13871: return ($path,$multiresp);
13872: }
13873:
13874: =pod
13875:
1.464 albertel 13876: =back
1.41 ng 13877:
1.112 bowersj2 13878: =head1 CSV Upload/Handling functions
1.38 albertel 13879:
1.41 ng 13880: =over 4
13881:
1.648 raeburn 13882: =item * &upfile_store($r)
1.41 ng 13883:
13884: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13885: needs $env{'form.upfile'}
1.41 ng 13886: returns $datatoken to be put into hidden field
13887:
13888: =cut
1.31 albertel 13889:
13890: sub upfile_store {
13891: my $r=shift;
1.258 albertel 13892: $env{'form.upfile'}=~s/\r/\n/gs;
13893: $env{'form.upfile'}=~s/\f/\n/gs;
13894: $env{'form.upfile'}=~s/\n+/\n/gs;
13895: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13896:
1.1299 raeburn 13897: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13898: '_enroll_'.$env{'request.course.id'}.'_'.
13899: time.'_'.$$);
13900: return if ($datatoken eq '');
13901:
1.31 albertel 13902: {
1.158 raeburn 13903: my $datafile = $r->dir_config('lonDaemons').
13904: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 13905: if ( open(my $fh,'>',$datafile) ) {
1.258 albertel 13906: print $fh $env{'form.upfile'};
1.158 raeburn 13907: close($fh);
13908: }
1.31 albertel 13909: }
13910: return $datatoken;
13911: }
13912:
1.56 matthew 13913: =pod
13914:
1.1290 raeburn 13915: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13916:
13917: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 13918: $datatoken is the name to assign to the temporary file.
1.258 albertel 13919: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13920:
13921: =cut
1.31 albertel 13922:
13923: sub load_tmp_file {
1.1290 raeburn 13924: my ($r,$datatoken) = @_;
13925: return if ($datatoken eq '');
1.31 albertel 13926: my @studentdata=();
13927: {
1.158 raeburn 13928: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 13929: '/tmp/'.$datatoken.'.tmp';
1.1317 raeburn 13930: if ( open(my $fh,'<',$studentfile) ) {
1.158 raeburn 13931: @studentdata=<$fh>;
13932: close($fh);
13933: }
1.31 albertel 13934: }
1.258 albertel 13935: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13936: }
13937:
1.1290 raeburn 13938: sub valid_datatoken {
13939: my ($datatoken) = @_;
1.1291 raeburn 13940: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_$match_domain\_$match_courseid\_\d+_\d+$/) {
1.1290 raeburn 13941: return $datatoken;
13942: }
13943: return;
13944: }
13945:
1.56 matthew 13946: =pod
13947:
1.648 raeburn 13948: =item * &upfile_record_sep()
1.41 ng 13949:
13950: Separate uploaded file into records
13951: returns array of records,
1.258 albertel 13952: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13953:
13954: =cut
1.31 albertel 13955:
13956: sub upfile_record_sep {
1.258 albertel 13957: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13958: } else {
1.248 albertel 13959: my @records;
1.258 albertel 13960: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13961: if ($line=~/^\s*$/) { next; }
13962: push(@records,$line);
13963: }
13964: return @records;
1.31 albertel 13965: }
13966: }
13967:
1.56 matthew 13968: =pod
13969:
1.648 raeburn 13970: =item * &record_sep($record)
1.41 ng 13971:
1.258 albertel 13972: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13973:
13974: =cut
13975:
1.263 www 13976: sub takeleft {
13977: my $index=shift;
13978: return substr('0000'.$index,-4,4);
13979: }
13980:
1.31 albertel 13981: sub record_sep {
13982: my $record=shift;
13983: my %components=();
1.258 albertel 13984: if ($env{'form.upfiletype'} eq 'xml') {
13985: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13986: my $i=0;
1.356 albertel 13987: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13988: $field=~s/^(\"|\')//;
13989: $field=~s/(\"|\')$//;
1.263 www 13990: $components{&takeleft($i)}=$field;
1.31 albertel 13991: $i++;
13992: }
1.258 albertel 13993: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13994: my $i=0;
1.356 albertel 13995: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13996: $field=~s/^(\"|\')//;
13997: $field=~s/(\"|\')$//;
1.263 www 13998: $components{&takeleft($i)}=$field;
1.31 albertel 13999: $i++;
14000: }
14001: } else {
1.561 www 14002: my $separator=',';
1.480 banghart 14003: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 14004: $separator=';';
1.480 banghart 14005: }
1.31 albertel 14006: my $i=0;
1.561 www 14007: # the character we are looking for to indicate the end of a quote or a record
14008: my $looking_for=$separator;
14009: # do not add the characters to the fields
14010: my $ignore=0;
14011: # we just encountered a separator (or the beginning of the record)
14012: my $just_found_separator=1;
14013: # store the field we are working on here
14014: my $field='';
14015: # work our way through all characters in record
14016: foreach my $character ($record=~/(.)/g) {
14017: if ($character eq $looking_for) {
14018: if ($character ne $separator) {
14019: # Found the end of a quote, again looking for separator
14020: $looking_for=$separator;
14021: $ignore=1;
14022: } else {
14023: # Found a separator, store away what we got
14024: $components{&takeleft($i)}=$field;
14025: $i++;
14026: $just_found_separator=1;
14027: $ignore=0;
14028: $field='';
14029: }
14030: next;
14031: }
14032: # single or double quotation marks after a separator indicate beginning of a quote
14033: # we are now looking for the end of the quote and need to ignore separators
14034: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
14035: $looking_for=$character;
14036: next;
14037: }
14038: # ignore would be true after we reached the end of a quote
14039: if ($ignore) { next; }
14040: if (($just_found_separator) && ($character=~/\s/)) { next; }
14041: $field.=$character;
14042: $just_found_separator=0;
1.31 albertel 14043: }
1.561 www 14044: # catch the very last entry, since we never encountered the separator
14045: $components{&takeleft($i)}=$field;
1.31 albertel 14046: }
14047: return %components;
14048: }
14049:
1.144 matthew 14050: ######################################################
14051: ######################################################
14052:
1.56 matthew 14053: =pod
14054:
1.648 raeburn 14055: =item * &upfile_select_html()
1.41 ng 14056:
1.144 matthew 14057: Return HTML code to select a file from the users machine and specify
14058: the file type.
1.41 ng 14059:
14060: =cut
14061:
1.144 matthew 14062: ######################################################
14063: ######################################################
1.31 albertel 14064: sub upfile_select_html {
1.144 matthew 14065: my %Types = (
14066: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 14067: semisv => &mt('Semicolon separated values'),
1.144 matthew 14068: space => &mt('Space separated'),
14069: tab => &mt('Tabulator separated'),
14070: # xml => &mt('HTML/XML'),
14071: );
14072: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14073: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14074: foreach my $type (sort(keys(%Types))) {
14075: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14076: }
14077: $Str .= "</select>\n";
14078: return $Str;
1.31 albertel 14079: }
14080:
1.301 albertel 14081: sub get_samples {
14082: my ($records,$toget) = @_;
14083: my @samples=({});
14084: my $got=0;
14085: foreach my $rec (@$records) {
14086: my %temp = &record_sep($rec);
14087: if (! grep(/\S/, values(%temp))) { next; }
14088: if (%temp) {
14089: $samples[$got]=\%temp;
14090: $got++;
14091: if ($got == $toget) { last; }
14092: }
14093: }
14094: return \@samples;
14095: }
14096:
1.144 matthew 14097: ######################################################
14098: ######################################################
14099:
1.56 matthew 14100: =pod
14101:
1.648 raeburn 14102: =item * &csv_print_samples($r,$records)
1.41 ng 14103:
14104: Prints a table of sample values from each column uploaded $r is an
14105: Apache Request ref, $records is an arrayref from
14106: &Apache::loncommon::upfile_record_sep
14107:
14108: =cut
14109:
1.144 matthew 14110: ######################################################
14111: ######################################################
1.31 albertel 14112: sub csv_print_samples {
14113: my ($r,$records) = @_;
1.662 bisitz 14114: my $samples = &get_samples($records,5);
1.301 albertel 14115:
1.594 raeburn 14116: $r->print(&mt('Samples').'<br />'.&start_data_table().
14117: &start_data_table_header_row());
1.356 albertel 14118: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14119: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14120: $r->print(&end_data_table_header_row());
1.301 albertel 14121: foreach my $hash (@$samples) {
1.594 raeburn 14122: $r->print(&start_data_table_row());
1.356 albertel 14123: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14124: $r->print('<td>');
1.356 albertel 14125: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14126: $r->print('</td>');
14127: }
1.594 raeburn 14128: $r->print(&end_data_table_row());
1.31 albertel 14129: }
1.594 raeburn 14130: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14131: }
14132:
1.144 matthew 14133: ######################################################
14134: ######################################################
14135:
1.56 matthew 14136: =pod
14137:
1.648 raeburn 14138: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14139:
14140: Prints a table to create associations between values and table columns.
1.144 matthew 14141:
1.41 ng 14142: $r is an Apache Request ref,
14143: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14144: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14145:
14146: =cut
14147:
1.144 matthew 14148: ######################################################
14149: ######################################################
1.31 albertel 14150: sub csv_print_select_table {
14151: my ($r,$records,$d) = @_;
1.301 albertel 14152: my $i=0;
14153: my $samples = &get_samples($records,1);
1.144 matthew 14154: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14155: &start_data_table().&start_data_table_header_row().
1.144 matthew 14156: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14157: '<th>'.&mt('Column').'</th>'.
14158: &end_data_table_header_row()."\n");
1.356 albertel 14159: foreach my $array_ref (@$d) {
14160: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14161: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14162:
1.875 bisitz 14163: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14164: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14165: $r->print('<option value="none"></option>');
1.356 albertel 14166: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14167: $r->print('<option value="'.$sample.'"'.
14168: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14169: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14170: }
1.594 raeburn 14171: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14172: $i++;
14173: }
1.594 raeburn 14174: $r->print(&end_data_table());
1.31 albertel 14175: $i--;
14176: return $i;
14177: }
1.56 matthew 14178:
1.144 matthew 14179: ######################################################
14180: ######################################################
14181:
1.56 matthew 14182: =pod
1.31 albertel 14183:
1.648 raeburn 14184: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14185:
14186: Prints a table of sample values from the upload and can make associate samples to internal names.
14187:
14188: $r is an Apache Request ref,
14189: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14190: $d is an array of 2 element arrays (internal name, displayed name)
14191:
14192: =cut
14193:
1.144 matthew 14194: ######################################################
14195: ######################################################
1.31 albertel 14196: sub csv_samples_select_table {
14197: my ($r,$records,$d) = @_;
14198: my $i=0;
1.144 matthew 14199: #
1.662 bisitz 14200: my $max_samples = 5;
14201: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14202: $r->print(&start_data_table().
14203: &start_data_table_header_row().'<th>'.
14204: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14205: &end_data_table_header_row());
1.301 albertel 14206:
14207: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14208: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14209: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14210: foreach my $option (@$d) {
14211: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14212: $r->print('<option value="'.$value.'"'.
1.253 albertel 14213: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14214: $display.'</option>');
1.31 albertel 14215: }
14216: $r->print('</select></td><td>');
1.662 bisitz 14217: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14218: if (defined($samples->[$line]{$key})) {
14219: $r->print($samples->[$line]{$key}."<br />\n");
14220: }
14221: }
1.594 raeburn 14222: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14223: $i++;
14224: }
1.594 raeburn 14225: $r->print(&end_data_table());
1.31 albertel 14226: $i--;
14227: return($i);
1.115 matthew 14228: }
14229:
1.144 matthew 14230: ######################################################
14231: ######################################################
14232:
1.115 matthew 14233: =pod
14234:
1.648 raeburn 14235: =item * &clean_excel_name($name)
1.115 matthew 14236:
14237: Returns a replacement for $name which does not contain any illegal characters.
14238:
14239: =cut
14240:
1.144 matthew 14241: ######################################################
14242: ######################################################
1.115 matthew 14243: sub clean_excel_name {
14244: my ($name) = @_;
14245: $name =~ s/[:\*\?\/\\]//g;
14246: if (length($name) > 31) {
14247: $name = substr($name,0,31);
14248: }
14249: return $name;
1.25 albertel 14250: }
1.84 albertel 14251:
1.85 albertel 14252: =pod
14253:
1.648 raeburn 14254: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14255:
14256: Returns either 1 or undef
14257:
14258: 1 if the part is to be hidden, undef if it is to be shown
14259:
14260: Arguments are:
14261:
14262: $id the id of the part to be checked
14263: $symb, optional the symb of the resource to check
14264: $udom, optional the domain of the user to check for
14265: $uname, optional the username of the user to check for
14266:
14267: =cut
1.84 albertel 14268:
14269: sub check_if_partid_hidden {
14270: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14271: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14272: $symb,$udom,$uname);
1.141 albertel 14273: my $truth=1;
14274: #if the string starts with !, then the list is the list to show not hide
14275: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14276: my @hiddenlist=split(/,/,$hiddenparts);
14277: foreach my $checkid (@hiddenlist) {
1.141 albertel 14278: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14279: }
1.141 albertel 14280: return !$truth;
1.84 albertel 14281: }
1.127 matthew 14282:
1.138 matthew 14283:
14284: ############################################################
14285: ############################################################
14286:
14287: =pod
14288:
1.157 matthew 14289: =back
14290:
1.138 matthew 14291: =head1 cgi-bin script and graphing routines
14292:
1.157 matthew 14293: =over 4
14294:
1.648 raeburn 14295: =item * &get_cgi_id()
1.138 matthew 14296:
14297: Inputs: none
14298:
14299: Returns an id which can be used to pass environment variables
14300: to various cgi-bin scripts. These environment variables will
14301: be removed from the users environment after a given time by
14302: the routine &Apache::lonnet::transfer_profile_to_env.
14303:
14304: =cut
14305:
14306: ############################################################
14307: ############################################################
1.152 albertel 14308: my $uniq=0;
1.136 matthew 14309: sub get_cgi_id {
1.154 albertel 14310: $uniq=($uniq+1)%100000;
1.280 albertel 14311: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14312: }
14313:
1.127 matthew 14314: ############################################################
14315: ############################################################
14316:
14317: =pod
14318:
1.648 raeburn 14319: =item * &DrawBarGraph()
1.127 matthew 14320:
1.138 matthew 14321: Facilitates the plotting of data in a (stacked) bar graph.
14322: Puts plot definition data into the users environment in order for
14323: graph.png to plot it. Returns an <img> tag for the plot.
14324: The bars on the plot are labeled '1','2',...,'n'.
14325:
14326: Inputs:
14327:
14328: =over 4
14329:
14330: =item $Title: string, the title of the plot
14331:
14332: =item $xlabel: string, text describing the X-axis of the plot
14333:
14334: =item $ylabel: string, text describing the Y-axis of the plot
14335:
14336: =item $Max: scalar, the maximum Y value to use in the plot
14337: If $Max is < any data point, the graph will not be rendered.
14338:
1.140 matthew 14339: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14340: they are plotted. If undefined, default values will be used.
14341:
1.178 matthew 14342: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14343:
1.138 matthew 14344: =item @Values: An array of array references. Each array reference holds data
14345: to be plotted in a stacked bar chart.
14346:
1.239 matthew 14347: =item If the final element of @Values is a hash reference the key/value
14348: pairs will be added to the graph definition.
14349:
1.138 matthew 14350: =back
14351:
14352: Returns:
14353:
14354: An <img> tag which references graph.png and the appropriate identifying
14355: information for the plot.
14356:
1.127 matthew 14357: =cut
14358:
14359: ############################################################
14360: ############################################################
1.134 matthew 14361: sub DrawBarGraph {
1.178 matthew 14362: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14363: #
14364: if (! defined($colors)) {
14365: $colors = ['#33ff00',
14366: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14367: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14368: ];
14369: }
1.228 matthew 14370: my $extra_settings = {};
14371: if (ref($Values[-1]) eq 'HASH') {
14372: $extra_settings = pop(@Values);
14373: }
1.127 matthew 14374: #
1.136 matthew 14375: my $identifier = &get_cgi_id();
14376: my $id = 'cgi.'.$identifier;
1.129 matthew 14377: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14378: return '';
14379: }
1.225 matthew 14380: #
14381: my @Labels;
14382: if (defined($labels)) {
14383: @Labels = @$labels;
14384: } else {
14385: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14386: push(@Labels,$i+1);
1.225 matthew 14387: }
14388: }
14389: #
1.129 matthew 14390: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14391: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14392: my %ValuesHash;
14393: my $NumSets=1;
14394: foreach my $array (@Values) {
14395: next if (! ref($array));
1.136 matthew 14396: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14397: join(',',@$array);
1.129 matthew 14398: }
1.127 matthew 14399: #
1.136 matthew 14400: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14401: if ($NumBars < 3) {
14402: $width = 120+$NumBars*32;
1.220 matthew 14403: $xskip = 1;
1.225 matthew 14404: $bar_width = 30;
14405: } elsif ($NumBars < 5) {
14406: $width = 120+$NumBars*20;
14407: $xskip = 1;
14408: $bar_width = 20;
1.220 matthew 14409: } elsif ($NumBars < 10) {
1.136 matthew 14410: $width = 120+$NumBars*15;
14411: $xskip = 1;
14412: $bar_width = 15;
14413: } elsif ($NumBars <= 25) {
14414: $width = 120+$NumBars*11;
14415: $xskip = 5;
14416: $bar_width = 8;
14417: } elsif ($NumBars <= 50) {
14418: $width = 120+$NumBars*8;
14419: $xskip = 5;
14420: $bar_width = 4;
14421: } else {
14422: $width = 120+$NumBars*8;
14423: $xskip = 5;
14424: $bar_width = 4;
14425: }
14426: #
1.137 matthew 14427: $Max = 1 if ($Max < 1);
14428: if ( int($Max) < $Max ) {
14429: $Max++;
14430: $Max = int($Max);
14431: }
1.127 matthew 14432: $Title = '' if (! defined($Title));
14433: $xlabel = '' if (! defined($xlabel));
14434: $ylabel = '' if (! defined($ylabel));
1.369 www 14435: $ValuesHash{$id.'.title'} = &escape($Title);
14436: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14437: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14438: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14439: $ValuesHash{$id.'.NumBars'} = $NumBars;
14440: $ValuesHash{$id.'.NumSets'} = $NumSets;
14441: $ValuesHash{$id.'.PlotType'} = 'bar';
14442: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14443: $ValuesHash{$id.'.height'} = $height;
14444: $ValuesHash{$id.'.width'} = $width;
14445: $ValuesHash{$id.'.xskip'} = $xskip;
14446: $ValuesHash{$id.'.bar_width'} = $bar_width;
14447: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14448: #
1.228 matthew 14449: # Deal with other parameters
14450: while (my ($key,$value) = each(%$extra_settings)) {
14451: $ValuesHash{$id.'.'.$key} = $value;
14452: }
14453: #
1.646 raeburn 14454: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14455: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14456: }
14457:
14458: ############################################################
14459: ############################################################
14460:
14461: =pod
14462:
1.648 raeburn 14463: =item * &DrawXYGraph()
1.137 matthew 14464:
1.138 matthew 14465: Facilitates the plotting of data in an XY graph.
14466: Puts plot definition data into the users environment in order for
14467: graph.png to plot it. Returns an <img> tag for the plot.
14468:
14469: Inputs:
14470:
14471: =over 4
14472:
14473: =item $Title: string, the title of the plot
14474:
14475: =item $xlabel: string, text describing the X-axis of the plot
14476:
14477: =item $ylabel: string, text describing the Y-axis of the plot
14478:
14479: =item $Max: scalar, the maximum Y value to use in the plot
14480: If $Max is < any data point, the graph will not be rendered.
14481:
14482: =item $colors: Array ref containing the hex color codes for the data to be
14483: plotted in. If undefined, default values will be used.
14484:
14485: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14486:
14487: =item $Ydata: Array ref containing Array refs.
1.185 www 14488: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14489:
14490: =item %Values: hash indicating or overriding any default values which are
14491: passed to graph.png.
14492: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14493:
14494: =back
14495:
14496: Returns:
14497:
14498: An <img> tag which references graph.png and the appropriate identifying
14499: information for the plot.
14500:
1.137 matthew 14501: =cut
14502:
14503: ############################################################
14504: ############################################################
14505: sub DrawXYGraph {
14506: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14507: #
14508: # Create the identifier for the graph
14509: my $identifier = &get_cgi_id();
14510: my $id = 'cgi.'.$identifier;
14511: #
14512: $Title = '' if (! defined($Title));
14513: $xlabel = '' if (! defined($xlabel));
14514: $ylabel = '' if (! defined($ylabel));
14515: my %ValuesHash =
14516: (
1.369 www 14517: $id.'.title' => &escape($Title),
14518: $id.'.xlabel' => &escape($xlabel),
14519: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14520: $id.'.y_max_value'=> $Max,
14521: $id.'.labels' => join(',',@$Xlabels),
14522: $id.'.PlotType' => 'XY',
14523: );
14524: #
14525: if (defined($colors) && ref($colors) eq 'ARRAY') {
14526: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14527: }
14528: #
14529: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14530: return '';
14531: }
14532: my $NumSets=1;
1.138 matthew 14533: foreach my $array (@{$Ydata}){
1.137 matthew 14534: next if (! ref($array));
14535: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14536: }
1.138 matthew 14537: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14538: #
14539: # Deal with other parameters
14540: while (my ($key,$value) = each(%Values)) {
14541: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14542: }
14543: #
1.646 raeburn 14544: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14545: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14546: }
14547:
14548: ############################################################
14549: ############################################################
14550:
14551: =pod
14552:
1.648 raeburn 14553: =item * &DrawXYYGraph()
1.138 matthew 14554:
14555: Facilitates the plotting of data in an XY graph with two Y axes.
14556: Puts plot definition data into the users environment in order for
14557: graph.png to plot it. Returns an <img> tag for the plot.
14558:
14559: Inputs:
14560:
14561: =over 4
14562:
14563: =item $Title: string, the title of the plot
14564:
14565: =item $xlabel: string, text describing the X-axis of the plot
14566:
14567: =item $ylabel: string, text describing the Y-axis of the plot
14568:
14569: =item $colors: Array ref containing the hex color codes for the data to be
14570: plotted in. If undefined, default values will be used.
14571:
14572: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14573:
14574: =item $Ydata1: The first data set
14575:
14576: =item $Min1: The minimum value of the left Y-axis
14577:
14578: =item $Max1: The maximum value of the left Y-axis
14579:
14580: =item $Ydata2: The second data set
14581:
14582: =item $Min2: The minimum value of the right Y-axis
14583:
14584: =item $Max2: The maximum value of the left Y-axis
14585:
14586: =item %Values: hash indicating or overriding any default values which are
14587: passed to graph.png.
14588: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14589:
14590: =back
14591:
14592: Returns:
14593:
14594: An <img> tag which references graph.png and the appropriate identifying
14595: information for the plot.
1.136 matthew 14596:
14597: =cut
14598:
14599: ############################################################
14600: ############################################################
1.137 matthew 14601: sub DrawXYYGraph {
14602: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14603: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14604: #
14605: # Create the identifier for the graph
14606: my $identifier = &get_cgi_id();
14607: my $id = 'cgi.'.$identifier;
14608: #
14609: $Title = '' if (! defined($Title));
14610: $xlabel = '' if (! defined($xlabel));
14611: $ylabel = '' if (! defined($ylabel));
14612: my %ValuesHash =
14613: (
1.369 www 14614: $id.'.title' => &escape($Title),
14615: $id.'.xlabel' => &escape($xlabel),
14616: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14617: $id.'.labels' => join(',',@$Xlabels),
14618: $id.'.PlotType' => 'XY',
14619: $id.'.NumSets' => 2,
1.137 matthew 14620: $id.'.two_axes' => 1,
14621: $id.'.y1_max_value' => $Max1,
14622: $id.'.y1_min_value' => $Min1,
14623: $id.'.y2_max_value' => $Max2,
14624: $id.'.y2_min_value' => $Min2,
1.136 matthew 14625: );
14626: #
1.137 matthew 14627: if (defined($colors) && ref($colors) eq 'ARRAY') {
14628: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14629: }
14630: #
14631: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14632: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14633: return '';
14634: }
14635: my $NumSets=1;
1.137 matthew 14636: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14637: next if (! ref($array));
14638: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14639: }
14640: #
14641: # Deal with other parameters
14642: while (my ($key,$value) = each(%Values)) {
14643: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14644: }
14645: #
1.646 raeburn 14646: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14647: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14648: }
14649:
14650: ############################################################
14651: ############################################################
14652:
14653: =pod
14654:
1.157 matthew 14655: =back
14656:
1.139 matthew 14657: =head1 Statistics helper routines?
14658:
14659: Bad place for them but what the hell.
14660:
1.157 matthew 14661: =over 4
14662:
1.648 raeburn 14663: =item * &chartlink()
1.139 matthew 14664:
14665: Returns a link to the chart for a specific student.
14666:
14667: Inputs:
14668:
14669: =over 4
14670:
14671: =item $linktext: The text of the link
14672:
14673: =item $sname: The students username
14674:
14675: =item $sdomain: The students domain
14676:
14677: =back
14678:
1.157 matthew 14679: =back
14680:
1.139 matthew 14681: =cut
14682:
14683: ############################################################
14684: ############################################################
14685: sub chartlink {
14686: my ($linktext, $sname, $sdomain) = @_;
14687: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14688: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14689: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14690: '">'.$linktext.'</a>';
1.153 matthew 14691: }
14692:
14693: #######################################################
14694: #######################################################
14695:
14696: =pod
14697:
14698: =head1 Course Environment Routines
1.157 matthew 14699:
14700: =over 4
1.153 matthew 14701:
1.648 raeburn 14702: =item * &restore_course_settings()
1.153 matthew 14703:
1.648 raeburn 14704: =item * &store_course_settings()
1.153 matthew 14705:
14706: Restores/Store indicated form parameters from the course environment.
14707: Will not overwrite existing values of the form parameters.
14708:
14709: Inputs:
14710: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14711:
14712: a hash ref describing the data to be stored. For example:
14713:
14714: %Save_Parameters = ('Status' => 'scalar',
14715: 'chartoutputmode' => 'scalar',
14716: 'chartoutputdata' => 'scalar',
14717: 'Section' => 'array',
1.373 raeburn 14718: 'Group' => 'array',
1.153 matthew 14719: 'StudentData' => 'array',
14720: 'Maps' => 'array');
14721:
14722: Returns: both routines return nothing
14723:
1.631 raeburn 14724: =back
14725:
1.153 matthew 14726: =cut
14727:
14728: #######################################################
14729: #######################################################
14730: sub store_course_settings {
1.496 albertel 14731: return &store_settings($env{'request.course.id'},@_);
14732: }
14733:
14734: sub store_settings {
1.153 matthew 14735: # save to the environment
14736: # appenv the same items, just to be safe
1.300 albertel 14737: my $udom = $env{'user.domain'};
14738: my $uname = $env{'user.name'};
1.496 albertel 14739: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14740: my %SaveHash;
14741: my %AppHash;
14742: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14743: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14744: my $envname = 'environment.'.$basename;
1.258 albertel 14745: if (exists($env{'form.'.$setting})) {
1.153 matthew 14746: # Save this value away
14747: if ($type eq 'scalar' &&
1.258 albertel 14748: (! exists($env{$envname}) ||
14749: $env{$envname} ne $env{'form.'.$setting})) {
14750: $SaveHash{$basename} = $env{'form.'.$setting};
14751: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14752: } elsif ($type eq 'array') {
14753: my $stored_form;
1.258 albertel 14754: if (ref($env{'form.'.$setting})) {
1.153 matthew 14755: $stored_form = join(',',
14756: map {
1.369 www 14757: &escape($_);
1.258 albertel 14758: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14759: } else {
14760: $stored_form =
1.369 www 14761: &escape($env{'form.'.$setting});
1.153 matthew 14762: }
14763: # Determine if the array contents are the same.
1.258 albertel 14764: if ($stored_form ne $env{$envname}) {
1.153 matthew 14765: $SaveHash{$basename} = $stored_form;
14766: $AppHash{$envname} = $stored_form;
14767: }
14768: }
14769: }
14770: }
14771: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14772: $udom,$uname);
1.153 matthew 14773: if ($put_result !~ /^(ok|delayed)/) {
14774: &Apache::lonnet::logthis('unable to save form parameters, '.
14775: 'got error:'.$put_result);
14776: }
14777: # Make sure these settings stick around in this session, too
1.646 raeburn 14778: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14779: return;
14780: }
14781:
14782: sub restore_course_settings {
1.499 albertel 14783: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14784: }
14785:
14786: sub restore_settings {
14787: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14788: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14789: next if (exists($env{'form.'.$setting}));
1.496 albertel 14790: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14791: '.'.$setting;
1.258 albertel 14792: if (exists($env{$envname})) {
1.153 matthew 14793: if ($type eq 'scalar') {
1.258 albertel 14794: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14795: } elsif ($type eq 'array') {
1.258 albertel 14796: $env{'form.'.$setting} = [
1.153 matthew 14797: map {
1.369 www 14798: &unescape($_);
1.258 albertel 14799: } split(',',$env{$envname})
1.153 matthew 14800: ];
14801: }
14802: }
14803: }
1.127 matthew 14804: }
14805:
1.618 raeburn 14806: #######################################################
14807: #######################################################
14808:
14809: =pod
14810:
14811: =head1 Domain E-mail Routines
14812:
14813: =over 4
14814:
1.648 raeburn 14815: =item * &build_recipient_list()
1.618 raeburn 14816:
1.1144 raeburn 14817: Build recipient lists for following types of e-mail:
1.766 raeburn 14818: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14819: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14820: module change checking, student/employee ID conflict checks, as
14821: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14822: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14823:
14824: Inputs:
1.619 raeburn 14825: defmail (scalar - email address of default recipient),
1.1144 raeburn 14826: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14827: requestsmail, updatesmail, or idconflictsmail).
14828:
1.619 raeburn 14829: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14830:
1.619 raeburn 14831: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 14832: i.e., predates configuration by DC via domainprefs.pm
14833:
14834: $requname username of requester (if mailing type is helpdeskmail)
14835:
14836: $requdom domain of requester (if mailing type is helpdeskmail)
14837:
14838: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14839:
1.618 raeburn 14840:
1.655 raeburn 14841: Returns: comma separated list of addresses to which to send e-mail.
14842:
14843: =back
1.618 raeburn 14844:
14845: =cut
14846:
14847: ############################################################
14848: ############################################################
14849: sub build_recipient_list {
1.1297 raeburn 14850: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14851: my @recipients;
1.1270 raeburn 14852: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14853: my %domconfig =
1.1270 raeburn 14854: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14855: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14856: if (exists($domconfig{'contacts'}{$mailing})) {
14857: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14858: my @contacts = ('adminemail','supportemail');
14859: foreach my $item (@contacts) {
14860: if ($domconfig{'contacts'}{$mailing}{$item}) {
14861: my $addr = $domconfig{'contacts'}{$item};
14862: if (!grep(/^\Q$addr\E$/,@recipients)) {
14863: push(@recipients,$addr);
14864: }
1.619 raeburn 14865: }
1.1270 raeburn 14866: }
14867: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14868: if ($mailing eq 'helpdeskmail') {
14869: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14870: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14871: my @ok_bccs;
14872: foreach my $bcc (@bccs) {
14873: $bcc =~ s/^\s+//g;
14874: $bcc =~ s/\s+$//g;
14875: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14876: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14877: push(@ok_bccs,$bcc);
14878: }
14879: }
14880: }
14881: if (@ok_bccs > 0) {
14882: $allbcc = join(', ',@ok_bccs);
14883: }
14884: }
14885: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14886: }
14887: }
1.766 raeburn 14888: } elsif ($origmail ne '') {
1.1270 raeburn 14889: $lastresort = $origmail;
1.618 raeburn 14890: }
1.1297 raeburn 14891: if ($mailing eq 'helpdeskmail') {
14892: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14893: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14894: my ($inststatus,$inststatus_checked);
14895: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14896: ($env{'user.domain'} ne 'public')) {
14897: $inststatus_checked = 1;
14898: $inststatus = $env{'environment.inststatus'};
14899: }
14900: unless ($inststatus_checked) {
14901: if (($requname ne '') && ($requdom ne '')) {
14902: if (($requname =~ /^$match_username$/) &&
14903: ($requdom =~ /^$match_domain$/) &&
14904: (&Apache::lonnet::domain($requdom))) {
14905: my $requhome = &Apache::lonnet::homeserver($requname,
14906: $requdom);
14907: unless ($requhome eq 'no_host') {
14908: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14909: $inststatus = $userenv{'inststatus'};
14910: $inststatus_checked = 1;
14911: }
14912: }
14913: }
14914: }
14915: unless ($inststatus_checked) {
14916: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
14917: my %srch = (srchby => 'email',
14918: srchdomain => $defdom,
14919: srchterm => $reqemail,
14920: srchtype => 'exact');
14921: my %srch_results = &Apache::lonnet::usersearch(\%srch);
14922: foreach my $uname (keys(%srch_results)) {
14923: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14924: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14925: $inststatus_checked = 1;
14926: last;
14927: }
14928: }
14929: unless ($inststatus_checked) {
14930: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
14931: if ($dirsrchres eq 'ok') {
14932: foreach my $uname (keys(%srch_results)) {
14933: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14934: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14935: $inststatus_checked = 1;
14936: last;
14937: }
14938: }
14939: }
14940: }
14941: }
14942: }
14943: if ($inststatus ne '') {
14944: foreach my $status (split(/\:/,$inststatus)) {
14945: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
14946: my @contacts = ('adminemail','supportemail');
14947: foreach my $item (@contacts) {
14948: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
14949: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
14950: if (!grep(/^\Q$addr\E$/,@recipients)) {
14951: push(@recipients,$addr);
14952: }
14953: }
14954: }
14955: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
14956: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
14957: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
14958: my @ok_bccs;
14959: foreach my $bcc (@bccs) {
14960: $bcc =~ s/^\s+//g;
14961: $bcc =~ s/\s+$//g;
14962: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14963: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14964: push(@ok_bccs,$bcc);
14965: }
14966: }
14967: }
14968: if (@ok_bccs > 0) {
14969: $allbcc = join(', ',@ok_bccs);
14970: }
14971: }
14972: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
14973: last;
14974: }
14975: }
14976: }
14977: }
14978: }
1.619 raeburn 14979: } elsif ($origmail ne '') {
1.1270 raeburn 14980: $lastresort = $origmail;
14981: }
1.1297 raeburn 14982: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 14983: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14984: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14985: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14986: my %what = (
14987: perlvar => 1,
14988: );
14989: my $primary = &Apache::lonnet::domain($defdom,'primary');
14990: if ($primary) {
14991: my $gotaddr;
14992: my ($result,$returnhash) =
14993: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14994: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14995: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14996: $lastresort = $returnhash->{'lonSupportEMail'};
14997: $gotaddr = 1;
14998: }
14999: }
15000: unless ($gotaddr) {
15001: my $uintdom = &Apache::lonnet::internet_dom($primary);
15002: my $intdom = &Apache::lonnet::internet_dom($lonhost);
15003: unless ($uintdom eq $intdom) {
15004: my %domconfig =
15005: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
15006: if (ref($domconfig{'contacts'}) eq 'HASH') {
15007: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
15008: my @contacts = ('adminemail','supportemail');
15009: foreach my $item (@contacts) {
15010: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
15011: my $addr = $domconfig{'contacts'}{$item};
15012: if (!grep(/^\Q$addr\E$/,@recipients)) {
15013: push(@recipients,$addr);
15014: }
15015: }
15016: }
15017: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
15018: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
15019: }
15020: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
15021: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
15022: my @ok_bccs;
15023: foreach my $bcc (@bccs) {
15024: $bcc =~ s/^\s+//g;
15025: $bcc =~ s/\s+$//g;
15026: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
15027: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
15028: push(@ok_bccs,$bcc);
15029: }
15030: }
15031: }
15032: if (@ok_bccs > 0) {
15033: $allbcc = join(', ',@ok_bccs);
15034: }
15035: }
15036: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
15037: }
15038: }
15039: }
15040: }
15041: }
15042: }
1.618 raeburn 15043: }
1.688 raeburn 15044: if (defined($defmail)) {
15045: if ($defmail ne '') {
15046: push(@recipients,$defmail);
15047: }
1.618 raeburn 15048: }
15049: if ($otheremails) {
1.619 raeburn 15050: my @others;
15051: if ($otheremails =~ /,/) {
15052: @others = split(/,/,$otheremails);
1.618 raeburn 15053: } else {
1.619 raeburn 15054: push(@others,$otheremails);
15055: }
15056: foreach my $addr (@others) {
15057: if (!grep(/^\Q$addr\E$/,@recipients)) {
15058: push(@recipients,$addr);
15059: }
1.618 raeburn 15060: }
15061: }
1.1298 raeburn 15062: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 15063: if ((!@recipients) && ($lastresort ne '')) {
15064: push(@recipients,$lastresort);
15065: }
15066: } elsif ($lastresort ne '') {
15067: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
15068: push(@recipients,$lastresort);
15069: }
15070: }
1.1271 raeburn 15071: my $recipientlist = join(',',@recipients);
1.1270 raeburn 15072: if (wantarray) {
15073: return ($recipientlist,$allbcc,$addtext);
15074: } else {
15075: return $recipientlist;
15076: }
1.618 raeburn 15077: }
15078:
1.127 matthew 15079: ############################################################
15080: ############################################################
1.154 albertel 15081:
1.655 raeburn 15082: =pod
15083:
1.1224 musolffc 15084: =over 4
15085:
1.1223 musolffc 15086: =item * &mime_email()
15087:
15088: Sends an email with a possible attachment
15089:
15090: Inputs:
15091:
15092: =over 4
15093:
15094: from - Sender's email address
15095:
15096: to - Email address of recipient
15097:
15098: subject - Subject of email
15099:
15100: body - Body of email
15101:
15102: cc_string - Carbon copy email address
15103:
15104: bcc - Blind carbon copy email address
15105:
15106: type - File type of attachment
15107:
15108: attachment_path - Path of file to be attached
15109:
15110: file_name - Name of file to be attached
15111:
15112: attachment_text - The body of an attachment of type "TEXT"
15113:
15114: =back
15115:
15116: =back
15117:
15118: =cut
15119:
15120: ############################################################
15121: ############################################################
15122:
15123: sub mime_email {
15124: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
15125: $file_name, $attachment_text) = @_;
15126: my $msg = MIME::Lite->new(
15127: From => $from,
15128: To => $to,
15129: Subject => $subject,
15130: Type =>'TEXT',
15131: Data => $body,
15132: );
15133: if ($cc_string ne '') {
15134: $msg->add("Cc" => $cc_string);
15135: }
15136: if ($bcc ne '') {
15137: $msg->add("Bcc" => $bcc);
15138: }
15139: $msg->attr("content-type" => "text/plain");
15140: $msg->attr("content-type.charset" => "UTF-8");
15141: # Attach file if given
15142: if ($attachment_path) {
15143: unless ($file_name) {
15144: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
15145: }
15146: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
15147: $msg->attach(Type => $type,
15148: Path => $attachment_path,
15149: Filename => $file_name
15150: );
15151: # Otherwise attach text if given
15152: } elsif ($attachment_text) {
15153: $msg->attach(Type => 'TEXT',
15154: Data => $attachment_text);
15155: }
15156: # Send it
15157: $msg->send('sendmail');
15158: }
15159:
15160: ############################################################
15161: ############################################################
15162:
15163: =pod
15164:
1.655 raeburn 15165: =head1 Course Catalog Routines
15166:
15167: =over 4
15168:
15169: =item * &gather_categories()
15170:
15171: Converts category definitions - keys of categories hash stored in
15172: coursecategories in configuration.db on the primary library server in a
15173: domain - to an array. Also generates javascript and idx hash used to
15174: generate Domain Coordinator interface for editing Course Categories.
15175:
15176: Inputs:
1.663 raeburn 15177:
1.655 raeburn 15178: categories (reference to hash of category definitions).
1.663 raeburn 15179:
1.655 raeburn 15180: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15181: categories and subcategories).
1.663 raeburn 15182:
1.655 raeburn 15183: idx (reference to hash of counters used in Domain Coordinator interface for
15184: editing Course Categories).
1.663 raeburn 15185:
1.655 raeburn 15186: jsarray (reference to array of categories used to create Javascript arrays for
15187: Domain Coordinator interface for editing Course Categories).
15188:
15189: Returns: nothing
15190:
15191: Side effects: populates cats, idx and jsarray.
15192:
15193: =cut
15194:
15195: sub gather_categories {
15196: my ($categories,$cats,$idx,$jsarray) = @_;
15197: my %counters;
15198: my $num = 0;
15199: foreach my $item (keys(%{$categories})) {
15200: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15201: if ($container eq '' && $depth == 0) {
15202: $cats->[$depth][$categories->{$item}] = $cat;
15203: } else {
15204: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15205: }
15206: my ($escitem,$tail) = split(/:/,$item,2);
15207: if ($counters{$tail} eq '') {
15208: $counters{$tail} = $num;
15209: $num ++;
15210: }
15211: if (ref($idx) eq 'HASH') {
15212: $idx->{$item} = $counters{$tail};
15213: }
15214: if (ref($jsarray) eq 'ARRAY') {
15215: push(@{$jsarray->[$counters{$tail}]},$item);
15216: }
15217: }
15218: return;
15219: }
15220:
15221: =pod
15222:
15223: =item * &extract_categories()
15224:
15225: Used to generate breadcrumb trails for course categories.
15226:
15227: Inputs:
1.663 raeburn 15228:
1.655 raeburn 15229: categories (reference to hash of category definitions).
1.663 raeburn 15230:
1.655 raeburn 15231: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15232: categories and subcategories).
1.663 raeburn 15233:
1.655 raeburn 15234: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15235:
1.655 raeburn 15236: allitems (reference to hash - key is category key
15237: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15238:
1.655 raeburn 15239: idx (reference to hash of counters used in Domain Coordinator interface for
15240: editing Course Categories).
1.663 raeburn 15241:
1.655 raeburn 15242: jsarray (reference to array of categories used to create Javascript arrays for
15243: Domain Coordinator interface for editing Course Categories).
15244:
1.665 raeburn 15245: subcats (reference to hash of arrays containing all subcategories within each
15246: category, -recursive)
15247:
1.1321 raeburn 15248: maxd (reference to hash used to hold max depth for all top-level categories).
15249:
1.655 raeburn 15250: Returns: nothing
15251:
15252: Side effects: populates trails and allitems hash references.
15253:
15254: =cut
15255:
15256: sub extract_categories {
1.1321 raeburn 15257: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats,$maxd) = @_;
1.655 raeburn 15258: if (ref($categories) eq 'HASH') {
15259: &gather_categories($categories,$cats,$idx,$jsarray);
15260: if (ref($cats->[0]) eq 'ARRAY') {
15261: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15262: my $name = $cats->[0][$i];
15263: my $item = &escape($name).'::0';
15264: my $trailstr;
15265: if ($name eq 'instcode') {
15266: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15267: } elsif ($name eq 'communities') {
15268: $trailstr = &mt('Communities');
1.1239 raeburn 15269: } elsif ($name eq 'placement') {
15270: $trailstr = &mt('Placement Tests');
1.655 raeburn 15271: } else {
15272: $trailstr = $name;
15273: }
15274: if ($allitems->{$item} eq '') {
15275: push(@{$trails},$trailstr);
15276: $allitems->{$item} = scalar(@{$trails})-1;
15277: }
15278: my @parents = ($name);
15279: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15280: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15281: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15282: if (ref($subcats) eq 'HASH') {
15283: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15284: }
1.1321 raeburn 15285: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats,$maxd);
1.665 raeburn 15286: }
15287: } else {
15288: if (ref($subcats) eq 'HASH') {
15289: $subcats->{$item} = [];
1.655 raeburn 15290: }
1.1321 raeburn 15291: if (ref($maxd) eq 'HASH') {
15292: $maxd->{$name} = 1;
15293: }
1.655 raeburn 15294: }
15295: }
15296: }
15297: }
15298: return;
15299: }
15300:
15301: =pod
15302:
1.1162 raeburn 15303: =item * &recurse_categories()
1.655 raeburn 15304:
15305: Recursively used to generate breadcrumb trails for course categories.
15306:
15307: Inputs:
1.663 raeburn 15308:
1.655 raeburn 15309: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15310: categories and subcategories).
1.663 raeburn 15311:
1.655 raeburn 15312: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15313:
15314: category (current course category, for which breadcrumb trail is being generated).
15315:
15316: trails (reference to array of breadcrumb trails for each category).
15317:
1.655 raeburn 15318: allitems (reference to hash - key is category key
15319: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15320:
1.655 raeburn 15321: parents (array containing containers directories for current category,
15322: back to top level).
15323:
15324: Returns: nothing
15325:
15326: Side effects: populates trails and allitems hash references
15327:
15328: =cut
15329:
15330: sub recurse_categories {
1.1321 raeburn 15331: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats,$maxd) = @_;
1.655 raeburn 15332: my $shallower = $depth - 1;
15333: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
15334: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
15335: my $name = $cats->[$depth]{$category}[$k];
15336: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15337: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15338: if ($allitems->{$item} eq '') {
15339: push(@{$trails},$trailstr);
15340: $allitems->{$item} = scalar(@{$trails})-1;
15341: }
15342: my $deeper = $depth+1;
15343: push(@{$parents},$category);
1.665 raeburn 15344: if (ref($subcats) eq 'HASH') {
15345: my $subcat = &escape($name).':'.$category.':'.$depth;
15346: for (my $j=@{$parents}; $j>=0; $j--) {
15347: my $higher;
15348: if ($j > 0) {
15349: $higher = &escape($parents->[$j]).':'.
15350: &escape($parents->[$j-1]).':'.$j;
15351: } else {
15352: $higher = &escape($parents->[$j]).'::'.$j;
15353: }
15354: push(@{$subcats->{$higher}},$subcat);
15355: }
15356: }
15357: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
1.1321 raeburn 15358: $subcats,$maxd);
1.655 raeburn 15359: pop(@{$parents});
15360: }
15361: } else {
15362: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
1.1321 raeburn 15363: my $trailstr = join(' » ',(@{$parents},$category));
1.655 raeburn 15364: if ($allitems->{$item} eq '') {
15365: push(@{$trails},$trailstr);
15366: $allitems->{$item} = scalar(@{$trails})-1;
15367: }
1.1321 raeburn 15368: if (ref($maxd) eq 'HASH') {
15369: if ($depth > $maxd->{$parents->[0]}) {
15370: $maxd->{$parents->[0]} = $depth;
15371: }
15372: }
1.655 raeburn 15373: }
15374: return;
15375: }
15376:
1.663 raeburn 15377: =pod
15378:
1.1162 raeburn 15379: =item * &assign_categories_table()
1.663 raeburn 15380:
15381: Create a datatable for display of hierarchical categories in a domain,
15382: with checkboxes to allow a course to be categorized.
15383:
15384: Inputs:
15385:
15386: cathash - reference to hash of categories defined for the domain (from
15387: configuration.db)
15388:
15389: currcat - scalar with an & separated list of categories assigned to a course.
15390:
1.919 raeburn 15391: type - scalar contains course type (Course or Community).
15392:
1.1260 raeburn 15393: disabled - scalar (optional) contains disabled="disabled" if input elements are
15394: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15395:
1.663 raeburn 15396: Returns: $output (markup to be displayed)
15397:
15398: =cut
15399:
15400: sub assign_categories_table {
1.1259 raeburn 15401: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15402: my $output;
15403: if (ref($cathash) eq 'HASH') {
1.1321 raeburn 15404: my (@cats,@trails,%allitems,%idx,@jsarray,%maxd,@path,$maxdepth);
15405: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray,\%maxd);
1.663 raeburn 15406: $maxdepth = scalar(@cats);
15407: if (@cats > 0) {
15408: my $itemcount = 0;
15409: if (ref($cats[0]) eq 'ARRAY') {
15410: my @currcategories;
15411: if ($currcat ne '') {
15412: @currcategories = split('&',$currcat);
15413: }
1.919 raeburn 15414: my $table;
1.663 raeburn 15415: for (my $i=0; $i<@{$cats[0]}; $i++) {
15416: my $parent = $cats[0][$i];
1.919 raeburn 15417: next if ($parent eq 'instcode');
15418: if ($type eq 'Community') {
15419: next unless ($parent eq 'communities');
1.1239 raeburn 15420: } elsif ($type eq 'Placement') {
15421: next unless ($parent eq 'placement');
1.919 raeburn 15422: } else {
1.1239 raeburn 15423: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15424: }
1.663 raeburn 15425: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15426: my $item = &escape($parent).'::0';
15427: my $checked = '';
15428: if (@currcategories > 0) {
15429: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15430: $checked = ' checked="checked"';
1.663 raeburn 15431: }
15432: }
1.919 raeburn 15433: my $parent_title = $parent;
15434: if ($parent eq 'communities') {
15435: $parent_title = &mt('Communities');
1.1239 raeburn 15436: } elsif ($parent eq 'placement') {
15437: $parent_title = &mt('Placement Tests');
1.919 raeburn 15438: }
15439: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15440: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15441: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15442: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15443: my $depth = 1;
15444: push(@path,$parent);
1.1259 raeburn 15445: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15446: pop(@path);
1.919 raeburn 15447: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15448: $itemcount ++;
15449: }
1.919 raeburn 15450: if ($itemcount) {
15451: $output = &Apache::loncommon::start_data_table().
15452: $table.
15453: &Apache::loncommon::end_data_table();
15454: }
1.663 raeburn 15455: }
15456: }
15457: }
15458: return $output;
15459: }
15460:
15461: =pod
15462:
1.1162 raeburn 15463: =item * &assign_category_rows()
1.663 raeburn 15464:
15465: Create a datatable row for display of nested categories in a domain,
15466: with checkboxes to allow a course to be categorized,called recursively.
15467:
15468: Inputs:
15469:
15470: itemcount - track row number for alternating colors
15471:
15472: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15473: categories and subcategories.
15474:
15475: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15476:
15477: parent - parent of current category item
15478:
15479: path - Array containing all categories back up through the hierarchy from the
15480: current category to the top level.
15481:
15482: currcategories - reference to array of current categories assigned to the course
15483:
1.1260 raeburn 15484: disabled - scalar (optional) contains disabled="disabled" if input elements are
15485: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15486:
1.663 raeburn 15487: Returns: $output (markup to be displayed).
15488:
15489: =cut
15490:
15491: sub assign_category_rows {
1.1259 raeburn 15492: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15493: my ($text,$name,$item,$chgstr);
15494: if (ref($cats) eq 'ARRAY') {
15495: my $maxdepth = scalar(@{$cats});
15496: if (ref($cats->[$depth]) eq 'HASH') {
15497: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15498: my $numchildren = @{$cats->[$depth]{$parent}};
15499: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 15500: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15501: for (my $j=0; $j<$numchildren; $j++) {
15502: $name = $cats->[$depth]{$parent}[$j];
15503: $item = &escape($name).':'.&escape($parent).':'.$depth;
15504: my $deeper = $depth+1;
15505: my $checked = '';
15506: if (ref($currcategories) eq 'ARRAY') {
15507: if (@{$currcategories} > 0) {
15508: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15509: $checked = ' checked="checked"';
1.663 raeburn 15510: }
15511: }
15512: }
1.664 raeburn 15513: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15514: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15515: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15516: '<input type="hidden" name="catname" value="'.$name.'" />'.
15517: '</td><td>';
1.663 raeburn 15518: if (ref($path) eq 'ARRAY') {
15519: push(@{$path},$name);
1.1259 raeburn 15520: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15521: pop(@{$path});
15522: }
15523: $text .= '</td></tr>';
15524: }
15525: $text .= '</table></td>';
15526: }
15527: }
15528: }
15529: return $text;
15530: }
15531:
1.1181 raeburn 15532: =pod
15533:
15534: =back
15535:
15536: =cut
15537:
1.655 raeburn 15538: ############################################################
15539: ############################################################
15540:
15541:
1.443 albertel 15542: sub commit_customrole {
1.664 raeburn 15543: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15544: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15545: ($start?', '.&mt('starting').' '.localtime($start):'').
15546: ($end?', ending '.localtime($end):'').': <b>'.
15547: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15548: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15549: '</b><br />';
15550: return $output;
15551: }
15552:
15553: sub commit_standardrole {
1.1116 raeburn 15554: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15555: my ($output,$logmsg,$linefeed);
15556: if ($context eq 'auto') {
15557: $linefeed = "\n";
15558: } else {
15559: $linefeed = "<br />\n";
15560: }
1.443 albertel 15561: if ($three eq 'st') {
1.541 raeburn 15562: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 15563: $one,$two,$sec,$context,$credits);
1.541 raeburn 15564: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15565: ($result eq 'unknown_course') || ($result eq 'refused')) {
15566: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15567: } else {
1.541 raeburn 15568: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15569: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15570: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15571: if ($context eq 'auto') {
15572: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15573: } else {
15574: $output .= '<b>'.$result.'</b>'.$linefeed.
15575: &mt('Add to classlist').': <b>ok</b>';
15576: }
15577: $output .= $linefeed;
1.443 albertel 15578: }
15579: } else {
15580: $output = &mt('Assigning').' '.$three.' in '.$url.
15581: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15582: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15583: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15584: if ($context eq 'auto') {
15585: $output .= $result.$linefeed;
15586: } else {
15587: $output .= '<b>'.$result.'</b>'.$linefeed;
15588: }
1.443 albertel 15589: }
15590: return $output;
15591: }
15592:
15593: sub commit_studentrole {
1.1116 raeburn 15594: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15595: $credits) = @_;
1.626 raeburn 15596: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15597: if ($context eq 'auto') {
15598: $linefeed = "\n";
15599: } else {
15600: $linefeed = '<br />'."\n";
15601: }
1.443 albertel 15602: if (defined($one) && defined($two)) {
15603: my $cid=$one.'_'.$two;
15604: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15605: my $secchange = 0;
15606: my $expire_role_result;
15607: my $modify_section_result;
1.628 raeburn 15608: if ($oldsec ne '-1') {
15609: if ($oldsec ne $sec) {
1.443 albertel 15610: $secchange = 1;
1.628 raeburn 15611: my $now = time;
1.443 albertel 15612: my $uurl='/'.$cid;
15613: $uurl=~s/\_/\//g;
15614: if ($oldsec) {
15615: $uurl.='/'.$oldsec;
15616: }
1.626 raeburn 15617: $oldsecurl = $uurl;
1.628 raeburn 15618: $expire_role_result =
1.652 raeburn 15619: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15620: if ($env{'request.course.sec'} ne '') {
15621: if ($expire_role_result eq 'refused') {
15622: my @roles = ('st');
15623: my @statuses = ('previous');
15624: my @roledoms = ($one);
15625: my $withsec = 1;
15626: my %roleshash =
15627: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15628: \@statuses,\@roles,\@roledoms,$withsec);
15629: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15630: my ($oldstart,$oldend) =
15631: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15632: if ($oldend > 0 && $oldend <= $now) {
15633: $expire_role_result = 'ok';
15634: }
15635: }
15636: }
15637: }
1.443 albertel 15638: $result = $expire_role_result;
15639: }
15640: }
15641: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15642: $modify_section_result =
15643: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15644: undef,undef,undef,$sec,
15645: $end,$start,'','',$cid,
15646: '',$context,$credits);
1.443 albertel 15647: if ($modify_section_result =~ /^ok/) {
15648: if ($secchange == 1) {
1.628 raeburn 15649: if ($sec eq '') {
15650: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15651: } else {
15652: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15653: }
1.443 albertel 15654: } elsif ($oldsec eq '-1') {
1.628 raeburn 15655: if ($sec eq '') {
15656: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15657: } else {
15658: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15659: }
1.443 albertel 15660: } else {
1.628 raeburn 15661: if ($sec eq '') {
15662: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15663: } else {
15664: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15665: }
1.443 albertel 15666: }
15667: } else {
1.1115 raeburn 15668: if ($secchange) {
1.628 raeburn 15669: $$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;
15670: } else {
15671: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15672: }
1.443 albertel 15673: }
15674: $result = $modify_section_result;
15675: } elsif ($secchange == 1) {
1.628 raeburn 15676: if ($oldsec eq '') {
1.1103 raeburn 15677: $$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 15678: } else {
15679: $$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;
15680: }
1.626 raeburn 15681: if ($expire_role_result eq 'refused') {
15682: my $newsecurl = '/'.$cid;
15683: $newsecurl =~ s/\_/\//g;
15684: if ($sec ne '') {
15685: $newsecurl.='/'.$sec;
15686: }
15687: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15688: if ($sec eq '') {
15689: $$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;
15690: } else {
15691: $$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;
15692: }
15693: }
15694: }
1.443 albertel 15695: }
15696: } else {
1.626 raeburn 15697: $$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 15698: $result = "error: incomplete course id\n";
15699: }
15700: return $result;
15701: }
15702:
1.1108 raeburn 15703: sub show_role_extent {
15704: my ($scope,$context,$role) = @_;
15705: $scope =~ s{^/}{};
15706: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15707: push(@courseroles,'co');
15708: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15709: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15710: $scope =~ s{/}{_};
15711: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15712: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15713: my ($audom,$auname) = split(/\//,$scope);
15714: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15715: &Apache::loncommon::plainname($auname,$audom).'</span>');
15716: } else {
15717: $scope =~ s{/$}{};
15718: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15719: &Apache::lonnet::domain($scope,'description').'</span>');
15720: }
15721: }
15722:
1.443 albertel 15723: ############################################################
15724: ############################################################
15725:
1.566 albertel 15726: sub check_clone {
1.578 raeburn 15727: my ($args,$linefeed) = @_;
1.566 albertel 15728: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15729: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15730: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15731: my $clonemsg;
15732: my $can_clone = 0;
1.944 raeburn 15733: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15734: if ($lctype ne 'community') {
15735: $lctype = 'course';
15736: }
1.566 albertel 15737: if ($clonehome eq 'no_host') {
1.944 raeburn 15738: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15739: $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a non-existent community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
15740: } else {
15741: $clonemsg = &mt('No new course created.').$linefeed.&mt('A new course could not be cloned from the specified original - [_1] - because it is a non-existent course.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
15742: }
1.566 albertel 15743: } else {
15744: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15745: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15746: if ($clonedesc{'type'} ne 'Community') {
1.1262 raeburn 15747: $clonemsg = &mt('No new community created.').$linefeed.&mt('A new community could not be cloned from the specified original - [_1] - because it is a course not a community.',$args->{'clonecourse'}.':'.$args->{'clonedomain'});
1.908 raeburn 15748: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15749: }
15750: }
1.1262 raeburn 15751: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15752: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15753: $can_clone = 1;
15754: } else {
1.1221 raeburn 15755: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15756: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 15757: if ($clonehash{'cloners'} eq '') {
15758: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15759: if ($domdefs{'canclone'}) {
15760: unless ($domdefs{'canclone'} eq 'none') {
15761: if ($domdefs{'canclone'} eq 'domain') {
15762: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15763: $can_clone = 1;
15764: }
15765: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15766: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15767: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15768: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15769: $can_clone = 1;
15770: }
15771: }
15772: }
15773: }
1.578 raeburn 15774: } else {
1.1221 raeburn 15775: my @cloners = split(/,/,$clonehash{'cloners'});
15776: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15777: $can_clone = 1;
1.1221 raeburn 15778: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15779: $can_clone = 1;
1.1225 raeburn 15780: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15781: $can_clone = 1;
1.1221 raeburn 15782: }
15783: unless ($can_clone) {
1.1225 raeburn 15784: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15785: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 15786: my (%gotdomdefaults,%gotcodedefaults);
15787: foreach my $cloner (@cloners) {
15788: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15789: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15790: my (%codedefaults,@code_order);
15791: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15792: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15793: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15794: }
15795: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15796: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15797: }
15798: } else {
15799: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15800: \%codedefaults,
15801: \@code_order);
15802: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15803: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15804: }
15805: if (@code_order > 0) {
15806: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15807: $cloner,$clonehash{'internal.coursecode'},
15808: $args->{'crscode'})) {
15809: $can_clone = 1;
15810: last;
15811: }
15812: }
15813: }
15814: }
15815: }
1.1225 raeburn 15816: }
15817: }
15818: unless ($can_clone) {
15819: my $ccrole = 'cc';
15820: if ($args->{'crstype'} eq 'Community') {
15821: $ccrole = 'co';
15822: }
15823: my %roleshash =
15824: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15825: $args->{'ccdomain'},
15826: 'userroles',['active'],[$ccrole],
15827: [$args->{'clonedomain'}]);
15828: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15829: $can_clone = 1;
15830: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15831: $args->{'ccuname'},$args->{'ccdomain'})) {
15832: $can_clone = 1;
1.1221 raeburn 15833: }
15834: }
15835: unless ($can_clone) {
15836: if ($args->{'crstype'} eq 'Community') {
15837: $clonemsg = &mt('No new community created.').$linefeed.&mt('The new community could not be cloned from the existing community because the new community owner ([_1]) does not have cloning rights in the existing community ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
1.942 raeburn 15838: } else {
1.1221 raeburn 15839: $clonemsg = &mt('No new course created.').$linefeed.&mt('The new course could not be cloned from the existing course because the new course owner ([_1]) does not have cloning rights in the existing course ([_2]).',$args->{'ccuname'}.':'.$args->{'ccdomain'},$clonedesc{'description'});
15840: }
1.566 albertel 15841: }
1.578 raeburn 15842: }
1.566 albertel 15843: }
15844: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15845: }
15846:
1.444 albertel 15847: sub construct_course {
1.1262 raeburn 15848: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15849: $cnum,$category,$coderef) = @_;
1.444 albertel 15850: my $outcome;
1.541 raeburn 15851: my $linefeed = '<br />'."\n";
15852: if ($context eq 'auto') {
15853: $linefeed = "\n";
15854: }
1.566 albertel 15855:
15856: #
15857: # Are we cloning?
15858: #
15859: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15860: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15861: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15862: if ($context ne 'auto') {
1.578 raeburn 15863: if ($clonemsg ne '') {
15864: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15865: }
1.566 albertel 15866: }
15867: $outcome .= $clonemsg.$linefeed;
15868:
15869: if (!$can_clone) {
15870: return (0,$outcome);
15871: }
15872: }
15873:
1.444 albertel 15874: #
15875: # Open course
15876: #
1.1239 raeburn 15877: my $showncrstype;
15878: if ($args->{'crstype'} eq 'Placement') {
15879: $showncrstype = 'placement test';
15880: } else {
15881: $showncrstype = lc($args->{'crstype'});
15882: }
1.444 albertel 15883: my %cenv=();
15884: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15885: $args->{'cdescr'},
15886: $args->{'curl'},
15887: $args->{'course_home'},
15888: $args->{'nonstandard'},
15889: $args->{'crscode'},
15890: $args->{'ccuname'}.':'.
15891: $args->{'ccdomain'},
1.882 raeburn 15892: $args->{'crstype'},
1.885 raeburn 15893: $cnum,$context,$category);
1.444 albertel 15894:
15895: # Note: The testing routines depend on this being output; see
15896: # Utils::Course. This needs to at least be output as a comment
15897: # if anyone ever decides to not show this, and Utils::Course::new
15898: # will need to be suitably modified.
1.1239 raeburn 15899: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
1.943 raeburn 15900: if ($$courseid =~ /^error:/) {
15901: return (0,$outcome);
15902: }
15903:
1.444 albertel 15904: #
15905: # Check if created correctly
15906: #
1.479 albertel 15907: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15908: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15909: if ($crsuhome eq 'no_host') {
15910: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15911: return (0,$outcome);
15912: }
1.541 raeburn 15913: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15914:
1.444 albertel 15915: #
1.566 albertel 15916: # Do the cloning
15917: #
15918: if ($can_clone && $cloneid) {
1.1239 raeburn 15919: $clonemsg = &mt('Cloning [_1] from [_2]',$showncrstype,$clonehome);
1.566 albertel 15920: if ($context ne 'auto') {
15921: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15922: }
15923: $outcome .= $clonemsg.$linefeed;
15924: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15925: # Copy all files
1.637 www 15926: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15927: # Restore URL
1.566 albertel 15928: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15929: # Restore title
1.566 albertel 15930: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15931: # Restore creation date, creator and creation context.
15932: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15933: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15934: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15935: # Mark as cloned
1.566 albertel 15936: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15937: # Need to clone grading mode
15938: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15939: $cenv{'grading'}=$newenv{'grading'};
15940: # Do not clone these environment entries
15941: &Apache::lonnet::del('environment',
15942: ['default_enrollment_start_date',
15943: 'default_enrollment_end_date',
15944: 'question.email',
15945: 'policy.email',
15946: 'comment.email',
15947: 'pch.users.denied',
1.725 raeburn 15948: 'plc.users.denied',
15949: 'hidefromcat',
1.1121 raeburn 15950: 'checkforpriv',
1.1166 raeburn 15951: 'categories',
15952: 'internal.uniquecode'],
1.638 www 15953: $$crsudom,$$crsunum);
1.1170 raeburn 15954: if ($args->{'textbook'}) {
15955: $cenv{'internal.textbook'} = $args->{'textbook'};
15956: }
1.444 albertel 15957: }
1.566 albertel 15958:
1.444 albertel 15959: #
15960: # Set environment (will override cloned, if existing)
15961: #
15962: my @sections = ();
15963: my @xlists = ();
15964: if ($args->{'crstype'}) {
15965: $cenv{'type'}=$args->{'crstype'};
15966: }
15967: if ($args->{'crsid'}) {
15968: $cenv{'courseid'}=$args->{'crsid'};
15969: }
15970: if ($args->{'crscode'}) {
15971: $cenv{'internal.coursecode'}=$args->{'crscode'};
15972: }
15973: if ($args->{'crsquota'} ne '') {
15974: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15975: } else {
15976: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15977: }
15978: if ($args->{'ccuname'}) {
15979: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15980: ':'.$args->{'ccdomain'};
15981: } else {
15982: $cenv{'internal.courseowner'} = $args->{'curruser'};
15983: }
1.1116 raeburn 15984: if ($args->{'defaultcredits'}) {
15985: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15986: }
1.444 albertel 15987: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15988: if ($args->{'crssections'}) {
15989: $cenv{'internal.sectionnums'} = '';
15990: if ($args->{'crssections'} =~ m/,/) {
15991: @sections = split/,/,$args->{'crssections'};
15992: } else {
15993: $sections[0] = $args->{'crssections'};
15994: }
15995: if (@sections > 0) {
15996: foreach my $item (@sections) {
15997: my ($sec,$gp) = split/:/,$item;
15998: my $class = $args->{'crscode'}.$sec;
15999: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
16000: $cenv{'internal.sectionnums'} .= $item.',';
16001: unless ($addcheck eq 'ok') {
1.1263 raeburn 16002: push(@badclasses,$class);
1.444 albertel 16003: }
16004: }
16005: $cenv{'internal.sectionnums'} =~ s/,$//;
16006: }
16007: }
16008: # do not hide course coordinator from staff listing,
16009: # even if privileged
16010: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 16011: # add course coordinator's domain to domains to check for privileged users
16012: # if different to course domain
16013: if ($$crsudom ne $args->{'ccdomain'}) {
16014: $cenv{'checkforpriv'} = $args->{'ccdomain'};
16015: }
1.444 albertel 16016: # add crosslistings
16017: if ($args->{'crsxlist'}) {
16018: $cenv{'internal.crosslistings'}='';
16019: if ($args->{'crsxlist'} =~ m/,/) {
16020: @xlists = split/,/,$args->{'crsxlist'};
16021: } else {
16022: $xlists[0] = $args->{'crsxlist'};
16023: }
16024: if (@xlists > 0) {
16025: foreach my $item (@xlists) {
16026: my ($xl,$gp) = split/:/,$item;
16027: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
16028: $cenv{'internal.crosslistings'} .= $item.',';
16029: unless ($addcheck eq 'ok') {
1.1263 raeburn 16030: push(@badclasses,$xl);
1.444 albertel 16031: }
16032: }
16033: $cenv{'internal.crosslistings'} =~ s/,$//;
16034: }
16035: }
16036: if ($args->{'autoadds'}) {
16037: $cenv{'internal.autoadds'}=$args->{'autoadds'};
16038: }
16039: if ($args->{'autodrops'}) {
16040: $cenv{'internal.autodrops'}=$args->{'autodrops'};
16041: }
16042: # check for notification of enrollment changes
16043: my @notified = ();
16044: if ($args->{'notify_owner'}) {
16045: if ($args->{'ccuname'} ne '') {
16046: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
16047: }
16048: }
16049: if ($args->{'notify_dc'}) {
16050: if ($uname ne '') {
1.630 raeburn 16051: push(@notified,$uname.':'.$udom);
1.444 albertel 16052: }
16053: }
16054: if (@notified > 0) {
16055: my $notifylist;
16056: if (@notified > 1) {
16057: $notifylist = join(',',@notified);
16058: } else {
16059: $notifylist = $notified[0];
16060: }
16061: $cenv{'internal.notifylist'} = $notifylist;
16062: }
16063: if (@badclasses > 0) {
16064: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 16065: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
16066: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
16067: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 16068: );
1.1264 raeburn 16069: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
16070: &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 16071: if ($context eq 'auto') {
16072: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 16073: } else {
1.566 albertel 16074: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 16075: }
16076: foreach my $item (@badclasses) {
1.541 raeburn 16077: if ($context eq 'auto') {
1.1261 raeburn 16078: $outcome .= " - $item\n";
1.541 raeburn 16079: } else {
1.1261 raeburn 16080: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16081: }
1.1261 raeburn 16082: }
16083: if ($context eq 'auto') {
16084: $outcome .= $linefeed;
16085: } else {
16086: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 16087: }
1.444 albertel 16088: }
16089: if ($args->{'no_end_date'}) {
16090: $args->{'endaccess'} = 0;
16091: }
16092: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16093: $cenv{'internal.autoend'}=$args->{'enrollend'};
16094: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16095: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16096: if ($args->{'showphotos'}) {
16097: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16098: }
16099: $cenv{'internal.authtype'} = $args->{'authtype'};
16100: $cenv{'internal.autharg'} = $args->{'autharg'};
16101: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16102: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16103: 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');
16104: if ($context eq 'auto') {
16105: $outcome .= $krb_msg;
16106: } else {
1.566 albertel 16107: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16108: }
16109: $outcome .= $linefeed;
1.444 albertel 16110: }
16111: }
16112: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16113: if ($args->{'setpolicy'}) {
16114: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16115: }
16116: if ($args->{'setcontent'}) {
16117: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16118: }
1.1251 raeburn 16119: if ($args->{'setcomment'}) {
16120: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16121: }
1.444 albertel 16122: }
16123: if ($args->{'reshome'}) {
16124: $cenv{'reshome'}=$args->{'reshome'}.'/';
16125: $cenv{'reshome'}=~s/\/+$/\//;
16126: }
16127: #
16128: # course has keyed access
16129: #
16130: if ($args->{'setkeys'}) {
16131: $cenv{'keyaccess'}='yes';
16132: }
16133: # if specified, key authority is not course, but user
16134: # only active if keyaccess is yes
16135: if ($args->{'keyauth'}) {
1.487 albertel 16136: my ($user,$domain) = split(':',$args->{'keyauth'});
16137: $user = &LONCAPA::clean_username($user);
16138: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16139: if ($user ne '' && $domain ne '') {
1.487 albertel 16140: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16141: }
16142: }
16143:
1.1166 raeburn 16144: #
1.1167 raeburn 16145: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 16146: #
16147: if ($args->{'uniquecode'}) {
16148: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16149: if ($code) {
16150: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 16151: my %crsinfo =
16152: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16153: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16154: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16155: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16156: }
1.1166 raeburn 16157: if (ref($coderef)) {
16158: $$coderef = $code;
16159: }
16160: }
16161: }
16162:
1.444 albertel 16163: if ($args->{'disresdis'}) {
16164: $cenv{'pch.roles.denied'}='st';
16165: }
16166: if ($args->{'disablechat'}) {
16167: $cenv{'plc.roles.denied'}='st';
16168: }
16169:
16170: # Record we've not yet viewed the Course Initialization Helper for this
16171: # course
16172: $cenv{'course.helper.not.run'} = 1;
16173: #
16174: # Use new Randomseed
16175: #
16176: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16177: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16178: #
16179: # The encryption code and receipt prefix for this course
16180: #
16181: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16182: $cenv{'internal.encpref'}=100+int(9*rand(99));
16183: #
16184: # By default, use standard grading
16185: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16186:
1.541 raeburn 16187: $outcome .= $linefeed.&mt('Setting environment').': '.
16188: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16189: #
16190: # Open all assignments
16191: #
16192: if ($args->{'openall'}) {
16193: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
16194: my %storecontent = ($storeunder => time,
16195: $storeunder.'.type' => 'date_start');
16196:
16197: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 16198: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16199: }
16200: #
16201: # Set first page
16202: #
16203: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16204: || ($cloneid)) {
1.445 albertel 16205: use LONCAPA::map;
1.444 albertel 16206: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16207:
16208: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16209: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16210:
1.444 albertel 16211: $outcome .= ($fatal?$errtext:'read ok').' - ';
16212: my $title; my $url;
16213: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16214: $title=&mt('Syllabus');
1.444 albertel 16215: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16216: } else {
1.963 raeburn 16217: $title=&mt('Table of Contents');
1.444 albertel 16218: $url='/adm/navmaps';
16219: }
1.445 albertel 16220:
16221: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16222: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16223:
16224: if ($errtext) { $fatal=2; }
1.541 raeburn 16225: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16226: }
1.566 albertel 16227:
1.1237 raeburn 16228: #
16229: # Set params for Placement Tests
16230: #
1.1239 raeburn 16231: if ($args->{'crstype'} eq 'Placement') {
16232: my %storecontent;
16233: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
16234: my %defaults = (
16235: buttonshide => { value => 'yes',
16236: type => 'string_yesno',},
16237: type => { value => 'randomizetry',
16238: type => 'string_questiontype',},
16239: maxtries => { value => 1,
16240: type => 'int_pos',},
16241: problemstatus => { value => 'no',
16242: type => 'string_problemstatus',},
16243: );
16244: foreach my $key (keys(%defaults)) {
16245: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
16246: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
16247: }
1.1237 raeburn 16248: &Apache::lonnet::cput
16249: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
16250: }
16251:
1.566 albertel 16252: return (1,$outcome);
1.444 albertel 16253: }
16254:
1.1166 raeburn 16255: sub make_unique_code {
16256: my ($cdom,$cnum) = @_;
16257: # get lock on uniquecodes db
16258: my $lockhash = {
16259: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16260: ':'.$env{'user.domain'},
16261: };
16262: my $tries = 0;
16263: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16264: my ($code,$error);
16265:
16266: while (($gotlock ne 'ok') && ($tries<3)) {
16267: $tries ++;
16268: sleep 1;
16269: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16270: }
16271: if ($gotlock eq 'ok') {
16272: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16273: my $gotcode;
16274: my $attempts = 0;
16275: while ((!$gotcode) && ($attempts < 100)) {
16276: $code = &generate_code();
16277: if (!exists($currcodes{$code})) {
16278: $gotcode = 1;
16279: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
16280: $error = 'nostore';
16281: }
16282: }
16283: $attempts ++;
16284: }
16285: my @del_lock = ($cnum."\0".'uniquecodes');
16286: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
16287: } else {
16288: $error = 'nolock';
16289: }
16290: return ($code,$error);
16291: }
16292:
16293: sub generate_code {
16294: my $code;
16295: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
16296: for (my $i=0; $i<6; $i++) {
16297: my $lettnum = int (rand 2);
16298: my $item = '';
16299: if ($lettnum) {
16300: $item = $letts[int( rand(18) )];
16301: } else {
16302: $item = 1+int( rand(8) );
16303: }
16304: $code .= $item;
16305: }
16306: return $code;
16307: }
16308:
1.444 albertel 16309: ############################################################
16310: ############################################################
16311:
1.1237 raeburn 16312: # Community, Course and Placement Test
1.378 raeburn 16313: sub course_type {
16314: my ($cid) = @_;
16315: if (!defined($cid)) {
16316: $cid = $env{'request.course.id'};
16317: }
1.404 albertel 16318: if (defined($env{'course.'.$cid.'.type'})) {
16319: return $env{'course.'.$cid.'.type'};
1.378 raeburn 16320: } else {
16321: return 'Course';
1.377 raeburn 16322: }
16323: }
1.156 albertel 16324:
1.406 raeburn 16325: sub group_term {
16326: my $crstype = &course_type();
16327: my %names = (
16328: 'Course' => 'group',
1.865 raeburn 16329: 'Community' => 'group',
1.1237 raeburn 16330: 'Placement' => 'group',
1.406 raeburn 16331: );
16332: return $names{$crstype};
16333: }
16334:
1.902 raeburn 16335: sub course_types {
1.1310 raeburn 16336: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 16337: my %typename = (
16338: official => 'Official course',
16339: unofficial => 'Unofficial course',
16340: community => 'Community',
1.1165 raeburn 16341: textbook => 'Textbook course',
1.1237 raeburn 16342: placement => 'Placement test',
1.1310 raeburn 16343: lti => 'LTI provider',
1.902 raeburn 16344: );
16345: return (\@types,\%typename);
16346: }
16347:
1.156 albertel 16348: sub icon {
16349: my ($file)=@_;
1.505 albertel 16350: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 16351: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 16352: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 16353: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
16354: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
16355: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16356: $curfext.".gif") {
16357: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16358: $curfext.".gif";
16359: }
16360: }
1.249 albertel 16361: return &lonhttpdurl($iconname);
1.154 albertel 16362: }
1.84 albertel 16363:
1.575 albertel 16364: sub lonhttpdurl {
1.692 www 16365: #
16366: # Had been used for "small fry" static images on separate port 8080.
16367: # Modify here if lightweight http functionality desired again.
16368: # Currently eliminated due to increasing firewall issues.
16369: #
1.575 albertel 16370: my ($url)=@_;
1.692 www 16371: return $url;
1.215 albertel 16372: }
16373:
1.213 albertel 16374: sub connection_aborted {
16375: my ($r)=@_;
16376: $r->print(" ");$r->rflush();
16377: my $c = $r->connection;
16378: return $c->aborted();
16379: }
16380:
1.221 foxr 16381: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16382: # strings as 'strings'.
16383: sub escape_single {
1.221 foxr 16384: my ($input) = @_;
1.223 albertel 16385: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16386: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16387: return $input;
16388: }
1.223 albertel 16389:
1.222 foxr 16390: # Same as escape_single, but escape's "'s This
16391: # can be used for "strings"
16392: sub escape_double {
16393: my ($input) = @_;
16394: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16395: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16396: return $input;
16397: }
1.223 albertel 16398:
1.222 foxr 16399: # Escapes the last element of a full URL.
16400: sub escape_url {
16401: my ($url) = @_;
1.238 raeburn 16402: my @urlslices = split(/\//, $url,-1);
1.369 www 16403: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 16404: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16405: }
1.462 albertel 16406:
1.820 raeburn 16407: sub compare_arrays {
16408: my ($arrayref1,$arrayref2) = @_;
16409: my (@difference,%count);
16410: @difference = ();
16411: %count = ();
16412: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16413: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16414: foreach my $element (keys(%count)) {
16415: if ($count{$element} == 1) {
16416: push(@difference,$element);
16417: }
16418: }
16419: }
16420: return @difference;
16421: }
16422:
1.1322 ! raeburn 16423: sub lon_status_items {
! 16424: my %defaults = (
! 16425: E => 100,
! 16426: W => 4,
! 16427: N => 1,
! 16428: threshold => 200,
! 16429: sysmail => 2500,
! 16430: );
! 16431: my %names = (
! 16432: E => 'Errors',
! 16433: W => 'Warnings',
! 16434: N => 'Notices',
! 16435: );
! 16436: return (\%defaults,\%names);
! 16437: }
! 16438:
1.817 bisitz 16439: # -------------------------------------------------------- Initialize user login
1.462 albertel 16440: sub init_user_environment {
1.463 albertel 16441: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16442: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16443:
16444: my $public=($username eq 'public' && $domain eq 'public');
16445:
1.1062 raeburn 16446: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16447: my $now=time;
16448:
16449: if ($public) {
16450: my $max_public=100;
16451: my $oldest;
16452: my $oldest_time=0;
16453: for(my $next=1;$next<=$max_public;$next++) {
16454: if (-e $lonids."/publicuser_$next.id") {
16455: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16456: if ($mtime<$oldest_time || !$oldest_time) {
16457: $oldest_time=$mtime;
16458: $oldest=$next;
16459: }
16460: } else {
16461: $cookie="publicuser_$next";
16462: last;
16463: }
16464: }
16465: if (!$cookie) { $cookie="publicuser_$oldest"; }
16466: } else {
1.1275 raeburn 16467: # See if old ID present, if so, remove if this isn't a robot,
16468: # killing any existing non-robot sessions
1.463 albertel 16469: if (!$args->{'robot'}) {
16470: opendir(DIR,$lonids);
16471: while ($filename=readdir(DIR)) {
16472: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1320 raeburn 16473: if (tie(my %oldenv,'GDBM_File',"$lonids/$filename",
16474: &GDBM_READER(),0640)) {
1.1295 raeburn 16475: my $linkedfile;
1.1320 raeburn 16476: if (exists($oldenv{'user.linkedenv'})) {
16477: $linkedfile = $oldenv{'user.linkedenv'};
1.1295 raeburn 16478: }
1.1320 raeburn 16479: untie(%oldenv);
16480: if (unlink("$lonids/$filename")) {
16481: if ($linkedfile =~ /^[a-f0-9]+_linked$/) {
16482: if (-l "$lonids/$linkedfile.id") {
16483: unlink("$lonids/$linkedfile.id");
16484: }
1.1295 raeburn 16485: }
16486: }
16487: } else {
16488: unlink($lonids.'/'.$filename);
16489: }
1.463 albertel 16490: }
1.462 albertel 16491: }
1.463 albertel 16492: closedir(DIR);
1.1204 raeburn 16493: # If there is a undeleted lockfile for the user's paste buffer remove it.
16494: my $namespace = 'nohist_courseeditor';
16495: my $lockingkey = 'paste'."\0".'locked_num';
16496: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16497: $domain,$username);
16498: if (exists($lockhash{$lockingkey})) {
16499: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16500: unless ($delresult eq 'ok') {
16501: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16502: }
16503: }
1.462 albertel 16504: }
16505: # Give them a new cookie
1.463 albertel 16506: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16507: : $now.$$.int(rand(10000)));
1.463 albertel 16508: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16509:
16510: # Initialize roles
16511:
1.1062 raeburn 16512: ($userroles,$firstaccenv,$timerintenv) =
16513: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16514: }
16515: # ------------------------------------ Check browser type and MathML capability
16516:
1.1194 raeburn 16517: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16518: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16519:
16520: # ------------------------------------------------------------- Get environment
16521:
16522: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16523: my ($tmp) = keys(%userenv);
1.1275 raeburn 16524: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 16525: undef(%userenv);
16526: }
16527: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16528: $form->{'interface'}=$userenv{'interface'};
16529: }
16530: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16531:
16532: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16533: foreach my $option ('interface','localpath','localres') {
16534: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16535: }
16536: # --------------------------------------------------------- Write first profile
16537:
16538: {
16539: my %initial_env =
16540: ("user.name" => $username,
16541: "user.domain" => $domain,
16542: "user.home" => $authhost,
16543: "browser.type" => $clientbrowser,
16544: "browser.version" => $clientversion,
16545: "browser.mathml" => $clientmathml,
16546: "browser.unicode" => $clientunicode,
16547: "browser.os" => $clientos,
1.1137 raeburn 16548: "browser.mobile" => $clientmobile,
1.1141 raeburn 16549: "browser.info" => $clientinfo,
1.1194 raeburn 16550: "browser.osversion" => $clientosversion,
1.462 albertel 16551: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16552: "request.course.fn" => '',
16553: "request.course.uri" => '',
16554: "request.course.sec" => '',
16555: "request.role" => 'cm',
16556: "request.role.adv" => $env{'user.adv'},
16557: "request.host" => $ENV{'REMOTE_ADDR'},);
16558:
16559: if ($form->{'localpath'}) {
16560: $initial_env{"browser.localpath"} = $form->{'localpath'};
16561: $initial_env{"browser.localres"} = $form->{'localres'};
16562: }
16563:
16564: if ($form->{'interface'}) {
16565: $form->{'interface'}=~s/\W//gs;
16566: $initial_env{"browser.interface"} = $form->{'interface'};
16567: $env{'browser.interface'}=$form->{'interface'};
16568: }
16569:
1.1157 raeburn 16570: if ($form->{'iptoken'}) {
16571: my $lonhost = $r->dir_config('lonHostID');
16572: $initial_env{"user.noloadbalance"} = $lonhost;
16573: $env{'user.noloadbalance'} = $lonhost;
16574: }
16575:
1.1268 raeburn 16576: if ($form->{'noloadbalance'}) {
16577: my @hosts = &Apache::lonnet::current_machine_ids();
16578: my $hosthere = $form->{'noloadbalance'};
16579: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16580: $initial_env{"user.noloadbalance"} = $hosthere;
16581: $env{'user.noloadbalance'} = $hosthere;
16582: }
16583: }
16584:
1.1016 raeburn 16585: unless ($domain eq 'public') {
1.1273 raeburn 16586: my %is_adv = ( is_adv => $env{'user.adv'} );
16587: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
16588:
16589: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16590: $userenv{'availabletools.'.$tool} =
16591: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16592: undef,\%userenv,\%domdef,\%is_adv);
16593: }
1.980 raeburn 16594:
1.1311 raeburn 16595: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 16596: $userenv{'canrequest.'.$crstype} =
16597: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16598: 'reload','requestcourses',
16599: \%userenv,\%domdef,\%is_adv);
16600: }
1.724 raeburn 16601:
1.1273 raeburn 16602: $userenv{'canrequest.author'} =
16603: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16604: 'reload','requestauthor',
1.980 raeburn 16605: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 16606: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16607: $domain,$username);
16608: my $reqstatus = $reqauthor{'author_status'};
16609: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16610: if (ref($reqauthor{'author'}) eq 'HASH') {
16611: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16612: $reqauthor{'author'}{'timestamp'};
16613: }
1.1092 raeburn 16614: }
1.1287 raeburn 16615: my ($types,$typename) = &course_types();
16616: if (ref($types) eq 'ARRAY') {
16617: my @options = ('approval','validate','autolimit');
16618: my $optregex = join('|',@options);
16619: my (%willtrust,%trustchecked);
16620: foreach my $type (@{$types}) {
16621: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
16622: if ($dom_str ne '') {
16623: my $updatedstr = '';
16624: my @possdomains = split(',',$dom_str);
16625: foreach my $entry (@possdomains) {
16626: my ($extdom,$extopt) = split(':',$entry);
16627: unless ($trustchecked{$extdom}) {
16628: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
16629: $trustchecked{$extdom} = 1;
16630: }
16631: if ($willtrust{$extdom}) {
16632: $updatedstr .= $entry.',';
16633: }
16634: }
16635: $updatedstr =~ s/,$//;
16636: if ($updatedstr) {
16637: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
16638: } else {
16639: delete($userenv{'reqcrsotherdom.'.$type});
16640: }
16641: }
16642: }
16643: }
1.1092 raeburn 16644: }
1.462 albertel 16645: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16646:
1.462 albertel 16647: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16648: &GDBM_WRCREAT(),0640)) {
16649: &_add_to_env(\%disk_env,\%initial_env);
16650: &_add_to_env(\%disk_env,\%userenv,'environment.');
16651: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16652: if (ref($firstaccenv) eq 'HASH') {
16653: &_add_to_env(\%disk_env,$firstaccenv);
16654: }
16655: if (ref($timerintenv) eq 'HASH') {
16656: &_add_to_env(\%disk_env,$timerintenv);
16657: }
1.463 albertel 16658: if (ref($args->{'extra_env'})) {
16659: &_add_to_env(\%disk_env,$args->{'extra_env'});
16660: }
1.462 albertel 16661: untie(%disk_env);
16662: } else {
1.705 tempelho 16663: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16664: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16665: return 'error: '.$!;
16666: }
16667: }
16668: $env{'request.role'}='cm';
16669: $env{'request.role.adv'}=$env{'user.adv'};
16670: $env{'browser.type'}=$clientbrowser;
16671:
16672: return $cookie;
16673:
16674: }
16675:
16676: sub _add_to_env {
16677: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16678: if (ref($env_data) eq 'HASH') {
16679: while (my ($key,$value) = each(%$env_data)) {
16680: $idf->{$prefix.$key} = $value;
16681: $env{$prefix.$key} = $value;
16682: }
1.462 albertel 16683: }
16684: }
16685:
1.685 tempelho 16686: # --- Get the symbolic name of a problem and the url
16687: sub get_symb {
16688: my ($request,$silent) = @_;
1.726 raeburn 16689: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16690: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16691: if ($symb eq '') {
16692: if (!$silent) {
1.1071 raeburn 16693: if (ref($request)) {
16694: $request->print("Unable to handle ambiguous references:$url:.");
16695: }
1.685 tempelho 16696: return ();
16697: }
16698: }
16699: &Apache::lonenc::check_decrypt(\$symb);
16700: return ($symb);
16701: }
16702:
16703: # --------------------------------------------------------------Get annotation
16704:
16705: sub get_annotation {
16706: my ($symb,$enc) = @_;
16707:
16708: my $key = $symb;
16709: if (!$enc) {
16710: $key =
16711: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16712: }
16713: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16714: return $annotation{$key};
16715: }
16716:
16717: sub clean_symb {
1.731 raeburn 16718: my ($symb,$delete_enc) = @_;
1.685 tempelho 16719:
16720: &Apache::lonenc::check_decrypt(\$symb);
16721: my $enc = $env{'request.enc'};
1.731 raeburn 16722: if ($delete_enc) {
1.730 raeburn 16723: delete($env{'request.enc'});
16724: }
1.685 tempelho 16725:
16726: return ($symb,$enc);
16727: }
1.462 albertel 16728:
1.1181 raeburn 16729: ############################################################
16730: ############################################################
16731:
16732: =pod
16733:
16734: =head1 Routines for building display used to search for courses
16735:
16736:
16737: =over 4
16738:
16739: =item * &build_filters()
16740:
16741: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 16742: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16743: and quotacheck.pl
16744:
1.1181 raeburn 16745:
16746: Inputs:
16747:
16748: filterlist - anonymous array of fields to include as potential filters
16749:
16750: crstype - course type
16751:
16752: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16753: to pop-open a course selector (will contain "extra element").
16754:
16755: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16756:
16757: filter - anonymous hash of criteria and their values
16758:
16759: action - form action
16760:
16761: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16762:
1.1182 raeburn 16763: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 16764:
16765: cloneruname - username of owner of new course who wants to clone
16766:
16767: clonerudom - domain of owner of new course who wants to clone
16768:
16769: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16770:
16771: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16772:
16773: codedom - domain
16774:
16775: formname - value of form element named "form".
16776:
16777: fixeddom - domain, if fixed.
16778:
16779: prevphase - value to assign to form element named "phase" when going back to the previous screen
16780:
16781: cnameelement - name of form element in form on opener page which will receive title of selected course
16782:
16783: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16784:
16785: cdomelement - name of form element in form on opener page which will receive domain of selected course
16786:
16787: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16788:
16789: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16790:
16791: clonewarning - warning message about missing information for intended course owner when DC creates a course
16792:
1.1182 raeburn 16793:
1.1181 raeburn 16794: Returns: $output - HTML for display of search criteria, and hidden form elements.
16795:
1.1182 raeburn 16796:
1.1181 raeburn 16797: Side Effects: None
16798:
16799: =cut
16800:
16801: # ---------------------------------------------- search for courses based on last activity etc.
16802:
16803: sub build_filters {
16804: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16805: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16806: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16807: $cnameelement,$cnumelement,$cdomelement,$setroles,
16808: $clonetext,$clonewarning) = @_;
1.1182 raeburn 16809: my ($list,$jscript);
1.1181 raeburn 16810: my $onchange = 'javascript:updateFilters(this)';
16811: my ($domainselectform,$sincefilterform,$createdfilterform,
16812: $ownerdomselectform,$persondomselectform,$instcodeform,
16813: $typeselectform,$instcodetitle);
16814: if ($formname eq '') {
16815: $formname = $caller;
16816: }
16817: foreach my $item (@{$filterlist}) {
16818: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16819: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16820: if ($item eq 'domainfilter') {
16821: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16822: } elsif ($item eq 'coursefilter') {
16823: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16824: } elsif ($item eq 'ownerfilter') {
16825: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16826: } elsif ($item eq 'ownerdomfilter') {
16827: $filter->{'ownerdomfilter'} =
16828: &LONCAPA::clean_domain($filter->{$item});
16829: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16830: 'ownerdomfilter',1);
16831: } elsif ($item eq 'personfilter') {
16832: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16833: } elsif ($item eq 'persondomfilter') {
16834: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16835: 'persondomfilter',1);
16836: } else {
16837: $filter->{$item} =~ s/\W//g;
16838: }
16839: if (!$filter->{$item}) {
16840: $filter->{$item} = '';
16841: }
16842: }
16843: if ($item eq 'domainfilter') {
16844: my $allow_blank = 1;
16845: if ($formname eq 'portform') {
16846: $allow_blank=0;
16847: } elsif ($formname eq 'studentform') {
16848: $allow_blank=0;
16849: }
16850: if ($fixeddom) {
16851: $domainselectform = '<input type="hidden" name="domainfilter"'.
16852: ' value="'.$codedom.'" />'.
16853: &Apache::lonnet::domain($codedom,'description');
16854: } else {
16855: $domainselectform = &select_dom_form($filter->{$item},
16856: 'domainfilter',
16857: $allow_blank,'',$onchange);
16858: }
16859: } else {
16860: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16861: }
16862: }
16863:
16864: # last course activity filter and selection
16865: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16866:
16867: # course created filter and selection
16868: if (exists($filter->{'createdfilter'})) {
16869: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16870: }
16871:
1.1239 raeburn 16872: my $prefix = $crstype;
16873: if ($crstype eq 'Placement') {
16874: $prefix = 'Placement Test'
16875: }
1.1181 raeburn 16876: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 16877: 'cac' => "$prefix Activity",
16878: 'ccr' => "$prefix Created",
16879: 'cde' => "$prefix Title",
16880: 'cdo' => "$prefix Domain",
1.1181 raeburn 16881: 'ins' => 'Institutional Code',
16882: 'inc' => 'Institutional Categorization',
1.1239 raeburn 16883: 'cow' => "$prefix Owner/Co-owner",
16884: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 16885: 'cog' => 'Type',
16886: );
16887:
16888: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16889: my $typeval = 'Course';
16890: if ($crstype eq 'Community') {
16891: $typeval = 'Community';
1.1239 raeburn 16892: } elsif ($crstype eq 'Placement') {
16893: $typeval = 'Placement';
1.1181 raeburn 16894: }
16895: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16896: } else {
16897: $typeselectform = '<select name="type" size="1"';
16898: if ($onchange) {
16899: $typeselectform .= ' onchange="'.$onchange.'"';
16900: }
16901: $typeselectform .= '>'."\n";
1.1237 raeburn 16902: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 16903: my $shown;
16904: if ($posstype eq 'Placement') {
16905: $shown = &mt('Placement Test');
16906: } else {
16907: $shown = &mt($posstype);
16908: }
1.1181 raeburn 16909: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 16910: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 16911: }
16912: $typeselectform.="</select>";
16913: }
16914:
16915: my ($cloneableonlyform,$cloneabletitle);
16916: if (exists($filter->{'cloneableonly'})) {
16917: my $cloneableon = '';
16918: my $cloneableoff = ' checked="checked"';
16919: if ($filter->{'cloneableonly'}) {
16920: $cloneableon = $cloneableoff;
16921: $cloneableoff = '';
16922: }
16923: $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>';
16924: if ($formname eq 'ccrs') {
1.1187 bisitz 16925: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 16926: } else {
16927: $cloneabletitle = &mt('Cloneable by you');
16928: }
16929: }
16930: my $officialjs;
16931: if ($crstype eq 'Course') {
16932: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 16933: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16934: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16935: if ($codedom) {
1.1181 raeburn 16936: $officialjs = 1;
16937: ($instcodeform,$jscript,$$numtitlesref) =
16938: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16939: $officialjs,$codetitlesref);
16940: if ($jscript) {
1.1182 raeburn 16941: $jscript = '<script type="text/javascript">'."\n".
16942: '// <![CDATA['."\n".
16943: $jscript."\n".
16944: '// ]]>'."\n".
16945: '</script>'."\n";
1.1181 raeburn 16946: }
16947: }
16948: if ($instcodeform eq '') {
16949: $instcodeform =
16950: '<input type="text" name="instcodefilter" size="10" value="'.
16951: $list->{'instcodefilter'}.'" />';
16952: $instcodetitle = $lt{'ins'};
16953: } else {
16954: $instcodetitle = $lt{'inc'};
16955: }
16956: if ($fixeddom) {
16957: $instcodetitle .= '<br />('.$codedom.')';
16958: }
16959: }
16960: }
16961: my $output = qq|
16962: <form method="post" name="filterpicker" action="$action">
16963: <input type="hidden" name="form" value="$formname" />
16964: |;
16965: if ($formname eq 'modifycourse') {
16966: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16967: '<input type="hidden" name="prevphase" value="'.
16968: $prevphase.'" />'."\n";
1.1198 musolffc 16969: } elsif ($formname eq 'quotacheck') {
16970: $output .= qq|
16971: <input type="hidden" name="sortby" value="" />
16972: <input type="hidden" name="sortorder" value="" />
16973: |;
16974: } else {
1.1181 raeburn 16975: my $name_input;
16976: if ($cnameelement ne '') {
16977: $name_input = '<input type="hidden" name="cnameelement" value="'.
16978: $cnameelement.'" />';
16979: }
16980: $output .= qq|
1.1182 raeburn 16981: <input type="hidden" name="cnumelement" value="$cnumelement" />
16982: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 16983: $name_input
16984: $roleelement
16985: $multelement
16986: $typeelement
16987: |;
16988: if ($formname eq 'portform') {
16989: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16990: }
16991: }
16992: if ($fixeddom) {
16993: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16994: }
16995: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16996: if ($sincefilterform) {
16997: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16998: .$sincefilterform
16999: .&Apache::lonhtmlcommon::row_closure();
17000: }
17001: if ($createdfilterform) {
17002: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
17003: .$createdfilterform
17004: .&Apache::lonhtmlcommon::row_closure();
17005: }
17006: if ($domainselectform) {
17007: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
17008: .$domainselectform
17009: .&Apache::lonhtmlcommon::row_closure();
17010: }
17011: if ($typeselectform) {
17012: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
17013: $output .= $typeselectform;
17014: } else {
17015: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
17016: .$typeselectform
17017: .&Apache::lonhtmlcommon::row_closure();
17018: }
17019: }
17020: if ($instcodeform) {
17021: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
17022: .$instcodeform
17023: .&Apache::lonhtmlcommon::row_closure();
17024: }
17025: if (exists($filter->{'ownerfilter'})) {
17026: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
17027: '<table><tr><td>'.&mt('Username').'<br />'.
17028: '<input type="text" name="ownerfilter" size="20" value="'.
17029: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17030: $ownerdomselectform.'</td></tr></table>'.
17031: &Apache::lonhtmlcommon::row_closure();
17032: }
17033: if (exists($filter->{'personfilter'})) {
17034: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
17035: '<table><tr><td>'.&mt('Username').'<br />'.
17036: '<input type="text" name="personfilter" size="20" value="'.
17037: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
17038: $persondomselectform.'</td></tr></table>'.
17039: &Apache::lonhtmlcommon::row_closure();
17040: }
17041: if (exists($filter->{'coursefilter'})) {
17042: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
17043: .'<input type="text" name="coursefilter" size="25" value="'
17044: .$list->{'coursefilter'}.'" />'
17045: .&Apache::lonhtmlcommon::row_closure();
17046: }
17047: if ($cloneableonlyform) {
17048: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
17049: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
17050: }
17051: if (exists($filter->{'descriptfilter'})) {
17052: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
17053: .'<input type="text" name="descriptfilter" size="40" value="'
17054: .$list->{'descriptfilter'}.'" />'
17055: .&Apache::lonhtmlcommon::row_closure(1);
17056: }
17057: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
17058: '<input type="hidden" name="updater" value="" />'."\n".
17059: '<input type="submit" name="gosearch" value="'.
17060: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
17061: return $jscript.$clonewarning.$output;
17062: }
17063:
17064: =pod
17065:
17066: =item * &timebased_select_form()
17067:
1.1182 raeburn 17068: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 17069: filter e.g., Course Activity, Course Created, when searching for courses
17070: or communities
17071:
17072: Inputs:
17073:
17074: item - name of form element (sincefilter or createdfilter)
17075:
17076: filter - anonymous hash of criteria and their values
17077:
17078: Returns: HTML for a select box contained a blank, then six time selections,
17079: with value set in incoming form variables currently selected.
17080:
17081: Side Effects: None
17082:
17083: =cut
17084:
17085: sub timebased_select_form {
17086: my ($item,$filter) = @_;
17087: if (ref($filter) eq 'HASH') {
17088: $filter->{$item} =~ s/[^\d-]//g;
17089: if (!$filter->{$item}) { $filter->{$item}=-1; }
17090: return &select_form(
17091: $filter->{$item},
17092: $item,
17093: { '-1' => '',
17094: '86400' => &mt('today'),
17095: '604800' => &mt('last week'),
17096: '2592000' => &mt('last month'),
17097: '7776000' => &mt('last three months'),
17098: '15552000' => &mt('last six months'),
17099: '31104000' => &mt('last year'),
17100: 'select_form_order' =>
17101: ['-1','86400','604800','2592000','7776000',
17102: '15552000','31104000']});
17103: }
17104: }
17105:
17106: =pod
17107:
17108: =item * &js_changer()
17109:
17110: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 17111: when course type or domain is changed, and also to hide 'Searching ...' on
17112: page load completion for page showing search result.
1.1181 raeburn 17113:
17114: Inputs: None
17115:
1.1183 raeburn 17116: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 17117:
17118: Side Effects: None
17119:
17120: =cut
17121:
17122: sub js_changer {
17123: return <<ENDJS;
17124: <script type="text/javascript">
17125: // <![CDATA[
17126: function updateFilters(caller) {
17127: if (typeof(caller) != "undefined") {
17128: document.filterpicker.updater.value = caller.name;
17129: }
17130: document.filterpicker.submit();
17131: }
1.1183 raeburn 17132:
17133: function hideSearching() {
17134: if (document.getElementById('searching')) {
17135: document.getElementById('searching').style.display = 'none';
17136: }
17137: return;
17138: }
17139:
1.1181 raeburn 17140: // ]]>
17141: </script>
17142:
17143: ENDJS
17144: }
17145:
17146: =pod
17147:
1.1182 raeburn 17148: =item * &search_courses()
17149:
17150: Process selected filters form course search form and pass to lonnet::courseiddump
17151: to retrieve a hash for which keys are courseIDs which match the selected filters.
17152:
17153: Inputs:
17154:
17155: dom - domain being searched
17156:
17157: type - course type ('Course' or 'Community' or '.' if any).
17158:
17159: filter - anonymous hash of criteria and their values
17160:
17161: numtitles - for institutional codes - number of categories
17162:
17163: cloneruname - optional username of new course owner
17164:
17165: clonerudom - optional domain of new course owner
17166:
1.1221 raeburn 17167: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 17168: (used when DC is using course creation form)
17169:
17170: codetitles - reference to array of titles of components in institutional codes (official courses).
17171:
1.1221 raeburn 17172: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17173: (and so can clone automatically)
17174:
17175: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17176:
17177: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17178: courses to clone
1.1182 raeburn 17179:
17180: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17181:
17182:
17183: Side Effects: None
17184:
17185: =cut
17186:
17187:
17188: sub search_courses {
1.1221 raeburn 17189: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17190: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 17191: my (%courses,%showcourses,$cloner);
17192: if (($filter->{'ownerfilter'} ne '') ||
17193: ($filter->{'ownerdomfilter'} ne '')) {
17194: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17195: $filter->{'ownerdomfilter'};
17196: }
17197: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17198: if (!$filter->{$item}) {
17199: $filter->{$item}='.';
17200: }
17201: }
17202: my $now = time;
17203: my $timefilter =
17204: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17205: my ($createdbefore,$createdafter);
17206: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17207: $createdbefore = $now;
17208: $createdafter = $now-$filter->{'createdfilter'};
17209: }
17210: my ($instcodefilter,$regexpok);
17211: if ($numtitles) {
17212: if ($env{'form.official'} eq 'on') {
17213: $instcodefilter =
17214: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17215: $regexpok = 1;
17216: } elsif ($env{'form.official'} eq 'off') {
17217: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17218: unless ($instcodefilter eq '') {
17219: $regexpok = -1;
17220: }
17221: }
17222: } else {
17223: $instcodefilter = $filter->{'instcodefilter'};
17224: }
17225: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17226: if ($type eq '') { $type = '.'; }
17227:
17228: if (($clonerudom ne '') && ($cloneruname ne '')) {
17229: $cloner = $cloneruname.':'.$clonerudom;
17230: }
17231: %courses = &Apache::lonnet::courseiddump($dom,
17232: $filter->{'descriptfilter'},
17233: $timefilter,
17234: $instcodefilter,
17235: $filter->{'combownerfilter'},
17236: $filter->{'coursefilter'},
17237: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 17238: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 17239: $filter->{'cloneableonly'},
17240: $createdbefore,$createdafter,undef,
1.1221 raeburn 17241: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 17242: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17243: my $ccrole;
17244: if ($type eq 'Community') {
17245: $ccrole = 'co';
17246: } else {
17247: $ccrole = 'cc';
17248: }
17249: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17250: $filter->{'persondomfilter'},
17251: 'userroles',undef,
17252: [$ccrole,'in','ad','ep','ta','cr'],
17253: $dom);
17254: foreach my $role (keys(%rolehash)) {
17255: my ($cnum,$cdom,$courserole) = split(':',$role);
17256: my $cid = $cdom.'_'.$cnum;
17257: if (exists($courses{$cid})) {
17258: if (ref($courses{$cid}) eq 'HASH') {
17259: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17260: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 17261: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 17262: }
17263: } else {
17264: $courses{$cid}{roles} = [$courserole];
17265: }
17266: $showcourses{$cid} = $courses{$cid};
17267: }
17268: }
17269: }
17270: %courses = %showcourses;
17271: }
17272: return %courses;
17273: }
17274:
17275: =pod
17276:
1.1181 raeburn 17277: =back
17278:
1.1207 raeburn 17279: =head1 Routines for version requirements for current course.
17280:
17281: =over 4
17282:
17283: =item * &check_release_required()
17284:
17285: Compares required LON-CAPA version with version on server, and
17286: if required version is newer looks for a server with the required version.
17287:
17288: Looks first at servers in user's owen domain; if none suitable, looks at
17289: servers in course's domain are permitted to host sessions for user's domain.
17290:
17291: Inputs:
17292:
17293: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17294:
17295: $courseid - Course ID of current course
17296:
17297: $rolecode - User's current role in course (for switchserver query string).
17298:
17299: $required - LON-CAPA version needed by course (format: Major.Minor).
17300:
17301:
17302: Returns:
17303:
17304: $switchserver - query string tp append to /adm/switchserver call (if
17305: current server's LON-CAPA version is too old.
17306:
17307: $warning - Message is displayed if no suitable server could be found.
17308:
17309: =cut
17310:
17311: sub check_release_required {
17312: my ($loncaparev,$courseid,$rolecode,$required) = @_;
17313: my ($switchserver,$warning);
17314: if ($required ne '') {
17315: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
17316: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17317: if ($reqdmajor ne '' && $reqdminor ne '') {
17318: my $otherserver;
17319: if (($major eq '' && $minor eq '') ||
17320: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
17321: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
17322: my $switchlcrev =
17323: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
17324: $userdomserver);
17325: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17326: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
17327: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
17328: my $cdom = $env{'course.'.$courseid.'.domain'};
17329: if ($cdom ne $env{'user.domain'}) {
17330: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
17331: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
17332: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17333: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
17334: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
17335: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
17336: my $canhost =
17337: &Apache::lonnet::can_host_session($env{'user.domain'},
17338: $coursedomserver,
17339: $remoterev,
17340: $udomdefaults{'remotesessions'},
17341: $defdomdefaults{'hostedsessions'});
17342:
17343: if ($canhost) {
17344: $otherserver = $coursedomserver;
17345: } else {
17346: $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.");
17347: }
17348: } else {
17349: $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).");
17350: }
17351: } else {
17352: $otherserver = $userdomserver;
17353: }
17354: }
17355: if ($otherserver ne '') {
17356: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
17357: }
17358: }
17359: }
17360: return ($switchserver,$warning);
17361: }
17362:
17363: =pod
17364:
17365: =item * &check_release_result()
17366:
17367: Inputs:
17368:
17369: $switchwarning - Warning message if no suitable server found to host session.
17370:
17371: $switchserver - query string to append to /adm/switchserver containing lonHostID
17372: and current role.
17373:
17374: Returns: HTML to display with information about requirement to switch server.
17375: Either displaying warning with link to Roles/Courses screen or
17376: display link to switchserver.
17377:
1.1181 raeburn 17378: =cut
17379:
1.1207 raeburn 17380: sub check_release_result {
17381: my ($switchwarning,$switchserver) = @_;
17382: my $output = &start_page('Selected course unavailable on this server').
17383: '<p class="LC_warning">';
17384: if ($switchwarning) {
17385: $output .= $switchwarning.'<br /><a href="/adm/roles">';
17386: if (&show_course()) {
17387: $output .= &mt('Display courses');
17388: } else {
17389: $output .= &mt('Display roles');
17390: }
17391: $output .= '</a>';
17392: } elsif ($switchserver) {
17393: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
17394: '<br />'.
17395: '<a href="/adm/switchserver?'.$switchserver.'">'.
17396: &mt('Switch Server').
17397: '</a>';
17398: }
17399: $output .= '</p>'.&end_page();
17400: return $output;
17401: }
17402:
17403: =pod
17404:
17405: =item * &needs_coursereinit()
17406:
17407: Determine if course contents stored for user's session needs to be
17408: refreshed, because content has changed since "Big Hash" last tied.
17409:
17410: Check for change is made if time last checked is more than 10 minutes ago
17411: (by default).
17412:
17413: Inputs:
17414:
17415: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17416:
17417: $interval (optional) - Time which may elapse (in s) between last check for content
17418: change in current course. (default: 600 s).
17419:
17420: Returns: an array; first element is:
17421:
17422: =over 4
17423:
17424: 'switch' - if content updates mean user's session
17425: needs to be switched to a server running a newer LON-CAPA version
17426:
17427: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
17428: on current server hosting user's session
17429:
17430: '' - if no action required.
17431:
17432: =back
17433:
17434: If first item element is 'switch':
17435:
17436: second item is $switchwarning - Warning message if no suitable server found to host session.
17437:
17438: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
17439: and current role.
17440:
17441: otherwise: no other elements returned.
17442:
17443: =back
17444:
17445: =cut
17446:
17447: sub needs_coursereinit {
17448: my ($loncaparev,$interval) = @_;
17449: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17450: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17451: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17452: my $now = time;
17453: if ($interval eq '') {
17454: $interval = 600;
17455: }
17456: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 17457: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1283 raeburn 17458: my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1);
1.1282 raeburn 17459: if ($blocked) {
17460: return ();
17461: }
1.1207 raeburn 17462: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17463: if ($lastchange > $env{'request.course.tied'}) {
17464: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17465: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17466: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17467: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17468: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17469: $curr_reqd_hash{'internal.releaserequired'}});
17470: my ($switchserver,$switchwarning) =
17471: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17472: $curr_reqd_hash{'internal.releaserequired'});
17473: if ($switchwarning ne '' || $switchserver ne '') {
17474: return ('switch',$switchwarning,$switchserver);
17475: }
17476: }
17477: }
17478: return ('update');
17479: }
17480: }
17481: return ();
17482: }
1.1181 raeburn 17483:
1.1083 raeburn 17484: sub update_content_constraints {
17485: my ($cdom,$cnum,$chome,$cid) = @_;
17486: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17487: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 17488: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 17489: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 17490: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 17491: if ($item eq 'resourcetag') {
17492: if ($name eq 'responsetype') {
17493: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17494: }
1.1307 raeburn 17495: } elsif ($item eq 'course') {
17496: if ($name eq 'courserestype') {
17497: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
17498: }
1.1083 raeburn 17499: }
17500: }
17501: my $navmap = Apache::lonnavmaps::navmap->new();
17502: if (defined($navmap)) {
1.1307 raeburn 17503: my (%allresponses,%allcrsrestypes);
17504: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
17505: if ($res->is_tool()) {
17506: if ($allcrsrestypes{'exttool'}) {
17507: $allcrsrestypes{'exttool'} ++;
17508: } else {
17509: $allcrsrestypes{'exttool'} = 1;
17510: }
17511: next;
17512: }
1.1083 raeburn 17513: my %responses = $res->responseTypes();
17514: foreach my $key (keys(%responses)) {
17515: next unless(exists($checkresponsetypes{$key}));
17516: $allresponses{$key} += $responses{$key};
17517: }
17518: }
17519: foreach my $key (keys(%allresponses)) {
17520: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17521: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17522: ($reqdmajor,$reqdminor) = ($major,$minor);
17523: }
17524: }
1.1307 raeburn 17525: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 17526: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 17527: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17528: ($reqdmajor,$reqdminor) = ($major,$minor);
17529: }
17530: }
1.1083 raeburn 17531: undef($navmap);
17532: }
1.1308 raeburn 17533: my $suppmap = 'supplemental.sequence';
17534: my ($suppcount,$supptools,$errors) = (0,0,0);
17535: ($suppcount,$supptools,$errors) = &recurse_supplemental($cnum,$cdom,$suppmap,
17536: $suppcount,$supptools,$errors);
17537: if ($supptools) {
17538: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
17539: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17540: ($reqdmajor,$reqdminor) = ($major,$minor);
17541: }
17542: }
1.1083 raeburn 17543: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17544: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17545: }
17546: return;
17547: }
17548:
1.1110 raeburn 17549: sub allmaps_incourse {
17550: my ($cdom,$cnum,$chome,$cid) = @_;
17551: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17552: $cid = $env{'request.course.id'};
17553: $cdom = $env{'course.'.$cid.'.domain'};
17554: $cnum = $env{'course.'.$cid.'.num'};
17555: $chome = $env{'course.'.$cid.'.home'};
17556: }
17557: my %allmaps = ();
17558: my $lastchange =
17559: &Apache::lonnet::get_coursechange($cdom,$cnum);
17560: if ($lastchange > $env{'request.course.tied'}) {
17561: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17562: unless ($ferr) {
17563: &update_content_constraints($cdom,$cnum,$chome,$cid);
17564: }
17565: }
17566: my $navmap = Apache::lonnavmaps::navmap->new();
17567: if (defined($navmap)) {
17568: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17569: $allmaps{$res->src()} = 1;
17570: }
17571: }
17572: return \%allmaps;
17573: }
17574:
1.1083 raeburn 17575: sub parse_supplemental_title {
17576: my ($title) = @_;
17577:
17578: my ($foldertitle,$renametitle);
17579: if ($title =~ /&&&/) {
17580: $title = &HTML::Entites::decode($title);
17581: }
17582: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17583: $renametitle=$4;
17584: my ($time,$uname,$udom) = ($1,$2,$3);
17585: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17586: my $name = &plainname($uname,$udom);
17587: $name = &HTML::Entities::encode($name,'"<>&\'');
17588: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17589: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17590: $name.': <br />'.$foldertitle;
17591: }
17592: if (wantarray) {
17593: return ($title,$foldertitle,$renametitle);
17594: }
17595: return $title;
17596: }
17597:
1.1143 raeburn 17598: sub recurse_supplemental {
1.1308 raeburn 17599: my ($cnum,$cdom,$suppmap,$numfiles,$numexttools,$errors) = @_;
1.1143 raeburn 17600: if ($suppmap) {
17601: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17602: if ($fatal) {
17603: $errors ++;
17604: } else {
17605: if ($#LONCAPA::map::resources > 0) {
17606: foreach my $res (@LONCAPA::map::resources) {
17607: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17608: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 17609: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1308 raeburn 17610: ($numfiles,$numexttools,$errors) = &recurse_supplemental($cnum,$cdom,$1,
17611: $numfiles,$numexttools,$errors);
1.1143 raeburn 17612: } else {
1.1308 raeburn 17613: if ($src =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
17614: $numexttools ++;
17615: }
1.1143 raeburn 17616: $numfiles ++;
17617: }
17618: }
17619: }
17620: }
17621: }
17622: }
1.1308 raeburn 17623: return ($numfiles,$numexttools,$errors);
1.1143 raeburn 17624: }
17625:
1.1101 raeburn 17626: sub symb_to_docspath {
1.1267 raeburn 17627: my ($symb,$navmapref) = @_;
17628: return unless ($symb && ref($navmapref));
1.1101 raeburn 17629: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17630: if ($resurl=~/\.(sequence|page)$/) {
17631: $mapurl=$resurl;
17632: } elsif ($resurl eq 'adm/navmaps') {
17633: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17634: }
17635: my $mapresobj;
1.1267 raeburn 17636: unless (ref($$navmapref)) {
17637: $$navmapref = Apache::lonnavmaps::navmap->new();
17638: }
17639: if (ref($$navmapref)) {
17640: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 17641: }
17642: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17643: my $type=$2;
17644: my $path;
17645: if (ref($mapresobj)) {
17646: my $pcslist = $mapresobj->map_hierarchy();
17647: if ($pcslist ne '') {
17648: foreach my $pc (split(/,/,$pcslist)) {
17649: next if ($pc <= 1);
1.1267 raeburn 17650: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 17651: if (ref($res)) {
17652: my $thisurl = $res->src();
17653: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17654: my $thistitle = $res->title();
17655: $path .= '&'.
17656: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 17657: &escape($thistitle).
1.1101 raeburn 17658: ':'.$res->randompick().
17659: ':'.$res->randomout().
17660: ':'.$res->encrypted().
17661: ':'.$res->randomorder().
17662: ':'.$res->is_page();
17663: }
17664: }
17665: }
17666: $path =~ s/^\&//;
17667: my $maptitle = $mapresobj->title();
17668: if ($mapurl eq 'default') {
1.1129 raeburn 17669: $maptitle = 'Main Content';
1.1101 raeburn 17670: }
17671: $path .= (($path ne '')? '&' : '').
17672: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17673: &escape($maptitle).
1.1101 raeburn 17674: ':'.$mapresobj->randompick().
17675: ':'.$mapresobj->randomout().
17676: ':'.$mapresobj->encrypted().
17677: ':'.$mapresobj->randomorder().
17678: ':'.$mapresobj->is_page();
17679: } else {
17680: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17681: my $ispage = (($type eq 'page')? 1 : '');
17682: if ($mapurl eq 'default') {
1.1129 raeburn 17683: $maptitle = 'Main Content';
1.1101 raeburn 17684: }
17685: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17686: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 17687: }
17688: unless ($mapurl eq 'default') {
17689: $path = 'default&'.
1.1146 raeburn 17690: &escape('Main Content').
1.1101 raeburn 17691: ':::::&'.$path;
17692: }
17693: return $path;
17694: }
17695:
1.1094 raeburn 17696: sub captcha_display {
17697: my ($context,$lonhost) = @_;
17698: my ($output,$error);
1.1234 raeburn 17699: my ($captcha,$pubkey,$privkey,$version) =
17700: &get_captcha_config($context,$lonhost);
1.1095 raeburn 17701: if ($captcha eq 'original') {
1.1094 raeburn 17702: $output = &create_captcha();
17703: unless ($output) {
1.1172 raeburn 17704: $error = 'captcha';
1.1094 raeburn 17705: }
17706: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17707: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 17708: unless ($output) {
1.1172 raeburn 17709: $error = 'recaptcha';
1.1094 raeburn 17710: }
17711: }
1.1234 raeburn 17712: return ($output,$error,$captcha,$version);
1.1094 raeburn 17713: }
17714:
17715: sub captcha_response {
17716: my ($context,$lonhost) = @_;
17717: my ($captcha_chk,$captcha_error);
1.1234 raeburn 17718: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 17719: if ($captcha eq 'original') {
1.1094 raeburn 17720: ($captcha_chk,$captcha_error) = &check_captcha();
17721: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17722: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 17723: } else {
17724: $captcha_chk = 1;
17725: }
17726: return ($captcha_chk,$captcha_error);
17727: }
17728:
17729: sub get_captcha_config {
17730: my ($context,$lonhost) = @_;
1.1234 raeburn 17731: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 17732: my $hostname = &Apache::lonnet::hostname($lonhost);
17733: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17734: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 17735: if ($context eq 'usercreation') {
17736: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17737: if (ref($domconfig{$context}) eq 'HASH') {
17738: $hashtocheck = $domconfig{$context}{'cancreate'};
17739: if (ref($hashtocheck) eq 'HASH') {
17740: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17741: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17742: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17743: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17744: }
17745: if ($privkey && $pubkey) {
17746: $captcha = 'recaptcha';
1.1234 raeburn 17747: $version = $hashtocheck->{'recaptchaversion'};
17748: if ($version ne '2') {
17749: $version = 1;
17750: }
1.1095 raeburn 17751: } else {
17752: $captcha = 'original';
17753: }
17754: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17755: $captcha = 'original';
17756: }
1.1094 raeburn 17757: }
1.1095 raeburn 17758: } else {
17759: $captcha = 'captcha';
17760: }
17761: } elsif ($context eq 'login') {
17762: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17763: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17764: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17765: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 17766: if ($privkey && $pubkey) {
17767: $captcha = 'recaptcha';
1.1234 raeburn 17768: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17769: if ($version ne '2') {
17770: $version = 1;
17771: }
1.1095 raeburn 17772: } else {
17773: $captcha = 'original';
1.1094 raeburn 17774: }
1.1095 raeburn 17775: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17776: $captcha = 'original';
1.1094 raeburn 17777: }
17778: }
1.1234 raeburn 17779: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 17780: }
17781:
17782: sub create_captcha {
17783: my %captcha_params = &captcha_settings();
17784: my ($output,$maxtries,$tries) = ('',10,0);
17785: while ($tries < $maxtries) {
17786: $tries ++;
17787: my $captcha = Authen::Captcha->new (
17788: output_folder => $captcha_params{'output_dir'},
17789: data_folder => $captcha_params{'db_dir'},
17790: );
17791: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17792:
17793: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17794: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17795: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 17796: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17797: '<br />'.
17798: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 17799: last;
17800: }
17801: }
17802: return $output;
17803: }
17804:
17805: sub captcha_settings {
17806: my %captcha_params = (
17807: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17808: www_output_dir => "/captchaspool",
17809: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17810: numchars => '5',
17811: );
17812: return %captcha_params;
17813: }
17814:
17815: sub check_captcha {
17816: my ($captcha_chk,$captcha_error);
17817: my $code = $env{'form.code'};
17818: my $md5sum = $env{'form.crypt'};
17819: my %captcha_params = &captcha_settings();
17820: my $captcha = Authen::Captcha->new(
17821: output_folder => $captcha_params{'output_dir'},
17822: data_folder => $captcha_params{'db_dir'},
17823: );
1.1109 raeburn 17824: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 17825: my %captcha_hash = (
17826: 0 => 'Code not checked (file error)',
17827: -1 => 'Failed: code expired',
17828: -2 => 'Failed: invalid code (not in database)',
17829: -3 => 'Failed: invalid code (code does not match crypt)',
17830: );
17831: if ($captcha_chk != 1) {
17832: $captcha_error = $captcha_hash{$captcha_chk}
17833: }
17834: return ($captcha_chk,$captcha_error);
17835: }
17836:
17837: sub create_recaptcha {
1.1234 raeburn 17838: my ($pubkey,$version) = @_;
17839: if ($version >= 2) {
17840: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17841: } else {
17842: my $use_ssl;
17843: if ($ENV{'SERVER_PORT'} == 443) {
17844: $use_ssl = 1;
17845: }
17846: my $captcha = Captcha::reCAPTCHA->new;
17847: return $captcha->get_options_setter({theme => 'white'})."\n".
17848: $captcha->get_html($pubkey,undef,$use_ssl).
17849: &mt('If the text is hard to read, [_1] will replace them.',
17850: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17851: '<br /><br />';
17852: }
1.1094 raeburn 17853: }
17854:
17855: sub check_recaptcha {
1.1234 raeburn 17856: my ($privkey,$version) = @_;
1.1094 raeburn 17857: my $captcha_chk;
1.1234 raeburn 17858: if ($version >= 2) {
17859: my %info = (
17860: secret => $privkey,
17861: response => $env{'form.g-recaptcha-response'},
17862: remoteip => $ENV{'REMOTE_ADDR'},
17863: );
1.1280 raeburn 17864: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
17865: $request->content(join('&',map {
17866: my $name = escape($_);
17867: "$name=" . ( ref($info{$_}) eq 'ARRAY'
17868: ? join("&$name=", map {escape($_) } @{$info{$_}})
17869: : &escape($info{$_}) );
17870: } keys(%info)));
17871: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 17872: if ($response->is_success) {
17873: my $data = JSON::DWIW->from_json($response->decoded_content);
17874: if (ref($data) eq 'HASH') {
17875: if ($data->{'success'}) {
17876: $captcha_chk = 1;
17877: }
17878: }
17879: }
17880: } else {
17881: my $captcha = Captcha::reCAPTCHA->new;
17882: my $captcha_result =
17883: $captcha->check_answer(
17884: $privkey,
17885: $ENV{'REMOTE_ADDR'},
17886: $env{'form.recaptcha_challenge_field'},
17887: $env{'form.recaptcha_response_field'},
17888: );
17889: if ($captcha_result->{is_valid}) {
17890: $captcha_chk = 1;
17891: }
1.1094 raeburn 17892: }
17893: return $captcha_chk;
17894: }
17895:
1.1174 raeburn 17896: sub emailusername_info {
1.1244 raeburn 17897: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 17898: my %titles = &Apache::lonlocal::texthash (
17899: lastname => 'Last Name',
17900: firstname => 'First Name',
17901: institution => 'School/college/university',
17902: location => "School's city, state/province, country",
17903: web => "School's web address",
17904: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 17905: id => 'Student/Employee ID',
1.1174 raeburn 17906: );
17907: return (\@fields,\%titles);
17908: }
17909:
1.1161 raeburn 17910: sub cleanup_html {
17911: my ($incoming) = @_;
17912: my $outgoing;
17913: if ($incoming ne '') {
17914: $outgoing = $incoming;
17915: $outgoing =~ s/;/;/g;
17916: $outgoing =~ s/\#/#/g;
17917: $outgoing =~ s/\&/&/g;
17918: $outgoing =~ s/</</g;
17919: $outgoing =~ s/>/>/g;
17920: $outgoing =~ s/\(/(/g;
17921: $outgoing =~ s/\)/)/g;
17922: $outgoing =~ s/"/"/g;
17923: $outgoing =~ s/'/'/g;
17924: $outgoing =~ s/\$/$/g;
17925: $outgoing =~ s{/}{/}g;
17926: $outgoing =~ s/=/=/g;
17927: $outgoing =~ s/\\/\/g
17928: }
17929: return $outgoing;
17930: }
17931:
1.1190 musolffc 17932: # Checks for critical messages and returns a redirect url if one exists.
17933: # $interval indicates how often to check for messages.
1.1282 raeburn 17934: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 17935: sub critical_redirect {
1.1282 raeburn 17936: my ($interval,$context) = @_;
1.1190 musolffc 17937: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 17938: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
17939: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17940: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17941: my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
17942: if ($blocked) {
17943: my $checkrole = "cm./$cdom/$cnum";
17944: if ($env{'request.course.sec'} ne '') {
17945: $checkrole .= "/$env{'request.course.sec'}";
17946: }
17947: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
17948: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
17949: return;
17950: }
17951: }
17952: }
1.1190 musolffc 17953: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17954: $env{'user.name'});
17955: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 17956: my $redirecturl;
1.1190 musolffc 17957: if ($what[0]) {
17958: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17959: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 17960: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17961: return (1, $url);
1.1190 musolffc 17962: }
1.1191 raeburn 17963: }
17964: }
17965: return ();
1.1190 musolffc 17966: }
17967:
1.1174 raeburn 17968: # Use:
17969: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17970: #
17971: ##################################################
17972: # password associated functions #
17973: ##################################################
17974: sub des_keys {
17975: # Make a new key for DES encryption.
17976: # Each key has two parts which are returned separately.
17977: # Please note: Each key must be passed through the &hex function
17978: # before it is output to the web browser. The hex versions cannot
17979: # be used to decrypt.
17980: my @hexstr=('0','1','2','3','4','5','6','7',
17981: '8','9','a','b','c','d','e','f');
17982: my $lkey='';
17983: for (0..7) {
17984: $lkey.=$hexstr[rand(15)];
17985: }
17986: my $ukey='';
17987: for (0..7) {
17988: $ukey.=$hexstr[rand(15)];
17989: }
17990: return ($lkey,$ukey);
17991: }
17992:
17993: sub des_decrypt {
17994: my ($key,$cyphertext) = @_;
17995: my $keybin=pack("H16",$key);
17996: my $cypher;
17997: if ($Crypt::DES::VERSION>=2.03) {
17998: $cypher=new Crypt::DES $keybin;
17999: } else {
18000: $cypher=new DES $keybin;
18001: }
1.1233 raeburn 18002: my $plaintext='';
18003: my $cypherlength = length($cyphertext);
18004: my $numchunks = int($cypherlength/32);
18005: for (my $j=0; $j<$numchunks; $j++) {
18006: my $start = $j*32;
18007: my $cypherblock = substr($cyphertext,$start,32);
18008: my $chunk =
18009: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
18010: $chunk .=
18011: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
18012: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
18013: $plaintext .= $chunk;
18014: }
1.1174 raeburn 18015: return $plaintext;
18016: }
18017:
1.1309 raeburn 18018: sub make_short_symbs {
18019: my ($cdom,$cnum,$navmap) = @_;
18020: return unless (ref($navmap));
18021: my ($numnew,@errors);
18022: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
18023: if (@toshorten) {
18024: my (%maps,%resources,%titles);
18025: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
18026: 'shorturls',$cdom,$cnum);
18027: my %tocreate;
18028: if (keys(%resources)) {
18029: foreach my $item (sort {$a <=> $b} (@toshorten)) {
18030: my $symb = $resources{$item};
18031: if ($symb) {
18032: $tocreate{$cnum.'&'.$symb} = 1;
18033: }
18034: }
18035: }
18036: if (keys(%tocreate)) {
18037: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
18038: my $su = Short::URL->new(no_vowels => 1);
18039: my $init = '';
18040: my (%newunique,%addcourse,%courseonly,%failed);
18041: # get lock on tiny db
18042: my $now = time;
18043: my $lockhash = {
18044: "lock\0$now" => $env{'user.name'}.
18045: ':'.$env{'user.domain'},
18046: };
18047: my $tries = 0;
18048: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
18049: my ($code,$error);
18050: while (($gotlock ne 'ok') && ($tries<3)) {
18051: $tries ++;
18052: sleep 1;
1.1319 raeburn 18053: $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
1.1309 raeburn 18054: }
18055: if ($gotlock eq 'ok') {
18056: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
18057: \%addcourse,\%courseonly,\%failed);
18058: if (keys(%failed)) {
18059: my $numfailed = scalar(keys(%failed));
18060: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
18061: }
18062: if (keys(%newunique)) {
18063: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
18064: if ($putres eq 'ok') {
18065: $numnew = scalar(keys(%newunique));
18066: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
18067: unless ($newputres eq 'ok') {
18068: push(@errors,&mt('error: could not store course look-up of short URLs'));
18069: }
18070: } else {
18071: push(@errors,&mt('error: could not store unique six character URLs'));
18072: }
18073: }
18074: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
18075: unless ($dellockres eq 'ok') {
18076: push(@errors,&mt('error: could not release lockfile'));
18077: }
18078: } else {
18079: push(@errors,&mt('error: could not obtain lockfile'));
18080: }
18081: if (keys(%courseonly)) {
18082: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
18083: if ($result ne 'ok') {
18084: push(@errors,&mt('error: could not update course look-up of short URLs'));
18085: }
18086: }
18087: }
18088: }
18089: return ($numnew,\@errors);
18090: }
18091:
18092: sub shorten_symbs {
18093: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
18094: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
18095: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
18096: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
18097: my (%possibles,%collisions);
18098: foreach my $key (keys(%{$tocreate})) {
18099: my $num = String::CRC32::crc32($key);
18100: my $tiny = $su->encode($num,$init);
18101: if ($tiny) {
18102: $possibles{$tiny} = $key;
18103: }
18104: }
18105: if (!$init) {
18106: $init = 1;
18107: } else {
18108: $init ++;
18109: }
18110: if (keys(%possibles)) {
18111: my @posstiny = keys(%possibles);
18112: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18113: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18114: if (keys(%currtiny)) {
18115: foreach my $key (keys(%currtiny)) {
18116: next if ($currtiny{$key} eq '');
18117: if ($currtiny{$key} eq $possibles{$key}) {
18118: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18119: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18120: $courseonly->{$tsymb} = $key;
18121: }
18122: } else {
18123: $collisions{$possibles{$key}} = 1;
18124: }
18125: delete($possibles{$key});
18126: }
18127: }
18128: foreach my $key (keys(%possibles)) {
18129: $newunique->{$key} = $possibles{$key};
18130: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18131: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18132: $addcourse->{$tsymb} = $key;
18133: }
18134: }
18135: }
18136: if (keys(%collisions)) {
18137: if ($init <5) {
18138: if (!$init) {
18139: $init = 1;
18140: } else {
18141: $init ++;
18142: }
18143: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
18144: $newunique,$addcourse,$courseonly,$failed);
18145: } else {
18146: foreach my $key (keys(%collisions)) {
18147: $failed->{$key} = 1;
18148: }
18149: }
18150: }
18151: return $init;
18152: }
18153:
1.112 bowersj2 18154: 1;
18155: __END__;
1.41 ng 18156:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>