Annotation of loncom/interface/loncommon.pm, revision 1.1311
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1311 ! raeburn 4: # $Id: loncommon.pm,v 1.1310 2018/03/23 01:01:21 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';
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';
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';
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';
256: if ( open (my $fh,"<$designfile") ) {
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';
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';
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.755 neumanie 1300: if ($text ne "") {
1.763 bisitz 1301: $template.='<span class="LC_help_open_topic">'
1302: .'<a target="_top" href="'.$link.'">'
1303: .$text.'</a>';
1.48 bowersj2 1304: }
1305:
1.763 bisitz 1306: # (Always) Add the graphic
1.179 matthew 1307: my $title = &mt('Online Help');
1.667 raeburn 1308: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1309: if ($imgid ne '') {
1310: $imgid = ' id="'.$imgid.'"';
1311: }
1.763 bisitz 1312: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1313: .'<img src="'.$helpicon.'" border="0"'
1314: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1315: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1316: .' /></a>';
1317: if ($text ne "") {
1318: $template.='</span>';
1319: }
1.44 bowersj2 1320: return $template;
1321:
1.106 bowersj2 1322: }
1323:
1324: # This is a quicky function for Latex cheatsheet editing, since it
1325: # appears in at least four places
1326: sub helpLatexCheatsheet {
1.1037 www 1327: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1328: my $out;
1.106 bowersj2 1329: my $addOther = '';
1.732 raeburn 1330: if ($topic) {
1.1037 www 1331: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1332: }
1333: $out = '<span>' # Start cheatsheet
1334: .$addOther
1335: .'<span>'
1.1037 www 1336: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1337: .'</span> <span>'
1.1037 www 1338: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1339: .'</span>';
1.732 raeburn 1340: unless ($not_author) {
1.1186 kruse 1341: $out .= '<span>'
1342: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1343: .'</span> <span>'
1344: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1345: .'</span>';
1.732 raeburn 1346: }
1.763 bisitz 1347: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1348: return $out;
1.172 www 1349: }
1350:
1.430 albertel 1351: sub general_help {
1352: my $helptopic='Student_Intro';
1353: if ($env{'request.role'}=~/^(ca|au)/) {
1354: $helptopic='Authoring_Intro';
1.907 raeburn 1355: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1356: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1357: } elsif ($env{'request.role'}=~/^dc/) {
1358: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1359: }
1360: return $helptopic;
1361: }
1362:
1363: sub update_help_link {
1364: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1365: my $origurl = $ENV{'REQUEST_URI'};
1366: $origurl=~s|^/~|/priv/|;
1367: my $timestamp = time;
1368: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1369: $$datum = &escape($$datum);
1370: }
1371:
1372: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1373: my $output .= <<"ENDOUTPUT";
1374: <script type="text/javascript">
1.824 bisitz 1375: // <![CDATA[
1.430 albertel 1376: banner_link = '$banner_link';
1.824 bisitz 1377: // ]]>
1.430 albertel 1378: </script>
1379: ENDOUTPUT
1380: return $output;
1381: }
1382:
1383: # now just updates the help link and generates a blue icon
1.193 raeburn 1384: sub help_open_menu {
1.430 albertel 1385: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1386: = @_;
1.949 droeschl 1387: $stayOnPage = 1;
1.430 albertel 1388: my $output;
1389: if ($component_help) {
1390: if (!$text) {
1391: $output=&help_open_topic($component_help,undef,$stayOnPage,
1392: $width,$height);
1393: } else {
1394: my $help_text;
1395: $help_text=&unescape($topic);
1396: $output='<table><tr><td>'.
1397: &help_open_topic($component_help,$help_text,$stayOnPage,
1398: $width,$height).'</td></tr></table>';
1399: }
1400: }
1401: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1402: return $output.$banner_link;
1403: }
1404:
1405: sub top_nav_help {
1406: my ($text) = @_;
1.436 albertel 1407: $text = &mt($text);
1.949 droeschl 1408: my $stay_on_page = 1;
1409:
1.1168 raeburn 1410: my ($link,$banner_link);
1411: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1412: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1413: : "javascript:helpMenu('open')";
1414: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1415: }
1.201 raeburn 1416: my $title = &mt('Get help');
1.1168 raeburn 1417: if ($link) {
1418: return <<"END";
1.436 albertel 1419: $banner_link
1.1159 raeburn 1420: <a href="$link" title="$title">$text</a>
1.436 albertel 1421: END
1.1168 raeburn 1422: } else {
1423: return ' '.$text.' ';
1424: }
1.436 albertel 1425: }
1426:
1427: sub help_menu_js {
1.1154 raeburn 1428: my ($httphost) = @_;
1.949 droeschl 1429: my $stayOnPage = 1;
1.436 albertel 1430: my $width = 620;
1431: my $height = 600;
1.430 albertel 1432: my $helptopic=&general_help();
1.1154 raeburn 1433: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1434: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1435: my $start_page =
1436: &Apache::loncommon::start_page('Help Menu', undef,
1437: {'frameset' => 1,
1438: 'js_ready' => 1,
1.1154 raeburn 1439: 'use_absolute' => $httphost,
1.331 albertel 1440: 'add_entries' => {
1.1168 raeburn 1441: 'border' => '0',
1.579 raeburn 1442: 'rows' => "110,*",},});
1.331 albertel 1443: my $end_page =
1444: &Apache::loncommon::end_page({'frameset' => 1,
1445: 'js_ready' => 1,});
1446:
1.436 albertel 1447: my $template .= <<"ENDTEMPLATE";
1448: <script type="text/javascript">
1.877 bisitz 1449: // <![CDATA[
1.253 albertel 1450: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1451: var banner_link = '';
1.243 raeburn 1452: function helpMenu(target) {
1453: var caller = this;
1454: if (target == 'open') {
1455: var newWindow = null;
1456: try {
1.262 albertel 1457: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1458: }
1459: catch(error) {
1460: writeHelp(caller);
1461: return;
1462: }
1463: if (newWindow) {
1464: caller = newWindow;
1465: }
1.193 raeburn 1466: }
1.243 raeburn 1467: writeHelp(caller);
1468: return;
1469: }
1470: function writeHelp(caller) {
1.1168 raeburn 1471: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1472: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1473: caller.document.close();
1474: caller.focus();
1.193 raeburn 1475: }
1.877 bisitz 1476: // END LON-CAPA Internal -->
1.253 albertel 1477: // ]]>
1.436 albertel 1478: </script>
1.193 raeburn 1479: ENDTEMPLATE
1480: return $template;
1481: }
1482:
1.172 www 1483: sub help_open_bug {
1484: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1485: unless ($env{'user.adv'}) { return ''; }
1.172 www 1486: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1487: $text = "" if (not defined $text);
1488: $stayOnPage=1;
1.184 albertel 1489: $width = 600 if (not defined $width);
1490: $height = 600 if (not defined $height);
1.172 www 1491:
1492: $topic=~s/\W+/\+/g;
1493: my $link='';
1494: my $template='';
1.379 albertel 1495: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1496: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1497: if (!$stayOnPage)
1498: {
1499: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1500: }
1501: else
1502: {
1503: $link = $url;
1504: }
1505: # Add the text
1506: if ($text ne "")
1507: {
1508: $template .=
1509: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1510: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1511: }
1512:
1513: # Add the graphic
1.179 matthew 1514: my $title = &mt('Report a Bug');
1.215 albertel 1515: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1516: $template .= <<"ENDTEMPLATE";
1.436 albertel 1517: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1518: ENDTEMPLATE
1519: if ($text ne '') { $template.='</td></tr></table>' };
1520: return $template;
1521:
1522: }
1523:
1524: sub help_open_faq {
1525: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1526: unless ($env{'user.adv'}) { return ''; }
1.172 www 1527: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1528: $text = "" if (not defined $text);
1529: $stayOnPage=1;
1530: $width = 350 if (not defined $width);
1531: $height = 400 if (not defined $height);
1532:
1533: $topic=~s/\W+/\+/g;
1534: my $link='';
1535: my $template='';
1536: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1537: if (!$stayOnPage)
1538: {
1539: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1540: }
1541: else
1542: {
1543: $link = $url;
1544: }
1545:
1546: # Add the text
1547: if ($text ne "")
1548: {
1549: $template .=
1.173 www 1550: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1551: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1552: }
1553:
1554: # Add the graphic
1.179 matthew 1555: my $title = &mt('View the FAQ');
1.215 albertel 1556: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1557: $template .= <<"ENDTEMPLATE";
1.436 albertel 1558: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1559: ENDTEMPLATE
1560: if ($text ne '') { $template.='</td></tr></table>' };
1561: return $template;
1562:
1.44 bowersj2 1563: }
1.37 matthew 1564:
1.180 matthew 1565: ###############################################################
1566: ###############################################################
1567:
1.45 matthew 1568: =pod
1569:
1.648 raeburn 1570: =item * &change_content_javascript():
1.256 matthew 1571:
1572: This and the next function allow you to create small sections of an
1573: otherwise static HTML page that you can update on the fly with
1574: Javascript, even in Netscape 4.
1575:
1576: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1577: must be written to the HTML page once. It will prove the Javascript
1578: function "change(name, content)". Calling the change function with the
1579: name of the section
1580: you want to update, matching the name passed to C<changable_area>, and
1581: the new content you want to put in there, will put the content into
1582: that area.
1583:
1584: B<Note>: Netscape 4 only reserves enough space for the changable area
1585: to contain room for the original contents. You need to "make space"
1586: for whatever changes you wish to make, and be B<sure> to check your
1587: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1588: it's adequate for updating a one-line status display, but little more.
1589: This script will set the space to 100% width, so you only need to
1590: worry about height in Netscape 4.
1591:
1592: Modern browsers are much less limiting, and if you can commit to the
1593: user not using Netscape 4, this feature may be used freely with
1594: pretty much any HTML.
1595:
1596: =cut
1597:
1598: sub change_content_javascript {
1599: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1600: if ($env{'browser.type'} eq 'netscape' &&
1601: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1602: return (<<NETSCAPE4);
1603: function change(name, content) {
1604: doc = document.layers[name+"___escape"].layers[0].document;
1605: doc.open();
1606: doc.write(content);
1607: doc.close();
1608: }
1609: NETSCAPE4
1610: } else {
1611: # Otherwise, we need to use semi-standards-compliant code
1612: # (technically, "innerHTML" isn't standard but the equivalent
1613: # is really scary, and every useful browser supports it
1614: return (<<DOMBASED);
1615: function change(name, content) {
1616: element = document.getElementById(name);
1617: element.innerHTML = content;
1618: }
1619: DOMBASED
1620: }
1621: }
1622:
1623: =pod
1624:
1.648 raeburn 1625: =item * &changable_area($name,$origContent):
1.256 matthew 1626:
1627: This provides a "changable area" that can be modified on the fly via
1628: the Javascript code provided in C<change_content_javascript>. $name is
1629: the name you will use to reference the area later; do not repeat the
1630: same name on a given HTML page more then once. $origContent is what
1631: the area will originally contain, which can be left blank.
1632:
1633: =cut
1634:
1635: sub changable_area {
1636: my ($name, $origContent) = @_;
1637:
1.258 albertel 1638: if ($env{'browser.type'} eq 'netscape' &&
1639: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1640: # If this is netscape 4, we need to use the Layer tag
1641: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1642: } else {
1643: return "<span id='$name'>$origContent</span>";
1644: }
1645: }
1646:
1647: =pod
1648:
1.648 raeburn 1649: =item * &viewport_geometry_js
1.590 raeburn 1650:
1651: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1652:
1653: =cut
1654:
1655:
1656: sub viewport_geometry_js {
1657: return <<"GEOMETRY";
1658: var Geometry = {};
1659: function init_geometry() {
1660: if (Geometry.init) { return };
1661: Geometry.init=1;
1662: if (window.innerHeight) {
1663: Geometry.getViewportHeight = function() { return window.innerHeight; };
1664: Geometry.getViewportWidth = function() { return window.innerWidth; };
1665: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1666: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1667: }
1668: else if (document.documentElement && document.documentElement.clientHeight) {
1669: Geometry.getViewportHeight =
1670: function() { return document.documentElement.clientHeight; };
1671: Geometry.getViewportWidth =
1672: function() { return document.documentElement.clientWidth; };
1673:
1674: Geometry.getHorizontalScroll =
1675: function() { return document.documentElement.scrollLeft; };
1676: Geometry.getVerticalScroll =
1677: function() { return document.documentElement.scrollTop; };
1678: }
1679: else if (document.body.clientHeight) {
1680: Geometry.getViewportHeight =
1681: function() { return document.body.clientHeight; };
1682: Geometry.getViewportWidth =
1683: function() { return document.body.clientWidth; };
1684: Geometry.getHorizontalScroll =
1685: function() { return document.body.scrollLeft; };
1686: Geometry.getVerticalScroll =
1687: function() { return document.body.scrollTop; };
1688: }
1689: }
1690:
1691: GEOMETRY
1692: }
1693:
1694: =pod
1695:
1.648 raeburn 1696: =item * &viewport_size_js()
1.590 raeburn 1697:
1698: 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.
1699:
1700: =cut
1701:
1702: sub viewport_size_js {
1703: my $geometry = &viewport_geometry_js();
1704: return <<"DIMS";
1705:
1706: $geometry
1707:
1708: function getViewportDims(width,height) {
1709: init_geometry();
1710: width.value = Geometry.getViewportWidth();
1711: height.value = Geometry.getViewportHeight();
1712: return;
1713: }
1714:
1715: DIMS
1716: }
1717:
1718: =pod
1719:
1.648 raeburn 1720: =item * &resize_textarea_js()
1.565 albertel 1721:
1722: emits the needed javascript to resize a textarea to be as big as possible
1723:
1724: creates a function resize_textrea that takes two IDs first should be
1725: the id of the element to resize, second should be the id of a div that
1726: surrounds everything that comes after the textarea, this routine needs
1727: to be attached to the <body> for the onload and onresize events.
1728:
1.648 raeburn 1729: =back
1.565 albertel 1730:
1731: =cut
1732:
1733: sub resize_textarea_js {
1.590 raeburn 1734: my $geometry = &viewport_geometry_js();
1.565 albertel 1735: return <<"RESIZE";
1736: <script type="text/javascript">
1.824 bisitz 1737: // <![CDATA[
1.590 raeburn 1738: $geometry
1.565 albertel 1739:
1.588 albertel 1740: function getX(element) {
1741: var x = 0;
1742: while (element) {
1743: x += element.offsetLeft;
1744: element = element.offsetParent;
1745: }
1746: return x;
1747: }
1748: function getY(element) {
1749: var y = 0;
1750: while (element) {
1751: y += element.offsetTop;
1752: element = element.offsetParent;
1753: }
1754: return y;
1755: }
1756:
1757:
1.565 albertel 1758: function resize_textarea(textarea_id,bottom_id) {
1759: init_geometry();
1760: var textarea = document.getElementById(textarea_id);
1761: //alert(textarea);
1762:
1.588 albertel 1763: var textarea_top = getY(textarea);
1.565 albertel 1764: var textarea_height = textarea.offsetHeight;
1765: var bottom = document.getElementById(bottom_id);
1.588 albertel 1766: var bottom_top = getY(bottom);
1.565 albertel 1767: var bottom_height = bottom.offsetHeight;
1768: var window_height = Geometry.getViewportHeight();
1.588 albertel 1769: var fudge = 23;
1.565 albertel 1770: var new_height = window_height-fudge-textarea_top-bottom_height;
1771: if (new_height < 300) {
1772: new_height = 300;
1773: }
1774: textarea.style.height=new_height+'px';
1775: }
1.824 bisitz 1776: // ]]>
1.565 albertel 1777: </script>
1778: RESIZE
1779:
1780: }
1781:
1.1205 golterma 1782: sub colorfuleditor_js {
1.1248 raeburn 1783: my $browse_or_search;
1784: my $respath;
1785: my ($cnum,$cdom) = &crsauthor_url();
1786: if ($cnum) {
1787: $respath = "/res/$cdom/$cnum/";
1788: my %js_lt = &Apache::lonlocal::texthash(
1789: sunm => 'Sub-directory name',
1790: save => 'Save page to make this permanent',
1791: );
1792: &js_escape(\%js_lt);
1793: $browse_or_search = <<"END";
1794:
1795: function toggleChooser(form,element,titleid,only,search) {
1796: var disp = 'none';
1797: if (document.getElementById('chooser_'+element)) {
1798: var curr = document.getElementById('chooser_'+element).style.display;
1799: if (curr == 'none') {
1800: disp='inline';
1801: if (form.elements['chooser_'+element].length) {
1802: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1803: form.elements['chooser_'+element][i].checked = false;
1804: }
1805: }
1806: toggleResImport(form,element);
1807: }
1808: document.getElementById('chooser_'+element).style.display = disp;
1809: }
1810: }
1811:
1812: function toggleCrsFile(form,element,numdirs) {
1813: if (document.getElementById('chooser_'+element+'_crsres')) {
1814: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1815: if (curr == 'none') {
1816: if (numdirs) {
1817: form.elements['coursepath_'+element].selectedIndex = 0;
1818: if (numdirs > 1) {
1819: window['select1'+element+'_changed']();
1820: }
1821: }
1822: }
1823: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1824:
1825: }
1826: if (document.getElementById('chooser_'+element+'_upload')) {
1827: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1828: if (document.getElementById('uploadcrsres_'+element)) {
1829: document.getElementById('uploadcrsres_'+element).value = '';
1830: }
1831: }
1832: return;
1833: }
1834:
1835: function toggleCrsUpload(form,element,numcrsdirs) {
1836: if (document.getElementById('chooser_'+element+'_crsres')) {
1837: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1838: }
1839: if (document.getElementById('chooser_'+element+'_upload')) {
1840: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1841: if (curr == 'none') {
1842: if (numcrsdirs) {
1843: form.elements['crsauthorpath_'+element].selectedIndex = 0;
1844: form.elements['newsubdir_'+element][0].checked = true;
1845: toggleNewsubdir(form,element);
1846: }
1847: }
1848: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1849: }
1850: return;
1851: }
1852:
1853: function toggleResImport(form,element) {
1854: var choices = new Array('crsres','upload');
1855: for (var i=0; i<choices.length; i++) {
1856: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1857: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1858: }
1859: }
1860: }
1861:
1862: function toggleNewsubdir(form,element) {
1863: var newsub = form.elements['newsubdir_'+element];
1864: if (newsub) {
1865: if (newsub.length) {
1866: for (var j=0; j<newsub.length; j++) {
1867: if (newsub[j].checked) {
1868: if (document.getElementById('newsubdirname_'+element)) {
1869: if (newsub[j].value == '1') {
1870: document.getElementById('newsubdirname_'+element).type = "text";
1871: if (document.getElementById('newsubdir_'+element)) {
1872: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1873: }
1874: } else {
1875: document.getElementById('newsubdirname_'+element).type = "hidden";
1876: document.getElementById('newsubdirname_'+element).value = "";
1877: document.getElementById('newsubdir_'+element).innerHTML = "";
1878: }
1879: }
1880: break;
1881: }
1882: }
1883: }
1884: }
1885: }
1886:
1887: function updateCrsFile(form,element) {
1888: var directory = form.elements['coursepath_'+element];
1889: var filename = form.elements['coursefile_'+element];
1890: var path = directory.options[directory.selectedIndex].value;
1891: var file = filename.options[filename.selectedIndex].value;
1892: form.elements[element].value = '$respath';
1893: if (path == '/') {
1894: form.elements[element].value += file;
1895: } else {
1896: form.elements[element].value += path+'/'+file;
1897: }
1898: unClean();
1899: if (document.getElementById('previewimg_'+element)) {
1900: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1901: var newsrc = document.getElementById('previewimg_'+element).src;
1902: }
1903: if (document.getElementById('showimg_'+element)) {
1904: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1905: }
1906: toggleChooser(form,element);
1907: return;
1908: }
1909:
1910: function uploadDone(suffix,name) {
1911: if (name) {
1912: document.forms["lonhomework"].elements[suffix].value = name;
1913: unClean();
1914: toggleChooser(document.forms["lonhomework"],suffix);
1915: }
1916: }
1917:
1918: \$(document).ready(function(){
1919:
1920: \$(document).delegate('form :submit', 'click', function( event ) {
1921: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
1922: var buttonId = this.id;
1923: var suffix = buttonId.toString();
1924: suffix = suffix.replace(/^crsupload_/,'');
1925: event.preventDefault();
1926: document.lonhomework.target = 'crsupload_target_'+suffix;
1927: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
1928: \$(this.form).submit();
1929: document.lonhomework.target = '';
1930: if (document.getElementById('crsuploadto_'+suffix)) {
1931: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
1932: }
1933: return false;
1934: }
1935: });
1936: });
1937: END
1938: }
1.1205 golterma 1939: return <<"COLORFULEDIT"
1940: <script type="text/javascript">
1941: // <![CDATA[>
1942: function fold_box(curDepth, lastresource){
1943:
1944: // we need a list because there can be several blocks you need to fold in one tag
1945: var block = document.getElementsByName('foldblock_'+curDepth);
1946: // but there is only one folding button per tag
1947: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1948:
1949: if(block.item(0).style.display == 'none'){
1950:
1951: foldbutton.value = '@{[&mt("Hide")]}';
1952: for (i = 0; i < block.length; i++){
1953: block.item(i).style.display = '';
1954: }
1955: }else{
1956:
1957: foldbutton.value = '@{[&mt("Show")]}';
1958: for (i = 0; i < block.length; i++){
1959: // block.item(i).style.visibility = 'collapse';
1960: block.item(i).style.display = 'none';
1961: }
1962: };
1963: saveState(lastresource);
1964: }
1965:
1966: function saveState (lastresource) {
1967:
1968: var tag_list = getTagList();
1969: if(tag_list != null){
1970: var timestamp = new Date().getTime();
1971: var key = lastresource;
1972:
1973: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1974: // starting with timestamp
1975: var value = timestamp+';';
1976:
1977: // building the list of key-value pairs
1978: for(var i = 0; i < tag_list.length; i++){
1979: value += tag_list[i]+',';
1980: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1981: }
1982:
1983: // only iterate whole storage if nothing to override
1984: if(localStorage.getItem(key) == null){
1985:
1986: // prevent storage from growing large
1987: if(localStorage.length > 50){
1988: var regex_getTimestamp = /^(?:\d)+;/;
1989: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1990: var oldest_key;
1991:
1992: for(var i = 1; i < localStorage.length; i++){
1993: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1994: oldest_key = localStorage.key(i);
1995: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1996: }
1997: }
1998: localStorage.removeItem(oldest_key);
1999: }
2000: }
2001: localStorage.setItem(key,value);
2002: }
2003: }
2004:
2005: // restore folding status of blocks (on page load)
2006: function restoreState (lastresource) {
2007: if(localStorage.getItem(lastresource) != null){
2008: var key = lastresource;
2009: var value = localStorage.getItem(key);
2010: var regex_delTimestamp = /^\d+;/;
2011:
2012: value.replace(regex_delTimestamp, '');
2013:
2014: var valueArr = value.split(';');
2015: var pairs;
2016: var elements;
2017: for (var i = 0; i < valueArr.length; i++){
2018: pairs = valueArr[i].split(',');
2019: elements = document.getElementsByName(pairs[0]);
2020:
2021: for (var j = 0; j < elements.length; j++){
2022: elements[j].style.display = pairs[1];
2023: if (pairs[1] == "none"){
2024: var regex_id = /([_\\d]+)\$/;
2025: regex_id.exec(pairs[0]);
2026: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2027: }
2028: }
2029: }
2030: }
2031: }
2032:
2033: function getTagList () {
2034:
2035: var stringToSearch = document.lonhomework.innerHTML;
2036:
2037: var ret = new Array();
2038: var regex_findBlock = /(foldblock_.*?)"/g;
2039: var tag_list = stringToSearch.match(regex_findBlock);
2040:
2041: if(tag_list != null){
2042: for(var i = 0; i < tag_list.length; i++){
2043: ret.push(tag_list[i].replace(/"/, ''));
2044: }
2045: }
2046: return ret;
2047: }
2048:
2049: function saveScrollPosition (resource) {
2050: var tag_list = getTagList();
2051:
2052: // we dont always want to jump to the first block
2053: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2054: if(\$(window).scrollTop() > 170){
2055: if(tag_list != null){
2056: var result;
2057: for(var i = 0; i < tag_list.length; i++){
2058: if(isElementInViewport(tag_list[i])){
2059: result += tag_list[i]+';';
2060: }
2061: }
2062: sessionStorage.setItem('anchor_'+resource, result);
2063: }
2064: } else {
2065: // we dont need to save zero, just delete the item to leave everything tidy
2066: sessionStorage.removeItem('anchor_'+resource);
2067: }
2068: }
2069:
2070: function restoreScrollPosition(resource){
2071:
2072: var elem = sessionStorage.getItem('anchor_'+resource);
2073: if(elem != null){
2074: var tag_list = elem.split(';');
2075: var elem_list;
2076:
2077: for(var i = 0; i < tag_list.length; i++){
2078: elem_list = document.getElementsByName(tag_list[i]);
2079:
2080: if(elem_list.length > 0){
2081: elem = elem_list[0];
2082: break;
2083: }
2084: }
2085: elem.scrollIntoView();
2086: }
2087: }
2088:
2089: function isElementInViewport(el) {
2090:
2091: // change to last element instead of first
2092: var elem = document.getElementsByName(el);
2093: var rect = elem[0].getBoundingClientRect();
2094:
2095: return (
2096: rect.top >= 0 &&
2097: rect.left >= 0 &&
2098: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2099: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2100: );
2101: }
2102:
2103: function autosize(depth){
2104: var cmInst = window['cm'+depth];
2105: var fitsizeButton = document.getElementById('fitsize'+depth);
2106:
2107: // is fixed size, switching to dynamic
2108: if (sessionStorage.getItem("autosized_"+depth) == null) {
2109: cmInst.setSize("","auto");
2110: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2111: sessionStorage.setItem("autosized_"+depth, "yes");
2112:
2113: // is dynamic size, switching to fixed
2114: } else {
2115: cmInst.setSize("","300px");
2116: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2117: sessionStorage.removeItem("autosized_"+depth);
2118: }
2119: }
2120:
1.1248 raeburn 2121: $browse_or_search
1.1205 golterma 2122:
2123: // ]]>
2124: </script>
2125: COLORFULEDIT
2126: }
2127:
2128: sub xmleditor_js {
2129: return <<XMLEDIT
2130: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2131: <script type="text/javascript">
2132: // <![CDATA[>
2133:
2134: function saveScrollPosition (resource) {
2135:
2136: var scrollPos = \$(window).scrollTop();
2137: sessionStorage.setItem(resource,scrollPos);
2138: }
2139:
2140: function restoreScrollPosition(resource){
2141:
2142: var scrollPos = sessionStorage.getItem(resource);
2143: \$(window).scrollTop(scrollPos);
2144: }
2145:
2146: // unless internet explorer
2147: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2148:
2149: \$(document).ready(function() {
2150: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2151: });
2152: }
2153:
2154: // inserts text at cursor position into codemirror (xml editor only)
2155: function insertText(text){
2156: cm.focus();
2157: var curPos = cm.getCursor();
2158: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2159: }
2160: // ]]>
2161: </script>
2162: XMLEDIT
2163: }
2164:
2165: sub insert_folding_button {
2166: my $curDepth = $Apache::lonxml::curdepth;
2167: my $lastresource = $env{'request.ambiguous'};
2168:
2169: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2170: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2171: }
2172:
1.1248 raeburn 2173: sub crsauthor_url {
2174: my ($url) = @_;
2175: if ($url eq '') {
2176: $url = $ENV{'REQUEST_URI'};
2177: }
2178: my ($cnum,$cdom);
2179: if ($env{'request.course.id'}) {
2180: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2181: if ($audom ne '' && $auname ne '') {
2182: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2183: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2184: $cnum = $auname;
2185: $cdom = $audom;
2186: }
2187: }
2188: }
2189: return ($cnum,$cdom);
2190: }
2191:
2192: sub import_crsauthor_form {
1.1265 raeburn 2193: my ($form,$firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2194: return (0) unless ($env{'request.course.id'});
2195: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2196: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2197: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2198: return (0) unless (($cnum ne '') && ($cdom ne ''));
2199: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
2200: my @ids=&Apache::lonnet::current_machine_ids();
2201: my ($output,$is_home,$relpath,%subdirs,%files,%selimport_menus);
2202:
2203: if (grep(/^\Q$crshome\E$/,@ids)) {
2204: $is_home = 1;
2205: }
2206: $relpath = "/priv/$cdom/$cnum";
2207: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$relpath,'',\%subdirs,\%files);
2208: my %lt = &Apache::lonlocal::texthash (
2209: fnam => 'Filename',
2210: dire => 'Directory',
2211: );
2212: my $numdirs = scalar(keys(%files));
2213: my (%possexts,$singledir,@singledirfiles);
2214: if ($only) {
2215: map { $possexts{$_} = 1; } split(/\s*,\s*/,$only);
2216: }
2217: my (%nonemptydirs,$possdirs);
2218: if ($numdirs > 1) {
2219: my @order;
2220: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
2221: if (ref($files{$key}) eq 'HASH') {
2222: my $shown = $key;
2223: if ($key eq '') {
2224: $shown = '/';
2225: }
2226: my @ordered = ();
2227: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$key}}))) {
2228: if ($only) {
2229: my ($ext) = ($file =~ /\.([^.]+)$/);
2230: unless ($possexts{lc($ext)}) {
2231: next;
2232: }
2233: }
2234: $selimport_menus{$key}->{'select2'}->{$file} = $file;
2235: push(@ordered,$file);
2236: }
2237: if (@ordered) {
2238: push(@order,$key);
2239: $nonemptydirs{$key} = 1;
2240: $selimport_menus{$key}->{'text'} = $shown;
2241: $selimport_menus{$key}->{'default'} = '';
2242: $selimport_menus{$key}->{'select2'}->{''} = '';
2243: $selimport_menus{$key}->{'order'} = \@ordered;
2244: }
2245: }
2246: }
2247: $possdirs = scalar(keys(%nonemptydirs));
2248: if ($possdirs > 1) {
2249: my @order = sort { lc($a) cmp lc($b) } (keys(%nonemptydirs));
2250: $output = $lt{'dire'}.
2251: &linked_select_forms($form,'<br />'.
2252: $lt{'fnam'},'',
2253: $firstselectname,$secondselectname,
2254: \%selimport_menus,\@order,
2255: $onchangefirst,'',$suffix).'<br />';
2256: } elsif ($possdirs == 1) {
2257: $singledir = (keys(%nonemptydirs))[0];
2258: if (ref($selimport_menus{$singledir}->{'order'}) eq 'ARRAY') {
2259: @singledirfiles = @{$selimport_menus{$singledir}->{'order'}};
2260: }
2261: delete($selimport_menus{$singledir});
2262: }
2263: } elsif ($numdirs == 1) {
2264: $singledir = (keys(%files))[0];
2265: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$singledir}}))) {
2266: if ($only) {
2267: my ($ext) = ($file =~ /\.([^.]+)$/);
2268: unless ($possexts{lc($ext)}) {
2269: next;
2270: }
2271: }
2272: push(@singledirfiles,$file);
2273: }
2274: if (@singledirfiles) {
2275: $possdirs == 1;
2276: }
2277: }
2278: if (($possdirs == 1) && (@singledirfiles)) {
2279: my $showdir = $singledir;
2280: if ($singledir eq '') {
2281: $showdir = '/';
2282: }
2283: $output = $lt{'dire'}.
2284: '<select name="'.$firstselectname.'">'.
2285: '<option value="'.$singledir.'">'.$showdir.'</option>'."\n".
2286: '</select><br />'.
2287: $lt{'fnam'}.'<select name="'.$secondselectname.'">'."\n".
2288: '<option value="" selected="selected">'.$lt{'se'}.'</option>'."\n";
2289: foreach my $file (@singledirfiles) {
2290: $output .= '<option value="'.$file.'">'.$file.'</option>'."\n";
2291: }
2292: $output .= '</select><br />'."\n";
2293: }
2294: return ($possdirs,$output);
2295: }
2296:
1.565 albertel 2297: =pod
2298:
1.256 matthew 2299: =head1 Excel and CSV file utility routines
2300:
2301: =cut
2302:
2303: ###############################################################
2304: ###############################################################
2305:
2306: =pod
2307:
1.1162 raeburn 2308: =over 4
2309:
1.648 raeburn 2310: =item * &csv_translate($text)
1.37 matthew 2311:
1.185 www 2312: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2313: format.
2314:
2315: =cut
2316:
1.180 matthew 2317: ###############################################################
2318: ###############################################################
1.37 matthew 2319: sub csv_translate {
2320: my $text = shift;
2321: $text =~ s/\"/\"\"/g;
1.209 albertel 2322: $text =~ s/\n/ /g;
1.37 matthew 2323: return $text;
2324: }
1.180 matthew 2325:
2326: ###############################################################
2327: ###############################################################
2328:
2329: =pod
2330:
1.648 raeburn 2331: =item * &define_excel_formats()
1.180 matthew 2332:
2333: Define some commonly used Excel cell formats.
2334:
2335: Currently supported formats:
2336:
2337: =over 4
2338:
2339: =item header
2340:
2341: =item bold
2342:
2343: =item h1
2344:
2345: =item h2
2346:
2347: =item h3
2348:
1.256 matthew 2349: =item h4
2350:
2351: =item i
2352:
1.180 matthew 2353: =item date
2354:
2355: =back
2356:
2357: Inputs: $workbook
2358:
2359: Returns: $format, a hash reference.
2360:
1.1057 foxr 2361:
1.180 matthew 2362: =cut
2363:
2364: ###############################################################
2365: ###############################################################
2366: sub define_excel_formats {
2367: my ($workbook) = @_;
2368: my $format;
2369: $format->{'header'} = $workbook->add_format(bold => 1,
2370: bottom => 1,
2371: align => 'center');
2372: $format->{'bold'} = $workbook->add_format(bold=>1);
2373: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2374: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2375: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2376: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2377: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2378: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2379: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2380: return $format;
2381: }
2382:
2383: ###############################################################
2384: ###############################################################
1.113 bowersj2 2385:
2386: =pod
2387:
1.648 raeburn 2388: =item * &create_workbook()
1.255 matthew 2389:
2390: Create an Excel worksheet. If it fails, output message on the
2391: request object and return undefs.
2392:
2393: Inputs: Apache request object
2394:
2395: Returns (undef) on failure,
2396: Excel worksheet object, scalar with filename, and formats
2397: from &Apache::loncommon::define_excel_formats on success
2398:
2399: =cut
2400:
2401: ###############################################################
2402: ###############################################################
2403: sub create_workbook {
2404: my ($r) = @_;
2405: #
2406: # Create the excel spreadsheet
2407: my $filename = '/prtspool/'.
1.258 albertel 2408: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2409: time.'_'.rand(1000000000).'.xls';
2410: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2411: if (! defined($workbook)) {
2412: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2413: $r->print(
2414: '<p class="LC_error">'
2415: .&mt('Problems occurred in creating the new Excel file.')
2416: .' '.&mt('This error has been logged.')
2417: .' '.&mt('Please alert your LON-CAPA administrator.')
2418: .'</p>'
2419: );
1.255 matthew 2420: return (undef);
2421: }
2422: #
1.1014 foxr 2423: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2424: #
2425: my $format = &Apache::loncommon::define_excel_formats($workbook);
2426: return ($workbook,$filename,$format);
2427: }
2428:
2429: ###############################################################
2430: ###############################################################
2431:
2432: =pod
2433:
1.648 raeburn 2434: =item * &create_text_file()
1.113 bowersj2 2435:
1.542 raeburn 2436: Create a file to write to and eventually make available to the user.
1.256 matthew 2437: If file creation fails, outputs an error message on the request object and
2438: return undefs.
1.113 bowersj2 2439:
1.256 matthew 2440: Inputs: Apache request object, and file suffix
1.113 bowersj2 2441:
1.256 matthew 2442: Returns (undef) on failure,
2443: Filehandle and filename on success.
1.113 bowersj2 2444:
2445: =cut
2446:
1.256 matthew 2447: ###############################################################
2448: ###############################################################
2449: sub create_text_file {
2450: my ($r,$suffix) = @_;
2451: if (! defined($suffix)) { $suffix = 'txt'; };
2452: my $fh;
2453: my $filename = '/prtspool/'.
1.258 albertel 2454: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2455: time.'_'.rand(1000000000).'.'.$suffix;
2456: $fh = Apache::File->new('>/home/httpd'.$filename);
2457: if (! defined($fh)) {
2458: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2459: $r->print(
2460: '<p class="LC_error">'
2461: .&mt('Problems occurred in creating the output file.')
2462: .' '.&mt('This error has been logged.')
2463: .' '.&mt('Please alert your LON-CAPA administrator.')
2464: .'</p>'
2465: );
1.113 bowersj2 2466: }
1.256 matthew 2467: return ($fh,$filename)
1.113 bowersj2 2468: }
2469:
2470:
1.256 matthew 2471: =pod
1.113 bowersj2 2472:
2473: =back
2474:
2475: =cut
1.37 matthew 2476:
2477: ###############################################################
1.33 matthew 2478: ## Home server <option> list generating code ##
2479: ###############################################################
1.35 matthew 2480:
1.169 www 2481: # ------------------------------------------
2482:
2483: sub domain_select {
1.1289 raeburn 2484: my ($name,$value,$multiple,$incdoms,$excdoms)=@_;
2485: my @possdoms;
2486: if (ref($incdoms) eq 'ARRAY') {
2487: @possdoms = @{$incdoms};
2488: } else {
2489: @possdoms = &Apache::lonnet::all_domains();
2490: }
2491:
1.169 www 2492: my %domains=map {
1.514 albertel 2493: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.1289 raeburn 2494: } @possdoms;
2495:
2496: if ((ref($excdoms) eq 'ARRAY') && (@{$excdoms} > 0)) {
2497: foreach my $dom (@{$excdoms}) {
2498: delete($domains{$dom});
2499: }
2500: }
2501:
1.169 www 2502: if ($multiple) {
2503: $domains{''}=&mt('Any domain');
1.550 albertel 2504: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2505: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2506: } else {
1.550 albertel 2507: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2508: return &select_form($name,$value,\%domains);
1.169 www 2509: }
2510: }
2511:
1.282 albertel 2512: #-------------------------------------------
2513:
2514: =pod
2515:
1.519 raeburn 2516: =head1 Routines for form select boxes
2517:
2518: =over 4
2519:
1.648 raeburn 2520: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2521:
2522: Returns a string containing a <select> element int multiple mode
2523:
2524:
2525: Args:
2526: $name - name of the <select> element
1.506 raeburn 2527: $value - scalar or array ref of values that should already be selected
1.282 albertel 2528: $size - number of rows long the select element is
1.283 albertel 2529: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2530: (shown text should already have been &mt())
1.506 raeburn 2531: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2532:
1.282 albertel 2533: =cut
2534:
2535: #-------------------------------------------
1.169 www 2536: sub multiple_select_form {
1.284 albertel 2537: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2538: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2539: my $output='';
1.191 matthew 2540: if (! defined($size)) {
2541: $size = 4;
1.283 albertel 2542: if (scalar(keys(%$hash))<4) {
2543: $size = scalar(keys(%$hash));
1.191 matthew 2544: }
2545: }
1.734 bisitz 2546: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2547: my @order;
1.506 raeburn 2548: if (ref($order) eq 'ARRAY') {
2549: @order = @{$order};
2550: } else {
2551: @order = sort(keys(%$hash));
1.501 banghart 2552: }
2553: if (exists($$hash{'select_form_order'})) {
2554: @order = @{$$hash{'select_form_order'}};
2555: }
2556:
1.284 albertel 2557: foreach my $key (@order) {
1.356 albertel 2558: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2559: $output.='selected="selected" ' if ($selected{$key});
2560: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2561: }
2562: $output.="</select>\n";
2563: return $output;
2564: }
2565:
1.88 www 2566: #-------------------------------------------
2567:
2568: =pod
2569:
1.1254 raeburn 2570: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2571:
2572: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2573: allow a user to select options from a ref to a hash containing:
2574: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2575: a javascript onchange item, e.g., onchange="this.form.submit();".
2576: An optional arg -- $readonly -- if true will cause the select form
2577: to be disabled, e.g., for the case where an instructor has a section-
2578: specific role, and is viewing/modifying parameters.
1.970 raeburn 2579:
1.88 www 2580: See lonrights.pm for an example invocation and use.
2581:
2582: =cut
2583:
2584: #-------------------------------------------
2585: sub select_form {
1.1228 raeburn 2586: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2587: return unless (ref($hashref) eq 'HASH');
2588: if ($onchange) {
2589: $onchange = ' onchange="'.$onchange.'"';
2590: }
1.1228 raeburn 2591: my $disabled;
2592: if ($readonly) {
2593: $disabled = ' disabled="disabled"';
2594: }
2595: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2596: my @keys;
1.970 raeburn 2597: if (exists($hashref->{'select_form_order'})) {
2598: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2599: } else {
1.970 raeburn 2600: @keys=sort(keys(%{$hashref}));
1.128 albertel 2601: }
1.356 albertel 2602: foreach my $key (@keys) {
2603: $selectform.=
2604: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2605: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2606: ">".$hashref->{$key}."</option>\n";
1.88 www 2607: }
2608: $selectform.="</select>";
2609: return $selectform;
2610: }
2611:
1.475 www 2612: # For display filters
2613:
2614: sub display_filter {
1.1074 raeburn 2615: my ($context) = @_;
1.475 www 2616: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2617: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2618: my $phraseinput = 'hidden';
2619: my $includeinput = 'hidden';
2620: my ($checked,$includetypestext);
2621: if ($env{'form.displayfilter'} eq 'containing') {
2622: $phraseinput = 'text';
2623: if ($context eq 'parmslog') {
2624: $includeinput = 'checkbox';
2625: if ($env{'form.includetypes'}) {
2626: $checked = ' checked="checked"';
2627: }
2628: $includetypestext = &mt('Include parameter types');
2629: }
2630: } else {
2631: $includetypestext = ' ';
2632: }
2633: my ($additional,$secondid,$thirdid);
2634: if ($context eq 'parmslog') {
2635: $additional =
2636: '<label><input type="'.$includeinput.'" name="includetypes"'.
2637: $checked.' name="includetypes" value="1" id="includetypes" />'.
2638: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2639: '</label>';
2640: $secondid = 'includetypes';
2641: $thirdid = 'includetypestext';
2642: }
2643: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2644: '$secondid','$thirdid')";
2645: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2646: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2647: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2648: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2649: &mt('Filter: [_1]',
1.477 www 2650: &select_form($env{'form.displayfilter'},
2651: 'displayfilter',
1.970 raeburn 2652: {'currentfolder' => 'Current folder/page',
1.477 www 2653: 'containing' => 'Containing phrase',
1.1074 raeburn 2654: 'none' => 'None'},$onchange)).' '.
2655: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2656: &HTML::Entities::encode($env{'form.containingphrase'}).
2657: '" />'.$additional;
2658: }
2659:
2660: sub display_filter_js {
2661: my $includetext = &mt('Include parameter types');
2662: return <<"ENDJS";
2663:
2664: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2665: var firstType = 'hidden';
2666: if (setter.options[setter.selectedIndex].value == 'containing') {
2667: firstType = 'text';
2668: }
2669: firstObject = document.getElementById(firstid);
2670: if (typeof(firstObject) == 'object') {
2671: if (firstObject.type != firstType) {
2672: changeInputType(firstObject,firstType);
2673: }
2674: }
2675: if (context == 'parmslog') {
2676: var secondType = 'hidden';
2677: if (firstType == 'text') {
2678: secondType = 'checkbox';
2679: }
2680: secondObject = document.getElementById(secondid);
2681: if (typeof(secondObject) == 'object') {
2682: if (secondObject.type != secondType) {
2683: changeInputType(secondObject,secondType);
2684: }
2685: }
2686: var textItem = document.getElementById(thirdid);
2687: var currtext = textItem.innerHTML;
2688: var newtext;
2689: if (firstType == 'text') {
2690: newtext = '$includetext';
2691: } else {
2692: newtext = ' ';
2693: }
2694: if (currtext != newtext) {
2695: textItem.innerHTML = newtext;
2696: }
2697: }
2698: return;
2699: }
2700:
2701: function changeInputType(oldObject,newType) {
2702: var newObject = document.createElement('input');
2703: newObject.type = newType;
2704: if (oldObject.size) {
2705: newObject.size = oldObject.size;
2706: }
2707: if (oldObject.value) {
2708: newObject.value = oldObject.value;
2709: }
2710: if (oldObject.name) {
2711: newObject.name = oldObject.name;
2712: }
2713: if (oldObject.id) {
2714: newObject.id = oldObject.id;
2715: }
2716: oldObject.parentNode.replaceChild(newObject,oldObject);
2717: return;
2718: }
2719:
2720: ENDJS
1.475 www 2721: }
2722:
1.167 www 2723: sub gradeleveldescription {
2724: my $gradelevel=shift;
2725: my %gradelevels=(0 => 'Not specified',
2726: 1 => 'Grade 1',
2727: 2 => 'Grade 2',
2728: 3 => 'Grade 3',
2729: 4 => 'Grade 4',
2730: 5 => 'Grade 5',
2731: 6 => 'Grade 6',
2732: 7 => 'Grade 7',
2733: 8 => 'Grade 8',
2734: 9 => 'Grade 9',
2735: 10 => 'Grade 10',
2736: 11 => 'Grade 11',
2737: 12 => 'Grade 12',
2738: 13 => 'Grade 13',
2739: 14 => '100 Level',
2740: 15 => '200 Level',
2741: 16 => '300 Level',
2742: 17 => '400 Level',
2743: 18 => 'Graduate Level');
2744: return &mt($gradelevels{$gradelevel});
2745: }
2746:
1.163 www 2747: sub select_level_form {
2748: my ($deflevel,$name)=@_;
2749: unless ($deflevel) { $deflevel=0; }
1.167 www 2750: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2751: for (my $i=0; $i<=18; $i++) {
2752: $selectform.="<option value=\"$i\" ".
1.253 albertel 2753: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2754: ">".&gradeleveldescription($i)."</option>\n";
2755: }
2756: $selectform.="</select>";
2757: return $selectform;
1.163 www 2758: }
1.167 www 2759:
1.35 matthew 2760: #-------------------------------------------
2761:
1.45 matthew 2762: =pod
2763:
1.1256 raeburn 2764: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2765:
2766: Returns a string containing a <select name='$name' size='1'> form to
2767: allow a user to select the domain to preform an operation in.
2768: See loncreateuser.pm for an example invocation and use.
2769:
1.90 www 2770: If the $includeempty flag is set, it also includes an empty choice ("no domain
2771: selected");
2772:
1.743 raeburn 2773: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2774:
1.910 raeburn 2775: 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.
2776:
1.1121 raeburn 2777: The optional $incdoms is a reference to an array of domains which will be the only available options.
2778:
2779: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2780:
1.1256 raeburn 2781: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
2782:
1.35 matthew 2783: =cut
2784:
2785: #-------------------------------------------
1.34 matthew 2786: sub select_dom_form {
1.1256 raeburn 2787: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2788: if ($onchange) {
1.874 raeburn 2789: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2790: }
1.1256 raeburn 2791: if ($disabled) {
2792: $disabled = ' disabled="disabled"';
2793: }
1.1121 raeburn 2794: my (@domains,%exclude);
1.910 raeburn 2795: if (ref($incdoms) eq 'ARRAY') {
2796: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2797: } else {
2798: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2799: }
1.90 www 2800: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2801: if (ref($excdoms) eq 'ARRAY') {
2802: map { $exclude{$_} = 1; } @{$excdoms};
2803: }
1.1256 raeburn 2804: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2805: foreach my $dom (@domains) {
1.1121 raeburn 2806: next if ($exclude{$dom});
1.356 albertel 2807: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2808: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2809: if ($showdomdesc) {
2810: if ($dom ne '') {
2811: my $domdesc = &Apache::lonnet::domain($dom,'description');
2812: if ($domdesc ne '') {
2813: $selectdomain .= ' ('.$domdesc.')';
2814: }
2815: }
2816: }
2817: $selectdomain .= "</option>\n";
1.34 matthew 2818: }
2819: $selectdomain.="</select>";
2820: return $selectdomain;
2821: }
2822:
1.35 matthew 2823: #-------------------------------------------
2824:
1.45 matthew 2825: =pod
2826:
1.648 raeburn 2827: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2828:
1.586 raeburn 2829: input: 4 arguments (two required, two optional) -
2830: $domain - domain of new user
2831: $name - name of form element
2832: $default - Value of 'default' causes a default item to be first
2833: option, and selected by default.
2834: $hide - Value of 'hide' causes hiding of the name of the server,
2835: if 1 server found, or default, if 0 found.
1.594 raeburn 2836: output: returns 2 items:
1.586 raeburn 2837: (a) form element which contains either:
2838: (i) <select name="$name">
2839: <option value="$hostid1">$hostid $servers{$hostid}</option>
2840: <option value="$hostid2">$hostid $servers{$hostid}</option>
2841: </select>
2842: form item if there are multiple library servers in $domain, or
2843: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2844: if there is only one library server in $domain.
2845:
2846: (b) number of library servers found.
2847:
2848: See loncreateuser.pm for example of use.
1.35 matthew 2849:
2850: =cut
2851:
2852: #-------------------------------------------
1.586 raeburn 2853: sub home_server_form_item {
2854: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2855: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2856: my $result;
2857: my $numlib = keys(%servers);
2858: if ($numlib > 1) {
2859: $result .= '<select name="'.$name.'" />'."\n";
2860: if ($default) {
1.804 bisitz 2861: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2862: '</option>'."\n";
2863: }
2864: foreach my $hostid (sort(keys(%servers))) {
2865: $result.= '<option value="'.$hostid.'">'.
2866: $hostid.' '.$servers{$hostid}."</option>\n";
2867: }
2868: $result .= '</select>'."\n";
2869: } elsif ($numlib == 1) {
2870: my $hostid;
2871: foreach my $item (keys(%servers)) {
2872: $hostid = $item;
2873: }
2874: $result .= '<input type="hidden" name="'.$name.'" value="'.
2875: $hostid.'" />';
2876: if (!$hide) {
2877: $result .= $hostid.' '.$servers{$hostid};
2878: }
2879: $result .= "\n";
2880: } elsif ($default) {
2881: $result .= '<input type="hidden" name="'.$name.
2882: '" value="default" />';
2883: if (!$hide) {
2884: $result .= &mt('default');
2885: }
2886: $result .= "\n";
1.33 matthew 2887: }
1.586 raeburn 2888: return ($result,$numlib);
1.33 matthew 2889: }
1.112 bowersj2 2890:
2891: =pod
2892:
1.534 albertel 2893: =back
2894:
1.112 bowersj2 2895: =cut
1.87 matthew 2896:
2897: ###############################################################
1.112 bowersj2 2898: ## Decoding User Agent ##
1.87 matthew 2899: ###############################################################
2900:
2901: =pod
2902:
1.112 bowersj2 2903: =head1 Decoding the User Agent
2904:
2905: =over 4
2906:
2907: =item * &decode_user_agent()
1.87 matthew 2908:
2909: Inputs: $r
2910:
2911: Outputs:
2912:
2913: =over 4
2914:
1.112 bowersj2 2915: =item * $httpbrowser
1.87 matthew 2916:
1.112 bowersj2 2917: =item * $clientbrowser
1.87 matthew 2918:
1.112 bowersj2 2919: =item * $clientversion
1.87 matthew 2920:
1.112 bowersj2 2921: =item * $clientmathml
1.87 matthew 2922:
1.112 bowersj2 2923: =item * $clientunicode
1.87 matthew 2924:
1.112 bowersj2 2925: =item * $clientos
1.87 matthew 2926:
1.1137 raeburn 2927: =item * $clientmobile
2928:
1.1141 raeburn 2929: =item * $clientinfo
2930:
1.1194 raeburn 2931: =item * $clientosversion
2932:
1.87 matthew 2933: =back
2934:
1.157 matthew 2935: =back
2936:
1.87 matthew 2937: =cut
2938:
2939: ###############################################################
2940: ###############################################################
2941: sub decode_user_agent {
1.247 albertel 2942: my ($r)=@_;
1.87 matthew 2943: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2944: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2945: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2946: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2947: my $clientbrowser='unknown';
2948: my $clientversion='0';
2949: my $clientmathml='';
2950: my $clientunicode='0';
1.1137 raeburn 2951: my $clientmobile=0;
1.1194 raeburn 2952: my $clientosversion='';
1.87 matthew 2953: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2954: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2955: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2956: $clientbrowser=$bname;
2957: $httpbrowser=~/$vreg/i;
2958: $clientversion=$1;
2959: $clientmathml=($clientversion>=$minv);
2960: $clientunicode=($clientversion>=$univ);
2961: }
2962: }
2963: my $clientos='unknown';
1.1141 raeburn 2964: my $clientinfo;
1.87 matthew 2965: if (($httpbrowser=~/linux/i) ||
2966: ($httpbrowser=~/unix/i) ||
2967: ($httpbrowser=~/ux/i) ||
2968: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2969: if (($httpbrowser=~/vax/i) ||
2970: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2971: if ($httpbrowser=~/next/i) { $clientos='next'; }
2972: if (($httpbrowser=~/mac/i) ||
2973: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2974: if ($httpbrowser=~/win/i) {
2975: $clientos='win';
2976: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2977: $clientosversion = $1;
2978: }
2979: }
1.87 matthew 2980: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2981: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2982: $clientmobile=lc($1);
2983: }
1.1141 raeburn 2984: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2985: $clientinfo = 'firefox-'.$1;
2986: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2987: $clientinfo = 'chromeframe-'.$1;
2988: }
1.87 matthew 2989: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 2990: $clientunicode,$clientos,$clientmobile,$clientinfo,
2991: $clientosversion);
1.87 matthew 2992: }
2993:
1.32 matthew 2994: ###############################################################
2995: ## Authentication changing form generation subroutines ##
2996: ###############################################################
2997: ##
2998: ## All of the authform_xxxxxxx subroutines take their inputs in a
2999: ## hash, and have reasonable default values.
3000: ##
3001: ## formname = the name given in the <form> tag.
1.35 matthew 3002: #-------------------------------------------
3003:
1.45 matthew 3004: =pod
3005:
1.112 bowersj2 3006: =head1 Authentication Routines
3007:
3008: =over 4
3009:
1.648 raeburn 3010: =item * &authform_xxxxxx()
1.35 matthew 3011:
3012: The authform_xxxxxx subroutines provide javascript and html forms which
3013: handle some of the conveniences required for authentication forms.
3014: This is not an optimal method, but it works.
3015:
3016: =over 4
3017:
1.112 bowersj2 3018: =item * authform_header
1.35 matthew 3019:
1.112 bowersj2 3020: =item * authform_authorwarning
1.35 matthew 3021:
1.112 bowersj2 3022: =item * authform_nochange
1.35 matthew 3023:
1.112 bowersj2 3024: =item * authform_kerberos
1.35 matthew 3025:
1.112 bowersj2 3026: =item * authform_internal
1.35 matthew 3027:
1.112 bowersj2 3028: =item * authform_filesystem
1.35 matthew 3029:
1.1310 raeburn 3030: =item * authform_lti
3031:
1.35 matthew 3032: =back
3033:
1.648 raeburn 3034: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3035:
1.35 matthew 3036: =cut
3037:
3038: #-------------------------------------------
1.32 matthew 3039: sub authform_header{
3040: my %in = (
3041: formname => 'cu',
1.80 albertel 3042: kerb_def_dom => '',
1.32 matthew 3043: @_,
3044: );
3045: $in{'formname'} = 'document.' . $in{'formname'};
3046: my $result='';
1.80 albertel 3047:
3048: #---------------------------------------------- Code for upper case translation
3049: my $Javascript_toUpperCase;
3050: unless ($in{kerb_def_dom}) {
3051: $Javascript_toUpperCase =<<"END";
3052: switch (choice) {
3053: case 'krb': currentform.elements[choicearg].value =
3054: currentform.elements[choicearg].value.toUpperCase();
3055: break;
3056: default:
3057: }
3058: END
3059: } else {
3060: $Javascript_toUpperCase = "";
3061: }
3062:
1.165 raeburn 3063: my $radioval = "'nochange'";
1.591 raeburn 3064: if (defined($in{'curr_authtype'})) {
3065: if ($in{'curr_authtype'} ne '') {
3066: $radioval = "'".$in{'curr_authtype'}."arg'";
3067: }
1.174 matthew 3068: }
1.165 raeburn 3069: my $argfield = 'null';
1.591 raeburn 3070: if (defined($in{'mode'})) {
1.165 raeburn 3071: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3072: if (defined($in{'curr_autharg'})) {
3073: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3074: $argfield = "'$in{'curr_autharg'}'";
3075: }
3076: }
3077: }
3078: }
3079:
1.32 matthew 3080: $result.=<<"END";
3081: var current = new Object();
1.165 raeburn 3082: current.radiovalue = $radioval;
3083: current.argfield = $argfield;
1.32 matthew 3084:
3085: function changed_radio(choice,currentform) {
3086: var choicearg = choice + 'arg';
3087: // If a radio button in changed, we need to change the argfield
3088: if (current.radiovalue != choice) {
3089: current.radiovalue = choice;
3090: if (current.argfield != null) {
3091: currentform.elements[current.argfield].value = '';
3092: }
3093: if (choice == 'nochange') {
3094: current.argfield = null;
3095: } else {
3096: current.argfield = choicearg;
3097: switch(choice) {
3098: case 'krb':
3099: currentform.elements[current.argfield].value =
3100: "$in{'kerb_def_dom'}";
3101: break;
3102: default:
3103: break;
3104: }
3105: }
3106: }
3107: return;
3108: }
1.22 www 3109:
1.32 matthew 3110: function changed_text(choice,currentform) {
3111: var choicearg = choice + 'arg';
3112: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3113: $Javascript_toUpperCase
1.32 matthew 3114: // clear old field
3115: if ((current.argfield != choicearg) && (current.argfield != null)) {
3116: currentform.elements[current.argfield].value = '';
3117: }
3118: current.argfield = choicearg;
3119: }
3120: set_auth_radio_buttons(choice,currentform);
3121: return;
1.20 www 3122: }
1.32 matthew 3123:
3124: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3125: var numauthchoices = currentform.login.length;
3126: if (typeof numauthchoices == "undefined") {
3127: return;
3128: }
1.32 matthew 3129: var i=0;
1.986 raeburn 3130: while (i < numauthchoices) {
1.32 matthew 3131: if (currentform.login[i].value == newvalue) { break; }
3132: i++;
3133: }
1.986 raeburn 3134: if (i == numauthchoices) {
1.32 matthew 3135: return;
3136: }
3137: current.radiovalue = newvalue;
3138: currentform.login[i].checked = true;
3139: return;
3140: }
3141: END
3142: return $result;
3143: }
3144:
1.1106 raeburn 3145: sub authform_authorwarning {
1.32 matthew 3146: my $result='';
1.144 matthew 3147: $result='<i>'.
3148: &mt('As a general rule, only authors or co-authors should be '.
3149: 'filesystem authenticated '.
3150: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3151: return $result;
3152: }
3153:
1.1106 raeburn 3154: sub authform_nochange {
1.32 matthew 3155: my %in = (
3156: formname => 'document.cu',
3157: kerb_def_dom => 'MSU.EDU',
3158: @_,
3159: );
1.1106 raeburn 3160: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3161: my $result;
1.1104 raeburn 3162: if (!$authnum) {
1.1105 raeburn 3163: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3164: } else {
3165: $result = '<label>'.&mt('[_1] Do not change login data',
3166: '<input type="radio" name="login" value="nochange" '.
3167: 'checked="checked" onclick="'.
1.281 albertel 3168: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3169: '</label>';
1.586 raeburn 3170: }
1.32 matthew 3171: return $result;
3172: }
3173:
1.591 raeburn 3174: sub authform_kerberos {
1.32 matthew 3175: my %in = (
3176: formname => 'document.cu',
3177: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3178: kerb_def_auth => 'krb4',
1.32 matthew 3179: @_,
3180: );
1.586 raeburn 3181: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3182: $autharg,$jscall,$disabled);
1.1106 raeburn 3183: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3184: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3185: $check5 = ' checked="checked"';
1.80 albertel 3186: } else {
1.772 bisitz 3187: $check4 = ' checked="checked"';
1.80 albertel 3188: }
1.1259 raeburn 3189: if ($in{'readonly'}) {
3190: $disabled = ' disabled="disabled"';
3191: }
1.165 raeburn 3192: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3193: if (defined($in{'curr_authtype'})) {
3194: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3195: $krbcheck = ' checked="checked"';
1.623 raeburn 3196: if (defined($in{'mode'})) {
3197: if ($in{'mode'} eq 'modifyuser') {
3198: $krbcheck = '';
3199: }
3200: }
1.591 raeburn 3201: if (defined($in{'curr_kerb_ver'})) {
3202: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3203: $check5 = ' checked="checked"';
1.591 raeburn 3204: $check4 = '';
3205: } else {
1.772 bisitz 3206: $check4 = ' checked="checked"';
1.591 raeburn 3207: $check5 = '';
3208: }
1.586 raeburn 3209: }
1.591 raeburn 3210: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3211: $krbarg = $in{'curr_autharg'};
3212: }
1.586 raeburn 3213: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3214: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3215: $result =
3216: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3217: $in{'curr_autharg'},$krbver);
3218: } else {
3219: $result =
3220: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3221: }
3222: return $result;
3223: }
3224: }
3225: } else {
3226: if ($authnum == 1) {
1.784 bisitz 3227: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3228: }
3229: }
1.586 raeburn 3230: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3231: return;
1.587 raeburn 3232: } elsif ($authtype eq '') {
1.591 raeburn 3233: if (defined($in{'mode'})) {
1.587 raeburn 3234: if ($in{'mode'} eq 'modifycourse') {
3235: if ($authnum == 1) {
1.1259 raeburn 3236: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3237: }
3238: }
3239: }
1.586 raeburn 3240: }
3241: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3242: if ($authtype eq '') {
3243: $authtype = '<input type="radio" name="login" value="krb" '.
3244: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3245: $krbcheck.$disabled.' />';
1.586 raeburn 3246: }
3247: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3248: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3249: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3250: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3251: $in{'curr_authtype'} eq 'krb4')) {
3252: $result .= &mt
1.144 matthew 3253: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3254: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3255: '<label>'.$authtype,
1.281 albertel 3256: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3257: 'value="'.$krbarg.'" '.
1.1259 raeburn 3258: 'onchange="'.$jscall.'"'.$disabled.' />',
3259: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3260: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3261: '</label>');
1.586 raeburn 3262: } elsif ($can_assign{'krb4'}) {
3263: $result .= &mt
3264: ('[_1] Kerberos authenticated with domain [_2] '.
3265: '[_3] Version 4 [_4]',
3266: '<label>'.$authtype,
3267: '</label><input type="text" size="10" name="krbarg" '.
3268: 'value="'.$krbarg.'" '.
1.1259 raeburn 3269: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3270: '<label><input type="hidden" name="krbver" value="4" />',
3271: '</label>');
3272: } elsif ($can_assign{'krb5'}) {
3273: $result .= &mt
3274: ('[_1] Kerberos authenticated with domain [_2] '.
3275: '[_3] Version 5 [_4]',
3276: '<label>'.$authtype,
3277: '</label><input type="text" size="10" name="krbarg" '.
3278: 'value="'.$krbarg.'" '.
1.1259 raeburn 3279: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3280: '<label><input type="hidden" name="krbver" value="5" />',
3281: '</label>');
3282: }
1.32 matthew 3283: return $result;
3284: }
3285:
1.1106 raeburn 3286: sub authform_internal {
1.586 raeburn 3287: my %in = (
1.32 matthew 3288: formname => 'document.cu',
3289: kerb_def_dom => 'MSU.EDU',
3290: @_,
3291: );
1.1259 raeburn 3292: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3293: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3294: if ($in{'readonly'}) {
3295: $disabled = ' disabled="disabled"';
3296: }
1.591 raeburn 3297: if (defined($in{'curr_authtype'})) {
3298: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3299: if ($can_assign{'int'}) {
1.772 bisitz 3300: $intcheck = 'checked="checked" ';
1.623 raeburn 3301: if (defined($in{'mode'})) {
3302: if ($in{'mode'} eq 'modifyuser') {
3303: $intcheck = '';
3304: }
3305: }
1.591 raeburn 3306: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3307: $intarg = $in{'curr_autharg'};
3308: }
3309: } else {
3310: $result = &mt('Currently internally authenticated.');
3311: return $result;
1.165 raeburn 3312: }
3313: }
1.586 raeburn 3314: } else {
3315: if ($authnum == 1) {
1.784 bisitz 3316: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3317: }
3318: }
3319: if (!$can_assign{'int'}) {
3320: return;
1.587 raeburn 3321: } elsif ($authtype eq '') {
1.591 raeburn 3322: if (defined($in{'mode'})) {
1.587 raeburn 3323: if ($in{'mode'} eq 'modifycourse') {
3324: if ($authnum == 1) {
1.1259 raeburn 3325: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3326: }
3327: }
3328: }
1.165 raeburn 3329: }
1.586 raeburn 3330: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3331: if ($authtype eq '') {
3332: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3333: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3334: }
1.605 bisitz 3335: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3336: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3337: $result = &mt
1.144 matthew 3338: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3339: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3340: $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 3341: return $result;
3342: }
3343:
1.1104 raeburn 3344: sub authform_local {
1.32 matthew 3345: my %in = (
3346: formname => 'document.cu',
3347: kerb_def_dom => 'MSU.EDU',
3348: @_,
3349: );
1.1259 raeburn 3350: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3351: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3352: if ($in{'readonly'}) {
3353: $disabled = ' disabled="disabled"';
3354: }
1.591 raeburn 3355: if (defined($in{'curr_authtype'})) {
3356: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3357: if ($can_assign{'loc'}) {
1.772 bisitz 3358: $loccheck = 'checked="checked" ';
1.623 raeburn 3359: if (defined($in{'mode'})) {
3360: if ($in{'mode'} eq 'modifyuser') {
3361: $loccheck = '';
3362: }
3363: }
1.591 raeburn 3364: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3365: $locarg = $in{'curr_autharg'};
3366: }
3367: } else {
3368: $result = &mt('Currently using local (institutional) authentication.');
3369: return $result;
1.165 raeburn 3370: }
3371: }
1.586 raeburn 3372: } else {
3373: if ($authnum == 1) {
1.784 bisitz 3374: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3375: }
3376: }
3377: if (!$can_assign{'loc'}) {
3378: return;
1.587 raeburn 3379: } elsif ($authtype eq '') {
1.591 raeburn 3380: if (defined($in{'mode'})) {
1.587 raeburn 3381: if ($in{'mode'} eq 'modifycourse') {
3382: if ($authnum == 1) {
1.1259 raeburn 3383: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3384: }
3385: }
3386: }
1.165 raeburn 3387: }
1.586 raeburn 3388: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3389: if ($authtype eq '') {
3390: $authtype = '<input type="radio" name="login" value="loc" '.
3391: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3392: $jscall.'"'.$disabled.' />';
1.586 raeburn 3393: }
3394: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3395: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3396: $result = &mt('[_1] Local Authentication with argument [_2]',
3397: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3398: return $result;
3399: }
3400:
1.1106 raeburn 3401: sub authform_filesystem {
1.32 matthew 3402: my %in = (
3403: formname => 'document.cu',
3404: kerb_def_dom => 'MSU.EDU',
3405: @_,
3406: );
1.1259 raeburn 3407: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3408: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3409: if ($in{'readonly'}) {
3410: $disabled = ' disabled="disabled"';
3411: }
1.591 raeburn 3412: if (defined($in{'curr_authtype'})) {
3413: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3414: if ($can_assign{'fsys'}) {
1.772 bisitz 3415: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3416: if (defined($in{'mode'})) {
3417: if ($in{'mode'} eq 'modifyuser') {
3418: $fsyscheck = '';
3419: }
3420: }
1.586 raeburn 3421: } else {
3422: $result = &mt('Currently Filesystem Authenticated.');
3423: return $result;
1.1259 raeburn 3424: }
1.586 raeburn 3425: }
3426: } else {
3427: if ($authnum == 1) {
1.784 bisitz 3428: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3429: }
3430: }
3431: if (!$can_assign{'fsys'}) {
3432: return;
1.587 raeburn 3433: } elsif ($authtype eq '') {
1.591 raeburn 3434: if (defined($in{'mode'})) {
1.587 raeburn 3435: if ($in{'mode'} eq 'modifycourse') {
3436: if ($authnum == 1) {
1.1259 raeburn 3437: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3438: }
3439: }
3440: }
1.586 raeburn 3441: }
3442: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3443: if ($authtype eq '') {
3444: $authtype = '<input type="radio" name="login" value="fsys" '.
3445: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3446: $jscall.'"'.$disabled.' />';
1.586 raeburn 3447: }
1.1310 raeburn 3448: $autharg = '<input type="password" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3449: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3450: $result = &mt
1.144 matthew 3451: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.1310 raeburn 3452: '<label>'.$authtype,'</label>'.$autharg);
3453: return $result;
3454: }
3455:
3456: sub authform_lti {
3457: my %in = (
3458: formname => 'document.cu',
3459: kerb_def_dom => 'MSU.EDU',
3460: @_,
3461: );
3462: my ($lticheck,$result,$authtype,$autharg,$jscall,$disabled);
3463: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
3464: if ($in{'readonly'}) {
3465: $disabled = ' disabled="disabled"';
3466: }
3467: if (defined($in{'curr_authtype'})) {
3468: if ($in{'curr_authtype'} eq 'lti') {
3469: if ($can_assign{'lti'}) {
3470: $lticheck = 'checked="checked" ';
3471: if (defined($in{'mode'})) {
3472: if ($in{'mode'} eq 'modifyuser') {
3473: $lticheck = '';
3474: }
3475: }
3476: } else {
3477: $result = &mt('Currently LTI Authenticated.');
3478: return $result;
3479: }
3480: }
3481: } else {
3482: if ($authnum == 1) {
3483: $authtype = '<input type="hidden" name="login" value="lti" />';
3484: }
3485: }
3486: if (!$can_assign{'lti'}) {
3487: return;
3488: } elsif ($authtype eq '') {
3489: if (defined($in{'mode'})) {
3490: if ($in{'mode'} eq 'modifycourse') {
3491: if ($authnum == 1) {
3492: $authtype = '<input type="radio" name="login" value="lti"'.$disabled.' />';
3493: }
3494: }
3495: }
3496: }
3497: $jscall = "javascript:changed_radio('lti',$in{'formname'});";
3498: if (($authtype eq '') && (($in{'mode'} eq 'modifycourse') || ($in{'curr_authtype'} ne 'lti'))) {
3499: $authtype = '<input type="radio" name="login" value="lti" '.
3500: $lticheck.' onchange="'.$jscall.'" onclick="'.
3501: $jscall.'"'.$disabled.' />';
3502: }
3503: $autharg = '<input type="hidden" name="ltiarg" value="" />';
3504: if ($authtype) {
3505: $result = &mt('[_1] LTI Authenticated',
3506: '<label>'.$authtype.'</label>'.$autharg);
3507: } else {
3508: $result = '<b>'.&mt('LTI Authenticated').'</b>'.
3509: $autharg;
3510: }
1.32 matthew 3511: return $result;
3512: }
3513:
1.586 raeburn 3514: sub get_assignable_auth {
3515: my ($dom) = @_;
3516: if ($dom eq '') {
3517: $dom = $env{'request.role.domain'};
3518: }
3519: my %can_assign = (
3520: krb4 => 1,
3521: krb5 => 1,
3522: int => 1,
3523: loc => 1,
1.1310 raeburn 3524: lti => 1,
1.586 raeburn 3525: );
3526: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3527: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3528: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3529: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3530: my $context;
3531: if ($env{'request.role'} =~ /^au/) {
3532: $context = 'author';
1.1259 raeburn 3533: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3534: $context = 'domain';
3535: } elsif ($env{'request.course.id'}) {
3536: $context = 'course';
3537: }
3538: if ($context) {
3539: if (ref($authhash->{$context}) eq 'HASH') {
3540: %can_assign = %{$authhash->{$context}};
3541: }
3542: }
3543: }
3544: }
3545: my $authnum = 0;
3546: foreach my $key (keys(%can_assign)) {
3547: if ($can_assign{$key}) {
3548: $authnum ++;
3549: }
3550: }
3551: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3552: $authnum --;
3553: }
3554: return ($authnum,%can_assign);
3555: }
3556:
1.80 albertel 3557: ###############################################################
3558: ## Get Kerberos Defaults for Domain ##
3559: ###############################################################
3560: ##
3561: ## Returns default kerberos version and an associated argument
3562: ## as listed in file domain.tab. If not listed, provides
3563: ## appropriate default domain and kerberos version.
3564: ##
3565: #-------------------------------------------
3566:
3567: =pod
3568:
1.648 raeburn 3569: =item * &get_kerberos_defaults()
1.80 albertel 3570:
3571: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3572: version and domain. If not found, it defaults to version 4 and the
3573: domain of the server.
1.80 albertel 3574:
1.648 raeburn 3575: =over 4
3576:
1.80 albertel 3577: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3578:
1.648 raeburn 3579: =back
3580:
3581: =back
3582:
1.80 albertel 3583: =cut
3584:
3585: #-------------------------------------------
3586: sub get_kerberos_defaults {
3587: my $domain=shift;
1.641 raeburn 3588: my ($krbdef,$krbdefdom);
3589: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3590: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3591: $krbdef = $domdefaults{'auth_def'};
3592: $krbdefdom = $domdefaults{'auth_arg_def'};
3593: } else {
1.80 albertel 3594: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3595: my $krbdefdom=$1;
3596: $krbdefdom=~tr/a-z/A-Z/;
3597: $krbdef = "krb4";
3598: }
3599: return ($krbdef,$krbdefdom);
3600: }
1.112 bowersj2 3601:
1.32 matthew 3602:
1.46 matthew 3603: ###############################################################
3604: ## Thesaurus Functions ##
3605: ###############################################################
1.20 www 3606:
1.46 matthew 3607: =pod
1.20 www 3608:
1.112 bowersj2 3609: =head1 Thesaurus Functions
3610:
3611: =over 4
3612:
1.648 raeburn 3613: =item * &initialize_keywords()
1.46 matthew 3614:
3615: Initializes the package variable %Keywords if it is empty. Uses the
3616: package variable $thesaurus_db_file.
3617:
3618: =cut
3619:
3620: ###################################################
3621:
3622: sub initialize_keywords {
3623: return 1 if (scalar keys(%Keywords));
3624: # If we are here, %Keywords is empty, so fill it up
3625: # Make sure the file we need exists...
3626: if (! -e $thesaurus_db_file) {
3627: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3628: " failed because it does not exist");
3629: return 0;
3630: }
3631: # Set up the hash as a database
3632: my %thesaurus_db;
3633: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3634: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3635: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3636: $thesaurus_db_file);
3637: return 0;
3638: }
3639: # Get the average number of appearances of a word.
3640: my $avecount = $thesaurus_db{'average.count'};
3641: # Put keywords (those that appear > average) into %Keywords
3642: while (my ($word,$data)=each (%thesaurus_db)) {
3643: my ($count,undef) = split /:/,$data;
3644: $Keywords{$word}++ if ($count > $avecount);
3645: }
3646: untie %thesaurus_db;
3647: # Remove special values from %Keywords.
1.356 albertel 3648: foreach my $value ('total.count','average.count') {
3649: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3650: }
1.46 matthew 3651: return 1;
3652: }
3653:
3654: ###################################################
3655:
3656: =pod
3657:
1.648 raeburn 3658: =item * &keyword($word)
1.46 matthew 3659:
3660: Returns true if $word is a keyword. A keyword is a word that appears more
3661: than the average number of times in the thesaurus database. Calls
3662: &initialize_keywords
3663:
3664: =cut
3665:
3666: ###################################################
1.20 www 3667:
3668: sub keyword {
1.46 matthew 3669: return if (!&initialize_keywords());
3670: my $word=lc(shift());
3671: $word=~s/\W//g;
3672: return exists($Keywords{$word});
1.20 www 3673: }
1.46 matthew 3674:
3675: ###############################################################
3676:
3677: =pod
1.20 www 3678:
1.648 raeburn 3679: =item * &get_related_words()
1.46 matthew 3680:
1.160 matthew 3681: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3682: an array of words. If the keyword is not in the thesaurus, an empty array
3683: will be returned. The order of the words returned is determined by the
3684: database which holds them.
3685:
3686: Uses global $thesaurus_db_file.
3687:
1.1057 foxr 3688:
1.46 matthew 3689: =cut
3690:
3691: ###############################################################
3692: sub get_related_words {
3693: my $keyword = shift;
3694: my %thesaurus_db;
3695: if (! -e $thesaurus_db_file) {
3696: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3697: "failed because the file does not exist");
3698: return ();
3699: }
3700: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3701: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3702: return ();
3703: }
3704: my @Words=();
1.429 www 3705: my $count=0;
1.46 matthew 3706: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3707: # The first element is the number of times
3708: # the word appears. We do not need it now.
1.429 www 3709: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3710: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3711: my $threshold=$mostfrequentcount/10;
3712: foreach my $possibleword (@RelatedWords) {
3713: my ($word,$wordcount)=split(/\,/,$possibleword);
3714: if ($wordcount>$threshold) {
3715: push(@Words,$word);
3716: $count++;
3717: if ($count>10) { last; }
3718: }
1.20 www 3719: }
3720: }
1.46 matthew 3721: untie %thesaurus_db;
3722: return @Words;
1.14 harris41 3723: }
1.1090 foxr 3724: ###############################################################
3725: #
3726: # Spell checking
3727: #
3728:
3729: =pod
3730:
1.1142 raeburn 3731: =back
3732:
1.1090 foxr 3733: =head1 Spell checking
3734:
3735: =over 4
3736:
3737: =item * &check_spelling($wordlist $language)
3738:
3739: Takes a string containing words and feeds it to an external
3740: spellcheck program via a pipeline. Returns a string containing
3741: them mis-spelled words.
3742:
3743: Parameters:
3744:
3745: =over 4
3746:
3747: =item - $wordlist
3748:
3749: String that will be fed into the spellcheck program.
3750:
3751: =item - $language
3752:
3753: Language string that specifies the language for which the spell
3754: check will be performed.
3755:
3756: =back
3757:
3758: =back
3759:
3760: Note: This sub assumes that aspell is installed.
3761:
3762:
3763: =cut
3764:
1.46 matthew 3765:
1.1090 foxr 3766: sub check_spelling {
3767: my ($wordlist, $language) = @_;
1.1091 foxr 3768: my @misspellings;
3769:
3770: # Generate the speller and set the langauge.
3771: # if explicitly selected:
1.1090 foxr 3772:
1.1091 foxr 3773: my $speller = Text::Aspell->new;
1.1090 foxr 3774: if ($language) {
1.1091 foxr 3775: $speller->set_option('lang', $language);
1.1090 foxr 3776: }
3777:
1.1091 foxr 3778: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3779:
1.1091 foxr 3780: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3781:
1.1091 foxr 3782: foreach my $word (@words) {
3783: if(! $speller->check($word)) {
3784: push(@misspellings, $word);
1.1090 foxr 3785: }
3786: }
1.1091 foxr 3787: return join(' ', @misspellings);
3788:
1.1090 foxr 3789: }
3790:
1.61 www 3791: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3792: =pod
3793:
1.112 bowersj2 3794: =head1 User Name Functions
3795:
3796: =over 4
3797:
1.648 raeburn 3798: =item * &plainname($uname,$udom,$first)
1.81 albertel 3799:
1.112 bowersj2 3800: Takes a users logon name and returns it as a string in
1.226 albertel 3801: "first middle last generation" form
3802: if $first is set to 'lastname' then it returns it as
3803: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3804:
3805: =cut
1.61 www 3806:
1.295 www 3807:
1.81 albertel 3808: ###############################################################
1.61 www 3809: sub plainname {
1.226 albertel 3810: my ($uname,$udom,$first)=@_;
1.537 albertel 3811: return if (!defined($uname) || !defined($udom));
1.295 www 3812: my %names=&getnames($uname,$udom);
1.226 albertel 3813: my $name=&Apache::lonnet::format_name($names{'firstname'},
3814: $names{'middlename'},
3815: $names{'lastname'},
3816: $names{'generation'},$first);
3817: $name=~s/^\s+//;
1.62 www 3818: $name=~s/\s+$//;
3819: $name=~s/\s+/ /g;
1.353 albertel 3820: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3821: return $name;
1.61 www 3822: }
1.66 www 3823:
3824: # -------------------------------------------------------------------- Nickname
1.81 albertel 3825: =pod
3826:
1.648 raeburn 3827: =item * &nickname($uname,$udom)
1.81 albertel 3828:
3829: Gets a users name and returns it as a string as
3830:
3831: ""nickname""
1.66 www 3832:
1.81 albertel 3833: if the user has a nickname or
3834:
3835: "first middle last generation"
3836:
3837: if the user does not
3838:
3839: =cut
1.66 www 3840:
3841: sub nickname {
3842: my ($uname,$udom)=@_;
1.537 albertel 3843: return if (!defined($uname) || !defined($udom));
1.295 www 3844: my %names=&getnames($uname,$udom);
1.68 albertel 3845: my $name=$names{'nickname'};
1.66 www 3846: if ($name) {
3847: $name='"'.$name.'"';
3848: } else {
3849: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3850: $names{'lastname'}.' '.$names{'generation'};
3851: $name=~s/\s+$//;
3852: $name=~s/\s+/ /g;
3853: }
3854: return $name;
3855: }
3856:
1.295 www 3857: sub getnames {
3858: my ($uname,$udom)=@_;
1.537 albertel 3859: return if (!defined($uname) || !defined($udom));
1.433 albertel 3860: if ($udom eq 'public' && $uname eq 'public') {
3861: return ('lastname' => &mt('Public'));
3862: }
1.295 www 3863: my $id=$uname.':'.$udom;
3864: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3865: if ($cached) {
3866: return %{$names};
3867: } else {
3868: my %loadnames=&Apache::lonnet::get('environment',
3869: ['firstname','middlename','lastname','generation','nickname'],
3870: $udom,$uname);
3871: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3872: return %loadnames;
3873: }
3874: }
1.61 www 3875:
1.542 raeburn 3876: # -------------------------------------------------------------------- getemails
1.648 raeburn 3877:
1.542 raeburn 3878: =pod
3879:
1.648 raeburn 3880: =item * &getemails($uname,$udom)
1.542 raeburn 3881:
3882: Gets a user's email information and returns it as a hash with keys:
3883: notification, critnotification, permanentemail
3884:
3885: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3886: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3887:
1.648 raeburn 3888:
1.542 raeburn 3889: =cut
3890:
1.648 raeburn 3891:
1.466 albertel 3892: sub getemails {
3893: my ($uname,$udom)=@_;
3894: if ($udom eq 'public' && $uname eq 'public') {
3895: return;
3896: }
1.467 www 3897: if (!$udom) { $udom=$env{'user.domain'}; }
3898: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3899: my $id=$uname.':'.$udom;
3900: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3901: if ($cached) {
3902: return %{$names};
3903: } else {
3904: my %loadnames=&Apache::lonnet::get('environment',
3905: ['notification','critnotification',
3906: 'permanentemail'],
3907: $udom,$uname);
3908: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3909: return %loadnames;
3910: }
3911: }
3912:
1.551 albertel 3913: sub flush_email_cache {
3914: my ($uname,$udom)=@_;
3915: if (!$udom) { $udom =$env{'user.domain'}; }
3916: if (!$uname) { $uname=$env{'user.name'}; }
3917: return if ($udom eq 'public' && $uname eq 'public');
3918: my $id=$uname.':'.$udom;
3919: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3920: }
3921:
1.728 raeburn 3922: # -------------------------------------------------------------------- getlangs
3923:
3924: =pod
3925:
3926: =item * &getlangs($uname,$udom)
3927:
3928: Gets a user's language preference and returns it as a hash with key:
3929: language.
3930:
3931: =cut
3932:
3933:
3934: sub getlangs {
3935: my ($uname,$udom) = @_;
3936: if (!$udom) { $udom =$env{'user.domain'}; }
3937: if (!$uname) { $uname=$env{'user.name'}; }
3938: my $id=$uname.':'.$udom;
3939: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3940: if ($cached) {
3941: return %{$langs};
3942: } else {
3943: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3944: $udom,$uname);
3945: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3946: return %loadlangs;
3947: }
3948: }
3949:
3950: sub flush_langs_cache {
3951: my ($uname,$udom)=@_;
3952: if (!$udom) { $udom =$env{'user.domain'}; }
3953: if (!$uname) { $uname=$env{'user.name'}; }
3954: return if ($udom eq 'public' && $uname eq 'public');
3955: my $id=$uname.':'.$udom;
3956: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3957: }
3958:
1.61 www 3959: # ------------------------------------------------------------------ Screenname
1.81 albertel 3960:
3961: =pod
3962:
1.648 raeburn 3963: =item * &screenname($uname,$udom)
1.81 albertel 3964:
3965: Gets a users screenname and returns it as a string
3966:
3967: =cut
1.61 www 3968:
3969: sub screenname {
3970: my ($uname,$udom)=@_;
1.258 albertel 3971: if ($uname eq $env{'user.name'} &&
3972: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3973: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3974: return $names{'screenname'};
1.62 www 3975: }
3976:
1.212 albertel 3977:
1.802 bisitz 3978: # ------------------------------------------------------------- Confirm Wrapper
3979: =pod
3980:
1.1142 raeburn 3981: =item * &confirmwrapper($message)
1.802 bisitz 3982:
3983: Wrap messages about completion of operation in box
3984:
3985: =cut
3986:
3987: sub confirmwrapper {
3988: my ($message)=@_;
3989: if ($message) {
3990: return "\n".'<div class="LC_confirm_box">'."\n"
3991: .$message."\n"
3992: .'</div>'."\n";
3993: } else {
3994: return $message;
3995: }
3996: }
3997:
1.62 www 3998: # ------------------------------------------------------------- Message Wrapper
3999:
4000: sub messagewrapper {
1.369 www 4001: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 4002: return
1.441 albertel 4003: '<a href="/adm/email?compose=individual&'.
4004: 'recname='.$username.'&recdom='.$domain.
4005: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 4006: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 4007: }
1.802 bisitz 4008:
1.74 www 4009: # --------------------------------------------------------------- Notes Wrapper
4010:
4011: sub noteswrapper {
4012: my ($link,$un,$do)=@_;
4013: return
1.896 amueller 4014: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 4015: }
1.802 bisitz 4016:
1.62 www 4017: # ------------------------------------------------------------- Aboutme Wrapper
4018:
4019: sub aboutmewrapper {
1.1070 raeburn 4020: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 4021: if (!defined($username) && !defined($domain)) {
4022: return;
4023: }
1.1096 raeburn 4024: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 4025: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 4026: }
4027:
4028: # ------------------------------------------------------------ Syllabus Wrapper
4029:
4030: sub syllabuswrapper {
1.707 bisitz 4031: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 4032: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 4033: }
1.14 harris41 4034:
1.802 bisitz 4035: # -----------------------------------------------------------------------------
4036:
1.208 matthew 4037: sub track_student_link {
1.887 raeburn 4038: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 4039: my $link ="/adm/trackstudent?";
1.208 matthew 4040: my $title = 'View recent activity';
4041: if (defined($sname) && $sname !~ /^\s*$/ &&
4042: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 4043: $link .= "selected_student=$sname:$sdom";
1.208 matthew 4044: $title .= ' of this student';
1.268 albertel 4045: }
1.208 matthew 4046: if (defined($target) && $target !~ /^\s*$/) {
4047: $target = qq{target="$target"};
4048: } else {
4049: $target = '';
4050: }
1.268 albertel 4051: if ($start) { $link.='&start='.$start; }
1.887 raeburn 4052: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 4053: $title = &mt($title);
4054: $linktext = &mt($linktext);
1.448 albertel 4055: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
4056: &help_open_topic('View_recent_activity');
1.208 matthew 4057: }
4058:
1.781 raeburn 4059: sub slot_reservations_link {
4060: my ($linktext,$sname,$sdom,$target) = @_;
4061: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
4062: my $title = 'View slot reservation history';
4063: if (defined($sname) && $sname !~ /^\s*$/ &&
4064: defined($sdom) && $sdom !~ /^\s*$/) {
4065: $link .= "&uname=$sname&udom=$sdom";
4066: $title .= ' of this student';
4067: }
4068: if (defined($target) && $target !~ /^\s*$/) {
4069: $target = qq{target="$target"};
4070: } else {
4071: $target = '';
4072: }
4073: $title = &mt($title);
4074: $linktext = &mt($linktext);
4075: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4076: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4077:
4078: }
4079:
1.508 www 4080: # ===================================================== Display a student photo
4081:
4082:
1.509 albertel 4083: sub student_image_tag {
1.508 www 4084: my ($domain,$user)=@_;
4085: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4086: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4087: return '<img src="'.$imgsrc.'" align="right" />';
4088: } else {
4089: return '';
4090: }
4091: }
4092:
1.112 bowersj2 4093: =pod
4094:
4095: =back
4096:
4097: =head1 Access .tab File Data
4098:
4099: =over 4
4100:
1.648 raeburn 4101: =item * &languageids()
1.112 bowersj2 4102:
4103: returns list of all language ids
4104:
4105: =cut
4106:
1.14 harris41 4107: sub languageids {
1.16 harris41 4108: return sort(keys(%language));
1.14 harris41 4109: }
4110:
1.112 bowersj2 4111: =pod
4112:
1.648 raeburn 4113: =item * &languagedescription()
1.112 bowersj2 4114:
4115: returns description of a specified language id
4116:
4117: =cut
4118:
1.14 harris41 4119: sub languagedescription {
1.125 www 4120: my $code=shift;
4121: return ($supported_language{$code}?'* ':'').
4122: $language{$code}.
1.126 www 4123: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4124: }
4125:
1.1048 foxr 4126: =pod
4127:
4128: =item * &plainlanguagedescription
4129:
4130: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4131: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4132:
4133: =cut
4134:
1.145 www 4135: sub plainlanguagedescription {
4136: my $code=shift;
4137: return $language{$code};
4138: }
4139:
1.1048 foxr 4140: =pod
4141:
4142: =item * &supportedlanguagecode
4143:
4144: Returns the supported language code (e.g. sptutf maps to pt) given a language
4145: code.
4146:
4147: =cut
4148:
1.145 www 4149: sub supportedlanguagecode {
4150: my $code=shift;
4151: return $supported_language{$code};
1.97 www 4152: }
4153:
1.112 bowersj2 4154: =pod
4155:
1.1048 foxr 4156: =item * &latexlanguage()
4157:
4158: Given a language key code returns the correspondnig language to use
4159: to select the correct hyphenation on LaTeX printouts. This is undef if there
4160: is no supported hyphenation for the language code.
4161:
4162: =cut
4163:
4164: sub latexlanguage {
4165: my $code = shift;
4166: return $latex_language{$code};
4167: }
4168:
4169: =pod
4170:
4171: =item * &latexhyphenation()
4172:
4173: Same as above but what's supplied is the language as it might be stored
4174: in the metadata.
4175:
4176: =cut
4177:
4178: sub latexhyphenation {
4179: my $key = shift;
4180: return $latex_language_bykey{$key};
4181: }
4182:
4183: =pod
4184:
1.648 raeburn 4185: =item * ©rightids()
1.112 bowersj2 4186:
4187: returns list of all copyrights
4188:
4189: =cut
4190:
4191: sub copyrightids {
4192: return sort(keys(%cprtag));
4193: }
4194:
4195: =pod
4196:
1.648 raeburn 4197: =item * ©rightdescription()
1.112 bowersj2 4198:
4199: returns description of a specified copyright id
4200:
4201: =cut
4202:
4203: sub copyrightdescription {
1.166 www 4204: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4205: }
1.197 matthew 4206:
4207: =pod
4208:
1.648 raeburn 4209: =item * &source_copyrightids()
1.192 taceyjo1 4210:
4211: returns list of all source copyrights
4212:
4213: =cut
4214:
4215: sub source_copyrightids {
4216: return sort(keys(%scprtag));
4217: }
4218:
4219: =pod
4220:
1.648 raeburn 4221: =item * &source_copyrightdescription()
1.192 taceyjo1 4222:
4223: returns description of a specified source copyright id
4224:
4225: =cut
4226:
4227: sub source_copyrightdescription {
4228: return &mt($scprtag{shift(@_)});
4229: }
1.112 bowersj2 4230:
4231: =pod
4232:
1.648 raeburn 4233: =item * &filecategories()
1.112 bowersj2 4234:
4235: returns list of all file categories
4236:
4237: =cut
4238:
4239: sub filecategories {
4240: return sort(keys(%category_extensions));
4241: }
4242:
4243: =pod
4244:
1.648 raeburn 4245: =item * &filecategorytypes()
1.112 bowersj2 4246:
4247: returns list of file types belonging to a given file
4248: category
4249:
4250: =cut
4251:
4252: sub filecategorytypes {
1.356 albertel 4253: my ($cat) = @_;
1.1248 raeburn 4254: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4255: return @{$category_extensions{lc($cat)}};
4256: } else {
4257: return ();
4258: }
1.112 bowersj2 4259: }
4260:
4261: =pod
4262:
1.648 raeburn 4263: =item * &fileembstyle()
1.112 bowersj2 4264:
4265: returns embedding style for a specified file type
4266:
4267: =cut
4268:
4269: sub fileembstyle {
4270: return $fe{lc(shift(@_))};
1.169 www 4271: }
4272:
1.351 www 4273: sub filemimetype {
4274: return $fm{lc(shift(@_))};
4275: }
4276:
1.169 www 4277:
4278: sub filecategoryselect {
4279: my ($name,$value)=@_;
1.189 matthew 4280: return &select_form($value,$name,
1.970 raeburn 4281: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4282: }
4283:
4284: =pod
4285:
1.648 raeburn 4286: =item * &filedescription()
1.112 bowersj2 4287:
4288: returns description for a specified file type
4289:
4290: =cut
4291:
4292: sub filedescription {
1.188 matthew 4293: my $file_description = $fd{lc(shift())};
4294: $file_description =~ s:([\[\]]):~$1:g;
4295: return &mt($file_description);
1.112 bowersj2 4296: }
4297:
4298: =pod
4299:
1.648 raeburn 4300: =item * &filedescriptionex()
1.112 bowersj2 4301:
4302: returns description for a specified file type with
4303: extra formatting
4304:
4305: =cut
4306:
4307: sub filedescriptionex {
4308: my $ex=shift;
1.188 matthew 4309: my $file_description = $fd{lc($ex)};
4310: $file_description =~ s:([\[\]]):~$1:g;
4311: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4312: }
4313:
4314: # End of .tab access
4315: =pod
4316:
4317: =back
4318:
4319: =cut
4320:
4321: # ------------------------------------------------------------------ File Types
4322: sub fileextensions {
4323: return sort(keys(%fe));
4324: }
4325:
1.97 www 4326: # ----------------------------------------------------------- Display Languages
4327: # returns a hash with all desired display languages
4328: #
4329:
4330: sub display_languages {
4331: my %languages=();
1.695 raeburn 4332: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4333: $languages{$lang}=1;
1.97 www 4334: }
4335: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4336: if ($env{'form.displaylanguage'}) {
1.356 albertel 4337: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4338: $languages{$lang}=1;
1.97 www 4339: }
4340: }
4341: return %languages;
1.14 harris41 4342: }
4343:
1.582 albertel 4344: sub languages {
4345: my ($possible_langs) = @_;
1.695 raeburn 4346: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4347: if (!ref($possible_langs)) {
4348: if( wantarray ) {
4349: return @preferred_langs;
4350: } else {
4351: return $preferred_langs[0];
4352: }
4353: }
4354: my %possibilities = map { $_ => 1 } (@$possible_langs);
4355: my @preferred_possibilities;
4356: foreach my $preferred_lang (@preferred_langs) {
4357: if (exists($possibilities{$preferred_lang})) {
4358: push(@preferred_possibilities, $preferred_lang);
4359: }
4360: }
4361: if( wantarray ) {
4362: return @preferred_possibilities;
4363: }
4364: return $preferred_possibilities[0];
4365: }
4366:
1.742 raeburn 4367: sub user_lang {
4368: my ($touname,$toudom,$fromcid) = @_;
4369: my @userlangs;
4370: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4371: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4372: $env{'course.'.$fromcid.'.languages'}));
4373: } else {
4374: my %langhash = &getlangs($touname,$toudom);
4375: if ($langhash{'languages'} ne '') {
4376: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4377: } else {
4378: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4379: if ($domdefs{'lang_def'} ne '') {
4380: @userlangs = ($domdefs{'lang_def'});
4381: }
4382: }
4383: }
4384: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4385: my $user_lh = Apache::localize->get_handle(@languages);
4386: return $user_lh;
4387: }
4388:
4389:
1.112 bowersj2 4390: ###############################################################
4391: ## Student Answer Attempts ##
4392: ###############################################################
4393:
4394: =pod
4395:
4396: =head1 Alternate Problem Views
4397:
4398: =over 4
4399:
1.648 raeburn 4400: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4401: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4402:
4403: Return string with previous attempt on problem. Arguments:
4404:
4405: =over 4
4406:
4407: =item * $symb: Problem, including path
4408:
4409: =item * $username: username of the desired student
4410:
4411: =item * $domain: domain of the desired student
1.14 harris41 4412:
1.112 bowersj2 4413: =item * $course: Course ID
1.14 harris41 4414:
1.112 bowersj2 4415: =item * $getattempt: Leave blank for all attempts, otherwise put
4416: something
1.14 harris41 4417:
1.112 bowersj2 4418: =item * $regexp: if string matches this regexp, the string will be
4419: sent to $gradesub
1.14 harris41 4420:
1.112 bowersj2 4421: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4422:
1.1199 raeburn 4423: =item * $usec: section of the desired student
4424:
4425: =item * $identifier: counter for student (multiple students one problem) or
4426: problem (one student; whole sequence).
4427:
1.112 bowersj2 4428: =back
1.14 harris41 4429:
1.112 bowersj2 4430: The output string is a table containing all desired attempts, if any.
1.16 harris41 4431:
1.112 bowersj2 4432: =cut
1.1 albertel 4433:
4434: sub get_previous_attempt {
1.1199 raeburn 4435: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4436: my $prevattempts='';
1.43 ng 4437: no strict 'refs';
1.1 albertel 4438: if ($symb) {
1.3 albertel 4439: my (%returnhash)=
4440: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4441: if ($returnhash{'version'}) {
4442: my %lasthash=();
4443: my $version;
4444: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4445: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4446: if ($key =~ /\.rawrndseed$/) {
4447: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4448: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4449: } else {
4450: $lasthash{$key}=$returnhash{$version.':'.$key};
4451: }
1.19 harris41 4452: }
1.1 albertel 4453: }
1.596 albertel 4454: $prevattempts=&start_data_table().&start_data_table_header_row();
4455: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4456: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4457: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4458: foreach my $key (sort(keys(%lasthash))) {
4459: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4460: if ($#parts > 0) {
1.31 albertel 4461: my $data=$parts[-1];
1.989 raeburn 4462: next if ($data eq 'foilorder');
1.31 albertel 4463: pop(@parts);
1.1010 www 4464: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4465: if ($data eq 'type') {
4466: unless ($showsurv) {
4467: my $id = join(',',@parts);
4468: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4469: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4470: $lasthidden{$ign.'.'.$id} = 1;
4471: }
1.945 raeburn 4472: }
1.1199 raeburn 4473: if ($identifier ne '') {
4474: my $id = join(',',@parts);
4475: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4476: $domain,$username,$usec,undef,$course) =~ /^no/) {
4477: $hidestatus{$ign.'.'.$id} = 1;
4478: }
4479: }
4480: } elsif ($data eq 'regrader') {
4481: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4482: my $id = join(',',@parts);
4483: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4484: }
1.1010 www 4485: }
1.31 albertel 4486: } else {
1.41 ng 4487: if ($#parts == 0) {
4488: $prevattempts.='<th>'.$parts[0].'</th>';
4489: } else {
4490: $prevattempts.='<th>'.$ign.'</th>';
4491: }
1.31 albertel 4492: }
1.16 harris41 4493: }
1.596 albertel 4494: $prevattempts.=&end_data_table_header_row();
1.40 ng 4495: if ($getattempt eq '') {
1.1199 raeburn 4496: my (%solved,%resets,%probstatus);
1.1200 raeburn 4497: if (($identifier ne '') && (keys(%regraded) > 0)) {
4498: for ($version=1;$version<=$returnhash{'version'};$version++) {
4499: foreach my $id (keys(%regraded)) {
4500: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4501: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4502: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4503: push(@{$resets{$id}},$version);
1.1199 raeburn 4504: }
4505: }
4506: }
1.1200 raeburn 4507: }
4508: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4509: my (@hidden,@unsolved);
1.945 raeburn 4510: if (%typeparts) {
4511: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4512: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4513: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4514: push(@hidden,$id);
1.1199 raeburn 4515: } elsif ($identifier ne '') {
4516: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4517: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4518: ($hidestatus{$id})) {
1.1200 raeburn 4519: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4520: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4521: push(@{$solved{$id}},$version);
4522: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4523: (ref($solved{$id}) eq 'ARRAY')) {
4524: my $skip;
4525: if (ref($resets{$id}) eq 'ARRAY') {
4526: foreach my $reset (@{$resets{$id}}) {
4527: if ($reset > $solved{$id}[-1]) {
4528: $skip=1;
4529: last;
4530: }
4531: }
4532: }
4533: unless ($skip) {
4534: my ($ign,$partslist) = split(/\./,$id,2);
4535: push(@unsolved,$partslist);
4536: }
4537: }
4538: }
1.945 raeburn 4539: }
4540: }
4541: }
4542: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4543: '<td>'.&mt('Transaction [_1]',$version);
4544: if (@unsolved) {
4545: $prevattempts .= '<span class="LC_nobreak"><label>'.
4546: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4547: &mt('Hide').'</label></span>';
4548: }
4549: $prevattempts .= '</td>';
1.945 raeburn 4550: if (@hidden) {
4551: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4552: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4553: my $hide;
4554: foreach my $id (@hidden) {
4555: if ($key =~ /^\Q$id\E/) {
4556: $hide = 1;
4557: last;
4558: }
4559: }
4560: if ($hide) {
4561: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4562: if (($data eq 'award') || ($data eq 'awarddetail')) {
4563: my $value = &format_previous_attempt_value($key,
4564: $returnhash{$version.':'.$key});
1.1173 kruse 4565: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4566: } else {
4567: $prevattempts.='<td> </td>';
4568: }
4569: } else {
4570: if ($key =~ /\./) {
1.1212 raeburn 4571: my $value = $returnhash{$version.':'.$key};
4572: if ($key =~ /\.rndseed$/) {
4573: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4574: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4575: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4576: }
4577: }
4578: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4579: ' </td>';
1.945 raeburn 4580: } else {
4581: $prevattempts.='<td> </td>';
4582: }
4583: }
4584: }
4585: } else {
4586: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4587: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4588: my $value = $returnhash{$version.':'.$key};
4589: if ($key =~ /\.rndseed$/) {
4590: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4591: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4592: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4593: }
4594: }
4595: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4596: ' </td>';
1.945 raeburn 4597: }
4598: }
4599: $prevattempts.=&end_data_table_row();
1.40 ng 4600: }
1.1 albertel 4601: }
1.945 raeburn 4602: my @currhidden = keys(%lasthidden);
1.596 albertel 4603: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4604: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4605: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4606: if (%typeparts) {
4607: my $hidden;
4608: foreach my $id (@currhidden) {
4609: if ($key =~ /^\Q$id\E/) {
4610: $hidden = 1;
4611: last;
4612: }
4613: }
4614: if ($hidden) {
4615: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4616: if (($data eq 'award') || ($data eq 'awarddetail')) {
4617: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4618: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4619: $value = &$gradesub($value);
4620: }
1.1173 kruse 4621: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4622: } else {
4623: $prevattempts.='<td> </td>';
4624: }
4625: } else {
4626: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4627: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4628: $value = &$gradesub($value);
4629: }
1.1173 kruse 4630: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4631: }
4632: } else {
4633: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4634: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4635: $value = &$gradesub($value);
4636: }
1.1173 kruse 4637: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4638: }
1.16 harris41 4639: }
1.596 albertel 4640: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4641: } else {
1.1305 raeburn 4642: my $msg;
4643: if ($symb =~ /ext\.tool$/) {
4644: $msg = &mt('No grade passed back.');
4645: } else {
4646: $msg = &mt('Nothing submitted - no attempts.');
4647: }
1.596 albertel 4648: $prevattempts=
4649: &start_data_table().&start_data_table_row().
1.1305 raeburn 4650: '<td>'.$msg.'</td>'.
1.596 albertel 4651: &end_data_table_row().&end_data_table();
1.1 albertel 4652: }
4653: } else {
1.596 albertel 4654: $prevattempts=
4655: &start_data_table().&start_data_table_row().
4656: '<td>'.&mt('No data.').'</td>'.
4657: &end_data_table_row().&end_data_table();
1.1 albertel 4658: }
1.10 albertel 4659: }
4660:
1.581 albertel 4661: sub format_previous_attempt_value {
4662: my ($key,$value) = @_;
1.1011 www 4663: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4664: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4665: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4666: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4667: } elsif ($key =~ /answerstring$/) {
4668: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4669: my @answer = %answers;
4670: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4671: my @anskeys = sort(keys(%answers));
4672: if (@anskeys == 1) {
4673: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4674: if ($answer =~ m{\0}) {
4675: $answer =~ s{\0}{,}g;
1.988 raeburn 4676: }
4677: my $tag_internal_answer_name = 'INTERNAL';
4678: if ($anskeys[0] eq $tag_internal_answer_name) {
4679: $value = $answer;
4680: } else {
4681: $value = $anskeys[0].'='.$answer;
4682: }
4683: } else {
4684: foreach my $ans (@anskeys) {
4685: my $answer = $answers{$ans};
1.1001 raeburn 4686: if ($answer =~ m{\0}) {
4687: $answer =~ s{\0}{,}g;
1.988 raeburn 4688: }
4689: $value .= $ans.'='.$answer.'<br />';;
4690: }
4691: }
1.581 albertel 4692: } else {
1.1173 kruse 4693: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4694: }
4695: return $value;
4696: }
4697:
4698:
1.107 albertel 4699: sub relative_to_absolute {
4700: my ($url,$output)=@_;
4701: my $parser=HTML::TokeParser->new(\$output);
4702: my $token;
4703: my $thisdir=$url;
4704: my @rlinks=();
4705: while ($token=$parser->get_token) {
4706: if ($token->[0] eq 'S') {
4707: if ($token->[1] eq 'a') {
4708: if ($token->[2]->{'href'}) {
4709: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4710: }
4711: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4712: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4713: } elsif ($token->[1] eq 'base') {
4714: $thisdir=$token->[2]->{'href'};
4715: }
4716: }
4717: }
4718: $thisdir=~s-/[^/]*$--;
1.356 albertel 4719: foreach my $link (@rlinks) {
1.726 raeburn 4720: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4721: ($link=~/^\//) ||
4722: ($link=~/^javascript:/i) ||
4723: ($link=~/^mailto:/i) ||
4724: ($link=~/^\#/)) {
4725: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4726: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4727: }
4728: }
4729: # -------------------------------------------------- Deal with Applet codebases
4730: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4731: return $output;
4732: }
4733:
1.112 bowersj2 4734: =pod
4735:
1.648 raeburn 4736: =item * &get_student_view()
1.112 bowersj2 4737:
4738: show a snapshot of what student was looking at
4739:
4740: =cut
4741:
1.10 albertel 4742: sub get_student_view {
1.186 albertel 4743: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4744: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4745: my (%form);
1.10 albertel 4746: my @elements=('symb','courseid','domain','username');
4747: foreach my $element (@elements) {
1.186 albertel 4748: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4749: }
1.186 albertel 4750: if (defined($moreenv)) {
4751: %form=(%form,%{$moreenv});
4752: }
1.236 albertel 4753: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4754: $feedurl=&Apache::lonnet::clutter($feedurl);
1.1306 raeburn 4755: if (($feedurl =~ /ext\.tool$/) && ($target eq 'tex')) {
4756: $feedurl =~ s{^/adm/wrapper}{};
4757: }
1.650 www 4758: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4759: $userview=~s/\<body[^\>]*\>//gi;
4760: $userview=~s/\<\/body\>//gi;
4761: $userview=~s/\<html\>//gi;
4762: $userview=~s/\<\/html\>//gi;
4763: $userview=~s/\<head\>//gi;
4764: $userview=~s/\<\/head\>//gi;
4765: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4766: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4767: if (wantarray) {
4768: return ($userview,$response);
4769: } else {
4770: return $userview;
4771: }
4772: }
4773:
4774: sub get_student_view_with_retries {
4775: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4776:
4777: my $ok = 0; # True if we got a good response.
4778: my $content;
4779: my $response;
4780:
4781: # Try to get the student_view done. within the retries count:
4782:
4783: do {
4784: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4785: $ok = $response->is_success;
4786: if (!$ok) {
4787: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4788: }
4789: $retries--;
4790: } while (!$ok && ($retries > 0));
4791:
4792: if (!$ok) {
4793: $content = ''; # On error return an empty content.
4794: }
1.651 www 4795: if (wantarray) {
4796: return ($content, $response);
4797: } else {
4798: return $content;
4799: }
1.11 albertel 4800: }
4801:
1.112 bowersj2 4802: =pod
4803:
1.648 raeburn 4804: =item * &get_student_answers()
1.112 bowersj2 4805:
4806: show a snapshot of how student was answering problem
4807:
4808: =cut
4809:
1.11 albertel 4810: sub get_student_answers {
1.100 sakharuk 4811: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4812: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4813: my (%moreenv);
1.11 albertel 4814: my @elements=('symb','courseid','domain','username');
4815: foreach my $element (@elements) {
1.186 albertel 4816: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4817: }
1.186 albertel 4818: $moreenv{'grade_target'}='answer';
4819: %moreenv=(%form,%moreenv);
1.497 raeburn 4820: $feedurl = &Apache::lonnet::clutter($feedurl);
4821: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4822: return $userview;
1.1 albertel 4823: }
1.116 albertel 4824:
4825: =pod
4826:
4827: =item * &submlink()
4828:
1.242 albertel 4829: Inputs: $text $uname $udom $symb $target
1.116 albertel 4830:
4831: Returns: A link to grades.pm such as to see the SUBM view of a student
4832:
4833: =cut
4834:
4835: ###############################################
4836: sub submlink {
1.242 albertel 4837: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4838: if (!($uname && $udom)) {
4839: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4840: &Apache::lonnet::whichuser($symb);
1.116 albertel 4841: if (!$symb) { $symb=$cursymb; }
4842: }
1.254 matthew 4843: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4844: $symb=&escape($symb);
1.960 bisitz 4845: if ($target) { $target=" target=\"$target\""; }
4846: return
4847: '<a href="/adm/grades?command=submission'.
4848: '&symb='.$symb.
4849: '&student='.$uname.
4850: '&userdom='.$udom.'"'.
4851: $target.'>'.$text.'</a>';
1.242 albertel 4852: }
4853: ##############################################
4854:
4855: =pod
4856:
4857: =item * &pgrdlink()
4858:
4859: Inputs: $text $uname $udom $symb $target
4860:
4861: Returns: A link to grades.pm such as to see the PGRD view of a student
4862:
4863: =cut
4864:
4865: ###############################################
4866: sub pgrdlink {
4867: my $link=&submlink(@_);
4868: $link=~s/(&command=submission)/$1&showgrading=yes/;
4869: return $link;
4870: }
4871: ##############################################
4872:
4873: =pod
4874:
4875: =item * &pprmlink()
4876:
4877: Inputs: $text $uname $udom $symb $target
4878:
4879: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4880: student and a specific resource
1.242 albertel 4881:
4882: =cut
4883:
4884: ###############################################
4885: sub pprmlink {
4886: my ($text,$uname,$udom,$symb,$target)=@_;
4887: if (!($uname && $udom)) {
4888: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4889: &Apache::lonnet::whichuser($symb);
1.242 albertel 4890: if (!$symb) { $symb=$cursymb; }
4891: }
1.254 matthew 4892: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4893: $symb=&escape($symb);
1.242 albertel 4894: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4895: return '<a href="/adm/parmset?command=set&'.
4896: 'symb='.$symb.'&uname='.$uname.
4897: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4898: }
4899: ##############################################
1.37 matthew 4900:
1.112 bowersj2 4901: =pod
4902:
4903: =back
4904:
4905: =cut
4906:
1.37 matthew 4907: ###############################################
1.51 www 4908:
4909:
4910: sub timehash {
1.687 raeburn 4911: my ($thistime) = @_;
4912: my $timezone = &Apache::lonlocal::gettimezone();
4913: my $dt = DateTime->from_epoch(epoch => $thistime)
4914: ->set_time_zone($timezone);
4915: my $wday = $dt->day_of_week();
4916: if ($wday == 7) { $wday = 0; }
4917: return ( 'second' => $dt->second(),
4918: 'minute' => $dt->minute(),
4919: 'hour' => $dt->hour(),
4920: 'day' => $dt->day_of_month(),
4921: 'month' => $dt->month(),
4922: 'year' => $dt->year(),
4923: 'weekday' => $wday,
4924: 'dayyear' => $dt->day_of_year(),
4925: 'dlsav' => $dt->is_dst() );
1.51 www 4926: }
4927:
1.370 www 4928: sub utc_string {
4929: my ($date)=@_;
1.371 www 4930: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4931: }
4932:
1.51 www 4933: sub maketime {
4934: my %th=@_;
1.687 raeburn 4935: my ($epoch_time,$timezone,$dt);
4936: $timezone = &Apache::lonlocal::gettimezone();
4937: eval {
4938: $dt = DateTime->new( year => $th{'year'},
4939: month => $th{'month'},
4940: day => $th{'day'},
4941: hour => $th{'hour'},
4942: minute => $th{'minute'},
4943: second => $th{'second'},
4944: time_zone => $timezone,
4945: );
4946: };
4947: if (!$@) {
4948: $epoch_time = $dt->epoch;
4949: if ($epoch_time) {
4950: return $epoch_time;
4951: }
4952: }
1.51 www 4953: return POSIX::mktime(
4954: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4955: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4956: }
4957:
4958: #########################################
1.51 www 4959:
4960: sub findallcourses {
1.482 raeburn 4961: my ($roles,$uname,$udom) = @_;
1.355 albertel 4962: my %roles;
4963: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4964: my %courses;
1.51 www 4965: my $now=time;
1.482 raeburn 4966: if (!defined($uname)) {
4967: $uname = $env{'user.name'};
4968: }
4969: if (!defined($udom)) {
4970: $udom = $env{'user.domain'};
4971: }
4972: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4973: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4974: if (!%roles) {
4975: %roles = (
4976: cc => 1,
1.907 raeburn 4977: co => 1,
1.482 raeburn 4978: in => 1,
4979: ep => 1,
4980: ta => 1,
4981: cr => 1,
4982: st => 1,
4983: );
4984: }
4985: foreach my $entry (keys(%roleshash)) {
4986: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4987: if ($trole =~ /^cr/) {
4988: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4989: } else {
4990: next if (!exists($roles{$trole}));
4991: }
4992: if ($tend) {
4993: next if ($tend < $now);
4994: }
4995: if ($tstart) {
4996: next if ($tstart > $now);
4997: }
1.1058 raeburn 4998: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4999: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 5000: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 5001: if ($secpart eq '') {
5002: ($cnum,$role) = split(/_/,$cnumpart);
5003: $sec = 'none';
1.1058 raeburn 5004: $value .= $cnum.'/';
1.482 raeburn 5005: } else {
5006: $cnum = $cnumpart;
5007: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 5008: $value .= $cnum.'/'.$sec;
5009: }
5010: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5011: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5012: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5013: }
5014: } else {
5015: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 5016: }
1.482 raeburn 5017: }
5018: } else {
5019: foreach my $key (keys(%env)) {
1.483 albertel 5020: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
5021: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 5022: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
5023: next if ($role eq 'ca' || $role eq 'aa');
5024: next if (%roles && !exists($roles{$role}));
5025: my ($starttime,$endtime)=split(/\./,$env{$key});
5026: my $active=1;
5027: if ($starttime) {
5028: if ($now<$starttime) { $active=0; }
5029: }
5030: if ($endtime) {
5031: if ($now>$endtime) { $active=0; }
5032: }
5033: if ($active) {
1.1058 raeburn 5034: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 5035: if ($sec eq '') {
5036: $sec = 'none';
1.1058 raeburn 5037: } else {
5038: $value .= $sec;
5039: }
5040: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
5041: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
5042: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
5043: }
5044: } else {
5045: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 5046: }
1.474 raeburn 5047: }
5048: }
1.51 www 5049: }
5050: }
1.474 raeburn 5051: return %courses;
1.51 www 5052: }
1.37 matthew 5053:
1.54 www 5054: ###############################################
1.474 raeburn 5055:
5056: sub blockcheck {
1.1189 raeburn 5057: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 5058:
1.1189 raeburn 5059: if (defined($udom) && defined($uname)) {
5060: # If uname and udom are for a course, check for blocks in the course.
5061: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
5062: my ($startblock,$endblock,$triggerblock) =
5063: &get_blocks($setters,$activity,$udom,$uname,$url);
5064: return ($startblock,$endblock,$triggerblock);
5065: }
5066: } else {
1.490 raeburn 5067: $udom = $env{'user.domain'};
5068: $uname = $env{'user.name'};
5069: }
5070:
1.502 raeburn 5071: my $startblock = 0;
5072: my $endblock = 0;
1.1062 raeburn 5073: my $triggerblock = '';
1.482 raeburn 5074: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 5075:
1.490 raeburn 5076: # If uname is for a user, and activity is course-specific, i.e.,
5077: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 5078:
1.490 raeburn 5079: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1282 raeburn 5080: $activity eq 'groups' || $activity eq 'printout' ||
5081: $activity eq 'reinit' || $activity eq 'alert') &&
1.1189 raeburn 5082: ($env{'request.course.id'})) {
1.490 raeburn 5083: foreach my $key (keys(%live_courses)) {
5084: if ($key ne $env{'request.course.id'}) {
5085: delete($live_courses{$key});
5086: }
5087: }
5088: }
5089:
5090: my $otheruser = 0;
5091: my %own_courses;
5092: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5093: # Resource belongs to user other than current user.
5094: $otheruser = 1;
5095: # Gather courses for current user
5096: %own_courses =
5097: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5098: }
5099:
5100: # Gather active course roles - course coordinator, instructor,
5101: # exam proctor, ta, student, or custom role.
1.474 raeburn 5102:
5103: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5104: my ($cdom,$cnum);
5105: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5106: $cdom = $env{'course.'.$course.'.domain'};
5107: $cnum = $env{'course.'.$course.'.num'};
5108: } else {
1.490 raeburn 5109: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5110: }
5111: my $no_ownblock = 0;
5112: my $no_userblock = 0;
1.533 raeburn 5113: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5114: # Check if current user has 'evb' priv for this
5115: if (defined($own_courses{$course})) {
5116: foreach my $sec (keys(%{$own_courses{$course}})) {
5117: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5118: if ($sec ne 'none') {
5119: $checkrole .= '/'.$sec;
5120: }
5121: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5122: $no_ownblock = 1;
5123: last;
5124: }
5125: }
5126: }
5127: # if they have 'evb' priv and are currently not playing student
5128: next if (($no_ownblock) &&
5129: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5130: }
1.474 raeburn 5131: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5132: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5133: if ($sec ne 'none') {
1.482 raeburn 5134: $checkrole .= '/'.$sec;
1.474 raeburn 5135: }
1.490 raeburn 5136: if ($otheruser) {
5137: # Resource belongs to user other than current user.
5138: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5139: my (%allroles,%userroles);
5140: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5141: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5142: my ($trole,$tdom,$tnum,$tsec);
5143: if ($entry =~ /^cr/) {
5144: ($trole,$tdom,$tnum,$tsec) =
5145: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5146: } else {
5147: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5148: }
5149: my ($spec,$area,$trest);
5150: $area = '/'.$tdom.'/'.$tnum;
5151: $trest = $tnum;
5152: if ($tsec ne '') {
5153: $area .= '/'.$tsec;
5154: $trest .= '/'.$tsec;
5155: }
5156: $spec = $trole.'.'.$area;
5157: if ($trole =~ /^cr/) {
5158: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5159: $tdom,$spec,$trest,$area);
5160: } else {
5161: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5162: $tdom,$spec,$trest,$area);
5163: }
5164: }
1.1276 raeburn 5165: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5166: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5167: if ($1) {
5168: $no_userblock = 1;
5169: last;
5170: }
1.486 raeburn 5171: }
5172: }
1.490 raeburn 5173: } else {
5174: # Resource belongs to current user
5175: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5176: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5177: $no_ownblock = 1;
5178: last;
5179: }
1.474 raeburn 5180: }
5181: }
5182: # if they have the evb priv and are currently not playing student
1.482 raeburn 5183: next if (($no_ownblock) &&
1.491 albertel 5184: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5185: next if ($no_userblock);
1.474 raeburn 5186:
1.1303 raeburn 5187: # Retrieve blocking times and identity of blocker for course
1.490 raeburn 5188: # of specified user, unless user has 'evb' privilege.
1.1284 raeburn 5189:
1.1062 raeburn 5190: my ($start,$end,$trigger) =
5191: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 5192: if (($start != 0) &&
5193: (($startblock == 0) || ($startblock > $start))) {
5194: $startblock = $start;
1.1062 raeburn 5195: if ($trigger ne '') {
5196: $triggerblock = $trigger;
5197: }
1.502 raeburn 5198: }
5199: if (($end != 0) &&
5200: (($endblock == 0) || ($endblock < $end))) {
5201: $endblock = $end;
1.1062 raeburn 5202: if ($trigger ne '') {
5203: $triggerblock = $trigger;
5204: }
1.502 raeburn 5205: }
1.490 raeburn 5206: }
1.1062 raeburn 5207: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5208: }
5209:
5210: sub get_blocks {
1.1062 raeburn 5211: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 5212: my $startblock = 0;
5213: my $endblock = 0;
1.1062 raeburn 5214: my $triggerblock = '';
1.490 raeburn 5215: my $course = $cdom.'_'.$cnum;
5216: $setters->{$course} = {};
5217: $setters->{$course}{'staff'} = [];
5218: $setters->{$course}{'times'} = [];
1.1062 raeburn 5219: $setters->{$course}{'triggers'} = [];
5220: my (@blockers,%triggered);
5221: my $now = time;
5222: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5223: if ($activity eq 'docs') {
5224: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
5225: foreach my $block (@blockers) {
5226: if ($block =~ /^firstaccess____(.+)$/) {
5227: my $item = $1;
5228: my $type = 'map';
5229: my $timersymb = $item;
5230: if ($item eq 'course') {
5231: $type = 'course';
5232: } elsif ($item =~ /___\d+___/) {
5233: $type = 'resource';
5234: } else {
5235: $timersymb = &Apache::lonnet::symbread($item);
5236: }
5237: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5238: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5239: $triggered{$block} = {
5240: start => $start,
5241: end => $end,
5242: type => $type,
5243: };
5244: }
5245: }
5246: } else {
5247: foreach my $block (keys(%commblocks)) {
5248: if ($block =~ m/^(\d+)____(\d+)$/) {
5249: my ($start,$end) = ($1,$2);
5250: if ($start <= time && $end >= time) {
5251: if (ref($commblocks{$block}) eq 'HASH') {
5252: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5253: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5254: unless(grep(/^\Q$block\E$/,@blockers)) {
5255: push(@blockers,$block);
5256: }
5257: }
5258: }
5259: }
5260: }
5261: } elsif ($block =~ /^firstaccess____(.+)$/) {
5262: my $item = $1;
5263: my $timersymb = $item;
5264: my $type = 'map';
5265: if ($item eq 'course') {
5266: $type = 'course';
5267: } elsif ($item =~ /___\d+___/) {
5268: $type = 'resource';
5269: } else {
5270: $timersymb = &Apache::lonnet::symbread($item);
5271: }
5272: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5273: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5274: if ($start && $end) {
5275: if (($start <= time) && ($end >= time)) {
1.1281 raeburn 5276: if (ref($commblocks{$block}) eq 'HASH') {
5277: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5278: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5279: unless(grep(/^\Q$block\E$/,@blockers)) {
5280: push(@blockers,$block);
5281: $triggered{$block} = {
5282: start => $start,
5283: end => $end,
5284: type => $type,
5285: };
5286: }
5287: }
5288: }
1.1062 raeburn 5289: }
5290: }
1.490 raeburn 5291: }
1.1062 raeburn 5292: }
5293: }
5294: }
5295: foreach my $blocker (@blockers) {
5296: my ($staff_name,$staff_dom,$title,$blocks) =
5297: &parse_block_record($commblocks{$blocker});
5298: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5299: my ($start,$end,$triggertype);
5300: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5301: ($start,$end) = ($1,$2);
5302: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5303: $start = $triggered{$blocker}{'start'};
5304: $end = $triggered{$blocker}{'end'};
5305: $triggertype = $triggered{$blocker}{'type'};
5306: }
5307: if ($start) {
5308: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5309: if ($triggertype) {
5310: push(@{$$setters{$course}{'triggers'}},$triggertype);
5311: } else {
5312: push(@{$$setters{$course}{'triggers'}},0);
5313: }
5314: if ( ($startblock == 0) || ($startblock > $start) ) {
5315: $startblock = $start;
5316: if ($triggertype) {
5317: $triggerblock = $blocker;
1.474 raeburn 5318: }
5319: }
1.1062 raeburn 5320: if ( ($endblock == 0) || ($endblock < $end) ) {
5321: $endblock = $end;
5322: if ($triggertype) {
5323: $triggerblock = $blocker;
5324: }
5325: }
1.474 raeburn 5326: }
5327: }
1.1062 raeburn 5328: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5329: }
5330:
5331: sub parse_block_record {
5332: my ($record) = @_;
5333: my ($setuname,$setudom,$title,$blocks);
5334: if (ref($record) eq 'HASH') {
5335: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5336: $title = &unescape($record->{'event'});
5337: $blocks = $record->{'blocks'};
5338: } else {
5339: my @data = split(/:/,$record,3);
5340: if (scalar(@data) eq 2) {
5341: $title = $data[1];
5342: ($setuname,$setudom) = split(/@/,$data[0]);
5343: } else {
5344: ($setuname,$setudom,$title) = @data;
5345: }
5346: $blocks = { 'com' => 'on' };
5347: }
5348: return ($setuname,$setudom,$title,$blocks);
5349: }
5350:
1.854 kalberla 5351: sub blocking_status {
1.1189 raeburn 5352: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 5353: my %setters;
1.890 droeschl 5354:
1.1061 raeburn 5355: # check for active blocking
1.1062 raeburn 5356: my ($startblock,$endblock,$triggerblock) =
1.1189 raeburn 5357: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 5358: my $blocked = 0;
5359: if ($startblock && $endblock) {
5360: $blocked = 1;
5361: }
1.890 droeschl 5362:
1.1061 raeburn 5363: # caller just wants to know whether a block is active
5364: if (!wantarray) { return $blocked; }
5365:
5366: # build a link to a popup window containing the details
5367: my $querystring = "?activity=$activity";
5368: # $uname and $udom decide whose portfolio the user is trying to look at
1.1232 raeburn 5369: if (($activity eq 'port') || ($activity eq 'passwd')) {
5370: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5371: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5372: } elsif ($activity eq 'docs') {
5373: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
5374: }
1.1061 raeburn 5375:
5376: my $output .= <<'END_MYBLOCK';
5377: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5378: var options = "width=" + w + ",height=" + h + ",";
5379: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5380: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5381: var newWin = window.open(url, wdwName, options);
5382: newWin.focus();
5383: }
1.890 droeschl 5384: END_MYBLOCK
1.854 kalberla 5385:
1.1061 raeburn 5386: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5387:
1.1061 raeburn 5388: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5389: my $text = &mt('Communication Blocked');
1.1217 raeburn 5390: my $class = 'LC_comblock';
1.1062 raeburn 5391: if ($activity eq 'docs') {
5392: $text = &mt('Content Access Blocked');
1.1217 raeburn 5393: $class = '';
1.1063 raeburn 5394: } elsif ($activity eq 'printout') {
5395: $text = &mt('Printing Blocked');
1.1232 raeburn 5396: } elsif ($activity eq 'passwd') {
5397: $text = &mt('Password Changing Blocked');
1.1282 raeburn 5398: } elsif ($activity eq 'alert') {
5399: $text = &mt('Checking Critical Messages Blocked');
5400: } elsif ($activity eq 'reinit') {
5401: $text = &mt('Checking Course Update Blocked');
1.1062 raeburn 5402: }
1.1061 raeburn 5403: $output .= <<"END_BLOCK";
1.1217 raeburn 5404: <div class='$class'>
1.869 kalberla 5405: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5406: title='$text'>
5407: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5408: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5409: title='$text'>$text</a>
1.867 kalberla 5410: </div>
5411:
5412: END_BLOCK
1.474 raeburn 5413:
1.1061 raeburn 5414: return ($blocked, $output);
1.854 kalberla 5415: }
1.490 raeburn 5416:
1.60 matthew 5417: ###############################################
5418:
1.682 raeburn 5419: sub check_ip_acc {
1.1201 raeburn 5420: my ($acc,$clientip)=@_;
1.682 raeburn 5421: &Apache::lonxml::debug("acc is $acc");
5422: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5423: return 1;
5424: }
1.1219 raeburn 5425: my $allowed;
1.1252 raeburn 5426: my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682 raeburn 5427:
5428: my $name;
1.1219 raeburn 5429: my %access = (
5430: allowfrom => 1,
5431: denyfrom => 0,
5432: );
5433: my @allows;
5434: my @denies;
5435: foreach my $item (split(',',$acc)) {
5436: $item =~ s/^\s*//;
5437: $item =~ s/\s*$//;
5438: my $pattern;
5439: if ($item =~ /^\!(.+)$/) {
5440: push(@denies,$1);
5441: } else {
5442: push(@allows,$item);
5443: }
5444: }
5445: my $numdenies = scalar(@denies);
5446: my $numallows = scalar(@allows);
5447: my $count = 0;
5448: foreach my $pattern (@denies,@allows) {
5449: $count ++;
5450: my $acctype = 'allowfrom';
5451: if ($count <= $numdenies) {
5452: $acctype = 'denyfrom';
5453: }
1.682 raeburn 5454: if ($pattern =~ /\*$/) {
5455: #35.8.*
5456: $pattern=~s/\*//;
1.1219 raeburn 5457: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5458: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5459: #35.8.3.[34-56]
5460: my $low=$2;
5461: my $high=$3;
5462: $pattern=$1;
5463: if ($ip =~ /^\Q$pattern\E/) {
5464: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5465: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5466: }
5467: } elsif ($pattern =~ /^\*/) {
5468: #*.msu.edu
5469: $pattern=~s/\*//;
5470: if (!defined($name)) {
5471: use Socket;
5472: my $netaddr=inet_aton($ip);
5473: ($name)=gethostbyaddr($netaddr,AF_INET);
5474: }
1.1219 raeburn 5475: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5476: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5477: #127.0.0.1
1.1219 raeburn 5478: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5479: } else {
5480: #some.name.com
5481: if (!defined($name)) {
5482: use Socket;
5483: my $netaddr=inet_aton($ip);
5484: ($name)=gethostbyaddr($netaddr,AF_INET);
5485: }
1.1219 raeburn 5486: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5487: }
5488: if ($allowed =~ /^(0|1)$/) { last; }
5489: }
5490: if ($allowed eq '') {
5491: if ($numdenies && !$numallows) {
5492: $allowed = 1;
5493: } else {
5494: $allowed = 0;
1.682 raeburn 5495: }
5496: }
5497: return $allowed;
5498: }
5499:
5500: ###############################################
5501:
1.60 matthew 5502: =pod
5503:
1.112 bowersj2 5504: =head1 Domain Template Functions
5505:
5506: =over 4
5507:
5508: =item * &determinedomain()
1.60 matthew 5509:
5510: Inputs: $domain (usually will be undef)
5511:
1.63 www 5512: Returns: Determines which domain should be used for designs
1.60 matthew 5513:
5514: =cut
1.54 www 5515:
1.60 matthew 5516: ###############################################
1.63 www 5517: sub determinedomain {
5518: my $domain=shift;
1.531 albertel 5519: if (! $domain) {
1.60 matthew 5520: # Determine domain if we have not been given one
1.893 raeburn 5521: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5522: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5523: if ($env{'request.role.domain'}) {
5524: $domain=$env{'request.role.domain'};
1.60 matthew 5525: }
5526: }
1.63 www 5527: return $domain;
5528: }
5529: ###############################################
1.517 raeburn 5530:
1.518 albertel 5531: sub devalidate_domconfig_cache {
5532: my ($udom)=@_;
5533: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5534: }
5535:
5536: # ---------------------- Get domain configuration for a domain
5537: sub get_domainconf {
5538: my ($udom) = @_;
5539: my $cachetime=1800;
5540: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5541: if (defined($cached)) { return %{$result}; }
5542:
5543: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5544: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5545: my (%designhash,%legacy);
1.518 albertel 5546: if (keys(%domconfig) > 0) {
5547: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5548: if (keys(%{$domconfig{'login'}})) {
5549: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5550: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5551: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5552: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5553: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5554: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5555: if ($key eq 'loginvia') {
5556: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5557: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5558: $designhash{$udom.'.login.loginvia'} = $server;
5559: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5560:
5561: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5562: } else {
5563: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5564: }
1.948 raeburn 5565: }
1.1208 raeburn 5566: } elsif ($key eq 'headtag') {
5567: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5568: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5569: }
1.946 raeburn 5570: }
1.1208 raeburn 5571: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5572: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5573: }
1.946 raeburn 5574: }
5575: }
5576: }
5577: } else {
5578: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5579: $designhash{$udom.'.login.'.$key.'_'.$img} =
5580: $domconfig{'login'}{$key}{$img};
5581: }
1.699 raeburn 5582: }
5583: } else {
5584: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5585: }
1.632 raeburn 5586: }
5587: } else {
5588: $legacy{'login'} = 1;
1.518 albertel 5589: }
1.632 raeburn 5590: } else {
5591: $legacy{'login'} = 1;
1.518 albertel 5592: }
5593: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5594: if (keys(%{$domconfig{'rolecolors'}})) {
5595: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5596: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5597: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5598: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5599: }
1.518 albertel 5600: }
5601: }
1.632 raeburn 5602: } else {
5603: $legacy{'rolecolors'} = 1;
1.518 albertel 5604: }
1.632 raeburn 5605: } else {
5606: $legacy{'rolecolors'} = 1;
1.518 albertel 5607: }
1.948 raeburn 5608: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5609: if ($domconfig{'autoenroll'}{'co-owners'}) {
5610: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5611: }
5612: }
1.632 raeburn 5613: if (keys(%legacy) > 0) {
5614: my %legacyhash = &get_legacy_domconf($udom);
5615: foreach my $item (keys(%legacyhash)) {
5616: if ($item =~ /^\Q$udom\E\.login/) {
5617: if ($legacy{'login'}) {
5618: $designhash{$item} = $legacyhash{$item};
5619: }
5620: } else {
5621: if ($legacy{'rolecolors'}) {
5622: $designhash{$item} = $legacyhash{$item};
5623: }
1.518 albertel 5624: }
5625: }
5626: }
1.632 raeburn 5627: } else {
5628: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5629: }
5630: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5631: $cachetime);
5632: return %designhash;
5633: }
5634:
1.632 raeburn 5635: sub get_legacy_domconf {
5636: my ($udom) = @_;
5637: my %legacyhash;
5638: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5639: my $designfile = $designdir.'/'.$udom.'.tab';
5640: if (-e $designfile) {
5641: if ( open (my $fh,"<$designfile") ) {
5642: while (my $line = <$fh>) {
5643: next if ($line =~ /^\#/);
5644: chomp($line);
5645: my ($key,$val)=(split(/\=/,$line));
5646: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5647: }
5648: close($fh);
5649: }
5650: }
1.1026 raeburn 5651: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5652: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5653: }
5654: return %legacyhash;
5655: }
5656:
1.63 www 5657: =pod
5658:
1.112 bowersj2 5659: =item * &domainlogo()
1.63 www 5660:
5661: Inputs: $domain (usually will be undef)
5662:
5663: Returns: A link to a domain logo, if the domain logo exists.
5664: If the domain logo does not exist, a description of the domain.
5665:
5666: =cut
1.112 bowersj2 5667:
1.63 www 5668: ###############################################
5669: sub domainlogo {
1.517 raeburn 5670: my $domain = &determinedomain(shift);
1.518 albertel 5671: my %designhash = &get_domainconf($domain);
1.517 raeburn 5672: # See if there is a logo
5673: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5674: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5675: if ($imgsrc =~ m{^/(adm|res)/}) {
5676: if ($imgsrc =~ m{^/res/}) {
5677: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5678: &Apache::lonnet::repcopy($local_name);
5679: }
5680: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5681: }
5682: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5683: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5684: return &Apache::lonnet::domain($domain,'description');
1.59 www 5685: } else {
1.60 matthew 5686: return '';
1.59 www 5687: }
5688: }
1.63 www 5689: ##############################################
5690:
5691: =pod
5692:
1.112 bowersj2 5693: =item * &designparm()
1.63 www 5694:
5695: Inputs: $which parameter; $domain (usually will be undef)
5696:
5697: Returns: value of designparamter $which
5698:
5699: =cut
1.112 bowersj2 5700:
1.397 albertel 5701:
1.400 albertel 5702: ##############################################
1.397 albertel 5703: sub designparm {
5704: my ($which,$domain)=@_;
5705: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5706: return $env{'environment.color.'.$which};
1.96 www 5707: }
1.63 www 5708: $domain=&determinedomain($domain);
1.1016 raeburn 5709: my %domdesign;
5710: unless ($domain eq 'public') {
5711: %domdesign = &get_domainconf($domain);
5712: }
1.520 raeburn 5713: my $output;
1.517 raeburn 5714: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5715: $output = $domdesign{$domain.'.'.$which};
1.63 www 5716: } else {
1.520 raeburn 5717: $output = $defaultdesign{$which};
5718: }
5719: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5720: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5721: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5722: if ($output =~ m{^/res/}) {
5723: my $local_name = &Apache::lonnet::filelocation('',$output);
5724: &Apache::lonnet::repcopy($local_name);
5725: }
1.520 raeburn 5726: $output = &lonhttpdurl($output);
5727: }
1.63 www 5728: }
1.520 raeburn 5729: return $output;
1.63 www 5730: }
1.59 www 5731:
1.822 bisitz 5732: ##############################################
5733: =pod
5734:
1.832 bisitz 5735: =item * &authorspace()
5736:
1.1028 raeburn 5737: Inputs: $url (usually will be undef).
1.832 bisitz 5738:
1.1132 raeburn 5739: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5740: directory being viewed (or for which action is being taken).
5741: If $url is provided, and begins /priv/<domain>/<uname>
5742: the path will be that portion of the $context argument.
5743: Otherwise the path will be for the author space of the current
5744: user when the current role is author, or for that of the
5745: co-author/assistant co-author space when the current role
5746: is co-author or assistant co-author.
1.832 bisitz 5747:
5748: =cut
5749:
5750: sub authorspace {
1.1028 raeburn 5751: my ($url) = @_;
5752: if ($url ne '') {
5753: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5754: return $1;
5755: }
5756: }
1.832 bisitz 5757: my $caname = '';
1.1024 www 5758: my $cadom = '';
1.1028 raeburn 5759: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5760: ($cadom,$caname) =
1.832 bisitz 5761: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5762: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5763: $caname = $env{'user.name'};
1.1024 www 5764: $cadom = $env{'user.domain'};
1.832 bisitz 5765: }
1.1028 raeburn 5766: if (($caname ne '') && ($cadom ne '')) {
5767: return "/priv/$cadom/$caname/";
5768: }
5769: return;
1.832 bisitz 5770: }
5771:
5772: ##############################################
5773: =pod
5774:
1.822 bisitz 5775: =item * &head_subbox()
5776:
5777: Inputs: $content (contains HTML code with page functions, etc.)
5778:
5779: Returns: HTML div with $content
5780: To be included in page header
5781:
5782: =cut
5783:
5784: sub head_subbox {
5785: my ($content)=@_;
5786: my $output =
1.993 raeburn 5787: '<div class="LC_head_subbox">'
1.822 bisitz 5788: .$content
5789: .'</div>'
5790: }
5791:
5792: ##############################################
5793: =pod
5794:
5795: =item * &CSTR_pageheader()
5796:
1.1026 raeburn 5797: Input: (optional) filename from which breadcrumb trail is built.
5798: In most cases no input as needed, as $env{'request.filename'}
5799: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5800:
5801: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5802: To be included on Authoring Space pages
1.822 bisitz 5803:
5804: =cut
5805:
5806: sub CSTR_pageheader {
1.1026 raeburn 5807: my ($trailfile) = @_;
5808: if ($trailfile eq '') {
5809: $trailfile = $env{'request.filename'};
5810: }
5811:
5812: # this is for resources; directories have customtitle, and crumbs
5813: # and select recent are created in lonpubdir.pm
5814:
5815: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5816: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5817: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5818: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5819: $formaction =~ s{/+}{/}g;
1.822 bisitz 5820:
5821: my $parentpath = '';
5822: my $lastitem = '';
5823: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5824: $parentpath = $1;
5825: $lastitem = $2;
5826: } else {
5827: $lastitem = $thisdisfn;
5828: }
1.921 bisitz 5829:
1.1246 raeburn 5830: my ($crsauthor,$title);
5831: if (($env{'request.course.id'}) &&
5832: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 5833: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 5834: $crsauthor = 1;
5835: $title = &mt('Course Authoring Space');
5836: } else {
5837: $title = &mt('Authoring Space');
5838: }
5839:
1.921 bisitz 5840: my $output =
1.822 bisitz 5841: '<div>'
5842: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 5843: .'<b>'.$title.'</b> '
1.822 bisitz 5844: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5845: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5846: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5847:
5848: if ($lastitem) {
5849: $output .=
5850: '<span class="LC_filename">'
5851: .$lastitem
5852: .'</span>';
5853: }
1.1245 raeburn 5854:
1.1246 raeburn 5855: if ($crsauthor) {
5856: $output .= '</form>'.&Apache::lonmenu::constspaceform();
5857: } else {
5858: $output .=
5859: '<br />'
5860: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5861: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5862: .'</form>'
5863: .&Apache::lonmenu::constspaceform();
5864: }
5865: $output .= '</div>';
1.921 bisitz 5866:
5867: return $output;
1.822 bisitz 5868: }
5869:
1.60 matthew 5870: ###############################################
5871: ###############################################
5872:
5873: =pod
5874:
1.112 bowersj2 5875: =back
5876:
1.549 albertel 5877: =head1 HTML Helpers
1.112 bowersj2 5878:
5879: =over 4
5880:
5881: =item * &bodytag()
1.60 matthew 5882:
5883: Returns a uniform header for LON-CAPA web pages.
5884:
5885: Inputs:
5886:
1.112 bowersj2 5887: =over 4
5888:
5889: =item * $title, A title to be displayed on the page.
5890:
5891: =item * $function, the current role (can be undef).
5892:
5893: =item * $addentries, extra parameters for the <body> tag.
5894:
5895: =item * $bodyonly, if defined, only return the <body> tag.
5896:
5897: =item * $domain, if defined, force a given domain.
5898:
5899: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5900: text interface only)
1.60 matthew 5901:
1.814 bisitz 5902: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5903: navigational links
1.317 albertel 5904:
1.338 albertel 5905: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5906:
1.460 albertel 5907: =item * $args, optional argument valid values are
5908: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 5909: use_absolute -> for external resource or syllabus, this will
5910: contain https://<hostname> if server uses
5911: https (as per hosts.tab), but request is for http
5912: hostname -> hostname, from $r->hostname().
1.460 albertel 5913:
1.1096 raeburn 5914: =item * $advtoolsref, optional argument, ref to an array containing
5915: inlineremote items to be added in "Functions" menu below
5916: breadcrumbs.
5917:
1.112 bowersj2 5918: =back
5919:
1.60 matthew 5920: Returns: A uniform header for LON-CAPA web pages.
5921: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5922: If $bodyonly is undef or zero, an html string containing a <body> tag and
5923: other decorations will be returned.
5924:
5925: =cut
5926:
1.54 www 5927: sub bodytag {
1.831 bisitz 5928: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5929: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5930:
1.954 raeburn 5931: my $public;
5932: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5933: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5934: $public = 1;
5935: }
1.460 albertel 5936: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 5937: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 5938: my $hostname = $args->{'hostname'};
1.339 albertel 5939:
1.183 matthew 5940: $function = &get_users_function() if (!$function);
1.339 albertel 5941: my $img = &designparm($function.'.img',$domain);
5942: my $font = &designparm($function.'.font',$domain);
5943: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5944:
1.803 bisitz 5945: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5946: 'bgcolor' => $pgbg,
1.339 albertel 5947: 'text' => $font,
5948: 'alink' => &designparm($function.'.alink',$domain),
5949: 'vlink' => &designparm($function.'.vlink',$domain),
5950: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5951: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5952:
1.63 www 5953: # role and realm
1.1178 raeburn 5954: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5955: if ($realm) {
5956: $realm = '/'.$realm;
5957: }
1.378 raeburn 5958: if ($role eq 'ca') {
1.479 albertel 5959: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5960: $realm = &plainname($rname,$rdom);
1.378 raeburn 5961: }
1.55 www 5962: # realm
1.258 albertel 5963: if ($env{'request.course.id'}) {
1.378 raeburn 5964: if ($env{'request.role'} !~ /^cr/) {
5965: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 5966: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 5967: if ($env{'request.role.desc'}) {
5968: $role = $env{'request.role.desc'};
5969: } else {
5970: $role = &mt('Helpdesk[_1]',' '.$2);
5971: }
1.1257 raeburn 5972: } else {
5973: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5974: }
1.898 raeburn 5975: if ($env{'request.course.sec'}) {
5976: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5977: }
1.359 albertel 5978: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5979: } else {
5980: $role = &Apache::lonnet::plaintext($role);
1.54 www 5981: }
1.433 albertel 5982:
1.359 albertel 5983: if (!$realm) { $realm=' '; }
1.330 albertel 5984:
1.438 albertel 5985: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5986:
1.101 www 5987: # construct main body tag
1.359 albertel 5988: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 5989: &Apache::lontexconvert::init_math_support();
1.252 albertel 5990:
1.1131 raeburn 5991: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5992:
1.1130 raeburn 5993: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5994: return $bodytag;
1.1130 raeburn 5995: }
1.359 albertel 5996:
1.954 raeburn 5997: if ($public) {
1.433 albertel 5998: undef($role);
5999: }
1.359 albertel 6000:
1.762 bisitz 6001: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 6002: #
6003: # Extra info if you are the DC
6004: my $dc_info = '';
6005: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
6006: $env{'course.'.$env{'request.course.id'}.
6007: '.domain'}.'/'})) {
6008: my $cid = $env{'request.course.id'};
1.917 raeburn 6009: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 6010: $dc_info =~ s/\s+$//;
1.359 albertel 6011: }
6012:
1.1237 raeburn 6013: my $crstype;
6014: if ($env{'request.course.id'}) {
6015: $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
6016: } elsif ($args->{'crstype'}) {
6017: $crstype = $args->{'crstype'};
6018: }
6019: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
6020: undef($role);
6021: } else {
1.1242 raeburn 6022: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 6023: }
1.853 droeschl 6024:
1.903 droeschl 6025: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
6026:
6027: # if ($env{'request.state'} eq 'construct') {
6028: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
6029: # }
6030:
1.1130 raeburn 6031: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 6032: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 6033:
1.1237 raeburn 6034: my ($left,$right) = Apache::lonmenu::primary_menu($crstype);
1.359 albertel 6035:
1.916 droeschl 6036: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 6037: if ($dc_info) {
6038: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
6039: }
1.1130 raeburn 6040: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 6041: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 6042: return $bodytag;
6043: }
1.894 droeschl 6044:
1.927 raeburn 6045: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 6046: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 6047: }
1.916 droeschl 6048:
1.1130 raeburn 6049: $bodytag .= $right;
1.852 droeschl 6050:
1.917 raeburn 6051: if ($dc_info) {
6052: $dc_info = &dc_courseid_toggle($dc_info);
6053: }
6054: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 6055:
1.1169 raeburn 6056: #if directed to not display the secondary menu, don't.
1.1168 raeburn 6057: if ($args->{'no_secondary_menu'}) {
6058: return $bodytag;
6059: }
1.1169 raeburn 6060: #don't show menus for public users
1.954 raeburn 6061: if (!$public){
1.1154 raeburn 6062: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 6063: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 6064: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
6065: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 6066: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1274 raeburn 6067: $args->{'bread_crumbs'},'','',$hostname);
1.1096 raeburn 6068: } elsif ($forcereg) {
6069: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 raeburn 6070: $args->{'group'},
1.1274 raeburn 6071: $args->{'hide_buttons'},
6072: $hostname);
1.1096 raeburn 6073: } else {
6074: $bodytag .=
6075: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
6076: $forcereg,$args->{'group'},
6077: $args->{'bread_crumbs'},
1.1274 raeburn 6078: $advtoolsref,'',$hostname);
1.920 raeburn 6079: }
1.903 droeschl 6080: }else{
6081: # this is to seperate menu from content when there's no secondary
6082: # menu. Especially needed for public accessible ressources.
6083: $bodytag .= '<hr style="clear:both" />';
6084: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 6085: }
1.903 droeschl 6086:
1.235 raeburn 6087: return $bodytag;
1.182 matthew 6088: }
6089:
1.917 raeburn 6090: sub dc_courseid_toggle {
6091: my ($dc_info) = @_;
1.980 raeburn 6092: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6093: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6094: &mt('(More ...)').'</a></span>'.
6095: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6096: }
6097:
1.330 albertel 6098: sub make_attr_string {
6099: my ($register,$attr_ref) = @_;
6100:
6101: if ($attr_ref && !ref($attr_ref)) {
6102: die("addentries Must be a hash ref ".
6103: join(':',caller(1))." ".
6104: join(':',caller(0))." ");
6105: }
6106:
6107: if ($register) {
1.339 albertel 6108: my ($on_load,$on_unload);
6109: foreach my $key (keys(%{$attr_ref})) {
6110: if (lc($key) eq 'onload') {
6111: $on_load.=$attr_ref->{$key}.';';
6112: delete($attr_ref->{$key});
6113:
6114: } elsif (lc($key) eq 'onunload') {
6115: $on_unload.=$attr_ref->{$key}.';';
6116: delete($attr_ref->{$key});
6117: }
6118: }
1.953 droeschl 6119: $attr_ref->{'onload'} = $on_load;
6120: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6121: }
1.339 albertel 6122:
1.330 albertel 6123: my $attr_string;
1.1159 raeburn 6124: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6125: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6126: }
6127: return $attr_string;
6128: }
6129:
6130:
1.182 matthew 6131: ###############################################
1.251 albertel 6132: ###############################################
6133:
6134: =pod
6135:
6136: =item * &endbodytag()
6137:
6138: Returns a uniform footer for LON-CAPA web pages.
6139:
1.635 raeburn 6140: Inputs: 1 - optional reference to an args hash
6141: If in the hash, key for noredirectlink has a value which evaluates to true,
6142: a 'Continue' link is not displayed if the page contains an
6143: internal redirect in the <head></head> section,
6144: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6145:
6146: =cut
6147:
6148: sub endbodytag {
1.635 raeburn 6149: my ($args) = @_;
1.1080 raeburn 6150: my $endbodytag;
6151: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6152: $endbodytag='</body>';
6153: }
1.315 albertel 6154: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6155: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6156: $endbodytag=
6157: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6158: &mt('Continue').'</a>'.
6159: $endbodytag;
6160: }
1.315 albertel 6161: }
1.251 albertel 6162: return $endbodytag;
6163: }
6164:
1.352 albertel 6165: =pod
6166:
6167: =item * &standard_css()
6168:
6169: Returns a style sheet
6170:
6171: Inputs: (all optional)
6172: domain -> force to color decorate a page for a specific
6173: domain
6174: function -> force usage of a specific rolish color scheme
6175: bgcolor -> override the default page bgcolor
6176:
6177: =cut
6178:
1.343 albertel 6179: sub standard_css {
1.345 albertel 6180: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6181: $function = &get_users_function() if (!$function);
6182: my $img = &designparm($function.'.img', $domain);
6183: my $tabbg = &designparm($function.'.tabbg', $domain);
6184: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6185: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6186: #second colour for later usage
1.345 albertel 6187: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6188: my $pgbg_or_bgcolor =
6189: $bgcolor ||
1.352 albertel 6190: &designparm($function.'.pgbg', $domain);
1.382 albertel 6191: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6192: my $alink = &designparm($function.'.alink', $domain);
6193: my $vlink = &designparm($function.'.vlink', $domain);
6194: my $link = &designparm($function.'.link', $domain);
6195:
1.602 albertel 6196: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6197: my $mono = 'monospace';
1.850 bisitz 6198: my $data_table_head = $sidebg;
6199: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6200: my $data_table_dark = '#E0E0E0';
1.470 banghart 6201: my $data_table_darker = '#CCCCCC';
1.349 albertel 6202: my $data_table_highlight = '#FFFF00';
1.352 albertel 6203: my $mail_new = '#FFBB77';
6204: my $mail_new_hover = '#DD9955';
6205: my $mail_read = '#BBBB77';
6206: my $mail_read_hover = '#999944';
6207: my $mail_replied = '#AAAA88';
6208: my $mail_replied_hover = '#888855';
6209: my $mail_other = '#99BBBB';
6210: my $mail_other_hover = '#669999';
1.391 albertel 6211: my $table_header = '#DDDDDD';
1.489 raeburn 6212: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6213: my $lg_border_color = '#C8C8C8';
1.952 onken 6214: my $button_hover = '#BF2317';
1.392 albertel 6215:
1.608 albertel 6216: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6217: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6218: : '0 3px 0 4px';
1.448 albertel 6219:
1.523 albertel 6220:
1.343 albertel 6221: return <<END;
1.947 droeschl 6222:
6223: /* needed for iframe to allow 100% height in FF */
6224: body, html {
6225: margin: 0;
6226: padding: 0 0.5%;
6227: height: 99%; /* to avoid scrollbars */
6228: }
6229:
1.795 www 6230: body {
1.911 bisitz 6231: font-family: $sans;
6232: line-height:130%;
6233: font-size:0.83em;
6234: color:$font;
1.795 www 6235: }
6236:
1.959 onken 6237: a:focus,
6238: a:focus img {
1.795 www 6239: color: red;
6240: }
1.698 harmsja 6241:
1.911 bisitz 6242: form, .inline {
6243: display: inline;
1.795 www 6244: }
1.721 harmsja 6245:
1.795 www 6246: .LC_right {
1.911 bisitz 6247: text-align:right;
1.795 www 6248: }
6249:
6250: .LC_middle {
1.911 bisitz 6251: vertical-align:middle;
1.795 www 6252: }
1.721 harmsja 6253:
1.1130 raeburn 6254: .LC_floatleft {
6255: float: left;
6256: }
6257:
6258: .LC_floatright {
6259: float: right;
6260: }
6261:
1.911 bisitz 6262: .LC_400Box {
6263: width:400px;
6264: }
1.721 harmsja 6265:
1.947 droeschl 6266: .LC_iframecontainer {
6267: width: 98%;
6268: margin: 0;
6269: position: fixed;
6270: top: 8.5em;
6271: bottom: 0;
6272: }
6273:
6274: .LC_iframecontainer iframe{
6275: border: none;
6276: width: 100%;
6277: height: 100%;
6278: }
6279:
1.778 bisitz 6280: .LC_filename {
6281: font-family: $mono;
6282: white-space:pre;
1.921 bisitz 6283: font-size: 120%;
1.778 bisitz 6284: }
6285:
6286: .LC_fileicon {
6287: border: none;
6288: height: 1.3em;
6289: vertical-align: text-bottom;
6290: margin-right: 0.3em;
6291: text-decoration:none;
6292: }
6293:
1.1008 www 6294: .LC_setting {
6295: text-decoration:underline;
6296: }
6297:
1.350 albertel 6298: .LC_error {
6299: color: red;
6300: }
1.795 www 6301:
1.1097 bisitz 6302: .LC_warning {
6303: color: darkorange;
6304: }
6305:
1.457 albertel 6306: .LC_diff_removed {
1.733 bisitz 6307: color: red;
1.394 albertel 6308: }
1.532 albertel 6309:
6310: .LC_info,
1.457 albertel 6311: .LC_success,
6312: .LC_diff_added {
1.350 albertel 6313: color: green;
6314: }
1.795 www 6315:
1.802 bisitz 6316: div.LC_confirm_box {
6317: background-color: #FAFAFA;
6318: border: 1px solid $lg_border_color;
6319: margin-right: 0;
6320: padding: 5px;
6321: }
6322:
6323: div.LC_confirm_box .LC_error img,
6324: div.LC_confirm_box .LC_success img {
6325: vertical-align: middle;
6326: }
6327:
1.1242 raeburn 6328: .LC_maxwidth {
6329: max-width: 100%;
6330: height: auto;
6331: }
6332:
1.1243 raeburn 6333: .LC_textsize_mobile {
6334: \@media only screen and (max-device-width: 480px) {
6335: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6336: }
6337: }
6338:
1.440 albertel 6339: .LC_icon {
1.771 droeschl 6340: border: none;
1.790 droeschl 6341: vertical-align: middle;
1.771 droeschl 6342: }
6343:
1.543 albertel 6344: .LC_docs_spacer {
6345: width: 25px;
6346: height: 1px;
1.771 droeschl 6347: border: none;
1.543 albertel 6348: }
1.346 albertel 6349:
1.532 albertel 6350: .LC_internal_info {
1.735 bisitz 6351: color: #999999;
1.532 albertel 6352: }
6353:
1.794 www 6354: .LC_discussion {
1.1050 www 6355: background: $data_table_dark;
1.911 bisitz 6356: border: 1px solid black;
6357: margin: 2px;
1.794 www 6358: }
6359:
6360: .LC_disc_action_left {
1.1050 www 6361: background: $sidebg;
1.911 bisitz 6362: text-align: left;
1.1050 www 6363: padding: 4px;
6364: margin: 2px;
1.794 www 6365: }
6366:
6367: .LC_disc_action_right {
1.1050 www 6368: background: $sidebg;
1.911 bisitz 6369: text-align: right;
1.1050 www 6370: padding: 4px;
6371: margin: 2px;
1.794 www 6372: }
6373:
6374: .LC_disc_new_item {
1.911 bisitz 6375: background: white;
6376: border: 2px solid red;
1.1050 www 6377: margin: 4px;
6378: padding: 4px;
1.794 www 6379: }
6380:
6381: .LC_disc_old_item {
1.911 bisitz 6382: background: white;
1.1050 www 6383: margin: 4px;
6384: padding: 4px;
1.794 www 6385: }
6386:
1.458 albertel 6387: table.LC_pastsubmission {
6388: border: 1px solid black;
6389: margin: 2px;
6390: }
6391:
1.924 bisitz 6392: table#LC_menubuttons {
1.345 albertel 6393: width: 100%;
6394: background: $pgbg;
1.392 albertel 6395: border: 2px;
1.402 albertel 6396: border-collapse: separate;
1.803 bisitz 6397: padding: 0;
1.345 albertel 6398: }
1.392 albertel 6399:
1.801 tempelho 6400: table#LC_title_bar a {
6401: color: $fontmenu;
6402: }
1.836 bisitz 6403:
1.807 droeschl 6404: table#LC_title_bar {
1.819 tempelho 6405: clear: both;
1.836 bisitz 6406: display: none;
1.807 droeschl 6407: }
6408:
1.795 www 6409: table#LC_title_bar,
1.933 droeschl 6410: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6411: table#LC_title_bar.LC_with_remote {
1.359 albertel 6412: width: 100%;
1.392 albertel 6413: border-color: $pgbg;
6414: border-style: solid;
6415: border-width: $border;
1.379 albertel 6416: background: $pgbg;
1.801 tempelho 6417: color: $fontmenu;
1.392 albertel 6418: border-collapse: collapse;
1.803 bisitz 6419: padding: 0;
1.819 tempelho 6420: margin: 0;
1.359 albertel 6421: }
1.795 www 6422:
1.933 droeschl 6423: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6424: margin: 0;
6425: padding: 0;
1.933 droeschl 6426: position: relative;
6427: list-style: none;
1.913 droeschl 6428: }
1.933 droeschl 6429: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6430: display: inline;
6431: }
1.933 droeschl 6432:
6433: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6434: padding: 0;
1.933 droeschl 6435: margin: 0;
6436: float: left;
1.913 droeschl 6437: }
1.933 droeschl 6438: .LC_breadcrumb_tools_tools {
6439: padding: 0;
6440: margin: 0;
1.913 droeschl 6441: float: right;
6442: }
6443:
1.1240 raeburn 6444: .LC_placement_prog {
6445: padding-right: 20px;
6446: font-weight: bold;
6447: font-size: 90%;
6448: }
6449:
1.359 albertel 6450: table#LC_title_bar td {
6451: background: $tabbg;
6452: }
1.795 www 6453:
1.911 bisitz 6454: table#LC_menubuttons img {
1.803 bisitz 6455: border: none;
1.346 albertel 6456: }
1.795 www 6457:
1.842 droeschl 6458: .LC_breadcrumbs_component {
1.911 bisitz 6459: float: right;
6460: margin: 0 1em;
1.357 albertel 6461: }
1.842 droeschl 6462: .LC_breadcrumbs_component img {
1.911 bisitz 6463: vertical-align: middle;
1.777 tempelho 6464: }
1.795 www 6465:
1.1243 raeburn 6466: .LC_breadcrumbs_hoverable {
6467: background: $sidebg;
6468: }
6469:
1.383 albertel 6470: td.LC_table_cell_checkbox {
6471: text-align: center;
6472: }
1.795 www 6473:
6474: .LC_fontsize_small {
1.911 bisitz 6475: font-size: 70%;
1.705 tempelho 6476: }
6477:
1.844 bisitz 6478: #LC_breadcrumbs {
1.911 bisitz 6479: clear:both;
6480: background: $sidebg;
6481: border-bottom: 1px solid $lg_border_color;
6482: line-height: 2.5em;
1.933 droeschl 6483: overflow: hidden;
1.911 bisitz 6484: margin: 0;
6485: padding: 0;
1.995 raeburn 6486: text-align: left;
1.819 tempelho 6487: }
1.862 bisitz 6488:
1.1098 bisitz 6489: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6490: clear:both;
6491: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6492: border: 1px solid $sidebg;
1.1098 bisitz 6493: margin: 0 0 10px 0;
1.966 bisitz 6494: padding: 3px;
1.995 raeburn 6495: text-align: left;
1.822 bisitz 6496: }
6497:
1.795 www 6498: .LC_fontsize_medium {
1.911 bisitz 6499: font-size: 85%;
1.705 tempelho 6500: }
6501:
1.795 www 6502: .LC_fontsize_large {
1.911 bisitz 6503: font-size: 120%;
1.705 tempelho 6504: }
6505:
1.346 albertel 6506: .LC_menubuttons_inline_text {
6507: color: $font;
1.698 harmsja 6508: font-size: 90%;
1.701 harmsja 6509: padding-left:3px;
1.346 albertel 6510: }
6511:
1.934 droeschl 6512: .LC_menubuttons_inline_text img{
6513: vertical-align: middle;
6514: }
6515:
1.1051 www 6516: li.LC_menubuttons_inline_text img {
1.951 onken 6517: cursor:pointer;
1.1002 droeschl 6518: text-decoration: none;
1.951 onken 6519: }
6520:
1.526 www 6521: .LC_menubuttons_link {
6522: text-decoration: none;
6523: }
1.795 www 6524:
1.522 albertel 6525: .LC_menubuttons_category {
1.521 www 6526: color: $font;
1.526 www 6527: background: $pgbg;
1.521 www 6528: font-size: larger;
6529: font-weight: bold;
6530: }
6531:
1.346 albertel 6532: td.LC_menubuttons_text {
1.911 bisitz 6533: color: $font;
1.346 albertel 6534: }
1.706 harmsja 6535:
1.346 albertel 6536: .LC_current_location {
6537: background: $tabbg;
6538: }
1.795 www 6539:
1.1286 raeburn 6540: td.LC_zero_height {
6541: line-height: 0;
6542: cellpadding: 0;
6543: }
6544:
1.938 bisitz 6545: table.LC_data_table {
1.347 albertel 6546: border: 1px solid #000000;
1.402 albertel 6547: border-collapse: separate;
1.426 albertel 6548: border-spacing: 1px;
1.610 albertel 6549: background: $pgbg;
1.347 albertel 6550: }
1.795 www 6551:
1.422 albertel 6552: .LC_data_table_dense {
6553: font-size: small;
6554: }
1.795 www 6555:
1.507 raeburn 6556: table.LC_nested_outer {
6557: border: 1px solid #000000;
1.589 raeburn 6558: border-collapse: collapse;
1.803 bisitz 6559: border-spacing: 0;
1.507 raeburn 6560: width: 100%;
6561: }
1.795 www 6562:
1.879 raeburn 6563: table.LC_innerpickbox,
1.507 raeburn 6564: table.LC_nested {
1.803 bisitz 6565: border: none;
1.589 raeburn 6566: border-collapse: collapse;
1.803 bisitz 6567: border-spacing: 0;
1.507 raeburn 6568: width: 100%;
6569: }
1.795 www 6570:
1.911 bisitz 6571: table.LC_data_table tr th,
6572: table.LC_calendar tr th,
1.879 raeburn 6573: table.LC_prior_tries tr th,
6574: table.LC_innerpickbox tr th {
1.349 albertel 6575: font-weight: bold;
6576: background-color: $data_table_head;
1.801 tempelho 6577: color:$fontmenu;
1.701 harmsja 6578: font-size:90%;
1.347 albertel 6579: }
1.795 www 6580:
1.879 raeburn 6581: table.LC_innerpickbox tr th,
6582: table.LC_innerpickbox tr td {
6583: vertical-align: top;
6584: }
6585:
1.711 raeburn 6586: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6587: background-color: #CCCCCC;
1.711 raeburn 6588: font-weight: bold;
6589: text-align: left;
6590: }
1.795 www 6591:
1.912 bisitz 6592: table.LC_data_table tr.LC_odd_row > td {
6593: background-color: $data_table_light;
6594: padding: 2px;
6595: vertical-align: top;
6596: }
6597:
1.809 bisitz 6598: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6599: background-color: $data_table_light;
1.912 bisitz 6600: vertical-align: top;
6601: }
6602:
6603: table.LC_data_table tr.LC_even_row > td {
6604: background-color: $data_table_dark;
1.425 albertel 6605: padding: 2px;
1.900 bisitz 6606: vertical-align: top;
1.347 albertel 6607: }
1.795 www 6608:
1.809 bisitz 6609: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6610: background-color: $data_table_dark;
1.900 bisitz 6611: vertical-align: top;
1.347 albertel 6612: }
1.795 www 6613:
1.425 albertel 6614: table.LC_data_table tr.LC_data_table_highlight td {
6615: background-color: $data_table_darker;
6616: }
1.795 www 6617:
1.639 raeburn 6618: table.LC_data_table tr td.LC_leftcol_header {
6619: background-color: $data_table_head;
6620: font-weight: bold;
6621: }
1.795 www 6622:
1.451 albertel 6623: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6624: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6625: font-weight: bold;
6626: font-style: italic;
6627: text-align: center;
6628: padding: 8px;
1.347 albertel 6629: }
1.795 www 6630:
1.1114 raeburn 6631: table.LC_data_table tr.LC_empty_row td,
6632: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6633: background-color: $sidebg;
6634: }
6635:
6636: table.LC_nested tr.LC_empty_row td {
6637: background-color: #FFFFFF;
6638: }
6639:
1.890 droeschl 6640: table.LC_caption {
6641: }
6642:
1.507 raeburn 6643: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6644: padding: 4ex
6645: }
1.795 www 6646:
1.507 raeburn 6647: table.LC_nested_outer tr th {
6648: font-weight: bold;
1.801 tempelho 6649: color:$fontmenu;
1.507 raeburn 6650: background-color: $data_table_head;
1.701 harmsja 6651: font-size: small;
1.507 raeburn 6652: border-bottom: 1px solid #000000;
6653: }
1.795 www 6654:
1.507 raeburn 6655: table.LC_nested_outer tr td.LC_subheader {
6656: background-color: $data_table_head;
6657: font-weight: bold;
6658: font-size: small;
6659: border-bottom: 1px solid #000000;
6660: text-align: right;
1.451 albertel 6661: }
1.795 www 6662:
1.507 raeburn 6663: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6664: background-color: #CCCCCC;
1.451 albertel 6665: font-weight: bold;
6666: font-size: small;
1.507 raeburn 6667: text-align: center;
6668: }
1.795 www 6669:
1.589 raeburn 6670: table.LC_nested tr.LC_info_row td.LC_left_item,
6671: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6672: text-align: left;
1.451 albertel 6673: }
1.795 www 6674:
1.507 raeburn 6675: table.LC_nested td {
1.735 bisitz 6676: background-color: #FFFFFF;
1.451 albertel 6677: font-size: small;
1.507 raeburn 6678: }
1.795 www 6679:
1.507 raeburn 6680: table.LC_nested_outer tr th.LC_right_item,
6681: table.LC_nested tr.LC_info_row td.LC_right_item,
6682: table.LC_nested tr.LC_odd_row td.LC_right_item,
6683: table.LC_nested tr td.LC_right_item {
1.451 albertel 6684: text-align: right;
6685: }
6686:
1.507 raeburn 6687: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6688: background-color: #EEEEEE;
1.451 albertel 6689: }
6690:
1.473 raeburn 6691: table.LC_createuser {
6692: }
6693:
6694: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6695: font-size: small;
1.473 raeburn 6696: }
6697:
6698: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6699: background-color: #CCCCCC;
1.473 raeburn 6700: font-weight: bold;
6701: text-align: center;
6702: }
6703:
1.349 albertel 6704: table.LC_calendar {
6705: border: 1px solid #000000;
6706: border-collapse: collapse;
1.917 raeburn 6707: width: 98%;
1.349 albertel 6708: }
1.795 www 6709:
1.349 albertel 6710: table.LC_calendar_pickdate {
6711: font-size: xx-small;
6712: }
1.795 www 6713:
1.349 albertel 6714: table.LC_calendar tr td {
6715: border: 1px solid #000000;
6716: vertical-align: top;
1.917 raeburn 6717: width: 14%;
1.349 albertel 6718: }
1.795 www 6719:
1.349 albertel 6720: table.LC_calendar tr td.LC_calendar_day_empty {
6721: background-color: $data_table_dark;
6722: }
1.795 www 6723:
1.779 bisitz 6724: table.LC_calendar tr td.LC_calendar_day_current {
6725: background-color: $data_table_highlight;
1.777 tempelho 6726: }
1.795 www 6727:
1.938 bisitz 6728: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6729: background-color: $mail_new;
6730: }
1.795 www 6731:
1.938 bisitz 6732: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6733: background-color: $mail_new_hover;
6734: }
1.795 www 6735:
1.938 bisitz 6736: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6737: background-color: $mail_read;
6738: }
1.795 www 6739:
1.938 bisitz 6740: /*
6741: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6742: background-color: $mail_read_hover;
6743: }
1.938 bisitz 6744: */
1.795 www 6745:
1.938 bisitz 6746: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6747: background-color: $mail_replied;
6748: }
1.795 www 6749:
1.938 bisitz 6750: /*
6751: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6752: background-color: $mail_replied_hover;
6753: }
1.938 bisitz 6754: */
1.795 www 6755:
1.938 bisitz 6756: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6757: background-color: $mail_other;
6758: }
1.795 www 6759:
1.938 bisitz 6760: /*
6761: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6762: background-color: $mail_other_hover;
6763: }
1.938 bisitz 6764: */
1.494 raeburn 6765:
1.777 tempelho 6766: table.LC_data_table tr > td.LC_browser_file,
6767: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6768: background: #AAEE77;
1.389 albertel 6769: }
1.795 www 6770:
1.777 tempelho 6771: table.LC_data_table tr > td.LC_browser_file_locked,
6772: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6773: background: #FFAA99;
1.387 albertel 6774: }
1.795 www 6775:
1.777 tempelho 6776: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6777: background: #888888;
1.779 bisitz 6778: }
1.795 www 6779:
1.777 tempelho 6780: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6781: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6782: background: #F8F866;
1.777 tempelho 6783: }
1.795 www 6784:
1.696 bisitz 6785: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6786: background: #E0E8FF;
1.387 albertel 6787: }
1.696 bisitz 6788:
1.707 bisitz 6789: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6790: /* background: #77FF77; */
1.707 bisitz 6791: }
1.795 www 6792:
1.707 bisitz 6793: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6794: border-right: 8px solid #FFFF77;
1.707 bisitz 6795: }
1.795 www 6796:
1.707 bisitz 6797: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6798: border-right: 8px solid #FFAA77;
1.707 bisitz 6799: }
1.795 www 6800:
1.707 bisitz 6801: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6802: border-right: 8px solid #FF7777;
1.707 bisitz 6803: }
1.795 www 6804:
1.707 bisitz 6805: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6806: border-right: 8px solid #AAFF77;
1.707 bisitz 6807: }
1.795 www 6808:
1.707 bisitz 6809: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6810: border-right: 8px solid #11CC55;
1.707 bisitz 6811: }
6812:
1.388 albertel 6813: span.LC_current_location {
1.701 harmsja 6814: font-size:larger;
1.388 albertel 6815: background: $pgbg;
6816: }
1.387 albertel 6817:
1.1029 www 6818: span.LC_current_nav_location {
6819: font-weight:bold;
6820: background: $sidebg;
6821: }
6822:
1.395 albertel 6823: span.LC_parm_menu_item {
6824: font-size: larger;
6825: }
1.795 www 6826:
1.395 albertel 6827: span.LC_parm_scope_all {
6828: color: red;
6829: }
1.795 www 6830:
1.395 albertel 6831: span.LC_parm_scope_folder {
6832: color: green;
6833: }
1.795 www 6834:
1.395 albertel 6835: span.LC_parm_scope_resource {
6836: color: orange;
6837: }
1.795 www 6838:
1.395 albertel 6839: span.LC_parm_part {
6840: color: blue;
6841: }
1.795 www 6842:
1.911 bisitz 6843: span.LC_parm_folder,
6844: span.LC_parm_symb {
1.395 albertel 6845: font-size: x-small;
6846: font-family: $mono;
6847: color: #AAAAAA;
6848: }
6849:
1.977 bisitz 6850: ul.LC_parm_parmlist li {
6851: display: inline-block;
6852: padding: 0.3em 0.8em;
6853: vertical-align: top;
6854: width: 150px;
6855: border-top:1px solid $lg_border_color;
6856: }
6857:
1.795 www 6858: td.LC_parm_overview_level_menu,
6859: td.LC_parm_overview_map_menu,
6860: td.LC_parm_overview_parm_selectors,
6861: td.LC_parm_overview_restrictions {
1.396 albertel 6862: border: 1px solid black;
6863: border-collapse: collapse;
6864: }
1.795 www 6865:
1.1285 raeburn 6866: span.LC_parm_recursive,
6867: td.LC_parm_recursive {
6868: font-weight: bold;
6869: font-size: smaller;
6870: }
6871:
1.396 albertel 6872: table.LC_parm_overview_restrictions td {
6873: border-width: 1px 4px 1px 4px;
6874: border-style: solid;
6875: border-color: $pgbg;
6876: text-align: center;
6877: }
1.795 www 6878:
1.396 albertel 6879: table.LC_parm_overview_restrictions th {
6880: background: $tabbg;
6881: border-width: 1px 4px 1px 4px;
6882: border-style: solid;
6883: border-color: $pgbg;
6884: }
1.795 www 6885:
1.398 albertel 6886: table#LC_helpmenu {
1.803 bisitz 6887: border: none;
1.398 albertel 6888: height: 55px;
1.803 bisitz 6889: border-spacing: 0;
1.398 albertel 6890: }
6891:
6892: table#LC_helpmenu fieldset legend {
6893: font-size: larger;
6894: }
1.795 www 6895:
1.397 albertel 6896: table#LC_helpmenu_links {
6897: width: 100%;
6898: border: 1px solid black;
6899: background: $pgbg;
1.803 bisitz 6900: padding: 0;
1.397 albertel 6901: border-spacing: 1px;
6902: }
1.795 www 6903:
1.397 albertel 6904: table#LC_helpmenu_links tr td {
6905: padding: 1px;
6906: background: $tabbg;
1.399 albertel 6907: text-align: center;
6908: font-weight: bold;
1.397 albertel 6909: }
1.396 albertel 6910:
1.795 www 6911: table#LC_helpmenu_links a:link,
6912: table#LC_helpmenu_links a:visited,
1.397 albertel 6913: table#LC_helpmenu_links a:active {
6914: text-decoration: none;
6915: color: $font;
6916: }
1.795 www 6917:
1.397 albertel 6918: table#LC_helpmenu_links a:hover {
6919: text-decoration: underline;
6920: color: $vlink;
6921: }
1.396 albertel 6922:
1.417 albertel 6923: .LC_chrt_popup_exists {
6924: border: 1px solid #339933;
6925: margin: -1px;
6926: }
1.795 www 6927:
1.417 albertel 6928: .LC_chrt_popup_up {
6929: border: 1px solid yellow;
6930: margin: -1px;
6931: }
1.795 www 6932:
1.417 albertel 6933: .LC_chrt_popup {
6934: border: 1px solid #8888FF;
6935: background: #CCCCFF;
6936: }
1.795 www 6937:
1.421 albertel 6938: table.LC_pick_box {
6939: border-collapse: separate;
6940: background: white;
6941: border: 1px solid black;
6942: border-spacing: 1px;
6943: }
1.795 www 6944:
1.421 albertel 6945: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6946: background: $sidebg;
1.421 albertel 6947: font-weight: bold;
1.900 bisitz 6948: text-align: left;
1.740 bisitz 6949: vertical-align: top;
1.421 albertel 6950: width: 184px;
6951: padding: 8px;
6952: }
1.795 www 6953:
1.579 raeburn 6954: table.LC_pick_box td.LC_pick_box_value {
6955: text-align: left;
6956: padding: 8px;
6957: }
1.795 www 6958:
1.579 raeburn 6959: table.LC_pick_box td.LC_pick_box_select {
6960: text-align: left;
6961: padding: 8px;
6962: }
1.795 www 6963:
1.424 albertel 6964: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6965: padding: 0;
1.421 albertel 6966: height: 1px;
6967: background: black;
6968: }
1.795 www 6969:
1.421 albertel 6970: table.LC_pick_box td.LC_pick_box_submit {
6971: text-align: right;
6972: }
1.795 www 6973:
1.579 raeburn 6974: table.LC_pick_box td.LC_evenrow_value {
6975: text-align: left;
6976: padding: 8px;
6977: background-color: $data_table_light;
6978: }
1.795 www 6979:
1.579 raeburn 6980: table.LC_pick_box td.LC_oddrow_value {
6981: text-align: left;
6982: padding: 8px;
6983: background-color: $data_table_light;
6984: }
1.795 www 6985:
1.579 raeburn 6986: span.LC_helpform_receipt_cat {
6987: font-weight: bold;
6988: }
1.795 www 6989:
1.424 albertel 6990: table.LC_group_priv_box {
6991: background: white;
6992: border: 1px solid black;
6993: border-spacing: 1px;
6994: }
1.795 www 6995:
1.424 albertel 6996: table.LC_group_priv_box td.LC_pick_box_title {
6997: background: $tabbg;
6998: font-weight: bold;
6999: text-align: right;
7000: width: 184px;
7001: }
1.795 www 7002:
1.424 albertel 7003: table.LC_group_priv_box td.LC_groups_fixed {
7004: background: $data_table_light;
7005: text-align: center;
7006: }
1.795 www 7007:
1.424 albertel 7008: table.LC_group_priv_box td.LC_groups_optional {
7009: background: $data_table_dark;
7010: text-align: center;
7011: }
1.795 www 7012:
1.424 albertel 7013: table.LC_group_priv_box td.LC_groups_functionality {
7014: background: $data_table_darker;
7015: text-align: center;
7016: font-weight: bold;
7017: }
1.795 www 7018:
1.424 albertel 7019: table.LC_group_priv td {
7020: text-align: left;
1.803 bisitz 7021: padding: 0;
1.424 albertel 7022: }
7023:
7024: .LC_navbuttons {
7025: margin: 2ex 0ex 2ex 0ex;
7026: }
1.795 www 7027:
1.423 albertel 7028: .LC_topic_bar {
7029: font-weight: bold;
7030: background: $tabbg;
1.918 wenzelju 7031: margin: 1em 0em 1em 2em;
1.805 bisitz 7032: padding: 3px;
1.918 wenzelju 7033: font-size: 1.2em;
1.423 albertel 7034: }
1.795 www 7035:
1.423 albertel 7036: .LC_topic_bar span {
1.918 wenzelju 7037: left: 0.5em;
7038: position: absolute;
1.423 albertel 7039: vertical-align: middle;
1.918 wenzelju 7040: font-size: 1.2em;
1.423 albertel 7041: }
1.795 www 7042:
1.423 albertel 7043: table.LC_course_group_status {
7044: margin: 20px;
7045: }
1.795 www 7046:
1.423 albertel 7047: table.LC_status_selector td {
7048: vertical-align: top;
7049: text-align: center;
1.424 albertel 7050: padding: 4px;
7051: }
1.795 www 7052:
1.599 albertel 7053: div.LC_feedback_link {
1.616 albertel 7054: clear: both;
1.829 kalberla 7055: background: $sidebg;
1.779 bisitz 7056: width: 100%;
1.829 kalberla 7057: padding-bottom: 10px;
7058: border: 1px $tabbg solid;
1.833 kalberla 7059: height: 22px;
7060: line-height: 22px;
7061: padding-top: 5px;
7062: }
7063:
7064: div.LC_feedback_link img {
7065: height: 22px;
1.867 kalberla 7066: vertical-align:middle;
1.829 kalberla 7067: }
7068:
1.911 bisitz 7069: div.LC_feedback_link a {
1.829 kalberla 7070: text-decoration: none;
1.489 raeburn 7071: }
1.795 www 7072:
1.867 kalberla 7073: div.LC_comblock {
1.911 bisitz 7074: display:inline;
1.867 kalberla 7075: color:$font;
7076: font-size:90%;
7077: }
7078:
7079: div.LC_feedback_link div.LC_comblock {
7080: padding-left:5px;
7081: }
7082:
7083: div.LC_feedback_link div.LC_comblock a {
7084: color:$font;
7085: }
7086:
1.489 raeburn 7087: span.LC_feedback_link {
1.858 bisitz 7088: /* background: $feedback_link_bg; */
1.599 albertel 7089: font-size: larger;
7090: }
1.795 www 7091:
1.599 albertel 7092: span.LC_message_link {
1.858 bisitz 7093: /* background: $feedback_link_bg; */
1.599 albertel 7094: font-size: larger;
7095: position: absolute;
7096: right: 1em;
1.489 raeburn 7097: }
1.421 albertel 7098:
1.515 albertel 7099: table.LC_prior_tries {
1.524 albertel 7100: border: 1px solid #000000;
7101: border-collapse: separate;
7102: border-spacing: 1px;
1.515 albertel 7103: }
1.523 albertel 7104:
1.515 albertel 7105: table.LC_prior_tries td {
1.524 albertel 7106: padding: 2px;
1.515 albertel 7107: }
1.523 albertel 7108:
7109: .LC_answer_correct {
1.795 www 7110: background: lightgreen;
7111: color: darkgreen;
7112: padding: 6px;
1.523 albertel 7113: }
1.795 www 7114:
1.523 albertel 7115: .LC_answer_charged_try {
1.797 www 7116: background: #FFAAAA;
1.795 www 7117: color: darkred;
7118: padding: 6px;
1.523 albertel 7119: }
1.795 www 7120:
1.779 bisitz 7121: .LC_answer_not_charged_try,
1.523 albertel 7122: .LC_answer_no_grade,
7123: .LC_answer_late {
1.795 www 7124: background: lightyellow;
1.523 albertel 7125: color: black;
1.795 www 7126: padding: 6px;
1.523 albertel 7127: }
1.795 www 7128:
1.523 albertel 7129: .LC_answer_previous {
1.795 www 7130: background: lightblue;
7131: color: darkblue;
7132: padding: 6px;
1.523 albertel 7133: }
1.795 www 7134:
1.779 bisitz 7135: .LC_answer_no_message {
1.777 tempelho 7136: background: #FFFFFF;
7137: color: black;
1.795 www 7138: padding: 6px;
1.779 bisitz 7139: }
1.795 www 7140:
1.779 bisitz 7141: .LC_answer_unknown {
7142: background: orange;
7143: color: black;
1.795 www 7144: padding: 6px;
1.777 tempelho 7145: }
1.795 www 7146:
1.529 albertel 7147: span.LC_prior_numerical,
7148: span.LC_prior_string,
7149: span.LC_prior_custom,
7150: span.LC_prior_reaction,
7151: span.LC_prior_math {
1.925 bisitz 7152: font-family: $mono;
1.523 albertel 7153: white-space: pre;
7154: }
7155:
1.525 albertel 7156: span.LC_prior_string {
1.925 bisitz 7157: font-family: $mono;
1.525 albertel 7158: white-space: pre;
7159: }
7160:
1.523 albertel 7161: table.LC_prior_option {
7162: width: 100%;
7163: border-collapse: collapse;
7164: }
1.795 www 7165:
1.911 bisitz 7166: table.LC_prior_rank,
1.795 www 7167: table.LC_prior_match {
1.528 albertel 7168: border-collapse: collapse;
7169: }
1.795 www 7170:
1.528 albertel 7171: table.LC_prior_option tr td,
7172: table.LC_prior_rank tr td,
7173: table.LC_prior_match tr td {
1.524 albertel 7174: border: 1px solid #000000;
1.515 albertel 7175: }
7176:
1.855 bisitz 7177: .LC_nobreak {
1.544 albertel 7178: white-space: nowrap;
1.519 raeburn 7179: }
7180:
1.576 raeburn 7181: span.LC_cusr_emph {
7182: font-style: italic;
7183: }
7184:
1.633 raeburn 7185: span.LC_cusr_subheading {
7186: font-weight: normal;
7187: font-size: 85%;
7188: }
7189:
1.861 bisitz 7190: div.LC_docs_entry_move {
1.859 bisitz 7191: border: 1px solid #BBBBBB;
1.545 albertel 7192: background: #DDDDDD;
1.861 bisitz 7193: width: 22px;
1.859 bisitz 7194: padding: 1px;
7195: margin: 0;
1.545 albertel 7196: }
7197:
1.861 bisitz 7198: table.LC_data_table tr > td.LC_docs_entry_commands,
7199: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7200: font-size: x-small;
7201: }
1.795 www 7202:
1.861 bisitz 7203: .LC_docs_entry_parameter {
7204: white-space: nowrap;
7205: }
7206:
1.544 albertel 7207: .LC_docs_copy {
1.545 albertel 7208: color: #000099;
1.544 albertel 7209: }
1.795 www 7210:
1.544 albertel 7211: .LC_docs_cut {
1.545 albertel 7212: color: #550044;
1.544 albertel 7213: }
1.795 www 7214:
1.544 albertel 7215: .LC_docs_rename {
1.545 albertel 7216: color: #009900;
1.544 albertel 7217: }
1.795 www 7218:
1.544 albertel 7219: .LC_docs_remove {
1.545 albertel 7220: color: #990000;
7221: }
7222:
1.1284 raeburn 7223: .LC_docs_alias {
7224: color: #440055;
7225: }
7226:
1.1286 raeburn 7227: .LC_domprefs_email,
1.1284 raeburn 7228: .LC_docs_alias_name,
1.547 albertel 7229: .LC_docs_reinit_warn,
7230: .LC_docs_ext_edit {
7231: font-size: x-small;
7232: }
7233:
1.545 albertel 7234: table.LC_docs_adddocs td,
7235: table.LC_docs_adddocs th {
7236: border: 1px solid #BBBBBB;
7237: padding: 4px;
7238: background: #DDDDDD;
1.543 albertel 7239: }
7240:
1.584 albertel 7241: table.LC_sty_begin {
7242: background: #BBFFBB;
7243: }
1.795 www 7244:
1.584 albertel 7245: table.LC_sty_end {
7246: background: #FFBBBB;
7247: }
7248:
1.589 raeburn 7249: table.LC_double_column {
1.803 bisitz 7250: border-width: 0;
1.589 raeburn 7251: border-collapse: collapse;
7252: width: 100%;
7253: padding: 2px;
7254: }
7255:
7256: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7257: top: 2px;
1.589 raeburn 7258: left: 2px;
7259: width: 47%;
7260: vertical-align: top;
7261: }
7262:
7263: table.LC_double_column tr td.LC_right_col {
7264: top: 2px;
1.779 bisitz 7265: right: 2px;
1.589 raeburn 7266: width: 47%;
7267: vertical-align: top;
7268: }
7269:
1.591 raeburn 7270: div.LC_left_float {
7271: float: left;
7272: padding-right: 5%;
1.597 albertel 7273: padding-bottom: 4px;
1.591 raeburn 7274: }
7275:
7276: div.LC_clear_float_header {
1.597 albertel 7277: padding-bottom: 2px;
1.591 raeburn 7278: }
7279:
7280: div.LC_clear_float_footer {
1.597 albertel 7281: padding-top: 10px;
1.591 raeburn 7282: clear: both;
7283: }
7284:
1.597 albertel 7285: div.LC_grade_show_user {
1.941 bisitz 7286: /* border-left: 5px solid $sidebg; */
7287: border-top: 5px solid #000000;
7288: margin: 50px 0 0 0;
1.936 bisitz 7289: padding: 15px 0 5px 10px;
1.597 albertel 7290: }
1.795 www 7291:
1.936 bisitz 7292: div.LC_grade_show_user_odd_row {
1.941 bisitz 7293: /* border-left: 5px solid #000000; */
7294: }
7295:
7296: div.LC_grade_show_user div.LC_Box {
7297: margin-right: 50px;
1.597 albertel 7298: }
7299:
7300: div.LC_grade_submissions,
7301: div.LC_grade_message_center,
1.936 bisitz 7302: div.LC_grade_info_links {
1.597 albertel 7303: margin: 5px;
7304: width: 99%;
7305: background: #FFFFFF;
7306: }
1.795 www 7307:
1.597 albertel 7308: div.LC_grade_submissions_header,
1.936 bisitz 7309: div.LC_grade_message_center_header {
1.705 tempelho 7310: font-weight: bold;
7311: font-size: large;
1.597 albertel 7312: }
1.795 www 7313:
1.597 albertel 7314: div.LC_grade_submissions_body,
1.936 bisitz 7315: div.LC_grade_message_center_body {
1.597 albertel 7316: border: 1px solid black;
7317: width: 99%;
7318: background: #FFFFFF;
7319: }
1.795 www 7320:
1.613 albertel 7321: table.LC_scantron_action {
7322: width: 100%;
7323: }
1.795 www 7324:
1.613 albertel 7325: table.LC_scantron_action tr th {
1.698 harmsja 7326: font-weight:bold;
7327: font-style:normal;
1.613 albertel 7328: }
1.795 www 7329:
1.779 bisitz 7330: .LC_edit_problem_header,
1.614 albertel 7331: div.LC_edit_problem_footer {
1.705 tempelho 7332: font-weight: normal;
7333: font-size: medium;
1.602 albertel 7334: margin: 2px;
1.1060 bisitz 7335: background-color: $sidebg;
1.600 albertel 7336: }
1.795 www 7337:
1.600 albertel 7338: div.LC_edit_problem_header,
1.602 albertel 7339: div.LC_edit_problem_header div,
1.614 albertel 7340: div.LC_edit_problem_footer,
7341: div.LC_edit_problem_footer div,
1.602 albertel 7342: div.LC_edit_problem_editxml_header,
7343: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7344: z-index: 100;
1.600 albertel 7345: }
1.795 www 7346:
1.600 albertel 7347: div.LC_edit_problem_header_title {
1.705 tempelho 7348: font-weight: bold;
7349: font-size: larger;
1.602 albertel 7350: background: $tabbg;
7351: padding: 3px;
1.1060 bisitz 7352: margin: 0 0 5px 0;
1.602 albertel 7353: }
1.795 www 7354:
1.602 albertel 7355: table.LC_edit_problem_header_title {
7356: width: 100%;
1.600 albertel 7357: background: $tabbg;
1.602 albertel 7358: }
7359:
1.1205 golterma 7360: div.LC_edit_actionbar {
7361: background-color: $sidebg;
1.1218 droeschl 7362: margin: 0;
7363: padding: 0;
7364: line-height: 200%;
1.602 albertel 7365: }
1.795 www 7366:
1.1218 droeschl 7367: div.LC_edit_actionbar div{
7368: padding: 0;
7369: margin: 0;
7370: display: inline-block;
1.600 albertel 7371: }
1.795 www 7372:
1.1124 bisitz 7373: .LC_edit_opt {
7374: padding-left: 1em;
7375: white-space: nowrap;
7376: }
7377:
1.1152 golterma 7378: .LC_edit_problem_latexhelper{
7379: text-align: right;
7380: }
7381:
7382: #LC_edit_problem_colorful div{
7383: margin-left: 40px;
7384: }
7385:
1.1205 golterma 7386: #LC_edit_problem_codemirror div{
7387: margin-left: 0px;
7388: }
7389:
1.911 bisitz 7390: img.stift {
1.803 bisitz 7391: border-width: 0;
7392: vertical-align: middle;
1.677 riegler 7393: }
1.680 riegler 7394:
1.923 bisitz 7395: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7396: vertical-align: top;
1.777 tempelho 7397: }
1.795 www 7398:
1.716 raeburn 7399: div.LC_createcourse {
1.911 bisitz 7400: margin: 10px 10px 10px 10px;
1.716 raeburn 7401: }
7402:
1.917 raeburn 7403: .LC_dccid {
1.1130 raeburn 7404: float: right;
1.917 raeburn 7405: margin: 0.2em 0 0 0;
7406: padding: 0;
7407: font-size: 90%;
7408: display:none;
7409: }
7410:
1.897 wenzelju 7411: ol.LC_primary_menu a:hover,
1.721 harmsja 7412: ol#LC_MenuBreadcrumbs a:hover,
7413: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7414: ul#LC_secondary_menu a:hover,
1.721 harmsja 7415: .LC_FormSectionClearButton input:hover
1.795 www 7416: ul.LC_TabContent li:hover a {
1.952 onken 7417: color:$button_hover;
1.911 bisitz 7418: text-decoration:none;
1.693 droeschl 7419: }
7420:
1.779 bisitz 7421: h1 {
1.911 bisitz 7422: padding: 0;
7423: line-height:130%;
1.693 droeschl 7424: }
1.698 harmsja 7425:
1.911 bisitz 7426: h2,
7427: h3,
7428: h4,
7429: h5,
7430: h6 {
7431: margin: 5px 0 5px 0;
7432: padding: 0;
7433: line-height:130%;
1.693 droeschl 7434: }
1.795 www 7435:
7436: .LC_hcell {
1.911 bisitz 7437: padding:3px 15px 3px 15px;
7438: margin: 0;
7439: background-color:$tabbg;
7440: color:$fontmenu;
7441: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7442: }
1.795 www 7443:
1.840 bisitz 7444: .LC_Box > .LC_hcell {
1.911 bisitz 7445: margin: 0 -10px 10px -10px;
1.835 bisitz 7446: }
7447:
1.721 harmsja 7448: .LC_noBorder {
1.911 bisitz 7449: border: 0;
1.698 harmsja 7450: }
1.693 droeschl 7451:
1.721 harmsja 7452: .LC_FormSectionClearButton input {
1.911 bisitz 7453: background-color:transparent;
7454: border: none;
7455: cursor:pointer;
7456: text-decoration:underline;
1.693 droeschl 7457: }
1.763 bisitz 7458:
7459: .LC_help_open_topic {
1.911 bisitz 7460: color: #FFFFFF;
7461: background-color: #EEEEFF;
7462: margin: 1px;
7463: padding: 4px;
7464: border: 1px solid #000033;
7465: white-space: nowrap;
7466: /* vertical-align: middle; */
1.759 neumanie 7467: }
1.693 droeschl 7468:
1.911 bisitz 7469: dl,
7470: ul,
7471: div,
7472: fieldset {
7473: margin: 10px 10px 10px 0;
7474: /* overflow: hidden; */
1.693 droeschl 7475: }
1.795 www 7476:
1.1211 raeburn 7477: article.geogebraweb div {
7478: margin: 0;
7479: }
7480:
1.838 bisitz 7481: fieldset > legend {
1.911 bisitz 7482: font-weight: bold;
7483: padding: 0 5px 0 5px;
1.838 bisitz 7484: }
7485:
1.813 bisitz 7486: #LC_nav_bar {
1.911 bisitz 7487: float: left;
1.995 raeburn 7488: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7489: margin: 0 0 2px 0;
1.807 droeschl 7490: }
7491:
1.916 droeschl 7492: #LC_realm {
7493: margin: 0.2em 0 0 0;
7494: padding: 0;
7495: font-weight: bold;
7496: text-align: center;
1.995 raeburn 7497: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7498: }
7499:
1.911 bisitz 7500: #LC_nav_bar em {
7501: font-weight: bold;
7502: font-style: normal;
1.807 droeschl 7503: }
7504:
1.897 wenzelju 7505: ol.LC_primary_menu {
1.934 droeschl 7506: margin: 0;
1.1076 raeburn 7507: padding: 0;
1.807 droeschl 7508: }
7509:
1.852 droeschl 7510: ol#LC_PathBreadcrumbs {
1.911 bisitz 7511: margin: 0;
1.693 droeschl 7512: }
7513:
1.897 wenzelju 7514: ol.LC_primary_menu li {
1.1076 raeburn 7515: color: RGB(80, 80, 80);
7516: vertical-align: middle;
7517: text-align: left;
7518: list-style: none;
1.1205 golterma 7519: position: relative;
1.1076 raeburn 7520: float: left;
1.1205 golterma 7521: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7522: line-height: 1.5em;
1.1076 raeburn 7523: }
7524:
1.1205 golterma 7525: ol.LC_primary_menu li a,
7526: ol.LC_primary_menu li p {
1.1076 raeburn 7527: display: block;
7528: margin: 0;
7529: padding: 0 5px 0 10px;
7530: text-decoration: none;
7531: }
7532:
1.1205 golterma 7533: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7534: display: inline-block;
7535: width: 95%;
7536: text-align: left;
7537: }
7538:
7539: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7540: display: inline-block;
7541: width: 5%;
7542: float: right;
7543: text-align: right;
7544: font-size: 70%;
7545: }
7546:
7547: ol.LC_primary_menu ul {
1.1076 raeburn 7548: display: none;
1.1205 golterma 7549: width: 15em;
1.1076 raeburn 7550: background-color: $data_table_light;
1.1205 golterma 7551: position: absolute;
7552: top: 100%;
1.1076 raeburn 7553: }
7554:
1.1205 golterma 7555: ol.LC_primary_menu ul ul {
7556: left: 100%;
7557: top: 0;
7558: }
7559:
7560: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7561: display: block;
7562: position: absolute;
7563: margin: 0;
7564: padding: 0;
1.1078 raeburn 7565: z-index: 2;
1.1076 raeburn 7566: }
7567:
7568: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7569: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7570: font-size: 90%;
1.911 bisitz 7571: vertical-align: top;
1.1076 raeburn 7572: float: none;
1.1079 raeburn 7573: border-left: 1px solid black;
7574: border-right: 1px solid black;
1.1205 golterma 7575: /* A dark bottom border to visualize different menu options;
7576: overwritten in the create_submenu routine for the last border-bottom of the menu */
7577: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7578: }
7579:
1.1205 golterma 7580: ol.LC_primary_menu li li p:hover {
7581: color:$button_hover;
7582: text-decoration:none;
7583: background-color:$data_table_dark;
1.1076 raeburn 7584: }
7585:
7586: ol.LC_primary_menu li li a:hover {
7587: color:$button_hover;
7588: background-color:$data_table_dark;
1.693 droeschl 7589: }
7590:
1.1205 golterma 7591: /* Font-size equal to the size of the predecessors*/
7592: ol.LC_primary_menu li:hover li li {
7593: font-size: 100%;
7594: }
7595:
1.897 wenzelju 7596: ol.LC_primary_menu li img {
1.911 bisitz 7597: vertical-align: bottom;
1.934 droeschl 7598: height: 1.1em;
1.1077 raeburn 7599: margin: 0.2em 0 0 0;
1.693 droeschl 7600: }
7601:
1.897 wenzelju 7602: ol.LC_primary_menu a {
1.911 bisitz 7603: color: RGB(80, 80, 80);
7604: text-decoration: none;
1.693 droeschl 7605: }
1.795 www 7606:
1.949 droeschl 7607: ol.LC_primary_menu a.LC_new_message {
7608: font-weight:bold;
7609: color: darkred;
7610: }
7611:
1.975 raeburn 7612: ol.LC_docs_parameters {
7613: margin-left: 0;
7614: padding: 0;
7615: list-style: none;
7616: }
7617:
7618: ol.LC_docs_parameters li {
7619: margin: 0;
7620: padding-right: 20px;
7621: display: inline;
7622: }
7623:
1.976 raeburn 7624: ol.LC_docs_parameters li:before {
7625: content: "\\002022 \\0020";
7626: }
7627:
7628: li.LC_docs_parameters_title {
7629: font-weight: bold;
7630: }
7631:
7632: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7633: content: "";
7634: }
7635:
1.897 wenzelju 7636: ul#LC_secondary_menu {
1.1107 raeburn 7637: clear: right;
1.911 bisitz 7638: color: $fontmenu;
7639: background: $tabbg;
7640: list-style: none;
7641: padding: 0;
7642: margin: 0;
7643: width: 100%;
1.995 raeburn 7644: text-align: left;
1.1107 raeburn 7645: float: left;
1.808 droeschl 7646: }
7647:
1.897 wenzelju 7648: ul#LC_secondary_menu li {
1.911 bisitz 7649: font-weight: bold;
7650: line-height: 1.8em;
1.1107 raeburn 7651: border-right: 1px solid black;
7652: float: left;
7653: }
7654:
7655: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7656: background-color: $data_table_light;
7657: }
7658:
7659: ul#LC_secondary_menu li a {
1.911 bisitz 7660: padding: 0 0.8em;
1.1107 raeburn 7661: }
7662:
7663: ul#LC_secondary_menu li ul {
7664: display: none;
7665: }
7666:
7667: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7668: display: block;
7669: position: absolute;
7670: margin: 0;
7671: padding: 0;
7672: list-style:none;
7673: float: none;
7674: background-color: $data_table_light;
7675: z-index: 2;
7676: margin-left: -1px;
7677: }
7678:
7679: ul#LC_secondary_menu li ul li {
7680: font-size: 90%;
7681: vertical-align: top;
7682: border-left: 1px solid black;
1.911 bisitz 7683: border-right: 1px solid black;
1.1119 raeburn 7684: background-color: $data_table_light;
1.1107 raeburn 7685: list-style:none;
7686: float: none;
7687: }
7688:
7689: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7690: background-color: $data_table_dark;
1.807 droeschl 7691: }
7692:
1.847 tempelho 7693: ul.LC_TabContent {
1.911 bisitz 7694: display:block;
7695: background: $sidebg;
7696: border-bottom: solid 1px $lg_border_color;
7697: list-style:none;
1.1020 raeburn 7698: margin: -1px -10px 0 -10px;
1.911 bisitz 7699: padding: 0;
1.693 droeschl 7700: }
7701:
1.795 www 7702: ul.LC_TabContent li,
7703: ul.LC_TabContentBigger li {
1.911 bisitz 7704: float:left;
1.741 harmsja 7705: }
1.795 www 7706:
1.897 wenzelju 7707: ul#LC_secondary_menu li a {
1.911 bisitz 7708: color: $fontmenu;
7709: text-decoration: none;
1.693 droeschl 7710: }
1.795 www 7711:
1.721 harmsja 7712: ul.LC_TabContent {
1.952 onken 7713: min-height:20px;
1.721 harmsja 7714: }
1.795 www 7715:
7716: ul.LC_TabContent li {
1.911 bisitz 7717: vertical-align:middle;
1.959 onken 7718: padding: 0 16px 0 10px;
1.911 bisitz 7719: background-color:$tabbg;
7720: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7721: border-left: solid 1px $font;
1.721 harmsja 7722: }
1.795 www 7723:
1.847 tempelho 7724: ul.LC_TabContent .right {
1.911 bisitz 7725: float:right;
1.847 tempelho 7726: }
7727:
1.911 bisitz 7728: ul.LC_TabContent li a,
7729: ul.LC_TabContent li {
7730: color:rgb(47,47,47);
7731: text-decoration:none;
7732: font-size:95%;
7733: font-weight:bold;
1.952 onken 7734: min-height:20px;
7735: }
7736:
1.959 onken 7737: ul.LC_TabContent li a:hover,
7738: ul.LC_TabContent li a:focus {
1.952 onken 7739: color: $button_hover;
1.959 onken 7740: background:none;
7741: outline:none;
1.952 onken 7742: }
7743:
7744: ul.LC_TabContent li:hover {
7745: color: $button_hover;
7746: cursor:pointer;
1.721 harmsja 7747: }
1.795 www 7748:
1.911 bisitz 7749: ul.LC_TabContent li.active {
1.952 onken 7750: color: $font;
1.911 bisitz 7751: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7752: border-bottom:solid 1px #FFFFFF;
7753: cursor: default;
1.744 ehlerst 7754: }
1.795 www 7755:
1.959 onken 7756: ul.LC_TabContent li.active a {
7757: color:$font;
7758: background:#FFFFFF;
7759: outline: none;
7760: }
1.1047 raeburn 7761:
7762: ul.LC_TabContent li.goback {
7763: float: left;
7764: border-left: none;
7765: }
7766:
1.870 tempelho 7767: #maincoursedoc {
1.911 bisitz 7768: clear:both;
1.870 tempelho 7769: }
7770:
7771: ul.LC_TabContentBigger {
1.911 bisitz 7772: display:block;
7773: list-style:none;
7774: padding: 0;
1.870 tempelho 7775: }
7776:
1.795 www 7777: ul.LC_TabContentBigger li {
1.911 bisitz 7778: vertical-align:bottom;
7779: height: 30px;
7780: font-size:110%;
7781: font-weight:bold;
7782: color: #737373;
1.841 tempelho 7783: }
7784:
1.957 onken 7785: ul.LC_TabContentBigger li.active {
7786: position: relative;
7787: top: 1px;
7788: }
7789:
1.870 tempelho 7790: ul.LC_TabContentBigger li a {
1.911 bisitz 7791: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7792: height: 30px;
7793: line-height: 30px;
7794: text-align: center;
7795: display: block;
7796: text-decoration: none;
1.958 onken 7797: outline: none;
1.741 harmsja 7798: }
1.795 www 7799:
1.870 tempelho 7800: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7801: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7802: color:$font;
1.744 ehlerst 7803: }
1.795 www 7804:
1.870 tempelho 7805: ul.LC_TabContentBigger li b {
1.911 bisitz 7806: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7807: display: block;
7808: float: left;
7809: padding: 0 30px;
1.957 onken 7810: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7811: }
7812:
1.956 onken 7813: ul.LC_TabContentBigger li:hover b {
7814: color:$button_hover;
7815: }
7816:
1.870 tempelho 7817: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7818: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7819: color:$font;
1.957 onken 7820: border: 0;
1.741 harmsja 7821: }
1.693 droeschl 7822:
1.870 tempelho 7823:
1.862 bisitz 7824: ul.LC_CourseBreadcrumbs {
7825: background: $sidebg;
1.1020 raeburn 7826: height: 2em;
1.862 bisitz 7827: padding-left: 10px;
1.1020 raeburn 7828: margin: 0;
1.862 bisitz 7829: list-style-position: inside;
7830: }
7831:
1.911 bisitz 7832: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7833: ol#LC_PathBreadcrumbs {
1.911 bisitz 7834: padding-left: 10px;
7835: margin: 0;
1.933 droeschl 7836: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7837: }
7838:
1.911 bisitz 7839: ol#LC_MenuBreadcrumbs li,
7840: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7841: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7842: display: inline;
1.933 droeschl 7843: white-space: normal;
1.693 droeschl 7844: }
7845:
1.823 bisitz 7846: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7847: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7848: text-decoration: none;
7849: font-size:90%;
1.693 droeschl 7850: }
1.795 www 7851:
1.969 droeschl 7852: ol#LC_MenuBreadcrumbs h1 {
7853: display: inline;
7854: font-size: 90%;
7855: line-height: 2.5em;
7856: margin: 0;
7857: padding: 0;
7858: }
7859:
1.795 www 7860: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7861: text-decoration:none;
7862: font-size:100%;
7863: font-weight:bold;
1.693 droeschl 7864: }
1.795 www 7865:
1.840 bisitz 7866: .LC_Box {
1.911 bisitz 7867: border: solid 1px $lg_border_color;
7868: padding: 0 10px 10px 10px;
1.746 neumanie 7869: }
1.795 www 7870:
1.1020 raeburn 7871: .LC_DocsBox {
7872: border: solid 1px $lg_border_color;
7873: padding: 0 0 10px 10px;
7874: }
7875:
1.795 www 7876: .LC_AboutMe_Image {
1.911 bisitz 7877: float:left;
7878: margin-right:10px;
1.747 neumanie 7879: }
1.795 www 7880:
7881: .LC_Clear_AboutMe_Image {
1.911 bisitz 7882: clear:left;
1.747 neumanie 7883: }
1.795 www 7884:
1.721 harmsja 7885: dl.LC_ListStyleClean dt {
1.911 bisitz 7886: padding-right: 5px;
7887: display: table-header-group;
1.693 droeschl 7888: }
7889:
1.721 harmsja 7890: dl.LC_ListStyleClean dd {
1.911 bisitz 7891: display: table-row;
1.693 droeschl 7892: }
7893:
1.721 harmsja 7894: .LC_ListStyleClean,
7895: .LC_ListStyleSimple,
7896: .LC_ListStyleNormal,
1.795 www 7897: .LC_ListStyleSpecial {
1.911 bisitz 7898: /* display:block; */
7899: list-style-position: inside;
7900: list-style-type: none;
7901: overflow: hidden;
7902: padding: 0;
1.693 droeschl 7903: }
7904:
1.721 harmsja 7905: .LC_ListStyleSimple li,
7906: .LC_ListStyleSimple dd,
7907: .LC_ListStyleNormal li,
7908: .LC_ListStyleNormal dd,
7909: .LC_ListStyleSpecial li,
1.795 www 7910: .LC_ListStyleSpecial dd {
1.911 bisitz 7911: margin: 0;
7912: padding: 5px 5px 5px 10px;
7913: clear: both;
1.693 droeschl 7914: }
7915:
1.721 harmsja 7916: .LC_ListStyleClean li,
7917: .LC_ListStyleClean dd {
1.911 bisitz 7918: padding-top: 0;
7919: padding-bottom: 0;
1.693 droeschl 7920: }
7921:
1.721 harmsja 7922: .LC_ListStyleSimple dd,
1.795 www 7923: .LC_ListStyleSimple li {
1.911 bisitz 7924: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7925: }
7926:
1.721 harmsja 7927: .LC_ListStyleSpecial li,
7928: .LC_ListStyleSpecial dd {
1.911 bisitz 7929: list-style-type: none;
7930: background-color: RGB(220, 220, 220);
7931: margin-bottom: 4px;
1.693 droeschl 7932: }
7933:
1.721 harmsja 7934: table.LC_SimpleTable {
1.911 bisitz 7935: margin:5px;
7936: border:solid 1px $lg_border_color;
1.795 www 7937: }
1.693 droeschl 7938:
1.721 harmsja 7939: table.LC_SimpleTable tr {
1.911 bisitz 7940: padding: 0;
7941: border:solid 1px $lg_border_color;
1.693 droeschl 7942: }
1.795 www 7943:
7944: table.LC_SimpleTable thead {
1.911 bisitz 7945: background:rgb(220,220,220);
1.693 droeschl 7946: }
7947:
1.721 harmsja 7948: div.LC_columnSection {
1.911 bisitz 7949: display: block;
7950: clear: both;
7951: overflow: hidden;
7952: margin: 0;
1.693 droeschl 7953: }
7954:
1.721 harmsja 7955: div.LC_columnSection>* {
1.911 bisitz 7956: float: left;
7957: margin: 10px 20px 10px 0;
7958: overflow:hidden;
1.693 droeschl 7959: }
1.721 harmsja 7960:
1.795 www 7961: table em {
1.911 bisitz 7962: font-weight: bold;
7963: font-style: normal;
1.748 schulted 7964: }
1.795 www 7965:
1.779 bisitz 7966: table.LC_tableBrowseRes,
1.795 www 7967: table.LC_tableOfContent {
1.911 bisitz 7968: border:none;
7969: border-spacing: 1px;
7970: padding: 3px;
7971: background-color: #FFFFFF;
7972: font-size: 90%;
1.753 droeschl 7973: }
1.789 droeschl 7974:
1.911 bisitz 7975: table.LC_tableOfContent {
7976: border-collapse: collapse;
1.789 droeschl 7977: }
7978:
1.771 droeschl 7979: table.LC_tableBrowseRes a,
1.768 schulted 7980: table.LC_tableOfContent a {
1.911 bisitz 7981: background-color: transparent;
7982: text-decoration: none;
1.753 droeschl 7983: }
7984:
1.795 www 7985: table.LC_tableOfContent img {
1.911 bisitz 7986: border: none;
7987: height: 1.3em;
7988: vertical-align: text-bottom;
7989: margin-right: 0.3em;
1.753 droeschl 7990: }
1.757 schulted 7991:
1.795 www 7992: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7993: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7994: }
7995:
1.795 www 7996: a#LC_content_toolbar_everything {
1.911 bisitz 7997: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7998: }
7999:
1.795 www 8000: a#LC_content_toolbar_uncompleted {
1.911 bisitz 8001: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 8002: }
8003:
1.795 www 8004: #LC_content_toolbar_clearbubbles {
1.911 bisitz 8005: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 8006: }
8007:
1.795 www 8008: a#LC_content_toolbar_changefolder {
1.911 bisitz 8009: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 8010: }
8011:
1.795 www 8012: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 8013: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 8014: }
8015:
1.1043 raeburn 8016: a#LC_content_toolbar_edittoplevel {
8017: background-image:url(/res/adm/pages/edittoplevel.gif);
8018: }
8019:
1.795 www 8020: ul#LC_toolbar li a:hover {
1.911 bisitz 8021: background-position: bottom center;
1.757 schulted 8022: }
8023:
1.795 www 8024: ul#LC_toolbar {
1.911 bisitz 8025: padding: 0;
8026: margin: 2px;
8027: list-style:none;
8028: position:relative;
8029: background-color:white;
1.1082 raeburn 8030: overflow: auto;
1.757 schulted 8031: }
8032:
1.795 www 8033: ul#LC_toolbar li {
1.911 bisitz 8034: border:1px solid white;
8035: padding: 0;
8036: margin: 0;
8037: float: left;
8038: display:inline;
8039: vertical-align:middle;
1.1082 raeburn 8040: white-space: nowrap;
1.911 bisitz 8041: }
1.757 schulted 8042:
1.783 amueller 8043:
1.795 www 8044: a.LC_toolbarItem {
1.911 bisitz 8045: display:block;
8046: padding: 0;
8047: margin: 0;
8048: height: 32px;
8049: width: 32px;
8050: color:white;
8051: border: none;
8052: background-repeat:no-repeat;
8053: background-color:transparent;
1.757 schulted 8054: }
8055:
1.915 droeschl 8056: ul.LC_funclist {
8057: margin: 0;
8058: padding: 0.5em 1em 0.5em 0;
8059: }
8060:
1.933 droeschl 8061: ul.LC_funclist > li:first-child {
8062: font-weight:bold;
8063: margin-left:0.8em;
8064: }
8065:
1.915 droeschl 8066: ul.LC_funclist + ul.LC_funclist {
8067: /*
8068: left border as a seperator if we have more than
8069: one list
8070: */
8071: border-left: 1px solid $sidebg;
8072: /*
8073: this hides the left border behind the border of the
8074: outer box if element is wrapped to the next 'line'
8075: */
8076: margin-left: -1px;
8077: }
8078:
1.843 bisitz 8079: ul.LC_funclist li {
1.915 droeschl 8080: display: inline;
1.782 bisitz 8081: white-space: nowrap;
1.915 droeschl 8082: margin: 0 0 0 25px;
8083: line-height: 150%;
1.782 bisitz 8084: }
8085:
1.974 wenzelju 8086: .LC_hidden {
8087: display: none;
8088: }
8089:
1.1030 www 8090: .LCmodal-overlay {
8091: position:fixed;
8092: top:0;
8093: right:0;
8094: bottom:0;
8095: left:0;
8096: height:100%;
8097: width:100%;
8098: margin:0;
8099: padding:0;
8100: background:#999;
8101: opacity:.75;
8102: filter: alpha(opacity=75);
8103: -moz-opacity: 0.75;
8104: z-index:101;
8105: }
8106:
8107: * html .LCmodal-overlay {
8108: position: absolute;
8109: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8110: }
8111:
8112: .LCmodal-window {
8113: position:fixed;
8114: top:50%;
8115: left:50%;
8116: margin:0;
8117: padding:0;
8118: z-index:102;
8119: }
8120:
8121: * html .LCmodal-window {
8122: position:absolute;
8123: }
8124:
8125: .LCclose-window {
8126: position:absolute;
8127: width:32px;
8128: height:32px;
8129: right:8px;
8130: top:8px;
8131: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8132: text-indent:-99999px;
8133: overflow:hidden;
8134: cursor:pointer;
8135: }
8136:
1.1100 raeburn 8137: /*
1.1231 damieng 8138: styles used for response display
8139: */
8140: div.LC_radiofoil, div.LC_rankfoil {
8141: margin: .5em 0em .5em 0em;
8142: }
8143: table.LC_itemgroup {
8144: margin-top: 1em;
8145: }
8146:
8147: /*
1.1100 raeburn 8148: styles used by TTH when "Default set of options to pass to tth/m
8149: when converting TeX" in course settings has been set
8150:
8151: option passed: -t
8152:
8153: */
8154:
8155: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8156: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8157: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8158: td div.norm {line-height:normal;}
8159:
8160: /*
8161: option passed -y3
8162: */
8163:
8164: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8165: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8166: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8167:
1.1230 damieng 8168: /*
8169: sections with roles, for content only
8170: */
8171: section[class^="role-"] {
8172: padding-left: 10px;
8173: padding-right: 5px;
8174: margin-top: 8px;
8175: margin-bottom: 8px;
8176: border: 1px solid #2A4;
8177: border-radius: 5px;
8178: box-shadow: 0px 1px 1px #BBB;
8179: }
8180: section[class^="role-"]>h1 {
8181: position: relative;
8182: margin: 0px;
8183: padding-top: 10px;
8184: padding-left: 40px;
8185: }
8186: section[class^="role-"]>h1:before {
8187: position: absolute;
8188: left: -5px;
8189: top: 5px;
8190: }
8191: section.role-activity>h1:before {
8192: content:url('/adm/daxe/images/section_icons/activity.png');
8193: }
8194: section.role-advice>h1:before {
8195: content:url('/adm/daxe/images/section_icons/advice.png');
8196: }
8197: section.role-bibliography>h1:before {
8198: content:url('/adm/daxe/images/section_icons/bibliography.png');
8199: }
8200: section.role-citation>h1:before {
8201: content:url('/adm/daxe/images/section_icons/citation.png');
8202: }
8203: section.role-conclusion>h1:before {
8204: content:url('/adm/daxe/images/section_icons/conclusion.png');
8205: }
8206: section.role-definition>h1:before {
8207: content:url('/adm/daxe/images/section_icons/definition.png');
8208: }
8209: section.role-demonstration>h1:before {
8210: content:url('/adm/daxe/images/section_icons/demonstration.png');
8211: }
8212: section.role-example>h1:before {
8213: content:url('/adm/daxe/images/section_icons/example.png');
8214: }
8215: section.role-explanation>h1:before {
8216: content:url('/adm/daxe/images/section_icons/explanation.png');
8217: }
8218: section.role-introduction>h1:before {
8219: content:url('/adm/daxe/images/section_icons/introduction.png');
8220: }
8221: section.role-method>h1:before {
8222: content:url('/adm/daxe/images/section_icons/method.png');
8223: }
8224: section.role-more_information>h1:before {
8225: content:url('/adm/daxe/images/section_icons/more_information.png');
8226: }
8227: section.role-objectives>h1:before {
8228: content:url('/adm/daxe/images/section_icons/objectives.png');
8229: }
8230: section.role-prerequisites>h1:before {
8231: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8232: }
8233: section.role-remark>h1:before {
8234: content:url('/adm/daxe/images/section_icons/remark.png');
8235: }
8236: section.role-reminder>h1:before {
8237: content:url('/adm/daxe/images/section_icons/reminder.png');
8238: }
8239: section.role-summary>h1:before {
8240: content:url('/adm/daxe/images/section_icons/summary.png');
8241: }
8242: section.role-syntax>h1:before {
8243: content:url('/adm/daxe/images/section_icons/syntax.png');
8244: }
8245: section.role-warning>h1:before {
8246: content:url('/adm/daxe/images/section_icons/warning.png');
8247: }
8248:
1.1269 raeburn 8249: #LC_minitab_header {
8250: float:left;
8251: width:100%;
8252: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8253: font-size:93%;
8254: line-height:normal;
8255: margin: 0.5em 0 0.5em 0;
8256: }
8257: #LC_minitab_header ul {
8258: margin:0;
8259: padding:10px 10px 0;
8260: list-style:none;
8261: }
8262: #LC_minitab_header li {
8263: float:left;
8264: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8265: margin:0;
8266: padding:0 0 0 9px;
8267: }
8268: #LC_minitab_header a {
8269: display:block;
8270: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8271: padding:5px 15px 4px 6px;
8272: }
8273: #LC_minitab_header #LC_current_minitab {
8274: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8275: }
8276: #LC_minitab_header #LC_current_minitab a {
8277: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8278: padding-bottom:5px;
8279: }
8280:
8281:
1.343 albertel 8282: END
8283: }
8284:
1.306 albertel 8285: =pod
8286:
8287: =item * &headtag()
8288:
8289: Returns a uniform footer for LON-CAPA web pages.
8290:
1.307 albertel 8291: Inputs: $title - optional title for the head
8292: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8293: $args - optional arguments
1.319 albertel 8294: force_register - if is true call registerurl so the remote is
8295: informed
1.415 albertel 8296: redirect -> array ref of
8297: 1- seconds before redirect occurs
8298: 2- url to redirect to
8299: 3- whether the side effect should occur
1.315 albertel 8300: (side effect of setting
8301: $env{'internal.head.redirect'} to the url
8302: redirected too)
1.352 albertel 8303: domain -> force to color decorate a page for a specific
8304: domain
8305: function -> force usage of a specific rolish color scheme
8306: bgcolor -> override the default page bgcolor
1.460 albertel 8307: no_auto_mt_title
8308: -> prevent &mt()ing the title arg
1.464 albertel 8309:
1.306 albertel 8310: =cut
8311:
8312: sub headtag {
1.313 albertel 8313: my ($title,$head_extra,$args) = @_;
1.306 albertel 8314:
1.363 albertel 8315: my $function = $args->{'function'} || &get_users_function();
8316: my $domain = $args->{'domain'} || &determinedomain();
8317: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8318: my $httphost = $args->{'use_absolute'};
1.418 albertel 8319: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8320: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8321: #time(),
1.418 albertel 8322: $env{'environment.color.timestamp'},
1.363 albertel 8323: $function,$domain,$bgcolor);
8324:
1.369 www 8325: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8326:
1.308 albertel 8327: my $result =
8328: '<head>'.
1.1160 raeburn 8329: &font_settings($args);
1.319 albertel 8330:
1.1188 raeburn 8331: my $inhibitprint;
8332: if ($args->{'print_suppress'}) {
8333: $inhibitprint = &print_suppression();
8334: }
1.1064 raeburn 8335:
1.461 albertel 8336: if (!$args->{'frameset'}) {
8337: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8338: }
1.962 droeschl 8339: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8340: $result .= Apache::lonxml::display_title();
1.319 albertel 8341: }
1.436 albertel 8342: if (!$args->{'no_nav_bar'}
8343: && !$args->{'only_body'}
8344: && !$args->{'frameset'}) {
1.1154 raeburn 8345: $result .= &help_menu_js($httphost);
1.1032 www 8346: $result.=&modal_window();
1.1038 www 8347: $result.=&togglebox_script();
1.1034 www 8348: $result.=&wishlist_window();
1.1041 www 8349: $result.=&LCprogressbarUpdate_script();
1.1034 www 8350: } else {
8351: if ($args->{'add_modal'}) {
8352: $result.=&modal_window();
8353: }
8354: if ($args->{'add_wishlist'}) {
8355: $result.=&wishlist_window();
8356: }
1.1038 www 8357: if ($args->{'add_togglebox'}) {
8358: $result.=&togglebox_script();
8359: }
1.1041 www 8360: if ($args->{'add_progressbar'}) {
8361: $result.=&LCprogressbarUpdate_script();
8362: }
1.436 albertel 8363: }
1.314 albertel 8364: if (ref($args->{'redirect'})) {
1.414 albertel 8365: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8366: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8367: if (!$inhibit_continue) {
8368: $env{'internal.head.redirect'} = $url;
8369: }
1.313 albertel 8370: $result.=<<ADDMETA
8371: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8372: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8373: ADDMETA
1.1210 raeburn 8374: } else {
8375: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8376: my $requrl = $env{'request.uri'};
8377: if ($requrl eq '') {
8378: $requrl = $ENV{'REQUEST_URI'};
8379: $requrl =~ s/\?.+$//;
8380: }
8381: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8382: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8383: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8384: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8385: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8386: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
8387: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8388: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
8389: if ($domdefs{'offloadnow'}{$lonhost}) {
8390: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
8391: if (($newserver) && ($newserver ne $lonhost)) {
8392: my $numsec = 5;
8393: my $timeout = $numsec * 1000;
8394: my ($newurl,$locknum,%locks,$msg);
8395: if ($env{'request.role.adv'}) {
8396: ($locknum,%locks) = &Apache::lonnet::get_locks();
8397: }
8398: my $disable_submit = 0;
8399: if ($requrl =~ /$LONCAPA::assess_re/) {
8400: $disable_submit = 1;
8401: }
8402: if ($locknum) {
8403: my @lockinfo = sort(values(%locks));
8404: $msg = &mt('Once the following tasks are complete: ')."\\n".
8405: join(", ",sort(values(%locks)))."\\n".
8406: &mt('your session will be transferred to a different server, after you click "Roles".');
8407: } else {
8408: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8409: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
8410: }
8411: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8412: $newurl = '/adm/switchserver?otherserver='.$newserver;
8413: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8414: $newurl .= '&role='.$env{'request.role'};
8415: }
8416: if ($env{'request.symb'}) {
8417: $newurl .= '&symb='.$env{'request.symb'};
8418: } else {
8419: $newurl .= '&origurl='.$requrl;
8420: }
8421: }
1.1222 damieng 8422: &js_escape(\$msg);
1.1210 raeburn 8423: $result.=<<OFFLOAD
8424: <meta http-equiv="pragma" content="no-cache" />
8425: <script type="text/javascript">
1.1215 raeburn 8426: // <![CDATA[
1.1210 raeburn 8427: function LC_Offload_Now() {
8428: var dest = "$newurl";
8429: if (dest != '') {
8430: window.location.href="$newurl";
8431: }
8432: }
1.1214 raeburn 8433: \$(document).ready(function () {
8434: window.alert('$msg');
8435: if ($disable_submit) {
1.1210 raeburn 8436: \$(".LC_hwk_submit").prop("disabled", true);
8437: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8438: }
8439: setTimeout('LC_Offload_Now()', $timeout);
8440: });
1.1215 raeburn 8441: // ]]>
1.1210 raeburn 8442: </script>
8443: OFFLOAD
8444: }
8445: }
8446: }
8447: }
8448: }
8449: }
1.313 albertel 8450: }
1.306 albertel 8451: if (!defined($title)) {
8452: $title = 'The LearningOnline Network with CAPA';
8453: }
1.460 albertel 8454: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8455: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8456: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8457: if (!$args->{'frameset'}) {
8458: $result .= ' /';
8459: }
8460: $result .= '>'
1.1064 raeburn 8461: .$inhibitprint
1.414 albertel 8462: .$head_extra;
1.1242 raeburn 8463: my $clientmobile;
8464: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8465: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8466: } else {
8467: $clientmobile = $env{'browser.mobile'};
8468: }
8469: if ($clientmobile) {
1.1137 raeburn 8470: $result .= '
8471: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8472: <meta name="apple-mobile-web-app-capable" content="yes" />';
8473: }
1.1278 raeburn 8474: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8475: return $result.'</head>';
1.306 albertel 8476: }
8477:
8478: =pod
8479:
1.340 albertel 8480: =item * &font_settings()
8481:
8482: Returns neccessary <meta> to set the proper encoding
8483:
1.1160 raeburn 8484: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8485:
8486: =cut
8487:
8488: sub font_settings {
1.1160 raeburn 8489: my ($args) = @_;
1.340 albertel 8490: my $headerstring='';
1.1160 raeburn 8491: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8492: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8493: $headerstring.=
8494: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8495: if (!$args->{'frameset'}) {
8496: $headerstring.= ' /';
8497: }
8498: $headerstring .= '>'."\n";
1.340 albertel 8499: }
8500: return $headerstring;
8501: }
8502:
1.341 albertel 8503: =pod
8504:
1.1064 raeburn 8505: =item * &print_suppression()
8506:
8507: In course context returns css which causes the body to be blank when media="print",
8508: if printout generation is unavailable for the current resource.
8509:
8510: This could be because:
8511:
8512: (a) printstartdate is in the future
8513:
8514: (b) printenddate is in the past
8515:
8516: (c) there is an active exam block with "printout"
8517: functionality blocked
8518:
8519: Users with pav, pfo or evb privileges are exempt.
8520:
8521: Inputs: none
8522:
8523: =cut
8524:
8525:
8526: sub print_suppression {
8527: my $noprint;
8528: if ($env{'request.course.id'}) {
8529: my $scope = $env{'request.course.id'};
8530: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8531: (&Apache::lonnet::allowed('pfo',$scope))) {
8532: return;
8533: }
8534: if ($env{'request.course.sec'} ne '') {
8535: $scope .= "/$env{'request.course.sec'}";
8536: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8537: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8538: return;
1.1064 raeburn 8539: }
8540: }
8541: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8542: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8543: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8544: if ($blocked) {
8545: my $checkrole = "cm./$cdom/$cnum";
8546: if ($env{'request.course.sec'} ne '') {
8547: $checkrole .= "/$env{'request.course.sec'}";
8548: }
8549: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8550: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8551: $noprint = 1;
8552: }
8553: }
8554: unless ($noprint) {
8555: my $symb = &Apache::lonnet::symbread();
8556: if ($symb ne '') {
8557: my $navmap = Apache::lonnavmaps::navmap->new();
8558: if (ref($navmap)) {
8559: my $res = $navmap->getBySymb($symb);
8560: if (ref($res)) {
8561: if (!$res->resprintable()) {
8562: $noprint = 1;
8563: }
8564: }
8565: }
8566: }
8567: }
8568: if ($noprint) {
8569: return <<"ENDSTYLE";
8570: <style type="text/css" media="print">
8571: body { display:none }
8572: </style>
8573: ENDSTYLE
8574: }
8575: }
8576: return;
8577: }
8578:
8579: =pod
8580:
1.341 albertel 8581: =item * &xml_begin()
8582:
8583: Returns the needed doctype and <html>
8584:
8585: Inputs: none
8586:
8587: =cut
8588:
8589: sub xml_begin {
1.1168 raeburn 8590: my ($is_frameset) = @_;
1.341 albertel 8591: my $output='';
8592:
8593: if ($env{'browser.mathml'}) {
8594: $output='<?xml version="1.0"?>'
8595: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8596: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8597:
8598: # .'<!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">] >'
8599: .'<!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">'
8600: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8601: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8602: } elsif ($is_frameset) {
8603: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8604: '<html>'."\n";
1.341 albertel 8605: } else {
1.1168 raeburn 8606: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8607: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8608: }
8609: return $output;
8610: }
1.340 albertel 8611:
8612: =pod
8613:
1.306 albertel 8614: =item * &start_page()
8615:
8616: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8617:
1.648 raeburn 8618: Inputs:
8619:
8620: =over 4
8621:
8622: $title - optional title for the page
8623:
8624: $head_extra - optional extra HTML to incude inside the <head>
8625:
8626: $args - additional optional args supported are:
8627:
8628: =over 8
8629:
8630: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8631: arg on
1.814 bisitz 8632: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8633: add_entries -> additional attributes to add to the <body>
8634: domain -> force to color decorate a page for a
1.317 albertel 8635: specific domain
1.648 raeburn 8636: function -> force usage of a specific rolish color
1.317 albertel 8637: scheme
1.648 raeburn 8638: redirect -> see &headtag()
8639: bgcolor -> override the default page bg color
8640: js_ready -> return a string ready for being used in
1.317 albertel 8641: a javascript writeln
1.648 raeburn 8642: html_encode -> return a string ready for being used in
1.320 albertel 8643: a html attribute
1.648 raeburn 8644: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8645: $forcereg arg
1.648 raeburn 8646: frameset -> if true will start with a <frameset>
1.330 albertel 8647: rather than <body>
1.648 raeburn 8648: skip_phases -> hash ref of
1.338 albertel 8649: head -> skip the <html><head> generation
8650: body -> skip all <body> generation
1.648 raeburn 8651: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8652: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8653: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 8654: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8655: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 8656: group -> includes the current group, if page is for a
1.1274 raeburn 8657: specific group
8658: use_absolute -> for request for external resource or syllabus, this
8659: will contain https://<hostname> if server uses
8660: https (as per hosts.tab), but request is for http
8661: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8662:
1.648 raeburn 8663: =back
1.460 albertel 8664:
1.648 raeburn 8665: =back
1.562 albertel 8666:
1.306 albertel 8667: =cut
8668:
8669: sub start_page {
1.309 albertel 8670: my ($title,$head_extra,$args) = @_;
1.318 albertel 8671: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8672:
1.315 albertel 8673: $env{'internal.start_page'}++;
1.1096 raeburn 8674: my ($result,@advtools);
1.964 droeschl 8675:
1.338 albertel 8676: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8677: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8678: }
8679:
8680: if (! exists($args->{'skip_phases'}{'body'}) ) {
8681: if ($args->{'frameset'}) {
8682: my $attr_string = &make_attr_string($args->{'force_register'},
8683: $args->{'add_entries'});
8684: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8685: } else {
8686: $result .=
8687: &bodytag($title,
8688: $args->{'function'}, $args->{'add_entries'},
8689: $args->{'only_body'}, $args->{'domain'},
8690: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8691: $args->{'bgcolor'}, $args,
8692: \@advtools);
1.831 bisitz 8693: }
1.330 albertel 8694: }
1.338 albertel 8695:
1.315 albertel 8696: if ($args->{'js_ready'}) {
1.713 kaisler 8697: $result = &js_ready($result);
1.315 albertel 8698: }
1.320 albertel 8699: if ($args->{'html_encode'}) {
1.713 kaisler 8700: $result = &html_encode($result);
8701: }
8702:
1.813 bisitz 8703: # Preparation for new and consistent functionlist at top of screen
8704: # if ($args->{'functionlist'}) {
8705: # $result .= &build_functionlist();
8706: #}
8707:
1.964 droeschl 8708: # Don't add anything more if only_body wanted or in const space
8709: return $result if $args->{'only_body'}
8710: || $env{'request.state'} eq 'construct';
1.813 bisitz 8711:
8712: #Breadcrumbs
1.758 kaisler 8713: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8714: &Apache::lonhtmlcommon::clear_breadcrumbs();
8715: #if any br links exists, add them to the breadcrumbs
8716: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8717: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8718: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8719: }
8720: }
1.1096 raeburn 8721: # if @advtools array contains items add then to the breadcrumbs
8722: if (@advtools > 0) {
8723: &Apache::lonmenu::advtools_crumbs(@advtools);
8724: }
1.1272 raeburn 8725: my $menulink;
8726: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8727: if ((exists($args->{'bread_crumbs_nomenu'})) ||
8728: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
8729: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
8730: (!$env{'request.role.adv'}))) {
8731: $menulink = 0;
8732: } else {
8733: undef($menulink);
8734: }
1.758 kaisler 8735: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8736: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 8737: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 8738: } else {
1.1272 raeburn 8739: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8740: }
1.320 albertel 8741: }
1.315 albertel 8742: return $result;
1.306 albertel 8743: }
8744:
8745: sub end_page {
1.315 albertel 8746: my ($args) = @_;
8747: $env{'internal.end_page'}++;
1.330 albertel 8748: my $result;
1.335 albertel 8749: if ($args->{'discussion'}) {
8750: my ($target,$parser);
8751: if (ref($args->{'discussion'})) {
8752: ($target,$parser) =($args->{'discussion'}{'target'},
8753: $args->{'discussion'}{'parser'});
8754: }
8755: $result .= &Apache::lonxml::xmlend($target,$parser);
8756: }
1.330 albertel 8757: if ($args->{'frameset'}) {
8758: $result .= '</frameset>';
8759: } else {
1.635 raeburn 8760: $result .= &endbodytag($args);
1.330 albertel 8761: }
1.1080 raeburn 8762: unless ($args->{'notbody'}) {
8763: $result .= "\n</html>";
8764: }
1.330 albertel 8765:
1.315 albertel 8766: if ($args->{'js_ready'}) {
1.317 albertel 8767: $result = &js_ready($result);
1.315 albertel 8768: }
1.335 albertel 8769:
1.320 albertel 8770: if ($args->{'html_encode'}) {
8771: $result = &html_encode($result);
8772: }
1.335 albertel 8773:
1.315 albertel 8774: return $result;
8775: }
8776:
1.1034 www 8777: sub wishlist_window {
8778: return(<<'ENDWISHLIST');
1.1046 raeburn 8779: <script type="text/javascript">
1.1034 www 8780: // <![CDATA[
8781: // <!-- BEGIN LON-CAPA Internal
8782: function set_wishlistlink(title, path) {
8783: if (!title) {
8784: title = document.title;
8785: title = title.replace(/^LON-CAPA /,'');
8786: }
1.1175 raeburn 8787: title = encodeURIComponent(title);
1.1203 raeburn 8788: title = title.replace("'","\\\'");
1.1034 www 8789: if (!path) {
8790: path = location.pathname;
8791: }
1.1175 raeburn 8792: path = encodeURIComponent(path);
1.1203 raeburn 8793: path = path.replace("'","\\\'");
1.1034 www 8794: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8795: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8796: }
8797: // END LON-CAPA Internal -->
8798: // ]]>
8799: </script>
8800: ENDWISHLIST
8801: }
8802:
1.1030 www 8803: sub modal_window {
8804: return(<<'ENDMODAL');
1.1046 raeburn 8805: <script type="text/javascript">
1.1030 www 8806: // <![CDATA[
8807: // <!-- BEGIN LON-CAPA Internal
8808: var modalWindow = {
8809: parent:"body",
8810: windowId:null,
8811: content:null,
8812: width:null,
8813: height:null,
8814: close:function()
8815: {
8816: $(".LCmodal-window").remove();
8817: $(".LCmodal-overlay").remove();
8818: },
8819: open:function()
8820: {
8821: var modal = "";
8822: modal += "<div class=\"LCmodal-overlay\"></div>";
8823: 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;\">";
8824: modal += this.content;
8825: modal += "</div>";
8826:
8827: $(this.parent).append(modal);
8828:
8829: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8830: $(".LCclose-window").click(function(){modalWindow.close();});
8831: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8832: }
8833: };
1.1140 raeburn 8834: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8835: {
1.1266 raeburn 8836: source = source.replace(/'/g,"'");
1.1030 www 8837: modalWindow.windowId = "myModal";
8838: modalWindow.width = width;
8839: modalWindow.height = height;
1.1196 raeburn 8840: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8841: modalWindow.open();
1.1208 raeburn 8842: };
1.1030 www 8843: // END LON-CAPA Internal -->
8844: // ]]>
8845: </script>
8846: ENDMODAL
8847: }
8848:
8849: sub modal_link {
1.1140 raeburn 8850: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8851: unless ($width) { $width=480; }
8852: unless ($height) { $height=400; }
1.1031 www 8853: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 8854: unless ($transparency) { $transparency='true'; }
8855:
1.1074 raeburn 8856: my $target_attr;
8857: if (defined($target)) {
8858: $target_attr = 'target="'.$target.'"';
8859: }
8860: return <<"ENDLINK";
1.1140 raeburn 8861: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8862: $linktext</a>
8863: ENDLINK
1.1030 www 8864: }
8865:
1.1032 www 8866: sub modal_adhoc_script {
8867: my ($funcname,$width,$height,$content)=@_;
8868: return (<<ENDADHOC);
1.1046 raeburn 8869: <script type="text/javascript">
1.1032 www 8870: // <![CDATA[
8871: var $funcname = function()
8872: {
8873: modalWindow.windowId = "myModal";
8874: modalWindow.width = $width;
8875: modalWindow.height = $height;
8876: modalWindow.content = '$content';
8877: modalWindow.open();
8878: };
8879: // ]]>
8880: </script>
8881: ENDADHOC
8882: }
8883:
1.1041 www 8884: sub modal_adhoc_inner {
8885: my ($funcname,$width,$height,$content)=@_;
8886: my $innerwidth=$width-20;
8887: $content=&js_ready(
1.1140 raeburn 8888: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
8889: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8890: $content.
1.1041 www 8891: &end_scrollbox().
1.1140 raeburn 8892: &end_page()
1.1041 www 8893: );
8894: return &modal_adhoc_script($funcname,$width,$height,$content);
8895: }
8896:
8897: sub modal_adhoc_window {
8898: my ($funcname,$width,$height,$content,$linktext)=@_;
8899: return &modal_adhoc_inner($funcname,$width,$height,$content).
8900: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8901: }
8902:
8903: sub modal_adhoc_launch {
8904: my ($funcname,$width,$height,$content)=@_;
8905: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8906: <script type="text/javascript">
8907: // <![CDATA[
8908: $funcname();
8909: // ]]>
8910: </script>
8911: ENDLAUNCH
8912: }
8913:
8914: sub modal_adhoc_close {
8915: return (<<ENDCLOSE);
8916: <script type="text/javascript">
8917: // <![CDATA[
8918: modalWindow.close();
8919: // ]]>
8920: </script>
8921: ENDCLOSE
8922: }
8923:
1.1038 www 8924: sub togglebox_script {
8925: return(<<ENDTOGGLE);
8926: <script type="text/javascript">
8927: // <![CDATA[
8928: function LCtoggleDisplay(id,hidetext,showtext) {
8929: link = document.getElementById(id + "link").childNodes[0];
8930: with (document.getElementById(id).style) {
8931: if (display == "none" ) {
8932: display = "inline";
8933: link.nodeValue = hidetext;
8934: } else {
8935: display = "none";
8936: link.nodeValue = showtext;
8937: }
8938: }
8939: }
8940: // ]]>
8941: </script>
8942: ENDTOGGLE
8943: }
8944:
1.1039 www 8945: sub start_togglebox {
8946: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8947: unless ($heading) { $heading=''; } else { $heading.=' '; }
8948: unless ($showtext) { $showtext=&mt('show'); }
8949: unless ($hidetext) { $hidetext=&mt('hide'); }
8950: unless ($headerbg) { $headerbg='#FFFFFF'; }
8951: return &start_data_table().
8952: &start_data_table_header_row().
8953: '<td bgcolor="'.$headerbg.'">'.$heading.
8954: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8955: $showtext.'\')">'.$showtext.'</a>]</td>'.
8956: &end_data_table_header_row().
8957: '<tr id="'.$id.'" style="display:none""><td>';
8958: }
8959:
8960: sub end_togglebox {
8961: return '</td></tr>'.&end_data_table();
8962: }
8963:
1.1041 www 8964: sub LCprogressbar_script {
1.1302 raeburn 8965: my ($id,$number_to_do)=@_;
8966: if ($number_to_do) {
8967: return(<<ENDPROGRESS);
1.1041 www 8968: <script type="text/javascript">
8969: // <![CDATA[
1.1045 www 8970: \$('#progressbar$id').progressbar({
1.1041 www 8971: value: 0,
8972: change: function(event, ui) {
8973: var newVal = \$(this).progressbar('option', 'value');
8974: \$('.pblabel', this).text(LCprogressTxt);
8975: }
8976: });
8977: // ]]>
8978: </script>
8979: ENDPROGRESS
1.1302 raeburn 8980: } else {
8981: return(<<ENDPROGRESS);
8982: <script type="text/javascript">
8983: // <![CDATA[
8984: \$('#progressbar$id').progressbar({
8985: value: false,
8986: create: function(event, ui) {
8987: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
8988: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
8989: }
8990: });
8991: // ]]>
8992: </script>
8993: ENDPROGRESS
8994: }
1.1041 www 8995: }
8996:
8997: sub LCprogressbarUpdate_script {
8998: return(<<ENDPROGRESSUPDATE);
8999: <style type="text/css">
9000: .ui-progressbar { position:relative; }
1.1302 raeburn 9001: .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 9002: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9003: </style>
9004: <script type="text/javascript">
9005: // <![CDATA[
1.1045 www 9006: var LCprogressTxt='---';
9007:
1.1302 raeburn 9008: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9009: LCprogressTxt=progresstext;
1.1302 raeburn 9010: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9011: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9012: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 9013: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9014: } else {
9015: \$('#progressbar'+id).progressbar('value',percent);
9016: }
1.1041 www 9017: }
9018: // ]]>
9019: </script>
9020: ENDPROGRESSUPDATE
9021: }
9022:
1.1042 www 9023: my $LClastpercent;
1.1045 www 9024: my $LCidcnt;
9025: my $LCcurrentid;
1.1042 www 9026:
1.1041 www 9027: sub LCprogressbar {
1.1302 raeburn 9028: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9029: $LClastpercent=0;
1.1045 www 9030: $LCidcnt++;
9031: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 9032: my ($starting,$content);
9033: if ($number_to_do) {
9034: $starting=&mt('Starting');
9035: $content=(<<ENDPROGBAR);
9036: $preamble
1.1045 www 9037: <div id="progressbar$LCcurrentid">
1.1041 www 9038: <span class="pblabel">$starting</span>
9039: </div>
9040: ENDPROGBAR
1.1302 raeburn 9041: } else {
9042: $starting=&mt('Loading...');
9043: $LClastpercent='false';
9044: $content=(<<ENDPROGBAR);
9045: $preamble
9046: <div id="progressbar$LCcurrentid">
9047: <div class="progress-label">$starting</div>
9048: </div>
9049: ENDPROGBAR
9050: }
9051: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9052: }
9053:
9054: sub LCprogressbarUpdate {
1.1302 raeburn 9055: my ($r,$val,$text,$number_to_do)=@_;
9056: if ($number_to_do) {
9057: unless ($val) {
9058: if ($LClastpercent) {
9059: $val=$LClastpercent;
9060: } else {
9061: $val=0;
9062: }
9063: }
9064: if ($val<0) { $val=0; }
9065: if ($val>100) { $val=0; }
9066: $LClastpercent=$val;
9067: unless ($text) { $text=$val.'%'; }
9068: } else {
9069: $val = 'false';
1.1042 www 9070: }
1.1041 www 9071: $text=&js_ready($text);
1.1044 www 9072: &r_print($r,<<ENDUPDATE);
1.1041 www 9073: <script type="text/javascript">
9074: // <![CDATA[
1.1302 raeburn 9075: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9076: // ]]>
9077: </script>
9078: ENDUPDATE
1.1035 www 9079: }
9080:
1.1042 www 9081: sub LCprogressbarClose {
9082: my ($r)=@_;
9083: $LClastpercent=0;
1.1044 www 9084: &r_print($r,<<ENDCLOSE);
1.1042 www 9085: <script type="text/javascript">
9086: // <![CDATA[
1.1045 www 9087: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9088: // ]]>
9089: </script>
9090: ENDCLOSE
1.1044 www 9091: }
9092:
9093: sub r_print {
9094: my ($r,$to_print)=@_;
9095: if ($r) {
9096: $r->print($to_print);
9097: $r->rflush();
9098: } else {
9099: print($to_print);
9100: }
1.1042 www 9101: }
9102:
1.320 albertel 9103: sub html_encode {
9104: my ($result) = @_;
9105:
1.322 albertel 9106: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9107:
9108: return $result;
9109: }
1.1044 www 9110:
1.317 albertel 9111: sub js_ready {
9112: my ($result) = @_;
9113:
1.323 albertel 9114: $result =~ s/[\n\r]/ /xmsg;
9115: $result =~ s/\\/\\\\/xmsg;
9116: $result =~ s/'/\\'/xmsg;
1.372 albertel 9117: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9118:
9119: return $result;
9120: }
9121:
1.315 albertel 9122: sub validate_page {
9123: if ( exists($env{'internal.start_page'})
1.316 albertel 9124: && $env{'internal.start_page'} > 1) {
9125: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9126: $env{'internal.start_page'}.' '.
1.316 albertel 9127: $ENV{'request.filename'});
1.315 albertel 9128: }
9129: if ( exists($env{'internal.end_page'})
1.316 albertel 9130: && $env{'internal.end_page'} > 1) {
9131: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9132: $env{'internal.end_page'}.' '.
1.316 albertel 9133: $env{'request.filename'});
1.315 albertel 9134: }
9135: if ( exists($env{'internal.start_page'})
9136: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9137: &Apache::lonnet::logthis('start_page called without end_page '.
9138: $env{'request.filename'});
1.315 albertel 9139: }
9140: if ( ! exists($env{'internal.start_page'})
9141: && exists($env{'internal.end_page'})) {
1.316 albertel 9142: &Apache::lonnet::logthis('end_page called without start_page'.
9143: $env{'request.filename'});
1.315 albertel 9144: }
1.306 albertel 9145: }
1.315 albertel 9146:
1.996 www 9147:
9148: sub start_scrollbox {
1.1140 raeburn 9149: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9150: unless ($outerwidth) { $outerwidth='520px'; }
9151: unless ($width) { $width='500px'; }
9152: unless ($height) { $height='200px'; }
1.1075 raeburn 9153: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9154: if ($id ne '') {
1.1140 raeburn 9155: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9156: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9157: }
1.1075 raeburn 9158: if ($bgcolor ne '') {
9159: $tdcol = "background-color: $bgcolor;";
9160: }
1.1137 raeburn 9161: my $nicescroll_js;
9162: if ($env{'browser.mobile'}) {
1.1140 raeburn 9163: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9164: }
9165: return <<"END";
9166: $nicescroll_js
9167:
9168: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9169: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9170: END
9171: }
9172:
9173: sub end_scrollbox {
9174: return '</div></td></tr></table>';
9175: }
9176:
9177: sub nicescroll_javascript {
9178: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9179: my %options;
9180: if (ref($cursor) eq 'HASH') {
9181: %options = %{$cursor};
9182: }
9183: unless ($options{'railalign'} =~ /^left|right$/) {
9184: $options{'railalign'} = 'left';
9185: }
9186: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9187: my $function = &get_users_function();
9188: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9189: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9190: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9191: }
1.1140 raeburn 9192: }
9193: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9194: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9195: $options{'cursoropacity'}='1.0';
9196: }
1.1140 raeburn 9197: } else {
9198: $options{'cursoropacity'}='1.0';
9199: }
9200: if ($options{'cursorfixedheight'} eq 'none') {
9201: delete($options{'cursorfixedheight'});
9202: } else {
9203: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9204: }
9205: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9206: delete($options{'railoffset'});
9207: }
9208: my @niceoptions;
9209: while (my($key,$value) = each(%options)) {
9210: if ($value =~ /^\{.+\}$/) {
9211: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9212: } else {
1.1140 raeburn 9213: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9214: }
1.1140 raeburn 9215: }
9216: my $nicescroll_js = '
1.1137 raeburn 9217: $(document).ready(
1.1140 raeburn 9218: function() {
9219: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9220: }
1.1137 raeburn 9221: );
9222: ';
1.1140 raeburn 9223: if ($framecheck) {
9224: $nicescroll_js .= '
9225: function expand_div(caller) {
9226: if (top === self) {
9227: document.getElementById("'.$id.'").style.width = "auto";
9228: document.getElementById("'.$id.'").style.height = "auto";
9229: } else {
9230: try {
9231: if (parent.frames) {
9232: if (parent.frames.length > 1) {
9233: var framesrc = parent.frames[1].location.href;
9234: var currsrc = framesrc.replace(/\#.*$/,"");
9235: if ((caller == "search") || (currsrc == "'.$location.'")) {
9236: document.getElementById("'.$id.'").style.width = "auto";
9237: document.getElementById("'.$id.'").style.height = "auto";
9238: }
9239: }
9240: }
9241: } catch (e) {
9242: return;
9243: }
1.1137 raeburn 9244: }
1.1140 raeburn 9245: return;
1.996 www 9246: }
1.1140 raeburn 9247: ';
9248: }
9249: if ($needjsready) {
9250: $nicescroll_js = '
9251: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9252: } else {
9253: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9254: }
9255: return $nicescroll_js;
1.996 www 9256: }
9257:
1.318 albertel 9258: sub simple_error_page {
1.1150 bisitz 9259: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 9260: my %displayargs;
1.1151 raeburn 9261: if (ref($args) eq 'HASH') {
9262: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 9263: if ($args->{'only_body'}) {
9264: $displayargs{'only_body'} = 1;
9265: }
9266: if ($args->{'no_nav_bar'}) {
9267: $displayargs{'no_nav_bar'} = 1;
9268: }
1.1151 raeburn 9269: } else {
9270: $msg = &mt($msg);
9271: }
1.1150 bisitz 9272:
1.318 albertel 9273: my $page =
1.1304 raeburn 9274: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 9275: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9276: &Apache::loncommon::end_page();
9277: if (ref($r)) {
9278: $r->print($page);
1.327 albertel 9279: return;
1.318 albertel 9280: }
9281: return $page;
9282: }
1.347 albertel 9283:
9284: {
1.610 albertel 9285: my @row_count;
1.961 onken 9286:
9287: sub start_data_table_count {
9288: unshift(@row_count, 0);
9289: return;
9290: }
9291:
9292: sub end_data_table_count {
9293: shift(@row_count);
9294: return;
9295: }
9296:
1.347 albertel 9297: sub start_data_table {
1.1018 raeburn 9298: my ($add_class,$id) = @_;
1.422 albertel 9299: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9300: my $table_id;
9301: if (defined($id)) {
9302: $table_id = ' id="'.$id.'"';
9303: }
1.961 onken 9304: &start_data_table_count();
1.1018 raeburn 9305: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9306: }
9307:
9308: sub end_data_table {
1.961 onken 9309: &end_data_table_count();
1.389 albertel 9310: return '</table>'."\n";;
1.347 albertel 9311: }
9312:
9313: sub start_data_table_row {
1.974 wenzelju 9314: my ($add_class, $id) = @_;
1.610 albertel 9315: $row_count[0]++;
9316: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9317: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9318: $id = (' id="'.$id.'"') unless ($id eq '');
9319: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9320: }
1.471 banghart 9321:
9322: sub continue_data_table_row {
1.974 wenzelju 9323: my ($add_class, $id) = @_;
1.610 albertel 9324: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9325: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9326: $id = (' id="'.$id.'"') unless ($id eq '');
9327: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9328: }
1.347 albertel 9329:
9330: sub end_data_table_row {
1.389 albertel 9331: return '</tr>'."\n";;
1.347 albertel 9332: }
1.367 www 9333:
1.421 albertel 9334: sub start_data_table_empty_row {
1.707 bisitz 9335: # $row_count[0]++;
1.421 albertel 9336: return '<tr class="LC_empty_row" >'."\n";;
9337: }
9338:
9339: sub end_data_table_empty_row {
9340: return '</tr>'."\n";;
9341: }
9342:
1.367 www 9343: sub start_data_table_header_row {
1.389 albertel 9344: return '<tr class="LC_header_row">'."\n";;
1.367 www 9345: }
9346:
9347: sub end_data_table_header_row {
1.389 albertel 9348: return '</tr>'."\n";;
1.367 www 9349: }
1.890 droeschl 9350:
9351: sub data_table_caption {
9352: my $caption = shift;
9353: return "<caption class=\"LC_caption\">$caption</caption>";
9354: }
1.347 albertel 9355: }
9356:
1.548 albertel 9357: =pod
9358:
9359: =item * &inhibit_menu_check($arg)
9360:
9361: Checks for a inhibitmenu state and generates output to preserve it
9362:
9363: Inputs: $arg - can be any of
9364: - undef - in which case the return value is a string
9365: to add into arguments list of a uri
9366: - 'input' - in which case the return value is a HTML
9367: <form> <input> field of type hidden to
9368: preserve the value
9369: - a url - in which case the return value is the url with
9370: the neccesary cgi args added to preserve the
9371: inhibitmenu state
9372: - a ref to a url - no return value, but the string is
9373: updated to include the neccessary cgi
9374: args to preserve the inhibitmenu state
9375:
9376: =cut
9377:
9378: sub inhibit_menu_check {
9379: my ($arg) = @_;
9380: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9381: if ($arg eq 'input') {
9382: if ($env{'form.inhibitmenu'}) {
9383: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9384: } else {
9385: return
9386: }
9387: }
9388: if ($env{'form.inhibitmenu'}) {
9389: if (ref($arg)) {
9390: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9391: } elsif ($arg eq '') {
9392: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9393: } else {
9394: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9395: }
9396: }
9397: if (!ref($arg)) {
9398: return $arg;
9399: }
9400: }
9401:
1.251 albertel 9402: ###############################################
1.182 matthew 9403:
9404: =pod
9405:
1.549 albertel 9406: =back
9407:
9408: =head1 User Information Routines
9409:
9410: =over 4
9411:
1.405 albertel 9412: =item * &get_users_function()
1.182 matthew 9413:
9414: Used by &bodytag to determine the current users primary role.
9415: Returns either 'student','coordinator','admin', or 'author'.
9416:
9417: =cut
9418:
9419: ###############################################
9420: sub get_users_function {
1.815 tempelho 9421: my $function = 'norole';
1.818 tempelho 9422: if ($env{'request.role'}=~/^(st)/) {
9423: $function='student';
9424: }
1.907 raeburn 9425: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9426: $function='coordinator';
9427: }
1.258 albertel 9428: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9429: $function='admin';
9430: }
1.826 bisitz 9431: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9432: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9433: $function='author';
9434: }
9435: return $function;
1.54 www 9436: }
1.99 www 9437:
9438: ###############################################
9439:
1.233 raeburn 9440: =pod
9441:
1.821 raeburn 9442: =item * &show_course()
9443:
9444: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9445: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9446:
9447: Inputs:
9448: None
9449:
9450: Outputs:
9451: Scalar: 1 if 'Course' to be used, 0 otherwise.
9452:
9453: =cut
9454:
9455: ###############################################
9456: sub show_course {
9457: my $course = !$env{'user.adv'};
9458: if (!$env{'user.adv'}) {
9459: foreach my $env (keys(%env)) {
9460: next if ($env !~ m/^user\.priv\./);
9461: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9462: $course = 0;
9463: last;
9464: }
9465: }
9466: }
9467: return $course;
9468: }
9469:
9470: ###############################################
9471:
9472: =pod
9473:
1.542 raeburn 9474: =item * &check_user_status()
1.274 raeburn 9475:
9476: Determines current status of supplied role for a
9477: specific user. Roles can be active, previous or future.
9478:
9479: Inputs:
9480: user's domain, user's username, course's domain,
1.375 raeburn 9481: course's number, optional section ID.
1.274 raeburn 9482:
9483: Outputs:
9484: role status: active, previous or future.
9485:
9486: =cut
9487:
9488: sub check_user_status {
1.412 raeburn 9489: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9490: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9491: my @uroles = keys(%userinfo);
1.274 raeburn 9492: my $srchstr;
9493: my $active_chk = 'none';
1.412 raeburn 9494: my $now = time;
1.274 raeburn 9495: if (@uroles > 0) {
1.908 raeburn 9496: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9497: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9498: } else {
1.412 raeburn 9499: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9500: }
9501: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9502: my $role_end = 0;
9503: my $role_start = 0;
9504: $active_chk = 'active';
1.412 raeburn 9505: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9506: $role_end = $1;
9507: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9508: $role_start = $1;
1.274 raeburn 9509: }
9510: }
9511: if ($role_start > 0) {
1.412 raeburn 9512: if ($now < $role_start) {
1.274 raeburn 9513: $active_chk = 'future';
9514: }
9515: }
9516: if ($role_end > 0) {
1.412 raeburn 9517: if ($now > $role_end) {
1.274 raeburn 9518: $active_chk = 'previous';
9519: }
9520: }
9521: }
9522: }
9523: return $active_chk;
9524: }
9525:
9526: ###############################################
9527:
9528: =pod
9529:
1.405 albertel 9530: =item * &get_sections()
1.233 raeburn 9531:
9532: Determines all the sections for a course including
9533: sections with students and sections containing other roles.
1.419 raeburn 9534: Incoming parameters:
9535:
9536: 1. domain
9537: 2. course number
9538: 3. reference to array containing roles for which sections should
9539: be gathered (optional).
9540: 4. reference to array containing status types for which sections
9541: should be gathered (optional).
9542:
9543: If the third argument is undefined, sections are gathered for any role.
9544: If the fourth argument is undefined, sections are gathered for any status.
9545: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9546:
1.374 raeburn 9547: Returns section hash (keys are section IDs, values are
9548: number of users in each section), subject to the
1.419 raeburn 9549: optional roles filter, optional status filter
1.233 raeburn 9550:
9551: =cut
9552:
9553: ###############################################
9554: sub get_sections {
1.419 raeburn 9555: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9556: if (!defined($cdom) || !defined($cnum)) {
9557: my $cid = $env{'request.course.id'};
9558:
9559: return if (!defined($cid));
9560:
9561: $cdom = $env{'course.'.$cid.'.domain'};
9562: $cnum = $env{'course.'.$cid.'.num'};
9563: }
9564:
9565: my %sectioncount;
1.419 raeburn 9566: my $now = time;
1.240 albertel 9567:
1.1118 raeburn 9568: my $check_students = 1;
9569: my $only_students = 0;
9570: if (ref($possible_roles) eq 'ARRAY') {
9571: if (grep(/^st$/,@{$possible_roles})) {
9572: if (@{$possible_roles} == 1) {
9573: $only_students = 1;
9574: }
9575: } else {
9576: $check_students = 0;
9577: }
9578: }
9579:
9580: if ($check_students) {
1.276 albertel 9581: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9582: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9583: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9584: my $start_index = &Apache::loncoursedata::CL_START();
9585: my $end_index = &Apache::loncoursedata::CL_END();
9586: my $status;
1.366 albertel 9587: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9588: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9589: $data->[$status_index],
9590: $data->[$start_index],
9591: $data->[$end_index]);
9592: if ($stu_status eq 'Active') {
9593: $status = 'active';
9594: } elsif ($end < $now) {
9595: $status = 'previous';
9596: } elsif ($start > $now) {
9597: $status = 'future';
9598: }
9599: if ($section ne '-1' && $section !~ /^\s*$/) {
9600: if ((!defined($possible_status)) || (($status ne '') &&
9601: (grep/^\Q$status\E$/,@{$possible_status}))) {
9602: $sectioncount{$section}++;
9603: }
1.240 albertel 9604: }
9605: }
9606: }
1.1118 raeburn 9607: if ($only_students) {
9608: return %sectioncount;
9609: }
1.240 albertel 9610: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9611: foreach my $user (sort(keys(%courseroles))) {
9612: if ($user !~ /^(\w{2})/) { next; }
9613: my ($role) = ($user =~ /^(\w{2})/);
9614: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9615: my ($section,$status);
1.240 albertel 9616: if ($role eq 'cr' &&
9617: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9618: $section=$1;
9619: }
9620: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9621: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9622: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9623: if ($end == -1 && $start == -1) {
9624: next; #deleted role
9625: }
9626: if (!defined($possible_status)) {
9627: $sectioncount{$section}++;
9628: } else {
9629: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9630: $status = 'active';
9631: } elsif ($end < $now) {
9632: $status = 'future';
9633: } elsif ($start > $now) {
9634: $status = 'previous';
9635: }
9636: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9637: $sectioncount{$section}++;
9638: }
9639: }
1.233 raeburn 9640: }
1.366 albertel 9641: return %sectioncount;
1.233 raeburn 9642: }
9643:
1.274 raeburn 9644: ###############################################
1.294 raeburn 9645:
9646: =pod
1.405 albertel 9647:
9648: =item * &get_course_users()
9649:
1.275 raeburn 9650: Retrieves usernames:domains for users in the specified course
9651: with specific role(s), and access status.
9652:
9653: Incoming parameters:
1.277 albertel 9654: 1. course domain
9655: 2. course number
9656: 3. access status: users must have - either active,
1.275 raeburn 9657: previous, future, or all.
1.277 albertel 9658: 4. reference to array of permissible roles
1.288 raeburn 9659: 5. reference to array of section restrictions (optional)
9660: 6. reference to results object (hash of hashes).
9661: 7. reference to optional userdata hash
1.609 raeburn 9662: 8. reference to optional statushash
1.630 raeburn 9663: 9. flag if privileged users (except those set to unhide in
9664: course settings) should be excluded
1.609 raeburn 9665: Keys of top level results hash are roles.
1.275 raeburn 9666: Keys of inner hashes are username:domain, with
9667: values set to access type.
1.288 raeburn 9668: Optional userdata hash returns an array with arguments in the
9669: same order as loncoursedata::get_classlist() for student data.
9670:
1.609 raeburn 9671: Optional statushash returns
9672:
1.288 raeburn 9673: Entries for end, start, section and status are blank because
9674: of the possibility of multiple values for non-student roles.
9675:
1.275 raeburn 9676: =cut
1.405 albertel 9677:
1.275 raeburn 9678: ###############################################
1.405 albertel 9679:
1.275 raeburn 9680: sub get_course_users {
1.630 raeburn 9681: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9682: my %idx = ();
1.419 raeburn 9683: my %seclists;
1.288 raeburn 9684:
9685: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9686: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9687: $idx{end} = &Apache::loncoursedata::CL_END();
9688: $idx{start} = &Apache::loncoursedata::CL_START();
9689: $idx{id} = &Apache::loncoursedata::CL_ID();
9690: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9691: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9692: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9693:
1.290 albertel 9694: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9695: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9696: my $now = time;
1.277 albertel 9697: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9698: my $match = 0;
1.412 raeburn 9699: my $secmatch = 0;
1.419 raeburn 9700: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9701: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9702: if ($section eq '') {
9703: $section = 'none';
9704: }
1.291 albertel 9705: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9706: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9707: $secmatch = 1;
9708: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9709: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9710: $secmatch = 1;
9711: }
9712: } else {
1.419 raeburn 9713: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9714: $secmatch = 1;
9715: }
1.290 albertel 9716: }
1.412 raeburn 9717: if (!$secmatch) {
9718: next;
9719: }
1.419 raeburn 9720: }
1.275 raeburn 9721: if (defined($$types{'active'})) {
1.288 raeburn 9722: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9723: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9724: $match = 1;
1.275 raeburn 9725: }
9726: }
9727: if (defined($$types{'previous'})) {
1.609 raeburn 9728: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9729: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9730: $match = 1;
1.275 raeburn 9731: }
9732: }
9733: if (defined($$types{'future'})) {
1.609 raeburn 9734: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9735: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9736: $match = 1;
1.275 raeburn 9737: }
9738: }
1.609 raeburn 9739: if ($match) {
9740: push(@{$seclists{$student}},$section);
9741: if (ref($userdata) eq 'HASH') {
9742: $$userdata{$student} = $$classlist{$student};
9743: }
9744: if (ref($statushash) eq 'HASH') {
9745: $statushash->{$student}{'st'}{$section} = $status;
9746: }
1.288 raeburn 9747: }
1.275 raeburn 9748: }
9749: }
1.412 raeburn 9750: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9751: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9752: my $now = time;
1.609 raeburn 9753: my %displaystatus = ( previous => 'Expired',
9754: active => 'Active',
9755: future => 'Future',
9756: );
1.1121 raeburn 9757: my (%nothide,@possdoms);
1.630 raeburn 9758: if ($hidepriv) {
9759: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9760: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9761: if ($user !~ /:/) {
9762: $nothide{join(':',split(/[\@]/,$user))}=1;
9763: } else {
9764: $nothide{$user} = 1;
9765: }
9766: }
1.1121 raeburn 9767: my @possdoms = ($cdom);
9768: if ($coursehash{'checkforpriv'}) {
9769: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9770: }
1.630 raeburn 9771: }
1.439 raeburn 9772: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9773: my $match = 0;
1.412 raeburn 9774: my $secmatch = 0;
1.439 raeburn 9775: my $status;
1.412 raeburn 9776: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9777: $user =~ s/:$//;
1.439 raeburn 9778: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9779: if ($end == -1 || $start == -1) {
9780: next;
9781: }
9782: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9783: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9784: my ($uname,$udom) = split(/:/,$user);
9785: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9786: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9787: $secmatch = 1;
9788: } elsif ($usec eq '') {
1.420 albertel 9789: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9790: $secmatch = 1;
9791: }
9792: } else {
9793: if (grep(/^\Q$usec\E$/,@{$sections})) {
9794: $secmatch = 1;
9795: }
9796: }
9797: if (!$secmatch) {
9798: next;
9799: }
1.288 raeburn 9800: }
1.419 raeburn 9801: if ($usec eq '') {
9802: $usec = 'none';
9803: }
1.275 raeburn 9804: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9805: if ($hidepriv) {
1.1121 raeburn 9806: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9807: (!$nothide{$uname.':'.$udom})) {
9808: next;
9809: }
9810: }
1.503 raeburn 9811: if ($end > 0 && $end < $now) {
1.439 raeburn 9812: $status = 'previous';
9813: } elsif ($start > $now) {
9814: $status = 'future';
9815: } else {
9816: $status = 'active';
9817: }
1.277 albertel 9818: foreach my $type (keys(%{$types})) {
1.275 raeburn 9819: if ($status eq $type) {
1.420 albertel 9820: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9821: push(@{$$users{$role}{$user}},$type);
9822: }
1.288 raeburn 9823: $match = 1;
9824: }
9825: }
1.419 raeburn 9826: if (($match) && (ref($userdata) eq 'HASH')) {
9827: if (!exists($$userdata{$uname.':'.$udom})) {
9828: &get_user_info($udom,$uname,\%idx,$userdata);
9829: }
1.420 albertel 9830: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9831: push(@{$seclists{$uname.':'.$udom}},$usec);
9832: }
1.609 raeburn 9833: if (ref($statushash) eq 'HASH') {
9834: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9835: }
1.275 raeburn 9836: }
9837: }
9838: }
9839: }
1.290 albertel 9840: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9841: if ((defined($cdom)) && (defined($cnum))) {
9842: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9843: if ( defined($csettings{'internal.courseowner'}) ) {
9844: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9845: next if ($owner eq '');
9846: my ($ownername,$ownerdom);
9847: if ($owner =~ /^([^:]+):([^:]+)$/) {
9848: $ownername = $1;
9849: $ownerdom = $2;
9850: } else {
9851: $ownername = $owner;
9852: $ownerdom = $cdom;
9853: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9854: }
9855: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9856: if (defined($userdata) &&
1.609 raeburn 9857: !exists($$userdata{$owner})) {
9858: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9859: if (!grep(/^none$/,@{$seclists{$owner}})) {
9860: push(@{$seclists{$owner}},'none');
9861: }
9862: if (ref($statushash) eq 'HASH') {
9863: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9864: }
1.290 albertel 9865: }
1.279 raeburn 9866: }
9867: }
9868: }
1.419 raeburn 9869: foreach my $user (keys(%seclists)) {
9870: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9871: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9872: }
1.275 raeburn 9873: }
9874: return;
9875: }
9876:
1.288 raeburn 9877: sub get_user_info {
9878: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9879: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9880: &plainname($uname,$udom,'lastname');
1.291 albertel 9881: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9882: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9883: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9884: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9885: return;
9886: }
1.275 raeburn 9887:
1.472 raeburn 9888: ###############################################
9889:
9890: =pod
9891:
9892: =item * &get_user_quota()
9893:
1.1134 raeburn 9894: Retrieves quota assigned for storage of user files.
9895: Default is to report quota for portfolio files.
1.472 raeburn 9896:
9897: Incoming parameters:
9898: 1. user's username
9899: 2. user's domain
1.1134 raeburn 9900: 3. quota name - portfolio, author, or course
1.1136 raeburn 9901: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 9902: 4. crstype - official, unofficial, textbook, placement or community,
9903: if quota name is course
1.472 raeburn 9904:
9905: Returns:
1.1163 raeburn 9906: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9907: 2. (Optional) Type of setting: custom or default
9908: (individually assigned or default for user's
9909: institutional status).
9910: 3. (Optional) - User's institutional status (e.g., faculty, staff
9911: or student - types as defined in localenroll::inst_usertypes
9912: for user's domain, which determines default quota for user.
9913: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9914:
9915: If a value has been stored in the user's environment,
1.536 raeburn 9916: it will return that, otherwise it returns the maximal default
1.1134 raeburn 9917: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9918:
9919: =cut
9920:
9921: ###############################################
9922:
9923:
9924: sub get_user_quota {
1.1136 raeburn 9925: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9926: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9927: if (!defined($udom)) {
9928: $udom = $env{'user.domain'};
9929: }
9930: if (!defined($uname)) {
9931: $uname = $env{'user.name'};
9932: }
9933: if (($udom eq '' || $uname eq '') ||
9934: ($udom eq 'public') && ($uname eq 'public')) {
9935: $quota = 0;
1.536 raeburn 9936: $quotatype = 'default';
9937: $defquota = 0;
1.472 raeburn 9938: } else {
1.536 raeburn 9939: my $inststatus;
1.1134 raeburn 9940: if ($quotaname eq 'course') {
9941: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9942: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9943: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9944: } else {
9945: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9946: $quota = $cenv{'internal.uploadquota'};
9947: }
1.536 raeburn 9948: } else {
1.1134 raeburn 9949: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9950: if ($quotaname eq 'author') {
9951: $quota = $env{'environment.authorquota'};
9952: } else {
9953: $quota = $env{'environment.portfolioquota'};
9954: }
9955: $inststatus = $env{'environment.inststatus'};
9956: } else {
9957: my %userenv =
9958: &Apache::lonnet::get('environment',['portfolioquota',
9959: 'authorquota','inststatus'],$udom,$uname);
9960: my ($tmp) = keys(%userenv);
9961: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9962: if ($quotaname eq 'author') {
9963: $quota = $userenv{'authorquota'};
9964: } else {
9965: $quota = $userenv{'portfolioquota'};
9966: }
9967: $inststatus = $userenv{'inststatus'};
9968: } else {
9969: undef(%userenv);
9970: }
9971: }
9972: }
9973: if ($quota eq '' || wantarray) {
9974: if ($quotaname eq 'course') {
9975: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 9976: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 9977: ($crstype eq 'community') || ($crstype eq 'textbook') ||
9978: ($crstype eq 'placement')) {
1.1136 raeburn 9979: $defquota = $domdefs{$crstype.'quota'};
9980: }
9981: if ($defquota eq '') {
9982: $defquota = 500;
9983: }
1.1134 raeburn 9984: } else {
9985: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9986: }
9987: if ($quota eq '') {
9988: $quota = $defquota;
9989: $quotatype = 'default';
9990: } else {
9991: $quotatype = 'custom';
9992: }
1.472 raeburn 9993: }
9994: }
1.536 raeburn 9995: if (wantarray) {
9996: return ($quota,$quotatype,$settingstatus,$defquota);
9997: } else {
9998: return $quota;
9999: }
1.472 raeburn 10000: }
10001:
10002: ###############################################
10003:
10004: =pod
10005:
10006: =item * &default_quota()
10007:
1.536 raeburn 10008: Retrieves default quota assigned for storage of user portfolio files,
10009: given an (optional) user's institutional status.
1.472 raeburn 10010:
10011: Incoming parameters:
1.1142 raeburn 10012:
1.472 raeburn 10013: 1. domain
1.536 raeburn 10014: 2. (Optional) institutional status(es). This is a : separated list of
10015: status types (e.g., faculty, staff, student etc.)
10016: which apply to the user for whom the default is being retrieved.
10017: If the institutional status string in undefined, the domain
1.1134 raeburn 10018: default quota will be returned.
10019: 3. quota name - portfolio, author, or course
10020: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10021:
10022: Returns:
1.1142 raeburn 10023:
1.1163 raeburn 10024: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10025: 2. (Optional) institutional type which determined the value of the
10026: default quota.
1.472 raeburn 10027:
10028: If a value has been stored in the domain's configuration db,
10029: it will return that, otherwise it returns 20 (for backwards
10030: compatibility with domains which have not set up a configuration
1.1163 raeburn 10031: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10032:
1.536 raeburn 10033: If the user's status includes multiple types (e.g., staff and student),
10034: the largest default quota which applies to the user determines the
10035: default quota returned.
10036:
1.472 raeburn 10037: =cut
10038:
10039: ###############################################
10040:
10041:
10042: sub default_quota {
1.1134 raeburn 10043: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10044: my ($defquota,$settingstatus);
10045: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10046: ['quotas'],$udom);
1.1134 raeburn 10047: my $key = 'defaultquota';
10048: if ($quotaname eq 'author') {
10049: $key = 'authorquota';
10050: }
1.622 raeburn 10051: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10052: if ($inststatus ne '') {
1.765 raeburn 10053: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10054: foreach my $item (@statuses) {
1.1134 raeburn 10055: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10056: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10057: if ($defquota eq '') {
1.1134 raeburn 10058: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10059: $settingstatus = $item;
1.1134 raeburn 10060: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10061: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10062: $settingstatus = $item;
10063: }
10064: }
1.1134 raeburn 10065: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10066: if ($quotahash{'quotas'}{$item} ne '') {
10067: if ($defquota eq '') {
10068: $defquota = $quotahash{'quotas'}{$item};
10069: $settingstatus = $item;
10070: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10071: $defquota = $quotahash{'quotas'}{$item};
10072: $settingstatus = $item;
10073: }
1.536 raeburn 10074: }
10075: }
10076: }
10077: }
10078: if ($defquota eq '') {
1.1134 raeburn 10079: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10080: $defquota = $quotahash{'quotas'}{$key}{'default'};
10081: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10082: $defquota = $quotahash{'quotas'}{'default'};
10083: }
1.536 raeburn 10084: $settingstatus = 'default';
1.1139 raeburn 10085: if ($defquota eq '') {
10086: if ($quotaname eq 'author') {
10087: $defquota = 500;
10088: }
10089: }
1.536 raeburn 10090: }
10091: } else {
10092: $settingstatus = 'default';
1.1134 raeburn 10093: if ($quotaname eq 'author') {
10094: $defquota = 500;
10095: } else {
10096: $defquota = 20;
10097: }
1.536 raeburn 10098: }
10099: if (wantarray) {
10100: return ($defquota,$settingstatus);
1.472 raeburn 10101: } else {
1.536 raeburn 10102: return $defquota;
1.472 raeburn 10103: }
10104: }
10105:
1.1135 raeburn 10106: ###############################################
10107:
10108: =pod
10109:
1.1136 raeburn 10110: =item * &excess_filesize_warning()
1.1135 raeburn 10111:
10112: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 10113: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 10114: space to be exceeded.
1.1136 raeburn 10115:
10116: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 10117: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 10118:
1.1165 raeburn 10119: Inputs: 7
1.1136 raeburn 10120: 1. username or coursenum
1.1135 raeburn 10121: 2. domain
1.1136 raeburn 10122: 3. context ('author' or 'course')
1.1135 raeburn 10123: 4. filename of file for which action is being requested
10124: 5. filesize (kB) of file
10125: 6. action being taken: copy or upload.
1.1237 raeburn 10126: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 10127:
10128: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 10129: otherwise return null.
10130:
10131: =back
1.1135 raeburn 10132:
10133: =cut
10134:
1.1136 raeburn 10135: sub excess_filesize_warning {
1.1165 raeburn 10136: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 10137: my $current_disk_usage = 0;
1.1165 raeburn 10138: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 10139: if ($context eq 'author') {
10140: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10141: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10142: } else {
10143: foreach my $subdir ('docs','supplemental') {
10144: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10145: }
10146: }
1.1135 raeburn 10147: $disk_quota = int($disk_quota * 1000);
10148: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 10149: return '<p class="LC_warning">'.
1.1135 raeburn 10150: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 10151: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10152: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 10153: $disk_quota,$current_disk_usage).
10154: '</p>';
10155: }
10156: return;
10157: }
10158:
10159: ###############################################
10160:
10161:
1.1136 raeburn 10162:
10163:
1.384 raeburn 10164: sub get_secgrprole_info {
10165: my ($cdom,$cnum,$needroles,$type) = @_;
10166: my %sections_count = &get_sections($cdom,$cnum);
10167: my @sections = (sort {$a <=> $b} keys(%sections_count));
10168: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10169: my @groups = sort(keys(%curr_groups));
10170: my $allroles = [];
10171: my $rolehash;
10172: my $accesshash = {
10173: active => 'Currently has access',
10174: future => 'Will have future access',
10175: previous => 'Previously had access',
10176: };
10177: if ($needroles) {
10178: $rolehash = {'all' => 'all'};
1.385 albertel 10179: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10180: if (&Apache::lonnet::error(%user_roles)) {
10181: undef(%user_roles);
10182: }
10183: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10184: my ($role)=split(/\:/,$item,2);
10185: if ($role eq 'cr') { next; }
10186: if ($role =~ /^cr/) {
10187: $$rolehash{$role} = (split('/',$role))[3];
10188: } else {
10189: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10190: }
10191: }
10192: foreach my $key (sort(keys(%{$rolehash}))) {
10193: push(@{$allroles},$key);
10194: }
10195: push (@{$allroles},'st');
10196: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10197: }
10198: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10199: }
10200:
1.555 raeburn 10201: sub user_picker {
1.1279 raeburn 10202: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10203: my $currdom = $dom;
1.1253 raeburn 10204: my @alldoms = &Apache::lonnet::all_domains();
10205: if (@alldoms == 1) {
10206: my %domsrch = &Apache::lonnet::get_dom('configuration',
10207: ['directorysrch'],$alldoms[0]);
10208: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10209: my $showdom = $domdesc;
10210: if ($showdom eq '') {
10211: $showdom = $dom;
10212: }
10213: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10214: if ((!$domsrch{'directorysrch'}{'available'}) &&
10215: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10216: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10217: }
10218: }
10219: }
1.555 raeburn 10220: my %curr_selected = (
10221: srchin => 'dom',
1.580 raeburn 10222: srchby => 'lastname',
1.555 raeburn 10223: );
10224: my $srchterm;
1.625 raeburn 10225: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10226: if ($srch->{'srchby'} ne '') {
10227: $curr_selected{'srchby'} = $srch->{'srchby'};
10228: }
10229: if ($srch->{'srchin'} ne '') {
10230: $curr_selected{'srchin'} = $srch->{'srchin'};
10231: }
10232: if ($srch->{'srchtype'} ne '') {
10233: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10234: }
10235: if ($srch->{'srchdomain'} ne '') {
10236: $currdom = $srch->{'srchdomain'};
10237: }
10238: $srchterm = $srch->{'srchterm'};
10239: }
1.1222 damieng 10240: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10241: 'usr' => 'Search criteria',
1.563 raeburn 10242: 'doma' => 'Domain/institution to search',
1.558 albertel 10243: 'uname' => 'username',
10244: 'lastname' => 'last name',
1.555 raeburn 10245: 'lastfirst' => 'last name, first name',
1.558 albertel 10246: 'crs' => 'in this course',
1.576 raeburn 10247: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10248: 'alc' => 'all LON-CAPA',
1.573 raeburn 10249: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10250: 'exact' => 'is',
10251: 'contains' => 'contains',
1.569 raeburn 10252: 'begins' => 'begins with',
1.1222 damieng 10253: );
10254: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10255: 'youm' => "You must include some text to search for.",
10256: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10257: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10258: 'yomc' => "You must choose a domain when using an institutional directory search.",
10259: 'ymcd' => "You must choose a domain when using a domain search.",
10260: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10261: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10262: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10263: );
1.1222 damieng 10264: &html_escape(\%html_lt);
10265: &js_escape(\%js_lt);
1.1255 raeburn 10266: my $domform;
1.1277 raeburn 10267: my $allow_blank = 1;
1.1255 raeburn 10268: if ($fixeddom) {
1.1277 raeburn 10269: $allow_blank = 0;
10270: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10271: } else {
1.1287 raeburn 10272: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 10273: my ($trusted,$untrusted);
1.1287 raeburn 10274: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 10275: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 10276: } elsif ($context eq 'author') {
1.1288 raeburn 10277: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 10278: } elsif ($context eq 'domain') {
1.1288 raeburn 10279: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 10280: }
1.1288 raeburn 10281: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 10282: }
1.563 raeburn 10283: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10284:
10285: my @srchins = ('crs','dom','alc','instd');
10286:
10287: foreach my $option (@srchins) {
10288: # FIXME 'alc' option unavailable until
10289: # loncreateuser::print_user_query_page()
10290: # has been completed.
10291: next if ($option eq 'alc');
1.880 raeburn 10292: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10293: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 10294: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10295: if ($curr_selected{'srchin'} eq $option) {
10296: $srchinsel .= '
1.1222 damieng 10297: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10298: } else {
10299: $srchinsel .= '
1.1222 damieng 10300: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10301: }
1.555 raeburn 10302: }
1.563 raeburn 10303: $srchinsel .= "\n </select>\n";
1.555 raeburn 10304:
10305: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10306: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10307: if ($curr_selected{'srchby'} eq $option) {
10308: $srchbysel .= '
1.1222 damieng 10309: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10310: } else {
10311: $srchbysel .= '
1.1222 damieng 10312: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10313: }
10314: }
10315: $srchbysel .= "\n </select>\n";
10316:
10317: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10318: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10319: if ($curr_selected{'srchtype'} eq $option) {
10320: $srchtypesel .= '
1.1222 damieng 10321: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10322: } else {
10323: $srchtypesel .= '
1.1222 damieng 10324: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10325: }
10326: }
10327: $srchtypesel .= "\n </select>\n";
10328:
1.558 albertel 10329: my ($newuserscript,$new_user_create);
1.994 raeburn 10330: my $context_dom = $env{'request.role.domain'};
10331: if ($context eq 'requestcrs') {
10332: if ($env{'form.coursedom'} ne '') {
10333: $context_dom = $env{'form.coursedom'};
10334: }
10335: }
1.556 raeburn 10336: if ($forcenewuser) {
1.576 raeburn 10337: if (ref($srch) eq 'HASH') {
1.994 raeburn 10338: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10339: if ($cancreate) {
10340: $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>';
10341: } else {
1.799 bisitz 10342: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10343: my %usertypetext = (
10344: official => 'institutional',
10345: unofficial => 'non-institutional',
10346: );
1.799 bisitz 10347: $new_user_create = '<p class="LC_warning">'
10348: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10349: .' '
10350: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10351: ,'<a href="'.$helplink.'">','</a>')
10352: .'</p><br />';
1.627 raeburn 10353: }
1.576 raeburn 10354: }
10355: }
10356:
1.556 raeburn 10357: $newuserscript = <<"ENDSCRIPT";
10358:
1.570 raeburn 10359: function setSearch(createnew,callingForm) {
1.556 raeburn 10360: if (createnew == 1) {
1.570 raeburn 10361: for (var i=0; i<callingForm.srchby.length; i++) {
10362: if (callingForm.srchby.options[i].value == 'uname') {
10363: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10364: }
10365: }
1.570 raeburn 10366: for (var i=0; i<callingForm.srchin.length; i++) {
10367: if ( callingForm.srchin.options[i].value == 'dom') {
10368: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10369: }
10370: }
1.570 raeburn 10371: for (var i=0; i<callingForm.srchtype.length; i++) {
10372: if (callingForm.srchtype.options[i].value == 'exact') {
10373: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10374: }
10375: }
1.570 raeburn 10376: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10377: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10378: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10379: }
10380: }
10381: }
10382: }
10383: ENDSCRIPT
1.558 albertel 10384:
1.556 raeburn 10385: }
10386:
1.555 raeburn 10387: my $output = <<"END_BLOCK";
1.556 raeburn 10388: <script type="text/javascript">
1.824 bisitz 10389: // <![CDATA[
1.570 raeburn 10390: function validateEntry(callingForm) {
1.558 albertel 10391:
1.556 raeburn 10392: var checkok = 1;
1.558 albertel 10393: var srchin;
1.570 raeburn 10394: for (var i=0; i<callingForm.srchin.length; i++) {
10395: if ( callingForm.srchin[i].checked ) {
10396: srchin = callingForm.srchin[i].value;
1.558 albertel 10397: }
10398: }
10399:
1.570 raeburn 10400: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10401: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10402: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10403: var srchterm = callingForm.srchterm.value;
10404: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10405: var msg = "";
10406:
10407: if (srchterm == "") {
10408: checkok = 0;
1.1222 damieng 10409: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10410: }
10411:
1.569 raeburn 10412: if (srchtype== 'begins') {
10413: if (srchterm.length < 2) {
10414: checkok = 0;
1.1222 damieng 10415: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10416: }
10417: }
10418:
1.556 raeburn 10419: if (srchtype== 'contains') {
10420: if (srchterm.length < 3) {
10421: checkok = 0;
1.1222 damieng 10422: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10423: }
10424: }
10425: if (srchin == 'instd') {
10426: if (srchdomain == '') {
10427: checkok = 0;
1.1222 damieng 10428: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10429: }
10430: }
10431: if (srchin == 'dom') {
10432: if (srchdomain == '') {
10433: checkok = 0;
1.1222 damieng 10434: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10435: }
10436: }
10437: if (srchby == 'lastfirst') {
10438: if (srchterm.indexOf(",") == -1) {
10439: checkok = 0;
1.1222 damieng 10440: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10441: }
10442: if (srchterm.indexOf(",") == srchterm.length -1) {
10443: checkok = 0;
1.1222 damieng 10444: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10445: }
10446: }
10447: if (checkok == 0) {
1.1222 damieng 10448: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10449: return;
10450: }
10451: if (checkok == 1) {
1.570 raeburn 10452: callingForm.submit();
1.556 raeburn 10453: }
10454: }
10455:
10456: $newuserscript
10457:
1.824 bisitz 10458: // ]]>
1.556 raeburn 10459: </script>
1.558 albertel 10460:
10461: $new_user_create
10462:
1.555 raeburn 10463: END_BLOCK
1.558 albertel 10464:
1.876 raeburn 10465: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10466: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10467: $domform.
10468: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10469: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10470: $srchbysel.
10471: $srchtypesel.
10472: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10473: $srchinsel.
10474: &Apache::lonhtmlcommon::row_closure(1).
10475: &Apache::lonhtmlcommon::end_pick_box().
10476: '<br />';
1.1253 raeburn 10477: return ($output,1);
1.555 raeburn 10478: }
10479:
1.612 raeburn 10480: sub user_rule_check {
1.615 raeburn 10481: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10482: my ($response,%inst_response);
1.612 raeburn 10483: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10484: if (keys(%{$usershash}) > 1) {
10485: my (%by_username,%by_id,%userdoms);
10486: my $checkid;
10487: if (ref($checks) eq 'HASH') {
10488: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10489: $checkid = 1;
10490: }
10491: }
10492: foreach my $user (keys(%{$usershash})) {
10493: my ($uname,$udom) = split(/:/,$user);
10494: if ($checkid) {
10495: if (ref($usershash->{$user}) eq 'HASH') {
10496: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10497: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10498: $userdoms{$udom} = 1;
1.1227 raeburn 10499: if (ref($inst_results) eq 'HASH') {
10500: $inst_results->{$uname.':'.$udom} = {};
10501: }
1.1226 raeburn 10502: }
10503: }
10504: } else {
10505: $by_username{$udom}{$uname} = 1;
10506: $userdoms{$udom} = 1;
1.1227 raeburn 10507: if (ref($inst_results) eq 'HASH') {
10508: $inst_results->{$uname.':'.$udom} = {};
10509: }
1.1226 raeburn 10510: }
10511: }
10512: foreach my $udom (keys(%userdoms)) {
10513: if (!$got_rules->{$udom}) {
10514: my %domconfig = &Apache::lonnet::get_dom('configuration',
10515: ['usercreation'],$udom);
10516: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10517: foreach my $item ('username','id') {
10518: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10519: $$curr_rules{$udom}{$item} =
10520: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10521: }
10522: }
10523: }
10524: $got_rules->{$udom} = 1;
10525: }
1.612 raeburn 10526: }
1.1226 raeburn 10527: if ($checkid) {
10528: foreach my $udom (keys(%by_id)) {
10529: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10530: if ($outcome eq 'ok') {
1.1227 raeburn 10531: foreach my $id (keys(%{$by_id{$udom}})) {
10532: my $uname = $by_id{$udom}{$id};
10533: $inst_response{$uname.':'.$udom} = $outcome;
10534: }
1.1226 raeburn 10535: if (ref($results) eq 'HASH') {
10536: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10537: if (exists($inst_response{$uname.':'.$udom})) {
10538: $inst_response{$uname.':'.$udom} = $outcome;
10539: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10540: }
1.1226 raeburn 10541: }
10542: }
10543: }
1.612 raeburn 10544: }
1.615 raeburn 10545: } else {
1.1226 raeburn 10546: foreach my $udom (keys(%by_username)) {
10547: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10548: if ($outcome eq 'ok') {
1.1227 raeburn 10549: foreach my $uname (keys(%{$by_username{$udom}})) {
10550: $inst_response{$uname.':'.$udom} = $outcome;
10551: }
1.1226 raeburn 10552: if (ref($results) eq 'HASH') {
10553: foreach my $uname (keys(%{$results})) {
10554: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10555: }
10556: }
10557: }
10558: }
1.612 raeburn 10559: }
1.1226 raeburn 10560: } elsif (keys(%{$usershash}) == 1) {
10561: my $user = (keys(%{$usershash}))[0];
10562: my ($uname,$udom) = split(/:/,$user);
10563: if (($udom ne '') && ($uname ne '')) {
10564: if (ref($usershash->{$user}) eq 'HASH') {
10565: if (ref($checks) eq 'HASH') {
10566: if (defined($checks->{'username'})) {
10567: ($inst_response{$user},%{$inst_results->{$user}}) =
10568: &Apache::lonnet::get_instuser($udom,$uname);
10569: } elsif (defined($checks->{'id'})) {
10570: if ($usershash->{$user}->{'id'} ne '') {
10571: ($inst_response{$user},%{$inst_results->{$user}}) =
10572: &Apache::lonnet::get_instuser($udom,undef,
10573: $usershash->{$user}->{'id'});
10574: } else {
10575: ($inst_response{$user},%{$inst_results->{$user}}) =
10576: &Apache::lonnet::get_instuser($udom,$uname);
10577: }
1.585 raeburn 10578: }
1.1226 raeburn 10579: } else {
10580: ($inst_response{$user},%{$inst_results->{$user}}) =
10581: &Apache::lonnet::get_instuser($udom,$uname);
10582: return;
10583: }
10584: if (!$got_rules->{$udom}) {
10585: my %domconfig = &Apache::lonnet::get_dom('configuration',
10586: ['usercreation'],$udom);
10587: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10588: foreach my $item ('username','id') {
10589: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10590: $$curr_rules{$udom}{$item} =
10591: $domconfig{'usercreation'}{$item.'_rule'};
10592: }
10593: }
10594: }
10595: $got_rules->{$udom} = 1;
1.585 raeburn 10596: }
10597: }
1.1226 raeburn 10598: } else {
10599: return;
10600: }
10601: } else {
10602: return;
10603: }
10604: foreach my $user (keys(%{$usershash})) {
10605: my ($uname,$udom) = split(/:/,$user);
10606: next if (($udom eq '') || ($uname eq ''));
10607: my $id;
1.1227 raeburn 10608: if (ref($inst_results) eq 'HASH') {
10609: if (ref($inst_results->{$user}) eq 'HASH') {
10610: $id = $inst_results->{$user}->{'id'};
10611: }
10612: }
10613: if ($id eq '') {
10614: if (ref($usershash->{$user})) {
10615: $id = $usershash->{$user}->{'id'};
10616: }
1.585 raeburn 10617: }
1.612 raeburn 10618: foreach my $item (keys(%{$checks})) {
10619: if (ref($$curr_rules{$udom}) eq 'HASH') {
10620: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10621: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10622: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10623: $$curr_rules{$udom}{$item});
1.612 raeburn 10624: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10625: if ($rule_check{$rule}) {
10626: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10627: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10628: if (ref($inst_results) eq 'HASH') {
10629: if (ref($inst_results->{$user}) eq 'HASH') {
10630: if (keys(%{$inst_results->{$user}}) == 0) {
10631: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10632: } elsif ($item eq 'id') {
10633: if ($inst_results->{$user}->{'id'} eq '') {
10634: $$alerts{$item}{$udom}{$uname} = 1;
10635: }
1.615 raeburn 10636: }
1.612 raeburn 10637: }
10638: }
1.615 raeburn 10639: }
10640: last;
1.585 raeburn 10641: }
10642: }
10643: }
10644: }
10645: }
10646: }
10647: }
10648: }
1.612 raeburn 10649: return;
10650: }
10651:
10652: sub user_rule_formats {
10653: my ($domain,$domdesc,$curr_rules,$check) = @_;
10654: my %text = (
10655: 'username' => 'Usernames',
10656: 'id' => 'IDs',
10657: );
10658: my $output;
10659: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10660: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10661: if (@{$ruleorder} > 0) {
1.1102 raeburn 10662: $output = '<br />'.
10663: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10664: '<span class="LC_cusr_emph">','</span>',$domdesc).
10665: ' <ul>';
1.612 raeburn 10666: foreach my $rule (@{$ruleorder}) {
10667: if (ref($curr_rules) eq 'ARRAY') {
10668: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10669: if (ref($rules->{$rule}) eq 'HASH') {
10670: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10671: $rules->{$rule}{'desc'}.'</li>';
10672: }
10673: }
10674: }
10675: }
10676: $output .= '</ul>';
10677: }
10678: }
10679: return $output;
10680: }
10681:
10682: sub instrule_disallow_msg {
1.615 raeburn 10683: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10684: my $response;
10685: my %text = (
10686: item => 'username',
10687: items => 'usernames',
10688: match => 'matches',
10689: do => 'does',
10690: action => 'a username',
10691: one => 'one',
10692: );
10693: if ($count > 1) {
10694: $text{'item'} = 'usernames';
10695: $text{'match'} ='match';
10696: $text{'do'} = 'do';
10697: $text{'action'} = 'usernames',
10698: $text{'one'} = 'ones';
10699: }
10700: if ($checkitem eq 'id') {
10701: $text{'items'} = 'IDs';
10702: $text{'item'} = 'ID';
10703: $text{'action'} = 'an ID';
1.615 raeburn 10704: if ($count > 1) {
10705: $text{'item'} = 'IDs';
10706: $text{'action'} = 'IDs';
10707: }
1.612 raeburn 10708: }
1.674 bisitz 10709: $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 10710: if ($mode eq 'upload') {
10711: if ($checkitem eq 'username') {
10712: $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'}.");
10713: } elsif ($checkitem eq 'id') {
1.674 bisitz 10714: $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 10715: }
1.669 raeburn 10716: } elsif ($mode eq 'selfcreate') {
10717: if ($checkitem eq 'id') {
10718: $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.");
10719: }
1.615 raeburn 10720: } else {
10721: if ($checkitem eq 'username') {
10722: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10723: } elsif ($checkitem eq 'id') {
10724: $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.");
10725: }
1.612 raeburn 10726: }
10727: return $response;
1.585 raeburn 10728: }
10729:
1.624 raeburn 10730: sub personal_data_fieldtitles {
10731: my %fieldtitles = &Apache::lonlocal::texthash (
10732: id => 'Student/Employee ID',
10733: permanentemail => 'E-mail address',
10734: lastname => 'Last Name',
10735: firstname => 'First Name',
10736: middlename => 'Middle Name',
10737: generation => 'Generation',
10738: gen => 'Generation',
1.765 raeburn 10739: inststatus => 'Affiliation',
1.624 raeburn 10740: );
10741: return %fieldtitles;
10742: }
10743:
1.642 raeburn 10744: sub sorted_inst_types {
10745: my ($dom) = @_;
1.1185 raeburn 10746: my ($usertypes,$order);
10747: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10748: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10749: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10750: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10751: } else {
10752: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10753: }
1.642 raeburn 10754: my $othertitle = &mt('All users');
10755: if ($env{'request.course.id'}) {
1.668 raeburn 10756: $othertitle = &mt('Any users');
1.642 raeburn 10757: }
10758: my @types;
10759: if (ref($order) eq 'ARRAY') {
10760: @types = @{$order};
10761: }
10762: if (@types == 0) {
10763: if (ref($usertypes) eq 'HASH') {
10764: @types = sort(keys(%{$usertypes}));
10765: }
10766: }
10767: if (keys(%{$usertypes}) > 0) {
10768: $othertitle = &mt('Other users');
10769: }
10770: return ($othertitle,$usertypes,\@types);
10771: }
10772:
1.645 raeburn 10773: sub get_institutional_codes {
10774: my ($settings,$allcourses,$LC_code) = @_;
10775: # Get complete list of course sections to update
10776: my @currsections = ();
10777: my @currxlists = ();
10778: my $coursecode = $$settings{'internal.coursecode'};
10779:
10780: if ($$settings{'internal.sectionnums'} ne '') {
10781: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10782: }
10783:
10784: if ($$settings{'internal.crosslistings'} ne '') {
10785: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10786: }
10787:
10788: if (@currxlists > 0) {
10789: foreach (@currxlists) {
10790: if (m/^([^:]+):(\w*)$/) {
10791: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 10792: push(@{$allcourses},$1);
1.645 raeburn 10793: $$LC_code{$1} = $2;
10794: }
10795: }
10796: }
10797: }
10798:
10799: if (@currsections > 0) {
10800: foreach (@currsections) {
10801: if (m/^(\w+):(\w*)$/) {
10802: my $sec = $coursecode.$1;
10803: my $lc_sec = $2;
10804: unless (grep/^$sec$/,@{$allcourses}) {
1.1263 raeburn 10805: push(@{$allcourses},$sec);
1.645 raeburn 10806: $$LC_code{$sec} = $lc_sec;
10807: }
10808: }
10809: }
10810: }
10811: return;
10812: }
10813:
1.971 raeburn 10814: sub get_standard_codeitems {
10815: return ('Year','Semester','Department','Number','Section');
10816: }
10817:
1.112 bowersj2 10818: =pod
10819:
1.780 raeburn 10820: =head1 Slot Helpers
10821:
10822: =over 4
10823:
10824: =item * sorted_slots()
10825:
1.1040 raeburn 10826: Sorts an array of slot names in order of an optional sort key,
10827: default sort is by slot start time (earliest first).
1.780 raeburn 10828:
10829: Inputs:
10830:
10831: =over 4
10832:
10833: slotsarr - Reference to array of unsorted slot names.
10834:
10835: slots - Reference to hash of hash, where outer hash keys are slot names.
10836:
1.1040 raeburn 10837: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10838:
1.549 albertel 10839: =back
10840:
1.780 raeburn 10841: Returns:
10842:
10843: =over 4
10844:
1.1040 raeburn 10845: sorted - An array of slot names sorted by a specified sort key
10846: (default sort key is start time of the slot).
1.780 raeburn 10847:
10848: =back
10849:
10850: =cut
10851:
10852:
10853: sub sorted_slots {
1.1040 raeburn 10854: my ($slotsarr,$slots,$sortkey) = @_;
10855: if ($sortkey eq '') {
10856: $sortkey = 'starttime';
10857: }
1.780 raeburn 10858: my @sorted;
10859: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10860: @sorted =
10861: sort {
10862: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10863: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10864: }
10865: if (ref($slots->{$a})) { return -1;}
10866: if (ref($slots->{$b})) { return 1;}
10867: return 0;
10868: } @{$slotsarr};
10869: }
10870: return @sorted;
10871: }
10872:
1.1040 raeburn 10873: =pod
10874:
10875: =item * get_future_slots()
10876:
10877: Inputs:
10878:
10879: =over 4
10880:
10881: cnum - course number
10882:
10883: cdom - course domain
10884:
10885: now - current UNIX time
10886:
10887: symb - optional symb
10888:
10889: =back
10890:
10891: Returns:
10892:
10893: =over 4
10894:
10895: sorted_reservable - ref to array of student_schedulable slots currently
10896: reservable, ordered by end date of reservation period.
10897:
10898: reservable_now - ref to hash of student_schedulable slots currently
10899: reservable.
10900:
10901: Keys in inner hash are:
10902: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10903: (b) endreserve: end date of reservation period.
10904: (c) uniqueperiod: start,end dates when slot is to be uniquely
10905: selected.
1.1040 raeburn 10906:
10907: sorted_future - ref to array of student_schedulable slots reservable in
10908: the future, ordered by start date of reservation period.
10909:
10910: future_reservable - ref to hash of student_schedulable slots reservable
10911: in the future.
10912:
10913: Keys in inner hash are:
10914: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10915: (b) startreserve: start date of reservation period.
10916: (c) uniqueperiod: start,end dates when slot is to be uniquely
10917: selected.
1.1040 raeburn 10918:
10919: =back
10920:
10921: =cut
10922:
10923: sub get_future_slots {
10924: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 10925: my $map;
10926: if ($symb) {
10927: ($map) = &Apache::lonnet::decode_symb($symb);
10928: }
1.1040 raeburn 10929: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10930: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10931: foreach my $slot (keys(%slots)) {
10932: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10933: if ($symb) {
1.1229 raeburn 10934: if ($slots{$slot}->{'symb'} ne '') {
10935: my $canuse;
10936: my %oksymbs;
10937: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
10938: map { $oksymbs{$_} = 1; } @slotsymbs;
10939: if ($oksymbs{$symb}) {
10940: $canuse = 1;
10941: } else {
10942: foreach my $item (@slotsymbs) {
10943: if ($item =~ /\.(page|sequence)$/) {
10944: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
10945: if (($map ne '') && ($map eq $sloturl)) {
10946: $canuse = 1;
10947: last;
10948: }
10949: }
10950: }
10951: }
10952: next unless ($canuse);
10953: }
1.1040 raeburn 10954: }
10955: if (($slots{$slot}->{'starttime'} > $now) &&
10956: ($slots{$slot}->{'endtime'} > $now)) {
10957: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10958: my $userallowed = 0;
10959: if ($slots{$slot}->{'allowedsections'}) {
10960: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10961: if (!defined($env{'request.role.sec'})
10962: && grep(/^No section assigned$/,@allowed_sec)) {
10963: $userallowed=1;
10964: } else {
10965: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10966: $userallowed=1;
10967: }
10968: }
10969: unless ($userallowed) {
10970: if (defined($env{'request.course.groups'})) {
10971: my @groups = split(/:/,$env{'request.course.groups'});
10972: foreach my $group (@groups) {
10973: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10974: $userallowed=1;
10975: last;
10976: }
10977: }
10978: }
10979: }
10980: }
10981: if ($slots{$slot}->{'allowedusers'}) {
10982: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10983: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10984: if (grep(/^\Q$user\E$/,@allowed_users)) {
10985: $userallowed = 1;
10986: }
10987: }
10988: next unless($userallowed);
10989: }
10990: my $startreserve = $slots{$slot}->{'startreserve'};
10991: my $endreserve = $slots{$slot}->{'endreserve'};
10992: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 10993: my $uniqueperiod;
10994: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10995: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10996: }
1.1040 raeburn 10997: if (($startreserve < $now) &&
10998: (!$endreserve || $endreserve > $now)) {
10999: my $lastres = $endreserve;
11000: if (!$lastres) {
11001: $lastres = $slots{$slot}->{'starttime'};
11002: }
11003: $reservable_now{$slot} = {
11004: symb => $symb,
1.1250 raeburn 11005: endreserve => $lastres,
11006: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11007: };
11008: } elsif (($startreserve > $now) &&
11009: (!$endreserve || $endreserve > $startreserve)) {
11010: $future_reservable{$slot} = {
11011: symb => $symb,
1.1250 raeburn 11012: startreserve => $startreserve,
11013: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11014: };
11015: }
11016: }
11017: }
11018: my @unsorted_reservable = keys(%reservable_now);
11019: if (@unsorted_reservable > 0) {
11020: @sorted_reservable =
11021: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11022: }
11023: my @unsorted_future = keys(%future_reservable);
11024: if (@unsorted_future > 0) {
11025: @sorted_future =
11026: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11027: }
11028: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11029: }
1.780 raeburn 11030:
11031: =pod
11032:
1.1057 foxr 11033: =back
11034:
1.549 albertel 11035: =head1 HTTP Helpers
11036:
11037: =over 4
11038:
1.648 raeburn 11039: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11040:
1.258 albertel 11041: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11042: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11043: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11044:
11045: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11046: $possible_names is an ref to an array of form element names. As an example:
11047: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11048: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11049:
11050: =cut
1.1 albertel 11051:
1.6 albertel 11052: sub get_unprocessed_cgi {
1.25 albertel 11053: my ($query,$possible_names)= @_;
1.26 matthew 11054: # $Apache::lonxml::debug=1;
1.356 albertel 11055: foreach my $pair (split(/&/,$query)) {
11056: my ($name, $value) = split(/=/,$pair);
1.369 www 11057: $name = &unescape($name);
1.25 albertel 11058: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11059: $value =~ tr/+/ /;
11060: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11061: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11062: }
1.16 harris41 11063: }
1.6 albertel 11064: }
11065:
1.112 bowersj2 11066: =pod
11067:
1.648 raeburn 11068: =item * &cacheheader()
1.112 bowersj2 11069:
11070: returns cache-controlling header code
11071:
11072: =cut
11073:
1.7 albertel 11074: sub cacheheader {
1.258 albertel 11075: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11076: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11077: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11078: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11079: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11080: return $output;
1.7 albertel 11081: }
11082:
1.112 bowersj2 11083: =pod
11084:
1.648 raeburn 11085: =item * &no_cache($r)
1.112 bowersj2 11086:
11087: specifies header code to not have cache
11088:
11089: =cut
11090:
1.9 albertel 11091: sub no_cache {
1.216 albertel 11092: my ($r) = @_;
11093: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11094: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11095: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11096: $r->no_cache(1);
11097: $r->header_out("Expires" => $date);
11098: $r->header_out("Pragma" => "no-cache");
1.123 www 11099: }
11100:
11101: sub content_type {
1.181 albertel 11102: my ($r,$type,$charset) = @_;
1.299 foxr 11103: if ($r) {
11104: # Note that printout.pl calls this with undef for $r.
11105: &no_cache($r);
11106: }
1.258 albertel 11107: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11108: unless ($charset) {
11109: $charset=&Apache::lonlocal::current_encoding;
11110: }
11111: if ($charset) { $type.='; charset='.$charset; }
11112: if ($r) {
11113: $r->content_type($type);
11114: } else {
11115: print("Content-type: $type\n\n");
11116: }
1.9 albertel 11117: }
1.25 albertel 11118:
1.112 bowersj2 11119: =pod
11120:
1.648 raeburn 11121: =item * &add_to_env($name,$value)
1.112 bowersj2 11122:
1.258 albertel 11123: adds $name to the %env hash with value
1.112 bowersj2 11124: $value, if $name already exists, the entry is converted to an array
11125: reference and $value is added to the array.
11126:
11127: =cut
11128:
1.25 albertel 11129: sub add_to_env {
11130: my ($name,$value)=@_;
1.258 albertel 11131: if (defined($env{$name})) {
11132: if (ref($env{$name})) {
1.25 albertel 11133: #already have multiple values
1.258 albertel 11134: push(@{ $env{$name} },$value);
1.25 albertel 11135: } else {
11136: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11137: my $first=$env{$name};
11138: undef($env{$name});
11139: push(@{ $env{$name} },$first,$value);
1.25 albertel 11140: }
11141: } else {
1.258 albertel 11142: $env{$name}=$value;
1.25 albertel 11143: }
1.31 albertel 11144: }
1.149 albertel 11145:
11146: =pod
11147:
1.648 raeburn 11148: =item * &get_env_multiple($name)
1.149 albertel 11149:
1.258 albertel 11150: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11151: values may be defined and end up as an array ref.
11152:
11153: returns an array of values
11154:
11155: =cut
11156:
11157: sub get_env_multiple {
11158: my ($name) = @_;
11159: my @values;
1.258 albertel 11160: if (defined($env{$name})) {
1.149 albertel 11161: # exists is it an array
1.258 albertel 11162: if (ref($env{$name})) {
11163: @values=@{ $env{$name} };
1.149 albertel 11164: } else {
1.258 albertel 11165: $values[0]=$env{$name};
1.149 albertel 11166: }
11167: }
11168: return(@values);
11169: }
11170:
1.1249 damieng 11171: # Looks at given dependencies, and returns something depending on the context.
11172: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11173: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11174: # For all other contexts, returns ($output, $counter, $numpathchg).
11175: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11176: # $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.
11177: # $numpathchg: integer with the number of cleaned up dependency paths.
11178: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11179: # \%mapping: hash reference clean path -> original path for all dependencies.
11180: # @param {string} actionurl - The path to the handler, indicative of the context.
11181: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11182: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11183: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11184: # @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)
11185: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11186: sub ask_for_embedded_content {
1.1249 damieng 11187: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11188: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11189: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11190: %currsubfile,%unused,$rem);
1.1071 raeburn 11191: my $counter = 0;
11192: my $numnew = 0;
1.987 raeburn 11193: my $numremref = 0;
11194: my $numinvalid = 0;
11195: my $numpathchg = 0;
11196: my $numexisting = 0;
1.1071 raeburn 11197: my $numunused = 0;
11198: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11199: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11200: my $heading = &mt('Upload embedded files');
11201: my $buttontext = &mt('Upload');
11202:
1.1249 damieng 11203: # fills these variables based on the context:
11204: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11205: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11206: if ($env{'request.course.id'}) {
1.1123 raeburn 11207: if ($actionurl eq '/adm/dependencies') {
11208: $navmap = Apache::lonnavmaps::navmap->new();
11209: }
11210: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11211: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11212: }
1.1123 raeburn 11213: if (($actionurl eq '/adm/portfolio') ||
11214: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11215: my $current_path='/';
11216: if ($env{'form.currentpath'}) {
11217: $current_path = $env{'form.currentpath'};
11218: }
11219: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11220: $udom = $cdom;
11221: $uname = $cnum;
1.984 raeburn 11222: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11223: } else {
11224: $udom = $env{'user.domain'};
11225: $uname = $env{'user.name'};
11226: $url = '/userfiles/portfolio';
11227: }
1.987 raeburn 11228: $toplevel = $url.'/';
1.984 raeburn 11229: $url .= $current_path;
11230: $getpropath = 1;
1.987 raeburn 11231: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11232: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11233: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11234: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11235: $toplevel = $url;
1.984 raeburn 11236: if ($rest ne '') {
1.987 raeburn 11237: $url .= $rest;
11238: }
11239: } elsif ($actionurl eq '/adm/coursedocs') {
11240: if (ref($args) eq 'HASH') {
1.1071 raeburn 11241: $url = $args->{'docs_url'};
11242: $toplevel = $url;
1.1084 raeburn 11243: if ($args->{'context'} eq 'paste') {
11244: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11245: ($path) =
11246: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11247: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11248: $fileloc =~ s{^/}{};
11249: }
1.1071 raeburn 11250: }
1.1084 raeburn 11251: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11252: if ($env{'request.course.id'} ne '') {
11253: if (ref($args) eq 'HASH') {
11254: $url = $args->{'docs_url'};
11255: $title = $args->{'docs_title'};
1.1126 raeburn 11256: $toplevel = $url;
11257: unless ($toplevel =~ m{^/}) {
11258: $toplevel = "/$url";
11259: }
1.1085 raeburn 11260: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11261: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11262: $path = $1;
11263: } else {
11264: ($path) =
11265: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11266: }
1.1195 raeburn 11267: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11268: $fileloc = $toplevel;
11269: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11270: my ($udom,$uname,$fname) =
11271: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11272: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11273: } else {
11274: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11275: }
1.1071 raeburn 11276: $fileloc =~ s{^/}{};
11277: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11278: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11279: }
1.987 raeburn 11280: }
1.1123 raeburn 11281: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11282: $udom = $cdom;
11283: $uname = $cnum;
11284: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11285: $toplevel = $url;
11286: $path = $url;
11287: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11288: $fileloc =~ s{^/}{};
1.987 raeburn 11289: }
1.1249 damieng 11290:
11291: # parses the dependency paths to get some info
11292: # fills $newfiles, $mapping, $subdependencies, $dependencies
11293: # $newfiles: hash URL -> 1 for new files or external URLs
11294: # (will be completed later)
11295: # $mapping:
11296: # for external URLs: external URL -> external URL
11297: # for relative paths: clean path -> original path
11298: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11299: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11300: foreach my $file (keys(%{$allfiles})) {
11301: my $embed_file;
11302: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11303: $embed_file = $1;
11304: } else {
11305: $embed_file = $file;
11306: }
1.1158 raeburn 11307: my ($absolutepath,$cleaned_file);
11308: if ($embed_file =~ m{^\w+://}) {
11309: $cleaned_file = $embed_file;
1.1147 raeburn 11310: $newfiles{$cleaned_file} = 1;
11311: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11312: } else {
1.1158 raeburn 11313: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11314: if ($embed_file =~ m{^/}) {
11315: $absolutepath = $embed_file;
11316: }
1.1147 raeburn 11317: if ($cleaned_file =~ m{/}) {
11318: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11319: $path = &check_for_traversal($path,$url,$toplevel);
11320: my $item = $fname;
11321: if ($path ne '') {
11322: $item = $path.'/'.$fname;
11323: $subdependencies{$path}{$fname} = 1;
11324: } else {
11325: $dependencies{$item} = 1;
11326: }
11327: if ($absolutepath) {
11328: $mapping{$item} = $absolutepath;
11329: } else {
11330: $mapping{$item} = $embed_file;
11331: }
11332: } else {
11333: $dependencies{$embed_file} = 1;
11334: if ($absolutepath) {
1.1147 raeburn 11335: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11336: } else {
1.1147 raeburn 11337: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11338: }
11339: }
1.984 raeburn 11340: }
11341: }
1.1249 damieng 11342:
11343: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11344: # and lists
11345: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11346: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11347: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11348: # the path had to be cleaned up
11349: # $existing: hash clean path -> 1 if the file exists
11350: # $numexisting: number of keys in $existing
11351: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11352: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11353: # dependency subdirectories that are
11354: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11355: my $dirptr = 16384;
1.984 raeburn 11356: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11357: $currsubfile{$path} = {};
1.1123 raeburn 11358: if (($actionurl eq '/adm/portfolio') ||
11359: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11360: my ($sublistref,$listerror) =
11361: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11362: if (ref($sublistref) eq 'ARRAY') {
11363: foreach my $line (@{$sublistref}) {
11364: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11365: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11366: }
1.984 raeburn 11367: }
1.987 raeburn 11368: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11369: if (opendir(my $dir,$url.'/'.$path)) {
11370: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11371: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11372: }
1.1084 raeburn 11373: } elsif (($actionurl eq '/adm/dependencies') ||
11374: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11375: ($args->{'context'} eq 'paste')) ||
11376: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11377: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11378: my $dir;
11379: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11380: $dir = $fileloc;
11381: } else {
11382: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11383: }
1.1071 raeburn 11384: if ($dir ne '') {
11385: my ($sublistref,$listerror) =
11386: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11387: if (ref($sublistref) eq 'ARRAY') {
11388: foreach my $line (@{$sublistref}) {
11389: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11390: undef,$mtime)=split(/\&/,$line,12);
11391: unless (($testdir&$dirptr) ||
11392: ($file_name =~ /^\.\.?$/)) {
11393: $currsubfile{$path}{$file_name} = [$size,$mtime];
11394: }
11395: }
11396: }
11397: }
1.984 raeburn 11398: }
11399: }
11400: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11401: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11402: my $item = $path.'/'.$file;
11403: unless ($mapping{$item} eq $item) {
11404: $pathchanges{$item} = 1;
11405: }
11406: $existing{$item} = 1;
11407: $numexisting ++;
11408: } else {
11409: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11410: }
11411: }
1.1071 raeburn 11412: if ($actionurl eq '/adm/dependencies') {
11413: foreach my $path (keys(%currsubfile)) {
11414: if (ref($currsubfile{$path}) eq 'HASH') {
11415: foreach my $file (keys(%{$currsubfile{$path}})) {
11416: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11417: next if (($rem ne '') &&
11418: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11419: (ref($navmap) &&
11420: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11421: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11422: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11423: $unused{$path.'/'.$file} = 1;
11424: }
11425: }
11426: }
11427: }
11428: }
1.984 raeburn 11429: }
1.1249 damieng 11430:
11431: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11432: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11433: my %currfile;
1.1123 raeburn 11434: if (($actionurl eq '/adm/portfolio') ||
11435: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11436: my ($dirlistref,$listerror) =
11437: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11438: if (ref($dirlistref) eq 'ARRAY') {
11439: foreach my $line (@{$dirlistref}) {
11440: my ($file_name,$rest) = split(/\&/,$line,2);
11441: $currfile{$file_name} = 1;
11442: }
1.984 raeburn 11443: }
1.987 raeburn 11444: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11445: if (opendir(my $dir,$url)) {
1.987 raeburn 11446: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11447: map {$currfile{$_} = 1;} @dir_list;
11448: }
1.1084 raeburn 11449: } elsif (($actionurl eq '/adm/dependencies') ||
11450: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11451: ($args->{'context'} eq 'paste')) ||
11452: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11453: if ($env{'request.course.id'} ne '') {
11454: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11455: if ($dir ne '') {
11456: my ($dirlistref,$listerror) =
11457: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11458: if (ref($dirlistref) eq 'ARRAY') {
11459: foreach my $line (@{$dirlistref}) {
11460: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11461: $size,undef,$mtime)=split(/\&/,$line,12);
11462: unless (($testdir&$dirptr) ||
11463: ($file_name =~ /^\.\.?$/)) {
11464: $currfile{$file_name} = [$size,$mtime];
11465: }
11466: }
11467: }
11468: }
11469: }
1.984 raeburn 11470: }
1.1249 damieng 11471: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11472: # are not in subdirectories, using $currfile
1.984 raeburn 11473: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11474: if (exists($currfile{$file})) {
1.987 raeburn 11475: unless ($mapping{$file} eq $file) {
11476: $pathchanges{$file} = 1;
11477: }
11478: $existing{$file} = 1;
11479: $numexisting ++;
11480: } else {
1.984 raeburn 11481: $newfiles{$file} = 1;
11482: }
11483: }
1.1071 raeburn 11484: foreach my $file (keys(%currfile)) {
11485: unless (($file eq $filename) ||
11486: ($file eq $filename.'.bak') ||
11487: ($dependencies{$file})) {
1.1085 raeburn 11488: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11489: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11490: next if (($rem ne '') &&
11491: (($env{"httpref.$rem".$file} ne '') ||
11492: (ref($navmap) &&
11493: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11494: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11495: ($navmap->getResourceByUrl($rem.$1)))))));
11496: }
1.1085 raeburn 11497: }
1.1071 raeburn 11498: $unused{$file} = 1;
11499: }
11500: }
1.1249 damieng 11501:
11502: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11503: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11504: ($args->{'context'} eq 'paste')) {
11505: $counter = scalar(keys(%existing));
11506: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11507: return ($output,$counter,$numpathchg,\%existing);
11508: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11509: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11510: $counter = scalar(keys(%existing));
11511: $numpathchg = scalar(keys(%pathchanges));
11512: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11513: }
1.1249 damieng 11514:
11515: # returns HTML otherwise, with dependency results and to ask for more uploads
11516:
11517: # $upload_output: missing dependencies (with upload form)
11518: # $modify_output: uploaded dependencies (in use)
11519: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11520: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11521: if ($actionurl eq '/adm/dependencies') {
11522: next if ($embed_file =~ m{^\w+://});
11523: }
1.660 raeburn 11524: $upload_output .= &start_data_table_row().
1.1123 raeburn 11525: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11526: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11527: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11528: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11529: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11530: }
1.1123 raeburn 11531: $upload_output .= '</td>';
1.1071 raeburn 11532: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11533: $upload_output.='<td align="right">'.
11534: '<span class="LC_info LC_fontsize_medium">'.
11535: &mt("URL points to web address").'</span>';
1.987 raeburn 11536: $numremref++;
1.660 raeburn 11537: } elsif ($args->{'error_on_invalid_names'}
11538: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11539: $upload_output.='<td align="right"><span class="LC_warning">'.
11540: &mt('Invalid characters').'</span>';
1.987 raeburn 11541: $numinvalid++;
1.660 raeburn 11542: } else {
1.1123 raeburn 11543: $upload_output .= '<td>'.
11544: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11545: $embed_file,\%mapping,
1.1071 raeburn 11546: $allfiles,$codebase,'upload');
11547: $counter ++;
11548: $numnew ++;
1.987 raeburn 11549: }
11550: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11551: }
11552: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11553: if ($actionurl eq '/adm/dependencies') {
11554: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11555: $modify_output .= &start_data_table_row().
11556: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11557: '<img src="'.&icon($embed_file).'" border="0" />'.
11558: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11559: '<td>'.$size.'</td>'.
11560: '<td>'.$mtime.'</td>'.
11561: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11562: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11563: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11564: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11565: &embedded_file_element('upload_embedded',$counter,
11566: $embed_file,\%mapping,
11567: $allfiles,$codebase,'modify').
11568: '</div></td>'.
11569: &end_data_table_row()."\n";
11570: $counter ++;
11571: } else {
11572: $upload_output .= &start_data_table_row().
1.1123 raeburn 11573: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11574: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11575: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11576: &Apache::loncommon::end_data_table_row()."\n";
11577: }
11578: }
11579: my $delidx = $counter;
11580: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11581: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11582: $delete_output .= &start_data_table_row().
11583: '<td><img src="'.&icon($oldfile).'" />'.
11584: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11585: '<td>'.$size.'</td>'.
11586: '<td>'.$mtime.'</td>'.
11587: '<td><label><input type="checkbox" name="del_upload_dep" '.
11588: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11589: &embedded_file_element('upload_embedded',$delidx,
11590: $oldfile,\%mapping,$allfiles,
11591: $codebase,'delete').'</td>'.
11592: &end_data_table_row()."\n";
11593: $numunused ++;
11594: $delidx ++;
1.987 raeburn 11595: }
11596: if ($upload_output) {
11597: $upload_output = &start_data_table().
11598: $upload_output.
11599: &end_data_table()."\n";
11600: }
1.1071 raeburn 11601: if ($modify_output) {
11602: $modify_output = &start_data_table().
11603: &start_data_table_header_row().
11604: '<th>'.&mt('File').'</th>'.
11605: '<th>'.&mt('Size (KB)').'</th>'.
11606: '<th>'.&mt('Modified').'</th>'.
11607: '<th>'.&mt('Upload replacement?').'</th>'.
11608: &end_data_table_header_row().
11609: $modify_output.
11610: &end_data_table()."\n";
11611: }
11612: if ($delete_output) {
11613: $delete_output = &start_data_table().
11614: &start_data_table_header_row().
11615: '<th>'.&mt('File').'</th>'.
11616: '<th>'.&mt('Size (KB)').'</th>'.
11617: '<th>'.&mt('Modified').'</th>'.
11618: '<th>'.&mt('Delete?').'</th>'.
11619: &end_data_table_header_row().
11620: $delete_output.
11621: &end_data_table()."\n";
11622: }
1.987 raeburn 11623: my $applies = 0;
11624: if ($numremref) {
11625: $applies ++;
11626: }
11627: if ($numinvalid) {
11628: $applies ++;
11629: }
11630: if ($numexisting) {
11631: $applies ++;
11632: }
1.1071 raeburn 11633: if ($counter || $numunused) {
1.987 raeburn 11634: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11635: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11636: $state.'<h3>'.$heading.'</h3>';
11637: if ($actionurl eq '/adm/dependencies') {
11638: if ($numnew) {
11639: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11640: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11641: $upload_output.'<br />'."\n";
11642: }
11643: if ($numexisting) {
11644: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11645: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11646: $modify_output.'<br />'."\n";
11647: $buttontext = &mt('Save changes');
11648: }
11649: if ($numunused) {
11650: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11651: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11652: $delete_output.'<br />'."\n";
11653: $buttontext = &mt('Save changes');
11654: }
11655: } else {
11656: $output .= $upload_output.'<br />'."\n";
11657: }
11658: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11659: $counter.'" />'."\n";
11660: if ($actionurl eq '/adm/dependencies') {
11661: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11662: $numnew.'" />'."\n";
11663: } elsif ($actionurl eq '') {
1.987 raeburn 11664: $output .= '<input type="hidden" name="phase" value="three" />';
11665: }
11666: } elsif ($applies) {
11667: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11668: if ($applies > 1) {
11669: $output .=
1.1123 raeburn 11670: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11671: if ($numremref) {
11672: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11673: }
11674: if ($numinvalid) {
11675: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11676: }
11677: if ($numexisting) {
11678: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11679: }
11680: $output .= '</ul><br />';
11681: } elsif ($numremref) {
11682: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11683: } elsif ($numinvalid) {
11684: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11685: } elsif ($numexisting) {
11686: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11687: }
11688: $output .= $upload_output.'<br />';
11689: }
11690: my ($pathchange_output,$chgcount);
1.1071 raeburn 11691: $chgcount = $counter;
1.987 raeburn 11692: if (keys(%pathchanges) > 0) {
11693: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11694: if ($counter) {
1.987 raeburn 11695: $output .= &embedded_file_element('pathchange',$chgcount,
11696: $embed_file,\%mapping,
1.1071 raeburn 11697: $allfiles,$codebase,'change');
1.987 raeburn 11698: } else {
11699: $pathchange_output .=
11700: &start_data_table_row().
11701: '<td><input type ="checkbox" name="namechange" value="'.
11702: $chgcount.'" checked="checked" /></td>'.
11703: '<td>'.$mapping{$embed_file}.'</td>'.
11704: '<td>'.$embed_file.
11705: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11706: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11707: '</td>'.&end_data_table_row();
1.660 raeburn 11708: }
1.987 raeburn 11709: $numpathchg ++;
11710: $chgcount ++;
1.660 raeburn 11711: }
11712: }
1.1127 raeburn 11713: if (($counter) || ($numunused)) {
1.987 raeburn 11714: if ($numpathchg) {
11715: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11716: $numpathchg.'" />'."\n";
11717: }
11718: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11719: ($actionurl eq '/adm/imsimport')) {
11720: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11721: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11722: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11723: } elsif ($actionurl eq '/adm/dependencies') {
11724: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11725: }
1.1123 raeburn 11726: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11727: } elsif ($numpathchg) {
11728: my %pathchange = ();
11729: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11730: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11731: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11732: }
1.987 raeburn 11733: }
1.1071 raeburn 11734: return ($output,$counter,$numpathchg);
1.987 raeburn 11735: }
11736:
1.1147 raeburn 11737: =pod
11738:
11739: =item * clean_path($name)
11740:
11741: Performs clean-up of directories, subdirectories and filename in an
11742: embedded object, referenced in an HTML file which is being uploaded
11743: to a course or portfolio, where
11744: "Upload embedded images/multimedia files if HTML file" checkbox was
11745: checked.
11746:
11747: Clean-up is similar to replacements in lonnet::clean_filename()
11748: except each / between sub-directory and next level is preserved.
11749:
11750: =cut
11751:
11752: sub clean_path {
11753: my ($embed_file) = @_;
11754: $embed_file =~s{^/+}{};
11755: my @contents;
11756: if ($embed_file =~ m{/}) {
11757: @contents = split(/\//,$embed_file);
11758: } else {
11759: @contents = ($embed_file);
11760: }
11761: my $lastidx = scalar(@contents)-1;
11762: for (my $i=0; $i<=$lastidx; $i++) {
11763: $contents[$i]=~s{\\}{/}g;
11764: $contents[$i]=~s/\s+/\_/g;
11765: $contents[$i]=~s{[^/\w\.\-]}{}g;
11766: if ($i == $lastidx) {
11767: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11768: }
11769: }
11770: if ($lastidx > 0) {
11771: return join('/',@contents);
11772: } else {
11773: return $contents[0];
11774: }
11775: }
11776:
1.987 raeburn 11777: sub embedded_file_element {
1.1071 raeburn 11778: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11779: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11780: (ref($codebase) eq 'HASH'));
11781: my $output;
1.1071 raeburn 11782: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11783: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11784: }
11785: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11786: &escape($embed_file).'" />';
11787: unless (($context eq 'upload_embedded') &&
11788: ($mapping->{$embed_file} eq $embed_file)) {
11789: $output .='
11790: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11791: }
11792: my $attrib;
11793: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11794: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11795: }
11796: $output .=
11797: "\n\t\t".
11798: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11799: $attrib.'" />';
11800: if (exists($codebase->{$mapping->{$embed_file}})) {
11801: $output .=
11802: "\n\t\t".
11803: '<input name="codebase_'.$num.'" type="hidden" value="'.
11804: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11805: }
1.987 raeburn 11806: return $output;
1.660 raeburn 11807: }
11808:
1.1071 raeburn 11809: sub get_dependency_details {
11810: my ($currfile,$currsubfile,$embed_file) = @_;
11811: my ($size,$mtime,$showsize,$showmtime);
11812: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11813: if ($embed_file =~ m{/}) {
11814: my ($path,$fname) = split(/\//,$embed_file);
11815: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11816: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11817: }
11818: } else {
11819: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11820: ($size,$mtime) = @{$currfile->{$embed_file}};
11821: }
11822: }
11823: $showsize = $size/1024.0;
11824: $showsize = sprintf("%.1f",$showsize);
11825: if ($mtime > 0) {
11826: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11827: }
11828: }
11829: return ($showsize,$showmtime);
11830: }
11831:
11832: sub ask_embedded_js {
11833: return <<"END";
11834: <script type="text/javascript"">
11835: // <![CDATA[
11836: function toggleBrowse(counter) {
11837: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11838: var fileid = document.getElementById('embedded_item_'+counter);
11839: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11840: if (chkboxid.checked == true) {
11841: uploaddivid.style.display='block';
11842: } else {
11843: uploaddivid.style.display='none';
11844: fileid.value = '';
11845: }
11846: }
11847: // ]]>
11848: </script>
11849:
11850: END
11851: }
11852:
1.661 raeburn 11853: sub upload_embedded {
11854: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11855: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11856: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11857: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11858: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11859: my $orig_uploaded_filename =
11860: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11861: foreach my $type ('orig','ref','attrib','codebase') {
11862: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11863: $env{'form.embedded_'.$type.'_'.$i} =
11864: &unescape($env{'form.embedded_'.$type.'_'.$i});
11865: }
11866: }
1.661 raeburn 11867: my ($path,$fname) =
11868: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11869: # no path, whole string is fname
11870: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11871: $fname = &Apache::lonnet::clean_filename($fname);
11872: # See if there is anything left
11873: next if ($fname eq '');
11874:
11875: # Check if file already exists as a file or directory.
11876: my ($state,$msg);
11877: if ($context eq 'portfolio') {
11878: my $port_path = $dirpath;
11879: if ($group ne '') {
11880: $port_path = "groups/$group/$port_path";
11881: }
1.987 raeburn 11882: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11883: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11884: $dir_root,$port_path,$disk_quota,
11885: $current_disk_usage,$uname,$udom);
11886: if ($state eq 'will_exceed_quota'
1.984 raeburn 11887: || $state eq 'file_locked') {
1.661 raeburn 11888: $output .= $msg;
11889: next;
11890: }
11891: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11892: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11893: if ($state eq 'exists') {
11894: $output .= $msg;
11895: next;
11896: }
11897: }
11898: # Check if extension is valid
11899: if (($fname =~ /\.(\w+)$/) &&
11900: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 11901: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11902: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11903: next;
11904: } elsif (($fname =~ /\.(\w+)$/) &&
11905: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11906: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11907: next;
11908: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 11909: $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 11910: next;
11911: }
11912: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 11913: my $subdir = $path;
11914: $subdir =~ s{/+$}{};
1.661 raeburn 11915: if ($context eq 'portfolio') {
1.984 raeburn 11916: my $result;
11917: if ($state eq 'existingfile') {
11918: $result=
11919: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 11920: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11921: } else {
1.984 raeburn 11922: $result=
11923: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11924: $dirpath.
1.1123 raeburn 11925: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11926: if ($result !~ m|^/uploaded/|) {
11927: $output .= '<span class="LC_error">'
11928: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11929: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11930: .'</span><br />';
11931: next;
11932: } else {
1.987 raeburn 11933: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11934: $path.$fname.'</span>').'<br />';
1.984 raeburn 11935: }
1.661 raeburn 11936: }
1.1123 raeburn 11937: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 11938: my $extendedsubdir = $dirpath.'/'.$subdir;
11939: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11940: my $result =
1.1126 raeburn 11941: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11942: if ($result !~ m|^/uploaded/|) {
11943: $output .= '<span class="LC_error">'
11944: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11945: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11946: .'</span><br />';
11947: next;
11948: } else {
11949: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11950: $path.$fname.'</span>').'<br />';
1.1125 raeburn 11951: if ($context eq 'syllabus') {
11952: &Apache::lonnet::make_public_indefinitely($result);
11953: }
1.987 raeburn 11954: }
1.661 raeburn 11955: } else {
11956: # Save the file
11957: my $target = $env{'form.embedded_item_'.$i};
11958: my $fullpath = $dir_root.$dirpath.'/'.$path;
11959: my $dest = $fullpath.$fname;
11960: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11961: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11962: my $count;
11963: my $filepath = $dir_root;
1.1027 raeburn 11964: foreach my $subdir (@parts) {
11965: $filepath .= "/$subdir";
11966: if (!-e $filepath) {
1.661 raeburn 11967: mkdir($filepath,0770);
11968: }
11969: }
11970: my $fh;
11971: if (!open($fh,'>'.$dest)) {
11972: &Apache::lonnet::logthis('Failed to create '.$dest);
11973: $output .= '<span class="LC_error">'.
1.1071 raeburn 11974: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11975: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11976: '</span><br />';
11977: } else {
11978: if (!print $fh $env{'form.embedded_item_'.$i}) {
11979: &Apache::lonnet::logthis('Failed to write to '.$dest);
11980: $output .= '<span class="LC_error">'.
1.1071 raeburn 11981: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11982: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11983: '</span><br />';
11984: } else {
1.987 raeburn 11985: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11986: $url.'</span>').'<br />';
11987: unless ($context eq 'testbank') {
11988: $footer .= &mt('View embedded file: [_1]',
11989: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11990: }
11991: }
11992: close($fh);
11993: }
11994: }
11995: if ($env{'form.embedded_ref_'.$i}) {
11996: $pathchange{$i} = 1;
11997: }
11998: }
11999: if ($output) {
12000: $output = '<p>'.$output.'</p>';
12001: }
12002: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12003: $returnflag = 'ok';
1.1071 raeburn 12004: my $numpathchgs = scalar(keys(%pathchange));
12005: if ($numpathchgs > 0) {
1.987 raeburn 12006: if ($context eq 'portfolio') {
12007: $output .= '<p>'.&mt('or').'</p>';
12008: } elsif ($context eq 'testbank') {
1.1071 raeburn 12009: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12010: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12011: $returnflag = 'modify_orightml';
12012: }
12013: }
1.1071 raeburn 12014: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12015: }
12016:
12017: sub modify_html_form {
12018: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12019: my $end = 0;
12020: my $modifyform;
12021: if ($context eq 'upload_embedded') {
12022: return unless (ref($pathchange) eq 'HASH');
12023: if ($env{'form.number_embedded_items'}) {
12024: $end += $env{'form.number_embedded_items'};
12025: }
12026: if ($env{'form.number_pathchange_items'}) {
12027: $end += $env{'form.number_pathchange_items'};
12028: }
12029: if ($end) {
12030: for (my $i=0; $i<$end; $i++) {
12031: if ($i < $env{'form.number_embedded_items'}) {
12032: next unless($pathchange->{$i});
12033: }
12034: $modifyform .=
12035: &start_data_table_row().
12036: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12037: 'checked="checked" /></td>'.
12038: '<td>'.$env{'form.embedded_ref_'.$i}.
12039: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12040: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12041: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12042: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12043: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12044: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12045: '<td>'.$env{'form.embedded_orig_'.$i}.
12046: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12047: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12048: &end_data_table_row();
1.1071 raeburn 12049: }
1.987 raeburn 12050: }
12051: } else {
12052: $modifyform = $pathchgtable;
12053: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12054: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12055: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12056: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12057: }
12058: }
12059: if ($modifyform) {
1.1071 raeburn 12060: if ($actionurl eq '/adm/dependencies') {
12061: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12062: }
1.987 raeburn 12063: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12064: '<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".
12065: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12066: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12067: '</ol></p>'."\n".'<p>'.
12068: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12069: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12070: &start_data_table()."\n".
12071: &start_data_table_header_row().
12072: '<th>'.&mt('Change?').'</th>'.
12073: '<th>'.&mt('Current reference').'</th>'.
12074: '<th>'.&mt('Required reference').'</th>'.
12075: &end_data_table_header_row()."\n".
12076: $modifyform.
12077: &end_data_table().'<br />'."\n".$hiddenstate.
12078: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12079: '</form>'."\n";
12080: }
12081: return;
12082: }
12083:
12084: sub modify_html_refs {
1.1123 raeburn 12085: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12086: my $container;
12087: if ($context eq 'portfolio') {
12088: $container = $env{'form.container'};
12089: } elsif ($context eq 'coursedoc') {
12090: $container = $env{'form.primaryurl'};
1.1071 raeburn 12091: } elsif ($context eq 'manage_dependencies') {
12092: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12093: $container = "/$container";
1.1123 raeburn 12094: } elsif ($context eq 'syllabus') {
12095: $container = $url;
1.987 raeburn 12096: } else {
1.1027 raeburn 12097: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12098: }
12099: my (%allfiles,%codebase,$output,$content);
12100: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 12101: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12102: if (wantarray) {
12103: return ('',0,0);
12104: } else {
12105: return;
12106: }
12107: }
12108: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12109: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12110: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12111: if (wantarray) {
12112: return ('',0,0);
12113: } else {
12114: return;
12115: }
12116: }
1.987 raeburn 12117: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12118: if ($content eq '-1') {
12119: if (wantarray) {
12120: return ('',0,0);
12121: } else {
12122: return;
12123: }
12124: }
1.987 raeburn 12125: } else {
1.1071 raeburn 12126: unless ($container =~ /^\Q$dir_root\E/) {
12127: if (wantarray) {
12128: return ('',0,0);
12129: } else {
12130: return;
12131: }
12132: }
1.987 raeburn 12133: if (open(my $fh,"<$container")) {
12134: $content = join('', <$fh>);
12135: close($fh);
12136: } else {
1.1071 raeburn 12137: if (wantarray) {
12138: return ('',0,0);
12139: } else {
12140: return;
12141: }
1.987 raeburn 12142: }
12143: }
12144: my ($count,$codebasecount) = (0,0);
12145: my $mm = new File::MMagic;
12146: my $mime_type = $mm->checktype_contents($content);
12147: if ($mime_type eq 'text/html') {
12148: my $parse_result =
12149: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12150: \%codebase,\$content);
12151: if ($parse_result eq 'ok') {
12152: foreach my $i (@changes) {
12153: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12154: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12155: if ($allfiles{$ref}) {
12156: my $newname = $orig;
12157: my ($attrib_regexp,$codebase);
1.1006 raeburn 12158: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12159: if ($attrib_regexp =~ /:/) {
12160: $attrib_regexp =~ s/\:/|/g;
12161: }
12162: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12163: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12164: $count += $numchg;
1.1123 raeburn 12165: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12166: delete($allfiles{$ref});
1.987 raeburn 12167: }
12168: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12169: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12170: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12171: $codebasecount ++;
12172: }
12173: }
12174: }
1.1123 raeburn 12175: my $skiprewrites;
1.987 raeburn 12176: if ($count || $codebasecount) {
12177: my $saveresult;
1.1071 raeburn 12178: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12179: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12180: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12181: if ($url eq $container) {
12182: my ($fname) = ($container =~ m{/([^/]+)$});
12183: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12184: $count,'<span class="LC_filename">'.
1.1071 raeburn 12185: $fname.'</span>').'</p>';
1.987 raeburn 12186: } else {
12187: $output = '<p class="LC_error">'.
12188: &mt('Error: update failed for: [_1].',
12189: '<span class="LC_filename">'.
12190: $container.'</span>').'</p>';
12191: }
1.1123 raeburn 12192: if ($context eq 'syllabus') {
12193: unless ($saveresult eq 'ok') {
12194: $skiprewrites = 1;
12195: }
12196: }
1.987 raeburn 12197: } else {
12198: if (open(my $fh,">$container")) {
12199: print $fh $content;
12200: close($fh);
12201: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12202: $count,'<span class="LC_filename">'.
12203: $container.'</span>').'</p>';
1.661 raeburn 12204: } else {
1.987 raeburn 12205: $output = '<p class="LC_error">'.
12206: &mt('Error: could not update [_1].',
12207: '<span class="LC_filename">'.
12208: $container.'</span>').'</p>';
1.661 raeburn 12209: }
12210: }
12211: }
1.1123 raeburn 12212: if (($context eq 'syllabus') && (!$skiprewrites)) {
12213: my ($actionurl,$state);
12214: $actionurl = "/public/$udom/$uname/syllabus";
12215: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12216: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12217: \%codebase,
12218: {'context' => 'rewrites',
12219: 'ignore_remote_references' => 1,});
12220: if (ref($mapping) eq 'HASH') {
12221: my $rewrites = 0;
12222: foreach my $key (keys(%{$mapping})) {
12223: next if ($key =~ m{^https?://});
12224: my $ref = $mapping->{$key};
12225: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12226: my $attrib;
12227: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12228: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12229: }
12230: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12231: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12232: $rewrites += $numchg;
12233: }
12234: }
12235: if ($rewrites) {
12236: my $saveresult;
12237: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12238: if ($url eq $container) {
12239: my ($fname) = ($container =~ m{/([^/]+)$});
12240: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12241: $count,'<span class="LC_filename">'.
12242: $fname.'</span>').'</p>';
12243: } else {
12244: $output .= '<p class="LC_error">'.
12245: &mt('Error: could not update links in [_1].',
12246: '<span class="LC_filename">'.
12247: $container.'</span>').'</p>';
12248:
12249: }
12250: }
12251: }
12252: }
1.987 raeburn 12253: } else {
12254: &logthis('Failed to parse '.$container.
12255: ' to modify references: '.$parse_result);
1.661 raeburn 12256: }
12257: }
1.1071 raeburn 12258: if (wantarray) {
12259: return ($output,$count,$codebasecount);
12260: } else {
12261: return $output;
12262: }
1.661 raeburn 12263: }
12264:
12265: sub check_for_existing {
12266: my ($path,$fname,$element) = @_;
12267: my ($state,$msg);
12268: if (-d $path.'/'.$fname) {
12269: $state = 'exists';
12270: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12271: } elsif (-e $path.'/'.$fname) {
12272: $state = 'exists';
12273: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12274: }
12275: if ($state eq 'exists') {
12276: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12277: }
12278: return ($state,$msg);
12279: }
12280:
12281: sub check_for_upload {
12282: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12283: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12284: my $filesize = length($env{'form.'.$element});
12285: if (!$filesize) {
12286: my $msg = '<span class="LC_error">'.
12287: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12288: '<span class="LC_filename">'.$fname.'</span>',
12289: $filesize).'<br />'.
1.1007 raeburn 12290: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12291: '</span>';
12292: return ('zero_bytes',$msg);
12293: }
12294: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12295: my $getpropath = 1;
1.1021 raeburn 12296: my ($dirlistref,$listerror) =
12297: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12298: my $found_file = 0;
12299: my $locked_file = 0;
1.991 raeburn 12300: my @lockers;
12301: my $navmap;
12302: if ($env{'request.course.id'}) {
12303: $navmap = Apache::lonnavmaps::navmap->new();
12304: }
1.1021 raeburn 12305: if (ref($dirlistref) eq 'ARRAY') {
12306: foreach my $line (@{$dirlistref}) {
12307: my ($file_name,$rest)=split(/\&/,$line,2);
12308: if ($file_name eq $fname){
12309: $file_name = $path.$file_name;
12310: if ($group ne '') {
12311: $file_name = $group.$file_name;
12312: }
12313: $found_file = 1;
12314: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12315: foreach my $lock (@lockers) {
12316: if (ref($lock) eq 'ARRAY') {
12317: my ($symb,$crsid) = @{$lock};
12318: if ($crsid eq $env{'request.course.id'}) {
12319: if (ref($navmap)) {
12320: my $res = $navmap->getBySymb($symb);
12321: foreach my $part (@{$res->parts()}) {
12322: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12323: unless (($slot_status == $res->RESERVED) ||
12324: ($slot_status == $res->RESERVED_LOCATION)) {
12325: $locked_file = 1;
12326: }
1.991 raeburn 12327: }
1.1021 raeburn 12328: } else {
12329: $locked_file = 1;
1.991 raeburn 12330: }
12331: } else {
12332: $locked_file = 1;
12333: }
12334: }
1.1021 raeburn 12335: }
12336: } else {
12337: my @info = split(/\&/,$rest);
12338: my $currsize = $info[6]/1000;
12339: if ($currsize < $filesize) {
12340: my $extra = $filesize - $currsize;
12341: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12342: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12343: &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 12344: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12345: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12346: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12347: return ('will_exceed_quota',$msg);
12348: }
1.984 raeburn 12349: }
12350: }
1.661 raeburn 12351: }
12352: }
12353: }
12354: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12355: my $msg = '<p class="LC_warning">'.
12356: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12357: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12358: return ('will_exceed_quota',$msg);
12359: } elsif ($found_file) {
12360: if ($locked_file) {
1.1179 bisitz 12361: my $msg = '<p class="LC_warning">';
1.661 raeburn 12362: $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 12363: $msg .= '</p>';
1.661 raeburn 12364: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12365: return ('file_locked',$msg);
12366: } else {
1.1179 bisitz 12367: my $msg = '<p class="LC_error">';
1.984 raeburn 12368: $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 12369: $msg .= '</p>';
1.984 raeburn 12370: return ('existingfile',$msg);
1.661 raeburn 12371: }
12372: }
12373: }
12374:
1.987 raeburn 12375: sub check_for_traversal {
12376: my ($path,$url,$toplevel) = @_;
12377: my @parts=split(/\//,$path);
12378: my $cleanpath;
12379: my $fullpath = $url;
12380: for (my $i=0;$i<@parts;$i++) {
12381: next if ($parts[$i] eq '.');
12382: if ($parts[$i] eq '..') {
12383: $fullpath =~ s{([^/]+/)$}{};
12384: } else {
12385: $fullpath .= $parts[$i].'/';
12386: }
12387: }
12388: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12389: $cleanpath = $1;
12390: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12391: my $curr_toprel = $1;
12392: my @parts = split(/\//,$curr_toprel);
12393: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12394: my @urlparts = split(/\//,$url_toprel);
12395: my $doubledots;
12396: my $startdiff = -1;
12397: for (my $i=0; $i<@urlparts; $i++) {
12398: if ($startdiff == -1) {
12399: unless ($urlparts[$i] eq $parts[$i]) {
12400: $startdiff = $i;
12401: $doubledots .= '../';
12402: }
12403: } else {
12404: $doubledots .= '../';
12405: }
12406: }
12407: if ($startdiff > -1) {
12408: $cleanpath = $doubledots;
12409: for (my $i=$startdiff; $i<@parts; $i++) {
12410: $cleanpath .= $parts[$i].'/';
12411: }
12412: }
12413: }
12414: $cleanpath =~ s{(/)$}{};
12415: return $cleanpath;
12416: }
1.31 albertel 12417:
1.1053 raeburn 12418: sub is_archive_file {
12419: my ($mimetype) = @_;
12420: if (($mimetype eq 'application/octet-stream') ||
12421: ($mimetype eq 'application/x-stuffit') ||
12422: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12423: return 1;
12424: }
12425: return;
12426: }
12427:
12428: sub decompress_form {
1.1065 raeburn 12429: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12430: my %lt = &Apache::lonlocal::texthash (
12431: this => 'This file is an archive file.',
1.1067 raeburn 12432: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12433: itsc => 'Its contents are as follows:',
1.1053 raeburn 12434: youm => 'You may wish to extract its contents.',
12435: extr => 'Extract contents',
1.1067 raeburn 12436: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12437: proa => 'Process automatically?',
1.1053 raeburn 12438: yes => 'Yes',
12439: no => 'No',
1.1067 raeburn 12440: fold => 'Title for folder containing movie',
12441: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12442: );
1.1065 raeburn 12443: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12444: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12445: my $info = &list_archive_contents($fileloc,\@paths);
12446: if (@paths) {
12447: foreach my $path (@paths) {
12448: $path =~ s{^/}{};
1.1067 raeburn 12449: if ($path =~ m{^([^/]+)/$}) {
12450: $topdir = $1;
12451: }
1.1065 raeburn 12452: if ($path =~ m{^([^/]+)/}) {
12453: $toplevel{$1} = $path;
12454: } else {
12455: $toplevel{$path} = $path;
12456: }
12457: }
12458: }
1.1067 raeburn 12459: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12460: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12461: "$topdir/media/",
12462: "$topdir/media/$topdir.mp4",
12463: "$topdir/media/FirstFrame.png",
12464: "$topdir/media/player.swf",
12465: "$topdir/media/swfobject.js",
12466: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12467: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12468: "$topdir/$topdir.mp4",
12469: "$topdir/$topdir\_config.xml",
12470: "$topdir/$topdir\_controller.swf",
12471: "$topdir/$topdir\_embed.css",
12472: "$topdir/$topdir\_First_Frame.png",
12473: "$topdir/$topdir\_player.html",
12474: "$topdir/$topdir\_Thumbnails.png",
12475: "$topdir/playerProductInstall.swf",
12476: "$topdir/scripts/",
12477: "$topdir/scripts/config_xml.js",
12478: "$topdir/scripts/handlebars.js",
12479: "$topdir/scripts/jquery-1.7.1.min.js",
12480: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12481: "$topdir/scripts/modernizr.js",
12482: "$topdir/scripts/player-min.js",
12483: "$topdir/scripts/swfobject.js",
12484: "$topdir/skins/",
12485: "$topdir/skins/configuration_express.xml",
12486: "$topdir/skins/express_show/",
12487: "$topdir/skins/express_show/player-min.css",
12488: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12489: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12490: "$topdir/$topdir.mp4",
12491: "$topdir/$topdir\_config.xml",
12492: "$topdir/$topdir\_controller.swf",
12493: "$topdir/$topdir\_embed.css",
12494: "$topdir/$topdir\_First_Frame.png",
12495: "$topdir/$topdir\_player.html",
12496: "$topdir/$topdir\_Thumbnails.png",
12497: "$topdir/playerProductInstall.swf",
12498: "$topdir/scripts/",
12499: "$topdir/scripts/config_xml.js",
12500: "$topdir/scripts/techsmith-smart-player.min.js",
12501: "$topdir/skins/",
12502: "$topdir/skins/configuration_express.xml",
12503: "$topdir/skins/express_show/",
12504: "$topdir/skins/express_show/spritesheet.min.css",
12505: "$topdir/skins/express_show/spritesheet.png",
12506: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12507: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12508: if (@diffs == 0) {
1.1164 raeburn 12509: $is_camtasia = 6;
12510: } else {
1.1197 raeburn 12511: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12512: if (@diffs == 0) {
12513: $is_camtasia = 8;
1.1197 raeburn 12514: } else {
12515: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12516: if (@diffs == 0) {
12517: $is_camtasia = 8;
12518: }
1.1164 raeburn 12519: }
1.1067 raeburn 12520: }
12521: }
12522: my $output;
12523: if ($is_camtasia) {
12524: $output = <<"ENDCAM";
12525: <script type="text/javascript" language="Javascript">
12526: // <![CDATA[
12527:
12528: function camtasiaToggle() {
12529: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12530: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12531: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12532: document.getElementById('camtasia_titles').style.display='block';
12533: } else {
12534: document.getElementById('camtasia_titles').style.display='none';
12535: }
12536: }
12537: }
12538: return;
12539: }
12540:
12541: // ]]>
12542: </script>
12543: <p>$lt{'camt'}</p>
12544: ENDCAM
1.1065 raeburn 12545: } else {
1.1067 raeburn 12546: $output = '<p>'.$lt{'this'};
12547: if ($info eq '') {
12548: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12549: } else {
12550: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12551: '<div><pre>'.$info.'</pre></div>';
12552: }
1.1065 raeburn 12553: }
1.1067 raeburn 12554: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12555: my $duplicates;
12556: my $num = 0;
12557: if (ref($dirlist) eq 'ARRAY') {
12558: foreach my $item (@{$dirlist}) {
12559: if (ref($item) eq 'ARRAY') {
12560: if (exists($toplevel{$item->[0]})) {
12561: $duplicates .=
12562: &start_data_table_row().
12563: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12564: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12565: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12566: 'value="1" />'.&mt('Yes').'</label>'.
12567: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12568: '<td>'.$item->[0].'</td>';
12569: if ($item->[2]) {
12570: $duplicates .= '<td>'.&mt('Directory').'</td>';
12571: } else {
12572: $duplicates .= '<td>'.&mt('File').'</td>';
12573: }
12574: $duplicates .= '<td>'.$item->[3].'</td>'.
12575: '<td>'.
12576: &Apache::lonlocal::locallocaltime($item->[4]).
12577: '</td>'.
12578: &end_data_table_row();
12579: $num ++;
12580: }
12581: }
12582: }
12583: }
12584: my $itemcount;
12585: if (@paths > 0) {
12586: $itemcount = scalar(@paths);
12587: } else {
12588: $itemcount = 1;
12589: }
1.1067 raeburn 12590: if ($is_camtasia) {
12591: $output .= $lt{'auto'}.'<br />'.
12592: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12593: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12594: $lt{'yes'}.'</label> <label>'.
12595: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12596: $lt{'no'}.'</label></span><br />'.
12597: '<div id="camtasia_titles" style="display:block">'.
12598: &Apache::lonhtmlcommon::start_pick_box().
12599: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12600: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12601: &Apache::lonhtmlcommon::row_closure().
12602: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12603: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12604: &Apache::lonhtmlcommon::row_closure(1).
12605: &Apache::lonhtmlcommon::end_pick_box().
12606: '</div>';
12607: }
1.1065 raeburn 12608: $output .=
12609: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12610: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12611: "\n";
1.1065 raeburn 12612: if ($duplicates ne '') {
12613: $output .= '<p><span class="LC_warning">'.
12614: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12615: &start_data_table().
12616: &start_data_table_header_row().
12617: '<th>'.&mt('Overwrite?').'</th>'.
12618: '<th>'.&mt('Name').'</th>'.
12619: '<th>'.&mt('Type').'</th>'.
12620: '<th>'.&mt('Size').'</th>'.
12621: '<th>'.&mt('Last modified').'</th>'.
12622: &end_data_table_header_row().
12623: $duplicates.
12624: &end_data_table().
12625: '</p>';
12626: }
1.1067 raeburn 12627: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12628: if (ref($hiddenelements) eq 'HASH') {
12629: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12630: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12631: }
12632: }
12633: $output .= <<"END";
1.1067 raeburn 12634: <br />
1.1053 raeburn 12635: <input type="submit" name="decompress" value="$lt{'extr'}" />
12636: </form>
12637: $noextract
12638: END
12639: return $output;
12640: }
12641:
1.1065 raeburn 12642: sub decompression_utility {
12643: my ($program) = @_;
12644: my @utilities = ('tar','gunzip','bunzip2','unzip');
12645: my $location;
12646: if (grep(/^\Q$program\E$/,@utilities)) {
12647: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12648: '/usr/sbin/') {
12649: if (-x $dir.$program) {
12650: $location = $dir.$program;
12651: last;
12652: }
12653: }
12654: }
12655: return $location;
12656: }
12657:
12658: sub list_archive_contents {
12659: my ($file,$pathsref) = @_;
12660: my (@cmd,$output);
12661: my $needsregexp;
12662: if ($file =~ /\.zip$/) {
12663: @cmd = (&decompression_utility('unzip'),"-l");
12664: $needsregexp = 1;
12665: } elsif (($file =~ m/\.tar\.gz$/) ||
12666: ($file =~ /\.tgz$/)) {
12667: @cmd = (&decompression_utility('tar'),"-ztf");
12668: } elsif ($file =~ /\.tar\.bz2$/) {
12669: @cmd = (&decompression_utility('tar'),"-jtf");
12670: } elsif ($file =~ m|\.tar$|) {
12671: @cmd = (&decompression_utility('tar'),"-tf");
12672: }
12673: if (@cmd) {
12674: undef($!);
12675: undef($@);
12676: if (open(my $fh,"-|", @cmd, $file)) {
12677: while (my $line = <$fh>) {
12678: $output .= $line;
12679: chomp($line);
12680: my $item;
12681: if ($needsregexp) {
12682: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12683: } else {
12684: $item = $line;
12685: }
12686: if ($item ne '') {
12687: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12688: push(@{$pathsref},$item);
12689: }
12690: }
12691: }
12692: close($fh);
12693: }
12694: }
12695: return $output;
12696: }
12697:
1.1053 raeburn 12698: sub decompress_uploaded_file {
12699: my ($file,$dir) = @_;
12700: &Apache::lonnet::appenv({'cgi.file' => $file});
12701: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12702: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12703: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12704: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12705: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12706: my $decompressed = $env{'cgi.decompressed'};
12707: &Apache::lonnet::delenv('cgi.file');
12708: &Apache::lonnet::delenv('cgi.dir');
12709: &Apache::lonnet::delenv('cgi.decompressed');
12710: return ($decompressed,$result);
12711: }
12712:
1.1055 raeburn 12713: sub process_decompression {
12714: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 12715: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12716: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12717: &mt('Unexpected file path.').'</p>'."\n";
12718: }
12719: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12720: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12721: &mt('Unexpected course context.').'</p>'."\n";
12722: }
1.1293 raeburn 12723: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 12724: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12725: &mt('Filename contained unexpected characters.').'</p>'."\n";
12726: }
1.1055 raeburn 12727: my ($dir,$error,$warning,$output);
1.1180 raeburn 12728: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12729: $error = &mt('Filename not a supported archive file type.').
12730: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12731: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12732: } else {
12733: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12734: if ($docuhome eq 'no_host') {
12735: $error = &mt('Could not determine home server for course.');
12736: } else {
12737: my @ids=&Apache::lonnet::current_machine_ids();
12738: my $currdir = "$dir_root/$destination";
12739: if (grep(/^\Q$docuhome\E$/,@ids)) {
12740: $dir = &LONCAPA::propath($docudom,$docuname).
12741: "$dir_root/$destination";
12742: } else {
12743: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12744: "$dir_root/$docudom/$docuname/$destination";
12745: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12746: $error = &mt('Archive file not found.');
12747: }
12748: }
1.1065 raeburn 12749: my (@to_overwrite,@to_skip);
12750: if ($env{'form.archive_overwrite_total'} > 0) {
12751: my $total = $env{'form.archive_overwrite_total'};
12752: for (my $i=0; $i<$total; $i++) {
12753: if ($env{'form.archive_overwrite_'.$i} == 1) {
12754: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12755: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12756: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12757: }
12758: }
12759: }
12760: my $numskip = scalar(@to_skip);
1.1292 raeburn 12761: my $numoverwrite = scalar(@to_overwrite);
12762: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12763: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12764: } elsif ($dir eq '') {
1.1055 raeburn 12765: $error = &mt('Directory containing archive file unavailable.');
12766: } elsif (!$error) {
1.1065 raeburn 12767: my ($decompressed,$display);
1.1292 raeburn 12768: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12769: my $tempdir = time.'_'.$$.int(rand(10000));
12770: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 12771: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12772: ($decompressed,$display) =
12773: &decompress_uploaded_file($file,"$dir/$tempdir");
12774: foreach my $item (@to_skip) {
12775: if (($item ne '') && ($item !~ /\.\./)) {
12776: if (-f "$dir/$tempdir/$item") {
12777: unlink("$dir/$tempdir/$item");
12778: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 12779: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 12780: }
12781: }
12782: }
12783: foreach my $item (@to_overwrite) {
12784: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12785: if (($item ne '') && ($item !~ /\.\./)) {
12786: if (-f "$dir/$item") {
12787: unlink("$dir/$item");
12788: } elsif (-d "$dir/$item") {
1.1300 raeburn 12789: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 12790: }
12791: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12792: }
1.1065 raeburn 12793: }
12794: }
1.1292 raeburn 12795: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 12796: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 12797: }
1.1065 raeburn 12798: }
12799: } else {
12800: ($decompressed,$display) =
12801: &decompress_uploaded_file($file,$dir);
12802: }
1.1055 raeburn 12803: if ($decompressed eq 'ok') {
1.1065 raeburn 12804: $output = '<p class="LC_info">'.
12805: &mt('Files extracted successfully from archive.').
12806: '</p>'."\n";
1.1055 raeburn 12807: my ($warning,$result,@contents);
12808: my ($newdirlistref,$newlisterror) =
12809: &Apache::lonnet::dirlist($currdir,$docudom,
12810: $docuname,1);
12811: my (%is_dir,%changes,@newitems);
12812: my $dirptr = 16384;
1.1065 raeburn 12813: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12814: foreach my $dir_line (@{$newdirlistref}) {
12815: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 12816: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12817: push(@newitems,$item);
12818: if ($dirptr&$testdir) {
12819: $is_dir{$item} = 1;
12820: }
12821: $changes{$item} = 1;
12822: }
12823: }
12824: }
12825: if (keys(%changes) > 0) {
12826: foreach my $item (sort(@newitems)) {
12827: if ($changes{$item}) {
12828: push(@contents,$item);
12829: }
12830: }
12831: }
12832: if (@contents > 0) {
1.1067 raeburn 12833: my $wantform;
12834: unless ($env{'form.autoextract_camtasia'}) {
12835: $wantform = 1;
12836: }
1.1056 raeburn 12837: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12838: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12839: $currdir,\%is_dir,
12840: \%children,\%parent,
1.1056 raeburn 12841: \@contents,\%dirorder,
12842: \%titles,$wantform);
1.1055 raeburn 12843: if ($datatable ne '') {
12844: $output .= &archive_options_form('decompressed',$datatable,
12845: $count,$hiddenelem);
1.1065 raeburn 12846: my $startcount = 6;
1.1055 raeburn 12847: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12848: \%titles,\%children);
1.1055 raeburn 12849: }
1.1067 raeburn 12850: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 12851: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12852: my %displayed;
12853: my $total = 1;
12854: $env{'form.archive_directory'} = [];
12855: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12856: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12857: $path =~ s{/$}{};
12858: my $item;
12859: if ($path ne '') {
12860: $item = "$path/$titles{$i}";
12861: } else {
12862: $item = $titles{$i};
12863: }
12864: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12865: if ($item eq $contents[0]) {
12866: push(@{$env{'form.archive_directory'}},$i);
12867: $env{'form.archive_'.$i} = 'display';
12868: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12869: $displayed{'folder'} = $i;
1.1164 raeburn 12870: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12871: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12872: $env{'form.archive_'.$i} = 'display';
12873: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12874: $displayed{'web'} = $i;
12875: } else {
1.1164 raeburn 12876: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12877: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12878: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12879: push(@{$env{'form.archive_directory'}},$i);
12880: }
12881: $env{'form.archive_'.$i} = 'dependency';
12882: }
12883: $total ++;
12884: }
12885: for (my $i=1; $i<$total; $i++) {
12886: next if ($i == $displayed{'web'});
12887: next if ($i == $displayed{'folder'});
12888: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12889: }
12890: $env{'form.phase'} = 'decompress_cleanup';
12891: $env{'form.archivedelete'} = 1;
12892: $env{'form.archive_count'} = $total-1;
12893: $output .=
12894: &process_extracted_files('coursedocs',$docudom,
12895: $docuname,$destination,
12896: $dir_root,$hiddenelem);
12897: }
1.1055 raeburn 12898: } else {
12899: $warning = &mt('No new items extracted from archive file.');
12900: }
12901: } else {
12902: $output = $display;
12903: $error = &mt('An error occurred during extraction from the archive file.');
12904: }
12905: }
12906: }
12907: }
12908: if ($error) {
12909: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12910: $error.'</p>'."\n";
12911: }
12912: if ($warning) {
12913: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12914: }
12915: return $output;
12916: }
12917:
12918: sub get_extracted {
1.1056 raeburn 12919: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12920: $titles,$wantform) = @_;
1.1055 raeburn 12921: my $count = 0;
12922: my $depth = 0;
12923: my $datatable;
1.1056 raeburn 12924: my @hierarchy;
1.1055 raeburn 12925: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12926: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12927: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12928: foreach my $item (@{$contents}) {
12929: $count ++;
1.1056 raeburn 12930: @{$dirorder->{$count}} = @hierarchy;
12931: $titles->{$count} = $item;
1.1055 raeburn 12932: &archive_hierarchy($depth,$count,$parent,$children);
12933: if ($wantform) {
12934: $datatable .= &archive_row($is_dir->{$item},$item,
12935: $currdir,$depth,$count);
12936: }
12937: if ($is_dir->{$item}) {
12938: $depth ++;
1.1056 raeburn 12939: push(@hierarchy,$count);
12940: $parent->{$depth} = $count;
1.1055 raeburn 12941: $datatable .=
12942: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12943: \$depth,\$count,\@hierarchy,$dirorder,
12944: $children,$parent,$titles,$wantform);
1.1055 raeburn 12945: $depth --;
1.1056 raeburn 12946: pop(@hierarchy);
1.1055 raeburn 12947: }
12948: }
12949: return ($count,$datatable);
12950: }
12951:
12952: sub recurse_extracted_archive {
1.1056 raeburn 12953: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12954: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12955: my $result='';
1.1056 raeburn 12956: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12957: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12958: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12959: return $result;
12960: }
12961: my $dirptr = 16384;
12962: my ($newdirlistref,$newlisterror) =
12963: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12964: if (ref($newdirlistref) eq 'ARRAY') {
12965: foreach my $dir_line (@{$newdirlistref}) {
12966: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12967: unless ($item =~ /^\.+$/) {
12968: $$count ++;
1.1056 raeburn 12969: @{$dirorder->{$$count}} = @{$hierarchy};
12970: $titles->{$$count} = $item;
1.1055 raeburn 12971: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12972:
1.1055 raeburn 12973: my $is_dir;
12974: if ($dirptr&$testdir) {
12975: $is_dir = 1;
12976: }
12977: if ($wantform) {
12978: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12979: }
12980: if ($is_dir) {
12981: $$depth ++;
1.1056 raeburn 12982: push(@{$hierarchy},$$count);
12983: $parent->{$$depth} = $$count;
1.1055 raeburn 12984: $result .=
12985: &recurse_extracted_archive("$currdir/$item",$docudom,
12986: $docuname,$depth,$count,
1.1056 raeburn 12987: $hierarchy,$dirorder,$children,
12988: $parent,$titles,$wantform);
1.1055 raeburn 12989: $$depth --;
1.1056 raeburn 12990: pop(@{$hierarchy});
1.1055 raeburn 12991: }
12992: }
12993: }
12994: }
12995: return $result;
12996: }
12997:
12998: sub archive_hierarchy {
12999: my ($depth,$count,$parent,$children) =@_;
13000: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13001: if (exists($parent->{$depth})) {
13002: $children->{$parent->{$depth}} .= $count.':';
13003: }
13004: }
13005: return;
13006: }
13007:
13008: sub archive_row {
13009: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13010: my ($name) = ($item =~ m{([^/]+)$});
13011: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13012: 'display' => 'Add as file',
1.1055 raeburn 13013: 'dependency' => 'Include as dependency',
13014: 'discard' => 'Discard',
13015: );
13016: if ($is_dir) {
1.1059 raeburn 13017: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13018: }
1.1056 raeburn 13019: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13020: my $offset = 0;
1.1055 raeburn 13021: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13022: $offset ++;
1.1065 raeburn 13023: if ($action ne 'display') {
13024: $offset ++;
13025: }
1.1055 raeburn 13026: $output .= '<td><span class="LC_nobreak">'.
13027: '<label><input type="radio" name="archive_'.$count.
13028: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13029: my $text = $choices{$action};
13030: if ($is_dir) {
13031: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13032: if ($action eq 'display') {
1.1059 raeburn 13033: $text = &mt('Add as folder');
1.1055 raeburn 13034: }
1.1056 raeburn 13035: } else {
13036: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13037:
13038: }
13039: $output .= ' /> '.$choices{$action}.'</label></span>';
13040: if ($action eq 'dependency') {
13041: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13042: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13043: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13044: '<option value=""></option>'."\n".
13045: '</select>'."\n".
13046: '</div>';
1.1059 raeburn 13047: } elsif ($action eq 'display') {
13048: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13049: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13050: '</div>';
1.1055 raeburn 13051: }
1.1056 raeburn 13052: $output .= '</td>';
1.1055 raeburn 13053: }
13054: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13055: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13056: for (my $i=0; $i<$depth; $i++) {
13057: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13058: }
13059: if ($is_dir) {
13060: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13061: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13062: } else {
13063: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13064: }
13065: $output .= ' '.$name.'</td>'."\n".
13066: &end_data_table_row();
13067: return $output;
13068: }
13069:
13070: sub archive_options_form {
1.1065 raeburn 13071: my ($form,$display,$count,$hiddenelem) = @_;
13072: my %lt = &Apache::lonlocal::texthash(
13073: perm => 'Permanently remove archive file?',
13074: hows => 'How should each extracted item be incorporated in the course?',
13075: cont => 'Content actions for all',
13076: addf => 'Add as folder/file',
13077: incd => 'Include as dependency for a displayed file',
13078: disc => 'Discard',
13079: no => 'No',
13080: yes => 'Yes',
13081: save => 'Save',
13082: );
13083: my $output = <<"END";
13084: <form name="$form" method="post" action="">
13085: <p><span class="LC_nobreak">$lt{'perm'}
13086: <label>
13087: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13088: </label>
13089:
13090: <label>
13091: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13092: </span>
13093: </p>
13094: <input type="hidden" name="phase" value="decompress_cleanup" />
13095: <br />$lt{'hows'}
13096: <div class="LC_columnSection">
13097: <fieldset>
13098: <legend>$lt{'cont'}</legend>
13099: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13100: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13101: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13102: </fieldset>
13103: </div>
13104: END
13105: return $output.
1.1055 raeburn 13106: &start_data_table()."\n".
1.1065 raeburn 13107: $display."\n".
1.1055 raeburn 13108: &end_data_table()."\n".
13109: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13110: $hiddenelem.
1.1065 raeburn 13111: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13112: '</form>';
13113: }
13114:
13115: sub archive_javascript {
1.1056 raeburn 13116: my ($startcount,$numitems,$titles,$children) = @_;
13117: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13118: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13119: my $scripttag = <<START;
13120: <script type="text/javascript">
13121: // <![CDATA[
13122:
13123: function checkAll(form,prefix) {
13124: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13125: for (var i=0; i < form.elements.length; i++) {
13126: var id = form.elements[i].id;
13127: if ((id != '') && (id != undefined)) {
13128: if (idstr.test(id)) {
13129: if (form.elements[i].type == 'radio') {
13130: form.elements[i].checked = true;
1.1056 raeburn 13131: var nostart = i-$startcount;
1.1059 raeburn 13132: var offset = nostart%7;
13133: var count = (nostart-offset)/7;
1.1056 raeburn 13134: dependencyCheck(form,count,offset);
1.1055 raeburn 13135: }
13136: }
13137: }
13138: }
13139: }
13140:
13141: function propagateCheck(form,count) {
13142: if (count > 0) {
1.1059 raeburn 13143: var startelement = $startcount + ((count-1) * 7);
13144: for (var j=1; j<6; j++) {
13145: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13146: var item = startelement + j;
13147: if (form.elements[item].type == 'radio') {
13148: if (form.elements[item].checked) {
13149: containerCheck(form,count,j);
13150: break;
13151: }
1.1055 raeburn 13152: }
13153: }
13154: }
13155: }
13156: }
13157:
13158: numitems = $numitems
1.1056 raeburn 13159: var titles = new Array(numitems);
13160: var parents = new Array(numitems);
1.1055 raeburn 13161: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13162: parents[i] = new Array;
1.1055 raeburn 13163: }
1.1059 raeburn 13164: var maintitle = '$maintitle';
1.1055 raeburn 13165:
13166: START
13167:
1.1056 raeburn 13168: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13169: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13170: for (my $i=0; $i<@contents; $i ++) {
13171: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13172: }
13173: }
13174:
1.1056 raeburn 13175: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13176: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13177: }
13178:
1.1055 raeburn 13179: $scripttag .= <<END;
13180:
13181: function containerCheck(form,count,offset) {
13182: if (count > 0) {
1.1056 raeburn 13183: dependencyCheck(form,count,offset);
1.1059 raeburn 13184: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13185: form.elements[item].checked = true;
13186: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13187: if (parents[count].length > 0) {
13188: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13189: containerCheck(form,parents[count][j],offset);
13190: }
13191: }
13192: }
13193: }
13194: }
13195:
13196: function dependencyCheck(form,count,offset) {
13197: if (count > 0) {
1.1059 raeburn 13198: var chosen = (offset+$startcount)+7*(count-1);
13199: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13200: var currtype = form.elements[depitem].type;
13201: if (form.elements[chosen].value == 'dependency') {
13202: document.getElementById('arc_depon_'+count).style.display='block';
13203: form.elements[depitem].options.length = 0;
13204: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13205: for (var i=1; i<=numitems; i++) {
13206: if (i == count) {
13207: continue;
13208: }
1.1059 raeburn 13209: var startelement = $startcount + (i-1) * 7;
13210: for (var j=1; j<6; j++) {
13211: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13212: var item = startelement + j;
13213: if (form.elements[item].type == 'radio') {
13214: if (form.elements[item].checked) {
13215: if (form.elements[item].value == 'display') {
13216: var n = form.elements[depitem].options.length;
13217: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13218: }
13219: }
13220: }
13221: }
13222: }
13223: }
13224: } else {
13225: document.getElementById('arc_depon_'+count).style.display='none';
13226: form.elements[depitem].options.length = 0;
13227: form.elements[depitem].options[0] = new Option('Select','',true,true);
13228: }
1.1059 raeburn 13229: titleCheck(form,count,offset);
1.1056 raeburn 13230: }
13231: }
13232:
13233: function propagateSelect(form,count,offset) {
13234: if (count > 0) {
1.1065 raeburn 13235: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13236: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13237: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13238: if (parents[count].length > 0) {
13239: for (var j=0; j<parents[count].length; j++) {
13240: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13241: }
13242: }
13243: }
13244: }
13245: }
1.1056 raeburn 13246:
13247: function containerSelect(form,count,offset,picked) {
13248: if (count > 0) {
1.1065 raeburn 13249: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13250: if (form.elements[item].type == 'radio') {
13251: if (form.elements[item].value == 'dependency') {
13252: if (form.elements[item+1].type == 'select-one') {
13253: for (var i=0; i<form.elements[item+1].options.length; i++) {
13254: if (form.elements[item+1].options[i].value == picked) {
13255: form.elements[item+1].selectedIndex = i;
13256: break;
13257: }
13258: }
13259: }
13260: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13261: if (parents[count].length > 0) {
13262: for (var j=0; j<parents[count].length; j++) {
13263: containerSelect(form,parents[count][j],offset,picked);
13264: }
13265: }
13266: }
13267: }
13268: }
13269: }
13270: }
13271:
1.1059 raeburn 13272: function titleCheck(form,count,offset) {
13273: if (count > 0) {
13274: var chosen = (offset+$startcount)+7*(count-1);
13275: var depitem = $startcount + ((count-1) * 7) + 2;
13276: var currtype = form.elements[depitem].type;
13277: if (form.elements[chosen].value == 'display') {
13278: document.getElementById('arc_title_'+count).style.display='block';
13279: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13280: document.getElementById('archive_title_'+count).value=maintitle;
13281: }
13282: } else {
13283: document.getElementById('arc_title_'+count).style.display='none';
13284: if (currtype == 'text') {
13285: document.getElementById('archive_title_'+count).value='';
13286: }
13287: }
13288: }
13289: return;
13290: }
13291:
1.1055 raeburn 13292: // ]]>
13293: </script>
13294: END
13295: return $scripttag;
13296: }
13297:
13298: sub process_extracted_files {
1.1067 raeburn 13299: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13300: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 13301: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13302: my @ids=&Apache::lonnet::current_machine_ids();
13303: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13304: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13305: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13306: if (grep(/^\Q$docuhome\E$/,@ids)) {
13307: $prefix = &LONCAPA::propath($docudom,$docuname);
13308: $pathtocheck = "$dir_root/$destination";
13309: $dir = $dir_root;
13310: $ishome = 1;
13311: } else {
13312: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13313: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 13314: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13315: }
13316: my $currdir = "$dir_root/$destination";
13317: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13318: if ($env{'form.folderpath'}) {
13319: my @items = split('&',$env{'form.folderpath'});
13320: $folders{'0'} = $items[-2];
1.1099 raeburn 13321: if ($env{'form.folderpath'} =~ /\:1$/) {
13322: $containers{'0'}='page';
13323: } else {
13324: $containers{'0'}='sequence';
13325: }
1.1055 raeburn 13326: }
13327: my @archdirs = &get_env_multiple('form.archive_directory');
13328: if ($numitems) {
13329: for (my $i=1; $i<=$numitems; $i++) {
13330: my $path = $env{'form.archive_content_'.$i};
13331: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13332: my $item = $1;
13333: $toplevelitems{$item} = $i;
13334: if (grep(/^\Q$i\E$/,@archdirs)) {
13335: $is_dir{$item} = 1;
13336: }
13337: }
13338: }
13339: }
1.1067 raeburn 13340: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13341: if (keys(%toplevelitems) > 0) {
13342: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13343: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13344: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13345: }
1.1066 raeburn 13346: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13347: if ($numitems) {
13348: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13349: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13350: my $path = $env{'form.archive_content_'.$i};
13351: if ($path =~ /^\Q$pathtocheck\E/) {
13352: if ($env{'form.archive_'.$i} eq 'discard') {
13353: if ($prefix ne '' && $path ne '') {
13354: if (-e $prefix.$path) {
1.1066 raeburn 13355: if ((@archdirs > 0) &&
13356: (grep(/^\Q$i\E$/,@archdirs))) {
13357: $todeletedir{$prefix.$path} = 1;
13358: } else {
13359: $todelete{$prefix.$path} = 1;
13360: }
1.1055 raeburn 13361: }
13362: }
13363: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13364: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13365: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13366: $docstitle = $env{'form.archive_title_'.$i};
13367: if ($docstitle eq '') {
13368: $docstitle = $title;
13369: }
1.1055 raeburn 13370: $outer = 0;
1.1056 raeburn 13371: if (ref($dirorder{$i}) eq 'ARRAY') {
13372: if (@{$dirorder{$i}} > 0) {
13373: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13374: if ($env{'form.archive_'.$item} eq 'display') {
13375: $outer = $item;
13376: last;
13377: }
13378: }
13379: }
13380: }
13381: my ($errtext,$fatal) =
13382: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13383: '/'.$folders{$outer}.'.'.
13384: $containers{$outer});
13385: next if ($fatal);
13386: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13387: if ($context eq 'coursedocs') {
1.1056 raeburn 13388: $mapinner{$i} = time;
1.1055 raeburn 13389: $folders{$i} = 'default_'.$mapinner{$i};
13390: $containers{$i} = 'sequence';
13391: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13392: $folders{$i}.'.'.$containers{$i};
13393: my $newidx = &LONCAPA::map::getresidx();
13394: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13395: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13396: push(@LONCAPA::map::order,$newidx);
13397: my ($outtext,$errtext) =
13398: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13399: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13400: '.'.$containers{$outer},1,1);
1.1056 raeburn 13401: $newseqid{$i} = $newidx;
1.1067 raeburn 13402: unless ($errtext) {
1.1294 raeburn 13403: $result .= '<li>'.&mt('Folder: [_1] added to course',
13404: &HTML::Entities::encode($docstitle,'<>&"')).
13405: '</li>'."\n";
1.1067 raeburn 13406: }
1.1055 raeburn 13407: }
13408: } else {
13409: if ($context eq 'coursedocs') {
13410: my $newidx=&LONCAPA::map::getresidx();
13411: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13412: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13413: $title;
1.1294 raeburn 13414: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
13415: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13416: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13417: }
13418: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13419: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13420: }
13421: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13422: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13423: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13424: unless ($ishome) {
13425: my $fetch = "$newdest{$i}/$title";
13426: $fetch =~ s/^\Q$prefix$dir\E//;
13427: $prompttofetch{$fetch} = 1;
13428: }
1.1292 raeburn 13429: }
1.1067 raeburn 13430: }
1.1294 raeburn 13431: $LONCAPA::map::resources[$newidx]=
13432: $docstitle.':'.$url.':false:normal:res';
13433: push(@LONCAPA::map::order, $newidx);
13434: my ($outtext,$errtext)=
13435: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13436: $docuname.'/'.$folders{$outer}.
13437: '.'.$containers{$outer},1,1);
13438: unless ($errtext) {
13439: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13440: $result .= '<li>'.&mt('File: [_1] added to course',
13441: &HTML::Entities::encode($docstitle,'<>&"')).
13442: '</li>'."\n";
13443: }
1.1067 raeburn 13444: }
1.1294 raeburn 13445: } else {
13446: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13447: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 13448: }
1.1055 raeburn 13449: }
13450: }
1.1086 raeburn 13451: }
13452: } else {
1.1294 raeburn 13453: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13454: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 13455: }
13456: }
13457: for (my $i=1; $i<=$numitems; $i++) {
13458: next unless ($env{'form.archive_'.$i} eq 'dependency');
13459: my $path = $env{'form.archive_content_'.$i};
13460: if ($path =~ /^\Q$pathtocheck\E/) {
13461: my ($title) = ($path =~ m{/([^/]+)$});
13462: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13463: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13464: if (ref($dirorder{$i}) eq 'ARRAY') {
13465: my ($itemidx,$fullpath,$relpath);
13466: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13467: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13468: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13469: if ($dirorder{$i}->[$j] eq $container) {
13470: $itemidx = $j;
1.1056 raeburn 13471: }
13472: }
1.1086 raeburn 13473: }
13474: if ($itemidx eq '') {
13475: $itemidx = 0;
13476: }
13477: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13478: if ($mapinner{$referrer{$i}}) {
13479: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13480: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13481: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13482: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13483: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13484: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13485: if (!-e $fullpath) {
13486: mkdir($fullpath,0755);
1.1056 raeburn 13487: }
13488: }
1.1086 raeburn 13489: } else {
13490: last;
1.1056 raeburn 13491: }
1.1086 raeburn 13492: }
13493: }
13494: } elsif ($newdest{$referrer{$i}}) {
13495: $fullpath = $newdest{$referrer{$i}};
13496: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13497: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13498: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13499: last;
13500: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13501: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13502: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13503: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13504: if (!-e $fullpath) {
13505: mkdir($fullpath,0755);
1.1056 raeburn 13506: }
13507: }
1.1086 raeburn 13508: } else {
13509: last;
1.1056 raeburn 13510: }
1.1055 raeburn 13511: }
13512: }
1.1086 raeburn 13513: if ($fullpath ne '') {
13514: if (-e "$prefix$path") {
1.1292 raeburn 13515: unless (rename("$prefix$path","$fullpath/$title")) {
13516: $warning .= &mt('Failed to rename dependency').'<br />';
13517: }
1.1086 raeburn 13518: }
13519: if (-e "$fullpath/$title") {
13520: my $showpath;
13521: if ($relpath ne '') {
13522: $showpath = "$relpath/$title";
13523: } else {
13524: $showpath = "/$title";
13525: }
1.1294 raeburn 13526: $result .= '<li>'.&mt('[_1] included as a dependency',
13527: &HTML::Entities::encode($showpath,'<>&"')).
13528: '</li>'."\n";
1.1292 raeburn 13529: unless ($ishome) {
13530: my $fetch = "$fullpath/$title";
13531: $fetch =~ s/^\Q$prefix$dir\E//;
13532: $prompttofetch{$fetch} = 1;
13533: }
1.1086 raeburn 13534: }
13535: }
1.1055 raeburn 13536: }
1.1086 raeburn 13537: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13538: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 13539: &HTML::Entities::encode($path,'<>&"'),
13540: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13541: '<br />';
1.1055 raeburn 13542: }
13543: } else {
1.1294 raeburn 13544: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 13545: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13546: }
13547: }
13548: if (keys(%todelete)) {
13549: foreach my $key (keys(%todelete)) {
13550: unlink($key);
1.1066 raeburn 13551: }
13552: }
13553: if (keys(%todeletedir)) {
13554: foreach my $key (keys(%todeletedir)) {
13555: rmdir($key);
13556: }
13557: }
13558: foreach my $dir (sort(keys(%is_dir))) {
13559: if (($pathtocheck ne '') && ($dir ne '')) {
13560: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13561: }
13562: }
1.1067 raeburn 13563: if ($result ne '') {
13564: $output .= '<ul>'."\n".
13565: $result."\n".
13566: '</ul>';
13567: }
13568: unless ($ishome) {
13569: my $replicationfail;
13570: foreach my $item (keys(%prompttofetch)) {
13571: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13572: unless ($fetchresult eq 'ok') {
13573: $replicationfail .= '<li>'.$item.'</li>'."\n";
13574: }
13575: }
13576: if ($replicationfail) {
13577: $output .= '<p class="LC_error">'.
13578: &mt('Course home server failed to retrieve:').'<ul>'.
13579: $replicationfail.
13580: '</ul></p>';
13581: }
13582: }
1.1055 raeburn 13583: } else {
13584: $warning = &mt('No items found in archive.');
13585: }
13586: if ($error) {
13587: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13588: $error.'</p>'."\n";
13589: }
13590: if ($warning) {
13591: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13592: }
13593: return $output;
13594: }
13595:
1.1066 raeburn 13596: sub cleanup_empty_dirs {
13597: my ($path) = @_;
13598: if (($path ne '') && (-d $path)) {
13599: if (opendir(my $dirh,$path)) {
13600: my @dircontents = grep(!/^\./,readdir($dirh));
13601: my $numitems = 0;
13602: foreach my $item (@dircontents) {
13603: if (-d "$path/$item") {
1.1111 raeburn 13604: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13605: if (-e "$path/$item") {
13606: $numitems ++;
13607: }
13608: } else {
13609: $numitems ++;
13610: }
13611: }
13612: if ($numitems == 0) {
13613: rmdir($path);
13614: }
13615: closedir($dirh);
13616: }
13617: }
13618: return;
13619: }
13620:
1.41 ng 13621: =pod
1.45 matthew 13622:
1.1162 raeburn 13623: =item * &get_folder_hierarchy()
1.1068 raeburn 13624:
13625: Provides hierarchy of names of folders/sub-folders containing the current
13626: item,
13627:
13628: Inputs: 3
13629: - $navmap - navmaps object
13630:
13631: - $map - url for map (either the trigger itself, or map containing
13632: the resource, which is the trigger).
13633:
13634: - $showitem - 1 => show title for map itself; 0 => do not show.
13635:
13636: Outputs: 1 @pathitems - array of folder/subfolder names.
13637:
13638: =cut
13639:
13640: sub get_folder_hierarchy {
13641: my ($navmap,$map,$showitem) = @_;
13642: my @pathitems;
13643: if (ref($navmap)) {
13644: my $mapres = $navmap->getResourceByUrl($map);
13645: if (ref($mapres)) {
13646: my $pcslist = $mapres->map_hierarchy();
13647: if ($pcslist ne '') {
13648: my @pcs = split(/,/,$pcslist);
13649: foreach my $pc (@pcs) {
13650: if ($pc == 1) {
1.1129 raeburn 13651: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13652: } else {
13653: my $res = $navmap->getByMapPc($pc);
13654: if (ref($res)) {
13655: my $title = $res->compTitle();
13656: $title =~ s/\W+/_/g;
13657: if ($title ne '') {
13658: push(@pathitems,$title);
13659: }
13660: }
13661: }
13662: }
13663: }
1.1071 raeburn 13664: if ($showitem) {
13665: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13666: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13667: } else {
13668: my $maptitle = $mapres->compTitle();
13669: $maptitle =~ s/\W+/_/g;
13670: if ($maptitle ne '') {
13671: push(@pathitems,$maptitle);
13672: }
1.1068 raeburn 13673: }
13674: }
13675: }
13676: }
13677: return @pathitems;
13678: }
13679:
13680: =pod
13681:
1.1015 raeburn 13682: =item * &get_turnedin_filepath()
13683:
13684: Determines path in a user's portfolio file for storage of files uploaded
13685: to a specific essayresponse or dropbox item.
13686:
13687: Inputs: 3 required + 1 optional.
13688: $symb is symb for resource, $uname and $udom are for current user (required).
13689: $caller is optional (can be "submission", if routine is called when storing
13690: an upoaded file when "Submit Answer" button was pressed).
13691:
13692: Returns array containing $path and $multiresp.
13693: $path is path in portfolio. $multiresp is 1 if this resource contains more
13694: than one file upload item. Callers of routine should append partid as a
13695: subdirectory to $path in cases where $multiresp is 1.
13696:
13697: Called by: homework/essayresponse.pm and homework/structuretags.pm
13698:
13699: =cut
13700:
13701: sub get_turnedin_filepath {
13702: my ($symb,$uname,$udom,$caller) = @_;
13703: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13704: my $turnindir;
13705: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13706: $turnindir = $userhash{'turnindir'};
13707: my ($path,$multiresp);
13708: if ($turnindir eq '') {
13709: if ($caller eq 'submission') {
13710: $turnindir = &mt('turned in');
13711: $turnindir =~ s/\W+/_/g;
13712: my %newhash = (
13713: 'turnindir' => $turnindir,
13714: );
13715: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13716: }
13717: }
13718: if ($turnindir ne '') {
13719: $path = '/'.$turnindir.'/';
13720: my ($multipart,$turnin,@pathitems);
13721: my $navmap = Apache::lonnavmaps::navmap->new();
13722: if (defined($navmap)) {
13723: my $mapres = $navmap->getResourceByUrl($map);
13724: if (ref($mapres)) {
13725: my $pcslist = $mapres->map_hierarchy();
13726: if ($pcslist ne '') {
13727: foreach my $pc (split(/,/,$pcslist)) {
13728: my $res = $navmap->getByMapPc($pc);
13729: if (ref($res)) {
13730: my $title = $res->compTitle();
13731: $title =~ s/\W+/_/g;
13732: if ($title ne '') {
1.1149 raeburn 13733: if (($pc > 1) && (length($title) > 12)) {
13734: $title = substr($title,0,12);
13735: }
1.1015 raeburn 13736: push(@pathitems,$title);
13737: }
13738: }
13739: }
13740: }
13741: my $maptitle = $mapres->compTitle();
13742: $maptitle =~ s/\W+/_/g;
13743: if ($maptitle ne '') {
1.1149 raeburn 13744: if (length($maptitle) > 12) {
13745: $maptitle = substr($maptitle,0,12);
13746: }
1.1015 raeburn 13747: push(@pathitems,$maptitle);
13748: }
13749: unless ($env{'request.state'} eq 'construct') {
13750: my $res = $navmap->getBySymb($symb);
13751: if (ref($res)) {
13752: my $partlist = $res->parts();
13753: my $totaluploads = 0;
13754: if (ref($partlist) eq 'ARRAY') {
13755: foreach my $part (@{$partlist}) {
13756: my @types = $res->responseType($part);
13757: my @ids = $res->responseIds($part);
13758: for (my $i=0; $i < scalar(@ids); $i++) {
13759: if ($types[$i] eq 'essay') {
13760: my $partid = $part.'_'.$ids[$i];
13761: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13762: $totaluploads ++;
13763: }
13764: }
13765: }
13766: }
13767: if ($totaluploads > 1) {
13768: $multiresp = 1;
13769: }
13770: }
13771: }
13772: }
13773: } else {
13774: return;
13775: }
13776: } else {
13777: return;
13778: }
13779: my $restitle=&Apache::lonnet::gettitle($symb);
13780: $restitle =~ s/\W+/_/g;
13781: if ($restitle eq '') {
13782: $restitle = ($resurl =~ m{/[^/]+$});
13783: if ($restitle eq '') {
13784: $restitle = time;
13785: }
13786: }
1.1149 raeburn 13787: if (length($restitle) > 12) {
13788: $restitle = substr($restitle,0,12);
13789: }
1.1015 raeburn 13790: push(@pathitems,$restitle);
13791: $path .= join('/',@pathitems);
13792: }
13793: return ($path,$multiresp);
13794: }
13795:
13796: =pod
13797:
1.464 albertel 13798: =back
1.41 ng 13799:
1.112 bowersj2 13800: =head1 CSV Upload/Handling functions
1.38 albertel 13801:
1.41 ng 13802: =over 4
13803:
1.648 raeburn 13804: =item * &upfile_store($r)
1.41 ng 13805:
13806: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13807: needs $env{'form.upfile'}
1.41 ng 13808: returns $datatoken to be put into hidden field
13809:
13810: =cut
1.31 albertel 13811:
13812: sub upfile_store {
13813: my $r=shift;
1.258 albertel 13814: $env{'form.upfile'}=~s/\r/\n/gs;
13815: $env{'form.upfile'}=~s/\f/\n/gs;
13816: $env{'form.upfile'}=~s/\n+/\n/gs;
13817: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13818:
1.1299 raeburn 13819: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13820: '_enroll_'.$env{'request.course.id'}.'_'.
13821: time.'_'.$$);
13822: return if ($datatoken eq '');
13823:
1.31 albertel 13824: {
1.158 raeburn 13825: my $datafile = $r->dir_config('lonDaemons').
13826: '/tmp/'.$datatoken.'.tmp';
13827: if ( open(my $fh,">$datafile") ) {
1.258 albertel 13828: print $fh $env{'form.upfile'};
1.158 raeburn 13829: close($fh);
13830: }
1.31 albertel 13831: }
13832: return $datatoken;
13833: }
13834:
1.56 matthew 13835: =pod
13836:
1.1290 raeburn 13837: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13838:
13839: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 13840: $datatoken is the name to assign to the temporary file.
1.258 albertel 13841: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13842:
13843: =cut
1.31 albertel 13844:
13845: sub load_tmp_file {
1.1290 raeburn 13846: my ($r,$datatoken) = @_;
13847: return if ($datatoken eq '');
1.31 albertel 13848: my @studentdata=();
13849: {
1.158 raeburn 13850: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 13851: '/tmp/'.$datatoken.'.tmp';
1.158 raeburn 13852: if ( open(my $fh,"<$studentfile") ) {
13853: @studentdata=<$fh>;
13854: close($fh);
13855: }
1.31 albertel 13856: }
1.258 albertel 13857: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13858: }
13859:
1.1290 raeburn 13860: sub valid_datatoken {
13861: my ($datatoken) = @_;
1.1291 raeburn 13862: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_$match_domain\_$match_courseid\_\d+_\d+$/) {
1.1290 raeburn 13863: return $datatoken;
13864: }
13865: return;
13866: }
13867:
1.56 matthew 13868: =pod
13869:
1.648 raeburn 13870: =item * &upfile_record_sep()
1.41 ng 13871:
13872: Separate uploaded file into records
13873: returns array of records,
1.258 albertel 13874: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13875:
13876: =cut
1.31 albertel 13877:
13878: sub upfile_record_sep {
1.258 albertel 13879: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13880: } else {
1.248 albertel 13881: my @records;
1.258 albertel 13882: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13883: if ($line=~/^\s*$/) { next; }
13884: push(@records,$line);
13885: }
13886: return @records;
1.31 albertel 13887: }
13888: }
13889:
1.56 matthew 13890: =pod
13891:
1.648 raeburn 13892: =item * &record_sep($record)
1.41 ng 13893:
1.258 albertel 13894: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13895:
13896: =cut
13897:
1.263 www 13898: sub takeleft {
13899: my $index=shift;
13900: return substr('0000'.$index,-4,4);
13901: }
13902:
1.31 albertel 13903: sub record_sep {
13904: my $record=shift;
13905: my %components=();
1.258 albertel 13906: if ($env{'form.upfiletype'} eq 'xml') {
13907: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13908: my $i=0;
1.356 albertel 13909: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13910: $field=~s/^(\"|\')//;
13911: $field=~s/(\"|\')$//;
1.263 www 13912: $components{&takeleft($i)}=$field;
1.31 albertel 13913: $i++;
13914: }
1.258 albertel 13915: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13916: my $i=0;
1.356 albertel 13917: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13918: $field=~s/^(\"|\')//;
13919: $field=~s/(\"|\')$//;
1.263 www 13920: $components{&takeleft($i)}=$field;
1.31 albertel 13921: $i++;
13922: }
13923: } else {
1.561 www 13924: my $separator=',';
1.480 banghart 13925: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13926: $separator=';';
1.480 banghart 13927: }
1.31 albertel 13928: my $i=0;
1.561 www 13929: # the character we are looking for to indicate the end of a quote or a record
13930: my $looking_for=$separator;
13931: # do not add the characters to the fields
13932: my $ignore=0;
13933: # we just encountered a separator (or the beginning of the record)
13934: my $just_found_separator=1;
13935: # store the field we are working on here
13936: my $field='';
13937: # work our way through all characters in record
13938: foreach my $character ($record=~/(.)/g) {
13939: if ($character eq $looking_for) {
13940: if ($character ne $separator) {
13941: # Found the end of a quote, again looking for separator
13942: $looking_for=$separator;
13943: $ignore=1;
13944: } else {
13945: # Found a separator, store away what we got
13946: $components{&takeleft($i)}=$field;
13947: $i++;
13948: $just_found_separator=1;
13949: $ignore=0;
13950: $field='';
13951: }
13952: next;
13953: }
13954: # single or double quotation marks after a separator indicate beginning of a quote
13955: # we are now looking for the end of the quote and need to ignore separators
13956: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13957: $looking_for=$character;
13958: next;
13959: }
13960: # ignore would be true after we reached the end of a quote
13961: if ($ignore) { next; }
13962: if (($just_found_separator) && ($character=~/\s/)) { next; }
13963: $field.=$character;
13964: $just_found_separator=0;
1.31 albertel 13965: }
1.561 www 13966: # catch the very last entry, since we never encountered the separator
13967: $components{&takeleft($i)}=$field;
1.31 albertel 13968: }
13969: return %components;
13970: }
13971:
1.144 matthew 13972: ######################################################
13973: ######################################################
13974:
1.56 matthew 13975: =pod
13976:
1.648 raeburn 13977: =item * &upfile_select_html()
1.41 ng 13978:
1.144 matthew 13979: Return HTML code to select a file from the users machine and specify
13980: the file type.
1.41 ng 13981:
13982: =cut
13983:
1.144 matthew 13984: ######################################################
13985: ######################################################
1.31 albertel 13986: sub upfile_select_html {
1.144 matthew 13987: my %Types = (
13988: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13989: semisv => &mt('Semicolon separated values'),
1.144 matthew 13990: space => &mt('Space separated'),
13991: tab => &mt('Tabulator separated'),
13992: # xml => &mt('HTML/XML'),
13993: );
13994: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13995: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13996: foreach my $type (sort(keys(%Types))) {
13997: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13998: }
13999: $Str .= "</select>\n";
14000: return $Str;
1.31 albertel 14001: }
14002:
1.301 albertel 14003: sub get_samples {
14004: my ($records,$toget) = @_;
14005: my @samples=({});
14006: my $got=0;
14007: foreach my $rec (@$records) {
14008: my %temp = &record_sep($rec);
14009: if (! grep(/\S/, values(%temp))) { next; }
14010: if (%temp) {
14011: $samples[$got]=\%temp;
14012: $got++;
14013: if ($got == $toget) { last; }
14014: }
14015: }
14016: return \@samples;
14017: }
14018:
1.144 matthew 14019: ######################################################
14020: ######################################################
14021:
1.56 matthew 14022: =pod
14023:
1.648 raeburn 14024: =item * &csv_print_samples($r,$records)
1.41 ng 14025:
14026: Prints a table of sample values from each column uploaded $r is an
14027: Apache Request ref, $records is an arrayref from
14028: &Apache::loncommon::upfile_record_sep
14029:
14030: =cut
14031:
1.144 matthew 14032: ######################################################
14033: ######################################################
1.31 albertel 14034: sub csv_print_samples {
14035: my ($r,$records) = @_;
1.662 bisitz 14036: my $samples = &get_samples($records,5);
1.301 albertel 14037:
1.594 raeburn 14038: $r->print(&mt('Samples').'<br />'.&start_data_table().
14039: &start_data_table_header_row());
1.356 albertel 14040: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14041: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14042: $r->print(&end_data_table_header_row());
1.301 albertel 14043: foreach my $hash (@$samples) {
1.594 raeburn 14044: $r->print(&start_data_table_row());
1.356 albertel 14045: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14046: $r->print('<td>');
1.356 albertel 14047: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14048: $r->print('</td>');
14049: }
1.594 raeburn 14050: $r->print(&end_data_table_row());
1.31 albertel 14051: }
1.594 raeburn 14052: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14053: }
14054:
1.144 matthew 14055: ######################################################
14056: ######################################################
14057:
1.56 matthew 14058: =pod
14059:
1.648 raeburn 14060: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14061:
14062: Prints a table to create associations between values and table columns.
1.144 matthew 14063:
1.41 ng 14064: $r is an Apache Request ref,
14065: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14066: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14067:
14068: =cut
14069:
1.144 matthew 14070: ######################################################
14071: ######################################################
1.31 albertel 14072: sub csv_print_select_table {
14073: my ($r,$records,$d) = @_;
1.301 albertel 14074: my $i=0;
14075: my $samples = &get_samples($records,1);
1.144 matthew 14076: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14077: &start_data_table().&start_data_table_header_row().
1.144 matthew 14078: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14079: '<th>'.&mt('Column').'</th>'.
14080: &end_data_table_header_row()."\n");
1.356 albertel 14081: foreach my $array_ref (@$d) {
14082: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14083: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14084:
1.875 bisitz 14085: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14086: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14087: $r->print('<option value="none"></option>');
1.356 albertel 14088: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14089: $r->print('<option value="'.$sample.'"'.
14090: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14091: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14092: }
1.594 raeburn 14093: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14094: $i++;
14095: }
1.594 raeburn 14096: $r->print(&end_data_table());
1.31 albertel 14097: $i--;
14098: return $i;
14099: }
1.56 matthew 14100:
1.144 matthew 14101: ######################################################
14102: ######################################################
14103:
1.56 matthew 14104: =pod
1.31 albertel 14105:
1.648 raeburn 14106: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14107:
14108: Prints a table of sample values from the upload and can make associate samples to internal names.
14109:
14110: $r is an Apache Request ref,
14111: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14112: $d is an array of 2 element arrays (internal name, displayed name)
14113:
14114: =cut
14115:
1.144 matthew 14116: ######################################################
14117: ######################################################
1.31 albertel 14118: sub csv_samples_select_table {
14119: my ($r,$records,$d) = @_;
14120: my $i=0;
1.144 matthew 14121: #
1.662 bisitz 14122: my $max_samples = 5;
14123: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14124: $r->print(&start_data_table().
14125: &start_data_table_header_row().'<th>'.
14126: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14127: &end_data_table_header_row());
1.301 albertel 14128:
14129: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14130: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14131: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14132: foreach my $option (@$d) {
14133: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14134: $r->print('<option value="'.$value.'"'.
1.253 albertel 14135: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14136: $display.'</option>');
1.31 albertel 14137: }
14138: $r->print('</select></td><td>');
1.662 bisitz 14139: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14140: if (defined($samples->[$line]{$key})) {
14141: $r->print($samples->[$line]{$key}."<br />\n");
14142: }
14143: }
1.594 raeburn 14144: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14145: $i++;
14146: }
1.594 raeburn 14147: $r->print(&end_data_table());
1.31 albertel 14148: $i--;
14149: return($i);
1.115 matthew 14150: }
14151:
1.144 matthew 14152: ######################################################
14153: ######################################################
14154:
1.115 matthew 14155: =pod
14156:
1.648 raeburn 14157: =item * &clean_excel_name($name)
1.115 matthew 14158:
14159: Returns a replacement for $name which does not contain any illegal characters.
14160:
14161: =cut
14162:
1.144 matthew 14163: ######################################################
14164: ######################################################
1.115 matthew 14165: sub clean_excel_name {
14166: my ($name) = @_;
14167: $name =~ s/[:\*\?\/\\]//g;
14168: if (length($name) > 31) {
14169: $name = substr($name,0,31);
14170: }
14171: return $name;
1.25 albertel 14172: }
1.84 albertel 14173:
1.85 albertel 14174: =pod
14175:
1.648 raeburn 14176: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14177:
14178: Returns either 1 or undef
14179:
14180: 1 if the part is to be hidden, undef if it is to be shown
14181:
14182: Arguments are:
14183:
14184: $id the id of the part to be checked
14185: $symb, optional the symb of the resource to check
14186: $udom, optional the domain of the user to check for
14187: $uname, optional the username of the user to check for
14188:
14189: =cut
1.84 albertel 14190:
14191: sub check_if_partid_hidden {
14192: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14193: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14194: $symb,$udom,$uname);
1.141 albertel 14195: my $truth=1;
14196: #if the string starts with !, then the list is the list to show not hide
14197: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14198: my @hiddenlist=split(/,/,$hiddenparts);
14199: foreach my $checkid (@hiddenlist) {
1.141 albertel 14200: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14201: }
1.141 albertel 14202: return !$truth;
1.84 albertel 14203: }
1.127 matthew 14204:
1.138 matthew 14205:
14206: ############################################################
14207: ############################################################
14208:
14209: =pod
14210:
1.157 matthew 14211: =back
14212:
1.138 matthew 14213: =head1 cgi-bin script and graphing routines
14214:
1.157 matthew 14215: =over 4
14216:
1.648 raeburn 14217: =item * &get_cgi_id()
1.138 matthew 14218:
14219: Inputs: none
14220:
14221: Returns an id which can be used to pass environment variables
14222: to various cgi-bin scripts. These environment variables will
14223: be removed from the users environment after a given time by
14224: the routine &Apache::lonnet::transfer_profile_to_env.
14225:
14226: =cut
14227:
14228: ############################################################
14229: ############################################################
1.152 albertel 14230: my $uniq=0;
1.136 matthew 14231: sub get_cgi_id {
1.154 albertel 14232: $uniq=($uniq+1)%100000;
1.280 albertel 14233: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14234: }
14235:
1.127 matthew 14236: ############################################################
14237: ############################################################
14238:
14239: =pod
14240:
1.648 raeburn 14241: =item * &DrawBarGraph()
1.127 matthew 14242:
1.138 matthew 14243: Facilitates the plotting of data in a (stacked) bar graph.
14244: Puts plot definition data into the users environment in order for
14245: graph.png to plot it. Returns an <img> tag for the plot.
14246: The bars on the plot are labeled '1','2',...,'n'.
14247:
14248: Inputs:
14249:
14250: =over 4
14251:
14252: =item $Title: string, the title of the plot
14253:
14254: =item $xlabel: string, text describing the X-axis of the plot
14255:
14256: =item $ylabel: string, text describing the Y-axis of the plot
14257:
14258: =item $Max: scalar, the maximum Y value to use in the plot
14259: If $Max is < any data point, the graph will not be rendered.
14260:
1.140 matthew 14261: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14262: they are plotted. If undefined, default values will be used.
14263:
1.178 matthew 14264: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14265:
1.138 matthew 14266: =item @Values: An array of array references. Each array reference holds data
14267: to be plotted in a stacked bar chart.
14268:
1.239 matthew 14269: =item If the final element of @Values is a hash reference the key/value
14270: pairs will be added to the graph definition.
14271:
1.138 matthew 14272: =back
14273:
14274: Returns:
14275:
14276: An <img> tag which references graph.png and the appropriate identifying
14277: information for the plot.
14278:
1.127 matthew 14279: =cut
14280:
14281: ############################################################
14282: ############################################################
1.134 matthew 14283: sub DrawBarGraph {
1.178 matthew 14284: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14285: #
14286: if (! defined($colors)) {
14287: $colors = ['#33ff00',
14288: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14289: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14290: ];
14291: }
1.228 matthew 14292: my $extra_settings = {};
14293: if (ref($Values[-1]) eq 'HASH') {
14294: $extra_settings = pop(@Values);
14295: }
1.127 matthew 14296: #
1.136 matthew 14297: my $identifier = &get_cgi_id();
14298: my $id = 'cgi.'.$identifier;
1.129 matthew 14299: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14300: return '';
14301: }
1.225 matthew 14302: #
14303: my @Labels;
14304: if (defined($labels)) {
14305: @Labels = @$labels;
14306: } else {
14307: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14308: push(@Labels,$i+1);
1.225 matthew 14309: }
14310: }
14311: #
1.129 matthew 14312: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14313: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14314: my %ValuesHash;
14315: my $NumSets=1;
14316: foreach my $array (@Values) {
14317: next if (! ref($array));
1.136 matthew 14318: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14319: join(',',@$array);
1.129 matthew 14320: }
1.127 matthew 14321: #
1.136 matthew 14322: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14323: if ($NumBars < 3) {
14324: $width = 120+$NumBars*32;
1.220 matthew 14325: $xskip = 1;
1.225 matthew 14326: $bar_width = 30;
14327: } elsif ($NumBars < 5) {
14328: $width = 120+$NumBars*20;
14329: $xskip = 1;
14330: $bar_width = 20;
1.220 matthew 14331: } elsif ($NumBars < 10) {
1.136 matthew 14332: $width = 120+$NumBars*15;
14333: $xskip = 1;
14334: $bar_width = 15;
14335: } elsif ($NumBars <= 25) {
14336: $width = 120+$NumBars*11;
14337: $xskip = 5;
14338: $bar_width = 8;
14339: } elsif ($NumBars <= 50) {
14340: $width = 120+$NumBars*8;
14341: $xskip = 5;
14342: $bar_width = 4;
14343: } else {
14344: $width = 120+$NumBars*8;
14345: $xskip = 5;
14346: $bar_width = 4;
14347: }
14348: #
1.137 matthew 14349: $Max = 1 if ($Max < 1);
14350: if ( int($Max) < $Max ) {
14351: $Max++;
14352: $Max = int($Max);
14353: }
1.127 matthew 14354: $Title = '' if (! defined($Title));
14355: $xlabel = '' if (! defined($xlabel));
14356: $ylabel = '' if (! defined($ylabel));
1.369 www 14357: $ValuesHash{$id.'.title'} = &escape($Title);
14358: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14359: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14360: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14361: $ValuesHash{$id.'.NumBars'} = $NumBars;
14362: $ValuesHash{$id.'.NumSets'} = $NumSets;
14363: $ValuesHash{$id.'.PlotType'} = 'bar';
14364: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14365: $ValuesHash{$id.'.height'} = $height;
14366: $ValuesHash{$id.'.width'} = $width;
14367: $ValuesHash{$id.'.xskip'} = $xskip;
14368: $ValuesHash{$id.'.bar_width'} = $bar_width;
14369: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14370: #
1.228 matthew 14371: # Deal with other parameters
14372: while (my ($key,$value) = each(%$extra_settings)) {
14373: $ValuesHash{$id.'.'.$key} = $value;
14374: }
14375: #
1.646 raeburn 14376: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14377: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14378: }
14379:
14380: ############################################################
14381: ############################################################
14382:
14383: =pod
14384:
1.648 raeburn 14385: =item * &DrawXYGraph()
1.137 matthew 14386:
1.138 matthew 14387: Facilitates the plotting of data in an XY graph.
14388: Puts plot definition data into the users environment in order for
14389: graph.png to plot it. Returns an <img> tag for the plot.
14390:
14391: Inputs:
14392:
14393: =over 4
14394:
14395: =item $Title: string, the title of the plot
14396:
14397: =item $xlabel: string, text describing the X-axis of the plot
14398:
14399: =item $ylabel: string, text describing the Y-axis of the plot
14400:
14401: =item $Max: scalar, the maximum Y value to use in the plot
14402: If $Max is < any data point, the graph will not be rendered.
14403:
14404: =item $colors: Array ref containing the hex color codes for the data to be
14405: plotted in. If undefined, default values will be used.
14406:
14407: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14408:
14409: =item $Ydata: Array ref containing Array refs.
1.185 www 14410: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14411:
14412: =item %Values: hash indicating or overriding any default values which are
14413: passed to graph.png.
14414: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14415:
14416: =back
14417:
14418: Returns:
14419:
14420: An <img> tag which references graph.png and the appropriate identifying
14421: information for the plot.
14422:
1.137 matthew 14423: =cut
14424:
14425: ############################################################
14426: ############################################################
14427: sub DrawXYGraph {
14428: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14429: #
14430: # Create the identifier for the graph
14431: my $identifier = &get_cgi_id();
14432: my $id = 'cgi.'.$identifier;
14433: #
14434: $Title = '' if (! defined($Title));
14435: $xlabel = '' if (! defined($xlabel));
14436: $ylabel = '' if (! defined($ylabel));
14437: my %ValuesHash =
14438: (
1.369 www 14439: $id.'.title' => &escape($Title),
14440: $id.'.xlabel' => &escape($xlabel),
14441: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14442: $id.'.y_max_value'=> $Max,
14443: $id.'.labels' => join(',',@$Xlabels),
14444: $id.'.PlotType' => 'XY',
14445: );
14446: #
14447: if (defined($colors) && ref($colors) eq 'ARRAY') {
14448: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14449: }
14450: #
14451: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14452: return '';
14453: }
14454: my $NumSets=1;
1.138 matthew 14455: foreach my $array (@{$Ydata}){
1.137 matthew 14456: next if (! ref($array));
14457: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14458: }
1.138 matthew 14459: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14460: #
14461: # Deal with other parameters
14462: while (my ($key,$value) = each(%Values)) {
14463: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14464: }
14465: #
1.646 raeburn 14466: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14467: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14468: }
14469:
14470: ############################################################
14471: ############################################################
14472:
14473: =pod
14474:
1.648 raeburn 14475: =item * &DrawXYYGraph()
1.138 matthew 14476:
14477: Facilitates the plotting of data in an XY graph with two Y axes.
14478: Puts plot definition data into the users environment in order for
14479: graph.png to plot it. Returns an <img> tag for the plot.
14480:
14481: Inputs:
14482:
14483: =over 4
14484:
14485: =item $Title: string, the title of the plot
14486:
14487: =item $xlabel: string, text describing the X-axis of the plot
14488:
14489: =item $ylabel: string, text describing the Y-axis of the plot
14490:
14491: =item $colors: Array ref containing the hex color codes for the data to be
14492: plotted in. If undefined, default values will be used.
14493:
14494: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14495:
14496: =item $Ydata1: The first data set
14497:
14498: =item $Min1: The minimum value of the left Y-axis
14499:
14500: =item $Max1: The maximum value of the left Y-axis
14501:
14502: =item $Ydata2: The second data set
14503:
14504: =item $Min2: The minimum value of the right Y-axis
14505:
14506: =item $Max2: The maximum value of the left Y-axis
14507:
14508: =item %Values: hash indicating or overriding any default values which are
14509: passed to graph.png.
14510: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14511:
14512: =back
14513:
14514: Returns:
14515:
14516: An <img> tag which references graph.png and the appropriate identifying
14517: information for the plot.
1.136 matthew 14518:
14519: =cut
14520:
14521: ############################################################
14522: ############################################################
1.137 matthew 14523: sub DrawXYYGraph {
14524: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14525: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14526: #
14527: # Create the identifier for the graph
14528: my $identifier = &get_cgi_id();
14529: my $id = 'cgi.'.$identifier;
14530: #
14531: $Title = '' if (! defined($Title));
14532: $xlabel = '' if (! defined($xlabel));
14533: $ylabel = '' if (! defined($ylabel));
14534: my %ValuesHash =
14535: (
1.369 www 14536: $id.'.title' => &escape($Title),
14537: $id.'.xlabel' => &escape($xlabel),
14538: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14539: $id.'.labels' => join(',',@$Xlabels),
14540: $id.'.PlotType' => 'XY',
14541: $id.'.NumSets' => 2,
1.137 matthew 14542: $id.'.two_axes' => 1,
14543: $id.'.y1_max_value' => $Max1,
14544: $id.'.y1_min_value' => $Min1,
14545: $id.'.y2_max_value' => $Max2,
14546: $id.'.y2_min_value' => $Min2,
1.136 matthew 14547: );
14548: #
1.137 matthew 14549: if (defined($colors) && ref($colors) eq 'ARRAY') {
14550: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14551: }
14552: #
14553: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14554: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14555: return '';
14556: }
14557: my $NumSets=1;
1.137 matthew 14558: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14559: next if (! ref($array));
14560: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14561: }
14562: #
14563: # Deal with other parameters
14564: while (my ($key,$value) = each(%Values)) {
14565: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14566: }
14567: #
1.646 raeburn 14568: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14569: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14570: }
14571:
14572: ############################################################
14573: ############################################################
14574:
14575: =pod
14576:
1.157 matthew 14577: =back
14578:
1.139 matthew 14579: =head1 Statistics helper routines?
14580:
14581: Bad place for them but what the hell.
14582:
1.157 matthew 14583: =over 4
14584:
1.648 raeburn 14585: =item * &chartlink()
1.139 matthew 14586:
14587: Returns a link to the chart for a specific student.
14588:
14589: Inputs:
14590:
14591: =over 4
14592:
14593: =item $linktext: The text of the link
14594:
14595: =item $sname: The students username
14596:
14597: =item $sdomain: The students domain
14598:
14599: =back
14600:
1.157 matthew 14601: =back
14602:
1.139 matthew 14603: =cut
14604:
14605: ############################################################
14606: ############################################################
14607: sub chartlink {
14608: my ($linktext, $sname, $sdomain) = @_;
14609: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14610: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14611: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14612: '">'.$linktext.'</a>';
1.153 matthew 14613: }
14614:
14615: #######################################################
14616: #######################################################
14617:
14618: =pod
14619:
14620: =head1 Course Environment Routines
1.157 matthew 14621:
14622: =over 4
1.153 matthew 14623:
1.648 raeburn 14624: =item * &restore_course_settings()
1.153 matthew 14625:
1.648 raeburn 14626: =item * &store_course_settings()
1.153 matthew 14627:
14628: Restores/Store indicated form parameters from the course environment.
14629: Will not overwrite existing values of the form parameters.
14630:
14631: Inputs:
14632: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14633:
14634: a hash ref describing the data to be stored. For example:
14635:
14636: %Save_Parameters = ('Status' => 'scalar',
14637: 'chartoutputmode' => 'scalar',
14638: 'chartoutputdata' => 'scalar',
14639: 'Section' => 'array',
1.373 raeburn 14640: 'Group' => 'array',
1.153 matthew 14641: 'StudentData' => 'array',
14642: 'Maps' => 'array');
14643:
14644: Returns: both routines return nothing
14645:
1.631 raeburn 14646: =back
14647:
1.153 matthew 14648: =cut
14649:
14650: #######################################################
14651: #######################################################
14652: sub store_course_settings {
1.496 albertel 14653: return &store_settings($env{'request.course.id'},@_);
14654: }
14655:
14656: sub store_settings {
1.153 matthew 14657: # save to the environment
14658: # appenv the same items, just to be safe
1.300 albertel 14659: my $udom = $env{'user.domain'};
14660: my $uname = $env{'user.name'};
1.496 albertel 14661: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14662: my %SaveHash;
14663: my %AppHash;
14664: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14665: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14666: my $envname = 'environment.'.$basename;
1.258 albertel 14667: if (exists($env{'form.'.$setting})) {
1.153 matthew 14668: # Save this value away
14669: if ($type eq 'scalar' &&
1.258 albertel 14670: (! exists($env{$envname}) ||
14671: $env{$envname} ne $env{'form.'.$setting})) {
14672: $SaveHash{$basename} = $env{'form.'.$setting};
14673: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14674: } elsif ($type eq 'array') {
14675: my $stored_form;
1.258 albertel 14676: if (ref($env{'form.'.$setting})) {
1.153 matthew 14677: $stored_form = join(',',
14678: map {
1.369 www 14679: &escape($_);
1.258 albertel 14680: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14681: } else {
14682: $stored_form =
1.369 www 14683: &escape($env{'form.'.$setting});
1.153 matthew 14684: }
14685: # Determine if the array contents are the same.
1.258 albertel 14686: if ($stored_form ne $env{$envname}) {
1.153 matthew 14687: $SaveHash{$basename} = $stored_form;
14688: $AppHash{$envname} = $stored_form;
14689: }
14690: }
14691: }
14692: }
14693: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14694: $udom,$uname);
1.153 matthew 14695: if ($put_result !~ /^(ok|delayed)/) {
14696: &Apache::lonnet::logthis('unable to save form parameters, '.
14697: 'got error:'.$put_result);
14698: }
14699: # Make sure these settings stick around in this session, too
1.646 raeburn 14700: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14701: return;
14702: }
14703:
14704: sub restore_course_settings {
1.499 albertel 14705: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14706: }
14707:
14708: sub restore_settings {
14709: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14710: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14711: next if (exists($env{'form.'.$setting}));
1.496 albertel 14712: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14713: '.'.$setting;
1.258 albertel 14714: if (exists($env{$envname})) {
1.153 matthew 14715: if ($type eq 'scalar') {
1.258 albertel 14716: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14717: } elsif ($type eq 'array') {
1.258 albertel 14718: $env{'form.'.$setting} = [
1.153 matthew 14719: map {
1.369 www 14720: &unescape($_);
1.258 albertel 14721: } split(',',$env{$envname})
1.153 matthew 14722: ];
14723: }
14724: }
14725: }
1.127 matthew 14726: }
14727:
1.618 raeburn 14728: #######################################################
14729: #######################################################
14730:
14731: =pod
14732:
14733: =head1 Domain E-mail Routines
14734:
14735: =over 4
14736:
1.648 raeburn 14737: =item * &build_recipient_list()
1.618 raeburn 14738:
1.1144 raeburn 14739: Build recipient lists for following types of e-mail:
1.766 raeburn 14740: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14741: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14742: module change checking, student/employee ID conflict checks, as
14743: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14744: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14745:
14746: Inputs:
1.619 raeburn 14747: defmail (scalar - email address of default recipient),
1.1144 raeburn 14748: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14749: requestsmail, updatesmail, or idconflictsmail).
14750:
1.619 raeburn 14751: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14752:
1.619 raeburn 14753: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 14754: i.e., predates configuration by DC via domainprefs.pm
14755:
14756: $requname username of requester (if mailing type is helpdeskmail)
14757:
14758: $requdom domain of requester (if mailing type is helpdeskmail)
14759:
14760: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14761:
1.618 raeburn 14762:
1.655 raeburn 14763: Returns: comma separated list of addresses to which to send e-mail.
14764:
14765: =back
1.618 raeburn 14766:
14767: =cut
14768:
14769: ############################################################
14770: ############################################################
14771: sub build_recipient_list {
1.1297 raeburn 14772: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14773: my @recipients;
1.1270 raeburn 14774: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14775: my %domconfig =
1.1270 raeburn 14776: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14777: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14778: if (exists($domconfig{'contacts'}{$mailing})) {
14779: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14780: my @contacts = ('adminemail','supportemail');
14781: foreach my $item (@contacts) {
14782: if ($domconfig{'contacts'}{$mailing}{$item}) {
14783: my $addr = $domconfig{'contacts'}{$item};
14784: if (!grep(/^\Q$addr\E$/,@recipients)) {
14785: push(@recipients,$addr);
14786: }
1.619 raeburn 14787: }
1.1270 raeburn 14788: }
14789: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14790: if ($mailing eq 'helpdeskmail') {
14791: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14792: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14793: my @ok_bccs;
14794: foreach my $bcc (@bccs) {
14795: $bcc =~ s/^\s+//g;
14796: $bcc =~ s/\s+$//g;
14797: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14798: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14799: push(@ok_bccs,$bcc);
14800: }
14801: }
14802: }
14803: if (@ok_bccs > 0) {
14804: $allbcc = join(', ',@ok_bccs);
14805: }
14806: }
14807: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14808: }
14809: }
1.766 raeburn 14810: } elsif ($origmail ne '') {
1.1270 raeburn 14811: $lastresort = $origmail;
1.618 raeburn 14812: }
1.1297 raeburn 14813: if ($mailing eq 'helpdeskmail') {
14814: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14815: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14816: my ($inststatus,$inststatus_checked);
14817: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14818: ($env{'user.domain'} ne 'public')) {
14819: $inststatus_checked = 1;
14820: $inststatus = $env{'environment.inststatus'};
14821: }
14822: unless ($inststatus_checked) {
14823: if (($requname ne '') && ($requdom ne '')) {
14824: if (($requname =~ /^$match_username$/) &&
14825: ($requdom =~ /^$match_domain$/) &&
14826: (&Apache::lonnet::domain($requdom))) {
14827: my $requhome = &Apache::lonnet::homeserver($requname,
14828: $requdom);
14829: unless ($requhome eq 'no_host') {
14830: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14831: $inststatus = $userenv{'inststatus'};
14832: $inststatus_checked = 1;
14833: }
14834: }
14835: }
14836: }
14837: unless ($inststatus_checked) {
14838: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
14839: my %srch = (srchby => 'email',
14840: srchdomain => $defdom,
14841: srchterm => $reqemail,
14842: srchtype => 'exact');
14843: my %srch_results = &Apache::lonnet::usersearch(\%srch);
14844: foreach my $uname (keys(%srch_results)) {
14845: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14846: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14847: $inststatus_checked = 1;
14848: last;
14849: }
14850: }
14851: unless ($inststatus_checked) {
14852: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
14853: if ($dirsrchres eq 'ok') {
14854: foreach my $uname (keys(%srch_results)) {
14855: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14856: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14857: $inststatus_checked = 1;
14858: last;
14859: }
14860: }
14861: }
14862: }
14863: }
14864: }
14865: if ($inststatus ne '') {
14866: foreach my $status (split(/\:/,$inststatus)) {
14867: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
14868: my @contacts = ('adminemail','supportemail');
14869: foreach my $item (@contacts) {
14870: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
14871: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
14872: if (!grep(/^\Q$addr\E$/,@recipients)) {
14873: push(@recipients,$addr);
14874: }
14875: }
14876: }
14877: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
14878: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
14879: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
14880: my @ok_bccs;
14881: foreach my $bcc (@bccs) {
14882: $bcc =~ s/^\s+//g;
14883: $bcc =~ s/\s+$//g;
14884: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14885: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14886: push(@ok_bccs,$bcc);
14887: }
14888: }
14889: }
14890: if (@ok_bccs > 0) {
14891: $allbcc = join(', ',@ok_bccs);
14892: }
14893: }
14894: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
14895: last;
14896: }
14897: }
14898: }
14899: }
14900: }
1.619 raeburn 14901: } elsif ($origmail ne '') {
1.1270 raeburn 14902: $lastresort = $origmail;
14903: }
1.1297 raeburn 14904: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 14905: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14906: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14907: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14908: my %what = (
14909: perlvar => 1,
14910: );
14911: my $primary = &Apache::lonnet::domain($defdom,'primary');
14912: if ($primary) {
14913: my $gotaddr;
14914: my ($result,$returnhash) =
14915: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14916: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14917: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14918: $lastresort = $returnhash->{'lonSupportEMail'};
14919: $gotaddr = 1;
14920: }
14921: }
14922: unless ($gotaddr) {
14923: my $uintdom = &Apache::lonnet::internet_dom($primary);
14924: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14925: unless ($uintdom eq $intdom) {
14926: my %domconfig =
14927: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14928: if (ref($domconfig{'contacts'}) eq 'HASH') {
14929: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14930: my @contacts = ('adminemail','supportemail');
14931: foreach my $item (@contacts) {
14932: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14933: my $addr = $domconfig{'contacts'}{$item};
14934: if (!grep(/^\Q$addr\E$/,@recipients)) {
14935: push(@recipients,$addr);
14936: }
14937: }
14938: }
14939: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14940: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14941: }
14942: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14943: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14944: my @ok_bccs;
14945: foreach my $bcc (@bccs) {
14946: $bcc =~ s/^\s+//g;
14947: $bcc =~ s/\s+$//g;
14948: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14949: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14950: push(@ok_bccs,$bcc);
14951: }
14952: }
14953: }
14954: if (@ok_bccs > 0) {
14955: $allbcc = join(', ',@ok_bccs);
14956: }
14957: }
14958: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14959: }
14960: }
14961: }
14962: }
14963: }
14964: }
1.618 raeburn 14965: }
1.688 raeburn 14966: if (defined($defmail)) {
14967: if ($defmail ne '') {
14968: push(@recipients,$defmail);
14969: }
1.618 raeburn 14970: }
14971: if ($otheremails) {
1.619 raeburn 14972: my @others;
14973: if ($otheremails =~ /,/) {
14974: @others = split(/,/,$otheremails);
1.618 raeburn 14975: } else {
1.619 raeburn 14976: push(@others,$otheremails);
14977: }
14978: foreach my $addr (@others) {
14979: if (!grep(/^\Q$addr\E$/,@recipients)) {
14980: push(@recipients,$addr);
14981: }
1.618 raeburn 14982: }
14983: }
1.1298 raeburn 14984: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 14985: if ((!@recipients) && ($lastresort ne '')) {
14986: push(@recipients,$lastresort);
14987: }
14988: } elsif ($lastresort ne '') {
14989: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14990: push(@recipients,$lastresort);
14991: }
14992: }
1.1271 raeburn 14993: my $recipientlist = join(',',@recipients);
1.1270 raeburn 14994: if (wantarray) {
14995: return ($recipientlist,$allbcc,$addtext);
14996: } else {
14997: return $recipientlist;
14998: }
1.618 raeburn 14999: }
15000:
1.127 matthew 15001: ############################################################
15002: ############################################################
1.154 albertel 15003:
1.655 raeburn 15004: =pod
15005:
1.1224 musolffc 15006: =over 4
15007:
1.1223 musolffc 15008: =item * &mime_email()
15009:
15010: Sends an email with a possible attachment
15011:
15012: Inputs:
15013:
15014: =over 4
15015:
15016: from - Sender's email address
15017:
15018: to - Email address of recipient
15019:
15020: subject - Subject of email
15021:
15022: body - Body of email
15023:
15024: cc_string - Carbon copy email address
15025:
15026: bcc - Blind carbon copy email address
15027:
15028: type - File type of attachment
15029:
15030: attachment_path - Path of file to be attached
15031:
15032: file_name - Name of file to be attached
15033:
15034: attachment_text - The body of an attachment of type "TEXT"
15035:
15036: =back
15037:
15038: =back
15039:
15040: =cut
15041:
15042: ############################################################
15043: ############################################################
15044:
15045: sub mime_email {
15046: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
15047: $file_name, $attachment_text) = @_;
15048: my $msg = MIME::Lite->new(
15049: From => $from,
15050: To => $to,
15051: Subject => $subject,
15052: Type =>'TEXT',
15053: Data => $body,
15054: );
15055: if ($cc_string ne '') {
15056: $msg->add("Cc" => $cc_string);
15057: }
15058: if ($bcc ne '') {
15059: $msg->add("Bcc" => $bcc);
15060: }
15061: $msg->attr("content-type" => "text/plain");
15062: $msg->attr("content-type.charset" => "UTF-8");
15063: # Attach file if given
15064: if ($attachment_path) {
15065: unless ($file_name) {
15066: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
15067: }
15068: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
15069: $msg->attach(Type => $type,
15070: Path => $attachment_path,
15071: Filename => $file_name
15072: );
15073: # Otherwise attach text if given
15074: } elsif ($attachment_text) {
15075: $msg->attach(Type => 'TEXT',
15076: Data => $attachment_text);
15077: }
15078: # Send it
15079: $msg->send('sendmail');
15080: }
15081:
15082: ############################################################
15083: ############################################################
15084:
15085: =pod
15086:
1.655 raeburn 15087: =head1 Course Catalog Routines
15088:
15089: =over 4
15090:
15091: =item * &gather_categories()
15092:
15093: Converts category definitions - keys of categories hash stored in
15094: coursecategories in configuration.db on the primary library server in a
15095: domain - to an array. Also generates javascript and idx hash used to
15096: generate Domain Coordinator interface for editing Course Categories.
15097:
15098: Inputs:
1.663 raeburn 15099:
1.655 raeburn 15100: categories (reference to hash of category definitions).
1.663 raeburn 15101:
1.655 raeburn 15102: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15103: categories and subcategories).
1.663 raeburn 15104:
1.655 raeburn 15105: idx (reference to hash of counters used in Domain Coordinator interface for
15106: editing Course Categories).
1.663 raeburn 15107:
1.655 raeburn 15108: jsarray (reference to array of categories used to create Javascript arrays for
15109: Domain Coordinator interface for editing Course Categories).
15110:
15111: Returns: nothing
15112:
15113: Side effects: populates cats, idx and jsarray.
15114:
15115: =cut
15116:
15117: sub gather_categories {
15118: my ($categories,$cats,$idx,$jsarray) = @_;
15119: my %counters;
15120: my $num = 0;
15121: foreach my $item (keys(%{$categories})) {
15122: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15123: if ($container eq '' && $depth == 0) {
15124: $cats->[$depth][$categories->{$item}] = $cat;
15125: } else {
15126: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15127: }
15128: my ($escitem,$tail) = split(/:/,$item,2);
15129: if ($counters{$tail} eq '') {
15130: $counters{$tail} = $num;
15131: $num ++;
15132: }
15133: if (ref($idx) eq 'HASH') {
15134: $idx->{$item} = $counters{$tail};
15135: }
15136: if (ref($jsarray) eq 'ARRAY') {
15137: push(@{$jsarray->[$counters{$tail}]},$item);
15138: }
15139: }
15140: return;
15141: }
15142:
15143: =pod
15144:
15145: =item * &extract_categories()
15146:
15147: Used to generate breadcrumb trails for course categories.
15148:
15149: Inputs:
1.663 raeburn 15150:
1.655 raeburn 15151: categories (reference to hash of category definitions).
1.663 raeburn 15152:
1.655 raeburn 15153: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15154: categories and subcategories).
1.663 raeburn 15155:
1.655 raeburn 15156: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15157:
1.655 raeburn 15158: allitems (reference to hash - key is category key
15159: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15160:
1.655 raeburn 15161: idx (reference to hash of counters used in Domain Coordinator interface for
15162: editing Course Categories).
1.663 raeburn 15163:
1.655 raeburn 15164: jsarray (reference to array of categories used to create Javascript arrays for
15165: Domain Coordinator interface for editing Course Categories).
15166:
1.665 raeburn 15167: subcats (reference to hash of arrays containing all subcategories within each
15168: category, -recursive)
15169:
1.655 raeburn 15170: Returns: nothing
15171:
15172: Side effects: populates trails and allitems hash references.
15173:
15174: =cut
15175:
15176: sub extract_categories {
1.665 raeburn 15177: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 15178: if (ref($categories) eq 'HASH') {
15179: &gather_categories($categories,$cats,$idx,$jsarray);
15180: if (ref($cats->[0]) eq 'ARRAY') {
15181: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15182: my $name = $cats->[0][$i];
15183: my $item = &escape($name).'::0';
15184: my $trailstr;
15185: if ($name eq 'instcode') {
15186: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15187: } elsif ($name eq 'communities') {
15188: $trailstr = &mt('Communities');
1.1239 raeburn 15189: } elsif ($name eq 'placement') {
15190: $trailstr = &mt('Placement Tests');
1.655 raeburn 15191: } else {
15192: $trailstr = $name;
15193: }
15194: if ($allitems->{$item} eq '') {
15195: push(@{$trails},$trailstr);
15196: $allitems->{$item} = scalar(@{$trails})-1;
15197: }
15198: my @parents = ($name);
15199: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15200: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15201: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15202: if (ref($subcats) eq 'HASH') {
15203: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15204: }
15205: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
15206: }
15207: } else {
15208: if (ref($subcats) eq 'HASH') {
15209: $subcats->{$item} = [];
1.655 raeburn 15210: }
15211: }
15212: }
15213: }
15214: }
15215: return;
15216: }
15217:
15218: =pod
15219:
1.1162 raeburn 15220: =item * &recurse_categories()
1.655 raeburn 15221:
15222: Recursively used to generate breadcrumb trails for course categories.
15223:
15224: Inputs:
1.663 raeburn 15225:
1.655 raeburn 15226: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15227: categories and subcategories).
1.663 raeburn 15228:
1.655 raeburn 15229: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15230:
15231: category (current course category, for which breadcrumb trail is being generated).
15232:
15233: trails (reference to array of breadcrumb trails for each category).
15234:
1.655 raeburn 15235: allitems (reference to hash - key is category key
15236: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15237:
1.655 raeburn 15238: parents (array containing containers directories for current category,
15239: back to top level).
15240:
15241: Returns: nothing
15242:
15243: Side effects: populates trails and allitems hash references
15244:
15245: =cut
15246:
15247: sub recurse_categories {
1.665 raeburn 15248: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 15249: my $shallower = $depth - 1;
15250: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
15251: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
15252: my $name = $cats->[$depth]{$category}[$k];
15253: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
15254: my $trailstr = join(' -> ',(@{$parents},$category));
15255: if ($allitems->{$item} eq '') {
15256: push(@{$trails},$trailstr);
15257: $allitems->{$item} = scalar(@{$trails})-1;
15258: }
15259: my $deeper = $depth+1;
15260: push(@{$parents},$category);
1.665 raeburn 15261: if (ref($subcats) eq 'HASH') {
15262: my $subcat = &escape($name).':'.$category.':'.$depth;
15263: for (my $j=@{$parents}; $j>=0; $j--) {
15264: my $higher;
15265: if ($j > 0) {
15266: $higher = &escape($parents->[$j]).':'.
15267: &escape($parents->[$j-1]).':'.$j;
15268: } else {
15269: $higher = &escape($parents->[$j]).'::'.$j;
15270: }
15271: push(@{$subcats->{$higher}},$subcat);
15272: }
15273: }
15274: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
15275: $subcats);
1.655 raeburn 15276: pop(@{$parents});
15277: }
15278: } else {
15279: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
15280: my $trailstr = join(' -> ',(@{$parents},$category));
15281: if ($allitems->{$item} eq '') {
15282: push(@{$trails},$trailstr);
15283: $allitems->{$item} = scalar(@{$trails})-1;
15284: }
15285: }
15286: return;
15287: }
15288:
1.663 raeburn 15289: =pod
15290:
1.1162 raeburn 15291: =item * &assign_categories_table()
1.663 raeburn 15292:
15293: Create a datatable for display of hierarchical categories in a domain,
15294: with checkboxes to allow a course to be categorized.
15295:
15296: Inputs:
15297:
15298: cathash - reference to hash of categories defined for the domain (from
15299: configuration.db)
15300:
15301: currcat - scalar with an & separated list of categories assigned to a course.
15302:
1.919 raeburn 15303: type - scalar contains course type (Course or Community).
15304:
1.1260 raeburn 15305: disabled - scalar (optional) contains disabled="disabled" if input elements are
15306: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15307:
1.663 raeburn 15308: Returns: $output (markup to be displayed)
15309:
15310: =cut
15311:
15312: sub assign_categories_table {
1.1259 raeburn 15313: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15314: my $output;
15315: if (ref($cathash) eq 'HASH') {
15316: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
15317: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
15318: $maxdepth = scalar(@cats);
15319: if (@cats > 0) {
15320: my $itemcount = 0;
15321: if (ref($cats[0]) eq 'ARRAY') {
15322: my @currcategories;
15323: if ($currcat ne '') {
15324: @currcategories = split('&',$currcat);
15325: }
1.919 raeburn 15326: my $table;
1.663 raeburn 15327: for (my $i=0; $i<@{$cats[0]}; $i++) {
15328: my $parent = $cats[0][$i];
1.919 raeburn 15329: next if ($parent eq 'instcode');
15330: if ($type eq 'Community') {
15331: next unless ($parent eq 'communities');
1.1239 raeburn 15332: } elsif ($type eq 'Placement') {
15333: next unless ($parent eq 'placement');
1.919 raeburn 15334: } else {
1.1239 raeburn 15335: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15336: }
1.663 raeburn 15337: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15338: my $item = &escape($parent).'::0';
15339: my $checked = '';
15340: if (@currcategories > 0) {
15341: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15342: $checked = ' checked="checked"';
1.663 raeburn 15343: }
15344: }
1.919 raeburn 15345: my $parent_title = $parent;
15346: if ($parent eq 'communities') {
15347: $parent_title = &mt('Communities');
1.1239 raeburn 15348: } elsif ($parent eq 'placement') {
15349: $parent_title = &mt('Placement Tests');
1.919 raeburn 15350: }
15351: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15352: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15353: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15354: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15355: my $depth = 1;
15356: push(@path,$parent);
1.1259 raeburn 15357: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15358: pop(@path);
1.919 raeburn 15359: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15360: $itemcount ++;
15361: }
1.919 raeburn 15362: if ($itemcount) {
15363: $output = &Apache::loncommon::start_data_table().
15364: $table.
15365: &Apache::loncommon::end_data_table();
15366: }
1.663 raeburn 15367: }
15368: }
15369: }
15370: return $output;
15371: }
15372:
15373: =pod
15374:
1.1162 raeburn 15375: =item * &assign_category_rows()
1.663 raeburn 15376:
15377: Create a datatable row for display of nested categories in a domain,
15378: with checkboxes to allow a course to be categorized,called recursively.
15379:
15380: Inputs:
15381:
15382: itemcount - track row number for alternating colors
15383:
15384: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15385: categories and subcategories.
15386:
15387: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15388:
15389: parent - parent of current category item
15390:
15391: path - Array containing all categories back up through the hierarchy from the
15392: current category to the top level.
15393:
15394: currcategories - reference to array of current categories assigned to the course
15395:
1.1260 raeburn 15396: disabled - scalar (optional) contains disabled="disabled" if input elements are
15397: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15398:
1.663 raeburn 15399: Returns: $output (markup to be displayed).
15400:
15401: =cut
15402:
15403: sub assign_category_rows {
1.1259 raeburn 15404: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15405: my ($text,$name,$item,$chgstr);
15406: if (ref($cats) eq 'ARRAY') {
15407: my $maxdepth = scalar(@{$cats});
15408: if (ref($cats->[$depth]) eq 'HASH') {
15409: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15410: my $numchildren = @{$cats->[$depth]{$parent}};
15411: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 15412: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15413: for (my $j=0; $j<$numchildren; $j++) {
15414: $name = $cats->[$depth]{$parent}[$j];
15415: $item = &escape($name).':'.&escape($parent).':'.$depth;
15416: my $deeper = $depth+1;
15417: my $checked = '';
15418: if (ref($currcategories) eq 'ARRAY') {
15419: if (@{$currcategories} > 0) {
15420: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15421: $checked = ' checked="checked"';
1.663 raeburn 15422: }
15423: }
15424: }
1.664 raeburn 15425: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15426: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15427: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15428: '<input type="hidden" name="catname" value="'.$name.'" />'.
15429: '</td><td>';
1.663 raeburn 15430: if (ref($path) eq 'ARRAY') {
15431: push(@{$path},$name);
1.1259 raeburn 15432: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15433: pop(@{$path});
15434: }
15435: $text .= '</td></tr>';
15436: }
15437: $text .= '</table></td>';
15438: }
15439: }
15440: }
15441: return $text;
15442: }
15443:
1.1181 raeburn 15444: =pod
15445:
15446: =back
15447:
15448: =cut
15449:
1.655 raeburn 15450: ############################################################
15451: ############################################################
15452:
15453:
1.443 albertel 15454: sub commit_customrole {
1.664 raeburn 15455: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15456: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15457: ($start?', '.&mt('starting').' '.localtime($start):'').
15458: ($end?', ending '.localtime($end):'').': <b>'.
15459: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15460: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15461: '</b><br />';
15462: return $output;
15463: }
15464:
15465: sub commit_standardrole {
1.1116 raeburn 15466: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15467: my ($output,$logmsg,$linefeed);
15468: if ($context eq 'auto') {
15469: $linefeed = "\n";
15470: } else {
15471: $linefeed = "<br />\n";
15472: }
1.443 albertel 15473: if ($three eq 'st') {
1.541 raeburn 15474: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 15475: $one,$two,$sec,$context,$credits);
1.541 raeburn 15476: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15477: ($result eq 'unknown_course') || ($result eq 'refused')) {
15478: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15479: } else {
1.541 raeburn 15480: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15481: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15482: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15483: if ($context eq 'auto') {
15484: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15485: } else {
15486: $output .= '<b>'.$result.'</b>'.$linefeed.
15487: &mt('Add to classlist').': <b>ok</b>';
15488: }
15489: $output .= $linefeed;
1.443 albertel 15490: }
15491: } else {
15492: $output = &mt('Assigning').' '.$three.' in '.$url.
15493: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15494: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15495: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15496: if ($context eq 'auto') {
15497: $output .= $result.$linefeed;
15498: } else {
15499: $output .= '<b>'.$result.'</b>'.$linefeed;
15500: }
1.443 albertel 15501: }
15502: return $output;
15503: }
15504:
15505: sub commit_studentrole {
1.1116 raeburn 15506: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15507: $credits) = @_;
1.626 raeburn 15508: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15509: if ($context eq 'auto') {
15510: $linefeed = "\n";
15511: } else {
15512: $linefeed = '<br />'."\n";
15513: }
1.443 albertel 15514: if (defined($one) && defined($two)) {
15515: my $cid=$one.'_'.$two;
15516: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15517: my $secchange = 0;
15518: my $expire_role_result;
15519: my $modify_section_result;
1.628 raeburn 15520: if ($oldsec ne '-1') {
15521: if ($oldsec ne $sec) {
1.443 albertel 15522: $secchange = 1;
1.628 raeburn 15523: my $now = time;
1.443 albertel 15524: my $uurl='/'.$cid;
15525: $uurl=~s/\_/\//g;
15526: if ($oldsec) {
15527: $uurl.='/'.$oldsec;
15528: }
1.626 raeburn 15529: $oldsecurl = $uurl;
1.628 raeburn 15530: $expire_role_result =
1.652 raeburn 15531: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15532: if ($env{'request.course.sec'} ne '') {
15533: if ($expire_role_result eq 'refused') {
15534: my @roles = ('st');
15535: my @statuses = ('previous');
15536: my @roledoms = ($one);
15537: my $withsec = 1;
15538: my %roleshash =
15539: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15540: \@statuses,\@roles,\@roledoms,$withsec);
15541: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15542: my ($oldstart,$oldend) =
15543: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15544: if ($oldend > 0 && $oldend <= $now) {
15545: $expire_role_result = 'ok';
15546: }
15547: }
15548: }
15549: }
1.443 albertel 15550: $result = $expire_role_result;
15551: }
15552: }
15553: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15554: $modify_section_result =
15555: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15556: undef,undef,undef,$sec,
15557: $end,$start,'','',$cid,
15558: '',$context,$credits);
1.443 albertel 15559: if ($modify_section_result =~ /^ok/) {
15560: if ($secchange == 1) {
1.628 raeburn 15561: if ($sec eq '') {
15562: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15563: } else {
15564: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15565: }
1.443 albertel 15566: } elsif ($oldsec eq '-1') {
1.628 raeburn 15567: if ($sec eq '') {
15568: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15569: } else {
15570: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15571: }
1.443 albertel 15572: } else {
1.628 raeburn 15573: if ($sec eq '') {
15574: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15575: } else {
15576: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15577: }
1.443 albertel 15578: }
15579: } else {
1.1115 raeburn 15580: if ($secchange) {
1.628 raeburn 15581: $$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;
15582: } else {
15583: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15584: }
1.443 albertel 15585: }
15586: $result = $modify_section_result;
15587: } elsif ($secchange == 1) {
1.628 raeburn 15588: if ($oldsec eq '') {
1.1103 raeburn 15589: $$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 15590: } else {
15591: $$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;
15592: }
1.626 raeburn 15593: if ($expire_role_result eq 'refused') {
15594: my $newsecurl = '/'.$cid;
15595: $newsecurl =~ s/\_/\//g;
15596: if ($sec ne '') {
15597: $newsecurl.='/'.$sec;
15598: }
15599: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15600: if ($sec eq '') {
15601: $$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;
15602: } else {
15603: $$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;
15604: }
15605: }
15606: }
1.443 albertel 15607: }
15608: } else {
1.626 raeburn 15609: $$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 15610: $result = "error: incomplete course id\n";
15611: }
15612: return $result;
15613: }
15614:
1.1108 raeburn 15615: sub show_role_extent {
15616: my ($scope,$context,$role) = @_;
15617: $scope =~ s{^/}{};
15618: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15619: push(@courseroles,'co');
15620: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15621: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15622: $scope =~ s{/}{_};
15623: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15624: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15625: my ($audom,$auname) = split(/\//,$scope);
15626: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15627: &Apache::loncommon::plainname($auname,$audom).'</span>');
15628: } else {
15629: $scope =~ s{/$}{};
15630: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15631: &Apache::lonnet::domain($scope,'description').'</span>');
15632: }
15633: }
15634:
1.443 albertel 15635: ############################################################
15636: ############################################################
15637:
1.566 albertel 15638: sub check_clone {
1.578 raeburn 15639: my ($args,$linefeed) = @_;
1.566 albertel 15640: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15641: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15642: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15643: my $clonemsg;
15644: my $can_clone = 0;
1.944 raeburn 15645: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15646: if ($lctype ne 'community') {
15647: $lctype = 'course';
15648: }
1.566 albertel 15649: if ($clonehome eq 'no_host') {
1.944 raeburn 15650: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15651: $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'});
15652: } else {
15653: $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'});
15654: }
1.566 albertel 15655: } else {
15656: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15657: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15658: if ($clonedesc{'type'} ne 'Community') {
1.1262 raeburn 15659: $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 15660: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15661: }
15662: }
1.1262 raeburn 15663: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15664: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15665: $can_clone = 1;
15666: } else {
1.1221 raeburn 15667: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15668: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 15669: if ($clonehash{'cloners'} eq '') {
15670: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15671: if ($domdefs{'canclone'}) {
15672: unless ($domdefs{'canclone'} eq 'none') {
15673: if ($domdefs{'canclone'} eq 'domain') {
15674: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15675: $can_clone = 1;
15676: }
15677: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15678: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15679: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15680: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15681: $can_clone = 1;
15682: }
15683: }
15684: }
15685: }
1.578 raeburn 15686: } else {
1.1221 raeburn 15687: my @cloners = split(/,/,$clonehash{'cloners'});
15688: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15689: $can_clone = 1;
1.1221 raeburn 15690: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15691: $can_clone = 1;
1.1225 raeburn 15692: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15693: $can_clone = 1;
1.1221 raeburn 15694: }
15695: unless ($can_clone) {
1.1225 raeburn 15696: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15697: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 15698: my (%gotdomdefaults,%gotcodedefaults);
15699: foreach my $cloner (@cloners) {
15700: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15701: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15702: my (%codedefaults,@code_order);
15703: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15704: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15705: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15706: }
15707: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15708: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15709: }
15710: } else {
15711: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15712: \%codedefaults,
15713: \@code_order);
15714: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15715: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15716: }
15717: if (@code_order > 0) {
15718: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15719: $cloner,$clonehash{'internal.coursecode'},
15720: $args->{'crscode'})) {
15721: $can_clone = 1;
15722: last;
15723: }
15724: }
15725: }
15726: }
15727: }
1.1225 raeburn 15728: }
15729: }
15730: unless ($can_clone) {
15731: my $ccrole = 'cc';
15732: if ($args->{'crstype'} eq 'Community') {
15733: $ccrole = 'co';
15734: }
15735: my %roleshash =
15736: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15737: $args->{'ccdomain'},
15738: 'userroles',['active'],[$ccrole],
15739: [$args->{'clonedomain'}]);
15740: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15741: $can_clone = 1;
15742: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15743: $args->{'ccuname'},$args->{'ccdomain'})) {
15744: $can_clone = 1;
1.1221 raeburn 15745: }
15746: }
15747: unless ($can_clone) {
15748: if ($args->{'crstype'} eq 'Community') {
15749: $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 15750: } else {
1.1221 raeburn 15751: $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'});
15752: }
1.566 albertel 15753: }
1.578 raeburn 15754: }
1.566 albertel 15755: }
15756: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15757: }
15758:
1.444 albertel 15759: sub construct_course {
1.1262 raeburn 15760: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15761: $cnum,$category,$coderef) = @_;
1.444 albertel 15762: my $outcome;
1.541 raeburn 15763: my $linefeed = '<br />'."\n";
15764: if ($context eq 'auto') {
15765: $linefeed = "\n";
15766: }
1.566 albertel 15767:
15768: #
15769: # Are we cloning?
15770: #
15771: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15772: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15773: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15774: if ($context ne 'auto') {
1.578 raeburn 15775: if ($clonemsg ne '') {
15776: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15777: }
1.566 albertel 15778: }
15779: $outcome .= $clonemsg.$linefeed;
15780:
15781: if (!$can_clone) {
15782: return (0,$outcome);
15783: }
15784: }
15785:
1.444 albertel 15786: #
15787: # Open course
15788: #
1.1239 raeburn 15789: my $showncrstype;
15790: if ($args->{'crstype'} eq 'Placement') {
15791: $showncrstype = 'placement test';
15792: } else {
15793: $showncrstype = lc($args->{'crstype'});
15794: }
1.444 albertel 15795: my %cenv=();
15796: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15797: $args->{'cdescr'},
15798: $args->{'curl'},
15799: $args->{'course_home'},
15800: $args->{'nonstandard'},
15801: $args->{'crscode'},
15802: $args->{'ccuname'}.':'.
15803: $args->{'ccdomain'},
1.882 raeburn 15804: $args->{'crstype'},
1.885 raeburn 15805: $cnum,$context,$category);
1.444 albertel 15806:
15807: # Note: The testing routines depend on this being output; see
15808: # Utils::Course. This needs to at least be output as a comment
15809: # if anyone ever decides to not show this, and Utils::Course::new
15810: # will need to be suitably modified.
1.1239 raeburn 15811: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
1.943 raeburn 15812: if ($$courseid =~ /^error:/) {
15813: return (0,$outcome);
15814: }
15815:
1.444 albertel 15816: #
15817: # Check if created correctly
15818: #
1.479 albertel 15819: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15820: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15821: if ($crsuhome eq 'no_host') {
15822: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15823: return (0,$outcome);
15824: }
1.541 raeburn 15825: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15826:
1.444 albertel 15827: #
1.566 albertel 15828: # Do the cloning
15829: #
15830: if ($can_clone && $cloneid) {
1.1239 raeburn 15831: $clonemsg = &mt('Cloning [_1] from [_2]',$showncrstype,$clonehome);
1.566 albertel 15832: if ($context ne 'auto') {
15833: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15834: }
15835: $outcome .= $clonemsg.$linefeed;
15836: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15837: # Copy all files
1.637 www 15838: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15839: # Restore URL
1.566 albertel 15840: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15841: # Restore title
1.566 albertel 15842: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15843: # Restore creation date, creator and creation context.
15844: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15845: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15846: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15847: # Mark as cloned
1.566 albertel 15848: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15849: # Need to clone grading mode
15850: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15851: $cenv{'grading'}=$newenv{'grading'};
15852: # Do not clone these environment entries
15853: &Apache::lonnet::del('environment',
15854: ['default_enrollment_start_date',
15855: 'default_enrollment_end_date',
15856: 'question.email',
15857: 'policy.email',
15858: 'comment.email',
15859: 'pch.users.denied',
1.725 raeburn 15860: 'plc.users.denied',
15861: 'hidefromcat',
1.1121 raeburn 15862: 'checkforpriv',
1.1166 raeburn 15863: 'categories',
15864: 'internal.uniquecode'],
1.638 www 15865: $$crsudom,$$crsunum);
1.1170 raeburn 15866: if ($args->{'textbook'}) {
15867: $cenv{'internal.textbook'} = $args->{'textbook'};
15868: }
1.444 albertel 15869: }
1.566 albertel 15870:
1.444 albertel 15871: #
15872: # Set environment (will override cloned, if existing)
15873: #
15874: my @sections = ();
15875: my @xlists = ();
15876: if ($args->{'crstype'}) {
15877: $cenv{'type'}=$args->{'crstype'};
15878: }
15879: if ($args->{'crsid'}) {
15880: $cenv{'courseid'}=$args->{'crsid'};
15881: }
15882: if ($args->{'crscode'}) {
15883: $cenv{'internal.coursecode'}=$args->{'crscode'};
15884: }
15885: if ($args->{'crsquota'} ne '') {
15886: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15887: } else {
15888: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15889: }
15890: if ($args->{'ccuname'}) {
15891: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15892: ':'.$args->{'ccdomain'};
15893: } else {
15894: $cenv{'internal.courseowner'} = $args->{'curruser'};
15895: }
1.1116 raeburn 15896: if ($args->{'defaultcredits'}) {
15897: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15898: }
1.444 albertel 15899: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15900: if ($args->{'crssections'}) {
15901: $cenv{'internal.sectionnums'} = '';
15902: if ($args->{'crssections'} =~ m/,/) {
15903: @sections = split/,/,$args->{'crssections'};
15904: } else {
15905: $sections[0] = $args->{'crssections'};
15906: }
15907: if (@sections > 0) {
15908: foreach my $item (@sections) {
15909: my ($sec,$gp) = split/:/,$item;
15910: my $class = $args->{'crscode'}.$sec;
15911: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15912: $cenv{'internal.sectionnums'} .= $item.',';
15913: unless ($addcheck eq 'ok') {
1.1263 raeburn 15914: push(@badclasses,$class);
1.444 albertel 15915: }
15916: }
15917: $cenv{'internal.sectionnums'} =~ s/,$//;
15918: }
15919: }
15920: # do not hide course coordinator from staff listing,
15921: # even if privileged
15922: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 15923: # add course coordinator's domain to domains to check for privileged users
15924: # if different to course domain
15925: if ($$crsudom ne $args->{'ccdomain'}) {
15926: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15927: }
1.444 albertel 15928: # add crosslistings
15929: if ($args->{'crsxlist'}) {
15930: $cenv{'internal.crosslistings'}='';
15931: if ($args->{'crsxlist'} =~ m/,/) {
15932: @xlists = split/,/,$args->{'crsxlist'};
15933: } else {
15934: $xlists[0] = $args->{'crsxlist'};
15935: }
15936: if (@xlists > 0) {
15937: foreach my $item (@xlists) {
15938: my ($xl,$gp) = split/:/,$item;
15939: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15940: $cenv{'internal.crosslistings'} .= $item.',';
15941: unless ($addcheck eq 'ok') {
1.1263 raeburn 15942: push(@badclasses,$xl);
1.444 albertel 15943: }
15944: }
15945: $cenv{'internal.crosslistings'} =~ s/,$//;
15946: }
15947: }
15948: if ($args->{'autoadds'}) {
15949: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15950: }
15951: if ($args->{'autodrops'}) {
15952: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15953: }
15954: # check for notification of enrollment changes
15955: my @notified = ();
15956: if ($args->{'notify_owner'}) {
15957: if ($args->{'ccuname'} ne '') {
15958: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15959: }
15960: }
15961: if ($args->{'notify_dc'}) {
15962: if ($uname ne '') {
1.630 raeburn 15963: push(@notified,$uname.':'.$udom);
1.444 albertel 15964: }
15965: }
15966: if (@notified > 0) {
15967: my $notifylist;
15968: if (@notified > 1) {
15969: $notifylist = join(',',@notified);
15970: } else {
15971: $notifylist = $notified[0];
15972: }
15973: $cenv{'internal.notifylist'} = $notifylist;
15974: }
15975: if (@badclasses > 0) {
15976: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 15977: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15978: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15979: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15980: );
1.1264 raeburn 15981: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15982: &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 15983: if ($context eq 'auto') {
15984: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 15985: } else {
1.566 albertel 15986: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 15987: }
15988: foreach my $item (@badclasses) {
1.541 raeburn 15989: if ($context eq 'auto') {
1.1261 raeburn 15990: $outcome .= " - $item\n";
1.541 raeburn 15991: } else {
1.1261 raeburn 15992: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15993: }
1.1261 raeburn 15994: }
15995: if ($context eq 'auto') {
15996: $outcome .= $linefeed;
15997: } else {
15998: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 15999: }
1.444 albertel 16000: }
16001: if ($args->{'no_end_date'}) {
16002: $args->{'endaccess'} = 0;
16003: }
16004: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16005: $cenv{'internal.autoend'}=$args->{'enrollend'};
16006: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16007: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16008: if ($args->{'showphotos'}) {
16009: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16010: }
16011: $cenv{'internal.authtype'} = $args->{'authtype'};
16012: $cenv{'internal.autharg'} = $args->{'autharg'};
16013: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16014: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16015: 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');
16016: if ($context eq 'auto') {
16017: $outcome .= $krb_msg;
16018: } else {
1.566 albertel 16019: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16020: }
16021: $outcome .= $linefeed;
1.444 albertel 16022: }
16023: }
16024: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16025: if ($args->{'setpolicy'}) {
16026: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16027: }
16028: if ($args->{'setcontent'}) {
16029: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16030: }
1.1251 raeburn 16031: if ($args->{'setcomment'}) {
16032: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16033: }
1.444 albertel 16034: }
16035: if ($args->{'reshome'}) {
16036: $cenv{'reshome'}=$args->{'reshome'}.'/';
16037: $cenv{'reshome'}=~s/\/+$/\//;
16038: }
16039: #
16040: # course has keyed access
16041: #
16042: if ($args->{'setkeys'}) {
16043: $cenv{'keyaccess'}='yes';
16044: }
16045: # if specified, key authority is not course, but user
16046: # only active if keyaccess is yes
16047: if ($args->{'keyauth'}) {
1.487 albertel 16048: my ($user,$domain) = split(':',$args->{'keyauth'});
16049: $user = &LONCAPA::clean_username($user);
16050: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16051: if ($user ne '' && $domain ne '') {
1.487 albertel 16052: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16053: }
16054: }
16055:
1.1166 raeburn 16056: #
1.1167 raeburn 16057: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 16058: #
16059: if ($args->{'uniquecode'}) {
16060: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16061: if ($code) {
16062: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 16063: my %crsinfo =
16064: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16065: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16066: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16067: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16068: }
1.1166 raeburn 16069: if (ref($coderef)) {
16070: $$coderef = $code;
16071: }
16072: }
16073: }
16074:
1.444 albertel 16075: if ($args->{'disresdis'}) {
16076: $cenv{'pch.roles.denied'}='st';
16077: }
16078: if ($args->{'disablechat'}) {
16079: $cenv{'plc.roles.denied'}='st';
16080: }
16081:
16082: # Record we've not yet viewed the Course Initialization Helper for this
16083: # course
16084: $cenv{'course.helper.not.run'} = 1;
16085: #
16086: # Use new Randomseed
16087: #
16088: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16089: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16090: #
16091: # The encryption code and receipt prefix for this course
16092: #
16093: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16094: $cenv{'internal.encpref'}=100+int(9*rand(99));
16095: #
16096: # By default, use standard grading
16097: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16098:
1.541 raeburn 16099: $outcome .= $linefeed.&mt('Setting environment').': '.
16100: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16101: #
16102: # Open all assignments
16103: #
16104: if ($args->{'openall'}) {
16105: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
16106: my %storecontent = ($storeunder => time,
16107: $storeunder.'.type' => 'date_start');
16108:
16109: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 16110: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16111: }
16112: #
16113: # Set first page
16114: #
16115: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16116: || ($cloneid)) {
1.445 albertel 16117: use LONCAPA::map;
1.444 albertel 16118: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16119:
16120: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16121: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16122:
1.444 albertel 16123: $outcome .= ($fatal?$errtext:'read ok').' - ';
16124: my $title; my $url;
16125: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16126: $title=&mt('Syllabus');
1.444 albertel 16127: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16128: } else {
1.963 raeburn 16129: $title=&mt('Table of Contents');
1.444 albertel 16130: $url='/adm/navmaps';
16131: }
1.445 albertel 16132:
16133: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16134: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16135:
16136: if ($errtext) { $fatal=2; }
1.541 raeburn 16137: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16138: }
1.566 albertel 16139:
1.1237 raeburn 16140: #
16141: # Set params for Placement Tests
16142: #
1.1239 raeburn 16143: if ($args->{'crstype'} eq 'Placement') {
16144: my %storecontent;
16145: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
16146: my %defaults = (
16147: buttonshide => { value => 'yes',
16148: type => 'string_yesno',},
16149: type => { value => 'randomizetry',
16150: type => 'string_questiontype',},
16151: maxtries => { value => 1,
16152: type => 'int_pos',},
16153: problemstatus => { value => 'no',
16154: type => 'string_problemstatus',},
16155: );
16156: foreach my $key (keys(%defaults)) {
16157: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
16158: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
16159: }
1.1237 raeburn 16160: &Apache::lonnet::cput
16161: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
16162: }
16163:
1.566 albertel 16164: return (1,$outcome);
1.444 albertel 16165: }
16166:
1.1166 raeburn 16167: sub make_unique_code {
16168: my ($cdom,$cnum) = @_;
16169: # get lock on uniquecodes db
16170: my $lockhash = {
16171: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16172: ':'.$env{'user.domain'},
16173: };
16174: my $tries = 0;
16175: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16176: my ($code,$error);
16177:
16178: while (($gotlock ne 'ok') && ($tries<3)) {
16179: $tries ++;
16180: sleep 1;
16181: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16182: }
16183: if ($gotlock eq 'ok') {
16184: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16185: my $gotcode;
16186: my $attempts = 0;
16187: while ((!$gotcode) && ($attempts < 100)) {
16188: $code = &generate_code();
16189: if (!exists($currcodes{$code})) {
16190: $gotcode = 1;
16191: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
16192: $error = 'nostore';
16193: }
16194: }
16195: $attempts ++;
16196: }
16197: my @del_lock = ($cnum."\0".'uniquecodes');
16198: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
16199: } else {
16200: $error = 'nolock';
16201: }
16202: return ($code,$error);
16203: }
16204:
16205: sub generate_code {
16206: my $code;
16207: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
16208: for (my $i=0; $i<6; $i++) {
16209: my $lettnum = int (rand 2);
16210: my $item = '';
16211: if ($lettnum) {
16212: $item = $letts[int( rand(18) )];
16213: } else {
16214: $item = 1+int( rand(8) );
16215: }
16216: $code .= $item;
16217: }
16218: return $code;
16219: }
16220:
1.444 albertel 16221: ############################################################
16222: ############################################################
16223:
1.1237 raeburn 16224: # Community, Course and Placement Test
1.378 raeburn 16225: sub course_type {
16226: my ($cid) = @_;
16227: if (!defined($cid)) {
16228: $cid = $env{'request.course.id'};
16229: }
1.404 albertel 16230: if (defined($env{'course.'.$cid.'.type'})) {
16231: return $env{'course.'.$cid.'.type'};
1.378 raeburn 16232: } else {
16233: return 'Course';
1.377 raeburn 16234: }
16235: }
1.156 albertel 16236:
1.406 raeburn 16237: sub group_term {
16238: my $crstype = &course_type();
16239: my %names = (
16240: 'Course' => 'group',
1.865 raeburn 16241: 'Community' => 'group',
1.1237 raeburn 16242: 'Placement' => 'group',
1.406 raeburn 16243: );
16244: return $names{$crstype};
16245: }
16246:
1.902 raeburn 16247: sub course_types {
1.1310 raeburn 16248: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 16249: my %typename = (
16250: official => 'Official course',
16251: unofficial => 'Unofficial course',
16252: community => 'Community',
1.1165 raeburn 16253: textbook => 'Textbook course',
1.1237 raeburn 16254: placement => 'Placement test',
1.1310 raeburn 16255: lti => 'LTI provider',
1.902 raeburn 16256: );
16257: return (\@types,\%typename);
16258: }
16259:
1.156 albertel 16260: sub icon {
16261: my ($file)=@_;
1.505 albertel 16262: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 16263: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 16264: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 16265: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
16266: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
16267: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16268: $curfext.".gif") {
16269: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16270: $curfext.".gif";
16271: }
16272: }
1.249 albertel 16273: return &lonhttpdurl($iconname);
1.154 albertel 16274: }
1.84 albertel 16275:
1.575 albertel 16276: sub lonhttpdurl {
1.692 www 16277: #
16278: # Had been used for "small fry" static images on separate port 8080.
16279: # Modify here if lightweight http functionality desired again.
16280: # Currently eliminated due to increasing firewall issues.
16281: #
1.575 albertel 16282: my ($url)=@_;
1.692 www 16283: return $url;
1.215 albertel 16284: }
16285:
1.213 albertel 16286: sub connection_aborted {
16287: my ($r)=@_;
16288: $r->print(" ");$r->rflush();
16289: my $c = $r->connection;
16290: return $c->aborted();
16291: }
16292:
1.221 foxr 16293: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16294: # strings as 'strings'.
16295: sub escape_single {
1.221 foxr 16296: my ($input) = @_;
1.223 albertel 16297: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16298: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16299: return $input;
16300: }
1.223 albertel 16301:
1.222 foxr 16302: # Same as escape_single, but escape's "'s This
16303: # can be used for "strings"
16304: sub escape_double {
16305: my ($input) = @_;
16306: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16307: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16308: return $input;
16309: }
1.223 albertel 16310:
1.222 foxr 16311: # Escapes the last element of a full URL.
16312: sub escape_url {
16313: my ($url) = @_;
1.238 raeburn 16314: my @urlslices = split(/\//, $url,-1);
1.369 www 16315: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 16316: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16317: }
1.462 albertel 16318:
1.820 raeburn 16319: sub compare_arrays {
16320: my ($arrayref1,$arrayref2) = @_;
16321: my (@difference,%count);
16322: @difference = ();
16323: %count = ();
16324: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16325: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16326: foreach my $element (keys(%count)) {
16327: if ($count{$element} == 1) {
16328: push(@difference,$element);
16329: }
16330: }
16331: }
16332: return @difference;
16333: }
16334:
1.817 bisitz 16335: # -------------------------------------------------------- Initialize user login
1.462 albertel 16336: sub init_user_environment {
1.463 albertel 16337: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16338: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16339:
16340: my $public=($username eq 'public' && $domain eq 'public');
16341:
1.1062 raeburn 16342: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16343: my $now=time;
16344:
16345: if ($public) {
16346: my $max_public=100;
16347: my $oldest;
16348: my $oldest_time=0;
16349: for(my $next=1;$next<=$max_public;$next++) {
16350: if (-e $lonids."/publicuser_$next.id") {
16351: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16352: if ($mtime<$oldest_time || !$oldest_time) {
16353: $oldest_time=$mtime;
16354: $oldest=$next;
16355: }
16356: } else {
16357: $cookie="publicuser_$next";
16358: last;
16359: }
16360: }
16361: if (!$cookie) { $cookie="publicuser_$oldest"; }
16362: } else {
1.1275 raeburn 16363: # See if old ID present, if so, remove if this isn't a robot,
16364: # killing any existing non-robot sessions
1.463 albertel 16365: if (!$args->{'robot'}) {
16366: opendir(DIR,$lonids);
16367: while ($filename=readdir(DIR)) {
16368: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1295 raeburn 16369: if ($ENV{'SERVER_PORT'} == 443) {
16370: my $linkedfile;
16371: if (tie(my %oldenv,'GDBM_File',"$lonids/$cookie.id",
16372: &GDBM_READER(),0640)) {
16373: if (exists($oldenv{'user.linkedenv'})) {
16374: $linkedfile = $oldenv{'user.linkedenv'};
16375: }
16376: untie(%oldenv);
16377: }
16378: if (unlink($lonids.'/'.$filename)) {
16379: if ($linkedfile =~ /^[a-f0-9]+_linked\.id$/) {
16380: unlink($lonids.'/'.$linkedfile);
16381: }
16382: }
16383: } else {
16384: unlink($lonids.'/'.$filename);
16385: }
1.463 albertel 16386: }
1.462 albertel 16387: }
1.463 albertel 16388: closedir(DIR);
1.1204 raeburn 16389: # If there is a undeleted lockfile for the user's paste buffer remove it.
16390: my $namespace = 'nohist_courseeditor';
16391: my $lockingkey = 'paste'."\0".'locked_num';
16392: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16393: $domain,$username);
16394: if (exists($lockhash{$lockingkey})) {
16395: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16396: unless ($delresult eq 'ok') {
16397: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16398: }
16399: }
1.462 albertel 16400: }
16401: # Give them a new cookie
1.463 albertel 16402: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16403: : $now.$$.int(rand(10000)));
1.463 albertel 16404: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16405:
16406: # Initialize roles
16407:
1.1062 raeburn 16408: ($userroles,$firstaccenv,$timerintenv) =
16409: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16410: }
16411: # ------------------------------------ Check browser type and MathML capability
16412:
1.1194 raeburn 16413: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16414: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16415:
16416: # ------------------------------------------------------------- Get environment
16417:
16418: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16419: my ($tmp) = keys(%userenv);
1.1275 raeburn 16420: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 16421: undef(%userenv);
16422: }
16423: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16424: $form->{'interface'}=$userenv{'interface'};
16425: }
16426: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16427:
16428: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16429: foreach my $option ('interface','localpath','localres') {
16430: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16431: }
16432: # --------------------------------------------------------- Write first profile
16433:
16434: {
16435: my %initial_env =
16436: ("user.name" => $username,
16437: "user.domain" => $domain,
16438: "user.home" => $authhost,
16439: "browser.type" => $clientbrowser,
16440: "browser.version" => $clientversion,
16441: "browser.mathml" => $clientmathml,
16442: "browser.unicode" => $clientunicode,
16443: "browser.os" => $clientos,
1.1137 raeburn 16444: "browser.mobile" => $clientmobile,
1.1141 raeburn 16445: "browser.info" => $clientinfo,
1.1194 raeburn 16446: "browser.osversion" => $clientosversion,
1.462 albertel 16447: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16448: "request.course.fn" => '',
16449: "request.course.uri" => '',
16450: "request.course.sec" => '',
16451: "request.role" => 'cm',
16452: "request.role.adv" => $env{'user.adv'},
16453: "request.host" => $ENV{'REMOTE_ADDR'},);
16454:
16455: if ($form->{'localpath'}) {
16456: $initial_env{"browser.localpath"} = $form->{'localpath'};
16457: $initial_env{"browser.localres"} = $form->{'localres'};
16458: }
16459:
16460: if ($form->{'interface'}) {
16461: $form->{'interface'}=~s/\W//gs;
16462: $initial_env{"browser.interface"} = $form->{'interface'};
16463: $env{'browser.interface'}=$form->{'interface'};
16464: }
16465:
1.1157 raeburn 16466: if ($form->{'iptoken'}) {
16467: my $lonhost = $r->dir_config('lonHostID');
16468: $initial_env{"user.noloadbalance"} = $lonhost;
16469: $env{'user.noloadbalance'} = $lonhost;
16470: }
16471:
1.1268 raeburn 16472: if ($form->{'noloadbalance'}) {
16473: my @hosts = &Apache::lonnet::current_machine_ids();
16474: my $hosthere = $form->{'noloadbalance'};
16475: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16476: $initial_env{"user.noloadbalance"} = $hosthere;
16477: $env{'user.noloadbalance'} = $hosthere;
16478: }
16479: }
16480:
1.1016 raeburn 16481: unless ($domain eq 'public') {
1.1273 raeburn 16482: my %is_adv = ( is_adv => $env{'user.adv'} );
16483: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
16484:
16485: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16486: $userenv{'availabletools.'.$tool} =
16487: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16488: undef,\%userenv,\%domdef,\%is_adv);
16489: }
1.980 raeburn 16490:
1.1311 ! raeburn 16491: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 16492: $userenv{'canrequest.'.$crstype} =
16493: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16494: 'reload','requestcourses',
16495: \%userenv,\%domdef,\%is_adv);
16496: }
1.724 raeburn 16497:
1.1273 raeburn 16498: $userenv{'canrequest.author'} =
16499: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16500: 'reload','requestauthor',
1.980 raeburn 16501: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 16502: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16503: $domain,$username);
16504: my $reqstatus = $reqauthor{'author_status'};
16505: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16506: if (ref($reqauthor{'author'}) eq 'HASH') {
16507: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16508: $reqauthor{'author'}{'timestamp'};
16509: }
1.1092 raeburn 16510: }
1.1287 raeburn 16511: my ($types,$typename) = &course_types();
16512: if (ref($types) eq 'ARRAY') {
16513: my @options = ('approval','validate','autolimit');
16514: my $optregex = join('|',@options);
16515: my (%willtrust,%trustchecked);
16516: foreach my $type (@{$types}) {
16517: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
16518: if ($dom_str ne '') {
16519: my $updatedstr = '';
16520: my @possdomains = split(',',$dom_str);
16521: foreach my $entry (@possdomains) {
16522: my ($extdom,$extopt) = split(':',$entry);
16523: unless ($trustchecked{$extdom}) {
16524: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
16525: $trustchecked{$extdom} = 1;
16526: }
16527: if ($willtrust{$extdom}) {
16528: $updatedstr .= $entry.',';
16529: }
16530: }
16531: $updatedstr =~ s/,$//;
16532: if ($updatedstr) {
16533: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
16534: } else {
16535: delete($userenv{'reqcrsotherdom.'.$type});
16536: }
16537: }
16538: }
16539: }
1.1092 raeburn 16540: }
1.462 albertel 16541: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16542:
1.462 albertel 16543: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16544: &GDBM_WRCREAT(),0640)) {
16545: &_add_to_env(\%disk_env,\%initial_env);
16546: &_add_to_env(\%disk_env,\%userenv,'environment.');
16547: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16548: if (ref($firstaccenv) eq 'HASH') {
16549: &_add_to_env(\%disk_env,$firstaccenv);
16550: }
16551: if (ref($timerintenv) eq 'HASH') {
16552: &_add_to_env(\%disk_env,$timerintenv);
16553: }
1.463 albertel 16554: if (ref($args->{'extra_env'})) {
16555: &_add_to_env(\%disk_env,$args->{'extra_env'});
16556: }
1.462 albertel 16557: untie(%disk_env);
16558: } else {
1.705 tempelho 16559: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16560: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16561: return 'error: '.$!;
16562: }
16563: }
16564: $env{'request.role'}='cm';
16565: $env{'request.role.adv'}=$env{'user.adv'};
16566: $env{'browser.type'}=$clientbrowser;
16567:
16568: return $cookie;
16569:
16570: }
16571:
16572: sub _add_to_env {
16573: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16574: if (ref($env_data) eq 'HASH') {
16575: while (my ($key,$value) = each(%$env_data)) {
16576: $idf->{$prefix.$key} = $value;
16577: $env{$prefix.$key} = $value;
16578: }
1.462 albertel 16579: }
16580: }
16581:
1.685 tempelho 16582: # --- Get the symbolic name of a problem and the url
16583: sub get_symb {
16584: my ($request,$silent) = @_;
1.726 raeburn 16585: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16586: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16587: if ($symb eq '') {
16588: if (!$silent) {
1.1071 raeburn 16589: if (ref($request)) {
16590: $request->print("Unable to handle ambiguous references:$url:.");
16591: }
1.685 tempelho 16592: return ();
16593: }
16594: }
16595: &Apache::lonenc::check_decrypt(\$symb);
16596: return ($symb);
16597: }
16598:
16599: # --------------------------------------------------------------Get annotation
16600:
16601: sub get_annotation {
16602: my ($symb,$enc) = @_;
16603:
16604: my $key = $symb;
16605: if (!$enc) {
16606: $key =
16607: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16608: }
16609: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16610: return $annotation{$key};
16611: }
16612:
16613: sub clean_symb {
1.731 raeburn 16614: my ($symb,$delete_enc) = @_;
1.685 tempelho 16615:
16616: &Apache::lonenc::check_decrypt(\$symb);
16617: my $enc = $env{'request.enc'};
1.731 raeburn 16618: if ($delete_enc) {
1.730 raeburn 16619: delete($env{'request.enc'});
16620: }
1.685 tempelho 16621:
16622: return ($symb,$enc);
16623: }
1.462 albertel 16624:
1.1181 raeburn 16625: ############################################################
16626: ############################################################
16627:
16628: =pod
16629:
16630: =head1 Routines for building display used to search for courses
16631:
16632:
16633: =over 4
16634:
16635: =item * &build_filters()
16636:
16637: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 16638: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16639: and quotacheck.pl
16640:
1.1181 raeburn 16641:
16642: Inputs:
16643:
16644: filterlist - anonymous array of fields to include as potential filters
16645:
16646: crstype - course type
16647:
16648: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16649: to pop-open a course selector (will contain "extra element").
16650:
16651: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16652:
16653: filter - anonymous hash of criteria and their values
16654:
16655: action - form action
16656:
16657: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16658:
1.1182 raeburn 16659: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 16660:
16661: cloneruname - username of owner of new course who wants to clone
16662:
16663: clonerudom - domain of owner of new course who wants to clone
16664:
16665: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16666:
16667: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16668:
16669: codedom - domain
16670:
16671: formname - value of form element named "form".
16672:
16673: fixeddom - domain, if fixed.
16674:
16675: prevphase - value to assign to form element named "phase" when going back to the previous screen
16676:
16677: cnameelement - name of form element in form on opener page which will receive title of selected course
16678:
16679: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16680:
16681: cdomelement - name of form element in form on opener page which will receive domain of selected course
16682:
16683: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16684:
16685: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16686:
16687: clonewarning - warning message about missing information for intended course owner when DC creates a course
16688:
1.1182 raeburn 16689:
1.1181 raeburn 16690: Returns: $output - HTML for display of search criteria, and hidden form elements.
16691:
1.1182 raeburn 16692:
1.1181 raeburn 16693: Side Effects: None
16694:
16695: =cut
16696:
16697: # ---------------------------------------------- search for courses based on last activity etc.
16698:
16699: sub build_filters {
16700: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16701: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16702: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16703: $cnameelement,$cnumelement,$cdomelement,$setroles,
16704: $clonetext,$clonewarning) = @_;
1.1182 raeburn 16705: my ($list,$jscript);
1.1181 raeburn 16706: my $onchange = 'javascript:updateFilters(this)';
16707: my ($domainselectform,$sincefilterform,$createdfilterform,
16708: $ownerdomselectform,$persondomselectform,$instcodeform,
16709: $typeselectform,$instcodetitle);
16710: if ($formname eq '') {
16711: $formname = $caller;
16712: }
16713: foreach my $item (@{$filterlist}) {
16714: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16715: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16716: if ($item eq 'domainfilter') {
16717: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16718: } elsif ($item eq 'coursefilter') {
16719: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16720: } elsif ($item eq 'ownerfilter') {
16721: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16722: } elsif ($item eq 'ownerdomfilter') {
16723: $filter->{'ownerdomfilter'} =
16724: &LONCAPA::clean_domain($filter->{$item});
16725: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16726: 'ownerdomfilter',1);
16727: } elsif ($item eq 'personfilter') {
16728: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16729: } elsif ($item eq 'persondomfilter') {
16730: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16731: 'persondomfilter',1);
16732: } else {
16733: $filter->{$item} =~ s/\W//g;
16734: }
16735: if (!$filter->{$item}) {
16736: $filter->{$item} = '';
16737: }
16738: }
16739: if ($item eq 'domainfilter') {
16740: my $allow_blank = 1;
16741: if ($formname eq 'portform') {
16742: $allow_blank=0;
16743: } elsif ($formname eq 'studentform') {
16744: $allow_blank=0;
16745: }
16746: if ($fixeddom) {
16747: $domainselectform = '<input type="hidden" name="domainfilter"'.
16748: ' value="'.$codedom.'" />'.
16749: &Apache::lonnet::domain($codedom,'description');
16750: } else {
16751: $domainselectform = &select_dom_form($filter->{$item},
16752: 'domainfilter',
16753: $allow_blank,'',$onchange);
16754: }
16755: } else {
16756: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16757: }
16758: }
16759:
16760: # last course activity filter and selection
16761: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16762:
16763: # course created filter and selection
16764: if (exists($filter->{'createdfilter'})) {
16765: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16766: }
16767:
1.1239 raeburn 16768: my $prefix = $crstype;
16769: if ($crstype eq 'Placement') {
16770: $prefix = 'Placement Test'
16771: }
1.1181 raeburn 16772: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 16773: 'cac' => "$prefix Activity",
16774: 'ccr' => "$prefix Created",
16775: 'cde' => "$prefix Title",
16776: 'cdo' => "$prefix Domain",
1.1181 raeburn 16777: 'ins' => 'Institutional Code',
16778: 'inc' => 'Institutional Categorization',
1.1239 raeburn 16779: 'cow' => "$prefix Owner/Co-owner",
16780: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 16781: 'cog' => 'Type',
16782: );
16783:
16784: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16785: my $typeval = 'Course';
16786: if ($crstype eq 'Community') {
16787: $typeval = 'Community';
1.1239 raeburn 16788: } elsif ($crstype eq 'Placement') {
16789: $typeval = 'Placement';
1.1181 raeburn 16790: }
16791: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16792: } else {
16793: $typeselectform = '<select name="type" size="1"';
16794: if ($onchange) {
16795: $typeselectform .= ' onchange="'.$onchange.'"';
16796: }
16797: $typeselectform .= '>'."\n";
1.1237 raeburn 16798: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 16799: my $shown;
16800: if ($posstype eq 'Placement') {
16801: $shown = &mt('Placement Test');
16802: } else {
16803: $shown = &mt($posstype);
16804: }
1.1181 raeburn 16805: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 16806: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 16807: }
16808: $typeselectform.="</select>";
16809: }
16810:
16811: my ($cloneableonlyform,$cloneabletitle);
16812: if (exists($filter->{'cloneableonly'})) {
16813: my $cloneableon = '';
16814: my $cloneableoff = ' checked="checked"';
16815: if ($filter->{'cloneableonly'}) {
16816: $cloneableon = $cloneableoff;
16817: $cloneableoff = '';
16818: }
16819: $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>';
16820: if ($formname eq 'ccrs') {
1.1187 bisitz 16821: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 16822: } else {
16823: $cloneabletitle = &mt('Cloneable by you');
16824: }
16825: }
16826: my $officialjs;
16827: if ($crstype eq 'Course') {
16828: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 16829: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16830: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16831: if ($codedom) {
1.1181 raeburn 16832: $officialjs = 1;
16833: ($instcodeform,$jscript,$$numtitlesref) =
16834: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16835: $officialjs,$codetitlesref);
16836: if ($jscript) {
1.1182 raeburn 16837: $jscript = '<script type="text/javascript">'."\n".
16838: '// <![CDATA['."\n".
16839: $jscript."\n".
16840: '// ]]>'."\n".
16841: '</script>'."\n";
1.1181 raeburn 16842: }
16843: }
16844: if ($instcodeform eq '') {
16845: $instcodeform =
16846: '<input type="text" name="instcodefilter" size="10" value="'.
16847: $list->{'instcodefilter'}.'" />';
16848: $instcodetitle = $lt{'ins'};
16849: } else {
16850: $instcodetitle = $lt{'inc'};
16851: }
16852: if ($fixeddom) {
16853: $instcodetitle .= '<br />('.$codedom.')';
16854: }
16855: }
16856: }
16857: my $output = qq|
16858: <form method="post" name="filterpicker" action="$action">
16859: <input type="hidden" name="form" value="$formname" />
16860: |;
16861: if ($formname eq 'modifycourse') {
16862: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16863: '<input type="hidden" name="prevphase" value="'.
16864: $prevphase.'" />'."\n";
1.1198 musolffc 16865: } elsif ($formname eq 'quotacheck') {
16866: $output .= qq|
16867: <input type="hidden" name="sortby" value="" />
16868: <input type="hidden" name="sortorder" value="" />
16869: |;
16870: } else {
1.1181 raeburn 16871: my $name_input;
16872: if ($cnameelement ne '') {
16873: $name_input = '<input type="hidden" name="cnameelement" value="'.
16874: $cnameelement.'" />';
16875: }
16876: $output .= qq|
1.1182 raeburn 16877: <input type="hidden" name="cnumelement" value="$cnumelement" />
16878: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 16879: $name_input
16880: $roleelement
16881: $multelement
16882: $typeelement
16883: |;
16884: if ($formname eq 'portform') {
16885: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16886: }
16887: }
16888: if ($fixeddom) {
16889: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16890: }
16891: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16892: if ($sincefilterform) {
16893: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16894: .$sincefilterform
16895: .&Apache::lonhtmlcommon::row_closure();
16896: }
16897: if ($createdfilterform) {
16898: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16899: .$createdfilterform
16900: .&Apache::lonhtmlcommon::row_closure();
16901: }
16902: if ($domainselectform) {
16903: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16904: .$domainselectform
16905: .&Apache::lonhtmlcommon::row_closure();
16906: }
16907: if ($typeselectform) {
16908: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16909: $output .= $typeselectform;
16910: } else {
16911: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16912: .$typeselectform
16913: .&Apache::lonhtmlcommon::row_closure();
16914: }
16915: }
16916: if ($instcodeform) {
16917: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16918: .$instcodeform
16919: .&Apache::lonhtmlcommon::row_closure();
16920: }
16921: if (exists($filter->{'ownerfilter'})) {
16922: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16923: '<table><tr><td>'.&mt('Username').'<br />'.
16924: '<input type="text" name="ownerfilter" size="20" value="'.
16925: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16926: $ownerdomselectform.'</td></tr></table>'.
16927: &Apache::lonhtmlcommon::row_closure();
16928: }
16929: if (exists($filter->{'personfilter'})) {
16930: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16931: '<table><tr><td>'.&mt('Username').'<br />'.
16932: '<input type="text" name="personfilter" size="20" value="'.
16933: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16934: $persondomselectform.'</td></tr></table>'.
16935: &Apache::lonhtmlcommon::row_closure();
16936: }
16937: if (exists($filter->{'coursefilter'})) {
16938: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16939: .'<input type="text" name="coursefilter" size="25" value="'
16940: .$list->{'coursefilter'}.'" />'
16941: .&Apache::lonhtmlcommon::row_closure();
16942: }
16943: if ($cloneableonlyform) {
16944: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16945: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16946: }
16947: if (exists($filter->{'descriptfilter'})) {
16948: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16949: .'<input type="text" name="descriptfilter" size="40" value="'
16950: .$list->{'descriptfilter'}.'" />'
16951: .&Apache::lonhtmlcommon::row_closure(1);
16952: }
16953: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16954: '<input type="hidden" name="updater" value="" />'."\n".
16955: '<input type="submit" name="gosearch" value="'.
16956: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16957: return $jscript.$clonewarning.$output;
16958: }
16959:
16960: =pod
16961:
16962: =item * &timebased_select_form()
16963:
1.1182 raeburn 16964: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 16965: filter e.g., Course Activity, Course Created, when searching for courses
16966: or communities
16967:
16968: Inputs:
16969:
16970: item - name of form element (sincefilter or createdfilter)
16971:
16972: filter - anonymous hash of criteria and their values
16973:
16974: Returns: HTML for a select box contained a blank, then six time selections,
16975: with value set in incoming form variables currently selected.
16976:
16977: Side Effects: None
16978:
16979: =cut
16980:
16981: sub timebased_select_form {
16982: my ($item,$filter) = @_;
16983: if (ref($filter) eq 'HASH') {
16984: $filter->{$item} =~ s/[^\d-]//g;
16985: if (!$filter->{$item}) { $filter->{$item}=-1; }
16986: return &select_form(
16987: $filter->{$item},
16988: $item,
16989: { '-1' => '',
16990: '86400' => &mt('today'),
16991: '604800' => &mt('last week'),
16992: '2592000' => &mt('last month'),
16993: '7776000' => &mt('last three months'),
16994: '15552000' => &mt('last six months'),
16995: '31104000' => &mt('last year'),
16996: 'select_form_order' =>
16997: ['-1','86400','604800','2592000','7776000',
16998: '15552000','31104000']});
16999: }
17000: }
17001:
17002: =pod
17003:
17004: =item * &js_changer()
17005:
17006: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 17007: when course type or domain is changed, and also to hide 'Searching ...' on
17008: page load completion for page showing search result.
1.1181 raeburn 17009:
17010: Inputs: None
17011:
1.1183 raeburn 17012: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 17013:
17014: Side Effects: None
17015:
17016: =cut
17017:
17018: sub js_changer {
17019: return <<ENDJS;
17020: <script type="text/javascript">
17021: // <![CDATA[
17022: function updateFilters(caller) {
17023: if (typeof(caller) != "undefined") {
17024: document.filterpicker.updater.value = caller.name;
17025: }
17026: document.filterpicker.submit();
17027: }
1.1183 raeburn 17028:
17029: function hideSearching() {
17030: if (document.getElementById('searching')) {
17031: document.getElementById('searching').style.display = 'none';
17032: }
17033: return;
17034: }
17035:
1.1181 raeburn 17036: // ]]>
17037: </script>
17038:
17039: ENDJS
17040: }
17041:
17042: =pod
17043:
1.1182 raeburn 17044: =item * &search_courses()
17045:
17046: Process selected filters form course search form and pass to lonnet::courseiddump
17047: to retrieve a hash for which keys are courseIDs which match the selected filters.
17048:
17049: Inputs:
17050:
17051: dom - domain being searched
17052:
17053: type - course type ('Course' or 'Community' or '.' if any).
17054:
17055: filter - anonymous hash of criteria and their values
17056:
17057: numtitles - for institutional codes - number of categories
17058:
17059: cloneruname - optional username of new course owner
17060:
17061: clonerudom - optional domain of new course owner
17062:
1.1221 raeburn 17063: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 17064: (used when DC is using course creation form)
17065:
17066: codetitles - reference to array of titles of components in institutional codes (official courses).
17067:
1.1221 raeburn 17068: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17069: (and so can clone automatically)
17070:
17071: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17072:
17073: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17074: courses to clone
1.1182 raeburn 17075:
17076: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17077:
17078:
17079: Side Effects: None
17080:
17081: =cut
17082:
17083:
17084: sub search_courses {
1.1221 raeburn 17085: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17086: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 17087: my (%courses,%showcourses,$cloner);
17088: if (($filter->{'ownerfilter'} ne '') ||
17089: ($filter->{'ownerdomfilter'} ne '')) {
17090: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17091: $filter->{'ownerdomfilter'};
17092: }
17093: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17094: if (!$filter->{$item}) {
17095: $filter->{$item}='.';
17096: }
17097: }
17098: my $now = time;
17099: my $timefilter =
17100: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17101: my ($createdbefore,$createdafter);
17102: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17103: $createdbefore = $now;
17104: $createdafter = $now-$filter->{'createdfilter'};
17105: }
17106: my ($instcodefilter,$regexpok);
17107: if ($numtitles) {
17108: if ($env{'form.official'} eq 'on') {
17109: $instcodefilter =
17110: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17111: $regexpok = 1;
17112: } elsif ($env{'form.official'} eq 'off') {
17113: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17114: unless ($instcodefilter eq '') {
17115: $regexpok = -1;
17116: }
17117: }
17118: } else {
17119: $instcodefilter = $filter->{'instcodefilter'};
17120: }
17121: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17122: if ($type eq '') { $type = '.'; }
17123:
17124: if (($clonerudom ne '') && ($cloneruname ne '')) {
17125: $cloner = $cloneruname.':'.$clonerudom;
17126: }
17127: %courses = &Apache::lonnet::courseiddump($dom,
17128: $filter->{'descriptfilter'},
17129: $timefilter,
17130: $instcodefilter,
17131: $filter->{'combownerfilter'},
17132: $filter->{'coursefilter'},
17133: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 17134: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 17135: $filter->{'cloneableonly'},
17136: $createdbefore,$createdafter,undef,
1.1221 raeburn 17137: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 17138: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17139: my $ccrole;
17140: if ($type eq 'Community') {
17141: $ccrole = 'co';
17142: } else {
17143: $ccrole = 'cc';
17144: }
17145: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17146: $filter->{'persondomfilter'},
17147: 'userroles',undef,
17148: [$ccrole,'in','ad','ep','ta','cr'],
17149: $dom);
17150: foreach my $role (keys(%rolehash)) {
17151: my ($cnum,$cdom,$courserole) = split(':',$role);
17152: my $cid = $cdom.'_'.$cnum;
17153: if (exists($courses{$cid})) {
17154: if (ref($courses{$cid}) eq 'HASH') {
17155: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17156: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 17157: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 17158: }
17159: } else {
17160: $courses{$cid}{roles} = [$courserole];
17161: }
17162: $showcourses{$cid} = $courses{$cid};
17163: }
17164: }
17165: }
17166: %courses = %showcourses;
17167: }
17168: return %courses;
17169: }
17170:
17171: =pod
17172:
1.1181 raeburn 17173: =back
17174:
1.1207 raeburn 17175: =head1 Routines for version requirements for current course.
17176:
17177: =over 4
17178:
17179: =item * &check_release_required()
17180:
17181: Compares required LON-CAPA version with version on server, and
17182: if required version is newer looks for a server with the required version.
17183:
17184: Looks first at servers in user's owen domain; if none suitable, looks at
17185: servers in course's domain are permitted to host sessions for user's domain.
17186:
17187: Inputs:
17188:
17189: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17190:
17191: $courseid - Course ID of current course
17192:
17193: $rolecode - User's current role in course (for switchserver query string).
17194:
17195: $required - LON-CAPA version needed by course (format: Major.Minor).
17196:
17197:
17198: Returns:
17199:
17200: $switchserver - query string tp append to /adm/switchserver call (if
17201: current server's LON-CAPA version is too old.
17202:
17203: $warning - Message is displayed if no suitable server could be found.
17204:
17205: =cut
17206:
17207: sub check_release_required {
17208: my ($loncaparev,$courseid,$rolecode,$required) = @_;
17209: my ($switchserver,$warning);
17210: if ($required ne '') {
17211: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
17212: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17213: if ($reqdmajor ne '' && $reqdminor ne '') {
17214: my $otherserver;
17215: if (($major eq '' && $minor eq '') ||
17216: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
17217: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
17218: my $switchlcrev =
17219: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
17220: $userdomserver);
17221: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17222: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
17223: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
17224: my $cdom = $env{'course.'.$courseid.'.domain'};
17225: if ($cdom ne $env{'user.domain'}) {
17226: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
17227: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
17228: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17229: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
17230: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
17231: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
17232: my $canhost =
17233: &Apache::lonnet::can_host_session($env{'user.domain'},
17234: $coursedomserver,
17235: $remoterev,
17236: $udomdefaults{'remotesessions'},
17237: $defdomdefaults{'hostedsessions'});
17238:
17239: if ($canhost) {
17240: $otherserver = $coursedomserver;
17241: } else {
17242: $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.");
17243: }
17244: } else {
17245: $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).");
17246: }
17247: } else {
17248: $otherserver = $userdomserver;
17249: }
17250: }
17251: if ($otherserver ne '') {
17252: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
17253: }
17254: }
17255: }
17256: return ($switchserver,$warning);
17257: }
17258:
17259: =pod
17260:
17261: =item * &check_release_result()
17262:
17263: Inputs:
17264:
17265: $switchwarning - Warning message if no suitable server found to host session.
17266:
17267: $switchserver - query string to append to /adm/switchserver containing lonHostID
17268: and current role.
17269:
17270: Returns: HTML to display with information about requirement to switch server.
17271: Either displaying warning with link to Roles/Courses screen or
17272: display link to switchserver.
17273:
1.1181 raeburn 17274: =cut
17275:
1.1207 raeburn 17276: sub check_release_result {
17277: my ($switchwarning,$switchserver) = @_;
17278: my $output = &start_page('Selected course unavailable on this server').
17279: '<p class="LC_warning">';
17280: if ($switchwarning) {
17281: $output .= $switchwarning.'<br /><a href="/adm/roles">';
17282: if (&show_course()) {
17283: $output .= &mt('Display courses');
17284: } else {
17285: $output .= &mt('Display roles');
17286: }
17287: $output .= '</a>';
17288: } elsif ($switchserver) {
17289: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
17290: '<br />'.
17291: '<a href="/adm/switchserver?'.$switchserver.'">'.
17292: &mt('Switch Server').
17293: '</a>';
17294: }
17295: $output .= '</p>'.&end_page();
17296: return $output;
17297: }
17298:
17299: =pod
17300:
17301: =item * &needs_coursereinit()
17302:
17303: Determine if course contents stored for user's session needs to be
17304: refreshed, because content has changed since "Big Hash" last tied.
17305:
17306: Check for change is made if time last checked is more than 10 minutes ago
17307: (by default).
17308:
17309: Inputs:
17310:
17311: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17312:
17313: $interval (optional) - Time which may elapse (in s) between last check for content
17314: change in current course. (default: 600 s).
17315:
17316: Returns: an array; first element is:
17317:
17318: =over 4
17319:
17320: 'switch' - if content updates mean user's session
17321: needs to be switched to a server running a newer LON-CAPA version
17322:
17323: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
17324: on current server hosting user's session
17325:
17326: '' - if no action required.
17327:
17328: =back
17329:
17330: If first item element is 'switch':
17331:
17332: second item is $switchwarning - Warning message if no suitable server found to host session.
17333:
17334: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
17335: and current role.
17336:
17337: otherwise: no other elements returned.
17338:
17339: =back
17340:
17341: =cut
17342:
17343: sub needs_coursereinit {
17344: my ($loncaparev,$interval) = @_;
17345: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17346: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17347: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17348: my $now = time;
17349: if ($interval eq '') {
17350: $interval = 600;
17351: }
17352: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 17353: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1283 raeburn 17354: my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1);
1.1282 raeburn 17355: if ($blocked) {
17356: return ();
17357: }
1.1207 raeburn 17358: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17359: if ($lastchange > $env{'request.course.tied'}) {
17360: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17361: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17362: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17363: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17364: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17365: $curr_reqd_hash{'internal.releaserequired'}});
17366: my ($switchserver,$switchwarning) =
17367: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17368: $curr_reqd_hash{'internal.releaserequired'});
17369: if ($switchwarning ne '' || $switchserver ne '') {
17370: return ('switch',$switchwarning,$switchserver);
17371: }
17372: }
17373: }
17374: return ('update');
17375: }
17376: }
17377: return ();
17378: }
1.1181 raeburn 17379:
1.1083 raeburn 17380: sub update_content_constraints {
17381: my ($cdom,$cnum,$chome,$cid) = @_;
17382: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17383: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 17384: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 17385: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 17386: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 17387: if ($item eq 'resourcetag') {
17388: if ($name eq 'responsetype') {
17389: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17390: }
1.1307 raeburn 17391: } elsif ($item eq 'course') {
17392: if ($name eq 'courserestype') {
17393: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
17394: }
1.1083 raeburn 17395: }
17396: }
17397: my $navmap = Apache::lonnavmaps::navmap->new();
17398: if (defined($navmap)) {
1.1307 raeburn 17399: my (%allresponses,%allcrsrestypes);
17400: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
17401: if ($res->is_tool()) {
17402: if ($allcrsrestypes{'exttool'}) {
17403: $allcrsrestypes{'exttool'} ++;
17404: } else {
17405: $allcrsrestypes{'exttool'} = 1;
17406: }
17407: next;
17408: }
1.1083 raeburn 17409: my %responses = $res->responseTypes();
17410: foreach my $key (keys(%responses)) {
17411: next unless(exists($checkresponsetypes{$key}));
17412: $allresponses{$key} += $responses{$key};
17413: }
17414: }
17415: foreach my $key (keys(%allresponses)) {
17416: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17417: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17418: ($reqdmajor,$reqdminor) = ($major,$minor);
17419: }
17420: }
1.1307 raeburn 17421: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 17422: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 17423: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17424: ($reqdmajor,$reqdminor) = ($major,$minor);
17425: }
17426: }
1.1083 raeburn 17427: undef($navmap);
17428: }
1.1308 raeburn 17429: my $suppmap = 'supplemental.sequence';
17430: my ($suppcount,$supptools,$errors) = (0,0,0);
17431: ($suppcount,$supptools,$errors) = &recurse_supplemental($cnum,$cdom,$suppmap,
17432: $suppcount,$supptools,$errors);
17433: if ($supptools) {
17434: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
17435: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17436: ($reqdmajor,$reqdminor) = ($major,$minor);
17437: }
17438: }
1.1083 raeburn 17439: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17440: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17441: }
17442: return;
17443: }
17444:
1.1110 raeburn 17445: sub allmaps_incourse {
17446: my ($cdom,$cnum,$chome,$cid) = @_;
17447: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17448: $cid = $env{'request.course.id'};
17449: $cdom = $env{'course.'.$cid.'.domain'};
17450: $cnum = $env{'course.'.$cid.'.num'};
17451: $chome = $env{'course.'.$cid.'.home'};
17452: }
17453: my %allmaps = ();
17454: my $lastchange =
17455: &Apache::lonnet::get_coursechange($cdom,$cnum);
17456: if ($lastchange > $env{'request.course.tied'}) {
17457: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17458: unless ($ferr) {
17459: &update_content_constraints($cdom,$cnum,$chome,$cid);
17460: }
17461: }
17462: my $navmap = Apache::lonnavmaps::navmap->new();
17463: if (defined($navmap)) {
17464: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17465: $allmaps{$res->src()} = 1;
17466: }
17467: }
17468: return \%allmaps;
17469: }
17470:
1.1083 raeburn 17471: sub parse_supplemental_title {
17472: my ($title) = @_;
17473:
17474: my ($foldertitle,$renametitle);
17475: if ($title =~ /&&&/) {
17476: $title = &HTML::Entites::decode($title);
17477: }
17478: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17479: $renametitle=$4;
17480: my ($time,$uname,$udom) = ($1,$2,$3);
17481: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17482: my $name = &plainname($uname,$udom);
17483: $name = &HTML::Entities::encode($name,'"<>&\'');
17484: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17485: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17486: $name.': <br />'.$foldertitle;
17487: }
17488: if (wantarray) {
17489: return ($title,$foldertitle,$renametitle);
17490: }
17491: return $title;
17492: }
17493:
1.1143 raeburn 17494: sub recurse_supplemental {
1.1308 raeburn 17495: my ($cnum,$cdom,$suppmap,$numfiles,$numexttools,$errors) = @_;
1.1143 raeburn 17496: if ($suppmap) {
17497: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17498: if ($fatal) {
17499: $errors ++;
17500: } else {
17501: if ($#LONCAPA::map::resources > 0) {
17502: foreach my $res (@LONCAPA::map::resources) {
17503: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17504: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 17505: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1308 raeburn 17506: ($numfiles,$numexttools,$errors) = &recurse_supplemental($cnum,$cdom,$1,
17507: $numfiles,$numexttools,$errors);
1.1143 raeburn 17508: } else {
1.1308 raeburn 17509: if ($src =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
17510: $numexttools ++;
17511: }
1.1143 raeburn 17512: $numfiles ++;
17513: }
17514: }
17515: }
17516: }
17517: }
17518: }
1.1308 raeburn 17519: return ($numfiles,$numexttools,$errors);
1.1143 raeburn 17520: }
17521:
1.1101 raeburn 17522: sub symb_to_docspath {
1.1267 raeburn 17523: my ($symb,$navmapref) = @_;
17524: return unless ($symb && ref($navmapref));
1.1101 raeburn 17525: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17526: if ($resurl=~/\.(sequence|page)$/) {
17527: $mapurl=$resurl;
17528: } elsif ($resurl eq 'adm/navmaps') {
17529: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17530: }
17531: my $mapresobj;
1.1267 raeburn 17532: unless (ref($$navmapref)) {
17533: $$navmapref = Apache::lonnavmaps::navmap->new();
17534: }
17535: if (ref($$navmapref)) {
17536: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 17537: }
17538: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17539: my $type=$2;
17540: my $path;
17541: if (ref($mapresobj)) {
17542: my $pcslist = $mapresobj->map_hierarchy();
17543: if ($pcslist ne '') {
17544: foreach my $pc (split(/,/,$pcslist)) {
17545: next if ($pc <= 1);
1.1267 raeburn 17546: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 17547: if (ref($res)) {
17548: my $thisurl = $res->src();
17549: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17550: my $thistitle = $res->title();
17551: $path .= '&'.
17552: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 17553: &escape($thistitle).
1.1101 raeburn 17554: ':'.$res->randompick().
17555: ':'.$res->randomout().
17556: ':'.$res->encrypted().
17557: ':'.$res->randomorder().
17558: ':'.$res->is_page();
17559: }
17560: }
17561: }
17562: $path =~ s/^\&//;
17563: my $maptitle = $mapresobj->title();
17564: if ($mapurl eq 'default') {
1.1129 raeburn 17565: $maptitle = 'Main Content';
1.1101 raeburn 17566: }
17567: $path .= (($path ne '')? '&' : '').
17568: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17569: &escape($maptitle).
1.1101 raeburn 17570: ':'.$mapresobj->randompick().
17571: ':'.$mapresobj->randomout().
17572: ':'.$mapresobj->encrypted().
17573: ':'.$mapresobj->randomorder().
17574: ':'.$mapresobj->is_page();
17575: } else {
17576: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17577: my $ispage = (($type eq 'page')? 1 : '');
17578: if ($mapurl eq 'default') {
1.1129 raeburn 17579: $maptitle = 'Main Content';
1.1101 raeburn 17580: }
17581: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17582: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 17583: }
17584: unless ($mapurl eq 'default') {
17585: $path = 'default&'.
1.1146 raeburn 17586: &escape('Main Content').
1.1101 raeburn 17587: ':::::&'.$path;
17588: }
17589: return $path;
17590: }
17591:
1.1094 raeburn 17592: sub captcha_display {
17593: my ($context,$lonhost) = @_;
17594: my ($output,$error);
1.1234 raeburn 17595: my ($captcha,$pubkey,$privkey,$version) =
17596: &get_captcha_config($context,$lonhost);
1.1095 raeburn 17597: if ($captcha eq 'original') {
1.1094 raeburn 17598: $output = &create_captcha();
17599: unless ($output) {
1.1172 raeburn 17600: $error = 'captcha';
1.1094 raeburn 17601: }
17602: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17603: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 17604: unless ($output) {
1.1172 raeburn 17605: $error = 'recaptcha';
1.1094 raeburn 17606: }
17607: }
1.1234 raeburn 17608: return ($output,$error,$captcha,$version);
1.1094 raeburn 17609: }
17610:
17611: sub captcha_response {
17612: my ($context,$lonhost) = @_;
17613: my ($captcha_chk,$captcha_error);
1.1234 raeburn 17614: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 17615: if ($captcha eq 'original') {
1.1094 raeburn 17616: ($captcha_chk,$captcha_error) = &check_captcha();
17617: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17618: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 17619: } else {
17620: $captcha_chk = 1;
17621: }
17622: return ($captcha_chk,$captcha_error);
17623: }
17624:
17625: sub get_captcha_config {
17626: my ($context,$lonhost) = @_;
1.1234 raeburn 17627: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 17628: my $hostname = &Apache::lonnet::hostname($lonhost);
17629: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17630: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 17631: if ($context eq 'usercreation') {
17632: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17633: if (ref($domconfig{$context}) eq 'HASH') {
17634: $hashtocheck = $domconfig{$context}{'cancreate'};
17635: if (ref($hashtocheck) eq 'HASH') {
17636: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17637: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17638: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17639: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17640: }
17641: if ($privkey && $pubkey) {
17642: $captcha = 'recaptcha';
1.1234 raeburn 17643: $version = $hashtocheck->{'recaptchaversion'};
17644: if ($version ne '2') {
17645: $version = 1;
17646: }
1.1095 raeburn 17647: } else {
17648: $captcha = 'original';
17649: }
17650: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17651: $captcha = 'original';
17652: }
1.1094 raeburn 17653: }
1.1095 raeburn 17654: } else {
17655: $captcha = 'captcha';
17656: }
17657: } elsif ($context eq 'login') {
17658: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17659: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17660: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17661: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 17662: if ($privkey && $pubkey) {
17663: $captcha = 'recaptcha';
1.1234 raeburn 17664: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17665: if ($version ne '2') {
17666: $version = 1;
17667: }
1.1095 raeburn 17668: } else {
17669: $captcha = 'original';
1.1094 raeburn 17670: }
1.1095 raeburn 17671: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17672: $captcha = 'original';
1.1094 raeburn 17673: }
17674: }
1.1234 raeburn 17675: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 17676: }
17677:
17678: sub create_captcha {
17679: my %captcha_params = &captcha_settings();
17680: my ($output,$maxtries,$tries) = ('',10,0);
17681: while ($tries < $maxtries) {
17682: $tries ++;
17683: my $captcha = Authen::Captcha->new (
17684: output_folder => $captcha_params{'output_dir'},
17685: data_folder => $captcha_params{'db_dir'},
17686: );
17687: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17688:
17689: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17690: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17691: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 17692: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17693: '<br />'.
17694: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 17695: last;
17696: }
17697: }
17698: return $output;
17699: }
17700:
17701: sub captcha_settings {
17702: my %captcha_params = (
17703: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17704: www_output_dir => "/captchaspool",
17705: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17706: numchars => '5',
17707: );
17708: return %captcha_params;
17709: }
17710:
17711: sub check_captcha {
17712: my ($captcha_chk,$captcha_error);
17713: my $code = $env{'form.code'};
17714: my $md5sum = $env{'form.crypt'};
17715: my %captcha_params = &captcha_settings();
17716: my $captcha = Authen::Captcha->new(
17717: output_folder => $captcha_params{'output_dir'},
17718: data_folder => $captcha_params{'db_dir'},
17719: );
1.1109 raeburn 17720: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 17721: my %captcha_hash = (
17722: 0 => 'Code not checked (file error)',
17723: -1 => 'Failed: code expired',
17724: -2 => 'Failed: invalid code (not in database)',
17725: -3 => 'Failed: invalid code (code does not match crypt)',
17726: );
17727: if ($captcha_chk != 1) {
17728: $captcha_error = $captcha_hash{$captcha_chk}
17729: }
17730: return ($captcha_chk,$captcha_error);
17731: }
17732:
17733: sub create_recaptcha {
1.1234 raeburn 17734: my ($pubkey,$version) = @_;
17735: if ($version >= 2) {
17736: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17737: } else {
17738: my $use_ssl;
17739: if ($ENV{'SERVER_PORT'} == 443) {
17740: $use_ssl = 1;
17741: }
17742: my $captcha = Captcha::reCAPTCHA->new;
17743: return $captcha->get_options_setter({theme => 'white'})."\n".
17744: $captcha->get_html($pubkey,undef,$use_ssl).
17745: &mt('If the text is hard to read, [_1] will replace them.',
17746: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17747: '<br /><br />';
17748: }
1.1094 raeburn 17749: }
17750:
17751: sub check_recaptcha {
1.1234 raeburn 17752: my ($privkey,$version) = @_;
1.1094 raeburn 17753: my $captcha_chk;
1.1234 raeburn 17754: if ($version >= 2) {
17755: my %info = (
17756: secret => $privkey,
17757: response => $env{'form.g-recaptcha-response'},
17758: remoteip => $ENV{'REMOTE_ADDR'},
17759: );
1.1280 raeburn 17760: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
17761: $request->content(join('&',map {
17762: my $name = escape($_);
17763: "$name=" . ( ref($info{$_}) eq 'ARRAY'
17764: ? join("&$name=", map {escape($_) } @{$info{$_}})
17765: : &escape($info{$_}) );
17766: } keys(%info)));
17767: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 17768: if ($response->is_success) {
17769: my $data = JSON::DWIW->from_json($response->decoded_content);
17770: if (ref($data) eq 'HASH') {
17771: if ($data->{'success'}) {
17772: $captcha_chk = 1;
17773: }
17774: }
17775: }
17776: } else {
17777: my $captcha = Captcha::reCAPTCHA->new;
17778: my $captcha_result =
17779: $captcha->check_answer(
17780: $privkey,
17781: $ENV{'REMOTE_ADDR'},
17782: $env{'form.recaptcha_challenge_field'},
17783: $env{'form.recaptcha_response_field'},
17784: );
17785: if ($captcha_result->{is_valid}) {
17786: $captcha_chk = 1;
17787: }
1.1094 raeburn 17788: }
17789: return $captcha_chk;
17790: }
17791:
1.1174 raeburn 17792: sub emailusername_info {
1.1244 raeburn 17793: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 17794: my %titles = &Apache::lonlocal::texthash (
17795: lastname => 'Last Name',
17796: firstname => 'First Name',
17797: institution => 'School/college/university',
17798: location => "School's city, state/province, country",
17799: web => "School's web address",
17800: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 17801: id => 'Student/Employee ID',
1.1174 raeburn 17802: );
17803: return (\@fields,\%titles);
17804: }
17805:
1.1161 raeburn 17806: sub cleanup_html {
17807: my ($incoming) = @_;
17808: my $outgoing;
17809: if ($incoming ne '') {
17810: $outgoing = $incoming;
17811: $outgoing =~ s/;/;/g;
17812: $outgoing =~ s/\#/#/g;
17813: $outgoing =~ s/\&/&/g;
17814: $outgoing =~ s/</</g;
17815: $outgoing =~ s/>/>/g;
17816: $outgoing =~ s/\(/(/g;
17817: $outgoing =~ s/\)/)/g;
17818: $outgoing =~ s/"/"/g;
17819: $outgoing =~ s/'/'/g;
17820: $outgoing =~ s/\$/$/g;
17821: $outgoing =~ s{/}{/}g;
17822: $outgoing =~ s/=/=/g;
17823: $outgoing =~ s/\\/\/g
17824: }
17825: return $outgoing;
17826: }
17827:
1.1190 musolffc 17828: # Checks for critical messages and returns a redirect url if one exists.
17829: # $interval indicates how often to check for messages.
1.1282 raeburn 17830: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 17831: sub critical_redirect {
1.1282 raeburn 17832: my ($interval,$context) = @_;
1.1190 musolffc 17833: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 17834: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
17835: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17836: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17837: my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
17838: if ($blocked) {
17839: my $checkrole = "cm./$cdom/$cnum";
17840: if ($env{'request.course.sec'} ne '') {
17841: $checkrole .= "/$env{'request.course.sec'}";
17842: }
17843: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
17844: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
17845: return;
17846: }
17847: }
17848: }
1.1190 musolffc 17849: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17850: $env{'user.name'});
17851: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 17852: my $redirecturl;
1.1190 musolffc 17853: if ($what[0]) {
17854: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17855: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 17856: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17857: return (1, $url);
1.1190 musolffc 17858: }
1.1191 raeburn 17859: }
17860: }
17861: return ();
1.1190 musolffc 17862: }
17863:
1.1174 raeburn 17864: # Use:
17865: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17866: #
17867: ##################################################
17868: # password associated functions #
17869: ##################################################
17870: sub des_keys {
17871: # Make a new key for DES encryption.
17872: # Each key has two parts which are returned separately.
17873: # Please note: Each key must be passed through the &hex function
17874: # before it is output to the web browser. The hex versions cannot
17875: # be used to decrypt.
17876: my @hexstr=('0','1','2','3','4','5','6','7',
17877: '8','9','a','b','c','d','e','f');
17878: my $lkey='';
17879: for (0..7) {
17880: $lkey.=$hexstr[rand(15)];
17881: }
17882: my $ukey='';
17883: for (0..7) {
17884: $ukey.=$hexstr[rand(15)];
17885: }
17886: return ($lkey,$ukey);
17887: }
17888:
17889: sub des_decrypt {
17890: my ($key,$cyphertext) = @_;
17891: my $keybin=pack("H16",$key);
17892: my $cypher;
17893: if ($Crypt::DES::VERSION>=2.03) {
17894: $cypher=new Crypt::DES $keybin;
17895: } else {
17896: $cypher=new DES $keybin;
17897: }
1.1233 raeburn 17898: my $plaintext='';
17899: my $cypherlength = length($cyphertext);
17900: my $numchunks = int($cypherlength/32);
17901: for (my $j=0; $j<$numchunks; $j++) {
17902: my $start = $j*32;
17903: my $cypherblock = substr($cyphertext,$start,32);
17904: my $chunk =
17905: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17906: $chunk .=
17907: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17908: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17909: $plaintext .= $chunk;
17910: }
1.1174 raeburn 17911: return $plaintext;
17912: }
17913:
1.1309 raeburn 17914: sub make_short_symbs {
17915: my ($cdom,$cnum,$navmap) = @_;
17916: return unless (ref($navmap));
17917: my ($numnew,@errors);
17918: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
17919: if (@toshorten) {
17920: my (%maps,%resources,%titles);
17921: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
17922: 'shorturls',$cdom,$cnum);
17923: my %tocreate;
17924: if (keys(%resources)) {
17925: foreach my $item (sort {$a <=> $b} (@toshorten)) {
17926: my $symb = $resources{$item};
17927: if ($symb) {
17928: $tocreate{$cnum.'&'.$symb} = 1;
17929: }
17930: }
17931: }
17932: if (keys(%tocreate)) {
17933: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
17934: my $su = Short::URL->new(no_vowels => 1);
17935: my $init = '';
17936: my (%newunique,%addcourse,%courseonly,%failed);
17937: # get lock on tiny db
17938: my $now = time;
17939: my $lockhash = {
17940: "lock\0$now" => $env{'user.name'}.
17941: ':'.$env{'user.domain'},
17942: };
17943: my $tries = 0;
17944: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
17945: my ($code,$error);
17946: while (($gotlock ne 'ok') && ($tries<3)) {
17947: $tries ++;
17948: sleep 1;
17949: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17950: }
17951: if ($gotlock eq 'ok') {
17952: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
17953: \%addcourse,\%courseonly,\%failed);
17954: if (keys(%failed)) {
17955: my $numfailed = scalar(keys(%failed));
17956: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
17957: }
17958: if (keys(%newunique)) {
17959: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
17960: if ($putres eq 'ok') {
17961: $numnew = scalar(keys(%newunique));
17962: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
17963: unless ($newputres eq 'ok') {
17964: push(@errors,&mt('error: could not store course look-up of short URLs'));
17965: }
17966: } else {
17967: push(@errors,&mt('error: could not store unique six character URLs'));
17968: }
17969: }
17970: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
17971: unless ($dellockres eq 'ok') {
17972: push(@errors,&mt('error: could not release lockfile'));
17973: }
17974: } else {
17975: push(@errors,&mt('error: could not obtain lockfile'));
17976: }
17977: if (keys(%courseonly)) {
17978: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
17979: if ($result ne 'ok') {
17980: push(@errors,&mt('error: could not update course look-up of short URLs'));
17981: }
17982: }
17983: }
17984: }
17985: return ($numnew,\@errors);
17986: }
17987:
17988: sub shorten_symbs {
17989: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
17990: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
17991: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
17992: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
17993: my (%possibles,%collisions);
17994: foreach my $key (keys(%{$tocreate})) {
17995: my $num = String::CRC32::crc32($key);
17996: my $tiny = $su->encode($num,$init);
17997: if ($tiny) {
17998: $possibles{$tiny} = $key;
17999: }
18000: }
18001: if (!$init) {
18002: $init = 1;
18003: } else {
18004: $init ++;
18005: }
18006: if (keys(%possibles)) {
18007: my @posstiny = keys(%possibles);
18008: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18009: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18010: if (keys(%currtiny)) {
18011: foreach my $key (keys(%currtiny)) {
18012: next if ($currtiny{$key} eq '');
18013: if ($currtiny{$key} eq $possibles{$key}) {
18014: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18015: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18016: $courseonly->{$tsymb} = $key;
18017: }
18018: } else {
18019: $collisions{$possibles{$key}} = 1;
18020: }
18021: delete($possibles{$key});
18022: }
18023: }
18024: foreach my $key (keys(%possibles)) {
18025: $newunique->{$key} = $possibles{$key};
18026: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18027: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18028: $addcourse->{$tsymb} = $key;
18029: }
18030: }
18031: }
18032: if (keys(%collisions)) {
18033: if ($init <5) {
18034: if (!$init) {
18035: $init = 1;
18036: } else {
18037: $init ++;
18038: }
18039: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
18040: $newunique,$addcourse,$courseonly,$failed);
18041: } else {
18042: foreach my $key (keys(%collisions)) {
18043: $failed->{$key} = 1;
18044: }
18045: }
18046: }
18047: return $init;
18048: }
18049:
1.112 bowersj2 18050: 1;
18051: __END__;
1.41 ng 18052:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>