Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.107
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1075.2.107! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.106 2016/08/11 00:15:06 raeburn Exp $
1.10 albertel 5: #
6: # Copyright Michigan State University Board of Trustees
7: #
8: # This file is part of the LearningOnline Network with CAPA (LON-CAPA).
9: #
10: # LON-CAPA is free software; you can redistribute it and/or modify
11: # it under the terms of the GNU General Public License as published by
12: # the Free Software Foundation; either version 2 of the License, or
13: # (at your option) any later version.
14: #
15: # LON-CAPA is distributed in the hope that it will be useful,
16: # but WITHOUT ANY WARRANTY; without even the implied warranty of
17: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18: # GNU General Public License for more details.
19: #
20: # You should have received a copy of the GNU General Public License
21: # along with LON-CAPA; if not, write to the Free Software
22: # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23: #
24: # /home/httpd/html/adm/gpl.txt
25: #
26: # http://www.lon-capa.org/
27: #
1.1 albertel 28:
29: # Makes a table out of the previous attempts
1.2 albertel 30: # Inputs result_from_symbread, user, domain, course_id
1.16 harris41 31: # Reads in non-network-related .tab files
1.1 albertel 32:
1.35 matthew 33: # POD header:
34:
1.45 matthew 35: =pod
36:
1.35 matthew 37: =head1 NAME
38:
39: Apache::loncommon - pile of common routines
40:
41: =head1 SYNOPSIS
42:
1.112 bowersj2 43: Common routines for manipulating connections, student answers,
44: domains, common Javascript fragments, etc.
1.35 matthew 45:
1.112 bowersj2 46: =head1 OVERVIEW
1.35 matthew 47:
1.112 bowersj2 48: A collection of commonly used subroutines that don't have a natural
49: home anywhere else. This collection helps remove
1.35 matthew 50: redundancy from other modules and increase efficiency of memory usage.
51:
52: =cut
53:
54: # End of POD header
1.1 albertel 55: package Apache::loncommon;
56:
57: use strict;
1.258 albertel 58: use Apache::lonnet;
1.46 matthew 59: use GDBM_File;
1.51 www 60: use POSIX qw(strftime mktime);
1.82 www 61: use Apache::lonmenu();
1.498 albertel 62: use Apache::lonenc();
1.117 www 63: use Apache::lonlocal;
1.685 tempelho 64: use Apache::lonnet();
1.139 matthew 65: use HTML::Entities;
1.334 albertel 66: use Apache::lonhtmlcommon();
67: use Apache::loncoursedata();
1.344 albertel 68: use Apache::lontexconvert();
1.444 albertel 69: use Apache::lonclonecourse();
1.1075.2.25 raeburn 70: use Apache::lonuserutils();
1.1075.2.27 raeburn 71: use Apache::lonuserstate();
1.1075.2.69 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 74: use DateTime::TimeZone;
1.1075.2.102 raeburn 75: use DateTime::Locale;
1.1075.2.94 raeburn 76: use Encode();
1.1075.2.14 raeburn 77: use Authen::Captcha;
78: use Captcha::reCAPTCHA;
1.1075.2.107! raeburn 79: use JSON::DWIW;
! 80: use LWP::UserAgent;
1.1075.2.64 raeburn 81: use Crypt::DES;
82: use DynaLoader; # for Crypt::DES version
1.117 www 83:
1.517 raeburn 84: # ---------------------------------------------- Designs
85: use vars qw(%defaultdesign);
86:
1.22 www 87: my $readit;
88:
1.517 raeburn 89:
1.157 matthew 90: ##
91: ## Global Variables
92: ##
1.46 matthew 93:
1.643 foxr 94:
95: # ----------------------------------------------- SSI with retries:
96: #
97:
98: =pod
99:
1.648 raeburn 100: =head1 Server Side include with retries:
1.643 foxr 101:
102: =over 4
103:
1.648 raeburn 104: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 105:
106: Performs an ssi with some number of retries. Retries continue either
107: until the result is ok or until the retry count supplied by the
108: caller is exhausted.
109:
110: Inputs:
1.648 raeburn 111:
112: =over 4
113:
1.643 foxr 114: resource - Identifies the resource to insert.
1.648 raeburn 115:
1.643 foxr 116: retries - Count of the number of retries allowed.
1.648 raeburn 117:
1.643 foxr 118: form - Hash that identifies the rendering options.
119:
1.648 raeburn 120: =back
121:
122: Returns:
123:
124: =over 4
125:
1.643 foxr 126: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 127:
1.643 foxr 128: response - The response from the last attempt (which may or may not have been successful.
129:
1.648 raeburn 130: =back
131:
132: =back
133:
1.643 foxr 134: =cut
135:
136: sub ssi_with_retries {
137: my ($resource, $retries, %form) = @_;
138:
139:
140: my $ok = 0; # True if we got a good response.
141: my $content;
142: my $response;
143:
144: # Try to get the ssi done. within the retries count:
145:
146: do {
147: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
148: $ok = $response->is_success;
1.650 www 149: if (!$ok) {
150: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
151: }
1.643 foxr 152: $retries--;
153: } while (!$ok && ($retries > 0));
154:
155: if (!$ok) {
156: $content = ''; # On error return an empty content.
157: }
158: return ($content, $response);
159:
160: }
161:
162:
163:
1.20 www 164: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 165: my %language;
1.124 www 166: my %supported_language;
1.1048 foxr 167: my %latex_language; # For choosing hyphenation in <transl..>
168: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 169: my %cprtag;
1.192 taceyjo1 170: my %scprtag;
1.351 www 171: my %fe; my %fd; my %fm;
1.41 ng 172: my %category_extensions;
1.12 harris41 173:
1.46 matthew 174: # ---------------------------------------------- Thesaurus variables
1.144 matthew 175: #
176: # %Keywords:
177: # A hash used by &keyword to determine if a word is considered a keyword.
178: # $thesaurus_db_file
179: # Scalar containing the full path to the thesaurus database.
1.46 matthew 180:
181: my %Keywords;
182: my $thesaurus_db_file;
183:
1.144 matthew 184: #
185: # Initialize values from language.tab, copyright.tab, filetypes.tab,
186: # thesaurus.tab, and filecategories.tab.
187: #
1.18 www 188: BEGIN {
1.46 matthew 189: # Variable initialization
190: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
191: #
1.22 www 192: unless ($readit) {
1.12 harris41 193: # ------------------------------------------------------------------- languages
194: {
1.158 raeburn 195: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
196: '/language.tab';
197: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 198: while (my $line = <$fh>) {
199: next if ($line=~/^\#/);
200: chomp($line);
1.1048 foxr 201: my ($key,$two,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 202: $language{$key}=$val.' - '.$enc;
203: if ($sup) {
204: $supported_language{$key}=$sup;
205: }
1.1048 foxr 206: if ($latex) {
207: $latex_language_bykey{$key} = $latex;
208: $latex_language{$two} = $latex;
209: }
1.158 raeburn 210: }
211: close($fh);
212: }
1.12 harris41 213: }
214: # ------------------------------------------------------------------ copyrights
215: {
1.158 raeburn 216: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
217: '/copyright.tab';
218: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 219: while (my $line = <$fh>) {
220: next if ($line=~/^\#/);
221: chomp($line);
222: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 223: $cprtag{$key}=$val;
224: }
225: close($fh);
226: }
1.12 harris41 227: }
1.351 www 228: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 229: {
230: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
231: '/source_copyright.tab';
232: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 233: while (my $line = <$fh>) {
234: next if ($line =~ /^\#/);
235: chomp($line);
236: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 237: $scprtag{$key}=$val;
238: }
239: close($fh);
240: }
241: }
1.63 www 242:
1.517 raeburn 243: # -------------------------------------------------------------- default domain designs
1.63 www 244: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 245: my $designfile = $designdir.'/default.tab';
246: if ( open (my $fh,"<$designfile") ) {
247: while (my $line = <$fh>) {
248: next if ($line =~ /^\#/);
249: chomp($line);
250: my ($key,$val)=(split(/\=/,$line));
251: if ($val) { $defaultdesign{$key}=$val; }
252: }
253: close($fh);
1.63 www 254: }
255:
1.15 harris41 256: # ------------------------------------------------------------- file categories
257: {
1.158 raeburn 258: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
259: '/filecategories.tab';
260: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 261: while (my $line = <$fh>) {
262: next if ($line =~ /^\#/);
263: chomp($line);
264: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 265: push @{$category_extensions{lc($category)}},$extension;
266: }
267: close($fh);
268: }
269:
1.15 harris41 270: }
1.12 harris41 271: # ------------------------------------------------------------------ file types
272: {
1.158 raeburn 273: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
274: '/filetypes.tab';
275: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 276: while (my $line = <$fh>) {
277: next if ($line =~ /^\#/);
278: chomp($line);
279: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 280: if ($descr ne '') {
281: $fe{$ending}=lc($emb);
282: $fd{$ending}=$descr;
1.351 www 283: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 284: }
285: }
286: close($fh);
287: }
1.12 harris41 288: }
1.22 www 289: &Apache::lonnet::logthis(
1.705 tempelho 290: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 291: $readit=1;
1.46 matthew 292: } # end of unless($readit)
1.32 matthew 293:
294: }
1.112 bowersj2 295:
1.42 matthew 296: ###############################################################
297: ## HTML and Javascript Helper Functions ##
298: ###############################################################
299:
300: =pod
301:
1.112 bowersj2 302: =head1 HTML and Javascript Functions
1.42 matthew 303:
1.112 bowersj2 304: =over 4
305:
1.648 raeburn 306: =item * &browser_and_searcher_javascript()
1.112 bowersj2 307:
308: X<browsing, javascript>X<searching, javascript>Returns a string
309: containing javascript with two functions, C<openbrowser> and
310: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
311: tags.
1.42 matthew 312:
1.648 raeburn 313: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 314:
315: inputs: formname, elementname, only, omit
316:
317: formname and elementname indicate the name of the html form and name of
318: the element that the results of the browsing selection are to be placed in.
319:
320: Specifying 'only' will restrict the browser to displaying only files
1.185 www 321: with the given extension. Can be a comma separated list.
1.42 matthew 322:
323: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 324: with the given extension. Can be a comma separated list.
1.42 matthew 325:
1.648 raeburn 326: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 327:
328: Inputs: formname, elementname
329:
330: formname and elementname specify the name of the html form and the name
331: of the element the selection from the search results will be placed in.
1.542 raeburn 332:
1.42 matthew 333: =cut
334:
335: sub browser_and_searcher_javascript {
1.199 albertel 336: my ($mode)=@_;
337: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 338: my $resurl=&escape_single(&lastresurl());
1.42 matthew 339: return <<END;
1.219 albertel 340: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 341: var editbrowser = null;
1.135 albertel 342: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 343: var url = '$resurl/?';
1.42 matthew 344: if (editbrowser == null) {
345: url += 'launch=1&';
346: }
347: url += 'catalogmode=interactive&';
1.199 albertel 348: url += 'mode=$mode&';
1.611 albertel 349: url += 'inhibitmenu=yes&';
1.42 matthew 350: url += 'form=' + formname + '&';
351: if (only != null) {
352: url += 'only=' + only + '&';
1.217 albertel 353: } else {
354: url += 'only=&';
355: }
1.42 matthew 356: if (omit != null) {
357: url += 'omit=' + omit + '&';
1.217 albertel 358: } else {
359: url += 'omit=&';
360: }
1.135 albertel 361: if (titleelement != null) {
362: url += 'titleelement=' + titleelement + '&';
1.217 albertel 363: } else {
364: url += 'titleelement=&';
365: }
1.42 matthew 366: url += 'element=' + elementname + '';
367: var title = 'Browser';
1.435 albertel 368: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 369: options += ',width=700,height=600';
370: editbrowser = open(url,title,options,'1');
371: editbrowser.focus();
372: }
373: var editsearcher;
1.135 albertel 374: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 375: var url = '/adm/searchcat?';
376: if (editsearcher == null) {
377: url += 'launch=1&';
378: }
379: url += 'catalogmode=interactive&';
1.199 albertel 380: url += 'mode=$mode&';
1.42 matthew 381: url += 'form=' + formname + '&';
1.135 albertel 382: if (titleelement != null) {
383: url += 'titleelement=' + titleelement + '&';
1.217 albertel 384: } else {
385: url += 'titleelement=&';
386: }
1.42 matthew 387: url += 'element=' + elementname + '';
388: var title = 'Search';
1.435 albertel 389: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 390: options += ',width=700,height=600';
391: editsearcher = open(url,title,options,'1');
392: editsearcher.focus();
393: }
1.219 albertel 394: // END LON-CAPA Internal -->
1.42 matthew 395: END
1.170 www 396: }
397:
398: sub lastresurl {
1.258 albertel 399: if ($env{'environment.lastresurl'}) {
400: return $env{'environment.lastresurl'}
1.170 www 401: } else {
402: return '/res';
403: }
404: }
405:
406: sub storeresurl {
407: my $resurl=&Apache::lonnet::clutter(shift);
408: unless ($resurl=~/^\/res/) { return 0; }
409: $resurl=~s/\/$//;
410: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 411: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 412: return 1;
1.42 matthew 413: }
414:
1.74 www 415: sub studentbrowser_javascript {
1.111 www 416: unless (
1.258 albertel 417: (($env{'request.course.id'}) &&
1.302 albertel 418: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
419: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
420: '/'.$env{'request.course.sec'})
421: ))
1.258 albertel 422: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 423: ) { return ''; }
1.74 www 424: return (<<'ENDSTDBRW');
1.776 bisitz 425: <script type="text/javascript" language="Javascript">
1.824 bisitz 426: // <![CDATA[
1.74 www 427: var stdeditbrowser;
1.999 www 428: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 429: var url = '/adm/pickstudent?';
430: var filter;
1.558 albertel 431: if (!ignorefilter) {
432: eval('filter=document.'+formname+'.'+uname+'.value;');
433: }
1.74 www 434: if (filter != null) {
435: if (filter != '') {
436: url += 'filter='+filter+'&';
437: }
438: }
439: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 440: '&udomelement='+udom+
441: '&clicker='+clicker;
1.111 www 442: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 443: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 444: var title = 'Student_Browser';
1.74 www 445: var options = 'scrollbars=1,resizable=1,menubar=0';
446: options += ',width=700,height=600';
447: stdeditbrowser = open(url,title,options,'1');
448: stdeditbrowser.focus();
449: }
1.824 bisitz 450: // ]]>
1.74 www 451: </script>
452: ENDSTDBRW
453: }
1.42 matthew 454:
1.1003 www 455: sub resourcebrowser_javascript {
456: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 457: return (<<'ENDRESBRW');
1.1003 www 458: <script type="text/javascript" language="Javascript">
459: // <![CDATA[
460: var reseditbrowser;
1.1004 www 461: function openresbrowser(formname,reslink) {
1.1005 www 462: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 463: var title = 'Resource_Browser';
464: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 465: options += ',width=700,height=500';
1.1004 www 466: reseditbrowser = open(url,title,options,'1');
467: reseditbrowser.focus();
1.1003 www 468: }
469: // ]]>
470: </script>
1.1004 www 471: ENDRESBRW
1.1003 www 472: }
473:
1.74 www 474: sub selectstudent_link {
1.999 www 475: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
476: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
477: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
478: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 479: if ($env{'request.course.id'}) {
1.302 albertel 480: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
481: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
482: '/'.$env{'request.course.sec'})) {
1.111 www 483: return '';
484: }
1.999 www 485: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 486: if ($courseadvonly) {
487: $callargs .= ",'',1,1";
488: }
489: return '<span class="LC_nobreak">'.
490: '<a href="javascript:openstdbrowser('.$callargs.');">'.
491: &mt('Select User').'</a></span>';
1.74 www 492: }
1.258 albertel 493: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 494: $callargs .= ",'',1";
1.793 raeburn 495: return '<span class="LC_nobreak">'.
496: '<a href="javascript:openstdbrowser('.$callargs.');">'.
497: &mt('Select User').'</a></span>';
1.111 www 498: }
499: return '';
1.91 www 500: }
501:
1.1004 www 502: sub selectresource_link {
503: my ($form,$reslink,$arg)=@_;
504:
505: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
506: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
507: unless ($env{'request.course.id'}) { return $arg; }
508: return '<span class="LC_nobreak">'.
509: '<a href="javascript:openresbrowser('.$callargs.');">'.
510: $arg.'</a></span>';
511: }
512:
513:
514:
1.653 raeburn 515: sub authorbrowser_javascript {
516: return <<"ENDAUTHORBRW";
1.776 bisitz 517: <script type="text/javascript" language="JavaScript">
1.824 bisitz 518: // <![CDATA[
1.653 raeburn 519: var stdeditbrowser;
520:
521: function openauthorbrowser(formname,udom) {
522: var url = '/adm/pickauthor?';
523: url += 'form='+formname+'&roledom='+udom;
524: var title = 'Author_Browser';
525: var options = 'scrollbars=1,resizable=1,menubar=0';
526: options += ',width=700,height=600';
527: stdeditbrowser = open(url,title,options,'1');
528: stdeditbrowser.focus();
529: }
530:
1.824 bisitz 531: // ]]>
1.653 raeburn 532: </script>
533: ENDAUTHORBRW
534: }
535:
1.91 www 536: sub coursebrowser_javascript {
1.1075.2.31 raeburn 537: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1075.2.95 raeburn 538: $credits_element,$instcode) = @_;
1.932 raeburn 539: my $wintitle = 'Course_Browser';
1.931 raeburn 540: if ($crstype eq 'Community') {
1.932 raeburn 541: $wintitle = 'Community_Browser';
1.909 raeburn 542: }
1.876 raeburn 543: my $id_functions = &javascript_index_functions();
544: my $output = '
1.776 bisitz 545: <script type="text/javascript" language="JavaScript">
1.824 bisitz 546: // <![CDATA[
1.468 raeburn 547: var stdeditbrowser;'."\n";
1.876 raeburn 548:
549: $output .= <<"ENDSTDBRW";
1.909 raeburn 550: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 551: var url = '/adm/pickcourse?';
1.895 raeburn 552: var formid = getFormIdByName(formname);
1.876 raeburn 553: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 554: if (domainfilter != null) {
555: if (domainfilter != '') {
556: url += 'domainfilter='+domainfilter+'&';
557: }
558: }
1.91 www 559: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 560: '&cdomelement='+udom+
561: '&cnameelement='+desc;
1.468 raeburn 562: if (extra_element !=null && extra_element != '') {
1.594 raeburn 563: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 564: url += '&roleelement='+extra_element;
565: if (domainfilter == null || domainfilter == '') {
566: url += '&domainfilter='+extra_element;
567: }
1.234 raeburn 568: }
1.468 raeburn 569: else {
570: if (formname == 'portform') {
571: url += '&setroles='+extra_element;
1.800 raeburn 572: } else {
573: if (formname == 'rules') {
574: url += '&fixeddom='+extra_element;
575: }
1.468 raeburn 576: }
577: }
1.230 raeburn 578: }
1.909 raeburn 579: if (type != null && type != '') {
580: url += '&type='+type;
581: }
582: if (type_elem != null && type_elem != '') {
583: url += '&typeelement='+type_elem;
584: }
1.872 raeburn 585: if (formname == 'ccrs') {
586: var ownername = document.forms[formid].ccuname.value;
587: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1075.2.101 raeburn 588: url += '&cloner='+ownername+':'+ownerdom;
589: if (type == 'Course') {
590: url += '&crscode='+document.forms[formid].crscode.value;
591: }
1.1075.2.95 raeburn 592: }
593: if (formname == 'requestcrs') {
594: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 595: }
1.293 raeburn 596: if (multflag !=null && multflag != '') {
597: url += '&multiple='+multflag;
598: }
1.909 raeburn 599: var title = '$wintitle';
1.91 www 600: var options = 'scrollbars=1,resizable=1,menubar=0';
601: options += ',width=700,height=600';
602: stdeditbrowser = open(url,title,options,'1');
603: stdeditbrowser.focus();
604: }
1.876 raeburn 605: $id_functions
606: ENDSTDBRW
1.1075.2.31 raeburn 607: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
608: $output .= &setsec_javascript($sec_element,$formname,$role_element,
609: $credits_element);
1.876 raeburn 610: }
611: $output .= '
612: // ]]>
613: </script>';
614: return $output;
615: }
616:
617: sub javascript_index_functions {
618: return <<"ENDJS";
619:
620: function getFormIdByName(formname) {
621: for (var i=0;i<document.forms.length;i++) {
622: if (document.forms[i].name == formname) {
623: return i;
624: }
625: }
626: return -1;
627: }
628:
629: function getIndexByName(formid,item) {
630: for (var i=0;i<document.forms[formid].elements.length;i++) {
631: if (document.forms[formid].elements[i].name == item) {
632: return i;
633: }
634: }
635: return -1;
636: }
1.468 raeburn 637:
1.876 raeburn 638: function getDomainFromSelectbox(formname,udom) {
639: var userdom;
640: var formid = getFormIdByName(formname);
641: if (formid > -1) {
642: var domid = getIndexByName(formid,udom);
643: if (domid > -1) {
644: if (document.forms[formid].elements[domid].type == 'select-one') {
645: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
646: }
647: if (document.forms[formid].elements[domid].type == 'hidden') {
648: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 649: }
650: }
651: }
1.876 raeburn 652: return userdom;
653: }
654:
655: ENDJS
1.468 raeburn 656:
1.876 raeburn 657: }
658:
1.1017 raeburn 659: sub javascript_array_indexof {
1.1018 raeburn 660: return <<ENDJS;
1.1017 raeburn 661: <script type="text/javascript" language="JavaScript">
662: // <![CDATA[
663:
664: if (!Array.prototype.indexOf) {
665: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
666: "use strict";
667: if (this === void 0 || this === null) {
668: throw new TypeError();
669: }
670: var t = Object(this);
671: var len = t.length >>> 0;
672: if (len === 0) {
673: return -1;
674: }
675: var n = 0;
676: if (arguments.length > 0) {
677: n = Number(arguments[1]);
678: if (n !== n) { // shortcut for verifying if it's NaN
679: n = 0;
680: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
681: n = (n > 0 || -1) * Math.floor(Math.abs(n));
682: }
683: }
684: if (n >= len) {
685: return -1;
686: }
687: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
688: for (; k < len; k++) {
689: if (k in t && t[k] === searchElement) {
690: return k;
691: }
692: }
693: return -1;
694: }
695: }
696:
697: // ]]>
698: </script>
699:
700: ENDJS
701:
702: }
703:
1.876 raeburn 704: sub userbrowser_javascript {
705: my $id_functions = &javascript_index_functions();
706: return <<"ENDUSERBRW";
707:
1.888 raeburn 708: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 709: var url = '/adm/pickuser?';
710: var userdom = getDomainFromSelectbox(formname,udom);
711: if (userdom != null) {
712: if (userdom != '') {
713: url += 'srchdom='+userdom+'&';
714: }
715: }
716: url += 'form=' + formname + '&unameelement='+uname+
717: '&udomelement='+udom+
718: '&ulastelement='+ulast+
719: '&ufirstelement='+ufirst+
720: '&uemailelement='+uemail+
1.881 raeburn 721: '&hideudomelement='+hideudom+
722: '&coursedom='+crsdom;
1.888 raeburn 723: if ((caller != null) && (caller != undefined)) {
724: url += '&caller='+caller;
725: }
1.876 raeburn 726: var title = 'User_Browser';
727: var options = 'scrollbars=1,resizable=1,menubar=0';
728: options += ',width=700,height=600';
729: var stdeditbrowser = open(url,title,options,'1');
730: stdeditbrowser.focus();
731: }
732:
1.888 raeburn 733: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 734: var formid = getFormIdByName(formname);
735: if (formid > -1) {
1.888 raeburn 736: var unameid = getIndexByName(formid,uname);
1.876 raeburn 737: var domid = getIndexByName(formid,udom);
738: var hidedomid = getIndexByName(formid,origdom);
739: if (hidedomid > -1) {
740: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 741: var unameval = document.forms[formid].elements[unameid].value;
742: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
743: if (domid > -1) {
744: var slct = document.forms[formid].elements[domid];
745: if (slct.type == 'select-one') {
746: var i;
747: for (i=0;i<slct.length;i++) {
748: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
749: }
750: }
751: if (slct.type == 'hidden') {
752: slct.value = fixeddom;
1.876 raeburn 753: }
754: }
1.468 raeburn 755: }
756: }
757: }
1.876 raeburn 758: return;
759: }
760:
761: $id_functions
762: ENDUSERBRW
1.468 raeburn 763: }
764:
765: sub setsec_javascript {
1.1075.2.31 raeburn 766: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 767: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
768: $communityrolestr);
769: if ($role_element ne '') {
770: my @allroles = ('st','ta','ep','in','ad');
771: foreach my $crstype ('Course','Community') {
772: if ($crstype eq 'Community') {
773: foreach my $role (@allroles) {
774: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
775: }
776: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
777: } else {
778: foreach my $role (@allroles) {
779: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
780: }
781: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
782: }
783: }
784: $rolestr = '"'.join('","',@allroles).'"';
785: $courserolestr = '"'.join('","',@courserolenames).'"';
786: $communityrolestr = '"'.join('","',@communityrolenames).'"';
787: }
1.468 raeburn 788: my $setsections = qq|
789: function setSect(sectionlist) {
1.629 raeburn 790: var sectionsArray = new Array();
791: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
792: sectionsArray = sectionlist.split(",");
793: }
1.468 raeburn 794: var numSections = sectionsArray.length;
795: document.$formname.$sec_element.length = 0;
796: if (numSections == 0) {
797: document.$formname.$sec_element.multiple=false;
798: document.$formname.$sec_element.size=1;
799: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
800: } else {
801: if (numSections == 1) {
802: document.$formname.$sec_element.multiple=false;
803: document.$formname.$sec_element.size=1;
804: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
805: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
806: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
807: } else {
808: for (var i=0; i<numSections; i++) {
809: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
810: }
811: document.$formname.$sec_element.multiple=true
812: if (numSections < 3) {
813: document.$formname.$sec_element.size=numSections;
814: } else {
815: document.$formname.$sec_element.size=3;
816: }
817: document.$formname.$sec_element.options[0].selected = false
818: }
819: }
1.91 www 820: }
1.905 raeburn 821:
822: function setRole(crstype) {
1.468 raeburn 823: |;
1.905 raeburn 824: if ($role_element eq '') {
825: $setsections .= ' return;
826: }
827: ';
828: } else {
829: $setsections .= qq|
830: var elementLength = document.$formname.$role_element.length;
831: var allroles = Array($rolestr);
832: var courserolenames = Array($courserolestr);
833: var communityrolenames = Array($communityrolestr);
834: if (elementLength != undefined) {
835: if (document.$formname.$role_element.options[5].value == 'cc') {
836: if (crstype == 'Course') {
837: return;
838: } else {
839: allroles[5] = 'co';
840: for (var i=0; i<6; i++) {
841: document.$formname.$role_element.options[i].value = allroles[i];
842: document.$formname.$role_element.options[i].text = communityrolenames[i];
843: }
844: }
845: } else {
846: if (crstype == 'Community') {
847: return;
848: } else {
849: allroles[5] = 'cc';
850: for (var i=0; i<6; i++) {
851: document.$formname.$role_element.options[i].value = allroles[i];
852: document.$formname.$role_element.options[i].text = courserolenames[i];
853: }
854: }
855: }
856: }
857: return;
858: }
859: |;
860: }
1.1075.2.31 raeburn 861: if ($credits_element) {
862: $setsections .= qq|
863: function setCredits(defaultcredits) {
864: document.$formname.$credits_element.value = defaultcredits;
865: return;
866: }
867: |;
868: }
1.468 raeburn 869: return $setsections;
870: }
871:
1.91 www 872: sub selectcourse_link {
1.909 raeburn 873: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
874: $typeelement) = @_;
875: my $type = $selecttype;
1.871 raeburn 876: my $linktext = &mt('Select Course');
877: if ($selecttype eq 'Community') {
1.909 raeburn 878: $linktext = &mt('Select Community');
1.906 raeburn 879: } elsif ($selecttype eq 'Course/Community') {
880: $linktext = &mt('Select Course/Community');
1.909 raeburn 881: $type = '';
1.1019 raeburn 882: } elsif ($selecttype eq 'Select') {
883: $linktext = &mt('Select');
884: $type = '';
1.871 raeburn 885: }
1.787 bisitz 886: return '<span class="LC_nobreak">'
887: ."<a href='"
888: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
889: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 890: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 891: ."'>".$linktext.'</a>'
1.787 bisitz 892: .'</span>';
1.74 www 893: }
1.42 matthew 894:
1.653 raeburn 895: sub selectauthor_link {
896: my ($form,$udom)=@_;
897: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
898: &mt('Select Author').'</a>';
899: }
900:
1.876 raeburn 901: sub selectuser_link {
1.881 raeburn 902: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 903: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 904: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 905: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 906: ');">'.$linktext.'</a>';
1.876 raeburn 907: }
908:
1.273 raeburn 909: sub check_uncheck_jscript {
910: my $jscript = <<"ENDSCRT";
911: function checkAll(field) {
912: if (field.length > 0) {
913: for (i = 0; i < field.length; i++) {
1.1075.2.14 raeburn 914: if (!field[i].disabled) {
915: field[i].checked = true;
916: }
1.273 raeburn 917: }
918: } else {
1.1075.2.14 raeburn 919: if (!field.disabled) {
920: field.checked = true;
921: }
1.273 raeburn 922: }
923: }
924:
925: function uncheckAll(field) {
926: if (field.length > 0) {
927: for (i = 0; i < field.length; i++) {
928: field[i].checked = false ;
1.543 albertel 929: }
930: } else {
1.273 raeburn 931: field.checked = false ;
932: }
933: }
934: ENDSCRT
935: return $jscript;
936: }
937:
1.656 www 938: sub select_timezone {
1.659 raeburn 939: my ($name,$selected,$onchange,$includeempty)=@_;
940: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
941: if ($includeempty) {
942: $output .= '<option value=""';
943: if (($selected eq '') || ($selected eq 'local')) {
944: $output .= ' selected="selected" ';
945: }
946: $output .= '> </option>';
947: }
1.657 raeburn 948: my @timezones = DateTime::TimeZone->all_names;
949: foreach my $tzone (@timezones) {
950: $output.= '<option value="'.$tzone.'"';
951: if ($tzone eq $selected) {
952: $output.=' selected="selected"';
953: }
954: $output.=">$tzone</option>\n";
1.656 www 955: }
956: $output.="</select>";
957: return $output;
958: }
1.273 raeburn 959:
1.687 raeburn 960: sub select_datelocale {
961: my ($name,$selected,$onchange,$includeempty)=@_;
962: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
963: if ($includeempty) {
964: $output .= '<option value=""';
965: if ($selected eq '') {
966: $output .= ' selected="selected" ';
967: }
968: $output .= '> </option>';
969: }
1.1075.2.102 raeburn 970: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 971: my (@possibles,%locale_names);
1.1075.2.102 raeburn 972: my @locales = DateTime::Locale->ids();
973: foreach my $id (@locales) {
974: if ($id ne '') {
975: my ($en_terr,$native_terr);
976: my $loc = DateTime::Locale->load($id);
977: if (ref($loc)) {
978: $en_terr = $loc->name();
979: $native_terr = $loc->native_name();
1.687 raeburn 980: if (grep(/^en$/,@languages) || !@languages) {
981: if ($en_terr ne '') {
982: $locale_names{$id} = '('.$en_terr.')';
983: } elsif ($native_terr ne '') {
984: $locale_names{$id} = $native_terr;
985: }
986: } else {
987: if ($native_terr ne '') {
988: $locale_names{$id} = $native_terr.' ';
989: } elsif ($en_terr ne '') {
990: $locale_names{$id} = '('.$en_terr.')';
991: }
992: }
1.1075.2.94 raeburn 993: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1075.2.102 raeburn 994: push(@possibles,$id);
1.687 raeburn 995: }
996: }
997: }
998: foreach my $item (sort(@possibles)) {
999: $output.= '<option value="'.$item.'"';
1000: if ($item eq $selected) {
1001: $output.=' selected="selected"';
1002: }
1003: $output.=">$item";
1004: if ($locale_names{$item} ne '') {
1.1075.2.94 raeburn 1005: $output.=' '.$locale_names{$item};
1.687 raeburn 1006: }
1007: $output.="</option>\n";
1008: }
1009: $output.="</select>";
1010: return $output;
1011: }
1012:
1.792 raeburn 1013: sub select_language {
1014: my ($name,$selected,$includeempty) = @_;
1015: my %langchoices;
1016: if ($includeempty) {
1.1075.2.32 raeburn 1017: %langchoices = ('' => 'No language preference');
1.792 raeburn 1018: }
1019: foreach my $id (&languageids()) {
1020: my $code = &supportedlanguagecode($id);
1021: if ($code) {
1022: $langchoices{$code} = &plainlanguagedescription($id);
1023: }
1024: }
1.1075.2.32 raeburn 1025: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.970 raeburn 1026: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 1027: }
1028:
1.42 matthew 1029: =pod
1.36 matthew 1030:
1.648 raeburn 1031: =item * &linked_select_forms(...)
1.36 matthew 1032:
1033: linked_select_forms returns a string containing a <script></script> block
1034: and html for two <select> menus. The select menus will be linked in that
1035: changing the value of the first menu will result in new values being placed
1036: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1037: order unless a defined order is provided.
1.36 matthew 1038:
1039: linked_select_forms takes the following ordered inputs:
1040:
1041: =over 4
1042:
1.112 bowersj2 1043: =item * $formname, the name of the <form> tag
1.36 matthew 1044:
1.112 bowersj2 1045: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1046:
1.112 bowersj2 1047: =item * $firstdefault, the default value for the first menu
1.36 matthew 1048:
1.112 bowersj2 1049: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1050:
1.112 bowersj2 1051: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1052:
1.112 bowersj2 1053: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1054:
1.609 raeburn 1055: =item * $menuorder, the order of values in the first menu
1056:
1.1075.2.31 raeburn 1057: =item * $onchangefirst, additional javascript call to execute for an onchange
1058: event for the first <select> tag
1059:
1060: =item * $onchangesecond, additional javascript call to execute for an onchange
1061: event for the second <select> tag
1062:
1.41 ng 1063: =back
1064:
1.36 matthew 1065: Below is an example of such a hash. Only the 'text', 'default', and
1066: 'select2' keys must appear as stated. keys(%menu) are the possible
1067: values for the first select menu. The text that coincides with the
1.41 ng 1068: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1069: and text for the second menu are given in the hash pointed to by
1070: $menu{$choice1}->{'select2'}.
1071:
1.112 bowersj2 1072: my %menu = ( A1 => { text =>"Choice A1" ,
1073: default => "B3",
1074: select2 => {
1075: B1 => "Choice B1",
1076: B2 => "Choice B2",
1077: B3 => "Choice B3",
1078: B4 => "Choice B4"
1.609 raeburn 1079: },
1080: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1081: },
1082: A2 => { text =>"Choice A2" ,
1083: default => "C2",
1084: select2 => {
1085: C1 => "Choice C1",
1086: C2 => "Choice C2",
1087: C3 => "Choice C3"
1.609 raeburn 1088: },
1089: order => ['C2','C1','C3'],
1.112 bowersj2 1090: },
1091: A3 => { text =>"Choice A3" ,
1092: default => "D6",
1093: select2 => {
1094: D1 => "Choice D1",
1095: D2 => "Choice D2",
1096: D3 => "Choice D3",
1097: D4 => "Choice D4",
1098: D5 => "Choice D5",
1099: D6 => "Choice D6",
1100: D7 => "Choice D7"
1.609 raeburn 1101: },
1102: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1103: }
1104: );
1.36 matthew 1105:
1106: =cut
1107:
1108: sub linked_select_forms {
1109: my ($formname,
1110: $middletext,
1111: $firstdefault,
1112: $firstselectname,
1113: $secondselectname,
1.609 raeburn 1114: $hashref,
1115: $menuorder,
1.1075.2.31 raeburn 1116: $onchangefirst,
1117: $onchangesecond
1.36 matthew 1118: ) = @_;
1119: my $second = "document.$formname.$secondselectname";
1120: my $first = "document.$formname.$firstselectname";
1121: # output the javascript to do the changing
1122: my $result = '';
1.776 bisitz 1123: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1124: $result.="// <![CDATA[\n";
1.36 matthew 1125: $result.="var select2data = new Object();\n";
1126: $" = '","';
1127: my $debug = '';
1128: foreach my $s1 (sort(keys(%$hashref))) {
1129: $result.="select2data.d_$s1 = new Object();\n";
1130: $result.="select2data.d_$s1.def = new String('".
1131: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1132: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1133: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1134: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1135: @s2values = @{$hashref->{$s1}->{'order'}};
1136: }
1.36 matthew 1137: $result.="\"@s2values\");\n";
1138: $result.="select2data.d_$s1.texts = new Array(";
1139: my @s2texts;
1140: foreach my $value (@s2values) {
1141: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1142: }
1143: $result.="\"@s2texts\");\n";
1144: }
1145: $"=' ';
1146: $result.= <<"END";
1147:
1148: function select1_changed() {
1149: // Determine new choice
1150: var newvalue = "d_" + $first.value;
1151: // update select2
1152: var values = select2data[newvalue].values;
1153: var texts = select2data[newvalue].texts;
1154: var select2def = select2data[newvalue].def;
1155: var i;
1156: // out with the old
1157: for (i = 0; i < $second.options.length; i++) {
1158: $second.options[i] = null;
1159: }
1160: // in with the nuclear
1161: for (i=0;i<values.length; i++) {
1162: $second.options[i] = new Option(values[i]);
1.143 matthew 1163: $second.options[i].value = values[i];
1.36 matthew 1164: $second.options[i].text = texts[i];
1165: if (values[i] == select2def) {
1166: $second.options[i].selected = true;
1167: }
1168: }
1169: }
1.824 bisitz 1170: // ]]>
1.36 matthew 1171: </script>
1172: END
1173: # output the initial values for the selection lists
1.1075.2.31 raeburn 1174: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1175: my @order = sort(keys(%{$hashref}));
1176: if (ref($menuorder) eq 'ARRAY') {
1177: @order = @{$menuorder};
1178: }
1179: foreach my $value (@order) {
1.36 matthew 1180: $result.=" <option value=\"$value\" ";
1.253 albertel 1181: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1182: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1183: }
1184: $result .= "</select>\n";
1185: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1186: $result .= $middletext;
1.1075.2.31 raeburn 1187: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1188: if ($onchangesecond) {
1189: $result .= ' onchange="'.$onchangesecond.'"';
1190: }
1191: $result .= ">\n";
1.36 matthew 1192: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1193:
1194: my @secondorder = sort(keys(%select2));
1195: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1196: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1197: }
1198: foreach my $value (@secondorder) {
1.36 matthew 1199: $result.=" <option value=\"$value\" ";
1.253 albertel 1200: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1201: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1202: }
1203: $result .= "</select>\n";
1204: # return $debug;
1205: return $result;
1206: } # end of sub linked_select_forms {
1207:
1.45 matthew 1208: =pod
1.44 bowersj2 1209:
1.973 raeburn 1210: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1211:
1.112 bowersj2 1212: Returns a string corresponding to an HTML link to the given help
1213: $topic, where $topic corresponds to the name of a .tex file in
1214: /home/httpd/html/adm/help/tex, with underscores replaced by
1215: spaces.
1216:
1217: $text will optionally be linked to the same topic, allowing you to
1218: link text in addition to the graphic. If you do not want to link
1219: text, but wish to specify one of the later parameters, pass an
1220: empty string.
1221:
1222: $stayOnPage is a value that will be interpreted as a boolean. If true,
1223: the link will not open a new window. If false, the link will open
1224: a new window using Javascript. (Default is false.)
1225:
1226: $width and $height are optional numerical parameters that will
1227: override the width and height of the popped up window, which may
1.973 raeburn 1228: be useful for certain help topics with big pictures included.
1229:
1230: $imgid is the id of the img tag used for the help icon. This may be
1231: used in a javascript call to switch the image src. See
1232: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1233:
1234: =cut
1235:
1236: sub help_open_topic {
1.973 raeburn 1237: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1238: $text = "" if (not defined $text);
1.44 bowersj2 1239: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1240: $width = 500 if (not defined $width);
1.44 bowersj2 1241: $height = 400 if (not defined $height);
1242: my $filename = $topic;
1243: $filename =~ s/ /_/g;
1244:
1.48 bowersj2 1245: my $template = "";
1246: my $link;
1.572 banghart 1247:
1.159 www 1248: $topic=~s/\W/\_/g;
1.44 bowersj2 1249:
1.572 banghart 1250: if (!$stayOnPage) {
1.1075.2.50 raeburn 1251: if ($env{'browser.mobile'}) {
1252: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1253: } else {
1254: $link = "javascript:void(open('/adm/help/${filename}.hlp', 'Help_for_$topic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1255: }
1.1037 www 1256: } elsif ($stayOnPage eq 'popup') {
1257: $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 1258: } else {
1.48 bowersj2 1259: $link = "/adm/help/${filename}.hlp";
1260: }
1261:
1262: # Add the text
1.755 neumanie 1263: if ($text ne "") {
1.763 bisitz 1264: $template.='<span class="LC_help_open_topic">'
1265: .'<a target="_top" href="'.$link.'">'
1266: .$text.'</a>';
1.48 bowersj2 1267: }
1268:
1.763 bisitz 1269: # (Always) Add the graphic
1.179 matthew 1270: my $title = &mt('Online Help');
1.667 raeburn 1271: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1272: if ($imgid ne '') {
1273: $imgid = ' id="'.$imgid.'"';
1274: }
1.763 bisitz 1275: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1276: .'<img src="'.$helpicon.'" border="0"'
1277: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1278: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1279: .' /></a>';
1280: if ($text ne "") {
1281: $template.='</span>';
1282: }
1.44 bowersj2 1283: return $template;
1284:
1.106 bowersj2 1285: }
1286:
1287: # This is a quicky function for Latex cheatsheet editing, since it
1288: # appears in at least four places
1289: sub helpLatexCheatsheet {
1.1037 www 1290: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1291: my $out;
1.106 bowersj2 1292: my $addOther = '';
1.732 raeburn 1293: if ($topic) {
1.1037 www 1294: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1295: }
1296: $out = '<span>' # Start cheatsheet
1297: .$addOther
1298: .'<span>'
1.1037 www 1299: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1300: .'</span> <span>'
1.1037 www 1301: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1302: .'</span>';
1.732 raeburn 1303: unless ($not_author) {
1.763 bisitz 1304: $out .= ' <span>'
1.1037 www 1305: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1306: .'</span> <span>'
1.1075.2.78 raeburn 1307: .&help_open_topic('Authoring_Multilingual_Problems',&mt('Languages'),$stayOnPage,undef,600)
1.1075.2.71 raeburn 1308: .'</span>';
1.732 raeburn 1309: }
1.763 bisitz 1310: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1311: return $out;
1.172 www 1312: }
1313:
1.430 albertel 1314: sub general_help {
1315: my $helptopic='Student_Intro';
1316: if ($env{'request.role'}=~/^(ca|au)/) {
1317: $helptopic='Authoring_Intro';
1.907 raeburn 1318: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1319: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1320: } elsif ($env{'request.role'}=~/^dc/) {
1321: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1322: }
1323: return $helptopic;
1324: }
1325:
1326: sub update_help_link {
1327: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1328: my $origurl = $ENV{'REQUEST_URI'};
1329: $origurl=~s|^/~|/priv/|;
1330: my $timestamp = time;
1331: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1332: $$datum = &escape($$datum);
1333: }
1334:
1335: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1336: my $output .= <<"ENDOUTPUT";
1337: <script type="text/javascript">
1.824 bisitz 1338: // <![CDATA[
1.430 albertel 1339: banner_link = '$banner_link';
1.824 bisitz 1340: // ]]>
1.430 albertel 1341: </script>
1342: ENDOUTPUT
1343: return $output;
1344: }
1345:
1346: # now just updates the help link and generates a blue icon
1.193 raeburn 1347: sub help_open_menu {
1.430 albertel 1348: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1349: = @_;
1.949 droeschl 1350: $stayOnPage = 1;
1.430 albertel 1351: my $output;
1352: if ($component_help) {
1353: if (!$text) {
1354: $output=&help_open_topic($component_help,undef,$stayOnPage,
1355: $width,$height);
1356: } else {
1357: my $help_text;
1358: $help_text=&unescape($topic);
1359: $output='<table><tr><td>'.
1360: &help_open_topic($component_help,$help_text,$stayOnPage,
1361: $width,$height).'</td></tr></table>';
1362: }
1363: }
1364: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1365: return $output.$banner_link;
1366: }
1367:
1368: sub top_nav_help {
1369: my ($text) = @_;
1.436 albertel 1370: $text = &mt($text);
1.1075.2.60 raeburn 1371: my $stay_on_page;
1372: unless ($env{'environment.remote'} eq 'on') {
1373: $stay_on_page = 1;
1374: }
1.1075.2.61 raeburn 1375: my ($link,$banner_link);
1376: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1377: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1378: : "javascript:helpMenu('open')";
1379: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1380: }
1.201 raeburn 1381: my $title = &mt('Get help');
1.1075.2.61 raeburn 1382: if ($link) {
1383: return <<"END";
1.436 albertel 1384: $banner_link
1.1075.2.56 raeburn 1385: <a href="$link" title="$title">$text</a>
1.436 albertel 1386: END
1.1075.2.61 raeburn 1387: } else {
1388: return ' '.$text.' ';
1389: }
1.436 albertel 1390: }
1391:
1392: sub help_menu_js {
1.1075.2.52 raeburn 1393: my ($httphost) = @_;
1.949 droeschl 1394: my $stayOnPage = 1;
1.436 albertel 1395: my $width = 620;
1396: my $height = 600;
1.430 albertel 1397: my $helptopic=&general_help();
1.1075.2.52 raeburn 1398: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1399: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1400: my $start_page =
1401: &Apache::loncommon::start_page('Help Menu', undef,
1402: {'frameset' => 1,
1403: 'js_ready' => 1,
1.1075.2.52 raeburn 1404: 'use_absolute' => $httphost,
1.331 albertel 1405: 'add_entries' => {
1406: 'border' => '0',
1.579 raeburn 1407: 'rows' => "110,*",},});
1.331 albertel 1408: my $end_page =
1409: &Apache::loncommon::end_page({'frameset' => 1,
1410: 'js_ready' => 1,});
1411:
1.436 albertel 1412: my $template .= <<"ENDTEMPLATE";
1413: <script type="text/javascript">
1.877 bisitz 1414: // <![CDATA[
1.253 albertel 1415: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1416: var banner_link = '';
1.243 raeburn 1417: function helpMenu(target) {
1418: var caller = this;
1419: if (target == 'open') {
1420: var newWindow = null;
1421: try {
1.262 albertel 1422: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1423: }
1424: catch(error) {
1425: writeHelp(caller);
1426: return;
1427: }
1428: if (newWindow) {
1429: caller = newWindow;
1430: }
1.193 raeburn 1431: }
1.243 raeburn 1432: writeHelp(caller);
1433: return;
1434: }
1435: function writeHelp(caller) {
1.1075.2.61 raeburn 1436: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1437: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1438: caller.document.close();
1439: caller.focus();
1.193 raeburn 1440: }
1.877 bisitz 1441: // END LON-CAPA Internal -->
1.253 albertel 1442: // ]]>
1.436 albertel 1443: </script>
1.193 raeburn 1444: ENDTEMPLATE
1445: return $template;
1446: }
1447:
1.172 www 1448: sub help_open_bug {
1449: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1450: unless ($env{'user.adv'}) { return ''; }
1.172 www 1451: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1452: $text = "" if (not defined $text);
1453: $stayOnPage=1;
1.184 albertel 1454: $width = 600 if (not defined $width);
1455: $height = 600 if (not defined $height);
1.172 www 1456:
1457: $topic=~s/\W+/\+/g;
1458: my $link='';
1459: my $template='';
1.379 albertel 1460: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1461: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1462: if (!$stayOnPage)
1463: {
1464: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1465: }
1466: else
1467: {
1468: $link = $url;
1469: }
1470: # Add the text
1471: if ($text ne "")
1472: {
1473: $template .=
1474: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1475: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1476: }
1477:
1478: # Add the graphic
1.179 matthew 1479: my $title = &mt('Report a Bug');
1.215 albertel 1480: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1481: $template .= <<"ENDTEMPLATE";
1.436 albertel 1482: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1483: ENDTEMPLATE
1484: if ($text ne '') { $template.='</td></tr></table>' };
1485: return $template;
1486:
1487: }
1488:
1489: sub help_open_faq {
1490: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1491: unless ($env{'user.adv'}) { return ''; }
1.172 www 1492: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1493: $text = "" if (not defined $text);
1494: $stayOnPage=1;
1495: $width = 350 if (not defined $width);
1496: $height = 400 if (not defined $height);
1497:
1498: $topic=~s/\W+/\+/g;
1499: my $link='';
1500: my $template='';
1501: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1502: if (!$stayOnPage)
1503: {
1504: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1505: }
1506: else
1507: {
1508: $link = $url;
1509: }
1510:
1511: # Add the text
1512: if ($text ne "")
1513: {
1514: $template .=
1.173 www 1515: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1516: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1517: }
1518:
1519: # Add the graphic
1.179 matthew 1520: my $title = &mt('View the FAQ');
1.215 albertel 1521: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1522: $template .= <<"ENDTEMPLATE";
1.436 albertel 1523: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1524: ENDTEMPLATE
1525: if ($text ne '') { $template.='</td></tr></table>' };
1526: return $template;
1527:
1.44 bowersj2 1528: }
1.37 matthew 1529:
1.180 matthew 1530: ###############################################################
1531: ###############################################################
1532:
1.45 matthew 1533: =pod
1534:
1.648 raeburn 1535: =item * &change_content_javascript():
1.256 matthew 1536:
1537: This and the next function allow you to create small sections of an
1538: otherwise static HTML page that you can update on the fly with
1539: Javascript, even in Netscape 4.
1540:
1541: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1542: must be written to the HTML page once. It will prove the Javascript
1543: function "change(name, content)". Calling the change function with the
1544: name of the section
1545: you want to update, matching the name passed to C<changable_area>, and
1546: the new content you want to put in there, will put the content into
1547: that area.
1548:
1549: B<Note>: Netscape 4 only reserves enough space for the changable area
1550: to contain room for the original contents. You need to "make space"
1551: for whatever changes you wish to make, and be B<sure> to check your
1552: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1553: it's adequate for updating a one-line status display, but little more.
1554: This script will set the space to 100% width, so you only need to
1555: worry about height in Netscape 4.
1556:
1557: Modern browsers are much less limiting, and if you can commit to the
1558: user not using Netscape 4, this feature may be used freely with
1559: pretty much any HTML.
1560:
1561: =cut
1562:
1563: sub change_content_javascript {
1564: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1565: if ($env{'browser.type'} eq 'netscape' &&
1566: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1567: return (<<NETSCAPE4);
1568: function change(name, content) {
1569: doc = document.layers[name+"___escape"].layers[0].document;
1570: doc.open();
1571: doc.write(content);
1572: doc.close();
1573: }
1574: NETSCAPE4
1575: } else {
1576: # Otherwise, we need to use semi-standards-compliant code
1577: # (technically, "innerHTML" isn't standard but the equivalent
1578: # is really scary, and every useful browser supports it
1579: return (<<DOMBASED);
1580: function change(name, content) {
1581: element = document.getElementById(name);
1582: element.innerHTML = content;
1583: }
1584: DOMBASED
1585: }
1586: }
1587:
1588: =pod
1589:
1.648 raeburn 1590: =item * &changable_area($name,$origContent):
1.256 matthew 1591:
1592: This provides a "changable area" that can be modified on the fly via
1593: the Javascript code provided in C<change_content_javascript>. $name is
1594: the name you will use to reference the area later; do not repeat the
1595: same name on a given HTML page more then once. $origContent is what
1596: the area will originally contain, which can be left blank.
1597:
1598: =cut
1599:
1600: sub changable_area {
1601: my ($name, $origContent) = @_;
1602:
1.258 albertel 1603: if ($env{'browser.type'} eq 'netscape' &&
1604: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1605: # If this is netscape 4, we need to use the Layer tag
1606: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1607: } else {
1608: return "<span id='$name'>$origContent</span>";
1609: }
1610: }
1611:
1612: =pod
1613:
1.648 raeburn 1614: =item * &viewport_geometry_js
1.590 raeburn 1615:
1616: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1617:
1618: =cut
1619:
1620:
1621: sub viewport_geometry_js {
1622: return <<"GEOMETRY";
1623: var Geometry = {};
1624: function init_geometry() {
1625: if (Geometry.init) { return };
1626: Geometry.init=1;
1627: if (window.innerHeight) {
1628: Geometry.getViewportHeight = function() { return window.innerHeight; };
1629: Geometry.getViewportWidth = function() { return window.innerWidth; };
1630: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1631: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1632: }
1633: else if (document.documentElement && document.documentElement.clientHeight) {
1634: Geometry.getViewportHeight =
1635: function() { return document.documentElement.clientHeight; };
1636: Geometry.getViewportWidth =
1637: function() { return document.documentElement.clientWidth; };
1638:
1639: Geometry.getHorizontalScroll =
1640: function() { return document.documentElement.scrollLeft; };
1641: Geometry.getVerticalScroll =
1642: function() { return document.documentElement.scrollTop; };
1643: }
1644: else if (document.body.clientHeight) {
1645: Geometry.getViewportHeight =
1646: function() { return document.body.clientHeight; };
1647: Geometry.getViewportWidth =
1648: function() { return document.body.clientWidth; };
1649: Geometry.getHorizontalScroll =
1650: function() { return document.body.scrollLeft; };
1651: Geometry.getVerticalScroll =
1652: function() { return document.body.scrollTop; };
1653: }
1654: }
1655:
1656: GEOMETRY
1657: }
1658:
1659: =pod
1660:
1.648 raeburn 1661: =item * &viewport_size_js()
1.590 raeburn 1662:
1663: 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.
1664:
1665: =cut
1666:
1667: sub viewport_size_js {
1668: my $geometry = &viewport_geometry_js();
1669: return <<"DIMS";
1670:
1671: $geometry
1672:
1673: function getViewportDims(width,height) {
1674: init_geometry();
1675: width.value = Geometry.getViewportWidth();
1676: height.value = Geometry.getViewportHeight();
1677: return;
1678: }
1679:
1680: DIMS
1681: }
1682:
1683: =pod
1684:
1.648 raeburn 1685: =item * &resize_textarea_js()
1.565 albertel 1686:
1687: emits the needed javascript to resize a textarea to be as big as possible
1688:
1689: creates a function resize_textrea that takes two IDs first should be
1690: the id of the element to resize, second should be the id of a div that
1691: surrounds everything that comes after the textarea, this routine needs
1692: to be attached to the <body> for the onload and onresize events.
1693:
1.648 raeburn 1694: =back
1.565 albertel 1695:
1696: =cut
1697:
1698: sub resize_textarea_js {
1.590 raeburn 1699: my $geometry = &viewport_geometry_js();
1.565 albertel 1700: return <<"RESIZE";
1701: <script type="text/javascript">
1.824 bisitz 1702: // <![CDATA[
1.590 raeburn 1703: $geometry
1.565 albertel 1704:
1.588 albertel 1705: function getX(element) {
1706: var x = 0;
1707: while (element) {
1708: x += element.offsetLeft;
1709: element = element.offsetParent;
1710: }
1711: return x;
1712: }
1713: function getY(element) {
1714: var y = 0;
1715: while (element) {
1716: y += element.offsetTop;
1717: element = element.offsetParent;
1718: }
1719: return y;
1720: }
1721:
1722:
1.565 albertel 1723: function resize_textarea(textarea_id,bottom_id) {
1724: init_geometry();
1725: var textarea = document.getElementById(textarea_id);
1726: //alert(textarea);
1727:
1.588 albertel 1728: var textarea_top = getY(textarea);
1.565 albertel 1729: var textarea_height = textarea.offsetHeight;
1730: var bottom = document.getElementById(bottom_id);
1.588 albertel 1731: var bottom_top = getY(bottom);
1.565 albertel 1732: var bottom_height = bottom.offsetHeight;
1733: var window_height = Geometry.getViewportHeight();
1.588 albertel 1734: var fudge = 23;
1.565 albertel 1735: var new_height = window_height-fudge-textarea_top-bottom_height;
1736: if (new_height < 300) {
1737: new_height = 300;
1738: }
1739: textarea.style.height=new_height+'px';
1740: }
1.824 bisitz 1741: // ]]>
1.565 albertel 1742: </script>
1743: RESIZE
1744:
1745: }
1746:
1747: =pod
1748:
1.256 matthew 1749: =head1 Excel and CSV file utility routines
1750:
1751: =cut
1752:
1753: ###############################################################
1754: ###############################################################
1755:
1756: =pod
1757:
1.1075.2.56 raeburn 1758: =over 4
1759:
1.648 raeburn 1760: =item * &csv_translate($text)
1.37 matthew 1761:
1.185 www 1762: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1763: format.
1764:
1765: =cut
1766:
1.180 matthew 1767: ###############################################################
1768: ###############################################################
1.37 matthew 1769: sub csv_translate {
1770: my $text = shift;
1771: $text =~ s/\"/\"\"/g;
1.209 albertel 1772: $text =~ s/\n/ /g;
1.37 matthew 1773: return $text;
1774: }
1.180 matthew 1775:
1776: ###############################################################
1777: ###############################################################
1778:
1779: =pod
1780:
1.648 raeburn 1781: =item * &define_excel_formats()
1.180 matthew 1782:
1783: Define some commonly used Excel cell formats.
1784:
1785: Currently supported formats:
1786:
1787: =over 4
1788:
1789: =item header
1790:
1791: =item bold
1792:
1793: =item h1
1794:
1795: =item h2
1796:
1797: =item h3
1798:
1.256 matthew 1799: =item h4
1800:
1801: =item i
1802:
1.180 matthew 1803: =item date
1804:
1805: =back
1806:
1807: Inputs: $workbook
1808:
1809: Returns: $format, a hash reference.
1810:
1.1057 foxr 1811:
1.180 matthew 1812: =cut
1813:
1814: ###############################################################
1815: ###############################################################
1816: sub define_excel_formats {
1817: my ($workbook) = @_;
1818: my $format;
1819: $format->{'header'} = $workbook->add_format(bold => 1,
1820: bottom => 1,
1821: align => 'center');
1822: $format->{'bold'} = $workbook->add_format(bold=>1);
1823: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1824: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1825: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1826: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1827: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1828: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1829: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1830: return $format;
1831: }
1832:
1833: ###############################################################
1834: ###############################################################
1.113 bowersj2 1835:
1836: =pod
1837:
1.648 raeburn 1838: =item * &create_workbook()
1.255 matthew 1839:
1840: Create an Excel worksheet. If it fails, output message on the
1841: request object and return undefs.
1842:
1843: Inputs: Apache request object
1844:
1845: Returns (undef) on failure,
1846: Excel worksheet object, scalar with filename, and formats
1847: from &Apache::loncommon::define_excel_formats on success
1848:
1849: =cut
1850:
1851: ###############################################################
1852: ###############################################################
1853: sub create_workbook {
1854: my ($r) = @_;
1855: #
1856: # Create the excel spreadsheet
1857: my $filename = '/prtspool/'.
1.258 albertel 1858: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1859: time.'_'.rand(1000000000).'.xls';
1860: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1861: if (! defined($workbook)) {
1862: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1863: $r->print(
1864: '<p class="LC_error">'
1865: .&mt('Problems occurred in creating the new Excel file.')
1866: .' '.&mt('This error has been logged.')
1867: .' '.&mt('Please alert your LON-CAPA administrator.')
1868: .'</p>'
1869: );
1.255 matthew 1870: return (undef);
1871: }
1872: #
1.1014 foxr 1873: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 1874: #
1875: my $format = &Apache::loncommon::define_excel_formats($workbook);
1876: return ($workbook,$filename,$format);
1877: }
1878:
1879: ###############################################################
1880: ###############################################################
1881:
1882: =pod
1883:
1.648 raeburn 1884: =item * &create_text_file()
1.113 bowersj2 1885:
1.542 raeburn 1886: Create a file to write to and eventually make available to the user.
1.256 matthew 1887: If file creation fails, outputs an error message on the request object and
1888: return undefs.
1.113 bowersj2 1889:
1.256 matthew 1890: Inputs: Apache request object, and file suffix
1.113 bowersj2 1891:
1.256 matthew 1892: Returns (undef) on failure,
1893: Filehandle and filename on success.
1.113 bowersj2 1894:
1895: =cut
1896:
1.256 matthew 1897: ###############################################################
1898: ###############################################################
1899: sub create_text_file {
1900: my ($r,$suffix) = @_;
1901: if (! defined($suffix)) { $suffix = 'txt'; };
1902: my $fh;
1903: my $filename = '/prtspool/'.
1.258 albertel 1904: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1905: time.'_'.rand(1000000000).'.'.$suffix;
1906: $fh = Apache::File->new('>/home/httpd'.$filename);
1907: if (! defined($fh)) {
1908: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1909: $r->print(
1910: '<p class="LC_error">'
1911: .&mt('Problems occurred in creating the output file.')
1912: .' '.&mt('This error has been logged.')
1913: .' '.&mt('Please alert your LON-CAPA administrator.')
1914: .'</p>'
1915: );
1.113 bowersj2 1916: }
1.256 matthew 1917: return ($fh,$filename)
1.113 bowersj2 1918: }
1919:
1920:
1.256 matthew 1921: =pod
1.113 bowersj2 1922:
1923: =back
1924:
1925: =cut
1.37 matthew 1926:
1927: ###############################################################
1.33 matthew 1928: ## Home server <option> list generating code ##
1929: ###############################################################
1.35 matthew 1930:
1.169 www 1931: # ------------------------------------------
1932:
1933: sub domain_select {
1934: my ($name,$value,$multiple)=@_;
1935: my %domains=map {
1.514 albertel 1936: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1937: } &Apache::lonnet::all_domains();
1.169 www 1938: if ($multiple) {
1939: $domains{''}=&mt('Any domain');
1.550 albertel 1940: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1941: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1942: } else {
1.550 albertel 1943: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1944: return &select_form($name,$value,\%domains);
1.169 www 1945: }
1946: }
1947:
1.282 albertel 1948: #-------------------------------------------
1949:
1950: =pod
1951:
1.519 raeburn 1952: =head1 Routines for form select boxes
1953:
1954: =over 4
1955:
1.648 raeburn 1956: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1957:
1958: Returns a string containing a <select> element int multiple mode
1959:
1960:
1961: Args:
1962: $name - name of the <select> element
1.506 raeburn 1963: $value - scalar or array ref of values that should already be selected
1.282 albertel 1964: $size - number of rows long the select element is
1.283 albertel 1965: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1966: (shown text should already have been &mt())
1.506 raeburn 1967: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1968:
1.282 albertel 1969: =cut
1970:
1971: #-------------------------------------------
1.169 www 1972: sub multiple_select_form {
1.284 albertel 1973: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1974: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1975: my $output='';
1.191 matthew 1976: if (! defined($size)) {
1977: $size = 4;
1.283 albertel 1978: if (scalar(keys(%$hash))<4) {
1979: $size = scalar(keys(%$hash));
1.191 matthew 1980: }
1981: }
1.734 bisitz 1982: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1983: my @order;
1.506 raeburn 1984: if (ref($order) eq 'ARRAY') {
1985: @order = @{$order};
1986: } else {
1987: @order = sort(keys(%$hash));
1.501 banghart 1988: }
1989: if (exists($$hash{'select_form_order'})) {
1990: @order = @{$$hash{'select_form_order'}};
1991: }
1992:
1.284 albertel 1993: foreach my $key (@order) {
1.356 albertel 1994: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 1995: $output.='selected="selected" ' if ($selected{$key});
1996: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 1997: }
1998: $output.="</select>\n";
1999: return $output;
2000: }
2001:
1.88 www 2002: #-------------------------------------------
2003:
2004: =pod
2005:
1.970 raeburn 2006: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 2007:
2008: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2009: allow a user to select options from a ref to a hash containing:
2010: option_name => displayed text. An optional $onchange can include
2011: a javascript onchange item, e.g., onchange="this.form.submit();"
2012:
1.88 www 2013: See lonrights.pm for an example invocation and use.
2014:
2015: =cut
2016:
2017: #-------------------------------------------
2018: sub select_form {
1.970 raeburn 2019: my ($def,$name,$hashref,$onchange) = @_;
2020: return unless (ref($hashref) eq 'HASH');
2021: if ($onchange) {
2022: $onchange = ' onchange="'.$onchange.'"';
2023: }
2024: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2025: my @keys;
1.970 raeburn 2026: if (exists($hashref->{'select_form_order'})) {
2027: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2028: } else {
1.970 raeburn 2029: @keys=sort(keys(%{$hashref}));
1.128 albertel 2030: }
1.356 albertel 2031: foreach my $key (@keys) {
2032: $selectform.=
2033: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2034: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2035: ">".$hashref->{$key}."</option>\n";
1.88 www 2036: }
2037: $selectform.="</select>";
2038: return $selectform;
2039: }
2040:
1.475 www 2041: # For display filters
2042:
2043: sub display_filter {
1.1074 raeburn 2044: my ($context) = @_;
1.475 www 2045: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2046: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2047: my $phraseinput = 'hidden';
2048: my $includeinput = 'hidden';
2049: my ($checked,$includetypestext);
2050: if ($env{'form.displayfilter'} eq 'containing') {
2051: $phraseinput = 'text';
2052: if ($context eq 'parmslog') {
2053: $includeinput = 'checkbox';
2054: if ($env{'form.includetypes'}) {
2055: $checked = ' checked="checked"';
2056: }
2057: $includetypestext = &mt('Include parameter types');
2058: }
2059: } else {
2060: $includetypestext = ' ';
2061: }
2062: my ($additional,$secondid,$thirdid);
2063: if ($context eq 'parmslog') {
2064: $additional =
2065: '<label><input type="'.$includeinput.'" name="includetypes"'.
2066: $checked.' name="includetypes" value="1" id="includetypes" />'.
2067: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2068: '</label>';
2069: $secondid = 'includetypes';
2070: $thirdid = 'includetypestext';
2071: }
2072: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2073: '$secondid','$thirdid')";
2074: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2075: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2076: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2077: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2078: &mt('Filter: [_1]',
1.477 www 2079: &select_form($env{'form.displayfilter'},
2080: 'displayfilter',
1.970 raeburn 2081: {'currentfolder' => 'Current folder/page',
1.477 www 2082: 'containing' => 'Containing phrase',
1.1074 raeburn 2083: 'none' => 'None'},$onchange)).' '.
2084: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2085: &HTML::Entities::encode($env{'form.containingphrase'}).
2086: '" />'.$additional;
2087: }
2088:
2089: sub display_filter_js {
2090: my $includetext = &mt('Include parameter types');
2091: return <<"ENDJS";
2092:
2093: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2094: var firstType = 'hidden';
2095: if (setter.options[setter.selectedIndex].value == 'containing') {
2096: firstType = 'text';
2097: }
2098: firstObject = document.getElementById(firstid);
2099: if (typeof(firstObject) == 'object') {
2100: if (firstObject.type != firstType) {
2101: changeInputType(firstObject,firstType);
2102: }
2103: }
2104: if (context == 'parmslog') {
2105: var secondType = 'hidden';
2106: if (firstType == 'text') {
2107: secondType = 'checkbox';
2108: }
2109: secondObject = document.getElementById(secondid);
2110: if (typeof(secondObject) == 'object') {
2111: if (secondObject.type != secondType) {
2112: changeInputType(secondObject,secondType);
2113: }
2114: }
2115: var textItem = document.getElementById(thirdid);
2116: var currtext = textItem.innerHTML;
2117: var newtext;
2118: if (firstType == 'text') {
2119: newtext = '$includetext';
2120: } else {
2121: newtext = ' ';
2122: }
2123: if (currtext != newtext) {
2124: textItem.innerHTML = newtext;
2125: }
2126: }
2127: return;
2128: }
2129:
2130: function changeInputType(oldObject,newType) {
2131: var newObject = document.createElement('input');
2132: newObject.type = newType;
2133: if (oldObject.size) {
2134: newObject.size = oldObject.size;
2135: }
2136: if (oldObject.value) {
2137: newObject.value = oldObject.value;
2138: }
2139: if (oldObject.name) {
2140: newObject.name = oldObject.name;
2141: }
2142: if (oldObject.id) {
2143: newObject.id = oldObject.id;
2144: }
2145: oldObject.parentNode.replaceChild(newObject,oldObject);
2146: return;
2147: }
2148:
2149: ENDJS
1.475 www 2150: }
2151:
1.167 www 2152: sub gradeleveldescription {
2153: my $gradelevel=shift;
2154: my %gradelevels=(0 => 'Not specified',
2155: 1 => 'Grade 1',
2156: 2 => 'Grade 2',
2157: 3 => 'Grade 3',
2158: 4 => 'Grade 4',
2159: 5 => 'Grade 5',
2160: 6 => 'Grade 6',
2161: 7 => 'Grade 7',
2162: 8 => 'Grade 8',
2163: 9 => 'Grade 9',
2164: 10 => 'Grade 10',
2165: 11 => 'Grade 11',
2166: 12 => 'Grade 12',
2167: 13 => 'Grade 13',
2168: 14 => '100 Level',
2169: 15 => '200 Level',
2170: 16 => '300 Level',
2171: 17 => '400 Level',
2172: 18 => 'Graduate Level');
2173: return &mt($gradelevels{$gradelevel});
2174: }
2175:
1.163 www 2176: sub select_level_form {
2177: my ($deflevel,$name)=@_;
2178: unless ($deflevel) { $deflevel=0; }
1.167 www 2179: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2180: for (my $i=0; $i<=18; $i++) {
2181: $selectform.="<option value=\"$i\" ".
1.253 albertel 2182: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2183: ">".&gradeleveldescription($i)."</option>\n";
2184: }
2185: $selectform.="</select>";
2186: return $selectform;
1.163 www 2187: }
1.167 www 2188:
1.35 matthew 2189: #-------------------------------------------
2190:
1.45 matthew 2191: =pod
2192:
1.1075.2.42 raeburn 2193: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35 matthew 2194:
2195: Returns a string containing a <select name='$name' size='1'> form to
2196: allow a user to select the domain to preform an operation in.
2197: See loncreateuser.pm for an example invocation and use.
2198:
1.90 www 2199: If the $includeempty flag is set, it also includes an empty choice ("no domain
2200: selected");
2201:
1.743 raeburn 2202: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2203:
1.910 raeburn 2204: 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.
2205:
1.1075.2.36 raeburn 2206: The optional $incdoms is a reference to an array of domains which will be the only available options.
2207:
2208: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2209:
1.35 matthew 2210: =cut
2211:
2212: #-------------------------------------------
1.34 matthew 2213: sub select_dom_form {
1.1075.2.36 raeburn 2214: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2215: if ($onchange) {
1.874 raeburn 2216: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2217: }
1.1075.2.36 raeburn 2218: my (@domains,%exclude);
1.910 raeburn 2219: if (ref($incdoms) eq 'ARRAY') {
2220: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2221: } else {
2222: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2223: }
1.90 www 2224: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2225: if (ref($excdoms) eq 'ARRAY') {
2226: map { $exclude{$_} = 1; } @{$excdoms};
2227: }
1.743 raeburn 2228: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2229: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2230: next if ($exclude{$dom});
1.356 albertel 2231: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2232: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2233: if ($showdomdesc) {
2234: if ($dom ne '') {
2235: my $domdesc = &Apache::lonnet::domain($dom,'description');
2236: if ($domdesc ne '') {
2237: $selectdomain .= ' ('.$domdesc.')';
2238: }
2239: }
2240: }
2241: $selectdomain .= "</option>\n";
1.34 matthew 2242: }
2243: $selectdomain.="</select>";
2244: return $selectdomain;
2245: }
2246:
1.35 matthew 2247: #-------------------------------------------
2248:
1.45 matthew 2249: =pod
2250:
1.648 raeburn 2251: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2252:
1.586 raeburn 2253: input: 4 arguments (two required, two optional) -
2254: $domain - domain of new user
2255: $name - name of form element
2256: $default - Value of 'default' causes a default item to be first
2257: option, and selected by default.
2258: $hide - Value of 'hide' causes hiding of the name of the server,
2259: if 1 server found, or default, if 0 found.
1.594 raeburn 2260: output: returns 2 items:
1.586 raeburn 2261: (a) form element which contains either:
2262: (i) <select name="$name">
2263: <option value="$hostid1">$hostid $servers{$hostid}</option>
2264: <option value="$hostid2">$hostid $servers{$hostid}</option>
2265: </select>
2266: form item if there are multiple library servers in $domain, or
2267: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2268: if there is only one library server in $domain.
2269:
2270: (b) number of library servers found.
2271:
2272: See loncreateuser.pm for example of use.
1.35 matthew 2273:
2274: =cut
2275:
2276: #-------------------------------------------
1.586 raeburn 2277: sub home_server_form_item {
2278: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2279: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2280: my $result;
2281: my $numlib = keys(%servers);
2282: if ($numlib > 1) {
2283: $result .= '<select name="'.$name.'" />'."\n";
2284: if ($default) {
1.804 bisitz 2285: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2286: '</option>'."\n";
2287: }
2288: foreach my $hostid (sort(keys(%servers))) {
2289: $result.= '<option value="'.$hostid.'">'.
2290: $hostid.' '.$servers{$hostid}."</option>\n";
2291: }
2292: $result .= '</select>'."\n";
2293: } elsif ($numlib == 1) {
2294: my $hostid;
2295: foreach my $item (keys(%servers)) {
2296: $hostid = $item;
2297: }
2298: $result .= '<input type="hidden" name="'.$name.'" value="'.
2299: $hostid.'" />';
2300: if (!$hide) {
2301: $result .= $hostid.' '.$servers{$hostid};
2302: }
2303: $result .= "\n";
2304: } elsif ($default) {
2305: $result .= '<input type="hidden" name="'.$name.
2306: '" value="default" />';
2307: if (!$hide) {
2308: $result .= &mt('default');
2309: }
2310: $result .= "\n";
1.33 matthew 2311: }
1.586 raeburn 2312: return ($result,$numlib);
1.33 matthew 2313: }
1.112 bowersj2 2314:
2315: =pod
2316:
1.534 albertel 2317: =back
2318:
1.112 bowersj2 2319: =cut
1.87 matthew 2320:
2321: ###############################################################
1.112 bowersj2 2322: ## Decoding User Agent ##
1.87 matthew 2323: ###############################################################
2324:
2325: =pod
2326:
1.112 bowersj2 2327: =head1 Decoding the User Agent
2328:
2329: =over 4
2330:
2331: =item * &decode_user_agent()
1.87 matthew 2332:
2333: Inputs: $r
2334:
2335: Outputs:
2336:
2337: =over 4
2338:
1.112 bowersj2 2339: =item * $httpbrowser
1.87 matthew 2340:
1.112 bowersj2 2341: =item * $clientbrowser
1.87 matthew 2342:
1.112 bowersj2 2343: =item * $clientversion
1.87 matthew 2344:
1.112 bowersj2 2345: =item * $clientmathml
1.87 matthew 2346:
1.112 bowersj2 2347: =item * $clientunicode
1.87 matthew 2348:
1.112 bowersj2 2349: =item * $clientos
1.87 matthew 2350:
1.1075.2.42 raeburn 2351: =item * $clientmobile
2352:
2353: =item * $clientinfo
2354:
1.1075.2.77 raeburn 2355: =item * $clientosversion
2356:
1.87 matthew 2357: =back
2358:
1.157 matthew 2359: =back
2360:
1.87 matthew 2361: =cut
2362:
2363: ###############################################################
2364: ###############################################################
2365: sub decode_user_agent {
1.247 albertel 2366: my ($r)=@_;
1.87 matthew 2367: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2368: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2369: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2370: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2371: my $clientbrowser='unknown';
2372: my $clientversion='0';
2373: my $clientmathml='';
2374: my $clientunicode='0';
1.1075.2.42 raeburn 2375: my $clientmobile=0;
1.1075.2.77 raeburn 2376: my $clientosversion='';
1.87 matthew 2377: for (my $i=0;$i<=$#browsertype;$i++) {
1.1075.2.76 raeburn 2378: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2379: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2380: $clientbrowser=$bname;
2381: $httpbrowser=~/$vreg/i;
2382: $clientversion=$1;
2383: $clientmathml=($clientversion>=$minv);
2384: $clientunicode=($clientversion>=$univ);
2385: }
2386: }
2387: my $clientos='unknown';
1.1075.2.42 raeburn 2388: my $clientinfo;
1.87 matthew 2389: if (($httpbrowser=~/linux/i) ||
2390: ($httpbrowser=~/unix/i) ||
2391: ($httpbrowser=~/ux/i) ||
2392: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2393: if (($httpbrowser=~/vax/i) ||
2394: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2395: if ($httpbrowser=~/next/i) { $clientos='next'; }
2396: if (($httpbrowser=~/mac/i) ||
2397: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1075.2.77 raeburn 2398: if ($httpbrowser=~/win/i) {
2399: $clientos='win';
2400: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2401: $clientosversion = $1;
2402: }
2403: }
1.87 matthew 2404: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2405: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2406: $clientmobile=lc($1);
2407: }
2408: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2409: $clientinfo = 'firefox-'.$1;
2410: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2411: $clientinfo = 'chromeframe-'.$1;
2412: }
1.87 matthew 2413: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.77 raeburn 2414: $clientunicode,$clientos,$clientmobile,$clientinfo,
2415: $clientosversion);
1.87 matthew 2416: }
2417:
1.32 matthew 2418: ###############################################################
2419: ## Authentication changing form generation subroutines ##
2420: ###############################################################
2421: ##
2422: ## All of the authform_xxxxxxx subroutines take their inputs in a
2423: ## hash, and have reasonable default values.
2424: ##
2425: ## formname = the name given in the <form> tag.
1.35 matthew 2426: #-------------------------------------------
2427:
1.45 matthew 2428: =pod
2429:
1.112 bowersj2 2430: =head1 Authentication Routines
2431:
2432: =over 4
2433:
1.648 raeburn 2434: =item * &authform_xxxxxx()
1.35 matthew 2435:
2436: The authform_xxxxxx subroutines provide javascript and html forms which
2437: handle some of the conveniences required for authentication forms.
2438: This is not an optimal method, but it works.
2439:
2440: =over 4
2441:
1.112 bowersj2 2442: =item * authform_header
1.35 matthew 2443:
1.112 bowersj2 2444: =item * authform_authorwarning
1.35 matthew 2445:
1.112 bowersj2 2446: =item * authform_nochange
1.35 matthew 2447:
1.112 bowersj2 2448: =item * authform_kerberos
1.35 matthew 2449:
1.112 bowersj2 2450: =item * authform_internal
1.35 matthew 2451:
1.112 bowersj2 2452: =item * authform_filesystem
1.35 matthew 2453:
2454: =back
2455:
1.648 raeburn 2456: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2457:
1.35 matthew 2458: =cut
2459:
2460: #-------------------------------------------
1.32 matthew 2461: sub authform_header{
2462: my %in = (
2463: formname => 'cu',
1.80 albertel 2464: kerb_def_dom => '',
1.32 matthew 2465: @_,
2466: );
2467: $in{'formname'} = 'document.' . $in{'formname'};
2468: my $result='';
1.80 albertel 2469:
2470: #---------------------------------------------- Code for upper case translation
2471: my $Javascript_toUpperCase;
2472: unless ($in{kerb_def_dom}) {
2473: $Javascript_toUpperCase =<<"END";
2474: switch (choice) {
2475: case 'krb': currentform.elements[choicearg].value =
2476: currentform.elements[choicearg].value.toUpperCase();
2477: break;
2478: default:
2479: }
2480: END
2481: } else {
2482: $Javascript_toUpperCase = "";
2483: }
2484:
1.165 raeburn 2485: my $radioval = "'nochange'";
1.591 raeburn 2486: if (defined($in{'curr_authtype'})) {
2487: if ($in{'curr_authtype'} ne '') {
2488: $radioval = "'".$in{'curr_authtype'}."arg'";
2489: }
1.174 matthew 2490: }
1.165 raeburn 2491: my $argfield = 'null';
1.591 raeburn 2492: if (defined($in{'mode'})) {
1.165 raeburn 2493: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2494: if (defined($in{'curr_autharg'})) {
2495: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2496: $argfield = "'$in{'curr_autharg'}'";
2497: }
2498: }
2499: }
2500: }
2501:
1.32 matthew 2502: $result.=<<"END";
2503: var current = new Object();
1.165 raeburn 2504: current.radiovalue = $radioval;
2505: current.argfield = $argfield;
1.32 matthew 2506:
2507: function changed_radio(choice,currentform) {
2508: var choicearg = choice + 'arg';
2509: // If a radio button in changed, we need to change the argfield
2510: if (current.radiovalue != choice) {
2511: current.radiovalue = choice;
2512: if (current.argfield != null) {
2513: currentform.elements[current.argfield].value = '';
2514: }
2515: if (choice == 'nochange') {
2516: current.argfield = null;
2517: } else {
2518: current.argfield = choicearg;
2519: switch(choice) {
2520: case 'krb':
2521: currentform.elements[current.argfield].value =
2522: "$in{'kerb_def_dom'}";
2523: break;
2524: default:
2525: break;
2526: }
2527: }
2528: }
2529: return;
2530: }
1.22 www 2531:
1.32 matthew 2532: function changed_text(choice,currentform) {
2533: var choicearg = choice + 'arg';
2534: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2535: $Javascript_toUpperCase
1.32 matthew 2536: // clear old field
2537: if ((current.argfield != choicearg) && (current.argfield != null)) {
2538: currentform.elements[current.argfield].value = '';
2539: }
2540: current.argfield = choicearg;
2541: }
2542: set_auth_radio_buttons(choice,currentform);
2543: return;
1.20 www 2544: }
1.32 matthew 2545:
2546: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2547: var numauthchoices = currentform.login.length;
2548: if (typeof numauthchoices == "undefined") {
2549: return;
2550: }
1.32 matthew 2551: var i=0;
1.986 raeburn 2552: while (i < numauthchoices) {
1.32 matthew 2553: if (currentform.login[i].value == newvalue) { break; }
2554: i++;
2555: }
1.986 raeburn 2556: if (i == numauthchoices) {
1.32 matthew 2557: return;
2558: }
2559: current.radiovalue = newvalue;
2560: currentform.login[i].checked = true;
2561: return;
2562: }
2563: END
2564: return $result;
2565: }
2566:
1.1075.2.20 raeburn 2567: sub authform_authorwarning {
1.32 matthew 2568: my $result='';
1.144 matthew 2569: $result='<i>'.
2570: &mt('As a general rule, only authors or co-authors should be '.
2571: 'filesystem authenticated '.
2572: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2573: return $result;
2574: }
2575:
1.1075.2.20 raeburn 2576: sub authform_nochange {
1.32 matthew 2577: my %in = (
2578: formname => 'document.cu',
2579: kerb_def_dom => 'MSU.EDU',
2580: @_,
2581: );
1.1075.2.20 raeburn 2582: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2583: my $result;
1.1075.2.20 raeburn 2584: if (!$authnum) {
2585: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2586: } else {
2587: $result = '<label>'.&mt('[_1] Do not change login data',
2588: '<input type="radio" name="login" value="nochange" '.
2589: 'checked="checked" onclick="'.
1.281 albertel 2590: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2591: '</label>';
1.586 raeburn 2592: }
1.32 matthew 2593: return $result;
2594: }
2595:
1.591 raeburn 2596: sub authform_kerberos {
1.32 matthew 2597: my %in = (
2598: formname => 'document.cu',
2599: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2600: kerb_def_auth => 'krb4',
1.32 matthew 2601: @_,
2602: );
1.586 raeburn 2603: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2604: $autharg,$jscall);
1.1075.2.20 raeburn 2605: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2606: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2607: $check5 = ' checked="checked"';
1.80 albertel 2608: } else {
1.772 bisitz 2609: $check4 = ' checked="checked"';
1.80 albertel 2610: }
1.165 raeburn 2611: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2612: if (defined($in{'curr_authtype'})) {
2613: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2614: $krbcheck = ' checked="checked"';
1.623 raeburn 2615: if (defined($in{'mode'})) {
2616: if ($in{'mode'} eq 'modifyuser') {
2617: $krbcheck = '';
2618: }
2619: }
1.591 raeburn 2620: if (defined($in{'curr_kerb_ver'})) {
2621: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2622: $check5 = ' checked="checked"';
1.591 raeburn 2623: $check4 = '';
2624: } else {
1.772 bisitz 2625: $check4 = ' checked="checked"';
1.591 raeburn 2626: $check5 = '';
2627: }
1.586 raeburn 2628: }
1.591 raeburn 2629: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2630: $krbarg = $in{'curr_autharg'};
2631: }
1.586 raeburn 2632: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2633: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2634: $result =
2635: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2636: $in{'curr_autharg'},$krbver);
2637: } else {
2638: $result =
2639: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2640: }
2641: return $result;
2642: }
2643: }
2644: } else {
2645: if ($authnum == 1) {
1.784 bisitz 2646: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2647: }
2648: }
1.586 raeburn 2649: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2650: return;
1.587 raeburn 2651: } elsif ($authtype eq '') {
1.591 raeburn 2652: if (defined($in{'mode'})) {
1.587 raeburn 2653: if ($in{'mode'} eq 'modifycourse') {
2654: if ($authnum == 1) {
1.1075.2.20 raeburn 2655: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2656: }
2657: }
2658: }
1.586 raeburn 2659: }
2660: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2661: if ($authtype eq '') {
2662: $authtype = '<input type="radio" name="login" value="krb" '.
2663: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2664: $krbcheck.' />';
2665: }
2666: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2667: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2668: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2669: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2670: $in{'curr_authtype'} eq 'krb4')) {
2671: $result .= &mt
1.144 matthew 2672: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2673: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2674: '<label>'.$authtype,
1.281 albertel 2675: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2676: 'value="'.$krbarg.'" '.
1.144 matthew 2677: 'onchange="'.$jscall.'" />',
1.281 albertel 2678: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2679: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2680: '</label>');
1.586 raeburn 2681: } elsif ($can_assign{'krb4'}) {
2682: $result .= &mt
2683: ('[_1] Kerberos authenticated with domain [_2] '.
2684: '[_3] Version 4 [_4]',
2685: '<label>'.$authtype,
2686: '</label><input type="text" size="10" name="krbarg" '.
2687: 'value="'.$krbarg.'" '.
2688: 'onchange="'.$jscall.'" />',
2689: '<label><input type="hidden" name="krbver" value="4" />',
2690: '</label>');
2691: } elsif ($can_assign{'krb5'}) {
2692: $result .= &mt
2693: ('[_1] Kerberos authenticated with domain [_2] '.
2694: '[_3] Version 5 [_4]',
2695: '<label>'.$authtype,
2696: '</label><input type="text" size="10" name="krbarg" '.
2697: 'value="'.$krbarg.'" '.
2698: 'onchange="'.$jscall.'" />',
2699: '<label><input type="hidden" name="krbver" value="5" />',
2700: '</label>');
2701: }
1.32 matthew 2702: return $result;
2703: }
2704:
1.1075.2.20 raeburn 2705: sub authform_internal {
1.586 raeburn 2706: my %in = (
1.32 matthew 2707: formname => 'document.cu',
2708: kerb_def_dom => 'MSU.EDU',
2709: @_,
2710: );
1.586 raeburn 2711: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2712: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2713: if (defined($in{'curr_authtype'})) {
2714: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2715: if ($can_assign{'int'}) {
1.772 bisitz 2716: $intcheck = 'checked="checked" ';
1.623 raeburn 2717: if (defined($in{'mode'})) {
2718: if ($in{'mode'} eq 'modifyuser') {
2719: $intcheck = '';
2720: }
2721: }
1.591 raeburn 2722: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2723: $intarg = $in{'curr_autharg'};
2724: }
2725: } else {
2726: $result = &mt('Currently internally authenticated.');
2727: return $result;
1.165 raeburn 2728: }
2729: }
1.586 raeburn 2730: } else {
2731: if ($authnum == 1) {
1.784 bisitz 2732: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2733: }
2734: }
2735: if (!$can_assign{'int'}) {
2736: return;
1.587 raeburn 2737: } elsif ($authtype eq '') {
1.591 raeburn 2738: if (defined($in{'mode'})) {
1.587 raeburn 2739: if ($in{'mode'} eq 'modifycourse') {
2740: if ($authnum == 1) {
1.1075.2.20 raeburn 2741: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2742: }
2743: }
2744: }
1.165 raeburn 2745: }
1.586 raeburn 2746: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2747: if ($authtype eq '') {
2748: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2749: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2750: }
1.605 bisitz 2751: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2752: $intarg.'" onchange="'.$jscall.'" />';
2753: $result = &mt
1.144 matthew 2754: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2755: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2756: $result.="<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 2757: return $result;
2758: }
2759:
1.1075.2.20 raeburn 2760: sub authform_local {
1.32 matthew 2761: my %in = (
2762: formname => 'document.cu',
2763: kerb_def_dom => 'MSU.EDU',
2764: @_,
2765: );
1.586 raeburn 2766: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2767: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2768: if (defined($in{'curr_authtype'})) {
2769: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2770: if ($can_assign{'loc'}) {
1.772 bisitz 2771: $loccheck = 'checked="checked" ';
1.623 raeburn 2772: if (defined($in{'mode'})) {
2773: if ($in{'mode'} eq 'modifyuser') {
2774: $loccheck = '';
2775: }
2776: }
1.591 raeburn 2777: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2778: $locarg = $in{'curr_autharg'};
2779: }
2780: } else {
2781: $result = &mt('Currently using local (institutional) authentication.');
2782: return $result;
1.165 raeburn 2783: }
2784: }
1.586 raeburn 2785: } else {
2786: if ($authnum == 1) {
1.784 bisitz 2787: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2788: }
2789: }
2790: if (!$can_assign{'loc'}) {
2791: return;
1.587 raeburn 2792: } elsif ($authtype eq '') {
1.591 raeburn 2793: if (defined($in{'mode'})) {
1.587 raeburn 2794: if ($in{'mode'} eq 'modifycourse') {
2795: if ($authnum == 1) {
1.1075.2.20 raeburn 2796: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 2797: }
2798: }
2799: }
1.165 raeburn 2800: }
1.586 raeburn 2801: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2802: if ($authtype eq '') {
2803: $authtype = '<input type="radio" name="login" value="loc" '.
2804: $loccheck.' onchange="'.$jscall.'" onclick="'.
2805: $jscall.'" />';
2806: }
2807: $autharg = '<input type="text" size="10" name="locarg" value="'.
2808: $locarg.'" onchange="'.$jscall.'" />';
2809: $result = &mt('[_1] Local Authentication with argument [_2]',
2810: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2811: return $result;
2812: }
2813:
1.1075.2.20 raeburn 2814: sub authform_filesystem {
1.32 matthew 2815: my %in = (
2816: formname => 'document.cu',
2817: kerb_def_dom => 'MSU.EDU',
2818: @_,
2819: );
1.586 raeburn 2820: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2821: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2822: if (defined($in{'curr_authtype'})) {
2823: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2824: if ($can_assign{'fsys'}) {
1.772 bisitz 2825: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2826: if (defined($in{'mode'})) {
2827: if ($in{'mode'} eq 'modifyuser') {
2828: $fsyscheck = '';
2829: }
2830: }
1.586 raeburn 2831: } else {
2832: $result = &mt('Currently Filesystem Authenticated.');
2833: return $result;
2834: }
2835: }
2836: } else {
2837: if ($authnum == 1) {
1.784 bisitz 2838: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2839: }
2840: }
2841: if (!$can_assign{'fsys'}) {
2842: return;
1.587 raeburn 2843: } elsif ($authtype eq '') {
1.591 raeburn 2844: if (defined($in{'mode'})) {
1.587 raeburn 2845: if ($in{'mode'} eq 'modifycourse') {
2846: if ($authnum == 1) {
1.1075.2.20 raeburn 2847: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 2848: }
2849: }
2850: }
1.586 raeburn 2851: }
2852: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2853: if ($authtype eq '') {
2854: $authtype = '<input type="radio" name="login" value="fsys" '.
2855: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2856: $jscall.'" />';
2857: }
2858: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2859: ' onchange="'.$jscall.'" />';
2860: $result = &mt
1.144 matthew 2861: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2862: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2863: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2864: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2865: 'onchange="'.$jscall.'" />');
1.32 matthew 2866: return $result;
2867: }
2868:
1.586 raeburn 2869: sub get_assignable_auth {
2870: my ($dom) = @_;
2871: if ($dom eq '') {
2872: $dom = $env{'request.role.domain'};
2873: }
2874: my %can_assign = (
2875: krb4 => 1,
2876: krb5 => 1,
2877: int => 1,
2878: loc => 1,
2879: );
2880: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2881: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2882: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2883: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2884: my $context;
2885: if ($env{'request.role'} =~ /^au/) {
2886: $context = 'author';
2887: } elsif ($env{'request.role'} =~ /^dc/) {
2888: $context = 'domain';
2889: } elsif ($env{'request.course.id'}) {
2890: $context = 'course';
2891: }
2892: if ($context) {
2893: if (ref($authhash->{$context}) eq 'HASH') {
2894: %can_assign = %{$authhash->{$context}};
2895: }
2896: }
2897: }
2898: }
2899: my $authnum = 0;
2900: foreach my $key (keys(%can_assign)) {
2901: if ($can_assign{$key}) {
2902: $authnum ++;
2903: }
2904: }
2905: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2906: $authnum --;
2907: }
2908: return ($authnum,%can_assign);
2909: }
2910:
1.80 albertel 2911: ###############################################################
2912: ## Get Kerberos Defaults for Domain ##
2913: ###############################################################
2914: ##
2915: ## Returns default kerberos version and an associated argument
2916: ## as listed in file domain.tab. If not listed, provides
2917: ## appropriate default domain and kerberos version.
2918: ##
2919: #-------------------------------------------
2920:
2921: =pod
2922:
1.648 raeburn 2923: =item * &get_kerberos_defaults()
1.80 albertel 2924:
2925: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2926: version and domain. If not found, it defaults to version 4 and the
2927: domain of the server.
1.80 albertel 2928:
1.648 raeburn 2929: =over 4
2930:
1.80 albertel 2931: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2932:
1.648 raeburn 2933: =back
2934:
2935: =back
2936:
1.80 albertel 2937: =cut
2938:
2939: #-------------------------------------------
2940: sub get_kerberos_defaults {
2941: my $domain=shift;
1.641 raeburn 2942: my ($krbdef,$krbdefdom);
2943: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2944: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2945: $krbdef = $domdefaults{'auth_def'};
2946: $krbdefdom = $domdefaults{'auth_arg_def'};
2947: } else {
1.80 albertel 2948: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2949: my $krbdefdom=$1;
2950: $krbdefdom=~tr/a-z/A-Z/;
2951: $krbdef = "krb4";
2952: }
2953: return ($krbdef,$krbdefdom);
2954: }
1.112 bowersj2 2955:
1.32 matthew 2956:
1.46 matthew 2957: ###############################################################
2958: ## Thesaurus Functions ##
2959: ###############################################################
1.20 www 2960:
1.46 matthew 2961: =pod
1.20 www 2962:
1.112 bowersj2 2963: =head1 Thesaurus Functions
2964:
2965: =over 4
2966:
1.648 raeburn 2967: =item * &initialize_keywords()
1.46 matthew 2968:
2969: Initializes the package variable %Keywords if it is empty. Uses the
2970: package variable $thesaurus_db_file.
2971:
2972: =cut
2973:
2974: ###################################################
2975:
2976: sub initialize_keywords {
2977: return 1 if (scalar keys(%Keywords));
2978: # If we are here, %Keywords is empty, so fill it up
2979: # Make sure the file we need exists...
2980: if (! -e $thesaurus_db_file) {
2981: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2982: " failed because it does not exist");
2983: return 0;
2984: }
2985: # Set up the hash as a database
2986: my %thesaurus_db;
2987: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 2988: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 2989: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
2990: $thesaurus_db_file);
2991: return 0;
2992: }
2993: # Get the average number of appearances of a word.
2994: my $avecount = $thesaurus_db{'average.count'};
2995: # Put keywords (those that appear > average) into %Keywords
2996: while (my ($word,$data)=each (%thesaurus_db)) {
2997: my ($count,undef) = split /:/,$data;
2998: $Keywords{$word}++ if ($count > $avecount);
2999: }
3000: untie %thesaurus_db;
3001: # Remove special values from %Keywords.
1.356 albertel 3002: foreach my $value ('total.count','average.count') {
3003: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3004: }
1.46 matthew 3005: return 1;
3006: }
3007:
3008: ###################################################
3009:
3010: =pod
3011:
1.648 raeburn 3012: =item * &keyword($word)
1.46 matthew 3013:
3014: Returns true if $word is a keyword. A keyword is a word that appears more
3015: than the average number of times in the thesaurus database. Calls
3016: &initialize_keywords
3017:
3018: =cut
3019:
3020: ###################################################
1.20 www 3021:
3022: sub keyword {
1.46 matthew 3023: return if (!&initialize_keywords());
3024: my $word=lc(shift());
3025: $word=~s/\W//g;
3026: return exists($Keywords{$word});
1.20 www 3027: }
1.46 matthew 3028:
3029: ###############################################################
3030:
3031: =pod
1.20 www 3032:
1.648 raeburn 3033: =item * &get_related_words()
1.46 matthew 3034:
1.160 matthew 3035: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3036: an array of words. If the keyword is not in the thesaurus, an empty array
3037: will be returned. The order of the words returned is determined by the
3038: database which holds them.
3039:
3040: Uses global $thesaurus_db_file.
3041:
1.1057 foxr 3042:
1.46 matthew 3043: =cut
3044:
3045: ###############################################################
3046: sub get_related_words {
3047: my $keyword = shift;
3048: my %thesaurus_db;
3049: if (! -e $thesaurus_db_file) {
3050: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3051: "failed because the file does not exist");
3052: return ();
3053: }
3054: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3055: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3056: return ();
3057: }
3058: my @Words=();
1.429 www 3059: my $count=0;
1.46 matthew 3060: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3061: # The first element is the number of times
3062: # the word appears. We do not need it now.
1.429 www 3063: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3064: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3065: my $threshold=$mostfrequentcount/10;
3066: foreach my $possibleword (@RelatedWords) {
3067: my ($word,$wordcount)=split(/\,/,$possibleword);
3068: if ($wordcount>$threshold) {
3069: push(@Words,$word);
3070: $count++;
3071: if ($count>10) { last; }
3072: }
1.20 www 3073: }
3074: }
1.46 matthew 3075: untie %thesaurus_db;
3076: return @Words;
1.14 harris41 3077: }
1.46 matthew 3078:
1.112 bowersj2 3079: =pod
3080:
3081: =back
3082:
3083: =cut
1.61 www 3084:
3085: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3086: =pod
3087:
1.112 bowersj2 3088: =head1 User Name Functions
3089:
3090: =over 4
3091:
1.648 raeburn 3092: =item * &plainname($uname,$udom,$first)
1.81 albertel 3093:
1.112 bowersj2 3094: Takes a users logon name and returns it as a string in
1.226 albertel 3095: "first middle last generation" form
3096: if $first is set to 'lastname' then it returns it as
3097: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3098:
3099: =cut
1.61 www 3100:
1.295 www 3101:
1.81 albertel 3102: ###############################################################
1.61 www 3103: sub plainname {
1.226 albertel 3104: my ($uname,$udom,$first)=@_;
1.537 albertel 3105: return if (!defined($uname) || !defined($udom));
1.295 www 3106: my %names=&getnames($uname,$udom);
1.226 albertel 3107: my $name=&Apache::lonnet::format_name($names{'firstname'},
3108: $names{'middlename'},
3109: $names{'lastname'},
3110: $names{'generation'},$first);
3111: $name=~s/^\s+//;
1.62 www 3112: $name=~s/\s+$//;
3113: $name=~s/\s+/ /g;
1.353 albertel 3114: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3115: return $name;
1.61 www 3116: }
1.66 www 3117:
3118: # -------------------------------------------------------------------- Nickname
1.81 albertel 3119: =pod
3120:
1.648 raeburn 3121: =item * &nickname($uname,$udom)
1.81 albertel 3122:
3123: Gets a users name and returns it as a string as
3124:
3125: ""nickname""
1.66 www 3126:
1.81 albertel 3127: if the user has a nickname or
3128:
3129: "first middle last generation"
3130:
3131: if the user does not
3132:
3133: =cut
1.66 www 3134:
3135: sub nickname {
3136: my ($uname,$udom)=@_;
1.537 albertel 3137: return if (!defined($uname) || !defined($udom));
1.295 www 3138: my %names=&getnames($uname,$udom);
1.68 albertel 3139: my $name=$names{'nickname'};
1.66 www 3140: if ($name) {
3141: $name='"'.$name.'"';
3142: } else {
3143: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3144: $names{'lastname'}.' '.$names{'generation'};
3145: $name=~s/\s+$//;
3146: $name=~s/\s+/ /g;
3147: }
3148: return $name;
3149: }
3150:
1.295 www 3151: sub getnames {
3152: my ($uname,$udom)=@_;
1.537 albertel 3153: return if (!defined($uname) || !defined($udom));
1.433 albertel 3154: if ($udom eq 'public' && $uname eq 'public') {
3155: return ('lastname' => &mt('Public'));
3156: }
1.295 www 3157: my $id=$uname.':'.$udom;
3158: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3159: if ($cached) {
3160: return %{$names};
3161: } else {
3162: my %loadnames=&Apache::lonnet::get('environment',
3163: ['firstname','middlename','lastname','generation','nickname'],
3164: $udom,$uname);
3165: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3166: return %loadnames;
3167: }
3168: }
1.61 www 3169:
1.542 raeburn 3170: # -------------------------------------------------------------------- getemails
1.648 raeburn 3171:
1.542 raeburn 3172: =pod
3173:
1.648 raeburn 3174: =item * &getemails($uname,$udom)
1.542 raeburn 3175:
3176: Gets a user's email information and returns it as a hash with keys:
3177: notification, critnotification, permanentemail
3178:
3179: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3180: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3181:
1.648 raeburn 3182:
1.542 raeburn 3183: =cut
3184:
1.648 raeburn 3185:
1.466 albertel 3186: sub getemails {
3187: my ($uname,$udom)=@_;
3188: if ($udom eq 'public' && $uname eq 'public') {
3189: return;
3190: }
1.467 www 3191: if (!$udom) { $udom=$env{'user.domain'}; }
3192: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3193: my $id=$uname.':'.$udom;
3194: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3195: if ($cached) {
3196: return %{$names};
3197: } else {
3198: my %loadnames=&Apache::lonnet::get('environment',
3199: ['notification','critnotification',
3200: 'permanentemail'],
3201: $udom,$uname);
3202: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3203: return %loadnames;
3204: }
3205: }
3206:
1.551 albertel 3207: sub flush_email_cache {
3208: my ($uname,$udom)=@_;
3209: if (!$udom) { $udom =$env{'user.domain'}; }
3210: if (!$uname) { $uname=$env{'user.name'}; }
3211: return if ($udom eq 'public' && $uname eq 'public');
3212: my $id=$uname.':'.$udom;
3213: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3214: }
3215:
1.728 raeburn 3216: # -------------------------------------------------------------------- getlangs
3217:
3218: =pod
3219:
3220: =item * &getlangs($uname,$udom)
3221:
3222: Gets a user's language preference and returns it as a hash with key:
3223: language.
3224:
3225: =cut
3226:
3227:
3228: sub getlangs {
3229: my ($uname,$udom) = @_;
3230: if (!$udom) { $udom =$env{'user.domain'}; }
3231: if (!$uname) { $uname=$env{'user.name'}; }
3232: my $id=$uname.':'.$udom;
3233: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3234: if ($cached) {
3235: return %{$langs};
3236: } else {
3237: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3238: $udom,$uname);
3239: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3240: return %loadlangs;
3241: }
3242: }
3243:
3244: sub flush_langs_cache {
3245: my ($uname,$udom)=@_;
3246: if (!$udom) { $udom =$env{'user.domain'}; }
3247: if (!$uname) { $uname=$env{'user.name'}; }
3248: return if ($udom eq 'public' && $uname eq 'public');
3249: my $id=$uname.':'.$udom;
3250: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3251: }
3252:
1.61 www 3253: # ------------------------------------------------------------------ Screenname
1.81 albertel 3254:
3255: =pod
3256:
1.648 raeburn 3257: =item * &screenname($uname,$udom)
1.81 albertel 3258:
3259: Gets a users screenname and returns it as a string
3260:
3261: =cut
1.61 www 3262:
3263: sub screenname {
3264: my ($uname,$udom)=@_;
1.258 albertel 3265: if ($uname eq $env{'user.name'} &&
3266: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3267: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3268: return $names{'screenname'};
1.62 www 3269: }
3270:
1.212 albertel 3271:
1.802 bisitz 3272: # ------------------------------------------------------------- Confirm Wrapper
3273: =pod
3274:
1.1075.2.42 raeburn 3275: =item * &confirmwrapper($message)
1.802 bisitz 3276:
3277: Wrap messages about completion of operation in box
3278:
3279: =cut
3280:
3281: sub confirmwrapper {
3282: my ($message)=@_;
3283: if ($message) {
3284: return "\n".'<div class="LC_confirm_box">'."\n"
3285: .$message."\n"
3286: .'</div>'."\n";
3287: } else {
3288: return $message;
3289: }
3290: }
3291:
1.62 www 3292: # ------------------------------------------------------------- Message Wrapper
3293:
3294: sub messagewrapper {
1.369 www 3295: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3296: return
1.441 albertel 3297: '<a href="/adm/email?compose=individual&'.
3298: 'recname='.$username.'&recdom='.$domain.
3299: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3300: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3301: }
1.802 bisitz 3302:
1.74 www 3303: # --------------------------------------------------------------- Notes Wrapper
3304:
3305: sub noteswrapper {
3306: my ($link,$un,$do)=@_;
3307: return
1.896 amueller 3308: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3309: }
1.802 bisitz 3310:
1.62 www 3311: # ------------------------------------------------------------- Aboutme Wrapper
3312:
3313: sub aboutmewrapper {
1.1070 raeburn 3314: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3315: if (!defined($username) && !defined($domain)) {
3316: return;
3317: }
1.1075.2.15 raeburn 3318: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3319: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3320: }
3321:
3322: # ------------------------------------------------------------ Syllabus Wrapper
3323:
3324: sub syllabuswrapper {
1.707 bisitz 3325: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3326: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3327: }
1.14 harris41 3328:
1.802 bisitz 3329: # -----------------------------------------------------------------------------
3330:
1.208 matthew 3331: sub track_student_link {
1.887 raeburn 3332: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3333: my $link ="/adm/trackstudent?";
1.208 matthew 3334: my $title = 'View recent activity';
3335: if (defined($sname) && $sname !~ /^\s*$/ &&
3336: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3337: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3338: $title .= ' of this student';
1.268 albertel 3339: }
1.208 matthew 3340: if (defined($target) && $target !~ /^\s*$/) {
3341: $target = qq{target="$target"};
3342: } else {
3343: $target = '';
3344: }
1.268 albertel 3345: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3346: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3347: $title = &mt($title);
3348: $linktext = &mt($linktext);
1.448 albertel 3349: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3350: &help_open_topic('View_recent_activity');
1.208 matthew 3351: }
3352:
1.781 raeburn 3353: sub slot_reservations_link {
3354: my ($linktext,$sname,$sdom,$target) = @_;
3355: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3356: my $title = 'View slot reservation history';
3357: if (defined($sname) && $sname !~ /^\s*$/ &&
3358: defined($sdom) && $sdom !~ /^\s*$/) {
3359: $link .= "&uname=$sname&udom=$sdom";
3360: $title .= ' of this student';
3361: }
3362: if (defined($target) && $target !~ /^\s*$/) {
3363: $target = qq{target="$target"};
3364: } else {
3365: $target = '';
3366: }
3367: $title = &mt($title);
3368: $linktext = &mt($linktext);
3369: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3370: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3371:
3372: }
3373:
1.508 www 3374: # ===================================================== Display a student photo
3375:
3376:
1.509 albertel 3377: sub student_image_tag {
1.508 www 3378: my ($domain,$user)=@_;
3379: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3380: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3381: return '<img src="'.$imgsrc.'" align="right" />';
3382: } else {
3383: return '';
3384: }
3385: }
3386:
1.112 bowersj2 3387: =pod
3388:
3389: =back
3390:
3391: =head1 Access .tab File Data
3392:
3393: =over 4
3394:
1.648 raeburn 3395: =item * &languageids()
1.112 bowersj2 3396:
3397: returns list of all language ids
3398:
3399: =cut
3400:
1.14 harris41 3401: sub languageids {
1.16 harris41 3402: return sort(keys(%language));
1.14 harris41 3403: }
3404:
1.112 bowersj2 3405: =pod
3406:
1.648 raeburn 3407: =item * &languagedescription()
1.112 bowersj2 3408:
3409: returns description of a specified language id
3410:
3411: =cut
3412:
1.14 harris41 3413: sub languagedescription {
1.125 www 3414: my $code=shift;
3415: return ($supported_language{$code}?'* ':'').
3416: $language{$code}.
1.126 www 3417: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3418: }
3419:
1.1048 foxr 3420: =pod
3421:
3422: =item * &plainlanguagedescription
3423:
3424: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3425: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3426:
3427: =cut
3428:
1.145 www 3429: sub plainlanguagedescription {
3430: my $code=shift;
3431: return $language{$code};
3432: }
3433:
1.1048 foxr 3434: =pod
3435:
3436: =item * &supportedlanguagecode
3437:
3438: Returns the supported language code (e.g. sptutf maps to pt) given a language
3439: code.
3440:
3441: =cut
3442:
1.145 www 3443: sub supportedlanguagecode {
3444: my $code=shift;
3445: return $supported_language{$code};
1.97 www 3446: }
3447:
1.112 bowersj2 3448: =pod
3449:
1.1048 foxr 3450: =item * &latexlanguage()
3451:
3452: Given a language key code returns the correspondnig language to use
3453: to select the correct hyphenation on LaTeX printouts. This is undef if there
3454: is no supported hyphenation for the language code.
3455:
3456: =cut
3457:
3458: sub latexlanguage {
3459: my $code = shift;
3460: return $latex_language{$code};
3461: }
3462:
3463: =pod
3464:
3465: =item * &latexhyphenation()
3466:
3467: Same as above but what's supplied is the language as it might be stored
3468: in the metadata.
3469:
3470: =cut
3471:
3472: sub latexhyphenation {
3473: my $key = shift;
3474: return $latex_language_bykey{$key};
3475: }
3476:
3477: =pod
3478:
1.648 raeburn 3479: =item * ©rightids()
1.112 bowersj2 3480:
3481: returns list of all copyrights
3482:
3483: =cut
3484:
3485: sub copyrightids {
3486: return sort(keys(%cprtag));
3487: }
3488:
3489: =pod
3490:
1.648 raeburn 3491: =item * ©rightdescription()
1.112 bowersj2 3492:
3493: returns description of a specified copyright id
3494:
3495: =cut
3496:
3497: sub copyrightdescription {
1.166 www 3498: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3499: }
1.197 matthew 3500:
3501: =pod
3502:
1.648 raeburn 3503: =item * &source_copyrightids()
1.192 taceyjo1 3504:
3505: returns list of all source copyrights
3506:
3507: =cut
3508:
3509: sub source_copyrightids {
3510: return sort(keys(%scprtag));
3511: }
3512:
3513: =pod
3514:
1.648 raeburn 3515: =item * &source_copyrightdescription()
1.192 taceyjo1 3516:
3517: returns description of a specified source copyright id
3518:
3519: =cut
3520:
3521: sub source_copyrightdescription {
3522: return &mt($scprtag{shift(@_)});
3523: }
1.112 bowersj2 3524:
3525: =pod
3526:
1.648 raeburn 3527: =item * &filecategories()
1.112 bowersj2 3528:
3529: returns list of all file categories
3530:
3531: =cut
3532:
3533: sub filecategories {
3534: return sort(keys(%category_extensions));
3535: }
3536:
3537: =pod
3538:
1.648 raeburn 3539: =item * &filecategorytypes()
1.112 bowersj2 3540:
3541: returns list of file types belonging to a given file
3542: category
3543:
3544: =cut
3545:
3546: sub filecategorytypes {
1.356 albertel 3547: my ($cat) = @_;
3548: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3549: }
3550:
3551: =pod
3552:
1.648 raeburn 3553: =item * &fileembstyle()
1.112 bowersj2 3554:
3555: returns embedding style for a specified file type
3556:
3557: =cut
3558:
3559: sub fileembstyle {
3560: return $fe{lc(shift(@_))};
1.169 www 3561: }
3562:
1.351 www 3563: sub filemimetype {
3564: return $fm{lc(shift(@_))};
3565: }
3566:
1.169 www 3567:
3568: sub filecategoryselect {
3569: my ($name,$value)=@_;
1.189 matthew 3570: return &select_form($value,$name,
1.970 raeburn 3571: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3572: }
3573:
3574: =pod
3575:
1.648 raeburn 3576: =item * &filedescription()
1.112 bowersj2 3577:
3578: returns description for a specified file type
3579:
3580: =cut
3581:
3582: sub filedescription {
1.188 matthew 3583: my $file_description = $fd{lc(shift())};
3584: $file_description =~ s:([\[\]]):~$1:g;
3585: return &mt($file_description);
1.112 bowersj2 3586: }
3587:
3588: =pod
3589:
1.648 raeburn 3590: =item * &filedescriptionex()
1.112 bowersj2 3591:
3592: returns description for a specified file type with
3593: extra formatting
3594:
3595: =cut
3596:
3597: sub filedescriptionex {
3598: my $ex=shift;
1.188 matthew 3599: my $file_description = $fd{lc($ex)};
3600: $file_description =~ s:([\[\]]):~$1:g;
3601: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3602: }
3603:
3604: # End of .tab access
3605: =pod
3606:
3607: =back
3608:
3609: =cut
3610:
3611: # ------------------------------------------------------------------ File Types
3612: sub fileextensions {
3613: return sort(keys(%fe));
3614: }
3615:
1.97 www 3616: # ----------------------------------------------------------- Display Languages
3617: # returns a hash with all desired display languages
3618: #
3619:
3620: sub display_languages {
3621: my %languages=();
1.695 raeburn 3622: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3623: $languages{$lang}=1;
1.97 www 3624: }
3625: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3626: if ($env{'form.displaylanguage'}) {
1.356 albertel 3627: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3628: $languages{$lang}=1;
1.97 www 3629: }
3630: }
3631: return %languages;
1.14 harris41 3632: }
3633:
1.582 albertel 3634: sub languages {
3635: my ($possible_langs) = @_;
1.695 raeburn 3636: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3637: if (!ref($possible_langs)) {
3638: if( wantarray ) {
3639: return @preferred_langs;
3640: } else {
3641: return $preferred_langs[0];
3642: }
3643: }
3644: my %possibilities = map { $_ => 1 } (@$possible_langs);
3645: my @preferred_possibilities;
3646: foreach my $preferred_lang (@preferred_langs) {
3647: if (exists($possibilities{$preferred_lang})) {
3648: push(@preferred_possibilities, $preferred_lang);
3649: }
3650: }
3651: if( wantarray ) {
3652: return @preferred_possibilities;
3653: }
3654: return $preferred_possibilities[0];
3655: }
3656:
1.742 raeburn 3657: sub user_lang {
3658: my ($touname,$toudom,$fromcid) = @_;
3659: my @userlangs;
3660: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3661: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3662: $env{'course.'.$fromcid.'.languages'}));
3663: } else {
3664: my %langhash = &getlangs($touname,$toudom);
3665: if ($langhash{'languages'} ne '') {
3666: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3667: } else {
3668: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3669: if ($domdefs{'lang_def'} ne '') {
3670: @userlangs = ($domdefs{'lang_def'});
3671: }
3672: }
3673: }
3674: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3675: my $user_lh = Apache::localize->get_handle(@languages);
3676: return $user_lh;
3677: }
3678:
3679:
1.112 bowersj2 3680: ###############################################################
3681: ## Student Answer Attempts ##
3682: ###############################################################
3683:
3684: =pod
3685:
3686: =head1 Alternate Problem Views
3687:
3688: =over 4
3689:
1.648 raeburn 3690: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1075.2.86 raeburn 3691: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 3692:
3693: Return string with previous attempt on problem. Arguments:
3694:
3695: =over 4
3696:
3697: =item * $symb: Problem, including path
3698:
3699: =item * $username: username of the desired student
3700:
3701: =item * $domain: domain of the desired student
1.14 harris41 3702:
1.112 bowersj2 3703: =item * $course: Course ID
1.14 harris41 3704:
1.112 bowersj2 3705: =item * $getattempt: Leave blank for all attempts, otherwise put
3706: something
1.14 harris41 3707:
1.112 bowersj2 3708: =item * $regexp: if string matches this regexp, the string will be
3709: sent to $gradesub
1.14 harris41 3710:
1.112 bowersj2 3711: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3712:
1.1075.2.86 raeburn 3713: =item * $usec: section of the desired student
3714:
3715: =item * $identifier: counter for student (multiple students one problem) or
3716: problem (one student; whole sequence).
3717:
1.112 bowersj2 3718: =back
1.14 harris41 3719:
1.112 bowersj2 3720: The output string is a table containing all desired attempts, if any.
1.16 harris41 3721:
1.112 bowersj2 3722: =cut
1.1 albertel 3723:
3724: sub get_previous_attempt {
1.1075.2.86 raeburn 3725: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 3726: my $prevattempts='';
1.43 ng 3727: no strict 'refs';
1.1 albertel 3728: if ($symb) {
1.3 albertel 3729: my (%returnhash)=
3730: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3731: if ($returnhash{'version'}) {
3732: my %lasthash=();
3733: my $version;
3734: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.91 raeburn 3735: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
3736: if ($key =~ /\.rawrndseed$/) {
3737: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
3738: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
3739: } else {
3740: $lasthash{$key}=$returnhash{$version.':'.$key};
3741: }
1.19 harris41 3742: }
1.1 albertel 3743: }
1.596 albertel 3744: $prevattempts=&start_data_table().&start_data_table_header_row();
3745: $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86 raeburn 3746: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 3747: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3748: foreach my $key (sort(keys(%lasthash))) {
3749: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3750: if ($#parts > 0) {
1.31 albertel 3751: my $data=$parts[-1];
1.989 raeburn 3752: next if ($data eq 'foilorder');
1.31 albertel 3753: pop(@parts);
1.1010 www 3754: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3755: if ($data eq 'type') {
3756: unless ($showsurv) {
3757: my $id = join(',',@parts);
3758: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3759: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3760: $lasthidden{$ign.'.'.$id} = 1;
3761: }
1.945 raeburn 3762: }
1.1075.2.86 raeburn 3763: if ($identifier ne '') {
3764: my $id = join(',',@parts);
3765: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
3766: $domain,$username,$usec,undef,$course) =~ /^no/) {
3767: $hidestatus{$ign.'.'.$id} = 1;
3768: }
3769: }
3770: } elsif ($data eq 'regrader') {
3771: if (($identifier ne '') && (@parts)) {
3772: my $id = join(',',@parts);
3773: $regraded{$ign.'.'.$id} = 1;
3774: }
1.1010 www 3775: }
1.31 albertel 3776: } else {
1.41 ng 3777: if ($#parts == 0) {
3778: $prevattempts.='<th>'.$parts[0].'</th>';
3779: } else {
3780: $prevattempts.='<th>'.$ign.'</th>';
3781: }
1.31 albertel 3782: }
1.16 harris41 3783: }
1.596 albertel 3784: $prevattempts.=&end_data_table_header_row();
1.40 ng 3785: if ($getattempt eq '') {
1.1075.2.86 raeburn 3786: my (%solved,%resets,%probstatus);
3787: if (($identifier ne '') && (keys(%regraded) > 0)) {
3788: for ($version=1;$version<=$returnhash{'version'};$version++) {
3789: foreach my $id (keys(%regraded)) {
3790: if (($returnhash{$version.':'.$id.'.regrader'}) &&
3791: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
3792: ($returnhash{$version.':'.$id.'.award'} eq '')) {
3793: push(@{$resets{$id}},$version);
3794: }
3795: }
3796: }
3797: }
1.40 ng 3798: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86 raeburn 3799: my (@hidden,@unsolved);
1.945 raeburn 3800: if (%typeparts) {
3801: foreach my $id (keys(%typeparts)) {
1.1075.2.86 raeburn 3802: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
3803: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 3804: push(@hidden,$id);
1.1075.2.86 raeburn 3805: } elsif ($identifier ne '') {
3806: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
3807: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
3808: ($hidestatus{$id})) {
3809: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
3810: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
3811: push(@{$solved{$id}},$version);
3812: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
3813: (ref($solved{$id}) eq 'ARRAY')) {
3814: my $skip;
3815: if (ref($resets{$id}) eq 'ARRAY') {
3816: foreach my $reset (@{$resets{$id}}) {
3817: if ($reset > $solved{$id}[-1]) {
3818: $skip=1;
3819: last;
3820: }
3821: }
3822: }
3823: unless ($skip) {
3824: my ($ign,$partslist) = split(/\./,$id,2);
3825: push(@unsolved,$partslist);
3826: }
3827: }
3828: }
1.945 raeburn 3829: }
3830: }
3831: }
3832: $prevattempts.=&start_data_table_row().
1.1075.2.86 raeburn 3833: '<td>'.&mt('Transaction [_1]',$version);
3834: if (@unsolved) {
3835: $prevattempts .= '<span class="LC_nobreak"><label>'.
3836: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
3837: &mt('Hide').'</label></span>';
3838: }
3839: $prevattempts .= '</td>';
1.945 raeburn 3840: if (@hidden) {
3841: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3842: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3843: my $hide;
3844: foreach my $id (@hidden) {
3845: if ($key =~ /^\Q$id\E/) {
3846: $hide = 1;
3847: last;
3848: }
3849: }
3850: if ($hide) {
3851: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3852: if (($data eq 'award') || ($data eq 'awarddetail')) {
3853: my $value = &format_previous_attempt_value($key,
3854: $returnhash{$version.':'.$key});
3855: $prevattempts.='<td>'.$value.' </td>';
3856: } else {
3857: $prevattempts.='<td> </td>';
3858: }
3859: } else {
3860: if ($key =~ /\./) {
1.1075.2.91 raeburn 3861: my $value = $returnhash{$version.':'.$key};
3862: if ($key =~ /\.rndseed$/) {
3863: my ($id) = ($key =~ /^(.+)\.rndseed$/);
3864: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
3865: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
3866: }
3867: }
3868: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
3869: ' </td>';
1.945 raeburn 3870: } else {
3871: $prevattempts.='<td> </td>';
3872: }
3873: }
3874: }
3875: } else {
3876: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3877: next if ($key =~ /\.foilorder$/);
1.1075.2.91 raeburn 3878: my $value = $returnhash{$version.':'.$key};
3879: if ($key =~ /\.rndseed$/) {
3880: my ($id) = ($key =~ /^(.+)\.rndseed$/);
3881: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
3882: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
3883: }
3884: }
3885: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
3886: ' </td>';
1.945 raeburn 3887: }
3888: }
3889: $prevattempts.=&end_data_table_row();
1.40 ng 3890: }
1.1 albertel 3891: }
1.945 raeburn 3892: my @currhidden = keys(%lasthidden);
1.596 albertel 3893: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3894: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3895: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3896: if (%typeparts) {
3897: my $hidden;
3898: foreach my $id (@currhidden) {
3899: if ($key =~ /^\Q$id\E/) {
3900: $hidden = 1;
3901: last;
3902: }
3903: }
3904: if ($hidden) {
3905: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3906: if (($data eq 'award') || ($data eq 'awarddetail')) {
3907: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3908: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3909: $value = &$gradesub($value);
3910: }
3911: $prevattempts.='<td>'.$value.' </td>';
3912: } else {
3913: $prevattempts.='<td> </td>';
3914: }
3915: } else {
3916: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3917: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3918: $value = &$gradesub($value);
3919: }
3920: $prevattempts.='<td>'.$value.' </td>';
3921: }
3922: } else {
3923: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3924: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3925: $value = &$gradesub($value);
3926: }
3927: $prevattempts.='<td>'.$value.' </td>';
3928: }
1.16 harris41 3929: }
1.596 albertel 3930: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3931: } else {
1.596 albertel 3932: $prevattempts=
3933: &start_data_table().&start_data_table_row().
3934: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3935: &end_data_table_row().&end_data_table();
1.1 albertel 3936: }
3937: } else {
1.596 albertel 3938: $prevattempts=
3939: &start_data_table().&start_data_table_row().
3940: '<td>'.&mt('No data.').'</td>'.
3941: &end_data_table_row().&end_data_table();
1.1 albertel 3942: }
1.10 albertel 3943: }
3944:
1.581 albertel 3945: sub format_previous_attempt_value {
3946: my ($key,$value) = @_;
1.1011 www 3947: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 3948: $value = &Apache::lonlocal::locallocaltime($value);
3949: } elsif (ref($value) eq 'ARRAY') {
3950: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 3951: } elsif ($key =~ /answerstring$/) {
3952: my %answers = &Apache::lonnet::str2hash($value);
3953: my @anskeys = sort(keys(%answers));
3954: if (@anskeys == 1) {
3955: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3956: if ($answer =~ m{\0}) {
3957: $answer =~ s{\0}{,}g;
1.988 raeburn 3958: }
3959: my $tag_internal_answer_name = 'INTERNAL';
3960: if ($anskeys[0] eq $tag_internal_answer_name) {
3961: $value = $answer;
3962: } else {
3963: $value = $anskeys[0].'='.$answer;
3964: }
3965: } else {
3966: foreach my $ans (@anskeys) {
3967: my $answer = $answers{$ans};
1.1001 raeburn 3968: if ($answer =~ m{\0}) {
3969: $answer =~ s{\0}{,}g;
1.988 raeburn 3970: }
3971: $value .= $ans.'='.$answer.'<br />';;
3972: }
3973: }
1.581 albertel 3974: } else {
3975: $value = &unescape($value);
3976: }
3977: return $value;
3978: }
3979:
3980:
1.107 albertel 3981: sub relative_to_absolute {
3982: my ($url,$output)=@_;
3983: my $parser=HTML::TokeParser->new(\$output);
3984: my $token;
3985: my $thisdir=$url;
3986: my @rlinks=();
3987: while ($token=$parser->get_token) {
3988: if ($token->[0] eq 'S') {
3989: if ($token->[1] eq 'a') {
3990: if ($token->[2]->{'href'}) {
3991: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3992: }
3993: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3994: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3995: } elsif ($token->[1] eq 'base') {
3996: $thisdir=$token->[2]->{'href'};
3997: }
3998: }
3999: }
4000: $thisdir=~s-/[^/]*$--;
1.356 albertel 4001: foreach my $link (@rlinks) {
1.726 raeburn 4002: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4003: ($link=~/^\//) ||
4004: ($link=~/^javascript:/i) ||
4005: ($link=~/^mailto:/i) ||
4006: ($link=~/^\#/)) {
4007: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4008: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4009: }
4010: }
4011: # -------------------------------------------------- Deal with Applet codebases
4012: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4013: return $output;
4014: }
4015:
1.112 bowersj2 4016: =pod
4017:
1.648 raeburn 4018: =item * &get_student_view()
1.112 bowersj2 4019:
4020: show a snapshot of what student was looking at
4021:
4022: =cut
4023:
1.10 albertel 4024: sub get_student_view {
1.186 albertel 4025: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4026: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4027: my (%form);
1.10 albertel 4028: my @elements=('symb','courseid','domain','username');
4029: foreach my $element (@elements) {
1.186 albertel 4030: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4031: }
1.186 albertel 4032: if (defined($moreenv)) {
4033: %form=(%form,%{$moreenv});
4034: }
1.236 albertel 4035: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4036: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4037: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4038: $userview=~s/\<body[^\>]*\>//gi;
4039: $userview=~s/\<\/body\>//gi;
4040: $userview=~s/\<html\>//gi;
4041: $userview=~s/\<\/html\>//gi;
4042: $userview=~s/\<head\>//gi;
4043: $userview=~s/\<\/head\>//gi;
4044: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4045: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4046: if (wantarray) {
4047: return ($userview,$response);
4048: } else {
4049: return $userview;
4050: }
4051: }
4052:
4053: sub get_student_view_with_retries {
4054: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4055:
4056: my $ok = 0; # True if we got a good response.
4057: my $content;
4058: my $response;
4059:
4060: # Try to get the student_view done. within the retries count:
4061:
4062: do {
4063: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4064: $ok = $response->is_success;
4065: if (!$ok) {
4066: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4067: }
4068: $retries--;
4069: } while (!$ok && ($retries > 0));
4070:
4071: if (!$ok) {
4072: $content = ''; # On error return an empty content.
4073: }
1.651 www 4074: if (wantarray) {
4075: return ($content, $response);
4076: } else {
4077: return $content;
4078: }
1.11 albertel 4079: }
4080:
1.112 bowersj2 4081: =pod
4082:
1.648 raeburn 4083: =item * &get_student_answers()
1.112 bowersj2 4084:
4085: show a snapshot of how student was answering problem
4086:
4087: =cut
4088:
1.11 albertel 4089: sub get_student_answers {
1.100 sakharuk 4090: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4091: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4092: my (%moreenv);
1.11 albertel 4093: my @elements=('symb','courseid','domain','username');
4094: foreach my $element (@elements) {
1.186 albertel 4095: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4096: }
1.186 albertel 4097: $moreenv{'grade_target'}='answer';
4098: %moreenv=(%form,%moreenv);
1.497 raeburn 4099: $feedurl = &Apache::lonnet::clutter($feedurl);
4100: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4101: return $userview;
1.1 albertel 4102: }
1.116 albertel 4103:
4104: =pod
4105:
4106: =item * &submlink()
4107:
1.242 albertel 4108: Inputs: $text $uname $udom $symb $target
1.116 albertel 4109:
4110: Returns: A link to grades.pm such as to see the SUBM view of a student
4111:
4112: =cut
4113:
4114: ###############################################
4115: sub submlink {
1.242 albertel 4116: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4117: if (!($uname && $udom)) {
4118: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4119: &Apache::lonnet::whichuser($symb);
1.116 albertel 4120: if (!$symb) { $symb=$cursymb; }
4121: }
1.254 matthew 4122: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4123: $symb=&escape($symb);
1.960 bisitz 4124: if ($target) { $target=" target=\"$target\""; }
4125: return
4126: '<a href="/adm/grades?command=submission'.
4127: '&symb='.$symb.
4128: '&student='.$uname.
4129: '&userdom='.$udom.'"'.
4130: $target.'>'.$text.'</a>';
1.242 albertel 4131: }
4132: ##############################################
4133:
4134: =pod
4135:
4136: =item * &pgrdlink()
4137:
4138: Inputs: $text $uname $udom $symb $target
4139:
4140: Returns: A link to grades.pm such as to see the PGRD view of a student
4141:
4142: =cut
4143:
4144: ###############################################
4145: sub pgrdlink {
4146: my $link=&submlink(@_);
4147: $link=~s/(&command=submission)/$1&showgrading=yes/;
4148: return $link;
4149: }
4150: ##############################################
4151:
4152: =pod
4153:
4154: =item * &pprmlink()
4155:
4156: Inputs: $text $uname $udom $symb $target
4157:
4158: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4159: student and a specific resource
1.242 albertel 4160:
4161: =cut
4162:
4163: ###############################################
4164: sub pprmlink {
4165: my ($text,$uname,$udom,$symb,$target)=@_;
4166: if (!($uname && $udom)) {
4167: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4168: &Apache::lonnet::whichuser($symb);
1.242 albertel 4169: if (!$symb) { $symb=$cursymb; }
4170: }
1.254 matthew 4171: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4172: $symb=&escape($symb);
1.242 albertel 4173: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4174: return '<a href="/adm/parmset?command=set&'.
4175: 'symb='.$symb.'&uname='.$uname.
4176: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4177: }
4178: ##############################################
1.37 matthew 4179:
1.112 bowersj2 4180: =pod
4181:
4182: =back
4183:
4184: =cut
4185:
1.37 matthew 4186: ###############################################
1.51 www 4187:
4188:
4189: sub timehash {
1.687 raeburn 4190: my ($thistime) = @_;
4191: my $timezone = &Apache::lonlocal::gettimezone();
4192: my $dt = DateTime->from_epoch(epoch => $thistime)
4193: ->set_time_zone($timezone);
4194: my $wday = $dt->day_of_week();
4195: if ($wday == 7) { $wday = 0; }
4196: return ( 'second' => $dt->second(),
4197: 'minute' => $dt->minute(),
4198: 'hour' => $dt->hour(),
4199: 'day' => $dt->day_of_month(),
4200: 'month' => $dt->month(),
4201: 'year' => $dt->year(),
4202: 'weekday' => $wday,
4203: 'dayyear' => $dt->day_of_year(),
4204: 'dlsav' => $dt->is_dst() );
1.51 www 4205: }
4206:
1.370 www 4207: sub utc_string {
4208: my ($date)=@_;
1.371 www 4209: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4210: }
4211:
1.51 www 4212: sub maketime {
4213: my %th=@_;
1.687 raeburn 4214: my ($epoch_time,$timezone,$dt);
4215: $timezone = &Apache::lonlocal::gettimezone();
4216: eval {
4217: $dt = DateTime->new( year => $th{'year'},
4218: month => $th{'month'},
4219: day => $th{'day'},
4220: hour => $th{'hour'},
4221: minute => $th{'minute'},
4222: second => $th{'second'},
4223: time_zone => $timezone,
4224: );
4225: };
4226: if (!$@) {
4227: $epoch_time = $dt->epoch;
4228: if ($epoch_time) {
4229: return $epoch_time;
4230: }
4231: }
1.51 www 4232: return POSIX::mktime(
4233: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4234: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4235: }
4236:
4237: #########################################
1.51 www 4238:
4239: sub findallcourses {
1.482 raeburn 4240: my ($roles,$uname,$udom) = @_;
1.355 albertel 4241: my %roles;
4242: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4243: my %courses;
1.51 www 4244: my $now=time;
1.482 raeburn 4245: if (!defined($uname)) {
4246: $uname = $env{'user.name'};
4247: }
4248: if (!defined($udom)) {
4249: $udom = $env{'user.domain'};
4250: }
4251: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4252: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4253: if (!%roles) {
4254: %roles = (
4255: cc => 1,
1.907 raeburn 4256: co => 1,
1.482 raeburn 4257: in => 1,
4258: ep => 1,
4259: ta => 1,
4260: cr => 1,
4261: st => 1,
4262: );
4263: }
4264: foreach my $entry (keys(%roleshash)) {
4265: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4266: if ($trole =~ /^cr/) {
4267: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4268: } else {
4269: next if (!exists($roles{$trole}));
4270: }
4271: if ($tend) {
4272: next if ($tend < $now);
4273: }
4274: if ($tstart) {
4275: next if ($tstart > $now);
4276: }
1.1058 raeburn 4277: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4278: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4279: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4280: if ($secpart eq '') {
4281: ($cnum,$role) = split(/_/,$cnumpart);
4282: $sec = 'none';
1.1058 raeburn 4283: $value .= $cnum.'/';
1.482 raeburn 4284: } else {
4285: $cnum = $cnumpart;
4286: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4287: $value .= $cnum.'/'.$sec;
4288: }
4289: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4290: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4291: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4292: }
4293: } else {
4294: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4295: }
1.482 raeburn 4296: }
4297: } else {
4298: foreach my $key (keys(%env)) {
1.483 albertel 4299: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4300: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4301: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4302: next if ($role eq 'ca' || $role eq 'aa');
4303: next if (%roles && !exists($roles{$role}));
4304: my ($starttime,$endtime)=split(/\./,$env{$key});
4305: my $active=1;
4306: if ($starttime) {
4307: if ($now<$starttime) { $active=0; }
4308: }
4309: if ($endtime) {
4310: if ($now>$endtime) { $active=0; }
4311: }
4312: if ($active) {
1.1058 raeburn 4313: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4314: if ($sec eq '') {
4315: $sec = 'none';
1.1058 raeburn 4316: } else {
4317: $value .= $sec;
4318: }
4319: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4320: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4321: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4322: }
4323: } else {
4324: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4325: }
1.474 raeburn 4326: }
4327: }
1.51 www 4328: }
4329: }
1.474 raeburn 4330: return %courses;
1.51 www 4331: }
1.37 matthew 4332:
1.54 www 4333: ###############################################
1.474 raeburn 4334:
4335: sub blockcheck {
1.1075.2.73 raeburn 4336: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4337:
1.1075.2.73 raeburn 4338: if (defined($udom) && defined($uname)) {
4339: # If uname and udom are for a course, check for blocks in the course.
4340: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4341: my ($startblock,$endblock,$triggerblock) =
4342: &get_blocks($setters,$activity,$udom,$uname,$url);
4343: return ($startblock,$endblock,$triggerblock);
4344: }
4345: } else {
1.490 raeburn 4346: $udom = $env{'user.domain'};
4347: $uname = $env{'user.name'};
4348: }
4349:
1.502 raeburn 4350: my $startblock = 0;
4351: my $endblock = 0;
1.1062 raeburn 4352: my $triggerblock = '';
1.482 raeburn 4353: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4354:
1.490 raeburn 4355: # If uname is for a user, and activity is course-specific, i.e.,
4356: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4357:
1.490 raeburn 4358: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.73 raeburn 4359: $activity eq 'groups' || $activity eq 'printout') &&
4360: ($env{'request.course.id'})) {
1.490 raeburn 4361: foreach my $key (keys(%live_courses)) {
4362: if ($key ne $env{'request.course.id'}) {
4363: delete($live_courses{$key});
4364: }
4365: }
4366: }
4367:
4368: my $otheruser = 0;
4369: my %own_courses;
4370: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4371: # Resource belongs to user other than current user.
4372: $otheruser = 1;
4373: # Gather courses for current user
4374: %own_courses =
4375: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4376: }
4377:
4378: # Gather active course roles - course coordinator, instructor,
4379: # exam proctor, ta, student, or custom role.
1.474 raeburn 4380:
4381: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4382: my ($cdom,$cnum);
4383: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4384: $cdom = $env{'course.'.$course.'.domain'};
4385: $cnum = $env{'course.'.$course.'.num'};
4386: } else {
1.490 raeburn 4387: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4388: }
4389: my $no_ownblock = 0;
4390: my $no_userblock = 0;
1.533 raeburn 4391: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4392: # Check if current user has 'evb' priv for this
4393: if (defined($own_courses{$course})) {
4394: foreach my $sec (keys(%{$own_courses{$course}})) {
4395: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4396: if ($sec ne 'none') {
4397: $checkrole .= '/'.$sec;
4398: }
4399: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4400: $no_ownblock = 1;
4401: last;
4402: }
4403: }
4404: }
4405: # if they have 'evb' priv and are currently not playing student
4406: next if (($no_ownblock) &&
4407: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4408: }
1.474 raeburn 4409: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4410: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4411: if ($sec ne 'none') {
1.482 raeburn 4412: $checkrole .= '/'.$sec;
1.474 raeburn 4413: }
1.490 raeburn 4414: if ($otheruser) {
4415: # Resource belongs to user other than current user.
4416: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4417: my (%allroles,%userroles);
4418: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4419: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4420: my ($trole,$tdom,$tnum,$tsec);
4421: if ($entry =~ /^cr/) {
4422: ($trole,$tdom,$tnum,$tsec) =
4423: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4424: } else {
4425: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4426: }
4427: my ($spec,$area,$trest);
4428: $area = '/'.$tdom.'/'.$tnum;
4429: $trest = $tnum;
4430: if ($tsec ne '') {
4431: $area .= '/'.$tsec;
4432: $trest .= '/'.$tsec;
4433: }
4434: $spec = $trole.'.'.$area;
4435: if ($trole =~ /^cr/) {
4436: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4437: $tdom,$spec,$trest,$area);
4438: } else {
4439: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4440: $tdom,$spec,$trest,$area);
4441: }
4442: }
4443: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4444: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4445: if ($1) {
4446: $no_userblock = 1;
4447: last;
4448: }
1.486 raeburn 4449: }
4450: }
1.490 raeburn 4451: } else {
4452: # Resource belongs to current user
4453: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4454: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4455: $no_ownblock = 1;
4456: last;
4457: }
1.474 raeburn 4458: }
4459: }
4460: # if they have the evb priv and are currently not playing student
1.482 raeburn 4461: next if (($no_ownblock) &&
1.491 albertel 4462: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4463: next if ($no_userblock);
1.474 raeburn 4464:
1.866 kalberla 4465: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4466: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4467:
1.1062 raeburn 4468: my ($start,$end,$trigger) =
4469: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4470: if (($start != 0) &&
4471: (($startblock == 0) || ($startblock > $start))) {
4472: $startblock = $start;
1.1062 raeburn 4473: if ($trigger ne '') {
4474: $triggerblock = $trigger;
4475: }
1.502 raeburn 4476: }
4477: if (($end != 0) &&
4478: (($endblock == 0) || ($endblock < $end))) {
4479: $endblock = $end;
1.1062 raeburn 4480: if ($trigger ne '') {
4481: $triggerblock = $trigger;
4482: }
1.502 raeburn 4483: }
1.490 raeburn 4484: }
1.1062 raeburn 4485: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4486: }
4487:
4488: sub get_blocks {
1.1062 raeburn 4489: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4490: my $startblock = 0;
4491: my $endblock = 0;
1.1062 raeburn 4492: my $triggerblock = '';
1.490 raeburn 4493: my $course = $cdom.'_'.$cnum;
4494: $setters->{$course} = {};
4495: $setters->{$course}{'staff'} = [];
4496: $setters->{$course}{'times'} = [];
1.1062 raeburn 4497: $setters->{$course}{'triggers'} = [];
4498: my (@blockers,%triggered);
4499: my $now = time;
4500: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4501: if ($activity eq 'docs') {
4502: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4503: foreach my $block (@blockers) {
4504: if ($block =~ /^firstaccess____(.+)$/) {
4505: my $item = $1;
4506: my $type = 'map';
4507: my $timersymb = $item;
4508: if ($item eq 'course') {
4509: $type = 'course';
4510: } elsif ($item =~ /___\d+___/) {
4511: $type = 'resource';
4512: } else {
4513: $timersymb = &Apache::lonnet::symbread($item);
4514: }
4515: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4516: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4517: $triggered{$block} = {
4518: start => $start,
4519: end => $end,
4520: type => $type,
4521: };
4522: }
4523: }
4524: } else {
4525: foreach my $block (keys(%commblocks)) {
4526: if ($block =~ m/^(\d+)____(\d+)$/) {
4527: my ($start,$end) = ($1,$2);
4528: if ($start <= time && $end >= time) {
4529: if (ref($commblocks{$block}) eq 'HASH') {
4530: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4531: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4532: unless(grep(/^\Q$block\E$/,@blockers)) {
4533: push(@blockers,$block);
4534: }
4535: }
4536: }
4537: }
4538: }
4539: } elsif ($block =~ /^firstaccess____(.+)$/) {
4540: my $item = $1;
4541: my $timersymb = $item;
4542: my $type = 'map';
4543: if ($item eq 'course') {
4544: $type = 'course';
4545: } elsif ($item =~ /___\d+___/) {
4546: $type = 'resource';
4547: } else {
4548: $timersymb = &Apache::lonnet::symbread($item);
4549: }
4550: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4551: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4552: if ($start && $end) {
4553: if (($start <= time) && ($end >= time)) {
4554: unless (grep(/^\Q$block\E$/,@blockers)) {
4555: push(@blockers,$block);
4556: $triggered{$block} = {
4557: start => $start,
4558: end => $end,
4559: type => $type,
4560: };
4561: }
4562: }
1.490 raeburn 4563: }
1.1062 raeburn 4564: }
4565: }
4566: }
4567: foreach my $blocker (@blockers) {
4568: my ($staff_name,$staff_dom,$title,$blocks) =
4569: &parse_block_record($commblocks{$blocker});
4570: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4571: my ($start,$end,$triggertype);
4572: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4573: ($start,$end) = ($1,$2);
4574: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4575: $start = $triggered{$blocker}{'start'};
4576: $end = $triggered{$blocker}{'end'};
4577: $triggertype = $triggered{$blocker}{'type'};
4578: }
4579: if ($start) {
4580: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4581: if ($triggertype) {
4582: push(@{$$setters{$course}{'triggers'}},$triggertype);
4583: } else {
4584: push(@{$$setters{$course}{'triggers'}},0);
4585: }
4586: if ( ($startblock == 0) || ($startblock > $start) ) {
4587: $startblock = $start;
4588: if ($triggertype) {
4589: $triggerblock = $blocker;
1.474 raeburn 4590: }
4591: }
1.1062 raeburn 4592: if ( ($endblock == 0) || ($endblock < $end) ) {
4593: $endblock = $end;
4594: if ($triggertype) {
4595: $triggerblock = $blocker;
4596: }
4597: }
1.474 raeburn 4598: }
4599: }
1.1062 raeburn 4600: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4601: }
4602:
4603: sub parse_block_record {
4604: my ($record) = @_;
4605: my ($setuname,$setudom,$title,$blocks);
4606: if (ref($record) eq 'HASH') {
4607: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4608: $title = &unescape($record->{'event'});
4609: $blocks = $record->{'blocks'};
4610: } else {
4611: my @data = split(/:/,$record,3);
4612: if (scalar(@data) eq 2) {
4613: $title = $data[1];
4614: ($setuname,$setudom) = split(/@/,$data[0]);
4615: } else {
4616: ($setuname,$setudom,$title) = @data;
4617: }
4618: $blocks = { 'com' => 'on' };
4619: }
4620: return ($setuname,$setudom,$title,$blocks);
4621: }
4622:
1.854 kalberla 4623: sub blocking_status {
1.1075.2.73 raeburn 4624: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 4625: my %setters;
1.890 droeschl 4626:
1.1061 raeburn 4627: # check for active blocking
1.1062 raeburn 4628: my ($startblock,$endblock,$triggerblock) =
1.1075.2.73 raeburn 4629: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 4630: my $blocked = 0;
4631: if ($startblock && $endblock) {
4632: $blocked = 1;
4633: }
1.890 droeschl 4634:
1.1061 raeburn 4635: # caller just wants to know whether a block is active
4636: if (!wantarray) { return $blocked; }
4637:
4638: # build a link to a popup window containing the details
4639: my $querystring = "?activity=$activity";
4640: # $uname and $udom decide whose portfolio the user is trying to look at
1.1075.2.97 raeburn 4641: if (($activity eq 'port') || ($activity eq 'passwd')) {
4642: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
4643: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 4644: } elsif ($activity eq 'docs') {
4645: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4646: }
1.1061 raeburn 4647:
4648: my $output .= <<'END_MYBLOCK';
4649: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4650: var options = "width=" + w + ",height=" + h + ",";
4651: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4652: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4653: var newWin = window.open(url, wdwName, options);
4654: newWin.focus();
4655: }
1.890 droeschl 4656: END_MYBLOCK
1.854 kalberla 4657:
1.1061 raeburn 4658: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4659:
1.1061 raeburn 4660: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4661: my $text = &mt('Communication Blocked');
1.1075.2.93 raeburn 4662: my $class = 'LC_comblock';
1.1062 raeburn 4663: if ($activity eq 'docs') {
4664: $text = &mt('Content Access Blocked');
1.1075.2.93 raeburn 4665: $class = '';
1.1063 raeburn 4666: } elsif ($activity eq 'printout') {
4667: $text = &mt('Printing Blocked');
1.1075.2.97 raeburn 4668: } elsif ($activity eq 'passwd') {
4669: $text = &mt('Password Changing Blocked');
1.1062 raeburn 4670: }
1.1061 raeburn 4671: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 4672: <div class='$class'>
1.869 kalberla 4673: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4674: title='$text'>
4675: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4676: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4677: title='$text'>$text</a>
1.867 kalberla 4678: </div>
4679:
4680: END_BLOCK
1.474 raeburn 4681:
1.1061 raeburn 4682: return ($blocked, $output);
1.854 kalberla 4683: }
1.490 raeburn 4684:
1.60 matthew 4685: ###############################################
4686:
1.682 raeburn 4687: sub check_ip_acc {
1.1075.2.105 raeburn 4688: my ($acc,$clientip)=@_;
1.682 raeburn 4689: &Apache::lonxml::debug("acc is $acc");
4690: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4691: return 1;
4692: }
4693: my $allowed=0;
1.1075.2.105 raeburn 4694: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
1.682 raeburn 4695:
4696: my $name;
4697: foreach my $pattern (split(',',$acc)) {
4698: $pattern =~ s/^\s*//;
4699: $pattern =~ s/\s*$//;
4700: if ($pattern =~ /\*$/) {
4701: #35.8.*
4702: $pattern=~s/\*//;
4703: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4704: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4705: #35.8.3.[34-56]
4706: my $low=$2;
4707: my $high=$3;
4708: $pattern=$1;
4709: if ($ip =~ /^\Q$pattern\E/) {
4710: my $last=(split(/\./,$ip))[3];
4711: if ($last <=$high && $last >=$low) { $allowed=1; }
4712: }
4713: } elsif ($pattern =~ /^\*/) {
4714: #*.msu.edu
4715: $pattern=~s/\*//;
4716: if (!defined($name)) {
4717: use Socket;
4718: my $netaddr=inet_aton($ip);
4719: ($name)=gethostbyaddr($netaddr,AF_INET);
4720: }
4721: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4722: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4723: #127.0.0.1
4724: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4725: } else {
4726: #some.name.com
4727: if (!defined($name)) {
4728: use Socket;
4729: my $netaddr=inet_aton($ip);
4730: ($name)=gethostbyaddr($netaddr,AF_INET);
4731: }
4732: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4733: }
4734: if ($allowed) { last; }
4735: }
4736: return $allowed;
4737: }
4738:
4739: ###############################################
4740:
1.60 matthew 4741: =pod
4742:
1.112 bowersj2 4743: =head1 Domain Template Functions
4744:
4745: =over 4
4746:
4747: =item * &determinedomain()
1.60 matthew 4748:
4749: Inputs: $domain (usually will be undef)
4750:
1.63 www 4751: Returns: Determines which domain should be used for designs
1.60 matthew 4752:
4753: =cut
1.54 www 4754:
1.60 matthew 4755: ###############################################
1.63 www 4756: sub determinedomain {
4757: my $domain=shift;
1.531 albertel 4758: if (! $domain) {
1.60 matthew 4759: # Determine domain if we have not been given one
1.893 raeburn 4760: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4761: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4762: if ($env{'request.role.domain'}) {
4763: $domain=$env{'request.role.domain'};
1.60 matthew 4764: }
4765: }
1.63 www 4766: return $domain;
4767: }
4768: ###############################################
1.517 raeburn 4769:
1.518 albertel 4770: sub devalidate_domconfig_cache {
4771: my ($udom)=@_;
4772: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4773: }
4774:
4775: # ---------------------- Get domain configuration for a domain
4776: sub get_domainconf {
4777: my ($udom) = @_;
4778: my $cachetime=1800;
4779: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4780: if (defined($cached)) { return %{$result}; }
4781:
4782: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4783: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4784: my (%designhash,%legacy);
1.518 albertel 4785: if (keys(%domconfig) > 0) {
4786: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4787: if (keys(%{$domconfig{'login'}})) {
4788: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4789: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 4790: if (($key eq 'loginvia') || ($key eq 'headtag')) {
4791: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
4792: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
4793: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
4794: if ($key eq 'loginvia') {
4795: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4796: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4797: $designhash{$udom.'.login.loginvia'} = $server;
4798: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4799: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4800: } else {
4801: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
4802: }
1.948 raeburn 4803: }
1.1075.2.87 raeburn 4804: } elsif ($key eq 'headtag') {
4805: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
4806: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 4807: }
1.946 raeburn 4808: }
1.1075.2.87 raeburn 4809: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
4810: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
4811: }
1.946 raeburn 4812: }
4813: }
4814: }
4815: } else {
4816: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4817: $designhash{$udom.'.login.'.$key.'_'.$img} =
4818: $domconfig{'login'}{$key}{$img};
4819: }
1.699 raeburn 4820: }
4821: } else {
4822: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4823: }
1.632 raeburn 4824: }
4825: } else {
4826: $legacy{'login'} = 1;
1.518 albertel 4827: }
1.632 raeburn 4828: } else {
4829: $legacy{'login'} = 1;
1.518 albertel 4830: }
4831: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4832: if (keys(%{$domconfig{'rolecolors'}})) {
4833: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4834: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4835: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4836: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4837: }
1.518 albertel 4838: }
4839: }
1.632 raeburn 4840: } else {
4841: $legacy{'rolecolors'} = 1;
1.518 albertel 4842: }
1.632 raeburn 4843: } else {
4844: $legacy{'rolecolors'} = 1;
1.518 albertel 4845: }
1.948 raeburn 4846: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4847: if ($domconfig{'autoenroll'}{'co-owners'}) {
4848: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4849: }
4850: }
1.632 raeburn 4851: if (keys(%legacy) > 0) {
4852: my %legacyhash = &get_legacy_domconf($udom);
4853: foreach my $item (keys(%legacyhash)) {
4854: if ($item =~ /^\Q$udom\E\.login/) {
4855: if ($legacy{'login'}) {
4856: $designhash{$item} = $legacyhash{$item};
4857: }
4858: } else {
4859: if ($legacy{'rolecolors'}) {
4860: $designhash{$item} = $legacyhash{$item};
4861: }
1.518 albertel 4862: }
4863: }
4864: }
1.632 raeburn 4865: } else {
4866: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4867: }
4868: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4869: $cachetime);
4870: return %designhash;
4871: }
4872:
1.632 raeburn 4873: sub get_legacy_domconf {
4874: my ($udom) = @_;
4875: my %legacyhash;
4876: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4877: my $designfile = $designdir.'/'.$udom.'.tab';
4878: if (-e $designfile) {
4879: if ( open (my $fh,"<$designfile") ) {
4880: while (my $line = <$fh>) {
4881: next if ($line =~ /^\#/);
4882: chomp($line);
4883: my ($key,$val)=(split(/\=/,$line));
4884: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4885: }
4886: close($fh);
4887: }
4888: }
1.1026 raeburn 4889: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4890: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4891: }
4892: return %legacyhash;
4893: }
4894:
1.63 www 4895: =pod
4896:
1.112 bowersj2 4897: =item * &domainlogo()
1.63 www 4898:
4899: Inputs: $domain (usually will be undef)
4900:
4901: Returns: A link to a domain logo, if the domain logo exists.
4902: If the domain logo does not exist, a description of the domain.
4903:
4904: =cut
1.112 bowersj2 4905:
1.63 www 4906: ###############################################
4907: sub domainlogo {
1.517 raeburn 4908: my $domain = &determinedomain(shift);
1.518 albertel 4909: my %designhash = &get_domainconf($domain);
1.517 raeburn 4910: # See if there is a logo
4911: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4912: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4913: if ($imgsrc =~ m{^/(adm|res)/}) {
4914: if ($imgsrc =~ m{^/res/}) {
4915: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4916: &Apache::lonnet::repcopy($local_name);
4917: }
4918: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4919: }
4920: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4921: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4922: return &Apache::lonnet::domain($domain,'description');
1.59 www 4923: } else {
1.60 matthew 4924: return '';
1.59 www 4925: }
4926: }
1.63 www 4927: ##############################################
4928:
4929: =pod
4930:
1.112 bowersj2 4931: =item * &designparm()
1.63 www 4932:
4933: Inputs: $which parameter; $domain (usually will be undef)
4934:
4935: Returns: value of designparamter $which
4936:
4937: =cut
1.112 bowersj2 4938:
1.397 albertel 4939:
1.400 albertel 4940: ##############################################
1.397 albertel 4941: sub designparm {
4942: my ($which,$domain)=@_;
4943: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4944: return $env{'environment.color.'.$which};
1.96 www 4945: }
1.63 www 4946: $domain=&determinedomain($domain);
1.1016 raeburn 4947: my %domdesign;
4948: unless ($domain eq 'public') {
4949: %domdesign = &get_domainconf($domain);
4950: }
1.520 raeburn 4951: my $output;
1.517 raeburn 4952: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4953: $output = $domdesign{$domain.'.'.$which};
1.63 www 4954: } else {
1.520 raeburn 4955: $output = $defaultdesign{$which};
4956: }
4957: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4958: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4959: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4960: if ($output =~ m{^/res/}) {
4961: my $local_name = &Apache::lonnet::filelocation('',$output);
4962: &Apache::lonnet::repcopy($local_name);
4963: }
1.520 raeburn 4964: $output = &lonhttpdurl($output);
4965: }
1.63 www 4966: }
1.520 raeburn 4967: return $output;
1.63 www 4968: }
1.59 www 4969:
1.822 bisitz 4970: ##############################################
4971: =pod
4972:
1.832 bisitz 4973: =item * &authorspace()
4974:
1.1028 raeburn 4975: Inputs: $url (usually will be undef).
1.832 bisitz 4976:
1.1075.2.40 raeburn 4977: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 4978: directory being viewed (or for which action is being taken).
4979: If $url is provided, and begins /priv/<domain>/<uname>
4980: the path will be that portion of the $context argument.
4981: Otherwise the path will be for the author space of the current
4982: user when the current role is author, or for that of the
4983: co-author/assistant co-author space when the current role
4984: is co-author or assistant co-author.
1.832 bisitz 4985:
4986: =cut
4987:
4988: sub authorspace {
1.1028 raeburn 4989: my ($url) = @_;
4990: if ($url ne '') {
4991: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4992: return $1;
4993: }
4994: }
1.832 bisitz 4995: my $caname = '';
1.1024 www 4996: my $cadom = '';
1.1028 raeburn 4997: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4998: ($cadom,$caname) =
1.832 bisitz 4999: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5000: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5001: $caname = $env{'user.name'};
1.1024 www 5002: $cadom = $env{'user.domain'};
1.832 bisitz 5003: }
1.1028 raeburn 5004: if (($caname ne '') && ($cadom ne '')) {
5005: return "/priv/$cadom/$caname/";
5006: }
5007: return;
1.832 bisitz 5008: }
5009:
5010: ##############################################
5011: =pod
5012:
1.822 bisitz 5013: =item * &head_subbox()
5014:
5015: Inputs: $content (contains HTML code with page functions, etc.)
5016:
5017: Returns: HTML div with $content
5018: To be included in page header
5019:
5020: =cut
5021:
5022: sub head_subbox {
5023: my ($content)=@_;
5024: my $output =
1.993 raeburn 5025: '<div class="LC_head_subbox">'
1.822 bisitz 5026: .$content
5027: .'</div>'
5028: }
5029:
5030: ##############################################
5031: =pod
5032:
5033: =item * &CSTR_pageheader()
5034:
1.1026 raeburn 5035: Input: (optional) filename from which breadcrumb trail is built.
5036: In most cases no input as needed, as $env{'request.filename'}
5037: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5038:
5039: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5040: To be included on Authoring Space pages
1.822 bisitz 5041:
5042: =cut
5043:
5044: sub CSTR_pageheader {
1.1026 raeburn 5045: my ($trailfile) = @_;
5046: if ($trailfile eq '') {
5047: $trailfile = $env{'request.filename'};
5048: }
5049:
5050: # this is for resources; directories have customtitle, and crumbs
5051: # and select recent are created in lonpubdir.pm
5052:
5053: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5054: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5055: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5056: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5057: $formaction =~ s{/+}{/}g;
1.822 bisitz 5058:
5059: my $parentpath = '';
5060: my $lastitem = '';
5061: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5062: $parentpath = $1;
5063: $lastitem = $2;
5064: } else {
5065: $lastitem = $thisdisfn;
5066: }
1.921 bisitz 5067:
5068: my $output =
1.822 bisitz 5069: '<div>'
5070: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5071: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5072: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5073: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5074: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5075:
5076: if ($lastitem) {
5077: $output .=
5078: '<span class="LC_filename">'
5079: .$lastitem
5080: .'</span>';
5081: }
5082: $output .=
5083: '<br />'
1.822 bisitz 5084: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5085: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5086: .'</form>'
5087: .&Apache::lonmenu::constspaceform()
5088: .'</div>';
1.921 bisitz 5089:
5090: return $output;
1.822 bisitz 5091: }
5092:
1.60 matthew 5093: ###############################################
5094: ###############################################
5095:
5096: =pod
5097:
1.112 bowersj2 5098: =back
5099:
1.549 albertel 5100: =head1 HTML Helpers
1.112 bowersj2 5101:
5102: =over 4
5103:
5104: =item * &bodytag()
1.60 matthew 5105:
5106: Returns a uniform header for LON-CAPA web pages.
5107:
5108: Inputs:
5109:
1.112 bowersj2 5110: =over 4
5111:
5112: =item * $title, A title to be displayed on the page.
5113:
5114: =item * $function, the current role (can be undef).
5115:
5116: =item * $addentries, extra parameters for the <body> tag.
5117:
5118: =item * $bodyonly, if defined, only return the <body> tag.
5119:
5120: =item * $domain, if defined, force a given domain.
5121:
5122: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5123: text interface only)
1.60 matthew 5124:
1.814 bisitz 5125: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5126: navigational links
1.317 albertel 5127:
1.338 albertel 5128: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5129:
1.1075.2.12 raeburn 5130: =item * $no_inline_link, if true and in remote mode, don't show the
5131: 'Switch To Inline Menu' link
5132:
1.460 albertel 5133: =item * $args, optional argument valid values are
5134: no_auto_mt_title -> prevents &mt()ing the title arg
5135:
1.1075.2.15 raeburn 5136: =item * $advtoolsref, optional argument, ref to an array containing
5137: inlineremote items to be added in "Functions" menu below
5138: breadcrumbs.
5139:
1.112 bowersj2 5140: =back
5141:
1.60 matthew 5142: Returns: A uniform header for LON-CAPA web pages.
5143: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5144: If $bodyonly is undef or zero, an html string containing a <body> tag and
5145: other decorations will be returned.
5146:
5147: =cut
5148:
1.54 www 5149: sub bodytag {
1.831 bisitz 5150: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5151: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5152:
1.954 raeburn 5153: my $public;
5154: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5155: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5156: $public = 1;
5157: }
1.460 albertel 5158: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5159: my $httphost = $args->{'use_absolute'};
1.339 albertel 5160:
1.183 matthew 5161: $function = &get_users_function() if (!$function);
1.339 albertel 5162: my $img = &designparm($function.'.img',$domain);
5163: my $font = &designparm($function.'.font',$domain);
5164: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5165:
1.803 bisitz 5166: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5167: 'bgcolor' => $pgbg,
1.339 albertel 5168: 'text' => $font,
5169: 'alink' => &designparm($function.'.alink',$domain),
5170: 'vlink' => &designparm($function.'.vlink',$domain),
5171: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5172: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5173:
1.63 www 5174: # role and realm
1.1075.2.68 raeburn 5175: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5176: if ($realm) {
5177: $realm = '/'.$realm;
5178: }
1.378 raeburn 5179: if ($role eq 'ca') {
1.479 albertel 5180: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5181: $realm = &plainname($rname,$rdom);
1.378 raeburn 5182: }
1.55 www 5183: # realm
1.258 albertel 5184: if ($env{'request.course.id'}) {
1.378 raeburn 5185: if ($env{'request.role'} !~ /^cr/) {
5186: $role = &Apache::lonnet::plaintext($role,&course_type());
5187: }
1.898 raeburn 5188: if ($env{'request.course.sec'}) {
5189: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5190: }
1.359 albertel 5191: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5192: } else {
5193: $role = &Apache::lonnet::plaintext($role);
1.54 www 5194: }
1.433 albertel 5195:
1.359 albertel 5196: if (!$realm) { $realm=' '; }
1.330 albertel 5197:
1.438 albertel 5198: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5199:
1.101 www 5200: # construct main body tag
1.359 albertel 5201: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 5202: &Apache::lontexconvert::init_math_support();
1.252 albertel 5203:
1.1075.2.38 raeburn 5204: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5205:
5206: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5207: return $bodytag;
1.1075.2.38 raeburn 5208: }
1.359 albertel 5209:
1.954 raeburn 5210: if ($public) {
1.433 albertel 5211: undef($role);
5212: }
1.359 albertel 5213:
1.762 bisitz 5214: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5215: #
5216: # Extra info if you are the DC
5217: my $dc_info = '';
5218: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5219: $env{'course.'.$env{'request.course.id'}.
5220: '.domain'}.'/'})) {
5221: my $cid = $env{'request.course.id'};
1.917 raeburn 5222: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5223: $dc_info =~ s/\s+$//;
1.359 albertel 5224: }
5225:
1.898 raeburn 5226: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.903 droeschl 5227:
1.1075.2.13 raeburn 5228: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5229:
1.1075.2.38 raeburn 5230:
5231:
1.1075.2.21 raeburn 5232: my $funclist;
5233: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5234: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5235: Apache::lonmenu::serverform();
5236: my $forbodytag;
5237: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5238: $forcereg,$args->{'group'},
5239: $args->{'bread_crumbs'},
5240: $advtoolsref,'',\$forbodytag);
5241: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5242: $funclist = $forbodytag;
5243: }
5244: } else {
1.903 droeschl 5245:
5246: # if ($env{'request.state'} eq 'construct') {
5247: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5248: # }
5249:
1.1075.2.38 raeburn 5250: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5251: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5252:
1.1075.2.38 raeburn 5253: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5254:
1.916 droeschl 5255: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5256: if ($dc_info) {
5257: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5258: }
1.1075.2.38 raeburn 5259: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5260: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5261: return $bodytag;
5262: }
1.894 droeschl 5263:
1.927 raeburn 5264: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5265: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5266: }
1.916 droeschl 5267:
1.1075.2.38 raeburn 5268: $bodytag .= $right;
1.852 droeschl 5269:
1.917 raeburn 5270: if ($dc_info) {
5271: $dc_info = &dc_courseid_toggle($dc_info);
5272: }
5273: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5274:
1.1075.2.61 raeburn 5275: #if directed to not display the secondary menu, don't.
5276: if ($args->{'no_secondary_menu'}) {
5277: return $bodytag;
5278: }
1.903 droeschl 5279: #don't show menus for public users
1.954 raeburn 5280: if (!$public){
1.1075.2.52 raeburn 5281: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5282: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5283: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5284: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5285: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5286: $args->{'bread_crumbs'});
5287: } elsif ($forcereg) {
1.1075.2.22 raeburn 5288: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5289: $args->{'group'});
1.1075.2.15 raeburn 5290: } else {
1.1075.2.21 raeburn 5291: my $forbodytag;
5292: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5293: $forcereg,$args->{'group'},
5294: $args->{'bread_crumbs'},
5295: $advtoolsref,'',\$forbodytag);
5296: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5297: $bodytag .= $forbodytag;
5298: }
1.920 raeburn 5299: }
1.903 droeschl 5300: }else{
5301: # this is to seperate menu from content when there's no secondary
5302: # menu. Especially needed for public accessible ressources.
5303: $bodytag .= '<hr style="clear:both" />';
5304: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5305: }
1.903 droeschl 5306:
1.235 raeburn 5307: return $bodytag;
1.1075.2.12 raeburn 5308: }
5309:
5310: #
5311: # Top frame rendering, Remote is up
5312: #
5313:
5314: my $imgsrc = $img;
5315: if ($img =~ /^\/adm/) {
5316: $imgsrc = &lonhttpdurl($img);
5317: }
5318: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5319:
1.1075.2.60 raeburn 5320: my $help=($no_inline_link?''
5321: :&Apache::loncommon::top_nav_help('Help'));
5322:
1.1075.2.12 raeburn 5323: # Explicit link to get inline menu
5324: my $menu= ($no_inline_link?''
5325: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5326:
5327: if ($dc_info) {
5328: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5329: }
5330:
1.1075.2.38 raeburn 5331: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5332: unless ($public) {
5333: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5334: undef,'LC_menubuttons_link');
5335: }
5336:
1.1075.2.12 raeburn 5337: unless ($env{'form.inhibitmenu'}) {
5338: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5339: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5340: <li>$help</li>
1.1075.2.12 raeburn 5341: <li>$menu</li>
5342: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5343: }
1.1075.2.13 raeburn 5344: if ($env{'request.state'} eq 'construct') {
5345: if (!$public){
5346: if ($env{'request.state'} eq 'construct') {
5347: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5348: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5349: &Apache::lonhtmlcommon::scripttag('','end').
5350: &Apache::lonmenu::innerregister($forcereg,
5351: $args->{'bread_crumbs'});
5352: }
5353: }
5354: }
1.1075.2.21 raeburn 5355: return $bodytag."\n".$funclist;
1.182 matthew 5356: }
5357:
1.917 raeburn 5358: sub dc_courseid_toggle {
5359: my ($dc_info) = @_;
1.980 raeburn 5360: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5361: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5362: &mt('(More ...)').'</a></span>'.
5363: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5364: }
5365:
1.330 albertel 5366: sub make_attr_string {
5367: my ($register,$attr_ref) = @_;
5368:
5369: if ($attr_ref && !ref($attr_ref)) {
5370: die("addentries Must be a hash ref ".
5371: join(':',caller(1))." ".
5372: join(':',caller(0))." ");
5373: }
5374:
5375: if ($register) {
1.339 albertel 5376: my ($on_load,$on_unload);
5377: foreach my $key (keys(%{$attr_ref})) {
5378: if (lc($key) eq 'onload') {
5379: $on_load.=$attr_ref->{$key}.';';
5380: delete($attr_ref->{$key});
5381:
5382: } elsif (lc($key) eq 'onunload') {
5383: $on_unload.=$attr_ref->{$key}.';';
5384: delete($attr_ref->{$key});
5385: }
5386: }
1.1075.2.12 raeburn 5387: if ($env{'environment.remote'} eq 'on') {
5388: $attr_ref->{'onload'} =
5389: &Apache::lonmenu::loadevents(). $on_load;
5390: $attr_ref->{'onunload'}=
5391: &Apache::lonmenu::unloadevents().$on_unload;
5392: } else {
5393: $attr_ref->{'onload'} = $on_load;
5394: $attr_ref->{'onunload'}= $on_unload;
5395: }
1.330 albertel 5396: }
1.339 albertel 5397:
1.330 albertel 5398: my $attr_string;
1.1075.2.56 raeburn 5399: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5400: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5401: }
5402: return $attr_string;
5403: }
5404:
5405:
1.182 matthew 5406: ###############################################
1.251 albertel 5407: ###############################################
5408:
5409: =pod
5410:
5411: =item * &endbodytag()
5412:
5413: Returns a uniform footer for LON-CAPA web pages.
5414:
1.635 raeburn 5415: Inputs: 1 - optional reference to an args hash
5416: If in the hash, key for noredirectlink has a value which evaluates to true,
5417: a 'Continue' link is not displayed if the page contains an
5418: internal redirect in the <head></head> section,
5419: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5420:
5421: =cut
5422:
5423: sub endbodytag {
1.635 raeburn 5424: my ($args) = @_;
1.1075.2.6 raeburn 5425: my $endbodytag;
5426: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5427: $endbodytag='</body>';
5428: }
1.315 albertel 5429: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5430: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5431: $endbodytag=
5432: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5433: &mt('Continue').'</a>'.
5434: $endbodytag;
5435: }
1.315 albertel 5436: }
1.251 albertel 5437: return $endbodytag;
5438: }
5439:
1.352 albertel 5440: =pod
5441:
5442: =item * &standard_css()
5443:
5444: Returns a style sheet
5445:
5446: Inputs: (all optional)
5447: domain -> force to color decorate a page for a specific
5448: domain
5449: function -> force usage of a specific rolish color scheme
5450: bgcolor -> override the default page bgcolor
5451:
5452: =cut
5453:
1.343 albertel 5454: sub standard_css {
1.345 albertel 5455: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5456: $function = &get_users_function() if (!$function);
5457: my $img = &designparm($function.'.img', $domain);
5458: my $tabbg = &designparm($function.'.tabbg', $domain);
5459: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5460: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5461: #second colour for later usage
1.345 albertel 5462: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5463: my $pgbg_or_bgcolor =
5464: $bgcolor ||
1.352 albertel 5465: &designparm($function.'.pgbg', $domain);
1.382 albertel 5466: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5467: my $alink = &designparm($function.'.alink', $domain);
5468: my $vlink = &designparm($function.'.vlink', $domain);
5469: my $link = &designparm($function.'.link', $domain);
5470:
1.602 albertel 5471: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5472: my $mono = 'monospace';
1.850 bisitz 5473: my $data_table_head = $sidebg;
5474: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5475: my $data_table_dark = '#E0E0E0';
1.470 banghart 5476: my $data_table_darker = '#CCCCCC';
1.349 albertel 5477: my $data_table_highlight = '#FFFF00';
1.352 albertel 5478: my $mail_new = '#FFBB77';
5479: my $mail_new_hover = '#DD9955';
5480: my $mail_read = '#BBBB77';
5481: my $mail_read_hover = '#999944';
5482: my $mail_replied = '#AAAA88';
5483: my $mail_replied_hover = '#888855';
5484: my $mail_other = '#99BBBB';
5485: my $mail_other_hover = '#669999';
1.391 albertel 5486: my $table_header = '#DDDDDD';
1.489 raeburn 5487: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5488: my $lg_border_color = '#C8C8C8';
1.952 onken 5489: my $button_hover = '#BF2317';
1.392 albertel 5490:
1.608 albertel 5491: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5492: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5493: : '0 3px 0 4px';
1.448 albertel 5494:
1.523 albertel 5495:
1.343 albertel 5496: return <<END;
1.947 droeschl 5497:
5498: /* needed for iframe to allow 100% height in FF */
5499: body, html {
5500: margin: 0;
5501: padding: 0 0.5%;
5502: height: 99%; /* to avoid scrollbars */
5503: }
5504:
1.795 www 5505: body {
1.911 bisitz 5506: font-family: $sans;
5507: line-height:130%;
5508: font-size:0.83em;
5509: color:$font;
1.795 www 5510: }
5511:
1.959 onken 5512: a:focus,
5513: a:focus img {
1.795 www 5514: color: red;
5515: }
1.698 harmsja 5516:
1.911 bisitz 5517: form, .inline {
5518: display: inline;
1.795 www 5519: }
1.721 harmsja 5520:
1.795 www 5521: .LC_right {
1.911 bisitz 5522: text-align:right;
1.795 www 5523: }
5524:
5525: .LC_middle {
1.911 bisitz 5526: vertical-align:middle;
1.795 www 5527: }
1.721 harmsja 5528:
1.1075.2.38 raeburn 5529: .LC_floatleft {
5530: float: left;
5531: }
5532:
5533: .LC_floatright {
5534: float: right;
5535: }
5536:
1.911 bisitz 5537: .LC_400Box {
5538: width:400px;
5539: }
1.721 harmsja 5540:
1.947 droeschl 5541: .LC_iframecontainer {
5542: width: 98%;
5543: margin: 0;
5544: position: fixed;
5545: top: 8.5em;
5546: bottom: 0;
5547: }
5548:
5549: .LC_iframecontainer iframe{
5550: border: none;
5551: width: 100%;
5552: height: 100%;
5553: }
5554:
1.778 bisitz 5555: .LC_filename {
5556: font-family: $mono;
5557: white-space:pre;
1.921 bisitz 5558: font-size: 120%;
1.778 bisitz 5559: }
5560:
5561: .LC_fileicon {
5562: border: none;
5563: height: 1.3em;
5564: vertical-align: text-bottom;
5565: margin-right: 0.3em;
5566: text-decoration:none;
5567: }
5568:
1.1008 www 5569: .LC_setting {
5570: text-decoration:underline;
5571: }
5572:
1.350 albertel 5573: .LC_error {
5574: color: red;
5575: }
1.795 www 5576:
1.1075.2.15 raeburn 5577: .LC_warning {
5578: color: darkorange;
5579: }
5580:
1.457 albertel 5581: .LC_diff_removed {
1.733 bisitz 5582: color: red;
1.394 albertel 5583: }
1.532 albertel 5584:
5585: .LC_info,
1.457 albertel 5586: .LC_success,
5587: .LC_diff_added {
1.350 albertel 5588: color: green;
5589: }
1.795 www 5590:
1.802 bisitz 5591: div.LC_confirm_box {
5592: background-color: #FAFAFA;
5593: border: 1px solid $lg_border_color;
5594: margin-right: 0;
5595: padding: 5px;
5596: }
5597:
5598: div.LC_confirm_box .LC_error img,
5599: div.LC_confirm_box .LC_success img {
5600: vertical-align: middle;
5601: }
5602:
1.440 albertel 5603: .LC_icon {
1.771 droeschl 5604: border: none;
1.790 droeschl 5605: vertical-align: middle;
1.771 droeschl 5606: }
5607:
1.543 albertel 5608: .LC_docs_spacer {
5609: width: 25px;
5610: height: 1px;
1.771 droeschl 5611: border: none;
1.543 albertel 5612: }
1.346 albertel 5613:
1.532 albertel 5614: .LC_internal_info {
1.735 bisitz 5615: color: #999999;
1.532 albertel 5616: }
5617:
1.794 www 5618: .LC_discussion {
1.1050 www 5619: background: $data_table_dark;
1.911 bisitz 5620: border: 1px solid black;
5621: margin: 2px;
1.794 www 5622: }
5623:
5624: .LC_disc_action_left {
1.1050 www 5625: background: $sidebg;
1.911 bisitz 5626: text-align: left;
1.1050 www 5627: padding: 4px;
5628: margin: 2px;
1.794 www 5629: }
5630:
5631: .LC_disc_action_right {
1.1050 www 5632: background: $sidebg;
1.911 bisitz 5633: text-align: right;
1.1050 www 5634: padding: 4px;
5635: margin: 2px;
1.794 www 5636: }
5637:
5638: .LC_disc_new_item {
1.911 bisitz 5639: background: white;
5640: border: 2px solid red;
1.1050 www 5641: margin: 4px;
5642: padding: 4px;
1.794 www 5643: }
5644:
5645: .LC_disc_old_item {
1.911 bisitz 5646: background: white;
1.1050 www 5647: margin: 4px;
5648: padding: 4px;
1.794 www 5649: }
5650:
1.458 albertel 5651: table.LC_pastsubmission {
5652: border: 1px solid black;
5653: margin: 2px;
5654: }
5655:
1.924 bisitz 5656: table#LC_menubuttons {
1.345 albertel 5657: width: 100%;
5658: background: $pgbg;
1.392 albertel 5659: border: 2px;
1.402 albertel 5660: border-collapse: separate;
1.803 bisitz 5661: padding: 0;
1.345 albertel 5662: }
1.392 albertel 5663:
1.801 tempelho 5664: table#LC_title_bar a {
5665: color: $fontmenu;
5666: }
1.836 bisitz 5667:
1.807 droeschl 5668: table#LC_title_bar {
1.819 tempelho 5669: clear: both;
1.836 bisitz 5670: display: none;
1.807 droeschl 5671: }
5672:
1.795 www 5673: table#LC_title_bar,
1.933 droeschl 5674: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5675: table#LC_title_bar.LC_with_remote {
1.359 albertel 5676: width: 100%;
1.392 albertel 5677: border-color: $pgbg;
5678: border-style: solid;
5679: border-width: $border;
1.379 albertel 5680: background: $pgbg;
1.801 tempelho 5681: color: $fontmenu;
1.392 albertel 5682: border-collapse: collapse;
1.803 bisitz 5683: padding: 0;
1.819 tempelho 5684: margin: 0;
1.359 albertel 5685: }
1.795 www 5686:
1.933 droeschl 5687: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5688: margin: 0;
5689: padding: 0;
1.933 droeschl 5690: position: relative;
5691: list-style: none;
1.913 droeschl 5692: }
1.933 droeschl 5693: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5694: display: inline;
5695: }
1.933 droeschl 5696:
5697: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5698: padding: 0;
1.933 droeschl 5699: margin: 0;
5700: float: left;
1.913 droeschl 5701: }
1.933 droeschl 5702: .LC_breadcrumb_tools_tools {
5703: padding: 0;
5704: margin: 0;
1.913 droeschl 5705: float: right;
5706: }
5707:
1.359 albertel 5708: table#LC_title_bar td {
5709: background: $tabbg;
5710: }
1.795 www 5711:
1.911 bisitz 5712: table#LC_menubuttons img {
1.803 bisitz 5713: border: none;
1.346 albertel 5714: }
1.795 www 5715:
1.842 droeschl 5716: .LC_breadcrumbs_component {
1.911 bisitz 5717: float: right;
5718: margin: 0 1em;
1.357 albertel 5719: }
1.842 droeschl 5720: .LC_breadcrumbs_component img {
1.911 bisitz 5721: vertical-align: middle;
1.777 tempelho 5722: }
1.795 www 5723:
1.383 albertel 5724: td.LC_table_cell_checkbox {
5725: text-align: center;
5726: }
1.795 www 5727:
5728: .LC_fontsize_small {
1.911 bisitz 5729: font-size: 70%;
1.705 tempelho 5730: }
5731:
1.844 bisitz 5732: #LC_breadcrumbs {
1.911 bisitz 5733: clear:both;
5734: background: $sidebg;
5735: border-bottom: 1px solid $lg_border_color;
5736: line-height: 2.5em;
1.933 droeschl 5737: overflow: hidden;
1.911 bisitz 5738: margin: 0;
5739: padding: 0;
1.995 raeburn 5740: text-align: left;
1.819 tempelho 5741: }
1.862 bisitz 5742:
1.1075.2.16 raeburn 5743: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5744: clear:both;
5745: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5746: border: 1px solid $sidebg;
1.1075.2.16 raeburn 5747: margin: 0 0 10px 0;
1.966 bisitz 5748: padding: 3px;
1.995 raeburn 5749: text-align: left;
1.822 bisitz 5750: }
5751:
1.795 www 5752: .LC_fontsize_medium {
1.911 bisitz 5753: font-size: 85%;
1.705 tempelho 5754: }
5755:
1.795 www 5756: .LC_fontsize_large {
1.911 bisitz 5757: font-size: 120%;
1.705 tempelho 5758: }
5759:
1.346 albertel 5760: .LC_menubuttons_inline_text {
5761: color: $font;
1.698 harmsja 5762: font-size: 90%;
1.701 harmsja 5763: padding-left:3px;
1.346 albertel 5764: }
5765:
1.934 droeschl 5766: .LC_menubuttons_inline_text img{
5767: vertical-align: middle;
5768: }
5769:
1.1051 www 5770: li.LC_menubuttons_inline_text img {
1.951 onken 5771: cursor:pointer;
1.1002 droeschl 5772: text-decoration: none;
1.951 onken 5773: }
5774:
1.526 www 5775: .LC_menubuttons_link {
5776: text-decoration: none;
5777: }
1.795 www 5778:
1.522 albertel 5779: .LC_menubuttons_category {
1.521 www 5780: color: $font;
1.526 www 5781: background: $pgbg;
1.521 www 5782: font-size: larger;
5783: font-weight: bold;
5784: }
5785:
1.346 albertel 5786: td.LC_menubuttons_text {
1.911 bisitz 5787: color: $font;
1.346 albertel 5788: }
1.706 harmsja 5789:
1.346 albertel 5790: .LC_current_location {
5791: background: $tabbg;
5792: }
1.795 www 5793:
1.938 bisitz 5794: table.LC_data_table {
1.347 albertel 5795: border: 1px solid #000000;
1.402 albertel 5796: border-collapse: separate;
1.426 albertel 5797: border-spacing: 1px;
1.610 albertel 5798: background: $pgbg;
1.347 albertel 5799: }
1.795 www 5800:
1.422 albertel 5801: .LC_data_table_dense {
5802: font-size: small;
5803: }
1.795 www 5804:
1.507 raeburn 5805: table.LC_nested_outer {
5806: border: 1px solid #000000;
1.589 raeburn 5807: border-collapse: collapse;
1.803 bisitz 5808: border-spacing: 0;
1.507 raeburn 5809: width: 100%;
5810: }
1.795 www 5811:
1.879 raeburn 5812: table.LC_innerpickbox,
1.507 raeburn 5813: table.LC_nested {
1.803 bisitz 5814: border: none;
1.589 raeburn 5815: border-collapse: collapse;
1.803 bisitz 5816: border-spacing: 0;
1.507 raeburn 5817: width: 100%;
5818: }
1.795 www 5819:
1.911 bisitz 5820: table.LC_data_table tr th,
5821: table.LC_calendar tr th,
1.879 raeburn 5822: table.LC_prior_tries tr th,
5823: table.LC_innerpickbox tr th {
1.349 albertel 5824: font-weight: bold;
5825: background-color: $data_table_head;
1.801 tempelho 5826: color:$fontmenu;
1.701 harmsja 5827: font-size:90%;
1.347 albertel 5828: }
1.795 www 5829:
1.879 raeburn 5830: table.LC_innerpickbox tr th,
5831: table.LC_innerpickbox tr td {
5832: vertical-align: top;
5833: }
5834:
1.711 raeburn 5835: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5836: background-color: #CCCCCC;
1.711 raeburn 5837: font-weight: bold;
5838: text-align: left;
5839: }
1.795 www 5840:
1.912 bisitz 5841: table.LC_data_table tr.LC_odd_row > td {
5842: background-color: $data_table_light;
5843: padding: 2px;
5844: vertical-align: top;
5845: }
5846:
1.809 bisitz 5847: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5848: background-color: $data_table_light;
1.912 bisitz 5849: vertical-align: top;
5850: }
5851:
5852: table.LC_data_table tr.LC_even_row > td {
5853: background-color: $data_table_dark;
1.425 albertel 5854: padding: 2px;
1.900 bisitz 5855: vertical-align: top;
1.347 albertel 5856: }
1.795 www 5857:
1.809 bisitz 5858: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5859: background-color: $data_table_dark;
1.900 bisitz 5860: vertical-align: top;
1.347 albertel 5861: }
1.795 www 5862:
1.425 albertel 5863: table.LC_data_table tr.LC_data_table_highlight td {
5864: background-color: $data_table_darker;
5865: }
1.795 www 5866:
1.639 raeburn 5867: table.LC_data_table tr td.LC_leftcol_header {
5868: background-color: $data_table_head;
5869: font-weight: bold;
5870: }
1.795 www 5871:
1.451 albertel 5872: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5873: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5874: font-weight: bold;
5875: font-style: italic;
5876: text-align: center;
5877: padding: 8px;
1.347 albertel 5878: }
1.795 www 5879:
1.1075.2.30 raeburn 5880: table.LC_data_table tr.LC_empty_row td,
5881: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5882: background-color: $sidebg;
5883: }
5884:
5885: table.LC_nested tr.LC_empty_row td {
5886: background-color: #FFFFFF;
5887: }
5888:
1.890 droeschl 5889: table.LC_caption {
5890: }
5891:
1.507 raeburn 5892: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5893: padding: 4ex
5894: }
1.795 www 5895:
1.507 raeburn 5896: table.LC_nested_outer tr th {
5897: font-weight: bold;
1.801 tempelho 5898: color:$fontmenu;
1.507 raeburn 5899: background-color: $data_table_head;
1.701 harmsja 5900: font-size: small;
1.507 raeburn 5901: border-bottom: 1px solid #000000;
5902: }
1.795 www 5903:
1.507 raeburn 5904: table.LC_nested_outer tr td.LC_subheader {
5905: background-color: $data_table_head;
5906: font-weight: bold;
5907: font-size: small;
5908: border-bottom: 1px solid #000000;
5909: text-align: right;
1.451 albertel 5910: }
1.795 www 5911:
1.507 raeburn 5912: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5913: background-color: #CCCCCC;
1.451 albertel 5914: font-weight: bold;
5915: font-size: small;
1.507 raeburn 5916: text-align: center;
5917: }
1.795 www 5918:
1.589 raeburn 5919: table.LC_nested tr.LC_info_row td.LC_left_item,
5920: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5921: text-align: left;
1.451 albertel 5922: }
1.795 www 5923:
1.507 raeburn 5924: table.LC_nested td {
1.735 bisitz 5925: background-color: #FFFFFF;
1.451 albertel 5926: font-size: small;
1.507 raeburn 5927: }
1.795 www 5928:
1.507 raeburn 5929: table.LC_nested_outer tr th.LC_right_item,
5930: table.LC_nested tr.LC_info_row td.LC_right_item,
5931: table.LC_nested tr.LC_odd_row td.LC_right_item,
5932: table.LC_nested tr td.LC_right_item {
1.451 albertel 5933: text-align: right;
5934: }
5935:
1.507 raeburn 5936: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5937: background-color: #EEEEEE;
1.451 albertel 5938: }
5939:
1.473 raeburn 5940: table.LC_createuser {
5941: }
5942:
5943: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5944: font-size: small;
1.473 raeburn 5945: }
5946:
5947: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5948: background-color: #CCCCCC;
1.473 raeburn 5949: font-weight: bold;
5950: text-align: center;
5951: }
5952:
1.349 albertel 5953: table.LC_calendar {
5954: border: 1px solid #000000;
5955: border-collapse: collapse;
1.917 raeburn 5956: width: 98%;
1.349 albertel 5957: }
1.795 www 5958:
1.349 albertel 5959: table.LC_calendar_pickdate {
5960: font-size: xx-small;
5961: }
1.795 www 5962:
1.349 albertel 5963: table.LC_calendar tr td {
5964: border: 1px solid #000000;
5965: vertical-align: top;
1.917 raeburn 5966: width: 14%;
1.349 albertel 5967: }
1.795 www 5968:
1.349 albertel 5969: table.LC_calendar tr td.LC_calendar_day_empty {
5970: background-color: $data_table_dark;
5971: }
1.795 www 5972:
1.779 bisitz 5973: table.LC_calendar tr td.LC_calendar_day_current {
5974: background-color: $data_table_highlight;
1.777 tempelho 5975: }
1.795 www 5976:
1.938 bisitz 5977: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5978: background-color: $mail_new;
5979: }
1.795 www 5980:
1.938 bisitz 5981: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5982: background-color: $mail_new_hover;
5983: }
1.795 www 5984:
1.938 bisitz 5985: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5986: background-color: $mail_read;
5987: }
1.795 www 5988:
1.938 bisitz 5989: /*
5990: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5991: background-color: $mail_read_hover;
5992: }
1.938 bisitz 5993: */
1.795 www 5994:
1.938 bisitz 5995: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5996: background-color: $mail_replied;
5997: }
1.795 www 5998:
1.938 bisitz 5999: /*
6000: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6001: background-color: $mail_replied_hover;
6002: }
1.938 bisitz 6003: */
1.795 www 6004:
1.938 bisitz 6005: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6006: background-color: $mail_other;
6007: }
1.795 www 6008:
1.938 bisitz 6009: /*
6010: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6011: background-color: $mail_other_hover;
6012: }
1.938 bisitz 6013: */
1.494 raeburn 6014:
1.777 tempelho 6015: table.LC_data_table tr > td.LC_browser_file,
6016: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6017: background: #AAEE77;
1.389 albertel 6018: }
1.795 www 6019:
1.777 tempelho 6020: table.LC_data_table tr > td.LC_browser_file_locked,
6021: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6022: background: #FFAA99;
1.387 albertel 6023: }
1.795 www 6024:
1.777 tempelho 6025: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6026: background: #888888;
1.779 bisitz 6027: }
1.795 www 6028:
1.777 tempelho 6029: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6030: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6031: background: #F8F866;
1.777 tempelho 6032: }
1.795 www 6033:
1.696 bisitz 6034: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6035: background: #E0E8FF;
1.387 albertel 6036: }
1.696 bisitz 6037:
1.707 bisitz 6038: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6039: /* background: #77FF77; */
1.707 bisitz 6040: }
1.795 www 6041:
1.707 bisitz 6042: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6043: border-right: 8px solid #FFFF77;
1.707 bisitz 6044: }
1.795 www 6045:
1.707 bisitz 6046: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6047: border-right: 8px solid #FFAA77;
1.707 bisitz 6048: }
1.795 www 6049:
1.707 bisitz 6050: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6051: border-right: 8px solid #FF7777;
1.707 bisitz 6052: }
1.795 www 6053:
1.707 bisitz 6054: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6055: border-right: 8px solid #AAFF77;
1.707 bisitz 6056: }
1.795 www 6057:
1.707 bisitz 6058: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6059: border-right: 8px solid #11CC55;
1.707 bisitz 6060: }
6061:
1.388 albertel 6062: span.LC_current_location {
1.701 harmsja 6063: font-size:larger;
1.388 albertel 6064: background: $pgbg;
6065: }
1.387 albertel 6066:
1.1029 www 6067: span.LC_current_nav_location {
6068: font-weight:bold;
6069: background: $sidebg;
6070: }
6071:
1.395 albertel 6072: span.LC_parm_menu_item {
6073: font-size: larger;
6074: }
1.795 www 6075:
1.395 albertel 6076: span.LC_parm_scope_all {
6077: color: red;
6078: }
1.795 www 6079:
1.395 albertel 6080: span.LC_parm_scope_folder {
6081: color: green;
6082: }
1.795 www 6083:
1.395 albertel 6084: span.LC_parm_scope_resource {
6085: color: orange;
6086: }
1.795 www 6087:
1.395 albertel 6088: span.LC_parm_part {
6089: color: blue;
6090: }
1.795 www 6091:
1.911 bisitz 6092: span.LC_parm_folder,
6093: span.LC_parm_symb {
1.395 albertel 6094: font-size: x-small;
6095: font-family: $mono;
6096: color: #AAAAAA;
6097: }
6098:
1.977 bisitz 6099: ul.LC_parm_parmlist li {
6100: display: inline-block;
6101: padding: 0.3em 0.8em;
6102: vertical-align: top;
6103: width: 150px;
6104: border-top:1px solid $lg_border_color;
6105: }
6106:
1.795 www 6107: td.LC_parm_overview_level_menu,
6108: td.LC_parm_overview_map_menu,
6109: td.LC_parm_overview_parm_selectors,
6110: td.LC_parm_overview_restrictions {
1.396 albertel 6111: border: 1px solid black;
6112: border-collapse: collapse;
6113: }
1.795 www 6114:
1.396 albertel 6115: table.LC_parm_overview_restrictions td {
6116: border-width: 1px 4px 1px 4px;
6117: border-style: solid;
6118: border-color: $pgbg;
6119: text-align: center;
6120: }
1.795 www 6121:
1.396 albertel 6122: table.LC_parm_overview_restrictions th {
6123: background: $tabbg;
6124: border-width: 1px 4px 1px 4px;
6125: border-style: solid;
6126: border-color: $pgbg;
6127: }
1.795 www 6128:
1.398 albertel 6129: table#LC_helpmenu {
1.803 bisitz 6130: border: none;
1.398 albertel 6131: height: 55px;
1.803 bisitz 6132: border-spacing: 0;
1.398 albertel 6133: }
6134:
6135: table#LC_helpmenu fieldset legend {
6136: font-size: larger;
6137: }
1.795 www 6138:
1.397 albertel 6139: table#LC_helpmenu_links {
6140: width: 100%;
6141: border: 1px solid black;
6142: background: $pgbg;
1.803 bisitz 6143: padding: 0;
1.397 albertel 6144: border-spacing: 1px;
6145: }
1.795 www 6146:
1.397 albertel 6147: table#LC_helpmenu_links tr td {
6148: padding: 1px;
6149: background: $tabbg;
1.399 albertel 6150: text-align: center;
6151: font-weight: bold;
1.397 albertel 6152: }
1.396 albertel 6153:
1.795 www 6154: table#LC_helpmenu_links a:link,
6155: table#LC_helpmenu_links a:visited,
1.397 albertel 6156: table#LC_helpmenu_links a:active {
6157: text-decoration: none;
6158: color: $font;
6159: }
1.795 www 6160:
1.397 albertel 6161: table#LC_helpmenu_links a:hover {
6162: text-decoration: underline;
6163: color: $vlink;
6164: }
1.396 albertel 6165:
1.417 albertel 6166: .LC_chrt_popup_exists {
6167: border: 1px solid #339933;
6168: margin: -1px;
6169: }
1.795 www 6170:
1.417 albertel 6171: .LC_chrt_popup_up {
6172: border: 1px solid yellow;
6173: margin: -1px;
6174: }
1.795 www 6175:
1.417 albertel 6176: .LC_chrt_popup {
6177: border: 1px solid #8888FF;
6178: background: #CCCCFF;
6179: }
1.795 www 6180:
1.421 albertel 6181: table.LC_pick_box {
6182: border-collapse: separate;
6183: background: white;
6184: border: 1px solid black;
6185: border-spacing: 1px;
6186: }
1.795 www 6187:
1.421 albertel 6188: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6189: background: $sidebg;
1.421 albertel 6190: font-weight: bold;
1.900 bisitz 6191: text-align: left;
1.740 bisitz 6192: vertical-align: top;
1.421 albertel 6193: width: 184px;
6194: padding: 8px;
6195: }
1.795 www 6196:
1.579 raeburn 6197: table.LC_pick_box td.LC_pick_box_value {
6198: text-align: left;
6199: padding: 8px;
6200: }
1.795 www 6201:
1.579 raeburn 6202: table.LC_pick_box td.LC_pick_box_select {
6203: text-align: left;
6204: padding: 8px;
6205: }
1.795 www 6206:
1.424 albertel 6207: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6208: padding: 0;
1.421 albertel 6209: height: 1px;
6210: background: black;
6211: }
1.795 www 6212:
1.421 albertel 6213: table.LC_pick_box td.LC_pick_box_submit {
6214: text-align: right;
6215: }
1.795 www 6216:
1.579 raeburn 6217: table.LC_pick_box td.LC_evenrow_value {
6218: text-align: left;
6219: padding: 8px;
6220: background-color: $data_table_light;
6221: }
1.795 www 6222:
1.579 raeburn 6223: table.LC_pick_box td.LC_oddrow_value {
6224: text-align: left;
6225: padding: 8px;
6226: background-color: $data_table_light;
6227: }
1.795 www 6228:
1.579 raeburn 6229: span.LC_helpform_receipt_cat {
6230: font-weight: bold;
6231: }
1.795 www 6232:
1.424 albertel 6233: table.LC_group_priv_box {
6234: background: white;
6235: border: 1px solid black;
6236: border-spacing: 1px;
6237: }
1.795 www 6238:
1.424 albertel 6239: table.LC_group_priv_box td.LC_pick_box_title {
6240: background: $tabbg;
6241: font-weight: bold;
6242: text-align: right;
6243: width: 184px;
6244: }
1.795 www 6245:
1.424 albertel 6246: table.LC_group_priv_box td.LC_groups_fixed {
6247: background: $data_table_light;
6248: text-align: center;
6249: }
1.795 www 6250:
1.424 albertel 6251: table.LC_group_priv_box td.LC_groups_optional {
6252: background: $data_table_dark;
6253: text-align: center;
6254: }
1.795 www 6255:
1.424 albertel 6256: table.LC_group_priv_box td.LC_groups_functionality {
6257: background: $data_table_darker;
6258: text-align: center;
6259: font-weight: bold;
6260: }
1.795 www 6261:
1.424 albertel 6262: table.LC_group_priv td {
6263: text-align: left;
1.803 bisitz 6264: padding: 0;
1.424 albertel 6265: }
6266:
6267: .LC_navbuttons {
6268: margin: 2ex 0ex 2ex 0ex;
6269: }
1.795 www 6270:
1.423 albertel 6271: .LC_topic_bar {
6272: font-weight: bold;
6273: background: $tabbg;
1.918 wenzelju 6274: margin: 1em 0em 1em 2em;
1.805 bisitz 6275: padding: 3px;
1.918 wenzelju 6276: font-size: 1.2em;
1.423 albertel 6277: }
1.795 www 6278:
1.423 albertel 6279: .LC_topic_bar span {
1.918 wenzelju 6280: left: 0.5em;
6281: position: absolute;
1.423 albertel 6282: vertical-align: middle;
1.918 wenzelju 6283: font-size: 1.2em;
1.423 albertel 6284: }
1.795 www 6285:
1.423 albertel 6286: table.LC_course_group_status {
6287: margin: 20px;
6288: }
1.795 www 6289:
1.423 albertel 6290: table.LC_status_selector td {
6291: vertical-align: top;
6292: text-align: center;
1.424 albertel 6293: padding: 4px;
6294: }
1.795 www 6295:
1.599 albertel 6296: div.LC_feedback_link {
1.616 albertel 6297: clear: both;
1.829 kalberla 6298: background: $sidebg;
1.779 bisitz 6299: width: 100%;
1.829 kalberla 6300: padding-bottom: 10px;
6301: border: 1px $tabbg solid;
1.833 kalberla 6302: height: 22px;
6303: line-height: 22px;
6304: padding-top: 5px;
6305: }
6306:
6307: div.LC_feedback_link img {
6308: height: 22px;
1.867 kalberla 6309: vertical-align:middle;
1.829 kalberla 6310: }
6311:
1.911 bisitz 6312: div.LC_feedback_link a {
1.829 kalberla 6313: text-decoration: none;
1.489 raeburn 6314: }
1.795 www 6315:
1.867 kalberla 6316: div.LC_comblock {
1.911 bisitz 6317: display:inline;
1.867 kalberla 6318: color:$font;
6319: font-size:90%;
6320: }
6321:
6322: div.LC_feedback_link div.LC_comblock {
6323: padding-left:5px;
6324: }
6325:
6326: div.LC_feedback_link div.LC_comblock a {
6327: color:$font;
6328: }
6329:
1.489 raeburn 6330: span.LC_feedback_link {
1.858 bisitz 6331: /* background: $feedback_link_bg; */
1.599 albertel 6332: font-size: larger;
6333: }
1.795 www 6334:
1.599 albertel 6335: span.LC_message_link {
1.858 bisitz 6336: /* background: $feedback_link_bg; */
1.599 albertel 6337: font-size: larger;
6338: position: absolute;
6339: right: 1em;
1.489 raeburn 6340: }
1.421 albertel 6341:
1.515 albertel 6342: table.LC_prior_tries {
1.524 albertel 6343: border: 1px solid #000000;
6344: border-collapse: separate;
6345: border-spacing: 1px;
1.515 albertel 6346: }
1.523 albertel 6347:
1.515 albertel 6348: table.LC_prior_tries td {
1.524 albertel 6349: padding: 2px;
1.515 albertel 6350: }
1.523 albertel 6351:
6352: .LC_answer_correct {
1.795 www 6353: background: lightgreen;
6354: color: darkgreen;
6355: padding: 6px;
1.523 albertel 6356: }
1.795 www 6357:
1.523 albertel 6358: .LC_answer_charged_try {
1.797 www 6359: background: #FFAAAA;
1.795 www 6360: color: darkred;
6361: padding: 6px;
1.523 albertel 6362: }
1.795 www 6363:
1.779 bisitz 6364: .LC_answer_not_charged_try,
1.523 albertel 6365: .LC_answer_no_grade,
6366: .LC_answer_late {
1.795 www 6367: background: lightyellow;
1.523 albertel 6368: color: black;
1.795 www 6369: padding: 6px;
1.523 albertel 6370: }
1.795 www 6371:
1.523 albertel 6372: .LC_answer_previous {
1.795 www 6373: background: lightblue;
6374: color: darkblue;
6375: padding: 6px;
1.523 albertel 6376: }
1.795 www 6377:
1.779 bisitz 6378: .LC_answer_no_message {
1.777 tempelho 6379: background: #FFFFFF;
6380: color: black;
1.795 www 6381: padding: 6px;
1.779 bisitz 6382: }
1.795 www 6383:
1.779 bisitz 6384: .LC_answer_unknown {
6385: background: orange;
6386: color: black;
1.795 www 6387: padding: 6px;
1.777 tempelho 6388: }
1.795 www 6389:
1.529 albertel 6390: span.LC_prior_numerical,
6391: span.LC_prior_string,
6392: span.LC_prior_custom,
6393: span.LC_prior_reaction,
6394: span.LC_prior_math {
1.925 bisitz 6395: font-family: $mono;
1.523 albertel 6396: white-space: pre;
6397: }
6398:
1.525 albertel 6399: span.LC_prior_string {
1.925 bisitz 6400: font-family: $mono;
1.525 albertel 6401: white-space: pre;
6402: }
6403:
1.523 albertel 6404: table.LC_prior_option {
6405: width: 100%;
6406: border-collapse: collapse;
6407: }
1.795 www 6408:
1.911 bisitz 6409: table.LC_prior_rank,
1.795 www 6410: table.LC_prior_match {
1.528 albertel 6411: border-collapse: collapse;
6412: }
1.795 www 6413:
1.528 albertel 6414: table.LC_prior_option tr td,
6415: table.LC_prior_rank tr td,
6416: table.LC_prior_match tr td {
1.524 albertel 6417: border: 1px solid #000000;
1.515 albertel 6418: }
6419:
1.855 bisitz 6420: .LC_nobreak {
1.544 albertel 6421: white-space: nowrap;
1.519 raeburn 6422: }
6423:
1.576 raeburn 6424: span.LC_cusr_emph {
6425: font-style: italic;
6426: }
6427:
1.633 raeburn 6428: span.LC_cusr_subheading {
6429: font-weight: normal;
6430: font-size: 85%;
6431: }
6432:
1.861 bisitz 6433: div.LC_docs_entry_move {
1.859 bisitz 6434: border: 1px solid #BBBBBB;
1.545 albertel 6435: background: #DDDDDD;
1.861 bisitz 6436: width: 22px;
1.859 bisitz 6437: padding: 1px;
6438: margin: 0;
1.545 albertel 6439: }
6440:
1.861 bisitz 6441: table.LC_data_table tr > td.LC_docs_entry_commands,
6442: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6443: font-size: x-small;
6444: }
1.795 www 6445:
1.861 bisitz 6446: .LC_docs_entry_parameter {
6447: white-space: nowrap;
6448: }
6449:
1.544 albertel 6450: .LC_docs_copy {
1.545 albertel 6451: color: #000099;
1.544 albertel 6452: }
1.795 www 6453:
1.544 albertel 6454: .LC_docs_cut {
1.545 albertel 6455: color: #550044;
1.544 albertel 6456: }
1.795 www 6457:
1.544 albertel 6458: .LC_docs_rename {
1.545 albertel 6459: color: #009900;
1.544 albertel 6460: }
1.795 www 6461:
1.544 albertel 6462: .LC_docs_remove {
1.545 albertel 6463: color: #990000;
6464: }
6465:
1.547 albertel 6466: .LC_docs_reinit_warn,
6467: .LC_docs_ext_edit {
6468: font-size: x-small;
6469: }
6470:
1.545 albertel 6471: table.LC_docs_adddocs td,
6472: table.LC_docs_adddocs th {
6473: border: 1px solid #BBBBBB;
6474: padding: 4px;
6475: background: #DDDDDD;
1.543 albertel 6476: }
6477:
1.584 albertel 6478: table.LC_sty_begin {
6479: background: #BBFFBB;
6480: }
1.795 www 6481:
1.584 albertel 6482: table.LC_sty_end {
6483: background: #FFBBBB;
6484: }
6485:
1.589 raeburn 6486: table.LC_double_column {
1.803 bisitz 6487: border-width: 0;
1.589 raeburn 6488: border-collapse: collapse;
6489: width: 100%;
6490: padding: 2px;
6491: }
6492:
6493: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6494: top: 2px;
1.589 raeburn 6495: left: 2px;
6496: width: 47%;
6497: vertical-align: top;
6498: }
6499:
6500: table.LC_double_column tr td.LC_right_col {
6501: top: 2px;
1.779 bisitz 6502: right: 2px;
1.589 raeburn 6503: width: 47%;
6504: vertical-align: top;
6505: }
6506:
1.591 raeburn 6507: div.LC_left_float {
6508: float: left;
6509: padding-right: 5%;
1.597 albertel 6510: padding-bottom: 4px;
1.591 raeburn 6511: }
6512:
6513: div.LC_clear_float_header {
1.597 albertel 6514: padding-bottom: 2px;
1.591 raeburn 6515: }
6516:
6517: div.LC_clear_float_footer {
1.597 albertel 6518: padding-top: 10px;
1.591 raeburn 6519: clear: both;
6520: }
6521:
1.597 albertel 6522: div.LC_grade_show_user {
1.941 bisitz 6523: /* border-left: 5px solid $sidebg; */
6524: border-top: 5px solid #000000;
6525: margin: 50px 0 0 0;
1.936 bisitz 6526: padding: 15px 0 5px 10px;
1.597 albertel 6527: }
1.795 www 6528:
1.936 bisitz 6529: div.LC_grade_show_user_odd_row {
1.941 bisitz 6530: /* border-left: 5px solid #000000; */
6531: }
6532:
6533: div.LC_grade_show_user div.LC_Box {
6534: margin-right: 50px;
1.597 albertel 6535: }
6536:
6537: div.LC_grade_submissions,
6538: div.LC_grade_message_center,
1.936 bisitz 6539: div.LC_grade_info_links {
1.597 albertel 6540: margin: 5px;
6541: width: 99%;
6542: background: #FFFFFF;
6543: }
1.795 www 6544:
1.597 albertel 6545: div.LC_grade_submissions_header,
1.936 bisitz 6546: div.LC_grade_message_center_header {
1.705 tempelho 6547: font-weight: bold;
6548: font-size: large;
1.597 albertel 6549: }
1.795 www 6550:
1.597 albertel 6551: div.LC_grade_submissions_body,
1.936 bisitz 6552: div.LC_grade_message_center_body {
1.597 albertel 6553: border: 1px solid black;
6554: width: 99%;
6555: background: #FFFFFF;
6556: }
1.795 www 6557:
1.613 albertel 6558: table.LC_scantron_action {
6559: width: 100%;
6560: }
1.795 www 6561:
1.613 albertel 6562: table.LC_scantron_action tr th {
1.698 harmsja 6563: font-weight:bold;
6564: font-style:normal;
1.613 albertel 6565: }
1.795 www 6566:
1.779 bisitz 6567: .LC_edit_problem_header,
1.614 albertel 6568: div.LC_edit_problem_footer {
1.705 tempelho 6569: font-weight: normal;
6570: font-size: medium;
1.602 albertel 6571: margin: 2px;
1.1060 bisitz 6572: background-color: $sidebg;
1.600 albertel 6573: }
1.795 www 6574:
1.600 albertel 6575: div.LC_edit_problem_header,
1.602 albertel 6576: div.LC_edit_problem_header div,
1.614 albertel 6577: div.LC_edit_problem_footer,
6578: div.LC_edit_problem_footer div,
1.602 albertel 6579: div.LC_edit_problem_editxml_header,
6580: div.LC_edit_problem_editxml_header div {
1.600 albertel 6581: margin-top: 5px;
6582: }
1.795 www 6583:
1.600 albertel 6584: div.LC_edit_problem_header_title {
1.705 tempelho 6585: font-weight: bold;
6586: font-size: larger;
1.602 albertel 6587: background: $tabbg;
6588: padding: 3px;
1.1060 bisitz 6589: margin: 0 0 5px 0;
1.602 albertel 6590: }
1.795 www 6591:
1.602 albertel 6592: table.LC_edit_problem_header_title {
6593: width: 100%;
1.600 albertel 6594: background: $tabbg;
1.602 albertel 6595: }
6596:
6597: div.LC_edit_problem_discards {
6598: float: left;
6599: padding-bottom: 5px;
6600: }
1.795 www 6601:
1.602 albertel 6602: div.LC_edit_problem_saves {
6603: float: right;
6604: padding-bottom: 5px;
1.600 albertel 6605: }
1.795 www 6606:
1.1075.2.34 raeburn 6607: .LC_edit_opt {
6608: padding-left: 1em;
6609: white-space: nowrap;
6610: }
6611:
1.1075.2.57 raeburn 6612: .LC_edit_problem_latexhelper{
6613: text-align: right;
6614: }
6615:
6616: #LC_edit_problem_colorful div{
6617: margin-left: 40px;
6618: }
6619:
1.911 bisitz 6620: img.stift {
1.803 bisitz 6621: border-width: 0;
6622: vertical-align: middle;
1.677 riegler 6623: }
1.680 riegler 6624:
1.923 bisitz 6625: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6626: vertical-align: top;
1.777 tempelho 6627: }
1.795 www 6628:
1.716 raeburn 6629: div.LC_createcourse {
1.911 bisitz 6630: margin: 10px 10px 10px 10px;
1.716 raeburn 6631: }
6632:
1.917 raeburn 6633: .LC_dccid {
1.1075.2.38 raeburn 6634: float: right;
1.917 raeburn 6635: margin: 0.2em 0 0 0;
6636: padding: 0;
6637: font-size: 90%;
6638: display:none;
6639: }
6640:
1.897 wenzelju 6641: ol.LC_primary_menu a:hover,
1.721 harmsja 6642: ol#LC_MenuBreadcrumbs a:hover,
6643: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6644: ul#LC_secondary_menu a:hover,
1.721 harmsja 6645: .LC_FormSectionClearButton input:hover
1.795 www 6646: ul.LC_TabContent li:hover a {
1.952 onken 6647: color:$button_hover;
1.911 bisitz 6648: text-decoration:none;
1.693 droeschl 6649: }
6650:
1.779 bisitz 6651: h1 {
1.911 bisitz 6652: padding: 0;
6653: line-height:130%;
1.693 droeschl 6654: }
1.698 harmsja 6655:
1.911 bisitz 6656: h2,
6657: h3,
6658: h4,
6659: h5,
6660: h6 {
6661: margin: 5px 0 5px 0;
6662: padding: 0;
6663: line-height:130%;
1.693 droeschl 6664: }
1.795 www 6665:
6666: .LC_hcell {
1.911 bisitz 6667: padding:3px 15px 3px 15px;
6668: margin: 0;
6669: background-color:$tabbg;
6670: color:$fontmenu;
6671: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6672: }
1.795 www 6673:
1.840 bisitz 6674: .LC_Box > .LC_hcell {
1.911 bisitz 6675: margin: 0 -10px 10px -10px;
1.835 bisitz 6676: }
6677:
1.721 harmsja 6678: .LC_noBorder {
1.911 bisitz 6679: border: 0;
1.698 harmsja 6680: }
1.693 droeschl 6681:
1.721 harmsja 6682: .LC_FormSectionClearButton input {
1.911 bisitz 6683: background-color:transparent;
6684: border: none;
6685: cursor:pointer;
6686: text-decoration:underline;
1.693 droeschl 6687: }
1.763 bisitz 6688:
6689: .LC_help_open_topic {
1.911 bisitz 6690: color: #FFFFFF;
6691: background-color: #EEEEFF;
6692: margin: 1px;
6693: padding: 4px;
6694: border: 1px solid #000033;
6695: white-space: nowrap;
6696: /* vertical-align: middle; */
1.759 neumanie 6697: }
1.693 droeschl 6698:
1.911 bisitz 6699: dl,
6700: ul,
6701: div,
6702: fieldset {
6703: margin: 10px 10px 10px 0;
6704: /* overflow: hidden; */
1.693 droeschl 6705: }
1.795 www 6706:
1.1075.2.90 raeburn 6707: article.geogebraweb div {
6708: margin: 0;
6709: }
6710:
1.838 bisitz 6711: fieldset > legend {
1.911 bisitz 6712: font-weight: bold;
6713: padding: 0 5px 0 5px;
1.838 bisitz 6714: }
6715:
1.813 bisitz 6716: #LC_nav_bar {
1.911 bisitz 6717: float: left;
1.995 raeburn 6718: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6719: margin: 0 0 2px 0;
1.807 droeschl 6720: }
6721:
1.916 droeschl 6722: #LC_realm {
6723: margin: 0.2em 0 0 0;
6724: padding: 0;
6725: font-weight: bold;
6726: text-align: center;
1.995 raeburn 6727: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6728: }
6729:
1.911 bisitz 6730: #LC_nav_bar em {
6731: font-weight: bold;
6732: font-style: normal;
1.807 droeschl 6733: }
6734:
1.897 wenzelju 6735: ol.LC_primary_menu {
1.934 droeschl 6736: margin: 0;
1.1075.2.2 raeburn 6737: padding: 0;
1.995 raeburn 6738: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6739: }
6740:
1.852 droeschl 6741: ol#LC_PathBreadcrumbs {
1.911 bisitz 6742: margin: 0;
1.693 droeschl 6743: }
6744:
1.897 wenzelju 6745: ol.LC_primary_menu li {
1.1075.2.2 raeburn 6746: color: RGB(80, 80, 80);
6747: vertical-align: middle;
6748: text-align: left;
6749: list-style: none;
6750: float: left;
6751: }
6752:
6753: ol.LC_primary_menu li a {
6754: display: block;
6755: margin: 0;
6756: padding: 0 5px 0 10px;
6757: text-decoration: none;
6758: }
6759:
6760: ol.LC_primary_menu li ul {
6761: display: none;
6762: width: 10em;
6763: background-color: $data_table_light;
6764: }
6765:
6766: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6767: display: block;
6768: position: absolute;
6769: margin: 0;
6770: padding: 0;
1.1075.2.5 raeburn 6771: z-index: 2;
1.1075.2.2 raeburn 6772: }
6773:
6774: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6775: font-size: 90%;
1.911 bisitz 6776: vertical-align: top;
1.1075.2.2 raeburn 6777: float: none;
1.1075.2.5 raeburn 6778: border-left: 1px solid black;
6779: border-right: 1px solid black;
1.1075.2.2 raeburn 6780: }
6781:
6782: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1075.2.5 raeburn 6783: background-color:$data_table_light;
1.1075.2.2 raeburn 6784: }
6785:
6786: ol.LC_primary_menu li li a:hover {
6787: color:$button_hover;
6788: background-color:$data_table_dark;
1.693 droeschl 6789: }
6790:
1.897 wenzelju 6791: ol.LC_primary_menu li img {
1.911 bisitz 6792: vertical-align: bottom;
1.934 droeschl 6793: height: 1.1em;
1.1075.2.3 raeburn 6794: margin: 0.2em 0 0 0;
1.693 droeschl 6795: }
6796:
1.897 wenzelju 6797: ol.LC_primary_menu a {
1.911 bisitz 6798: color: RGB(80, 80, 80);
6799: text-decoration: none;
1.693 droeschl 6800: }
1.795 www 6801:
1.949 droeschl 6802: ol.LC_primary_menu a.LC_new_message {
6803: font-weight:bold;
6804: color: darkred;
6805: }
6806:
1.975 raeburn 6807: ol.LC_docs_parameters {
6808: margin-left: 0;
6809: padding: 0;
6810: list-style: none;
6811: }
6812:
6813: ol.LC_docs_parameters li {
6814: margin: 0;
6815: padding-right: 20px;
6816: display: inline;
6817: }
6818:
1.976 raeburn 6819: ol.LC_docs_parameters li:before {
6820: content: "\\002022 \\0020";
6821: }
6822:
6823: li.LC_docs_parameters_title {
6824: font-weight: bold;
6825: }
6826:
6827: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6828: content: "";
6829: }
6830:
1.897 wenzelju 6831: ul#LC_secondary_menu {
1.1075.2.23 raeburn 6832: clear: right;
1.911 bisitz 6833: color: $fontmenu;
6834: background: $tabbg;
6835: list-style: none;
6836: padding: 0;
6837: margin: 0;
6838: width: 100%;
1.995 raeburn 6839: text-align: left;
1.1075.2.4 raeburn 6840: float: left;
1.808 droeschl 6841: }
6842:
1.897 wenzelju 6843: ul#LC_secondary_menu li {
1.911 bisitz 6844: font-weight: bold;
6845: line-height: 1.8em;
6846: border-right: 1px solid black;
6847: vertical-align: middle;
1.1075.2.4 raeburn 6848: float: left;
6849: }
6850:
6851: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6852: background-color: $data_table_light;
6853: }
6854:
6855: ul#LC_secondary_menu li a {
6856: padding: 0 0.8em;
6857: }
6858:
6859: ul#LC_secondary_menu li ul {
6860: display: none;
6861: }
6862:
6863: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6864: display: block;
6865: position: absolute;
6866: margin: 0;
6867: padding: 0;
6868: list-style:none;
6869: float: none;
6870: background-color: $data_table_light;
1.1075.2.5 raeburn 6871: z-index: 2;
1.1075.2.10 raeburn 6872: margin-left: -1px;
1.1075.2.4 raeburn 6873: }
6874:
6875: ul#LC_secondary_menu li ul li {
6876: font-size: 90%;
6877: vertical-align: top;
6878: border-left: 1px solid black;
6879: border-right: 1px solid black;
1.1075.2.33 raeburn 6880: background-color: $data_table_light;
1.1075.2.4 raeburn 6881: list-style:none;
6882: float: none;
6883: }
6884:
6885: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6886: background-color: $data_table_dark;
1.807 droeschl 6887: }
6888:
1.847 tempelho 6889: ul.LC_TabContent {
1.911 bisitz 6890: display:block;
6891: background: $sidebg;
6892: border-bottom: solid 1px $lg_border_color;
6893: list-style:none;
1.1020 raeburn 6894: margin: -1px -10px 0 -10px;
1.911 bisitz 6895: padding: 0;
1.693 droeschl 6896: }
6897:
1.795 www 6898: ul.LC_TabContent li,
6899: ul.LC_TabContentBigger li {
1.911 bisitz 6900: float:left;
1.741 harmsja 6901: }
1.795 www 6902:
1.897 wenzelju 6903: ul#LC_secondary_menu li a {
1.911 bisitz 6904: color: $fontmenu;
6905: text-decoration: none;
1.693 droeschl 6906: }
1.795 www 6907:
1.721 harmsja 6908: ul.LC_TabContent {
1.952 onken 6909: min-height:20px;
1.721 harmsja 6910: }
1.795 www 6911:
6912: ul.LC_TabContent li {
1.911 bisitz 6913: vertical-align:middle;
1.959 onken 6914: padding: 0 16px 0 10px;
1.911 bisitz 6915: background-color:$tabbg;
6916: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6917: border-left: solid 1px $font;
1.721 harmsja 6918: }
1.795 www 6919:
1.847 tempelho 6920: ul.LC_TabContent .right {
1.911 bisitz 6921: float:right;
1.847 tempelho 6922: }
6923:
1.911 bisitz 6924: ul.LC_TabContent li a,
6925: ul.LC_TabContent li {
6926: color:rgb(47,47,47);
6927: text-decoration:none;
6928: font-size:95%;
6929: font-weight:bold;
1.952 onken 6930: min-height:20px;
6931: }
6932:
1.959 onken 6933: ul.LC_TabContent li a:hover,
6934: ul.LC_TabContent li a:focus {
1.952 onken 6935: color: $button_hover;
1.959 onken 6936: background:none;
6937: outline:none;
1.952 onken 6938: }
6939:
6940: ul.LC_TabContent li:hover {
6941: color: $button_hover;
6942: cursor:pointer;
1.721 harmsja 6943: }
1.795 www 6944:
1.911 bisitz 6945: ul.LC_TabContent li.active {
1.952 onken 6946: color: $font;
1.911 bisitz 6947: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6948: border-bottom:solid 1px #FFFFFF;
6949: cursor: default;
1.744 ehlerst 6950: }
1.795 www 6951:
1.959 onken 6952: ul.LC_TabContent li.active a {
6953: color:$font;
6954: background:#FFFFFF;
6955: outline: none;
6956: }
1.1047 raeburn 6957:
6958: ul.LC_TabContent li.goback {
6959: float: left;
6960: border-left: none;
6961: }
6962:
1.870 tempelho 6963: #maincoursedoc {
1.911 bisitz 6964: clear:both;
1.870 tempelho 6965: }
6966:
6967: ul.LC_TabContentBigger {
1.911 bisitz 6968: display:block;
6969: list-style:none;
6970: padding: 0;
1.870 tempelho 6971: }
6972:
1.795 www 6973: ul.LC_TabContentBigger li {
1.911 bisitz 6974: vertical-align:bottom;
6975: height: 30px;
6976: font-size:110%;
6977: font-weight:bold;
6978: color: #737373;
1.841 tempelho 6979: }
6980:
1.957 onken 6981: ul.LC_TabContentBigger li.active {
6982: position: relative;
6983: top: 1px;
6984: }
6985:
1.870 tempelho 6986: ul.LC_TabContentBigger li a {
1.911 bisitz 6987: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6988: height: 30px;
6989: line-height: 30px;
6990: text-align: center;
6991: display: block;
6992: text-decoration: none;
1.958 onken 6993: outline: none;
1.741 harmsja 6994: }
1.795 www 6995:
1.870 tempelho 6996: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6997: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6998: color:$font;
1.744 ehlerst 6999: }
1.795 www 7000:
1.870 tempelho 7001: ul.LC_TabContentBigger li b {
1.911 bisitz 7002: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7003: display: block;
7004: float: left;
7005: padding: 0 30px;
1.957 onken 7006: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7007: }
7008:
1.956 onken 7009: ul.LC_TabContentBigger li:hover b {
7010: color:$button_hover;
7011: }
7012:
1.870 tempelho 7013: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7014: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7015: color:$font;
1.957 onken 7016: border: 0;
1.741 harmsja 7017: }
1.693 droeschl 7018:
1.870 tempelho 7019:
1.862 bisitz 7020: ul.LC_CourseBreadcrumbs {
7021: background: $sidebg;
1.1020 raeburn 7022: height: 2em;
1.862 bisitz 7023: padding-left: 10px;
1.1020 raeburn 7024: margin: 0;
1.862 bisitz 7025: list-style-position: inside;
7026: }
7027:
1.911 bisitz 7028: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7029: ol#LC_PathBreadcrumbs {
1.911 bisitz 7030: padding-left: 10px;
7031: margin: 0;
1.933 droeschl 7032: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7033: }
7034:
1.911 bisitz 7035: ol#LC_MenuBreadcrumbs li,
7036: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7037: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7038: display: inline;
1.933 droeschl 7039: white-space: normal;
1.693 droeschl 7040: }
7041:
1.823 bisitz 7042: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7043: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7044: text-decoration: none;
7045: font-size:90%;
1.693 droeschl 7046: }
1.795 www 7047:
1.969 droeschl 7048: ol#LC_MenuBreadcrumbs h1 {
7049: display: inline;
7050: font-size: 90%;
7051: line-height: 2.5em;
7052: margin: 0;
7053: padding: 0;
7054: }
7055:
1.795 www 7056: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7057: text-decoration:none;
7058: font-size:100%;
7059: font-weight:bold;
1.693 droeschl 7060: }
1.795 www 7061:
1.840 bisitz 7062: .LC_Box {
1.911 bisitz 7063: border: solid 1px $lg_border_color;
7064: padding: 0 10px 10px 10px;
1.746 neumanie 7065: }
1.795 www 7066:
1.1020 raeburn 7067: .LC_DocsBox {
7068: border: solid 1px $lg_border_color;
7069: padding: 0 0 10px 10px;
7070: }
7071:
1.795 www 7072: .LC_AboutMe_Image {
1.911 bisitz 7073: float:left;
7074: margin-right:10px;
1.747 neumanie 7075: }
1.795 www 7076:
7077: .LC_Clear_AboutMe_Image {
1.911 bisitz 7078: clear:left;
1.747 neumanie 7079: }
1.795 www 7080:
1.721 harmsja 7081: dl.LC_ListStyleClean dt {
1.911 bisitz 7082: padding-right: 5px;
7083: display: table-header-group;
1.693 droeschl 7084: }
7085:
1.721 harmsja 7086: dl.LC_ListStyleClean dd {
1.911 bisitz 7087: display: table-row;
1.693 droeschl 7088: }
7089:
1.721 harmsja 7090: .LC_ListStyleClean,
7091: .LC_ListStyleSimple,
7092: .LC_ListStyleNormal,
1.795 www 7093: .LC_ListStyleSpecial {
1.911 bisitz 7094: /* display:block; */
7095: list-style-position: inside;
7096: list-style-type: none;
7097: overflow: hidden;
7098: padding: 0;
1.693 droeschl 7099: }
7100:
1.721 harmsja 7101: .LC_ListStyleSimple li,
7102: .LC_ListStyleSimple dd,
7103: .LC_ListStyleNormal li,
7104: .LC_ListStyleNormal dd,
7105: .LC_ListStyleSpecial li,
1.795 www 7106: .LC_ListStyleSpecial dd {
1.911 bisitz 7107: margin: 0;
7108: padding: 5px 5px 5px 10px;
7109: clear: both;
1.693 droeschl 7110: }
7111:
1.721 harmsja 7112: .LC_ListStyleClean li,
7113: .LC_ListStyleClean dd {
1.911 bisitz 7114: padding-top: 0;
7115: padding-bottom: 0;
1.693 droeschl 7116: }
7117:
1.721 harmsja 7118: .LC_ListStyleSimple dd,
1.795 www 7119: .LC_ListStyleSimple li {
1.911 bisitz 7120: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7121: }
7122:
1.721 harmsja 7123: .LC_ListStyleSpecial li,
7124: .LC_ListStyleSpecial dd {
1.911 bisitz 7125: list-style-type: none;
7126: background-color: RGB(220, 220, 220);
7127: margin-bottom: 4px;
1.693 droeschl 7128: }
7129:
1.721 harmsja 7130: table.LC_SimpleTable {
1.911 bisitz 7131: margin:5px;
7132: border:solid 1px $lg_border_color;
1.795 www 7133: }
1.693 droeschl 7134:
1.721 harmsja 7135: table.LC_SimpleTable tr {
1.911 bisitz 7136: padding: 0;
7137: border:solid 1px $lg_border_color;
1.693 droeschl 7138: }
1.795 www 7139:
7140: table.LC_SimpleTable thead {
1.911 bisitz 7141: background:rgb(220,220,220);
1.693 droeschl 7142: }
7143:
1.721 harmsja 7144: div.LC_columnSection {
1.911 bisitz 7145: display: block;
7146: clear: both;
7147: overflow: hidden;
7148: margin: 0;
1.693 droeschl 7149: }
7150:
1.721 harmsja 7151: div.LC_columnSection>* {
1.911 bisitz 7152: float: left;
7153: margin: 10px 20px 10px 0;
7154: overflow:hidden;
1.693 droeschl 7155: }
1.721 harmsja 7156:
1.795 www 7157: table em {
1.911 bisitz 7158: font-weight: bold;
7159: font-style: normal;
1.748 schulted 7160: }
1.795 www 7161:
1.779 bisitz 7162: table.LC_tableBrowseRes,
1.795 www 7163: table.LC_tableOfContent {
1.911 bisitz 7164: border:none;
7165: border-spacing: 1px;
7166: padding: 3px;
7167: background-color: #FFFFFF;
7168: font-size: 90%;
1.753 droeschl 7169: }
1.789 droeschl 7170:
1.911 bisitz 7171: table.LC_tableOfContent {
7172: border-collapse: collapse;
1.789 droeschl 7173: }
7174:
1.771 droeschl 7175: table.LC_tableBrowseRes a,
1.768 schulted 7176: table.LC_tableOfContent a {
1.911 bisitz 7177: background-color: transparent;
7178: text-decoration: none;
1.753 droeschl 7179: }
7180:
1.795 www 7181: table.LC_tableOfContent img {
1.911 bisitz 7182: border: none;
7183: height: 1.3em;
7184: vertical-align: text-bottom;
7185: margin-right: 0.3em;
1.753 droeschl 7186: }
1.757 schulted 7187:
1.795 www 7188: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7189: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7190: }
7191:
1.795 www 7192: a#LC_content_toolbar_everything {
1.911 bisitz 7193: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7194: }
7195:
1.795 www 7196: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7197: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7198: }
7199:
1.795 www 7200: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7201: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7202: }
7203:
1.795 www 7204: a#LC_content_toolbar_changefolder {
1.911 bisitz 7205: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7206: }
7207:
1.795 www 7208: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7209: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7210: }
7211:
1.1043 raeburn 7212: a#LC_content_toolbar_edittoplevel {
7213: background-image:url(/res/adm/pages/edittoplevel.gif);
7214: }
7215:
1.795 www 7216: ul#LC_toolbar li a:hover {
1.911 bisitz 7217: background-position: bottom center;
1.757 schulted 7218: }
7219:
1.795 www 7220: ul#LC_toolbar {
1.911 bisitz 7221: padding: 0;
7222: margin: 2px;
7223: list-style:none;
7224: position:relative;
7225: background-color:white;
1.1075.2.9 raeburn 7226: overflow: auto;
1.757 schulted 7227: }
7228:
1.795 www 7229: ul#LC_toolbar li {
1.911 bisitz 7230: border:1px solid white;
7231: padding: 0;
7232: margin: 0;
7233: float: left;
7234: display:inline;
7235: vertical-align:middle;
1.1075.2.9 raeburn 7236: white-space: nowrap;
1.911 bisitz 7237: }
1.757 schulted 7238:
1.783 amueller 7239:
1.795 www 7240: a.LC_toolbarItem {
1.911 bisitz 7241: display:block;
7242: padding: 0;
7243: margin: 0;
7244: height: 32px;
7245: width: 32px;
7246: color:white;
7247: border: none;
7248: background-repeat:no-repeat;
7249: background-color:transparent;
1.757 schulted 7250: }
7251:
1.915 droeschl 7252: ul.LC_funclist {
7253: margin: 0;
7254: padding: 0.5em 1em 0.5em 0;
7255: }
7256:
1.933 droeschl 7257: ul.LC_funclist > li:first-child {
7258: font-weight:bold;
7259: margin-left:0.8em;
7260: }
7261:
1.915 droeschl 7262: ul.LC_funclist + ul.LC_funclist {
7263: /*
7264: left border as a seperator if we have more than
7265: one list
7266: */
7267: border-left: 1px solid $sidebg;
7268: /*
7269: this hides the left border behind the border of the
7270: outer box if element is wrapped to the next 'line'
7271: */
7272: margin-left: -1px;
7273: }
7274:
1.843 bisitz 7275: ul.LC_funclist li {
1.915 droeschl 7276: display: inline;
1.782 bisitz 7277: white-space: nowrap;
1.915 droeschl 7278: margin: 0 0 0 25px;
7279: line-height: 150%;
1.782 bisitz 7280: }
7281:
1.974 wenzelju 7282: .LC_hidden {
7283: display: none;
7284: }
7285:
1.1030 www 7286: .LCmodal-overlay {
7287: position:fixed;
7288: top:0;
7289: right:0;
7290: bottom:0;
7291: left:0;
7292: height:100%;
7293: width:100%;
7294: margin:0;
7295: padding:0;
7296: background:#999;
7297: opacity:.75;
7298: filter: alpha(opacity=75);
7299: -moz-opacity: 0.75;
7300: z-index:101;
7301: }
7302:
7303: * html .LCmodal-overlay {
7304: position: absolute;
7305: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7306: }
7307:
7308: .LCmodal-window {
7309: position:fixed;
7310: top:50%;
7311: left:50%;
7312: margin:0;
7313: padding:0;
7314: z-index:102;
7315: }
7316:
7317: * html .LCmodal-window {
7318: position:absolute;
7319: }
7320:
7321: .LCclose-window {
7322: position:absolute;
7323: width:32px;
7324: height:32px;
7325: right:8px;
7326: top:8px;
7327: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7328: text-indent:-99999px;
7329: overflow:hidden;
7330: cursor:pointer;
7331: }
7332:
1.1075.2.17 raeburn 7333: /*
7334: styles used by TTH when "Default set of options to pass to tth/m
7335: when converting TeX" in course settings has been set
7336:
7337: option passed: -t
7338:
7339: */
7340:
7341: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7342: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7343: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7344: td div.norm {line-height:normal;}
7345:
7346: /*
7347: option passed -y3
7348: */
7349:
7350: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7351: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7352: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7353:
1.343 albertel 7354: END
7355: }
7356:
1.306 albertel 7357: =pod
7358:
7359: =item * &headtag()
7360:
7361: Returns a uniform footer for LON-CAPA web pages.
7362:
1.307 albertel 7363: Inputs: $title - optional title for the head
7364: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7365: $args - optional arguments
1.319 albertel 7366: force_register - if is true call registerurl so the remote is
7367: informed
1.415 albertel 7368: redirect -> array ref of
7369: 1- seconds before redirect occurs
7370: 2- url to redirect to
7371: 3- whether the side effect should occur
1.315 albertel 7372: (side effect of setting
7373: $env{'internal.head.redirect'} to the url
7374: redirected too)
1.352 albertel 7375: domain -> force to color decorate a page for a specific
7376: domain
7377: function -> force usage of a specific rolish color scheme
7378: bgcolor -> override the default page bgcolor
1.460 albertel 7379: no_auto_mt_title
7380: -> prevent &mt()ing the title arg
1.464 albertel 7381:
1.306 albertel 7382: =cut
7383:
7384: sub headtag {
1.313 albertel 7385: my ($title,$head_extra,$args) = @_;
1.306 albertel 7386:
1.363 albertel 7387: my $function = $args->{'function'} || &get_users_function();
7388: my $domain = $args->{'domain'} || &determinedomain();
7389: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7390: my $httphost = $args->{'use_absolute'};
1.418 albertel 7391: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7392: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7393: #time(),
1.418 albertel 7394: $env{'environment.color.timestamp'},
1.363 albertel 7395: $function,$domain,$bgcolor);
7396:
1.369 www 7397: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7398:
1.308 albertel 7399: my $result =
7400: '<head>'.
1.1075.2.56 raeburn 7401: &font_settings($args);
1.319 albertel 7402:
1.1075.2.72 raeburn 7403: my $inhibitprint;
7404: if ($args->{'print_suppress'}) {
7405: $inhibitprint = &print_suppression();
7406: }
1.1064 raeburn 7407:
1.461 albertel 7408: if (!$args->{'frameset'}) {
7409: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7410: }
1.1075.2.12 raeburn 7411: if ($args->{'force_register'}) {
7412: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7413: }
1.436 albertel 7414: if (!$args->{'no_nav_bar'}
7415: && !$args->{'only_body'}
7416: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7417: $result .= &help_menu_js($httphost);
1.1032 www 7418: $result.=&modal_window();
1.1038 www 7419: $result.=&togglebox_script();
1.1034 www 7420: $result.=&wishlist_window();
1.1041 www 7421: $result.=&LCprogressbarUpdate_script();
1.1034 www 7422: } else {
7423: if ($args->{'add_modal'}) {
7424: $result.=&modal_window();
7425: }
7426: if ($args->{'add_wishlist'}) {
7427: $result.=&wishlist_window();
7428: }
1.1038 www 7429: if ($args->{'add_togglebox'}) {
7430: $result.=&togglebox_script();
7431: }
1.1041 www 7432: if ($args->{'add_progressbar'}) {
7433: $result.=&LCprogressbarUpdate_script();
7434: }
1.436 albertel 7435: }
1.314 albertel 7436: if (ref($args->{'redirect'})) {
1.414 albertel 7437: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7438: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7439: if (!$inhibit_continue) {
7440: $env{'internal.head.redirect'} = $url;
7441: }
1.313 albertel 7442: $result.=<<ADDMETA
7443: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7444: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7445: ADDMETA
1.1075.2.89 raeburn 7446: } else {
7447: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
7448: my $requrl = $env{'request.uri'};
7449: if ($requrl eq '') {
7450: $requrl = $ENV{'REQUEST_URI'};
7451: $requrl =~ s/\?.+$//;
7452: }
7453: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
7454: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
7455: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
7456: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
7457: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
7458: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
7459: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
7460: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7461: if ($domdefs{'offloadnow'}{$lonhost}) {
7462: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
7463: if (($newserver) && ($newserver ne $lonhost)) {
7464: my $numsec = 5;
7465: my $timeout = $numsec * 1000;
7466: my ($newurl,$locknum,%locks,$msg);
7467: if ($env{'request.role.adv'}) {
7468: ($locknum,%locks) = &Apache::lonnet::get_locks();
7469: }
7470: my $disable_submit = 0;
7471: if ($requrl =~ /$LONCAPA::assess_re/) {
7472: $disable_submit = 1;
7473: }
7474: if ($locknum) {
7475: my @lockinfo = sort(values(%locks));
7476: $msg = &mt('Once the following tasks are complete: ')."\\n".
7477: join(", ",sort(values(%locks)))."\\n".
7478: &mt('your session will be transferred to a different server, after you click "Roles".');
7479: } else {
7480: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
7481: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
7482: }
7483: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
7484: $newurl = '/adm/switchserver?otherserver='.$newserver;
7485: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
7486: $newurl .= '&role='.$env{'request.role'};
7487: }
7488: if ($env{'request.symb'}) {
7489: $newurl .= '&symb='.$env{'request.symb'};
7490: } else {
7491: $newurl .= '&origurl='.$requrl;
7492: }
7493: }
1.1075.2.98 raeburn 7494: &js_escape(\$msg);
1.1075.2.89 raeburn 7495: $result.=<<OFFLOAD
7496: <meta http-equiv="pragma" content="no-cache" />
7497: <script type="text/javascript">
1.1075.2.92 raeburn 7498: // <![CDATA[
1.1075.2.89 raeburn 7499: function LC_Offload_Now() {
7500: var dest = "$newurl";
7501: if (dest != '') {
7502: window.location.href="$newurl";
7503: }
7504: }
1.1075.2.92 raeburn 7505: \$(document).ready(function () {
7506: window.alert('$msg');
7507: if ($disable_submit) {
1.1075.2.89 raeburn 7508: \$(".LC_hwk_submit").prop("disabled", true);
7509: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 7510: }
7511: setTimeout('LC_Offload_Now()', $timeout);
7512: });
7513: // ]]>
1.1075.2.89 raeburn 7514: </script>
7515: OFFLOAD
7516: }
7517: }
7518: }
7519: }
7520: }
7521: }
1.313 albertel 7522: }
1.306 albertel 7523: if (!defined($title)) {
7524: $title = 'The LearningOnline Network with CAPA';
7525: }
1.460 albertel 7526: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7527: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 7528: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7529: if (!$args->{'frameset'}) {
7530: $result .= ' /';
7531: }
7532: $result .= '>'
1.1064 raeburn 7533: .$inhibitprint
1.414 albertel 7534: .$head_extra;
1.1075.2.42 raeburn 7535: if ($env{'browser.mobile'}) {
7536: $result .= '
7537: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7538: <meta name="apple-mobile-web-app-capable" content="yes" />';
7539: }
1.962 droeschl 7540: return $result.'</head>';
1.306 albertel 7541: }
7542:
7543: =pod
7544:
1.340 albertel 7545: =item * &font_settings()
7546:
7547: Returns neccessary <meta> to set the proper encoding
7548:
1.1075.2.56 raeburn 7549: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7550:
7551: =cut
7552:
7553: sub font_settings {
1.1075.2.56 raeburn 7554: my ($args) = @_;
1.340 albertel 7555: my $headerstring='';
1.1075.2.56 raeburn 7556: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7557: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 7558: $headerstring.=
1.1075.2.61 raeburn 7559: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7560: if (!$args->{'frameset'}) {
7561: $headerstring.= ' /';
7562: }
7563: $headerstring .= '>'."\n";
1.340 albertel 7564: }
7565: return $headerstring;
7566: }
7567:
1.341 albertel 7568: =pod
7569:
1.1064 raeburn 7570: =item * &print_suppression()
7571:
7572: In course context returns css which causes the body to be blank when media="print",
7573: if printout generation is unavailable for the current resource.
7574:
7575: This could be because:
7576:
7577: (a) printstartdate is in the future
7578:
7579: (b) printenddate is in the past
7580:
7581: (c) there is an active exam block with "printout"
7582: functionality blocked
7583:
7584: Users with pav, pfo or evb privileges are exempt.
7585:
7586: Inputs: none
7587:
7588: =cut
7589:
7590:
7591: sub print_suppression {
7592: my $noprint;
7593: if ($env{'request.course.id'}) {
7594: my $scope = $env{'request.course.id'};
7595: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7596: (&Apache::lonnet::allowed('pfo',$scope))) {
7597: return;
7598: }
7599: if ($env{'request.course.sec'} ne '') {
7600: $scope .= "/$env{'request.course.sec'}";
7601: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7602: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7603: return;
1.1064 raeburn 7604: }
7605: }
7606: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7607: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73 raeburn 7608: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 7609: if ($blocked) {
7610: my $checkrole = "cm./$cdom/$cnum";
7611: if ($env{'request.course.sec'} ne '') {
7612: $checkrole .= "/$env{'request.course.sec'}";
7613: }
7614: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7615: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7616: $noprint = 1;
7617: }
7618: }
7619: unless ($noprint) {
7620: my $symb = &Apache::lonnet::symbread();
7621: if ($symb ne '') {
7622: my $navmap = Apache::lonnavmaps::navmap->new();
7623: if (ref($navmap)) {
7624: my $res = $navmap->getBySymb($symb);
7625: if (ref($res)) {
7626: if (!$res->resprintable()) {
7627: $noprint = 1;
7628: }
7629: }
7630: }
7631: }
7632: }
7633: if ($noprint) {
7634: return <<"ENDSTYLE";
7635: <style type="text/css" media="print">
7636: body { display:none }
7637: </style>
7638: ENDSTYLE
7639: }
7640: }
7641: return;
7642: }
7643:
7644: =pod
7645:
1.341 albertel 7646: =item * &xml_begin()
7647:
7648: Returns the needed doctype and <html>
7649:
7650: Inputs: none
7651:
7652: =cut
7653:
7654: sub xml_begin {
1.1075.2.61 raeburn 7655: my ($is_frameset) = @_;
1.341 albertel 7656: my $output='';
7657:
7658: if ($env{'browser.mathml'}) {
7659: $output='<?xml version="1.0"?>'
7660: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7661: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7662:
7663: # .'<!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">] >'
7664: .'<!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">'
7665: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7666: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 7667: } elsif ($is_frameset) {
7668: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
7669: '<html>'."\n";
1.341 albertel 7670: } else {
1.1075.2.61 raeburn 7671: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
7672: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7673: }
7674: return $output;
7675: }
1.340 albertel 7676:
7677: =pod
7678:
1.306 albertel 7679: =item * &start_page()
7680:
7681: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7682:
1.648 raeburn 7683: Inputs:
7684:
7685: =over 4
7686:
7687: $title - optional title for the page
7688:
7689: $head_extra - optional extra HTML to incude inside the <head>
7690:
7691: $args - additional optional args supported are:
7692:
7693: =over 8
7694:
7695: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7696: arg on
1.814 bisitz 7697: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7698: add_entries -> additional attributes to add to the <body>
7699: domain -> force to color decorate a page for a
1.317 albertel 7700: specific domain
1.648 raeburn 7701: function -> force usage of a specific rolish color
1.317 albertel 7702: scheme
1.648 raeburn 7703: redirect -> see &headtag()
7704: bgcolor -> override the default page bg color
7705: js_ready -> return a string ready for being used in
1.317 albertel 7706: a javascript writeln
1.648 raeburn 7707: html_encode -> return a string ready for being used in
1.320 albertel 7708: a html attribute
1.648 raeburn 7709: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7710: $forcereg arg
1.648 raeburn 7711: frameset -> if true will start with a <frameset>
1.330 albertel 7712: rather than <body>
1.648 raeburn 7713: skip_phases -> hash ref of
1.338 albertel 7714: head -> skip the <html><head> generation
7715: body -> skip all <body> generation
1.1075.2.12 raeburn 7716: no_inline_link -> if true and in remote mode, don't show the
7717: 'Switch To Inline Menu' link
1.648 raeburn 7718: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 7719: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7720: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.15 raeburn 7721: group -> includes the current group, if page is for a
7722: specific group
1.361 albertel 7723:
1.648 raeburn 7724: =back
1.460 albertel 7725:
1.648 raeburn 7726: =back
1.562 albertel 7727:
1.306 albertel 7728: =cut
7729:
7730: sub start_page {
1.309 albertel 7731: my ($title,$head_extra,$args) = @_;
1.318 albertel 7732: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7733:
1.315 albertel 7734: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 7735: my ($result,@advtools);
1.964 droeschl 7736:
1.338 albertel 7737: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 7738: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 7739: }
7740:
7741: if (! exists($args->{'skip_phases'}{'body'}) ) {
7742: if ($args->{'frameset'}) {
7743: my $attr_string = &make_attr_string($args->{'force_register'},
7744: $args->{'add_entries'});
7745: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7746: } else {
7747: $result .=
7748: &bodytag($title,
7749: $args->{'function'}, $args->{'add_entries'},
7750: $args->{'only_body'}, $args->{'domain'},
7751: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 7752: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 7753: $args, \@advtools);
1.831 bisitz 7754: }
1.330 albertel 7755: }
1.338 albertel 7756:
1.315 albertel 7757: if ($args->{'js_ready'}) {
1.713 kaisler 7758: $result = &js_ready($result);
1.315 albertel 7759: }
1.320 albertel 7760: if ($args->{'html_encode'}) {
1.713 kaisler 7761: $result = &html_encode($result);
7762: }
7763:
1.813 bisitz 7764: # Preparation for new and consistent functionlist at top of screen
7765: # if ($args->{'functionlist'}) {
7766: # $result .= &build_functionlist();
7767: #}
7768:
1.964 droeschl 7769: # Don't add anything more if only_body wanted or in const space
7770: return $result if $args->{'only_body'}
7771: || $env{'request.state'} eq 'construct';
1.813 bisitz 7772:
7773: #Breadcrumbs
1.758 kaisler 7774: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7775: &Apache::lonhtmlcommon::clear_breadcrumbs();
7776: #if any br links exists, add them to the breadcrumbs
7777: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7778: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7779: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7780: }
7781: }
1.1075.2.19 raeburn 7782: # if @advtools array contains items add then to the breadcrumbs
7783: if (@advtools > 0) {
7784: &Apache::lonmenu::advtools_crumbs(@advtools);
7785: }
1.758 kaisler 7786:
7787: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7788: if(exists($args->{'bread_crumbs_component'})){
7789: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7790: }else{
7791: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7792: }
1.1075.2.24 raeburn 7793: } elsif (($env{'environment.remote'} eq 'on') &&
7794: ($env{'form.inhibitmenu'} ne 'yes') &&
7795: ($env{'request.noversionuri'} =~ m{^/res/}) &&
7796: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 7797: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 7798: }
1.315 albertel 7799: return $result;
1.306 albertel 7800: }
7801:
7802: sub end_page {
1.315 albertel 7803: my ($args) = @_;
7804: $env{'internal.end_page'}++;
1.330 albertel 7805: my $result;
1.335 albertel 7806: if ($args->{'discussion'}) {
7807: my ($target,$parser);
7808: if (ref($args->{'discussion'})) {
7809: ($target,$parser) =($args->{'discussion'}{'target'},
7810: $args->{'discussion'}{'parser'});
7811: }
7812: $result .= &Apache::lonxml::xmlend($target,$parser);
7813: }
1.330 albertel 7814: if ($args->{'frameset'}) {
7815: $result .= '</frameset>';
7816: } else {
1.635 raeburn 7817: $result .= &endbodytag($args);
1.330 albertel 7818: }
1.1075.2.6 raeburn 7819: unless ($args->{'notbody'}) {
7820: $result .= "\n</html>";
7821: }
1.330 albertel 7822:
1.315 albertel 7823: if ($args->{'js_ready'}) {
1.317 albertel 7824: $result = &js_ready($result);
1.315 albertel 7825: }
1.335 albertel 7826:
1.320 albertel 7827: if ($args->{'html_encode'}) {
7828: $result = &html_encode($result);
7829: }
1.335 albertel 7830:
1.315 albertel 7831: return $result;
7832: }
7833:
1.1034 www 7834: sub wishlist_window {
7835: return(<<'ENDWISHLIST');
1.1046 raeburn 7836: <script type="text/javascript">
1.1034 www 7837: // <![CDATA[
7838: // <!-- BEGIN LON-CAPA Internal
7839: function set_wishlistlink(title, path) {
7840: if (!title) {
7841: title = document.title;
7842: title = title.replace(/^LON-CAPA /,'');
7843: }
1.1075.2.65 raeburn 7844: title = encodeURIComponent(title);
1.1075.2.83 raeburn 7845: title = title.replace("'","\\\'");
1.1034 www 7846: if (!path) {
7847: path = location.pathname;
7848: }
1.1075.2.65 raeburn 7849: path = encodeURIComponent(path);
1.1075.2.83 raeburn 7850: path = path.replace("'","\\\'");
1.1034 www 7851: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7852: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7853: }
7854: // END LON-CAPA Internal -->
7855: // ]]>
7856: </script>
7857: ENDWISHLIST
7858: }
7859:
1.1030 www 7860: sub modal_window {
7861: return(<<'ENDMODAL');
1.1046 raeburn 7862: <script type="text/javascript">
1.1030 www 7863: // <![CDATA[
7864: // <!-- BEGIN LON-CAPA Internal
7865: var modalWindow = {
7866: parent:"body",
7867: windowId:null,
7868: content:null,
7869: width:null,
7870: height:null,
7871: close:function()
7872: {
7873: $(".LCmodal-window").remove();
7874: $(".LCmodal-overlay").remove();
7875: },
7876: open:function()
7877: {
7878: var modal = "";
7879: modal += "<div class=\"LCmodal-overlay\"></div>";
7880: 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;\">";
7881: modal += this.content;
7882: modal += "</div>";
7883:
7884: $(this.parent).append(modal);
7885:
7886: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7887: $(".LCclose-window").click(function(){modalWindow.close();});
7888: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7889: }
7890: };
1.1075.2.42 raeburn 7891: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7892: {
1.1075.2.83 raeburn 7893: source = source.replace("'","'");
1.1030 www 7894: modalWindow.windowId = "myModal";
7895: modalWindow.width = width;
7896: modalWindow.height = height;
1.1075.2.80 raeburn 7897: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7898: modalWindow.open();
1.1075.2.87 raeburn 7899: };
1.1030 www 7900: // END LON-CAPA Internal -->
7901: // ]]>
7902: </script>
7903: ENDMODAL
7904: }
7905:
7906: sub modal_link {
1.1075.2.42 raeburn 7907: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7908: unless ($width) { $width=480; }
7909: unless ($height) { $height=400; }
1.1031 www 7910: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 7911: unless ($transparency) { $transparency='true'; }
7912:
1.1074 raeburn 7913: my $target_attr;
7914: if (defined($target)) {
7915: $target_attr = 'target="'.$target.'"';
7916: }
7917: return <<"ENDLINK";
1.1075.2.42 raeburn 7918: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7919: $linktext</a>
7920: ENDLINK
1.1030 www 7921: }
7922:
1.1032 www 7923: sub modal_adhoc_script {
7924: my ($funcname,$width,$height,$content)=@_;
7925: return (<<ENDADHOC);
1.1046 raeburn 7926: <script type="text/javascript">
1.1032 www 7927: // <![CDATA[
7928: var $funcname = function()
7929: {
7930: modalWindow.windowId = "myModal";
7931: modalWindow.width = $width;
7932: modalWindow.height = $height;
7933: modalWindow.content = '$content';
7934: modalWindow.open();
7935: };
7936: // ]]>
7937: </script>
7938: ENDADHOC
7939: }
7940:
1.1041 www 7941: sub modal_adhoc_inner {
7942: my ($funcname,$width,$height,$content)=@_;
7943: my $innerwidth=$width-20;
7944: $content=&js_ready(
1.1042 www 7945: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 7946: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
7947: $content.
1.1041 www 7948: &end_scrollbox().
1.1075.2.42 raeburn 7949: &end_page()
1.1041 www 7950: );
7951: return &modal_adhoc_script($funcname,$width,$height,$content);
7952: }
7953:
7954: sub modal_adhoc_window {
7955: my ($funcname,$width,$height,$content,$linktext)=@_;
7956: return &modal_adhoc_inner($funcname,$width,$height,$content).
7957: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7958: }
7959:
7960: sub modal_adhoc_launch {
7961: my ($funcname,$width,$height,$content)=@_;
7962: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7963: <script type="text/javascript">
7964: // <![CDATA[
7965: $funcname();
7966: // ]]>
7967: </script>
7968: ENDLAUNCH
7969: }
7970:
7971: sub modal_adhoc_close {
7972: return (<<ENDCLOSE);
7973: <script type="text/javascript">
7974: // <![CDATA[
7975: modalWindow.close();
7976: // ]]>
7977: </script>
7978: ENDCLOSE
7979: }
7980:
1.1038 www 7981: sub togglebox_script {
7982: return(<<ENDTOGGLE);
7983: <script type="text/javascript">
7984: // <![CDATA[
7985: function LCtoggleDisplay(id,hidetext,showtext) {
7986: link = document.getElementById(id + "link").childNodes[0];
7987: with (document.getElementById(id).style) {
7988: if (display == "none" ) {
7989: display = "inline";
7990: link.nodeValue = hidetext;
7991: } else {
7992: display = "none";
7993: link.nodeValue = showtext;
7994: }
7995: }
7996: }
7997: // ]]>
7998: </script>
7999: ENDTOGGLE
8000: }
8001:
1.1039 www 8002: sub start_togglebox {
8003: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8004: unless ($heading) { $heading=''; } else { $heading.=' '; }
8005: unless ($showtext) { $showtext=&mt('show'); }
8006: unless ($hidetext) { $hidetext=&mt('hide'); }
8007: unless ($headerbg) { $headerbg='#FFFFFF'; }
8008: return &start_data_table().
8009: &start_data_table_header_row().
8010: '<td bgcolor="'.$headerbg.'">'.$heading.
8011: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8012: $showtext.'\')">'.$showtext.'</a>]</td>'.
8013: &end_data_table_header_row().
8014: '<tr id="'.$id.'" style="display:none""><td>';
8015: }
8016:
8017: sub end_togglebox {
8018: return '</td></tr>'.&end_data_table();
8019: }
8020:
1.1041 www 8021: sub LCprogressbar_script {
1.1045 www 8022: my ($id)=@_;
1.1041 www 8023: return(<<ENDPROGRESS);
8024: <script type="text/javascript">
8025: // <![CDATA[
1.1045 www 8026: \$('#progressbar$id').progressbar({
1.1041 www 8027: value: 0,
8028: change: function(event, ui) {
8029: var newVal = \$(this).progressbar('option', 'value');
8030: \$('.pblabel', this).text(LCprogressTxt);
8031: }
8032: });
8033: // ]]>
8034: </script>
8035: ENDPROGRESS
8036: }
8037:
8038: sub LCprogressbarUpdate_script {
8039: return(<<ENDPROGRESSUPDATE);
8040: <style type="text/css">
8041: .ui-progressbar { position:relative; }
8042: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8043: </style>
8044: <script type="text/javascript">
8045: // <![CDATA[
1.1045 www 8046: var LCprogressTxt='---';
8047:
8048: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8049: LCprogressTxt=progresstext;
1.1045 www 8050: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8051: }
8052: // ]]>
8053: </script>
8054: ENDPROGRESSUPDATE
8055: }
8056:
1.1042 www 8057: my $LClastpercent;
1.1045 www 8058: my $LCidcnt;
8059: my $LCcurrentid;
1.1042 www 8060:
1.1041 www 8061: sub LCprogressbar {
1.1042 www 8062: my ($r)=(@_);
8063: $LClastpercent=0;
1.1045 www 8064: $LCidcnt++;
8065: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8066: my $starting=&mt('Starting');
8067: my $content=(<<ENDPROGBAR);
1.1045 www 8068: <div id="progressbar$LCcurrentid">
1.1041 www 8069: <span class="pblabel">$starting</span>
8070: </div>
8071: ENDPROGBAR
1.1045 www 8072: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8073: }
8074:
8075: sub LCprogressbarUpdate {
1.1042 www 8076: my ($r,$val,$text)=@_;
8077: unless ($val) {
8078: if ($LClastpercent) {
8079: $val=$LClastpercent;
8080: } else {
8081: $val=0;
8082: }
8083: }
1.1041 www 8084: if ($val<0) { $val=0; }
8085: if ($val>100) { $val=0; }
1.1042 www 8086: $LClastpercent=$val;
1.1041 www 8087: unless ($text) { $text=$val.'%'; }
8088: $text=&js_ready($text);
1.1044 www 8089: &r_print($r,<<ENDUPDATE);
1.1041 www 8090: <script type="text/javascript">
8091: // <![CDATA[
1.1045 www 8092: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8093: // ]]>
8094: </script>
8095: ENDUPDATE
1.1035 www 8096: }
8097:
1.1042 www 8098: sub LCprogressbarClose {
8099: my ($r)=@_;
8100: $LClastpercent=0;
1.1044 www 8101: &r_print($r,<<ENDCLOSE);
1.1042 www 8102: <script type="text/javascript">
8103: // <![CDATA[
1.1045 www 8104: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8105: // ]]>
8106: </script>
8107: ENDCLOSE
1.1044 www 8108: }
8109:
8110: sub r_print {
8111: my ($r,$to_print)=@_;
8112: if ($r) {
8113: $r->print($to_print);
8114: $r->rflush();
8115: } else {
8116: print($to_print);
8117: }
1.1042 www 8118: }
8119:
1.320 albertel 8120: sub html_encode {
8121: my ($result) = @_;
8122:
1.322 albertel 8123: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8124:
8125: return $result;
8126: }
1.1044 www 8127:
1.317 albertel 8128: sub js_ready {
8129: my ($result) = @_;
8130:
1.323 albertel 8131: $result =~ s/[\n\r]/ /xmsg;
8132: $result =~ s/\\/\\\\/xmsg;
8133: $result =~ s/'/\\'/xmsg;
1.372 albertel 8134: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8135:
8136: return $result;
8137: }
8138:
1.315 albertel 8139: sub validate_page {
8140: if ( exists($env{'internal.start_page'})
1.316 albertel 8141: && $env{'internal.start_page'} > 1) {
8142: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8143: $env{'internal.start_page'}.' '.
1.316 albertel 8144: $ENV{'request.filename'});
1.315 albertel 8145: }
8146: if ( exists($env{'internal.end_page'})
1.316 albertel 8147: && $env{'internal.end_page'} > 1) {
8148: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8149: $env{'internal.end_page'}.' '.
1.316 albertel 8150: $env{'request.filename'});
1.315 albertel 8151: }
8152: if ( exists($env{'internal.start_page'})
8153: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8154: &Apache::lonnet::logthis('start_page called without end_page '.
8155: $env{'request.filename'});
1.315 albertel 8156: }
8157: if ( ! exists($env{'internal.start_page'})
8158: && exists($env{'internal.end_page'})) {
1.316 albertel 8159: &Apache::lonnet::logthis('end_page called without start_page'.
8160: $env{'request.filename'});
1.315 albertel 8161: }
1.306 albertel 8162: }
1.315 albertel 8163:
1.996 www 8164:
8165: sub start_scrollbox {
1.1075.2.56 raeburn 8166: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8167: unless ($outerwidth) { $outerwidth='520px'; }
8168: unless ($width) { $width='500px'; }
8169: unless ($height) { $height='200px'; }
1.1075 raeburn 8170: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8171: if ($id ne '') {
1.1075.2.42 raeburn 8172: $table_id = ' id="table_'.$id.'"';
8173: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8174: }
1.1075 raeburn 8175: if ($bgcolor ne '') {
8176: $tdcol = "background-color: $bgcolor;";
8177: }
1.1075.2.42 raeburn 8178: my $nicescroll_js;
8179: if ($env{'browser.mobile'}) {
8180: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8181: }
1.1075 raeburn 8182: return <<"END";
1.1075.2.42 raeburn 8183: $nicescroll_js
8184:
8185: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8186: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8187: END
1.996 www 8188: }
8189:
8190: sub end_scrollbox {
1.1036 www 8191: return '</div></td></tr></table>';
1.996 www 8192: }
8193:
1.1075.2.42 raeburn 8194: sub nicescroll_javascript {
8195: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8196: my %options;
8197: if (ref($cursor) eq 'HASH') {
8198: %options = %{$cursor};
8199: }
8200: unless ($options{'railalign'} =~ /^left|right$/) {
8201: $options{'railalign'} = 'left';
8202: }
8203: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8204: my $function = &get_users_function();
8205: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8206: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8207: $options{'cursorcolor'} = '#00F';
8208: }
8209: }
8210: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8211: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8212: $options{'cursoropacity'}='1.0';
8213: }
8214: } else {
8215: $options{'cursoropacity'}='1.0';
8216: }
8217: if ($options{'cursorfixedheight'} eq 'none') {
8218: delete($options{'cursorfixedheight'});
8219: } else {
8220: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8221: }
8222: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8223: delete($options{'railoffset'});
8224: }
8225: my @niceoptions;
8226: while (my($key,$value) = each(%options)) {
8227: if ($value =~ /^\{.+\}$/) {
8228: push(@niceoptions,$key.':'.$value);
8229: } else {
8230: push(@niceoptions,$key.':"'.$value.'"');
8231: }
8232: }
8233: my $nicescroll_js = '
8234: $(document).ready(
8235: function() {
8236: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8237: }
8238: );
8239: ';
8240: if ($framecheck) {
8241: $nicescroll_js .= '
8242: function expand_div(caller) {
8243: if (top === self) {
8244: document.getElementById("'.$id.'").style.width = "auto";
8245: document.getElementById("'.$id.'").style.height = "auto";
8246: } else {
8247: try {
8248: if (parent.frames) {
8249: if (parent.frames.length > 1) {
8250: var framesrc = parent.frames[1].location.href;
8251: var currsrc = framesrc.replace(/\#.*$/,"");
8252: if ((caller == "search") || (currsrc == "'.$location.'")) {
8253: document.getElementById("'.$id.'").style.width = "auto";
8254: document.getElementById("'.$id.'").style.height = "auto";
8255: }
8256: }
8257: }
8258: } catch (e) {
8259: return;
8260: }
8261: }
8262: return;
8263: }
8264: ';
8265: }
8266: if ($needjsready) {
8267: $nicescroll_js = '
8268: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8269: } else {
8270: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8271: }
8272: return $nicescroll_js;
8273: }
8274:
1.318 albertel 8275: sub simple_error_page {
1.1075.2.49 raeburn 8276: my ($r,$title,$msg,$args) = @_;
8277: if (ref($args) eq 'HASH') {
8278: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8279: } else {
8280: $msg = &mt($msg);
8281: }
8282:
1.318 albertel 8283: my $page =
8284: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8285: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8286: &Apache::loncommon::end_page();
8287: if (ref($r)) {
8288: $r->print($page);
1.327 albertel 8289: return;
1.318 albertel 8290: }
8291: return $page;
8292: }
1.347 albertel 8293:
8294: {
1.610 albertel 8295: my @row_count;
1.961 onken 8296:
8297: sub start_data_table_count {
8298: unshift(@row_count, 0);
8299: return;
8300: }
8301:
8302: sub end_data_table_count {
8303: shift(@row_count);
8304: return;
8305: }
8306:
1.347 albertel 8307: sub start_data_table {
1.1018 raeburn 8308: my ($add_class,$id) = @_;
1.422 albertel 8309: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8310: my $table_id;
8311: if (defined($id)) {
8312: $table_id = ' id="'.$id.'"';
8313: }
1.961 onken 8314: &start_data_table_count();
1.1018 raeburn 8315: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8316: }
8317:
8318: sub end_data_table {
1.961 onken 8319: &end_data_table_count();
1.389 albertel 8320: return '</table>'."\n";;
1.347 albertel 8321: }
8322:
8323: sub start_data_table_row {
1.974 wenzelju 8324: my ($add_class, $id) = @_;
1.610 albertel 8325: $row_count[0]++;
8326: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8327: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8328: $id = (' id="'.$id.'"') unless ($id eq '');
8329: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8330: }
1.471 banghart 8331:
8332: sub continue_data_table_row {
1.974 wenzelju 8333: my ($add_class, $id) = @_;
1.610 albertel 8334: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8335: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8336: $id = (' id="'.$id.'"') unless ($id eq '');
8337: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8338: }
1.347 albertel 8339:
8340: sub end_data_table_row {
1.389 albertel 8341: return '</tr>'."\n";;
1.347 albertel 8342: }
1.367 www 8343:
1.421 albertel 8344: sub start_data_table_empty_row {
1.707 bisitz 8345: # $row_count[0]++;
1.421 albertel 8346: return '<tr class="LC_empty_row" >'."\n";;
8347: }
8348:
8349: sub end_data_table_empty_row {
8350: return '</tr>'."\n";;
8351: }
8352:
1.367 www 8353: sub start_data_table_header_row {
1.389 albertel 8354: return '<tr class="LC_header_row">'."\n";;
1.367 www 8355: }
8356:
8357: sub end_data_table_header_row {
1.389 albertel 8358: return '</tr>'."\n";;
1.367 www 8359: }
1.890 droeschl 8360:
8361: sub data_table_caption {
8362: my $caption = shift;
8363: return "<caption class=\"LC_caption\">$caption</caption>";
8364: }
1.347 albertel 8365: }
8366:
1.548 albertel 8367: =pod
8368:
8369: =item * &inhibit_menu_check($arg)
8370:
8371: Checks for a inhibitmenu state and generates output to preserve it
8372:
8373: Inputs: $arg - can be any of
8374: - undef - in which case the return value is a string
8375: to add into arguments list of a uri
8376: - 'input' - in which case the return value is a HTML
8377: <form> <input> field of type hidden to
8378: preserve the value
8379: - a url - in which case the return value is the url with
8380: the neccesary cgi args added to preserve the
8381: inhibitmenu state
8382: - a ref to a url - no return value, but the string is
8383: updated to include the neccessary cgi
8384: args to preserve the inhibitmenu state
8385:
8386: =cut
8387:
8388: sub inhibit_menu_check {
8389: my ($arg) = @_;
8390: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8391: if ($arg eq 'input') {
8392: if ($env{'form.inhibitmenu'}) {
8393: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8394: } else {
8395: return
8396: }
8397: }
8398: if ($env{'form.inhibitmenu'}) {
8399: if (ref($arg)) {
8400: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8401: } elsif ($arg eq '') {
8402: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8403: } else {
8404: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8405: }
8406: }
8407: if (!ref($arg)) {
8408: return $arg;
8409: }
8410: }
8411:
1.251 albertel 8412: ###############################################
1.182 matthew 8413:
8414: =pod
8415:
1.549 albertel 8416: =back
8417:
8418: =head1 User Information Routines
8419:
8420: =over 4
8421:
1.405 albertel 8422: =item * &get_users_function()
1.182 matthew 8423:
8424: Used by &bodytag to determine the current users primary role.
8425: Returns either 'student','coordinator','admin', or 'author'.
8426:
8427: =cut
8428:
8429: ###############################################
8430: sub get_users_function {
1.815 tempelho 8431: my $function = 'norole';
1.818 tempelho 8432: if ($env{'request.role'}=~/^(st)/) {
8433: $function='student';
8434: }
1.907 raeburn 8435: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8436: $function='coordinator';
8437: }
1.258 albertel 8438: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8439: $function='admin';
8440: }
1.826 bisitz 8441: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8442: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8443: $function='author';
8444: }
8445: return $function;
1.54 www 8446: }
1.99 www 8447:
8448: ###############################################
8449:
1.233 raeburn 8450: =pod
8451:
1.821 raeburn 8452: =item * &show_course()
8453:
8454: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8455: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8456:
8457: Inputs:
8458: None
8459:
8460: Outputs:
8461: Scalar: 1 if 'Course' to be used, 0 otherwise.
8462:
8463: =cut
8464:
8465: ###############################################
8466: sub show_course {
8467: my $course = !$env{'user.adv'};
8468: if (!$env{'user.adv'}) {
8469: foreach my $env (keys(%env)) {
8470: next if ($env !~ m/^user\.priv\./);
8471: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8472: $course = 0;
8473: last;
8474: }
8475: }
8476: }
8477: return $course;
8478: }
8479:
8480: ###############################################
8481:
8482: =pod
8483:
1.542 raeburn 8484: =item * &check_user_status()
1.274 raeburn 8485:
8486: Determines current status of supplied role for a
8487: specific user. Roles can be active, previous or future.
8488:
8489: Inputs:
8490: user's domain, user's username, course's domain,
1.375 raeburn 8491: course's number, optional section ID.
1.274 raeburn 8492:
8493: Outputs:
8494: role status: active, previous or future.
8495:
8496: =cut
8497:
8498: sub check_user_status {
1.412 raeburn 8499: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8500: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 8501: my @uroles = keys(%userinfo);
1.274 raeburn 8502: my $srchstr;
8503: my $active_chk = 'none';
1.412 raeburn 8504: my $now = time;
1.274 raeburn 8505: if (@uroles > 0) {
1.908 raeburn 8506: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8507: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8508: } else {
1.412 raeburn 8509: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8510: }
8511: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8512: my $role_end = 0;
8513: my $role_start = 0;
8514: $active_chk = 'active';
1.412 raeburn 8515: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8516: $role_end = $1;
8517: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8518: $role_start = $1;
1.274 raeburn 8519: }
8520: }
8521: if ($role_start > 0) {
1.412 raeburn 8522: if ($now < $role_start) {
1.274 raeburn 8523: $active_chk = 'future';
8524: }
8525: }
8526: if ($role_end > 0) {
1.412 raeburn 8527: if ($now > $role_end) {
1.274 raeburn 8528: $active_chk = 'previous';
8529: }
8530: }
8531: }
8532: }
8533: return $active_chk;
8534: }
8535:
8536: ###############################################
8537:
8538: =pod
8539:
1.405 albertel 8540: =item * &get_sections()
1.233 raeburn 8541:
8542: Determines all the sections for a course including
8543: sections with students and sections containing other roles.
1.419 raeburn 8544: Incoming parameters:
8545:
8546: 1. domain
8547: 2. course number
8548: 3. reference to array containing roles for which sections should
8549: be gathered (optional).
8550: 4. reference to array containing status types for which sections
8551: should be gathered (optional).
8552:
8553: If the third argument is undefined, sections are gathered for any role.
8554: If the fourth argument is undefined, sections are gathered for any status.
8555: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8556:
1.374 raeburn 8557: Returns section hash (keys are section IDs, values are
8558: number of users in each section), subject to the
1.419 raeburn 8559: optional roles filter, optional status filter
1.233 raeburn 8560:
8561: =cut
8562:
8563: ###############################################
8564: sub get_sections {
1.419 raeburn 8565: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8566: if (!defined($cdom) || !defined($cnum)) {
8567: my $cid = $env{'request.course.id'};
8568:
8569: return if (!defined($cid));
8570:
8571: $cdom = $env{'course.'.$cid.'.domain'};
8572: $cnum = $env{'course.'.$cid.'.num'};
8573: }
8574:
8575: my %sectioncount;
1.419 raeburn 8576: my $now = time;
1.240 albertel 8577:
1.1075.2.33 raeburn 8578: my $check_students = 1;
8579: my $only_students = 0;
8580: if (ref($possible_roles) eq 'ARRAY') {
8581: if (grep(/^st$/,@{$possible_roles})) {
8582: if (@{$possible_roles} == 1) {
8583: $only_students = 1;
8584: }
8585: } else {
8586: $check_students = 0;
8587: }
8588: }
8589:
8590: if ($check_students) {
1.276 albertel 8591: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8592: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8593: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8594: my $start_index = &Apache::loncoursedata::CL_START();
8595: my $end_index = &Apache::loncoursedata::CL_END();
8596: my $status;
1.366 albertel 8597: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8598: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8599: $data->[$status_index],
8600: $data->[$start_index],
8601: $data->[$end_index]);
8602: if ($stu_status eq 'Active') {
8603: $status = 'active';
8604: } elsif ($end < $now) {
8605: $status = 'previous';
8606: } elsif ($start > $now) {
8607: $status = 'future';
8608: }
8609: if ($section ne '-1' && $section !~ /^\s*$/) {
8610: if ((!defined($possible_status)) || (($status ne '') &&
8611: (grep/^\Q$status\E$/,@{$possible_status}))) {
8612: $sectioncount{$section}++;
8613: }
1.240 albertel 8614: }
8615: }
8616: }
1.1075.2.33 raeburn 8617: if ($only_students) {
8618: return %sectioncount;
8619: }
1.240 albertel 8620: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8621: foreach my $user (sort(keys(%courseroles))) {
8622: if ($user !~ /^(\w{2})/) { next; }
8623: my ($role) = ($user =~ /^(\w{2})/);
8624: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8625: my ($section,$status);
1.240 albertel 8626: if ($role eq 'cr' &&
8627: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8628: $section=$1;
8629: }
8630: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8631: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8632: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8633: if ($end == -1 && $start == -1) {
8634: next; #deleted role
8635: }
8636: if (!defined($possible_status)) {
8637: $sectioncount{$section}++;
8638: } else {
8639: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8640: $status = 'active';
8641: } elsif ($end < $now) {
8642: $status = 'future';
8643: } elsif ($start > $now) {
8644: $status = 'previous';
8645: }
8646: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8647: $sectioncount{$section}++;
8648: }
8649: }
1.233 raeburn 8650: }
1.366 albertel 8651: return %sectioncount;
1.233 raeburn 8652: }
8653:
1.274 raeburn 8654: ###############################################
1.294 raeburn 8655:
8656: =pod
1.405 albertel 8657:
8658: =item * &get_course_users()
8659:
1.275 raeburn 8660: Retrieves usernames:domains for users in the specified course
8661: with specific role(s), and access status.
8662:
8663: Incoming parameters:
1.277 albertel 8664: 1. course domain
8665: 2. course number
8666: 3. access status: users must have - either active,
1.275 raeburn 8667: previous, future, or all.
1.277 albertel 8668: 4. reference to array of permissible roles
1.288 raeburn 8669: 5. reference to array of section restrictions (optional)
8670: 6. reference to results object (hash of hashes).
8671: 7. reference to optional userdata hash
1.609 raeburn 8672: 8. reference to optional statushash
1.630 raeburn 8673: 9. flag if privileged users (except those set to unhide in
8674: course settings) should be excluded
1.609 raeburn 8675: Keys of top level results hash are roles.
1.275 raeburn 8676: Keys of inner hashes are username:domain, with
8677: values set to access type.
1.288 raeburn 8678: Optional userdata hash returns an array with arguments in the
8679: same order as loncoursedata::get_classlist() for student data.
8680:
1.609 raeburn 8681: Optional statushash returns
8682:
1.288 raeburn 8683: Entries for end, start, section and status are blank because
8684: of the possibility of multiple values for non-student roles.
8685:
1.275 raeburn 8686: =cut
1.405 albertel 8687:
1.275 raeburn 8688: ###############################################
1.405 albertel 8689:
1.275 raeburn 8690: sub get_course_users {
1.630 raeburn 8691: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8692: my %idx = ();
1.419 raeburn 8693: my %seclists;
1.288 raeburn 8694:
8695: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8696: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8697: $idx{end} = &Apache::loncoursedata::CL_END();
8698: $idx{start} = &Apache::loncoursedata::CL_START();
8699: $idx{id} = &Apache::loncoursedata::CL_ID();
8700: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8701: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8702: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8703:
1.290 albertel 8704: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8705: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8706: my $now = time;
1.277 albertel 8707: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8708: my $match = 0;
1.412 raeburn 8709: my $secmatch = 0;
1.419 raeburn 8710: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8711: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8712: if ($section eq '') {
8713: $section = 'none';
8714: }
1.291 albertel 8715: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8716: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8717: $secmatch = 1;
8718: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8719: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8720: $secmatch = 1;
8721: }
8722: } else {
1.419 raeburn 8723: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8724: $secmatch = 1;
8725: }
1.290 albertel 8726: }
1.412 raeburn 8727: if (!$secmatch) {
8728: next;
8729: }
1.419 raeburn 8730: }
1.275 raeburn 8731: if (defined($$types{'active'})) {
1.288 raeburn 8732: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8733: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8734: $match = 1;
1.275 raeburn 8735: }
8736: }
8737: if (defined($$types{'previous'})) {
1.609 raeburn 8738: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8739: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8740: $match = 1;
1.275 raeburn 8741: }
8742: }
8743: if (defined($$types{'future'})) {
1.609 raeburn 8744: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8745: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8746: $match = 1;
1.275 raeburn 8747: }
8748: }
1.609 raeburn 8749: if ($match) {
8750: push(@{$seclists{$student}},$section);
8751: if (ref($userdata) eq 'HASH') {
8752: $$userdata{$student} = $$classlist{$student};
8753: }
8754: if (ref($statushash) eq 'HASH') {
8755: $statushash->{$student}{'st'}{$section} = $status;
8756: }
1.288 raeburn 8757: }
1.275 raeburn 8758: }
8759: }
1.412 raeburn 8760: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8761: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8762: my $now = time;
1.609 raeburn 8763: my %displaystatus = ( previous => 'Expired',
8764: active => 'Active',
8765: future => 'Future',
8766: );
1.1075.2.36 raeburn 8767: my (%nothide,@possdoms);
1.630 raeburn 8768: if ($hidepriv) {
8769: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8770: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8771: if ($user !~ /:/) {
8772: $nothide{join(':',split(/[\@]/,$user))}=1;
8773: } else {
8774: $nothide{$user} = 1;
8775: }
8776: }
1.1075.2.36 raeburn 8777: my @possdoms = ($cdom);
8778: if ($coursehash{'checkforpriv'}) {
8779: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8780: }
1.630 raeburn 8781: }
1.439 raeburn 8782: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8783: my $match = 0;
1.412 raeburn 8784: my $secmatch = 0;
1.439 raeburn 8785: my $status;
1.412 raeburn 8786: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8787: $user =~ s/:$//;
1.439 raeburn 8788: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8789: if ($end == -1 || $start == -1) {
8790: next;
8791: }
8792: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8793: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8794: my ($uname,$udom) = split(/:/,$user);
8795: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8796: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8797: $secmatch = 1;
8798: } elsif ($usec eq '') {
1.420 albertel 8799: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8800: $secmatch = 1;
8801: }
8802: } else {
8803: if (grep(/^\Q$usec\E$/,@{$sections})) {
8804: $secmatch = 1;
8805: }
8806: }
8807: if (!$secmatch) {
8808: next;
8809: }
1.288 raeburn 8810: }
1.419 raeburn 8811: if ($usec eq '') {
8812: $usec = 'none';
8813: }
1.275 raeburn 8814: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8815: if ($hidepriv) {
1.1075.2.36 raeburn 8816: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8817: (!$nothide{$uname.':'.$udom})) {
8818: next;
8819: }
8820: }
1.503 raeburn 8821: if ($end > 0 && $end < $now) {
1.439 raeburn 8822: $status = 'previous';
8823: } elsif ($start > $now) {
8824: $status = 'future';
8825: } else {
8826: $status = 'active';
8827: }
1.277 albertel 8828: foreach my $type (keys(%{$types})) {
1.275 raeburn 8829: if ($status eq $type) {
1.420 albertel 8830: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8831: push(@{$$users{$role}{$user}},$type);
8832: }
1.288 raeburn 8833: $match = 1;
8834: }
8835: }
1.419 raeburn 8836: if (($match) && (ref($userdata) eq 'HASH')) {
8837: if (!exists($$userdata{$uname.':'.$udom})) {
8838: &get_user_info($udom,$uname,\%idx,$userdata);
8839: }
1.420 albertel 8840: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8841: push(@{$seclists{$uname.':'.$udom}},$usec);
8842: }
1.609 raeburn 8843: if (ref($statushash) eq 'HASH') {
8844: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8845: }
1.275 raeburn 8846: }
8847: }
8848: }
8849: }
1.290 albertel 8850: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8851: if ((defined($cdom)) && (defined($cnum))) {
8852: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8853: if ( defined($csettings{'internal.courseowner'}) ) {
8854: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8855: next if ($owner eq '');
8856: my ($ownername,$ownerdom);
8857: if ($owner =~ /^([^:]+):([^:]+)$/) {
8858: $ownername = $1;
8859: $ownerdom = $2;
8860: } else {
8861: $ownername = $owner;
8862: $ownerdom = $cdom;
8863: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8864: }
8865: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8866: if (defined($userdata) &&
1.609 raeburn 8867: !exists($$userdata{$owner})) {
8868: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8869: if (!grep(/^none$/,@{$seclists{$owner}})) {
8870: push(@{$seclists{$owner}},'none');
8871: }
8872: if (ref($statushash) eq 'HASH') {
8873: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8874: }
1.290 albertel 8875: }
1.279 raeburn 8876: }
8877: }
8878: }
1.419 raeburn 8879: foreach my $user (keys(%seclists)) {
8880: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8881: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8882: }
1.275 raeburn 8883: }
8884: return;
8885: }
8886:
1.288 raeburn 8887: sub get_user_info {
8888: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8889: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8890: &plainname($uname,$udom,'lastname');
1.291 albertel 8891: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8892: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8893: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8894: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8895: return;
8896: }
1.275 raeburn 8897:
1.472 raeburn 8898: ###############################################
8899:
8900: =pod
8901:
8902: =item * &get_user_quota()
8903:
1.1075.2.41 raeburn 8904: Retrieves quota assigned for storage of user files.
8905: Default is to report quota for portfolio files.
1.472 raeburn 8906:
8907: Incoming parameters:
8908: 1. user's username
8909: 2. user's domain
1.1075.2.41 raeburn 8910: 3. quota name - portfolio, author, or course
8911: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 8912: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 8913: course
1.472 raeburn 8914:
8915: Returns:
1.1075.2.58 raeburn 8916: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 8917: 2. (Optional) Type of setting: custom or default
8918: (individually assigned or default for user's
8919: institutional status).
8920: 3. (Optional) - User's institutional status (e.g., faculty, staff
8921: or student - types as defined in localenroll::inst_usertypes
8922: for user's domain, which determines default quota for user.
8923: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8924:
8925: If a value has been stored in the user's environment,
1.536 raeburn 8926: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 8927: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8928:
8929: =cut
8930:
8931: ###############################################
8932:
8933:
8934: sub get_user_quota {
1.1075.2.42 raeburn 8935: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8936: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8937: if (!defined($udom)) {
8938: $udom = $env{'user.domain'};
8939: }
8940: if (!defined($uname)) {
8941: $uname = $env{'user.name'};
8942: }
8943: if (($udom eq '' || $uname eq '') ||
8944: ($udom eq 'public') && ($uname eq 'public')) {
8945: $quota = 0;
1.536 raeburn 8946: $quotatype = 'default';
8947: $defquota = 0;
1.472 raeburn 8948: } else {
1.536 raeburn 8949: my $inststatus;
1.1075.2.41 raeburn 8950: if ($quotaname eq 'course') {
8951: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8952: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8953: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8954: } else {
8955: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8956: $quota = $cenv{'internal.uploadquota'};
8957: }
1.536 raeburn 8958: } else {
1.1075.2.41 raeburn 8959: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8960: if ($quotaname eq 'author') {
8961: $quota = $env{'environment.authorquota'};
8962: } else {
8963: $quota = $env{'environment.portfolioquota'};
8964: }
8965: $inststatus = $env{'environment.inststatus'};
8966: } else {
8967: my %userenv =
8968: &Apache::lonnet::get('environment',['portfolioquota',
8969: 'authorquota','inststatus'],$udom,$uname);
8970: my ($tmp) = keys(%userenv);
8971: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8972: if ($quotaname eq 'author') {
8973: $quota = $userenv{'authorquota'};
8974: } else {
8975: $quota = $userenv{'portfolioquota'};
8976: }
8977: $inststatus = $userenv{'inststatus'};
8978: } else {
8979: undef(%userenv);
8980: }
8981: }
8982: }
8983: if ($quota eq '' || wantarray) {
8984: if ($quotaname eq 'course') {
8985: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 8986: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
8987: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 8988: $defquota = $domdefs{$crstype.'quota'};
8989: }
8990: if ($defquota eq '') {
8991: $defquota = 500;
8992: }
1.1075.2.41 raeburn 8993: } else {
8994: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8995: }
8996: if ($quota eq '') {
8997: $quota = $defquota;
8998: $quotatype = 'default';
8999: } else {
9000: $quotatype = 'custom';
9001: }
1.472 raeburn 9002: }
9003: }
1.536 raeburn 9004: if (wantarray) {
9005: return ($quota,$quotatype,$settingstatus,$defquota);
9006: } else {
9007: return $quota;
9008: }
1.472 raeburn 9009: }
9010:
9011: ###############################################
9012:
9013: =pod
9014:
9015: =item * &default_quota()
9016:
1.536 raeburn 9017: Retrieves default quota assigned for storage of user portfolio files,
9018: given an (optional) user's institutional status.
1.472 raeburn 9019:
9020: Incoming parameters:
1.1075.2.42 raeburn 9021:
1.472 raeburn 9022: 1. domain
1.536 raeburn 9023: 2. (Optional) institutional status(es). This is a : separated list of
9024: status types (e.g., faculty, staff, student etc.)
9025: which apply to the user for whom the default is being retrieved.
9026: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9027: default quota will be returned.
9028: 3. quota name - portfolio, author, or course
9029: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9030:
9031: Returns:
1.1075.2.42 raeburn 9032:
1.1075.2.58 raeburn 9033: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9034: 2. (Optional) institutional type which determined the value of the
9035: default quota.
1.472 raeburn 9036:
9037: If a value has been stored in the domain's configuration db,
9038: it will return that, otherwise it returns 20 (for backwards
9039: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9040: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9041:
1.536 raeburn 9042: If the user's status includes multiple types (e.g., staff and student),
9043: the largest default quota which applies to the user determines the
9044: default quota returned.
9045:
1.472 raeburn 9046: =cut
9047:
9048: ###############################################
9049:
9050:
9051: sub default_quota {
1.1075.2.41 raeburn 9052: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9053: my ($defquota,$settingstatus);
9054: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9055: ['quotas'],$udom);
1.1075.2.41 raeburn 9056: my $key = 'defaultquota';
9057: if ($quotaname eq 'author') {
9058: $key = 'authorquota';
9059: }
1.622 raeburn 9060: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9061: if ($inststatus ne '') {
1.765 raeburn 9062: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9063: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9064: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9065: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9066: if ($defquota eq '') {
1.1075.2.41 raeburn 9067: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9068: $settingstatus = $item;
1.1075.2.41 raeburn 9069: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9070: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9071: $settingstatus = $item;
9072: }
9073: }
1.1075.2.41 raeburn 9074: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9075: if ($quotahash{'quotas'}{$item} ne '') {
9076: if ($defquota eq '') {
9077: $defquota = $quotahash{'quotas'}{$item};
9078: $settingstatus = $item;
9079: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9080: $defquota = $quotahash{'quotas'}{$item};
9081: $settingstatus = $item;
9082: }
1.536 raeburn 9083: }
9084: }
9085: }
9086: }
9087: if ($defquota eq '') {
1.1075.2.41 raeburn 9088: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9089: $defquota = $quotahash{'quotas'}{$key}{'default'};
9090: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9091: $defquota = $quotahash{'quotas'}{'default'};
9092: }
1.536 raeburn 9093: $settingstatus = 'default';
1.1075.2.42 raeburn 9094: if ($defquota eq '') {
9095: if ($quotaname eq 'author') {
9096: $defquota = 500;
9097: }
9098: }
1.536 raeburn 9099: }
9100: } else {
9101: $settingstatus = 'default';
1.1075.2.41 raeburn 9102: if ($quotaname eq 'author') {
9103: $defquota = 500;
9104: } else {
9105: $defquota = 20;
9106: }
1.536 raeburn 9107: }
9108: if (wantarray) {
9109: return ($defquota,$settingstatus);
1.472 raeburn 9110: } else {
1.536 raeburn 9111: return $defquota;
1.472 raeburn 9112: }
9113: }
9114:
1.1075.2.41 raeburn 9115: ###############################################
9116:
9117: =pod
9118:
1.1075.2.42 raeburn 9119: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9120:
9121: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9122: of existing file within authoring space will cause quota for the authoring
9123: space to be exceeded.
9124:
9125: Same, if upload of a file directly to a course/community via Course Editor
9126: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9127:
1.1075.2.61 raeburn 9128: Inputs: 7
1.1075.2.42 raeburn 9129: 1. username or coursenum
1.1075.2.41 raeburn 9130: 2. domain
1.1075.2.42 raeburn 9131: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9132: 4. filename of file for which action is being requested
9133: 5. filesize (kB) of file
9134: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9135: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9136:
9137: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9138: otherwise return null.
9139:
1.1075.2.42 raeburn 9140: =back
9141:
1.1075.2.41 raeburn 9142: =cut
9143:
1.1075.2.42 raeburn 9144: sub excess_filesize_warning {
1.1075.2.59 raeburn 9145: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9146: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9147: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9148: if ($context eq 'author') {
9149: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9150: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9151: } else {
9152: foreach my $subdir ('docs','supplemental') {
9153: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9154: }
9155: }
1.1075.2.41 raeburn 9156: $disk_quota = int($disk_quota * 1000);
9157: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9158: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9159: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9160: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9161: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9162: $disk_quota,$current_disk_usage).
9163: '</p>';
9164: }
9165: return;
9166: }
9167:
9168: ###############################################
9169:
9170:
1.384 raeburn 9171: sub get_secgrprole_info {
9172: my ($cdom,$cnum,$needroles,$type) = @_;
9173: my %sections_count = &get_sections($cdom,$cnum);
9174: my @sections = (sort {$a <=> $b} keys(%sections_count));
9175: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9176: my @groups = sort(keys(%curr_groups));
9177: my $allroles = [];
9178: my $rolehash;
9179: my $accesshash = {
9180: active => 'Currently has access',
9181: future => 'Will have future access',
9182: previous => 'Previously had access',
9183: };
9184: if ($needroles) {
9185: $rolehash = {'all' => 'all'};
1.385 albertel 9186: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9187: if (&Apache::lonnet::error(%user_roles)) {
9188: undef(%user_roles);
9189: }
9190: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9191: my ($role)=split(/\:/,$item,2);
9192: if ($role eq 'cr') { next; }
9193: if ($role =~ /^cr/) {
9194: $$rolehash{$role} = (split('/',$role))[3];
9195: } else {
9196: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9197: }
9198: }
9199: foreach my $key (sort(keys(%{$rolehash}))) {
9200: push(@{$allroles},$key);
9201: }
9202: push (@{$allroles},'st');
9203: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9204: }
9205: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9206: }
9207:
1.555 raeburn 9208: sub user_picker {
1.994 raeburn 9209: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 9210: my $currdom = $dom;
9211: my %curr_selected = (
9212: srchin => 'dom',
1.580 raeburn 9213: srchby => 'lastname',
1.555 raeburn 9214: );
9215: my $srchterm;
1.625 raeburn 9216: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9217: if ($srch->{'srchby'} ne '') {
9218: $curr_selected{'srchby'} = $srch->{'srchby'};
9219: }
9220: if ($srch->{'srchin'} ne '') {
9221: $curr_selected{'srchin'} = $srch->{'srchin'};
9222: }
9223: if ($srch->{'srchtype'} ne '') {
9224: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9225: }
9226: if ($srch->{'srchdomain'} ne '') {
9227: $currdom = $srch->{'srchdomain'};
9228: }
9229: $srchterm = $srch->{'srchterm'};
9230: }
1.1075.2.98 raeburn 9231: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9232: 'usr' => 'Search criteria',
1.563 raeburn 9233: 'doma' => 'Domain/institution to search',
1.558 albertel 9234: 'uname' => 'username',
9235: 'lastname' => 'last name',
1.555 raeburn 9236: 'lastfirst' => 'last name, first name',
1.558 albertel 9237: 'crs' => 'in this course',
1.576 raeburn 9238: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9239: 'alc' => 'all LON-CAPA',
1.573 raeburn 9240: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9241: 'exact' => 'is',
9242: 'contains' => 'contains',
1.569 raeburn 9243: 'begins' => 'begins with',
1.1075.2.98 raeburn 9244: );
9245: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9246: 'youm' => "You must include some text to search for.",
9247: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9248: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9249: 'yomc' => "You must choose a domain when using an institutional directory search.",
9250: 'ymcd' => "You must choose a domain when using a domain search.",
9251: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9252: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9253: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9254: );
1.1075.2.98 raeburn 9255: &html_escape(\%html_lt);
9256: &js_escape(\%js_lt);
1.563 raeburn 9257: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9258: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9259:
9260: my @srchins = ('crs','dom','alc','instd');
9261:
9262: foreach my $option (@srchins) {
9263: # FIXME 'alc' option unavailable until
9264: # loncreateuser::print_user_query_page()
9265: # has been completed.
9266: next if ($option eq 'alc');
1.880 raeburn 9267: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9268: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9269: if ($curr_selected{'srchin'} eq $option) {
9270: $srchinsel .= '
1.1075.2.98 raeburn 9271: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 9272: } else {
9273: $srchinsel .= '
1.1075.2.98 raeburn 9274: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 9275: }
1.555 raeburn 9276: }
1.563 raeburn 9277: $srchinsel .= "\n </select>\n";
1.555 raeburn 9278:
9279: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9280: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9281: if ($curr_selected{'srchby'} eq $option) {
9282: $srchbysel .= '
1.1075.2.98 raeburn 9283: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9284: } else {
9285: $srchbysel .= '
1.1075.2.98 raeburn 9286: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9287: }
9288: }
9289: $srchbysel .= "\n </select>\n";
9290:
9291: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9292: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9293: if ($curr_selected{'srchtype'} eq $option) {
9294: $srchtypesel .= '
1.1075.2.98 raeburn 9295: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9296: } else {
9297: $srchtypesel .= '
1.1075.2.98 raeburn 9298: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9299: }
9300: }
9301: $srchtypesel .= "\n </select>\n";
9302:
1.558 albertel 9303: my ($newuserscript,$new_user_create);
1.994 raeburn 9304: my $context_dom = $env{'request.role.domain'};
9305: if ($context eq 'requestcrs') {
9306: if ($env{'form.coursedom'} ne '') {
9307: $context_dom = $env{'form.coursedom'};
9308: }
9309: }
1.556 raeburn 9310: if ($forcenewuser) {
1.576 raeburn 9311: if (ref($srch) eq 'HASH') {
1.994 raeburn 9312: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9313: if ($cancreate) {
9314: $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>';
9315: } else {
1.799 bisitz 9316: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9317: my %usertypetext = (
9318: official => 'institutional',
9319: unofficial => 'non-institutional',
9320: );
1.799 bisitz 9321: $new_user_create = '<p class="LC_warning">'
9322: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9323: .' '
9324: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9325: ,'<a href="'.$helplink.'">','</a>')
9326: .'</p><br />';
1.627 raeburn 9327: }
1.576 raeburn 9328: }
9329: }
9330:
1.556 raeburn 9331: $newuserscript = <<"ENDSCRIPT";
9332:
1.570 raeburn 9333: function setSearch(createnew,callingForm) {
1.556 raeburn 9334: if (createnew == 1) {
1.570 raeburn 9335: for (var i=0; i<callingForm.srchby.length; i++) {
9336: if (callingForm.srchby.options[i].value == 'uname') {
9337: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9338: }
9339: }
1.570 raeburn 9340: for (var i=0; i<callingForm.srchin.length; i++) {
9341: if ( callingForm.srchin.options[i].value == 'dom') {
9342: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9343: }
9344: }
1.570 raeburn 9345: for (var i=0; i<callingForm.srchtype.length; i++) {
9346: if (callingForm.srchtype.options[i].value == 'exact') {
9347: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9348: }
9349: }
1.570 raeburn 9350: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9351: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9352: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9353: }
9354: }
9355: }
9356: }
9357: ENDSCRIPT
1.558 albertel 9358:
1.556 raeburn 9359: }
9360:
1.555 raeburn 9361: my $output = <<"END_BLOCK";
1.556 raeburn 9362: <script type="text/javascript">
1.824 bisitz 9363: // <![CDATA[
1.570 raeburn 9364: function validateEntry(callingForm) {
1.558 albertel 9365:
1.556 raeburn 9366: var checkok = 1;
1.558 albertel 9367: var srchin;
1.570 raeburn 9368: for (var i=0; i<callingForm.srchin.length; i++) {
9369: if ( callingForm.srchin[i].checked ) {
9370: srchin = callingForm.srchin[i].value;
1.558 albertel 9371: }
9372: }
9373:
1.570 raeburn 9374: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9375: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9376: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9377: var srchterm = callingForm.srchterm.value;
9378: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9379: var msg = "";
9380:
9381: if (srchterm == "") {
9382: checkok = 0;
1.1075.2.98 raeburn 9383: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 9384: }
9385:
1.569 raeburn 9386: if (srchtype== 'begins') {
9387: if (srchterm.length < 2) {
9388: checkok = 0;
1.1075.2.98 raeburn 9389: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 9390: }
9391: }
9392:
1.556 raeburn 9393: if (srchtype== 'contains') {
9394: if (srchterm.length < 3) {
9395: checkok = 0;
1.1075.2.98 raeburn 9396: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 9397: }
9398: }
9399: if (srchin == 'instd') {
9400: if (srchdomain == '') {
9401: checkok = 0;
1.1075.2.98 raeburn 9402: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 9403: }
9404: }
9405: if (srchin == 'dom') {
9406: if (srchdomain == '') {
9407: checkok = 0;
1.1075.2.98 raeburn 9408: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 9409: }
9410: }
9411: if (srchby == 'lastfirst') {
9412: if (srchterm.indexOf(",") == -1) {
9413: checkok = 0;
1.1075.2.98 raeburn 9414: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 9415: }
9416: if (srchterm.indexOf(",") == srchterm.length -1) {
9417: checkok = 0;
1.1075.2.98 raeburn 9418: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 9419: }
9420: }
9421: if (checkok == 0) {
1.1075.2.98 raeburn 9422: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 9423: return;
9424: }
9425: if (checkok == 1) {
1.570 raeburn 9426: callingForm.submit();
1.556 raeburn 9427: }
9428: }
9429:
9430: $newuserscript
9431:
1.824 bisitz 9432: // ]]>
1.556 raeburn 9433: </script>
1.558 albertel 9434:
9435: $new_user_create
9436:
1.555 raeburn 9437: END_BLOCK
1.558 albertel 9438:
1.876 raeburn 9439: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 9440: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 9441: $domform.
9442: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 9443: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 9444: $srchbysel.
9445: $srchtypesel.
9446: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9447: $srchinsel.
9448: &Apache::lonhtmlcommon::row_closure(1).
9449: &Apache::lonhtmlcommon::end_pick_box().
9450: '<br />';
1.555 raeburn 9451: return $output;
9452: }
9453:
1.612 raeburn 9454: sub user_rule_check {
1.615 raeburn 9455: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 9456: my ($response,%inst_response);
1.612 raeburn 9457: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 9458: if (keys(%{$usershash}) > 1) {
9459: my (%by_username,%by_id,%userdoms);
9460: my $checkid;
1.612 raeburn 9461: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 9462: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
9463: $checkid = 1;
9464: }
9465: }
9466: foreach my $user (keys(%{$usershash})) {
9467: my ($uname,$udom) = split(/:/,$user);
9468: if ($checkid) {
9469: if (ref($usershash->{$user}) eq 'HASH') {
9470: if ($usershash->{$user}->{'id'} ne '') {
9471: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
9472: $userdoms{$udom} = 1;
9473: if (ref($inst_results) eq 'HASH') {
9474: $inst_results->{$uname.':'.$udom} = {};
9475: }
9476: }
9477: }
9478: } else {
9479: $by_username{$udom}{$uname} = 1;
9480: $userdoms{$udom} = 1;
9481: if (ref($inst_results) eq 'HASH') {
9482: $inst_results->{$uname.':'.$udom} = {};
9483: }
9484: }
9485: }
9486: foreach my $udom (keys(%userdoms)) {
9487: if (!$got_rules->{$udom}) {
9488: my %domconfig = &Apache::lonnet::get_dom('configuration',
9489: ['usercreation'],$udom);
9490: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9491: foreach my $item ('username','id') {
9492: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9493: $$curr_rules{$udom}{$item} =
9494: $domconfig{'usercreation'}{$item.'_rule'};
9495: }
9496: }
9497: }
9498: $got_rules->{$udom} = 1;
9499: }
9500: }
9501: if ($checkid) {
9502: foreach my $udom (keys(%by_id)) {
9503: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
9504: if ($outcome eq 'ok') {
9505: foreach my $id (keys(%{$by_id{$udom}})) {
9506: my $uname = $by_id{$udom}{$id};
9507: $inst_response{$uname.':'.$udom} = $outcome;
9508: }
9509: if (ref($results) eq 'HASH') {
9510: foreach my $uname (keys(%{$results})) {
9511: if (exists($inst_response{$uname.':'.$udom})) {
9512: $inst_response{$uname.':'.$udom} = $outcome;
9513: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9514: }
9515: }
9516: }
9517: }
1.612 raeburn 9518: }
1.615 raeburn 9519: } else {
1.1075.2.99 raeburn 9520: foreach my $udom (keys(%by_username)) {
9521: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
9522: if ($outcome eq 'ok') {
9523: foreach my $uname (keys(%{$by_username{$udom}})) {
9524: $inst_response{$uname.':'.$udom} = $outcome;
9525: }
9526: if (ref($results) eq 'HASH') {
9527: foreach my $uname (keys(%{$results})) {
9528: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9529: }
9530: }
9531: }
9532: }
1.612 raeburn 9533: }
1.1075.2.99 raeburn 9534: } elsif (keys(%{$usershash}) == 1) {
9535: my $user = (keys(%{$usershash}))[0];
9536: my ($uname,$udom) = split(/:/,$user);
9537: if (($udom ne '') && ($uname ne '')) {
9538: if (ref($usershash->{$user}) eq 'HASH') {
9539: if (ref($checks) eq 'HASH') {
9540: if (defined($checks->{'username'})) {
9541: ($inst_response{$user},%{$inst_results->{$user}}) =
9542: &Apache::lonnet::get_instuser($udom,$uname);
9543: } elsif (defined($checks->{'id'})) {
9544: if ($usershash->{$user}->{'id'} ne '') {
9545: ($inst_response{$user},%{$inst_results->{$user}}) =
9546: &Apache::lonnet::get_instuser($udom,undef,
9547: $usershash->{$user}->{'id'});
9548: } else {
9549: ($inst_response{$user},%{$inst_results->{$user}}) =
9550: &Apache::lonnet::get_instuser($udom,$uname);
9551: }
9552: }
9553: } else {
9554: ($inst_response{$user},%{$inst_results->{$user}}) =
9555: &Apache::lonnet::get_instuser($udom,$uname);
9556: return;
9557: }
9558: if (!$got_rules->{$udom}) {
9559: my %domconfig = &Apache::lonnet::get_dom('configuration',
9560: ['usercreation'],$udom);
9561: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9562: foreach my $item ('username','id') {
9563: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9564: $$curr_rules{$udom}{$item} =
9565: $domconfig{'usercreation'}{$item.'_rule'};
9566: }
9567: }
1.585 raeburn 9568: }
1.1075.2.99 raeburn 9569: $got_rules->{$udom} = 1;
1.585 raeburn 9570: }
9571: }
1.1075.2.99 raeburn 9572: } else {
9573: return;
9574: }
9575: } else {
9576: return;
9577: }
9578: foreach my $user (keys(%{$usershash})) {
9579: my ($uname,$udom) = split(/:/,$user);
9580: next if (($udom eq '') || ($uname eq ''));
9581: my $id;
9582: if (ref($inst_results) eq 'HASH') {
9583: if (ref($inst_results->{$user}) eq 'HASH') {
9584: $id = $inst_results->{$user}->{'id'};
9585: }
9586: }
9587: if ($id eq '') {
9588: if (ref($usershash->{$user})) {
9589: $id = $usershash->{$user}->{'id'};
9590: }
1.585 raeburn 9591: }
1.612 raeburn 9592: foreach my $item (keys(%{$checks})) {
9593: if (ref($$curr_rules{$udom}) eq 'HASH') {
9594: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9595: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 9596: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
9597: $$curr_rules{$udom}{$item});
1.612 raeburn 9598: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9599: if ($rule_check{$rule}) {
9600: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 9601: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 9602: if (ref($inst_results) eq 'HASH') {
9603: if (ref($inst_results->{$user}) eq 'HASH') {
9604: if (keys(%{$inst_results->{$user}}) == 0) {
9605: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 9606: } elsif ($item eq 'id') {
9607: if ($inst_results->{$user}->{'id'} eq '') {
9608: $$alerts{$item}{$udom}{$uname} = 1;
9609: }
1.615 raeburn 9610: }
1.612 raeburn 9611: }
9612: }
1.615 raeburn 9613: }
9614: last;
1.585 raeburn 9615: }
9616: }
9617: }
9618: }
9619: }
9620: }
9621: }
9622: }
1.612 raeburn 9623: return;
9624: }
9625:
9626: sub user_rule_formats {
9627: my ($domain,$domdesc,$curr_rules,$check) = @_;
9628: my %text = (
9629: 'username' => 'Usernames',
9630: 'id' => 'IDs',
9631: );
9632: my $output;
9633: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9634: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9635: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 9636: $output = '<br />'.
9637: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9638: '<span class="LC_cusr_emph">','</span>',$domdesc).
9639: ' <ul>';
1.612 raeburn 9640: foreach my $rule (@{$ruleorder}) {
9641: if (ref($curr_rules) eq 'ARRAY') {
9642: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9643: if (ref($rules->{$rule}) eq 'HASH') {
9644: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9645: $rules->{$rule}{'desc'}.'</li>';
9646: }
9647: }
9648: }
9649: }
9650: $output .= '</ul>';
9651: }
9652: }
9653: return $output;
9654: }
9655:
9656: sub instrule_disallow_msg {
1.615 raeburn 9657: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9658: my $response;
9659: my %text = (
9660: item => 'username',
9661: items => 'usernames',
9662: match => 'matches',
9663: do => 'does',
9664: action => 'a username',
9665: one => 'one',
9666: );
9667: if ($count > 1) {
9668: $text{'item'} = 'usernames';
9669: $text{'match'} ='match';
9670: $text{'do'} = 'do';
9671: $text{'action'} = 'usernames',
9672: $text{'one'} = 'ones';
9673: }
9674: if ($checkitem eq 'id') {
9675: $text{'items'} = 'IDs';
9676: $text{'item'} = 'ID';
9677: $text{'action'} = 'an ID';
1.615 raeburn 9678: if ($count > 1) {
9679: $text{'item'} = 'IDs';
9680: $text{'action'} = 'IDs';
9681: }
1.612 raeburn 9682: }
1.674 bisitz 9683: $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 9684: if ($mode eq 'upload') {
9685: if ($checkitem eq 'username') {
9686: $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'}.");
9687: } elsif ($checkitem eq 'id') {
1.674 bisitz 9688: $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 9689: }
1.669 raeburn 9690: } elsif ($mode eq 'selfcreate') {
9691: if ($checkitem eq 'id') {
9692: $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.");
9693: }
1.615 raeburn 9694: } else {
9695: if ($checkitem eq 'username') {
9696: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9697: } elsif ($checkitem eq 'id') {
9698: $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.");
9699: }
1.612 raeburn 9700: }
9701: return $response;
1.585 raeburn 9702: }
9703:
1.624 raeburn 9704: sub personal_data_fieldtitles {
9705: my %fieldtitles = &Apache::lonlocal::texthash (
9706: id => 'Student/Employee ID',
9707: permanentemail => 'E-mail address',
9708: lastname => 'Last Name',
9709: firstname => 'First Name',
9710: middlename => 'Middle Name',
9711: generation => 'Generation',
9712: gen => 'Generation',
1.765 raeburn 9713: inststatus => 'Affiliation',
1.624 raeburn 9714: );
9715: return %fieldtitles;
9716: }
9717:
1.642 raeburn 9718: sub sorted_inst_types {
9719: my ($dom) = @_;
1.1075.2.70 raeburn 9720: my ($usertypes,$order);
9721: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
9722: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
9723: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
9724: $order = $domdefaults{'inststatus'}{'inststatusorder'};
9725: } else {
9726: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9727: }
1.642 raeburn 9728: my $othertitle = &mt('All users');
9729: if ($env{'request.course.id'}) {
1.668 raeburn 9730: $othertitle = &mt('Any users');
1.642 raeburn 9731: }
9732: my @types;
9733: if (ref($order) eq 'ARRAY') {
9734: @types = @{$order};
9735: }
9736: if (@types == 0) {
9737: if (ref($usertypes) eq 'HASH') {
9738: @types = sort(keys(%{$usertypes}));
9739: }
9740: }
9741: if (keys(%{$usertypes}) > 0) {
9742: $othertitle = &mt('Other users');
9743: }
9744: return ($othertitle,$usertypes,\@types);
9745: }
9746:
1.645 raeburn 9747: sub get_institutional_codes {
9748: my ($settings,$allcourses,$LC_code) = @_;
9749: # Get complete list of course sections to update
9750: my @currsections = ();
9751: my @currxlists = ();
9752: my $coursecode = $$settings{'internal.coursecode'};
9753:
9754: if ($$settings{'internal.sectionnums'} ne '') {
9755: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9756: }
9757:
9758: if ($$settings{'internal.crosslistings'} ne '') {
9759: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9760: }
9761:
9762: if (@currxlists > 0) {
9763: foreach (@currxlists) {
9764: if (m/^([^:]+):(\w*)$/) {
9765: unless (grep/^$1$/,@{$allcourses}) {
9766: push @{$allcourses},$1;
9767: $$LC_code{$1} = $2;
9768: }
9769: }
9770: }
9771: }
9772:
9773: if (@currsections > 0) {
9774: foreach (@currsections) {
9775: if (m/^(\w+):(\w*)$/) {
9776: my $sec = $coursecode.$1;
9777: my $lc_sec = $2;
9778: unless (grep/^$sec$/,@{$allcourses}) {
9779: push @{$allcourses},$sec;
9780: $$LC_code{$sec} = $lc_sec;
9781: }
9782: }
9783: }
9784: }
9785: return;
9786: }
9787:
1.971 raeburn 9788: sub get_standard_codeitems {
9789: return ('Year','Semester','Department','Number','Section');
9790: }
9791:
1.112 bowersj2 9792: =pod
9793:
1.780 raeburn 9794: =head1 Slot Helpers
9795:
9796: =over 4
9797:
9798: =item * sorted_slots()
9799:
1.1040 raeburn 9800: Sorts an array of slot names in order of an optional sort key,
9801: default sort is by slot start time (earliest first).
1.780 raeburn 9802:
9803: Inputs:
9804:
9805: =over 4
9806:
9807: slotsarr - Reference to array of unsorted slot names.
9808:
9809: slots - Reference to hash of hash, where outer hash keys are slot names.
9810:
1.1040 raeburn 9811: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9812:
1.549 albertel 9813: =back
9814:
1.780 raeburn 9815: Returns:
9816:
9817: =over 4
9818:
1.1040 raeburn 9819: sorted - An array of slot names sorted by a specified sort key
9820: (default sort key is start time of the slot).
1.780 raeburn 9821:
9822: =back
9823:
9824: =cut
9825:
9826:
9827: sub sorted_slots {
1.1040 raeburn 9828: my ($slotsarr,$slots,$sortkey) = @_;
9829: if ($sortkey eq '') {
9830: $sortkey = 'starttime';
9831: }
1.780 raeburn 9832: my @sorted;
9833: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9834: @sorted =
9835: sort {
9836: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9837: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9838: }
9839: if (ref($slots->{$a})) { return -1;}
9840: if (ref($slots->{$b})) { return 1;}
9841: return 0;
9842: } @{$slotsarr};
9843: }
9844: return @sorted;
9845: }
9846:
1.1040 raeburn 9847: =pod
9848:
9849: =item * get_future_slots()
9850:
9851: Inputs:
9852:
9853: =over 4
9854:
9855: cnum - course number
9856:
9857: cdom - course domain
9858:
9859: now - current UNIX time
9860:
9861: symb - optional symb
9862:
9863: =back
9864:
9865: Returns:
9866:
9867: =over 4
9868:
9869: sorted_reservable - ref to array of student_schedulable slots currently
9870: reservable, ordered by end date of reservation period.
9871:
9872: reservable_now - ref to hash of student_schedulable slots currently
9873: reservable.
9874:
9875: Keys in inner hash are:
9876: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 9877: (b) endreserve: end date of reservation period.
9878: (c) uniqueperiod: start,end dates when slot is to be uniquely
9879: selected.
1.1040 raeburn 9880:
9881: sorted_future - ref to array of student_schedulable slots reservable in
9882: the future, ordered by start date of reservation period.
9883:
9884: future_reservable - ref to hash of student_schedulable slots reservable
9885: in the future.
9886:
9887: Keys in inner hash are:
9888: (a) symb: either blank or symb to which slot use is restricted.
9889: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 9890: (c) uniqueperiod: start,end dates when slot is to be uniquely
9891: selected.
1.1040 raeburn 9892:
9893: =back
9894:
9895: =cut
9896:
9897: sub get_future_slots {
9898: my ($cnum,$cdom,$now,$symb) = @_;
9899: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9900: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9901: foreach my $slot (keys(%slots)) {
9902: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9903: if ($symb) {
9904: next if (($slots{$slot}->{'symb'} ne '') &&
9905: ($slots{$slot}->{'symb'} ne $symb));
9906: }
9907: if (($slots{$slot}->{'starttime'} > $now) &&
9908: ($slots{$slot}->{'endtime'} > $now)) {
9909: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9910: my $userallowed = 0;
9911: if ($slots{$slot}->{'allowedsections'}) {
9912: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9913: if (!defined($env{'request.role.sec'})
9914: && grep(/^No section assigned$/,@allowed_sec)) {
9915: $userallowed=1;
9916: } else {
9917: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9918: $userallowed=1;
9919: }
9920: }
9921: unless ($userallowed) {
9922: if (defined($env{'request.course.groups'})) {
9923: my @groups = split(/:/,$env{'request.course.groups'});
9924: foreach my $group (@groups) {
9925: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9926: $userallowed=1;
9927: last;
9928: }
9929: }
9930: }
9931: }
9932: }
9933: if ($slots{$slot}->{'allowedusers'}) {
9934: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9935: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9936: if (grep(/^\Q$user\E$/,@allowed_users)) {
9937: $userallowed = 1;
9938: }
9939: }
9940: next unless($userallowed);
9941: }
9942: my $startreserve = $slots{$slot}->{'startreserve'};
9943: my $endreserve = $slots{$slot}->{'endreserve'};
9944: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 9945: my $uniqueperiod;
9946: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
9947: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
9948: }
1.1040 raeburn 9949: if (($startreserve < $now) &&
9950: (!$endreserve || $endreserve > $now)) {
9951: my $lastres = $endreserve;
9952: if (!$lastres) {
9953: $lastres = $slots{$slot}->{'starttime'};
9954: }
9955: $reservable_now{$slot} = {
9956: symb => $symb,
1.1075.2.104 raeburn 9957: endreserve => $lastres,
9958: uniqueperiod => $uniqueperiod,
1.1040 raeburn 9959: };
9960: } elsif (($startreserve > $now) &&
9961: (!$endreserve || $endreserve > $startreserve)) {
9962: $future_reservable{$slot} = {
9963: symb => $symb,
1.1075.2.104 raeburn 9964: startreserve => $startreserve,
9965: uniqueperiod => $uniqueperiod,
1.1040 raeburn 9966: };
9967: }
9968: }
9969: }
9970: my @unsorted_reservable = keys(%reservable_now);
9971: if (@unsorted_reservable > 0) {
9972: @sorted_reservable =
9973: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9974: }
9975: my @unsorted_future = keys(%future_reservable);
9976: if (@unsorted_future > 0) {
9977: @sorted_future =
9978: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9979: }
9980: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9981: }
1.780 raeburn 9982:
9983: =pod
9984:
1.1057 foxr 9985: =back
9986:
1.549 albertel 9987: =head1 HTTP Helpers
9988:
9989: =over 4
9990:
1.648 raeburn 9991: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9992:
1.258 albertel 9993: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9994: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9995: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9996:
9997: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9998: $possible_names is an ref to an array of form element names. As an example:
9999: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10000: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10001:
10002: =cut
1.1 albertel 10003:
1.6 albertel 10004: sub get_unprocessed_cgi {
1.25 albertel 10005: my ($query,$possible_names)= @_;
1.26 matthew 10006: # $Apache::lonxml::debug=1;
1.356 albertel 10007: foreach my $pair (split(/&/,$query)) {
10008: my ($name, $value) = split(/=/,$pair);
1.369 www 10009: $name = &unescape($name);
1.25 albertel 10010: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10011: $value =~ tr/+/ /;
10012: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10013: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10014: }
1.16 harris41 10015: }
1.6 albertel 10016: }
10017:
1.112 bowersj2 10018: =pod
10019:
1.648 raeburn 10020: =item * &cacheheader()
1.112 bowersj2 10021:
10022: returns cache-controlling header code
10023:
10024: =cut
10025:
1.7 albertel 10026: sub cacheheader {
1.258 albertel 10027: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10028: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10029: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10030: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10031: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10032: return $output;
1.7 albertel 10033: }
10034:
1.112 bowersj2 10035: =pod
10036:
1.648 raeburn 10037: =item * &no_cache($r)
1.112 bowersj2 10038:
10039: specifies header code to not have cache
10040:
10041: =cut
10042:
1.9 albertel 10043: sub no_cache {
1.216 albertel 10044: my ($r) = @_;
10045: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10046: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10047: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10048: $r->no_cache(1);
10049: $r->header_out("Expires" => $date);
10050: $r->header_out("Pragma" => "no-cache");
1.123 www 10051: }
10052:
10053: sub content_type {
1.181 albertel 10054: my ($r,$type,$charset) = @_;
1.299 foxr 10055: if ($r) {
10056: # Note that printout.pl calls this with undef for $r.
10057: &no_cache($r);
10058: }
1.258 albertel 10059: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10060: unless ($charset) {
10061: $charset=&Apache::lonlocal::current_encoding;
10062: }
10063: if ($charset) { $type.='; charset='.$charset; }
10064: if ($r) {
10065: $r->content_type($type);
10066: } else {
10067: print("Content-type: $type\n\n");
10068: }
1.9 albertel 10069: }
1.25 albertel 10070:
1.112 bowersj2 10071: =pod
10072:
1.648 raeburn 10073: =item * &add_to_env($name,$value)
1.112 bowersj2 10074:
1.258 albertel 10075: adds $name to the %env hash with value
1.112 bowersj2 10076: $value, if $name already exists, the entry is converted to an array
10077: reference and $value is added to the array.
10078:
10079: =cut
10080:
1.25 albertel 10081: sub add_to_env {
10082: my ($name,$value)=@_;
1.258 albertel 10083: if (defined($env{$name})) {
10084: if (ref($env{$name})) {
1.25 albertel 10085: #already have multiple values
1.258 albertel 10086: push(@{ $env{$name} },$value);
1.25 albertel 10087: } else {
10088: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10089: my $first=$env{$name};
10090: undef($env{$name});
10091: push(@{ $env{$name} },$first,$value);
1.25 albertel 10092: }
10093: } else {
1.258 albertel 10094: $env{$name}=$value;
1.25 albertel 10095: }
1.31 albertel 10096: }
1.149 albertel 10097:
10098: =pod
10099:
1.648 raeburn 10100: =item * &get_env_multiple($name)
1.149 albertel 10101:
1.258 albertel 10102: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10103: values may be defined and end up as an array ref.
10104:
10105: returns an array of values
10106:
10107: =cut
10108:
10109: sub get_env_multiple {
10110: my ($name) = @_;
10111: my @values;
1.258 albertel 10112: if (defined($env{$name})) {
1.149 albertel 10113: # exists is it an array
1.258 albertel 10114: if (ref($env{$name})) {
10115: @values=@{ $env{$name} };
1.149 albertel 10116: } else {
1.258 albertel 10117: $values[0]=$env{$name};
1.149 albertel 10118: }
10119: }
10120: return(@values);
10121: }
10122:
1.660 raeburn 10123: sub ask_for_embedded_content {
10124: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10125: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 10126: %currsubfile,%unused,$rem);
1.1071 raeburn 10127: my $counter = 0;
10128: my $numnew = 0;
1.987 raeburn 10129: my $numremref = 0;
10130: my $numinvalid = 0;
10131: my $numpathchg = 0;
10132: my $numexisting = 0;
1.1071 raeburn 10133: my $numunused = 0;
10134: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 10135: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10136: my $heading = &mt('Upload embedded files');
10137: my $buttontext = &mt('Upload');
10138:
1.1075.2.11 raeburn 10139: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 10140: if ($actionurl eq '/adm/dependencies') {
10141: $navmap = Apache::lonnavmaps::navmap->new();
10142: }
10143: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10144: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 10145: }
1.1075.2.35 raeburn 10146: if (($actionurl eq '/adm/portfolio') ||
10147: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10148: my $current_path='/';
10149: if ($env{'form.currentpath'}) {
10150: $current_path = $env{'form.currentpath'};
10151: }
10152: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 10153: $udom = $cdom;
10154: $uname = $cnum;
1.984 raeburn 10155: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10156: } else {
10157: $udom = $env{'user.domain'};
10158: $uname = $env{'user.name'};
10159: $url = '/userfiles/portfolio';
10160: }
1.987 raeburn 10161: $toplevel = $url.'/';
1.984 raeburn 10162: $url .= $current_path;
10163: $getpropath = 1;
1.987 raeburn 10164: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10165: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10166: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10167: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10168: $toplevel = $url;
1.984 raeburn 10169: if ($rest ne '') {
1.987 raeburn 10170: $url .= $rest;
10171: }
10172: } elsif ($actionurl eq '/adm/coursedocs') {
10173: if (ref($args) eq 'HASH') {
1.1071 raeburn 10174: $url = $args->{'docs_url'};
10175: $toplevel = $url;
1.1075.2.11 raeburn 10176: if ($args->{'context'} eq 'paste') {
10177: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10178: ($path) =
10179: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10180: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10181: $fileloc =~ s{^/}{};
10182: }
1.1071 raeburn 10183: }
10184: } elsif ($actionurl eq '/adm/dependencies') {
10185: if ($env{'request.course.id'} ne '') {
10186: if (ref($args) eq 'HASH') {
10187: $url = $args->{'docs_url'};
10188: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 10189: $toplevel = $url;
10190: unless ($toplevel =~ m{^/}) {
10191: $toplevel = "/$url";
10192: }
1.1075.2.11 raeburn 10193: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 10194: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10195: $path = $1;
10196: } else {
10197: ($path) =
10198: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10199: }
1.1075.2.79 raeburn 10200: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10201: $fileloc = $toplevel;
10202: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10203: my ($udom,$uname,$fname) =
10204: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10205: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10206: } else {
10207: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10208: }
1.1071 raeburn 10209: $fileloc =~ s{^/}{};
10210: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10211: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10212: }
1.987 raeburn 10213: }
1.1075.2.35 raeburn 10214: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10215: $udom = $cdom;
10216: $uname = $cnum;
10217: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10218: $toplevel = $url;
10219: $path = $url;
10220: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10221: $fileloc =~ s{^/}{};
10222: }
10223: foreach my $file (keys(%{$allfiles})) {
10224: my $embed_file;
10225: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10226: $embed_file = $1;
10227: } else {
10228: $embed_file = $file;
10229: }
1.1075.2.55 raeburn 10230: my ($absolutepath,$cleaned_file);
10231: if ($embed_file =~ m{^\w+://}) {
10232: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 10233: $newfiles{$cleaned_file} = 1;
10234: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10235: } else {
1.1075.2.55 raeburn 10236: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10237: if ($embed_file =~ m{^/}) {
10238: $absolutepath = $embed_file;
10239: }
1.1075.2.47 raeburn 10240: if ($cleaned_file =~ m{/}) {
10241: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10242: $path = &check_for_traversal($path,$url,$toplevel);
10243: my $item = $fname;
10244: if ($path ne '') {
10245: $item = $path.'/'.$fname;
10246: $subdependencies{$path}{$fname} = 1;
10247: } else {
10248: $dependencies{$item} = 1;
10249: }
10250: if ($absolutepath) {
10251: $mapping{$item} = $absolutepath;
10252: } else {
10253: $mapping{$item} = $embed_file;
10254: }
10255: } else {
10256: $dependencies{$embed_file} = 1;
10257: if ($absolutepath) {
1.1075.2.47 raeburn 10258: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10259: } else {
1.1075.2.47 raeburn 10260: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10261: }
10262: }
1.984 raeburn 10263: }
10264: }
1.1071 raeburn 10265: my $dirptr = 16384;
1.984 raeburn 10266: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10267: $currsubfile{$path} = {};
1.1075.2.35 raeburn 10268: if (($actionurl eq '/adm/portfolio') ||
10269: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10270: my ($sublistref,$listerror) =
10271: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10272: if (ref($sublistref) eq 'ARRAY') {
10273: foreach my $line (@{$sublistref}) {
10274: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10275: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10276: }
1.984 raeburn 10277: }
1.987 raeburn 10278: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10279: if (opendir(my $dir,$url.'/'.$path)) {
10280: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10281: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10282: }
1.1075.2.11 raeburn 10283: } elsif (($actionurl eq '/adm/dependencies') ||
10284: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10285: ($args->{'context'} eq 'paste')) ||
10286: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10287: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 10288: my $dir;
10289: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10290: $dir = $fileloc;
10291: } else {
10292: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10293: }
1.1071 raeburn 10294: if ($dir ne '') {
10295: my ($sublistref,$listerror) =
10296: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10297: if (ref($sublistref) eq 'ARRAY') {
10298: foreach my $line (@{$sublistref}) {
10299: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10300: undef,$mtime)=split(/\&/,$line,12);
10301: unless (($testdir&$dirptr) ||
10302: ($file_name =~ /^\.\.?$/)) {
10303: $currsubfile{$path}{$file_name} = [$size,$mtime];
10304: }
10305: }
10306: }
10307: }
1.984 raeburn 10308: }
10309: }
10310: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10311: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10312: my $item = $path.'/'.$file;
10313: unless ($mapping{$item} eq $item) {
10314: $pathchanges{$item} = 1;
10315: }
10316: $existing{$item} = 1;
10317: $numexisting ++;
10318: } else {
10319: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10320: }
10321: }
1.1071 raeburn 10322: if ($actionurl eq '/adm/dependencies') {
10323: foreach my $path (keys(%currsubfile)) {
10324: if (ref($currsubfile{$path}) eq 'HASH') {
10325: foreach my $file (keys(%{$currsubfile{$path}})) {
10326: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10327: next if (($rem ne '') &&
10328: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10329: (ref($navmap) &&
10330: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10331: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10332: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10333: $unused{$path.'/'.$file} = 1;
10334: }
10335: }
10336: }
10337: }
10338: }
1.984 raeburn 10339: }
1.987 raeburn 10340: my %currfile;
1.1075.2.35 raeburn 10341: if (($actionurl eq '/adm/portfolio') ||
10342: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10343: my ($dirlistref,$listerror) =
10344: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10345: if (ref($dirlistref) eq 'ARRAY') {
10346: foreach my $line (@{$dirlistref}) {
10347: my ($file_name,$rest) = split(/\&/,$line,2);
10348: $currfile{$file_name} = 1;
10349: }
1.984 raeburn 10350: }
1.987 raeburn 10351: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10352: if (opendir(my $dir,$url)) {
1.987 raeburn 10353: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10354: map {$currfile{$_} = 1;} @dir_list;
10355: }
1.1075.2.11 raeburn 10356: } elsif (($actionurl eq '/adm/dependencies') ||
10357: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10358: ($args->{'context'} eq 'paste')) ||
10359: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10360: if ($env{'request.course.id'} ne '') {
10361: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10362: if ($dir ne '') {
10363: my ($dirlistref,$listerror) =
10364: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10365: if (ref($dirlistref) eq 'ARRAY') {
10366: foreach my $line (@{$dirlistref}) {
10367: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10368: $size,undef,$mtime)=split(/\&/,$line,12);
10369: unless (($testdir&$dirptr) ||
10370: ($file_name =~ /^\.\.?$/)) {
10371: $currfile{$file_name} = [$size,$mtime];
10372: }
10373: }
10374: }
10375: }
10376: }
1.984 raeburn 10377: }
10378: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10379: if (exists($currfile{$file})) {
1.987 raeburn 10380: unless ($mapping{$file} eq $file) {
10381: $pathchanges{$file} = 1;
10382: }
10383: $existing{$file} = 1;
10384: $numexisting ++;
10385: } else {
1.984 raeburn 10386: $newfiles{$file} = 1;
10387: }
10388: }
1.1071 raeburn 10389: foreach my $file (keys(%currfile)) {
10390: unless (($file eq $filename) ||
10391: ($file eq $filename.'.bak') ||
10392: ($dependencies{$file})) {
1.1075.2.11 raeburn 10393: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10394: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10395: next if (($rem ne '') &&
10396: (($env{"httpref.$rem".$file} ne '') ||
10397: (ref($navmap) &&
10398: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10399: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10400: ($navmap->getResourceByUrl($rem.$1)))))));
10401: }
1.1075.2.11 raeburn 10402: }
1.1071 raeburn 10403: $unused{$file} = 1;
10404: }
10405: }
1.1075.2.11 raeburn 10406: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10407: ($args->{'context'} eq 'paste')) {
10408: $counter = scalar(keys(%existing));
10409: $numpathchg = scalar(keys(%pathchanges));
10410: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10411: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10412: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10413: $counter = scalar(keys(%existing));
10414: $numpathchg = scalar(keys(%pathchanges));
10415: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10416: }
1.984 raeburn 10417: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10418: if ($actionurl eq '/adm/dependencies') {
10419: next if ($embed_file =~ m{^\w+://});
10420: }
1.660 raeburn 10421: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10422: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10423: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10424: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10425: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10426: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10427: }
1.1075.2.35 raeburn 10428: $upload_output .= '</td>';
1.1071 raeburn 10429: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10430: $upload_output.='<td align="right">'.
10431: '<span class="LC_info LC_fontsize_medium">'.
10432: &mt("URL points to web address").'</span>';
1.987 raeburn 10433: $numremref++;
1.660 raeburn 10434: } elsif ($args->{'error_on_invalid_names'}
10435: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10436: $upload_output.='<td align="right"><span class="LC_warning">'.
10437: &mt('Invalid characters').'</span>';
1.987 raeburn 10438: $numinvalid++;
1.660 raeburn 10439: } else {
1.1075.2.35 raeburn 10440: $upload_output .= '<td>'.
10441: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10442: $embed_file,\%mapping,
1.1071 raeburn 10443: $allfiles,$codebase,'upload');
10444: $counter ++;
10445: $numnew ++;
1.987 raeburn 10446: }
10447: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10448: }
10449: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10450: if ($actionurl eq '/adm/dependencies') {
10451: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10452: $modify_output .= &start_data_table_row().
10453: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10454: '<img src="'.&icon($embed_file).'" border="0" />'.
10455: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10456: '<td>'.$size.'</td>'.
10457: '<td>'.$mtime.'</td>'.
10458: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10459: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10460: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10461: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10462: &embedded_file_element('upload_embedded',$counter,
10463: $embed_file,\%mapping,
10464: $allfiles,$codebase,'modify').
10465: '</div></td>'.
10466: &end_data_table_row()."\n";
10467: $counter ++;
10468: } else {
10469: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10470: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10471: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10472: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10473: &Apache::loncommon::end_data_table_row()."\n";
10474: }
10475: }
10476: my $delidx = $counter;
10477: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10478: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10479: $delete_output .= &start_data_table_row().
10480: '<td><img src="'.&icon($oldfile).'" />'.
10481: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10482: '<td>'.$size.'</td>'.
10483: '<td>'.$mtime.'</td>'.
10484: '<td><label><input type="checkbox" name="del_upload_dep" '.
10485: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10486: &embedded_file_element('upload_embedded',$delidx,
10487: $oldfile,\%mapping,$allfiles,
10488: $codebase,'delete').'</td>'.
10489: &end_data_table_row()."\n";
10490: $numunused ++;
10491: $delidx ++;
1.987 raeburn 10492: }
10493: if ($upload_output) {
10494: $upload_output = &start_data_table().
10495: $upload_output.
10496: &end_data_table()."\n";
10497: }
1.1071 raeburn 10498: if ($modify_output) {
10499: $modify_output = &start_data_table().
10500: &start_data_table_header_row().
10501: '<th>'.&mt('File').'</th>'.
10502: '<th>'.&mt('Size (KB)').'</th>'.
10503: '<th>'.&mt('Modified').'</th>'.
10504: '<th>'.&mt('Upload replacement?').'</th>'.
10505: &end_data_table_header_row().
10506: $modify_output.
10507: &end_data_table()."\n";
10508: }
10509: if ($delete_output) {
10510: $delete_output = &start_data_table().
10511: &start_data_table_header_row().
10512: '<th>'.&mt('File').'</th>'.
10513: '<th>'.&mt('Size (KB)').'</th>'.
10514: '<th>'.&mt('Modified').'</th>'.
10515: '<th>'.&mt('Delete?').'</th>'.
10516: &end_data_table_header_row().
10517: $delete_output.
10518: &end_data_table()."\n";
10519: }
1.987 raeburn 10520: my $applies = 0;
10521: if ($numremref) {
10522: $applies ++;
10523: }
10524: if ($numinvalid) {
10525: $applies ++;
10526: }
10527: if ($numexisting) {
10528: $applies ++;
10529: }
1.1071 raeburn 10530: if ($counter || $numunused) {
1.987 raeburn 10531: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10532: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10533: $state.'<h3>'.$heading.'</h3>';
10534: if ($actionurl eq '/adm/dependencies') {
10535: if ($numnew) {
10536: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10537: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10538: $upload_output.'<br />'."\n";
10539: }
10540: if ($numexisting) {
10541: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10542: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10543: $modify_output.'<br />'."\n";
10544: $buttontext = &mt('Save changes');
10545: }
10546: if ($numunused) {
10547: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10548: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10549: $delete_output.'<br />'."\n";
10550: $buttontext = &mt('Save changes');
10551: }
10552: } else {
10553: $output .= $upload_output.'<br />'."\n";
10554: }
10555: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10556: $counter.'" />'."\n";
10557: if ($actionurl eq '/adm/dependencies') {
10558: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10559: $numnew.'" />'."\n";
10560: } elsif ($actionurl eq '') {
1.987 raeburn 10561: $output .= '<input type="hidden" name="phase" value="three" />';
10562: }
10563: } elsif ($applies) {
10564: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10565: if ($applies > 1) {
10566: $output .=
1.1075.2.35 raeburn 10567: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10568: if ($numremref) {
10569: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10570: }
10571: if ($numinvalid) {
10572: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10573: }
10574: if ($numexisting) {
10575: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10576: }
10577: $output .= '</ul><br />';
10578: } elsif ($numremref) {
10579: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10580: } elsif ($numinvalid) {
10581: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10582: } elsif ($numexisting) {
10583: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10584: }
10585: $output .= $upload_output.'<br />';
10586: }
10587: my ($pathchange_output,$chgcount);
1.1071 raeburn 10588: $chgcount = $counter;
1.987 raeburn 10589: if (keys(%pathchanges) > 0) {
10590: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10591: if ($counter) {
1.987 raeburn 10592: $output .= &embedded_file_element('pathchange',$chgcount,
10593: $embed_file,\%mapping,
1.1071 raeburn 10594: $allfiles,$codebase,'change');
1.987 raeburn 10595: } else {
10596: $pathchange_output .=
10597: &start_data_table_row().
10598: '<td><input type ="checkbox" name="namechange" value="'.
10599: $chgcount.'" checked="checked" /></td>'.
10600: '<td>'.$mapping{$embed_file}.'</td>'.
10601: '<td>'.$embed_file.
10602: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10603: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10604: '</td>'.&end_data_table_row();
1.660 raeburn 10605: }
1.987 raeburn 10606: $numpathchg ++;
10607: $chgcount ++;
1.660 raeburn 10608: }
10609: }
1.1075.2.35 raeburn 10610: if (($counter) || ($numunused)) {
1.987 raeburn 10611: if ($numpathchg) {
10612: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10613: $numpathchg.'" />'."\n";
10614: }
10615: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10616: ($actionurl eq '/adm/imsimport')) {
10617: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10618: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10619: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10620: } elsif ($actionurl eq '/adm/dependencies') {
10621: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10622: }
1.1075.2.35 raeburn 10623: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10624: } elsif ($numpathchg) {
10625: my %pathchange = ();
10626: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10627: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10628: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 10629: }
1.987 raeburn 10630: }
1.1071 raeburn 10631: return ($output,$counter,$numpathchg);
1.987 raeburn 10632: }
10633:
1.1075.2.47 raeburn 10634: =pod
10635:
10636: =item * clean_path($name)
10637:
10638: Performs clean-up of directories, subdirectories and filename in an
10639: embedded object, referenced in an HTML file which is being uploaded
10640: to a course or portfolio, where
10641: "Upload embedded images/multimedia files if HTML file" checkbox was
10642: checked.
10643:
10644: Clean-up is similar to replacements in lonnet::clean_filename()
10645: except each / between sub-directory and next level is preserved.
10646:
10647: =cut
10648:
10649: sub clean_path {
10650: my ($embed_file) = @_;
10651: $embed_file =~s{^/+}{};
10652: my @contents;
10653: if ($embed_file =~ m{/}) {
10654: @contents = split(/\//,$embed_file);
10655: } else {
10656: @contents = ($embed_file);
10657: }
10658: my $lastidx = scalar(@contents)-1;
10659: for (my $i=0; $i<=$lastidx; $i++) {
10660: $contents[$i]=~s{\\}{/}g;
10661: $contents[$i]=~s/\s+/\_/g;
10662: $contents[$i]=~s{[^/\w\.\-]}{}g;
10663: if ($i == $lastidx) {
10664: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10665: }
10666: }
10667: if ($lastidx > 0) {
10668: return join('/',@contents);
10669: } else {
10670: return $contents[0];
10671: }
10672: }
10673:
1.987 raeburn 10674: sub embedded_file_element {
1.1071 raeburn 10675: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10676: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10677: (ref($codebase) eq 'HASH'));
10678: my $output;
1.1071 raeburn 10679: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10680: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10681: }
10682: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10683: &escape($embed_file).'" />';
10684: unless (($context eq 'upload_embedded') &&
10685: ($mapping->{$embed_file} eq $embed_file)) {
10686: $output .='
10687: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10688: }
10689: my $attrib;
10690: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10691: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10692: }
10693: $output .=
10694: "\n\t\t".
10695: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10696: $attrib.'" />';
10697: if (exists($codebase->{$mapping->{$embed_file}})) {
10698: $output .=
10699: "\n\t\t".
10700: '<input name="codebase_'.$num.'" type="hidden" value="'.
10701: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10702: }
1.987 raeburn 10703: return $output;
1.660 raeburn 10704: }
10705:
1.1071 raeburn 10706: sub get_dependency_details {
10707: my ($currfile,$currsubfile,$embed_file) = @_;
10708: my ($size,$mtime,$showsize,$showmtime);
10709: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10710: if ($embed_file =~ m{/}) {
10711: my ($path,$fname) = split(/\//,$embed_file);
10712: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10713: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10714: }
10715: } else {
10716: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10717: ($size,$mtime) = @{$currfile->{$embed_file}};
10718: }
10719: }
10720: $showsize = $size/1024.0;
10721: $showsize = sprintf("%.1f",$showsize);
10722: if ($mtime > 0) {
10723: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10724: }
10725: }
10726: return ($showsize,$showmtime);
10727: }
10728:
10729: sub ask_embedded_js {
10730: return <<"END";
10731: <script type="text/javascript"">
10732: // <![CDATA[
10733: function toggleBrowse(counter) {
10734: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10735: var fileid = document.getElementById('embedded_item_'+counter);
10736: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10737: if (chkboxid.checked == true) {
10738: uploaddivid.style.display='block';
10739: } else {
10740: uploaddivid.style.display='none';
10741: fileid.value = '';
10742: }
10743: }
10744: // ]]>
10745: </script>
10746:
10747: END
10748: }
10749:
1.661 raeburn 10750: sub upload_embedded {
10751: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10752: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10753: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10754: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10755: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10756: my $orig_uploaded_filename =
10757: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10758: foreach my $type ('orig','ref','attrib','codebase') {
10759: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10760: $env{'form.embedded_'.$type.'_'.$i} =
10761: &unescape($env{'form.embedded_'.$type.'_'.$i});
10762: }
10763: }
1.661 raeburn 10764: my ($path,$fname) =
10765: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10766: # no path, whole string is fname
10767: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10768: $fname = &Apache::lonnet::clean_filename($fname);
10769: # See if there is anything left
10770: next if ($fname eq '');
10771:
10772: # Check if file already exists as a file or directory.
10773: my ($state,$msg);
10774: if ($context eq 'portfolio') {
10775: my $port_path = $dirpath;
10776: if ($group ne '') {
10777: $port_path = "groups/$group/$port_path";
10778: }
1.987 raeburn 10779: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10780: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10781: $dir_root,$port_path,$disk_quota,
10782: $current_disk_usage,$uname,$udom);
10783: if ($state eq 'will_exceed_quota'
1.984 raeburn 10784: || $state eq 'file_locked') {
1.661 raeburn 10785: $output .= $msg;
10786: next;
10787: }
10788: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10789: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10790: if ($state eq 'exists') {
10791: $output .= $msg;
10792: next;
10793: }
10794: }
10795: # Check if extension is valid
10796: if (($fname =~ /\.(\w+)$/) &&
10797: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 10798: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
10799: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 10800: next;
10801: } elsif (($fname =~ /\.(\w+)$/) &&
10802: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10803: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10804: next;
10805: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 10806: $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 10807: next;
10808: }
10809: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 10810: my $subdir = $path;
10811: $subdir =~ s{/+$}{};
1.661 raeburn 10812: if ($context eq 'portfolio') {
1.984 raeburn 10813: my $result;
10814: if ($state eq 'existingfile') {
10815: $result=
10816: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 10817: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10818: } else {
1.984 raeburn 10819: $result=
10820: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10821: $dirpath.
1.1075.2.35 raeburn 10822: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10823: if ($result !~ m|^/uploaded/|) {
10824: $output .= '<span class="LC_error">'
10825: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10826: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10827: .'</span><br />';
10828: next;
10829: } else {
1.987 raeburn 10830: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10831: $path.$fname.'</span>').'<br />';
1.984 raeburn 10832: }
1.661 raeburn 10833: }
1.1075.2.35 raeburn 10834: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
10835: my $extendedsubdir = $dirpath.'/'.$subdir;
10836: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10837: my $result =
1.1075.2.35 raeburn 10838: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10839: if ($result !~ m|^/uploaded/|) {
10840: $output .= '<span class="LC_error">'
10841: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10842: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10843: .'</span><br />';
10844: next;
10845: } else {
10846: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10847: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 10848: if ($context eq 'syllabus') {
10849: &Apache::lonnet::make_public_indefinitely($result);
10850: }
1.987 raeburn 10851: }
1.661 raeburn 10852: } else {
10853: # Save the file
10854: my $target = $env{'form.embedded_item_'.$i};
10855: my $fullpath = $dir_root.$dirpath.'/'.$path;
10856: my $dest = $fullpath.$fname;
10857: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10858: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10859: my $count;
10860: my $filepath = $dir_root;
1.1027 raeburn 10861: foreach my $subdir (@parts) {
10862: $filepath .= "/$subdir";
10863: if (!-e $filepath) {
1.661 raeburn 10864: mkdir($filepath,0770);
10865: }
10866: }
10867: my $fh;
10868: if (!open($fh,'>'.$dest)) {
10869: &Apache::lonnet::logthis('Failed to create '.$dest);
10870: $output .= '<span class="LC_error">'.
1.1071 raeburn 10871: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10872: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10873: '</span><br />';
10874: } else {
10875: if (!print $fh $env{'form.embedded_item_'.$i}) {
10876: &Apache::lonnet::logthis('Failed to write to '.$dest);
10877: $output .= '<span class="LC_error">'.
1.1071 raeburn 10878: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10879: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10880: '</span><br />';
10881: } else {
1.987 raeburn 10882: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10883: $url.'</span>').'<br />';
10884: unless ($context eq 'testbank') {
10885: $footer .= &mt('View embedded file: [_1]',
10886: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10887: }
10888: }
10889: close($fh);
10890: }
10891: }
10892: if ($env{'form.embedded_ref_'.$i}) {
10893: $pathchange{$i} = 1;
10894: }
10895: }
10896: if ($output) {
10897: $output = '<p>'.$output.'</p>';
10898: }
10899: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10900: $returnflag = 'ok';
1.1071 raeburn 10901: my $numpathchgs = scalar(keys(%pathchange));
10902: if ($numpathchgs > 0) {
1.987 raeburn 10903: if ($context eq 'portfolio') {
10904: $output .= '<p>'.&mt('or').'</p>';
10905: } elsif ($context eq 'testbank') {
1.1071 raeburn 10906: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10907: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10908: $returnflag = 'modify_orightml';
10909: }
10910: }
1.1071 raeburn 10911: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10912: }
10913:
10914: sub modify_html_form {
10915: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10916: my $end = 0;
10917: my $modifyform;
10918: if ($context eq 'upload_embedded') {
10919: return unless (ref($pathchange) eq 'HASH');
10920: if ($env{'form.number_embedded_items'}) {
10921: $end += $env{'form.number_embedded_items'};
10922: }
10923: if ($env{'form.number_pathchange_items'}) {
10924: $end += $env{'form.number_pathchange_items'};
10925: }
10926: if ($end) {
10927: for (my $i=0; $i<$end; $i++) {
10928: if ($i < $env{'form.number_embedded_items'}) {
10929: next unless($pathchange->{$i});
10930: }
10931: $modifyform .=
10932: &start_data_table_row().
10933: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10934: 'checked="checked" /></td>'.
10935: '<td>'.$env{'form.embedded_ref_'.$i}.
10936: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10937: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10938: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10939: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10940: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10941: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10942: '<td>'.$env{'form.embedded_orig_'.$i}.
10943: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10944: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10945: &end_data_table_row();
1.1071 raeburn 10946: }
1.987 raeburn 10947: }
10948: } else {
10949: $modifyform = $pathchgtable;
10950: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10951: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10952: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10953: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10954: }
10955: }
10956: if ($modifyform) {
1.1071 raeburn 10957: if ($actionurl eq '/adm/dependencies') {
10958: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10959: }
1.987 raeburn 10960: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10961: '<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".
10962: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10963: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10964: '</ol></p>'."\n".'<p>'.
10965: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10966: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10967: &start_data_table()."\n".
10968: &start_data_table_header_row().
10969: '<th>'.&mt('Change?').'</th>'.
10970: '<th>'.&mt('Current reference').'</th>'.
10971: '<th>'.&mt('Required reference').'</th>'.
10972: &end_data_table_header_row()."\n".
10973: $modifyform.
10974: &end_data_table().'<br />'."\n".$hiddenstate.
10975: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10976: '</form>'."\n";
10977: }
10978: return;
10979: }
10980:
10981: sub modify_html_refs {
1.1075.2.35 raeburn 10982: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10983: my $container;
10984: if ($context eq 'portfolio') {
10985: $container = $env{'form.container'};
10986: } elsif ($context eq 'coursedoc') {
10987: $container = $env{'form.primaryurl'};
1.1071 raeburn 10988: } elsif ($context eq 'manage_dependencies') {
10989: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10990: $container = "/$container";
1.1075.2.35 raeburn 10991: } elsif ($context eq 'syllabus') {
10992: $container = $url;
1.987 raeburn 10993: } else {
1.1027 raeburn 10994: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10995: }
10996: my (%allfiles,%codebase,$output,$content);
10997: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 10998: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10999: if (wantarray) {
11000: return ('',0,0);
11001: } else {
11002: return;
11003: }
11004: }
11005: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11006: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11007: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11008: if (wantarray) {
11009: return ('',0,0);
11010: } else {
11011: return;
11012: }
11013: }
1.987 raeburn 11014: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11015: if ($content eq '-1') {
11016: if (wantarray) {
11017: return ('',0,0);
11018: } else {
11019: return;
11020: }
11021: }
1.987 raeburn 11022: } else {
1.1071 raeburn 11023: unless ($container =~ /^\Q$dir_root\E/) {
11024: if (wantarray) {
11025: return ('',0,0);
11026: } else {
11027: return;
11028: }
11029: }
1.987 raeburn 11030: if (open(my $fh,"<$container")) {
11031: $content = join('', <$fh>);
11032: close($fh);
11033: } else {
1.1071 raeburn 11034: if (wantarray) {
11035: return ('',0,0);
11036: } else {
11037: return;
11038: }
1.987 raeburn 11039: }
11040: }
11041: my ($count,$codebasecount) = (0,0);
11042: my $mm = new File::MMagic;
11043: my $mime_type = $mm->checktype_contents($content);
11044: if ($mime_type eq 'text/html') {
11045: my $parse_result =
11046: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11047: \%codebase,\$content);
11048: if ($parse_result eq 'ok') {
11049: foreach my $i (@changes) {
11050: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11051: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11052: if ($allfiles{$ref}) {
11053: my $newname = $orig;
11054: my ($attrib_regexp,$codebase);
1.1006 raeburn 11055: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11056: if ($attrib_regexp =~ /:/) {
11057: $attrib_regexp =~ s/\:/|/g;
11058: }
11059: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11060: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11061: $count += $numchg;
1.1075.2.35 raeburn 11062: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11063: delete($allfiles{$ref});
1.987 raeburn 11064: }
11065: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11066: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11067: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11068: $codebasecount ++;
11069: }
11070: }
11071: }
1.1075.2.35 raeburn 11072: my $skiprewrites;
1.987 raeburn 11073: if ($count || $codebasecount) {
11074: my $saveresult;
1.1071 raeburn 11075: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11076: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11077: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11078: if ($url eq $container) {
11079: my ($fname) = ($container =~ m{/([^/]+)$});
11080: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11081: $count,'<span class="LC_filename">'.
1.1071 raeburn 11082: $fname.'</span>').'</p>';
1.987 raeburn 11083: } else {
11084: $output = '<p class="LC_error">'.
11085: &mt('Error: update failed for: [_1].',
11086: '<span class="LC_filename">'.
11087: $container.'</span>').'</p>';
11088: }
1.1075.2.35 raeburn 11089: if ($context eq 'syllabus') {
11090: unless ($saveresult eq 'ok') {
11091: $skiprewrites = 1;
11092: }
11093: }
1.987 raeburn 11094: } else {
11095: if (open(my $fh,">$container")) {
11096: print $fh $content;
11097: close($fh);
11098: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11099: $count,'<span class="LC_filename">'.
11100: $container.'</span>').'</p>';
1.661 raeburn 11101: } else {
1.987 raeburn 11102: $output = '<p class="LC_error">'.
11103: &mt('Error: could not update [_1].',
11104: '<span class="LC_filename">'.
11105: $container.'</span>').'</p>';
1.661 raeburn 11106: }
11107: }
11108: }
1.1075.2.35 raeburn 11109: if (($context eq 'syllabus') && (!$skiprewrites)) {
11110: my ($actionurl,$state);
11111: $actionurl = "/public/$udom/$uname/syllabus";
11112: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11113: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11114: \%codebase,
11115: {'context' => 'rewrites',
11116: 'ignore_remote_references' => 1,});
11117: if (ref($mapping) eq 'HASH') {
11118: my $rewrites = 0;
11119: foreach my $key (keys(%{$mapping})) {
11120: next if ($key =~ m{^https?://});
11121: my $ref = $mapping->{$key};
11122: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11123: my $attrib;
11124: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11125: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11126: }
11127: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11128: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11129: $rewrites += $numchg;
11130: }
11131: }
11132: if ($rewrites) {
11133: my $saveresult;
11134: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11135: if ($url eq $container) {
11136: my ($fname) = ($container =~ m{/([^/]+)$});
11137: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11138: $count,'<span class="LC_filename">'.
11139: $fname.'</span>').'</p>';
11140: } else {
11141: $output .= '<p class="LC_error">'.
11142: &mt('Error: could not update links in [_1].',
11143: '<span class="LC_filename">'.
11144: $container.'</span>').'</p>';
11145:
11146: }
11147: }
11148: }
11149: }
1.987 raeburn 11150: } else {
11151: &logthis('Failed to parse '.$container.
11152: ' to modify references: '.$parse_result);
1.661 raeburn 11153: }
11154: }
1.1071 raeburn 11155: if (wantarray) {
11156: return ($output,$count,$codebasecount);
11157: } else {
11158: return $output;
11159: }
1.661 raeburn 11160: }
11161:
11162: sub check_for_existing {
11163: my ($path,$fname,$element) = @_;
11164: my ($state,$msg);
11165: if (-d $path.'/'.$fname) {
11166: $state = 'exists';
11167: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11168: } elsif (-e $path.'/'.$fname) {
11169: $state = 'exists';
11170: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11171: }
11172: if ($state eq 'exists') {
11173: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11174: }
11175: return ($state,$msg);
11176: }
11177:
11178: sub check_for_upload {
11179: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11180: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11181: my $filesize = length($env{'form.'.$element});
11182: if (!$filesize) {
11183: my $msg = '<span class="LC_error">'.
11184: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11185: '<span class="LC_filename">'.$fname.'</span>',
11186: $filesize).'<br />'.
1.1007 raeburn 11187: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11188: '</span>';
11189: return ('zero_bytes',$msg);
11190: }
11191: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11192: my $getpropath = 1;
1.1021 raeburn 11193: my ($dirlistref,$listerror) =
11194: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11195: my $found_file = 0;
11196: my $locked_file = 0;
1.991 raeburn 11197: my @lockers;
11198: my $navmap;
11199: if ($env{'request.course.id'}) {
11200: $navmap = Apache::lonnavmaps::navmap->new();
11201: }
1.1021 raeburn 11202: if (ref($dirlistref) eq 'ARRAY') {
11203: foreach my $line (@{$dirlistref}) {
11204: my ($file_name,$rest)=split(/\&/,$line,2);
11205: if ($file_name eq $fname){
11206: $file_name = $path.$file_name;
11207: if ($group ne '') {
11208: $file_name = $group.$file_name;
11209: }
11210: $found_file = 1;
11211: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11212: foreach my $lock (@lockers) {
11213: if (ref($lock) eq 'ARRAY') {
11214: my ($symb,$crsid) = @{$lock};
11215: if ($crsid eq $env{'request.course.id'}) {
11216: if (ref($navmap)) {
11217: my $res = $navmap->getBySymb($symb);
11218: foreach my $part (@{$res->parts()}) {
11219: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11220: unless (($slot_status == $res->RESERVED) ||
11221: ($slot_status == $res->RESERVED_LOCATION)) {
11222: $locked_file = 1;
11223: }
1.991 raeburn 11224: }
1.1021 raeburn 11225: } else {
11226: $locked_file = 1;
1.991 raeburn 11227: }
11228: } else {
11229: $locked_file = 1;
11230: }
11231: }
1.1021 raeburn 11232: }
11233: } else {
11234: my @info = split(/\&/,$rest);
11235: my $currsize = $info[6]/1000;
11236: if ($currsize < $filesize) {
11237: my $extra = $filesize - $currsize;
11238: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 11239: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11240: &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.1075.2.69 raeburn 11241: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11242: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11243: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11244: return ('will_exceed_quota',$msg);
11245: }
1.984 raeburn 11246: }
11247: }
1.661 raeburn 11248: }
11249: }
11250: }
11251: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 11252: my $msg = '<p class="LC_warning">'.
11253: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
11254: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11255: return ('will_exceed_quota',$msg);
11256: } elsif ($found_file) {
11257: if ($locked_file) {
1.1075.2.69 raeburn 11258: my $msg = '<p class="LC_warning">';
1.661 raeburn 11259: $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.1075.2.69 raeburn 11260: $msg .= '</p>';
1.661 raeburn 11261: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11262: return ('file_locked',$msg);
11263: } else {
1.1075.2.69 raeburn 11264: my $msg = '<p class="LC_error">';
1.984 raeburn 11265: $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.1075.2.69 raeburn 11266: $msg .= '</p>';
1.984 raeburn 11267: return ('existingfile',$msg);
1.661 raeburn 11268: }
11269: }
11270: }
11271:
1.987 raeburn 11272: sub check_for_traversal {
11273: my ($path,$url,$toplevel) = @_;
11274: my @parts=split(/\//,$path);
11275: my $cleanpath;
11276: my $fullpath = $url;
11277: for (my $i=0;$i<@parts;$i++) {
11278: next if ($parts[$i] eq '.');
11279: if ($parts[$i] eq '..') {
11280: $fullpath =~ s{([^/]+/)$}{};
11281: } else {
11282: $fullpath .= $parts[$i].'/';
11283: }
11284: }
11285: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11286: $cleanpath = $1;
11287: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11288: my $curr_toprel = $1;
11289: my @parts = split(/\//,$curr_toprel);
11290: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11291: my @urlparts = split(/\//,$url_toprel);
11292: my $doubledots;
11293: my $startdiff = -1;
11294: for (my $i=0; $i<@urlparts; $i++) {
11295: if ($startdiff == -1) {
11296: unless ($urlparts[$i] eq $parts[$i]) {
11297: $startdiff = $i;
11298: $doubledots .= '../';
11299: }
11300: } else {
11301: $doubledots .= '../';
11302: }
11303: }
11304: if ($startdiff > -1) {
11305: $cleanpath = $doubledots;
11306: for (my $i=$startdiff; $i<@parts; $i++) {
11307: $cleanpath .= $parts[$i].'/';
11308: }
11309: }
11310: }
11311: $cleanpath =~ s{(/)$}{};
11312: return $cleanpath;
11313: }
1.31 albertel 11314:
1.1053 raeburn 11315: sub is_archive_file {
11316: my ($mimetype) = @_;
11317: if (($mimetype eq 'application/octet-stream') ||
11318: ($mimetype eq 'application/x-stuffit') ||
11319: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11320: return 1;
11321: }
11322: return;
11323: }
11324:
11325: sub decompress_form {
1.1065 raeburn 11326: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11327: my %lt = &Apache::lonlocal::texthash (
11328: this => 'This file is an archive file.',
1.1067 raeburn 11329: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11330: itsc => 'Its contents are as follows:',
1.1053 raeburn 11331: youm => 'You may wish to extract its contents.',
11332: extr => 'Extract contents',
1.1067 raeburn 11333: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11334: proa => 'Process automatically?',
1.1053 raeburn 11335: yes => 'Yes',
11336: no => 'No',
1.1067 raeburn 11337: fold => 'Title for folder containing movie',
11338: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11339: );
1.1065 raeburn 11340: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11341: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11342: my $info = &list_archive_contents($fileloc,\@paths);
11343: if (@paths) {
11344: foreach my $path (@paths) {
11345: $path =~ s{^/}{};
1.1067 raeburn 11346: if ($path =~ m{^([^/]+)/$}) {
11347: $topdir = $1;
11348: }
1.1065 raeburn 11349: if ($path =~ m{^([^/]+)/}) {
11350: $toplevel{$1} = $path;
11351: } else {
11352: $toplevel{$path} = $path;
11353: }
11354: }
11355: }
1.1067 raeburn 11356: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 11357: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11358: "$topdir/media/",
11359: "$topdir/media/$topdir.mp4",
11360: "$topdir/media/FirstFrame.png",
11361: "$topdir/media/player.swf",
11362: "$topdir/media/swfobject.js",
11363: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 11364: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 11365: "$topdir/$topdir.mp4",
11366: "$topdir/$topdir\_config.xml",
11367: "$topdir/$topdir\_controller.swf",
11368: "$topdir/$topdir\_embed.css",
11369: "$topdir/$topdir\_First_Frame.png",
11370: "$topdir/$topdir\_player.html",
11371: "$topdir/$topdir\_Thumbnails.png",
11372: "$topdir/playerProductInstall.swf",
11373: "$topdir/scripts/",
11374: "$topdir/scripts/config_xml.js",
11375: "$topdir/scripts/handlebars.js",
11376: "$topdir/scripts/jquery-1.7.1.min.js",
11377: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11378: "$topdir/scripts/modernizr.js",
11379: "$topdir/scripts/player-min.js",
11380: "$topdir/scripts/swfobject.js",
11381: "$topdir/skins/",
11382: "$topdir/skins/configuration_express.xml",
11383: "$topdir/skins/express_show/",
11384: "$topdir/skins/express_show/player-min.css",
11385: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 11386: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11387: "$topdir/$topdir.mp4",
11388: "$topdir/$topdir\_config.xml",
11389: "$topdir/$topdir\_controller.swf",
11390: "$topdir/$topdir\_embed.css",
11391: "$topdir/$topdir\_First_Frame.png",
11392: "$topdir/$topdir\_player.html",
11393: "$topdir/$topdir\_Thumbnails.png",
11394: "$topdir/playerProductInstall.swf",
11395: "$topdir/scripts/",
11396: "$topdir/scripts/config_xml.js",
11397: "$topdir/scripts/techsmith-smart-player.min.js",
11398: "$topdir/skins/",
11399: "$topdir/skins/configuration_express.xml",
11400: "$topdir/skins/express_show/",
11401: "$topdir/skins/express_show/spritesheet.min.css",
11402: "$topdir/skins/express_show/spritesheet.png",
11403: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 11404: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11405: if (@diffs == 0) {
1.1075.2.59 raeburn 11406: $is_camtasia = 6;
11407: } else {
1.1075.2.81 raeburn 11408: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 11409: if (@diffs == 0) {
11410: $is_camtasia = 8;
1.1075.2.81 raeburn 11411: } else {
11412: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
11413: if (@diffs == 0) {
11414: $is_camtasia = 8;
11415: }
1.1075.2.59 raeburn 11416: }
1.1067 raeburn 11417: }
11418: }
11419: my $output;
11420: if ($is_camtasia) {
11421: $output = <<"ENDCAM";
11422: <script type="text/javascript" language="Javascript">
11423: // <![CDATA[
11424:
11425: function camtasiaToggle() {
11426: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11427: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 11428: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11429: document.getElementById('camtasia_titles').style.display='block';
11430: } else {
11431: document.getElementById('camtasia_titles').style.display='none';
11432: }
11433: }
11434: }
11435: return;
11436: }
11437:
11438: // ]]>
11439: </script>
11440: <p>$lt{'camt'}</p>
11441: ENDCAM
1.1065 raeburn 11442: } else {
1.1067 raeburn 11443: $output = '<p>'.$lt{'this'};
11444: if ($info eq '') {
11445: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11446: } else {
11447: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11448: '<div><pre>'.$info.'</pre></div>';
11449: }
1.1065 raeburn 11450: }
1.1067 raeburn 11451: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11452: my $duplicates;
11453: my $num = 0;
11454: if (ref($dirlist) eq 'ARRAY') {
11455: foreach my $item (@{$dirlist}) {
11456: if (ref($item) eq 'ARRAY') {
11457: if (exists($toplevel{$item->[0]})) {
11458: $duplicates .=
11459: &start_data_table_row().
11460: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11461: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11462: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11463: 'value="1" />'.&mt('Yes').'</label>'.
11464: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11465: '<td>'.$item->[0].'</td>';
11466: if ($item->[2]) {
11467: $duplicates .= '<td>'.&mt('Directory').'</td>';
11468: } else {
11469: $duplicates .= '<td>'.&mt('File').'</td>';
11470: }
11471: $duplicates .= '<td>'.$item->[3].'</td>'.
11472: '<td>'.
11473: &Apache::lonlocal::locallocaltime($item->[4]).
11474: '</td>'.
11475: &end_data_table_row();
11476: $num ++;
11477: }
11478: }
11479: }
11480: }
11481: my $itemcount;
11482: if (@paths > 0) {
11483: $itemcount = scalar(@paths);
11484: } else {
11485: $itemcount = 1;
11486: }
1.1067 raeburn 11487: if ($is_camtasia) {
11488: $output .= $lt{'auto'}.'<br />'.
11489: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 11490: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11491: $lt{'yes'}.'</label> <label>'.
11492: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11493: $lt{'no'}.'</label></span><br />'.
11494: '<div id="camtasia_titles" style="display:block">'.
11495: &Apache::lonhtmlcommon::start_pick_box().
11496: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11497: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11498: &Apache::lonhtmlcommon::row_closure().
11499: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11500: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11501: &Apache::lonhtmlcommon::row_closure(1).
11502: &Apache::lonhtmlcommon::end_pick_box().
11503: '</div>';
11504: }
1.1065 raeburn 11505: $output .=
11506: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11507: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11508: "\n";
1.1065 raeburn 11509: if ($duplicates ne '') {
11510: $output .= '<p><span class="LC_warning">'.
11511: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11512: &start_data_table().
11513: &start_data_table_header_row().
11514: '<th>'.&mt('Overwrite?').'</th>'.
11515: '<th>'.&mt('Name').'</th>'.
11516: '<th>'.&mt('Type').'</th>'.
11517: '<th>'.&mt('Size').'</th>'.
11518: '<th>'.&mt('Last modified').'</th>'.
11519: &end_data_table_header_row().
11520: $duplicates.
11521: &end_data_table().
11522: '</p>';
11523: }
1.1067 raeburn 11524: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11525: if (ref($hiddenelements) eq 'HASH') {
11526: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11527: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11528: }
11529: }
11530: $output .= <<"END";
1.1067 raeburn 11531: <br />
1.1053 raeburn 11532: <input type="submit" name="decompress" value="$lt{'extr'}" />
11533: </form>
11534: $noextract
11535: END
11536: return $output;
11537: }
11538:
1.1065 raeburn 11539: sub decompression_utility {
11540: my ($program) = @_;
11541: my @utilities = ('tar','gunzip','bunzip2','unzip');
11542: my $location;
11543: if (grep(/^\Q$program\E$/,@utilities)) {
11544: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11545: '/usr/sbin/') {
11546: if (-x $dir.$program) {
11547: $location = $dir.$program;
11548: last;
11549: }
11550: }
11551: }
11552: return $location;
11553: }
11554:
11555: sub list_archive_contents {
11556: my ($file,$pathsref) = @_;
11557: my (@cmd,$output);
11558: my $needsregexp;
11559: if ($file =~ /\.zip$/) {
11560: @cmd = (&decompression_utility('unzip'),"-l");
11561: $needsregexp = 1;
11562: } elsif (($file =~ m/\.tar\.gz$/) ||
11563: ($file =~ /\.tgz$/)) {
11564: @cmd = (&decompression_utility('tar'),"-ztf");
11565: } elsif ($file =~ /\.tar\.bz2$/) {
11566: @cmd = (&decompression_utility('tar'),"-jtf");
11567: } elsif ($file =~ m|\.tar$|) {
11568: @cmd = (&decompression_utility('tar'),"-tf");
11569: }
11570: if (@cmd) {
11571: undef($!);
11572: undef($@);
11573: if (open(my $fh,"-|", @cmd, $file)) {
11574: while (my $line = <$fh>) {
11575: $output .= $line;
11576: chomp($line);
11577: my $item;
11578: if ($needsregexp) {
11579: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11580: } else {
11581: $item = $line;
11582: }
11583: if ($item ne '') {
11584: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11585: push(@{$pathsref},$item);
11586: }
11587: }
11588: }
11589: close($fh);
11590: }
11591: }
11592: return $output;
11593: }
11594:
1.1053 raeburn 11595: sub decompress_uploaded_file {
11596: my ($file,$dir) = @_;
11597: &Apache::lonnet::appenv({'cgi.file' => $file});
11598: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11599: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11600: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11601: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11602: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11603: my $decompressed = $env{'cgi.decompressed'};
11604: &Apache::lonnet::delenv('cgi.file');
11605: &Apache::lonnet::delenv('cgi.dir');
11606: &Apache::lonnet::delenv('cgi.decompressed');
11607: return ($decompressed,$result);
11608: }
11609:
1.1055 raeburn 11610: sub process_decompression {
11611: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11612: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 11613: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 11614: $error = &mt('Filename not a supported archive file type.').
11615: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11616: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11617: } else {
11618: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11619: if ($docuhome eq 'no_host') {
11620: $error = &mt('Could not determine home server for course.');
11621: } else {
11622: my @ids=&Apache::lonnet::current_machine_ids();
11623: my $currdir = "$dir_root/$destination";
11624: if (grep(/^\Q$docuhome\E$/,@ids)) {
11625: $dir = &LONCAPA::propath($docudom,$docuname).
11626: "$dir_root/$destination";
11627: } else {
11628: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11629: "$dir_root/$docudom/$docuname/$destination";
11630: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11631: $error = &mt('Archive file not found.');
11632: }
11633: }
1.1065 raeburn 11634: my (@to_overwrite,@to_skip);
11635: if ($env{'form.archive_overwrite_total'} > 0) {
11636: my $total = $env{'form.archive_overwrite_total'};
11637: for (my $i=0; $i<$total; $i++) {
11638: if ($env{'form.archive_overwrite_'.$i} == 1) {
11639: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11640: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11641: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11642: }
11643: }
11644: }
11645: my $numskip = scalar(@to_skip);
11646: if (($numskip > 0) &&
11647: ($numskip == $env{'form.archive_itemcount'})) {
11648: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11649: } elsif ($dir eq '') {
1.1055 raeburn 11650: $error = &mt('Directory containing archive file unavailable.');
11651: } elsif (!$error) {
1.1065 raeburn 11652: my ($decompressed,$display);
11653: if ($numskip > 0) {
11654: my $tempdir = time.'_'.$$.int(rand(10000));
11655: mkdir("$dir/$tempdir",0755);
11656: system("mv $dir/$file $dir/$tempdir/$file");
11657: ($decompressed,$display) =
11658: &decompress_uploaded_file($file,"$dir/$tempdir");
11659: foreach my $item (@to_skip) {
11660: if (($item ne '') && ($item !~ /\.\./)) {
11661: if (-f "$dir/$tempdir/$item") {
11662: unlink("$dir/$tempdir/$item");
11663: } elsif (-d "$dir/$tempdir/$item") {
11664: system("rm -rf $dir/$tempdir/$item");
11665: }
11666: }
11667: }
11668: system("mv $dir/$tempdir/* $dir");
11669: rmdir("$dir/$tempdir");
11670: } else {
11671: ($decompressed,$display) =
11672: &decompress_uploaded_file($file,$dir);
11673: }
1.1055 raeburn 11674: if ($decompressed eq 'ok') {
1.1065 raeburn 11675: $output = '<p class="LC_info">'.
11676: &mt('Files extracted successfully from archive.').
11677: '</p>'."\n";
1.1055 raeburn 11678: my ($warning,$result,@contents);
11679: my ($newdirlistref,$newlisterror) =
11680: &Apache::lonnet::dirlist($currdir,$docudom,
11681: $docuname,1);
11682: my (%is_dir,%changes,@newitems);
11683: my $dirptr = 16384;
1.1065 raeburn 11684: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11685: foreach my $dir_line (@{$newdirlistref}) {
11686: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11687: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11688: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11689: push(@newitems,$item);
11690: if ($dirptr&$testdir) {
11691: $is_dir{$item} = 1;
11692: }
11693: $changes{$item} = 1;
11694: }
11695: }
11696: }
11697: if (keys(%changes) > 0) {
11698: foreach my $item (sort(@newitems)) {
11699: if ($changes{$item}) {
11700: push(@contents,$item);
11701: }
11702: }
11703: }
11704: if (@contents > 0) {
1.1067 raeburn 11705: my $wantform;
11706: unless ($env{'form.autoextract_camtasia'}) {
11707: $wantform = 1;
11708: }
1.1056 raeburn 11709: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11710: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11711: $currdir,\%is_dir,
11712: \%children,\%parent,
1.1056 raeburn 11713: \@contents,\%dirorder,
11714: \%titles,$wantform);
1.1055 raeburn 11715: if ($datatable ne '') {
11716: $output .= &archive_options_form('decompressed',$datatable,
11717: $count,$hiddenelem);
1.1065 raeburn 11718: my $startcount = 6;
1.1055 raeburn 11719: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11720: \%titles,\%children);
1.1055 raeburn 11721: }
1.1067 raeburn 11722: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 11723: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 11724: my %displayed;
11725: my $total = 1;
11726: $env{'form.archive_directory'} = [];
11727: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11728: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11729: $path =~ s{/$}{};
11730: my $item;
11731: if ($path ne '') {
11732: $item = "$path/$titles{$i}";
11733: } else {
11734: $item = $titles{$i};
11735: }
11736: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11737: if ($item eq $contents[0]) {
11738: push(@{$env{'form.archive_directory'}},$i);
11739: $env{'form.archive_'.$i} = 'display';
11740: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11741: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 11742: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
11743: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 11744: $env{'form.archive_'.$i} = 'display';
11745: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11746: $displayed{'web'} = $i;
11747: } else {
1.1075.2.59 raeburn 11748: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
11749: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
11750: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 11751: push(@{$env{'form.archive_directory'}},$i);
11752: }
11753: $env{'form.archive_'.$i} = 'dependency';
11754: }
11755: $total ++;
11756: }
11757: for (my $i=1; $i<$total; $i++) {
11758: next if ($i == $displayed{'web'});
11759: next if ($i == $displayed{'folder'});
11760: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11761: }
11762: $env{'form.phase'} = 'decompress_cleanup';
11763: $env{'form.archivedelete'} = 1;
11764: $env{'form.archive_count'} = $total-1;
11765: $output .=
11766: &process_extracted_files('coursedocs',$docudom,
11767: $docuname,$destination,
11768: $dir_root,$hiddenelem);
11769: }
1.1055 raeburn 11770: } else {
11771: $warning = &mt('No new items extracted from archive file.');
11772: }
11773: } else {
11774: $output = $display;
11775: $error = &mt('An error occurred during extraction from the archive file.');
11776: }
11777: }
11778: }
11779: }
11780: if ($error) {
11781: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11782: $error.'</p>'."\n";
11783: }
11784: if ($warning) {
11785: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11786: }
11787: return $output;
11788: }
11789:
11790: sub get_extracted {
1.1056 raeburn 11791: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11792: $titles,$wantform) = @_;
1.1055 raeburn 11793: my $count = 0;
11794: my $depth = 0;
11795: my $datatable;
1.1056 raeburn 11796: my @hierarchy;
1.1055 raeburn 11797: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11798: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11799: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11800: foreach my $item (@{$contents}) {
11801: $count ++;
1.1056 raeburn 11802: @{$dirorder->{$count}} = @hierarchy;
11803: $titles->{$count} = $item;
1.1055 raeburn 11804: &archive_hierarchy($depth,$count,$parent,$children);
11805: if ($wantform) {
11806: $datatable .= &archive_row($is_dir->{$item},$item,
11807: $currdir,$depth,$count);
11808: }
11809: if ($is_dir->{$item}) {
11810: $depth ++;
1.1056 raeburn 11811: push(@hierarchy,$count);
11812: $parent->{$depth} = $count;
1.1055 raeburn 11813: $datatable .=
11814: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11815: \$depth,\$count,\@hierarchy,$dirorder,
11816: $children,$parent,$titles,$wantform);
1.1055 raeburn 11817: $depth --;
1.1056 raeburn 11818: pop(@hierarchy);
1.1055 raeburn 11819: }
11820: }
11821: return ($count,$datatable);
11822: }
11823:
11824: sub recurse_extracted_archive {
1.1056 raeburn 11825: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11826: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11827: my $result='';
1.1056 raeburn 11828: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11829: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11830: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11831: return $result;
11832: }
11833: my $dirptr = 16384;
11834: my ($newdirlistref,$newlisterror) =
11835: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11836: if (ref($newdirlistref) eq 'ARRAY') {
11837: foreach my $dir_line (@{$newdirlistref}) {
11838: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11839: unless ($item =~ /^\.+$/) {
11840: $$count ++;
1.1056 raeburn 11841: @{$dirorder->{$$count}} = @{$hierarchy};
11842: $titles->{$$count} = $item;
1.1055 raeburn 11843: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11844:
1.1055 raeburn 11845: my $is_dir;
11846: if ($dirptr&$testdir) {
11847: $is_dir = 1;
11848: }
11849: if ($wantform) {
11850: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11851: }
11852: if ($is_dir) {
11853: $$depth ++;
1.1056 raeburn 11854: push(@{$hierarchy},$$count);
11855: $parent->{$$depth} = $$count;
1.1055 raeburn 11856: $result .=
11857: &recurse_extracted_archive("$currdir/$item",$docudom,
11858: $docuname,$depth,$count,
1.1056 raeburn 11859: $hierarchy,$dirorder,$children,
11860: $parent,$titles,$wantform);
1.1055 raeburn 11861: $$depth --;
1.1056 raeburn 11862: pop(@{$hierarchy});
1.1055 raeburn 11863: }
11864: }
11865: }
11866: }
11867: return $result;
11868: }
11869:
11870: sub archive_hierarchy {
11871: my ($depth,$count,$parent,$children) =@_;
11872: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11873: if (exists($parent->{$depth})) {
11874: $children->{$parent->{$depth}} .= $count.':';
11875: }
11876: }
11877: return;
11878: }
11879:
11880: sub archive_row {
11881: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11882: my ($name) = ($item =~ m{([^/]+)$});
11883: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11884: 'display' => 'Add as file',
1.1055 raeburn 11885: 'dependency' => 'Include as dependency',
11886: 'discard' => 'Discard',
11887: );
11888: if ($is_dir) {
1.1059 raeburn 11889: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11890: }
1.1056 raeburn 11891: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11892: my $offset = 0;
1.1055 raeburn 11893: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11894: $offset ++;
1.1065 raeburn 11895: if ($action ne 'display') {
11896: $offset ++;
11897: }
1.1055 raeburn 11898: $output .= '<td><span class="LC_nobreak">'.
11899: '<label><input type="radio" name="archive_'.$count.
11900: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11901: my $text = $choices{$action};
11902: if ($is_dir) {
11903: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11904: if ($action eq 'display') {
1.1059 raeburn 11905: $text = &mt('Add as folder');
1.1055 raeburn 11906: }
1.1056 raeburn 11907: } else {
11908: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11909:
11910: }
11911: $output .= ' /> '.$choices{$action}.'</label></span>';
11912: if ($action eq 'dependency') {
11913: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11914: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11915: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11916: '<option value=""></option>'."\n".
11917: '</select>'."\n".
11918: '</div>';
1.1059 raeburn 11919: } elsif ($action eq 'display') {
11920: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11921: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11922: '</div>';
1.1055 raeburn 11923: }
1.1056 raeburn 11924: $output .= '</td>';
1.1055 raeburn 11925: }
11926: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11927: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11928: for (my $i=0; $i<$depth; $i++) {
11929: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11930: }
11931: if ($is_dir) {
11932: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11933: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11934: } else {
11935: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11936: }
11937: $output .= ' '.$name.'</td>'."\n".
11938: &end_data_table_row();
11939: return $output;
11940: }
11941:
11942: sub archive_options_form {
1.1065 raeburn 11943: my ($form,$display,$count,$hiddenelem) = @_;
11944: my %lt = &Apache::lonlocal::texthash(
11945: perm => 'Permanently remove archive file?',
11946: hows => 'How should each extracted item be incorporated in the course?',
11947: cont => 'Content actions for all',
11948: addf => 'Add as folder/file',
11949: incd => 'Include as dependency for a displayed file',
11950: disc => 'Discard',
11951: no => 'No',
11952: yes => 'Yes',
11953: save => 'Save',
11954: );
11955: my $output = <<"END";
11956: <form name="$form" method="post" action="">
11957: <p><span class="LC_nobreak">$lt{'perm'}
11958: <label>
11959: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11960: </label>
11961:
11962: <label>
11963: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11964: </span>
11965: </p>
11966: <input type="hidden" name="phase" value="decompress_cleanup" />
11967: <br />$lt{'hows'}
11968: <div class="LC_columnSection">
11969: <fieldset>
11970: <legend>$lt{'cont'}</legend>
11971: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11972: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11973: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11974: </fieldset>
11975: </div>
11976: END
11977: return $output.
1.1055 raeburn 11978: &start_data_table()."\n".
1.1065 raeburn 11979: $display."\n".
1.1055 raeburn 11980: &end_data_table()."\n".
11981: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11982: $hiddenelem.
1.1065 raeburn 11983: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11984: '</form>';
11985: }
11986:
11987: sub archive_javascript {
1.1056 raeburn 11988: my ($startcount,$numitems,$titles,$children) = @_;
11989: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11990: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11991: my $scripttag = <<START;
11992: <script type="text/javascript">
11993: // <![CDATA[
11994:
11995: function checkAll(form,prefix) {
11996: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11997: for (var i=0; i < form.elements.length; i++) {
11998: var id = form.elements[i].id;
11999: if ((id != '') && (id != undefined)) {
12000: if (idstr.test(id)) {
12001: if (form.elements[i].type == 'radio') {
12002: form.elements[i].checked = true;
1.1056 raeburn 12003: var nostart = i-$startcount;
1.1059 raeburn 12004: var offset = nostart%7;
12005: var count = (nostart-offset)/7;
1.1056 raeburn 12006: dependencyCheck(form,count,offset);
1.1055 raeburn 12007: }
12008: }
12009: }
12010: }
12011: }
12012:
12013: function propagateCheck(form,count) {
12014: if (count > 0) {
1.1059 raeburn 12015: var startelement = $startcount + ((count-1) * 7);
12016: for (var j=1; j<6; j++) {
12017: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12018: var item = startelement + j;
12019: if (form.elements[item].type == 'radio') {
12020: if (form.elements[item].checked) {
12021: containerCheck(form,count,j);
12022: break;
12023: }
1.1055 raeburn 12024: }
12025: }
12026: }
12027: }
12028: }
12029:
12030: numitems = $numitems
1.1056 raeburn 12031: var titles = new Array(numitems);
12032: var parents = new Array(numitems);
1.1055 raeburn 12033: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12034: parents[i] = new Array;
1.1055 raeburn 12035: }
1.1059 raeburn 12036: var maintitle = '$maintitle';
1.1055 raeburn 12037:
12038: START
12039:
1.1056 raeburn 12040: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12041: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12042: for (my $i=0; $i<@contents; $i ++) {
12043: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12044: }
12045: }
12046:
1.1056 raeburn 12047: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12048: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12049: }
12050:
1.1055 raeburn 12051: $scripttag .= <<END;
12052:
12053: function containerCheck(form,count,offset) {
12054: if (count > 0) {
1.1056 raeburn 12055: dependencyCheck(form,count,offset);
1.1059 raeburn 12056: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12057: form.elements[item].checked = true;
12058: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12059: if (parents[count].length > 0) {
12060: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12061: containerCheck(form,parents[count][j],offset);
12062: }
12063: }
12064: }
12065: }
12066: }
12067:
12068: function dependencyCheck(form,count,offset) {
12069: if (count > 0) {
1.1059 raeburn 12070: var chosen = (offset+$startcount)+7*(count-1);
12071: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12072: var currtype = form.elements[depitem].type;
12073: if (form.elements[chosen].value == 'dependency') {
12074: document.getElementById('arc_depon_'+count).style.display='block';
12075: form.elements[depitem].options.length = 0;
12076: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12077: for (var i=1; i<=numitems; i++) {
12078: if (i == count) {
12079: continue;
12080: }
1.1059 raeburn 12081: var startelement = $startcount + (i-1) * 7;
12082: for (var j=1; j<6; j++) {
12083: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12084: var item = startelement + j;
12085: if (form.elements[item].type == 'radio') {
12086: if (form.elements[item].checked) {
12087: if (form.elements[item].value == 'display') {
12088: var n = form.elements[depitem].options.length;
12089: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12090: }
12091: }
12092: }
12093: }
12094: }
12095: }
12096: } else {
12097: document.getElementById('arc_depon_'+count).style.display='none';
12098: form.elements[depitem].options.length = 0;
12099: form.elements[depitem].options[0] = new Option('Select','',true,true);
12100: }
1.1059 raeburn 12101: titleCheck(form,count,offset);
1.1056 raeburn 12102: }
12103: }
12104:
12105: function propagateSelect(form,count,offset) {
12106: if (count > 0) {
1.1065 raeburn 12107: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12108: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12109: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12110: if (parents[count].length > 0) {
12111: for (var j=0; j<parents[count].length; j++) {
12112: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12113: }
12114: }
12115: }
12116: }
12117: }
1.1056 raeburn 12118:
12119: function containerSelect(form,count,offset,picked) {
12120: if (count > 0) {
1.1065 raeburn 12121: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12122: if (form.elements[item].type == 'radio') {
12123: if (form.elements[item].value == 'dependency') {
12124: if (form.elements[item+1].type == 'select-one') {
12125: for (var i=0; i<form.elements[item+1].options.length; i++) {
12126: if (form.elements[item+1].options[i].value == picked) {
12127: form.elements[item+1].selectedIndex = i;
12128: break;
12129: }
12130: }
12131: }
12132: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12133: if (parents[count].length > 0) {
12134: for (var j=0; j<parents[count].length; j++) {
12135: containerSelect(form,parents[count][j],offset,picked);
12136: }
12137: }
12138: }
12139: }
12140: }
12141: }
12142: }
12143:
1.1059 raeburn 12144: function titleCheck(form,count,offset) {
12145: if (count > 0) {
12146: var chosen = (offset+$startcount)+7*(count-1);
12147: var depitem = $startcount + ((count-1) * 7) + 2;
12148: var currtype = form.elements[depitem].type;
12149: if (form.elements[chosen].value == 'display') {
12150: document.getElementById('arc_title_'+count).style.display='block';
12151: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12152: document.getElementById('archive_title_'+count).value=maintitle;
12153: }
12154: } else {
12155: document.getElementById('arc_title_'+count).style.display='none';
12156: if (currtype == 'text') {
12157: document.getElementById('archive_title_'+count).value='';
12158: }
12159: }
12160: }
12161: return;
12162: }
12163:
1.1055 raeburn 12164: // ]]>
12165: </script>
12166: END
12167: return $scripttag;
12168: }
12169:
12170: sub process_extracted_files {
1.1067 raeburn 12171: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12172: my $numitems = $env{'form.archive_count'};
12173: return unless ($numitems);
12174: my @ids=&Apache::lonnet::current_machine_ids();
12175: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12176: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12177: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12178: if (grep(/^\Q$docuhome\E$/,@ids)) {
12179: $prefix = &LONCAPA::propath($docudom,$docuname);
12180: $pathtocheck = "$dir_root/$destination";
12181: $dir = $dir_root;
12182: $ishome = 1;
12183: } else {
12184: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12185: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
12186: $dir = "$dir_root/$docudom/$docuname";
12187: }
12188: my $currdir = "$dir_root/$destination";
12189: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12190: if ($env{'form.folderpath'}) {
12191: my @items = split('&',$env{'form.folderpath'});
12192: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 12193: if ($env{'form.folderpath'} =~ /\:1$/) {
12194: $containers{'0'}='page';
12195: } else {
12196: $containers{'0'}='sequence';
12197: }
1.1055 raeburn 12198: }
12199: my @archdirs = &get_env_multiple('form.archive_directory');
12200: if ($numitems) {
12201: for (my $i=1; $i<=$numitems; $i++) {
12202: my $path = $env{'form.archive_content_'.$i};
12203: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12204: my $item = $1;
12205: $toplevelitems{$item} = $i;
12206: if (grep(/^\Q$i\E$/,@archdirs)) {
12207: $is_dir{$item} = 1;
12208: }
12209: }
12210: }
12211: }
1.1067 raeburn 12212: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12213: if (keys(%toplevelitems) > 0) {
12214: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12215: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12216: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12217: }
1.1066 raeburn 12218: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12219: if ($numitems) {
12220: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 12221: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12222: my $path = $env{'form.archive_content_'.$i};
12223: if ($path =~ /^\Q$pathtocheck\E/) {
12224: if ($env{'form.archive_'.$i} eq 'discard') {
12225: if ($prefix ne '' && $path ne '') {
12226: if (-e $prefix.$path) {
1.1066 raeburn 12227: if ((@archdirs > 0) &&
12228: (grep(/^\Q$i\E$/,@archdirs))) {
12229: $todeletedir{$prefix.$path} = 1;
12230: } else {
12231: $todelete{$prefix.$path} = 1;
12232: }
1.1055 raeburn 12233: }
12234: }
12235: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12236: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12237: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12238: $docstitle = $env{'form.archive_title_'.$i};
12239: if ($docstitle eq '') {
12240: $docstitle = $title;
12241: }
1.1055 raeburn 12242: $outer = 0;
1.1056 raeburn 12243: if (ref($dirorder{$i}) eq 'ARRAY') {
12244: if (@{$dirorder{$i}} > 0) {
12245: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12246: if ($env{'form.archive_'.$item} eq 'display') {
12247: $outer = $item;
12248: last;
12249: }
12250: }
12251: }
12252: }
12253: my ($errtext,$fatal) =
12254: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12255: '/'.$folders{$outer}.'.'.
12256: $containers{$outer});
12257: next if ($fatal);
12258: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12259: if ($context eq 'coursedocs') {
1.1056 raeburn 12260: $mapinner{$i} = time;
1.1055 raeburn 12261: $folders{$i} = 'default_'.$mapinner{$i};
12262: $containers{$i} = 'sequence';
12263: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12264: $folders{$i}.'.'.$containers{$i};
12265: my $newidx = &LONCAPA::map::getresidx();
12266: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12267: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12268: push(@LONCAPA::map::order,$newidx);
12269: my ($outtext,$errtext) =
12270: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12271: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12272: '.'.$containers{$outer},1,1);
1.1056 raeburn 12273: $newseqid{$i} = $newidx;
1.1067 raeburn 12274: unless ($errtext) {
12275: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
12276: }
1.1055 raeburn 12277: }
12278: } else {
12279: if ($context eq 'coursedocs') {
12280: my $newidx=&LONCAPA::map::getresidx();
12281: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12282: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12283: $title;
12284: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12285: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
12286: }
12287: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12288: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12289: }
12290: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12291: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 12292: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 12293: unless ($ishome) {
12294: my $fetch = "$newdest{$i}/$title";
12295: $fetch =~ s/^\Q$prefix$dir\E//;
12296: $prompttofetch{$fetch} = 1;
12297: }
1.1055 raeburn 12298: }
12299: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12300: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12301: push(@LONCAPA::map::order, $newidx);
12302: my ($outtext,$errtext)=
12303: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12304: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12305: '.'.$containers{$outer},1,1);
1.1067 raeburn 12306: unless ($errtext) {
12307: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
12308: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
12309: }
12310: }
1.1055 raeburn 12311: }
12312: }
1.1075.2.11 raeburn 12313: }
12314: } else {
12315: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12316: }
12317: }
12318: for (my $i=1; $i<=$numitems; $i++) {
12319: next unless ($env{'form.archive_'.$i} eq 'dependency');
12320: my $path = $env{'form.archive_content_'.$i};
12321: if ($path =~ /^\Q$pathtocheck\E/) {
12322: my ($title) = ($path =~ m{/([^/]+)$});
12323: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12324: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12325: if (ref($dirorder{$i}) eq 'ARRAY') {
12326: my ($itemidx,$fullpath,$relpath);
12327: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12328: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12329: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 12330: if ($dirorder{$i}->[$j] eq $container) {
12331: $itemidx = $j;
1.1056 raeburn 12332: }
12333: }
1.1075.2.11 raeburn 12334: }
12335: if ($itemidx eq '') {
12336: $itemidx = 0;
12337: }
12338: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12339: if ($mapinner{$referrer{$i}}) {
12340: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12341: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12342: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12343: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12344: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12345: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12346: if (!-e $fullpath) {
12347: mkdir($fullpath,0755);
1.1056 raeburn 12348: }
12349: }
1.1075.2.11 raeburn 12350: } else {
12351: last;
1.1056 raeburn 12352: }
1.1075.2.11 raeburn 12353: }
12354: }
12355: } elsif ($newdest{$referrer{$i}}) {
12356: $fullpath = $newdest{$referrer{$i}};
12357: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12358: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12359: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12360: last;
12361: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12362: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12363: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12364: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12365: if (!-e $fullpath) {
12366: mkdir($fullpath,0755);
1.1056 raeburn 12367: }
12368: }
1.1075.2.11 raeburn 12369: } else {
12370: last;
1.1056 raeburn 12371: }
1.1075.2.11 raeburn 12372: }
12373: }
12374: if ($fullpath ne '') {
12375: if (-e "$prefix$path") {
12376: system("mv $prefix$path $fullpath/$title");
12377: }
12378: if (-e "$fullpath/$title") {
12379: my $showpath;
12380: if ($relpath ne '') {
12381: $showpath = "$relpath/$title";
12382: } else {
12383: $showpath = "/$title";
1.1056 raeburn 12384: }
1.1075.2.11 raeburn 12385: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12386: }
12387: unless ($ishome) {
12388: my $fetch = "$fullpath/$title";
12389: $fetch =~ s/^\Q$prefix$dir\E//;
12390: $prompttofetch{$fetch} = 1;
1.1055 raeburn 12391: }
12392: }
12393: }
1.1075.2.11 raeburn 12394: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12395: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12396: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12397: }
12398: } else {
1.1075.2.11 raeburn 12399: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055 raeburn 12400: }
12401: }
12402: if (keys(%todelete)) {
12403: foreach my $key (keys(%todelete)) {
12404: unlink($key);
1.1066 raeburn 12405: }
12406: }
12407: if (keys(%todeletedir)) {
12408: foreach my $key (keys(%todeletedir)) {
12409: rmdir($key);
12410: }
12411: }
12412: foreach my $dir (sort(keys(%is_dir))) {
12413: if (($pathtocheck ne '') && ($dir ne '')) {
12414: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12415: }
12416: }
1.1067 raeburn 12417: if ($result ne '') {
12418: $output .= '<ul>'."\n".
12419: $result."\n".
12420: '</ul>';
12421: }
12422: unless ($ishome) {
12423: my $replicationfail;
12424: foreach my $item (keys(%prompttofetch)) {
12425: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12426: unless ($fetchresult eq 'ok') {
12427: $replicationfail .= '<li>'.$item.'</li>'."\n";
12428: }
12429: }
12430: if ($replicationfail) {
12431: $output .= '<p class="LC_error">'.
12432: &mt('Course home server failed to retrieve:').'<ul>'.
12433: $replicationfail.
12434: '</ul></p>';
12435: }
12436: }
1.1055 raeburn 12437: } else {
12438: $warning = &mt('No items found in archive.');
12439: }
12440: if ($error) {
12441: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12442: $error.'</p>'."\n";
12443: }
12444: if ($warning) {
12445: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12446: }
12447: return $output;
12448: }
12449:
1.1066 raeburn 12450: sub cleanup_empty_dirs {
12451: my ($path) = @_;
12452: if (($path ne '') && (-d $path)) {
12453: if (opendir(my $dirh,$path)) {
12454: my @dircontents = grep(!/^\./,readdir($dirh));
12455: my $numitems = 0;
12456: foreach my $item (@dircontents) {
12457: if (-d "$path/$item") {
1.1075.2.28 raeburn 12458: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12459: if (-e "$path/$item") {
12460: $numitems ++;
12461: }
12462: } else {
12463: $numitems ++;
12464: }
12465: }
12466: if ($numitems == 0) {
12467: rmdir($path);
12468: }
12469: closedir($dirh);
12470: }
12471: }
12472: return;
12473: }
12474:
1.41 ng 12475: =pod
1.45 matthew 12476:
1.1075.2.56 raeburn 12477: =item * &get_folder_hierarchy()
1.1068 raeburn 12478:
12479: Provides hierarchy of names of folders/sub-folders containing the current
12480: item,
12481:
12482: Inputs: 3
12483: - $navmap - navmaps object
12484:
12485: - $map - url for map (either the trigger itself, or map containing
12486: the resource, which is the trigger).
12487:
12488: - $showitem - 1 => show title for map itself; 0 => do not show.
12489:
12490: Outputs: 1 @pathitems - array of folder/subfolder names.
12491:
12492: =cut
12493:
12494: sub get_folder_hierarchy {
12495: my ($navmap,$map,$showitem) = @_;
12496: my @pathitems;
12497: if (ref($navmap)) {
12498: my $mapres = $navmap->getResourceByUrl($map);
12499: if (ref($mapres)) {
12500: my $pcslist = $mapres->map_hierarchy();
12501: if ($pcslist ne '') {
12502: my @pcs = split(/,/,$pcslist);
12503: foreach my $pc (@pcs) {
12504: if ($pc == 1) {
1.1075.2.38 raeburn 12505: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12506: } else {
12507: my $res = $navmap->getByMapPc($pc);
12508: if (ref($res)) {
12509: my $title = $res->compTitle();
12510: $title =~ s/\W+/_/g;
12511: if ($title ne '') {
12512: push(@pathitems,$title);
12513: }
12514: }
12515: }
12516: }
12517: }
1.1071 raeburn 12518: if ($showitem) {
12519: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 12520: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12521: } else {
12522: my $maptitle = $mapres->compTitle();
12523: $maptitle =~ s/\W+/_/g;
12524: if ($maptitle ne '') {
12525: push(@pathitems,$maptitle);
12526: }
1.1068 raeburn 12527: }
12528: }
12529: }
12530: }
12531: return @pathitems;
12532: }
12533:
12534: =pod
12535:
1.1015 raeburn 12536: =item * &get_turnedin_filepath()
12537:
12538: Determines path in a user's portfolio file for storage of files uploaded
12539: to a specific essayresponse or dropbox item.
12540:
12541: Inputs: 3 required + 1 optional.
12542: $symb is symb for resource, $uname and $udom are for current user (required).
12543: $caller is optional (can be "submission", if routine is called when storing
12544: an upoaded file when "Submit Answer" button was pressed).
12545:
12546: Returns array containing $path and $multiresp.
12547: $path is path in portfolio. $multiresp is 1 if this resource contains more
12548: than one file upload item. Callers of routine should append partid as a
12549: subdirectory to $path in cases where $multiresp is 1.
12550:
12551: Called by: homework/essayresponse.pm and homework/structuretags.pm
12552:
12553: =cut
12554:
12555: sub get_turnedin_filepath {
12556: my ($symb,$uname,$udom,$caller) = @_;
12557: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12558: my $turnindir;
12559: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12560: $turnindir = $userhash{'turnindir'};
12561: my ($path,$multiresp);
12562: if ($turnindir eq '') {
12563: if ($caller eq 'submission') {
12564: $turnindir = &mt('turned in');
12565: $turnindir =~ s/\W+/_/g;
12566: my %newhash = (
12567: 'turnindir' => $turnindir,
12568: );
12569: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12570: }
12571: }
12572: if ($turnindir ne '') {
12573: $path = '/'.$turnindir.'/';
12574: my ($multipart,$turnin,@pathitems);
12575: my $navmap = Apache::lonnavmaps::navmap->new();
12576: if (defined($navmap)) {
12577: my $mapres = $navmap->getResourceByUrl($map);
12578: if (ref($mapres)) {
12579: my $pcslist = $mapres->map_hierarchy();
12580: if ($pcslist ne '') {
12581: foreach my $pc (split(/,/,$pcslist)) {
12582: my $res = $navmap->getByMapPc($pc);
12583: if (ref($res)) {
12584: my $title = $res->compTitle();
12585: $title =~ s/\W+/_/g;
12586: if ($title ne '') {
1.1075.2.48 raeburn 12587: if (($pc > 1) && (length($title) > 12)) {
12588: $title = substr($title,0,12);
12589: }
1.1015 raeburn 12590: push(@pathitems,$title);
12591: }
12592: }
12593: }
12594: }
12595: my $maptitle = $mapres->compTitle();
12596: $maptitle =~ s/\W+/_/g;
12597: if ($maptitle ne '') {
1.1075.2.48 raeburn 12598: if (length($maptitle) > 12) {
12599: $maptitle = substr($maptitle,0,12);
12600: }
1.1015 raeburn 12601: push(@pathitems,$maptitle);
12602: }
12603: unless ($env{'request.state'} eq 'construct') {
12604: my $res = $navmap->getBySymb($symb);
12605: if (ref($res)) {
12606: my $partlist = $res->parts();
12607: my $totaluploads = 0;
12608: if (ref($partlist) eq 'ARRAY') {
12609: foreach my $part (@{$partlist}) {
12610: my @types = $res->responseType($part);
12611: my @ids = $res->responseIds($part);
12612: for (my $i=0; $i < scalar(@ids); $i++) {
12613: if ($types[$i] eq 'essay') {
12614: my $partid = $part.'_'.$ids[$i];
12615: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12616: $totaluploads ++;
12617: }
12618: }
12619: }
12620: }
12621: if ($totaluploads > 1) {
12622: $multiresp = 1;
12623: }
12624: }
12625: }
12626: }
12627: } else {
12628: return;
12629: }
12630: } else {
12631: return;
12632: }
12633: my $restitle=&Apache::lonnet::gettitle($symb);
12634: $restitle =~ s/\W+/_/g;
12635: if ($restitle eq '') {
12636: $restitle = ($resurl =~ m{/[^/]+$});
12637: if ($restitle eq '') {
12638: $restitle = time;
12639: }
12640: }
1.1075.2.48 raeburn 12641: if (length($restitle) > 12) {
12642: $restitle = substr($restitle,0,12);
12643: }
1.1015 raeburn 12644: push(@pathitems,$restitle);
12645: $path .= join('/',@pathitems);
12646: }
12647: return ($path,$multiresp);
12648: }
12649:
12650: =pod
12651:
1.464 albertel 12652: =back
1.41 ng 12653:
1.112 bowersj2 12654: =head1 CSV Upload/Handling functions
1.38 albertel 12655:
1.41 ng 12656: =over 4
12657:
1.648 raeburn 12658: =item * &upfile_store($r)
1.41 ng 12659:
12660: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12661: needs $env{'form.upfile'}
1.41 ng 12662: returns $datatoken to be put into hidden field
12663:
12664: =cut
1.31 albertel 12665:
12666: sub upfile_store {
12667: my $r=shift;
1.258 albertel 12668: $env{'form.upfile'}=~s/\r/\n/gs;
12669: $env{'form.upfile'}=~s/\f/\n/gs;
12670: $env{'form.upfile'}=~s/\n+/\n/gs;
12671: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12672:
1.258 albertel 12673: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12674: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12675: {
1.158 raeburn 12676: my $datafile = $r->dir_config('lonDaemons').
12677: '/tmp/'.$datatoken.'.tmp';
12678: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12679: print $fh $env{'form.upfile'};
1.158 raeburn 12680: close($fh);
12681: }
1.31 albertel 12682: }
12683: return $datatoken;
12684: }
12685:
1.56 matthew 12686: =pod
12687:
1.648 raeburn 12688: =item * &load_tmp_file($r)
1.41 ng 12689:
12690: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12691: needs $env{'form.datatoken'},
12692: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12693:
12694: =cut
1.31 albertel 12695:
12696: sub load_tmp_file {
12697: my $r=shift;
12698: my @studentdata=();
12699: {
1.158 raeburn 12700: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12701: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12702: if ( open(my $fh,"<$studentfile") ) {
12703: @studentdata=<$fh>;
12704: close($fh);
12705: }
1.31 albertel 12706: }
1.258 albertel 12707: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12708: }
12709:
1.56 matthew 12710: =pod
12711:
1.648 raeburn 12712: =item * &upfile_record_sep()
1.41 ng 12713:
12714: Separate uploaded file into records
12715: returns array of records,
1.258 albertel 12716: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12717:
12718: =cut
1.31 albertel 12719:
12720: sub upfile_record_sep {
1.258 albertel 12721: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12722: } else {
1.248 albertel 12723: my @records;
1.258 albertel 12724: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12725: if ($line=~/^\s*$/) { next; }
12726: push(@records,$line);
12727: }
12728: return @records;
1.31 albertel 12729: }
12730: }
12731:
1.56 matthew 12732: =pod
12733:
1.648 raeburn 12734: =item * &record_sep($record)
1.41 ng 12735:
1.258 albertel 12736: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12737:
12738: =cut
12739:
1.263 www 12740: sub takeleft {
12741: my $index=shift;
12742: return substr('0000'.$index,-4,4);
12743: }
12744:
1.31 albertel 12745: sub record_sep {
12746: my $record=shift;
12747: my %components=();
1.258 albertel 12748: if ($env{'form.upfiletype'} eq 'xml') {
12749: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12750: my $i=0;
1.356 albertel 12751: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12752: $field=~s/^(\"|\')//;
12753: $field=~s/(\"|\')$//;
1.263 www 12754: $components{&takeleft($i)}=$field;
1.31 albertel 12755: $i++;
12756: }
1.258 albertel 12757: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12758: my $i=0;
1.356 albertel 12759: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12760: $field=~s/^(\"|\')//;
12761: $field=~s/(\"|\')$//;
1.263 www 12762: $components{&takeleft($i)}=$field;
1.31 albertel 12763: $i++;
12764: }
12765: } else {
1.561 www 12766: my $separator=',';
1.480 banghart 12767: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12768: $separator=';';
1.480 banghart 12769: }
1.31 albertel 12770: my $i=0;
1.561 www 12771: # the character we are looking for to indicate the end of a quote or a record
12772: my $looking_for=$separator;
12773: # do not add the characters to the fields
12774: my $ignore=0;
12775: # we just encountered a separator (or the beginning of the record)
12776: my $just_found_separator=1;
12777: # store the field we are working on here
12778: my $field='';
12779: # work our way through all characters in record
12780: foreach my $character ($record=~/(.)/g) {
12781: if ($character eq $looking_for) {
12782: if ($character ne $separator) {
12783: # Found the end of a quote, again looking for separator
12784: $looking_for=$separator;
12785: $ignore=1;
12786: } else {
12787: # Found a separator, store away what we got
12788: $components{&takeleft($i)}=$field;
12789: $i++;
12790: $just_found_separator=1;
12791: $ignore=0;
12792: $field='';
12793: }
12794: next;
12795: }
12796: # single or double quotation marks after a separator indicate beginning of a quote
12797: # we are now looking for the end of the quote and need to ignore separators
12798: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12799: $looking_for=$character;
12800: next;
12801: }
12802: # ignore would be true after we reached the end of a quote
12803: if ($ignore) { next; }
12804: if (($just_found_separator) && ($character=~/\s/)) { next; }
12805: $field.=$character;
12806: $just_found_separator=0;
1.31 albertel 12807: }
1.561 www 12808: # catch the very last entry, since we never encountered the separator
12809: $components{&takeleft($i)}=$field;
1.31 albertel 12810: }
12811: return %components;
12812: }
12813:
1.144 matthew 12814: ######################################################
12815: ######################################################
12816:
1.56 matthew 12817: =pod
12818:
1.648 raeburn 12819: =item * &upfile_select_html()
1.41 ng 12820:
1.144 matthew 12821: Return HTML code to select a file from the users machine and specify
12822: the file type.
1.41 ng 12823:
12824: =cut
12825:
1.144 matthew 12826: ######################################################
12827: ######################################################
1.31 albertel 12828: sub upfile_select_html {
1.144 matthew 12829: my %Types = (
12830: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12831: semisv => &mt('Semicolon separated values'),
1.144 matthew 12832: space => &mt('Space separated'),
12833: tab => &mt('Tabulator separated'),
12834: # xml => &mt('HTML/XML'),
12835: );
12836: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12837: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12838: foreach my $type (sort(keys(%Types))) {
12839: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12840: }
12841: $Str .= "</select>\n";
12842: return $Str;
1.31 albertel 12843: }
12844:
1.301 albertel 12845: sub get_samples {
12846: my ($records,$toget) = @_;
12847: my @samples=({});
12848: my $got=0;
12849: foreach my $rec (@$records) {
12850: my %temp = &record_sep($rec);
12851: if (! grep(/\S/, values(%temp))) { next; }
12852: if (%temp) {
12853: $samples[$got]=\%temp;
12854: $got++;
12855: if ($got == $toget) { last; }
12856: }
12857: }
12858: return \@samples;
12859: }
12860:
1.144 matthew 12861: ######################################################
12862: ######################################################
12863:
1.56 matthew 12864: =pod
12865:
1.648 raeburn 12866: =item * &csv_print_samples($r,$records)
1.41 ng 12867:
12868: Prints a table of sample values from each column uploaded $r is an
12869: Apache Request ref, $records is an arrayref from
12870: &Apache::loncommon::upfile_record_sep
12871:
12872: =cut
12873:
1.144 matthew 12874: ######################################################
12875: ######################################################
1.31 albertel 12876: sub csv_print_samples {
12877: my ($r,$records) = @_;
1.662 bisitz 12878: my $samples = &get_samples($records,5);
1.301 albertel 12879:
1.594 raeburn 12880: $r->print(&mt('Samples').'<br />'.&start_data_table().
12881: &start_data_table_header_row());
1.356 albertel 12882: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12883: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12884: $r->print(&end_data_table_header_row());
1.301 albertel 12885: foreach my $hash (@$samples) {
1.594 raeburn 12886: $r->print(&start_data_table_row());
1.356 albertel 12887: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12888: $r->print('<td>');
1.356 albertel 12889: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12890: $r->print('</td>');
12891: }
1.594 raeburn 12892: $r->print(&end_data_table_row());
1.31 albertel 12893: }
1.594 raeburn 12894: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12895: }
12896:
1.144 matthew 12897: ######################################################
12898: ######################################################
12899:
1.56 matthew 12900: =pod
12901:
1.648 raeburn 12902: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12903:
12904: Prints a table to create associations between values and table columns.
1.144 matthew 12905:
1.41 ng 12906: $r is an Apache Request ref,
12907: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12908: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12909:
12910: =cut
12911:
1.144 matthew 12912: ######################################################
12913: ######################################################
1.31 albertel 12914: sub csv_print_select_table {
12915: my ($r,$records,$d) = @_;
1.301 albertel 12916: my $i=0;
12917: my $samples = &get_samples($records,1);
1.144 matthew 12918: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12919: &start_data_table().&start_data_table_header_row().
1.144 matthew 12920: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12921: '<th>'.&mt('Column').'</th>'.
12922: &end_data_table_header_row()."\n");
1.356 albertel 12923: foreach my $array_ref (@$d) {
12924: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12925: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12926:
1.875 bisitz 12927: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12928: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12929: $r->print('<option value="none"></option>');
1.356 albertel 12930: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12931: $r->print('<option value="'.$sample.'"'.
12932: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12933: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12934: }
1.594 raeburn 12935: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12936: $i++;
12937: }
1.594 raeburn 12938: $r->print(&end_data_table());
1.31 albertel 12939: $i--;
12940: return $i;
12941: }
1.56 matthew 12942:
1.144 matthew 12943: ######################################################
12944: ######################################################
12945:
1.56 matthew 12946: =pod
1.31 albertel 12947:
1.648 raeburn 12948: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12949:
12950: Prints a table of sample values from the upload and can make associate samples to internal names.
12951:
12952: $r is an Apache Request ref,
12953: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12954: $d is an array of 2 element arrays (internal name, displayed name)
12955:
12956: =cut
12957:
1.144 matthew 12958: ######################################################
12959: ######################################################
1.31 albertel 12960: sub csv_samples_select_table {
12961: my ($r,$records,$d) = @_;
12962: my $i=0;
1.144 matthew 12963: #
1.662 bisitz 12964: my $max_samples = 5;
12965: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12966: $r->print(&start_data_table().
12967: &start_data_table_header_row().'<th>'.
12968: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12969: &end_data_table_header_row());
1.301 albertel 12970:
12971: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12972: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12973: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12974: foreach my $option (@$d) {
12975: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12976: $r->print('<option value="'.$value.'"'.
1.253 albertel 12977: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12978: $display.'</option>');
1.31 albertel 12979: }
12980: $r->print('</select></td><td>');
1.662 bisitz 12981: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12982: if (defined($samples->[$line]{$key})) {
12983: $r->print($samples->[$line]{$key}."<br />\n");
12984: }
12985: }
1.594 raeburn 12986: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12987: $i++;
12988: }
1.594 raeburn 12989: $r->print(&end_data_table());
1.31 albertel 12990: $i--;
12991: return($i);
1.115 matthew 12992: }
12993:
1.144 matthew 12994: ######################################################
12995: ######################################################
12996:
1.115 matthew 12997: =pod
12998:
1.648 raeburn 12999: =item * &clean_excel_name($name)
1.115 matthew 13000:
13001: Returns a replacement for $name which does not contain any illegal characters.
13002:
13003: =cut
13004:
1.144 matthew 13005: ######################################################
13006: ######################################################
1.115 matthew 13007: sub clean_excel_name {
13008: my ($name) = @_;
13009: $name =~ s/[:\*\?\/\\]//g;
13010: if (length($name) > 31) {
13011: $name = substr($name,0,31);
13012: }
13013: return $name;
1.25 albertel 13014: }
1.84 albertel 13015:
1.85 albertel 13016: =pod
13017:
1.648 raeburn 13018: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13019:
13020: Returns either 1 or undef
13021:
13022: 1 if the part is to be hidden, undef if it is to be shown
13023:
13024: Arguments are:
13025:
13026: $id the id of the part to be checked
13027: $symb, optional the symb of the resource to check
13028: $udom, optional the domain of the user to check for
13029: $uname, optional the username of the user to check for
13030:
13031: =cut
1.84 albertel 13032:
13033: sub check_if_partid_hidden {
13034: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13035: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13036: $symb,$udom,$uname);
1.141 albertel 13037: my $truth=1;
13038: #if the string starts with !, then the list is the list to show not hide
13039: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13040: my @hiddenlist=split(/,/,$hiddenparts);
13041: foreach my $checkid (@hiddenlist) {
1.141 albertel 13042: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13043: }
1.141 albertel 13044: return !$truth;
1.84 albertel 13045: }
1.127 matthew 13046:
1.138 matthew 13047:
13048: ############################################################
13049: ############################################################
13050:
13051: =pod
13052:
1.157 matthew 13053: =back
13054:
1.138 matthew 13055: =head1 cgi-bin script and graphing routines
13056:
1.157 matthew 13057: =over 4
13058:
1.648 raeburn 13059: =item * &get_cgi_id()
1.138 matthew 13060:
13061: Inputs: none
13062:
13063: Returns an id which can be used to pass environment variables
13064: to various cgi-bin scripts. These environment variables will
13065: be removed from the users environment after a given time by
13066: the routine &Apache::lonnet::transfer_profile_to_env.
13067:
13068: =cut
13069:
13070: ############################################################
13071: ############################################################
1.152 albertel 13072: my $uniq=0;
1.136 matthew 13073: sub get_cgi_id {
1.154 albertel 13074: $uniq=($uniq+1)%100000;
1.280 albertel 13075: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13076: }
13077:
1.127 matthew 13078: ############################################################
13079: ############################################################
13080:
13081: =pod
13082:
1.648 raeburn 13083: =item * &DrawBarGraph()
1.127 matthew 13084:
1.138 matthew 13085: Facilitates the plotting of data in a (stacked) bar graph.
13086: Puts plot definition data into the users environment in order for
13087: graph.png to plot it. Returns an <img> tag for the plot.
13088: The bars on the plot are labeled '1','2',...,'n'.
13089:
13090: Inputs:
13091:
13092: =over 4
13093:
13094: =item $Title: string, the title of the plot
13095:
13096: =item $xlabel: string, text describing the X-axis of the plot
13097:
13098: =item $ylabel: string, text describing the Y-axis of the plot
13099:
13100: =item $Max: scalar, the maximum Y value to use in the plot
13101: If $Max is < any data point, the graph will not be rendered.
13102:
1.140 matthew 13103: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13104: they are plotted. If undefined, default values will be used.
13105:
1.178 matthew 13106: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13107:
1.138 matthew 13108: =item @Values: An array of array references. Each array reference holds data
13109: to be plotted in a stacked bar chart.
13110:
1.239 matthew 13111: =item If the final element of @Values is a hash reference the key/value
13112: pairs will be added to the graph definition.
13113:
1.138 matthew 13114: =back
13115:
13116: Returns:
13117:
13118: An <img> tag which references graph.png and the appropriate identifying
13119: information for the plot.
13120:
1.127 matthew 13121: =cut
13122:
13123: ############################################################
13124: ############################################################
1.134 matthew 13125: sub DrawBarGraph {
1.178 matthew 13126: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13127: #
13128: if (! defined($colors)) {
13129: $colors = ['#33ff00',
13130: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13131: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13132: ];
13133: }
1.228 matthew 13134: my $extra_settings = {};
13135: if (ref($Values[-1]) eq 'HASH') {
13136: $extra_settings = pop(@Values);
13137: }
1.127 matthew 13138: #
1.136 matthew 13139: my $identifier = &get_cgi_id();
13140: my $id = 'cgi.'.$identifier;
1.129 matthew 13141: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13142: return '';
13143: }
1.225 matthew 13144: #
13145: my @Labels;
13146: if (defined($labels)) {
13147: @Labels = @$labels;
13148: } else {
13149: for (my $i=0;$i<@{$Values[0]};$i++) {
13150: push (@Labels,$i+1);
13151: }
13152: }
13153: #
1.129 matthew 13154: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13155: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13156: my %ValuesHash;
13157: my $NumSets=1;
13158: foreach my $array (@Values) {
13159: next if (! ref($array));
1.136 matthew 13160: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13161: join(',',@$array);
1.129 matthew 13162: }
1.127 matthew 13163: #
1.136 matthew 13164: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13165: if ($NumBars < 3) {
13166: $width = 120+$NumBars*32;
1.220 matthew 13167: $xskip = 1;
1.225 matthew 13168: $bar_width = 30;
13169: } elsif ($NumBars < 5) {
13170: $width = 120+$NumBars*20;
13171: $xskip = 1;
13172: $bar_width = 20;
1.220 matthew 13173: } elsif ($NumBars < 10) {
1.136 matthew 13174: $width = 120+$NumBars*15;
13175: $xskip = 1;
13176: $bar_width = 15;
13177: } elsif ($NumBars <= 25) {
13178: $width = 120+$NumBars*11;
13179: $xskip = 5;
13180: $bar_width = 8;
13181: } elsif ($NumBars <= 50) {
13182: $width = 120+$NumBars*8;
13183: $xskip = 5;
13184: $bar_width = 4;
13185: } else {
13186: $width = 120+$NumBars*8;
13187: $xskip = 5;
13188: $bar_width = 4;
13189: }
13190: #
1.137 matthew 13191: $Max = 1 if ($Max < 1);
13192: if ( int($Max) < $Max ) {
13193: $Max++;
13194: $Max = int($Max);
13195: }
1.127 matthew 13196: $Title = '' if (! defined($Title));
13197: $xlabel = '' if (! defined($xlabel));
13198: $ylabel = '' if (! defined($ylabel));
1.369 www 13199: $ValuesHash{$id.'.title'} = &escape($Title);
13200: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13201: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13202: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13203: $ValuesHash{$id.'.NumBars'} = $NumBars;
13204: $ValuesHash{$id.'.NumSets'} = $NumSets;
13205: $ValuesHash{$id.'.PlotType'} = 'bar';
13206: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13207: $ValuesHash{$id.'.height'} = $height;
13208: $ValuesHash{$id.'.width'} = $width;
13209: $ValuesHash{$id.'.xskip'} = $xskip;
13210: $ValuesHash{$id.'.bar_width'} = $bar_width;
13211: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13212: #
1.228 matthew 13213: # Deal with other parameters
13214: while (my ($key,$value) = each(%$extra_settings)) {
13215: $ValuesHash{$id.'.'.$key} = $value;
13216: }
13217: #
1.646 raeburn 13218: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13219: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13220: }
13221:
13222: ############################################################
13223: ############################################################
13224:
13225: =pod
13226:
1.648 raeburn 13227: =item * &DrawXYGraph()
1.137 matthew 13228:
1.138 matthew 13229: Facilitates the plotting of data in an XY graph.
13230: Puts plot definition data into the users environment in order for
13231: graph.png to plot it. Returns an <img> tag for the plot.
13232:
13233: Inputs:
13234:
13235: =over 4
13236:
13237: =item $Title: string, the title of the plot
13238:
13239: =item $xlabel: string, text describing the X-axis of the plot
13240:
13241: =item $ylabel: string, text describing the Y-axis of the plot
13242:
13243: =item $Max: scalar, the maximum Y value to use in the plot
13244: If $Max is < any data point, the graph will not be rendered.
13245:
13246: =item $colors: Array ref containing the hex color codes for the data to be
13247: plotted in. If undefined, default values will be used.
13248:
13249: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13250:
13251: =item $Ydata: Array ref containing Array refs.
1.185 www 13252: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13253:
13254: =item %Values: hash indicating or overriding any default values which are
13255: passed to graph.png.
13256: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13257:
13258: =back
13259:
13260: Returns:
13261:
13262: An <img> tag which references graph.png and the appropriate identifying
13263: information for the plot.
13264:
1.137 matthew 13265: =cut
13266:
13267: ############################################################
13268: ############################################################
13269: sub DrawXYGraph {
13270: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13271: #
13272: # Create the identifier for the graph
13273: my $identifier = &get_cgi_id();
13274: my $id = 'cgi.'.$identifier;
13275: #
13276: $Title = '' if (! defined($Title));
13277: $xlabel = '' if (! defined($xlabel));
13278: $ylabel = '' if (! defined($ylabel));
13279: my %ValuesHash =
13280: (
1.369 www 13281: $id.'.title' => &escape($Title),
13282: $id.'.xlabel' => &escape($xlabel),
13283: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13284: $id.'.y_max_value'=> $Max,
13285: $id.'.labels' => join(',',@$Xlabels),
13286: $id.'.PlotType' => 'XY',
13287: );
13288: #
13289: if (defined($colors) && ref($colors) eq 'ARRAY') {
13290: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13291: }
13292: #
13293: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13294: return '';
13295: }
13296: my $NumSets=1;
1.138 matthew 13297: foreach my $array (@{$Ydata}){
1.137 matthew 13298: next if (! ref($array));
13299: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13300: }
1.138 matthew 13301: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13302: #
13303: # Deal with other parameters
13304: while (my ($key,$value) = each(%Values)) {
13305: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13306: }
13307: #
1.646 raeburn 13308: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13309: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13310: }
13311:
13312: ############################################################
13313: ############################################################
13314:
13315: =pod
13316:
1.648 raeburn 13317: =item * &DrawXYYGraph()
1.138 matthew 13318:
13319: Facilitates the plotting of data in an XY graph with two Y axes.
13320: Puts plot definition data into the users environment in order for
13321: graph.png to plot it. Returns an <img> tag for the plot.
13322:
13323: Inputs:
13324:
13325: =over 4
13326:
13327: =item $Title: string, the title of the plot
13328:
13329: =item $xlabel: string, text describing the X-axis of the plot
13330:
13331: =item $ylabel: string, text describing the Y-axis of the plot
13332:
13333: =item $colors: Array ref containing the hex color codes for the data to be
13334: plotted in. If undefined, default values will be used.
13335:
13336: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13337:
13338: =item $Ydata1: The first data set
13339:
13340: =item $Min1: The minimum value of the left Y-axis
13341:
13342: =item $Max1: The maximum value of the left Y-axis
13343:
13344: =item $Ydata2: The second data set
13345:
13346: =item $Min2: The minimum value of the right Y-axis
13347:
13348: =item $Max2: The maximum value of the left Y-axis
13349:
13350: =item %Values: hash indicating or overriding any default values which are
13351: passed to graph.png.
13352: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13353:
13354: =back
13355:
13356: Returns:
13357:
13358: An <img> tag which references graph.png and the appropriate identifying
13359: information for the plot.
1.136 matthew 13360:
13361: =cut
13362:
13363: ############################################################
13364: ############################################################
1.137 matthew 13365: sub DrawXYYGraph {
13366: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13367: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13368: #
13369: # Create the identifier for the graph
13370: my $identifier = &get_cgi_id();
13371: my $id = 'cgi.'.$identifier;
13372: #
13373: $Title = '' if (! defined($Title));
13374: $xlabel = '' if (! defined($xlabel));
13375: $ylabel = '' if (! defined($ylabel));
13376: my %ValuesHash =
13377: (
1.369 www 13378: $id.'.title' => &escape($Title),
13379: $id.'.xlabel' => &escape($xlabel),
13380: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13381: $id.'.labels' => join(',',@$Xlabels),
13382: $id.'.PlotType' => 'XY',
13383: $id.'.NumSets' => 2,
1.137 matthew 13384: $id.'.two_axes' => 1,
13385: $id.'.y1_max_value' => $Max1,
13386: $id.'.y1_min_value' => $Min1,
13387: $id.'.y2_max_value' => $Max2,
13388: $id.'.y2_min_value' => $Min2,
1.136 matthew 13389: );
13390: #
1.137 matthew 13391: if (defined($colors) && ref($colors) eq 'ARRAY') {
13392: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13393: }
13394: #
13395: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13396: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13397: return '';
13398: }
13399: my $NumSets=1;
1.137 matthew 13400: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13401: next if (! ref($array));
13402: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13403: }
13404: #
13405: # Deal with other parameters
13406: while (my ($key,$value) = each(%Values)) {
13407: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13408: }
13409: #
1.646 raeburn 13410: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13411: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13412: }
13413:
13414: ############################################################
13415: ############################################################
13416:
13417: =pod
13418:
1.157 matthew 13419: =back
13420:
1.139 matthew 13421: =head1 Statistics helper routines?
13422:
13423: Bad place for them but what the hell.
13424:
1.157 matthew 13425: =over 4
13426:
1.648 raeburn 13427: =item * &chartlink()
1.139 matthew 13428:
13429: Returns a link to the chart for a specific student.
13430:
13431: Inputs:
13432:
13433: =over 4
13434:
13435: =item $linktext: The text of the link
13436:
13437: =item $sname: The students username
13438:
13439: =item $sdomain: The students domain
13440:
13441: =back
13442:
1.157 matthew 13443: =back
13444:
1.139 matthew 13445: =cut
13446:
13447: ############################################################
13448: ############################################################
13449: sub chartlink {
13450: my ($linktext, $sname, $sdomain) = @_;
13451: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13452: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13453: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13454: '">'.$linktext.'</a>';
1.153 matthew 13455: }
13456:
13457: #######################################################
13458: #######################################################
13459:
13460: =pod
13461:
13462: =head1 Course Environment Routines
1.157 matthew 13463:
13464: =over 4
1.153 matthew 13465:
1.648 raeburn 13466: =item * &restore_course_settings()
1.153 matthew 13467:
1.648 raeburn 13468: =item * &store_course_settings()
1.153 matthew 13469:
13470: Restores/Store indicated form parameters from the course environment.
13471: Will not overwrite existing values of the form parameters.
13472:
13473: Inputs:
13474: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13475:
13476: a hash ref describing the data to be stored. For example:
13477:
13478: %Save_Parameters = ('Status' => 'scalar',
13479: 'chartoutputmode' => 'scalar',
13480: 'chartoutputdata' => 'scalar',
13481: 'Section' => 'array',
1.373 raeburn 13482: 'Group' => 'array',
1.153 matthew 13483: 'StudentData' => 'array',
13484: 'Maps' => 'array');
13485:
13486: Returns: both routines return nothing
13487:
1.631 raeburn 13488: =back
13489:
1.153 matthew 13490: =cut
13491:
13492: #######################################################
13493: #######################################################
13494: sub store_course_settings {
1.496 albertel 13495: return &store_settings($env{'request.course.id'},@_);
13496: }
13497:
13498: sub store_settings {
1.153 matthew 13499: # save to the environment
13500: # appenv the same items, just to be safe
1.300 albertel 13501: my $udom = $env{'user.domain'};
13502: my $uname = $env{'user.name'};
1.496 albertel 13503: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13504: my %SaveHash;
13505: my %AppHash;
13506: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13507: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13508: my $envname = 'environment.'.$basename;
1.258 albertel 13509: if (exists($env{'form.'.$setting})) {
1.153 matthew 13510: # Save this value away
13511: if ($type eq 'scalar' &&
1.258 albertel 13512: (! exists($env{$envname}) ||
13513: $env{$envname} ne $env{'form.'.$setting})) {
13514: $SaveHash{$basename} = $env{'form.'.$setting};
13515: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13516: } elsif ($type eq 'array') {
13517: my $stored_form;
1.258 albertel 13518: if (ref($env{'form.'.$setting})) {
1.153 matthew 13519: $stored_form = join(',',
13520: map {
1.369 www 13521: &escape($_);
1.258 albertel 13522: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13523: } else {
13524: $stored_form =
1.369 www 13525: &escape($env{'form.'.$setting});
1.153 matthew 13526: }
13527: # Determine if the array contents are the same.
1.258 albertel 13528: if ($stored_form ne $env{$envname}) {
1.153 matthew 13529: $SaveHash{$basename} = $stored_form;
13530: $AppHash{$envname} = $stored_form;
13531: }
13532: }
13533: }
13534: }
13535: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13536: $udom,$uname);
1.153 matthew 13537: if ($put_result !~ /^(ok|delayed)/) {
13538: &Apache::lonnet::logthis('unable to save form parameters, '.
13539: 'got error:'.$put_result);
13540: }
13541: # Make sure these settings stick around in this session, too
1.646 raeburn 13542: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13543: return;
13544: }
13545:
13546: sub restore_course_settings {
1.499 albertel 13547: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13548: }
13549:
13550: sub restore_settings {
13551: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13552: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13553: next if (exists($env{'form.'.$setting}));
1.496 albertel 13554: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13555: '.'.$setting;
1.258 albertel 13556: if (exists($env{$envname})) {
1.153 matthew 13557: if ($type eq 'scalar') {
1.258 albertel 13558: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13559: } elsif ($type eq 'array') {
1.258 albertel 13560: $env{'form.'.$setting} = [
1.153 matthew 13561: map {
1.369 www 13562: &unescape($_);
1.258 albertel 13563: } split(',',$env{$envname})
1.153 matthew 13564: ];
13565: }
13566: }
13567: }
1.127 matthew 13568: }
13569:
1.618 raeburn 13570: #######################################################
13571: #######################################################
13572:
13573: =pod
13574:
13575: =head1 Domain E-mail Routines
13576:
13577: =over 4
13578:
1.648 raeburn 13579: =item * &build_recipient_list()
1.618 raeburn 13580:
1.1075.2.44 raeburn 13581: Build recipient lists for following types of e-mail:
1.766 raeburn 13582: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 13583: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13584: module change checking, student/employee ID conflict checks, as
13585: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13586: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13587:
13588: Inputs:
1.1075.2.44 raeburn 13589: defmail (scalar - email address of default recipient),
13590: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13591: requestsmail, updatesmail, or idconflictsmail).
13592:
1.619 raeburn 13593: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 13594:
13595: origmail (scalar - email address of recipient from loncapa.conf,
13596: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13597:
1.655 raeburn 13598: Returns: comma separated list of addresses to which to send e-mail.
13599:
13600: =back
1.618 raeburn 13601:
13602: =cut
13603:
13604: ############################################################
13605: ############################################################
13606: sub build_recipient_list {
1.619 raeburn 13607: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13608: my @recipients;
13609: my $otheremails;
13610: my %domconfig =
13611: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13612: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13613: if (exists($domconfig{'contacts'}{$mailing})) {
13614: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13615: my @contacts = ('adminemail','supportemail');
13616: foreach my $item (@contacts) {
13617: if ($domconfig{'contacts'}{$mailing}{$item}) {
13618: my $addr = $domconfig{'contacts'}{$item};
13619: if (!grep(/^\Q$addr\E$/,@recipients)) {
13620: push(@recipients,$addr);
13621: }
1.619 raeburn 13622: }
1.766 raeburn 13623: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13624: }
13625: }
1.766 raeburn 13626: } elsif ($origmail ne '') {
13627: push(@recipients,$origmail);
1.618 raeburn 13628: }
1.619 raeburn 13629: } elsif ($origmail ne '') {
13630: push(@recipients,$origmail);
1.618 raeburn 13631: }
1.688 raeburn 13632: if (defined($defmail)) {
13633: if ($defmail ne '') {
13634: push(@recipients,$defmail);
13635: }
1.618 raeburn 13636: }
13637: if ($otheremails) {
1.619 raeburn 13638: my @others;
13639: if ($otheremails =~ /,/) {
13640: @others = split(/,/,$otheremails);
1.618 raeburn 13641: } else {
1.619 raeburn 13642: push(@others,$otheremails);
13643: }
13644: foreach my $addr (@others) {
13645: if (!grep(/^\Q$addr\E$/,@recipients)) {
13646: push(@recipients,$addr);
13647: }
1.618 raeburn 13648: }
13649: }
1.619 raeburn 13650: my $recipientlist = join(',',@recipients);
1.618 raeburn 13651: return $recipientlist;
13652: }
13653:
1.127 matthew 13654: ############################################################
13655: ############################################################
1.154 albertel 13656:
1.655 raeburn 13657: =pod
13658:
13659: =head1 Course Catalog Routines
13660:
13661: =over 4
13662:
13663: =item * &gather_categories()
13664:
13665: Converts category definitions - keys of categories hash stored in
13666: coursecategories in configuration.db on the primary library server in a
13667: domain - to an array. Also generates javascript and idx hash used to
13668: generate Domain Coordinator interface for editing Course Categories.
13669:
13670: Inputs:
1.663 raeburn 13671:
1.655 raeburn 13672: categories (reference to hash of category definitions).
1.663 raeburn 13673:
1.655 raeburn 13674: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13675: categories and subcategories).
1.663 raeburn 13676:
1.655 raeburn 13677: idx (reference to hash of counters used in Domain Coordinator interface for
13678: editing Course Categories).
1.663 raeburn 13679:
1.655 raeburn 13680: jsarray (reference to array of categories used to create Javascript arrays for
13681: Domain Coordinator interface for editing Course Categories).
13682:
13683: Returns: nothing
13684:
13685: Side effects: populates cats, idx and jsarray.
13686:
13687: =cut
13688:
13689: sub gather_categories {
13690: my ($categories,$cats,$idx,$jsarray) = @_;
13691: my %counters;
13692: my $num = 0;
13693: foreach my $item (keys(%{$categories})) {
13694: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13695: if ($container eq '' && $depth == 0) {
13696: $cats->[$depth][$categories->{$item}] = $cat;
13697: } else {
13698: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13699: }
13700: my ($escitem,$tail) = split(/:/,$item,2);
13701: if ($counters{$tail} eq '') {
13702: $counters{$tail} = $num;
13703: $num ++;
13704: }
13705: if (ref($idx) eq 'HASH') {
13706: $idx->{$item} = $counters{$tail};
13707: }
13708: if (ref($jsarray) eq 'ARRAY') {
13709: push(@{$jsarray->[$counters{$tail}]},$item);
13710: }
13711: }
13712: return;
13713: }
13714:
13715: =pod
13716:
13717: =item * &extract_categories()
13718:
13719: Used to generate breadcrumb trails for course categories.
13720:
13721: Inputs:
1.663 raeburn 13722:
1.655 raeburn 13723: categories (reference to hash of category definitions).
1.663 raeburn 13724:
1.655 raeburn 13725: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13726: categories and subcategories).
1.663 raeburn 13727:
1.655 raeburn 13728: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13729:
1.655 raeburn 13730: allitems (reference to hash - key is category key
13731: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13732:
1.655 raeburn 13733: idx (reference to hash of counters used in Domain Coordinator interface for
13734: editing Course Categories).
1.663 raeburn 13735:
1.655 raeburn 13736: jsarray (reference to array of categories used to create Javascript arrays for
13737: Domain Coordinator interface for editing Course Categories).
13738:
1.665 raeburn 13739: subcats (reference to hash of arrays containing all subcategories within each
13740: category, -recursive)
13741:
1.655 raeburn 13742: Returns: nothing
13743:
13744: Side effects: populates trails and allitems hash references.
13745:
13746: =cut
13747:
13748: sub extract_categories {
1.665 raeburn 13749: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13750: if (ref($categories) eq 'HASH') {
13751: &gather_categories($categories,$cats,$idx,$jsarray);
13752: if (ref($cats->[0]) eq 'ARRAY') {
13753: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13754: my $name = $cats->[0][$i];
13755: my $item = &escape($name).'::0';
13756: my $trailstr;
13757: if ($name eq 'instcode') {
13758: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13759: } elsif ($name eq 'communities') {
13760: $trailstr = &mt('Communities');
1.655 raeburn 13761: } else {
13762: $trailstr = $name;
13763: }
13764: if ($allitems->{$item} eq '') {
13765: push(@{$trails},$trailstr);
13766: $allitems->{$item} = scalar(@{$trails})-1;
13767: }
13768: my @parents = ($name);
13769: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13770: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13771: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13772: if (ref($subcats) eq 'HASH') {
13773: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13774: }
13775: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13776: }
13777: } else {
13778: if (ref($subcats) eq 'HASH') {
13779: $subcats->{$item} = [];
1.655 raeburn 13780: }
13781: }
13782: }
13783: }
13784: }
13785: return;
13786: }
13787:
13788: =pod
13789:
1.1075.2.56 raeburn 13790: =item * &recurse_categories()
1.655 raeburn 13791:
13792: Recursively used to generate breadcrumb trails for course categories.
13793:
13794: Inputs:
1.663 raeburn 13795:
1.655 raeburn 13796: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13797: categories and subcategories).
1.663 raeburn 13798:
1.655 raeburn 13799: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13800:
13801: category (current course category, for which breadcrumb trail is being generated).
13802:
13803: trails (reference to array of breadcrumb trails for each category).
13804:
1.655 raeburn 13805: allitems (reference to hash - key is category key
13806: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13807:
1.655 raeburn 13808: parents (array containing containers directories for current category,
13809: back to top level).
13810:
13811: Returns: nothing
13812:
13813: Side effects: populates trails and allitems hash references
13814:
13815: =cut
13816:
13817: sub recurse_categories {
1.665 raeburn 13818: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13819: my $shallower = $depth - 1;
13820: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13821: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13822: my $name = $cats->[$depth]{$category}[$k];
13823: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13824: my $trailstr = join(' -> ',(@{$parents},$category));
13825: if ($allitems->{$item} eq '') {
13826: push(@{$trails},$trailstr);
13827: $allitems->{$item} = scalar(@{$trails})-1;
13828: }
13829: my $deeper = $depth+1;
13830: push(@{$parents},$category);
1.665 raeburn 13831: if (ref($subcats) eq 'HASH') {
13832: my $subcat = &escape($name).':'.$category.':'.$depth;
13833: for (my $j=@{$parents}; $j>=0; $j--) {
13834: my $higher;
13835: if ($j > 0) {
13836: $higher = &escape($parents->[$j]).':'.
13837: &escape($parents->[$j-1]).':'.$j;
13838: } else {
13839: $higher = &escape($parents->[$j]).'::'.$j;
13840: }
13841: push(@{$subcats->{$higher}},$subcat);
13842: }
13843: }
13844: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13845: $subcats);
1.655 raeburn 13846: pop(@{$parents});
13847: }
13848: } else {
13849: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13850: my $trailstr = join(' -> ',(@{$parents},$category));
13851: if ($allitems->{$item} eq '') {
13852: push(@{$trails},$trailstr);
13853: $allitems->{$item} = scalar(@{$trails})-1;
13854: }
13855: }
13856: return;
13857: }
13858:
1.663 raeburn 13859: =pod
13860:
1.1075.2.56 raeburn 13861: =item * &assign_categories_table()
1.663 raeburn 13862:
13863: Create a datatable for display of hierarchical categories in a domain,
13864: with checkboxes to allow a course to be categorized.
13865:
13866: Inputs:
13867:
13868: cathash - reference to hash of categories defined for the domain (from
13869: configuration.db)
13870:
13871: currcat - scalar with an & separated list of categories assigned to a course.
13872:
1.919 raeburn 13873: type - scalar contains course type (Course or Community).
13874:
1.663 raeburn 13875: Returns: $output (markup to be displayed)
13876:
13877: =cut
13878:
13879: sub assign_categories_table {
1.919 raeburn 13880: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13881: my $output;
13882: if (ref($cathash) eq 'HASH') {
13883: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13884: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13885: $maxdepth = scalar(@cats);
13886: if (@cats > 0) {
13887: my $itemcount = 0;
13888: if (ref($cats[0]) eq 'ARRAY') {
13889: my @currcategories;
13890: if ($currcat ne '') {
13891: @currcategories = split('&',$currcat);
13892: }
1.919 raeburn 13893: my $table;
1.663 raeburn 13894: for (my $i=0; $i<@{$cats[0]}; $i++) {
13895: my $parent = $cats[0][$i];
1.919 raeburn 13896: next if ($parent eq 'instcode');
13897: if ($type eq 'Community') {
13898: next unless ($parent eq 'communities');
13899: } else {
13900: next if ($parent eq 'communities');
13901: }
1.663 raeburn 13902: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13903: my $item = &escape($parent).'::0';
13904: my $checked = '';
13905: if (@currcategories > 0) {
13906: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13907: $checked = ' checked="checked"';
1.663 raeburn 13908: }
13909: }
1.919 raeburn 13910: my $parent_title = $parent;
13911: if ($parent eq 'communities') {
13912: $parent_title = &mt('Communities');
13913: }
13914: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13915: '<input type="checkbox" name="usecategory" value="'.
13916: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13917: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13918: my $depth = 1;
13919: push(@path,$parent);
1.919 raeburn 13920: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13921: pop(@path);
1.919 raeburn 13922: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13923: $itemcount ++;
13924: }
1.919 raeburn 13925: if ($itemcount) {
13926: $output = &Apache::loncommon::start_data_table().
13927: $table.
13928: &Apache::loncommon::end_data_table();
13929: }
1.663 raeburn 13930: }
13931: }
13932: }
13933: return $output;
13934: }
13935:
13936: =pod
13937:
1.1075.2.56 raeburn 13938: =item * &assign_category_rows()
1.663 raeburn 13939:
13940: Create a datatable row for display of nested categories in a domain,
13941: with checkboxes to allow a course to be categorized,called recursively.
13942:
13943: Inputs:
13944:
13945: itemcount - track row number for alternating colors
13946:
13947: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13948: categories and subcategories.
13949:
13950: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13951:
13952: parent - parent of current category item
13953:
13954: path - Array containing all categories back up through the hierarchy from the
13955: current category to the top level.
13956:
13957: currcategories - reference to array of current categories assigned to the course
13958:
13959: Returns: $output (markup to be displayed).
13960:
13961: =cut
13962:
13963: sub assign_category_rows {
13964: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13965: my ($text,$name,$item,$chgstr);
13966: if (ref($cats) eq 'ARRAY') {
13967: my $maxdepth = scalar(@{$cats});
13968: if (ref($cats->[$depth]) eq 'HASH') {
13969: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13970: my $numchildren = @{$cats->[$depth]{$parent}};
13971: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 13972: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 13973: for (my $j=0; $j<$numchildren; $j++) {
13974: $name = $cats->[$depth]{$parent}[$j];
13975: $item = &escape($name).':'.&escape($parent).':'.$depth;
13976: my $deeper = $depth+1;
13977: my $checked = '';
13978: if (ref($currcategories) eq 'ARRAY') {
13979: if (@{$currcategories} > 0) {
13980: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13981: $checked = ' checked="checked"';
1.663 raeburn 13982: }
13983: }
13984: }
1.664 raeburn 13985: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13986: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13987: $item.'"'.$checked.' />'.$name.'</label></span>'.
13988: '<input type="hidden" name="catname" value="'.$name.'" />'.
13989: '</td><td>';
1.663 raeburn 13990: if (ref($path) eq 'ARRAY') {
13991: push(@{$path},$name);
13992: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13993: pop(@{$path});
13994: }
13995: $text .= '</td></tr>';
13996: }
13997: $text .= '</table></td>';
13998: }
13999: }
14000: }
14001: return $text;
14002: }
14003:
1.1075.2.69 raeburn 14004: =pod
14005:
14006: =back
14007:
14008: =cut
14009:
1.655 raeburn 14010: ############################################################
14011: ############################################################
14012:
14013:
1.443 albertel 14014: sub commit_customrole {
1.664 raeburn 14015: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14016: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14017: ($start?', '.&mt('starting').' '.localtime($start):'').
14018: ($end?', ending '.localtime($end):'').': <b>'.
14019: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14020: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14021: '</b><br />';
14022: return $output;
14023: }
14024:
14025: sub commit_standardrole {
1.1075.2.31 raeburn 14026: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14027: my ($output,$logmsg,$linefeed);
14028: if ($context eq 'auto') {
14029: $linefeed = "\n";
14030: } else {
14031: $linefeed = "<br />\n";
14032: }
1.443 albertel 14033: if ($three eq 'st') {
1.541 raeburn 14034: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 14035: $one,$two,$sec,$context,$credits);
1.541 raeburn 14036: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14037: ($result eq 'unknown_course') || ($result eq 'refused')) {
14038: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14039: } else {
1.541 raeburn 14040: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14041: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14042: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14043: if ($context eq 'auto') {
14044: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14045: } else {
14046: $output .= '<b>'.$result.'</b>'.$linefeed.
14047: &mt('Add to classlist').': <b>ok</b>';
14048: }
14049: $output .= $linefeed;
1.443 albertel 14050: }
14051: } else {
14052: $output = &mt('Assigning').' '.$three.' in '.$url.
14053: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14054: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 14055: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 14056: if ($context eq 'auto') {
14057: $output .= $result.$linefeed;
14058: } else {
14059: $output .= '<b>'.$result.'</b>'.$linefeed;
14060: }
1.443 albertel 14061: }
14062: return $output;
14063: }
14064:
14065: sub commit_studentrole {
1.1075.2.31 raeburn 14066: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
14067: $credits) = @_;
1.626 raeburn 14068: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 14069: if ($context eq 'auto') {
14070: $linefeed = "\n";
14071: } else {
14072: $linefeed = '<br />'."\n";
14073: }
1.443 albertel 14074: if (defined($one) && defined($two)) {
14075: my $cid=$one.'_'.$two;
14076: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
14077: my $secchange = 0;
14078: my $expire_role_result;
14079: my $modify_section_result;
1.628 raeburn 14080: if ($oldsec ne '-1') {
14081: if ($oldsec ne $sec) {
1.443 albertel 14082: $secchange = 1;
1.628 raeburn 14083: my $now = time;
1.443 albertel 14084: my $uurl='/'.$cid;
14085: $uurl=~s/\_/\//g;
14086: if ($oldsec) {
14087: $uurl.='/'.$oldsec;
14088: }
1.626 raeburn 14089: $oldsecurl = $uurl;
1.628 raeburn 14090: $expire_role_result =
1.652 raeburn 14091: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 14092: if ($env{'request.course.sec'} ne '') {
14093: if ($expire_role_result eq 'refused') {
14094: my @roles = ('st');
14095: my @statuses = ('previous');
14096: my @roledoms = ($one);
14097: my $withsec = 1;
14098: my %roleshash =
14099: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
14100: \@statuses,\@roles,\@roledoms,$withsec);
14101: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
14102: my ($oldstart,$oldend) =
14103: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
14104: if ($oldend > 0 && $oldend <= $now) {
14105: $expire_role_result = 'ok';
14106: }
14107: }
14108: }
14109: }
1.443 albertel 14110: $result = $expire_role_result;
14111: }
14112: }
14113: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 14114: $modify_section_result =
14115: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
14116: undef,undef,undef,$sec,
14117: $end,$start,'','',$cid,
14118: '',$context,$credits);
1.443 albertel 14119: if ($modify_section_result =~ /^ok/) {
14120: if ($secchange == 1) {
1.628 raeburn 14121: if ($sec eq '') {
14122: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
14123: } else {
14124: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
14125: }
1.443 albertel 14126: } elsif ($oldsec eq '-1') {
1.628 raeburn 14127: if ($sec eq '') {
14128: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
14129: } else {
14130: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14131: }
1.443 albertel 14132: } else {
1.628 raeburn 14133: if ($sec eq '') {
14134: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
14135: } else {
14136: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14137: }
1.443 albertel 14138: }
14139: } else {
1.628 raeburn 14140: if ($secchange) {
14141: $$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;
14142: } else {
14143: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
14144: }
1.443 albertel 14145: }
14146: $result = $modify_section_result;
14147: } elsif ($secchange == 1) {
1.628 raeburn 14148: if ($oldsec eq '') {
1.1075.2.20 raeburn 14149: $$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 14150: } else {
14151: $$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;
14152: }
1.626 raeburn 14153: if ($expire_role_result eq 'refused') {
14154: my $newsecurl = '/'.$cid;
14155: $newsecurl =~ s/\_/\//g;
14156: if ($sec ne '') {
14157: $newsecurl.='/'.$sec;
14158: }
14159: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
14160: if ($sec eq '') {
14161: $$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;
14162: } else {
14163: $$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;
14164: }
14165: }
14166: }
1.443 albertel 14167: }
14168: } else {
1.626 raeburn 14169: $$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 14170: $result = "error: incomplete course id\n";
14171: }
14172: return $result;
14173: }
14174:
1.1075.2.25 raeburn 14175: sub show_role_extent {
14176: my ($scope,$context,$role) = @_;
14177: $scope =~ s{^/}{};
14178: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
14179: push(@courseroles,'co');
14180: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
14181: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
14182: $scope =~ s{/}{_};
14183: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
14184: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
14185: my ($audom,$auname) = split(/\//,$scope);
14186: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
14187: &Apache::loncommon::plainname($auname,$audom).'</span>');
14188: } else {
14189: $scope =~ s{/$}{};
14190: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
14191: &Apache::lonnet::domain($scope,'description').'</span>');
14192: }
14193: }
14194:
1.443 albertel 14195: ############################################################
14196: ############################################################
14197:
1.566 albertel 14198: sub check_clone {
1.578 raeburn 14199: my ($args,$linefeed) = @_;
1.566 albertel 14200: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
14201: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
14202: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
14203: my $clonemsg;
14204: my $can_clone = 0;
1.944 raeburn 14205: my $lctype = lc($args->{'crstype'});
1.908 raeburn 14206: if ($lctype ne 'community') {
14207: $lctype = 'course';
14208: }
1.566 albertel 14209: if ($clonehome eq 'no_host') {
1.944 raeburn 14210: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14211: $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'});
14212: } else {
14213: $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'});
14214: }
1.566 albertel 14215: } else {
14216: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 14217: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14218: if ($clonedesc{'type'} ne 'Community') {
14219: $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'});
14220: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14221: }
14222: }
1.882 raeburn 14223: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
14224: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 14225: $can_clone = 1;
14226: } else {
1.1075.2.95 raeburn 14227: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 14228: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 14229: if ($clonehash{'cloners'} eq '') {
14230: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
14231: if ($domdefs{'canclone'}) {
14232: unless ($domdefs{'canclone'} eq 'none') {
14233: if ($domdefs{'canclone'} eq 'domain') {
14234: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
14235: $can_clone = 1;
14236: }
14237: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14238: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
14239: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
14240: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
14241: $can_clone = 1;
14242: }
14243: }
14244: }
1.908 raeburn 14245: }
1.1075.2.95 raeburn 14246: } else {
14247: my @cloners = split(/,/,$clonehash{'cloners'});
14248: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 14249: $can_clone = 1;
1.1075.2.95 raeburn 14250: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 14251: $can_clone = 1;
1.1075.2.96 raeburn 14252: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
14253: $can_clone = 1;
1.1075.2.95 raeburn 14254: }
14255: unless ($can_clone) {
1.1075.2.96 raeburn 14256: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14257: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 14258: my (%gotdomdefaults,%gotcodedefaults);
14259: foreach my $cloner (@cloners) {
14260: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
14261: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
14262: my (%codedefaults,@code_order);
14263: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
14264: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
14265: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
14266: }
14267: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
14268: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
14269: }
14270: } else {
14271: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
14272: \%codedefaults,
14273: \@code_order);
14274: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
14275: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
14276: }
14277: if (@code_order > 0) {
14278: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
14279: $cloner,$clonehash{'internal.coursecode'},
14280: $args->{'crscode'})) {
14281: $can_clone = 1;
14282: last;
14283: }
14284: }
14285: }
14286: }
14287: }
1.1075.2.96 raeburn 14288: }
14289: }
14290: unless ($can_clone) {
14291: my $ccrole = 'cc';
14292: if ($args->{'crstype'} eq 'Community') {
14293: $ccrole = 'co';
14294: }
14295: my %roleshash =
14296: &Apache::lonnet::get_my_roles($args->{'ccuname'},
14297: $args->{'ccdomain'},
14298: 'userroles',['active'],[$ccrole],
14299: [$args->{'clonedomain'}]);
14300: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
14301: $can_clone = 1;
14302: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
14303: $args->{'ccuname'},$args->{'ccdomain'})) {
14304: $can_clone = 1;
1.1075.2.95 raeburn 14305: }
14306: }
14307: unless ($can_clone) {
14308: if ($args->{'crstype'} eq 'Community') {
14309: $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'});
14310: } else {
14311: $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'});
1.578 raeburn 14312: }
1.566 albertel 14313: }
1.578 raeburn 14314: }
1.566 albertel 14315: }
14316: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14317: }
14318:
1.444 albertel 14319: sub construct_course {
1.1075.2.59 raeburn 14320: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 14321: my $outcome;
1.541 raeburn 14322: my $linefeed = '<br />'."\n";
14323: if ($context eq 'auto') {
14324: $linefeed = "\n";
14325: }
1.566 albertel 14326:
14327: #
14328: # Are we cloning?
14329: #
14330: my ($can_clone, $clonemsg, $cloneid, $clonehome);
14331: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 14332: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 14333: if ($context ne 'auto') {
1.578 raeburn 14334: if ($clonemsg ne '') {
14335: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
14336: }
1.566 albertel 14337: }
14338: $outcome .= $clonemsg.$linefeed;
14339:
14340: if (!$can_clone) {
14341: return (0,$outcome);
14342: }
14343: }
14344:
1.444 albertel 14345: #
14346: # Open course
14347: #
14348: my $crstype = lc($args->{'crstype'});
14349: my %cenv=();
14350: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
14351: $args->{'cdescr'},
14352: $args->{'curl'},
14353: $args->{'course_home'},
14354: $args->{'nonstandard'},
14355: $args->{'crscode'},
14356: $args->{'ccuname'}.':'.
14357: $args->{'ccdomain'},
1.882 raeburn 14358: $args->{'crstype'},
1.885 raeburn 14359: $cnum,$context,$category);
1.444 albertel 14360:
14361: # Note: The testing routines depend on this being output; see
14362: # Utils::Course. This needs to at least be output as a comment
14363: # if anyone ever decides to not show this, and Utils::Course::new
14364: # will need to be suitably modified.
1.541 raeburn 14365: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 14366: if ($$courseid =~ /^error:/) {
14367: return (0,$outcome);
14368: }
14369:
1.444 albertel 14370: #
14371: # Check if created correctly
14372: #
1.479 albertel 14373: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 14374: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 14375: if ($crsuhome eq 'no_host') {
14376: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
14377: return (0,$outcome);
14378: }
1.541 raeburn 14379: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 14380:
1.444 albertel 14381: #
1.566 albertel 14382: # Do the cloning
14383: #
14384: if ($can_clone && $cloneid) {
14385: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
14386: if ($context ne 'auto') {
14387: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
14388: }
14389: $outcome .= $clonemsg.$linefeed;
14390: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 14391: # Copy all files
1.637 www 14392: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 14393: # Restore URL
1.566 albertel 14394: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 14395: # Restore title
1.566 albertel 14396: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 14397: # Restore creation date, creator and creation context.
14398: $cenv{'internal.created'}=$oldcenv{'internal.created'};
14399: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
14400: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 14401: # Mark as cloned
1.566 albertel 14402: $cenv{'clonedfrom'}=$cloneid;
1.638 www 14403: # Need to clone grading mode
14404: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
14405: $cenv{'grading'}=$newenv{'grading'};
14406: # Do not clone these environment entries
14407: &Apache::lonnet::del('environment',
14408: ['default_enrollment_start_date',
14409: 'default_enrollment_end_date',
14410: 'question.email',
14411: 'policy.email',
14412: 'comment.email',
14413: 'pch.users.denied',
1.725 raeburn 14414: 'plc.users.denied',
14415: 'hidefromcat',
1.1075.2.36 raeburn 14416: 'checkforpriv',
1.1075.2.59 raeburn 14417: 'categories',
14418: 'internal.uniquecode'],
1.638 www 14419: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 14420: if ($args->{'textbook'}) {
14421: $cenv{'internal.textbook'} = $args->{'textbook'};
14422: }
1.444 albertel 14423: }
1.566 albertel 14424:
1.444 albertel 14425: #
14426: # Set environment (will override cloned, if existing)
14427: #
14428: my @sections = ();
14429: my @xlists = ();
14430: if ($args->{'crstype'}) {
14431: $cenv{'type'}=$args->{'crstype'};
14432: }
14433: if ($args->{'crsid'}) {
14434: $cenv{'courseid'}=$args->{'crsid'};
14435: }
14436: if ($args->{'crscode'}) {
14437: $cenv{'internal.coursecode'}=$args->{'crscode'};
14438: }
14439: if ($args->{'crsquota'} ne '') {
14440: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14441: } else {
14442: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14443: }
14444: if ($args->{'ccuname'}) {
14445: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14446: ':'.$args->{'ccdomain'};
14447: } else {
14448: $cenv{'internal.courseowner'} = $args->{'curruser'};
14449: }
1.1075.2.31 raeburn 14450: if ($args->{'defaultcredits'}) {
14451: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14452: }
1.444 albertel 14453: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14454: if ($args->{'crssections'}) {
14455: $cenv{'internal.sectionnums'} = '';
14456: if ($args->{'crssections'} =~ m/,/) {
14457: @sections = split/,/,$args->{'crssections'};
14458: } else {
14459: $sections[0] = $args->{'crssections'};
14460: }
14461: if (@sections > 0) {
14462: foreach my $item (@sections) {
14463: my ($sec,$gp) = split/:/,$item;
14464: my $class = $args->{'crscode'}.$sec;
14465: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14466: $cenv{'internal.sectionnums'} .= $item.',';
14467: unless ($addcheck eq 'ok') {
14468: push @badclasses, $class;
14469: }
14470: }
14471: $cenv{'internal.sectionnums'} =~ s/,$//;
14472: }
14473: }
14474: # do not hide course coordinator from staff listing,
14475: # even if privileged
14476: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 14477: # add course coordinator's domain to domains to check for privileged users
14478: # if different to course domain
14479: if ($$crsudom ne $args->{'ccdomain'}) {
14480: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14481: }
1.444 albertel 14482: # add crosslistings
14483: if ($args->{'crsxlist'}) {
14484: $cenv{'internal.crosslistings'}='';
14485: if ($args->{'crsxlist'} =~ m/,/) {
14486: @xlists = split/,/,$args->{'crsxlist'};
14487: } else {
14488: $xlists[0] = $args->{'crsxlist'};
14489: }
14490: if (@xlists > 0) {
14491: foreach my $item (@xlists) {
14492: my ($xl,$gp) = split/:/,$item;
14493: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14494: $cenv{'internal.crosslistings'} .= $item.',';
14495: unless ($addcheck eq 'ok') {
14496: push @badclasses, $xl;
14497: }
14498: }
14499: $cenv{'internal.crosslistings'} =~ s/,$//;
14500: }
14501: }
14502: if ($args->{'autoadds'}) {
14503: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14504: }
14505: if ($args->{'autodrops'}) {
14506: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14507: }
14508: # check for notification of enrollment changes
14509: my @notified = ();
14510: if ($args->{'notify_owner'}) {
14511: if ($args->{'ccuname'} ne '') {
14512: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14513: }
14514: }
14515: if ($args->{'notify_dc'}) {
14516: if ($uname ne '') {
1.630 raeburn 14517: push(@notified,$uname.':'.$udom);
1.444 albertel 14518: }
14519: }
14520: if (@notified > 0) {
14521: my $notifylist;
14522: if (@notified > 1) {
14523: $notifylist = join(',',@notified);
14524: } else {
14525: $notifylist = $notified[0];
14526: }
14527: $cenv{'internal.notifylist'} = $notifylist;
14528: }
14529: if (@badclasses > 0) {
14530: my %lt=&Apache::lonlocal::texthash(
14531: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course. However, if automated course roster updates are enabled for this class, these particular sections/crosslistings will not contribute towards enrollment, because the user identified as the course owner for this LON-CAPA course',
14532: 'dnhr' => 'does not have rights to access enrollment in these classes',
14533: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14534: );
1.541 raeburn 14535: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14536: ' ('.$lt{'adby'}.')';
14537: if ($context eq 'auto') {
14538: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14539: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14540: foreach my $item (@badclasses) {
14541: if ($context eq 'auto') {
14542: $outcome .= " - $item\n";
14543: } else {
14544: $outcome .= "<li>$item</li>\n";
14545: }
14546: }
14547: if ($context eq 'auto') {
14548: $outcome .= $linefeed;
14549: } else {
1.566 albertel 14550: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14551: }
14552: }
1.444 albertel 14553: }
14554: if ($args->{'no_end_date'}) {
14555: $args->{'endaccess'} = 0;
14556: }
14557: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14558: $cenv{'internal.autoend'}=$args->{'enrollend'};
14559: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14560: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14561: if ($args->{'showphotos'}) {
14562: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14563: }
14564: $cenv{'internal.authtype'} = $args->{'authtype'};
14565: $cenv{'internal.autharg'} = $args->{'autharg'};
14566: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14567: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14568: 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');
14569: if ($context eq 'auto') {
14570: $outcome .= $krb_msg;
14571: } else {
1.566 albertel 14572: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14573: }
14574: $outcome .= $linefeed;
1.444 albertel 14575: }
14576: }
14577: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14578: if ($args->{'setpolicy'}) {
14579: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14580: }
14581: if ($args->{'setcontent'}) {
14582: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14583: }
14584: }
14585: if ($args->{'reshome'}) {
14586: $cenv{'reshome'}=$args->{'reshome'}.'/';
14587: $cenv{'reshome'}=~s/\/+$/\//;
14588: }
14589: #
14590: # course has keyed access
14591: #
14592: if ($args->{'setkeys'}) {
14593: $cenv{'keyaccess'}='yes';
14594: }
14595: # if specified, key authority is not course, but user
14596: # only active if keyaccess is yes
14597: if ($args->{'keyauth'}) {
1.487 albertel 14598: my ($user,$domain) = split(':',$args->{'keyauth'});
14599: $user = &LONCAPA::clean_username($user);
14600: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14601: if ($user ne '' && $domain ne '') {
1.487 albertel 14602: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14603: }
14604: }
14605:
1.1075.2.59 raeburn 14606: #
14607: # generate and store uniquecode (available to course requester), if course should have one.
14608: #
14609: if ($args->{'uniquecode'}) {
14610: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
14611: if ($code) {
14612: $cenv{'internal.uniquecode'} = $code;
14613: my %crsinfo =
14614: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
14615: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
14616: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
14617: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
14618: }
14619: if (ref($coderef)) {
14620: $$coderef = $code;
14621: }
14622: }
14623: }
14624:
1.444 albertel 14625: if ($args->{'disresdis'}) {
14626: $cenv{'pch.roles.denied'}='st';
14627: }
14628: if ($args->{'disablechat'}) {
14629: $cenv{'plc.roles.denied'}='st';
14630: }
14631:
14632: # Record we've not yet viewed the Course Initialization Helper for this
14633: # course
14634: $cenv{'course.helper.not.run'} = 1;
14635: #
14636: # Use new Randomseed
14637: #
14638: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14639: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14640: #
14641: # The encryption code and receipt prefix for this course
14642: #
14643: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14644: $cenv{'internal.encpref'}=100+int(9*rand(99));
14645: #
14646: # By default, use standard grading
14647: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14648:
1.541 raeburn 14649: $outcome .= $linefeed.&mt('Setting environment').': '.
14650: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14651: #
14652: # Open all assignments
14653: #
14654: if ($args->{'openall'}) {
14655: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14656: my %storecontent = ($storeunder => time,
14657: $storeunder.'.type' => 'date_start');
14658:
14659: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14660: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14661: }
14662: #
14663: # Set first page
14664: #
14665: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14666: || ($cloneid)) {
1.445 albertel 14667: use LONCAPA::map;
1.444 albertel 14668: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14669:
14670: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14671: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14672:
1.444 albertel 14673: $outcome .= ($fatal?$errtext:'read ok').' - ';
14674: my $title; my $url;
14675: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14676: $title=&mt('Syllabus');
1.444 albertel 14677: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14678: } else {
1.963 raeburn 14679: $title=&mt('Table of Contents');
1.444 albertel 14680: $url='/adm/navmaps';
14681: }
1.445 albertel 14682:
14683: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14684: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14685:
14686: if ($errtext) { $fatal=2; }
1.541 raeburn 14687: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14688: }
1.566 albertel 14689:
14690: return (1,$outcome);
1.444 albertel 14691: }
14692:
1.1075.2.59 raeburn 14693: sub make_unique_code {
14694: my ($cdom,$cnum) = @_;
14695: # get lock on uniquecodes db
14696: my $lockhash = {
14697: $cnum."\0".'uniquecodes' => $env{'user.name'}.
14698: ':'.$env{'user.domain'},
14699: };
14700: my $tries = 0;
14701: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14702: my ($code,$error);
14703:
14704: while (($gotlock ne 'ok') && ($tries<3)) {
14705: $tries ++;
14706: sleep 1;
14707: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14708: }
14709: if ($gotlock eq 'ok') {
14710: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
14711: my $gotcode;
14712: my $attempts = 0;
14713: while ((!$gotcode) && ($attempts < 100)) {
14714: $code = &generate_code();
14715: if (!exists($currcodes{$code})) {
14716: $gotcode = 1;
14717: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
14718: $error = 'nostore';
14719: }
14720: }
14721: $attempts ++;
14722: }
14723: my @del_lock = ($cnum."\0".'uniquecodes');
14724: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
14725: } else {
14726: $error = 'nolock';
14727: }
14728: return ($code,$error);
14729: }
14730:
14731: sub generate_code {
14732: my $code;
14733: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
14734: for (my $i=0; $i<6; $i++) {
14735: my $lettnum = int (rand 2);
14736: my $item = '';
14737: if ($lettnum) {
14738: $item = $letts[int( rand(18) )];
14739: } else {
14740: $item = 1+int( rand(8) );
14741: }
14742: $code .= $item;
14743: }
14744: return $code;
14745: }
14746:
1.444 albertel 14747: ############################################################
14748: ############################################################
14749:
1.953 droeschl 14750: #SD
14751: # only Community and Course, or anything else?
1.378 raeburn 14752: sub course_type {
14753: my ($cid) = @_;
14754: if (!defined($cid)) {
14755: $cid = $env{'request.course.id'};
14756: }
1.404 albertel 14757: if (defined($env{'course.'.$cid.'.type'})) {
14758: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14759: } else {
14760: return 'Course';
1.377 raeburn 14761: }
14762: }
1.156 albertel 14763:
1.406 raeburn 14764: sub group_term {
14765: my $crstype = &course_type();
14766: my %names = (
14767: 'Course' => 'group',
1.865 raeburn 14768: 'Community' => 'group',
1.406 raeburn 14769: );
14770: return $names{$crstype};
14771: }
14772:
1.902 raeburn 14773: sub course_types {
1.1075.2.59 raeburn 14774: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 14775: my %typename = (
14776: official => 'Official course',
14777: unofficial => 'Unofficial course',
14778: community => 'Community',
1.1075.2.59 raeburn 14779: textbook => 'Textbook course',
1.902 raeburn 14780: );
14781: return (\@types,\%typename);
14782: }
14783:
1.156 albertel 14784: sub icon {
14785: my ($file)=@_;
1.505 albertel 14786: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14787: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14788: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14789: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14790: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14791: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14792: $curfext.".gif") {
14793: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14794: $curfext.".gif";
14795: }
14796: }
1.249 albertel 14797: return &lonhttpdurl($iconname);
1.154 albertel 14798: }
1.84 albertel 14799:
1.575 albertel 14800: sub lonhttpdurl {
1.692 www 14801: #
14802: # Had been used for "small fry" static images on separate port 8080.
14803: # Modify here if lightweight http functionality desired again.
14804: # Currently eliminated due to increasing firewall issues.
14805: #
1.575 albertel 14806: my ($url)=@_;
1.692 www 14807: return $url;
1.215 albertel 14808: }
14809:
1.213 albertel 14810: sub connection_aborted {
14811: my ($r)=@_;
14812: $r->print(" ");$r->rflush();
14813: my $c = $r->connection;
14814: return $c->aborted();
14815: }
14816:
1.221 foxr 14817: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14818: # strings as 'strings'.
14819: sub escape_single {
1.221 foxr 14820: my ($input) = @_;
1.223 albertel 14821: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14822: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14823: return $input;
14824: }
1.223 albertel 14825:
1.222 foxr 14826: # Same as escape_single, but escape's "'s This
14827: # can be used for "strings"
14828: sub escape_double {
14829: my ($input) = @_;
14830: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14831: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14832: return $input;
14833: }
1.223 albertel 14834:
1.222 foxr 14835: # Escapes the last element of a full URL.
14836: sub escape_url {
14837: my ($url) = @_;
1.238 raeburn 14838: my @urlslices = split(/\//, $url,-1);
1.369 www 14839: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 14840: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 14841: }
1.462 albertel 14842:
1.820 raeburn 14843: sub compare_arrays {
14844: my ($arrayref1,$arrayref2) = @_;
14845: my (@difference,%count);
14846: @difference = ();
14847: %count = ();
14848: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14849: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14850: foreach my $element (keys(%count)) {
14851: if ($count{$element} == 1) {
14852: push(@difference,$element);
14853: }
14854: }
14855: }
14856: return @difference;
14857: }
14858:
1.817 bisitz 14859: # -------------------------------------------------------- Initialize user login
1.462 albertel 14860: sub init_user_environment {
1.463 albertel 14861: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14862: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14863:
14864: my $public=($username eq 'public' && $domain eq 'public');
14865:
14866: # See if old ID present, if so, remove
14867:
1.1062 raeburn 14868: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14869: my $now=time;
14870:
14871: if ($public) {
14872: my $max_public=100;
14873: my $oldest;
14874: my $oldest_time=0;
14875: for(my $next=1;$next<=$max_public;$next++) {
14876: if (-e $lonids."/publicuser_$next.id") {
14877: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14878: if ($mtime<$oldest_time || !$oldest_time) {
14879: $oldest_time=$mtime;
14880: $oldest=$next;
14881: }
14882: } else {
14883: $cookie="publicuser_$next";
14884: last;
14885: }
14886: }
14887: if (!$cookie) { $cookie="publicuser_$oldest"; }
14888: } else {
1.463 albertel 14889: # if this isn't a robot, kill any existing non-robot sessions
14890: if (!$args->{'robot'}) {
14891: opendir(DIR,$lonids);
14892: while ($filename=readdir(DIR)) {
14893: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14894: unlink($lonids.'/'.$filename);
14895: }
1.462 albertel 14896: }
1.463 albertel 14897: closedir(DIR);
1.1075.2.84 raeburn 14898: # If there is a undeleted lockfile for the user's paste buffer remove it.
14899: my $namespace = 'nohist_courseeditor';
14900: my $lockingkey = 'paste'."\0".'locked_num';
14901: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
14902: $domain,$username);
14903: if (exists($lockhash{$lockingkey})) {
14904: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
14905: unless ($delresult eq 'ok') {
14906: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
14907: }
14908: }
1.462 albertel 14909: }
14910: # Give them a new cookie
1.463 albertel 14911: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14912: : $now.$$.int(rand(10000)));
1.463 albertel 14913: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14914:
14915: # Initialize roles
14916:
1.1062 raeburn 14917: ($userroles,$firstaccenv,$timerintenv) =
14918: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14919: }
14920: # ------------------------------------ Check browser type and MathML capability
14921:
1.1075.2.77 raeburn 14922: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
14923: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 14924:
14925: # ------------------------------------------------------------- Get environment
14926:
14927: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14928: my ($tmp) = keys(%userenv);
14929: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14930: } else {
14931: undef(%userenv);
14932: }
14933: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14934: $form->{'interface'}=$userenv{'interface'};
14935: }
14936: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14937:
14938: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14939: foreach my $option ('interface','localpath','localres') {
14940: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14941: }
14942: # --------------------------------------------------------- Write first profile
14943:
14944: {
14945: my %initial_env =
14946: ("user.name" => $username,
14947: "user.domain" => $domain,
14948: "user.home" => $authhost,
14949: "browser.type" => $clientbrowser,
14950: "browser.version" => $clientversion,
14951: "browser.mathml" => $clientmathml,
14952: "browser.unicode" => $clientunicode,
14953: "browser.os" => $clientos,
1.1075.2.42 raeburn 14954: "browser.mobile" => $clientmobile,
14955: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 14956: "browser.osversion" => $clientosversion,
1.462 albertel 14957: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14958: "request.course.fn" => '',
14959: "request.course.uri" => '',
14960: "request.course.sec" => '',
14961: "request.role" => 'cm',
14962: "request.role.adv" => $env{'user.adv'},
14963: "request.host" => $ENV{'REMOTE_ADDR'},);
14964:
14965: if ($form->{'localpath'}) {
14966: $initial_env{"browser.localpath"} = $form->{'localpath'};
14967: $initial_env{"browser.localres"} = $form->{'localres'};
14968: }
14969:
14970: if ($form->{'interface'}) {
14971: $form->{'interface'}=~s/\W//gs;
14972: $initial_env{"browser.interface"} = $form->{'interface'};
14973: $env{'browser.interface'}=$form->{'interface'};
14974: }
14975:
1.1075.2.54 raeburn 14976: if ($form->{'iptoken'}) {
14977: my $lonhost = $r->dir_config('lonHostID');
14978: $initial_env{"user.noloadbalance"} = $lonhost;
14979: $env{'user.noloadbalance'} = $lonhost;
14980: }
14981:
1.981 raeburn 14982: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14983: my %domdef;
14984: unless ($domain eq 'public') {
14985: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14986: }
1.980 raeburn 14987:
1.1075.2.7 raeburn 14988: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14989: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14990: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14991: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14992: }
14993:
1.1075.2.59 raeburn 14994: foreach my $crstype ('official','unofficial','community','textbook') {
1.765 raeburn 14995: $userenv{'canrequest.'.$crstype} =
14996: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14997: 'reload','requestcourses',
14998: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14999: }
15000:
1.1075.2.14 raeburn 15001: $userenv{'canrequest.author'} =
15002: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15003: 'reload','requestauthor',
15004: \%userenv,\%domdef,\%is_adv);
15005: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15006: $domain,$username);
15007: my $reqstatus = $reqauthor{'author_status'};
15008: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15009: if (ref($reqauthor{'author'}) eq 'HASH') {
15010: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15011: $reqauthor{'author'}{'timestamp'};
15012: }
15013: }
15014:
1.462 albertel 15015: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15016:
1.462 albertel 15017: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
15018: &GDBM_WRCREAT(),0640)) {
15019: &_add_to_env(\%disk_env,\%initial_env);
15020: &_add_to_env(\%disk_env,\%userenv,'environment.');
15021: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 15022: if (ref($firstaccenv) eq 'HASH') {
15023: &_add_to_env(\%disk_env,$firstaccenv);
15024: }
15025: if (ref($timerintenv) eq 'HASH') {
15026: &_add_to_env(\%disk_env,$timerintenv);
15027: }
1.463 albertel 15028: if (ref($args->{'extra_env'})) {
15029: &_add_to_env(\%disk_env,$args->{'extra_env'});
15030: }
1.462 albertel 15031: untie(%disk_env);
15032: } else {
1.705 tempelho 15033: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
15034: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 15035: return 'error: '.$!;
15036: }
15037: }
15038: $env{'request.role'}='cm';
15039: $env{'request.role.adv'}=$env{'user.adv'};
15040: $env{'browser.type'}=$clientbrowser;
15041:
15042: return $cookie;
15043:
15044: }
15045:
15046: sub _add_to_env {
15047: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 15048: if (ref($env_data) eq 'HASH') {
15049: while (my ($key,$value) = each(%$env_data)) {
15050: $idf->{$prefix.$key} = $value;
15051: $env{$prefix.$key} = $value;
15052: }
1.462 albertel 15053: }
15054: }
15055:
1.685 tempelho 15056: # --- Get the symbolic name of a problem and the url
15057: sub get_symb {
15058: my ($request,$silent) = @_;
1.726 raeburn 15059: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 15060: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
15061: if ($symb eq '') {
15062: if (!$silent) {
1.1071 raeburn 15063: if (ref($request)) {
15064: $request->print("Unable to handle ambiguous references:$url:.");
15065: }
1.685 tempelho 15066: return ();
15067: }
15068: }
15069: &Apache::lonenc::check_decrypt(\$symb);
15070: return ($symb);
15071: }
15072:
15073: # --------------------------------------------------------------Get annotation
15074:
15075: sub get_annotation {
15076: my ($symb,$enc) = @_;
15077:
15078: my $key = $symb;
15079: if (!$enc) {
15080: $key =
15081: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
15082: }
15083: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
15084: return $annotation{$key};
15085: }
15086:
15087: sub clean_symb {
1.731 raeburn 15088: my ($symb,$delete_enc) = @_;
1.685 tempelho 15089:
15090: &Apache::lonenc::check_decrypt(\$symb);
15091: my $enc = $env{'request.enc'};
1.731 raeburn 15092: if ($delete_enc) {
1.730 raeburn 15093: delete($env{'request.enc'});
15094: }
1.685 tempelho 15095:
15096: return ($symb,$enc);
15097: }
1.462 albertel 15098:
1.1075.2.69 raeburn 15099: ############################################################
15100: ############################################################
15101:
15102: =pod
15103:
15104: =head1 Routines for building display used to search for courses
15105:
15106:
15107: =over 4
15108:
15109: =item * &build_filters()
15110:
15111: Create markup for a table used to set filters to use when selecting
15112: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
15113: and quotacheck.pl
15114:
15115:
15116: Inputs:
15117:
15118: filterlist - anonymous array of fields to include as potential filters
15119:
15120: crstype - course type
15121:
15122: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
15123: to pop-open a course selector (will contain "extra element").
15124:
15125: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
15126:
15127: filter - anonymous hash of criteria and their values
15128:
15129: action - form action
15130:
15131: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
15132:
15133: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
15134:
15135: cloneruname - username of owner of new course who wants to clone
15136:
15137: clonerudom - domain of owner of new course who wants to clone
15138:
15139: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
15140:
15141: codetitlesref - reference to array of titles of components in institutional codes (official courses)
15142:
15143: codedom - domain
15144:
15145: formname - value of form element named "form".
15146:
15147: fixeddom - domain, if fixed.
15148:
15149: prevphase - value to assign to form element named "phase" when going back to the previous screen
15150:
15151: cnameelement - name of form element in form on opener page which will receive title of selected course
15152:
15153: cnumelement - name of form element in form on opener page which will receive courseID of selected course
15154:
15155: cdomelement - name of form element in form on opener page which will receive domain of selected course
15156:
15157: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
15158:
15159: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
15160:
15161: clonewarning - warning message about missing information for intended course owner when DC creates a course
15162:
15163:
15164: Returns: $output - HTML for display of search criteria, and hidden form elements.
15165:
15166:
15167: Side Effects: None
15168:
15169: =cut
15170:
15171: # ---------------------------------------------- search for courses based on last activity etc.
15172:
15173: sub build_filters {
15174: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
15175: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
15176: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
15177: $cnameelement,$cnumelement,$cdomelement,$setroles,
15178: $clonetext,$clonewarning) = @_;
15179: my ($list,$jscript);
15180: my $onchange = 'javascript:updateFilters(this)';
15181: my ($domainselectform,$sincefilterform,$createdfilterform,
15182: $ownerdomselectform,$persondomselectform,$instcodeform,
15183: $typeselectform,$instcodetitle);
15184: if ($formname eq '') {
15185: $formname = $caller;
15186: }
15187: foreach my $item (@{$filterlist}) {
15188: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
15189: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
15190: if ($item eq 'domainfilter') {
15191: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
15192: } elsif ($item eq 'coursefilter') {
15193: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
15194: } elsif ($item eq 'ownerfilter') {
15195: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15196: } elsif ($item eq 'ownerdomfilter') {
15197: $filter->{'ownerdomfilter'} =
15198: &LONCAPA::clean_domain($filter->{$item});
15199: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
15200: 'ownerdomfilter',1);
15201: } elsif ($item eq 'personfilter') {
15202: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15203: } elsif ($item eq 'persondomfilter') {
15204: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
15205: 'persondomfilter',1);
15206: } else {
15207: $filter->{$item} =~ s/\W//g;
15208: }
15209: if (!$filter->{$item}) {
15210: $filter->{$item} = '';
15211: }
15212: }
15213: if ($item eq 'domainfilter') {
15214: my $allow_blank = 1;
15215: if ($formname eq 'portform') {
15216: $allow_blank=0;
15217: } elsif ($formname eq 'studentform') {
15218: $allow_blank=0;
15219: }
15220: if ($fixeddom) {
15221: $domainselectform = '<input type="hidden" name="domainfilter"'.
15222: ' value="'.$codedom.'" />'.
15223: &Apache::lonnet::domain($codedom,'description');
15224: } else {
15225: $domainselectform = &select_dom_form($filter->{$item},
15226: 'domainfilter',
15227: $allow_blank,'',$onchange);
15228: }
15229: } else {
15230: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
15231: }
15232: }
15233:
15234: # last course activity filter and selection
15235: $sincefilterform = &timebased_select_form('sincefilter',$filter);
15236:
15237: # course created filter and selection
15238: if (exists($filter->{'createdfilter'})) {
15239: $createdfilterform = &timebased_select_form('createdfilter',$filter);
15240: }
15241:
15242: my %lt = &Apache::lonlocal::texthash(
15243: 'cac' => "$crstype Activity",
15244: 'ccr' => "$crstype Created",
15245: 'cde' => "$crstype Title",
15246: 'cdo' => "$crstype Domain",
15247: 'ins' => 'Institutional Code',
15248: 'inc' => 'Institutional Categorization',
15249: 'cow' => "$crstype Owner/Co-owner",
15250: 'cop' => "$crstype Personnel Includes",
15251: 'cog' => 'Type',
15252: );
15253:
15254: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15255: my $typeval = 'Course';
15256: if ($crstype eq 'Community') {
15257: $typeval = 'Community';
15258: }
15259: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
15260: } else {
15261: $typeselectform = '<select name="type" size="1"';
15262: if ($onchange) {
15263: $typeselectform .= ' onchange="'.$onchange.'"';
15264: }
15265: $typeselectform .= '>'."\n";
15266: foreach my $posstype ('Course','Community') {
15267: $typeselectform.='<option value="'.$posstype.'"'.
15268: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
15269: }
15270: $typeselectform.="</select>";
15271: }
15272:
15273: my ($cloneableonlyform,$cloneabletitle);
15274: if (exists($filter->{'cloneableonly'})) {
15275: my $cloneableon = '';
15276: my $cloneableoff = ' checked="checked"';
15277: if ($filter->{'cloneableonly'}) {
15278: $cloneableon = $cloneableoff;
15279: $cloneableoff = '';
15280: }
15281: $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>';
15282: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 15283: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 15284: } else {
15285: $cloneabletitle = &mt('Cloneable by you');
15286: }
15287: }
15288: my $officialjs;
15289: if ($crstype eq 'Course') {
15290: if (exists($filter->{'instcodefilter'})) {
15291: # if (($fixeddom) || ($formname eq 'requestcrs') ||
15292: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
15293: if ($codedom) {
15294: $officialjs = 1;
15295: ($instcodeform,$jscript,$$numtitlesref) =
15296: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
15297: $officialjs,$codetitlesref);
15298: if ($jscript) {
15299: $jscript = '<script type="text/javascript">'."\n".
15300: '// <![CDATA['."\n".
15301: $jscript."\n".
15302: '// ]]>'."\n".
15303: '</script>'."\n";
15304: }
15305: }
15306: if ($instcodeform eq '') {
15307: $instcodeform =
15308: '<input type="text" name="instcodefilter" size="10" value="'.
15309: $list->{'instcodefilter'}.'" />';
15310: $instcodetitle = $lt{'ins'};
15311: } else {
15312: $instcodetitle = $lt{'inc'};
15313: }
15314: if ($fixeddom) {
15315: $instcodetitle .= '<br />('.$codedom.')';
15316: }
15317: }
15318: }
15319: my $output = qq|
15320: <form method="post" name="filterpicker" action="$action">
15321: <input type="hidden" name="form" value="$formname" />
15322: |;
15323: if ($formname eq 'modifycourse') {
15324: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
15325: '<input type="hidden" name="prevphase" value="'.
15326: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 15327: } elsif ($formname eq 'quotacheck') {
15328: $output .= qq|
15329: <input type="hidden" name="sortby" value="" />
15330: <input type="hidden" name="sortorder" value="" />
15331: |;
15332: } else {
1.1075.2.69 raeburn 15333: my $name_input;
15334: if ($cnameelement ne '') {
15335: $name_input = '<input type="hidden" name="cnameelement" value="'.
15336: $cnameelement.'" />';
15337: }
15338: $output .= qq|
15339: <input type="hidden" name="cnumelement" value="$cnumelement" />
15340: <input type="hidden" name="cdomelement" value="$cdomelement" />
15341: $name_input
15342: $roleelement
15343: $multelement
15344: $typeelement
15345: |;
15346: if ($formname eq 'portform') {
15347: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
15348: }
15349: }
15350: if ($fixeddom) {
15351: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
15352: }
15353: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
15354: if ($sincefilterform) {
15355: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
15356: .$sincefilterform
15357: .&Apache::lonhtmlcommon::row_closure();
15358: }
15359: if ($createdfilterform) {
15360: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
15361: .$createdfilterform
15362: .&Apache::lonhtmlcommon::row_closure();
15363: }
15364: if ($domainselectform) {
15365: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
15366: .$domainselectform
15367: .&Apache::lonhtmlcommon::row_closure();
15368: }
15369: if ($typeselectform) {
15370: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15371: $output .= $typeselectform;
15372: } else {
15373: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
15374: .$typeselectform
15375: .&Apache::lonhtmlcommon::row_closure();
15376: }
15377: }
15378: if ($instcodeform) {
15379: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
15380: .$instcodeform
15381: .&Apache::lonhtmlcommon::row_closure();
15382: }
15383: if (exists($filter->{'ownerfilter'})) {
15384: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
15385: '<table><tr><td>'.&mt('Username').'<br />'.
15386: '<input type="text" name="ownerfilter" size="20" value="'.
15387: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15388: $ownerdomselectform.'</td></tr></table>'.
15389: &Apache::lonhtmlcommon::row_closure();
15390: }
15391: if (exists($filter->{'personfilter'})) {
15392: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
15393: '<table><tr><td>'.&mt('Username').'<br />'.
15394: '<input type="text" name="personfilter" size="20" value="'.
15395: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15396: $persondomselectform.'</td></tr></table>'.
15397: &Apache::lonhtmlcommon::row_closure();
15398: }
15399: if (exists($filter->{'coursefilter'})) {
15400: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
15401: .'<input type="text" name="coursefilter" size="25" value="'
15402: .$list->{'coursefilter'}.'" />'
15403: .&Apache::lonhtmlcommon::row_closure();
15404: }
15405: if ($cloneableonlyform) {
15406: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
15407: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
15408: }
15409: if (exists($filter->{'descriptfilter'})) {
15410: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
15411: .'<input type="text" name="descriptfilter" size="40" value="'
15412: .$list->{'descriptfilter'}.'" />'
15413: .&Apache::lonhtmlcommon::row_closure(1);
15414: }
15415: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
15416: '<input type="hidden" name="updater" value="" />'."\n".
15417: '<input type="submit" name="gosearch" value="'.
15418: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
15419: return $jscript.$clonewarning.$output;
15420: }
15421:
15422: =pod
15423:
15424: =item * &timebased_select_form()
15425:
15426: Create markup for a dropdown list used to select a time-based
15427: filter e.g., Course Activity, Course Created, when searching for courses
15428: or communities
15429:
15430: Inputs:
15431:
15432: item - name of form element (sincefilter or createdfilter)
15433:
15434: filter - anonymous hash of criteria and their values
15435:
15436: Returns: HTML for a select box contained a blank, then six time selections,
15437: with value set in incoming form variables currently selected.
15438:
15439: Side Effects: None
15440:
15441: =cut
15442:
15443: sub timebased_select_form {
15444: my ($item,$filter) = @_;
15445: if (ref($filter) eq 'HASH') {
15446: $filter->{$item} =~ s/[^\d-]//g;
15447: if (!$filter->{$item}) { $filter->{$item}=-1; }
15448: return &select_form(
15449: $filter->{$item},
15450: $item,
15451: { '-1' => '',
15452: '86400' => &mt('today'),
15453: '604800' => &mt('last week'),
15454: '2592000' => &mt('last month'),
15455: '7776000' => &mt('last three months'),
15456: '15552000' => &mt('last six months'),
15457: '31104000' => &mt('last year'),
15458: 'select_form_order' =>
15459: ['-1','86400','604800','2592000','7776000',
15460: '15552000','31104000']});
15461: }
15462: }
15463:
15464: =pod
15465:
15466: =item * &js_changer()
15467:
15468: Create script tag containing Javascript used to submit course search form
15469: when course type or domain is changed, and also to hide 'Searching ...' on
15470: page load completion for page showing search result.
15471:
15472: Inputs: None
15473:
15474: Returns: markup containing updateFilters() and hideSearching() javascript functions.
15475:
15476: Side Effects: None
15477:
15478: =cut
15479:
15480: sub js_changer {
15481: return <<ENDJS;
15482: <script type="text/javascript">
15483: // <![CDATA[
15484: function updateFilters(caller) {
15485: if (typeof(caller) != "undefined") {
15486: document.filterpicker.updater.value = caller.name;
15487: }
15488: document.filterpicker.submit();
15489: }
15490:
15491: function hideSearching() {
15492: if (document.getElementById('searching')) {
15493: document.getElementById('searching').style.display = 'none';
15494: }
15495: return;
15496: }
15497:
15498: // ]]>
15499: </script>
15500:
15501: ENDJS
15502: }
15503:
15504: =pod
15505:
15506: =item * &search_courses()
15507:
15508: Process selected filters form course search form and pass to lonnet::courseiddump
15509: to retrieve a hash for which keys are courseIDs which match the selected filters.
15510:
15511: Inputs:
15512:
15513: dom - domain being searched
15514:
15515: type - course type ('Course' or 'Community' or '.' if any).
15516:
15517: filter - anonymous hash of criteria and their values
15518:
15519: numtitles - for institutional codes - number of categories
15520:
15521: cloneruname - optional username of new course owner
15522:
15523: clonerudom - optional domain of new course owner
15524:
1.1075.2.95 raeburn 15525: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 15526: (used when DC is using course creation form)
15527:
15528: codetitles - reference to array of titles of components in institutional codes (official courses).
15529:
1.1075.2.95 raeburn 15530: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
15531: (and so can clone automatically)
15532:
15533: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
15534:
15535: reqinstcode - institutional code of new course, where search_courses is used to identify potential
15536: courses to clone
1.1075.2.69 raeburn 15537:
15538: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
15539:
15540:
15541: Side Effects: None
15542:
15543: =cut
15544:
15545:
15546: sub search_courses {
1.1075.2.95 raeburn 15547: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
15548: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 15549: my (%courses,%showcourses,$cloner);
15550: if (($filter->{'ownerfilter'} ne '') ||
15551: ($filter->{'ownerdomfilter'} ne '')) {
15552: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
15553: $filter->{'ownerdomfilter'};
15554: }
15555: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
15556: if (!$filter->{$item}) {
15557: $filter->{$item}='.';
15558: }
15559: }
15560: my $now = time;
15561: my $timefilter =
15562: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
15563: my ($createdbefore,$createdafter);
15564: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
15565: $createdbefore = $now;
15566: $createdafter = $now-$filter->{'createdfilter'};
15567: }
15568: my ($instcodefilter,$regexpok);
15569: if ($numtitles) {
15570: if ($env{'form.official'} eq 'on') {
15571: $instcodefilter =
15572: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15573: $regexpok = 1;
15574: } elsif ($env{'form.official'} eq 'off') {
15575: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15576: unless ($instcodefilter eq '') {
15577: $regexpok = -1;
15578: }
15579: }
15580: } else {
15581: $instcodefilter = $filter->{'instcodefilter'};
15582: }
15583: if ($instcodefilter eq '') { $instcodefilter = '.'; }
15584: if ($type eq '') { $type = '.'; }
15585:
15586: if (($clonerudom ne '') && ($cloneruname ne '')) {
15587: $cloner = $cloneruname.':'.$clonerudom;
15588: }
15589: %courses = &Apache::lonnet::courseiddump($dom,
15590: $filter->{'descriptfilter'},
15591: $timefilter,
15592: $instcodefilter,
15593: $filter->{'combownerfilter'},
15594: $filter->{'coursefilter'},
15595: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 15596: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 15597: $filter->{'cloneableonly'},
15598: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 15599: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 15600: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
15601: my $ccrole;
15602: if ($type eq 'Community') {
15603: $ccrole = 'co';
15604: } else {
15605: $ccrole = 'cc';
15606: }
15607: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
15608: $filter->{'persondomfilter'},
15609: 'userroles',undef,
15610: [$ccrole,'in','ad','ep','ta','cr'],
15611: $dom);
15612: foreach my $role (keys(%rolehash)) {
15613: my ($cnum,$cdom,$courserole) = split(':',$role);
15614: my $cid = $cdom.'_'.$cnum;
15615: if (exists($courses{$cid})) {
15616: if (ref($courses{$cid}) eq 'HASH') {
15617: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
15618: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
15619: push (@{$courses{$cid}{roles}},$courserole);
15620: }
15621: } else {
15622: $courses{$cid}{roles} = [$courserole];
15623: }
15624: $showcourses{$cid} = $courses{$cid};
15625: }
15626: }
15627: }
15628: %courses = %showcourses;
15629: }
15630: return %courses;
15631: }
15632:
15633: =pod
15634:
15635: =back
15636:
1.1075.2.88 raeburn 15637: =head1 Routines for version requirements for current course.
15638:
15639: =over 4
15640:
15641: =item * &check_release_required()
15642:
15643: Compares required LON-CAPA version with version on server, and
15644: if required version is newer looks for a server with the required version.
15645:
15646: Looks first at servers in user's owen domain; if none suitable, looks at
15647: servers in course's domain are permitted to host sessions for user's domain.
15648:
15649: Inputs:
15650:
15651: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
15652:
15653: $courseid - Course ID of current course
15654:
15655: $rolecode - User's current role in course (for switchserver query string).
15656:
15657: $required - LON-CAPA version needed by course (format: Major.Minor).
15658:
15659:
15660: Returns:
15661:
15662: $switchserver - query string tp append to /adm/switchserver call (if
15663: current server's LON-CAPA version is too old.
15664:
15665: $warning - Message is displayed if no suitable server could be found.
15666:
15667: =cut
15668:
15669: sub check_release_required {
15670: my ($loncaparev,$courseid,$rolecode,$required) = @_;
15671: my ($switchserver,$warning);
15672: if ($required ne '') {
15673: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
15674: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
15675: if ($reqdmajor ne '' && $reqdminor ne '') {
15676: my $otherserver;
15677: if (($major eq '' && $minor eq '') ||
15678: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
15679: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
15680: my $switchlcrev =
15681: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
15682: $userdomserver);
15683: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
15684: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
15685: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
15686: my $cdom = $env{'course.'.$courseid.'.domain'};
15687: if ($cdom ne $env{'user.domain'}) {
15688: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
15689: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
15690: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
15691: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
15692: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
15693: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
15694: my $canhost =
15695: &Apache::lonnet::can_host_session($env{'user.domain'},
15696: $coursedomserver,
15697: $remoterev,
15698: $udomdefaults{'remotesessions'},
15699: $defdomdefaults{'hostedsessions'});
15700:
15701: if ($canhost) {
15702: $otherserver = $coursedomserver;
15703: } else {
15704: $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.");
15705: }
15706: } else {
15707: $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).");
15708: }
15709: } else {
15710: $otherserver = $userdomserver;
15711: }
15712: }
15713: if ($otherserver ne '') {
15714: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
15715: }
15716: }
15717: }
15718: return ($switchserver,$warning);
15719: }
15720:
15721: =pod
15722:
15723: =item * &check_release_result()
15724:
15725: Inputs:
15726:
15727: $switchwarning - Warning message if no suitable server found to host session.
15728:
15729: $switchserver - query string to append to /adm/switchserver containing lonHostID
15730: and current role.
15731:
15732: Returns: HTML to display with information about requirement to switch server.
15733: Either displaying warning with link to Roles/Courses screen or
15734: display link to switchserver.
15735:
1.1075.2.69 raeburn 15736: =cut
15737:
1.1075.2.88 raeburn 15738: sub check_release_result {
15739: my ($switchwarning,$switchserver) = @_;
15740: my $output = &start_page('Selected course unavailable on this server').
15741: '<p class="LC_warning">';
15742: if ($switchwarning) {
15743: $output .= $switchwarning.'<br /><a href="/adm/roles">';
15744: if (&show_course()) {
15745: $output .= &mt('Display courses');
15746: } else {
15747: $output .= &mt('Display roles');
15748: }
15749: $output .= '</a>';
15750: } elsif ($switchserver) {
15751: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
15752: '<br />'.
15753: '<a href="/adm/switchserver?'.$switchserver.'">'.
15754: &mt('Switch Server').
15755: '</a>';
15756: }
15757: $output .= '</p>'.&end_page();
15758: return $output;
15759: }
15760:
15761: =pod
15762:
15763: =item * &needs_coursereinit()
15764:
15765: Determine if course contents stored for user's session needs to be
15766: refreshed, because content has changed since "Big Hash" last tied.
15767:
15768: Check for change is made if time last checked is more than 10 minutes ago
15769: (by default).
15770:
15771: Inputs:
15772:
15773: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
15774:
15775: $interval (optional) - Time which may elapse (in s) between last check for content
15776: change in current course. (default: 600 s).
15777:
15778: Returns: an array; first element is:
15779:
15780: =over 4
15781:
15782: 'switch' - if content updates mean user's session
15783: needs to be switched to a server running a newer LON-CAPA version
15784:
15785: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
15786: on current server hosting user's session
15787:
15788: '' - if no action required.
15789:
15790: =back
15791:
15792: If first item element is 'switch':
15793:
15794: second item is $switchwarning - Warning message if no suitable server found to host session.
15795:
15796: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
15797: and current role.
15798:
15799: otherwise: no other elements returned.
15800:
15801: =back
15802:
15803: =cut
15804:
15805: sub needs_coursereinit {
15806: my ($loncaparev,$interval) = @_;
15807: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
15808: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
15809: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
15810: my $now = time;
15811: if ($interval eq '') {
15812: $interval = 600;
15813: }
15814: if (($now-$env{'request.course.timechecked'})>$interval) {
15815: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
15816: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
15817: if ($lastchange > $env{'request.course.tied'}) {
15818: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
15819: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
15820: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
15821: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
15822: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
15823: $curr_reqd_hash{'internal.releaserequired'}});
15824: my ($switchserver,$switchwarning) =
15825: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
15826: $curr_reqd_hash{'internal.releaserequired'});
15827: if ($switchwarning ne '' || $switchserver ne '') {
15828: return ('switch',$switchwarning,$switchserver);
15829: }
15830: }
15831: }
15832: return ('update');
15833: }
15834: }
15835: return ();
15836: }
1.1075.2.69 raeburn 15837:
1.1075.2.11 raeburn 15838: sub update_content_constraints {
15839: my ($cdom,$cnum,$chome,$cid) = @_;
15840: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
15841: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
15842: my %checkresponsetypes;
15843: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
15844: my ($item,$name,$value) = split(/:/,$key);
15845: if ($item eq 'resourcetag') {
15846: if ($name eq 'responsetype') {
15847: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
15848: }
15849: }
15850: }
15851: my $navmap = Apache::lonnavmaps::navmap->new();
15852: if (defined($navmap)) {
15853: my %allresponses;
15854: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
15855: my %responses = $res->responseTypes();
15856: foreach my $key (keys(%responses)) {
15857: next unless(exists($checkresponsetypes{$key}));
15858: $allresponses{$key} += $responses{$key};
15859: }
15860: }
15861: foreach my $key (keys(%allresponses)) {
15862: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
15863: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
15864: ($reqdmajor,$reqdminor) = ($major,$minor);
15865: }
15866: }
15867: undef($navmap);
15868: }
15869: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
15870: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
15871: }
15872: return;
15873: }
15874:
1.1075.2.27 raeburn 15875: sub allmaps_incourse {
15876: my ($cdom,$cnum,$chome,$cid) = @_;
15877: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
15878: $cid = $env{'request.course.id'};
15879: $cdom = $env{'course.'.$cid.'.domain'};
15880: $cnum = $env{'course.'.$cid.'.num'};
15881: $chome = $env{'course.'.$cid.'.home'};
15882: }
15883: my %allmaps = ();
15884: my $lastchange =
15885: &Apache::lonnet::get_coursechange($cdom,$cnum);
15886: if ($lastchange > $env{'request.course.tied'}) {
15887: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
15888: unless ($ferr) {
15889: &update_content_constraints($cdom,$cnum,$chome,$cid);
15890: }
15891: }
15892: my $navmap = Apache::lonnavmaps::navmap->new();
15893: if (defined($navmap)) {
15894: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
15895: $allmaps{$res->src()} = 1;
15896: }
15897: }
15898: return \%allmaps;
15899: }
15900:
1.1075.2.11 raeburn 15901: sub parse_supplemental_title {
15902: my ($title) = @_;
15903:
15904: my ($foldertitle,$renametitle);
15905: if ($title =~ /&&&/) {
15906: $title = &HTML::Entites::decode($title);
15907: }
15908: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
15909: $renametitle=$4;
15910: my ($time,$uname,$udom) = ($1,$2,$3);
15911: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
15912: my $name = &plainname($uname,$udom);
15913: $name = &HTML::Entities::encode($name,'"<>&\'');
15914: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
15915: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
15916: $name.': <br />'.$foldertitle;
15917: }
15918: if (wantarray) {
15919: return ($title,$foldertitle,$renametitle);
15920: }
15921: return $title;
15922: }
15923:
1.1075.2.43 raeburn 15924: sub recurse_supplemental {
15925: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
15926: if ($suppmap) {
15927: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
15928: if ($fatal) {
15929: $errors ++;
15930: } else {
15931: if ($#LONCAPA::map::resources > 0) {
15932: foreach my $res (@LONCAPA::map::resources) {
15933: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
15934: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 15935: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
15936: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 15937: } else {
15938: $numfiles ++;
15939: }
15940: }
15941: }
15942: }
15943: }
15944: }
15945: return ($numfiles,$errors);
15946: }
15947:
1.1075.2.18 raeburn 15948: sub symb_to_docspath {
15949: my ($symb) = @_;
15950: return unless ($symb);
15951: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
15952: if ($resurl=~/\.(sequence|page)$/) {
15953: $mapurl=$resurl;
15954: } elsif ($resurl eq 'adm/navmaps') {
15955: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
15956: }
15957: my $mapresobj;
15958: my $navmap = Apache::lonnavmaps::navmap->new();
15959: if (ref($navmap)) {
15960: $mapresobj = $navmap->getResourceByUrl($mapurl);
15961: }
15962: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
15963: my $type=$2;
15964: my $path;
15965: if (ref($mapresobj)) {
15966: my $pcslist = $mapresobj->map_hierarchy();
15967: if ($pcslist ne '') {
15968: foreach my $pc (split(/,/,$pcslist)) {
15969: next if ($pc <= 1);
15970: my $res = $navmap->getByMapPc($pc);
15971: if (ref($res)) {
15972: my $thisurl = $res->src();
15973: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
15974: my $thistitle = $res->title();
15975: $path .= '&'.
15976: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 15977: &escape($thistitle).
1.1075.2.18 raeburn 15978: ':'.$res->randompick().
15979: ':'.$res->randomout().
15980: ':'.$res->encrypted().
15981: ':'.$res->randomorder().
15982: ':'.$res->is_page();
15983: }
15984: }
15985: }
15986: $path =~ s/^\&//;
15987: my $maptitle = $mapresobj->title();
15988: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 15989: $maptitle = 'Main Content';
1.1075.2.18 raeburn 15990: }
15991: $path .= (($path ne '')? '&' : '').
15992: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 15993: &escape($maptitle).
1.1075.2.18 raeburn 15994: ':'.$mapresobj->randompick().
15995: ':'.$mapresobj->randomout().
15996: ':'.$mapresobj->encrypted().
15997: ':'.$mapresobj->randomorder().
15998: ':'.$mapresobj->is_page();
15999: } else {
16000: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16001: my $ispage = (($type eq 'page')? 1 : '');
16002: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16003: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16004: }
16005: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16006: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 16007: }
16008: unless ($mapurl eq 'default') {
16009: $path = 'default&'.
1.1075.2.46 raeburn 16010: &escape('Main Content').
1.1075.2.18 raeburn 16011: ':::::&'.$path;
16012: }
16013: return $path;
16014: }
16015:
1.1075.2.14 raeburn 16016: sub captcha_display {
16017: my ($context,$lonhost) = @_;
16018: my ($output,$error);
1.1075.2.107! raeburn 16019: my ($captcha,$pubkey,$privkey,$version) =
! 16020: &get_captcha_config($context,$lonhost);
1.1075.2.14 raeburn 16021: if ($captcha eq 'original') {
16022: $output = &create_captcha();
16023: unless ($output) {
16024: $error = 'captcha';
16025: }
16026: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107! raeburn 16027: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 16028: unless ($output) {
16029: $error = 'recaptcha';
16030: }
16031: }
1.1075.2.107! raeburn 16032: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 16033: }
16034:
16035: sub captcha_response {
16036: my ($context,$lonhost) = @_;
16037: my ($captcha_chk,$captcha_error);
1.1075.2.107! raeburn 16038: my ($captcha,$pubkey,$privkey.$version) = &get_captcha_config($context,$lonhost);
1.1075.2.14 raeburn 16039: if ($captcha eq 'original') {
16040: ($captcha_chk,$captcha_error) = &check_captcha();
16041: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107! raeburn 16042: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 16043: } else {
16044: $captcha_chk = 1;
16045: }
16046: return ($captcha_chk,$captcha_error);
16047: }
16048:
16049: sub get_captcha_config {
16050: my ($context,$lonhost) = @_;
1.1075.2.107! raeburn 16051: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 16052: my $hostname = &Apache::lonnet::hostname($lonhost);
16053: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
16054: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16055: if ($context eq 'usercreation') {
16056: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
16057: if (ref($domconfig{$context}) eq 'HASH') {
16058: $hashtocheck = $domconfig{$context}{'cancreate'};
16059: if (ref($hashtocheck) eq 'HASH') {
16060: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
16061: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
16062: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
16063: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
16064: }
16065: if ($privkey && $pubkey) {
16066: $captcha = 'recaptcha';
1.1075.2.107! raeburn 16067: $version = $hashtocheck->{'recaptchaversion'};
! 16068: if ($version ne '2') {
! 16069: $version = 1;
! 16070: }
1.1075.2.14 raeburn 16071: } else {
16072: $captcha = 'original';
16073: }
16074: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
16075: $captcha = 'original';
16076: }
16077: }
16078: } else {
16079: $captcha = 'captcha';
16080: }
16081: } elsif ($context eq 'login') {
16082: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
16083: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
16084: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
16085: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
16086: if ($privkey && $pubkey) {
16087: $captcha = 'recaptcha';
1.1075.2.107! raeburn 16088: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
! 16089: if ($version ne '2') {
! 16090: $version = 1;
! 16091: }
1.1075.2.14 raeburn 16092: } else {
16093: $captcha = 'original';
16094: }
16095: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
16096: $captcha = 'original';
16097: }
16098: }
1.1075.2.107! raeburn 16099: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 16100: }
16101:
16102: sub create_captcha {
16103: my %captcha_params = &captcha_settings();
16104: my ($output,$maxtries,$tries) = ('',10,0);
16105: while ($tries < $maxtries) {
16106: $tries ++;
16107: my $captcha = Authen::Captcha->new (
16108: output_folder => $captcha_params{'output_dir'},
16109: data_folder => $captcha_params{'db_dir'},
16110: );
16111: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
16112:
16113: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
16114: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
16115: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 16116: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
16117: '<br />'.
16118: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 16119: last;
16120: }
16121: }
16122: return $output;
16123: }
16124:
16125: sub captcha_settings {
16126: my %captcha_params = (
16127: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
16128: www_output_dir => "/captchaspool",
16129: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
16130: numchars => '5',
16131: );
16132: return %captcha_params;
16133: }
16134:
16135: sub check_captcha {
16136: my ($captcha_chk,$captcha_error);
16137: my $code = $env{'form.code'};
16138: my $md5sum = $env{'form.crypt'};
16139: my %captcha_params = &captcha_settings();
16140: my $captcha = Authen::Captcha->new(
16141: output_folder => $captcha_params{'output_dir'},
16142: data_folder => $captcha_params{'db_dir'},
16143: );
1.1075.2.26 raeburn 16144: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 16145: my %captcha_hash = (
16146: 0 => 'Code not checked (file error)',
16147: -1 => 'Failed: code expired',
16148: -2 => 'Failed: invalid code (not in database)',
16149: -3 => 'Failed: invalid code (code does not match crypt)',
16150: );
16151: if ($captcha_chk != 1) {
16152: $captcha_error = $captcha_hash{$captcha_chk}
16153: }
16154: return ($captcha_chk,$captcha_error);
16155: }
16156:
16157: sub create_recaptcha {
1.1075.2.107! raeburn 16158: my ($pubkey,$version) = @_;
! 16159: if ($version >= 2) {
! 16160: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
! 16161: } else {
! 16162: my $use_ssl;
! 16163: if ($ENV{'SERVER_PORT'} == 443) {
! 16164: $use_ssl = 1;
! 16165: }
! 16166: my $captcha = Captcha::reCAPTCHA->new;
! 16167: return $captcha->get_options_setter({theme => 'white'})."\n".
! 16168: $captcha->get_html($pubkey,undef,$use_ssl).
! 16169: &mt('If the text is hard to read, [_1] will replace them.',
! 16170: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
! 16171: '<br /><br />';
! 16172: }
1.1075.2.14 raeburn 16173: }
16174:
16175: sub check_recaptcha {
1.1075.2.107! raeburn 16176: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 16177: my $captcha_chk;
1.1075.2.107! raeburn 16178: if ($version >= 2) {
! 16179: my $ua = LWP::UserAgent->new;
! 16180: $ua->timeout(10);
! 16181: my %info = (
! 16182: secret => $privkey,
! 16183: response => $env{'form.g-recaptcha-response'},
! 16184: remoteip => $ENV{'REMOTE_ADDR'},
! 16185: );
! 16186: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
! 16187: if ($response->is_success) {
! 16188: my $data = JSON::DWIW->from_json($response->decoded_content);
! 16189: if (ref($data) eq 'HASH') {
! 16190: if ($data->{'success'}) {
! 16191: $captcha_chk = 1;
! 16192: }
! 16193: }
! 16194: }
! 16195: } else {
! 16196: my $captcha = Captcha::reCAPTCHA->new;
! 16197: my $captcha_result =
! 16198: $captcha->check_answer(
! 16199: $privkey,
! 16200: $ENV{'REMOTE_ADDR'},
! 16201: $env{'form.recaptcha_challenge_field'},
! 16202: $env{'form.recaptcha_response_field'},
! 16203: );
! 16204: if ($captcha_result->{is_valid}) {
! 16205: $captcha_chk = 1;
! 16206: }
1.1075.2.14 raeburn 16207: }
16208: return $captcha_chk;
16209: }
16210:
1.1075.2.64 raeburn 16211: sub emailusername_info {
1.1075.2.103 raeburn 16212: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 16213: my %titles = &Apache::lonlocal::texthash (
16214: lastname => 'Last Name',
16215: firstname => 'First Name',
16216: institution => 'School/college/university',
16217: location => "School's city, state/province, country",
16218: web => "School's web address",
16219: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 16220: id => 'Student/Employee ID',
1.1075.2.64 raeburn 16221: );
16222: return (\@fields,\%titles);
16223: }
16224:
1.1075.2.56 raeburn 16225: sub cleanup_html {
16226: my ($incoming) = @_;
16227: my $outgoing;
16228: if ($incoming ne '') {
16229: $outgoing = $incoming;
16230: $outgoing =~ s/;/;/g;
16231: $outgoing =~ s/\#/#/g;
16232: $outgoing =~ s/\&/&/g;
16233: $outgoing =~ s/</</g;
16234: $outgoing =~ s/>/>/g;
16235: $outgoing =~ s/\(/(/g;
16236: $outgoing =~ s/\)/)/g;
16237: $outgoing =~ s/"/"/g;
16238: $outgoing =~ s/'/'/g;
16239: $outgoing =~ s/\$/$/g;
16240: $outgoing =~ s{/}{/}g;
16241: $outgoing =~ s/=/=/g;
16242: $outgoing =~ s/\\/\/g
16243: }
16244: return $outgoing;
16245: }
16246:
1.1075.2.74 raeburn 16247: # Checks for critical messages and returns a redirect url if one exists.
16248: # $interval indicates how often to check for messages.
16249: sub critical_redirect {
16250: my ($interval) = @_;
16251: if ((time-$env{'user.criticalcheck.time'})>$interval) {
16252: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
16253: $env{'user.name'});
16254: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
16255: my $redirecturl;
16256: if ($what[0]) {
16257: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
16258: $redirecturl='/adm/email?critical=display';
16259: my $url=&Apache::lonnet::absolute_url().$redirecturl;
16260: return (1, $url);
16261: }
16262: }
16263: }
16264: return ();
16265: }
16266:
1.1075.2.64 raeburn 16267: # Use:
16268: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
16269: #
16270: ##################################################
16271: # password associated functions #
16272: ##################################################
16273: sub des_keys {
16274: # Make a new key for DES encryption.
16275: # Each key has two parts which are returned separately.
16276: # Please note: Each key must be passed through the &hex function
16277: # before it is output to the web browser. The hex versions cannot
16278: # be used to decrypt.
16279: my @hexstr=('0','1','2','3','4','5','6','7',
16280: '8','9','a','b','c','d','e','f');
16281: my $lkey='';
16282: for (0..7) {
16283: $lkey.=$hexstr[rand(15)];
16284: }
16285: my $ukey='';
16286: for (0..7) {
16287: $ukey.=$hexstr[rand(15)];
16288: }
16289: return ($lkey,$ukey);
16290: }
16291:
16292: sub des_decrypt {
16293: my ($key,$cyphertext) = @_;
16294: my $keybin=pack("H16",$key);
16295: my $cypher;
16296: if ($Crypt::DES::VERSION>=2.03) {
16297: $cypher=new Crypt::DES $keybin;
16298: } else {
16299: $cypher=new DES $keybin;
16300: }
1.1075.2.106 raeburn 16301: my $plaintext='';
16302: my $cypherlength = length($cyphertext);
16303: my $numchunks = int($cypherlength/32);
16304: for (my $j=0; $j<$numchunks; $j++) {
16305: my $start = $j*32;
16306: my $cypherblock = substr($cyphertext,$start,32);
16307: my $chunk =
16308: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
16309: $chunk .=
16310: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
16311: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
16312: $plaintext .= $chunk;
16313: }
1.1075.2.64 raeburn 16314: return $plaintext;
16315: }
16316:
1.112 bowersj2 16317: 1;
16318: __END__;
1.41 ng 16319:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>