Annotation of loncom/interface/loncommon.pm, revision 1.1312
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1312 ! raeburn 4: # $Id: loncommon.pm,v 1.1311 2018/04/14 00:36:06 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1108 raeburn 70: use Apache::lonuserutils();
1.1110 raeburn 71: use Apache::lonuserstate();
1.1182 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.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.1312 ! raeburn 8725: my $ltiscope;
! 8726: if (($env{'request.course.id'}) && ($env{'request.lti.login'})) {
! 8727: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
! 8728: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
! 8729: ($ltiscope) = &LONCAPA::ltiutils::lti_provider_scope($env{'request.lti.uri'},$cdom,$cnum);
! 8730: }
1.1272 raeburn 8731: my $menulink;
8732: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8733: if ((exists($args->{'bread_crumbs_nomenu'})) ||
1.1312 ! raeburn 8734: ($ltiscope eq 'map') || ($ltiscope eq 'resource') ||
1.1272 raeburn 8735: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
8736: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
8737: (!$env{'request.role.adv'}))) {
8738: $menulink = 0;
8739: } else {
8740: undef($menulink);
8741: }
1.758 kaisler 8742: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8743: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 8744: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 8745: } else {
1.1272 raeburn 8746: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8747: }
1.320 albertel 8748: }
1.315 albertel 8749: return $result;
1.306 albertel 8750: }
8751:
8752: sub end_page {
1.315 albertel 8753: my ($args) = @_;
8754: $env{'internal.end_page'}++;
1.330 albertel 8755: my $result;
1.335 albertel 8756: if ($args->{'discussion'}) {
8757: my ($target,$parser);
8758: if (ref($args->{'discussion'})) {
8759: ($target,$parser) =($args->{'discussion'}{'target'},
8760: $args->{'discussion'}{'parser'});
8761: }
8762: $result .= &Apache::lonxml::xmlend($target,$parser);
8763: }
1.330 albertel 8764: if ($args->{'frameset'}) {
8765: $result .= '</frameset>';
8766: } else {
1.635 raeburn 8767: $result .= &endbodytag($args);
1.330 albertel 8768: }
1.1080 raeburn 8769: unless ($args->{'notbody'}) {
8770: $result .= "\n</html>";
8771: }
1.330 albertel 8772:
1.315 albertel 8773: if ($args->{'js_ready'}) {
1.317 albertel 8774: $result = &js_ready($result);
1.315 albertel 8775: }
1.335 albertel 8776:
1.320 albertel 8777: if ($args->{'html_encode'}) {
8778: $result = &html_encode($result);
8779: }
1.335 albertel 8780:
1.315 albertel 8781: return $result;
8782: }
8783:
1.1034 www 8784: sub wishlist_window {
8785: return(<<'ENDWISHLIST');
1.1046 raeburn 8786: <script type="text/javascript">
1.1034 www 8787: // <![CDATA[
8788: // <!-- BEGIN LON-CAPA Internal
8789: function set_wishlistlink(title, path) {
8790: if (!title) {
8791: title = document.title;
8792: title = title.replace(/^LON-CAPA /,'');
8793: }
1.1175 raeburn 8794: title = encodeURIComponent(title);
1.1203 raeburn 8795: title = title.replace("'","\\\'");
1.1034 www 8796: if (!path) {
8797: path = location.pathname;
8798: }
1.1175 raeburn 8799: path = encodeURIComponent(path);
1.1203 raeburn 8800: path = path.replace("'","\\\'");
1.1034 www 8801: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8802: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8803: }
8804: // END LON-CAPA Internal -->
8805: // ]]>
8806: </script>
8807: ENDWISHLIST
8808: }
8809:
1.1030 www 8810: sub modal_window {
8811: return(<<'ENDMODAL');
1.1046 raeburn 8812: <script type="text/javascript">
1.1030 www 8813: // <![CDATA[
8814: // <!-- BEGIN LON-CAPA Internal
8815: var modalWindow = {
8816: parent:"body",
8817: windowId:null,
8818: content:null,
8819: width:null,
8820: height:null,
8821: close:function()
8822: {
8823: $(".LCmodal-window").remove();
8824: $(".LCmodal-overlay").remove();
8825: },
8826: open:function()
8827: {
8828: var modal = "";
8829: modal += "<div class=\"LCmodal-overlay\"></div>";
8830: 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;\">";
8831: modal += this.content;
8832: modal += "</div>";
8833:
8834: $(this.parent).append(modal);
8835:
8836: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8837: $(".LCclose-window").click(function(){modalWindow.close();});
8838: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8839: }
8840: };
1.1140 raeburn 8841: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8842: {
1.1266 raeburn 8843: source = source.replace(/'/g,"'");
1.1030 www 8844: modalWindow.windowId = "myModal";
8845: modalWindow.width = width;
8846: modalWindow.height = height;
1.1196 raeburn 8847: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8848: modalWindow.open();
1.1208 raeburn 8849: };
1.1030 www 8850: // END LON-CAPA Internal -->
8851: // ]]>
8852: </script>
8853: ENDMODAL
8854: }
8855:
8856: sub modal_link {
1.1140 raeburn 8857: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8858: unless ($width) { $width=480; }
8859: unless ($height) { $height=400; }
1.1031 www 8860: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 8861: unless ($transparency) { $transparency='true'; }
8862:
1.1074 raeburn 8863: my $target_attr;
8864: if (defined($target)) {
8865: $target_attr = 'target="'.$target.'"';
8866: }
8867: return <<"ENDLINK";
1.1140 raeburn 8868: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8869: $linktext</a>
8870: ENDLINK
1.1030 www 8871: }
8872:
1.1032 www 8873: sub modal_adhoc_script {
8874: my ($funcname,$width,$height,$content)=@_;
8875: return (<<ENDADHOC);
1.1046 raeburn 8876: <script type="text/javascript">
1.1032 www 8877: // <![CDATA[
8878: var $funcname = function()
8879: {
8880: modalWindow.windowId = "myModal";
8881: modalWindow.width = $width;
8882: modalWindow.height = $height;
8883: modalWindow.content = '$content';
8884: modalWindow.open();
8885: };
8886: // ]]>
8887: </script>
8888: ENDADHOC
8889: }
8890:
1.1041 www 8891: sub modal_adhoc_inner {
8892: my ($funcname,$width,$height,$content)=@_;
8893: my $innerwidth=$width-20;
8894: $content=&js_ready(
1.1140 raeburn 8895: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
8896: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8897: $content.
1.1041 www 8898: &end_scrollbox().
1.1140 raeburn 8899: &end_page()
1.1041 www 8900: );
8901: return &modal_adhoc_script($funcname,$width,$height,$content);
8902: }
8903:
8904: sub modal_adhoc_window {
8905: my ($funcname,$width,$height,$content,$linktext)=@_;
8906: return &modal_adhoc_inner($funcname,$width,$height,$content).
8907: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8908: }
8909:
8910: sub modal_adhoc_launch {
8911: my ($funcname,$width,$height,$content)=@_;
8912: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8913: <script type="text/javascript">
8914: // <![CDATA[
8915: $funcname();
8916: // ]]>
8917: </script>
8918: ENDLAUNCH
8919: }
8920:
8921: sub modal_adhoc_close {
8922: return (<<ENDCLOSE);
8923: <script type="text/javascript">
8924: // <![CDATA[
8925: modalWindow.close();
8926: // ]]>
8927: </script>
8928: ENDCLOSE
8929: }
8930:
1.1038 www 8931: sub togglebox_script {
8932: return(<<ENDTOGGLE);
8933: <script type="text/javascript">
8934: // <![CDATA[
8935: function LCtoggleDisplay(id,hidetext,showtext) {
8936: link = document.getElementById(id + "link").childNodes[0];
8937: with (document.getElementById(id).style) {
8938: if (display == "none" ) {
8939: display = "inline";
8940: link.nodeValue = hidetext;
8941: } else {
8942: display = "none";
8943: link.nodeValue = showtext;
8944: }
8945: }
8946: }
8947: // ]]>
8948: </script>
8949: ENDTOGGLE
8950: }
8951:
1.1039 www 8952: sub start_togglebox {
8953: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8954: unless ($heading) { $heading=''; } else { $heading.=' '; }
8955: unless ($showtext) { $showtext=&mt('show'); }
8956: unless ($hidetext) { $hidetext=&mt('hide'); }
8957: unless ($headerbg) { $headerbg='#FFFFFF'; }
8958: return &start_data_table().
8959: &start_data_table_header_row().
8960: '<td bgcolor="'.$headerbg.'">'.$heading.
8961: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8962: $showtext.'\')">'.$showtext.'</a>]</td>'.
8963: &end_data_table_header_row().
8964: '<tr id="'.$id.'" style="display:none""><td>';
8965: }
8966:
8967: sub end_togglebox {
8968: return '</td></tr>'.&end_data_table();
8969: }
8970:
1.1041 www 8971: sub LCprogressbar_script {
1.1302 raeburn 8972: my ($id,$number_to_do)=@_;
8973: if ($number_to_do) {
8974: return(<<ENDPROGRESS);
1.1041 www 8975: <script type="text/javascript">
8976: // <![CDATA[
1.1045 www 8977: \$('#progressbar$id').progressbar({
1.1041 www 8978: value: 0,
8979: change: function(event, ui) {
8980: var newVal = \$(this).progressbar('option', 'value');
8981: \$('.pblabel', this).text(LCprogressTxt);
8982: }
8983: });
8984: // ]]>
8985: </script>
8986: ENDPROGRESS
1.1302 raeburn 8987: } else {
8988: return(<<ENDPROGRESS);
8989: <script type="text/javascript">
8990: // <![CDATA[
8991: \$('#progressbar$id').progressbar({
8992: value: false,
8993: create: function(event, ui) {
8994: \$('.ui-widget-header', this).css({'background':'#F0F0F0'});
8995: \$('.ui-progressbar-overlay', this).css({'margin':'0'});
8996: }
8997: });
8998: // ]]>
8999: </script>
9000: ENDPROGRESS
9001: }
1.1041 www 9002: }
9003:
9004: sub LCprogressbarUpdate_script {
9005: return(<<ENDPROGRESSUPDATE);
9006: <style type="text/css">
9007: .ui-progressbar { position:relative; }
1.1302 raeburn 9008: .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 9009: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
9010: </style>
9011: <script type="text/javascript">
9012: // <![CDATA[
1.1045 www 9013: var LCprogressTxt='---';
9014:
1.1302 raeburn 9015: function LCupdateProgress(percent,progresstext,id,maxnum) {
1.1041 www 9016: LCprogressTxt=progresstext;
1.1302 raeburn 9017: if ((maxnum == '') || (maxnum == undefined) || (maxnum == null)) {
9018: \$('#progressbar'+id).find('.progress-label').text(LCprogressTxt);
9019: } else if (percent === \$('#progressbar'+id).progressbar( "value" )) {
1.1301 raeburn 9020: \$('#progressbar'+id).find('.pblabel').text(LCprogressTxt);
9021: } else {
9022: \$('#progressbar'+id).progressbar('value',percent);
9023: }
1.1041 www 9024: }
9025: // ]]>
9026: </script>
9027: ENDPROGRESSUPDATE
9028: }
9029:
1.1042 www 9030: my $LClastpercent;
1.1045 www 9031: my $LCidcnt;
9032: my $LCcurrentid;
1.1042 www 9033:
1.1041 www 9034: sub LCprogressbar {
1.1302 raeburn 9035: my ($r,$number_to_do,$preamble)=@_;
1.1042 www 9036: $LClastpercent=0;
1.1045 www 9037: $LCidcnt++;
9038: $LCcurrentid=$$.'_'.$LCidcnt;
1.1302 raeburn 9039: my ($starting,$content);
9040: if ($number_to_do) {
9041: $starting=&mt('Starting');
9042: $content=(<<ENDPROGBAR);
9043: $preamble
1.1045 www 9044: <div id="progressbar$LCcurrentid">
1.1041 www 9045: <span class="pblabel">$starting</span>
9046: </div>
9047: ENDPROGBAR
1.1302 raeburn 9048: } else {
9049: $starting=&mt('Loading...');
9050: $LClastpercent='false';
9051: $content=(<<ENDPROGBAR);
9052: $preamble
9053: <div id="progressbar$LCcurrentid">
9054: <div class="progress-label">$starting</div>
9055: </div>
9056: ENDPROGBAR
9057: }
9058: &r_print($r,$content.&LCprogressbar_script($LCcurrentid,$number_to_do));
1.1041 www 9059: }
9060:
9061: sub LCprogressbarUpdate {
1.1302 raeburn 9062: my ($r,$val,$text,$number_to_do)=@_;
9063: if ($number_to_do) {
9064: unless ($val) {
9065: if ($LClastpercent) {
9066: $val=$LClastpercent;
9067: } else {
9068: $val=0;
9069: }
9070: }
9071: if ($val<0) { $val=0; }
9072: if ($val>100) { $val=0; }
9073: $LClastpercent=$val;
9074: unless ($text) { $text=$val.'%'; }
9075: } else {
9076: $val = 'false';
1.1042 www 9077: }
1.1041 www 9078: $text=&js_ready($text);
1.1044 www 9079: &r_print($r,<<ENDUPDATE);
1.1041 www 9080: <script type="text/javascript">
9081: // <![CDATA[
1.1302 raeburn 9082: LCupdateProgress($val,'$text','$LCcurrentid','$number_to_do');
1.1041 www 9083: // ]]>
9084: </script>
9085: ENDUPDATE
1.1035 www 9086: }
9087:
1.1042 www 9088: sub LCprogressbarClose {
9089: my ($r)=@_;
9090: $LClastpercent=0;
1.1044 www 9091: &r_print($r,<<ENDCLOSE);
1.1042 www 9092: <script type="text/javascript">
9093: // <![CDATA[
1.1045 www 9094: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 9095: // ]]>
9096: </script>
9097: ENDCLOSE
1.1044 www 9098: }
9099:
9100: sub r_print {
9101: my ($r,$to_print)=@_;
9102: if ($r) {
9103: $r->print($to_print);
9104: $r->rflush();
9105: } else {
9106: print($to_print);
9107: }
1.1042 www 9108: }
9109:
1.320 albertel 9110: sub html_encode {
9111: my ($result) = @_;
9112:
1.322 albertel 9113: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 9114:
9115: return $result;
9116: }
1.1044 www 9117:
1.317 albertel 9118: sub js_ready {
9119: my ($result) = @_;
9120:
1.323 albertel 9121: $result =~ s/[\n\r]/ /xmsg;
9122: $result =~ s/\\/\\\\/xmsg;
9123: $result =~ s/'/\\'/xmsg;
1.372 albertel 9124: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 9125:
9126: return $result;
9127: }
9128:
1.315 albertel 9129: sub validate_page {
9130: if ( exists($env{'internal.start_page'})
1.316 albertel 9131: && $env{'internal.start_page'} > 1) {
9132: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 9133: $env{'internal.start_page'}.' '.
1.316 albertel 9134: $ENV{'request.filename'});
1.315 albertel 9135: }
9136: if ( exists($env{'internal.end_page'})
1.316 albertel 9137: && $env{'internal.end_page'} > 1) {
9138: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 9139: $env{'internal.end_page'}.' '.
1.316 albertel 9140: $env{'request.filename'});
1.315 albertel 9141: }
9142: if ( exists($env{'internal.start_page'})
9143: && ! exists($env{'internal.end_page'})) {
1.316 albertel 9144: &Apache::lonnet::logthis('start_page called without end_page '.
9145: $env{'request.filename'});
1.315 albertel 9146: }
9147: if ( ! exists($env{'internal.start_page'})
9148: && exists($env{'internal.end_page'})) {
1.316 albertel 9149: &Apache::lonnet::logthis('end_page called without start_page'.
9150: $env{'request.filename'});
1.315 albertel 9151: }
1.306 albertel 9152: }
1.315 albertel 9153:
1.996 www 9154:
9155: sub start_scrollbox {
1.1140 raeburn 9156: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9157: unless ($outerwidth) { $outerwidth='520px'; }
9158: unless ($width) { $width='500px'; }
9159: unless ($height) { $height='200px'; }
1.1075 raeburn 9160: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9161: if ($id ne '') {
1.1140 raeburn 9162: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9163: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9164: }
1.1075 raeburn 9165: if ($bgcolor ne '') {
9166: $tdcol = "background-color: $bgcolor;";
9167: }
1.1137 raeburn 9168: my $nicescroll_js;
9169: if ($env{'browser.mobile'}) {
1.1140 raeburn 9170: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9171: }
9172: return <<"END";
9173: $nicescroll_js
9174:
9175: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9176: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9177: END
9178: }
9179:
9180: sub end_scrollbox {
9181: return '</div></td></tr></table>';
9182: }
9183:
9184: sub nicescroll_javascript {
9185: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9186: my %options;
9187: if (ref($cursor) eq 'HASH') {
9188: %options = %{$cursor};
9189: }
9190: unless ($options{'railalign'} =~ /^left|right$/) {
9191: $options{'railalign'} = 'left';
9192: }
9193: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9194: my $function = &get_users_function();
9195: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9196: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9197: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9198: }
1.1140 raeburn 9199: }
9200: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9201: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9202: $options{'cursoropacity'}='1.0';
9203: }
1.1140 raeburn 9204: } else {
9205: $options{'cursoropacity'}='1.0';
9206: }
9207: if ($options{'cursorfixedheight'} eq 'none') {
9208: delete($options{'cursorfixedheight'});
9209: } else {
9210: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9211: }
9212: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9213: delete($options{'railoffset'});
9214: }
9215: my @niceoptions;
9216: while (my($key,$value) = each(%options)) {
9217: if ($value =~ /^\{.+\}$/) {
9218: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9219: } else {
1.1140 raeburn 9220: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9221: }
1.1140 raeburn 9222: }
9223: my $nicescroll_js = '
1.1137 raeburn 9224: $(document).ready(
1.1140 raeburn 9225: function() {
9226: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9227: }
1.1137 raeburn 9228: );
9229: ';
1.1140 raeburn 9230: if ($framecheck) {
9231: $nicescroll_js .= '
9232: function expand_div(caller) {
9233: if (top === self) {
9234: document.getElementById("'.$id.'").style.width = "auto";
9235: document.getElementById("'.$id.'").style.height = "auto";
9236: } else {
9237: try {
9238: if (parent.frames) {
9239: if (parent.frames.length > 1) {
9240: var framesrc = parent.frames[1].location.href;
9241: var currsrc = framesrc.replace(/\#.*$/,"");
9242: if ((caller == "search") || (currsrc == "'.$location.'")) {
9243: document.getElementById("'.$id.'").style.width = "auto";
9244: document.getElementById("'.$id.'").style.height = "auto";
9245: }
9246: }
9247: }
9248: } catch (e) {
9249: return;
9250: }
1.1137 raeburn 9251: }
1.1140 raeburn 9252: return;
1.996 www 9253: }
1.1140 raeburn 9254: ';
9255: }
9256: if ($needjsready) {
9257: $nicescroll_js = '
9258: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9259: } else {
9260: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9261: }
9262: return $nicescroll_js;
1.996 www 9263: }
9264:
1.318 albertel 9265: sub simple_error_page {
1.1150 bisitz 9266: my ($r,$title,$msg,$args) = @_;
1.1304 raeburn 9267: my %displayargs;
1.1151 raeburn 9268: if (ref($args) eq 'HASH') {
9269: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
1.1304 raeburn 9270: if ($args->{'only_body'}) {
9271: $displayargs{'only_body'} = 1;
9272: }
9273: if ($args->{'no_nav_bar'}) {
9274: $displayargs{'no_nav_bar'} = 1;
9275: }
1.1151 raeburn 9276: } else {
9277: $msg = &mt($msg);
9278: }
1.1150 bisitz 9279:
1.318 albertel 9280: my $page =
1.1304 raeburn 9281: &Apache::loncommon::start_page($title,'',\%displayargs).
1.1150 bisitz 9282: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9283: &Apache::loncommon::end_page();
9284: if (ref($r)) {
9285: $r->print($page);
1.327 albertel 9286: return;
1.318 albertel 9287: }
9288: return $page;
9289: }
1.347 albertel 9290:
9291: {
1.610 albertel 9292: my @row_count;
1.961 onken 9293:
9294: sub start_data_table_count {
9295: unshift(@row_count, 0);
9296: return;
9297: }
9298:
9299: sub end_data_table_count {
9300: shift(@row_count);
9301: return;
9302: }
9303:
1.347 albertel 9304: sub start_data_table {
1.1018 raeburn 9305: my ($add_class,$id) = @_;
1.422 albertel 9306: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9307: my $table_id;
9308: if (defined($id)) {
9309: $table_id = ' id="'.$id.'"';
9310: }
1.961 onken 9311: &start_data_table_count();
1.1018 raeburn 9312: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9313: }
9314:
9315: sub end_data_table {
1.961 onken 9316: &end_data_table_count();
1.389 albertel 9317: return '</table>'."\n";;
1.347 albertel 9318: }
9319:
9320: sub start_data_table_row {
1.974 wenzelju 9321: my ($add_class, $id) = @_;
1.610 albertel 9322: $row_count[0]++;
9323: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9324: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9325: $id = (' id="'.$id.'"') unless ($id eq '');
9326: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9327: }
1.471 banghart 9328:
9329: sub continue_data_table_row {
1.974 wenzelju 9330: my ($add_class, $id) = @_;
1.610 albertel 9331: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9332: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9333: $id = (' id="'.$id.'"') unless ($id eq '');
9334: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9335: }
1.347 albertel 9336:
9337: sub end_data_table_row {
1.389 albertel 9338: return '</tr>'."\n";;
1.347 albertel 9339: }
1.367 www 9340:
1.421 albertel 9341: sub start_data_table_empty_row {
1.707 bisitz 9342: # $row_count[0]++;
1.421 albertel 9343: return '<tr class="LC_empty_row" >'."\n";;
9344: }
9345:
9346: sub end_data_table_empty_row {
9347: return '</tr>'."\n";;
9348: }
9349:
1.367 www 9350: sub start_data_table_header_row {
1.389 albertel 9351: return '<tr class="LC_header_row">'."\n";;
1.367 www 9352: }
9353:
9354: sub end_data_table_header_row {
1.389 albertel 9355: return '</tr>'."\n";;
1.367 www 9356: }
1.890 droeschl 9357:
9358: sub data_table_caption {
9359: my $caption = shift;
9360: return "<caption class=\"LC_caption\">$caption</caption>";
9361: }
1.347 albertel 9362: }
9363:
1.548 albertel 9364: =pod
9365:
9366: =item * &inhibit_menu_check($arg)
9367:
9368: Checks for a inhibitmenu state and generates output to preserve it
9369:
9370: Inputs: $arg - can be any of
9371: - undef - in which case the return value is a string
9372: to add into arguments list of a uri
9373: - 'input' - in which case the return value is a HTML
9374: <form> <input> field of type hidden to
9375: preserve the value
9376: - a url - in which case the return value is the url with
9377: the neccesary cgi args added to preserve the
9378: inhibitmenu state
9379: - a ref to a url - no return value, but the string is
9380: updated to include the neccessary cgi
9381: args to preserve the inhibitmenu state
9382:
9383: =cut
9384:
9385: sub inhibit_menu_check {
9386: my ($arg) = @_;
9387: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9388: if ($arg eq 'input') {
9389: if ($env{'form.inhibitmenu'}) {
9390: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9391: } else {
9392: return
9393: }
9394: }
9395: if ($env{'form.inhibitmenu'}) {
9396: if (ref($arg)) {
9397: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9398: } elsif ($arg eq '') {
9399: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9400: } else {
9401: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9402: }
9403: }
9404: if (!ref($arg)) {
9405: return $arg;
9406: }
9407: }
9408:
1.251 albertel 9409: ###############################################
1.182 matthew 9410:
9411: =pod
9412:
1.549 albertel 9413: =back
9414:
9415: =head1 User Information Routines
9416:
9417: =over 4
9418:
1.405 albertel 9419: =item * &get_users_function()
1.182 matthew 9420:
9421: Used by &bodytag to determine the current users primary role.
9422: Returns either 'student','coordinator','admin', or 'author'.
9423:
9424: =cut
9425:
9426: ###############################################
9427: sub get_users_function {
1.815 tempelho 9428: my $function = 'norole';
1.818 tempelho 9429: if ($env{'request.role'}=~/^(st)/) {
9430: $function='student';
9431: }
1.907 raeburn 9432: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9433: $function='coordinator';
9434: }
1.258 albertel 9435: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9436: $function='admin';
9437: }
1.826 bisitz 9438: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9439: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9440: $function='author';
9441: }
9442: return $function;
1.54 www 9443: }
1.99 www 9444:
9445: ###############################################
9446:
1.233 raeburn 9447: =pod
9448:
1.821 raeburn 9449: =item * &show_course()
9450:
9451: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9452: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9453:
9454: Inputs:
9455: None
9456:
9457: Outputs:
9458: Scalar: 1 if 'Course' to be used, 0 otherwise.
9459:
9460: =cut
9461:
9462: ###############################################
9463: sub show_course {
9464: my $course = !$env{'user.adv'};
9465: if (!$env{'user.adv'}) {
9466: foreach my $env (keys(%env)) {
9467: next if ($env !~ m/^user\.priv\./);
9468: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9469: $course = 0;
9470: last;
9471: }
9472: }
9473: }
9474: return $course;
9475: }
9476:
9477: ###############################################
9478:
9479: =pod
9480:
1.542 raeburn 9481: =item * &check_user_status()
1.274 raeburn 9482:
9483: Determines current status of supplied role for a
9484: specific user. Roles can be active, previous or future.
9485:
9486: Inputs:
9487: user's domain, user's username, course's domain,
1.375 raeburn 9488: course's number, optional section ID.
1.274 raeburn 9489:
9490: Outputs:
9491: role status: active, previous or future.
9492:
9493: =cut
9494:
9495: sub check_user_status {
1.412 raeburn 9496: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9497: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9498: my @uroles = keys(%userinfo);
1.274 raeburn 9499: my $srchstr;
9500: my $active_chk = 'none';
1.412 raeburn 9501: my $now = time;
1.274 raeburn 9502: if (@uroles > 0) {
1.908 raeburn 9503: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9504: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9505: } else {
1.412 raeburn 9506: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9507: }
9508: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9509: my $role_end = 0;
9510: my $role_start = 0;
9511: $active_chk = 'active';
1.412 raeburn 9512: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9513: $role_end = $1;
9514: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9515: $role_start = $1;
1.274 raeburn 9516: }
9517: }
9518: if ($role_start > 0) {
1.412 raeburn 9519: if ($now < $role_start) {
1.274 raeburn 9520: $active_chk = 'future';
9521: }
9522: }
9523: if ($role_end > 0) {
1.412 raeburn 9524: if ($now > $role_end) {
1.274 raeburn 9525: $active_chk = 'previous';
9526: }
9527: }
9528: }
9529: }
9530: return $active_chk;
9531: }
9532:
9533: ###############################################
9534:
9535: =pod
9536:
1.405 albertel 9537: =item * &get_sections()
1.233 raeburn 9538:
9539: Determines all the sections for a course including
9540: sections with students and sections containing other roles.
1.419 raeburn 9541: Incoming parameters:
9542:
9543: 1. domain
9544: 2. course number
9545: 3. reference to array containing roles for which sections should
9546: be gathered (optional).
9547: 4. reference to array containing status types for which sections
9548: should be gathered (optional).
9549:
9550: If the third argument is undefined, sections are gathered for any role.
9551: If the fourth argument is undefined, sections are gathered for any status.
9552: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9553:
1.374 raeburn 9554: Returns section hash (keys are section IDs, values are
9555: number of users in each section), subject to the
1.419 raeburn 9556: optional roles filter, optional status filter
1.233 raeburn 9557:
9558: =cut
9559:
9560: ###############################################
9561: sub get_sections {
1.419 raeburn 9562: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9563: if (!defined($cdom) || !defined($cnum)) {
9564: my $cid = $env{'request.course.id'};
9565:
9566: return if (!defined($cid));
9567:
9568: $cdom = $env{'course.'.$cid.'.domain'};
9569: $cnum = $env{'course.'.$cid.'.num'};
9570: }
9571:
9572: my %sectioncount;
1.419 raeburn 9573: my $now = time;
1.240 albertel 9574:
1.1118 raeburn 9575: my $check_students = 1;
9576: my $only_students = 0;
9577: if (ref($possible_roles) eq 'ARRAY') {
9578: if (grep(/^st$/,@{$possible_roles})) {
9579: if (@{$possible_roles} == 1) {
9580: $only_students = 1;
9581: }
9582: } else {
9583: $check_students = 0;
9584: }
9585: }
9586:
9587: if ($check_students) {
1.276 albertel 9588: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9589: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9590: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9591: my $start_index = &Apache::loncoursedata::CL_START();
9592: my $end_index = &Apache::loncoursedata::CL_END();
9593: my $status;
1.366 albertel 9594: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9595: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9596: $data->[$status_index],
9597: $data->[$start_index],
9598: $data->[$end_index]);
9599: if ($stu_status eq 'Active') {
9600: $status = 'active';
9601: } elsif ($end < $now) {
9602: $status = 'previous';
9603: } elsif ($start > $now) {
9604: $status = 'future';
9605: }
9606: if ($section ne '-1' && $section !~ /^\s*$/) {
9607: if ((!defined($possible_status)) || (($status ne '') &&
9608: (grep/^\Q$status\E$/,@{$possible_status}))) {
9609: $sectioncount{$section}++;
9610: }
1.240 albertel 9611: }
9612: }
9613: }
1.1118 raeburn 9614: if ($only_students) {
9615: return %sectioncount;
9616: }
1.240 albertel 9617: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9618: foreach my $user (sort(keys(%courseroles))) {
9619: if ($user !~ /^(\w{2})/) { next; }
9620: my ($role) = ($user =~ /^(\w{2})/);
9621: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9622: my ($section,$status);
1.240 albertel 9623: if ($role eq 'cr' &&
9624: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9625: $section=$1;
9626: }
9627: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9628: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9629: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9630: if ($end == -1 && $start == -1) {
9631: next; #deleted role
9632: }
9633: if (!defined($possible_status)) {
9634: $sectioncount{$section}++;
9635: } else {
9636: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9637: $status = 'active';
9638: } elsif ($end < $now) {
9639: $status = 'future';
9640: } elsif ($start > $now) {
9641: $status = 'previous';
9642: }
9643: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9644: $sectioncount{$section}++;
9645: }
9646: }
1.233 raeburn 9647: }
1.366 albertel 9648: return %sectioncount;
1.233 raeburn 9649: }
9650:
1.274 raeburn 9651: ###############################################
1.294 raeburn 9652:
9653: =pod
1.405 albertel 9654:
9655: =item * &get_course_users()
9656:
1.275 raeburn 9657: Retrieves usernames:domains for users in the specified course
9658: with specific role(s), and access status.
9659:
9660: Incoming parameters:
1.277 albertel 9661: 1. course domain
9662: 2. course number
9663: 3. access status: users must have - either active,
1.275 raeburn 9664: previous, future, or all.
1.277 albertel 9665: 4. reference to array of permissible roles
1.288 raeburn 9666: 5. reference to array of section restrictions (optional)
9667: 6. reference to results object (hash of hashes).
9668: 7. reference to optional userdata hash
1.609 raeburn 9669: 8. reference to optional statushash
1.630 raeburn 9670: 9. flag if privileged users (except those set to unhide in
9671: course settings) should be excluded
1.609 raeburn 9672: Keys of top level results hash are roles.
1.275 raeburn 9673: Keys of inner hashes are username:domain, with
9674: values set to access type.
1.288 raeburn 9675: Optional userdata hash returns an array with arguments in the
9676: same order as loncoursedata::get_classlist() for student data.
9677:
1.609 raeburn 9678: Optional statushash returns
9679:
1.288 raeburn 9680: Entries for end, start, section and status are blank because
9681: of the possibility of multiple values for non-student roles.
9682:
1.275 raeburn 9683: =cut
1.405 albertel 9684:
1.275 raeburn 9685: ###############################################
1.405 albertel 9686:
1.275 raeburn 9687: sub get_course_users {
1.630 raeburn 9688: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9689: my %idx = ();
1.419 raeburn 9690: my %seclists;
1.288 raeburn 9691:
9692: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9693: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9694: $idx{end} = &Apache::loncoursedata::CL_END();
9695: $idx{start} = &Apache::loncoursedata::CL_START();
9696: $idx{id} = &Apache::loncoursedata::CL_ID();
9697: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9698: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9699: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9700:
1.290 albertel 9701: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9702: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9703: my $now = time;
1.277 albertel 9704: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9705: my $match = 0;
1.412 raeburn 9706: my $secmatch = 0;
1.419 raeburn 9707: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9708: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9709: if ($section eq '') {
9710: $section = 'none';
9711: }
1.291 albertel 9712: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9713: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9714: $secmatch = 1;
9715: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9716: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9717: $secmatch = 1;
9718: }
9719: } else {
1.419 raeburn 9720: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9721: $secmatch = 1;
9722: }
1.290 albertel 9723: }
1.412 raeburn 9724: if (!$secmatch) {
9725: next;
9726: }
1.419 raeburn 9727: }
1.275 raeburn 9728: if (defined($$types{'active'})) {
1.288 raeburn 9729: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9730: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9731: $match = 1;
1.275 raeburn 9732: }
9733: }
9734: if (defined($$types{'previous'})) {
1.609 raeburn 9735: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9736: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9737: $match = 1;
1.275 raeburn 9738: }
9739: }
9740: if (defined($$types{'future'})) {
1.609 raeburn 9741: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9742: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9743: $match = 1;
1.275 raeburn 9744: }
9745: }
1.609 raeburn 9746: if ($match) {
9747: push(@{$seclists{$student}},$section);
9748: if (ref($userdata) eq 'HASH') {
9749: $$userdata{$student} = $$classlist{$student};
9750: }
9751: if (ref($statushash) eq 'HASH') {
9752: $statushash->{$student}{'st'}{$section} = $status;
9753: }
1.288 raeburn 9754: }
1.275 raeburn 9755: }
9756: }
1.412 raeburn 9757: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9758: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9759: my $now = time;
1.609 raeburn 9760: my %displaystatus = ( previous => 'Expired',
9761: active => 'Active',
9762: future => 'Future',
9763: );
1.1121 raeburn 9764: my (%nothide,@possdoms);
1.630 raeburn 9765: if ($hidepriv) {
9766: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9767: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9768: if ($user !~ /:/) {
9769: $nothide{join(':',split(/[\@]/,$user))}=1;
9770: } else {
9771: $nothide{$user} = 1;
9772: }
9773: }
1.1121 raeburn 9774: my @possdoms = ($cdom);
9775: if ($coursehash{'checkforpriv'}) {
9776: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9777: }
1.630 raeburn 9778: }
1.439 raeburn 9779: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9780: my $match = 0;
1.412 raeburn 9781: my $secmatch = 0;
1.439 raeburn 9782: my $status;
1.412 raeburn 9783: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9784: $user =~ s/:$//;
1.439 raeburn 9785: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9786: if ($end == -1 || $start == -1) {
9787: next;
9788: }
9789: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9790: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9791: my ($uname,$udom) = split(/:/,$user);
9792: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9793: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9794: $secmatch = 1;
9795: } elsif ($usec eq '') {
1.420 albertel 9796: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9797: $secmatch = 1;
9798: }
9799: } else {
9800: if (grep(/^\Q$usec\E$/,@{$sections})) {
9801: $secmatch = 1;
9802: }
9803: }
9804: if (!$secmatch) {
9805: next;
9806: }
1.288 raeburn 9807: }
1.419 raeburn 9808: if ($usec eq '') {
9809: $usec = 'none';
9810: }
1.275 raeburn 9811: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9812: if ($hidepriv) {
1.1121 raeburn 9813: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9814: (!$nothide{$uname.':'.$udom})) {
9815: next;
9816: }
9817: }
1.503 raeburn 9818: if ($end > 0 && $end < $now) {
1.439 raeburn 9819: $status = 'previous';
9820: } elsif ($start > $now) {
9821: $status = 'future';
9822: } else {
9823: $status = 'active';
9824: }
1.277 albertel 9825: foreach my $type (keys(%{$types})) {
1.275 raeburn 9826: if ($status eq $type) {
1.420 albertel 9827: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9828: push(@{$$users{$role}{$user}},$type);
9829: }
1.288 raeburn 9830: $match = 1;
9831: }
9832: }
1.419 raeburn 9833: if (($match) && (ref($userdata) eq 'HASH')) {
9834: if (!exists($$userdata{$uname.':'.$udom})) {
9835: &get_user_info($udom,$uname,\%idx,$userdata);
9836: }
1.420 albertel 9837: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9838: push(@{$seclists{$uname.':'.$udom}},$usec);
9839: }
1.609 raeburn 9840: if (ref($statushash) eq 'HASH') {
9841: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9842: }
1.275 raeburn 9843: }
9844: }
9845: }
9846: }
1.290 albertel 9847: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9848: if ((defined($cdom)) && (defined($cnum))) {
9849: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9850: if ( defined($csettings{'internal.courseowner'}) ) {
9851: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9852: next if ($owner eq '');
9853: my ($ownername,$ownerdom);
9854: if ($owner =~ /^([^:]+):([^:]+)$/) {
9855: $ownername = $1;
9856: $ownerdom = $2;
9857: } else {
9858: $ownername = $owner;
9859: $ownerdom = $cdom;
9860: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9861: }
9862: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9863: if (defined($userdata) &&
1.609 raeburn 9864: !exists($$userdata{$owner})) {
9865: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9866: if (!grep(/^none$/,@{$seclists{$owner}})) {
9867: push(@{$seclists{$owner}},'none');
9868: }
9869: if (ref($statushash) eq 'HASH') {
9870: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9871: }
1.290 albertel 9872: }
1.279 raeburn 9873: }
9874: }
9875: }
1.419 raeburn 9876: foreach my $user (keys(%seclists)) {
9877: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9878: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9879: }
1.275 raeburn 9880: }
9881: return;
9882: }
9883:
1.288 raeburn 9884: sub get_user_info {
9885: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9886: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9887: &plainname($uname,$udom,'lastname');
1.291 albertel 9888: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9889: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9890: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9891: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9892: return;
9893: }
1.275 raeburn 9894:
1.472 raeburn 9895: ###############################################
9896:
9897: =pod
9898:
9899: =item * &get_user_quota()
9900:
1.1134 raeburn 9901: Retrieves quota assigned for storage of user files.
9902: Default is to report quota for portfolio files.
1.472 raeburn 9903:
9904: Incoming parameters:
9905: 1. user's username
9906: 2. user's domain
1.1134 raeburn 9907: 3. quota name - portfolio, author, or course
1.1136 raeburn 9908: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 9909: 4. crstype - official, unofficial, textbook, placement or community,
9910: if quota name is course
1.472 raeburn 9911:
9912: Returns:
1.1163 raeburn 9913: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9914: 2. (Optional) Type of setting: custom or default
9915: (individually assigned or default for user's
9916: institutional status).
9917: 3. (Optional) - User's institutional status (e.g., faculty, staff
9918: or student - types as defined in localenroll::inst_usertypes
9919: for user's domain, which determines default quota for user.
9920: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9921:
9922: If a value has been stored in the user's environment,
1.536 raeburn 9923: it will return that, otherwise it returns the maximal default
1.1134 raeburn 9924: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9925:
9926: =cut
9927:
9928: ###############################################
9929:
9930:
9931: sub get_user_quota {
1.1136 raeburn 9932: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9933: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9934: if (!defined($udom)) {
9935: $udom = $env{'user.domain'};
9936: }
9937: if (!defined($uname)) {
9938: $uname = $env{'user.name'};
9939: }
9940: if (($udom eq '' || $uname eq '') ||
9941: ($udom eq 'public') && ($uname eq 'public')) {
9942: $quota = 0;
1.536 raeburn 9943: $quotatype = 'default';
9944: $defquota = 0;
1.472 raeburn 9945: } else {
1.536 raeburn 9946: my $inststatus;
1.1134 raeburn 9947: if ($quotaname eq 'course') {
9948: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9949: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9950: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9951: } else {
9952: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9953: $quota = $cenv{'internal.uploadquota'};
9954: }
1.536 raeburn 9955: } else {
1.1134 raeburn 9956: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9957: if ($quotaname eq 'author') {
9958: $quota = $env{'environment.authorquota'};
9959: } else {
9960: $quota = $env{'environment.portfolioquota'};
9961: }
9962: $inststatus = $env{'environment.inststatus'};
9963: } else {
9964: my %userenv =
9965: &Apache::lonnet::get('environment',['portfolioquota',
9966: 'authorquota','inststatus'],$udom,$uname);
9967: my ($tmp) = keys(%userenv);
9968: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9969: if ($quotaname eq 'author') {
9970: $quota = $userenv{'authorquota'};
9971: } else {
9972: $quota = $userenv{'portfolioquota'};
9973: }
9974: $inststatus = $userenv{'inststatus'};
9975: } else {
9976: undef(%userenv);
9977: }
9978: }
9979: }
9980: if ($quota eq '' || wantarray) {
9981: if ($quotaname eq 'course') {
9982: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 9983: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 9984: ($crstype eq 'community') || ($crstype eq 'textbook') ||
9985: ($crstype eq 'placement')) {
1.1136 raeburn 9986: $defquota = $domdefs{$crstype.'quota'};
9987: }
9988: if ($defquota eq '') {
9989: $defquota = 500;
9990: }
1.1134 raeburn 9991: } else {
9992: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9993: }
9994: if ($quota eq '') {
9995: $quota = $defquota;
9996: $quotatype = 'default';
9997: } else {
9998: $quotatype = 'custom';
9999: }
1.472 raeburn 10000: }
10001: }
1.536 raeburn 10002: if (wantarray) {
10003: return ($quota,$quotatype,$settingstatus,$defquota);
10004: } else {
10005: return $quota;
10006: }
1.472 raeburn 10007: }
10008:
10009: ###############################################
10010:
10011: =pod
10012:
10013: =item * &default_quota()
10014:
1.536 raeburn 10015: Retrieves default quota assigned for storage of user portfolio files,
10016: given an (optional) user's institutional status.
1.472 raeburn 10017:
10018: Incoming parameters:
1.1142 raeburn 10019:
1.472 raeburn 10020: 1. domain
1.536 raeburn 10021: 2. (Optional) institutional status(es). This is a : separated list of
10022: status types (e.g., faculty, staff, student etc.)
10023: which apply to the user for whom the default is being retrieved.
10024: If the institutional status string in undefined, the domain
1.1134 raeburn 10025: default quota will be returned.
10026: 3. quota name - portfolio, author, or course
10027: (if no quota name provided, defaults to portfolio).
1.472 raeburn 10028:
10029: Returns:
1.1142 raeburn 10030:
1.1163 raeburn 10031: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 10032: 2. (Optional) institutional type which determined the value of the
10033: default quota.
1.472 raeburn 10034:
10035: If a value has been stored in the domain's configuration db,
10036: it will return that, otherwise it returns 20 (for backwards
10037: compatibility with domains which have not set up a configuration
1.1163 raeburn 10038: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 10039:
1.536 raeburn 10040: If the user's status includes multiple types (e.g., staff and student),
10041: the largest default quota which applies to the user determines the
10042: default quota returned.
10043:
1.472 raeburn 10044: =cut
10045:
10046: ###############################################
10047:
10048:
10049: sub default_quota {
1.1134 raeburn 10050: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 10051: my ($defquota,$settingstatus);
10052: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 10053: ['quotas'],$udom);
1.1134 raeburn 10054: my $key = 'defaultquota';
10055: if ($quotaname eq 'author') {
10056: $key = 'authorquota';
10057: }
1.622 raeburn 10058: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 10059: if ($inststatus ne '') {
1.765 raeburn 10060: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 10061: foreach my $item (@statuses) {
1.1134 raeburn 10062: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10063: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 10064: if ($defquota eq '') {
1.1134 raeburn 10065: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10066: $settingstatus = $item;
1.1134 raeburn 10067: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
10068: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 10069: $settingstatus = $item;
10070: }
10071: }
1.1134 raeburn 10072: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10073: if ($quotahash{'quotas'}{$item} ne '') {
10074: if ($defquota eq '') {
10075: $defquota = $quotahash{'quotas'}{$item};
10076: $settingstatus = $item;
10077: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
10078: $defquota = $quotahash{'quotas'}{$item};
10079: $settingstatus = $item;
10080: }
1.536 raeburn 10081: }
10082: }
10083: }
10084: }
10085: if ($defquota eq '') {
1.1134 raeburn 10086: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
10087: $defquota = $quotahash{'quotas'}{$key}{'default'};
10088: } elsif ($key eq 'defaultquota') {
1.711 raeburn 10089: $defquota = $quotahash{'quotas'}{'default'};
10090: }
1.536 raeburn 10091: $settingstatus = 'default';
1.1139 raeburn 10092: if ($defquota eq '') {
10093: if ($quotaname eq 'author') {
10094: $defquota = 500;
10095: }
10096: }
1.536 raeburn 10097: }
10098: } else {
10099: $settingstatus = 'default';
1.1134 raeburn 10100: if ($quotaname eq 'author') {
10101: $defquota = 500;
10102: } else {
10103: $defquota = 20;
10104: }
1.536 raeburn 10105: }
10106: if (wantarray) {
10107: return ($defquota,$settingstatus);
1.472 raeburn 10108: } else {
1.536 raeburn 10109: return $defquota;
1.472 raeburn 10110: }
10111: }
10112:
1.1135 raeburn 10113: ###############################################
10114:
10115: =pod
10116:
1.1136 raeburn 10117: =item * &excess_filesize_warning()
1.1135 raeburn 10118:
10119: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 10120: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 10121: space to be exceeded.
1.1136 raeburn 10122:
10123: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 10124: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 10125:
1.1165 raeburn 10126: Inputs: 7
1.1136 raeburn 10127: 1. username or coursenum
1.1135 raeburn 10128: 2. domain
1.1136 raeburn 10129: 3. context ('author' or 'course')
1.1135 raeburn 10130: 4. filename of file for which action is being requested
10131: 5. filesize (kB) of file
10132: 6. action being taken: copy or upload.
1.1237 raeburn 10133: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 10134:
10135: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 10136: otherwise return null.
10137:
10138: =back
1.1135 raeburn 10139:
10140: =cut
10141:
1.1136 raeburn 10142: sub excess_filesize_warning {
1.1165 raeburn 10143: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 10144: my $current_disk_usage = 0;
1.1165 raeburn 10145: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 10146: if ($context eq 'author') {
10147: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
10148: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
10149: } else {
10150: foreach my $subdir ('docs','supplemental') {
10151: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
10152: }
10153: }
1.1135 raeburn 10154: $disk_quota = int($disk_quota * 1000);
10155: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 10156: return '<p class="LC_warning">'.
1.1135 raeburn 10157: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 10158: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
10159: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 10160: $disk_quota,$current_disk_usage).
10161: '</p>';
10162: }
10163: return;
10164: }
10165:
10166: ###############################################
10167:
10168:
1.1136 raeburn 10169:
10170:
1.384 raeburn 10171: sub get_secgrprole_info {
10172: my ($cdom,$cnum,$needroles,$type) = @_;
10173: my %sections_count = &get_sections($cdom,$cnum);
10174: my @sections = (sort {$a <=> $b} keys(%sections_count));
10175: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10176: my @groups = sort(keys(%curr_groups));
10177: my $allroles = [];
10178: my $rolehash;
10179: my $accesshash = {
10180: active => 'Currently has access',
10181: future => 'Will have future access',
10182: previous => 'Previously had access',
10183: };
10184: if ($needroles) {
10185: $rolehash = {'all' => 'all'};
1.385 albertel 10186: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10187: if (&Apache::lonnet::error(%user_roles)) {
10188: undef(%user_roles);
10189: }
10190: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10191: my ($role)=split(/\:/,$item,2);
10192: if ($role eq 'cr') { next; }
10193: if ($role =~ /^cr/) {
10194: $$rolehash{$role} = (split('/',$role))[3];
10195: } else {
10196: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10197: }
10198: }
10199: foreach my $key (sort(keys(%{$rolehash}))) {
10200: push(@{$allroles},$key);
10201: }
10202: push (@{$allroles},'st');
10203: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10204: }
10205: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10206: }
10207:
1.555 raeburn 10208: sub user_picker {
1.1279 raeburn 10209: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10210: my $currdom = $dom;
1.1253 raeburn 10211: my @alldoms = &Apache::lonnet::all_domains();
10212: if (@alldoms == 1) {
10213: my %domsrch = &Apache::lonnet::get_dom('configuration',
10214: ['directorysrch'],$alldoms[0]);
10215: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10216: my $showdom = $domdesc;
10217: if ($showdom eq '') {
10218: $showdom = $dom;
10219: }
10220: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10221: if ((!$domsrch{'directorysrch'}{'available'}) &&
10222: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10223: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10224: }
10225: }
10226: }
1.555 raeburn 10227: my %curr_selected = (
10228: srchin => 'dom',
1.580 raeburn 10229: srchby => 'lastname',
1.555 raeburn 10230: );
10231: my $srchterm;
1.625 raeburn 10232: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10233: if ($srch->{'srchby'} ne '') {
10234: $curr_selected{'srchby'} = $srch->{'srchby'};
10235: }
10236: if ($srch->{'srchin'} ne '') {
10237: $curr_selected{'srchin'} = $srch->{'srchin'};
10238: }
10239: if ($srch->{'srchtype'} ne '') {
10240: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10241: }
10242: if ($srch->{'srchdomain'} ne '') {
10243: $currdom = $srch->{'srchdomain'};
10244: }
10245: $srchterm = $srch->{'srchterm'};
10246: }
1.1222 damieng 10247: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10248: 'usr' => 'Search criteria',
1.563 raeburn 10249: 'doma' => 'Domain/institution to search',
1.558 albertel 10250: 'uname' => 'username',
10251: 'lastname' => 'last name',
1.555 raeburn 10252: 'lastfirst' => 'last name, first name',
1.558 albertel 10253: 'crs' => 'in this course',
1.576 raeburn 10254: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10255: 'alc' => 'all LON-CAPA',
1.573 raeburn 10256: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10257: 'exact' => 'is',
10258: 'contains' => 'contains',
1.569 raeburn 10259: 'begins' => 'begins with',
1.1222 damieng 10260: );
10261: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10262: 'youm' => "You must include some text to search for.",
10263: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10264: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10265: 'yomc' => "You must choose a domain when using an institutional directory search.",
10266: 'ymcd' => "You must choose a domain when using a domain search.",
10267: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10268: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10269: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10270: );
1.1222 damieng 10271: &html_escape(\%html_lt);
10272: &js_escape(\%js_lt);
1.1255 raeburn 10273: my $domform;
1.1277 raeburn 10274: my $allow_blank = 1;
1.1255 raeburn 10275: if ($fixeddom) {
1.1277 raeburn 10276: $allow_blank = 0;
10277: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10278: } else {
1.1287 raeburn 10279: my $defdom = $env{'request.role.domain'};
1.1288 raeburn 10280: my ($trusted,$untrusted);
1.1287 raeburn 10281: if (($context eq 'requestcrs') || ($context eq 'course')) {
1.1288 raeburn 10282: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('enroll',$defdom);
1.1287 raeburn 10283: } elsif ($context eq 'author') {
1.1288 raeburn 10284: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('othcoau',$defdom);
1.1287 raeburn 10285: } elsif ($context eq 'domain') {
1.1288 raeburn 10286: ($trusted,$untrusted) = &Apache::lonnet::trusted_domains('domroles',$defdom);
1.1287 raeburn 10287: }
1.1288 raeburn 10288: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,$trusted,$untrusted);
1.1255 raeburn 10289: }
1.563 raeburn 10290: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10291:
10292: my @srchins = ('crs','dom','alc','instd');
10293:
10294: foreach my $option (@srchins) {
10295: # FIXME 'alc' option unavailable until
10296: # loncreateuser::print_user_query_page()
10297: # has been completed.
10298: next if ($option eq 'alc');
1.880 raeburn 10299: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10300: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 10301: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10302: if ($curr_selected{'srchin'} eq $option) {
10303: $srchinsel .= '
1.1222 damieng 10304: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10305: } else {
10306: $srchinsel .= '
1.1222 damieng 10307: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10308: }
1.555 raeburn 10309: }
1.563 raeburn 10310: $srchinsel .= "\n </select>\n";
1.555 raeburn 10311:
10312: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10313: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10314: if ($curr_selected{'srchby'} eq $option) {
10315: $srchbysel .= '
1.1222 damieng 10316: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10317: } else {
10318: $srchbysel .= '
1.1222 damieng 10319: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10320: }
10321: }
10322: $srchbysel .= "\n </select>\n";
10323:
10324: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10325: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10326: if ($curr_selected{'srchtype'} eq $option) {
10327: $srchtypesel .= '
1.1222 damieng 10328: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10329: } else {
10330: $srchtypesel .= '
1.1222 damieng 10331: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10332: }
10333: }
10334: $srchtypesel .= "\n </select>\n";
10335:
1.558 albertel 10336: my ($newuserscript,$new_user_create);
1.994 raeburn 10337: my $context_dom = $env{'request.role.domain'};
10338: if ($context eq 'requestcrs') {
10339: if ($env{'form.coursedom'} ne '') {
10340: $context_dom = $env{'form.coursedom'};
10341: }
10342: }
1.556 raeburn 10343: if ($forcenewuser) {
1.576 raeburn 10344: if (ref($srch) eq 'HASH') {
1.994 raeburn 10345: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10346: if ($cancreate) {
10347: $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>';
10348: } else {
1.799 bisitz 10349: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10350: my %usertypetext = (
10351: official => 'institutional',
10352: unofficial => 'non-institutional',
10353: );
1.799 bisitz 10354: $new_user_create = '<p class="LC_warning">'
10355: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10356: .' '
10357: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10358: ,'<a href="'.$helplink.'">','</a>')
10359: .'</p><br />';
1.627 raeburn 10360: }
1.576 raeburn 10361: }
10362: }
10363:
1.556 raeburn 10364: $newuserscript = <<"ENDSCRIPT";
10365:
1.570 raeburn 10366: function setSearch(createnew,callingForm) {
1.556 raeburn 10367: if (createnew == 1) {
1.570 raeburn 10368: for (var i=0; i<callingForm.srchby.length; i++) {
10369: if (callingForm.srchby.options[i].value == 'uname') {
10370: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10371: }
10372: }
1.570 raeburn 10373: for (var i=0; i<callingForm.srchin.length; i++) {
10374: if ( callingForm.srchin.options[i].value == 'dom') {
10375: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10376: }
10377: }
1.570 raeburn 10378: for (var i=0; i<callingForm.srchtype.length; i++) {
10379: if (callingForm.srchtype.options[i].value == 'exact') {
10380: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10381: }
10382: }
1.570 raeburn 10383: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10384: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10385: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10386: }
10387: }
10388: }
10389: }
10390: ENDSCRIPT
1.558 albertel 10391:
1.556 raeburn 10392: }
10393:
1.555 raeburn 10394: my $output = <<"END_BLOCK";
1.556 raeburn 10395: <script type="text/javascript">
1.824 bisitz 10396: // <![CDATA[
1.570 raeburn 10397: function validateEntry(callingForm) {
1.558 albertel 10398:
1.556 raeburn 10399: var checkok = 1;
1.558 albertel 10400: var srchin;
1.570 raeburn 10401: for (var i=0; i<callingForm.srchin.length; i++) {
10402: if ( callingForm.srchin[i].checked ) {
10403: srchin = callingForm.srchin[i].value;
1.558 albertel 10404: }
10405: }
10406:
1.570 raeburn 10407: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10408: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10409: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10410: var srchterm = callingForm.srchterm.value;
10411: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10412: var msg = "";
10413:
10414: if (srchterm == "") {
10415: checkok = 0;
1.1222 damieng 10416: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10417: }
10418:
1.569 raeburn 10419: if (srchtype== 'begins') {
10420: if (srchterm.length < 2) {
10421: checkok = 0;
1.1222 damieng 10422: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10423: }
10424: }
10425:
1.556 raeburn 10426: if (srchtype== 'contains') {
10427: if (srchterm.length < 3) {
10428: checkok = 0;
1.1222 damieng 10429: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10430: }
10431: }
10432: if (srchin == 'instd') {
10433: if (srchdomain == '') {
10434: checkok = 0;
1.1222 damieng 10435: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10436: }
10437: }
10438: if (srchin == 'dom') {
10439: if (srchdomain == '') {
10440: checkok = 0;
1.1222 damieng 10441: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10442: }
10443: }
10444: if (srchby == 'lastfirst') {
10445: if (srchterm.indexOf(",") == -1) {
10446: checkok = 0;
1.1222 damieng 10447: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10448: }
10449: if (srchterm.indexOf(",") == srchterm.length -1) {
10450: checkok = 0;
1.1222 damieng 10451: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10452: }
10453: }
10454: if (checkok == 0) {
1.1222 damieng 10455: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10456: return;
10457: }
10458: if (checkok == 1) {
1.570 raeburn 10459: callingForm.submit();
1.556 raeburn 10460: }
10461: }
10462:
10463: $newuserscript
10464:
1.824 bisitz 10465: // ]]>
1.556 raeburn 10466: </script>
1.558 albertel 10467:
10468: $new_user_create
10469:
1.555 raeburn 10470: END_BLOCK
1.558 albertel 10471:
1.876 raeburn 10472: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10473: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10474: $domform.
10475: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10476: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10477: $srchbysel.
10478: $srchtypesel.
10479: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10480: $srchinsel.
10481: &Apache::lonhtmlcommon::row_closure(1).
10482: &Apache::lonhtmlcommon::end_pick_box().
10483: '<br />';
1.1253 raeburn 10484: return ($output,1);
1.555 raeburn 10485: }
10486:
1.612 raeburn 10487: sub user_rule_check {
1.615 raeburn 10488: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10489: my ($response,%inst_response);
1.612 raeburn 10490: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10491: if (keys(%{$usershash}) > 1) {
10492: my (%by_username,%by_id,%userdoms);
10493: my $checkid;
10494: if (ref($checks) eq 'HASH') {
10495: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10496: $checkid = 1;
10497: }
10498: }
10499: foreach my $user (keys(%{$usershash})) {
10500: my ($uname,$udom) = split(/:/,$user);
10501: if ($checkid) {
10502: if (ref($usershash->{$user}) eq 'HASH') {
10503: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10504: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10505: $userdoms{$udom} = 1;
1.1227 raeburn 10506: if (ref($inst_results) eq 'HASH') {
10507: $inst_results->{$uname.':'.$udom} = {};
10508: }
1.1226 raeburn 10509: }
10510: }
10511: } else {
10512: $by_username{$udom}{$uname} = 1;
10513: $userdoms{$udom} = 1;
1.1227 raeburn 10514: if (ref($inst_results) eq 'HASH') {
10515: $inst_results->{$uname.':'.$udom} = {};
10516: }
1.1226 raeburn 10517: }
10518: }
10519: foreach my $udom (keys(%userdoms)) {
10520: if (!$got_rules->{$udom}) {
10521: my %domconfig = &Apache::lonnet::get_dom('configuration',
10522: ['usercreation'],$udom);
10523: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10524: foreach my $item ('username','id') {
10525: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10526: $$curr_rules{$udom}{$item} =
10527: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10528: }
10529: }
10530: }
10531: $got_rules->{$udom} = 1;
10532: }
1.612 raeburn 10533: }
1.1226 raeburn 10534: if ($checkid) {
10535: foreach my $udom (keys(%by_id)) {
10536: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10537: if ($outcome eq 'ok') {
1.1227 raeburn 10538: foreach my $id (keys(%{$by_id{$udom}})) {
10539: my $uname = $by_id{$udom}{$id};
10540: $inst_response{$uname.':'.$udom} = $outcome;
10541: }
1.1226 raeburn 10542: if (ref($results) eq 'HASH') {
10543: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10544: if (exists($inst_response{$uname.':'.$udom})) {
10545: $inst_response{$uname.':'.$udom} = $outcome;
10546: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10547: }
1.1226 raeburn 10548: }
10549: }
10550: }
1.612 raeburn 10551: }
1.615 raeburn 10552: } else {
1.1226 raeburn 10553: foreach my $udom (keys(%by_username)) {
10554: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10555: if ($outcome eq 'ok') {
1.1227 raeburn 10556: foreach my $uname (keys(%{$by_username{$udom}})) {
10557: $inst_response{$uname.':'.$udom} = $outcome;
10558: }
1.1226 raeburn 10559: if (ref($results) eq 'HASH') {
10560: foreach my $uname (keys(%{$results})) {
10561: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10562: }
10563: }
10564: }
10565: }
1.612 raeburn 10566: }
1.1226 raeburn 10567: } elsif (keys(%{$usershash}) == 1) {
10568: my $user = (keys(%{$usershash}))[0];
10569: my ($uname,$udom) = split(/:/,$user);
10570: if (($udom ne '') && ($uname ne '')) {
10571: if (ref($usershash->{$user}) eq 'HASH') {
10572: if (ref($checks) eq 'HASH') {
10573: if (defined($checks->{'username'})) {
10574: ($inst_response{$user},%{$inst_results->{$user}}) =
10575: &Apache::lonnet::get_instuser($udom,$uname);
10576: } elsif (defined($checks->{'id'})) {
10577: if ($usershash->{$user}->{'id'} ne '') {
10578: ($inst_response{$user},%{$inst_results->{$user}}) =
10579: &Apache::lonnet::get_instuser($udom,undef,
10580: $usershash->{$user}->{'id'});
10581: } else {
10582: ($inst_response{$user},%{$inst_results->{$user}}) =
10583: &Apache::lonnet::get_instuser($udom,$uname);
10584: }
1.585 raeburn 10585: }
1.1226 raeburn 10586: } else {
10587: ($inst_response{$user},%{$inst_results->{$user}}) =
10588: &Apache::lonnet::get_instuser($udom,$uname);
10589: return;
10590: }
10591: if (!$got_rules->{$udom}) {
10592: my %domconfig = &Apache::lonnet::get_dom('configuration',
10593: ['usercreation'],$udom);
10594: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10595: foreach my $item ('username','id') {
10596: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10597: $$curr_rules{$udom}{$item} =
10598: $domconfig{'usercreation'}{$item.'_rule'};
10599: }
10600: }
10601: }
10602: $got_rules->{$udom} = 1;
1.585 raeburn 10603: }
10604: }
1.1226 raeburn 10605: } else {
10606: return;
10607: }
10608: } else {
10609: return;
10610: }
10611: foreach my $user (keys(%{$usershash})) {
10612: my ($uname,$udom) = split(/:/,$user);
10613: next if (($udom eq '') || ($uname eq ''));
10614: my $id;
1.1227 raeburn 10615: if (ref($inst_results) eq 'HASH') {
10616: if (ref($inst_results->{$user}) eq 'HASH') {
10617: $id = $inst_results->{$user}->{'id'};
10618: }
10619: }
10620: if ($id eq '') {
10621: if (ref($usershash->{$user})) {
10622: $id = $usershash->{$user}->{'id'};
10623: }
1.585 raeburn 10624: }
1.612 raeburn 10625: foreach my $item (keys(%{$checks})) {
10626: if (ref($$curr_rules{$udom}) eq 'HASH') {
10627: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10628: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10629: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10630: $$curr_rules{$udom}{$item});
1.612 raeburn 10631: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10632: if ($rule_check{$rule}) {
10633: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10634: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10635: if (ref($inst_results) eq 'HASH') {
10636: if (ref($inst_results->{$user}) eq 'HASH') {
10637: if (keys(%{$inst_results->{$user}}) == 0) {
10638: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10639: } elsif ($item eq 'id') {
10640: if ($inst_results->{$user}->{'id'} eq '') {
10641: $$alerts{$item}{$udom}{$uname} = 1;
10642: }
1.615 raeburn 10643: }
1.612 raeburn 10644: }
10645: }
1.615 raeburn 10646: }
10647: last;
1.585 raeburn 10648: }
10649: }
10650: }
10651: }
10652: }
10653: }
10654: }
10655: }
1.612 raeburn 10656: return;
10657: }
10658:
10659: sub user_rule_formats {
10660: my ($domain,$domdesc,$curr_rules,$check) = @_;
10661: my %text = (
10662: 'username' => 'Usernames',
10663: 'id' => 'IDs',
10664: );
10665: my $output;
10666: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10667: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10668: if (@{$ruleorder} > 0) {
1.1102 raeburn 10669: $output = '<br />'.
10670: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10671: '<span class="LC_cusr_emph">','</span>',$domdesc).
10672: ' <ul>';
1.612 raeburn 10673: foreach my $rule (@{$ruleorder}) {
10674: if (ref($curr_rules) eq 'ARRAY') {
10675: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10676: if (ref($rules->{$rule}) eq 'HASH') {
10677: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10678: $rules->{$rule}{'desc'}.'</li>';
10679: }
10680: }
10681: }
10682: }
10683: $output .= '</ul>';
10684: }
10685: }
10686: return $output;
10687: }
10688:
10689: sub instrule_disallow_msg {
1.615 raeburn 10690: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10691: my $response;
10692: my %text = (
10693: item => 'username',
10694: items => 'usernames',
10695: match => 'matches',
10696: do => 'does',
10697: action => 'a username',
10698: one => 'one',
10699: );
10700: if ($count > 1) {
10701: $text{'item'} = 'usernames';
10702: $text{'match'} ='match';
10703: $text{'do'} = 'do';
10704: $text{'action'} = 'usernames',
10705: $text{'one'} = 'ones';
10706: }
10707: if ($checkitem eq 'id') {
10708: $text{'items'} = 'IDs';
10709: $text{'item'} = 'ID';
10710: $text{'action'} = 'an ID';
1.615 raeburn 10711: if ($count > 1) {
10712: $text{'item'} = 'IDs';
10713: $text{'action'} = 'IDs';
10714: }
1.612 raeburn 10715: }
1.674 bisitz 10716: $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 10717: if ($mode eq 'upload') {
10718: if ($checkitem eq 'username') {
10719: $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'}.");
10720: } elsif ($checkitem eq 'id') {
1.674 bisitz 10721: $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 10722: }
1.669 raeburn 10723: } elsif ($mode eq 'selfcreate') {
10724: if ($checkitem eq 'id') {
10725: $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.");
10726: }
1.615 raeburn 10727: } else {
10728: if ($checkitem eq 'username') {
10729: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10730: } elsif ($checkitem eq 'id') {
10731: $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.");
10732: }
1.612 raeburn 10733: }
10734: return $response;
1.585 raeburn 10735: }
10736:
1.624 raeburn 10737: sub personal_data_fieldtitles {
10738: my %fieldtitles = &Apache::lonlocal::texthash (
10739: id => 'Student/Employee ID',
10740: permanentemail => 'E-mail address',
10741: lastname => 'Last Name',
10742: firstname => 'First Name',
10743: middlename => 'Middle Name',
10744: generation => 'Generation',
10745: gen => 'Generation',
1.765 raeburn 10746: inststatus => 'Affiliation',
1.624 raeburn 10747: );
10748: return %fieldtitles;
10749: }
10750:
1.642 raeburn 10751: sub sorted_inst_types {
10752: my ($dom) = @_;
1.1185 raeburn 10753: my ($usertypes,$order);
10754: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10755: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10756: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10757: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10758: } else {
10759: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10760: }
1.642 raeburn 10761: my $othertitle = &mt('All users');
10762: if ($env{'request.course.id'}) {
1.668 raeburn 10763: $othertitle = &mt('Any users');
1.642 raeburn 10764: }
10765: my @types;
10766: if (ref($order) eq 'ARRAY') {
10767: @types = @{$order};
10768: }
10769: if (@types == 0) {
10770: if (ref($usertypes) eq 'HASH') {
10771: @types = sort(keys(%{$usertypes}));
10772: }
10773: }
10774: if (keys(%{$usertypes}) > 0) {
10775: $othertitle = &mt('Other users');
10776: }
10777: return ($othertitle,$usertypes,\@types);
10778: }
10779:
1.645 raeburn 10780: sub get_institutional_codes {
10781: my ($settings,$allcourses,$LC_code) = @_;
10782: # Get complete list of course sections to update
10783: my @currsections = ();
10784: my @currxlists = ();
10785: my $coursecode = $$settings{'internal.coursecode'};
10786:
10787: if ($$settings{'internal.sectionnums'} ne '') {
10788: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10789: }
10790:
10791: if ($$settings{'internal.crosslistings'} ne '') {
10792: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10793: }
10794:
10795: if (@currxlists > 0) {
10796: foreach (@currxlists) {
10797: if (m/^([^:]+):(\w*)$/) {
10798: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 10799: push(@{$allcourses},$1);
1.645 raeburn 10800: $$LC_code{$1} = $2;
10801: }
10802: }
10803: }
10804: }
10805:
10806: if (@currsections > 0) {
10807: foreach (@currsections) {
10808: if (m/^(\w+):(\w*)$/) {
10809: my $sec = $coursecode.$1;
10810: my $lc_sec = $2;
10811: unless (grep/^$sec$/,@{$allcourses}) {
1.1263 raeburn 10812: push(@{$allcourses},$sec);
1.645 raeburn 10813: $$LC_code{$sec} = $lc_sec;
10814: }
10815: }
10816: }
10817: }
10818: return;
10819: }
10820:
1.971 raeburn 10821: sub get_standard_codeitems {
10822: return ('Year','Semester','Department','Number','Section');
10823: }
10824:
1.112 bowersj2 10825: =pod
10826:
1.780 raeburn 10827: =head1 Slot Helpers
10828:
10829: =over 4
10830:
10831: =item * sorted_slots()
10832:
1.1040 raeburn 10833: Sorts an array of slot names in order of an optional sort key,
10834: default sort is by slot start time (earliest first).
1.780 raeburn 10835:
10836: Inputs:
10837:
10838: =over 4
10839:
10840: slotsarr - Reference to array of unsorted slot names.
10841:
10842: slots - Reference to hash of hash, where outer hash keys are slot names.
10843:
1.1040 raeburn 10844: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10845:
1.549 albertel 10846: =back
10847:
1.780 raeburn 10848: Returns:
10849:
10850: =over 4
10851:
1.1040 raeburn 10852: sorted - An array of slot names sorted by a specified sort key
10853: (default sort key is start time of the slot).
1.780 raeburn 10854:
10855: =back
10856:
10857: =cut
10858:
10859:
10860: sub sorted_slots {
1.1040 raeburn 10861: my ($slotsarr,$slots,$sortkey) = @_;
10862: if ($sortkey eq '') {
10863: $sortkey = 'starttime';
10864: }
1.780 raeburn 10865: my @sorted;
10866: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10867: @sorted =
10868: sort {
10869: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10870: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10871: }
10872: if (ref($slots->{$a})) { return -1;}
10873: if (ref($slots->{$b})) { return 1;}
10874: return 0;
10875: } @{$slotsarr};
10876: }
10877: return @sorted;
10878: }
10879:
1.1040 raeburn 10880: =pod
10881:
10882: =item * get_future_slots()
10883:
10884: Inputs:
10885:
10886: =over 4
10887:
10888: cnum - course number
10889:
10890: cdom - course domain
10891:
10892: now - current UNIX time
10893:
10894: symb - optional symb
10895:
10896: =back
10897:
10898: Returns:
10899:
10900: =over 4
10901:
10902: sorted_reservable - ref to array of student_schedulable slots currently
10903: reservable, ordered by end date of reservation period.
10904:
10905: reservable_now - ref to hash of student_schedulable slots currently
10906: reservable.
10907:
10908: Keys in inner hash are:
10909: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10910: (b) endreserve: end date of reservation period.
10911: (c) uniqueperiod: start,end dates when slot is to be uniquely
10912: selected.
1.1040 raeburn 10913:
10914: sorted_future - ref to array of student_schedulable slots reservable in
10915: the future, ordered by start date of reservation period.
10916:
10917: future_reservable - ref to hash of student_schedulable slots reservable
10918: in the future.
10919:
10920: Keys in inner hash are:
10921: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10922: (b) startreserve: start date of reservation period.
10923: (c) uniqueperiod: start,end dates when slot is to be uniquely
10924: selected.
1.1040 raeburn 10925:
10926: =back
10927:
10928: =cut
10929:
10930: sub get_future_slots {
10931: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 10932: my $map;
10933: if ($symb) {
10934: ($map) = &Apache::lonnet::decode_symb($symb);
10935: }
1.1040 raeburn 10936: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10937: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10938: foreach my $slot (keys(%slots)) {
10939: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10940: if ($symb) {
1.1229 raeburn 10941: if ($slots{$slot}->{'symb'} ne '') {
10942: my $canuse;
10943: my %oksymbs;
10944: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
10945: map { $oksymbs{$_} = 1; } @slotsymbs;
10946: if ($oksymbs{$symb}) {
10947: $canuse = 1;
10948: } else {
10949: foreach my $item (@slotsymbs) {
10950: if ($item =~ /\.(page|sequence)$/) {
10951: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
10952: if (($map ne '') && ($map eq $sloturl)) {
10953: $canuse = 1;
10954: last;
10955: }
10956: }
10957: }
10958: }
10959: next unless ($canuse);
10960: }
1.1040 raeburn 10961: }
10962: if (($slots{$slot}->{'starttime'} > $now) &&
10963: ($slots{$slot}->{'endtime'} > $now)) {
10964: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10965: my $userallowed = 0;
10966: if ($slots{$slot}->{'allowedsections'}) {
10967: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10968: if (!defined($env{'request.role.sec'})
10969: && grep(/^No section assigned$/,@allowed_sec)) {
10970: $userallowed=1;
10971: } else {
10972: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10973: $userallowed=1;
10974: }
10975: }
10976: unless ($userallowed) {
10977: if (defined($env{'request.course.groups'})) {
10978: my @groups = split(/:/,$env{'request.course.groups'});
10979: foreach my $group (@groups) {
10980: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10981: $userallowed=1;
10982: last;
10983: }
10984: }
10985: }
10986: }
10987: }
10988: if ($slots{$slot}->{'allowedusers'}) {
10989: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10990: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10991: if (grep(/^\Q$user\E$/,@allowed_users)) {
10992: $userallowed = 1;
10993: }
10994: }
10995: next unless($userallowed);
10996: }
10997: my $startreserve = $slots{$slot}->{'startreserve'};
10998: my $endreserve = $slots{$slot}->{'endreserve'};
10999: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 11000: my $uniqueperiod;
11001: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
11002: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
11003: }
1.1040 raeburn 11004: if (($startreserve < $now) &&
11005: (!$endreserve || $endreserve > $now)) {
11006: my $lastres = $endreserve;
11007: if (!$lastres) {
11008: $lastres = $slots{$slot}->{'starttime'};
11009: }
11010: $reservable_now{$slot} = {
11011: symb => $symb,
1.1250 raeburn 11012: endreserve => $lastres,
11013: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11014: };
11015: } elsif (($startreserve > $now) &&
11016: (!$endreserve || $endreserve > $startreserve)) {
11017: $future_reservable{$slot} = {
11018: symb => $symb,
1.1250 raeburn 11019: startreserve => $startreserve,
11020: uniqueperiod => $uniqueperiod,
1.1040 raeburn 11021: };
11022: }
11023: }
11024: }
11025: my @unsorted_reservable = keys(%reservable_now);
11026: if (@unsorted_reservable > 0) {
11027: @sorted_reservable =
11028: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
11029: }
11030: my @unsorted_future = keys(%future_reservable);
11031: if (@unsorted_future > 0) {
11032: @sorted_future =
11033: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
11034: }
11035: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
11036: }
1.780 raeburn 11037:
11038: =pod
11039:
1.1057 foxr 11040: =back
11041:
1.549 albertel 11042: =head1 HTTP Helpers
11043:
11044: =over 4
11045:
1.648 raeburn 11046: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 11047:
1.258 albertel 11048: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 11049: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 11050: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 11051:
11052: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
11053: $possible_names is an ref to an array of form element names. As an example:
11054: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 11055: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 11056:
11057: =cut
1.1 albertel 11058:
1.6 albertel 11059: sub get_unprocessed_cgi {
1.25 albertel 11060: my ($query,$possible_names)= @_;
1.26 matthew 11061: # $Apache::lonxml::debug=1;
1.356 albertel 11062: foreach my $pair (split(/&/,$query)) {
11063: my ($name, $value) = split(/=/,$pair);
1.369 www 11064: $name = &unescape($name);
1.25 albertel 11065: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
11066: $value =~ tr/+/ /;
11067: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 11068: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 11069: }
1.16 harris41 11070: }
1.6 albertel 11071: }
11072:
1.112 bowersj2 11073: =pod
11074:
1.648 raeburn 11075: =item * &cacheheader()
1.112 bowersj2 11076:
11077: returns cache-controlling header code
11078:
11079: =cut
11080:
1.7 albertel 11081: sub cacheheader {
1.258 albertel 11082: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 11083: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
11084: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 11085: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
11086: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 11087: return $output;
1.7 albertel 11088: }
11089:
1.112 bowersj2 11090: =pod
11091:
1.648 raeburn 11092: =item * &no_cache($r)
1.112 bowersj2 11093:
11094: specifies header code to not have cache
11095:
11096: =cut
11097:
1.9 albertel 11098: sub no_cache {
1.216 albertel 11099: my ($r) = @_;
11100: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 11101: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 11102: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
11103: $r->no_cache(1);
11104: $r->header_out("Expires" => $date);
11105: $r->header_out("Pragma" => "no-cache");
1.123 www 11106: }
11107:
11108: sub content_type {
1.181 albertel 11109: my ($r,$type,$charset) = @_;
1.299 foxr 11110: if ($r) {
11111: # Note that printout.pl calls this with undef for $r.
11112: &no_cache($r);
11113: }
1.258 albertel 11114: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 11115: unless ($charset) {
11116: $charset=&Apache::lonlocal::current_encoding;
11117: }
11118: if ($charset) { $type.='; charset='.$charset; }
11119: if ($r) {
11120: $r->content_type($type);
11121: } else {
11122: print("Content-type: $type\n\n");
11123: }
1.9 albertel 11124: }
1.25 albertel 11125:
1.112 bowersj2 11126: =pod
11127:
1.648 raeburn 11128: =item * &add_to_env($name,$value)
1.112 bowersj2 11129:
1.258 albertel 11130: adds $name to the %env hash with value
1.112 bowersj2 11131: $value, if $name already exists, the entry is converted to an array
11132: reference and $value is added to the array.
11133:
11134: =cut
11135:
1.25 albertel 11136: sub add_to_env {
11137: my ($name,$value)=@_;
1.258 albertel 11138: if (defined($env{$name})) {
11139: if (ref($env{$name})) {
1.25 albertel 11140: #already have multiple values
1.258 albertel 11141: push(@{ $env{$name} },$value);
1.25 albertel 11142: } else {
11143: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 11144: my $first=$env{$name};
11145: undef($env{$name});
11146: push(@{ $env{$name} },$first,$value);
1.25 albertel 11147: }
11148: } else {
1.258 albertel 11149: $env{$name}=$value;
1.25 albertel 11150: }
1.31 albertel 11151: }
1.149 albertel 11152:
11153: =pod
11154:
1.648 raeburn 11155: =item * &get_env_multiple($name)
1.149 albertel 11156:
1.258 albertel 11157: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 11158: values may be defined and end up as an array ref.
11159:
11160: returns an array of values
11161:
11162: =cut
11163:
11164: sub get_env_multiple {
11165: my ($name) = @_;
11166: my @values;
1.258 albertel 11167: if (defined($env{$name})) {
1.149 albertel 11168: # exists is it an array
1.258 albertel 11169: if (ref($env{$name})) {
11170: @values=@{ $env{$name} };
1.149 albertel 11171: } else {
1.258 albertel 11172: $values[0]=$env{$name};
1.149 albertel 11173: }
11174: }
11175: return(@values);
11176: }
11177:
1.1249 damieng 11178: # Looks at given dependencies, and returns something depending on the context.
11179: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11180: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11181: # For all other contexts, returns ($output, $counter, $numpathchg).
11182: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11183: # $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.
11184: # $numpathchg: integer with the number of cleaned up dependency paths.
11185: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11186: # \%mapping: hash reference clean path -> original path for all dependencies.
11187: # @param {string} actionurl - The path to the handler, indicative of the context.
11188: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11189: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11190: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11191: # @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)
11192: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11193: sub ask_for_embedded_content {
1.1249 damieng 11194: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11195: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11196: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11197: %currsubfile,%unused,$rem);
1.1071 raeburn 11198: my $counter = 0;
11199: my $numnew = 0;
1.987 raeburn 11200: my $numremref = 0;
11201: my $numinvalid = 0;
11202: my $numpathchg = 0;
11203: my $numexisting = 0;
1.1071 raeburn 11204: my $numunused = 0;
11205: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11206: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11207: my $heading = &mt('Upload embedded files');
11208: my $buttontext = &mt('Upload');
11209:
1.1249 damieng 11210: # fills these variables based on the context:
11211: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11212: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11213: if ($env{'request.course.id'}) {
1.1123 raeburn 11214: if ($actionurl eq '/adm/dependencies') {
11215: $navmap = Apache::lonnavmaps::navmap->new();
11216: }
11217: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11218: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11219: }
1.1123 raeburn 11220: if (($actionurl eq '/adm/portfolio') ||
11221: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11222: my $current_path='/';
11223: if ($env{'form.currentpath'}) {
11224: $current_path = $env{'form.currentpath'};
11225: }
11226: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11227: $udom = $cdom;
11228: $uname = $cnum;
1.984 raeburn 11229: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11230: } else {
11231: $udom = $env{'user.domain'};
11232: $uname = $env{'user.name'};
11233: $url = '/userfiles/portfolio';
11234: }
1.987 raeburn 11235: $toplevel = $url.'/';
1.984 raeburn 11236: $url .= $current_path;
11237: $getpropath = 1;
1.987 raeburn 11238: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11239: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11240: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11241: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11242: $toplevel = $url;
1.984 raeburn 11243: if ($rest ne '') {
1.987 raeburn 11244: $url .= $rest;
11245: }
11246: } elsif ($actionurl eq '/adm/coursedocs') {
11247: if (ref($args) eq 'HASH') {
1.1071 raeburn 11248: $url = $args->{'docs_url'};
11249: $toplevel = $url;
1.1084 raeburn 11250: if ($args->{'context'} eq 'paste') {
11251: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11252: ($path) =
11253: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11254: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11255: $fileloc =~ s{^/}{};
11256: }
1.1071 raeburn 11257: }
1.1084 raeburn 11258: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11259: if ($env{'request.course.id'} ne '') {
11260: if (ref($args) eq 'HASH') {
11261: $url = $args->{'docs_url'};
11262: $title = $args->{'docs_title'};
1.1126 raeburn 11263: $toplevel = $url;
11264: unless ($toplevel =~ m{^/}) {
11265: $toplevel = "/$url";
11266: }
1.1085 raeburn 11267: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11268: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11269: $path = $1;
11270: } else {
11271: ($path) =
11272: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11273: }
1.1195 raeburn 11274: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11275: $fileloc = $toplevel;
11276: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11277: my ($udom,$uname,$fname) =
11278: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11279: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11280: } else {
11281: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11282: }
1.1071 raeburn 11283: $fileloc =~ s{^/}{};
11284: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11285: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11286: }
1.987 raeburn 11287: }
1.1123 raeburn 11288: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11289: $udom = $cdom;
11290: $uname = $cnum;
11291: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11292: $toplevel = $url;
11293: $path = $url;
11294: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11295: $fileloc =~ s{^/}{};
1.987 raeburn 11296: }
1.1249 damieng 11297:
11298: # parses the dependency paths to get some info
11299: # fills $newfiles, $mapping, $subdependencies, $dependencies
11300: # $newfiles: hash URL -> 1 for new files or external URLs
11301: # (will be completed later)
11302: # $mapping:
11303: # for external URLs: external URL -> external URL
11304: # for relative paths: clean path -> original path
11305: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11306: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11307: foreach my $file (keys(%{$allfiles})) {
11308: my $embed_file;
11309: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11310: $embed_file = $1;
11311: } else {
11312: $embed_file = $file;
11313: }
1.1158 raeburn 11314: my ($absolutepath,$cleaned_file);
11315: if ($embed_file =~ m{^\w+://}) {
11316: $cleaned_file = $embed_file;
1.1147 raeburn 11317: $newfiles{$cleaned_file} = 1;
11318: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11319: } else {
1.1158 raeburn 11320: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11321: if ($embed_file =~ m{^/}) {
11322: $absolutepath = $embed_file;
11323: }
1.1147 raeburn 11324: if ($cleaned_file =~ m{/}) {
11325: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11326: $path = &check_for_traversal($path,$url,$toplevel);
11327: my $item = $fname;
11328: if ($path ne '') {
11329: $item = $path.'/'.$fname;
11330: $subdependencies{$path}{$fname} = 1;
11331: } else {
11332: $dependencies{$item} = 1;
11333: }
11334: if ($absolutepath) {
11335: $mapping{$item} = $absolutepath;
11336: } else {
11337: $mapping{$item} = $embed_file;
11338: }
11339: } else {
11340: $dependencies{$embed_file} = 1;
11341: if ($absolutepath) {
1.1147 raeburn 11342: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11343: } else {
1.1147 raeburn 11344: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11345: }
11346: }
1.984 raeburn 11347: }
11348: }
1.1249 damieng 11349:
11350: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11351: # and lists
11352: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11353: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11354: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11355: # the path had to be cleaned up
11356: # $existing: hash clean path -> 1 if the file exists
11357: # $numexisting: number of keys in $existing
11358: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11359: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11360: # dependency subdirectories that are
11361: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11362: my $dirptr = 16384;
1.984 raeburn 11363: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11364: $currsubfile{$path} = {};
1.1123 raeburn 11365: if (($actionurl eq '/adm/portfolio') ||
11366: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11367: my ($sublistref,$listerror) =
11368: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11369: if (ref($sublistref) eq 'ARRAY') {
11370: foreach my $line (@{$sublistref}) {
11371: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11372: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11373: }
1.984 raeburn 11374: }
1.987 raeburn 11375: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11376: if (opendir(my $dir,$url.'/'.$path)) {
11377: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11378: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11379: }
1.1084 raeburn 11380: } elsif (($actionurl eq '/adm/dependencies') ||
11381: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11382: ($args->{'context'} eq 'paste')) ||
11383: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11384: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11385: my $dir;
11386: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11387: $dir = $fileloc;
11388: } else {
11389: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11390: }
1.1071 raeburn 11391: if ($dir ne '') {
11392: my ($sublistref,$listerror) =
11393: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11394: if (ref($sublistref) eq 'ARRAY') {
11395: foreach my $line (@{$sublistref}) {
11396: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11397: undef,$mtime)=split(/\&/,$line,12);
11398: unless (($testdir&$dirptr) ||
11399: ($file_name =~ /^\.\.?$/)) {
11400: $currsubfile{$path}{$file_name} = [$size,$mtime];
11401: }
11402: }
11403: }
11404: }
1.984 raeburn 11405: }
11406: }
11407: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11408: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11409: my $item = $path.'/'.$file;
11410: unless ($mapping{$item} eq $item) {
11411: $pathchanges{$item} = 1;
11412: }
11413: $existing{$item} = 1;
11414: $numexisting ++;
11415: } else {
11416: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11417: }
11418: }
1.1071 raeburn 11419: if ($actionurl eq '/adm/dependencies') {
11420: foreach my $path (keys(%currsubfile)) {
11421: if (ref($currsubfile{$path}) eq 'HASH') {
11422: foreach my $file (keys(%{$currsubfile{$path}})) {
11423: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11424: next if (($rem ne '') &&
11425: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11426: (ref($navmap) &&
11427: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11428: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11429: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11430: $unused{$path.'/'.$file} = 1;
11431: }
11432: }
11433: }
11434: }
11435: }
1.984 raeburn 11436: }
1.1249 damieng 11437:
11438: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11439: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11440: my %currfile;
1.1123 raeburn 11441: if (($actionurl eq '/adm/portfolio') ||
11442: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11443: my ($dirlistref,$listerror) =
11444: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11445: if (ref($dirlistref) eq 'ARRAY') {
11446: foreach my $line (@{$dirlistref}) {
11447: my ($file_name,$rest) = split(/\&/,$line,2);
11448: $currfile{$file_name} = 1;
11449: }
1.984 raeburn 11450: }
1.987 raeburn 11451: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11452: if (opendir(my $dir,$url)) {
1.987 raeburn 11453: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11454: map {$currfile{$_} = 1;} @dir_list;
11455: }
1.1084 raeburn 11456: } elsif (($actionurl eq '/adm/dependencies') ||
11457: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11458: ($args->{'context'} eq 'paste')) ||
11459: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11460: if ($env{'request.course.id'} ne '') {
11461: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11462: if ($dir ne '') {
11463: my ($dirlistref,$listerror) =
11464: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11465: if (ref($dirlistref) eq 'ARRAY') {
11466: foreach my $line (@{$dirlistref}) {
11467: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11468: $size,undef,$mtime)=split(/\&/,$line,12);
11469: unless (($testdir&$dirptr) ||
11470: ($file_name =~ /^\.\.?$/)) {
11471: $currfile{$file_name} = [$size,$mtime];
11472: }
11473: }
11474: }
11475: }
11476: }
1.984 raeburn 11477: }
1.1249 damieng 11478: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11479: # are not in subdirectories, using $currfile
1.984 raeburn 11480: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11481: if (exists($currfile{$file})) {
1.987 raeburn 11482: unless ($mapping{$file} eq $file) {
11483: $pathchanges{$file} = 1;
11484: }
11485: $existing{$file} = 1;
11486: $numexisting ++;
11487: } else {
1.984 raeburn 11488: $newfiles{$file} = 1;
11489: }
11490: }
1.1071 raeburn 11491: foreach my $file (keys(%currfile)) {
11492: unless (($file eq $filename) ||
11493: ($file eq $filename.'.bak') ||
11494: ($dependencies{$file})) {
1.1085 raeburn 11495: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11496: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11497: next if (($rem ne '') &&
11498: (($env{"httpref.$rem".$file} ne '') ||
11499: (ref($navmap) &&
11500: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11501: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11502: ($navmap->getResourceByUrl($rem.$1)))))));
11503: }
1.1085 raeburn 11504: }
1.1071 raeburn 11505: $unused{$file} = 1;
11506: }
11507: }
1.1249 damieng 11508:
11509: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11510: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11511: ($args->{'context'} eq 'paste')) {
11512: $counter = scalar(keys(%existing));
11513: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11514: return ($output,$counter,$numpathchg,\%existing);
11515: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11516: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11517: $counter = scalar(keys(%existing));
11518: $numpathchg = scalar(keys(%pathchanges));
11519: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11520: }
1.1249 damieng 11521:
11522: # returns HTML otherwise, with dependency results and to ask for more uploads
11523:
11524: # $upload_output: missing dependencies (with upload form)
11525: # $modify_output: uploaded dependencies (in use)
11526: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11527: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11528: if ($actionurl eq '/adm/dependencies') {
11529: next if ($embed_file =~ m{^\w+://});
11530: }
1.660 raeburn 11531: $upload_output .= &start_data_table_row().
1.1123 raeburn 11532: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11533: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11534: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11535: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11536: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11537: }
1.1123 raeburn 11538: $upload_output .= '</td>';
1.1071 raeburn 11539: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11540: $upload_output.='<td align="right">'.
11541: '<span class="LC_info LC_fontsize_medium">'.
11542: &mt("URL points to web address").'</span>';
1.987 raeburn 11543: $numremref++;
1.660 raeburn 11544: } elsif ($args->{'error_on_invalid_names'}
11545: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11546: $upload_output.='<td align="right"><span class="LC_warning">'.
11547: &mt('Invalid characters').'</span>';
1.987 raeburn 11548: $numinvalid++;
1.660 raeburn 11549: } else {
1.1123 raeburn 11550: $upload_output .= '<td>'.
11551: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11552: $embed_file,\%mapping,
1.1071 raeburn 11553: $allfiles,$codebase,'upload');
11554: $counter ++;
11555: $numnew ++;
1.987 raeburn 11556: }
11557: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11558: }
11559: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11560: if ($actionurl eq '/adm/dependencies') {
11561: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11562: $modify_output .= &start_data_table_row().
11563: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11564: '<img src="'.&icon($embed_file).'" border="0" />'.
11565: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11566: '<td>'.$size.'</td>'.
11567: '<td>'.$mtime.'</td>'.
11568: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11569: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11570: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11571: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11572: &embedded_file_element('upload_embedded',$counter,
11573: $embed_file,\%mapping,
11574: $allfiles,$codebase,'modify').
11575: '</div></td>'.
11576: &end_data_table_row()."\n";
11577: $counter ++;
11578: } else {
11579: $upload_output .= &start_data_table_row().
1.1123 raeburn 11580: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11581: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11582: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11583: &Apache::loncommon::end_data_table_row()."\n";
11584: }
11585: }
11586: my $delidx = $counter;
11587: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11588: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11589: $delete_output .= &start_data_table_row().
11590: '<td><img src="'.&icon($oldfile).'" />'.
11591: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11592: '<td>'.$size.'</td>'.
11593: '<td>'.$mtime.'</td>'.
11594: '<td><label><input type="checkbox" name="del_upload_dep" '.
11595: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11596: &embedded_file_element('upload_embedded',$delidx,
11597: $oldfile,\%mapping,$allfiles,
11598: $codebase,'delete').'</td>'.
11599: &end_data_table_row()."\n";
11600: $numunused ++;
11601: $delidx ++;
1.987 raeburn 11602: }
11603: if ($upload_output) {
11604: $upload_output = &start_data_table().
11605: $upload_output.
11606: &end_data_table()."\n";
11607: }
1.1071 raeburn 11608: if ($modify_output) {
11609: $modify_output = &start_data_table().
11610: &start_data_table_header_row().
11611: '<th>'.&mt('File').'</th>'.
11612: '<th>'.&mt('Size (KB)').'</th>'.
11613: '<th>'.&mt('Modified').'</th>'.
11614: '<th>'.&mt('Upload replacement?').'</th>'.
11615: &end_data_table_header_row().
11616: $modify_output.
11617: &end_data_table()."\n";
11618: }
11619: if ($delete_output) {
11620: $delete_output = &start_data_table().
11621: &start_data_table_header_row().
11622: '<th>'.&mt('File').'</th>'.
11623: '<th>'.&mt('Size (KB)').'</th>'.
11624: '<th>'.&mt('Modified').'</th>'.
11625: '<th>'.&mt('Delete?').'</th>'.
11626: &end_data_table_header_row().
11627: $delete_output.
11628: &end_data_table()."\n";
11629: }
1.987 raeburn 11630: my $applies = 0;
11631: if ($numremref) {
11632: $applies ++;
11633: }
11634: if ($numinvalid) {
11635: $applies ++;
11636: }
11637: if ($numexisting) {
11638: $applies ++;
11639: }
1.1071 raeburn 11640: if ($counter || $numunused) {
1.987 raeburn 11641: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11642: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11643: $state.'<h3>'.$heading.'</h3>';
11644: if ($actionurl eq '/adm/dependencies') {
11645: if ($numnew) {
11646: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11647: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11648: $upload_output.'<br />'."\n";
11649: }
11650: if ($numexisting) {
11651: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11652: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11653: $modify_output.'<br />'."\n";
11654: $buttontext = &mt('Save changes');
11655: }
11656: if ($numunused) {
11657: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11658: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11659: $delete_output.'<br />'."\n";
11660: $buttontext = &mt('Save changes');
11661: }
11662: } else {
11663: $output .= $upload_output.'<br />'."\n";
11664: }
11665: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11666: $counter.'" />'."\n";
11667: if ($actionurl eq '/adm/dependencies') {
11668: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11669: $numnew.'" />'."\n";
11670: } elsif ($actionurl eq '') {
1.987 raeburn 11671: $output .= '<input type="hidden" name="phase" value="three" />';
11672: }
11673: } elsif ($applies) {
11674: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11675: if ($applies > 1) {
11676: $output .=
1.1123 raeburn 11677: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11678: if ($numremref) {
11679: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11680: }
11681: if ($numinvalid) {
11682: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11683: }
11684: if ($numexisting) {
11685: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11686: }
11687: $output .= '</ul><br />';
11688: } elsif ($numremref) {
11689: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11690: } elsif ($numinvalid) {
11691: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11692: } elsif ($numexisting) {
11693: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11694: }
11695: $output .= $upload_output.'<br />';
11696: }
11697: my ($pathchange_output,$chgcount);
1.1071 raeburn 11698: $chgcount = $counter;
1.987 raeburn 11699: if (keys(%pathchanges) > 0) {
11700: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11701: if ($counter) {
1.987 raeburn 11702: $output .= &embedded_file_element('pathchange',$chgcount,
11703: $embed_file,\%mapping,
1.1071 raeburn 11704: $allfiles,$codebase,'change');
1.987 raeburn 11705: } else {
11706: $pathchange_output .=
11707: &start_data_table_row().
11708: '<td><input type ="checkbox" name="namechange" value="'.
11709: $chgcount.'" checked="checked" /></td>'.
11710: '<td>'.$mapping{$embed_file}.'</td>'.
11711: '<td>'.$embed_file.
11712: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11713: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11714: '</td>'.&end_data_table_row();
1.660 raeburn 11715: }
1.987 raeburn 11716: $numpathchg ++;
11717: $chgcount ++;
1.660 raeburn 11718: }
11719: }
1.1127 raeburn 11720: if (($counter) || ($numunused)) {
1.987 raeburn 11721: if ($numpathchg) {
11722: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11723: $numpathchg.'" />'."\n";
11724: }
11725: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11726: ($actionurl eq '/adm/imsimport')) {
11727: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11728: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11729: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11730: } elsif ($actionurl eq '/adm/dependencies') {
11731: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11732: }
1.1123 raeburn 11733: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11734: } elsif ($numpathchg) {
11735: my %pathchange = ();
11736: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11737: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11738: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11739: }
1.987 raeburn 11740: }
1.1071 raeburn 11741: return ($output,$counter,$numpathchg);
1.987 raeburn 11742: }
11743:
1.1147 raeburn 11744: =pod
11745:
11746: =item * clean_path($name)
11747:
11748: Performs clean-up of directories, subdirectories and filename in an
11749: embedded object, referenced in an HTML file which is being uploaded
11750: to a course or portfolio, where
11751: "Upload embedded images/multimedia files if HTML file" checkbox was
11752: checked.
11753:
11754: Clean-up is similar to replacements in lonnet::clean_filename()
11755: except each / between sub-directory and next level is preserved.
11756:
11757: =cut
11758:
11759: sub clean_path {
11760: my ($embed_file) = @_;
11761: $embed_file =~s{^/+}{};
11762: my @contents;
11763: if ($embed_file =~ m{/}) {
11764: @contents = split(/\//,$embed_file);
11765: } else {
11766: @contents = ($embed_file);
11767: }
11768: my $lastidx = scalar(@contents)-1;
11769: for (my $i=0; $i<=$lastidx; $i++) {
11770: $contents[$i]=~s{\\}{/}g;
11771: $contents[$i]=~s/\s+/\_/g;
11772: $contents[$i]=~s{[^/\w\.\-]}{}g;
11773: if ($i == $lastidx) {
11774: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11775: }
11776: }
11777: if ($lastidx > 0) {
11778: return join('/',@contents);
11779: } else {
11780: return $contents[0];
11781: }
11782: }
11783:
1.987 raeburn 11784: sub embedded_file_element {
1.1071 raeburn 11785: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11786: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11787: (ref($codebase) eq 'HASH'));
11788: my $output;
1.1071 raeburn 11789: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11790: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11791: }
11792: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11793: &escape($embed_file).'" />';
11794: unless (($context eq 'upload_embedded') &&
11795: ($mapping->{$embed_file} eq $embed_file)) {
11796: $output .='
11797: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11798: }
11799: my $attrib;
11800: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11801: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11802: }
11803: $output .=
11804: "\n\t\t".
11805: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11806: $attrib.'" />';
11807: if (exists($codebase->{$mapping->{$embed_file}})) {
11808: $output .=
11809: "\n\t\t".
11810: '<input name="codebase_'.$num.'" type="hidden" value="'.
11811: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11812: }
1.987 raeburn 11813: return $output;
1.660 raeburn 11814: }
11815:
1.1071 raeburn 11816: sub get_dependency_details {
11817: my ($currfile,$currsubfile,$embed_file) = @_;
11818: my ($size,$mtime,$showsize,$showmtime);
11819: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11820: if ($embed_file =~ m{/}) {
11821: my ($path,$fname) = split(/\//,$embed_file);
11822: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11823: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11824: }
11825: } else {
11826: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11827: ($size,$mtime) = @{$currfile->{$embed_file}};
11828: }
11829: }
11830: $showsize = $size/1024.0;
11831: $showsize = sprintf("%.1f",$showsize);
11832: if ($mtime > 0) {
11833: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11834: }
11835: }
11836: return ($showsize,$showmtime);
11837: }
11838:
11839: sub ask_embedded_js {
11840: return <<"END";
11841: <script type="text/javascript"">
11842: // <![CDATA[
11843: function toggleBrowse(counter) {
11844: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11845: var fileid = document.getElementById('embedded_item_'+counter);
11846: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11847: if (chkboxid.checked == true) {
11848: uploaddivid.style.display='block';
11849: } else {
11850: uploaddivid.style.display='none';
11851: fileid.value = '';
11852: }
11853: }
11854: // ]]>
11855: </script>
11856:
11857: END
11858: }
11859:
1.661 raeburn 11860: sub upload_embedded {
11861: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11862: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11863: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11864: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11865: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11866: my $orig_uploaded_filename =
11867: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11868: foreach my $type ('orig','ref','attrib','codebase') {
11869: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11870: $env{'form.embedded_'.$type.'_'.$i} =
11871: &unescape($env{'form.embedded_'.$type.'_'.$i});
11872: }
11873: }
1.661 raeburn 11874: my ($path,$fname) =
11875: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11876: # no path, whole string is fname
11877: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11878: $fname = &Apache::lonnet::clean_filename($fname);
11879: # See if there is anything left
11880: next if ($fname eq '');
11881:
11882: # Check if file already exists as a file or directory.
11883: my ($state,$msg);
11884: if ($context eq 'portfolio') {
11885: my $port_path = $dirpath;
11886: if ($group ne '') {
11887: $port_path = "groups/$group/$port_path";
11888: }
1.987 raeburn 11889: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11890: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11891: $dir_root,$port_path,$disk_quota,
11892: $current_disk_usage,$uname,$udom);
11893: if ($state eq 'will_exceed_quota'
1.984 raeburn 11894: || $state eq 'file_locked') {
1.661 raeburn 11895: $output .= $msg;
11896: next;
11897: }
11898: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11899: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11900: if ($state eq 'exists') {
11901: $output .= $msg;
11902: next;
11903: }
11904: }
11905: # Check if extension is valid
11906: if (($fname =~ /\.(\w+)$/) &&
11907: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 11908: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11909: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11910: next;
11911: } elsif (($fname =~ /\.(\w+)$/) &&
11912: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11913: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11914: next;
11915: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 11916: $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 11917: next;
11918: }
11919: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 11920: my $subdir = $path;
11921: $subdir =~ s{/+$}{};
1.661 raeburn 11922: if ($context eq 'portfolio') {
1.984 raeburn 11923: my $result;
11924: if ($state eq 'existingfile') {
11925: $result=
11926: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 11927: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11928: } else {
1.984 raeburn 11929: $result=
11930: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11931: $dirpath.
1.1123 raeburn 11932: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11933: if ($result !~ m|^/uploaded/|) {
11934: $output .= '<span class="LC_error">'
11935: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11936: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11937: .'</span><br />';
11938: next;
11939: } else {
1.987 raeburn 11940: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11941: $path.$fname.'</span>').'<br />';
1.984 raeburn 11942: }
1.661 raeburn 11943: }
1.1123 raeburn 11944: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 11945: my $extendedsubdir = $dirpath.'/'.$subdir;
11946: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11947: my $result =
1.1126 raeburn 11948: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11949: if ($result !~ m|^/uploaded/|) {
11950: $output .= '<span class="LC_error">'
11951: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11952: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11953: .'</span><br />';
11954: next;
11955: } else {
11956: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11957: $path.$fname.'</span>').'<br />';
1.1125 raeburn 11958: if ($context eq 'syllabus') {
11959: &Apache::lonnet::make_public_indefinitely($result);
11960: }
1.987 raeburn 11961: }
1.661 raeburn 11962: } else {
11963: # Save the file
11964: my $target = $env{'form.embedded_item_'.$i};
11965: my $fullpath = $dir_root.$dirpath.'/'.$path;
11966: my $dest = $fullpath.$fname;
11967: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11968: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11969: my $count;
11970: my $filepath = $dir_root;
1.1027 raeburn 11971: foreach my $subdir (@parts) {
11972: $filepath .= "/$subdir";
11973: if (!-e $filepath) {
1.661 raeburn 11974: mkdir($filepath,0770);
11975: }
11976: }
11977: my $fh;
11978: if (!open($fh,'>'.$dest)) {
11979: &Apache::lonnet::logthis('Failed to create '.$dest);
11980: $output .= '<span class="LC_error">'.
1.1071 raeburn 11981: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11982: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11983: '</span><br />';
11984: } else {
11985: if (!print $fh $env{'form.embedded_item_'.$i}) {
11986: &Apache::lonnet::logthis('Failed to write to '.$dest);
11987: $output .= '<span class="LC_error">'.
1.1071 raeburn 11988: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11989: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11990: '</span><br />';
11991: } else {
1.987 raeburn 11992: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11993: $url.'</span>').'<br />';
11994: unless ($context eq 'testbank') {
11995: $footer .= &mt('View embedded file: [_1]',
11996: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11997: }
11998: }
11999: close($fh);
12000: }
12001: }
12002: if ($env{'form.embedded_ref_'.$i}) {
12003: $pathchange{$i} = 1;
12004: }
12005: }
12006: if ($output) {
12007: $output = '<p>'.$output.'</p>';
12008: }
12009: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
12010: $returnflag = 'ok';
1.1071 raeburn 12011: my $numpathchgs = scalar(keys(%pathchange));
12012: if ($numpathchgs > 0) {
1.987 raeburn 12013: if ($context eq 'portfolio') {
12014: $output .= '<p>'.&mt('or').'</p>';
12015: } elsif ($context eq 'testbank') {
1.1071 raeburn 12016: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
12017: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 12018: $returnflag = 'modify_orightml';
12019: }
12020: }
1.1071 raeburn 12021: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 12022: }
12023:
12024: sub modify_html_form {
12025: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
12026: my $end = 0;
12027: my $modifyform;
12028: if ($context eq 'upload_embedded') {
12029: return unless (ref($pathchange) eq 'HASH');
12030: if ($env{'form.number_embedded_items'}) {
12031: $end += $env{'form.number_embedded_items'};
12032: }
12033: if ($env{'form.number_pathchange_items'}) {
12034: $end += $env{'form.number_pathchange_items'};
12035: }
12036: if ($end) {
12037: for (my $i=0; $i<$end; $i++) {
12038: if ($i < $env{'form.number_embedded_items'}) {
12039: next unless($pathchange->{$i});
12040: }
12041: $modifyform .=
12042: &start_data_table_row().
12043: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
12044: 'checked="checked" /></td>'.
12045: '<td>'.$env{'form.embedded_ref_'.$i}.
12046: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
12047: &escape($env{'form.embedded_ref_'.$i}).'" />'.
12048: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
12049: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
12050: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
12051: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
12052: '<td>'.$env{'form.embedded_orig_'.$i}.
12053: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
12054: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
12055: &end_data_table_row();
1.1071 raeburn 12056: }
1.987 raeburn 12057: }
12058: } else {
12059: $modifyform = $pathchgtable;
12060: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
12061: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
12062: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
12063: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
12064: }
12065: }
12066: if ($modifyform) {
1.1071 raeburn 12067: if ($actionurl eq '/adm/dependencies') {
12068: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
12069: }
1.987 raeburn 12070: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
12071: '<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".
12072: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
12073: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
12074: '</ol></p>'."\n".'<p>'.
12075: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
12076: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
12077: &start_data_table()."\n".
12078: &start_data_table_header_row().
12079: '<th>'.&mt('Change?').'</th>'.
12080: '<th>'.&mt('Current reference').'</th>'.
12081: '<th>'.&mt('Required reference').'</th>'.
12082: &end_data_table_header_row()."\n".
12083: $modifyform.
12084: &end_data_table().'<br />'."\n".$hiddenstate.
12085: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
12086: '</form>'."\n";
12087: }
12088: return;
12089: }
12090:
12091: sub modify_html_refs {
1.1123 raeburn 12092: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 12093: my $container;
12094: if ($context eq 'portfolio') {
12095: $container = $env{'form.container'};
12096: } elsif ($context eq 'coursedoc') {
12097: $container = $env{'form.primaryurl'};
1.1071 raeburn 12098: } elsif ($context eq 'manage_dependencies') {
12099: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
12100: $container = "/$container";
1.1123 raeburn 12101: } elsif ($context eq 'syllabus') {
12102: $container = $url;
1.987 raeburn 12103: } else {
1.1027 raeburn 12104: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 12105: }
12106: my (%allfiles,%codebase,$output,$content);
12107: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 12108: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 12109: if (wantarray) {
12110: return ('',0,0);
12111: } else {
12112: return;
12113: }
12114: }
12115: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12116: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 12117: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
12118: if (wantarray) {
12119: return ('',0,0);
12120: } else {
12121: return;
12122: }
12123: }
1.987 raeburn 12124: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 12125: if ($content eq '-1') {
12126: if (wantarray) {
12127: return ('',0,0);
12128: } else {
12129: return;
12130: }
12131: }
1.987 raeburn 12132: } else {
1.1071 raeburn 12133: unless ($container =~ /^\Q$dir_root\E/) {
12134: if (wantarray) {
12135: return ('',0,0);
12136: } else {
12137: return;
12138: }
12139: }
1.987 raeburn 12140: if (open(my $fh,"<$container")) {
12141: $content = join('', <$fh>);
12142: close($fh);
12143: } else {
1.1071 raeburn 12144: if (wantarray) {
12145: return ('',0,0);
12146: } else {
12147: return;
12148: }
1.987 raeburn 12149: }
12150: }
12151: my ($count,$codebasecount) = (0,0);
12152: my $mm = new File::MMagic;
12153: my $mime_type = $mm->checktype_contents($content);
12154: if ($mime_type eq 'text/html') {
12155: my $parse_result =
12156: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
12157: \%codebase,\$content);
12158: if ($parse_result eq 'ok') {
12159: foreach my $i (@changes) {
12160: my $orig = &unescape($env{'form.embedded_orig_'.$i});
12161: my $ref = &unescape($env{'form.embedded_ref_'.$i});
12162: if ($allfiles{$ref}) {
12163: my $newname = $orig;
12164: my ($attrib_regexp,$codebase);
1.1006 raeburn 12165: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 12166: if ($attrib_regexp =~ /:/) {
12167: $attrib_regexp =~ s/\:/|/g;
12168: }
12169: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12170: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12171: $count += $numchg;
1.1123 raeburn 12172: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12173: delete($allfiles{$ref});
1.987 raeburn 12174: }
12175: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12176: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12177: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12178: $codebasecount ++;
12179: }
12180: }
12181: }
1.1123 raeburn 12182: my $skiprewrites;
1.987 raeburn 12183: if ($count || $codebasecount) {
12184: my $saveresult;
1.1071 raeburn 12185: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12186: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12187: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12188: if ($url eq $container) {
12189: my ($fname) = ($container =~ m{/([^/]+)$});
12190: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12191: $count,'<span class="LC_filename">'.
1.1071 raeburn 12192: $fname.'</span>').'</p>';
1.987 raeburn 12193: } else {
12194: $output = '<p class="LC_error">'.
12195: &mt('Error: update failed for: [_1].',
12196: '<span class="LC_filename">'.
12197: $container.'</span>').'</p>';
12198: }
1.1123 raeburn 12199: if ($context eq 'syllabus') {
12200: unless ($saveresult eq 'ok') {
12201: $skiprewrites = 1;
12202: }
12203: }
1.987 raeburn 12204: } else {
12205: if (open(my $fh,">$container")) {
12206: print $fh $content;
12207: close($fh);
12208: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12209: $count,'<span class="LC_filename">'.
12210: $container.'</span>').'</p>';
1.661 raeburn 12211: } else {
1.987 raeburn 12212: $output = '<p class="LC_error">'.
12213: &mt('Error: could not update [_1].',
12214: '<span class="LC_filename">'.
12215: $container.'</span>').'</p>';
1.661 raeburn 12216: }
12217: }
12218: }
1.1123 raeburn 12219: if (($context eq 'syllabus') && (!$skiprewrites)) {
12220: my ($actionurl,$state);
12221: $actionurl = "/public/$udom/$uname/syllabus";
12222: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12223: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12224: \%codebase,
12225: {'context' => 'rewrites',
12226: 'ignore_remote_references' => 1,});
12227: if (ref($mapping) eq 'HASH') {
12228: my $rewrites = 0;
12229: foreach my $key (keys(%{$mapping})) {
12230: next if ($key =~ m{^https?://});
12231: my $ref = $mapping->{$key};
12232: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12233: my $attrib;
12234: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12235: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12236: }
12237: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12238: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12239: $rewrites += $numchg;
12240: }
12241: }
12242: if ($rewrites) {
12243: my $saveresult;
12244: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12245: if ($url eq $container) {
12246: my ($fname) = ($container =~ m{/([^/]+)$});
12247: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12248: $count,'<span class="LC_filename">'.
12249: $fname.'</span>').'</p>';
12250: } else {
12251: $output .= '<p class="LC_error">'.
12252: &mt('Error: could not update links in [_1].',
12253: '<span class="LC_filename">'.
12254: $container.'</span>').'</p>';
12255:
12256: }
12257: }
12258: }
12259: }
1.987 raeburn 12260: } else {
12261: &logthis('Failed to parse '.$container.
12262: ' to modify references: '.$parse_result);
1.661 raeburn 12263: }
12264: }
1.1071 raeburn 12265: if (wantarray) {
12266: return ($output,$count,$codebasecount);
12267: } else {
12268: return $output;
12269: }
1.661 raeburn 12270: }
12271:
12272: sub check_for_existing {
12273: my ($path,$fname,$element) = @_;
12274: my ($state,$msg);
12275: if (-d $path.'/'.$fname) {
12276: $state = 'exists';
12277: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12278: } elsif (-e $path.'/'.$fname) {
12279: $state = 'exists';
12280: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12281: }
12282: if ($state eq 'exists') {
12283: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12284: }
12285: return ($state,$msg);
12286: }
12287:
12288: sub check_for_upload {
12289: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12290: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12291: my $filesize = length($env{'form.'.$element});
12292: if (!$filesize) {
12293: my $msg = '<span class="LC_error">'.
12294: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12295: '<span class="LC_filename">'.$fname.'</span>',
12296: $filesize).'<br />'.
1.1007 raeburn 12297: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12298: '</span>';
12299: return ('zero_bytes',$msg);
12300: }
12301: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12302: my $getpropath = 1;
1.1021 raeburn 12303: my ($dirlistref,$listerror) =
12304: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12305: my $found_file = 0;
12306: my $locked_file = 0;
1.991 raeburn 12307: my @lockers;
12308: my $navmap;
12309: if ($env{'request.course.id'}) {
12310: $navmap = Apache::lonnavmaps::navmap->new();
12311: }
1.1021 raeburn 12312: if (ref($dirlistref) eq 'ARRAY') {
12313: foreach my $line (@{$dirlistref}) {
12314: my ($file_name,$rest)=split(/\&/,$line,2);
12315: if ($file_name eq $fname){
12316: $file_name = $path.$file_name;
12317: if ($group ne '') {
12318: $file_name = $group.$file_name;
12319: }
12320: $found_file = 1;
12321: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12322: foreach my $lock (@lockers) {
12323: if (ref($lock) eq 'ARRAY') {
12324: my ($symb,$crsid) = @{$lock};
12325: if ($crsid eq $env{'request.course.id'}) {
12326: if (ref($navmap)) {
12327: my $res = $navmap->getBySymb($symb);
12328: foreach my $part (@{$res->parts()}) {
12329: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12330: unless (($slot_status == $res->RESERVED) ||
12331: ($slot_status == $res->RESERVED_LOCATION)) {
12332: $locked_file = 1;
12333: }
1.991 raeburn 12334: }
1.1021 raeburn 12335: } else {
12336: $locked_file = 1;
1.991 raeburn 12337: }
12338: } else {
12339: $locked_file = 1;
12340: }
12341: }
1.1021 raeburn 12342: }
12343: } else {
12344: my @info = split(/\&/,$rest);
12345: my $currsize = $info[6]/1000;
12346: if ($currsize < $filesize) {
12347: my $extra = $filesize - $currsize;
12348: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12349: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12350: &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 12351: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12352: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12353: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12354: return ('will_exceed_quota',$msg);
12355: }
1.984 raeburn 12356: }
12357: }
1.661 raeburn 12358: }
12359: }
12360: }
12361: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12362: my $msg = '<p class="LC_warning">'.
12363: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12364: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12365: return ('will_exceed_quota',$msg);
12366: } elsif ($found_file) {
12367: if ($locked_file) {
1.1179 bisitz 12368: my $msg = '<p class="LC_warning">';
1.661 raeburn 12369: $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 12370: $msg .= '</p>';
1.661 raeburn 12371: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12372: return ('file_locked',$msg);
12373: } else {
1.1179 bisitz 12374: my $msg = '<p class="LC_error">';
1.984 raeburn 12375: $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 12376: $msg .= '</p>';
1.984 raeburn 12377: return ('existingfile',$msg);
1.661 raeburn 12378: }
12379: }
12380: }
12381:
1.987 raeburn 12382: sub check_for_traversal {
12383: my ($path,$url,$toplevel) = @_;
12384: my @parts=split(/\//,$path);
12385: my $cleanpath;
12386: my $fullpath = $url;
12387: for (my $i=0;$i<@parts;$i++) {
12388: next if ($parts[$i] eq '.');
12389: if ($parts[$i] eq '..') {
12390: $fullpath =~ s{([^/]+/)$}{};
12391: } else {
12392: $fullpath .= $parts[$i].'/';
12393: }
12394: }
12395: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12396: $cleanpath = $1;
12397: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12398: my $curr_toprel = $1;
12399: my @parts = split(/\//,$curr_toprel);
12400: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12401: my @urlparts = split(/\//,$url_toprel);
12402: my $doubledots;
12403: my $startdiff = -1;
12404: for (my $i=0; $i<@urlparts; $i++) {
12405: if ($startdiff == -1) {
12406: unless ($urlparts[$i] eq $parts[$i]) {
12407: $startdiff = $i;
12408: $doubledots .= '../';
12409: }
12410: } else {
12411: $doubledots .= '../';
12412: }
12413: }
12414: if ($startdiff > -1) {
12415: $cleanpath = $doubledots;
12416: for (my $i=$startdiff; $i<@parts; $i++) {
12417: $cleanpath .= $parts[$i].'/';
12418: }
12419: }
12420: }
12421: $cleanpath =~ s{(/)$}{};
12422: return $cleanpath;
12423: }
1.31 albertel 12424:
1.1053 raeburn 12425: sub is_archive_file {
12426: my ($mimetype) = @_;
12427: if (($mimetype eq 'application/octet-stream') ||
12428: ($mimetype eq 'application/x-stuffit') ||
12429: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12430: return 1;
12431: }
12432: return;
12433: }
12434:
12435: sub decompress_form {
1.1065 raeburn 12436: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12437: my %lt = &Apache::lonlocal::texthash (
12438: this => 'This file is an archive file.',
1.1067 raeburn 12439: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12440: itsc => 'Its contents are as follows:',
1.1053 raeburn 12441: youm => 'You may wish to extract its contents.',
12442: extr => 'Extract contents',
1.1067 raeburn 12443: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12444: proa => 'Process automatically?',
1.1053 raeburn 12445: yes => 'Yes',
12446: no => 'No',
1.1067 raeburn 12447: fold => 'Title for folder containing movie',
12448: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12449: );
1.1065 raeburn 12450: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12451: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12452: my $info = &list_archive_contents($fileloc,\@paths);
12453: if (@paths) {
12454: foreach my $path (@paths) {
12455: $path =~ s{^/}{};
1.1067 raeburn 12456: if ($path =~ m{^([^/]+)/$}) {
12457: $topdir = $1;
12458: }
1.1065 raeburn 12459: if ($path =~ m{^([^/]+)/}) {
12460: $toplevel{$1} = $path;
12461: } else {
12462: $toplevel{$path} = $path;
12463: }
12464: }
12465: }
1.1067 raeburn 12466: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12467: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12468: "$topdir/media/",
12469: "$topdir/media/$topdir.mp4",
12470: "$topdir/media/FirstFrame.png",
12471: "$topdir/media/player.swf",
12472: "$topdir/media/swfobject.js",
12473: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12474: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12475: "$topdir/$topdir.mp4",
12476: "$topdir/$topdir\_config.xml",
12477: "$topdir/$topdir\_controller.swf",
12478: "$topdir/$topdir\_embed.css",
12479: "$topdir/$topdir\_First_Frame.png",
12480: "$topdir/$topdir\_player.html",
12481: "$topdir/$topdir\_Thumbnails.png",
12482: "$topdir/playerProductInstall.swf",
12483: "$topdir/scripts/",
12484: "$topdir/scripts/config_xml.js",
12485: "$topdir/scripts/handlebars.js",
12486: "$topdir/scripts/jquery-1.7.1.min.js",
12487: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12488: "$topdir/scripts/modernizr.js",
12489: "$topdir/scripts/player-min.js",
12490: "$topdir/scripts/swfobject.js",
12491: "$topdir/skins/",
12492: "$topdir/skins/configuration_express.xml",
12493: "$topdir/skins/express_show/",
12494: "$topdir/skins/express_show/player-min.css",
12495: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12496: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12497: "$topdir/$topdir.mp4",
12498: "$topdir/$topdir\_config.xml",
12499: "$topdir/$topdir\_controller.swf",
12500: "$topdir/$topdir\_embed.css",
12501: "$topdir/$topdir\_First_Frame.png",
12502: "$topdir/$topdir\_player.html",
12503: "$topdir/$topdir\_Thumbnails.png",
12504: "$topdir/playerProductInstall.swf",
12505: "$topdir/scripts/",
12506: "$topdir/scripts/config_xml.js",
12507: "$topdir/scripts/techsmith-smart-player.min.js",
12508: "$topdir/skins/",
12509: "$topdir/skins/configuration_express.xml",
12510: "$topdir/skins/express_show/",
12511: "$topdir/skins/express_show/spritesheet.min.css",
12512: "$topdir/skins/express_show/spritesheet.png",
12513: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12514: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12515: if (@diffs == 0) {
1.1164 raeburn 12516: $is_camtasia = 6;
12517: } else {
1.1197 raeburn 12518: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12519: if (@diffs == 0) {
12520: $is_camtasia = 8;
1.1197 raeburn 12521: } else {
12522: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12523: if (@diffs == 0) {
12524: $is_camtasia = 8;
12525: }
1.1164 raeburn 12526: }
1.1067 raeburn 12527: }
12528: }
12529: my $output;
12530: if ($is_camtasia) {
12531: $output = <<"ENDCAM";
12532: <script type="text/javascript" language="Javascript">
12533: // <![CDATA[
12534:
12535: function camtasiaToggle() {
12536: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12537: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12538: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12539: document.getElementById('camtasia_titles').style.display='block';
12540: } else {
12541: document.getElementById('camtasia_titles').style.display='none';
12542: }
12543: }
12544: }
12545: return;
12546: }
12547:
12548: // ]]>
12549: </script>
12550: <p>$lt{'camt'}</p>
12551: ENDCAM
1.1065 raeburn 12552: } else {
1.1067 raeburn 12553: $output = '<p>'.$lt{'this'};
12554: if ($info eq '') {
12555: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12556: } else {
12557: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12558: '<div><pre>'.$info.'</pre></div>';
12559: }
1.1065 raeburn 12560: }
1.1067 raeburn 12561: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12562: my $duplicates;
12563: my $num = 0;
12564: if (ref($dirlist) eq 'ARRAY') {
12565: foreach my $item (@{$dirlist}) {
12566: if (ref($item) eq 'ARRAY') {
12567: if (exists($toplevel{$item->[0]})) {
12568: $duplicates .=
12569: &start_data_table_row().
12570: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12571: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12572: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12573: 'value="1" />'.&mt('Yes').'</label>'.
12574: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12575: '<td>'.$item->[0].'</td>';
12576: if ($item->[2]) {
12577: $duplicates .= '<td>'.&mt('Directory').'</td>';
12578: } else {
12579: $duplicates .= '<td>'.&mt('File').'</td>';
12580: }
12581: $duplicates .= '<td>'.$item->[3].'</td>'.
12582: '<td>'.
12583: &Apache::lonlocal::locallocaltime($item->[4]).
12584: '</td>'.
12585: &end_data_table_row();
12586: $num ++;
12587: }
12588: }
12589: }
12590: }
12591: my $itemcount;
12592: if (@paths > 0) {
12593: $itemcount = scalar(@paths);
12594: } else {
12595: $itemcount = 1;
12596: }
1.1067 raeburn 12597: if ($is_camtasia) {
12598: $output .= $lt{'auto'}.'<br />'.
12599: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12600: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12601: $lt{'yes'}.'</label> <label>'.
12602: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12603: $lt{'no'}.'</label></span><br />'.
12604: '<div id="camtasia_titles" style="display:block">'.
12605: &Apache::lonhtmlcommon::start_pick_box().
12606: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12607: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12608: &Apache::lonhtmlcommon::row_closure().
12609: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12610: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12611: &Apache::lonhtmlcommon::row_closure(1).
12612: &Apache::lonhtmlcommon::end_pick_box().
12613: '</div>';
12614: }
1.1065 raeburn 12615: $output .=
12616: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12617: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12618: "\n";
1.1065 raeburn 12619: if ($duplicates ne '') {
12620: $output .= '<p><span class="LC_warning">'.
12621: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12622: &start_data_table().
12623: &start_data_table_header_row().
12624: '<th>'.&mt('Overwrite?').'</th>'.
12625: '<th>'.&mt('Name').'</th>'.
12626: '<th>'.&mt('Type').'</th>'.
12627: '<th>'.&mt('Size').'</th>'.
12628: '<th>'.&mt('Last modified').'</th>'.
12629: &end_data_table_header_row().
12630: $duplicates.
12631: &end_data_table().
12632: '</p>';
12633: }
1.1067 raeburn 12634: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12635: if (ref($hiddenelements) eq 'HASH') {
12636: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12637: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12638: }
12639: }
12640: $output .= <<"END";
1.1067 raeburn 12641: <br />
1.1053 raeburn 12642: <input type="submit" name="decompress" value="$lt{'extr'}" />
12643: </form>
12644: $noextract
12645: END
12646: return $output;
12647: }
12648:
1.1065 raeburn 12649: sub decompression_utility {
12650: my ($program) = @_;
12651: my @utilities = ('tar','gunzip','bunzip2','unzip');
12652: my $location;
12653: if (grep(/^\Q$program\E$/,@utilities)) {
12654: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12655: '/usr/sbin/') {
12656: if (-x $dir.$program) {
12657: $location = $dir.$program;
12658: last;
12659: }
12660: }
12661: }
12662: return $location;
12663: }
12664:
12665: sub list_archive_contents {
12666: my ($file,$pathsref) = @_;
12667: my (@cmd,$output);
12668: my $needsregexp;
12669: if ($file =~ /\.zip$/) {
12670: @cmd = (&decompression_utility('unzip'),"-l");
12671: $needsregexp = 1;
12672: } elsif (($file =~ m/\.tar\.gz$/) ||
12673: ($file =~ /\.tgz$/)) {
12674: @cmd = (&decompression_utility('tar'),"-ztf");
12675: } elsif ($file =~ /\.tar\.bz2$/) {
12676: @cmd = (&decompression_utility('tar'),"-jtf");
12677: } elsif ($file =~ m|\.tar$|) {
12678: @cmd = (&decompression_utility('tar'),"-tf");
12679: }
12680: if (@cmd) {
12681: undef($!);
12682: undef($@);
12683: if (open(my $fh,"-|", @cmd, $file)) {
12684: while (my $line = <$fh>) {
12685: $output .= $line;
12686: chomp($line);
12687: my $item;
12688: if ($needsregexp) {
12689: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12690: } else {
12691: $item = $line;
12692: }
12693: if ($item ne '') {
12694: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12695: push(@{$pathsref},$item);
12696: }
12697: }
12698: }
12699: close($fh);
12700: }
12701: }
12702: return $output;
12703: }
12704:
1.1053 raeburn 12705: sub decompress_uploaded_file {
12706: my ($file,$dir) = @_;
12707: &Apache::lonnet::appenv({'cgi.file' => $file});
12708: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12709: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12710: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12711: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12712: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12713: my $decompressed = $env{'cgi.decompressed'};
12714: &Apache::lonnet::delenv('cgi.file');
12715: &Apache::lonnet::delenv('cgi.dir');
12716: &Apache::lonnet::delenv('cgi.decompressed');
12717: return ($decompressed,$result);
12718: }
12719:
1.1055 raeburn 12720: sub process_decompression {
12721: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
1.1292 raeburn 12722: unless (($dir_root eq '/userfiles') && ($destination =~ m{^(docs|supplemental)/(default|\d+)/\d+$})) {
12723: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12724: &mt('Unexpected file path.').'</p>'."\n";
12725: }
12726: unless (($docudom =~ /^$match_domain$/) && ($docuname =~ /^$match_courseid$/)) {
12727: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12728: &mt('Unexpected course context.').'</p>'."\n";
12729: }
1.1293 raeburn 12730: unless ($file eq &Apache::lonnet::clean_filename($file)) {
1.1292 raeburn 12731: return '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12732: &mt('Filename contained unexpected characters.').'</p>'."\n";
12733: }
1.1055 raeburn 12734: my ($dir,$error,$warning,$output);
1.1180 raeburn 12735: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12736: $error = &mt('Filename not a supported archive file type.').
12737: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12738: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12739: } else {
12740: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12741: if ($docuhome eq 'no_host') {
12742: $error = &mt('Could not determine home server for course.');
12743: } else {
12744: my @ids=&Apache::lonnet::current_machine_ids();
12745: my $currdir = "$dir_root/$destination";
12746: if (grep(/^\Q$docuhome\E$/,@ids)) {
12747: $dir = &LONCAPA::propath($docudom,$docuname).
12748: "$dir_root/$destination";
12749: } else {
12750: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12751: "$dir_root/$docudom/$docuname/$destination";
12752: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12753: $error = &mt('Archive file not found.');
12754: }
12755: }
1.1065 raeburn 12756: my (@to_overwrite,@to_skip);
12757: if ($env{'form.archive_overwrite_total'} > 0) {
12758: my $total = $env{'form.archive_overwrite_total'};
12759: for (my $i=0; $i<$total; $i++) {
12760: if ($env{'form.archive_overwrite_'.$i} == 1) {
12761: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12762: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12763: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12764: }
12765: }
12766: }
12767: my $numskip = scalar(@to_skip);
1.1292 raeburn 12768: my $numoverwrite = scalar(@to_overwrite);
12769: if (($numskip) && (!$numoverwrite)) {
1.1065 raeburn 12770: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12771: } elsif ($dir eq '') {
1.1055 raeburn 12772: $error = &mt('Directory containing archive file unavailable.');
12773: } elsif (!$error) {
1.1065 raeburn 12774: my ($decompressed,$display);
1.1292 raeburn 12775: if (($numskip) || ($numoverwrite)) {
1.1065 raeburn 12776: my $tempdir = time.'_'.$$.int(rand(10000));
12777: mkdir("$dir/$tempdir",0755);
1.1292 raeburn 12778: if (&File::Copy::move("$dir/$file","$dir/$tempdir/$file")) {
12779: ($decompressed,$display) =
12780: &decompress_uploaded_file($file,"$dir/$tempdir");
12781: foreach my $item (@to_skip) {
12782: if (($item ne '') && ($item !~ /\.\./)) {
12783: if (-f "$dir/$tempdir/$item") {
12784: unlink("$dir/$tempdir/$item");
12785: } elsif (-d "$dir/$tempdir/$item") {
1.1300 raeburn 12786: &File::Path::remove_tree("$dir/$tempdir/$item",{ safe => 1 });
1.1292 raeburn 12787: }
12788: }
12789: }
12790: foreach my $item (@to_overwrite) {
12791: if ((-e "$dir/$tempdir/$item") && (-e "$dir/$item")) {
12792: if (($item ne '') && ($item !~ /\.\./)) {
12793: if (-f "$dir/$item") {
12794: unlink("$dir/$item");
12795: } elsif (-d "$dir/$item") {
1.1300 raeburn 12796: &File::Path::remove_tree("$dir/$item",{ safe => 1 });
1.1292 raeburn 12797: }
12798: &File::Copy::move("$dir/$tempdir/$item","$dir/$item");
12799: }
1.1065 raeburn 12800: }
12801: }
1.1292 raeburn 12802: if (&File::Copy::move("$dir/$tempdir/$file","$dir/$file")) {
1.1300 raeburn 12803: &File::Path::remove_tree("$dir/$tempdir",{ safe => 1 });
1.1292 raeburn 12804: }
1.1065 raeburn 12805: }
12806: } else {
12807: ($decompressed,$display) =
12808: &decompress_uploaded_file($file,$dir);
12809: }
1.1055 raeburn 12810: if ($decompressed eq 'ok') {
1.1065 raeburn 12811: $output = '<p class="LC_info">'.
12812: &mt('Files extracted successfully from archive.').
12813: '</p>'."\n";
1.1055 raeburn 12814: my ($warning,$result,@contents);
12815: my ($newdirlistref,$newlisterror) =
12816: &Apache::lonnet::dirlist($currdir,$docudom,
12817: $docuname,1);
12818: my (%is_dir,%changes,@newitems);
12819: my $dirptr = 16384;
1.1065 raeburn 12820: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12821: foreach my $dir_line (@{$newdirlistref}) {
12822: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1292 raeburn 12823: unless (($item =~ /^\.+$/) || ($item eq $file)) {
1.1055 raeburn 12824: push(@newitems,$item);
12825: if ($dirptr&$testdir) {
12826: $is_dir{$item} = 1;
12827: }
12828: $changes{$item} = 1;
12829: }
12830: }
12831: }
12832: if (keys(%changes) > 0) {
12833: foreach my $item (sort(@newitems)) {
12834: if ($changes{$item}) {
12835: push(@contents,$item);
12836: }
12837: }
12838: }
12839: if (@contents > 0) {
1.1067 raeburn 12840: my $wantform;
12841: unless ($env{'form.autoextract_camtasia'}) {
12842: $wantform = 1;
12843: }
1.1056 raeburn 12844: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12845: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12846: $currdir,\%is_dir,
12847: \%children,\%parent,
1.1056 raeburn 12848: \@contents,\%dirorder,
12849: \%titles,$wantform);
1.1055 raeburn 12850: if ($datatable ne '') {
12851: $output .= &archive_options_form('decompressed',$datatable,
12852: $count,$hiddenelem);
1.1065 raeburn 12853: my $startcount = 6;
1.1055 raeburn 12854: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12855: \%titles,\%children);
1.1055 raeburn 12856: }
1.1067 raeburn 12857: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 12858: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12859: my %displayed;
12860: my $total = 1;
12861: $env{'form.archive_directory'} = [];
12862: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12863: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12864: $path =~ s{/$}{};
12865: my $item;
12866: if ($path ne '') {
12867: $item = "$path/$titles{$i}";
12868: } else {
12869: $item = $titles{$i};
12870: }
12871: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12872: if ($item eq $contents[0]) {
12873: push(@{$env{'form.archive_directory'}},$i);
12874: $env{'form.archive_'.$i} = 'display';
12875: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12876: $displayed{'folder'} = $i;
1.1164 raeburn 12877: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12878: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12879: $env{'form.archive_'.$i} = 'display';
12880: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12881: $displayed{'web'} = $i;
12882: } else {
1.1164 raeburn 12883: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12884: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12885: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12886: push(@{$env{'form.archive_directory'}},$i);
12887: }
12888: $env{'form.archive_'.$i} = 'dependency';
12889: }
12890: $total ++;
12891: }
12892: for (my $i=1; $i<$total; $i++) {
12893: next if ($i == $displayed{'web'});
12894: next if ($i == $displayed{'folder'});
12895: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12896: }
12897: $env{'form.phase'} = 'decompress_cleanup';
12898: $env{'form.archivedelete'} = 1;
12899: $env{'form.archive_count'} = $total-1;
12900: $output .=
12901: &process_extracted_files('coursedocs',$docudom,
12902: $docuname,$destination,
12903: $dir_root,$hiddenelem);
12904: }
1.1055 raeburn 12905: } else {
12906: $warning = &mt('No new items extracted from archive file.');
12907: }
12908: } else {
12909: $output = $display;
12910: $error = &mt('An error occurred during extraction from the archive file.');
12911: }
12912: }
12913: }
12914: }
12915: if ($error) {
12916: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12917: $error.'</p>'."\n";
12918: }
12919: if ($warning) {
12920: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12921: }
12922: return $output;
12923: }
12924:
12925: sub get_extracted {
1.1056 raeburn 12926: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12927: $titles,$wantform) = @_;
1.1055 raeburn 12928: my $count = 0;
12929: my $depth = 0;
12930: my $datatable;
1.1056 raeburn 12931: my @hierarchy;
1.1055 raeburn 12932: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12933: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12934: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12935: foreach my $item (@{$contents}) {
12936: $count ++;
1.1056 raeburn 12937: @{$dirorder->{$count}} = @hierarchy;
12938: $titles->{$count} = $item;
1.1055 raeburn 12939: &archive_hierarchy($depth,$count,$parent,$children);
12940: if ($wantform) {
12941: $datatable .= &archive_row($is_dir->{$item},$item,
12942: $currdir,$depth,$count);
12943: }
12944: if ($is_dir->{$item}) {
12945: $depth ++;
1.1056 raeburn 12946: push(@hierarchy,$count);
12947: $parent->{$depth} = $count;
1.1055 raeburn 12948: $datatable .=
12949: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12950: \$depth,\$count,\@hierarchy,$dirorder,
12951: $children,$parent,$titles,$wantform);
1.1055 raeburn 12952: $depth --;
1.1056 raeburn 12953: pop(@hierarchy);
1.1055 raeburn 12954: }
12955: }
12956: return ($count,$datatable);
12957: }
12958:
12959: sub recurse_extracted_archive {
1.1056 raeburn 12960: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12961: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12962: my $result='';
1.1056 raeburn 12963: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12964: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12965: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12966: return $result;
12967: }
12968: my $dirptr = 16384;
12969: my ($newdirlistref,$newlisterror) =
12970: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12971: if (ref($newdirlistref) eq 'ARRAY') {
12972: foreach my $dir_line (@{$newdirlistref}) {
12973: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12974: unless ($item =~ /^\.+$/) {
12975: $$count ++;
1.1056 raeburn 12976: @{$dirorder->{$$count}} = @{$hierarchy};
12977: $titles->{$$count} = $item;
1.1055 raeburn 12978: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12979:
1.1055 raeburn 12980: my $is_dir;
12981: if ($dirptr&$testdir) {
12982: $is_dir = 1;
12983: }
12984: if ($wantform) {
12985: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12986: }
12987: if ($is_dir) {
12988: $$depth ++;
1.1056 raeburn 12989: push(@{$hierarchy},$$count);
12990: $parent->{$$depth} = $$count;
1.1055 raeburn 12991: $result .=
12992: &recurse_extracted_archive("$currdir/$item",$docudom,
12993: $docuname,$depth,$count,
1.1056 raeburn 12994: $hierarchy,$dirorder,$children,
12995: $parent,$titles,$wantform);
1.1055 raeburn 12996: $$depth --;
1.1056 raeburn 12997: pop(@{$hierarchy});
1.1055 raeburn 12998: }
12999: }
13000: }
13001: }
13002: return $result;
13003: }
13004:
13005: sub archive_hierarchy {
13006: my ($depth,$count,$parent,$children) =@_;
13007: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
13008: if (exists($parent->{$depth})) {
13009: $children->{$parent->{$depth}} .= $count.':';
13010: }
13011: }
13012: return;
13013: }
13014:
13015: sub archive_row {
13016: my ($is_dir,$item,$currdir,$depth,$count) = @_;
13017: my ($name) = ($item =~ m{([^/]+)$});
13018: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 13019: 'display' => 'Add as file',
1.1055 raeburn 13020: 'dependency' => 'Include as dependency',
13021: 'discard' => 'Discard',
13022: );
13023: if ($is_dir) {
1.1059 raeburn 13024: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 13025: }
1.1056 raeburn 13026: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
13027: my $offset = 0;
1.1055 raeburn 13028: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 13029: $offset ++;
1.1065 raeburn 13030: if ($action ne 'display') {
13031: $offset ++;
13032: }
1.1055 raeburn 13033: $output .= '<td><span class="LC_nobreak">'.
13034: '<label><input type="radio" name="archive_'.$count.
13035: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
13036: my $text = $choices{$action};
13037: if ($is_dir) {
13038: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
13039: if ($action eq 'display') {
1.1059 raeburn 13040: $text = &mt('Add as folder');
1.1055 raeburn 13041: }
1.1056 raeburn 13042: } else {
13043: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
13044:
13045: }
13046: $output .= ' /> '.$choices{$action}.'</label></span>';
13047: if ($action eq 'dependency') {
13048: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
13049: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
13050: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
13051: '<option value=""></option>'."\n".
13052: '</select>'."\n".
13053: '</div>';
1.1059 raeburn 13054: } elsif ($action eq 'display') {
13055: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
13056: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
13057: '</div>';
1.1055 raeburn 13058: }
1.1056 raeburn 13059: $output .= '</td>';
1.1055 raeburn 13060: }
13061: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
13062: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
13063: for (my $i=0; $i<$depth; $i++) {
13064: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
13065: }
13066: if ($is_dir) {
13067: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
13068: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
13069: } else {
13070: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
13071: }
13072: $output .= ' '.$name.'</td>'."\n".
13073: &end_data_table_row();
13074: return $output;
13075: }
13076:
13077: sub archive_options_form {
1.1065 raeburn 13078: my ($form,$display,$count,$hiddenelem) = @_;
13079: my %lt = &Apache::lonlocal::texthash(
13080: perm => 'Permanently remove archive file?',
13081: hows => 'How should each extracted item be incorporated in the course?',
13082: cont => 'Content actions for all',
13083: addf => 'Add as folder/file',
13084: incd => 'Include as dependency for a displayed file',
13085: disc => 'Discard',
13086: no => 'No',
13087: yes => 'Yes',
13088: save => 'Save',
13089: );
13090: my $output = <<"END";
13091: <form name="$form" method="post" action="">
13092: <p><span class="LC_nobreak">$lt{'perm'}
13093: <label>
13094: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
13095: </label>
13096:
13097: <label>
13098: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
13099: </span>
13100: </p>
13101: <input type="hidden" name="phase" value="decompress_cleanup" />
13102: <br />$lt{'hows'}
13103: <div class="LC_columnSection">
13104: <fieldset>
13105: <legend>$lt{'cont'}</legend>
13106: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
13107: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
13108: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
13109: </fieldset>
13110: </div>
13111: END
13112: return $output.
1.1055 raeburn 13113: &start_data_table()."\n".
1.1065 raeburn 13114: $display."\n".
1.1055 raeburn 13115: &end_data_table()."\n".
13116: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
13117: $hiddenelem.
1.1065 raeburn 13118: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 13119: '</form>';
13120: }
13121:
13122: sub archive_javascript {
1.1056 raeburn 13123: my ($startcount,$numitems,$titles,$children) = @_;
13124: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 13125: my $maintitle = $env{'form.comment'};
1.1055 raeburn 13126: my $scripttag = <<START;
13127: <script type="text/javascript">
13128: // <![CDATA[
13129:
13130: function checkAll(form,prefix) {
13131: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
13132: for (var i=0; i < form.elements.length; i++) {
13133: var id = form.elements[i].id;
13134: if ((id != '') && (id != undefined)) {
13135: if (idstr.test(id)) {
13136: if (form.elements[i].type == 'radio') {
13137: form.elements[i].checked = true;
1.1056 raeburn 13138: var nostart = i-$startcount;
1.1059 raeburn 13139: var offset = nostart%7;
13140: var count = (nostart-offset)/7;
1.1056 raeburn 13141: dependencyCheck(form,count,offset);
1.1055 raeburn 13142: }
13143: }
13144: }
13145: }
13146: }
13147:
13148: function propagateCheck(form,count) {
13149: if (count > 0) {
1.1059 raeburn 13150: var startelement = $startcount + ((count-1) * 7);
13151: for (var j=1; j<6; j++) {
13152: if ((j != 2) && (j != 4)) {
1.1056 raeburn 13153: var item = startelement + j;
13154: if (form.elements[item].type == 'radio') {
13155: if (form.elements[item].checked) {
13156: containerCheck(form,count,j);
13157: break;
13158: }
1.1055 raeburn 13159: }
13160: }
13161: }
13162: }
13163: }
13164:
13165: numitems = $numitems
1.1056 raeburn 13166: var titles = new Array(numitems);
13167: var parents = new Array(numitems);
1.1055 raeburn 13168: for (var i=0; i<numitems; i++) {
1.1056 raeburn 13169: parents[i] = new Array;
1.1055 raeburn 13170: }
1.1059 raeburn 13171: var maintitle = '$maintitle';
1.1055 raeburn 13172:
13173: START
13174:
1.1056 raeburn 13175: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
13176: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 13177: for (my $i=0; $i<@contents; $i ++) {
13178: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
13179: }
13180: }
13181:
1.1056 raeburn 13182: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
13183: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
13184: }
13185:
1.1055 raeburn 13186: $scripttag .= <<END;
13187:
13188: function containerCheck(form,count,offset) {
13189: if (count > 0) {
1.1056 raeburn 13190: dependencyCheck(form,count,offset);
1.1059 raeburn 13191: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 13192: form.elements[item].checked = true;
13193: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
13194: if (parents[count].length > 0) {
13195: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13196: containerCheck(form,parents[count][j],offset);
13197: }
13198: }
13199: }
13200: }
13201: }
13202:
13203: function dependencyCheck(form,count,offset) {
13204: if (count > 0) {
1.1059 raeburn 13205: var chosen = (offset+$startcount)+7*(count-1);
13206: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13207: var currtype = form.elements[depitem].type;
13208: if (form.elements[chosen].value == 'dependency') {
13209: document.getElementById('arc_depon_'+count).style.display='block';
13210: form.elements[depitem].options.length = 0;
13211: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13212: for (var i=1; i<=numitems; i++) {
13213: if (i == count) {
13214: continue;
13215: }
1.1059 raeburn 13216: var startelement = $startcount + (i-1) * 7;
13217: for (var j=1; j<6; j++) {
13218: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13219: var item = startelement + j;
13220: if (form.elements[item].type == 'radio') {
13221: if (form.elements[item].checked) {
13222: if (form.elements[item].value == 'display') {
13223: var n = form.elements[depitem].options.length;
13224: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13225: }
13226: }
13227: }
13228: }
13229: }
13230: }
13231: } else {
13232: document.getElementById('arc_depon_'+count).style.display='none';
13233: form.elements[depitem].options.length = 0;
13234: form.elements[depitem].options[0] = new Option('Select','',true,true);
13235: }
1.1059 raeburn 13236: titleCheck(form,count,offset);
1.1056 raeburn 13237: }
13238: }
13239:
13240: function propagateSelect(form,count,offset) {
13241: if (count > 0) {
1.1065 raeburn 13242: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13243: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13244: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13245: if (parents[count].length > 0) {
13246: for (var j=0; j<parents[count].length; j++) {
13247: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13248: }
13249: }
13250: }
13251: }
13252: }
1.1056 raeburn 13253:
13254: function containerSelect(form,count,offset,picked) {
13255: if (count > 0) {
1.1065 raeburn 13256: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13257: if (form.elements[item].type == 'radio') {
13258: if (form.elements[item].value == 'dependency') {
13259: if (form.elements[item+1].type == 'select-one') {
13260: for (var i=0; i<form.elements[item+1].options.length; i++) {
13261: if (form.elements[item+1].options[i].value == picked) {
13262: form.elements[item+1].selectedIndex = i;
13263: break;
13264: }
13265: }
13266: }
13267: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13268: if (parents[count].length > 0) {
13269: for (var j=0; j<parents[count].length; j++) {
13270: containerSelect(form,parents[count][j],offset,picked);
13271: }
13272: }
13273: }
13274: }
13275: }
13276: }
13277: }
13278:
1.1059 raeburn 13279: function titleCheck(form,count,offset) {
13280: if (count > 0) {
13281: var chosen = (offset+$startcount)+7*(count-1);
13282: var depitem = $startcount + ((count-1) * 7) + 2;
13283: var currtype = form.elements[depitem].type;
13284: if (form.elements[chosen].value == 'display') {
13285: document.getElementById('arc_title_'+count).style.display='block';
13286: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13287: document.getElementById('archive_title_'+count).value=maintitle;
13288: }
13289: } else {
13290: document.getElementById('arc_title_'+count).style.display='none';
13291: if (currtype == 'text') {
13292: document.getElementById('archive_title_'+count).value='';
13293: }
13294: }
13295: }
13296: return;
13297: }
13298:
1.1055 raeburn 13299: // ]]>
13300: </script>
13301: END
13302: return $scripttag;
13303: }
13304:
13305: sub process_extracted_files {
1.1067 raeburn 13306: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13307: my $numitems = $env{'form.archive_count'};
1.1294 raeburn 13308: return if ((!$numitems) || ($numitems =~ /\D/));
1.1055 raeburn 13309: my @ids=&Apache::lonnet::current_machine_ids();
13310: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13311: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13312: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13313: if (grep(/^\Q$docuhome\E$/,@ids)) {
13314: $prefix = &LONCAPA::propath($docudom,$docuname);
13315: $pathtocheck = "$dir_root/$destination";
13316: $dir = $dir_root;
13317: $ishome = 1;
13318: } else {
13319: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13320: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
1.1294 raeburn 13321: $dir = "$dir_root/$docudom/$docuname";
1.1055 raeburn 13322: }
13323: my $currdir = "$dir_root/$destination";
13324: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13325: if ($env{'form.folderpath'}) {
13326: my @items = split('&',$env{'form.folderpath'});
13327: $folders{'0'} = $items[-2];
1.1099 raeburn 13328: if ($env{'form.folderpath'} =~ /\:1$/) {
13329: $containers{'0'}='page';
13330: } else {
13331: $containers{'0'}='sequence';
13332: }
1.1055 raeburn 13333: }
13334: my @archdirs = &get_env_multiple('form.archive_directory');
13335: if ($numitems) {
13336: for (my $i=1; $i<=$numitems; $i++) {
13337: my $path = $env{'form.archive_content_'.$i};
13338: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13339: my $item = $1;
13340: $toplevelitems{$item} = $i;
13341: if (grep(/^\Q$i\E$/,@archdirs)) {
13342: $is_dir{$item} = 1;
13343: }
13344: }
13345: }
13346: }
1.1067 raeburn 13347: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13348: if (keys(%toplevelitems) > 0) {
13349: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13350: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13351: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13352: }
1.1066 raeburn 13353: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13354: if ($numitems) {
13355: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13356: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13357: my $path = $env{'form.archive_content_'.$i};
13358: if ($path =~ /^\Q$pathtocheck\E/) {
13359: if ($env{'form.archive_'.$i} eq 'discard') {
13360: if ($prefix ne '' && $path ne '') {
13361: if (-e $prefix.$path) {
1.1066 raeburn 13362: if ((@archdirs > 0) &&
13363: (grep(/^\Q$i\E$/,@archdirs))) {
13364: $todeletedir{$prefix.$path} = 1;
13365: } else {
13366: $todelete{$prefix.$path} = 1;
13367: }
1.1055 raeburn 13368: }
13369: }
13370: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13371: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13372: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13373: $docstitle = $env{'form.archive_title_'.$i};
13374: if ($docstitle eq '') {
13375: $docstitle = $title;
13376: }
1.1055 raeburn 13377: $outer = 0;
1.1056 raeburn 13378: if (ref($dirorder{$i}) eq 'ARRAY') {
13379: if (@{$dirorder{$i}} > 0) {
13380: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13381: if ($env{'form.archive_'.$item} eq 'display') {
13382: $outer = $item;
13383: last;
13384: }
13385: }
13386: }
13387: }
13388: my ($errtext,$fatal) =
13389: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13390: '/'.$folders{$outer}.'.'.
13391: $containers{$outer});
13392: next if ($fatal);
13393: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13394: if ($context eq 'coursedocs') {
1.1056 raeburn 13395: $mapinner{$i} = time;
1.1055 raeburn 13396: $folders{$i} = 'default_'.$mapinner{$i};
13397: $containers{$i} = 'sequence';
13398: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13399: $folders{$i}.'.'.$containers{$i};
13400: my $newidx = &LONCAPA::map::getresidx();
13401: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13402: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13403: push(@LONCAPA::map::order,$newidx);
13404: my ($outtext,$errtext) =
13405: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13406: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13407: '.'.$containers{$outer},1,1);
1.1056 raeburn 13408: $newseqid{$i} = $newidx;
1.1067 raeburn 13409: unless ($errtext) {
1.1294 raeburn 13410: $result .= '<li>'.&mt('Folder: [_1] added to course',
13411: &HTML::Entities::encode($docstitle,'<>&"')).
13412: '</li>'."\n";
1.1067 raeburn 13413: }
1.1055 raeburn 13414: }
13415: } else {
13416: if ($context eq 'coursedocs') {
13417: my $newidx=&LONCAPA::map::getresidx();
13418: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13419: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13420: $title;
1.1294 raeburn 13421: if (($outer !~ /\D/) && ($mapinner{$outer} !~ /\D/) && ($newidx !~ /\D/)) {
13422: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13423: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13424: }
13425: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13426: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13427: }
13428: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13429: if (rename("$prefix$path","$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title")) {
13430: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
13431: unless ($ishome) {
13432: my $fetch = "$newdest{$i}/$title";
13433: $fetch =~ s/^\Q$prefix$dir\E//;
13434: $prompttofetch{$fetch} = 1;
13435: }
1.1292 raeburn 13436: }
1.1067 raeburn 13437: }
1.1294 raeburn 13438: $LONCAPA::map::resources[$newidx]=
13439: $docstitle.':'.$url.':false:normal:res';
13440: push(@LONCAPA::map::order, $newidx);
13441: my ($outtext,$errtext)=
13442: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13443: $docuname.'/'.$folders{$outer}.
13444: '.'.$containers{$outer},1,1);
13445: unless ($errtext) {
13446: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13447: $result .= '<li>'.&mt('File: [_1] added to course',
13448: &HTML::Entities::encode($docstitle,'<>&"')).
13449: '</li>'."\n";
13450: }
1.1067 raeburn 13451: }
1.1294 raeburn 13452: } else {
13453: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13454: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1296 raeburn 13455: }
1.1055 raeburn 13456: }
13457: }
1.1086 raeburn 13458: }
13459: } else {
1.1294 raeburn 13460: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
13461: &HTML::Entities::encode($path,'<>&"')).'<br />';
1.1086 raeburn 13462: }
13463: }
13464: for (my $i=1; $i<=$numitems; $i++) {
13465: next unless ($env{'form.archive_'.$i} eq 'dependency');
13466: my $path = $env{'form.archive_content_'.$i};
13467: if ($path =~ /^\Q$pathtocheck\E/) {
13468: my ($title) = ($path =~ m{/([^/]+)$});
13469: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13470: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13471: if (ref($dirorder{$i}) eq 'ARRAY') {
13472: my ($itemidx,$fullpath,$relpath);
13473: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13474: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13475: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13476: if ($dirorder{$i}->[$j] eq $container) {
13477: $itemidx = $j;
1.1056 raeburn 13478: }
13479: }
1.1086 raeburn 13480: }
13481: if ($itemidx eq '') {
13482: $itemidx = 0;
13483: }
13484: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13485: if ($mapinner{$referrer{$i}}) {
13486: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13487: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13488: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13489: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13490: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13491: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13492: if (!-e $fullpath) {
13493: mkdir($fullpath,0755);
1.1056 raeburn 13494: }
13495: }
1.1086 raeburn 13496: } else {
13497: last;
1.1056 raeburn 13498: }
1.1086 raeburn 13499: }
13500: }
13501: } elsif ($newdest{$referrer{$i}}) {
13502: $fullpath = $newdest{$referrer{$i}};
13503: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13504: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13505: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13506: last;
13507: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13508: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13509: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13510: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13511: if (!-e $fullpath) {
13512: mkdir($fullpath,0755);
1.1056 raeburn 13513: }
13514: }
1.1086 raeburn 13515: } else {
13516: last;
1.1056 raeburn 13517: }
1.1055 raeburn 13518: }
13519: }
1.1086 raeburn 13520: if ($fullpath ne '') {
13521: if (-e "$prefix$path") {
1.1292 raeburn 13522: unless (rename("$prefix$path","$fullpath/$title")) {
13523: $warning .= &mt('Failed to rename dependency').'<br />';
13524: }
1.1086 raeburn 13525: }
13526: if (-e "$fullpath/$title") {
13527: my $showpath;
13528: if ($relpath ne '') {
13529: $showpath = "$relpath/$title";
13530: } else {
13531: $showpath = "/$title";
13532: }
1.1294 raeburn 13533: $result .= '<li>'.&mt('[_1] included as a dependency',
13534: &HTML::Entities::encode($showpath,'<>&"')).
13535: '</li>'."\n";
1.1292 raeburn 13536: unless ($ishome) {
13537: my $fetch = "$fullpath/$title";
13538: $fetch =~ s/^\Q$prefix$dir\E//;
13539: $prompttofetch{$fetch} = 1;
13540: }
1.1086 raeburn 13541: }
13542: }
1.1055 raeburn 13543: }
1.1086 raeburn 13544: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13545: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
1.1294 raeburn 13546: &HTML::Entities::encode($path,'<>&"'),
13547: &HTML::Entities::encode($env{'form.archive_content_'.$referrer{$i}},'<>&"')).
13548: '<br />';
1.1055 raeburn 13549: }
13550: } else {
1.1294 raeburn 13551: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',
1.1296 raeburn 13552: &HTML::Entities::encode($path)).'<br />';
1.1055 raeburn 13553: }
13554: }
13555: if (keys(%todelete)) {
13556: foreach my $key (keys(%todelete)) {
13557: unlink($key);
1.1066 raeburn 13558: }
13559: }
13560: if (keys(%todeletedir)) {
13561: foreach my $key (keys(%todeletedir)) {
13562: rmdir($key);
13563: }
13564: }
13565: foreach my $dir (sort(keys(%is_dir))) {
13566: if (($pathtocheck ne '') && ($dir ne '')) {
13567: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13568: }
13569: }
1.1067 raeburn 13570: if ($result ne '') {
13571: $output .= '<ul>'."\n".
13572: $result."\n".
13573: '</ul>';
13574: }
13575: unless ($ishome) {
13576: my $replicationfail;
13577: foreach my $item (keys(%prompttofetch)) {
13578: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13579: unless ($fetchresult eq 'ok') {
13580: $replicationfail .= '<li>'.$item.'</li>'."\n";
13581: }
13582: }
13583: if ($replicationfail) {
13584: $output .= '<p class="LC_error">'.
13585: &mt('Course home server failed to retrieve:').'<ul>'.
13586: $replicationfail.
13587: '</ul></p>';
13588: }
13589: }
1.1055 raeburn 13590: } else {
13591: $warning = &mt('No items found in archive.');
13592: }
13593: if ($error) {
13594: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13595: $error.'</p>'."\n";
13596: }
13597: if ($warning) {
13598: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13599: }
13600: return $output;
13601: }
13602:
1.1066 raeburn 13603: sub cleanup_empty_dirs {
13604: my ($path) = @_;
13605: if (($path ne '') && (-d $path)) {
13606: if (opendir(my $dirh,$path)) {
13607: my @dircontents = grep(!/^\./,readdir($dirh));
13608: my $numitems = 0;
13609: foreach my $item (@dircontents) {
13610: if (-d "$path/$item") {
1.1111 raeburn 13611: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13612: if (-e "$path/$item") {
13613: $numitems ++;
13614: }
13615: } else {
13616: $numitems ++;
13617: }
13618: }
13619: if ($numitems == 0) {
13620: rmdir($path);
13621: }
13622: closedir($dirh);
13623: }
13624: }
13625: return;
13626: }
13627:
1.41 ng 13628: =pod
1.45 matthew 13629:
1.1162 raeburn 13630: =item * &get_folder_hierarchy()
1.1068 raeburn 13631:
13632: Provides hierarchy of names of folders/sub-folders containing the current
13633: item,
13634:
13635: Inputs: 3
13636: - $navmap - navmaps object
13637:
13638: - $map - url for map (either the trigger itself, or map containing
13639: the resource, which is the trigger).
13640:
13641: - $showitem - 1 => show title for map itself; 0 => do not show.
13642:
13643: Outputs: 1 @pathitems - array of folder/subfolder names.
13644:
13645: =cut
13646:
13647: sub get_folder_hierarchy {
13648: my ($navmap,$map,$showitem) = @_;
13649: my @pathitems;
13650: if (ref($navmap)) {
13651: my $mapres = $navmap->getResourceByUrl($map);
13652: if (ref($mapres)) {
13653: my $pcslist = $mapres->map_hierarchy();
13654: if ($pcslist ne '') {
13655: my @pcs = split(/,/,$pcslist);
13656: foreach my $pc (@pcs) {
13657: if ($pc == 1) {
1.1129 raeburn 13658: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13659: } else {
13660: my $res = $navmap->getByMapPc($pc);
13661: if (ref($res)) {
13662: my $title = $res->compTitle();
13663: $title =~ s/\W+/_/g;
13664: if ($title ne '') {
13665: push(@pathitems,$title);
13666: }
13667: }
13668: }
13669: }
13670: }
1.1071 raeburn 13671: if ($showitem) {
13672: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13673: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13674: } else {
13675: my $maptitle = $mapres->compTitle();
13676: $maptitle =~ s/\W+/_/g;
13677: if ($maptitle ne '') {
13678: push(@pathitems,$maptitle);
13679: }
1.1068 raeburn 13680: }
13681: }
13682: }
13683: }
13684: return @pathitems;
13685: }
13686:
13687: =pod
13688:
1.1015 raeburn 13689: =item * &get_turnedin_filepath()
13690:
13691: Determines path in a user's portfolio file for storage of files uploaded
13692: to a specific essayresponse or dropbox item.
13693:
13694: Inputs: 3 required + 1 optional.
13695: $symb is symb for resource, $uname and $udom are for current user (required).
13696: $caller is optional (can be "submission", if routine is called when storing
13697: an upoaded file when "Submit Answer" button was pressed).
13698:
13699: Returns array containing $path and $multiresp.
13700: $path is path in portfolio. $multiresp is 1 if this resource contains more
13701: than one file upload item. Callers of routine should append partid as a
13702: subdirectory to $path in cases where $multiresp is 1.
13703:
13704: Called by: homework/essayresponse.pm and homework/structuretags.pm
13705:
13706: =cut
13707:
13708: sub get_turnedin_filepath {
13709: my ($symb,$uname,$udom,$caller) = @_;
13710: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13711: my $turnindir;
13712: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13713: $turnindir = $userhash{'turnindir'};
13714: my ($path,$multiresp);
13715: if ($turnindir eq '') {
13716: if ($caller eq 'submission') {
13717: $turnindir = &mt('turned in');
13718: $turnindir =~ s/\W+/_/g;
13719: my %newhash = (
13720: 'turnindir' => $turnindir,
13721: );
13722: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13723: }
13724: }
13725: if ($turnindir ne '') {
13726: $path = '/'.$turnindir.'/';
13727: my ($multipart,$turnin,@pathitems);
13728: my $navmap = Apache::lonnavmaps::navmap->new();
13729: if (defined($navmap)) {
13730: my $mapres = $navmap->getResourceByUrl($map);
13731: if (ref($mapres)) {
13732: my $pcslist = $mapres->map_hierarchy();
13733: if ($pcslist ne '') {
13734: foreach my $pc (split(/,/,$pcslist)) {
13735: my $res = $navmap->getByMapPc($pc);
13736: if (ref($res)) {
13737: my $title = $res->compTitle();
13738: $title =~ s/\W+/_/g;
13739: if ($title ne '') {
1.1149 raeburn 13740: if (($pc > 1) && (length($title) > 12)) {
13741: $title = substr($title,0,12);
13742: }
1.1015 raeburn 13743: push(@pathitems,$title);
13744: }
13745: }
13746: }
13747: }
13748: my $maptitle = $mapres->compTitle();
13749: $maptitle =~ s/\W+/_/g;
13750: if ($maptitle ne '') {
1.1149 raeburn 13751: if (length($maptitle) > 12) {
13752: $maptitle = substr($maptitle,0,12);
13753: }
1.1015 raeburn 13754: push(@pathitems,$maptitle);
13755: }
13756: unless ($env{'request.state'} eq 'construct') {
13757: my $res = $navmap->getBySymb($symb);
13758: if (ref($res)) {
13759: my $partlist = $res->parts();
13760: my $totaluploads = 0;
13761: if (ref($partlist) eq 'ARRAY') {
13762: foreach my $part (@{$partlist}) {
13763: my @types = $res->responseType($part);
13764: my @ids = $res->responseIds($part);
13765: for (my $i=0; $i < scalar(@ids); $i++) {
13766: if ($types[$i] eq 'essay') {
13767: my $partid = $part.'_'.$ids[$i];
13768: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13769: $totaluploads ++;
13770: }
13771: }
13772: }
13773: }
13774: if ($totaluploads > 1) {
13775: $multiresp = 1;
13776: }
13777: }
13778: }
13779: }
13780: } else {
13781: return;
13782: }
13783: } else {
13784: return;
13785: }
13786: my $restitle=&Apache::lonnet::gettitle($symb);
13787: $restitle =~ s/\W+/_/g;
13788: if ($restitle eq '') {
13789: $restitle = ($resurl =~ m{/[^/]+$});
13790: if ($restitle eq '') {
13791: $restitle = time;
13792: }
13793: }
1.1149 raeburn 13794: if (length($restitle) > 12) {
13795: $restitle = substr($restitle,0,12);
13796: }
1.1015 raeburn 13797: push(@pathitems,$restitle);
13798: $path .= join('/',@pathitems);
13799: }
13800: return ($path,$multiresp);
13801: }
13802:
13803: =pod
13804:
1.464 albertel 13805: =back
1.41 ng 13806:
1.112 bowersj2 13807: =head1 CSV Upload/Handling functions
1.38 albertel 13808:
1.41 ng 13809: =over 4
13810:
1.648 raeburn 13811: =item * &upfile_store($r)
1.41 ng 13812:
13813: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13814: needs $env{'form.upfile'}
1.41 ng 13815: returns $datatoken to be put into hidden field
13816:
13817: =cut
1.31 albertel 13818:
13819: sub upfile_store {
13820: my $r=shift;
1.258 albertel 13821: $env{'form.upfile'}=~s/\r/\n/gs;
13822: $env{'form.upfile'}=~s/\f/\n/gs;
13823: $env{'form.upfile'}=~s/\n+/\n/gs;
13824: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13825:
1.1299 raeburn 13826: my $datatoken = &valid_datatoken($env{'user.name'}.'_'.$env{'user.domain'}.
13827: '_enroll_'.$env{'request.course.id'}.'_'.
13828: time.'_'.$$);
13829: return if ($datatoken eq '');
13830:
1.31 albertel 13831: {
1.158 raeburn 13832: my $datafile = $r->dir_config('lonDaemons').
13833: '/tmp/'.$datatoken.'.tmp';
13834: if ( open(my $fh,">$datafile") ) {
1.258 albertel 13835: print $fh $env{'form.upfile'};
1.158 raeburn 13836: close($fh);
13837: }
1.31 albertel 13838: }
13839: return $datatoken;
13840: }
13841:
1.56 matthew 13842: =pod
13843:
1.1290 raeburn 13844: =item * &load_tmp_file($r,$datatoken)
1.41 ng 13845:
13846: Load uploaded file from tmp, $r should be the HTTP Request object,
1.1290 raeburn 13847: $datatoken is the name to assign to the temporary file.
1.258 albertel 13848: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13849:
13850: =cut
1.31 albertel 13851:
13852: sub load_tmp_file {
1.1290 raeburn 13853: my ($r,$datatoken) = @_;
13854: return if ($datatoken eq '');
1.31 albertel 13855: my @studentdata=();
13856: {
1.158 raeburn 13857: my $studentfile = $r->dir_config('lonDaemons').
1.1290 raeburn 13858: '/tmp/'.$datatoken.'.tmp';
1.158 raeburn 13859: if ( open(my $fh,"<$studentfile") ) {
13860: @studentdata=<$fh>;
13861: close($fh);
13862: }
1.31 albertel 13863: }
1.258 albertel 13864: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13865: }
13866:
1.1290 raeburn 13867: sub valid_datatoken {
13868: my ($datatoken) = @_;
1.1291 raeburn 13869: if ($datatoken =~ /^$match_username\_$match_domain\_enroll_$match_domain\_$match_courseid\_\d+_\d+$/) {
1.1290 raeburn 13870: return $datatoken;
13871: }
13872: return;
13873: }
13874:
1.56 matthew 13875: =pod
13876:
1.648 raeburn 13877: =item * &upfile_record_sep()
1.41 ng 13878:
13879: Separate uploaded file into records
13880: returns array of records,
1.258 albertel 13881: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13882:
13883: =cut
1.31 albertel 13884:
13885: sub upfile_record_sep {
1.258 albertel 13886: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13887: } else {
1.248 albertel 13888: my @records;
1.258 albertel 13889: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13890: if ($line=~/^\s*$/) { next; }
13891: push(@records,$line);
13892: }
13893: return @records;
1.31 albertel 13894: }
13895: }
13896:
1.56 matthew 13897: =pod
13898:
1.648 raeburn 13899: =item * &record_sep($record)
1.41 ng 13900:
1.258 albertel 13901: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13902:
13903: =cut
13904:
1.263 www 13905: sub takeleft {
13906: my $index=shift;
13907: return substr('0000'.$index,-4,4);
13908: }
13909:
1.31 albertel 13910: sub record_sep {
13911: my $record=shift;
13912: my %components=();
1.258 albertel 13913: if ($env{'form.upfiletype'} eq 'xml') {
13914: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13915: my $i=0;
1.356 albertel 13916: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13917: $field=~s/^(\"|\')//;
13918: $field=~s/(\"|\')$//;
1.263 www 13919: $components{&takeleft($i)}=$field;
1.31 albertel 13920: $i++;
13921: }
1.258 albertel 13922: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13923: my $i=0;
1.356 albertel 13924: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13925: $field=~s/^(\"|\')//;
13926: $field=~s/(\"|\')$//;
1.263 www 13927: $components{&takeleft($i)}=$field;
1.31 albertel 13928: $i++;
13929: }
13930: } else {
1.561 www 13931: my $separator=',';
1.480 banghart 13932: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13933: $separator=';';
1.480 banghart 13934: }
1.31 albertel 13935: my $i=0;
1.561 www 13936: # the character we are looking for to indicate the end of a quote or a record
13937: my $looking_for=$separator;
13938: # do not add the characters to the fields
13939: my $ignore=0;
13940: # we just encountered a separator (or the beginning of the record)
13941: my $just_found_separator=1;
13942: # store the field we are working on here
13943: my $field='';
13944: # work our way through all characters in record
13945: foreach my $character ($record=~/(.)/g) {
13946: if ($character eq $looking_for) {
13947: if ($character ne $separator) {
13948: # Found the end of a quote, again looking for separator
13949: $looking_for=$separator;
13950: $ignore=1;
13951: } else {
13952: # Found a separator, store away what we got
13953: $components{&takeleft($i)}=$field;
13954: $i++;
13955: $just_found_separator=1;
13956: $ignore=0;
13957: $field='';
13958: }
13959: next;
13960: }
13961: # single or double quotation marks after a separator indicate beginning of a quote
13962: # we are now looking for the end of the quote and need to ignore separators
13963: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13964: $looking_for=$character;
13965: next;
13966: }
13967: # ignore would be true after we reached the end of a quote
13968: if ($ignore) { next; }
13969: if (($just_found_separator) && ($character=~/\s/)) { next; }
13970: $field.=$character;
13971: $just_found_separator=0;
1.31 albertel 13972: }
1.561 www 13973: # catch the very last entry, since we never encountered the separator
13974: $components{&takeleft($i)}=$field;
1.31 albertel 13975: }
13976: return %components;
13977: }
13978:
1.144 matthew 13979: ######################################################
13980: ######################################################
13981:
1.56 matthew 13982: =pod
13983:
1.648 raeburn 13984: =item * &upfile_select_html()
1.41 ng 13985:
1.144 matthew 13986: Return HTML code to select a file from the users machine and specify
13987: the file type.
1.41 ng 13988:
13989: =cut
13990:
1.144 matthew 13991: ######################################################
13992: ######################################################
1.31 albertel 13993: sub upfile_select_html {
1.144 matthew 13994: my %Types = (
13995: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13996: semisv => &mt('Semicolon separated values'),
1.144 matthew 13997: space => &mt('Space separated'),
13998: tab => &mt('Tabulator separated'),
13999: # xml => &mt('HTML/XML'),
14000: );
14001: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 14002: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 14003: foreach my $type (sort(keys(%Types))) {
14004: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
14005: }
14006: $Str .= "</select>\n";
14007: return $Str;
1.31 albertel 14008: }
14009:
1.301 albertel 14010: sub get_samples {
14011: my ($records,$toget) = @_;
14012: my @samples=({});
14013: my $got=0;
14014: foreach my $rec (@$records) {
14015: my %temp = &record_sep($rec);
14016: if (! grep(/\S/, values(%temp))) { next; }
14017: if (%temp) {
14018: $samples[$got]=\%temp;
14019: $got++;
14020: if ($got == $toget) { last; }
14021: }
14022: }
14023: return \@samples;
14024: }
14025:
1.144 matthew 14026: ######################################################
14027: ######################################################
14028:
1.56 matthew 14029: =pod
14030:
1.648 raeburn 14031: =item * &csv_print_samples($r,$records)
1.41 ng 14032:
14033: Prints a table of sample values from each column uploaded $r is an
14034: Apache Request ref, $records is an arrayref from
14035: &Apache::loncommon::upfile_record_sep
14036:
14037: =cut
14038:
1.144 matthew 14039: ######################################################
14040: ######################################################
1.31 albertel 14041: sub csv_print_samples {
14042: my ($r,$records) = @_;
1.662 bisitz 14043: my $samples = &get_samples($records,5);
1.301 albertel 14044:
1.594 raeburn 14045: $r->print(&mt('Samples').'<br />'.&start_data_table().
14046: &start_data_table_header_row());
1.356 albertel 14047: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 14048: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 14049: $r->print(&end_data_table_header_row());
1.301 albertel 14050: foreach my $hash (@$samples) {
1.594 raeburn 14051: $r->print(&start_data_table_row());
1.356 albertel 14052: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 14053: $r->print('<td>');
1.356 albertel 14054: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 14055: $r->print('</td>');
14056: }
1.594 raeburn 14057: $r->print(&end_data_table_row());
1.31 albertel 14058: }
1.594 raeburn 14059: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 14060: }
14061:
1.144 matthew 14062: ######################################################
14063: ######################################################
14064:
1.56 matthew 14065: =pod
14066:
1.648 raeburn 14067: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 14068:
14069: Prints a table to create associations between values and table columns.
1.144 matthew 14070:
1.41 ng 14071: $r is an Apache Request ref,
14072: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 14073: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 14074:
14075: =cut
14076:
1.144 matthew 14077: ######################################################
14078: ######################################################
1.31 albertel 14079: sub csv_print_select_table {
14080: my ($r,$records,$d) = @_;
1.301 albertel 14081: my $i=0;
14082: my $samples = &get_samples($records,1);
1.144 matthew 14083: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 14084: &start_data_table().&start_data_table_header_row().
1.144 matthew 14085: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 14086: '<th>'.&mt('Column').'</th>'.
14087: &end_data_table_header_row()."\n");
1.356 albertel 14088: foreach my $array_ref (@$d) {
14089: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 14090: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 14091:
1.875 bisitz 14092: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 14093: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 14094: $r->print('<option value="none"></option>');
1.356 albertel 14095: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
14096: $r->print('<option value="'.$sample.'"'.
14097: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 14098: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 14099: }
1.594 raeburn 14100: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 14101: $i++;
14102: }
1.594 raeburn 14103: $r->print(&end_data_table());
1.31 albertel 14104: $i--;
14105: return $i;
14106: }
1.56 matthew 14107:
1.144 matthew 14108: ######################################################
14109: ######################################################
14110:
1.56 matthew 14111: =pod
1.31 albertel 14112:
1.648 raeburn 14113: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 14114:
14115: Prints a table of sample values from the upload and can make associate samples to internal names.
14116:
14117: $r is an Apache Request ref,
14118: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
14119: $d is an array of 2 element arrays (internal name, displayed name)
14120:
14121: =cut
14122:
1.144 matthew 14123: ######################################################
14124: ######################################################
1.31 albertel 14125: sub csv_samples_select_table {
14126: my ($r,$records,$d) = @_;
14127: my $i=0;
1.144 matthew 14128: #
1.662 bisitz 14129: my $max_samples = 5;
14130: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 14131: $r->print(&start_data_table().
14132: &start_data_table_header_row().'<th>'.
14133: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
14134: &end_data_table_header_row());
1.301 albertel 14135:
14136: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 14137: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 14138: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 14139: foreach my $option (@$d) {
14140: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 14141: $r->print('<option value="'.$value.'"'.
1.253 albertel 14142: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 14143: $display.'</option>');
1.31 albertel 14144: }
14145: $r->print('</select></td><td>');
1.662 bisitz 14146: foreach my $line (0..($max_samples-1)) {
1.301 albertel 14147: if (defined($samples->[$line]{$key})) {
14148: $r->print($samples->[$line]{$key}."<br />\n");
14149: }
14150: }
1.594 raeburn 14151: $r->print('</td>'.&end_data_table_row());
1.31 albertel 14152: $i++;
14153: }
1.594 raeburn 14154: $r->print(&end_data_table());
1.31 albertel 14155: $i--;
14156: return($i);
1.115 matthew 14157: }
14158:
1.144 matthew 14159: ######################################################
14160: ######################################################
14161:
1.115 matthew 14162: =pod
14163:
1.648 raeburn 14164: =item * &clean_excel_name($name)
1.115 matthew 14165:
14166: Returns a replacement for $name which does not contain any illegal characters.
14167:
14168: =cut
14169:
1.144 matthew 14170: ######################################################
14171: ######################################################
1.115 matthew 14172: sub clean_excel_name {
14173: my ($name) = @_;
14174: $name =~ s/[:\*\?\/\\]//g;
14175: if (length($name) > 31) {
14176: $name = substr($name,0,31);
14177: }
14178: return $name;
1.25 albertel 14179: }
1.84 albertel 14180:
1.85 albertel 14181: =pod
14182:
1.648 raeburn 14183: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 14184:
14185: Returns either 1 or undef
14186:
14187: 1 if the part is to be hidden, undef if it is to be shown
14188:
14189: Arguments are:
14190:
14191: $id the id of the part to be checked
14192: $symb, optional the symb of the resource to check
14193: $udom, optional the domain of the user to check for
14194: $uname, optional the username of the user to check for
14195:
14196: =cut
1.84 albertel 14197:
14198: sub check_if_partid_hidden {
14199: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 14200: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 14201: $symb,$udom,$uname);
1.141 albertel 14202: my $truth=1;
14203: #if the string starts with !, then the list is the list to show not hide
14204: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 14205: my @hiddenlist=split(/,/,$hiddenparts);
14206: foreach my $checkid (@hiddenlist) {
1.141 albertel 14207: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 14208: }
1.141 albertel 14209: return !$truth;
1.84 albertel 14210: }
1.127 matthew 14211:
1.138 matthew 14212:
14213: ############################################################
14214: ############################################################
14215:
14216: =pod
14217:
1.157 matthew 14218: =back
14219:
1.138 matthew 14220: =head1 cgi-bin script and graphing routines
14221:
1.157 matthew 14222: =over 4
14223:
1.648 raeburn 14224: =item * &get_cgi_id()
1.138 matthew 14225:
14226: Inputs: none
14227:
14228: Returns an id which can be used to pass environment variables
14229: to various cgi-bin scripts. These environment variables will
14230: be removed from the users environment after a given time by
14231: the routine &Apache::lonnet::transfer_profile_to_env.
14232:
14233: =cut
14234:
14235: ############################################################
14236: ############################################################
1.152 albertel 14237: my $uniq=0;
1.136 matthew 14238: sub get_cgi_id {
1.154 albertel 14239: $uniq=($uniq+1)%100000;
1.280 albertel 14240: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14241: }
14242:
1.127 matthew 14243: ############################################################
14244: ############################################################
14245:
14246: =pod
14247:
1.648 raeburn 14248: =item * &DrawBarGraph()
1.127 matthew 14249:
1.138 matthew 14250: Facilitates the plotting of data in a (stacked) bar graph.
14251: Puts plot definition data into the users environment in order for
14252: graph.png to plot it. Returns an <img> tag for the plot.
14253: The bars on the plot are labeled '1','2',...,'n'.
14254:
14255: Inputs:
14256:
14257: =over 4
14258:
14259: =item $Title: string, the title of the plot
14260:
14261: =item $xlabel: string, text describing the X-axis of the plot
14262:
14263: =item $ylabel: string, text describing the Y-axis of the plot
14264:
14265: =item $Max: scalar, the maximum Y value to use in the plot
14266: If $Max is < any data point, the graph will not be rendered.
14267:
1.140 matthew 14268: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14269: they are plotted. If undefined, default values will be used.
14270:
1.178 matthew 14271: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14272:
1.138 matthew 14273: =item @Values: An array of array references. Each array reference holds data
14274: to be plotted in a stacked bar chart.
14275:
1.239 matthew 14276: =item If the final element of @Values is a hash reference the key/value
14277: pairs will be added to the graph definition.
14278:
1.138 matthew 14279: =back
14280:
14281: Returns:
14282:
14283: An <img> tag which references graph.png and the appropriate identifying
14284: information for the plot.
14285:
1.127 matthew 14286: =cut
14287:
14288: ############################################################
14289: ############################################################
1.134 matthew 14290: sub DrawBarGraph {
1.178 matthew 14291: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14292: #
14293: if (! defined($colors)) {
14294: $colors = ['#33ff00',
14295: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14296: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14297: ];
14298: }
1.228 matthew 14299: my $extra_settings = {};
14300: if (ref($Values[-1]) eq 'HASH') {
14301: $extra_settings = pop(@Values);
14302: }
1.127 matthew 14303: #
1.136 matthew 14304: my $identifier = &get_cgi_id();
14305: my $id = 'cgi.'.$identifier;
1.129 matthew 14306: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14307: return '';
14308: }
1.225 matthew 14309: #
14310: my @Labels;
14311: if (defined($labels)) {
14312: @Labels = @$labels;
14313: } else {
14314: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14315: push(@Labels,$i+1);
1.225 matthew 14316: }
14317: }
14318: #
1.129 matthew 14319: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14320: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14321: my %ValuesHash;
14322: my $NumSets=1;
14323: foreach my $array (@Values) {
14324: next if (! ref($array));
1.136 matthew 14325: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14326: join(',',@$array);
1.129 matthew 14327: }
1.127 matthew 14328: #
1.136 matthew 14329: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14330: if ($NumBars < 3) {
14331: $width = 120+$NumBars*32;
1.220 matthew 14332: $xskip = 1;
1.225 matthew 14333: $bar_width = 30;
14334: } elsif ($NumBars < 5) {
14335: $width = 120+$NumBars*20;
14336: $xskip = 1;
14337: $bar_width = 20;
1.220 matthew 14338: } elsif ($NumBars < 10) {
1.136 matthew 14339: $width = 120+$NumBars*15;
14340: $xskip = 1;
14341: $bar_width = 15;
14342: } elsif ($NumBars <= 25) {
14343: $width = 120+$NumBars*11;
14344: $xskip = 5;
14345: $bar_width = 8;
14346: } elsif ($NumBars <= 50) {
14347: $width = 120+$NumBars*8;
14348: $xskip = 5;
14349: $bar_width = 4;
14350: } else {
14351: $width = 120+$NumBars*8;
14352: $xskip = 5;
14353: $bar_width = 4;
14354: }
14355: #
1.137 matthew 14356: $Max = 1 if ($Max < 1);
14357: if ( int($Max) < $Max ) {
14358: $Max++;
14359: $Max = int($Max);
14360: }
1.127 matthew 14361: $Title = '' if (! defined($Title));
14362: $xlabel = '' if (! defined($xlabel));
14363: $ylabel = '' if (! defined($ylabel));
1.369 www 14364: $ValuesHash{$id.'.title'} = &escape($Title);
14365: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14366: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14367: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14368: $ValuesHash{$id.'.NumBars'} = $NumBars;
14369: $ValuesHash{$id.'.NumSets'} = $NumSets;
14370: $ValuesHash{$id.'.PlotType'} = 'bar';
14371: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14372: $ValuesHash{$id.'.height'} = $height;
14373: $ValuesHash{$id.'.width'} = $width;
14374: $ValuesHash{$id.'.xskip'} = $xskip;
14375: $ValuesHash{$id.'.bar_width'} = $bar_width;
14376: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14377: #
1.228 matthew 14378: # Deal with other parameters
14379: while (my ($key,$value) = each(%$extra_settings)) {
14380: $ValuesHash{$id.'.'.$key} = $value;
14381: }
14382: #
1.646 raeburn 14383: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14384: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14385: }
14386:
14387: ############################################################
14388: ############################################################
14389:
14390: =pod
14391:
1.648 raeburn 14392: =item * &DrawXYGraph()
1.137 matthew 14393:
1.138 matthew 14394: Facilitates the plotting of data in an XY graph.
14395: Puts plot definition data into the users environment in order for
14396: graph.png to plot it. Returns an <img> tag for the plot.
14397:
14398: Inputs:
14399:
14400: =over 4
14401:
14402: =item $Title: string, the title of the plot
14403:
14404: =item $xlabel: string, text describing the X-axis of the plot
14405:
14406: =item $ylabel: string, text describing the Y-axis of the plot
14407:
14408: =item $Max: scalar, the maximum Y value to use in the plot
14409: If $Max is < any data point, the graph will not be rendered.
14410:
14411: =item $colors: Array ref containing the hex color codes for the data to be
14412: plotted in. If undefined, default values will be used.
14413:
14414: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14415:
14416: =item $Ydata: Array ref containing Array refs.
1.185 www 14417: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14418:
14419: =item %Values: hash indicating or overriding any default values which are
14420: passed to graph.png.
14421: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14422:
14423: =back
14424:
14425: Returns:
14426:
14427: An <img> tag which references graph.png and the appropriate identifying
14428: information for the plot.
14429:
1.137 matthew 14430: =cut
14431:
14432: ############################################################
14433: ############################################################
14434: sub DrawXYGraph {
14435: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14436: #
14437: # Create the identifier for the graph
14438: my $identifier = &get_cgi_id();
14439: my $id = 'cgi.'.$identifier;
14440: #
14441: $Title = '' if (! defined($Title));
14442: $xlabel = '' if (! defined($xlabel));
14443: $ylabel = '' if (! defined($ylabel));
14444: my %ValuesHash =
14445: (
1.369 www 14446: $id.'.title' => &escape($Title),
14447: $id.'.xlabel' => &escape($xlabel),
14448: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14449: $id.'.y_max_value'=> $Max,
14450: $id.'.labels' => join(',',@$Xlabels),
14451: $id.'.PlotType' => 'XY',
14452: );
14453: #
14454: if (defined($colors) && ref($colors) eq 'ARRAY') {
14455: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14456: }
14457: #
14458: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14459: return '';
14460: }
14461: my $NumSets=1;
1.138 matthew 14462: foreach my $array (@{$Ydata}){
1.137 matthew 14463: next if (! ref($array));
14464: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14465: }
1.138 matthew 14466: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14467: #
14468: # Deal with other parameters
14469: while (my ($key,$value) = each(%Values)) {
14470: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14471: }
14472: #
1.646 raeburn 14473: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14474: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14475: }
14476:
14477: ############################################################
14478: ############################################################
14479:
14480: =pod
14481:
1.648 raeburn 14482: =item * &DrawXYYGraph()
1.138 matthew 14483:
14484: Facilitates the plotting of data in an XY graph with two Y axes.
14485: Puts plot definition data into the users environment in order for
14486: graph.png to plot it. Returns an <img> tag for the plot.
14487:
14488: Inputs:
14489:
14490: =over 4
14491:
14492: =item $Title: string, the title of the plot
14493:
14494: =item $xlabel: string, text describing the X-axis of the plot
14495:
14496: =item $ylabel: string, text describing the Y-axis of the plot
14497:
14498: =item $colors: Array ref containing the hex color codes for the data to be
14499: plotted in. If undefined, default values will be used.
14500:
14501: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14502:
14503: =item $Ydata1: The first data set
14504:
14505: =item $Min1: The minimum value of the left Y-axis
14506:
14507: =item $Max1: The maximum value of the left Y-axis
14508:
14509: =item $Ydata2: The second data set
14510:
14511: =item $Min2: The minimum value of the right Y-axis
14512:
14513: =item $Max2: The maximum value of the left Y-axis
14514:
14515: =item %Values: hash indicating or overriding any default values which are
14516: passed to graph.png.
14517: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14518:
14519: =back
14520:
14521: Returns:
14522:
14523: An <img> tag which references graph.png and the appropriate identifying
14524: information for the plot.
1.136 matthew 14525:
14526: =cut
14527:
14528: ############################################################
14529: ############################################################
1.137 matthew 14530: sub DrawXYYGraph {
14531: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14532: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14533: #
14534: # Create the identifier for the graph
14535: my $identifier = &get_cgi_id();
14536: my $id = 'cgi.'.$identifier;
14537: #
14538: $Title = '' if (! defined($Title));
14539: $xlabel = '' if (! defined($xlabel));
14540: $ylabel = '' if (! defined($ylabel));
14541: my %ValuesHash =
14542: (
1.369 www 14543: $id.'.title' => &escape($Title),
14544: $id.'.xlabel' => &escape($xlabel),
14545: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14546: $id.'.labels' => join(',',@$Xlabels),
14547: $id.'.PlotType' => 'XY',
14548: $id.'.NumSets' => 2,
1.137 matthew 14549: $id.'.two_axes' => 1,
14550: $id.'.y1_max_value' => $Max1,
14551: $id.'.y1_min_value' => $Min1,
14552: $id.'.y2_max_value' => $Max2,
14553: $id.'.y2_min_value' => $Min2,
1.136 matthew 14554: );
14555: #
1.137 matthew 14556: if (defined($colors) && ref($colors) eq 'ARRAY') {
14557: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14558: }
14559: #
14560: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14561: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14562: return '';
14563: }
14564: my $NumSets=1;
1.137 matthew 14565: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14566: next if (! ref($array));
14567: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14568: }
14569: #
14570: # Deal with other parameters
14571: while (my ($key,$value) = each(%Values)) {
14572: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14573: }
14574: #
1.646 raeburn 14575: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14576: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14577: }
14578:
14579: ############################################################
14580: ############################################################
14581:
14582: =pod
14583:
1.157 matthew 14584: =back
14585:
1.139 matthew 14586: =head1 Statistics helper routines?
14587:
14588: Bad place for them but what the hell.
14589:
1.157 matthew 14590: =over 4
14591:
1.648 raeburn 14592: =item * &chartlink()
1.139 matthew 14593:
14594: Returns a link to the chart for a specific student.
14595:
14596: Inputs:
14597:
14598: =over 4
14599:
14600: =item $linktext: The text of the link
14601:
14602: =item $sname: The students username
14603:
14604: =item $sdomain: The students domain
14605:
14606: =back
14607:
1.157 matthew 14608: =back
14609:
1.139 matthew 14610: =cut
14611:
14612: ############################################################
14613: ############################################################
14614: sub chartlink {
14615: my ($linktext, $sname, $sdomain) = @_;
14616: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14617: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14618: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14619: '">'.$linktext.'</a>';
1.153 matthew 14620: }
14621:
14622: #######################################################
14623: #######################################################
14624:
14625: =pod
14626:
14627: =head1 Course Environment Routines
1.157 matthew 14628:
14629: =over 4
1.153 matthew 14630:
1.648 raeburn 14631: =item * &restore_course_settings()
1.153 matthew 14632:
1.648 raeburn 14633: =item * &store_course_settings()
1.153 matthew 14634:
14635: Restores/Store indicated form parameters from the course environment.
14636: Will not overwrite existing values of the form parameters.
14637:
14638: Inputs:
14639: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14640:
14641: a hash ref describing the data to be stored. For example:
14642:
14643: %Save_Parameters = ('Status' => 'scalar',
14644: 'chartoutputmode' => 'scalar',
14645: 'chartoutputdata' => 'scalar',
14646: 'Section' => 'array',
1.373 raeburn 14647: 'Group' => 'array',
1.153 matthew 14648: 'StudentData' => 'array',
14649: 'Maps' => 'array');
14650:
14651: Returns: both routines return nothing
14652:
1.631 raeburn 14653: =back
14654:
1.153 matthew 14655: =cut
14656:
14657: #######################################################
14658: #######################################################
14659: sub store_course_settings {
1.496 albertel 14660: return &store_settings($env{'request.course.id'},@_);
14661: }
14662:
14663: sub store_settings {
1.153 matthew 14664: # save to the environment
14665: # appenv the same items, just to be safe
1.300 albertel 14666: my $udom = $env{'user.domain'};
14667: my $uname = $env{'user.name'};
1.496 albertel 14668: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14669: my %SaveHash;
14670: my %AppHash;
14671: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14672: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14673: my $envname = 'environment.'.$basename;
1.258 albertel 14674: if (exists($env{'form.'.$setting})) {
1.153 matthew 14675: # Save this value away
14676: if ($type eq 'scalar' &&
1.258 albertel 14677: (! exists($env{$envname}) ||
14678: $env{$envname} ne $env{'form.'.$setting})) {
14679: $SaveHash{$basename} = $env{'form.'.$setting};
14680: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14681: } elsif ($type eq 'array') {
14682: my $stored_form;
1.258 albertel 14683: if (ref($env{'form.'.$setting})) {
1.153 matthew 14684: $stored_form = join(',',
14685: map {
1.369 www 14686: &escape($_);
1.258 albertel 14687: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14688: } else {
14689: $stored_form =
1.369 www 14690: &escape($env{'form.'.$setting});
1.153 matthew 14691: }
14692: # Determine if the array contents are the same.
1.258 albertel 14693: if ($stored_form ne $env{$envname}) {
1.153 matthew 14694: $SaveHash{$basename} = $stored_form;
14695: $AppHash{$envname} = $stored_form;
14696: }
14697: }
14698: }
14699: }
14700: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14701: $udom,$uname);
1.153 matthew 14702: if ($put_result !~ /^(ok|delayed)/) {
14703: &Apache::lonnet::logthis('unable to save form parameters, '.
14704: 'got error:'.$put_result);
14705: }
14706: # Make sure these settings stick around in this session, too
1.646 raeburn 14707: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14708: return;
14709: }
14710:
14711: sub restore_course_settings {
1.499 albertel 14712: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14713: }
14714:
14715: sub restore_settings {
14716: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14717: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14718: next if (exists($env{'form.'.$setting}));
1.496 albertel 14719: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14720: '.'.$setting;
1.258 albertel 14721: if (exists($env{$envname})) {
1.153 matthew 14722: if ($type eq 'scalar') {
1.258 albertel 14723: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14724: } elsif ($type eq 'array') {
1.258 albertel 14725: $env{'form.'.$setting} = [
1.153 matthew 14726: map {
1.369 www 14727: &unescape($_);
1.258 albertel 14728: } split(',',$env{$envname})
1.153 matthew 14729: ];
14730: }
14731: }
14732: }
1.127 matthew 14733: }
14734:
1.618 raeburn 14735: #######################################################
14736: #######################################################
14737:
14738: =pod
14739:
14740: =head1 Domain E-mail Routines
14741:
14742: =over 4
14743:
1.648 raeburn 14744: =item * &build_recipient_list()
1.618 raeburn 14745:
1.1144 raeburn 14746: Build recipient lists for following types of e-mail:
1.766 raeburn 14747: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14748: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14749: module change checking, student/employee ID conflict checks, as
14750: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14751: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14752:
14753: Inputs:
1.619 raeburn 14754: defmail (scalar - email address of default recipient),
1.1144 raeburn 14755: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14756: requestsmail, updatesmail, or idconflictsmail).
14757:
1.619 raeburn 14758: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14759:
1.619 raeburn 14760: origmail (scalar - email address of recipient from loncapa.conf,
1.1297 raeburn 14761: i.e., predates configuration by DC via domainprefs.pm
14762:
14763: $requname username of requester (if mailing type is helpdeskmail)
14764:
14765: $requdom domain of requester (if mailing type is helpdeskmail)
14766:
14767: $reqemail e-mail address of requester (if mailing type is helpdeskmail)
14768:
1.618 raeburn 14769:
1.655 raeburn 14770: Returns: comma separated list of addresses to which to send e-mail.
14771:
14772: =back
1.618 raeburn 14773:
14774: =cut
14775:
14776: ############################################################
14777: ############################################################
14778: sub build_recipient_list {
1.1297 raeburn 14779: my ($defmail,$mailing,$defdom,$origmail,$requname,$requdom,$reqemail) = @_;
1.618 raeburn 14780: my @recipients;
1.1270 raeburn 14781: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14782: my %domconfig =
1.1270 raeburn 14783: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14784: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14785: if (exists($domconfig{'contacts'}{$mailing})) {
14786: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14787: my @contacts = ('adminemail','supportemail');
14788: foreach my $item (@contacts) {
14789: if ($domconfig{'contacts'}{$mailing}{$item}) {
14790: my $addr = $domconfig{'contacts'}{$item};
14791: if (!grep(/^\Q$addr\E$/,@recipients)) {
14792: push(@recipients,$addr);
14793: }
1.619 raeburn 14794: }
1.1270 raeburn 14795: }
14796: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14797: if ($mailing eq 'helpdeskmail') {
14798: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14799: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14800: my @ok_bccs;
14801: foreach my $bcc (@bccs) {
14802: $bcc =~ s/^\s+//g;
14803: $bcc =~ s/\s+$//g;
14804: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14805: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14806: push(@ok_bccs,$bcc);
14807: }
14808: }
14809: }
14810: if (@ok_bccs > 0) {
14811: $allbcc = join(', ',@ok_bccs);
14812: }
14813: }
14814: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14815: }
14816: }
1.766 raeburn 14817: } elsif ($origmail ne '') {
1.1270 raeburn 14818: $lastresort = $origmail;
1.618 raeburn 14819: }
1.1297 raeburn 14820: if ($mailing eq 'helpdeskmail') {
14821: if ((ref($domconfig{'contacts'}{'overrides'}) eq 'HASH') &&
14822: (keys(%{$domconfig{'contacts'}{'overrides'}}))) {
14823: my ($inststatus,$inststatus_checked);
14824: if (($env{'user.name'} ne '') && ($env{'user.domain'} ne '') &&
14825: ($env{'user.domain'} ne 'public')) {
14826: $inststatus_checked = 1;
14827: $inststatus = $env{'environment.inststatus'};
14828: }
14829: unless ($inststatus_checked) {
14830: if (($requname ne '') && ($requdom ne '')) {
14831: if (($requname =~ /^$match_username$/) &&
14832: ($requdom =~ /^$match_domain$/) &&
14833: (&Apache::lonnet::domain($requdom))) {
14834: my $requhome = &Apache::lonnet::homeserver($requname,
14835: $requdom);
14836: unless ($requhome eq 'no_host') {
14837: my %userenv = &Apache::lonnet::userenvironment($requdom,$requname,'inststatus');
14838: $inststatus = $userenv{'inststatus'};
14839: $inststatus_checked = 1;
14840: }
14841: }
14842: }
14843: }
14844: unless ($inststatus_checked) {
14845: if ($reqemail =~ /^[^\@]+\@[^\@]+$/) {
14846: my %srch = (srchby => 'email',
14847: srchdomain => $defdom,
14848: srchterm => $reqemail,
14849: srchtype => 'exact');
14850: my %srch_results = &Apache::lonnet::usersearch(\%srch);
14851: foreach my $uname (keys(%srch_results)) {
14852: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14853: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14854: $inststatus_checked = 1;
14855: last;
14856: }
14857: }
14858: unless ($inststatus_checked) {
14859: my ($dirsrchres,%srch_results) = &Apache::lonnet::inst_directory_query(\%srch);
14860: if ($dirsrchres eq 'ok') {
14861: foreach my $uname (keys(%srch_results)) {
14862: if (ref($srch_results{$uname}{'inststatus'}) eq 'ARRAY') {
14863: $inststatus = join(',',@{$srch_results{$uname}{'inststatus'}});
14864: $inststatus_checked = 1;
14865: last;
14866: }
14867: }
14868: }
14869: }
14870: }
14871: }
14872: if ($inststatus ne '') {
14873: foreach my $status (split(/\:/,$inststatus)) {
14874: if (ref($domconfig{'contacts'}{'overrides'}{$status}) eq 'HASH') {
14875: my @contacts = ('adminemail','supportemail');
14876: foreach my $item (@contacts) {
14877: if ($domconfig{'contacts'}{'overrides'}{$status}{$item}) {
14878: my $addr = $domconfig{'contacts'}{'overrides'}{$status};
14879: if (!grep(/^\Q$addr\E$/,@recipients)) {
14880: push(@recipients,$addr);
14881: }
14882: }
14883: }
14884: $otheremails = $domconfig{'contacts'}{'overrides'}{$status}{'others'};
14885: if ($domconfig{'contacts'}{'overrides'}{$status}{'bcc'}) {
14886: my @bccs = split(/,/,$domconfig{'contacts'}{'overrides'}{$status}{'bcc'});
14887: my @ok_bccs;
14888: foreach my $bcc (@bccs) {
14889: $bcc =~ s/^\s+//g;
14890: $bcc =~ s/\s+$//g;
14891: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14892: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14893: push(@ok_bccs,$bcc);
14894: }
14895: }
14896: }
14897: if (@ok_bccs > 0) {
14898: $allbcc = join(', ',@ok_bccs);
14899: }
14900: }
14901: $addtext = $domconfig{'contacts'}{'overrides'}{$status}{'include'};
14902: last;
14903: }
14904: }
14905: }
14906: }
14907: }
1.619 raeburn 14908: } elsif ($origmail ne '') {
1.1270 raeburn 14909: $lastresort = $origmail;
14910: }
1.1297 raeburn 14911: if (($mailing eq 'helpdeskmail') && ($lastresort ne '')) {
1.1270 raeburn 14912: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14913: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14914: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14915: my %what = (
14916: perlvar => 1,
14917: );
14918: my $primary = &Apache::lonnet::domain($defdom,'primary');
14919: if ($primary) {
14920: my $gotaddr;
14921: my ($result,$returnhash) =
14922: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14923: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14924: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14925: $lastresort = $returnhash->{'lonSupportEMail'};
14926: $gotaddr = 1;
14927: }
14928: }
14929: unless ($gotaddr) {
14930: my $uintdom = &Apache::lonnet::internet_dom($primary);
14931: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14932: unless ($uintdom eq $intdom) {
14933: my %domconfig =
14934: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14935: if (ref($domconfig{'contacts'}) eq 'HASH') {
14936: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14937: my @contacts = ('adminemail','supportemail');
14938: foreach my $item (@contacts) {
14939: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14940: my $addr = $domconfig{'contacts'}{$item};
14941: if (!grep(/^\Q$addr\E$/,@recipients)) {
14942: push(@recipients,$addr);
14943: }
14944: }
14945: }
14946: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14947: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14948: }
14949: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14950: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14951: my @ok_bccs;
14952: foreach my $bcc (@bccs) {
14953: $bcc =~ s/^\s+//g;
14954: $bcc =~ s/\s+$//g;
14955: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14956: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14957: push(@ok_bccs,$bcc);
14958: }
14959: }
14960: }
14961: if (@ok_bccs > 0) {
14962: $allbcc = join(', ',@ok_bccs);
14963: }
14964: }
14965: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14966: }
14967: }
14968: }
14969: }
14970: }
14971: }
1.618 raeburn 14972: }
1.688 raeburn 14973: if (defined($defmail)) {
14974: if ($defmail ne '') {
14975: push(@recipients,$defmail);
14976: }
1.618 raeburn 14977: }
14978: if ($otheremails) {
1.619 raeburn 14979: my @others;
14980: if ($otheremails =~ /,/) {
14981: @others = split(/,/,$otheremails);
1.618 raeburn 14982: } else {
1.619 raeburn 14983: push(@others,$otheremails);
14984: }
14985: foreach my $addr (@others) {
14986: if (!grep(/^\Q$addr\E$/,@recipients)) {
14987: push(@recipients,$addr);
14988: }
1.618 raeburn 14989: }
14990: }
1.1298 raeburn 14991: if ($mailing eq 'helpdeskmail') {
1.1270 raeburn 14992: if ((!@recipients) && ($lastresort ne '')) {
14993: push(@recipients,$lastresort);
14994: }
14995: } elsif ($lastresort ne '') {
14996: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14997: push(@recipients,$lastresort);
14998: }
14999: }
1.1271 raeburn 15000: my $recipientlist = join(',',@recipients);
1.1270 raeburn 15001: if (wantarray) {
15002: return ($recipientlist,$allbcc,$addtext);
15003: } else {
15004: return $recipientlist;
15005: }
1.618 raeburn 15006: }
15007:
1.127 matthew 15008: ############################################################
15009: ############################################################
1.154 albertel 15010:
1.655 raeburn 15011: =pod
15012:
1.1224 musolffc 15013: =over 4
15014:
1.1223 musolffc 15015: =item * &mime_email()
15016:
15017: Sends an email with a possible attachment
15018:
15019: Inputs:
15020:
15021: =over 4
15022:
15023: from - Sender's email address
15024:
15025: to - Email address of recipient
15026:
15027: subject - Subject of email
15028:
15029: body - Body of email
15030:
15031: cc_string - Carbon copy email address
15032:
15033: bcc - Blind carbon copy email address
15034:
15035: type - File type of attachment
15036:
15037: attachment_path - Path of file to be attached
15038:
15039: file_name - Name of file to be attached
15040:
15041: attachment_text - The body of an attachment of type "TEXT"
15042:
15043: =back
15044:
15045: =back
15046:
15047: =cut
15048:
15049: ############################################################
15050: ############################################################
15051:
15052: sub mime_email {
15053: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
15054: $file_name, $attachment_text) = @_;
15055: my $msg = MIME::Lite->new(
15056: From => $from,
15057: To => $to,
15058: Subject => $subject,
15059: Type =>'TEXT',
15060: Data => $body,
15061: );
15062: if ($cc_string ne '') {
15063: $msg->add("Cc" => $cc_string);
15064: }
15065: if ($bcc ne '') {
15066: $msg->add("Bcc" => $bcc);
15067: }
15068: $msg->attr("content-type" => "text/plain");
15069: $msg->attr("content-type.charset" => "UTF-8");
15070: # Attach file if given
15071: if ($attachment_path) {
15072: unless ($file_name) {
15073: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
15074: }
15075: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
15076: $msg->attach(Type => $type,
15077: Path => $attachment_path,
15078: Filename => $file_name
15079: );
15080: # Otherwise attach text if given
15081: } elsif ($attachment_text) {
15082: $msg->attach(Type => 'TEXT',
15083: Data => $attachment_text);
15084: }
15085: # Send it
15086: $msg->send('sendmail');
15087: }
15088:
15089: ############################################################
15090: ############################################################
15091:
15092: =pod
15093:
1.655 raeburn 15094: =head1 Course Catalog Routines
15095:
15096: =over 4
15097:
15098: =item * &gather_categories()
15099:
15100: Converts category definitions - keys of categories hash stored in
15101: coursecategories in configuration.db on the primary library server in a
15102: domain - to an array. Also generates javascript and idx hash used to
15103: generate Domain Coordinator interface for editing Course Categories.
15104:
15105: Inputs:
1.663 raeburn 15106:
1.655 raeburn 15107: categories (reference to hash of category definitions).
1.663 raeburn 15108:
1.655 raeburn 15109: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15110: categories and subcategories).
1.663 raeburn 15111:
1.655 raeburn 15112: idx (reference to hash of counters used in Domain Coordinator interface for
15113: editing Course Categories).
1.663 raeburn 15114:
1.655 raeburn 15115: jsarray (reference to array of categories used to create Javascript arrays for
15116: Domain Coordinator interface for editing Course Categories).
15117:
15118: Returns: nothing
15119:
15120: Side effects: populates cats, idx and jsarray.
15121:
15122: =cut
15123:
15124: sub gather_categories {
15125: my ($categories,$cats,$idx,$jsarray) = @_;
15126: my %counters;
15127: my $num = 0;
15128: foreach my $item (keys(%{$categories})) {
15129: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
15130: if ($container eq '' && $depth == 0) {
15131: $cats->[$depth][$categories->{$item}] = $cat;
15132: } else {
15133: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
15134: }
15135: my ($escitem,$tail) = split(/:/,$item,2);
15136: if ($counters{$tail} eq '') {
15137: $counters{$tail} = $num;
15138: $num ++;
15139: }
15140: if (ref($idx) eq 'HASH') {
15141: $idx->{$item} = $counters{$tail};
15142: }
15143: if (ref($jsarray) eq 'ARRAY') {
15144: push(@{$jsarray->[$counters{$tail}]},$item);
15145: }
15146: }
15147: return;
15148: }
15149:
15150: =pod
15151:
15152: =item * &extract_categories()
15153:
15154: Used to generate breadcrumb trails for course categories.
15155:
15156: Inputs:
1.663 raeburn 15157:
1.655 raeburn 15158: categories (reference to hash of category definitions).
1.663 raeburn 15159:
1.655 raeburn 15160: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15161: categories and subcategories).
1.663 raeburn 15162:
1.655 raeburn 15163: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 15164:
1.655 raeburn 15165: allitems (reference to hash - key is category key
15166: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15167:
1.655 raeburn 15168: idx (reference to hash of counters used in Domain Coordinator interface for
15169: editing Course Categories).
1.663 raeburn 15170:
1.655 raeburn 15171: jsarray (reference to array of categories used to create Javascript arrays for
15172: Domain Coordinator interface for editing Course Categories).
15173:
1.665 raeburn 15174: subcats (reference to hash of arrays containing all subcategories within each
15175: category, -recursive)
15176:
1.655 raeburn 15177: Returns: nothing
15178:
15179: Side effects: populates trails and allitems hash references.
15180:
15181: =cut
15182:
15183: sub extract_categories {
1.665 raeburn 15184: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 15185: if (ref($categories) eq 'HASH') {
15186: &gather_categories($categories,$cats,$idx,$jsarray);
15187: if (ref($cats->[0]) eq 'ARRAY') {
15188: for (my $i=0; $i<@{$cats->[0]}; $i++) {
15189: my $name = $cats->[0][$i];
15190: my $item = &escape($name).'::0';
15191: my $trailstr;
15192: if ($name eq 'instcode') {
15193: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 15194: } elsif ($name eq 'communities') {
15195: $trailstr = &mt('Communities');
1.1239 raeburn 15196: } elsif ($name eq 'placement') {
15197: $trailstr = &mt('Placement Tests');
1.655 raeburn 15198: } else {
15199: $trailstr = $name;
15200: }
15201: if ($allitems->{$item} eq '') {
15202: push(@{$trails},$trailstr);
15203: $allitems->{$item} = scalar(@{$trails})-1;
15204: }
15205: my @parents = ($name);
15206: if (ref($cats->[1]{$name}) eq 'ARRAY') {
15207: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
15208: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 15209: if (ref($subcats) eq 'HASH') {
15210: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
15211: }
15212: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
15213: }
15214: } else {
15215: if (ref($subcats) eq 'HASH') {
15216: $subcats->{$item} = [];
1.655 raeburn 15217: }
15218: }
15219: }
15220: }
15221: }
15222: return;
15223: }
15224:
15225: =pod
15226:
1.1162 raeburn 15227: =item * &recurse_categories()
1.655 raeburn 15228:
15229: Recursively used to generate breadcrumb trails for course categories.
15230:
15231: Inputs:
1.663 raeburn 15232:
1.655 raeburn 15233: cats (reference to array of arrays/hashes which encapsulates hierarchy of
15234: categories and subcategories).
1.663 raeburn 15235:
1.655 raeburn 15236: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 15237:
15238: category (current course category, for which breadcrumb trail is being generated).
15239:
15240: trails (reference to array of breadcrumb trails for each category).
15241:
1.655 raeburn 15242: allitems (reference to hash - key is category key
15243: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 15244:
1.655 raeburn 15245: parents (array containing containers directories for current category,
15246: back to top level).
15247:
15248: Returns: nothing
15249:
15250: Side effects: populates trails and allitems hash references
15251:
15252: =cut
15253:
15254: sub recurse_categories {
1.665 raeburn 15255: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 15256: my $shallower = $depth - 1;
15257: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
15258: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
15259: my $name = $cats->[$depth]{$category}[$k];
15260: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
15261: my $trailstr = join(' -> ',(@{$parents},$category));
15262: if ($allitems->{$item} eq '') {
15263: push(@{$trails},$trailstr);
15264: $allitems->{$item} = scalar(@{$trails})-1;
15265: }
15266: my $deeper = $depth+1;
15267: push(@{$parents},$category);
1.665 raeburn 15268: if (ref($subcats) eq 'HASH') {
15269: my $subcat = &escape($name).':'.$category.':'.$depth;
15270: for (my $j=@{$parents}; $j>=0; $j--) {
15271: my $higher;
15272: if ($j > 0) {
15273: $higher = &escape($parents->[$j]).':'.
15274: &escape($parents->[$j-1]).':'.$j;
15275: } else {
15276: $higher = &escape($parents->[$j]).'::'.$j;
15277: }
15278: push(@{$subcats->{$higher}},$subcat);
15279: }
15280: }
15281: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
15282: $subcats);
1.655 raeburn 15283: pop(@{$parents});
15284: }
15285: } else {
15286: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
15287: my $trailstr = join(' -> ',(@{$parents},$category));
15288: if ($allitems->{$item} eq '') {
15289: push(@{$trails},$trailstr);
15290: $allitems->{$item} = scalar(@{$trails})-1;
15291: }
15292: }
15293: return;
15294: }
15295:
1.663 raeburn 15296: =pod
15297:
1.1162 raeburn 15298: =item * &assign_categories_table()
1.663 raeburn 15299:
15300: Create a datatable for display of hierarchical categories in a domain,
15301: with checkboxes to allow a course to be categorized.
15302:
15303: Inputs:
15304:
15305: cathash - reference to hash of categories defined for the domain (from
15306: configuration.db)
15307:
15308: currcat - scalar with an & separated list of categories assigned to a course.
15309:
1.919 raeburn 15310: type - scalar contains course type (Course or Community).
15311:
1.1260 raeburn 15312: disabled - scalar (optional) contains disabled="disabled" if input elements are
15313: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15314:
1.663 raeburn 15315: Returns: $output (markup to be displayed)
15316:
15317: =cut
15318:
15319: sub assign_categories_table {
1.1259 raeburn 15320: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15321: my $output;
15322: if (ref($cathash) eq 'HASH') {
15323: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
15324: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
15325: $maxdepth = scalar(@cats);
15326: if (@cats > 0) {
15327: my $itemcount = 0;
15328: if (ref($cats[0]) eq 'ARRAY') {
15329: my @currcategories;
15330: if ($currcat ne '') {
15331: @currcategories = split('&',$currcat);
15332: }
1.919 raeburn 15333: my $table;
1.663 raeburn 15334: for (my $i=0; $i<@{$cats[0]}; $i++) {
15335: my $parent = $cats[0][$i];
1.919 raeburn 15336: next if ($parent eq 'instcode');
15337: if ($type eq 'Community') {
15338: next unless ($parent eq 'communities');
1.1239 raeburn 15339: } elsif ($type eq 'Placement') {
15340: next unless ($parent eq 'placement');
1.919 raeburn 15341: } else {
1.1239 raeburn 15342: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15343: }
1.663 raeburn 15344: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15345: my $item = &escape($parent).'::0';
15346: my $checked = '';
15347: if (@currcategories > 0) {
15348: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15349: $checked = ' checked="checked"';
1.663 raeburn 15350: }
15351: }
1.919 raeburn 15352: my $parent_title = $parent;
15353: if ($parent eq 'communities') {
15354: $parent_title = &mt('Communities');
1.1239 raeburn 15355: } elsif ($parent eq 'placement') {
15356: $parent_title = &mt('Placement Tests');
1.919 raeburn 15357: }
15358: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15359: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15360: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15361: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15362: my $depth = 1;
15363: push(@path,$parent);
1.1259 raeburn 15364: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15365: pop(@path);
1.919 raeburn 15366: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15367: $itemcount ++;
15368: }
1.919 raeburn 15369: if ($itemcount) {
15370: $output = &Apache::loncommon::start_data_table().
15371: $table.
15372: &Apache::loncommon::end_data_table();
15373: }
1.663 raeburn 15374: }
15375: }
15376: }
15377: return $output;
15378: }
15379:
15380: =pod
15381:
1.1162 raeburn 15382: =item * &assign_category_rows()
1.663 raeburn 15383:
15384: Create a datatable row for display of nested categories in a domain,
15385: with checkboxes to allow a course to be categorized,called recursively.
15386:
15387: Inputs:
15388:
15389: itemcount - track row number for alternating colors
15390:
15391: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15392: categories and subcategories.
15393:
15394: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15395:
15396: parent - parent of current category item
15397:
15398: path - Array containing all categories back up through the hierarchy from the
15399: current category to the top level.
15400:
15401: currcategories - reference to array of current categories assigned to the course
15402:
1.1260 raeburn 15403: disabled - scalar (optional) contains disabled="disabled" if input elements are
15404: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15405:
1.663 raeburn 15406: Returns: $output (markup to be displayed).
15407:
15408: =cut
15409:
15410: sub assign_category_rows {
1.1259 raeburn 15411: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15412: my ($text,$name,$item,$chgstr);
15413: if (ref($cats) eq 'ARRAY') {
15414: my $maxdepth = scalar(@{$cats});
15415: if (ref($cats->[$depth]) eq 'HASH') {
15416: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15417: my $numchildren = @{$cats->[$depth]{$parent}};
15418: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 15419: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15420: for (my $j=0; $j<$numchildren; $j++) {
15421: $name = $cats->[$depth]{$parent}[$j];
15422: $item = &escape($name).':'.&escape($parent).':'.$depth;
15423: my $deeper = $depth+1;
15424: my $checked = '';
15425: if (ref($currcategories) eq 'ARRAY') {
15426: if (@{$currcategories} > 0) {
15427: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15428: $checked = ' checked="checked"';
1.663 raeburn 15429: }
15430: }
15431: }
1.664 raeburn 15432: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15433: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15434: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15435: '<input type="hidden" name="catname" value="'.$name.'" />'.
15436: '</td><td>';
1.663 raeburn 15437: if (ref($path) eq 'ARRAY') {
15438: push(@{$path},$name);
1.1259 raeburn 15439: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15440: pop(@{$path});
15441: }
15442: $text .= '</td></tr>';
15443: }
15444: $text .= '</table></td>';
15445: }
15446: }
15447: }
15448: return $text;
15449: }
15450:
1.1181 raeburn 15451: =pod
15452:
15453: =back
15454:
15455: =cut
15456:
1.655 raeburn 15457: ############################################################
15458: ############################################################
15459:
15460:
1.443 albertel 15461: sub commit_customrole {
1.664 raeburn 15462: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15463: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15464: ($start?', '.&mt('starting').' '.localtime($start):'').
15465: ($end?', ending '.localtime($end):'').': <b>'.
15466: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15467: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15468: '</b><br />';
15469: return $output;
15470: }
15471:
15472: sub commit_standardrole {
1.1116 raeburn 15473: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15474: my ($output,$logmsg,$linefeed);
15475: if ($context eq 'auto') {
15476: $linefeed = "\n";
15477: } else {
15478: $linefeed = "<br />\n";
15479: }
1.443 albertel 15480: if ($three eq 'st') {
1.541 raeburn 15481: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 15482: $one,$two,$sec,$context,$credits);
1.541 raeburn 15483: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15484: ($result eq 'unknown_course') || ($result eq 'refused')) {
15485: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15486: } else {
1.541 raeburn 15487: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15488: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15489: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15490: if ($context eq 'auto') {
15491: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15492: } else {
15493: $output .= '<b>'.$result.'</b>'.$linefeed.
15494: &mt('Add to classlist').': <b>ok</b>';
15495: }
15496: $output .= $linefeed;
1.443 albertel 15497: }
15498: } else {
15499: $output = &mt('Assigning').' '.$three.' in '.$url.
15500: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15501: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15502: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15503: if ($context eq 'auto') {
15504: $output .= $result.$linefeed;
15505: } else {
15506: $output .= '<b>'.$result.'</b>'.$linefeed;
15507: }
1.443 albertel 15508: }
15509: return $output;
15510: }
15511:
15512: sub commit_studentrole {
1.1116 raeburn 15513: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15514: $credits) = @_;
1.626 raeburn 15515: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15516: if ($context eq 'auto') {
15517: $linefeed = "\n";
15518: } else {
15519: $linefeed = '<br />'."\n";
15520: }
1.443 albertel 15521: if (defined($one) && defined($two)) {
15522: my $cid=$one.'_'.$two;
15523: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15524: my $secchange = 0;
15525: my $expire_role_result;
15526: my $modify_section_result;
1.628 raeburn 15527: if ($oldsec ne '-1') {
15528: if ($oldsec ne $sec) {
1.443 albertel 15529: $secchange = 1;
1.628 raeburn 15530: my $now = time;
1.443 albertel 15531: my $uurl='/'.$cid;
15532: $uurl=~s/\_/\//g;
15533: if ($oldsec) {
15534: $uurl.='/'.$oldsec;
15535: }
1.626 raeburn 15536: $oldsecurl = $uurl;
1.628 raeburn 15537: $expire_role_result =
1.652 raeburn 15538: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15539: if ($env{'request.course.sec'} ne '') {
15540: if ($expire_role_result eq 'refused') {
15541: my @roles = ('st');
15542: my @statuses = ('previous');
15543: my @roledoms = ($one);
15544: my $withsec = 1;
15545: my %roleshash =
15546: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15547: \@statuses,\@roles,\@roledoms,$withsec);
15548: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15549: my ($oldstart,$oldend) =
15550: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15551: if ($oldend > 0 && $oldend <= $now) {
15552: $expire_role_result = 'ok';
15553: }
15554: }
15555: }
15556: }
1.443 albertel 15557: $result = $expire_role_result;
15558: }
15559: }
15560: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15561: $modify_section_result =
15562: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15563: undef,undef,undef,$sec,
15564: $end,$start,'','',$cid,
15565: '',$context,$credits);
1.443 albertel 15566: if ($modify_section_result =~ /^ok/) {
15567: if ($secchange == 1) {
1.628 raeburn 15568: if ($sec eq '') {
15569: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15570: } else {
15571: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15572: }
1.443 albertel 15573: } elsif ($oldsec eq '-1') {
1.628 raeburn 15574: if ($sec eq '') {
15575: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15576: } else {
15577: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15578: }
1.443 albertel 15579: } else {
1.628 raeburn 15580: if ($sec eq '') {
15581: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15582: } else {
15583: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15584: }
1.443 albertel 15585: }
15586: } else {
1.1115 raeburn 15587: if ($secchange) {
1.628 raeburn 15588: $$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;
15589: } else {
15590: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15591: }
1.443 albertel 15592: }
15593: $result = $modify_section_result;
15594: } elsif ($secchange == 1) {
1.628 raeburn 15595: if ($oldsec eq '') {
1.1103 raeburn 15596: $$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 15597: } else {
15598: $$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;
15599: }
1.626 raeburn 15600: if ($expire_role_result eq 'refused') {
15601: my $newsecurl = '/'.$cid;
15602: $newsecurl =~ s/\_/\//g;
15603: if ($sec ne '') {
15604: $newsecurl.='/'.$sec;
15605: }
15606: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15607: if ($sec eq '') {
15608: $$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;
15609: } else {
15610: $$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;
15611: }
15612: }
15613: }
1.443 albertel 15614: }
15615: } else {
1.626 raeburn 15616: $$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 15617: $result = "error: incomplete course id\n";
15618: }
15619: return $result;
15620: }
15621:
1.1108 raeburn 15622: sub show_role_extent {
15623: my ($scope,$context,$role) = @_;
15624: $scope =~ s{^/}{};
15625: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15626: push(@courseroles,'co');
15627: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15628: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15629: $scope =~ s{/}{_};
15630: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15631: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15632: my ($audom,$auname) = split(/\//,$scope);
15633: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15634: &Apache::loncommon::plainname($auname,$audom).'</span>');
15635: } else {
15636: $scope =~ s{/$}{};
15637: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15638: &Apache::lonnet::domain($scope,'description').'</span>');
15639: }
15640: }
15641:
1.443 albertel 15642: ############################################################
15643: ############################################################
15644:
1.566 albertel 15645: sub check_clone {
1.578 raeburn 15646: my ($args,$linefeed) = @_;
1.566 albertel 15647: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15648: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15649: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15650: my $clonemsg;
15651: my $can_clone = 0;
1.944 raeburn 15652: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15653: if ($lctype ne 'community') {
15654: $lctype = 'course';
15655: }
1.566 albertel 15656: if ($clonehome eq 'no_host') {
1.944 raeburn 15657: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15658: $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'});
15659: } else {
15660: $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'});
15661: }
1.566 albertel 15662: } else {
15663: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15664: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15665: if ($clonedesc{'type'} ne 'Community') {
1.1262 raeburn 15666: $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 15667: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15668: }
15669: }
1.1262 raeburn 15670: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15671: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15672: $can_clone = 1;
15673: } else {
1.1221 raeburn 15674: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15675: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 15676: if ($clonehash{'cloners'} eq '') {
15677: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15678: if ($domdefs{'canclone'}) {
15679: unless ($domdefs{'canclone'} eq 'none') {
15680: if ($domdefs{'canclone'} eq 'domain') {
15681: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15682: $can_clone = 1;
15683: }
15684: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15685: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15686: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15687: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15688: $can_clone = 1;
15689: }
15690: }
15691: }
15692: }
1.578 raeburn 15693: } else {
1.1221 raeburn 15694: my @cloners = split(/,/,$clonehash{'cloners'});
15695: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15696: $can_clone = 1;
1.1221 raeburn 15697: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15698: $can_clone = 1;
1.1225 raeburn 15699: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15700: $can_clone = 1;
1.1221 raeburn 15701: }
15702: unless ($can_clone) {
1.1225 raeburn 15703: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15704: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 15705: my (%gotdomdefaults,%gotcodedefaults);
15706: foreach my $cloner (@cloners) {
15707: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15708: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15709: my (%codedefaults,@code_order);
15710: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15711: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15712: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15713: }
15714: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15715: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15716: }
15717: } else {
15718: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15719: \%codedefaults,
15720: \@code_order);
15721: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15722: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15723: }
15724: if (@code_order > 0) {
15725: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15726: $cloner,$clonehash{'internal.coursecode'},
15727: $args->{'crscode'})) {
15728: $can_clone = 1;
15729: last;
15730: }
15731: }
15732: }
15733: }
15734: }
1.1225 raeburn 15735: }
15736: }
15737: unless ($can_clone) {
15738: my $ccrole = 'cc';
15739: if ($args->{'crstype'} eq 'Community') {
15740: $ccrole = 'co';
15741: }
15742: my %roleshash =
15743: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15744: $args->{'ccdomain'},
15745: 'userroles',['active'],[$ccrole],
15746: [$args->{'clonedomain'}]);
15747: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15748: $can_clone = 1;
15749: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15750: $args->{'ccuname'},$args->{'ccdomain'})) {
15751: $can_clone = 1;
1.1221 raeburn 15752: }
15753: }
15754: unless ($can_clone) {
15755: if ($args->{'crstype'} eq 'Community') {
15756: $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 15757: } else {
1.1221 raeburn 15758: $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'});
15759: }
1.566 albertel 15760: }
1.578 raeburn 15761: }
1.566 albertel 15762: }
15763: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15764: }
15765:
1.444 albertel 15766: sub construct_course {
1.1262 raeburn 15767: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15768: $cnum,$category,$coderef) = @_;
1.444 albertel 15769: my $outcome;
1.541 raeburn 15770: my $linefeed = '<br />'."\n";
15771: if ($context eq 'auto') {
15772: $linefeed = "\n";
15773: }
1.566 albertel 15774:
15775: #
15776: # Are we cloning?
15777: #
15778: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15779: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15780: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15781: if ($context ne 'auto') {
1.578 raeburn 15782: if ($clonemsg ne '') {
15783: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15784: }
1.566 albertel 15785: }
15786: $outcome .= $clonemsg.$linefeed;
15787:
15788: if (!$can_clone) {
15789: return (0,$outcome);
15790: }
15791: }
15792:
1.444 albertel 15793: #
15794: # Open course
15795: #
1.1239 raeburn 15796: my $showncrstype;
15797: if ($args->{'crstype'} eq 'Placement') {
15798: $showncrstype = 'placement test';
15799: } else {
15800: $showncrstype = lc($args->{'crstype'});
15801: }
1.444 albertel 15802: my %cenv=();
15803: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15804: $args->{'cdescr'},
15805: $args->{'curl'},
15806: $args->{'course_home'},
15807: $args->{'nonstandard'},
15808: $args->{'crscode'},
15809: $args->{'ccuname'}.':'.
15810: $args->{'ccdomain'},
1.882 raeburn 15811: $args->{'crstype'},
1.885 raeburn 15812: $cnum,$context,$category);
1.444 albertel 15813:
15814: # Note: The testing routines depend on this being output; see
15815: # Utils::Course. This needs to at least be output as a comment
15816: # if anyone ever decides to not show this, and Utils::Course::new
15817: # will need to be suitably modified.
1.1239 raeburn 15818: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
1.943 raeburn 15819: if ($$courseid =~ /^error:/) {
15820: return (0,$outcome);
15821: }
15822:
1.444 albertel 15823: #
15824: # Check if created correctly
15825: #
1.479 albertel 15826: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15827: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15828: if ($crsuhome eq 'no_host') {
15829: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15830: return (0,$outcome);
15831: }
1.541 raeburn 15832: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15833:
1.444 albertel 15834: #
1.566 albertel 15835: # Do the cloning
15836: #
15837: if ($can_clone && $cloneid) {
1.1239 raeburn 15838: $clonemsg = &mt('Cloning [_1] from [_2]',$showncrstype,$clonehome);
1.566 albertel 15839: if ($context ne 'auto') {
15840: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15841: }
15842: $outcome .= $clonemsg.$linefeed;
15843: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15844: # Copy all files
1.637 www 15845: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15846: # Restore URL
1.566 albertel 15847: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15848: # Restore title
1.566 albertel 15849: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15850: # Restore creation date, creator and creation context.
15851: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15852: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15853: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15854: # Mark as cloned
1.566 albertel 15855: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15856: # Need to clone grading mode
15857: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15858: $cenv{'grading'}=$newenv{'grading'};
15859: # Do not clone these environment entries
15860: &Apache::lonnet::del('environment',
15861: ['default_enrollment_start_date',
15862: 'default_enrollment_end_date',
15863: 'question.email',
15864: 'policy.email',
15865: 'comment.email',
15866: 'pch.users.denied',
1.725 raeburn 15867: 'plc.users.denied',
15868: 'hidefromcat',
1.1121 raeburn 15869: 'checkforpriv',
1.1166 raeburn 15870: 'categories',
15871: 'internal.uniquecode'],
1.638 www 15872: $$crsudom,$$crsunum);
1.1170 raeburn 15873: if ($args->{'textbook'}) {
15874: $cenv{'internal.textbook'} = $args->{'textbook'};
15875: }
1.444 albertel 15876: }
1.566 albertel 15877:
1.444 albertel 15878: #
15879: # Set environment (will override cloned, if existing)
15880: #
15881: my @sections = ();
15882: my @xlists = ();
15883: if ($args->{'crstype'}) {
15884: $cenv{'type'}=$args->{'crstype'};
15885: }
15886: if ($args->{'crsid'}) {
15887: $cenv{'courseid'}=$args->{'crsid'};
15888: }
15889: if ($args->{'crscode'}) {
15890: $cenv{'internal.coursecode'}=$args->{'crscode'};
15891: }
15892: if ($args->{'crsquota'} ne '') {
15893: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15894: } else {
15895: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15896: }
15897: if ($args->{'ccuname'}) {
15898: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15899: ':'.$args->{'ccdomain'};
15900: } else {
15901: $cenv{'internal.courseowner'} = $args->{'curruser'};
15902: }
1.1116 raeburn 15903: if ($args->{'defaultcredits'}) {
15904: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15905: }
1.444 albertel 15906: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15907: if ($args->{'crssections'}) {
15908: $cenv{'internal.sectionnums'} = '';
15909: if ($args->{'crssections'} =~ m/,/) {
15910: @sections = split/,/,$args->{'crssections'};
15911: } else {
15912: $sections[0] = $args->{'crssections'};
15913: }
15914: if (@sections > 0) {
15915: foreach my $item (@sections) {
15916: my ($sec,$gp) = split/:/,$item;
15917: my $class = $args->{'crscode'}.$sec;
15918: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15919: $cenv{'internal.sectionnums'} .= $item.',';
15920: unless ($addcheck eq 'ok') {
1.1263 raeburn 15921: push(@badclasses,$class);
1.444 albertel 15922: }
15923: }
15924: $cenv{'internal.sectionnums'} =~ s/,$//;
15925: }
15926: }
15927: # do not hide course coordinator from staff listing,
15928: # even if privileged
15929: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 15930: # add course coordinator's domain to domains to check for privileged users
15931: # if different to course domain
15932: if ($$crsudom ne $args->{'ccdomain'}) {
15933: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15934: }
1.444 albertel 15935: # add crosslistings
15936: if ($args->{'crsxlist'}) {
15937: $cenv{'internal.crosslistings'}='';
15938: if ($args->{'crsxlist'} =~ m/,/) {
15939: @xlists = split/,/,$args->{'crsxlist'};
15940: } else {
15941: $xlists[0] = $args->{'crsxlist'};
15942: }
15943: if (@xlists > 0) {
15944: foreach my $item (@xlists) {
15945: my ($xl,$gp) = split/:/,$item;
15946: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15947: $cenv{'internal.crosslistings'} .= $item.',';
15948: unless ($addcheck eq 'ok') {
1.1263 raeburn 15949: push(@badclasses,$xl);
1.444 albertel 15950: }
15951: }
15952: $cenv{'internal.crosslistings'} =~ s/,$//;
15953: }
15954: }
15955: if ($args->{'autoadds'}) {
15956: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15957: }
15958: if ($args->{'autodrops'}) {
15959: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15960: }
15961: # check for notification of enrollment changes
15962: my @notified = ();
15963: if ($args->{'notify_owner'}) {
15964: if ($args->{'ccuname'} ne '') {
15965: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15966: }
15967: }
15968: if ($args->{'notify_dc'}) {
15969: if ($uname ne '') {
1.630 raeburn 15970: push(@notified,$uname.':'.$udom);
1.444 albertel 15971: }
15972: }
15973: if (@notified > 0) {
15974: my $notifylist;
15975: if (@notified > 1) {
15976: $notifylist = join(',',@notified);
15977: } else {
15978: $notifylist = $notified[0];
15979: }
15980: $cenv{'internal.notifylist'} = $notifylist;
15981: }
15982: if (@badclasses > 0) {
15983: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 15984: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15985: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15986: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15987: );
1.1264 raeburn 15988: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15989: &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 15990: if ($context eq 'auto') {
15991: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 15992: } else {
1.566 albertel 15993: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 15994: }
15995: foreach my $item (@badclasses) {
1.541 raeburn 15996: if ($context eq 'auto') {
1.1261 raeburn 15997: $outcome .= " - $item\n";
1.541 raeburn 15998: } else {
1.1261 raeburn 15999: $outcome .= "<li>$item</li>\n";
1.541 raeburn 16000: }
1.1261 raeburn 16001: }
16002: if ($context eq 'auto') {
16003: $outcome .= $linefeed;
16004: } else {
16005: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 16006: }
1.444 albertel 16007: }
16008: if ($args->{'no_end_date'}) {
16009: $args->{'endaccess'} = 0;
16010: }
16011: $cenv{'internal.autostart'}=$args->{'enrollstart'};
16012: $cenv{'internal.autoend'}=$args->{'enrollend'};
16013: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
16014: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
16015: if ($args->{'showphotos'}) {
16016: $cenv{'internal.showphotos'}=$args->{'showphotos'};
16017: }
16018: $cenv{'internal.authtype'} = $args->{'authtype'};
16019: $cenv{'internal.autharg'} = $args->{'autharg'};
16020: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
16021: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 16022: 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');
16023: if ($context eq 'auto') {
16024: $outcome .= $krb_msg;
16025: } else {
1.566 albertel 16026: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 16027: }
16028: $outcome .= $linefeed;
1.444 albertel 16029: }
16030: }
16031: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
16032: if ($args->{'setpolicy'}) {
16033: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16034: }
16035: if ($args->{'setcontent'}) {
16036: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16037: }
1.1251 raeburn 16038: if ($args->{'setcomment'}) {
16039: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
16040: }
1.444 albertel 16041: }
16042: if ($args->{'reshome'}) {
16043: $cenv{'reshome'}=$args->{'reshome'}.'/';
16044: $cenv{'reshome'}=~s/\/+$/\//;
16045: }
16046: #
16047: # course has keyed access
16048: #
16049: if ($args->{'setkeys'}) {
16050: $cenv{'keyaccess'}='yes';
16051: }
16052: # if specified, key authority is not course, but user
16053: # only active if keyaccess is yes
16054: if ($args->{'keyauth'}) {
1.487 albertel 16055: my ($user,$domain) = split(':',$args->{'keyauth'});
16056: $user = &LONCAPA::clean_username($user);
16057: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 16058: if ($user ne '' && $domain ne '') {
1.487 albertel 16059: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 16060: }
16061: }
16062:
1.1166 raeburn 16063: #
1.1167 raeburn 16064: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 16065: #
16066: if ($args->{'uniquecode'}) {
16067: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
16068: if ($code) {
16069: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 16070: my %crsinfo =
16071: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
16072: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
16073: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
16074: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
16075: }
1.1166 raeburn 16076: if (ref($coderef)) {
16077: $$coderef = $code;
16078: }
16079: }
16080: }
16081:
1.444 albertel 16082: if ($args->{'disresdis'}) {
16083: $cenv{'pch.roles.denied'}='st';
16084: }
16085: if ($args->{'disablechat'}) {
16086: $cenv{'plc.roles.denied'}='st';
16087: }
16088:
16089: # Record we've not yet viewed the Course Initialization Helper for this
16090: # course
16091: $cenv{'course.helper.not.run'} = 1;
16092: #
16093: # Use new Randomseed
16094: #
16095: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
16096: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
16097: #
16098: # The encryption code and receipt prefix for this course
16099: #
16100: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
16101: $cenv{'internal.encpref'}=100+int(9*rand(99));
16102: #
16103: # By default, use standard grading
16104: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
16105:
1.541 raeburn 16106: $outcome .= $linefeed.&mt('Setting environment').': '.
16107: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16108: #
16109: # Open all assignments
16110: #
16111: if ($args->{'openall'}) {
16112: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
16113: my %storecontent = ($storeunder => time,
16114: $storeunder.'.type' => 'date_start');
16115:
16116: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 16117: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 16118: }
16119: #
16120: # Set first page
16121: #
16122: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
16123: || ($cloneid)) {
1.445 albertel 16124: use LONCAPA::map;
1.444 albertel 16125: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 16126:
16127: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
16128: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
16129:
1.444 albertel 16130: $outcome .= ($fatal?$errtext:'read ok').' - ';
16131: my $title; my $url;
16132: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 16133: $title=&mt('Syllabus');
1.444 albertel 16134: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
16135: } else {
1.963 raeburn 16136: $title=&mt('Table of Contents');
1.444 albertel 16137: $url='/adm/navmaps';
16138: }
1.445 albertel 16139:
16140: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
16141: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
16142:
16143: if ($errtext) { $fatal=2; }
1.541 raeburn 16144: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 16145: }
1.566 albertel 16146:
1.1237 raeburn 16147: #
16148: # Set params for Placement Tests
16149: #
1.1239 raeburn 16150: if ($args->{'crstype'} eq 'Placement') {
16151: my %storecontent;
16152: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
16153: my %defaults = (
16154: buttonshide => { value => 'yes',
16155: type => 'string_yesno',},
16156: type => { value => 'randomizetry',
16157: type => 'string_questiontype',},
16158: maxtries => { value => 1,
16159: type => 'int_pos',},
16160: problemstatus => { value => 'no',
16161: type => 'string_problemstatus',},
16162: );
16163: foreach my $key (keys(%defaults)) {
16164: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
16165: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
16166: }
1.1237 raeburn 16167: &Apache::lonnet::cput
16168: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
16169: }
16170:
1.566 albertel 16171: return (1,$outcome);
1.444 albertel 16172: }
16173:
1.1166 raeburn 16174: sub make_unique_code {
16175: my ($cdom,$cnum) = @_;
16176: # get lock on uniquecodes db
16177: my $lockhash = {
16178: $cnum."\0".'uniquecodes' => $env{'user.name'}.
16179: ':'.$env{'user.domain'},
16180: };
16181: my $tries = 0;
16182: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16183: my ($code,$error);
16184:
16185: while (($gotlock ne 'ok') && ($tries<3)) {
16186: $tries ++;
16187: sleep 1;
16188: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
16189: }
16190: if ($gotlock eq 'ok') {
16191: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
16192: my $gotcode;
16193: my $attempts = 0;
16194: while ((!$gotcode) && ($attempts < 100)) {
16195: $code = &generate_code();
16196: if (!exists($currcodes{$code})) {
16197: $gotcode = 1;
16198: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
16199: $error = 'nostore';
16200: }
16201: }
16202: $attempts ++;
16203: }
16204: my @del_lock = ($cnum."\0".'uniquecodes');
16205: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
16206: } else {
16207: $error = 'nolock';
16208: }
16209: return ($code,$error);
16210: }
16211:
16212: sub generate_code {
16213: my $code;
16214: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
16215: for (my $i=0; $i<6; $i++) {
16216: my $lettnum = int (rand 2);
16217: my $item = '';
16218: if ($lettnum) {
16219: $item = $letts[int( rand(18) )];
16220: } else {
16221: $item = 1+int( rand(8) );
16222: }
16223: $code .= $item;
16224: }
16225: return $code;
16226: }
16227:
1.444 albertel 16228: ############################################################
16229: ############################################################
16230:
1.1237 raeburn 16231: # Community, Course and Placement Test
1.378 raeburn 16232: sub course_type {
16233: my ($cid) = @_;
16234: if (!defined($cid)) {
16235: $cid = $env{'request.course.id'};
16236: }
1.404 albertel 16237: if (defined($env{'course.'.$cid.'.type'})) {
16238: return $env{'course.'.$cid.'.type'};
1.378 raeburn 16239: } else {
16240: return 'Course';
1.377 raeburn 16241: }
16242: }
1.156 albertel 16243:
1.406 raeburn 16244: sub group_term {
16245: my $crstype = &course_type();
16246: my %names = (
16247: 'Course' => 'group',
1.865 raeburn 16248: 'Community' => 'group',
1.1237 raeburn 16249: 'Placement' => 'group',
1.406 raeburn 16250: );
16251: return $names{$crstype};
16252: }
16253:
1.902 raeburn 16254: sub course_types {
1.1310 raeburn 16255: my @types = ('official','unofficial','community','textbook','placement','lti');
1.902 raeburn 16256: my %typename = (
16257: official => 'Official course',
16258: unofficial => 'Unofficial course',
16259: community => 'Community',
1.1165 raeburn 16260: textbook => 'Textbook course',
1.1237 raeburn 16261: placement => 'Placement test',
1.1310 raeburn 16262: lti => 'LTI provider',
1.902 raeburn 16263: );
16264: return (\@types,\%typename);
16265: }
16266:
1.156 albertel 16267: sub icon {
16268: my ($file)=@_;
1.505 albertel 16269: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 16270: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 16271: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 16272: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
16273: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
16274: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16275: $curfext.".gif") {
16276: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
16277: $curfext.".gif";
16278: }
16279: }
1.249 albertel 16280: return &lonhttpdurl($iconname);
1.154 albertel 16281: }
1.84 albertel 16282:
1.575 albertel 16283: sub lonhttpdurl {
1.692 www 16284: #
16285: # Had been used for "small fry" static images on separate port 8080.
16286: # Modify here if lightweight http functionality desired again.
16287: # Currently eliminated due to increasing firewall issues.
16288: #
1.575 albertel 16289: my ($url)=@_;
1.692 www 16290: return $url;
1.215 albertel 16291: }
16292:
1.213 albertel 16293: sub connection_aborted {
16294: my ($r)=@_;
16295: $r->print(" ");$r->rflush();
16296: my $c = $r->connection;
16297: return $c->aborted();
16298: }
16299:
1.221 foxr 16300: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 16301: # strings as 'strings'.
16302: sub escape_single {
1.221 foxr 16303: my ($input) = @_;
1.223 albertel 16304: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 16305: $input =~ s/\'/\\\'/g; # Esacpe the 's....
16306: return $input;
16307: }
1.223 albertel 16308:
1.222 foxr 16309: # Same as escape_single, but escape's "'s This
16310: # can be used for "strings"
16311: sub escape_double {
16312: my ($input) = @_;
16313: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
16314: $input =~ s/\"/\\\"/g; # Esacpe the "s....
16315: return $input;
16316: }
1.223 albertel 16317:
1.222 foxr 16318: # Escapes the last element of a full URL.
16319: sub escape_url {
16320: my ($url) = @_;
1.238 raeburn 16321: my @urlslices = split(/\//, $url,-1);
1.369 www 16322: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 16323: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16324: }
1.462 albertel 16325:
1.820 raeburn 16326: sub compare_arrays {
16327: my ($arrayref1,$arrayref2) = @_;
16328: my (@difference,%count);
16329: @difference = ();
16330: %count = ();
16331: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16332: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16333: foreach my $element (keys(%count)) {
16334: if ($count{$element} == 1) {
16335: push(@difference,$element);
16336: }
16337: }
16338: }
16339: return @difference;
16340: }
16341:
1.817 bisitz 16342: # -------------------------------------------------------- Initialize user login
1.462 albertel 16343: sub init_user_environment {
1.463 albertel 16344: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16345: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16346:
16347: my $public=($username eq 'public' && $domain eq 'public');
16348:
1.1062 raeburn 16349: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16350: my $now=time;
16351:
16352: if ($public) {
16353: my $max_public=100;
16354: my $oldest;
16355: my $oldest_time=0;
16356: for(my $next=1;$next<=$max_public;$next++) {
16357: if (-e $lonids."/publicuser_$next.id") {
16358: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16359: if ($mtime<$oldest_time || !$oldest_time) {
16360: $oldest_time=$mtime;
16361: $oldest=$next;
16362: }
16363: } else {
16364: $cookie="publicuser_$next";
16365: last;
16366: }
16367: }
16368: if (!$cookie) { $cookie="publicuser_$oldest"; }
16369: } else {
1.1275 raeburn 16370: # See if old ID present, if so, remove if this isn't a robot,
16371: # killing any existing non-robot sessions
1.463 albertel 16372: if (!$args->{'robot'}) {
16373: opendir(DIR,$lonids);
16374: while ($filename=readdir(DIR)) {
16375: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
1.1295 raeburn 16376: if ($ENV{'SERVER_PORT'} == 443) {
16377: my $linkedfile;
16378: if (tie(my %oldenv,'GDBM_File',"$lonids/$cookie.id",
16379: &GDBM_READER(),0640)) {
16380: if (exists($oldenv{'user.linkedenv'})) {
16381: $linkedfile = $oldenv{'user.linkedenv'};
16382: }
16383: untie(%oldenv);
16384: }
16385: if (unlink($lonids.'/'.$filename)) {
16386: if ($linkedfile =~ /^[a-f0-9]+_linked\.id$/) {
16387: unlink($lonids.'/'.$linkedfile);
16388: }
16389: }
16390: } else {
16391: unlink($lonids.'/'.$filename);
16392: }
1.463 albertel 16393: }
1.462 albertel 16394: }
1.463 albertel 16395: closedir(DIR);
1.1204 raeburn 16396: # If there is a undeleted lockfile for the user's paste buffer remove it.
16397: my $namespace = 'nohist_courseeditor';
16398: my $lockingkey = 'paste'."\0".'locked_num';
16399: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16400: $domain,$username);
16401: if (exists($lockhash{$lockingkey})) {
16402: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16403: unless ($delresult eq 'ok') {
16404: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16405: }
16406: }
1.462 albertel 16407: }
16408: # Give them a new cookie
1.463 albertel 16409: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16410: : $now.$$.int(rand(10000)));
1.463 albertel 16411: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16412:
16413: # Initialize roles
16414:
1.1062 raeburn 16415: ($userroles,$firstaccenv,$timerintenv) =
16416: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16417: }
16418: # ------------------------------------ Check browser type and MathML capability
16419:
1.1194 raeburn 16420: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16421: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16422:
16423: # ------------------------------------------------------------- Get environment
16424:
16425: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16426: my ($tmp) = keys(%userenv);
1.1275 raeburn 16427: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 16428: undef(%userenv);
16429: }
16430: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16431: $form->{'interface'}=$userenv{'interface'};
16432: }
16433: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16434:
16435: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16436: foreach my $option ('interface','localpath','localres') {
16437: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16438: }
16439: # --------------------------------------------------------- Write first profile
16440:
16441: {
16442: my %initial_env =
16443: ("user.name" => $username,
16444: "user.domain" => $domain,
16445: "user.home" => $authhost,
16446: "browser.type" => $clientbrowser,
16447: "browser.version" => $clientversion,
16448: "browser.mathml" => $clientmathml,
16449: "browser.unicode" => $clientunicode,
16450: "browser.os" => $clientos,
1.1137 raeburn 16451: "browser.mobile" => $clientmobile,
1.1141 raeburn 16452: "browser.info" => $clientinfo,
1.1194 raeburn 16453: "browser.osversion" => $clientosversion,
1.462 albertel 16454: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16455: "request.course.fn" => '',
16456: "request.course.uri" => '',
16457: "request.course.sec" => '',
16458: "request.role" => 'cm',
16459: "request.role.adv" => $env{'user.adv'},
16460: "request.host" => $ENV{'REMOTE_ADDR'},);
16461:
16462: if ($form->{'localpath'}) {
16463: $initial_env{"browser.localpath"} = $form->{'localpath'};
16464: $initial_env{"browser.localres"} = $form->{'localres'};
16465: }
16466:
16467: if ($form->{'interface'}) {
16468: $form->{'interface'}=~s/\W//gs;
16469: $initial_env{"browser.interface"} = $form->{'interface'};
16470: $env{'browser.interface'}=$form->{'interface'};
16471: }
16472:
1.1157 raeburn 16473: if ($form->{'iptoken'}) {
16474: my $lonhost = $r->dir_config('lonHostID');
16475: $initial_env{"user.noloadbalance"} = $lonhost;
16476: $env{'user.noloadbalance'} = $lonhost;
16477: }
16478:
1.1268 raeburn 16479: if ($form->{'noloadbalance'}) {
16480: my @hosts = &Apache::lonnet::current_machine_ids();
16481: my $hosthere = $form->{'noloadbalance'};
16482: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16483: $initial_env{"user.noloadbalance"} = $hosthere;
16484: $env{'user.noloadbalance'} = $hosthere;
16485: }
16486: }
16487:
1.1016 raeburn 16488: unless ($domain eq 'public') {
1.1273 raeburn 16489: my %is_adv = ( is_adv => $env{'user.adv'} );
16490: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
16491:
16492: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16493: $userenv{'availabletools.'.$tool} =
16494: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16495: undef,\%userenv,\%domdef,\%is_adv);
16496: }
1.980 raeburn 16497:
1.1311 raeburn 16498: foreach my $crstype ('official','unofficial','community','textbook','placement','lti') {
1.1273 raeburn 16499: $userenv{'canrequest.'.$crstype} =
16500: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16501: 'reload','requestcourses',
16502: \%userenv,\%domdef,\%is_adv);
16503: }
1.724 raeburn 16504:
1.1273 raeburn 16505: $userenv{'canrequest.author'} =
16506: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16507: 'reload','requestauthor',
1.980 raeburn 16508: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 16509: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16510: $domain,$username);
16511: my $reqstatus = $reqauthor{'author_status'};
16512: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16513: if (ref($reqauthor{'author'}) eq 'HASH') {
16514: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16515: $reqauthor{'author'}{'timestamp'};
16516: }
1.1092 raeburn 16517: }
1.1287 raeburn 16518: my ($types,$typename) = &course_types();
16519: if (ref($types) eq 'ARRAY') {
16520: my @options = ('approval','validate','autolimit');
16521: my $optregex = join('|',@options);
16522: my (%willtrust,%trustchecked);
16523: foreach my $type (@{$types}) {
16524: my $dom_str = $env{'environment.reqcrsotherdom.'.$type};
16525: if ($dom_str ne '') {
16526: my $updatedstr = '';
16527: my @possdomains = split(',',$dom_str);
16528: foreach my $entry (@possdomains) {
16529: my ($extdom,$extopt) = split(':',$entry);
16530: unless ($trustchecked{$extdom}) {
16531: $willtrust{$extdom} = &Apache::lonnet::will_trust('reqcrs',$domain,$extdom);
16532: $trustchecked{$extdom} = 1;
16533: }
16534: if ($willtrust{$extdom}) {
16535: $updatedstr .= $entry.',';
16536: }
16537: }
16538: $updatedstr =~ s/,$//;
16539: if ($updatedstr) {
16540: $userenv{'reqcrsotherdom.'.$type} = $updatedstr;
16541: } else {
16542: delete($userenv{'reqcrsotherdom.'.$type});
16543: }
16544: }
16545: }
16546: }
1.1092 raeburn 16547: }
1.462 albertel 16548: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16549:
1.462 albertel 16550: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16551: &GDBM_WRCREAT(),0640)) {
16552: &_add_to_env(\%disk_env,\%initial_env);
16553: &_add_to_env(\%disk_env,\%userenv,'environment.');
16554: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16555: if (ref($firstaccenv) eq 'HASH') {
16556: &_add_to_env(\%disk_env,$firstaccenv);
16557: }
16558: if (ref($timerintenv) eq 'HASH') {
16559: &_add_to_env(\%disk_env,$timerintenv);
16560: }
1.463 albertel 16561: if (ref($args->{'extra_env'})) {
16562: &_add_to_env(\%disk_env,$args->{'extra_env'});
16563: }
1.462 albertel 16564: untie(%disk_env);
16565: } else {
1.705 tempelho 16566: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16567: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16568: return 'error: '.$!;
16569: }
16570: }
16571: $env{'request.role'}='cm';
16572: $env{'request.role.adv'}=$env{'user.adv'};
16573: $env{'browser.type'}=$clientbrowser;
16574:
16575: return $cookie;
16576:
16577: }
16578:
16579: sub _add_to_env {
16580: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16581: if (ref($env_data) eq 'HASH') {
16582: while (my ($key,$value) = each(%$env_data)) {
16583: $idf->{$prefix.$key} = $value;
16584: $env{$prefix.$key} = $value;
16585: }
1.462 albertel 16586: }
16587: }
16588:
1.685 tempelho 16589: # --- Get the symbolic name of a problem and the url
16590: sub get_symb {
16591: my ($request,$silent) = @_;
1.726 raeburn 16592: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16593: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16594: if ($symb eq '') {
16595: if (!$silent) {
1.1071 raeburn 16596: if (ref($request)) {
16597: $request->print("Unable to handle ambiguous references:$url:.");
16598: }
1.685 tempelho 16599: return ();
16600: }
16601: }
16602: &Apache::lonenc::check_decrypt(\$symb);
16603: return ($symb);
16604: }
16605:
16606: # --------------------------------------------------------------Get annotation
16607:
16608: sub get_annotation {
16609: my ($symb,$enc) = @_;
16610:
16611: my $key = $symb;
16612: if (!$enc) {
16613: $key =
16614: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16615: }
16616: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16617: return $annotation{$key};
16618: }
16619:
16620: sub clean_symb {
1.731 raeburn 16621: my ($symb,$delete_enc) = @_;
1.685 tempelho 16622:
16623: &Apache::lonenc::check_decrypt(\$symb);
16624: my $enc = $env{'request.enc'};
1.731 raeburn 16625: if ($delete_enc) {
1.730 raeburn 16626: delete($env{'request.enc'});
16627: }
1.685 tempelho 16628:
16629: return ($symb,$enc);
16630: }
1.462 albertel 16631:
1.1181 raeburn 16632: ############################################################
16633: ############################################################
16634:
16635: =pod
16636:
16637: =head1 Routines for building display used to search for courses
16638:
16639:
16640: =over 4
16641:
16642: =item * &build_filters()
16643:
16644: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 16645: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16646: and quotacheck.pl
16647:
1.1181 raeburn 16648:
16649: Inputs:
16650:
16651: filterlist - anonymous array of fields to include as potential filters
16652:
16653: crstype - course type
16654:
16655: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16656: to pop-open a course selector (will contain "extra element").
16657:
16658: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16659:
16660: filter - anonymous hash of criteria and their values
16661:
16662: action - form action
16663:
16664: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16665:
1.1182 raeburn 16666: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 16667:
16668: cloneruname - username of owner of new course who wants to clone
16669:
16670: clonerudom - domain of owner of new course who wants to clone
16671:
16672: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16673:
16674: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16675:
16676: codedom - domain
16677:
16678: formname - value of form element named "form".
16679:
16680: fixeddom - domain, if fixed.
16681:
16682: prevphase - value to assign to form element named "phase" when going back to the previous screen
16683:
16684: cnameelement - name of form element in form on opener page which will receive title of selected course
16685:
16686: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16687:
16688: cdomelement - name of form element in form on opener page which will receive domain of selected course
16689:
16690: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16691:
16692: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16693:
16694: clonewarning - warning message about missing information for intended course owner when DC creates a course
16695:
1.1182 raeburn 16696:
1.1181 raeburn 16697: Returns: $output - HTML for display of search criteria, and hidden form elements.
16698:
1.1182 raeburn 16699:
1.1181 raeburn 16700: Side Effects: None
16701:
16702: =cut
16703:
16704: # ---------------------------------------------- search for courses based on last activity etc.
16705:
16706: sub build_filters {
16707: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16708: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16709: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16710: $cnameelement,$cnumelement,$cdomelement,$setroles,
16711: $clonetext,$clonewarning) = @_;
1.1182 raeburn 16712: my ($list,$jscript);
1.1181 raeburn 16713: my $onchange = 'javascript:updateFilters(this)';
16714: my ($domainselectform,$sincefilterform,$createdfilterform,
16715: $ownerdomselectform,$persondomselectform,$instcodeform,
16716: $typeselectform,$instcodetitle);
16717: if ($formname eq '') {
16718: $formname = $caller;
16719: }
16720: foreach my $item (@{$filterlist}) {
16721: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16722: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16723: if ($item eq 'domainfilter') {
16724: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16725: } elsif ($item eq 'coursefilter') {
16726: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16727: } elsif ($item eq 'ownerfilter') {
16728: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16729: } elsif ($item eq 'ownerdomfilter') {
16730: $filter->{'ownerdomfilter'} =
16731: &LONCAPA::clean_domain($filter->{$item});
16732: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16733: 'ownerdomfilter',1);
16734: } elsif ($item eq 'personfilter') {
16735: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16736: } elsif ($item eq 'persondomfilter') {
16737: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16738: 'persondomfilter',1);
16739: } else {
16740: $filter->{$item} =~ s/\W//g;
16741: }
16742: if (!$filter->{$item}) {
16743: $filter->{$item} = '';
16744: }
16745: }
16746: if ($item eq 'domainfilter') {
16747: my $allow_blank = 1;
16748: if ($formname eq 'portform') {
16749: $allow_blank=0;
16750: } elsif ($formname eq 'studentform') {
16751: $allow_blank=0;
16752: }
16753: if ($fixeddom) {
16754: $domainselectform = '<input type="hidden" name="domainfilter"'.
16755: ' value="'.$codedom.'" />'.
16756: &Apache::lonnet::domain($codedom,'description');
16757: } else {
16758: $domainselectform = &select_dom_form($filter->{$item},
16759: 'domainfilter',
16760: $allow_blank,'',$onchange);
16761: }
16762: } else {
16763: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16764: }
16765: }
16766:
16767: # last course activity filter and selection
16768: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16769:
16770: # course created filter and selection
16771: if (exists($filter->{'createdfilter'})) {
16772: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16773: }
16774:
1.1239 raeburn 16775: my $prefix = $crstype;
16776: if ($crstype eq 'Placement') {
16777: $prefix = 'Placement Test'
16778: }
1.1181 raeburn 16779: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 16780: 'cac' => "$prefix Activity",
16781: 'ccr' => "$prefix Created",
16782: 'cde' => "$prefix Title",
16783: 'cdo' => "$prefix Domain",
1.1181 raeburn 16784: 'ins' => 'Institutional Code',
16785: 'inc' => 'Institutional Categorization',
1.1239 raeburn 16786: 'cow' => "$prefix Owner/Co-owner",
16787: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 16788: 'cog' => 'Type',
16789: );
16790:
16791: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16792: my $typeval = 'Course';
16793: if ($crstype eq 'Community') {
16794: $typeval = 'Community';
1.1239 raeburn 16795: } elsif ($crstype eq 'Placement') {
16796: $typeval = 'Placement';
1.1181 raeburn 16797: }
16798: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16799: } else {
16800: $typeselectform = '<select name="type" size="1"';
16801: if ($onchange) {
16802: $typeselectform .= ' onchange="'.$onchange.'"';
16803: }
16804: $typeselectform .= '>'."\n";
1.1237 raeburn 16805: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 16806: my $shown;
16807: if ($posstype eq 'Placement') {
16808: $shown = &mt('Placement Test');
16809: } else {
16810: $shown = &mt($posstype);
16811: }
1.1181 raeburn 16812: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 16813: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 16814: }
16815: $typeselectform.="</select>";
16816: }
16817:
16818: my ($cloneableonlyform,$cloneabletitle);
16819: if (exists($filter->{'cloneableonly'})) {
16820: my $cloneableon = '';
16821: my $cloneableoff = ' checked="checked"';
16822: if ($filter->{'cloneableonly'}) {
16823: $cloneableon = $cloneableoff;
16824: $cloneableoff = '';
16825: }
16826: $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>';
16827: if ($formname eq 'ccrs') {
1.1187 bisitz 16828: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 16829: } else {
16830: $cloneabletitle = &mt('Cloneable by you');
16831: }
16832: }
16833: my $officialjs;
16834: if ($crstype eq 'Course') {
16835: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 16836: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16837: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16838: if ($codedom) {
1.1181 raeburn 16839: $officialjs = 1;
16840: ($instcodeform,$jscript,$$numtitlesref) =
16841: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16842: $officialjs,$codetitlesref);
16843: if ($jscript) {
1.1182 raeburn 16844: $jscript = '<script type="text/javascript">'."\n".
16845: '// <![CDATA['."\n".
16846: $jscript."\n".
16847: '// ]]>'."\n".
16848: '</script>'."\n";
1.1181 raeburn 16849: }
16850: }
16851: if ($instcodeform eq '') {
16852: $instcodeform =
16853: '<input type="text" name="instcodefilter" size="10" value="'.
16854: $list->{'instcodefilter'}.'" />';
16855: $instcodetitle = $lt{'ins'};
16856: } else {
16857: $instcodetitle = $lt{'inc'};
16858: }
16859: if ($fixeddom) {
16860: $instcodetitle .= '<br />('.$codedom.')';
16861: }
16862: }
16863: }
16864: my $output = qq|
16865: <form method="post" name="filterpicker" action="$action">
16866: <input type="hidden" name="form" value="$formname" />
16867: |;
16868: if ($formname eq 'modifycourse') {
16869: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16870: '<input type="hidden" name="prevphase" value="'.
16871: $prevphase.'" />'."\n";
1.1198 musolffc 16872: } elsif ($formname eq 'quotacheck') {
16873: $output .= qq|
16874: <input type="hidden" name="sortby" value="" />
16875: <input type="hidden" name="sortorder" value="" />
16876: |;
16877: } else {
1.1181 raeburn 16878: my $name_input;
16879: if ($cnameelement ne '') {
16880: $name_input = '<input type="hidden" name="cnameelement" value="'.
16881: $cnameelement.'" />';
16882: }
16883: $output .= qq|
1.1182 raeburn 16884: <input type="hidden" name="cnumelement" value="$cnumelement" />
16885: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 16886: $name_input
16887: $roleelement
16888: $multelement
16889: $typeelement
16890: |;
16891: if ($formname eq 'portform') {
16892: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16893: }
16894: }
16895: if ($fixeddom) {
16896: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16897: }
16898: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16899: if ($sincefilterform) {
16900: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16901: .$sincefilterform
16902: .&Apache::lonhtmlcommon::row_closure();
16903: }
16904: if ($createdfilterform) {
16905: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16906: .$createdfilterform
16907: .&Apache::lonhtmlcommon::row_closure();
16908: }
16909: if ($domainselectform) {
16910: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16911: .$domainselectform
16912: .&Apache::lonhtmlcommon::row_closure();
16913: }
16914: if ($typeselectform) {
16915: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16916: $output .= $typeselectform;
16917: } else {
16918: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16919: .$typeselectform
16920: .&Apache::lonhtmlcommon::row_closure();
16921: }
16922: }
16923: if ($instcodeform) {
16924: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16925: .$instcodeform
16926: .&Apache::lonhtmlcommon::row_closure();
16927: }
16928: if (exists($filter->{'ownerfilter'})) {
16929: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16930: '<table><tr><td>'.&mt('Username').'<br />'.
16931: '<input type="text" name="ownerfilter" size="20" value="'.
16932: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16933: $ownerdomselectform.'</td></tr></table>'.
16934: &Apache::lonhtmlcommon::row_closure();
16935: }
16936: if (exists($filter->{'personfilter'})) {
16937: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16938: '<table><tr><td>'.&mt('Username').'<br />'.
16939: '<input type="text" name="personfilter" size="20" value="'.
16940: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16941: $persondomselectform.'</td></tr></table>'.
16942: &Apache::lonhtmlcommon::row_closure();
16943: }
16944: if (exists($filter->{'coursefilter'})) {
16945: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16946: .'<input type="text" name="coursefilter" size="25" value="'
16947: .$list->{'coursefilter'}.'" />'
16948: .&Apache::lonhtmlcommon::row_closure();
16949: }
16950: if ($cloneableonlyform) {
16951: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16952: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16953: }
16954: if (exists($filter->{'descriptfilter'})) {
16955: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16956: .'<input type="text" name="descriptfilter" size="40" value="'
16957: .$list->{'descriptfilter'}.'" />'
16958: .&Apache::lonhtmlcommon::row_closure(1);
16959: }
16960: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16961: '<input type="hidden" name="updater" value="" />'."\n".
16962: '<input type="submit" name="gosearch" value="'.
16963: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16964: return $jscript.$clonewarning.$output;
16965: }
16966:
16967: =pod
16968:
16969: =item * &timebased_select_form()
16970:
1.1182 raeburn 16971: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 16972: filter e.g., Course Activity, Course Created, when searching for courses
16973: or communities
16974:
16975: Inputs:
16976:
16977: item - name of form element (sincefilter or createdfilter)
16978:
16979: filter - anonymous hash of criteria and their values
16980:
16981: Returns: HTML for a select box contained a blank, then six time selections,
16982: with value set in incoming form variables currently selected.
16983:
16984: Side Effects: None
16985:
16986: =cut
16987:
16988: sub timebased_select_form {
16989: my ($item,$filter) = @_;
16990: if (ref($filter) eq 'HASH') {
16991: $filter->{$item} =~ s/[^\d-]//g;
16992: if (!$filter->{$item}) { $filter->{$item}=-1; }
16993: return &select_form(
16994: $filter->{$item},
16995: $item,
16996: { '-1' => '',
16997: '86400' => &mt('today'),
16998: '604800' => &mt('last week'),
16999: '2592000' => &mt('last month'),
17000: '7776000' => &mt('last three months'),
17001: '15552000' => &mt('last six months'),
17002: '31104000' => &mt('last year'),
17003: 'select_form_order' =>
17004: ['-1','86400','604800','2592000','7776000',
17005: '15552000','31104000']});
17006: }
17007: }
17008:
17009: =pod
17010:
17011: =item * &js_changer()
17012:
17013: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 17014: when course type or domain is changed, and also to hide 'Searching ...' on
17015: page load completion for page showing search result.
1.1181 raeburn 17016:
17017: Inputs: None
17018:
1.1183 raeburn 17019: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 17020:
17021: Side Effects: None
17022:
17023: =cut
17024:
17025: sub js_changer {
17026: return <<ENDJS;
17027: <script type="text/javascript">
17028: // <![CDATA[
17029: function updateFilters(caller) {
17030: if (typeof(caller) != "undefined") {
17031: document.filterpicker.updater.value = caller.name;
17032: }
17033: document.filterpicker.submit();
17034: }
1.1183 raeburn 17035:
17036: function hideSearching() {
17037: if (document.getElementById('searching')) {
17038: document.getElementById('searching').style.display = 'none';
17039: }
17040: return;
17041: }
17042:
1.1181 raeburn 17043: // ]]>
17044: </script>
17045:
17046: ENDJS
17047: }
17048:
17049: =pod
17050:
1.1182 raeburn 17051: =item * &search_courses()
17052:
17053: Process selected filters form course search form and pass to lonnet::courseiddump
17054: to retrieve a hash for which keys are courseIDs which match the selected filters.
17055:
17056: Inputs:
17057:
17058: dom - domain being searched
17059:
17060: type - course type ('Course' or 'Community' or '.' if any).
17061:
17062: filter - anonymous hash of criteria and their values
17063:
17064: numtitles - for institutional codes - number of categories
17065:
17066: cloneruname - optional username of new course owner
17067:
17068: clonerudom - optional domain of new course owner
17069:
1.1221 raeburn 17070: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 17071: (used when DC is using course creation form)
17072:
17073: codetitles - reference to array of titles of components in institutional codes (official courses).
17074:
1.1221 raeburn 17075: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
17076: (and so can clone automatically)
17077:
17078: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
17079:
17080: reqinstcode - institutional code of new course, where search_courses is used to identify potential
17081: courses to clone
1.1182 raeburn 17082:
17083: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
17084:
17085:
17086: Side Effects: None
17087:
17088: =cut
17089:
17090:
17091: sub search_courses {
1.1221 raeburn 17092: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
17093: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 17094: my (%courses,%showcourses,$cloner);
17095: if (($filter->{'ownerfilter'} ne '') ||
17096: ($filter->{'ownerdomfilter'} ne '')) {
17097: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
17098: $filter->{'ownerdomfilter'};
17099: }
17100: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
17101: if (!$filter->{$item}) {
17102: $filter->{$item}='.';
17103: }
17104: }
17105: my $now = time;
17106: my $timefilter =
17107: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
17108: my ($createdbefore,$createdafter);
17109: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
17110: $createdbefore = $now;
17111: $createdafter = $now-$filter->{'createdfilter'};
17112: }
17113: my ($instcodefilter,$regexpok);
17114: if ($numtitles) {
17115: if ($env{'form.official'} eq 'on') {
17116: $instcodefilter =
17117: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17118: $regexpok = 1;
17119: } elsif ($env{'form.official'} eq 'off') {
17120: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
17121: unless ($instcodefilter eq '') {
17122: $regexpok = -1;
17123: }
17124: }
17125: } else {
17126: $instcodefilter = $filter->{'instcodefilter'};
17127: }
17128: if ($instcodefilter eq '') { $instcodefilter = '.'; }
17129: if ($type eq '') { $type = '.'; }
17130:
17131: if (($clonerudom ne '') && ($cloneruname ne '')) {
17132: $cloner = $cloneruname.':'.$clonerudom;
17133: }
17134: %courses = &Apache::lonnet::courseiddump($dom,
17135: $filter->{'descriptfilter'},
17136: $timefilter,
17137: $instcodefilter,
17138: $filter->{'combownerfilter'},
17139: $filter->{'coursefilter'},
17140: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 17141: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 17142: $filter->{'cloneableonly'},
17143: $createdbefore,$createdafter,undef,
1.1221 raeburn 17144: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 17145: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
17146: my $ccrole;
17147: if ($type eq 'Community') {
17148: $ccrole = 'co';
17149: } else {
17150: $ccrole = 'cc';
17151: }
17152: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
17153: $filter->{'persondomfilter'},
17154: 'userroles',undef,
17155: [$ccrole,'in','ad','ep','ta','cr'],
17156: $dom);
17157: foreach my $role (keys(%rolehash)) {
17158: my ($cnum,$cdom,$courserole) = split(':',$role);
17159: my $cid = $cdom.'_'.$cnum;
17160: if (exists($courses{$cid})) {
17161: if (ref($courses{$cid}) eq 'HASH') {
17162: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
17163: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 17164: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 17165: }
17166: } else {
17167: $courses{$cid}{roles} = [$courserole];
17168: }
17169: $showcourses{$cid} = $courses{$cid};
17170: }
17171: }
17172: }
17173: %courses = %showcourses;
17174: }
17175: return %courses;
17176: }
17177:
17178: =pod
17179:
1.1181 raeburn 17180: =back
17181:
1.1207 raeburn 17182: =head1 Routines for version requirements for current course.
17183:
17184: =over 4
17185:
17186: =item * &check_release_required()
17187:
17188: Compares required LON-CAPA version with version on server, and
17189: if required version is newer looks for a server with the required version.
17190:
17191: Looks first at servers in user's owen domain; if none suitable, looks at
17192: servers in course's domain are permitted to host sessions for user's domain.
17193:
17194: Inputs:
17195:
17196: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17197:
17198: $courseid - Course ID of current course
17199:
17200: $rolecode - User's current role in course (for switchserver query string).
17201:
17202: $required - LON-CAPA version needed by course (format: Major.Minor).
17203:
17204:
17205: Returns:
17206:
17207: $switchserver - query string tp append to /adm/switchserver call (if
17208: current server's LON-CAPA version is too old.
17209:
17210: $warning - Message is displayed if no suitable server could be found.
17211:
17212: =cut
17213:
17214: sub check_release_required {
17215: my ($loncaparev,$courseid,$rolecode,$required) = @_;
17216: my ($switchserver,$warning);
17217: if ($required ne '') {
17218: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
17219: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17220: if ($reqdmajor ne '' && $reqdminor ne '') {
17221: my $otherserver;
17222: if (($major eq '' && $minor eq '') ||
17223: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
17224: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
17225: my $switchlcrev =
17226: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
17227: $userdomserver);
17228: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
17229: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
17230: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
17231: my $cdom = $env{'course.'.$courseid.'.domain'};
17232: if ($cdom ne $env{'user.domain'}) {
17233: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
17234: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
17235: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
17236: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
17237: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
17238: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
17239: my $canhost =
17240: &Apache::lonnet::can_host_session($env{'user.domain'},
17241: $coursedomserver,
17242: $remoterev,
17243: $udomdefaults{'remotesessions'},
17244: $defdomdefaults{'hostedsessions'});
17245:
17246: if ($canhost) {
17247: $otherserver = $coursedomserver;
17248: } else {
17249: $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.");
17250: }
17251: } else {
17252: $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).");
17253: }
17254: } else {
17255: $otherserver = $userdomserver;
17256: }
17257: }
17258: if ($otherserver ne '') {
17259: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
17260: }
17261: }
17262: }
17263: return ($switchserver,$warning);
17264: }
17265:
17266: =pod
17267:
17268: =item * &check_release_result()
17269:
17270: Inputs:
17271:
17272: $switchwarning - Warning message if no suitable server found to host session.
17273:
17274: $switchserver - query string to append to /adm/switchserver containing lonHostID
17275: and current role.
17276:
17277: Returns: HTML to display with information about requirement to switch server.
17278: Either displaying warning with link to Roles/Courses screen or
17279: display link to switchserver.
17280:
1.1181 raeburn 17281: =cut
17282:
1.1207 raeburn 17283: sub check_release_result {
17284: my ($switchwarning,$switchserver) = @_;
17285: my $output = &start_page('Selected course unavailable on this server').
17286: '<p class="LC_warning">';
17287: if ($switchwarning) {
17288: $output .= $switchwarning.'<br /><a href="/adm/roles">';
17289: if (&show_course()) {
17290: $output .= &mt('Display courses');
17291: } else {
17292: $output .= &mt('Display roles');
17293: }
17294: $output .= '</a>';
17295: } elsif ($switchserver) {
17296: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
17297: '<br />'.
17298: '<a href="/adm/switchserver?'.$switchserver.'">'.
17299: &mt('Switch Server').
17300: '</a>';
17301: }
17302: $output .= '</p>'.&end_page();
17303: return $output;
17304: }
17305:
17306: =pod
17307:
17308: =item * &needs_coursereinit()
17309:
17310: Determine if course contents stored for user's session needs to be
17311: refreshed, because content has changed since "Big Hash" last tied.
17312:
17313: Check for change is made if time last checked is more than 10 minutes ago
17314: (by default).
17315:
17316: Inputs:
17317:
17318: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
17319:
17320: $interval (optional) - Time which may elapse (in s) between last check for content
17321: change in current course. (default: 600 s).
17322:
17323: Returns: an array; first element is:
17324:
17325: =over 4
17326:
17327: 'switch' - if content updates mean user's session
17328: needs to be switched to a server running a newer LON-CAPA version
17329:
17330: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
17331: on current server hosting user's session
17332:
17333: '' - if no action required.
17334:
17335: =back
17336:
17337: If first item element is 'switch':
17338:
17339: second item is $switchwarning - Warning message if no suitable server found to host session.
17340:
17341: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
17342: and current role.
17343:
17344: otherwise: no other elements returned.
17345:
17346: =back
17347:
17348: =cut
17349:
17350: sub needs_coursereinit {
17351: my ($loncaparev,$interval) = @_;
17352: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
17353: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17354: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17355: my $now = time;
17356: if ($interval eq '') {
17357: $interval = 600;
17358: }
17359: if (($now-$env{'request.course.timechecked'})>$interval) {
1.1282 raeburn 17360: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
1.1283 raeburn 17361: my $blocked = &blocking_status('reinit',$cnum,$cdom,undef,1);
1.1282 raeburn 17362: if ($blocked) {
17363: return ();
17364: }
1.1207 raeburn 17365: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
17366: if ($lastchange > $env{'request.course.tied'}) {
17367: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17368: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17369: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17370: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17371: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17372: $curr_reqd_hash{'internal.releaserequired'}});
17373: my ($switchserver,$switchwarning) =
17374: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17375: $curr_reqd_hash{'internal.releaserequired'});
17376: if ($switchwarning ne '' || $switchserver ne '') {
17377: return ('switch',$switchwarning,$switchserver);
17378: }
17379: }
17380: }
17381: return ('update');
17382: }
17383: }
17384: return ();
17385: }
1.1181 raeburn 17386:
1.1083 raeburn 17387: sub update_content_constraints {
17388: my ($cdom,$cnum,$chome,$cid) = @_;
17389: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17390: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
1.1307 raeburn 17391: my (%checkresponsetypes,%checkcrsrestypes);
1.1083 raeburn 17392: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 17393: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 17394: if ($item eq 'resourcetag') {
17395: if ($name eq 'responsetype') {
17396: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17397: }
1.1307 raeburn 17398: } elsif ($item eq 'course') {
17399: if ($name eq 'courserestype') {
17400: $checkcrsrestypes{$value} = $Apache::lonnet::needsrelease{$key};
17401: }
1.1083 raeburn 17402: }
17403: }
17404: my $navmap = Apache::lonnavmaps::navmap->new();
17405: if (defined($navmap)) {
1.1307 raeburn 17406: my (%allresponses,%allcrsrestypes);
17407: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() || $_[0]->is_tool() },1,0)) {
17408: if ($res->is_tool()) {
17409: if ($allcrsrestypes{'exttool'}) {
17410: $allcrsrestypes{'exttool'} ++;
17411: } else {
17412: $allcrsrestypes{'exttool'} = 1;
17413: }
17414: next;
17415: }
1.1083 raeburn 17416: my %responses = $res->responseTypes();
17417: foreach my $key (keys(%responses)) {
17418: next unless(exists($checkresponsetypes{$key}));
17419: $allresponses{$key} += $responses{$key};
17420: }
17421: }
17422: foreach my $key (keys(%allresponses)) {
17423: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17424: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17425: ($reqdmajor,$reqdminor) = ($major,$minor);
17426: }
17427: }
1.1307 raeburn 17428: foreach my $key (keys(%allcrsrestypes)) {
1.1308 raeburn 17429: my ($major,$minor) = split(/\./,$checkcrsrestypes{$key});
1.1307 raeburn 17430: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17431: ($reqdmajor,$reqdminor) = ($major,$minor);
17432: }
17433: }
1.1083 raeburn 17434: undef($navmap);
17435: }
1.1308 raeburn 17436: my $suppmap = 'supplemental.sequence';
17437: my ($suppcount,$supptools,$errors) = (0,0,0);
17438: ($suppcount,$supptools,$errors) = &recurse_supplemental($cnum,$cdom,$suppmap,
17439: $suppcount,$supptools,$errors);
17440: if ($supptools) {
17441: my ($major,$minor) = split(/\./,$checkcrsrestypes{'exttool'});
17442: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17443: ($reqdmajor,$reqdminor) = ($major,$minor);
17444: }
17445: }
1.1083 raeburn 17446: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17447: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17448: }
17449: return;
17450: }
17451:
1.1110 raeburn 17452: sub allmaps_incourse {
17453: my ($cdom,$cnum,$chome,$cid) = @_;
17454: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17455: $cid = $env{'request.course.id'};
17456: $cdom = $env{'course.'.$cid.'.domain'};
17457: $cnum = $env{'course.'.$cid.'.num'};
17458: $chome = $env{'course.'.$cid.'.home'};
17459: }
17460: my %allmaps = ();
17461: my $lastchange =
17462: &Apache::lonnet::get_coursechange($cdom,$cnum);
17463: if ($lastchange > $env{'request.course.tied'}) {
17464: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17465: unless ($ferr) {
17466: &update_content_constraints($cdom,$cnum,$chome,$cid);
17467: }
17468: }
17469: my $navmap = Apache::lonnavmaps::navmap->new();
17470: if (defined($navmap)) {
17471: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17472: $allmaps{$res->src()} = 1;
17473: }
17474: }
17475: return \%allmaps;
17476: }
17477:
1.1083 raeburn 17478: sub parse_supplemental_title {
17479: my ($title) = @_;
17480:
17481: my ($foldertitle,$renametitle);
17482: if ($title =~ /&&&/) {
17483: $title = &HTML::Entites::decode($title);
17484: }
17485: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17486: $renametitle=$4;
17487: my ($time,$uname,$udom) = ($1,$2,$3);
17488: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17489: my $name = &plainname($uname,$udom);
17490: $name = &HTML::Entities::encode($name,'"<>&\'');
17491: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17492: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17493: $name.': <br />'.$foldertitle;
17494: }
17495: if (wantarray) {
17496: return ($title,$foldertitle,$renametitle);
17497: }
17498: return $title;
17499: }
17500:
1.1143 raeburn 17501: sub recurse_supplemental {
1.1308 raeburn 17502: my ($cnum,$cdom,$suppmap,$numfiles,$numexttools,$errors) = @_;
1.1143 raeburn 17503: if ($suppmap) {
17504: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17505: if ($fatal) {
17506: $errors ++;
17507: } else {
17508: if ($#LONCAPA::map::resources > 0) {
17509: foreach my $res (@LONCAPA::map::resources) {
17510: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17511: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 17512: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
1.1308 raeburn 17513: ($numfiles,$numexttools,$errors) = &recurse_supplemental($cnum,$cdom,$1,
17514: $numfiles,$numexttools,$errors);
1.1143 raeburn 17515: } else {
1.1308 raeburn 17516: if ($src =~ m{^/adm/$cdom/$cnum/\d+/ext\.tool$}) {
17517: $numexttools ++;
17518: }
1.1143 raeburn 17519: $numfiles ++;
17520: }
17521: }
17522: }
17523: }
17524: }
17525: }
1.1308 raeburn 17526: return ($numfiles,$numexttools,$errors);
1.1143 raeburn 17527: }
17528:
1.1101 raeburn 17529: sub symb_to_docspath {
1.1267 raeburn 17530: my ($symb,$navmapref) = @_;
17531: return unless ($symb && ref($navmapref));
1.1101 raeburn 17532: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17533: if ($resurl=~/\.(sequence|page)$/) {
17534: $mapurl=$resurl;
17535: } elsif ($resurl eq 'adm/navmaps') {
17536: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17537: }
17538: my $mapresobj;
1.1267 raeburn 17539: unless (ref($$navmapref)) {
17540: $$navmapref = Apache::lonnavmaps::navmap->new();
17541: }
17542: if (ref($$navmapref)) {
17543: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 17544: }
17545: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17546: my $type=$2;
17547: my $path;
17548: if (ref($mapresobj)) {
17549: my $pcslist = $mapresobj->map_hierarchy();
17550: if ($pcslist ne '') {
17551: foreach my $pc (split(/,/,$pcslist)) {
17552: next if ($pc <= 1);
1.1267 raeburn 17553: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 17554: if (ref($res)) {
17555: my $thisurl = $res->src();
17556: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17557: my $thistitle = $res->title();
17558: $path .= '&'.
17559: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 17560: &escape($thistitle).
1.1101 raeburn 17561: ':'.$res->randompick().
17562: ':'.$res->randomout().
17563: ':'.$res->encrypted().
17564: ':'.$res->randomorder().
17565: ':'.$res->is_page();
17566: }
17567: }
17568: }
17569: $path =~ s/^\&//;
17570: my $maptitle = $mapresobj->title();
17571: if ($mapurl eq 'default') {
1.1129 raeburn 17572: $maptitle = 'Main Content';
1.1101 raeburn 17573: }
17574: $path .= (($path ne '')? '&' : '').
17575: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17576: &escape($maptitle).
1.1101 raeburn 17577: ':'.$mapresobj->randompick().
17578: ':'.$mapresobj->randomout().
17579: ':'.$mapresobj->encrypted().
17580: ':'.$mapresobj->randomorder().
17581: ':'.$mapresobj->is_page();
17582: } else {
17583: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17584: my $ispage = (($type eq 'page')? 1 : '');
17585: if ($mapurl eq 'default') {
1.1129 raeburn 17586: $maptitle = 'Main Content';
1.1101 raeburn 17587: }
17588: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17589: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 17590: }
17591: unless ($mapurl eq 'default') {
17592: $path = 'default&'.
1.1146 raeburn 17593: &escape('Main Content').
1.1101 raeburn 17594: ':::::&'.$path;
17595: }
17596: return $path;
17597: }
17598:
1.1094 raeburn 17599: sub captcha_display {
17600: my ($context,$lonhost) = @_;
17601: my ($output,$error);
1.1234 raeburn 17602: my ($captcha,$pubkey,$privkey,$version) =
17603: &get_captcha_config($context,$lonhost);
1.1095 raeburn 17604: if ($captcha eq 'original') {
1.1094 raeburn 17605: $output = &create_captcha();
17606: unless ($output) {
1.1172 raeburn 17607: $error = 'captcha';
1.1094 raeburn 17608: }
17609: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17610: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 17611: unless ($output) {
1.1172 raeburn 17612: $error = 'recaptcha';
1.1094 raeburn 17613: }
17614: }
1.1234 raeburn 17615: return ($output,$error,$captcha,$version);
1.1094 raeburn 17616: }
17617:
17618: sub captcha_response {
17619: my ($context,$lonhost) = @_;
17620: my ($captcha_chk,$captcha_error);
1.1234 raeburn 17621: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 17622: if ($captcha eq 'original') {
1.1094 raeburn 17623: ($captcha_chk,$captcha_error) = &check_captcha();
17624: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17625: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 17626: } else {
17627: $captcha_chk = 1;
17628: }
17629: return ($captcha_chk,$captcha_error);
17630: }
17631:
17632: sub get_captcha_config {
17633: my ($context,$lonhost) = @_;
1.1234 raeburn 17634: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 17635: my $hostname = &Apache::lonnet::hostname($lonhost);
17636: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17637: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 17638: if ($context eq 'usercreation') {
17639: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17640: if (ref($domconfig{$context}) eq 'HASH') {
17641: $hashtocheck = $domconfig{$context}{'cancreate'};
17642: if (ref($hashtocheck) eq 'HASH') {
17643: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17644: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17645: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17646: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17647: }
17648: if ($privkey && $pubkey) {
17649: $captcha = 'recaptcha';
1.1234 raeburn 17650: $version = $hashtocheck->{'recaptchaversion'};
17651: if ($version ne '2') {
17652: $version = 1;
17653: }
1.1095 raeburn 17654: } else {
17655: $captcha = 'original';
17656: }
17657: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17658: $captcha = 'original';
17659: }
1.1094 raeburn 17660: }
1.1095 raeburn 17661: } else {
17662: $captcha = 'captcha';
17663: }
17664: } elsif ($context eq 'login') {
17665: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17666: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17667: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17668: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 17669: if ($privkey && $pubkey) {
17670: $captcha = 'recaptcha';
1.1234 raeburn 17671: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17672: if ($version ne '2') {
17673: $version = 1;
17674: }
1.1095 raeburn 17675: } else {
17676: $captcha = 'original';
1.1094 raeburn 17677: }
1.1095 raeburn 17678: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17679: $captcha = 'original';
1.1094 raeburn 17680: }
17681: }
1.1234 raeburn 17682: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 17683: }
17684:
17685: sub create_captcha {
17686: my %captcha_params = &captcha_settings();
17687: my ($output,$maxtries,$tries) = ('',10,0);
17688: while ($tries < $maxtries) {
17689: $tries ++;
17690: my $captcha = Authen::Captcha->new (
17691: output_folder => $captcha_params{'output_dir'},
17692: data_folder => $captcha_params{'db_dir'},
17693: );
17694: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17695:
17696: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17697: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17698: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 17699: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17700: '<br />'.
17701: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 17702: last;
17703: }
17704: }
17705: return $output;
17706: }
17707:
17708: sub captcha_settings {
17709: my %captcha_params = (
17710: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17711: www_output_dir => "/captchaspool",
17712: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17713: numchars => '5',
17714: );
17715: return %captcha_params;
17716: }
17717:
17718: sub check_captcha {
17719: my ($captcha_chk,$captcha_error);
17720: my $code = $env{'form.code'};
17721: my $md5sum = $env{'form.crypt'};
17722: my %captcha_params = &captcha_settings();
17723: my $captcha = Authen::Captcha->new(
17724: output_folder => $captcha_params{'output_dir'},
17725: data_folder => $captcha_params{'db_dir'},
17726: );
1.1109 raeburn 17727: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 17728: my %captcha_hash = (
17729: 0 => 'Code not checked (file error)',
17730: -1 => 'Failed: code expired',
17731: -2 => 'Failed: invalid code (not in database)',
17732: -3 => 'Failed: invalid code (code does not match crypt)',
17733: );
17734: if ($captcha_chk != 1) {
17735: $captcha_error = $captcha_hash{$captcha_chk}
17736: }
17737: return ($captcha_chk,$captcha_error);
17738: }
17739:
17740: sub create_recaptcha {
1.1234 raeburn 17741: my ($pubkey,$version) = @_;
17742: if ($version >= 2) {
17743: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17744: } else {
17745: my $use_ssl;
17746: if ($ENV{'SERVER_PORT'} == 443) {
17747: $use_ssl = 1;
17748: }
17749: my $captcha = Captcha::reCAPTCHA->new;
17750: return $captcha->get_options_setter({theme => 'white'})."\n".
17751: $captcha->get_html($pubkey,undef,$use_ssl).
17752: &mt('If the text is hard to read, [_1] will replace them.',
17753: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17754: '<br /><br />';
17755: }
1.1094 raeburn 17756: }
17757:
17758: sub check_recaptcha {
1.1234 raeburn 17759: my ($privkey,$version) = @_;
1.1094 raeburn 17760: my $captcha_chk;
1.1234 raeburn 17761: if ($version >= 2) {
17762: my %info = (
17763: secret => $privkey,
17764: response => $env{'form.g-recaptcha-response'},
17765: remoteip => $ENV{'REMOTE_ADDR'},
17766: );
1.1280 raeburn 17767: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
17768: $request->content(join('&',map {
17769: my $name = escape($_);
17770: "$name=" . ( ref($info{$_}) eq 'ARRAY'
17771: ? join("&$name=", map {escape($_) } @{$info{$_}})
17772: : &escape($info{$_}) );
17773: } keys(%info)));
17774: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 17775: if ($response->is_success) {
17776: my $data = JSON::DWIW->from_json($response->decoded_content);
17777: if (ref($data) eq 'HASH') {
17778: if ($data->{'success'}) {
17779: $captcha_chk = 1;
17780: }
17781: }
17782: }
17783: } else {
17784: my $captcha = Captcha::reCAPTCHA->new;
17785: my $captcha_result =
17786: $captcha->check_answer(
17787: $privkey,
17788: $ENV{'REMOTE_ADDR'},
17789: $env{'form.recaptcha_challenge_field'},
17790: $env{'form.recaptcha_response_field'},
17791: );
17792: if ($captcha_result->{is_valid}) {
17793: $captcha_chk = 1;
17794: }
1.1094 raeburn 17795: }
17796: return $captcha_chk;
17797: }
17798:
1.1174 raeburn 17799: sub emailusername_info {
1.1244 raeburn 17800: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 17801: my %titles = &Apache::lonlocal::texthash (
17802: lastname => 'Last Name',
17803: firstname => 'First Name',
17804: institution => 'School/college/university',
17805: location => "School's city, state/province, country",
17806: web => "School's web address",
17807: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 17808: id => 'Student/Employee ID',
1.1174 raeburn 17809: );
17810: return (\@fields,\%titles);
17811: }
17812:
1.1161 raeburn 17813: sub cleanup_html {
17814: my ($incoming) = @_;
17815: my $outgoing;
17816: if ($incoming ne '') {
17817: $outgoing = $incoming;
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: $outgoing =~ s/\)/)/g;
17825: $outgoing =~ s/"/"/g;
17826: $outgoing =~ s/'/'/g;
17827: $outgoing =~ s/\$/$/g;
17828: $outgoing =~ s{/}{/}g;
17829: $outgoing =~ s/=/=/g;
17830: $outgoing =~ s/\\/\/g
17831: }
17832: return $outgoing;
17833: }
17834:
1.1190 musolffc 17835: # Checks for critical messages and returns a redirect url if one exists.
17836: # $interval indicates how often to check for messages.
1.1282 raeburn 17837: # $context is the calling context -- roles, grades, contents, menu or flip.
1.1190 musolffc 17838: sub critical_redirect {
1.1282 raeburn 17839: my ($interval,$context) = @_;
1.1190 musolffc 17840: if ((time-$env{'user.criticalcheck.time'})>$interval) {
1.1282 raeburn 17841: if (($env{'request.course.id'}) && (($context eq 'flip') || ($context eq 'contents'))) {
17842: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
17843: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
17844: my $blocked = &blocking_status('alert',$cnum,$cdom,undef,1);
17845: if ($blocked) {
17846: my $checkrole = "cm./$cdom/$cnum";
17847: if ($env{'request.course.sec'} ne '') {
17848: $checkrole .= "/$env{'request.course.sec'}";
17849: }
17850: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
17851: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
17852: return;
17853: }
17854: }
17855: }
1.1190 musolffc 17856: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17857: $env{'user.name'});
17858: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 17859: my $redirecturl;
1.1190 musolffc 17860: if ($what[0]) {
17861: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17862: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 17863: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17864: return (1, $url);
1.1190 musolffc 17865: }
1.1191 raeburn 17866: }
17867: }
17868: return ();
1.1190 musolffc 17869: }
17870:
1.1174 raeburn 17871: # Use:
17872: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17873: #
17874: ##################################################
17875: # password associated functions #
17876: ##################################################
17877: sub des_keys {
17878: # Make a new key for DES encryption.
17879: # Each key has two parts which are returned separately.
17880: # Please note: Each key must be passed through the &hex function
17881: # before it is output to the web browser. The hex versions cannot
17882: # be used to decrypt.
17883: my @hexstr=('0','1','2','3','4','5','6','7',
17884: '8','9','a','b','c','d','e','f');
17885: my $lkey='';
17886: for (0..7) {
17887: $lkey.=$hexstr[rand(15)];
17888: }
17889: my $ukey='';
17890: for (0..7) {
17891: $ukey.=$hexstr[rand(15)];
17892: }
17893: return ($lkey,$ukey);
17894: }
17895:
17896: sub des_decrypt {
17897: my ($key,$cyphertext) = @_;
17898: my $keybin=pack("H16",$key);
17899: my $cypher;
17900: if ($Crypt::DES::VERSION>=2.03) {
17901: $cypher=new Crypt::DES $keybin;
17902: } else {
17903: $cypher=new DES $keybin;
17904: }
1.1233 raeburn 17905: my $plaintext='';
17906: my $cypherlength = length($cyphertext);
17907: my $numchunks = int($cypherlength/32);
17908: for (my $j=0; $j<$numchunks; $j++) {
17909: my $start = $j*32;
17910: my $cypherblock = substr($cyphertext,$start,32);
17911: my $chunk =
17912: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17913: $chunk .=
17914: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17915: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17916: $plaintext .= $chunk;
17917: }
1.1174 raeburn 17918: return $plaintext;
17919: }
17920:
1.1309 raeburn 17921: sub make_short_symbs {
17922: my ($cdom,$cnum,$navmap) = @_;
17923: return unless (ref($navmap));
17924: my ($numnew,@errors);
17925: my @toshorten = &Apache::loncommon::get_env_multiple('form.addtiny');
17926: if (@toshorten) {
17927: my (%maps,%resources,%titles);
17928: &Apache::loncourserespicker::enumerate_course_contents($navmap,\%maps,\%resources,\%titles,
17929: 'shorturls',$cdom,$cnum);
17930: my %tocreate;
17931: if (keys(%resources)) {
17932: foreach my $item (sort {$a <=> $b} (@toshorten)) {
17933: my $symb = $resources{$item};
17934: if ($symb) {
17935: $tocreate{$cnum.'&'.$symb} = 1;
17936: }
17937: }
17938: }
17939: if (keys(%tocreate)) {
17940: my %coursetiny = &Apache::lonnet::dump('tiny',$cdom,$cnum);
17941: my $su = Short::URL->new(no_vowels => 1);
17942: my $init = '';
17943: my (%newunique,%addcourse,%courseonly,%failed);
17944: # get lock on tiny db
17945: my $now = time;
17946: my $lockhash = {
17947: "lock\0$now" => $env{'user.name'}.
17948: ':'.$env{'user.domain'},
17949: };
17950: my $tries = 0;
17951: my $gotlock = &Apache::lonnet::newput_dom('tiny',$lockhash,$cdom);
17952: my ($code,$error);
17953: while (($gotlock ne 'ok') && ($tries<3)) {
17954: $tries ++;
17955: sleep 1;
17956: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
17957: }
17958: if ($gotlock eq 'ok') {
17959: $init = &shorten_symbs($cdom,$init,$su,\%coursetiny,\%tocreate,\%newunique,
17960: \%addcourse,\%courseonly,\%failed);
17961: if (keys(%failed)) {
17962: my $numfailed = scalar(keys(%failed));
17963: push(@errors,&mt('error: could not obtain unique six character URL for [quant,_1,resource]',$numfailed));
17964: }
17965: if (keys(%newunique)) {
17966: my $putres = &Apache::lonnet::newput_dom('tiny',\%newunique,$cdom);
17967: if ($putres eq 'ok') {
17968: $numnew = scalar(keys(%newunique));
17969: my $newputres = &Apache::lonnet::newput('tiny',\%addcourse,$cdom,$cnum);
17970: unless ($newputres eq 'ok') {
17971: push(@errors,&mt('error: could not store course look-up of short URLs'));
17972: }
17973: } else {
17974: push(@errors,&mt('error: could not store unique six character URLs'));
17975: }
17976: }
17977: my $dellockres = &Apache::lonnet::del_dom('tiny',["lock\0$now"],$cdom);
17978: unless ($dellockres eq 'ok') {
17979: push(@errors,&mt('error: could not release lockfile'));
17980: }
17981: } else {
17982: push(@errors,&mt('error: could not obtain lockfile'));
17983: }
17984: if (keys(%courseonly)) {
17985: my $result = &Apache::lonnet::newput('tiny',\%courseonly,$cdom,$cnum);
17986: if ($result ne 'ok') {
17987: push(@errors,&mt('error: could not update course look-up of short URLs'));
17988: }
17989: }
17990: }
17991: }
17992: return ($numnew,\@errors);
17993: }
17994:
17995: sub shorten_symbs {
17996: my ($cdom,$init,$su,$coursetiny,$tocreate,$newunique,$addcourse,$courseonly,$failed) = @_;
17997: return unless ((ref($su)) && (ref($coursetiny) eq 'HASH') && (ref($tocreate) eq 'HASH') &&
17998: (ref($newunique) eq 'HASH') && (ref($addcourse) eq 'HASH') &&
17999: (ref($courseonly) eq 'HASH') && (ref($failed) eq 'HASH'));
18000: my (%possibles,%collisions);
18001: foreach my $key (keys(%{$tocreate})) {
18002: my $num = String::CRC32::crc32($key);
18003: my $tiny = $su->encode($num,$init);
18004: if ($tiny) {
18005: $possibles{$tiny} = $key;
18006: }
18007: }
18008: if (!$init) {
18009: $init = 1;
18010: } else {
18011: $init ++;
18012: }
18013: if (keys(%possibles)) {
18014: my @posstiny = keys(%possibles);
18015: my $configuname = &Apache::lonnet::get_domainconfiguser($cdom);
18016: my %currtiny = &Apache::lonnet::get('tiny',\@posstiny,$cdom,$configuname);
18017: if (keys(%currtiny)) {
18018: foreach my $key (keys(%currtiny)) {
18019: next if ($currtiny{$key} eq '');
18020: if ($currtiny{$key} eq $possibles{$key}) {
18021: my ($tcnum,$tsymb) = split(/\&/,$currtiny{$key});
18022: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18023: $courseonly->{$tsymb} = $key;
18024: }
18025: } else {
18026: $collisions{$possibles{$key}} = 1;
18027: }
18028: delete($possibles{$key});
18029: }
18030: }
18031: foreach my $key (keys(%possibles)) {
18032: $newunique->{$key} = $possibles{$key};
18033: my ($tcnum,$tsymb) = split(/\&/,$possibles{$key});
18034: unless (($coursetiny->{$tsymb} eq $key) || ($addcourse->{$tsymb} eq $key) || ($courseonly->{$tsymb} eq $key)) {
18035: $addcourse->{$tsymb} = $key;
18036: }
18037: }
18038: }
18039: if (keys(%collisions)) {
18040: if ($init <5) {
18041: if (!$init) {
18042: $init = 1;
18043: } else {
18044: $init ++;
18045: }
18046: $init = &shorten_symbs($cdom,$init,$su,$coursetiny,\%collisions,
18047: $newunique,$addcourse,$courseonly,$failed);
18048: } else {
18049: foreach my $key (keys(%collisions)) {
18050: $failed->{$key} = 1;
18051: }
18052: }
18053: }
18054: return $init;
18055: }
18056:
1.112 bowersj2 18057: 1;
18058: __END__;
1.41 ng 18059:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>