Annotation of loncom/interface/loncommon.pm, revision 1.1280
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1280 ! raeburn 4: # $Id: loncommon.pm,v 1.1279 2017/03/30 14:08:18 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.117 www 87:
1.517 raeburn 88: # ---------------------------------------------- Designs
89: use vars qw(%defaultdesign);
90:
1.22 www 91: my $readit;
92:
1.517 raeburn 93:
1.157 matthew 94: ##
95: ## Global Variables
96: ##
1.46 matthew 97:
1.643 foxr 98:
99: # ----------------------------------------------- SSI with retries:
100: #
101:
102: =pod
103:
1.648 raeburn 104: =head1 Server Side include with retries:
1.643 foxr 105:
106: =over 4
107:
1.648 raeburn 108: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 109:
110: Performs an ssi with some number of retries. Retries continue either
111: until the result is ok or until the retry count supplied by the
112: caller is exhausted.
113:
114: Inputs:
1.648 raeburn 115:
116: =over 4
117:
1.643 foxr 118: resource - Identifies the resource to insert.
1.648 raeburn 119:
1.643 foxr 120: retries - Count of the number of retries allowed.
1.648 raeburn 121:
1.643 foxr 122: form - Hash that identifies the rendering options.
123:
1.648 raeburn 124: =back
125:
126: Returns:
127:
128: =over 4
129:
1.643 foxr 130: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 131:
1.643 foxr 132: response - The response from the last attempt (which may or may not have been successful.
133:
1.648 raeburn 134: =back
135:
136: =back
137:
1.643 foxr 138: =cut
139:
140: sub ssi_with_retries {
141: my ($resource, $retries, %form) = @_;
142:
143:
144: my $ok = 0; # True if we got a good response.
145: my $content;
146: my $response;
147:
148: # Try to get the ssi done. within the retries count:
149:
150: do {
151: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
152: $ok = $response->is_success;
1.650 www 153: if (!$ok) {
154: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
155: }
1.643 foxr 156: $retries--;
157: } while (!$ok && ($retries > 0));
158:
159: if (!$ok) {
160: $content = ''; # On error return an empty content.
161: }
162: return ($content, $response);
163:
164: }
165:
166:
167:
1.20 www 168: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 169: my %language;
1.124 www 170: my %supported_language;
1.1088 foxr 171: my %supported_codes;
1.1048 foxr 172: my %latex_language; # For choosing hyphenation in <transl..>
173: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 174: my %cprtag;
1.192 taceyjo1 175: my %scprtag;
1.351 www 176: my %fe; my %fd; my %fm;
1.41 ng 177: my %category_extensions;
1.12 harris41 178:
1.46 matthew 179: # ---------------------------------------------- Thesaurus variables
1.144 matthew 180: #
181: # %Keywords:
182: # A hash used by &keyword to determine if a word is considered a keyword.
183: # $thesaurus_db_file
184: # Scalar containing the full path to the thesaurus database.
1.46 matthew 185:
186: my %Keywords;
187: my $thesaurus_db_file;
188:
1.144 matthew 189: #
190: # Initialize values from language.tab, copyright.tab, filetypes.tab,
191: # thesaurus.tab, and filecategories.tab.
192: #
1.18 www 193: BEGIN {
1.46 matthew 194: # Variable initialization
195: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
196: #
1.22 www 197: unless ($readit) {
1.12 harris41 198: # ------------------------------------------------------------------- languages
199: {
1.158 raeburn 200: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
201: '/language.tab';
202: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 203: while (my $line = <$fh>) {
204: next if ($line=~/^\#/);
205: chomp($line);
1.1088 foxr 206: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 207: $language{$key}=$val.' - '.$enc;
208: if ($sup) {
209: $supported_language{$key}=$sup;
1.1088 foxr 210: $supported_codes{$key} = $code;
1.158 raeburn 211: }
1.1048 foxr 212: if ($latex) {
213: $latex_language_bykey{$key} = $latex;
1.1088 foxr 214: $latex_language{$code} = $latex;
1.1048 foxr 215: }
1.158 raeburn 216: }
217: close($fh);
218: }
1.12 harris41 219: }
220: # ------------------------------------------------------------------ copyrights
221: {
1.158 raeburn 222: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
223: '/copyright.tab';
224: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 225: while (my $line = <$fh>) {
226: next if ($line=~/^\#/);
227: chomp($line);
228: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 229: $cprtag{$key}=$val;
230: }
231: close($fh);
232: }
1.12 harris41 233: }
1.351 www 234: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 235: {
236: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
237: '/source_copyright.tab';
238: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 239: while (my $line = <$fh>) {
240: next if ($line =~ /^\#/);
241: chomp($line);
242: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 243: $scprtag{$key}=$val;
244: }
245: close($fh);
246: }
247: }
1.63 www 248:
1.517 raeburn 249: # -------------------------------------------------------------- default domain designs
1.63 www 250: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 251: my $designfile = $designdir.'/default.tab';
252: if ( open (my $fh,"<$designfile") ) {
253: while (my $line = <$fh>) {
254: next if ($line =~ /^\#/);
255: chomp($line);
256: my ($key,$val)=(split(/\=/,$line));
257: if ($val) { $defaultdesign{$key}=$val; }
258: }
259: close($fh);
1.63 www 260: }
261:
1.15 harris41 262: # ------------------------------------------------------------- file categories
263: {
1.158 raeburn 264: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
265: '/filecategories.tab';
266: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 267: while (my $line = <$fh>) {
268: next if ($line =~ /^\#/);
269: chomp($line);
270: my ($extension,$category)=(split(/\s+/,$line,2));
1.1263 raeburn 271: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 272: }
273: close($fh);
274: }
275:
1.15 harris41 276: }
1.12 harris41 277: # ------------------------------------------------------------------ file types
278: {
1.158 raeburn 279: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
280: '/filetypes.tab';
281: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 282: while (my $line = <$fh>) {
283: next if ($line =~ /^\#/);
284: chomp($line);
285: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 286: if ($descr ne '') {
287: $fe{$ending}=lc($emb);
288: $fd{$ending}=$descr;
1.351 www 289: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 290: }
291: }
292: close($fh);
293: }
1.12 harris41 294: }
1.22 www 295: &Apache::lonnet::logthis(
1.705 tempelho 296: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 297: $readit=1;
1.46 matthew 298: } # end of unless($readit)
1.32 matthew 299:
300: }
1.112 bowersj2 301:
1.42 matthew 302: ###############################################################
303: ## HTML and Javascript Helper Functions ##
304: ###############################################################
305:
306: =pod
307:
1.112 bowersj2 308: =head1 HTML and Javascript Functions
1.42 matthew 309:
1.112 bowersj2 310: =over 4
311:
1.648 raeburn 312: =item * &browser_and_searcher_javascript()
1.112 bowersj2 313:
314: X<browsing, javascript>X<searching, javascript>Returns a string
315: containing javascript with two functions, C<openbrowser> and
316: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
317: tags.
1.42 matthew 318:
1.648 raeburn 319: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 320:
321: inputs: formname, elementname, only, omit
322:
323: formname and elementname indicate the name of the html form and name of
324: the element that the results of the browsing selection are to be placed in.
325:
326: Specifying 'only' will restrict the browser to displaying only files
1.185 www 327: with the given extension. Can be a comma separated list.
1.42 matthew 328:
329: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 330: with the given extension. Can be a comma separated list.
1.42 matthew 331:
1.648 raeburn 332: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 333:
334: Inputs: formname, elementname
335:
336: formname and elementname specify the name of the html form and the name
337: of the element the selection from the search results will be placed in.
1.542 raeburn 338:
1.42 matthew 339: =cut
340:
341: sub browser_and_searcher_javascript {
1.199 albertel 342: my ($mode)=@_;
343: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 344: my $resurl=&escape_single(&lastresurl());
1.42 matthew 345: return <<END;
1.219 albertel 346: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 347: var editbrowser = null;
1.135 albertel 348: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 349: var url = '$resurl/?';
1.42 matthew 350: if (editbrowser == null) {
351: url += 'launch=1&';
352: }
353: url += 'catalogmode=interactive&';
1.199 albertel 354: url += 'mode=$mode&';
1.611 albertel 355: url += 'inhibitmenu=yes&';
1.42 matthew 356: url += 'form=' + formname + '&';
357: if (only != null) {
358: url += 'only=' + only + '&';
1.217 albertel 359: } else {
360: url += 'only=&';
361: }
1.42 matthew 362: if (omit != null) {
363: url += 'omit=' + omit + '&';
1.217 albertel 364: } else {
365: url += 'omit=&';
366: }
1.135 albertel 367: if (titleelement != null) {
368: url += 'titleelement=' + titleelement + '&';
1.217 albertel 369: } else {
370: url += 'titleelement=&';
371: }
1.42 matthew 372: url += 'element=' + elementname + '';
373: var title = 'Browser';
1.435 albertel 374: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 375: options += ',width=700,height=600';
376: editbrowser = open(url,title,options,'1');
377: editbrowser.focus();
378: }
379: var editsearcher;
1.135 albertel 380: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 381: var url = '/adm/searchcat?';
382: if (editsearcher == null) {
383: url += 'launch=1&';
384: }
385: url += 'catalogmode=interactive&';
1.199 albertel 386: url += 'mode=$mode&';
1.42 matthew 387: url += 'form=' + formname + '&';
1.135 albertel 388: if (titleelement != null) {
389: url += 'titleelement=' + titleelement + '&';
1.217 albertel 390: } else {
391: url += 'titleelement=&';
392: }
1.42 matthew 393: url += 'element=' + elementname + '';
394: var title = 'Search';
1.435 albertel 395: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 396: options += ',width=700,height=600';
397: editsearcher = open(url,title,options,'1');
398: editsearcher.focus();
399: }
1.219 albertel 400: // END LON-CAPA Internal -->
1.42 matthew 401: END
1.170 www 402: }
403:
404: sub lastresurl {
1.258 albertel 405: if ($env{'environment.lastresurl'}) {
406: return $env{'environment.lastresurl'}
1.170 www 407: } else {
408: return '/res';
409: }
410: }
411:
412: sub storeresurl {
413: my $resurl=&Apache::lonnet::clutter(shift);
414: unless ($resurl=~/^\/res/) { return 0; }
415: $resurl=~s/\/$//;
416: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 417: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 418: return 1;
1.42 matthew 419: }
420:
1.74 www 421: sub studentbrowser_javascript {
1.111 www 422: unless (
1.258 albertel 423: (($env{'request.course.id'}) &&
1.302 albertel 424: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
425: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
426: '/'.$env{'request.course.sec'})
427: ))
1.258 albertel 428: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 429: ) { return ''; }
1.74 www 430: return (<<'ENDSTDBRW');
1.776 bisitz 431: <script type="text/javascript" language="Javascript">
1.824 bisitz 432: // <![CDATA[
1.74 www 433: var stdeditbrowser;
1.999 www 434: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 435: var url = '/adm/pickstudent?';
436: var filter;
1.558 albertel 437: if (!ignorefilter) {
438: eval('filter=document.'+formname+'.'+uname+'.value;');
439: }
1.74 www 440: if (filter != null) {
441: if (filter != '') {
442: url += 'filter='+filter+'&';
443: }
444: }
445: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 446: '&udomelement='+udom+
447: '&clicker='+clicker;
1.111 www 448: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 449: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 450: var title = 'Student_Browser';
1.74 www 451: var options = 'scrollbars=1,resizable=1,menubar=0';
452: options += ',width=700,height=600';
453: stdeditbrowser = open(url,title,options,'1');
454: stdeditbrowser.focus();
455: }
1.824 bisitz 456: // ]]>
1.74 www 457: </script>
458: ENDSTDBRW
459: }
1.42 matthew 460:
1.1003 www 461: sub resourcebrowser_javascript {
462: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 463: return (<<'ENDRESBRW');
1.1003 www 464: <script type="text/javascript" language="Javascript">
465: // <![CDATA[
466: var reseditbrowser;
1.1004 www 467: function openresbrowser(formname,reslink) {
1.1005 www 468: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 469: var title = 'Resource_Browser';
470: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 471: options += ',width=700,height=500';
1.1004 www 472: reseditbrowser = open(url,title,options,'1');
473: reseditbrowser.focus();
1.1003 www 474: }
475: // ]]>
476: </script>
1.1004 www 477: ENDRESBRW
1.1003 www 478: }
479:
1.74 www 480: sub selectstudent_link {
1.999 www 481: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
482: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
483: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
484: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 485: if ($env{'request.course.id'}) {
1.302 albertel 486: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
487: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
488: '/'.$env{'request.course.sec'})) {
1.111 www 489: return '';
490: }
1.999 www 491: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 492: if ($courseadvonly) {
493: $callargs .= ",'',1,1";
494: }
495: return '<span class="LC_nobreak">'.
496: '<a href="javascript:openstdbrowser('.$callargs.');">'.
497: &mt('Select User').'</a></span>';
1.74 www 498: }
1.258 albertel 499: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 500: $callargs .= ",'',1";
1.793 raeburn 501: return '<span class="LC_nobreak">'.
502: '<a href="javascript:openstdbrowser('.$callargs.');">'.
503: &mt('Select User').'</a></span>';
1.111 www 504: }
505: return '';
1.91 www 506: }
507:
1.1004 www 508: sub selectresource_link {
509: my ($form,$reslink,$arg)=@_;
510:
511: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
512: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
513: unless ($env{'request.course.id'}) { return $arg; }
514: return '<span class="LC_nobreak">'.
515: '<a href="javascript:openresbrowser('.$callargs.');">'.
516: $arg.'</a></span>';
517: }
518:
519:
520:
1.653 raeburn 521: sub authorbrowser_javascript {
522: return <<"ENDAUTHORBRW";
1.776 bisitz 523: <script type="text/javascript" language="JavaScript">
1.824 bisitz 524: // <![CDATA[
1.653 raeburn 525: var stdeditbrowser;
526:
527: function openauthorbrowser(formname,udom) {
528: var url = '/adm/pickauthor?';
529: url += 'form='+formname+'&roledom='+udom;
530: var title = 'Author_Browser';
531: var options = 'scrollbars=1,resizable=1,menubar=0';
532: options += ',width=700,height=600';
533: stdeditbrowser = open(url,title,options,'1');
534: stdeditbrowser.focus();
535: }
536:
1.824 bisitz 537: // ]]>
1.653 raeburn 538: </script>
539: ENDAUTHORBRW
540: }
541:
1.91 www 542: sub coursebrowser_javascript {
1.1116 raeburn 543: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1221 raeburn 544: $credits_element,$instcode) = @_;
1.932 raeburn 545: my $wintitle = 'Course_Browser';
1.931 raeburn 546: if ($crstype eq 'Community') {
1.932 raeburn 547: $wintitle = 'Community_Browser';
1.909 raeburn 548: }
1.876 raeburn 549: my $id_functions = &javascript_index_functions();
550: my $output = '
1.776 bisitz 551: <script type="text/javascript" language="JavaScript">
1.824 bisitz 552: // <![CDATA[
1.468 raeburn 553: var stdeditbrowser;'."\n";
1.876 raeburn 554:
555: $output .= <<"ENDSTDBRW";
1.909 raeburn 556: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 557: var url = '/adm/pickcourse?';
1.895 raeburn 558: var formid = getFormIdByName(formname);
1.876 raeburn 559: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 560: if (domainfilter != null) {
561: if (domainfilter != '') {
562: url += 'domainfilter='+domainfilter+'&';
563: }
564: }
1.91 www 565: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 566: '&cdomelement='+udom+
567: '&cnameelement='+desc;
1.468 raeburn 568: if (extra_element !=null && extra_element != '') {
1.594 raeburn 569: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 570: url += '&roleelement='+extra_element;
571: if (domainfilter == null || domainfilter == '') {
572: url += '&domainfilter='+extra_element;
573: }
1.234 raeburn 574: }
1.468 raeburn 575: else {
576: if (formname == 'portform') {
577: url += '&setroles='+extra_element;
1.800 raeburn 578: } else {
579: if (formname == 'rules') {
580: url += '&fixeddom='+extra_element;
581: }
1.468 raeburn 582: }
583: }
1.230 raeburn 584: }
1.909 raeburn 585: if (type != null && type != '') {
586: url += '&type='+type;
587: }
588: if (type_elem != null && type_elem != '') {
589: url += '&typeelement='+type_elem;
590: }
1.872 raeburn 591: if (formname == 'ccrs') {
592: var ownername = document.forms[formid].ccuname.value;
593: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1238 raeburn 594: url += '&cloner='+ownername+':'+ownerdom;
595: if (type == 'Course') {
596: url += '&crscode='+document.forms[formid].crscode.value;
597: }
1.1221 raeburn 598: }
599: if (formname == 'requestcrs') {
600: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 601: }
1.293 raeburn 602: if (multflag !=null && multflag != '') {
603: url += '&multiple='+multflag;
604: }
1.909 raeburn 605: var title = '$wintitle';
1.91 www 606: var options = 'scrollbars=1,resizable=1,menubar=0';
607: options += ',width=700,height=600';
608: stdeditbrowser = open(url,title,options,'1');
609: stdeditbrowser.focus();
610: }
1.876 raeburn 611: $id_functions
612: ENDSTDBRW
1.1116 raeburn 613: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
614: $output .= &setsec_javascript($sec_element,$formname,$role_element,
615: $credits_element);
1.876 raeburn 616: }
617: $output .= '
618: // ]]>
619: </script>';
620: return $output;
621: }
622:
623: sub javascript_index_functions {
624: return <<"ENDJS";
625:
626: function getFormIdByName(formname) {
627: for (var i=0;i<document.forms.length;i++) {
628: if (document.forms[i].name == formname) {
629: return i;
630: }
631: }
632: return -1;
633: }
634:
635: function getIndexByName(formid,item) {
636: for (var i=0;i<document.forms[formid].elements.length;i++) {
637: if (document.forms[formid].elements[i].name == item) {
638: return i;
639: }
640: }
641: return -1;
642: }
1.468 raeburn 643:
1.876 raeburn 644: function getDomainFromSelectbox(formname,udom) {
645: var userdom;
646: var formid = getFormIdByName(formname);
647: if (formid > -1) {
648: var domid = getIndexByName(formid,udom);
649: if (domid > -1) {
650: if (document.forms[formid].elements[domid].type == 'select-one') {
651: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
652: }
653: if (document.forms[formid].elements[domid].type == 'hidden') {
654: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 655: }
656: }
657: }
1.876 raeburn 658: return userdom;
659: }
660:
661: ENDJS
1.468 raeburn 662:
1.876 raeburn 663: }
664:
1.1017 raeburn 665: sub javascript_array_indexof {
1.1018 raeburn 666: return <<ENDJS;
1.1017 raeburn 667: <script type="text/javascript" language="JavaScript">
668: // <![CDATA[
669:
670: if (!Array.prototype.indexOf) {
671: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
672: "use strict";
673: if (this === void 0 || this === null) {
674: throw new TypeError();
675: }
676: var t = Object(this);
677: var len = t.length >>> 0;
678: if (len === 0) {
679: return -1;
680: }
681: var n = 0;
682: if (arguments.length > 0) {
683: n = Number(arguments[1]);
1.1088 foxr 684: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 685: n = 0;
686: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
687: n = (n > 0 || -1) * Math.floor(Math.abs(n));
688: }
689: }
690: if (n >= len) {
691: return -1;
692: }
693: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
694: for (; k < len; k++) {
695: if (k in t && t[k] === searchElement) {
696: return k;
697: }
698: }
699: return -1;
700: }
701: }
702:
703: // ]]>
704: </script>
705:
706: ENDJS
707:
708: }
709:
1.876 raeburn 710: sub userbrowser_javascript {
711: my $id_functions = &javascript_index_functions();
712: return <<"ENDUSERBRW";
713:
1.888 raeburn 714: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 715: var url = '/adm/pickuser?';
716: var userdom = getDomainFromSelectbox(formname,udom);
717: if (userdom != null) {
718: if (userdom != '') {
719: url += 'srchdom='+userdom+'&';
720: }
721: }
722: url += 'form=' + formname + '&unameelement='+uname+
723: '&udomelement='+udom+
724: '&ulastelement='+ulast+
725: '&ufirstelement='+ufirst+
726: '&uemailelement='+uemail+
1.881 raeburn 727: '&hideudomelement='+hideudom+
728: '&coursedom='+crsdom;
1.888 raeburn 729: if ((caller != null) && (caller != undefined)) {
730: url += '&caller='+caller;
731: }
1.876 raeburn 732: var title = 'User_Browser';
733: var options = 'scrollbars=1,resizable=1,menubar=0';
734: options += ',width=700,height=600';
735: var stdeditbrowser = open(url,title,options,'1');
736: stdeditbrowser.focus();
737: }
738:
1.888 raeburn 739: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 740: var formid = getFormIdByName(formname);
741: if (formid > -1) {
1.888 raeburn 742: var unameid = getIndexByName(formid,uname);
1.876 raeburn 743: var domid = getIndexByName(formid,udom);
744: var hidedomid = getIndexByName(formid,origdom);
745: if (hidedomid > -1) {
746: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 747: var unameval = document.forms[formid].elements[unameid].value;
748: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
749: if (domid > -1) {
750: var slct = document.forms[formid].elements[domid];
751: if (slct.type == 'select-one') {
752: var i;
753: for (i=0;i<slct.length;i++) {
754: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
755: }
756: }
757: if (slct.type == 'hidden') {
758: slct.value = fixeddom;
1.876 raeburn 759: }
760: }
1.468 raeburn 761: }
762: }
763: }
1.876 raeburn 764: return;
765: }
766:
767: $id_functions
768: ENDUSERBRW
1.468 raeburn 769: }
770:
771: sub setsec_javascript {
1.1116 raeburn 772: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 773: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
774: $communityrolestr);
775: if ($role_element ne '') {
776: my @allroles = ('st','ta','ep','in','ad');
777: foreach my $crstype ('Course','Community') {
778: if ($crstype eq 'Community') {
779: foreach my $role (@allroles) {
780: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
781: }
782: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
783: } else {
784: foreach my $role (@allroles) {
785: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
786: }
787: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
788: }
789: }
790: $rolestr = '"'.join('","',@allroles).'"';
791: $courserolestr = '"'.join('","',@courserolenames).'"';
792: $communityrolestr = '"'.join('","',@communityrolenames).'"';
793: }
1.468 raeburn 794: my $setsections = qq|
795: function setSect(sectionlist) {
1.629 raeburn 796: var sectionsArray = new Array();
797: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
798: sectionsArray = sectionlist.split(",");
799: }
1.468 raeburn 800: var numSections = sectionsArray.length;
801: document.$formname.$sec_element.length = 0;
802: if (numSections == 0) {
803: document.$formname.$sec_element.multiple=false;
804: document.$formname.$sec_element.size=1;
805: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
806: } else {
807: if (numSections == 1) {
808: document.$formname.$sec_element.multiple=false;
809: document.$formname.$sec_element.size=1;
810: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
811: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
812: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
813: } else {
814: for (var i=0; i<numSections; i++) {
815: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
816: }
817: document.$formname.$sec_element.multiple=true
818: if (numSections < 3) {
819: document.$formname.$sec_element.size=numSections;
820: } else {
821: document.$formname.$sec_element.size=3;
822: }
823: document.$formname.$sec_element.options[0].selected = false
824: }
825: }
1.91 www 826: }
1.905 raeburn 827:
828: function setRole(crstype) {
1.468 raeburn 829: |;
1.905 raeburn 830: if ($role_element eq '') {
831: $setsections .= ' return;
832: }
833: ';
834: } else {
835: $setsections .= qq|
836: var elementLength = document.$formname.$role_element.length;
837: var allroles = Array($rolestr);
838: var courserolenames = Array($courserolestr);
839: var communityrolenames = Array($communityrolestr);
840: if (elementLength != undefined) {
841: if (document.$formname.$role_element.options[5].value == 'cc') {
842: if (crstype == 'Course') {
843: return;
844: } else {
845: allroles[5] = 'co';
846: for (var i=0; i<6; i++) {
847: document.$formname.$role_element.options[i].value = allroles[i];
848: document.$formname.$role_element.options[i].text = communityrolenames[i];
849: }
850: }
851: } else {
852: if (crstype == 'Community') {
853: return;
854: } else {
855: allroles[5] = 'cc';
856: for (var i=0; i<6; i++) {
857: document.$formname.$role_element.options[i].value = allroles[i];
858: document.$formname.$role_element.options[i].text = courserolenames[i];
859: }
860: }
861: }
862: }
863: return;
864: }
865: |;
866: }
1.1116 raeburn 867: if ($credits_element) {
868: $setsections .= qq|
869: function setCredits(defaultcredits) {
870: document.$formname.$credits_element.value = defaultcredits;
871: return;
872: }
873: |;
874: }
1.468 raeburn 875: return $setsections;
876: }
877:
1.91 www 878: sub selectcourse_link {
1.909 raeburn 879: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
880: $typeelement) = @_;
881: my $type = $selecttype;
1.871 raeburn 882: my $linktext = &mt('Select Course');
883: if ($selecttype eq 'Community') {
1.909 raeburn 884: $linktext = &mt('Select Community');
1.1239 raeburn 885: } elsif ($selecttype eq 'Placement') {
886: $linktext = &mt('Select Placement Test');
1.906 raeburn 887: } elsif ($selecttype eq 'Course/Community') {
888: $linktext = &mt('Select Course/Community');
1.909 raeburn 889: $type = '';
1.1019 raeburn 890: } elsif ($selecttype eq 'Select') {
891: $linktext = &mt('Select');
892: $type = '';
1.871 raeburn 893: }
1.787 bisitz 894: return '<span class="LC_nobreak">'
895: ."<a href='"
896: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
897: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 898: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 899: ."'>".$linktext.'</a>'
1.787 bisitz 900: .'</span>';
1.74 www 901: }
1.42 matthew 902:
1.653 raeburn 903: sub selectauthor_link {
904: my ($form,$udom)=@_;
905: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
906: &mt('Select Author').'</a>';
907: }
908:
1.876 raeburn 909: sub selectuser_link {
1.881 raeburn 910: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 911: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 912: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 913: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 914: ');">'.$linktext.'</a>';
1.876 raeburn 915: }
916:
1.273 raeburn 917: sub check_uncheck_jscript {
918: my $jscript = <<"ENDSCRT";
919: function checkAll(field) {
920: if (field.length > 0) {
921: for (i = 0; i < field.length; i++) {
1.1093 raeburn 922: if (!field[i].disabled) {
923: field[i].checked = true;
924: }
1.273 raeburn 925: }
926: } else {
1.1093 raeburn 927: if (!field.disabled) {
928: field.checked = true;
929: }
1.273 raeburn 930: }
931: }
932:
933: function uncheckAll(field) {
934: if (field.length > 0) {
935: for (i = 0; i < field.length; i++) {
936: field[i].checked = false ;
1.543 albertel 937: }
938: } else {
1.273 raeburn 939: field.checked = false ;
940: }
941: }
942: ENDSCRT
943: return $jscript;
944: }
945:
1.656 www 946: sub select_timezone {
1.1256 raeburn 947: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
948: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 949: if ($includeempty) {
950: $output .= '<option value=""';
951: if (($selected eq '') || ($selected eq 'local')) {
952: $output .= ' selected="selected" ';
953: }
954: $output .= '> </option>';
955: }
1.657 raeburn 956: my @timezones = DateTime::TimeZone->all_names;
957: foreach my $tzone (@timezones) {
958: $output.= '<option value="'.$tzone.'"';
959: if ($tzone eq $selected) {
960: $output.=' selected="selected"';
961: }
962: $output.=">$tzone</option>\n";
1.656 www 963: }
964: $output.="</select>";
965: return $output;
966: }
1.273 raeburn 967:
1.687 raeburn 968: sub select_datelocale {
1.1256 raeburn 969: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
970: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 971: if ($includeempty) {
972: $output .= '<option value=""';
973: if ($selected eq '') {
974: $output .= ' selected="selected" ';
975: }
976: $output .= '> </option>';
977: }
1.1241 raeburn 978: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 979: my (@possibles,%locale_names);
1.1241 raeburn 980: my @locales = DateTime::Locale->ids();
981: foreach my $id (@locales) {
982: if ($id ne '') {
983: my ($en_terr,$native_terr);
984: my $loc = DateTime::Locale->load($id);
985: if (ref($loc)) {
986: $en_terr = $loc->name();
987: $native_terr = $loc->native_name();
1.687 raeburn 988: if (grep(/^en$/,@languages) || !@languages) {
989: if ($en_terr ne '') {
990: $locale_names{$id} = '('.$en_terr.')';
991: } elsif ($native_terr ne '') {
992: $locale_names{$id} = $native_terr;
993: }
994: } else {
995: if ($native_terr ne '') {
996: $locale_names{$id} = $native_terr.' ';
997: } elsif ($en_terr ne '') {
998: $locale_names{$id} = '('.$en_terr.')';
999: }
1000: }
1.1220 raeburn 1001: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1241 raeburn 1002: push(@possibles,$id);
1003: }
1.687 raeburn 1004: }
1005: }
1006: foreach my $item (sort(@possibles)) {
1007: $output.= '<option value="'.$item.'"';
1008: if ($item eq $selected) {
1009: $output.=' selected="selected"';
1010: }
1011: $output.=">$item";
1012: if ($locale_names{$item} ne '') {
1.1220 raeburn 1013: $output.=' '.$locale_names{$item};
1.687 raeburn 1014: }
1015: $output.="</option>\n";
1016: }
1017: $output.="</select>";
1018: return $output;
1019: }
1020:
1.792 raeburn 1021: sub select_language {
1.1256 raeburn 1022: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1023: my %langchoices;
1024: if ($includeempty) {
1.1117 raeburn 1025: %langchoices = ('' => 'No language preference');
1.792 raeburn 1026: }
1027: foreach my $id (&languageids()) {
1028: my $code = &supportedlanguagecode($id);
1029: if ($code) {
1030: $langchoices{$code} = &plainlanguagedescription($id);
1031: }
1032: }
1.1117 raeburn 1033: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1256 raeburn 1034: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1035: }
1036:
1.42 matthew 1037: =pod
1.36 matthew 1038:
1.1088 foxr 1039:
1040: =item * &list_languages()
1041:
1042: Returns an array reference that is suitable for use in language prompters.
1043: Each array element is itself a two element array. The first element
1044: is the language code. The second element a descsriptiuon of the
1045: language itself. This is suitable for use in e.g.
1046: &Apache::edit::select_arg (once dereferenced that is).
1047:
1048: =cut
1049:
1050: sub list_languages {
1051: my @lang_choices;
1052:
1053: foreach my $id (&languageids()) {
1054: my $code = &supportedlanguagecode($id);
1055: if ($code) {
1056: my $selector = $supported_codes{$id};
1057: my $description = &plainlanguagedescription($id);
1.1263 raeburn 1058: push(@lang_choices, [$selector, $description]);
1.1088 foxr 1059: }
1060: }
1061: return \@lang_choices;
1062: }
1063:
1064: =pod
1065:
1.648 raeburn 1066: =item * &linked_select_forms(...)
1.36 matthew 1067:
1068: linked_select_forms returns a string containing a <script></script> block
1069: and html for two <select> menus. The select menus will be linked in that
1070: changing the value of the first menu will result in new values being placed
1071: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1072: order unless a defined order is provided.
1.36 matthew 1073:
1074: linked_select_forms takes the following ordered inputs:
1075:
1076: =over 4
1077:
1.112 bowersj2 1078: =item * $formname, the name of the <form> tag
1.36 matthew 1079:
1.112 bowersj2 1080: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1081:
1.112 bowersj2 1082: =item * $firstdefault, the default value for the first menu
1.36 matthew 1083:
1.112 bowersj2 1084: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1085:
1.112 bowersj2 1086: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1087:
1.112 bowersj2 1088: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1089:
1.609 raeburn 1090: =item * $menuorder, the order of values in the first menu
1091:
1.1115 raeburn 1092: =item * $onchangefirst, additional javascript call to execute for an onchange
1093: event for the first <select> tag
1094:
1095: =item * $onchangesecond, additional javascript call to execute for an onchange
1096: event for the second <select> tag
1097:
1.1245 raeburn 1098: =item * $suffix, to differentiate separate uses of select2data javascript
1099: objects in a page.
1100:
1.41 ng 1101: =back
1102:
1.36 matthew 1103: Below is an example of such a hash. Only the 'text', 'default', and
1104: 'select2' keys must appear as stated. keys(%menu) are the possible
1105: values for the first select menu. The text that coincides with the
1.41 ng 1106: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1107: and text for the second menu are given in the hash pointed to by
1108: $menu{$choice1}->{'select2'}.
1109:
1.112 bowersj2 1110: my %menu = ( A1 => { text =>"Choice A1" ,
1111: default => "B3",
1112: select2 => {
1113: B1 => "Choice B1",
1114: B2 => "Choice B2",
1115: B3 => "Choice B3",
1116: B4 => "Choice B4"
1.609 raeburn 1117: },
1118: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1119: },
1120: A2 => { text =>"Choice A2" ,
1121: default => "C2",
1122: select2 => {
1123: C1 => "Choice C1",
1124: C2 => "Choice C2",
1125: C3 => "Choice C3"
1.609 raeburn 1126: },
1127: order => ['C2','C1','C3'],
1.112 bowersj2 1128: },
1129: A3 => { text =>"Choice A3" ,
1130: default => "D6",
1131: select2 => {
1132: D1 => "Choice D1",
1133: D2 => "Choice D2",
1134: D3 => "Choice D3",
1135: D4 => "Choice D4",
1136: D5 => "Choice D5",
1137: D6 => "Choice D6",
1138: D7 => "Choice D7"
1.609 raeburn 1139: },
1140: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1141: }
1142: );
1.36 matthew 1143:
1144: =cut
1145:
1146: sub linked_select_forms {
1147: my ($formname,
1148: $middletext,
1149: $firstdefault,
1150: $firstselectname,
1151: $secondselectname,
1.609 raeburn 1152: $hashref,
1153: $menuorder,
1.1115 raeburn 1154: $onchangefirst,
1.1245 raeburn 1155: $onchangesecond,
1156: $suffix
1.36 matthew 1157: ) = @_;
1158: my $second = "document.$formname.$secondselectname";
1159: my $first = "document.$formname.$firstselectname";
1160: # output the javascript to do the changing
1161: my $result = '';
1.776 bisitz 1162: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1163: $result.="// <![CDATA[\n";
1.1245 raeburn 1164: $result.="var select2data${suffix} = new Object();\n";
1.36 matthew 1165: $" = '","';
1166: my $debug = '';
1167: foreach my $s1 (sort(keys(%$hashref))) {
1.1245 raeburn 1168: $result.="select2data${suffix}['d_$s1'] = new Object();\n";
1169: $result.="select2data${suffix}['d_$s1'].def = new String('".
1.36 matthew 1170: $hashref->{$s1}->{'default'}."');\n";
1.1245 raeburn 1171: $result.="select2data${suffix}['d_$s1'].values = new Array(";
1.36 matthew 1172: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1173: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1174: @s2values = @{$hashref->{$s1}->{'order'}};
1175: }
1.36 matthew 1176: $result.="\"@s2values\");\n";
1.1245 raeburn 1177: $result.="select2data${suffix}['d_$s1'].texts = new Array(";
1.36 matthew 1178: my @s2texts;
1179: foreach my $value (@s2values) {
1.1263 raeburn 1180: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1181: }
1182: $result.="\"@s2texts\");\n";
1183: }
1184: $"=' ';
1185: $result.= <<"END";
1186:
1.1245 raeburn 1187: function select1${suffix}_changed() {
1.36 matthew 1188: // Determine new choice
1.1245 raeburn 1189: var newvalue = "d_" + $first.options[$first.selectedIndex].value;
1.36 matthew 1190: // update select2
1.1245 raeburn 1191: var values = select2data${suffix}[newvalue].values;
1192: var texts = select2data${suffix}[newvalue].texts;
1193: var select2def = select2data${suffix}[newvalue].def;
1.36 matthew 1194: var i;
1195: // out with the old
1.1245 raeburn 1196: $second.options.length = 0;
1197: // in with the new
1.36 matthew 1198: for (i=0;i<values.length; i++) {
1199: $second.options[i] = new Option(values[i]);
1.143 matthew 1200: $second.options[i].value = values[i];
1.36 matthew 1201: $second.options[i].text = texts[i];
1202: if (values[i] == select2def) {
1203: $second.options[i].selected = true;
1204: }
1205: }
1206: }
1.824 bisitz 1207: // ]]>
1.36 matthew 1208: </script>
1209: END
1210: # output the initial values for the selection lists
1.1245 raeburn 1211: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
1.609 raeburn 1212: my @order = sort(keys(%{$hashref}));
1213: if (ref($menuorder) eq 'ARRAY') {
1214: @order = @{$menuorder};
1215: }
1216: foreach my $value (@order) {
1.36 matthew 1217: $result.=" <option value=\"$value\" ";
1.253 albertel 1218: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1219: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1220: }
1221: $result .= "</select>\n";
1222: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1223: $result .= $middletext;
1.1115 raeburn 1224: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1225: if ($onchangesecond) {
1226: $result .= ' onchange="'.$onchangesecond.'"';
1227: }
1228: $result .= ">\n";
1.36 matthew 1229: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1230:
1231: my @secondorder = sort(keys(%select2));
1232: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1233: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1234: }
1235: foreach my $value (@secondorder) {
1.36 matthew 1236: $result.=" <option value=\"$value\" ";
1.253 albertel 1237: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1238: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1239: }
1240: $result .= "</select>\n";
1241: # return $debug;
1242: return $result;
1243: } # end of sub linked_select_forms {
1244:
1.45 matthew 1245: =pod
1.44 bowersj2 1246:
1.973 raeburn 1247: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1248:
1.112 bowersj2 1249: Returns a string corresponding to an HTML link to the given help
1250: $topic, where $topic corresponds to the name of a .tex file in
1251: /home/httpd/html/adm/help/tex, with underscores replaced by
1252: spaces.
1253:
1254: $text will optionally be linked to the same topic, allowing you to
1255: link text in addition to the graphic. If you do not want to link
1256: text, but wish to specify one of the later parameters, pass an
1257: empty string.
1258:
1259: $stayOnPage is a value that will be interpreted as a boolean. If true,
1260: the link will not open a new window. If false, the link will open
1261: a new window using Javascript. (Default is false.)
1262:
1263: $width and $height are optional numerical parameters that will
1264: override the width and height of the popped up window, which may
1.973 raeburn 1265: be useful for certain help topics with big pictures included.
1266:
1267: $imgid is the id of the img tag used for the help icon. This may be
1268: used in a javascript call to switch the image src. See
1269: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1270:
1271: =cut
1272:
1273: sub help_open_topic {
1.973 raeburn 1274: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1275: $text = "" if (not defined $text);
1.44 bowersj2 1276: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1277: $width = 500 if (not defined $width);
1.44 bowersj2 1278: $height = 400 if (not defined $height);
1279: my $filename = $topic;
1280: $filename =~ s/ /_/g;
1281:
1.48 bowersj2 1282: my $template = "";
1283: my $link;
1.572 banghart 1284:
1.159 www 1285: $topic=~s/\W/\_/g;
1.44 bowersj2 1286:
1.572 banghart 1287: if (!$stayOnPage) {
1.1033 www 1288: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1289: } elsif ($stayOnPage eq 'popup') {
1290: $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 1291: } else {
1.48 bowersj2 1292: $link = "/adm/help/${filename}.hlp";
1293: }
1294:
1295: # Add the text
1.755 neumanie 1296: if ($text ne "") {
1.763 bisitz 1297: $template.='<span class="LC_help_open_topic">'
1298: .'<a target="_top" href="'.$link.'">'
1299: .$text.'</a>';
1.48 bowersj2 1300: }
1301:
1.763 bisitz 1302: # (Always) Add the graphic
1.179 matthew 1303: my $title = &mt('Online Help');
1.667 raeburn 1304: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1305: if ($imgid ne '') {
1306: $imgid = ' id="'.$imgid.'"';
1307: }
1.763 bisitz 1308: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1309: .'<img src="'.$helpicon.'" border="0"'
1310: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1311: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1312: .' /></a>';
1313: if ($text ne "") {
1314: $template.='</span>';
1315: }
1.44 bowersj2 1316: return $template;
1317:
1.106 bowersj2 1318: }
1319:
1320: # This is a quicky function for Latex cheatsheet editing, since it
1321: # appears in at least four places
1322: sub helpLatexCheatsheet {
1.1037 www 1323: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1324: my $out;
1.106 bowersj2 1325: my $addOther = '';
1.732 raeburn 1326: if ($topic) {
1.1037 www 1327: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1328: }
1329: $out = '<span>' # Start cheatsheet
1330: .$addOther
1331: .'<span>'
1.1037 www 1332: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1333: .'</span> <span>'
1.1037 www 1334: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1335: .'</span>';
1.732 raeburn 1336: unless ($not_author) {
1.1186 kruse 1337: $out .= '<span>'
1338: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1339: .'</span> <span>'
1340: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1341: .'</span>';
1.732 raeburn 1342: }
1.763 bisitz 1343: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1344: return $out;
1.172 www 1345: }
1346:
1.430 albertel 1347: sub general_help {
1348: my $helptopic='Student_Intro';
1349: if ($env{'request.role'}=~/^(ca|au)/) {
1350: $helptopic='Authoring_Intro';
1.907 raeburn 1351: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1352: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1353: } elsif ($env{'request.role'}=~/^dc/) {
1354: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1355: }
1356: return $helptopic;
1357: }
1358:
1359: sub update_help_link {
1360: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1361: my $origurl = $ENV{'REQUEST_URI'};
1362: $origurl=~s|^/~|/priv/|;
1363: my $timestamp = time;
1364: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1365: $$datum = &escape($$datum);
1366: }
1367:
1368: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1369: my $output .= <<"ENDOUTPUT";
1370: <script type="text/javascript">
1.824 bisitz 1371: // <![CDATA[
1.430 albertel 1372: banner_link = '$banner_link';
1.824 bisitz 1373: // ]]>
1.430 albertel 1374: </script>
1375: ENDOUTPUT
1376: return $output;
1377: }
1378:
1379: # now just updates the help link and generates a blue icon
1.193 raeburn 1380: sub help_open_menu {
1.430 albertel 1381: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1382: = @_;
1.949 droeschl 1383: $stayOnPage = 1;
1.430 albertel 1384: my $output;
1385: if ($component_help) {
1386: if (!$text) {
1387: $output=&help_open_topic($component_help,undef,$stayOnPage,
1388: $width,$height);
1389: } else {
1390: my $help_text;
1391: $help_text=&unescape($topic);
1392: $output='<table><tr><td>'.
1393: &help_open_topic($component_help,$help_text,$stayOnPage,
1394: $width,$height).'</td></tr></table>';
1395: }
1396: }
1397: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1398: return $output.$banner_link;
1399: }
1400:
1401: sub top_nav_help {
1402: my ($text) = @_;
1.436 albertel 1403: $text = &mt($text);
1.949 droeschl 1404: my $stay_on_page = 1;
1405:
1.1168 raeburn 1406: my ($link,$banner_link);
1407: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1408: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1409: : "javascript:helpMenu('open')";
1410: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1411: }
1.201 raeburn 1412: my $title = &mt('Get help');
1.1168 raeburn 1413: if ($link) {
1414: return <<"END";
1.436 albertel 1415: $banner_link
1.1159 raeburn 1416: <a href="$link" title="$title">$text</a>
1.436 albertel 1417: END
1.1168 raeburn 1418: } else {
1419: return ' '.$text.' ';
1420: }
1.436 albertel 1421: }
1422:
1423: sub help_menu_js {
1.1154 raeburn 1424: my ($httphost) = @_;
1.949 droeschl 1425: my $stayOnPage = 1;
1.436 albertel 1426: my $width = 620;
1427: my $height = 600;
1.430 albertel 1428: my $helptopic=&general_help();
1.1154 raeburn 1429: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1430: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1431: my $start_page =
1432: &Apache::loncommon::start_page('Help Menu', undef,
1433: {'frameset' => 1,
1434: 'js_ready' => 1,
1.1154 raeburn 1435: 'use_absolute' => $httphost,
1.331 albertel 1436: 'add_entries' => {
1.1168 raeburn 1437: 'border' => '0',
1.579 raeburn 1438: 'rows' => "110,*",},});
1.331 albertel 1439: my $end_page =
1440: &Apache::loncommon::end_page({'frameset' => 1,
1441: 'js_ready' => 1,});
1442:
1.436 albertel 1443: my $template .= <<"ENDTEMPLATE";
1444: <script type="text/javascript">
1.877 bisitz 1445: // <![CDATA[
1.253 albertel 1446: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1447: var banner_link = '';
1.243 raeburn 1448: function helpMenu(target) {
1449: var caller = this;
1450: if (target == 'open') {
1451: var newWindow = null;
1452: try {
1.262 albertel 1453: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1454: }
1455: catch(error) {
1456: writeHelp(caller);
1457: return;
1458: }
1459: if (newWindow) {
1460: caller = newWindow;
1461: }
1.193 raeburn 1462: }
1.243 raeburn 1463: writeHelp(caller);
1464: return;
1465: }
1466: function writeHelp(caller) {
1.1168 raeburn 1467: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1468: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1469: caller.document.close();
1470: caller.focus();
1.193 raeburn 1471: }
1.877 bisitz 1472: // END LON-CAPA Internal -->
1.253 albertel 1473: // ]]>
1.436 albertel 1474: </script>
1.193 raeburn 1475: ENDTEMPLATE
1476: return $template;
1477: }
1478:
1.172 www 1479: sub help_open_bug {
1480: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1481: unless ($env{'user.adv'}) { return ''; }
1.172 www 1482: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1483: $text = "" if (not defined $text);
1484: $stayOnPage=1;
1.184 albertel 1485: $width = 600 if (not defined $width);
1486: $height = 600 if (not defined $height);
1.172 www 1487:
1488: $topic=~s/\W+/\+/g;
1489: my $link='';
1490: my $template='';
1.379 albertel 1491: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1492: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1493: if (!$stayOnPage)
1494: {
1495: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1496: }
1497: else
1498: {
1499: $link = $url;
1500: }
1501: # Add the text
1502: if ($text ne "")
1503: {
1504: $template .=
1505: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1506: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1507: }
1508:
1509: # Add the graphic
1.179 matthew 1510: my $title = &mt('Report a Bug');
1.215 albertel 1511: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1512: $template .= <<"ENDTEMPLATE";
1.436 albertel 1513: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1514: ENDTEMPLATE
1515: if ($text ne '') { $template.='</td></tr></table>' };
1516: return $template;
1517:
1518: }
1519:
1520: sub help_open_faq {
1521: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1522: unless ($env{'user.adv'}) { return ''; }
1.172 www 1523: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1524: $text = "" if (not defined $text);
1525: $stayOnPage=1;
1526: $width = 350 if (not defined $width);
1527: $height = 400 if (not defined $height);
1528:
1529: $topic=~s/\W+/\+/g;
1530: my $link='';
1531: my $template='';
1532: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1533: if (!$stayOnPage)
1534: {
1535: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1536: }
1537: else
1538: {
1539: $link = $url;
1540: }
1541:
1542: # Add the text
1543: if ($text ne "")
1544: {
1545: $template .=
1.173 www 1546: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1547: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1548: }
1549:
1550: # Add the graphic
1.179 matthew 1551: my $title = &mt('View the FAQ');
1.215 albertel 1552: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1553: $template .= <<"ENDTEMPLATE";
1.436 albertel 1554: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1555: ENDTEMPLATE
1556: if ($text ne '') { $template.='</td></tr></table>' };
1557: return $template;
1558:
1.44 bowersj2 1559: }
1.37 matthew 1560:
1.180 matthew 1561: ###############################################################
1562: ###############################################################
1563:
1.45 matthew 1564: =pod
1565:
1.648 raeburn 1566: =item * &change_content_javascript():
1.256 matthew 1567:
1568: This and the next function allow you to create small sections of an
1569: otherwise static HTML page that you can update on the fly with
1570: Javascript, even in Netscape 4.
1571:
1572: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1573: must be written to the HTML page once. It will prove the Javascript
1574: function "change(name, content)". Calling the change function with the
1575: name of the section
1576: you want to update, matching the name passed to C<changable_area>, and
1577: the new content you want to put in there, will put the content into
1578: that area.
1579:
1580: B<Note>: Netscape 4 only reserves enough space for the changable area
1581: to contain room for the original contents. You need to "make space"
1582: for whatever changes you wish to make, and be B<sure> to check your
1583: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1584: it's adequate for updating a one-line status display, but little more.
1585: This script will set the space to 100% width, so you only need to
1586: worry about height in Netscape 4.
1587:
1588: Modern browsers are much less limiting, and if you can commit to the
1589: user not using Netscape 4, this feature may be used freely with
1590: pretty much any HTML.
1591:
1592: =cut
1593:
1594: sub change_content_javascript {
1595: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1596: if ($env{'browser.type'} eq 'netscape' &&
1597: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1598: return (<<NETSCAPE4);
1599: function change(name, content) {
1600: doc = document.layers[name+"___escape"].layers[0].document;
1601: doc.open();
1602: doc.write(content);
1603: doc.close();
1604: }
1605: NETSCAPE4
1606: } else {
1607: # Otherwise, we need to use semi-standards-compliant code
1608: # (technically, "innerHTML" isn't standard but the equivalent
1609: # is really scary, and every useful browser supports it
1610: return (<<DOMBASED);
1611: function change(name, content) {
1612: element = document.getElementById(name);
1613: element.innerHTML = content;
1614: }
1615: DOMBASED
1616: }
1617: }
1618:
1619: =pod
1620:
1.648 raeburn 1621: =item * &changable_area($name,$origContent):
1.256 matthew 1622:
1623: This provides a "changable area" that can be modified on the fly via
1624: the Javascript code provided in C<change_content_javascript>. $name is
1625: the name you will use to reference the area later; do not repeat the
1626: same name on a given HTML page more then once. $origContent is what
1627: the area will originally contain, which can be left blank.
1628:
1629: =cut
1630:
1631: sub changable_area {
1632: my ($name, $origContent) = @_;
1633:
1.258 albertel 1634: if ($env{'browser.type'} eq 'netscape' &&
1635: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1636: # If this is netscape 4, we need to use the Layer tag
1637: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1638: } else {
1639: return "<span id='$name'>$origContent</span>";
1640: }
1641: }
1642:
1643: =pod
1644:
1.648 raeburn 1645: =item * &viewport_geometry_js
1.590 raeburn 1646:
1647: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1648:
1649: =cut
1650:
1651:
1652: sub viewport_geometry_js {
1653: return <<"GEOMETRY";
1654: var Geometry = {};
1655: function init_geometry() {
1656: if (Geometry.init) { return };
1657: Geometry.init=1;
1658: if (window.innerHeight) {
1659: Geometry.getViewportHeight = function() { return window.innerHeight; };
1660: Geometry.getViewportWidth = function() { return window.innerWidth; };
1661: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1662: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1663: }
1664: else if (document.documentElement && document.documentElement.clientHeight) {
1665: Geometry.getViewportHeight =
1666: function() { return document.documentElement.clientHeight; };
1667: Geometry.getViewportWidth =
1668: function() { return document.documentElement.clientWidth; };
1669:
1670: Geometry.getHorizontalScroll =
1671: function() { return document.documentElement.scrollLeft; };
1672: Geometry.getVerticalScroll =
1673: function() { return document.documentElement.scrollTop; };
1674: }
1675: else if (document.body.clientHeight) {
1676: Geometry.getViewportHeight =
1677: function() { return document.body.clientHeight; };
1678: Geometry.getViewportWidth =
1679: function() { return document.body.clientWidth; };
1680: Geometry.getHorizontalScroll =
1681: function() { return document.body.scrollLeft; };
1682: Geometry.getVerticalScroll =
1683: function() { return document.body.scrollTop; };
1684: }
1685: }
1686:
1687: GEOMETRY
1688: }
1689:
1690: =pod
1691:
1.648 raeburn 1692: =item * &viewport_size_js()
1.590 raeburn 1693:
1694: 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.
1695:
1696: =cut
1697:
1698: sub viewport_size_js {
1699: my $geometry = &viewport_geometry_js();
1700: return <<"DIMS";
1701:
1702: $geometry
1703:
1704: function getViewportDims(width,height) {
1705: init_geometry();
1706: width.value = Geometry.getViewportWidth();
1707: height.value = Geometry.getViewportHeight();
1708: return;
1709: }
1710:
1711: DIMS
1712: }
1713:
1714: =pod
1715:
1.648 raeburn 1716: =item * &resize_textarea_js()
1.565 albertel 1717:
1718: emits the needed javascript to resize a textarea to be as big as possible
1719:
1720: creates a function resize_textrea that takes two IDs first should be
1721: the id of the element to resize, second should be the id of a div that
1722: surrounds everything that comes after the textarea, this routine needs
1723: to be attached to the <body> for the onload and onresize events.
1724:
1.648 raeburn 1725: =back
1.565 albertel 1726:
1727: =cut
1728:
1729: sub resize_textarea_js {
1.590 raeburn 1730: my $geometry = &viewport_geometry_js();
1.565 albertel 1731: return <<"RESIZE";
1732: <script type="text/javascript">
1.824 bisitz 1733: // <![CDATA[
1.590 raeburn 1734: $geometry
1.565 albertel 1735:
1.588 albertel 1736: function getX(element) {
1737: var x = 0;
1738: while (element) {
1739: x += element.offsetLeft;
1740: element = element.offsetParent;
1741: }
1742: return x;
1743: }
1744: function getY(element) {
1745: var y = 0;
1746: while (element) {
1747: y += element.offsetTop;
1748: element = element.offsetParent;
1749: }
1750: return y;
1751: }
1752:
1753:
1.565 albertel 1754: function resize_textarea(textarea_id,bottom_id) {
1755: init_geometry();
1756: var textarea = document.getElementById(textarea_id);
1757: //alert(textarea);
1758:
1.588 albertel 1759: var textarea_top = getY(textarea);
1.565 albertel 1760: var textarea_height = textarea.offsetHeight;
1761: var bottom = document.getElementById(bottom_id);
1.588 albertel 1762: var bottom_top = getY(bottom);
1.565 albertel 1763: var bottom_height = bottom.offsetHeight;
1764: var window_height = Geometry.getViewportHeight();
1.588 albertel 1765: var fudge = 23;
1.565 albertel 1766: var new_height = window_height-fudge-textarea_top-bottom_height;
1767: if (new_height < 300) {
1768: new_height = 300;
1769: }
1770: textarea.style.height=new_height+'px';
1771: }
1.824 bisitz 1772: // ]]>
1.565 albertel 1773: </script>
1774: RESIZE
1775:
1776: }
1777:
1.1205 golterma 1778: sub colorfuleditor_js {
1.1248 raeburn 1779: my $browse_or_search;
1780: my $respath;
1781: my ($cnum,$cdom) = &crsauthor_url();
1782: if ($cnum) {
1783: $respath = "/res/$cdom/$cnum/";
1784: my %js_lt = &Apache::lonlocal::texthash(
1785: sunm => 'Sub-directory name',
1786: save => 'Save page to make this permanent',
1787: );
1788: &js_escape(\%js_lt);
1789: $browse_or_search = <<"END";
1790:
1791: function toggleChooser(form,element,titleid,only,search) {
1792: var disp = 'none';
1793: if (document.getElementById('chooser_'+element)) {
1794: var curr = document.getElementById('chooser_'+element).style.display;
1795: if (curr == 'none') {
1796: disp='inline';
1797: if (form.elements['chooser_'+element].length) {
1798: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1799: form.elements['chooser_'+element][i].checked = false;
1800: }
1801: }
1802: toggleResImport(form,element);
1803: }
1804: document.getElementById('chooser_'+element).style.display = disp;
1805: }
1806: }
1807:
1808: function toggleCrsFile(form,element,numdirs) {
1809: if (document.getElementById('chooser_'+element+'_crsres')) {
1810: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1811: if (curr == 'none') {
1812: if (numdirs) {
1813: form.elements['coursepath_'+element].selectedIndex = 0;
1814: if (numdirs > 1) {
1815: window['select1'+element+'_changed']();
1816: }
1817: }
1818: }
1819: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1820:
1821: }
1822: if (document.getElementById('chooser_'+element+'_upload')) {
1823: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1824: if (document.getElementById('uploadcrsres_'+element)) {
1825: document.getElementById('uploadcrsres_'+element).value = '';
1826: }
1827: }
1828: return;
1829: }
1830:
1831: function toggleCrsUpload(form,element,numcrsdirs) {
1832: if (document.getElementById('chooser_'+element+'_crsres')) {
1833: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1834: }
1835: if (document.getElementById('chooser_'+element+'_upload')) {
1836: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1837: if (curr == 'none') {
1838: if (numcrsdirs) {
1839: form.elements['crsauthorpath_'+element].selectedIndex = 0;
1840: form.elements['newsubdir_'+element][0].checked = true;
1841: toggleNewsubdir(form,element);
1842: }
1843: }
1844: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1845: }
1846: return;
1847: }
1848:
1849: function toggleResImport(form,element) {
1850: var choices = new Array('crsres','upload');
1851: for (var i=0; i<choices.length; i++) {
1852: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1853: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1854: }
1855: }
1856: }
1857:
1858: function toggleNewsubdir(form,element) {
1859: var newsub = form.elements['newsubdir_'+element];
1860: if (newsub) {
1861: if (newsub.length) {
1862: for (var j=0; j<newsub.length; j++) {
1863: if (newsub[j].checked) {
1864: if (document.getElementById('newsubdirname_'+element)) {
1865: if (newsub[j].value == '1') {
1866: document.getElementById('newsubdirname_'+element).type = "text";
1867: if (document.getElementById('newsubdir_'+element)) {
1868: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1869: }
1870: } else {
1871: document.getElementById('newsubdirname_'+element).type = "hidden";
1872: document.getElementById('newsubdirname_'+element).value = "";
1873: document.getElementById('newsubdir_'+element).innerHTML = "";
1874: }
1875: }
1876: break;
1877: }
1878: }
1879: }
1880: }
1881: }
1882:
1883: function updateCrsFile(form,element) {
1884: var directory = form.elements['coursepath_'+element];
1885: var filename = form.elements['coursefile_'+element];
1886: var path = directory.options[directory.selectedIndex].value;
1887: var file = filename.options[filename.selectedIndex].value;
1888: form.elements[element].value = '$respath';
1889: if (path == '/') {
1890: form.elements[element].value += file;
1891: } else {
1892: form.elements[element].value += path+'/'+file;
1893: }
1894: unClean();
1895: if (document.getElementById('previewimg_'+element)) {
1896: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1897: var newsrc = document.getElementById('previewimg_'+element).src;
1898: }
1899: if (document.getElementById('showimg_'+element)) {
1900: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1901: }
1902: toggleChooser(form,element);
1903: return;
1904: }
1905:
1906: function uploadDone(suffix,name) {
1907: if (name) {
1908: document.forms["lonhomework"].elements[suffix].value = name;
1909: unClean();
1910: toggleChooser(document.forms["lonhomework"],suffix);
1911: }
1912: }
1913:
1914: \$(document).ready(function(){
1915:
1916: \$(document).delegate('form :submit', 'click', function( event ) {
1917: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
1918: var buttonId = this.id;
1919: var suffix = buttonId.toString();
1920: suffix = suffix.replace(/^crsupload_/,'');
1921: event.preventDefault();
1922: document.lonhomework.target = 'crsupload_target_'+suffix;
1923: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
1924: \$(this.form).submit();
1925: document.lonhomework.target = '';
1926: if (document.getElementById('crsuploadto_'+suffix)) {
1927: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
1928: }
1929: return false;
1930: }
1931: });
1932: });
1933: END
1934: }
1.1205 golterma 1935: return <<"COLORFULEDIT"
1936: <script type="text/javascript">
1937: // <![CDATA[>
1938: function fold_box(curDepth, lastresource){
1939:
1940: // we need a list because there can be several blocks you need to fold in one tag
1941: var block = document.getElementsByName('foldblock_'+curDepth);
1942: // but there is only one folding button per tag
1943: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1944:
1945: if(block.item(0).style.display == 'none'){
1946:
1947: foldbutton.value = '@{[&mt("Hide")]}';
1948: for (i = 0; i < block.length; i++){
1949: block.item(i).style.display = '';
1950: }
1951: }else{
1952:
1953: foldbutton.value = '@{[&mt("Show")]}';
1954: for (i = 0; i < block.length; i++){
1955: // block.item(i).style.visibility = 'collapse';
1956: block.item(i).style.display = 'none';
1957: }
1958: };
1959: saveState(lastresource);
1960: }
1961:
1962: function saveState (lastresource) {
1963:
1964: var tag_list = getTagList();
1965: if(tag_list != null){
1966: var timestamp = new Date().getTime();
1967: var key = lastresource;
1968:
1969: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1970: // starting with timestamp
1971: var value = timestamp+';';
1972:
1973: // building the list of key-value pairs
1974: for(var i = 0; i < tag_list.length; i++){
1975: value += tag_list[i]+',';
1976: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1977: }
1978:
1979: // only iterate whole storage if nothing to override
1980: if(localStorage.getItem(key) == null){
1981:
1982: // prevent storage from growing large
1983: if(localStorage.length > 50){
1984: var regex_getTimestamp = /^(?:\d)+;/;
1985: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1986: var oldest_key;
1987:
1988: for(var i = 1; i < localStorage.length; i++){
1989: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1990: oldest_key = localStorage.key(i);
1991: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1992: }
1993: }
1994: localStorage.removeItem(oldest_key);
1995: }
1996: }
1997: localStorage.setItem(key,value);
1998: }
1999: }
2000:
2001: // restore folding status of blocks (on page load)
2002: function restoreState (lastresource) {
2003: if(localStorage.getItem(lastresource) != null){
2004: var key = lastresource;
2005: var value = localStorage.getItem(key);
2006: var regex_delTimestamp = /^\d+;/;
2007:
2008: value.replace(regex_delTimestamp, '');
2009:
2010: var valueArr = value.split(';');
2011: var pairs;
2012: var elements;
2013: for (var i = 0; i < valueArr.length; i++){
2014: pairs = valueArr[i].split(',');
2015: elements = document.getElementsByName(pairs[0]);
2016:
2017: for (var j = 0; j < elements.length; j++){
2018: elements[j].style.display = pairs[1];
2019: if (pairs[1] == "none"){
2020: var regex_id = /([_\\d]+)\$/;
2021: regex_id.exec(pairs[0]);
2022: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2023: }
2024: }
2025: }
2026: }
2027: }
2028:
2029: function getTagList () {
2030:
2031: var stringToSearch = document.lonhomework.innerHTML;
2032:
2033: var ret = new Array();
2034: var regex_findBlock = /(foldblock_.*?)"/g;
2035: var tag_list = stringToSearch.match(regex_findBlock);
2036:
2037: if(tag_list != null){
2038: for(var i = 0; i < tag_list.length; i++){
2039: ret.push(tag_list[i].replace(/"/, ''));
2040: }
2041: }
2042: return ret;
2043: }
2044:
2045: function saveScrollPosition (resource) {
2046: var tag_list = getTagList();
2047:
2048: // we dont always want to jump to the first block
2049: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2050: if(\$(window).scrollTop() > 170){
2051: if(tag_list != null){
2052: var result;
2053: for(var i = 0; i < tag_list.length; i++){
2054: if(isElementInViewport(tag_list[i])){
2055: result += tag_list[i]+';';
2056: }
2057: }
2058: sessionStorage.setItem('anchor_'+resource, result);
2059: }
2060: } else {
2061: // we dont need to save zero, just delete the item to leave everything tidy
2062: sessionStorage.removeItem('anchor_'+resource);
2063: }
2064: }
2065:
2066: function restoreScrollPosition(resource){
2067:
2068: var elem = sessionStorage.getItem('anchor_'+resource);
2069: if(elem != null){
2070: var tag_list = elem.split(';');
2071: var elem_list;
2072:
2073: for(var i = 0; i < tag_list.length; i++){
2074: elem_list = document.getElementsByName(tag_list[i]);
2075:
2076: if(elem_list.length > 0){
2077: elem = elem_list[0];
2078: break;
2079: }
2080: }
2081: elem.scrollIntoView();
2082: }
2083: }
2084:
2085: function isElementInViewport(el) {
2086:
2087: // change to last element instead of first
2088: var elem = document.getElementsByName(el);
2089: var rect = elem[0].getBoundingClientRect();
2090:
2091: return (
2092: rect.top >= 0 &&
2093: rect.left >= 0 &&
2094: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2095: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2096: );
2097: }
2098:
2099: function autosize(depth){
2100: var cmInst = window['cm'+depth];
2101: var fitsizeButton = document.getElementById('fitsize'+depth);
2102:
2103: // is fixed size, switching to dynamic
2104: if (sessionStorage.getItem("autosized_"+depth) == null) {
2105: cmInst.setSize("","auto");
2106: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2107: sessionStorage.setItem("autosized_"+depth, "yes");
2108:
2109: // is dynamic size, switching to fixed
2110: } else {
2111: cmInst.setSize("","300px");
2112: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2113: sessionStorage.removeItem("autosized_"+depth);
2114: }
2115: }
2116:
1.1248 raeburn 2117: $browse_or_search
1.1205 golterma 2118:
2119: // ]]>
2120: </script>
2121: COLORFULEDIT
2122: }
2123:
2124: sub xmleditor_js {
2125: return <<XMLEDIT
2126: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2127: <script type="text/javascript">
2128: // <![CDATA[>
2129:
2130: function saveScrollPosition (resource) {
2131:
2132: var scrollPos = \$(window).scrollTop();
2133: sessionStorage.setItem(resource,scrollPos);
2134: }
2135:
2136: function restoreScrollPosition(resource){
2137:
2138: var scrollPos = sessionStorage.getItem(resource);
2139: \$(window).scrollTop(scrollPos);
2140: }
2141:
2142: // unless internet explorer
2143: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2144:
2145: \$(document).ready(function() {
2146: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2147: });
2148: }
2149:
2150: // inserts text at cursor position into codemirror (xml editor only)
2151: function insertText(text){
2152: cm.focus();
2153: var curPos = cm.getCursor();
2154: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2155: }
2156: // ]]>
2157: </script>
2158: XMLEDIT
2159: }
2160:
2161: sub insert_folding_button {
2162: my $curDepth = $Apache::lonxml::curdepth;
2163: my $lastresource = $env{'request.ambiguous'};
2164:
2165: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2166: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2167: }
2168:
1.1248 raeburn 2169: sub crsauthor_url {
2170: my ($url) = @_;
2171: if ($url eq '') {
2172: $url = $ENV{'REQUEST_URI'};
2173: }
2174: my ($cnum,$cdom);
2175: if ($env{'request.course.id'}) {
2176: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2177: if ($audom ne '' && $auname ne '') {
2178: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2179: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2180: $cnum = $auname;
2181: $cdom = $audom;
2182: }
2183: }
2184: }
2185: return ($cnum,$cdom);
2186: }
2187:
2188: sub import_crsauthor_form {
1.1265 raeburn 2189: my ($form,$firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2190: return (0) unless ($env{'request.course.id'});
2191: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2192: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2193: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2194: return (0) unless (($cnum ne '') && ($cdom ne ''));
2195: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
2196: my @ids=&Apache::lonnet::current_machine_ids();
2197: my ($output,$is_home,$relpath,%subdirs,%files,%selimport_menus);
2198:
2199: if (grep(/^\Q$crshome\E$/,@ids)) {
2200: $is_home = 1;
2201: }
2202: $relpath = "/priv/$cdom/$cnum";
2203: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$relpath,'',\%subdirs,\%files);
2204: my %lt = &Apache::lonlocal::texthash (
2205: fnam => 'Filename',
2206: dire => 'Directory',
2207: );
2208: my $numdirs = scalar(keys(%files));
2209: my (%possexts,$singledir,@singledirfiles);
2210: if ($only) {
2211: map { $possexts{$_} = 1; } split(/\s*,\s*/,$only);
2212: }
2213: my (%nonemptydirs,$possdirs);
2214: if ($numdirs > 1) {
2215: my @order;
2216: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
2217: if (ref($files{$key}) eq 'HASH') {
2218: my $shown = $key;
2219: if ($key eq '') {
2220: $shown = '/';
2221: }
2222: my @ordered = ();
2223: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$key}}))) {
2224: if ($only) {
2225: my ($ext) = ($file =~ /\.([^.]+)$/);
2226: unless ($possexts{lc($ext)}) {
2227: next;
2228: }
2229: }
2230: $selimport_menus{$key}->{'select2'}->{$file} = $file;
2231: push(@ordered,$file);
2232: }
2233: if (@ordered) {
2234: push(@order,$key);
2235: $nonemptydirs{$key} = 1;
2236: $selimport_menus{$key}->{'text'} = $shown;
2237: $selimport_menus{$key}->{'default'} = '';
2238: $selimport_menus{$key}->{'select2'}->{''} = '';
2239: $selimport_menus{$key}->{'order'} = \@ordered;
2240: }
2241: }
2242: }
2243: $possdirs = scalar(keys(%nonemptydirs));
2244: if ($possdirs > 1) {
2245: my @order = sort { lc($a) cmp lc($b) } (keys(%nonemptydirs));
2246: $output = $lt{'dire'}.
2247: &linked_select_forms($form,'<br />'.
2248: $lt{'fnam'},'',
2249: $firstselectname,$secondselectname,
2250: \%selimport_menus,\@order,
2251: $onchangefirst,'',$suffix).'<br />';
2252: } elsif ($possdirs == 1) {
2253: $singledir = (keys(%nonemptydirs))[0];
2254: if (ref($selimport_menus{$singledir}->{'order'}) eq 'ARRAY') {
2255: @singledirfiles = @{$selimport_menus{$singledir}->{'order'}};
2256: }
2257: delete($selimport_menus{$singledir});
2258: }
2259: } elsif ($numdirs == 1) {
2260: $singledir = (keys(%files))[0];
2261: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$singledir}}))) {
2262: if ($only) {
2263: my ($ext) = ($file =~ /\.([^.]+)$/);
2264: unless ($possexts{lc($ext)}) {
2265: next;
2266: }
2267: }
2268: push(@singledirfiles,$file);
2269: }
2270: if (@singledirfiles) {
2271: $possdirs == 1;
2272: }
2273: }
2274: if (($possdirs == 1) && (@singledirfiles)) {
2275: my $showdir = $singledir;
2276: if ($singledir eq '') {
2277: $showdir = '/';
2278: }
2279: $output = $lt{'dire'}.
2280: '<select name="'.$firstselectname.'">'.
2281: '<option value="'.$singledir.'">'.$showdir.'</option>'."\n".
2282: '</select><br />'.
2283: $lt{'fnam'}.'<select name="'.$secondselectname.'">'."\n".
2284: '<option value="" selected="selected">'.$lt{'se'}.'</option>'."\n";
2285: foreach my $file (@singledirfiles) {
2286: $output .= '<option value="'.$file.'">'.$file.'</option>'."\n";
2287: }
2288: $output .= '</select><br />'."\n";
2289: }
2290: return ($possdirs,$output);
2291: }
2292:
1.565 albertel 2293: =pod
2294:
1.256 matthew 2295: =head1 Excel and CSV file utility routines
2296:
2297: =cut
2298:
2299: ###############################################################
2300: ###############################################################
2301:
2302: =pod
2303:
1.1162 raeburn 2304: =over 4
2305:
1.648 raeburn 2306: =item * &csv_translate($text)
1.37 matthew 2307:
1.185 www 2308: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2309: format.
2310:
2311: =cut
2312:
1.180 matthew 2313: ###############################################################
2314: ###############################################################
1.37 matthew 2315: sub csv_translate {
2316: my $text = shift;
2317: $text =~ s/\"/\"\"/g;
1.209 albertel 2318: $text =~ s/\n/ /g;
1.37 matthew 2319: return $text;
2320: }
1.180 matthew 2321:
2322: ###############################################################
2323: ###############################################################
2324:
2325: =pod
2326:
1.648 raeburn 2327: =item * &define_excel_formats()
1.180 matthew 2328:
2329: Define some commonly used Excel cell formats.
2330:
2331: Currently supported formats:
2332:
2333: =over 4
2334:
2335: =item header
2336:
2337: =item bold
2338:
2339: =item h1
2340:
2341: =item h2
2342:
2343: =item h3
2344:
1.256 matthew 2345: =item h4
2346:
2347: =item i
2348:
1.180 matthew 2349: =item date
2350:
2351: =back
2352:
2353: Inputs: $workbook
2354:
2355: Returns: $format, a hash reference.
2356:
1.1057 foxr 2357:
1.180 matthew 2358: =cut
2359:
2360: ###############################################################
2361: ###############################################################
2362: sub define_excel_formats {
2363: my ($workbook) = @_;
2364: my $format;
2365: $format->{'header'} = $workbook->add_format(bold => 1,
2366: bottom => 1,
2367: align => 'center');
2368: $format->{'bold'} = $workbook->add_format(bold=>1);
2369: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2370: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2371: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2372: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2373: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2374: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2375: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2376: return $format;
2377: }
2378:
2379: ###############################################################
2380: ###############################################################
1.113 bowersj2 2381:
2382: =pod
2383:
1.648 raeburn 2384: =item * &create_workbook()
1.255 matthew 2385:
2386: Create an Excel worksheet. If it fails, output message on the
2387: request object and return undefs.
2388:
2389: Inputs: Apache request object
2390:
2391: Returns (undef) on failure,
2392: Excel worksheet object, scalar with filename, and formats
2393: from &Apache::loncommon::define_excel_formats on success
2394:
2395: =cut
2396:
2397: ###############################################################
2398: ###############################################################
2399: sub create_workbook {
2400: my ($r) = @_;
2401: #
2402: # Create the excel spreadsheet
2403: my $filename = '/prtspool/'.
1.258 albertel 2404: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2405: time.'_'.rand(1000000000).'.xls';
2406: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2407: if (! defined($workbook)) {
2408: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2409: $r->print(
2410: '<p class="LC_error">'
2411: .&mt('Problems occurred in creating the new Excel file.')
2412: .' '.&mt('This error has been logged.')
2413: .' '.&mt('Please alert your LON-CAPA administrator.')
2414: .'</p>'
2415: );
1.255 matthew 2416: return (undef);
2417: }
2418: #
1.1014 foxr 2419: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2420: #
2421: my $format = &Apache::loncommon::define_excel_formats($workbook);
2422: return ($workbook,$filename,$format);
2423: }
2424:
2425: ###############################################################
2426: ###############################################################
2427:
2428: =pod
2429:
1.648 raeburn 2430: =item * &create_text_file()
1.113 bowersj2 2431:
1.542 raeburn 2432: Create a file to write to and eventually make available to the user.
1.256 matthew 2433: If file creation fails, outputs an error message on the request object and
2434: return undefs.
1.113 bowersj2 2435:
1.256 matthew 2436: Inputs: Apache request object, and file suffix
1.113 bowersj2 2437:
1.256 matthew 2438: Returns (undef) on failure,
2439: Filehandle and filename on success.
1.113 bowersj2 2440:
2441: =cut
2442:
1.256 matthew 2443: ###############################################################
2444: ###############################################################
2445: sub create_text_file {
2446: my ($r,$suffix) = @_;
2447: if (! defined($suffix)) { $suffix = 'txt'; };
2448: my $fh;
2449: my $filename = '/prtspool/'.
1.258 albertel 2450: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2451: time.'_'.rand(1000000000).'.'.$suffix;
2452: $fh = Apache::File->new('>/home/httpd'.$filename);
2453: if (! defined($fh)) {
2454: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2455: $r->print(
2456: '<p class="LC_error">'
2457: .&mt('Problems occurred in creating the output file.')
2458: .' '.&mt('This error has been logged.')
2459: .' '.&mt('Please alert your LON-CAPA administrator.')
2460: .'</p>'
2461: );
1.113 bowersj2 2462: }
1.256 matthew 2463: return ($fh,$filename)
1.113 bowersj2 2464: }
2465:
2466:
1.256 matthew 2467: =pod
1.113 bowersj2 2468:
2469: =back
2470:
2471: =cut
1.37 matthew 2472:
2473: ###############################################################
1.33 matthew 2474: ## Home server <option> list generating code ##
2475: ###############################################################
1.35 matthew 2476:
1.169 www 2477: # ------------------------------------------
2478:
2479: sub domain_select {
2480: my ($name,$value,$multiple)=@_;
2481: my %domains=map {
1.514 albertel 2482: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2483: } &Apache::lonnet::all_domains();
1.169 www 2484: if ($multiple) {
2485: $domains{''}=&mt('Any domain');
1.550 albertel 2486: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2487: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2488: } else {
1.550 albertel 2489: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2490: return &select_form($name,$value,\%domains);
1.169 www 2491: }
2492: }
2493:
1.282 albertel 2494: #-------------------------------------------
2495:
2496: =pod
2497:
1.519 raeburn 2498: =head1 Routines for form select boxes
2499:
2500: =over 4
2501:
1.648 raeburn 2502: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2503:
2504: Returns a string containing a <select> element int multiple mode
2505:
2506:
2507: Args:
2508: $name - name of the <select> element
1.506 raeburn 2509: $value - scalar or array ref of values that should already be selected
1.282 albertel 2510: $size - number of rows long the select element is
1.283 albertel 2511: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2512: (shown text should already have been &mt())
1.506 raeburn 2513: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2514:
1.282 albertel 2515: =cut
2516:
2517: #-------------------------------------------
1.169 www 2518: sub multiple_select_form {
1.284 albertel 2519: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2520: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2521: my $output='';
1.191 matthew 2522: if (! defined($size)) {
2523: $size = 4;
1.283 albertel 2524: if (scalar(keys(%$hash))<4) {
2525: $size = scalar(keys(%$hash));
1.191 matthew 2526: }
2527: }
1.734 bisitz 2528: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2529: my @order;
1.506 raeburn 2530: if (ref($order) eq 'ARRAY') {
2531: @order = @{$order};
2532: } else {
2533: @order = sort(keys(%$hash));
1.501 banghart 2534: }
2535: if (exists($$hash{'select_form_order'})) {
2536: @order = @{$$hash{'select_form_order'}};
2537: }
2538:
1.284 albertel 2539: foreach my $key (@order) {
1.356 albertel 2540: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2541: $output.='selected="selected" ' if ($selected{$key});
2542: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2543: }
2544: $output.="</select>\n";
2545: return $output;
2546: }
2547:
1.88 www 2548: #-------------------------------------------
2549:
2550: =pod
2551:
1.1254 raeburn 2552: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2553:
2554: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2555: allow a user to select options from a ref to a hash containing:
2556: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2557: a javascript onchange item, e.g., onchange="this.form.submit();".
2558: An optional arg -- $readonly -- if true will cause the select form
2559: to be disabled, e.g., for the case where an instructor has a section-
2560: specific role, and is viewing/modifying parameters.
1.970 raeburn 2561:
1.88 www 2562: See lonrights.pm for an example invocation and use.
2563:
2564: =cut
2565:
2566: #-------------------------------------------
2567: sub select_form {
1.1228 raeburn 2568: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2569: return unless (ref($hashref) eq 'HASH');
2570: if ($onchange) {
2571: $onchange = ' onchange="'.$onchange.'"';
2572: }
1.1228 raeburn 2573: my $disabled;
2574: if ($readonly) {
2575: $disabled = ' disabled="disabled"';
2576: }
2577: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2578: my @keys;
1.970 raeburn 2579: if (exists($hashref->{'select_form_order'})) {
2580: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2581: } else {
1.970 raeburn 2582: @keys=sort(keys(%{$hashref}));
1.128 albertel 2583: }
1.356 albertel 2584: foreach my $key (@keys) {
2585: $selectform.=
2586: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2587: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2588: ">".$hashref->{$key}."</option>\n";
1.88 www 2589: }
2590: $selectform.="</select>";
2591: return $selectform;
2592: }
2593:
1.475 www 2594: # For display filters
2595:
2596: sub display_filter {
1.1074 raeburn 2597: my ($context) = @_;
1.475 www 2598: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2599: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2600: my $phraseinput = 'hidden';
2601: my $includeinput = 'hidden';
2602: my ($checked,$includetypestext);
2603: if ($env{'form.displayfilter'} eq 'containing') {
2604: $phraseinput = 'text';
2605: if ($context eq 'parmslog') {
2606: $includeinput = 'checkbox';
2607: if ($env{'form.includetypes'}) {
2608: $checked = ' checked="checked"';
2609: }
2610: $includetypestext = &mt('Include parameter types');
2611: }
2612: } else {
2613: $includetypestext = ' ';
2614: }
2615: my ($additional,$secondid,$thirdid);
2616: if ($context eq 'parmslog') {
2617: $additional =
2618: '<label><input type="'.$includeinput.'" name="includetypes"'.
2619: $checked.' name="includetypes" value="1" id="includetypes" />'.
2620: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2621: '</label>';
2622: $secondid = 'includetypes';
2623: $thirdid = 'includetypestext';
2624: }
2625: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2626: '$secondid','$thirdid')";
2627: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2628: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2629: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2630: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2631: &mt('Filter: [_1]',
1.477 www 2632: &select_form($env{'form.displayfilter'},
2633: 'displayfilter',
1.970 raeburn 2634: {'currentfolder' => 'Current folder/page',
1.477 www 2635: 'containing' => 'Containing phrase',
1.1074 raeburn 2636: 'none' => 'None'},$onchange)).' '.
2637: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2638: &HTML::Entities::encode($env{'form.containingphrase'}).
2639: '" />'.$additional;
2640: }
2641:
2642: sub display_filter_js {
2643: my $includetext = &mt('Include parameter types');
2644: return <<"ENDJS";
2645:
2646: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2647: var firstType = 'hidden';
2648: if (setter.options[setter.selectedIndex].value == 'containing') {
2649: firstType = 'text';
2650: }
2651: firstObject = document.getElementById(firstid);
2652: if (typeof(firstObject) == 'object') {
2653: if (firstObject.type != firstType) {
2654: changeInputType(firstObject,firstType);
2655: }
2656: }
2657: if (context == 'parmslog') {
2658: var secondType = 'hidden';
2659: if (firstType == 'text') {
2660: secondType = 'checkbox';
2661: }
2662: secondObject = document.getElementById(secondid);
2663: if (typeof(secondObject) == 'object') {
2664: if (secondObject.type != secondType) {
2665: changeInputType(secondObject,secondType);
2666: }
2667: }
2668: var textItem = document.getElementById(thirdid);
2669: var currtext = textItem.innerHTML;
2670: var newtext;
2671: if (firstType == 'text') {
2672: newtext = '$includetext';
2673: } else {
2674: newtext = ' ';
2675: }
2676: if (currtext != newtext) {
2677: textItem.innerHTML = newtext;
2678: }
2679: }
2680: return;
2681: }
2682:
2683: function changeInputType(oldObject,newType) {
2684: var newObject = document.createElement('input');
2685: newObject.type = newType;
2686: if (oldObject.size) {
2687: newObject.size = oldObject.size;
2688: }
2689: if (oldObject.value) {
2690: newObject.value = oldObject.value;
2691: }
2692: if (oldObject.name) {
2693: newObject.name = oldObject.name;
2694: }
2695: if (oldObject.id) {
2696: newObject.id = oldObject.id;
2697: }
2698: oldObject.parentNode.replaceChild(newObject,oldObject);
2699: return;
2700: }
2701:
2702: ENDJS
1.475 www 2703: }
2704:
1.167 www 2705: sub gradeleveldescription {
2706: my $gradelevel=shift;
2707: my %gradelevels=(0 => 'Not specified',
2708: 1 => 'Grade 1',
2709: 2 => 'Grade 2',
2710: 3 => 'Grade 3',
2711: 4 => 'Grade 4',
2712: 5 => 'Grade 5',
2713: 6 => 'Grade 6',
2714: 7 => 'Grade 7',
2715: 8 => 'Grade 8',
2716: 9 => 'Grade 9',
2717: 10 => 'Grade 10',
2718: 11 => 'Grade 11',
2719: 12 => 'Grade 12',
2720: 13 => 'Grade 13',
2721: 14 => '100 Level',
2722: 15 => '200 Level',
2723: 16 => '300 Level',
2724: 17 => '400 Level',
2725: 18 => 'Graduate Level');
2726: return &mt($gradelevels{$gradelevel});
2727: }
2728:
1.163 www 2729: sub select_level_form {
2730: my ($deflevel,$name)=@_;
2731: unless ($deflevel) { $deflevel=0; }
1.167 www 2732: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2733: for (my $i=0; $i<=18; $i++) {
2734: $selectform.="<option value=\"$i\" ".
1.253 albertel 2735: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2736: ">".&gradeleveldescription($i)."</option>\n";
2737: }
2738: $selectform.="</select>";
2739: return $selectform;
1.163 www 2740: }
1.167 www 2741:
1.35 matthew 2742: #-------------------------------------------
2743:
1.45 matthew 2744: =pod
2745:
1.1256 raeburn 2746: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2747:
2748: Returns a string containing a <select name='$name' size='1'> form to
2749: allow a user to select the domain to preform an operation in.
2750: See loncreateuser.pm for an example invocation and use.
2751:
1.90 www 2752: If the $includeempty flag is set, it also includes an empty choice ("no domain
2753: selected");
2754:
1.743 raeburn 2755: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2756:
1.910 raeburn 2757: 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.
2758:
1.1121 raeburn 2759: The optional $incdoms is a reference to an array of domains which will be the only available options.
2760:
2761: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2762:
1.1256 raeburn 2763: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
2764:
1.35 matthew 2765: =cut
2766:
2767: #-------------------------------------------
1.34 matthew 2768: sub select_dom_form {
1.1256 raeburn 2769: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2770: if ($onchange) {
1.874 raeburn 2771: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2772: }
1.1256 raeburn 2773: if ($disabled) {
2774: $disabled = ' disabled="disabled"';
2775: }
1.1121 raeburn 2776: my (@domains,%exclude);
1.910 raeburn 2777: if (ref($incdoms) eq 'ARRAY') {
2778: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2779: } else {
2780: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2781: }
1.90 www 2782: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2783: if (ref($excdoms) eq 'ARRAY') {
2784: map { $exclude{$_} = 1; } @{$excdoms};
2785: }
1.1256 raeburn 2786: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2787: foreach my $dom (@domains) {
1.1121 raeburn 2788: next if ($exclude{$dom});
1.356 albertel 2789: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2790: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2791: if ($showdomdesc) {
2792: if ($dom ne '') {
2793: my $domdesc = &Apache::lonnet::domain($dom,'description');
2794: if ($domdesc ne '') {
2795: $selectdomain .= ' ('.$domdesc.')';
2796: }
2797: }
2798: }
2799: $selectdomain .= "</option>\n";
1.34 matthew 2800: }
2801: $selectdomain.="</select>";
2802: return $selectdomain;
2803: }
2804:
1.35 matthew 2805: #-------------------------------------------
2806:
1.45 matthew 2807: =pod
2808:
1.648 raeburn 2809: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2810:
1.586 raeburn 2811: input: 4 arguments (two required, two optional) -
2812: $domain - domain of new user
2813: $name - name of form element
2814: $default - Value of 'default' causes a default item to be first
2815: option, and selected by default.
2816: $hide - Value of 'hide' causes hiding of the name of the server,
2817: if 1 server found, or default, if 0 found.
1.594 raeburn 2818: output: returns 2 items:
1.586 raeburn 2819: (a) form element which contains either:
2820: (i) <select name="$name">
2821: <option value="$hostid1">$hostid $servers{$hostid}</option>
2822: <option value="$hostid2">$hostid $servers{$hostid}</option>
2823: </select>
2824: form item if there are multiple library servers in $domain, or
2825: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2826: if there is only one library server in $domain.
2827:
2828: (b) number of library servers found.
2829:
2830: See loncreateuser.pm for example of use.
1.35 matthew 2831:
2832: =cut
2833:
2834: #-------------------------------------------
1.586 raeburn 2835: sub home_server_form_item {
2836: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2837: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2838: my $result;
2839: my $numlib = keys(%servers);
2840: if ($numlib > 1) {
2841: $result .= '<select name="'.$name.'" />'."\n";
2842: if ($default) {
1.804 bisitz 2843: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2844: '</option>'."\n";
2845: }
2846: foreach my $hostid (sort(keys(%servers))) {
2847: $result.= '<option value="'.$hostid.'">'.
2848: $hostid.' '.$servers{$hostid}."</option>\n";
2849: }
2850: $result .= '</select>'."\n";
2851: } elsif ($numlib == 1) {
2852: my $hostid;
2853: foreach my $item (keys(%servers)) {
2854: $hostid = $item;
2855: }
2856: $result .= '<input type="hidden" name="'.$name.'" value="'.
2857: $hostid.'" />';
2858: if (!$hide) {
2859: $result .= $hostid.' '.$servers{$hostid};
2860: }
2861: $result .= "\n";
2862: } elsif ($default) {
2863: $result .= '<input type="hidden" name="'.$name.
2864: '" value="default" />';
2865: if (!$hide) {
2866: $result .= &mt('default');
2867: }
2868: $result .= "\n";
1.33 matthew 2869: }
1.586 raeburn 2870: return ($result,$numlib);
1.33 matthew 2871: }
1.112 bowersj2 2872:
2873: =pod
2874:
1.534 albertel 2875: =back
2876:
1.112 bowersj2 2877: =cut
1.87 matthew 2878:
2879: ###############################################################
1.112 bowersj2 2880: ## Decoding User Agent ##
1.87 matthew 2881: ###############################################################
2882:
2883: =pod
2884:
1.112 bowersj2 2885: =head1 Decoding the User Agent
2886:
2887: =over 4
2888:
2889: =item * &decode_user_agent()
1.87 matthew 2890:
2891: Inputs: $r
2892:
2893: Outputs:
2894:
2895: =over 4
2896:
1.112 bowersj2 2897: =item * $httpbrowser
1.87 matthew 2898:
1.112 bowersj2 2899: =item * $clientbrowser
1.87 matthew 2900:
1.112 bowersj2 2901: =item * $clientversion
1.87 matthew 2902:
1.112 bowersj2 2903: =item * $clientmathml
1.87 matthew 2904:
1.112 bowersj2 2905: =item * $clientunicode
1.87 matthew 2906:
1.112 bowersj2 2907: =item * $clientos
1.87 matthew 2908:
1.1137 raeburn 2909: =item * $clientmobile
2910:
1.1141 raeburn 2911: =item * $clientinfo
2912:
1.1194 raeburn 2913: =item * $clientosversion
2914:
1.87 matthew 2915: =back
2916:
1.157 matthew 2917: =back
2918:
1.87 matthew 2919: =cut
2920:
2921: ###############################################################
2922: ###############################################################
2923: sub decode_user_agent {
1.247 albertel 2924: my ($r)=@_;
1.87 matthew 2925: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2926: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2927: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2928: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2929: my $clientbrowser='unknown';
2930: my $clientversion='0';
2931: my $clientmathml='';
2932: my $clientunicode='0';
1.1137 raeburn 2933: my $clientmobile=0;
1.1194 raeburn 2934: my $clientosversion='';
1.87 matthew 2935: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2936: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2937: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2938: $clientbrowser=$bname;
2939: $httpbrowser=~/$vreg/i;
2940: $clientversion=$1;
2941: $clientmathml=($clientversion>=$minv);
2942: $clientunicode=($clientversion>=$univ);
2943: }
2944: }
2945: my $clientos='unknown';
1.1141 raeburn 2946: my $clientinfo;
1.87 matthew 2947: if (($httpbrowser=~/linux/i) ||
2948: ($httpbrowser=~/unix/i) ||
2949: ($httpbrowser=~/ux/i) ||
2950: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2951: if (($httpbrowser=~/vax/i) ||
2952: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2953: if ($httpbrowser=~/next/i) { $clientos='next'; }
2954: if (($httpbrowser=~/mac/i) ||
2955: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2956: if ($httpbrowser=~/win/i) {
2957: $clientos='win';
2958: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2959: $clientosversion = $1;
2960: }
2961: }
1.87 matthew 2962: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2963: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2964: $clientmobile=lc($1);
2965: }
1.1141 raeburn 2966: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2967: $clientinfo = 'firefox-'.$1;
2968: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2969: $clientinfo = 'chromeframe-'.$1;
2970: }
1.87 matthew 2971: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 2972: $clientunicode,$clientos,$clientmobile,$clientinfo,
2973: $clientosversion);
1.87 matthew 2974: }
2975:
1.32 matthew 2976: ###############################################################
2977: ## Authentication changing form generation subroutines ##
2978: ###############################################################
2979: ##
2980: ## All of the authform_xxxxxxx subroutines take their inputs in a
2981: ## hash, and have reasonable default values.
2982: ##
2983: ## formname = the name given in the <form> tag.
1.35 matthew 2984: #-------------------------------------------
2985:
1.45 matthew 2986: =pod
2987:
1.112 bowersj2 2988: =head1 Authentication Routines
2989:
2990: =over 4
2991:
1.648 raeburn 2992: =item * &authform_xxxxxx()
1.35 matthew 2993:
2994: The authform_xxxxxx subroutines provide javascript and html forms which
2995: handle some of the conveniences required for authentication forms.
2996: This is not an optimal method, but it works.
2997:
2998: =over 4
2999:
1.112 bowersj2 3000: =item * authform_header
1.35 matthew 3001:
1.112 bowersj2 3002: =item * authform_authorwarning
1.35 matthew 3003:
1.112 bowersj2 3004: =item * authform_nochange
1.35 matthew 3005:
1.112 bowersj2 3006: =item * authform_kerberos
1.35 matthew 3007:
1.112 bowersj2 3008: =item * authform_internal
1.35 matthew 3009:
1.112 bowersj2 3010: =item * authform_filesystem
1.35 matthew 3011:
3012: =back
3013:
1.648 raeburn 3014: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3015:
1.35 matthew 3016: =cut
3017:
3018: #-------------------------------------------
1.32 matthew 3019: sub authform_header{
3020: my %in = (
3021: formname => 'cu',
1.80 albertel 3022: kerb_def_dom => '',
1.32 matthew 3023: @_,
3024: );
3025: $in{'formname'} = 'document.' . $in{'formname'};
3026: my $result='';
1.80 albertel 3027:
3028: #---------------------------------------------- Code for upper case translation
3029: my $Javascript_toUpperCase;
3030: unless ($in{kerb_def_dom}) {
3031: $Javascript_toUpperCase =<<"END";
3032: switch (choice) {
3033: case 'krb': currentform.elements[choicearg].value =
3034: currentform.elements[choicearg].value.toUpperCase();
3035: break;
3036: default:
3037: }
3038: END
3039: } else {
3040: $Javascript_toUpperCase = "";
3041: }
3042:
1.165 raeburn 3043: my $radioval = "'nochange'";
1.591 raeburn 3044: if (defined($in{'curr_authtype'})) {
3045: if ($in{'curr_authtype'} ne '') {
3046: $radioval = "'".$in{'curr_authtype'}."arg'";
3047: }
1.174 matthew 3048: }
1.165 raeburn 3049: my $argfield = 'null';
1.591 raeburn 3050: if (defined($in{'mode'})) {
1.165 raeburn 3051: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3052: if (defined($in{'curr_autharg'})) {
3053: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3054: $argfield = "'$in{'curr_autharg'}'";
3055: }
3056: }
3057: }
3058: }
3059:
1.32 matthew 3060: $result.=<<"END";
3061: var current = new Object();
1.165 raeburn 3062: current.radiovalue = $radioval;
3063: current.argfield = $argfield;
1.32 matthew 3064:
3065: function changed_radio(choice,currentform) {
3066: var choicearg = choice + 'arg';
3067: // If a radio button in changed, we need to change the argfield
3068: if (current.radiovalue != choice) {
3069: current.radiovalue = choice;
3070: if (current.argfield != null) {
3071: currentform.elements[current.argfield].value = '';
3072: }
3073: if (choice == 'nochange') {
3074: current.argfield = null;
3075: } else {
3076: current.argfield = choicearg;
3077: switch(choice) {
3078: case 'krb':
3079: currentform.elements[current.argfield].value =
3080: "$in{'kerb_def_dom'}";
3081: break;
3082: default:
3083: break;
3084: }
3085: }
3086: }
3087: return;
3088: }
1.22 www 3089:
1.32 matthew 3090: function changed_text(choice,currentform) {
3091: var choicearg = choice + 'arg';
3092: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3093: $Javascript_toUpperCase
1.32 matthew 3094: // clear old field
3095: if ((current.argfield != choicearg) && (current.argfield != null)) {
3096: currentform.elements[current.argfield].value = '';
3097: }
3098: current.argfield = choicearg;
3099: }
3100: set_auth_radio_buttons(choice,currentform);
3101: return;
1.20 www 3102: }
1.32 matthew 3103:
3104: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3105: var numauthchoices = currentform.login.length;
3106: if (typeof numauthchoices == "undefined") {
3107: return;
3108: }
1.32 matthew 3109: var i=0;
1.986 raeburn 3110: while (i < numauthchoices) {
1.32 matthew 3111: if (currentform.login[i].value == newvalue) { break; }
3112: i++;
3113: }
1.986 raeburn 3114: if (i == numauthchoices) {
1.32 matthew 3115: return;
3116: }
3117: current.radiovalue = newvalue;
3118: currentform.login[i].checked = true;
3119: return;
3120: }
3121: END
3122: return $result;
3123: }
3124:
1.1106 raeburn 3125: sub authform_authorwarning {
1.32 matthew 3126: my $result='';
1.144 matthew 3127: $result='<i>'.
3128: &mt('As a general rule, only authors or co-authors should be '.
3129: 'filesystem authenticated '.
3130: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3131: return $result;
3132: }
3133:
1.1106 raeburn 3134: sub authform_nochange {
1.32 matthew 3135: my %in = (
3136: formname => 'document.cu',
3137: kerb_def_dom => 'MSU.EDU',
3138: @_,
3139: );
1.1106 raeburn 3140: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3141: my $result;
1.1104 raeburn 3142: if (!$authnum) {
1.1105 raeburn 3143: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3144: } else {
3145: $result = '<label>'.&mt('[_1] Do not change login data',
3146: '<input type="radio" name="login" value="nochange" '.
3147: 'checked="checked" onclick="'.
1.281 albertel 3148: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3149: '</label>';
1.586 raeburn 3150: }
1.32 matthew 3151: return $result;
3152: }
3153:
1.591 raeburn 3154: sub authform_kerberos {
1.32 matthew 3155: my %in = (
3156: formname => 'document.cu',
3157: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3158: kerb_def_auth => 'krb4',
1.32 matthew 3159: @_,
3160: );
1.586 raeburn 3161: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3162: $autharg,$jscall,$disabled);
1.1106 raeburn 3163: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3164: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3165: $check5 = ' checked="checked"';
1.80 albertel 3166: } else {
1.772 bisitz 3167: $check4 = ' checked="checked"';
1.80 albertel 3168: }
1.1259 raeburn 3169: if ($in{'readonly'}) {
3170: $disabled = ' disabled="disabled"';
3171: }
1.165 raeburn 3172: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3173: if (defined($in{'curr_authtype'})) {
3174: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3175: $krbcheck = ' checked="checked"';
1.623 raeburn 3176: if (defined($in{'mode'})) {
3177: if ($in{'mode'} eq 'modifyuser') {
3178: $krbcheck = '';
3179: }
3180: }
1.591 raeburn 3181: if (defined($in{'curr_kerb_ver'})) {
3182: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3183: $check5 = ' checked="checked"';
1.591 raeburn 3184: $check4 = '';
3185: } else {
1.772 bisitz 3186: $check4 = ' checked="checked"';
1.591 raeburn 3187: $check5 = '';
3188: }
1.586 raeburn 3189: }
1.591 raeburn 3190: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3191: $krbarg = $in{'curr_autharg'};
3192: }
1.586 raeburn 3193: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3194: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3195: $result =
3196: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3197: $in{'curr_autharg'},$krbver);
3198: } else {
3199: $result =
3200: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3201: }
3202: return $result;
3203: }
3204: }
3205: } else {
3206: if ($authnum == 1) {
1.784 bisitz 3207: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3208: }
3209: }
1.586 raeburn 3210: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3211: return;
1.587 raeburn 3212: } elsif ($authtype eq '') {
1.591 raeburn 3213: if (defined($in{'mode'})) {
1.587 raeburn 3214: if ($in{'mode'} eq 'modifycourse') {
3215: if ($authnum == 1) {
1.1259 raeburn 3216: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3217: }
3218: }
3219: }
1.586 raeburn 3220: }
3221: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3222: if ($authtype eq '') {
3223: $authtype = '<input type="radio" name="login" value="krb" '.
3224: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3225: $krbcheck.$disabled.' />';
1.586 raeburn 3226: }
3227: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3228: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3229: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3230: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3231: $in{'curr_authtype'} eq 'krb4')) {
3232: $result .= &mt
1.144 matthew 3233: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3234: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3235: '<label>'.$authtype,
1.281 albertel 3236: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3237: 'value="'.$krbarg.'" '.
1.1259 raeburn 3238: 'onchange="'.$jscall.'"'.$disabled.' />',
3239: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3240: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3241: '</label>');
1.586 raeburn 3242: } elsif ($can_assign{'krb4'}) {
3243: $result .= &mt
3244: ('[_1] Kerberos authenticated with domain [_2] '.
3245: '[_3] Version 4 [_4]',
3246: '<label>'.$authtype,
3247: '</label><input type="text" size="10" name="krbarg" '.
3248: 'value="'.$krbarg.'" '.
1.1259 raeburn 3249: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3250: '<label><input type="hidden" name="krbver" value="4" />',
3251: '</label>');
3252: } elsif ($can_assign{'krb5'}) {
3253: $result .= &mt
3254: ('[_1] Kerberos authenticated with domain [_2] '.
3255: '[_3] Version 5 [_4]',
3256: '<label>'.$authtype,
3257: '</label><input type="text" size="10" name="krbarg" '.
3258: 'value="'.$krbarg.'" '.
1.1259 raeburn 3259: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3260: '<label><input type="hidden" name="krbver" value="5" />',
3261: '</label>');
3262: }
1.32 matthew 3263: return $result;
3264: }
3265:
1.1106 raeburn 3266: sub authform_internal {
1.586 raeburn 3267: my %in = (
1.32 matthew 3268: formname => 'document.cu',
3269: kerb_def_dom => 'MSU.EDU',
3270: @_,
3271: );
1.1259 raeburn 3272: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3273: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3274: if ($in{'readonly'}) {
3275: $disabled = ' disabled="disabled"';
3276: }
1.591 raeburn 3277: if (defined($in{'curr_authtype'})) {
3278: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3279: if ($can_assign{'int'}) {
1.772 bisitz 3280: $intcheck = 'checked="checked" ';
1.623 raeburn 3281: if (defined($in{'mode'})) {
3282: if ($in{'mode'} eq 'modifyuser') {
3283: $intcheck = '';
3284: }
3285: }
1.591 raeburn 3286: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3287: $intarg = $in{'curr_autharg'};
3288: }
3289: } else {
3290: $result = &mt('Currently internally authenticated.');
3291: return $result;
1.165 raeburn 3292: }
3293: }
1.586 raeburn 3294: } else {
3295: if ($authnum == 1) {
1.784 bisitz 3296: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3297: }
3298: }
3299: if (!$can_assign{'int'}) {
3300: return;
1.587 raeburn 3301: } elsif ($authtype eq '') {
1.591 raeburn 3302: if (defined($in{'mode'})) {
1.587 raeburn 3303: if ($in{'mode'} eq 'modifycourse') {
3304: if ($authnum == 1) {
1.1259 raeburn 3305: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3306: }
3307: }
3308: }
1.165 raeburn 3309: }
1.586 raeburn 3310: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3311: if ($authtype eq '') {
3312: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3313: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3314: }
1.605 bisitz 3315: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3316: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3317: $result = &mt
1.144 matthew 3318: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3319: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3320: $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 3321: return $result;
3322: }
3323:
1.1104 raeburn 3324: sub authform_local {
1.32 matthew 3325: my %in = (
3326: formname => 'document.cu',
3327: kerb_def_dom => 'MSU.EDU',
3328: @_,
3329: );
1.1259 raeburn 3330: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3331: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3332: if ($in{'readonly'}) {
3333: $disabled = ' disabled="disabled"';
3334: }
1.591 raeburn 3335: if (defined($in{'curr_authtype'})) {
3336: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3337: if ($can_assign{'loc'}) {
1.772 bisitz 3338: $loccheck = 'checked="checked" ';
1.623 raeburn 3339: if (defined($in{'mode'})) {
3340: if ($in{'mode'} eq 'modifyuser') {
3341: $loccheck = '';
3342: }
3343: }
1.591 raeburn 3344: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3345: $locarg = $in{'curr_autharg'};
3346: }
3347: } else {
3348: $result = &mt('Currently using local (institutional) authentication.');
3349: return $result;
1.165 raeburn 3350: }
3351: }
1.586 raeburn 3352: } else {
3353: if ($authnum == 1) {
1.784 bisitz 3354: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3355: }
3356: }
3357: if (!$can_assign{'loc'}) {
3358: return;
1.587 raeburn 3359: } elsif ($authtype eq '') {
1.591 raeburn 3360: if (defined($in{'mode'})) {
1.587 raeburn 3361: if ($in{'mode'} eq 'modifycourse') {
3362: if ($authnum == 1) {
1.1259 raeburn 3363: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3364: }
3365: }
3366: }
1.165 raeburn 3367: }
1.586 raeburn 3368: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3369: if ($authtype eq '') {
3370: $authtype = '<input type="radio" name="login" value="loc" '.
3371: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3372: $jscall.'"'.$disabled.' />';
1.586 raeburn 3373: }
3374: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3375: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3376: $result = &mt('[_1] Local Authentication with argument [_2]',
3377: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3378: return $result;
3379: }
3380:
1.1106 raeburn 3381: sub authform_filesystem {
1.32 matthew 3382: my %in = (
3383: formname => 'document.cu',
3384: kerb_def_dom => 'MSU.EDU',
3385: @_,
3386: );
1.1259 raeburn 3387: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3388: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3389: if ($in{'readonly'}) {
3390: $disabled = ' disabled="disabled"';
3391: }
1.591 raeburn 3392: if (defined($in{'curr_authtype'})) {
3393: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3394: if ($can_assign{'fsys'}) {
1.772 bisitz 3395: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3396: if (defined($in{'mode'})) {
3397: if ($in{'mode'} eq 'modifyuser') {
3398: $fsyscheck = '';
3399: }
3400: }
1.586 raeburn 3401: } else {
3402: $result = &mt('Currently Filesystem Authenticated.');
3403: return $result;
1.1259 raeburn 3404: }
1.586 raeburn 3405: }
3406: } else {
3407: if ($authnum == 1) {
1.784 bisitz 3408: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3409: }
3410: }
3411: if (!$can_assign{'fsys'}) {
3412: return;
1.587 raeburn 3413: } elsif ($authtype eq '') {
1.591 raeburn 3414: if (defined($in{'mode'})) {
1.587 raeburn 3415: if ($in{'mode'} eq 'modifycourse') {
3416: if ($authnum == 1) {
1.1259 raeburn 3417: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3418: }
3419: }
3420: }
1.586 raeburn 3421: }
3422: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3423: if ($authtype eq '') {
3424: $authtype = '<input type="radio" name="login" value="fsys" '.
3425: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3426: $jscall.'"'.$disabled.' />';
1.586 raeburn 3427: }
3428: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3429: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3430: $result = &mt
1.144 matthew 3431: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 3432: '<label><input type="radio" name="login" value="fsys" '.
1.1259 raeburn 3433: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />',
1.605 bisitz 3434: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.1259 raeburn 3435: 'onchange="'.$jscall.'"'.$disabled.' />');
1.32 matthew 3436: return $result;
3437: }
3438:
1.586 raeburn 3439: sub get_assignable_auth {
3440: my ($dom) = @_;
3441: if ($dom eq '') {
3442: $dom = $env{'request.role.domain'};
3443: }
3444: my %can_assign = (
3445: krb4 => 1,
3446: krb5 => 1,
3447: int => 1,
3448: loc => 1,
3449: );
3450: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3451: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3452: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3453: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3454: my $context;
3455: if ($env{'request.role'} =~ /^au/) {
3456: $context = 'author';
1.1259 raeburn 3457: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3458: $context = 'domain';
3459: } elsif ($env{'request.course.id'}) {
3460: $context = 'course';
3461: }
3462: if ($context) {
3463: if (ref($authhash->{$context}) eq 'HASH') {
3464: %can_assign = %{$authhash->{$context}};
3465: }
3466: }
3467: }
3468: }
3469: my $authnum = 0;
3470: foreach my $key (keys(%can_assign)) {
3471: if ($can_assign{$key}) {
3472: $authnum ++;
3473: }
3474: }
3475: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3476: $authnum --;
3477: }
3478: return ($authnum,%can_assign);
3479: }
3480:
1.80 albertel 3481: ###############################################################
3482: ## Get Kerberos Defaults for Domain ##
3483: ###############################################################
3484: ##
3485: ## Returns default kerberos version and an associated argument
3486: ## as listed in file domain.tab. If not listed, provides
3487: ## appropriate default domain and kerberos version.
3488: ##
3489: #-------------------------------------------
3490:
3491: =pod
3492:
1.648 raeburn 3493: =item * &get_kerberos_defaults()
1.80 albertel 3494:
3495: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3496: version and domain. If not found, it defaults to version 4 and the
3497: domain of the server.
1.80 albertel 3498:
1.648 raeburn 3499: =over 4
3500:
1.80 albertel 3501: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3502:
1.648 raeburn 3503: =back
3504:
3505: =back
3506:
1.80 albertel 3507: =cut
3508:
3509: #-------------------------------------------
3510: sub get_kerberos_defaults {
3511: my $domain=shift;
1.641 raeburn 3512: my ($krbdef,$krbdefdom);
3513: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3514: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3515: $krbdef = $domdefaults{'auth_def'};
3516: $krbdefdom = $domdefaults{'auth_arg_def'};
3517: } else {
1.80 albertel 3518: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3519: my $krbdefdom=$1;
3520: $krbdefdom=~tr/a-z/A-Z/;
3521: $krbdef = "krb4";
3522: }
3523: return ($krbdef,$krbdefdom);
3524: }
1.112 bowersj2 3525:
1.32 matthew 3526:
1.46 matthew 3527: ###############################################################
3528: ## Thesaurus Functions ##
3529: ###############################################################
1.20 www 3530:
1.46 matthew 3531: =pod
1.20 www 3532:
1.112 bowersj2 3533: =head1 Thesaurus Functions
3534:
3535: =over 4
3536:
1.648 raeburn 3537: =item * &initialize_keywords()
1.46 matthew 3538:
3539: Initializes the package variable %Keywords if it is empty. Uses the
3540: package variable $thesaurus_db_file.
3541:
3542: =cut
3543:
3544: ###################################################
3545:
3546: sub initialize_keywords {
3547: return 1 if (scalar keys(%Keywords));
3548: # If we are here, %Keywords is empty, so fill it up
3549: # Make sure the file we need exists...
3550: if (! -e $thesaurus_db_file) {
3551: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3552: " failed because it does not exist");
3553: return 0;
3554: }
3555: # Set up the hash as a database
3556: my %thesaurus_db;
3557: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3558: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3559: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3560: $thesaurus_db_file);
3561: return 0;
3562: }
3563: # Get the average number of appearances of a word.
3564: my $avecount = $thesaurus_db{'average.count'};
3565: # Put keywords (those that appear > average) into %Keywords
3566: while (my ($word,$data)=each (%thesaurus_db)) {
3567: my ($count,undef) = split /:/,$data;
3568: $Keywords{$word}++ if ($count > $avecount);
3569: }
3570: untie %thesaurus_db;
3571: # Remove special values from %Keywords.
1.356 albertel 3572: foreach my $value ('total.count','average.count') {
3573: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3574: }
1.46 matthew 3575: return 1;
3576: }
3577:
3578: ###################################################
3579:
3580: =pod
3581:
1.648 raeburn 3582: =item * &keyword($word)
1.46 matthew 3583:
3584: Returns true if $word is a keyword. A keyword is a word that appears more
3585: than the average number of times in the thesaurus database. Calls
3586: &initialize_keywords
3587:
3588: =cut
3589:
3590: ###################################################
1.20 www 3591:
3592: sub keyword {
1.46 matthew 3593: return if (!&initialize_keywords());
3594: my $word=lc(shift());
3595: $word=~s/\W//g;
3596: return exists($Keywords{$word});
1.20 www 3597: }
1.46 matthew 3598:
3599: ###############################################################
3600:
3601: =pod
1.20 www 3602:
1.648 raeburn 3603: =item * &get_related_words()
1.46 matthew 3604:
1.160 matthew 3605: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3606: an array of words. If the keyword is not in the thesaurus, an empty array
3607: will be returned. The order of the words returned is determined by the
3608: database which holds them.
3609:
3610: Uses global $thesaurus_db_file.
3611:
1.1057 foxr 3612:
1.46 matthew 3613: =cut
3614:
3615: ###############################################################
3616: sub get_related_words {
3617: my $keyword = shift;
3618: my %thesaurus_db;
3619: if (! -e $thesaurus_db_file) {
3620: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3621: "failed because the file does not exist");
3622: return ();
3623: }
3624: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3625: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3626: return ();
3627: }
3628: my @Words=();
1.429 www 3629: my $count=0;
1.46 matthew 3630: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3631: # The first element is the number of times
3632: # the word appears. We do not need it now.
1.429 www 3633: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3634: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3635: my $threshold=$mostfrequentcount/10;
3636: foreach my $possibleword (@RelatedWords) {
3637: my ($word,$wordcount)=split(/\,/,$possibleword);
3638: if ($wordcount>$threshold) {
3639: push(@Words,$word);
3640: $count++;
3641: if ($count>10) { last; }
3642: }
1.20 www 3643: }
3644: }
1.46 matthew 3645: untie %thesaurus_db;
3646: return @Words;
1.14 harris41 3647: }
1.1090 foxr 3648: ###############################################################
3649: #
3650: # Spell checking
3651: #
3652:
3653: =pod
3654:
1.1142 raeburn 3655: =back
3656:
1.1090 foxr 3657: =head1 Spell checking
3658:
3659: =over 4
3660:
3661: =item * &check_spelling($wordlist $language)
3662:
3663: Takes a string containing words and feeds it to an external
3664: spellcheck program via a pipeline. Returns a string containing
3665: them mis-spelled words.
3666:
3667: Parameters:
3668:
3669: =over 4
3670:
3671: =item - $wordlist
3672:
3673: String that will be fed into the spellcheck program.
3674:
3675: =item - $language
3676:
3677: Language string that specifies the language for which the spell
3678: check will be performed.
3679:
3680: =back
3681:
3682: =back
3683:
3684: Note: This sub assumes that aspell is installed.
3685:
3686:
3687: =cut
3688:
1.46 matthew 3689:
1.1090 foxr 3690: sub check_spelling {
3691: my ($wordlist, $language) = @_;
1.1091 foxr 3692: my @misspellings;
3693:
3694: # Generate the speller and set the langauge.
3695: # if explicitly selected:
1.1090 foxr 3696:
1.1091 foxr 3697: my $speller = Text::Aspell->new;
1.1090 foxr 3698: if ($language) {
1.1091 foxr 3699: $speller->set_option('lang', $language);
1.1090 foxr 3700: }
3701:
1.1091 foxr 3702: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3703:
1.1091 foxr 3704: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3705:
1.1091 foxr 3706: foreach my $word (@words) {
3707: if(! $speller->check($word)) {
3708: push(@misspellings, $word);
1.1090 foxr 3709: }
3710: }
1.1091 foxr 3711: return join(' ', @misspellings);
3712:
1.1090 foxr 3713: }
3714:
1.61 www 3715: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3716: =pod
3717:
1.112 bowersj2 3718: =head1 User Name Functions
3719:
3720: =over 4
3721:
1.648 raeburn 3722: =item * &plainname($uname,$udom,$first)
1.81 albertel 3723:
1.112 bowersj2 3724: Takes a users logon name and returns it as a string in
1.226 albertel 3725: "first middle last generation" form
3726: if $first is set to 'lastname' then it returns it as
3727: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3728:
3729: =cut
1.61 www 3730:
1.295 www 3731:
1.81 albertel 3732: ###############################################################
1.61 www 3733: sub plainname {
1.226 albertel 3734: my ($uname,$udom,$first)=@_;
1.537 albertel 3735: return if (!defined($uname) || !defined($udom));
1.295 www 3736: my %names=&getnames($uname,$udom);
1.226 albertel 3737: my $name=&Apache::lonnet::format_name($names{'firstname'},
3738: $names{'middlename'},
3739: $names{'lastname'},
3740: $names{'generation'},$first);
3741: $name=~s/^\s+//;
1.62 www 3742: $name=~s/\s+$//;
3743: $name=~s/\s+/ /g;
1.353 albertel 3744: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3745: return $name;
1.61 www 3746: }
1.66 www 3747:
3748: # -------------------------------------------------------------------- Nickname
1.81 albertel 3749: =pod
3750:
1.648 raeburn 3751: =item * &nickname($uname,$udom)
1.81 albertel 3752:
3753: Gets a users name and returns it as a string as
3754:
3755: ""nickname""
1.66 www 3756:
1.81 albertel 3757: if the user has a nickname or
3758:
3759: "first middle last generation"
3760:
3761: if the user does not
3762:
3763: =cut
1.66 www 3764:
3765: sub nickname {
3766: my ($uname,$udom)=@_;
1.537 albertel 3767: return if (!defined($uname) || !defined($udom));
1.295 www 3768: my %names=&getnames($uname,$udom);
1.68 albertel 3769: my $name=$names{'nickname'};
1.66 www 3770: if ($name) {
3771: $name='"'.$name.'"';
3772: } else {
3773: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3774: $names{'lastname'}.' '.$names{'generation'};
3775: $name=~s/\s+$//;
3776: $name=~s/\s+/ /g;
3777: }
3778: return $name;
3779: }
3780:
1.295 www 3781: sub getnames {
3782: my ($uname,$udom)=@_;
1.537 albertel 3783: return if (!defined($uname) || !defined($udom));
1.433 albertel 3784: if ($udom eq 'public' && $uname eq 'public') {
3785: return ('lastname' => &mt('Public'));
3786: }
1.295 www 3787: my $id=$uname.':'.$udom;
3788: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3789: if ($cached) {
3790: return %{$names};
3791: } else {
3792: my %loadnames=&Apache::lonnet::get('environment',
3793: ['firstname','middlename','lastname','generation','nickname'],
3794: $udom,$uname);
3795: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3796: return %loadnames;
3797: }
3798: }
1.61 www 3799:
1.542 raeburn 3800: # -------------------------------------------------------------------- getemails
1.648 raeburn 3801:
1.542 raeburn 3802: =pod
3803:
1.648 raeburn 3804: =item * &getemails($uname,$udom)
1.542 raeburn 3805:
3806: Gets a user's email information and returns it as a hash with keys:
3807: notification, critnotification, permanentemail
3808:
3809: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3810: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3811:
1.648 raeburn 3812:
1.542 raeburn 3813: =cut
3814:
1.648 raeburn 3815:
1.466 albertel 3816: sub getemails {
3817: my ($uname,$udom)=@_;
3818: if ($udom eq 'public' && $uname eq 'public') {
3819: return;
3820: }
1.467 www 3821: if (!$udom) { $udom=$env{'user.domain'}; }
3822: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3823: my $id=$uname.':'.$udom;
3824: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3825: if ($cached) {
3826: return %{$names};
3827: } else {
3828: my %loadnames=&Apache::lonnet::get('environment',
3829: ['notification','critnotification',
3830: 'permanentemail'],
3831: $udom,$uname);
3832: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3833: return %loadnames;
3834: }
3835: }
3836:
1.551 albertel 3837: sub flush_email_cache {
3838: my ($uname,$udom)=@_;
3839: if (!$udom) { $udom =$env{'user.domain'}; }
3840: if (!$uname) { $uname=$env{'user.name'}; }
3841: return if ($udom eq 'public' && $uname eq 'public');
3842: my $id=$uname.':'.$udom;
3843: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3844: }
3845:
1.728 raeburn 3846: # -------------------------------------------------------------------- getlangs
3847:
3848: =pod
3849:
3850: =item * &getlangs($uname,$udom)
3851:
3852: Gets a user's language preference and returns it as a hash with key:
3853: language.
3854:
3855: =cut
3856:
3857:
3858: sub getlangs {
3859: my ($uname,$udom) = @_;
3860: if (!$udom) { $udom =$env{'user.domain'}; }
3861: if (!$uname) { $uname=$env{'user.name'}; }
3862: my $id=$uname.':'.$udom;
3863: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3864: if ($cached) {
3865: return %{$langs};
3866: } else {
3867: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3868: $udom,$uname);
3869: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3870: return %loadlangs;
3871: }
3872: }
3873:
3874: sub flush_langs_cache {
3875: my ($uname,$udom)=@_;
3876: if (!$udom) { $udom =$env{'user.domain'}; }
3877: if (!$uname) { $uname=$env{'user.name'}; }
3878: return if ($udom eq 'public' && $uname eq 'public');
3879: my $id=$uname.':'.$udom;
3880: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3881: }
3882:
1.61 www 3883: # ------------------------------------------------------------------ Screenname
1.81 albertel 3884:
3885: =pod
3886:
1.648 raeburn 3887: =item * &screenname($uname,$udom)
1.81 albertel 3888:
3889: Gets a users screenname and returns it as a string
3890:
3891: =cut
1.61 www 3892:
3893: sub screenname {
3894: my ($uname,$udom)=@_;
1.258 albertel 3895: if ($uname eq $env{'user.name'} &&
3896: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3897: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3898: return $names{'screenname'};
1.62 www 3899: }
3900:
1.212 albertel 3901:
1.802 bisitz 3902: # ------------------------------------------------------------- Confirm Wrapper
3903: =pod
3904:
1.1142 raeburn 3905: =item * &confirmwrapper($message)
1.802 bisitz 3906:
3907: Wrap messages about completion of operation in box
3908:
3909: =cut
3910:
3911: sub confirmwrapper {
3912: my ($message)=@_;
3913: if ($message) {
3914: return "\n".'<div class="LC_confirm_box">'."\n"
3915: .$message."\n"
3916: .'</div>'."\n";
3917: } else {
3918: return $message;
3919: }
3920: }
3921:
1.62 www 3922: # ------------------------------------------------------------- Message Wrapper
3923:
3924: sub messagewrapper {
1.369 www 3925: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3926: return
1.441 albertel 3927: '<a href="/adm/email?compose=individual&'.
3928: 'recname='.$username.'&recdom='.$domain.
3929: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3930: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3931: }
1.802 bisitz 3932:
1.74 www 3933: # --------------------------------------------------------------- Notes Wrapper
3934:
3935: sub noteswrapper {
3936: my ($link,$un,$do)=@_;
3937: return
1.896 amueller 3938: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3939: }
1.802 bisitz 3940:
1.62 www 3941: # ------------------------------------------------------------- Aboutme Wrapper
3942:
3943: sub aboutmewrapper {
1.1070 raeburn 3944: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3945: if (!defined($username) && !defined($domain)) {
3946: return;
3947: }
1.1096 raeburn 3948: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3949: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3950: }
3951:
3952: # ------------------------------------------------------------ Syllabus Wrapper
3953:
3954: sub syllabuswrapper {
1.707 bisitz 3955: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3956: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3957: }
1.14 harris41 3958:
1.802 bisitz 3959: # -----------------------------------------------------------------------------
3960:
1.208 matthew 3961: sub track_student_link {
1.887 raeburn 3962: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3963: my $link ="/adm/trackstudent?";
1.208 matthew 3964: my $title = 'View recent activity';
3965: if (defined($sname) && $sname !~ /^\s*$/ &&
3966: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3967: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3968: $title .= ' of this student';
1.268 albertel 3969: }
1.208 matthew 3970: if (defined($target) && $target !~ /^\s*$/) {
3971: $target = qq{target="$target"};
3972: } else {
3973: $target = '';
3974: }
1.268 albertel 3975: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3976: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3977: $title = &mt($title);
3978: $linktext = &mt($linktext);
1.448 albertel 3979: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3980: &help_open_topic('View_recent_activity');
1.208 matthew 3981: }
3982:
1.781 raeburn 3983: sub slot_reservations_link {
3984: my ($linktext,$sname,$sdom,$target) = @_;
3985: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3986: my $title = 'View slot reservation history';
3987: if (defined($sname) && $sname !~ /^\s*$/ &&
3988: defined($sdom) && $sdom !~ /^\s*$/) {
3989: $link .= "&uname=$sname&udom=$sdom";
3990: $title .= ' of this student';
3991: }
3992: if (defined($target) && $target !~ /^\s*$/) {
3993: $target = qq{target="$target"};
3994: } else {
3995: $target = '';
3996: }
3997: $title = &mt($title);
3998: $linktext = &mt($linktext);
3999: return qq{<a href="$link" title="$title" $target>$linktext</a>};
4000: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4001:
4002: }
4003:
1.508 www 4004: # ===================================================== Display a student photo
4005:
4006:
1.509 albertel 4007: sub student_image_tag {
1.508 www 4008: my ($domain,$user)=@_;
4009: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4010: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4011: return '<img src="'.$imgsrc.'" align="right" />';
4012: } else {
4013: return '';
4014: }
4015: }
4016:
1.112 bowersj2 4017: =pod
4018:
4019: =back
4020:
4021: =head1 Access .tab File Data
4022:
4023: =over 4
4024:
1.648 raeburn 4025: =item * &languageids()
1.112 bowersj2 4026:
4027: returns list of all language ids
4028:
4029: =cut
4030:
1.14 harris41 4031: sub languageids {
1.16 harris41 4032: return sort(keys(%language));
1.14 harris41 4033: }
4034:
1.112 bowersj2 4035: =pod
4036:
1.648 raeburn 4037: =item * &languagedescription()
1.112 bowersj2 4038:
4039: returns description of a specified language id
4040:
4041: =cut
4042:
1.14 harris41 4043: sub languagedescription {
1.125 www 4044: my $code=shift;
4045: return ($supported_language{$code}?'* ':'').
4046: $language{$code}.
1.126 www 4047: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4048: }
4049:
1.1048 foxr 4050: =pod
4051:
4052: =item * &plainlanguagedescription
4053:
4054: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4055: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4056:
4057: =cut
4058:
1.145 www 4059: sub plainlanguagedescription {
4060: my $code=shift;
4061: return $language{$code};
4062: }
4063:
1.1048 foxr 4064: =pod
4065:
4066: =item * &supportedlanguagecode
4067:
4068: Returns the supported language code (e.g. sptutf maps to pt) given a language
4069: code.
4070:
4071: =cut
4072:
1.145 www 4073: sub supportedlanguagecode {
4074: my $code=shift;
4075: return $supported_language{$code};
1.97 www 4076: }
4077:
1.112 bowersj2 4078: =pod
4079:
1.1048 foxr 4080: =item * &latexlanguage()
4081:
4082: Given a language key code returns the correspondnig language to use
4083: to select the correct hyphenation on LaTeX printouts. This is undef if there
4084: is no supported hyphenation for the language code.
4085:
4086: =cut
4087:
4088: sub latexlanguage {
4089: my $code = shift;
4090: return $latex_language{$code};
4091: }
4092:
4093: =pod
4094:
4095: =item * &latexhyphenation()
4096:
4097: Same as above but what's supplied is the language as it might be stored
4098: in the metadata.
4099:
4100: =cut
4101:
4102: sub latexhyphenation {
4103: my $key = shift;
4104: return $latex_language_bykey{$key};
4105: }
4106:
4107: =pod
4108:
1.648 raeburn 4109: =item * ©rightids()
1.112 bowersj2 4110:
4111: returns list of all copyrights
4112:
4113: =cut
4114:
4115: sub copyrightids {
4116: return sort(keys(%cprtag));
4117: }
4118:
4119: =pod
4120:
1.648 raeburn 4121: =item * ©rightdescription()
1.112 bowersj2 4122:
4123: returns description of a specified copyright id
4124:
4125: =cut
4126:
4127: sub copyrightdescription {
1.166 www 4128: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4129: }
1.197 matthew 4130:
4131: =pod
4132:
1.648 raeburn 4133: =item * &source_copyrightids()
1.192 taceyjo1 4134:
4135: returns list of all source copyrights
4136:
4137: =cut
4138:
4139: sub source_copyrightids {
4140: return sort(keys(%scprtag));
4141: }
4142:
4143: =pod
4144:
1.648 raeburn 4145: =item * &source_copyrightdescription()
1.192 taceyjo1 4146:
4147: returns description of a specified source copyright id
4148:
4149: =cut
4150:
4151: sub source_copyrightdescription {
4152: return &mt($scprtag{shift(@_)});
4153: }
1.112 bowersj2 4154:
4155: =pod
4156:
1.648 raeburn 4157: =item * &filecategories()
1.112 bowersj2 4158:
4159: returns list of all file categories
4160:
4161: =cut
4162:
4163: sub filecategories {
4164: return sort(keys(%category_extensions));
4165: }
4166:
4167: =pod
4168:
1.648 raeburn 4169: =item * &filecategorytypes()
1.112 bowersj2 4170:
4171: returns list of file types belonging to a given file
4172: category
4173:
4174: =cut
4175:
4176: sub filecategorytypes {
1.356 albertel 4177: my ($cat) = @_;
1.1248 raeburn 4178: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4179: return @{$category_extensions{lc($cat)}};
4180: } else {
4181: return ();
4182: }
1.112 bowersj2 4183: }
4184:
4185: =pod
4186:
1.648 raeburn 4187: =item * &fileembstyle()
1.112 bowersj2 4188:
4189: returns embedding style for a specified file type
4190:
4191: =cut
4192:
4193: sub fileembstyle {
4194: return $fe{lc(shift(@_))};
1.169 www 4195: }
4196:
1.351 www 4197: sub filemimetype {
4198: return $fm{lc(shift(@_))};
4199: }
4200:
1.169 www 4201:
4202: sub filecategoryselect {
4203: my ($name,$value)=@_;
1.189 matthew 4204: return &select_form($value,$name,
1.970 raeburn 4205: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4206: }
4207:
4208: =pod
4209:
1.648 raeburn 4210: =item * &filedescription()
1.112 bowersj2 4211:
4212: returns description for a specified file type
4213:
4214: =cut
4215:
4216: sub filedescription {
1.188 matthew 4217: my $file_description = $fd{lc(shift())};
4218: $file_description =~ s:([\[\]]):~$1:g;
4219: return &mt($file_description);
1.112 bowersj2 4220: }
4221:
4222: =pod
4223:
1.648 raeburn 4224: =item * &filedescriptionex()
1.112 bowersj2 4225:
4226: returns description for a specified file type with
4227: extra formatting
4228:
4229: =cut
4230:
4231: sub filedescriptionex {
4232: my $ex=shift;
1.188 matthew 4233: my $file_description = $fd{lc($ex)};
4234: $file_description =~ s:([\[\]]):~$1:g;
4235: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4236: }
4237:
4238: # End of .tab access
4239: =pod
4240:
4241: =back
4242:
4243: =cut
4244:
4245: # ------------------------------------------------------------------ File Types
4246: sub fileextensions {
4247: return sort(keys(%fe));
4248: }
4249:
1.97 www 4250: # ----------------------------------------------------------- Display Languages
4251: # returns a hash with all desired display languages
4252: #
4253:
4254: sub display_languages {
4255: my %languages=();
1.695 raeburn 4256: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4257: $languages{$lang}=1;
1.97 www 4258: }
4259: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4260: if ($env{'form.displaylanguage'}) {
1.356 albertel 4261: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4262: $languages{$lang}=1;
1.97 www 4263: }
4264: }
4265: return %languages;
1.14 harris41 4266: }
4267:
1.582 albertel 4268: sub languages {
4269: my ($possible_langs) = @_;
1.695 raeburn 4270: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4271: if (!ref($possible_langs)) {
4272: if( wantarray ) {
4273: return @preferred_langs;
4274: } else {
4275: return $preferred_langs[0];
4276: }
4277: }
4278: my %possibilities = map { $_ => 1 } (@$possible_langs);
4279: my @preferred_possibilities;
4280: foreach my $preferred_lang (@preferred_langs) {
4281: if (exists($possibilities{$preferred_lang})) {
4282: push(@preferred_possibilities, $preferred_lang);
4283: }
4284: }
4285: if( wantarray ) {
4286: return @preferred_possibilities;
4287: }
4288: return $preferred_possibilities[0];
4289: }
4290:
1.742 raeburn 4291: sub user_lang {
4292: my ($touname,$toudom,$fromcid) = @_;
4293: my @userlangs;
4294: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4295: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4296: $env{'course.'.$fromcid.'.languages'}));
4297: } else {
4298: my %langhash = &getlangs($touname,$toudom);
4299: if ($langhash{'languages'} ne '') {
4300: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4301: } else {
4302: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4303: if ($domdefs{'lang_def'} ne '') {
4304: @userlangs = ($domdefs{'lang_def'});
4305: }
4306: }
4307: }
4308: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4309: my $user_lh = Apache::localize->get_handle(@languages);
4310: return $user_lh;
4311: }
4312:
4313:
1.112 bowersj2 4314: ###############################################################
4315: ## Student Answer Attempts ##
4316: ###############################################################
4317:
4318: =pod
4319:
4320: =head1 Alternate Problem Views
4321:
4322: =over 4
4323:
1.648 raeburn 4324: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4325: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4326:
4327: Return string with previous attempt on problem. Arguments:
4328:
4329: =over 4
4330:
4331: =item * $symb: Problem, including path
4332:
4333: =item * $username: username of the desired student
4334:
4335: =item * $domain: domain of the desired student
1.14 harris41 4336:
1.112 bowersj2 4337: =item * $course: Course ID
1.14 harris41 4338:
1.112 bowersj2 4339: =item * $getattempt: Leave blank for all attempts, otherwise put
4340: something
1.14 harris41 4341:
1.112 bowersj2 4342: =item * $regexp: if string matches this regexp, the string will be
4343: sent to $gradesub
1.14 harris41 4344:
1.112 bowersj2 4345: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4346:
1.1199 raeburn 4347: =item * $usec: section of the desired student
4348:
4349: =item * $identifier: counter for student (multiple students one problem) or
4350: problem (one student; whole sequence).
4351:
1.112 bowersj2 4352: =back
1.14 harris41 4353:
1.112 bowersj2 4354: The output string is a table containing all desired attempts, if any.
1.16 harris41 4355:
1.112 bowersj2 4356: =cut
1.1 albertel 4357:
4358: sub get_previous_attempt {
1.1199 raeburn 4359: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4360: my $prevattempts='';
1.43 ng 4361: no strict 'refs';
1.1 albertel 4362: if ($symb) {
1.3 albertel 4363: my (%returnhash)=
4364: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4365: if ($returnhash{'version'}) {
4366: my %lasthash=();
4367: my $version;
4368: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4369: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4370: if ($key =~ /\.rawrndseed$/) {
4371: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4372: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4373: } else {
4374: $lasthash{$key}=$returnhash{$version.':'.$key};
4375: }
1.19 harris41 4376: }
1.1 albertel 4377: }
1.596 albertel 4378: $prevattempts=&start_data_table().&start_data_table_header_row();
4379: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4380: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4381: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4382: foreach my $key (sort(keys(%lasthash))) {
4383: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4384: if ($#parts > 0) {
1.31 albertel 4385: my $data=$parts[-1];
1.989 raeburn 4386: next if ($data eq 'foilorder');
1.31 albertel 4387: pop(@parts);
1.1010 www 4388: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4389: if ($data eq 'type') {
4390: unless ($showsurv) {
4391: my $id = join(',',@parts);
4392: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4393: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4394: $lasthidden{$ign.'.'.$id} = 1;
4395: }
1.945 raeburn 4396: }
1.1199 raeburn 4397: if ($identifier ne '') {
4398: my $id = join(',',@parts);
4399: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4400: $domain,$username,$usec,undef,$course) =~ /^no/) {
4401: $hidestatus{$ign.'.'.$id} = 1;
4402: }
4403: }
4404: } elsif ($data eq 'regrader') {
4405: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4406: my $id = join(',',@parts);
4407: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4408: }
1.1010 www 4409: }
1.31 albertel 4410: } else {
1.41 ng 4411: if ($#parts == 0) {
4412: $prevattempts.='<th>'.$parts[0].'</th>';
4413: } else {
4414: $prevattempts.='<th>'.$ign.'</th>';
4415: }
1.31 albertel 4416: }
1.16 harris41 4417: }
1.596 albertel 4418: $prevattempts.=&end_data_table_header_row();
1.40 ng 4419: if ($getattempt eq '') {
1.1199 raeburn 4420: my (%solved,%resets,%probstatus);
1.1200 raeburn 4421: if (($identifier ne '') && (keys(%regraded) > 0)) {
4422: for ($version=1;$version<=$returnhash{'version'};$version++) {
4423: foreach my $id (keys(%regraded)) {
4424: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4425: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4426: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4427: push(@{$resets{$id}},$version);
1.1199 raeburn 4428: }
4429: }
4430: }
1.1200 raeburn 4431: }
4432: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4433: my (@hidden,@unsolved);
1.945 raeburn 4434: if (%typeparts) {
4435: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4436: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4437: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4438: push(@hidden,$id);
1.1199 raeburn 4439: } elsif ($identifier ne '') {
4440: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4441: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4442: ($hidestatus{$id})) {
1.1200 raeburn 4443: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4444: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4445: push(@{$solved{$id}},$version);
4446: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4447: (ref($solved{$id}) eq 'ARRAY')) {
4448: my $skip;
4449: if (ref($resets{$id}) eq 'ARRAY') {
4450: foreach my $reset (@{$resets{$id}}) {
4451: if ($reset > $solved{$id}[-1]) {
4452: $skip=1;
4453: last;
4454: }
4455: }
4456: }
4457: unless ($skip) {
4458: my ($ign,$partslist) = split(/\./,$id,2);
4459: push(@unsolved,$partslist);
4460: }
4461: }
4462: }
1.945 raeburn 4463: }
4464: }
4465: }
4466: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4467: '<td>'.&mt('Transaction [_1]',$version);
4468: if (@unsolved) {
4469: $prevattempts .= '<span class="LC_nobreak"><label>'.
4470: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4471: &mt('Hide').'</label></span>';
4472: }
4473: $prevattempts .= '</td>';
1.945 raeburn 4474: if (@hidden) {
4475: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4476: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4477: my $hide;
4478: foreach my $id (@hidden) {
4479: if ($key =~ /^\Q$id\E/) {
4480: $hide = 1;
4481: last;
4482: }
4483: }
4484: if ($hide) {
4485: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4486: if (($data eq 'award') || ($data eq 'awarddetail')) {
4487: my $value = &format_previous_attempt_value($key,
4488: $returnhash{$version.':'.$key});
1.1173 kruse 4489: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4490: } else {
4491: $prevattempts.='<td> </td>';
4492: }
4493: } else {
4494: if ($key =~ /\./) {
1.1212 raeburn 4495: my $value = $returnhash{$version.':'.$key};
4496: if ($key =~ /\.rndseed$/) {
4497: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4498: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4499: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4500: }
4501: }
4502: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4503: ' </td>';
1.945 raeburn 4504: } else {
4505: $prevattempts.='<td> </td>';
4506: }
4507: }
4508: }
4509: } else {
4510: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4511: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4512: my $value = $returnhash{$version.':'.$key};
4513: if ($key =~ /\.rndseed$/) {
4514: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4515: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4516: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4517: }
4518: }
4519: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4520: ' </td>';
1.945 raeburn 4521: }
4522: }
4523: $prevattempts.=&end_data_table_row();
1.40 ng 4524: }
1.1 albertel 4525: }
1.945 raeburn 4526: my @currhidden = keys(%lasthidden);
1.596 albertel 4527: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4528: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4529: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4530: if (%typeparts) {
4531: my $hidden;
4532: foreach my $id (@currhidden) {
4533: if ($key =~ /^\Q$id\E/) {
4534: $hidden = 1;
4535: last;
4536: }
4537: }
4538: if ($hidden) {
4539: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4540: if (($data eq 'award') || ($data eq 'awarddetail')) {
4541: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4542: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4543: $value = &$gradesub($value);
4544: }
1.1173 kruse 4545: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4546: } else {
4547: $prevattempts.='<td> </td>';
4548: }
4549: } else {
4550: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4551: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4552: $value = &$gradesub($value);
4553: }
1.1173 kruse 4554: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4555: }
4556: } else {
4557: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4558: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4559: $value = &$gradesub($value);
4560: }
1.1173 kruse 4561: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4562: }
1.16 harris41 4563: }
1.596 albertel 4564: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4565: } else {
1.596 albertel 4566: $prevattempts=
4567: &start_data_table().&start_data_table_row().
4568: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4569: &end_data_table_row().&end_data_table();
1.1 albertel 4570: }
4571: } else {
1.596 albertel 4572: $prevattempts=
4573: &start_data_table().&start_data_table_row().
4574: '<td>'.&mt('No data.').'</td>'.
4575: &end_data_table_row().&end_data_table();
1.1 albertel 4576: }
1.10 albertel 4577: }
4578:
1.581 albertel 4579: sub format_previous_attempt_value {
4580: my ($key,$value) = @_;
1.1011 www 4581: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4582: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4583: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4584: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4585: } elsif ($key =~ /answerstring$/) {
4586: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4587: my @answer = %answers;
4588: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4589: my @anskeys = sort(keys(%answers));
4590: if (@anskeys == 1) {
4591: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4592: if ($answer =~ m{\0}) {
4593: $answer =~ s{\0}{,}g;
1.988 raeburn 4594: }
4595: my $tag_internal_answer_name = 'INTERNAL';
4596: if ($anskeys[0] eq $tag_internal_answer_name) {
4597: $value = $answer;
4598: } else {
4599: $value = $anskeys[0].'='.$answer;
4600: }
4601: } else {
4602: foreach my $ans (@anskeys) {
4603: my $answer = $answers{$ans};
1.1001 raeburn 4604: if ($answer =~ m{\0}) {
4605: $answer =~ s{\0}{,}g;
1.988 raeburn 4606: }
4607: $value .= $ans.'='.$answer.'<br />';;
4608: }
4609: }
1.581 albertel 4610: } else {
1.1173 kruse 4611: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4612: }
4613: return $value;
4614: }
4615:
4616:
1.107 albertel 4617: sub relative_to_absolute {
4618: my ($url,$output)=@_;
4619: my $parser=HTML::TokeParser->new(\$output);
4620: my $token;
4621: my $thisdir=$url;
4622: my @rlinks=();
4623: while ($token=$parser->get_token) {
4624: if ($token->[0] eq 'S') {
4625: if ($token->[1] eq 'a') {
4626: if ($token->[2]->{'href'}) {
4627: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4628: }
4629: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4630: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4631: } elsif ($token->[1] eq 'base') {
4632: $thisdir=$token->[2]->{'href'};
4633: }
4634: }
4635: }
4636: $thisdir=~s-/[^/]*$--;
1.356 albertel 4637: foreach my $link (@rlinks) {
1.726 raeburn 4638: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4639: ($link=~/^\//) ||
4640: ($link=~/^javascript:/i) ||
4641: ($link=~/^mailto:/i) ||
4642: ($link=~/^\#/)) {
4643: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4644: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4645: }
4646: }
4647: # -------------------------------------------------- Deal with Applet codebases
4648: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4649: return $output;
4650: }
4651:
1.112 bowersj2 4652: =pod
4653:
1.648 raeburn 4654: =item * &get_student_view()
1.112 bowersj2 4655:
4656: show a snapshot of what student was looking at
4657:
4658: =cut
4659:
1.10 albertel 4660: sub get_student_view {
1.186 albertel 4661: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4662: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4663: my (%form);
1.10 albertel 4664: my @elements=('symb','courseid','domain','username');
4665: foreach my $element (@elements) {
1.186 albertel 4666: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4667: }
1.186 albertel 4668: if (defined($moreenv)) {
4669: %form=(%form,%{$moreenv});
4670: }
1.236 albertel 4671: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4672: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4673: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4674: $userview=~s/\<body[^\>]*\>//gi;
4675: $userview=~s/\<\/body\>//gi;
4676: $userview=~s/\<html\>//gi;
4677: $userview=~s/\<\/html\>//gi;
4678: $userview=~s/\<head\>//gi;
4679: $userview=~s/\<\/head\>//gi;
4680: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4681: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4682: if (wantarray) {
4683: return ($userview,$response);
4684: } else {
4685: return $userview;
4686: }
4687: }
4688:
4689: sub get_student_view_with_retries {
4690: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4691:
4692: my $ok = 0; # True if we got a good response.
4693: my $content;
4694: my $response;
4695:
4696: # Try to get the student_view done. within the retries count:
4697:
4698: do {
4699: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4700: $ok = $response->is_success;
4701: if (!$ok) {
4702: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4703: }
4704: $retries--;
4705: } while (!$ok && ($retries > 0));
4706:
4707: if (!$ok) {
4708: $content = ''; # On error return an empty content.
4709: }
1.651 www 4710: if (wantarray) {
4711: return ($content, $response);
4712: } else {
4713: return $content;
4714: }
1.11 albertel 4715: }
4716:
1.112 bowersj2 4717: =pod
4718:
1.648 raeburn 4719: =item * &get_student_answers()
1.112 bowersj2 4720:
4721: show a snapshot of how student was answering problem
4722:
4723: =cut
4724:
1.11 albertel 4725: sub get_student_answers {
1.100 sakharuk 4726: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4727: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4728: my (%moreenv);
1.11 albertel 4729: my @elements=('symb','courseid','domain','username');
4730: foreach my $element (@elements) {
1.186 albertel 4731: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4732: }
1.186 albertel 4733: $moreenv{'grade_target'}='answer';
4734: %moreenv=(%form,%moreenv);
1.497 raeburn 4735: $feedurl = &Apache::lonnet::clutter($feedurl);
4736: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4737: return $userview;
1.1 albertel 4738: }
1.116 albertel 4739:
4740: =pod
4741:
4742: =item * &submlink()
4743:
1.242 albertel 4744: Inputs: $text $uname $udom $symb $target
1.116 albertel 4745:
4746: Returns: A link to grades.pm such as to see the SUBM view of a student
4747:
4748: =cut
4749:
4750: ###############################################
4751: sub submlink {
1.242 albertel 4752: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4753: if (!($uname && $udom)) {
4754: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4755: &Apache::lonnet::whichuser($symb);
1.116 albertel 4756: if (!$symb) { $symb=$cursymb; }
4757: }
1.254 matthew 4758: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4759: $symb=&escape($symb);
1.960 bisitz 4760: if ($target) { $target=" target=\"$target\""; }
4761: return
4762: '<a href="/adm/grades?command=submission'.
4763: '&symb='.$symb.
4764: '&student='.$uname.
4765: '&userdom='.$udom.'"'.
4766: $target.'>'.$text.'</a>';
1.242 albertel 4767: }
4768: ##############################################
4769:
4770: =pod
4771:
4772: =item * &pgrdlink()
4773:
4774: Inputs: $text $uname $udom $symb $target
4775:
4776: Returns: A link to grades.pm such as to see the PGRD view of a student
4777:
4778: =cut
4779:
4780: ###############################################
4781: sub pgrdlink {
4782: my $link=&submlink(@_);
4783: $link=~s/(&command=submission)/$1&showgrading=yes/;
4784: return $link;
4785: }
4786: ##############################################
4787:
4788: =pod
4789:
4790: =item * &pprmlink()
4791:
4792: Inputs: $text $uname $udom $symb $target
4793:
4794: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4795: student and a specific resource
1.242 albertel 4796:
4797: =cut
4798:
4799: ###############################################
4800: sub pprmlink {
4801: my ($text,$uname,$udom,$symb,$target)=@_;
4802: if (!($uname && $udom)) {
4803: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4804: &Apache::lonnet::whichuser($symb);
1.242 albertel 4805: if (!$symb) { $symb=$cursymb; }
4806: }
1.254 matthew 4807: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4808: $symb=&escape($symb);
1.242 albertel 4809: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4810: return '<a href="/adm/parmset?command=set&'.
4811: 'symb='.$symb.'&uname='.$uname.
4812: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4813: }
4814: ##############################################
1.37 matthew 4815:
1.112 bowersj2 4816: =pod
4817:
4818: =back
4819:
4820: =cut
4821:
1.37 matthew 4822: ###############################################
1.51 www 4823:
4824:
4825: sub timehash {
1.687 raeburn 4826: my ($thistime) = @_;
4827: my $timezone = &Apache::lonlocal::gettimezone();
4828: my $dt = DateTime->from_epoch(epoch => $thistime)
4829: ->set_time_zone($timezone);
4830: my $wday = $dt->day_of_week();
4831: if ($wday == 7) { $wday = 0; }
4832: return ( 'second' => $dt->second(),
4833: 'minute' => $dt->minute(),
4834: 'hour' => $dt->hour(),
4835: 'day' => $dt->day_of_month(),
4836: 'month' => $dt->month(),
4837: 'year' => $dt->year(),
4838: 'weekday' => $wday,
4839: 'dayyear' => $dt->day_of_year(),
4840: 'dlsav' => $dt->is_dst() );
1.51 www 4841: }
4842:
1.370 www 4843: sub utc_string {
4844: my ($date)=@_;
1.371 www 4845: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4846: }
4847:
1.51 www 4848: sub maketime {
4849: my %th=@_;
1.687 raeburn 4850: my ($epoch_time,$timezone,$dt);
4851: $timezone = &Apache::lonlocal::gettimezone();
4852: eval {
4853: $dt = DateTime->new( year => $th{'year'},
4854: month => $th{'month'},
4855: day => $th{'day'},
4856: hour => $th{'hour'},
4857: minute => $th{'minute'},
4858: second => $th{'second'},
4859: time_zone => $timezone,
4860: );
4861: };
4862: if (!$@) {
4863: $epoch_time = $dt->epoch;
4864: if ($epoch_time) {
4865: return $epoch_time;
4866: }
4867: }
1.51 www 4868: return POSIX::mktime(
4869: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4870: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4871: }
4872:
4873: #########################################
1.51 www 4874:
4875: sub findallcourses {
1.482 raeburn 4876: my ($roles,$uname,$udom) = @_;
1.355 albertel 4877: my %roles;
4878: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4879: my %courses;
1.51 www 4880: my $now=time;
1.482 raeburn 4881: if (!defined($uname)) {
4882: $uname = $env{'user.name'};
4883: }
4884: if (!defined($udom)) {
4885: $udom = $env{'user.domain'};
4886: }
4887: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4888: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4889: if (!%roles) {
4890: %roles = (
4891: cc => 1,
1.907 raeburn 4892: co => 1,
1.482 raeburn 4893: in => 1,
4894: ep => 1,
4895: ta => 1,
4896: cr => 1,
4897: st => 1,
4898: );
4899: }
4900: foreach my $entry (keys(%roleshash)) {
4901: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4902: if ($trole =~ /^cr/) {
4903: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4904: } else {
4905: next if (!exists($roles{$trole}));
4906: }
4907: if ($tend) {
4908: next if ($tend < $now);
4909: }
4910: if ($tstart) {
4911: next if ($tstart > $now);
4912: }
1.1058 raeburn 4913: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4914: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4915: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4916: if ($secpart eq '') {
4917: ($cnum,$role) = split(/_/,$cnumpart);
4918: $sec = 'none';
1.1058 raeburn 4919: $value .= $cnum.'/';
1.482 raeburn 4920: } else {
4921: $cnum = $cnumpart;
4922: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4923: $value .= $cnum.'/'.$sec;
4924: }
4925: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4926: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4927: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4928: }
4929: } else {
4930: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4931: }
1.482 raeburn 4932: }
4933: } else {
4934: foreach my $key (keys(%env)) {
1.483 albertel 4935: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4936: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4937: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4938: next if ($role eq 'ca' || $role eq 'aa');
4939: next if (%roles && !exists($roles{$role}));
4940: my ($starttime,$endtime)=split(/\./,$env{$key});
4941: my $active=1;
4942: if ($starttime) {
4943: if ($now<$starttime) { $active=0; }
4944: }
4945: if ($endtime) {
4946: if ($now>$endtime) { $active=0; }
4947: }
4948: if ($active) {
1.1058 raeburn 4949: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4950: if ($sec eq '') {
4951: $sec = 'none';
1.1058 raeburn 4952: } else {
4953: $value .= $sec;
4954: }
4955: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4956: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4957: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4958: }
4959: } else {
4960: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4961: }
1.474 raeburn 4962: }
4963: }
1.51 www 4964: }
4965: }
1.474 raeburn 4966: return %courses;
1.51 www 4967: }
1.37 matthew 4968:
1.54 www 4969: ###############################################
1.474 raeburn 4970:
4971: sub blockcheck {
1.1189 raeburn 4972: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4973:
1.1189 raeburn 4974: if (defined($udom) && defined($uname)) {
4975: # If uname and udom are for a course, check for blocks in the course.
4976: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4977: my ($startblock,$endblock,$triggerblock) =
4978: &get_blocks($setters,$activity,$udom,$uname,$url);
4979: return ($startblock,$endblock,$triggerblock);
4980: }
4981: } else {
1.490 raeburn 4982: $udom = $env{'user.domain'};
4983: $uname = $env{'user.name'};
4984: }
4985:
1.502 raeburn 4986: my $startblock = 0;
4987: my $endblock = 0;
1.1062 raeburn 4988: my $triggerblock = '';
1.482 raeburn 4989: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4990:
1.490 raeburn 4991: # If uname is for a user, and activity is course-specific, i.e.,
4992: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4993:
1.490 raeburn 4994: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1189 raeburn 4995: $activity eq 'groups' || $activity eq 'printout') &&
4996: ($env{'request.course.id'})) {
1.490 raeburn 4997: foreach my $key (keys(%live_courses)) {
4998: if ($key ne $env{'request.course.id'}) {
4999: delete($live_courses{$key});
5000: }
5001: }
5002: }
5003:
5004: my $otheruser = 0;
5005: my %own_courses;
5006: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5007: # Resource belongs to user other than current user.
5008: $otheruser = 1;
5009: # Gather courses for current user
5010: %own_courses =
5011: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5012: }
5013:
5014: # Gather active course roles - course coordinator, instructor,
5015: # exam proctor, ta, student, or custom role.
1.474 raeburn 5016:
5017: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5018: my ($cdom,$cnum);
5019: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5020: $cdom = $env{'course.'.$course.'.domain'};
5021: $cnum = $env{'course.'.$course.'.num'};
5022: } else {
1.490 raeburn 5023: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5024: }
5025: my $no_ownblock = 0;
5026: my $no_userblock = 0;
1.533 raeburn 5027: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5028: # Check if current user has 'evb' priv for this
5029: if (defined($own_courses{$course})) {
5030: foreach my $sec (keys(%{$own_courses{$course}})) {
5031: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5032: if ($sec ne 'none') {
5033: $checkrole .= '/'.$sec;
5034: }
5035: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5036: $no_ownblock = 1;
5037: last;
5038: }
5039: }
5040: }
5041: # if they have 'evb' priv and are currently not playing student
5042: next if (($no_ownblock) &&
5043: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5044: }
1.474 raeburn 5045: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5046: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5047: if ($sec ne 'none') {
1.482 raeburn 5048: $checkrole .= '/'.$sec;
1.474 raeburn 5049: }
1.490 raeburn 5050: if ($otheruser) {
5051: # Resource belongs to user other than current user.
5052: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5053: my (%allroles,%userroles);
5054: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5055: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5056: my ($trole,$tdom,$tnum,$tsec);
5057: if ($entry =~ /^cr/) {
5058: ($trole,$tdom,$tnum,$tsec) =
5059: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5060: } else {
5061: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5062: }
5063: my ($spec,$area,$trest);
5064: $area = '/'.$tdom.'/'.$tnum;
5065: $trest = $tnum;
5066: if ($tsec ne '') {
5067: $area .= '/'.$tsec;
5068: $trest .= '/'.$tsec;
5069: }
5070: $spec = $trole.'.'.$area;
5071: if ($trole =~ /^cr/) {
5072: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5073: $tdom,$spec,$trest,$area);
5074: } else {
5075: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5076: $tdom,$spec,$trest,$area);
5077: }
5078: }
1.1276 raeburn 5079: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 5080: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5081: if ($1) {
5082: $no_userblock = 1;
5083: last;
5084: }
1.486 raeburn 5085: }
5086: }
1.490 raeburn 5087: } else {
5088: # Resource belongs to current user
5089: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5090: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5091: $no_ownblock = 1;
5092: last;
5093: }
1.474 raeburn 5094: }
5095: }
5096: # if they have the evb priv and are currently not playing student
1.482 raeburn 5097: next if (($no_ownblock) &&
1.491 albertel 5098: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5099: next if ($no_userblock);
1.474 raeburn 5100:
1.866 kalberla 5101: # Retrieve blocking times and identity of locker for course
1.490 raeburn 5102: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 5103:
1.1062 raeburn 5104: my ($start,$end,$trigger) =
5105: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 5106: if (($start != 0) &&
5107: (($startblock == 0) || ($startblock > $start))) {
5108: $startblock = $start;
1.1062 raeburn 5109: if ($trigger ne '') {
5110: $triggerblock = $trigger;
5111: }
1.502 raeburn 5112: }
5113: if (($end != 0) &&
5114: (($endblock == 0) || ($endblock < $end))) {
5115: $endblock = $end;
1.1062 raeburn 5116: if ($trigger ne '') {
5117: $triggerblock = $trigger;
5118: }
1.502 raeburn 5119: }
1.490 raeburn 5120: }
1.1062 raeburn 5121: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5122: }
5123:
5124: sub get_blocks {
1.1062 raeburn 5125: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 5126: my $startblock = 0;
5127: my $endblock = 0;
1.1062 raeburn 5128: my $triggerblock = '';
1.490 raeburn 5129: my $course = $cdom.'_'.$cnum;
5130: $setters->{$course} = {};
5131: $setters->{$course}{'staff'} = [];
5132: $setters->{$course}{'times'} = [];
1.1062 raeburn 5133: $setters->{$course}{'triggers'} = [];
5134: my (@blockers,%triggered);
5135: my $now = time;
5136: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5137: if ($activity eq 'docs') {
5138: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
5139: foreach my $block (@blockers) {
5140: if ($block =~ /^firstaccess____(.+)$/) {
5141: my $item = $1;
5142: my $type = 'map';
5143: my $timersymb = $item;
5144: if ($item eq 'course') {
5145: $type = 'course';
5146: } elsif ($item =~ /___\d+___/) {
5147: $type = 'resource';
5148: } else {
5149: $timersymb = &Apache::lonnet::symbread($item);
5150: }
5151: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5152: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5153: $triggered{$block} = {
5154: start => $start,
5155: end => $end,
5156: type => $type,
5157: };
5158: }
5159: }
5160: } else {
5161: foreach my $block (keys(%commblocks)) {
5162: if ($block =~ m/^(\d+)____(\d+)$/) {
5163: my ($start,$end) = ($1,$2);
5164: if ($start <= time && $end >= time) {
5165: if (ref($commblocks{$block}) eq 'HASH') {
5166: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5167: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5168: unless(grep(/^\Q$block\E$/,@blockers)) {
5169: push(@blockers,$block);
5170: }
5171: }
5172: }
5173: }
5174: }
5175: } elsif ($block =~ /^firstaccess____(.+)$/) {
5176: my $item = $1;
5177: my $timersymb = $item;
5178: my $type = 'map';
5179: if ($item eq 'course') {
5180: $type = 'course';
5181: } elsif ($item =~ /___\d+___/) {
5182: $type = 'resource';
5183: } else {
5184: $timersymb = &Apache::lonnet::symbread($item);
5185: }
5186: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5187: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5188: if ($start && $end) {
5189: if (($start <= time) && ($end >= time)) {
5190: unless (grep(/^\Q$block\E$/,@blockers)) {
5191: push(@blockers,$block);
5192: $triggered{$block} = {
5193: start => $start,
5194: end => $end,
5195: type => $type,
5196: };
5197: }
5198: }
1.490 raeburn 5199: }
1.1062 raeburn 5200: }
5201: }
5202: }
5203: foreach my $blocker (@blockers) {
5204: my ($staff_name,$staff_dom,$title,$blocks) =
5205: &parse_block_record($commblocks{$blocker});
5206: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5207: my ($start,$end,$triggertype);
5208: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5209: ($start,$end) = ($1,$2);
5210: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5211: $start = $triggered{$blocker}{'start'};
5212: $end = $triggered{$blocker}{'end'};
5213: $triggertype = $triggered{$blocker}{'type'};
5214: }
5215: if ($start) {
5216: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5217: if ($triggertype) {
5218: push(@{$$setters{$course}{'triggers'}},$triggertype);
5219: } else {
5220: push(@{$$setters{$course}{'triggers'}},0);
5221: }
5222: if ( ($startblock == 0) || ($startblock > $start) ) {
5223: $startblock = $start;
5224: if ($triggertype) {
5225: $triggerblock = $blocker;
1.474 raeburn 5226: }
5227: }
1.1062 raeburn 5228: if ( ($endblock == 0) || ($endblock < $end) ) {
5229: $endblock = $end;
5230: if ($triggertype) {
5231: $triggerblock = $blocker;
5232: }
5233: }
1.474 raeburn 5234: }
5235: }
1.1062 raeburn 5236: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5237: }
5238:
5239: sub parse_block_record {
5240: my ($record) = @_;
5241: my ($setuname,$setudom,$title,$blocks);
5242: if (ref($record) eq 'HASH') {
5243: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5244: $title = &unescape($record->{'event'});
5245: $blocks = $record->{'blocks'};
5246: } else {
5247: my @data = split(/:/,$record,3);
5248: if (scalar(@data) eq 2) {
5249: $title = $data[1];
5250: ($setuname,$setudom) = split(/@/,$data[0]);
5251: } else {
5252: ($setuname,$setudom,$title) = @data;
5253: }
5254: $blocks = { 'com' => 'on' };
5255: }
5256: return ($setuname,$setudom,$title,$blocks);
5257: }
5258:
1.854 kalberla 5259: sub blocking_status {
1.1189 raeburn 5260: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 5261: my %setters;
1.890 droeschl 5262:
1.1061 raeburn 5263: # check for active blocking
1.1062 raeburn 5264: my ($startblock,$endblock,$triggerblock) =
1.1189 raeburn 5265: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 5266: my $blocked = 0;
5267: if ($startblock && $endblock) {
5268: $blocked = 1;
5269: }
1.890 droeschl 5270:
1.1061 raeburn 5271: # caller just wants to know whether a block is active
5272: if (!wantarray) { return $blocked; }
5273:
5274: # build a link to a popup window containing the details
5275: my $querystring = "?activity=$activity";
5276: # $uname and $udom decide whose portfolio the user is trying to look at
1.1232 raeburn 5277: if (($activity eq 'port') || ($activity eq 'passwd')) {
5278: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5279: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5280: } elsif ($activity eq 'docs') {
5281: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
5282: }
1.1061 raeburn 5283:
5284: my $output .= <<'END_MYBLOCK';
5285: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5286: var options = "width=" + w + ",height=" + h + ",";
5287: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5288: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5289: var newWin = window.open(url, wdwName, options);
5290: newWin.focus();
5291: }
1.890 droeschl 5292: END_MYBLOCK
1.854 kalberla 5293:
1.1061 raeburn 5294: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5295:
1.1061 raeburn 5296: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5297: my $text = &mt('Communication Blocked');
1.1217 raeburn 5298: my $class = 'LC_comblock';
1.1062 raeburn 5299: if ($activity eq 'docs') {
5300: $text = &mt('Content Access Blocked');
1.1217 raeburn 5301: $class = '';
1.1063 raeburn 5302: } elsif ($activity eq 'printout') {
5303: $text = &mt('Printing Blocked');
1.1232 raeburn 5304: } elsif ($activity eq 'passwd') {
5305: $text = &mt('Password Changing Blocked');
1.1062 raeburn 5306: }
1.1061 raeburn 5307: $output .= <<"END_BLOCK";
1.1217 raeburn 5308: <div class='$class'>
1.869 kalberla 5309: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5310: title='$text'>
5311: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5312: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5313: title='$text'>$text</a>
1.867 kalberla 5314: </div>
5315:
5316: END_BLOCK
1.474 raeburn 5317:
1.1061 raeburn 5318: return ($blocked, $output);
1.854 kalberla 5319: }
1.490 raeburn 5320:
1.60 matthew 5321: ###############################################
5322:
1.682 raeburn 5323: sub check_ip_acc {
1.1201 raeburn 5324: my ($acc,$clientip)=@_;
1.682 raeburn 5325: &Apache::lonxml::debug("acc is $acc");
5326: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5327: return 1;
5328: }
1.1219 raeburn 5329: my $allowed;
1.1252 raeburn 5330: my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682 raeburn 5331:
5332: my $name;
1.1219 raeburn 5333: my %access = (
5334: allowfrom => 1,
5335: denyfrom => 0,
5336: );
5337: my @allows;
5338: my @denies;
5339: foreach my $item (split(',',$acc)) {
5340: $item =~ s/^\s*//;
5341: $item =~ s/\s*$//;
5342: my $pattern;
5343: if ($item =~ /^\!(.+)$/) {
5344: push(@denies,$1);
5345: } else {
5346: push(@allows,$item);
5347: }
5348: }
5349: my $numdenies = scalar(@denies);
5350: my $numallows = scalar(@allows);
5351: my $count = 0;
5352: foreach my $pattern (@denies,@allows) {
5353: $count ++;
5354: my $acctype = 'allowfrom';
5355: if ($count <= $numdenies) {
5356: $acctype = 'denyfrom';
5357: }
1.682 raeburn 5358: if ($pattern =~ /\*$/) {
5359: #35.8.*
5360: $pattern=~s/\*//;
1.1219 raeburn 5361: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5362: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5363: #35.8.3.[34-56]
5364: my $low=$2;
5365: my $high=$3;
5366: $pattern=$1;
5367: if ($ip =~ /^\Q$pattern\E/) {
5368: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5369: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5370: }
5371: } elsif ($pattern =~ /^\*/) {
5372: #*.msu.edu
5373: $pattern=~s/\*//;
5374: if (!defined($name)) {
5375: use Socket;
5376: my $netaddr=inet_aton($ip);
5377: ($name)=gethostbyaddr($netaddr,AF_INET);
5378: }
1.1219 raeburn 5379: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5380: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5381: #127.0.0.1
1.1219 raeburn 5382: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5383: } else {
5384: #some.name.com
5385: if (!defined($name)) {
5386: use Socket;
5387: my $netaddr=inet_aton($ip);
5388: ($name)=gethostbyaddr($netaddr,AF_INET);
5389: }
1.1219 raeburn 5390: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5391: }
5392: if ($allowed =~ /^(0|1)$/) { last; }
5393: }
5394: if ($allowed eq '') {
5395: if ($numdenies && !$numallows) {
5396: $allowed = 1;
5397: } else {
5398: $allowed = 0;
1.682 raeburn 5399: }
5400: }
5401: return $allowed;
5402: }
5403:
5404: ###############################################
5405:
1.60 matthew 5406: =pod
5407:
1.112 bowersj2 5408: =head1 Domain Template Functions
5409:
5410: =over 4
5411:
5412: =item * &determinedomain()
1.60 matthew 5413:
5414: Inputs: $domain (usually will be undef)
5415:
1.63 www 5416: Returns: Determines which domain should be used for designs
1.60 matthew 5417:
5418: =cut
1.54 www 5419:
1.60 matthew 5420: ###############################################
1.63 www 5421: sub determinedomain {
5422: my $domain=shift;
1.531 albertel 5423: if (! $domain) {
1.60 matthew 5424: # Determine domain if we have not been given one
1.893 raeburn 5425: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5426: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5427: if ($env{'request.role.domain'}) {
5428: $domain=$env{'request.role.domain'};
1.60 matthew 5429: }
5430: }
1.63 www 5431: return $domain;
5432: }
5433: ###############################################
1.517 raeburn 5434:
1.518 albertel 5435: sub devalidate_domconfig_cache {
5436: my ($udom)=@_;
5437: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5438: }
5439:
5440: # ---------------------- Get domain configuration for a domain
5441: sub get_domainconf {
5442: my ($udom) = @_;
5443: my $cachetime=1800;
5444: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5445: if (defined($cached)) { return %{$result}; }
5446:
5447: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5448: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5449: my (%designhash,%legacy);
1.518 albertel 5450: if (keys(%domconfig) > 0) {
5451: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5452: if (keys(%{$domconfig{'login'}})) {
5453: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5454: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5455: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5456: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5457: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5458: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5459: if ($key eq 'loginvia') {
5460: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5461: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5462: $designhash{$udom.'.login.loginvia'} = $server;
5463: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5464:
5465: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5466: } else {
5467: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5468: }
1.948 raeburn 5469: }
1.1208 raeburn 5470: } elsif ($key eq 'headtag') {
5471: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5472: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5473: }
1.946 raeburn 5474: }
1.1208 raeburn 5475: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5476: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5477: }
1.946 raeburn 5478: }
5479: }
5480: }
5481: } else {
5482: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5483: $designhash{$udom.'.login.'.$key.'_'.$img} =
5484: $domconfig{'login'}{$key}{$img};
5485: }
1.699 raeburn 5486: }
5487: } else {
5488: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5489: }
1.632 raeburn 5490: }
5491: } else {
5492: $legacy{'login'} = 1;
1.518 albertel 5493: }
1.632 raeburn 5494: } else {
5495: $legacy{'login'} = 1;
1.518 albertel 5496: }
5497: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5498: if (keys(%{$domconfig{'rolecolors'}})) {
5499: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5500: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5501: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5502: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5503: }
1.518 albertel 5504: }
5505: }
1.632 raeburn 5506: } else {
5507: $legacy{'rolecolors'} = 1;
1.518 albertel 5508: }
1.632 raeburn 5509: } else {
5510: $legacy{'rolecolors'} = 1;
1.518 albertel 5511: }
1.948 raeburn 5512: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5513: if ($domconfig{'autoenroll'}{'co-owners'}) {
5514: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5515: }
5516: }
1.632 raeburn 5517: if (keys(%legacy) > 0) {
5518: my %legacyhash = &get_legacy_domconf($udom);
5519: foreach my $item (keys(%legacyhash)) {
5520: if ($item =~ /^\Q$udom\E\.login/) {
5521: if ($legacy{'login'}) {
5522: $designhash{$item} = $legacyhash{$item};
5523: }
5524: } else {
5525: if ($legacy{'rolecolors'}) {
5526: $designhash{$item} = $legacyhash{$item};
5527: }
1.518 albertel 5528: }
5529: }
5530: }
1.632 raeburn 5531: } else {
5532: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5533: }
5534: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5535: $cachetime);
5536: return %designhash;
5537: }
5538:
1.632 raeburn 5539: sub get_legacy_domconf {
5540: my ($udom) = @_;
5541: my %legacyhash;
5542: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5543: my $designfile = $designdir.'/'.$udom.'.tab';
5544: if (-e $designfile) {
5545: if ( open (my $fh,"<$designfile") ) {
5546: while (my $line = <$fh>) {
5547: next if ($line =~ /^\#/);
5548: chomp($line);
5549: my ($key,$val)=(split(/\=/,$line));
5550: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5551: }
5552: close($fh);
5553: }
5554: }
1.1026 raeburn 5555: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5556: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5557: }
5558: return %legacyhash;
5559: }
5560:
1.63 www 5561: =pod
5562:
1.112 bowersj2 5563: =item * &domainlogo()
1.63 www 5564:
5565: Inputs: $domain (usually will be undef)
5566:
5567: Returns: A link to a domain logo, if the domain logo exists.
5568: If the domain logo does not exist, a description of the domain.
5569:
5570: =cut
1.112 bowersj2 5571:
1.63 www 5572: ###############################################
5573: sub domainlogo {
1.517 raeburn 5574: my $domain = &determinedomain(shift);
1.518 albertel 5575: my %designhash = &get_domainconf($domain);
1.517 raeburn 5576: # See if there is a logo
5577: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5578: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5579: if ($imgsrc =~ m{^/(adm|res)/}) {
5580: if ($imgsrc =~ m{^/res/}) {
5581: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5582: &Apache::lonnet::repcopy($local_name);
5583: }
5584: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5585: }
5586: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5587: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5588: return &Apache::lonnet::domain($domain,'description');
1.59 www 5589: } else {
1.60 matthew 5590: return '';
1.59 www 5591: }
5592: }
1.63 www 5593: ##############################################
5594:
5595: =pod
5596:
1.112 bowersj2 5597: =item * &designparm()
1.63 www 5598:
5599: Inputs: $which parameter; $domain (usually will be undef)
5600:
5601: Returns: value of designparamter $which
5602:
5603: =cut
1.112 bowersj2 5604:
1.397 albertel 5605:
1.400 albertel 5606: ##############################################
1.397 albertel 5607: sub designparm {
5608: my ($which,$domain)=@_;
5609: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5610: return $env{'environment.color.'.$which};
1.96 www 5611: }
1.63 www 5612: $domain=&determinedomain($domain);
1.1016 raeburn 5613: my %domdesign;
5614: unless ($domain eq 'public') {
5615: %domdesign = &get_domainconf($domain);
5616: }
1.520 raeburn 5617: my $output;
1.517 raeburn 5618: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5619: $output = $domdesign{$domain.'.'.$which};
1.63 www 5620: } else {
1.520 raeburn 5621: $output = $defaultdesign{$which};
5622: }
5623: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5624: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5625: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5626: if ($output =~ m{^/res/}) {
5627: my $local_name = &Apache::lonnet::filelocation('',$output);
5628: &Apache::lonnet::repcopy($local_name);
5629: }
1.520 raeburn 5630: $output = &lonhttpdurl($output);
5631: }
1.63 www 5632: }
1.520 raeburn 5633: return $output;
1.63 www 5634: }
1.59 www 5635:
1.822 bisitz 5636: ##############################################
5637: =pod
5638:
1.832 bisitz 5639: =item * &authorspace()
5640:
1.1028 raeburn 5641: Inputs: $url (usually will be undef).
1.832 bisitz 5642:
1.1132 raeburn 5643: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5644: directory being viewed (or for which action is being taken).
5645: If $url is provided, and begins /priv/<domain>/<uname>
5646: the path will be that portion of the $context argument.
5647: Otherwise the path will be for the author space of the current
5648: user when the current role is author, or for that of the
5649: co-author/assistant co-author space when the current role
5650: is co-author or assistant co-author.
1.832 bisitz 5651:
5652: =cut
5653:
5654: sub authorspace {
1.1028 raeburn 5655: my ($url) = @_;
5656: if ($url ne '') {
5657: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5658: return $1;
5659: }
5660: }
1.832 bisitz 5661: my $caname = '';
1.1024 www 5662: my $cadom = '';
1.1028 raeburn 5663: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5664: ($cadom,$caname) =
1.832 bisitz 5665: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5666: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5667: $caname = $env{'user.name'};
1.1024 www 5668: $cadom = $env{'user.domain'};
1.832 bisitz 5669: }
1.1028 raeburn 5670: if (($caname ne '') && ($cadom ne '')) {
5671: return "/priv/$cadom/$caname/";
5672: }
5673: return;
1.832 bisitz 5674: }
5675:
5676: ##############################################
5677: =pod
5678:
1.822 bisitz 5679: =item * &head_subbox()
5680:
5681: Inputs: $content (contains HTML code with page functions, etc.)
5682:
5683: Returns: HTML div with $content
5684: To be included in page header
5685:
5686: =cut
5687:
5688: sub head_subbox {
5689: my ($content)=@_;
5690: my $output =
1.993 raeburn 5691: '<div class="LC_head_subbox">'
1.822 bisitz 5692: .$content
5693: .'</div>'
5694: }
5695:
5696: ##############################################
5697: =pod
5698:
5699: =item * &CSTR_pageheader()
5700:
1.1026 raeburn 5701: Input: (optional) filename from which breadcrumb trail is built.
5702: In most cases no input as needed, as $env{'request.filename'}
5703: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5704:
5705: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5706: To be included on Authoring Space pages
1.822 bisitz 5707:
5708: =cut
5709:
5710: sub CSTR_pageheader {
1.1026 raeburn 5711: my ($trailfile) = @_;
5712: if ($trailfile eq '') {
5713: $trailfile = $env{'request.filename'};
5714: }
5715:
5716: # this is for resources; directories have customtitle, and crumbs
5717: # and select recent are created in lonpubdir.pm
5718:
5719: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5720: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5721: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5722: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5723: $formaction =~ s{/+}{/}g;
1.822 bisitz 5724:
5725: my $parentpath = '';
5726: my $lastitem = '';
5727: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5728: $parentpath = $1;
5729: $lastitem = $2;
5730: } else {
5731: $lastitem = $thisdisfn;
5732: }
1.921 bisitz 5733:
1.1246 raeburn 5734: my ($crsauthor,$title);
5735: if (($env{'request.course.id'}) &&
5736: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 5737: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 5738: $crsauthor = 1;
5739: $title = &mt('Course Authoring Space');
5740: } else {
5741: $title = &mt('Authoring Space');
5742: }
5743:
1.921 bisitz 5744: my $output =
1.822 bisitz 5745: '<div>'
5746: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 5747: .'<b>'.$title.'</b> '
1.822 bisitz 5748: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5749: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5750: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5751:
5752: if ($lastitem) {
5753: $output .=
5754: '<span class="LC_filename">'
5755: .$lastitem
5756: .'</span>';
5757: }
1.1245 raeburn 5758:
1.1246 raeburn 5759: if ($crsauthor) {
5760: $output .= '</form>'.&Apache::lonmenu::constspaceform();
5761: } else {
5762: $output .=
5763: '<br />'
5764: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5765: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5766: .'</form>'
5767: .&Apache::lonmenu::constspaceform();
5768: }
5769: $output .= '</div>';
1.921 bisitz 5770:
5771: return $output;
1.822 bisitz 5772: }
5773:
1.60 matthew 5774: ###############################################
5775: ###############################################
5776:
5777: =pod
5778:
1.112 bowersj2 5779: =back
5780:
1.549 albertel 5781: =head1 HTML Helpers
1.112 bowersj2 5782:
5783: =over 4
5784:
5785: =item * &bodytag()
1.60 matthew 5786:
5787: Returns a uniform header for LON-CAPA web pages.
5788:
5789: Inputs:
5790:
1.112 bowersj2 5791: =over 4
5792:
5793: =item * $title, A title to be displayed on the page.
5794:
5795: =item * $function, the current role (can be undef).
5796:
5797: =item * $addentries, extra parameters for the <body> tag.
5798:
5799: =item * $bodyonly, if defined, only return the <body> tag.
5800:
5801: =item * $domain, if defined, force a given domain.
5802:
5803: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5804: text interface only)
1.60 matthew 5805:
1.814 bisitz 5806: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5807: navigational links
1.317 albertel 5808:
1.338 albertel 5809: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5810:
1.460 albertel 5811: =item * $args, optional argument valid values are
5812: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 5813: use_absolute -> for external resource or syllabus, this will
5814: contain https://<hostname> if server uses
5815: https (as per hosts.tab), but request is for http
5816: hostname -> hostname, from $r->hostname().
1.460 albertel 5817:
1.1096 raeburn 5818: =item * $advtoolsref, optional argument, ref to an array containing
5819: inlineremote items to be added in "Functions" menu below
5820: breadcrumbs.
5821:
1.112 bowersj2 5822: =back
5823:
1.60 matthew 5824: Returns: A uniform header for LON-CAPA web pages.
5825: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5826: If $bodyonly is undef or zero, an html string containing a <body> tag and
5827: other decorations will be returned.
5828:
5829: =cut
5830:
1.54 www 5831: sub bodytag {
1.831 bisitz 5832: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5833: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5834:
1.954 raeburn 5835: my $public;
5836: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5837: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5838: $public = 1;
5839: }
1.460 albertel 5840: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 5841: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 5842: my $hostname = $args->{'hostname'};
1.339 albertel 5843:
1.183 matthew 5844: $function = &get_users_function() if (!$function);
1.339 albertel 5845: my $img = &designparm($function.'.img',$domain);
5846: my $font = &designparm($function.'.font',$domain);
5847: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5848:
1.803 bisitz 5849: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5850: 'bgcolor' => $pgbg,
1.339 albertel 5851: 'text' => $font,
5852: 'alink' => &designparm($function.'.alink',$domain),
5853: 'vlink' => &designparm($function.'.vlink',$domain),
5854: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5855: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5856:
1.63 www 5857: # role and realm
1.1178 raeburn 5858: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5859: if ($realm) {
5860: $realm = '/'.$realm;
5861: }
1.378 raeburn 5862: if ($role eq 'ca') {
1.479 albertel 5863: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5864: $realm = &plainname($rname,$rdom);
1.378 raeburn 5865: }
1.55 www 5866: # realm
1.258 albertel 5867: if ($env{'request.course.id'}) {
1.378 raeburn 5868: if ($env{'request.role'} !~ /^cr/) {
5869: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 5870: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 5871: if ($env{'request.role.desc'}) {
5872: $role = $env{'request.role.desc'};
5873: } else {
5874: $role = &mt('Helpdesk[_1]',' '.$2);
5875: }
1.1257 raeburn 5876: } else {
5877: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5878: }
1.898 raeburn 5879: if ($env{'request.course.sec'}) {
5880: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5881: }
1.359 albertel 5882: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5883: } else {
5884: $role = &Apache::lonnet::plaintext($role);
1.54 www 5885: }
1.433 albertel 5886:
1.359 albertel 5887: if (!$realm) { $realm=' '; }
1.330 albertel 5888:
1.438 albertel 5889: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5890:
1.101 www 5891: # construct main body tag
1.359 albertel 5892: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 5893: &Apache::lontexconvert::init_math_support();
1.252 albertel 5894:
1.1131 raeburn 5895: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5896:
1.1130 raeburn 5897: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5898: return $bodytag;
1.1130 raeburn 5899: }
1.359 albertel 5900:
1.954 raeburn 5901: if ($public) {
1.433 albertel 5902: undef($role);
5903: }
1.359 albertel 5904:
1.762 bisitz 5905: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5906: #
5907: # Extra info if you are the DC
5908: my $dc_info = '';
5909: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5910: $env{'course.'.$env{'request.course.id'}.
5911: '.domain'}.'/'})) {
5912: my $cid = $env{'request.course.id'};
1.917 raeburn 5913: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5914: $dc_info =~ s/\s+$//;
1.359 albertel 5915: }
5916:
1.1237 raeburn 5917: my $crstype;
5918: if ($env{'request.course.id'}) {
5919: $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
5920: } elsif ($args->{'crstype'}) {
5921: $crstype = $args->{'crstype'};
5922: }
5923: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
5924: undef($role);
5925: } else {
1.1242 raeburn 5926: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 5927: }
1.853 droeschl 5928:
1.903 droeschl 5929: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5930:
5931: # if ($env{'request.state'} eq 'construct') {
5932: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5933: # }
5934:
1.1130 raeburn 5935: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 5936: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5937:
1.1237 raeburn 5938: my ($left,$right) = Apache::lonmenu::primary_menu($crstype);
1.359 albertel 5939:
1.916 droeschl 5940: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5941: if ($dc_info) {
5942: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5943: }
1.1130 raeburn 5944: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 5945: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5946: return $bodytag;
5947: }
1.894 droeschl 5948:
1.927 raeburn 5949: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 5950: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5951: }
1.916 droeschl 5952:
1.1130 raeburn 5953: $bodytag .= $right;
1.852 droeschl 5954:
1.917 raeburn 5955: if ($dc_info) {
5956: $dc_info = &dc_courseid_toggle($dc_info);
5957: }
5958: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5959:
1.1169 raeburn 5960: #if directed to not display the secondary menu, don't.
1.1168 raeburn 5961: if ($args->{'no_secondary_menu'}) {
5962: return $bodytag;
5963: }
1.1169 raeburn 5964: #don't show menus for public users
1.954 raeburn 5965: if (!$public){
1.1154 raeburn 5966: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5967: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5968: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5969: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5970: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1274 raeburn 5971: $args->{'bread_crumbs'},'','',$hostname);
1.1096 raeburn 5972: } elsif ($forcereg) {
5973: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 raeburn 5974: $args->{'group'},
1.1274 raeburn 5975: $args->{'hide_buttons'},
5976: $hostname);
1.1096 raeburn 5977: } else {
5978: $bodytag .=
5979: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5980: $forcereg,$args->{'group'},
5981: $args->{'bread_crumbs'},
1.1274 raeburn 5982: $advtoolsref,'',$hostname);
1.920 raeburn 5983: }
1.903 droeschl 5984: }else{
5985: # this is to seperate menu from content when there's no secondary
5986: # menu. Especially needed for public accessible ressources.
5987: $bodytag .= '<hr style="clear:both" />';
5988: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5989: }
1.903 droeschl 5990:
1.235 raeburn 5991: return $bodytag;
1.182 matthew 5992: }
5993:
1.917 raeburn 5994: sub dc_courseid_toggle {
5995: my ($dc_info) = @_;
1.980 raeburn 5996: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5997: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5998: &mt('(More ...)').'</a></span>'.
5999: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6000: }
6001:
1.330 albertel 6002: sub make_attr_string {
6003: my ($register,$attr_ref) = @_;
6004:
6005: if ($attr_ref && !ref($attr_ref)) {
6006: die("addentries Must be a hash ref ".
6007: join(':',caller(1))." ".
6008: join(':',caller(0))." ");
6009: }
6010:
6011: if ($register) {
1.339 albertel 6012: my ($on_load,$on_unload);
6013: foreach my $key (keys(%{$attr_ref})) {
6014: if (lc($key) eq 'onload') {
6015: $on_load.=$attr_ref->{$key}.';';
6016: delete($attr_ref->{$key});
6017:
6018: } elsif (lc($key) eq 'onunload') {
6019: $on_unload.=$attr_ref->{$key}.';';
6020: delete($attr_ref->{$key});
6021: }
6022: }
1.953 droeschl 6023: $attr_ref->{'onload'} = $on_load;
6024: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6025: }
1.339 albertel 6026:
1.330 albertel 6027: my $attr_string;
1.1159 raeburn 6028: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6029: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6030: }
6031: return $attr_string;
6032: }
6033:
6034:
1.182 matthew 6035: ###############################################
1.251 albertel 6036: ###############################################
6037:
6038: =pod
6039:
6040: =item * &endbodytag()
6041:
6042: Returns a uniform footer for LON-CAPA web pages.
6043:
1.635 raeburn 6044: Inputs: 1 - optional reference to an args hash
6045: If in the hash, key for noredirectlink has a value which evaluates to true,
6046: a 'Continue' link is not displayed if the page contains an
6047: internal redirect in the <head></head> section,
6048: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6049:
6050: =cut
6051:
6052: sub endbodytag {
1.635 raeburn 6053: my ($args) = @_;
1.1080 raeburn 6054: my $endbodytag;
6055: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6056: $endbodytag='</body>';
6057: }
1.315 albertel 6058: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6059: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6060: $endbodytag=
6061: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6062: &mt('Continue').'</a>'.
6063: $endbodytag;
6064: }
1.315 albertel 6065: }
1.251 albertel 6066: return $endbodytag;
6067: }
6068:
1.352 albertel 6069: =pod
6070:
6071: =item * &standard_css()
6072:
6073: Returns a style sheet
6074:
6075: Inputs: (all optional)
6076: domain -> force to color decorate a page for a specific
6077: domain
6078: function -> force usage of a specific rolish color scheme
6079: bgcolor -> override the default page bgcolor
6080:
6081: =cut
6082:
1.343 albertel 6083: sub standard_css {
1.345 albertel 6084: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6085: $function = &get_users_function() if (!$function);
6086: my $img = &designparm($function.'.img', $domain);
6087: my $tabbg = &designparm($function.'.tabbg', $domain);
6088: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6089: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6090: #second colour for later usage
1.345 albertel 6091: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6092: my $pgbg_or_bgcolor =
6093: $bgcolor ||
1.352 albertel 6094: &designparm($function.'.pgbg', $domain);
1.382 albertel 6095: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6096: my $alink = &designparm($function.'.alink', $domain);
6097: my $vlink = &designparm($function.'.vlink', $domain);
6098: my $link = &designparm($function.'.link', $domain);
6099:
1.602 albertel 6100: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6101: my $mono = 'monospace';
1.850 bisitz 6102: my $data_table_head = $sidebg;
6103: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6104: my $data_table_dark = '#E0E0E0';
1.470 banghart 6105: my $data_table_darker = '#CCCCCC';
1.349 albertel 6106: my $data_table_highlight = '#FFFF00';
1.352 albertel 6107: my $mail_new = '#FFBB77';
6108: my $mail_new_hover = '#DD9955';
6109: my $mail_read = '#BBBB77';
6110: my $mail_read_hover = '#999944';
6111: my $mail_replied = '#AAAA88';
6112: my $mail_replied_hover = '#888855';
6113: my $mail_other = '#99BBBB';
6114: my $mail_other_hover = '#669999';
1.391 albertel 6115: my $table_header = '#DDDDDD';
1.489 raeburn 6116: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6117: my $lg_border_color = '#C8C8C8';
1.952 onken 6118: my $button_hover = '#BF2317';
1.392 albertel 6119:
1.608 albertel 6120: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6121: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6122: : '0 3px 0 4px';
1.448 albertel 6123:
1.523 albertel 6124:
1.343 albertel 6125: return <<END;
1.947 droeschl 6126:
6127: /* needed for iframe to allow 100% height in FF */
6128: body, html {
6129: margin: 0;
6130: padding: 0 0.5%;
6131: height: 99%; /* to avoid scrollbars */
6132: }
6133:
1.795 www 6134: body {
1.911 bisitz 6135: font-family: $sans;
6136: line-height:130%;
6137: font-size:0.83em;
6138: color:$font;
1.795 www 6139: }
6140:
1.959 onken 6141: a:focus,
6142: a:focus img {
1.795 www 6143: color: red;
6144: }
1.698 harmsja 6145:
1.911 bisitz 6146: form, .inline {
6147: display: inline;
1.795 www 6148: }
1.721 harmsja 6149:
1.795 www 6150: .LC_right {
1.911 bisitz 6151: text-align:right;
1.795 www 6152: }
6153:
6154: .LC_middle {
1.911 bisitz 6155: vertical-align:middle;
1.795 www 6156: }
1.721 harmsja 6157:
1.1130 raeburn 6158: .LC_floatleft {
6159: float: left;
6160: }
6161:
6162: .LC_floatright {
6163: float: right;
6164: }
6165:
1.911 bisitz 6166: .LC_400Box {
6167: width:400px;
6168: }
1.721 harmsja 6169:
1.947 droeschl 6170: .LC_iframecontainer {
6171: width: 98%;
6172: margin: 0;
6173: position: fixed;
6174: top: 8.5em;
6175: bottom: 0;
6176: }
6177:
6178: .LC_iframecontainer iframe{
6179: border: none;
6180: width: 100%;
6181: height: 100%;
6182: }
6183:
1.778 bisitz 6184: .LC_filename {
6185: font-family: $mono;
6186: white-space:pre;
1.921 bisitz 6187: font-size: 120%;
1.778 bisitz 6188: }
6189:
6190: .LC_fileicon {
6191: border: none;
6192: height: 1.3em;
6193: vertical-align: text-bottom;
6194: margin-right: 0.3em;
6195: text-decoration:none;
6196: }
6197:
1.1008 www 6198: .LC_setting {
6199: text-decoration:underline;
6200: }
6201:
1.350 albertel 6202: .LC_error {
6203: color: red;
6204: }
1.795 www 6205:
1.1097 bisitz 6206: .LC_warning {
6207: color: darkorange;
6208: }
6209:
1.457 albertel 6210: .LC_diff_removed {
1.733 bisitz 6211: color: red;
1.394 albertel 6212: }
1.532 albertel 6213:
6214: .LC_info,
1.457 albertel 6215: .LC_success,
6216: .LC_diff_added {
1.350 albertel 6217: color: green;
6218: }
1.795 www 6219:
1.802 bisitz 6220: div.LC_confirm_box {
6221: background-color: #FAFAFA;
6222: border: 1px solid $lg_border_color;
6223: margin-right: 0;
6224: padding: 5px;
6225: }
6226:
6227: div.LC_confirm_box .LC_error img,
6228: div.LC_confirm_box .LC_success img {
6229: vertical-align: middle;
6230: }
6231:
1.1242 raeburn 6232: .LC_maxwidth {
6233: max-width: 100%;
6234: height: auto;
6235: }
6236:
1.1243 raeburn 6237: .LC_textsize_mobile {
6238: \@media only screen and (max-device-width: 480px) {
6239: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6240: }
6241: }
6242:
1.440 albertel 6243: .LC_icon {
1.771 droeschl 6244: border: none;
1.790 droeschl 6245: vertical-align: middle;
1.771 droeschl 6246: }
6247:
1.543 albertel 6248: .LC_docs_spacer {
6249: width: 25px;
6250: height: 1px;
1.771 droeschl 6251: border: none;
1.543 albertel 6252: }
1.346 albertel 6253:
1.532 albertel 6254: .LC_internal_info {
1.735 bisitz 6255: color: #999999;
1.532 albertel 6256: }
6257:
1.794 www 6258: .LC_discussion {
1.1050 www 6259: background: $data_table_dark;
1.911 bisitz 6260: border: 1px solid black;
6261: margin: 2px;
1.794 www 6262: }
6263:
6264: .LC_disc_action_left {
1.1050 www 6265: background: $sidebg;
1.911 bisitz 6266: text-align: left;
1.1050 www 6267: padding: 4px;
6268: margin: 2px;
1.794 www 6269: }
6270:
6271: .LC_disc_action_right {
1.1050 www 6272: background: $sidebg;
1.911 bisitz 6273: text-align: right;
1.1050 www 6274: padding: 4px;
6275: margin: 2px;
1.794 www 6276: }
6277:
6278: .LC_disc_new_item {
1.911 bisitz 6279: background: white;
6280: border: 2px solid red;
1.1050 www 6281: margin: 4px;
6282: padding: 4px;
1.794 www 6283: }
6284:
6285: .LC_disc_old_item {
1.911 bisitz 6286: background: white;
1.1050 www 6287: margin: 4px;
6288: padding: 4px;
1.794 www 6289: }
6290:
1.458 albertel 6291: table.LC_pastsubmission {
6292: border: 1px solid black;
6293: margin: 2px;
6294: }
6295:
1.924 bisitz 6296: table#LC_menubuttons {
1.345 albertel 6297: width: 100%;
6298: background: $pgbg;
1.392 albertel 6299: border: 2px;
1.402 albertel 6300: border-collapse: separate;
1.803 bisitz 6301: padding: 0;
1.345 albertel 6302: }
1.392 albertel 6303:
1.801 tempelho 6304: table#LC_title_bar a {
6305: color: $fontmenu;
6306: }
1.836 bisitz 6307:
1.807 droeschl 6308: table#LC_title_bar {
1.819 tempelho 6309: clear: both;
1.836 bisitz 6310: display: none;
1.807 droeschl 6311: }
6312:
1.795 www 6313: table#LC_title_bar,
1.933 droeschl 6314: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6315: table#LC_title_bar.LC_with_remote {
1.359 albertel 6316: width: 100%;
1.392 albertel 6317: border-color: $pgbg;
6318: border-style: solid;
6319: border-width: $border;
1.379 albertel 6320: background: $pgbg;
1.801 tempelho 6321: color: $fontmenu;
1.392 albertel 6322: border-collapse: collapse;
1.803 bisitz 6323: padding: 0;
1.819 tempelho 6324: margin: 0;
1.359 albertel 6325: }
1.795 www 6326:
1.933 droeschl 6327: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6328: margin: 0;
6329: padding: 0;
1.933 droeschl 6330: position: relative;
6331: list-style: none;
1.913 droeschl 6332: }
1.933 droeschl 6333: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6334: display: inline;
6335: }
1.933 droeschl 6336:
6337: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6338: padding: 0;
1.933 droeschl 6339: margin: 0;
6340: float: left;
1.913 droeschl 6341: }
1.933 droeschl 6342: .LC_breadcrumb_tools_tools {
6343: padding: 0;
6344: margin: 0;
1.913 droeschl 6345: float: right;
6346: }
6347:
1.1240 raeburn 6348: .LC_placement_prog {
6349: padding-right: 20px;
6350: font-weight: bold;
6351: font-size: 90%;
6352: }
6353:
1.359 albertel 6354: table#LC_title_bar td {
6355: background: $tabbg;
6356: }
1.795 www 6357:
1.911 bisitz 6358: table#LC_menubuttons img {
1.803 bisitz 6359: border: none;
1.346 albertel 6360: }
1.795 www 6361:
1.842 droeschl 6362: .LC_breadcrumbs_component {
1.911 bisitz 6363: float: right;
6364: margin: 0 1em;
1.357 albertel 6365: }
1.842 droeschl 6366: .LC_breadcrumbs_component img {
1.911 bisitz 6367: vertical-align: middle;
1.777 tempelho 6368: }
1.795 www 6369:
1.1243 raeburn 6370: .LC_breadcrumbs_hoverable {
6371: background: $sidebg;
6372: }
6373:
1.383 albertel 6374: td.LC_table_cell_checkbox {
6375: text-align: center;
6376: }
1.795 www 6377:
6378: .LC_fontsize_small {
1.911 bisitz 6379: font-size: 70%;
1.705 tempelho 6380: }
6381:
1.844 bisitz 6382: #LC_breadcrumbs {
1.911 bisitz 6383: clear:both;
6384: background: $sidebg;
6385: border-bottom: 1px solid $lg_border_color;
6386: line-height: 2.5em;
1.933 droeschl 6387: overflow: hidden;
1.911 bisitz 6388: margin: 0;
6389: padding: 0;
1.995 raeburn 6390: text-align: left;
1.819 tempelho 6391: }
1.862 bisitz 6392:
1.1098 bisitz 6393: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6394: clear:both;
6395: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6396: border: 1px solid $sidebg;
1.1098 bisitz 6397: margin: 0 0 10px 0;
1.966 bisitz 6398: padding: 3px;
1.995 raeburn 6399: text-align: left;
1.822 bisitz 6400: }
6401:
1.795 www 6402: .LC_fontsize_medium {
1.911 bisitz 6403: font-size: 85%;
1.705 tempelho 6404: }
6405:
1.795 www 6406: .LC_fontsize_large {
1.911 bisitz 6407: font-size: 120%;
1.705 tempelho 6408: }
6409:
1.346 albertel 6410: .LC_menubuttons_inline_text {
6411: color: $font;
1.698 harmsja 6412: font-size: 90%;
1.701 harmsja 6413: padding-left:3px;
1.346 albertel 6414: }
6415:
1.934 droeschl 6416: .LC_menubuttons_inline_text img{
6417: vertical-align: middle;
6418: }
6419:
1.1051 www 6420: li.LC_menubuttons_inline_text img {
1.951 onken 6421: cursor:pointer;
1.1002 droeschl 6422: text-decoration: none;
1.951 onken 6423: }
6424:
1.526 www 6425: .LC_menubuttons_link {
6426: text-decoration: none;
6427: }
1.795 www 6428:
1.522 albertel 6429: .LC_menubuttons_category {
1.521 www 6430: color: $font;
1.526 www 6431: background: $pgbg;
1.521 www 6432: font-size: larger;
6433: font-weight: bold;
6434: }
6435:
1.346 albertel 6436: td.LC_menubuttons_text {
1.911 bisitz 6437: color: $font;
1.346 albertel 6438: }
1.706 harmsja 6439:
1.346 albertel 6440: .LC_current_location {
6441: background: $tabbg;
6442: }
1.795 www 6443:
1.938 bisitz 6444: table.LC_data_table {
1.347 albertel 6445: border: 1px solid #000000;
1.402 albertel 6446: border-collapse: separate;
1.426 albertel 6447: border-spacing: 1px;
1.610 albertel 6448: background: $pgbg;
1.347 albertel 6449: }
1.795 www 6450:
1.422 albertel 6451: .LC_data_table_dense {
6452: font-size: small;
6453: }
1.795 www 6454:
1.507 raeburn 6455: table.LC_nested_outer {
6456: border: 1px solid #000000;
1.589 raeburn 6457: border-collapse: collapse;
1.803 bisitz 6458: border-spacing: 0;
1.507 raeburn 6459: width: 100%;
6460: }
1.795 www 6461:
1.879 raeburn 6462: table.LC_innerpickbox,
1.507 raeburn 6463: table.LC_nested {
1.803 bisitz 6464: border: none;
1.589 raeburn 6465: border-collapse: collapse;
1.803 bisitz 6466: border-spacing: 0;
1.507 raeburn 6467: width: 100%;
6468: }
1.795 www 6469:
1.911 bisitz 6470: table.LC_data_table tr th,
6471: table.LC_calendar tr th,
1.879 raeburn 6472: table.LC_prior_tries tr th,
6473: table.LC_innerpickbox tr th {
1.349 albertel 6474: font-weight: bold;
6475: background-color: $data_table_head;
1.801 tempelho 6476: color:$fontmenu;
1.701 harmsja 6477: font-size:90%;
1.347 albertel 6478: }
1.795 www 6479:
1.879 raeburn 6480: table.LC_innerpickbox tr th,
6481: table.LC_innerpickbox tr td {
6482: vertical-align: top;
6483: }
6484:
1.711 raeburn 6485: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6486: background-color: #CCCCCC;
1.711 raeburn 6487: font-weight: bold;
6488: text-align: left;
6489: }
1.795 www 6490:
1.912 bisitz 6491: table.LC_data_table tr.LC_odd_row > td {
6492: background-color: $data_table_light;
6493: padding: 2px;
6494: vertical-align: top;
6495: }
6496:
1.809 bisitz 6497: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6498: background-color: $data_table_light;
1.912 bisitz 6499: vertical-align: top;
6500: }
6501:
6502: table.LC_data_table tr.LC_even_row > td {
6503: background-color: $data_table_dark;
1.425 albertel 6504: padding: 2px;
1.900 bisitz 6505: vertical-align: top;
1.347 albertel 6506: }
1.795 www 6507:
1.809 bisitz 6508: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6509: background-color: $data_table_dark;
1.900 bisitz 6510: vertical-align: top;
1.347 albertel 6511: }
1.795 www 6512:
1.425 albertel 6513: table.LC_data_table tr.LC_data_table_highlight td {
6514: background-color: $data_table_darker;
6515: }
1.795 www 6516:
1.639 raeburn 6517: table.LC_data_table tr td.LC_leftcol_header {
6518: background-color: $data_table_head;
6519: font-weight: bold;
6520: }
1.795 www 6521:
1.451 albertel 6522: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6523: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6524: font-weight: bold;
6525: font-style: italic;
6526: text-align: center;
6527: padding: 8px;
1.347 albertel 6528: }
1.795 www 6529:
1.1114 raeburn 6530: table.LC_data_table tr.LC_empty_row td,
6531: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6532: background-color: $sidebg;
6533: }
6534:
6535: table.LC_nested tr.LC_empty_row td {
6536: background-color: #FFFFFF;
6537: }
6538:
1.890 droeschl 6539: table.LC_caption {
6540: }
6541:
1.507 raeburn 6542: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6543: padding: 4ex
6544: }
1.795 www 6545:
1.507 raeburn 6546: table.LC_nested_outer tr th {
6547: font-weight: bold;
1.801 tempelho 6548: color:$fontmenu;
1.507 raeburn 6549: background-color: $data_table_head;
1.701 harmsja 6550: font-size: small;
1.507 raeburn 6551: border-bottom: 1px solid #000000;
6552: }
1.795 www 6553:
1.507 raeburn 6554: table.LC_nested_outer tr td.LC_subheader {
6555: background-color: $data_table_head;
6556: font-weight: bold;
6557: font-size: small;
6558: border-bottom: 1px solid #000000;
6559: text-align: right;
1.451 albertel 6560: }
1.795 www 6561:
1.507 raeburn 6562: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6563: background-color: #CCCCCC;
1.451 albertel 6564: font-weight: bold;
6565: font-size: small;
1.507 raeburn 6566: text-align: center;
6567: }
1.795 www 6568:
1.589 raeburn 6569: table.LC_nested tr.LC_info_row td.LC_left_item,
6570: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6571: text-align: left;
1.451 albertel 6572: }
1.795 www 6573:
1.507 raeburn 6574: table.LC_nested td {
1.735 bisitz 6575: background-color: #FFFFFF;
1.451 albertel 6576: font-size: small;
1.507 raeburn 6577: }
1.795 www 6578:
1.507 raeburn 6579: table.LC_nested_outer tr th.LC_right_item,
6580: table.LC_nested tr.LC_info_row td.LC_right_item,
6581: table.LC_nested tr.LC_odd_row td.LC_right_item,
6582: table.LC_nested tr td.LC_right_item {
1.451 albertel 6583: text-align: right;
6584: }
6585:
1.507 raeburn 6586: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6587: background-color: #EEEEEE;
1.451 albertel 6588: }
6589:
1.473 raeburn 6590: table.LC_createuser {
6591: }
6592:
6593: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6594: font-size: small;
1.473 raeburn 6595: }
6596:
6597: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6598: background-color: #CCCCCC;
1.473 raeburn 6599: font-weight: bold;
6600: text-align: center;
6601: }
6602:
1.349 albertel 6603: table.LC_calendar {
6604: border: 1px solid #000000;
6605: border-collapse: collapse;
1.917 raeburn 6606: width: 98%;
1.349 albertel 6607: }
1.795 www 6608:
1.349 albertel 6609: table.LC_calendar_pickdate {
6610: font-size: xx-small;
6611: }
1.795 www 6612:
1.349 albertel 6613: table.LC_calendar tr td {
6614: border: 1px solid #000000;
6615: vertical-align: top;
1.917 raeburn 6616: width: 14%;
1.349 albertel 6617: }
1.795 www 6618:
1.349 albertel 6619: table.LC_calendar tr td.LC_calendar_day_empty {
6620: background-color: $data_table_dark;
6621: }
1.795 www 6622:
1.779 bisitz 6623: table.LC_calendar tr td.LC_calendar_day_current {
6624: background-color: $data_table_highlight;
1.777 tempelho 6625: }
1.795 www 6626:
1.938 bisitz 6627: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6628: background-color: $mail_new;
6629: }
1.795 www 6630:
1.938 bisitz 6631: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6632: background-color: $mail_new_hover;
6633: }
1.795 www 6634:
1.938 bisitz 6635: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6636: background-color: $mail_read;
6637: }
1.795 www 6638:
1.938 bisitz 6639: /*
6640: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6641: background-color: $mail_read_hover;
6642: }
1.938 bisitz 6643: */
1.795 www 6644:
1.938 bisitz 6645: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6646: background-color: $mail_replied;
6647: }
1.795 www 6648:
1.938 bisitz 6649: /*
6650: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6651: background-color: $mail_replied_hover;
6652: }
1.938 bisitz 6653: */
1.795 www 6654:
1.938 bisitz 6655: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6656: background-color: $mail_other;
6657: }
1.795 www 6658:
1.938 bisitz 6659: /*
6660: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6661: background-color: $mail_other_hover;
6662: }
1.938 bisitz 6663: */
1.494 raeburn 6664:
1.777 tempelho 6665: table.LC_data_table tr > td.LC_browser_file,
6666: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6667: background: #AAEE77;
1.389 albertel 6668: }
1.795 www 6669:
1.777 tempelho 6670: table.LC_data_table tr > td.LC_browser_file_locked,
6671: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6672: background: #FFAA99;
1.387 albertel 6673: }
1.795 www 6674:
1.777 tempelho 6675: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6676: background: #888888;
1.779 bisitz 6677: }
1.795 www 6678:
1.777 tempelho 6679: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6680: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6681: background: #F8F866;
1.777 tempelho 6682: }
1.795 www 6683:
1.696 bisitz 6684: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6685: background: #E0E8FF;
1.387 albertel 6686: }
1.696 bisitz 6687:
1.707 bisitz 6688: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6689: /* background: #77FF77; */
1.707 bisitz 6690: }
1.795 www 6691:
1.707 bisitz 6692: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6693: border-right: 8px solid #FFFF77;
1.707 bisitz 6694: }
1.795 www 6695:
1.707 bisitz 6696: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6697: border-right: 8px solid #FFAA77;
1.707 bisitz 6698: }
1.795 www 6699:
1.707 bisitz 6700: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6701: border-right: 8px solid #FF7777;
1.707 bisitz 6702: }
1.795 www 6703:
1.707 bisitz 6704: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6705: border-right: 8px solid #AAFF77;
1.707 bisitz 6706: }
1.795 www 6707:
1.707 bisitz 6708: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6709: border-right: 8px solid #11CC55;
1.707 bisitz 6710: }
6711:
1.388 albertel 6712: span.LC_current_location {
1.701 harmsja 6713: font-size:larger;
1.388 albertel 6714: background: $pgbg;
6715: }
1.387 albertel 6716:
1.1029 www 6717: span.LC_current_nav_location {
6718: font-weight:bold;
6719: background: $sidebg;
6720: }
6721:
1.395 albertel 6722: span.LC_parm_menu_item {
6723: font-size: larger;
6724: }
1.795 www 6725:
1.395 albertel 6726: span.LC_parm_scope_all {
6727: color: red;
6728: }
1.795 www 6729:
1.395 albertel 6730: span.LC_parm_scope_folder {
6731: color: green;
6732: }
1.795 www 6733:
1.395 albertel 6734: span.LC_parm_scope_resource {
6735: color: orange;
6736: }
1.795 www 6737:
1.395 albertel 6738: span.LC_parm_part {
6739: color: blue;
6740: }
1.795 www 6741:
1.911 bisitz 6742: span.LC_parm_folder,
6743: span.LC_parm_symb {
1.395 albertel 6744: font-size: x-small;
6745: font-family: $mono;
6746: color: #AAAAAA;
6747: }
6748:
1.977 bisitz 6749: ul.LC_parm_parmlist li {
6750: display: inline-block;
6751: padding: 0.3em 0.8em;
6752: vertical-align: top;
6753: width: 150px;
6754: border-top:1px solid $lg_border_color;
6755: }
6756:
1.795 www 6757: td.LC_parm_overview_level_menu,
6758: td.LC_parm_overview_map_menu,
6759: td.LC_parm_overview_parm_selectors,
6760: td.LC_parm_overview_restrictions {
1.396 albertel 6761: border: 1px solid black;
6762: border-collapse: collapse;
6763: }
1.795 www 6764:
1.396 albertel 6765: table.LC_parm_overview_restrictions td {
6766: border-width: 1px 4px 1px 4px;
6767: border-style: solid;
6768: border-color: $pgbg;
6769: text-align: center;
6770: }
1.795 www 6771:
1.396 albertel 6772: table.LC_parm_overview_restrictions th {
6773: background: $tabbg;
6774: border-width: 1px 4px 1px 4px;
6775: border-style: solid;
6776: border-color: $pgbg;
6777: }
1.795 www 6778:
1.398 albertel 6779: table#LC_helpmenu {
1.803 bisitz 6780: border: none;
1.398 albertel 6781: height: 55px;
1.803 bisitz 6782: border-spacing: 0;
1.398 albertel 6783: }
6784:
6785: table#LC_helpmenu fieldset legend {
6786: font-size: larger;
6787: }
1.795 www 6788:
1.397 albertel 6789: table#LC_helpmenu_links {
6790: width: 100%;
6791: border: 1px solid black;
6792: background: $pgbg;
1.803 bisitz 6793: padding: 0;
1.397 albertel 6794: border-spacing: 1px;
6795: }
1.795 www 6796:
1.397 albertel 6797: table#LC_helpmenu_links tr td {
6798: padding: 1px;
6799: background: $tabbg;
1.399 albertel 6800: text-align: center;
6801: font-weight: bold;
1.397 albertel 6802: }
1.396 albertel 6803:
1.795 www 6804: table#LC_helpmenu_links a:link,
6805: table#LC_helpmenu_links a:visited,
1.397 albertel 6806: table#LC_helpmenu_links a:active {
6807: text-decoration: none;
6808: color: $font;
6809: }
1.795 www 6810:
1.397 albertel 6811: table#LC_helpmenu_links a:hover {
6812: text-decoration: underline;
6813: color: $vlink;
6814: }
1.396 albertel 6815:
1.417 albertel 6816: .LC_chrt_popup_exists {
6817: border: 1px solid #339933;
6818: margin: -1px;
6819: }
1.795 www 6820:
1.417 albertel 6821: .LC_chrt_popup_up {
6822: border: 1px solid yellow;
6823: margin: -1px;
6824: }
1.795 www 6825:
1.417 albertel 6826: .LC_chrt_popup {
6827: border: 1px solid #8888FF;
6828: background: #CCCCFF;
6829: }
1.795 www 6830:
1.421 albertel 6831: table.LC_pick_box {
6832: border-collapse: separate;
6833: background: white;
6834: border: 1px solid black;
6835: border-spacing: 1px;
6836: }
1.795 www 6837:
1.421 albertel 6838: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6839: background: $sidebg;
1.421 albertel 6840: font-weight: bold;
1.900 bisitz 6841: text-align: left;
1.740 bisitz 6842: vertical-align: top;
1.421 albertel 6843: width: 184px;
6844: padding: 8px;
6845: }
1.795 www 6846:
1.579 raeburn 6847: table.LC_pick_box td.LC_pick_box_value {
6848: text-align: left;
6849: padding: 8px;
6850: }
1.795 www 6851:
1.579 raeburn 6852: table.LC_pick_box td.LC_pick_box_select {
6853: text-align: left;
6854: padding: 8px;
6855: }
1.795 www 6856:
1.424 albertel 6857: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6858: padding: 0;
1.421 albertel 6859: height: 1px;
6860: background: black;
6861: }
1.795 www 6862:
1.421 albertel 6863: table.LC_pick_box td.LC_pick_box_submit {
6864: text-align: right;
6865: }
1.795 www 6866:
1.579 raeburn 6867: table.LC_pick_box td.LC_evenrow_value {
6868: text-align: left;
6869: padding: 8px;
6870: background-color: $data_table_light;
6871: }
1.795 www 6872:
1.579 raeburn 6873: table.LC_pick_box td.LC_oddrow_value {
6874: text-align: left;
6875: padding: 8px;
6876: background-color: $data_table_light;
6877: }
1.795 www 6878:
1.579 raeburn 6879: span.LC_helpform_receipt_cat {
6880: font-weight: bold;
6881: }
1.795 www 6882:
1.424 albertel 6883: table.LC_group_priv_box {
6884: background: white;
6885: border: 1px solid black;
6886: border-spacing: 1px;
6887: }
1.795 www 6888:
1.424 albertel 6889: table.LC_group_priv_box td.LC_pick_box_title {
6890: background: $tabbg;
6891: font-weight: bold;
6892: text-align: right;
6893: width: 184px;
6894: }
1.795 www 6895:
1.424 albertel 6896: table.LC_group_priv_box td.LC_groups_fixed {
6897: background: $data_table_light;
6898: text-align: center;
6899: }
1.795 www 6900:
1.424 albertel 6901: table.LC_group_priv_box td.LC_groups_optional {
6902: background: $data_table_dark;
6903: text-align: center;
6904: }
1.795 www 6905:
1.424 albertel 6906: table.LC_group_priv_box td.LC_groups_functionality {
6907: background: $data_table_darker;
6908: text-align: center;
6909: font-weight: bold;
6910: }
1.795 www 6911:
1.424 albertel 6912: table.LC_group_priv td {
6913: text-align: left;
1.803 bisitz 6914: padding: 0;
1.424 albertel 6915: }
6916:
6917: .LC_navbuttons {
6918: margin: 2ex 0ex 2ex 0ex;
6919: }
1.795 www 6920:
1.423 albertel 6921: .LC_topic_bar {
6922: font-weight: bold;
6923: background: $tabbg;
1.918 wenzelju 6924: margin: 1em 0em 1em 2em;
1.805 bisitz 6925: padding: 3px;
1.918 wenzelju 6926: font-size: 1.2em;
1.423 albertel 6927: }
1.795 www 6928:
1.423 albertel 6929: .LC_topic_bar span {
1.918 wenzelju 6930: left: 0.5em;
6931: position: absolute;
1.423 albertel 6932: vertical-align: middle;
1.918 wenzelju 6933: font-size: 1.2em;
1.423 albertel 6934: }
1.795 www 6935:
1.423 albertel 6936: table.LC_course_group_status {
6937: margin: 20px;
6938: }
1.795 www 6939:
1.423 albertel 6940: table.LC_status_selector td {
6941: vertical-align: top;
6942: text-align: center;
1.424 albertel 6943: padding: 4px;
6944: }
1.795 www 6945:
1.599 albertel 6946: div.LC_feedback_link {
1.616 albertel 6947: clear: both;
1.829 kalberla 6948: background: $sidebg;
1.779 bisitz 6949: width: 100%;
1.829 kalberla 6950: padding-bottom: 10px;
6951: border: 1px $tabbg solid;
1.833 kalberla 6952: height: 22px;
6953: line-height: 22px;
6954: padding-top: 5px;
6955: }
6956:
6957: div.LC_feedback_link img {
6958: height: 22px;
1.867 kalberla 6959: vertical-align:middle;
1.829 kalberla 6960: }
6961:
1.911 bisitz 6962: div.LC_feedback_link a {
1.829 kalberla 6963: text-decoration: none;
1.489 raeburn 6964: }
1.795 www 6965:
1.867 kalberla 6966: div.LC_comblock {
1.911 bisitz 6967: display:inline;
1.867 kalberla 6968: color:$font;
6969: font-size:90%;
6970: }
6971:
6972: div.LC_feedback_link div.LC_comblock {
6973: padding-left:5px;
6974: }
6975:
6976: div.LC_feedback_link div.LC_comblock a {
6977: color:$font;
6978: }
6979:
1.489 raeburn 6980: span.LC_feedback_link {
1.858 bisitz 6981: /* background: $feedback_link_bg; */
1.599 albertel 6982: font-size: larger;
6983: }
1.795 www 6984:
1.599 albertel 6985: span.LC_message_link {
1.858 bisitz 6986: /* background: $feedback_link_bg; */
1.599 albertel 6987: font-size: larger;
6988: position: absolute;
6989: right: 1em;
1.489 raeburn 6990: }
1.421 albertel 6991:
1.515 albertel 6992: table.LC_prior_tries {
1.524 albertel 6993: border: 1px solid #000000;
6994: border-collapse: separate;
6995: border-spacing: 1px;
1.515 albertel 6996: }
1.523 albertel 6997:
1.515 albertel 6998: table.LC_prior_tries td {
1.524 albertel 6999: padding: 2px;
1.515 albertel 7000: }
1.523 albertel 7001:
7002: .LC_answer_correct {
1.795 www 7003: background: lightgreen;
7004: color: darkgreen;
7005: padding: 6px;
1.523 albertel 7006: }
1.795 www 7007:
1.523 albertel 7008: .LC_answer_charged_try {
1.797 www 7009: background: #FFAAAA;
1.795 www 7010: color: darkred;
7011: padding: 6px;
1.523 albertel 7012: }
1.795 www 7013:
1.779 bisitz 7014: .LC_answer_not_charged_try,
1.523 albertel 7015: .LC_answer_no_grade,
7016: .LC_answer_late {
1.795 www 7017: background: lightyellow;
1.523 albertel 7018: color: black;
1.795 www 7019: padding: 6px;
1.523 albertel 7020: }
1.795 www 7021:
1.523 albertel 7022: .LC_answer_previous {
1.795 www 7023: background: lightblue;
7024: color: darkblue;
7025: padding: 6px;
1.523 albertel 7026: }
1.795 www 7027:
1.779 bisitz 7028: .LC_answer_no_message {
1.777 tempelho 7029: background: #FFFFFF;
7030: color: black;
1.795 www 7031: padding: 6px;
1.779 bisitz 7032: }
1.795 www 7033:
1.779 bisitz 7034: .LC_answer_unknown {
7035: background: orange;
7036: color: black;
1.795 www 7037: padding: 6px;
1.777 tempelho 7038: }
1.795 www 7039:
1.529 albertel 7040: span.LC_prior_numerical,
7041: span.LC_prior_string,
7042: span.LC_prior_custom,
7043: span.LC_prior_reaction,
7044: span.LC_prior_math {
1.925 bisitz 7045: font-family: $mono;
1.523 albertel 7046: white-space: pre;
7047: }
7048:
1.525 albertel 7049: span.LC_prior_string {
1.925 bisitz 7050: font-family: $mono;
1.525 albertel 7051: white-space: pre;
7052: }
7053:
1.523 albertel 7054: table.LC_prior_option {
7055: width: 100%;
7056: border-collapse: collapse;
7057: }
1.795 www 7058:
1.911 bisitz 7059: table.LC_prior_rank,
1.795 www 7060: table.LC_prior_match {
1.528 albertel 7061: border-collapse: collapse;
7062: }
1.795 www 7063:
1.528 albertel 7064: table.LC_prior_option tr td,
7065: table.LC_prior_rank tr td,
7066: table.LC_prior_match tr td {
1.524 albertel 7067: border: 1px solid #000000;
1.515 albertel 7068: }
7069:
1.855 bisitz 7070: .LC_nobreak {
1.544 albertel 7071: white-space: nowrap;
1.519 raeburn 7072: }
7073:
1.576 raeburn 7074: span.LC_cusr_emph {
7075: font-style: italic;
7076: }
7077:
1.633 raeburn 7078: span.LC_cusr_subheading {
7079: font-weight: normal;
7080: font-size: 85%;
7081: }
7082:
1.861 bisitz 7083: div.LC_docs_entry_move {
1.859 bisitz 7084: border: 1px solid #BBBBBB;
1.545 albertel 7085: background: #DDDDDD;
1.861 bisitz 7086: width: 22px;
1.859 bisitz 7087: padding: 1px;
7088: margin: 0;
1.545 albertel 7089: }
7090:
1.861 bisitz 7091: table.LC_data_table tr > td.LC_docs_entry_commands,
7092: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7093: font-size: x-small;
7094: }
1.795 www 7095:
1.861 bisitz 7096: .LC_docs_entry_parameter {
7097: white-space: nowrap;
7098: }
7099:
1.544 albertel 7100: .LC_docs_copy {
1.545 albertel 7101: color: #000099;
1.544 albertel 7102: }
1.795 www 7103:
1.544 albertel 7104: .LC_docs_cut {
1.545 albertel 7105: color: #550044;
1.544 albertel 7106: }
1.795 www 7107:
1.544 albertel 7108: .LC_docs_rename {
1.545 albertel 7109: color: #009900;
1.544 albertel 7110: }
1.795 www 7111:
1.544 albertel 7112: .LC_docs_remove {
1.545 albertel 7113: color: #990000;
7114: }
7115:
1.547 albertel 7116: .LC_docs_reinit_warn,
7117: .LC_docs_ext_edit {
7118: font-size: x-small;
7119: }
7120:
1.545 albertel 7121: table.LC_docs_adddocs td,
7122: table.LC_docs_adddocs th {
7123: border: 1px solid #BBBBBB;
7124: padding: 4px;
7125: background: #DDDDDD;
1.543 albertel 7126: }
7127:
1.584 albertel 7128: table.LC_sty_begin {
7129: background: #BBFFBB;
7130: }
1.795 www 7131:
1.584 albertel 7132: table.LC_sty_end {
7133: background: #FFBBBB;
7134: }
7135:
1.589 raeburn 7136: table.LC_double_column {
1.803 bisitz 7137: border-width: 0;
1.589 raeburn 7138: border-collapse: collapse;
7139: width: 100%;
7140: padding: 2px;
7141: }
7142:
7143: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7144: top: 2px;
1.589 raeburn 7145: left: 2px;
7146: width: 47%;
7147: vertical-align: top;
7148: }
7149:
7150: table.LC_double_column tr td.LC_right_col {
7151: top: 2px;
1.779 bisitz 7152: right: 2px;
1.589 raeburn 7153: width: 47%;
7154: vertical-align: top;
7155: }
7156:
1.591 raeburn 7157: div.LC_left_float {
7158: float: left;
7159: padding-right: 5%;
1.597 albertel 7160: padding-bottom: 4px;
1.591 raeburn 7161: }
7162:
7163: div.LC_clear_float_header {
1.597 albertel 7164: padding-bottom: 2px;
1.591 raeburn 7165: }
7166:
7167: div.LC_clear_float_footer {
1.597 albertel 7168: padding-top: 10px;
1.591 raeburn 7169: clear: both;
7170: }
7171:
1.597 albertel 7172: div.LC_grade_show_user {
1.941 bisitz 7173: /* border-left: 5px solid $sidebg; */
7174: border-top: 5px solid #000000;
7175: margin: 50px 0 0 0;
1.936 bisitz 7176: padding: 15px 0 5px 10px;
1.597 albertel 7177: }
1.795 www 7178:
1.936 bisitz 7179: div.LC_grade_show_user_odd_row {
1.941 bisitz 7180: /* border-left: 5px solid #000000; */
7181: }
7182:
7183: div.LC_grade_show_user div.LC_Box {
7184: margin-right: 50px;
1.597 albertel 7185: }
7186:
7187: div.LC_grade_submissions,
7188: div.LC_grade_message_center,
1.936 bisitz 7189: div.LC_grade_info_links {
1.597 albertel 7190: margin: 5px;
7191: width: 99%;
7192: background: #FFFFFF;
7193: }
1.795 www 7194:
1.597 albertel 7195: div.LC_grade_submissions_header,
1.936 bisitz 7196: div.LC_grade_message_center_header {
1.705 tempelho 7197: font-weight: bold;
7198: font-size: large;
1.597 albertel 7199: }
1.795 www 7200:
1.597 albertel 7201: div.LC_grade_submissions_body,
1.936 bisitz 7202: div.LC_grade_message_center_body {
1.597 albertel 7203: border: 1px solid black;
7204: width: 99%;
7205: background: #FFFFFF;
7206: }
1.795 www 7207:
1.613 albertel 7208: table.LC_scantron_action {
7209: width: 100%;
7210: }
1.795 www 7211:
1.613 albertel 7212: table.LC_scantron_action tr th {
1.698 harmsja 7213: font-weight:bold;
7214: font-style:normal;
1.613 albertel 7215: }
1.795 www 7216:
1.779 bisitz 7217: .LC_edit_problem_header,
1.614 albertel 7218: div.LC_edit_problem_footer {
1.705 tempelho 7219: font-weight: normal;
7220: font-size: medium;
1.602 albertel 7221: margin: 2px;
1.1060 bisitz 7222: background-color: $sidebg;
1.600 albertel 7223: }
1.795 www 7224:
1.600 albertel 7225: div.LC_edit_problem_header,
1.602 albertel 7226: div.LC_edit_problem_header div,
1.614 albertel 7227: div.LC_edit_problem_footer,
7228: div.LC_edit_problem_footer div,
1.602 albertel 7229: div.LC_edit_problem_editxml_header,
7230: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7231: z-index: 100;
1.600 albertel 7232: }
1.795 www 7233:
1.600 albertel 7234: div.LC_edit_problem_header_title {
1.705 tempelho 7235: font-weight: bold;
7236: font-size: larger;
1.602 albertel 7237: background: $tabbg;
7238: padding: 3px;
1.1060 bisitz 7239: margin: 0 0 5px 0;
1.602 albertel 7240: }
1.795 www 7241:
1.602 albertel 7242: table.LC_edit_problem_header_title {
7243: width: 100%;
1.600 albertel 7244: background: $tabbg;
1.602 albertel 7245: }
7246:
1.1205 golterma 7247: div.LC_edit_actionbar {
7248: background-color: $sidebg;
1.1218 droeschl 7249: margin: 0;
7250: padding: 0;
7251: line-height: 200%;
1.602 albertel 7252: }
1.795 www 7253:
1.1218 droeschl 7254: div.LC_edit_actionbar div{
7255: padding: 0;
7256: margin: 0;
7257: display: inline-block;
1.600 albertel 7258: }
1.795 www 7259:
1.1124 bisitz 7260: .LC_edit_opt {
7261: padding-left: 1em;
7262: white-space: nowrap;
7263: }
7264:
1.1152 golterma 7265: .LC_edit_problem_latexhelper{
7266: text-align: right;
7267: }
7268:
7269: #LC_edit_problem_colorful div{
7270: margin-left: 40px;
7271: }
7272:
1.1205 golterma 7273: #LC_edit_problem_codemirror div{
7274: margin-left: 0px;
7275: }
7276:
1.911 bisitz 7277: img.stift {
1.803 bisitz 7278: border-width: 0;
7279: vertical-align: middle;
1.677 riegler 7280: }
1.680 riegler 7281:
1.923 bisitz 7282: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7283: vertical-align: top;
1.777 tempelho 7284: }
1.795 www 7285:
1.716 raeburn 7286: div.LC_createcourse {
1.911 bisitz 7287: margin: 10px 10px 10px 10px;
1.716 raeburn 7288: }
7289:
1.917 raeburn 7290: .LC_dccid {
1.1130 raeburn 7291: float: right;
1.917 raeburn 7292: margin: 0.2em 0 0 0;
7293: padding: 0;
7294: font-size: 90%;
7295: display:none;
7296: }
7297:
1.897 wenzelju 7298: ol.LC_primary_menu a:hover,
1.721 harmsja 7299: ol#LC_MenuBreadcrumbs a:hover,
7300: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7301: ul#LC_secondary_menu a:hover,
1.721 harmsja 7302: .LC_FormSectionClearButton input:hover
1.795 www 7303: ul.LC_TabContent li:hover a {
1.952 onken 7304: color:$button_hover;
1.911 bisitz 7305: text-decoration:none;
1.693 droeschl 7306: }
7307:
1.779 bisitz 7308: h1 {
1.911 bisitz 7309: padding: 0;
7310: line-height:130%;
1.693 droeschl 7311: }
1.698 harmsja 7312:
1.911 bisitz 7313: h2,
7314: h3,
7315: h4,
7316: h5,
7317: h6 {
7318: margin: 5px 0 5px 0;
7319: padding: 0;
7320: line-height:130%;
1.693 droeschl 7321: }
1.795 www 7322:
7323: .LC_hcell {
1.911 bisitz 7324: padding:3px 15px 3px 15px;
7325: margin: 0;
7326: background-color:$tabbg;
7327: color:$fontmenu;
7328: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7329: }
1.795 www 7330:
1.840 bisitz 7331: .LC_Box > .LC_hcell {
1.911 bisitz 7332: margin: 0 -10px 10px -10px;
1.835 bisitz 7333: }
7334:
1.721 harmsja 7335: .LC_noBorder {
1.911 bisitz 7336: border: 0;
1.698 harmsja 7337: }
1.693 droeschl 7338:
1.721 harmsja 7339: .LC_FormSectionClearButton input {
1.911 bisitz 7340: background-color:transparent;
7341: border: none;
7342: cursor:pointer;
7343: text-decoration:underline;
1.693 droeschl 7344: }
1.763 bisitz 7345:
7346: .LC_help_open_topic {
1.911 bisitz 7347: color: #FFFFFF;
7348: background-color: #EEEEFF;
7349: margin: 1px;
7350: padding: 4px;
7351: border: 1px solid #000033;
7352: white-space: nowrap;
7353: /* vertical-align: middle; */
1.759 neumanie 7354: }
1.693 droeschl 7355:
1.911 bisitz 7356: dl,
7357: ul,
7358: div,
7359: fieldset {
7360: margin: 10px 10px 10px 0;
7361: /* overflow: hidden; */
1.693 droeschl 7362: }
1.795 www 7363:
1.1211 raeburn 7364: article.geogebraweb div {
7365: margin: 0;
7366: }
7367:
1.838 bisitz 7368: fieldset > legend {
1.911 bisitz 7369: font-weight: bold;
7370: padding: 0 5px 0 5px;
1.838 bisitz 7371: }
7372:
1.813 bisitz 7373: #LC_nav_bar {
1.911 bisitz 7374: float: left;
1.995 raeburn 7375: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7376: margin: 0 0 2px 0;
1.807 droeschl 7377: }
7378:
1.916 droeschl 7379: #LC_realm {
7380: margin: 0.2em 0 0 0;
7381: padding: 0;
7382: font-weight: bold;
7383: text-align: center;
1.995 raeburn 7384: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7385: }
7386:
1.911 bisitz 7387: #LC_nav_bar em {
7388: font-weight: bold;
7389: font-style: normal;
1.807 droeschl 7390: }
7391:
1.897 wenzelju 7392: ol.LC_primary_menu {
1.934 droeschl 7393: margin: 0;
1.1076 raeburn 7394: padding: 0;
1.807 droeschl 7395: }
7396:
1.852 droeschl 7397: ol#LC_PathBreadcrumbs {
1.911 bisitz 7398: margin: 0;
1.693 droeschl 7399: }
7400:
1.897 wenzelju 7401: ol.LC_primary_menu li {
1.1076 raeburn 7402: color: RGB(80, 80, 80);
7403: vertical-align: middle;
7404: text-align: left;
7405: list-style: none;
1.1205 golterma 7406: position: relative;
1.1076 raeburn 7407: float: left;
1.1205 golterma 7408: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7409: line-height: 1.5em;
1.1076 raeburn 7410: }
7411:
1.1205 golterma 7412: ol.LC_primary_menu li a,
7413: ol.LC_primary_menu li p {
1.1076 raeburn 7414: display: block;
7415: margin: 0;
7416: padding: 0 5px 0 10px;
7417: text-decoration: none;
7418: }
7419:
1.1205 golterma 7420: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7421: display: inline-block;
7422: width: 95%;
7423: text-align: left;
7424: }
7425:
7426: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7427: display: inline-block;
7428: width: 5%;
7429: float: right;
7430: text-align: right;
7431: font-size: 70%;
7432: }
7433:
7434: ol.LC_primary_menu ul {
1.1076 raeburn 7435: display: none;
1.1205 golterma 7436: width: 15em;
1.1076 raeburn 7437: background-color: $data_table_light;
1.1205 golterma 7438: position: absolute;
7439: top: 100%;
1.1076 raeburn 7440: }
7441:
1.1205 golterma 7442: ol.LC_primary_menu ul ul {
7443: left: 100%;
7444: top: 0;
7445: }
7446:
7447: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7448: display: block;
7449: position: absolute;
7450: margin: 0;
7451: padding: 0;
1.1078 raeburn 7452: z-index: 2;
1.1076 raeburn 7453: }
7454:
7455: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7456: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7457: font-size: 90%;
1.911 bisitz 7458: vertical-align: top;
1.1076 raeburn 7459: float: none;
1.1079 raeburn 7460: border-left: 1px solid black;
7461: border-right: 1px solid black;
1.1205 golterma 7462: /* A dark bottom border to visualize different menu options;
7463: overwritten in the create_submenu routine for the last border-bottom of the menu */
7464: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7465: }
7466:
1.1205 golterma 7467: ol.LC_primary_menu li li p:hover {
7468: color:$button_hover;
7469: text-decoration:none;
7470: background-color:$data_table_dark;
1.1076 raeburn 7471: }
7472:
7473: ol.LC_primary_menu li li a:hover {
7474: color:$button_hover;
7475: background-color:$data_table_dark;
1.693 droeschl 7476: }
7477:
1.1205 golterma 7478: /* Font-size equal to the size of the predecessors*/
7479: ol.LC_primary_menu li:hover li li {
7480: font-size: 100%;
7481: }
7482:
1.897 wenzelju 7483: ol.LC_primary_menu li img {
1.911 bisitz 7484: vertical-align: bottom;
1.934 droeschl 7485: height: 1.1em;
1.1077 raeburn 7486: margin: 0.2em 0 0 0;
1.693 droeschl 7487: }
7488:
1.897 wenzelju 7489: ol.LC_primary_menu a {
1.911 bisitz 7490: color: RGB(80, 80, 80);
7491: text-decoration: none;
1.693 droeschl 7492: }
1.795 www 7493:
1.949 droeschl 7494: ol.LC_primary_menu a.LC_new_message {
7495: font-weight:bold;
7496: color: darkred;
7497: }
7498:
1.975 raeburn 7499: ol.LC_docs_parameters {
7500: margin-left: 0;
7501: padding: 0;
7502: list-style: none;
7503: }
7504:
7505: ol.LC_docs_parameters li {
7506: margin: 0;
7507: padding-right: 20px;
7508: display: inline;
7509: }
7510:
1.976 raeburn 7511: ol.LC_docs_parameters li:before {
7512: content: "\\002022 \\0020";
7513: }
7514:
7515: li.LC_docs_parameters_title {
7516: font-weight: bold;
7517: }
7518:
7519: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7520: content: "";
7521: }
7522:
1.897 wenzelju 7523: ul#LC_secondary_menu {
1.1107 raeburn 7524: clear: right;
1.911 bisitz 7525: color: $fontmenu;
7526: background: $tabbg;
7527: list-style: none;
7528: padding: 0;
7529: margin: 0;
7530: width: 100%;
1.995 raeburn 7531: text-align: left;
1.1107 raeburn 7532: float: left;
1.808 droeschl 7533: }
7534:
1.897 wenzelju 7535: ul#LC_secondary_menu li {
1.911 bisitz 7536: font-weight: bold;
7537: line-height: 1.8em;
1.1107 raeburn 7538: border-right: 1px solid black;
7539: float: left;
7540: }
7541:
7542: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7543: background-color: $data_table_light;
7544: }
7545:
7546: ul#LC_secondary_menu li a {
1.911 bisitz 7547: padding: 0 0.8em;
1.1107 raeburn 7548: }
7549:
7550: ul#LC_secondary_menu li ul {
7551: display: none;
7552: }
7553:
7554: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7555: display: block;
7556: position: absolute;
7557: margin: 0;
7558: padding: 0;
7559: list-style:none;
7560: float: none;
7561: background-color: $data_table_light;
7562: z-index: 2;
7563: margin-left: -1px;
7564: }
7565:
7566: ul#LC_secondary_menu li ul li {
7567: font-size: 90%;
7568: vertical-align: top;
7569: border-left: 1px solid black;
1.911 bisitz 7570: border-right: 1px solid black;
1.1119 raeburn 7571: background-color: $data_table_light;
1.1107 raeburn 7572: list-style:none;
7573: float: none;
7574: }
7575:
7576: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7577: background-color: $data_table_dark;
1.807 droeschl 7578: }
7579:
1.847 tempelho 7580: ul.LC_TabContent {
1.911 bisitz 7581: display:block;
7582: background: $sidebg;
7583: border-bottom: solid 1px $lg_border_color;
7584: list-style:none;
1.1020 raeburn 7585: margin: -1px -10px 0 -10px;
1.911 bisitz 7586: padding: 0;
1.693 droeschl 7587: }
7588:
1.795 www 7589: ul.LC_TabContent li,
7590: ul.LC_TabContentBigger li {
1.911 bisitz 7591: float:left;
1.741 harmsja 7592: }
1.795 www 7593:
1.897 wenzelju 7594: ul#LC_secondary_menu li a {
1.911 bisitz 7595: color: $fontmenu;
7596: text-decoration: none;
1.693 droeschl 7597: }
1.795 www 7598:
1.721 harmsja 7599: ul.LC_TabContent {
1.952 onken 7600: min-height:20px;
1.721 harmsja 7601: }
1.795 www 7602:
7603: ul.LC_TabContent li {
1.911 bisitz 7604: vertical-align:middle;
1.959 onken 7605: padding: 0 16px 0 10px;
1.911 bisitz 7606: background-color:$tabbg;
7607: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7608: border-left: solid 1px $font;
1.721 harmsja 7609: }
1.795 www 7610:
1.847 tempelho 7611: ul.LC_TabContent .right {
1.911 bisitz 7612: float:right;
1.847 tempelho 7613: }
7614:
1.911 bisitz 7615: ul.LC_TabContent li a,
7616: ul.LC_TabContent li {
7617: color:rgb(47,47,47);
7618: text-decoration:none;
7619: font-size:95%;
7620: font-weight:bold;
1.952 onken 7621: min-height:20px;
7622: }
7623:
1.959 onken 7624: ul.LC_TabContent li a:hover,
7625: ul.LC_TabContent li a:focus {
1.952 onken 7626: color: $button_hover;
1.959 onken 7627: background:none;
7628: outline:none;
1.952 onken 7629: }
7630:
7631: ul.LC_TabContent li:hover {
7632: color: $button_hover;
7633: cursor:pointer;
1.721 harmsja 7634: }
1.795 www 7635:
1.911 bisitz 7636: ul.LC_TabContent li.active {
1.952 onken 7637: color: $font;
1.911 bisitz 7638: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7639: border-bottom:solid 1px #FFFFFF;
7640: cursor: default;
1.744 ehlerst 7641: }
1.795 www 7642:
1.959 onken 7643: ul.LC_TabContent li.active a {
7644: color:$font;
7645: background:#FFFFFF;
7646: outline: none;
7647: }
1.1047 raeburn 7648:
7649: ul.LC_TabContent li.goback {
7650: float: left;
7651: border-left: none;
7652: }
7653:
1.870 tempelho 7654: #maincoursedoc {
1.911 bisitz 7655: clear:both;
1.870 tempelho 7656: }
7657:
7658: ul.LC_TabContentBigger {
1.911 bisitz 7659: display:block;
7660: list-style:none;
7661: padding: 0;
1.870 tempelho 7662: }
7663:
1.795 www 7664: ul.LC_TabContentBigger li {
1.911 bisitz 7665: vertical-align:bottom;
7666: height: 30px;
7667: font-size:110%;
7668: font-weight:bold;
7669: color: #737373;
1.841 tempelho 7670: }
7671:
1.957 onken 7672: ul.LC_TabContentBigger li.active {
7673: position: relative;
7674: top: 1px;
7675: }
7676:
1.870 tempelho 7677: ul.LC_TabContentBigger li a {
1.911 bisitz 7678: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7679: height: 30px;
7680: line-height: 30px;
7681: text-align: center;
7682: display: block;
7683: text-decoration: none;
1.958 onken 7684: outline: none;
1.741 harmsja 7685: }
1.795 www 7686:
1.870 tempelho 7687: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7688: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7689: color:$font;
1.744 ehlerst 7690: }
1.795 www 7691:
1.870 tempelho 7692: ul.LC_TabContentBigger li b {
1.911 bisitz 7693: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7694: display: block;
7695: float: left;
7696: padding: 0 30px;
1.957 onken 7697: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7698: }
7699:
1.956 onken 7700: ul.LC_TabContentBigger li:hover b {
7701: color:$button_hover;
7702: }
7703:
1.870 tempelho 7704: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7705: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7706: color:$font;
1.957 onken 7707: border: 0;
1.741 harmsja 7708: }
1.693 droeschl 7709:
1.870 tempelho 7710:
1.862 bisitz 7711: ul.LC_CourseBreadcrumbs {
7712: background: $sidebg;
1.1020 raeburn 7713: height: 2em;
1.862 bisitz 7714: padding-left: 10px;
1.1020 raeburn 7715: margin: 0;
1.862 bisitz 7716: list-style-position: inside;
7717: }
7718:
1.911 bisitz 7719: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7720: ol#LC_PathBreadcrumbs {
1.911 bisitz 7721: padding-left: 10px;
7722: margin: 0;
1.933 droeschl 7723: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7724: }
7725:
1.911 bisitz 7726: ol#LC_MenuBreadcrumbs li,
7727: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7728: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7729: display: inline;
1.933 droeschl 7730: white-space: normal;
1.693 droeschl 7731: }
7732:
1.823 bisitz 7733: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7734: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7735: text-decoration: none;
7736: font-size:90%;
1.693 droeschl 7737: }
1.795 www 7738:
1.969 droeschl 7739: ol#LC_MenuBreadcrumbs h1 {
7740: display: inline;
7741: font-size: 90%;
7742: line-height: 2.5em;
7743: margin: 0;
7744: padding: 0;
7745: }
7746:
1.795 www 7747: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7748: text-decoration:none;
7749: font-size:100%;
7750: font-weight:bold;
1.693 droeschl 7751: }
1.795 www 7752:
1.840 bisitz 7753: .LC_Box {
1.911 bisitz 7754: border: solid 1px $lg_border_color;
7755: padding: 0 10px 10px 10px;
1.746 neumanie 7756: }
1.795 www 7757:
1.1020 raeburn 7758: .LC_DocsBox {
7759: border: solid 1px $lg_border_color;
7760: padding: 0 0 10px 10px;
7761: }
7762:
1.795 www 7763: .LC_AboutMe_Image {
1.911 bisitz 7764: float:left;
7765: margin-right:10px;
1.747 neumanie 7766: }
1.795 www 7767:
7768: .LC_Clear_AboutMe_Image {
1.911 bisitz 7769: clear:left;
1.747 neumanie 7770: }
1.795 www 7771:
1.721 harmsja 7772: dl.LC_ListStyleClean dt {
1.911 bisitz 7773: padding-right: 5px;
7774: display: table-header-group;
1.693 droeschl 7775: }
7776:
1.721 harmsja 7777: dl.LC_ListStyleClean dd {
1.911 bisitz 7778: display: table-row;
1.693 droeschl 7779: }
7780:
1.721 harmsja 7781: .LC_ListStyleClean,
7782: .LC_ListStyleSimple,
7783: .LC_ListStyleNormal,
1.795 www 7784: .LC_ListStyleSpecial {
1.911 bisitz 7785: /* display:block; */
7786: list-style-position: inside;
7787: list-style-type: none;
7788: overflow: hidden;
7789: padding: 0;
1.693 droeschl 7790: }
7791:
1.721 harmsja 7792: .LC_ListStyleSimple li,
7793: .LC_ListStyleSimple dd,
7794: .LC_ListStyleNormal li,
7795: .LC_ListStyleNormal dd,
7796: .LC_ListStyleSpecial li,
1.795 www 7797: .LC_ListStyleSpecial dd {
1.911 bisitz 7798: margin: 0;
7799: padding: 5px 5px 5px 10px;
7800: clear: both;
1.693 droeschl 7801: }
7802:
1.721 harmsja 7803: .LC_ListStyleClean li,
7804: .LC_ListStyleClean dd {
1.911 bisitz 7805: padding-top: 0;
7806: padding-bottom: 0;
1.693 droeschl 7807: }
7808:
1.721 harmsja 7809: .LC_ListStyleSimple dd,
1.795 www 7810: .LC_ListStyleSimple li {
1.911 bisitz 7811: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7812: }
7813:
1.721 harmsja 7814: .LC_ListStyleSpecial li,
7815: .LC_ListStyleSpecial dd {
1.911 bisitz 7816: list-style-type: none;
7817: background-color: RGB(220, 220, 220);
7818: margin-bottom: 4px;
1.693 droeschl 7819: }
7820:
1.721 harmsja 7821: table.LC_SimpleTable {
1.911 bisitz 7822: margin:5px;
7823: border:solid 1px $lg_border_color;
1.795 www 7824: }
1.693 droeschl 7825:
1.721 harmsja 7826: table.LC_SimpleTable tr {
1.911 bisitz 7827: padding: 0;
7828: border:solid 1px $lg_border_color;
1.693 droeschl 7829: }
1.795 www 7830:
7831: table.LC_SimpleTable thead {
1.911 bisitz 7832: background:rgb(220,220,220);
1.693 droeschl 7833: }
7834:
1.721 harmsja 7835: div.LC_columnSection {
1.911 bisitz 7836: display: block;
7837: clear: both;
7838: overflow: hidden;
7839: margin: 0;
1.693 droeschl 7840: }
7841:
1.721 harmsja 7842: div.LC_columnSection>* {
1.911 bisitz 7843: float: left;
7844: margin: 10px 20px 10px 0;
7845: overflow:hidden;
1.693 droeschl 7846: }
1.721 harmsja 7847:
1.795 www 7848: table em {
1.911 bisitz 7849: font-weight: bold;
7850: font-style: normal;
1.748 schulted 7851: }
1.795 www 7852:
1.779 bisitz 7853: table.LC_tableBrowseRes,
1.795 www 7854: table.LC_tableOfContent {
1.911 bisitz 7855: border:none;
7856: border-spacing: 1px;
7857: padding: 3px;
7858: background-color: #FFFFFF;
7859: font-size: 90%;
1.753 droeschl 7860: }
1.789 droeschl 7861:
1.911 bisitz 7862: table.LC_tableOfContent {
7863: border-collapse: collapse;
1.789 droeschl 7864: }
7865:
1.771 droeschl 7866: table.LC_tableBrowseRes a,
1.768 schulted 7867: table.LC_tableOfContent a {
1.911 bisitz 7868: background-color: transparent;
7869: text-decoration: none;
1.753 droeschl 7870: }
7871:
1.795 www 7872: table.LC_tableOfContent img {
1.911 bisitz 7873: border: none;
7874: height: 1.3em;
7875: vertical-align: text-bottom;
7876: margin-right: 0.3em;
1.753 droeschl 7877: }
1.757 schulted 7878:
1.795 www 7879: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7880: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7881: }
7882:
1.795 www 7883: a#LC_content_toolbar_everything {
1.911 bisitz 7884: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7885: }
7886:
1.795 www 7887: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7888: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7889: }
7890:
1.795 www 7891: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7892: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7893: }
7894:
1.795 www 7895: a#LC_content_toolbar_changefolder {
1.911 bisitz 7896: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7897: }
7898:
1.795 www 7899: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7900: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7901: }
7902:
1.1043 raeburn 7903: a#LC_content_toolbar_edittoplevel {
7904: background-image:url(/res/adm/pages/edittoplevel.gif);
7905: }
7906:
1.795 www 7907: ul#LC_toolbar li a:hover {
1.911 bisitz 7908: background-position: bottom center;
1.757 schulted 7909: }
7910:
1.795 www 7911: ul#LC_toolbar {
1.911 bisitz 7912: padding: 0;
7913: margin: 2px;
7914: list-style:none;
7915: position:relative;
7916: background-color:white;
1.1082 raeburn 7917: overflow: auto;
1.757 schulted 7918: }
7919:
1.795 www 7920: ul#LC_toolbar li {
1.911 bisitz 7921: border:1px solid white;
7922: padding: 0;
7923: margin: 0;
7924: float: left;
7925: display:inline;
7926: vertical-align:middle;
1.1082 raeburn 7927: white-space: nowrap;
1.911 bisitz 7928: }
1.757 schulted 7929:
1.783 amueller 7930:
1.795 www 7931: a.LC_toolbarItem {
1.911 bisitz 7932: display:block;
7933: padding: 0;
7934: margin: 0;
7935: height: 32px;
7936: width: 32px;
7937: color:white;
7938: border: none;
7939: background-repeat:no-repeat;
7940: background-color:transparent;
1.757 schulted 7941: }
7942:
1.915 droeschl 7943: ul.LC_funclist {
7944: margin: 0;
7945: padding: 0.5em 1em 0.5em 0;
7946: }
7947:
1.933 droeschl 7948: ul.LC_funclist > li:first-child {
7949: font-weight:bold;
7950: margin-left:0.8em;
7951: }
7952:
1.915 droeschl 7953: ul.LC_funclist + ul.LC_funclist {
7954: /*
7955: left border as a seperator if we have more than
7956: one list
7957: */
7958: border-left: 1px solid $sidebg;
7959: /*
7960: this hides the left border behind the border of the
7961: outer box if element is wrapped to the next 'line'
7962: */
7963: margin-left: -1px;
7964: }
7965:
1.843 bisitz 7966: ul.LC_funclist li {
1.915 droeschl 7967: display: inline;
1.782 bisitz 7968: white-space: nowrap;
1.915 droeschl 7969: margin: 0 0 0 25px;
7970: line-height: 150%;
1.782 bisitz 7971: }
7972:
1.974 wenzelju 7973: .LC_hidden {
7974: display: none;
7975: }
7976:
1.1030 www 7977: .LCmodal-overlay {
7978: position:fixed;
7979: top:0;
7980: right:0;
7981: bottom:0;
7982: left:0;
7983: height:100%;
7984: width:100%;
7985: margin:0;
7986: padding:0;
7987: background:#999;
7988: opacity:.75;
7989: filter: alpha(opacity=75);
7990: -moz-opacity: 0.75;
7991: z-index:101;
7992: }
7993:
7994: * html .LCmodal-overlay {
7995: position: absolute;
7996: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7997: }
7998:
7999: .LCmodal-window {
8000: position:fixed;
8001: top:50%;
8002: left:50%;
8003: margin:0;
8004: padding:0;
8005: z-index:102;
8006: }
8007:
8008: * html .LCmodal-window {
8009: position:absolute;
8010: }
8011:
8012: .LCclose-window {
8013: position:absolute;
8014: width:32px;
8015: height:32px;
8016: right:8px;
8017: top:8px;
8018: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8019: text-indent:-99999px;
8020: overflow:hidden;
8021: cursor:pointer;
8022: }
8023:
1.1100 raeburn 8024: /*
1.1231 damieng 8025: styles used for response display
8026: */
8027: div.LC_radiofoil, div.LC_rankfoil {
8028: margin: .5em 0em .5em 0em;
8029: }
8030: table.LC_itemgroup {
8031: margin-top: 1em;
8032: }
8033:
8034: /*
1.1100 raeburn 8035: styles used by TTH when "Default set of options to pass to tth/m
8036: when converting TeX" in course settings has been set
8037:
8038: option passed: -t
8039:
8040: */
8041:
8042: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8043: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8044: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8045: td div.norm {line-height:normal;}
8046:
8047: /*
8048: option passed -y3
8049: */
8050:
8051: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8052: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8053: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8054:
1.1230 damieng 8055: /*
8056: sections with roles, for content only
8057: */
8058: section[class^="role-"] {
8059: padding-left: 10px;
8060: padding-right: 5px;
8061: margin-top: 8px;
8062: margin-bottom: 8px;
8063: border: 1px solid #2A4;
8064: border-radius: 5px;
8065: box-shadow: 0px 1px 1px #BBB;
8066: }
8067: section[class^="role-"]>h1 {
8068: position: relative;
8069: margin: 0px;
8070: padding-top: 10px;
8071: padding-left: 40px;
8072: }
8073: section[class^="role-"]>h1:before {
8074: position: absolute;
8075: left: -5px;
8076: top: 5px;
8077: }
8078: section.role-activity>h1:before {
8079: content:url('/adm/daxe/images/section_icons/activity.png');
8080: }
8081: section.role-advice>h1:before {
8082: content:url('/adm/daxe/images/section_icons/advice.png');
8083: }
8084: section.role-bibliography>h1:before {
8085: content:url('/adm/daxe/images/section_icons/bibliography.png');
8086: }
8087: section.role-citation>h1:before {
8088: content:url('/adm/daxe/images/section_icons/citation.png');
8089: }
8090: section.role-conclusion>h1:before {
8091: content:url('/adm/daxe/images/section_icons/conclusion.png');
8092: }
8093: section.role-definition>h1:before {
8094: content:url('/adm/daxe/images/section_icons/definition.png');
8095: }
8096: section.role-demonstration>h1:before {
8097: content:url('/adm/daxe/images/section_icons/demonstration.png');
8098: }
8099: section.role-example>h1:before {
8100: content:url('/adm/daxe/images/section_icons/example.png');
8101: }
8102: section.role-explanation>h1:before {
8103: content:url('/adm/daxe/images/section_icons/explanation.png');
8104: }
8105: section.role-introduction>h1:before {
8106: content:url('/adm/daxe/images/section_icons/introduction.png');
8107: }
8108: section.role-method>h1:before {
8109: content:url('/adm/daxe/images/section_icons/method.png');
8110: }
8111: section.role-more_information>h1:before {
8112: content:url('/adm/daxe/images/section_icons/more_information.png');
8113: }
8114: section.role-objectives>h1:before {
8115: content:url('/adm/daxe/images/section_icons/objectives.png');
8116: }
8117: section.role-prerequisites>h1:before {
8118: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8119: }
8120: section.role-remark>h1:before {
8121: content:url('/adm/daxe/images/section_icons/remark.png');
8122: }
8123: section.role-reminder>h1:before {
8124: content:url('/adm/daxe/images/section_icons/reminder.png');
8125: }
8126: section.role-summary>h1:before {
8127: content:url('/adm/daxe/images/section_icons/summary.png');
8128: }
8129: section.role-syntax>h1:before {
8130: content:url('/adm/daxe/images/section_icons/syntax.png');
8131: }
8132: section.role-warning>h1:before {
8133: content:url('/adm/daxe/images/section_icons/warning.png');
8134: }
8135:
1.1269 raeburn 8136: #LC_minitab_header {
8137: float:left;
8138: width:100%;
8139: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8140: font-size:93%;
8141: line-height:normal;
8142: margin: 0.5em 0 0.5em 0;
8143: }
8144: #LC_minitab_header ul {
8145: margin:0;
8146: padding:10px 10px 0;
8147: list-style:none;
8148: }
8149: #LC_minitab_header li {
8150: float:left;
8151: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8152: margin:0;
8153: padding:0 0 0 9px;
8154: }
8155: #LC_minitab_header a {
8156: display:block;
8157: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8158: padding:5px 15px 4px 6px;
8159: }
8160: #LC_minitab_header #LC_current_minitab {
8161: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8162: }
8163: #LC_minitab_header #LC_current_minitab a {
8164: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8165: padding-bottom:5px;
8166: }
8167:
8168:
1.343 albertel 8169: END
8170: }
8171:
1.306 albertel 8172: =pod
8173:
8174: =item * &headtag()
8175:
8176: Returns a uniform footer for LON-CAPA web pages.
8177:
1.307 albertel 8178: Inputs: $title - optional title for the head
8179: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8180: $args - optional arguments
1.319 albertel 8181: force_register - if is true call registerurl so the remote is
8182: informed
1.415 albertel 8183: redirect -> array ref of
8184: 1- seconds before redirect occurs
8185: 2- url to redirect to
8186: 3- whether the side effect should occur
1.315 albertel 8187: (side effect of setting
8188: $env{'internal.head.redirect'} to the url
8189: redirected too)
1.352 albertel 8190: domain -> force to color decorate a page for a specific
8191: domain
8192: function -> force usage of a specific rolish color scheme
8193: bgcolor -> override the default page bgcolor
1.460 albertel 8194: no_auto_mt_title
8195: -> prevent &mt()ing the title arg
1.464 albertel 8196:
1.306 albertel 8197: =cut
8198:
8199: sub headtag {
1.313 albertel 8200: my ($title,$head_extra,$args) = @_;
1.306 albertel 8201:
1.363 albertel 8202: my $function = $args->{'function'} || &get_users_function();
8203: my $domain = $args->{'domain'} || &determinedomain();
8204: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8205: my $httphost = $args->{'use_absolute'};
1.418 albertel 8206: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8207: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8208: #time(),
1.418 albertel 8209: $env{'environment.color.timestamp'},
1.363 albertel 8210: $function,$domain,$bgcolor);
8211:
1.369 www 8212: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8213:
1.308 albertel 8214: my $result =
8215: '<head>'.
1.1160 raeburn 8216: &font_settings($args);
1.319 albertel 8217:
1.1188 raeburn 8218: my $inhibitprint;
8219: if ($args->{'print_suppress'}) {
8220: $inhibitprint = &print_suppression();
8221: }
1.1064 raeburn 8222:
1.461 albertel 8223: if (!$args->{'frameset'}) {
8224: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8225: }
1.962 droeschl 8226: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8227: $result .= Apache::lonxml::display_title();
1.319 albertel 8228: }
1.436 albertel 8229: if (!$args->{'no_nav_bar'}
8230: && !$args->{'only_body'}
8231: && !$args->{'frameset'}) {
1.1154 raeburn 8232: $result .= &help_menu_js($httphost);
1.1032 www 8233: $result.=&modal_window();
1.1038 www 8234: $result.=&togglebox_script();
1.1034 www 8235: $result.=&wishlist_window();
1.1041 www 8236: $result.=&LCprogressbarUpdate_script();
1.1034 www 8237: } else {
8238: if ($args->{'add_modal'}) {
8239: $result.=&modal_window();
8240: }
8241: if ($args->{'add_wishlist'}) {
8242: $result.=&wishlist_window();
8243: }
1.1038 www 8244: if ($args->{'add_togglebox'}) {
8245: $result.=&togglebox_script();
8246: }
1.1041 www 8247: if ($args->{'add_progressbar'}) {
8248: $result.=&LCprogressbarUpdate_script();
8249: }
1.436 albertel 8250: }
1.314 albertel 8251: if (ref($args->{'redirect'})) {
1.414 albertel 8252: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8253: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8254: if (!$inhibit_continue) {
8255: $env{'internal.head.redirect'} = $url;
8256: }
1.313 albertel 8257: $result.=<<ADDMETA
8258: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8259: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8260: ADDMETA
1.1210 raeburn 8261: } else {
8262: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8263: my $requrl = $env{'request.uri'};
8264: if ($requrl eq '') {
8265: $requrl = $ENV{'REQUEST_URI'};
8266: $requrl =~ s/\?.+$//;
8267: }
8268: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8269: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8270: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8271: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8272: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8273: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
8274: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8275: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
8276: if ($domdefs{'offloadnow'}{$lonhost}) {
8277: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
8278: if (($newserver) && ($newserver ne $lonhost)) {
8279: my $numsec = 5;
8280: my $timeout = $numsec * 1000;
8281: my ($newurl,$locknum,%locks,$msg);
8282: if ($env{'request.role.adv'}) {
8283: ($locknum,%locks) = &Apache::lonnet::get_locks();
8284: }
8285: my $disable_submit = 0;
8286: if ($requrl =~ /$LONCAPA::assess_re/) {
8287: $disable_submit = 1;
8288: }
8289: if ($locknum) {
8290: my @lockinfo = sort(values(%locks));
8291: $msg = &mt('Once the following tasks are complete: ')."\\n".
8292: join(", ",sort(values(%locks)))."\\n".
8293: &mt('your session will be transferred to a different server, after you click "Roles".');
8294: } else {
8295: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8296: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
8297: }
8298: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8299: $newurl = '/adm/switchserver?otherserver='.$newserver;
8300: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8301: $newurl .= '&role='.$env{'request.role'};
8302: }
8303: if ($env{'request.symb'}) {
8304: $newurl .= '&symb='.$env{'request.symb'};
8305: } else {
8306: $newurl .= '&origurl='.$requrl;
8307: }
8308: }
1.1222 damieng 8309: &js_escape(\$msg);
1.1210 raeburn 8310: $result.=<<OFFLOAD
8311: <meta http-equiv="pragma" content="no-cache" />
8312: <script type="text/javascript">
1.1215 raeburn 8313: // <![CDATA[
1.1210 raeburn 8314: function LC_Offload_Now() {
8315: var dest = "$newurl";
8316: if (dest != '') {
8317: window.location.href="$newurl";
8318: }
8319: }
1.1214 raeburn 8320: \$(document).ready(function () {
8321: window.alert('$msg');
8322: if ($disable_submit) {
1.1210 raeburn 8323: \$(".LC_hwk_submit").prop("disabled", true);
8324: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8325: }
8326: setTimeout('LC_Offload_Now()', $timeout);
8327: });
1.1215 raeburn 8328: // ]]>
1.1210 raeburn 8329: </script>
8330: OFFLOAD
8331: }
8332: }
8333: }
8334: }
8335: }
8336: }
1.313 albertel 8337: }
1.306 albertel 8338: if (!defined($title)) {
8339: $title = 'The LearningOnline Network with CAPA';
8340: }
1.460 albertel 8341: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8342: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8343: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8344: if (!$args->{'frameset'}) {
8345: $result .= ' /';
8346: }
8347: $result .= '>'
1.1064 raeburn 8348: .$inhibitprint
1.414 albertel 8349: .$head_extra;
1.1242 raeburn 8350: my $clientmobile;
8351: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8352: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8353: } else {
8354: $clientmobile = $env{'browser.mobile'};
8355: }
8356: if ($clientmobile) {
1.1137 raeburn 8357: $result .= '
8358: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8359: <meta name="apple-mobile-web-app-capable" content="yes" />';
8360: }
1.1278 raeburn 8361: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8362: return $result.'</head>';
1.306 albertel 8363: }
8364:
8365: =pod
8366:
1.340 albertel 8367: =item * &font_settings()
8368:
8369: Returns neccessary <meta> to set the proper encoding
8370:
1.1160 raeburn 8371: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8372:
8373: =cut
8374:
8375: sub font_settings {
1.1160 raeburn 8376: my ($args) = @_;
1.340 albertel 8377: my $headerstring='';
1.1160 raeburn 8378: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8379: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8380: $headerstring.=
8381: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8382: if (!$args->{'frameset'}) {
8383: $headerstring.= ' /';
8384: }
8385: $headerstring .= '>'."\n";
1.340 albertel 8386: }
8387: return $headerstring;
8388: }
8389:
1.341 albertel 8390: =pod
8391:
1.1064 raeburn 8392: =item * &print_suppression()
8393:
8394: In course context returns css which causes the body to be blank when media="print",
8395: if printout generation is unavailable for the current resource.
8396:
8397: This could be because:
8398:
8399: (a) printstartdate is in the future
8400:
8401: (b) printenddate is in the past
8402:
8403: (c) there is an active exam block with "printout"
8404: functionality blocked
8405:
8406: Users with pav, pfo or evb privileges are exempt.
8407:
8408: Inputs: none
8409:
8410: =cut
8411:
8412:
8413: sub print_suppression {
8414: my $noprint;
8415: if ($env{'request.course.id'}) {
8416: my $scope = $env{'request.course.id'};
8417: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8418: (&Apache::lonnet::allowed('pfo',$scope))) {
8419: return;
8420: }
8421: if ($env{'request.course.sec'} ne '') {
8422: $scope .= "/$env{'request.course.sec'}";
8423: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8424: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8425: return;
1.1064 raeburn 8426: }
8427: }
8428: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8429: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8430: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8431: if ($blocked) {
8432: my $checkrole = "cm./$cdom/$cnum";
8433: if ($env{'request.course.sec'} ne '') {
8434: $checkrole .= "/$env{'request.course.sec'}";
8435: }
8436: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8437: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8438: $noprint = 1;
8439: }
8440: }
8441: unless ($noprint) {
8442: my $symb = &Apache::lonnet::symbread();
8443: if ($symb ne '') {
8444: my $navmap = Apache::lonnavmaps::navmap->new();
8445: if (ref($navmap)) {
8446: my $res = $navmap->getBySymb($symb);
8447: if (ref($res)) {
8448: if (!$res->resprintable()) {
8449: $noprint = 1;
8450: }
8451: }
8452: }
8453: }
8454: }
8455: if ($noprint) {
8456: return <<"ENDSTYLE";
8457: <style type="text/css" media="print">
8458: body { display:none }
8459: </style>
8460: ENDSTYLE
8461: }
8462: }
8463: return;
8464: }
8465:
8466: =pod
8467:
1.341 albertel 8468: =item * &xml_begin()
8469:
8470: Returns the needed doctype and <html>
8471:
8472: Inputs: none
8473:
8474: =cut
8475:
8476: sub xml_begin {
1.1168 raeburn 8477: my ($is_frameset) = @_;
1.341 albertel 8478: my $output='';
8479:
8480: if ($env{'browser.mathml'}) {
8481: $output='<?xml version="1.0"?>'
8482: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8483: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8484:
8485: # .'<!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">] >'
8486: .'<!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">'
8487: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8488: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8489: } elsif ($is_frameset) {
8490: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8491: '<html>'."\n";
1.341 albertel 8492: } else {
1.1168 raeburn 8493: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8494: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8495: }
8496: return $output;
8497: }
1.340 albertel 8498:
8499: =pod
8500:
1.306 albertel 8501: =item * &start_page()
8502:
8503: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8504:
1.648 raeburn 8505: Inputs:
8506:
8507: =over 4
8508:
8509: $title - optional title for the page
8510:
8511: $head_extra - optional extra HTML to incude inside the <head>
8512:
8513: $args - additional optional args supported are:
8514:
8515: =over 8
8516:
8517: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8518: arg on
1.814 bisitz 8519: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8520: add_entries -> additional attributes to add to the <body>
8521: domain -> force to color decorate a page for a
1.317 albertel 8522: specific domain
1.648 raeburn 8523: function -> force usage of a specific rolish color
1.317 albertel 8524: scheme
1.648 raeburn 8525: redirect -> see &headtag()
8526: bgcolor -> override the default page bg color
8527: js_ready -> return a string ready for being used in
1.317 albertel 8528: a javascript writeln
1.648 raeburn 8529: html_encode -> return a string ready for being used in
1.320 albertel 8530: a html attribute
1.648 raeburn 8531: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8532: $forcereg arg
1.648 raeburn 8533: frameset -> if true will start with a <frameset>
1.330 albertel 8534: rather than <body>
1.648 raeburn 8535: skip_phases -> hash ref of
1.338 albertel 8536: head -> skip the <html><head> generation
8537: body -> skip all <body> generation
1.648 raeburn 8538: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8539: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8540: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 8541: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8542: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 8543: group -> includes the current group, if page is for a
1.1274 raeburn 8544: specific group
8545: use_absolute -> for request for external resource or syllabus, this
8546: will contain https://<hostname> if server uses
8547: https (as per hosts.tab), but request is for http
8548: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8549:
1.648 raeburn 8550: =back
1.460 albertel 8551:
1.648 raeburn 8552: =back
1.562 albertel 8553:
1.306 albertel 8554: =cut
8555:
8556: sub start_page {
1.309 albertel 8557: my ($title,$head_extra,$args) = @_;
1.318 albertel 8558: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8559:
1.315 albertel 8560: $env{'internal.start_page'}++;
1.1096 raeburn 8561: my ($result,@advtools);
1.964 droeschl 8562:
1.338 albertel 8563: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8564: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8565: }
8566:
8567: if (! exists($args->{'skip_phases'}{'body'}) ) {
8568: if ($args->{'frameset'}) {
8569: my $attr_string = &make_attr_string($args->{'force_register'},
8570: $args->{'add_entries'});
8571: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8572: } else {
8573: $result .=
8574: &bodytag($title,
8575: $args->{'function'}, $args->{'add_entries'},
8576: $args->{'only_body'}, $args->{'domain'},
8577: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8578: $args->{'bgcolor'}, $args,
8579: \@advtools);
1.831 bisitz 8580: }
1.330 albertel 8581: }
1.338 albertel 8582:
1.315 albertel 8583: if ($args->{'js_ready'}) {
1.713 kaisler 8584: $result = &js_ready($result);
1.315 albertel 8585: }
1.320 albertel 8586: if ($args->{'html_encode'}) {
1.713 kaisler 8587: $result = &html_encode($result);
8588: }
8589:
1.813 bisitz 8590: # Preparation for new and consistent functionlist at top of screen
8591: # if ($args->{'functionlist'}) {
8592: # $result .= &build_functionlist();
8593: #}
8594:
1.964 droeschl 8595: # Don't add anything more if only_body wanted or in const space
8596: return $result if $args->{'only_body'}
8597: || $env{'request.state'} eq 'construct';
1.813 bisitz 8598:
8599: #Breadcrumbs
1.758 kaisler 8600: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8601: &Apache::lonhtmlcommon::clear_breadcrumbs();
8602: #if any br links exists, add them to the breadcrumbs
8603: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8604: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8605: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8606: }
8607: }
1.1096 raeburn 8608: # if @advtools array contains items add then to the breadcrumbs
8609: if (@advtools > 0) {
8610: &Apache::lonmenu::advtools_crumbs(@advtools);
8611: }
1.1272 raeburn 8612: my $menulink;
8613: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8614: if ((exists($args->{'bread_crumbs_nomenu'})) ||
8615: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
8616: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
8617: (!$env{'request.role.adv'}))) {
8618: $menulink = 0;
8619: } else {
8620: undef($menulink);
8621: }
1.758 kaisler 8622: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8623: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 8624: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 8625: } else {
1.1272 raeburn 8626: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8627: }
1.320 albertel 8628: }
1.315 albertel 8629: return $result;
1.306 albertel 8630: }
8631:
8632: sub end_page {
1.315 albertel 8633: my ($args) = @_;
8634: $env{'internal.end_page'}++;
1.330 albertel 8635: my $result;
1.335 albertel 8636: if ($args->{'discussion'}) {
8637: my ($target,$parser);
8638: if (ref($args->{'discussion'})) {
8639: ($target,$parser) =($args->{'discussion'}{'target'},
8640: $args->{'discussion'}{'parser'});
8641: }
8642: $result .= &Apache::lonxml::xmlend($target,$parser);
8643: }
1.330 albertel 8644: if ($args->{'frameset'}) {
8645: $result .= '</frameset>';
8646: } else {
1.635 raeburn 8647: $result .= &endbodytag($args);
1.330 albertel 8648: }
1.1080 raeburn 8649: unless ($args->{'notbody'}) {
8650: $result .= "\n</html>";
8651: }
1.330 albertel 8652:
1.315 albertel 8653: if ($args->{'js_ready'}) {
1.317 albertel 8654: $result = &js_ready($result);
1.315 albertel 8655: }
1.335 albertel 8656:
1.320 albertel 8657: if ($args->{'html_encode'}) {
8658: $result = &html_encode($result);
8659: }
1.335 albertel 8660:
1.315 albertel 8661: return $result;
8662: }
8663:
1.1034 www 8664: sub wishlist_window {
8665: return(<<'ENDWISHLIST');
1.1046 raeburn 8666: <script type="text/javascript">
1.1034 www 8667: // <![CDATA[
8668: // <!-- BEGIN LON-CAPA Internal
8669: function set_wishlistlink(title, path) {
8670: if (!title) {
8671: title = document.title;
8672: title = title.replace(/^LON-CAPA /,'');
8673: }
1.1175 raeburn 8674: title = encodeURIComponent(title);
1.1203 raeburn 8675: title = title.replace("'","\\\'");
1.1034 www 8676: if (!path) {
8677: path = location.pathname;
8678: }
1.1175 raeburn 8679: path = encodeURIComponent(path);
1.1203 raeburn 8680: path = path.replace("'","\\\'");
1.1034 www 8681: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8682: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8683: }
8684: // END LON-CAPA Internal -->
8685: // ]]>
8686: </script>
8687: ENDWISHLIST
8688: }
8689:
1.1030 www 8690: sub modal_window {
8691: return(<<'ENDMODAL');
1.1046 raeburn 8692: <script type="text/javascript">
1.1030 www 8693: // <![CDATA[
8694: // <!-- BEGIN LON-CAPA Internal
8695: var modalWindow = {
8696: parent:"body",
8697: windowId:null,
8698: content:null,
8699: width:null,
8700: height:null,
8701: close:function()
8702: {
8703: $(".LCmodal-window").remove();
8704: $(".LCmodal-overlay").remove();
8705: },
8706: open:function()
8707: {
8708: var modal = "";
8709: modal += "<div class=\"LCmodal-overlay\"></div>";
8710: 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;\">";
8711: modal += this.content;
8712: modal += "</div>";
8713:
8714: $(this.parent).append(modal);
8715:
8716: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8717: $(".LCclose-window").click(function(){modalWindow.close();});
8718: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8719: }
8720: };
1.1140 raeburn 8721: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8722: {
1.1266 raeburn 8723: source = source.replace(/'/g,"'");
1.1030 www 8724: modalWindow.windowId = "myModal";
8725: modalWindow.width = width;
8726: modalWindow.height = height;
1.1196 raeburn 8727: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8728: modalWindow.open();
1.1208 raeburn 8729: };
1.1030 www 8730: // END LON-CAPA Internal -->
8731: // ]]>
8732: </script>
8733: ENDMODAL
8734: }
8735:
8736: sub modal_link {
1.1140 raeburn 8737: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8738: unless ($width) { $width=480; }
8739: unless ($height) { $height=400; }
1.1031 www 8740: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 8741: unless ($transparency) { $transparency='true'; }
8742:
1.1074 raeburn 8743: my $target_attr;
8744: if (defined($target)) {
8745: $target_attr = 'target="'.$target.'"';
8746: }
8747: return <<"ENDLINK";
1.1140 raeburn 8748: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8749: $linktext</a>
8750: ENDLINK
1.1030 www 8751: }
8752:
1.1032 www 8753: sub modal_adhoc_script {
8754: my ($funcname,$width,$height,$content)=@_;
8755: return (<<ENDADHOC);
1.1046 raeburn 8756: <script type="text/javascript">
1.1032 www 8757: // <![CDATA[
8758: var $funcname = function()
8759: {
8760: modalWindow.windowId = "myModal";
8761: modalWindow.width = $width;
8762: modalWindow.height = $height;
8763: modalWindow.content = '$content';
8764: modalWindow.open();
8765: };
8766: // ]]>
8767: </script>
8768: ENDADHOC
8769: }
8770:
1.1041 www 8771: sub modal_adhoc_inner {
8772: my ($funcname,$width,$height,$content)=@_;
8773: my $innerwidth=$width-20;
8774: $content=&js_ready(
1.1140 raeburn 8775: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
8776: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8777: $content.
1.1041 www 8778: &end_scrollbox().
1.1140 raeburn 8779: &end_page()
1.1041 www 8780: );
8781: return &modal_adhoc_script($funcname,$width,$height,$content);
8782: }
8783:
8784: sub modal_adhoc_window {
8785: my ($funcname,$width,$height,$content,$linktext)=@_;
8786: return &modal_adhoc_inner($funcname,$width,$height,$content).
8787: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8788: }
8789:
8790: sub modal_adhoc_launch {
8791: my ($funcname,$width,$height,$content)=@_;
8792: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8793: <script type="text/javascript">
8794: // <![CDATA[
8795: $funcname();
8796: // ]]>
8797: </script>
8798: ENDLAUNCH
8799: }
8800:
8801: sub modal_adhoc_close {
8802: return (<<ENDCLOSE);
8803: <script type="text/javascript">
8804: // <![CDATA[
8805: modalWindow.close();
8806: // ]]>
8807: </script>
8808: ENDCLOSE
8809: }
8810:
1.1038 www 8811: sub togglebox_script {
8812: return(<<ENDTOGGLE);
8813: <script type="text/javascript">
8814: // <![CDATA[
8815: function LCtoggleDisplay(id,hidetext,showtext) {
8816: link = document.getElementById(id + "link").childNodes[0];
8817: with (document.getElementById(id).style) {
8818: if (display == "none" ) {
8819: display = "inline";
8820: link.nodeValue = hidetext;
8821: } else {
8822: display = "none";
8823: link.nodeValue = showtext;
8824: }
8825: }
8826: }
8827: // ]]>
8828: </script>
8829: ENDTOGGLE
8830: }
8831:
1.1039 www 8832: sub start_togglebox {
8833: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8834: unless ($heading) { $heading=''; } else { $heading.=' '; }
8835: unless ($showtext) { $showtext=&mt('show'); }
8836: unless ($hidetext) { $hidetext=&mt('hide'); }
8837: unless ($headerbg) { $headerbg='#FFFFFF'; }
8838: return &start_data_table().
8839: &start_data_table_header_row().
8840: '<td bgcolor="'.$headerbg.'">'.$heading.
8841: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8842: $showtext.'\')">'.$showtext.'</a>]</td>'.
8843: &end_data_table_header_row().
8844: '<tr id="'.$id.'" style="display:none""><td>';
8845: }
8846:
8847: sub end_togglebox {
8848: return '</td></tr>'.&end_data_table();
8849: }
8850:
1.1041 www 8851: sub LCprogressbar_script {
1.1045 www 8852: my ($id)=@_;
1.1041 www 8853: return(<<ENDPROGRESS);
8854: <script type="text/javascript">
8855: // <![CDATA[
1.1045 www 8856: \$('#progressbar$id').progressbar({
1.1041 www 8857: value: 0,
8858: change: function(event, ui) {
8859: var newVal = \$(this).progressbar('option', 'value');
8860: \$('.pblabel', this).text(LCprogressTxt);
8861: }
8862: });
8863: // ]]>
8864: </script>
8865: ENDPROGRESS
8866: }
8867:
8868: sub LCprogressbarUpdate_script {
8869: return(<<ENDPROGRESSUPDATE);
8870: <style type="text/css">
8871: .ui-progressbar { position:relative; }
8872: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8873: </style>
8874: <script type="text/javascript">
8875: // <![CDATA[
1.1045 www 8876: var LCprogressTxt='---';
8877:
8878: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8879: LCprogressTxt=progresstext;
1.1045 www 8880: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8881: }
8882: // ]]>
8883: </script>
8884: ENDPROGRESSUPDATE
8885: }
8886:
1.1042 www 8887: my $LClastpercent;
1.1045 www 8888: my $LCidcnt;
8889: my $LCcurrentid;
1.1042 www 8890:
1.1041 www 8891: sub LCprogressbar {
1.1042 www 8892: my ($r)=(@_);
8893: $LClastpercent=0;
1.1045 www 8894: $LCidcnt++;
8895: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8896: my $starting=&mt('Starting');
8897: my $content=(<<ENDPROGBAR);
1.1045 www 8898: <div id="progressbar$LCcurrentid">
1.1041 www 8899: <span class="pblabel">$starting</span>
8900: </div>
8901: ENDPROGBAR
1.1045 www 8902: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8903: }
8904:
8905: sub LCprogressbarUpdate {
1.1042 www 8906: my ($r,$val,$text)=@_;
8907: unless ($val) {
8908: if ($LClastpercent) {
8909: $val=$LClastpercent;
8910: } else {
8911: $val=0;
8912: }
8913: }
1.1041 www 8914: if ($val<0) { $val=0; }
8915: if ($val>100) { $val=0; }
1.1042 www 8916: $LClastpercent=$val;
1.1041 www 8917: unless ($text) { $text=$val.'%'; }
8918: $text=&js_ready($text);
1.1044 www 8919: &r_print($r,<<ENDUPDATE);
1.1041 www 8920: <script type="text/javascript">
8921: // <![CDATA[
1.1045 www 8922: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8923: // ]]>
8924: </script>
8925: ENDUPDATE
1.1035 www 8926: }
8927:
1.1042 www 8928: sub LCprogressbarClose {
8929: my ($r)=@_;
8930: $LClastpercent=0;
1.1044 www 8931: &r_print($r,<<ENDCLOSE);
1.1042 www 8932: <script type="text/javascript">
8933: // <![CDATA[
1.1045 www 8934: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8935: // ]]>
8936: </script>
8937: ENDCLOSE
1.1044 www 8938: }
8939:
8940: sub r_print {
8941: my ($r,$to_print)=@_;
8942: if ($r) {
8943: $r->print($to_print);
8944: $r->rflush();
8945: } else {
8946: print($to_print);
8947: }
1.1042 www 8948: }
8949:
1.320 albertel 8950: sub html_encode {
8951: my ($result) = @_;
8952:
1.322 albertel 8953: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8954:
8955: return $result;
8956: }
1.1044 www 8957:
1.317 albertel 8958: sub js_ready {
8959: my ($result) = @_;
8960:
1.323 albertel 8961: $result =~ s/[\n\r]/ /xmsg;
8962: $result =~ s/\\/\\\\/xmsg;
8963: $result =~ s/'/\\'/xmsg;
1.372 albertel 8964: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8965:
8966: return $result;
8967: }
8968:
1.315 albertel 8969: sub validate_page {
8970: if ( exists($env{'internal.start_page'})
1.316 albertel 8971: && $env{'internal.start_page'} > 1) {
8972: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8973: $env{'internal.start_page'}.' '.
1.316 albertel 8974: $ENV{'request.filename'});
1.315 albertel 8975: }
8976: if ( exists($env{'internal.end_page'})
1.316 albertel 8977: && $env{'internal.end_page'} > 1) {
8978: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8979: $env{'internal.end_page'}.' '.
1.316 albertel 8980: $env{'request.filename'});
1.315 albertel 8981: }
8982: if ( exists($env{'internal.start_page'})
8983: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8984: &Apache::lonnet::logthis('start_page called without end_page '.
8985: $env{'request.filename'});
1.315 albertel 8986: }
8987: if ( ! exists($env{'internal.start_page'})
8988: && exists($env{'internal.end_page'})) {
1.316 albertel 8989: &Apache::lonnet::logthis('end_page called without start_page'.
8990: $env{'request.filename'});
1.315 albertel 8991: }
1.306 albertel 8992: }
1.315 albertel 8993:
1.996 www 8994:
8995: sub start_scrollbox {
1.1140 raeburn 8996: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8997: unless ($outerwidth) { $outerwidth='520px'; }
8998: unless ($width) { $width='500px'; }
8999: unless ($height) { $height='200px'; }
1.1075 raeburn 9000: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9001: if ($id ne '') {
1.1140 raeburn 9002: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9003: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9004: }
1.1075 raeburn 9005: if ($bgcolor ne '') {
9006: $tdcol = "background-color: $bgcolor;";
9007: }
1.1137 raeburn 9008: my $nicescroll_js;
9009: if ($env{'browser.mobile'}) {
1.1140 raeburn 9010: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9011: }
9012: return <<"END";
9013: $nicescroll_js
9014:
9015: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9016: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9017: END
9018: }
9019:
9020: sub end_scrollbox {
9021: return '</div></td></tr></table>';
9022: }
9023:
9024: sub nicescroll_javascript {
9025: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9026: my %options;
9027: if (ref($cursor) eq 'HASH') {
9028: %options = %{$cursor};
9029: }
9030: unless ($options{'railalign'} =~ /^left|right$/) {
9031: $options{'railalign'} = 'left';
9032: }
9033: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9034: my $function = &get_users_function();
9035: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9036: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9037: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9038: }
1.1140 raeburn 9039: }
9040: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9041: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9042: $options{'cursoropacity'}='1.0';
9043: }
1.1140 raeburn 9044: } else {
9045: $options{'cursoropacity'}='1.0';
9046: }
9047: if ($options{'cursorfixedheight'} eq 'none') {
9048: delete($options{'cursorfixedheight'});
9049: } else {
9050: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9051: }
9052: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9053: delete($options{'railoffset'});
9054: }
9055: my @niceoptions;
9056: while (my($key,$value) = each(%options)) {
9057: if ($value =~ /^\{.+\}$/) {
9058: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9059: } else {
1.1140 raeburn 9060: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9061: }
1.1140 raeburn 9062: }
9063: my $nicescroll_js = '
1.1137 raeburn 9064: $(document).ready(
1.1140 raeburn 9065: function() {
9066: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9067: }
1.1137 raeburn 9068: );
9069: ';
1.1140 raeburn 9070: if ($framecheck) {
9071: $nicescroll_js .= '
9072: function expand_div(caller) {
9073: if (top === self) {
9074: document.getElementById("'.$id.'").style.width = "auto";
9075: document.getElementById("'.$id.'").style.height = "auto";
9076: } else {
9077: try {
9078: if (parent.frames) {
9079: if (parent.frames.length > 1) {
9080: var framesrc = parent.frames[1].location.href;
9081: var currsrc = framesrc.replace(/\#.*$/,"");
9082: if ((caller == "search") || (currsrc == "'.$location.'")) {
9083: document.getElementById("'.$id.'").style.width = "auto";
9084: document.getElementById("'.$id.'").style.height = "auto";
9085: }
9086: }
9087: }
9088: } catch (e) {
9089: return;
9090: }
1.1137 raeburn 9091: }
1.1140 raeburn 9092: return;
1.996 www 9093: }
1.1140 raeburn 9094: ';
9095: }
9096: if ($needjsready) {
9097: $nicescroll_js = '
9098: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9099: } else {
9100: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9101: }
9102: return $nicescroll_js;
1.996 www 9103: }
9104:
1.318 albertel 9105: sub simple_error_page {
1.1150 bisitz 9106: my ($r,$title,$msg,$args) = @_;
1.1151 raeburn 9107: if (ref($args) eq 'HASH') {
9108: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
9109: } else {
9110: $msg = &mt($msg);
9111: }
1.1150 bisitz 9112:
1.318 albertel 9113: my $page =
9114: &Apache::loncommon::start_page($title).
1.1150 bisitz 9115: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9116: &Apache::loncommon::end_page();
9117: if (ref($r)) {
9118: $r->print($page);
1.327 albertel 9119: return;
1.318 albertel 9120: }
9121: return $page;
9122: }
1.347 albertel 9123:
9124: {
1.610 albertel 9125: my @row_count;
1.961 onken 9126:
9127: sub start_data_table_count {
9128: unshift(@row_count, 0);
9129: return;
9130: }
9131:
9132: sub end_data_table_count {
9133: shift(@row_count);
9134: return;
9135: }
9136:
1.347 albertel 9137: sub start_data_table {
1.1018 raeburn 9138: my ($add_class,$id) = @_;
1.422 albertel 9139: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9140: my $table_id;
9141: if (defined($id)) {
9142: $table_id = ' id="'.$id.'"';
9143: }
1.961 onken 9144: &start_data_table_count();
1.1018 raeburn 9145: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9146: }
9147:
9148: sub end_data_table {
1.961 onken 9149: &end_data_table_count();
1.389 albertel 9150: return '</table>'."\n";;
1.347 albertel 9151: }
9152:
9153: sub start_data_table_row {
1.974 wenzelju 9154: my ($add_class, $id) = @_;
1.610 albertel 9155: $row_count[0]++;
9156: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9157: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9158: $id = (' id="'.$id.'"') unless ($id eq '');
9159: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9160: }
1.471 banghart 9161:
9162: sub continue_data_table_row {
1.974 wenzelju 9163: my ($add_class, $id) = @_;
1.610 albertel 9164: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9165: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9166: $id = (' id="'.$id.'"') unless ($id eq '');
9167: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9168: }
1.347 albertel 9169:
9170: sub end_data_table_row {
1.389 albertel 9171: return '</tr>'."\n";;
1.347 albertel 9172: }
1.367 www 9173:
1.421 albertel 9174: sub start_data_table_empty_row {
1.707 bisitz 9175: # $row_count[0]++;
1.421 albertel 9176: return '<tr class="LC_empty_row" >'."\n";;
9177: }
9178:
9179: sub end_data_table_empty_row {
9180: return '</tr>'."\n";;
9181: }
9182:
1.367 www 9183: sub start_data_table_header_row {
1.389 albertel 9184: return '<tr class="LC_header_row">'."\n";;
1.367 www 9185: }
9186:
9187: sub end_data_table_header_row {
1.389 albertel 9188: return '</tr>'."\n";;
1.367 www 9189: }
1.890 droeschl 9190:
9191: sub data_table_caption {
9192: my $caption = shift;
9193: return "<caption class=\"LC_caption\">$caption</caption>";
9194: }
1.347 albertel 9195: }
9196:
1.548 albertel 9197: =pod
9198:
9199: =item * &inhibit_menu_check($arg)
9200:
9201: Checks for a inhibitmenu state and generates output to preserve it
9202:
9203: Inputs: $arg - can be any of
9204: - undef - in which case the return value is a string
9205: to add into arguments list of a uri
9206: - 'input' - in which case the return value is a HTML
9207: <form> <input> field of type hidden to
9208: preserve the value
9209: - a url - in which case the return value is the url with
9210: the neccesary cgi args added to preserve the
9211: inhibitmenu state
9212: - a ref to a url - no return value, but the string is
9213: updated to include the neccessary cgi
9214: args to preserve the inhibitmenu state
9215:
9216: =cut
9217:
9218: sub inhibit_menu_check {
9219: my ($arg) = @_;
9220: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9221: if ($arg eq 'input') {
9222: if ($env{'form.inhibitmenu'}) {
9223: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9224: } else {
9225: return
9226: }
9227: }
9228: if ($env{'form.inhibitmenu'}) {
9229: if (ref($arg)) {
9230: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9231: } elsif ($arg eq '') {
9232: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9233: } else {
9234: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9235: }
9236: }
9237: if (!ref($arg)) {
9238: return $arg;
9239: }
9240: }
9241:
1.251 albertel 9242: ###############################################
1.182 matthew 9243:
9244: =pod
9245:
1.549 albertel 9246: =back
9247:
9248: =head1 User Information Routines
9249:
9250: =over 4
9251:
1.405 albertel 9252: =item * &get_users_function()
1.182 matthew 9253:
9254: Used by &bodytag to determine the current users primary role.
9255: Returns either 'student','coordinator','admin', or 'author'.
9256:
9257: =cut
9258:
9259: ###############################################
9260: sub get_users_function {
1.815 tempelho 9261: my $function = 'norole';
1.818 tempelho 9262: if ($env{'request.role'}=~/^(st)/) {
9263: $function='student';
9264: }
1.907 raeburn 9265: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9266: $function='coordinator';
9267: }
1.258 albertel 9268: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9269: $function='admin';
9270: }
1.826 bisitz 9271: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9272: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9273: $function='author';
9274: }
9275: return $function;
1.54 www 9276: }
1.99 www 9277:
9278: ###############################################
9279:
1.233 raeburn 9280: =pod
9281:
1.821 raeburn 9282: =item * &show_course()
9283:
9284: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9285: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9286:
9287: Inputs:
9288: None
9289:
9290: Outputs:
9291: Scalar: 1 if 'Course' to be used, 0 otherwise.
9292:
9293: =cut
9294:
9295: ###############################################
9296: sub show_course {
9297: my $course = !$env{'user.adv'};
9298: if (!$env{'user.adv'}) {
9299: foreach my $env (keys(%env)) {
9300: next if ($env !~ m/^user\.priv\./);
9301: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9302: $course = 0;
9303: last;
9304: }
9305: }
9306: }
9307: return $course;
9308: }
9309:
9310: ###############################################
9311:
9312: =pod
9313:
1.542 raeburn 9314: =item * &check_user_status()
1.274 raeburn 9315:
9316: Determines current status of supplied role for a
9317: specific user. Roles can be active, previous or future.
9318:
9319: Inputs:
9320: user's domain, user's username, course's domain,
1.375 raeburn 9321: course's number, optional section ID.
1.274 raeburn 9322:
9323: Outputs:
9324: role status: active, previous or future.
9325:
9326: =cut
9327:
9328: sub check_user_status {
1.412 raeburn 9329: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9330: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9331: my @uroles = keys(%userinfo);
1.274 raeburn 9332: my $srchstr;
9333: my $active_chk = 'none';
1.412 raeburn 9334: my $now = time;
1.274 raeburn 9335: if (@uroles > 0) {
1.908 raeburn 9336: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9337: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9338: } else {
1.412 raeburn 9339: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9340: }
9341: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9342: my $role_end = 0;
9343: my $role_start = 0;
9344: $active_chk = 'active';
1.412 raeburn 9345: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9346: $role_end = $1;
9347: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9348: $role_start = $1;
1.274 raeburn 9349: }
9350: }
9351: if ($role_start > 0) {
1.412 raeburn 9352: if ($now < $role_start) {
1.274 raeburn 9353: $active_chk = 'future';
9354: }
9355: }
9356: if ($role_end > 0) {
1.412 raeburn 9357: if ($now > $role_end) {
1.274 raeburn 9358: $active_chk = 'previous';
9359: }
9360: }
9361: }
9362: }
9363: return $active_chk;
9364: }
9365:
9366: ###############################################
9367:
9368: =pod
9369:
1.405 albertel 9370: =item * &get_sections()
1.233 raeburn 9371:
9372: Determines all the sections for a course including
9373: sections with students and sections containing other roles.
1.419 raeburn 9374: Incoming parameters:
9375:
9376: 1. domain
9377: 2. course number
9378: 3. reference to array containing roles for which sections should
9379: be gathered (optional).
9380: 4. reference to array containing status types for which sections
9381: should be gathered (optional).
9382:
9383: If the third argument is undefined, sections are gathered for any role.
9384: If the fourth argument is undefined, sections are gathered for any status.
9385: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9386:
1.374 raeburn 9387: Returns section hash (keys are section IDs, values are
9388: number of users in each section), subject to the
1.419 raeburn 9389: optional roles filter, optional status filter
1.233 raeburn 9390:
9391: =cut
9392:
9393: ###############################################
9394: sub get_sections {
1.419 raeburn 9395: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9396: if (!defined($cdom) || !defined($cnum)) {
9397: my $cid = $env{'request.course.id'};
9398:
9399: return if (!defined($cid));
9400:
9401: $cdom = $env{'course.'.$cid.'.domain'};
9402: $cnum = $env{'course.'.$cid.'.num'};
9403: }
9404:
9405: my %sectioncount;
1.419 raeburn 9406: my $now = time;
1.240 albertel 9407:
1.1118 raeburn 9408: my $check_students = 1;
9409: my $only_students = 0;
9410: if (ref($possible_roles) eq 'ARRAY') {
9411: if (grep(/^st$/,@{$possible_roles})) {
9412: if (@{$possible_roles} == 1) {
9413: $only_students = 1;
9414: }
9415: } else {
9416: $check_students = 0;
9417: }
9418: }
9419:
9420: if ($check_students) {
1.276 albertel 9421: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9422: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9423: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9424: my $start_index = &Apache::loncoursedata::CL_START();
9425: my $end_index = &Apache::loncoursedata::CL_END();
9426: my $status;
1.366 albertel 9427: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9428: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9429: $data->[$status_index],
9430: $data->[$start_index],
9431: $data->[$end_index]);
9432: if ($stu_status eq 'Active') {
9433: $status = 'active';
9434: } elsif ($end < $now) {
9435: $status = 'previous';
9436: } elsif ($start > $now) {
9437: $status = 'future';
9438: }
9439: if ($section ne '-1' && $section !~ /^\s*$/) {
9440: if ((!defined($possible_status)) || (($status ne '') &&
9441: (grep/^\Q$status\E$/,@{$possible_status}))) {
9442: $sectioncount{$section}++;
9443: }
1.240 albertel 9444: }
9445: }
9446: }
1.1118 raeburn 9447: if ($only_students) {
9448: return %sectioncount;
9449: }
1.240 albertel 9450: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9451: foreach my $user (sort(keys(%courseroles))) {
9452: if ($user !~ /^(\w{2})/) { next; }
9453: my ($role) = ($user =~ /^(\w{2})/);
9454: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9455: my ($section,$status);
1.240 albertel 9456: if ($role eq 'cr' &&
9457: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9458: $section=$1;
9459: }
9460: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9461: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9462: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9463: if ($end == -1 && $start == -1) {
9464: next; #deleted role
9465: }
9466: if (!defined($possible_status)) {
9467: $sectioncount{$section}++;
9468: } else {
9469: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9470: $status = 'active';
9471: } elsif ($end < $now) {
9472: $status = 'future';
9473: } elsif ($start > $now) {
9474: $status = 'previous';
9475: }
9476: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9477: $sectioncount{$section}++;
9478: }
9479: }
1.233 raeburn 9480: }
1.366 albertel 9481: return %sectioncount;
1.233 raeburn 9482: }
9483:
1.274 raeburn 9484: ###############################################
1.294 raeburn 9485:
9486: =pod
1.405 albertel 9487:
9488: =item * &get_course_users()
9489:
1.275 raeburn 9490: Retrieves usernames:domains for users in the specified course
9491: with specific role(s), and access status.
9492:
9493: Incoming parameters:
1.277 albertel 9494: 1. course domain
9495: 2. course number
9496: 3. access status: users must have - either active,
1.275 raeburn 9497: previous, future, or all.
1.277 albertel 9498: 4. reference to array of permissible roles
1.288 raeburn 9499: 5. reference to array of section restrictions (optional)
9500: 6. reference to results object (hash of hashes).
9501: 7. reference to optional userdata hash
1.609 raeburn 9502: 8. reference to optional statushash
1.630 raeburn 9503: 9. flag if privileged users (except those set to unhide in
9504: course settings) should be excluded
1.609 raeburn 9505: Keys of top level results hash are roles.
1.275 raeburn 9506: Keys of inner hashes are username:domain, with
9507: values set to access type.
1.288 raeburn 9508: Optional userdata hash returns an array with arguments in the
9509: same order as loncoursedata::get_classlist() for student data.
9510:
1.609 raeburn 9511: Optional statushash returns
9512:
1.288 raeburn 9513: Entries for end, start, section and status are blank because
9514: of the possibility of multiple values for non-student roles.
9515:
1.275 raeburn 9516: =cut
1.405 albertel 9517:
1.275 raeburn 9518: ###############################################
1.405 albertel 9519:
1.275 raeburn 9520: sub get_course_users {
1.630 raeburn 9521: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9522: my %idx = ();
1.419 raeburn 9523: my %seclists;
1.288 raeburn 9524:
9525: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9526: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9527: $idx{end} = &Apache::loncoursedata::CL_END();
9528: $idx{start} = &Apache::loncoursedata::CL_START();
9529: $idx{id} = &Apache::loncoursedata::CL_ID();
9530: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9531: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9532: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9533:
1.290 albertel 9534: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9535: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9536: my $now = time;
1.277 albertel 9537: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9538: my $match = 0;
1.412 raeburn 9539: my $secmatch = 0;
1.419 raeburn 9540: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9541: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9542: if ($section eq '') {
9543: $section = 'none';
9544: }
1.291 albertel 9545: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9546: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9547: $secmatch = 1;
9548: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9549: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9550: $secmatch = 1;
9551: }
9552: } else {
1.419 raeburn 9553: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9554: $secmatch = 1;
9555: }
1.290 albertel 9556: }
1.412 raeburn 9557: if (!$secmatch) {
9558: next;
9559: }
1.419 raeburn 9560: }
1.275 raeburn 9561: if (defined($$types{'active'})) {
1.288 raeburn 9562: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9563: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9564: $match = 1;
1.275 raeburn 9565: }
9566: }
9567: if (defined($$types{'previous'})) {
1.609 raeburn 9568: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9569: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9570: $match = 1;
1.275 raeburn 9571: }
9572: }
9573: if (defined($$types{'future'})) {
1.609 raeburn 9574: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9575: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9576: $match = 1;
1.275 raeburn 9577: }
9578: }
1.609 raeburn 9579: if ($match) {
9580: push(@{$seclists{$student}},$section);
9581: if (ref($userdata) eq 'HASH') {
9582: $$userdata{$student} = $$classlist{$student};
9583: }
9584: if (ref($statushash) eq 'HASH') {
9585: $statushash->{$student}{'st'}{$section} = $status;
9586: }
1.288 raeburn 9587: }
1.275 raeburn 9588: }
9589: }
1.412 raeburn 9590: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9591: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9592: my $now = time;
1.609 raeburn 9593: my %displaystatus = ( previous => 'Expired',
9594: active => 'Active',
9595: future => 'Future',
9596: );
1.1121 raeburn 9597: my (%nothide,@possdoms);
1.630 raeburn 9598: if ($hidepriv) {
9599: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9600: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9601: if ($user !~ /:/) {
9602: $nothide{join(':',split(/[\@]/,$user))}=1;
9603: } else {
9604: $nothide{$user} = 1;
9605: }
9606: }
1.1121 raeburn 9607: my @possdoms = ($cdom);
9608: if ($coursehash{'checkforpriv'}) {
9609: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9610: }
1.630 raeburn 9611: }
1.439 raeburn 9612: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9613: my $match = 0;
1.412 raeburn 9614: my $secmatch = 0;
1.439 raeburn 9615: my $status;
1.412 raeburn 9616: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9617: $user =~ s/:$//;
1.439 raeburn 9618: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9619: if ($end == -1 || $start == -1) {
9620: next;
9621: }
9622: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9623: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9624: my ($uname,$udom) = split(/:/,$user);
9625: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9626: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9627: $secmatch = 1;
9628: } elsif ($usec eq '') {
1.420 albertel 9629: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9630: $secmatch = 1;
9631: }
9632: } else {
9633: if (grep(/^\Q$usec\E$/,@{$sections})) {
9634: $secmatch = 1;
9635: }
9636: }
9637: if (!$secmatch) {
9638: next;
9639: }
1.288 raeburn 9640: }
1.419 raeburn 9641: if ($usec eq '') {
9642: $usec = 'none';
9643: }
1.275 raeburn 9644: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9645: if ($hidepriv) {
1.1121 raeburn 9646: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9647: (!$nothide{$uname.':'.$udom})) {
9648: next;
9649: }
9650: }
1.503 raeburn 9651: if ($end > 0 && $end < $now) {
1.439 raeburn 9652: $status = 'previous';
9653: } elsif ($start > $now) {
9654: $status = 'future';
9655: } else {
9656: $status = 'active';
9657: }
1.277 albertel 9658: foreach my $type (keys(%{$types})) {
1.275 raeburn 9659: if ($status eq $type) {
1.420 albertel 9660: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9661: push(@{$$users{$role}{$user}},$type);
9662: }
1.288 raeburn 9663: $match = 1;
9664: }
9665: }
1.419 raeburn 9666: if (($match) && (ref($userdata) eq 'HASH')) {
9667: if (!exists($$userdata{$uname.':'.$udom})) {
9668: &get_user_info($udom,$uname,\%idx,$userdata);
9669: }
1.420 albertel 9670: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9671: push(@{$seclists{$uname.':'.$udom}},$usec);
9672: }
1.609 raeburn 9673: if (ref($statushash) eq 'HASH') {
9674: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9675: }
1.275 raeburn 9676: }
9677: }
9678: }
9679: }
1.290 albertel 9680: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9681: if ((defined($cdom)) && (defined($cnum))) {
9682: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9683: if ( defined($csettings{'internal.courseowner'}) ) {
9684: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9685: next if ($owner eq '');
9686: my ($ownername,$ownerdom);
9687: if ($owner =~ /^([^:]+):([^:]+)$/) {
9688: $ownername = $1;
9689: $ownerdom = $2;
9690: } else {
9691: $ownername = $owner;
9692: $ownerdom = $cdom;
9693: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9694: }
9695: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9696: if (defined($userdata) &&
1.609 raeburn 9697: !exists($$userdata{$owner})) {
9698: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9699: if (!grep(/^none$/,@{$seclists{$owner}})) {
9700: push(@{$seclists{$owner}},'none');
9701: }
9702: if (ref($statushash) eq 'HASH') {
9703: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9704: }
1.290 albertel 9705: }
1.279 raeburn 9706: }
9707: }
9708: }
1.419 raeburn 9709: foreach my $user (keys(%seclists)) {
9710: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9711: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9712: }
1.275 raeburn 9713: }
9714: return;
9715: }
9716:
1.288 raeburn 9717: sub get_user_info {
9718: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9719: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9720: &plainname($uname,$udom,'lastname');
1.291 albertel 9721: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9722: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9723: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9724: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9725: return;
9726: }
1.275 raeburn 9727:
1.472 raeburn 9728: ###############################################
9729:
9730: =pod
9731:
9732: =item * &get_user_quota()
9733:
1.1134 raeburn 9734: Retrieves quota assigned for storage of user files.
9735: Default is to report quota for portfolio files.
1.472 raeburn 9736:
9737: Incoming parameters:
9738: 1. user's username
9739: 2. user's domain
1.1134 raeburn 9740: 3. quota name - portfolio, author, or course
1.1136 raeburn 9741: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 9742: 4. crstype - official, unofficial, textbook, placement or community,
9743: if quota name is course
1.472 raeburn 9744:
9745: Returns:
1.1163 raeburn 9746: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9747: 2. (Optional) Type of setting: custom or default
9748: (individually assigned or default for user's
9749: institutional status).
9750: 3. (Optional) - User's institutional status (e.g., faculty, staff
9751: or student - types as defined in localenroll::inst_usertypes
9752: for user's domain, which determines default quota for user.
9753: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9754:
9755: If a value has been stored in the user's environment,
1.536 raeburn 9756: it will return that, otherwise it returns the maximal default
1.1134 raeburn 9757: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9758:
9759: =cut
9760:
9761: ###############################################
9762:
9763:
9764: sub get_user_quota {
1.1136 raeburn 9765: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9766: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9767: if (!defined($udom)) {
9768: $udom = $env{'user.domain'};
9769: }
9770: if (!defined($uname)) {
9771: $uname = $env{'user.name'};
9772: }
9773: if (($udom eq '' || $uname eq '') ||
9774: ($udom eq 'public') && ($uname eq 'public')) {
9775: $quota = 0;
1.536 raeburn 9776: $quotatype = 'default';
9777: $defquota = 0;
1.472 raeburn 9778: } else {
1.536 raeburn 9779: my $inststatus;
1.1134 raeburn 9780: if ($quotaname eq 'course') {
9781: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9782: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9783: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9784: } else {
9785: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9786: $quota = $cenv{'internal.uploadquota'};
9787: }
1.536 raeburn 9788: } else {
1.1134 raeburn 9789: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9790: if ($quotaname eq 'author') {
9791: $quota = $env{'environment.authorquota'};
9792: } else {
9793: $quota = $env{'environment.portfolioquota'};
9794: }
9795: $inststatus = $env{'environment.inststatus'};
9796: } else {
9797: my %userenv =
9798: &Apache::lonnet::get('environment',['portfolioquota',
9799: 'authorquota','inststatus'],$udom,$uname);
9800: my ($tmp) = keys(%userenv);
9801: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9802: if ($quotaname eq 'author') {
9803: $quota = $userenv{'authorquota'};
9804: } else {
9805: $quota = $userenv{'portfolioquota'};
9806: }
9807: $inststatus = $userenv{'inststatus'};
9808: } else {
9809: undef(%userenv);
9810: }
9811: }
9812: }
9813: if ($quota eq '' || wantarray) {
9814: if ($quotaname eq 'course') {
9815: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 9816: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 9817: ($crstype eq 'community') || ($crstype eq 'textbook') ||
9818: ($crstype eq 'placement')) {
1.1136 raeburn 9819: $defquota = $domdefs{$crstype.'quota'};
9820: }
9821: if ($defquota eq '') {
9822: $defquota = 500;
9823: }
1.1134 raeburn 9824: } else {
9825: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9826: }
9827: if ($quota eq '') {
9828: $quota = $defquota;
9829: $quotatype = 'default';
9830: } else {
9831: $quotatype = 'custom';
9832: }
1.472 raeburn 9833: }
9834: }
1.536 raeburn 9835: if (wantarray) {
9836: return ($quota,$quotatype,$settingstatus,$defquota);
9837: } else {
9838: return $quota;
9839: }
1.472 raeburn 9840: }
9841:
9842: ###############################################
9843:
9844: =pod
9845:
9846: =item * &default_quota()
9847:
1.536 raeburn 9848: Retrieves default quota assigned for storage of user portfolio files,
9849: given an (optional) user's institutional status.
1.472 raeburn 9850:
9851: Incoming parameters:
1.1142 raeburn 9852:
1.472 raeburn 9853: 1. domain
1.536 raeburn 9854: 2. (Optional) institutional status(es). This is a : separated list of
9855: status types (e.g., faculty, staff, student etc.)
9856: which apply to the user for whom the default is being retrieved.
9857: If the institutional status string in undefined, the domain
1.1134 raeburn 9858: default quota will be returned.
9859: 3. quota name - portfolio, author, or course
9860: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9861:
9862: Returns:
1.1142 raeburn 9863:
1.1163 raeburn 9864: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9865: 2. (Optional) institutional type which determined the value of the
9866: default quota.
1.472 raeburn 9867:
9868: If a value has been stored in the domain's configuration db,
9869: it will return that, otherwise it returns 20 (for backwards
9870: compatibility with domains which have not set up a configuration
1.1163 raeburn 9871: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9872:
1.536 raeburn 9873: If the user's status includes multiple types (e.g., staff and student),
9874: the largest default quota which applies to the user determines the
9875: default quota returned.
9876:
1.472 raeburn 9877: =cut
9878:
9879: ###############################################
9880:
9881:
9882: sub default_quota {
1.1134 raeburn 9883: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9884: my ($defquota,$settingstatus);
9885: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9886: ['quotas'],$udom);
1.1134 raeburn 9887: my $key = 'defaultquota';
9888: if ($quotaname eq 'author') {
9889: $key = 'authorquota';
9890: }
1.622 raeburn 9891: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9892: if ($inststatus ne '') {
1.765 raeburn 9893: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9894: foreach my $item (@statuses) {
1.1134 raeburn 9895: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9896: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9897: if ($defquota eq '') {
1.1134 raeburn 9898: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9899: $settingstatus = $item;
1.1134 raeburn 9900: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9901: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9902: $settingstatus = $item;
9903: }
9904: }
1.1134 raeburn 9905: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9906: if ($quotahash{'quotas'}{$item} ne '') {
9907: if ($defquota eq '') {
9908: $defquota = $quotahash{'quotas'}{$item};
9909: $settingstatus = $item;
9910: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9911: $defquota = $quotahash{'quotas'}{$item};
9912: $settingstatus = $item;
9913: }
1.536 raeburn 9914: }
9915: }
9916: }
9917: }
9918: if ($defquota eq '') {
1.1134 raeburn 9919: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9920: $defquota = $quotahash{'quotas'}{$key}{'default'};
9921: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9922: $defquota = $quotahash{'quotas'}{'default'};
9923: }
1.536 raeburn 9924: $settingstatus = 'default';
1.1139 raeburn 9925: if ($defquota eq '') {
9926: if ($quotaname eq 'author') {
9927: $defquota = 500;
9928: }
9929: }
1.536 raeburn 9930: }
9931: } else {
9932: $settingstatus = 'default';
1.1134 raeburn 9933: if ($quotaname eq 'author') {
9934: $defquota = 500;
9935: } else {
9936: $defquota = 20;
9937: }
1.536 raeburn 9938: }
9939: if (wantarray) {
9940: return ($defquota,$settingstatus);
1.472 raeburn 9941: } else {
1.536 raeburn 9942: return $defquota;
1.472 raeburn 9943: }
9944: }
9945:
1.1135 raeburn 9946: ###############################################
9947:
9948: =pod
9949:
1.1136 raeburn 9950: =item * &excess_filesize_warning()
1.1135 raeburn 9951:
9952: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 9953: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 9954: space to be exceeded.
1.1136 raeburn 9955:
9956: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 9957: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 9958:
1.1165 raeburn 9959: Inputs: 7
1.1136 raeburn 9960: 1. username or coursenum
1.1135 raeburn 9961: 2. domain
1.1136 raeburn 9962: 3. context ('author' or 'course')
1.1135 raeburn 9963: 4. filename of file for which action is being requested
9964: 5. filesize (kB) of file
9965: 6. action being taken: copy or upload.
1.1237 raeburn 9966: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 9967:
9968: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 9969: otherwise return null.
9970:
9971: =back
1.1135 raeburn 9972:
9973: =cut
9974:
1.1136 raeburn 9975: sub excess_filesize_warning {
1.1165 raeburn 9976: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 9977: my $current_disk_usage = 0;
1.1165 raeburn 9978: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 9979: if ($context eq 'author') {
9980: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9981: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9982: } else {
9983: foreach my $subdir ('docs','supplemental') {
9984: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9985: }
9986: }
1.1135 raeburn 9987: $disk_quota = int($disk_quota * 1000);
9988: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 9989: return '<p class="LC_warning">'.
1.1135 raeburn 9990: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 9991: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9992: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 9993: $disk_quota,$current_disk_usage).
9994: '</p>';
9995: }
9996: return;
9997: }
9998:
9999: ###############################################
10000:
10001:
1.1136 raeburn 10002:
10003:
1.384 raeburn 10004: sub get_secgrprole_info {
10005: my ($cdom,$cnum,$needroles,$type) = @_;
10006: my %sections_count = &get_sections($cdom,$cnum);
10007: my @sections = (sort {$a <=> $b} keys(%sections_count));
10008: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10009: my @groups = sort(keys(%curr_groups));
10010: my $allroles = [];
10011: my $rolehash;
10012: my $accesshash = {
10013: active => 'Currently has access',
10014: future => 'Will have future access',
10015: previous => 'Previously had access',
10016: };
10017: if ($needroles) {
10018: $rolehash = {'all' => 'all'};
1.385 albertel 10019: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10020: if (&Apache::lonnet::error(%user_roles)) {
10021: undef(%user_roles);
10022: }
10023: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10024: my ($role)=split(/\:/,$item,2);
10025: if ($role eq 'cr') { next; }
10026: if ($role =~ /^cr/) {
10027: $$rolehash{$role} = (split('/',$role))[3];
10028: } else {
10029: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10030: }
10031: }
10032: foreach my $key (sort(keys(%{$rolehash}))) {
10033: push(@{$allroles},$key);
10034: }
10035: push (@{$allroles},'st');
10036: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10037: }
10038: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10039: }
10040:
1.555 raeburn 10041: sub user_picker {
1.1279 raeburn 10042: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10043: my $currdom = $dom;
1.1253 raeburn 10044: my @alldoms = &Apache::lonnet::all_domains();
10045: if (@alldoms == 1) {
10046: my %domsrch = &Apache::lonnet::get_dom('configuration',
10047: ['directorysrch'],$alldoms[0]);
10048: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10049: my $showdom = $domdesc;
10050: if ($showdom eq '') {
10051: $showdom = $dom;
10052: }
10053: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10054: if ((!$domsrch{'directorysrch'}{'available'}) &&
10055: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10056: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10057: }
10058: }
10059: }
1.555 raeburn 10060: my %curr_selected = (
10061: srchin => 'dom',
1.580 raeburn 10062: srchby => 'lastname',
1.555 raeburn 10063: );
10064: my $srchterm;
1.625 raeburn 10065: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10066: if ($srch->{'srchby'} ne '') {
10067: $curr_selected{'srchby'} = $srch->{'srchby'};
10068: }
10069: if ($srch->{'srchin'} ne '') {
10070: $curr_selected{'srchin'} = $srch->{'srchin'};
10071: }
10072: if ($srch->{'srchtype'} ne '') {
10073: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10074: }
10075: if ($srch->{'srchdomain'} ne '') {
10076: $currdom = $srch->{'srchdomain'};
10077: }
10078: $srchterm = $srch->{'srchterm'};
10079: }
1.1222 damieng 10080: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10081: 'usr' => 'Search criteria',
1.563 raeburn 10082: 'doma' => 'Domain/institution to search',
1.558 albertel 10083: 'uname' => 'username',
10084: 'lastname' => 'last name',
1.555 raeburn 10085: 'lastfirst' => 'last name, first name',
1.558 albertel 10086: 'crs' => 'in this course',
1.576 raeburn 10087: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10088: 'alc' => 'all LON-CAPA',
1.573 raeburn 10089: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10090: 'exact' => 'is',
10091: 'contains' => 'contains',
1.569 raeburn 10092: 'begins' => 'begins with',
1.1222 damieng 10093: );
10094: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10095: 'youm' => "You must include some text to search for.",
10096: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10097: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10098: 'yomc' => "You must choose a domain when using an institutional directory search.",
10099: 'ymcd' => "You must choose a domain when using a domain search.",
10100: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10101: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10102: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10103: );
1.1222 damieng 10104: &html_escape(\%html_lt);
10105: &js_escape(\%js_lt);
1.1255 raeburn 10106: my $domform;
1.1277 raeburn 10107: my $allow_blank = 1;
1.1255 raeburn 10108: if ($fixeddom) {
1.1277 raeburn 10109: $allow_blank = 0;
10110: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10111: } else {
1.1277 raeburn 10112: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1255 raeburn 10113: }
1.563 raeburn 10114: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10115:
10116: my @srchins = ('crs','dom','alc','instd');
10117:
10118: foreach my $option (@srchins) {
10119: # FIXME 'alc' option unavailable until
10120: # loncreateuser::print_user_query_page()
10121: # has been completed.
10122: next if ($option eq 'alc');
1.880 raeburn 10123: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10124: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 10125: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10126: if ($curr_selected{'srchin'} eq $option) {
10127: $srchinsel .= '
1.1222 damieng 10128: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10129: } else {
10130: $srchinsel .= '
1.1222 damieng 10131: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10132: }
1.555 raeburn 10133: }
1.563 raeburn 10134: $srchinsel .= "\n </select>\n";
1.555 raeburn 10135:
10136: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10137: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10138: if ($curr_selected{'srchby'} eq $option) {
10139: $srchbysel .= '
1.1222 damieng 10140: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10141: } else {
10142: $srchbysel .= '
1.1222 damieng 10143: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10144: }
10145: }
10146: $srchbysel .= "\n </select>\n";
10147:
10148: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10149: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10150: if ($curr_selected{'srchtype'} eq $option) {
10151: $srchtypesel .= '
1.1222 damieng 10152: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10153: } else {
10154: $srchtypesel .= '
1.1222 damieng 10155: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10156: }
10157: }
10158: $srchtypesel .= "\n </select>\n";
10159:
1.558 albertel 10160: my ($newuserscript,$new_user_create);
1.994 raeburn 10161: my $context_dom = $env{'request.role.domain'};
10162: if ($context eq 'requestcrs') {
10163: if ($env{'form.coursedom'} ne '') {
10164: $context_dom = $env{'form.coursedom'};
10165: }
10166: }
1.556 raeburn 10167: if ($forcenewuser) {
1.576 raeburn 10168: if (ref($srch) eq 'HASH') {
1.994 raeburn 10169: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10170: if ($cancreate) {
10171: $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>';
10172: } else {
1.799 bisitz 10173: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10174: my %usertypetext = (
10175: official => 'institutional',
10176: unofficial => 'non-institutional',
10177: );
1.799 bisitz 10178: $new_user_create = '<p class="LC_warning">'
10179: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10180: .' '
10181: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10182: ,'<a href="'.$helplink.'">','</a>')
10183: .'</p><br />';
1.627 raeburn 10184: }
1.576 raeburn 10185: }
10186: }
10187:
1.556 raeburn 10188: $newuserscript = <<"ENDSCRIPT";
10189:
1.570 raeburn 10190: function setSearch(createnew,callingForm) {
1.556 raeburn 10191: if (createnew == 1) {
1.570 raeburn 10192: for (var i=0; i<callingForm.srchby.length; i++) {
10193: if (callingForm.srchby.options[i].value == 'uname') {
10194: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10195: }
10196: }
1.570 raeburn 10197: for (var i=0; i<callingForm.srchin.length; i++) {
10198: if ( callingForm.srchin.options[i].value == 'dom') {
10199: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10200: }
10201: }
1.570 raeburn 10202: for (var i=0; i<callingForm.srchtype.length; i++) {
10203: if (callingForm.srchtype.options[i].value == 'exact') {
10204: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10205: }
10206: }
1.570 raeburn 10207: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10208: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10209: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10210: }
10211: }
10212: }
10213: }
10214: ENDSCRIPT
1.558 albertel 10215:
1.556 raeburn 10216: }
10217:
1.555 raeburn 10218: my $output = <<"END_BLOCK";
1.556 raeburn 10219: <script type="text/javascript">
1.824 bisitz 10220: // <![CDATA[
1.570 raeburn 10221: function validateEntry(callingForm) {
1.558 albertel 10222:
1.556 raeburn 10223: var checkok = 1;
1.558 albertel 10224: var srchin;
1.570 raeburn 10225: for (var i=0; i<callingForm.srchin.length; i++) {
10226: if ( callingForm.srchin[i].checked ) {
10227: srchin = callingForm.srchin[i].value;
1.558 albertel 10228: }
10229: }
10230:
1.570 raeburn 10231: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10232: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10233: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10234: var srchterm = callingForm.srchterm.value;
10235: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10236: var msg = "";
10237:
10238: if (srchterm == "") {
10239: checkok = 0;
1.1222 damieng 10240: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10241: }
10242:
1.569 raeburn 10243: if (srchtype== 'begins') {
10244: if (srchterm.length < 2) {
10245: checkok = 0;
1.1222 damieng 10246: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10247: }
10248: }
10249:
1.556 raeburn 10250: if (srchtype== 'contains') {
10251: if (srchterm.length < 3) {
10252: checkok = 0;
1.1222 damieng 10253: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10254: }
10255: }
10256: if (srchin == 'instd') {
10257: if (srchdomain == '') {
10258: checkok = 0;
1.1222 damieng 10259: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10260: }
10261: }
10262: if (srchin == 'dom') {
10263: if (srchdomain == '') {
10264: checkok = 0;
1.1222 damieng 10265: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10266: }
10267: }
10268: if (srchby == 'lastfirst') {
10269: if (srchterm.indexOf(",") == -1) {
10270: checkok = 0;
1.1222 damieng 10271: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10272: }
10273: if (srchterm.indexOf(",") == srchterm.length -1) {
10274: checkok = 0;
1.1222 damieng 10275: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10276: }
10277: }
10278: if (checkok == 0) {
1.1222 damieng 10279: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10280: return;
10281: }
10282: if (checkok == 1) {
1.570 raeburn 10283: callingForm.submit();
1.556 raeburn 10284: }
10285: }
10286:
10287: $newuserscript
10288:
1.824 bisitz 10289: // ]]>
1.556 raeburn 10290: </script>
1.558 albertel 10291:
10292: $new_user_create
10293:
1.555 raeburn 10294: END_BLOCK
1.558 albertel 10295:
1.876 raeburn 10296: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10297: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10298: $domform.
10299: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10300: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10301: $srchbysel.
10302: $srchtypesel.
10303: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10304: $srchinsel.
10305: &Apache::lonhtmlcommon::row_closure(1).
10306: &Apache::lonhtmlcommon::end_pick_box().
10307: '<br />';
1.1253 raeburn 10308: return ($output,1);
1.555 raeburn 10309: }
10310:
1.612 raeburn 10311: sub user_rule_check {
1.615 raeburn 10312: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10313: my ($response,%inst_response);
1.612 raeburn 10314: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10315: if (keys(%{$usershash}) > 1) {
10316: my (%by_username,%by_id,%userdoms);
10317: my $checkid;
10318: if (ref($checks) eq 'HASH') {
10319: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10320: $checkid = 1;
10321: }
10322: }
10323: foreach my $user (keys(%{$usershash})) {
10324: my ($uname,$udom) = split(/:/,$user);
10325: if ($checkid) {
10326: if (ref($usershash->{$user}) eq 'HASH') {
10327: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10328: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10329: $userdoms{$udom} = 1;
1.1227 raeburn 10330: if (ref($inst_results) eq 'HASH') {
10331: $inst_results->{$uname.':'.$udom} = {};
10332: }
1.1226 raeburn 10333: }
10334: }
10335: } else {
10336: $by_username{$udom}{$uname} = 1;
10337: $userdoms{$udom} = 1;
1.1227 raeburn 10338: if (ref($inst_results) eq 'HASH') {
10339: $inst_results->{$uname.':'.$udom} = {};
10340: }
1.1226 raeburn 10341: }
10342: }
10343: foreach my $udom (keys(%userdoms)) {
10344: if (!$got_rules->{$udom}) {
10345: my %domconfig = &Apache::lonnet::get_dom('configuration',
10346: ['usercreation'],$udom);
10347: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10348: foreach my $item ('username','id') {
10349: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10350: $$curr_rules{$udom}{$item} =
10351: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10352: }
10353: }
10354: }
10355: $got_rules->{$udom} = 1;
10356: }
1.612 raeburn 10357: }
1.1226 raeburn 10358: if ($checkid) {
10359: foreach my $udom (keys(%by_id)) {
10360: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10361: if ($outcome eq 'ok') {
1.1227 raeburn 10362: foreach my $id (keys(%{$by_id{$udom}})) {
10363: my $uname = $by_id{$udom}{$id};
10364: $inst_response{$uname.':'.$udom} = $outcome;
10365: }
1.1226 raeburn 10366: if (ref($results) eq 'HASH') {
10367: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10368: if (exists($inst_response{$uname.':'.$udom})) {
10369: $inst_response{$uname.':'.$udom} = $outcome;
10370: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10371: }
1.1226 raeburn 10372: }
10373: }
10374: }
1.612 raeburn 10375: }
1.615 raeburn 10376: } else {
1.1226 raeburn 10377: foreach my $udom (keys(%by_username)) {
10378: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10379: if ($outcome eq 'ok') {
1.1227 raeburn 10380: foreach my $uname (keys(%{$by_username{$udom}})) {
10381: $inst_response{$uname.':'.$udom} = $outcome;
10382: }
1.1226 raeburn 10383: if (ref($results) eq 'HASH') {
10384: foreach my $uname (keys(%{$results})) {
10385: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10386: }
10387: }
10388: }
10389: }
1.612 raeburn 10390: }
1.1226 raeburn 10391: } elsif (keys(%{$usershash}) == 1) {
10392: my $user = (keys(%{$usershash}))[0];
10393: my ($uname,$udom) = split(/:/,$user);
10394: if (($udom ne '') && ($uname ne '')) {
10395: if (ref($usershash->{$user}) eq 'HASH') {
10396: if (ref($checks) eq 'HASH') {
10397: if (defined($checks->{'username'})) {
10398: ($inst_response{$user},%{$inst_results->{$user}}) =
10399: &Apache::lonnet::get_instuser($udom,$uname);
10400: } elsif (defined($checks->{'id'})) {
10401: if ($usershash->{$user}->{'id'} ne '') {
10402: ($inst_response{$user},%{$inst_results->{$user}}) =
10403: &Apache::lonnet::get_instuser($udom,undef,
10404: $usershash->{$user}->{'id'});
10405: } else {
10406: ($inst_response{$user},%{$inst_results->{$user}}) =
10407: &Apache::lonnet::get_instuser($udom,$uname);
10408: }
1.585 raeburn 10409: }
1.1226 raeburn 10410: } else {
10411: ($inst_response{$user},%{$inst_results->{$user}}) =
10412: &Apache::lonnet::get_instuser($udom,$uname);
10413: return;
10414: }
10415: if (!$got_rules->{$udom}) {
10416: my %domconfig = &Apache::lonnet::get_dom('configuration',
10417: ['usercreation'],$udom);
10418: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10419: foreach my $item ('username','id') {
10420: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10421: $$curr_rules{$udom}{$item} =
10422: $domconfig{'usercreation'}{$item.'_rule'};
10423: }
10424: }
10425: }
10426: $got_rules->{$udom} = 1;
1.585 raeburn 10427: }
10428: }
1.1226 raeburn 10429: } else {
10430: return;
10431: }
10432: } else {
10433: return;
10434: }
10435: foreach my $user (keys(%{$usershash})) {
10436: my ($uname,$udom) = split(/:/,$user);
10437: next if (($udom eq '') || ($uname eq ''));
10438: my $id;
1.1227 raeburn 10439: if (ref($inst_results) eq 'HASH') {
10440: if (ref($inst_results->{$user}) eq 'HASH') {
10441: $id = $inst_results->{$user}->{'id'};
10442: }
10443: }
10444: if ($id eq '') {
10445: if (ref($usershash->{$user})) {
10446: $id = $usershash->{$user}->{'id'};
10447: }
1.585 raeburn 10448: }
1.612 raeburn 10449: foreach my $item (keys(%{$checks})) {
10450: if (ref($$curr_rules{$udom}) eq 'HASH') {
10451: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10452: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10453: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10454: $$curr_rules{$udom}{$item});
1.612 raeburn 10455: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10456: if ($rule_check{$rule}) {
10457: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10458: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10459: if (ref($inst_results) eq 'HASH') {
10460: if (ref($inst_results->{$user}) eq 'HASH') {
10461: if (keys(%{$inst_results->{$user}}) == 0) {
10462: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10463: } elsif ($item eq 'id') {
10464: if ($inst_results->{$user}->{'id'} eq '') {
10465: $$alerts{$item}{$udom}{$uname} = 1;
10466: }
1.615 raeburn 10467: }
1.612 raeburn 10468: }
10469: }
1.615 raeburn 10470: }
10471: last;
1.585 raeburn 10472: }
10473: }
10474: }
10475: }
10476: }
10477: }
10478: }
10479: }
1.612 raeburn 10480: return;
10481: }
10482:
10483: sub user_rule_formats {
10484: my ($domain,$domdesc,$curr_rules,$check) = @_;
10485: my %text = (
10486: 'username' => 'Usernames',
10487: 'id' => 'IDs',
10488: );
10489: my $output;
10490: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10491: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10492: if (@{$ruleorder} > 0) {
1.1102 raeburn 10493: $output = '<br />'.
10494: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10495: '<span class="LC_cusr_emph">','</span>',$domdesc).
10496: ' <ul>';
1.612 raeburn 10497: foreach my $rule (@{$ruleorder}) {
10498: if (ref($curr_rules) eq 'ARRAY') {
10499: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10500: if (ref($rules->{$rule}) eq 'HASH') {
10501: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10502: $rules->{$rule}{'desc'}.'</li>';
10503: }
10504: }
10505: }
10506: }
10507: $output .= '</ul>';
10508: }
10509: }
10510: return $output;
10511: }
10512:
10513: sub instrule_disallow_msg {
1.615 raeburn 10514: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10515: my $response;
10516: my %text = (
10517: item => 'username',
10518: items => 'usernames',
10519: match => 'matches',
10520: do => 'does',
10521: action => 'a username',
10522: one => 'one',
10523: );
10524: if ($count > 1) {
10525: $text{'item'} = 'usernames';
10526: $text{'match'} ='match';
10527: $text{'do'} = 'do';
10528: $text{'action'} = 'usernames',
10529: $text{'one'} = 'ones';
10530: }
10531: if ($checkitem eq 'id') {
10532: $text{'items'} = 'IDs';
10533: $text{'item'} = 'ID';
10534: $text{'action'} = 'an ID';
1.615 raeburn 10535: if ($count > 1) {
10536: $text{'item'} = 'IDs';
10537: $text{'action'} = 'IDs';
10538: }
1.612 raeburn 10539: }
1.674 bisitz 10540: $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 10541: if ($mode eq 'upload') {
10542: if ($checkitem eq 'username') {
10543: $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'}.");
10544: } elsif ($checkitem eq 'id') {
1.674 bisitz 10545: $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 10546: }
1.669 raeburn 10547: } elsif ($mode eq 'selfcreate') {
10548: if ($checkitem eq 'id') {
10549: $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.");
10550: }
1.615 raeburn 10551: } else {
10552: if ($checkitem eq 'username') {
10553: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10554: } elsif ($checkitem eq 'id') {
10555: $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.");
10556: }
1.612 raeburn 10557: }
10558: return $response;
1.585 raeburn 10559: }
10560:
1.624 raeburn 10561: sub personal_data_fieldtitles {
10562: my %fieldtitles = &Apache::lonlocal::texthash (
10563: id => 'Student/Employee ID',
10564: permanentemail => 'E-mail address',
10565: lastname => 'Last Name',
10566: firstname => 'First Name',
10567: middlename => 'Middle Name',
10568: generation => 'Generation',
10569: gen => 'Generation',
1.765 raeburn 10570: inststatus => 'Affiliation',
1.624 raeburn 10571: );
10572: return %fieldtitles;
10573: }
10574:
1.642 raeburn 10575: sub sorted_inst_types {
10576: my ($dom) = @_;
1.1185 raeburn 10577: my ($usertypes,$order);
10578: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10579: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10580: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10581: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10582: } else {
10583: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10584: }
1.642 raeburn 10585: my $othertitle = &mt('All users');
10586: if ($env{'request.course.id'}) {
1.668 raeburn 10587: $othertitle = &mt('Any users');
1.642 raeburn 10588: }
10589: my @types;
10590: if (ref($order) eq 'ARRAY') {
10591: @types = @{$order};
10592: }
10593: if (@types == 0) {
10594: if (ref($usertypes) eq 'HASH') {
10595: @types = sort(keys(%{$usertypes}));
10596: }
10597: }
10598: if (keys(%{$usertypes}) > 0) {
10599: $othertitle = &mt('Other users');
10600: }
10601: return ($othertitle,$usertypes,\@types);
10602: }
10603:
1.645 raeburn 10604: sub get_institutional_codes {
10605: my ($settings,$allcourses,$LC_code) = @_;
10606: # Get complete list of course sections to update
10607: my @currsections = ();
10608: my @currxlists = ();
10609: my $coursecode = $$settings{'internal.coursecode'};
10610:
10611: if ($$settings{'internal.sectionnums'} ne '') {
10612: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10613: }
10614:
10615: if ($$settings{'internal.crosslistings'} ne '') {
10616: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10617: }
10618:
10619: if (@currxlists > 0) {
10620: foreach (@currxlists) {
10621: if (m/^([^:]+):(\w*)$/) {
10622: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 10623: push(@{$allcourses},$1);
1.645 raeburn 10624: $$LC_code{$1} = $2;
10625: }
10626: }
10627: }
10628: }
10629:
10630: if (@currsections > 0) {
10631: foreach (@currsections) {
10632: if (m/^(\w+):(\w*)$/) {
10633: my $sec = $coursecode.$1;
10634: my $lc_sec = $2;
10635: unless (grep/^$sec$/,@{$allcourses}) {
1.1263 raeburn 10636: push(@{$allcourses},$sec);
1.645 raeburn 10637: $$LC_code{$sec} = $lc_sec;
10638: }
10639: }
10640: }
10641: }
10642: return;
10643: }
10644:
1.971 raeburn 10645: sub get_standard_codeitems {
10646: return ('Year','Semester','Department','Number','Section');
10647: }
10648:
1.112 bowersj2 10649: =pod
10650:
1.780 raeburn 10651: =head1 Slot Helpers
10652:
10653: =over 4
10654:
10655: =item * sorted_slots()
10656:
1.1040 raeburn 10657: Sorts an array of slot names in order of an optional sort key,
10658: default sort is by slot start time (earliest first).
1.780 raeburn 10659:
10660: Inputs:
10661:
10662: =over 4
10663:
10664: slotsarr - Reference to array of unsorted slot names.
10665:
10666: slots - Reference to hash of hash, where outer hash keys are slot names.
10667:
1.1040 raeburn 10668: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10669:
1.549 albertel 10670: =back
10671:
1.780 raeburn 10672: Returns:
10673:
10674: =over 4
10675:
1.1040 raeburn 10676: sorted - An array of slot names sorted by a specified sort key
10677: (default sort key is start time of the slot).
1.780 raeburn 10678:
10679: =back
10680:
10681: =cut
10682:
10683:
10684: sub sorted_slots {
1.1040 raeburn 10685: my ($slotsarr,$slots,$sortkey) = @_;
10686: if ($sortkey eq '') {
10687: $sortkey = 'starttime';
10688: }
1.780 raeburn 10689: my @sorted;
10690: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10691: @sorted =
10692: sort {
10693: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10694: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10695: }
10696: if (ref($slots->{$a})) { return -1;}
10697: if (ref($slots->{$b})) { return 1;}
10698: return 0;
10699: } @{$slotsarr};
10700: }
10701: return @sorted;
10702: }
10703:
1.1040 raeburn 10704: =pod
10705:
10706: =item * get_future_slots()
10707:
10708: Inputs:
10709:
10710: =over 4
10711:
10712: cnum - course number
10713:
10714: cdom - course domain
10715:
10716: now - current UNIX time
10717:
10718: symb - optional symb
10719:
10720: =back
10721:
10722: Returns:
10723:
10724: =over 4
10725:
10726: sorted_reservable - ref to array of student_schedulable slots currently
10727: reservable, ordered by end date of reservation period.
10728:
10729: reservable_now - ref to hash of student_schedulable slots currently
10730: reservable.
10731:
10732: Keys in inner hash are:
10733: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10734: (b) endreserve: end date of reservation period.
10735: (c) uniqueperiod: start,end dates when slot is to be uniquely
10736: selected.
1.1040 raeburn 10737:
10738: sorted_future - ref to array of student_schedulable slots reservable in
10739: the future, ordered by start date of reservation period.
10740:
10741: future_reservable - ref to hash of student_schedulable slots reservable
10742: in the future.
10743:
10744: Keys in inner hash are:
10745: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10746: (b) startreserve: start date of reservation period.
10747: (c) uniqueperiod: start,end dates when slot is to be uniquely
10748: selected.
1.1040 raeburn 10749:
10750: =back
10751:
10752: =cut
10753:
10754: sub get_future_slots {
10755: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 10756: my $map;
10757: if ($symb) {
10758: ($map) = &Apache::lonnet::decode_symb($symb);
10759: }
1.1040 raeburn 10760: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10761: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10762: foreach my $slot (keys(%slots)) {
10763: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10764: if ($symb) {
1.1229 raeburn 10765: if ($slots{$slot}->{'symb'} ne '') {
10766: my $canuse;
10767: my %oksymbs;
10768: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
10769: map { $oksymbs{$_} = 1; } @slotsymbs;
10770: if ($oksymbs{$symb}) {
10771: $canuse = 1;
10772: } else {
10773: foreach my $item (@slotsymbs) {
10774: if ($item =~ /\.(page|sequence)$/) {
10775: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
10776: if (($map ne '') && ($map eq $sloturl)) {
10777: $canuse = 1;
10778: last;
10779: }
10780: }
10781: }
10782: }
10783: next unless ($canuse);
10784: }
1.1040 raeburn 10785: }
10786: if (($slots{$slot}->{'starttime'} > $now) &&
10787: ($slots{$slot}->{'endtime'} > $now)) {
10788: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10789: my $userallowed = 0;
10790: if ($slots{$slot}->{'allowedsections'}) {
10791: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10792: if (!defined($env{'request.role.sec'})
10793: && grep(/^No section assigned$/,@allowed_sec)) {
10794: $userallowed=1;
10795: } else {
10796: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10797: $userallowed=1;
10798: }
10799: }
10800: unless ($userallowed) {
10801: if (defined($env{'request.course.groups'})) {
10802: my @groups = split(/:/,$env{'request.course.groups'});
10803: foreach my $group (@groups) {
10804: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10805: $userallowed=1;
10806: last;
10807: }
10808: }
10809: }
10810: }
10811: }
10812: if ($slots{$slot}->{'allowedusers'}) {
10813: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10814: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10815: if (grep(/^\Q$user\E$/,@allowed_users)) {
10816: $userallowed = 1;
10817: }
10818: }
10819: next unless($userallowed);
10820: }
10821: my $startreserve = $slots{$slot}->{'startreserve'};
10822: my $endreserve = $slots{$slot}->{'endreserve'};
10823: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 10824: my $uniqueperiod;
10825: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10826: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10827: }
1.1040 raeburn 10828: if (($startreserve < $now) &&
10829: (!$endreserve || $endreserve > $now)) {
10830: my $lastres = $endreserve;
10831: if (!$lastres) {
10832: $lastres = $slots{$slot}->{'starttime'};
10833: }
10834: $reservable_now{$slot} = {
10835: symb => $symb,
1.1250 raeburn 10836: endreserve => $lastres,
10837: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10838: };
10839: } elsif (($startreserve > $now) &&
10840: (!$endreserve || $endreserve > $startreserve)) {
10841: $future_reservable{$slot} = {
10842: symb => $symb,
1.1250 raeburn 10843: startreserve => $startreserve,
10844: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10845: };
10846: }
10847: }
10848: }
10849: my @unsorted_reservable = keys(%reservable_now);
10850: if (@unsorted_reservable > 0) {
10851: @sorted_reservable =
10852: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10853: }
10854: my @unsorted_future = keys(%future_reservable);
10855: if (@unsorted_future > 0) {
10856: @sorted_future =
10857: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10858: }
10859: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10860: }
1.780 raeburn 10861:
10862: =pod
10863:
1.1057 foxr 10864: =back
10865:
1.549 albertel 10866: =head1 HTTP Helpers
10867:
10868: =over 4
10869:
1.648 raeburn 10870: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10871:
1.258 albertel 10872: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10873: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10874: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10875:
10876: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10877: $possible_names is an ref to an array of form element names. As an example:
10878: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10879: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10880:
10881: =cut
1.1 albertel 10882:
1.6 albertel 10883: sub get_unprocessed_cgi {
1.25 albertel 10884: my ($query,$possible_names)= @_;
1.26 matthew 10885: # $Apache::lonxml::debug=1;
1.356 albertel 10886: foreach my $pair (split(/&/,$query)) {
10887: my ($name, $value) = split(/=/,$pair);
1.369 www 10888: $name = &unescape($name);
1.25 albertel 10889: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10890: $value =~ tr/+/ /;
10891: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10892: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10893: }
1.16 harris41 10894: }
1.6 albertel 10895: }
10896:
1.112 bowersj2 10897: =pod
10898:
1.648 raeburn 10899: =item * &cacheheader()
1.112 bowersj2 10900:
10901: returns cache-controlling header code
10902:
10903: =cut
10904:
1.7 albertel 10905: sub cacheheader {
1.258 albertel 10906: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10907: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10908: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10909: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10910: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10911: return $output;
1.7 albertel 10912: }
10913:
1.112 bowersj2 10914: =pod
10915:
1.648 raeburn 10916: =item * &no_cache($r)
1.112 bowersj2 10917:
10918: specifies header code to not have cache
10919:
10920: =cut
10921:
1.9 albertel 10922: sub no_cache {
1.216 albertel 10923: my ($r) = @_;
10924: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10925: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10926: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10927: $r->no_cache(1);
10928: $r->header_out("Expires" => $date);
10929: $r->header_out("Pragma" => "no-cache");
1.123 www 10930: }
10931:
10932: sub content_type {
1.181 albertel 10933: my ($r,$type,$charset) = @_;
1.299 foxr 10934: if ($r) {
10935: # Note that printout.pl calls this with undef for $r.
10936: &no_cache($r);
10937: }
1.258 albertel 10938: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10939: unless ($charset) {
10940: $charset=&Apache::lonlocal::current_encoding;
10941: }
10942: if ($charset) { $type.='; charset='.$charset; }
10943: if ($r) {
10944: $r->content_type($type);
10945: } else {
10946: print("Content-type: $type\n\n");
10947: }
1.9 albertel 10948: }
1.25 albertel 10949:
1.112 bowersj2 10950: =pod
10951:
1.648 raeburn 10952: =item * &add_to_env($name,$value)
1.112 bowersj2 10953:
1.258 albertel 10954: adds $name to the %env hash with value
1.112 bowersj2 10955: $value, if $name already exists, the entry is converted to an array
10956: reference and $value is added to the array.
10957:
10958: =cut
10959:
1.25 albertel 10960: sub add_to_env {
10961: my ($name,$value)=@_;
1.258 albertel 10962: if (defined($env{$name})) {
10963: if (ref($env{$name})) {
1.25 albertel 10964: #already have multiple values
1.258 albertel 10965: push(@{ $env{$name} },$value);
1.25 albertel 10966: } else {
10967: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10968: my $first=$env{$name};
10969: undef($env{$name});
10970: push(@{ $env{$name} },$first,$value);
1.25 albertel 10971: }
10972: } else {
1.258 albertel 10973: $env{$name}=$value;
1.25 albertel 10974: }
1.31 albertel 10975: }
1.149 albertel 10976:
10977: =pod
10978:
1.648 raeburn 10979: =item * &get_env_multiple($name)
1.149 albertel 10980:
1.258 albertel 10981: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10982: values may be defined and end up as an array ref.
10983:
10984: returns an array of values
10985:
10986: =cut
10987:
10988: sub get_env_multiple {
10989: my ($name) = @_;
10990: my @values;
1.258 albertel 10991: if (defined($env{$name})) {
1.149 albertel 10992: # exists is it an array
1.258 albertel 10993: if (ref($env{$name})) {
10994: @values=@{ $env{$name} };
1.149 albertel 10995: } else {
1.258 albertel 10996: $values[0]=$env{$name};
1.149 albertel 10997: }
10998: }
10999: return(@values);
11000: }
11001:
1.1249 damieng 11002: # Looks at given dependencies, and returns something depending on the context.
11003: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11004: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11005: # For all other contexts, returns ($output, $counter, $numpathchg).
11006: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11007: # $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.
11008: # $numpathchg: integer with the number of cleaned up dependency paths.
11009: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11010: # \%mapping: hash reference clean path -> original path for all dependencies.
11011: # @param {string} actionurl - The path to the handler, indicative of the context.
11012: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11013: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11014: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11015: # @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)
11016: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11017: sub ask_for_embedded_content {
1.1249 damieng 11018: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11019: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11020: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11021: %currsubfile,%unused,$rem);
1.1071 raeburn 11022: my $counter = 0;
11023: my $numnew = 0;
1.987 raeburn 11024: my $numremref = 0;
11025: my $numinvalid = 0;
11026: my $numpathchg = 0;
11027: my $numexisting = 0;
1.1071 raeburn 11028: my $numunused = 0;
11029: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11030: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11031: my $heading = &mt('Upload embedded files');
11032: my $buttontext = &mt('Upload');
11033:
1.1249 damieng 11034: # fills these variables based on the context:
11035: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11036: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11037: if ($env{'request.course.id'}) {
1.1123 raeburn 11038: if ($actionurl eq '/adm/dependencies') {
11039: $navmap = Apache::lonnavmaps::navmap->new();
11040: }
11041: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11042: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11043: }
1.1123 raeburn 11044: if (($actionurl eq '/adm/portfolio') ||
11045: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11046: my $current_path='/';
11047: if ($env{'form.currentpath'}) {
11048: $current_path = $env{'form.currentpath'};
11049: }
11050: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11051: $udom = $cdom;
11052: $uname = $cnum;
1.984 raeburn 11053: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11054: } else {
11055: $udom = $env{'user.domain'};
11056: $uname = $env{'user.name'};
11057: $url = '/userfiles/portfolio';
11058: }
1.987 raeburn 11059: $toplevel = $url.'/';
1.984 raeburn 11060: $url .= $current_path;
11061: $getpropath = 1;
1.987 raeburn 11062: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11063: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11064: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11065: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11066: $toplevel = $url;
1.984 raeburn 11067: if ($rest ne '') {
1.987 raeburn 11068: $url .= $rest;
11069: }
11070: } elsif ($actionurl eq '/adm/coursedocs') {
11071: if (ref($args) eq 'HASH') {
1.1071 raeburn 11072: $url = $args->{'docs_url'};
11073: $toplevel = $url;
1.1084 raeburn 11074: if ($args->{'context'} eq 'paste') {
11075: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11076: ($path) =
11077: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11078: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11079: $fileloc =~ s{^/}{};
11080: }
1.1071 raeburn 11081: }
1.1084 raeburn 11082: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11083: if ($env{'request.course.id'} ne '') {
11084: if (ref($args) eq 'HASH') {
11085: $url = $args->{'docs_url'};
11086: $title = $args->{'docs_title'};
1.1126 raeburn 11087: $toplevel = $url;
11088: unless ($toplevel =~ m{^/}) {
11089: $toplevel = "/$url";
11090: }
1.1085 raeburn 11091: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11092: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11093: $path = $1;
11094: } else {
11095: ($path) =
11096: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11097: }
1.1195 raeburn 11098: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11099: $fileloc = $toplevel;
11100: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11101: my ($udom,$uname,$fname) =
11102: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11103: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11104: } else {
11105: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11106: }
1.1071 raeburn 11107: $fileloc =~ s{^/}{};
11108: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11109: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11110: }
1.987 raeburn 11111: }
1.1123 raeburn 11112: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11113: $udom = $cdom;
11114: $uname = $cnum;
11115: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11116: $toplevel = $url;
11117: $path = $url;
11118: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11119: $fileloc =~ s{^/}{};
1.987 raeburn 11120: }
1.1249 damieng 11121:
11122: # parses the dependency paths to get some info
11123: # fills $newfiles, $mapping, $subdependencies, $dependencies
11124: # $newfiles: hash URL -> 1 for new files or external URLs
11125: # (will be completed later)
11126: # $mapping:
11127: # for external URLs: external URL -> external URL
11128: # for relative paths: clean path -> original path
11129: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11130: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11131: foreach my $file (keys(%{$allfiles})) {
11132: my $embed_file;
11133: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11134: $embed_file = $1;
11135: } else {
11136: $embed_file = $file;
11137: }
1.1158 raeburn 11138: my ($absolutepath,$cleaned_file);
11139: if ($embed_file =~ m{^\w+://}) {
11140: $cleaned_file = $embed_file;
1.1147 raeburn 11141: $newfiles{$cleaned_file} = 1;
11142: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11143: } else {
1.1158 raeburn 11144: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11145: if ($embed_file =~ m{^/}) {
11146: $absolutepath = $embed_file;
11147: }
1.1147 raeburn 11148: if ($cleaned_file =~ m{/}) {
11149: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11150: $path = &check_for_traversal($path,$url,$toplevel);
11151: my $item = $fname;
11152: if ($path ne '') {
11153: $item = $path.'/'.$fname;
11154: $subdependencies{$path}{$fname} = 1;
11155: } else {
11156: $dependencies{$item} = 1;
11157: }
11158: if ($absolutepath) {
11159: $mapping{$item} = $absolutepath;
11160: } else {
11161: $mapping{$item} = $embed_file;
11162: }
11163: } else {
11164: $dependencies{$embed_file} = 1;
11165: if ($absolutepath) {
1.1147 raeburn 11166: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11167: } else {
1.1147 raeburn 11168: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11169: }
11170: }
1.984 raeburn 11171: }
11172: }
1.1249 damieng 11173:
11174: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11175: # and lists
11176: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11177: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11178: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11179: # the path had to be cleaned up
11180: # $existing: hash clean path -> 1 if the file exists
11181: # $numexisting: number of keys in $existing
11182: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11183: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11184: # dependency subdirectories that are
11185: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11186: my $dirptr = 16384;
1.984 raeburn 11187: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11188: $currsubfile{$path} = {};
1.1123 raeburn 11189: if (($actionurl eq '/adm/portfolio') ||
11190: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11191: my ($sublistref,$listerror) =
11192: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11193: if (ref($sublistref) eq 'ARRAY') {
11194: foreach my $line (@{$sublistref}) {
11195: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11196: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11197: }
1.984 raeburn 11198: }
1.987 raeburn 11199: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11200: if (opendir(my $dir,$url.'/'.$path)) {
11201: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11202: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11203: }
1.1084 raeburn 11204: } elsif (($actionurl eq '/adm/dependencies') ||
11205: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11206: ($args->{'context'} eq 'paste')) ||
11207: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11208: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11209: my $dir;
11210: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11211: $dir = $fileloc;
11212: } else {
11213: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11214: }
1.1071 raeburn 11215: if ($dir ne '') {
11216: my ($sublistref,$listerror) =
11217: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11218: if (ref($sublistref) eq 'ARRAY') {
11219: foreach my $line (@{$sublistref}) {
11220: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11221: undef,$mtime)=split(/\&/,$line,12);
11222: unless (($testdir&$dirptr) ||
11223: ($file_name =~ /^\.\.?$/)) {
11224: $currsubfile{$path}{$file_name} = [$size,$mtime];
11225: }
11226: }
11227: }
11228: }
1.984 raeburn 11229: }
11230: }
11231: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11232: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11233: my $item = $path.'/'.$file;
11234: unless ($mapping{$item} eq $item) {
11235: $pathchanges{$item} = 1;
11236: }
11237: $existing{$item} = 1;
11238: $numexisting ++;
11239: } else {
11240: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11241: }
11242: }
1.1071 raeburn 11243: if ($actionurl eq '/adm/dependencies') {
11244: foreach my $path (keys(%currsubfile)) {
11245: if (ref($currsubfile{$path}) eq 'HASH') {
11246: foreach my $file (keys(%{$currsubfile{$path}})) {
11247: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11248: next if (($rem ne '') &&
11249: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11250: (ref($navmap) &&
11251: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11252: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11253: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11254: $unused{$path.'/'.$file} = 1;
11255: }
11256: }
11257: }
11258: }
11259: }
1.984 raeburn 11260: }
1.1249 damieng 11261:
11262: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11263: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11264: my %currfile;
1.1123 raeburn 11265: if (($actionurl eq '/adm/portfolio') ||
11266: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11267: my ($dirlistref,$listerror) =
11268: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11269: if (ref($dirlistref) eq 'ARRAY') {
11270: foreach my $line (@{$dirlistref}) {
11271: my ($file_name,$rest) = split(/\&/,$line,2);
11272: $currfile{$file_name} = 1;
11273: }
1.984 raeburn 11274: }
1.987 raeburn 11275: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11276: if (opendir(my $dir,$url)) {
1.987 raeburn 11277: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11278: map {$currfile{$_} = 1;} @dir_list;
11279: }
1.1084 raeburn 11280: } elsif (($actionurl eq '/adm/dependencies') ||
11281: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11282: ($args->{'context'} eq 'paste')) ||
11283: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11284: if ($env{'request.course.id'} ne '') {
11285: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11286: if ($dir ne '') {
11287: my ($dirlistref,$listerror) =
11288: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11289: if (ref($dirlistref) eq 'ARRAY') {
11290: foreach my $line (@{$dirlistref}) {
11291: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11292: $size,undef,$mtime)=split(/\&/,$line,12);
11293: unless (($testdir&$dirptr) ||
11294: ($file_name =~ /^\.\.?$/)) {
11295: $currfile{$file_name} = [$size,$mtime];
11296: }
11297: }
11298: }
11299: }
11300: }
1.984 raeburn 11301: }
1.1249 damieng 11302: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11303: # are not in subdirectories, using $currfile
1.984 raeburn 11304: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11305: if (exists($currfile{$file})) {
1.987 raeburn 11306: unless ($mapping{$file} eq $file) {
11307: $pathchanges{$file} = 1;
11308: }
11309: $existing{$file} = 1;
11310: $numexisting ++;
11311: } else {
1.984 raeburn 11312: $newfiles{$file} = 1;
11313: }
11314: }
1.1071 raeburn 11315: foreach my $file (keys(%currfile)) {
11316: unless (($file eq $filename) ||
11317: ($file eq $filename.'.bak') ||
11318: ($dependencies{$file})) {
1.1085 raeburn 11319: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11320: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11321: next if (($rem ne '') &&
11322: (($env{"httpref.$rem".$file} ne '') ||
11323: (ref($navmap) &&
11324: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11325: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11326: ($navmap->getResourceByUrl($rem.$1)))))));
11327: }
1.1085 raeburn 11328: }
1.1071 raeburn 11329: $unused{$file} = 1;
11330: }
11331: }
1.1249 damieng 11332:
11333: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11334: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11335: ($args->{'context'} eq 'paste')) {
11336: $counter = scalar(keys(%existing));
11337: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11338: return ($output,$counter,$numpathchg,\%existing);
11339: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11340: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11341: $counter = scalar(keys(%existing));
11342: $numpathchg = scalar(keys(%pathchanges));
11343: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11344: }
1.1249 damieng 11345:
11346: # returns HTML otherwise, with dependency results and to ask for more uploads
11347:
11348: # $upload_output: missing dependencies (with upload form)
11349: # $modify_output: uploaded dependencies (in use)
11350: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11351: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11352: if ($actionurl eq '/adm/dependencies') {
11353: next if ($embed_file =~ m{^\w+://});
11354: }
1.660 raeburn 11355: $upload_output .= &start_data_table_row().
1.1123 raeburn 11356: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11357: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11358: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11359: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11360: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11361: }
1.1123 raeburn 11362: $upload_output .= '</td>';
1.1071 raeburn 11363: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11364: $upload_output.='<td align="right">'.
11365: '<span class="LC_info LC_fontsize_medium">'.
11366: &mt("URL points to web address").'</span>';
1.987 raeburn 11367: $numremref++;
1.660 raeburn 11368: } elsif ($args->{'error_on_invalid_names'}
11369: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11370: $upload_output.='<td align="right"><span class="LC_warning">'.
11371: &mt('Invalid characters').'</span>';
1.987 raeburn 11372: $numinvalid++;
1.660 raeburn 11373: } else {
1.1123 raeburn 11374: $upload_output .= '<td>'.
11375: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11376: $embed_file,\%mapping,
1.1071 raeburn 11377: $allfiles,$codebase,'upload');
11378: $counter ++;
11379: $numnew ++;
1.987 raeburn 11380: }
11381: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11382: }
11383: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11384: if ($actionurl eq '/adm/dependencies') {
11385: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11386: $modify_output .= &start_data_table_row().
11387: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11388: '<img src="'.&icon($embed_file).'" border="0" />'.
11389: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11390: '<td>'.$size.'</td>'.
11391: '<td>'.$mtime.'</td>'.
11392: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11393: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11394: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11395: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11396: &embedded_file_element('upload_embedded',$counter,
11397: $embed_file,\%mapping,
11398: $allfiles,$codebase,'modify').
11399: '</div></td>'.
11400: &end_data_table_row()."\n";
11401: $counter ++;
11402: } else {
11403: $upload_output .= &start_data_table_row().
1.1123 raeburn 11404: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11405: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11406: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11407: &Apache::loncommon::end_data_table_row()."\n";
11408: }
11409: }
11410: my $delidx = $counter;
11411: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11412: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11413: $delete_output .= &start_data_table_row().
11414: '<td><img src="'.&icon($oldfile).'" />'.
11415: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11416: '<td>'.$size.'</td>'.
11417: '<td>'.$mtime.'</td>'.
11418: '<td><label><input type="checkbox" name="del_upload_dep" '.
11419: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11420: &embedded_file_element('upload_embedded',$delidx,
11421: $oldfile,\%mapping,$allfiles,
11422: $codebase,'delete').'</td>'.
11423: &end_data_table_row()."\n";
11424: $numunused ++;
11425: $delidx ++;
1.987 raeburn 11426: }
11427: if ($upload_output) {
11428: $upload_output = &start_data_table().
11429: $upload_output.
11430: &end_data_table()."\n";
11431: }
1.1071 raeburn 11432: if ($modify_output) {
11433: $modify_output = &start_data_table().
11434: &start_data_table_header_row().
11435: '<th>'.&mt('File').'</th>'.
11436: '<th>'.&mt('Size (KB)').'</th>'.
11437: '<th>'.&mt('Modified').'</th>'.
11438: '<th>'.&mt('Upload replacement?').'</th>'.
11439: &end_data_table_header_row().
11440: $modify_output.
11441: &end_data_table()."\n";
11442: }
11443: if ($delete_output) {
11444: $delete_output = &start_data_table().
11445: &start_data_table_header_row().
11446: '<th>'.&mt('File').'</th>'.
11447: '<th>'.&mt('Size (KB)').'</th>'.
11448: '<th>'.&mt('Modified').'</th>'.
11449: '<th>'.&mt('Delete?').'</th>'.
11450: &end_data_table_header_row().
11451: $delete_output.
11452: &end_data_table()."\n";
11453: }
1.987 raeburn 11454: my $applies = 0;
11455: if ($numremref) {
11456: $applies ++;
11457: }
11458: if ($numinvalid) {
11459: $applies ++;
11460: }
11461: if ($numexisting) {
11462: $applies ++;
11463: }
1.1071 raeburn 11464: if ($counter || $numunused) {
1.987 raeburn 11465: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11466: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11467: $state.'<h3>'.$heading.'</h3>';
11468: if ($actionurl eq '/adm/dependencies') {
11469: if ($numnew) {
11470: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11471: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11472: $upload_output.'<br />'."\n";
11473: }
11474: if ($numexisting) {
11475: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11476: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11477: $modify_output.'<br />'."\n";
11478: $buttontext = &mt('Save changes');
11479: }
11480: if ($numunused) {
11481: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11482: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11483: $delete_output.'<br />'."\n";
11484: $buttontext = &mt('Save changes');
11485: }
11486: } else {
11487: $output .= $upload_output.'<br />'."\n";
11488: }
11489: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11490: $counter.'" />'."\n";
11491: if ($actionurl eq '/adm/dependencies') {
11492: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11493: $numnew.'" />'."\n";
11494: } elsif ($actionurl eq '') {
1.987 raeburn 11495: $output .= '<input type="hidden" name="phase" value="three" />';
11496: }
11497: } elsif ($applies) {
11498: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11499: if ($applies > 1) {
11500: $output .=
1.1123 raeburn 11501: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11502: if ($numremref) {
11503: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11504: }
11505: if ($numinvalid) {
11506: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11507: }
11508: if ($numexisting) {
11509: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11510: }
11511: $output .= '</ul><br />';
11512: } elsif ($numremref) {
11513: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11514: } elsif ($numinvalid) {
11515: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11516: } elsif ($numexisting) {
11517: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11518: }
11519: $output .= $upload_output.'<br />';
11520: }
11521: my ($pathchange_output,$chgcount);
1.1071 raeburn 11522: $chgcount = $counter;
1.987 raeburn 11523: if (keys(%pathchanges) > 0) {
11524: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11525: if ($counter) {
1.987 raeburn 11526: $output .= &embedded_file_element('pathchange',$chgcount,
11527: $embed_file,\%mapping,
1.1071 raeburn 11528: $allfiles,$codebase,'change');
1.987 raeburn 11529: } else {
11530: $pathchange_output .=
11531: &start_data_table_row().
11532: '<td><input type ="checkbox" name="namechange" value="'.
11533: $chgcount.'" checked="checked" /></td>'.
11534: '<td>'.$mapping{$embed_file}.'</td>'.
11535: '<td>'.$embed_file.
11536: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11537: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11538: '</td>'.&end_data_table_row();
1.660 raeburn 11539: }
1.987 raeburn 11540: $numpathchg ++;
11541: $chgcount ++;
1.660 raeburn 11542: }
11543: }
1.1127 raeburn 11544: if (($counter) || ($numunused)) {
1.987 raeburn 11545: if ($numpathchg) {
11546: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11547: $numpathchg.'" />'."\n";
11548: }
11549: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11550: ($actionurl eq '/adm/imsimport')) {
11551: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11552: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11553: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11554: } elsif ($actionurl eq '/adm/dependencies') {
11555: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11556: }
1.1123 raeburn 11557: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11558: } elsif ($numpathchg) {
11559: my %pathchange = ();
11560: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11561: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11562: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11563: }
1.987 raeburn 11564: }
1.1071 raeburn 11565: return ($output,$counter,$numpathchg);
1.987 raeburn 11566: }
11567:
1.1147 raeburn 11568: =pod
11569:
11570: =item * clean_path($name)
11571:
11572: Performs clean-up of directories, subdirectories and filename in an
11573: embedded object, referenced in an HTML file which is being uploaded
11574: to a course or portfolio, where
11575: "Upload embedded images/multimedia files if HTML file" checkbox was
11576: checked.
11577:
11578: Clean-up is similar to replacements in lonnet::clean_filename()
11579: except each / between sub-directory and next level is preserved.
11580:
11581: =cut
11582:
11583: sub clean_path {
11584: my ($embed_file) = @_;
11585: $embed_file =~s{^/+}{};
11586: my @contents;
11587: if ($embed_file =~ m{/}) {
11588: @contents = split(/\//,$embed_file);
11589: } else {
11590: @contents = ($embed_file);
11591: }
11592: my $lastidx = scalar(@contents)-1;
11593: for (my $i=0; $i<=$lastidx; $i++) {
11594: $contents[$i]=~s{\\}{/}g;
11595: $contents[$i]=~s/\s+/\_/g;
11596: $contents[$i]=~s{[^/\w\.\-]}{}g;
11597: if ($i == $lastidx) {
11598: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11599: }
11600: }
11601: if ($lastidx > 0) {
11602: return join('/',@contents);
11603: } else {
11604: return $contents[0];
11605: }
11606: }
11607:
1.987 raeburn 11608: sub embedded_file_element {
1.1071 raeburn 11609: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11610: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11611: (ref($codebase) eq 'HASH'));
11612: my $output;
1.1071 raeburn 11613: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11614: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11615: }
11616: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11617: &escape($embed_file).'" />';
11618: unless (($context eq 'upload_embedded') &&
11619: ($mapping->{$embed_file} eq $embed_file)) {
11620: $output .='
11621: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11622: }
11623: my $attrib;
11624: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11625: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11626: }
11627: $output .=
11628: "\n\t\t".
11629: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11630: $attrib.'" />';
11631: if (exists($codebase->{$mapping->{$embed_file}})) {
11632: $output .=
11633: "\n\t\t".
11634: '<input name="codebase_'.$num.'" type="hidden" value="'.
11635: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11636: }
1.987 raeburn 11637: return $output;
1.660 raeburn 11638: }
11639:
1.1071 raeburn 11640: sub get_dependency_details {
11641: my ($currfile,$currsubfile,$embed_file) = @_;
11642: my ($size,$mtime,$showsize,$showmtime);
11643: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11644: if ($embed_file =~ m{/}) {
11645: my ($path,$fname) = split(/\//,$embed_file);
11646: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11647: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11648: }
11649: } else {
11650: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11651: ($size,$mtime) = @{$currfile->{$embed_file}};
11652: }
11653: }
11654: $showsize = $size/1024.0;
11655: $showsize = sprintf("%.1f",$showsize);
11656: if ($mtime > 0) {
11657: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11658: }
11659: }
11660: return ($showsize,$showmtime);
11661: }
11662:
11663: sub ask_embedded_js {
11664: return <<"END";
11665: <script type="text/javascript"">
11666: // <![CDATA[
11667: function toggleBrowse(counter) {
11668: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11669: var fileid = document.getElementById('embedded_item_'+counter);
11670: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11671: if (chkboxid.checked == true) {
11672: uploaddivid.style.display='block';
11673: } else {
11674: uploaddivid.style.display='none';
11675: fileid.value = '';
11676: }
11677: }
11678: // ]]>
11679: </script>
11680:
11681: END
11682: }
11683:
1.661 raeburn 11684: sub upload_embedded {
11685: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11686: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11687: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11688: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11689: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11690: my $orig_uploaded_filename =
11691: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11692: foreach my $type ('orig','ref','attrib','codebase') {
11693: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11694: $env{'form.embedded_'.$type.'_'.$i} =
11695: &unescape($env{'form.embedded_'.$type.'_'.$i});
11696: }
11697: }
1.661 raeburn 11698: my ($path,$fname) =
11699: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11700: # no path, whole string is fname
11701: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11702: $fname = &Apache::lonnet::clean_filename($fname);
11703: # See if there is anything left
11704: next if ($fname eq '');
11705:
11706: # Check if file already exists as a file or directory.
11707: my ($state,$msg);
11708: if ($context eq 'portfolio') {
11709: my $port_path = $dirpath;
11710: if ($group ne '') {
11711: $port_path = "groups/$group/$port_path";
11712: }
1.987 raeburn 11713: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11714: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11715: $dir_root,$port_path,$disk_quota,
11716: $current_disk_usage,$uname,$udom);
11717: if ($state eq 'will_exceed_quota'
1.984 raeburn 11718: || $state eq 'file_locked') {
1.661 raeburn 11719: $output .= $msg;
11720: next;
11721: }
11722: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11723: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11724: if ($state eq 'exists') {
11725: $output .= $msg;
11726: next;
11727: }
11728: }
11729: # Check if extension is valid
11730: if (($fname =~ /\.(\w+)$/) &&
11731: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 11732: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11733: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11734: next;
11735: } elsif (($fname =~ /\.(\w+)$/) &&
11736: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11737: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11738: next;
11739: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 11740: $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 11741: next;
11742: }
11743: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 11744: my $subdir = $path;
11745: $subdir =~ s{/+$}{};
1.661 raeburn 11746: if ($context eq 'portfolio') {
1.984 raeburn 11747: my $result;
11748: if ($state eq 'existingfile') {
11749: $result=
11750: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 11751: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11752: } else {
1.984 raeburn 11753: $result=
11754: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11755: $dirpath.
1.1123 raeburn 11756: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11757: if ($result !~ m|^/uploaded/|) {
11758: $output .= '<span class="LC_error">'
11759: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11760: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11761: .'</span><br />';
11762: next;
11763: } else {
1.987 raeburn 11764: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11765: $path.$fname.'</span>').'<br />';
1.984 raeburn 11766: }
1.661 raeburn 11767: }
1.1123 raeburn 11768: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 11769: my $extendedsubdir = $dirpath.'/'.$subdir;
11770: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11771: my $result =
1.1126 raeburn 11772: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11773: if ($result !~ m|^/uploaded/|) {
11774: $output .= '<span class="LC_error">'
11775: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11776: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11777: .'</span><br />';
11778: next;
11779: } else {
11780: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11781: $path.$fname.'</span>').'<br />';
1.1125 raeburn 11782: if ($context eq 'syllabus') {
11783: &Apache::lonnet::make_public_indefinitely($result);
11784: }
1.987 raeburn 11785: }
1.661 raeburn 11786: } else {
11787: # Save the file
11788: my $target = $env{'form.embedded_item_'.$i};
11789: my $fullpath = $dir_root.$dirpath.'/'.$path;
11790: my $dest = $fullpath.$fname;
11791: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11792: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11793: my $count;
11794: my $filepath = $dir_root;
1.1027 raeburn 11795: foreach my $subdir (@parts) {
11796: $filepath .= "/$subdir";
11797: if (!-e $filepath) {
1.661 raeburn 11798: mkdir($filepath,0770);
11799: }
11800: }
11801: my $fh;
11802: if (!open($fh,'>'.$dest)) {
11803: &Apache::lonnet::logthis('Failed to create '.$dest);
11804: $output .= '<span class="LC_error">'.
1.1071 raeburn 11805: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11806: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11807: '</span><br />';
11808: } else {
11809: if (!print $fh $env{'form.embedded_item_'.$i}) {
11810: &Apache::lonnet::logthis('Failed to write to '.$dest);
11811: $output .= '<span class="LC_error">'.
1.1071 raeburn 11812: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11813: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11814: '</span><br />';
11815: } else {
1.987 raeburn 11816: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11817: $url.'</span>').'<br />';
11818: unless ($context eq 'testbank') {
11819: $footer .= &mt('View embedded file: [_1]',
11820: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11821: }
11822: }
11823: close($fh);
11824: }
11825: }
11826: if ($env{'form.embedded_ref_'.$i}) {
11827: $pathchange{$i} = 1;
11828: }
11829: }
11830: if ($output) {
11831: $output = '<p>'.$output.'</p>';
11832: }
11833: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11834: $returnflag = 'ok';
1.1071 raeburn 11835: my $numpathchgs = scalar(keys(%pathchange));
11836: if ($numpathchgs > 0) {
1.987 raeburn 11837: if ($context eq 'portfolio') {
11838: $output .= '<p>'.&mt('or').'</p>';
11839: } elsif ($context eq 'testbank') {
1.1071 raeburn 11840: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11841: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11842: $returnflag = 'modify_orightml';
11843: }
11844: }
1.1071 raeburn 11845: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11846: }
11847:
11848: sub modify_html_form {
11849: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11850: my $end = 0;
11851: my $modifyform;
11852: if ($context eq 'upload_embedded') {
11853: return unless (ref($pathchange) eq 'HASH');
11854: if ($env{'form.number_embedded_items'}) {
11855: $end += $env{'form.number_embedded_items'};
11856: }
11857: if ($env{'form.number_pathchange_items'}) {
11858: $end += $env{'form.number_pathchange_items'};
11859: }
11860: if ($end) {
11861: for (my $i=0; $i<$end; $i++) {
11862: if ($i < $env{'form.number_embedded_items'}) {
11863: next unless($pathchange->{$i});
11864: }
11865: $modifyform .=
11866: &start_data_table_row().
11867: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11868: 'checked="checked" /></td>'.
11869: '<td>'.$env{'form.embedded_ref_'.$i}.
11870: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11871: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11872: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11873: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11874: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11875: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11876: '<td>'.$env{'form.embedded_orig_'.$i}.
11877: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11878: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11879: &end_data_table_row();
1.1071 raeburn 11880: }
1.987 raeburn 11881: }
11882: } else {
11883: $modifyform = $pathchgtable;
11884: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11885: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11886: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11887: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11888: }
11889: }
11890: if ($modifyform) {
1.1071 raeburn 11891: if ($actionurl eq '/adm/dependencies') {
11892: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11893: }
1.987 raeburn 11894: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11895: '<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".
11896: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11897: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11898: '</ol></p>'."\n".'<p>'.
11899: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11900: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11901: &start_data_table()."\n".
11902: &start_data_table_header_row().
11903: '<th>'.&mt('Change?').'</th>'.
11904: '<th>'.&mt('Current reference').'</th>'.
11905: '<th>'.&mt('Required reference').'</th>'.
11906: &end_data_table_header_row()."\n".
11907: $modifyform.
11908: &end_data_table().'<br />'."\n".$hiddenstate.
11909: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11910: '</form>'."\n";
11911: }
11912: return;
11913: }
11914:
11915: sub modify_html_refs {
1.1123 raeburn 11916: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11917: my $container;
11918: if ($context eq 'portfolio') {
11919: $container = $env{'form.container'};
11920: } elsif ($context eq 'coursedoc') {
11921: $container = $env{'form.primaryurl'};
1.1071 raeburn 11922: } elsif ($context eq 'manage_dependencies') {
11923: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11924: $container = "/$container";
1.1123 raeburn 11925: } elsif ($context eq 'syllabus') {
11926: $container = $url;
1.987 raeburn 11927: } else {
1.1027 raeburn 11928: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11929: }
11930: my (%allfiles,%codebase,$output,$content);
11931: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 11932: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11933: if (wantarray) {
11934: return ('',0,0);
11935: } else {
11936: return;
11937: }
11938: }
11939: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11940: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11941: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11942: if (wantarray) {
11943: return ('',0,0);
11944: } else {
11945: return;
11946: }
11947: }
1.987 raeburn 11948: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11949: if ($content eq '-1') {
11950: if (wantarray) {
11951: return ('',0,0);
11952: } else {
11953: return;
11954: }
11955: }
1.987 raeburn 11956: } else {
1.1071 raeburn 11957: unless ($container =~ /^\Q$dir_root\E/) {
11958: if (wantarray) {
11959: return ('',0,0);
11960: } else {
11961: return;
11962: }
11963: }
1.987 raeburn 11964: if (open(my $fh,"<$container")) {
11965: $content = join('', <$fh>);
11966: close($fh);
11967: } else {
1.1071 raeburn 11968: if (wantarray) {
11969: return ('',0,0);
11970: } else {
11971: return;
11972: }
1.987 raeburn 11973: }
11974: }
11975: my ($count,$codebasecount) = (0,0);
11976: my $mm = new File::MMagic;
11977: my $mime_type = $mm->checktype_contents($content);
11978: if ($mime_type eq 'text/html') {
11979: my $parse_result =
11980: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11981: \%codebase,\$content);
11982: if ($parse_result eq 'ok') {
11983: foreach my $i (@changes) {
11984: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11985: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11986: if ($allfiles{$ref}) {
11987: my $newname = $orig;
11988: my ($attrib_regexp,$codebase);
1.1006 raeburn 11989: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11990: if ($attrib_regexp =~ /:/) {
11991: $attrib_regexp =~ s/\:/|/g;
11992: }
11993: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11994: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11995: $count += $numchg;
1.1123 raeburn 11996: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 11997: delete($allfiles{$ref});
1.987 raeburn 11998: }
11999: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12000: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12001: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12002: $codebasecount ++;
12003: }
12004: }
12005: }
1.1123 raeburn 12006: my $skiprewrites;
1.987 raeburn 12007: if ($count || $codebasecount) {
12008: my $saveresult;
1.1071 raeburn 12009: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12010: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12011: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12012: if ($url eq $container) {
12013: my ($fname) = ($container =~ m{/([^/]+)$});
12014: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12015: $count,'<span class="LC_filename">'.
1.1071 raeburn 12016: $fname.'</span>').'</p>';
1.987 raeburn 12017: } else {
12018: $output = '<p class="LC_error">'.
12019: &mt('Error: update failed for: [_1].',
12020: '<span class="LC_filename">'.
12021: $container.'</span>').'</p>';
12022: }
1.1123 raeburn 12023: if ($context eq 'syllabus') {
12024: unless ($saveresult eq 'ok') {
12025: $skiprewrites = 1;
12026: }
12027: }
1.987 raeburn 12028: } else {
12029: if (open(my $fh,">$container")) {
12030: print $fh $content;
12031: close($fh);
12032: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12033: $count,'<span class="LC_filename">'.
12034: $container.'</span>').'</p>';
1.661 raeburn 12035: } else {
1.987 raeburn 12036: $output = '<p class="LC_error">'.
12037: &mt('Error: could not update [_1].',
12038: '<span class="LC_filename">'.
12039: $container.'</span>').'</p>';
1.661 raeburn 12040: }
12041: }
12042: }
1.1123 raeburn 12043: if (($context eq 'syllabus') && (!$skiprewrites)) {
12044: my ($actionurl,$state);
12045: $actionurl = "/public/$udom/$uname/syllabus";
12046: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12047: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12048: \%codebase,
12049: {'context' => 'rewrites',
12050: 'ignore_remote_references' => 1,});
12051: if (ref($mapping) eq 'HASH') {
12052: my $rewrites = 0;
12053: foreach my $key (keys(%{$mapping})) {
12054: next if ($key =~ m{^https?://});
12055: my $ref = $mapping->{$key};
12056: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12057: my $attrib;
12058: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12059: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12060: }
12061: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12062: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12063: $rewrites += $numchg;
12064: }
12065: }
12066: if ($rewrites) {
12067: my $saveresult;
12068: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12069: if ($url eq $container) {
12070: my ($fname) = ($container =~ m{/([^/]+)$});
12071: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12072: $count,'<span class="LC_filename">'.
12073: $fname.'</span>').'</p>';
12074: } else {
12075: $output .= '<p class="LC_error">'.
12076: &mt('Error: could not update links in [_1].',
12077: '<span class="LC_filename">'.
12078: $container.'</span>').'</p>';
12079:
12080: }
12081: }
12082: }
12083: }
1.987 raeburn 12084: } else {
12085: &logthis('Failed to parse '.$container.
12086: ' to modify references: '.$parse_result);
1.661 raeburn 12087: }
12088: }
1.1071 raeburn 12089: if (wantarray) {
12090: return ($output,$count,$codebasecount);
12091: } else {
12092: return $output;
12093: }
1.661 raeburn 12094: }
12095:
12096: sub check_for_existing {
12097: my ($path,$fname,$element) = @_;
12098: my ($state,$msg);
12099: if (-d $path.'/'.$fname) {
12100: $state = 'exists';
12101: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12102: } elsif (-e $path.'/'.$fname) {
12103: $state = 'exists';
12104: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12105: }
12106: if ($state eq 'exists') {
12107: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12108: }
12109: return ($state,$msg);
12110: }
12111:
12112: sub check_for_upload {
12113: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12114: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12115: my $filesize = length($env{'form.'.$element});
12116: if (!$filesize) {
12117: my $msg = '<span class="LC_error">'.
12118: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12119: '<span class="LC_filename">'.$fname.'</span>',
12120: $filesize).'<br />'.
1.1007 raeburn 12121: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12122: '</span>';
12123: return ('zero_bytes',$msg);
12124: }
12125: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12126: my $getpropath = 1;
1.1021 raeburn 12127: my ($dirlistref,$listerror) =
12128: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12129: my $found_file = 0;
12130: my $locked_file = 0;
1.991 raeburn 12131: my @lockers;
12132: my $navmap;
12133: if ($env{'request.course.id'}) {
12134: $navmap = Apache::lonnavmaps::navmap->new();
12135: }
1.1021 raeburn 12136: if (ref($dirlistref) eq 'ARRAY') {
12137: foreach my $line (@{$dirlistref}) {
12138: my ($file_name,$rest)=split(/\&/,$line,2);
12139: if ($file_name eq $fname){
12140: $file_name = $path.$file_name;
12141: if ($group ne '') {
12142: $file_name = $group.$file_name;
12143: }
12144: $found_file = 1;
12145: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12146: foreach my $lock (@lockers) {
12147: if (ref($lock) eq 'ARRAY') {
12148: my ($symb,$crsid) = @{$lock};
12149: if ($crsid eq $env{'request.course.id'}) {
12150: if (ref($navmap)) {
12151: my $res = $navmap->getBySymb($symb);
12152: foreach my $part (@{$res->parts()}) {
12153: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12154: unless (($slot_status == $res->RESERVED) ||
12155: ($slot_status == $res->RESERVED_LOCATION)) {
12156: $locked_file = 1;
12157: }
1.991 raeburn 12158: }
1.1021 raeburn 12159: } else {
12160: $locked_file = 1;
1.991 raeburn 12161: }
12162: } else {
12163: $locked_file = 1;
12164: }
12165: }
1.1021 raeburn 12166: }
12167: } else {
12168: my @info = split(/\&/,$rest);
12169: my $currsize = $info[6]/1000;
12170: if ($currsize < $filesize) {
12171: my $extra = $filesize - $currsize;
12172: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12173: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12174: &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 12175: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12176: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12177: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12178: return ('will_exceed_quota',$msg);
12179: }
1.984 raeburn 12180: }
12181: }
1.661 raeburn 12182: }
12183: }
12184: }
12185: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12186: my $msg = '<p class="LC_warning">'.
12187: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12188: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12189: return ('will_exceed_quota',$msg);
12190: } elsif ($found_file) {
12191: if ($locked_file) {
1.1179 bisitz 12192: my $msg = '<p class="LC_warning">';
1.661 raeburn 12193: $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 12194: $msg .= '</p>';
1.661 raeburn 12195: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12196: return ('file_locked',$msg);
12197: } else {
1.1179 bisitz 12198: my $msg = '<p class="LC_error">';
1.984 raeburn 12199: $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 12200: $msg .= '</p>';
1.984 raeburn 12201: return ('existingfile',$msg);
1.661 raeburn 12202: }
12203: }
12204: }
12205:
1.987 raeburn 12206: sub check_for_traversal {
12207: my ($path,$url,$toplevel) = @_;
12208: my @parts=split(/\//,$path);
12209: my $cleanpath;
12210: my $fullpath = $url;
12211: for (my $i=0;$i<@parts;$i++) {
12212: next if ($parts[$i] eq '.');
12213: if ($parts[$i] eq '..') {
12214: $fullpath =~ s{([^/]+/)$}{};
12215: } else {
12216: $fullpath .= $parts[$i].'/';
12217: }
12218: }
12219: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12220: $cleanpath = $1;
12221: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12222: my $curr_toprel = $1;
12223: my @parts = split(/\//,$curr_toprel);
12224: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12225: my @urlparts = split(/\//,$url_toprel);
12226: my $doubledots;
12227: my $startdiff = -1;
12228: for (my $i=0; $i<@urlparts; $i++) {
12229: if ($startdiff == -1) {
12230: unless ($urlparts[$i] eq $parts[$i]) {
12231: $startdiff = $i;
12232: $doubledots .= '../';
12233: }
12234: } else {
12235: $doubledots .= '../';
12236: }
12237: }
12238: if ($startdiff > -1) {
12239: $cleanpath = $doubledots;
12240: for (my $i=$startdiff; $i<@parts; $i++) {
12241: $cleanpath .= $parts[$i].'/';
12242: }
12243: }
12244: }
12245: $cleanpath =~ s{(/)$}{};
12246: return $cleanpath;
12247: }
1.31 albertel 12248:
1.1053 raeburn 12249: sub is_archive_file {
12250: my ($mimetype) = @_;
12251: if (($mimetype eq 'application/octet-stream') ||
12252: ($mimetype eq 'application/x-stuffit') ||
12253: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12254: return 1;
12255: }
12256: return;
12257: }
12258:
12259: sub decompress_form {
1.1065 raeburn 12260: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12261: my %lt = &Apache::lonlocal::texthash (
12262: this => 'This file is an archive file.',
1.1067 raeburn 12263: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12264: itsc => 'Its contents are as follows:',
1.1053 raeburn 12265: youm => 'You may wish to extract its contents.',
12266: extr => 'Extract contents',
1.1067 raeburn 12267: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12268: proa => 'Process automatically?',
1.1053 raeburn 12269: yes => 'Yes',
12270: no => 'No',
1.1067 raeburn 12271: fold => 'Title for folder containing movie',
12272: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12273: );
1.1065 raeburn 12274: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12275: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12276: my $info = &list_archive_contents($fileloc,\@paths);
12277: if (@paths) {
12278: foreach my $path (@paths) {
12279: $path =~ s{^/}{};
1.1067 raeburn 12280: if ($path =~ m{^([^/]+)/$}) {
12281: $topdir = $1;
12282: }
1.1065 raeburn 12283: if ($path =~ m{^([^/]+)/}) {
12284: $toplevel{$1} = $path;
12285: } else {
12286: $toplevel{$path} = $path;
12287: }
12288: }
12289: }
1.1067 raeburn 12290: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12291: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12292: "$topdir/media/",
12293: "$topdir/media/$topdir.mp4",
12294: "$topdir/media/FirstFrame.png",
12295: "$topdir/media/player.swf",
12296: "$topdir/media/swfobject.js",
12297: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12298: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12299: "$topdir/$topdir.mp4",
12300: "$topdir/$topdir\_config.xml",
12301: "$topdir/$topdir\_controller.swf",
12302: "$topdir/$topdir\_embed.css",
12303: "$topdir/$topdir\_First_Frame.png",
12304: "$topdir/$topdir\_player.html",
12305: "$topdir/$topdir\_Thumbnails.png",
12306: "$topdir/playerProductInstall.swf",
12307: "$topdir/scripts/",
12308: "$topdir/scripts/config_xml.js",
12309: "$topdir/scripts/handlebars.js",
12310: "$topdir/scripts/jquery-1.7.1.min.js",
12311: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12312: "$topdir/scripts/modernizr.js",
12313: "$topdir/scripts/player-min.js",
12314: "$topdir/scripts/swfobject.js",
12315: "$topdir/skins/",
12316: "$topdir/skins/configuration_express.xml",
12317: "$topdir/skins/express_show/",
12318: "$topdir/skins/express_show/player-min.css",
12319: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12320: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12321: "$topdir/$topdir.mp4",
12322: "$topdir/$topdir\_config.xml",
12323: "$topdir/$topdir\_controller.swf",
12324: "$topdir/$topdir\_embed.css",
12325: "$topdir/$topdir\_First_Frame.png",
12326: "$topdir/$topdir\_player.html",
12327: "$topdir/$topdir\_Thumbnails.png",
12328: "$topdir/playerProductInstall.swf",
12329: "$topdir/scripts/",
12330: "$topdir/scripts/config_xml.js",
12331: "$topdir/scripts/techsmith-smart-player.min.js",
12332: "$topdir/skins/",
12333: "$topdir/skins/configuration_express.xml",
12334: "$topdir/skins/express_show/",
12335: "$topdir/skins/express_show/spritesheet.min.css",
12336: "$topdir/skins/express_show/spritesheet.png",
12337: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12338: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12339: if (@diffs == 0) {
1.1164 raeburn 12340: $is_camtasia = 6;
12341: } else {
1.1197 raeburn 12342: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12343: if (@diffs == 0) {
12344: $is_camtasia = 8;
1.1197 raeburn 12345: } else {
12346: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12347: if (@diffs == 0) {
12348: $is_camtasia = 8;
12349: }
1.1164 raeburn 12350: }
1.1067 raeburn 12351: }
12352: }
12353: my $output;
12354: if ($is_camtasia) {
12355: $output = <<"ENDCAM";
12356: <script type="text/javascript" language="Javascript">
12357: // <![CDATA[
12358:
12359: function camtasiaToggle() {
12360: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12361: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12362: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12363: document.getElementById('camtasia_titles').style.display='block';
12364: } else {
12365: document.getElementById('camtasia_titles').style.display='none';
12366: }
12367: }
12368: }
12369: return;
12370: }
12371:
12372: // ]]>
12373: </script>
12374: <p>$lt{'camt'}</p>
12375: ENDCAM
1.1065 raeburn 12376: } else {
1.1067 raeburn 12377: $output = '<p>'.$lt{'this'};
12378: if ($info eq '') {
12379: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12380: } else {
12381: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12382: '<div><pre>'.$info.'</pre></div>';
12383: }
1.1065 raeburn 12384: }
1.1067 raeburn 12385: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12386: my $duplicates;
12387: my $num = 0;
12388: if (ref($dirlist) eq 'ARRAY') {
12389: foreach my $item (@{$dirlist}) {
12390: if (ref($item) eq 'ARRAY') {
12391: if (exists($toplevel{$item->[0]})) {
12392: $duplicates .=
12393: &start_data_table_row().
12394: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12395: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12396: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12397: 'value="1" />'.&mt('Yes').'</label>'.
12398: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12399: '<td>'.$item->[0].'</td>';
12400: if ($item->[2]) {
12401: $duplicates .= '<td>'.&mt('Directory').'</td>';
12402: } else {
12403: $duplicates .= '<td>'.&mt('File').'</td>';
12404: }
12405: $duplicates .= '<td>'.$item->[3].'</td>'.
12406: '<td>'.
12407: &Apache::lonlocal::locallocaltime($item->[4]).
12408: '</td>'.
12409: &end_data_table_row();
12410: $num ++;
12411: }
12412: }
12413: }
12414: }
12415: my $itemcount;
12416: if (@paths > 0) {
12417: $itemcount = scalar(@paths);
12418: } else {
12419: $itemcount = 1;
12420: }
1.1067 raeburn 12421: if ($is_camtasia) {
12422: $output .= $lt{'auto'}.'<br />'.
12423: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12424: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12425: $lt{'yes'}.'</label> <label>'.
12426: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12427: $lt{'no'}.'</label></span><br />'.
12428: '<div id="camtasia_titles" style="display:block">'.
12429: &Apache::lonhtmlcommon::start_pick_box().
12430: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12431: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12432: &Apache::lonhtmlcommon::row_closure().
12433: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12434: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12435: &Apache::lonhtmlcommon::row_closure(1).
12436: &Apache::lonhtmlcommon::end_pick_box().
12437: '</div>';
12438: }
1.1065 raeburn 12439: $output .=
12440: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12441: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12442: "\n";
1.1065 raeburn 12443: if ($duplicates ne '') {
12444: $output .= '<p><span class="LC_warning">'.
12445: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12446: &start_data_table().
12447: &start_data_table_header_row().
12448: '<th>'.&mt('Overwrite?').'</th>'.
12449: '<th>'.&mt('Name').'</th>'.
12450: '<th>'.&mt('Type').'</th>'.
12451: '<th>'.&mt('Size').'</th>'.
12452: '<th>'.&mt('Last modified').'</th>'.
12453: &end_data_table_header_row().
12454: $duplicates.
12455: &end_data_table().
12456: '</p>';
12457: }
1.1067 raeburn 12458: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12459: if (ref($hiddenelements) eq 'HASH') {
12460: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12461: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12462: }
12463: }
12464: $output .= <<"END";
1.1067 raeburn 12465: <br />
1.1053 raeburn 12466: <input type="submit" name="decompress" value="$lt{'extr'}" />
12467: </form>
12468: $noextract
12469: END
12470: return $output;
12471: }
12472:
1.1065 raeburn 12473: sub decompression_utility {
12474: my ($program) = @_;
12475: my @utilities = ('tar','gunzip','bunzip2','unzip');
12476: my $location;
12477: if (grep(/^\Q$program\E$/,@utilities)) {
12478: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12479: '/usr/sbin/') {
12480: if (-x $dir.$program) {
12481: $location = $dir.$program;
12482: last;
12483: }
12484: }
12485: }
12486: return $location;
12487: }
12488:
12489: sub list_archive_contents {
12490: my ($file,$pathsref) = @_;
12491: my (@cmd,$output);
12492: my $needsregexp;
12493: if ($file =~ /\.zip$/) {
12494: @cmd = (&decompression_utility('unzip'),"-l");
12495: $needsregexp = 1;
12496: } elsif (($file =~ m/\.tar\.gz$/) ||
12497: ($file =~ /\.tgz$/)) {
12498: @cmd = (&decompression_utility('tar'),"-ztf");
12499: } elsif ($file =~ /\.tar\.bz2$/) {
12500: @cmd = (&decompression_utility('tar'),"-jtf");
12501: } elsif ($file =~ m|\.tar$|) {
12502: @cmd = (&decompression_utility('tar'),"-tf");
12503: }
12504: if (@cmd) {
12505: undef($!);
12506: undef($@);
12507: if (open(my $fh,"-|", @cmd, $file)) {
12508: while (my $line = <$fh>) {
12509: $output .= $line;
12510: chomp($line);
12511: my $item;
12512: if ($needsregexp) {
12513: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12514: } else {
12515: $item = $line;
12516: }
12517: if ($item ne '') {
12518: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12519: push(@{$pathsref},$item);
12520: }
12521: }
12522: }
12523: close($fh);
12524: }
12525: }
12526: return $output;
12527: }
12528:
1.1053 raeburn 12529: sub decompress_uploaded_file {
12530: my ($file,$dir) = @_;
12531: &Apache::lonnet::appenv({'cgi.file' => $file});
12532: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12533: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12534: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12535: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12536: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12537: my $decompressed = $env{'cgi.decompressed'};
12538: &Apache::lonnet::delenv('cgi.file');
12539: &Apache::lonnet::delenv('cgi.dir');
12540: &Apache::lonnet::delenv('cgi.decompressed');
12541: return ($decompressed,$result);
12542: }
12543:
1.1055 raeburn 12544: sub process_decompression {
12545: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
12546: my ($dir,$error,$warning,$output);
1.1180 raeburn 12547: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12548: $error = &mt('Filename not a supported archive file type.').
12549: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12550: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12551: } else {
12552: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12553: if ($docuhome eq 'no_host') {
12554: $error = &mt('Could not determine home server for course.');
12555: } else {
12556: my @ids=&Apache::lonnet::current_machine_ids();
12557: my $currdir = "$dir_root/$destination";
12558: if (grep(/^\Q$docuhome\E$/,@ids)) {
12559: $dir = &LONCAPA::propath($docudom,$docuname).
12560: "$dir_root/$destination";
12561: } else {
12562: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12563: "$dir_root/$docudom/$docuname/$destination";
12564: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12565: $error = &mt('Archive file not found.');
12566: }
12567: }
1.1065 raeburn 12568: my (@to_overwrite,@to_skip);
12569: if ($env{'form.archive_overwrite_total'} > 0) {
12570: my $total = $env{'form.archive_overwrite_total'};
12571: for (my $i=0; $i<$total; $i++) {
12572: if ($env{'form.archive_overwrite_'.$i} == 1) {
12573: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12574: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12575: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12576: }
12577: }
12578: }
12579: my $numskip = scalar(@to_skip);
12580: if (($numskip > 0) &&
12581: ($numskip == $env{'form.archive_itemcount'})) {
12582: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12583: } elsif ($dir eq '') {
1.1055 raeburn 12584: $error = &mt('Directory containing archive file unavailable.');
12585: } elsif (!$error) {
1.1065 raeburn 12586: my ($decompressed,$display);
12587: if ($numskip > 0) {
12588: my $tempdir = time.'_'.$$.int(rand(10000));
12589: mkdir("$dir/$tempdir",0755);
12590: system("mv $dir/$file $dir/$tempdir/$file");
12591: ($decompressed,$display) =
12592: &decompress_uploaded_file($file,"$dir/$tempdir");
12593: foreach my $item (@to_skip) {
12594: if (($item ne '') && ($item !~ /\.\./)) {
12595: if (-f "$dir/$tempdir/$item") {
12596: unlink("$dir/$tempdir/$item");
12597: } elsif (-d "$dir/$tempdir/$item") {
12598: system("rm -rf $dir/$tempdir/$item");
12599: }
12600: }
12601: }
12602: system("mv $dir/$tempdir/* $dir");
12603: rmdir("$dir/$tempdir");
12604: } else {
12605: ($decompressed,$display) =
12606: &decompress_uploaded_file($file,$dir);
12607: }
1.1055 raeburn 12608: if ($decompressed eq 'ok') {
1.1065 raeburn 12609: $output = '<p class="LC_info">'.
12610: &mt('Files extracted successfully from archive.').
12611: '</p>'."\n";
1.1055 raeburn 12612: my ($warning,$result,@contents);
12613: my ($newdirlistref,$newlisterror) =
12614: &Apache::lonnet::dirlist($currdir,$docudom,
12615: $docuname,1);
12616: my (%is_dir,%changes,@newitems);
12617: my $dirptr = 16384;
1.1065 raeburn 12618: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12619: foreach my $dir_line (@{$newdirlistref}) {
12620: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 12621: unless (($item =~ /^\.+$/) || ($item eq $file) ||
12622: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 12623: push(@newitems,$item);
12624: if ($dirptr&$testdir) {
12625: $is_dir{$item} = 1;
12626: }
12627: $changes{$item} = 1;
12628: }
12629: }
12630: }
12631: if (keys(%changes) > 0) {
12632: foreach my $item (sort(@newitems)) {
12633: if ($changes{$item}) {
12634: push(@contents,$item);
12635: }
12636: }
12637: }
12638: if (@contents > 0) {
1.1067 raeburn 12639: my $wantform;
12640: unless ($env{'form.autoextract_camtasia'}) {
12641: $wantform = 1;
12642: }
1.1056 raeburn 12643: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12644: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12645: $currdir,\%is_dir,
12646: \%children,\%parent,
1.1056 raeburn 12647: \@contents,\%dirorder,
12648: \%titles,$wantform);
1.1055 raeburn 12649: if ($datatable ne '') {
12650: $output .= &archive_options_form('decompressed',$datatable,
12651: $count,$hiddenelem);
1.1065 raeburn 12652: my $startcount = 6;
1.1055 raeburn 12653: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12654: \%titles,\%children);
1.1055 raeburn 12655: }
1.1067 raeburn 12656: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 12657: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12658: my %displayed;
12659: my $total = 1;
12660: $env{'form.archive_directory'} = [];
12661: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12662: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12663: $path =~ s{/$}{};
12664: my $item;
12665: if ($path ne '') {
12666: $item = "$path/$titles{$i}";
12667: } else {
12668: $item = $titles{$i};
12669: }
12670: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12671: if ($item eq $contents[0]) {
12672: push(@{$env{'form.archive_directory'}},$i);
12673: $env{'form.archive_'.$i} = 'display';
12674: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12675: $displayed{'folder'} = $i;
1.1164 raeburn 12676: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12677: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12678: $env{'form.archive_'.$i} = 'display';
12679: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12680: $displayed{'web'} = $i;
12681: } else {
1.1164 raeburn 12682: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12683: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12684: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12685: push(@{$env{'form.archive_directory'}},$i);
12686: }
12687: $env{'form.archive_'.$i} = 'dependency';
12688: }
12689: $total ++;
12690: }
12691: for (my $i=1; $i<$total; $i++) {
12692: next if ($i == $displayed{'web'});
12693: next if ($i == $displayed{'folder'});
12694: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12695: }
12696: $env{'form.phase'} = 'decompress_cleanup';
12697: $env{'form.archivedelete'} = 1;
12698: $env{'form.archive_count'} = $total-1;
12699: $output .=
12700: &process_extracted_files('coursedocs',$docudom,
12701: $docuname,$destination,
12702: $dir_root,$hiddenelem);
12703: }
1.1055 raeburn 12704: } else {
12705: $warning = &mt('No new items extracted from archive file.');
12706: }
12707: } else {
12708: $output = $display;
12709: $error = &mt('An error occurred during extraction from the archive file.');
12710: }
12711: }
12712: }
12713: }
12714: if ($error) {
12715: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12716: $error.'</p>'."\n";
12717: }
12718: if ($warning) {
12719: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12720: }
12721: return $output;
12722: }
12723:
12724: sub get_extracted {
1.1056 raeburn 12725: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12726: $titles,$wantform) = @_;
1.1055 raeburn 12727: my $count = 0;
12728: my $depth = 0;
12729: my $datatable;
1.1056 raeburn 12730: my @hierarchy;
1.1055 raeburn 12731: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12732: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12733: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12734: foreach my $item (@{$contents}) {
12735: $count ++;
1.1056 raeburn 12736: @{$dirorder->{$count}} = @hierarchy;
12737: $titles->{$count} = $item;
1.1055 raeburn 12738: &archive_hierarchy($depth,$count,$parent,$children);
12739: if ($wantform) {
12740: $datatable .= &archive_row($is_dir->{$item},$item,
12741: $currdir,$depth,$count);
12742: }
12743: if ($is_dir->{$item}) {
12744: $depth ++;
1.1056 raeburn 12745: push(@hierarchy,$count);
12746: $parent->{$depth} = $count;
1.1055 raeburn 12747: $datatable .=
12748: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12749: \$depth,\$count,\@hierarchy,$dirorder,
12750: $children,$parent,$titles,$wantform);
1.1055 raeburn 12751: $depth --;
1.1056 raeburn 12752: pop(@hierarchy);
1.1055 raeburn 12753: }
12754: }
12755: return ($count,$datatable);
12756: }
12757:
12758: sub recurse_extracted_archive {
1.1056 raeburn 12759: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12760: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12761: my $result='';
1.1056 raeburn 12762: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12763: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12764: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12765: return $result;
12766: }
12767: my $dirptr = 16384;
12768: my ($newdirlistref,$newlisterror) =
12769: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12770: if (ref($newdirlistref) eq 'ARRAY') {
12771: foreach my $dir_line (@{$newdirlistref}) {
12772: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12773: unless ($item =~ /^\.+$/) {
12774: $$count ++;
1.1056 raeburn 12775: @{$dirorder->{$$count}} = @{$hierarchy};
12776: $titles->{$$count} = $item;
1.1055 raeburn 12777: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12778:
1.1055 raeburn 12779: my $is_dir;
12780: if ($dirptr&$testdir) {
12781: $is_dir = 1;
12782: }
12783: if ($wantform) {
12784: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12785: }
12786: if ($is_dir) {
12787: $$depth ++;
1.1056 raeburn 12788: push(@{$hierarchy},$$count);
12789: $parent->{$$depth} = $$count;
1.1055 raeburn 12790: $result .=
12791: &recurse_extracted_archive("$currdir/$item",$docudom,
12792: $docuname,$depth,$count,
1.1056 raeburn 12793: $hierarchy,$dirorder,$children,
12794: $parent,$titles,$wantform);
1.1055 raeburn 12795: $$depth --;
1.1056 raeburn 12796: pop(@{$hierarchy});
1.1055 raeburn 12797: }
12798: }
12799: }
12800: }
12801: return $result;
12802: }
12803:
12804: sub archive_hierarchy {
12805: my ($depth,$count,$parent,$children) =@_;
12806: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12807: if (exists($parent->{$depth})) {
12808: $children->{$parent->{$depth}} .= $count.':';
12809: }
12810: }
12811: return;
12812: }
12813:
12814: sub archive_row {
12815: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12816: my ($name) = ($item =~ m{([^/]+)$});
12817: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12818: 'display' => 'Add as file',
1.1055 raeburn 12819: 'dependency' => 'Include as dependency',
12820: 'discard' => 'Discard',
12821: );
12822: if ($is_dir) {
1.1059 raeburn 12823: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12824: }
1.1056 raeburn 12825: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12826: my $offset = 0;
1.1055 raeburn 12827: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12828: $offset ++;
1.1065 raeburn 12829: if ($action ne 'display') {
12830: $offset ++;
12831: }
1.1055 raeburn 12832: $output .= '<td><span class="LC_nobreak">'.
12833: '<label><input type="radio" name="archive_'.$count.
12834: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12835: my $text = $choices{$action};
12836: if ($is_dir) {
12837: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12838: if ($action eq 'display') {
1.1059 raeburn 12839: $text = &mt('Add as folder');
1.1055 raeburn 12840: }
1.1056 raeburn 12841: } else {
12842: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12843:
12844: }
12845: $output .= ' /> '.$choices{$action}.'</label></span>';
12846: if ($action eq 'dependency') {
12847: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12848: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12849: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12850: '<option value=""></option>'."\n".
12851: '</select>'."\n".
12852: '</div>';
1.1059 raeburn 12853: } elsif ($action eq 'display') {
12854: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12855: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12856: '</div>';
1.1055 raeburn 12857: }
1.1056 raeburn 12858: $output .= '</td>';
1.1055 raeburn 12859: }
12860: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12861: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12862: for (my $i=0; $i<$depth; $i++) {
12863: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12864: }
12865: if ($is_dir) {
12866: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12867: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12868: } else {
12869: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12870: }
12871: $output .= ' '.$name.'</td>'."\n".
12872: &end_data_table_row();
12873: return $output;
12874: }
12875:
12876: sub archive_options_form {
1.1065 raeburn 12877: my ($form,$display,$count,$hiddenelem) = @_;
12878: my %lt = &Apache::lonlocal::texthash(
12879: perm => 'Permanently remove archive file?',
12880: hows => 'How should each extracted item be incorporated in the course?',
12881: cont => 'Content actions for all',
12882: addf => 'Add as folder/file',
12883: incd => 'Include as dependency for a displayed file',
12884: disc => 'Discard',
12885: no => 'No',
12886: yes => 'Yes',
12887: save => 'Save',
12888: );
12889: my $output = <<"END";
12890: <form name="$form" method="post" action="">
12891: <p><span class="LC_nobreak">$lt{'perm'}
12892: <label>
12893: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12894: </label>
12895:
12896: <label>
12897: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12898: </span>
12899: </p>
12900: <input type="hidden" name="phase" value="decompress_cleanup" />
12901: <br />$lt{'hows'}
12902: <div class="LC_columnSection">
12903: <fieldset>
12904: <legend>$lt{'cont'}</legend>
12905: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12906: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12907: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12908: </fieldset>
12909: </div>
12910: END
12911: return $output.
1.1055 raeburn 12912: &start_data_table()."\n".
1.1065 raeburn 12913: $display."\n".
1.1055 raeburn 12914: &end_data_table()."\n".
12915: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12916: $hiddenelem.
1.1065 raeburn 12917: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12918: '</form>';
12919: }
12920:
12921: sub archive_javascript {
1.1056 raeburn 12922: my ($startcount,$numitems,$titles,$children) = @_;
12923: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12924: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12925: my $scripttag = <<START;
12926: <script type="text/javascript">
12927: // <![CDATA[
12928:
12929: function checkAll(form,prefix) {
12930: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12931: for (var i=0; i < form.elements.length; i++) {
12932: var id = form.elements[i].id;
12933: if ((id != '') && (id != undefined)) {
12934: if (idstr.test(id)) {
12935: if (form.elements[i].type == 'radio') {
12936: form.elements[i].checked = true;
1.1056 raeburn 12937: var nostart = i-$startcount;
1.1059 raeburn 12938: var offset = nostart%7;
12939: var count = (nostart-offset)/7;
1.1056 raeburn 12940: dependencyCheck(form,count,offset);
1.1055 raeburn 12941: }
12942: }
12943: }
12944: }
12945: }
12946:
12947: function propagateCheck(form,count) {
12948: if (count > 0) {
1.1059 raeburn 12949: var startelement = $startcount + ((count-1) * 7);
12950: for (var j=1; j<6; j++) {
12951: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12952: var item = startelement + j;
12953: if (form.elements[item].type == 'radio') {
12954: if (form.elements[item].checked) {
12955: containerCheck(form,count,j);
12956: break;
12957: }
1.1055 raeburn 12958: }
12959: }
12960: }
12961: }
12962: }
12963:
12964: numitems = $numitems
1.1056 raeburn 12965: var titles = new Array(numitems);
12966: var parents = new Array(numitems);
1.1055 raeburn 12967: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12968: parents[i] = new Array;
1.1055 raeburn 12969: }
1.1059 raeburn 12970: var maintitle = '$maintitle';
1.1055 raeburn 12971:
12972: START
12973:
1.1056 raeburn 12974: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12975: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12976: for (my $i=0; $i<@contents; $i ++) {
12977: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12978: }
12979: }
12980:
1.1056 raeburn 12981: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12982: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12983: }
12984:
1.1055 raeburn 12985: $scripttag .= <<END;
12986:
12987: function containerCheck(form,count,offset) {
12988: if (count > 0) {
1.1056 raeburn 12989: dependencyCheck(form,count,offset);
1.1059 raeburn 12990: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12991: form.elements[item].checked = true;
12992: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12993: if (parents[count].length > 0) {
12994: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12995: containerCheck(form,parents[count][j],offset);
12996: }
12997: }
12998: }
12999: }
13000: }
13001:
13002: function dependencyCheck(form,count,offset) {
13003: if (count > 0) {
1.1059 raeburn 13004: var chosen = (offset+$startcount)+7*(count-1);
13005: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13006: var currtype = form.elements[depitem].type;
13007: if (form.elements[chosen].value == 'dependency') {
13008: document.getElementById('arc_depon_'+count).style.display='block';
13009: form.elements[depitem].options.length = 0;
13010: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13011: for (var i=1; i<=numitems; i++) {
13012: if (i == count) {
13013: continue;
13014: }
1.1059 raeburn 13015: var startelement = $startcount + (i-1) * 7;
13016: for (var j=1; j<6; j++) {
13017: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13018: var item = startelement + j;
13019: if (form.elements[item].type == 'radio') {
13020: if (form.elements[item].checked) {
13021: if (form.elements[item].value == 'display') {
13022: var n = form.elements[depitem].options.length;
13023: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13024: }
13025: }
13026: }
13027: }
13028: }
13029: }
13030: } else {
13031: document.getElementById('arc_depon_'+count).style.display='none';
13032: form.elements[depitem].options.length = 0;
13033: form.elements[depitem].options[0] = new Option('Select','',true,true);
13034: }
1.1059 raeburn 13035: titleCheck(form,count,offset);
1.1056 raeburn 13036: }
13037: }
13038:
13039: function propagateSelect(form,count,offset) {
13040: if (count > 0) {
1.1065 raeburn 13041: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13042: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13043: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13044: if (parents[count].length > 0) {
13045: for (var j=0; j<parents[count].length; j++) {
13046: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13047: }
13048: }
13049: }
13050: }
13051: }
1.1056 raeburn 13052:
13053: function containerSelect(form,count,offset,picked) {
13054: if (count > 0) {
1.1065 raeburn 13055: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13056: if (form.elements[item].type == 'radio') {
13057: if (form.elements[item].value == 'dependency') {
13058: if (form.elements[item+1].type == 'select-one') {
13059: for (var i=0; i<form.elements[item+1].options.length; i++) {
13060: if (form.elements[item+1].options[i].value == picked) {
13061: form.elements[item+1].selectedIndex = i;
13062: break;
13063: }
13064: }
13065: }
13066: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13067: if (parents[count].length > 0) {
13068: for (var j=0; j<parents[count].length; j++) {
13069: containerSelect(form,parents[count][j],offset,picked);
13070: }
13071: }
13072: }
13073: }
13074: }
13075: }
13076: }
13077:
1.1059 raeburn 13078: function titleCheck(form,count,offset) {
13079: if (count > 0) {
13080: var chosen = (offset+$startcount)+7*(count-1);
13081: var depitem = $startcount + ((count-1) * 7) + 2;
13082: var currtype = form.elements[depitem].type;
13083: if (form.elements[chosen].value == 'display') {
13084: document.getElementById('arc_title_'+count).style.display='block';
13085: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13086: document.getElementById('archive_title_'+count).value=maintitle;
13087: }
13088: } else {
13089: document.getElementById('arc_title_'+count).style.display='none';
13090: if (currtype == 'text') {
13091: document.getElementById('archive_title_'+count).value='';
13092: }
13093: }
13094: }
13095: return;
13096: }
13097:
1.1055 raeburn 13098: // ]]>
13099: </script>
13100: END
13101: return $scripttag;
13102: }
13103:
13104: sub process_extracted_files {
1.1067 raeburn 13105: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13106: my $numitems = $env{'form.archive_count'};
13107: return unless ($numitems);
13108: my @ids=&Apache::lonnet::current_machine_ids();
13109: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13110: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13111: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13112: if (grep(/^\Q$docuhome\E$/,@ids)) {
13113: $prefix = &LONCAPA::propath($docudom,$docuname);
13114: $pathtocheck = "$dir_root/$destination";
13115: $dir = $dir_root;
13116: $ishome = 1;
13117: } else {
13118: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13119: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
13120: $dir = "$dir_root/$docudom/$docuname";
13121: }
13122: my $currdir = "$dir_root/$destination";
13123: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13124: if ($env{'form.folderpath'}) {
13125: my @items = split('&',$env{'form.folderpath'});
13126: $folders{'0'} = $items[-2];
1.1099 raeburn 13127: if ($env{'form.folderpath'} =~ /\:1$/) {
13128: $containers{'0'}='page';
13129: } else {
13130: $containers{'0'}='sequence';
13131: }
1.1055 raeburn 13132: }
13133: my @archdirs = &get_env_multiple('form.archive_directory');
13134: if ($numitems) {
13135: for (my $i=1; $i<=$numitems; $i++) {
13136: my $path = $env{'form.archive_content_'.$i};
13137: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13138: my $item = $1;
13139: $toplevelitems{$item} = $i;
13140: if (grep(/^\Q$i\E$/,@archdirs)) {
13141: $is_dir{$item} = 1;
13142: }
13143: }
13144: }
13145: }
1.1067 raeburn 13146: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13147: if (keys(%toplevelitems) > 0) {
13148: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13149: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13150: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13151: }
1.1066 raeburn 13152: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13153: if ($numitems) {
13154: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13155: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13156: my $path = $env{'form.archive_content_'.$i};
13157: if ($path =~ /^\Q$pathtocheck\E/) {
13158: if ($env{'form.archive_'.$i} eq 'discard') {
13159: if ($prefix ne '' && $path ne '') {
13160: if (-e $prefix.$path) {
1.1066 raeburn 13161: if ((@archdirs > 0) &&
13162: (grep(/^\Q$i\E$/,@archdirs))) {
13163: $todeletedir{$prefix.$path} = 1;
13164: } else {
13165: $todelete{$prefix.$path} = 1;
13166: }
1.1055 raeburn 13167: }
13168: }
13169: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13170: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13171: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13172: $docstitle = $env{'form.archive_title_'.$i};
13173: if ($docstitle eq '') {
13174: $docstitle = $title;
13175: }
1.1055 raeburn 13176: $outer = 0;
1.1056 raeburn 13177: if (ref($dirorder{$i}) eq 'ARRAY') {
13178: if (@{$dirorder{$i}} > 0) {
13179: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13180: if ($env{'form.archive_'.$item} eq 'display') {
13181: $outer = $item;
13182: last;
13183: }
13184: }
13185: }
13186: }
13187: my ($errtext,$fatal) =
13188: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13189: '/'.$folders{$outer}.'.'.
13190: $containers{$outer});
13191: next if ($fatal);
13192: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13193: if ($context eq 'coursedocs') {
1.1056 raeburn 13194: $mapinner{$i} = time;
1.1055 raeburn 13195: $folders{$i} = 'default_'.$mapinner{$i};
13196: $containers{$i} = 'sequence';
13197: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13198: $folders{$i}.'.'.$containers{$i};
13199: my $newidx = &LONCAPA::map::getresidx();
13200: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13201: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13202: push(@LONCAPA::map::order,$newidx);
13203: my ($outtext,$errtext) =
13204: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13205: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13206: '.'.$containers{$outer},1,1);
1.1056 raeburn 13207: $newseqid{$i} = $newidx;
1.1067 raeburn 13208: unless ($errtext) {
13209: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
13210: }
1.1055 raeburn 13211: }
13212: } else {
13213: if ($context eq 'coursedocs') {
13214: my $newidx=&LONCAPA::map::getresidx();
13215: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13216: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13217: $title;
13218: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13219: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13220: }
13221: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13222: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13223: }
13224: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13225: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 13226: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 13227: unless ($ishome) {
13228: my $fetch = "$newdest{$i}/$title";
13229: $fetch =~ s/^\Q$prefix$dir\E//;
13230: $prompttofetch{$fetch} = 1;
13231: }
1.1055 raeburn 13232: }
13233: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13234: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13235: push(@LONCAPA::map::order, $newidx);
13236: my ($outtext,$errtext)=
13237: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13238: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13239: '.'.$containers{$outer},1,1);
1.1067 raeburn 13240: unless ($errtext) {
13241: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13242: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
13243: }
13244: }
1.1055 raeburn 13245: }
13246: }
1.1086 raeburn 13247: }
13248: } else {
13249: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
13250: }
13251: }
13252: for (my $i=1; $i<=$numitems; $i++) {
13253: next unless ($env{'form.archive_'.$i} eq 'dependency');
13254: my $path = $env{'form.archive_content_'.$i};
13255: if ($path =~ /^\Q$pathtocheck\E/) {
13256: my ($title) = ($path =~ m{/([^/]+)$});
13257: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13258: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13259: if (ref($dirorder{$i}) eq 'ARRAY') {
13260: my ($itemidx,$fullpath,$relpath);
13261: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13262: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13263: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13264: if ($dirorder{$i}->[$j] eq $container) {
13265: $itemidx = $j;
1.1056 raeburn 13266: }
13267: }
1.1086 raeburn 13268: }
13269: if ($itemidx eq '') {
13270: $itemidx = 0;
13271: }
13272: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13273: if ($mapinner{$referrer{$i}}) {
13274: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13275: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13276: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13277: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13278: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13279: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13280: if (!-e $fullpath) {
13281: mkdir($fullpath,0755);
1.1056 raeburn 13282: }
13283: }
1.1086 raeburn 13284: } else {
13285: last;
1.1056 raeburn 13286: }
1.1086 raeburn 13287: }
13288: }
13289: } elsif ($newdest{$referrer{$i}}) {
13290: $fullpath = $newdest{$referrer{$i}};
13291: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13292: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13293: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13294: last;
13295: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13296: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13297: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13298: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13299: if (!-e $fullpath) {
13300: mkdir($fullpath,0755);
1.1056 raeburn 13301: }
13302: }
1.1086 raeburn 13303: } else {
13304: last;
1.1056 raeburn 13305: }
1.1055 raeburn 13306: }
13307: }
1.1086 raeburn 13308: if ($fullpath ne '') {
13309: if (-e "$prefix$path") {
13310: system("mv $prefix$path $fullpath/$title");
13311: }
13312: if (-e "$fullpath/$title") {
13313: my $showpath;
13314: if ($relpath ne '') {
13315: $showpath = "$relpath/$title";
13316: } else {
13317: $showpath = "/$title";
13318: }
13319: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
13320: }
13321: unless ($ishome) {
13322: my $fetch = "$fullpath/$title";
13323: $fetch =~ s/^\Q$prefix$dir\E//;
13324: $prompttofetch{$fetch} = 1;
13325: }
13326: }
1.1055 raeburn 13327: }
1.1086 raeburn 13328: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13329: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
13330: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 13331: }
13332: } else {
13333: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
13334: }
13335: }
13336: if (keys(%todelete)) {
13337: foreach my $key (keys(%todelete)) {
13338: unlink($key);
1.1066 raeburn 13339: }
13340: }
13341: if (keys(%todeletedir)) {
13342: foreach my $key (keys(%todeletedir)) {
13343: rmdir($key);
13344: }
13345: }
13346: foreach my $dir (sort(keys(%is_dir))) {
13347: if (($pathtocheck ne '') && ($dir ne '')) {
13348: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13349: }
13350: }
1.1067 raeburn 13351: if ($result ne '') {
13352: $output .= '<ul>'."\n".
13353: $result."\n".
13354: '</ul>';
13355: }
13356: unless ($ishome) {
13357: my $replicationfail;
13358: foreach my $item (keys(%prompttofetch)) {
13359: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13360: unless ($fetchresult eq 'ok') {
13361: $replicationfail .= '<li>'.$item.'</li>'."\n";
13362: }
13363: }
13364: if ($replicationfail) {
13365: $output .= '<p class="LC_error">'.
13366: &mt('Course home server failed to retrieve:').'<ul>'.
13367: $replicationfail.
13368: '</ul></p>';
13369: }
13370: }
1.1055 raeburn 13371: } else {
13372: $warning = &mt('No items found in archive.');
13373: }
13374: if ($error) {
13375: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13376: $error.'</p>'."\n";
13377: }
13378: if ($warning) {
13379: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13380: }
13381: return $output;
13382: }
13383:
1.1066 raeburn 13384: sub cleanup_empty_dirs {
13385: my ($path) = @_;
13386: if (($path ne '') && (-d $path)) {
13387: if (opendir(my $dirh,$path)) {
13388: my @dircontents = grep(!/^\./,readdir($dirh));
13389: my $numitems = 0;
13390: foreach my $item (@dircontents) {
13391: if (-d "$path/$item") {
1.1111 raeburn 13392: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13393: if (-e "$path/$item") {
13394: $numitems ++;
13395: }
13396: } else {
13397: $numitems ++;
13398: }
13399: }
13400: if ($numitems == 0) {
13401: rmdir($path);
13402: }
13403: closedir($dirh);
13404: }
13405: }
13406: return;
13407: }
13408:
1.41 ng 13409: =pod
1.45 matthew 13410:
1.1162 raeburn 13411: =item * &get_folder_hierarchy()
1.1068 raeburn 13412:
13413: Provides hierarchy of names of folders/sub-folders containing the current
13414: item,
13415:
13416: Inputs: 3
13417: - $navmap - navmaps object
13418:
13419: - $map - url for map (either the trigger itself, or map containing
13420: the resource, which is the trigger).
13421:
13422: - $showitem - 1 => show title for map itself; 0 => do not show.
13423:
13424: Outputs: 1 @pathitems - array of folder/subfolder names.
13425:
13426: =cut
13427:
13428: sub get_folder_hierarchy {
13429: my ($navmap,$map,$showitem) = @_;
13430: my @pathitems;
13431: if (ref($navmap)) {
13432: my $mapres = $navmap->getResourceByUrl($map);
13433: if (ref($mapres)) {
13434: my $pcslist = $mapres->map_hierarchy();
13435: if ($pcslist ne '') {
13436: my @pcs = split(/,/,$pcslist);
13437: foreach my $pc (@pcs) {
13438: if ($pc == 1) {
1.1129 raeburn 13439: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13440: } else {
13441: my $res = $navmap->getByMapPc($pc);
13442: if (ref($res)) {
13443: my $title = $res->compTitle();
13444: $title =~ s/\W+/_/g;
13445: if ($title ne '') {
13446: push(@pathitems,$title);
13447: }
13448: }
13449: }
13450: }
13451: }
1.1071 raeburn 13452: if ($showitem) {
13453: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13454: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13455: } else {
13456: my $maptitle = $mapres->compTitle();
13457: $maptitle =~ s/\W+/_/g;
13458: if ($maptitle ne '') {
13459: push(@pathitems,$maptitle);
13460: }
1.1068 raeburn 13461: }
13462: }
13463: }
13464: }
13465: return @pathitems;
13466: }
13467:
13468: =pod
13469:
1.1015 raeburn 13470: =item * &get_turnedin_filepath()
13471:
13472: Determines path in a user's portfolio file for storage of files uploaded
13473: to a specific essayresponse or dropbox item.
13474:
13475: Inputs: 3 required + 1 optional.
13476: $symb is symb for resource, $uname and $udom are for current user (required).
13477: $caller is optional (can be "submission", if routine is called when storing
13478: an upoaded file when "Submit Answer" button was pressed).
13479:
13480: Returns array containing $path and $multiresp.
13481: $path is path in portfolio. $multiresp is 1 if this resource contains more
13482: than one file upload item. Callers of routine should append partid as a
13483: subdirectory to $path in cases where $multiresp is 1.
13484:
13485: Called by: homework/essayresponse.pm and homework/structuretags.pm
13486:
13487: =cut
13488:
13489: sub get_turnedin_filepath {
13490: my ($symb,$uname,$udom,$caller) = @_;
13491: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13492: my $turnindir;
13493: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13494: $turnindir = $userhash{'turnindir'};
13495: my ($path,$multiresp);
13496: if ($turnindir eq '') {
13497: if ($caller eq 'submission') {
13498: $turnindir = &mt('turned in');
13499: $turnindir =~ s/\W+/_/g;
13500: my %newhash = (
13501: 'turnindir' => $turnindir,
13502: );
13503: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13504: }
13505: }
13506: if ($turnindir ne '') {
13507: $path = '/'.$turnindir.'/';
13508: my ($multipart,$turnin,@pathitems);
13509: my $navmap = Apache::lonnavmaps::navmap->new();
13510: if (defined($navmap)) {
13511: my $mapres = $navmap->getResourceByUrl($map);
13512: if (ref($mapres)) {
13513: my $pcslist = $mapres->map_hierarchy();
13514: if ($pcslist ne '') {
13515: foreach my $pc (split(/,/,$pcslist)) {
13516: my $res = $navmap->getByMapPc($pc);
13517: if (ref($res)) {
13518: my $title = $res->compTitle();
13519: $title =~ s/\W+/_/g;
13520: if ($title ne '') {
1.1149 raeburn 13521: if (($pc > 1) && (length($title) > 12)) {
13522: $title = substr($title,0,12);
13523: }
1.1015 raeburn 13524: push(@pathitems,$title);
13525: }
13526: }
13527: }
13528: }
13529: my $maptitle = $mapres->compTitle();
13530: $maptitle =~ s/\W+/_/g;
13531: if ($maptitle ne '') {
1.1149 raeburn 13532: if (length($maptitle) > 12) {
13533: $maptitle = substr($maptitle,0,12);
13534: }
1.1015 raeburn 13535: push(@pathitems,$maptitle);
13536: }
13537: unless ($env{'request.state'} eq 'construct') {
13538: my $res = $navmap->getBySymb($symb);
13539: if (ref($res)) {
13540: my $partlist = $res->parts();
13541: my $totaluploads = 0;
13542: if (ref($partlist) eq 'ARRAY') {
13543: foreach my $part (@{$partlist}) {
13544: my @types = $res->responseType($part);
13545: my @ids = $res->responseIds($part);
13546: for (my $i=0; $i < scalar(@ids); $i++) {
13547: if ($types[$i] eq 'essay') {
13548: my $partid = $part.'_'.$ids[$i];
13549: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13550: $totaluploads ++;
13551: }
13552: }
13553: }
13554: }
13555: if ($totaluploads > 1) {
13556: $multiresp = 1;
13557: }
13558: }
13559: }
13560: }
13561: } else {
13562: return;
13563: }
13564: } else {
13565: return;
13566: }
13567: my $restitle=&Apache::lonnet::gettitle($symb);
13568: $restitle =~ s/\W+/_/g;
13569: if ($restitle eq '') {
13570: $restitle = ($resurl =~ m{/[^/]+$});
13571: if ($restitle eq '') {
13572: $restitle = time;
13573: }
13574: }
1.1149 raeburn 13575: if (length($restitle) > 12) {
13576: $restitle = substr($restitle,0,12);
13577: }
1.1015 raeburn 13578: push(@pathitems,$restitle);
13579: $path .= join('/',@pathitems);
13580: }
13581: return ($path,$multiresp);
13582: }
13583:
13584: =pod
13585:
1.464 albertel 13586: =back
1.41 ng 13587:
1.112 bowersj2 13588: =head1 CSV Upload/Handling functions
1.38 albertel 13589:
1.41 ng 13590: =over 4
13591:
1.648 raeburn 13592: =item * &upfile_store($r)
1.41 ng 13593:
13594: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13595: needs $env{'form.upfile'}
1.41 ng 13596: returns $datatoken to be put into hidden field
13597:
13598: =cut
1.31 albertel 13599:
13600: sub upfile_store {
13601: my $r=shift;
1.258 albertel 13602: $env{'form.upfile'}=~s/\r/\n/gs;
13603: $env{'form.upfile'}=~s/\f/\n/gs;
13604: $env{'form.upfile'}=~s/\n+/\n/gs;
13605: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13606:
1.258 albertel 13607: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
13608: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 13609: {
1.158 raeburn 13610: my $datafile = $r->dir_config('lonDaemons').
13611: '/tmp/'.$datatoken.'.tmp';
13612: if ( open(my $fh,">$datafile") ) {
1.258 albertel 13613: print $fh $env{'form.upfile'};
1.158 raeburn 13614: close($fh);
13615: }
1.31 albertel 13616: }
13617: return $datatoken;
13618: }
13619:
1.56 matthew 13620: =pod
13621:
1.648 raeburn 13622: =item * &load_tmp_file($r)
1.41 ng 13623:
13624: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 13625: needs $env{'form.datatoken'},
13626: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13627:
13628: =cut
1.31 albertel 13629:
13630: sub load_tmp_file {
13631: my $r=shift;
13632: my @studentdata=();
13633: {
1.158 raeburn 13634: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 13635: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 13636: if ( open(my $fh,"<$studentfile") ) {
13637: @studentdata=<$fh>;
13638: close($fh);
13639: }
1.31 albertel 13640: }
1.258 albertel 13641: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13642: }
13643:
1.56 matthew 13644: =pod
13645:
1.648 raeburn 13646: =item * &upfile_record_sep()
1.41 ng 13647:
13648: Separate uploaded file into records
13649: returns array of records,
1.258 albertel 13650: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13651:
13652: =cut
1.31 albertel 13653:
13654: sub upfile_record_sep {
1.258 albertel 13655: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13656: } else {
1.248 albertel 13657: my @records;
1.258 albertel 13658: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13659: if ($line=~/^\s*$/) { next; }
13660: push(@records,$line);
13661: }
13662: return @records;
1.31 albertel 13663: }
13664: }
13665:
1.56 matthew 13666: =pod
13667:
1.648 raeburn 13668: =item * &record_sep($record)
1.41 ng 13669:
1.258 albertel 13670: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13671:
13672: =cut
13673:
1.263 www 13674: sub takeleft {
13675: my $index=shift;
13676: return substr('0000'.$index,-4,4);
13677: }
13678:
1.31 albertel 13679: sub record_sep {
13680: my $record=shift;
13681: my %components=();
1.258 albertel 13682: if ($env{'form.upfiletype'} eq 'xml') {
13683: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13684: my $i=0;
1.356 albertel 13685: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13686: $field=~s/^(\"|\')//;
13687: $field=~s/(\"|\')$//;
1.263 www 13688: $components{&takeleft($i)}=$field;
1.31 albertel 13689: $i++;
13690: }
1.258 albertel 13691: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13692: my $i=0;
1.356 albertel 13693: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13694: $field=~s/^(\"|\')//;
13695: $field=~s/(\"|\')$//;
1.263 www 13696: $components{&takeleft($i)}=$field;
1.31 albertel 13697: $i++;
13698: }
13699: } else {
1.561 www 13700: my $separator=',';
1.480 banghart 13701: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13702: $separator=';';
1.480 banghart 13703: }
1.31 albertel 13704: my $i=0;
1.561 www 13705: # the character we are looking for to indicate the end of a quote or a record
13706: my $looking_for=$separator;
13707: # do not add the characters to the fields
13708: my $ignore=0;
13709: # we just encountered a separator (or the beginning of the record)
13710: my $just_found_separator=1;
13711: # store the field we are working on here
13712: my $field='';
13713: # work our way through all characters in record
13714: foreach my $character ($record=~/(.)/g) {
13715: if ($character eq $looking_for) {
13716: if ($character ne $separator) {
13717: # Found the end of a quote, again looking for separator
13718: $looking_for=$separator;
13719: $ignore=1;
13720: } else {
13721: # Found a separator, store away what we got
13722: $components{&takeleft($i)}=$field;
13723: $i++;
13724: $just_found_separator=1;
13725: $ignore=0;
13726: $field='';
13727: }
13728: next;
13729: }
13730: # single or double quotation marks after a separator indicate beginning of a quote
13731: # we are now looking for the end of the quote and need to ignore separators
13732: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13733: $looking_for=$character;
13734: next;
13735: }
13736: # ignore would be true after we reached the end of a quote
13737: if ($ignore) { next; }
13738: if (($just_found_separator) && ($character=~/\s/)) { next; }
13739: $field.=$character;
13740: $just_found_separator=0;
1.31 albertel 13741: }
1.561 www 13742: # catch the very last entry, since we never encountered the separator
13743: $components{&takeleft($i)}=$field;
1.31 albertel 13744: }
13745: return %components;
13746: }
13747:
1.144 matthew 13748: ######################################################
13749: ######################################################
13750:
1.56 matthew 13751: =pod
13752:
1.648 raeburn 13753: =item * &upfile_select_html()
1.41 ng 13754:
1.144 matthew 13755: Return HTML code to select a file from the users machine and specify
13756: the file type.
1.41 ng 13757:
13758: =cut
13759:
1.144 matthew 13760: ######################################################
13761: ######################################################
1.31 albertel 13762: sub upfile_select_html {
1.144 matthew 13763: my %Types = (
13764: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13765: semisv => &mt('Semicolon separated values'),
1.144 matthew 13766: space => &mt('Space separated'),
13767: tab => &mt('Tabulator separated'),
13768: # xml => &mt('HTML/XML'),
13769: );
13770: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13771: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13772: foreach my $type (sort(keys(%Types))) {
13773: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13774: }
13775: $Str .= "</select>\n";
13776: return $Str;
1.31 albertel 13777: }
13778:
1.301 albertel 13779: sub get_samples {
13780: my ($records,$toget) = @_;
13781: my @samples=({});
13782: my $got=0;
13783: foreach my $rec (@$records) {
13784: my %temp = &record_sep($rec);
13785: if (! grep(/\S/, values(%temp))) { next; }
13786: if (%temp) {
13787: $samples[$got]=\%temp;
13788: $got++;
13789: if ($got == $toget) { last; }
13790: }
13791: }
13792: return \@samples;
13793: }
13794:
1.144 matthew 13795: ######################################################
13796: ######################################################
13797:
1.56 matthew 13798: =pod
13799:
1.648 raeburn 13800: =item * &csv_print_samples($r,$records)
1.41 ng 13801:
13802: Prints a table of sample values from each column uploaded $r is an
13803: Apache Request ref, $records is an arrayref from
13804: &Apache::loncommon::upfile_record_sep
13805:
13806: =cut
13807:
1.144 matthew 13808: ######################################################
13809: ######################################################
1.31 albertel 13810: sub csv_print_samples {
13811: my ($r,$records) = @_;
1.662 bisitz 13812: my $samples = &get_samples($records,5);
1.301 albertel 13813:
1.594 raeburn 13814: $r->print(&mt('Samples').'<br />'.&start_data_table().
13815: &start_data_table_header_row());
1.356 albertel 13816: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13817: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13818: $r->print(&end_data_table_header_row());
1.301 albertel 13819: foreach my $hash (@$samples) {
1.594 raeburn 13820: $r->print(&start_data_table_row());
1.356 albertel 13821: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13822: $r->print('<td>');
1.356 albertel 13823: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13824: $r->print('</td>');
13825: }
1.594 raeburn 13826: $r->print(&end_data_table_row());
1.31 albertel 13827: }
1.594 raeburn 13828: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13829: }
13830:
1.144 matthew 13831: ######################################################
13832: ######################################################
13833:
1.56 matthew 13834: =pod
13835:
1.648 raeburn 13836: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13837:
13838: Prints a table to create associations between values and table columns.
1.144 matthew 13839:
1.41 ng 13840: $r is an Apache Request ref,
13841: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13842: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13843:
13844: =cut
13845:
1.144 matthew 13846: ######################################################
13847: ######################################################
1.31 albertel 13848: sub csv_print_select_table {
13849: my ($r,$records,$d) = @_;
1.301 albertel 13850: my $i=0;
13851: my $samples = &get_samples($records,1);
1.144 matthew 13852: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13853: &start_data_table().&start_data_table_header_row().
1.144 matthew 13854: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13855: '<th>'.&mt('Column').'</th>'.
13856: &end_data_table_header_row()."\n");
1.356 albertel 13857: foreach my $array_ref (@$d) {
13858: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13859: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13860:
1.875 bisitz 13861: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13862: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13863: $r->print('<option value="none"></option>');
1.356 albertel 13864: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13865: $r->print('<option value="'.$sample.'"'.
13866: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13867: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13868: }
1.594 raeburn 13869: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13870: $i++;
13871: }
1.594 raeburn 13872: $r->print(&end_data_table());
1.31 albertel 13873: $i--;
13874: return $i;
13875: }
1.56 matthew 13876:
1.144 matthew 13877: ######################################################
13878: ######################################################
13879:
1.56 matthew 13880: =pod
1.31 albertel 13881:
1.648 raeburn 13882: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13883:
13884: Prints a table of sample values from the upload and can make associate samples to internal names.
13885:
13886: $r is an Apache Request ref,
13887: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13888: $d is an array of 2 element arrays (internal name, displayed name)
13889:
13890: =cut
13891:
1.144 matthew 13892: ######################################################
13893: ######################################################
1.31 albertel 13894: sub csv_samples_select_table {
13895: my ($r,$records,$d) = @_;
13896: my $i=0;
1.144 matthew 13897: #
1.662 bisitz 13898: my $max_samples = 5;
13899: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13900: $r->print(&start_data_table().
13901: &start_data_table_header_row().'<th>'.
13902: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13903: &end_data_table_header_row());
1.301 albertel 13904:
13905: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13906: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13907: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13908: foreach my $option (@$d) {
13909: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13910: $r->print('<option value="'.$value.'"'.
1.253 albertel 13911: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13912: $display.'</option>');
1.31 albertel 13913: }
13914: $r->print('</select></td><td>');
1.662 bisitz 13915: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13916: if (defined($samples->[$line]{$key})) {
13917: $r->print($samples->[$line]{$key}."<br />\n");
13918: }
13919: }
1.594 raeburn 13920: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13921: $i++;
13922: }
1.594 raeburn 13923: $r->print(&end_data_table());
1.31 albertel 13924: $i--;
13925: return($i);
1.115 matthew 13926: }
13927:
1.144 matthew 13928: ######################################################
13929: ######################################################
13930:
1.115 matthew 13931: =pod
13932:
1.648 raeburn 13933: =item * &clean_excel_name($name)
1.115 matthew 13934:
13935: Returns a replacement for $name which does not contain any illegal characters.
13936:
13937: =cut
13938:
1.144 matthew 13939: ######################################################
13940: ######################################################
1.115 matthew 13941: sub clean_excel_name {
13942: my ($name) = @_;
13943: $name =~ s/[:\*\?\/\\]//g;
13944: if (length($name) > 31) {
13945: $name = substr($name,0,31);
13946: }
13947: return $name;
1.25 albertel 13948: }
1.84 albertel 13949:
1.85 albertel 13950: =pod
13951:
1.648 raeburn 13952: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13953:
13954: Returns either 1 or undef
13955:
13956: 1 if the part is to be hidden, undef if it is to be shown
13957:
13958: Arguments are:
13959:
13960: $id the id of the part to be checked
13961: $symb, optional the symb of the resource to check
13962: $udom, optional the domain of the user to check for
13963: $uname, optional the username of the user to check for
13964:
13965: =cut
1.84 albertel 13966:
13967: sub check_if_partid_hidden {
13968: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13969: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13970: $symb,$udom,$uname);
1.141 albertel 13971: my $truth=1;
13972: #if the string starts with !, then the list is the list to show not hide
13973: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13974: my @hiddenlist=split(/,/,$hiddenparts);
13975: foreach my $checkid (@hiddenlist) {
1.141 albertel 13976: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13977: }
1.141 albertel 13978: return !$truth;
1.84 albertel 13979: }
1.127 matthew 13980:
1.138 matthew 13981:
13982: ############################################################
13983: ############################################################
13984:
13985: =pod
13986:
1.157 matthew 13987: =back
13988:
1.138 matthew 13989: =head1 cgi-bin script and graphing routines
13990:
1.157 matthew 13991: =over 4
13992:
1.648 raeburn 13993: =item * &get_cgi_id()
1.138 matthew 13994:
13995: Inputs: none
13996:
13997: Returns an id which can be used to pass environment variables
13998: to various cgi-bin scripts. These environment variables will
13999: be removed from the users environment after a given time by
14000: the routine &Apache::lonnet::transfer_profile_to_env.
14001:
14002: =cut
14003:
14004: ############################################################
14005: ############################################################
1.152 albertel 14006: my $uniq=0;
1.136 matthew 14007: sub get_cgi_id {
1.154 albertel 14008: $uniq=($uniq+1)%100000;
1.280 albertel 14009: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14010: }
14011:
1.127 matthew 14012: ############################################################
14013: ############################################################
14014:
14015: =pod
14016:
1.648 raeburn 14017: =item * &DrawBarGraph()
1.127 matthew 14018:
1.138 matthew 14019: Facilitates the plotting of data in a (stacked) bar graph.
14020: Puts plot definition data into the users environment in order for
14021: graph.png to plot it. Returns an <img> tag for the plot.
14022: The bars on the plot are labeled '1','2',...,'n'.
14023:
14024: Inputs:
14025:
14026: =over 4
14027:
14028: =item $Title: string, the title of the plot
14029:
14030: =item $xlabel: string, text describing the X-axis of the plot
14031:
14032: =item $ylabel: string, text describing the Y-axis of the plot
14033:
14034: =item $Max: scalar, the maximum Y value to use in the plot
14035: If $Max is < any data point, the graph will not be rendered.
14036:
1.140 matthew 14037: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14038: they are plotted. If undefined, default values will be used.
14039:
1.178 matthew 14040: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14041:
1.138 matthew 14042: =item @Values: An array of array references. Each array reference holds data
14043: to be plotted in a stacked bar chart.
14044:
1.239 matthew 14045: =item If the final element of @Values is a hash reference the key/value
14046: pairs will be added to the graph definition.
14047:
1.138 matthew 14048: =back
14049:
14050: Returns:
14051:
14052: An <img> tag which references graph.png and the appropriate identifying
14053: information for the plot.
14054:
1.127 matthew 14055: =cut
14056:
14057: ############################################################
14058: ############################################################
1.134 matthew 14059: sub DrawBarGraph {
1.178 matthew 14060: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14061: #
14062: if (! defined($colors)) {
14063: $colors = ['#33ff00',
14064: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14065: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14066: ];
14067: }
1.228 matthew 14068: my $extra_settings = {};
14069: if (ref($Values[-1]) eq 'HASH') {
14070: $extra_settings = pop(@Values);
14071: }
1.127 matthew 14072: #
1.136 matthew 14073: my $identifier = &get_cgi_id();
14074: my $id = 'cgi.'.$identifier;
1.129 matthew 14075: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14076: return '';
14077: }
1.225 matthew 14078: #
14079: my @Labels;
14080: if (defined($labels)) {
14081: @Labels = @$labels;
14082: } else {
14083: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14084: push(@Labels,$i+1);
1.225 matthew 14085: }
14086: }
14087: #
1.129 matthew 14088: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14089: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14090: my %ValuesHash;
14091: my $NumSets=1;
14092: foreach my $array (@Values) {
14093: next if (! ref($array));
1.136 matthew 14094: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14095: join(',',@$array);
1.129 matthew 14096: }
1.127 matthew 14097: #
1.136 matthew 14098: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14099: if ($NumBars < 3) {
14100: $width = 120+$NumBars*32;
1.220 matthew 14101: $xskip = 1;
1.225 matthew 14102: $bar_width = 30;
14103: } elsif ($NumBars < 5) {
14104: $width = 120+$NumBars*20;
14105: $xskip = 1;
14106: $bar_width = 20;
1.220 matthew 14107: } elsif ($NumBars < 10) {
1.136 matthew 14108: $width = 120+$NumBars*15;
14109: $xskip = 1;
14110: $bar_width = 15;
14111: } elsif ($NumBars <= 25) {
14112: $width = 120+$NumBars*11;
14113: $xskip = 5;
14114: $bar_width = 8;
14115: } elsif ($NumBars <= 50) {
14116: $width = 120+$NumBars*8;
14117: $xskip = 5;
14118: $bar_width = 4;
14119: } else {
14120: $width = 120+$NumBars*8;
14121: $xskip = 5;
14122: $bar_width = 4;
14123: }
14124: #
1.137 matthew 14125: $Max = 1 if ($Max < 1);
14126: if ( int($Max) < $Max ) {
14127: $Max++;
14128: $Max = int($Max);
14129: }
1.127 matthew 14130: $Title = '' if (! defined($Title));
14131: $xlabel = '' if (! defined($xlabel));
14132: $ylabel = '' if (! defined($ylabel));
1.369 www 14133: $ValuesHash{$id.'.title'} = &escape($Title);
14134: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14135: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14136: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14137: $ValuesHash{$id.'.NumBars'} = $NumBars;
14138: $ValuesHash{$id.'.NumSets'} = $NumSets;
14139: $ValuesHash{$id.'.PlotType'} = 'bar';
14140: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14141: $ValuesHash{$id.'.height'} = $height;
14142: $ValuesHash{$id.'.width'} = $width;
14143: $ValuesHash{$id.'.xskip'} = $xskip;
14144: $ValuesHash{$id.'.bar_width'} = $bar_width;
14145: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14146: #
1.228 matthew 14147: # Deal with other parameters
14148: while (my ($key,$value) = each(%$extra_settings)) {
14149: $ValuesHash{$id.'.'.$key} = $value;
14150: }
14151: #
1.646 raeburn 14152: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14153: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14154: }
14155:
14156: ############################################################
14157: ############################################################
14158:
14159: =pod
14160:
1.648 raeburn 14161: =item * &DrawXYGraph()
1.137 matthew 14162:
1.138 matthew 14163: Facilitates the plotting of data in an XY graph.
14164: Puts plot definition data into the users environment in order for
14165: graph.png to plot it. Returns an <img> tag for the plot.
14166:
14167: Inputs:
14168:
14169: =over 4
14170:
14171: =item $Title: string, the title of the plot
14172:
14173: =item $xlabel: string, text describing the X-axis of the plot
14174:
14175: =item $ylabel: string, text describing the Y-axis of the plot
14176:
14177: =item $Max: scalar, the maximum Y value to use in the plot
14178: If $Max is < any data point, the graph will not be rendered.
14179:
14180: =item $colors: Array ref containing the hex color codes for the data to be
14181: plotted in. If undefined, default values will be used.
14182:
14183: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14184:
14185: =item $Ydata: Array ref containing Array refs.
1.185 www 14186: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14187:
14188: =item %Values: hash indicating or overriding any default values which are
14189: passed to graph.png.
14190: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14191:
14192: =back
14193:
14194: Returns:
14195:
14196: An <img> tag which references graph.png and the appropriate identifying
14197: information for the plot.
14198:
1.137 matthew 14199: =cut
14200:
14201: ############################################################
14202: ############################################################
14203: sub DrawXYGraph {
14204: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14205: #
14206: # Create the identifier for the graph
14207: my $identifier = &get_cgi_id();
14208: my $id = 'cgi.'.$identifier;
14209: #
14210: $Title = '' if (! defined($Title));
14211: $xlabel = '' if (! defined($xlabel));
14212: $ylabel = '' if (! defined($ylabel));
14213: my %ValuesHash =
14214: (
1.369 www 14215: $id.'.title' => &escape($Title),
14216: $id.'.xlabel' => &escape($xlabel),
14217: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14218: $id.'.y_max_value'=> $Max,
14219: $id.'.labels' => join(',',@$Xlabels),
14220: $id.'.PlotType' => 'XY',
14221: );
14222: #
14223: if (defined($colors) && ref($colors) eq 'ARRAY') {
14224: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14225: }
14226: #
14227: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14228: return '';
14229: }
14230: my $NumSets=1;
1.138 matthew 14231: foreach my $array (@{$Ydata}){
1.137 matthew 14232: next if (! ref($array));
14233: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14234: }
1.138 matthew 14235: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14236: #
14237: # Deal with other parameters
14238: while (my ($key,$value) = each(%Values)) {
14239: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14240: }
14241: #
1.646 raeburn 14242: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14243: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14244: }
14245:
14246: ############################################################
14247: ############################################################
14248:
14249: =pod
14250:
1.648 raeburn 14251: =item * &DrawXYYGraph()
1.138 matthew 14252:
14253: Facilitates the plotting of data in an XY graph with two Y axes.
14254: Puts plot definition data into the users environment in order for
14255: graph.png to plot it. Returns an <img> tag for the plot.
14256:
14257: Inputs:
14258:
14259: =over 4
14260:
14261: =item $Title: string, the title of the plot
14262:
14263: =item $xlabel: string, text describing the X-axis of the plot
14264:
14265: =item $ylabel: string, text describing the Y-axis of the plot
14266:
14267: =item $colors: Array ref containing the hex color codes for the data to be
14268: plotted in. If undefined, default values will be used.
14269:
14270: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14271:
14272: =item $Ydata1: The first data set
14273:
14274: =item $Min1: The minimum value of the left Y-axis
14275:
14276: =item $Max1: The maximum value of the left Y-axis
14277:
14278: =item $Ydata2: The second data set
14279:
14280: =item $Min2: The minimum value of the right Y-axis
14281:
14282: =item $Max2: The maximum value of the left Y-axis
14283:
14284: =item %Values: hash indicating or overriding any default values which are
14285: passed to graph.png.
14286: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14287:
14288: =back
14289:
14290: Returns:
14291:
14292: An <img> tag which references graph.png and the appropriate identifying
14293: information for the plot.
1.136 matthew 14294:
14295: =cut
14296:
14297: ############################################################
14298: ############################################################
1.137 matthew 14299: sub DrawXYYGraph {
14300: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14301: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14302: #
14303: # Create the identifier for the graph
14304: my $identifier = &get_cgi_id();
14305: my $id = 'cgi.'.$identifier;
14306: #
14307: $Title = '' if (! defined($Title));
14308: $xlabel = '' if (! defined($xlabel));
14309: $ylabel = '' if (! defined($ylabel));
14310: my %ValuesHash =
14311: (
1.369 www 14312: $id.'.title' => &escape($Title),
14313: $id.'.xlabel' => &escape($xlabel),
14314: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14315: $id.'.labels' => join(',',@$Xlabels),
14316: $id.'.PlotType' => 'XY',
14317: $id.'.NumSets' => 2,
1.137 matthew 14318: $id.'.two_axes' => 1,
14319: $id.'.y1_max_value' => $Max1,
14320: $id.'.y1_min_value' => $Min1,
14321: $id.'.y2_max_value' => $Max2,
14322: $id.'.y2_min_value' => $Min2,
1.136 matthew 14323: );
14324: #
1.137 matthew 14325: if (defined($colors) && ref($colors) eq 'ARRAY') {
14326: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14327: }
14328: #
14329: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14330: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14331: return '';
14332: }
14333: my $NumSets=1;
1.137 matthew 14334: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14335: next if (! ref($array));
14336: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14337: }
14338: #
14339: # Deal with other parameters
14340: while (my ($key,$value) = each(%Values)) {
14341: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14342: }
14343: #
1.646 raeburn 14344: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14345: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14346: }
14347:
14348: ############################################################
14349: ############################################################
14350:
14351: =pod
14352:
1.157 matthew 14353: =back
14354:
1.139 matthew 14355: =head1 Statistics helper routines?
14356:
14357: Bad place for them but what the hell.
14358:
1.157 matthew 14359: =over 4
14360:
1.648 raeburn 14361: =item * &chartlink()
1.139 matthew 14362:
14363: Returns a link to the chart for a specific student.
14364:
14365: Inputs:
14366:
14367: =over 4
14368:
14369: =item $linktext: The text of the link
14370:
14371: =item $sname: The students username
14372:
14373: =item $sdomain: The students domain
14374:
14375: =back
14376:
1.157 matthew 14377: =back
14378:
1.139 matthew 14379: =cut
14380:
14381: ############################################################
14382: ############################################################
14383: sub chartlink {
14384: my ($linktext, $sname, $sdomain) = @_;
14385: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14386: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14387: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14388: '">'.$linktext.'</a>';
1.153 matthew 14389: }
14390:
14391: #######################################################
14392: #######################################################
14393:
14394: =pod
14395:
14396: =head1 Course Environment Routines
1.157 matthew 14397:
14398: =over 4
1.153 matthew 14399:
1.648 raeburn 14400: =item * &restore_course_settings()
1.153 matthew 14401:
1.648 raeburn 14402: =item * &store_course_settings()
1.153 matthew 14403:
14404: Restores/Store indicated form parameters from the course environment.
14405: Will not overwrite existing values of the form parameters.
14406:
14407: Inputs:
14408: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14409:
14410: a hash ref describing the data to be stored. For example:
14411:
14412: %Save_Parameters = ('Status' => 'scalar',
14413: 'chartoutputmode' => 'scalar',
14414: 'chartoutputdata' => 'scalar',
14415: 'Section' => 'array',
1.373 raeburn 14416: 'Group' => 'array',
1.153 matthew 14417: 'StudentData' => 'array',
14418: 'Maps' => 'array');
14419:
14420: Returns: both routines return nothing
14421:
1.631 raeburn 14422: =back
14423:
1.153 matthew 14424: =cut
14425:
14426: #######################################################
14427: #######################################################
14428: sub store_course_settings {
1.496 albertel 14429: return &store_settings($env{'request.course.id'},@_);
14430: }
14431:
14432: sub store_settings {
1.153 matthew 14433: # save to the environment
14434: # appenv the same items, just to be safe
1.300 albertel 14435: my $udom = $env{'user.domain'};
14436: my $uname = $env{'user.name'};
1.496 albertel 14437: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14438: my %SaveHash;
14439: my %AppHash;
14440: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14441: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14442: my $envname = 'environment.'.$basename;
1.258 albertel 14443: if (exists($env{'form.'.$setting})) {
1.153 matthew 14444: # Save this value away
14445: if ($type eq 'scalar' &&
1.258 albertel 14446: (! exists($env{$envname}) ||
14447: $env{$envname} ne $env{'form.'.$setting})) {
14448: $SaveHash{$basename} = $env{'form.'.$setting};
14449: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14450: } elsif ($type eq 'array') {
14451: my $stored_form;
1.258 albertel 14452: if (ref($env{'form.'.$setting})) {
1.153 matthew 14453: $stored_form = join(',',
14454: map {
1.369 www 14455: &escape($_);
1.258 albertel 14456: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14457: } else {
14458: $stored_form =
1.369 www 14459: &escape($env{'form.'.$setting});
1.153 matthew 14460: }
14461: # Determine if the array contents are the same.
1.258 albertel 14462: if ($stored_form ne $env{$envname}) {
1.153 matthew 14463: $SaveHash{$basename} = $stored_form;
14464: $AppHash{$envname} = $stored_form;
14465: }
14466: }
14467: }
14468: }
14469: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14470: $udom,$uname);
1.153 matthew 14471: if ($put_result !~ /^(ok|delayed)/) {
14472: &Apache::lonnet::logthis('unable to save form parameters, '.
14473: 'got error:'.$put_result);
14474: }
14475: # Make sure these settings stick around in this session, too
1.646 raeburn 14476: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14477: return;
14478: }
14479:
14480: sub restore_course_settings {
1.499 albertel 14481: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14482: }
14483:
14484: sub restore_settings {
14485: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14486: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14487: next if (exists($env{'form.'.$setting}));
1.496 albertel 14488: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14489: '.'.$setting;
1.258 albertel 14490: if (exists($env{$envname})) {
1.153 matthew 14491: if ($type eq 'scalar') {
1.258 albertel 14492: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14493: } elsif ($type eq 'array') {
1.258 albertel 14494: $env{'form.'.$setting} = [
1.153 matthew 14495: map {
1.369 www 14496: &unescape($_);
1.258 albertel 14497: } split(',',$env{$envname})
1.153 matthew 14498: ];
14499: }
14500: }
14501: }
1.127 matthew 14502: }
14503:
1.618 raeburn 14504: #######################################################
14505: #######################################################
14506:
14507: =pod
14508:
14509: =head1 Domain E-mail Routines
14510:
14511: =over 4
14512:
1.648 raeburn 14513: =item * &build_recipient_list()
1.618 raeburn 14514:
1.1144 raeburn 14515: Build recipient lists for following types of e-mail:
1.766 raeburn 14516: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14517: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14518: module change checking, student/employee ID conflict checks, as
14519: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14520: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14521:
14522: Inputs:
1.619 raeburn 14523: defmail (scalar - email address of default recipient),
1.1144 raeburn 14524: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14525: requestsmail, updatesmail, or idconflictsmail).
14526:
1.619 raeburn 14527: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14528:
1.619 raeburn 14529: origmail (scalar - email address of recipient from loncapa.conf,
14530: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14531:
1.655 raeburn 14532: Returns: comma separated list of addresses to which to send e-mail.
14533:
14534: =back
1.618 raeburn 14535:
14536: =cut
14537:
14538: ############################################################
14539: ############################################################
14540: sub build_recipient_list {
1.619 raeburn 14541: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 14542: my @recipients;
1.1270 raeburn 14543: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14544: my %domconfig =
1.1270 raeburn 14545: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14546: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14547: if (exists($domconfig{'contacts'}{$mailing})) {
14548: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14549: my @contacts = ('adminemail','supportemail');
14550: foreach my $item (@contacts) {
14551: if ($domconfig{'contacts'}{$mailing}{$item}) {
14552: my $addr = $domconfig{'contacts'}{$item};
14553: if (!grep(/^\Q$addr\E$/,@recipients)) {
14554: push(@recipients,$addr);
14555: }
1.619 raeburn 14556: }
1.1270 raeburn 14557: }
14558: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14559: if ($mailing eq 'helpdeskmail') {
14560: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14561: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14562: my @ok_bccs;
14563: foreach my $bcc (@bccs) {
14564: $bcc =~ s/^\s+//g;
14565: $bcc =~ s/\s+$//g;
14566: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14567: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14568: push(@ok_bccs,$bcc);
14569: }
14570: }
14571: }
14572: if (@ok_bccs > 0) {
14573: $allbcc = join(', ',@ok_bccs);
14574: }
14575: }
14576: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14577: }
14578: }
1.766 raeburn 14579: } elsif ($origmail ne '') {
1.1270 raeburn 14580: $lastresort = $origmail;
1.618 raeburn 14581: }
1.619 raeburn 14582: } elsif ($origmail ne '') {
1.1270 raeburn 14583: $lastresort = $origmail;
14584: }
14585:
14586: if (($mailing eq 'helpdesk') && ($lastresort ne '')) {
14587: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14588: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14589: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14590: my %what = (
14591: perlvar => 1,
14592: );
14593: my $primary = &Apache::lonnet::domain($defdom,'primary');
14594: if ($primary) {
14595: my $gotaddr;
14596: my ($result,$returnhash) =
14597: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14598: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14599: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14600: $lastresort = $returnhash->{'lonSupportEMail'};
14601: $gotaddr = 1;
14602: }
14603: }
14604: unless ($gotaddr) {
14605: my $uintdom = &Apache::lonnet::internet_dom($primary);
14606: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14607: unless ($uintdom eq $intdom) {
14608: my %domconfig =
14609: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14610: if (ref($domconfig{'contacts'}) eq 'HASH') {
14611: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14612: my @contacts = ('adminemail','supportemail');
14613: foreach my $item (@contacts) {
14614: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14615: my $addr = $domconfig{'contacts'}{$item};
14616: if (!grep(/^\Q$addr\E$/,@recipients)) {
14617: push(@recipients,$addr);
14618: }
14619: }
14620: }
14621: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14622: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14623: }
14624: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14625: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14626: my @ok_bccs;
14627: foreach my $bcc (@bccs) {
14628: $bcc =~ s/^\s+//g;
14629: $bcc =~ s/\s+$//g;
14630: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14631: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14632: push(@ok_bccs,$bcc);
14633: }
14634: }
14635: }
14636: if (@ok_bccs > 0) {
14637: $allbcc = join(', ',@ok_bccs);
14638: }
14639: }
14640: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14641: }
14642: }
14643: }
14644: }
14645: }
14646: }
1.618 raeburn 14647: }
1.688 raeburn 14648: if (defined($defmail)) {
14649: if ($defmail ne '') {
14650: push(@recipients,$defmail);
14651: }
1.618 raeburn 14652: }
14653: if ($otheremails) {
1.619 raeburn 14654: my @others;
14655: if ($otheremails =~ /,/) {
14656: @others = split(/,/,$otheremails);
1.618 raeburn 14657: } else {
1.619 raeburn 14658: push(@others,$otheremails);
14659: }
14660: foreach my $addr (@others) {
14661: if (!grep(/^\Q$addr\E$/,@recipients)) {
14662: push(@recipients,$addr);
14663: }
1.618 raeburn 14664: }
14665: }
1.1270 raeburn 14666: if ($mailing eq 'helpdesk') {
14667: if ((!@recipients) && ($lastresort ne '')) {
14668: push(@recipients,$lastresort);
14669: }
14670: } elsif ($lastresort ne '') {
14671: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14672: push(@recipients,$lastresort);
14673: }
14674: }
1.1271 raeburn 14675: my $recipientlist = join(',',@recipients);
1.1270 raeburn 14676: if (wantarray) {
14677: return ($recipientlist,$allbcc,$addtext);
14678: } else {
14679: return $recipientlist;
14680: }
1.618 raeburn 14681: }
14682:
1.127 matthew 14683: ############################################################
14684: ############################################################
1.154 albertel 14685:
1.655 raeburn 14686: =pod
14687:
1.1224 musolffc 14688: =over 4
14689:
1.1223 musolffc 14690: =item * &mime_email()
14691:
14692: Sends an email with a possible attachment
14693:
14694: Inputs:
14695:
14696: =over 4
14697:
14698: from - Sender's email address
14699:
14700: to - Email address of recipient
14701:
14702: subject - Subject of email
14703:
14704: body - Body of email
14705:
14706: cc_string - Carbon copy email address
14707:
14708: bcc - Blind carbon copy email address
14709:
14710: type - File type of attachment
14711:
14712: attachment_path - Path of file to be attached
14713:
14714: file_name - Name of file to be attached
14715:
14716: attachment_text - The body of an attachment of type "TEXT"
14717:
14718: =back
14719:
14720: =back
14721:
14722: =cut
14723:
14724: ############################################################
14725: ############################################################
14726:
14727: sub mime_email {
14728: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
14729: $file_name, $attachment_text) = @_;
14730: my $msg = MIME::Lite->new(
14731: From => $from,
14732: To => $to,
14733: Subject => $subject,
14734: Type =>'TEXT',
14735: Data => $body,
14736: );
14737: if ($cc_string ne '') {
14738: $msg->add("Cc" => $cc_string);
14739: }
14740: if ($bcc ne '') {
14741: $msg->add("Bcc" => $bcc);
14742: }
14743: $msg->attr("content-type" => "text/plain");
14744: $msg->attr("content-type.charset" => "UTF-8");
14745: # Attach file if given
14746: if ($attachment_path) {
14747: unless ($file_name) {
14748: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
14749: }
14750: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
14751: $msg->attach(Type => $type,
14752: Path => $attachment_path,
14753: Filename => $file_name
14754: );
14755: # Otherwise attach text if given
14756: } elsif ($attachment_text) {
14757: $msg->attach(Type => 'TEXT',
14758: Data => $attachment_text);
14759: }
14760: # Send it
14761: $msg->send('sendmail');
14762: }
14763:
14764: ############################################################
14765: ############################################################
14766:
14767: =pod
14768:
1.655 raeburn 14769: =head1 Course Catalog Routines
14770:
14771: =over 4
14772:
14773: =item * &gather_categories()
14774:
14775: Converts category definitions - keys of categories hash stored in
14776: coursecategories in configuration.db on the primary library server in a
14777: domain - to an array. Also generates javascript and idx hash used to
14778: generate Domain Coordinator interface for editing Course Categories.
14779:
14780: Inputs:
1.663 raeburn 14781:
1.655 raeburn 14782: categories (reference to hash of category definitions).
1.663 raeburn 14783:
1.655 raeburn 14784: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14785: categories and subcategories).
1.663 raeburn 14786:
1.655 raeburn 14787: idx (reference to hash of counters used in Domain Coordinator interface for
14788: editing Course Categories).
1.663 raeburn 14789:
1.655 raeburn 14790: jsarray (reference to array of categories used to create Javascript arrays for
14791: Domain Coordinator interface for editing Course Categories).
14792:
14793: Returns: nothing
14794:
14795: Side effects: populates cats, idx and jsarray.
14796:
14797: =cut
14798:
14799: sub gather_categories {
14800: my ($categories,$cats,$idx,$jsarray) = @_;
14801: my %counters;
14802: my $num = 0;
14803: foreach my $item (keys(%{$categories})) {
14804: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14805: if ($container eq '' && $depth == 0) {
14806: $cats->[$depth][$categories->{$item}] = $cat;
14807: } else {
14808: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14809: }
14810: my ($escitem,$tail) = split(/:/,$item,2);
14811: if ($counters{$tail} eq '') {
14812: $counters{$tail} = $num;
14813: $num ++;
14814: }
14815: if (ref($idx) eq 'HASH') {
14816: $idx->{$item} = $counters{$tail};
14817: }
14818: if (ref($jsarray) eq 'ARRAY') {
14819: push(@{$jsarray->[$counters{$tail}]},$item);
14820: }
14821: }
14822: return;
14823: }
14824:
14825: =pod
14826:
14827: =item * &extract_categories()
14828:
14829: Used to generate breadcrumb trails for course categories.
14830:
14831: Inputs:
1.663 raeburn 14832:
1.655 raeburn 14833: categories (reference to hash of category definitions).
1.663 raeburn 14834:
1.655 raeburn 14835: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14836: categories and subcategories).
1.663 raeburn 14837:
1.655 raeburn 14838: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14839:
1.655 raeburn 14840: allitems (reference to hash - key is category key
14841: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14842:
1.655 raeburn 14843: idx (reference to hash of counters used in Domain Coordinator interface for
14844: editing Course Categories).
1.663 raeburn 14845:
1.655 raeburn 14846: jsarray (reference to array of categories used to create Javascript arrays for
14847: Domain Coordinator interface for editing Course Categories).
14848:
1.665 raeburn 14849: subcats (reference to hash of arrays containing all subcategories within each
14850: category, -recursive)
14851:
1.655 raeburn 14852: Returns: nothing
14853:
14854: Side effects: populates trails and allitems hash references.
14855:
14856: =cut
14857:
14858: sub extract_categories {
1.665 raeburn 14859: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 14860: if (ref($categories) eq 'HASH') {
14861: &gather_categories($categories,$cats,$idx,$jsarray);
14862: if (ref($cats->[0]) eq 'ARRAY') {
14863: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14864: my $name = $cats->[0][$i];
14865: my $item = &escape($name).'::0';
14866: my $trailstr;
14867: if ($name eq 'instcode') {
14868: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14869: } elsif ($name eq 'communities') {
14870: $trailstr = &mt('Communities');
1.1239 raeburn 14871: } elsif ($name eq 'placement') {
14872: $trailstr = &mt('Placement Tests');
1.655 raeburn 14873: } else {
14874: $trailstr = $name;
14875: }
14876: if ($allitems->{$item} eq '') {
14877: push(@{$trails},$trailstr);
14878: $allitems->{$item} = scalar(@{$trails})-1;
14879: }
14880: my @parents = ($name);
14881: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14882: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14883: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14884: if (ref($subcats) eq 'HASH') {
14885: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14886: }
14887: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
14888: }
14889: } else {
14890: if (ref($subcats) eq 'HASH') {
14891: $subcats->{$item} = [];
1.655 raeburn 14892: }
14893: }
14894: }
14895: }
14896: }
14897: return;
14898: }
14899:
14900: =pod
14901:
1.1162 raeburn 14902: =item * &recurse_categories()
1.655 raeburn 14903:
14904: Recursively used to generate breadcrumb trails for course categories.
14905:
14906: Inputs:
1.663 raeburn 14907:
1.655 raeburn 14908: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14909: categories and subcategories).
1.663 raeburn 14910:
1.655 raeburn 14911: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14912:
14913: category (current course category, for which breadcrumb trail is being generated).
14914:
14915: trails (reference to array of breadcrumb trails for each category).
14916:
1.655 raeburn 14917: allitems (reference to hash - key is category key
14918: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14919:
1.655 raeburn 14920: parents (array containing containers directories for current category,
14921: back to top level).
14922:
14923: Returns: nothing
14924:
14925: Side effects: populates trails and allitems hash references
14926:
14927: =cut
14928:
14929: sub recurse_categories {
1.665 raeburn 14930: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 14931: my $shallower = $depth - 1;
14932: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14933: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14934: my $name = $cats->[$depth]{$category}[$k];
14935: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14936: my $trailstr = join(' -> ',(@{$parents},$category));
14937: if ($allitems->{$item} eq '') {
14938: push(@{$trails},$trailstr);
14939: $allitems->{$item} = scalar(@{$trails})-1;
14940: }
14941: my $deeper = $depth+1;
14942: push(@{$parents},$category);
1.665 raeburn 14943: if (ref($subcats) eq 'HASH') {
14944: my $subcat = &escape($name).':'.$category.':'.$depth;
14945: for (my $j=@{$parents}; $j>=0; $j--) {
14946: my $higher;
14947: if ($j > 0) {
14948: $higher = &escape($parents->[$j]).':'.
14949: &escape($parents->[$j-1]).':'.$j;
14950: } else {
14951: $higher = &escape($parents->[$j]).'::'.$j;
14952: }
14953: push(@{$subcats->{$higher}},$subcat);
14954: }
14955: }
14956: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
14957: $subcats);
1.655 raeburn 14958: pop(@{$parents});
14959: }
14960: } else {
14961: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14962: my $trailstr = join(' -> ',(@{$parents},$category));
14963: if ($allitems->{$item} eq '') {
14964: push(@{$trails},$trailstr);
14965: $allitems->{$item} = scalar(@{$trails})-1;
14966: }
14967: }
14968: return;
14969: }
14970:
1.663 raeburn 14971: =pod
14972:
1.1162 raeburn 14973: =item * &assign_categories_table()
1.663 raeburn 14974:
14975: Create a datatable for display of hierarchical categories in a domain,
14976: with checkboxes to allow a course to be categorized.
14977:
14978: Inputs:
14979:
14980: cathash - reference to hash of categories defined for the domain (from
14981: configuration.db)
14982:
14983: currcat - scalar with an & separated list of categories assigned to a course.
14984:
1.919 raeburn 14985: type - scalar contains course type (Course or Community).
14986:
1.1260 raeburn 14987: disabled - scalar (optional) contains disabled="disabled" if input elements are
14988: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14989:
1.663 raeburn 14990: Returns: $output (markup to be displayed)
14991:
14992: =cut
14993:
14994: sub assign_categories_table {
1.1259 raeburn 14995: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 14996: my $output;
14997: if (ref($cathash) eq 'HASH') {
14998: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
14999: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
15000: $maxdepth = scalar(@cats);
15001: if (@cats > 0) {
15002: my $itemcount = 0;
15003: if (ref($cats[0]) eq 'ARRAY') {
15004: my @currcategories;
15005: if ($currcat ne '') {
15006: @currcategories = split('&',$currcat);
15007: }
1.919 raeburn 15008: my $table;
1.663 raeburn 15009: for (my $i=0; $i<@{$cats[0]}; $i++) {
15010: my $parent = $cats[0][$i];
1.919 raeburn 15011: next if ($parent eq 'instcode');
15012: if ($type eq 'Community') {
15013: next unless ($parent eq 'communities');
1.1239 raeburn 15014: } elsif ($type eq 'Placement') {
15015: next unless ($parent eq 'placement');
1.919 raeburn 15016: } else {
1.1239 raeburn 15017: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15018: }
1.663 raeburn 15019: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15020: my $item = &escape($parent).'::0';
15021: my $checked = '';
15022: if (@currcategories > 0) {
15023: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15024: $checked = ' checked="checked"';
1.663 raeburn 15025: }
15026: }
1.919 raeburn 15027: my $parent_title = $parent;
15028: if ($parent eq 'communities') {
15029: $parent_title = &mt('Communities');
1.1239 raeburn 15030: } elsif ($parent eq 'placement') {
15031: $parent_title = &mt('Placement Tests');
1.919 raeburn 15032: }
15033: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15034: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15035: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15036: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15037: my $depth = 1;
15038: push(@path,$parent);
1.1259 raeburn 15039: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15040: pop(@path);
1.919 raeburn 15041: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15042: $itemcount ++;
15043: }
1.919 raeburn 15044: if ($itemcount) {
15045: $output = &Apache::loncommon::start_data_table().
15046: $table.
15047: &Apache::loncommon::end_data_table();
15048: }
1.663 raeburn 15049: }
15050: }
15051: }
15052: return $output;
15053: }
15054:
15055: =pod
15056:
1.1162 raeburn 15057: =item * &assign_category_rows()
1.663 raeburn 15058:
15059: Create a datatable row for display of nested categories in a domain,
15060: with checkboxes to allow a course to be categorized,called recursively.
15061:
15062: Inputs:
15063:
15064: itemcount - track row number for alternating colors
15065:
15066: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15067: categories and subcategories.
15068:
15069: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15070:
15071: parent - parent of current category item
15072:
15073: path - Array containing all categories back up through the hierarchy from the
15074: current category to the top level.
15075:
15076: currcategories - reference to array of current categories assigned to the course
15077:
1.1260 raeburn 15078: disabled - scalar (optional) contains disabled="disabled" if input elements are
15079: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15080:
1.663 raeburn 15081: Returns: $output (markup to be displayed).
15082:
15083: =cut
15084:
15085: sub assign_category_rows {
1.1259 raeburn 15086: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15087: my ($text,$name,$item,$chgstr);
15088: if (ref($cats) eq 'ARRAY') {
15089: my $maxdepth = scalar(@{$cats});
15090: if (ref($cats->[$depth]) eq 'HASH') {
15091: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15092: my $numchildren = @{$cats->[$depth]{$parent}};
15093: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 15094: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15095: for (my $j=0; $j<$numchildren; $j++) {
15096: $name = $cats->[$depth]{$parent}[$j];
15097: $item = &escape($name).':'.&escape($parent).':'.$depth;
15098: my $deeper = $depth+1;
15099: my $checked = '';
15100: if (ref($currcategories) eq 'ARRAY') {
15101: if (@{$currcategories} > 0) {
15102: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15103: $checked = ' checked="checked"';
1.663 raeburn 15104: }
15105: }
15106: }
1.664 raeburn 15107: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15108: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15109: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15110: '<input type="hidden" name="catname" value="'.$name.'" />'.
15111: '</td><td>';
1.663 raeburn 15112: if (ref($path) eq 'ARRAY') {
15113: push(@{$path},$name);
1.1259 raeburn 15114: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15115: pop(@{$path});
15116: }
15117: $text .= '</td></tr>';
15118: }
15119: $text .= '</table></td>';
15120: }
15121: }
15122: }
15123: return $text;
15124: }
15125:
1.1181 raeburn 15126: =pod
15127:
15128: =back
15129:
15130: =cut
15131:
1.655 raeburn 15132: ############################################################
15133: ############################################################
15134:
15135:
1.443 albertel 15136: sub commit_customrole {
1.664 raeburn 15137: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15138: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15139: ($start?', '.&mt('starting').' '.localtime($start):'').
15140: ($end?', ending '.localtime($end):'').': <b>'.
15141: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15142: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15143: '</b><br />';
15144: return $output;
15145: }
15146:
15147: sub commit_standardrole {
1.1116 raeburn 15148: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15149: my ($output,$logmsg,$linefeed);
15150: if ($context eq 'auto') {
15151: $linefeed = "\n";
15152: } else {
15153: $linefeed = "<br />\n";
15154: }
1.443 albertel 15155: if ($three eq 'st') {
1.541 raeburn 15156: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 15157: $one,$two,$sec,$context,$credits);
1.541 raeburn 15158: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15159: ($result eq 'unknown_course') || ($result eq 'refused')) {
15160: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15161: } else {
1.541 raeburn 15162: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15163: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15164: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15165: if ($context eq 'auto') {
15166: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15167: } else {
15168: $output .= '<b>'.$result.'</b>'.$linefeed.
15169: &mt('Add to classlist').': <b>ok</b>';
15170: }
15171: $output .= $linefeed;
1.443 albertel 15172: }
15173: } else {
15174: $output = &mt('Assigning').' '.$three.' in '.$url.
15175: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15176: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15177: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15178: if ($context eq 'auto') {
15179: $output .= $result.$linefeed;
15180: } else {
15181: $output .= '<b>'.$result.'</b>'.$linefeed;
15182: }
1.443 albertel 15183: }
15184: return $output;
15185: }
15186:
15187: sub commit_studentrole {
1.1116 raeburn 15188: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15189: $credits) = @_;
1.626 raeburn 15190: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15191: if ($context eq 'auto') {
15192: $linefeed = "\n";
15193: } else {
15194: $linefeed = '<br />'."\n";
15195: }
1.443 albertel 15196: if (defined($one) && defined($two)) {
15197: my $cid=$one.'_'.$two;
15198: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15199: my $secchange = 0;
15200: my $expire_role_result;
15201: my $modify_section_result;
1.628 raeburn 15202: if ($oldsec ne '-1') {
15203: if ($oldsec ne $sec) {
1.443 albertel 15204: $secchange = 1;
1.628 raeburn 15205: my $now = time;
1.443 albertel 15206: my $uurl='/'.$cid;
15207: $uurl=~s/\_/\//g;
15208: if ($oldsec) {
15209: $uurl.='/'.$oldsec;
15210: }
1.626 raeburn 15211: $oldsecurl = $uurl;
1.628 raeburn 15212: $expire_role_result =
1.652 raeburn 15213: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15214: if ($env{'request.course.sec'} ne '') {
15215: if ($expire_role_result eq 'refused') {
15216: my @roles = ('st');
15217: my @statuses = ('previous');
15218: my @roledoms = ($one);
15219: my $withsec = 1;
15220: my %roleshash =
15221: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15222: \@statuses,\@roles,\@roledoms,$withsec);
15223: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15224: my ($oldstart,$oldend) =
15225: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15226: if ($oldend > 0 && $oldend <= $now) {
15227: $expire_role_result = 'ok';
15228: }
15229: }
15230: }
15231: }
1.443 albertel 15232: $result = $expire_role_result;
15233: }
15234: }
15235: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15236: $modify_section_result =
15237: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15238: undef,undef,undef,$sec,
15239: $end,$start,'','',$cid,
15240: '',$context,$credits);
1.443 albertel 15241: if ($modify_section_result =~ /^ok/) {
15242: if ($secchange == 1) {
1.628 raeburn 15243: if ($sec eq '') {
15244: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15245: } else {
15246: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15247: }
1.443 albertel 15248: } elsif ($oldsec eq '-1') {
1.628 raeburn 15249: if ($sec eq '') {
15250: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15251: } else {
15252: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15253: }
1.443 albertel 15254: } else {
1.628 raeburn 15255: if ($sec eq '') {
15256: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15257: } else {
15258: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15259: }
1.443 albertel 15260: }
15261: } else {
1.1115 raeburn 15262: if ($secchange) {
1.628 raeburn 15263: $$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;
15264: } else {
15265: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15266: }
1.443 albertel 15267: }
15268: $result = $modify_section_result;
15269: } elsif ($secchange == 1) {
1.628 raeburn 15270: if ($oldsec eq '') {
1.1103 raeburn 15271: $$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 15272: } else {
15273: $$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;
15274: }
1.626 raeburn 15275: if ($expire_role_result eq 'refused') {
15276: my $newsecurl = '/'.$cid;
15277: $newsecurl =~ s/\_/\//g;
15278: if ($sec ne '') {
15279: $newsecurl.='/'.$sec;
15280: }
15281: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15282: if ($sec eq '') {
15283: $$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;
15284: } else {
15285: $$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;
15286: }
15287: }
15288: }
1.443 albertel 15289: }
15290: } else {
1.626 raeburn 15291: $$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 15292: $result = "error: incomplete course id\n";
15293: }
15294: return $result;
15295: }
15296:
1.1108 raeburn 15297: sub show_role_extent {
15298: my ($scope,$context,$role) = @_;
15299: $scope =~ s{^/}{};
15300: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15301: push(@courseroles,'co');
15302: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15303: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15304: $scope =~ s{/}{_};
15305: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15306: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15307: my ($audom,$auname) = split(/\//,$scope);
15308: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15309: &Apache::loncommon::plainname($auname,$audom).'</span>');
15310: } else {
15311: $scope =~ s{/$}{};
15312: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15313: &Apache::lonnet::domain($scope,'description').'</span>');
15314: }
15315: }
15316:
1.443 albertel 15317: ############################################################
15318: ############################################################
15319:
1.566 albertel 15320: sub check_clone {
1.578 raeburn 15321: my ($args,$linefeed) = @_;
1.566 albertel 15322: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15323: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15324: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15325: my $clonemsg;
15326: my $can_clone = 0;
1.944 raeburn 15327: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15328: if ($lctype ne 'community') {
15329: $lctype = 'course';
15330: }
1.566 albertel 15331: if ($clonehome eq 'no_host') {
1.944 raeburn 15332: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15333: $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'});
15334: } else {
15335: $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'});
15336: }
1.566 albertel 15337: } else {
15338: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15339: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15340: if ($clonedesc{'type'} ne 'Community') {
1.1262 raeburn 15341: $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 15342: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15343: }
15344: }
1.1262 raeburn 15345: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15346: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15347: $can_clone = 1;
15348: } else {
1.1221 raeburn 15349: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15350: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 15351: if ($clonehash{'cloners'} eq '') {
15352: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15353: if ($domdefs{'canclone'}) {
15354: unless ($domdefs{'canclone'} eq 'none') {
15355: if ($domdefs{'canclone'} eq 'domain') {
15356: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15357: $can_clone = 1;
15358: }
15359: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15360: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15361: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15362: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15363: $can_clone = 1;
15364: }
15365: }
15366: }
15367: }
1.578 raeburn 15368: } else {
1.1221 raeburn 15369: my @cloners = split(/,/,$clonehash{'cloners'});
15370: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15371: $can_clone = 1;
1.1221 raeburn 15372: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15373: $can_clone = 1;
1.1225 raeburn 15374: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15375: $can_clone = 1;
1.1221 raeburn 15376: }
15377: unless ($can_clone) {
1.1225 raeburn 15378: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15379: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 15380: my (%gotdomdefaults,%gotcodedefaults);
15381: foreach my $cloner (@cloners) {
15382: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15383: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15384: my (%codedefaults,@code_order);
15385: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15386: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15387: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15388: }
15389: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15390: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15391: }
15392: } else {
15393: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15394: \%codedefaults,
15395: \@code_order);
15396: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15397: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15398: }
15399: if (@code_order > 0) {
15400: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15401: $cloner,$clonehash{'internal.coursecode'},
15402: $args->{'crscode'})) {
15403: $can_clone = 1;
15404: last;
15405: }
15406: }
15407: }
15408: }
15409: }
1.1225 raeburn 15410: }
15411: }
15412: unless ($can_clone) {
15413: my $ccrole = 'cc';
15414: if ($args->{'crstype'} eq 'Community') {
15415: $ccrole = 'co';
15416: }
15417: my %roleshash =
15418: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15419: $args->{'ccdomain'},
15420: 'userroles',['active'],[$ccrole],
15421: [$args->{'clonedomain'}]);
15422: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15423: $can_clone = 1;
15424: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15425: $args->{'ccuname'},$args->{'ccdomain'})) {
15426: $can_clone = 1;
1.1221 raeburn 15427: }
15428: }
15429: unless ($can_clone) {
15430: if ($args->{'crstype'} eq 'Community') {
15431: $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 15432: } else {
1.1221 raeburn 15433: $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'});
15434: }
1.566 albertel 15435: }
1.578 raeburn 15436: }
1.566 albertel 15437: }
15438: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15439: }
15440:
1.444 albertel 15441: sub construct_course {
1.1262 raeburn 15442: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15443: $cnum,$category,$coderef) = @_;
1.444 albertel 15444: my $outcome;
1.541 raeburn 15445: my $linefeed = '<br />'."\n";
15446: if ($context eq 'auto') {
15447: $linefeed = "\n";
15448: }
1.566 albertel 15449:
15450: #
15451: # Are we cloning?
15452: #
15453: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15454: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15455: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15456: if ($context ne 'auto') {
1.578 raeburn 15457: if ($clonemsg ne '') {
15458: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15459: }
1.566 albertel 15460: }
15461: $outcome .= $clonemsg.$linefeed;
15462:
15463: if (!$can_clone) {
15464: return (0,$outcome);
15465: }
15466: }
15467:
1.444 albertel 15468: #
15469: # Open course
15470: #
1.1239 raeburn 15471: my $showncrstype;
15472: if ($args->{'crstype'} eq 'Placement') {
15473: $showncrstype = 'placement test';
15474: } else {
15475: $showncrstype = lc($args->{'crstype'});
15476: }
1.444 albertel 15477: my %cenv=();
15478: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15479: $args->{'cdescr'},
15480: $args->{'curl'},
15481: $args->{'course_home'},
15482: $args->{'nonstandard'},
15483: $args->{'crscode'},
15484: $args->{'ccuname'}.':'.
15485: $args->{'ccdomain'},
1.882 raeburn 15486: $args->{'crstype'},
1.885 raeburn 15487: $cnum,$context,$category);
1.444 albertel 15488:
15489: # Note: The testing routines depend on this being output; see
15490: # Utils::Course. This needs to at least be output as a comment
15491: # if anyone ever decides to not show this, and Utils::Course::new
15492: # will need to be suitably modified.
1.1239 raeburn 15493: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
1.943 raeburn 15494: if ($$courseid =~ /^error:/) {
15495: return (0,$outcome);
15496: }
15497:
1.444 albertel 15498: #
15499: # Check if created correctly
15500: #
1.479 albertel 15501: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15502: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15503: if ($crsuhome eq 'no_host') {
15504: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15505: return (0,$outcome);
15506: }
1.541 raeburn 15507: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15508:
1.444 albertel 15509: #
1.566 albertel 15510: # Do the cloning
15511: #
15512: if ($can_clone && $cloneid) {
1.1239 raeburn 15513: $clonemsg = &mt('Cloning [_1] from [_2]',$showncrstype,$clonehome);
1.566 albertel 15514: if ($context ne 'auto') {
15515: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15516: }
15517: $outcome .= $clonemsg.$linefeed;
15518: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15519: # Copy all files
1.637 www 15520: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15521: # Restore URL
1.566 albertel 15522: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15523: # Restore title
1.566 albertel 15524: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15525: # Restore creation date, creator and creation context.
15526: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15527: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15528: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15529: # Mark as cloned
1.566 albertel 15530: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15531: # Need to clone grading mode
15532: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15533: $cenv{'grading'}=$newenv{'grading'};
15534: # Do not clone these environment entries
15535: &Apache::lonnet::del('environment',
15536: ['default_enrollment_start_date',
15537: 'default_enrollment_end_date',
15538: 'question.email',
15539: 'policy.email',
15540: 'comment.email',
15541: 'pch.users.denied',
1.725 raeburn 15542: 'plc.users.denied',
15543: 'hidefromcat',
1.1121 raeburn 15544: 'checkforpriv',
1.1166 raeburn 15545: 'categories',
15546: 'internal.uniquecode'],
1.638 www 15547: $$crsudom,$$crsunum);
1.1170 raeburn 15548: if ($args->{'textbook'}) {
15549: $cenv{'internal.textbook'} = $args->{'textbook'};
15550: }
1.444 albertel 15551: }
1.566 albertel 15552:
1.444 albertel 15553: #
15554: # Set environment (will override cloned, if existing)
15555: #
15556: my @sections = ();
15557: my @xlists = ();
15558: if ($args->{'crstype'}) {
15559: $cenv{'type'}=$args->{'crstype'};
15560: }
15561: if ($args->{'crsid'}) {
15562: $cenv{'courseid'}=$args->{'crsid'};
15563: }
15564: if ($args->{'crscode'}) {
15565: $cenv{'internal.coursecode'}=$args->{'crscode'};
15566: }
15567: if ($args->{'crsquota'} ne '') {
15568: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15569: } else {
15570: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15571: }
15572: if ($args->{'ccuname'}) {
15573: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15574: ':'.$args->{'ccdomain'};
15575: } else {
15576: $cenv{'internal.courseowner'} = $args->{'curruser'};
15577: }
1.1116 raeburn 15578: if ($args->{'defaultcredits'}) {
15579: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15580: }
1.444 albertel 15581: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15582: if ($args->{'crssections'}) {
15583: $cenv{'internal.sectionnums'} = '';
15584: if ($args->{'crssections'} =~ m/,/) {
15585: @sections = split/,/,$args->{'crssections'};
15586: } else {
15587: $sections[0] = $args->{'crssections'};
15588: }
15589: if (@sections > 0) {
15590: foreach my $item (@sections) {
15591: my ($sec,$gp) = split/:/,$item;
15592: my $class = $args->{'crscode'}.$sec;
15593: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15594: $cenv{'internal.sectionnums'} .= $item.',';
15595: unless ($addcheck eq 'ok') {
1.1263 raeburn 15596: push(@badclasses,$class);
1.444 albertel 15597: }
15598: }
15599: $cenv{'internal.sectionnums'} =~ s/,$//;
15600: }
15601: }
15602: # do not hide course coordinator from staff listing,
15603: # even if privileged
15604: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 15605: # add course coordinator's domain to domains to check for privileged users
15606: # if different to course domain
15607: if ($$crsudom ne $args->{'ccdomain'}) {
15608: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15609: }
1.444 albertel 15610: # add crosslistings
15611: if ($args->{'crsxlist'}) {
15612: $cenv{'internal.crosslistings'}='';
15613: if ($args->{'crsxlist'} =~ m/,/) {
15614: @xlists = split/,/,$args->{'crsxlist'};
15615: } else {
15616: $xlists[0] = $args->{'crsxlist'};
15617: }
15618: if (@xlists > 0) {
15619: foreach my $item (@xlists) {
15620: my ($xl,$gp) = split/:/,$item;
15621: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15622: $cenv{'internal.crosslistings'} .= $item.',';
15623: unless ($addcheck eq 'ok') {
1.1263 raeburn 15624: push(@badclasses,$xl);
1.444 albertel 15625: }
15626: }
15627: $cenv{'internal.crosslistings'} =~ s/,$//;
15628: }
15629: }
15630: if ($args->{'autoadds'}) {
15631: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15632: }
15633: if ($args->{'autodrops'}) {
15634: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15635: }
15636: # check for notification of enrollment changes
15637: my @notified = ();
15638: if ($args->{'notify_owner'}) {
15639: if ($args->{'ccuname'} ne '') {
15640: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15641: }
15642: }
15643: if ($args->{'notify_dc'}) {
15644: if ($uname ne '') {
1.630 raeburn 15645: push(@notified,$uname.':'.$udom);
1.444 albertel 15646: }
15647: }
15648: if (@notified > 0) {
15649: my $notifylist;
15650: if (@notified > 1) {
15651: $notifylist = join(',',@notified);
15652: } else {
15653: $notifylist = $notified[0];
15654: }
15655: $cenv{'internal.notifylist'} = $notifylist;
15656: }
15657: if (@badclasses > 0) {
15658: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 15659: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15660: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15661: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15662: );
1.1264 raeburn 15663: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15664: &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 15665: if ($context eq 'auto') {
15666: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 15667: } else {
1.566 albertel 15668: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 15669: }
15670: foreach my $item (@badclasses) {
1.541 raeburn 15671: if ($context eq 'auto') {
1.1261 raeburn 15672: $outcome .= " - $item\n";
1.541 raeburn 15673: } else {
1.1261 raeburn 15674: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15675: }
1.1261 raeburn 15676: }
15677: if ($context eq 'auto') {
15678: $outcome .= $linefeed;
15679: } else {
15680: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 15681: }
1.444 albertel 15682: }
15683: if ($args->{'no_end_date'}) {
15684: $args->{'endaccess'} = 0;
15685: }
15686: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15687: $cenv{'internal.autoend'}=$args->{'enrollend'};
15688: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15689: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15690: if ($args->{'showphotos'}) {
15691: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15692: }
15693: $cenv{'internal.authtype'} = $args->{'authtype'};
15694: $cenv{'internal.autharg'} = $args->{'autharg'};
15695: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15696: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15697: 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');
15698: if ($context eq 'auto') {
15699: $outcome .= $krb_msg;
15700: } else {
1.566 albertel 15701: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15702: }
15703: $outcome .= $linefeed;
1.444 albertel 15704: }
15705: }
15706: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15707: if ($args->{'setpolicy'}) {
15708: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15709: }
15710: if ($args->{'setcontent'}) {
15711: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15712: }
1.1251 raeburn 15713: if ($args->{'setcomment'}) {
15714: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15715: }
1.444 albertel 15716: }
15717: if ($args->{'reshome'}) {
15718: $cenv{'reshome'}=$args->{'reshome'}.'/';
15719: $cenv{'reshome'}=~s/\/+$/\//;
15720: }
15721: #
15722: # course has keyed access
15723: #
15724: if ($args->{'setkeys'}) {
15725: $cenv{'keyaccess'}='yes';
15726: }
15727: # if specified, key authority is not course, but user
15728: # only active if keyaccess is yes
15729: if ($args->{'keyauth'}) {
1.487 albertel 15730: my ($user,$domain) = split(':',$args->{'keyauth'});
15731: $user = &LONCAPA::clean_username($user);
15732: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15733: if ($user ne '' && $domain ne '') {
1.487 albertel 15734: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15735: }
15736: }
15737:
1.1166 raeburn 15738: #
1.1167 raeburn 15739: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 15740: #
15741: if ($args->{'uniquecode'}) {
15742: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15743: if ($code) {
15744: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 15745: my %crsinfo =
15746: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15747: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15748: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15749: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15750: }
1.1166 raeburn 15751: if (ref($coderef)) {
15752: $$coderef = $code;
15753: }
15754: }
15755: }
15756:
1.444 albertel 15757: if ($args->{'disresdis'}) {
15758: $cenv{'pch.roles.denied'}='st';
15759: }
15760: if ($args->{'disablechat'}) {
15761: $cenv{'plc.roles.denied'}='st';
15762: }
15763:
15764: # Record we've not yet viewed the Course Initialization Helper for this
15765: # course
15766: $cenv{'course.helper.not.run'} = 1;
15767: #
15768: # Use new Randomseed
15769: #
15770: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15771: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15772: #
15773: # The encryption code and receipt prefix for this course
15774: #
15775: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15776: $cenv{'internal.encpref'}=100+int(9*rand(99));
15777: #
15778: # By default, use standard grading
15779: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15780:
1.541 raeburn 15781: $outcome .= $linefeed.&mt('Setting environment').': '.
15782: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15783: #
15784: # Open all assignments
15785: #
15786: if ($args->{'openall'}) {
15787: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15788: my %storecontent = ($storeunder => time,
15789: $storeunder.'.type' => 'date_start');
15790:
15791: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15792: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15793: }
15794: #
15795: # Set first page
15796: #
15797: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15798: || ($cloneid)) {
1.445 albertel 15799: use LONCAPA::map;
1.444 albertel 15800: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15801:
15802: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15803: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15804:
1.444 albertel 15805: $outcome .= ($fatal?$errtext:'read ok').' - ';
15806: my $title; my $url;
15807: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15808: $title=&mt('Syllabus');
1.444 albertel 15809: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15810: } else {
1.963 raeburn 15811: $title=&mt('Table of Contents');
1.444 albertel 15812: $url='/adm/navmaps';
15813: }
1.445 albertel 15814:
15815: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15816: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15817:
15818: if ($errtext) { $fatal=2; }
1.541 raeburn 15819: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15820: }
1.566 albertel 15821:
1.1237 raeburn 15822: #
15823: # Set params for Placement Tests
15824: #
1.1239 raeburn 15825: if ($args->{'crstype'} eq 'Placement') {
15826: my %storecontent;
15827: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
15828: my %defaults = (
15829: buttonshide => { value => 'yes',
15830: type => 'string_yesno',},
15831: type => { value => 'randomizetry',
15832: type => 'string_questiontype',},
15833: maxtries => { value => 1,
15834: type => 'int_pos',},
15835: problemstatus => { value => 'no',
15836: type => 'string_problemstatus',},
15837: );
15838: foreach my $key (keys(%defaults)) {
15839: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
15840: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
15841: }
1.1237 raeburn 15842: &Apache::lonnet::cput
15843: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
15844: }
15845:
1.566 albertel 15846: return (1,$outcome);
1.444 albertel 15847: }
15848:
1.1166 raeburn 15849: sub make_unique_code {
15850: my ($cdom,$cnum) = @_;
15851: # get lock on uniquecodes db
15852: my $lockhash = {
15853: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15854: ':'.$env{'user.domain'},
15855: };
15856: my $tries = 0;
15857: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15858: my ($code,$error);
15859:
15860: while (($gotlock ne 'ok') && ($tries<3)) {
15861: $tries ++;
15862: sleep 1;
15863: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15864: }
15865: if ($gotlock eq 'ok') {
15866: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15867: my $gotcode;
15868: my $attempts = 0;
15869: while ((!$gotcode) && ($attempts < 100)) {
15870: $code = &generate_code();
15871: if (!exists($currcodes{$code})) {
15872: $gotcode = 1;
15873: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15874: $error = 'nostore';
15875: }
15876: }
15877: $attempts ++;
15878: }
15879: my @del_lock = ($cnum."\0".'uniquecodes');
15880: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15881: } else {
15882: $error = 'nolock';
15883: }
15884: return ($code,$error);
15885: }
15886:
15887: sub generate_code {
15888: my $code;
15889: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15890: for (my $i=0; $i<6; $i++) {
15891: my $lettnum = int (rand 2);
15892: my $item = '';
15893: if ($lettnum) {
15894: $item = $letts[int( rand(18) )];
15895: } else {
15896: $item = 1+int( rand(8) );
15897: }
15898: $code .= $item;
15899: }
15900: return $code;
15901: }
15902:
1.444 albertel 15903: ############################################################
15904: ############################################################
15905:
1.1237 raeburn 15906: # Community, Course and Placement Test
1.378 raeburn 15907: sub course_type {
15908: my ($cid) = @_;
15909: if (!defined($cid)) {
15910: $cid = $env{'request.course.id'};
15911: }
1.404 albertel 15912: if (defined($env{'course.'.$cid.'.type'})) {
15913: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15914: } else {
15915: return 'Course';
1.377 raeburn 15916: }
15917: }
1.156 albertel 15918:
1.406 raeburn 15919: sub group_term {
15920: my $crstype = &course_type();
15921: my %names = (
15922: 'Course' => 'group',
1.865 raeburn 15923: 'Community' => 'group',
1.1237 raeburn 15924: 'Placement' => 'group',
1.406 raeburn 15925: );
15926: return $names{$crstype};
15927: }
15928:
1.902 raeburn 15929: sub course_types {
1.1237 raeburn 15930: my @types = ('official','unofficial','community','textbook','placement');
1.902 raeburn 15931: my %typename = (
15932: official => 'Official course',
15933: unofficial => 'Unofficial course',
15934: community => 'Community',
1.1165 raeburn 15935: textbook => 'Textbook course',
1.1237 raeburn 15936: placement => 'Placement test',
1.902 raeburn 15937: );
15938: return (\@types,\%typename);
15939: }
15940:
1.156 albertel 15941: sub icon {
15942: my ($file)=@_;
1.505 albertel 15943: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15944: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15945: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15946: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15947: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15948: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15949: $curfext.".gif") {
15950: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15951: $curfext.".gif";
15952: }
15953: }
1.249 albertel 15954: return &lonhttpdurl($iconname);
1.154 albertel 15955: }
1.84 albertel 15956:
1.575 albertel 15957: sub lonhttpdurl {
1.692 www 15958: #
15959: # Had been used for "small fry" static images on separate port 8080.
15960: # Modify here if lightweight http functionality desired again.
15961: # Currently eliminated due to increasing firewall issues.
15962: #
1.575 albertel 15963: my ($url)=@_;
1.692 www 15964: return $url;
1.215 albertel 15965: }
15966:
1.213 albertel 15967: sub connection_aborted {
15968: my ($r)=@_;
15969: $r->print(" ");$r->rflush();
15970: my $c = $r->connection;
15971: return $c->aborted();
15972: }
15973:
1.221 foxr 15974: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15975: # strings as 'strings'.
15976: sub escape_single {
1.221 foxr 15977: my ($input) = @_;
1.223 albertel 15978: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15979: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15980: return $input;
15981: }
1.223 albertel 15982:
1.222 foxr 15983: # Same as escape_single, but escape's "'s This
15984: # can be used for "strings"
15985: sub escape_double {
15986: my ($input) = @_;
15987: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15988: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15989: return $input;
15990: }
1.223 albertel 15991:
1.222 foxr 15992: # Escapes the last element of a full URL.
15993: sub escape_url {
15994: my ($url) = @_;
1.238 raeburn 15995: my @urlslices = split(/\//, $url,-1);
1.369 www 15996: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 15997: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15998: }
1.462 albertel 15999:
1.820 raeburn 16000: sub compare_arrays {
16001: my ($arrayref1,$arrayref2) = @_;
16002: my (@difference,%count);
16003: @difference = ();
16004: %count = ();
16005: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16006: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16007: foreach my $element (keys(%count)) {
16008: if ($count{$element} == 1) {
16009: push(@difference,$element);
16010: }
16011: }
16012: }
16013: return @difference;
16014: }
16015:
1.817 bisitz 16016: # -------------------------------------------------------- Initialize user login
1.462 albertel 16017: sub init_user_environment {
1.463 albertel 16018: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16019: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16020:
16021: my $public=($username eq 'public' && $domain eq 'public');
16022:
1.1062 raeburn 16023: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16024: my $now=time;
16025:
16026: if ($public) {
16027: my $max_public=100;
16028: my $oldest;
16029: my $oldest_time=0;
16030: for(my $next=1;$next<=$max_public;$next++) {
16031: if (-e $lonids."/publicuser_$next.id") {
16032: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16033: if ($mtime<$oldest_time || !$oldest_time) {
16034: $oldest_time=$mtime;
16035: $oldest=$next;
16036: }
16037: } else {
16038: $cookie="publicuser_$next";
16039: last;
16040: }
16041: }
16042: if (!$cookie) { $cookie="publicuser_$oldest"; }
16043: } else {
1.1275 raeburn 16044: # See if old ID present, if so, remove if this isn't a robot,
16045: # killing any existing non-robot sessions
1.463 albertel 16046: if (!$args->{'robot'}) {
16047: opendir(DIR,$lonids);
16048: while ($filename=readdir(DIR)) {
16049: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
16050: unlink($lonids.'/'.$filename);
16051: }
1.462 albertel 16052: }
1.463 albertel 16053: closedir(DIR);
1.1204 raeburn 16054: # If there is a undeleted lockfile for the user's paste buffer remove it.
16055: my $namespace = 'nohist_courseeditor';
16056: my $lockingkey = 'paste'."\0".'locked_num';
16057: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16058: $domain,$username);
16059: if (exists($lockhash{$lockingkey})) {
16060: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16061: unless ($delresult eq 'ok') {
16062: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16063: }
16064: }
1.462 albertel 16065: }
16066: # Give them a new cookie
1.463 albertel 16067: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16068: : $now.$$.int(rand(10000)));
1.463 albertel 16069: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16070:
16071: # Initialize roles
16072:
1.1062 raeburn 16073: ($userroles,$firstaccenv,$timerintenv) =
16074: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16075: }
16076: # ------------------------------------ Check browser type and MathML capability
16077:
1.1194 raeburn 16078: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16079: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16080:
16081: # ------------------------------------------------------------- Get environment
16082:
16083: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16084: my ($tmp) = keys(%userenv);
1.1275 raeburn 16085: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 16086: undef(%userenv);
16087: }
16088: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16089: $form->{'interface'}=$userenv{'interface'};
16090: }
16091: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16092:
16093: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16094: foreach my $option ('interface','localpath','localres') {
16095: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16096: }
16097: # --------------------------------------------------------- Write first profile
16098:
16099: {
16100: my %initial_env =
16101: ("user.name" => $username,
16102: "user.domain" => $domain,
16103: "user.home" => $authhost,
16104: "browser.type" => $clientbrowser,
16105: "browser.version" => $clientversion,
16106: "browser.mathml" => $clientmathml,
16107: "browser.unicode" => $clientunicode,
16108: "browser.os" => $clientos,
1.1137 raeburn 16109: "browser.mobile" => $clientmobile,
1.1141 raeburn 16110: "browser.info" => $clientinfo,
1.1194 raeburn 16111: "browser.osversion" => $clientosversion,
1.462 albertel 16112: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16113: "request.course.fn" => '',
16114: "request.course.uri" => '',
16115: "request.course.sec" => '',
16116: "request.role" => 'cm',
16117: "request.role.adv" => $env{'user.adv'},
16118: "request.host" => $ENV{'REMOTE_ADDR'},);
16119:
16120: if ($form->{'localpath'}) {
16121: $initial_env{"browser.localpath"} = $form->{'localpath'};
16122: $initial_env{"browser.localres"} = $form->{'localres'};
16123: }
16124:
16125: if ($form->{'interface'}) {
16126: $form->{'interface'}=~s/\W//gs;
16127: $initial_env{"browser.interface"} = $form->{'interface'};
16128: $env{'browser.interface'}=$form->{'interface'};
16129: }
16130:
1.1157 raeburn 16131: if ($form->{'iptoken'}) {
16132: my $lonhost = $r->dir_config('lonHostID');
16133: $initial_env{"user.noloadbalance"} = $lonhost;
16134: $env{'user.noloadbalance'} = $lonhost;
16135: }
16136:
1.1268 raeburn 16137: if ($form->{'noloadbalance'}) {
16138: my @hosts = &Apache::lonnet::current_machine_ids();
16139: my $hosthere = $form->{'noloadbalance'};
16140: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16141: $initial_env{"user.noloadbalance"} = $hosthere;
16142: $env{'user.noloadbalance'} = $hosthere;
16143: }
16144: }
16145:
1.1016 raeburn 16146: unless ($domain eq 'public') {
1.1273 raeburn 16147: my %is_adv = ( is_adv => $env{'user.adv'} );
16148: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
16149:
16150: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16151: $userenv{'availabletools.'.$tool} =
16152: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16153: undef,\%userenv,\%domdef,\%is_adv);
16154: }
1.980 raeburn 16155:
1.1273 raeburn 16156: foreach my $crstype ('official','unofficial','community','textbook','placement') {
16157: $userenv{'canrequest.'.$crstype} =
16158: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16159: 'reload','requestcourses',
16160: \%userenv,\%domdef,\%is_adv);
16161: }
1.724 raeburn 16162:
1.1273 raeburn 16163: $userenv{'canrequest.author'} =
16164: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16165: 'reload','requestauthor',
1.980 raeburn 16166: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 16167: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16168: $domain,$username);
16169: my $reqstatus = $reqauthor{'author_status'};
16170: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16171: if (ref($reqauthor{'author'}) eq 'HASH') {
16172: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16173: $reqauthor{'author'}{'timestamp'};
16174: }
1.1092 raeburn 16175: }
16176: }
16177:
1.462 albertel 16178: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16179:
1.462 albertel 16180: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16181: &GDBM_WRCREAT(),0640)) {
16182: &_add_to_env(\%disk_env,\%initial_env);
16183: &_add_to_env(\%disk_env,\%userenv,'environment.');
16184: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16185: if (ref($firstaccenv) eq 'HASH') {
16186: &_add_to_env(\%disk_env,$firstaccenv);
16187: }
16188: if (ref($timerintenv) eq 'HASH') {
16189: &_add_to_env(\%disk_env,$timerintenv);
16190: }
1.463 albertel 16191: if (ref($args->{'extra_env'})) {
16192: &_add_to_env(\%disk_env,$args->{'extra_env'});
16193: }
1.462 albertel 16194: untie(%disk_env);
16195: } else {
1.705 tempelho 16196: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16197: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16198: return 'error: '.$!;
16199: }
16200: }
16201: $env{'request.role'}='cm';
16202: $env{'request.role.adv'}=$env{'user.adv'};
16203: $env{'browser.type'}=$clientbrowser;
16204:
16205: return $cookie;
16206:
16207: }
16208:
16209: sub _add_to_env {
16210: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16211: if (ref($env_data) eq 'HASH') {
16212: while (my ($key,$value) = each(%$env_data)) {
16213: $idf->{$prefix.$key} = $value;
16214: $env{$prefix.$key} = $value;
16215: }
1.462 albertel 16216: }
16217: }
16218:
1.685 tempelho 16219: # --- Get the symbolic name of a problem and the url
16220: sub get_symb {
16221: my ($request,$silent) = @_;
1.726 raeburn 16222: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16223: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16224: if ($symb eq '') {
16225: if (!$silent) {
1.1071 raeburn 16226: if (ref($request)) {
16227: $request->print("Unable to handle ambiguous references:$url:.");
16228: }
1.685 tempelho 16229: return ();
16230: }
16231: }
16232: &Apache::lonenc::check_decrypt(\$symb);
16233: return ($symb);
16234: }
16235:
16236: # --------------------------------------------------------------Get annotation
16237:
16238: sub get_annotation {
16239: my ($symb,$enc) = @_;
16240:
16241: my $key = $symb;
16242: if (!$enc) {
16243: $key =
16244: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16245: }
16246: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16247: return $annotation{$key};
16248: }
16249:
16250: sub clean_symb {
1.731 raeburn 16251: my ($symb,$delete_enc) = @_;
1.685 tempelho 16252:
16253: &Apache::lonenc::check_decrypt(\$symb);
16254: my $enc = $env{'request.enc'};
1.731 raeburn 16255: if ($delete_enc) {
1.730 raeburn 16256: delete($env{'request.enc'});
16257: }
1.685 tempelho 16258:
16259: return ($symb,$enc);
16260: }
1.462 albertel 16261:
1.1181 raeburn 16262: ############################################################
16263: ############################################################
16264:
16265: =pod
16266:
16267: =head1 Routines for building display used to search for courses
16268:
16269:
16270: =over 4
16271:
16272: =item * &build_filters()
16273:
16274: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 16275: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16276: and quotacheck.pl
16277:
1.1181 raeburn 16278:
16279: Inputs:
16280:
16281: filterlist - anonymous array of fields to include as potential filters
16282:
16283: crstype - course type
16284:
16285: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16286: to pop-open a course selector (will contain "extra element").
16287:
16288: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16289:
16290: filter - anonymous hash of criteria and their values
16291:
16292: action - form action
16293:
16294: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16295:
1.1182 raeburn 16296: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 16297:
16298: cloneruname - username of owner of new course who wants to clone
16299:
16300: clonerudom - domain of owner of new course who wants to clone
16301:
16302: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16303:
16304: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16305:
16306: codedom - domain
16307:
16308: formname - value of form element named "form".
16309:
16310: fixeddom - domain, if fixed.
16311:
16312: prevphase - value to assign to form element named "phase" when going back to the previous screen
16313:
16314: cnameelement - name of form element in form on opener page which will receive title of selected course
16315:
16316: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16317:
16318: cdomelement - name of form element in form on opener page which will receive domain of selected course
16319:
16320: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16321:
16322: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16323:
16324: clonewarning - warning message about missing information for intended course owner when DC creates a course
16325:
1.1182 raeburn 16326:
1.1181 raeburn 16327: Returns: $output - HTML for display of search criteria, and hidden form elements.
16328:
1.1182 raeburn 16329:
1.1181 raeburn 16330: Side Effects: None
16331:
16332: =cut
16333:
16334: # ---------------------------------------------- search for courses based on last activity etc.
16335:
16336: sub build_filters {
16337: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16338: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16339: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16340: $cnameelement,$cnumelement,$cdomelement,$setroles,
16341: $clonetext,$clonewarning) = @_;
1.1182 raeburn 16342: my ($list,$jscript);
1.1181 raeburn 16343: my $onchange = 'javascript:updateFilters(this)';
16344: my ($domainselectform,$sincefilterform,$createdfilterform,
16345: $ownerdomselectform,$persondomselectform,$instcodeform,
16346: $typeselectform,$instcodetitle);
16347: if ($formname eq '') {
16348: $formname = $caller;
16349: }
16350: foreach my $item (@{$filterlist}) {
16351: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16352: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16353: if ($item eq 'domainfilter') {
16354: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16355: } elsif ($item eq 'coursefilter') {
16356: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16357: } elsif ($item eq 'ownerfilter') {
16358: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16359: } elsif ($item eq 'ownerdomfilter') {
16360: $filter->{'ownerdomfilter'} =
16361: &LONCAPA::clean_domain($filter->{$item});
16362: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16363: 'ownerdomfilter',1);
16364: } elsif ($item eq 'personfilter') {
16365: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16366: } elsif ($item eq 'persondomfilter') {
16367: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16368: 'persondomfilter',1);
16369: } else {
16370: $filter->{$item} =~ s/\W//g;
16371: }
16372: if (!$filter->{$item}) {
16373: $filter->{$item} = '';
16374: }
16375: }
16376: if ($item eq 'domainfilter') {
16377: my $allow_blank = 1;
16378: if ($formname eq 'portform') {
16379: $allow_blank=0;
16380: } elsif ($formname eq 'studentform') {
16381: $allow_blank=0;
16382: }
16383: if ($fixeddom) {
16384: $domainselectform = '<input type="hidden" name="domainfilter"'.
16385: ' value="'.$codedom.'" />'.
16386: &Apache::lonnet::domain($codedom,'description');
16387: } else {
16388: $domainselectform = &select_dom_form($filter->{$item},
16389: 'domainfilter',
16390: $allow_blank,'',$onchange);
16391: }
16392: } else {
16393: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16394: }
16395: }
16396:
16397: # last course activity filter and selection
16398: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16399:
16400: # course created filter and selection
16401: if (exists($filter->{'createdfilter'})) {
16402: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16403: }
16404:
1.1239 raeburn 16405: my $prefix = $crstype;
16406: if ($crstype eq 'Placement') {
16407: $prefix = 'Placement Test'
16408: }
1.1181 raeburn 16409: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 16410: 'cac' => "$prefix Activity",
16411: 'ccr' => "$prefix Created",
16412: 'cde' => "$prefix Title",
16413: 'cdo' => "$prefix Domain",
1.1181 raeburn 16414: 'ins' => 'Institutional Code',
16415: 'inc' => 'Institutional Categorization',
1.1239 raeburn 16416: 'cow' => "$prefix Owner/Co-owner",
16417: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 16418: 'cog' => 'Type',
16419: );
16420:
16421: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16422: my $typeval = 'Course';
16423: if ($crstype eq 'Community') {
16424: $typeval = 'Community';
1.1239 raeburn 16425: } elsif ($crstype eq 'Placement') {
16426: $typeval = 'Placement';
1.1181 raeburn 16427: }
16428: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16429: } else {
16430: $typeselectform = '<select name="type" size="1"';
16431: if ($onchange) {
16432: $typeselectform .= ' onchange="'.$onchange.'"';
16433: }
16434: $typeselectform .= '>'."\n";
1.1237 raeburn 16435: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 16436: my $shown;
16437: if ($posstype eq 'Placement') {
16438: $shown = &mt('Placement Test');
16439: } else {
16440: $shown = &mt($posstype);
16441: }
1.1181 raeburn 16442: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 16443: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 16444: }
16445: $typeselectform.="</select>";
16446: }
16447:
16448: my ($cloneableonlyform,$cloneabletitle);
16449: if (exists($filter->{'cloneableonly'})) {
16450: my $cloneableon = '';
16451: my $cloneableoff = ' checked="checked"';
16452: if ($filter->{'cloneableonly'}) {
16453: $cloneableon = $cloneableoff;
16454: $cloneableoff = '';
16455: }
16456: $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>';
16457: if ($formname eq 'ccrs') {
1.1187 bisitz 16458: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 16459: } else {
16460: $cloneabletitle = &mt('Cloneable by you');
16461: }
16462: }
16463: my $officialjs;
16464: if ($crstype eq 'Course') {
16465: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 16466: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16467: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16468: if ($codedom) {
1.1181 raeburn 16469: $officialjs = 1;
16470: ($instcodeform,$jscript,$$numtitlesref) =
16471: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16472: $officialjs,$codetitlesref);
16473: if ($jscript) {
1.1182 raeburn 16474: $jscript = '<script type="text/javascript">'."\n".
16475: '// <![CDATA['."\n".
16476: $jscript."\n".
16477: '// ]]>'."\n".
16478: '</script>'."\n";
1.1181 raeburn 16479: }
16480: }
16481: if ($instcodeform eq '') {
16482: $instcodeform =
16483: '<input type="text" name="instcodefilter" size="10" value="'.
16484: $list->{'instcodefilter'}.'" />';
16485: $instcodetitle = $lt{'ins'};
16486: } else {
16487: $instcodetitle = $lt{'inc'};
16488: }
16489: if ($fixeddom) {
16490: $instcodetitle .= '<br />('.$codedom.')';
16491: }
16492: }
16493: }
16494: my $output = qq|
16495: <form method="post" name="filterpicker" action="$action">
16496: <input type="hidden" name="form" value="$formname" />
16497: |;
16498: if ($formname eq 'modifycourse') {
16499: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16500: '<input type="hidden" name="prevphase" value="'.
16501: $prevphase.'" />'."\n";
1.1198 musolffc 16502: } elsif ($formname eq 'quotacheck') {
16503: $output .= qq|
16504: <input type="hidden" name="sortby" value="" />
16505: <input type="hidden" name="sortorder" value="" />
16506: |;
16507: } else {
1.1181 raeburn 16508: my $name_input;
16509: if ($cnameelement ne '') {
16510: $name_input = '<input type="hidden" name="cnameelement" value="'.
16511: $cnameelement.'" />';
16512: }
16513: $output .= qq|
1.1182 raeburn 16514: <input type="hidden" name="cnumelement" value="$cnumelement" />
16515: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 16516: $name_input
16517: $roleelement
16518: $multelement
16519: $typeelement
16520: |;
16521: if ($formname eq 'portform') {
16522: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16523: }
16524: }
16525: if ($fixeddom) {
16526: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16527: }
16528: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16529: if ($sincefilterform) {
16530: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16531: .$sincefilterform
16532: .&Apache::lonhtmlcommon::row_closure();
16533: }
16534: if ($createdfilterform) {
16535: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16536: .$createdfilterform
16537: .&Apache::lonhtmlcommon::row_closure();
16538: }
16539: if ($domainselectform) {
16540: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16541: .$domainselectform
16542: .&Apache::lonhtmlcommon::row_closure();
16543: }
16544: if ($typeselectform) {
16545: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16546: $output .= $typeselectform;
16547: } else {
16548: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16549: .$typeselectform
16550: .&Apache::lonhtmlcommon::row_closure();
16551: }
16552: }
16553: if ($instcodeform) {
16554: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16555: .$instcodeform
16556: .&Apache::lonhtmlcommon::row_closure();
16557: }
16558: if (exists($filter->{'ownerfilter'})) {
16559: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16560: '<table><tr><td>'.&mt('Username').'<br />'.
16561: '<input type="text" name="ownerfilter" size="20" value="'.
16562: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16563: $ownerdomselectform.'</td></tr></table>'.
16564: &Apache::lonhtmlcommon::row_closure();
16565: }
16566: if (exists($filter->{'personfilter'})) {
16567: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16568: '<table><tr><td>'.&mt('Username').'<br />'.
16569: '<input type="text" name="personfilter" size="20" value="'.
16570: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16571: $persondomselectform.'</td></tr></table>'.
16572: &Apache::lonhtmlcommon::row_closure();
16573: }
16574: if (exists($filter->{'coursefilter'})) {
16575: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16576: .'<input type="text" name="coursefilter" size="25" value="'
16577: .$list->{'coursefilter'}.'" />'
16578: .&Apache::lonhtmlcommon::row_closure();
16579: }
16580: if ($cloneableonlyform) {
16581: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16582: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16583: }
16584: if (exists($filter->{'descriptfilter'})) {
16585: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16586: .'<input type="text" name="descriptfilter" size="40" value="'
16587: .$list->{'descriptfilter'}.'" />'
16588: .&Apache::lonhtmlcommon::row_closure(1);
16589: }
16590: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16591: '<input type="hidden" name="updater" value="" />'."\n".
16592: '<input type="submit" name="gosearch" value="'.
16593: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16594: return $jscript.$clonewarning.$output;
16595: }
16596:
16597: =pod
16598:
16599: =item * &timebased_select_form()
16600:
1.1182 raeburn 16601: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 16602: filter e.g., Course Activity, Course Created, when searching for courses
16603: or communities
16604:
16605: Inputs:
16606:
16607: item - name of form element (sincefilter or createdfilter)
16608:
16609: filter - anonymous hash of criteria and their values
16610:
16611: Returns: HTML for a select box contained a blank, then six time selections,
16612: with value set in incoming form variables currently selected.
16613:
16614: Side Effects: None
16615:
16616: =cut
16617:
16618: sub timebased_select_form {
16619: my ($item,$filter) = @_;
16620: if (ref($filter) eq 'HASH') {
16621: $filter->{$item} =~ s/[^\d-]//g;
16622: if (!$filter->{$item}) { $filter->{$item}=-1; }
16623: return &select_form(
16624: $filter->{$item},
16625: $item,
16626: { '-1' => '',
16627: '86400' => &mt('today'),
16628: '604800' => &mt('last week'),
16629: '2592000' => &mt('last month'),
16630: '7776000' => &mt('last three months'),
16631: '15552000' => &mt('last six months'),
16632: '31104000' => &mt('last year'),
16633: 'select_form_order' =>
16634: ['-1','86400','604800','2592000','7776000',
16635: '15552000','31104000']});
16636: }
16637: }
16638:
16639: =pod
16640:
16641: =item * &js_changer()
16642:
16643: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 16644: when course type or domain is changed, and also to hide 'Searching ...' on
16645: page load completion for page showing search result.
1.1181 raeburn 16646:
16647: Inputs: None
16648:
1.1183 raeburn 16649: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 16650:
16651: Side Effects: None
16652:
16653: =cut
16654:
16655: sub js_changer {
16656: return <<ENDJS;
16657: <script type="text/javascript">
16658: // <![CDATA[
16659: function updateFilters(caller) {
16660: if (typeof(caller) != "undefined") {
16661: document.filterpicker.updater.value = caller.name;
16662: }
16663: document.filterpicker.submit();
16664: }
1.1183 raeburn 16665:
16666: function hideSearching() {
16667: if (document.getElementById('searching')) {
16668: document.getElementById('searching').style.display = 'none';
16669: }
16670: return;
16671: }
16672:
1.1181 raeburn 16673: // ]]>
16674: </script>
16675:
16676: ENDJS
16677: }
16678:
16679: =pod
16680:
1.1182 raeburn 16681: =item * &search_courses()
16682:
16683: Process selected filters form course search form and pass to lonnet::courseiddump
16684: to retrieve a hash for which keys are courseIDs which match the selected filters.
16685:
16686: Inputs:
16687:
16688: dom - domain being searched
16689:
16690: type - course type ('Course' or 'Community' or '.' if any).
16691:
16692: filter - anonymous hash of criteria and their values
16693:
16694: numtitles - for institutional codes - number of categories
16695:
16696: cloneruname - optional username of new course owner
16697:
16698: clonerudom - optional domain of new course owner
16699:
1.1221 raeburn 16700: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 16701: (used when DC is using course creation form)
16702:
16703: codetitles - reference to array of titles of components in institutional codes (official courses).
16704:
1.1221 raeburn 16705: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16706: (and so can clone automatically)
16707:
16708: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16709:
16710: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16711: courses to clone
1.1182 raeburn 16712:
16713: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16714:
16715:
16716: Side Effects: None
16717:
16718: =cut
16719:
16720:
16721: sub search_courses {
1.1221 raeburn 16722: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16723: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 16724: my (%courses,%showcourses,$cloner);
16725: if (($filter->{'ownerfilter'} ne '') ||
16726: ($filter->{'ownerdomfilter'} ne '')) {
16727: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16728: $filter->{'ownerdomfilter'};
16729: }
16730: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16731: if (!$filter->{$item}) {
16732: $filter->{$item}='.';
16733: }
16734: }
16735: my $now = time;
16736: my $timefilter =
16737: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16738: my ($createdbefore,$createdafter);
16739: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16740: $createdbefore = $now;
16741: $createdafter = $now-$filter->{'createdfilter'};
16742: }
16743: my ($instcodefilter,$regexpok);
16744: if ($numtitles) {
16745: if ($env{'form.official'} eq 'on') {
16746: $instcodefilter =
16747: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16748: $regexpok = 1;
16749: } elsif ($env{'form.official'} eq 'off') {
16750: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16751: unless ($instcodefilter eq '') {
16752: $regexpok = -1;
16753: }
16754: }
16755: } else {
16756: $instcodefilter = $filter->{'instcodefilter'};
16757: }
16758: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16759: if ($type eq '') { $type = '.'; }
16760:
16761: if (($clonerudom ne '') && ($cloneruname ne '')) {
16762: $cloner = $cloneruname.':'.$clonerudom;
16763: }
16764: %courses = &Apache::lonnet::courseiddump($dom,
16765: $filter->{'descriptfilter'},
16766: $timefilter,
16767: $instcodefilter,
16768: $filter->{'combownerfilter'},
16769: $filter->{'coursefilter'},
16770: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 16771: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 16772: $filter->{'cloneableonly'},
16773: $createdbefore,$createdafter,undef,
1.1221 raeburn 16774: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 16775: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16776: my $ccrole;
16777: if ($type eq 'Community') {
16778: $ccrole = 'co';
16779: } else {
16780: $ccrole = 'cc';
16781: }
16782: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16783: $filter->{'persondomfilter'},
16784: 'userroles',undef,
16785: [$ccrole,'in','ad','ep','ta','cr'],
16786: $dom);
16787: foreach my $role (keys(%rolehash)) {
16788: my ($cnum,$cdom,$courserole) = split(':',$role);
16789: my $cid = $cdom.'_'.$cnum;
16790: if (exists($courses{$cid})) {
16791: if (ref($courses{$cid}) eq 'HASH') {
16792: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16793: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 16794: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 16795: }
16796: } else {
16797: $courses{$cid}{roles} = [$courserole];
16798: }
16799: $showcourses{$cid} = $courses{$cid};
16800: }
16801: }
16802: }
16803: %courses = %showcourses;
16804: }
16805: return %courses;
16806: }
16807:
16808: =pod
16809:
1.1181 raeburn 16810: =back
16811:
1.1207 raeburn 16812: =head1 Routines for version requirements for current course.
16813:
16814: =over 4
16815:
16816: =item * &check_release_required()
16817:
16818: Compares required LON-CAPA version with version on server, and
16819: if required version is newer looks for a server with the required version.
16820:
16821: Looks first at servers in user's owen domain; if none suitable, looks at
16822: servers in course's domain are permitted to host sessions for user's domain.
16823:
16824: Inputs:
16825:
16826: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16827:
16828: $courseid - Course ID of current course
16829:
16830: $rolecode - User's current role in course (for switchserver query string).
16831:
16832: $required - LON-CAPA version needed by course (format: Major.Minor).
16833:
16834:
16835: Returns:
16836:
16837: $switchserver - query string tp append to /adm/switchserver call (if
16838: current server's LON-CAPA version is too old.
16839:
16840: $warning - Message is displayed if no suitable server could be found.
16841:
16842: =cut
16843:
16844: sub check_release_required {
16845: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16846: my ($switchserver,$warning);
16847: if ($required ne '') {
16848: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16849: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16850: if ($reqdmajor ne '' && $reqdminor ne '') {
16851: my $otherserver;
16852: if (($major eq '' && $minor eq '') ||
16853: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16854: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16855: my $switchlcrev =
16856: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16857: $userdomserver);
16858: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16859: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16860: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16861: my $cdom = $env{'course.'.$courseid.'.domain'};
16862: if ($cdom ne $env{'user.domain'}) {
16863: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16864: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16865: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16866: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16867: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16868: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16869: my $canhost =
16870: &Apache::lonnet::can_host_session($env{'user.domain'},
16871: $coursedomserver,
16872: $remoterev,
16873: $udomdefaults{'remotesessions'},
16874: $defdomdefaults{'hostedsessions'});
16875:
16876: if ($canhost) {
16877: $otherserver = $coursedomserver;
16878: } else {
16879: $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.");
16880: }
16881: } else {
16882: $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).");
16883: }
16884: } else {
16885: $otherserver = $userdomserver;
16886: }
16887: }
16888: if ($otherserver ne '') {
16889: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16890: }
16891: }
16892: }
16893: return ($switchserver,$warning);
16894: }
16895:
16896: =pod
16897:
16898: =item * &check_release_result()
16899:
16900: Inputs:
16901:
16902: $switchwarning - Warning message if no suitable server found to host session.
16903:
16904: $switchserver - query string to append to /adm/switchserver containing lonHostID
16905: and current role.
16906:
16907: Returns: HTML to display with information about requirement to switch server.
16908: Either displaying warning with link to Roles/Courses screen or
16909: display link to switchserver.
16910:
1.1181 raeburn 16911: =cut
16912:
1.1207 raeburn 16913: sub check_release_result {
16914: my ($switchwarning,$switchserver) = @_;
16915: my $output = &start_page('Selected course unavailable on this server').
16916: '<p class="LC_warning">';
16917: if ($switchwarning) {
16918: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16919: if (&show_course()) {
16920: $output .= &mt('Display courses');
16921: } else {
16922: $output .= &mt('Display roles');
16923: }
16924: $output .= '</a>';
16925: } elsif ($switchserver) {
16926: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16927: '<br />'.
16928: '<a href="/adm/switchserver?'.$switchserver.'">'.
16929: &mt('Switch Server').
16930: '</a>';
16931: }
16932: $output .= '</p>'.&end_page();
16933: return $output;
16934: }
16935:
16936: =pod
16937:
16938: =item * &needs_coursereinit()
16939:
16940: Determine if course contents stored for user's session needs to be
16941: refreshed, because content has changed since "Big Hash" last tied.
16942:
16943: Check for change is made if time last checked is more than 10 minutes ago
16944: (by default).
16945:
16946: Inputs:
16947:
16948: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16949:
16950: $interval (optional) - Time which may elapse (in s) between last check for content
16951: change in current course. (default: 600 s).
16952:
16953: Returns: an array; first element is:
16954:
16955: =over 4
16956:
16957: 'switch' - if content updates mean user's session
16958: needs to be switched to a server running a newer LON-CAPA version
16959:
16960: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16961: on current server hosting user's session
16962:
16963: '' - if no action required.
16964:
16965: =back
16966:
16967: If first item element is 'switch':
16968:
16969: second item is $switchwarning - Warning message if no suitable server found to host session.
16970:
16971: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16972: and current role.
16973:
16974: otherwise: no other elements returned.
16975:
16976: =back
16977:
16978: =cut
16979:
16980: sub needs_coursereinit {
16981: my ($loncaparev,$interval) = @_;
16982: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16983: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16984: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16985: my $now = time;
16986: if ($interval eq '') {
16987: $interval = 600;
16988: }
16989: if (($now-$env{'request.course.timechecked'})>$interval) {
16990: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16991: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16992: if ($lastchange > $env{'request.course.tied'}) {
16993: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16994: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16995: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16996: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16997: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16998: $curr_reqd_hash{'internal.releaserequired'}});
16999: my ($switchserver,$switchwarning) =
17000: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17001: $curr_reqd_hash{'internal.releaserequired'});
17002: if ($switchwarning ne '' || $switchserver ne '') {
17003: return ('switch',$switchwarning,$switchserver);
17004: }
17005: }
17006: }
17007: return ('update');
17008: }
17009: }
17010: return ();
17011: }
1.1181 raeburn 17012:
1.1083 raeburn 17013: sub update_content_constraints {
17014: my ($cdom,$cnum,$chome,$cid) = @_;
17015: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17016: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
17017: my %checkresponsetypes;
17018: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 17019: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 17020: if ($item eq 'resourcetag') {
17021: if ($name eq 'responsetype') {
17022: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17023: }
17024: }
17025: }
17026: my $navmap = Apache::lonnavmaps::navmap->new();
17027: if (defined($navmap)) {
17028: my %allresponses;
17029: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
17030: my %responses = $res->responseTypes();
17031: foreach my $key (keys(%responses)) {
17032: next unless(exists($checkresponsetypes{$key}));
17033: $allresponses{$key} += $responses{$key};
17034: }
17035: }
17036: foreach my $key (keys(%allresponses)) {
17037: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17038: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17039: ($reqdmajor,$reqdminor) = ($major,$minor);
17040: }
17041: }
17042: undef($navmap);
17043: }
17044: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17045: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17046: }
17047: return;
17048: }
17049:
1.1110 raeburn 17050: sub allmaps_incourse {
17051: my ($cdom,$cnum,$chome,$cid) = @_;
17052: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17053: $cid = $env{'request.course.id'};
17054: $cdom = $env{'course.'.$cid.'.domain'};
17055: $cnum = $env{'course.'.$cid.'.num'};
17056: $chome = $env{'course.'.$cid.'.home'};
17057: }
17058: my %allmaps = ();
17059: my $lastchange =
17060: &Apache::lonnet::get_coursechange($cdom,$cnum);
17061: if ($lastchange > $env{'request.course.tied'}) {
17062: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17063: unless ($ferr) {
17064: &update_content_constraints($cdom,$cnum,$chome,$cid);
17065: }
17066: }
17067: my $navmap = Apache::lonnavmaps::navmap->new();
17068: if (defined($navmap)) {
17069: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17070: $allmaps{$res->src()} = 1;
17071: }
17072: }
17073: return \%allmaps;
17074: }
17075:
1.1083 raeburn 17076: sub parse_supplemental_title {
17077: my ($title) = @_;
17078:
17079: my ($foldertitle,$renametitle);
17080: if ($title =~ /&&&/) {
17081: $title = &HTML::Entites::decode($title);
17082: }
17083: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17084: $renametitle=$4;
17085: my ($time,$uname,$udom) = ($1,$2,$3);
17086: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17087: my $name = &plainname($uname,$udom);
17088: $name = &HTML::Entities::encode($name,'"<>&\'');
17089: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17090: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17091: $name.': <br />'.$foldertitle;
17092: }
17093: if (wantarray) {
17094: return ($title,$foldertitle,$renametitle);
17095: }
17096: return $title;
17097: }
17098:
1.1143 raeburn 17099: sub recurse_supplemental {
17100: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
17101: if ($suppmap) {
17102: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17103: if ($fatal) {
17104: $errors ++;
17105: } else {
17106: if ($#LONCAPA::map::resources > 0) {
17107: foreach my $res (@LONCAPA::map::resources) {
17108: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17109: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 17110: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
17111: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1143 raeburn 17112: } else {
17113: $numfiles ++;
17114: }
17115: }
17116: }
17117: }
17118: }
17119: }
17120: return ($numfiles,$errors);
17121: }
17122:
1.1101 raeburn 17123: sub symb_to_docspath {
1.1267 raeburn 17124: my ($symb,$navmapref) = @_;
17125: return unless ($symb && ref($navmapref));
1.1101 raeburn 17126: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17127: if ($resurl=~/\.(sequence|page)$/) {
17128: $mapurl=$resurl;
17129: } elsif ($resurl eq 'adm/navmaps') {
17130: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17131: }
17132: my $mapresobj;
1.1267 raeburn 17133: unless (ref($$navmapref)) {
17134: $$navmapref = Apache::lonnavmaps::navmap->new();
17135: }
17136: if (ref($$navmapref)) {
17137: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 17138: }
17139: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17140: my $type=$2;
17141: my $path;
17142: if (ref($mapresobj)) {
17143: my $pcslist = $mapresobj->map_hierarchy();
17144: if ($pcslist ne '') {
17145: foreach my $pc (split(/,/,$pcslist)) {
17146: next if ($pc <= 1);
1.1267 raeburn 17147: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 17148: if (ref($res)) {
17149: my $thisurl = $res->src();
17150: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17151: my $thistitle = $res->title();
17152: $path .= '&'.
17153: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 17154: &escape($thistitle).
1.1101 raeburn 17155: ':'.$res->randompick().
17156: ':'.$res->randomout().
17157: ':'.$res->encrypted().
17158: ':'.$res->randomorder().
17159: ':'.$res->is_page();
17160: }
17161: }
17162: }
17163: $path =~ s/^\&//;
17164: my $maptitle = $mapresobj->title();
17165: if ($mapurl eq 'default') {
1.1129 raeburn 17166: $maptitle = 'Main Content';
1.1101 raeburn 17167: }
17168: $path .= (($path ne '')? '&' : '').
17169: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17170: &escape($maptitle).
1.1101 raeburn 17171: ':'.$mapresobj->randompick().
17172: ':'.$mapresobj->randomout().
17173: ':'.$mapresobj->encrypted().
17174: ':'.$mapresobj->randomorder().
17175: ':'.$mapresobj->is_page();
17176: } else {
17177: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17178: my $ispage = (($type eq 'page')? 1 : '');
17179: if ($mapurl eq 'default') {
1.1129 raeburn 17180: $maptitle = 'Main Content';
1.1101 raeburn 17181: }
17182: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17183: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 17184: }
17185: unless ($mapurl eq 'default') {
17186: $path = 'default&'.
1.1146 raeburn 17187: &escape('Main Content').
1.1101 raeburn 17188: ':::::&'.$path;
17189: }
17190: return $path;
17191: }
17192:
1.1094 raeburn 17193: sub captcha_display {
17194: my ($context,$lonhost) = @_;
17195: my ($output,$error);
1.1234 raeburn 17196: my ($captcha,$pubkey,$privkey,$version) =
17197: &get_captcha_config($context,$lonhost);
1.1095 raeburn 17198: if ($captcha eq 'original') {
1.1094 raeburn 17199: $output = &create_captcha();
17200: unless ($output) {
1.1172 raeburn 17201: $error = 'captcha';
1.1094 raeburn 17202: }
17203: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17204: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 17205: unless ($output) {
1.1172 raeburn 17206: $error = 'recaptcha';
1.1094 raeburn 17207: }
17208: }
1.1234 raeburn 17209: return ($output,$error,$captcha,$version);
1.1094 raeburn 17210: }
17211:
17212: sub captcha_response {
17213: my ($context,$lonhost) = @_;
17214: my ($captcha_chk,$captcha_error);
1.1234 raeburn 17215: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 17216: if ($captcha eq 'original') {
1.1094 raeburn 17217: ($captcha_chk,$captcha_error) = &check_captcha();
17218: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17219: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 17220: } else {
17221: $captcha_chk = 1;
17222: }
17223: return ($captcha_chk,$captcha_error);
17224: }
17225:
17226: sub get_captcha_config {
17227: my ($context,$lonhost) = @_;
1.1234 raeburn 17228: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 17229: my $hostname = &Apache::lonnet::hostname($lonhost);
17230: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17231: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 17232: if ($context eq 'usercreation') {
17233: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17234: if (ref($domconfig{$context}) eq 'HASH') {
17235: $hashtocheck = $domconfig{$context}{'cancreate'};
17236: if (ref($hashtocheck) eq 'HASH') {
17237: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17238: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17239: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17240: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17241: }
17242: if ($privkey && $pubkey) {
17243: $captcha = 'recaptcha';
1.1234 raeburn 17244: $version = $hashtocheck->{'recaptchaversion'};
17245: if ($version ne '2') {
17246: $version = 1;
17247: }
1.1095 raeburn 17248: } else {
17249: $captcha = 'original';
17250: }
17251: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17252: $captcha = 'original';
17253: }
1.1094 raeburn 17254: }
1.1095 raeburn 17255: } else {
17256: $captcha = 'captcha';
17257: }
17258: } elsif ($context eq 'login') {
17259: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17260: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17261: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17262: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 17263: if ($privkey && $pubkey) {
17264: $captcha = 'recaptcha';
1.1234 raeburn 17265: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17266: if ($version ne '2') {
17267: $version = 1;
17268: }
1.1095 raeburn 17269: } else {
17270: $captcha = 'original';
1.1094 raeburn 17271: }
1.1095 raeburn 17272: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17273: $captcha = 'original';
1.1094 raeburn 17274: }
17275: }
1.1234 raeburn 17276: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 17277: }
17278:
17279: sub create_captcha {
17280: my %captcha_params = &captcha_settings();
17281: my ($output,$maxtries,$tries) = ('',10,0);
17282: while ($tries < $maxtries) {
17283: $tries ++;
17284: my $captcha = Authen::Captcha->new (
17285: output_folder => $captcha_params{'output_dir'},
17286: data_folder => $captcha_params{'db_dir'},
17287: );
17288: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17289:
17290: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17291: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17292: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 17293: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17294: '<br />'.
17295: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 17296: last;
17297: }
17298: }
17299: return $output;
17300: }
17301:
17302: sub captcha_settings {
17303: my %captcha_params = (
17304: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17305: www_output_dir => "/captchaspool",
17306: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17307: numchars => '5',
17308: );
17309: return %captcha_params;
17310: }
17311:
17312: sub check_captcha {
17313: my ($captcha_chk,$captcha_error);
17314: my $code = $env{'form.code'};
17315: my $md5sum = $env{'form.crypt'};
17316: my %captcha_params = &captcha_settings();
17317: my $captcha = Authen::Captcha->new(
17318: output_folder => $captcha_params{'output_dir'},
17319: data_folder => $captcha_params{'db_dir'},
17320: );
1.1109 raeburn 17321: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 17322: my %captcha_hash = (
17323: 0 => 'Code not checked (file error)',
17324: -1 => 'Failed: code expired',
17325: -2 => 'Failed: invalid code (not in database)',
17326: -3 => 'Failed: invalid code (code does not match crypt)',
17327: );
17328: if ($captcha_chk != 1) {
17329: $captcha_error = $captcha_hash{$captcha_chk}
17330: }
17331: return ($captcha_chk,$captcha_error);
17332: }
17333:
17334: sub create_recaptcha {
1.1234 raeburn 17335: my ($pubkey,$version) = @_;
17336: if ($version >= 2) {
17337: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17338: } else {
17339: my $use_ssl;
17340: if ($ENV{'SERVER_PORT'} == 443) {
17341: $use_ssl = 1;
17342: }
17343: my $captcha = Captcha::reCAPTCHA->new;
17344: return $captcha->get_options_setter({theme => 'white'})."\n".
17345: $captcha->get_html($pubkey,undef,$use_ssl).
17346: &mt('If the text is hard to read, [_1] will replace them.',
17347: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17348: '<br /><br />';
17349: }
1.1094 raeburn 17350: }
17351:
17352: sub check_recaptcha {
1.1234 raeburn 17353: my ($privkey,$version) = @_;
1.1094 raeburn 17354: my $captcha_chk;
1.1234 raeburn 17355: if ($version >= 2) {
17356: my %info = (
17357: secret => $privkey,
17358: response => $env{'form.g-recaptcha-response'},
17359: remoteip => $ENV{'REMOTE_ADDR'},
17360: );
1.1280 ! raeburn 17361: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
! 17362: $request->content(join('&',map {
! 17363: my $name = escape($_);
! 17364: "$name=" . ( ref($info{$_}) eq 'ARRAY'
! 17365: ? join("&$name=", map {escape($_) } @{$info{$_}})
! 17366: : &escape($info{$_}) );
! 17367: } keys(%info)));
! 17368: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 17369: if ($response->is_success) {
17370: my $data = JSON::DWIW->from_json($response->decoded_content);
17371: if (ref($data) eq 'HASH') {
17372: if ($data->{'success'}) {
17373: $captcha_chk = 1;
17374: }
17375: }
17376: }
17377: } else {
17378: my $captcha = Captcha::reCAPTCHA->new;
17379: my $captcha_result =
17380: $captcha->check_answer(
17381: $privkey,
17382: $ENV{'REMOTE_ADDR'},
17383: $env{'form.recaptcha_challenge_field'},
17384: $env{'form.recaptcha_response_field'},
17385: );
17386: if ($captcha_result->{is_valid}) {
17387: $captcha_chk = 1;
17388: }
1.1094 raeburn 17389: }
17390: return $captcha_chk;
17391: }
17392:
1.1174 raeburn 17393: sub emailusername_info {
1.1244 raeburn 17394: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 17395: my %titles = &Apache::lonlocal::texthash (
17396: lastname => 'Last Name',
17397: firstname => 'First Name',
17398: institution => 'School/college/university',
17399: location => "School's city, state/province, country",
17400: web => "School's web address",
17401: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 17402: id => 'Student/Employee ID',
1.1174 raeburn 17403: );
17404: return (\@fields,\%titles);
17405: }
17406:
1.1161 raeburn 17407: sub cleanup_html {
17408: my ($incoming) = @_;
17409: my $outgoing;
17410: if ($incoming ne '') {
17411: $outgoing = $incoming;
17412: $outgoing =~ s/;/;/g;
17413: $outgoing =~ s/\#/#/g;
17414: $outgoing =~ s/\&/&/g;
17415: $outgoing =~ s/</</g;
17416: $outgoing =~ s/>/>/g;
17417: $outgoing =~ s/\(/(/g;
17418: $outgoing =~ s/\)/)/g;
17419: $outgoing =~ s/"/"/g;
17420: $outgoing =~ s/'/'/g;
17421: $outgoing =~ s/\$/$/g;
17422: $outgoing =~ s{/}{/}g;
17423: $outgoing =~ s/=/=/g;
17424: $outgoing =~ s/\\/\/g
17425: }
17426: return $outgoing;
17427: }
17428:
1.1190 musolffc 17429: # Checks for critical messages and returns a redirect url if one exists.
17430: # $interval indicates how often to check for messages.
17431: sub critical_redirect {
17432: my ($interval) = @_;
17433: if ((time-$env{'user.criticalcheck.time'})>$interval) {
17434: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17435: $env{'user.name'});
17436: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 17437: my $redirecturl;
1.1190 musolffc 17438: if ($what[0]) {
17439: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17440: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 17441: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17442: return (1, $url);
1.1190 musolffc 17443: }
1.1191 raeburn 17444: }
17445: }
17446: return ();
1.1190 musolffc 17447: }
17448:
1.1174 raeburn 17449: # Use:
17450: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17451: #
17452: ##################################################
17453: # password associated functions #
17454: ##################################################
17455: sub des_keys {
17456: # Make a new key for DES encryption.
17457: # Each key has two parts which are returned separately.
17458: # Please note: Each key must be passed through the &hex function
17459: # before it is output to the web browser. The hex versions cannot
17460: # be used to decrypt.
17461: my @hexstr=('0','1','2','3','4','5','6','7',
17462: '8','9','a','b','c','d','e','f');
17463: my $lkey='';
17464: for (0..7) {
17465: $lkey.=$hexstr[rand(15)];
17466: }
17467: my $ukey='';
17468: for (0..7) {
17469: $ukey.=$hexstr[rand(15)];
17470: }
17471: return ($lkey,$ukey);
17472: }
17473:
17474: sub des_decrypt {
17475: my ($key,$cyphertext) = @_;
17476: my $keybin=pack("H16",$key);
17477: my $cypher;
17478: if ($Crypt::DES::VERSION>=2.03) {
17479: $cypher=new Crypt::DES $keybin;
17480: } else {
17481: $cypher=new DES $keybin;
17482: }
1.1233 raeburn 17483: my $plaintext='';
17484: my $cypherlength = length($cyphertext);
17485: my $numchunks = int($cypherlength/32);
17486: for (my $j=0; $j<$numchunks; $j++) {
17487: my $start = $j*32;
17488: my $cypherblock = substr($cyphertext,$start,32);
17489: my $chunk =
17490: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17491: $chunk .=
17492: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17493: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17494: $plaintext .= $chunk;
17495: }
1.1174 raeburn 17496: return $plaintext;
17497: }
17498:
1.112 bowersj2 17499: 1;
17500: __END__;
1.41 ng 17501:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>