Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.109
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.109! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.108 2016/08/13 20:20:23 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.1075.2.108 raeburn 5226: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
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.1075.2.108 raeburn 5603: .LC_maxwidth {
5604: max-width: 100%;
5605: height: auto;
5606: }
5607:
5608: .LC_textsize_mobile {
5609: \@media only screen and (max-device-width: 480px) {
5610: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
5611: }
5612: }
5613:
1.440 albertel 5614: .LC_icon {
1.771 droeschl 5615: border: none;
1.790 droeschl 5616: vertical-align: middle;
1.771 droeschl 5617: }
5618:
1.543 albertel 5619: .LC_docs_spacer {
5620: width: 25px;
5621: height: 1px;
1.771 droeschl 5622: border: none;
1.543 albertel 5623: }
1.346 albertel 5624:
1.532 albertel 5625: .LC_internal_info {
1.735 bisitz 5626: color: #999999;
1.532 albertel 5627: }
5628:
1.794 www 5629: .LC_discussion {
1.1050 www 5630: background: $data_table_dark;
1.911 bisitz 5631: border: 1px solid black;
5632: margin: 2px;
1.794 www 5633: }
5634:
5635: .LC_disc_action_left {
1.1050 www 5636: background: $sidebg;
1.911 bisitz 5637: text-align: left;
1.1050 www 5638: padding: 4px;
5639: margin: 2px;
1.794 www 5640: }
5641:
5642: .LC_disc_action_right {
1.1050 www 5643: background: $sidebg;
1.911 bisitz 5644: text-align: right;
1.1050 www 5645: padding: 4px;
5646: margin: 2px;
1.794 www 5647: }
5648:
5649: .LC_disc_new_item {
1.911 bisitz 5650: background: white;
5651: border: 2px solid red;
1.1050 www 5652: margin: 4px;
5653: padding: 4px;
1.794 www 5654: }
5655:
5656: .LC_disc_old_item {
1.911 bisitz 5657: background: white;
1.1050 www 5658: margin: 4px;
5659: padding: 4px;
1.794 www 5660: }
5661:
1.458 albertel 5662: table.LC_pastsubmission {
5663: border: 1px solid black;
5664: margin: 2px;
5665: }
5666:
1.924 bisitz 5667: table#LC_menubuttons {
1.345 albertel 5668: width: 100%;
5669: background: $pgbg;
1.392 albertel 5670: border: 2px;
1.402 albertel 5671: border-collapse: separate;
1.803 bisitz 5672: padding: 0;
1.345 albertel 5673: }
1.392 albertel 5674:
1.801 tempelho 5675: table#LC_title_bar a {
5676: color: $fontmenu;
5677: }
1.836 bisitz 5678:
1.807 droeschl 5679: table#LC_title_bar {
1.819 tempelho 5680: clear: both;
1.836 bisitz 5681: display: none;
1.807 droeschl 5682: }
5683:
1.795 www 5684: table#LC_title_bar,
1.933 droeschl 5685: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5686: table#LC_title_bar.LC_with_remote {
1.359 albertel 5687: width: 100%;
1.392 albertel 5688: border-color: $pgbg;
5689: border-style: solid;
5690: border-width: $border;
1.379 albertel 5691: background: $pgbg;
1.801 tempelho 5692: color: $fontmenu;
1.392 albertel 5693: border-collapse: collapse;
1.803 bisitz 5694: padding: 0;
1.819 tempelho 5695: margin: 0;
1.359 albertel 5696: }
1.795 www 5697:
1.933 droeschl 5698: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5699: margin: 0;
5700: padding: 0;
1.933 droeschl 5701: position: relative;
5702: list-style: none;
1.913 droeschl 5703: }
1.933 droeschl 5704: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5705: display: inline;
5706: }
1.933 droeschl 5707:
5708: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5709: padding: 0;
1.933 droeschl 5710: margin: 0;
5711: float: left;
1.913 droeschl 5712: }
1.933 droeschl 5713: .LC_breadcrumb_tools_tools {
5714: padding: 0;
5715: margin: 0;
1.913 droeschl 5716: float: right;
5717: }
5718:
1.359 albertel 5719: table#LC_title_bar td {
5720: background: $tabbg;
5721: }
1.795 www 5722:
1.911 bisitz 5723: table#LC_menubuttons img {
1.803 bisitz 5724: border: none;
1.346 albertel 5725: }
1.795 www 5726:
1.842 droeschl 5727: .LC_breadcrumbs_component {
1.911 bisitz 5728: float: right;
5729: margin: 0 1em;
1.357 albertel 5730: }
1.842 droeschl 5731: .LC_breadcrumbs_component img {
1.911 bisitz 5732: vertical-align: middle;
1.777 tempelho 5733: }
1.795 www 5734:
1.1075.2.108 raeburn 5735: .LC_breadcrumbs_hoverable {
5736: background: $sidebg;
5737: }
5738:
1.383 albertel 5739: td.LC_table_cell_checkbox {
5740: text-align: center;
5741: }
1.795 www 5742:
5743: .LC_fontsize_small {
1.911 bisitz 5744: font-size: 70%;
1.705 tempelho 5745: }
5746:
1.844 bisitz 5747: #LC_breadcrumbs {
1.911 bisitz 5748: clear:both;
5749: background: $sidebg;
5750: border-bottom: 1px solid $lg_border_color;
5751: line-height: 2.5em;
1.933 droeschl 5752: overflow: hidden;
1.911 bisitz 5753: margin: 0;
5754: padding: 0;
1.995 raeburn 5755: text-align: left;
1.819 tempelho 5756: }
1.862 bisitz 5757:
1.1075.2.16 raeburn 5758: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5759: clear:both;
5760: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5761: border: 1px solid $sidebg;
1.1075.2.16 raeburn 5762: margin: 0 0 10px 0;
1.966 bisitz 5763: padding: 3px;
1.995 raeburn 5764: text-align: left;
1.822 bisitz 5765: }
5766:
1.795 www 5767: .LC_fontsize_medium {
1.911 bisitz 5768: font-size: 85%;
1.705 tempelho 5769: }
5770:
1.795 www 5771: .LC_fontsize_large {
1.911 bisitz 5772: font-size: 120%;
1.705 tempelho 5773: }
5774:
1.346 albertel 5775: .LC_menubuttons_inline_text {
5776: color: $font;
1.698 harmsja 5777: font-size: 90%;
1.701 harmsja 5778: padding-left:3px;
1.346 albertel 5779: }
5780:
1.934 droeschl 5781: .LC_menubuttons_inline_text img{
5782: vertical-align: middle;
5783: }
5784:
1.1051 www 5785: li.LC_menubuttons_inline_text img {
1.951 onken 5786: cursor:pointer;
1.1002 droeschl 5787: text-decoration: none;
1.951 onken 5788: }
5789:
1.526 www 5790: .LC_menubuttons_link {
5791: text-decoration: none;
5792: }
1.795 www 5793:
1.522 albertel 5794: .LC_menubuttons_category {
1.521 www 5795: color: $font;
1.526 www 5796: background: $pgbg;
1.521 www 5797: font-size: larger;
5798: font-weight: bold;
5799: }
5800:
1.346 albertel 5801: td.LC_menubuttons_text {
1.911 bisitz 5802: color: $font;
1.346 albertel 5803: }
1.706 harmsja 5804:
1.346 albertel 5805: .LC_current_location {
5806: background: $tabbg;
5807: }
1.795 www 5808:
1.938 bisitz 5809: table.LC_data_table {
1.347 albertel 5810: border: 1px solid #000000;
1.402 albertel 5811: border-collapse: separate;
1.426 albertel 5812: border-spacing: 1px;
1.610 albertel 5813: background: $pgbg;
1.347 albertel 5814: }
1.795 www 5815:
1.422 albertel 5816: .LC_data_table_dense {
5817: font-size: small;
5818: }
1.795 www 5819:
1.507 raeburn 5820: table.LC_nested_outer {
5821: border: 1px solid #000000;
1.589 raeburn 5822: border-collapse: collapse;
1.803 bisitz 5823: border-spacing: 0;
1.507 raeburn 5824: width: 100%;
5825: }
1.795 www 5826:
1.879 raeburn 5827: table.LC_innerpickbox,
1.507 raeburn 5828: table.LC_nested {
1.803 bisitz 5829: border: none;
1.589 raeburn 5830: border-collapse: collapse;
1.803 bisitz 5831: border-spacing: 0;
1.507 raeburn 5832: width: 100%;
5833: }
1.795 www 5834:
1.911 bisitz 5835: table.LC_data_table tr th,
5836: table.LC_calendar tr th,
1.879 raeburn 5837: table.LC_prior_tries tr th,
5838: table.LC_innerpickbox tr th {
1.349 albertel 5839: font-weight: bold;
5840: background-color: $data_table_head;
1.801 tempelho 5841: color:$fontmenu;
1.701 harmsja 5842: font-size:90%;
1.347 albertel 5843: }
1.795 www 5844:
1.879 raeburn 5845: table.LC_innerpickbox tr th,
5846: table.LC_innerpickbox tr td {
5847: vertical-align: top;
5848: }
5849:
1.711 raeburn 5850: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5851: background-color: #CCCCCC;
1.711 raeburn 5852: font-weight: bold;
5853: text-align: left;
5854: }
1.795 www 5855:
1.912 bisitz 5856: table.LC_data_table tr.LC_odd_row > td {
5857: background-color: $data_table_light;
5858: padding: 2px;
5859: vertical-align: top;
5860: }
5861:
1.809 bisitz 5862: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5863: background-color: $data_table_light;
1.912 bisitz 5864: vertical-align: top;
5865: }
5866:
5867: table.LC_data_table tr.LC_even_row > td {
5868: background-color: $data_table_dark;
1.425 albertel 5869: padding: 2px;
1.900 bisitz 5870: vertical-align: top;
1.347 albertel 5871: }
1.795 www 5872:
1.809 bisitz 5873: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5874: background-color: $data_table_dark;
1.900 bisitz 5875: vertical-align: top;
1.347 albertel 5876: }
1.795 www 5877:
1.425 albertel 5878: table.LC_data_table tr.LC_data_table_highlight td {
5879: background-color: $data_table_darker;
5880: }
1.795 www 5881:
1.639 raeburn 5882: table.LC_data_table tr td.LC_leftcol_header {
5883: background-color: $data_table_head;
5884: font-weight: bold;
5885: }
1.795 www 5886:
1.451 albertel 5887: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5888: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5889: font-weight: bold;
5890: font-style: italic;
5891: text-align: center;
5892: padding: 8px;
1.347 albertel 5893: }
1.795 www 5894:
1.1075.2.30 raeburn 5895: table.LC_data_table tr.LC_empty_row td,
5896: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5897: background-color: $sidebg;
5898: }
5899:
5900: table.LC_nested tr.LC_empty_row td {
5901: background-color: #FFFFFF;
5902: }
5903:
1.890 droeschl 5904: table.LC_caption {
5905: }
5906:
1.507 raeburn 5907: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5908: padding: 4ex
5909: }
1.795 www 5910:
1.507 raeburn 5911: table.LC_nested_outer tr th {
5912: font-weight: bold;
1.801 tempelho 5913: color:$fontmenu;
1.507 raeburn 5914: background-color: $data_table_head;
1.701 harmsja 5915: font-size: small;
1.507 raeburn 5916: border-bottom: 1px solid #000000;
5917: }
1.795 www 5918:
1.507 raeburn 5919: table.LC_nested_outer tr td.LC_subheader {
5920: background-color: $data_table_head;
5921: font-weight: bold;
5922: font-size: small;
5923: border-bottom: 1px solid #000000;
5924: text-align: right;
1.451 albertel 5925: }
1.795 www 5926:
1.507 raeburn 5927: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5928: background-color: #CCCCCC;
1.451 albertel 5929: font-weight: bold;
5930: font-size: small;
1.507 raeburn 5931: text-align: center;
5932: }
1.795 www 5933:
1.589 raeburn 5934: table.LC_nested tr.LC_info_row td.LC_left_item,
5935: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5936: text-align: left;
1.451 albertel 5937: }
1.795 www 5938:
1.507 raeburn 5939: table.LC_nested td {
1.735 bisitz 5940: background-color: #FFFFFF;
1.451 albertel 5941: font-size: small;
1.507 raeburn 5942: }
1.795 www 5943:
1.507 raeburn 5944: table.LC_nested_outer tr th.LC_right_item,
5945: table.LC_nested tr.LC_info_row td.LC_right_item,
5946: table.LC_nested tr.LC_odd_row td.LC_right_item,
5947: table.LC_nested tr td.LC_right_item {
1.451 albertel 5948: text-align: right;
5949: }
5950:
1.507 raeburn 5951: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5952: background-color: #EEEEEE;
1.451 albertel 5953: }
5954:
1.473 raeburn 5955: table.LC_createuser {
5956: }
5957:
5958: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5959: font-size: small;
1.473 raeburn 5960: }
5961:
5962: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5963: background-color: #CCCCCC;
1.473 raeburn 5964: font-weight: bold;
5965: text-align: center;
5966: }
5967:
1.349 albertel 5968: table.LC_calendar {
5969: border: 1px solid #000000;
5970: border-collapse: collapse;
1.917 raeburn 5971: width: 98%;
1.349 albertel 5972: }
1.795 www 5973:
1.349 albertel 5974: table.LC_calendar_pickdate {
5975: font-size: xx-small;
5976: }
1.795 www 5977:
1.349 albertel 5978: table.LC_calendar tr td {
5979: border: 1px solid #000000;
5980: vertical-align: top;
1.917 raeburn 5981: width: 14%;
1.349 albertel 5982: }
1.795 www 5983:
1.349 albertel 5984: table.LC_calendar tr td.LC_calendar_day_empty {
5985: background-color: $data_table_dark;
5986: }
1.795 www 5987:
1.779 bisitz 5988: table.LC_calendar tr td.LC_calendar_day_current {
5989: background-color: $data_table_highlight;
1.777 tempelho 5990: }
1.795 www 5991:
1.938 bisitz 5992: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5993: background-color: $mail_new;
5994: }
1.795 www 5995:
1.938 bisitz 5996: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5997: background-color: $mail_new_hover;
5998: }
1.795 www 5999:
1.938 bisitz 6000: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6001: background-color: $mail_read;
6002: }
1.795 www 6003:
1.938 bisitz 6004: /*
6005: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6006: background-color: $mail_read_hover;
6007: }
1.938 bisitz 6008: */
1.795 www 6009:
1.938 bisitz 6010: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6011: background-color: $mail_replied;
6012: }
1.795 www 6013:
1.938 bisitz 6014: /*
6015: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6016: background-color: $mail_replied_hover;
6017: }
1.938 bisitz 6018: */
1.795 www 6019:
1.938 bisitz 6020: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6021: background-color: $mail_other;
6022: }
1.795 www 6023:
1.938 bisitz 6024: /*
6025: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6026: background-color: $mail_other_hover;
6027: }
1.938 bisitz 6028: */
1.494 raeburn 6029:
1.777 tempelho 6030: table.LC_data_table tr > td.LC_browser_file,
6031: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6032: background: #AAEE77;
1.389 albertel 6033: }
1.795 www 6034:
1.777 tempelho 6035: table.LC_data_table tr > td.LC_browser_file_locked,
6036: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6037: background: #FFAA99;
1.387 albertel 6038: }
1.795 www 6039:
1.777 tempelho 6040: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6041: background: #888888;
1.779 bisitz 6042: }
1.795 www 6043:
1.777 tempelho 6044: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6045: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6046: background: #F8F866;
1.777 tempelho 6047: }
1.795 www 6048:
1.696 bisitz 6049: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6050: background: #E0E8FF;
1.387 albertel 6051: }
1.696 bisitz 6052:
1.707 bisitz 6053: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6054: /* background: #77FF77; */
1.707 bisitz 6055: }
1.795 www 6056:
1.707 bisitz 6057: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6058: border-right: 8px solid #FFFF77;
1.707 bisitz 6059: }
1.795 www 6060:
1.707 bisitz 6061: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6062: border-right: 8px solid #FFAA77;
1.707 bisitz 6063: }
1.795 www 6064:
1.707 bisitz 6065: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6066: border-right: 8px solid #FF7777;
1.707 bisitz 6067: }
1.795 www 6068:
1.707 bisitz 6069: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6070: border-right: 8px solid #AAFF77;
1.707 bisitz 6071: }
1.795 www 6072:
1.707 bisitz 6073: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6074: border-right: 8px solid #11CC55;
1.707 bisitz 6075: }
6076:
1.388 albertel 6077: span.LC_current_location {
1.701 harmsja 6078: font-size:larger;
1.388 albertel 6079: background: $pgbg;
6080: }
1.387 albertel 6081:
1.1029 www 6082: span.LC_current_nav_location {
6083: font-weight:bold;
6084: background: $sidebg;
6085: }
6086:
1.395 albertel 6087: span.LC_parm_menu_item {
6088: font-size: larger;
6089: }
1.795 www 6090:
1.395 albertel 6091: span.LC_parm_scope_all {
6092: color: red;
6093: }
1.795 www 6094:
1.395 albertel 6095: span.LC_parm_scope_folder {
6096: color: green;
6097: }
1.795 www 6098:
1.395 albertel 6099: span.LC_parm_scope_resource {
6100: color: orange;
6101: }
1.795 www 6102:
1.395 albertel 6103: span.LC_parm_part {
6104: color: blue;
6105: }
1.795 www 6106:
1.911 bisitz 6107: span.LC_parm_folder,
6108: span.LC_parm_symb {
1.395 albertel 6109: font-size: x-small;
6110: font-family: $mono;
6111: color: #AAAAAA;
6112: }
6113:
1.977 bisitz 6114: ul.LC_parm_parmlist li {
6115: display: inline-block;
6116: padding: 0.3em 0.8em;
6117: vertical-align: top;
6118: width: 150px;
6119: border-top:1px solid $lg_border_color;
6120: }
6121:
1.795 www 6122: td.LC_parm_overview_level_menu,
6123: td.LC_parm_overview_map_menu,
6124: td.LC_parm_overview_parm_selectors,
6125: td.LC_parm_overview_restrictions {
1.396 albertel 6126: border: 1px solid black;
6127: border-collapse: collapse;
6128: }
1.795 www 6129:
1.396 albertel 6130: table.LC_parm_overview_restrictions td {
6131: border-width: 1px 4px 1px 4px;
6132: border-style: solid;
6133: border-color: $pgbg;
6134: text-align: center;
6135: }
1.795 www 6136:
1.396 albertel 6137: table.LC_parm_overview_restrictions th {
6138: background: $tabbg;
6139: border-width: 1px 4px 1px 4px;
6140: border-style: solid;
6141: border-color: $pgbg;
6142: }
1.795 www 6143:
1.398 albertel 6144: table#LC_helpmenu {
1.803 bisitz 6145: border: none;
1.398 albertel 6146: height: 55px;
1.803 bisitz 6147: border-spacing: 0;
1.398 albertel 6148: }
6149:
6150: table#LC_helpmenu fieldset legend {
6151: font-size: larger;
6152: }
1.795 www 6153:
1.397 albertel 6154: table#LC_helpmenu_links {
6155: width: 100%;
6156: border: 1px solid black;
6157: background: $pgbg;
1.803 bisitz 6158: padding: 0;
1.397 albertel 6159: border-spacing: 1px;
6160: }
1.795 www 6161:
1.397 albertel 6162: table#LC_helpmenu_links tr td {
6163: padding: 1px;
6164: background: $tabbg;
1.399 albertel 6165: text-align: center;
6166: font-weight: bold;
1.397 albertel 6167: }
1.396 albertel 6168:
1.795 www 6169: table#LC_helpmenu_links a:link,
6170: table#LC_helpmenu_links a:visited,
1.397 albertel 6171: table#LC_helpmenu_links a:active {
6172: text-decoration: none;
6173: color: $font;
6174: }
1.795 www 6175:
1.397 albertel 6176: table#LC_helpmenu_links a:hover {
6177: text-decoration: underline;
6178: color: $vlink;
6179: }
1.396 albertel 6180:
1.417 albertel 6181: .LC_chrt_popup_exists {
6182: border: 1px solid #339933;
6183: margin: -1px;
6184: }
1.795 www 6185:
1.417 albertel 6186: .LC_chrt_popup_up {
6187: border: 1px solid yellow;
6188: margin: -1px;
6189: }
1.795 www 6190:
1.417 albertel 6191: .LC_chrt_popup {
6192: border: 1px solid #8888FF;
6193: background: #CCCCFF;
6194: }
1.795 www 6195:
1.421 albertel 6196: table.LC_pick_box {
6197: border-collapse: separate;
6198: background: white;
6199: border: 1px solid black;
6200: border-spacing: 1px;
6201: }
1.795 www 6202:
1.421 albertel 6203: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6204: background: $sidebg;
1.421 albertel 6205: font-weight: bold;
1.900 bisitz 6206: text-align: left;
1.740 bisitz 6207: vertical-align: top;
1.421 albertel 6208: width: 184px;
6209: padding: 8px;
6210: }
1.795 www 6211:
1.579 raeburn 6212: table.LC_pick_box td.LC_pick_box_value {
6213: text-align: left;
6214: padding: 8px;
6215: }
1.795 www 6216:
1.579 raeburn 6217: table.LC_pick_box td.LC_pick_box_select {
6218: text-align: left;
6219: padding: 8px;
6220: }
1.795 www 6221:
1.424 albertel 6222: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6223: padding: 0;
1.421 albertel 6224: height: 1px;
6225: background: black;
6226: }
1.795 www 6227:
1.421 albertel 6228: table.LC_pick_box td.LC_pick_box_submit {
6229: text-align: right;
6230: }
1.795 www 6231:
1.579 raeburn 6232: table.LC_pick_box td.LC_evenrow_value {
6233: text-align: left;
6234: padding: 8px;
6235: background-color: $data_table_light;
6236: }
1.795 www 6237:
1.579 raeburn 6238: table.LC_pick_box td.LC_oddrow_value {
6239: text-align: left;
6240: padding: 8px;
6241: background-color: $data_table_light;
6242: }
1.795 www 6243:
1.579 raeburn 6244: span.LC_helpform_receipt_cat {
6245: font-weight: bold;
6246: }
1.795 www 6247:
1.424 albertel 6248: table.LC_group_priv_box {
6249: background: white;
6250: border: 1px solid black;
6251: border-spacing: 1px;
6252: }
1.795 www 6253:
1.424 albertel 6254: table.LC_group_priv_box td.LC_pick_box_title {
6255: background: $tabbg;
6256: font-weight: bold;
6257: text-align: right;
6258: width: 184px;
6259: }
1.795 www 6260:
1.424 albertel 6261: table.LC_group_priv_box td.LC_groups_fixed {
6262: background: $data_table_light;
6263: text-align: center;
6264: }
1.795 www 6265:
1.424 albertel 6266: table.LC_group_priv_box td.LC_groups_optional {
6267: background: $data_table_dark;
6268: text-align: center;
6269: }
1.795 www 6270:
1.424 albertel 6271: table.LC_group_priv_box td.LC_groups_functionality {
6272: background: $data_table_darker;
6273: text-align: center;
6274: font-weight: bold;
6275: }
1.795 www 6276:
1.424 albertel 6277: table.LC_group_priv td {
6278: text-align: left;
1.803 bisitz 6279: padding: 0;
1.424 albertel 6280: }
6281:
6282: .LC_navbuttons {
6283: margin: 2ex 0ex 2ex 0ex;
6284: }
1.795 www 6285:
1.423 albertel 6286: .LC_topic_bar {
6287: font-weight: bold;
6288: background: $tabbg;
1.918 wenzelju 6289: margin: 1em 0em 1em 2em;
1.805 bisitz 6290: padding: 3px;
1.918 wenzelju 6291: font-size: 1.2em;
1.423 albertel 6292: }
1.795 www 6293:
1.423 albertel 6294: .LC_topic_bar span {
1.918 wenzelju 6295: left: 0.5em;
6296: position: absolute;
1.423 albertel 6297: vertical-align: middle;
1.918 wenzelju 6298: font-size: 1.2em;
1.423 albertel 6299: }
1.795 www 6300:
1.423 albertel 6301: table.LC_course_group_status {
6302: margin: 20px;
6303: }
1.795 www 6304:
1.423 albertel 6305: table.LC_status_selector td {
6306: vertical-align: top;
6307: text-align: center;
1.424 albertel 6308: padding: 4px;
6309: }
1.795 www 6310:
1.599 albertel 6311: div.LC_feedback_link {
1.616 albertel 6312: clear: both;
1.829 kalberla 6313: background: $sidebg;
1.779 bisitz 6314: width: 100%;
1.829 kalberla 6315: padding-bottom: 10px;
6316: border: 1px $tabbg solid;
1.833 kalberla 6317: height: 22px;
6318: line-height: 22px;
6319: padding-top: 5px;
6320: }
6321:
6322: div.LC_feedback_link img {
6323: height: 22px;
1.867 kalberla 6324: vertical-align:middle;
1.829 kalberla 6325: }
6326:
1.911 bisitz 6327: div.LC_feedback_link a {
1.829 kalberla 6328: text-decoration: none;
1.489 raeburn 6329: }
1.795 www 6330:
1.867 kalberla 6331: div.LC_comblock {
1.911 bisitz 6332: display:inline;
1.867 kalberla 6333: color:$font;
6334: font-size:90%;
6335: }
6336:
6337: div.LC_feedback_link div.LC_comblock {
6338: padding-left:5px;
6339: }
6340:
6341: div.LC_feedback_link div.LC_comblock a {
6342: color:$font;
6343: }
6344:
1.489 raeburn 6345: span.LC_feedback_link {
1.858 bisitz 6346: /* background: $feedback_link_bg; */
1.599 albertel 6347: font-size: larger;
6348: }
1.795 www 6349:
1.599 albertel 6350: span.LC_message_link {
1.858 bisitz 6351: /* background: $feedback_link_bg; */
1.599 albertel 6352: font-size: larger;
6353: position: absolute;
6354: right: 1em;
1.489 raeburn 6355: }
1.421 albertel 6356:
1.515 albertel 6357: table.LC_prior_tries {
1.524 albertel 6358: border: 1px solid #000000;
6359: border-collapse: separate;
6360: border-spacing: 1px;
1.515 albertel 6361: }
1.523 albertel 6362:
1.515 albertel 6363: table.LC_prior_tries td {
1.524 albertel 6364: padding: 2px;
1.515 albertel 6365: }
1.523 albertel 6366:
6367: .LC_answer_correct {
1.795 www 6368: background: lightgreen;
6369: color: darkgreen;
6370: padding: 6px;
1.523 albertel 6371: }
1.795 www 6372:
1.523 albertel 6373: .LC_answer_charged_try {
1.797 www 6374: background: #FFAAAA;
1.795 www 6375: color: darkred;
6376: padding: 6px;
1.523 albertel 6377: }
1.795 www 6378:
1.779 bisitz 6379: .LC_answer_not_charged_try,
1.523 albertel 6380: .LC_answer_no_grade,
6381: .LC_answer_late {
1.795 www 6382: background: lightyellow;
1.523 albertel 6383: color: black;
1.795 www 6384: padding: 6px;
1.523 albertel 6385: }
1.795 www 6386:
1.523 albertel 6387: .LC_answer_previous {
1.795 www 6388: background: lightblue;
6389: color: darkblue;
6390: padding: 6px;
1.523 albertel 6391: }
1.795 www 6392:
1.779 bisitz 6393: .LC_answer_no_message {
1.777 tempelho 6394: background: #FFFFFF;
6395: color: black;
1.795 www 6396: padding: 6px;
1.779 bisitz 6397: }
1.795 www 6398:
1.779 bisitz 6399: .LC_answer_unknown {
6400: background: orange;
6401: color: black;
1.795 www 6402: padding: 6px;
1.777 tempelho 6403: }
1.795 www 6404:
1.529 albertel 6405: span.LC_prior_numerical,
6406: span.LC_prior_string,
6407: span.LC_prior_custom,
6408: span.LC_prior_reaction,
6409: span.LC_prior_math {
1.925 bisitz 6410: font-family: $mono;
1.523 albertel 6411: white-space: pre;
6412: }
6413:
1.525 albertel 6414: span.LC_prior_string {
1.925 bisitz 6415: font-family: $mono;
1.525 albertel 6416: white-space: pre;
6417: }
6418:
1.523 albertel 6419: table.LC_prior_option {
6420: width: 100%;
6421: border-collapse: collapse;
6422: }
1.795 www 6423:
1.911 bisitz 6424: table.LC_prior_rank,
1.795 www 6425: table.LC_prior_match {
1.528 albertel 6426: border-collapse: collapse;
6427: }
1.795 www 6428:
1.528 albertel 6429: table.LC_prior_option tr td,
6430: table.LC_prior_rank tr td,
6431: table.LC_prior_match tr td {
1.524 albertel 6432: border: 1px solid #000000;
1.515 albertel 6433: }
6434:
1.855 bisitz 6435: .LC_nobreak {
1.544 albertel 6436: white-space: nowrap;
1.519 raeburn 6437: }
6438:
1.576 raeburn 6439: span.LC_cusr_emph {
6440: font-style: italic;
6441: }
6442:
1.633 raeburn 6443: span.LC_cusr_subheading {
6444: font-weight: normal;
6445: font-size: 85%;
6446: }
6447:
1.861 bisitz 6448: div.LC_docs_entry_move {
1.859 bisitz 6449: border: 1px solid #BBBBBB;
1.545 albertel 6450: background: #DDDDDD;
1.861 bisitz 6451: width: 22px;
1.859 bisitz 6452: padding: 1px;
6453: margin: 0;
1.545 albertel 6454: }
6455:
1.861 bisitz 6456: table.LC_data_table tr > td.LC_docs_entry_commands,
6457: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6458: font-size: x-small;
6459: }
1.795 www 6460:
1.861 bisitz 6461: .LC_docs_entry_parameter {
6462: white-space: nowrap;
6463: }
6464:
1.544 albertel 6465: .LC_docs_copy {
1.545 albertel 6466: color: #000099;
1.544 albertel 6467: }
1.795 www 6468:
1.544 albertel 6469: .LC_docs_cut {
1.545 albertel 6470: color: #550044;
1.544 albertel 6471: }
1.795 www 6472:
1.544 albertel 6473: .LC_docs_rename {
1.545 albertel 6474: color: #009900;
1.544 albertel 6475: }
1.795 www 6476:
1.544 albertel 6477: .LC_docs_remove {
1.545 albertel 6478: color: #990000;
6479: }
6480:
1.547 albertel 6481: .LC_docs_reinit_warn,
6482: .LC_docs_ext_edit {
6483: font-size: x-small;
6484: }
6485:
1.545 albertel 6486: table.LC_docs_adddocs td,
6487: table.LC_docs_adddocs th {
6488: border: 1px solid #BBBBBB;
6489: padding: 4px;
6490: background: #DDDDDD;
1.543 albertel 6491: }
6492:
1.584 albertel 6493: table.LC_sty_begin {
6494: background: #BBFFBB;
6495: }
1.795 www 6496:
1.584 albertel 6497: table.LC_sty_end {
6498: background: #FFBBBB;
6499: }
6500:
1.589 raeburn 6501: table.LC_double_column {
1.803 bisitz 6502: border-width: 0;
1.589 raeburn 6503: border-collapse: collapse;
6504: width: 100%;
6505: padding: 2px;
6506: }
6507:
6508: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6509: top: 2px;
1.589 raeburn 6510: left: 2px;
6511: width: 47%;
6512: vertical-align: top;
6513: }
6514:
6515: table.LC_double_column tr td.LC_right_col {
6516: top: 2px;
1.779 bisitz 6517: right: 2px;
1.589 raeburn 6518: width: 47%;
6519: vertical-align: top;
6520: }
6521:
1.591 raeburn 6522: div.LC_left_float {
6523: float: left;
6524: padding-right: 5%;
1.597 albertel 6525: padding-bottom: 4px;
1.591 raeburn 6526: }
6527:
6528: div.LC_clear_float_header {
1.597 albertel 6529: padding-bottom: 2px;
1.591 raeburn 6530: }
6531:
6532: div.LC_clear_float_footer {
1.597 albertel 6533: padding-top: 10px;
1.591 raeburn 6534: clear: both;
6535: }
6536:
1.597 albertel 6537: div.LC_grade_show_user {
1.941 bisitz 6538: /* border-left: 5px solid $sidebg; */
6539: border-top: 5px solid #000000;
6540: margin: 50px 0 0 0;
1.936 bisitz 6541: padding: 15px 0 5px 10px;
1.597 albertel 6542: }
1.795 www 6543:
1.936 bisitz 6544: div.LC_grade_show_user_odd_row {
1.941 bisitz 6545: /* border-left: 5px solid #000000; */
6546: }
6547:
6548: div.LC_grade_show_user div.LC_Box {
6549: margin-right: 50px;
1.597 albertel 6550: }
6551:
6552: div.LC_grade_submissions,
6553: div.LC_grade_message_center,
1.936 bisitz 6554: div.LC_grade_info_links {
1.597 albertel 6555: margin: 5px;
6556: width: 99%;
6557: background: #FFFFFF;
6558: }
1.795 www 6559:
1.597 albertel 6560: div.LC_grade_submissions_header,
1.936 bisitz 6561: div.LC_grade_message_center_header {
1.705 tempelho 6562: font-weight: bold;
6563: font-size: large;
1.597 albertel 6564: }
1.795 www 6565:
1.597 albertel 6566: div.LC_grade_submissions_body,
1.936 bisitz 6567: div.LC_grade_message_center_body {
1.597 albertel 6568: border: 1px solid black;
6569: width: 99%;
6570: background: #FFFFFF;
6571: }
1.795 www 6572:
1.613 albertel 6573: table.LC_scantron_action {
6574: width: 100%;
6575: }
1.795 www 6576:
1.613 albertel 6577: table.LC_scantron_action tr th {
1.698 harmsja 6578: font-weight:bold;
6579: font-style:normal;
1.613 albertel 6580: }
1.795 www 6581:
1.779 bisitz 6582: .LC_edit_problem_header,
1.614 albertel 6583: div.LC_edit_problem_footer {
1.705 tempelho 6584: font-weight: normal;
6585: font-size: medium;
1.602 albertel 6586: margin: 2px;
1.1060 bisitz 6587: background-color: $sidebg;
1.600 albertel 6588: }
1.795 www 6589:
1.600 albertel 6590: div.LC_edit_problem_header,
1.602 albertel 6591: div.LC_edit_problem_header div,
1.614 albertel 6592: div.LC_edit_problem_footer,
6593: div.LC_edit_problem_footer div,
1.602 albertel 6594: div.LC_edit_problem_editxml_header,
6595: div.LC_edit_problem_editxml_header div {
1.600 albertel 6596: margin-top: 5px;
6597: }
1.795 www 6598:
1.600 albertel 6599: div.LC_edit_problem_header_title {
1.705 tempelho 6600: font-weight: bold;
6601: font-size: larger;
1.602 albertel 6602: background: $tabbg;
6603: padding: 3px;
1.1060 bisitz 6604: margin: 0 0 5px 0;
1.602 albertel 6605: }
1.795 www 6606:
1.602 albertel 6607: table.LC_edit_problem_header_title {
6608: width: 100%;
1.600 albertel 6609: background: $tabbg;
1.602 albertel 6610: }
6611:
6612: div.LC_edit_problem_discards {
6613: float: left;
6614: padding-bottom: 5px;
6615: }
1.795 www 6616:
1.602 albertel 6617: div.LC_edit_problem_saves {
6618: float: right;
6619: padding-bottom: 5px;
1.600 albertel 6620: }
1.795 www 6621:
1.1075.2.34 raeburn 6622: .LC_edit_opt {
6623: padding-left: 1em;
6624: white-space: nowrap;
6625: }
6626:
1.1075.2.57 raeburn 6627: .LC_edit_problem_latexhelper{
6628: text-align: right;
6629: }
6630:
6631: #LC_edit_problem_colorful div{
6632: margin-left: 40px;
6633: }
6634:
1.911 bisitz 6635: img.stift {
1.803 bisitz 6636: border-width: 0;
6637: vertical-align: middle;
1.677 riegler 6638: }
1.680 riegler 6639:
1.923 bisitz 6640: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6641: vertical-align: top;
1.777 tempelho 6642: }
1.795 www 6643:
1.716 raeburn 6644: div.LC_createcourse {
1.911 bisitz 6645: margin: 10px 10px 10px 10px;
1.716 raeburn 6646: }
6647:
1.917 raeburn 6648: .LC_dccid {
1.1075.2.38 raeburn 6649: float: right;
1.917 raeburn 6650: margin: 0.2em 0 0 0;
6651: padding: 0;
6652: font-size: 90%;
6653: display:none;
6654: }
6655:
1.897 wenzelju 6656: ol.LC_primary_menu a:hover,
1.721 harmsja 6657: ol#LC_MenuBreadcrumbs a:hover,
6658: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6659: ul#LC_secondary_menu a:hover,
1.721 harmsja 6660: .LC_FormSectionClearButton input:hover
1.795 www 6661: ul.LC_TabContent li:hover a {
1.952 onken 6662: color:$button_hover;
1.911 bisitz 6663: text-decoration:none;
1.693 droeschl 6664: }
6665:
1.779 bisitz 6666: h1 {
1.911 bisitz 6667: padding: 0;
6668: line-height:130%;
1.693 droeschl 6669: }
1.698 harmsja 6670:
1.911 bisitz 6671: h2,
6672: h3,
6673: h4,
6674: h5,
6675: h6 {
6676: margin: 5px 0 5px 0;
6677: padding: 0;
6678: line-height:130%;
1.693 droeschl 6679: }
1.795 www 6680:
6681: .LC_hcell {
1.911 bisitz 6682: padding:3px 15px 3px 15px;
6683: margin: 0;
6684: background-color:$tabbg;
6685: color:$fontmenu;
6686: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6687: }
1.795 www 6688:
1.840 bisitz 6689: .LC_Box > .LC_hcell {
1.911 bisitz 6690: margin: 0 -10px 10px -10px;
1.835 bisitz 6691: }
6692:
1.721 harmsja 6693: .LC_noBorder {
1.911 bisitz 6694: border: 0;
1.698 harmsja 6695: }
1.693 droeschl 6696:
1.721 harmsja 6697: .LC_FormSectionClearButton input {
1.911 bisitz 6698: background-color:transparent;
6699: border: none;
6700: cursor:pointer;
6701: text-decoration:underline;
1.693 droeschl 6702: }
1.763 bisitz 6703:
6704: .LC_help_open_topic {
1.911 bisitz 6705: color: #FFFFFF;
6706: background-color: #EEEEFF;
6707: margin: 1px;
6708: padding: 4px;
6709: border: 1px solid #000033;
6710: white-space: nowrap;
6711: /* vertical-align: middle; */
1.759 neumanie 6712: }
1.693 droeschl 6713:
1.911 bisitz 6714: dl,
6715: ul,
6716: div,
6717: fieldset {
6718: margin: 10px 10px 10px 0;
6719: /* overflow: hidden; */
1.693 droeschl 6720: }
1.795 www 6721:
1.1075.2.90 raeburn 6722: article.geogebraweb div {
6723: margin: 0;
6724: }
6725:
1.838 bisitz 6726: fieldset > legend {
1.911 bisitz 6727: font-weight: bold;
6728: padding: 0 5px 0 5px;
1.838 bisitz 6729: }
6730:
1.813 bisitz 6731: #LC_nav_bar {
1.911 bisitz 6732: float: left;
1.995 raeburn 6733: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6734: margin: 0 0 2px 0;
1.807 droeschl 6735: }
6736:
1.916 droeschl 6737: #LC_realm {
6738: margin: 0.2em 0 0 0;
6739: padding: 0;
6740: font-weight: bold;
6741: text-align: center;
1.995 raeburn 6742: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6743: }
6744:
1.911 bisitz 6745: #LC_nav_bar em {
6746: font-weight: bold;
6747: font-style: normal;
1.807 droeschl 6748: }
6749:
1.897 wenzelju 6750: ol.LC_primary_menu {
1.934 droeschl 6751: margin: 0;
1.1075.2.2 raeburn 6752: padding: 0;
1.995 raeburn 6753: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6754: }
6755:
1.852 droeschl 6756: ol#LC_PathBreadcrumbs {
1.911 bisitz 6757: margin: 0;
1.693 droeschl 6758: }
6759:
1.897 wenzelju 6760: ol.LC_primary_menu li {
1.1075.2.2 raeburn 6761: color: RGB(80, 80, 80);
6762: vertical-align: middle;
6763: text-align: left;
6764: list-style: none;
6765: float: left;
6766: }
6767:
6768: ol.LC_primary_menu li a {
6769: display: block;
6770: margin: 0;
6771: padding: 0 5px 0 10px;
6772: text-decoration: none;
6773: }
6774:
6775: ol.LC_primary_menu li ul {
6776: display: none;
6777: width: 10em;
6778: background-color: $data_table_light;
6779: }
6780:
6781: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6782: display: block;
6783: position: absolute;
6784: margin: 0;
6785: padding: 0;
1.1075.2.5 raeburn 6786: z-index: 2;
1.1075.2.2 raeburn 6787: }
6788:
6789: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6790: font-size: 90%;
1.911 bisitz 6791: vertical-align: top;
1.1075.2.2 raeburn 6792: float: none;
1.1075.2.5 raeburn 6793: border-left: 1px solid black;
6794: border-right: 1px solid black;
1.1075.2.2 raeburn 6795: }
6796:
6797: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1075.2.5 raeburn 6798: background-color:$data_table_light;
1.1075.2.2 raeburn 6799: }
6800:
6801: ol.LC_primary_menu li li a:hover {
6802: color:$button_hover;
6803: background-color:$data_table_dark;
1.693 droeschl 6804: }
6805:
1.897 wenzelju 6806: ol.LC_primary_menu li img {
1.911 bisitz 6807: vertical-align: bottom;
1.934 droeschl 6808: height: 1.1em;
1.1075.2.3 raeburn 6809: margin: 0.2em 0 0 0;
1.693 droeschl 6810: }
6811:
1.897 wenzelju 6812: ol.LC_primary_menu a {
1.911 bisitz 6813: color: RGB(80, 80, 80);
6814: text-decoration: none;
1.693 droeschl 6815: }
1.795 www 6816:
1.949 droeschl 6817: ol.LC_primary_menu a.LC_new_message {
6818: font-weight:bold;
6819: color: darkred;
6820: }
6821:
1.975 raeburn 6822: ol.LC_docs_parameters {
6823: margin-left: 0;
6824: padding: 0;
6825: list-style: none;
6826: }
6827:
6828: ol.LC_docs_parameters li {
6829: margin: 0;
6830: padding-right: 20px;
6831: display: inline;
6832: }
6833:
1.976 raeburn 6834: ol.LC_docs_parameters li:before {
6835: content: "\\002022 \\0020";
6836: }
6837:
6838: li.LC_docs_parameters_title {
6839: font-weight: bold;
6840: }
6841:
6842: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6843: content: "";
6844: }
6845:
1.897 wenzelju 6846: ul#LC_secondary_menu {
1.1075.2.23 raeburn 6847: clear: right;
1.911 bisitz 6848: color: $fontmenu;
6849: background: $tabbg;
6850: list-style: none;
6851: padding: 0;
6852: margin: 0;
6853: width: 100%;
1.995 raeburn 6854: text-align: left;
1.1075.2.4 raeburn 6855: float: left;
1.808 droeschl 6856: }
6857:
1.897 wenzelju 6858: ul#LC_secondary_menu li {
1.911 bisitz 6859: font-weight: bold;
6860: line-height: 1.8em;
6861: border-right: 1px solid black;
6862: vertical-align: middle;
1.1075.2.4 raeburn 6863: float: left;
6864: }
6865:
6866: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6867: background-color: $data_table_light;
6868: }
6869:
6870: ul#LC_secondary_menu li a {
6871: padding: 0 0.8em;
6872: }
6873:
6874: ul#LC_secondary_menu li ul {
6875: display: none;
6876: }
6877:
6878: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6879: display: block;
6880: position: absolute;
6881: margin: 0;
6882: padding: 0;
6883: list-style:none;
6884: float: none;
6885: background-color: $data_table_light;
1.1075.2.5 raeburn 6886: z-index: 2;
1.1075.2.10 raeburn 6887: margin-left: -1px;
1.1075.2.4 raeburn 6888: }
6889:
6890: ul#LC_secondary_menu li ul li {
6891: font-size: 90%;
6892: vertical-align: top;
6893: border-left: 1px solid black;
6894: border-right: 1px solid black;
1.1075.2.33 raeburn 6895: background-color: $data_table_light;
1.1075.2.4 raeburn 6896: list-style:none;
6897: float: none;
6898: }
6899:
6900: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6901: background-color: $data_table_dark;
1.807 droeschl 6902: }
6903:
1.847 tempelho 6904: ul.LC_TabContent {
1.911 bisitz 6905: display:block;
6906: background: $sidebg;
6907: border-bottom: solid 1px $lg_border_color;
6908: list-style:none;
1.1020 raeburn 6909: margin: -1px -10px 0 -10px;
1.911 bisitz 6910: padding: 0;
1.693 droeschl 6911: }
6912:
1.795 www 6913: ul.LC_TabContent li,
6914: ul.LC_TabContentBigger li {
1.911 bisitz 6915: float:left;
1.741 harmsja 6916: }
1.795 www 6917:
1.897 wenzelju 6918: ul#LC_secondary_menu li a {
1.911 bisitz 6919: color: $fontmenu;
6920: text-decoration: none;
1.693 droeschl 6921: }
1.795 www 6922:
1.721 harmsja 6923: ul.LC_TabContent {
1.952 onken 6924: min-height:20px;
1.721 harmsja 6925: }
1.795 www 6926:
6927: ul.LC_TabContent li {
1.911 bisitz 6928: vertical-align:middle;
1.959 onken 6929: padding: 0 16px 0 10px;
1.911 bisitz 6930: background-color:$tabbg;
6931: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6932: border-left: solid 1px $font;
1.721 harmsja 6933: }
1.795 www 6934:
1.847 tempelho 6935: ul.LC_TabContent .right {
1.911 bisitz 6936: float:right;
1.847 tempelho 6937: }
6938:
1.911 bisitz 6939: ul.LC_TabContent li a,
6940: ul.LC_TabContent li {
6941: color:rgb(47,47,47);
6942: text-decoration:none;
6943: font-size:95%;
6944: font-weight:bold;
1.952 onken 6945: min-height:20px;
6946: }
6947:
1.959 onken 6948: ul.LC_TabContent li a:hover,
6949: ul.LC_TabContent li a:focus {
1.952 onken 6950: color: $button_hover;
1.959 onken 6951: background:none;
6952: outline:none;
1.952 onken 6953: }
6954:
6955: ul.LC_TabContent li:hover {
6956: color: $button_hover;
6957: cursor:pointer;
1.721 harmsja 6958: }
1.795 www 6959:
1.911 bisitz 6960: ul.LC_TabContent li.active {
1.952 onken 6961: color: $font;
1.911 bisitz 6962: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6963: border-bottom:solid 1px #FFFFFF;
6964: cursor: default;
1.744 ehlerst 6965: }
1.795 www 6966:
1.959 onken 6967: ul.LC_TabContent li.active a {
6968: color:$font;
6969: background:#FFFFFF;
6970: outline: none;
6971: }
1.1047 raeburn 6972:
6973: ul.LC_TabContent li.goback {
6974: float: left;
6975: border-left: none;
6976: }
6977:
1.870 tempelho 6978: #maincoursedoc {
1.911 bisitz 6979: clear:both;
1.870 tempelho 6980: }
6981:
6982: ul.LC_TabContentBigger {
1.911 bisitz 6983: display:block;
6984: list-style:none;
6985: padding: 0;
1.870 tempelho 6986: }
6987:
1.795 www 6988: ul.LC_TabContentBigger li {
1.911 bisitz 6989: vertical-align:bottom;
6990: height: 30px;
6991: font-size:110%;
6992: font-weight:bold;
6993: color: #737373;
1.841 tempelho 6994: }
6995:
1.957 onken 6996: ul.LC_TabContentBigger li.active {
6997: position: relative;
6998: top: 1px;
6999: }
7000:
1.870 tempelho 7001: ul.LC_TabContentBigger li a {
1.911 bisitz 7002: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7003: height: 30px;
7004: line-height: 30px;
7005: text-align: center;
7006: display: block;
7007: text-decoration: none;
1.958 onken 7008: outline: none;
1.741 harmsja 7009: }
1.795 www 7010:
1.870 tempelho 7011: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7012: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7013: color:$font;
1.744 ehlerst 7014: }
1.795 www 7015:
1.870 tempelho 7016: ul.LC_TabContentBigger li b {
1.911 bisitz 7017: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7018: display: block;
7019: float: left;
7020: padding: 0 30px;
1.957 onken 7021: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7022: }
7023:
1.956 onken 7024: ul.LC_TabContentBigger li:hover b {
7025: color:$button_hover;
7026: }
7027:
1.870 tempelho 7028: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7029: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7030: color:$font;
1.957 onken 7031: border: 0;
1.741 harmsja 7032: }
1.693 droeschl 7033:
1.870 tempelho 7034:
1.862 bisitz 7035: ul.LC_CourseBreadcrumbs {
7036: background: $sidebg;
1.1020 raeburn 7037: height: 2em;
1.862 bisitz 7038: padding-left: 10px;
1.1020 raeburn 7039: margin: 0;
1.862 bisitz 7040: list-style-position: inside;
7041: }
7042:
1.911 bisitz 7043: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7044: ol#LC_PathBreadcrumbs {
1.911 bisitz 7045: padding-left: 10px;
7046: margin: 0;
1.933 droeschl 7047: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7048: }
7049:
1.911 bisitz 7050: ol#LC_MenuBreadcrumbs li,
7051: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7052: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7053: display: inline;
1.933 droeschl 7054: white-space: normal;
1.693 droeschl 7055: }
7056:
1.823 bisitz 7057: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7058: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7059: text-decoration: none;
7060: font-size:90%;
1.693 droeschl 7061: }
1.795 www 7062:
1.969 droeschl 7063: ol#LC_MenuBreadcrumbs h1 {
7064: display: inline;
7065: font-size: 90%;
7066: line-height: 2.5em;
7067: margin: 0;
7068: padding: 0;
7069: }
7070:
1.795 www 7071: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7072: text-decoration:none;
7073: font-size:100%;
7074: font-weight:bold;
1.693 droeschl 7075: }
1.795 www 7076:
1.840 bisitz 7077: .LC_Box {
1.911 bisitz 7078: border: solid 1px $lg_border_color;
7079: padding: 0 10px 10px 10px;
1.746 neumanie 7080: }
1.795 www 7081:
1.1020 raeburn 7082: .LC_DocsBox {
7083: border: solid 1px $lg_border_color;
7084: padding: 0 0 10px 10px;
7085: }
7086:
1.795 www 7087: .LC_AboutMe_Image {
1.911 bisitz 7088: float:left;
7089: margin-right:10px;
1.747 neumanie 7090: }
1.795 www 7091:
7092: .LC_Clear_AboutMe_Image {
1.911 bisitz 7093: clear:left;
1.747 neumanie 7094: }
1.795 www 7095:
1.721 harmsja 7096: dl.LC_ListStyleClean dt {
1.911 bisitz 7097: padding-right: 5px;
7098: display: table-header-group;
1.693 droeschl 7099: }
7100:
1.721 harmsja 7101: dl.LC_ListStyleClean dd {
1.911 bisitz 7102: display: table-row;
1.693 droeschl 7103: }
7104:
1.721 harmsja 7105: .LC_ListStyleClean,
7106: .LC_ListStyleSimple,
7107: .LC_ListStyleNormal,
1.795 www 7108: .LC_ListStyleSpecial {
1.911 bisitz 7109: /* display:block; */
7110: list-style-position: inside;
7111: list-style-type: none;
7112: overflow: hidden;
7113: padding: 0;
1.693 droeschl 7114: }
7115:
1.721 harmsja 7116: .LC_ListStyleSimple li,
7117: .LC_ListStyleSimple dd,
7118: .LC_ListStyleNormal li,
7119: .LC_ListStyleNormal dd,
7120: .LC_ListStyleSpecial li,
1.795 www 7121: .LC_ListStyleSpecial dd {
1.911 bisitz 7122: margin: 0;
7123: padding: 5px 5px 5px 10px;
7124: clear: both;
1.693 droeschl 7125: }
7126:
1.721 harmsja 7127: .LC_ListStyleClean li,
7128: .LC_ListStyleClean dd {
1.911 bisitz 7129: padding-top: 0;
7130: padding-bottom: 0;
1.693 droeschl 7131: }
7132:
1.721 harmsja 7133: .LC_ListStyleSimple dd,
1.795 www 7134: .LC_ListStyleSimple li {
1.911 bisitz 7135: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7136: }
7137:
1.721 harmsja 7138: .LC_ListStyleSpecial li,
7139: .LC_ListStyleSpecial dd {
1.911 bisitz 7140: list-style-type: none;
7141: background-color: RGB(220, 220, 220);
7142: margin-bottom: 4px;
1.693 droeschl 7143: }
7144:
1.721 harmsja 7145: table.LC_SimpleTable {
1.911 bisitz 7146: margin:5px;
7147: border:solid 1px $lg_border_color;
1.795 www 7148: }
1.693 droeschl 7149:
1.721 harmsja 7150: table.LC_SimpleTable tr {
1.911 bisitz 7151: padding: 0;
7152: border:solid 1px $lg_border_color;
1.693 droeschl 7153: }
1.795 www 7154:
7155: table.LC_SimpleTable thead {
1.911 bisitz 7156: background:rgb(220,220,220);
1.693 droeschl 7157: }
7158:
1.721 harmsja 7159: div.LC_columnSection {
1.911 bisitz 7160: display: block;
7161: clear: both;
7162: overflow: hidden;
7163: margin: 0;
1.693 droeschl 7164: }
7165:
1.721 harmsja 7166: div.LC_columnSection>* {
1.911 bisitz 7167: float: left;
7168: margin: 10px 20px 10px 0;
7169: overflow:hidden;
1.693 droeschl 7170: }
1.721 harmsja 7171:
1.795 www 7172: table em {
1.911 bisitz 7173: font-weight: bold;
7174: font-style: normal;
1.748 schulted 7175: }
1.795 www 7176:
1.779 bisitz 7177: table.LC_tableBrowseRes,
1.795 www 7178: table.LC_tableOfContent {
1.911 bisitz 7179: border:none;
7180: border-spacing: 1px;
7181: padding: 3px;
7182: background-color: #FFFFFF;
7183: font-size: 90%;
1.753 droeschl 7184: }
1.789 droeschl 7185:
1.911 bisitz 7186: table.LC_tableOfContent {
7187: border-collapse: collapse;
1.789 droeschl 7188: }
7189:
1.771 droeschl 7190: table.LC_tableBrowseRes a,
1.768 schulted 7191: table.LC_tableOfContent a {
1.911 bisitz 7192: background-color: transparent;
7193: text-decoration: none;
1.753 droeschl 7194: }
7195:
1.795 www 7196: table.LC_tableOfContent img {
1.911 bisitz 7197: border: none;
7198: height: 1.3em;
7199: vertical-align: text-bottom;
7200: margin-right: 0.3em;
1.753 droeschl 7201: }
1.757 schulted 7202:
1.795 www 7203: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7204: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7205: }
7206:
1.795 www 7207: a#LC_content_toolbar_everything {
1.911 bisitz 7208: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7209: }
7210:
1.795 www 7211: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7212: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7213: }
7214:
1.795 www 7215: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7216: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7217: }
7218:
1.795 www 7219: a#LC_content_toolbar_changefolder {
1.911 bisitz 7220: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7221: }
7222:
1.795 www 7223: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7224: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7225: }
7226:
1.1043 raeburn 7227: a#LC_content_toolbar_edittoplevel {
7228: background-image:url(/res/adm/pages/edittoplevel.gif);
7229: }
7230:
1.795 www 7231: ul#LC_toolbar li a:hover {
1.911 bisitz 7232: background-position: bottom center;
1.757 schulted 7233: }
7234:
1.795 www 7235: ul#LC_toolbar {
1.911 bisitz 7236: padding: 0;
7237: margin: 2px;
7238: list-style:none;
7239: position:relative;
7240: background-color:white;
1.1075.2.9 raeburn 7241: overflow: auto;
1.757 schulted 7242: }
7243:
1.795 www 7244: ul#LC_toolbar li {
1.911 bisitz 7245: border:1px solid white;
7246: padding: 0;
7247: margin: 0;
7248: float: left;
7249: display:inline;
7250: vertical-align:middle;
1.1075.2.9 raeburn 7251: white-space: nowrap;
1.911 bisitz 7252: }
1.757 schulted 7253:
1.783 amueller 7254:
1.795 www 7255: a.LC_toolbarItem {
1.911 bisitz 7256: display:block;
7257: padding: 0;
7258: margin: 0;
7259: height: 32px;
7260: width: 32px;
7261: color:white;
7262: border: none;
7263: background-repeat:no-repeat;
7264: background-color:transparent;
1.757 schulted 7265: }
7266:
1.915 droeschl 7267: ul.LC_funclist {
7268: margin: 0;
7269: padding: 0.5em 1em 0.5em 0;
7270: }
7271:
1.933 droeschl 7272: ul.LC_funclist > li:first-child {
7273: font-weight:bold;
7274: margin-left:0.8em;
7275: }
7276:
1.915 droeschl 7277: ul.LC_funclist + ul.LC_funclist {
7278: /*
7279: left border as a seperator if we have more than
7280: one list
7281: */
7282: border-left: 1px solid $sidebg;
7283: /*
7284: this hides the left border behind the border of the
7285: outer box if element is wrapped to the next 'line'
7286: */
7287: margin-left: -1px;
7288: }
7289:
1.843 bisitz 7290: ul.LC_funclist li {
1.915 droeschl 7291: display: inline;
1.782 bisitz 7292: white-space: nowrap;
1.915 droeschl 7293: margin: 0 0 0 25px;
7294: line-height: 150%;
1.782 bisitz 7295: }
7296:
1.974 wenzelju 7297: .LC_hidden {
7298: display: none;
7299: }
7300:
1.1030 www 7301: .LCmodal-overlay {
7302: position:fixed;
7303: top:0;
7304: right:0;
7305: bottom:0;
7306: left:0;
7307: height:100%;
7308: width:100%;
7309: margin:0;
7310: padding:0;
7311: background:#999;
7312: opacity:.75;
7313: filter: alpha(opacity=75);
7314: -moz-opacity: 0.75;
7315: z-index:101;
7316: }
7317:
7318: * html .LCmodal-overlay {
7319: position: absolute;
7320: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7321: }
7322:
7323: .LCmodal-window {
7324: position:fixed;
7325: top:50%;
7326: left:50%;
7327: margin:0;
7328: padding:0;
7329: z-index:102;
7330: }
7331:
7332: * html .LCmodal-window {
7333: position:absolute;
7334: }
7335:
7336: .LCclose-window {
7337: position:absolute;
7338: width:32px;
7339: height:32px;
7340: right:8px;
7341: top:8px;
7342: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7343: text-indent:-99999px;
7344: overflow:hidden;
7345: cursor:pointer;
7346: }
7347:
1.1075.2.17 raeburn 7348: /*
7349: styles used by TTH when "Default set of options to pass to tth/m
7350: when converting TeX" in course settings has been set
7351:
7352: option passed: -t
7353:
7354: */
7355:
7356: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7357: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7358: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7359: td div.norm {line-height:normal;}
7360:
7361: /*
7362: option passed -y3
7363: */
7364:
7365: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7366: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7367: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7368:
1.343 albertel 7369: END
7370: }
7371:
1.306 albertel 7372: =pod
7373:
7374: =item * &headtag()
7375:
7376: Returns a uniform footer for LON-CAPA web pages.
7377:
1.307 albertel 7378: Inputs: $title - optional title for the head
7379: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7380: $args - optional arguments
1.319 albertel 7381: force_register - if is true call registerurl so the remote is
7382: informed
1.415 albertel 7383: redirect -> array ref of
7384: 1- seconds before redirect occurs
7385: 2- url to redirect to
7386: 3- whether the side effect should occur
1.315 albertel 7387: (side effect of setting
7388: $env{'internal.head.redirect'} to the url
7389: redirected too)
1.352 albertel 7390: domain -> force to color decorate a page for a specific
7391: domain
7392: function -> force usage of a specific rolish color scheme
7393: bgcolor -> override the default page bgcolor
1.460 albertel 7394: no_auto_mt_title
7395: -> prevent &mt()ing the title arg
1.464 albertel 7396:
1.306 albertel 7397: =cut
7398:
7399: sub headtag {
1.313 albertel 7400: my ($title,$head_extra,$args) = @_;
1.306 albertel 7401:
1.363 albertel 7402: my $function = $args->{'function'} || &get_users_function();
7403: my $domain = $args->{'domain'} || &determinedomain();
7404: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7405: my $httphost = $args->{'use_absolute'};
1.418 albertel 7406: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7407: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7408: #time(),
1.418 albertel 7409: $env{'environment.color.timestamp'},
1.363 albertel 7410: $function,$domain,$bgcolor);
7411:
1.369 www 7412: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7413:
1.308 albertel 7414: my $result =
7415: '<head>'.
1.1075.2.56 raeburn 7416: &font_settings($args);
1.319 albertel 7417:
1.1075.2.72 raeburn 7418: my $inhibitprint;
7419: if ($args->{'print_suppress'}) {
7420: $inhibitprint = &print_suppression();
7421: }
1.1064 raeburn 7422:
1.461 albertel 7423: if (!$args->{'frameset'}) {
7424: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7425: }
1.1075.2.12 raeburn 7426: if ($args->{'force_register'}) {
7427: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7428: }
1.436 albertel 7429: if (!$args->{'no_nav_bar'}
7430: && !$args->{'only_body'}
7431: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7432: $result .= &help_menu_js($httphost);
1.1032 www 7433: $result.=&modal_window();
1.1038 www 7434: $result.=&togglebox_script();
1.1034 www 7435: $result.=&wishlist_window();
1.1041 www 7436: $result.=&LCprogressbarUpdate_script();
1.1034 www 7437: } else {
7438: if ($args->{'add_modal'}) {
7439: $result.=&modal_window();
7440: }
7441: if ($args->{'add_wishlist'}) {
7442: $result.=&wishlist_window();
7443: }
1.1038 www 7444: if ($args->{'add_togglebox'}) {
7445: $result.=&togglebox_script();
7446: }
1.1041 www 7447: if ($args->{'add_progressbar'}) {
7448: $result.=&LCprogressbarUpdate_script();
7449: }
1.436 albertel 7450: }
1.314 albertel 7451: if (ref($args->{'redirect'})) {
1.414 albertel 7452: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7453: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7454: if (!$inhibit_continue) {
7455: $env{'internal.head.redirect'} = $url;
7456: }
1.313 albertel 7457: $result.=<<ADDMETA
7458: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7459: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7460: ADDMETA
1.1075.2.89 raeburn 7461: } else {
7462: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
7463: my $requrl = $env{'request.uri'};
7464: if ($requrl eq '') {
7465: $requrl = $ENV{'REQUEST_URI'};
7466: $requrl =~ s/\?.+$//;
7467: }
7468: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
7469: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
7470: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
7471: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
7472: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
7473: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
7474: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
7475: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7476: if ($domdefs{'offloadnow'}{$lonhost}) {
7477: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
7478: if (($newserver) && ($newserver ne $lonhost)) {
7479: my $numsec = 5;
7480: my $timeout = $numsec * 1000;
7481: my ($newurl,$locknum,%locks,$msg);
7482: if ($env{'request.role.adv'}) {
7483: ($locknum,%locks) = &Apache::lonnet::get_locks();
7484: }
7485: my $disable_submit = 0;
7486: if ($requrl =~ /$LONCAPA::assess_re/) {
7487: $disable_submit = 1;
7488: }
7489: if ($locknum) {
7490: my @lockinfo = sort(values(%locks));
7491: $msg = &mt('Once the following tasks are complete: ')."\\n".
7492: join(", ",sort(values(%locks)))."\\n".
7493: &mt('your session will be transferred to a different server, after you click "Roles".');
7494: } else {
7495: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
7496: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
7497: }
7498: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
7499: $newurl = '/adm/switchserver?otherserver='.$newserver;
7500: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
7501: $newurl .= '&role='.$env{'request.role'};
7502: }
7503: if ($env{'request.symb'}) {
7504: $newurl .= '&symb='.$env{'request.symb'};
7505: } else {
7506: $newurl .= '&origurl='.$requrl;
7507: }
7508: }
1.1075.2.98 raeburn 7509: &js_escape(\$msg);
1.1075.2.89 raeburn 7510: $result.=<<OFFLOAD
7511: <meta http-equiv="pragma" content="no-cache" />
7512: <script type="text/javascript">
1.1075.2.92 raeburn 7513: // <![CDATA[
1.1075.2.89 raeburn 7514: function LC_Offload_Now() {
7515: var dest = "$newurl";
7516: if (dest != '') {
7517: window.location.href="$newurl";
7518: }
7519: }
1.1075.2.92 raeburn 7520: \$(document).ready(function () {
7521: window.alert('$msg');
7522: if ($disable_submit) {
1.1075.2.89 raeburn 7523: \$(".LC_hwk_submit").prop("disabled", true);
7524: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 7525: }
7526: setTimeout('LC_Offload_Now()', $timeout);
7527: });
7528: // ]]>
1.1075.2.89 raeburn 7529: </script>
7530: OFFLOAD
7531: }
7532: }
7533: }
7534: }
7535: }
7536: }
1.313 albertel 7537: }
1.306 albertel 7538: if (!defined($title)) {
7539: $title = 'The LearningOnline Network with CAPA';
7540: }
1.460 albertel 7541: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7542: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 7543: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7544: if (!$args->{'frameset'}) {
7545: $result .= ' /';
7546: }
7547: $result .= '>'
1.1064 raeburn 7548: .$inhibitprint
1.414 albertel 7549: .$head_extra;
1.1075.2.108 raeburn 7550: my $clientmobile;
7551: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
7552: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
7553: } else {
7554: $clientmobile = $env{'browser.mobile'};
7555: }
7556: if ($clientmobile) {
1.1075.2.42 raeburn 7557: $result .= '
7558: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7559: <meta name="apple-mobile-web-app-capable" content="yes" />';
7560: }
1.962 droeschl 7561: return $result.'</head>';
1.306 albertel 7562: }
7563:
7564: =pod
7565:
1.340 albertel 7566: =item * &font_settings()
7567:
7568: Returns neccessary <meta> to set the proper encoding
7569:
1.1075.2.56 raeburn 7570: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7571:
7572: =cut
7573:
7574: sub font_settings {
1.1075.2.56 raeburn 7575: my ($args) = @_;
1.340 albertel 7576: my $headerstring='';
1.1075.2.56 raeburn 7577: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7578: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 7579: $headerstring.=
1.1075.2.61 raeburn 7580: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7581: if (!$args->{'frameset'}) {
7582: $headerstring.= ' /';
7583: }
7584: $headerstring .= '>'."\n";
1.340 albertel 7585: }
7586: return $headerstring;
7587: }
7588:
1.341 albertel 7589: =pod
7590:
1.1064 raeburn 7591: =item * &print_suppression()
7592:
7593: In course context returns css which causes the body to be blank when media="print",
7594: if printout generation is unavailable for the current resource.
7595:
7596: This could be because:
7597:
7598: (a) printstartdate is in the future
7599:
7600: (b) printenddate is in the past
7601:
7602: (c) there is an active exam block with "printout"
7603: functionality blocked
7604:
7605: Users with pav, pfo or evb privileges are exempt.
7606:
7607: Inputs: none
7608:
7609: =cut
7610:
7611:
7612: sub print_suppression {
7613: my $noprint;
7614: if ($env{'request.course.id'}) {
7615: my $scope = $env{'request.course.id'};
7616: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7617: (&Apache::lonnet::allowed('pfo',$scope))) {
7618: return;
7619: }
7620: if ($env{'request.course.sec'} ne '') {
7621: $scope .= "/$env{'request.course.sec'}";
7622: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7623: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7624: return;
1.1064 raeburn 7625: }
7626: }
7627: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7628: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73 raeburn 7629: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 7630: if ($blocked) {
7631: my $checkrole = "cm./$cdom/$cnum";
7632: if ($env{'request.course.sec'} ne '') {
7633: $checkrole .= "/$env{'request.course.sec'}";
7634: }
7635: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7636: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7637: $noprint = 1;
7638: }
7639: }
7640: unless ($noprint) {
7641: my $symb = &Apache::lonnet::symbread();
7642: if ($symb ne '') {
7643: my $navmap = Apache::lonnavmaps::navmap->new();
7644: if (ref($navmap)) {
7645: my $res = $navmap->getBySymb($symb);
7646: if (ref($res)) {
7647: if (!$res->resprintable()) {
7648: $noprint = 1;
7649: }
7650: }
7651: }
7652: }
7653: }
7654: if ($noprint) {
7655: return <<"ENDSTYLE";
7656: <style type="text/css" media="print">
7657: body { display:none }
7658: </style>
7659: ENDSTYLE
7660: }
7661: }
7662: return;
7663: }
7664:
7665: =pod
7666:
1.341 albertel 7667: =item * &xml_begin()
7668:
7669: Returns the needed doctype and <html>
7670:
7671: Inputs: none
7672:
7673: =cut
7674:
7675: sub xml_begin {
1.1075.2.61 raeburn 7676: my ($is_frameset) = @_;
1.341 albertel 7677: my $output='';
7678:
7679: if ($env{'browser.mathml'}) {
7680: $output='<?xml version="1.0"?>'
7681: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7682: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7683:
7684: # .'<!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">] >'
7685: .'<!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">'
7686: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7687: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 7688: } elsif ($is_frameset) {
7689: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
7690: '<html>'."\n";
1.341 albertel 7691: } else {
1.1075.2.61 raeburn 7692: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
7693: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7694: }
7695: return $output;
7696: }
1.340 albertel 7697:
7698: =pod
7699:
1.306 albertel 7700: =item * &start_page()
7701:
7702: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7703:
1.648 raeburn 7704: Inputs:
7705:
7706: =over 4
7707:
7708: $title - optional title for the page
7709:
7710: $head_extra - optional extra HTML to incude inside the <head>
7711:
7712: $args - additional optional args supported are:
7713:
7714: =over 8
7715:
7716: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7717: arg on
1.814 bisitz 7718: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7719: add_entries -> additional attributes to add to the <body>
7720: domain -> force to color decorate a page for a
1.317 albertel 7721: specific domain
1.648 raeburn 7722: function -> force usage of a specific rolish color
1.317 albertel 7723: scheme
1.648 raeburn 7724: redirect -> see &headtag()
7725: bgcolor -> override the default page bg color
7726: js_ready -> return a string ready for being used in
1.317 albertel 7727: a javascript writeln
1.648 raeburn 7728: html_encode -> return a string ready for being used in
1.320 albertel 7729: a html attribute
1.648 raeburn 7730: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7731: $forcereg arg
1.648 raeburn 7732: frameset -> if true will start with a <frameset>
1.330 albertel 7733: rather than <body>
1.648 raeburn 7734: skip_phases -> hash ref of
1.338 albertel 7735: head -> skip the <html><head> generation
7736: body -> skip all <body> generation
1.1075.2.12 raeburn 7737: no_inline_link -> if true and in remote mode, don't show the
7738: 'Switch To Inline Menu' link
1.648 raeburn 7739: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 7740: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7741: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.15 raeburn 7742: group -> includes the current group, if page is for a
7743: specific group
1.361 albertel 7744:
1.648 raeburn 7745: =back
1.460 albertel 7746:
1.648 raeburn 7747: =back
1.562 albertel 7748:
1.306 albertel 7749: =cut
7750:
7751: sub start_page {
1.309 albertel 7752: my ($title,$head_extra,$args) = @_;
1.318 albertel 7753: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7754:
1.315 albertel 7755: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 7756: my ($result,@advtools);
1.964 droeschl 7757:
1.338 albertel 7758: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 7759: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 7760: }
7761:
7762: if (! exists($args->{'skip_phases'}{'body'}) ) {
7763: if ($args->{'frameset'}) {
7764: my $attr_string = &make_attr_string($args->{'force_register'},
7765: $args->{'add_entries'});
7766: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7767: } else {
7768: $result .=
7769: &bodytag($title,
7770: $args->{'function'}, $args->{'add_entries'},
7771: $args->{'only_body'}, $args->{'domain'},
7772: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 7773: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 7774: $args, \@advtools);
1.831 bisitz 7775: }
1.330 albertel 7776: }
1.338 albertel 7777:
1.315 albertel 7778: if ($args->{'js_ready'}) {
1.713 kaisler 7779: $result = &js_ready($result);
1.315 albertel 7780: }
1.320 albertel 7781: if ($args->{'html_encode'}) {
1.713 kaisler 7782: $result = &html_encode($result);
7783: }
7784:
1.813 bisitz 7785: # Preparation for new and consistent functionlist at top of screen
7786: # if ($args->{'functionlist'}) {
7787: # $result .= &build_functionlist();
7788: #}
7789:
1.964 droeschl 7790: # Don't add anything more if only_body wanted or in const space
7791: return $result if $args->{'only_body'}
7792: || $env{'request.state'} eq 'construct';
1.813 bisitz 7793:
7794: #Breadcrumbs
1.758 kaisler 7795: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7796: &Apache::lonhtmlcommon::clear_breadcrumbs();
7797: #if any br links exists, add them to the breadcrumbs
7798: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7799: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7800: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7801: }
7802: }
1.1075.2.19 raeburn 7803: # if @advtools array contains items add then to the breadcrumbs
7804: if (@advtools > 0) {
7805: &Apache::lonmenu::advtools_crumbs(@advtools);
7806: }
1.758 kaisler 7807:
7808: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7809: if(exists($args->{'bread_crumbs_component'})){
7810: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7811: }else{
7812: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7813: }
1.1075.2.24 raeburn 7814: } elsif (($env{'environment.remote'} eq 'on') &&
7815: ($env{'form.inhibitmenu'} ne 'yes') &&
7816: ($env{'request.noversionuri'} =~ m{^/res/}) &&
7817: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 7818: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 7819: }
1.315 albertel 7820: return $result;
1.306 albertel 7821: }
7822:
7823: sub end_page {
1.315 albertel 7824: my ($args) = @_;
7825: $env{'internal.end_page'}++;
1.330 albertel 7826: my $result;
1.335 albertel 7827: if ($args->{'discussion'}) {
7828: my ($target,$parser);
7829: if (ref($args->{'discussion'})) {
7830: ($target,$parser) =($args->{'discussion'}{'target'},
7831: $args->{'discussion'}{'parser'});
7832: }
7833: $result .= &Apache::lonxml::xmlend($target,$parser);
7834: }
1.330 albertel 7835: if ($args->{'frameset'}) {
7836: $result .= '</frameset>';
7837: } else {
1.635 raeburn 7838: $result .= &endbodytag($args);
1.330 albertel 7839: }
1.1075.2.6 raeburn 7840: unless ($args->{'notbody'}) {
7841: $result .= "\n</html>";
7842: }
1.330 albertel 7843:
1.315 albertel 7844: if ($args->{'js_ready'}) {
1.317 albertel 7845: $result = &js_ready($result);
1.315 albertel 7846: }
1.335 albertel 7847:
1.320 albertel 7848: if ($args->{'html_encode'}) {
7849: $result = &html_encode($result);
7850: }
1.335 albertel 7851:
1.315 albertel 7852: return $result;
7853: }
7854:
1.1034 www 7855: sub wishlist_window {
7856: return(<<'ENDWISHLIST');
1.1046 raeburn 7857: <script type="text/javascript">
1.1034 www 7858: // <![CDATA[
7859: // <!-- BEGIN LON-CAPA Internal
7860: function set_wishlistlink(title, path) {
7861: if (!title) {
7862: title = document.title;
7863: title = title.replace(/^LON-CAPA /,'');
7864: }
1.1075.2.65 raeburn 7865: title = encodeURIComponent(title);
1.1075.2.83 raeburn 7866: title = title.replace("'","\\\'");
1.1034 www 7867: if (!path) {
7868: path = location.pathname;
7869: }
1.1075.2.65 raeburn 7870: path = encodeURIComponent(path);
1.1075.2.83 raeburn 7871: path = path.replace("'","\\\'");
1.1034 www 7872: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7873: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7874: }
7875: // END LON-CAPA Internal -->
7876: // ]]>
7877: </script>
7878: ENDWISHLIST
7879: }
7880:
1.1030 www 7881: sub modal_window {
7882: return(<<'ENDMODAL');
1.1046 raeburn 7883: <script type="text/javascript">
1.1030 www 7884: // <![CDATA[
7885: // <!-- BEGIN LON-CAPA Internal
7886: var modalWindow = {
7887: parent:"body",
7888: windowId:null,
7889: content:null,
7890: width:null,
7891: height:null,
7892: close:function()
7893: {
7894: $(".LCmodal-window").remove();
7895: $(".LCmodal-overlay").remove();
7896: },
7897: open:function()
7898: {
7899: var modal = "";
7900: modal += "<div class=\"LCmodal-overlay\"></div>";
7901: 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;\">";
7902: modal += this.content;
7903: modal += "</div>";
7904:
7905: $(this.parent).append(modal);
7906:
7907: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7908: $(".LCclose-window").click(function(){modalWindow.close();});
7909: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7910: }
7911: };
1.1075.2.42 raeburn 7912: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7913: {
1.1075.2.83 raeburn 7914: source = source.replace("'","'");
1.1030 www 7915: modalWindow.windowId = "myModal";
7916: modalWindow.width = width;
7917: modalWindow.height = height;
1.1075.2.80 raeburn 7918: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7919: modalWindow.open();
1.1075.2.87 raeburn 7920: };
1.1030 www 7921: // END LON-CAPA Internal -->
7922: // ]]>
7923: </script>
7924: ENDMODAL
7925: }
7926:
7927: sub modal_link {
1.1075.2.42 raeburn 7928: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7929: unless ($width) { $width=480; }
7930: unless ($height) { $height=400; }
1.1031 www 7931: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 7932: unless ($transparency) { $transparency='true'; }
7933:
1.1074 raeburn 7934: my $target_attr;
7935: if (defined($target)) {
7936: $target_attr = 'target="'.$target.'"';
7937: }
7938: return <<"ENDLINK";
1.1075.2.42 raeburn 7939: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7940: $linktext</a>
7941: ENDLINK
1.1030 www 7942: }
7943:
1.1032 www 7944: sub modal_adhoc_script {
7945: my ($funcname,$width,$height,$content)=@_;
7946: return (<<ENDADHOC);
1.1046 raeburn 7947: <script type="text/javascript">
1.1032 www 7948: // <![CDATA[
7949: var $funcname = function()
7950: {
7951: modalWindow.windowId = "myModal";
7952: modalWindow.width = $width;
7953: modalWindow.height = $height;
7954: modalWindow.content = '$content';
7955: modalWindow.open();
7956: };
7957: // ]]>
7958: </script>
7959: ENDADHOC
7960: }
7961:
1.1041 www 7962: sub modal_adhoc_inner {
7963: my ($funcname,$width,$height,$content)=@_;
7964: my $innerwidth=$width-20;
7965: $content=&js_ready(
1.1042 www 7966: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 7967: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
7968: $content.
1.1041 www 7969: &end_scrollbox().
1.1075.2.42 raeburn 7970: &end_page()
1.1041 www 7971: );
7972: return &modal_adhoc_script($funcname,$width,$height,$content);
7973: }
7974:
7975: sub modal_adhoc_window {
7976: my ($funcname,$width,$height,$content,$linktext)=@_;
7977: return &modal_adhoc_inner($funcname,$width,$height,$content).
7978: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7979: }
7980:
7981: sub modal_adhoc_launch {
7982: my ($funcname,$width,$height,$content)=@_;
7983: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7984: <script type="text/javascript">
7985: // <![CDATA[
7986: $funcname();
7987: // ]]>
7988: </script>
7989: ENDLAUNCH
7990: }
7991:
7992: sub modal_adhoc_close {
7993: return (<<ENDCLOSE);
7994: <script type="text/javascript">
7995: // <![CDATA[
7996: modalWindow.close();
7997: // ]]>
7998: </script>
7999: ENDCLOSE
8000: }
8001:
1.1038 www 8002: sub togglebox_script {
8003: return(<<ENDTOGGLE);
8004: <script type="text/javascript">
8005: // <![CDATA[
8006: function LCtoggleDisplay(id,hidetext,showtext) {
8007: link = document.getElementById(id + "link").childNodes[0];
8008: with (document.getElementById(id).style) {
8009: if (display == "none" ) {
8010: display = "inline";
8011: link.nodeValue = hidetext;
8012: } else {
8013: display = "none";
8014: link.nodeValue = showtext;
8015: }
8016: }
8017: }
8018: // ]]>
8019: </script>
8020: ENDTOGGLE
8021: }
8022:
1.1039 www 8023: sub start_togglebox {
8024: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8025: unless ($heading) { $heading=''; } else { $heading.=' '; }
8026: unless ($showtext) { $showtext=&mt('show'); }
8027: unless ($hidetext) { $hidetext=&mt('hide'); }
8028: unless ($headerbg) { $headerbg='#FFFFFF'; }
8029: return &start_data_table().
8030: &start_data_table_header_row().
8031: '<td bgcolor="'.$headerbg.'">'.$heading.
8032: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8033: $showtext.'\')">'.$showtext.'</a>]</td>'.
8034: &end_data_table_header_row().
8035: '<tr id="'.$id.'" style="display:none""><td>';
8036: }
8037:
8038: sub end_togglebox {
8039: return '</td></tr>'.&end_data_table();
8040: }
8041:
1.1041 www 8042: sub LCprogressbar_script {
1.1045 www 8043: my ($id)=@_;
1.1041 www 8044: return(<<ENDPROGRESS);
8045: <script type="text/javascript">
8046: // <![CDATA[
1.1045 www 8047: \$('#progressbar$id').progressbar({
1.1041 www 8048: value: 0,
8049: change: function(event, ui) {
8050: var newVal = \$(this).progressbar('option', 'value');
8051: \$('.pblabel', this).text(LCprogressTxt);
8052: }
8053: });
8054: // ]]>
8055: </script>
8056: ENDPROGRESS
8057: }
8058:
8059: sub LCprogressbarUpdate_script {
8060: return(<<ENDPROGRESSUPDATE);
8061: <style type="text/css">
8062: .ui-progressbar { position:relative; }
8063: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8064: </style>
8065: <script type="text/javascript">
8066: // <![CDATA[
1.1045 www 8067: var LCprogressTxt='---';
8068:
8069: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8070: LCprogressTxt=progresstext;
1.1045 www 8071: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8072: }
8073: // ]]>
8074: </script>
8075: ENDPROGRESSUPDATE
8076: }
8077:
1.1042 www 8078: my $LClastpercent;
1.1045 www 8079: my $LCidcnt;
8080: my $LCcurrentid;
1.1042 www 8081:
1.1041 www 8082: sub LCprogressbar {
1.1042 www 8083: my ($r)=(@_);
8084: $LClastpercent=0;
1.1045 www 8085: $LCidcnt++;
8086: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8087: my $starting=&mt('Starting');
8088: my $content=(<<ENDPROGBAR);
1.1045 www 8089: <div id="progressbar$LCcurrentid">
1.1041 www 8090: <span class="pblabel">$starting</span>
8091: </div>
8092: ENDPROGBAR
1.1045 www 8093: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8094: }
8095:
8096: sub LCprogressbarUpdate {
1.1042 www 8097: my ($r,$val,$text)=@_;
8098: unless ($val) {
8099: if ($LClastpercent) {
8100: $val=$LClastpercent;
8101: } else {
8102: $val=0;
8103: }
8104: }
1.1041 www 8105: if ($val<0) { $val=0; }
8106: if ($val>100) { $val=0; }
1.1042 www 8107: $LClastpercent=$val;
1.1041 www 8108: unless ($text) { $text=$val.'%'; }
8109: $text=&js_ready($text);
1.1044 www 8110: &r_print($r,<<ENDUPDATE);
1.1041 www 8111: <script type="text/javascript">
8112: // <![CDATA[
1.1045 www 8113: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8114: // ]]>
8115: </script>
8116: ENDUPDATE
1.1035 www 8117: }
8118:
1.1042 www 8119: sub LCprogressbarClose {
8120: my ($r)=@_;
8121: $LClastpercent=0;
1.1044 www 8122: &r_print($r,<<ENDCLOSE);
1.1042 www 8123: <script type="text/javascript">
8124: // <![CDATA[
1.1045 www 8125: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8126: // ]]>
8127: </script>
8128: ENDCLOSE
1.1044 www 8129: }
8130:
8131: sub r_print {
8132: my ($r,$to_print)=@_;
8133: if ($r) {
8134: $r->print($to_print);
8135: $r->rflush();
8136: } else {
8137: print($to_print);
8138: }
1.1042 www 8139: }
8140:
1.320 albertel 8141: sub html_encode {
8142: my ($result) = @_;
8143:
1.322 albertel 8144: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8145:
8146: return $result;
8147: }
1.1044 www 8148:
1.317 albertel 8149: sub js_ready {
8150: my ($result) = @_;
8151:
1.323 albertel 8152: $result =~ s/[\n\r]/ /xmsg;
8153: $result =~ s/\\/\\\\/xmsg;
8154: $result =~ s/'/\\'/xmsg;
1.372 albertel 8155: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8156:
8157: return $result;
8158: }
8159:
1.315 albertel 8160: sub validate_page {
8161: if ( exists($env{'internal.start_page'})
1.316 albertel 8162: && $env{'internal.start_page'} > 1) {
8163: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8164: $env{'internal.start_page'}.' '.
1.316 albertel 8165: $ENV{'request.filename'});
1.315 albertel 8166: }
8167: if ( exists($env{'internal.end_page'})
1.316 albertel 8168: && $env{'internal.end_page'} > 1) {
8169: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8170: $env{'internal.end_page'}.' '.
1.316 albertel 8171: $env{'request.filename'});
1.315 albertel 8172: }
8173: if ( exists($env{'internal.start_page'})
8174: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8175: &Apache::lonnet::logthis('start_page called without end_page '.
8176: $env{'request.filename'});
1.315 albertel 8177: }
8178: if ( ! exists($env{'internal.start_page'})
8179: && exists($env{'internal.end_page'})) {
1.316 albertel 8180: &Apache::lonnet::logthis('end_page called without start_page'.
8181: $env{'request.filename'});
1.315 albertel 8182: }
1.306 albertel 8183: }
1.315 albertel 8184:
1.996 www 8185:
8186: sub start_scrollbox {
1.1075.2.56 raeburn 8187: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8188: unless ($outerwidth) { $outerwidth='520px'; }
8189: unless ($width) { $width='500px'; }
8190: unless ($height) { $height='200px'; }
1.1075 raeburn 8191: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8192: if ($id ne '') {
1.1075.2.42 raeburn 8193: $table_id = ' id="table_'.$id.'"';
8194: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8195: }
1.1075 raeburn 8196: if ($bgcolor ne '') {
8197: $tdcol = "background-color: $bgcolor;";
8198: }
1.1075.2.42 raeburn 8199: my $nicescroll_js;
8200: if ($env{'browser.mobile'}) {
8201: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8202: }
1.1075 raeburn 8203: return <<"END";
1.1075.2.42 raeburn 8204: $nicescroll_js
8205:
8206: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8207: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8208: END
1.996 www 8209: }
8210:
8211: sub end_scrollbox {
1.1036 www 8212: return '</div></td></tr></table>';
1.996 www 8213: }
8214:
1.1075.2.42 raeburn 8215: sub nicescroll_javascript {
8216: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8217: my %options;
8218: if (ref($cursor) eq 'HASH') {
8219: %options = %{$cursor};
8220: }
8221: unless ($options{'railalign'} =~ /^left|right$/) {
8222: $options{'railalign'} = 'left';
8223: }
8224: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8225: my $function = &get_users_function();
8226: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8227: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8228: $options{'cursorcolor'} = '#00F';
8229: }
8230: }
8231: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8232: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8233: $options{'cursoropacity'}='1.0';
8234: }
8235: } else {
8236: $options{'cursoropacity'}='1.0';
8237: }
8238: if ($options{'cursorfixedheight'} eq 'none') {
8239: delete($options{'cursorfixedheight'});
8240: } else {
8241: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8242: }
8243: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8244: delete($options{'railoffset'});
8245: }
8246: my @niceoptions;
8247: while (my($key,$value) = each(%options)) {
8248: if ($value =~ /^\{.+\}$/) {
8249: push(@niceoptions,$key.':'.$value);
8250: } else {
8251: push(@niceoptions,$key.':"'.$value.'"');
8252: }
8253: }
8254: my $nicescroll_js = '
8255: $(document).ready(
8256: function() {
8257: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8258: }
8259: );
8260: ';
8261: if ($framecheck) {
8262: $nicescroll_js .= '
8263: function expand_div(caller) {
8264: if (top === self) {
8265: document.getElementById("'.$id.'").style.width = "auto";
8266: document.getElementById("'.$id.'").style.height = "auto";
8267: } else {
8268: try {
8269: if (parent.frames) {
8270: if (parent.frames.length > 1) {
8271: var framesrc = parent.frames[1].location.href;
8272: var currsrc = framesrc.replace(/\#.*$/,"");
8273: if ((caller == "search") || (currsrc == "'.$location.'")) {
8274: document.getElementById("'.$id.'").style.width = "auto";
8275: document.getElementById("'.$id.'").style.height = "auto";
8276: }
8277: }
8278: }
8279: } catch (e) {
8280: return;
8281: }
8282: }
8283: return;
8284: }
8285: ';
8286: }
8287: if ($needjsready) {
8288: $nicescroll_js = '
8289: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8290: } else {
8291: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8292: }
8293: return $nicescroll_js;
8294: }
8295:
1.318 albertel 8296: sub simple_error_page {
1.1075.2.49 raeburn 8297: my ($r,$title,$msg,$args) = @_;
8298: if (ref($args) eq 'HASH') {
8299: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8300: } else {
8301: $msg = &mt($msg);
8302: }
8303:
1.318 albertel 8304: my $page =
8305: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8306: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8307: &Apache::loncommon::end_page();
8308: if (ref($r)) {
8309: $r->print($page);
1.327 albertel 8310: return;
1.318 albertel 8311: }
8312: return $page;
8313: }
1.347 albertel 8314:
8315: {
1.610 albertel 8316: my @row_count;
1.961 onken 8317:
8318: sub start_data_table_count {
8319: unshift(@row_count, 0);
8320: return;
8321: }
8322:
8323: sub end_data_table_count {
8324: shift(@row_count);
8325: return;
8326: }
8327:
1.347 albertel 8328: sub start_data_table {
1.1018 raeburn 8329: my ($add_class,$id) = @_;
1.422 albertel 8330: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8331: my $table_id;
8332: if (defined($id)) {
8333: $table_id = ' id="'.$id.'"';
8334: }
1.961 onken 8335: &start_data_table_count();
1.1018 raeburn 8336: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8337: }
8338:
8339: sub end_data_table {
1.961 onken 8340: &end_data_table_count();
1.389 albertel 8341: return '</table>'."\n";;
1.347 albertel 8342: }
8343:
8344: sub start_data_table_row {
1.974 wenzelju 8345: my ($add_class, $id) = @_;
1.610 albertel 8346: $row_count[0]++;
8347: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8348: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8349: $id = (' id="'.$id.'"') unless ($id eq '');
8350: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8351: }
1.471 banghart 8352:
8353: sub continue_data_table_row {
1.974 wenzelju 8354: my ($add_class, $id) = @_;
1.610 albertel 8355: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8356: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8357: $id = (' id="'.$id.'"') unless ($id eq '');
8358: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8359: }
1.347 albertel 8360:
8361: sub end_data_table_row {
1.389 albertel 8362: return '</tr>'."\n";;
1.347 albertel 8363: }
1.367 www 8364:
1.421 albertel 8365: sub start_data_table_empty_row {
1.707 bisitz 8366: # $row_count[0]++;
1.421 albertel 8367: return '<tr class="LC_empty_row" >'."\n";;
8368: }
8369:
8370: sub end_data_table_empty_row {
8371: return '</tr>'."\n";;
8372: }
8373:
1.367 www 8374: sub start_data_table_header_row {
1.389 albertel 8375: return '<tr class="LC_header_row">'."\n";;
1.367 www 8376: }
8377:
8378: sub end_data_table_header_row {
1.389 albertel 8379: return '</tr>'."\n";;
1.367 www 8380: }
1.890 droeschl 8381:
8382: sub data_table_caption {
8383: my $caption = shift;
8384: return "<caption class=\"LC_caption\">$caption</caption>";
8385: }
1.347 albertel 8386: }
8387:
1.548 albertel 8388: =pod
8389:
8390: =item * &inhibit_menu_check($arg)
8391:
8392: Checks for a inhibitmenu state and generates output to preserve it
8393:
8394: Inputs: $arg - can be any of
8395: - undef - in which case the return value is a string
8396: to add into arguments list of a uri
8397: - 'input' - in which case the return value is a HTML
8398: <form> <input> field of type hidden to
8399: preserve the value
8400: - a url - in which case the return value is the url with
8401: the neccesary cgi args added to preserve the
8402: inhibitmenu state
8403: - a ref to a url - no return value, but the string is
8404: updated to include the neccessary cgi
8405: args to preserve the inhibitmenu state
8406:
8407: =cut
8408:
8409: sub inhibit_menu_check {
8410: my ($arg) = @_;
8411: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8412: if ($arg eq 'input') {
8413: if ($env{'form.inhibitmenu'}) {
8414: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8415: } else {
8416: return
8417: }
8418: }
8419: if ($env{'form.inhibitmenu'}) {
8420: if (ref($arg)) {
8421: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8422: } elsif ($arg eq '') {
8423: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8424: } else {
8425: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8426: }
8427: }
8428: if (!ref($arg)) {
8429: return $arg;
8430: }
8431: }
8432:
1.251 albertel 8433: ###############################################
1.182 matthew 8434:
8435: =pod
8436:
1.549 albertel 8437: =back
8438:
8439: =head1 User Information Routines
8440:
8441: =over 4
8442:
1.405 albertel 8443: =item * &get_users_function()
1.182 matthew 8444:
8445: Used by &bodytag to determine the current users primary role.
8446: Returns either 'student','coordinator','admin', or 'author'.
8447:
8448: =cut
8449:
8450: ###############################################
8451: sub get_users_function {
1.815 tempelho 8452: my $function = 'norole';
1.818 tempelho 8453: if ($env{'request.role'}=~/^(st)/) {
8454: $function='student';
8455: }
1.907 raeburn 8456: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8457: $function='coordinator';
8458: }
1.258 albertel 8459: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8460: $function='admin';
8461: }
1.826 bisitz 8462: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8463: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8464: $function='author';
8465: }
8466: return $function;
1.54 www 8467: }
1.99 www 8468:
8469: ###############################################
8470:
1.233 raeburn 8471: =pod
8472:
1.821 raeburn 8473: =item * &show_course()
8474:
8475: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8476: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8477:
8478: Inputs:
8479: None
8480:
8481: Outputs:
8482: Scalar: 1 if 'Course' to be used, 0 otherwise.
8483:
8484: =cut
8485:
8486: ###############################################
8487: sub show_course {
8488: my $course = !$env{'user.adv'};
8489: if (!$env{'user.adv'}) {
8490: foreach my $env (keys(%env)) {
8491: next if ($env !~ m/^user\.priv\./);
8492: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8493: $course = 0;
8494: last;
8495: }
8496: }
8497: }
8498: return $course;
8499: }
8500:
8501: ###############################################
8502:
8503: =pod
8504:
1.542 raeburn 8505: =item * &check_user_status()
1.274 raeburn 8506:
8507: Determines current status of supplied role for a
8508: specific user. Roles can be active, previous or future.
8509:
8510: Inputs:
8511: user's domain, user's username, course's domain,
1.375 raeburn 8512: course's number, optional section ID.
1.274 raeburn 8513:
8514: Outputs:
8515: role status: active, previous or future.
8516:
8517: =cut
8518:
8519: sub check_user_status {
1.412 raeburn 8520: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8521: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 8522: my @uroles = keys(%userinfo);
1.274 raeburn 8523: my $srchstr;
8524: my $active_chk = 'none';
1.412 raeburn 8525: my $now = time;
1.274 raeburn 8526: if (@uroles > 0) {
1.908 raeburn 8527: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8528: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8529: } else {
1.412 raeburn 8530: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8531: }
8532: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8533: my $role_end = 0;
8534: my $role_start = 0;
8535: $active_chk = 'active';
1.412 raeburn 8536: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8537: $role_end = $1;
8538: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8539: $role_start = $1;
1.274 raeburn 8540: }
8541: }
8542: if ($role_start > 0) {
1.412 raeburn 8543: if ($now < $role_start) {
1.274 raeburn 8544: $active_chk = 'future';
8545: }
8546: }
8547: if ($role_end > 0) {
1.412 raeburn 8548: if ($now > $role_end) {
1.274 raeburn 8549: $active_chk = 'previous';
8550: }
8551: }
8552: }
8553: }
8554: return $active_chk;
8555: }
8556:
8557: ###############################################
8558:
8559: =pod
8560:
1.405 albertel 8561: =item * &get_sections()
1.233 raeburn 8562:
8563: Determines all the sections for a course including
8564: sections with students and sections containing other roles.
1.419 raeburn 8565: Incoming parameters:
8566:
8567: 1. domain
8568: 2. course number
8569: 3. reference to array containing roles for which sections should
8570: be gathered (optional).
8571: 4. reference to array containing status types for which sections
8572: should be gathered (optional).
8573:
8574: If the third argument is undefined, sections are gathered for any role.
8575: If the fourth argument is undefined, sections are gathered for any status.
8576: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8577:
1.374 raeburn 8578: Returns section hash (keys are section IDs, values are
8579: number of users in each section), subject to the
1.419 raeburn 8580: optional roles filter, optional status filter
1.233 raeburn 8581:
8582: =cut
8583:
8584: ###############################################
8585: sub get_sections {
1.419 raeburn 8586: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8587: if (!defined($cdom) || !defined($cnum)) {
8588: my $cid = $env{'request.course.id'};
8589:
8590: return if (!defined($cid));
8591:
8592: $cdom = $env{'course.'.$cid.'.domain'};
8593: $cnum = $env{'course.'.$cid.'.num'};
8594: }
8595:
8596: my %sectioncount;
1.419 raeburn 8597: my $now = time;
1.240 albertel 8598:
1.1075.2.33 raeburn 8599: my $check_students = 1;
8600: my $only_students = 0;
8601: if (ref($possible_roles) eq 'ARRAY') {
8602: if (grep(/^st$/,@{$possible_roles})) {
8603: if (@{$possible_roles} == 1) {
8604: $only_students = 1;
8605: }
8606: } else {
8607: $check_students = 0;
8608: }
8609: }
8610:
8611: if ($check_students) {
1.276 albertel 8612: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8613: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8614: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8615: my $start_index = &Apache::loncoursedata::CL_START();
8616: my $end_index = &Apache::loncoursedata::CL_END();
8617: my $status;
1.366 albertel 8618: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8619: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8620: $data->[$status_index],
8621: $data->[$start_index],
8622: $data->[$end_index]);
8623: if ($stu_status eq 'Active') {
8624: $status = 'active';
8625: } elsif ($end < $now) {
8626: $status = 'previous';
8627: } elsif ($start > $now) {
8628: $status = 'future';
8629: }
8630: if ($section ne '-1' && $section !~ /^\s*$/) {
8631: if ((!defined($possible_status)) || (($status ne '') &&
8632: (grep/^\Q$status\E$/,@{$possible_status}))) {
8633: $sectioncount{$section}++;
8634: }
1.240 albertel 8635: }
8636: }
8637: }
1.1075.2.33 raeburn 8638: if ($only_students) {
8639: return %sectioncount;
8640: }
1.240 albertel 8641: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8642: foreach my $user (sort(keys(%courseroles))) {
8643: if ($user !~ /^(\w{2})/) { next; }
8644: my ($role) = ($user =~ /^(\w{2})/);
8645: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8646: my ($section,$status);
1.240 albertel 8647: if ($role eq 'cr' &&
8648: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8649: $section=$1;
8650: }
8651: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8652: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8653: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8654: if ($end == -1 && $start == -1) {
8655: next; #deleted role
8656: }
8657: if (!defined($possible_status)) {
8658: $sectioncount{$section}++;
8659: } else {
8660: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8661: $status = 'active';
8662: } elsif ($end < $now) {
8663: $status = 'future';
8664: } elsif ($start > $now) {
8665: $status = 'previous';
8666: }
8667: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8668: $sectioncount{$section}++;
8669: }
8670: }
1.233 raeburn 8671: }
1.366 albertel 8672: return %sectioncount;
1.233 raeburn 8673: }
8674:
1.274 raeburn 8675: ###############################################
1.294 raeburn 8676:
8677: =pod
1.405 albertel 8678:
8679: =item * &get_course_users()
8680:
1.275 raeburn 8681: Retrieves usernames:domains for users in the specified course
8682: with specific role(s), and access status.
8683:
8684: Incoming parameters:
1.277 albertel 8685: 1. course domain
8686: 2. course number
8687: 3. access status: users must have - either active,
1.275 raeburn 8688: previous, future, or all.
1.277 albertel 8689: 4. reference to array of permissible roles
1.288 raeburn 8690: 5. reference to array of section restrictions (optional)
8691: 6. reference to results object (hash of hashes).
8692: 7. reference to optional userdata hash
1.609 raeburn 8693: 8. reference to optional statushash
1.630 raeburn 8694: 9. flag if privileged users (except those set to unhide in
8695: course settings) should be excluded
1.609 raeburn 8696: Keys of top level results hash are roles.
1.275 raeburn 8697: Keys of inner hashes are username:domain, with
8698: values set to access type.
1.288 raeburn 8699: Optional userdata hash returns an array with arguments in the
8700: same order as loncoursedata::get_classlist() for student data.
8701:
1.609 raeburn 8702: Optional statushash returns
8703:
1.288 raeburn 8704: Entries for end, start, section and status are blank because
8705: of the possibility of multiple values for non-student roles.
8706:
1.275 raeburn 8707: =cut
1.405 albertel 8708:
1.275 raeburn 8709: ###############################################
1.405 albertel 8710:
1.275 raeburn 8711: sub get_course_users {
1.630 raeburn 8712: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8713: my %idx = ();
1.419 raeburn 8714: my %seclists;
1.288 raeburn 8715:
8716: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8717: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8718: $idx{end} = &Apache::loncoursedata::CL_END();
8719: $idx{start} = &Apache::loncoursedata::CL_START();
8720: $idx{id} = &Apache::loncoursedata::CL_ID();
8721: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8722: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8723: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8724:
1.290 albertel 8725: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8726: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8727: my $now = time;
1.277 albertel 8728: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8729: my $match = 0;
1.412 raeburn 8730: my $secmatch = 0;
1.419 raeburn 8731: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8732: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8733: if ($section eq '') {
8734: $section = 'none';
8735: }
1.291 albertel 8736: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8737: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8738: $secmatch = 1;
8739: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8740: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8741: $secmatch = 1;
8742: }
8743: } else {
1.419 raeburn 8744: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8745: $secmatch = 1;
8746: }
1.290 albertel 8747: }
1.412 raeburn 8748: if (!$secmatch) {
8749: next;
8750: }
1.419 raeburn 8751: }
1.275 raeburn 8752: if (defined($$types{'active'})) {
1.288 raeburn 8753: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8754: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8755: $match = 1;
1.275 raeburn 8756: }
8757: }
8758: if (defined($$types{'previous'})) {
1.609 raeburn 8759: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8760: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8761: $match = 1;
1.275 raeburn 8762: }
8763: }
8764: if (defined($$types{'future'})) {
1.609 raeburn 8765: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8766: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8767: $match = 1;
1.275 raeburn 8768: }
8769: }
1.609 raeburn 8770: if ($match) {
8771: push(@{$seclists{$student}},$section);
8772: if (ref($userdata) eq 'HASH') {
8773: $$userdata{$student} = $$classlist{$student};
8774: }
8775: if (ref($statushash) eq 'HASH') {
8776: $statushash->{$student}{'st'}{$section} = $status;
8777: }
1.288 raeburn 8778: }
1.275 raeburn 8779: }
8780: }
1.412 raeburn 8781: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8782: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8783: my $now = time;
1.609 raeburn 8784: my %displaystatus = ( previous => 'Expired',
8785: active => 'Active',
8786: future => 'Future',
8787: );
1.1075.2.36 raeburn 8788: my (%nothide,@possdoms);
1.630 raeburn 8789: if ($hidepriv) {
8790: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8791: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8792: if ($user !~ /:/) {
8793: $nothide{join(':',split(/[\@]/,$user))}=1;
8794: } else {
8795: $nothide{$user} = 1;
8796: }
8797: }
1.1075.2.36 raeburn 8798: my @possdoms = ($cdom);
8799: if ($coursehash{'checkforpriv'}) {
8800: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8801: }
1.630 raeburn 8802: }
1.439 raeburn 8803: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8804: my $match = 0;
1.412 raeburn 8805: my $secmatch = 0;
1.439 raeburn 8806: my $status;
1.412 raeburn 8807: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8808: $user =~ s/:$//;
1.439 raeburn 8809: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8810: if ($end == -1 || $start == -1) {
8811: next;
8812: }
8813: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8814: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8815: my ($uname,$udom) = split(/:/,$user);
8816: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8817: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8818: $secmatch = 1;
8819: } elsif ($usec eq '') {
1.420 albertel 8820: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8821: $secmatch = 1;
8822: }
8823: } else {
8824: if (grep(/^\Q$usec\E$/,@{$sections})) {
8825: $secmatch = 1;
8826: }
8827: }
8828: if (!$secmatch) {
8829: next;
8830: }
1.288 raeburn 8831: }
1.419 raeburn 8832: if ($usec eq '') {
8833: $usec = 'none';
8834: }
1.275 raeburn 8835: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8836: if ($hidepriv) {
1.1075.2.36 raeburn 8837: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8838: (!$nothide{$uname.':'.$udom})) {
8839: next;
8840: }
8841: }
1.503 raeburn 8842: if ($end > 0 && $end < $now) {
1.439 raeburn 8843: $status = 'previous';
8844: } elsif ($start > $now) {
8845: $status = 'future';
8846: } else {
8847: $status = 'active';
8848: }
1.277 albertel 8849: foreach my $type (keys(%{$types})) {
1.275 raeburn 8850: if ($status eq $type) {
1.420 albertel 8851: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8852: push(@{$$users{$role}{$user}},$type);
8853: }
1.288 raeburn 8854: $match = 1;
8855: }
8856: }
1.419 raeburn 8857: if (($match) && (ref($userdata) eq 'HASH')) {
8858: if (!exists($$userdata{$uname.':'.$udom})) {
8859: &get_user_info($udom,$uname,\%idx,$userdata);
8860: }
1.420 albertel 8861: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8862: push(@{$seclists{$uname.':'.$udom}},$usec);
8863: }
1.609 raeburn 8864: if (ref($statushash) eq 'HASH') {
8865: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8866: }
1.275 raeburn 8867: }
8868: }
8869: }
8870: }
1.290 albertel 8871: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8872: if ((defined($cdom)) && (defined($cnum))) {
8873: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8874: if ( defined($csettings{'internal.courseowner'}) ) {
8875: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8876: next if ($owner eq '');
8877: my ($ownername,$ownerdom);
8878: if ($owner =~ /^([^:]+):([^:]+)$/) {
8879: $ownername = $1;
8880: $ownerdom = $2;
8881: } else {
8882: $ownername = $owner;
8883: $ownerdom = $cdom;
8884: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8885: }
8886: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8887: if (defined($userdata) &&
1.609 raeburn 8888: !exists($$userdata{$owner})) {
8889: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8890: if (!grep(/^none$/,@{$seclists{$owner}})) {
8891: push(@{$seclists{$owner}},'none');
8892: }
8893: if (ref($statushash) eq 'HASH') {
8894: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8895: }
1.290 albertel 8896: }
1.279 raeburn 8897: }
8898: }
8899: }
1.419 raeburn 8900: foreach my $user (keys(%seclists)) {
8901: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8902: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8903: }
1.275 raeburn 8904: }
8905: return;
8906: }
8907:
1.288 raeburn 8908: sub get_user_info {
8909: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8910: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8911: &plainname($uname,$udom,'lastname');
1.291 albertel 8912: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8913: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8914: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8915: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8916: return;
8917: }
1.275 raeburn 8918:
1.472 raeburn 8919: ###############################################
8920:
8921: =pod
8922:
8923: =item * &get_user_quota()
8924:
1.1075.2.41 raeburn 8925: Retrieves quota assigned for storage of user files.
8926: Default is to report quota for portfolio files.
1.472 raeburn 8927:
8928: Incoming parameters:
8929: 1. user's username
8930: 2. user's domain
1.1075.2.41 raeburn 8931: 3. quota name - portfolio, author, or course
8932: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 8933: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 8934: course
1.472 raeburn 8935:
8936: Returns:
1.1075.2.58 raeburn 8937: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 8938: 2. (Optional) Type of setting: custom or default
8939: (individually assigned or default for user's
8940: institutional status).
8941: 3. (Optional) - User's institutional status (e.g., faculty, staff
8942: or student - types as defined in localenroll::inst_usertypes
8943: for user's domain, which determines default quota for user.
8944: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8945:
8946: If a value has been stored in the user's environment,
1.536 raeburn 8947: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 8948: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8949:
8950: =cut
8951:
8952: ###############################################
8953:
8954:
8955: sub get_user_quota {
1.1075.2.42 raeburn 8956: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8957: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8958: if (!defined($udom)) {
8959: $udom = $env{'user.domain'};
8960: }
8961: if (!defined($uname)) {
8962: $uname = $env{'user.name'};
8963: }
8964: if (($udom eq '' || $uname eq '') ||
8965: ($udom eq 'public') && ($uname eq 'public')) {
8966: $quota = 0;
1.536 raeburn 8967: $quotatype = 'default';
8968: $defquota = 0;
1.472 raeburn 8969: } else {
1.536 raeburn 8970: my $inststatus;
1.1075.2.41 raeburn 8971: if ($quotaname eq 'course') {
8972: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8973: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8974: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8975: } else {
8976: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8977: $quota = $cenv{'internal.uploadquota'};
8978: }
1.536 raeburn 8979: } else {
1.1075.2.41 raeburn 8980: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8981: if ($quotaname eq 'author') {
8982: $quota = $env{'environment.authorquota'};
8983: } else {
8984: $quota = $env{'environment.portfolioquota'};
8985: }
8986: $inststatus = $env{'environment.inststatus'};
8987: } else {
8988: my %userenv =
8989: &Apache::lonnet::get('environment',['portfolioquota',
8990: 'authorquota','inststatus'],$udom,$uname);
8991: my ($tmp) = keys(%userenv);
8992: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8993: if ($quotaname eq 'author') {
8994: $quota = $userenv{'authorquota'};
8995: } else {
8996: $quota = $userenv{'portfolioquota'};
8997: }
8998: $inststatus = $userenv{'inststatus'};
8999: } else {
9000: undef(%userenv);
9001: }
9002: }
9003: }
9004: if ($quota eq '' || wantarray) {
9005: if ($quotaname eq 'course') {
9006: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9007: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9008: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9009: $defquota = $domdefs{$crstype.'quota'};
9010: }
9011: if ($defquota eq '') {
9012: $defquota = 500;
9013: }
1.1075.2.41 raeburn 9014: } else {
9015: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9016: }
9017: if ($quota eq '') {
9018: $quota = $defquota;
9019: $quotatype = 'default';
9020: } else {
9021: $quotatype = 'custom';
9022: }
1.472 raeburn 9023: }
9024: }
1.536 raeburn 9025: if (wantarray) {
9026: return ($quota,$quotatype,$settingstatus,$defquota);
9027: } else {
9028: return $quota;
9029: }
1.472 raeburn 9030: }
9031:
9032: ###############################################
9033:
9034: =pod
9035:
9036: =item * &default_quota()
9037:
1.536 raeburn 9038: Retrieves default quota assigned for storage of user portfolio files,
9039: given an (optional) user's institutional status.
1.472 raeburn 9040:
9041: Incoming parameters:
1.1075.2.42 raeburn 9042:
1.472 raeburn 9043: 1. domain
1.536 raeburn 9044: 2. (Optional) institutional status(es). This is a : separated list of
9045: status types (e.g., faculty, staff, student etc.)
9046: which apply to the user for whom the default is being retrieved.
9047: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9048: default quota will be returned.
9049: 3. quota name - portfolio, author, or course
9050: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9051:
9052: Returns:
1.1075.2.42 raeburn 9053:
1.1075.2.58 raeburn 9054: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9055: 2. (Optional) institutional type which determined the value of the
9056: default quota.
1.472 raeburn 9057:
9058: If a value has been stored in the domain's configuration db,
9059: it will return that, otherwise it returns 20 (for backwards
9060: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9061: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9062:
1.536 raeburn 9063: If the user's status includes multiple types (e.g., staff and student),
9064: the largest default quota which applies to the user determines the
9065: default quota returned.
9066:
1.472 raeburn 9067: =cut
9068:
9069: ###############################################
9070:
9071:
9072: sub default_quota {
1.1075.2.41 raeburn 9073: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9074: my ($defquota,$settingstatus);
9075: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9076: ['quotas'],$udom);
1.1075.2.41 raeburn 9077: my $key = 'defaultquota';
9078: if ($quotaname eq 'author') {
9079: $key = 'authorquota';
9080: }
1.622 raeburn 9081: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9082: if ($inststatus ne '') {
1.765 raeburn 9083: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9084: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9085: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9086: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9087: if ($defquota eq '') {
1.1075.2.41 raeburn 9088: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9089: $settingstatus = $item;
1.1075.2.41 raeburn 9090: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9091: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9092: $settingstatus = $item;
9093: }
9094: }
1.1075.2.41 raeburn 9095: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9096: if ($quotahash{'quotas'}{$item} ne '') {
9097: if ($defquota eq '') {
9098: $defquota = $quotahash{'quotas'}{$item};
9099: $settingstatus = $item;
9100: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9101: $defquota = $quotahash{'quotas'}{$item};
9102: $settingstatus = $item;
9103: }
1.536 raeburn 9104: }
9105: }
9106: }
9107: }
9108: if ($defquota eq '') {
1.1075.2.41 raeburn 9109: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9110: $defquota = $quotahash{'quotas'}{$key}{'default'};
9111: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9112: $defquota = $quotahash{'quotas'}{'default'};
9113: }
1.536 raeburn 9114: $settingstatus = 'default';
1.1075.2.42 raeburn 9115: if ($defquota eq '') {
9116: if ($quotaname eq 'author') {
9117: $defquota = 500;
9118: }
9119: }
1.536 raeburn 9120: }
9121: } else {
9122: $settingstatus = 'default';
1.1075.2.41 raeburn 9123: if ($quotaname eq 'author') {
9124: $defquota = 500;
9125: } else {
9126: $defquota = 20;
9127: }
1.536 raeburn 9128: }
9129: if (wantarray) {
9130: return ($defquota,$settingstatus);
1.472 raeburn 9131: } else {
1.536 raeburn 9132: return $defquota;
1.472 raeburn 9133: }
9134: }
9135:
1.1075.2.41 raeburn 9136: ###############################################
9137:
9138: =pod
9139:
1.1075.2.42 raeburn 9140: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9141:
9142: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9143: of existing file within authoring space will cause quota for the authoring
9144: space to be exceeded.
9145:
9146: Same, if upload of a file directly to a course/community via Course Editor
9147: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9148:
1.1075.2.61 raeburn 9149: Inputs: 7
1.1075.2.42 raeburn 9150: 1. username or coursenum
1.1075.2.41 raeburn 9151: 2. domain
1.1075.2.42 raeburn 9152: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9153: 4. filename of file for which action is being requested
9154: 5. filesize (kB) of file
9155: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9156: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9157:
9158: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9159: otherwise return null.
9160:
1.1075.2.42 raeburn 9161: =back
9162:
1.1075.2.41 raeburn 9163: =cut
9164:
1.1075.2.42 raeburn 9165: sub excess_filesize_warning {
1.1075.2.59 raeburn 9166: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9167: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9168: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9169: if ($context eq 'author') {
9170: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9171: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9172: } else {
9173: foreach my $subdir ('docs','supplemental') {
9174: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9175: }
9176: }
1.1075.2.41 raeburn 9177: $disk_quota = int($disk_quota * 1000);
9178: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9179: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9180: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9181: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9182: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9183: $disk_quota,$current_disk_usage).
9184: '</p>';
9185: }
9186: return;
9187: }
9188:
9189: ###############################################
9190:
9191:
1.384 raeburn 9192: sub get_secgrprole_info {
9193: my ($cdom,$cnum,$needroles,$type) = @_;
9194: my %sections_count = &get_sections($cdom,$cnum);
9195: my @sections = (sort {$a <=> $b} keys(%sections_count));
9196: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9197: my @groups = sort(keys(%curr_groups));
9198: my $allroles = [];
9199: my $rolehash;
9200: my $accesshash = {
9201: active => 'Currently has access',
9202: future => 'Will have future access',
9203: previous => 'Previously had access',
9204: };
9205: if ($needroles) {
9206: $rolehash = {'all' => 'all'};
1.385 albertel 9207: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9208: if (&Apache::lonnet::error(%user_roles)) {
9209: undef(%user_roles);
9210: }
9211: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9212: my ($role)=split(/\:/,$item,2);
9213: if ($role eq 'cr') { next; }
9214: if ($role =~ /^cr/) {
9215: $$rolehash{$role} = (split('/',$role))[3];
9216: } else {
9217: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9218: }
9219: }
9220: foreach my $key (sort(keys(%{$rolehash}))) {
9221: push(@{$allroles},$key);
9222: }
9223: push (@{$allroles},'st');
9224: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9225: }
9226: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9227: }
9228:
1.555 raeburn 9229: sub user_picker {
1.994 raeburn 9230: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 9231: my $currdom = $dom;
9232: my %curr_selected = (
9233: srchin => 'dom',
1.580 raeburn 9234: srchby => 'lastname',
1.555 raeburn 9235: );
9236: my $srchterm;
1.625 raeburn 9237: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9238: if ($srch->{'srchby'} ne '') {
9239: $curr_selected{'srchby'} = $srch->{'srchby'};
9240: }
9241: if ($srch->{'srchin'} ne '') {
9242: $curr_selected{'srchin'} = $srch->{'srchin'};
9243: }
9244: if ($srch->{'srchtype'} ne '') {
9245: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9246: }
9247: if ($srch->{'srchdomain'} ne '') {
9248: $currdom = $srch->{'srchdomain'};
9249: }
9250: $srchterm = $srch->{'srchterm'};
9251: }
1.1075.2.98 raeburn 9252: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9253: 'usr' => 'Search criteria',
1.563 raeburn 9254: 'doma' => 'Domain/institution to search',
1.558 albertel 9255: 'uname' => 'username',
9256: 'lastname' => 'last name',
1.555 raeburn 9257: 'lastfirst' => 'last name, first name',
1.558 albertel 9258: 'crs' => 'in this course',
1.576 raeburn 9259: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9260: 'alc' => 'all LON-CAPA',
1.573 raeburn 9261: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9262: 'exact' => 'is',
9263: 'contains' => 'contains',
1.569 raeburn 9264: 'begins' => 'begins with',
1.1075.2.98 raeburn 9265: );
9266: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9267: 'youm' => "You must include some text to search for.",
9268: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9269: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9270: 'yomc' => "You must choose a domain when using an institutional directory search.",
9271: 'ymcd' => "You must choose a domain when using a domain search.",
9272: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9273: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9274: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9275: );
1.1075.2.98 raeburn 9276: &html_escape(\%html_lt);
9277: &js_escape(\%js_lt);
1.563 raeburn 9278: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9279: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9280:
9281: my @srchins = ('crs','dom','alc','instd');
9282:
9283: foreach my $option (@srchins) {
9284: # FIXME 'alc' option unavailable until
9285: # loncreateuser::print_user_query_page()
9286: # has been completed.
9287: next if ($option eq 'alc');
1.880 raeburn 9288: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9289: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9290: if ($curr_selected{'srchin'} eq $option) {
9291: $srchinsel .= '
1.1075.2.98 raeburn 9292: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 9293: } else {
9294: $srchinsel .= '
1.1075.2.98 raeburn 9295: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 9296: }
1.555 raeburn 9297: }
1.563 raeburn 9298: $srchinsel .= "\n </select>\n";
1.555 raeburn 9299:
9300: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9301: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9302: if ($curr_selected{'srchby'} eq $option) {
9303: $srchbysel .= '
1.1075.2.98 raeburn 9304: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9305: } else {
9306: $srchbysel .= '
1.1075.2.98 raeburn 9307: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9308: }
9309: }
9310: $srchbysel .= "\n </select>\n";
9311:
9312: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9313: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9314: if ($curr_selected{'srchtype'} eq $option) {
9315: $srchtypesel .= '
1.1075.2.98 raeburn 9316: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9317: } else {
9318: $srchtypesel .= '
1.1075.2.98 raeburn 9319: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9320: }
9321: }
9322: $srchtypesel .= "\n </select>\n";
9323:
1.558 albertel 9324: my ($newuserscript,$new_user_create);
1.994 raeburn 9325: my $context_dom = $env{'request.role.domain'};
9326: if ($context eq 'requestcrs') {
9327: if ($env{'form.coursedom'} ne '') {
9328: $context_dom = $env{'form.coursedom'};
9329: }
9330: }
1.556 raeburn 9331: if ($forcenewuser) {
1.576 raeburn 9332: if (ref($srch) eq 'HASH') {
1.994 raeburn 9333: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9334: if ($cancreate) {
9335: $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>';
9336: } else {
1.799 bisitz 9337: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9338: my %usertypetext = (
9339: official => 'institutional',
9340: unofficial => 'non-institutional',
9341: );
1.799 bisitz 9342: $new_user_create = '<p class="LC_warning">'
9343: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9344: .' '
9345: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9346: ,'<a href="'.$helplink.'">','</a>')
9347: .'</p><br />';
1.627 raeburn 9348: }
1.576 raeburn 9349: }
9350: }
9351:
1.556 raeburn 9352: $newuserscript = <<"ENDSCRIPT";
9353:
1.570 raeburn 9354: function setSearch(createnew,callingForm) {
1.556 raeburn 9355: if (createnew == 1) {
1.570 raeburn 9356: for (var i=0; i<callingForm.srchby.length; i++) {
9357: if (callingForm.srchby.options[i].value == 'uname') {
9358: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9359: }
9360: }
1.570 raeburn 9361: for (var i=0; i<callingForm.srchin.length; i++) {
9362: if ( callingForm.srchin.options[i].value == 'dom') {
9363: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9364: }
9365: }
1.570 raeburn 9366: for (var i=0; i<callingForm.srchtype.length; i++) {
9367: if (callingForm.srchtype.options[i].value == 'exact') {
9368: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9369: }
9370: }
1.570 raeburn 9371: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9372: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9373: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9374: }
9375: }
9376: }
9377: }
9378: ENDSCRIPT
1.558 albertel 9379:
1.556 raeburn 9380: }
9381:
1.555 raeburn 9382: my $output = <<"END_BLOCK";
1.556 raeburn 9383: <script type="text/javascript">
1.824 bisitz 9384: // <![CDATA[
1.570 raeburn 9385: function validateEntry(callingForm) {
1.558 albertel 9386:
1.556 raeburn 9387: var checkok = 1;
1.558 albertel 9388: var srchin;
1.570 raeburn 9389: for (var i=0; i<callingForm.srchin.length; i++) {
9390: if ( callingForm.srchin[i].checked ) {
9391: srchin = callingForm.srchin[i].value;
1.558 albertel 9392: }
9393: }
9394:
1.570 raeburn 9395: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9396: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9397: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9398: var srchterm = callingForm.srchterm.value;
9399: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9400: var msg = "";
9401:
9402: if (srchterm == "") {
9403: checkok = 0;
1.1075.2.98 raeburn 9404: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 9405: }
9406:
1.569 raeburn 9407: if (srchtype== 'begins') {
9408: if (srchterm.length < 2) {
9409: checkok = 0;
1.1075.2.98 raeburn 9410: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 9411: }
9412: }
9413:
1.556 raeburn 9414: if (srchtype== 'contains') {
9415: if (srchterm.length < 3) {
9416: checkok = 0;
1.1075.2.98 raeburn 9417: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 9418: }
9419: }
9420: if (srchin == 'instd') {
9421: if (srchdomain == '') {
9422: checkok = 0;
1.1075.2.98 raeburn 9423: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 9424: }
9425: }
9426: if (srchin == 'dom') {
9427: if (srchdomain == '') {
9428: checkok = 0;
1.1075.2.98 raeburn 9429: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 9430: }
9431: }
9432: if (srchby == 'lastfirst') {
9433: if (srchterm.indexOf(",") == -1) {
9434: checkok = 0;
1.1075.2.98 raeburn 9435: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 9436: }
9437: if (srchterm.indexOf(",") == srchterm.length -1) {
9438: checkok = 0;
1.1075.2.98 raeburn 9439: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 9440: }
9441: }
9442: if (checkok == 0) {
1.1075.2.98 raeburn 9443: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 9444: return;
9445: }
9446: if (checkok == 1) {
1.570 raeburn 9447: callingForm.submit();
1.556 raeburn 9448: }
9449: }
9450:
9451: $newuserscript
9452:
1.824 bisitz 9453: // ]]>
1.556 raeburn 9454: </script>
1.558 albertel 9455:
9456: $new_user_create
9457:
1.555 raeburn 9458: END_BLOCK
1.558 albertel 9459:
1.876 raeburn 9460: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 9461: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 9462: $domform.
9463: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 9464: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 9465: $srchbysel.
9466: $srchtypesel.
9467: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9468: $srchinsel.
9469: &Apache::lonhtmlcommon::row_closure(1).
9470: &Apache::lonhtmlcommon::end_pick_box().
9471: '<br />';
1.555 raeburn 9472: return $output;
9473: }
9474:
1.612 raeburn 9475: sub user_rule_check {
1.615 raeburn 9476: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 9477: my ($response,%inst_response);
1.612 raeburn 9478: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 9479: if (keys(%{$usershash}) > 1) {
9480: my (%by_username,%by_id,%userdoms);
9481: my $checkid;
1.612 raeburn 9482: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 9483: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
9484: $checkid = 1;
9485: }
9486: }
9487: foreach my $user (keys(%{$usershash})) {
9488: my ($uname,$udom) = split(/:/,$user);
9489: if ($checkid) {
9490: if (ref($usershash->{$user}) eq 'HASH') {
9491: if ($usershash->{$user}->{'id'} ne '') {
9492: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
9493: $userdoms{$udom} = 1;
9494: if (ref($inst_results) eq 'HASH') {
9495: $inst_results->{$uname.':'.$udom} = {};
9496: }
9497: }
9498: }
9499: } else {
9500: $by_username{$udom}{$uname} = 1;
9501: $userdoms{$udom} = 1;
9502: if (ref($inst_results) eq 'HASH') {
9503: $inst_results->{$uname.':'.$udom} = {};
9504: }
9505: }
9506: }
9507: foreach my $udom (keys(%userdoms)) {
9508: if (!$got_rules->{$udom}) {
9509: my %domconfig = &Apache::lonnet::get_dom('configuration',
9510: ['usercreation'],$udom);
9511: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9512: foreach my $item ('username','id') {
9513: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9514: $$curr_rules{$udom}{$item} =
9515: $domconfig{'usercreation'}{$item.'_rule'};
9516: }
9517: }
9518: }
9519: $got_rules->{$udom} = 1;
9520: }
9521: }
9522: if ($checkid) {
9523: foreach my $udom (keys(%by_id)) {
9524: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
9525: if ($outcome eq 'ok') {
9526: foreach my $id (keys(%{$by_id{$udom}})) {
9527: my $uname = $by_id{$udom}{$id};
9528: $inst_response{$uname.':'.$udom} = $outcome;
9529: }
9530: if (ref($results) eq 'HASH') {
9531: foreach my $uname (keys(%{$results})) {
9532: if (exists($inst_response{$uname.':'.$udom})) {
9533: $inst_response{$uname.':'.$udom} = $outcome;
9534: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9535: }
9536: }
9537: }
9538: }
1.612 raeburn 9539: }
1.615 raeburn 9540: } else {
1.1075.2.99 raeburn 9541: foreach my $udom (keys(%by_username)) {
9542: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
9543: if ($outcome eq 'ok') {
9544: foreach my $uname (keys(%{$by_username{$udom}})) {
9545: $inst_response{$uname.':'.$udom} = $outcome;
9546: }
9547: if (ref($results) eq 'HASH') {
9548: foreach my $uname (keys(%{$results})) {
9549: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9550: }
9551: }
9552: }
9553: }
1.612 raeburn 9554: }
1.1075.2.99 raeburn 9555: } elsif (keys(%{$usershash}) == 1) {
9556: my $user = (keys(%{$usershash}))[0];
9557: my ($uname,$udom) = split(/:/,$user);
9558: if (($udom ne '') && ($uname ne '')) {
9559: if (ref($usershash->{$user}) eq 'HASH') {
9560: if (ref($checks) eq 'HASH') {
9561: if (defined($checks->{'username'})) {
9562: ($inst_response{$user},%{$inst_results->{$user}}) =
9563: &Apache::lonnet::get_instuser($udom,$uname);
9564: } elsif (defined($checks->{'id'})) {
9565: if ($usershash->{$user}->{'id'} ne '') {
9566: ($inst_response{$user},%{$inst_results->{$user}}) =
9567: &Apache::lonnet::get_instuser($udom,undef,
9568: $usershash->{$user}->{'id'});
9569: } else {
9570: ($inst_response{$user},%{$inst_results->{$user}}) =
9571: &Apache::lonnet::get_instuser($udom,$uname);
9572: }
9573: }
9574: } else {
9575: ($inst_response{$user},%{$inst_results->{$user}}) =
9576: &Apache::lonnet::get_instuser($udom,$uname);
9577: return;
9578: }
9579: if (!$got_rules->{$udom}) {
9580: my %domconfig = &Apache::lonnet::get_dom('configuration',
9581: ['usercreation'],$udom);
9582: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9583: foreach my $item ('username','id') {
9584: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9585: $$curr_rules{$udom}{$item} =
9586: $domconfig{'usercreation'}{$item.'_rule'};
9587: }
9588: }
1.585 raeburn 9589: }
1.1075.2.99 raeburn 9590: $got_rules->{$udom} = 1;
1.585 raeburn 9591: }
9592: }
1.1075.2.99 raeburn 9593: } else {
9594: return;
9595: }
9596: } else {
9597: return;
9598: }
9599: foreach my $user (keys(%{$usershash})) {
9600: my ($uname,$udom) = split(/:/,$user);
9601: next if (($udom eq '') || ($uname eq ''));
9602: my $id;
9603: if (ref($inst_results) eq 'HASH') {
9604: if (ref($inst_results->{$user}) eq 'HASH') {
9605: $id = $inst_results->{$user}->{'id'};
9606: }
9607: }
9608: if ($id eq '') {
9609: if (ref($usershash->{$user})) {
9610: $id = $usershash->{$user}->{'id'};
9611: }
1.585 raeburn 9612: }
1.612 raeburn 9613: foreach my $item (keys(%{$checks})) {
9614: if (ref($$curr_rules{$udom}) eq 'HASH') {
9615: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9616: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 9617: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
9618: $$curr_rules{$udom}{$item});
1.612 raeburn 9619: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9620: if ($rule_check{$rule}) {
9621: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 9622: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 9623: if (ref($inst_results) eq 'HASH') {
9624: if (ref($inst_results->{$user}) eq 'HASH') {
9625: if (keys(%{$inst_results->{$user}}) == 0) {
9626: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 9627: } elsif ($item eq 'id') {
9628: if ($inst_results->{$user}->{'id'} eq '') {
9629: $$alerts{$item}{$udom}{$uname} = 1;
9630: }
1.615 raeburn 9631: }
1.612 raeburn 9632: }
9633: }
1.615 raeburn 9634: }
9635: last;
1.585 raeburn 9636: }
9637: }
9638: }
9639: }
9640: }
9641: }
9642: }
9643: }
1.612 raeburn 9644: return;
9645: }
9646:
9647: sub user_rule_formats {
9648: my ($domain,$domdesc,$curr_rules,$check) = @_;
9649: my %text = (
9650: 'username' => 'Usernames',
9651: 'id' => 'IDs',
9652: );
9653: my $output;
9654: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9655: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9656: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 9657: $output = '<br />'.
9658: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9659: '<span class="LC_cusr_emph">','</span>',$domdesc).
9660: ' <ul>';
1.612 raeburn 9661: foreach my $rule (@{$ruleorder}) {
9662: if (ref($curr_rules) eq 'ARRAY') {
9663: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9664: if (ref($rules->{$rule}) eq 'HASH') {
9665: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9666: $rules->{$rule}{'desc'}.'</li>';
9667: }
9668: }
9669: }
9670: }
9671: $output .= '</ul>';
9672: }
9673: }
9674: return $output;
9675: }
9676:
9677: sub instrule_disallow_msg {
1.615 raeburn 9678: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9679: my $response;
9680: my %text = (
9681: item => 'username',
9682: items => 'usernames',
9683: match => 'matches',
9684: do => 'does',
9685: action => 'a username',
9686: one => 'one',
9687: );
9688: if ($count > 1) {
9689: $text{'item'} = 'usernames';
9690: $text{'match'} ='match';
9691: $text{'do'} = 'do';
9692: $text{'action'} = 'usernames',
9693: $text{'one'} = 'ones';
9694: }
9695: if ($checkitem eq 'id') {
9696: $text{'items'} = 'IDs';
9697: $text{'item'} = 'ID';
9698: $text{'action'} = 'an ID';
1.615 raeburn 9699: if ($count > 1) {
9700: $text{'item'} = 'IDs';
9701: $text{'action'} = 'IDs';
9702: }
1.612 raeburn 9703: }
1.674 bisitz 9704: $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 9705: if ($mode eq 'upload') {
9706: if ($checkitem eq 'username') {
9707: $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'}.");
9708: } elsif ($checkitem eq 'id') {
1.674 bisitz 9709: $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 9710: }
1.669 raeburn 9711: } elsif ($mode eq 'selfcreate') {
9712: if ($checkitem eq 'id') {
9713: $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.");
9714: }
1.615 raeburn 9715: } else {
9716: if ($checkitem eq 'username') {
9717: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9718: } elsif ($checkitem eq 'id') {
9719: $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.");
9720: }
1.612 raeburn 9721: }
9722: return $response;
1.585 raeburn 9723: }
9724:
1.624 raeburn 9725: sub personal_data_fieldtitles {
9726: my %fieldtitles = &Apache::lonlocal::texthash (
9727: id => 'Student/Employee ID',
9728: permanentemail => 'E-mail address',
9729: lastname => 'Last Name',
9730: firstname => 'First Name',
9731: middlename => 'Middle Name',
9732: generation => 'Generation',
9733: gen => 'Generation',
1.765 raeburn 9734: inststatus => 'Affiliation',
1.624 raeburn 9735: );
9736: return %fieldtitles;
9737: }
9738:
1.642 raeburn 9739: sub sorted_inst_types {
9740: my ($dom) = @_;
1.1075.2.70 raeburn 9741: my ($usertypes,$order);
9742: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
9743: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
9744: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
9745: $order = $domdefaults{'inststatus'}{'inststatusorder'};
9746: } else {
9747: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9748: }
1.642 raeburn 9749: my $othertitle = &mt('All users');
9750: if ($env{'request.course.id'}) {
1.668 raeburn 9751: $othertitle = &mt('Any users');
1.642 raeburn 9752: }
9753: my @types;
9754: if (ref($order) eq 'ARRAY') {
9755: @types = @{$order};
9756: }
9757: if (@types == 0) {
9758: if (ref($usertypes) eq 'HASH') {
9759: @types = sort(keys(%{$usertypes}));
9760: }
9761: }
9762: if (keys(%{$usertypes}) > 0) {
9763: $othertitle = &mt('Other users');
9764: }
9765: return ($othertitle,$usertypes,\@types);
9766: }
9767:
1.645 raeburn 9768: sub get_institutional_codes {
9769: my ($settings,$allcourses,$LC_code) = @_;
9770: # Get complete list of course sections to update
9771: my @currsections = ();
9772: my @currxlists = ();
9773: my $coursecode = $$settings{'internal.coursecode'};
9774:
9775: if ($$settings{'internal.sectionnums'} ne '') {
9776: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9777: }
9778:
9779: if ($$settings{'internal.crosslistings'} ne '') {
9780: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9781: }
9782:
9783: if (@currxlists > 0) {
9784: foreach (@currxlists) {
9785: if (m/^([^:]+):(\w*)$/) {
9786: unless (grep/^$1$/,@{$allcourses}) {
9787: push @{$allcourses},$1;
9788: $$LC_code{$1} = $2;
9789: }
9790: }
9791: }
9792: }
9793:
9794: if (@currsections > 0) {
9795: foreach (@currsections) {
9796: if (m/^(\w+):(\w*)$/) {
9797: my $sec = $coursecode.$1;
9798: my $lc_sec = $2;
9799: unless (grep/^$sec$/,@{$allcourses}) {
9800: push @{$allcourses},$sec;
9801: $$LC_code{$sec} = $lc_sec;
9802: }
9803: }
9804: }
9805: }
9806: return;
9807: }
9808:
1.971 raeburn 9809: sub get_standard_codeitems {
9810: return ('Year','Semester','Department','Number','Section');
9811: }
9812:
1.112 bowersj2 9813: =pod
9814:
1.780 raeburn 9815: =head1 Slot Helpers
9816:
9817: =over 4
9818:
9819: =item * sorted_slots()
9820:
1.1040 raeburn 9821: Sorts an array of slot names in order of an optional sort key,
9822: default sort is by slot start time (earliest first).
1.780 raeburn 9823:
9824: Inputs:
9825:
9826: =over 4
9827:
9828: slotsarr - Reference to array of unsorted slot names.
9829:
9830: slots - Reference to hash of hash, where outer hash keys are slot names.
9831:
1.1040 raeburn 9832: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9833:
1.549 albertel 9834: =back
9835:
1.780 raeburn 9836: Returns:
9837:
9838: =over 4
9839:
1.1040 raeburn 9840: sorted - An array of slot names sorted by a specified sort key
9841: (default sort key is start time of the slot).
1.780 raeburn 9842:
9843: =back
9844:
9845: =cut
9846:
9847:
9848: sub sorted_slots {
1.1040 raeburn 9849: my ($slotsarr,$slots,$sortkey) = @_;
9850: if ($sortkey eq '') {
9851: $sortkey = 'starttime';
9852: }
1.780 raeburn 9853: my @sorted;
9854: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9855: @sorted =
9856: sort {
9857: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9858: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9859: }
9860: if (ref($slots->{$a})) { return -1;}
9861: if (ref($slots->{$b})) { return 1;}
9862: return 0;
9863: } @{$slotsarr};
9864: }
9865: return @sorted;
9866: }
9867:
1.1040 raeburn 9868: =pod
9869:
9870: =item * get_future_slots()
9871:
9872: Inputs:
9873:
9874: =over 4
9875:
9876: cnum - course number
9877:
9878: cdom - course domain
9879:
9880: now - current UNIX time
9881:
9882: symb - optional symb
9883:
9884: =back
9885:
9886: Returns:
9887:
9888: =over 4
9889:
9890: sorted_reservable - ref to array of student_schedulable slots currently
9891: reservable, ordered by end date of reservation period.
9892:
9893: reservable_now - ref to hash of student_schedulable slots currently
9894: reservable.
9895:
9896: Keys in inner hash are:
9897: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 9898: (b) endreserve: end date of reservation period.
9899: (c) uniqueperiod: start,end dates when slot is to be uniquely
9900: selected.
1.1040 raeburn 9901:
9902: sorted_future - ref to array of student_schedulable slots reservable in
9903: the future, ordered by start date of reservation period.
9904:
9905: future_reservable - ref to hash of student_schedulable slots reservable
9906: in the future.
9907:
9908: Keys in inner hash are:
9909: (a) symb: either blank or symb to which slot use is restricted.
9910: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 9911: (c) uniqueperiod: start,end dates when slot is to be uniquely
9912: selected.
1.1040 raeburn 9913:
9914: =back
9915:
9916: =cut
9917:
9918: sub get_future_slots {
9919: my ($cnum,$cdom,$now,$symb) = @_;
9920: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9921: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9922: foreach my $slot (keys(%slots)) {
9923: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9924: if ($symb) {
9925: next if (($slots{$slot}->{'symb'} ne '') &&
9926: ($slots{$slot}->{'symb'} ne $symb));
9927: }
9928: if (($slots{$slot}->{'starttime'} > $now) &&
9929: ($slots{$slot}->{'endtime'} > $now)) {
9930: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9931: my $userallowed = 0;
9932: if ($slots{$slot}->{'allowedsections'}) {
9933: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9934: if (!defined($env{'request.role.sec'})
9935: && grep(/^No section assigned$/,@allowed_sec)) {
9936: $userallowed=1;
9937: } else {
9938: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9939: $userallowed=1;
9940: }
9941: }
9942: unless ($userallowed) {
9943: if (defined($env{'request.course.groups'})) {
9944: my @groups = split(/:/,$env{'request.course.groups'});
9945: foreach my $group (@groups) {
9946: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9947: $userallowed=1;
9948: last;
9949: }
9950: }
9951: }
9952: }
9953: }
9954: if ($slots{$slot}->{'allowedusers'}) {
9955: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9956: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9957: if (grep(/^\Q$user\E$/,@allowed_users)) {
9958: $userallowed = 1;
9959: }
9960: }
9961: next unless($userallowed);
9962: }
9963: my $startreserve = $slots{$slot}->{'startreserve'};
9964: my $endreserve = $slots{$slot}->{'endreserve'};
9965: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 9966: my $uniqueperiod;
9967: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
9968: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
9969: }
1.1040 raeburn 9970: if (($startreserve < $now) &&
9971: (!$endreserve || $endreserve > $now)) {
9972: my $lastres = $endreserve;
9973: if (!$lastres) {
9974: $lastres = $slots{$slot}->{'starttime'};
9975: }
9976: $reservable_now{$slot} = {
9977: symb => $symb,
1.1075.2.104 raeburn 9978: endreserve => $lastres,
9979: uniqueperiod => $uniqueperiod,
1.1040 raeburn 9980: };
9981: } elsif (($startreserve > $now) &&
9982: (!$endreserve || $endreserve > $startreserve)) {
9983: $future_reservable{$slot} = {
9984: symb => $symb,
1.1075.2.104 raeburn 9985: startreserve => $startreserve,
9986: uniqueperiod => $uniqueperiod,
1.1040 raeburn 9987: };
9988: }
9989: }
9990: }
9991: my @unsorted_reservable = keys(%reservable_now);
9992: if (@unsorted_reservable > 0) {
9993: @sorted_reservable =
9994: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9995: }
9996: my @unsorted_future = keys(%future_reservable);
9997: if (@unsorted_future > 0) {
9998: @sorted_future =
9999: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10000: }
10001: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10002: }
1.780 raeburn 10003:
10004: =pod
10005:
1.1057 foxr 10006: =back
10007:
1.549 albertel 10008: =head1 HTTP Helpers
10009:
10010: =over 4
10011:
1.648 raeburn 10012: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10013:
1.258 albertel 10014: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10015: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10016: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10017:
10018: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10019: $possible_names is an ref to an array of form element names. As an example:
10020: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10021: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10022:
10023: =cut
1.1 albertel 10024:
1.6 albertel 10025: sub get_unprocessed_cgi {
1.25 albertel 10026: my ($query,$possible_names)= @_;
1.26 matthew 10027: # $Apache::lonxml::debug=1;
1.356 albertel 10028: foreach my $pair (split(/&/,$query)) {
10029: my ($name, $value) = split(/=/,$pair);
1.369 www 10030: $name = &unescape($name);
1.25 albertel 10031: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10032: $value =~ tr/+/ /;
10033: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10034: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10035: }
1.16 harris41 10036: }
1.6 albertel 10037: }
10038:
1.112 bowersj2 10039: =pod
10040:
1.648 raeburn 10041: =item * &cacheheader()
1.112 bowersj2 10042:
10043: returns cache-controlling header code
10044:
10045: =cut
10046:
1.7 albertel 10047: sub cacheheader {
1.258 albertel 10048: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10049: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10050: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10051: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10052: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10053: return $output;
1.7 albertel 10054: }
10055:
1.112 bowersj2 10056: =pod
10057:
1.648 raeburn 10058: =item * &no_cache($r)
1.112 bowersj2 10059:
10060: specifies header code to not have cache
10061:
10062: =cut
10063:
1.9 albertel 10064: sub no_cache {
1.216 albertel 10065: my ($r) = @_;
10066: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10067: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10068: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10069: $r->no_cache(1);
10070: $r->header_out("Expires" => $date);
10071: $r->header_out("Pragma" => "no-cache");
1.123 www 10072: }
10073:
10074: sub content_type {
1.181 albertel 10075: my ($r,$type,$charset) = @_;
1.299 foxr 10076: if ($r) {
10077: # Note that printout.pl calls this with undef for $r.
10078: &no_cache($r);
10079: }
1.258 albertel 10080: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10081: unless ($charset) {
10082: $charset=&Apache::lonlocal::current_encoding;
10083: }
10084: if ($charset) { $type.='; charset='.$charset; }
10085: if ($r) {
10086: $r->content_type($type);
10087: } else {
10088: print("Content-type: $type\n\n");
10089: }
1.9 albertel 10090: }
1.25 albertel 10091:
1.112 bowersj2 10092: =pod
10093:
1.648 raeburn 10094: =item * &add_to_env($name,$value)
1.112 bowersj2 10095:
1.258 albertel 10096: adds $name to the %env hash with value
1.112 bowersj2 10097: $value, if $name already exists, the entry is converted to an array
10098: reference and $value is added to the array.
10099:
10100: =cut
10101:
1.25 albertel 10102: sub add_to_env {
10103: my ($name,$value)=@_;
1.258 albertel 10104: if (defined($env{$name})) {
10105: if (ref($env{$name})) {
1.25 albertel 10106: #already have multiple values
1.258 albertel 10107: push(@{ $env{$name} },$value);
1.25 albertel 10108: } else {
10109: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10110: my $first=$env{$name};
10111: undef($env{$name});
10112: push(@{ $env{$name} },$first,$value);
1.25 albertel 10113: }
10114: } else {
1.258 albertel 10115: $env{$name}=$value;
1.25 albertel 10116: }
1.31 albertel 10117: }
1.149 albertel 10118:
10119: =pod
10120:
1.648 raeburn 10121: =item * &get_env_multiple($name)
1.149 albertel 10122:
1.258 albertel 10123: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10124: values may be defined and end up as an array ref.
10125:
10126: returns an array of values
10127:
10128: =cut
10129:
10130: sub get_env_multiple {
10131: my ($name) = @_;
10132: my @values;
1.258 albertel 10133: if (defined($env{$name})) {
1.149 albertel 10134: # exists is it an array
1.258 albertel 10135: if (ref($env{$name})) {
10136: @values=@{ $env{$name} };
1.149 albertel 10137: } else {
1.258 albertel 10138: $values[0]=$env{$name};
1.149 albertel 10139: }
10140: }
10141: return(@values);
10142: }
10143:
1.660 raeburn 10144: sub ask_for_embedded_content {
10145: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10146: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 10147: %currsubfile,%unused,$rem);
1.1071 raeburn 10148: my $counter = 0;
10149: my $numnew = 0;
1.987 raeburn 10150: my $numremref = 0;
10151: my $numinvalid = 0;
10152: my $numpathchg = 0;
10153: my $numexisting = 0;
1.1071 raeburn 10154: my $numunused = 0;
10155: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 10156: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10157: my $heading = &mt('Upload embedded files');
10158: my $buttontext = &mt('Upload');
10159:
1.1075.2.11 raeburn 10160: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 10161: if ($actionurl eq '/adm/dependencies') {
10162: $navmap = Apache::lonnavmaps::navmap->new();
10163: }
10164: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10165: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 10166: }
1.1075.2.35 raeburn 10167: if (($actionurl eq '/adm/portfolio') ||
10168: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10169: my $current_path='/';
10170: if ($env{'form.currentpath'}) {
10171: $current_path = $env{'form.currentpath'};
10172: }
10173: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 10174: $udom = $cdom;
10175: $uname = $cnum;
1.984 raeburn 10176: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10177: } else {
10178: $udom = $env{'user.domain'};
10179: $uname = $env{'user.name'};
10180: $url = '/userfiles/portfolio';
10181: }
1.987 raeburn 10182: $toplevel = $url.'/';
1.984 raeburn 10183: $url .= $current_path;
10184: $getpropath = 1;
1.987 raeburn 10185: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10186: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10187: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10188: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10189: $toplevel = $url;
1.984 raeburn 10190: if ($rest ne '') {
1.987 raeburn 10191: $url .= $rest;
10192: }
10193: } elsif ($actionurl eq '/adm/coursedocs') {
10194: if (ref($args) eq 'HASH') {
1.1071 raeburn 10195: $url = $args->{'docs_url'};
10196: $toplevel = $url;
1.1075.2.11 raeburn 10197: if ($args->{'context'} eq 'paste') {
10198: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10199: ($path) =
10200: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10201: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10202: $fileloc =~ s{^/}{};
10203: }
1.1071 raeburn 10204: }
10205: } elsif ($actionurl eq '/adm/dependencies') {
10206: if ($env{'request.course.id'} ne '') {
10207: if (ref($args) eq 'HASH') {
10208: $url = $args->{'docs_url'};
10209: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 10210: $toplevel = $url;
10211: unless ($toplevel =~ m{^/}) {
10212: $toplevel = "/$url";
10213: }
1.1075.2.11 raeburn 10214: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 10215: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10216: $path = $1;
10217: } else {
10218: ($path) =
10219: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10220: }
1.1075.2.79 raeburn 10221: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10222: $fileloc = $toplevel;
10223: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10224: my ($udom,$uname,$fname) =
10225: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10226: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10227: } else {
10228: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10229: }
1.1071 raeburn 10230: $fileloc =~ s{^/}{};
10231: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10232: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10233: }
1.987 raeburn 10234: }
1.1075.2.35 raeburn 10235: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10236: $udom = $cdom;
10237: $uname = $cnum;
10238: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10239: $toplevel = $url;
10240: $path = $url;
10241: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10242: $fileloc =~ s{^/}{};
10243: }
10244: foreach my $file (keys(%{$allfiles})) {
10245: my $embed_file;
10246: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10247: $embed_file = $1;
10248: } else {
10249: $embed_file = $file;
10250: }
1.1075.2.55 raeburn 10251: my ($absolutepath,$cleaned_file);
10252: if ($embed_file =~ m{^\w+://}) {
10253: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 10254: $newfiles{$cleaned_file} = 1;
10255: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10256: } else {
1.1075.2.55 raeburn 10257: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10258: if ($embed_file =~ m{^/}) {
10259: $absolutepath = $embed_file;
10260: }
1.1075.2.47 raeburn 10261: if ($cleaned_file =~ m{/}) {
10262: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10263: $path = &check_for_traversal($path,$url,$toplevel);
10264: my $item = $fname;
10265: if ($path ne '') {
10266: $item = $path.'/'.$fname;
10267: $subdependencies{$path}{$fname} = 1;
10268: } else {
10269: $dependencies{$item} = 1;
10270: }
10271: if ($absolutepath) {
10272: $mapping{$item} = $absolutepath;
10273: } else {
10274: $mapping{$item} = $embed_file;
10275: }
10276: } else {
10277: $dependencies{$embed_file} = 1;
10278: if ($absolutepath) {
1.1075.2.47 raeburn 10279: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10280: } else {
1.1075.2.47 raeburn 10281: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10282: }
10283: }
1.984 raeburn 10284: }
10285: }
1.1071 raeburn 10286: my $dirptr = 16384;
1.984 raeburn 10287: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10288: $currsubfile{$path} = {};
1.1075.2.35 raeburn 10289: if (($actionurl eq '/adm/portfolio') ||
10290: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10291: my ($sublistref,$listerror) =
10292: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10293: if (ref($sublistref) eq 'ARRAY') {
10294: foreach my $line (@{$sublistref}) {
10295: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10296: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10297: }
1.984 raeburn 10298: }
1.987 raeburn 10299: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10300: if (opendir(my $dir,$url.'/'.$path)) {
10301: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10302: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10303: }
1.1075.2.11 raeburn 10304: } elsif (($actionurl eq '/adm/dependencies') ||
10305: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10306: ($args->{'context'} eq 'paste')) ||
10307: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10308: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 10309: my $dir;
10310: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10311: $dir = $fileloc;
10312: } else {
10313: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10314: }
1.1071 raeburn 10315: if ($dir ne '') {
10316: my ($sublistref,$listerror) =
10317: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10318: if (ref($sublistref) eq 'ARRAY') {
10319: foreach my $line (@{$sublistref}) {
10320: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10321: undef,$mtime)=split(/\&/,$line,12);
10322: unless (($testdir&$dirptr) ||
10323: ($file_name =~ /^\.\.?$/)) {
10324: $currsubfile{$path}{$file_name} = [$size,$mtime];
10325: }
10326: }
10327: }
10328: }
1.984 raeburn 10329: }
10330: }
10331: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10332: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10333: my $item = $path.'/'.$file;
10334: unless ($mapping{$item} eq $item) {
10335: $pathchanges{$item} = 1;
10336: }
10337: $existing{$item} = 1;
10338: $numexisting ++;
10339: } else {
10340: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10341: }
10342: }
1.1071 raeburn 10343: if ($actionurl eq '/adm/dependencies') {
10344: foreach my $path (keys(%currsubfile)) {
10345: if (ref($currsubfile{$path}) eq 'HASH') {
10346: foreach my $file (keys(%{$currsubfile{$path}})) {
10347: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10348: next if (($rem ne '') &&
10349: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10350: (ref($navmap) &&
10351: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10352: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10353: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10354: $unused{$path.'/'.$file} = 1;
10355: }
10356: }
10357: }
10358: }
10359: }
1.984 raeburn 10360: }
1.987 raeburn 10361: my %currfile;
1.1075.2.35 raeburn 10362: if (($actionurl eq '/adm/portfolio') ||
10363: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10364: my ($dirlistref,$listerror) =
10365: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10366: if (ref($dirlistref) eq 'ARRAY') {
10367: foreach my $line (@{$dirlistref}) {
10368: my ($file_name,$rest) = split(/\&/,$line,2);
10369: $currfile{$file_name} = 1;
10370: }
1.984 raeburn 10371: }
1.987 raeburn 10372: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10373: if (opendir(my $dir,$url)) {
1.987 raeburn 10374: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10375: map {$currfile{$_} = 1;} @dir_list;
10376: }
1.1075.2.11 raeburn 10377: } elsif (($actionurl eq '/adm/dependencies') ||
10378: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10379: ($args->{'context'} eq 'paste')) ||
10380: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10381: if ($env{'request.course.id'} ne '') {
10382: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10383: if ($dir ne '') {
10384: my ($dirlistref,$listerror) =
10385: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10386: if (ref($dirlistref) eq 'ARRAY') {
10387: foreach my $line (@{$dirlistref}) {
10388: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10389: $size,undef,$mtime)=split(/\&/,$line,12);
10390: unless (($testdir&$dirptr) ||
10391: ($file_name =~ /^\.\.?$/)) {
10392: $currfile{$file_name} = [$size,$mtime];
10393: }
10394: }
10395: }
10396: }
10397: }
1.984 raeburn 10398: }
10399: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10400: if (exists($currfile{$file})) {
1.987 raeburn 10401: unless ($mapping{$file} eq $file) {
10402: $pathchanges{$file} = 1;
10403: }
10404: $existing{$file} = 1;
10405: $numexisting ++;
10406: } else {
1.984 raeburn 10407: $newfiles{$file} = 1;
10408: }
10409: }
1.1071 raeburn 10410: foreach my $file (keys(%currfile)) {
10411: unless (($file eq $filename) ||
10412: ($file eq $filename.'.bak') ||
10413: ($dependencies{$file})) {
1.1075.2.11 raeburn 10414: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10415: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10416: next if (($rem ne '') &&
10417: (($env{"httpref.$rem".$file} ne '') ||
10418: (ref($navmap) &&
10419: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10420: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10421: ($navmap->getResourceByUrl($rem.$1)))))));
10422: }
1.1075.2.11 raeburn 10423: }
1.1071 raeburn 10424: $unused{$file} = 1;
10425: }
10426: }
1.1075.2.11 raeburn 10427: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10428: ($args->{'context'} eq 'paste')) {
10429: $counter = scalar(keys(%existing));
10430: $numpathchg = scalar(keys(%pathchanges));
10431: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10432: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10433: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10434: $counter = scalar(keys(%existing));
10435: $numpathchg = scalar(keys(%pathchanges));
10436: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10437: }
1.984 raeburn 10438: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10439: if ($actionurl eq '/adm/dependencies') {
10440: next if ($embed_file =~ m{^\w+://});
10441: }
1.660 raeburn 10442: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10443: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10444: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10445: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10446: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10447: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10448: }
1.1075.2.35 raeburn 10449: $upload_output .= '</td>';
1.1071 raeburn 10450: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10451: $upload_output.='<td align="right">'.
10452: '<span class="LC_info LC_fontsize_medium">'.
10453: &mt("URL points to web address").'</span>';
1.987 raeburn 10454: $numremref++;
1.660 raeburn 10455: } elsif ($args->{'error_on_invalid_names'}
10456: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10457: $upload_output.='<td align="right"><span class="LC_warning">'.
10458: &mt('Invalid characters').'</span>';
1.987 raeburn 10459: $numinvalid++;
1.660 raeburn 10460: } else {
1.1075.2.35 raeburn 10461: $upload_output .= '<td>'.
10462: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10463: $embed_file,\%mapping,
1.1071 raeburn 10464: $allfiles,$codebase,'upload');
10465: $counter ++;
10466: $numnew ++;
1.987 raeburn 10467: }
10468: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10469: }
10470: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10471: if ($actionurl eq '/adm/dependencies') {
10472: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10473: $modify_output .= &start_data_table_row().
10474: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10475: '<img src="'.&icon($embed_file).'" border="0" />'.
10476: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10477: '<td>'.$size.'</td>'.
10478: '<td>'.$mtime.'</td>'.
10479: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10480: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10481: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10482: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10483: &embedded_file_element('upload_embedded',$counter,
10484: $embed_file,\%mapping,
10485: $allfiles,$codebase,'modify').
10486: '</div></td>'.
10487: &end_data_table_row()."\n";
10488: $counter ++;
10489: } else {
10490: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10491: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10492: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10493: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10494: &Apache::loncommon::end_data_table_row()."\n";
10495: }
10496: }
10497: my $delidx = $counter;
10498: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10499: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10500: $delete_output .= &start_data_table_row().
10501: '<td><img src="'.&icon($oldfile).'" />'.
10502: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10503: '<td>'.$size.'</td>'.
10504: '<td>'.$mtime.'</td>'.
10505: '<td><label><input type="checkbox" name="del_upload_dep" '.
10506: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10507: &embedded_file_element('upload_embedded',$delidx,
10508: $oldfile,\%mapping,$allfiles,
10509: $codebase,'delete').'</td>'.
10510: &end_data_table_row()."\n";
10511: $numunused ++;
10512: $delidx ++;
1.987 raeburn 10513: }
10514: if ($upload_output) {
10515: $upload_output = &start_data_table().
10516: $upload_output.
10517: &end_data_table()."\n";
10518: }
1.1071 raeburn 10519: if ($modify_output) {
10520: $modify_output = &start_data_table().
10521: &start_data_table_header_row().
10522: '<th>'.&mt('File').'</th>'.
10523: '<th>'.&mt('Size (KB)').'</th>'.
10524: '<th>'.&mt('Modified').'</th>'.
10525: '<th>'.&mt('Upload replacement?').'</th>'.
10526: &end_data_table_header_row().
10527: $modify_output.
10528: &end_data_table()."\n";
10529: }
10530: if ($delete_output) {
10531: $delete_output = &start_data_table().
10532: &start_data_table_header_row().
10533: '<th>'.&mt('File').'</th>'.
10534: '<th>'.&mt('Size (KB)').'</th>'.
10535: '<th>'.&mt('Modified').'</th>'.
10536: '<th>'.&mt('Delete?').'</th>'.
10537: &end_data_table_header_row().
10538: $delete_output.
10539: &end_data_table()."\n";
10540: }
1.987 raeburn 10541: my $applies = 0;
10542: if ($numremref) {
10543: $applies ++;
10544: }
10545: if ($numinvalid) {
10546: $applies ++;
10547: }
10548: if ($numexisting) {
10549: $applies ++;
10550: }
1.1071 raeburn 10551: if ($counter || $numunused) {
1.987 raeburn 10552: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10553: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10554: $state.'<h3>'.$heading.'</h3>';
10555: if ($actionurl eq '/adm/dependencies') {
10556: if ($numnew) {
10557: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10558: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10559: $upload_output.'<br />'."\n";
10560: }
10561: if ($numexisting) {
10562: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10563: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10564: $modify_output.'<br />'."\n";
10565: $buttontext = &mt('Save changes');
10566: }
10567: if ($numunused) {
10568: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10569: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10570: $delete_output.'<br />'."\n";
10571: $buttontext = &mt('Save changes');
10572: }
10573: } else {
10574: $output .= $upload_output.'<br />'."\n";
10575: }
10576: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10577: $counter.'" />'."\n";
10578: if ($actionurl eq '/adm/dependencies') {
10579: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10580: $numnew.'" />'."\n";
10581: } elsif ($actionurl eq '') {
1.987 raeburn 10582: $output .= '<input type="hidden" name="phase" value="three" />';
10583: }
10584: } elsif ($applies) {
10585: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10586: if ($applies > 1) {
10587: $output .=
1.1075.2.35 raeburn 10588: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10589: if ($numremref) {
10590: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10591: }
10592: if ($numinvalid) {
10593: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10594: }
10595: if ($numexisting) {
10596: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10597: }
10598: $output .= '</ul><br />';
10599: } elsif ($numremref) {
10600: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10601: } elsif ($numinvalid) {
10602: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10603: } elsif ($numexisting) {
10604: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10605: }
10606: $output .= $upload_output.'<br />';
10607: }
10608: my ($pathchange_output,$chgcount);
1.1071 raeburn 10609: $chgcount = $counter;
1.987 raeburn 10610: if (keys(%pathchanges) > 0) {
10611: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10612: if ($counter) {
1.987 raeburn 10613: $output .= &embedded_file_element('pathchange',$chgcount,
10614: $embed_file,\%mapping,
1.1071 raeburn 10615: $allfiles,$codebase,'change');
1.987 raeburn 10616: } else {
10617: $pathchange_output .=
10618: &start_data_table_row().
10619: '<td><input type ="checkbox" name="namechange" value="'.
10620: $chgcount.'" checked="checked" /></td>'.
10621: '<td>'.$mapping{$embed_file}.'</td>'.
10622: '<td>'.$embed_file.
10623: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10624: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10625: '</td>'.&end_data_table_row();
1.660 raeburn 10626: }
1.987 raeburn 10627: $numpathchg ++;
10628: $chgcount ++;
1.660 raeburn 10629: }
10630: }
1.1075.2.35 raeburn 10631: if (($counter) || ($numunused)) {
1.987 raeburn 10632: if ($numpathchg) {
10633: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10634: $numpathchg.'" />'."\n";
10635: }
10636: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10637: ($actionurl eq '/adm/imsimport')) {
10638: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10639: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10640: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10641: } elsif ($actionurl eq '/adm/dependencies') {
10642: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10643: }
1.1075.2.35 raeburn 10644: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10645: } elsif ($numpathchg) {
10646: my %pathchange = ();
10647: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10648: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10649: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 10650: }
1.987 raeburn 10651: }
1.1071 raeburn 10652: return ($output,$counter,$numpathchg);
1.987 raeburn 10653: }
10654:
1.1075.2.47 raeburn 10655: =pod
10656:
10657: =item * clean_path($name)
10658:
10659: Performs clean-up of directories, subdirectories and filename in an
10660: embedded object, referenced in an HTML file which is being uploaded
10661: to a course or portfolio, where
10662: "Upload embedded images/multimedia files if HTML file" checkbox was
10663: checked.
10664:
10665: Clean-up is similar to replacements in lonnet::clean_filename()
10666: except each / between sub-directory and next level is preserved.
10667:
10668: =cut
10669:
10670: sub clean_path {
10671: my ($embed_file) = @_;
10672: $embed_file =~s{^/+}{};
10673: my @contents;
10674: if ($embed_file =~ m{/}) {
10675: @contents = split(/\//,$embed_file);
10676: } else {
10677: @contents = ($embed_file);
10678: }
10679: my $lastidx = scalar(@contents)-1;
10680: for (my $i=0; $i<=$lastidx; $i++) {
10681: $contents[$i]=~s{\\}{/}g;
10682: $contents[$i]=~s/\s+/\_/g;
10683: $contents[$i]=~s{[^/\w\.\-]}{}g;
10684: if ($i == $lastidx) {
10685: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10686: }
10687: }
10688: if ($lastidx > 0) {
10689: return join('/',@contents);
10690: } else {
10691: return $contents[0];
10692: }
10693: }
10694:
1.987 raeburn 10695: sub embedded_file_element {
1.1071 raeburn 10696: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10697: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10698: (ref($codebase) eq 'HASH'));
10699: my $output;
1.1071 raeburn 10700: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10701: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10702: }
10703: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10704: &escape($embed_file).'" />';
10705: unless (($context eq 'upload_embedded') &&
10706: ($mapping->{$embed_file} eq $embed_file)) {
10707: $output .='
10708: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10709: }
10710: my $attrib;
10711: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10712: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10713: }
10714: $output .=
10715: "\n\t\t".
10716: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10717: $attrib.'" />';
10718: if (exists($codebase->{$mapping->{$embed_file}})) {
10719: $output .=
10720: "\n\t\t".
10721: '<input name="codebase_'.$num.'" type="hidden" value="'.
10722: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10723: }
1.987 raeburn 10724: return $output;
1.660 raeburn 10725: }
10726:
1.1071 raeburn 10727: sub get_dependency_details {
10728: my ($currfile,$currsubfile,$embed_file) = @_;
10729: my ($size,$mtime,$showsize,$showmtime);
10730: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10731: if ($embed_file =~ m{/}) {
10732: my ($path,$fname) = split(/\//,$embed_file);
10733: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10734: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10735: }
10736: } else {
10737: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10738: ($size,$mtime) = @{$currfile->{$embed_file}};
10739: }
10740: }
10741: $showsize = $size/1024.0;
10742: $showsize = sprintf("%.1f",$showsize);
10743: if ($mtime > 0) {
10744: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10745: }
10746: }
10747: return ($showsize,$showmtime);
10748: }
10749:
10750: sub ask_embedded_js {
10751: return <<"END";
10752: <script type="text/javascript"">
10753: // <![CDATA[
10754: function toggleBrowse(counter) {
10755: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10756: var fileid = document.getElementById('embedded_item_'+counter);
10757: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10758: if (chkboxid.checked == true) {
10759: uploaddivid.style.display='block';
10760: } else {
10761: uploaddivid.style.display='none';
10762: fileid.value = '';
10763: }
10764: }
10765: // ]]>
10766: </script>
10767:
10768: END
10769: }
10770:
1.661 raeburn 10771: sub upload_embedded {
10772: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10773: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10774: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10775: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10776: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10777: my $orig_uploaded_filename =
10778: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10779: foreach my $type ('orig','ref','attrib','codebase') {
10780: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10781: $env{'form.embedded_'.$type.'_'.$i} =
10782: &unescape($env{'form.embedded_'.$type.'_'.$i});
10783: }
10784: }
1.661 raeburn 10785: my ($path,$fname) =
10786: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10787: # no path, whole string is fname
10788: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10789: $fname = &Apache::lonnet::clean_filename($fname);
10790: # See if there is anything left
10791: next if ($fname eq '');
10792:
10793: # Check if file already exists as a file or directory.
10794: my ($state,$msg);
10795: if ($context eq 'portfolio') {
10796: my $port_path = $dirpath;
10797: if ($group ne '') {
10798: $port_path = "groups/$group/$port_path";
10799: }
1.987 raeburn 10800: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10801: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10802: $dir_root,$port_path,$disk_quota,
10803: $current_disk_usage,$uname,$udom);
10804: if ($state eq 'will_exceed_quota'
1.984 raeburn 10805: || $state eq 'file_locked') {
1.661 raeburn 10806: $output .= $msg;
10807: next;
10808: }
10809: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10810: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10811: if ($state eq 'exists') {
10812: $output .= $msg;
10813: next;
10814: }
10815: }
10816: # Check if extension is valid
10817: if (($fname =~ /\.(\w+)$/) &&
10818: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 10819: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
10820: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 10821: next;
10822: } elsif (($fname =~ /\.(\w+)$/) &&
10823: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10824: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10825: next;
10826: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 10827: $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 10828: next;
10829: }
10830: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 10831: my $subdir = $path;
10832: $subdir =~ s{/+$}{};
1.661 raeburn 10833: if ($context eq 'portfolio') {
1.984 raeburn 10834: my $result;
10835: if ($state eq 'existingfile') {
10836: $result=
10837: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 10838: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10839: } else {
1.984 raeburn 10840: $result=
10841: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10842: $dirpath.
1.1075.2.35 raeburn 10843: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10844: if ($result !~ m|^/uploaded/|) {
10845: $output .= '<span class="LC_error">'
10846: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10847: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10848: .'</span><br />';
10849: next;
10850: } else {
1.987 raeburn 10851: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10852: $path.$fname.'</span>').'<br />';
1.984 raeburn 10853: }
1.661 raeburn 10854: }
1.1075.2.35 raeburn 10855: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
10856: my $extendedsubdir = $dirpath.'/'.$subdir;
10857: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10858: my $result =
1.1075.2.35 raeburn 10859: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10860: if ($result !~ m|^/uploaded/|) {
10861: $output .= '<span class="LC_error">'
10862: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10863: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10864: .'</span><br />';
10865: next;
10866: } else {
10867: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10868: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 10869: if ($context eq 'syllabus') {
10870: &Apache::lonnet::make_public_indefinitely($result);
10871: }
1.987 raeburn 10872: }
1.661 raeburn 10873: } else {
10874: # Save the file
10875: my $target = $env{'form.embedded_item_'.$i};
10876: my $fullpath = $dir_root.$dirpath.'/'.$path;
10877: my $dest = $fullpath.$fname;
10878: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10879: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10880: my $count;
10881: my $filepath = $dir_root;
1.1027 raeburn 10882: foreach my $subdir (@parts) {
10883: $filepath .= "/$subdir";
10884: if (!-e $filepath) {
1.661 raeburn 10885: mkdir($filepath,0770);
10886: }
10887: }
10888: my $fh;
10889: if (!open($fh,'>'.$dest)) {
10890: &Apache::lonnet::logthis('Failed to create '.$dest);
10891: $output .= '<span class="LC_error">'.
1.1071 raeburn 10892: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10893: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10894: '</span><br />';
10895: } else {
10896: if (!print $fh $env{'form.embedded_item_'.$i}) {
10897: &Apache::lonnet::logthis('Failed to write to '.$dest);
10898: $output .= '<span class="LC_error">'.
1.1071 raeburn 10899: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10900: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10901: '</span><br />';
10902: } else {
1.987 raeburn 10903: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10904: $url.'</span>').'<br />';
10905: unless ($context eq 'testbank') {
10906: $footer .= &mt('View embedded file: [_1]',
10907: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10908: }
10909: }
10910: close($fh);
10911: }
10912: }
10913: if ($env{'form.embedded_ref_'.$i}) {
10914: $pathchange{$i} = 1;
10915: }
10916: }
10917: if ($output) {
10918: $output = '<p>'.$output.'</p>';
10919: }
10920: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10921: $returnflag = 'ok';
1.1071 raeburn 10922: my $numpathchgs = scalar(keys(%pathchange));
10923: if ($numpathchgs > 0) {
1.987 raeburn 10924: if ($context eq 'portfolio') {
10925: $output .= '<p>'.&mt('or').'</p>';
10926: } elsif ($context eq 'testbank') {
1.1071 raeburn 10927: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10928: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10929: $returnflag = 'modify_orightml';
10930: }
10931: }
1.1071 raeburn 10932: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10933: }
10934:
10935: sub modify_html_form {
10936: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10937: my $end = 0;
10938: my $modifyform;
10939: if ($context eq 'upload_embedded') {
10940: return unless (ref($pathchange) eq 'HASH');
10941: if ($env{'form.number_embedded_items'}) {
10942: $end += $env{'form.number_embedded_items'};
10943: }
10944: if ($env{'form.number_pathchange_items'}) {
10945: $end += $env{'form.number_pathchange_items'};
10946: }
10947: if ($end) {
10948: for (my $i=0; $i<$end; $i++) {
10949: if ($i < $env{'form.number_embedded_items'}) {
10950: next unless($pathchange->{$i});
10951: }
10952: $modifyform .=
10953: &start_data_table_row().
10954: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10955: 'checked="checked" /></td>'.
10956: '<td>'.$env{'form.embedded_ref_'.$i}.
10957: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10958: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10959: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10960: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10961: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10962: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10963: '<td>'.$env{'form.embedded_orig_'.$i}.
10964: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10965: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10966: &end_data_table_row();
1.1071 raeburn 10967: }
1.987 raeburn 10968: }
10969: } else {
10970: $modifyform = $pathchgtable;
10971: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10972: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10973: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10974: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10975: }
10976: }
10977: if ($modifyform) {
1.1071 raeburn 10978: if ($actionurl eq '/adm/dependencies') {
10979: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10980: }
1.987 raeburn 10981: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10982: '<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".
10983: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10984: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10985: '</ol></p>'."\n".'<p>'.
10986: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10987: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10988: &start_data_table()."\n".
10989: &start_data_table_header_row().
10990: '<th>'.&mt('Change?').'</th>'.
10991: '<th>'.&mt('Current reference').'</th>'.
10992: '<th>'.&mt('Required reference').'</th>'.
10993: &end_data_table_header_row()."\n".
10994: $modifyform.
10995: &end_data_table().'<br />'."\n".$hiddenstate.
10996: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10997: '</form>'."\n";
10998: }
10999: return;
11000: }
11001:
11002: sub modify_html_refs {
1.1075.2.35 raeburn 11003: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11004: my $container;
11005: if ($context eq 'portfolio') {
11006: $container = $env{'form.container'};
11007: } elsif ($context eq 'coursedoc') {
11008: $container = $env{'form.primaryurl'};
1.1071 raeburn 11009: } elsif ($context eq 'manage_dependencies') {
11010: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11011: $container = "/$container";
1.1075.2.35 raeburn 11012: } elsif ($context eq 'syllabus') {
11013: $container = $url;
1.987 raeburn 11014: } else {
1.1027 raeburn 11015: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11016: }
11017: my (%allfiles,%codebase,$output,$content);
11018: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11019: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11020: if (wantarray) {
11021: return ('',0,0);
11022: } else {
11023: return;
11024: }
11025: }
11026: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11027: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11028: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11029: if (wantarray) {
11030: return ('',0,0);
11031: } else {
11032: return;
11033: }
11034: }
1.987 raeburn 11035: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11036: if ($content eq '-1') {
11037: if (wantarray) {
11038: return ('',0,0);
11039: } else {
11040: return;
11041: }
11042: }
1.987 raeburn 11043: } else {
1.1071 raeburn 11044: unless ($container =~ /^\Q$dir_root\E/) {
11045: if (wantarray) {
11046: return ('',0,0);
11047: } else {
11048: return;
11049: }
11050: }
1.987 raeburn 11051: if (open(my $fh,"<$container")) {
11052: $content = join('', <$fh>);
11053: close($fh);
11054: } else {
1.1071 raeburn 11055: if (wantarray) {
11056: return ('',0,0);
11057: } else {
11058: return;
11059: }
1.987 raeburn 11060: }
11061: }
11062: my ($count,$codebasecount) = (0,0);
11063: my $mm = new File::MMagic;
11064: my $mime_type = $mm->checktype_contents($content);
11065: if ($mime_type eq 'text/html') {
11066: my $parse_result =
11067: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11068: \%codebase,\$content);
11069: if ($parse_result eq 'ok') {
11070: foreach my $i (@changes) {
11071: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11072: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11073: if ($allfiles{$ref}) {
11074: my $newname = $orig;
11075: my ($attrib_regexp,$codebase);
1.1006 raeburn 11076: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11077: if ($attrib_regexp =~ /:/) {
11078: $attrib_regexp =~ s/\:/|/g;
11079: }
11080: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11081: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11082: $count += $numchg;
1.1075.2.35 raeburn 11083: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11084: delete($allfiles{$ref});
1.987 raeburn 11085: }
11086: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11087: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11088: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11089: $codebasecount ++;
11090: }
11091: }
11092: }
1.1075.2.35 raeburn 11093: my $skiprewrites;
1.987 raeburn 11094: if ($count || $codebasecount) {
11095: my $saveresult;
1.1071 raeburn 11096: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11097: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11098: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11099: if ($url eq $container) {
11100: my ($fname) = ($container =~ m{/([^/]+)$});
11101: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11102: $count,'<span class="LC_filename">'.
1.1071 raeburn 11103: $fname.'</span>').'</p>';
1.987 raeburn 11104: } else {
11105: $output = '<p class="LC_error">'.
11106: &mt('Error: update failed for: [_1].',
11107: '<span class="LC_filename">'.
11108: $container.'</span>').'</p>';
11109: }
1.1075.2.35 raeburn 11110: if ($context eq 'syllabus') {
11111: unless ($saveresult eq 'ok') {
11112: $skiprewrites = 1;
11113: }
11114: }
1.987 raeburn 11115: } else {
11116: if (open(my $fh,">$container")) {
11117: print $fh $content;
11118: close($fh);
11119: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11120: $count,'<span class="LC_filename">'.
11121: $container.'</span>').'</p>';
1.661 raeburn 11122: } else {
1.987 raeburn 11123: $output = '<p class="LC_error">'.
11124: &mt('Error: could not update [_1].',
11125: '<span class="LC_filename">'.
11126: $container.'</span>').'</p>';
1.661 raeburn 11127: }
11128: }
11129: }
1.1075.2.35 raeburn 11130: if (($context eq 'syllabus') && (!$skiprewrites)) {
11131: my ($actionurl,$state);
11132: $actionurl = "/public/$udom/$uname/syllabus";
11133: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11134: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11135: \%codebase,
11136: {'context' => 'rewrites',
11137: 'ignore_remote_references' => 1,});
11138: if (ref($mapping) eq 'HASH') {
11139: my $rewrites = 0;
11140: foreach my $key (keys(%{$mapping})) {
11141: next if ($key =~ m{^https?://});
11142: my $ref = $mapping->{$key};
11143: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11144: my $attrib;
11145: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11146: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11147: }
11148: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11149: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11150: $rewrites += $numchg;
11151: }
11152: }
11153: if ($rewrites) {
11154: my $saveresult;
11155: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11156: if ($url eq $container) {
11157: my ($fname) = ($container =~ m{/([^/]+)$});
11158: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11159: $count,'<span class="LC_filename">'.
11160: $fname.'</span>').'</p>';
11161: } else {
11162: $output .= '<p class="LC_error">'.
11163: &mt('Error: could not update links in [_1].',
11164: '<span class="LC_filename">'.
11165: $container.'</span>').'</p>';
11166:
11167: }
11168: }
11169: }
11170: }
1.987 raeburn 11171: } else {
11172: &logthis('Failed to parse '.$container.
11173: ' to modify references: '.$parse_result);
1.661 raeburn 11174: }
11175: }
1.1071 raeburn 11176: if (wantarray) {
11177: return ($output,$count,$codebasecount);
11178: } else {
11179: return $output;
11180: }
1.661 raeburn 11181: }
11182:
11183: sub check_for_existing {
11184: my ($path,$fname,$element) = @_;
11185: my ($state,$msg);
11186: if (-d $path.'/'.$fname) {
11187: $state = 'exists';
11188: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11189: } elsif (-e $path.'/'.$fname) {
11190: $state = 'exists';
11191: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11192: }
11193: if ($state eq 'exists') {
11194: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11195: }
11196: return ($state,$msg);
11197: }
11198:
11199: sub check_for_upload {
11200: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11201: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11202: my $filesize = length($env{'form.'.$element});
11203: if (!$filesize) {
11204: my $msg = '<span class="LC_error">'.
11205: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11206: '<span class="LC_filename">'.$fname.'</span>',
11207: $filesize).'<br />'.
1.1007 raeburn 11208: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11209: '</span>';
11210: return ('zero_bytes',$msg);
11211: }
11212: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11213: my $getpropath = 1;
1.1021 raeburn 11214: my ($dirlistref,$listerror) =
11215: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11216: my $found_file = 0;
11217: my $locked_file = 0;
1.991 raeburn 11218: my @lockers;
11219: my $navmap;
11220: if ($env{'request.course.id'}) {
11221: $navmap = Apache::lonnavmaps::navmap->new();
11222: }
1.1021 raeburn 11223: if (ref($dirlistref) eq 'ARRAY') {
11224: foreach my $line (@{$dirlistref}) {
11225: my ($file_name,$rest)=split(/\&/,$line,2);
11226: if ($file_name eq $fname){
11227: $file_name = $path.$file_name;
11228: if ($group ne '') {
11229: $file_name = $group.$file_name;
11230: }
11231: $found_file = 1;
11232: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11233: foreach my $lock (@lockers) {
11234: if (ref($lock) eq 'ARRAY') {
11235: my ($symb,$crsid) = @{$lock};
11236: if ($crsid eq $env{'request.course.id'}) {
11237: if (ref($navmap)) {
11238: my $res = $navmap->getBySymb($symb);
11239: foreach my $part (@{$res->parts()}) {
11240: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11241: unless (($slot_status == $res->RESERVED) ||
11242: ($slot_status == $res->RESERVED_LOCATION)) {
11243: $locked_file = 1;
11244: }
1.991 raeburn 11245: }
1.1021 raeburn 11246: } else {
11247: $locked_file = 1;
1.991 raeburn 11248: }
11249: } else {
11250: $locked_file = 1;
11251: }
11252: }
1.1021 raeburn 11253: }
11254: } else {
11255: my @info = split(/\&/,$rest);
11256: my $currsize = $info[6]/1000;
11257: if ($currsize < $filesize) {
11258: my $extra = $filesize - $currsize;
11259: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 11260: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11261: &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 11262: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11263: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11264: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11265: return ('will_exceed_quota',$msg);
11266: }
1.984 raeburn 11267: }
11268: }
1.661 raeburn 11269: }
11270: }
11271: }
11272: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 11273: my $msg = '<p class="LC_warning">'.
11274: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
11275: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11276: return ('will_exceed_quota',$msg);
11277: } elsif ($found_file) {
11278: if ($locked_file) {
1.1075.2.69 raeburn 11279: my $msg = '<p class="LC_warning">';
1.661 raeburn 11280: $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 11281: $msg .= '</p>';
1.661 raeburn 11282: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11283: return ('file_locked',$msg);
11284: } else {
1.1075.2.69 raeburn 11285: my $msg = '<p class="LC_error">';
1.984 raeburn 11286: $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 11287: $msg .= '</p>';
1.984 raeburn 11288: return ('existingfile',$msg);
1.661 raeburn 11289: }
11290: }
11291: }
11292:
1.987 raeburn 11293: sub check_for_traversal {
11294: my ($path,$url,$toplevel) = @_;
11295: my @parts=split(/\//,$path);
11296: my $cleanpath;
11297: my $fullpath = $url;
11298: for (my $i=0;$i<@parts;$i++) {
11299: next if ($parts[$i] eq '.');
11300: if ($parts[$i] eq '..') {
11301: $fullpath =~ s{([^/]+/)$}{};
11302: } else {
11303: $fullpath .= $parts[$i].'/';
11304: }
11305: }
11306: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11307: $cleanpath = $1;
11308: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11309: my $curr_toprel = $1;
11310: my @parts = split(/\//,$curr_toprel);
11311: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11312: my @urlparts = split(/\//,$url_toprel);
11313: my $doubledots;
11314: my $startdiff = -1;
11315: for (my $i=0; $i<@urlparts; $i++) {
11316: if ($startdiff == -1) {
11317: unless ($urlparts[$i] eq $parts[$i]) {
11318: $startdiff = $i;
11319: $doubledots .= '../';
11320: }
11321: } else {
11322: $doubledots .= '../';
11323: }
11324: }
11325: if ($startdiff > -1) {
11326: $cleanpath = $doubledots;
11327: for (my $i=$startdiff; $i<@parts; $i++) {
11328: $cleanpath .= $parts[$i].'/';
11329: }
11330: }
11331: }
11332: $cleanpath =~ s{(/)$}{};
11333: return $cleanpath;
11334: }
1.31 albertel 11335:
1.1053 raeburn 11336: sub is_archive_file {
11337: my ($mimetype) = @_;
11338: if (($mimetype eq 'application/octet-stream') ||
11339: ($mimetype eq 'application/x-stuffit') ||
11340: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11341: return 1;
11342: }
11343: return;
11344: }
11345:
11346: sub decompress_form {
1.1065 raeburn 11347: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11348: my %lt = &Apache::lonlocal::texthash (
11349: this => 'This file is an archive file.',
1.1067 raeburn 11350: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11351: itsc => 'Its contents are as follows:',
1.1053 raeburn 11352: youm => 'You may wish to extract its contents.',
11353: extr => 'Extract contents',
1.1067 raeburn 11354: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11355: proa => 'Process automatically?',
1.1053 raeburn 11356: yes => 'Yes',
11357: no => 'No',
1.1067 raeburn 11358: fold => 'Title for folder containing movie',
11359: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11360: );
1.1065 raeburn 11361: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11362: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11363: my $info = &list_archive_contents($fileloc,\@paths);
11364: if (@paths) {
11365: foreach my $path (@paths) {
11366: $path =~ s{^/}{};
1.1067 raeburn 11367: if ($path =~ m{^([^/]+)/$}) {
11368: $topdir = $1;
11369: }
1.1065 raeburn 11370: if ($path =~ m{^([^/]+)/}) {
11371: $toplevel{$1} = $path;
11372: } else {
11373: $toplevel{$path} = $path;
11374: }
11375: }
11376: }
1.1067 raeburn 11377: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 11378: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11379: "$topdir/media/",
11380: "$topdir/media/$topdir.mp4",
11381: "$topdir/media/FirstFrame.png",
11382: "$topdir/media/player.swf",
11383: "$topdir/media/swfobject.js",
11384: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 11385: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 11386: "$topdir/$topdir.mp4",
11387: "$topdir/$topdir\_config.xml",
11388: "$topdir/$topdir\_controller.swf",
11389: "$topdir/$topdir\_embed.css",
11390: "$topdir/$topdir\_First_Frame.png",
11391: "$topdir/$topdir\_player.html",
11392: "$topdir/$topdir\_Thumbnails.png",
11393: "$topdir/playerProductInstall.swf",
11394: "$topdir/scripts/",
11395: "$topdir/scripts/config_xml.js",
11396: "$topdir/scripts/handlebars.js",
11397: "$topdir/scripts/jquery-1.7.1.min.js",
11398: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11399: "$topdir/scripts/modernizr.js",
11400: "$topdir/scripts/player-min.js",
11401: "$topdir/scripts/swfobject.js",
11402: "$topdir/skins/",
11403: "$topdir/skins/configuration_express.xml",
11404: "$topdir/skins/express_show/",
11405: "$topdir/skins/express_show/player-min.css",
11406: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 11407: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11408: "$topdir/$topdir.mp4",
11409: "$topdir/$topdir\_config.xml",
11410: "$topdir/$topdir\_controller.swf",
11411: "$topdir/$topdir\_embed.css",
11412: "$topdir/$topdir\_First_Frame.png",
11413: "$topdir/$topdir\_player.html",
11414: "$topdir/$topdir\_Thumbnails.png",
11415: "$topdir/playerProductInstall.swf",
11416: "$topdir/scripts/",
11417: "$topdir/scripts/config_xml.js",
11418: "$topdir/scripts/techsmith-smart-player.min.js",
11419: "$topdir/skins/",
11420: "$topdir/skins/configuration_express.xml",
11421: "$topdir/skins/express_show/",
11422: "$topdir/skins/express_show/spritesheet.min.css",
11423: "$topdir/skins/express_show/spritesheet.png",
11424: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 11425: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11426: if (@diffs == 0) {
1.1075.2.59 raeburn 11427: $is_camtasia = 6;
11428: } else {
1.1075.2.81 raeburn 11429: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 11430: if (@diffs == 0) {
11431: $is_camtasia = 8;
1.1075.2.81 raeburn 11432: } else {
11433: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
11434: if (@diffs == 0) {
11435: $is_camtasia = 8;
11436: }
1.1075.2.59 raeburn 11437: }
1.1067 raeburn 11438: }
11439: }
11440: my $output;
11441: if ($is_camtasia) {
11442: $output = <<"ENDCAM";
11443: <script type="text/javascript" language="Javascript">
11444: // <![CDATA[
11445:
11446: function camtasiaToggle() {
11447: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11448: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 11449: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11450: document.getElementById('camtasia_titles').style.display='block';
11451: } else {
11452: document.getElementById('camtasia_titles').style.display='none';
11453: }
11454: }
11455: }
11456: return;
11457: }
11458:
11459: // ]]>
11460: </script>
11461: <p>$lt{'camt'}</p>
11462: ENDCAM
1.1065 raeburn 11463: } else {
1.1067 raeburn 11464: $output = '<p>'.$lt{'this'};
11465: if ($info eq '') {
11466: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11467: } else {
11468: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11469: '<div><pre>'.$info.'</pre></div>';
11470: }
1.1065 raeburn 11471: }
1.1067 raeburn 11472: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11473: my $duplicates;
11474: my $num = 0;
11475: if (ref($dirlist) eq 'ARRAY') {
11476: foreach my $item (@{$dirlist}) {
11477: if (ref($item) eq 'ARRAY') {
11478: if (exists($toplevel{$item->[0]})) {
11479: $duplicates .=
11480: &start_data_table_row().
11481: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11482: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11483: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11484: 'value="1" />'.&mt('Yes').'</label>'.
11485: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11486: '<td>'.$item->[0].'</td>';
11487: if ($item->[2]) {
11488: $duplicates .= '<td>'.&mt('Directory').'</td>';
11489: } else {
11490: $duplicates .= '<td>'.&mt('File').'</td>';
11491: }
11492: $duplicates .= '<td>'.$item->[3].'</td>'.
11493: '<td>'.
11494: &Apache::lonlocal::locallocaltime($item->[4]).
11495: '</td>'.
11496: &end_data_table_row();
11497: $num ++;
11498: }
11499: }
11500: }
11501: }
11502: my $itemcount;
11503: if (@paths > 0) {
11504: $itemcount = scalar(@paths);
11505: } else {
11506: $itemcount = 1;
11507: }
1.1067 raeburn 11508: if ($is_camtasia) {
11509: $output .= $lt{'auto'}.'<br />'.
11510: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 11511: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11512: $lt{'yes'}.'</label> <label>'.
11513: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11514: $lt{'no'}.'</label></span><br />'.
11515: '<div id="camtasia_titles" style="display:block">'.
11516: &Apache::lonhtmlcommon::start_pick_box().
11517: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11518: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11519: &Apache::lonhtmlcommon::row_closure().
11520: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11521: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11522: &Apache::lonhtmlcommon::row_closure(1).
11523: &Apache::lonhtmlcommon::end_pick_box().
11524: '</div>';
11525: }
1.1065 raeburn 11526: $output .=
11527: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11528: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11529: "\n";
1.1065 raeburn 11530: if ($duplicates ne '') {
11531: $output .= '<p><span class="LC_warning">'.
11532: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11533: &start_data_table().
11534: &start_data_table_header_row().
11535: '<th>'.&mt('Overwrite?').'</th>'.
11536: '<th>'.&mt('Name').'</th>'.
11537: '<th>'.&mt('Type').'</th>'.
11538: '<th>'.&mt('Size').'</th>'.
11539: '<th>'.&mt('Last modified').'</th>'.
11540: &end_data_table_header_row().
11541: $duplicates.
11542: &end_data_table().
11543: '</p>';
11544: }
1.1067 raeburn 11545: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11546: if (ref($hiddenelements) eq 'HASH') {
11547: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11548: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11549: }
11550: }
11551: $output .= <<"END";
1.1067 raeburn 11552: <br />
1.1053 raeburn 11553: <input type="submit" name="decompress" value="$lt{'extr'}" />
11554: </form>
11555: $noextract
11556: END
11557: return $output;
11558: }
11559:
1.1065 raeburn 11560: sub decompression_utility {
11561: my ($program) = @_;
11562: my @utilities = ('tar','gunzip','bunzip2','unzip');
11563: my $location;
11564: if (grep(/^\Q$program\E$/,@utilities)) {
11565: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11566: '/usr/sbin/') {
11567: if (-x $dir.$program) {
11568: $location = $dir.$program;
11569: last;
11570: }
11571: }
11572: }
11573: return $location;
11574: }
11575:
11576: sub list_archive_contents {
11577: my ($file,$pathsref) = @_;
11578: my (@cmd,$output);
11579: my $needsregexp;
11580: if ($file =~ /\.zip$/) {
11581: @cmd = (&decompression_utility('unzip'),"-l");
11582: $needsregexp = 1;
11583: } elsif (($file =~ m/\.tar\.gz$/) ||
11584: ($file =~ /\.tgz$/)) {
11585: @cmd = (&decompression_utility('tar'),"-ztf");
11586: } elsif ($file =~ /\.tar\.bz2$/) {
11587: @cmd = (&decompression_utility('tar'),"-jtf");
11588: } elsif ($file =~ m|\.tar$|) {
11589: @cmd = (&decompression_utility('tar'),"-tf");
11590: }
11591: if (@cmd) {
11592: undef($!);
11593: undef($@);
11594: if (open(my $fh,"-|", @cmd, $file)) {
11595: while (my $line = <$fh>) {
11596: $output .= $line;
11597: chomp($line);
11598: my $item;
11599: if ($needsregexp) {
11600: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11601: } else {
11602: $item = $line;
11603: }
11604: if ($item ne '') {
11605: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11606: push(@{$pathsref},$item);
11607: }
11608: }
11609: }
11610: close($fh);
11611: }
11612: }
11613: return $output;
11614: }
11615:
1.1053 raeburn 11616: sub decompress_uploaded_file {
11617: my ($file,$dir) = @_;
11618: &Apache::lonnet::appenv({'cgi.file' => $file});
11619: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11620: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11621: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11622: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11623: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11624: my $decompressed = $env{'cgi.decompressed'};
11625: &Apache::lonnet::delenv('cgi.file');
11626: &Apache::lonnet::delenv('cgi.dir');
11627: &Apache::lonnet::delenv('cgi.decompressed');
11628: return ($decompressed,$result);
11629: }
11630:
1.1055 raeburn 11631: sub process_decompression {
11632: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11633: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 11634: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 11635: $error = &mt('Filename not a supported archive file type.').
11636: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11637: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11638: } else {
11639: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11640: if ($docuhome eq 'no_host') {
11641: $error = &mt('Could not determine home server for course.');
11642: } else {
11643: my @ids=&Apache::lonnet::current_machine_ids();
11644: my $currdir = "$dir_root/$destination";
11645: if (grep(/^\Q$docuhome\E$/,@ids)) {
11646: $dir = &LONCAPA::propath($docudom,$docuname).
11647: "$dir_root/$destination";
11648: } else {
11649: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11650: "$dir_root/$docudom/$docuname/$destination";
11651: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11652: $error = &mt('Archive file not found.');
11653: }
11654: }
1.1065 raeburn 11655: my (@to_overwrite,@to_skip);
11656: if ($env{'form.archive_overwrite_total'} > 0) {
11657: my $total = $env{'form.archive_overwrite_total'};
11658: for (my $i=0; $i<$total; $i++) {
11659: if ($env{'form.archive_overwrite_'.$i} == 1) {
11660: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11661: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11662: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11663: }
11664: }
11665: }
11666: my $numskip = scalar(@to_skip);
11667: if (($numskip > 0) &&
11668: ($numskip == $env{'form.archive_itemcount'})) {
11669: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11670: } elsif ($dir eq '') {
1.1055 raeburn 11671: $error = &mt('Directory containing archive file unavailable.');
11672: } elsif (!$error) {
1.1065 raeburn 11673: my ($decompressed,$display);
11674: if ($numskip > 0) {
11675: my $tempdir = time.'_'.$$.int(rand(10000));
11676: mkdir("$dir/$tempdir",0755);
11677: system("mv $dir/$file $dir/$tempdir/$file");
11678: ($decompressed,$display) =
11679: &decompress_uploaded_file($file,"$dir/$tempdir");
11680: foreach my $item (@to_skip) {
11681: if (($item ne '') && ($item !~ /\.\./)) {
11682: if (-f "$dir/$tempdir/$item") {
11683: unlink("$dir/$tempdir/$item");
11684: } elsif (-d "$dir/$tempdir/$item") {
11685: system("rm -rf $dir/$tempdir/$item");
11686: }
11687: }
11688: }
11689: system("mv $dir/$tempdir/* $dir");
11690: rmdir("$dir/$tempdir");
11691: } else {
11692: ($decompressed,$display) =
11693: &decompress_uploaded_file($file,$dir);
11694: }
1.1055 raeburn 11695: if ($decompressed eq 'ok') {
1.1065 raeburn 11696: $output = '<p class="LC_info">'.
11697: &mt('Files extracted successfully from archive.').
11698: '</p>'."\n";
1.1055 raeburn 11699: my ($warning,$result,@contents);
11700: my ($newdirlistref,$newlisterror) =
11701: &Apache::lonnet::dirlist($currdir,$docudom,
11702: $docuname,1);
11703: my (%is_dir,%changes,@newitems);
11704: my $dirptr = 16384;
1.1065 raeburn 11705: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11706: foreach my $dir_line (@{$newdirlistref}) {
11707: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11708: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11709: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11710: push(@newitems,$item);
11711: if ($dirptr&$testdir) {
11712: $is_dir{$item} = 1;
11713: }
11714: $changes{$item} = 1;
11715: }
11716: }
11717: }
11718: if (keys(%changes) > 0) {
11719: foreach my $item (sort(@newitems)) {
11720: if ($changes{$item}) {
11721: push(@contents,$item);
11722: }
11723: }
11724: }
11725: if (@contents > 0) {
1.1067 raeburn 11726: my $wantform;
11727: unless ($env{'form.autoextract_camtasia'}) {
11728: $wantform = 1;
11729: }
1.1056 raeburn 11730: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11731: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11732: $currdir,\%is_dir,
11733: \%children,\%parent,
1.1056 raeburn 11734: \@contents,\%dirorder,
11735: \%titles,$wantform);
1.1055 raeburn 11736: if ($datatable ne '') {
11737: $output .= &archive_options_form('decompressed',$datatable,
11738: $count,$hiddenelem);
1.1065 raeburn 11739: my $startcount = 6;
1.1055 raeburn 11740: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11741: \%titles,\%children);
1.1055 raeburn 11742: }
1.1067 raeburn 11743: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 11744: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 11745: my %displayed;
11746: my $total = 1;
11747: $env{'form.archive_directory'} = [];
11748: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11749: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11750: $path =~ s{/$}{};
11751: my $item;
11752: if ($path ne '') {
11753: $item = "$path/$titles{$i}";
11754: } else {
11755: $item = $titles{$i};
11756: }
11757: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11758: if ($item eq $contents[0]) {
11759: push(@{$env{'form.archive_directory'}},$i);
11760: $env{'form.archive_'.$i} = 'display';
11761: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11762: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 11763: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
11764: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 11765: $env{'form.archive_'.$i} = 'display';
11766: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11767: $displayed{'web'} = $i;
11768: } else {
1.1075.2.59 raeburn 11769: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
11770: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
11771: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 11772: push(@{$env{'form.archive_directory'}},$i);
11773: }
11774: $env{'form.archive_'.$i} = 'dependency';
11775: }
11776: $total ++;
11777: }
11778: for (my $i=1; $i<$total; $i++) {
11779: next if ($i == $displayed{'web'});
11780: next if ($i == $displayed{'folder'});
11781: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11782: }
11783: $env{'form.phase'} = 'decompress_cleanup';
11784: $env{'form.archivedelete'} = 1;
11785: $env{'form.archive_count'} = $total-1;
11786: $output .=
11787: &process_extracted_files('coursedocs',$docudom,
11788: $docuname,$destination,
11789: $dir_root,$hiddenelem);
11790: }
1.1055 raeburn 11791: } else {
11792: $warning = &mt('No new items extracted from archive file.');
11793: }
11794: } else {
11795: $output = $display;
11796: $error = &mt('An error occurred during extraction from the archive file.');
11797: }
11798: }
11799: }
11800: }
11801: if ($error) {
11802: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11803: $error.'</p>'."\n";
11804: }
11805: if ($warning) {
11806: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11807: }
11808: return $output;
11809: }
11810:
11811: sub get_extracted {
1.1056 raeburn 11812: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11813: $titles,$wantform) = @_;
1.1055 raeburn 11814: my $count = 0;
11815: my $depth = 0;
11816: my $datatable;
1.1056 raeburn 11817: my @hierarchy;
1.1055 raeburn 11818: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11819: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11820: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11821: foreach my $item (@{$contents}) {
11822: $count ++;
1.1056 raeburn 11823: @{$dirorder->{$count}} = @hierarchy;
11824: $titles->{$count} = $item;
1.1055 raeburn 11825: &archive_hierarchy($depth,$count,$parent,$children);
11826: if ($wantform) {
11827: $datatable .= &archive_row($is_dir->{$item},$item,
11828: $currdir,$depth,$count);
11829: }
11830: if ($is_dir->{$item}) {
11831: $depth ++;
1.1056 raeburn 11832: push(@hierarchy,$count);
11833: $parent->{$depth} = $count;
1.1055 raeburn 11834: $datatable .=
11835: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11836: \$depth,\$count,\@hierarchy,$dirorder,
11837: $children,$parent,$titles,$wantform);
1.1055 raeburn 11838: $depth --;
1.1056 raeburn 11839: pop(@hierarchy);
1.1055 raeburn 11840: }
11841: }
11842: return ($count,$datatable);
11843: }
11844:
11845: sub recurse_extracted_archive {
1.1056 raeburn 11846: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11847: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11848: my $result='';
1.1056 raeburn 11849: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11850: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11851: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11852: return $result;
11853: }
11854: my $dirptr = 16384;
11855: my ($newdirlistref,$newlisterror) =
11856: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11857: if (ref($newdirlistref) eq 'ARRAY') {
11858: foreach my $dir_line (@{$newdirlistref}) {
11859: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11860: unless ($item =~ /^\.+$/) {
11861: $$count ++;
1.1056 raeburn 11862: @{$dirorder->{$$count}} = @{$hierarchy};
11863: $titles->{$$count} = $item;
1.1055 raeburn 11864: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11865:
1.1055 raeburn 11866: my $is_dir;
11867: if ($dirptr&$testdir) {
11868: $is_dir = 1;
11869: }
11870: if ($wantform) {
11871: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11872: }
11873: if ($is_dir) {
11874: $$depth ++;
1.1056 raeburn 11875: push(@{$hierarchy},$$count);
11876: $parent->{$$depth} = $$count;
1.1055 raeburn 11877: $result .=
11878: &recurse_extracted_archive("$currdir/$item",$docudom,
11879: $docuname,$depth,$count,
1.1056 raeburn 11880: $hierarchy,$dirorder,$children,
11881: $parent,$titles,$wantform);
1.1055 raeburn 11882: $$depth --;
1.1056 raeburn 11883: pop(@{$hierarchy});
1.1055 raeburn 11884: }
11885: }
11886: }
11887: }
11888: return $result;
11889: }
11890:
11891: sub archive_hierarchy {
11892: my ($depth,$count,$parent,$children) =@_;
11893: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11894: if (exists($parent->{$depth})) {
11895: $children->{$parent->{$depth}} .= $count.':';
11896: }
11897: }
11898: return;
11899: }
11900:
11901: sub archive_row {
11902: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11903: my ($name) = ($item =~ m{([^/]+)$});
11904: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11905: 'display' => 'Add as file',
1.1055 raeburn 11906: 'dependency' => 'Include as dependency',
11907: 'discard' => 'Discard',
11908: );
11909: if ($is_dir) {
1.1059 raeburn 11910: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11911: }
1.1056 raeburn 11912: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11913: my $offset = 0;
1.1055 raeburn 11914: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11915: $offset ++;
1.1065 raeburn 11916: if ($action ne 'display') {
11917: $offset ++;
11918: }
1.1055 raeburn 11919: $output .= '<td><span class="LC_nobreak">'.
11920: '<label><input type="radio" name="archive_'.$count.
11921: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11922: my $text = $choices{$action};
11923: if ($is_dir) {
11924: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11925: if ($action eq 'display') {
1.1059 raeburn 11926: $text = &mt('Add as folder');
1.1055 raeburn 11927: }
1.1056 raeburn 11928: } else {
11929: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11930:
11931: }
11932: $output .= ' /> '.$choices{$action}.'</label></span>';
11933: if ($action eq 'dependency') {
11934: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11935: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11936: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11937: '<option value=""></option>'."\n".
11938: '</select>'."\n".
11939: '</div>';
1.1059 raeburn 11940: } elsif ($action eq 'display') {
11941: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11942: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11943: '</div>';
1.1055 raeburn 11944: }
1.1056 raeburn 11945: $output .= '</td>';
1.1055 raeburn 11946: }
11947: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11948: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11949: for (my $i=0; $i<$depth; $i++) {
11950: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11951: }
11952: if ($is_dir) {
11953: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11954: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11955: } else {
11956: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11957: }
11958: $output .= ' '.$name.'</td>'."\n".
11959: &end_data_table_row();
11960: return $output;
11961: }
11962:
11963: sub archive_options_form {
1.1065 raeburn 11964: my ($form,$display,$count,$hiddenelem) = @_;
11965: my %lt = &Apache::lonlocal::texthash(
11966: perm => 'Permanently remove archive file?',
11967: hows => 'How should each extracted item be incorporated in the course?',
11968: cont => 'Content actions for all',
11969: addf => 'Add as folder/file',
11970: incd => 'Include as dependency for a displayed file',
11971: disc => 'Discard',
11972: no => 'No',
11973: yes => 'Yes',
11974: save => 'Save',
11975: );
11976: my $output = <<"END";
11977: <form name="$form" method="post" action="">
11978: <p><span class="LC_nobreak">$lt{'perm'}
11979: <label>
11980: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11981: </label>
11982:
11983: <label>
11984: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11985: </span>
11986: </p>
11987: <input type="hidden" name="phase" value="decompress_cleanup" />
11988: <br />$lt{'hows'}
11989: <div class="LC_columnSection">
11990: <fieldset>
11991: <legend>$lt{'cont'}</legend>
11992: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11993: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11994: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11995: </fieldset>
11996: </div>
11997: END
11998: return $output.
1.1055 raeburn 11999: &start_data_table()."\n".
1.1065 raeburn 12000: $display."\n".
1.1055 raeburn 12001: &end_data_table()."\n".
12002: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12003: $hiddenelem.
1.1065 raeburn 12004: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12005: '</form>';
12006: }
12007:
12008: sub archive_javascript {
1.1056 raeburn 12009: my ($startcount,$numitems,$titles,$children) = @_;
12010: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12011: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12012: my $scripttag = <<START;
12013: <script type="text/javascript">
12014: // <![CDATA[
12015:
12016: function checkAll(form,prefix) {
12017: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12018: for (var i=0; i < form.elements.length; i++) {
12019: var id = form.elements[i].id;
12020: if ((id != '') && (id != undefined)) {
12021: if (idstr.test(id)) {
12022: if (form.elements[i].type == 'radio') {
12023: form.elements[i].checked = true;
1.1056 raeburn 12024: var nostart = i-$startcount;
1.1059 raeburn 12025: var offset = nostart%7;
12026: var count = (nostart-offset)/7;
1.1056 raeburn 12027: dependencyCheck(form,count,offset);
1.1055 raeburn 12028: }
12029: }
12030: }
12031: }
12032: }
12033:
12034: function propagateCheck(form,count) {
12035: if (count > 0) {
1.1059 raeburn 12036: var startelement = $startcount + ((count-1) * 7);
12037: for (var j=1; j<6; j++) {
12038: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12039: var item = startelement + j;
12040: if (form.elements[item].type == 'radio') {
12041: if (form.elements[item].checked) {
12042: containerCheck(form,count,j);
12043: break;
12044: }
1.1055 raeburn 12045: }
12046: }
12047: }
12048: }
12049: }
12050:
12051: numitems = $numitems
1.1056 raeburn 12052: var titles = new Array(numitems);
12053: var parents = new Array(numitems);
1.1055 raeburn 12054: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12055: parents[i] = new Array;
1.1055 raeburn 12056: }
1.1059 raeburn 12057: var maintitle = '$maintitle';
1.1055 raeburn 12058:
12059: START
12060:
1.1056 raeburn 12061: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12062: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12063: for (my $i=0; $i<@contents; $i ++) {
12064: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12065: }
12066: }
12067:
1.1056 raeburn 12068: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12069: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12070: }
12071:
1.1055 raeburn 12072: $scripttag .= <<END;
12073:
12074: function containerCheck(form,count,offset) {
12075: if (count > 0) {
1.1056 raeburn 12076: dependencyCheck(form,count,offset);
1.1059 raeburn 12077: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12078: form.elements[item].checked = true;
12079: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12080: if (parents[count].length > 0) {
12081: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12082: containerCheck(form,parents[count][j],offset);
12083: }
12084: }
12085: }
12086: }
12087: }
12088:
12089: function dependencyCheck(form,count,offset) {
12090: if (count > 0) {
1.1059 raeburn 12091: var chosen = (offset+$startcount)+7*(count-1);
12092: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12093: var currtype = form.elements[depitem].type;
12094: if (form.elements[chosen].value == 'dependency') {
12095: document.getElementById('arc_depon_'+count).style.display='block';
12096: form.elements[depitem].options.length = 0;
12097: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12098: for (var i=1; i<=numitems; i++) {
12099: if (i == count) {
12100: continue;
12101: }
1.1059 raeburn 12102: var startelement = $startcount + (i-1) * 7;
12103: for (var j=1; j<6; j++) {
12104: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12105: var item = startelement + j;
12106: if (form.elements[item].type == 'radio') {
12107: if (form.elements[item].checked) {
12108: if (form.elements[item].value == 'display') {
12109: var n = form.elements[depitem].options.length;
12110: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12111: }
12112: }
12113: }
12114: }
12115: }
12116: }
12117: } else {
12118: document.getElementById('arc_depon_'+count).style.display='none';
12119: form.elements[depitem].options.length = 0;
12120: form.elements[depitem].options[0] = new Option('Select','',true,true);
12121: }
1.1059 raeburn 12122: titleCheck(form,count,offset);
1.1056 raeburn 12123: }
12124: }
12125:
12126: function propagateSelect(form,count,offset) {
12127: if (count > 0) {
1.1065 raeburn 12128: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12129: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12130: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12131: if (parents[count].length > 0) {
12132: for (var j=0; j<parents[count].length; j++) {
12133: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12134: }
12135: }
12136: }
12137: }
12138: }
1.1056 raeburn 12139:
12140: function containerSelect(form,count,offset,picked) {
12141: if (count > 0) {
1.1065 raeburn 12142: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12143: if (form.elements[item].type == 'radio') {
12144: if (form.elements[item].value == 'dependency') {
12145: if (form.elements[item+1].type == 'select-one') {
12146: for (var i=0; i<form.elements[item+1].options.length; i++) {
12147: if (form.elements[item+1].options[i].value == picked) {
12148: form.elements[item+1].selectedIndex = i;
12149: break;
12150: }
12151: }
12152: }
12153: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12154: if (parents[count].length > 0) {
12155: for (var j=0; j<parents[count].length; j++) {
12156: containerSelect(form,parents[count][j],offset,picked);
12157: }
12158: }
12159: }
12160: }
12161: }
12162: }
12163: }
12164:
1.1059 raeburn 12165: function titleCheck(form,count,offset) {
12166: if (count > 0) {
12167: var chosen = (offset+$startcount)+7*(count-1);
12168: var depitem = $startcount + ((count-1) * 7) + 2;
12169: var currtype = form.elements[depitem].type;
12170: if (form.elements[chosen].value == 'display') {
12171: document.getElementById('arc_title_'+count).style.display='block';
12172: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12173: document.getElementById('archive_title_'+count).value=maintitle;
12174: }
12175: } else {
12176: document.getElementById('arc_title_'+count).style.display='none';
12177: if (currtype == 'text') {
12178: document.getElementById('archive_title_'+count).value='';
12179: }
12180: }
12181: }
12182: return;
12183: }
12184:
1.1055 raeburn 12185: // ]]>
12186: </script>
12187: END
12188: return $scripttag;
12189: }
12190:
12191: sub process_extracted_files {
1.1067 raeburn 12192: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12193: my $numitems = $env{'form.archive_count'};
12194: return unless ($numitems);
12195: my @ids=&Apache::lonnet::current_machine_ids();
12196: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12197: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12198: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12199: if (grep(/^\Q$docuhome\E$/,@ids)) {
12200: $prefix = &LONCAPA::propath($docudom,$docuname);
12201: $pathtocheck = "$dir_root/$destination";
12202: $dir = $dir_root;
12203: $ishome = 1;
12204: } else {
12205: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12206: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
12207: $dir = "$dir_root/$docudom/$docuname";
12208: }
12209: my $currdir = "$dir_root/$destination";
12210: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12211: if ($env{'form.folderpath'}) {
12212: my @items = split('&',$env{'form.folderpath'});
12213: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 12214: if ($env{'form.folderpath'} =~ /\:1$/) {
12215: $containers{'0'}='page';
12216: } else {
12217: $containers{'0'}='sequence';
12218: }
1.1055 raeburn 12219: }
12220: my @archdirs = &get_env_multiple('form.archive_directory');
12221: if ($numitems) {
12222: for (my $i=1; $i<=$numitems; $i++) {
12223: my $path = $env{'form.archive_content_'.$i};
12224: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12225: my $item = $1;
12226: $toplevelitems{$item} = $i;
12227: if (grep(/^\Q$i\E$/,@archdirs)) {
12228: $is_dir{$item} = 1;
12229: }
12230: }
12231: }
12232: }
1.1067 raeburn 12233: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12234: if (keys(%toplevelitems) > 0) {
12235: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12236: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12237: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12238: }
1.1066 raeburn 12239: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12240: if ($numitems) {
12241: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 12242: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12243: my $path = $env{'form.archive_content_'.$i};
12244: if ($path =~ /^\Q$pathtocheck\E/) {
12245: if ($env{'form.archive_'.$i} eq 'discard') {
12246: if ($prefix ne '' && $path ne '') {
12247: if (-e $prefix.$path) {
1.1066 raeburn 12248: if ((@archdirs > 0) &&
12249: (grep(/^\Q$i\E$/,@archdirs))) {
12250: $todeletedir{$prefix.$path} = 1;
12251: } else {
12252: $todelete{$prefix.$path} = 1;
12253: }
1.1055 raeburn 12254: }
12255: }
12256: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12257: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12258: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12259: $docstitle = $env{'form.archive_title_'.$i};
12260: if ($docstitle eq '') {
12261: $docstitle = $title;
12262: }
1.1055 raeburn 12263: $outer = 0;
1.1056 raeburn 12264: if (ref($dirorder{$i}) eq 'ARRAY') {
12265: if (@{$dirorder{$i}} > 0) {
12266: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12267: if ($env{'form.archive_'.$item} eq 'display') {
12268: $outer = $item;
12269: last;
12270: }
12271: }
12272: }
12273: }
12274: my ($errtext,$fatal) =
12275: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12276: '/'.$folders{$outer}.'.'.
12277: $containers{$outer});
12278: next if ($fatal);
12279: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12280: if ($context eq 'coursedocs') {
1.1056 raeburn 12281: $mapinner{$i} = time;
1.1055 raeburn 12282: $folders{$i} = 'default_'.$mapinner{$i};
12283: $containers{$i} = 'sequence';
12284: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12285: $folders{$i}.'.'.$containers{$i};
12286: my $newidx = &LONCAPA::map::getresidx();
12287: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12288: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12289: push(@LONCAPA::map::order,$newidx);
12290: my ($outtext,$errtext) =
12291: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12292: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12293: '.'.$containers{$outer},1,1);
1.1056 raeburn 12294: $newseqid{$i} = $newidx;
1.1067 raeburn 12295: unless ($errtext) {
12296: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
12297: }
1.1055 raeburn 12298: }
12299: } else {
12300: if ($context eq 'coursedocs') {
12301: my $newidx=&LONCAPA::map::getresidx();
12302: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12303: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12304: $title;
12305: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12306: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
12307: }
12308: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12309: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12310: }
12311: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12312: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 12313: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 12314: unless ($ishome) {
12315: my $fetch = "$newdest{$i}/$title";
12316: $fetch =~ s/^\Q$prefix$dir\E//;
12317: $prompttofetch{$fetch} = 1;
12318: }
1.1055 raeburn 12319: }
12320: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12321: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12322: push(@LONCAPA::map::order, $newidx);
12323: my ($outtext,$errtext)=
12324: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12325: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12326: '.'.$containers{$outer},1,1);
1.1067 raeburn 12327: unless ($errtext) {
12328: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
12329: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
12330: }
12331: }
1.1055 raeburn 12332: }
12333: }
1.1075.2.11 raeburn 12334: }
12335: } else {
12336: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12337: }
12338: }
12339: for (my $i=1; $i<=$numitems; $i++) {
12340: next unless ($env{'form.archive_'.$i} eq 'dependency');
12341: my $path = $env{'form.archive_content_'.$i};
12342: if ($path =~ /^\Q$pathtocheck\E/) {
12343: my ($title) = ($path =~ m{/([^/]+)$});
12344: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12345: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12346: if (ref($dirorder{$i}) eq 'ARRAY') {
12347: my ($itemidx,$fullpath,$relpath);
12348: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12349: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12350: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 12351: if ($dirorder{$i}->[$j] eq $container) {
12352: $itemidx = $j;
1.1056 raeburn 12353: }
12354: }
1.1075.2.11 raeburn 12355: }
12356: if ($itemidx eq '') {
12357: $itemidx = 0;
12358: }
12359: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12360: if ($mapinner{$referrer{$i}}) {
12361: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12362: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12363: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12364: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12365: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12366: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12367: if (!-e $fullpath) {
12368: mkdir($fullpath,0755);
1.1056 raeburn 12369: }
12370: }
1.1075.2.11 raeburn 12371: } else {
12372: last;
1.1056 raeburn 12373: }
1.1075.2.11 raeburn 12374: }
12375: }
12376: } elsif ($newdest{$referrer{$i}}) {
12377: $fullpath = $newdest{$referrer{$i}};
12378: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12379: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12380: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12381: last;
12382: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12383: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12384: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12385: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12386: if (!-e $fullpath) {
12387: mkdir($fullpath,0755);
1.1056 raeburn 12388: }
12389: }
1.1075.2.11 raeburn 12390: } else {
12391: last;
1.1056 raeburn 12392: }
1.1075.2.11 raeburn 12393: }
12394: }
12395: if ($fullpath ne '') {
12396: if (-e "$prefix$path") {
12397: system("mv $prefix$path $fullpath/$title");
12398: }
12399: if (-e "$fullpath/$title") {
12400: my $showpath;
12401: if ($relpath ne '') {
12402: $showpath = "$relpath/$title";
12403: } else {
12404: $showpath = "/$title";
1.1056 raeburn 12405: }
1.1075.2.11 raeburn 12406: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12407: }
12408: unless ($ishome) {
12409: my $fetch = "$fullpath/$title";
12410: $fetch =~ s/^\Q$prefix$dir\E//;
12411: $prompttofetch{$fetch} = 1;
1.1055 raeburn 12412: }
12413: }
12414: }
1.1075.2.11 raeburn 12415: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12416: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12417: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12418: }
12419: } else {
1.1075.2.11 raeburn 12420: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055 raeburn 12421: }
12422: }
12423: if (keys(%todelete)) {
12424: foreach my $key (keys(%todelete)) {
12425: unlink($key);
1.1066 raeburn 12426: }
12427: }
12428: if (keys(%todeletedir)) {
12429: foreach my $key (keys(%todeletedir)) {
12430: rmdir($key);
12431: }
12432: }
12433: foreach my $dir (sort(keys(%is_dir))) {
12434: if (($pathtocheck ne '') && ($dir ne '')) {
12435: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12436: }
12437: }
1.1067 raeburn 12438: if ($result ne '') {
12439: $output .= '<ul>'."\n".
12440: $result."\n".
12441: '</ul>';
12442: }
12443: unless ($ishome) {
12444: my $replicationfail;
12445: foreach my $item (keys(%prompttofetch)) {
12446: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12447: unless ($fetchresult eq 'ok') {
12448: $replicationfail .= '<li>'.$item.'</li>'."\n";
12449: }
12450: }
12451: if ($replicationfail) {
12452: $output .= '<p class="LC_error">'.
12453: &mt('Course home server failed to retrieve:').'<ul>'.
12454: $replicationfail.
12455: '</ul></p>';
12456: }
12457: }
1.1055 raeburn 12458: } else {
12459: $warning = &mt('No items found in archive.');
12460: }
12461: if ($error) {
12462: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12463: $error.'</p>'."\n";
12464: }
12465: if ($warning) {
12466: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12467: }
12468: return $output;
12469: }
12470:
1.1066 raeburn 12471: sub cleanup_empty_dirs {
12472: my ($path) = @_;
12473: if (($path ne '') && (-d $path)) {
12474: if (opendir(my $dirh,$path)) {
12475: my @dircontents = grep(!/^\./,readdir($dirh));
12476: my $numitems = 0;
12477: foreach my $item (@dircontents) {
12478: if (-d "$path/$item") {
1.1075.2.28 raeburn 12479: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12480: if (-e "$path/$item") {
12481: $numitems ++;
12482: }
12483: } else {
12484: $numitems ++;
12485: }
12486: }
12487: if ($numitems == 0) {
12488: rmdir($path);
12489: }
12490: closedir($dirh);
12491: }
12492: }
12493: return;
12494: }
12495:
1.41 ng 12496: =pod
1.45 matthew 12497:
1.1075.2.56 raeburn 12498: =item * &get_folder_hierarchy()
1.1068 raeburn 12499:
12500: Provides hierarchy of names of folders/sub-folders containing the current
12501: item,
12502:
12503: Inputs: 3
12504: - $navmap - navmaps object
12505:
12506: - $map - url for map (either the trigger itself, or map containing
12507: the resource, which is the trigger).
12508:
12509: - $showitem - 1 => show title for map itself; 0 => do not show.
12510:
12511: Outputs: 1 @pathitems - array of folder/subfolder names.
12512:
12513: =cut
12514:
12515: sub get_folder_hierarchy {
12516: my ($navmap,$map,$showitem) = @_;
12517: my @pathitems;
12518: if (ref($navmap)) {
12519: my $mapres = $navmap->getResourceByUrl($map);
12520: if (ref($mapres)) {
12521: my $pcslist = $mapres->map_hierarchy();
12522: if ($pcslist ne '') {
12523: my @pcs = split(/,/,$pcslist);
12524: foreach my $pc (@pcs) {
12525: if ($pc == 1) {
1.1075.2.38 raeburn 12526: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12527: } else {
12528: my $res = $navmap->getByMapPc($pc);
12529: if (ref($res)) {
12530: my $title = $res->compTitle();
12531: $title =~ s/\W+/_/g;
12532: if ($title ne '') {
12533: push(@pathitems,$title);
12534: }
12535: }
12536: }
12537: }
12538: }
1.1071 raeburn 12539: if ($showitem) {
12540: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 12541: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12542: } else {
12543: my $maptitle = $mapres->compTitle();
12544: $maptitle =~ s/\W+/_/g;
12545: if ($maptitle ne '') {
12546: push(@pathitems,$maptitle);
12547: }
1.1068 raeburn 12548: }
12549: }
12550: }
12551: }
12552: return @pathitems;
12553: }
12554:
12555: =pod
12556:
1.1015 raeburn 12557: =item * &get_turnedin_filepath()
12558:
12559: Determines path in a user's portfolio file for storage of files uploaded
12560: to a specific essayresponse or dropbox item.
12561:
12562: Inputs: 3 required + 1 optional.
12563: $symb is symb for resource, $uname and $udom are for current user (required).
12564: $caller is optional (can be "submission", if routine is called when storing
12565: an upoaded file when "Submit Answer" button was pressed).
12566:
12567: Returns array containing $path and $multiresp.
12568: $path is path in portfolio. $multiresp is 1 if this resource contains more
12569: than one file upload item. Callers of routine should append partid as a
12570: subdirectory to $path in cases where $multiresp is 1.
12571:
12572: Called by: homework/essayresponse.pm and homework/structuretags.pm
12573:
12574: =cut
12575:
12576: sub get_turnedin_filepath {
12577: my ($symb,$uname,$udom,$caller) = @_;
12578: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12579: my $turnindir;
12580: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12581: $turnindir = $userhash{'turnindir'};
12582: my ($path,$multiresp);
12583: if ($turnindir eq '') {
12584: if ($caller eq 'submission') {
12585: $turnindir = &mt('turned in');
12586: $turnindir =~ s/\W+/_/g;
12587: my %newhash = (
12588: 'turnindir' => $turnindir,
12589: );
12590: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12591: }
12592: }
12593: if ($turnindir ne '') {
12594: $path = '/'.$turnindir.'/';
12595: my ($multipart,$turnin,@pathitems);
12596: my $navmap = Apache::lonnavmaps::navmap->new();
12597: if (defined($navmap)) {
12598: my $mapres = $navmap->getResourceByUrl($map);
12599: if (ref($mapres)) {
12600: my $pcslist = $mapres->map_hierarchy();
12601: if ($pcslist ne '') {
12602: foreach my $pc (split(/,/,$pcslist)) {
12603: my $res = $navmap->getByMapPc($pc);
12604: if (ref($res)) {
12605: my $title = $res->compTitle();
12606: $title =~ s/\W+/_/g;
12607: if ($title ne '') {
1.1075.2.48 raeburn 12608: if (($pc > 1) && (length($title) > 12)) {
12609: $title = substr($title,0,12);
12610: }
1.1015 raeburn 12611: push(@pathitems,$title);
12612: }
12613: }
12614: }
12615: }
12616: my $maptitle = $mapres->compTitle();
12617: $maptitle =~ s/\W+/_/g;
12618: if ($maptitle ne '') {
1.1075.2.48 raeburn 12619: if (length($maptitle) > 12) {
12620: $maptitle = substr($maptitle,0,12);
12621: }
1.1015 raeburn 12622: push(@pathitems,$maptitle);
12623: }
12624: unless ($env{'request.state'} eq 'construct') {
12625: my $res = $navmap->getBySymb($symb);
12626: if (ref($res)) {
12627: my $partlist = $res->parts();
12628: my $totaluploads = 0;
12629: if (ref($partlist) eq 'ARRAY') {
12630: foreach my $part (@{$partlist}) {
12631: my @types = $res->responseType($part);
12632: my @ids = $res->responseIds($part);
12633: for (my $i=0; $i < scalar(@ids); $i++) {
12634: if ($types[$i] eq 'essay') {
12635: my $partid = $part.'_'.$ids[$i];
12636: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12637: $totaluploads ++;
12638: }
12639: }
12640: }
12641: }
12642: if ($totaluploads > 1) {
12643: $multiresp = 1;
12644: }
12645: }
12646: }
12647: }
12648: } else {
12649: return;
12650: }
12651: } else {
12652: return;
12653: }
12654: my $restitle=&Apache::lonnet::gettitle($symb);
12655: $restitle =~ s/\W+/_/g;
12656: if ($restitle eq '') {
12657: $restitle = ($resurl =~ m{/[^/]+$});
12658: if ($restitle eq '') {
12659: $restitle = time;
12660: }
12661: }
1.1075.2.48 raeburn 12662: if (length($restitle) > 12) {
12663: $restitle = substr($restitle,0,12);
12664: }
1.1015 raeburn 12665: push(@pathitems,$restitle);
12666: $path .= join('/',@pathitems);
12667: }
12668: return ($path,$multiresp);
12669: }
12670:
12671: =pod
12672:
1.464 albertel 12673: =back
1.41 ng 12674:
1.112 bowersj2 12675: =head1 CSV Upload/Handling functions
1.38 albertel 12676:
1.41 ng 12677: =over 4
12678:
1.648 raeburn 12679: =item * &upfile_store($r)
1.41 ng 12680:
12681: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12682: needs $env{'form.upfile'}
1.41 ng 12683: returns $datatoken to be put into hidden field
12684:
12685: =cut
1.31 albertel 12686:
12687: sub upfile_store {
12688: my $r=shift;
1.258 albertel 12689: $env{'form.upfile'}=~s/\r/\n/gs;
12690: $env{'form.upfile'}=~s/\f/\n/gs;
12691: $env{'form.upfile'}=~s/\n+/\n/gs;
12692: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12693:
1.258 albertel 12694: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12695: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12696: {
1.158 raeburn 12697: my $datafile = $r->dir_config('lonDaemons').
12698: '/tmp/'.$datatoken.'.tmp';
12699: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12700: print $fh $env{'form.upfile'};
1.158 raeburn 12701: close($fh);
12702: }
1.31 albertel 12703: }
12704: return $datatoken;
12705: }
12706:
1.56 matthew 12707: =pod
12708:
1.648 raeburn 12709: =item * &load_tmp_file($r)
1.41 ng 12710:
12711: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12712: needs $env{'form.datatoken'},
12713: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12714:
12715: =cut
1.31 albertel 12716:
12717: sub load_tmp_file {
12718: my $r=shift;
12719: my @studentdata=();
12720: {
1.158 raeburn 12721: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12722: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12723: if ( open(my $fh,"<$studentfile") ) {
12724: @studentdata=<$fh>;
12725: close($fh);
12726: }
1.31 albertel 12727: }
1.258 albertel 12728: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12729: }
12730:
1.56 matthew 12731: =pod
12732:
1.648 raeburn 12733: =item * &upfile_record_sep()
1.41 ng 12734:
12735: Separate uploaded file into records
12736: returns array of records,
1.258 albertel 12737: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12738:
12739: =cut
1.31 albertel 12740:
12741: sub upfile_record_sep {
1.258 albertel 12742: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12743: } else {
1.248 albertel 12744: my @records;
1.258 albertel 12745: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12746: if ($line=~/^\s*$/) { next; }
12747: push(@records,$line);
12748: }
12749: return @records;
1.31 albertel 12750: }
12751: }
12752:
1.56 matthew 12753: =pod
12754:
1.648 raeburn 12755: =item * &record_sep($record)
1.41 ng 12756:
1.258 albertel 12757: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12758:
12759: =cut
12760:
1.263 www 12761: sub takeleft {
12762: my $index=shift;
12763: return substr('0000'.$index,-4,4);
12764: }
12765:
1.31 albertel 12766: sub record_sep {
12767: my $record=shift;
12768: my %components=();
1.258 albertel 12769: if ($env{'form.upfiletype'} eq 'xml') {
12770: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12771: my $i=0;
1.356 albertel 12772: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12773: $field=~s/^(\"|\')//;
12774: $field=~s/(\"|\')$//;
1.263 www 12775: $components{&takeleft($i)}=$field;
1.31 albertel 12776: $i++;
12777: }
1.258 albertel 12778: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12779: my $i=0;
1.356 albertel 12780: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12781: $field=~s/^(\"|\')//;
12782: $field=~s/(\"|\')$//;
1.263 www 12783: $components{&takeleft($i)}=$field;
1.31 albertel 12784: $i++;
12785: }
12786: } else {
1.561 www 12787: my $separator=',';
1.480 banghart 12788: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12789: $separator=';';
1.480 banghart 12790: }
1.31 albertel 12791: my $i=0;
1.561 www 12792: # the character we are looking for to indicate the end of a quote or a record
12793: my $looking_for=$separator;
12794: # do not add the characters to the fields
12795: my $ignore=0;
12796: # we just encountered a separator (or the beginning of the record)
12797: my $just_found_separator=1;
12798: # store the field we are working on here
12799: my $field='';
12800: # work our way through all characters in record
12801: foreach my $character ($record=~/(.)/g) {
12802: if ($character eq $looking_for) {
12803: if ($character ne $separator) {
12804: # Found the end of a quote, again looking for separator
12805: $looking_for=$separator;
12806: $ignore=1;
12807: } else {
12808: # Found a separator, store away what we got
12809: $components{&takeleft($i)}=$field;
12810: $i++;
12811: $just_found_separator=1;
12812: $ignore=0;
12813: $field='';
12814: }
12815: next;
12816: }
12817: # single or double quotation marks after a separator indicate beginning of a quote
12818: # we are now looking for the end of the quote and need to ignore separators
12819: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12820: $looking_for=$character;
12821: next;
12822: }
12823: # ignore would be true after we reached the end of a quote
12824: if ($ignore) { next; }
12825: if (($just_found_separator) && ($character=~/\s/)) { next; }
12826: $field.=$character;
12827: $just_found_separator=0;
1.31 albertel 12828: }
1.561 www 12829: # catch the very last entry, since we never encountered the separator
12830: $components{&takeleft($i)}=$field;
1.31 albertel 12831: }
12832: return %components;
12833: }
12834:
1.144 matthew 12835: ######################################################
12836: ######################################################
12837:
1.56 matthew 12838: =pod
12839:
1.648 raeburn 12840: =item * &upfile_select_html()
1.41 ng 12841:
1.144 matthew 12842: Return HTML code to select a file from the users machine and specify
12843: the file type.
1.41 ng 12844:
12845: =cut
12846:
1.144 matthew 12847: ######################################################
12848: ######################################################
1.31 albertel 12849: sub upfile_select_html {
1.144 matthew 12850: my %Types = (
12851: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12852: semisv => &mt('Semicolon separated values'),
1.144 matthew 12853: space => &mt('Space separated'),
12854: tab => &mt('Tabulator separated'),
12855: # xml => &mt('HTML/XML'),
12856: );
12857: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12858: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12859: foreach my $type (sort(keys(%Types))) {
12860: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12861: }
12862: $Str .= "</select>\n";
12863: return $Str;
1.31 albertel 12864: }
12865:
1.301 albertel 12866: sub get_samples {
12867: my ($records,$toget) = @_;
12868: my @samples=({});
12869: my $got=0;
12870: foreach my $rec (@$records) {
12871: my %temp = &record_sep($rec);
12872: if (! grep(/\S/, values(%temp))) { next; }
12873: if (%temp) {
12874: $samples[$got]=\%temp;
12875: $got++;
12876: if ($got == $toget) { last; }
12877: }
12878: }
12879: return \@samples;
12880: }
12881:
1.144 matthew 12882: ######################################################
12883: ######################################################
12884:
1.56 matthew 12885: =pod
12886:
1.648 raeburn 12887: =item * &csv_print_samples($r,$records)
1.41 ng 12888:
12889: Prints a table of sample values from each column uploaded $r is an
12890: Apache Request ref, $records is an arrayref from
12891: &Apache::loncommon::upfile_record_sep
12892:
12893: =cut
12894:
1.144 matthew 12895: ######################################################
12896: ######################################################
1.31 albertel 12897: sub csv_print_samples {
12898: my ($r,$records) = @_;
1.662 bisitz 12899: my $samples = &get_samples($records,5);
1.301 albertel 12900:
1.594 raeburn 12901: $r->print(&mt('Samples').'<br />'.&start_data_table().
12902: &start_data_table_header_row());
1.356 albertel 12903: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12904: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12905: $r->print(&end_data_table_header_row());
1.301 albertel 12906: foreach my $hash (@$samples) {
1.594 raeburn 12907: $r->print(&start_data_table_row());
1.356 albertel 12908: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12909: $r->print('<td>');
1.356 albertel 12910: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12911: $r->print('</td>');
12912: }
1.594 raeburn 12913: $r->print(&end_data_table_row());
1.31 albertel 12914: }
1.594 raeburn 12915: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12916: }
12917:
1.144 matthew 12918: ######################################################
12919: ######################################################
12920:
1.56 matthew 12921: =pod
12922:
1.648 raeburn 12923: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12924:
12925: Prints a table to create associations between values and table columns.
1.144 matthew 12926:
1.41 ng 12927: $r is an Apache Request ref,
12928: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12929: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12930:
12931: =cut
12932:
1.144 matthew 12933: ######################################################
12934: ######################################################
1.31 albertel 12935: sub csv_print_select_table {
12936: my ($r,$records,$d) = @_;
1.301 albertel 12937: my $i=0;
12938: my $samples = &get_samples($records,1);
1.144 matthew 12939: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12940: &start_data_table().&start_data_table_header_row().
1.144 matthew 12941: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12942: '<th>'.&mt('Column').'</th>'.
12943: &end_data_table_header_row()."\n");
1.356 albertel 12944: foreach my $array_ref (@$d) {
12945: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12946: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12947:
1.875 bisitz 12948: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12949: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12950: $r->print('<option value="none"></option>');
1.356 albertel 12951: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12952: $r->print('<option value="'.$sample.'"'.
12953: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12954: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12955: }
1.594 raeburn 12956: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12957: $i++;
12958: }
1.594 raeburn 12959: $r->print(&end_data_table());
1.31 albertel 12960: $i--;
12961: return $i;
12962: }
1.56 matthew 12963:
1.144 matthew 12964: ######################################################
12965: ######################################################
12966:
1.56 matthew 12967: =pod
1.31 albertel 12968:
1.648 raeburn 12969: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12970:
12971: Prints a table of sample values from the upload and can make associate samples to internal names.
12972:
12973: $r is an Apache Request ref,
12974: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12975: $d is an array of 2 element arrays (internal name, displayed name)
12976:
12977: =cut
12978:
1.144 matthew 12979: ######################################################
12980: ######################################################
1.31 albertel 12981: sub csv_samples_select_table {
12982: my ($r,$records,$d) = @_;
12983: my $i=0;
1.144 matthew 12984: #
1.662 bisitz 12985: my $max_samples = 5;
12986: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12987: $r->print(&start_data_table().
12988: &start_data_table_header_row().'<th>'.
12989: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12990: &end_data_table_header_row());
1.301 albertel 12991:
12992: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12993: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12994: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12995: foreach my $option (@$d) {
12996: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12997: $r->print('<option value="'.$value.'"'.
1.253 albertel 12998: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12999: $display.'</option>');
1.31 albertel 13000: }
13001: $r->print('</select></td><td>');
1.662 bisitz 13002: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13003: if (defined($samples->[$line]{$key})) {
13004: $r->print($samples->[$line]{$key}."<br />\n");
13005: }
13006: }
1.594 raeburn 13007: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13008: $i++;
13009: }
1.594 raeburn 13010: $r->print(&end_data_table());
1.31 albertel 13011: $i--;
13012: return($i);
1.115 matthew 13013: }
13014:
1.144 matthew 13015: ######################################################
13016: ######################################################
13017:
1.115 matthew 13018: =pod
13019:
1.648 raeburn 13020: =item * &clean_excel_name($name)
1.115 matthew 13021:
13022: Returns a replacement for $name which does not contain any illegal characters.
13023:
13024: =cut
13025:
1.144 matthew 13026: ######################################################
13027: ######################################################
1.115 matthew 13028: sub clean_excel_name {
13029: my ($name) = @_;
13030: $name =~ s/[:\*\?\/\\]//g;
13031: if (length($name) > 31) {
13032: $name = substr($name,0,31);
13033: }
13034: return $name;
1.25 albertel 13035: }
1.84 albertel 13036:
1.85 albertel 13037: =pod
13038:
1.648 raeburn 13039: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13040:
13041: Returns either 1 or undef
13042:
13043: 1 if the part is to be hidden, undef if it is to be shown
13044:
13045: Arguments are:
13046:
13047: $id the id of the part to be checked
13048: $symb, optional the symb of the resource to check
13049: $udom, optional the domain of the user to check for
13050: $uname, optional the username of the user to check for
13051:
13052: =cut
1.84 albertel 13053:
13054: sub check_if_partid_hidden {
13055: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13056: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13057: $symb,$udom,$uname);
1.141 albertel 13058: my $truth=1;
13059: #if the string starts with !, then the list is the list to show not hide
13060: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13061: my @hiddenlist=split(/,/,$hiddenparts);
13062: foreach my $checkid (@hiddenlist) {
1.141 albertel 13063: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13064: }
1.141 albertel 13065: return !$truth;
1.84 albertel 13066: }
1.127 matthew 13067:
1.138 matthew 13068:
13069: ############################################################
13070: ############################################################
13071:
13072: =pod
13073:
1.157 matthew 13074: =back
13075:
1.138 matthew 13076: =head1 cgi-bin script and graphing routines
13077:
1.157 matthew 13078: =over 4
13079:
1.648 raeburn 13080: =item * &get_cgi_id()
1.138 matthew 13081:
13082: Inputs: none
13083:
13084: Returns an id which can be used to pass environment variables
13085: to various cgi-bin scripts. These environment variables will
13086: be removed from the users environment after a given time by
13087: the routine &Apache::lonnet::transfer_profile_to_env.
13088:
13089: =cut
13090:
13091: ############################################################
13092: ############################################################
1.152 albertel 13093: my $uniq=0;
1.136 matthew 13094: sub get_cgi_id {
1.154 albertel 13095: $uniq=($uniq+1)%100000;
1.280 albertel 13096: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13097: }
13098:
1.127 matthew 13099: ############################################################
13100: ############################################################
13101:
13102: =pod
13103:
1.648 raeburn 13104: =item * &DrawBarGraph()
1.127 matthew 13105:
1.138 matthew 13106: Facilitates the plotting of data in a (stacked) bar graph.
13107: Puts plot definition data into the users environment in order for
13108: graph.png to plot it. Returns an <img> tag for the plot.
13109: The bars on the plot are labeled '1','2',...,'n'.
13110:
13111: Inputs:
13112:
13113: =over 4
13114:
13115: =item $Title: string, the title of the plot
13116:
13117: =item $xlabel: string, text describing the X-axis of the plot
13118:
13119: =item $ylabel: string, text describing the Y-axis of the plot
13120:
13121: =item $Max: scalar, the maximum Y value to use in the plot
13122: If $Max is < any data point, the graph will not be rendered.
13123:
1.140 matthew 13124: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13125: they are plotted. If undefined, default values will be used.
13126:
1.178 matthew 13127: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13128:
1.138 matthew 13129: =item @Values: An array of array references. Each array reference holds data
13130: to be plotted in a stacked bar chart.
13131:
1.239 matthew 13132: =item If the final element of @Values is a hash reference the key/value
13133: pairs will be added to the graph definition.
13134:
1.138 matthew 13135: =back
13136:
13137: Returns:
13138:
13139: An <img> tag which references graph.png and the appropriate identifying
13140: information for the plot.
13141:
1.127 matthew 13142: =cut
13143:
13144: ############################################################
13145: ############################################################
1.134 matthew 13146: sub DrawBarGraph {
1.178 matthew 13147: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13148: #
13149: if (! defined($colors)) {
13150: $colors = ['#33ff00',
13151: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13152: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13153: ];
13154: }
1.228 matthew 13155: my $extra_settings = {};
13156: if (ref($Values[-1]) eq 'HASH') {
13157: $extra_settings = pop(@Values);
13158: }
1.127 matthew 13159: #
1.136 matthew 13160: my $identifier = &get_cgi_id();
13161: my $id = 'cgi.'.$identifier;
1.129 matthew 13162: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13163: return '';
13164: }
1.225 matthew 13165: #
13166: my @Labels;
13167: if (defined($labels)) {
13168: @Labels = @$labels;
13169: } else {
13170: for (my $i=0;$i<@{$Values[0]};$i++) {
13171: push (@Labels,$i+1);
13172: }
13173: }
13174: #
1.129 matthew 13175: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13176: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13177: my %ValuesHash;
13178: my $NumSets=1;
13179: foreach my $array (@Values) {
13180: next if (! ref($array));
1.136 matthew 13181: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13182: join(',',@$array);
1.129 matthew 13183: }
1.127 matthew 13184: #
1.136 matthew 13185: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13186: if ($NumBars < 3) {
13187: $width = 120+$NumBars*32;
1.220 matthew 13188: $xskip = 1;
1.225 matthew 13189: $bar_width = 30;
13190: } elsif ($NumBars < 5) {
13191: $width = 120+$NumBars*20;
13192: $xskip = 1;
13193: $bar_width = 20;
1.220 matthew 13194: } elsif ($NumBars < 10) {
1.136 matthew 13195: $width = 120+$NumBars*15;
13196: $xskip = 1;
13197: $bar_width = 15;
13198: } elsif ($NumBars <= 25) {
13199: $width = 120+$NumBars*11;
13200: $xskip = 5;
13201: $bar_width = 8;
13202: } elsif ($NumBars <= 50) {
13203: $width = 120+$NumBars*8;
13204: $xskip = 5;
13205: $bar_width = 4;
13206: } else {
13207: $width = 120+$NumBars*8;
13208: $xskip = 5;
13209: $bar_width = 4;
13210: }
13211: #
1.137 matthew 13212: $Max = 1 if ($Max < 1);
13213: if ( int($Max) < $Max ) {
13214: $Max++;
13215: $Max = int($Max);
13216: }
1.127 matthew 13217: $Title = '' if (! defined($Title));
13218: $xlabel = '' if (! defined($xlabel));
13219: $ylabel = '' if (! defined($ylabel));
1.369 www 13220: $ValuesHash{$id.'.title'} = &escape($Title);
13221: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13222: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13223: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13224: $ValuesHash{$id.'.NumBars'} = $NumBars;
13225: $ValuesHash{$id.'.NumSets'} = $NumSets;
13226: $ValuesHash{$id.'.PlotType'} = 'bar';
13227: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13228: $ValuesHash{$id.'.height'} = $height;
13229: $ValuesHash{$id.'.width'} = $width;
13230: $ValuesHash{$id.'.xskip'} = $xskip;
13231: $ValuesHash{$id.'.bar_width'} = $bar_width;
13232: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13233: #
1.228 matthew 13234: # Deal with other parameters
13235: while (my ($key,$value) = each(%$extra_settings)) {
13236: $ValuesHash{$id.'.'.$key} = $value;
13237: }
13238: #
1.646 raeburn 13239: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13240: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13241: }
13242:
13243: ############################################################
13244: ############################################################
13245:
13246: =pod
13247:
1.648 raeburn 13248: =item * &DrawXYGraph()
1.137 matthew 13249:
1.138 matthew 13250: Facilitates the plotting of data in an XY graph.
13251: Puts plot definition data into the users environment in order for
13252: graph.png to plot it. Returns an <img> tag for the plot.
13253:
13254: Inputs:
13255:
13256: =over 4
13257:
13258: =item $Title: string, the title of the plot
13259:
13260: =item $xlabel: string, text describing the X-axis of the plot
13261:
13262: =item $ylabel: string, text describing the Y-axis of the plot
13263:
13264: =item $Max: scalar, the maximum Y value to use in the plot
13265: If $Max is < any data point, the graph will not be rendered.
13266:
13267: =item $colors: Array ref containing the hex color codes for the data to be
13268: plotted in. If undefined, default values will be used.
13269:
13270: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13271:
13272: =item $Ydata: Array ref containing Array refs.
1.185 www 13273: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13274:
13275: =item %Values: hash indicating or overriding any default values which are
13276: passed to graph.png.
13277: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13278:
13279: =back
13280:
13281: Returns:
13282:
13283: An <img> tag which references graph.png and the appropriate identifying
13284: information for the plot.
13285:
1.137 matthew 13286: =cut
13287:
13288: ############################################################
13289: ############################################################
13290: sub DrawXYGraph {
13291: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13292: #
13293: # Create the identifier for the graph
13294: my $identifier = &get_cgi_id();
13295: my $id = 'cgi.'.$identifier;
13296: #
13297: $Title = '' if (! defined($Title));
13298: $xlabel = '' if (! defined($xlabel));
13299: $ylabel = '' if (! defined($ylabel));
13300: my %ValuesHash =
13301: (
1.369 www 13302: $id.'.title' => &escape($Title),
13303: $id.'.xlabel' => &escape($xlabel),
13304: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13305: $id.'.y_max_value'=> $Max,
13306: $id.'.labels' => join(',',@$Xlabels),
13307: $id.'.PlotType' => 'XY',
13308: );
13309: #
13310: if (defined($colors) && ref($colors) eq 'ARRAY') {
13311: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13312: }
13313: #
13314: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13315: return '';
13316: }
13317: my $NumSets=1;
1.138 matthew 13318: foreach my $array (@{$Ydata}){
1.137 matthew 13319: next if (! ref($array));
13320: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13321: }
1.138 matthew 13322: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13323: #
13324: # Deal with other parameters
13325: while (my ($key,$value) = each(%Values)) {
13326: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13327: }
13328: #
1.646 raeburn 13329: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13330: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13331: }
13332:
13333: ############################################################
13334: ############################################################
13335:
13336: =pod
13337:
1.648 raeburn 13338: =item * &DrawXYYGraph()
1.138 matthew 13339:
13340: Facilitates the plotting of data in an XY graph with two Y axes.
13341: Puts plot definition data into the users environment in order for
13342: graph.png to plot it. Returns an <img> tag for the plot.
13343:
13344: Inputs:
13345:
13346: =over 4
13347:
13348: =item $Title: string, the title of the plot
13349:
13350: =item $xlabel: string, text describing the X-axis of the plot
13351:
13352: =item $ylabel: string, text describing the Y-axis of the plot
13353:
13354: =item $colors: Array ref containing the hex color codes for the data to be
13355: plotted in. If undefined, default values will be used.
13356:
13357: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13358:
13359: =item $Ydata1: The first data set
13360:
13361: =item $Min1: The minimum value of the left Y-axis
13362:
13363: =item $Max1: The maximum value of the left Y-axis
13364:
13365: =item $Ydata2: The second data set
13366:
13367: =item $Min2: The minimum value of the right Y-axis
13368:
13369: =item $Max2: The maximum value of the left Y-axis
13370:
13371: =item %Values: hash indicating or overriding any default values which are
13372: passed to graph.png.
13373: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13374:
13375: =back
13376:
13377: Returns:
13378:
13379: An <img> tag which references graph.png and the appropriate identifying
13380: information for the plot.
1.136 matthew 13381:
13382: =cut
13383:
13384: ############################################################
13385: ############################################################
1.137 matthew 13386: sub DrawXYYGraph {
13387: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13388: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13389: #
13390: # Create the identifier for the graph
13391: my $identifier = &get_cgi_id();
13392: my $id = 'cgi.'.$identifier;
13393: #
13394: $Title = '' if (! defined($Title));
13395: $xlabel = '' if (! defined($xlabel));
13396: $ylabel = '' if (! defined($ylabel));
13397: my %ValuesHash =
13398: (
1.369 www 13399: $id.'.title' => &escape($Title),
13400: $id.'.xlabel' => &escape($xlabel),
13401: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13402: $id.'.labels' => join(',',@$Xlabels),
13403: $id.'.PlotType' => 'XY',
13404: $id.'.NumSets' => 2,
1.137 matthew 13405: $id.'.two_axes' => 1,
13406: $id.'.y1_max_value' => $Max1,
13407: $id.'.y1_min_value' => $Min1,
13408: $id.'.y2_max_value' => $Max2,
13409: $id.'.y2_min_value' => $Min2,
1.136 matthew 13410: );
13411: #
1.137 matthew 13412: if (defined($colors) && ref($colors) eq 'ARRAY') {
13413: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13414: }
13415: #
13416: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13417: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13418: return '';
13419: }
13420: my $NumSets=1;
1.137 matthew 13421: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13422: next if (! ref($array));
13423: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13424: }
13425: #
13426: # Deal with other parameters
13427: while (my ($key,$value) = each(%Values)) {
13428: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13429: }
13430: #
1.646 raeburn 13431: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13432: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13433: }
13434:
13435: ############################################################
13436: ############################################################
13437:
13438: =pod
13439:
1.157 matthew 13440: =back
13441:
1.139 matthew 13442: =head1 Statistics helper routines?
13443:
13444: Bad place for them but what the hell.
13445:
1.157 matthew 13446: =over 4
13447:
1.648 raeburn 13448: =item * &chartlink()
1.139 matthew 13449:
13450: Returns a link to the chart for a specific student.
13451:
13452: Inputs:
13453:
13454: =over 4
13455:
13456: =item $linktext: The text of the link
13457:
13458: =item $sname: The students username
13459:
13460: =item $sdomain: The students domain
13461:
13462: =back
13463:
1.157 matthew 13464: =back
13465:
1.139 matthew 13466: =cut
13467:
13468: ############################################################
13469: ############################################################
13470: sub chartlink {
13471: my ($linktext, $sname, $sdomain) = @_;
13472: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13473: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13474: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13475: '">'.$linktext.'</a>';
1.153 matthew 13476: }
13477:
13478: #######################################################
13479: #######################################################
13480:
13481: =pod
13482:
13483: =head1 Course Environment Routines
1.157 matthew 13484:
13485: =over 4
1.153 matthew 13486:
1.648 raeburn 13487: =item * &restore_course_settings()
1.153 matthew 13488:
1.648 raeburn 13489: =item * &store_course_settings()
1.153 matthew 13490:
13491: Restores/Store indicated form parameters from the course environment.
13492: Will not overwrite existing values of the form parameters.
13493:
13494: Inputs:
13495: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13496:
13497: a hash ref describing the data to be stored. For example:
13498:
13499: %Save_Parameters = ('Status' => 'scalar',
13500: 'chartoutputmode' => 'scalar',
13501: 'chartoutputdata' => 'scalar',
13502: 'Section' => 'array',
1.373 raeburn 13503: 'Group' => 'array',
1.153 matthew 13504: 'StudentData' => 'array',
13505: 'Maps' => 'array');
13506:
13507: Returns: both routines return nothing
13508:
1.631 raeburn 13509: =back
13510:
1.153 matthew 13511: =cut
13512:
13513: #######################################################
13514: #######################################################
13515: sub store_course_settings {
1.496 albertel 13516: return &store_settings($env{'request.course.id'},@_);
13517: }
13518:
13519: sub store_settings {
1.153 matthew 13520: # save to the environment
13521: # appenv the same items, just to be safe
1.300 albertel 13522: my $udom = $env{'user.domain'};
13523: my $uname = $env{'user.name'};
1.496 albertel 13524: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13525: my %SaveHash;
13526: my %AppHash;
13527: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13528: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13529: my $envname = 'environment.'.$basename;
1.258 albertel 13530: if (exists($env{'form.'.$setting})) {
1.153 matthew 13531: # Save this value away
13532: if ($type eq 'scalar' &&
1.258 albertel 13533: (! exists($env{$envname}) ||
13534: $env{$envname} ne $env{'form.'.$setting})) {
13535: $SaveHash{$basename} = $env{'form.'.$setting};
13536: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13537: } elsif ($type eq 'array') {
13538: my $stored_form;
1.258 albertel 13539: if (ref($env{'form.'.$setting})) {
1.153 matthew 13540: $stored_form = join(',',
13541: map {
1.369 www 13542: &escape($_);
1.258 albertel 13543: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13544: } else {
13545: $stored_form =
1.369 www 13546: &escape($env{'form.'.$setting});
1.153 matthew 13547: }
13548: # Determine if the array contents are the same.
1.258 albertel 13549: if ($stored_form ne $env{$envname}) {
1.153 matthew 13550: $SaveHash{$basename} = $stored_form;
13551: $AppHash{$envname} = $stored_form;
13552: }
13553: }
13554: }
13555: }
13556: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13557: $udom,$uname);
1.153 matthew 13558: if ($put_result !~ /^(ok|delayed)/) {
13559: &Apache::lonnet::logthis('unable to save form parameters, '.
13560: 'got error:'.$put_result);
13561: }
13562: # Make sure these settings stick around in this session, too
1.646 raeburn 13563: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13564: return;
13565: }
13566:
13567: sub restore_course_settings {
1.499 albertel 13568: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13569: }
13570:
13571: sub restore_settings {
13572: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13573: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13574: next if (exists($env{'form.'.$setting}));
1.496 albertel 13575: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13576: '.'.$setting;
1.258 albertel 13577: if (exists($env{$envname})) {
1.153 matthew 13578: if ($type eq 'scalar') {
1.258 albertel 13579: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13580: } elsif ($type eq 'array') {
1.258 albertel 13581: $env{'form.'.$setting} = [
1.153 matthew 13582: map {
1.369 www 13583: &unescape($_);
1.258 albertel 13584: } split(',',$env{$envname})
1.153 matthew 13585: ];
13586: }
13587: }
13588: }
1.127 matthew 13589: }
13590:
1.618 raeburn 13591: #######################################################
13592: #######################################################
13593:
13594: =pod
13595:
13596: =head1 Domain E-mail Routines
13597:
13598: =over 4
13599:
1.648 raeburn 13600: =item * &build_recipient_list()
1.618 raeburn 13601:
1.1075.2.44 raeburn 13602: Build recipient lists for following types of e-mail:
1.766 raeburn 13603: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 13604: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13605: module change checking, student/employee ID conflict checks, as
13606: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13607: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13608:
13609: Inputs:
1.1075.2.44 raeburn 13610: defmail (scalar - email address of default recipient),
13611: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13612: requestsmail, updatesmail, or idconflictsmail).
13613:
1.619 raeburn 13614: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 13615:
13616: origmail (scalar - email address of recipient from loncapa.conf,
13617: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13618:
1.655 raeburn 13619: Returns: comma separated list of addresses to which to send e-mail.
13620:
13621: =back
1.618 raeburn 13622:
13623: =cut
13624:
13625: ############################################################
13626: ############################################################
13627: sub build_recipient_list {
1.619 raeburn 13628: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13629: my @recipients;
13630: my $otheremails;
13631: my %domconfig =
13632: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13633: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13634: if (exists($domconfig{'contacts'}{$mailing})) {
13635: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13636: my @contacts = ('adminemail','supportemail');
13637: foreach my $item (@contacts) {
13638: if ($domconfig{'contacts'}{$mailing}{$item}) {
13639: my $addr = $domconfig{'contacts'}{$item};
13640: if (!grep(/^\Q$addr\E$/,@recipients)) {
13641: push(@recipients,$addr);
13642: }
1.619 raeburn 13643: }
1.766 raeburn 13644: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13645: }
13646: }
1.766 raeburn 13647: } elsif ($origmail ne '') {
13648: push(@recipients,$origmail);
1.618 raeburn 13649: }
1.619 raeburn 13650: } elsif ($origmail ne '') {
13651: push(@recipients,$origmail);
1.618 raeburn 13652: }
1.688 raeburn 13653: if (defined($defmail)) {
13654: if ($defmail ne '') {
13655: push(@recipients,$defmail);
13656: }
1.618 raeburn 13657: }
13658: if ($otheremails) {
1.619 raeburn 13659: my @others;
13660: if ($otheremails =~ /,/) {
13661: @others = split(/,/,$otheremails);
1.618 raeburn 13662: } else {
1.619 raeburn 13663: push(@others,$otheremails);
13664: }
13665: foreach my $addr (@others) {
13666: if (!grep(/^\Q$addr\E$/,@recipients)) {
13667: push(@recipients,$addr);
13668: }
1.618 raeburn 13669: }
13670: }
1.619 raeburn 13671: my $recipientlist = join(',',@recipients);
1.618 raeburn 13672: return $recipientlist;
13673: }
13674:
1.127 matthew 13675: ############################################################
13676: ############################################################
1.154 albertel 13677:
1.655 raeburn 13678: =pod
13679:
13680: =head1 Course Catalog Routines
13681:
13682: =over 4
13683:
13684: =item * &gather_categories()
13685:
13686: Converts category definitions - keys of categories hash stored in
13687: coursecategories in configuration.db on the primary library server in a
13688: domain - to an array. Also generates javascript and idx hash used to
13689: generate Domain Coordinator interface for editing Course Categories.
13690:
13691: Inputs:
1.663 raeburn 13692:
1.655 raeburn 13693: categories (reference to hash of category definitions).
1.663 raeburn 13694:
1.655 raeburn 13695: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13696: categories and subcategories).
1.663 raeburn 13697:
1.655 raeburn 13698: idx (reference to hash of counters used in Domain Coordinator interface for
13699: editing Course Categories).
1.663 raeburn 13700:
1.655 raeburn 13701: jsarray (reference to array of categories used to create Javascript arrays for
13702: Domain Coordinator interface for editing Course Categories).
13703:
13704: Returns: nothing
13705:
13706: Side effects: populates cats, idx and jsarray.
13707:
13708: =cut
13709:
13710: sub gather_categories {
13711: my ($categories,$cats,$idx,$jsarray) = @_;
13712: my %counters;
13713: my $num = 0;
13714: foreach my $item (keys(%{$categories})) {
13715: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13716: if ($container eq '' && $depth == 0) {
13717: $cats->[$depth][$categories->{$item}] = $cat;
13718: } else {
13719: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13720: }
13721: my ($escitem,$tail) = split(/:/,$item,2);
13722: if ($counters{$tail} eq '') {
13723: $counters{$tail} = $num;
13724: $num ++;
13725: }
13726: if (ref($idx) eq 'HASH') {
13727: $idx->{$item} = $counters{$tail};
13728: }
13729: if (ref($jsarray) eq 'ARRAY') {
13730: push(@{$jsarray->[$counters{$tail}]},$item);
13731: }
13732: }
13733: return;
13734: }
13735:
13736: =pod
13737:
13738: =item * &extract_categories()
13739:
13740: Used to generate breadcrumb trails for course categories.
13741:
13742: Inputs:
1.663 raeburn 13743:
1.655 raeburn 13744: categories (reference to hash of category definitions).
1.663 raeburn 13745:
1.655 raeburn 13746: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13747: categories and subcategories).
1.663 raeburn 13748:
1.655 raeburn 13749: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13750:
1.655 raeburn 13751: allitems (reference to hash - key is category key
13752: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13753:
1.655 raeburn 13754: idx (reference to hash of counters used in Domain Coordinator interface for
13755: editing Course Categories).
1.663 raeburn 13756:
1.655 raeburn 13757: jsarray (reference to array of categories used to create Javascript arrays for
13758: Domain Coordinator interface for editing Course Categories).
13759:
1.665 raeburn 13760: subcats (reference to hash of arrays containing all subcategories within each
13761: category, -recursive)
13762:
1.655 raeburn 13763: Returns: nothing
13764:
13765: Side effects: populates trails and allitems hash references.
13766:
13767: =cut
13768:
13769: sub extract_categories {
1.665 raeburn 13770: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13771: if (ref($categories) eq 'HASH') {
13772: &gather_categories($categories,$cats,$idx,$jsarray);
13773: if (ref($cats->[0]) eq 'ARRAY') {
13774: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13775: my $name = $cats->[0][$i];
13776: my $item = &escape($name).'::0';
13777: my $trailstr;
13778: if ($name eq 'instcode') {
13779: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13780: } elsif ($name eq 'communities') {
13781: $trailstr = &mt('Communities');
1.655 raeburn 13782: } else {
13783: $trailstr = $name;
13784: }
13785: if ($allitems->{$item} eq '') {
13786: push(@{$trails},$trailstr);
13787: $allitems->{$item} = scalar(@{$trails})-1;
13788: }
13789: my @parents = ($name);
13790: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13791: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13792: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13793: if (ref($subcats) eq 'HASH') {
13794: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13795: }
13796: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13797: }
13798: } else {
13799: if (ref($subcats) eq 'HASH') {
13800: $subcats->{$item} = [];
1.655 raeburn 13801: }
13802: }
13803: }
13804: }
13805: }
13806: return;
13807: }
13808:
13809: =pod
13810:
1.1075.2.56 raeburn 13811: =item * &recurse_categories()
1.655 raeburn 13812:
13813: Recursively used to generate breadcrumb trails for course categories.
13814:
13815: Inputs:
1.663 raeburn 13816:
1.655 raeburn 13817: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13818: categories and subcategories).
1.663 raeburn 13819:
1.655 raeburn 13820: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13821:
13822: category (current course category, for which breadcrumb trail is being generated).
13823:
13824: trails (reference to array of breadcrumb trails for each category).
13825:
1.655 raeburn 13826: allitems (reference to hash - key is category key
13827: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13828:
1.655 raeburn 13829: parents (array containing containers directories for current category,
13830: back to top level).
13831:
13832: Returns: nothing
13833:
13834: Side effects: populates trails and allitems hash references
13835:
13836: =cut
13837:
13838: sub recurse_categories {
1.665 raeburn 13839: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13840: my $shallower = $depth - 1;
13841: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13842: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13843: my $name = $cats->[$depth]{$category}[$k];
13844: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13845: my $trailstr = join(' -> ',(@{$parents},$category));
13846: if ($allitems->{$item} eq '') {
13847: push(@{$trails},$trailstr);
13848: $allitems->{$item} = scalar(@{$trails})-1;
13849: }
13850: my $deeper = $depth+1;
13851: push(@{$parents},$category);
1.665 raeburn 13852: if (ref($subcats) eq 'HASH') {
13853: my $subcat = &escape($name).':'.$category.':'.$depth;
13854: for (my $j=@{$parents}; $j>=0; $j--) {
13855: my $higher;
13856: if ($j > 0) {
13857: $higher = &escape($parents->[$j]).':'.
13858: &escape($parents->[$j-1]).':'.$j;
13859: } else {
13860: $higher = &escape($parents->[$j]).'::'.$j;
13861: }
13862: push(@{$subcats->{$higher}},$subcat);
13863: }
13864: }
13865: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13866: $subcats);
1.655 raeburn 13867: pop(@{$parents});
13868: }
13869: } else {
13870: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13871: my $trailstr = join(' -> ',(@{$parents},$category));
13872: if ($allitems->{$item} eq '') {
13873: push(@{$trails},$trailstr);
13874: $allitems->{$item} = scalar(@{$trails})-1;
13875: }
13876: }
13877: return;
13878: }
13879:
1.663 raeburn 13880: =pod
13881:
1.1075.2.56 raeburn 13882: =item * &assign_categories_table()
1.663 raeburn 13883:
13884: Create a datatable for display of hierarchical categories in a domain,
13885: with checkboxes to allow a course to be categorized.
13886:
13887: Inputs:
13888:
13889: cathash - reference to hash of categories defined for the domain (from
13890: configuration.db)
13891:
13892: currcat - scalar with an & separated list of categories assigned to a course.
13893:
1.919 raeburn 13894: type - scalar contains course type (Course or Community).
13895:
1.663 raeburn 13896: Returns: $output (markup to be displayed)
13897:
13898: =cut
13899:
13900: sub assign_categories_table {
1.919 raeburn 13901: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13902: my $output;
13903: if (ref($cathash) eq 'HASH') {
13904: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13905: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13906: $maxdepth = scalar(@cats);
13907: if (@cats > 0) {
13908: my $itemcount = 0;
13909: if (ref($cats[0]) eq 'ARRAY') {
13910: my @currcategories;
13911: if ($currcat ne '') {
13912: @currcategories = split('&',$currcat);
13913: }
1.919 raeburn 13914: my $table;
1.663 raeburn 13915: for (my $i=0; $i<@{$cats[0]}; $i++) {
13916: my $parent = $cats[0][$i];
1.919 raeburn 13917: next if ($parent eq 'instcode');
13918: if ($type eq 'Community') {
13919: next unless ($parent eq 'communities');
13920: } else {
13921: next if ($parent eq 'communities');
13922: }
1.663 raeburn 13923: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13924: my $item = &escape($parent).'::0';
13925: my $checked = '';
13926: if (@currcategories > 0) {
13927: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13928: $checked = ' checked="checked"';
1.663 raeburn 13929: }
13930: }
1.919 raeburn 13931: my $parent_title = $parent;
13932: if ($parent eq 'communities') {
13933: $parent_title = &mt('Communities');
13934: }
13935: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13936: '<input type="checkbox" name="usecategory" value="'.
13937: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13938: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13939: my $depth = 1;
13940: push(@path,$parent);
1.919 raeburn 13941: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13942: pop(@path);
1.919 raeburn 13943: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13944: $itemcount ++;
13945: }
1.919 raeburn 13946: if ($itemcount) {
13947: $output = &Apache::loncommon::start_data_table().
13948: $table.
13949: &Apache::loncommon::end_data_table();
13950: }
1.663 raeburn 13951: }
13952: }
13953: }
13954: return $output;
13955: }
13956:
13957: =pod
13958:
1.1075.2.56 raeburn 13959: =item * &assign_category_rows()
1.663 raeburn 13960:
13961: Create a datatable row for display of nested categories in a domain,
13962: with checkboxes to allow a course to be categorized,called recursively.
13963:
13964: Inputs:
13965:
13966: itemcount - track row number for alternating colors
13967:
13968: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13969: categories and subcategories.
13970:
13971: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13972:
13973: parent - parent of current category item
13974:
13975: path - Array containing all categories back up through the hierarchy from the
13976: current category to the top level.
13977:
13978: currcategories - reference to array of current categories assigned to the course
13979:
13980: Returns: $output (markup to be displayed).
13981:
13982: =cut
13983:
13984: sub assign_category_rows {
13985: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13986: my ($text,$name,$item,$chgstr);
13987: if (ref($cats) eq 'ARRAY') {
13988: my $maxdepth = scalar(@{$cats});
13989: if (ref($cats->[$depth]) eq 'HASH') {
13990: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13991: my $numchildren = @{$cats->[$depth]{$parent}};
13992: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 13993: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 13994: for (my $j=0; $j<$numchildren; $j++) {
13995: $name = $cats->[$depth]{$parent}[$j];
13996: $item = &escape($name).':'.&escape($parent).':'.$depth;
13997: my $deeper = $depth+1;
13998: my $checked = '';
13999: if (ref($currcategories) eq 'ARRAY') {
14000: if (@{$currcategories} > 0) {
14001: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14002: $checked = ' checked="checked"';
1.663 raeburn 14003: }
14004: }
14005: }
1.664 raeburn 14006: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14007: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 14008: $item.'"'.$checked.' />'.$name.'</label></span>'.
14009: '<input type="hidden" name="catname" value="'.$name.'" />'.
14010: '</td><td>';
1.663 raeburn 14011: if (ref($path) eq 'ARRAY') {
14012: push(@{$path},$name);
14013: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
14014: pop(@{$path});
14015: }
14016: $text .= '</td></tr>';
14017: }
14018: $text .= '</table></td>';
14019: }
14020: }
14021: }
14022: return $text;
14023: }
14024:
1.1075.2.69 raeburn 14025: =pod
14026:
14027: =back
14028:
14029: =cut
14030:
1.655 raeburn 14031: ############################################################
14032: ############################################################
14033:
14034:
1.443 albertel 14035: sub commit_customrole {
1.664 raeburn 14036: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14037: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14038: ($start?', '.&mt('starting').' '.localtime($start):'').
14039: ($end?', ending '.localtime($end):'').': <b>'.
14040: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14041: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14042: '</b><br />';
14043: return $output;
14044: }
14045:
14046: sub commit_standardrole {
1.1075.2.31 raeburn 14047: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14048: my ($output,$logmsg,$linefeed);
14049: if ($context eq 'auto') {
14050: $linefeed = "\n";
14051: } else {
14052: $linefeed = "<br />\n";
14053: }
1.443 albertel 14054: if ($three eq 'st') {
1.541 raeburn 14055: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 14056: $one,$two,$sec,$context,$credits);
1.541 raeburn 14057: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14058: ($result eq 'unknown_course') || ($result eq 'refused')) {
14059: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14060: } else {
1.541 raeburn 14061: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14062: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14063: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14064: if ($context eq 'auto') {
14065: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14066: } else {
14067: $output .= '<b>'.$result.'</b>'.$linefeed.
14068: &mt('Add to classlist').': <b>ok</b>';
14069: }
14070: $output .= $linefeed;
1.443 albertel 14071: }
14072: } else {
14073: $output = &mt('Assigning').' '.$three.' in '.$url.
14074: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14075: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 14076: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 14077: if ($context eq 'auto') {
14078: $output .= $result.$linefeed;
14079: } else {
14080: $output .= '<b>'.$result.'</b>'.$linefeed;
14081: }
1.443 albertel 14082: }
14083: return $output;
14084: }
14085:
14086: sub commit_studentrole {
1.1075.2.31 raeburn 14087: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
14088: $credits) = @_;
1.626 raeburn 14089: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 14090: if ($context eq 'auto') {
14091: $linefeed = "\n";
14092: } else {
14093: $linefeed = '<br />'."\n";
14094: }
1.443 albertel 14095: if (defined($one) && defined($two)) {
14096: my $cid=$one.'_'.$two;
14097: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
14098: my $secchange = 0;
14099: my $expire_role_result;
14100: my $modify_section_result;
1.628 raeburn 14101: if ($oldsec ne '-1') {
14102: if ($oldsec ne $sec) {
1.443 albertel 14103: $secchange = 1;
1.628 raeburn 14104: my $now = time;
1.443 albertel 14105: my $uurl='/'.$cid;
14106: $uurl=~s/\_/\//g;
14107: if ($oldsec) {
14108: $uurl.='/'.$oldsec;
14109: }
1.626 raeburn 14110: $oldsecurl = $uurl;
1.628 raeburn 14111: $expire_role_result =
1.652 raeburn 14112: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 14113: if ($env{'request.course.sec'} ne '') {
14114: if ($expire_role_result eq 'refused') {
14115: my @roles = ('st');
14116: my @statuses = ('previous');
14117: my @roledoms = ($one);
14118: my $withsec = 1;
14119: my %roleshash =
14120: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
14121: \@statuses,\@roles,\@roledoms,$withsec);
14122: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
14123: my ($oldstart,$oldend) =
14124: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
14125: if ($oldend > 0 && $oldend <= $now) {
14126: $expire_role_result = 'ok';
14127: }
14128: }
14129: }
14130: }
1.443 albertel 14131: $result = $expire_role_result;
14132: }
14133: }
14134: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 14135: $modify_section_result =
14136: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
14137: undef,undef,undef,$sec,
14138: $end,$start,'','',$cid,
14139: '',$context,$credits);
1.443 albertel 14140: if ($modify_section_result =~ /^ok/) {
14141: if ($secchange == 1) {
1.628 raeburn 14142: if ($sec eq '') {
14143: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
14144: } else {
14145: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
14146: }
1.443 albertel 14147: } elsif ($oldsec eq '-1') {
1.628 raeburn 14148: if ($sec eq '') {
14149: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
14150: } else {
14151: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14152: }
1.443 albertel 14153: } else {
1.628 raeburn 14154: if ($sec eq '') {
14155: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
14156: } else {
14157: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14158: }
1.443 albertel 14159: }
14160: } else {
1.628 raeburn 14161: if ($secchange) {
14162: $$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;
14163: } else {
14164: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
14165: }
1.443 albertel 14166: }
14167: $result = $modify_section_result;
14168: } elsif ($secchange == 1) {
1.628 raeburn 14169: if ($oldsec eq '') {
1.1075.2.20 raeburn 14170: $$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 14171: } else {
14172: $$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;
14173: }
1.626 raeburn 14174: if ($expire_role_result eq 'refused') {
14175: my $newsecurl = '/'.$cid;
14176: $newsecurl =~ s/\_/\//g;
14177: if ($sec ne '') {
14178: $newsecurl.='/'.$sec;
14179: }
14180: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
14181: if ($sec eq '') {
14182: $$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;
14183: } else {
14184: $$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;
14185: }
14186: }
14187: }
1.443 albertel 14188: }
14189: } else {
1.626 raeburn 14190: $$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 14191: $result = "error: incomplete course id\n";
14192: }
14193: return $result;
14194: }
14195:
1.1075.2.25 raeburn 14196: sub show_role_extent {
14197: my ($scope,$context,$role) = @_;
14198: $scope =~ s{^/}{};
14199: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
14200: push(@courseroles,'co');
14201: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
14202: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
14203: $scope =~ s{/}{_};
14204: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
14205: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
14206: my ($audom,$auname) = split(/\//,$scope);
14207: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
14208: &Apache::loncommon::plainname($auname,$audom).'</span>');
14209: } else {
14210: $scope =~ s{/$}{};
14211: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
14212: &Apache::lonnet::domain($scope,'description').'</span>');
14213: }
14214: }
14215:
1.443 albertel 14216: ############################################################
14217: ############################################################
14218:
1.566 albertel 14219: sub check_clone {
1.578 raeburn 14220: my ($args,$linefeed) = @_;
1.566 albertel 14221: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
14222: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
14223: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
14224: my $clonemsg;
14225: my $can_clone = 0;
1.944 raeburn 14226: my $lctype = lc($args->{'crstype'});
1.908 raeburn 14227: if ($lctype ne 'community') {
14228: $lctype = 'course';
14229: }
1.566 albertel 14230: if ($clonehome eq 'no_host') {
1.944 raeburn 14231: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14232: $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'});
14233: } else {
14234: $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'});
14235: }
1.566 albertel 14236: } else {
14237: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 14238: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14239: if ($clonedesc{'type'} ne 'Community') {
14240: $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'});
14241: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14242: }
14243: }
1.882 raeburn 14244: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
14245: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 14246: $can_clone = 1;
14247: } else {
1.1075.2.95 raeburn 14248: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 14249: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 14250: if ($clonehash{'cloners'} eq '') {
14251: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
14252: if ($domdefs{'canclone'}) {
14253: unless ($domdefs{'canclone'} eq 'none') {
14254: if ($domdefs{'canclone'} eq 'domain') {
14255: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
14256: $can_clone = 1;
14257: }
14258: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14259: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
14260: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
14261: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
14262: $can_clone = 1;
14263: }
14264: }
14265: }
1.908 raeburn 14266: }
1.1075.2.95 raeburn 14267: } else {
14268: my @cloners = split(/,/,$clonehash{'cloners'});
14269: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 14270: $can_clone = 1;
1.1075.2.95 raeburn 14271: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 14272: $can_clone = 1;
1.1075.2.96 raeburn 14273: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
14274: $can_clone = 1;
1.1075.2.95 raeburn 14275: }
14276: unless ($can_clone) {
1.1075.2.96 raeburn 14277: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14278: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 14279: my (%gotdomdefaults,%gotcodedefaults);
14280: foreach my $cloner (@cloners) {
14281: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
14282: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
14283: my (%codedefaults,@code_order);
14284: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
14285: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
14286: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
14287: }
14288: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
14289: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
14290: }
14291: } else {
14292: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
14293: \%codedefaults,
14294: \@code_order);
14295: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
14296: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
14297: }
14298: if (@code_order > 0) {
14299: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
14300: $cloner,$clonehash{'internal.coursecode'},
14301: $args->{'crscode'})) {
14302: $can_clone = 1;
14303: last;
14304: }
14305: }
14306: }
14307: }
14308: }
1.1075.2.96 raeburn 14309: }
14310: }
14311: unless ($can_clone) {
14312: my $ccrole = 'cc';
14313: if ($args->{'crstype'} eq 'Community') {
14314: $ccrole = 'co';
14315: }
14316: my %roleshash =
14317: &Apache::lonnet::get_my_roles($args->{'ccuname'},
14318: $args->{'ccdomain'},
14319: 'userroles',['active'],[$ccrole],
14320: [$args->{'clonedomain'}]);
14321: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
14322: $can_clone = 1;
14323: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
14324: $args->{'ccuname'},$args->{'ccdomain'})) {
14325: $can_clone = 1;
1.1075.2.95 raeburn 14326: }
14327: }
14328: unless ($can_clone) {
14329: if ($args->{'crstype'} eq 'Community') {
14330: $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'});
14331: } else {
14332: $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 14333: }
1.566 albertel 14334: }
1.578 raeburn 14335: }
1.566 albertel 14336: }
14337: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14338: }
14339:
1.444 albertel 14340: sub construct_course {
1.1075.2.59 raeburn 14341: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 14342: my $outcome;
1.541 raeburn 14343: my $linefeed = '<br />'."\n";
14344: if ($context eq 'auto') {
14345: $linefeed = "\n";
14346: }
1.566 albertel 14347:
14348: #
14349: # Are we cloning?
14350: #
14351: my ($can_clone, $clonemsg, $cloneid, $clonehome);
14352: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 14353: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 14354: if ($context ne 'auto') {
1.578 raeburn 14355: if ($clonemsg ne '') {
14356: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
14357: }
1.566 albertel 14358: }
14359: $outcome .= $clonemsg.$linefeed;
14360:
14361: if (!$can_clone) {
14362: return (0,$outcome);
14363: }
14364: }
14365:
1.444 albertel 14366: #
14367: # Open course
14368: #
14369: my $crstype = lc($args->{'crstype'});
14370: my %cenv=();
14371: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
14372: $args->{'cdescr'},
14373: $args->{'curl'},
14374: $args->{'course_home'},
14375: $args->{'nonstandard'},
14376: $args->{'crscode'},
14377: $args->{'ccuname'}.':'.
14378: $args->{'ccdomain'},
1.882 raeburn 14379: $args->{'crstype'},
1.885 raeburn 14380: $cnum,$context,$category);
1.444 albertel 14381:
14382: # Note: The testing routines depend on this being output; see
14383: # Utils::Course. This needs to at least be output as a comment
14384: # if anyone ever decides to not show this, and Utils::Course::new
14385: # will need to be suitably modified.
1.541 raeburn 14386: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 14387: if ($$courseid =~ /^error:/) {
14388: return (0,$outcome);
14389: }
14390:
1.444 albertel 14391: #
14392: # Check if created correctly
14393: #
1.479 albertel 14394: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 14395: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 14396: if ($crsuhome eq 'no_host') {
14397: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
14398: return (0,$outcome);
14399: }
1.541 raeburn 14400: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 14401:
1.444 albertel 14402: #
1.566 albertel 14403: # Do the cloning
14404: #
14405: if ($can_clone && $cloneid) {
14406: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
14407: if ($context ne 'auto') {
14408: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
14409: }
14410: $outcome .= $clonemsg.$linefeed;
14411: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 14412: # Copy all files
1.637 www 14413: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 14414: # Restore URL
1.566 albertel 14415: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 14416: # Restore title
1.566 albertel 14417: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 14418: # Restore creation date, creator and creation context.
14419: $cenv{'internal.created'}=$oldcenv{'internal.created'};
14420: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
14421: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 14422: # Mark as cloned
1.566 albertel 14423: $cenv{'clonedfrom'}=$cloneid;
1.638 www 14424: # Need to clone grading mode
14425: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
14426: $cenv{'grading'}=$newenv{'grading'};
14427: # Do not clone these environment entries
14428: &Apache::lonnet::del('environment',
14429: ['default_enrollment_start_date',
14430: 'default_enrollment_end_date',
14431: 'question.email',
14432: 'policy.email',
14433: 'comment.email',
14434: 'pch.users.denied',
1.725 raeburn 14435: 'plc.users.denied',
14436: 'hidefromcat',
1.1075.2.36 raeburn 14437: 'checkforpriv',
1.1075.2.59 raeburn 14438: 'categories',
14439: 'internal.uniquecode'],
1.638 www 14440: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 14441: if ($args->{'textbook'}) {
14442: $cenv{'internal.textbook'} = $args->{'textbook'};
14443: }
1.444 albertel 14444: }
1.566 albertel 14445:
1.444 albertel 14446: #
14447: # Set environment (will override cloned, if existing)
14448: #
14449: my @sections = ();
14450: my @xlists = ();
14451: if ($args->{'crstype'}) {
14452: $cenv{'type'}=$args->{'crstype'};
14453: }
14454: if ($args->{'crsid'}) {
14455: $cenv{'courseid'}=$args->{'crsid'};
14456: }
14457: if ($args->{'crscode'}) {
14458: $cenv{'internal.coursecode'}=$args->{'crscode'};
14459: }
14460: if ($args->{'crsquota'} ne '') {
14461: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14462: } else {
14463: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14464: }
14465: if ($args->{'ccuname'}) {
14466: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14467: ':'.$args->{'ccdomain'};
14468: } else {
14469: $cenv{'internal.courseowner'} = $args->{'curruser'};
14470: }
1.1075.2.31 raeburn 14471: if ($args->{'defaultcredits'}) {
14472: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14473: }
1.444 albertel 14474: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14475: if ($args->{'crssections'}) {
14476: $cenv{'internal.sectionnums'} = '';
14477: if ($args->{'crssections'} =~ m/,/) {
14478: @sections = split/,/,$args->{'crssections'};
14479: } else {
14480: $sections[0] = $args->{'crssections'};
14481: }
14482: if (@sections > 0) {
14483: foreach my $item (@sections) {
14484: my ($sec,$gp) = split/:/,$item;
14485: my $class = $args->{'crscode'}.$sec;
14486: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14487: $cenv{'internal.sectionnums'} .= $item.',';
14488: unless ($addcheck eq 'ok') {
14489: push @badclasses, $class;
14490: }
14491: }
14492: $cenv{'internal.sectionnums'} =~ s/,$//;
14493: }
14494: }
14495: # do not hide course coordinator from staff listing,
14496: # even if privileged
14497: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 14498: # add course coordinator's domain to domains to check for privileged users
14499: # if different to course domain
14500: if ($$crsudom ne $args->{'ccdomain'}) {
14501: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14502: }
1.444 albertel 14503: # add crosslistings
14504: if ($args->{'crsxlist'}) {
14505: $cenv{'internal.crosslistings'}='';
14506: if ($args->{'crsxlist'} =~ m/,/) {
14507: @xlists = split/,/,$args->{'crsxlist'};
14508: } else {
14509: $xlists[0] = $args->{'crsxlist'};
14510: }
14511: if (@xlists > 0) {
14512: foreach my $item (@xlists) {
14513: my ($xl,$gp) = split/:/,$item;
14514: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14515: $cenv{'internal.crosslistings'} .= $item.',';
14516: unless ($addcheck eq 'ok') {
14517: push @badclasses, $xl;
14518: }
14519: }
14520: $cenv{'internal.crosslistings'} =~ s/,$//;
14521: }
14522: }
14523: if ($args->{'autoadds'}) {
14524: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14525: }
14526: if ($args->{'autodrops'}) {
14527: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14528: }
14529: # check for notification of enrollment changes
14530: my @notified = ();
14531: if ($args->{'notify_owner'}) {
14532: if ($args->{'ccuname'} ne '') {
14533: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14534: }
14535: }
14536: if ($args->{'notify_dc'}) {
14537: if ($uname ne '') {
1.630 raeburn 14538: push(@notified,$uname.':'.$udom);
1.444 albertel 14539: }
14540: }
14541: if (@notified > 0) {
14542: my $notifylist;
14543: if (@notified > 1) {
14544: $notifylist = join(',',@notified);
14545: } else {
14546: $notifylist = $notified[0];
14547: }
14548: $cenv{'internal.notifylist'} = $notifylist;
14549: }
14550: if (@badclasses > 0) {
14551: my %lt=&Apache::lonlocal::texthash(
14552: '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',
14553: 'dnhr' => 'does not have rights to access enrollment in these classes',
14554: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14555: );
1.541 raeburn 14556: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14557: ' ('.$lt{'adby'}.')';
14558: if ($context eq 'auto') {
14559: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14560: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14561: foreach my $item (@badclasses) {
14562: if ($context eq 'auto') {
14563: $outcome .= " - $item\n";
14564: } else {
14565: $outcome .= "<li>$item</li>\n";
14566: }
14567: }
14568: if ($context eq 'auto') {
14569: $outcome .= $linefeed;
14570: } else {
1.566 albertel 14571: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14572: }
14573: }
1.444 albertel 14574: }
14575: if ($args->{'no_end_date'}) {
14576: $args->{'endaccess'} = 0;
14577: }
14578: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14579: $cenv{'internal.autoend'}=$args->{'enrollend'};
14580: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14581: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14582: if ($args->{'showphotos'}) {
14583: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14584: }
14585: $cenv{'internal.authtype'} = $args->{'authtype'};
14586: $cenv{'internal.autharg'} = $args->{'autharg'};
14587: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14588: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14589: 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');
14590: if ($context eq 'auto') {
14591: $outcome .= $krb_msg;
14592: } else {
1.566 albertel 14593: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14594: }
14595: $outcome .= $linefeed;
1.444 albertel 14596: }
14597: }
14598: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14599: if ($args->{'setpolicy'}) {
14600: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14601: }
14602: if ($args->{'setcontent'}) {
14603: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14604: }
14605: }
14606: if ($args->{'reshome'}) {
14607: $cenv{'reshome'}=$args->{'reshome'}.'/';
14608: $cenv{'reshome'}=~s/\/+$/\//;
14609: }
14610: #
14611: # course has keyed access
14612: #
14613: if ($args->{'setkeys'}) {
14614: $cenv{'keyaccess'}='yes';
14615: }
14616: # if specified, key authority is not course, but user
14617: # only active if keyaccess is yes
14618: if ($args->{'keyauth'}) {
1.487 albertel 14619: my ($user,$domain) = split(':',$args->{'keyauth'});
14620: $user = &LONCAPA::clean_username($user);
14621: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14622: if ($user ne '' && $domain ne '') {
1.487 albertel 14623: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14624: }
14625: }
14626:
1.1075.2.59 raeburn 14627: #
14628: # generate and store uniquecode (available to course requester), if course should have one.
14629: #
14630: if ($args->{'uniquecode'}) {
14631: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
14632: if ($code) {
14633: $cenv{'internal.uniquecode'} = $code;
14634: my %crsinfo =
14635: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
14636: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
14637: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
14638: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
14639: }
14640: if (ref($coderef)) {
14641: $$coderef = $code;
14642: }
14643: }
14644: }
14645:
1.444 albertel 14646: if ($args->{'disresdis'}) {
14647: $cenv{'pch.roles.denied'}='st';
14648: }
14649: if ($args->{'disablechat'}) {
14650: $cenv{'plc.roles.denied'}='st';
14651: }
14652:
14653: # Record we've not yet viewed the Course Initialization Helper for this
14654: # course
14655: $cenv{'course.helper.not.run'} = 1;
14656: #
14657: # Use new Randomseed
14658: #
14659: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14660: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14661: #
14662: # The encryption code and receipt prefix for this course
14663: #
14664: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14665: $cenv{'internal.encpref'}=100+int(9*rand(99));
14666: #
14667: # By default, use standard grading
14668: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14669:
1.541 raeburn 14670: $outcome .= $linefeed.&mt('Setting environment').': '.
14671: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14672: #
14673: # Open all assignments
14674: #
14675: if ($args->{'openall'}) {
14676: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14677: my %storecontent = ($storeunder => time,
14678: $storeunder.'.type' => 'date_start');
14679:
14680: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14681: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14682: }
14683: #
14684: # Set first page
14685: #
14686: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14687: || ($cloneid)) {
1.445 albertel 14688: use LONCAPA::map;
1.444 albertel 14689: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14690:
14691: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14692: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14693:
1.444 albertel 14694: $outcome .= ($fatal?$errtext:'read ok').' - ';
14695: my $title; my $url;
14696: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14697: $title=&mt('Syllabus');
1.444 albertel 14698: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14699: } else {
1.963 raeburn 14700: $title=&mt('Table of Contents');
1.444 albertel 14701: $url='/adm/navmaps';
14702: }
1.445 albertel 14703:
14704: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14705: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14706:
14707: if ($errtext) { $fatal=2; }
1.541 raeburn 14708: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14709: }
1.566 albertel 14710:
14711: return (1,$outcome);
1.444 albertel 14712: }
14713:
1.1075.2.59 raeburn 14714: sub make_unique_code {
14715: my ($cdom,$cnum) = @_;
14716: # get lock on uniquecodes db
14717: my $lockhash = {
14718: $cnum."\0".'uniquecodes' => $env{'user.name'}.
14719: ':'.$env{'user.domain'},
14720: };
14721: my $tries = 0;
14722: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14723: my ($code,$error);
14724:
14725: while (($gotlock ne 'ok') && ($tries<3)) {
14726: $tries ++;
14727: sleep 1;
14728: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14729: }
14730: if ($gotlock eq 'ok') {
14731: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
14732: my $gotcode;
14733: my $attempts = 0;
14734: while ((!$gotcode) && ($attempts < 100)) {
14735: $code = &generate_code();
14736: if (!exists($currcodes{$code})) {
14737: $gotcode = 1;
14738: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
14739: $error = 'nostore';
14740: }
14741: }
14742: $attempts ++;
14743: }
14744: my @del_lock = ($cnum."\0".'uniquecodes');
14745: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
14746: } else {
14747: $error = 'nolock';
14748: }
14749: return ($code,$error);
14750: }
14751:
14752: sub generate_code {
14753: my $code;
14754: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
14755: for (my $i=0; $i<6; $i++) {
14756: my $lettnum = int (rand 2);
14757: my $item = '';
14758: if ($lettnum) {
14759: $item = $letts[int( rand(18) )];
14760: } else {
14761: $item = 1+int( rand(8) );
14762: }
14763: $code .= $item;
14764: }
14765: return $code;
14766: }
14767:
1.444 albertel 14768: ############################################################
14769: ############################################################
14770:
1.953 droeschl 14771: #SD
14772: # only Community and Course, or anything else?
1.378 raeburn 14773: sub course_type {
14774: my ($cid) = @_;
14775: if (!defined($cid)) {
14776: $cid = $env{'request.course.id'};
14777: }
1.404 albertel 14778: if (defined($env{'course.'.$cid.'.type'})) {
14779: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14780: } else {
14781: return 'Course';
1.377 raeburn 14782: }
14783: }
1.156 albertel 14784:
1.406 raeburn 14785: sub group_term {
14786: my $crstype = &course_type();
14787: my %names = (
14788: 'Course' => 'group',
1.865 raeburn 14789: 'Community' => 'group',
1.406 raeburn 14790: );
14791: return $names{$crstype};
14792: }
14793:
1.902 raeburn 14794: sub course_types {
1.1075.2.59 raeburn 14795: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 14796: my %typename = (
14797: official => 'Official course',
14798: unofficial => 'Unofficial course',
14799: community => 'Community',
1.1075.2.59 raeburn 14800: textbook => 'Textbook course',
1.902 raeburn 14801: );
14802: return (\@types,\%typename);
14803: }
14804:
1.156 albertel 14805: sub icon {
14806: my ($file)=@_;
1.505 albertel 14807: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14808: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14809: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14810: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14811: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14812: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14813: $curfext.".gif") {
14814: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14815: $curfext.".gif";
14816: }
14817: }
1.249 albertel 14818: return &lonhttpdurl($iconname);
1.154 albertel 14819: }
1.84 albertel 14820:
1.575 albertel 14821: sub lonhttpdurl {
1.692 www 14822: #
14823: # Had been used for "small fry" static images on separate port 8080.
14824: # Modify here if lightweight http functionality desired again.
14825: # Currently eliminated due to increasing firewall issues.
14826: #
1.575 albertel 14827: my ($url)=@_;
1.692 www 14828: return $url;
1.215 albertel 14829: }
14830:
1.213 albertel 14831: sub connection_aborted {
14832: my ($r)=@_;
14833: $r->print(" ");$r->rflush();
14834: my $c = $r->connection;
14835: return $c->aborted();
14836: }
14837:
1.221 foxr 14838: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14839: # strings as 'strings'.
14840: sub escape_single {
1.221 foxr 14841: my ($input) = @_;
1.223 albertel 14842: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14843: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14844: return $input;
14845: }
1.223 albertel 14846:
1.222 foxr 14847: # Same as escape_single, but escape's "'s This
14848: # can be used for "strings"
14849: sub escape_double {
14850: my ($input) = @_;
14851: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14852: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14853: return $input;
14854: }
1.223 albertel 14855:
1.222 foxr 14856: # Escapes the last element of a full URL.
14857: sub escape_url {
14858: my ($url) = @_;
1.238 raeburn 14859: my @urlslices = split(/\//, $url,-1);
1.369 www 14860: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 14861: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 14862: }
1.462 albertel 14863:
1.820 raeburn 14864: sub compare_arrays {
14865: my ($arrayref1,$arrayref2) = @_;
14866: my (@difference,%count);
14867: @difference = ();
14868: %count = ();
14869: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14870: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14871: foreach my $element (keys(%count)) {
14872: if ($count{$element} == 1) {
14873: push(@difference,$element);
14874: }
14875: }
14876: }
14877: return @difference;
14878: }
14879:
1.817 bisitz 14880: # -------------------------------------------------------- Initialize user login
1.462 albertel 14881: sub init_user_environment {
1.463 albertel 14882: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14883: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14884:
14885: my $public=($username eq 'public' && $domain eq 'public');
14886:
14887: # See if old ID present, if so, remove
14888:
1.1062 raeburn 14889: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14890: my $now=time;
14891:
14892: if ($public) {
14893: my $max_public=100;
14894: my $oldest;
14895: my $oldest_time=0;
14896: for(my $next=1;$next<=$max_public;$next++) {
14897: if (-e $lonids."/publicuser_$next.id") {
14898: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14899: if ($mtime<$oldest_time || !$oldest_time) {
14900: $oldest_time=$mtime;
14901: $oldest=$next;
14902: }
14903: } else {
14904: $cookie="publicuser_$next";
14905: last;
14906: }
14907: }
14908: if (!$cookie) { $cookie="publicuser_$oldest"; }
14909: } else {
1.463 albertel 14910: # if this isn't a robot, kill any existing non-robot sessions
14911: if (!$args->{'robot'}) {
14912: opendir(DIR,$lonids);
14913: while ($filename=readdir(DIR)) {
14914: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14915: unlink($lonids.'/'.$filename);
14916: }
1.462 albertel 14917: }
1.463 albertel 14918: closedir(DIR);
1.1075.2.84 raeburn 14919: # If there is a undeleted lockfile for the user's paste buffer remove it.
14920: my $namespace = 'nohist_courseeditor';
14921: my $lockingkey = 'paste'."\0".'locked_num';
14922: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
14923: $domain,$username);
14924: if (exists($lockhash{$lockingkey})) {
14925: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
14926: unless ($delresult eq 'ok') {
14927: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
14928: }
14929: }
1.462 albertel 14930: }
14931: # Give them a new cookie
1.463 albertel 14932: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14933: : $now.$$.int(rand(10000)));
1.463 albertel 14934: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14935:
14936: # Initialize roles
14937:
1.1062 raeburn 14938: ($userroles,$firstaccenv,$timerintenv) =
14939: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14940: }
14941: # ------------------------------------ Check browser type and MathML capability
14942:
1.1075.2.77 raeburn 14943: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
14944: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 14945:
14946: # ------------------------------------------------------------- Get environment
14947:
14948: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14949: my ($tmp) = keys(%userenv);
14950: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14951: } else {
14952: undef(%userenv);
14953: }
14954: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14955: $form->{'interface'}=$userenv{'interface'};
14956: }
14957: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14958:
14959: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14960: foreach my $option ('interface','localpath','localres') {
14961: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14962: }
14963: # --------------------------------------------------------- Write first profile
14964:
14965: {
14966: my %initial_env =
14967: ("user.name" => $username,
14968: "user.domain" => $domain,
14969: "user.home" => $authhost,
14970: "browser.type" => $clientbrowser,
14971: "browser.version" => $clientversion,
14972: "browser.mathml" => $clientmathml,
14973: "browser.unicode" => $clientunicode,
14974: "browser.os" => $clientos,
1.1075.2.42 raeburn 14975: "browser.mobile" => $clientmobile,
14976: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 14977: "browser.osversion" => $clientosversion,
1.462 albertel 14978: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14979: "request.course.fn" => '',
14980: "request.course.uri" => '',
14981: "request.course.sec" => '',
14982: "request.role" => 'cm',
14983: "request.role.adv" => $env{'user.adv'},
14984: "request.host" => $ENV{'REMOTE_ADDR'},);
14985:
14986: if ($form->{'localpath'}) {
14987: $initial_env{"browser.localpath"} = $form->{'localpath'};
14988: $initial_env{"browser.localres"} = $form->{'localres'};
14989: }
14990:
14991: if ($form->{'interface'}) {
14992: $form->{'interface'}=~s/\W//gs;
14993: $initial_env{"browser.interface"} = $form->{'interface'};
14994: $env{'browser.interface'}=$form->{'interface'};
14995: }
14996:
1.1075.2.54 raeburn 14997: if ($form->{'iptoken'}) {
14998: my $lonhost = $r->dir_config('lonHostID');
14999: $initial_env{"user.noloadbalance"} = $lonhost;
15000: $env{'user.noloadbalance'} = $lonhost;
15001: }
15002:
1.981 raeburn 15003: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 15004: my %domdef;
15005: unless ($domain eq 'public') {
15006: %domdef = &Apache::lonnet::get_domain_defaults($domain);
15007: }
1.980 raeburn 15008:
1.1075.2.7 raeburn 15009: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 15010: $userenv{'availabletools.'.$tool} =
1.980 raeburn 15011: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15012: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 15013: }
15014:
1.1075.2.59 raeburn 15015: foreach my $crstype ('official','unofficial','community','textbook') {
1.765 raeburn 15016: $userenv{'canrequest.'.$crstype} =
15017: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 15018: 'reload','requestcourses',
15019: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 15020: }
15021:
1.1075.2.14 raeburn 15022: $userenv{'canrequest.author'} =
15023: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15024: 'reload','requestauthor',
15025: \%userenv,\%domdef,\%is_adv);
15026: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15027: $domain,$username);
15028: my $reqstatus = $reqauthor{'author_status'};
15029: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15030: if (ref($reqauthor{'author'}) eq 'HASH') {
15031: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15032: $reqauthor{'author'}{'timestamp'};
15033: }
15034: }
15035:
1.462 albertel 15036: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15037:
1.462 albertel 15038: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
15039: &GDBM_WRCREAT(),0640)) {
15040: &_add_to_env(\%disk_env,\%initial_env);
15041: &_add_to_env(\%disk_env,\%userenv,'environment.');
15042: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 15043: if (ref($firstaccenv) eq 'HASH') {
15044: &_add_to_env(\%disk_env,$firstaccenv);
15045: }
15046: if (ref($timerintenv) eq 'HASH') {
15047: &_add_to_env(\%disk_env,$timerintenv);
15048: }
1.463 albertel 15049: if (ref($args->{'extra_env'})) {
15050: &_add_to_env(\%disk_env,$args->{'extra_env'});
15051: }
1.462 albertel 15052: untie(%disk_env);
15053: } else {
1.705 tempelho 15054: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
15055: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 15056: return 'error: '.$!;
15057: }
15058: }
15059: $env{'request.role'}='cm';
15060: $env{'request.role.adv'}=$env{'user.adv'};
15061: $env{'browser.type'}=$clientbrowser;
15062:
15063: return $cookie;
15064:
15065: }
15066:
15067: sub _add_to_env {
15068: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 15069: if (ref($env_data) eq 'HASH') {
15070: while (my ($key,$value) = each(%$env_data)) {
15071: $idf->{$prefix.$key} = $value;
15072: $env{$prefix.$key} = $value;
15073: }
1.462 albertel 15074: }
15075: }
15076:
1.685 tempelho 15077: # --- Get the symbolic name of a problem and the url
15078: sub get_symb {
15079: my ($request,$silent) = @_;
1.726 raeburn 15080: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 15081: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
15082: if ($symb eq '') {
15083: if (!$silent) {
1.1071 raeburn 15084: if (ref($request)) {
15085: $request->print("Unable to handle ambiguous references:$url:.");
15086: }
1.685 tempelho 15087: return ();
15088: }
15089: }
15090: &Apache::lonenc::check_decrypt(\$symb);
15091: return ($symb);
15092: }
15093:
15094: # --------------------------------------------------------------Get annotation
15095:
15096: sub get_annotation {
15097: my ($symb,$enc) = @_;
15098:
15099: my $key = $symb;
15100: if (!$enc) {
15101: $key =
15102: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
15103: }
15104: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
15105: return $annotation{$key};
15106: }
15107:
15108: sub clean_symb {
1.731 raeburn 15109: my ($symb,$delete_enc) = @_;
1.685 tempelho 15110:
15111: &Apache::lonenc::check_decrypt(\$symb);
15112: my $enc = $env{'request.enc'};
1.731 raeburn 15113: if ($delete_enc) {
1.730 raeburn 15114: delete($env{'request.enc'});
15115: }
1.685 tempelho 15116:
15117: return ($symb,$enc);
15118: }
1.462 albertel 15119:
1.1075.2.69 raeburn 15120: ############################################################
15121: ############################################################
15122:
15123: =pod
15124:
15125: =head1 Routines for building display used to search for courses
15126:
15127:
15128: =over 4
15129:
15130: =item * &build_filters()
15131:
15132: Create markup for a table used to set filters to use when selecting
15133: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
15134: and quotacheck.pl
15135:
15136:
15137: Inputs:
15138:
15139: filterlist - anonymous array of fields to include as potential filters
15140:
15141: crstype - course type
15142:
15143: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
15144: to pop-open a course selector (will contain "extra element").
15145:
15146: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
15147:
15148: filter - anonymous hash of criteria and their values
15149:
15150: action - form action
15151:
15152: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
15153:
15154: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
15155:
15156: cloneruname - username of owner of new course who wants to clone
15157:
15158: clonerudom - domain of owner of new course who wants to clone
15159:
15160: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
15161:
15162: codetitlesref - reference to array of titles of components in institutional codes (official courses)
15163:
15164: codedom - domain
15165:
15166: formname - value of form element named "form".
15167:
15168: fixeddom - domain, if fixed.
15169:
15170: prevphase - value to assign to form element named "phase" when going back to the previous screen
15171:
15172: cnameelement - name of form element in form on opener page which will receive title of selected course
15173:
15174: cnumelement - name of form element in form on opener page which will receive courseID of selected course
15175:
15176: cdomelement - name of form element in form on opener page which will receive domain of selected course
15177:
15178: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
15179:
15180: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
15181:
15182: clonewarning - warning message about missing information for intended course owner when DC creates a course
15183:
15184:
15185: Returns: $output - HTML for display of search criteria, and hidden form elements.
15186:
15187:
15188: Side Effects: None
15189:
15190: =cut
15191:
15192: # ---------------------------------------------- search for courses based on last activity etc.
15193:
15194: sub build_filters {
15195: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
15196: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
15197: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
15198: $cnameelement,$cnumelement,$cdomelement,$setroles,
15199: $clonetext,$clonewarning) = @_;
15200: my ($list,$jscript);
15201: my $onchange = 'javascript:updateFilters(this)';
15202: my ($domainselectform,$sincefilterform,$createdfilterform,
15203: $ownerdomselectform,$persondomselectform,$instcodeform,
15204: $typeselectform,$instcodetitle);
15205: if ($formname eq '') {
15206: $formname = $caller;
15207: }
15208: foreach my $item (@{$filterlist}) {
15209: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
15210: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
15211: if ($item eq 'domainfilter') {
15212: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
15213: } elsif ($item eq 'coursefilter') {
15214: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
15215: } elsif ($item eq 'ownerfilter') {
15216: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15217: } elsif ($item eq 'ownerdomfilter') {
15218: $filter->{'ownerdomfilter'} =
15219: &LONCAPA::clean_domain($filter->{$item});
15220: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
15221: 'ownerdomfilter',1);
15222: } elsif ($item eq 'personfilter') {
15223: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15224: } elsif ($item eq 'persondomfilter') {
15225: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
15226: 'persondomfilter',1);
15227: } else {
15228: $filter->{$item} =~ s/\W//g;
15229: }
15230: if (!$filter->{$item}) {
15231: $filter->{$item} = '';
15232: }
15233: }
15234: if ($item eq 'domainfilter') {
15235: my $allow_blank = 1;
15236: if ($formname eq 'portform') {
15237: $allow_blank=0;
15238: } elsif ($formname eq 'studentform') {
15239: $allow_blank=0;
15240: }
15241: if ($fixeddom) {
15242: $domainselectform = '<input type="hidden" name="domainfilter"'.
15243: ' value="'.$codedom.'" />'.
15244: &Apache::lonnet::domain($codedom,'description');
15245: } else {
15246: $domainselectform = &select_dom_form($filter->{$item},
15247: 'domainfilter',
15248: $allow_blank,'',$onchange);
15249: }
15250: } else {
15251: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
15252: }
15253: }
15254:
15255: # last course activity filter and selection
15256: $sincefilterform = &timebased_select_form('sincefilter',$filter);
15257:
15258: # course created filter and selection
15259: if (exists($filter->{'createdfilter'})) {
15260: $createdfilterform = &timebased_select_form('createdfilter',$filter);
15261: }
15262:
15263: my %lt = &Apache::lonlocal::texthash(
15264: 'cac' => "$crstype Activity",
15265: 'ccr' => "$crstype Created",
15266: 'cde' => "$crstype Title",
15267: 'cdo' => "$crstype Domain",
15268: 'ins' => 'Institutional Code',
15269: 'inc' => 'Institutional Categorization',
15270: 'cow' => "$crstype Owner/Co-owner",
15271: 'cop' => "$crstype Personnel Includes",
15272: 'cog' => 'Type',
15273: );
15274:
15275: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15276: my $typeval = 'Course';
15277: if ($crstype eq 'Community') {
15278: $typeval = 'Community';
15279: }
15280: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
15281: } else {
15282: $typeselectform = '<select name="type" size="1"';
15283: if ($onchange) {
15284: $typeselectform .= ' onchange="'.$onchange.'"';
15285: }
15286: $typeselectform .= '>'."\n";
15287: foreach my $posstype ('Course','Community') {
15288: $typeselectform.='<option value="'.$posstype.'"'.
15289: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
15290: }
15291: $typeselectform.="</select>";
15292: }
15293:
15294: my ($cloneableonlyform,$cloneabletitle);
15295: if (exists($filter->{'cloneableonly'})) {
15296: my $cloneableon = '';
15297: my $cloneableoff = ' checked="checked"';
15298: if ($filter->{'cloneableonly'}) {
15299: $cloneableon = $cloneableoff;
15300: $cloneableoff = '';
15301: }
15302: $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>';
15303: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 15304: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 15305: } else {
15306: $cloneabletitle = &mt('Cloneable by you');
15307: }
15308: }
15309: my $officialjs;
15310: if ($crstype eq 'Course') {
15311: if (exists($filter->{'instcodefilter'})) {
15312: # if (($fixeddom) || ($formname eq 'requestcrs') ||
15313: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
15314: if ($codedom) {
15315: $officialjs = 1;
15316: ($instcodeform,$jscript,$$numtitlesref) =
15317: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
15318: $officialjs,$codetitlesref);
15319: if ($jscript) {
15320: $jscript = '<script type="text/javascript">'."\n".
15321: '// <![CDATA['."\n".
15322: $jscript."\n".
15323: '// ]]>'."\n".
15324: '</script>'."\n";
15325: }
15326: }
15327: if ($instcodeform eq '') {
15328: $instcodeform =
15329: '<input type="text" name="instcodefilter" size="10" value="'.
15330: $list->{'instcodefilter'}.'" />';
15331: $instcodetitle = $lt{'ins'};
15332: } else {
15333: $instcodetitle = $lt{'inc'};
15334: }
15335: if ($fixeddom) {
15336: $instcodetitle .= '<br />('.$codedom.')';
15337: }
15338: }
15339: }
15340: my $output = qq|
15341: <form method="post" name="filterpicker" action="$action">
15342: <input type="hidden" name="form" value="$formname" />
15343: |;
15344: if ($formname eq 'modifycourse') {
15345: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
15346: '<input type="hidden" name="prevphase" value="'.
15347: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 15348: } elsif ($formname eq 'quotacheck') {
15349: $output .= qq|
15350: <input type="hidden" name="sortby" value="" />
15351: <input type="hidden" name="sortorder" value="" />
15352: |;
15353: } else {
1.1075.2.69 raeburn 15354: my $name_input;
15355: if ($cnameelement ne '') {
15356: $name_input = '<input type="hidden" name="cnameelement" value="'.
15357: $cnameelement.'" />';
15358: }
15359: $output .= qq|
15360: <input type="hidden" name="cnumelement" value="$cnumelement" />
15361: <input type="hidden" name="cdomelement" value="$cdomelement" />
15362: $name_input
15363: $roleelement
15364: $multelement
15365: $typeelement
15366: |;
15367: if ($formname eq 'portform') {
15368: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
15369: }
15370: }
15371: if ($fixeddom) {
15372: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
15373: }
15374: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
15375: if ($sincefilterform) {
15376: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
15377: .$sincefilterform
15378: .&Apache::lonhtmlcommon::row_closure();
15379: }
15380: if ($createdfilterform) {
15381: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
15382: .$createdfilterform
15383: .&Apache::lonhtmlcommon::row_closure();
15384: }
15385: if ($domainselectform) {
15386: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
15387: .$domainselectform
15388: .&Apache::lonhtmlcommon::row_closure();
15389: }
15390: if ($typeselectform) {
15391: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15392: $output .= $typeselectform;
15393: } else {
15394: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
15395: .$typeselectform
15396: .&Apache::lonhtmlcommon::row_closure();
15397: }
15398: }
15399: if ($instcodeform) {
15400: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
15401: .$instcodeform
15402: .&Apache::lonhtmlcommon::row_closure();
15403: }
15404: if (exists($filter->{'ownerfilter'})) {
15405: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
15406: '<table><tr><td>'.&mt('Username').'<br />'.
15407: '<input type="text" name="ownerfilter" size="20" value="'.
15408: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15409: $ownerdomselectform.'</td></tr></table>'.
15410: &Apache::lonhtmlcommon::row_closure();
15411: }
15412: if (exists($filter->{'personfilter'})) {
15413: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
15414: '<table><tr><td>'.&mt('Username').'<br />'.
15415: '<input type="text" name="personfilter" size="20" value="'.
15416: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15417: $persondomselectform.'</td></tr></table>'.
15418: &Apache::lonhtmlcommon::row_closure();
15419: }
15420: if (exists($filter->{'coursefilter'})) {
15421: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
15422: .'<input type="text" name="coursefilter" size="25" value="'
15423: .$list->{'coursefilter'}.'" />'
15424: .&Apache::lonhtmlcommon::row_closure();
15425: }
15426: if ($cloneableonlyform) {
15427: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
15428: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
15429: }
15430: if (exists($filter->{'descriptfilter'})) {
15431: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
15432: .'<input type="text" name="descriptfilter" size="40" value="'
15433: .$list->{'descriptfilter'}.'" />'
15434: .&Apache::lonhtmlcommon::row_closure(1);
15435: }
15436: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
15437: '<input type="hidden" name="updater" value="" />'."\n".
15438: '<input type="submit" name="gosearch" value="'.
15439: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
15440: return $jscript.$clonewarning.$output;
15441: }
15442:
15443: =pod
15444:
15445: =item * &timebased_select_form()
15446:
15447: Create markup for a dropdown list used to select a time-based
15448: filter e.g., Course Activity, Course Created, when searching for courses
15449: or communities
15450:
15451: Inputs:
15452:
15453: item - name of form element (sincefilter or createdfilter)
15454:
15455: filter - anonymous hash of criteria and their values
15456:
15457: Returns: HTML for a select box contained a blank, then six time selections,
15458: with value set in incoming form variables currently selected.
15459:
15460: Side Effects: None
15461:
15462: =cut
15463:
15464: sub timebased_select_form {
15465: my ($item,$filter) = @_;
15466: if (ref($filter) eq 'HASH') {
15467: $filter->{$item} =~ s/[^\d-]//g;
15468: if (!$filter->{$item}) { $filter->{$item}=-1; }
15469: return &select_form(
15470: $filter->{$item},
15471: $item,
15472: { '-1' => '',
15473: '86400' => &mt('today'),
15474: '604800' => &mt('last week'),
15475: '2592000' => &mt('last month'),
15476: '7776000' => &mt('last three months'),
15477: '15552000' => &mt('last six months'),
15478: '31104000' => &mt('last year'),
15479: 'select_form_order' =>
15480: ['-1','86400','604800','2592000','7776000',
15481: '15552000','31104000']});
15482: }
15483: }
15484:
15485: =pod
15486:
15487: =item * &js_changer()
15488:
15489: Create script tag containing Javascript used to submit course search form
15490: when course type or domain is changed, and also to hide 'Searching ...' on
15491: page load completion for page showing search result.
15492:
15493: Inputs: None
15494:
15495: Returns: markup containing updateFilters() and hideSearching() javascript functions.
15496:
15497: Side Effects: None
15498:
15499: =cut
15500:
15501: sub js_changer {
15502: return <<ENDJS;
15503: <script type="text/javascript">
15504: // <![CDATA[
15505: function updateFilters(caller) {
15506: if (typeof(caller) != "undefined") {
15507: document.filterpicker.updater.value = caller.name;
15508: }
15509: document.filterpicker.submit();
15510: }
15511:
15512: function hideSearching() {
15513: if (document.getElementById('searching')) {
15514: document.getElementById('searching').style.display = 'none';
15515: }
15516: return;
15517: }
15518:
15519: // ]]>
15520: </script>
15521:
15522: ENDJS
15523: }
15524:
15525: =pod
15526:
15527: =item * &search_courses()
15528:
15529: Process selected filters form course search form and pass to lonnet::courseiddump
15530: to retrieve a hash for which keys are courseIDs which match the selected filters.
15531:
15532: Inputs:
15533:
15534: dom - domain being searched
15535:
15536: type - course type ('Course' or 'Community' or '.' if any).
15537:
15538: filter - anonymous hash of criteria and their values
15539:
15540: numtitles - for institutional codes - number of categories
15541:
15542: cloneruname - optional username of new course owner
15543:
15544: clonerudom - optional domain of new course owner
15545:
1.1075.2.95 raeburn 15546: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 15547: (used when DC is using course creation form)
15548:
15549: codetitles - reference to array of titles of components in institutional codes (official courses).
15550:
1.1075.2.95 raeburn 15551: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
15552: (and so can clone automatically)
15553:
15554: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
15555:
15556: reqinstcode - institutional code of new course, where search_courses is used to identify potential
15557: courses to clone
1.1075.2.69 raeburn 15558:
15559: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
15560:
15561:
15562: Side Effects: None
15563:
15564: =cut
15565:
15566:
15567: sub search_courses {
1.1075.2.95 raeburn 15568: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
15569: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 15570: my (%courses,%showcourses,$cloner);
15571: if (($filter->{'ownerfilter'} ne '') ||
15572: ($filter->{'ownerdomfilter'} ne '')) {
15573: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
15574: $filter->{'ownerdomfilter'};
15575: }
15576: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
15577: if (!$filter->{$item}) {
15578: $filter->{$item}='.';
15579: }
15580: }
15581: my $now = time;
15582: my $timefilter =
15583: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
15584: my ($createdbefore,$createdafter);
15585: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
15586: $createdbefore = $now;
15587: $createdafter = $now-$filter->{'createdfilter'};
15588: }
15589: my ($instcodefilter,$regexpok);
15590: if ($numtitles) {
15591: if ($env{'form.official'} eq 'on') {
15592: $instcodefilter =
15593: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15594: $regexpok = 1;
15595: } elsif ($env{'form.official'} eq 'off') {
15596: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15597: unless ($instcodefilter eq '') {
15598: $regexpok = -1;
15599: }
15600: }
15601: } else {
15602: $instcodefilter = $filter->{'instcodefilter'};
15603: }
15604: if ($instcodefilter eq '') { $instcodefilter = '.'; }
15605: if ($type eq '') { $type = '.'; }
15606:
15607: if (($clonerudom ne '') && ($cloneruname ne '')) {
15608: $cloner = $cloneruname.':'.$clonerudom;
15609: }
15610: %courses = &Apache::lonnet::courseiddump($dom,
15611: $filter->{'descriptfilter'},
15612: $timefilter,
15613: $instcodefilter,
15614: $filter->{'combownerfilter'},
15615: $filter->{'coursefilter'},
15616: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 15617: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 15618: $filter->{'cloneableonly'},
15619: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 15620: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 15621: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
15622: my $ccrole;
15623: if ($type eq 'Community') {
15624: $ccrole = 'co';
15625: } else {
15626: $ccrole = 'cc';
15627: }
15628: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
15629: $filter->{'persondomfilter'},
15630: 'userroles',undef,
15631: [$ccrole,'in','ad','ep','ta','cr'],
15632: $dom);
15633: foreach my $role (keys(%rolehash)) {
15634: my ($cnum,$cdom,$courserole) = split(':',$role);
15635: my $cid = $cdom.'_'.$cnum;
15636: if (exists($courses{$cid})) {
15637: if (ref($courses{$cid}) eq 'HASH') {
15638: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
15639: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
15640: push (@{$courses{$cid}{roles}},$courserole);
15641: }
15642: } else {
15643: $courses{$cid}{roles} = [$courserole];
15644: }
15645: $showcourses{$cid} = $courses{$cid};
15646: }
15647: }
15648: }
15649: %courses = %showcourses;
15650: }
15651: return %courses;
15652: }
15653:
15654: =pod
15655:
15656: =back
15657:
1.1075.2.88 raeburn 15658: =head1 Routines for version requirements for current course.
15659:
15660: =over 4
15661:
15662: =item * &check_release_required()
15663:
15664: Compares required LON-CAPA version with version on server, and
15665: if required version is newer looks for a server with the required version.
15666:
15667: Looks first at servers in user's owen domain; if none suitable, looks at
15668: servers in course's domain are permitted to host sessions for user's domain.
15669:
15670: Inputs:
15671:
15672: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
15673:
15674: $courseid - Course ID of current course
15675:
15676: $rolecode - User's current role in course (for switchserver query string).
15677:
15678: $required - LON-CAPA version needed by course (format: Major.Minor).
15679:
15680:
15681: Returns:
15682:
15683: $switchserver - query string tp append to /adm/switchserver call (if
15684: current server's LON-CAPA version is too old.
15685:
15686: $warning - Message is displayed if no suitable server could be found.
15687:
15688: =cut
15689:
15690: sub check_release_required {
15691: my ($loncaparev,$courseid,$rolecode,$required) = @_;
15692: my ($switchserver,$warning);
15693: if ($required ne '') {
15694: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
15695: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
15696: if ($reqdmajor ne '' && $reqdminor ne '') {
15697: my $otherserver;
15698: if (($major eq '' && $minor eq '') ||
15699: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
15700: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
15701: my $switchlcrev =
15702: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
15703: $userdomserver);
15704: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
15705: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
15706: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
15707: my $cdom = $env{'course.'.$courseid.'.domain'};
15708: if ($cdom ne $env{'user.domain'}) {
15709: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
15710: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
15711: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
15712: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
15713: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
15714: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
15715: my $canhost =
15716: &Apache::lonnet::can_host_session($env{'user.domain'},
15717: $coursedomserver,
15718: $remoterev,
15719: $udomdefaults{'remotesessions'},
15720: $defdomdefaults{'hostedsessions'});
15721:
15722: if ($canhost) {
15723: $otherserver = $coursedomserver;
15724: } else {
15725: $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.");
15726: }
15727: } else {
15728: $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).");
15729: }
15730: } else {
15731: $otherserver = $userdomserver;
15732: }
15733: }
15734: if ($otherserver ne '') {
15735: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
15736: }
15737: }
15738: }
15739: return ($switchserver,$warning);
15740: }
15741:
15742: =pod
15743:
15744: =item * &check_release_result()
15745:
15746: Inputs:
15747:
15748: $switchwarning - Warning message if no suitable server found to host session.
15749:
15750: $switchserver - query string to append to /adm/switchserver containing lonHostID
15751: and current role.
15752:
15753: Returns: HTML to display with information about requirement to switch server.
15754: Either displaying warning with link to Roles/Courses screen or
15755: display link to switchserver.
15756:
1.1075.2.69 raeburn 15757: =cut
15758:
1.1075.2.88 raeburn 15759: sub check_release_result {
15760: my ($switchwarning,$switchserver) = @_;
15761: my $output = &start_page('Selected course unavailable on this server').
15762: '<p class="LC_warning">';
15763: if ($switchwarning) {
15764: $output .= $switchwarning.'<br /><a href="/adm/roles">';
15765: if (&show_course()) {
15766: $output .= &mt('Display courses');
15767: } else {
15768: $output .= &mt('Display roles');
15769: }
15770: $output .= '</a>';
15771: } elsif ($switchserver) {
15772: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
15773: '<br />'.
15774: '<a href="/adm/switchserver?'.$switchserver.'">'.
15775: &mt('Switch Server').
15776: '</a>';
15777: }
15778: $output .= '</p>'.&end_page();
15779: return $output;
15780: }
15781:
15782: =pod
15783:
15784: =item * &needs_coursereinit()
15785:
15786: Determine if course contents stored for user's session needs to be
15787: refreshed, because content has changed since "Big Hash" last tied.
15788:
15789: Check for change is made if time last checked is more than 10 minutes ago
15790: (by default).
15791:
15792: Inputs:
15793:
15794: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
15795:
15796: $interval (optional) - Time which may elapse (in s) between last check for content
15797: change in current course. (default: 600 s).
15798:
15799: Returns: an array; first element is:
15800:
15801: =over 4
15802:
15803: 'switch' - if content updates mean user's session
15804: needs to be switched to a server running a newer LON-CAPA version
15805:
15806: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
15807: on current server hosting user's session
15808:
15809: '' - if no action required.
15810:
15811: =back
15812:
15813: If first item element is 'switch':
15814:
15815: second item is $switchwarning - Warning message if no suitable server found to host session.
15816:
15817: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
15818: and current role.
15819:
15820: otherwise: no other elements returned.
15821:
15822: =back
15823:
15824: =cut
15825:
15826: sub needs_coursereinit {
15827: my ($loncaparev,$interval) = @_;
15828: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
15829: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
15830: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
15831: my $now = time;
15832: if ($interval eq '') {
15833: $interval = 600;
15834: }
15835: if (($now-$env{'request.course.timechecked'})>$interval) {
15836: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
15837: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
15838: if ($lastchange > $env{'request.course.tied'}) {
15839: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
15840: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
15841: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
15842: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
15843: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
15844: $curr_reqd_hash{'internal.releaserequired'}});
15845: my ($switchserver,$switchwarning) =
15846: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
15847: $curr_reqd_hash{'internal.releaserequired'});
15848: if ($switchwarning ne '' || $switchserver ne '') {
15849: return ('switch',$switchwarning,$switchserver);
15850: }
15851: }
15852: }
15853: return ('update');
15854: }
15855: }
15856: return ();
15857: }
1.1075.2.69 raeburn 15858:
1.1075.2.11 raeburn 15859: sub update_content_constraints {
15860: my ($cdom,$cnum,$chome,$cid) = @_;
15861: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
15862: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
15863: my %checkresponsetypes;
15864: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
15865: my ($item,$name,$value) = split(/:/,$key);
15866: if ($item eq 'resourcetag') {
15867: if ($name eq 'responsetype') {
15868: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
15869: }
15870: }
15871: }
15872: my $navmap = Apache::lonnavmaps::navmap->new();
15873: if (defined($navmap)) {
15874: my %allresponses;
15875: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
15876: my %responses = $res->responseTypes();
15877: foreach my $key (keys(%responses)) {
15878: next unless(exists($checkresponsetypes{$key}));
15879: $allresponses{$key} += $responses{$key};
15880: }
15881: }
15882: foreach my $key (keys(%allresponses)) {
15883: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
15884: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
15885: ($reqdmajor,$reqdminor) = ($major,$minor);
15886: }
15887: }
15888: undef($navmap);
15889: }
15890: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
15891: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
15892: }
15893: return;
15894: }
15895:
1.1075.2.27 raeburn 15896: sub allmaps_incourse {
15897: my ($cdom,$cnum,$chome,$cid) = @_;
15898: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
15899: $cid = $env{'request.course.id'};
15900: $cdom = $env{'course.'.$cid.'.domain'};
15901: $cnum = $env{'course.'.$cid.'.num'};
15902: $chome = $env{'course.'.$cid.'.home'};
15903: }
15904: my %allmaps = ();
15905: my $lastchange =
15906: &Apache::lonnet::get_coursechange($cdom,$cnum);
15907: if ($lastchange > $env{'request.course.tied'}) {
15908: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
15909: unless ($ferr) {
15910: &update_content_constraints($cdom,$cnum,$chome,$cid);
15911: }
15912: }
15913: my $navmap = Apache::lonnavmaps::navmap->new();
15914: if (defined($navmap)) {
15915: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
15916: $allmaps{$res->src()} = 1;
15917: }
15918: }
15919: return \%allmaps;
15920: }
15921:
1.1075.2.11 raeburn 15922: sub parse_supplemental_title {
15923: my ($title) = @_;
15924:
15925: my ($foldertitle,$renametitle);
15926: if ($title =~ /&&&/) {
15927: $title = &HTML::Entites::decode($title);
15928: }
15929: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
15930: $renametitle=$4;
15931: my ($time,$uname,$udom) = ($1,$2,$3);
15932: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
15933: my $name = &plainname($uname,$udom);
15934: $name = &HTML::Entities::encode($name,'"<>&\'');
15935: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
15936: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
15937: $name.': <br />'.$foldertitle;
15938: }
15939: if (wantarray) {
15940: return ($title,$foldertitle,$renametitle);
15941: }
15942: return $title;
15943: }
15944:
1.1075.2.43 raeburn 15945: sub recurse_supplemental {
15946: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
15947: if ($suppmap) {
15948: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
15949: if ($fatal) {
15950: $errors ++;
15951: } else {
15952: if ($#LONCAPA::map::resources > 0) {
15953: foreach my $res (@LONCAPA::map::resources) {
15954: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
15955: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 15956: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
15957: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 15958: } else {
15959: $numfiles ++;
15960: }
15961: }
15962: }
15963: }
15964: }
15965: }
15966: return ($numfiles,$errors);
15967: }
15968:
1.1075.2.18 raeburn 15969: sub symb_to_docspath {
15970: my ($symb) = @_;
15971: return unless ($symb);
15972: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
15973: if ($resurl=~/\.(sequence|page)$/) {
15974: $mapurl=$resurl;
15975: } elsif ($resurl eq 'adm/navmaps') {
15976: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
15977: }
15978: my $mapresobj;
15979: my $navmap = Apache::lonnavmaps::navmap->new();
15980: if (ref($navmap)) {
15981: $mapresobj = $navmap->getResourceByUrl($mapurl);
15982: }
15983: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
15984: my $type=$2;
15985: my $path;
15986: if (ref($mapresobj)) {
15987: my $pcslist = $mapresobj->map_hierarchy();
15988: if ($pcslist ne '') {
15989: foreach my $pc (split(/,/,$pcslist)) {
15990: next if ($pc <= 1);
15991: my $res = $navmap->getByMapPc($pc);
15992: if (ref($res)) {
15993: my $thisurl = $res->src();
15994: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
15995: my $thistitle = $res->title();
15996: $path .= '&'.
15997: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 15998: &escape($thistitle).
1.1075.2.18 raeburn 15999: ':'.$res->randompick().
16000: ':'.$res->randomout().
16001: ':'.$res->encrypted().
16002: ':'.$res->randomorder().
16003: ':'.$res->is_page();
16004: }
16005: }
16006: }
16007: $path =~ s/^\&//;
16008: my $maptitle = $mapresobj->title();
16009: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16010: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16011: }
16012: $path .= (($path ne '')? '&' : '').
16013: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16014: &escape($maptitle).
1.1075.2.18 raeburn 16015: ':'.$mapresobj->randompick().
16016: ':'.$mapresobj->randomout().
16017: ':'.$mapresobj->encrypted().
16018: ':'.$mapresobj->randomorder().
16019: ':'.$mapresobj->is_page();
16020: } else {
16021: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16022: my $ispage = (($type eq 'page')? 1 : '');
16023: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16024: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16025: }
16026: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16027: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 16028: }
16029: unless ($mapurl eq 'default') {
16030: $path = 'default&'.
1.1075.2.46 raeburn 16031: &escape('Main Content').
1.1075.2.18 raeburn 16032: ':::::&'.$path;
16033: }
16034: return $path;
16035: }
16036:
1.1075.2.14 raeburn 16037: sub captcha_display {
16038: my ($context,$lonhost) = @_;
16039: my ($output,$error);
1.1075.2.107 raeburn 16040: my ($captcha,$pubkey,$privkey,$version) =
16041: &get_captcha_config($context,$lonhost);
1.1075.2.14 raeburn 16042: if ($captcha eq 'original') {
16043: $output = &create_captcha();
16044: unless ($output) {
16045: $error = 'captcha';
16046: }
16047: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16048: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 16049: unless ($output) {
16050: $error = 'recaptcha';
16051: }
16052: }
1.1075.2.107 raeburn 16053: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 16054: }
16055:
16056: sub captcha_response {
16057: my ($context,$lonhost) = @_;
16058: my ($captcha_chk,$captcha_error);
1.1075.2.109! raeburn 16059: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1075.2.14 raeburn 16060: if ($captcha eq 'original') {
16061: ($captcha_chk,$captcha_error) = &check_captcha();
16062: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16063: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 16064: } else {
16065: $captcha_chk = 1;
16066: }
16067: return ($captcha_chk,$captcha_error);
16068: }
16069:
16070: sub get_captcha_config {
16071: my ($context,$lonhost) = @_;
1.1075.2.107 raeburn 16072: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 16073: my $hostname = &Apache::lonnet::hostname($lonhost);
16074: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
16075: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16076: if ($context eq 'usercreation') {
16077: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
16078: if (ref($domconfig{$context}) eq 'HASH') {
16079: $hashtocheck = $domconfig{$context}{'cancreate'};
16080: if (ref($hashtocheck) eq 'HASH') {
16081: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
16082: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
16083: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
16084: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
16085: }
16086: if ($privkey && $pubkey) {
16087: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16088: $version = $hashtocheck->{'recaptchaversion'};
16089: if ($version ne '2') {
16090: $version = 1;
16091: }
1.1075.2.14 raeburn 16092: } else {
16093: $captcha = 'original';
16094: }
16095: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
16096: $captcha = 'original';
16097: }
16098: }
16099: } else {
16100: $captcha = 'captcha';
16101: }
16102: } elsif ($context eq 'login') {
16103: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
16104: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
16105: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
16106: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
16107: if ($privkey && $pubkey) {
16108: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16109: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
16110: if ($version ne '2') {
16111: $version = 1;
16112: }
1.1075.2.14 raeburn 16113: } else {
16114: $captcha = 'original';
16115: }
16116: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
16117: $captcha = 'original';
16118: }
16119: }
1.1075.2.107 raeburn 16120: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 16121: }
16122:
16123: sub create_captcha {
16124: my %captcha_params = &captcha_settings();
16125: my ($output,$maxtries,$tries) = ('',10,0);
16126: while ($tries < $maxtries) {
16127: $tries ++;
16128: my $captcha = Authen::Captcha->new (
16129: output_folder => $captcha_params{'output_dir'},
16130: data_folder => $captcha_params{'db_dir'},
16131: );
16132: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
16133:
16134: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
16135: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
16136: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 16137: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
16138: '<br />'.
16139: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 16140: last;
16141: }
16142: }
16143: return $output;
16144: }
16145:
16146: sub captcha_settings {
16147: my %captcha_params = (
16148: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
16149: www_output_dir => "/captchaspool",
16150: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
16151: numchars => '5',
16152: );
16153: return %captcha_params;
16154: }
16155:
16156: sub check_captcha {
16157: my ($captcha_chk,$captcha_error);
16158: my $code = $env{'form.code'};
16159: my $md5sum = $env{'form.crypt'};
16160: my %captcha_params = &captcha_settings();
16161: my $captcha = Authen::Captcha->new(
16162: output_folder => $captcha_params{'output_dir'},
16163: data_folder => $captcha_params{'db_dir'},
16164: );
1.1075.2.26 raeburn 16165: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 16166: my %captcha_hash = (
16167: 0 => 'Code not checked (file error)',
16168: -1 => 'Failed: code expired',
16169: -2 => 'Failed: invalid code (not in database)',
16170: -3 => 'Failed: invalid code (code does not match crypt)',
16171: );
16172: if ($captcha_chk != 1) {
16173: $captcha_error = $captcha_hash{$captcha_chk}
16174: }
16175: return ($captcha_chk,$captcha_error);
16176: }
16177:
16178: sub create_recaptcha {
1.1075.2.107 raeburn 16179: my ($pubkey,$version) = @_;
16180: if ($version >= 2) {
16181: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
16182: } else {
16183: my $use_ssl;
16184: if ($ENV{'SERVER_PORT'} == 443) {
16185: $use_ssl = 1;
16186: }
16187: my $captcha = Captcha::reCAPTCHA->new;
16188: return $captcha->get_options_setter({theme => 'white'})."\n".
16189: $captcha->get_html($pubkey,undef,$use_ssl).
16190: &mt('If the text is hard to read, [_1] will replace them.',
16191: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
16192: '<br /><br />';
16193: }
1.1075.2.14 raeburn 16194: }
16195:
16196: sub check_recaptcha {
1.1075.2.107 raeburn 16197: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 16198: my $captcha_chk;
1.1075.2.107 raeburn 16199: if ($version >= 2) {
16200: my $ua = LWP::UserAgent->new;
16201: $ua->timeout(10);
16202: my %info = (
16203: secret => $privkey,
16204: response => $env{'form.g-recaptcha-response'},
16205: remoteip => $ENV{'REMOTE_ADDR'},
16206: );
16207: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
16208: if ($response->is_success) {
16209: my $data = JSON::DWIW->from_json($response->decoded_content);
16210: if (ref($data) eq 'HASH') {
16211: if ($data->{'success'}) {
16212: $captcha_chk = 1;
16213: }
16214: }
16215: }
16216: } else {
16217: my $captcha = Captcha::reCAPTCHA->new;
16218: my $captcha_result =
16219: $captcha->check_answer(
16220: $privkey,
16221: $ENV{'REMOTE_ADDR'},
16222: $env{'form.recaptcha_challenge_field'},
16223: $env{'form.recaptcha_response_field'},
16224: );
16225: if ($captcha_result->{is_valid}) {
16226: $captcha_chk = 1;
16227: }
1.1075.2.14 raeburn 16228: }
16229: return $captcha_chk;
16230: }
16231:
1.1075.2.64 raeburn 16232: sub emailusername_info {
1.1075.2.103 raeburn 16233: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 16234: my %titles = &Apache::lonlocal::texthash (
16235: lastname => 'Last Name',
16236: firstname => 'First Name',
16237: institution => 'School/college/university',
16238: location => "School's city, state/province, country",
16239: web => "School's web address",
16240: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 16241: id => 'Student/Employee ID',
1.1075.2.64 raeburn 16242: );
16243: return (\@fields,\%titles);
16244: }
16245:
1.1075.2.56 raeburn 16246: sub cleanup_html {
16247: my ($incoming) = @_;
16248: my $outgoing;
16249: if ($incoming ne '') {
16250: $outgoing = $incoming;
16251: $outgoing =~ s/;/;/g;
16252: $outgoing =~ s/\#/#/g;
16253: $outgoing =~ s/\&/&/g;
16254: $outgoing =~ s/</</g;
16255: $outgoing =~ s/>/>/g;
16256: $outgoing =~ s/\(/(/g;
16257: $outgoing =~ s/\)/)/g;
16258: $outgoing =~ s/"/"/g;
16259: $outgoing =~ s/'/'/g;
16260: $outgoing =~ s/\$/$/g;
16261: $outgoing =~ s{/}{/}g;
16262: $outgoing =~ s/=/=/g;
16263: $outgoing =~ s/\\/\/g
16264: }
16265: return $outgoing;
16266: }
16267:
1.1075.2.74 raeburn 16268: # Checks for critical messages and returns a redirect url if one exists.
16269: # $interval indicates how often to check for messages.
16270: sub critical_redirect {
16271: my ($interval) = @_;
16272: if ((time-$env{'user.criticalcheck.time'})>$interval) {
16273: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
16274: $env{'user.name'});
16275: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
16276: my $redirecturl;
16277: if ($what[0]) {
16278: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
16279: $redirecturl='/adm/email?critical=display';
16280: my $url=&Apache::lonnet::absolute_url().$redirecturl;
16281: return (1, $url);
16282: }
16283: }
16284: }
16285: return ();
16286: }
16287:
1.1075.2.64 raeburn 16288: # Use:
16289: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
16290: #
16291: ##################################################
16292: # password associated functions #
16293: ##################################################
16294: sub des_keys {
16295: # Make a new key for DES encryption.
16296: # Each key has two parts which are returned separately.
16297: # Please note: Each key must be passed through the &hex function
16298: # before it is output to the web browser. The hex versions cannot
16299: # be used to decrypt.
16300: my @hexstr=('0','1','2','3','4','5','6','7',
16301: '8','9','a','b','c','d','e','f');
16302: my $lkey='';
16303: for (0..7) {
16304: $lkey.=$hexstr[rand(15)];
16305: }
16306: my $ukey='';
16307: for (0..7) {
16308: $ukey.=$hexstr[rand(15)];
16309: }
16310: return ($lkey,$ukey);
16311: }
16312:
16313: sub des_decrypt {
16314: my ($key,$cyphertext) = @_;
16315: my $keybin=pack("H16",$key);
16316: my $cypher;
16317: if ($Crypt::DES::VERSION>=2.03) {
16318: $cypher=new Crypt::DES $keybin;
16319: } else {
16320: $cypher=new DES $keybin;
16321: }
1.1075.2.106 raeburn 16322: my $plaintext='';
16323: my $cypherlength = length($cyphertext);
16324: my $numchunks = int($cypherlength/32);
16325: for (my $j=0; $j<$numchunks; $j++) {
16326: my $start = $j*32;
16327: my $cypherblock = substr($cyphertext,$start,32);
16328: my $chunk =
16329: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
16330: $chunk .=
16331: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
16332: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
16333: $plaintext .= $chunk;
16334: }
1.1075.2.64 raeburn 16335: return $plaintext;
16336: }
16337:
1.112 bowersj2 16338: 1;
16339: __END__;
1.41 ng 16340:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>