Annotation of loncom/interface/loncommon.pm, revision 1.1281
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1281 ! raeburn 4: # $Id: loncommon.pm,v 1.1280 2017/05/23 03:07:36 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)) {
1.1281 ! raeburn 5190: if (ref($commblocks{$block}) eq 'HASH') {
! 5191: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
! 5192: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
! 5193: unless(grep(/^\Q$block\E$/,@blockers)) {
! 5194: push(@blockers,$block);
! 5195: $triggered{$block} = {
! 5196: start => $start,
! 5197: end => $end,
! 5198: type => $type,
! 5199: };
! 5200: }
! 5201: }
! 5202: }
1.1062 raeburn 5203: }
5204: }
1.490 raeburn 5205: }
1.1062 raeburn 5206: }
5207: }
5208: }
5209: foreach my $blocker (@blockers) {
5210: my ($staff_name,$staff_dom,$title,$blocks) =
5211: &parse_block_record($commblocks{$blocker});
5212: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5213: my ($start,$end,$triggertype);
5214: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5215: ($start,$end) = ($1,$2);
5216: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5217: $start = $triggered{$blocker}{'start'};
5218: $end = $triggered{$blocker}{'end'};
5219: $triggertype = $triggered{$blocker}{'type'};
5220: }
5221: if ($start) {
5222: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5223: if ($triggertype) {
5224: push(@{$$setters{$course}{'triggers'}},$triggertype);
5225: } else {
5226: push(@{$$setters{$course}{'triggers'}},0);
5227: }
5228: if ( ($startblock == 0) || ($startblock > $start) ) {
5229: $startblock = $start;
5230: if ($triggertype) {
5231: $triggerblock = $blocker;
1.474 raeburn 5232: }
5233: }
1.1062 raeburn 5234: if ( ($endblock == 0) || ($endblock < $end) ) {
5235: $endblock = $end;
5236: if ($triggertype) {
5237: $triggerblock = $blocker;
5238: }
5239: }
1.474 raeburn 5240: }
5241: }
1.1062 raeburn 5242: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5243: }
5244:
5245: sub parse_block_record {
5246: my ($record) = @_;
5247: my ($setuname,$setudom,$title,$blocks);
5248: if (ref($record) eq 'HASH') {
5249: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5250: $title = &unescape($record->{'event'});
5251: $blocks = $record->{'blocks'};
5252: } else {
5253: my @data = split(/:/,$record,3);
5254: if (scalar(@data) eq 2) {
5255: $title = $data[1];
5256: ($setuname,$setudom) = split(/@/,$data[0]);
5257: } else {
5258: ($setuname,$setudom,$title) = @data;
5259: }
5260: $blocks = { 'com' => 'on' };
5261: }
5262: return ($setuname,$setudom,$title,$blocks);
5263: }
5264:
1.854 kalberla 5265: sub blocking_status {
1.1189 raeburn 5266: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 5267: my %setters;
1.890 droeschl 5268:
1.1061 raeburn 5269: # check for active blocking
1.1062 raeburn 5270: my ($startblock,$endblock,$triggerblock) =
1.1189 raeburn 5271: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 5272: my $blocked = 0;
5273: if ($startblock && $endblock) {
5274: $blocked = 1;
5275: }
1.890 droeschl 5276:
1.1061 raeburn 5277: # caller just wants to know whether a block is active
5278: if (!wantarray) { return $blocked; }
5279:
5280: # build a link to a popup window containing the details
5281: my $querystring = "?activity=$activity";
5282: # $uname and $udom decide whose portfolio the user is trying to look at
1.1232 raeburn 5283: if (($activity eq 'port') || ($activity eq 'passwd')) {
5284: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5285: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5286: } elsif ($activity eq 'docs') {
5287: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
5288: }
1.1061 raeburn 5289:
5290: my $output .= <<'END_MYBLOCK';
5291: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5292: var options = "width=" + w + ",height=" + h + ",";
5293: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5294: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5295: var newWin = window.open(url, wdwName, options);
5296: newWin.focus();
5297: }
1.890 droeschl 5298: END_MYBLOCK
1.854 kalberla 5299:
1.1061 raeburn 5300: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5301:
1.1061 raeburn 5302: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5303: my $text = &mt('Communication Blocked');
1.1217 raeburn 5304: my $class = 'LC_comblock';
1.1062 raeburn 5305: if ($activity eq 'docs') {
5306: $text = &mt('Content Access Blocked');
1.1217 raeburn 5307: $class = '';
1.1063 raeburn 5308: } elsif ($activity eq 'printout') {
5309: $text = &mt('Printing Blocked');
1.1232 raeburn 5310: } elsif ($activity eq 'passwd') {
5311: $text = &mt('Password Changing Blocked');
1.1062 raeburn 5312: }
1.1061 raeburn 5313: $output .= <<"END_BLOCK";
1.1217 raeburn 5314: <div class='$class'>
1.869 kalberla 5315: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5316: title='$text'>
5317: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5318: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5319: title='$text'>$text</a>
1.867 kalberla 5320: </div>
5321:
5322: END_BLOCK
1.474 raeburn 5323:
1.1061 raeburn 5324: return ($blocked, $output);
1.854 kalberla 5325: }
1.490 raeburn 5326:
1.60 matthew 5327: ###############################################
5328:
1.682 raeburn 5329: sub check_ip_acc {
1.1201 raeburn 5330: my ($acc,$clientip)=@_;
1.682 raeburn 5331: &Apache::lonxml::debug("acc is $acc");
5332: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5333: return 1;
5334: }
1.1219 raeburn 5335: my $allowed;
1.1252 raeburn 5336: my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682 raeburn 5337:
5338: my $name;
1.1219 raeburn 5339: my %access = (
5340: allowfrom => 1,
5341: denyfrom => 0,
5342: );
5343: my @allows;
5344: my @denies;
5345: foreach my $item (split(',',$acc)) {
5346: $item =~ s/^\s*//;
5347: $item =~ s/\s*$//;
5348: my $pattern;
5349: if ($item =~ /^\!(.+)$/) {
5350: push(@denies,$1);
5351: } else {
5352: push(@allows,$item);
5353: }
5354: }
5355: my $numdenies = scalar(@denies);
5356: my $numallows = scalar(@allows);
5357: my $count = 0;
5358: foreach my $pattern (@denies,@allows) {
5359: $count ++;
5360: my $acctype = 'allowfrom';
5361: if ($count <= $numdenies) {
5362: $acctype = 'denyfrom';
5363: }
1.682 raeburn 5364: if ($pattern =~ /\*$/) {
5365: #35.8.*
5366: $pattern=~s/\*//;
1.1219 raeburn 5367: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5368: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5369: #35.8.3.[34-56]
5370: my $low=$2;
5371: my $high=$3;
5372: $pattern=$1;
5373: if ($ip =~ /^\Q$pattern\E/) {
5374: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5375: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5376: }
5377: } elsif ($pattern =~ /^\*/) {
5378: #*.msu.edu
5379: $pattern=~s/\*//;
5380: if (!defined($name)) {
5381: use Socket;
5382: my $netaddr=inet_aton($ip);
5383: ($name)=gethostbyaddr($netaddr,AF_INET);
5384: }
1.1219 raeburn 5385: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5386: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5387: #127.0.0.1
1.1219 raeburn 5388: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5389: } else {
5390: #some.name.com
5391: if (!defined($name)) {
5392: use Socket;
5393: my $netaddr=inet_aton($ip);
5394: ($name)=gethostbyaddr($netaddr,AF_INET);
5395: }
1.1219 raeburn 5396: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5397: }
5398: if ($allowed =~ /^(0|1)$/) { last; }
5399: }
5400: if ($allowed eq '') {
5401: if ($numdenies && !$numallows) {
5402: $allowed = 1;
5403: } else {
5404: $allowed = 0;
1.682 raeburn 5405: }
5406: }
5407: return $allowed;
5408: }
5409:
5410: ###############################################
5411:
1.60 matthew 5412: =pod
5413:
1.112 bowersj2 5414: =head1 Domain Template Functions
5415:
5416: =over 4
5417:
5418: =item * &determinedomain()
1.60 matthew 5419:
5420: Inputs: $domain (usually will be undef)
5421:
1.63 www 5422: Returns: Determines which domain should be used for designs
1.60 matthew 5423:
5424: =cut
1.54 www 5425:
1.60 matthew 5426: ###############################################
1.63 www 5427: sub determinedomain {
5428: my $domain=shift;
1.531 albertel 5429: if (! $domain) {
1.60 matthew 5430: # Determine domain if we have not been given one
1.893 raeburn 5431: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5432: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5433: if ($env{'request.role.domain'}) {
5434: $domain=$env{'request.role.domain'};
1.60 matthew 5435: }
5436: }
1.63 www 5437: return $domain;
5438: }
5439: ###############################################
1.517 raeburn 5440:
1.518 albertel 5441: sub devalidate_domconfig_cache {
5442: my ($udom)=@_;
5443: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5444: }
5445:
5446: # ---------------------- Get domain configuration for a domain
5447: sub get_domainconf {
5448: my ($udom) = @_;
5449: my $cachetime=1800;
5450: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5451: if (defined($cached)) { return %{$result}; }
5452:
5453: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5454: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5455: my (%designhash,%legacy);
1.518 albertel 5456: if (keys(%domconfig) > 0) {
5457: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5458: if (keys(%{$domconfig{'login'}})) {
5459: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5460: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5461: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5462: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5463: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5464: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5465: if ($key eq 'loginvia') {
5466: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5467: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5468: $designhash{$udom.'.login.loginvia'} = $server;
5469: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5470:
5471: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5472: } else {
5473: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5474: }
1.948 raeburn 5475: }
1.1208 raeburn 5476: } elsif ($key eq 'headtag') {
5477: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5478: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5479: }
1.946 raeburn 5480: }
1.1208 raeburn 5481: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5482: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5483: }
1.946 raeburn 5484: }
5485: }
5486: }
5487: } else {
5488: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5489: $designhash{$udom.'.login.'.$key.'_'.$img} =
5490: $domconfig{'login'}{$key}{$img};
5491: }
1.699 raeburn 5492: }
5493: } else {
5494: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5495: }
1.632 raeburn 5496: }
5497: } else {
5498: $legacy{'login'} = 1;
1.518 albertel 5499: }
1.632 raeburn 5500: } else {
5501: $legacy{'login'} = 1;
1.518 albertel 5502: }
5503: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5504: if (keys(%{$domconfig{'rolecolors'}})) {
5505: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5506: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5507: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5508: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5509: }
1.518 albertel 5510: }
5511: }
1.632 raeburn 5512: } else {
5513: $legacy{'rolecolors'} = 1;
1.518 albertel 5514: }
1.632 raeburn 5515: } else {
5516: $legacy{'rolecolors'} = 1;
1.518 albertel 5517: }
1.948 raeburn 5518: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5519: if ($domconfig{'autoenroll'}{'co-owners'}) {
5520: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5521: }
5522: }
1.632 raeburn 5523: if (keys(%legacy) > 0) {
5524: my %legacyhash = &get_legacy_domconf($udom);
5525: foreach my $item (keys(%legacyhash)) {
5526: if ($item =~ /^\Q$udom\E\.login/) {
5527: if ($legacy{'login'}) {
5528: $designhash{$item} = $legacyhash{$item};
5529: }
5530: } else {
5531: if ($legacy{'rolecolors'}) {
5532: $designhash{$item} = $legacyhash{$item};
5533: }
1.518 albertel 5534: }
5535: }
5536: }
1.632 raeburn 5537: } else {
5538: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5539: }
5540: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5541: $cachetime);
5542: return %designhash;
5543: }
5544:
1.632 raeburn 5545: sub get_legacy_domconf {
5546: my ($udom) = @_;
5547: my %legacyhash;
5548: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5549: my $designfile = $designdir.'/'.$udom.'.tab';
5550: if (-e $designfile) {
5551: if ( open (my $fh,"<$designfile") ) {
5552: while (my $line = <$fh>) {
5553: next if ($line =~ /^\#/);
5554: chomp($line);
5555: my ($key,$val)=(split(/\=/,$line));
5556: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5557: }
5558: close($fh);
5559: }
5560: }
1.1026 raeburn 5561: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5562: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5563: }
5564: return %legacyhash;
5565: }
5566:
1.63 www 5567: =pod
5568:
1.112 bowersj2 5569: =item * &domainlogo()
1.63 www 5570:
5571: Inputs: $domain (usually will be undef)
5572:
5573: Returns: A link to a domain logo, if the domain logo exists.
5574: If the domain logo does not exist, a description of the domain.
5575:
5576: =cut
1.112 bowersj2 5577:
1.63 www 5578: ###############################################
5579: sub domainlogo {
1.517 raeburn 5580: my $domain = &determinedomain(shift);
1.518 albertel 5581: my %designhash = &get_domainconf($domain);
1.517 raeburn 5582: # See if there is a logo
5583: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5584: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5585: if ($imgsrc =~ m{^/(adm|res)/}) {
5586: if ($imgsrc =~ m{^/res/}) {
5587: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5588: &Apache::lonnet::repcopy($local_name);
5589: }
5590: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5591: }
5592: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5593: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5594: return &Apache::lonnet::domain($domain,'description');
1.59 www 5595: } else {
1.60 matthew 5596: return '';
1.59 www 5597: }
5598: }
1.63 www 5599: ##############################################
5600:
5601: =pod
5602:
1.112 bowersj2 5603: =item * &designparm()
1.63 www 5604:
5605: Inputs: $which parameter; $domain (usually will be undef)
5606:
5607: Returns: value of designparamter $which
5608:
5609: =cut
1.112 bowersj2 5610:
1.397 albertel 5611:
1.400 albertel 5612: ##############################################
1.397 albertel 5613: sub designparm {
5614: my ($which,$domain)=@_;
5615: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5616: return $env{'environment.color.'.$which};
1.96 www 5617: }
1.63 www 5618: $domain=&determinedomain($domain);
1.1016 raeburn 5619: my %domdesign;
5620: unless ($domain eq 'public') {
5621: %domdesign = &get_domainconf($domain);
5622: }
1.520 raeburn 5623: my $output;
1.517 raeburn 5624: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5625: $output = $domdesign{$domain.'.'.$which};
1.63 www 5626: } else {
1.520 raeburn 5627: $output = $defaultdesign{$which};
5628: }
5629: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5630: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5631: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5632: if ($output =~ m{^/res/}) {
5633: my $local_name = &Apache::lonnet::filelocation('',$output);
5634: &Apache::lonnet::repcopy($local_name);
5635: }
1.520 raeburn 5636: $output = &lonhttpdurl($output);
5637: }
1.63 www 5638: }
1.520 raeburn 5639: return $output;
1.63 www 5640: }
1.59 www 5641:
1.822 bisitz 5642: ##############################################
5643: =pod
5644:
1.832 bisitz 5645: =item * &authorspace()
5646:
1.1028 raeburn 5647: Inputs: $url (usually will be undef).
1.832 bisitz 5648:
1.1132 raeburn 5649: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5650: directory being viewed (or for which action is being taken).
5651: If $url is provided, and begins /priv/<domain>/<uname>
5652: the path will be that portion of the $context argument.
5653: Otherwise the path will be for the author space of the current
5654: user when the current role is author, or for that of the
5655: co-author/assistant co-author space when the current role
5656: is co-author or assistant co-author.
1.832 bisitz 5657:
5658: =cut
5659:
5660: sub authorspace {
1.1028 raeburn 5661: my ($url) = @_;
5662: if ($url ne '') {
5663: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5664: return $1;
5665: }
5666: }
1.832 bisitz 5667: my $caname = '';
1.1024 www 5668: my $cadom = '';
1.1028 raeburn 5669: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5670: ($cadom,$caname) =
1.832 bisitz 5671: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5672: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5673: $caname = $env{'user.name'};
1.1024 www 5674: $cadom = $env{'user.domain'};
1.832 bisitz 5675: }
1.1028 raeburn 5676: if (($caname ne '') && ($cadom ne '')) {
5677: return "/priv/$cadom/$caname/";
5678: }
5679: return;
1.832 bisitz 5680: }
5681:
5682: ##############################################
5683: =pod
5684:
1.822 bisitz 5685: =item * &head_subbox()
5686:
5687: Inputs: $content (contains HTML code with page functions, etc.)
5688:
5689: Returns: HTML div with $content
5690: To be included in page header
5691:
5692: =cut
5693:
5694: sub head_subbox {
5695: my ($content)=@_;
5696: my $output =
1.993 raeburn 5697: '<div class="LC_head_subbox">'
1.822 bisitz 5698: .$content
5699: .'</div>'
5700: }
5701:
5702: ##############################################
5703: =pod
5704:
5705: =item * &CSTR_pageheader()
5706:
1.1026 raeburn 5707: Input: (optional) filename from which breadcrumb trail is built.
5708: In most cases no input as needed, as $env{'request.filename'}
5709: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5710:
5711: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5712: To be included on Authoring Space pages
1.822 bisitz 5713:
5714: =cut
5715:
5716: sub CSTR_pageheader {
1.1026 raeburn 5717: my ($trailfile) = @_;
5718: if ($trailfile eq '') {
5719: $trailfile = $env{'request.filename'};
5720: }
5721:
5722: # this is for resources; directories have customtitle, and crumbs
5723: # and select recent are created in lonpubdir.pm
5724:
5725: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5726: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5727: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5728: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5729: $formaction =~ s{/+}{/}g;
1.822 bisitz 5730:
5731: my $parentpath = '';
5732: my $lastitem = '';
5733: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5734: $parentpath = $1;
5735: $lastitem = $2;
5736: } else {
5737: $lastitem = $thisdisfn;
5738: }
1.921 bisitz 5739:
1.1246 raeburn 5740: my ($crsauthor,$title);
5741: if (($env{'request.course.id'}) &&
5742: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 5743: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 5744: $crsauthor = 1;
5745: $title = &mt('Course Authoring Space');
5746: } else {
5747: $title = &mt('Authoring Space');
5748: }
5749:
1.921 bisitz 5750: my $output =
1.822 bisitz 5751: '<div>'
5752: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 5753: .'<b>'.$title.'</b> '
1.822 bisitz 5754: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5755: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5756: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5757:
5758: if ($lastitem) {
5759: $output .=
5760: '<span class="LC_filename">'
5761: .$lastitem
5762: .'</span>';
5763: }
1.1245 raeburn 5764:
1.1246 raeburn 5765: if ($crsauthor) {
5766: $output .= '</form>'.&Apache::lonmenu::constspaceform();
5767: } else {
5768: $output .=
5769: '<br />'
5770: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5771: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5772: .'</form>'
5773: .&Apache::lonmenu::constspaceform();
5774: }
5775: $output .= '</div>';
1.921 bisitz 5776:
5777: return $output;
1.822 bisitz 5778: }
5779:
1.60 matthew 5780: ###############################################
5781: ###############################################
5782:
5783: =pod
5784:
1.112 bowersj2 5785: =back
5786:
1.549 albertel 5787: =head1 HTML Helpers
1.112 bowersj2 5788:
5789: =over 4
5790:
5791: =item * &bodytag()
1.60 matthew 5792:
5793: Returns a uniform header for LON-CAPA web pages.
5794:
5795: Inputs:
5796:
1.112 bowersj2 5797: =over 4
5798:
5799: =item * $title, A title to be displayed on the page.
5800:
5801: =item * $function, the current role (can be undef).
5802:
5803: =item * $addentries, extra parameters for the <body> tag.
5804:
5805: =item * $bodyonly, if defined, only return the <body> tag.
5806:
5807: =item * $domain, if defined, force a given domain.
5808:
5809: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5810: text interface only)
1.60 matthew 5811:
1.814 bisitz 5812: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5813: navigational links
1.317 albertel 5814:
1.338 albertel 5815: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5816:
1.460 albertel 5817: =item * $args, optional argument valid values are
5818: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 raeburn 5819: use_absolute -> for external resource or syllabus, this will
5820: contain https://<hostname> if server uses
5821: https (as per hosts.tab), but request is for http
5822: hostname -> hostname, from $r->hostname().
1.460 albertel 5823:
1.1096 raeburn 5824: =item * $advtoolsref, optional argument, ref to an array containing
5825: inlineremote items to be added in "Functions" menu below
5826: breadcrumbs.
5827:
1.112 bowersj2 5828: =back
5829:
1.60 matthew 5830: Returns: A uniform header for LON-CAPA web pages.
5831: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5832: If $bodyonly is undef or zero, an html string containing a <body> tag and
5833: other decorations will be returned.
5834:
5835: =cut
5836:
1.54 www 5837: sub bodytag {
1.831 bisitz 5838: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5839: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5840:
1.954 raeburn 5841: my $public;
5842: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5843: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5844: $public = 1;
5845: }
1.460 albertel 5846: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 5847: my $httphost = $args->{'use_absolute'};
1.1274 raeburn 5848: my $hostname = $args->{'hostname'};
1.339 albertel 5849:
1.183 matthew 5850: $function = &get_users_function() if (!$function);
1.339 albertel 5851: my $img = &designparm($function.'.img',$domain);
5852: my $font = &designparm($function.'.font',$domain);
5853: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5854:
1.803 bisitz 5855: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5856: 'bgcolor' => $pgbg,
1.339 albertel 5857: 'text' => $font,
5858: 'alink' => &designparm($function.'.alink',$domain),
5859: 'vlink' => &designparm($function.'.vlink',$domain),
5860: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5861: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5862:
1.63 www 5863: # role and realm
1.1178 raeburn 5864: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5865: if ($realm) {
5866: $realm = '/'.$realm;
5867: }
1.378 raeburn 5868: if ($role eq 'ca') {
1.479 albertel 5869: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5870: $realm = &plainname($rname,$rdom);
1.378 raeburn 5871: }
1.55 www 5872: # realm
1.258 albertel 5873: if ($env{'request.course.id'}) {
1.378 raeburn 5874: if ($env{'request.role'} !~ /^cr/) {
5875: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 5876: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 5877: if ($env{'request.role.desc'}) {
5878: $role = $env{'request.role.desc'};
5879: } else {
5880: $role = &mt('Helpdesk[_1]',' '.$2);
5881: }
1.1257 raeburn 5882: } else {
5883: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5884: }
1.898 raeburn 5885: if ($env{'request.course.sec'}) {
5886: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5887: }
1.359 albertel 5888: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5889: } else {
5890: $role = &Apache::lonnet::plaintext($role);
1.54 www 5891: }
1.433 albertel 5892:
1.359 albertel 5893: if (!$realm) { $realm=' '; }
1.330 albertel 5894:
1.438 albertel 5895: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5896:
1.101 www 5897: # construct main body tag
1.359 albertel 5898: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 5899: &Apache::lontexconvert::init_math_support();
1.252 albertel 5900:
1.1131 raeburn 5901: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5902:
1.1130 raeburn 5903: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5904: return $bodytag;
1.1130 raeburn 5905: }
1.359 albertel 5906:
1.954 raeburn 5907: if ($public) {
1.433 albertel 5908: undef($role);
5909: }
1.359 albertel 5910:
1.762 bisitz 5911: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5912: #
5913: # Extra info if you are the DC
5914: my $dc_info = '';
5915: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5916: $env{'course.'.$env{'request.course.id'}.
5917: '.domain'}.'/'})) {
5918: my $cid = $env{'request.course.id'};
1.917 raeburn 5919: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5920: $dc_info =~ s/\s+$//;
1.359 albertel 5921: }
5922:
1.1237 raeburn 5923: my $crstype;
5924: if ($env{'request.course.id'}) {
5925: $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
5926: } elsif ($args->{'crstype'}) {
5927: $crstype = $args->{'crstype'};
5928: }
5929: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
5930: undef($role);
5931: } else {
1.1242 raeburn 5932: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 5933: }
1.853 droeschl 5934:
1.903 droeschl 5935: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5936:
5937: # if ($env{'request.state'} eq 'construct') {
5938: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5939: # }
5940:
1.1130 raeburn 5941: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 5942: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5943:
1.1237 raeburn 5944: my ($left,$right) = Apache::lonmenu::primary_menu($crstype);
1.359 albertel 5945:
1.916 droeschl 5946: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5947: if ($dc_info) {
5948: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5949: }
1.1130 raeburn 5950: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 5951: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5952: return $bodytag;
5953: }
1.894 droeschl 5954:
1.927 raeburn 5955: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 5956: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5957: }
1.916 droeschl 5958:
1.1130 raeburn 5959: $bodytag .= $right;
1.852 droeschl 5960:
1.917 raeburn 5961: if ($dc_info) {
5962: $dc_info = &dc_courseid_toggle($dc_info);
5963: }
5964: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5965:
1.1169 raeburn 5966: #if directed to not display the secondary menu, don't.
1.1168 raeburn 5967: if ($args->{'no_secondary_menu'}) {
5968: return $bodytag;
5969: }
1.1169 raeburn 5970: #don't show menus for public users
1.954 raeburn 5971: if (!$public){
1.1154 raeburn 5972: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5973: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5974: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5975: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5976: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1274 raeburn 5977: $args->{'bread_crumbs'},'','',$hostname);
1.1096 raeburn 5978: } elsif ($forcereg) {
5979: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 raeburn 5980: $args->{'group'},
1.1274 raeburn 5981: $args->{'hide_buttons'},
5982: $hostname);
1.1096 raeburn 5983: } else {
5984: $bodytag .=
5985: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5986: $forcereg,$args->{'group'},
5987: $args->{'bread_crumbs'},
1.1274 raeburn 5988: $advtoolsref,'',$hostname);
1.920 raeburn 5989: }
1.903 droeschl 5990: }else{
5991: # this is to seperate menu from content when there's no secondary
5992: # menu. Especially needed for public accessible ressources.
5993: $bodytag .= '<hr style="clear:both" />';
5994: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5995: }
1.903 droeschl 5996:
1.235 raeburn 5997: return $bodytag;
1.182 matthew 5998: }
5999:
1.917 raeburn 6000: sub dc_courseid_toggle {
6001: my ($dc_info) = @_;
1.980 raeburn 6002: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 6003: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 6004: &mt('(More ...)').'</a></span>'.
6005: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
6006: }
6007:
1.330 albertel 6008: sub make_attr_string {
6009: my ($register,$attr_ref) = @_;
6010:
6011: if ($attr_ref && !ref($attr_ref)) {
6012: die("addentries Must be a hash ref ".
6013: join(':',caller(1))." ".
6014: join(':',caller(0))." ");
6015: }
6016:
6017: if ($register) {
1.339 albertel 6018: my ($on_load,$on_unload);
6019: foreach my $key (keys(%{$attr_ref})) {
6020: if (lc($key) eq 'onload') {
6021: $on_load.=$attr_ref->{$key}.';';
6022: delete($attr_ref->{$key});
6023:
6024: } elsif (lc($key) eq 'onunload') {
6025: $on_unload.=$attr_ref->{$key}.';';
6026: delete($attr_ref->{$key});
6027: }
6028: }
1.953 droeschl 6029: $attr_ref->{'onload'} = $on_load;
6030: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6031: }
1.339 albertel 6032:
1.330 albertel 6033: my $attr_string;
1.1159 raeburn 6034: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6035: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6036: }
6037: return $attr_string;
6038: }
6039:
6040:
1.182 matthew 6041: ###############################################
1.251 albertel 6042: ###############################################
6043:
6044: =pod
6045:
6046: =item * &endbodytag()
6047:
6048: Returns a uniform footer for LON-CAPA web pages.
6049:
1.635 raeburn 6050: Inputs: 1 - optional reference to an args hash
6051: If in the hash, key for noredirectlink has a value which evaluates to true,
6052: a 'Continue' link is not displayed if the page contains an
6053: internal redirect in the <head></head> section,
6054: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6055:
6056: =cut
6057:
6058: sub endbodytag {
1.635 raeburn 6059: my ($args) = @_;
1.1080 raeburn 6060: my $endbodytag;
6061: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6062: $endbodytag='</body>';
6063: }
1.315 albertel 6064: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6065: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6066: $endbodytag=
6067: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6068: &mt('Continue').'</a>'.
6069: $endbodytag;
6070: }
1.315 albertel 6071: }
1.251 albertel 6072: return $endbodytag;
6073: }
6074:
1.352 albertel 6075: =pod
6076:
6077: =item * &standard_css()
6078:
6079: Returns a style sheet
6080:
6081: Inputs: (all optional)
6082: domain -> force to color decorate a page for a specific
6083: domain
6084: function -> force usage of a specific rolish color scheme
6085: bgcolor -> override the default page bgcolor
6086:
6087: =cut
6088:
1.343 albertel 6089: sub standard_css {
1.345 albertel 6090: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6091: $function = &get_users_function() if (!$function);
6092: my $img = &designparm($function.'.img', $domain);
6093: my $tabbg = &designparm($function.'.tabbg', $domain);
6094: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6095: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6096: #second colour for later usage
1.345 albertel 6097: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6098: my $pgbg_or_bgcolor =
6099: $bgcolor ||
1.352 albertel 6100: &designparm($function.'.pgbg', $domain);
1.382 albertel 6101: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6102: my $alink = &designparm($function.'.alink', $domain);
6103: my $vlink = &designparm($function.'.vlink', $domain);
6104: my $link = &designparm($function.'.link', $domain);
6105:
1.602 albertel 6106: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6107: my $mono = 'monospace';
1.850 bisitz 6108: my $data_table_head = $sidebg;
6109: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6110: my $data_table_dark = '#E0E0E0';
1.470 banghart 6111: my $data_table_darker = '#CCCCCC';
1.349 albertel 6112: my $data_table_highlight = '#FFFF00';
1.352 albertel 6113: my $mail_new = '#FFBB77';
6114: my $mail_new_hover = '#DD9955';
6115: my $mail_read = '#BBBB77';
6116: my $mail_read_hover = '#999944';
6117: my $mail_replied = '#AAAA88';
6118: my $mail_replied_hover = '#888855';
6119: my $mail_other = '#99BBBB';
6120: my $mail_other_hover = '#669999';
1.391 albertel 6121: my $table_header = '#DDDDDD';
1.489 raeburn 6122: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6123: my $lg_border_color = '#C8C8C8';
1.952 onken 6124: my $button_hover = '#BF2317';
1.392 albertel 6125:
1.608 albertel 6126: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6127: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6128: : '0 3px 0 4px';
1.448 albertel 6129:
1.523 albertel 6130:
1.343 albertel 6131: return <<END;
1.947 droeschl 6132:
6133: /* needed for iframe to allow 100% height in FF */
6134: body, html {
6135: margin: 0;
6136: padding: 0 0.5%;
6137: height: 99%; /* to avoid scrollbars */
6138: }
6139:
1.795 www 6140: body {
1.911 bisitz 6141: font-family: $sans;
6142: line-height:130%;
6143: font-size:0.83em;
6144: color:$font;
1.795 www 6145: }
6146:
1.959 onken 6147: a:focus,
6148: a:focus img {
1.795 www 6149: color: red;
6150: }
1.698 harmsja 6151:
1.911 bisitz 6152: form, .inline {
6153: display: inline;
1.795 www 6154: }
1.721 harmsja 6155:
1.795 www 6156: .LC_right {
1.911 bisitz 6157: text-align:right;
1.795 www 6158: }
6159:
6160: .LC_middle {
1.911 bisitz 6161: vertical-align:middle;
1.795 www 6162: }
1.721 harmsja 6163:
1.1130 raeburn 6164: .LC_floatleft {
6165: float: left;
6166: }
6167:
6168: .LC_floatright {
6169: float: right;
6170: }
6171:
1.911 bisitz 6172: .LC_400Box {
6173: width:400px;
6174: }
1.721 harmsja 6175:
1.947 droeschl 6176: .LC_iframecontainer {
6177: width: 98%;
6178: margin: 0;
6179: position: fixed;
6180: top: 8.5em;
6181: bottom: 0;
6182: }
6183:
6184: .LC_iframecontainer iframe{
6185: border: none;
6186: width: 100%;
6187: height: 100%;
6188: }
6189:
1.778 bisitz 6190: .LC_filename {
6191: font-family: $mono;
6192: white-space:pre;
1.921 bisitz 6193: font-size: 120%;
1.778 bisitz 6194: }
6195:
6196: .LC_fileicon {
6197: border: none;
6198: height: 1.3em;
6199: vertical-align: text-bottom;
6200: margin-right: 0.3em;
6201: text-decoration:none;
6202: }
6203:
1.1008 www 6204: .LC_setting {
6205: text-decoration:underline;
6206: }
6207:
1.350 albertel 6208: .LC_error {
6209: color: red;
6210: }
1.795 www 6211:
1.1097 bisitz 6212: .LC_warning {
6213: color: darkorange;
6214: }
6215:
1.457 albertel 6216: .LC_diff_removed {
1.733 bisitz 6217: color: red;
1.394 albertel 6218: }
1.532 albertel 6219:
6220: .LC_info,
1.457 albertel 6221: .LC_success,
6222: .LC_diff_added {
1.350 albertel 6223: color: green;
6224: }
1.795 www 6225:
1.802 bisitz 6226: div.LC_confirm_box {
6227: background-color: #FAFAFA;
6228: border: 1px solid $lg_border_color;
6229: margin-right: 0;
6230: padding: 5px;
6231: }
6232:
6233: div.LC_confirm_box .LC_error img,
6234: div.LC_confirm_box .LC_success img {
6235: vertical-align: middle;
6236: }
6237:
1.1242 raeburn 6238: .LC_maxwidth {
6239: max-width: 100%;
6240: height: auto;
6241: }
6242:
1.1243 raeburn 6243: .LC_textsize_mobile {
6244: \@media only screen and (max-device-width: 480px) {
6245: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6246: }
6247: }
6248:
1.440 albertel 6249: .LC_icon {
1.771 droeschl 6250: border: none;
1.790 droeschl 6251: vertical-align: middle;
1.771 droeschl 6252: }
6253:
1.543 albertel 6254: .LC_docs_spacer {
6255: width: 25px;
6256: height: 1px;
1.771 droeschl 6257: border: none;
1.543 albertel 6258: }
1.346 albertel 6259:
1.532 albertel 6260: .LC_internal_info {
1.735 bisitz 6261: color: #999999;
1.532 albertel 6262: }
6263:
1.794 www 6264: .LC_discussion {
1.1050 www 6265: background: $data_table_dark;
1.911 bisitz 6266: border: 1px solid black;
6267: margin: 2px;
1.794 www 6268: }
6269:
6270: .LC_disc_action_left {
1.1050 www 6271: background: $sidebg;
1.911 bisitz 6272: text-align: left;
1.1050 www 6273: padding: 4px;
6274: margin: 2px;
1.794 www 6275: }
6276:
6277: .LC_disc_action_right {
1.1050 www 6278: background: $sidebg;
1.911 bisitz 6279: text-align: right;
1.1050 www 6280: padding: 4px;
6281: margin: 2px;
1.794 www 6282: }
6283:
6284: .LC_disc_new_item {
1.911 bisitz 6285: background: white;
6286: border: 2px solid red;
1.1050 www 6287: margin: 4px;
6288: padding: 4px;
1.794 www 6289: }
6290:
6291: .LC_disc_old_item {
1.911 bisitz 6292: background: white;
1.1050 www 6293: margin: 4px;
6294: padding: 4px;
1.794 www 6295: }
6296:
1.458 albertel 6297: table.LC_pastsubmission {
6298: border: 1px solid black;
6299: margin: 2px;
6300: }
6301:
1.924 bisitz 6302: table#LC_menubuttons {
1.345 albertel 6303: width: 100%;
6304: background: $pgbg;
1.392 albertel 6305: border: 2px;
1.402 albertel 6306: border-collapse: separate;
1.803 bisitz 6307: padding: 0;
1.345 albertel 6308: }
1.392 albertel 6309:
1.801 tempelho 6310: table#LC_title_bar a {
6311: color: $fontmenu;
6312: }
1.836 bisitz 6313:
1.807 droeschl 6314: table#LC_title_bar {
1.819 tempelho 6315: clear: both;
1.836 bisitz 6316: display: none;
1.807 droeschl 6317: }
6318:
1.795 www 6319: table#LC_title_bar,
1.933 droeschl 6320: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6321: table#LC_title_bar.LC_with_remote {
1.359 albertel 6322: width: 100%;
1.392 albertel 6323: border-color: $pgbg;
6324: border-style: solid;
6325: border-width: $border;
1.379 albertel 6326: background: $pgbg;
1.801 tempelho 6327: color: $fontmenu;
1.392 albertel 6328: border-collapse: collapse;
1.803 bisitz 6329: padding: 0;
1.819 tempelho 6330: margin: 0;
1.359 albertel 6331: }
1.795 www 6332:
1.933 droeschl 6333: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6334: margin: 0;
6335: padding: 0;
1.933 droeschl 6336: position: relative;
6337: list-style: none;
1.913 droeschl 6338: }
1.933 droeschl 6339: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6340: display: inline;
6341: }
1.933 droeschl 6342:
6343: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6344: padding: 0;
1.933 droeschl 6345: margin: 0;
6346: float: left;
1.913 droeschl 6347: }
1.933 droeschl 6348: .LC_breadcrumb_tools_tools {
6349: padding: 0;
6350: margin: 0;
1.913 droeschl 6351: float: right;
6352: }
6353:
1.1240 raeburn 6354: .LC_placement_prog {
6355: padding-right: 20px;
6356: font-weight: bold;
6357: font-size: 90%;
6358: }
6359:
1.359 albertel 6360: table#LC_title_bar td {
6361: background: $tabbg;
6362: }
1.795 www 6363:
1.911 bisitz 6364: table#LC_menubuttons img {
1.803 bisitz 6365: border: none;
1.346 albertel 6366: }
1.795 www 6367:
1.842 droeschl 6368: .LC_breadcrumbs_component {
1.911 bisitz 6369: float: right;
6370: margin: 0 1em;
1.357 albertel 6371: }
1.842 droeschl 6372: .LC_breadcrumbs_component img {
1.911 bisitz 6373: vertical-align: middle;
1.777 tempelho 6374: }
1.795 www 6375:
1.1243 raeburn 6376: .LC_breadcrumbs_hoverable {
6377: background: $sidebg;
6378: }
6379:
1.383 albertel 6380: td.LC_table_cell_checkbox {
6381: text-align: center;
6382: }
1.795 www 6383:
6384: .LC_fontsize_small {
1.911 bisitz 6385: font-size: 70%;
1.705 tempelho 6386: }
6387:
1.844 bisitz 6388: #LC_breadcrumbs {
1.911 bisitz 6389: clear:both;
6390: background: $sidebg;
6391: border-bottom: 1px solid $lg_border_color;
6392: line-height: 2.5em;
1.933 droeschl 6393: overflow: hidden;
1.911 bisitz 6394: margin: 0;
6395: padding: 0;
1.995 raeburn 6396: text-align: left;
1.819 tempelho 6397: }
1.862 bisitz 6398:
1.1098 bisitz 6399: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6400: clear:both;
6401: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6402: border: 1px solid $sidebg;
1.1098 bisitz 6403: margin: 0 0 10px 0;
1.966 bisitz 6404: padding: 3px;
1.995 raeburn 6405: text-align: left;
1.822 bisitz 6406: }
6407:
1.795 www 6408: .LC_fontsize_medium {
1.911 bisitz 6409: font-size: 85%;
1.705 tempelho 6410: }
6411:
1.795 www 6412: .LC_fontsize_large {
1.911 bisitz 6413: font-size: 120%;
1.705 tempelho 6414: }
6415:
1.346 albertel 6416: .LC_menubuttons_inline_text {
6417: color: $font;
1.698 harmsja 6418: font-size: 90%;
1.701 harmsja 6419: padding-left:3px;
1.346 albertel 6420: }
6421:
1.934 droeschl 6422: .LC_menubuttons_inline_text img{
6423: vertical-align: middle;
6424: }
6425:
1.1051 www 6426: li.LC_menubuttons_inline_text img {
1.951 onken 6427: cursor:pointer;
1.1002 droeschl 6428: text-decoration: none;
1.951 onken 6429: }
6430:
1.526 www 6431: .LC_menubuttons_link {
6432: text-decoration: none;
6433: }
1.795 www 6434:
1.522 albertel 6435: .LC_menubuttons_category {
1.521 www 6436: color: $font;
1.526 www 6437: background: $pgbg;
1.521 www 6438: font-size: larger;
6439: font-weight: bold;
6440: }
6441:
1.346 albertel 6442: td.LC_menubuttons_text {
1.911 bisitz 6443: color: $font;
1.346 albertel 6444: }
1.706 harmsja 6445:
1.346 albertel 6446: .LC_current_location {
6447: background: $tabbg;
6448: }
1.795 www 6449:
1.938 bisitz 6450: table.LC_data_table {
1.347 albertel 6451: border: 1px solid #000000;
1.402 albertel 6452: border-collapse: separate;
1.426 albertel 6453: border-spacing: 1px;
1.610 albertel 6454: background: $pgbg;
1.347 albertel 6455: }
1.795 www 6456:
1.422 albertel 6457: .LC_data_table_dense {
6458: font-size: small;
6459: }
1.795 www 6460:
1.507 raeburn 6461: table.LC_nested_outer {
6462: border: 1px solid #000000;
1.589 raeburn 6463: border-collapse: collapse;
1.803 bisitz 6464: border-spacing: 0;
1.507 raeburn 6465: width: 100%;
6466: }
1.795 www 6467:
1.879 raeburn 6468: table.LC_innerpickbox,
1.507 raeburn 6469: table.LC_nested {
1.803 bisitz 6470: border: none;
1.589 raeburn 6471: border-collapse: collapse;
1.803 bisitz 6472: border-spacing: 0;
1.507 raeburn 6473: width: 100%;
6474: }
1.795 www 6475:
1.911 bisitz 6476: table.LC_data_table tr th,
6477: table.LC_calendar tr th,
1.879 raeburn 6478: table.LC_prior_tries tr th,
6479: table.LC_innerpickbox tr th {
1.349 albertel 6480: font-weight: bold;
6481: background-color: $data_table_head;
1.801 tempelho 6482: color:$fontmenu;
1.701 harmsja 6483: font-size:90%;
1.347 albertel 6484: }
1.795 www 6485:
1.879 raeburn 6486: table.LC_innerpickbox tr th,
6487: table.LC_innerpickbox tr td {
6488: vertical-align: top;
6489: }
6490:
1.711 raeburn 6491: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6492: background-color: #CCCCCC;
1.711 raeburn 6493: font-weight: bold;
6494: text-align: left;
6495: }
1.795 www 6496:
1.912 bisitz 6497: table.LC_data_table tr.LC_odd_row > td {
6498: background-color: $data_table_light;
6499: padding: 2px;
6500: vertical-align: top;
6501: }
6502:
1.809 bisitz 6503: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6504: background-color: $data_table_light;
1.912 bisitz 6505: vertical-align: top;
6506: }
6507:
6508: table.LC_data_table tr.LC_even_row > td {
6509: background-color: $data_table_dark;
1.425 albertel 6510: padding: 2px;
1.900 bisitz 6511: vertical-align: top;
1.347 albertel 6512: }
1.795 www 6513:
1.809 bisitz 6514: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6515: background-color: $data_table_dark;
1.900 bisitz 6516: vertical-align: top;
1.347 albertel 6517: }
1.795 www 6518:
1.425 albertel 6519: table.LC_data_table tr.LC_data_table_highlight td {
6520: background-color: $data_table_darker;
6521: }
1.795 www 6522:
1.639 raeburn 6523: table.LC_data_table tr td.LC_leftcol_header {
6524: background-color: $data_table_head;
6525: font-weight: bold;
6526: }
1.795 www 6527:
1.451 albertel 6528: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6529: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6530: font-weight: bold;
6531: font-style: italic;
6532: text-align: center;
6533: padding: 8px;
1.347 albertel 6534: }
1.795 www 6535:
1.1114 raeburn 6536: table.LC_data_table tr.LC_empty_row td,
6537: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6538: background-color: $sidebg;
6539: }
6540:
6541: table.LC_nested tr.LC_empty_row td {
6542: background-color: #FFFFFF;
6543: }
6544:
1.890 droeschl 6545: table.LC_caption {
6546: }
6547:
1.507 raeburn 6548: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6549: padding: 4ex
6550: }
1.795 www 6551:
1.507 raeburn 6552: table.LC_nested_outer tr th {
6553: font-weight: bold;
1.801 tempelho 6554: color:$fontmenu;
1.507 raeburn 6555: background-color: $data_table_head;
1.701 harmsja 6556: font-size: small;
1.507 raeburn 6557: border-bottom: 1px solid #000000;
6558: }
1.795 www 6559:
1.507 raeburn 6560: table.LC_nested_outer tr td.LC_subheader {
6561: background-color: $data_table_head;
6562: font-weight: bold;
6563: font-size: small;
6564: border-bottom: 1px solid #000000;
6565: text-align: right;
1.451 albertel 6566: }
1.795 www 6567:
1.507 raeburn 6568: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6569: background-color: #CCCCCC;
1.451 albertel 6570: font-weight: bold;
6571: font-size: small;
1.507 raeburn 6572: text-align: center;
6573: }
1.795 www 6574:
1.589 raeburn 6575: table.LC_nested tr.LC_info_row td.LC_left_item,
6576: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6577: text-align: left;
1.451 albertel 6578: }
1.795 www 6579:
1.507 raeburn 6580: table.LC_nested td {
1.735 bisitz 6581: background-color: #FFFFFF;
1.451 albertel 6582: font-size: small;
1.507 raeburn 6583: }
1.795 www 6584:
1.507 raeburn 6585: table.LC_nested_outer tr th.LC_right_item,
6586: table.LC_nested tr.LC_info_row td.LC_right_item,
6587: table.LC_nested tr.LC_odd_row td.LC_right_item,
6588: table.LC_nested tr td.LC_right_item {
1.451 albertel 6589: text-align: right;
6590: }
6591:
1.507 raeburn 6592: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6593: background-color: #EEEEEE;
1.451 albertel 6594: }
6595:
1.473 raeburn 6596: table.LC_createuser {
6597: }
6598:
6599: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6600: font-size: small;
1.473 raeburn 6601: }
6602:
6603: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6604: background-color: #CCCCCC;
1.473 raeburn 6605: font-weight: bold;
6606: text-align: center;
6607: }
6608:
1.349 albertel 6609: table.LC_calendar {
6610: border: 1px solid #000000;
6611: border-collapse: collapse;
1.917 raeburn 6612: width: 98%;
1.349 albertel 6613: }
1.795 www 6614:
1.349 albertel 6615: table.LC_calendar_pickdate {
6616: font-size: xx-small;
6617: }
1.795 www 6618:
1.349 albertel 6619: table.LC_calendar tr td {
6620: border: 1px solid #000000;
6621: vertical-align: top;
1.917 raeburn 6622: width: 14%;
1.349 albertel 6623: }
1.795 www 6624:
1.349 albertel 6625: table.LC_calendar tr td.LC_calendar_day_empty {
6626: background-color: $data_table_dark;
6627: }
1.795 www 6628:
1.779 bisitz 6629: table.LC_calendar tr td.LC_calendar_day_current {
6630: background-color: $data_table_highlight;
1.777 tempelho 6631: }
1.795 www 6632:
1.938 bisitz 6633: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6634: background-color: $mail_new;
6635: }
1.795 www 6636:
1.938 bisitz 6637: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6638: background-color: $mail_new_hover;
6639: }
1.795 www 6640:
1.938 bisitz 6641: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6642: background-color: $mail_read;
6643: }
1.795 www 6644:
1.938 bisitz 6645: /*
6646: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6647: background-color: $mail_read_hover;
6648: }
1.938 bisitz 6649: */
1.795 www 6650:
1.938 bisitz 6651: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6652: background-color: $mail_replied;
6653: }
1.795 www 6654:
1.938 bisitz 6655: /*
6656: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6657: background-color: $mail_replied_hover;
6658: }
1.938 bisitz 6659: */
1.795 www 6660:
1.938 bisitz 6661: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6662: background-color: $mail_other;
6663: }
1.795 www 6664:
1.938 bisitz 6665: /*
6666: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6667: background-color: $mail_other_hover;
6668: }
1.938 bisitz 6669: */
1.494 raeburn 6670:
1.777 tempelho 6671: table.LC_data_table tr > td.LC_browser_file,
6672: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6673: background: #AAEE77;
1.389 albertel 6674: }
1.795 www 6675:
1.777 tempelho 6676: table.LC_data_table tr > td.LC_browser_file_locked,
6677: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6678: background: #FFAA99;
1.387 albertel 6679: }
1.795 www 6680:
1.777 tempelho 6681: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6682: background: #888888;
1.779 bisitz 6683: }
1.795 www 6684:
1.777 tempelho 6685: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6686: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6687: background: #F8F866;
1.777 tempelho 6688: }
1.795 www 6689:
1.696 bisitz 6690: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6691: background: #E0E8FF;
1.387 albertel 6692: }
1.696 bisitz 6693:
1.707 bisitz 6694: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6695: /* background: #77FF77; */
1.707 bisitz 6696: }
1.795 www 6697:
1.707 bisitz 6698: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6699: border-right: 8px solid #FFFF77;
1.707 bisitz 6700: }
1.795 www 6701:
1.707 bisitz 6702: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6703: border-right: 8px solid #FFAA77;
1.707 bisitz 6704: }
1.795 www 6705:
1.707 bisitz 6706: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6707: border-right: 8px solid #FF7777;
1.707 bisitz 6708: }
1.795 www 6709:
1.707 bisitz 6710: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6711: border-right: 8px solid #AAFF77;
1.707 bisitz 6712: }
1.795 www 6713:
1.707 bisitz 6714: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6715: border-right: 8px solid #11CC55;
1.707 bisitz 6716: }
6717:
1.388 albertel 6718: span.LC_current_location {
1.701 harmsja 6719: font-size:larger;
1.388 albertel 6720: background: $pgbg;
6721: }
1.387 albertel 6722:
1.1029 www 6723: span.LC_current_nav_location {
6724: font-weight:bold;
6725: background: $sidebg;
6726: }
6727:
1.395 albertel 6728: span.LC_parm_menu_item {
6729: font-size: larger;
6730: }
1.795 www 6731:
1.395 albertel 6732: span.LC_parm_scope_all {
6733: color: red;
6734: }
1.795 www 6735:
1.395 albertel 6736: span.LC_parm_scope_folder {
6737: color: green;
6738: }
1.795 www 6739:
1.395 albertel 6740: span.LC_parm_scope_resource {
6741: color: orange;
6742: }
1.795 www 6743:
1.395 albertel 6744: span.LC_parm_part {
6745: color: blue;
6746: }
1.795 www 6747:
1.911 bisitz 6748: span.LC_parm_folder,
6749: span.LC_parm_symb {
1.395 albertel 6750: font-size: x-small;
6751: font-family: $mono;
6752: color: #AAAAAA;
6753: }
6754:
1.977 bisitz 6755: ul.LC_parm_parmlist li {
6756: display: inline-block;
6757: padding: 0.3em 0.8em;
6758: vertical-align: top;
6759: width: 150px;
6760: border-top:1px solid $lg_border_color;
6761: }
6762:
1.795 www 6763: td.LC_parm_overview_level_menu,
6764: td.LC_parm_overview_map_menu,
6765: td.LC_parm_overview_parm_selectors,
6766: td.LC_parm_overview_restrictions {
1.396 albertel 6767: border: 1px solid black;
6768: border-collapse: collapse;
6769: }
1.795 www 6770:
1.396 albertel 6771: table.LC_parm_overview_restrictions td {
6772: border-width: 1px 4px 1px 4px;
6773: border-style: solid;
6774: border-color: $pgbg;
6775: text-align: center;
6776: }
1.795 www 6777:
1.396 albertel 6778: table.LC_parm_overview_restrictions th {
6779: background: $tabbg;
6780: border-width: 1px 4px 1px 4px;
6781: border-style: solid;
6782: border-color: $pgbg;
6783: }
1.795 www 6784:
1.398 albertel 6785: table#LC_helpmenu {
1.803 bisitz 6786: border: none;
1.398 albertel 6787: height: 55px;
1.803 bisitz 6788: border-spacing: 0;
1.398 albertel 6789: }
6790:
6791: table#LC_helpmenu fieldset legend {
6792: font-size: larger;
6793: }
1.795 www 6794:
1.397 albertel 6795: table#LC_helpmenu_links {
6796: width: 100%;
6797: border: 1px solid black;
6798: background: $pgbg;
1.803 bisitz 6799: padding: 0;
1.397 albertel 6800: border-spacing: 1px;
6801: }
1.795 www 6802:
1.397 albertel 6803: table#LC_helpmenu_links tr td {
6804: padding: 1px;
6805: background: $tabbg;
1.399 albertel 6806: text-align: center;
6807: font-weight: bold;
1.397 albertel 6808: }
1.396 albertel 6809:
1.795 www 6810: table#LC_helpmenu_links a:link,
6811: table#LC_helpmenu_links a:visited,
1.397 albertel 6812: table#LC_helpmenu_links a:active {
6813: text-decoration: none;
6814: color: $font;
6815: }
1.795 www 6816:
1.397 albertel 6817: table#LC_helpmenu_links a:hover {
6818: text-decoration: underline;
6819: color: $vlink;
6820: }
1.396 albertel 6821:
1.417 albertel 6822: .LC_chrt_popup_exists {
6823: border: 1px solid #339933;
6824: margin: -1px;
6825: }
1.795 www 6826:
1.417 albertel 6827: .LC_chrt_popup_up {
6828: border: 1px solid yellow;
6829: margin: -1px;
6830: }
1.795 www 6831:
1.417 albertel 6832: .LC_chrt_popup {
6833: border: 1px solid #8888FF;
6834: background: #CCCCFF;
6835: }
1.795 www 6836:
1.421 albertel 6837: table.LC_pick_box {
6838: border-collapse: separate;
6839: background: white;
6840: border: 1px solid black;
6841: border-spacing: 1px;
6842: }
1.795 www 6843:
1.421 albertel 6844: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6845: background: $sidebg;
1.421 albertel 6846: font-weight: bold;
1.900 bisitz 6847: text-align: left;
1.740 bisitz 6848: vertical-align: top;
1.421 albertel 6849: width: 184px;
6850: padding: 8px;
6851: }
1.795 www 6852:
1.579 raeburn 6853: table.LC_pick_box td.LC_pick_box_value {
6854: text-align: left;
6855: padding: 8px;
6856: }
1.795 www 6857:
1.579 raeburn 6858: table.LC_pick_box td.LC_pick_box_select {
6859: text-align: left;
6860: padding: 8px;
6861: }
1.795 www 6862:
1.424 albertel 6863: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6864: padding: 0;
1.421 albertel 6865: height: 1px;
6866: background: black;
6867: }
1.795 www 6868:
1.421 albertel 6869: table.LC_pick_box td.LC_pick_box_submit {
6870: text-align: right;
6871: }
1.795 www 6872:
1.579 raeburn 6873: table.LC_pick_box td.LC_evenrow_value {
6874: text-align: left;
6875: padding: 8px;
6876: background-color: $data_table_light;
6877: }
1.795 www 6878:
1.579 raeburn 6879: table.LC_pick_box td.LC_oddrow_value {
6880: text-align: left;
6881: padding: 8px;
6882: background-color: $data_table_light;
6883: }
1.795 www 6884:
1.579 raeburn 6885: span.LC_helpform_receipt_cat {
6886: font-weight: bold;
6887: }
1.795 www 6888:
1.424 albertel 6889: table.LC_group_priv_box {
6890: background: white;
6891: border: 1px solid black;
6892: border-spacing: 1px;
6893: }
1.795 www 6894:
1.424 albertel 6895: table.LC_group_priv_box td.LC_pick_box_title {
6896: background: $tabbg;
6897: font-weight: bold;
6898: text-align: right;
6899: width: 184px;
6900: }
1.795 www 6901:
1.424 albertel 6902: table.LC_group_priv_box td.LC_groups_fixed {
6903: background: $data_table_light;
6904: text-align: center;
6905: }
1.795 www 6906:
1.424 albertel 6907: table.LC_group_priv_box td.LC_groups_optional {
6908: background: $data_table_dark;
6909: text-align: center;
6910: }
1.795 www 6911:
1.424 albertel 6912: table.LC_group_priv_box td.LC_groups_functionality {
6913: background: $data_table_darker;
6914: text-align: center;
6915: font-weight: bold;
6916: }
1.795 www 6917:
1.424 albertel 6918: table.LC_group_priv td {
6919: text-align: left;
1.803 bisitz 6920: padding: 0;
1.424 albertel 6921: }
6922:
6923: .LC_navbuttons {
6924: margin: 2ex 0ex 2ex 0ex;
6925: }
1.795 www 6926:
1.423 albertel 6927: .LC_topic_bar {
6928: font-weight: bold;
6929: background: $tabbg;
1.918 wenzelju 6930: margin: 1em 0em 1em 2em;
1.805 bisitz 6931: padding: 3px;
1.918 wenzelju 6932: font-size: 1.2em;
1.423 albertel 6933: }
1.795 www 6934:
1.423 albertel 6935: .LC_topic_bar span {
1.918 wenzelju 6936: left: 0.5em;
6937: position: absolute;
1.423 albertel 6938: vertical-align: middle;
1.918 wenzelju 6939: font-size: 1.2em;
1.423 albertel 6940: }
1.795 www 6941:
1.423 albertel 6942: table.LC_course_group_status {
6943: margin: 20px;
6944: }
1.795 www 6945:
1.423 albertel 6946: table.LC_status_selector td {
6947: vertical-align: top;
6948: text-align: center;
1.424 albertel 6949: padding: 4px;
6950: }
1.795 www 6951:
1.599 albertel 6952: div.LC_feedback_link {
1.616 albertel 6953: clear: both;
1.829 kalberla 6954: background: $sidebg;
1.779 bisitz 6955: width: 100%;
1.829 kalberla 6956: padding-bottom: 10px;
6957: border: 1px $tabbg solid;
1.833 kalberla 6958: height: 22px;
6959: line-height: 22px;
6960: padding-top: 5px;
6961: }
6962:
6963: div.LC_feedback_link img {
6964: height: 22px;
1.867 kalberla 6965: vertical-align:middle;
1.829 kalberla 6966: }
6967:
1.911 bisitz 6968: div.LC_feedback_link a {
1.829 kalberla 6969: text-decoration: none;
1.489 raeburn 6970: }
1.795 www 6971:
1.867 kalberla 6972: div.LC_comblock {
1.911 bisitz 6973: display:inline;
1.867 kalberla 6974: color:$font;
6975: font-size:90%;
6976: }
6977:
6978: div.LC_feedback_link div.LC_comblock {
6979: padding-left:5px;
6980: }
6981:
6982: div.LC_feedback_link div.LC_comblock a {
6983: color:$font;
6984: }
6985:
1.489 raeburn 6986: span.LC_feedback_link {
1.858 bisitz 6987: /* background: $feedback_link_bg; */
1.599 albertel 6988: font-size: larger;
6989: }
1.795 www 6990:
1.599 albertel 6991: span.LC_message_link {
1.858 bisitz 6992: /* background: $feedback_link_bg; */
1.599 albertel 6993: font-size: larger;
6994: position: absolute;
6995: right: 1em;
1.489 raeburn 6996: }
1.421 albertel 6997:
1.515 albertel 6998: table.LC_prior_tries {
1.524 albertel 6999: border: 1px solid #000000;
7000: border-collapse: separate;
7001: border-spacing: 1px;
1.515 albertel 7002: }
1.523 albertel 7003:
1.515 albertel 7004: table.LC_prior_tries td {
1.524 albertel 7005: padding: 2px;
1.515 albertel 7006: }
1.523 albertel 7007:
7008: .LC_answer_correct {
1.795 www 7009: background: lightgreen;
7010: color: darkgreen;
7011: padding: 6px;
1.523 albertel 7012: }
1.795 www 7013:
1.523 albertel 7014: .LC_answer_charged_try {
1.797 www 7015: background: #FFAAAA;
1.795 www 7016: color: darkred;
7017: padding: 6px;
1.523 albertel 7018: }
1.795 www 7019:
1.779 bisitz 7020: .LC_answer_not_charged_try,
1.523 albertel 7021: .LC_answer_no_grade,
7022: .LC_answer_late {
1.795 www 7023: background: lightyellow;
1.523 albertel 7024: color: black;
1.795 www 7025: padding: 6px;
1.523 albertel 7026: }
1.795 www 7027:
1.523 albertel 7028: .LC_answer_previous {
1.795 www 7029: background: lightblue;
7030: color: darkblue;
7031: padding: 6px;
1.523 albertel 7032: }
1.795 www 7033:
1.779 bisitz 7034: .LC_answer_no_message {
1.777 tempelho 7035: background: #FFFFFF;
7036: color: black;
1.795 www 7037: padding: 6px;
1.779 bisitz 7038: }
1.795 www 7039:
1.779 bisitz 7040: .LC_answer_unknown {
7041: background: orange;
7042: color: black;
1.795 www 7043: padding: 6px;
1.777 tempelho 7044: }
1.795 www 7045:
1.529 albertel 7046: span.LC_prior_numerical,
7047: span.LC_prior_string,
7048: span.LC_prior_custom,
7049: span.LC_prior_reaction,
7050: span.LC_prior_math {
1.925 bisitz 7051: font-family: $mono;
1.523 albertel 7052: white-space: pre;
7053: }
7054:
1.525 albertel 7055: span.LC_prior_string {
1.925 bisitz 7056: font-family: $mono;
1.525 albertel 7057: white-space: pre;
7058: }
7059:
1.523 albertel 7060: table.LC_prior_option {
7061: width: 100%;
7062: border-collapse: collapse;
7063: }
1.795 www 7064:
1.911 bisitz 7065: table.LC_prior_rank,
1.795 www 7066: table.LC_prior_match {
1.528 albertel 7067: border-collapse: collapse;
7068: }
1.795 www 7069:
1.528 albertel 7070: table.LC_prior_option tr td,
7071: table.LC_prior_rank tr td,
7072: table.LC_prior_match tr td {
1.524 albertel 7073: border: 1px solid #000000;
1.515 albertel 7074: }
7075:
1.855 bisitz 7076: .LC_nobreak {
1.544 albertel 7077: white-space: nowrap;
1.519 raeburn 7078: }
7079:
1.576 raeburn 7080: span.LC_cusr_emph {
7081: font-style: italic;
7082: }
7083:
1.633 raeburn 7084: span.LC_cusr_subheading {
7085: font-weight: normal;
7086: font-size: 85%;
7087: }
7088:
1.861 bisitz 7089: div.LC_docs_entry_move {
1.859 bisitz 7090: border: 1px solid #BBBBBB;
1.545 albertel 7091: background: #DDDDDD;
1.861 bisitz 7092: width: 22px;
1.859 bisitz 7093: padding: 1px;
7094: margin: 0;
1.545 albertel 7095: }
7096:
1.861 bisitz 7097: table.LC_data_table tr > td.LC_docs_entry_commands,
7098: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7099: font-size: x-small;
7100: }
1.795 www 7101:
1.861 bisitz 7102: .LC_docs_entry_parameter {
7103: white-space: nowrap;
7104: }
7105:
1.544 albertel 7106: .LC_docs_copy {
1.545 albertel 7107: color: #000099;
1.544 albertel 7108: }
1.795 www 7109:
1.544 albertel 7110: .LC_docs_cut {
1.545 albertel 7111: color: #550044;
1.544 albertel 7112: }
1.795 www 7113:
1.544 albertel 7114: .LC_docs_rename {
1.545 albertel 7115: color: #009900;
1.544 albertel 7116: }
1.795 www 7117:
1.544 albertel 7118: .LC_docs_remove {
1.545 albertel 7119: color: #990000;
7120: }
7121:
1.547 albertel 7122: .LC_docs_reinit_warn,
7123: .LC_docs_ext_edit {
7124: font-size: x-small;
7125: }
7126:
1.545 albertel 7127: table.LC_docs_adddocs td,
7128: table.LC_docs_adddocs th {
7129: border: 1px solid #BBBBBB;
7130: padding: 4px;
7131: background: #DDDDDD;
1.543 albertel 7132: }
7133:
1.584 albertel 7134: table.LC_sty_begin {
7135: background: #BBFFBB;
7136: }
1.795 www 7137:
1.584 albertel 7138: table.LC_sty_end {
7139: background: #FFBBBB;
7140: }
7141:
1.589 raeburn 7142: table.LC_double_column {
1.803 bisitz 7143: border-width: 0;
1.589 raeburn 7144: border-collapse: collapse;
7145: width: 100%;
7146: padding: 2px;
7147: }
7148:
7149: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7150: top: 2px;
1.589 raeburn 7151: left: 2px;
7152: width: 47%;
7153: vertical-align: top;
7154: }
7155:
7156: table.LC_double_column tr td.LC_right_col {
7157: top: 2px;
1.779 bisitz 7158: right: 2px;
1.589 raeburn 7159: width: 47%;
7160: vertical-align: top;
7161: }
7162:
1.591 raeburn 7163: div.LC_left_float {
7164: float: left;
7165: padding-right: 5%;
1.597 albertel 7166: padding-bottom: 4px;
1.591 raeburn 7167: }
7168:
7169: div.LC_clear_float_header {
1.597 albertel 7170: padding-bottom: 2px;
1.591 raeburn 7171: }
7172:
7173: div.LC_clear_float_footer {
1.597 albertel 7174: padding-top: 10px;
1.591 raeburn 7175: clear: both;
7176: }
7177:
1.597 albertel 7178: div.LC_grade_show_user {
1.941 bisitz 7179: /* border-left: 5px solid $sidebg; */
7180: border-top: 5px solid #000000;
7181: margin: 50px 0 0 0;
1.936 bisitz 7182: padding: 15px 0 5px 10px;
1.597 albertel 7183: }
1.795 www 7184:
1.936 bisitz 7185: div.LC_grade_show_user_odd_row {
1.941 bisitz 7186: /* border-left: 5px solid #000000; */
7187: }
7188:
7189: div.LC_grade_show_user div.LC_Box {
7190: margin-right: 50px;
1.597 albertel 7191: }
7192:
7193: div.LC_grade_submissions,
7194: div.LC_grade_message_center,
1.936 bisitz 7195: div.LC_grade_info_links {
1.597 albertel 7196: margin: 5px;
7197: width: 99%;
7198: background: #FFFFFF;
7199: }
1.795 www 7200:
1.597 albertel 7201: div.LC_grade_submissions_header,
1.936 bisitz 7202: div.LC_grade_message_center_header {
1.705 tempelho 7203: font-weight: bold;
7204: font-size: large;
1.597 albertel 7205: }
1.795 www 7206:
1.597 albertel 7207: div.LC_grade_submissions_body,
1.936 bisitz 7208: div.LC_grade_message_center_body {
1.597 albertel 7209: border: 1px solid black;
7210: width: 99%;
7211: background: #FFFFFF;
7212: }
1.795 www 7213:
1.613 albertel 7214: table.LC_scantron_action {
7215: width: 100%;
7216: }
1.795 www 7217:
1.613 albertel 7218: table.LC_scantron_action tr th {
1.698 harmsja 7219: font-weight:bold;
7220: font-style:normal;
1.613 albertel 7221: }
1.795 www 7222:
1.779 bisitz 7223: .LC_edit_problem_header,
1.614 albertel 7224: div.LC_edit_problem_footer {
1.705 tempelho 7225: font-weight: normal;
7226: font-size: medium;
1.602 albertel 7227: margin: 2px;
1.1060 bisitz 7228: background-color: $sidebg;
1.600 albertel 7229: }
1.795 www 7230:
1.600 albertel 7231: div.LC_edit_problem_header,
1.602 albertel 7232: div.LC_edit_problem_header div,
1.614 albertel 7233: div.LC_edit_problem_footer,
7234: div.LC_edit_problem_footer div,
1.602 albertel 7235: div.LC_edit_problem_editxml_header,
7236: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7237: z-index: 100;
1.600 albertel 7238: }
1.795 www 7239:
1.600 albertel 7240: div.LC_edit_problem_header_title {
1.705 tempelho 7241: font-weight: bold;
7242: font-size: larger;
1.602 albertel 7243: background: $tabbg;
7244: padding: 3px;
1.1060 bisitz 7245: margin: 0 0 5px 0;
1.602 albertel 7246: }
1.795 www 7247:
1.602 albertel 7248: table.LC_edit_problem_header_title {
7249: width: 100%;
1.600 albertel 7250: background: $tabbg;
1.602 albertel 7251: }
7252:
1.1205 golterma 7253: div.LC_edit_actionbar {
7254: background-color: $sidebg;
1.1218 droeschl 7255: margin: 0;
7256: padding: 0;
7257: line-height: 200%;
1.602 albertel 7258: }
1.795 www 7259:
1.1218 droeschl 7260: div.LC_edit_actionbar div{
7261: padding: 0;
7262: margin: 0;
7263: display: inline-block;
1.600 albertel 7264: }
1.795 www 7265:
1.1124 bisitz 7266: .LC_edit_opt {
7267: padding-left: 1em;
7268: white-space: nowrap;
7269: }
7270:
1.1152 golterma 7271: .LC_edit_problem_latexhelper{
7272: text-align: right;
7273: }
7274:
7275: #LC_edit_problem_colorful div{
7276: margin-left: 40px;
7277: }
7278:
1.1205 golterma 7279: #LC_edit_problem_codemirror div{
7280: margin-left: 0px;
7281: }
7282:
1.911 bisitz 7283: img.stift {
1.803 bisitz 7284: border-width: 0;
7285: vertical-align: middle;
1.677 riegler 7286: }
1.680 riegler 7287:
1.923 bisitz 7288: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7289: vertical-align: top;
1.777 tempelho 7290: }
1.795 www 7291:
1.716 raeburn 7292: div.LC_createcourse {
1.911 bisitz 7293: margin: 10px 10px 10px 10px;
1.716 raeburn 7294: }
7295:
1.917 raeburn 7296: .LC_dccid {
1.1130 raeburn 7297: float: right;
1.917 raeburn 7298: margin: 0.2em 0 0 0;
7299: padding: 0;
7300: font-size: 90%;
7301: display:none;
7302: }
7303:
1.897 wenzelju 7304: ol.LC_primary_menu a:hover,
1.721 harmsja 7305: ol#LC_MenuBreadcrumbs a:hover,
7306: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7307: ul#LC_secondary_menu a:hover,
1.721 harmsja 7308: .LC_FormSectionClearButton input:hover
1.795 www 7309: ul.LC_TabContent li:hover a {
1.952 onken 7310: color:$button_hover;
1.911 bisitz 7311: text-decoration:none;
1.693 droeschl 7312: }
7313:
1.779 bisitz 7314: h1 {
1.911 bisitz 7315: padding: 0;
7316: line-height:130%;
1.693 droeschl 7317: }
1.698 harmsja 7318:
1.911 bisitz 7319: h2,
7320: h3,
7321: h4,
7322: h5,
7323: h6 {
7324: margin: 5px 0 5px 0;
7325: padding: 0;
7326: line-height:130%;
1.693 droeschl 7327: }
1.795 www 7328:
7329: .LC_hcell {
1.911 bisitz 7330: padding:3px 15px 3px 15px;
7331: margin: 0;
7332: background-color:$tabbg;
7333: color:$fontmenu;
7334: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7335: }
1.795 www 7336:
1.840 bisitz 7337: .LC_Box > .LC_hcell {
1.911 bisitz 7338: margin: 0 -10px 10px -10px;
1.835 bisitz 7339: }
7340:
1.721 harmsja 7341: .LC_noBorder {
1.911 bisitz 7342: border: 0;
1.698 harmsja 7343: }
1.693 droeschl 7344:
1.721 harmsja 7345: .LC_FormSectionClearButton input {
1.911 bisitz 7346: background-color:transparent;
7347: border: none;
7348: cursor:pointer;
7349: text-decoration:underline;
1.693 droeschl 7350: }
1.763 bisitz 7351:
7352: .LC_help_open_topic {
1.911 bisitz 7353: color: #FFFFFF;
7354: background-color: #EEEEFF;
7355: margin: 1px;
7356: padding: 4px;
7357: border: 1px solid #000033;
7358: white-space: nowrap;
7359: /* vertical-align: middle; */
1.759 neumanie 7360: }
1.693 droeschl 7361:
1.911 bisitz 7362: dl,
7363: ul,
7364: div,
7365: fieldset {
7366: margin: 10px 10px 10px 0;
7367: /* overflow: hidden; */
1.693 droeschl 7368: }
1.795 www 7369:
1.1211 raeburn 7370: article.geogebraweb div {
7371: margin: 0;
7372: }
7373:
1.838 bisitz 7374: fieldset > legend {
1.911 bisitz 7375: font-weight: bold;
7376: padding: 0 5px 0 5px;
1.838 bisitz 7377: }
7378:
1.813 bisitz 7379: #LC_nav_bar {
1.911 bisitz 7380: float: left;
1.995 raeburn 7381: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7382: margin: 0 0 2px 0;
1.807 droeschl 7383: }
7384:
1.916 droeschl 7385: #LC_realm {
7386: margin: 0.2em 0 0 0;
7387: padding: 0;
7388: font-weight: bold;
7389: text-align: center;
1.995 raeburn 7390: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7391: }
7392:
1.911 bisitz 7393: #LC_nav_bar em {
7394: font-weight: bold;
7395: font-style: normal;
1.807 droeschl 7396: }
7397:
1.897 wenzelju 7398: ol.LC_primary_menu {
1.934 droeschl 7399: margin: 0;
1.1076 raeburn 7400: padding: 0;
1.807 droeschl 7401: }
7402:
1.852 droeschl 7403: ol#LC_PathBreadcrumbs {
1.911 bisitz 7404: margin: 0;
1.693 droeschl 7405: }
7406:
1.897 wenzelju 7407: ol.LC_primary_menu li {
1.1076 raeburn 7408: color: RGB(80, 80, 80);
7409: vertical-align: middle;
7410: text-align: left;
7411: list-style: none;
1.1205 golterma 7412: position: relative;
1.1076 raeburn 7413: float: left;
1.1205 golterma 7414: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7415: line-height: 1.5em;
1.1076 raeburn 7416: }
7417:
1.1205 golterma 7418: ol.LC_primary_menu li a,
7419: ol.LC_primary_menu li p {
1.1076 raeburn 7420: display: block;
7421: margin: 0;
7422: padding: 0 5px 0 10px;
7423: text-decoration: none;
7424: }
7425:
1.1205 golterma 7426: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7427: display: inline-block;
7428: width: 95%;
7429: text-align: left;
7430: }
7431:
7432: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7433: display: inline-block;
7434: width: 5%;
7435: float: right;
7436: text-align: right;
7437: font-size: 70%;
7438: }
7439:
7440: ol.LC_primary_menu ul {
1.1076 raeburn 7441: display: none;
1.1205 golterma 7442: width: 15em;
1.1076 raeburn 7443: background-color: $data_table_light;
1.1205 golterma 7444: position: absolute;
7445: top: 100%;
1.1076 raeburn 7446: }
7447:
1.1205 golterma 7448: ol.LC_primary_menu ul ul {
7449: left: 100%;
7450: top: 0;
7451: }
7452:
7453: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7454: display: block;
7455: position: absolute;
7456: margin: 0;
7457: padding: 0;
1.1078 raeburn 7458: z-index: 2;
1.1076 raeburn 7459: }
7460:
7461: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7462: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7463: font-size: 90%;
1.911 bisitz 7464: vertical-align: top;
1.1076 raeburn 7465: float: none;
1.1079 raeburn 7466: border-left: 1px solid black;
7467: border-right: 1px solid black;
1.1205 golterma 7468: /* A dark bottom border to visualize different menu options;
7469: overwritten in the create_submenu routine for the last border-bottom of the menu */
7470: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7471: }
7472:
1.1205 golterma 7473: ol.LC_primary_menu li li p:hover {
7474: color:$button_hover;
7475: text-decoration:none;
7476: background-color:$data_table_dark;
1.1076 raeburn 7477: }
7478:
7479: ol.LC_primary_menu li li a:hover {
7480: color:$button_hover;
7481: background-color:$data_table_dark;
1.693 droeschl 7482: }
7483:
1.1205 golterma 7484: /* Font-size equal to the size of the predecessors*/
7485: ol.LC_primary_menu li:hover li li {
7486: font-size: 100%;
7487: }
7488:
1.897 wenzelju 7489: ol.LC_primary_menu li img {
1.911 bisitz 7490: vertical-align: bottom;
1.934 droeschl 7491: height: 1.1em;
1.1077 raeburn 7492: margin: 0.2em 0 0 0;
1.693 droeschl 7493: }
7494:
1.897 wenzelju 7495: ol.LC_primary_menu a {
1.911 bisitz 7496: color: RGB(80, 80, 80);
7497: text-decoration: none;
1.693 droeschl 7498: }
1.795 www 7499:
1.949 droeschl 7500: ol.LC_primary_menu a.LC_new_message {
7501: font-weight:bold;
7502: color: darkred;
7503: }
7504:
1.975 raeburn 7505: ol.LC_docs_parameters {
7506: margin-left: 0;
7507: padding: 0;
7508: list-style: none;
7509: }
7510:
7511: ol.LC_docs_parameters li {
7512: margin: 0;
7513: padding-right: 20px;
7514: display: inline;
7515: }
7516:
1.976 raeburn 7517: ol.LC_docs_parameters li:before {
7518: content: "\\002022 \\0020";
7519: }
7520:
7521: li.LC_docs_parameters_title {
7522: font-weight: bold;
7523: }
7524:
7525: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7526: content: "";
7527: }
7528:
1.897 wenzelju 7529: ul#LC_secondary_menu {
1.1107 raeburn 7530: clear: right;
1.911 bisitz 7531: color: $fontmenu;
7532: background: $tabbg;
7533: list-style: none;
7534: padding: 0;
7535: margin: 0;
7536: width: 100%;
1.995 raeburn 7537: text-align: left;
1.1107 raeburn 7538: float: left;
1.808 droeschl 7539: }
7540:
1.897 wenzelju 7541: ul#LC_secondary_menu li {
1.911 bisitz 7542: font-weight: bold;
7543: line-height: 1.8em;
1.1107 raeburn 7544: border-right: 1px solid black;
7545: float: left;
7546: }
7547:
7548: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7549: background-color: $data_table_light;
7550: }
7551:
7552: ul#LC_secondary_menu li a {
1.911 bisitz 7553: padding: 0 0.8em;
1.1107 raeburn 7554: }
7555:
7556: ul#LC_secondary_menu li ul {
7557: display: none;
7558: }
7559:
7560: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7561: display: block;
7562: position: absolute;
7563: margin: 0;
7564: padding: 0;
7565: list-style:none;
7566: float: none;
7567: background-color: $data_table_light;
7568: z-index: 2;
7569: margin-left: -1px;
7570: }
7571:
7572: ul#LC_secondary_menu li ul li {
7573: font-size: 90%;
7574: vertical-align: top;
7575: border-left: 1px solid black;
1.911 bisitz 7576: border-right: 1px solid black;
1.1119 raeburn 7577: background-color: $data_table_light;
1.1107 raeburn 7578: list-style:none;
7579: float: none;
7580: }
7581:
7582: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7583: background-color: $data_table_dark;
1.807 droeschl 7584: }
7585:
1.847 tempelho 7586: ul.LC_TabContent {
1.911 bisitz 7587: display:block;
7588: background: $sidebg;
7589: border-bottom: solid 1px $lg_border_color;
7590: list-style:none;
1.1020 raeburn 7591: margin: -1px -10px 0 -10px;
1.911 bisitz 7592: padding: 0;
1.693 droeschl 7593: }
7594:
1.795 www 7595: ul.LC_TabContent li,
7596: ul.LC_TabContentBigger li {
1.911 bisitz 7597: float:left;
1.741 harmsja 7598: }
1.795 www 7599:
1.897 wenzelju 7600: ul#LC_secondary_menu li a {
1.911 bisitz 7601: color: $fontmenu;
7602: text-decoration: none;
1.693 droeschl 7603: }
1.795 www 7604:
1.721 harmsja 7605: ul.LC_TabContent {
1.952 onken 7606: min-height:20px;
1.721 harmsja 7607: }
1.795 www 7608:
7609: ul.LC_TabContent li {
1.911 bisitz 7610: vertical-align:middle;
1.959 onken 7611: padding: 0 16px 0 10px;
1.911 bisitz 7612: background-color:$tabbg;
7613: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7614: border-left: solid 1px $font;
1.721 harmsja 7615: }
1.795 www 7616:
1.847 tempelho 7617: ul.LC_TabContent .right {
1.911 bisitz 7618: float:right;
1.847 tempelho 7619: }
7620:
1.911 bisitz 7621: ul.LC_TabContent li a,
7622: ul.LC_TabContent li {
7623: color:rgb(47,47,47);
7624: text-decoration:none;
7625: font-size:95%;
7626: font-weight:bold;
1.952 onken 7627: min-height:20px;
7628: }
7629:
1.959 onken 7630: ul.LC_TabContent li a:hover,
7631: ul.LC_TabContent li a:focus {
1.952 onken 7632: color: $button_hover;
1.959 onken 7633: background:none;
7634: outline:none;
1.952 onken 7635: }
7636:
7637: ul.LC_TabContent li:hover {
7638: color: $button_hover;
7639: cursor:pointer;
1.721 harmsja 7640: }
1.795 www 7641:
1.911 bisitz 7642: ul.LC_TabContent li.active {
1.952 onken 7643: color: $font;
1.911 bisitz 7644: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7645: border-bottom:solid 1px #FFFFFF;
7646: cursor: default;
1.744 ehlerst 7647: }
1.795 www 7648:
1.959 onken 7649: ul.LC_TabContent li.active a {
7650: color:$font;
7651: background:#FFFFFF;
7652: outline: none;
7653: }
1.1047 raeburn 7654:
7655: ul.LC_TabContent li.goback {
7656: float: left;
7657: border-left: none;
7658: }
7659:
1.870 tempelho 7660: #maincoursedoc {
1.911 bisitz 7661: clear:both;
1.870 tempelho 7662: }
7663:
7664: ul.LC_TabContentBigger {
1.911 bisitz 7665: display:block;
7666: list-style:none;
7667: padding: 0;
1.870 tempelho 7668: }
7669:
1.795 www 7670: ul.LC_TabContentBigger li {
1.911 bisitz 7671: vertical-align:bottom;
7672: height: 30px;
7673: font-size:110%;
7674: font-weight:bold;
7675: color: #737373;
1.841 tempelho 7676: }
7677:
1.957 onken 7678: ul.LC_TabContentBigger li.active {
7679: position: relative;
7680: top: 1px;
7681: }
7682:
1.870 tempelho 7683: ul.LC_TabContentBigger li a {
1.911 bisitz 7684: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7685: height: 30px;
7686: line-height: 30px;
7687: text-align: center;
7688: display: block;
7689: text-decoration: none;
1.958 onken 7690: outline: none;
1.741 harmsja 7691: }
1.795 www 7692:
1.870 tempelho 7693: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7694: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7695: color:$font;
1.744 ehlerst 7696: }
1.795 www 7697:
1.870 tempelho 7698: ul.LC_TabContentBigger li b {
1.911 bisitz 7699: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7700: display: block;
7701: float: left;
7702: padding: 0 30px;
1.957 onken 7703: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7704: }
7705:
1.956 onken 7706: ul.LC_TabContentBigger li:hover b {
7707: color:$button_hover;
7708: }
7709:
1.870 tempelho 7710: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7711: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7712: color:$font;
1.957 onken 7713: border: 0;
1.741 harmsja 7714: }
1.693 droeschl 7715:
1.870 tempelho 7716:
1.862 bisitz 7717: ul.LC_CourseBreadcrumbs {
7718: background: $sidebg;
1.1020 raeburn 7719: height: 2em;
1.862 bisitz 7720: padding-left: 10px;
1.1020 raeburn 7721: margin: 0;
1.862 bisitz 7722: list-style-position: inside;
7723: }
7724:
1.911 bisitz 7725: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7726: ol#LC_PathBreadcrumbs {
1.911 bisitz 7727: padding-left: 10px;
7728: margin: 0;
1.933 droeschl 7729: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7730: }
7731:
1.911 bisitz 7732: ol#LC_MenuBreadcrumbs li,
7733: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7734: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7735: display: inline;
1.933 droeschl 7736: white-space: normal;
1.693 droeschl 7737: }
7738:
1.823 bisitz 7739: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7740: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7741: text-decoration: none;
7742: font-size:90%;
1.693 droeschl 7743: }
1.795 www 7744:
1.969 droeschl 7745: ol#LC_MenuBreadcrumbs h1 {
7746: display: inline;
7747: font-size: 90%;
7748: line-height: 2.5em;
7749: margin: 0;
7750: padding: 0;
7751: }
7752:
1.795 www 7753: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7754: text-decoration:none;
7755: font-size:100%;
7756: font-weight:bold;
1.693 droeschl 7757: }
1.795 www 7758:
1.840 bisitz 7759: .LC_Box {
1.911 bisitz 7760: border: solid 1px $lg_border_color;
7761: padding: 0 10px 10px 10px;
1.746 neumanie 7762: }
1.795 www 7763:
1.1020 raeburn 7764: .LC_DocsBox {
7765: border: solid 1px $lg_border_color;
7766: padding: 0 0 10px 10px;
7767: }
7768:
1.795 www 7769: .LC_AboutMe_Image {
1.911 bisitz 7770: float:left;
7771: margin-right:10px;
1.747 neumanie 7772: }
1.795 www 7773:
7774: .LC_Clear_AboutMe_Image {
1.911 bisitz 7775: clear:left;
1.747 neumanie 7776: }
1.795 www 7777:
1.721 harmsja 7778: dl.LC_ListStyleClean dt {
1.911 bisitz 7779: padding-right: 5px;
7780: display: table-header-group;
1.693 droeschl 7781: }
7782:
1.721 harmsja 7783: dl.LC_ListStyleClean dd {
1.911 bisitz 7784: display: table-row;
1.693 droeschl 7785: }
7786:
1.721 harmsja 7787: .LC_ListStyleClean,
7788: .LC_ListStyleSimple,
7789: .LC_ListStyleNormal,
1.795 www 7790: .LC_ListStyleSpecial {
1.911 bisitz 7791: /* display:block; */
7792: list-style-position: inside;
7793: list-style-type: none;
7794: overflow: hidden;
7795: padding: 0;
1.693 droeschl 7796: }
7797:
1.721 harmsja 7798: .LC_ListStyleSimple li,
7799: .LC_ListStyleSimple dd,
7800: .LC_ListStyleNormal li,
7801: .LC_ListStyleNormal dd,
7802: .LC_ListStyleSpecial li,
1.795 www 7803: .LC_ListStyleSpecial dd {
1.911 bisitz 7804: margin: 0;
7805: padding: 5px 5px 5px 10px;
7806: clear: both;
1.693 droeschl 7807: }
7808:
1.721 harmsja 7809: .LC_ListStyleClean li,
7810: .LC_ListStyleClean dd {
1.911 bisitz 7811: padding-top: 0;
7812: padding-bottom: 0;
1.693 droeschl 7813: }
7814:
1.721 harmsja 7815: .LC_ListStyleSimple dd,
1.795 www 7816: .LC_ListStyleSimple li {
1.911 bisitz 7817: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7818: }
7819:
1.721 harmsja 7820: .LC_ListStyleSpecial li,
7821: .LC_ListStyleSpecial dd {
1.911 bisitz 7822: list-style-type: none;
7823: background-color: RGB(220, 220, 220);
7824: margin-bottom: 4px;
1.693 droeschl 7825: }
7826:
1.721 harmsja 7827: table.LC_SimpleTable {
1.911 bisitz 7828: margin:5px;
7829: border:solid 1px $lg_border_color;
1.795 www 7830: }
1.693 droeschl 7831:
1.721 harmsja 7832: table.LC_SimpleTable tr {
1.911 bisitz 7833: padding: 0;
7834: border:solid 1px $lg_border_color;
1.693 droeschl 7835: }
1.795 www 7836:
7837: table.LC_SimpleTable thead {
1.911 bisitz 7838: background:rgb(220,220,220);
1.693 droeschl 7839: }
7840:
1.721 harmsja 7841: div.LC_columnSection {
1.911 bisitz 7842: display: block;
7843: clear: both;
7844: overflow: hidden;
7845: margin: 0;
1.693 droeschl 7846: }
7847:
1.721 harmsja 7848: div.LC_columnSection>* {
1.911 bisitz 7849: float: left;
7850: margin: 10px 20px 10px 0;
7851: overflow:hidden;
1.693 droeschl 7852: }
1.721 harmsja 7853:
1.795 www 7854: table em {
1.911 bisitz 7855: font-weight: bold;
7856: font-style: normal;
1.748 schulted 7857: }
1.795 www 7858:
1.779 bisitz 7859: table.LC_tableBrowseRes,
1.795 www 7860: table.LC_tableOfContent {
1.911 bisitz 7861: border:none;
7862: border-spacing: 1px;
7863: padding: 3px;
7864: background-color: #FFFFFF;
7865: font-size: 90%;
1.753 droeschl 7866: }
1.789 droeschl 7867:
1.911 bisitz 7868: table.LC_tableOfContent {
7869: border-collapse: collapse;
1.789 droeschl 7870: }
7871:
1.771 droeschl 7872: table.LC_tableBrowseRes a,
1.768 schulted 7873: table.LC_tableOfContent a {
1.911 bisitz 7874: background-color: transparent;
7875: text-decoration: none;
1.753 droeschl 7876: }
7877:
1.795 www 7878: table.LC_tableOfContent img {
1.911 bisitz 7879: border: none;
7880: height: 1.3em;
7881: vertical-align: text-bottom;
7882: margin-right: 0.3em;
1.753 droeschl 7883: }
1.757 schulted 7884:
1.795 www 7885: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7886: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7887: }
7888:
1.795 www 7889: a#LC_content_toolbar_everything {
1.911 bisitz 7890: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7891: }
7892:
1.795 www 7893: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7894: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7895: }
7896:
1.795 www 7897: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7898: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7899: }
7900:
1.795 www 7901: a#LC_content_toolbar_changefolder {
1.911 bisitz 7902: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7903: }
7904:
1.795 www 7905: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7906: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7907: }
7908:
1.1043 raeburn 7909: a#LC_content_toolbar_edittoplevel {
7910: background-image:url(/res/adm/pages/edittoplevel.gif);
7911: }
7912:
1.795 www 7913: ul#LC_toolbar li a:hover {
1.911 bisitz 7914: background-position: bottom center;
1.757 schulted 7915: }
7916:
1.795 www 7917: ul#LC_toolbar {
1.911 bisitz 7918: padding: 0;
7919: margin: 2px;
7920: list-style:none;
7921: position:relative;
7922: background-color:white;
1.1082 raeburn 7923: overflow: auto;
1.757 schulted 7924: }
7925:
1.795 www 7926: ul#LC_toolbar li {
1.911 bisitz 7927: border:1px solid white;
7928: padding: 0;
7929: margin: 0;
7930: float: left;
7931: display:inline;
7932: vertical-align:middle;
1.1082 raeburn 7933: white-space: nowrap;
1.911 bisitz 7934: }
1.757 schulted 7935:
1.783 amueller 7936:
1.795 www 7937: a.LC_toolbarItem {
1.911 bisitz 7938: display:block;
7939: padding: 0;
7940: margin: 0;
7941: height: 32px;
7942: width: 32px;
7943: color:white;
7944: border: none;
7945: background-repeat:no-repeat;
7946: background-color:transparent;
1.757 schulted 7947: }
7948:
1.915 droeschl 7949: ul.LC_funclist {
7950: margin: 0;
7951: padding: 0.5em 1em 0.5em 0;
7952: }
7953:
1.933 droeschl 7954: ul.LC_funclist > li:first-child {
7955: font-weight:bold;
7956: margin-left:0.8em;
7957: }
7958:
1.915 droeschl 7959: ul.LC_funclist + ul.LC_funclist {
7960: /*
7961: left border as a seperator if we have more than
7962: one list
7963: */
7964: border-left: 1px solid $sidebg;
7965: /*
7966: this hides the left border behind the border of the
7967: outer box if element is wrapped to the next 'line'
7968: */
7969: margin-left: -1px;
7970: }
7971:
1.843 bisitz 7972: ul.LC_funclist li {
1.915 droeschl 7973: display: inline;
1.782 bisitz 7974: white-space: nowrap;
1.915 droeschl 7975: margin: 0 0 0 25px;
7976: line-height: 150%;
1.782 bisitz 7977: }
7978:
1.974 wenzelju 7979: .LC_hidden {
7980: display: none;
7981: }
7982:
1.1030 www 7983: .LCmodal-overlay {
7984: position:fixed;
7985: top:0;
7986: right:0;
7987: bottom:0;
7988: left:0;
7989: height:100%;
7990: width:100%;
7991: margin:0;
7992: padding:0;
7993: background:#999;
7994: opacity:.75;
7995: filter: alpha(opacity=75);
7996: -moz-opacity: 0.75;
7997: z-index:101;
7998: }
7999:
8000: * html .LCmodal-overlay {
8001: position: absolute;
8002: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
8003: }
8004:
8005: .LCmodal-window {
8006: position:fixed;
8007: top:50%;
8008: left:50%;
8009: margin:0;
8010: padding:0;
8011: z-index:102;
8012: }
8013:
8014: * html .LCmodal-window {
8015: position:absolute;
8016: }
8017:
8018: .LCclose-window {
8019: position:absolute;
8020: width:32px;
8021: height:32px;
8022: right:8px;
8023: top:8px;
8024: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8025: text-indent:-99999px;
8026: overflow:hidden;
8027: cursor:pointer;
8028: }
8029:
1.1100 raeburn 8030: /*
1.1231 damieng 8031: styles used for response display
8032: */
8033: div.LC_radiofoil, div.LC_rankfoil {
8034: margin: .5em 0em .5em 0em;
8035: }
8036: table.LC_itemgroup {
8037: margin-top: 1em;
8038: }
8039:
8040: /*
1.1100 raeburn 8041: styles used by TTH when "Default set of options to pass to tth/m
8042: when converting TeX" in course settings has been set
8043:
8044: option passed: -t
8045:
8046: */
8047:
8048: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8049: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8050: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8051: td div.norm {line-height:normal;}
8052:
8053: /*
8054: option passed -y3
8055: */
8056:
8057: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8058: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8059: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8060:
1.1230 damieng 8061: /*
8062: sections with roles, for content only
8063: */
8064: section[class^="role-"] {
8065: padding-left: 10px;
8066: padding-right: 5px;
8067: margin-top: 8px;
8068: margin-bottom: 8px;
8069: border: 1px solid #2A4;
8070: border-radius: 5px;
8071: box-shadow: 0px 1px 1px #BBB;
8072: }
8073: section[class^="role-"]>h1 {
8074: position: relative;
8075: margin: 0px;
8076: padding-top: 10px;
8077: padding-left: 40px;
8078: }
8079: section[class^="role-"]>h1:before {
8080: position: absolute;
8081: left: -5px;
8082: top: 5px;
8083: }
8084: section.role-activity>h1:before {
8085: content:url('/adm/daxe/images/section_icons/activity.png');
8086: }
8087: section.role-advice>h1:before {
8088: content:url('/adm/daxe/images/section_icons/advice.png');
8089: }
8090: section.role-bibliography>h1:before {
8091: content:url('/adm/daxe/images/section_icons/bibliography.png');
8092: }
8093: section.role-citation>h1:before {
8094: content:url('/adm/daxe/images/section_icons/citation.png');
8095: }
8096: section.role-conclusion>h1:before {
8097: content:url('/adm/daxe/images/section_icons/conclusion.png');
8098: }
8099: section.role-definition>h1:before {
8100: content:url('/adm/daxe/images/section_icons/definition.png');
8101: }
8102: section.role-demonstration>h1:before {
8103: content:url('/adm/daxe/images/section_icons/demonstration.png');
8104: }
8105: section.role-example>h1:before {
8106: content:url('/adm/daxe/images/section_icons/example.png');
8107: }
8108: section.role-explanation>h1:before {
8109: content:url('/adm/daxe/images/section_icons/explanation.png');
8110: }
8111: section.role-introduction>h1:before {
8112: content:url('/adm/daxe/images/section_icons/introduction.png');
8113: }
8114: section.role-method>h1:before {
8115: content:url('/adm/daxe/images/section_icons/method.png');
8116: }
8117: section.role-more_information>h1:before {
8118: content:url('/adm/daxe/images/section_icons/more_information.png');
8119: }
8120: section.role-objectives>h1:before {
8121: content:url('/adm/daxe/images/section_icons/objectives.png');
8122: }
8123: section.role-prerequisites>h1:before {
8124: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8125: }
8126: section.role-remark>h1:before {
8127: content:url('/adm/daxe/images/section_icons/remark.png');
8128: }
8129: section.role-reminder>h1:before {
8130: content:url('/adm/daxe/images/section_icons/reminder.png');
8131: }
8132: section.role-summary>h1:before {
8133: content:url('/adm/daxe/images/section_icons/summary.png');
8134: }
8135: section.role-syntax>h1:before {
8136: content:url('/adm/daxe/images/section_icons/syntax.png');
8137: }
8138: section.role-warning>h1:before {
8139: content:url('/adm/daxe/images/section_icons/warning.png');
8140: }
8141:
1.1269 raeburn 8142: #LC_minitab_header {
8143: float:left;
8144: width:100%;
8145: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8146: font-size:93%;
8147: line-height:normal;
8148: margin: 0.5em 0 0.5em 0;
8149: }
8150: #LC_minitab_header ul {
8151: margin:0;
8152: padding:10px 10px 0;
8153: list-style:none;
8154: }
8155: #LC_minitab_header li {
8156: float:left;
8157: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8158: margin:0;
8159: padding:0 0 0 9px;
8160: }
8161: #LC_minitab_header a {
8162: display:block;
8163: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8164: padding:5px 15px 4px 6px;
8165: }
8166: #LC_minitab_header #LC_current_minitab {
8167: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8168: }
8169: #LC_minitab_header #LC_current_minitab a {
8170: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8171: padding-bottom:5px;
8172: }
8173:
8174:
1.343 albertel 8175: END
8176: }
8177:
1.306 albertel 8178: =pod
8179:
8180: =item * &headtag()
8181:
8182: Returns a uniform footer for LON-CAPA web pages.
8183:
1.307 albertel 8184: Inputs: $title - optional title for the head
8185: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8186: $args - optional arguments
1.319 albertel 8187: force_register - if is true call registerurl so the remote is
8188: informed
1.415 albertel 8189: redirect -> array ref of
8190: 1- seconds before redirect occurs
8191: 2- url to redirect to
8192: 3- whether the side effect should occur
1.315 albertel 8193: (side effect of setting
8194: $env{'internal.head.redirect'} to the url
8195: redirected too)
1.352 albertel 8196: domain -> force to color decorate a page for a specific
8197: domain
8198: function -> force usage of a specific rolish color scheme
8199: bgcolor -> override the default page bgcolor
1.460 albertel 8200: no_auto_mt_title
8201: -> prevent &mt()ing the title arg
1.464 albertel 8202:
1.306 albertel 8203: =cut
8204:
8205: sub headtag {
1.313 albertel 8206: my ($title,$head_extra,$args) = @_;
1.306 albertel 8207:
1.363 albertel 8208: my $function = $args->{'function'} || &get_users_function();
8209: my $domain = $args->{'domain'} || &determinedomain();
8210: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8211: my $httphost = $args->{'use_absolute'};
1.418 albertel 8212: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8213: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8214: #time(),
1.418 albertel 8215: $env{'environment.color.timestamp'},
1.363 albertel 8216: $function,$domain,$bgcolor);
8217:
1.369 www 8218: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8219:
1.308 albertel 8220: my $result =
8221: '<head>'.
1.1160 raeburn 8222: &font_settings($args);
1.319 albertel 8223:
1.1188 raeburn 8224: my $inhibitprint;
8225: if ($args->{'print_suppress'}) {
8226: $inhibitprint = &print_suppression();
8227: }
1.1064 raeburn 8228:
1.461 albertel 8229: if (!$args->{'frameset'}) {
8230: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8231: }
1.962 droeschl 8232: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8233: $result .= Apache::lonxml::display_title();
1.319 albertel 8234: }
1.436 albertel 8235: if (!$args->{'no_nav_bar'}
8236: && !$args->{'only_body'}
8237: && !$args->{'frameset'}) {
1.1154 raeburn 8238: $result .= &help_menu_js($httphost);
1.1032 www 8239: $result.=&modal_window();
1.1038 www 8240: $result.=&togglebox_script();
1.1034 www 8241: $result.=&wishlist_window();
1.1041 www 8242: $result.=&LCprogressbarUpdate_script();
1.1034 www 8243: } else {
8244: if ($args->{'add_modal'}) {
8245: $result.=&modal_window();
8246: }
8247: if ($args->{'add_wishlist'}) {
8248: $result.=&wishlist_window();
8249: }
1.1038 www 8250: if ($args->{'add_togglebox'}) {
8251: $result.=&togglebox_script();
8252: }
1.1041 www 8253: if ($args->{'add_progressbar'}) {
8254: $result.=&LCprogressbarUpdate_script();
8255: }
1.436 albertel 8256: }
1.314 albertel 8257: if (ref($args->{'redirect'})) {
1.414 albertel 8258: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8259: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8260: if (!$inhibit_continue) {
8261: $env{'internal.head.redirect'} = $url;
8262: }
1.313 albertel 8263: $result.=<<ADDMETA
8264: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8265: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8266: ADDMETA
1.1210 raeburn 8267: } else {
8268: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8269: my $requrl = $env{'request.uri'};
8270: if ($requrl eq '') {
8271: $requrl = $ENV{'REQUEST_URI'};
8272: $requrl =~ s/\?.+$//;
8273: }
8274: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8275: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8276: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8277: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8278: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8279: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
8280: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8281: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
8282: if ($domdefs{'offloadnow'}{$lonhost}) {
8283: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
8284: if (($newserver) && ($newserver ne $lonhost)) {
8285: my $numsec = 5;
8286: my $timeout = $numsec * 1000;
8287: my ($newurl,$locknum,%locks,$msg);
8288: if ($env{'request.role.adv'}) {
8289: ($locknum,%locks) = &Apache::lonnet::get_locks();
8290: }
8291: my $disable_submit = 0;
8292: if ($requrl =~ /$LONCAPA::assess_re/) {
8293: $disable_submit = 1;
8294: }
8295: if ($locknum) {
8296: my @lockinfo = sort(values(%locks));
8297: $msg = &mt('Once the following tasks are complete: ')."\\n".
8298: join(", ",sort(values(%locks)))."\\n".
8299: &mt('your session will be transferred to a different server, after you click "Roles".');
8300: } else {
8301: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8302: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
8303: }
8304: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8305: $newurl = '/adm/switchserver?otherserver='.$newserver;
8306: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8307: $newurl .= '&role='.$env{'request.role'};
8308: }
8309: if ($env{'request.symb'}) {
8310: $newurl .= '&symb='.$env{'request.symb'};
8311: } else {
8312: $newurl .= '&origurl='.$requrl;
8313: }
8314: }
1.1222 damieng 8315: &js_escape(\$msg);
1.1210 raeburn 8316: $result.=<<OFFLOAD
8317: <meta http-equiv="pragma" content="no-cache" />
8318: <script type="text/javascript">
1.1215 raeburn 8319: // <![CDATA[
1.1210 raeburn 8320: function LC_Offload_Now() {
8321: var dest = "$newurl";
8322: if (dest != '') {
8323: window.location.href="$newurl";
8324: }
8325: }
1.1214 raeburn 8326: \$(document).ready(function () {
8327: window.alert('$msg');
8328: if ($disable_submit) {
1.1210 raeburn 8329: \$(".LC_hwk_submit").prop("disabled", true);
8330: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8331: }
8332: setTimeout('LC_Offload_Now()', $timeout);
8333: });
1.1215 raeburn 8334: // ]]>
1.1210 raeburn 8335: </script>
8336: OFFLOAD
8337: }
8338: }
8339: }
8340: }
8341: }
8342: }
1.313 albertel 8343: }
1.306 albertel 8344: if (!defined($title)) {
8345: $title = 'The LearningOnline Network with CAPA';
8346: }
1.460 albertel 8347: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8348: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8349: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8350: if (!$args->{'frameset'}) {
8351: $result .= ' /';
8352: }
8353: $result .= '>'
1.1064 raeburn 8354: .$inhibitprint
1.414 albertel 8355: .$head_extra;
1.1242 raeburn 8356: my $clientmobile;
8357: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8358: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8359: } else {
8360: $clientmobile = $env{'browser.mobile'};
8361: }
8362: if ($clientmobile) {
1.1137 raeburn 8363: $result .= '
8364: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8365: <meta name="apple-mobile-web-app-capable" content="yes" />';
8366: }
1.1278 raeburn 8367: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 8368: return $result.'</head>';
1.306 albertel 8369: }
8370:
8371: =pod
8372:
1.340 albertel 8373: =item * &font_settings()
8374:
8375: Returns neccessary <meta> to set the proper encoding
8376:
1.1160 raeburn 8377: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8378:
8379: =cut
8380:
8381: sub font_settings {
1.1160 raeburn 8382: my ($args) = @_;
1.340 albertel 8383: my $headerstring='';
1.1160 raeburn 8384: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8385: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8386: $headerstring.=
8387: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8388: if (!$args->{'frameset'}) {
8389: $headerstring.= ' /';
8390: }
8391: $headerstring .= '>'."\n";
1.340 albertel 8392: }
8393: return $headerstring;
8394: }
8395:
1.341 albertel 8396: =pod
8397:
1.1064 raeburn 8398: =item * &print_suppression()
8399:
8400: In course context returns css which causes the body to be blank when media="print",
8401: if printout generation is unavailable for the current resource.
8402:
8403: This could be because:
8404:
8405: (a) printstartdate is in the future
8406:
8407: (b) printenddate is in the past
8408:
8409: (c) there is an active exam block with "printout"
8410: functionality blocked
8411:
8412: Users with pav, pfo or evb privileges are exempt.
8413:
8414: Inputs: none
8415:
8416: =cut
8417:
8418:
8419: sub print_suppression {
8420: my $noprint;
8421: if ($env{'request.course.id'}) {
8422: my $scope = $env{'request.course.id'};
8423: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8424: (&Apache::lonnet::allowed('pfo',$scope))) {
8425: return;
8426: }
8427: if ($env{'request.course.sec'} ne '') {
8428: $scope .= "/$env{'request.course.sec'}";
8429: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8430: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8431: return;
1.1064 raeburn 8432: }
8433: }
8434: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8435: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8436: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8437: if ($blocked) {
8438: my $checkrole = "cm./$cdom/$cnum";
8439: if ($env{'request.course.sec'} ne '') {
8440: $checkrole .= "/$env{'request.course.sec'}";
8441: }
8442: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8443: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8444: $noprint = 1;
8445: }
8446: }
8447: unless ($noprint) {
8448: my $symb = &Apache::lonnet::symbread();
8449: if ($symb ne '') {
8450: my $navmap = Apache::lonnavmaps::navmap->new();
8451: if (ref($navmap)) {
8452: my $res = $navmap->getBySymb($symb);
8453: if (ref($res)) {
8454: if (!$res->resprintable()) {
8455: $noprint = 1;
8456: }
8457: }
8458: }
8459: }
8460: }
8461: if ($noprint) {
8462: return <<"ENDSTYLE";
8463: <style type="text/css" media="print">
8464: body { display:none }
8465: </style>
8466: ENDSTYLE
8467: }
8468: }
8469: return;
8470: }
8471:
8472: =pod
8473:
1.341 albertel 8474: =item * &xml_begin()
8475:
8476: Returns the needed doctype and <html>
8477:
8478: Inputs: none
8479:
8480: =cut
8481:
8482: sub xml_begin {
1.1168 raeburn 8483: my ($is_frameset) = @_;
1.341 albertel 8484: my $output='';
8485:
8486: if ($env{'browser.mathml'}) {
8487: $output='<?xml version="1.0"?>'
8488: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8489: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8490:
8491: # .'<!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">] >'
8492: .'<!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">'
8493: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8494: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8495: } elsif ($is_frameset) {
8496: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8497: '<html>'."\n";
1.341 albertel 8498: } else {
1.1168 raeburn 8499: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8500: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8501: }
8502: return $output;
8503: }
1.340 albertel 8504:
8505: =pod
8506:
1.306 albertel 8507: =item * &start_page()
8508:
8509: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8510:
1.648 raeburn 8511: Inputs:
8512:
8513: =over 4
8514:
8515: $title - optional title for the page
8516:
8517: $head_extra - optional extra HTML to incude inside the <head>
8518:
8519: $args - additional optional args supported are:
8520:
8521: =over 8
8522:
8523: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8524: arg on
1.814 bisitz 8525: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8526: add_entries -> additional attributes to add to the <body>
8527: domain -> force to color decorate a page for a
1.317 albertel 8528: specific domain
1.648 raeburn 8529: function -> force usage of a specific rolish color
1.317 albertel 8530: scheme
1.648 raeburn 8531: redirect -> see &headtag()
8532: bgcolor -> override the default page bg color
8533: js_ready -> return a string ready for being used in
1.317 albertel 8534: a javascript writeln
1.648 raeburn 8535: html_encode -> return a string ready for being used in
1.320 albertel 8536: a html attribute
1.648 raeburn 8537: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8538: $forcereg arg
1.648 raeburn 8539: frameset -> if true will start with a <frameset>
1.330 albertel 8540: rather than <body>
1.648 raeburn 8541: skip_phases -> hash ref of
1.338 albertel 8542: head -> skip the <html><head> generation
8543: body -> skip all <body> generation
1.648 raeburn 8544: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8545: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8546: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 8547: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8548: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 8549: group -> includes the current group, if page is for a
1.1274 raeburn 8550: specific group
8551: use_absolute -> for request for external resource or syllabus, this
8552: will contain https://<hostname> if server uses
8553: https (as per hosts.tab), but request is for http
8554: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8555:
1.648 raeburn 8556: =back
1.460 albertel 8557:
1.648 raeburn 8558: =back
1.562 albertel 8559:
1.306 albertel 8560: =cut
8561:
8562: sub start_page {
1.309 albertel 8563: my ($title,$head_extra,$args) = @_;
1.318 albertel 8564: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8565:
1.315 albertel 8566: $env{'internal.start_page'}++;
1.1096 raeburn 8567: my ($result,@advtools);
1.964 droeschl 8568:
1.338 albertel 8569: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8570: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8571: }
8572:
8573: if (! exists($args->{'skip_phases'}{'body'}) ) {
8574: if ($args->{'frameset'}) {
8575: my $attr_string = &make_attr_string($args->{'force_register'},
8576: $args->{'add_entries'});
8577: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8578: } else {
8579: $result .=
8580: &bodytag($title,
8581: $args->{'function'}, $args->{'add_entries'},
8582: $args->{'only_body'}, $args->{'domain'},
8583: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8584: $args->{'bgcolor'}, $args,
8585: \@advtools);
1.831 bisitz 8586: }
1.330 albertel 8587: }
1.338 albertel 8588:
1.315 albertel 8589: if ($args->{'js_ready'}) {
1.713 kaisler 8590: $result = &js_ready($result);
1.315 albertel 8591: }
1.320 albertel 8592: if ($args->{'html_encode'}) {
1.713 kaisler 8593: $result = &html_encode($result);
8594: }
8595:
1.813 bisitz 8596: # Preparation for new and consistent functionlist at top of screen
8597: # if ($args->{'functionlist'}) {
8598: # $result .= &build_functionlist();
8599: #}
8600:
1.964 droeschl 8601: # Don't add anything more if only_body wanted or in const space
8602: return $result if $args->{'only_body'}
8603: || $env{'request.state'} eq 'construct';
1.813 bisitz 8604:
8605: #Breadcrumbs
1.758 kaisler 8606: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8607: &Apache::lonhtmlcommon::clear_breadcrumbs();
8608: #if any br links exists, add them to the breadcrumbs
8609: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8610: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8611: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8612: }
8613: }
1.1096 raeburn 8614: # if @advtools array contains items add then to the breadcrumbs
8615: if (@advtools > 0) {
8616: &Apache::lonmenu::advtools_crumbs(@advtools);
8617: }
1.1272 raeburn 8618: my $menulink;
8619: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8620: if ((exists($args->{'bread_crumbs_nomenu'})) ||
8621: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
8622: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
8623: (!$env{'request.role.adv'}))) {
8624: $menulink = 0;
8625: } else {
8626: undef($menulink);
8627: }
1.758 kaisler 8628: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8629: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 8630: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 8631: } else {
1.1272 raeburn 8632: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8633: }
1.320 albertel 8634: }
1.315 albertel 8635: return $result;
1.306 albertel 8636: }
8637:
8638: sub end_page {
1.315 albertel 8639: my ($args) = @_;
8640: $env{'internal.end_page'}++;
1.330 albertel 8641: my $result;
1.335 albertel 8642: if ($args->{'discussion'}) {
8643: my ($target,$parser);
8644: if (ref($args->{'discussion'})) {
8645: ($target,$parser) =($args->{'discussion'}{'target'},
8646: $args->{'discussion'}{'parser'});
8647: }
8648: $result .= &Apache::lonxml::xmlend($target,$parser);
8649: }
1.330 albertel 8650: if ($args->{'frameset'}) {
8651: $result .= '</frameset>';
8652: } else {
1.635 raeburn 8653: $result .= &endbodytag($args);
1.330 albertel 8654: }
1.1080 raeburn 8655: unless ($args->{'notbody'}) {
8656: $result .= "\n</html>";
8657: }
1.330 albertel 8658:
1.315 albertel 8659: if ($args->{'js_ready'}) {
1.317 albertel 8660: $result = &js_ready($result);
1.315 albertel 8661: }
1.335 albertel 8662:
1.320 albertel 8663: if ($args->{'html_encode'}) {
8664: $result = &html_encode($result);
8665: }
1.335 albertel 8666:
1.315 albertel 8667: return $result;
8668: }
8669:
1.1034 www 8670: sub wishlist_window {
8671: return(<<'ENDWISHLIST');
1.1046 raeburn 8672: <script type="text/javascript">
1.1034 www 8673: // <![CDATA[
8674: // <!-- BEGIN LON-CAPA Internal
8675: function set_wishlistlink(title, path) {
8676: if (!title) {
8677: title = document.title;
8678: title = title.replace(/^LON-CAPA /,'');
8679: }
1.1175 raeburn 8680: title = encodeURIComponent(title);
1.1203 raeburn 8681: title = title.replace("'","\\\'");
1.1034 www 8682: if (!path) {
8683: path = location.pathname;
8684: }
1.1175 raeburn 8685: path = encodeURIComponent(path);
1.1203 raeburn 8686: path = path.replace("'","\\\'");
1.1034 www 8687: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8688: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8689: }
8690: // END LON-CAPA Internal -->
8691: // ]]>
8692: </script>
8693: ENDWISHLIST
8694: }
8695:
1.1030 www 8696: sub modal_window {
8697: return(<<'ENDMODAL');
1.1046 raeburn 8698: <script type="text/javascript">
1.1030 www 8699: // <![CDATA[
8700: // <!-- BEGIN LON-CAPA Internal
8701: var modalWindow = {
8702: parent:"body",
8703: windowId:null,
8704: content:null,
8705: width:null,
8706: height:null,
8707: close:function()
8708: {
8709: $(".LCmodal-window").remove();
8710: $(".LCmodal-overlay").remove();
8711: },
8712: open:function()
8713: {
8714: var modal = "";
8715: modal += "<div class=\"LCmodal-overlay\"></div>";
8716: 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;\">";
8717: modal += this.content;
8718: modal += "</div>";
8719:
8720: $(this.parent).append(modal);
8721:
8722: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8723: $(".LCclose-window").click(function(){modalWindow.close();});
8724: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8725: }
8726: };
1.1140 raeburn 8727: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8728: {
1.1266 raeburn 8729: source = source.replace(/'/g,"'");
1.1030 www 8730: modalWindow.windowId = "myModal";
8731: modalWindow.width = width;
8732: modalWindow.height = height;
1.1196 raeburn 8733: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8734: modalWindow.open();
1.1208 raeburn 8735: };
1.1030 www 8736: // END LON-CAPA Internal -->
8737: // ]]>
8738: </script>
8739: ENDMODAL
8740: }
8741:
8742: sub modal_link {
1.1140 raeburn 8743: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8744: unless ($width) { $width=480; }
8745: unless ($height) { $height=400; }
1.1031 www 8746: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 8747: unless ($transparency) { $transparency='true'; }
8748:
1.1074 raeburn 8749: my $target_attr;
8750: if (defined($target)) {
8751: $target_attr = 'target="'.$target.'"';
8752: }
8753: return <<"ENDLINK";
1.1140 raeburn 8754: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8755: $linktext</a>
8756: ENDLINK
1.1030 www 8757: }
8758:
1.1032 www 8759: sub modal_adhoc_script {
8760: my ($funcname,$width,$height,$content)=@_;
8761: return (<<ENDADHOC);
1.1046 raeburn 8762: <script type="text/javascript">
1.1032 www 8763: // <![CDATA[
8764: var $funcname = function()
8765: {
8766: modalWindow.windowId = "myModal";
8767: modalWindow.width = $width;
8768: modalWindow.height = $height;
8769: modalWindow.content = '$content';
8770: modalWindow.open();
8771: };
8772: // ]]>
8773: </script>
8774: ENDADHOC
8775: }
8776:
1.1041 www 8777: sub modal_adhoc_inner {
8778: my ($funcname,$width,$height,$content)=@_;
8779: my $innerwidth=$width-20;
8780: $content=&js_ready(
1.1140 raeburn 8781: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
8782: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8783: $content.
1.1041 www 8784: &end_scrollbox().
1.1140 raeburn 8785: &end_page()
1.1041 www 8786: );
8787: return &modal_adhoc_script($funcname,$width,$height,$content);
8788: }
8789:
8790: sub modal_adhoc_window {
8791: my ($funcname,$width,$height,$content,$linktext)=@_;
8792: return &modal_adhoc_inner($funcname,$width,$height,$content).
8793: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8794: }
8795:
8796: sub modal_adhoc_launch {
8797: my ($funcname,$width,$height,$content)=@_;
8798: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8799: <script type="text/javascript">
8800: // <![CDATA[
8801: $funcname();
8802: // ]]>
8803: </script>
8804: ENDLAUNCH
8805: }
8806:
8807: sub modal_adhoc_close {
8808: return (<<ENDCLOSE);
8809: <script type="text/javascript">
8810: // <![CDATA[
8811: modalWindow.close();
8812: // ]]>
8813: </script>
8814: ENDCLOSE
8815: }
8816:
1.1038 www 8817: sub togglebox_script {
8818: return(<<ENDTOGGLE);
8819: <script type="text/javascript">
8820: // <![CDATA[
8821: function LCtoggleDisplay(id,hidetext,showtext) {
8822: link = document.getElementById(id + "link").childNodes[0];
8823: with (document.getElementById(id).style) {
8824: if (display == "none" ) {
8825: display = "inline";
8826: link.nodeValue = hidetext;
8827: } else {
8828: display = "none";
8829: link.nodeValue = showtext;
8830: }
8831: }
8832: }
8833: // ]]>
8834: </script>
8835: ENDTOGGLE
8836: }
8837:
1.1039 www 8838: sub start_togglebox {
8839: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8840: unless ($heading) { $heading=''; } else { $heading.=' '; }
8841: unless ($showtext) { $showtext=&mt('show'); }
8842: unless ($hidetext) { $hidetext=&mt('hide'); }
8843: unless ($headerbg) { $headerbg='#FFFFFF'; }
8844: return &start_data_table().
8845: &start_data_table_header_row().
8846: '<td bgcolor="'.$headerbg.'">'.$heading.
8847: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8848: $showtext.'\')">'.$showtext.'</a>]</td>'.
8849: &end_data_table_header_row().
8850: '<tr id="'.$id.'" style="display:none""><td>';
8851: }
8852:
8853: sub end_togglebox {
8854: return '</td></tr>'.&end_data_table();
8855: }
8856:
1.1041 www 8857: sub LCprogressbar_script {
1.1045 www 8858: my ($id)=@_;
1.1041 www 8859: return(<<ENDPROGRESS);
8860: <script type="text/javascript">
8861: // <![CDATA[
1.1045 www 8862: \$('#progressbar$id').progressbar({
1.1041 www 8863: value: 0,
8864: change: function(event, ui) {
8865: var newVal = \$(this).progressbar('option', 'value');
8866: \$('.pblabel', this).text(LCprogressTxt);
8867: }
8868: });
8869: // ]]>
8870: </script>
8871: ENDPROGRESS
8872: }
8873:
8874: sub LCprogressbarUpdate_script {
8875: return(<<ENDPROGRESSUPDATE);
8876: <style type="text/css">
8877: .ui-progressbar { position:relative; }
8878: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8879: </style>
8880: <script type="text/javascript">
8881: // <![CDATA[
1.1045 www 8882: var LCprogressTxt='---';
8883:
8884: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8885: LCprogressTxt=progresstext;
1.1045 www 8886: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8887: }
8888: // ]]>
8889: </script>
8890: ENDPROGRESSUPDATE
8891: }
8892:
1.1042 www 8893: my $LClastpercent;
1.1045 www 8894: my $LCidcnt;
8895: my $LCcurrentid;
1.1042 www 8896:
1.1041 www 8897: sub LCprogressbar {
1.1042 www 8898: my ($r)=(@_);
8899: $LClastpercent=0;
1.1045 www 8900: $LCidcnt++;
8901: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8902: my $starting=&mt('Starting');
8903: my $content=(<<ENDPROGBAR);
1.1045 www 8904: <div id="progressbar$LCcurrentid">
1.1041 www 8905: <span class="pblabel">$starting</span>
8906: </div>
8907: ENDPROGBAR
1.1045 www 8908: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8909: }
8910:
8911: sub LCprogressbarUpdate {
1.1042 www 8912: my ($r,$val,$text)=@_;
8913: unless ($val) {
8914: if ($LClastpercent) {
8915: $val=$LClastpercent;
8916: } else {
8917: $val=0;
8918: }
8919: }
1.1041 www 8920: if ($val<0) { $val=0; }
8921: if ($val>100) { $val=0; }
1.1042 www 8922: $LClastpercent=$val;
1.1041 www 8923: unless ($text) { $text=$val.'%'; }
8924: $text=&js_ready($text);
1.1044 www 8925: &r_print($r,<<ENDUPDATE);
1.1041 www 8926: <script type="text/javascript">
8927: // <![CDATA[
1.1045 www 8928: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8929: // ]]>
8930: </script>
8931: ENDUPDATE
1.1035 www 8932: }
8933:
1.1042 www 8934: sub LCprogressbarClose {
8935: my ($r)=@_;
8936: $LClastpercent=0;
1.1044 www 8937: &r_print($r,<<ENDCLOSE);
1.1042 www 8938: <script type="text/javascript">
8939: // <![CDATA[
1.1045 www 8940: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8941: // ]]>
8942: </script>
8943: ENDCLOSE
1.1044 www 8944: }
8945:
8946: sub r_print {
8947: my ($r,$to_print)=@_;
8948: if ($r) {
8949: $r->print($to_print);
8950: $r->rflush();
8951: } else {
8952: print($to_print);
8953: }
1.1042 www 8954: }
8955:
1.320 albertel 8956: sub html_encode {
8957: my ($result) = @_;
8958:
1.322 albertel 8959: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8960:
8961: return $result;
8962: }
1.1044 www 8963:
1.317 albertel 8964: sub js_ready {
8965: my ($result) = @_;
8966:
1.323 albertel 8967: $result =~ s/[\n\r]/ /xmsg;
8968: $result =~ s/\\/\\\\/xmsg;
8969: $result =~ s/'/\\'/xmsg;
1.372 albertel 8970: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8971:
8972: return $result;
8973: }
8974:
1.315 albertel 8975: sub validate_page {
8976: if ( exists($env{'internal.start_page'})
1.316 albertel 8977: && $env{'internal.start_page'} > 1) {
8978: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8979: $env{'internal.start_page'}.' '.
1.316 albertel 8980: $ENV{'request.filename'});
1.315 albertel 8981: }
8982: if ( exists($env{'internal.end_page'})
1.316 albertel 8983: && $env{'internal.end_page'} > 1) {
8984: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8985: $env{'internal.end_page'}.' '.
1.316 albertel 8986: $env{'request.filename'});
1.315 albertel 8987: }
8988: if ( exists($env{'internal.start_page'})
8989: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8990: &Apache::lonnet::logthis('start_page called without end_page '.
8991: $env{'request.filename'});
1.315 albertel 8992: }
8993: if ( ! exists($env{'internal.start_page'})
8994: && exists($env{'internal.end_page'})) {
1.316 albertel 8995: &Apache::lonnet::logthis('end_page called without start_page'.
8996: $env{'request.filename'});
1.315 albertel 8997: }
1.306 albertel 8998: }
1.315 albertel 8999:
1.996 www 9000:
9001: sub start_scrollbox {
1.1140 raeburn 9002: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 9003: unless ($outerwidth) { $outerwidth='520px'; }
9004: unless ($width) { $width='500px'; }
9005: unless ($height) { $height='200px'; }
1.1075 raeburn 9006: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 9007: if ($id ne '') {
1.1140 raeburn 9008: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9009: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9010: }
1.1075 raeburn 9011: if ($bgcolor ne '') {
9012: $tdcol = "background-color: $bgcolor;";
9013: }
1.1137 raeburn 9014: my $nicescroll_js;
9015: if ($env{'browser.mobile'}) {
1.1140 raeburn 9016: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9017: }
9018: return <<"END";
9019: $nicescroll_js
9020:
9021: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9022: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9023: END
9024: }
9025:
9026: sub end_scrollbox {
9027: return '</div></td></tr></table>';
9028: }
9029:
9030: sub nicescroll_javascript {
9031: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9032: my %options;
9033: if (ref($cursor) eq 'HASH') {
9034: %options = %{$cursor};
9035: }
9036: unless ($options{'railalign'} =~ /^left|right$/) {
9037: $options{'railalign'} = 'left';
9038: }
9039: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9040: my $function = &get_users_function();
9041: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9042: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9043: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9044: }
1.1140 raeburn 9045: }
9046: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9047: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9048: $options{'cursoropacity'}='1.0';
9049: }
1.1140 raeburn 9050: } else {
9051: $options{'cursoropacity'}='1.0';
9052: }
9053: if ($options{'cursorfixedheight'} eq 'none') {
9054: delete($options{'cursorfixedheight'});
9055: } else {
9056: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9057: }
9058: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9059: delete($options{'railoffset'});
9060: }
9061: my @niceoptions;
9062: while (my($key,$value) = each(%options)) {
9063: if ($value =~ /^\{.+\}$/) {
9064: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9065: } else {
1.1140 raeburn 9066: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9067: }
1.1140 raeburn 9068: }
9069: my $nicescroll_js = '
1.1137 raeburn 9070: $(document).ready(
1.1140 raeburn 9071: function() {
9072: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9073: }
1.1137 raeburn 9074: );
9075: ';
1.1140 raeburn 9076: if ($framecheck) {
9077: $nicescroll_js .= '
9078: function expand_div(caller) {
9079: if (top === self) {
9080: document.getElementById("'.$id.'").style.width = "auto";
9081: document.getElementById("'.$id.'").style.height = "auto";
9082: } else {
9083: try {
9084: if (parent.frames) {
9085: if (parent.frames.length > 1) {
9086: var framesrc = parent.frames[1].location.href;
9087: var currsrc = framesrc.replace(/\#.*$/,"");
9088: if ((caller == "search") || (currsrc == "'.$location.'")) {
9089: document.getElementById("'.$id.'").style.width = "auto";
9090: document.getElementById("'.$id.'").style.height = "auto";
9091: }
9092: }
9093: }
9094: } catch (e) {
9095: return;
9096: }
1.1137 raeburn 9097: }
1.1140 raeburn 9098: return;
1.996 www 9099: }
1.1140 raeburn 9100: ';
9101: }
9102: if ($needjsready) {
9103: $nicescroll_js = '
9104: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9105: } else {
9106: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9107: }
9108: return $nicescroll_js;
1.996 www 9109: }
9110:
1.318 albertel 9111: sub simple_error_page {
1.1150 bisitz 9112: my ($r,$title,$msg,$args) = @_;
1.1151 raeburn 9113: if (ref($args) eq 'HASH') {
9114: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
9115: } else {
9116: $msg = &mt($msg);
9117: }
1.1150 bisitz 9118:
1.318 albertel 9119: my $page =
9120: &Apache::loncommon::start_page($title).
1.1150 bisitz 9121: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9122: &Apache::loncommon::end_page();
9123: if (ref($r)) {
9124: $r->print($page);
1.327 albertel 9125: return;
1.318 albertel 9126: }
9127: return $page;
9128: }
1.347 albertel 9129:
9130: {
1.610 albertel 9131: my @row_count;
1.961 onken 9132:
9133: sub start_data_table_count {
9134: unshift(@row_count, 0);
9135: return;
9136: }
9137:
9138: sub end_data_table_count {
9139: shift(@row_count);
9140: return;
9141: }
9142:
1.347 albertel 9143: sub start_data_table {
1.1018 raeburn 9144: my ($add_class,$id) = @_;
1.422 albertel 9145: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9146: my $table_id;
9147: if (defined($id)) {
9148: $table_id = ' id="'.$id.'"';
9149: }
1.961 onken 9150: &start_data_table_count();
1.1018 raeburn 9151: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9152: }
9153:
9154: sub end_data_table {
1.961 onken 9155: &end_data_table_count();
1.389 albertel 9156: return '</table>'."\n";;
1.347 albertel 9157: }
9158:
9159: sub start_data_table_row {
1.974 wenzelju 9160: my ($add_class, $id) = @_;
1.610 albertel 9161: $row_count[0]++;
9162: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9163: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9164: $id = (' id="'.$id.'"') unless ($id eq '');
9165: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9166: }
1.471 banghart 9167:
9168: sub continue_data_table_row {
1.974 wenzelju 9169: my ($add_class, $id) = @_;
1.610 albertel 9170: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9171: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9172: $id = (' id="'.$id.'"') unless ($id eq '');
9173: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9174: }
1.347 albertel 9175:
9176: sub end_data_table_row {
1.389 albertel 9177: return '</tr>'."\n";;
1.347 albertel 9178: }
1.367 www 9179:
1.421 albertel 9180: sub start_data_table_empty_row {
1.707 bisitz 9181: # $row_count[0]++;
1.421 albertel 9182: return '<tr class="LC_empty_row" >'."\n";;
9183: }
9184:
9185: sub end_data_table_empty_row {
9186: return '</tr>'."\n";;
9187: }
9188:
1.367 www 9189: sub start_data_table_header_row {
1.389 albertel 9190: return '<tr class="LC_header_row">'."\n";;
1.367 www 9191: }
9192:
9193: sub end_data_table_header_row {
1.389 albertel 9194: return '</tr>'."\n";;
1.367 www 9195: }
1.890 droeschl 9196:
9197: sub data_table_caption {
9198: my $caption = shift;
9199: return "<caption class=\"LC_caption\">$caption</caption>";
9200: }
1.347 albertel 9201: }
9202:
1.548 albertel 9203: =pod
9204:
9205: =item * &inhibit_menu_check($arg)
9206:
9207: Checks for a inhibitmenu state and generates output to preserve it
9208:
9209: Inputs: $arg - can be any of
9210: - undef - in which case the return value is a string
9211: to add into arguments list of a uri
9212: - 'input' - in which case the return value is a HTML
9213: <form> <input> field of type hidden to
9214: preserve the value
9215: - a url - in which case the return value is the url with
9216: the neccesary cgi args added to preserve the
9217: inhibitmenu state
9218: - a ref to a url - no return value, but the string is
9219: updated to include the neccessary cgi
9220: args to preserve the inhibitmenu state
9221:
9222: =cut
9223:
9224: sub inhibit_menu_check {
9225: my ($arg) = @_;
9226: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9227: if ($arg eq 'input') {
9228: if ($env{'form.inhibitmenu'}) {
9229: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9230: } else {
9231: return
9232: }
9233: }
9234: if ($env{'form.inhibitmenu'}) {
9235: if (ref($arg)) {
9236: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9237: } elsif ($arg eq '') {
9238: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9239: } else {
9240: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9241: }
9242: }
9243: if (!ref($arg)) {
9244: return $arg;
9245: }
9246: }
9247:
1.251 albertel 9248: ###############################################
1.182 matthew 9249:
9250: =pod
9251:
1.549 albertel 9252: =back
9253:
9254: =head1 User Information Routines
9255:
9256: =over 4
9257:
1.405 albertel 9258: =item * &get_users_function()
1.182 matthew 9259:
9260: Used by &bodytag to determine the current users primary role.
9261: Returns either 'student','coordinator','admin', or 'author'.
9262:
9263: =cut
9264:
9265: ###############################################
9266: sub get_users_function {
1.815 tempelho 9267: my $function = 'norole';
1.818 tempelho 9268: if ($env{'request.role'}=~/^(st)/) {
9269: $function='student';
9270: }
1.907 raeburn 9271: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9272: $function='coordinator';
9273: }
1.258 albertel 9274: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9275: $function='admin';
9276: }
1.826 bisitz 9277: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9278: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9279: $function='author';
9280: }
9281: return $function;
1.54 www 9282: }
1.99 www 9283:
9284: ###############################################
9285:
1.233 raeburn 9286: =pod
9287:
1.821 raeburn 9288: =item * &show_course()
9289:
9290: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9291: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9292:
9293: Inputs:
9294: None
9295:
9296: Outputs:
9297: Scalar: 1 if 'Course' to be used, 0 otherwise.
9298:
9299: =cut
9300:
9301: ###############################################
9302: sub show_course {
9303: my $course = !$env{'user.adv'};
9304: if (!$env{'user.adv'}) {
9305: foreach my $env (keys(%env)) {
9306: next if ($env !~ m/^user\.priv\./);
9307: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9308: $course = 0;
9309: last;
9310: }
9311: }
9312: }
9313: return $course;
9314: }
9315:
9316: ###############################################
9317:
9318: =pod
9319:
1.542 raeburn 9320: =item * &check_user_status()
1.274 raeburn 9321:
9322: Determines current status of supplied role for a
9323: specific user. Roles can be active, previous or future.
9324:
9325: Inputs:
9326: user's domain, user's username, course's domain,
1.375 raeburn 9327: course's number, optional section ID.
1.274 raeburn 9328:
9329: Outputs:
9330: role status: active, previous or future.
9331:
9332: =cut
9333:
9334: sub check_user_status {
1.412 raeburn 9335: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9336: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9337: my @uroles = keys(%userinfo);
1.274 raeburn 9338: my $srchstr;
9339: my $active_chk = 'none';
1.412 raeburn 9340: my $now = time;
1.274 raeburn 9341: if (@uroles > 0) {
1.908 raeburn 9342: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9343: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9344: } else {
1.412 raeburn 9345: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9346: }
9347: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9348: my $role_end = 0;
9349: my $role_start = 0;
9350: $active_chk = 'active';
1.412 raeburn 9351: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9352: $role_end = $1;
9353: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9354: $role_start = $1;
1.274 raeburn 9355: }
9356: }
9357: if ($role_start > 0) {
1.412 raeburn 9358: if ($now < $role_start) {
1.274 raeburn 9359: $active_chk = 'future';
9360: }
9361: }
9362: if ($role_end > 0) {
1.412 raeburn 9363: if ($now > $role_end) {
1.274 raeburn 9364: $active_chk = 'previous';
9365: }
9366: }
9367: }
9368: }
9369: return $active_chk;
9370: }
9371:
9372: ###############################################
9373:
9374: =pod
9375:
1.405 albertel 9376: =item * &get_sections()
1.233 raeburn 9377:
9378: Determines all the sections for a course including
9379: sections with students and sections containing other roles.
1.419 raeburn 9380: Incoming parameters:
9381:
9382: 1. domain
9383: 2. course number
9384: 3. reference to array containing roles for which sections should
9385: be gathered (optional).
9386: 4. reference to array containing status types for which sections
9387: should be gathered (optional).
9388:
9389: If the third argument is undefined, sections are gathered for any role.
9390: If the fourth argument is undefined, sections are gathered for any status.
9391: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9392:
1.374 raeburn 9393: Returns section hash (keys are section IDs, values are
9394: number of users in each section), subject to the
1.419 raeburn 9395: optional roles filter, optional status filter
1.233 raeburn 9396:
9397: =cut
9398:
9399: ###############################################
9400: sub get_sections {
1.419 raeburn 9401: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9402: if (!defined($cdom) || !defined($cnum)) {
9403: my $cid = $env{'request.course.id'};
9404:
9405: return if (!defined($cid));
9406:
9407: $cdom = $env{'course.'.$cid.'.domain'};
9408: $cnum = $env{'course.'.$cid.'.num'};
9409: }
9410:
9411: my %sectioncount;
1.419 raeburn 9412: my $now = time;
1.240 albertel 9413:
1.1118 raeburn 9414: my $check_students = 1;
9415: my $only_students = 0;
9416: if (ref($possible_roles) eq 'ARRAY') {
9417: if (grep(/^st$/,@{$possible_roles})) {
9418: if (@{$possible_roles} == 1) {
9419: $only_students = 1;
9420: }
9421: } else {
9422: $check_students = 0;
9423: }
9424: }
9425:
9426: if ($check_students) {
1.276 albertel 9427: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9428: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9429: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9430: my $start_index = &Apache::loncoursedata::CL_START();
9431: my $end_index = &Apache::loncoursedata::CL_END();
9432: my $status;
1.366 albertel 9433: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9434: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9435: $data->[$status_index],
9436: $data->[$start_index],
9437: $data->[$end_index]);
9438: if ($stu_status eq 'Active') {
9439: $status = 'active';
9440: } elsif ($end < $now) {
9441: $status = 'previous';
9442: } elsif ($start > $now) {
9443: $status = 'future';
9444: }
9445: if ($section ne '-1' && $section !~ /^\s*$/) {
9446: if ((!defined($possible_status)) || (($status ne '') &&
9447: (grep/^\Q$status\E$/,@{$possible_status}))) {
9448: $sectioncount{$section}++;
9449: }
1.240 albertel 9450: }
9451: }
9452: }
1.1118 raeburn 9453: if ($only_students) {
9454: return %sectioncount;
9455: }
1.240 albertel 9456: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9457: foreach my $user (sort(keys(%courseroles))) {
9458: if ($user !~ /^(\w{2})/) { next; }
9459: my ($role) = ($user =~ /^(\w{2})/);
9460: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9461: my ($section,$status);
1.240 albertel 9462: if ($role eq 'cr' &&
9463: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9464: $section=$1;
9465: }
9466: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9467: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9468: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9469: if ($end == -1 && $start == -1) {
9470: next; #deleted role
9471: }
9472: if (!defined($possible_status)) {
9473: $sectioncount{$section}++;
9474: } else {
9475: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9476: $status = 'active';
9477: } elsif ($end < $now) {
9478: $status = 'future';
9479: } elsif ($start > $now) {
9480: $status = 'previous';
9481: }
9482: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9483: $sectioncount{$section}++;
9484: }
9485: }
1.233 raeburn 9486: }
1.366 albertel 9487: return %sectioncount;
1.233 raeburn 9488: }
9489:
1.274 raeburn 9490: ###############################################
1.294 raeburn 9491:
9492: =pod
1.405 albertel 9493:
9494: =item * &get_course_users()
9495:
1.275 raeburn 9496: Retrieves usernames:domains for users in the specified course
9497: with specific role(s), and access status.
9498:
9499: Incoming parameters:
1.277 albertel 9500: 1. course domain
9501: 2. course number
9502: 3. access status: users must have - either active,
1.275 raeburn 9503: previous, future, or all.
1.277 albertel 9504: 4. reference to array of permissible roles
1.288 raeburn 9505: 5. reference to array of section restrictions (optional)
9506: 6. reference to results object (hash of hashes).
9507: 7. reference to optional userdata hash
1.609 raeburn 9508: 8. reference to optional statushash
1.630 raeburn 9509: 9. flag if privileged users (except those set to unhide in
9510: course settings) should be excluded
1.609 raeburn 9511: Keys of top level results hash are roles.
1.275 raeburn 9512: Keys of inner hashes are username:domain, with
9513: values set to access type.
1.288 raeburn 9514: Optional userdata hash returns an array with arguments in the
9515: same order as loncoursedata::get_classlist() for student data.
9516:
1.609 raeburn 9517: Optional statushash returns
9518:
1.288 raeburn 9519: Entries for end, start, section and status are blank because
9520: of the possibility of multiple values for non-student roles.
9521:
1.275 raeburn 9522: =cut
1.405 albertel 9523:
1.275 raeburn 9524: ###############################################
1.405 albertel 9525:
1.275 raeburn 9526: sub get_course_users {
1.630 raeburn 9527: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9528: my %idx = ();
1.419 raeburn 9529: my %seclists;
1.288 raeburn 9530:
9531: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9532: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9533: $idx{end} = &Apache::loncoursedata::CL_END();
9534: $idx{start} = &Apache::loncoursedata::CL_START();
9535: $idx{id} = &Apache::loncoursedata::CL_ID();
9536: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9537: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9538: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9539:
1.290 albertel 9540: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9541: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9542: my $now = time;
1.277 albertel 9543: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9544: my $match = 0;
1.412 raeburn 9545: my $secmatch = 0;
1.419 raeburn 9546: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9547: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9548: if ($section eq '') {
9549: $section = 'none';
9550: }
1.291 albertel 9551: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9552: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9553: $secmatch = 1;
9554: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9555: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9556: $secmatch = 1;
9557: }
9558: } else {
1.419 raeburn 9559: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9560: $secmatch = 1;
9561: }
1.290 albertel 9562: }
1.412 raeburn 9563: if (!$secmatch) {
9564: next;
9565: }
1.419 raeburn 9566: }
1.275 raeburn 9567: if (defined($$types{'active'})) {
1.288 raeburn 9568: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9569: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9570: $match = 1;
1.275 raeburn 9571: }
9572: }
9573: if (defined($$types{'previous'})) {
1.609 raeburn 9574: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9575: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9576: $match = 1;
1.275 raeburn 9577: }
9578: }
9579: if (defined($$types{'future'})) {
1.609 raeburn 9580: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9581: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9582: $match = 1;
1.275 raeburn 9583: }
9584: }
1.609 raeburn 9585: if ($match) {
9586: push(@{$seclists{$student}},$section);
9587: if (ref($userdata) eq 'HASH') {
9588: $$userdata{$student} = $$classlist{$student};
9589: }
9590: if (ref($statushash) eq 'HASH') {
9591: $statushash->{$student}{'st'}{$section} = $status;
9592: }
1.288 raeburn 9593: }
1.275 raeburn 9594: }
9595: }
1.412 raeburn 9596: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9597: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9598: my $now = time;
1.609 raeburn 9599: my %displaystatus = ( previous => 'Expired',
9600: active => 'Active',
9601: future => 'Future',
9602: );
1.1121 raeburn 9603: my (%nothide,@possdoms);
1.630 raeburn 9604: if ($hidepriv) {
9605: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9606: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9607: if ($user !~ /:/) {
9608: $nothide{join(':',split(/[\@]/,$user))}=1;
9609: } else {
9610: $nothide{$user} = 1;
9611: }
9612: }
1.1121 raeburn 9613: my @possdoms = ($cdom);
9614: if ($coursehash{'checkforpriv'}) {
9615: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9616: }
1.630 raeburn 9617: }
1.439 raeburn 9618: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9619: my $match = 0;
1.412 raeburn 9620: my $secmatch = 0;
1.439 raeburn 9621: my $status;
1.412 raeburn 9622: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9623: $user =~ s/:$//;
1.439 raeburn 9624: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9625: if ($end == -1 || $start == -1) {
9626: next;
9627: }
9628: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9629: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9630: my ($uname,$udom) = split(/:/,$user);
9631: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9632: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9633: $secmatch = 1;
9634: } elsif ($usec eq '') {
1.420 albertel 9635: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9636: $secmatch = 1;
9637: }
9638: } else {
9639: if (grep(/^\Q$usec\E$/,@{$sections})) {
9640: $secmatch = 1;
9641: }
9642: }
9643: if (!$secmatch) {
9644: next;
9645: }
1.288 raeburn 9646: }
1.419 raeburn 9647: if ($usec eq '') {
9648: $usec = 'none';
9649: }
1.275 raeburn 9650: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9651: if ($hidepriv) {
1.1121 raeburn 9652: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9653: (!$nothide{$uname.':'.$udom})) {
9654: next;
9655: }
9656: }
1.503 raeburn 9657: if ($end > 0 && $end < $now) {
1.439 raeburn 9658: $status = 'previous';
9659: } elsif ($start > $now) {
9660: $status = 'future';
9661: } else {
9662: $status = 'active';
9663: }
1.277 albertel 9664: foreach my $type (keys(%{$types})) {
1.275 raeburn 9665: if ($status eq $type) {
1.420 albertel 9666: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9667: push(@{$$users{$role}{$user}},$type);
9668: }
1.288 raeburn 9669: $match = 1;
9670: }
9671: }
1.419 raeburn 9672: if (($match) && (ref($userdata) eq 'HASH')) {
9673: if (!exists($$userdata{$uname.':'.$udom})) {
9674: &get_user_info($udom,$uname,\%idx,$userdata);
9675: }
1.420 albertel 9676: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9677: push(@{$seclists{$uname.':'.$udom}},$usec);
9678: }
1.609 raeburn 9679: if (ref($statushash) eq 'HASH') {
9680: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9681: }
1.275 raeburn 9682: }
9683: }
9684: }
9685: }
1.290 albertel 9686: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9687: if ((defined($cdom)) && (defined($cnum))) {
9688: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9689: if ( defined($csettings{'internal.courseowner'}) ) {
9690: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9691: next if ($owner eq '');
9692: my ($ownername,$ownerdom);
9693: if ($owner =~ /^([^:]+):([^:]+)$/) {
9694: $ownername = $1;
9695: $ownerdom = $2;
9696: } else {
9697: $ownername = $owner;
9698: $ownerdom = $cdom;
9699: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9700: }
9701: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9702: if (defined($userdata) &&
1.609 raeburn 9703: !exists($$userdata{$owner})) {
9704: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9705: if (!grep(/^none$/,@{$seclists{$owner}})) {
9706: push(@{$seclists{$owner}},'none');
9707: }
9708: if (ref($statushash) eq 'HASH') {
9709: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9710: }
1.290 albertel 9711: }
1.279 raeburn 9712: }
9713: }
9714: }
1.419 raeburn 9715: foreach my $user (keys(%seclists)) {
9716: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9717: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9718: }
1.275 raeburn 9719: }
9720: return;
9721: }
9722:
1.288 raeburn 9723: sub get_user_info {
9724: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9725: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9726: &plainname($uname,$udom,'lastname');
1.291 albertel 9727: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9728: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9729: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9730: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9731: return;
9732: }
1.275 raeburn 9733:
1.472 raeburn 9734: ###############################################
9735:
9736: =pod
9737:
9738: =item * &get_user_quota()
9739:
1.1134 raeburn 9740: Retrieves quota assigned for storage of user files.
9741: Default is to report quota for portfolio files.
1.472 raeburn 9742:
9743: Incoming parameters:
9744: 1. user's username
9745: 2. user's domain
1.1134 raeburn 9746: 3. quota name - portfolio, author, or course
1.1136 raeburn 9747: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 9748: 4. crstype - official, unofficial, textbook, placement or community,
9749: if quota name is course
1.472 raeburn 9750:
9751: Returns:
1.1163 raeburn 9752: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9753: 2. (Optional) Type of setting: custom or default
9754: (individually assigned or default for user's
9755: institutional status).
9756: 3. (Optional) - User's institutional status (e.g., faculty, staff
9757: or student - types as defined in localenroll::inst_usertypes
9758: for user's domain, which determines default quota for user.
9759: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9760:
9761: If a value has been stored in the user's environment,
1.536 raeburn 9762: it will return that, otherwise it returns the maximal default
1.1134 raeburn 9763: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9764:
9765: =cut
9766:
9767: ###############################################
9768:
9769:
9770: sub get_user_quota {
1.1136 raeburn 9771: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9772: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9773: if (!defined($udom)) {
9774: $udom = $env{'user.domain'};
9775: }
9776: if (!defined($uname)) {
9777: $uname = $env{'user.name'};
9778: }
9779: if (($udom eq '' || $uname eq '') ||
9780: ($udom eq 'public') && ($uname eq 'public')) {
9781: $quota = 0;
1.536 raeburn 9782: $quotatype = 'default';
9783: $defquota = 0;
1.472 raeburn 9784: } else {
1.536 raeburn 9785: my $inststatus;
1.1134 raeburn 9786: if ($quotaname eq 'course') {
9787: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9788: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9789: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9790: } else {
9791: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9792: $quota = $cenv{'internal.uploadquota'};
9793: }
1.536 raeburn 9794: } else {
1.1134 raeburn 9795: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9796: if ($quotaname eq 'author') {
9797: $quota = $env{'environment.authorquota'};
9798: } else {
9799: $quota = $env{'environment.portfolioquota'};
9800: }
9801: $inststatus = $env{'environment.inststatus'};
9802: } else {
9803: my %userenv =
9804: &Apache::lonnet::get('environment',['portfolioquota',
9805: 'authorquota','inststatus'],$udom,$uname);
9806: my ($tmp) = keys(%userenv);
9807: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9808: if ($quotaname eq 'author') {
9809: $quota = $userenv{'authorquota'};
9810: } else {
9811: $quota = $userenv{'portfolioquota'};
9812: }
9813: $inststatus = $userenv{'inststatus'};
9814: } else {
9815: undef(%userenv);
9816: }
9817: }
9818: }
9819: if ($quota eq '' || wantarray) {
9820: if ($quotaname eq 'course') {
9821: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 9822: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 9823: ($crstype eq 'community') || ($crstype eq 'textbook') ||
9824: ($crstype eq 'placement')) {
1.1136 raeburn 9825: $defquota = $domdefs{$crstype.'quota'};
9826: }
9827: if ($defquota eq '') {
9828: $defquota = 500;
9829: }
1.1134 raeburn 9830: } else {
9831: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9832: }
9833: if ($quota eq '') {
9834: $quota = $defquota;
9835: $quotatype = 'default';
9836: } else {
9837: $quotatype = 'custom';
9838: }
1.472 raeburn 9839: }
9840: }
1.536 raeburn 9841: if (wantarray) {
9842: return ($quota,$quotatype,$settingstatus,$defquota);
9843: } else {
9844: return $quota;
9845: }
1.472 raeburn 9846: }
9847:
9848: ###############################################
9849:
9850: =pod
9851:
9852: =item * &default_quota()
9853:
1.536 raeburn 9854: Retrieves default quota assigned for storage of user portfolio files,
9855: given an (optional) user's institutional status.
1.472 raeburn 9856:
9857: Incoming parameters:
1.1142 raeburn 9858:
1.472 raeburn 9859: 1. domain
1.536 raeburn 9860: 2. (Optional) institutional status(es). This is a : separated list of
9861: status types (e.g., faculty, staff, student etc.)
9862: which apply to the user for whom the default is being retrieved.
9863: If the institutional status string in undefined, the domain
1.1134 raeburn 9864: default quota will be returned.
9865: 3. quota name - portfolio, author, or course
9866: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9867:
9868: Returns:
1.1142 raeburn 9869:
1.1163 raeburn 9870: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9871: 2. (Optional) institutional type which determined the value of the
9872: default quota.
1.472 raeburn 9873:
9874: If a value has been stored in the domain's configuration db,
9875: it will return that, otherwise it returns 20 (for backwards
9876: compatibility with domains which have not set up a configuration
1.1163 raeburn 9877: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9878:
1.536 raeburn 9879: If the user's status includes multiple types (e.g., staff and student),
9880: the largest default quota which applies to the user determines the
9881: default quota returned.
9882:
1.472 raeburn 9883: =cut
9884:
9885: ###############################################
9886:
9887:
9888: sub default_quota {
1.1134 raeburn 9889: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9890: my ($defquota,$settingstatus);
9891: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9892: ['quotas'],$udom);
1.1134 raeburn 9893: my $key = 'defaultquota';
9894: if ($quotaname eq 'author') {
9895: $key = 'authorquota';
9896: }
1.622 raeburn 9897: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9898: if ($inststatus ne '') {
1.765 raeburn 9899: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9900: foreach my $item (@statuses) {
1.1134 raeburn 9901: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9902: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9903: if ($defquota eq '') {
1.1134 raeburn 9904: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9905: $settingstatus = $item;
1.1134 raeburn 9906: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9907: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9908: $settingstatus = $item;
9909: }
9910: }
1.1134 raeburn 9911: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9912: if ($quotahash{'quotas'}{$item} ne '') {
9913: if ($defquota eq '') {
9914: $defquota = $quotahash{'quotas'}{$item};
9915: $settingstatus = $item;
9916: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9917: $defquota = $quotahash{'quotas'}{$item};
9918: $settingstatus = $item;
9919: }
1.536 raeburn 9920: }
9921: }
9922: }
9923: }
9924: if ($defquota eq '') {
1.1134 raeburn 9925: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9926: $defquota = $quotahash{'quotas'}{$key}{'default'};
9927: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9928: $defquota = $quotahash{'quotas'}{'default'};
9929: }
1.536 raeburn 9930: $settingstatus = 'default';
1.1139 raeburn 9931: if ($defquota eq '') {
9932: if ($quotaname eq 'author') {
9933: $defquota = 500;
9934: }
9935: }
1.536 raeburn 9936: }
9937: } else {
9938: $settingstatus = 'default';
1.1134 raeburn 9939: if ($quotaname eq 'author') {
9940: $defquota = 500;
9941: } else {
9942: $defquota = 20;
9943: }
1.536 raeburn 9944: }
9945: if (wantarray) {
9946: return ($defquota,$settingstatus);
1.472 raeburn 9947: } else {
1.536 raeburn 9948: return $defquota;
1.472 raeburn 9949: }
9950: }
9951:
1.1135 raeburn 9952: ###############################################
9953:
9954: =pod
9955:
1.1136 raeburn 9956: =item * &excess_filesize_warning()
1.1135 raeburn 9957:
9958: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 9959: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 9960: space to be exceeded.
1.1136 raeburn 9961:
9962: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 9963: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 9964:
1.1165 raeburn 9965: Inputs: 7
1.1136 raeburn 9966: 1. username or coursenum
1.1135 raeburn 9967: 2. domain
1.1136 raeburn 9968: 3. context ('author' or 'course')
1.1135 raeburn 9969: 4. filename of file for which action is being requested
9970: 5. filesize (kB) of file
9971: 6. action being taken: copy or upload.
1.1237 raeburn 9972: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 9973:
9974: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 9975: otherwise return null.
9976:
9977: =back
1.1135 raeburn 9978:
9979: =cut
9980:
1.1136 raeburn 9981: sub excess_filesize_warning {
1.1165 raeburn 9982: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 9983: my $current_disk_usage = 0;
1.1165 raeburn 9984: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 9985: if ($context eq 'author') {
9986: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9987: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9988: } else {
9989: foreach my $subdir ('docs','supplemental') {
9990: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9991: }
9992: }
1.1135 raeburn 9993: $disk_quota = int($disk_quota * 1000);
9994: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 9995: return '<p class="LC_warning">'.
1.1135 raeburn 9996: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 9997: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9998: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 9999: $disk_quota,$current_disk_usage).
10000: '</p>';
10001: }
10002: return;
10003: }
10004:
10005: ###############################################
10006:
10007:
1.1136 raeburn 10008:
10009:
1.384 raeburn 10010: sub get_secgrprole_info {
10011: my ($cdom,$cnum,$needroles,$type) = @_;
10012: my %sections_count = &get_sections($cdom,$cnum);
10013: my @sections = (sort {$a <=> $b} keys(%sections_count));
10014: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10015: my @groups = sort(keys(%curr_groups));
10016: my $allroles = [];
10017: my $rolehash;
10018: my $accesshash = {
10019: active => 'Currently has access',
10020: future => 'Will have future access',
10021: previous => 'Previously had access',
10022: };
10023: if ($needroles) {
10024: $rolehash = {'all' => 'all'};
1.385 albertel 10025: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10026: if (&Apache::lonnet::error(%user_roles)) {
10027: undef(%user_roles);
10028: }
10029: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10030: my ($role)=split(/\:/,$item,2);
10031: if ($role eq 'cr') { next; }
10032: if ($role =~ /^cr/) {
10033: $$rolehash{$role} = (split('/',$role))[3];
10034: } else {
10035: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10036: }
10037: }
10038: foreach my $key (sort(keys(%{$rolehash}))) {
10039: push(@{$allroles},$key);
10040: }
10041: push (@{$allroles},'st');
10042: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10043: }
10044: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10045: }
10046:
1.555 raeburn 10047: sub user_picker {
1.1279 raeburn 10048: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 10049: my $currdom = $dom;
1.1253 raeburn 10050: my @alldoms = &Apache::lonnet::all_domains();
10051: if (@alldoms == 1) {
10052: my %domsrch = &Apache::lonnet::get_dom('configuration',
10053: ['directorysrch'],$alldoms[0]);
10054: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10055: my $showdom = $domdesc;
10056: if ($showdom eq '') {
10057: $showdom = $dom;
10058: }
10059: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10060: if ((!$domsrch{'directorysrch'}{'available'}) &&
10061: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10062: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10063: }
10064: }
10065: }
1.555 raeburn 10066: my %curr_selected = (
10067: srchin => 'dom',
1.580 raeburn 10068: srchby => 'lastname',
1.555 raeburn 10069: );
10070: my $srchterm;
1.625 raeburn 10071: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10072: if ($srch->{'srchby'} ne '') {
10073: $curr_selected{'srchby'} = $srch->{'srchby'};
10074: }
10075: if ($srch->{'srchin'} ne '') {
10076: $curr_selected{'srchin'} = $srch->{'srchin'};
10077: }
10078: if ($srch->{'srchtype'} ne '') {
10079: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10080: }
10081: if ($srch->{'srchdomain'} ne '') {
10082: $currdom = $srch->{'srchdomain'};
10083: }
10084: $srchterm = $srch->{'srchterm'};
10085: }
1.1222 damieng 10086: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10087: 'usr' => 'Search criteria',
1.563 raeburn 10088: 'doma' => 'Domain/institution to search',
1.558 albertel 10089: 'uname' => 'username',
10090: 'lastname' => 'last name',
1.555 raeburn 10091: 'lastfirst' => 'last name, first name',
1.558 albertel 10092: 'crs' => 'in this course',
1.576 raeburn 10093: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10094: 'alc' => 'all LON-CAPA',
1.573 raeburn 10095: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10096: 'exact' => 'is',
10097: 'contains' => 'contains',
1.569 raeburn 10098: 'begins' => 'begins with',
1.1222 damieng 10099: );
10100: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10101: 'youm' => "You must include some text to search for.",
10102: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10103: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10104: 'yomc' => "You must choose a domain when using an institutional directory search.",
10105: 'ymcd' => "You must choose a domain when using a domain search.",
10106: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10107: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10108: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10109: );
1.1222 damieng 10110: &html_escape(\%html_lt);
10111: &js_escape(\%js_lt);
1.1255 raeburn 10112: my $domform;
1.1277 raeburn 10113: my $allow_blank = 1;
1.1255 raeburn 10114: if ($fixeddom) {
1.1277 raeburn 10115: $allow_blank = 0;
10116: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1255 raeburn 10117: } else {
1.1277 raeburn 10118: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1255 raeburn 10119: }
1.563 raeburn 10120: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10121:
10122: my @srchins = ('crs','dom','alc','instd');
10123:
10124: foreach my $option (@srchins) {
10125: # FIXME 'alc' option unavailable until
10126: # loncreateuser::print_user_query_page()
10127: # has been completed.
10128: next if ($option eq 'alc');
1.880 raeburn 10129: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10130: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1279 raeburn 10131: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 10132: if ($curr_selected{'srchin'} eq $option) {
10133: $srchinsel .= '
1.1222 damieng 10134: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10135: } else {
10136: $srchinsel .= '
1.1222 damieng 10137: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10138: }
1.555 raeburn 10139: }
1.563 raeburn 10140: $srchinsel .= "\n </select>\n";
1.555 raeburn 10141:
10142: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10143: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10144: if ($curr_selected{'srchby'} eq $option) {
10145: $srchbysel .= '
1.1222 damieng 10146: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10147: } else {
10148: $srchbysel .= '
1.1222 damieng 10149: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10150: }
10151: }
10152: $srchbysel .= "\n </select>\n";
10153:
10154: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10155: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10156: if ($curr_selected{'srchtype'} eq $option) {
10157: $srchtypesel .= '
1.1222 damieng 10158: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10159: } else {
10160: $srchtypesel .= '
1.1222 damieng 10161: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10162: }
10163: }
10164: $srchtypesel .= "\n </select>\n";
10165:
1.558 albertel 10166: my ($newuserscript,$new_user_create);
1.994 raeburn 10167: my $context_dom = $env{'request.role.domain'};
10168: if ($context eq 'requestcrs') {
10169: if ($env{'form.coursedom'} ne '') {
10170: $context_dom = $env{'form.coursedom'};
10171: }
10172: }
1.556 raeburn 10173: if ($forcenewuser) {
1.576 raeburn 10174: if (ref($srch) eq 'HASH') {
1.994 raeburn 10175: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10176: if ($cancreate) {
10177: $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>';
10178: } else {
1.799 bisitz 10179: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10180: my %usertypetext = (
10181: official => 'institutional',
10182: unofficial => 'non-institutional',
10183: );
1.799 bisitz 10184: $new_user_create = '<p class="LC_warning">'
10185: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10186: .' '
10187: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10188: ,'<a href="'.$helplink.'">','</a>')
10189: .'</p><br />';
1.627 raeburn 10190: }
1.576 raeburn 10191: }
10192: }
10193:
1.556 raeburn 10194: $newuserscript = <<"ENDSCRIPT";
10195:
1.570 raeburn 10196: function setSearch(createnew,callingForm) {
1.556 raeburn 10197: if (createnew == 1) {
1.570 raeburn 10198: for (var i=0; i<callingForm.srchby.length; i++) {
10199: if (callingForm.srchby.options[i].value == 'uname') {
10200: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10201: }
10202: }
1.570 raeburn 10203: for (var i=0; i<callingForm.srchin.length; i++) {
10204: if ( callingForm.srchin.options[i].value == 'dom') {
10205: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10206: }
10207: }
1.570 raeburn 10208: for (var i=0; i<callingForm.srchtype.length; i++) {
10209: if (callingForm.srchtype.options[i].value == 'exact') {
10210: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10211: }
10212: }
1.570 raeburn 10213: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10214: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10215: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10216: }
10217: }
10218: }
10219: }
10220: ENDSCRIPT
1.558 albertel 10221:
1.556 raeburn 10222: }
10223:
1.555 raeburn 10224: my $output = <<"END_BLOCK";
1.556 raeburn 10225: <script type="text/javascript">
1.824 bisitz 10226: // <![CDATA[
1.570 raeburn 10227: function validateEntry(callingForm) {
1.558 albertel 10228:
1.556 raeburn 10229: var checkok = 1;
1.558 albertel 10230: var srchin;
1.570 raeburn 10231: for (var i=0; i<callingForm.srchin.length; i++) {
10232: if ( callingForm.srchin[i].checked ) {
10233: srchin = callingForm.srchin[i].value;
1.558 albertel 10234: }
10235: }
10236:
1.570 raeburn 10237: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10238: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10239: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10240: var srchterm = callingForm.srchterm.value;
10241: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10242: var msg = "";
10243:
10244: if (srchterm == "") {
10245: checkok = 0;
1.1222 damieng 10246: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10247: }
10248:
1.569 raeburn 10249: if (srchtype== 'begins') {
10250: if (srchterm.length < 2) {
10251: checkok = 0;
1.1222 damieng 10252: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10253: }
10254: }
10255:
1.556 raeburn 10256: if (srchtype== 'contains') {
10257: if (srchterm.length < 3) {
10258: checkok = 0;
1.1222 damieng 10259: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10260: }
10261: }
10262: if (srchin == 'instd') {
10263: if (srchdomain == '') {
10264: checkok = 0;
1.1222 damieng 10265: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10266: }
10267: }
10268: if (srchin == 'dom') {
10269: if (srchdomain == '') {
10270: checkok = 0;
1.1222 damieng 10271: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10272: }
10273: }
10274: if (srchby == 'lastfirst') {
10275: if (srchterm.indexOf(",") == -1) {
10276: checkok = 0;
1.1222 damieng 10277: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10278: }
10279: if (srchterm.indexOf(",") == srchterm.length -1) {
10280: checkok = 0;
1.1222 damieng 10281: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10282: }
10283: }
10284: if (checkok == 0) {
1.1222 damieng 10285: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10286: return;
10287: }
10288: if (checkok == 1) {
1.570 raeburn 10289: callingForm.submit();
1.556 raeburn 10290: }
10291: }
10292:
10293: $newuserscript
10294:
1.824 bisitz 10295: // ]]>
1.556 raeburn 10296: </script>
1.558 albertel 10297:
10298: $new_user_create
10299:
1.555 raeburn 10300: END_BLOCK
1.558 albertel 10301:
1.876 raeburn 10302: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10303: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10304: $domform.
10305: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10306: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10307: $srchbysel.
10308: $srchtypesel.
10309: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10310: $srchinsel.
10311: &Apache::lonhtmlcommon::row_closure(1).
10312: &Apache::lonhtmlcommon::end_pick_box().
10313: '<br />';
1.1253 raeburn 10314: return ($output,1);
1.555 raeburn 10315: }
10316:
1.612 raeburn 10317: sub user_rule_check {
1.615 raeburn 10318: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10319: my ($response,%inst_response);
1.612 raeburn 10320: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10321: if (keys(%{$usershash}) > 1) {
10322: my (%by_username,%by_id,%userdoms);
10323: my $checkid;
10324: if (ref($checks) eq 'HASH') {
10325: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10326: $checkid = 1;
10327: }
10328: }
10329: foreach my $user (keys(%{$usershash})) {
10330: my ($uname,$udom) = split(/:/,$user);
10331: if ($checkid) {
10332: if (ref($usershash->{$user}) eq 'HASH') {
10333: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10334: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10335: $userdoms{$udom} = 1;
1.1227 raeburn 10336: if (ref($inst_results) eq 'HASH') {
10337: $inst_results->{$uname.':'.$udom} = {};
10338: }
1.1226 raeburn 10339: }
10340: }
10341: } else {
10342: $by_username{$udom}{$uname} = 1;
10343: $userdoms{$udom} = 1;
1.1227 raeburn 10344: if (ref($inst_results) eq 'HASH') {
10345: $inst_results->{$uname.':'.$udom} = {};
10346: }
1.1226 raeburn 10347: }
10348: }
10349: foreach my $udom (keys(%userdoms)) {
10350: if (!$got_rules->{$udom}) {
10351: my %domconfig = &Apache::lonnet::get_dom('configuration',
10352: ['usercreation'],$udom);
10353: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10354: foreach my $item ('username','id') {
10355: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10356: $$curr_rules{$udom}{$item} =
10357: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10358: }
10359: }
10360: }
10361: $got_rules->{$udom} = 1;
10362: }
1.612 raeburn 10363: }
1.1226 raeburn 10364: if ($checkid) {
10365: foreach my $udom (keys(%by_id)) {
10366: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10367: if ($outcome eq 'ok') {
1.1227 raeburn 10368: foreach my $id (keys(%{$by_id{$udom}})) {
10369: my $uname = $by_id{$udom}{$id};
10370: $inst_response{$uname.':'.$udom} = $outcome;
10371: }
1.1226 raeburn 10372: if (ref($results) eq 'HASH') {
10373: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10374: if (exists($inst_response{$uname.':'.$udom})) {
10375: $inst_response{$uname.':'.$udom} = $outcome;
10376: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10377: }
1.1226 raeburn 10378: }
10379: }
10380: }
1.612 raeburn 10381: }
1.615 raeburn 10382: } else {
1.1226 raeburn 10383: foreach my $udom (keys(%by_username)) {
10384: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10385: if ($outcome eq 'ok') {
1.1227 raeburn 10386: foreach my $uname (keys(%{$by_username{$udom}})) {
10387: $inst_response{$uname.':'.$udom} = $outcome;
10388: }
1.1226 raeburn 10389: if (ref($results) eq 'HASH') {
10390: foreach my $uname (keys(%{$results})) {
10391: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10392: }
10393: }
10394: }
10395: }
1.612 raeburn 10396: }
1.1226 raeburn 10397: } elsif (keys(%{$usershash}) == 1) {
10398: my $user = (keys(%{$usershash}))[0];
10399: my ($uname,$udom) = split(/:/,$user);
10400: if (($udom ne '') && ($uname ne '')) {
10401: if (ref($usershash->{$user}) eq 'HASH') {
10402: if (ref($checks) eq 'HASH') {
10403: if (defined($checks->{'username'})) {
10404: ($inst_response{$user},%{$inst_results->{$user}}) =
10405: &Apache::lonnet::get_instuser($udom,$uname);
10406: } elsif (defined($checks->{'id'})) {
10407: if ($usershash->{$user}->{'id'} ne '') {
10408: ($inst_response{$user},%{$inst_results->{$user}}) =
10409: &Apache::lonnet::get_instuser($udom,undef,
10410: $usershash->{$user}->{'id'});
10411: } else {
10412: ($inst_response{$user},%{$inst_results->{$user}}) =
10413: &Apache::lonnet::get_instuser($udom,$uname);
10414: }
1.585 raeburn 10415: }
1.1226 raeburn 10416: } else {
10417: ($inst_response{$user},%{$inst_results->{$user}}) =
10418: &Apache::lonnet::get_instuser($udom,$uname);
10419: return;
10420: }
10421: if (!$got_rules->{$udom}) {
10422: my %domconfig = &Apache::lonnet::get_dom('configuration',
10423: ['usercreation'],$udom);
10424: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10425: foreach my $item ('username','id') {
10426: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10427: $$curr_rules{$udom}{$item} =
10428: $domconfig{'usercreation'}{$item.'_rule'};
10429: }
10430: }
10431: }
10432: $got_rules->{$udom} = 1;
1.585 raeburn 10433: }
10434: }
1.1226 raeburn 10435: } else {
10436: return;
10437: }
10438: } else {
10439: return;
10440: }
10441: foreach my $user (keys(%{$usershash})) {
10442: my ($uname,$udom) = split(/:/,$user);
10443: next if (($udom eq '') || ($uname eq ''));
10444: my $id;
1.1227 raeburn 10445: if (ref($inst_results) eq 'HASH') {
10446: if (ref($inst_results->{$user}) eq 'HASH') {
10447: $id = $inst_results->{$user}->{'id'};
10448: }
10449: }
10450: if ($id eq '') {
10451: if (ref($usershash->{$user})) {
10452: $id = $usershash->{$user}->{'id'};
10453: }
1.585 raeburn 10454: }
1.612 raeburn 10455: foreach my $item (keys(%{$checks})) {
10456: if (ref($$curr_rules{$udom}) eq 'HASH') {
10457: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10458: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10459: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10460: $$curr_rules{$udom}{$item});
1.612 raeburn 10461: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10462: if ($rule_check{$rule}) {
10463: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10464: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10465: if (ref($inst_results) eq 'HASH') {
10466: if (ref($inst_results->{$user}) eq 'HASH') {
10467: if (keys(%{$inst_results->{$user}}) == 0) {
10468: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10469: } elsif ($item eq 'id') {
10470: if ($inst_results->{$user}->{'id'} eq '') {
10471: $$alerts{$item}{$udom}{$uname} = 1;
10472: }
1.615 raeburn 10473: }
1.612 raeburn 10474: }
10475: }
1.615 raeburn 10476: }
10477: last;
1.585 raeburn 10478: }
10479: }
10480: }
10481: }
10482: }
10483: }
10484: }
10485: }
1.612 raeburn 10486: return;
10487: }
10488:
10489: sub user_rule_formats {
10490: my ($domain,$domdesc,$curr_rules,$check) = @_;
10491: my %text = (
10492: 'username' => 'Usernames',
10493: 'id' => 'IDs',
10494: );
10495: my $output;
10496: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10497: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10498: if (@{$ruleorder} > 0) {
1.1102 raeburn 10499: $output = '<br />'.
10500: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10501: '<span class="LC_cusr_emph">','</span>',$domdesc).
10502: ' <ul>';
1.612 raeburn 10503: foreach my $rule (@{$ruleorder}) {
10504: if (ref($curr_rules) eq 'ARRAY') {
10505: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10506: if (ref($rules->{$rule}) eq 'HASH') {
10507: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10508: $rules->{$rule}{'desc'}.'</li>';
10509: }
10510: }
10511: }
10512: }
10513: $output .= '</ul>';
10514: }
10515: }
10516: return $output;
10517: }
10518:
10519: sub instrule_disallow_msg {
1.615 raeburn 10520: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10521: my $response;
10522: my %text = (
10523: item => 'username',
10524: items => 'usernames',
10525: match => 'matches',
10526: do => 'does',
10527: action => 'a username',
10528: one => 'one',
10529: );
10530: if ($count > 1) {
10531: $text{'item'} = 'usernames';
10532: $text{'match'} ='match';
10533: $text{'do'} = 'do';
10534: $text{'action'} = 'usernames',
10535: $text{'one'} = 'ones';
10536: }
10537: if ($checkitem eq 'id') {
10538: $text{'items'} = 'IDs';
10539: $text{'item'} = 'ID';
10540: $text{'action'} = 'an ID';
1.615 raeburn 10541: if ($count > 1) {
10542: $text{'item'} = 'IDs';
10543: $text{'action'} = 'IDs';
10544: }
1.612 raeburn 10545: }
1.674 bisitz 10546: $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 10547: if ($mode eq 'upload') {
10548: if ($checkitem eq 'username') {
10549: $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'}.");
10550: } elsif ($checkitem eq 'id') {
1.674 bisitz 10551: $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 10552: }
1.669 raeburn 10553: } elsif ($mode eq 'selfcreate') {
10554: if ($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.615 raeburn 10557: } else {
10558: if ($checkitem eq 'username') {
10559: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10560: } elsif ($checkitem eq 'id') {
10561: $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.");
10562: }
1.612 raeburn 10563: }
10564: return $response;
1.585 raeburn 10565: }
10566:
1.624 raeburn 10567: sub personal_data_fieldtitles {
10568: my %fieldtitles = &Apache::lonlocal::texthash (
10569: id => 'Student/Employee ID',
10570: permanentemail => 'E-mail address',
10571: lastname => 'Last Name',
10572: firstname => 'First Name',
10573: middlename => 'Middle Name',
10574: generation => 'Generation',
10575: gen => 'Generation',
1.765 raeburn 10576: inststatus => 'Affiliation',
1.624 raeburn 10577: );
10578: return %fieldtitles;
10579: }
10580:
1.642 raeburn 10581: sub sorted_inst_types {
10582: my ($dom) = @_;
1.1185 raeburn 10583: my ($usertypes,$order);
10584: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10585: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10586: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10587: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10588: } else {
10589: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10590: }
1.642 raeburn 10591: my $othertitle = &mt('All users');
10592: if ($env{'request.course.id'}) {
1.668 raeburn 10593: $othertitle = &mt('Any users');
1.642 raeburn 10594: }
10595: my @types;
10596: if (ref($order) eq 'ARRAY') {
10597: @types = @{$order};
10598: }
10599: if (@types == 0) {
10600: if (ref($usertypes) eq 'HASH') {
10601: @types = sort(keys(%{$usertypes}));
10602: }
10603: }
10604: if (keys(%{$usertypes}) > 0) {
10605: $othertitle = &mt('Other users');
10606: }
10607: return ($othertitle,$usertypes,\@types);
10608: }
10609:
1.645 raeburn 10610: sub get_institutional_codes {
10611: my ($settings,$allcourses,$LC_code) = @_;
10612: # Get complete list of course sections to update
10613: my @currsections = ();
10614: my @currxlists = ();
10615: my $coursecode = $$settings{'internal.coursecode'};
10616:
10617: if ($$settings{'internal.sectionnums'} ne '') {
10618: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10619: }
10620:
10621: if ($$settings{'internal.crosslistings'} ne '') {
10622: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10623: }
10624:
10625: if (@currxlists > 0) {
10626: foreach (@currxlists) {
10627: if (m/^([^:]+):(\w*)$/) {
10628: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 10629: push(@{$allcourses},$1);
1.645 raeburn 10630: $$LC_code{$1} = $2;
10631: }
10632: }
10633: }
10634: }
10635:
10636: if (@currsections > 0) {
10637: foreach (@currsections) {
10638: if (m/^(\w+):(\w*)$/) {
10639: my $sec = $coursecode.$1;
10640: my $lc_sec = $2;
10641: unless (grep/^$sec$/,@{$allcourses}) {
1.1263 raeburn 10642: push(@{$allcourses},$sec);
1.645 raeburn 10643: $$LC_code{$sec} = $lc_sec;
10644: }
10645: }
10646: }
10647: }
10648: return;
10649: }
10650:
1.971 raeburn 10651: sub get_standard_codeitems {
10652: return ('Year','Semester','Department','Number','Section');
10653: }
10654:
1.112 bowersj2 10655: =pod
10656:
1.780 raeburn 10657: =head1 Slot Helpers
10658:
10659: =over 4
10660:
10661: =item * sorted_slots()
10662:
1.1040 raeburn 10663: Sorts an array of slot names in order of an optional sort key,
10664: default sort is by slot start time (earliest first).
1.780 raeburn 10665:
10666: Inputs:
10667:
10668: =over 4
10669:
10670: slotsarr - Reference to array of unsorted slot names.
10671:
10672: slots - Reference to hash of hash, where outer hash keys are slot names.
10673:
1.1040 raeburn 10674: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10675:
1.549 albertel 10676: =back
10677:
1.780 raeburn 10678: Returns:
10679:
10680: =over 4
10681:
1.1040 raeburn 10682: sorted - An array of slot names sorted by a specified sort key
10683: (default sort key is start time of the slot).
1.780 raeburn 10684:
10685: =back
10686:
10687: =cut
10688:
10689:
10690: sub sorted_slots {
1.1040 raeburn 10691: my ($slotsarr,$slots,$sortkey) = @_;
10692: if ($sortkey eq '') {
10693: $sortkey = 'starttime';
10694: }
1.780 raeburn 10695: my @sorted;
10696: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10697: @sorted =
10698: sort {
10699: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10700: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10701: }
10702: if (ref($slots->{$a})) { return -1;}
10703: if (ref($slots->{$b})) { return 1;}
10704: return 0;
10705: } @{$slotsarr};
10706: }
10707: return @sorted;
10708: }
10709:
1.1040 raeburn 10710: =pod
10711:
10712: =item * get_future_slots()
10713:
10714: Inputs:
10715:
10716: =over 4
10717:
10718: cnum - course number
10719:
10720: cdom - course domain
10721:
10722: now - current UNIX time
10723:
10724: symb - optional symb
10725:
10726: =back
10727:
10728: Returns:
10729:
10730: =over 4
10731:
10732: sorted_reservable - ref to array of student_schedulable slots currently
10733: reservable, ordered by end date of reservation period.
10734:
10735: reservable_now - ref to hash of student_schedulable slots currently
10736: reservable.
10737:
10738: Keys in inner hash are:
10739: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10740: (b) endreserve: end date of reservation period.
10741: (c) uniqueperiod: start,end dates when slot is to be uniquely
10742: selected.
1.1040 raeburn 10743:
10744: sorted_future - ref to array of student_schedulable slots reservable in
10745: the future, ordered by start date of reservation period.
10746:
10747: future_reservable - ref to hash of student_schedulable slots reservable
10748: in the future.
10749:
10750: Keys in inner hash are:
10751: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10752: (b) startreserve: start date of reservation period.
10753: (c) uniqueperiod: start,end dates when slot is to be uniquely
10754: selected.
1.1040 raeburn 10755:
10756: =back
10757:
10758: =cut
10759:
10760: sub get_future_slots {
10761: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 10762: my $map;
10763: if ($symb) {
10764: ($map) = &Apache::lonnet::decode_symb($symb);
10765: }
1.1040 raeburn 10766: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10767: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10768: foreach my $slot (keys(%slots)) {
10769: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10770: if ($symb) {
1.1229 raeburn 10771: if ($slots{$slot}->{'symb'} ne '') {
10772: my $canuse;
10773: my %oksymbs;
10774: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
10775: map { $oksymbs{$_} = 1; } @slotsymbs;
10776: if ($oksymbs{$symb}) {
10777: $canuse = 1;
10778: } else {
10779: foreach my $item (@slotsymbs) {
10780: if ($item =~ /\.(page|sequence)$/) {
10781: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
10782: if (($map ne '') && ($map eq $sloturl)) {
10783: $canuse = 1;
10784: last;
10785: }
10786: }
10787: }
10788: }
10789: next unless ($canuse);
10790: }
1.1040 raeburn 10791: }
10792: if (($slots{$slot}->{'starttime'} > $now) &&
10793: ($slots{$slot}->{'endtime'} > $now)) {
10794: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10795: my $userallowed = 0;
10796: if ($slots{$slot}->{'allowedsections'}) {
10797: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10798: if (!defined($env{'request.role.sec'})
10799: && grep(/^No section assigned$/,@allowed_sec)) {
10800: $userallowed=1;
10801: } else {
10802: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10803: $userallowed=1;
10804: }
10805: }
10806: unless ($userallowed) {
10807: if (defined($env{'request.course.groups'})) {
10808: my @groups = split(/:/,$env{'request.course.groups'});
10809: foreach my $group (@groups) {
10810: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10811: $userallowed=1;
10812: last;
10813: }
10814: }
10815: }
10816: }
10817: }
10818: if ($slots{$slot}->{'allowedusers'}) {
10819: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10820: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10821: if (grep(/^\Q$user\E$/,@allowed_users)) {
10822: $userallowed = 1;
10823: }
10824: }
10825: next unless($userallowed);
10826: }
10827: my $startreserve = $slots{$slot}->{'startreserve'};
10828: my $endreserve = $slots{$slot}->{'endreserve'};
10829: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 10830: my $uniqueperiod;
10831: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10832: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10833: }
1.1040 raeburn 10834: if (($startreserve < $now) &&
10835: (!$endreserve || $endreserve > $now)) {
10836: my $lastres = $endreserve;
10837: if (!$lastres) {
10838: $lastres = $slots{$slot}->{'starttime'};
10839: }
10840: $reservable_now{$slot} = {
10841: symb => $symb,
1.1250 raeburn 10842: endreserve => $lastres,
10843: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10844: };
10845: } elsif (($startreserve > $now) &&
10846: (!$endreserve || $endreserve > $startreserve)) {
10847: $future_reservable{$slot} = {
10848: symb => $symb,
1.1250 raeburn 10849: startreserve => $startreserve,
10850: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10851: };
10852: }
10853: }
10854: }
10855: my @unsorted_reservable = keys(%reservable_now);
10856: if (@unsorted_reservable > 0) {
10857: @sorted_reservable =
10858: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10859: }
10860: my @unsorted_future = keys(%future_reservable);
10861: if (@unsorted_future > 0) {
10862: @sorted_future =
10863: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10864: }
10865: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10866: }
1.780 raeburn 10867:
10868: =pod
10869:
1.1057 foxr 10870: =back
10871:
1.549 albertel 10872: =head1 HTTP Helpers
10873:
10874: =over 4
10875:
1.648 raeburn 10876: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10877:
1.258 albertel 10878: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10879: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10880: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10881:
10882: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10883: $possible_names is an ref to an array of form element names. As an example:
10884: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10885: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10886:
10887: =cut
1.1 albertel 10888:
1.6 albertel 10889: sub get_unprocessed_cgi {
1.25 albertel 10890: my ($query,$possible_names)= @_;
1.26 matthew 10891: # $Apache::lonxml::debug=1;
1.356 albertel 10892: foreach my $pair (split(/&/,$query)) {
10893: my ($name, $value) = split(/=/,$pair);
1.369 www 10894: $name = &unescape($name);
1.25 albertel 10895: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10896: $value =~ tr/+/ /;
10897: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10898: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10899: }
1.16 harris41 10900: }
1.6 albertel 10901: }
10902:
1.112 bowersj2 10903: =pod
10904:
1.648 raeburn 10905: =item * &cacheheader()
1.112 bowersj2 10906:
10907: returns cache-controlling header code
10908:
10909: =cut
10910:
1.7 albertel 10911: sub cacheheader {
1.258 albertel 10912: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10913: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10914: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10915: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10916: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10917: return $output;
1.7 albertel 10918: }
10919:
1.112 bowersj2 10920: =pod
10921:
1.648 raeburn 10922: =item * &no_cache($r)
1.112 bowersj2 10923:
10924: specifies header code to not have cache
10925:
10926: =cut
10927:
1.9 albertel 10928: sub no_cache {
1.216 albertel 10929: my ($r) = @_;
10930: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10931: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10932: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10933: $r->no_cache(1);
10934: $r->header_out("Expires" => $date);
10935: $r->header_out("Pragma" => "no-cache");
1.123 www 10936: }
10937:
10938: sub content_type {
1.181 albertel 10939: my ($r,$type,$charset) = @_;
1.299 foxr 10940: if ($r) {
10941: # Note that printout.pl calls this with undef for $r.
10942: &no_cache($r);
10943: }
1.258 albertel 10944: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10945: unless ($charset) {
10946: $charset=&Apache::lonlocal::current_encoding;
10947: }
10948: if ($charset) { $type.='; charset='.$charset; }
10949: if ($r) {
10950: $r->content_type($type);
10951: } else {
10952: print("Content-type: $type\n\n");
10953: }
1.9 albertel 10954: }
1.25 albertel 10955:
1.112 bowersj2 10956: =pod
10957:
1.648 raeburn 10958: =item * &add_to_env($name,$value)
1.112 bowersj2 10959:
1.258 albertel 10960: adds $name to the %env hash with value
1.112 bowersj2 10961: $value, if $name already exists, the entry is converted to an array
10962: reference and $value is added to the array.
10963:
10964: =cut
10965:
1.25 albertel 10966: sub add_to_env {
10967: my ($name,$value)=@_;
1.258 albertel 10968: if (defined($env{$name})) {
10969: if (ref($env{$name})) {
1.25 albertel 10970: #already have multiple values
1.258 albertel 10971: push(@{ $env{$name} },$value);
1.25 albertel 10972: } else {
10973: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10974: my $first=$env{$name};
10975: undef($env{$name});
10976: push(@{ $env{$name} },$first,$value);
1.25 albertel 10977: }
10978: } else {
1.258 albertel 10979: $env{$name}=$value;
1.25 albertel 10980: }
1.31 albertel 10981: }
1.149 albertel 10982:
10983: =pod
10984:
1.648 raeburn 10985: =item * &get_env_multiple($name)
1.149 albertel 10986:
1.258 albertel 10987: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10988: values may be defined and end up as an array ref.
10989:
10990: returns an array of values
10991:
10992: =cut
10993:
10994: sub get_env_multiple {
10995: my ($name) = @_;
10996: my @values;
1.258 albertel 10997: if (defined($env{$name})) {
1.149 albertel 10998: # exists is it an array
1.258 albertel 10999: if (ref($env{$name})) {
11000: @values=@{ $env{$name} };
1.149 albertel 11001: } else {
1.258 albertel 11002: $values[0]=$env{$name};
1.149 albertel 11003: }
11004: }
11005: return(@values);
11006: }
11007:
1.1249 damieng 11008: # Looks at given dependencies, and returns something depending on the context.
11009: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
11010: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11011: # For all other contexts, returns ($output, $counter, $numpathchg).
11012: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11013: # $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.
11014: # $numpathchg: integer with the number of cleaned up dependency paths.
11015: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11016: # \%mapping: hash reference clean path -> original path for all dependencies.
11017: # @param {string} actionurl - The path to the handler, indicative of the context.
11018: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11019: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11020: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11021: # @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)
11022: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11023: sub ask_for_embedded_content {
1.1249 damieng 11024: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11025: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11026: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11027: %currsubfile,%unused,$rem);
1.1071 raeburn 11028: my $counter = 0;
11029: my $numnew = 0;
1.987 raeburn 11030: my $numremref = 0;
11031: my $numinvalid = 0;
11032: my $numpathchg = 0;
11033: my $numexisting = 0;
1.1071 raeburn 11034: my $numunused = 0;
11035: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11036: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11037: my $heading = &mt('Upload embedded files');
11038: my $buttontext = &mt('Upload');
11039:
1.1249 damieng 11040: # fills these variables based on the context:
11041: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11042: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11043: if ($env{'request.course.id'}) {
1.1123 raeburn 11044: if ($actionurl eq '/adm/dependencies') {
11045: $navmap = Apache::lonnavmaps::navmap->new();
11046: }
11047: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11048: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11049: }
1.1123 raeburn 11050: if (($actionurl eq '/adm/portfolio') ||
11051: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11052: my $current_path='/';
11053: if ($env{'form.currentpath'}) {
11054: $current_path = $env{'form.currentpath'};
11055: }
11056: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11057: $udom = $cdom;
11058: $uname = $cnum;
1.984 raeburn 11059: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11060: } else {
11061: $udom = $env{'user.domain'};
11062: $uname = $env{'user.name'};
11063: $url = '/userfiles/portfolio';
11064: }
1.987 raeburn 11065: $toplevel = $url.'/';
1.984 raeburn 11066: $url .= $current_path;
11067: $getpropath = 1;
1.987 raeburn 11068: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11069: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11070: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11071: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11072: $toplevel = $url;
1.984 raeburn 11073: if ($rest ne '') {
1.987 raeburn 11074: $url .= $rest;
11075: }
11076: } elsif ($actionurl eq '/adm/coursedocs') {
11077: if (ref($args) eq 'HASH') {
1.1071 raeburn 11078: $url = $args->{'docs_url'};
11079: $toplevel = $url;
1.1084 raeburn 11080: if ($args->{'context'} eq 'paste') {
11081: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11082: ($path) =
11083: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11084: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11085: $fileloc =~ s{^/}{};
11086: }
1.1071 raeburn 11087: }
1.1084 raeburn 11088: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11089: if ($env{'request.course.id'} ne '') {
11090: if (ref($args) eq 'HASH') {
11091: $url = $args->{'docs_url'};
11092: $title = $args->{'docs_title'};
1.1126 raeburn 11093: $toplevel = $url;
11094: unless ($toplevel =~ m{^/}) {
11095: $toplevel = "/$url";
11096: }
1.1085 raeburn 11097: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11098: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11099: $path = $1;
11100: } else {
11101: ($path) =
11102: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11103: }
1.1195 raeburn 11104: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11105: $fileloc = $toplevel;
11106: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11107: my ($udom,$uname,$fname) =
11108: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11109: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11110: } else {
11111: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11112: }
1.1071 raeburn 11113: $fileloc =~ s{^/}{};
11114: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11115: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11116: }
1.987 raeburn 11117: }
1.1123 raeburn 11118: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11119: $udom = $cdom;
11120: $uname = $cnum;
11121: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11122: $toplevel = $url;
11123: $path = $url;
11124: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11125: $fileloc =~ s{^/}{};
1.987 raeburn 11126: }
1.1249 damieng 11127:
11128: # parses the dependency paths to get some info
11129: # fills $newfiles, $mapping, $subdependencies, $dependencies
11130: # $newfiles: hash URL -> 1 for new files or external URLs
11131: # (will be completed later)
11132: # $mapping:
11133: # for external URLs: external URL -> external URL
11134: # for relative paths: clean path -> original path
11135: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11136: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11137: foreach my $file (keys(%{$allfiles})) {
11138: my $embed_file;
11139: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11140: $embed_file = $1;
11141: } else {
11142: $embed_file = $file;
11143: }
1.1158 raeburn 11144: my ($absolutepath,$cleaned_file);
11145: if ($embed_file =~ m{^\w+://}) {
11146: $cleaned_file = $embed_file;
1.1147 raeburn 11147: $newfiles{$cleaned_file} = 1;
11148: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11149: } else {
1.1158 raeburn 11150: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11151: if ($embed_file =~ m{^/}) {
11152: $absolutepath = $embed_file;
11153: }
1.1147 raeburn 11154: if ($cleaned_file =~ m{/}) {
11155: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11156: $path = &check_for_traversal($path,$url,$toplevel);
11157: my $item = $fname;
11158: if ($path ne '') {
11159: $item = $path.'/'.$fname;
11160: $subdependencies{$path}{$fname} = 1;
11161: } else {
11162: $dependencies{$item} = 1;
11163: }
11164: if ($absolutepath) {
11165: $mapping{$item} = $absolutepath;
11166: } else {
11167: $mapping{$item} = $embed_file;
11168: }
11169: } else {
11170: $dependencies{$embed_file} = 1;
11171: if ($absolutepath) {
1.1147 raeburn 11172: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11173: } else {
1.1147 raeburn 11174: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11175: }
11176: }
1.984 raeburn 11177: }
11178: }
1.1249 damieng 11179:
11180: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11181: # and lists
11182: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11183: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11184: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11185: # the path had to be cleaned up
11186: # $existing: hash clean path -> 1 if the file exists
11187: # $numexisting: number of keys in $existing
11188: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11189: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11190: # dependency subdirectories that are
11191: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11192: my $dirptr = 16384;
1.984 raeburn 11193: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11194: $currsubfile{$path} = {};
1.1123 raeburn 11195: if (($actionurl eq '/adm/portfolio') ||
11196: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11197: my ($sublistref,$listerror) =
11198: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11199: if (ref($sublistref) eq 'ARRAY') {
11200: foreach my $line (@{$sublistref}) {
11201: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11202: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11203: }
1.984 raeburn 11204: }
1.987 raeburn 11205: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11206: if (opendir(my $dir,$url.'/'.$path)) {
11207: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11208: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11209: }
1.1084 raeburn 11210: } elsif (($actionurl eq '/adm/dependencies') ||
11211: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11212: ($args->{'context'} eq 'paste')) ||
11213: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11214: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11215: my $dir;
11216: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11217: $dir = $fileloc;
11218: } else {
11219: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11220: }
1.1071 raeburn 11221: if ($dir ne '') {
11222: my ($sublistref,$listerror) =
11223: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11224: if (ref($sublistref) eq 'ARRAY') {
11225: foreach my $line (@{$sublistref}) {
11226: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11227: undef,$mtime)=split(/\&/,$line,12);
11228: unless (($testdir&$dirptr) ||
11229: ($file_name =~ /^\.\.?$/)) {
11230: $currsubfile{$path}{$file_name} = [$size,$mtime];
11231: }
11232: }
11233: }
11234: }
1.984 raeburn 11235: }
11236: }
11237: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11238: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11239: my $item = $path.'/'.$file;
11240: unless ($mapping{$item} eq $item) {
11241: $pathchanges{$item} = 1;
11242: }
11243: $existing{$item} = 1;
11244: $numexisting ++;
11245: } else {
11246: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11247: }
11248: }
1.1071 raeburn 11249: if ($actionurl eq '/adm/dependencies') {
11250: foreach my $path (keys(%currsubfile)) {
11251: if (ref($currsubfile{$path}) eq 'HASH') {
11252: foreach my $file (keys(%{$currsubfile{$path}})) {
11253: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11254: next if (($rem ne '') &&
11255: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11256: (ref($navmap) &&
11257: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11258: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11259: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11260: $unused{$path.'/'.$file} = 1;
11261: }
11262: }
11263: }
11264: }
11265: }
1.984 raeburn 11266: }
1.1249 damieng 11267:
11268: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11269: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11270: my %currfile;
1.1123 raeburn 11271: if (($actionurl eq '/adm/portfolio') ||
11272: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11273: my ($dirlistref,$listerror) =
11274: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11275: if (ref($dirlistref) eq 'ARRAY') {
11276: foreach my $line (@{$dirlistref}) {
11277: my ($file_name,$rest) = split(/\&/,$line,2);
11278: $currfile{$file_name} = 1;
11279: }
1.984 raeburn 11280: }
1.987 raeburn 11281: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11282: if (opendir(my $dir,$url)) {
1.987 raeburn 11283: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11284: map {$currfile{$_} = 1;} @dir_list;
11285: }
1.1084 raeburn 11286: } elsif (($actionurl eq '/adm/dependencies') ||
11287: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11288: ($args->{'context'} eq 'paste')) ||
11289: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11290: if ($env{'request.course.id'} ne '') {
11291: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11292: if ($dir ne '') {
11293: my ($dirlistref,$listerror) =
11294: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11295: if (ref($dirlistref) eq 'ARRAY') {
11296: foreach my $line (@{$dirlistref}) {
11297: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11298: $size,undef,$mtime)=split(/\&/,$line,12);
11299: unless (($testdir&$dirptr) ||
11300: ($file_name =~ /^\.\.?$/)) {
11301: $currfile{$file_name} = [$size,$mtime];
11302: }
11303: }
11304: }
11305: }
11306: }
1.984 raeburn 11307: }
1.1249 damieng 11308: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11309: # are not in subdirectories, using $currfile
1.984 raeburn 11310: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11311: if (exists($currfile{$file})) {
1.987 raeburn 11312: unless ($mapping{$file} eq $file) {
11313: $pathchanges{$file} = 1;
11314: }
11315: $existing{$file} = 1;
11316: $numexisting ++;
11317: } else {
1.984 raeburn 11318: $newfiles{$file} = 1;
11319: }
11320: }
1.1071 raeburn 11321: foreach my $file (keys(%currfile)) {
11322: unless (($file eq $filename) ||
11323: ($file eq $filename.'.bak') ||
11324: ($dependencies{$file})) {
1.1085 raeburn 11325: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11326: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11327: next if (($rem ne '') &&
11328: (($env{"httpref.$rem".$file} ne '') ||
11329: (ref($navmap) &&
11330: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11331: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11332: ($navmap->getResourceByUrl($rem.$1)))))));
11333: }
1.1085 raeburn 11334: }
1.1071 raeburn 11335: $unused{$file} = 1;
11336: }
11337: }
1.1249 damieng 11338:
11339: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11340: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11341: ($args->{'context'} eq 'paste')) {
11342: $counter = scalar(keys(%existing));
11343: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11344: return ($output,$counter,$numpathchg,\%existing);
11345: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11346: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11347: $counter = scalar(keys(%existing));
11348: $numpathchg = scalar(keys(%pathchanges));
11349: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11350: }
1.1249 damieng 11351:
11352: # returns HTML otherwise, with dependency results and to ask for more uploads
11353:
11354: # $upload_output: missing dependencies (with upload form)
11355: # $modify_output: uploaded dependencies (in use)
11356: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11357: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11358: if ($actionurl eq '/adm/dependencies') {
11359: next if ($embed_file =~ m{^\w+://});
11360: }
1.660 raeburn 11361: $upload_output .= &start_data_table_row().
1.1123 raeburn 11362: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11363: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11364: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11365: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11366: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11367: }
1.1123 raeburn 11368: $upload_output .= '</td>';
1.1071 raeburn 11369: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11370: $upload_output.='<td align="right">'.
11371: '<span class="LC_info LC_fontsize_medium">'.
11372: &mt("URL points to web address").'</span>';
1.987 raeburn 11373: $numremref++;
1.660 raeburn 11374: } elsif ($args->{'error_on_invalid_names'}
11375: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11376: $upload_output.='<td align="right"><span class="LC_warning">'.
11377: &mt('Invalid characters').'</span>';
1.987 raeburn 11378: $numinvalid++;
1.660 raeburn 11379: } else {
1.1123 raeburn 11380: $upload_output .= '<td>'.
11381: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11382: $embed_file,\%mapping,
1.1071 raeburn 11383: $allfiles,$codebase,'upload');
11384: $counter ++;
11385: $numnew ++;
1.987 raeburn 11386: }
11387: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11388: }
11389: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11390: if ($actionurl eq '/adm/dependencies') {
11391: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11392: $modify_output .= &start_data_table_row().
11393: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11394: '<img src="'.&icon($embed_file).'" border="0" />'.
11395: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11396: '<td>'.$size.'</td>'.
11397: '<td>'.$mtime.'</td>'.
11398: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11399: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11400: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11401: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11402: &embedded_file_element('upload_embedded',$counter,
11403: $embed_file,\%mapping,
11404: $allfiles,$codebase,'modify').
11405: '</div></td>'.
11406: &end_data_table_row()."\n";
11407: $counter ++;
11408: } else {
11409: $upload_output .= &start_data_table_row().
1.1123 raeburn 11410: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11411: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11412: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11413: &Apache::loncommon::end_data_table_row()."\n";
11414: }
11415: }
11416: my $delidx = $counter;
11417: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11418: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11419: $delete_output .= &start_data_table_row().
11420: '<td><img src="'.&icon($oldfile).'" />'.
11421: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11422: '<td>'.$size.'</td>'.
11423: '<td>'.$mtime.'</td>'.
11424: '<td><label><input type="checkbox" name="del_upload_dep" '.
11425: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11426: &embedded_file_element('upload_embedded',$delidx,
11427: $oldfile,\%mapping,$allfiles,
11428: $codebase,'delete').'</td>'.
11429: &end_data_table_row()."\n";
11430: $numunused ++;
11431: $delidx ++;
1.987 raeburn 11432: }
11433: if ($upload_output) {
11434: $upload_output = &start_data_table().
11435: $upload_output.
11436: &end_data_table()."\n";
11437: }
1.1071 raeburn 11438: if ($modify_output) {
11439: $modify_output = &start_data_table().
11440: &start_data_table_header_row().
11441: '<th>'.&mt('File').'</th>'.
11442: '<th>'.&mt('Size (KB)').'</th>'.
11443: '<th>'.&mt('Modified').'</th>'.
11444: '<th>'.&mt('Upload replacement?').'</th>'.
11445: &end_data_table_header_row().
11446: $modify_output.
11447: &end_data_table()."\n";
11448: }
11449: if ($delete_output) {
11450: $delete_output = &start_data_table().
11451: &start_data_table_header_row().
11452: '<th>'.&mt('File').'</th>'.
11453: '<th>'.&mt('Size (KB)').'</th>'.
11454: '<th>'.&mt('Modified').'</th>'.
11455: '<th>'.&mt('Delete?').'</th>'.
11456: &end_data_table_header_row().
11457: $delete_output.
11458: &end_data_table()."\n";
11459: }
1.987 raeburn 11460: my $applies = 0;
11461: if ($numremref) {
11462: $applies ++;
11463: }
11464: if ($numinvalid) {
11465: $applies ++;
11466: }
11467: if ($numexisting) {
11468: $applies ++;
11469: }
1.1071 raeburn 11470: if ($counter || $numunused) {
1.987 raeburn 11471: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11472: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11473: $state.'<h3>'.$heading.'</h3>';
11474: if ($actionurl eq '/adm/dependencies') {
11475: if ($numnew) {
11476: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11477: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11478: $upload_output.'<br />'."\n";
11479: }
11480: if ($numexisting) {
11481: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11482: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11483: $modify_output.'<br />'."\n";
11484: $buttontext = &mt('Save changes');
11485: }
11486: if ($numunused) {
11487: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11488: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11489: $delete_output.'<br />'."\n";
11490: $buttontext = &mt('Save changes');
11491: }
11492: } else {
11493: $output .= $upload_output.'<br />'."\n";
11494: }
11495: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11496: $counter.'" />'."\n";
11497: if ($actionurl eq '/adm/dependencies') {
11498: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11499: $numnew.'" />'."\n";
11500: } elsif ($actionurl eq '') {
1.987 raeburn 11501: $output .= '<input type="hidden" name="phase" value="three" />';
11502: }
11503: } elsif ($applies) {
11504: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11505: if ($applies > 1) {
11506: $output .=
1.1123 raeburn 11507: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11508: if ($numremref) {
11509: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11510: }
11511: if ($numinvalid) {
11512: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11513: }
11514: if ($numexisting) {
11515: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11516: }
11517: $output .= '</ul><br />';
11518: } elsif ($numremref) {
11519: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11520: } elsif ($numinvalid) {
11521: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11522: } elsif ($numexisting) {
11523: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11524: }
11525: $output .= $upload_output.'<br />';
11526: }
11527: my ($pathchange_output,$chgcount);
1.1071 raeburn 11528: $chgcount = $counter;
1.987 raeburn 11529: if (keys(%pathchanges) > 0) {
11530: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11531: if ($counter) {
1.987 raeburn 11532: $output .= &embedded_file_element('pathchange',$chgcount,
11533: $embed_file,\%mapping,
1.1071 raeburn 11534: $allfiles,$codebase,'change');
1.987 raeburn 11535: } else {
11536: $pathchange_output .=
11537: &start_data_table_row().
11538: '<td><input type ="checkbox" name="namechange" value="'.
11539: $chgcount.'" checked="checked" /></td>'.
11540: '<td>'.$mapping{$embed_file}.'</td>'.
11541: '<td>'.$embed_file.
11542: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11543: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11544: '</td>'.&end_data_table_row();
1.660 raeburn 11545: }
1.987 raeburn 11546: $numpathchg ++;
11547: $chgcount ++;
1.660 raeburn 11548: }
11549: }
1.1127 raeburn 11550: if (($counter) || ($numunused)) {
1.987 raeburn 11551: if ($numpathchg) {
11552: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11553: $numpathchg.'" />'."\n";
11554: }
11555: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11556: ($actionurl eq '/adm/imsimport')) {
11557: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11558: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11559: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11560: } elsif ($actionurl eq '/adm/dependencies') {
11561: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11562: }
1.1123 raeburn 11563: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11564: } elsif ($numpathchg) {
11565: my %pathchange = ();
11566: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11567: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11568: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11569: }
1.987 raeburn 11570: }
1.1071 raeburn 11571: return ($output,$counter,$numpathchg);
1.987 raeburn 11572: }
11573:
1.1147 raeburn 11574: =pod
11575:
11576: =item * clean_path($name)
11577:
11578: Performs clean-up of directories, subdirectories and filename in an
11579: embedded object, referenced in an HTML file which is being uploaded
11580: to a course or portfolio, where
11581: "Upload embedded images/multimedia files if HTML file" checkbox was
11582: checked.
11583:
11584: Clean-up is similar to replacements in lonnet::clean_filename()
11585: except each / between sub-directory and next level is preserved.
11586:
11587: =cut
11588:
11589: sub clean_path {
11590: my ($embed_file) = @_;
11591: $embed_file =~s{^/+}{};
11592: my @contents;
11593: if ($embed_file =~ m{/}) {
11594: @contents = split(/\//,$embed_file);
11595: } else {
11596: @contents = ($embed_file);
11597: }
11598: my $lastidx = scalar(@contents)-1;
11599: for (my $i=0; $i<=$lastidx; $i++) {
11600: $contents[$i]=~s{\\}{/}g;
11601: $contents[$i]=~s/\s+/\_/g;
11602: $contents[$i]=~s{[^/\w\.\-]}{}g;
11603: if ($i == $lastidx) {
11604: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11605: }
11606: }
11607: if ($lastidx > 0) {
11608: return join('/',@contents);
11609: } else {
11610: return $contents[0];
11611: }
11612: }
11613:
1.987 raeburn 11614: sub embedded_file_element {
1.1071 raeburn 11615: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11616: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11617: (ref($codebase) eq 'HASH'));
11618: my $output;
1.1071 raeburn 11619: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11620: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11621: }
11622: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11623: &escape($embed_file).'" />';
11624: unless (($context eq 'upload_embedded') &&
11625: ($mapping->{$embed_file} eq $embed_file)) {
11626: $output .='
11627: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11628: }
11629: my $attrib;
11630: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11631: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11632: }
11633: $output .=
11634: "\n\t\t".
11635: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11636: $attrib.'" />';
11637: if (exists($codebase->{$mapping->{$embed_file}})) {
11638: $output .=
11639: "\n\t\t".
11640: '<input name="codebase_'.$num.'" type="hidden" value="'.
11641: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11642: }
1.987 raeburn 11643: return $output;
1.660 raeburn 11644: }
11645:
1.1071 raeburn 11646: sub get_dependency_details {
11647: my ($currfile,$currsubfile,$embed_file) = @_;
11648: my ($size,$mtime,$showsize,$showmtime);
11649: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11650: if ($embed_file =~ m{/}) {
11651: my ($path,$fname) = split(/\//,$embed_file);
11652: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11653: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11654: }
11655: } else {
11656: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11657: ($size,$mtime) = @{$currfile->{$embed_file}};
11658: }
11659: }
11660: $showsize = $size/1024.0;
11661: $showsize = sprintf("%.1f",$showsize);
11662: if ($mtime > 0) {
11663: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11664: }
11665: }
11666: return ($showsize,$showmtime);
11667: }
11668:
11669: sub ask_embedded_js {
11670: return <<"END";
11671: <script type="text/javascript"">
11672: // <![CDATA[
11673: function toggleBrowse(counter) {
11674: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11675: var fileid = document.getElementById('embedded_item_'+counter);
11676: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11677: if (chkboxid.checked == true) {
11678: uploaddivid.style.display='block';
11679: } else {
11680: uploaddivid.style.display='none';
11681: fileid.value = '';
11682: }
11683: }
11684: // ]]>
11685: </script>
11686:
11687: END
11688: }
11689:
1.661 raeburn 11690: sub upload_embedded {
11691: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11692: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11693: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11694: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11695: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11696: my $orig_uploaded_filename =
11697: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11698: foreach my $type ('orig','ref','attrib','codebase') {
11699: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11700: $env{'form.embedded_'.$type.'_'.$i} =
11701: &unescape($env{'form.embedded_'.$type.'_'.$i});
11702: }
11703: }
1.661 raeburn 11704: my ($path,$fname) =
11705: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11706: # no path, whole string is fname
11707: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11708: $fname = &Apache::lonnet::clean_filename($fname);
11709: # See if there is anything left
11710: next if ($fname eq '');
11711:
11712: # Check if file already exists as a file or directory.
11713: my ($state,$msg);
11714: if ($context eq 'portfolio') {
11715: my $port_path = $dirpath;
11716: if ($group ne '') {
11717: $port_path = "groups/$group/$port_path";
11718: }
1.987 raeburn 11719: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11720: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11721: $dir_root,$port_path,$disk_quota,
11722: $current_disk_usage,$uname,$udom);
11723: if ($state eq 'will_exceed_quota'
1.984 raeburn 11724: || $state eq 'file_locked') {
1.661 raeburn 11725: $output .= $msg;
11726: next;
11727: }
11728: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11729: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11730: if ($state eq 'exists') {
11731: $output .= $msg;
11732: next;
11733: }
11734: }
11735: # Check if extension is valid
11736: if (($fname =~ /\.(\w+)$/) &&
11737: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 11738: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11739: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11740: next;
11741: } elsif (($fname =~ /\.(\w+)$/) &&
11742: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11743: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11744: next;
11745: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 11746: $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 11747: next;
11748: }
11749: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 11750: my $subdir = $path;
11751: $subdir =~ s{/+$}{};
1.661 raeburn 11752: if ($context eq 'portfolio') {
1.984 raeburn 11753: my $result;
11754: if ($state eq 'existingfile') {
11755: $result=
11756: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 11757: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11758: } else {
1.984 raeburn 11759: $result=
11760: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11761: $dirpath.
1.1123 raeburn 11762: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11763: if ($result !~ m|^/uploaded/|) {
11764: $output .= '<span class="LC_error">'
11765: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11766: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11767: .'</span><br />';
11768: next;
11769: } else {
1.987 raeburn 11770: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11771: $path.$fname.'</span>').'<br />';
1.984 raeburn 11772: }
1.661 raeburn 11773: }
1.1123 raeburn 11774: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 11775: my $extendedsubdir = $dirpath.'/'.$subdir;
11776: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11777: my $result =
1.1126 raeburn 11778: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11779: if ($result !~ m|^/uploaded/|) {
11780: $output .= '<span class="LC_error">'
11781: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11782: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11783: .'</span><br />';
11784: next;
11785: } else {
11786: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11787: $path.$fname.'</span>').'<br />';
1.1125 raeburn 11788: if ($context eq 'syllabus') {
11789: &Apache::lonnet::make_public_indefinitely($result);
11790: }
1.987 raeburn 11791: }
1.661 raeburn 11792: } else {
11793: # Save the file
11794: my $target = $env{'form.embedded_item_'.$i};
11795: my $fullpath = $dir_root.$dirpath.'/'.$path;
11796: my $dest = $fullpath.$fname;
11797: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11798: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11799: my $count;
11800: my $filepath = $dir_root;
1.1027 raeburn 11801: foreach my $subdir (@parts) {
11802: $filepath .= "/$subdir";
11803: if (!-e $filepath) {
1.661 raeburn 11804: mkdir($filepath,0770);
11805: }
11806: }
11807: my $fh;
11808: if (!open($fh,'>'.$dest)) {
11809: &Apache::lonnet::logthis('Failed to create '.$dest);
11810: $output .= '<span class="LC_error">'.
1.1071 raeburn 11811: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11812: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11813: '</span><br />';
11814: } else {
11815: if (!print $fh $env{'form.embedded_item_'.$i}) {
11816: &Apache::lonnet::logthis('Failed to write to '.$dest);
11817: $output .= '<span class="LC_error">'.
1.1071 raeburn 11818: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11819: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11820: '</span><br />';
11821: } else {
1.987 raeburn 11822: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11823: $url.'</span>').'<br />';
11824: unless ($context eq 'testbank') {
11825: $footer .= &mt('View embedded file: [_1]',
11826: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11827: }
11828: }
11829: close($fh);
11830: }
11831: }
11832: if ($env{'form.embedded_ref_'.$i}) {
11833: $pathchange{$i} = 1;
11834: }
11835: }
11836: if ($output) {
11837: $output = '<p>'.$output.'</p>';
11838: }
11839: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11840: $returnflag = 'ok';
1.1071 raeburn 11841: my $numpathchgs = scalar(keys(%pathchange));
11842: if ($numpathchgs > 0) {
1.987 raeburn 11843: if ($context eq 'portfolio') {
11844: $output .= '<p>'.&mt('or').'</p>';
11845: } elsif ($context eq 'testbank') {
1.1071 raeburn 11846: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11847: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11848: $returnflag = 'modify_orightml';
11849: }
11850: }
1.1071 raeburn 11851: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11852: }
11853:
11854: sub modify_html_form {
11855: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11856: my $end = 0;
11857: my $modifyform;
11858: if ($context eq 'upload_embedded') {
11859: return unless (ref($pathchange) eq 'HASH');
11860: if ($env{'form.number_embedded_items'}) {
11861: $end += $env{'form.number_embedded_items'};
11862: }
11863: if ($env{'form.number_pathchange_items'}) {
11864: $end += $env{'form.number_pathchange_items'};
11865: }
11866: if ($end) {
11867: for (my $i=0; $i<$end; $i++) {
11868: if ($i < $env{'form.number_embedded_items'}) {
11869: next unless($pathchange->{$i});
11870: }
11871: $modifyform .=
11872: &start_data_table_row().
11873: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11874: 'checked="checked" /></td>'.
11875: '<td>'.$env{'form.embedded_ref_'.$i}.
11876: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11877: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11878: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11879: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11880: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11881: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11882: '<td>'.$env{'form.embedded_orig_'.$i}.
11883: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11884: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11885: &end_data_table_row();
1.1071 raeburn 11886: }
1.987 raeburn 11887: }
11888: } else {
11889: $modifyform = $pathchgtable;
11890: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11891: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11892: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11893: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11894: }
11895: }
11896: if ($modifyform) {
1.1071 raeburn 11897: if ($actionurl eq '/adm/dependencies') {
11898: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11899: }
1.987 raeburn 11900: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11901: '<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".
11902: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11903: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11904: '</ol></p>'."\n".'<p>'.
11905: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11906: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11907: &start_data_table()."\n".
11908: &start_data_table_header_row().
11909: '<th>'.&mt('Change?').'</th>'.
11910: '<th>'.&mt('Current reference').'</th>'.
11911: '<th>'.&mt('Required reference').'</th>'.
11912: &end_data_table_header_row()."\n".
11913: $modifyform.
11914: &end_data_table().'<br />'."\n".$hiddenstate.
11915: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11916: '</form>'."\n";
11917: }
11918: return;
11919: }
11920:
11921: sub modify_html_refs {
1.1123 raeburn 11922: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11923: my $container;
11924: if ($context eq 'portfolio') {
11925: $container = $env{'form.container'};
11926: } elsif ($context eq 'coursedoc') {
11927: $container = $env{'form.primaryurl'};
1.1071 raeburn 11928: } elsif ($context eq 'manage_dependencies') {
11929: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11930: $container = "/$container";
1.1123 raeburn 11931: } elsif ($context eq 'syllabus') {
11932: $container = $url;
1.987 raeburn 11933: } else {
1.1027 raeburn 11934: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11935: }
11936: my (%allfiles,%codebase,$output,$content);
11937: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 11938: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11939: if (wantarray) {
11940: return ('',0,0);
11941: } else {
11942: return;
11943: }
11944: }
11945: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11946: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11947: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11948: if (wantarray) {
11949: return ('',0,0);
11950: } else {
11951: return;
11952: }
11953: }
1.987 raeburn 11954: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11955: if ($content eq '-1') {
11956: if (wantarray) {
11957: return ('',0,0);
11958: } else {
11959: return;
11960: }
11961: }
1.987 raeburn 11962: } else {
1.1071 raeburn 11963: unless ($container =~ /^\Q$dir_root\E/) {
11964: if (wantarray) {
11965: return ('',0,0);
11966: } else {
11967: return;
11968: }
11969: }
1.987 raeburn 11970: if (open(my $fh,"<$container")) {
11971: $content = join('', <$fh>);
11972: close($fh);
11973: } else {
1.1071 raeburn 11974: if (wantarray) {
11975: return ('',0,0);
11976: } else {
11977: return;
11978: }
1.987 raeburn 11979: }
11980: }
11981: my ($count,$codebasecount) = (0,0);
11982: my $mm = new File::MMagic;
11983: my $mime_type = $mm->checktype_contents($content);
11984: if ($mime_type eq 'text/html') {
11985: my $parse_result =
11986: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11987: \%codebase,\$content);
11988: if ($parse_result eq 'ok') {
11989: foreach my $i (@changes) {
11990: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11991: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11992: if ($allfiles{$ref}) {
11993: my $newname = $orig;
11994: my ($attrib_regexp,$codebase);
1.1006 raeburn 11995: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11996: if ($attrib_regexp =~ /:/) {
11997: $attrib_regexp =~ s/\:/|/g;
11998: }
11999: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12000: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12001: $count += $numchg;
1.1123 raeburn 12002: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 12003: delete($allfiles{$ref});
1.987 raeburn 12004: }
12005: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 12006: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 12007: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
12008: $codebasecount ++;
12009: }
12010: }
12011: }
1.1123 raeburn 12012: my $skiprewrites;
1.987 raeburn 12013: if ($count || $codebasecount) {
12014: my $saveresult;
1.1071 raeburn 12015: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12016: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12017: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12018: if ($url eq $container) {
12019: my ($fname) = ($container =~ m{/([^/]+)$});
12020: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12021: $count,'<span class="LC_filename">'.
1.1071 raeburn 12022: $fname.'</span>').'</p>';
1.987 raeburn 12023: } else {
12024: $output = '<p class="LC_error">'.
12025: &mt('Error: update failed for: [_1].',
12026: '<span class="LC_filename">'.
12027: $container.'</span>').'</p>';
12028: }
1.1123 raeburn 12029: if ($context eq 'syllabus') {
12030: unless ($saveresult eq 'ok') {
12031: $skiprewrites = 1;
12032: }
12033: }
1.987 raeburn 12034: } else {
12035: if (open(my $fh,">$container")) {
12036: print $fh $content;
12037: close($fh);
12038: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12039: $count,'<span class="LC_filename">'.
12040: $container.'</span>').'</p>';
1.661 raeburn 12041: } else {
1.987 raeburn 12042: $output = '<p class="LC_error">'.
12043: &mt('Error: could not update [_1].',
12044: '<span class="LC_filename">'.
12045: $container.'</span>').'</p>';
1.661 raeburn 12046: }
12047: }
12048: }
1.1123 raeburn 12049: if (($context eq 'syllabus') && (!$skiprewrites)) {
12050: my ($actionurl,$state);
12051: $actionurl = "/public/$udom/$uname/syllabus";
12052: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12053: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12054: \%codebase,
12055: {'context' => 'rewrites',
12056: 'ignore_remote_references' => 1,});
12057: if (ref($mapping) eq 'HASH') {
12058: my $rewrites = 0;
12059: foreach my $key (keys(%{$mapping})) {
12060: next if ($key =~ m{^https?://});
12061: my $ref = $mapping->{$key};
12062: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12063: my $attrib;
12064: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12065: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12066: }
12067: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12068: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12069: $rewrites += $numchg;
12070: }
12071: }
12072: if ($rewrites) {
12073: my $saveresult;
12074: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12075: if ($url eq $container) {
12076: my ($fname) = ($container =~ m{/([^/]+)$});
12077: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12078: $count,'<span class="LC_filename">'.
12079: $fname.'</span>').'</p>';
12080: } else {
12081: $output .= '<p class="LC_error">'.
12082: &mt('Error: could not update links in [_1].',
12083: '<span class="LC_filename">'.
12084: $container.'</span>').'</p>';
12085:
12086: }
12087: }
12088: }
12089: }
1.987 raeburn 12090: } else {
12091: &logthis('Failed to parse '.$container.
12092: ' to modify references: '.$parse_result);
1.661 raeburn 12093: }
12094: }
1.1071 raeburn 12095: if (wantarray) {
12096: return ($output,$count,$codebasecount);
12097: } else {
12098: return $output;
12099: }
1.661 raeburn 12100: }
12101:
12102: sub check_for_existing {
12103: my ($path,$fname,$element) = @_;
12104: my ($state,$msg);
12105: if (-d $path.'/'.$fname) {
12106: $state = 'exists';
12107: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12108: } elsif (-e $path.'/'.$fname) {
12109: $state = 'exists';
12110: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12111: }
12112: if ($state eq 'exists') {
12113: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12114: }
12115: return ($state,$msg);
12116: }
12117:
12118: sub check_for_upload {
12119: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12120: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12121: my $filesize = length($env{'form.'.$element});
12122: if (!$filesize) {
12123: my $msg = '<span class="LC_error">'.
12124: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12125: '<span class="LC_filename">'.$fname.'</span>',
12126: $filesize).'<br />'.
1.1007 raeburn 12127: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12128: '</span>';
12129: return ('zero_bytes',$msg);
12130: }
12131: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12132: my $getpropath = 1;
1.1021 raeburn 12133: my ($dirlistref,$listerror) =
12134: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12135: my $found_file = 0;
12136: my $locked_file = 0;
1.991 raeburn 12137: my @lockers;
12138: my $navmap;
12139: if ($env{'request.course.id'}) {
12140: $navmap = Apache::lonnavmaps::navmap->new();
12141: }
1.1021 raeburn 12142: if (ref($dirlistref) eq 'ARRAY') {
12143: foreach my $line (@{$dirlistref}) {
12144: my ($file_name,$rest)=split(/\&/,$line,2);
12145: if ($file_name eq $fname){
12146: $file_name = $path.$file_name;
12147: if ($group ne '') {
12148: $file_name = $group.$file_name;
12149: }
12150: $found_file = 1;
12151: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12152: foreach my $lock (@lockers) {
12153: if (ref($lock) eq 'ARRAY') {
12154: my ($symb,$crsid) = @{$lock};
12155: if ($crsid eq $env{'request.course.id'}) {
12156: if (ref($navmap)) {
12157: my $res = $navmap->getBySymb($symb);
12158: foreach my $part (@{$res->parts()}) {
12159: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12160: unless (($slot_status == $res->RESERVED) ||
12161: ($slot_status == $res->RESERVED_LOCATION)) {
12162: $locked_file = 1;
12163: }
1.991 raeburn 12164: }
1.1021 raeburn 12165: } else {
12166: $locked_file = 1;
1.991 raeburn 12167: }
12168: } else {
12169: $locked_file = 1;
12170: }
12171: }
1.1021 raeburn 12172: }
12173: } else {
12174: my @info = split(/\&/,$rest);
12175: my $currsize = $info[6]/1000;
12176: if ($currsize < $filesize) {
12177: my $extra = $filesize - $currsize;
12178: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12179: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12180: &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 12181: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12182: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12183: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12184: return ('will_exceed_quota',$msg);
12185: }
1.984 raeburn 12186: }
12187: }
1.661 raeburn 12188: }
12189: }
12190: }
12191: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12192: my $msg = '<p class="LC_warning">'.
12193: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12194: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12195: return ('will_exceed_quota',$msg);
12196: } elsif ($found_file) {
12197: if ($locked_file) {
1.1179 bisitz 12198: my $msg = '<p class="LC_warning">';
1.661 raeburn 12199: $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 12200: $msg .= '</p>';
1.661 raeburn 12201: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12202: return ('file_locked',$msg);
12203: } else {
1.1179 bisitz 12204: my $msg = '<p class="LC_error">';
1.984 raeburn 12205: $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 12206: $msg .= '</p>';
1.984 raeburn 12207: return ('existingfile',$msg);
1.661 raeburn 12208: }
12209: }
12210: }
12211:
1.987 raeburn 12212: sub check_for_traversal {
12213: my ($path,$url,$toplevel) = @_;
12214: my @parts=split(/\//,$path);
12215: my $cleanpath;
12216: my $fullpath = $url;
12217: for (my $i=0;$i<@parts;$i++) {
12218: next if ($parts[$i] eq '.');
12219: if ($parts[$i] eq '..') {
12220: $fullpath =~ s{([^/]+/)$}{};
12221: } else {
12222: $fullpath .= $parts[$i].'/';
12223: }
12224: }
12225: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12226: $cleanpath = $1;
12227: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12228: my $curr_toprel = $1;
12229: my @parts = split(/\//,$curr_toprel);
12230: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12231: my @urlparts = split(/\//,$url_toprel);
12232: my $doubledots;
12233: my $startdiff = -1;
12234: for (my $i=0; $i<@urlparts; $i++) {
12235: if ($startdiff == -1) {
12236: unless ($urlparts[$i] eq $parts[$i]) {
12237: $startdiff = $i;
12238: $doubledots .= '../';
12239: }
12240: } else {
12241: $doubledots .= '../';
12242: }
12243: }
12244: if ($startdiff > -1) {
12245: $cleanpath = $doubledots;
12246: for (my $i=$startdiff; $i<@parts; $i++) {
12247: $cleanpath .= $parts[$i].'/';
12248: }
12249: }
12250: }
12251: $cleanpath =~ s{(/)$}{};
12252: return $cleanpath;
12253: }
1.31 albertel 12254:
1.1053 raeburn 12255: sub is_archive_file {
12256: my ($mimetype) = @_;
12257: if (($mimetype eq 'application/octet-stream') ||
12258: ($mimetype eq 'application/x-stuffit') ||
12259: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12260: return 1;
12261: }
12262: return;
12263: }
12264:
12265: sub decompress_form {
1.1065 raeburn 12266: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12267: my %lt = &Apache::lonlocal::texthash (
12268: this => 'This file is an archive file.',
1.1067 raeburn 12269: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12270: itsc => 'Its contents are as follows:',
1.1053 raeburn 12271: youm => 'You may wish to extract its contents.',
12272: extr => 'Extract contents',
1.1067 raeburn 12273: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12274: proa => 'Process automatically?',
1.1053 raeburn 12275: yes => 'Yes',
12276: no => 'No',
1.1067 raeburn 12277: fold => 'Title for folder containing movie',
12278: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12279: );
1.1065 raeburn 12280: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12281: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12282: my $info = &list_archive_contents($fileloc,\@paths);
12283: if (@paths) {
12284: foreach my $path (@paths) {
12285: $path =~ s{^/}{};
1.1067 raeburn 12286: if ($path =~ m{^([^/]+)/$}) {
12287: $topdir = $1;
12288: }
1.1065 raeburn 12289: if ($path =~ m{^([^/]+)/}) {
12290: $toplevel{$1} = $path;
12291: } else {
12292: $toplevel{$path} = $path;
12293: }
12294: }
12295: }
1.1067 raeburn 12296: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12297: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12298: "$topdir/media/",
12299: "$topdir/media/$topdir.mp4",
12300: "$topdir/media/FirstFrame.png",
12301: "$topdir/media/player.swf",
12302: "$topdir/media/swfobject.js",
12303: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12304: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12305: "$topdir/$topdir.mp4",
12306: "$topdir/$topdir\_config.xml",
12307: "$topdir/$topdir\_controller.swf",
12308: "$topdir/$topdir\_embed.css",
12309: "$topdir/$topdir\_First_Frame.png",
12310: "$topdir/$topdir\_player.html",
12311: "$topdir/$topdir\_Thumbnails.png",
12312: "$topdir/playerProductInstall.swf",
12313: "$topdir/scripts/",
12314: "$topdir/scripts/config_xml.js",
12315: "$topdir/scripts/handlebars.js",
12316: "$topdir/scripts/jquery-1.7.1.min.js",
12317: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12318: "$topdir/scripts/modernizr.js",
12319: "$topdir/scripts/player-min.js",
12320: "$topdir/scripts/swfobject.js",
12321: "$topdir/skins/",
12322: "$topdir/skins/configuration_express.xml",
12323: "$topdir/skins/express_show/",
12324: "$topdir/skins/express_show/player-min.css",
12325: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12326: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12327: "$topdir/$topdir.mp4",
12328: "$topdir/$topdir\_config.xml",
12329: "$topdir/$topdir\_controller.swf",
12330: "$topdir/$topdir\_embed.css",
12331: "$topdir/$topdir\_First_Frame.png",
12332: "$topdir/$topdir\_player.html",
12333: "$topdir/$topdir\_Thumbnails.png",
12334: "$topdir/playerProductInstall.swf",
12335: "$topdir/scripts/",
12336: "$topdir/scripts/config_xml.js",
12337: "$topdir/scripts/techsmith-smart-player.min.js",
12338: "$topdir/skins/",
12339: "$topdir/skins/configuration_express.xml",
12340: "$topdir/skins/express_show/",
12341: "$topdir/skins/express_show/spritesheet.min.css",
12342: "$topdir/skins/express_show/spritesheet.png",
12343: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12344: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12345: if (@diffs == 0) {
1.1164 raeburn 12346: $is_camtasia = 6;
12347: } else {
1.1197 raeburn 12348: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12349: if (@diffs == 0) {
12350: $is_camtasia = 8;
1.1197 raeburn 12351: } else {
12352: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12353: if (@diffs == 0) {
12354: $is_camtasia = 8;
12355: }
1.1164 raeburn 12356: }
1.1067 raeburn 12357: }
12358: }
12359: my $output;
12360: if ($is_camtasia) {
12361: $output = <<"ENDCAM";
12362: <script type="text/javascript" language="Javascript">
12363: // <![CDATA[
12364:
12365: function camtasiaToggle() {
12366: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12367: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12368: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12369: document.getElementById('camtasia_titles').style.display='block';
12370: } else {
12371: document.getElementById('camtasia_titles').style.display='none';
12372: }
12373: }
12374: }
12375: return;
12376: }
12377:
12378: // ]]>
12379: </script>
12380: <p>$lt{'camt'}</p>
12381: ENDCAM
1.1065 raeburn 12382: } else {
1.1067 raeburn 12383: $output = '<p>'.$lt{'this'};
12384: if ($info eq '') {
12385: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12386: } else {
12387: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12388: '<div><pre>'.$info.'</pre></div>';
12389: }
1.1065 raeburn 12390: }
1.1067 raeburn 12391: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12392: my $duplicates;
12393: my $num = 0;
12394: if (ref($dirlist) eq 'ARRAY') {
12395: foreach my $item (@{$dirlist}) {
12396: if (ref($item) eq 'ARRAY') {
12397: if (exists($toplevel{$item->[0]})) {
12398: $duplicates .=
12399: &start_data_table_row().
12400: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12401: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12402: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12403: 'value="1" />'.&mt('Yes').'</label>'.
12404: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12405: '<td>'.$item->[0].'</td>';
12406: if ($item->[2]) {
12407: $duplicates .= '<td>'.&mt('Directory').'</td>';
12408: } else {
12409: $duplicates .= '<td>'.&mt('File').'</td>';
12410: }
12411: $duplicates .= '<td>'.$item->[3].'</td>'.
12412: '<td>'.
12413: &Apache::lonlocal::locallocaltime($item->[4]).
12414: '</td>'.
12415: &end_data_table_row();
12416: $num ++;
12417: }
12418: }
12419: }
12420: }
12421: my $itemcount;
12422: if (@paths > 0) {
12423: $itemcount = scalar(@paths);
12424: } else {
12425: $itemcount = 1;
12426: }
1.1067 raeburn 12427: if ($is_camtasia) {
12428: $output .= $lt{'auto'}.'<br />'.
12429: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12430: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12431: $lt{'yes'}.'</label> <label>'.
12432: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12433: $lt{'no'}.'</label></span><br />'.
12434: '<div id="camtasia_titles" style="display:block">'.
12435: &Apache::lonhtmlcommon::start_pick_box().
12436: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12437: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12438: &Apache::lonhtmlcommon::row_closure().
12439: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12440: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12441: &Apache::lonhtmlcommon::row_closure(1).
12442: &Apache::lonhtmlcommon::end_pick_box().
12443: '</div>';
12444: }
1.1065 raeburn 12445: $output .=
12446: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12447: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12448: "\n";
1.1065 raeburn 12449: if ($duplicates ne '') {
12450: $output .= '<p><span class="LC_warning">'.
12451: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12452: &start_data_table().
12453: &start_data_table_header_row().
12454: '<th>'.&mt('Overwrite?').'</th>'.
12455: '<th>'.&mt('Name').'</th>'.
12456: '<th>'.&mt('Type').'</th>'.
12457: '<th>'.&mt('Size').'</th>'.
12458: '<th>'.&mt('Last modified').'</th>'.
12459: &end_data_table_header_row().
12460: $duplicates.
12461: &end_data_table().
12462: '</p>';
12463: }
1.1067 raeburn 12464: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12465: if (ref($hiddenelements) eq 'HASH') {
12466: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12467: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12468: }
12469: }
12470: $output .= <<"END";
1.1067 raeburn 12471: <br />
1.1053 raeburn 12472: <input type="submit" name="decompress" value="$lt{'extr'}" />
12473: </form>
12474: $noextract
12475: END
12476: return $output;
12477: }
12478:
1.1065 raeburn 12479: sub decompression_utility {
12480: my ($program) = @_;
12481: my @utilities = ('tar','gunzip','bunzip2','unzip');
12482: my $location;
12483: if (grep(/^\Q$program\E$/,@utilities)) {
12484: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12485: '/usr/sbin/') {
12486: if (-x $dir.$program) {
12487: $location = $dir.$program;
12488: last;
12489: }
12490: }
12491: }
12492: return $location;
12493: }
12494:
12495: sub list_archive_contents {
12496: my ($file,$pathsref) = @_;
12497: my (@cmd,$output);
12498: my $needsregexp;
12499: if ($file =~ /\.zip$/) {
12500: @cmd = (&decompression_utility('unzip'),"-l");
12501: $needsregexp = 1;
12502: } elsif (($file =~ m/\.tar\.gz$/) ||
12503: ($file =~ /\.tgz$/)) {
12504: @cmd = (&decompression_utility('tar'),"-ztf");
12505: } elsif ($file =~ /\.tar\.bz2$/) {
12506: @cmd = (&decompression_utility('tar'),"-jtf");
12507: } elsif ($file =~ m|\.tar$|) {
12508: @cmd = (&decompression_utility('tar'),"-tf");
12509: }
12510: if (@cmd) {
12511: undef($!);
12512: undef($@);
12513: if (open(my $fh,"-|", @cmd, $file)) {
12514: while (my $line = <$fh>) {
12515: $output .= $line;
12516: chomp($line);
12517: my $item;
12518: if ($needsregexp) {
12519: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12520: } else {
12521: $item = $line;
12522: }
12523: if ($item ne '') {
12524: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12525: push(@{$pathsref},$item);
12526: }
12527: }
12528: }
12529: close($fh);
12530: }
12531: }
12532: return $output;
12533: }
12534:
1.1053 raeburn 12535: sub decompress_uploaded_file {
12536: my ($file,$dir) = @_;
12537: &Apache::lonnet::appenv({'cgi.file' => $file});
12538: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12539: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12540: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12541: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12542: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12543: my $decompressed = $env{'cgi.decompressed'};
12544: &Apache::lonnet::delenv('cgi.file');
12545: &Apache::lonnet::delenv('cgi.dir');
12546: &Apache::lonnet::delenv('cgi.decompressed');
12547: return ($decompressed,$result);
12548: }
12549:
1.1055 raeburn 12550: sub process_decompression {
12551: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
12552: my ($dir,$error,$warning,$output);
1.1180 raeburn 12553: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12554: $error = &mt('Filename not a supported archive file type.').
12555: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12556: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12557: } else {
12558: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12559: if ($docuhome eq 'no_host') {
12560: $error = &mt('Could not determine home server for course.');
12561: } else {
12562: my @ids=&Apache::lonnet::current_machine_ids();
12563: my $currdir = "$dir_root/$destination";
12564: if (grep(/^\Q$docuhome\E$/,@ids)) {
12565: $dir = &LONCAPA::propath($docudom,$docuname).
12566: "$dir_root/$destination";
12567: } else {
12568: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12569: "$dir_root/$docudom/$docuname/$destination";
12570: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12571: $error = &mt('Archive file not found.');
12572: }
12573: }
1.1065 raeburn 12574: my (@to_overwrite,@to_skip);
12575: if ($env{'form.archive_overwrite_total'} > 0) {
12576: my $total = $env{'form.archive_overwrite_total'};
12577: for (my $i=0; $i<$total; $i++) {
12578: if ($env{'form.archive_overwrite_'.$i} == 1) {
12579: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12580: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12581: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12582: }
12583: }
12584: }
12585: my $numskip = scalar(@to_skip);
12586: if (($numskip > 0) &&
12587: ($numskip == $env{'form.archive_itemcount'})) {
12588: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12589: } elsif ($dir eq '') {
1.1055 raeburn 12590: $error = &mt('Directory containing archive file unavailable.');
12591: } elsif (!$error) {
1.1065 raeburn 12592: my ($decompressed,$display);
12593: if ($numskip > 0) {
12594: my $tempdir = time.'_'.$$.int(rand(10000));
12595: mkdir("$dir/$tempdir",0755);
12596: system("mv $dir/$file $dir/$tempdir/$file");
12597: ($decompressed,$display) =
12598: &decompress_uploaded_file($file,"$dir/$tempdir");
12599: foreach my $item (@to_skip) {
12600: if (($item ne '') && ($item !~ /\.\./)) {
12601: if (-f "$dir/$tempdir/$item") {
12602: unlink("$dir/$tempdir/$item");
12603: } elsif (-d "$dir/$tempdir/$item") {
12604: system("rm -rf $dir/$tempdir/$item");
12605: }
12606: }
12607: }
12608: system("mv $dir/$tempdir/* $dir");
12609: rmdir("$dir/$tempdir");
12610: } else {
12611: ($decompressed,$display) =
12612: &decompress_uploaded_file($file,$dir);
12613: }
1.1055 raeburn 12614: if ($decompressed eq 'ok') {
1.1065 raeburn 12615: $output = '<p class="LC_info">'.
12616: &mt('Files extracted successfully from archive.').
12617: '</p>'."\n";
1.1055 raeburn 12618: my ($warning,$result,@contents);
12619: my ($newdirlistref,$newlisterror) =
12620: &Apache::lonnet::dirlist($currdir,$docudom,
12621: $docuname,1);
12622: my (%is_dir,%changes,@newitems);
12623: my $dirptr = 16384;
1.1065 raeburn 12624: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12625: foreach my $dir_line (@{$newdirlistref}) {
12626: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 12627: unless (($item =~ /^\.+$/) || ($item eq $file) ||
12628: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 12629: push(@newitems,$item);
12630: if ($dirptr&$testdir) {
12631: $is_dir{$item} = 1;
12632: }
12633: $changes{$item} = 1;
12634: }
12635: }
12636: }
12637: if (keys(%changes) > 0) {
12638: foreach my $item (sort(@newitems)) {
12639: if ($changes{$item}) {
12640: push(@contents,$item);
12641: }
12642: }
12643: }
12644: if (@contents > 0) {
1.1067 raeburn 12645: my $wantform;
12646: unless ($env{'form.autoextract_camtasia'}) {
12647: $wantform = 1;
12648: }
1.1056 raeburn 12649: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12650: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12651: $currdir,\%is_dir,
12652: \%children,\%parent,
1.1056 raeburn 12653: \@contents,\%dirorder,
12654: \%titles,$wantform);
1.1055 raeburn 12655: if ($datatable ne '') {
12656: $output .= &archive_options_form('decompressed',$datatable,
12657: $count,$hiddenelem);
1.1065 raeburn 12658: my $startcount = 6;
1.1055 raeburn 12659: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12660: \%titles,\%children);
1.1055 raeburn 12661: }
1.1067 raeburn 12662: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 12663: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12664: my %displayed;
12665: my $total = 1;
12666: $env{'form.archive_directory'} = [];
12667: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12668: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12669: $path =~ s{/$}{};
12670: my $item;
12671: if ($path ne '') {
12672: $item = "$path/$titles{$i}";
12673: } else {
12674: $item = $titles{$i};
12675: }
12676: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12677: if ($item eq $contents[0]) {
12678: push(@{$env{'form.archive_directory'}},$i);
12679: $env{'form.archive_'.$i} = 'display';
12680: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12681: $displayed{'folder'} = $i;
1.1164 raeburn 12682: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12683: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12684: $env{'form.archive_'.$i} = 'display';
12685: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12686: $displayed{'web'} = $i;
12687: } else {
1.1164 raeburn 12688: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12689: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12690: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12691: push(@{$env{'form.archive_directory'}},$i);
12692: }
12693: $env{'form.archive_'.$i} = 'dependency';
12694: }
12695: $total ++;
12696: }
12697: for (my $i=1; $i<$total; $i++) {
12698: next if ($i == $displayed{'web'});
12699: next if ($i == $displayed{'folder'});
12700: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12701: }
12702: $env{'form.phase'} = 'decompress_cleanup';
12703: $env{'form.archivedelete'} = 1;
12704: $env{'form.archive_count'} = $total-1;
12705: $output .=
12706: &process_extracted_files('coursedocs',$docudom,
12707: $docuname,$destination,
12708: $dir_root,$hiddenelem);
12709: }
1.1055 raeburn 12710: } else {
12711: $warning = &mt('No new items extracted from archive file.');
12712: }
12713: } else {
12714: $output = $display;
12715: $error = &mt('An error occurred during extraction from the archive file.');
12716: }
12717: }
12718: }
12719: }
12720: if ($error) {
12721: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12722: $error.'</p>'."\n";
12723: }
12724: if ($warning) {
12725: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12726: }
12727: return $output;
12728: }
12729:
12730: sub get_extracted {
1.1056 raeburn 12731: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12732: $titles,$wantform) = @_;
1.1055 raeburn 12733: my $count = 0;
12734: my $depth = 0;
12735: my $datatable;
1.1056 raeburn 12736: my @hierarchy;
1.1055 raeburn 12737: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12738: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12739: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12740: foreach my $item (@{$contents}) {
12741: $count ++;
1.1056 raeburn 12742: @{$dirorder->{$count}} = @hierarchy;
12743: $titles->{$count} = $item;
1.1055 raeburn 12744: &archive_hierarchy($depth,$count,$parent,$children);
12745: if ($wantform) {
12746: $datatable .= &archive_row($is_dir->{$item},$item,
12747: $currdir,$depth,$count);
12748: }
12749: if ($is_dir->{$item}) {
12750: $depth ++;
1.1056 raeburn 12751: push(@hierarchy,$count);
12752: $parent->{$depth} = $count;
1.1055 raeburn 12753: $datatable .=
12754: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12755: \$depth,\$count,\@hierarchy,$dirorder,
12756: $children,$parent,$titles,$wantform);
1.1055 raeburn 12757: $depth --;
1.1056 raeburn 12758: pop(@hierarchy);
1.1055 raeburn 12759: }
12760: }
12761: return ($count,$datatable);
12762: }
12763:
12764: sub recurse_extracted_archive {
1.1056 raeburn 12765: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12766: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12767: my $result='';
1.1056 raeburn 12768: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12769: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12770: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12771: return $result;
12772: }
12773: my $dirptr = 16384;
12774: my ($newdirlistref,$newlisterror) =
12775: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12776: if (ref($newdirlistref) eq 'ARRAY') {
12777: foreach my $dir_line (@{$newdirlistref}) {
12778: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12779: unless ($item =~ /^\.+$/) {
12780: $$count ++;
1.1056 raeburn 12781: @{$dirorder->{$$count}} = @{$hierarchy};
12782: $titles->{$$count} = $item;
1.1055 raeburn 12783: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12784:
1.1055 raeburn 12785: my $is_dir;
12786: if ($dirptr&$testdir) {
12787: $is_dir = 1;
12788: }
12789: if ($wantform) {
12790: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12791: }
12792: if ($is_dir) {
12793: $$depth ++;
1.1056 raeburn 12794: push(@{$hierarchy},$$count);
12795: $parent->{$$depth} = $$count;
1.1055 raeburn 12796: $result .=
12797: &recurse_extracted_archive("$currdir/$item",$docudom,
12798: $docuname,$depth,$count,
1.1056 raeburn 12799: $hierarchy,$dirorder,$children,
12800: $parent,$titles,$wantform);
1.1055 raeburn 12801: $$depth --;
1.1056 raeburn 12802: pop(@{$hierarchy});
1.1055 raeburn 12803: }
12804: }
12805: }
12806: }
12807: return $result;
12808: }
12809:
12810: sub archive_hierarchy {
12811: my ($depth,$count,$parent,$children) =@_;
12812: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12813: if (exists($parent->{$depth})) {
12814: $children->{$parent->{$depth}} .= $count.':';
12815: }
12816: }
12817: return;
12818: }
12819:
12820: sub archive_row {
12821: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12822: my ($name) = ($item =~ m{([^/]+)$});
12823: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12824: 'display' => 'Add as file',
1.1055 raeburn 12825: 'dependency' => 'Include as dependency',
12826: 'discard' => 'Discard',
12827: );
12828: if ($is_dir) {
1.1059 raeburn 12829: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12830: }
1.1056 raeburn 12831: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12832: my $offset = 0;
1.1055 raeburn 12833: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12834: $offset ++;
1.1065 raeburn 12835: if ($action ne 'display') {
12836: $offset ++;
12837: }
1.1055 raeburn 12838: $output .= '<td><span class="LC_nobreak">'.
12839: '<label><input type="radio" name="archive_'.$count.
12840: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12841: my $text = $choices{$action};
12842: if ($is_dir) {
12843: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12844: if ($action eq 'display') {
1.1059 raeburn 12845: $text = &mt('Add as folder');
1.1055 raeburn 12846: }
1.1056 raeburn 12847: } else {
12848: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12849:
12850: }
12851: $output .= ' /> '.$choices{$action}.'</label></span>';
12852: if ($action eq 'dependency') {
12853: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12854: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12855: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12856: '<option value=""></option>'."\n".
12857: '</select>'."\n".
12858: '</div>';
1.1059 raeburn 12859: } elsif ($action eq 'display') {
12860: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12861: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12862: '</div>';
1.1055 raeburn 12863: }
1.1056 raeburn 12864: $output .= '</td>';
1.1055 raeburn 12865: }
12866: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12867: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12868: for (my $i=0; $i<$depth; $i++) {
12869: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12870: }
12871: if ($is_dir) {
12872: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12873: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12874: } else {
12875: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12876: }
12877: $output .= ' '.$name.'</td>'."\n".
12878: &end_data_table_row();
12879: return $output;
12880: }
12881:
12882: sub archive_options_form {
1.1065 raeburn 12883: my ($form,$display,$count,$hiddenelem) = @_;
12884: my %lt = &Apache::lonlocal::texthash(
12885: perm => 'Permanently remove archive file?',
12886: hows => 'How should each extracted item be incorporated in the course?',
12887: cont => 'Content actions for all',
12888: addf => 'Add as folder/file',
12889: incd => 'Include as dependency for a displayed file',
12890: disc => 'Discard',
12891: no => 'No',
12892: yes => 'Yes',
12893: save => 'Save',
12894: );
12895: my $output = <<"END";
12896: <form name="$form" method="post" action="">
12897: <p><span class="LC_nobreak">$lt{'perm'}
12898: <label>
12899: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12900: </label>
12901:
12902: <label>
12903: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12904: </span>
12905: </p>
12906: <input type="hidden" name="phase" value="decompress_cleanup" />
12907: <br />$lt{'hows'}
12908: <div class="LC_columnSection">
12909: <fieldset>
12910: <legend>$lt{'cont'}</legend>
12911: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12912: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12913: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12914: </fieldset>
12915: </div>
12916: END
12917: return $output.
1.1055 raeburn 12918: &start_data_table()."\n".
1.1065 raeburn 12919: $display."\n".
1.1055 raeburn 12920: &end_data_table()."\n".
12921: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12922: $hiddenelem.
1.1065 raeburn 12923: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12924: '</form>';
12925: }
12926:
12927: sub archive_javascript {
1.1056 raeburn 12928: my ($startcount,$numitems,$titles,$children) = @_;
12929: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12930: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12931: my $scripttag = <<START;
12932: <script type="text/javascript">
12933: // <![CDATA[
12934:
12935: function checkAll(form,prefix) {
12936: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12937: for (var i=0; i < form.elements.length; i++) {
12938: var id = form.elements[i].id;
12939: if ((id != '') && (id != undefined)) {
12940: if (idstr.test(id)) {
12941: if (form.elements[i].type == 'radio') {
12942: form.elements[i].checked = true;
1.1056 raeburn 12943: var nostart = i-$startcount;
1.1059 raeburn 12944: var offset = nostart%7;
12945: var count = (nostart-offset)/7;
1.1056 raeburn 12946: dependencyCheck(form,count,offset);
1.1055 raeburn 12947: }
12948: }
12949: }
12950: }
12951: }
12952:
12953: function propagateCheck(form,count) {
12954: if (count > 0) {
1.1059 raeburn 12955: var startelement = $startcount + ((count-1) * 7);
12956: for (var j=1; j<6; j++) {
12957: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12958: var item = startelement + j;
12959: if (form.elements[item].type == 'radio') {
12960: if (form.elements[item].checked) {
12961: containerCheck(form,count,j);
12962: break;
12963: }
1.1055 raeburn 12964: }
12965: }
12966: }
12967: }
12968: }
12969:
12970: numitems = $numitems
1.1056 raeburn 12971: var titles = new Array(numitems);
12972: var parents = new Array(numitems);
1.1055 raeburn 12973: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12974: parents[i] = new Array;
1.1055 raeburn 12975: }
1.1059 raeburn 12976: var maintitle = '$maintitle';
1.1055 raeburn 12977:
12978: START
12979:
1.1056 raeburn 12980: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12981: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12982: for (my $i=0; $i<@contents; $i ++) {
12983: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12984: }
12985: }
12986:
1.1056 raeburn 12987: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12988: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12989: }
12990:
1.1055 raeburn 12991: $scripttag .= <<END;
12992:
12993: function containerCheck(form,count,offset) {
12994: if (count > 0) {
1.1056 raeburn 12995: dependencyCheck(form,count,offset);
1.1059 raeburn 12996: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12997: form.elements[item].checked = true;
12998: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12999: if (parents[count].length > 0) {
13000: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 13001: containerCheck(form,parents[count][j],offset);
13002: }
13003: }
13004: }
13005: }
13006: }
13007:
13008: function dependencyCheck(form,count,offset) {
13009: if (count > 0) {
1.1059 raeburn 13010: var chosen = (offset+$startcount)+7*(count-1);
13011: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13012: var currtype = form.elements[depitem].type;
13013: if (form.elements[chosen].value == 'dependency') {
13014: document.getElementById('arc_depon_'+count).style.display='block';
13015: form.elements[depitem].options.length = 0;
13016: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13017: for (var i=1; i<=numitems; i++) {
13018: if (i == count) {
13019: continue;
13020: }
1.1059 raeburn 13021: var startelement = $startcount + (i-1) * 7;
13022: for (var j=1; j<6; j++) {
13023: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13024: var item = startelement + j;
13025: if (form.elements[item].type == 'radio') {
13026: if (form.elements[item].checked) {
13027: if (form.elements[item].value == 'display') {
13028: var n = form.elements[depitem].options.length;
13029: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13030: }
13031: }
13032: }
13033: }
13034: }
13035: }
13036: } else {
13037: document.getElementById('arc_depon_'+count).style.display='none';
13038: form.elements[depitem].options.length = 0;
13039: form.elements[depitem].options[0] = new Option('Select','',true,true);
13040: }
1.1059 raeburn 13041: titleCheck(form,count,offset);
1.1056 raeburn 13042: }
13043: }
13044:
13045: function propagateSelect(form,count,offset) {
13046: if (count > 0) {
1.1065 raeburn 13047: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13048: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13049: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13050: if (parents[count].length > 0) {
13051: for (var j=0; j<parents[count].length; j++) {
13052: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13053: }
13054: }
13055: }
13056: }
13057: }
1.1056 raeburn 13058:
13059: function containerSelect(form,count,offset,picked) {
13060: if (count > 0) {
1.1065 raeburn 13061: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13062: if (form.elements[item].type == 'radio') {
13063: if (form.elements[item].value == 'dependency') {
13064: if (form.elements[item+1].type == 'select-one') {
13065: for (var i=0; i<form.elements[item+1].options.length; i++) {
13066: if (form.elements[item+1].options[i].value == picked) {
13067: form.elements[item+1].selectedIndex = i;
13068: break;
13069: }
13070: }
13071: }
13072: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13073: if (parents[count].length > 0) {
13074: for (var j=0; j<parents[count].length; j++) {
13075: containerSelect(form,parents[count][j],offset,picked);
13076: }
13077: }
13078: }
13079: }
13080: }
13081: }
13082: }
13083:
1.1059 raeburn 13084: function titleCheck(form,count,offset) {
13085: if (count > 0) {
13086: var chosen = (offset+$startcount)+7*(count-1);
13087: var depitem = $startcount + ((count-1) * 7) + 2;
13088: var currtype = form.elements[depitem].type;
13089: if (form.elements[chosen].value == 'display') {
13090: document.getElementById('arc_title_'+count).style.display='block';
13091: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13092: document.getElementById('archive_title_'+count).value=maintitle;
13093: }
13094: } else {
13095: document.getElementById('arc_title_'+count).style.display='none';
13096: if (currtype == 'text') {
13097: document.getElementById('archive_title_'+count).value='';
13098: }
13099: }
13100: }
13101: return;
13102: }
13103:
1.1055 raeburn 13104: // ]]>
13105: </script>
13106: END
13107: return $scripttag;
13108: }
13109:
13110: sub process_extracted_files {
1.1067 raeburn 13111: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13112: my $numitems = $env{'form.archive_count'};
13113: return unless ($numitems);
13114: my @ids=&Apache::lonnet::current_machine_ids();
13115: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13116: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13117: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13118: if (grep(/^\Q$docuhome\E$/,@ids)) {
13119: $prefix = &LONCAPA::propath($docudom,$docuname);
13120: $pathtocheck = "$dir_root/$destination";
13121: $dir = $dir_root;
13122: $ishome = 1;
13123: } else {
13124: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13125: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
13126: $dir = "$dir_root/$docudom/$docuname";
13127: }
13128: my $currdir = "$dir_root/$destination";
13129: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13130: if ($env{'form.folderpath'}) {
13131: my @items = split('&',$env{'form.folderpath'});
13132: $folders{'0'} = $items[-2];
1.1099 raeburn 13133: if ($env{'form.folderpath'} =~ /\:1$/) {
13134: $containers{'0'}='page';
13135: } else {
13136: $containers{'0'}='sequence';
13137: }
1.1055 raeburn 13138: }
13139: my @archdirs = &get_env_multiple('form.archive_directory');
13140: if ($numitems) {
13141: for (my $i=1; $i<=$numitems; $i++) {
13142: my $path = $env{'form.archive_content_'.$i};
13143: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13144: my $item = $1;
13145: $toplevelitems{$item} = $i;
13146: if (grep(/^\Q$i\E$/,@archdirs)) {
13147: $is_dir{$item} = 1;
13148: }
13149: }
13150: }
13151: }
1.1067 raeburn 13152: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13153: if (keys(%toplevelitems) > 0) {
13154: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13155: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13156: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13157: }
1.1066 raeburn 13158: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13159: if ($numitems) {
13160: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13161: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13162: my $path = $env{'form.archive_content_'.$i};
13163: if ($path =~ /^\Q$pathtocheck\E/) {
13164: if ($env{'form.archive_'.$i} eq 'discard') {
13165: if ($prefix ne '' && $path ne '') {
13166: if (-e $prefix.$path) {
1.1066 raeburn 13167: if ((@archdirs > 0) &&
13168: (grep(/^\Q$i\E$/,@archdirs))) {
13169: $todeletedir{$prefix.$path} = 1;
13170: } else {
13171: $todelete{$prefix.$path} = 1;
13172: }
1.1055 raeburn 13173: }
13174: }
13175: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13176: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13177: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13178: $docstitle = $env{'form.archive_title_'.$i};
13179: if ($docstitle eq '') {
13180: $docstitle = $title;
13181: }
1.1055 raeburn 13182: $outer = 0;
1.1056 raeburn 13183: if (ref($dirorder{$i}) eq 'ARRAY') {
13184: if (@{$dirorder{$i}} > 0) {
13185: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13186: if ($env{'form.archive_'.$item} eq 'display') {
13187: $outer = $item;
13188: last;
13189: }
13190: }
13191: }
13192: }
13193: my ($errtext,$fatal) =
13194: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13195: '/'.$folders{$outer}.'.'.
13196: $containers{$outer});
13197: next if ($fatal);
13198: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13199: if ($context eq 'coursedocs') {
1.1056 raeburn 13200: $mapinner{$i} = time;
1.1055 raeburn 13201: $folders{$i} = 'default_'.$mapinner{$i};
13202: $containers{$i} = 'sequence';
13203: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13204: $folders{$i}.'.'.$containers{$i};
13205: my $newidx = &LONCAPA::map::getresidx();
13206: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13207: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13208: push(@LONCAPA::map::order,$newidx);
13209: my ($outtext,$errtext) =
13210: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13211: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13212: '.'.$containers{$outer},1,1);
1.1056 raeburn 13213: $newseqid{$i} = $newidx;
1.1067 raeburn 13214: unless ($errtext) {
13215: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
13216: }
1.1055 raeburn 13217: }
13218: } else {
13219: if ($context eq 'coursedocs') {
13220: my $newidx=&LONCAPA::map::getresidx();
13221: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13222: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13223: $title;
13224: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13225: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13226: }
13227: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13228: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13229: }
13230: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13231: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 13232: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 13233: unless ($ishome) {
13234: my $fetch = "$newdest{$i}/$title";
13235: $fetch =~ s/^\Q$prefix$dir\E//;
13236: $prompttofetch{$fetch} = 1;
13237: }
1.1055 raeburn 13238: }
13239: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13240: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13241: push(@LONCAPA::map::order, $newidx);
13242: my ($outtext,$errtext)=
13243: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13244: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13245: '.'.$containers{$outer},1,1);
1.1067 raeburn 13246: unless ($errtext) {
13247: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13248: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
13249: }
13250: }
1.1055 raeburn 13251: }
13252: }
1.1086 raeburn 13253: }
13254: } else {
13255: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
13256: }
13257: }
13258: for (my $i=1; $i<=$numitems; $i++) {
13259: next unless ($env{'form.archive_'.$i} eq 'dependency');
13260: my $path = $env{'form.archive_content_'.$i};
13261: if ($path =~ /^\Q$pathtocheck\E/) {
13262: my ($title) = ($path =~ m{/([^/]+)$});
13263: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13264: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13265: if (ref($dirorder{$i}) eq 'ARRAY') {
13266: my ($itemidx,$fullpath,$relpath);
13267: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13268: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13269: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13270: if ($dirorder{$i}->[$j] eq $container) {
13271: $itemidx = $j;
1.1056 raeburn 13272: }
13273: }
1.1086 raeburn 13274: }
13275: if ($itemidx eq '') {
13276: $itemidx = 0;
13277: }
13278: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13279: if ($mapinner{$referrer{$i}}) {
13280: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13281: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13282: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13283: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13284: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13285: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13286: if (!-e $fullpath) {
13287: mkdir($fullpath,0755);
1.1056 raeburn 13288: }
13289: }
1.1086 raeburn 13290: } else {
13291: last;
1.1056 raeburn 13292: }
1.1086 raeburn 13293: }
13294: }
13295: } elsif ($newdest{$referrer{$i}}) {
13296: $fullpath = $newdest{$referrer{$i}};
13297: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13298: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13299: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13300: last;
13301: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13302: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13303: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13304: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13305: if (!-e $fullpath) {
13306: mkdir($fullpath,0755);
1.1056 raeburn 13307: }
13308: }
1.1086 raeburn 13309: } else {
13310: last;
1.1056 raeburn 13311: }
1.1055 raeburn 13312: }
13313: }
1.1086 raeburn 13314: if ($fullpath ne '') {
13315: if (-e "$prefix$path") {
13316: system("mv $prefix$path $fullpath/$title");
13317: }
13318: if (-e "$fullpath/$title") {
13319: my $showpath;
13320: if ($relpath ne '') {
13321: $showpath = "$relpath/$title";
13322: } else {
13323: $showpath = "/$title";
13324: }
13325: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
13326: }
13327: unless ($ishome) {
13328: my $fetch = "$fullpath/$title";
13329: $fetch =~ s/^\Q$prefix$dir\E//;
13330: $prompttofetch{$fetch} = 1;
13331: }
13332: }
1.1055 raeburn 13333: }
1.1086 raeburn 13334: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13335: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
13336: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 13337: }
13338: } else {
13339: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
13340: }
13341: }
13342: if (keys(%todelete)) {
13343: foreach my $key (keys(%todelete)) {
13344: unlink($key);
1.1066 raeburn 13345: }
13346: }
13347: if (keys(%todeletedir)) {
13348: foreach my $key (keys(%todeletedir)) {
13349: rmdir($key);
13350: }
13351: }
13352: foreach my $dir (sort(keys(%is_dir))) {
13353: if (($pathtocheck ne '') && ($dir ne '')) {
13354: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13355: }
13356: }
1.1067 raeburn 13357: if ($result ne '') {
13358: $output .= '<ul>'."\n".
13359: $result."\n".
13360: '</ul>';
13361: }
13362: unless ($ishome) {
13363: my $replicationfail;
13364: foreach my $item (keys(%prompttofetch)) {
13365: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13366: unless ($fetchresult eq 'ok') {
13367: $replicationfail .= '<li>'.$item.'</li>'."\n";
13368: }
13369: }
13370: if ($replicationfail) {
13371: $output .= '<p class="LC_error">'.
13372: &mt('Course home server failed to retrieve:').'<ul>'.
13373: $replicationfail.
13374: '</ul></p>';
13375: }
13376: }
1.1055 raeburn 13377: } else {
13378: $warning = &mt('No items found in archive.');
13379: }
13380: if ($error) {
13381: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13382: $error.'</p>'."\n";
13383: }
13384: if ($warning) {
13385: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13386: }
13387: return $output;
13388: }
13389:
1.1066 raeburn 13390: sub cleanup_empty_dirs {
13391: my ($path) = @_;
13392: if (($path ne '') && (-d $path)) {
13393: if (opendir(my $dirh,$path)) {
13394: my @dircontents = grep(!/^\./,readdir($dirh));
13395: my $numitems = 0;
13396: foreach my $item (@dircontents) {
13397: if (-d "$path/$item") {
1.1111 raeburn 13398: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13399: if (-e "$path/$item") {
13400: $numitems ++;
13401: }
13402: } else {
13403: $numitems ++;
13404: }
13405: }
13406: if ($numitems == 0) {
13407: rmdir($path);
13408: }
13409: closedir($dirh);
13410: }
13411: }
13412: return;
13413: }
13414:
1.41 ng 13415: =pod
1.45 matthew 13416:
1.1162 raeburn 13417: =item * &get_folder_hierarchy()
1.1068 raeburn 13418:
13419: Provides hierarchy of names of folders/sub-folders containing the current
13420: item,
13421:
13422: Inputs: 3
13423: - $navmap - navmaps object
13424:
13425: - $map - url for map (either the trigger itself, or map containing
13426: the resource, which is the trigger).
13427:
13428: - $showitem - 1 => show title for map itself; 0 => do not show.
13429:
13430: Outputs: 1 @pathitems - array of folder/subfolder names.
13431:
13432: =cut
13433:
13434: sub get_folder_hierarchy {
13435: my ($navmap,$map,$showitem) = @_;
13436: my @pathitems;
13437: if (ref($navmap)) {
13438: my $mapres = $navmap->getResourceByUrl($map);
13439: if (ref($mapres)) {
13440: my $pcslist = $mapres->map_hierarchy();
13441: if ($pcslist ne '') {
13442: my @pcs = split(/,/,$pcslist);
13443: foreach my $pc (@pcs) {
13444: if ($pc == 1) {
1.1129 raeburn 13445: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13446: } else {
13447: my $res = $navmap->getByMapPc($pc);
13448: if (ref($res)) {
13449: my $title = $res->compTitle();
13450: $title =~ s/\W+/_/g;
13451: if ($title ne '') {
13452: push(@pathitems,$title);
13453: }
13454: }
13455: }
13456: }
13457: }
1.1071 raeburn 13458: if ($showitem) {
13459: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13460: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13461: } else {
13462: my $maptitle = $mapres->compTitle();
13463: $maptitle =~ s/\W+/_/g;
13464: if ($maptitle ne '') {
13465: push(@pathitems,$maptitle);
13466: }
1.1068 raeburn 13467: }
13468: }
13469: }
13470: }
13471: return @pathitems;
13472: }
13473:
13474: =pod
13475:
1.1015 raeburn 13476: =item * &get_turnedin_filepath()
13477:
13478: Determines path in a user's portfolio file for storage of files uploaded
13479: to a specific essayresponse or dropbox item.
13480:
13481: Inputs: 3 required + 1 optional.
13482: $symb is symb for resource, $uname and $udom are for current user (required).
13483: $caller is optional (can be "submission", if routine is called when storing
13484: an upoaded file when "Submit Answer" button was pressed).
13485:
13486: Returns array containing $path and $multiresp.
13487: $path is path in portfolio. $multiresp is 1 if this resource contains more
13488: than one file upload item. Callers of routine should append partid as a
13489: subdirectory to $path in cases where $multiresp is 1.
13490:
13491: Called by: homework/essayresponse.pm and homework/structuretags.pm
13492:
13493: =cut
13494:
13495: sub get_turnedin_filepath {
13496: my ($symb,$uname,$udom,$caller) = @_;
13497: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13498: my $turnindir;
13499: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13500: $turnindir = $userhash{'turnindir'};
13501: my ($path,$multiresp);
13502: if ($turnindir eq '') {
13503: if ($caller eq 'submission') {
13504: $turnindir = &mt('turned in');
13505: $turnindir =~ s/\W+/_/g;
13506: my %newhash = (
13507: 'turnindir' => $turnindir,
13508: );
13509: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13510: }
13511: }
13512: if ($turnindir ne '') {
13513: $path = '/'.$turnindir.'/';
13514: my ($multipart,$turnin,@pathitems);
13515: my $navmap = Apache::lonnavmaps::navmap->new();
13516: if (defined($navmap)) {
13517: my $mapres = $navmap->getResourceByUrl($map);
13518: if (ref($mapres)) {
13519: my $pcslist = $mapres->map_hierarchy();
13520: if ($pcslist ne '') {
13521: foreach my $pc (split(/,/,$pcslist)) {
13522: my $res = $navmap->getByMapPc($pc);
13523: if (ref($res)) {
13524: my $title = $res->compTitle();
13525: $title =~ s/\W+/_/g;
13526: if ($title ne '') {
1.1149 raeburn 13527: if (($pc > 1) && (length($title) > 12)) {
13528: $title = substr($title,0,12);
13529: }
1.1015 raeburn 13530: push(@pathitems,$title);
13531: }
13532: }
13533: }
13534: }
13535: my $maptitle = $mapres->compTitle();
13536: $maptitle =~ s/\W+/_/g;
13537: if ($maptitle ne '') {
1.1149 raeburn 13538: if (length($maptitle) > 12) {
13539: $maptitle = substr($maptitle,0,12);
13540: }
1.1015 raeburn 13541: push(@pathitems,$maptitle);
13542: }
13543: unless ($env{'request.state'} eq 'construct') {
13544: my $res = $navmap->getBySymb($symb);
13545: if (ref($res)) {
13546: my $partlist = $res->parts();
13547: my $totaluploads = 0;
13548: if (ref($partlist) eq 'ARRAY') {
13549: foreach my $part (@{$partlist}) {
13550: my @types = $res->responseType($part);
13551: my @ids = $res->responseIds($part);
13552: for (my $i=0; $i < scalar(@ids); $i++) {
13553: if ($types[$i] eq 'essay') {
13554: my $partid = $part.'_'.$ids[$i];
13555: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13556: $totaluploads ++;
13557: }
13558: }
13559: }
13560: }
13561: if ($totaluploads > 1) {
13562: $multiresp = 1;
13563: }
13564: }
13565: }
13566: }
13567: } else {
13568: return;
13569: }
13570: } else {
13571: return;
13572: }
13573: my $restitle=&Apache::lonnet::gettitle($symb);
13574: $restitle =~ s/\W+/_/g;
13575: if ($restitle eq '') {
13576: $restitle = ($resurl =~ m{/[^/]+$});
13577: if ($restitle eq '') {
13578: $restitle = time;
13579: }
13580: }
1.1149 raeburn 13581: if (length($restitle) > 12) {
13582: $restitle = substr($restitle,0,12);
13583: }
1.1015 raeburn 13584: push(@pathitems,$restitle);
13585: $path .= join('/',@pathitems);
13586: }
13587: return ($path,$multiresp);
13588: }
13589:
13590: =pod
13591:
1.464 albertel 13592: =back
1.41 ng 13593:
1.112 bowersj2 13594: =head1 CSV Upload/Handling functions
1.38 albertel 13595:
1.41 ng 13596: =over 4
13597:
1.648 raeburn 13598: =item * &upfile_store($r)
1.41 ng 13599:
13600: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13601: needs $env{'form.upfile'}
1.41 ng 13602: returns $datatoken to be put into hidden field
13603:
13604: =cut
1.31 albertel 13605:
13606: sub upfile_store {
13607: my $r=shift;
1.258 albertel 13608: $env{'form.upfile'}=~s/\r/\n/gs;
13609: $env{'form.upfile'}=~s/\f/\n/gs;
13610: $env{'form.upfile'}=~s/\n+/\n/gs;
13611: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13612:
1.258 albertel 13613: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
13614: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 13615: {
1.158 raeburn 13616: my $datafile = $r->dir_config('lonDaemons').
13617: '/tmp/'.$datatoken.'.tmp';
13618: if ( open(my $fh,">$datafile") ) {
1.258 albertel 13619: print $fh $env{'form.upfile'};
1.158 raeburn 13620: close($fh);
13621: }
1.31 albertel 13622: }
13623: return $datatoken;
13624: }
13625:
1.56 matthew 13626: =pod
13627:
1.648 raeburn 13628: =item * &load_tmp_file($r)
1.41 ng 13629:
13630: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 13631: needs $env{'form.datatoken'},
13632: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13633:
13634: =cut
1.31 albertel 13635:
13636: sub load_tmp_file {
13637: my $r=shift;
13638: my @studentdata=();
13639: {
1.158 raeburn 13640: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 13641: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 13642: if ( open(my $fh,"<$studentfile") ) {
13643: @studentdata=<$fh>;
13644: close($fh);
13645: }
1.31 albertel 13646: }
1.258 albertel 13647: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13648: }
13649:
1.56 matthew 13650: =pod
13651:
1.648 raeburn 13652: =item * &upfile_record_sep()
1.41 ng 13653:
13654: Separate uploaded file into records
13655: returns array of records,
1.258 albertel 13656: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13657:
13658: =cut
1.31 albertel 13659:
13660: sub upfile_record_sep {
1.258 albertel 13661: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13662: } else {
1.248 albertel 13663: my @records;
1.258 albertel 13664: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13665: if ($line=~/^\s*$/) { next; }
13666: push(@records,$line);
13667: }
13668: return @records;
1.31 albertel 13669: }
13670: }
13671:
1.56 matthew 13672: =pod
13673:
1.648 raeburn 13674: =item * &record_sep($record)
1.41 ng 13675:
1.258 albertel 13676: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13677:
13678: =cut
13679:
1.263 www 13680: sub takeleft {
13681: my $index=shift;
13682: return substr('0000'.$index,-4,4);
13683: }
13684:
1.31 albertel 13685: sub record_sep {
13686: my $record=shift;
13687: my %components=();
1.258 albertel 13688: if ($env{'form.upfiletype'} eq 'xml') {
13689: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13690: my $i=0;
1.356 albertel 13691: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13692: $field=~s/^(\"|\')//;
13693: $field=~s/(\"|\')$//;
1.263 www 13694: $components{&takeleft($i)}=$field;
1.31 albertel 13695: $i++;
13696: }
1.258 albertel 13697: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13698: my $i=0;
1.356 albertel 13699: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13700: $field=~s/^(\"|\')//;
13701: $field=~s/(\"|\')$//;
1.263 www 13702: $components{&takeleft($i)}=$field;
1.31 albertel 13703: $i++;
13704: }
13705: } else {
1.561 www 13706: my $separator=',';
1.480 banghart 13707: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13708: $separator=';';
1.480 banghart 13709: }
1.31 albertel 13710: my $i=0;
1.561 www 13711: # the character we are looking for to indicate the end of a quote or a record
13712: my $looking_for=$separator;
13713: # do not add the characters to the fields
13714: my $ignore=0;
13715: # we just encountered a separator (or the beginning of the record)
13716: my $just_found_separator=1;
13717: # store the field we are working on here
13718: my $field='';
13719: # work our way through all characters in record
13720: foreach my $character ($record=~/(.)/g) {
13721: if ($character eq $looking_for) {
13722: if ($character ne $separator) {
13723: # Found the end of a quote, again looking for separator
13724: $looking_for=$separator;
13725: $ignore=1;
13726: } else {
13727: # Found a separator, store away what we got
13728: $components{&takeleft($i)}=$field;
13729: $i++;
13730: $just_found_separator=1;
13731: $ignore=0;
13732: $field='';
13733: }
13734: next;
13735: }
13736: # single or double quotation marks after a separator indicate beginning of a quote
13737: # we are now looking for the end of the quote and need to ignore separators
13738: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13739: $looking_for=$character;
13740: next;
13741: }
13742: # ignore would be true after we reached the end of a quote
13743: if ($ignore) { next; }
13744: if (($just_found_separator) && ($character=~/\s/)) { next; }
13745: $field.=$character;
13746: $just_found_separator=0;
1.31 albertel 13747: }
1.561 www 13748: # catch the very last entry, since we never encountered the separator
13749: $components{&takeleft($i)}=$field;
1.31 albertel 13750: }
13751: return %components;
13752: }
13753:
1.144 matthew 13754: ######################################################
13755: ######################################################
13756:
1.56 matthew 13757: =pod
13758:
1.648 raeburn 13759: =item * &upfile_select_html()
1.41 ng 13760:
1.144 matthew 13761: Return HTML code to select a file from the users machine and specify
13762: the file type.
1.41 ng 13763:
13764: =cut
13765:
1.144 matthew 13766: ######################################################
13767: ######################################################
1.31 albertel 13768: sub upfile_select_html {
1.144 matthew 13769: my %Types = (
13770: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13771: semisv => &mt('Semicolon separated values'),
1.144 matthew 13772: space => &mt('Space separated'),
13773: tab => &mt('Tabulator separated'),
13774: # xml => &mt('HTML/XML'),
13775: );
13776: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13777: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13778: foreach my $type (sort(keys(%Types))) {
13779: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13780: }
13781: $Str .= "</select>\n";
13782: return $Str;
1.31 albertel 13783: }
13784:
1.301 albertel 13785: sub get_samples {
13786: my ($records,$toget) = @_;
13787: my @samples=({});
13788: my $got=0;
13789: foreach my $rec (@$records) {
13790: my %temp = &record_sep($rec);
13791: if (! grep(/\S/, values(%temp))) { next; }
13792: if (%temp) {
13793: $samples[$got]=\%temp;
13794: $got++;
13795: if ($got == $toget) { last; }
13796: }
13797: }
13798: return \@samples;
13799: }
13800:
1.144 matthew 13801: ######################################################
13802: ######################################################
13803:
1.56 matthew 13804: =pod
13805:
1.648 raeburn 13806: =item * &csv_print_samples($r,$records)
1.41 ng 13807:
13808: Prints a table of sample values from each column uploaded $r is an
13809: Apache Request ref, $records is an arrayref from
13810: &Apache::loncommon::upfile_record_sep
13811:
13812: =cut
13813:
1.144 matthew 13814: ######################################################
13815: ######################################################
1.31 albertel 13816: sub csv_print_samples {
13817: my ($r,$records) = @_;
1.662 bisitz 13818: my $samples = &get_samples($records,5);
1.301 albertel 13819:
1.594 raeburn 13820: $r->print(&mt('Samples').'<br />'.&start_data_table().
13821: &start_data_table_header_row());
1.356 albertel 13822: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13823: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13824: $r->print(&end_data_table_header_row());
1.301 albertel 13825: foreach my $hash (@$samples) {
1.594 raeburn 13826: $r->print(&start_data_table_row());
1.356 albertel 13827: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13828: $r->print('<td>');
1.356 albertel 13829: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13830: $r->print('</td>');
13831: }
1.594 raeburn 13832: $r->print(&end_data_table_row());
1.31 albertel 13833: }
1.594 raeburn 13834: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13835: }
13836:
1.144 matthew 13837: ######################################################
13838: ######################################################
13839:
1.56 matthew 13840: =pod
13841:
1.648 raeburn 13842: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13843:
13844: Prints a table to create associations between values and table columns.
1.144 matthew 13845:
1.41 ng 13846: $r is an Apache Request ref,
13847: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13848: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13849:
13850: =cut
13851:
1.144 matthew 13852: ######################################################
13853: ######################################################
1.31 albertel 13854: sub csv_print_select_table {
13855: my ($r,$records,$d) = @_;
1.301 albertel 13856: my $i=0;
13857: my $samples = &get_samples($records,1);
1.144 matthew 13858: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13859: &start_data_table().&start_data_table_header_row().
1.144 matthew 13860: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13861: '<th>'.&mt('Column').'</th>'.
13862: &end_data_table_header_row()."\n");
1.356 albertel 13863: foreach my $array_ref (@$d) {
13864: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13865: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13866:
1.875 bisitz 13867: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13868: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13869: $r->print('<option value="none"></option>');
1.356 albertel 13870: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13871: $r->print('<option value="'.$sample.'"'.
13872: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13873: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13874: }
1.594 raeburn 13875: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13876: $i++;
13877: }
1.594 raeburn 13878: $r->print(&end_data_table());
1.31 albertel 13879: $i--;
13880: return $i;
13881: }
1.56 matthew 13882:
1.144 matthew 13883: ######################################################
13884: ######################################################
13885:
1.56 matthew 13886: =pod
1.31 albertel 13887:
1.648 raeburn 13888: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13889:
13890: Prints a table of sample values from the upload and can make associate samples to internal names.
13891:
13892: $r is an Apache Request ref,
13893: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13894: $d is an array of 2 element arrays (internal name, displayed name)
13895:
13896: =cut
13897:
1.144 matthew 13898: ######################################################
13899: ######################################################
1.31 albertel 13900: sub csv_samples_select_table {
13901: my ($r,$records,$d) = @_;
13902: my $i=0;
1.144 matthew 13903: #
1.662 bisitz 13904: my $max_samples = 5;
13905: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13906: $r->print(&start_data_table().
13907: &start_data_table_header_row().'<th>'.
13908: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13909: &end_data_table_header_row());
1.301 albertel 13910:
13911: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13912: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13913: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13914: foreach my $option (@$d) {
13915: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13916: $r->print('<option value="'.$value.'"'.
1.253 albertel 13917: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13918: $display.'</option>');
1.31 albertel 13919: }
13920: $r->print('</select></td><td>');
1.662 bisitz 13921: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13922: if (defined($samples->[$line]{$key})) {
13923: $r->print($samples->[$line]{$key}."<br />\n");
13924: }
13925: }
1.594 raeburn 13926: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13927: $i++;
13928: }
1.594 raeburn 13929: $r->print(&end_data_table());
1.31 albertel 13930: $i--;
13931: return($i);
1.115 matthew 13932: }
13933:
1.144 matthew 13934: ######################################################
13935: ######################################################
13936:
1.115 matthew 13937: =pod
13938:
1.648 raeburn 13939: =item * &clean_excel_name($name)
1.115 matthew 13940:
13941: Returns a replacement for $name which does not contain any illegal characters.
13942:
13943: =cut
13944:
1.144 matthew 13945: ######################################################
13946: ######################################################
1.115 matthew 13947: sub clean_excel_name {
13948: my ($name) = @_;
13949: $name =~ s/[:\*\?\/\\]//g;
13950: if (length($name) > 31) {
13951: $name = substr($name,0,31);
13952: }
13953: return $name;
1.25 albertel 13954: }
1.84 albertel 13955:
1.85 albertel 13956: =pod
13957:
1.648 raeburn 13958: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13959:
13960: Returns either 1 or undef
13961:
13962: 1 if the part is to be hidden, undef if it is to be shown
13963:
13964: Arguments are:
13965:
13966: $id the id of the part to be checked
13967: $symb, optional the symb of the resource to check
13968: $udom, optional the domain of the user to check for
13969: $uname, optional the username of the user to check for
13970:
13971: =cut
1.84 albertel 13972:
13973: sub check_if_partid_hidden {
13974: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13975: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13976: $symb,$udom,$uname);
1.141 albertel 13977: my $truth=1;
13978: #if the string starts with !, then the list is the list to show not hide
13979: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13980: my @hiddenlist=split(/,/,$hiddenparts);
13981: foreach my $checkid (@hiddenlist) {
1.141 albertel 13982: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13983: }
1.141 albertel 13984: return !$truth;
1.84 albertel 13985: }
1.127 matthew 13986:
1.138 matthew 13987:
13988: ############################################################
13989: ############################################################
13990:
13991: =pod
13992:
1.157 matthew 13993: =back
13994:
1.138 matthew 13995: =head1 cgi-bin script and graphing routines
13996:
1.157 matthew 13997: =over 4
13998:
1.648 raeburn 13999: =item * &get_cgi_id()
1.138 matthew 14000:
14001: Inputs: none
14002:
14003: Returns an id which can be used to pass environment variables
14004: to various cgi-bin scripts. These environment variables will
14005: be removed from the users environment after a given time by
14006: the routine &Apache::lonnet::transfer_profile_to_env.
14007:
14008: =cut
14009:
14010: ############################################################
14011: ############################################################
1.152 albertel 14012: my $uniq=0;
1.136 matthew 14013: sub get_cgi_id {
1.154 albertel 14014: $uniq=($uniq+1)%100000;
1.280 albertel 14015: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14016: }
14017:
1.127 matthew 14018: ############################################################
14019: ############################################################
14020:
14021: =pod
14022:
1.648 raeburn 14023: =item * &DrawBarGraph()
1.127 matthew 14024:
1.138 matthew 14025: Facilitates the plotting of data in a (stacked) bar graph.
14026: Puts plot definition data into the users environment in order for
14027: graph.png to plot it. Returns an <img> tag for the plot.
14028: The bars on the plot are labeled '1','2',...,'n'.
14029:
14030: Inputs:
14031:
14032: =over 4
14033:
14034: =item $Title: string, the title of the plot
14035:
14036: =item $xlabel: string, text describing the X-axis of the plot
14037:
14038: =item $ylabel: string, text describing the Y-axis of the plot
14039:
14040: =item $Max: scalar, the maximum Y value to use in the plot
14041: If $Max is < any data point, the graph will not be rendered.
14042:
1.140 matthew 14043: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14044: they are plotted. If undefined, default values will be used.
14045:
1.178 matthew 14046: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14047:
1.138 matthew 14048: =item @Values: An array of array references. Each array reference holds data
14049: to be plotted in a stacked bar chart.
14050:
1.239 matthew 14051: =item If the final element of @Values is a hash reference the key/value
14052: pairs will be added to the graph definition.
14053:
1.138 matthew 14054: =back
14055:
14056: Returns:
14057:
14058: An <img> tag which references graph.png and the appropriate identifying
14059: information for the plot.
14060:
1.127 matthew 14061: =cut
14062:
14063: ############################################################
14064: ############################################################
1.134 matthew 14065: sub DrawBarGraph {
1.178 matthew 14066: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14067: #
14068: if (! defined($colors)) {
14069: $colors = ['#33ff00',
14070: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14071: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14072: ];
14073: }
1.228 matthew 14074: my $extra_settings = {};
14075: if (ref($Values[-1]) eq 'HASH') {
14076: $extra_settings = pop(@Values);
14077: }
1.127 matthew 14078: #
1.136 matthew 14079: my $identifier = &get_cgi_id();
14080: my $id = 'cgi.'.$identifier;
1.129 matthew 14081: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14082: return '';
14083: }
1.225 matthew 14084: #
14085: my @Labels;
14086: if (defined($labels)) {
14087: @Labels = @$labels;
14088: } else {
14089: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14090: push(@Labels,$i+1);
1.225 matthew 14091: }
14092: }
14093: #
1.129 matthew 14094: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14095: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14096: my %ValuesHash;
14097: my $NumSets=1;
14098: foreach my $array (@Values) {
14099: next if (! ref($array));
1.136 matthew 14100: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14101: join(',',@$array);
1.129 matthew 14102: }
1.127 matthew 14103: #
1.136 matthew 14104: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14105: if ($NumBars < 3) {
14106: $width = 120+$NumBars*32;
1.220 matthew 14107: $xskip = 1;
1.225 matthew 14108: $bar_width = 30;
14109: } elsif ($NumBars < 5) {
14110: $width = 120+$NumBars*20;
14111: $xskip = 1;
14112: $bar_width = 20;
1.220 matthew 14113: } elsif ($NumBars < 10) {
1.136 matthew 14114: $width = 120+$NumBars*15;
14115: $xskip = 1;
14116: $bar_width = 15;
14117: } elsif ($NumBars <= 25) {
14118: $width = 120+$NumBars*11;
14119: $xskip = 5;
14120: $bar_width = 8;
14121: } elsif ($NumBars <= 50) {
14122: $width = 120+$NumBars*8;
14123: $xskip = 5;
14124: $bar_width = 4;
14125: } else {
14126: $width = 120+$NumBars*8;
14127: $xskip = 5;
14128: $bar_width = 4;
14129: }
14130: #
1.137 matthew 14131: $Max = 1 if ($Max < 1);
14132: if ( int($Max) < $Max ) {
14133: $Max++;
14134: $Max = int($Max);
14135: }
1.127 matthew 14136: $Title = '' if (! defined($Title));
14137: $xlabel = '' if (! defined($xlabel));
14138: $ylabel = '' if (! defined($ylabel));
1.369 www 14139: $ValuesHash{$id.'.title'} = &escape($Title);
14140: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14141: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14142: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14143: $ValuesHash{$id.'.NumBars'} = $NumBars;
14144: $ValuesHash{$id.'.NumSets'} = $NumSets;
14145: $ValuesHash{$id.'.PlotType'} = 'bar';
14146: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14147: $ValuesHash{$id.'.height'} = $height;
14148: $ValuesHash{$id.'.width'} = $width;
14149: $ValuesHash{$id.'.xskip'} = $xskip;
14150: $ValuesHash{$id.'.bar_width'} = $bar_width;
14151: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14152: #
1.228 matthew 14153: # Deal with other parameters
14154: while (my ($key,$value) = each(%$extra_settings)) {
14155: $ValuesHash{$id.'.'.$key} = $value;
14156: }
14157: #
1.646 raeburn 14158: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14159: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14160: }
14161:
14162: ############################################################
14163: ############################################################
14164:
14165: =pod
14166:
1.648 raeburn 14167: =item * &DrawXYGraph()
1.137 matthew 14168:
1.138 matthew 14169: Facilitates the plotting of data in an XY graph.
14170: Puts plot definition data into the users environment in order for
14171: graph.png to plot it. Returns an <img> tag for the plot.
14172:
14173: Inputs:
14174:
14175: =over 4
14176:
14177: =item $Title: string, the title of the plot
14178:
14179: =item $xlabel: string, text describing the X-axis of the plot
14180:
14181: =item $ylabel: string, text describing the Y-axis of the plot
14182:
14183: =item $Max: scalar, the maximum Y value to use in the plot
14184: If $Max is < any data point, the graph will not be rendered.
14185:
14186: =item $colors: Array ref containing the hex color codes for the data to be
14187: plotted in. If undefined, default values will be used.
14188:
14189: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14190:
14191: =item $Ydata: Array ref containing Array refs.
1.185 www 14192: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14193:
14194: =item %Values: hash indicating or overriding any default values which are
14195: passed to graph.png.
14196: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14197:
14198: =back
14199:
14200: Returns:
14201:
14202: An <img> tag which references graph.png and the appropriate identifying
14203: information for the plot.
14204:
1.137 matthew 14205: =cut
14206:
14207: ############################################################
14208: ############################################################
14209: sub DrawXYGraph {
14210: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14211: #
14212: # Create the identifier for the graph
14213: my $identifier = &get_cgi_id();
14214: my $id = 'cgi.'.$identifier;
14215: #
14216: $Title = '' if (! defined($Title));
14217: $xlabel = '' if (! defined($xlabel));
14218: $ylabel = '' if (! defined($ylabel));
14219: my %ValuesHash =
14220: (
1.369 www 14221: $id.'.title' => &escape($Title),
14222: $id.'.xlabel' => &escape($xlabel),
14223: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14224: $id.'.y_max_value'=> $Max,
14225: $id.'.labels' => join(',',@$Xlabels),
14226: $id.'.PlotType' => 'XY',
14227: );
14228: #
14229: if (defined($colors) && ref($colors) eq 'ARRAY') {
14230: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14231: }
14232: #
14233: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14234: return '';
14235: }
14236: my $NumSets=1;
1.138 matthew 14237: foreach my $array (@{$Ydata}){
1.137 matthew 14238: next if (! ref($array));
14239: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14240: }
1.138 matthew 14241: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14242: #
14243: # Deal with other parameters
14244: while (my ($key,$value) = each(%Values)) {
14245: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14246: }
14247: #
1.646 raeburn 14248: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14249: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14250: }
14251:
14252: ############################################################
14253: ############################################################
14254:
14255: =pod
14256:
1.648 raeburn 14257: =item * &DrawXYYGraph()
1.138 matthew 14258:
14259: Facilitates the plotting of data in an XY graph with two Y axes.
14260: Puts plot definition data into the users environment in order for
14261: graph.png to plot it. Returns an <img> tag for the plot.
14262:
14263: Inputs:
14264:
14265: =over 4
14266:
14267: =item $Title: string, the title of the plot
14268:
14269: =item $xlabel: string, text describing the X-axis of the plot
14270:
14271: =item $ylabel: string, text describing the Y-axis of the plot
14272:
14273: =item $colors: Array ref containing the hex color codes for the data to be
14274: plotted in. If undefined, default values will be used.
14275:
14276: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14277:
14278: =item $Ydata1: The first data set
14279:
14280: =item $Min1: The minimum value of the left Y-axis
14281:
14282: =item $Max1: The maximum value of the left Y-axis
14283:
14284: =item $Ydata2: The second data set
14285:
14286: =item $Min2: The minimum value of the right Y-axis
14287:
14288: =item $Max2: The maximum value of the left Y-axis
14289:
14290: =item %Values: hash indicating or overriding any default values which are
14291: passed to graph.png.
14292: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14293:
14294: =back
14295:
14296: Returns:
14297:
14298: An <img> tag which references graph.png and the appropriate identifying
14299: information for the plot.
1.136 matthew 14300:
14301: =cut
14302:
14303: ############################################################
14304: ############################################################
1.137 matthew 14305: sub DrawXYYGraph {
14306: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14307: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14308: #
14309: # Create the identifier for the graph
14310: my $identifier = &get_cgi_id();
14311: my $id = 'cgi.'.$identifier;
14312: #
14313: $Title = '' if (! defined($Title));
14314: $xlabel = '' if (! defined($xlabel));
14315: $ylabel = '' if (! defined($ylabel));
14316: my %ValuesHash =
14317: (
1.369 www 14318: $id.'.title' => &escape($Title),
14319: $id.'.xlabel' => &escape($xlabel),
14320: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14321: $id.'.labels' => join(',',@$Xlabels),
14322: $id.'.PlotType' => 'XY',
14323: $id.'.NumSets' => 2,
1.137 matthew 14324: $id.'.two_axes' => 1,
14325: $id.'.y1_max_value' => $Max1,
14326: $id.'.y1_min_value' => $Min1,
14327: $id.'.y2_max_value' => $Max2,
14328: $id.'.y2_min_value' => $Min2,
1.136 matthew 14329: );
14330: #
1.137 matthew 14331: if (defined($colors) && ref($colors) eq 'ARRAY') {
14332: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14333: }
14334: #
14335: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14336: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14337: return '';
14338: }
14339: my $NumSets=1;
1.137 matthew 14340: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14341: next if (! ref($array));
14342: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14343: }
14344: #
14345: # Deal with other parameters
14346: while (my ($key,$value) = each(%Values)) {
14347: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14348: }
14349: #
1.646 raeburn 14350: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14351: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14352: }
14353:
14354: ############################################################
14355: ############################################################
14356:
14357: =pod
14358:
1.157 matthew 14359: =back
14360:
1.139 matthew 14361: =head1 Statistics helper routines?
14362:
14363: Bad place for them but what the hell.
14364:
1.157 matthew 14365: =over 4
14366:
1.648 raeburn 14367: =item * &chartlink()
1.139 matthew 14368:
14369: Returns a link to the chart for a specific student.
14370:
14371: Inputs:
14372:
14373: =over 4
14374:
14375: =item $linktext: The text of the link
14376:
14377: =item $sname: The students username
14378:
14379: =item $sdomain: The students domain
14380:
14381: =back
14382:
1.157 matthew 14383: =back
14384:
1.139 matthew 14385: =cut
14386:
14387: ############################################################
14388: ############################################################
14389: sub chartlink {
14390: my ($linktext, $sname, $sdomain) = @_;
14391: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14392: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14393: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14394: '">'.$linktext.'</a>';
1.153 matthew 14395: }
14396:
14397: #######################################################
14398: #######################################################
14399:
14400: =pod
14401:
14402: =head1 Course Environment Routines
1.157 matthew 14403:
14404: =over 4
1.153 matthew 14405:
1.648 raeburn 14406: =item * &restore_course_settings()
1.153 matthew 14407:
1.648 raeburn 14408: =item * &store_course_settings()
1.153 matthew 14409:
14410: Restores/Store indicated form parameters from the course environment.
14411: Will not overwrite existing values of the form parameters.
14412:
14413: Inputs:
14414: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14415:
14416: a hash ref describing the data to be stored. For example:
14417:
14418: %Save_Parameters = ('Status' => 'scalar',
14419: 'chartoutputmode' => 'scalar',
14420: 'chartoutputdata' => 'scalar',
14421: 'Section' => 'array',
1.373 raeburn 14422: 'Group' => 'array',
1.153 matthew 14423: 'StudentData' => 'array',
14424: 'Maps' => 'array');
14425:
14426: Returns: both routines return nothing
14427:
1.631 raeburn 14428: =back
14429:
1.153 matthew 14430: =cut
14431:
14432: #######################################################
14433: #######################################################
14434: sub store_course_settings {
1.496 albertel 14435: return &store_settings($env{'request.course.id'},@_);
14436: }
14437:
14438: sub store_settings {
1.153 matthew 14439: # save to the environment
14440: # appenv the same items, just to be safe
1.300 albertel 14441: my $udom = $env{'user.domain'};
14442: my $uname = $env{'user.name'};
1.496 albertel 14443: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14444: my %SaveHash;
14445: my %AppHash;
14446: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14447: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14448: my $envname = 'environment.'.$basename;
1.258 albertel 14449: if (exists($env{'form.'.$setting})) {
1.153 matthew 14450: # Save this value away
14451: if ($type eq 'scalar' &&
1.258 albertel 14452: (! exists($env{$envname}) ||
14453: $env{$envname} ne $env{'form.'.$setting})) {
14454: $SaveHash{$basename} = $env{'form.'.$setting};
14455: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14456: } elsif ($type eq 'array') {
14457: my $stored_form;
1.258 albertel 14458: if (ref($env{'form.'.$setting})) {
1.153 matthew 14459: $stored_form = join(',',
14460: map {
1.369 www 14461: &escape($_);
1.258 albertel 14462: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14463: } else {
14464: $stored_form =
1.369 www 14465: &escape($env{'form.'.$setting});
1.153 matthew 14466: }
14467: # Determine if the array contents are the same.
1.258 albertel 14468: if ($stored_form ne $env{$envname}) {
1.153 matthew 14469: $SaveHash{$basename} = $stored_form;
14470: $AppHash{$envname} = $stored_form;
14471: }
14472: }
14473: }
14474: }
14475: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14476: $udom,$uname);
1.153 matthew 14477: if ($put_result !~ /^(ok|delayed)/) {
14478: &Apache::lonnet::logthis('unable to save form parameters, '.
14479: 'got error:'.$put_result);
14480: }
14481: # Make sure these settings stick around in this session, too
1.646 raeburn 14482: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14483: return;
14484: }
14485:
14486: sub restore_course_settings {
1.499 albertel 14487: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14488: }
14489:
14490: sub restore_settings {
14491: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14492: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14493: next if (exists($env{'form.'.$setting}));
1.496 albertel 14494: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14495: '.'.$setting;
1.258 albertel 14496: if (exists($env{$envname})) {
1.153 matthew 14497: if ($type eq 'scalar') {
1.258 albertel 14498: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14499: } elsif ($type eq 'array') {
1.258 albertel 14500: $env{'form.'.$setting} = [
1.153 matthew 14501: map {
1.369 www 14502: &unescape($_);
1.258 albertel 14503: } split(',',$env{$envname})
1.153 matthew 14504: ];
14505: }
14506: }
14507: }
1.127 matthew 14508: }
14509:
1.618 raeburn 14510: #######################################################
14511: #######################################################
14512:
14513: =pod
14514:
14515: =head1 Domain E-mail Routines
14516:
14517: =over 4
14518:
1.648 raeburn 14519: =item * &build_recipient_list()
1.618 raeburn 14520:
1.1144 raeburn 14521: Build recipient lists for following types of e-mail:
1.766 raeburn 14522: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14523: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14524: module change checking, student/employee ID conflict checks, as
14525: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14526: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14527:
14528: Inputs:
1.619 raeburn 14529: defmail (scalar - email address of default recipient),
1.1144 raeburn 14530: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14531: requestsmail, updatesmail, or idconflictsmail).
14532:
1.619 raeburn 14533: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14534:
1.619 raeburn 14535: origmail (scalar - email address of recipient from loncapa.conf,
14536: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14537:
1.655 raeburn 14538: Returns: comma separated list of addresses to which to send e-mail.
14539:
14540: =back
1.618 raeburn 14541:
14542: =cut
14543:
14544: ############################################################
14545: ############################################################
14546: sub build_recipient_list {
1.619 raeburn 14547: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 14548: my @recipients;
1.1270 raeburn 14549: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14550: my %domconfig =
1.1270 raeburn 14551: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14552: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14553: if (exists($domconfig{'contacts'}{$mailing})) {
14554: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14555: my @contacts = ('adminemail','supportemail');
14556: foreach my $item (@contacts) {
14557: if ($domconfig{'contacts'}{$mailing}{$item}) {
14558: my $addr = $domconfig{'contacts'}{$item};
14559: if (!grep(/^\Q$addr\E$/,@recipients)) {
14560: push(@recipients,$addr);
14561: }
1.619 raeburn 14562: }
1.1270 raeburn 14563: }
14564: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14565: if ($mailing eq 'helpdeskmail') {
14566: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14567: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14568: my @ok_bccs;
14569: foreach my $bcc (@bccs) {
14570: $bcc =~ s/^\s+//g;
14571: $bcc =~ s/\s+$//g;
14572: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14573: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14574: push(@ok_bccs,$bcc);
14575: }
14576: }
14577: }
14578: if (@ok_bccs > 0) {
14579: $allbcc = join(', ',@ok_bccs);
14580: }
14581: }
14582: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14583: }
14584: }
1.766 raeburn 14585: } elsif ($origmail ne '') {
1.1270 raeburn 14586: $lastresort = $origmail;
1.618 raeburn 14587: }
1.619 raeburn 14588: } elsif ($origmail ne '') {
1.1270 raeburn 14589: $lastresort = $origmail;
14590: }
14591:
14592: if (($mailing eq 'helpdesk') && ($lastresort ne '')) {
14593: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14594: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14595: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14596: my %what = (
14597: perlvar => 1,
14598: );
14599: my $primary = &Apache::lonnet::domain($defdom,'primary');
14600: if ($primary) {
14601: my $gotaddr;
14602: my ($result,$returnhash) =
14603: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14604: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14605: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14606: $lastresort = $returnhash->{'lonSupportEMail'};
14607: $gotaddr = 1;
14608: }
14609: }
14610: unless ($gotaddr) {
14611: my $uintdom = &Apache::lonnet::internet_dom($primary);
14612: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14613: unless ($uintdom eq $intdom) {
14614: my %domconfig =
14615: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14616: if (ref($domconfig{'contacts'}) eq 'HASH') {
14617: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14618: my @contacts = ('adminemail','supportemail');
14619: foreach my $item (@contacts) {
14620: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14621: my $addr = $domconfig{'contacts'}{$item};
14622: if (!grep(/^\Q$addr\E$/,@recipients)) {
14623: push(@recipients,$addr);
14624: }
14625: }
14626: }
14627: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14628: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14629: }
14630: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14631: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14632: my @ok_bccs;
14633: foreach my $bcc (@bccs) {
14634: $bcc =~ s/^\s+//g;
14635: $bcc =~ s/\s+$//g;
14636: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14637: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14638: push(@ok_bccs,$bcc);
14639: }
14640: }
14641: }
14642: if (@ok_bccs > 0) {
14643: $allbcc = join(', ',@ok_bccs);
14644: }
14645: }
14646: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14647: }
14648: }
14649: }
14650: }
14651: }
14652: }
1.618 raeburn 14653: }
1.688 raeburn 14654: if (defined($defmail)) {
14655: if ($defmail ne '') {
14656: push(@recipients,$defmail);
14657: }
1.618 raeburn 14658: }
14659: if ($otheremails) {
1.619 raeburn 14660: my @others;
14661: if ($otheremails =~ /,/) {
14662: @others = split(/,/,$otheremails);
1.618 raeburn 14663: } else {
1.619 raeburn 14664: push(@others,$otheremails);
14665: }
14666: foreach my $addr (@others) {
14667: if (!grep(/^\Q$addr\E$/,@recipients)) {
14668: push(@recipients,$addr);
14669: }
1.618 raeburn 14670: }
14671: }
1.1270 raeburn 14672: if ($mailing eq 'helpdesk') {
14673: if ((!@recipients) && ($lastresort ne '')) {
14674: push(@recipients,$lastresort);
14675: }
14676: } elsif ($lastresort ne '') {
14677: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14678: push(@recipients,$lastresort);
14679: }
14680: }
1.1271 raeburn 14681: my $recipientlist = join(',',@recipients);
1.1270 raeburn 14682: if (wantarray) {
14683: return ($recipientlist,$allbcc,$addtext);
14684: } else {
14685: return $recipientlist;
14686: }
1.618 raeburn 14687: }
14688:
1.127 matthew 14689: ############################################################
14690: ############################################################
1.154 albertel 14691:
1.655 raeburn 14692: =pod
14693:
1.1224 musolffc 14694: =over 4
14695:
1.1223 musolffc 14696: =item * &mime_email()
14697:
14698: Sends an email with a possible attachment
14699:
14700: Inputs:
14701:
14702: =over 4
14703:
14704: from - Sender's email address
14705:
14706: to - Email address of recipient
14707:
14708: subject - Subject of email
14709:
14710: body - Body of email
14711:
14712: cc_string - Carbon copy email address
14713:
14714: bcc - Blind carbon copy email address
14715:
14716: type - File type of attachment
14717:
14718: attachment_path - Path of file to be attached
14719:
14720: file_name - Name of file to be attached
14721:
14722: attachment_text - The body of an attachment of type "TEXT"
14723:
14724: =back
14725:
14726: =back
14727:
14728: =cut
14729:
14730: ############################################################
14731: ############################################################
14732:
14733: sub mime_email {
14734: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
14735: $file_name, $attachment_text) = @_;
14736: my $msg = MIME::Lite->new(
14737: From => $from,
14738: To => $to,
14739: Subject => $subject,
14740: Type =>'TEXT',
14741: Data => $body,
14742: );
14743: if ($cc_string ne '') {
14744: $msg->add("Cc" => $cc_string);
14745: }
14746: if ($bcc ne '') {
14747: $msg->add("Bcc" => $bcc);
14748: }
14749: $msg->attr("content-type" => "text/plain");
14750: $msg->attr("content-type.charset" => "UTF-8");
14751: # Attach file if given
14752: if ($attachment_path) {
14753: unless ($file_name) {
14754: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
14755: }
14756: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
14757: $msg->attach(Type => $type,
14758: Path => $attachment_path,
14759: Filename => $file_name
14760: );
14761: # Otherwise attach text if given
14762: } elsif ($attachment_text) {
14763: $msg->attach(Type => 'TEXT',
14764: Data => $attachment_text);
14765: }
14766: # Send it
14767: $msg->send('sendmail');
14768: }
14769:
14770: ############################################################
14771: ############################################################
14772:
14773: =pod
14774:
1.655 raeburn 14775: =head1 Course Catalog Routines
14776:
14777: =over 4
14778:
14779: =item * &gather_categories()
14780:
14781: Converts category definitions - keys of categories hash stored in
14782: coursecategories in configuration.db on the primary library server in a
14783: domain - to an array. Also generates javascript and idx hash used to
14784: generate Domain Coordinator interface for editing Course Categories.
14785:
14786: Inputs:
1.663 raeburn 14787:
1.655 raeburn 14788: categories (reference to hash of category definitions).
1.663 raeburn 14789:
1.655 raeburn 14790: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14791: categories and subcategories).
1.663 raeburn 14792:
1.655 raeburn 14793: idx (reference to hash of counters used in Domain Coordinator interface for
14794: editing Course Categories).
1.663 raeburn 14795:
1.655 raeburn 14796: jsarray (reference to array of categories used to create Javascript arrays for
14797: Domain Coordinator interface for editing Course Categories).
14798:
14799: Returns: nothing
14800:
14801: Side effects: populates cats, idx and jsarray.
14802:
14803: =cut
14804:
14805: sub gather_categories {
14806: my ($categories,$cats,$idx,$jsarray) = @_;
14807: my %counters;
14808: my $num = 0;
14809: foreach my $item (keys(%{$categories})) {
14810: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14811: if ($container eq '' && $depth == 0) {
14812: $cats->[$depth][$categories->{$item}] = $cat;
14813: } else {
14814: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14815: }
14816: my ($escitem,$tail) = split(/:/,$item,2);
14817: if ($counters{$tail} eq '') {
14818: $counters{$tail} = $num;
14819: $num ++;
14820: }
14821: if (ref($idx) eq 'HASH') {
14822: $idx->{$item} = $counters{$tail};
14823: }
14824: if (ref($jsarray) eq 'ARRAY') {
14825: push(@{$jsarray->[$counters{$tail}]},$item);
14826: }
14827: }
14828: return;
14829: }
14830:
14831: =pod
14832:
14833: =item * &extract_categories()
14834:
14835: Used to generate breadcrumb trails for course categories.
14836:
14837: Inputs:
1.663 raeburn 14838:
1.655 raeburn 14839: categories (reference to hash of category definitions).
1.663 raeburn 14840:
1.655 raeburn 14841: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14842: categories and subcategories).
1.663 raeburn 14843:
1.655 raeburn 14844: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14845:
1.655 raeburn 14846: allitems (reference to hash - key is category key
14847: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14848:
1.655 raeburn 14849: idx (reference to hash of counters used in Domain Coordinator interface for
14850: editing Course Categories).
1.663 raeburn 14851:
1.655 raeburn 14852: jsarray (reference to array of categories used to create Javascript arrays for
14853: Domain Coordinator interface for editing Course Categories).
14854:
1.665 raeburn 14855: subcats (reference to hash of arrays containing all subcategories within each
14856: category, -recursive)
14857:
1.655 raeburn 14858: Returns: nothing
14859:
14860: Side effects: populates trails and allitems hash references.
14861:
14862: =cut
14863:
14864: sub extract_categories {
1.665 raeburn 14865: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 14866: if (ref($categories) eq 'HASH') {
14867: &gather_categories($categories,$cats,$idx,$jsarray);
14868: if (ref($cats->[0]) eq 'ARRAY') {
14869: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14870: my $name = $cats->[0][$i];
14871: my $item = &escape($name).'::0';
14872: my $trailstr;
14873: if ($name eq 'instcode') {
14874: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14875: } elsif ($name eq 'communities') {
14876: $trailstr = &mt('Communities');
1.1239 raeburn 14877: } elsif ($name eq 'placement') {
14878: $trailstr = &mt('Placement Tests');
1.655 raeburn 14879: } else {
14880: $trailstr = $name;
14881: }
14882: if ($allitems->{$item} eq '') {
14883: push(@{$trails},$trailstr);
14884: $allitems->{$item} = scalar(@{$trails})-1;
14885: }
14886: my @parents = ($name);
14887: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14888: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14889: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14890: if (ref($subcats) eq 'HASH') {
14891: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14892: }
14893: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
14894: }
14895: } else {
14896: if (ref($subcats) eq 'HASH') {
14897: $subcats->{$item} = [];
1.655 raeburn 14898: }
14899: }
14900: }
14901: }
14902: }
14903: return;
14904: }
14905:
14906: =pod
14907:
1.1162 raeburn 14908: =item * &recurse_categories()
1.655 raeburn 14909:
14910: Recursively used to generate breadcrumb trails for course categories.
14911:
14912: Inputs:
1.663 raeburn 14913:
1.655 raeburn 14914: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14915: categories and subcategories).
1.663 raeburn 14916:
1.655 raeburn 14917: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14918:
14919: category (current course category, for which breadcrumb trail is being generated).
14920:
14921: trails (reference to array of breadcrumb trails for each category).
14922:
1.655 raeburn 14923: allitems (reference to hash - key is category key
14924: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14925:
1.655 raeburn 14926: parents (array containing containers directories for current category,
14927: back to top level).
14928:
14929: Returns: nothing
14930:
14931: Side effects: populates trails and allitems hash references
14932:
14933: =cut
14934:
14935: sub recurse_categories {
1.665 raeburn 14936: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 14937: my $shallower = $depth - 1;
14938: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14939: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14940: my $name = $cats->[$depth]{$category}[$k];
14941: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14942: my $trailstr = join(' -> ',(@{$parents},$category));
14943: if ($allitems->{$item} eq '') {
14944: push(@{$trails},$trailstr);
14945: $allitems->{$item} = scalar(@{$trails})-1;
14946: }
14947: my $deeper = $depth+1;
14948: push(@{$parents},$category);
1.665 raeburn 14949: if (ref($subcats) eq 'HASH') {
14950: my $subcat = &escape($name).':'.$category.':'.$depth;
14951: for (my $j=@{$parents}; $j>=0; $j--) {
14952: my $higher;
14953: if ($j > 0) {
14954: $higher = &escape($parents->[$j]).':'.
14955: &escape($parents->[$j-1]).':'.$j;
14956: } else {
14957: $higher = &escape($parents->[$j]).'::'.$j;
14958: }
14959: push(@{$subcats->{$higher}},$subcat);
14960: }
14961: }
14962: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
14963: $subcats);
1.655 raeburn 14964: pop(@{$parents});
14965: }
14966: } else {
14967: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14968: my $trailstr = join(' -> ',(@{$parents},$category));
14969: if ($allitems->{$item} eq '') {
14970: push(@{$trails},$trailstr);
14971: $allitems->{$item} = scalar(@{$trails})-1;
14972: }
14973: }
14974: return;
14975: }
14976:
1.663 raeburn 14977: =pod
14978:
1.1162 raeburn 14979: =item * &assign_categories_table()
1.663 raeburn 14980:
14981: Create a datatable for display of hierarchical categories in a domain,
14982: with checkboxes to allow a course to be categorized.
14983:
14984: Inputs:
14985:
14986: cathash - reference to hash of categories defined for the domain (from
14987: configuration.db)
14988:
14989: currcat - scalar with an & separated list of categories assigned to a course.
14990:
1.919 raeburn 14991: type - scalar contains course type (Course or Community).
14992:
1.1260 raeburn 14993: disabled - scalar (optional) contains disabled="disabled" if input elements are
14994: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14995:
1.663 raeburn 14996: Returns: $output (markup to be displayed)
14997:
14998: =cut
14999:
15000: sub assign_categories_table {
1.1259 raeburn 15001: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 15002: my $output;
15003: if (ref($cathash) eq 'HASH') {
15004: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
15005: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
15006: $maxdepth = scalar(@cats);
15007: if (@cats > 0) {
15008: my $itemcount = 0;
15009: if (ref($cats[0]) eq 'ARRAY') {
15010: my @currcategories;
15011: if ($currcat ne '') {
15012: @currcategories = split('&',$currcat);
15013: }
1.919 raeburn 15014: my $table;
1.663 raeburn 15015: for (my $i=0; $i<@{$cats[0]}; $i++) {
15016: my $parent = $cats[0][$i];
1.919 raeburn 15017: next if ($parent eq 'instcode');
15018: if ($type eq 'Community') {
15019: next unless ($parent eq 'communities');
1.1239 raeburn 15020: } elsif ($type eq 'Placement') {
15021: next unless ($parent eq 'placement');
1.919 raeburn 15022: } else {
1.1239 raeburn 15023: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15024: }
1.663 raeburn 15025: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15026: my $item = &escape($parent).'::0';
15027: my $checked = '';
15028: if (@currcategories > 0) {
15029: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15030: $checked = ' checked="checked"';
1.663 raeburn 15031: }
15032: }
1.919 raeburn 15033: my $parent_title = $parent;
15034: if ($parent eq 'communities') {
15035: $parent_title = &mt('Communities');
1.1239 raeburn 15036: } elsif ($parent eq 'placement') {
15037: $parent_title = &mt('Placement Tests');
1.919 raeburn 15038: }
15039: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15040: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15041: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15042: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15043: my $depth = 1;
15044: push(@path,$parent);
1.1259 raeburn 15045: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15046: pop(@path);
1.919 raeburn 15047: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15048: $itemcount ++;
15049: }
1.919 raeburn 15050: if ($itemcount) {
15051: $output = &Apache::loncommon::start_data_table().
15052: $table.
15053: &Apache::loncommon::end_data_table();
15054: }
1.663 raeburn 15055: }
15056: }
15057: }
15058: return $output;
15059: }
15060:
15061: =pod
15062:
1.1162 raeburn 15063: =item * &assign_category_rows()
1.663 raeburn 15064:
15065: Create a datatable row for display of nested categories in a domain,
15066: with checkboxes to allow a course to be categorized,called recursively.
15067:
15068: Inputs:
15069:
15070: itemcount - track row number for alternating colors
15071:
15072: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15073: categories and subcategories.
15074:
15075: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15076:
15077: parent - parent of current category item
15078:
15079: path - Array containing all categories back up through the hierarchy from the
15080: current category to the top level.
15081:
15082: currcategories - reference to array of current categories assigned to the course
15083:
1.1260 raeburn 15084: disabled - scalar (optional) contains disabled="disabled" if input elements are
15085: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15086:
1.663 raeburn 15087: Returns: $output (markup to be displayed).
15088:
15089: =cut
15090:
15091: sub assign_category_rows {
1.1259 raeburn 15092: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15093: my ($text,$name,$item,$chgstr);
15094: if (ref($cats) eq 'ARRAY') {
15095: my $maxdepth = scalar(@{$cats});
15096: if (ref($cats->[$depth]) eq 'HASH') {
15097: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15098: my $numchildren = @{$cats->[$depth]{$parent}};
15099: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 15100: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15101: for (my $j=0; $j<$numchildren; $j++) {
15102: $name = $cats->[$depth]{$parent}[$j];
15103: $item = &escape($name).':'.&escape($parent).':'.$depth;
15104: my $deeper = $depth+1;
15105: my $checked = '';
15106: if (ref($currcategories) eq 'ARRAY') {
15107: if (@{$currcategories} > 0) {
15108: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15109: $checked = ' checked="checked"';
1.663 raeburn 15110: }
15111: }
15112: }
1.664 raeburn 15113: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15114: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15115: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15116: '<input type="hidden" name="catname" value="'.$name.'" />'.
15117: '</td><td>';
1.663 raeburn 15118: if (ref($path) eq 'ARRAY') {
15119: push(@{$path},$name);
1.1259 raeburn 15120: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15121: pop(@{$path});
15122: }
15123: $text .= '</td></tr>';
15124: }
15125: $text .= '</table></td>';
15126: }
15127: }
15128: }
15129: return $text;
15130: }
15131:
1.1181 raeburn 15132: =pod
15133:
15134: =back
15135:
15136: =cut
15137:
1.655 raeburn 15138: ############################################################
15139: ############################################################
15140:
15141:
1.443 albertel 15142: sub commit_customrole {
1.664 raeburn 15143: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15144: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15145: ($start?', '.&mt('starting').' '.localtime($start):'').
15146: ($end?', ending '.localtime($end):'').': <b>'.
15147: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15148: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15149: '</b><br />';
15150: return $output;
15151: }
15152:
15153: sub commit_standardrole {
1.1116 raeburn 15154: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15155: my ($output,$logmsg,$linefeed);
15156: if ($context eq 'auto') {
15157: $linefeed = "\n";
15158: } else {
15159: $linefeed = "<br />\n";
15160: }
1.443 albertel 15161: if ($three eq 'st') {
1.541 raeburn 15162: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 15163: $one,$two,$sec,$context,$credits);
1.541 raeburn 15164: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15165: ($result eq 'unknown_course') || ($result eq 'refused')) {
15166: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15167: } else {
1.541 raeburn 15168: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15169: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15170: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15171: if ($context eq 'auto') {
15172: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15173: } else {
15174: $output .= '<b>'.$result.'</b>'.$linefeed.
15175: &mt('Add to classlist').': <b>ok</b>';
15176: }
15177: $output .= $linefeed;
1.443 albertel 15178: }
15179: } else {
15180: $output = &mt('Assigning').' '.$three.' in '.$url.
15181: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15182: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15183: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15184: if ($context eq 'auto') {
15185: $output .= $result.$linefeed;
15186: } else {
15187: $output .= '<b>'.$result.'</b>'.$linefeed;
15188: }
1.443 albertel 15189: }
15190: return $output;
15191: }
15192:
15193: sub commit_studentrole {
1.1116 raeburn 15194: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15195: $credits) = @_;
1.626 raeburn 15196: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15197: if ($context eq 'auto') {
15198: $linefeed = "\n";
15199: } else {
15200: $linefeed = '<br />'."\n";
15201: }
1.443 albertel 15202: if (defined($one) && defined($two)) {
15203: my $cid=$one.'_'.$two;
15204: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15205: my $secchange = 0;
15206: my $expire_role_result;
15207: my $modify_section_result;
1.628 raeburn 15208: if ($oldsec ne '-1') {
15209: if ($oldsec ne $sec) {
1.443 albertel 15210: $secchange = 1;
1.628 raeburn 15211: my $now = time;
1.443 albertel 15212: my $uurl='/'.$cid;
15213: $uurl=~s/\_/\//g;
15214: if ($oldsec) {
15215: $uurl.='/'.$oldsec;
15216: }
1.626 raeburn 15217: $oldsecurl = $uurl;
1.628 raeburn 15218: $expire_role_result =
1.652 raeburn 15219: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15220: if ($env{'request.course.sec'} ne '') {
15221: if ($expire_role_result eq 'refused') {
15222: my @roles = ('st');
15223: my @statuses = ('previous');
15224: my @roledoms = ($one);
15225: my $withsec = 1;
15226: my %roleshash =
15227: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15228: \@statuses,\@roles,\@roledoms,$withsec);
15229: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15230: my ($oldstart,$oldend) =
15231: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15232: if ($oldend > 0 && $oldend <= $now) {
15233: $expire_role_result = 'ok';
15234: }
15235: }
15236: }
15237: }
1.443 albertel 15238: $result = $expire_role_result;
15239: }
15240: }
15241: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15242: $modify_section_result =
15243: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15244: undef,undef,undef,$sec,
15245: $end,$start,'','',$cid,
15246: '',$context,$credits);
1.443 albertel 15247: if ($modify_section_result =~ /^ok/) {
15248: if ($secchange == 1) {
1.628 raeburn 15249: if ($sec eq '') {
15250: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15251: } else {
15252: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15253: }
1.443 albertel 15254: } elsif ($oldsec eq '-1') {
1.628 raeburn 15255: if ($sec eq '') {
15256: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15257: } else {
15258: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15259: }
1.443 albertel 15260: } else {
1.628 raeburn 15261: if ($sec eq '') {
15262: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15263: } else {
15264: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15265: }
1.443 albertel 15266: }
15267: } else {
1.1115 raeburn 15268: if ($secchange) {
1.628 raeburn 15269: $$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;
15270: } else {
15271: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15272: }
1.443 albertel 15273: }
15274: $result = $modify_section_result;
15275: } elsif ($secchange == 1) {
1.628 raeburn 15276: if ($oldsec eq '') {
1.1103 raeburn 15277: $$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 15278: } else {
15279: $$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;
15280: }
1.626 raeburn 15281: if ($expire_role_result eq 'refused') {
15282: my $newsecurl = '/'.$cid;
15283: $newsecurl =~ s/\_/\//g;
15284: if ($sec ne '') {
15285: $newsecurl.='/'.$sec;
15286: }
15287: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15288: if ($sec eq '') {
15289: $$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;
15290: } else {
15291: $$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;
15292: }
15293: }
15294: }
1.443 albertel 15295: }
15296: } else {
1.626 raeburn 15297: $$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 15298: $result = "error: incomplete course id\n";
15299: }
15300: return $result;
15301: }
15302:
1.1108 raeburn 15303: sub show_role_extent {
15304: my ($scope,$context,$role) = @_;
15305: $scope =~ s{^/}{};
15306: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15307: push(@courseroles,'co');
15308: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15309: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15310: $scope =~ s{/}{_};
15311: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15312: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15313: my ($audom,$auname) = split(/\//,$scope);
15314: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15315: &Apache::loncommon::plainname($auname,$audom).'</span>');
15316: } else {
15317: $scope =~ s{/$}{};
15318: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15319: &Apache::lonnet::domain($scope,'description').'</span>');
15320: }
15321: }
15322:
1.443 albertel 15323: ############################################################
15324: ############################################################
15325:
1.566 albertel 15326: sub check_clone {
1.578 raeburn 15327: my ($args,$linefeed) = @_;
1.566 albertel 15328: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15329: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15330: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15331: my $clonemsg;
15332: my $can_clone = 0;
1.944 raeburn 15333: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15334: if ($lctype ne 'community') {
15335: $lctype = 'course';
15336: }
1.566 albertel 15337: if ($clonehome eq 'no_host') {
1.944 raeburn 15338: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15339: $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'});
15340: } else {
15341: $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'});
15342: }
1.566 albertel 15343: } else {
15344: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15345: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15346: if ($clonedesc{'type'} ne 'Community') {
1.1262 raeburn 15347: $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 15348: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15349: }
15350: }
1.1262 raeburn 15351: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15352: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15353: $can_clone = 1;
15354: } else {
1.1221 raeburn 15355: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15356: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 15357: if ($clonehash{'cloners'} eq '') {
15358: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15359: if ($domdefs{'canclone'}) {
15360: unless ($domdefs{'canclone'} eq 'none') {
15361: if ($domdefs{'canclone'} eq 'domain') {
15362: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15363: $can_clone = 1;
15364: }
15365: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15366: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15367: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15368: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15369: $can_clone = 1;
15370: }
15371: }
15372: }
15373: }
1.578 raeburn 15374: } else {
1.1221 raeburn 15375: my @cloners = split(/,/,$clonehash{'cloners'});
15376: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15377: $can_clone = 1;
1.1221 raeburn 15378: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15379: $can_clone = 1;
1.1225 raeburn 15380: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15381: $can_clone = 1;
1.1221 raeburn 15382: }
15383: unless ($can_clone) {
1.1225 raeburn 15384: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15385: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 15386: my (%gotdomdefaults,%gotcodedefaults);
15387: foreach my $cloner (@cloners) {
15388: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15389: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15390: my (%codedefaults,@code_order);
15391: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15392: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15393: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15394: }
15395: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15396: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15397: }
15398: } else {
15399: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15400: \%codedefaults,
15401: \@code_order);
15402: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15403: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15404: }
15405: if (@code_order > 0) {
15406: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15407: $cloner,$clonehash{'internal.coursecode'},
15408: $args->{'crscode'})) {
15409: $can_clone = 1;
15410: last;
15411: }
15412: }
15413: }
15414: }
15415: }
1.1225 raeburn 15416: }
15417: }
15418: unless ($can_clone) {
15419: my $ccrole = 'cc';
15420: if ($args->{'crstype'} eq 'Community') {
15421: $ccrole = 'co';
15422: }
15423: my %roleshash =
15424: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15425: $args->{'ccdomain'},
15426: 'userroles',['active'],[$ccrole],
15427: [$args->{'clonedomain'}]);
15428: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15429: $can_clone = 1;
15430: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15431: $args->{'ccuname'},$args->{'ccdomain'})) {
15432: $can_clone = 1;
1.1221 raeburn 15433: }
15434: }
15435: unless ($can_clone) {
15436: if ($args->{'crstype'} eq 'Community') {
15437: $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 15438: } else {
1.1221 raeburn 15439: $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'});
15440: }
1.566 albertel 15441: }
1.578 raeburn 15442: }
1.566 albertel 15443: }
15444: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15445: }
15446:
1.444 albertel 15447: sub construct_course {
1.1262 raeburn 15448: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15449: $cnum,$category,$coderef) = @_;
1.444 albertel 15450: my $outcome;
1.541 raeburn 15451: my $linefeed = '<br />'."\n";
15452: if ($context eq 'auto') {
15453: $linefeed = "\n";
15454: }
1.566 albertel 15455:
15456: #
15457: # Are we cloning?
15458: #
15459: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15460: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15461: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15462: if ($context ne 'auto') {
1.578 raeburn 15463: if ($clonemsg ne '') {
15464: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15465: }
1.566 albertel 15466: }
15467: $outcome .= $clonemsg.$linefeed;
15468:
15469: if (!$can_clone) {
15470: return (0,$outcome);
15471: }
15472: }
15473:
1.444 albertel 15474: #
15475: # Open course
15476: #
1.1239 raeburn 15477: my $showncrstype;
15478: if ($args->{'crstype'} eq 'Placement') {
15479: $showncrstype = 'placement test';
15480: } else {
15481: $showncrstype = lc($args->{'crstype'});
15482: }
1.444 albertel 15483: my %cenv=();
15484: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15485: $args->{'cdescr'},
15486: $args->{'curl'},
15487: $args->{'course_home'},
15488: $args->{'nonstandard'},
15489: $args->{'crscode'},
15490: $args->{'ccuname'}.':'.
15491: $args->{'ccdomain'},
1.882 raeburn 15492: $args->{'crstype'},
1.885 raeburn 15493: $cnum,$context,$category);
1.444 albertel 15494:
15495: # Note: The testing routines depend on this being output; see
15496: # Utils::Course. This needs to at least be output as a comment
15497: # if anyone ever decides to not show this, and Utils::Course::new
15498: # will need to be suitably modified.
1.1239 raeburn 15499: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
1.943 raeburn 15500: if ($$courseid =~ /^error:/) {
15501: return (0,$outcome);
15502: }
15503:
1.444 albertel 15504: #
15505: # Check if created correctly
15506: #
1.479 albertel 15507: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15508: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15509: if ($crsuhome eq 'no_host') {
15510: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15511: return (0,$outcome);
15512: }
1.541 raeburn 15513: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15514:
1.444 albertel 15515: #
1.566 albertel 15516: # Do the cloning
15517: #
15518: if ($can_clone && $cloneid) {
1.1239 raeburn 15519: $clonemsg = &mt('Cloning [_1] from [_2]',$showncrstype,$clonehome);
1.566 albertel 15520: if ($context ne 'auto') {
15521: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15522: }
15523: $outcome .= $clonemsg.$linefeed;
15524: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15525: # Copy all files
1.637 www 15526: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15527: # Restore URL
1.566 albertel 15528: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15529: # Restore title
1.566 albertel 15530: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15531: # Restore creation date, creator and creation context.
15532: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15533: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15534: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15535: # Mark as cloned
1.566 albertel 15536: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15537: # Need to clone grading mode
15538: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15539: $cenv{'grading'}=$newenv{'grading'};
15540: # Do not clone these environment entries
15541: &Apache::lonnet::del('environment',
15542: ['default_enrollment_start_date',
15543: 'default_enrollment_end_date',
15544: 'question.email',
15545: 'policy.email',
15546: 'comment.email',
15547: 'pch.users.denied',
1.725 raeburn 15548: 'plc.users.denied',
15549: 'hidefromcat',
1.1121 raeburn 15550: 'checkforpriv',
1.1166 raeburn 15551: 'categories',
15552: 'internal.uniquecode'],
1.638 www 15553: $$crsudom,$$crsunum);
1.1170 raeburn 15554: if ($args->{'textbook'}) {
15555: $cenv{'internal.textbook'} = $args->{'textbook'};
15556: }
1.444 albertel 15557: }
1.566 albertel 15558:
1.444 albertel 15559: #
15560: # Set environment (will override cloned, if existing)
15561: #
15562: my @sections = ();
15563: my @xlists = ();
15564: if ($args->{'crstype'}) {
15565: $cenv{'type'}=$args->{'crstype'};
15566: }
15567: if ($args->{'crsid'}) {
15568: $cenv{'courseid'}=$args->{'crsid'};
15569: }
15570: if ($args->{'crscode'}) {
15571: $cenv{'internal.coursecode'}=$args->{'crscode'};
15572: }
15573: if ($args->{'crsquota'} ne '') {
15574: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15575: } else {
15576: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15577: }
15578: if ($args->{'ccuname'}) {
15579: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15580: ':'.$args->{'ccdomain'};
15581: } else {
15582: $cenv{'internal.courseowner'} = $args->{'curruser'};
15583: }
1.1116 raeburn 15584: if ($args->{'defaultcredits'}) {
15585: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15586: }
1.444 albertel 15587: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15588: if ($args->{'crssections'}) {
15589: $cenv{'internal.sectionnums'} = '';
15590: if ($args->{'crssections'} =~ m/,/) {
15591: @sections = split/,/,$args->{'crssections'};
15592: } else {
15593: $sections[0] = $args->{'crssections'};
15594: }
15595: if (@sections > 0) {
15596: foreach my $item (@sections) {
15597: my ($sec,$gp) = split/:/,$item;
15598: my $class = $args->{'crscode'}.$sec;
15599: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15600: $cenv{'internal.sectionnums'} .= $item.',';
15601: unless ($addcheck eq 'ok') {
1.1263 raeburn 15602: push(@badclasses,$class);
1.444 albertel 15603: }
15604: }
15605: $cenv{'internal.sectionnums'} =~ s/,$//;
15606: }
15607: }
15608: # do not hide course coordinator from staff listing,
15609: # even if privileged
15610: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 15611: # add course coordinator's domain to domains to check for privileged users
15612: # if different to course domain
15613: if ($$crsudom ne $args->{'ccdomain'}) {
15614: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15615: }
1.444 albertel 15616: # add crosslistings
15617: if ($args->{'crsxlist'}) {
15618: $cenv{'internal.crosslistings'}='';
15619: if ($args->{'crsxlist'} =~ m/,/) {
15620: @xlists = split/,/,$args->{'crsxlist'};
15621: } else {
15622: $xlists[0] = $args->{'crsxlist'};
15623: }
15624: if (@xlists > 0) {
15625: foreach my $item (@xlists) {
15626: my ($xl,$gp) = split/:/,$item;
15627: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15628: $cenv{'internal.crosslistings'} .= $item.',';
15629: unless ($addcheck eq 'ok') {
1.1263 raeburn 15630: push(@badclasses,$xl);
1.444 albertel 15631: }
15632: }
15633: $cenv{'internal.crosslistings'} =~ s/,$//;
15634: }
15635: }
15636: if ($args->{'autoadds'}) {
15637: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15638: }
15639: if ($args->{'autodrops'}) {
15640: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15641: }
15642: # check for notification of enrollment changes
15643: my @notified = ();
15644: if ($args->{'notify_owner'}) {
15645: if ($args->{'ccuname'} ne '') {
15646: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15647: }
15648: }
15649: if ($args->{'notify_dc'}) {
15650: if ($uname ne '') {
1.630 raeburn 15651: push(@notified,$uname.':'.$udom);
1.444 albertel 15652: }
15653: }
15654: if (@notified > 0) {
15655: my $notifylist;
15656: if (@notified > 1) {
15657: $notifylist = join(',',@notified);
15658: } else {
15659: $notifylist = $notified[0];
15660: }
15661: $cenv{'internal.notifylist'} = $notifylist;
15662: }
15663: if (@badclasses > 0) {
15664: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 15665: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15666: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15667: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15668: );
1.1264 raeburn 15669: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15670: &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 15671: if ($context eq 'auto') {
15672: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 15673: } else {
1.566 albertel 15674: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 15675: }
15676: foreach my $item (@badclasses) {
1.541 raeburn 15677: if ($context eq 'auto') {
1.1261 raeburn 15678: $outcome .= " - $item\n";
1.541 raeburn 15679: } else {
1.1261 raeburn 15680: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15681: }
1.1261 raeburn 15682: }
15683: if ($context eq 'auto') {
15684: $outcome .= $linefeed;
15685: } else {
15686: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 15687: }
1.444 albertel 15688: }
15689: if ($args->{'no_end_date'}) {
15690: $args->{'endaccess'} = 0;
15691: }
15692: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15693: $cenv{'internal.autoend'}=$args->{'enrollend'};
15694: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15695: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15696: if ($args->{'showphotos'}) {
15697: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15698: }
15699: $cenv{'internal.authtype'} = $args->{'authtype'};
15700: $cenv{'internal.autharg'} = $args->{'autharg'};
15701: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15702: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15703: 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');
15704: if ($context eq 'auto') {
15705: $outcome .= $krb_msg;
15706: } else {
1.566 albertel 15707: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15708: }
15709: $outcome .= $linefeed;
1.444 albertel 15710: }
15711: }
15712: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15713: if ($args->{'setpolicy'}) {
15714: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15715: }
15716: if ($args->{'setcontent'}) {
15717: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15718: }
1.1251 raeburn 15719: if ($args->{'setcomment'}) {
15720: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15721: }
1.444 albertel 15722: }
15723: if ($args->{'reshome'}) {
15724: $cenv{'reshome'}=$args->{'reshome'}.'/';
15725: $cenv{'reshome'}=~s/\/+$/\//;
15726: }
15727: #
15728: # course has keyed access
15729: #
15730: if ($args->{'setkeys'}) {
15731: $cenv{'keyaccess'}='yes';
15732: }
15733: # if specified, key authority is not course, but user
15734: # only active if keyaccess is yes
15735: if ($args->{'keyauth'}) {
1.487 albertel 15736: my ($user,$domain) = split(':',$args->{'keyauth'});
15737: $user = &LONCAPA::clean_username($user);
15738: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15739: if ($user ne '' && $domain ne '') {
1.487 albertel 15740: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15741: }
15742: }
15743:
1.1166 raeburn 15744: #
1.1167 raeburn 15745: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 15746: #
15747: if ($args->{'uniquecode'}) {
15748: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15749: if ($code) {
15750: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 15751: my %crsinfo =
15752: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15753: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15754: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15755: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15756: }
1.1166 raeburn 15757: if (ref($coderef)) {
15758: $$coderef = $code;
15759: }
15760: }
15761: }
15762:
1.444 albertel 15763: if ($args->{'disresdis'}) {
15764: $cenv{'pch.roles.denied'}='st';
15765: }
15766: if ($args->{'disablechat'}) {
15767: $cenv{'plc.roles.denied'}='st';
15768: }
15769:
15770: # Record we've not yet viewed the Course Initialization Helper for this
15771: # course
15772: $cenv{'course.helper.not.run'} = 1;
15773: #
15774: # Use new Randomseed
15775: #
15776: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15777: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15778: #
15779: # The encryption code and receipt prefix for this course
15780: #
15781: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15782: $cenv{'internal.encpref'}=100+int(9*rand(99));
15783: #
15784: # By default, use standard grading
15785: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15786:
1.541 raeburn 15787: $outcome .= $linefeed.&mt('Setting environment').': '.
15788: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15789: #
15790: # Open all assignments
15791: #
15792: if ($args->{'openall'}) {
15793: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15794: my %storecontent = ($storeunder => time,
15795: $storeunder.'.type' => 'date_start');
15796:
15797: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15798: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15799: }
15800: #
15801: # Set first page
15802: #
15803: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15804: || ($cloneid)) {
1.445 albertel 15805: use LONCAPA::map;
1.444 albertel 15806: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15807:
15808: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15809: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15810:
1.444 albertel 15811: $outcome .= ($fatal?$errtext:'read ok').' - ';
15812: my $title; my $url;
15813: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15814: $title=&mt('Syllabus');
1.444 albertel 15815: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15816: } else {
1.963 raeburn 15817: $title=&mt('Table of Contents');
1.444 albertel 15818: $url='/adm/navmaps';
15819: }
1.445 albertel 15820:
15821: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15822: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15823:
15824: if ($errtext) { $fatal=2; }
1.541 raeburn 15825: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15826: }
1.566 albertel 15827:
1.1237 raeburn 15828: #
15829: # Set params for Placement Tests
15830: #
1.1239 raeburn 15831: if ($args->{'crstype'} eq 'Placement') {
15832: my %storecontent;
15833: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
15834: my %defaults = (
15835: buttonshide => { value => 'yes',
15836: type => 'string_yesno',},
15837: type => { value => 'randomizetry',
15838: type => 'string_questiontype',},
15839: maxtries => { value => 1,
15840: type => 'int_pos',},
15841: problemstatus => { value => 'no',
15842: type => 'string_problemstatus',},
15843: );
15844: foreach my $key (keys(%defaults)) {
15845: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
15846: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
15847: }
1.1237 raeburn 15848: &Apache::lonnet::cput
15849: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
15850: }
15851:
1.566 albertel 15852: return (1,$outcome);
1.444 albertel 15853: }
15854:
1.1166 raeburn 15855: sub make_unique_code {
15856: my ($cdom,$cnum) = @_;
15857: # get lock on uniquecodes db
15858: my $lockhash = {
15859: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15860: ':'.$env{'user.domain'},
15861: };
15862: my $tries = 0;
15863: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15864: my ($code,$error);
15865:
15866: while (($gotlock ne 'ok') && ($tries<3)) {
15867: $tries ++;
15868: sleep 1;
15869: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15870: }
15871: if ($gotlock eq 'ok') {
15872: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15873: my $gotcode;
15874: my $attempts = 0;
15875: while ((!$gotcode) && ($attempts < 100)) {
15876: $code = &generate_code();
15877: if (!exists($currcodes{$code})) {
15878: $gotcode = 1;
15879: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15880: $error = 'nostore';
15881: }
15882: }
15883: $attempts ++;
15884: }
15885: my @del_lock = ($cnum."\0".'uniquecodes');
15886: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15887: } else {
15888: $error = 'nolock';
15889: }
15890: return ($code,$error);
15891: }
15892:
15893: sub generate_code {
15894: my $code;
15895: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15896: for (my $i=0; $i<6; $i++) {
15897: my $lettnum = int (rand 2);
15898: my $item = '';
15899: if ($lettnum) {
15900: $item = $letts[int( rand(18) )];
15901: } else {
15902: $item = 1+int( rand(8) );
15903: }
15904: $code .= $item;
15905: }
15906: return $code;
15907: }
15908:
1.444 albertel 15909: ############################################################
15910: ############################################################
15911:
1.1237 raeburn 15912: # Community, Course and Placement Test
1.378 raeburn 15913: sub course_type {
15914: my ($cid) = @_;
15915: if (!defined($cid)) {
15916: $cid = $env{'request.course.id'};
15917: }
1.404 albertel 15918: if (defined($env{'course.'.$cid.'.type'})) {
15919: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15920: } else {
15921: return 'Course';
1.377 raeburn 15922: }
15923: }
1.156 albertel 15924:
1.406 raeburn 15925: sub group_term {
15926: my $crstype = &course_type();
15927: my %names = (
15928: 'Course' => 'group',
1.865 raeburn 15929: 'Community' => 'group',
1.1237 raeburn 15930: 'Placement' => 'group',
1.406 raeburn 15931: );
15932: return $names{$crstype};
15933: }
15934:
1.902 raeburn 15935: sub course_types {
1.1237 raeburn 15936: my @types = ('official','unofficial','community','textbook','placement');
1.902 raeburn 15937: my %typename = (
15938: official => 'Official course',
15939: unofficial => 'Unofficial course',
15940: community => 'Community',
1.1165 raeburn 15941: textbook => 'Textbook course',
1.1237 raeburn 15942: placement => 'Placement test',
1.902 raeburn 15943: );
15944: return (\@types,\%typename);
15945: }
15946:
1.156 albertel 15947: sub icon {
15948: my ($file)=@_;
1.505 albertel 15949: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15950: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15951: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15952: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15953: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15954: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15955: $curfext.".gif") {
15956: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15957: $curfext.".gif";
15958: }
15959: }
1.249 albertel 15960: return &lonhttpdurl($iconname);
1.154 albertel 15961: }
1.84 albertel 15962:
1.575 albertel 15963: sub lonhttpdurl {
1.692 www 15964: #
15965: # Had been used for "small fry" static images on separate port 8080.
15966: # Modify here if lightweight http functionality desired again.
15967: # Currently eliminated due to increasing firewall issues.
15968: #
1.575 albertel 15969: my ($url)=@_;
1.692 www 15970: return $url;
1.215 albertel 15971: }
15972:
1.213 albertel 15973: sub connection_aborted {
15974: my ($r)=@_;
15975: $r->print(" ");$r->rflush();
15976: my $c = $r->connection;
15977: return $c->aborted();
15978: }
15979:
1.221 foxr 15980: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15981: # strings as 'strings'.
15982: sub escape_single {
1.221 foxr 15983: my ($input) = @_;
1.223 albertel 15984: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15985: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15986: return $input;
15987: }
1.223 albertel 15988:
1.222 foxr 15989: # Same as escape_single, but escape's "'s This
15990: # can be used for "strings"
15991: sub escape_double {
15992: my ($input) = @_;
15993: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15994: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15995: return $input;
15996: }
1.223 albertel 15997:
1.222 foxr 15998: # Escapes the last element of a full URL.
15999: sub escape_url {
16000: my ($url) = @_;
1.238 raeburn 16001: my @urlslices = split(/\//, $url,-1);
1.369 www 16002: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 16003: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 16004: }
1.462 albertel 16005:
1.820 raeburn 16006: sub compare_arrays {
16007: my ($arrayref1,$arrayref2) = @_;
16008: my (@difference,%count);
16009: @difference = ();
16010: %count = ();
16011: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16012: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16013: foreach my $element (keys(%count)) {
16014: if ($count{$element} == 1) {
16015: push(@difference,$element);
16016: }
16017: }
16018: }
16019: return @difference;
16020: }
16021:
1.817 bisitz 16022: # -------------------------------------------------------- Initialize user login
1.462 albertel 16023: sub init_user_environment {
1.463 albertel 16024: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16025: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16026:
16027: my $public=($username eq 'public' && $domain eq 'public');
16028:
1.1062 raeburn 16029: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16030: my $now=time;
16031:
16032: if ($public) {
16033: my $max_public=100;
16034: my $oldest;
16035: my $oldest_time=0;
16036: for(my $next=1;$next<=$max_public;$next++) {
16037: if (-e $lonids."/publicuser_$next.id") {
16038: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16039: if ($mtime<$oldest_time || !$oldest_time) {
16040: $oldest_time=$mtime;
16041: $oldest=$next;
16042: }
16043: } else {
16044: $cookie="publicuser_$next";
16045: last;
16046: }
16047: }
16048: if (!$cookie) { $cookie="publicuser_$oldest"; }
16049: } else {
1.1275 raeburn 16050: # See if old ID present, if so, remove if this isn't a robot,
16051: # killing any existing non-robot sessions
1.463 albertel 16052: if (!$args->{'robot'}) {
16053: opendir(DIR,$lonids);
16054: while ($filename=readdir(DIR)) {
16055: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
16056: unlink($lonids.'/'.$filename);
16057: }
1.462 albertel 16058: }
1.463 albertel 16059: closedir(DIR);
1.1204 raeburn 16060: # If there is a undeleted lockfile for the user's paste buffer remove it.
16061: my $namespace = 'nohist_courseeditor';
16062: my $lockingkey = 'paste'."\0".'locked_num';
16063: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16064: $domain,$username);
16065: if (exists($lockhash{$lockingkey})) {
16066: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16067: unless ($delresult eq 'ok') {
16068: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16069: }
16070: }
1.462 albertel 16071: }
16072: # Give them a new cookie
1.463 albertel 16073: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16074: : $now.$$.int(rand(10000)));
1.463 albertel 16075: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16076:
16077: # Initialize roles
16078:
1.1062 raeburn 16079: ($userroles,$firstaccenv,$timerintenv) =
16080: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16081: }
16082: # ------------------------------------ Check browser type and MathML capability
16083:
1.1194 raeburn 16084: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16085: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16086:
16087: # ------------------------------------------------------------- Get environment
16088:
16089: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16090: my ($tmp) = keys(%userenv);
1.1275 raeburn 16091: if ($tmp =~ /^(con_lost|error|no_such_host)/i) {
1.462 albertel 16092: undef(%userenv);
16093: }
16094: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16095: $form->{'interface'}=$userenv{'interface'};
16096: }
16097: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16098:
16099: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16100: foreach my $option ('interface','localpath','localres') {
16101: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16102: }
16103: # --------------------------------------------------------- Write first profile
16104:
16105: {
16106: my %initial_env =
16107: ("user.name" => $username,
16108: "user.domain" => $domain,
16109: "user.home" => $authhost,
16110: "browser.type" => $clientbrowser,
16111: "browser.version" => $clientversion,
16112: "browser.mathml" => $clientmathml,
16113: "browser.unicode" => $clientunicode,
16114: "browser.os" => $clientos,
1.1137 raeburn 16115: "browser.mobile" => $clientmobile,
1.1141 raeburn 16116: "browser.info" => $clientinfo,
1.1194 raeburn 16117: "browser.osversion" => $clientosversion,
1.462 albertel 16118: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16119: "request.course.fn" => '',
16120: "request.course.uri" => '',
16121: "request.course.sec" => '',
16122: "request.role" => 'cm',
16123: "request.role.adv" => $env{'user.adv'},
16124: "request.host" => $ENV{'REMOTE_ADDR'},);
16125:
16126: if ($form->{'localpath'}) {
16127: $initial_env{"browser.localpath"} = $form->{'localpath'};
16128: $initial_env{"browser.localres"} = $form->{'localres'};
16129: }
16130:
16131: if ($form->{'interface'}) {
16132: $form->{'interface'}=~s/\W//gs;
16133: $initial_env{"browser.interface"} = $form->{'interface'};
16134: $env{'browser.interface'}=$form->{'interface'};
16135: }
16136:
1.1157 raeburn 16137: if ($form->{'iptoken'}) {
16138: my $lonhost = $r->dir_config('lonHostID');
16139: $initial_env{"user.noloadbalance"} = $lonhost;
16140: $env{'user.noloadbalance'} = $lonhost;
16141: }
16142:
1.1268 raeburn 16143: if ($form->{'noloadbalance'}) {
16144: my @hosts = &Apache::lonnet::current_machine_ids();
16145: my $hosthere = $form->{'noloadbalance'};
16146: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16147: $initial_env{"user.noloadbalance"} = $hosthere;
16148: $env{'user.noloadbalance'} = $hosthere;
16149: }
16150: }
16151:
1.1016 raeburn 16152: unless ($domain eq 'public') {
1.1273 raeburn 16153: my %is_adv = ( is_adv => $env{'user.adv'} );
16154: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
16155:
16156: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16157: $userenv{'availabletools.'.$tool} =
16158: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16159: undef,\%userenv,\%domdef,\%is_adv);
16160: }
1.980 raeburn 16161:
1.1273 raeburn 16162: foreach my $crstype ('official','unofficial','community','textbook','placement') {
16163: $userenv{'canrequest.'.$crstype} =
16164: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16165: 'reload','requestcourses',
16166: \%userenv,\%domdef,\%is_adv);
16167: }
1.724 raeburn 16168:
1.1273 raeburn 16169: $userenv{'canrequest.author'} =
16170: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16171: 'reload','requestauthor',
1.980 raeburn 16172: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 16173: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16174: $domain,$username);
16175: my $reqstatus = $reqauthor{'author_status'};
16176: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16177: if (ref($reqauthor{'author'}) eq 'HASH') {
16178: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16179: $reqauthor{'author'}{'timestamp'};
16180: }
1.1092 raeburn 16181: }
16182: }
16183:
1.462 albertel 16184: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16185:
1.462 albertel 16186: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16187: &GDBM_WRCREAT(),0640)) {
16188: &_add_to_env(\%disk_env,\%initial_env);
16189: &_add_to_env(\%disk_env,\%userenv,'environment.');
16190: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16191: if (ref($firstaccenv) eq 'HASH') {
16192: &_add_to_env(\%disk_env,$firstaccenv);
16193: }
16194: if (ref($timerintenv) eq 'HASH') {
16195: &_add_to_env(\%disk_env,$timerintenv);
16196: }
1.463 albertel 16197: if (ref($args->{'extra_env'})) {
16198: &_add_to_env(\%disk_env,$args->{'extra_env'});
16199: }
1.462 albertel 16200: untie(%disk_env);
16201: } else {
1.705 tempelho 16202: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16203: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16204: return 'error: '.$!;
16205: }
16206: }
16207: $env{'request.role'}='cm';
16208: $env{'request.role.adv'}=$env{'user.adv'};
16209: $env{'browser.type'}=$clientbrowser;
16210:
16211: return $cookie;
16212:
16213: }
16214:
16215: sub _add_to_env {
16216: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16217: if (ref($env_data) eq 'HASH') {
16218: while (my ($key,$value) = each(%$env_data)) {
16219: $idf->{$prefix.$key} = $value;
16220: $env{$prefix.$key} = $value;
16221: }
1.462 albertel 16222: }
16223: }
16224:
1.685 tempelho 16225: # --- Get the symbolic name of a problem and the url
16226: sub get_symb {
16227: my ($request,$silent) = @_;
1.726 raeburn 16228: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16229: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16230: if ($symb eq '') {
16231: if (!$silent) {
1.1071 raeburn 16232: if (ref($request)) {
16233: $request->print("Unable to handle ambiguous references:$url:.");
16234: }
1.685 tempelho 16235: return ();
16236: }
16237: }
16238: &Apache::lonenc::check_decrypt(\$symb);
16239: return ($symb);
16240: }
16241:
16242: # --------------------------------------------------------------Get annotation
16243:
16244: sub get_annotation {
16245: my ($symb,$enc) = @_;
16246:
16247: my $key = $symb;
16248: if (!$enc) {
16249: $key =
16250: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16251: }
16252: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16253: return $annotation{$key};
16254: }
16255:
16256: sub clean_symb {
1.731 raeburn 16257: my ($symb,$delete_enc) = @_;
1.685 tempelho 16258:
16259: &Apache::lonenc::check_decrypt(\$symb);
16260: my $enc = $env{'request.enc'};
1.731 raeburn 16261: if ($delete_enc) {
1.730 raeburn 16262: delete($env{'request.enc'});
16263: }
1.685 tempelho 16264:
16265: return ($symb,$enc);
16266: }
1.462 albertel 16267:
1.1181 raeburn 16268: ############################################################
16269: ############################################################
16270:
16271: =pod
16272:
16273: =head1 Routines for building display used to search for courses
16274:
16275:
16276: =over 4
16277:
16278: =item * &build_filters()
16279:
16280: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 16281: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16282: and quotacheck.pl
16283:
1.1181 raeburn 16284:
16285: Inputs:
16286:
16287: filterlist - anonymous array of fields to include as potential filters
16288:
16289: crstype - course type
16290:
16291: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16292: to pop-open a course selector (will contain "extra element").
16293:
16294: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16295:
16296: filter - anonymous hash of criteria and their values
16297:
16298: action - form action
16299:
16300: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16301:
1.1182 raeburn 16302: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 16303:
16304: cloneruname - username of owner of new course who wants to clone
16305:
16306: clonerudom - domain of owner of new course who wants to clone
16307:
16308: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16309:
16310: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16311:
16312: codedom - domain
16313:
16314: formname - value of form element named "form".
16315:
16316: fixeddom - domain, if fixed.
16317:
16318: prevphase - value to assign to form element named "phase" when going back to the previous screen
16319:
16320: cnameelement - name of form element in form on opener page which will receive title of selected course
16321:
16322: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16323:
16324: cdomelement - name of form element in form on opener page which will receive domain of selected course
16325:
16326: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16327:
16328: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16329:
16330: clonewarning - warning message about missing information for intended course owner when DC creates a course
16331:
1.1182 raeburn 16332:
1.1181 raeburn 16333: Returns: $output - HTML for display of search criteria, and hidden form elements.
16334:
1.1182 raeburn 16335:
1.1181 raeburn 16336: Side Effects: None
16337:
16338: =cut
16339:
16340: # ---------------------------------------------- search for courses based on last activity etc.
16341:
16342: sub build_filters {
16343: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16344: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16345: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16346: $cnameelement,$cnumelement,$cdomelement,$setroles,
16347: $clonetext,$clonewarning) = @_;
1.1182 raeburn 16348: my ($list,$jscript);
1.1181 raeburn 16349: my $onchange = 'javascript:updateFilters(this)';
16350: my ($domainselectform,$sincefilterform,$createdfilterform,
16351: $ownerdomselectform,$persondomselectform,$instcodeform,
16352: $typeselectform,$instcodetitle);
16353: if ($formname eq '') {
16354: $formname = $caller;
16355: }
16356: foreach my $item (@{$filterlist}) {
16357: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16358: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16359: if ($item eq 'domainfilter') {
16360: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16361: } elsif ($item eq 'coursefilter') {
16362: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16363: } elsif ($item eq 'ownerfilter') {
16364: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16365: } elsif ($item eq 'ownerdomfilter') {
16366: $filter->{'ownerdomfilter'} =
16367: &LONCAPA::clean_domain($filter->{$item});
16368: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16369: 'ownerdomfilter',1);
16370: } elsif ($item eq 'personfilter') {
16371: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16372: } elsif ($item eq 'persondomfilter') {
16373: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16374: 'persondomfilter',1);
16375: } else {
16376: $filter->{$item} =~ s/\W//g;
16377: }
16378: if (!$filter->{$item}) {
16379: $filter->{$item} = '';
16380: }
16381: }
16382: if ($item eq 'domainfilter') {
16383: my $allow_blank = 1;
16384: if ($formname eq 'portform') {
16385: $allow_blank=0;
16386: } elsif ($formname eq 'studentform') {
16387: $allow_blank=0;
16388: }
16389: if ($fixeddom) {
16390: $domainselectform = '<input type="hidden" name="domainfilter"'.
16391: ' value="'.$codedom.'" />'.
16392: &Apache::lonnet::domain($codedom,'description');
16393: } else {
16394: $domainselectform = &select_dom_form($filter->{$item},
16395: 'domainfilter',
16396: $allow_blank,'',$onchange);
16397: }
16398: } else {
16399: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16400: }
16401: }
16402:
16403: # last course activity filter and selection
16404: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16405:
16406: # course created filter and selection
16407: if (exists($filter->{'createdfilter'})) {
16408: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16409: }
16410:
1.1239 raeburn 16411: my $prefix = $crstype;
16412: if ($crstype eq 'Placement') {
16413: $prefix = 'Placement Test'
16414: }
1.1181 raeburn 16415: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 16416: 'cac' => "$prefix Activity",
16417: 'ccr' => "$prefix Created",
16418: 'cde' => "$prefix Title",
16419: 'cdo' => "$prefix Domain",
1.1181 raeburn 16420: 'ins' => 'Institutional Code',
16421: 'inc' => 'Institutional Categorization',
1.1239 raeburn 16422: 'cow' => "$prefix Owner/Co-owner",
16423: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 16424: 'cog' => 'Type',
16425: );
16426:
16427: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16428: my $typeval = 'Course';
16429: if ($crstype eq 'Community') {
16430: $typeval = 'Community';
1.1239 raeburn 16431: } elsif ($crstype eq 'Placement') {
16432: $typeval = 'Placement';
1.1181 raeburn 16433: }
16434: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16435: } else {
16436: $typeselectform = '<select name="type" size="1"';
16437: if ($onchange) {
16438: $typeselectform .= ' onchange="'.$onchange.'"';
16439: }
16440: $typeselectform .= '>'."\n";
1.1237 raeburn 16441: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 16442: my $shown;
16443: if ($posstype eq 'Placement') {
16444: $shown = &mt('Placement Test');
16445: } else {
16446: $shown = &mt($posstype);
16447: }
1.1181 raeburn 16448: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 16449: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 16450: }
16451: $typeselectform.="</select>";
16452: }
16453:
16454: my ($cloneableonlyform,$cloneabletitle);
16455: if (exists($filter->{'cloneableonly'})) {
16456: my $cloneableon = '';
16457: my $cloneableoff = ' checked="checked"';
16458: if ($filter->{'cloneableonly'}) {
16459: $cloneableon = $cloneableoff;
16460: $cloneableoff = '';
16461: }
16462: $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>';
16463: if ($formname eq 'ccrs') {
1.1187 bisitz 16464: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 16465: } else {
16466: $cloneabletitle = &mt('Cloneable by you');
16467: }
16468: }
16469: my $officialjs;
16470: if ($crstype eq 'Course') {
16471: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 16472: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16473: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16474: if ($codedom) {
1.1181 raeburn 16475: $officialjs = 1;
16476: ($instcodeform,$jscript,$$numtitlesref) =
16477: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16478: $officialjs,$codetitlesref);
16479: if ($jscript) {
1.1182 raeburn 16480: $jscript = '<script type="text/javascript">'."\n".
16481: '// <![CDATA['."\n".
16482: $jscript."\n".
16483: '// ]]>'."\n".
16484: '</script>'."\n";
1.1181 raeburn 16485: }
16486: }
16487: if ($instcodeform eq '') {
16488: $instcodeform =
16489: '<input type="text" name="instcodefilter" size="10" value="'.
16490: $list->{'instcodefilter'}.'" />';
16491: $instcodetitle = $lt{'ins'};
16492: } else {
16493: $instcodetitle = $lt{'inc'};
16494: }
16495: if ($fixeddom) {
16496: $instcodetitle .= '<br />('.$codedom.')';
16497: }
16498: }
16499: }
16500: my $output = qq|
16501: <form method="post" name="filterpicker" action="$action">
16502: <input type="hidden" name="form" value="$formname" />
16503: |;
16504: if ($formname eq 'modifycourse') {
16505: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16506: '<input type="hidden" name="prevphase" value="'.
16507: $prevphase.'" />'."\n";
1.1198 musolffc 16508: } elsif ($formname eq 'quotacheck') {
16509: $output .= qq|
16510: <input type="hidden" name="sortby" value="" />
16511: <input type="hidden" name="sortorder" value="" />
16512: |;
16513: } else {
1.1181 raeburn 16514: my $name_input;
16515: if ($cnameelement ne '') {
16516: $name_input = '<input type="hidden" name="cnameelement" value="'.
16517: $cnameelement.'" />';
16518: }
16519: $output .= qq|
1.1182 raeburn 16520: <input type="hidden" name="cnumelement" value="$cnumelement" />
16521: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 16522: $name_input
16523: $roleelement
16524: $multelement
16525: $typeelement
16526: |;
16527: if ($formname eq 'portform') {
16528: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16529: }
16530: }
16531: if ($fixeddom) {
16532: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16533: }
16534: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16535: if ($sincefilterform) {
16536: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16537: .$sincefilterform
16538: .&Apache::lonhtmlcommon::row_closure();
16539: }
16540: if ($createdfilterform) {
16541: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16542: .$createdfilterform
16543: .&Apache::lonhtmlcommon::row_closure();
16544: }
16545: if ($domainselectform) {
16546: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16547: .$domainselectform
16548: .&Apache::lonhtmlcommon::row_closure();
16549: }
16550: if ($typeselectform) {
16551: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16552: $output .= $typeselectform;
16553: } else {
16554: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16555: .$typeselectform
16556: .&Apache::lonhtmlcommon::row_closure();
16557: }
16558: }
16559: if ($instcodeform) {
16560: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16561: .$instcodeform
16562: .&Apache::lonhtmlcommon::row_closure();
16563: }
16564: if (exists($filter->{'ownerfilter'})) {
16565: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16566: '<table><tr><td>'.&mt('Username').'<br />'.
16567: '<input type="text" name="ownerfilter" size="20" value="'.
16568: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16569: $ownerdomselectform.'</td></tr></table>'.
16570: &Apache::lonhtmlcommon::row_closure();
16571: }
16572: if (exists($filter->{'personfilter'})) {
16573: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16574: '<table><tr><td>'.&mt('Username').'<br />'.
16575: '<input type="text" name="personfilter" size="20" value="'.
16576: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16577: $persondomselectform.'</td></tr></table>'.
16578: &Apache::lonhtmlcommon::row_closure();
16579: }
16580: if (exists($filter->{'coursefilter'})) {
16581: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16582: .'<input type="text" name="coursefilter" size="25" value="'
16583: .$list->{'coursefilter'}.'" />'
16584: .&Apache::lonhtmlcommon::row_closure();
16585: }
16586: if ($cloneableonlyform) {
16587: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16588: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16589: }
16590: if (exists($filter->{'descriptfilter'})) {
16591: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16592: .'<input type="text" name="descriptfilter" size="40" value="'
16593: .$list->{'descriptfilter'}.'" />'
16594: .&Apache::lonhtmlcommon::row_closure(1);
16595: }
16596: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16597: '<input type="hidden" name="updater" value="" />'."\n".
16598: '<input type="submit" name="gosearch" value="'.
16599: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16600: return $jscript.$clonewarning.$output;
16601: }
16602:
16603: =pod
16604:
16605: =item * &timebased_select_form()
16606:
1.1182 raeburn 16607: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 16608: filter e.g., Course Activity, Course Created, when searching for courses
16609: or communities
16610:
16611: Inputs:
16612:
16613: item - name of form element (sincefilter or createdfilter)
16614:
16615: filter - anonymous hash of criteria and their values
16616:
16617: Returns: HTML for a select box contained a blank, then six time selections,
16618: with value set in incoming form variables currently selected.
16619:
16620: Side Effects: None
16621:
16622: =cut
16623:
16624: sub timebased_select_form {
16625: my ($item,$filter) = @_;
16626: if (ref($filter) eq 'HASH') {
16627: $filter->{$item} =~ s/[^\d-]//g;
16628: if (!$filter->{$item}) { $filter->{$item}=-1; }
16629: return &select_form(
16630: $filter->{$item},
16631: $item,
16632: { '-1' => '',
16633: '86400' => &mt('today'),
16634: '604800' => &mt('last week'),
16635: '2592000' => &mt('last month'),
16636: '7776000' => &mt('last three months'),
16637: '15552000' => &mt('last six months'),
16638: '31104000' => &mt('last year'),
16639: 'select_form_order' =>
16640: ['-1','86400','604800','2592000','7776000',
16641: '15552000','31104000']});
16642: }
16643: }
16644:
16645: =pod
16646:
16647: =item * &js_changer()
16648:
16649: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 16650: when course type or domain is changed, and also to hide 'Searching ...' on
16651: page load completion for page showing search result.
1.1181 raeburn 16652:
16653: Inputs: None
16654:
1.1183 raeburn 16655: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 16656:
16657: Side Effects: None
16658:
16659: =cut
16660:
16661: sub js_changer {
16662: return <<ENDJS;
16663: <script type="text/javascript">
16664: // <![CDATA[
16665: function updateFilters(caller) {
16666: if (typeof(caller) != "undefined") {
16667: document.filterpicker.updater.value = caller.name;
16668: }
16669: document.filterpicker.submit();
16670: }
1.1183 raeburn 16671:
16672: function hideSearching() {
16673: if (document.getElementById('searching')) {
16674: document.getElementById('searching').style.display = 'none';
16675: }
16676: return;
16677: }
16678:
1.1181 raeburn 16679: // ]]>
16680: </script>
16681:
16682: ENDJS
16683: }
16684:
16685: =pod
16686:
1.1182 raeburn 16687: =item * &search_courses()
16688:
16689: Process selected filters form course search form and pass to lonnet::courseiddump
16690: to retrieve a hash for which keys are courseIDs which match the selected filters.
16691:
16692: Inputs:
16693:
16694: dom - domain being searched
16695:
16696: type - course type ('Course' or 'Community' or '.' if any).
16697:
16698: filter - anonymous hash of criteria and their values
16699:
16700: numtitles - for institutional codes - number of categories
16701:
16702: cloneruname - optional username of new course owner
16703:
16704: clonerudom - optional domain of new course owner
16705:
1.1221 raeburn 16706: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 16707: (used when DC is using course creation form)
16708:
16709: codetitles - reference to array of titles of components in institutional codes (official courses).
16710:
1.1221 raeburn 16711: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16712: (and so can clone automatically)
16713:
16714: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16715:
16716: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16717: courses to clone
1.1182 raeburn 16718:
16719: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16720:
16721:
16722: Side Effects: None
16723:
16724: =cut
16725:
16726:
16727: sub search_courses {
1.1221 raeburn 16728: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16729: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 16730: my (%courses,%showcourses,$cloner);
16731: if (($filter->{'ownerfilter'} ne '') ||
16732: ($filter->{'ownerdomfilter'} ne '')) {
16733: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16734: $filter->{'ownerdomfilter'};
16735: }
16736: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16737: if (!$filter->{$item}) {
16738: $filter->{$item}='.';
16739: }
16740: }
16741: my $now = time;
16742: my $timefilter =
16743: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16744: my ($createdbefore,$createdafter);
16745: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16746: $createdbefore = $now;
16747: $createdafter = $now-$filter->{'createdfilter'};
16748: }
16749: my ($instcodefilter,$regexpok);
16750: if ($numtitles) {
16751: if ($env{'form.official'} eq 'on') {
16752: $instcodefilter =
16753: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16754: $regexpok = 1;
16755: } elsif ($env{'form.official'} eq 'off') {
16756: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16757: unless ($instcodefilter eq '') {
16758: $regexpok = -1;
16759: }
16760: }
16761: } else {
16762: $instcodefilter = $filter->{'instcodefilter'};
16763: }
16764: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16765: if ($type eq '') { $type = '.'; }
16766:
16767: if (($clonerudom ne '') && ($cloneruname ne '')) {
16768: $cloner = $cloneruname.':'.$clonerudom;
16769: }
16770: %courses = &Apache::lonnet::courseiddump($dom,
16771: $filter->{'descriptfilter'},
16772: $timefilter,
16773: $instcodefilter,
16774: $filter->{'combownerfilter'},
16775: $filter->{'coursefilter'},
16776: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 16777: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 16778: $filter->{'cloneableonly'},
16779: $createdbefore,$createdafter,undef,
1.1221 raeburn 16780: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 16781: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16782: my $ccrole;
16783: if ($type eq 'Community') {
16784: $ccrole = 'co';
16785: } else {
16786: $ccrole = 'cc';
16787: }
16788: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16789: $filter->{'persondomfilter'},
16790: 'userroles',undef,
16791: [$ccrole,'in','ad','ep','ta','cr'],
16792: $dom);
16793: foreach my $role (keys(%rolehash)) {
16794: my ($cnum,$cdom,$courserole) = split(':',$role);
16795: my $cid = $cdom.'_'.$cnum;
16796: if (exists($courses{$cid})) {
16797: if (ref($courses{$cid}) eq 'HASH') {
16798: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16799: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 16800: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 16801: }
16802: } else {
16803: $courses{$cid}{roles} = [$courserole];
16804: }
16805: $showcourses{$cid} = $courses{$cid};
16806: }
16807: }
16808: }
16809: %courses = %showcourses;
16810: }
16811: return %courses;
16812: }
16813:
16814: =pod
16815:
1.1181 raeburn 16816: =back
16817:
1.1207 raeburn 16818: =head1 Routines for version requirements for current course.
16819:
16820: =over 4
16821:
16822: =item * &check_release_required()
16823:
16824: Compares required LON-CAPA version with version on server, and
16825: if required version is newer looks for a server with the required version.
16826:
16827: Looks first at servers in user's owen domain; if none suitable, looks at
16828: servers in course's domain are permitted to host sessions for user's domain.
16829:
16830: Inputs:
16831:
16832: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16833:
16834: $courseid - Course ID of current course
16835:
16836: $rolecode - User's current role in course (for switchserver query string).
16837:
16838: $required - LON-CAPA version needed by course (format: Major.Minor).
16839:
16840:
16841: Returns:
16842:
16843: $switchserver - query string tp append to /adm/switchserver call (if
16844: current server's LON-CAPA version is too old.
16845:
16846: $warning - Message is displayed if no suitable server could be found.
16847:
16848: =cut
16849:
16850: sub check_release_required {
16851: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16852: my ($switchserver,$warning);
16853: if ($required ne '') {
16854: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16855: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16856: if ($reqdmajor ne '' && $reqdminor ne '') {
16857: my $otherserver;
16858: if (($major eq '' && $minor eq '') ||
16859: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16860: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16861: my $switchlcrev =
16862: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16863: $userdomserver);
16864: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16865: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16866: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16867: my $cdom = $env{'course.'.$courseid.'.domain'};
16868: if ($cdom ne $env{'user.domain'}) {
16869: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16870: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16871: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16872: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16873: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16874: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16875: my $canhost =
16876: &Apache::lonnet::can_host_session($env{'user.domain'},
16877: $coursedomserver,
16878: $remoterev,
16879: $udomdefaults{'remotesessions'},
16880: $defdomdefaults{'hostedsessions'});
16881:
16882: if ($canhost) {
16883: $otherserver = $coursedomserver;
16884: } else {
16885: $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.");
16886: }
16887: } else {
16888: $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).");
16889: }
16890: } else {
16891: $otherserver = $userdomserver;
16892: }
16893: }
16894: if ($otherserver ne '') {
16895: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16896: }
16897: }
16898: }
16899: return ($switchserver,$warning);
16900: }
16901:
16902: =pod
16903:
16904: =item * &check_release_result()
16905:
16906: Inputs:
16907:
16908: $switchwarning - Warning message if no suitable server found to host session.
16909:
16910: $switchserver - query string to append to /adm/switchserver containing lonHostID
16911: and current role.
16912:
16913: Returns: HTML to display with information about requirement to switch server.
16914: Either displaying warning with link to Roles/Courses screen or
16915: display link to switchserver.
16916:
1.1181 raeburn 16917: =cut
16918:
1.1207 raeburn 16919: sub check_release_result {
16920: my ($switchwarning,$switchserver) = @_;
16921: my $output = &start_page('Selected course unavailable on this server').
16922: '<p class="LC_warning">';
16923: if ($switchwarning) {
16924: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16925: if (&show_course()) {
16926: $output .= &mt('Display courses');
16927: } else {
16928: $output .= &mt('Display roles');
16929: }
16930: $output .= '</a>';
16931: } elsif ($switchserver) {
16932: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16933: '<br />'.
16934: '<a href="/adm/switchserver?'.$switchserver.'">'.
16935: &mt('Switch Server').
16936: '</a>';
16937: }
16938: $output .= '</p>'.&end_page();
16939: return $output;
16940: }
16941:
16942: =pod
16943:
16944: =item * &needs_coursereinit()
16945:
16946: Determine if course contents stored for user's session needs to be
16947: refreshed, because content has changed since "Big Hash" last tied.
16948:
16949: Check for change is made if time last checked is more than 10 minutes ago
16950: (by default).
16951:
16952: Inputs:
16953:
16954: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16955:
16956: $interval (optional) - Time which may elapse (in s) between last check for content
16957: change in current course. (default: 600 s).
16958:
16959: Returns: an array; first element is:
16960:
16961: =over 4
16962:
16963: 'switch' - if content updates mean user's session
16964: needs to be switched to a server running a newer LON-CAPA version
16965:
16966: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16967: on current server hosting user's session
16968:
16969: '' - if no action required.
16970:
16971: =back
16972:
16973: If first item element is 'switch':
16974:
16975: second item is $switchwarning - Warning message if no suitable server found to host session.
16976:
16977: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16978: and current role.
16979:
16980: otherwise: no other elements returned.
16981:
16982: =back
16983:
16984: =cut
16985:
16986: sub needs_coursereinit {
16987: my ($loncaparev,$interval) = @_;
16988: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16989: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16990: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16991: my $now = time;
16992: if ($interval eq '') {
16993: $interval = 600;
16994: }
16995: if (($now-$env{'request.course.timechecked'})>$interval) {
16996: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16997: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16998: if ($lastchange > $env{'request.course.tied'}) {
16999: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17000: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
17001: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
17002: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
17003: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
17004: $curr_reqd_hash{'internal.releaserequired'}});
17005: my ($switchserver,$switchwarning) =
17006: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
17007: $curr_reqd_hash{'internal.releaserequired'});
17008: if ($switchwarning ne '' || $switchserver ne '') {
17009: return ('switch',$switchwarning,$switchserver);
17010: }
17011: }
17012: }
17013: return ('update');
17014: }
17015: }
17016: return ();
17017: }
1.1181 raeburn 17018:
1.1083 raeburn 17019: sub update_content_constraints {
17020: my ($cdom,$cnum,$chome,$cid) = @_;
17021: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17022: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
17023: my %checkresponsetypes;
17024: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 17025: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 17026: if ($item eq 'resourcetag') {
17027: if ($name eq 'responsetype') {
17028: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17029: }
17030: }
17031: }
17032: my $navmap = Apache::lonnavmaps::navmap->new();
17033: if (defined($navmap)) {
17034: my %allresponses;
17035: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
17036: my %responses = $res->responseTypes();
17037: foreach my $key (keys(%responses)) {
17038: next unless(exists($checkresponsetypes{$key}));
17039: $allresponses{$key} += $responses{$key};
17040: }
17041: }
17042: foreach my $key (keys(%allresponses)) {
17043: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17044: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17045: ($reqdmajor,$reqdminor) = ($major,$minor);
17046: }
17047: }
17048: undef($navmap);
17049: }
17050: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17051: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17052: }
17053: return;
17054: }
17055:
1.1110 raeburn 17056: sub allmaps_incourse {
17057: my ($cdom,$cnum,$chome,$cid) = @_;
17058: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17059: $cid = $env{'request.course.id'};
17060: $cdom = $env{'course.'.$cid.'.domain'};
17061: $cnum = $env{'course.'.$cid.'.num'};
17062: $chome = $env{'course.'.$cid.'.home'};
17063: }
17064: my %allmaps = ();
17065: my $lastchange =
17066: &Apache::lonnet::get_coursechange($cdom,$cnum);
17067: if ($lastchange > $env{'request.course.tied'}) {
17068: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17069: unless ($ferr) {
17070: &update_content_constraints($cdom,$cnum,$chome,$cid);
17071: }
17072: }
17073: my $navmap = Apache::lonnavmaps::navmap->new();
17074: if (defined($navmap)) {
17075: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17076: $allmaps{$res->src()} = 1;
17077: }
17078: }
17079: return \%allmaps;
17080: }
17081:
1.1083 raeburn 17082: sub parse_supplemental_title {
17083: my ($title) = @_;
17084:
17085: my ($foldertitle,$renametitle);
17086: if ($title =~ /&&&/) {
17087: $title = &HTML::Entites::decode($title);
17088: }
17089: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17090: $renametitle=$4;
17091: my ($time,$uname,$udom) = ($1,$2,$3);
17092: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17093: my $name = &plainname($uname,$udom);
17094: $name = &HTML::Entities::encode($name,'"<>&\'');
17095: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17096: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17097: $name.': <br />'.$foldertitle;
17098: }
17099: if (wantarray) {
17100: return ($title,$foldertitle,$renametitle);
17101: }
17102: return $title;
17103: }
17104:
1.1143 raeburn 17105: sub recurse_supplemental {
17106: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
17107: if ($suppmap) {
17108: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17109: if ($fatal) {
17110: $errors ++;
17111: } else {
17112: if ($#LONCAPA::map::resources > 0) {
17113: foreach my $res (@LONCAPA::map::resources) {
17114: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17115: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 17116: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
17117: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1143 raeburn 17118: } else {
17119: $numfiles ++;
17120: }
17121: }
17122: }
17123: }
17124: }
17125: }
17126: return ($numfiles,$errors);
17127: }
17128:
1.1101 raeburn 17129: sub symb_to_docspath {
1.1267 raeburn 17130: my ($symb,$navmapref) = @_;
17131: return unless ($symb && ref($navmapref));
1.1101 raeburn 17132: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17133: if ($resurl=~/\.(sequence|page)$/) {
17134: $mapurl=$resurl;
17135: } elsif ($resurl eq 'adm/navmaps') {
17136: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17137: }
17138: my $mapresobj;
1.1267 raeburn 17139: unless (ref($$navmapref)) {
17140: $$navmapref = Apache::lonnavmaps::navmap->new();
17141: }
17142: if (ref($$navmapref)) {
17143: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 17144: }
17145: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17146: my $type=$2;
17147: my $path;
17148: if (ref($mapresobj)) {
17149: my $pcslist = $mapresobj->map_hierarchy();
17150: if ($pcslist ne '') {
17151: foreach my $pc (split(/,/,$pcslist)) {
17152: next if ($pc <= 1);
1.1267 raeburn 17153: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 17154: if (ref($res)) {
17155: my $thisurl = $res->src();
17156: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17157: my $thistitle = $res->title();
17158: $path .= '&'.
17159: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 17160: &escape($thistitle).
1.1101 raeburn 17161: ':'.$res->randompick().
17162: ':'.$res->randomout().
17163: ':'.$res->encrypted().
17164: ':'.$res->randomorder().
17165: ':'.$res->is_page();
17166: }
17167: }
17168: }
17169: $path =~ s/^\&//;
17170: my $maptitle = $mapresobj->title();
17171: if ($mapurl eq 'default') {
1.1129 raeburn 17172: $maptitle = 'Main Content';
1.1101 raeburn 17173: }
17174: $path .= (($path ne '')? '&' : '').
17175: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17176: &escape($maptitle).
1.1101 raeburn 17177: ':'.$mapresobj->randompick().
17178: ':'.$mapresobj->randomout().
17179: ':'.$mapresobj->encrypted().
17180: ':'.$mapresobj->randomorder().
17181: ':'.$mapresobj->is_page();
17182: } else {
17183: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17184: my $ispage = (($type eq 'page')? 1 : '');
17185: if ($mapurl eq 'default') {
1.1129 raeburn 17186: $maptitle = 'Main Content';
1.1101 raeburn 17187: }
17188: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17189: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 17190: }
17191: unless ($mapurl eq 'default') {
17192: $path = 'default&'.
1.1146 raeburn 17193: &escape('Main Content').
1.1101 raeburn 17194: ':::::&'.$path;
17195: }
17196: return $path;
17197: }
17198:
1.1094 raeburn 17199: sub captcha_display {
17200: my ($context,$lonhost) = @_;
17201: my ($output,$error);
1.1234 raeburn 17202: my ($captcha,$pubkey,$privkey,$version) =
17203: &get_captcha_config($context,$lonhost);
1.1095 raeburn 17204: if ($captcha eq 'original') {
1.1094 raeburn 17205: $output = &create_captcha();
17206: unless ($output) {
1.1172 raeburn 17207: $error = 'captcha';
1.1094 raeburn 17208: }
17209: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17210: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 17211: unless ($output) {
1.1172 raeburn 17212: $error = 'recaptcha';
1.1094 raeburn 17213: }
17214: }
1.1234 raeburn 17215: return ($output,$error,$captcha,$version);
1.1094 raeburn 17216: }
17217:
17218: sub captcha_response {
17219: my ($context,$lonhost) = @_;
17220: my ($captcha_chk,$captcha_error);
1.1234 raeburn 17221: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 17222: if ($captcha eq 'original') {
1.1094 raeburn 17223: ($captcha_chk,$captcha_error) = &check_captcha();
17224: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17225: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 17226: } else {
17227: $captcha_chk = 1;
17228: }
17229: return ($captcha_chk,$captcha_error);
17230: }
17231:
17232: sub get_captcha_config {
17233: my ($context,$lonhost) = @_;
1.1234 raeburn 17234: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 17235: my $hostname = &Apache::lonnet::hostname($lonhost);
17236: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17237: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 17238: if ($context eq 'usercreation') {
17239: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17240: if (ref($domconfig{$context}) eq 'HASH') {
17241: $hashtocheck = $domconfig{$context}{'cancreate'};
17242: if (ref($hashtocheck) eq 'HASH') {
17243: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17244: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17245: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17246: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17247: }
17248: if ($privkey && $pubkey) {
17249: $captcha = 'recaptcha';
1.1234 raeburn 17250: $version = $hashtocheck->{'recaptchaversion'};
17251: if ($version ne '2') {
17252: $version = 1;
17253: }
1.1095 raeburn 17254: } else {
17255: $captcha = 'original';
17256: }
17257: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17258: $captcha = 'original';
17259: }
1.1094 raeburn 17260: }
1.1095 raeburn 17261: } else {
17262: $captcha = 'captcha';
17263: }
17264: } elsif ($context eq 'login') {
17265: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17266: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17267: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17268: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 17269: if ($privkey && $pubkey) {
17270: $captcha = 'recaptcha';
1.1234 raeburn 17271: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17272: if ($version ne '2') {
17273: $version = 1;
17274: }
1.1095 raeburn 17275: } else {
17276: $captcha = 'original';
1.1094 raeburn 17277: }
1.1095 raeburn 17278: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17279: $captcha = 'original';
1.1094 raeburn 17280: }
17281: }
1.1234 raeburn 17282: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 17283: }
17284:
17285: sub create_captcha {
17286: my %captcha_params = &captcha_settings();
17287: my ($output,$maxtries,$tries) = ('',10,0);
17288: while ($tries < $maxtries) {
17289: $tries ++;
17290: my $captcha = Authen::Captcha->new (
17291: output_folder => $captcha_params{'output_dir'},
17292: data_folder => $captcha_params{'db_dir'},
17293: );
17294: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17295:
17296: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17297: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17298: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 17299: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17300: '<br />'.
17301: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 17302: last;
17303: }
17304: }
17305: return $output;
17306: }
17307:
17308: sub captcha_settings {
17309: my %captcha_params = (
17310: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17311: www_output_dir => "/captchaspool",
17312: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17313: numchars => '5',
17314: );
17315: return %captcha_params;
17316: }
17317:
17318: sub check_captcha {
17319: my ($captcha_chk,$captcha_error);
17320: my $code = $env{'form.code'};
17321: my $md5sum = $env{'form.crypt'};
17322: my %captcha_params = &captcha_settings();
17323: my $captcha = Authen::Captcha->new(
17324: output_folder => $captcha_params{'output_dir'},
17325: data_folder => $captcha_params{'db_dir'},
17326: );
1.1109 raeburn 17327: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 17328: my %captcha_hash = (
17329: 0 => 'Code not checked (file error)',
17330: -1 => 'Failed: code expired',
17331: -2 => 'Failed: invalid code (not in database)',
17332: -3 => 'Failed: invalid code (code does not match crypt)',
17333: );
17334: if ($captcha_chk != 1) {
17335: $captcha_error = $captcha_hash{$captcha_chk}
17336: }
17337: return ($captcha_chk,$captcha_error);
17338: }
17339:
17340: sub create_recaptcha {
1.1234 raeburn 17341: my ($pubkey,$version) = @_;
17342: if ($version >= 2) {
17343: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17344: } else {
17345: my $use_ssl;
17346: if ($ENV{'SERVER_PORT'} == 443) {
17347: $use_ssl = 1;
17348: }
17349: my $captcha = Captcha::reCAPTCHA->new;
17350: return $captcha->get_options_setter({theme => 'white'})."\n".
17351: $captcha->get_html($pubkey,undef,$use_ssl).
17352: &mt('If the text is hard to read, [_1] will replace them.',
17353: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17354: '<br /><br />';
17355: }
1.1094 raeburn 17356: }
17357:
17358: sub check_recaptcha {
1.1234 raeburn 17359: my ($privkey,$version) = @_;
1.1094 raeburn 17360: my $captcha_chk;
1.1234 raeburn 17361: if ($version >= 2) {
17362: my %info = (
17363: secret => $privkey,
17364: response => $env{'form.g-recaptcha-response'},
17365: remoteip => $ENV{'REMOTE_ADDR'},
17366: );
1.1280 raeburn 17367: my $request=new HTTP::Request('POST','https://www.google.com/recaptcha/api/siteverify');
17368: $request->content(join('&',map {
17369: my $name = escape($_);
17370: "$name=" . ( ref($info{$_}) eq 'ARRAY'
17371: ? join("&$name=", map {escape($_) } @{$info{$_}})
17372: : &escape($info{$_}) );
17373: } keys(%info)));
17374: my $response = &LONCAPA::LWPReq::makerequest('',$request,'','',10,1);
1.1234 raeburn 17375: if ($response->is_success) {
17376: my $data = JSON::DWIW->from_json($response->decoded_content);
17377: if (ref($data) eq 'HASH') {
17378: if ($data->{'success'}) {
17379: $captcha_chk = 1;
17380: }
17381: }
17382: }
17383: } else {
17384: my $captcha = Captcha::reCAPTCHA->new;
17385: my $captcha_result =
17386: $captcha->check_answer(
17387: $privkey,
17388: $ENV{'REMOTE_ADDR'},
17389: $env{'form.recaptcha_challenge_field'},
17390: $env{'form.recaptcha_response_field'},
17391: );
17392: if ($captcha_result->{is_valid}) {
17393: $captcha_chk = 1;
17394: }
1.1094 raeburn 17395: }
17396: return $captcha_chk;
17397: }
17398:
1.1174 raeburn 17399: sub emailusername_info {
1.1244 raeburn 17400: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 17401: my %titles = &Apache::lonlocal::texthash (
17402: lastname => 'Last Name',
17403: firstname => 'First Name',
17404: institution => 'School/college/university',
17405: location => "School's city, state/province, country",
17406: web => "School's web address",
17407: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 17408: id => 'Student/Employee ID',
1.1174 raeburn 17409: );
17410: return (\@fields,\%titles);
17411: }
17412:
1.1161 raeburn 17413: sub cleanup_html {
17414: my ($incoming) = @_;
17415: my $outgoing;
17416: if ($incoming ne '') {
17417: $outgoing = $incoming;
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: $outgoing =~ s/"/"/g;
17426: $outgoing =~ s/'/'/g;
17427: $outgoing =~ s/\$/$/g;
17428: $outgoing =~ s{/}{/}g;
17429: $outgoing =~ s/=/=/g;
17430: $outgoing =~ s/\\/\/g
17431: }
17432: return $outgoing;
17433: }
17434:
1.1190 musolffc 17435: # Checks for critical messages and returns a redirect url if one exists.
17436: # $interval indicates how often to check for messages.
17437: sub critical_redirect {
17438: my ($interval) = @_;
17439: if ((time-$env{'user.criticalcheck.time'})>$interval) {
17440: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17441: $env{'user.name'});
17442: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 17443: my $redirecturl;
1.1190 musolffc 17444: if ($what[0]) {
17445: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17446: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 17447: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17448: return (1, $url);
1.1190 musolffc 17449: }
1.1191 raeburn 17450: }
17451: }
17452: return ();
1.1190 musolffc 17453: }
17454:
1.1174 raeburn 17455: # Use:
17456: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17457: #
17458: ##################################################
17459: # password associated functions #
17460: ##################################################
17461: sub des_keys {
17462: # Make a new key for DES encryption.
17463: # Each key has two parts which are returned separately.
17464: # Please note: Each key must be passed through the &hex function
17465: # before it is output to the web browser. The hex versions cannot
17466: # be used to decrypt.
17467: my @hexstr=('0','1','2','3','4','5','6','7',
17468: '8','9','a','b','c','d','e','f');
17469: my $lkey='';
17470: for (0..7) {
17471: $lkey.=$hexstr[rand(15)];
17472: }
17473: my $ukey='';
17474: for (0..7) {
17475: $ukey.=$hexstr[rand(15)];
17476: }
17477: return ($lkey,$ukey);
17478: }
17479:
17480: sub des_decrypt {
17481: my ($key,$cyphertext) = @_;
17482: my $keybin=pack("H16",$key);
17483: my $cypher;
17484: if ($Crypt::DES::VERSION>=2.03) {
17485: $cypher=new Crypt::DES $keybin;
17486: } else {
17487: $cypher=new DES $keybin;
17488: }
1.1233 raeburn 17489: my $plaintext='';
17490: my $cypherlength = length($cyphertext);
17491: my $numchunks = int($cypherlength/32);
17492: for (my $j=0; $j<$numchunks; $j++) {
17493: my $start = $j*32;
17494: my $cypherblock = substr($cyphertext,$start,32);
17495: my $chunk =
17496: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17497: $chunk .=
17498: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17499: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17500: $plaintext .= $chunk;
17501: }
1.1174 raeburn 17502: return $plaintext;
17503: }
17504:
1.112 bowersj2 17505: 1;
17506: __END__;
1.41 ng 17507:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>