Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.113
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.113! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.112 2016/09/15 04:18:38 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:
1.1075.2.112 raeburn 1747: sub colorfuleditor_js {
1748: return <<"COLORFULEDIT"
1749: <script type="text/javascript">
1750: // <![CDATA[>
1751: function fold_box(curDepth, lastresource){
1752:
1753: // we need a list because there can be several blocks you need to fold in one tag
1754: var block = document.getElementsByName('foldblock_'+curDepth);
1755: // but there is only one folding button per tag
1756: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1757:
1758: if(block.item(0).style.display == 'none'){
1759:
1760: foldbutton.value = '@{[&mt("Hide")]}';
1761: for (i = 0; i < block.length; i++){
1762: block.item(i).style.display = '';
1763: }
1764: }else{
1765:
1766: foldbutton.value = '@{[&mt("Show")]}';
1767: for (i = 0; i < block.length; i++){
1768: // block.item(i).style.visibility = 'collapse';
1769: block.item(i).style.display = 'none';
1770: }
1771: };
1772: saveState(lastresource);
1773: }
1774:
1775: function saveState (lastresource) {
1776:
1777: var tag_list = getTagList();
1778: if(tag_list != null){
1779: var timestamp = new Date().getTime();
1780: var key = lastresource;
1781:
1782: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1783: // starting with timestamp
1784: var value = timestamp+';';
1785:
1786: // building the list of key-value pairs
1787: for(var i = 0; i < tag_list.length; i++){
1788: value += tag_list[i]+',';
1789: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1790: }
1791:
1792: // only iterate whole storage if nothing to override
1793: if(localStorage.getItem(key) == null){
1794:
1795: // prevent storage from growing large
1796: if(localStorage.length > 50){
1797: var regex_getTimestamp = /^(?:\d)+;/;
1798: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1799: var oldest_key;
1800:
1801: for(var i = 1; i < localStorage.length; i++){
1802: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1803: oldest_key = localStorage.key(i);
1804: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1805: }
1806: }
1807: localStorage.removeItem(oldest_key);
1808: }
1809: }
1810: localStorage.setItem(key,value);
1811: }
1812: }
1813:
1814: // restore folding status of blocks (on page load)
1815: function restoreState (lastresource) {
1816: if(localStorage.getItem(lastresource) != null){
1817: var key = lastresource;
1818: var value = localStorage.getItem(key);
1819: var regex_delTimestamp = /^\d+;/;
1820:
1821: value.replace(regex_delTimestamp, '');
1822:
1823: var valueArr = value.split(';');
1824: var pairs;
1825: var elements;
1826: for (var i = 0; i < valueArr.length; i++){
1827: pairs = valueArr[i].split(',');
1828: elements = document.getElementsByName(pairs[0]);
1829:
1830: for (var j = 0; j < elements.length; j++){
1831: elements[j].style.display = pairs[1];
1832: if (pairs[1] == "none"){
1833: var regex_id = /([_\\d]+)\$/;
1834: regex_id.exec(pairs[0]);
1835: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
1836: }
1837: }
1838: }
1839: }
1840: }
1841:
1842: function getTagList () {
1843:
1844: var stringToSearch = document.lonhomework.innerHTML;
1845:
1846: var ret = new Array();
1847: var regex_findBlock = /(foldblock_.*?)"/g;
1848: var tag_list = stringToSearch.match(regex_findBlock);
1849:
1850: if(tag_list != null){
1851: for(var i = 0; i < tag_list.length; i++){
1852: ret.push(tag_list[i].replace(/"/, ''));
1853: }
1854: }
1855: return ret;
1856: }
1857:
1858: function saveScrollPosition (resource) {
1859: var tag_list = getTagList();
1860:
1861: // we dont always want to jump to the first block
1862: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
1863: if(\$(window).scrollTop() > 170){
1864: if(tag_list != null){
1865: var result;
1866: for(var i = 0; i < tag_list.length; i++){
1867: if(isElementInViewport(tag_list[i])){
1868: result += tag_list[i]+';';
1869: }
1870: }
1871: sessionStorage.setItem('anchor_'+resource, result);
1872: }
1873: } else {
1874: // we dont need to save zero, just delete the item to leave everything tidy
1875: sessionStorage.removeItem('anchor_'+resource);
1876: }
1877: }
1878:
1879: function restoreScrollPosition(resource){
1880:
1881: var elem = sessionStorage.getItem('anchor_'+resource);
1882: if(elem != null){
1883: var tag_list = elem.split(';');
1884: var elem_list;
1885:
1886: for(var i = 0; i < tag_list.length; i++){
1887: elem_list = document.getElementsByName(tag_list[i]);
1888:
1889: if(elem_list.length > 0){
1890: elem = elem_list[0];
1891: break;
1892: }
1893: }
1894: elem.scrollIntoView();
1895: }
1896: }
1897:
1898: function isElementInViewport(el) {
1899:
1900: // change to last element instead of first
1901: var elem = document.getElementsByName(el);
1902: var rect = elem[0].getBoundingClientRect();
1903:
1904: return (
1905: rect.top >= 0 &&
1906: rect.left >= 0 &&
1907: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1908: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1909: );
1910: }
1911:
1912: function autosize(depth){
1913: var cmInst = window['cm'+depth];
1914: var fitsizeButton = document.getElementById('fitsize'+depth);
1915:
1916: // is fixed size, switching to dynamic
1917: if (sessionStorage.getItem("autosized_"+depth) == null) {
1918: cmInst.setSize("","auto");
1919: fitsizeButton.value = "@{[&mt('Fixed size')]}";
1920: sessionStorage.setItem("autosized_"+depth, "yes");
1921:
1922: // is dynamic size, switching to fixed
1923: } else {
1924: cmInst.setSize("","300px");
1925: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
1926: sessionStorage.removeItem("autosized_"+depth);
1927: }
1928: }
1929:
1930:
1931:
1932: // ]]>
1933: </script>
1934: COLORFULEDIT
1935: }
1936:
1937: sub xmleditor_js {
1938: return <<XMLEDIT
1939: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
1940: <script type="text/javascript">
1941: // <![CDATA[>
1942:
1943: function saveScrollPosition (resource) {
1944:
1945: var scrollPos = \$(window).scrollTop();
1946: sessionStorage.setItem(resource,scrollPos);
1947: }
1948:
1949: function restoreScrollPosition(resource){
1950:
1951: var scrollPos = sessionStorage.getItem(resource);
1952: \$(window).scrollTop(scrollPos);
1953: }
1954:
1955: // unless internet explorer
1956: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
1957:
1958: \$(document).ready(function() {
1959: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
1960: });
1961: }
1962:
1963: // inserts text at cursor position into codemirror (xml editor only)
1964: function insertText(text){
1965: cm.focus();
1966: var curPos = cm.getCursor();
1967: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
1968: }
1969: // ]]>
1970: </script>
1971: XMLEDIT
1972: }
1973:
1974: sub insert_folding_button {
1975: my $curDepth = $Apache::lonxml::curdepth;
1976: my $lastresource = $env{'request.ambiguous'};
1977:
1978: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
1979: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
1980: }
1981:
1982:
1.565 albertel 1983: =pod
1984:
1.256 matthew 1985: =head1 Excel and CSV file utility routines
1986:
1987: =cut
1988:
1989: ###############################################################
1990: ###############################################################
1991:
1992: =pod
1993:
1.1075.2.56 raeburn 1994: =over 4
1995:
1.648 raeburn 1996: =item * &csv_translate($text)
1.37 matthew 1997:
1.185 www 1998: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1999: format.
2000:
2001: =cut
2002:
1.180 matthew 2003: ###############################################################
2004: ###############################################################
1.37 matthew 2005: sub csv_translate {
2006: my $text = shift;
2007: $text =~ s/\"/\"\"/g;
1.209 albertel 2008: $text =~ s/\n/ /g;
1.37 matthew 2009: return $text;
2010: }
1.180 matthew 2011:
2012: ###############################################################
2013: ###############################################################
2014:
2015: =pod
2016:
1.648 raeburn 2017: =item * &define_excel_formats()
1.180 matthew 2018:
2019: Define some commonly used Excel cell formats.
2020:
2021: Currently supported formats:
2022:
2023: =over 4
2024:
2025: =item header
2026:
2027: =item bold
2028:
2029: =item h1
2030:
2031: =item h2
2032:
2033: =item h3
2034:
1.256 matthew 2035: =item h4
2036:
2037: =item i
2038:
1.180 matthew 2039: =item date
2040:
2041: =back
2042:
2043: Inputs: $workbook
2044:
2045: Returns: $format, a hash reference.
2046:
1.1057 foxr 2047:
1.180 matthew 2048: =cut
2049:
2050: ###############################################################
2051: ###############################################################
2052: sub define_excel_formats {
2053: my ($workbook) = @_;
2054: my $format;
2055: $format->{'header'} = $workbook->add_format(bold => 1,
2056: bottom => 1,
2057: align => 'center');
2058: $format->{'bold'} = $workbook->add_format(bold=>1);
2059: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2060: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2061: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2062: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2063: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2064: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2065: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2066: return $format;
2067: }
2068:
2069: ###############################################################
2070: ###############################################################
1.113 bowersj2 2071:
2072: =pod
2073:
1.648 raeburn 2074: =item * &create_workbook()
1.255 matthew 2075:
2076: Create an Excel worksheet. If it fails, output message on the
2077: request object and return undefs.
2078:
2079: Inputs: Apache request object
2080:
2081: Returns (undef) on failure,
2082: Excel worksheet object, scalar with filename, and formats
2083: from &Apache::loncommon::define_excel_formats on success
2084:
2085: =cut
2086:
2087: ###############################################################
2088: ###############################################################
2089: sub create_workbook {
2090: my ($r) = @_;
2091: #
2092: # Create the excel spreadsheet
2093: my $filename = '/prtspool/'.
1.258 albertel 2094: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2095: time.'_'.rand(1000000000).'.xls';
2096: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2097: if (! defined($workbook)) {
2098: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2099: $r->print(
2100: '<p class="LC_error">'
2101: .&mt('Problems occurred in creating the new Excel file.')
2102: .' '.&mt('This error has been logged.')
2103: .' '.&mt('Please alert your LON-CAPA administrator.')
2104: .'</p>'
2105: );
1.255 matthew 2106: return (undef);
2107: }
2108: #
1.1014 foxr 2109: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2110: #
2111: my $format = &Apache::loncommon::define_excel_formats($workbook);
2112: return ($workbook,$filename,$format);
2113: }
2114:
2115: ###############################################################
2116: ###############################################################
2117:
2118: =pod
2119:
1.648 raeburn 2120: =item * &create_text_file()
1.113 bowersj2 2121:
1.542 raeburn 2122: Create a file to write to and eventually make available to the user.
1.256 matthew 2123: If file creation fails, outputs an error message on the request object and
2124: return undefs.
1.113 bowersj2 2125:
1.256 matthew 2126: Inputs: Apache request object, and file suffix
1.113 bowersj2 2127:
1.256 matthew 2128: Returns (undef) on failure,
2129: Filehandle and filename on success.
1.113 bowersj2 2130:
2131: =cut
2132:
1.256 matthew 2133: ###############################################################
2134: ###############################################################
2135: sub create_text_file {
2136: my ($r,$suffix) = @_;
2137: if (! defined($suffix)) { $suffix = 'txt'; };
2138: my $fh;
2139: my $filename = '/prtspool/'.
1.258 albertel 2140: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2141: time.'_'.rand(1000000000).'.'.$suffix;
2142: $fh = Apache::File->new('>/home/httpd'.$filename);
2143: if (! defined($fh)) {
2144: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2145: $r->print(
2146: '<p class="LC_error">'
2147: .&mt('Problems occurred in creating the output file.')
2148: .' '.&mt('This error has been logged.')
2149: .' '.&mt('Please alert your LON-CAPA administrator.')
2150: .'</p>'
2151: );
1.113 bowersj2 2152: }
1.256 matthew 2153: return ($fh,$filename)
1.113 bowersj2 2154: }
2155:
2156:
1.256 matthew 2157: =pod
1.113 bowersj2 2158:
2159: =back
2160:
2161: =cut
1.37 matthew 2162:
2163: ###############################################################
1.33 matthew 2164: ## Home server <option> list generating code ##
2165: ###############################################################
1.35 matthew 2166:
1.169 www 2167: # ------------------------------------------
2168:
2169: sub domain_select {
2170: my ($name,$value,$multiple)=@_;
2171: my %domains=map {
1.514 albertel 2172: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2173: } &Apache::lonnet::all_domains();
1.169 www 2174: if ($multiple) {
2175: $domains{''}=&mt('Any domain');
1.550 albertel 2176: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2177: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2178: } else {
1.550 albertel 2179: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2180: return &select_form($name,$value,\%domains);
1.169 www 2181: }
2182: }
2183:
1.282 albertel 2184: #-------------------------------------------
2185:
2186: =pod
2187:
1.519 raeburn 2188: =head1 Routines for form select boxes
2189:
2190: =over 4
2191:
1.648 raeburn 2192: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2193:
2194: Returns a string containing a <select> element int multiple mode
2195:
2196:
2197: Args:
2198: $name - name of the <select> element
1.506 raeburn 2199: $value - scalar or array ref of values that should already be selected
1.282 albertel 2200: $size - number of rows long the select element is
1.283 albertel 2201: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2202: (shown text should already have been &mt())
1.506 raeburn 2203: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2204:
1.282 albertel 2205: =cut
2206:
2207: #-------------------------------------------
1.169 www 2208: sub multiple_select_form {
1.284 albertel 2209: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2210: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2211: my $output='';
1.191 matthew 2212: if (! defined($size)) {
2213: $size = 4;
1.283 albertel 2214: if (scalar(keys(%$hash))<4) {
2215: $size = scalar(keys(%$hash));
1.191 matthew 2216: }
2217: }
1.734 bisitz 2218: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2219: my @order;
1.506 raeburn 2220: if (ref($order) eq 'ARRAY') {
2221: @order = @{$order};
2222: } else {
2223: @order = sort(keys(%$hash));
1.501 banghart 2224: }
2225: if (exists($$hash{'select_form_order'})) {
2226: @order = @{$$hash{'select_form_order'}};
2227: }
2228:
1.284 albertel 2229: foreach my $key (@order) {
1.356 albertel 2230: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2231: $output.='selected="selected" ' if ($selected{$key});
2232: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2233: }
2234: $output.="</select>\n";
2235: return $output;
2236: }
2237:
1.88 www 2238: #-------------------------------------------
2239:
2240: =pod
2241:
1.970 raeburn 2242: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 2243:
2244: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2245: allow a user to select options from a ref to a hash containing:
2246: option_name => displayed text. An optional $onchange can include
2247: a javascript onchange item, e.g., onchange="this.form.submit();"
2248:
1.88 www 2249: See lonrights.pm for an example invocation and use.
2250:
2251: =cut
2252:
2253: #-------------------------------------------
2254: sub select_form {
1.970 raeburn 2255: my ($def,$name,$hashref,$onchange) = @_;
2256: return unless (ref($hashref) eq 'HASH');
2257: if ($onchange) {
2258: $onchange = ' onchange="'.$onchange.'"';
2259: }
2260: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2261: my @keys;
1.970 raeburn 2262: if (exists($hashref->{'select_form_order'})) {
2263: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2264: } else {
1.970 raeburn 2265: @keys=sort(keys(%{$hashref}));
1.128 albertel 2266: }
1.356 albertel 2267: foreach my $key (@keys) {
2268: $selectform.=
2269: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2270: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2271: ">".$hashref->{$key}."</option>\n";
1.88 www 2272: }
2273: $selectform.="</select>";
2274: return $selectform;
2275: }
2276:
1.475 www 2277: # For display filters
2278:
2279: sub display_filter {
1.1074 raeburn 2280: my ($context) = @_;
1.475 www 2281: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2282: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2283: my $phraseinput = 'hidden';
2284: my $includeinput = 'hidden';
2285: my ($checked,$includetypestext);
2286: if ($env{'form.displayfilter'} eq 'containing') {
2287: $phraseinput = 'text';
2288: if ($context eq 'parmslog') {
2289: $includeinput = 'checkbox';
2290: if ($env{'form.includetypes'}) {
2291: $checked = ' checked="checked"';
2292: }
2293: $includetypestext = &mt('Include parameter types');
2294: }
2295: } else {
2296: $includetypestext = ' ';
2297: }
2298: my ($additional,$secondid,$thirdid);
2299: if ($context eq 'parmslog') {
2300: $additional =
2301: '<label><input type="'.$includeinput.'" name="includetypes"'.
2302: $checked.' name="includetypes" value="1" id="includetypes" />'.
2303: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2304: '</label>';
2305: $secondid = 'includetypes';
2306: $thirdid = 'includetypestext';
2307: }
2308: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2309: '$secondid','$thirdid')";
2310: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2311: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2312: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2313: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2314: &mt('Filter: [_1]',
1.477 www 2315: &select_form($env{'form.displayfilter'},
2316: 'displayfilter',
1.970 raeburn 2317: {'currentfolder' => 'Current folder/page',
1.477 www 2318: 'containing' => 'Containing phrase',
1.1074 raeburn 2319: 'none' => 'None'},$onchange)).' '.
2320: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2321: &HTML::Entities::encode($env{'form.containingphrase'}).
2322: '" />'.$additional;
2323: }
2324:
2325: sub display_filter_js {
2326: my $includetext = &mt('Include parameter types');
2327: return <<"ENDJS";
2328:
2329: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2330: var firstType = 'hidden';
2331: if (setter.options[setter.selectedIndex].value == 'containing') {
2332: firstType = 'text';
2333: }
2334: firstObject = document.getElementById(firstid);
2335: if (typeof(firstObject) == 'object') {
2336: if (firstObject.type != firstType) {
2337: changeInputType(firstObject,firstType);
2338: }
2339: }
2340: if (context == 'parmslog') {
2341: var secondType = 'hidden';
2342: if (firstType == 'text') {
2343: secondType = 'checkbox';
2344: }
2345: secondObject = document.getElementById(secondid);
2346: if (typeof(secondObject) == 'object') {
2347: if (secondObject.type != secondType) {
2348: changeInputType(secondObject,secondType);
2349: }
2350: }
2351: var textItem = document.getElementById(thirdid);
2352: var currtext = textItem.innerHTML;
2353: var newtext;
2354: if (firstType == 'text') {
2355: newtext = '$includetext';
2356: } else {
2357: newtext = ' ';
2358: }
2359: if (currtext != newtext) {
2360: textItem.innerHTML = newtext;
2361: }
2362: }
2363: return;
2364: }
2365:
2366: function changeInputType(oldObject,newType) {
2367: var newObject = document.createElement('input');
2368: newObject.type = newType;
2369: if (oldObject.size) {
2370: newObject.size = oldObject.size;
2371: }
2372: if (oldObject.value) {
2373: newObject.value = oldObject.value;
2374: }
2375: if (oldObject.name) {
2376: newObject.name = oldObject.name;
2377: }
2378: if (oldObject.id) {
2379: newObject.id = oldObject.id;
2380: }
2381: oldObject.parentNode.replaceChild(newObject,oldObject);
2382: return;
2383: }
2384:
2385: ENDJS
1.475 www 2386: }
2387:
1.167 www 2388: sub gradeleveldescription {
2389: my $gradelevel=shift;
2390: my %gradelevels=(0 => 'Not specified',
2391: 1 => 'Grade 1',
2392: 2 => 'Grade 2',
2393: 3 => 'Grade 3',
2394: 4 => 'Grade 4',
2395: 5 => 'Grade 5',
2396: 6 => 'Grade 6',
2397: 7 => 'Grade 7',
2398: 8 => 'Grade 8',
2399: 9 => 'Grade 9',
2400: 10 => 'Grade 10',
2401: 11 => 'Grade 11',
2402: 12 => 'Grade 12',
2403: 13 => 'Grade 13',
2404: 14 => '100 Level',
2405: 15 => '200 Level',
2406: 16 => '300 Level',
2407: 17 => '400 Level',
2408: 18 => 'Graduate Level');
2409: return &mt($gradelevels{$gradelevel});
2410: }
2411:
1.163 www 2412: sub select_level_form {
2413: my ($deflevel,$name)=@_;
2414: unless ($deflevel) { $deflevel=0; }
1.167 www 2415: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2416: for (my $i=0; $i<=18; $i++) {
2417: $selectform.="<option value=\"$i\" ".
1.253 albertel 2418: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2419: ">".&gradeleveldescription($i)."</option>\n";
2420: }
2421: $selectform.="</select>";
2422: return $selectform;
1.163 www 2423: }
1.167 www 2424:
1.35 matthew 2425: #-------------------------------------------
2426:
1.45 matthew 2427: =pod
2428:
1.1075.2.42 raeburn 2429: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35 matthew 2430:
2431: Returns a string containing a <select name='$name' size='1'> form to
2432: allow a user to select the domain to preform an operation in.
2433: See loncreateuser.pm for an example invocation and use.
2434:
1.90 www 2435: If the $includeempty flag is set, it also includes an empty choice ("no domain
2436: selected");
2437:
1.743 raeburn 2438: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2439:
1.910 raeburn 2440: 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.
2441:
1.1075.2.36 raeburn 2442: The optional $incdoms is a reference to an array of domains which will be the only available options.
2443:
2444: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2445:
1.35 matthew 2446: =cut
2447:
2448: #-------------------------------------------
1.34 matthew 2449: sub select_dom_form {
1.1075.2.36 raeburn 2450: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2451: if ($onchange) {
1.874 raeburn 2452: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2453: }
1.1075.2.36 raeburn 2454: my (@domains,%exclude);
1.910 raeburn 2455: if (ref($incdoms) eq 'ARRAY') {
2456: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2457: } else {
2458: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2459: }
1.90 www 2460: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2461: if (ref($excdoms) eq 'ARRAY') {
2462: map { $exclude{$_} = 1; } @{$excdoms};
2463: }
1.743 raeburn 2464: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2465: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2466: next if ($exclude{$dom});
1.356 albertel 2467: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2468: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2469: if ($showdomdesc) {
2470: if ($dom ne '') {
2471: my $domdesc = &Apache::lonnet::domain($dom,'description');
2472: if ($domdesc ne '') {
2473: $selectdomain .= ' ('.$domdesc.')';
2474: }
2475: }
2476: }
2477: $selectdomain .= "</option>\n";
1.34 matthew 2478: }
2479: $selectdomain.="</select>";
2480: return $selectdomain;
2481: }
2482:
1.35 matthew 2483: #-------------------------------------------
2484:
1.45 matthew 2485: =pod
2486:
1.648 raeburn 2487: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2488:
1.586 raeburn 2489: input: 4 arguments (two required, two optional) -
2490: $domain - domain of new user
2491: $name - name of form element
2492: $default - Value of 'default' causes a default item to be first
2493: option, and selected by default.
2494: $hide - Value of 'hide' causes hiding of the name of the server,
2495: if 1 server found, or default, if 0 found.
1.594 raeburn 2496: output: returns 2 items:
1.586 raeburn 2497: (a) form element which contains either:
2498: (i) <select name="$name">
2499: <option value="$hostid1">$hostid $servers{$hostid}</option>
2500: <option value="$hostid2">$hostid $servers{$hostid}</option>
2501: </select>
2502: form item if there are multiple library servers in $domain, or
2503: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2504: if there is only one library server in $domain.
2505:
2506: (b) number of library servers found.
2507:
2508: See loncreateuser.pm for example of use.
1.35 matthew 2509:
2510: =cut
2511:
2512: #-------------------------------------------
1.586 raeburn 2513: sub home_server_form_item {
2514: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2515: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2516: my $result;
2517: my $numlib = keys(%servers);
2518: if ($numlib > 1) {
2519: $result .= '<select name="'.$name.'" />'."\n";
2520: if ($default) {
1.804 bisitz 2521: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2522: '</option>'."\n";
2523: }
2524: foreach my $hostid (sort(keys(%servers))) {
2525: $result.= '<option value="'.$hostid.'">'.
2526: $hostid.' '.$servers{$hostid}."</option>\n";
2527: }
2528: $result .= '</select>'."\n";
2529: } elsif ($numlib == 1) {
2530: my $hostid;
2531: foreach my $item (keys(%servers)) {
2532: $hostid = $item;
2533: }
2534: $result .= '<input type="hidden" name="'.$name.'" value="'.
2535: $hostid.'" />';
2536: if (!$hide) {
2537: $result .= $hostid.' '.$servers{$hostid};
2538: }
2539: $result .= "\n";
2540: } elsif ($default) {
2541: $result .= '<input type="hidden" name="'.$name.
2542: '" value="default" />';
2543: if (!$hide) {
2544: $result .= &mt('default');
2545: }
2546: $result .= "\n";
1.33 matthew 2547: }
1.586 raeburn 2548: return ($result,$numlib);
1.33 matthew 2549: }
1.112 bowersj2 2550:
2551: =pod
2552:
1.534 albertel 2553: =back
2554:
1.112 bowersj2 2555: =cut
1.87 matthew 2556:
2557: ###############################################################
1.112 bowersj2 2558: ## Decoding User Agent ##
1.87 matthew 2559: ###############################################################
2560:
2561: =pod
2562:
1.112 bowersj2 2563: =head1 Decoding the User Agent
2564:
2565: =over 4
2566:
2567: =item * &decode_user_agent()
1.87 matthew 2568:
2569: Inputs: $r
2570:
2571: Outputs:
2572:
2573: =over 4
2574:
1.112 bowersj2 2575: =item * $httpbrowser
1.87 matthew 2576:
1.112 bowersj2 2577: =item * $clientbrowser
1.87 matthew 2578:
1.112 bowersj2 2579: =item * $clientversion
1.87 matthew 2580:
1.112 bowersj2 2581: =item * $clientmathml
1.87 matthew 2582:
1.112 bowersj2 2583: =item * $clientunicode
1.87 matthew 2584:
1.112 bowersj2 2585: =item * $clientos
1.87 matthew 2586:
1.1075.2.42 raeburn 2587: =item * $clientmobile
2588:
2589: =item * $clientinfo
2590:
1.1075.2.77 raeburn 2591: =item * $clientosversion
2592:
1.87 matthew 2593: =back
2594:
1.157 matthew 2595: =back
2596:
1.87 matthew 2597: =cut
2598:
2599: ###############################################################
2600: ###############################################################
2601: sub decode_user_agent {
1.247 albertel 2602: my ($r)=@_;
1.87 matthew 2603: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2604: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2605: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2606: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2607: my $clientbrowser='unknown';
2608: my $clientversion='0';
2609: my $clientmathml='';
2610: my $clientunicode='0';
1.1075.2.42 raeburn 2611: my $clientmobile=0;
1.1075.2.77 raeburn 2612: my $clientosversion='';
1.87 matthew 2613: for (my $i=0;$i<=$#browsertype;$i++) {
1.1075.2.76 raeburn 2614: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2615: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2616: $clientbrowser=$bname;
2617: $httpbrowser=~/$vreg/i;
2618: $clientversion=$1;
2619: $clientmathml=($clientversion>=$minv);
2620: $clientunicode=($clientversion>=$univ);
2621: }
2622: }
2623: my $clientos='unknown';
1.1075.2.42 raeburn 2624: my $clientinfo;
1.87 matthew 2625: if (($httpbrowser=~/linux/i) ||
2626: ($httpbrowser=~/unix/i) ||
2627: ($httpbrowser=~/ux/i) ||
2628: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2629: if (($httpbrowser=~/vax/i) ||
2630: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2631: if ($httpbrowser=~/next/i) { $clientos='next'; }
2632: if (($httpbrowser=~/mac/i) ||
2633: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1075.2.77 raeburn 2634: if ($httpbrowser=~/win/i) {
2635: $clientos='win';
2636: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2637: $clientosversion = $1;
2638: }
2639: }
1.87 matthew 2640: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2641: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2642: $clientmobile=lc($1);
2643: }
2644: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2645: $clientinfo = 'firefox-'.$1;
2646: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2647: $clientinfo = 'chromeframe-'.$1;
2648: }
1.87 matthew 2649: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.77 raeburn 2650: $clientunicode,$clientos,$clientmobile,$clientinfo,
2651: $clientosversion);
1.87 matthew 2652: }
2653:
1.32 matthew 2654: ###############################################################
2655: ## Authentication changing form generation subroutines ##
2656: ###############################################################
2657: ##
2658: ## All of the authform_xxxxxxx subroutines take their inputs in a
2659: ## hash, and have reasonable default values.
2660: ##
2661: ## formname = the name given in the <form> tag.
1.35 matthew 2662: #-------------------------------------------
2663:
1.45 matthew 2664: =pod
2665:
1.112 bowersj2 2666: =head1 Authentication Routines
2667:
2668: =over 4
2669:
1.648 raeburn 2670: =item * &authform_xxxxxx()
1.35 matthew 2671:
2672: The authform_xxxxxx subroutines provide javascript and html forms which
2673: handle some of the conveniences required for authentication forms.
2674: This is not an optimal method, but it works.
2675:
2676: =over 4
2677:
1.112 bowersj2 2678: =item * authform_header
1.35 matthew 2679:
1.112 bowersj2 2680: =item * authform_authorwarning
1.35 matthew 2681:
1.112 bowersj2 2682: =item * authform_nochange
1.35 matthew 2683:
1.112 bowersj2 2684: =item * authform_kerberos
1.35 matthew 2685:
1.112 bowersj2 2686: =item * authform_internal
1.35 matthew 2687:
1.112 bowersj2 2688: =item * authform_filesystem
1.35 matthew 2689:
2690: =back
2691:
1.648 raeburn 2692: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2693:
1.35 matthew 2694: =cut
2695:
2696: #-------------------------------------------
1.32 matthew 2697: sub authform_header{
2698: my %in = (
2699: formname => 'cu',
1.80 albertel 2700: kerb_def_dom => '',
1.32 matthew 2701: @_,
2702: );
2703: $in{'formname'} = 'document.' . $in{'formname'};
2704: my $result='';
1.80 albertel 2705:
2706: #---------------------------------------------- Code for upper case translation
2707: my $Javascript_toUpperCase;
2708: unless ($in{kerb_def_dom}) {
2709: $Javascript_toUpperCase =<<"END";
2710: switch (choice) {
2711: case 'krb': currentform.elements[choicearg].value =
2712: currentform.elements[choicearg].value.toUpperCase();
2713: break;
2714: default:
2715: }
2716: END
2717: } else {
2718: $Javascript_toUpperCase = "";
2719: }
2720:
1.165 raeburn 2721: my $radioval = "'nochange'";
1.591 raeburn 2722: if (defined($in{'curr_authtype'})) {
2723: if ($in{'curr_authtype'} ne '') {
2724: $radioval = "'".$in{'curr_authtype'}."arg'";
2725: }
1.174 matthew 2726: }
1.165 raeburn 2727: my $argfield = 'null';
1.591 raeburn 2728: if (defined($in{'mode'})) {
1.165 raeburn 2729: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2730: if (defined($in{'curr_autharg'})) {
2731: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2732: $argfield = "'$in{'curr_autharg'}'";
2733: }
2734: }
2735: }
2736: }
2737:
1.32 matthew 2738: $result.=<<"END";
2739: var current = new Object();
1.165 raeburn 2740: current.radiovalue = $radioval;
2741: current.argfield = $argfield;
1.32 matthew 2742:
2743: function changed_radio(choice,currentform) {
2744: var choicearg = choice + 'arg';
2745: // If a radio button in changed, we need to change the argfield
2746: if (current.radiovalue != choice) {
2747: current.radiovalue = choice;
2748: if (current.argfield != null) {
2749: currentform.elements[current.argfield].value = '';
2750: }
2751: if (choice == 'nochange') {
2752: current.argfield = null;
2753: } else {
2754: current.argfield = choicearg;
2755: switch(choice) {
2756: case 'krb':
2757: currentform.elements[current.argfield].value =
2758: "$in{'kerb_def_dom'}";
2759: break;
2760: default:
2761: break;
2762: }
2763: }
2764: }
2765: return;
2766: }
1.22 www 2767:
1.32 matthew 2768: function changed_text(choice,currentform) {
2769: var choicearg = choice + 'arg';
2770: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2771: $Javascript_toUpperCase
1.32 matthew 2772: // clear old field
2773: if ((current.argfield != choicearg) && (current.argfield != null)) {
2774: currentform.elements[current.argfield].value = '';
2775: }
2776: current.argfield = choicearg;
2777: }
2778: set_auth_radio_buttons(choice,currentform);
2779: return;
1.20 www 2780: }
1.32 matthew 2781:
2782: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2783: var numauthchoices = currentform.login.length;
2784: if (typeof numauthchoices == "undefined") {
2785: return;
2786: }
1.32 matthew 2787: var i=0;
1.986 raeburn 2788: while (i < numauthchoices) {
1.32 matthew 2789: if (currentform.login[i].value == newvalue) { break; }
2790: i++;
2791: }
1.986 raeburn 2792: if (i == numauthchoices) {
1.32 matthew 2793: return;
2794: }
2795: current.radiovalue = newvalue;
2796: currentform.login[i].checked = true;
2797: return;
2798: }
2799: END
2800: return $result;
2801: }
2802:
1.1075.2.20 raeburn 2803: sub authform_authorwarning {
1.32 matthew 2804: my $result='';
1.144 matthew 2805: $result='<i>'.
2806: &mt('As a general rule, only authors or co-authors should be '.
2807: 'filesystem authenticated '.
2808: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2809: return $result;
2810: }
2811:
1.1075.2.20 raeburn 2812: sub authform_nochange {
1.32 matthew 2813: my %in = (
2814: formname => 'document.cu',
2815: kerb_def_dom => 'MSU.EDU',
2816: @_,
2817: );
1.1075.2.20 raeburn 2818: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2819: my $result;
1.1075.2.20 raeburn 2820: if (!$authnum) {
2821: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2822: } else {
2823: $result = '<label>'.&mt('[_1] Do not change login data',
2824: '<input type="radio" name="login" value="nochange" '.
2825: 'checked="checked" onclick="'.
1.281 albertel 2826: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2827: '</label>';
1.586 raeburn 2828: }
1.32 matthew 2829: return $result;
2830: }
2831:
1.591 raeburn 2832: sub authform_kerberos {
1.32 matthew 2833: my %in = (
2834: formname => 'document.cu',
2835: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2836: kerb_def_auth => 'krb4',
1.32 matthew 2837: @_,
2838: );
1.586 raeburn 2839: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2840: $autharg,$jscall);
1.1075.2.20 raeburn 2841: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2842: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2843: $check5 = ' checked="checked"';
1.80 albertel 2844: } else {
1.772 bisitz 2845: $check4 = ' checked="checked"';
1.80 albertel 2846: }
1.165 raeburn 2847: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2848: if (defined($in{'curr_authtype'})) {
2849: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2850: $krbcheck = ' checked="checked"';
1.623 raeburn 2851: if (defined($in{'mode'})) {
2852: if ($in{'mode'} eq 'modifyuser') {
2853: $krbcheck = '';
2854: }
2855: }
1.591 raeburn 2856: if (defined($in{'curr_kerb_ver'})) {
2857: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2858: $check5 = ' checked="checked"';
1.591 raeburn 2859: $check4 = '';
2860: } else {
1.772 bisitz 2861: $check4 = ' checked="checked"';
1.591 raeburn 2862: $check5 = '';
2863: }
1.586 raeburn 2864: }
1.591 raeburn 2865: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2866: $krbarg = $in{'curr_autharg'};
2867: }
1.586 raeburn 2868: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2869: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2870: $result =
2871: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2872: $in{'curr_autharg'},$krbver);
2873: } else {
2874: $result =
2875: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2876: }
2877: return $result;
2878: }
2879: }
2880: } else {
2881: if ($authnum == 1) {
1.784 bisitz 2882: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2883: }
2884: }
1.586 raeburn 2885: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2886: return;
1.587 raeburn 2887: } elsif ($authtype eq '') {
1.591 raeburn 2888: if (defined($in{'mode'})) {
1.587 raeburn 2889: if ($in{'mode'} eq 'modifycourse') {
2890: if ($authnum == 1) {
1.1075.2.20 raeburn 2891: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2892: }
2893: }
2894: }
1.586 raeburn 2895: }
2896: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2897: if ($authtype eq '') {
2898: $authtype = '<input type="radio" name="login" value="krb" '.
2899: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2900: $krbcheck.' />';
2901: }
2902: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2903: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2904: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2905: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2906: $in{'curr_authtype'} eq 'krb4')) {
2907: $result .= &mt
1.144 matthew 2908: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2909: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2910: '<label>'.$authtype,
1.281 albertel 2911: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2912: 'value="'.$krbarg.'" '.
1.144 matthew 2913: 'onchange="'.$jscall.'" />',
1.281 albertel 2914: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2915: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2916: '</label>');
1.586 raeburn 2917: } elsif ($can_assign{'krb4'}) {
2918: $result .= &mt
2919: ('[_1] Kerberos authenticated with domain [_2] '.
2920: '[_3] Version 4 [_4]',
2921: '<label>'.$authtype,
2922: '</label><input type="text" size="10" name="krbarg" '.
2923: 'value="'.$krbarg.'" '.
2924: 'onchange="'.$jscall.'" />',
2925: '<label><input type="hidden" name="krbver" value="4" />',
2926: '</label>');
2927: } elsif ($can_assign{'krb5'}) {
2928: $result .= &mt
2929: ('[_1] Kerberos authenticated with domain [_2] '.
2930: '[_3] Version 5 [_4]',
2931: '<label>'.$authtype,
2932: '</label><input type="text" size="10" name="krbarg" '.
2933: 'value="'.$krbarg.'" '.
2934: 'onchange="'.$jscall.'" />',
2935: '<label><input type="hidden" name="krbver" value="5" />',
2936: '</label>');
2937: }
1.32 matthew 2938: return $result;
2939: }
2940:
1.1075.2.20 raeburn 2941: sub authform_internal {
1.586 raeburn 2942: my %in = (
1.32 matthew 2943: formname => 'document.cu',
2944: kerb_def_dom => 'MSU.EDU',
2945: @_,
2946: );
1.586 raeburn 2947: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 2948: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2949: if (defined($in{'curr_authtype'})) {
2950: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2951: if ($can_assign{'int'}) {
1.772 bisitz 2952: $intcheck = 'checked="checked" ';
1.623 raeburn 2953: if (defined($in{'mode'})) {
2954: if ($in{'mode'} eq 'modifyuser') {
2955: $intcheck = '';
2956: }
2957: }
1.591 raeburn 2958: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2959: $intarg = $in{'curr_autharg'};
2960: }
2961: } else {
2962: $result = &mt('Currently internally authenticated.');
2963: return $result;
1.165 raeburn 2964: }
2965: }
1.586 raeburn 2966: } else {
2967: if ($authnum == 1) {
1.784 bisitz 2968: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2969: }
2970: }
2971: if (!$can_assign{'int'}) {
2972: return;
1.587 raeburn 2973: } elsif ($authtype eq '') {
1.591 raeburn 2974: if (defined($in{'mode'})) {
1.587 raeburn 2975: if ($in{'mode'} eq 'modifycourse') {
2976: if ($authnum == 1) {
1.1075.2.20 raeburn 2977: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2978: }
2979: }
2980: }
1.165 raeburn 2981: }
1.586 raeburn 2982: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2983: if ($authtype eq '') {
2984: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2985: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2986: }
1.605 bisitz 2987: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2988: $intarg.'" onchange="'.$jscall.'" />';
2989: $result = &mt
1.144 matthew 2990: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2991: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2992: $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 2993: return $result;
2994: }
2995:
1.1075.2.20 raeburn 2996: sub authform_local {
1.32 matthew 2997: my %in = (
2998: formname => 'document.cu',
2999: kerb_def_dom => 'MSU.EDU',
3000: @_,
3001: );
1.586 raeburn 3002: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 3003: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 3004: if (defined($in{'curr_authtype'})) {
3005: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3006: if ($can_assign{'loc'}) {
1.772 bisitz 3007: $loccheck = 'checked="checked" ';
1.623 raeburn 3008: if (defined($in{'mode'})) {
3009: if ($in{'mode'} eq 'modifyuser') {
3010: $loccheck = '';
3011: }
3012: }
1.591 raeburn 3013: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3014: $locarg = $in{'curr_autharg'};
3015: }
3016: } else {
3017: $result = &mt('Currently using local (institutional) authentication.');
3018: return $result;
1.165 raeburn 3019: }
3020: }
1.586 raeburn 3021: } else {
3022: if ($authnum == 1) {
1.784 bisitz 3023: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3024: }
3025: }
3026: if (!$can_assign{'loc'}) {
3027: return;
1.587 raeburn 3028: } elsif ($authtype eq '') {
1.591 raeburn 3029: if (defined($in{'mode'})) {
1.587 raeburn 3030: if ($in{'mode'} eq 'modifycourse') {
3031: if ($authnum == 1) {
1.1075.2.20 raeburn 3032: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 3033: }
3034: }
3035: }
1.165 raeburn 3036: }
1.586 raeburn 3037: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3038: if ($authtype eq '') {
3039: $authtype = '<input type="radio" name="login" value="loc" '.
3040: $loccheck.' onchange="'.$jscall.'" onclick="'.
3041: $jscall.'" />';
3042: }
3043: $autharg = '<input type="text" size="10" name="locarg" value="'.
3044: $locarg.'" onchange="'.$jscall.'" />';
3045: $result = &mt('[_1] Local Authentication with argument [_2]',
3046: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3047: return $result;
3048: }
3049:
1.1075.2.20 raeburn 3050: sub authform_filesystem {
1.32 matthew 3051: my %in = (
3052: formname => 'document.cu',
3053: kerb_def_dom => 'MSU.EDU',
3054: @_,
3055: );
1.586 raeburn 3056: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1075.2.20 raeburn 3057: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 3058: if (defined($in{'curr_authtype'})) {
3059: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3060: if ($can_assign{'fsys'}) {
1.772 bisitz 3061: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3062: if (defined($in{'mode'})) {
3063: if ($in{'mode'} eq 'modifyuser') {
3064: $fsyscheck = '';
3065: }
3066: }
1.586 raeburn 3067: } else {
3068: $result = &mt('Currently Filesystem Authenticated.');
3069: return $result;
3070: }
3071: }
3072: } else {
3073: if ($authnum == 1) {
1.784 bisitz 3074: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3075: }
3076: }
3077: if (!$can_assign{'fsys'}) {
3078: return;
1.587 raeburn 3079: } elsif ($authtype eq '') {
1.591 raeburn 3080: if (defined($in{'mode'})) {
1.587 raeburn 3081: if ($in{'mode'} eq 'modifycourse') {
3082: if ($authnum == 1) {
1.1075.2.20 raeburn 3083: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 3084: }
3085: }
3086: }
1.586 raeburn 3087: }
3088: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3089: if ($authtype eq '') {
3090: $authtype = '<input type="radio" name="login" value="fsys" '.
3091: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
3092: $jscall.'" />';
3093: }
3094: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
3095: ' onchange="'.$jscall.'" />';
3096: $result = &mt
1.144 matthew 3097: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 3098: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 3099: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 3100: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 3101: 'onchange="'.$jscall.'" />');
1.32 matthew 3102: return $result;
3103: }
3104:
1.586 raeburn 3105: sub get_assignable_auth {
3106: my ($dom) = @_;
3107: if ($dom eq '') {
3108: $dom = $env{'request.role.domain'};
3109: }
3110: my %can_assign = (
3111: krb4 => 1,
3112: krb5 => 1,
3113: int => 1,
3114: loc => 1,
3115: );
3116: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3117: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3118: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3119: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3120: my $context;
3121: if ($env{'request.role'} =~ /^au/) {
3122: $context = 'author';
3123: } elsif ($env{'request.role'} =~ /^dc/) {
3124: $context = 'domain';
3125: } elsif ($env{'request.course.id'}) {
3126: $context = 'course';
3127: }
3128: if ($context) {
3129: if (ref($authhash->{$context}) eq 'HASH') {
3130: %can_assign = %{$authhash->{$context}};
3131: }
3132: }
3133: }
3134: }
3135: my $authnum = 0;
3136: foreach my $key (keys(%can_assign)) {
3137: if ($can_assign{$key}) {
3138: $authnum ++;
3139: }
3140: }
3141: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3142: $authnum --;
3143: }
3144: return ($authnum,%can_assign);
3145: }
3146:
1.80 albertel 3147: ###############################################################
3148: ## Get Kerberos Defaults for Domain ##
3149: ###############################################################
3150: ##
3151: ## Returns default kerberos version and an associated argument
3152: ## as listed in file domain.tab. If not listed, provides
3153: ## appropriate default domain and kerberos version.
3154: ##
3155: #-------------------------------------------
3156:
3157: =pod
3158:
1.648 raeburn 3159: =item * &get_kerberos_defaults()
1.80 albertel 3160:
3161: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3162: version and domain. If not found, it defaults to version 4 and the
3163: domain of the server.
1.80 albertel 3164:
1.648 raeburn 3165: =over 4
3166:
1.80 albertel 3167: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3168:
1.648 raeburn 3169: =back
3170:
3171: =back
3172:
1.80 albertel 3173: =cut
3174:
3175: #-------------------------------------------
3176: sub get_kerberos_defaults {
3177: my $domain=shift;
1.641 raeburn 3178: my ($krbdef,$krbdefdom);
3179: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3180: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3181: $krbdef = $domdefaults{'auth_def'};
3182: $krbdefdom = $domdefaults{'auth_arg_def'};
3183: } else {
1.80 albertel 3184: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3185: my $krbdefdom=$1;
3186: $krbdefdom=~tr/a-z/A-Z/;
3187: $krbdef = "krb4";
3188: }
3189: return ($krbdef,$krbdefdom);
3190: }
1.112 bowersj2 3191:
1.32 matthew 3192:
1.46 matthew 3193: ###############################################################
3194: ## Thesaurus Functions ##
3195: ###############################################################
1.20 www 3196:
1.46 matthew 3197: =pod
1.20 www 3198:
1.112 bowersj2 3199: =head1 Thesaurus Functions
3200:
3201: =over 4
3202:
1.648 raeburn 3203: =item * &initialize_keywords()
1.46 matthew 3204:
3205: Initializes the package variable %Keywords if it is empty. Uses the
3206: package variable $thesaurus_db_file.
3207:
3208: =cut
3209:
3210: ###################################################
3211:
3212: sub initialize_keywords {
3213: return 1 if (scalar keys(%Keywords));
3214: # If we are here, %Keywords is empty, so fill it up
3215: # Make sure the file we need exists...
3216: if (! -e $thesaurus_db_file) {
3217: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3218: " failed because it does not exist");
3219: return 0;
3220: }
3221: # Set up the hash as a database
3222: my %thesaurus_db;
3223: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3224: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3225: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3226: $thesaurus_db_file);
3227: return 0;
3228: }
3229: # Get the average number of appearances of a word.
3230: my $avecount = $thesaurus_db{'average.count'};
3231: # Put keywords (those that appear > average) into %Keywords
3232: while (my ($word,$data)=each (%thesaurus_db)) {
3233: my ($count,undef) = split /:/,$data;
3234: $Keywords{$word}++ if ($count > $avecount);
3235: }
3236: untie %thesaurus_db;
3237: # Remove special values from %Keywords.
1.356 albertel 3238: foreach my $value ('total.count','average.count') {
3239: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3240: }
1.46 matthew 3241: return 1;
3242: }
3243:
3244: ###################################################
3245:
3246: =pod
3247:
1.648 raeburn 3248: =item * &keyword($word)
1.46 matthew 3249:
3250: Returns true if $word is a keyword. A keyword is a word that appears more
3251: than the average number of times in the thesaurus database. Calls
3252: &initialize_keywords
3253:
3254: =cut
3255:
3256: ###################################################
1.20 www 3257:
3258: sub keyword {
1.46 matthew 3259: return if (!&initialize_keywords());
3260: my $word=lc(shift());
3261: $word=~s/\W//g;
3262: return exists($Keywords{$word});
1.20 www 3263: }
1.46 matthew 3264:
3265: ###############################################################
3266:
3267: =pod
1.20 www 3268:
1.648 raeburn 3269: =item * &get_related_words()
1.46 matthew 3270:
1.160 matthew 3271: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3272: an array of words. If the keyword is not in the thesaurus, an empty array
3273: will be returned. The order of the words returned is determined by the
3274: database which holds them.
3275:
3276: Uses global $thesaurus_db_file.
3277:
1.1057 foxr 3278:
1.46 matthew 3279: =cut
3280:
3281: ###############################################################
3282: sub get_related_words {
3283: my $keyword = shift;
3284: my %thesaurus_db;
3285: if (! -e $thesaurus_db_file) {
3286: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3287: "failed because the file does not exist");
3288: return ();
3289: }
3290: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3291: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3292: return ();
3293: }
3294: my @Words=();
1.429 www 3295: my $count=0;
1.46 matthew 3296: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3297: # The first element is the number of times
3298: # the word appears. We do not need it now.
1.429 www 3299: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3300: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3301: my $threshold=$mostfrequentcount/10;
3302: foreach my $possibleword (@RelatedWords) {
3303: my ($word,$wordcount)=split(/\,/,$possibleword);
3304: if ($wordcount>$threshold) {
3305: push(@Words,$word);
3306: $count++;
3307: if ($count>10) { last; }
3308: }
1.20 www 3309: }
3310: }
1.46 matthew 3311: untie %thesaurus_db;
3312: return @Words;
1.14 harris41 3313: }
1.46 matthew 3314:
1.112 bowersj2 3315: =pod
3316:
3317: =back
3318:
3319: =cut
1.61 www 3320:
3321: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3322: =pod
3323:
1.112 bowersj2 3324: =head1 User Name Functions
3325:
3326: =over 4
3327:
1.648 raeburn 3328: =item * &plainname($uname,$udom,$first)
1.81 albertel 3329:
1.112 bowersj2 3330: Takes a users logon name and returns it as a string in
1.226 albertel 3331: "first middle last generation" form
3332: if $first is set to 'lastname' then it returns it as
3333: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3334:
3335: =cut
1.61 www 3336:
1.295 www 3337:
1.81 albertel 3338: ###############################################################
1.61 www 3339: sub plainname {
1.226 albertel 3340: my ($uname,$udom,$first)=@_;
1.537 albertel 3341: return if (!defined($uname) || !defined($udom));
1.295 www 3342: my %names=&getnames($uname,$udom);
1.226 albertel 3343: my $name=&Apache::lonnet::format_name($names{'firstname'},
3344: $names{'middlename'},
3345: $names{'lastname'},
3346: $names{'generation'},$first);
3347: $name=~s/^\s+//;
1.62 www 3348: $name=~s/\s+$//;
3349: $name=~s/\s+/ /g;
1.353 albertel 3350: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3351: return $name;
1.61 www 3352: }
1.66 www 3353:
3354: # -------------------------------------------------------------------- Nickname
1.81 albertel 3355: =pod
3356:
1.648 raeburn 3357: =item * &nickname($uname,$udom)
1.81 albertel 3358:
3359: Gets a users name and returns it as a string as
3360:
3361: ""nickname""
1.66 www 3362:
1.81 albertel 3363: if the user has a nickname or
3364:
3365: "first middle last generation"
3366:
3367: if the user does not
3368:
3369: =cut
1.66 www 3370:
3371: sub nickname {
3372: my ($uname,$udom)=@_;
1.537 albertel 3373: return if (!defined($uname) || !defined($udom));
1.295 www 3374: my %names=&getnames($uname,$udom);
1.68 albertel 3375: my $name=$names{'nickname'};
1.66 www 3376: if ($name) {
3377: $name='"'.$name.'"';
3378: } else {
3379: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3380: $names{'lastname'}.' '.$names{'generation'};
3381: $name=~s/\s+$//;
3382: $name=~s/\s+/ /g;
3383: }
3384: return $name;
3385: }
3386:
1.295 www 3387: sub getnames {
3388: my ($uname,$udom)=@_;
1.537 albertel 3389: return if (!defined($uname) || !defined($udom));
1.433 albertel 3390: if ($udom eq 'public' && $uname eq 'public') {
3391: return ('lastname' => &mt('Public'));
3392: }
1.295 www 3393: my $id=$uname.':'.$udom;
3394: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3395: if ($cached) {
3396: return %{$names};
3397: } else {
3398: my %loadnames=&Apache::lonnet::get('environment',
3399: ['firstname','middlename','lastname','generation','nickname'],
3400: $udom,$uname);
3401: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3402: return %loadnames;
3403: }
3404: }
1.61 www 3405:
1.542 raeburn 3406: # -------------------------------------------------------------------- getemails
1.648 raeburn 3407:
1.542 raeburn 3408: =pod
3409:
1.648 raeburn 3410: =item * &getemails($uname,$udom)
1.542 raeburn 3411:
3412: Gets a user's email information and returns it as a hash with keys:
3413: notification, critnotification, permanentemail
3414:
3415: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3416: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3417:
1.648 raeburn 3418:
1.542 raeburn 3419: =cut
3420:
1.648 raeburn 3421:
1.466 albertel 3422: sub getemails {
3423: my ($uname,$udom)=@_;
3424: if ($udom eq 'public' && $uname eq 'public') {
3425: return;
3426: }
1.467 www 3427: if (!$udom) { $udom=$env{'user.domain'}; }
3428: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3429: my $id=$uname.':'.$udom;
3430: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3431: if ($cached) {
3432: return %{$names};
3433: } else {
3434: my %loadnames=&Apache::lonnet::get('environment',
3435: ['notification','critnotification',
3436: 'permanentemail'],
3437: $udom,$uname);
3438: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3439: return %loadnames;
3440: }
3441: }
3442:
1.551 albertel 3443: sub flush_email_cache {
3444: my ($uname,$udom)=@_;
3445: if (!$udom) { $udom =$env{'user.domain'}; }
3446: if (!$uname) { $uname=$env{'user.name'}; }
3447: return if ($udom eq 'public' && $uname eq 'public');
3448: my $id=$uname.':'.$udom;
3449: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3450: }
3451:
1.728 raeburn 3452: # -------------------------------------------------------------------- getlangs
3453:
3454: =pod
3455:
3456: =item * &getlangs($uname,$udom)
3457:
3458: Gets a user's language preference and returns it as a hash with key:
3459: language.
3460:
3461: =cut
3462:
3463:
3464: sub getlangs {
3465: my ($uname,$udom) = @_;
3466: if (!$udom) { $udom =$env{'user.domain'}; }
3467: if (!$uname) { $uname=$env{'user.name'}; }
3468: my $id=$uname.':'.$udom;
3469: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3470: if ($cached) {
3471: return %{$langs};
3472: } else {
3473: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3474: $udom,$uname);
3475: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3476: return %loadlangs;
3477: }
3478: }
3479:
3480: sub flush_langs_cache {
3481: my ($uname,$udom)=@_;
3482: if (!$udom) { $udom =$env{'user.domain'}; }
3483: if (!$uname) { $uname=$env{'user.name'}; }
3484: return if ($udom eq 'public' && $uname eq 'public');
3485: my $id=$uname.':'.$udom;
3486: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3487: }
3488:
1.61 www 3489: # ------------------------------------------------------------------ Screenname
1.81 albertel 3490:
3491: =pod
3492:
1.648 raeburn 3493: =item * &screenname($uname,$udom)
1.81 albertel 3494:
3495: Gets a users screenname and returns it as a string
3496:
3497: =cut
1.61 www 3498:
3499: sub screenname {
3500: my ($uname,$udom)=@_;
1.258 albertel 3501: if ($uname eq $env{'user.name'} &&
3502: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3503: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3504: return $names{'screenname'};
1.62 www 3505: }
3506:
1.212 albertel 3507:
1.802 bisitz 3508: # ------------------------------------------------------------- Confirm Wrapper
3509: =pod
3510:
1.1075.2.42 raeburn 3511: =item * &confirmwrapper($message)
1.802 bisitz 3512:
3513: Wrap messages about completion of operation in box
3514:
3515: =cut
3516:
3517: sub confirmwrapper {
3518: my ($message)=@_;
3519: if ($message) {
3520: return "\n".'<div class="LC_confirm_box">'."\n"
3521: .$message."\n"
3522: .'</div>'."\n";
3523: } else {
3524: return $message;
3525: }
3526: }
3527:
1.62 www 3528: # ------------------------------------------------------------- Message Wrapper
3529:
3530: sub messagewrapper {
1.369 www 3531: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3532: return
1.441 albertel 3533: '<a href="/adm/email?compose=individual&'.
3534: 'recname='.$username.'&recdom='.$domain.
3535: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3536: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3537: }
1.802 bisitz 3538:
1.74 www 3539: # --------------------------------------------------------------- Notes Wrapper
3540:
3541: sub noteswrapper {
3542: my ($link,$un,$do)=@_;
3543: return
1.896 amueller 3544: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3545: }
1.802 bisitz 3546:
1.62 www 3547: # ------------------------------------------------------------- Aboutme Wrapper
3548:
3549: sub aboutmewrapper {
1.1070 raeburn 3550: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3551: if (!defined($username) && !defined($domain)) {
3552: return;
3553: }
1.1075.2.15 raeburn 3554: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3555: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3556: }
3557:
3558: # ------------------------------------------------------------ Syllabus Wrapper
3559:
3560: sub syllabuswrapper {
1.707 bisitz 3561: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3562: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3563: }
1.14 harris41 3564:
1.802 bisitz 3565: # -----------------------------------------------------------------------------
3566:
1.208 matthew 3567: sub track_student_link {
1.887 raeburn 3568: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3569: my $link ="/adm/trackstudent?";
1.208 matthew 3570: my $title = 'View recent activity';
3571: if (defined($sname) && $sname !~ /^\s*$/ &&
3572: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3573: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3574: $title .= ' of this student';
1.268 albertel 3575: }
1.208 matthew 3576: if (defined($target) && $target !~ /^\s*$/) {
3577: $target = qq{target="$target"};
3578: } else {
3579: $target = '';
3580: }
1.268 albertel 3581: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3582: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3583: $title = &mt($title);
3584: $linktext = &mt($linktext);
1.448 albertel 3585: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3586: &help_open_topic('View_recent_activity');
1.208 matthew 3587: }
3588:
1.781 raeburn 3589: sub slot_reservations_link {
3590: my ($linktext,$sname,$sdom,$target) = @_;
3591: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3592: my $title = 'View slot reservation history';
3593: if (defined($sname) && $sname !~ /^\s*$/ &&
3594: defined($sdom) && $sdom !~ /^\s*$/) {
3595: $link .= "&uname=$sname&udom=$sdom";
3596: $title .= ' of this student';
3597: }
3598: if (defined($target) && $target !~ /^\s*$/) {
3599: $target = qq{target="$target"};
3600: } else {
3601: $target = '';
3602: }
3603: $title = &mt($title);
3604: $linktext = &mt($linktext);
3605: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3606: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3607:
3608: }
3609:
1.508 www 3610: # ===================================================== Display a student photo
3611:
3612:
1.509 albertel 3613: sub student_image_tag {
1.508 www 3614: my ($domain,$user)=@_;
3615: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3616: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3617: return '<img src="'.$imgsrc.'" align="right" />';
3618: } else {
3619: return '';
3620: }
3621: }
3622:
1.112 bowersj2 3623: =pod
3624:
3625: =back
3626:
3627: =head1 Access .tab File Data
3628:
3629: =over 4
3630:
1.648 raeburn 3631: =item * &languageids()
1.112 bowersj2 3632:
3633: returns list of all language ids
3634:
3635: =cut
3636:
1.14 harris41 3637: sub languageids {
1.16 harris41 3638: return sort(keys(%language));
1.14 harris41 3639: }
3640:
1.112 bowersj2 3641: =pod
3642:
1.648 raeburn 3643: =item * &languagedescription()
1.112 bowersj2 3644:
3645: returns description of a specified language id
3646:
3647: =cut
3648:
1.14 harris41 3649: sub languagedescription {
1.125 www 3650: my $code=shift;
3651: return ($supported_language{$code}?'* ':'').
3652: $language{$code}.
1.126 www 3653: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3654: }
3655:
1.1048 foxr 3656: =pod
3657:
3658: =item * &plainlanguagedescription
3659:
3660: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3661: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3662:
3663: =cut
3664:
1.145 www 3665: sub plainlanguagedescription {
3666: my $code=shift;
3667: return $language{$code};
3668: }
3669:
1.1048 foxr 3670: =pod
3671:
3672: =item * &supportedlanguagecode
3673:
3674: Returns the supported language code (e.g. sptutf maps to pt) given a language
3675: code.
3676:
3677: =cut
3678:
1.145 www 3679: sub supportedlanguagecode {
3680: my $code=shift;
3681: return $supported_language{$code};
1.97 www 3682: }
3683:
1.112 bowersj2 3684: =pod
3685:
1.1048 foxr 3686: =item * &latexlanguage()
3687:
3688: Given a language key code returns the correspondnig language to use
3689: to select the correct hyphenation on LaTeX printouts. This is undef if there
3690: is no supported hyphenation for the language code.
3691:
3692: =cut
3693:
3694: sub latexlanguage {
3695: my $code = shift;
3696: return $latex_language{$code};
3697: }
3698:
3699: =pod
3700:
3701: =item * &latexhyphenation()
3702:
3703: Same as above but what's supplied is the language as it might be stored
3704: in the metadata.
3705:
3706: =cut
3707:
3708: sub latexhyphenation {
3709: my $key = shift;
3710: return $latex_language_bykey{$key};
3711: }
3712:
3713: =pod
3714:
1.648 raeburn 3715: =item * ©rightids()
1.112 bowersj2 3716:
3717: returns list of all copyrights
3718:
3719: =cut
3720:
3721: sub copyrightids {
3722: return sort(keys(%cprtag));
3723: }
3724:
3725: =pod
3726:
1.648 raeburn 3727: =item * ©rightdescription()
1.112 bowersj2 3728:
3729: returns description of a specified copyright id
3730:
3731: =cut
3732:
3733: sub copyrightdescription {
1.166 www 3734: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3735: }
1.197 matthew 3736:
3737: =pod
3738:
1.648 raeburn 3739: =item * &source_copyrightids()
1.192 taceyjo1 3740:
3741: returns list of all source copyrights
3742:
3743: =cut
3744:
3745: sub source_copyrightids {
3746: return sort(keys(%scprtag));
3747: }
3748:
3749: =pod
3750:
1.648 raeburn 3751: =item * &source_copyrightdescription()
1.192 taceyjo1 3752:
3753: returns description of a specified source copyright id
3754:
3755: =cut
3756:
3757: sub source_copyrightdescription {
3758: return &mt($scprtag{shift(@_)});
3759: }
1.112 bowersj2 3760:
3761: =pod
3762:
1.648 raeburn 3763: =item * &filecategories()
1.112 bowersj2 3764:
3765: returns list of all file categories
3766:
3767: =cut
3768:
3769: sub filecategories {
3770: return sort(keys(%category_extensions));
3771: }
3772:
3773: =pod
3774:
1.648 raeburn 3775: =item * &filecategorytypes()
1.112 bowersj2 3776:
3777: returns list of file types belonging to a given file
3778: category
3779:
3780: =cut
3781:
3782: sub filecategorytypes {
1.356 albertel 3783: my ($cat) = @_;
3784: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3785: }
3786:
3787: =pod
3788:
1.648 raeburn 3789: =item * &fileembstyle()
1.112 bowersj2 3790:
3791: returns embedding style for a specified file type
3792:
3793: =cut
3794:
3795: sub fileembstyle {
3796: return $fe{lc(shift(@_))};
1.169 www 3797: }
3798:
1.351 www 3799: sub filemimetype {
3800: return $fm{lc(shift(@_))};
3801: }
3802:
1.169 www 3803:
3804: sub filecategoryselect {
3805: my ($name,$value)=@_;
1.189 matthew 3806: return &select_form($value,$name,
1.970 raeburn 3807: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3808: }
3809:
3810: =pod
3811:
1.648 raeburn 3812: =item * &filedescription()
1.112 bowersj2 3813:
3814: returns description for a specified file type
3815:
3816: =cut
3817:
3818: sub filedescription {
1.188 matthew 3819: my $file_description = $fd{lc(shift())};
3820: $file_description =~ s:([\[\]]):~$1:g;
3821: return &mt($file_description);
1.112 bowersj2 3822: }
3823:
3824: =pod
3825:
1.648 raeburn 3826: =item * &filedescriptionex()
1.112 bowersj2 3827:
3828: returns description for a specified file type with
3829: extra formatting
3830:
3831: =cut
3832:
3833: sub filedescriptionex {
3834: my $ex=shift;
1.188 matthew 3835: my $file_description = $fd{lc($ex)};
3836: $file_description =~ s:([\[\]]):~$1:g;
3837: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3838: }
3839:
3840: # End of .tab access
3841: =pod
3842:
3843: =back
3844:
3845: =cut
3846:
3847: # ------------------------------------------------------------------ File Types
3848: sub fileextensions {
3849: return sort(keys(%fe));
3850: }
3851:
1.97 www 3852: # ----------------------------------------------------------- Display Languages
3853: # returns a hash with all desired display languages
3854: #
3855:
3856: sub display_languages {
3857: my %languages=();
1.695 raeburn 3858: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3859: $languages{$lang}=1;
1.97 www 3860: }
3861: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3862: if ($env{'form.displaylanguage'}) {
1.356 albertel 3863: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3864: $languages{$lang}=1;
1.97 www 3865: }
3866: }
3867: return %languages;
1.14 harris41 3868: }
3869:
1.582 albertel 3870: sub languages {
3871: my ($possible_langs) = @_;
1.695 raeburn 3872: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3873: if (!ref($possible_langs)) {
3874: if( wantarray ) {
3875: return @preferred_langs;
3876: } else {
3877: return $preferred_langs[0];
3878: }
3879: }
3880: my %possibilities = map { $_ => 1 } (@$possible_langs);
3881: my @preferred_possibilities;
3882: foreach my $preferred_lang (@preferred_langs) {
3883: if (exists($possibilities{$preferred_lang})) {
3884: push(@preferred_possibilities, $preferred_lang);
3885: }
3886: }
3887: if( wantarray ) {
3888: return @preferred_possibilities;
3889: }
3890: return $preferred_possibilities[0];
3891: }
3892:
1.742 raeburn 3893: sub user_lang {
3894: my ($touname,$toudom,$fromcid) = @_;
3895: my @userlangs;
3896: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3897: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3898: $env{'course.'.$fromcid.'.languages'}));
3899: } else {
3900: my %langhash = &getlangs($touname,$toudom);
3901: if ($langhash{'languages'} ne '') {
3902: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3903: } else {
3904: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3905: if ($domdefs{'lang_def'} ne '') {
3906: @userlangs = ($domdefs{'lang_def'});
3907: }
3908: }
3909: }
3910: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3911: my $user_lh = Apache::localize->get_handle(@languages);
3912: return $user_lh;
3913: }
3914:
3915:
1.112 bowersj2 3916: ###############################################################
3917: ## Student Answer Attempts ##
3918: ###############################################################
3919:
3920: =pod
3921:
3922: =head1 Alternate Problem Views
3923:
3924: =over 4
3925:
1.648 raeburn 3926: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1075.2.86 raeburn 3927: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 3928:
3929: Return string with previous attempt on problem. Arguments:
3930:
3931: =over 4
3932:
3933: =item * $symb: Problem, including path
3934:
3935: =item * $username: username of the desired student
3936:
3937: =item * $domain: domain of the desired student
1.14 harris41 3938:
1.112 bowersj2 3939: =item * $course: Course ID
1.14 harris41 3940:
1.112 bowersj2 3941: =item * $getattempt: Leave blank for all attempts, otherwise put
3942: something
1.14 harris41 3943:
1.112 bowersj2 3944: =item * $regexp: if string matches this regexp, the string will be
3945: sent to $gradesub
1.14 harris41 3946:
1.112 bowersj2 3947: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3948:
1.1075.2.86 raeburn 3949: =item * $usec: section of the desired student
3950:
3951: =item * $identifier: counter for student (multiple students one problem) or
3952: problem (one student; whole sequence).
3953:
1.112 bowersj2 3954: =back
1.14 harris41 3955:
1.112 bowersj2 3956: The output string is a table containing all desired attempts, if any.
1.16 harris41 3957:
1.112 bowersj2 3958: =cut
1.1 albertel 3959:
3960: sub get_previous_attempt {
1.1075.2.86 raeburn 3961: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 3962: my $prevattempts='';
1.43 ng 3963: no strict 'refs';
1.1 albertel 3964: if ($symb) {
1.3 albertel 3965: my (%returnhash)=
3966: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3967: if ($returnhash{'version'}) {
3968: my %lasthash=();
3969: my $version;
3970: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.91 raeburn 3971: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
3972: if ($key =~ /\.rawrndseed$/) {
3973: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
3974: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
3975: } else {
3976: $lasthash{$key}=$returnhash{$version.':'.$key};
3977: }
1.19 harris41 3978: }
1.1 albertel 3979: }
1.596 albertel 3980: $prevattempts=&start_data_table().&start_data_table_header_row();
3981: $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86 raeburn 3982: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 3983: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3984: foreach my $key (sort(keys(%lasthash))) {
3985: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3986: if ($#parts > 0) {
1.31 albertel 3987: my $data=$parts[-1];
1.989 raeburn 3988: next if ($data eq 'foilorder');
1.31 albertel 3989: pop(@parts);
1.1010 www 3990: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3991: if ($data eq 'type') {
3992: unless ($showsurv) {
3993: my $id = join(',',@parts);
3994: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3995: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3996: $lasthidden{$ign.'.'.$id} = 1;
3997: }
1.945 raeburn 3998: }
1.1075.2.86 raeburn 3999: if ($identifier ne '') {
4000: my $id = join(',',@parts);
4001: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4002: $domain,$username,$usec,undef,$course) =~ /^no/) {
4003: $hidestatus{$ign.'.'.$id} = 1;
4004: }
4005: }
4006: } elsif ($data eq 'regrader') {
4007: if (($identifier ne '') && (@parts)) {
4008: my $id = join(',',@parts);
4009: $regraded{$ign.'.'.$id} = 1;
4010: }
1.1010 www 4011: }
1.31 albertel 4012: } else {
1.41 ng 4013: if ($#parts == 0) {
4014: $prevattempts.='<th>'.$parts[0].'</th>';
4015: } else {
4016: $prevattempts.='<th>'.$ign.'</th>';
4017: }
1.31 albertel 4018: }
1.16 harris41 4019: }
1.596 albertel 4020: $prevattempts.=&end_data_table_header_row();
1.40 ng 4021: if ($getattempt eq '') {
1.1075.2.86 raeburn 4022: my (%solved,%resets,%probstatus);
4023: if (($identifier ne '') && (keys(%regraded) > 0)) {
4024: for ($version=1;$version<=$returnhash{'version'};$version++) {
4025: foreach my $id (keys(%regraded)) {
4026: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4027: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4028: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4029: push(@{$resets{$id}},$version);
4030: }
4031: }
4032: }
4033: }
1.40 ng 4034: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86 raeburn 4035: my (@hidden,@unsolved);
1.945 raeburn 4036: if (%typeparts) {
4037: foreach my $id (keys(%typeparts)) {
1.1075.2.86 raeburn 4038: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4039: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4040: push(@hidden,$id);
1.1075.2.86 raeburn 4041: } elsif ($identifier ne '') {
4042: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4043: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4044: ($hidestatus{$id})) {
4045: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
4046: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4047: push(@{$solved{$id}},$version);
4048: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4049: (ref($solved{$id}) eq 'ARRAY')) {
4050: my $skip;
4051: if (ref($resets{$id}) eq 'ARRAY') {
4052: foreach my $reset (@{$resets{$id}}) {
4053: if ($reset > $solved{$id}[-1]) {
4054: $skip=1;
4055: last;
4056: }
4057: }
4058: }
4059: unless ($skip) {
4060: my ($ign,$partslist) = split(/\./,$id,2);
4061: push(@unsolved,$partslist);
4062: }
4063: }
4064: }
1.945 raeburn 4065: }
4066: }
4067: }
4068: $prevattempts.=&start_data_table_row().
1.1075.2.86 raeburn 4069: '<td>'.&mt('Transaction [_1]',$version);
4070: if (@unsolved) {
4071: $prevattempts .= '<span class="LC_nobreak"><label>'.
4072: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4073: &mt('Hide').'</label></span>';
4074: }
4075: $prevattempts .= '</td>';
1.945 raeburn 4076: if (@hidden) {
4077: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4078: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4079: my $hide;
4080: foreach my $id (@hidden) {
4081: if ($key =~ /^\Q$id\E/) {
4082: $hide = 1;
4083: last;
4084: }
4085: }
4086: if ($hide) {
4087: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4088: if (($data eq 'award') || ($data eq 'awarddetail')) {
4089: my $value = &format_previous_attempt_value($key,
4090: $returnhash{$version.':'.$key});
4091: $prevattempts.='<td>'.$value.' </td>';
4092: } else {
4093: $prevattempts.='<td> </td>';
4094: }
4095: } else {
4096: if ($key =~ /\./) {
1.1075.2.91 raeburn 4097: my $value = $returnhash{$version.':'.$key};
4098: if ($key =~ /\.rndseed$/) {
4099: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4100: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4101: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4102: }
4103: }
4104: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4105: ' </td>';
1.945 raeburn 4106: } else {
4107: $prevattempts.='<td> </td>';
4108: }
4109: }
4110: }
4111: } else {
4112: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4113: next if ($key =~ /\.foilorder$/);
1.1075.2.91 raeburn 4114: my $value = $returnhash{$version.':'.$key};
4115: if ($key =~ /\.rndseed$/) {
4116: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4117: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4118: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4119: }
4120: }
4121: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4122: ' </td>';
1.945 raeburn 4123: }
4124: }
4125: $prevattempts.=&end_data_table_row();
1.40 ng 4126: }
1.1 albertel 4127: }
1.945 raeburn 4128: my @currhidden = keys(%lasthidden);
1.596 albertel 4129: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4130: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4131: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4132: if (%typeparts) {
4133: my $hidden;
4134: foreach my $id (@currhidden) {
4135: if ($key =~ /^\Q$id\E/) {
4136: $hidden = 1;
4137: last;
4138: }
4139: }
4140: if ($hidden) {
4141: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4142: if (($data eq 'award') || ($data eq 'awarddetail')) {
4143: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4144: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4145: $value = &$gradesub($value);
4146: }
4147: $prevattempts.='<td>'.$value.' </td>';
4148: } else {
4149: $prevattempts.='<td> </td>';
4150: }
4151: } else {
4152: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4153: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4154: $value = &$gradesub($value);
4155: }
4156: $prevattempts.='<td>'.$value.' </td>';
4157: }
4158: } else {
4159: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4160: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4161: $value = &$gradesub($value);
4162: }
4163: $prevattempts.='<td>'.$value.' </td>';
4164: }
1.16 harris41 4165: }
1.596 albertel 4166: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4167: } else {
1.596 albertel 4168: $prevattempts=
4169: &start_data_table().&start_data_table_row().
4170: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4171: &end_data_table_row().&end_data_table();
1.1 albertel 4172: }
4173: } else {
1.596 albertel 4174: $prevattempts=
4175: &start_data_table().&start_data_table_row().
4176: '<td>'.&mt('No data.').'</td>'.
4177: &end_data_table_row().&end_data_table();
1.1 albertel 4178: }
1.10 albertel 4179: }
4180:
1.581 albertel 4181: sub format_previous_attempt_value {
4182: my ($key,$value) = @_;
1.1011 www 4183: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 4184: $value = &Apache::lonlocal::locallocaltime($value);
4185: } elsif (ref($value) eq 'ARRAY') {
4186: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 4187: } elsif ($key =~ /answerstring$/) {
4188: my %answers = &Apache::lonnet::str2hash($value);
4189: my @anskeys = sort(keys(%answers));
4190: if (@anskeys == 1) {
4191: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4192: if ($answer =~ m{\0}) {
4193: $answer =~ s{\0}{,}g;
1.988 raeburn 4194: }
4195: my $tag_internal_answer_name = 'INTERNAL';
4196: if ($anskeys[0] eq $tag_internal_answer_name) {
4197: $value = $answer;
4198: } else {
4199: $value = $anskeys[0].'='.$answer;
4200: }
4201: } else {
4202: foreach my $ans (@anskeys) {
4203: my $answer = $answers{$ans};
1.1001 raeburn 4204: if ($answer =~ m{\0}) {
4205: $answer =~ s{\0}{,}g;
1.988 raeburn 4206: }
4207: $value .= $ans.'='.$answer.'<br />';;
4208: }
4209: }
1.581 albertel 4210: } else {
4211: $value = &unescape($value);
4212: }
4213: return $value;
4214: }
4215:
4216:
1.107 albertel 4217: sub relative_to_absolute {
4218: my ($url,$output)=@_;
4219: my $parser=HTML::TokeParser->new(\$output);
4220: my $token;
4221: my $thisdir=$url;
4222: my @rlinks=();
4223: while ($token=$parser->get_token) {
4224: if ($token->[0] eq 'S') {
4225: if ($token->[1] eq 'a') {
4226: if ($token->[2]->{'href'}) {
4227: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4228: }
4229: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4230: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4231: } elsif ($token->[1] eq 'base') {
4232: $thisdir=$token->[2]->{'href'};
4233: }
4234: }
4235: }
4236: $thisdir=~s-/[^/]*$--;
1.356 albertel 4237: foreach my $link (@rlinks) {
1.726 raeburn 4238: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4239: ($link=~/^\//) ||
4240: ($link=~/^javascript:/i) ||
4241: ($link=~/^mailto:/i) ||
4242: ($link=~/^\#/)) {
4243: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4244: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4245: }
4246: }
4247: # -------------------------------------------------- Deal with Applet codebases
4248: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4249: return $output;
4250: }
4251:
1.112 bowersj2 4252: =pod
4253:
1.648 raeburn 4254: =item * &get_student_view()
1.112 bowersj2 4255:
4256: show a snapshot of what student was looking at
4257:
4258: =cut
4259:
1.10 albertel 4260: sub get_student_view {
1.186 albertel 4261: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4262: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4263: my (%form);
1.10 albertel 4264: my @elements=('symb','courseid','domain','username');
4265: foreach my $element (@elements) {
1.186 albertel 4266: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4267: }
1.186 albertel 4268: if (defined($moreenv)) {
4269: %form=(%form,%{$moreenv});
4270: }
1.236 albertel 4271: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4272: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4273: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4274: $userview=~s/\<body[^\>]*\>//gi;
4275: $userview=~s/\<\/body\>//gi;
4276: $userview=~s/\<html\>//gi;
4277: $userview=~s/\<\/html\>//gi;
4278: $userview=~s/\<head\>//gi;
4279: $userview=~s/\<\/head\>//gi;
4280: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4281: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4282: if (wantarray) {
4283: return ($userview,$response);
4284: } else {
4285: return $userview;
4286: }
4287: }
4288:
4289: sub get_student_view_with_retries {
4290: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4291:
4292: my $ok = 0; # True if we got a good response.
4293: my $content;
4294: my $response;
4295:
4296: # Try to get the student_view done. within the retries count:
4297:
4298: do {
4299: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4300: $ok = $response->is_success;
4301: if (!$ok) {
4302: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4303: }
4304: $retries--;
4305: } while (!$ok && ($retries > 0));
4306:
4307: if (!$ok) {
4308: $content = ''; # On error return an empty content.
4309: }
1.651 www 4310: if (wantarray) {
4311: return ($content, $response);
4312: } else {
4313: return $content;
4314: }
1.11 albertel 4315: }
4316:
1.112 bowersj2 4317: =pod
4318:
1.648 raeburn 4319: =item * &get_student_answers()
1.112 bowersj2 4320:
4321: show a snapshot of how student was answering problem
4322:
4323: =cut
4324:
1.11 albertel 4325: sub get_student_answers {
1.100 sakharuk 4326: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4327: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4328: my (%moreenv);
1.11 albertel 4329: my @elements=('symb','courseid','domain','username');
4330: foreach my $element (@elements) {
1.186 albertel 4331: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4332: }
1.186 albertel 4333: $moreenv{'grade_target'}='answer';
4334: %moreenv=(%form,%moreenv);
1.497 raeburn 4335: $feedurl = &Apache::lonnet::clutter($feedurl);
4336: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4337: return $userview;
1.1 albertel 4338: }
1.116 albertel 4339:
4340: =pod
4341:
4342: =item * &submlink()
4343:
1.242 albertel 4344: Inputs: $text $uname $udom $symb $target
1.116 albertel 4345:
4346: Returns: A link to grades.pm such as to see the SUBM view of a student
4347:
4348: =cut
4349:
4350: ###############################################
4351: sub submlink {
1.242 albertel 4352: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4353: if (!($uname && $udom)) {
4354: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4355: &Apache::lonnet::whichuser($symb);
1.116 albertel 4356: if (!$symb) { $symb=$cursymb; }
4357: }
1.254 matthew 4358: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4359: $symb=&escape($symb);
1.960 bisitz 4360: if ($target) { $target=" target=\"$target\""; }
4361: return
4362: '<a href="/adm/grades?command=submission'.
4363: '&symb='.$symb.
4364: '&student='.$uname.
4365: '&userdom='.$udom.'"'.
4366: $target.'>'.$text.'</a>';
1.242 albertel 4367: }
4368: ##############################################
4369:
4370: =pod
4371:
4372: =item * &pgrdlink()
4373:
4374: Inputs: $text $uname $udom $symb $target
4375:
4376: Returns: A link to grades.pm such as to see the PGRD view of a student
4377:
4378: =cut
4379:
4380: ###############################################
4381: sub pgrdlink {
4382: my $link=&submlink(@_);
4383: $link=~s/(&command=submission)/$1&showgrading=yes/;
4384: return $link;
4385: }
4386: ##############################################
4387:
4388: =pod
4389:
4390: =item * &pprmlink()
4391:
4392: Inputs: $text $uname $udom $symb $target
4393:
4394: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4395: student and a specific resource
1.242 albertel 4396:
4397: =cut
4398:
4399: ###############################################
4400: sub pprmlink {
4401: my ($text,$uname,$udom,$symb,$target)=@_;
4402: if (!($uname && $udom)) {
4403: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4404: &Apache::lonnet::whichuser($symb);
1.242 albertel 4405: if (!$symb) { $symb=$cursymb; }
4406: }
1.254 matthew 4407: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4408: $symb=&escape($symb);
1.242 albertel 4409: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4410: return '<a href="/adm/parmset?command=set&'.
4411: 'symb='.$symb.'&uname='.$uname.
4412: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4413: }
4414: ##############################################
1.37 matthew 4415:
1.112 bowersj2 4416: =pod
4417:
4418: =back
4419:
4420: =cut
4421:
1.37 matthew 4422: ###############################################
1.51 www 4423:
4424:
4425: sub timehash {
1.687 raeburn 4426: my ($thistime) = @_;
4427: my $timezone = &Apache::lonlocal::gettimezone();
4428: my $dt = DateTime->from_epoch(epoch => $thistime)
4429: ->set_time_zone($timezone);
4430: my $wday = $dt->day_of_week();
4431: if ($wday == 7) { $wday = 0; }
4432: return ( 'second' => $dt->second(),
4433: 'minute' => $dt->minute(),
4434: 'hour' => $dt->hour(),
4435: 'day' => $dt->day_of_month(),
4436: 'month' => $dt->month(),
4437: 'year' => $dt->year(),
4438: 'weekday' => $wday,
4439: 'dayyear' => $dt->day_of_year(),
4440: 'dlsav' => $dt->is_dst() );
1.51 www 4441: }
4442:
1.370 www 4443: sub utc_string {
4444: my ($date)=@_;
1.371 www 4445: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4446: }
4447:
1.51 www 4448: sub maketime {
4449: my %th=@_;
1.687 raeburn 4450: my ($epoch_time,$timezone,$dt);
4451: $timezone = &Apache::lonlocal::gettimezone();
4452: eval {
4453: $dt = DateTime->new( year => $th{'year'},
4454: month => $th{'month'},
4455: day => $th{'day'},
4456: hour => $th{'hour'},
4457: minute => $th{'minute'},
4458: second => $th{'second'},
4459: time_zone => $timezone,
4460: );
4461: };
4462: if (!$@) {
4463: $epoch_time = $dt->epoch;
4464: if ($epoch_time) {
4465: return $epoch_time;
4466: }
4467: }
1.51 www 4468: return POSIX::mktime(
4469: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4470: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4471: }
4472:
4473: #########################################
1.51 www 4474:
4475: sub findallcourses {
1.482 raeburn 4476: my ($roles,$uname,$udom) = @_;
1.355 albertel 4477: my %roles;
4478: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4479: my %courses;
1.51 www 4480: my $now=time;
1.482 raeburn 4481: if (!defined($uname)) {
4482: $uname = $env{'user.name'};
4483: }
4484: if (!defined($udom)) {
4485: $udom = $env{'user.domain'};
4486: }
4487: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4488: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4489: if (!%roles) {
4490: %roles = (
4491: cc => 1,
1.907 raeburn 4492: co => 1,
1.482 raeburn 4493: in => 1,
4494: ep => 1,
4495: ta => 1,
4496: cr => 1,
4497: st => 1,
4498: );
4499: }
4500: foreach my $entry (keys(%roleshash)) {
4501: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4502: if ($trole =~ /^cr/) {
4503: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4504: } else {
4505: next if (!exists($roles{$trole}));
4506: }
4507: if ($tend) {
4508: next if ($tend < $now);
4509: }
4510: if ($tstart) {
4511: next if ($tstart > $now);
4512: }
1.1058 raeburn 4513: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4514: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4515: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4516: if ($secpart eq '') {
4517: ($cnum,$role) = split(/_/,$cnumpart);
4518: $sec = 'none';
1.1058 raeburn 4519: $value .= $cnum.'/';
1.482 raeburn 4520: } else {
4521: $cnum = $cnumpart;
4522: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4523: $value .= $cnum.'/'.$sec;
4524: }
4525: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4526: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4527: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4528: }
4529: } else {
4530: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4531: }
1.482 raeburn 4532: }
4533: } else {
4534: foreach my $key (keys(%env)) {
1.483 albertel 4535: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4536: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4537: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4538: next if ($role eq 'ca' || $role eq 'aa');
4539: next if (%roles && !exists($roles{$role}));
4540: my ($starttime,$endtime)=split(/\./,$env{$key});
4541: my $active=1;
4542: if ($starttime) {
4543: if ($now<$starttime) { $active=0; }
4544: }
4545: if ($endtime) {
4546: if ($now>$endtime) { $active=0; }
4547: }
4548: if ($active) {
1.1058 raeburn 4549: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4550: if ($sec eq '') {
4551: $sec = 'none';
1.1058 raeburn 4552: } else {
4553: $value .= $sec;
4554: }
4555: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4556: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4557: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4558: }
4559: } else {
4560: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4561: }
1.474 raeburn 4562: }
4563: }
1.51 www 4564: }
4565: }
1.474 raeburn 4566: return %courses;
1.51 www 4567: }
1.37 matthew 4568:
1.54 www 4569: ###############################################
1.474 raeburn 4570:
4571: sub blockcheck {
1.1075.2.73 raeburn 4572: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4573:
1.1075.2.73 raeburn 4574: if (defined($udom) && defined($uname)) {
4575: # If uname and udom are for a course, check for blocks in the course.
4576: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4577: my ($startblock,$endblock,$triggerblock) =
4578: &get_blocks($setters,$activity,$udom,$uname,$url);
4579: return ($startblock,$endblock,$triggerblock);
4580: }
4581: } else {
1.490 raeburn 4582: $udom = $env{'user.domain'};
4583: $uname = $env{'user.name'};
4584: }
4585:
1.502 raeburn 4586: my $startblock = 0;
4587: my $endblock = 0;
1.1062 raeburn 4588: my $triggerblock = '';
1.482 raeburn 4589: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4590:
1.490 raeburn 4591: # If uname is for a user, and activity is course-specific, i.e.,
4592: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4593:
1.490 raeburn 4594: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.73 raeburn 4595: $activity eq 'groups' || $activity eq 'printout') &&
4596: ($env{'request.course.id'})) {
1.490 raeburn 4597: foreach my $key (keys(%live_courses)) {
4598: if ($key ne $env{'request.course.id'}) {
4599: delete($live_courses{$key});
4600: }
4601: }
4602: }
4603:
4604: my $otheruser = 0;
4605: my %own_courses;
4606: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4607: # Resource belongs to user other than current user.
4608: $otheruser = 1;
4609: # Gather courses for current user
4610: %own_courses =
4611: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4612: }
4613:
4614: # Gather active course roles - course coordinator, instructor,
4615: # exam proctor, ta, student, or custom role.
1.474 raeburn 4616:
4617: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4618: my ($cdom,$cnum);
4619: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4620: $cdom = $env{'course.'.$course.'.domain'};
4621: $cnum = $env{'course.'.$course.'.num'};
4622: } else {
1.490 raeburn 4623: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4624: }
4625: my $no_ownblock = 0;
4626: my $no_userblock = 0;
1.533 raeburn 4627: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4628: # Check if current user has 'evb' priv for this
4629: if (defined($own_courses{$course})) {
4630: foreach my $sec (keys(%{$own_courses{$course}})) {
4631: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4632: if ($sec ne 'none') {
4633: $checkrole .= '/'.$sec;
4634: }
4635: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4636: $no_ownblock = 1;
4637: last;
4638: }
4639: }
4640: }
4641: # if they have 'evb' priv and are currently not playing student
4642: next if (($no_ownblock) &&
4643: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4644: }
1.474 raeburn 4645: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4646: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4647: if ($sec ne 'none') {
1.482 raeburn 4648: $checkrole .= '/'.$sec;
1.474 raeburn 4649: }
1.490 raeburn 4650: if ($otheruser) {
4651: # Resource belongs to user other than current user.
4652: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4653: my (%allroles,%userroles);
4654: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4655: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4656: my ($trole,$tdom,$tnum,$tsec);
4657: if ($entry =~ /^cr/) {
4658: ($trole,$tdom,$tnum,$tsec) =
4659: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4660: } else {
4661: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4662: }
4663: my ($spec,$area,$trest);
4664: $area = '/'.$tdom.'/'.$tnum;
4665: $trest = $tnum;
4666: if ($tsec ne '') {
4667: $area .= '/'.$tsec;
4668: $trest .= '/'.$tsec;
4669: }
4670: $spec = $trole.'.'.$area;
4671: if ($trole =~ /^cr/) {
4672: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4673: $tdom,$spec,$trest,$area);
4674: } else {
4675: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4676: $tdom,$spec,$trest,$area);
4677: }
4678: }
4679: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4680: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4681: if ($1) {
4682: $no_userblock = 1;
4683: last;
4684: }
1.486 raeburn 4685: }
4686: }
1.490 raeburn 4687: } else {
4688: # Resource belongs to current user
4689: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4690: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4691: $no_ownblock = 1;
4692: last;
4693: }
1.474 raeburn 4694: }
4695: }
4696: # if they have the evb priv and are currently not playing student
1.482 raeburn 4697: next if (($no_ownblock) &&
1.491 albertel 4698: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4699: next if ($no_userblock);
1.474 raeburn 4700:
1.866 kalberla 4701: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4702: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4703:
1.1062 raeburn 4704: my ($start,$end,$trigger) =
4705: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4706: if (($start != 0) &&
4707: (($startblock == 0) || ($startblock > $start))) {
4708: $startblock = $start;
1.1062 raeburn 4709: if ($trigger ne '') {
4710: $triggerblock = $trigger;
4711: }
1.502 raeburn 4712: }
4713: if (($end != 0) &&
4714: (($endblock == 0) || ($endblock < $end))) {
4715: $endblock = $end;
1.1062 raeburn 4716: if ($trigger ne '') {
4717: $triggerblock = $trigger;
4718: }
1.502 raeburn 4719: }
1.490 raeburn 4720: }
1.1062 raeburn 4721: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4722: }
4723:
4724: sub get_blocks {
1.1062 raeburn 4725: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4726: my $startblock = 0;
4727: my $endblock = 0;
1.1062 raeburn 4728: my $triggerblock = '';
1.490 raeburn 4729: my $course = $cdom.'_'.$cnum;
4730: $setters->{$course} = {};
4731: $setters->{$course}{'staff'} = [];
4732: $setters->{$course}{'times'} = [];
1.1062 raeburn 4733: $setters->{$course}{'triggers'} = [];
4734: my (@blockers,%triggered);
4735: my $now = time;
4736: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4737: if ($activity eq 'docs') {
4738: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4739: foreach my $block (@blockers) {
4740: if ($block =~ /^firstaccess____(.+)$/) {
4741: my $item = $1;
4742: my $type = 'map';
4743: my $timersymb = $item;
4744: if ($item eq 'course') {
4745: $type = 'course';
4746: } elsif ($item =~ /___\d+___/) {
4747: $type = 'resource';
4748: } else {
4749: $timersymb = &Apache::lonnet::symbread($item);
4750: }
4751: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4752: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4753: $triggered{$block} = {
4754: start => $start,
4755: end => $end,
4756: type => $type,
4757: };
4758: }
4759: }
4760: } else {
4761: foreach my $block (keys(%commblocks)) {
4762: if ($block =~ m/^(\d+)____(\d+)$/) {
4763: my ($start,$end) = ($1,$2);
4764: if ($start <= time && $end >= time) {
4765: if (ref($commblocks{$block}) eq 'HASH') {
4766: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4767: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4768: unless(grep(/^\Q$block\E$/,@blockers)) {
4769: push(@blockers,$block);
4770: }
4771: }
4772: }
4773: }
4774: }
4775: } elsif ($block =~ /^firstaccess____(.+)$/) {
4776: my $item = $1;
4777: my $timersymb = $item;
4778: my $type = 'map';
4779: if ($item eq 'course') {
4780: $type = 'course';
4781: } elsif ($item =~ /___\d+___/) {
4782: $type = 'resource';
4783: } else {
4784: $timersymb = &Apache::lonnet::symbread($item);
4785: }
4786: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4787: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4788: if ($start && $end) {
4789: if (($start <= time) && ($end >= time)) {
4790: unless (grep(/^\Q$block\E$/,@blockers)) {
4791: push(@blockers,$block);
4792: $triggered{$block} = {
4793: start => $start,
4794: end => $end,
4795: type => $type,
4796: };
4797: }
4798: }
1.490 raeburn 4799: }
1.1062 raeburn 4800: }
4801: }
4802: }
4803: foreach my $blocker (@blockers) {
4804: my ($staff_name,$staff_dom,$title,$blocks) =
4805: &parse_block_record($commblocks{$blocker});
4806: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4807: my ($start,$end,$triggertype);
4808: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4809: ($start,$end) = ($1,$2);
4810: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4811: $start = $triggered{$blocker}{'start'};
4812: $end = $triggered{$blocker}{'end'};
4813: $triggertype = $triggered{$blocker}{'type'};
4814: }
4815: if ($start) {
4816: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4817: if ($triggertype) {
4818: push(@{$$setters{$course}{'triggers'}},$triggertype);
4819: } else {
4820: push(@{$$setters{$course}{'triggers'}},0);
4821: }
4822: if ( ($startblock == 0) || ($startblock > $start) ) {
4823: $startblock = $start;
4824: if ($triggertype) {
4825: $triggerblock = $blocker;
1.474 raeburn 4826: }
4827: }
1.1062 raeburn 4828: if ( ($endblock == 0) || ($endblock < $end) ) {
4829: $endblock = $end;
4830: if ($triggertype) {
4831: $triggerblock = $blocker;
4832: }
4833: }
1.474 raeburn 4834: }
4835: }
1.1062 raeburn 4836: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4837: }
4838:
4839: sub parse_block_record {
4840: my ($record) = @_;
4841: my ($setuname,$setudom,$title,$blocks);
4842: if (ref($record) eq 'HASH') {
4843: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4844: $title = &unescape($record->{'event'});
4845: $blocks = $record->{'blocks'};
4846: } else {
4847: my @data = split(/:/,$record,3);
4848: if (scalar(@data) eq 2) {
4849: $title = $data[1];
4850: ($setuname,$setudom) = split(/@/,$data[0]);
4851: } else {
4852: ($setuname,$setudom,$title) = @data;
4853: }
4854: $blocks = { 'com' => 'on' };
4855: }
4856: return ($setuname,$setudom,$title,$blocks);
4857: }
4858:
1.854 kalberla 4859: sub blocking_status {
1.1075.2.73 raeburn 4860: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 4861: my %setters;
1.890 droeschl 4862:
1.1061 raeburn 4863: # check for active blocking
1.1062 raeburn 4864: my ($startblock,$endblock,$triggerblock) =
1.1075.2.73 raeburn 4865: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 4866: my $blocked = 0;
4867: if ($startblock && $endblock) {
4868: $blocked = 1;
4869: }
1.890 droeschl 4870:
1.1061 raeburn 4871: # caller just wants to know whether a block is active
4872: if (!wantarray) { return $blocked; }
4873:
4874: # build a link to a popup window containing the details
4875: my $querystring = "?activity=$activity";
4876: # $uname and $udom decide whose portfolio the user is trying to look at
1.1075.2.97 raeburn 4877: if (($activity eq 'port') || ($activity eq 'passwd')) {
4878: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
4879: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 4880: } elsif ($activity eq 'docs') {
4881: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4882: }
1.1061 raeburn 4883:
4884: my $output .= <<'END_MYBLOCK';
4885: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4886: var options = "width=" + w + ",height=" + h + ",";
4887: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4888: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4889: var newWin = window.open(url, wdwName, options);
4890: newWin.focus();
4891: }
1.890 droeschl 4892: END_MYBLOCK
1.854 kalberla 4893:
1.1061 raeburn 4894: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4895:
1.1061 raeburn 4896: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4897: my $text = &mt('Communication Blocked');
1.1075.2.93 raeburn 4898: my $class = 'LC_comblock';
1.1062 raeburn 4899: if ($activity eq 'docs') {
4900: $text = &mt('Content Access Blocked');
1.1075.2.93 raeburn 4901: $class = '';
1.1063 raeburn 4902: } elsif ($activity eq 'printout') {
4903: $text = &mt('Printing Blocked');
1.1075.2.97 raeburn 4904: } elsif ($activity eq 'passwd') {
4905: $text = &mt('Password Changing Blocked');
1.1062 raeburn 4906: }
1.1061 raeburn 4907: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 4908: <div class='$class'>
1.869 kalberla 4909: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4910: title='$text'>
4911: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4912: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4913: title='$text'>$text</a>
1.867 kalberla 4914: </div>
4915:
4916: END_BLOCK
1.474 raeburn 4917:
1.1061 raeburn 4918: return ($blocked, $output);
1.854 kalberla 4919: }
1.490 raeburn 4920:
1.60 matthew 4921: ###############################################
4922:
1.682 raeburn 4923: sub check_ip_acc {
1.1075.2.105 raeburn 4924: my ($acc,$clientip)=@_;
1.682 raeburn 4925: &Apache::lonxml::debug("acc is $acc");
4926: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4927: return 1;
4928: }
4929: my $allowed=0;
1.1075.2.111 raeburn 4930: my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682 raeburn 4931:
4932: my $name;
4933: foreach my $pattern (split(',',$acc)) {
4934: $pattern =~ s/^\s*//;
4935: $pattern =~ s/\s*$//;
4936: if ($pattern =~ /\*$/) {
4937: #35.8.*
4938: $pattern=~s/\*//;
4939: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4940: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4941: #35.8.3.[34-56]
4942: my $low=$2;
4943: my $high=$3;
4944: $pattern=$1;
4945: if ($ip =~ /^\Q$pattern\E/) {
4946: my $last=(split(/\./,$ip))[3];
4947: if ($last <=$high && $last >=$low) { $allowed=1; }
4948: }
4949: } elsif ($pattern =~ /^\*/) {
4950: #*.msu.edu
4951: $pattern=~s/\*//;
4952: if (!defined($name)) {
4953: use Socket;
4954: my $netaddr=inet_aton($ip);
4955: ($name)=gethostbyaddr($netaddr,AF_INET);
4956: }
4957: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4958: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4959: #127.0.0.1
4960: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4961: } else {
4962: #some.name.com
4963: if (!defined($name)) {
4964: use Socket;
4965: my $netaddr=inet_aton($ip);
4966: ($name)=gethostbyaddr($netaddr,AF_INET);
4967: }
4968: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4969: }
4970: if ($allowed) { last; }
4971: }
4972: return $allowed;
4973: }
4974:
4975: ###############################################
4976:
1.60 matthew 4977: =pod
4978:
1.112 bowersj2 4979: =head1 Domain Template Functions
4980:
4981: =over 4
4982:
4983: =item * &determinedomain()
1.60 matthew 4984:
4985: Inputs: $domain (usually will be undef)
4986:
1.63 www 4987: Returns: Determines which domain should be used for designs
1.60 matthew 4988:
4989: =cut
1.54 www 4990:
1.60 matthew 4991: ###############################################
1.63 www 4992: sub determinedomain {
4993: my $domain=shift;
1.531 albertel 4994: if (! $domain) {
1.60 matthew 4995: # Determine domain if we have not been given one
1.893 raeburn 4996: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4997: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4998: if ($env{'request.role.domain'}) {
4999: $domain=$env{'request.role.domain'};
1.60 matthew 5000: }
5001: }
1.63 www 5002: return $domain;
5003: }
5004: ###############################################
1.517 raeburn 5005:
1.518 albertel 5006: sub devalidate_domconfig_cache {
5007: my ($udom)=@_;
5008: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5009: }
5010:
5011: # ---------------------- Get domain configuration for a domain
5012: sub get_domainconf {
5013: my ($udom) = @_;
5014: my $cachetime=1800;
5015: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5016: if (defined($cached)) { return %{$result}; }
5017:
5018: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5019: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5020: my (%designhash,%legacy);
1.518 albertel 5021: if (keys(%domconfig) > 0) {
5022: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5023: if (keys(%{$domconfig{'login'}})) {
5024: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5025: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 5026: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5027: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5028: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5029: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5030: if ($key eq 'loginvia') {
5031: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5032: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5033: $designhash{$udom.'.login.loginvia'} = $server;
5034: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5035: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5036: } else {
5037: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5038: }
1.948 raeburn 5039: }
1.1075.2.87 raeburn 5040: } elsif ($key eq 'headtag') {
5041: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5042: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5043: }
1.946 raeburn 5044: }
1.1075.2.87 raeburn 5045: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5046: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5047: }
1.946 raeburn 5048: }
5049: }
5050: }
5051: } else {
5052: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5053: $designhash{$udom.'.login.'.$key.'_'.$img} =
5054: $domconfig{'login'}{$key}{$img};
5055: }
1.699 raeburn 5056: }
5057: } else {
5058: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5059: }
1.632 raeburn 5060: }
5061: } else {
5062: $legacy{'login'} = 1;
1.518 albertel 5063: }
1.632 raeburn 5064: } else {
5065: $legacy{'login'} = 1;
1.518 albertel 5066: }
5067: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5068: if (keys(%{$domconfig{'rolecolors'}})) {
5069: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5070: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5071: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5072: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5073: }
1.518 albertel 5074: }
5075: }
1.632 raeburn 5076: } else {
5077: $legacy{'rolecolors'} = 1;
1.518 albertel 5078: }
1.632 raeburn 5079: } else {
5080: $legacy{'rolecolors'} = 1;
1.518 albertel 5081: }
1.948 raeburn 5082: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5083: if ($domconfig{'autoenroll'}{'co-owners'}) {
5084: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5085: }
5086: }
1.632 raeburn 5087: if (keys(%legacy) > 0) {
5088: my %legacyhash = &get_legacy_domconf($udom);
5089: foreach my $item (keys(%legacyhash)) {
5090: if ($item =~ /^\Q$udom\E\.login/) {
5091: if ($legacy{'login'}) {
5092: $designhash{$item} = $legacyhash{$item};
5093: }
5094: } else {
5095: if ($legacy{'rolecolors'}) {
5096: $designhash{$item} = $legacyhash{$item};
5097: }
1.518 albertel 5098: }
5099: }
5100: }
1.632 raeburn 5101: } else {
5102: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5103: }
5104: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5105: $cachetime);
5106: return %designhash;
5107: }
5108:
1.632 raeburn 5109: sub get_legacy_domconf {
5110: my ($udom) = @_;
5111: my %legacyhash;
5112: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5113: my $designfile = $designdir.'/'.$udom.'.tab';
5114: if (-e $designfile) {
5115: if ( open (my $fh,"<$designfile") ) {
5116: while (my $line = <$fh>) {
5117: next if ($line =~ /^\#/);
5118: chomp($line);
5119: my ($key,$val)=(split(/\=/,$line));
5120: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5121: }
5122: close($fh);
5123: }
5124: }
1.1026 raeburn 5125: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5126: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5127: }
5128: return %legacyhash;
5129: }
5130:
1.63 www 5131: =pod
5132:
1.112 bowersj2 5133: =item * &domainlogo()
1.63 www 5134:
5135: Inputs: $domain (usually will be undef)
5136:
5137: Returns: A link to a domain logo, if the domain logo exists.
5138: If the domain logo does not exist, a description of the domain.
5139:
5140: =cut
1.112 bowersj2 5141:
1.63 www 5142: ###############################################
5143: sub domainlogo {
1.517 raeburn 5144: my $domain = &determinedomain(shift);
1.518 albertel 5145: my %designhash = &get_domainconf($domain);
1.517 raeburn 5146: # See if there is a logo
5147: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5148: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5149: if ($imgsrc =~ m{^/(adm|res)/}) {
5150: if ($imgsrc =~ m{^/res/}) {
5151: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5152: &Apache::lonnet::repcopy($local_name);
5153: }
5154: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5155: }
5156: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5157: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5158: return &Apache::lonnet::domain($domain,'description');
1.59 www 5159: } else {
1.60 matthew 5160: return '';
1.59 www 5161: }
5162: }
1.63 www 5163: ##############################################
5164:
5165: =pod
5166:
1.112 bowersj2 5167: =item * &designparm()
1.63 www 5168:
5169: Inputs: $which parameter; $domain (usually will be undef)
5170:
5171: Returns: value of designparamter $which
5172:
5173: =cut
1.112 bowersj2 5174:
1.397 albertel 5175:
1.400 albertel 5176: ##############################################
1.397 albertel 5177: sub designparm {
5178: my ($which,$domain)=@_;
5179: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5180: return $env{'environment.color.'.$which};
1.96 www 5181: }
1.63 www 5182: $domain=&determinedomain($domain);
1.1016 raeburn 5183: my %domdesign;
5184: unless ($domain eq 'public') {
5185: %domdesign = &get_domainconf($domain);
5186: }
1.520 raeburn 5187: my $output;
1.517 raeburn 5188: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5189: $output = $domdesign{$domain.'.'.$which};
1.63 www 5190: } else {
1.520 raeburn 5191: $output = $defaultdesign{$which};
5192: }
5193: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5194: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5195: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5196: if ($output =~ m{^/res/}) {
5197: my $local_name = &Apache::lonnet::filelocation('',$output);
5198: &Apache::lonnet::repcopy($local_name);
5199: }
1.520 raeburn 5200: $output = &lonhttpdurl($output);
5201: }
1.63 www 5202: }
1.520 raeburn 5203: return $output;
1.63 www 5204: }
1.59 www 5205:
1.822 bisitz 5206: ##############################################
5207: =pod
5208:
1.832 bisitz 5209: =item * &authorspace()
5210:
1.1028 raeburn 5211: Inputs: $url (usually will be undef).
1.832 bisitz 5212:
1.1075.2.40 raeburn 5213: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5214: directory being viewed (or for which action is being taken).
5215: If $url is provided, and begins /priv/<domain>/<uname>
5216: the path will be that portion of the $context argument.
5217: Otherwise the path will be for the author space of the current
5218: user when the current role is author, or for that of the
5219: co-author/assistant co-author space when the current role
5220: is co-author or assistant co-author.
1.832 bisitz 5221:
5222: =cut
5223:
5224: sub authorspace {
1.1028 raeburn 5225: my ($url) = @_;
5226: if ($url ne '') {
5227: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5228: return $1;
5229: }
5230: }
1.832 bisitz 5231: my $caname = '';
1.1024 www 5232: my $cadom = '';
1.1028 raeburn 5233: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5234: ($cadom,$caname) =
1.832 bisitz 5235: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5236: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5237: $caname = $env{'user.name'};
1.1024 www 5238: $cadom = $env{'user.domain'};
1.832 bisitz 5239: }
1.1028 raeburn 5240: if (($caname ne '') && ($cadom ne '')) {
5241: return "/priv/$cadom/$caname/";
5242: }
5243: return;
1.832 bisitz 5244: }
5245:
5246: ##############################################
5247: =pod
5248:
1.822 bisitz 5249: =item * &head_subbox()
5250:
5251: Inputs: $content (contains HTML code with page functions, etc.)
5252:
5253: Returns: HTML div with $content
5254: To be included in page header
5255:
5256: =cut
5257:
5258: sub head_subbox {
5259: my ($content)=@_;
5260: my $output =
1.993 raeburn 5261: '<div class="LC_head_subbox">'
1.822 bisitz 5262: .$content
5263: .'</div>'
5264: }
5265:
5266: ##############################################
5267: =pod
5268:
5269: =item * &CSTR_pageheader()
5270:
1.1026 raeburn 5271: Input: (optional) filename from which breadcrumb trail is built.
5272: In most cases no input as needed, as $env{'request.filename'}
5273: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5274:
5275: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5276: To be included on Authoring Space pages
1.822 bisitz 5277:
5278: =cut
5279:
5280: sub CSTR_pageheader {
1.1026 raeburn 5281: my ($trailfile) = @_;
5282: if ($trailfile eq '') {
5283: $trailfile = $env{'request.filename'};
5284: }
5285:
5286: # this is for resources; directories have customtitle, and crumbs
5287: # and select recent are created in lonpubdir.pm
5288:
5289: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5290: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5291: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5292: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5293: $formaction =~ s{/+}{/}g;
1.822 bisitz 5294:
5295: my $parentpath = '';
5296: my $lastitem = '';
5297: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5298: $parentpath = $1;
5299: $lastitem = $2;
5300: } else {
5301: $lastitem = $thisdisfn;
5302: }
1.921 bisitz 5303:
5304: my $output =
1.822 bisitz 5305: '<div>'
5306: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5307: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5308: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5309: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5310: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5311:
5312: if ($lastitem) {
5313: $output .=
5314: '<span class="LC_filename">'
5315: .$lastitem
5316: .'</span>';
5317: }
5318: $output .=
5319: '<br />'
1.822 bisitz 5320: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5321: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5322: .'</form>'
5323: .&Apache::lonmenu::constspaceform()
5324: .'</div>';
1.921 bisitz 5325:
5326: return $output;
1.822 bisitz 5327: }
5328:
1.60 matthew 5329: ###############################################
5330: ###############################################
5331:
5332: =pod
5333:
1.112 bowersj2 5334: =back
5335:
1.549 albertel 5336: =head1 HTML Helpers
1.112 bowersj2 5337:
5338: =over 4
5339:
5340: =item * &bodytag()
1.60 matthew 5341:
5342: Returns a uniform header for LON-CAPA web pages.
5343:
5344: Inputs:
5345:
1.112 bowersj2 5346: =over 4
5347:
5348: =item * $title, A title to be displayed on the page.
5349:
5350: =item * $function, the current role (can be undef).
5351:
5352: =item * $addentries, extra parameters for the <body> tag.
5353:
5354: =item * $bodyonly, if defined, only return the <body> tag.
5355:
5356: =item * $domain, if defined, force a given domain.
5357:
5358: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5359: text interface only)
1.60 matthew 5360:
1.814 bisitz 5361: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5362: navigational links
1.317 albertel 5363:
1.338 albertel 5364: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5365:
1.1075.2.12 raeburn 5366: =item * $no_inline_link, if true and in remote mode, don't show the
5367: 'Switch To Inline Menu' link
5368:
1.460 albertel 5369: =item * $args, optional argument valid values are
5370: no_auto_mt_title -> prevents &mt()ing the title arg
5371:
1.1075.2.15 raeburn 5372: =item * $advtoolsref, optional argument, ref to an array containing
5373: inlineremote items to be added in "Functions" menu below
5374: breadcrumbs.
5375:
1.112 bowersj2 5376: =back
5377:
1.60 matthew 5378: Returns: A uniform header for LON-CAPA web pages.
5379: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5380: If $bodyonly is undef or zero, an html string containing a <body> tag and
5381: other decorations will be returned.
5382:
5383: =cut
5384:
1.54 www 5385: sub bodytag {
1.831 bisitz 5386: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5387: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5388:
1.954 raeburn 5389: my $public;
5390: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5391: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5392: $public = 1;
5393: }
1.460 albertel 5394: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5395: my $httphost = $args->{'use_absolute'};
1.339 albertel 5396:
1.183 matthew 5397: $function = &get_users_function() if (!$function);
1.339 albertel 5398: my $img = &designparm($function.'.img',$domain);
5399: my $font = &designparm($function.'.font',$domain);
5400: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5401:
1.803 bisitz 5402: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5403: 'bgcolor' => $pgbg,
1.339 albertel 5404: 'text' => $font,
5405: 'alink' => &designparm($function.'.alink',$domain),
5406: 'vlink' => &designparm($function.'.vlink',$domain),
5407: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5408: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5409:
1.63 www 5410: # role and realm
1.1075.2.68 raeburn 5411: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5412: if ($realm) {
5413: $realm = '/'.$realm;
5414: }
1.378 raeburn 5415: if ($role eq 'ca') {
1.479 albertel 5416: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5417: $realm = &plainname($rname,$rdom);
1.378 raeburn 5418: }
1.55 www 5419: # realm
1.258 albertel 5420: if ($env{'request.course.id'}) {
1.378 raeburn 5421: if ($env{'request.role'} !~ /^cr/) {
5422: $role = &Apache::lonnet::plaintext($role,&course_type());
5423: }
1.898 raeburn 5424: if ($env{'request.course.sec'}) {
5425: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5426: }
1.359 albertel 5427: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5428: } else {
5429: $role = &Apache::lonnet::plaintext($role);
1.54 www 5430: }
1.433 albertel 5431:
1.359 albertel 5432: if (!$realm) { $realm=' '; }
1.330 albertel 5433:
1.438 albertel 5434: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5435:
1.101 www 5436: # construct main body tag
1.359 albertel 5437: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 5438: &Apache::lontexconvert::init_math_support();
1.252 albertel 5439:
1.1075.2.38 raeburn 5440: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5441:
5442: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5443: return $bodytag;
1.1075.2.38 raeburn 5444: }
1.359 albertel 5445:
1.954 raeburn 5446: if ($public) {
1.433 albertel 5447: undef($role);
5448: }
1.359 albertel 5449:
1.762 bisitz 5450: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5451: #
5452: # Extra info if you are the DC
5453: my $dc_info = '';
5454: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5455: $env{'course.'.$env{'request.course.id'}.
5456: '.domain'}.'/'})) {
5457: my $cid = $env{'request.course.id'};
1.917 raeburn 5458: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5459: $dc_info =~ s/\s+$//;
1.359 albertel 5460: }
5461:
1.1075.2.108 raeburn 5462: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 5463:
1.1075.2.13 raeburn 5464: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5465:
1.1075.2.38 raeburn 5466:
5467:
1.1075.2.21 raeburn 5468: my $funclist;
5469: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5470: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5471: Apache::lonmenu::serverform();
5472: my $forbodytag;
5473: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5474: $forcereg,$args->{'group'},
5475: $args->{'bread_crumbs'},
5476: $advtoolsref,'',\$forbodytag);
5477: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5478: $funclist = $forbodytag;
5479: }
5480: } else {
1.903 droeschl 5481:
5482: # if ($env{'request.state'} eq 'construct') {
5483: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5484: # }
5485:
1.1075.2.38 raeburn 5486: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5487: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5488:
1.1075.2.38 raeburn 5489: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5490:
1.916 droeschl 5491: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5492: if ($dc_info) {
5493: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5494: }
1.1075.2.38 raeburn 5495: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5496: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5497: return $bodytag;
5498: }
1.894 droeschl 5499:
1.927 raeburn 5500: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5501: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5502: }
1.916 droeschl 5503:
1.1075.2.38 raeburn 5504: $bodytag .= $right;
1.852 droeschl 5505:
1.917 raeburn 5506: if ($dc_info) {
5507: $dc_info = &dc_courseid_toggle($dc_info);
5508: }
5509: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5510:
1.1075.2.61 raeburn 5511: #if directed to not display the secondary menu, don't.
5512: if ($args->{'no_secondary_menu'}) {
5513: return $bodytag;
5514: }
1.903 droeschl 5515: #don't show menus for public users
1.954 raeburn 5516: if (!$public){
1.1075.2.52 raeburn 5517: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5518: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5519: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5520: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5521: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5522: $args->{'bread_crumbs'});
5523: } elsif ($forcereg) {
1.1075.2.22 raeburn 5524: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5525: $args->{'group'});
1.1075.2.15 raeburn 5526: } else {
1.1075.2.21 raeburn 5527: my $forbodytag;
5528: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5529: $forcereg,$args->{'group'},
5530: $args->{'bread_crumbs'},
5531: $advtoolsref,'',\$forbodytag);
5532: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5533: $bodytag .= $forbodytag;
5534: }
1.920 raeburn 5535: }
1.903 droeschl 5536: }else{
5537: # this is to seperate menu from content when there's no secondary
5538: # menu. Especially needed for public accessible ressources.
5539: $bodytag .= '<hr style="clear:both" />';
5540: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5541: }
1.903 droeschl 5542:
1.235 raeburn 5543: return $bodytag;
1.1075.2.12 raeburn 5544: }
5545:
5546: #
5547: # Top frame rendering, Remote is up
5548: #
5549:
5550: my $imgsrc = $img;
5551: if ($img =~ /^\/adm/) {
5552: $imgsrc = &lonhttpdurl($img);
5553: }
5554: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5555:
1.1075.2.60 raeburn 5556: my $help=($no_inline_link?''
5557: :&Apache::loncommon::top_nav_help('Help'));
5558:
1.1075.2.12 raeburn 5559: # Explicit link to get inline menu
5560: my $menu= ($no_inline_link?''
5561: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5562:
5563: if ($dc_info) {
5564: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5565: }
5566:
1.1075.2.38 raeburn 5567: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5568: unless ($public) {
5569: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5570: undef,'LC_menubuttons_link');
5571: }
5572:
1.1075.2.12 raeburn 5573: unless ($env{'form.inhibitmenu'}) {
5574: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5575: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5576: <li>$help</li>
1.1075.2.12 raeburn 5577: <li>$menu</li>
5578: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5579: }
1.1075.2.13 raeburn 5580: if ($env{'request.state'} eq 'construct') {
5581: if (!$public){
5582: if ($env{'request.state'} eq 'construct') {
5583: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5584: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5585: &Apache::lonhtmlcommon::scripttag('','end').
5586: &Apache::lonmenu::innerregister($forcereg,
5587: $args->{'bread_crumbs'});
5588: }
5589: }
5590: }
1.1075.2.21 raeburn 5591: return $bodytag."\n".$funclist;
1.182 matthew 5592: }
5593:
1.917 raeburn 5594: sub dc_courseid_toggle {
5595: my ($dc_info) = @_;
1.980 raeburn 5596: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5597: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5598: &mt('(More ...)').'</a></span>'.
5599: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5600: }
5601:
1.330 albertel 5602: sub make_attr_string {
5603: my ($register,$attr_ref) = @_;
5604:
5605: if ($attr_ref && !ref($attr_ref)) {
5606: die("addentries Must be a hash ref ".
5607: join(':',caller(1))." ".
5608: join(':',caller(0))." ");
5609: }
5610:
5611: if ($register) {
1.339 albertel 5612: my ($on_load,$on_unload);
5613: foreach my $key (keys(%{$attr_ref})) {
5614: if (lc($key) eq 'onload') {
5615: $on_load.=$attr_ref->{$key}.';';
5616: delete($attr_ref->{$key});
5617:
5618: } elsif (lc($key) eq 'onunload') {
5619: $on_unload.=$attr_ref->{$key}.';';
5620: delete($attr_ref->{$key});
5621: }
5622: }
1.1075.2.12 raeburn 5623: if ($env{'environment.remote'} eq 'on') {
5624: $attr_ref->{'onload'} =
5625: &Apache::lonmenu::loadevents(). $on_load;
5626: $attr_ref->{'onunload'}=
5627: &Apache::lonmenu::unloadevents().$on_unload;
5628: } else {
5629: $attr_ref->{'onload'} = $on_load;
5630: $attr_ref->{'onunload'}= $on_unload;
5631: }
1.330 albertel 5632: }
1.339 albertel 5633:
1.330 albertel 5634: my $attr_string;
1.1075.2.56 raeburn 5635: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5636: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5637: }
5638: return $attr_string;
5639: }
5640:
5641:
1.182 matthew 5642: ###############################################
1.251 albertel 5643: ###############################################
5644:
5645: =pod
5646:
5647: =item * &endbodytag()
5648:
5649: Returns a uniform footer for LON-CAPA web pages.
5650:
1.635 raeburn 5651: Inputs: 1 - optional reference to an args hash
5652: If in the hash, key for noredirectlink has a value which evaluates to true,
5653: a 'Continue' link is not displayed if the page contains an
5654: internal redirect in the <head></head> section,
5655: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5656:
5657: =cut
5658:
5659: sub endbodytag {
1.635 raeburn 5660: my ($args) = @_;
1.1075.2.6 raeburn 5661: my $endbodytag;
5662: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5663: $endbodytag='</body>';
5664: }
1.315 albertel 5665: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5666: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5667: $endbodytag=
5668: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5669: &mt('Continue').'</a>'.
5670: $endbodytag;
5671: }
1.315 albertel 5672: }
1.251 albertel 5673: return $endbodytag;
5674: }
5675:
1.352 albertel 5676: =pod
5677:
5678: =item * &standard_css()
5679:
5680: Returns a style sheet
5681:
5682: Inputs: (all optional)
5683: domain -> force to color decorate a page for a specific
5684: domain
5685: function -> force usage of a specific rolish color scheme
5686: bgcolor -> override the default page bgcolor
5687:
5688: =cut
5689:
1.343 albertel 5690: sub standard_css {
1.345 albertel 5691: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5692: $function = &get_users_function() if (!$function);
5693: my $img = &designparm($function.'.img', $domain);
5694: my $tabbg = &designparm($function.'.tabbg', $domain);
5695: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5696: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5697: #second colour for later usage
1.345 albertel 5698: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5699: my $pgbg_or_bgcolor =
5700: $bgcolor ||
1.352 albertel 5701: &designparm($function.'.pgbg', $domain);
1.382 albertel 5702: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5703: my $alink = &designparm($function.'.alink', $domain);
5704: my $vlink = &designparm($function.'.vlink', $domain);
5705: my $link = &designparm($function.'.link', $domain);
5706:
1.602 albertel 5707: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5708: my $mono = 'monospace';
1.850 bisitz 5709: my $data_table_head = $sidebg;
5710: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5711: my $data_table_dark = '#E0E0E0';
1.470 banghart 5712: my $data_table_darker = '#CCCCCC';
1.349 albertel 5713: my $data_table_highlight = '#FFFF00';
1.352 albertel 5714: my $mail_new = '#FFBB77';
5715: my $mail_new_hover = '#DD9955';
5716: my $mail_read = '#BBBB77';
5717: my $mail_read_hover = '#999944';
5718: my $mail_replied = '#AAAA88';
5719: my $mail_replied_hover = '#888855';
5720: my $mail_other = '#99BBBB';
5721: my $mail_other_hover = '#669999';
1.391 albertel 5722: my $table_header = '#DDDDDD';
1.489 raeburn 5723: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5724: my $lg_border_color = '#C8C8C8';
1.952 onken 5725: my $button_hover = '#BF2317';
1.392 albertel 5726:
1.608 albertel 5727: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5728: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5729: : '0 3px 0 4px';
1.448 albertel 5730:
1.523 albertel 5731:
1.343 albertel 5732: return <<END;
1.947 droeschl 5733:
5734: /* needed for iframe to allow 100% height in FF */
5735: body, html {
5736: margin: 0;
5737: padding: 0 0.5%;
5738: height: 99%; /* to avoid scrollbars */
5739: }
5740:
1.795 www 5741: body {
1.911 bisitz 5742: font-family: $sans;
5743: line-height:130%;
5744: font-size:0.83em;
5745: color:$font;
1.795 www 5746: }
5747:
1.959 onken 5748: a:focus,
5749: a:focus img {
1.795 www 5750: color: red;
5751: }
1.698 harmsja 5752:
1.911 bisitz 5753: form, .inline {
5754: display: inline;
1.795 www 5755: }
1.721 harmsja 5756:
1.795 www 5757: .LC_right {
1.911 bisitz 5758: text-align:right;
1.795 www 5759: }
5760:
5761: .LC_middle {
1.911 bisitz 5762: vertical-align:middle;
1.795 www 5763: }
1.721 harmsja 5764:
1.1075.2.38 raeburn 5765: .LC_floatleft {
5766: float: left;
5767: }
5768:
5769: .LC_floatright {
5770: float: right;
5771: }
5772:
1.911 bisitz 5773: .LC_400Box {
5774: width:400px;
5775: }
1.721 harmsja 5776:
1.947 droeschl 5777: .LC_iframecontainer {
5778: width: 98%;
5779: margin: 0;
5780: position: fixed;
5781: top: 8.5em;
5782: bottom: 0;
5783: }
5784:
5785: .LC_iframecontainer iframe{
5786: border: none;
5787: width: 100%;
5788: height: 100%;
5789: }
5790:
1.778 bisitz 5791: .LC_filename {
5792: font-family: $mono;
5793: white-space:pre;
1.921 bisitz 5794: font-size: 120%;
1.778 bisitz 5795: }
5796:
5797: .LC_fileicon {
5798: border: none;
5799: height: 1.3em;
5800: vertical-align: text-bottom;
5801: margin-right: 0.3em;
5802: text-decoration:none;
5803: }
5804:
1.1008 www 5805: .LC_setting {
5806: text-decoration:underline;
5807: }
5808:
1.350 albertel 5809: .LC_error {
5810: color: red;
5811: }
1.795 www 5812:
1.1075.2.15 raeburn 5813: .LC_warning {
5814: color: darkorange;
5815: }
5816:
1.457 albertel 5817: .LC_diff_removed {
1.733 bisitz 5818: color: red;
1.394 albertel 5819: }
1.532 albertel 5820:
5821: .LC_info,
1.457 albertel 5822: .LC_success,
5823: .LC_diff_added {
1.350 albertel 5824: color: green;
5825: }
1.795 www 5826:
1.802 bisitz 5827: div.LC_confirm_box {
5828: background-color: #FAFAFA;
5829: border: 1px solid $lg_border_color;
5830: margin-right: 0;
5831: padding: 5px;
5832: }
5833:
5834: div.LC_confirm_box .LC_error img,
5835: div.LC_confirm_box .LC_success img {
5836: vertical-align: middle;
5837: }
5838:
1.1075.2.108 raeburn 5839: .LC_maxwidth {
5840: max-width: 100%;
5841: height: auto;
5842: }
5843:
5844: .LC_textsize_mobile {
5845: \@media only screen and (max-device-width: 480px) {
5846: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
5847: }
5848: }
5849:
1.440 albertel 5850: .LC_icon {
1.771 droeschl 5851: border: none;
1.790 droeschl 5852: vertical-align: middle;
1.771 droeschl 5853: }
5854:
1.543 albertel 5855: .LC_docs_spacer {
5856: width: 25px;
5857: height: 1px;
1.771 droeschl 5858: border: none;
1.543 albertel 5859: }
1.346 albertel 5860:
1.532 albertel 5861: .LC_internal_info {
1.735 bisitz 5862: color: #999999;
1.532 albertel 5863: }
5864:
1.794 www 5865: .LC_discussion {
1.1050 www 5866: background: $data_table_dark;
1.911 bisitz 5867: border: 1px solid black;
5868: margin: 2px;
1.794 www 5869: }
5870:
5871: .LC_disc_action_left {
1.1050 www 5872: background: $sidebg;
1.911 bisitz 5873: text-align: left;
1.1050 www 5874: padding: 4px;
5875: margin: 2px;
1.794 www 5876: }
5877:
5878: .LC_disc_action_right {
1.1050 www 5879: background: $sidebg;
1.911 bisitz 5880: text-align: right;
1.1050 www 5881: padding: 4px;
5882: margin: 2px;
1.794 www 5883: }
5884:
5885: .LC_disc_new_item {
1.911 bisitz 5886: background: white;
5887: border: 2px solid red;
1.1050 www 5888: margin: 4px;
5889: padding: 4px;
1.794 www 5890: }
5891:
5892: .LC_disc_old_item {
1.911 bisitz 5893: background: white;
1.1050 www 5894: margin: 4px;
5895: padding: 4px;
1.794 www 5896: }
5897:
1.458 albertel 5898: table.LC_pastsubmission {
5899: border: 1px solid black;
5900: margin: 2px;
5901: }
5902:
1.924 bisitz 5903: table#LC_menubuttons {
1.345 albertel 5904: width: 100%;
5905: background: $pgbg;
1.392 albertel 5906: border: 2px;
1.402 albertel 5907: border-collapse: separate;
1.803 bisitz 5908: padding: 0;
1.345 albertel 5909: }
1.392 albertel 5910:
1.801 tempelho 5911: table#LC_title_bar a {
5912: color: $fontmenu;
5913: }
1.836 bisitz 5914:
1.807 droeschl 5915: table#LC_title_bar {
1.819 tempelho 5916: clear: both;
1.836 bisitz 5917: display: none;
1.807 droeschl 5918: }
5919:
1.795 www 5920: table#LC_title_bar,
1.933 droeschl 5921: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5922: table#LC_title_bar.LC_with_remote {
1.359 albertel 5923: width: 100%;
1.392 albertel 5924: border-color: $pgbg;
5925: border-style: solid;
5926: border-width: $border;
1.379 albertel 5927: background: $pgbg;
1.801 tempelho 5928: color: $fontmenu;
1.392 albertel 5929: border-collapse: collapse;
1.803 bisitz 5930: padding: 0;
1.819 tempelho 5931: margin: 0;
1.359 albertel 5932: }
1.795 www 5933:
1.933 droeschl 5934: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5935: margin: 0;
5936: padding: 0;
1.933 droeschl 5937: position: relative;
5938: list-style: none;
1.913 droeschl 5939: }
1.933 droeschl 5940: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5941: display: inline;
5942: }
1.933 droeschl 5943:
5944: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5945: padding: 0;
1.933 droeschl 5946: margin: 0;
5947: float: left;
1.913 droeschl 5948: }
1.933 droeschl 5949: .LC_breadcrumb_tools_tools {
5950: padding: 0;
5951: margin: 0;
1.913 droeschl 5952: float: right;
5953: }
5954:
1.359 albertel 5955: table#LC_title_bar td {
5956: background: $tabbg;
5957: }
1.795 www 5958:
1.911 bisitz 5959: table#LC_menubuttons img {
1.803 bisitz 5960: border: none;
1.346 albertel 5961: }
1.795 www 5962:
1.842 droeschl 5963: .LC_breadcrumbs_component {
1.911 bisitz 5964: float: right;
5965: margin: 0 1em;
1.357 albertel 5966: }
1.842 droeschl 5967: .LC_breadcrumbs_component img {
1.911 bisitz 5968: vertical-align: middle;
1.777 tempelho 5969: }
1.795 www 5970:
1.1075.2.108 raeburn 5971: .LC_breadcrumbs_hoverable {
5972: background: $sidebg;
5973: }
5974:
1.383 albertel 5975: td.LC_table_cell_checkbox {
5976: text-align: center;
5977: }
1.795 www 5978:
5979: .LC_fontsize_small {
1.911 bisitz 5980: font-size: 70%;
1.705 tempelho 5981: }
5982:
1.844 bisitz 5983: #LC_breadcrumbs {
1.911 bisitz 5984: clear:both;
5985: background: $sidebg;
5986: border-bottom: 1px solid $lg_border_color;
5987: line-height: 2.5em;
1.933 droeschl 5988: overflow: hidden;
1.911 bisitz 5989: margin: 0;
5990: padding: 0;
1.995 raeburn 5991: text-align: left;
1.819 tempelho 5992: }
1.862 bisitz 5993:
1.1075.2.16 raeburn 5994: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5995: clear:both;
5996: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5997: border: 1px solid $sidebg;
1.1075.2.16 raeburn 5998: margin: 0 0 10px 0;
1.966 bisitz 5999: padding: 3px;
1.995 raeburn 6000: text-align: left;
1.822 bisitz 6001: }
6002:
1.795 www 6003: .LC_fontsize_medium {
1.911 bisitz 6004: font-size: 85%;
1.705 tempelho 6005: }
6006:
1.795 www 6007: .LC_fontsize_large {
1.911 bisitz 6008: font-size: 120%;
1.705 tempelho 6009: }
6010:
1.346 albertel 6011: .LC_menubuttons_inline_text {
6012: color: $font;
1.698 harmsja 6013: font-size: 90%;
1.701 harmsja 6014: padding-left:3px;
1.346 albertel 6015: }
6016:
1.934 droeschl 6017: .LC_menubuttons_inline_text img{
6018: vertical-align: middle;
6019: }
6020:
1.1051 www 6021: li.LC_menubuttons_inline_text img {
1.951 onken 6022: cursor:pointer;
1.1002 droeschl 6023: text-decoration: none;
1.951 onken 6024: }
6025:
1.526 www 6026: .LC_menubuttons_link {
6027: text-decoration: none;
6028: }
1.795 www 6029:
1.522 albertel 6030: .LC_menubuttons_category {
1.521 www 6031: color: $font;
1.526 www 6032: background: $pgbg;
1.521 www 6033: font-size: larger;
6034: font-weight: bold;
6035: }
6036:
1.346 albertel 6037: td.LC_menubuttons_text {
1.911 bisitz 6038: color: $font;
1.346 albertel 6039: }
1.706 harmsja 6040:
1.346 albertel 6041: .LC_current_location {
6042: background: $tabbg;
6043: }
1.795 www 6044:
1.938 bisitz 6045: table.LC_data_table {
1.347 albertel 6046: border: 1px solid #000000;
1.402 albertel 6047: border-collapse: separate;
1.426 albertel 6048: border-spacing: 1px;
1.610 albertel 6049: background: $pgbg;
1.347 albertel 6050: }
1.795 www 6051:
1.422 albertel 6052: .LC_data_table_dense {
6053: font-size: small;
6054: }
1.795 www 6055:
1.507 raeburn 6056: table.LC_nested_outer {
6057: border: 1px solid #000000;
1.589 raeburn 6058: border-collapse: collapse;
1.803 bisitz 6059: border-spacing: 0;
1.507 raeburn 6060: width: 100%;
6061: }
1.795 www 6062:
1.879 raeburn 6063: table.LC_innerpickbox,
1.507 raeburn 6064: table.LC_nested {
1.803 bisitz 6065: border: none;
1.589 raeburn 6066: border-collapse: collapse;
1.803 bisitz 6067: border-spacing: 0;
1.507 raeburn 6068: width: 100%;
6069: }
1.795 www 6070:
1.911 bisitz 6071: table.LC_data_table tr th,
6072: table.LC_calendar tr th,
1.879 raeburn 6073: table.LC_prior_tries tr th,
6074: table.LC_innerpickbox tr th {
1.349 albertel 6075: font-weight: bold;
6076: background-color: $data_table_head;
1.801 tempelho 6077: color:$fontmenu;
1.701 harmsja 6078: font-size:90%;
1.347 albertel 6079: }
1.795 www 6080:
1.879 raeburn 6081: table.LC_innerpickbox tr th,
6082: table.LC_innerpickbox tr td {
6083: vertical-align: top;
6084: }
6085:
1.711 raeburn 6086: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6087: background-color: #CCCCCC;
1.711 raeburn 6088: font-weight: bold;
6089: text-align: left;
6090: }
1.795 www 6091:
1.912 bisitz 6092: table.LC_data_table tr.LC_odd_row > td {
6093: background-color: $data_table_light;
6094: padding: 2px;
6095: vertical-align: top;
6096: }
6097:
1.809 bisitz 6098: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6099: background-color: $data_table_light;
1.912 bisitz 6100: vertical-align: top;
6101: }
6102:
6103: table.LC_data_table tr.LC_even_row > td {
6104: background-color: $data_table_dark;
1.425 albertel 6105: padding: 2px;
1.900 bisitz 6106: vertical-align: top;
1.347 albertel 6107: }
1.795 www 6108:
1.809 bisitz 6109: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6110: background-color: $data_table_dark;
1.900 bisitz 6111: vertical-align: top;
1.347 albertel 6112: }
1.795 www 6113:
1.425 albertel 6114: table.LC_data_table tr.LC_data_table_highlight td {
6115: background-color: $data_table_darker;
6116: }
1.795 www 6117:
1.639 raeburn 6118: table.LC_data_table tr td.LC_leftcol_header {
6119: background-color: $data_table_head;
6120: font-weight: bold;
6121: }
1.795 www 6122:
1.451 albertel 6123: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6124: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6125: font-weight: bold;
6126: font-style: italic;
6127: text-align: center;
6128: padding: 8px;
1.347 albertel 6129: }
1.795 www 6130:
1.1075.2.30 raeburn 6131: table.LC_data_table tr.LC_empty_row td,
6132: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6133: background-color: $sidebg;
6134: }
6135:
6136: table.LC_nested tr.LC_empty_row td {
6137: background-color: #FFFFFF;
6138: }
6139:
1.890 droeschl 6140: table.LC_caption {
6141: }
6142:
1.507 raeburn 6143: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6144: padding: 4ex
6145: }
1.795 www 6146:
1.507 raeburn 6147: table.LC_nested_outer tr th {
6148: font-weight: bold;
1.801 tempelho 6149: color:$fontmenu;
1.507 raeburn 6150: background-color: $data_table_head;
1.701 harmsja 6151: font-size: small;
1.507 raeburn 6152: border-bottom: 1px solid #000000;
6153: }
1.795 www 6154:
1.507 raeburn 6155: table.LC_nested_outer tr td.LC_subheader {
6156: background-color: $data_table_head;
6157: font-weight: bold;
6158: font-size: small;
6159: border-bottom: 1px solid #000000;
6160: text-align: right;
1.451 albertel 6161: }
1.795 www 6162:
1.507 raeburn 6163: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6164: background-color: #CCCCCC;
1.451 albertel 6165: font-weight: bold;
6166: font-size: small;
1.507 raeburn 6167: text-align: center;
6168: }
1.795 www 6169:
1.589 raeburn 6170: table.LC_nested tr.LC_info_row td.LC_left_item,
6171: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6172: text-align: left;
1.451 albertel 6173: }
1.795 www 6174:
1.507 raeburn 6175: table.LC_nested td {
1.735 bisitz 6176: background-color: #FFFFFF;
1.451 albertel 6177: font-size: small;
1.507 raeburn 6178: }
1.795 www 6179:
1.507 raeburn 6180: table.LC_nested_outer tr th.LC_right_item,
6181: table.LC_nested tr.LC_info_row td.LC_right_item,
6182: table.LC_nested tr.LC_odd_row td.LC_right_item,
6183: table.LC_nested tr td.LC_right_item {
1.451 albertel 6184: text-align: right;
6185: }
6186:
1.507 raeburn 6187: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6188: background-color: #EEEEEE;
1.451 albertel 6189: }
6190:
1.473 raeburn 6191: table.LC_createuser {
6192: }
6193:
6194: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6195: font-size: small;
1.473 raeburn 6196: }
6197:
6198: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6199: background-color: #CCCCCC;
1.473 raeburn 6200: font-weight: bold;
6201: text-align: center;
6202: }
6203:
1.349 albertel 6204: table.LC_calendar {
6205: border: 1px solid #000000;
6206: border-collapse: collapse;
1.917 raeburn 6207: width: 98%;
1.349 albertel 6208: }
1.795 www 6209:
1.349 albertel 6210: table.LC_calendar_pickdate {
6211: font-size: xx-small;
6212: }
1.795 www 6213:
1.349 albertel 6214: table.LC_calendar tr td {
6215: border: 1px solid #000000;
6216: vertical-align: top;
1.917 raeburn 6217: width: 14%;
1.349 albertel 6218: }
1.795 www 6219:
1.349 albertel 6220: table.LC_calendar tr td.LC_calendar_day_empty {
6221: background-color: $data_table_dark;
6222: }
1.795 www 6223:
1.779 bisitz 6224: table.LC_calendar tr td.LC_calendar_day_current {
6225: background-color: $data_table_highlight;
1.777 tempelho 6226: }
1.795 www 6227:
1.938 bisitz 6228: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6229: background-color: $mail_new;
6230: }
1.795 www 6231:
1.938 bisitz 6232: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6233: background-color: $mail_new_hover;
6234: }
1.795 www 6235:
1.938 bisitz 6236: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6237: background-color: $mail_read;
6238: }
1.795 www 6239:
1.938 bisitz 6240: /*
6241: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6242: background-color: $mail_read_hover;
6243: }
1.938 bisitz 6244: */
1.795 www 6245:
1.938 bisitz 6246: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6247: background-color: $mail_replied;
6248: }
1.795 www 6249:
1.938 bisitz 6250: /*
6251: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6252: background-color: $mail_replied_hover;
6253: }
1.938 bisitz 6254: */
1.795 www 6255:
1.938 bisitz 6256: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6257: background-color: $mail_other;
6258: }
1.795 www 6259:
1.938 bisitz 6260: /*
6261: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6262: background-color: $mail_other_hover;
6263: }
1.938 bisitz 6264: */
1.494 raeburn 6265:
1.777 tempelho 6266: table.LC_data_table tr > td.LC_browser_file,
6267: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6268: background: #AAEE77;
1.389 albertel 6269: }
1.795 www 6270:
1.777 tempelho 6271: table.LC_data_table tr > td.LC_browser_file_locked,
6272: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6273: background: #FFAA99;
1.387 albertel 6274: }
1.795 www 6275:
1.777 tempelho 6276: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6277: background: #888888;
1.779 bisitz 6278: }
1.795 www 6279:
1.777 tempelho 6280: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6281: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6282: background: #F8F866;
1.777 tempelho 6283: }
1.795 www 6284:
1.696 bisitz 6285: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6286: background: #E0E8FF;
1.387 albertel 6287: }
1.696 bisitz 6288:
1.707 bisitz 6289: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6290: /* background: #77FF77; */
1.707 bisitz 6291: }
1.795 www 6292:
1.707 bisitz 6293: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6294: border-right: 8px solid #FFFF77;
1.707 bisitz 6295: }
1.795 www 6296:
1.707 bisitz 6297: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6298: border-right: 8px solid #FFAA77;
1.707 bisitz 6299: }
1.795 www 6300:
1.707 bisitz 6301: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6302: border-right: 8px solid #FF7777;
1.707 bisitz 6303: }
1.795 www 6304:
1.707 bisitz 6305: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6306: border-right: 8px solid #AAFF77;
1.707 bisitz 6307: }
1.795 www 6308:
1.707 bisitz 6309: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6310: border-right: 8px solid #11CC55;
1.707 bisitz 6311: }
6312:
1.388 albertel 6313: span.LC_current_location {
1.701 harmsja 6314: font-size:larger;
1.388 albertel 6315: background: $pgbg;
6316: }
1.387 albertel 6317:
1.1029 www 6318: span.LC_current_nav_location {
6319: font-weight:bold;
6320: background: $sidebg;
6321: }
6322:
1.395 albertel 6323: span.LC_parm_menu_item {
6324: font-size: larger;
6325: }
1.795 www 6326:
1.395 albertel 6327: span.LC_parm_scope_all {
6328: color: red;
6329: }
1.795 www 6330:
1.395 albertel 6331: span.LC_parm_scope_folder {
6332: color: green;
6333: }
1.795 www 6334:
1.395 albertel 6335: span.LC_parm_scope_resource {
6336: color: orange;
6337: }
1.795 www 6338:
1.395 albertel 6339: span.LC_parm_part {
6340: color: blue;
6341: }
1.795 www 6342:
1.911 bisitz 6343: span.LC_parm_folder,
6344: span.LC_parm_symb {
1.395 albertel 6345: font-size: x-small;
6346: font-family: $mono;
6347: color: #AAAAAA;
6348: }
6349:
1.977 bisitz 6350: ul.LC_parm_parmlist li {
6351: display: inline-block;
6352: padding: 0.3em 0.8em;
6353: vertical-align: top;
6354: width: 150px;
6355: border-top:1px solid $lg_border_color;
6356: }
6357:
1.795 www 6358: td.LC_parm_overview_level_menu,
6359: td.LC_parm_overview_map_menu,
6360: td.LC_parm_overview_parm_selectors,
6361: td.LC_parm_overview_restrictions {
1.396 albertel 6362: border: 1px solid black;
6363: border-collapse: collapse;
6364: }
1.795 www 6365:
1.396 albertel 6366: table.LC_parm_overview_restrictions td {
6367: border-width: 1px 4px 1px 4px;
6368: border-style: solid;
6369: border-color: $pgbg;
6370: text-align: center;
6371: }
1.795 www 6372:
1.396 albertel 6373: table.LC_parm_overview_restrictions th {
6374: background: $tabbg;
6375: border-width: 1px 4px 1px 4px;
6376: border-style: solid;
6377: border-color: $pgbg;
6378: }
1.795 www 6379:
1.398 albertel 6380: table#LC_helpmenu {
1.803 bisitz 6381: border: none;
1.398 albertel 6382: height: 55px;
1.803 bisitz 6383: border-spacing: 0;
1.398 albertel 6384: }
6385:
6386: table#LC_helpmenu fieldset legend {
6387: font-size: larger;
6388: }
1.795 www 6389:
1.397 albertel 6390: table#LC_helpmenu_links {
6391: width: 100%;
6392: border: 1px solid black;
6393: background: $pgbg;
1.803 bisitz 6394: padding: 0;
1.397 albertel 6395: border-spacing: 1px;
6396: }
1.795 www 6397:
1.397 albertel 6398: table#LC_helpmenu_links tr td {
6399: padding: 1px;
6400: background: $tabbg;
1.399 albertel 6401: text-align: center;
6402: font-weight: bold;
1.397 albertel 6403: }
1.396 albertel 6404:
1.795 www 6405: table#LC_helpmenu_links a:link,
6406: table#LC_helpmenu_links a:visited,
1.397 albertel 6407: table#LC_helpmenu_links a:active {
6408: text-decoration: none;
6409: color: $font;
6410: }
1.795 www 6411:
1.397 albertel 6412: table#LC_helpmenu_links a:hover {
6413: text-decoration: underline;
6414: color: $vlink;
6415: }
1.396 albertel 6416:
1.417 albertel 6417: .LC_chrt_popup_exists {
6418: border: 1px solid #339933;
6419: margin: -1px;
6420: }
1.795 www 6421:
1.417 albertel 6422: .LC_chrt_popup_up {
6423: border: 1px solid yellow;
6424: margin: -1px;
6425: }
1.795 www 6426:
1.417 albertel 6427: .LC_chrt_popup {
6428: border: 1px solid #8888FF;
6429: background: #CCCCFF;
6430: }
1.795 www 6431:
1.421 albertel 6432: table.LC_pick_box {
6433: border-collapse: separate;
6434: background: white;
6435: border: 1px solid black;
6436: border-spacing: 1px;
6437: }
1.795 www 6438:
1.421 albertel 6439: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6440: background: $sidebg;
1.421 albertel 6441: font-weight: bold;
1.900 bisitz 6442: text-align: left;
1.740 bisitz 6443: vertical-align: top;
1.421 albertel 6444: width: 184px;
6445: padding: 8px;
6446: }
1.795 www 6447:
1.579 raeburn 6448: table.LC_pick_box td.LC_pick_box_value {
6449: text-align: left;
6450: padding: 8px;
6451: }
1.795 www 6452:
1.579 raeburn 6453: table.LC_pick_box td.LC_pick_box_select {
6454: text-align: left;
6455: padding: 8px;
6456: }
1.795 www 6457:
1.424 albertel 6458: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6459: padding: 0;
1.421 albertel 6460: height: 1px;
6461: background: black;
6462: }
1.795 www 6463:
1.421 albertel 6464: table.LC_pick_box td.LC_pick_box_submit {
6465: text-align: right;
6466: }
1.795 www 6467:
1.579 raeburn 6468: table.LC_pick_box td.LC_evenrow_value {
6469: text-align: left;
6470: padding: 8px;
6471: background-color: $data_table_light;
6472: }
1.795 www 6473:
1.579 raeburn 6474: table.LC_pick_box td.LC_oddrow_value {
6475: text-align: left;
6476: padding: 8px;
6477: background-color: $data_table_light;
6478: }
1.795 www 6479:
1.579 raeburn 6480: span.LC_helpform_receipt_cat {
6481: font-weight: bold;
6482: }
1.795 www 6483:
1.424 albertel 6484: table.LC_group_priv_box {
6485: background: white;
6486: border: 1px solid black;
6487: border-spacing: 1px;
6488: }
1.795 www 6489:
1.424 albertel 6490: table.LC_group_priv_box td.LC_pick_box_title {
6491: background: $tabbg;
6492: font-weight: bold;
6493: text-align: right;
6494: width: 184px;
6495: }
1.795 www 6496:
1.424 albertel 6497: table.LC_group_priv_box td.LC_groups_fixed {
6498: background: $data_table_light;
6499: text-align: center;
6500: }
1.795 www 6501:
1.424 albertel 6502: table.LC_group_priv_box td.LC_groups_optional {
6503: background: $data_table_dark;
6504: text-align: center;
6505: }
1.795 www 6506:
1.424 albertel 6507: table.LC_group_priv_box td.LC_groups_functionality {
6508: background: $data_table_darker;
6509: text-align: center;
6510: font-weight: bold;
6511: }
1.795 www 6512:
1.424 albertel 6513: table.LC_group_priv td {
6514: text-align: left;
1.803 bisitz 6515: padding: 0;
1.424 albertel 6516: }
6517:
6518: .LC_navbuttons {
6519: margin: 2ex 0ex 2ex 0ex;
6520: }
1.795 www 6521:
1.423 albertel 6522: .LC_topic_bar {
6523: font-weight: bold;
6524: background: $tabbg;
1.918 wenzelju 6525: margin: 1em 0em 1em 2em;
1.805 bisitz 6526: padding: 3px;
1.918 wenzelju 6527: font-size: 1.2em;
1.423 albertel 6528: }
1.795 www 6529:
1.423 albertel 6530: .LC_topic_bar span {
1.918 wenzelju 6531: left: 0.5em;
6532: position: absolute;
1.423 albertel 6533: vertical-align: middle;
1.918 wenzelju 6534: font-size: 1.2em;
1.423 albertel 6535: }
1.795 www 6536:
1.423 albertel 6537: table.LC_course_group_status {
6538: margin: 20px;
6539: }
1.795 www 6540:
1.423 albertel 6541: table.LC_status_selector td {
6542: vertical-align: top;
6543: text-align: center;
1.424 albertel 6544: padding: 4px;
6545: }
1.795 www 6546:
1.599 albertel 6547: div.LC_feedback_link {
1.616 albertel 6548: clear: both;
1.829 kalberla 6549: background: $sidebg;
1.779 bisitz 6550: width: 100%;
1.829 kalberla 6551: padding-bottom: 10px;
6552: border: 1px $tabbg solid;
1.833 kalberla 6553: height: 22px;
6554: line-height: 22px;
6555: padding-top: 5px;
6556: }
6557:
6558: div.LC_feedback_link img {
6559: height: 22px;
1.867 kalberla 6560: vertical-align:middle;
1.829 kalberla 6561: }
6562:
1.911 bisitz 6563: div.LC_feedback_link a {
1.829 kalberla 6564: text-decoration: none;
1.489 raeburn 6565: }
1.795 www 6566:
1.867 kalberla 6567: div.LC_comblock {
1.911 bisitz 6568: display:inline;
1.867 kalberla 6569: color:$font;
6570: font-size:90%;
6571: }
6572:
6573: div.LC_feedback_link div.LC_comblock {
6574: padding-left:5px;
6575: }
6576:
6577: div.LC_feedback_link div.LC_comblock a {
6578: color:$font;
6579: }
6580:
1.489 raeburn 6581: span.LC_feedback_link {
1.858 bisitz 6582: /* background: $feedback_link_bg; */
1.599 albertel 6583: font-size: larger;
6584: }
1.795 www 6585:
1.599 albertel 6586: span.LC_message_link {
1.858 bisitz 6587: /* background: $feedback_link_bg; */
1.599 albertel 6588: font-size: larger;
6589: position: absolute;
6590: right: 1em;
1.489 raeburn 6591: }
1.421 albertel 6592:
1.515 albertel 6593: table.LC_prior_tries {
1.524 albertel 6594: border: 1px solid #000000;
6595: border-collapse: separate;
6596: border-spacing: 1px;
1.515 albertel 6597: }
1.523 albertel 6598:
1.515 albertel 6599: table.LC_prior_tries td {
1.524 albertel 6600: padding: 2px;
1.515 albertel 6601: }
1.523 albertel 6602:
6603: .LC_answer_correct {
1.795 www 6604: background: lightgreen;
6605: color: darkgreen;
6606: padding: 6px;
1.523 albertel 6607: }
1.795 www 6608:
1.523 albertel 6609: .LC_answer_charged_try {
1.797 www 6610: background: #FFAAAA;
1.795 www 6611: color: darkred;
6612: padding: 6px;
1.523 albertel 6613: }
1.795 www 6614:
1.779 bisitz 6615: .LC_answer_not_charged_try,
1.523 albertel 6616: .LC_answer_no_grade,
6617: .LC_answer_late {
1.795 www 6618: background: lightyellow;
1.523 albertel 6619: color: black;
1.795 www 6620: padding: 6px;
1.523 albertel 6621: }
1.795 www 6622:
1.523 albertel 6623: .LC_answer_previous {
1.795 www 6624: background: lightblue;
6625: color: darkblue;
6626: padding: 6px;
1.523 albertel 6627: }
1.795 www 6628:
1.779 bisitz 6629: .LC_answer_no_message {
1.777 tempelho 6630: background: #FFFFFF;
6631: color: black;
1.795 www 6632: padding: 6px;
1.779 bisitz 6633: }
1.795 www 6634:
1.779 bisitz 6635: .LC_answer_unknown {
6636: background: orange;
6637: color: black;
1.795 www 6638: padding: 6px;
1.777 tempelho 6639: }
1.795 www 6640:
1.529 albertel 6641: span.LC_prior_numerical,
6642: span.LC_prior_string,
6643: span.LC_prior_custom,
6644: span.LC_prior_reaction,
6645: span.LC_prior_math {
1.925 bisitz 6646: font-family: $mono;
1.523 albertel 6647: white-space: pre;
6648: }
6649:
1.525 albertel 6650: span.LC_prior_string {
1.925 bisitz 6651: font-family: $mono;
1.525 albertel 6652: white-space: pre;
6653: }
6654:
1.523 albertel 6655: table.LC_prior_option {
6656: width: 100%;
6657: border-collapse: collapse;
6658: }
1.795 www 6659:
1.911 bisitz 6660: table.LC_prior_rank,
1.795 www 6661: table.LC_prior_match {
1.528 albertel 6662: border-collapse: collapse;
6663: }
1.795 www 6664:
1.528 albertel 6665: table.LC_prior_option tr td,
6666: table.LC_prior_rank tr td,
6667: table.LC_prior_match tr td {
1.524 albertel 6668: border: 1px solid #000000;
1.515 albertel 6669: }
6670:
1.855 bisitz 6671: .LC_nobreak {
1.544 albertel 6672: white-space: nowrap;
1.519 raeburn 6673: }
6674:
1.576 raeburn 6675: span.LC_cusr_emph {
6676: font-style: italic;
6677: }
6678:
1.633 raeburn 6679: span.LC_cusr_subheading {
6680: font-weight: normal;
6681: font-size: 85%;
6682: }
6683:
1.861 bisitz 6684: div.LC_docs_entry_move {
1.859 bisitz 6685: border: 1px solid #BBBBBB;
1.545 albertel 6686: background: #DDDDDD;
1.861 bisitz 6687: width: 22px;
1.859 bisitz 6688: padding: 1px;
6689: margin: 0;
1.545 albertel 6690: }
6691:
1.861 bisitz 6692: table.LC_data_table tr > td.LC_docs_entry_commands,
6693: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6694: font-size: x-small;
6695: }
1.795 www 6696:
1.861 bisitz 6697: .LC_docs_entry_parameter {
6698: white-space: nowrap;
6699: }
6700:
1.544 albertel 6701: .LC_docs_copy {
1.545 albertel 6702: color: #000099;
1.544 albertel 6703: }
1.795 www 6704:
1.544 albertel 6705: .LC_docs_cut {
1.545 albertel 6706: color: #550044;
1.544 albertel 6707: }
1.795 www 6708:
1.544 albertel 6709: .LC_docs_rename {
1.545 albertel 6710: color: #009900;
1.544 albertel 6711: }
1.795 www 6712:
1.544 albertel 6713: .LC_docs_remove {
1.545 albertel 6714: color: #990000;
6715: }
6716:
1.547 albertel 6717: .LC_docs_reinit_warn,
6718: .LC_docs_ext_edit {
6719: font-size: x-small;
6720: }
6721:
1.545 albertel 6722: table.LC_docs_adddocs td,
6723: table.LC_docs_adddocs th {
6724: border: 1px solid #BBBBBB;
6725: padding: 4px;
6726: background: #DDDDDD;
1.543 albertel 6727: }
6728:
1.584 albertel 6729: table.LC_sty_begin {
6730: background: #BBFFBB;
6731: }
1.795 www 6732:
1.584 albertel 6733: table.LC_sty_end {
6734: background: #FFBBBB;
6735: }
6736:
1.589 raeburn 6737: table.LC_double_column {
1.803 bisitz 6738: border-width: 0;
1.589 raeburn 6739: border-collapse: collapse;
6740: width: 100%;
6741: padding: 2px;
6742: }
6743:
6744: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6745: top: 2px;
1.589 raeburn 6746: left: 2px;
6747: width: 47%;
6748: vertical-align: top;
6749: }
6750:
6751: table.LC_double_column tr td.LC_right_col {
6752: top: 2px;
1.779 bisitz 6753: right: 2px;
1.589 raeburn 6754: width: 47%;
6755: vertical-align: top;
6756: }
6757:
1.591 raeburn 6758: div.LC_left_float {
6759: float: left;
6760: padding-right: 5%;
1.597 albertel 6761: padding-bottom: 4px;
1.591 raeburn 6762: }
6763:
6764: div.LC_clear_float_header {
1.597 albertel 6765: padding-bottom: 2px;
1.591 raeburn 6766: }
6767:
6768: div.LC_clear_float_footer {
1.597 albertel 6769: padding-top: 10px;
1.591 raeburn 6770: clear: both;
6771: }
6772:
1.597 albertel 6773: div.LC_grade_show_user {
1.941 bisitz 6774: /* border-left: 5px solid $sidebg; */
6775: border-top: 5px solid #000000;
6776: margin: 50px 0 0 0;
1.936 bisitz 6777: padding: 15px 0 5px 10px;
1.597 albertel 6778: }
1.795 www 6779:
1.936 bisitz 6780: div.LC_grade_show_user_odd_row {
1.941 bisitz 6781: /* border-left: 5px solid #000000; */
6782: }
6783:
6784: div.LC_grade_show_user div.LC_Box {
6785: margin-right: 50px;
1.597 albertel 6786: }
6787:
6788: div.LC_grade_submissions,
6789: div.LC_grade_message_center,
1.936 bisitz 6790: div.LC_grade_info_links {
1.597 albertel 6791: margin: 5px;
6792: width: 99%;
6793: background: #FFFFFF;
6794: }
1.795 www 6795:
1.597 albertel 6796: div.LC_grade_submissions_header,
1.936 bisitz 6797: div.LC_grade_message_center_header {
1.705 tempelho 6798: font-weight: bold;
6799: font-size: large;
1.597 albertel 6800: }
1.795 www 6801:
1.597 albertel 6802: div.LC_grade_submissions_body,
1.936 bisitz 6803: div.LC_grade_message_center_body {
1.597 albertel 6804: border: 1px solid black;
6805: width: 99%;
6806: background: #FFFFFF;
6807: }
1.795 www 6808:
1.613 albertel 6809: table.LC_scantron_action {
6810: width: 100%;
6811: }
1.795 www 6812:
1.613 albertel 6813: table.LC_scantron_action tr th {
1.698 harmsja 6814: font-weight:bold;
6815: font-style:normal;
1.613 albertel 6816: }
1.795 www 6817:
1.779 bisitz 6818: .LC_edit_problem_header,
1.614 albertel 6819: div.LC_edit_problem_footer {
1.705 tempelho 6820: font-weight: normal;
6821: font-size: medium;
1.602 albertel 6822: margin: 2px;
1.1060 bisitz 6823: background-color: $sidebg;
1.600 albertel 6824: }
1.795 www 6825:
1.600 albertel 6826: div.LC_edit_problem_header,
1.602 albertel 6827: div.LC_edit_problem_header div,
1.614 albertel 6828: div.LC_edit_problem_footer,
6829: div.LC_edit_problem_footer div,
1.602 albertel 6830: div.LC_edit_problem_editxml_header,
6831: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 6832: z-index: 100;
1.600 albertel 6833: }
1.795 www 6834:
1.600 albertel 6835: div.LC_edit_problem_header_title {
1.705 tempelho 6836: font-weight: bold;
6837: font-size: larger;
1.602 albertel 6838: background: $tabbg;
6839: padding: 3px;
1.1060 bisitz 6840: margin: 0 0 5px 0;
1.602 albertel 6841: }
1.795 www 6842:
1.602 albertel 6843: table.LC_edit_problem_header_title {
6844: width: 100%;
1.600 albertel 6845: background: $tabbg;
1.602 albertel 6846: }
6847:
1.1075.2.112 raeburn 6848: div.LC_edit_actionbar {
6849: background-color: $sidebg;
6850: margin: 0;
6851: padding: 0;
6852: line-height: 200%;
1.602 albertel 6853: }
1.795 www 6854:
1.1075.2.112 raeburn 6855: div.LC_edit_actionbar div{
6856: padding: 0;
6857: margin: 0;
6858: display: inline-block;
1.600 albertel 6859: }
1.795 www 6860:
1.1075.2.34 raeburn 6861: .LC_edit_opt {
6862: padding-left: 1em;
6863: white-space: nowrap;
6864: }
6865:
1.1075.2.57 raeburn 6866: .LC_edit_problem_latexhelper{
6867: text-align: right;
6868: }
6869:
6870: #LC_edit_problem_colorful div{
6871: margin-left: 40px;
6872: }
6873:
1.1075.2.112 raeburn 6874: #LC_edit_problem_codemirror div{
6875: margin-left: 0px;
6876: }
6877:
1.911 bisitz 6878: img.stift {
1.803 bisitz 6879: border-width: 0;
6880: vertical-align: middle;
1.677 riegler 6881: }
1.680 riegler 6882:
1.923 bisitz 6883: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6884: vertical-align: top;
1.777 tempelho 6885: }
1.795 www 6886:
1.716 raeburn 6887: div.LC_createcourse {
1.911 bisitz 6888: margin: 10px 10px 10px 10px;
1.716 raeburn 6889: }
6890:
1.917 raeburn 6891: .LC_dccid {
1.1075.2.38 raeburn 6892: float: right;
1.917 raeburn 6893: margin: 0.2em 0 0 0;
6894: padding: 0;
6895: font-size: 90%;
6896: display:none;
6897: }
6898:
1.897 wenzelju 6899: ol.LC_primary_menu a:hover,
1.721 harmsja 6900: ol#LC_MenuBreadcrumbs a:hover,
6901: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6902: ul#LC_secondary_menu a:hover,
1.721 harmsja 6903: .LC_FormSectionClearButton input:hover
1.795 www 6904: ul.LC_TabContent li:hover a {
1.952 onken 6905: color:$button_hover;
1.911 bisitz 6906: text-decoration:none;
1.693 droeschl 6907: }
6908:
1.779 bisitz 6909: h1 {
1.911 bisitz 6910: padding: 0;
6911: line-height:130%;
1.693 droeschl 6912: }
1.698 harmsja 6913:
1.911 bisitz 6914: h2,
6915: h3,
6916: h4,
6917: h5,
6918: h6 {
6919: margin: 5px 0 5px 0;
6920: padding: 0;
6921: line-height:130%;
1.693 droeschl 6922: }
1.795 www 6923:
6924: .LC_hcell {
1.911 bisitz 6925: padding:3px 15px 3px 15px;
6926: margin: 0;
6927: background-color:$tabbg;
6928: color:$fontmenu;
6929: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6930: }
1.795 www 6931:
1.840 bisitz 6932: .LC_Box > .LC_hcell {
1.911 bisitz 6933: margin: 0 -10px 10px -10px;
1.835 bisitz 6934: }
6935:
1.721 harmsja 6936: .LC_noBorder {
1.911 bisitz 6937: border: 0;
1.698 harmsja 6938: }
1.693 droeschl 6939:
1.721 harmsja 6940: .LC_FormSectionClearButton input {
1.911 bisitz 6941: background-color:transparent;
6942: border: none;
6943: cursor:pointer;
6944: text-decoration:underline;
1.693 droeschl 6945: }
1.763 bisitz 6946:
6947: .LC_help_open_topic {
1.911 bisitz 6948: color: #FFFFFF;
6949: background-color: #EEEEFF;
6950: margin: 1px;
6951: padding: 4px;
6952: border: 1px solid #000033;
6953: white-space: nowrap;
6954: /* vertical-align: middle; */
1.759 neumanie 6955: }
1.693 droeschl 6956:
1.911 bisitz 6957: dl,
6958: ul,
6959: div,
6960: fieldset {
6961: margin: 10px 10px 10px 0;
6962: /* overflow: hidden; */
1.693 droeschl 6963: }
1.795 www 6964:
1.1075.2.90 raeburn 6965: article.geogebraweb div {
6966: margin: 0;
6967: }
6968:
1.838 bisitz 6969: fieldset > legend {
1.911 bisitz 6970: font-weight: bold;
6971: padding: 0 5px 0 5px;
1.838 bisitz 6972: }
6973:
1.813 bisitz 6974: #LC_nav_bar {
1.911 bisitz 6975: float: left;
1.995 raeburn 6976: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6977: margin: 0 0 2px 0;
1.807 droeschl 6978: }
6979:
1.916 droeschl 6980: #LC_realm {
6981: margin: 0.2em 0 0 0;
6982: padding: 0;
6983: font-weight: bold;
6984: text-align: center;
1.995 raeburn 6985: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6986: }
6987:
1.911 bisitz 6988: #LC_nav_bar em {
6989: font-weight: bold;
6990: font-style: normal;
1.807 droeschl 6991: }
6992:
1.897 wenzelju 6993: ol.LC_primary_menu {
1.934 droeschl 6994: margin: 0;
1.1075.2.2 raeburn 6995: padding: 0;
1.807 droeschl 6996: }
6997:
1.852 droeschl 6998: ol#LC_PathBreadcrumbs {
1.911 bisitz 6999: margin: 0;
1.693 droeschl 7000: }
7001:
1.897 wenzelju 7002: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7003: color: RGB(80, 80, 80);
7004: vertical-align: middle;
7005: text-align: left;
7006: list-style: none;
1.1075.2.112 raeburn 7007: position: relative;
1.1075.2.2 raeburn 7008: float: left;
1.1075.2.112 raeburn 7009: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7010: line-height: 1.5em;
1.1075.2.2 raeburn 7011: }
7012:
1.1075.2.113! raeburn 7013: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7014: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7015: display: block;
7016: margin: 0;
7017: padding: 0 5px 0 10px;
7018: text-decoration: none;
7019: }
7020:
1.1075.2.112 raeburn 7021: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7022: display: inline-block;
7023: width: 95%;
7024: text-align: left;
7025: }
7026:
7027: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7028: display: inline-block;
7029: width: 5%;
7030: float: right;
7031: text-align: right;
7032: font-size: 70%;
7033: }
7034:
7035: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7036: display: none;
1.1075.2.112 raeburn 7037: width: 15em;
1.1075.2.2 raeburn 7038: background-color: $data_table_light;
1.1075.2.112 raeburn 7039: position: absolute;
7040: top: 100%;
7041: }
7042:
7043: ol.LC_primary_menu ul ul {
7044: left: 100%;
7045: top: 0;
1.1075.2.2 raeburn 7046: }
7047:
1.1075.2.112 raeburn 7048: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7049: display: block;
7050: position: absolute;
7051: margin: 0;
7052: padding: 0;
1.1075.2.5 raeburn 7053: z-index: 2;
1.1075.2.2 raeburn 7054: }
7055:
7056: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7057: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7058: font-size: 90%;
1.911 bisitz 7059: vertical-align: top;
1.1075.2.2 raeburn 7060: float: none;
1.1075.2.5 raeburn 7061: border-left: 1px solid black;
7062: border-right: 1px solid black;
1.1075.2.112 raeburn 7063: /* A dark bottom border to visualize different menu options;
7064: overwritten in the create_submenu routine for the last border-bottom of the menu */
7065: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7066: }
7067:
1.1075.2.112 raeburn 7068: ol.LC_primary_menu li li p:hover {
7069: color:$button_hover;
7070: text-decoration:none;
7071: background-color:$data_table_dark;
1.1075.2.2 raeburn 7072: }
7073:
7074: ol.LC_primary_menu li li a:hover {
7075: color:$button_hover;
7076: background-color:$data_table_dark;
1.693 droeschl 7077: }
7078:
1.1075.2.112 raeburn 7079: /* Font-size equal to the size of the predecessors*/
7080: ol.LC_primary_menu li:hover li li {
7081: font-size: 100%;
7082: }
7083:
1.897 wenzelju 7084: ol.LC_primary_menu li img {
1.911 bisitz 7085: vertical-align: bottom;
1.934 droeschl 7086: height: 1.1em;
1.1075.2.3 raeburn 7087: margin: 0.2em 0 0 0;
1.693 droeschl 7088: }
7089:
1.897 wenzelju 7090: ol.LC_primary_menu a {
1.911 bisitz 7091: color: RGB(80, 80, 80);
7092: text-decoration: none;
1.693 droeschl 7093: }
1.795 www 7094:
1.949 droeschl 7095: ol.LC_primary_menu a.LC_new_message {
7096: font-weight:bold;
7097: color: darkred;
7098: }
7099:
1.975 raeburn 7100: ol.LC_docs_parameters {
7101: margin-left: 0;
7102: padding: 0;
7103: list-style: none;
7104: }
7105:
7106: ol.LC_docs_parameters li {
7107: margin: 0;
7108: padding-right: 20px;
7109: display: inline;
7110: }
7111:
1.976 raeburn 7112: ol.LC_docs_parameters li:before {
7113: content: "\\002022 \\0020";
7114: }
7115:
7116: li.LC_docs_parameters_title {
7117: font-weight: bold;
7118: }
7119:
7120: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7121: content: "";
7122: }
7123:
1.897 wenzelju 7124: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7125: clear: right;
1.911 bisitz 7126: color: $fontmenu;
7127: background: $tabbg;
7128: list-style: none;
7129: padding: 0;
7130: margin: 0;
7131: width: 100%;
1.995 raeburn 7132: text-align: left;
1.1075.2.4 raeburn 7133: float: left;
1.808 droeschl 7134: }
7135:
1.897 wenzelju 7136: ul#LC_secondary_menu li {
1.911 bisitz 7137: font-weight: bold;
7138: line-height: 1.8em;
7139: border-right: 1px solid black;
1.1075.2.4 raeburn 7140: float: left;
7141: }
7142:
7143: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7144: background-color: $data_table_light;
7145: }
7146:
7147: ul#LC_secondary_menu li a {
7148: padding: 0 0.8em;
7149: }
7150:
7151: ul#LC_secondary_menu li ul {
7152: display: none;
7153: }
7154:
7155: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7156: display: block;
7157: position: absolute;
7158: margin: 0;
7159: padding: 0;
7160: list-style:none;
7161: float: none;
7162: background-color: $data_table_light;
1.1075.2.5 raeburn 7163: z-index: 2;
1.1075.2.10 raeburn 7164: margin-left: -1px;
1.1075.2.4 raeburn 7165: }
7166:
7167: ul#LC_secondary_menu li ul li {
7168: font-size: 90%;
7169: vertical-align: top;
7170: border-left: 1px solid black;
7171: border-right: 1px solid black;
1.1075.2.33 raeburn 7172: background-color: $data_table_light;
1.1075.2.4 raeburn 7173: list-style:none;
7174: float: none;
7175: }
7176:
7177: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7178: background-color: $data_table_dark;
1.807 droeschl 7179: }
7180:
1.847 tempelho 7181: ul.LC_TabContent {
1.911 bisitz 7182: display:block;
7183: background: $sidebg;
7184: border-bottom: solid 1px $lg_border_color;
7185: list-style:none;
1.1020 raeburn 7186: margin: -1px -10px 0 -10px;
1.911 bisitz 7187: padding: 0;
1.693 droeschl 7188: }
7189:
1.795 www 7190: ul.LC_TabContent li,
7191: ul.LC_TabContentBigger li {
1.911 bisitz 7192: float:left;
1.741 harmsja 7193: }
1.795 www 7194:
1.897 wenzelju 7195: ul#LC_secondary_menu li a {
1.911 bisitz 7196: color: $fontmenu;
7197: text-decoration: none;
1.693 droeschl 7198: }
1.795 www 7199:
1.721 harmsja 7200: ul.LC_TabContent {
1.952 onken 7201: min-height:20px;
1.721 harmsja 7202: }
1.795 www 7203:
7204: ul.LC_TabContent li {
1.911 bisitz 7205: vertical-align:middle;
1.959 onken 7206: padding: 0 16px 0 10px;
1.911 bisitz 7207: background-color:$tabbg;
7208: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7209: border-left: solid 1px $font;
1.721 harmsja 7210: }
1.795 www 7211:
1.847 tempelho 7212: ul.LC_TabContent .right {
1.911 bisitz 7213: float:right;
1.847 tempelho 7214: }
7215:
1.911 bisitz 7216: ul.LC_TabContent li a,
7217: ul.LC_TabContent li {
7218: color:rgb(47,47,47);
7219: text-decoration:none;
7220: font-size:95%;
7221: font-weight:bold;
1.952 onken 7222: min-height:20px;
7223: }
7224:
1.959 onken 7225: ul.LC_TabContent li a:hover,
7226: ul.LC_TabContent li a:focus {
1.952 onken 7227: color: $button_hover;
1.959 onken 7228: background:none;
7229: outline:none;
1.952 onken 7230: }
7231:
7232: ul.LC_TabContent li:hover {
7233: color: $button_hover;
7234: cursor:pointer;
1.721 harmsja 7235: }
1.795 www 7236:
1.911 bisitz 7237: ul.LC_TabContent li.active {
1.952 onken 7238: color: $font;
1.911 bisitz 7239: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7240: border-bottom:solid 1px #FFFFFF;
7241: cursor: default;
1.744 ehlerst 7242: }
1.795 www 7243:
1.959 onken 7244: ul.LC_TabContent li.active a {
7245: color:$font;
7246: background:#FFFFFF;
7247: outline: none;
7248: }
1.1047 raeburn 7249:
7250: ul.LC_TabContent li.goback {
7251: float: left;
7252: border-left: none;
7253: }
7254:
1.870 tempelho 7255: #maincoursedoc {
1.911 bisitz 7256: clear:both;
1.870 tempelho 7257: }
7258:
7259: ul.LC_TabContentBigger {
1.911 bisitz 7260: display:block;
7261: list-style:none;
7262: padding: 0;
1.870 tempelho 7263: }
7264:
1.795 www 7265: ul.LC_TabContentBigger li {
1.911 bisitz 7266: vertical-align:bottom;
7267: height: 30px;
7268: font-size:110%;
7269: font-weight:bold;
7270: color: #737373;
1.841 tempelho 7271: }
7272:
1.957 onken 7273: ul.LC_TabContentBigger li.active {
7274: position: relative;
7275: top: 1px;
7276: }
7277:
1.870 tempelho 7278: ul.LC_TabContentBigger li a {
1.911 bisitz 7279: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7280: height: 30px;
7281: line-height: 30px;
7282: text-align: center;
7283: display: block;
7284: text-decoration: none;
1.958 onken 7285: outline: none;
1.741 harmsja 7286: }
1.795 www 7287:
1.870 tempelho 7288: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7289: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7290: color:$font;
1.744 ehlerst 7291: }
1.795 www 7292:
1.870 tempelho 7293: ul.LC_TabContentBigger li b {
1.911 bisitz 7294: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7295: display: block;
7296: float: left;
7297: padding: 0 30px;
1.957 onken 7298: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7299: }
7300:
1.956 onken 7301: ul.LC_TabContentBigger li:hover b {
7302: color:$button_hover;
7303: }
7304:
1.870 tempelho 7305: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7306: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7307: color:$font;
1.957 onken 7308: border: 0;
1.741 harmsja 7309: }
1.693 droeschl 7310:
1.870 tempelho 7311:
1.862 bisitz 7312: ul.LC_CourseBreadcrumbs {
7313: background: $sidebg;
1.1020 raeburn 7314: height: 2em;
1.862 bisitz 7315: padding-left: 10px;
1.1020 raeburn 7316: margin: 0;
1.862 bisitz 7317: list-style-position: inside;
7318: }
7319:
1.911 bisitz 7320: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7321: ol#LC_PathBreadcrumbs {
1.911 bisitz 7322: padding-left: 10px;
7323: margin: 0;
1.933 droeschl 7324: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7325: }
7326:
1.911 bisitz 7327: ol#LC_MenuBreadcrumbs li,
7328: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7329: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7330: display: inline;
1.933 droeschl 7331: white-space: normal;
1.693 droeschl 7332: }
7333:
1.823 bisitz 7334: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7335: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7336: text-decoration: none;
7337: font-size:90%;
1.693 droeschl 7338: }
1.795 www 7339:
1.969 droeschl 7340: ol#LC_MenuBreadcrumbs h1 {
7341: display: inline;
7342: font-size: 90%;
7343: line-height: 2.5em;
7344: margin: 0;
7345: padding: 0;
7346: }
7347:
1.795 www 7348: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7349: text-decoration:none;
7350: font-size:100%;
7351: font-weight:bold;
1.693 droeschl 7352: }
1.795 www 7353:
1.840 bisitz 7354: .LC_Box {
1.911 bisitz 7355: border: solid 1px $lg_border_color;
7356: padding: 0 10px 10px 10px;
1.746 neumanie 7357: }
1.795 www 7358:
1.1020 raeburn 7359: .LC_DocsBox {
7360: border: solid 1px $lg_border_color;
7361: padding: 0 0 10px 10px;
7362: }
7363:
1.795 www 7364: .LC_AboutMe_Image {
1.911 bisitz 7365: float:left;
7366: margin-right:10px;
1.747 neumanie 7367: }
1.795 www 7368:
7369: .LC_Clear_AboutMe_Image {
1.911 bisitz 7370: clear:left;
1.747 neumanie 7371: }
1.795 www 7372:
1.721 harmsja 7373: dl.LC_ListStyleClean dt {
1.911 bisitz 7374: padding-right: 5px;
7375: display: table-header-group;
1.693 droeschl 7376: }
7377:
1.721 harmsja 7378: dl.LC_ListStyleClean dd {
1.911 bisitz 7379: display: table-row;
1.693 droeschl 7380: }
7381:
1.721 harmsja 7382: .LC_ListStyleClean,
7383: .LC_ListStyleSimple,
7384: .LC_ListStyleNormal,
1.795 www 7385: .LC_ListStyleSpecial {
1.911 bisitz 7386: /* display:block; */
7387: list-style-position: inside;
7388: list-style-type: none;
7389: overflow: hidden;
7390: padding: 0;
1.693 droeschl 7391: }
7392:
1.721 harmsja 7393: .LC_ListStyleSimple li,
7394: .LC_ListStyleSimple dd,
7395: .LC_ListStyleNormal li,
7396: .LC_ListStyleNormal dd,
7397: .LC_ListStyleSpecial li,
1.795 www 7398: .LC_ListStyleSpecial dd {
1.911 bisitz 7399: margin: 0;
7400: padding: 5px 5px 5px 10px;
7401: clear: both;
1.693 droeschl 7402: }
7403:
1.721 harmsja 7404: .LC_ListStyleClean li,
7405: .LC_ListStyleClean dd {
1.911 bisitz 7406: padding-top: 0;
7407: padding-bottom: 0;
1.693 droeschl 7408: }
7409:
1.721 harmsja 7410: .LC_ListStyleSimple dd,
1.795 www 7411: .LC_ListStyleSimple li {
1.911 bisitz 7412: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7413: }
7414:
1.721 harmsja 7415: .LC_ListStyleSpecial li,
7416: .LC_ListStyleSpecial dd {
1.911 bisitz 7417: list-style-type: none;
7418: background-color: RGB(220, 220, 220);
7419: margin-bottom: 4px;
1.693 droeschl 7420: }
7421:
1.721 harmsja 7422: table.LC_SimpleTable {
1.911 bisitz 7423: margin:5px;
7424: border:solid 1px $lg_border_color;
1.795 www 7425: }
1.693 droeschl 7426:
1.721 harmsja 7427: table.LC_SimpleTable tr {
1.911 bisitz 7428: padding: 0;
7429: border:solid 1px $lg_border_color;
1.693 droeschl 7430: }
1.795 www 7431:
7432: table.LC_SimpleTable thead {
1.911 bisitz 7433: background:rgb(220,220,220);
1.693 droeschl 7434: }
7435:
1.721 harmsja 7436: div.LC_columnSection {
1.911 bisitz 7437: display: block;
7438: clear: both;
7439: overflow: hidden;
7440: margin: 0;
1.693 droeschl 7441: }
7442:
1.721 harmsja 7443: div.LC_columnSection>* {
1.911 bisitz 7444: float: left;
7445: margin: 10px 20px 10px 0;
7446: overflow:hidden;
1.693 droeschl 7447: }
1.721 harmsja 7448:
1.795 www 7449: table em {
1.911 bisitz 7450: font-weight: bold;
7451: font-style: normal;
1.748 schulted 7452: }
1.795 www 7453:
1.779 bisitz 7454: table.LC_tableBrowseRes,
1.795 www 7455: table.LC_tableOfContent {
1.911 bisitz 7456: border:none;
7457: border-spacing: 1px;
7458: padding: 3px;
7459: background-color: #FFFFFF;
7460: font-size: 90%;
1.753 droeschl 7461: }
1.789 droeschl 7462:
1.911 bisitz 7463: table.LC_tableOfContent {
7464: border-collapse: collapse;
1.789 droeschl 7465: }
7466:
1.771 droeschl 7467: table.LC_tableBrowseRes a,
1.768 schulted 7468: table.LC_tableOfContent a {
1.911 bisitz 7469: background-color: transparent;
7470: text-decoration: none;
1.753 droeschl 7471: }
7472:
1.795 www 7473: table.LC_tableOfContent img {
1.911 bisitz 7474: border: none;
7475: height: 1.3em;
7476: vertical-align: text-bottom;
7477: margin-right: 0.3em;
1.753 droeschl 7478: }
1.757 schulted 7479:
1.795 www 7480: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7481: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7482: }
7483:
1.795 www 7484: a#LC_content_toolbar_everything {
1.911 bisitz 7485: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7486: }
7487:
1.795 www 7488: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7489: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7490: }
7491:
1.795 www 7492: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7493: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7494: }
7495:
1.795 www 7496: a#LC_content_toolbar_changefolder {
1.911 bisitz 7497: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7498: }
7499:
1.795 www 7500: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7501: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7502: }
7503:
1.1043 raeburn 7504: a#LC_content_toolbar_edittoplevel {
7505: background-image:url(/res/adm/pages/edittoplevel.gif);
7506: }
7507:
1.795 www 7508: ul#LC_toolbar li a:hover {
1.911 bisitz 7509: background-position: bottom center;
1.757 schulted 7510: }
7511:
1.795 www 7512: ul#LC_toolbar {
1.911 bisitz 7513: padding: 0;
7514: margin: 2px;
7515: list-style:none;
7516: position:relative;
7517: background-color:white;
1.1075.2.9 raeburn 7518: overflow: auto;
1.757 schulted 7519: }
7520:
1.795 www 7521: ul#LC_toolbar li {
1.911 bisitz 7522: border:1px solid white;
7523: padding: 0;
7524: margin: 0;
7525: float: left;
7526: display:inline;
7527: vertical-align:middle;
1.1075.2.9 raeburn 7528: white-space: nowrap;
1.911 bisitz 7529: }
1.757 schulted 7530:
1.783 amueller 7531:
1.795 www 7532: a.LC_toolbarItem {
1.911 bisitz 7533: display:block;
7534: padding: 0;
7535: margin: 0;
7536: height: 32px;
7537: width: 32px;
7538: color:white;
7539: border: none;
7540: background-repeat:no-repeat;
7541: background-color:transparent;
1.757 schulted 7542: }
7543:
1.915 droeschl 7544: ul.LC_funclist {
7545: margin: 0;
7546: padding: 0.5em 1em 0.5em 0;
7547: }
7548:
1.933 droeschl 7549: ul.LC_funclist > li:first-child {
7550: font-weight:bold;
7551: margin-left:0.8em;
7552: }
7553:
1.915 droeschl 7554: ul.LC_funclist + ul.LC_funclist {
7555: /*
7556: left border as a seperator if we have more than
7557: one list
7558: */
7559: border-left: 1px solid $sidebg;
7560: /*
7561: this hides the left border behind the border of the
7562: outer box if element is wrapped to the next 'line'
7563: */
7564: margin-left: -1px;
7565: }
7566:
1.843 bisitz 7567: ul.LC_funclist li {
1.915 droeschl 7568: display: inline;
1.782 bisitz 7569: white-space: nowrap;
1.915 droeschl 7570: margin: 0 0 0 25px;
7571: line-height: 150%;
1.782 bisitz 7572: }
7573:
1.974 wenzelju 7574: .LC_hidden {
7575: display: none;
7576: }
7577:
1.1030 www 7578: .LCmodal-overlay {
7579: position:fixed;
7580: top:0;
7581: right:0;
7582: bottom:0;
7583: left:0;
7584: height:100%;
7585: width:100%;
7586: margin:0;
7587: padding:0;
7588: background:#999;
7589: opacity:.75;
7590: filter: alpha(opacity=75);
7591: -moz-opacity: 0.75;
7592: z-index:101;
7593: }
7594:
7595: * html .LCmodal-overlay {
7596: position: absolute;
7597: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7598: }
7599:
7600: .LCmodal-window {
7601: position:fixed;
7602: top:50%;
7603: left:50%;
7604: margin:0;
7605: padding:0;
7606: z-index:102;
7607: }
7608:
7609: * html .LCmodal-window {
7610: position:absolute;
7611: }
7612:
7613: .LCclose-window {
7614: position:absolute;
7615: width:32px;
7616: height:32px;
7617: right:8px;
7618: top:8px;
7619: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7620: text-indent:-99999px;
7621: overflow:hidden;
7622: cursor:pointer;
7623: }
7624:
1.1075.2.17 raeburn 7625: /*
7626: styles used by TTH when "Default set of options to pass to tth/m
7627: when converting TeX" in course settings has been set
7628:
7629: option passed: -t
7630:
7631: */
7632:
7633: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7634: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7635: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7636: td div.norm {line-height:normal;}
7637:
7638: /*
7639: option passed -y3
7640: */
7641:
7642: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7643: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7644: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7645:
1.343 albertel 7646: END
7647: }
7648:
1.306 albertel 7649: =pod
7650:
7651: =item * &headtag()
7652:
7653: Returns a uniform footer for LON-CAPA web pages.
7654:
1.307 albertel 7655: Inputs: $title - optional title for the head
7656: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7657: $args - optional arguments
1.319 albertel 7658: force_register - if is true call registerurl so the remote is
7659: informed
1.415 albertel 7660: redirect -> array ref of
7661: 1- seconds before redirect occurs
7662: 2- url to redirect to
7663: 3- whether the side effect should occur
1.315 albertel 7664: (side effect of setting
7665: $env{'internal.head.redirect'} to the url
7666: redirected too)
1.352 albertel 7667: domain -> force to color decorate a page for a specific
7668: domain
7669: function -> force usage of a specific rolish color scheme
7670: bgcolor -> override the default page bgcolor
1.460 albertel 7671: no_auto_mt_title
7672: -> prevent &mt()ing the title arg
1.464 albertel 7673:
1.306 albertel 7674: =cut
7675:
7676: sub headtag {
1.313 albertel 7677: my ($title,$head_extra,$args) = @_;
1.306 albertel 7678:
1.363 albertel 7679: my $function = $args->{'function'} || &get_users_function();
7680: my $domain = $args->{'domain'} || &determinedomain();
7681: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7682: my $httphost = $args->{'use_absolute'};
1.418 albertel 7683: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7684: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7685: #time(),
1.418 albertel 7686: $env{'environment.color.timestamp'},
1.363 albertel 7687: $function,$domain,$bgcolor);
7688:
1.369 www 7689: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7690:
1.308 albertel 7691: my $result =
7692: '<head>'.
1.1075.2.56 raeburn 7693: &font_settings($args);
1.319 albertel 7694:
1.1075.2.72 raeburn 7695: my $inhibitprint;
7696: if ($args->{'print_suppress'}) {
7697: $inhibitprint = &print_suppression();
7698: }
1.1064 raeburn 7699:
1.461 albertel 7700: if (!$args->{'frameset'}) {
7701: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7702: }
1.1075.2.12 raeburn 7703: if ($args->{'force_register'}) {
7704: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7705: }
1.436 albertel 7706: if (!$args->{'no_nav_bar'}
7707: && !$args->{'only_body'}
7708: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7709: $result .= &help_menu_js($httphost);
1.1032 www 7710: $result.=&modal_window();
1.1038 www 7711: $result.=&togglebox_script();
1.1034 www 7712: $result.=&wishlist_window();
1.1041 www 7713: $result.=&LCprogressbarUpdate_script();
1.1034 www 7714: } else {
7715: if ($args->{'add_modal'}) {
7716: $result.=&modal_window();
7717: }
7718: if ($args->{'add_wishlist'}) {
7719: $result.=&wishlist_window();
7720: }
1.1038 www 7721: if ($args->{'add_togglebox'}) {
7722: $result.=&togglebox_script();
7723: }
1.1041 www 7724: if ($args->{'add_progressbar'}) {
7725: $result.=&LCprogressbarUpdate_script();
7726: }
1.436 albertel 7727: }
1.314 albertel 7728: if (ref($args->{'redirect'})) {
1.414 albertel 7729: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7730: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7731: if (!$inhibit_continue) {
7732: $env{'internal.head.redirect'} = $url;
7733: }
1.313 albertel 7734: $result.=<<ADDMETA
7735: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7736: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7737: ADDMETA
1.1075.2.89 raeburn 7738: } else {
7739: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
7740: my $requrl = $env{'request.uri'};
7741: if ($requrl eq '') {
7742: $requrl = $ENV{'REQUEST_URI'};
7743: $requrl =~ s/\?.+$//;
7744: }
7745: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
7746: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
7747: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
7748: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
7749: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
7750: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
7751: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
7752: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7753: if ($domdefs{'offloadnow'}{$lonhost}) {
7754: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
7755: if (($newserver) && ($newserver ne $lonhost)) {
7756: my $numsec = 5;
7757: my $timeout = $numsec * 1000;
7758: my ($newurl,$locknum,%locks,$msg);
7759: if ($env{'request.role.adv'}) {
7760: ($locknum,%locks) = &Apache::lonnet::get_locks();
7761: }
7762: my $disable_submit = 0;
7763: if ($requrl =~ /$LONCAPA::assess_re/) {
7764: $disable_submit = 1;
7765: }
7766: if ($locknum) {
7767: my @lockinfo = sort(values(%locks));
7768: $msg = &mt('Once the following tasks are complete: ')."\\n".
7769: join(", ",sort(values(%locks)))."\\n".
7770: &mt('your session will be transferred to a different server, after you click "Roles".');
7771: } else {
7772: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
7773: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
7774: }
7775: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
7776: $newurl = '/adm/switchserver?otherserver='.$newserver;
7777: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
7778: $newurl .= '&role='.$env{'request.role'};
7779: }
7780: if ($env{'request.symb'}) {
7781: $newurl .= '&symb='.$env{'request.symb'};
7782: } else {
7783: $newurl .= '&origurl='.$requrl;
7784: }
7785: }
1.1075.2.98 raeburn 7786: &js_escape(\$msg);
1.1075.2.89 raeburn 7787: $result.=<<OFFLOAD
7788: <meta http-equiv="pragma" content="no-cache" />
7789: <script type="text/javascript">
1.1075.2.92 raeburn 7790: // <![CDATA[
1.1075.2.89 raeburn 7791: function LC_Offload_Now() {
7792: var dest = "$newurl";
7793: if (dest != '') {
7794: window.location.href="$newurl";
7795: }
7796: }
1.1075.2.92 raeburn 7797: \$(document).ready(function () {
7798: window.alert('$msg');
7799: if ($disable_submit) {
1.1075.2.89 raeburn 7800: \$(".LC_hwk_submit").prop("disabled", true);
7801: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 7802: }
7803: setTimeout('LC_Offload_Now()', $timeout);
7804: });
7805: // ]]>
1.1075.2.89 raeburn 7806: </script>
7807: OFFLOAD
7808: }
7809: }
7810: }
7811: }
7812: }
7813: }
1.313 albertel 7814: }
1.306 albertel 7815: if (!defined($title)) {
7816: $title = 'The LearningOnline Network with CAPA';
7817: }
1.460 albertel 7818: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7819: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 7820: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7821: if (!$args->{'frameset'}) {
7822: $result .= ' /';
7823: }
7824: $result .= '>'
1.1064 raeburn 7825: .$inhibitprint
1.414 albertel 7826: .$head_extra;
1.1075.2.108 raeburn 7827: my $clientmobile;
7828: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
7829: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
7830: } else {
7831: $clientmobile = $env{'browser.mobile'};
7832: }
7833: if ($clientmobile) {
1.1075.2.42 raeburn 7834: $result .= '
7835: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7836: <meta name="apple-mobile-web-app-capable" content="yes" />';
7837: }
1.962 droeschl 7838: return $result.'</head>';
1.306 albertel 7839: }
7840:
7841: =pod
7842:
1.340 albertel 7843: =item * &font_settings()
7844:
7845: Returns neccessary <meta> to set the proper encoding
7846:
1.1075.2.56 raeburn 7847: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7848:
7849: =cut
7850:
7851: sub font_settings {
1.1075.2.56 raeburn 7852: my ($args) = @_;
1.340 albertel 7853: my $headerstring='';
1.1075.2.56 raeburn 7854: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7855: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 7856: $headerstring.=
1.1075.2.61 raeburn 7857: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7858: if (!$args->{'frameset'}) {
7859: $headerstring.= ' /';
7860: }
7861: $headerstring .= '>'."\n";
1.340 albertel 7862: }
7863: return $headerstring;
7864: }
7865:
1.341 albertel 7866: =pod
7867:
1.1064 raeburn 7868: =item * &print_suppression()
7869:
7870: In course context returns css which causes the body to be blank when media="print",
7871: if printout generation is unavailable for the current resource.
7872:
7873: This could be because:
7874:
7875: (a) printstartdate is in the future
7876:
7877: (b) printenddate is in the past
7878:
7879: (c) there is an active exam block with "printout"
7880: functionality blocked
7881:
7882: Users with pav, pfo or evb privileges are exempt.
7883:
7884: Inputs: none
7885:
7886: =cut
7887:
7888:
7889: sub print_suppression {
7890: my $noprint;
7891: if ($env{'request.course.id'}) {
7892: my $scope = $env{'request.course.id'};
7893: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7894: (&Apache::lonnet::allowed('pfo',$scope))) {
7895: return;
7896: }
7897: if ($env{'request.course.sec'} ne '') {
7898: $scope .= "/$env{'request.course.sec'}";
7899: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7900: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7901: return;
1.1064 raeburn 7902: }
7903: }
7904: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7905: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73 raeburn 7906: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 7907: if ($blocked) {
7908: my $checkrole = "cm./$cdom/$cnum";
7909: if ($env{'request.course.sec'} ne '') {
7910: $checkrole .= "/$env{'request.course.sec'}";
7911: }
7912: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7913: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7914: $noprint = 1;
7915: }
7916: }
7917: unless ($noprint) {
7918: my $symb = &Apache::lonnet::symbread();
7919: if ($symb ne '') {
7920: my $navmap = Apache::lonnavmaps::navmap->new();
7921: if (ref($navmap)) {
7922: my $res = $navmap->getBySymb($symb);
7923: if (ref($res)) {
7924: if (!$res->resprintable()) {
7925: $noprint = 1;
7926: }
7927: }
7928: }
7929: }
7930: }
7931: if ($noprint) {
7932: return <<"ENDSTYLE";
7933: <style type="text/css" media="print">
7934: body { display:none }
7935: </style>
7936: ENDSTYLE
7937: }
7938: }
7939: return;
7940: }
7941:
7942: =pod
7943:
1.341 albertel 7944: =item * &xml_begin()
7945:
7946: Returns the needed doctype and <html>
7947:
7948: Inputs: none
7949:
7950: =cut
7951:
7952: sub xml_begin {
1.1075.2.61 raeburn 7953: my ($is_frameset) = @_;
1.341 albertel 7954: my $output='';
7955:
7956: if ($env{'browser.mathml'}) {
7957: $output='<?xml version="1.0"?>'
7958: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7959: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7960:
7961: # .'<!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">] >'
7962: .'<!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">'
7963: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7964: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 7965: } elsif ($is_frameset) {
7966: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
7967: '<html>'."\n";
1.341 albertel 7968: } else {
1.1075.2.61 raeburn 7969: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
7970: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7971: }
7972: return $output;
7973: }
1.340 albertel 7974:
7975: =pod
7976:
1.306 albertel 7977: =item * &start_page()
7978:
7979: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7980:
1.648 raeburn 7981: Inputs:
7982:
7983: =over 4
7984:
7985: $title - optional title for the page
7986:
7987: $head_extra - optional extra HTML to incude inside the <head>
7988:
7989: $args - additional optional args supported are:
7990:
7991: =over 8
7992:
7993: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7994: arg on
1.814 bisitz 7995: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7996: add_entries -> additional attributes to add to the <body>
7997: domain -> force to color decorate a page for a
1.317 albertel 7998: specific domain
1.648 raeburn 7999: function -> force usage of a specific rolish color
1.317 albertel 8000: scheme
1.648 raeburn 8001: redirect -> see &headtag()
8002: bgcolor -> override the default page bg color
8003: js_ready -> return a string ready for being used in
1.317 albertel 8004: a javascript writeln
1.648 raeburn 8005: html_encode -> return a string ready for being used in
1.320 albertel 8006: a html attribute
1.648 raeburn 8007: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8008: $forcereg arg
1.648 raeburn 8009: frameset -> if true will start with a <frameset>
1.330 albertel 8010: rather than <body>
1.648 raeburn 8011: skip_phases -> hash ref of
1.338 albertel 8012: head -> skip the <html><head> generation
8013: body -> skip all <body> generation
1.1075.2.12 raeburn 8014: no_inline_link -> if true and in remote mode, don't show the
8015: 'Switch To Inline Menu' link
1.648 raeburn 8016: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8017: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8018: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.15 raeburn 8019: group -> includes the current group, if page is for a
8020: specific group
1.361 albertel 8021:
1.648 raeburn 8022: =back
1.460 albertel 8023:
1.648 raeburn 8024: =back
1.562 albertel 8025:
1.306 albertel 8026: =cut
8027:
8028: sub start_page {
1.309 albertel 8029: my ($title,$head_extra,$args) = @_;
1.318 albertel 8030: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8031:
1.315 albertel 8032: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 8033: my ($result,@advtools);
1.964 droeschl 8034:
1.338 albertel 8035: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8036: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8037: }
8038:
8039: if (! exists($args->{'skip_phases'}{'body'}) ) {
8040: if ($args->{'frameset'}) {
8041: my $attr_string = &make_attr_string($args->{'force_register'},
8042: $args->{'add_entries'});
8043: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8044: } else {
8045: $result .=
8046: &bodytag($title,
8047: $args->{'function'}, $args->{'add_entries'},
8048: $args->{'only_body'}, $args->{'domain'},
8049: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8050: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 8051: $args, \@advtools);
1.831 bisitz 8052: }
1.330 albertel 8053: }
1.338 albertel 8054:
1.315 albertel 8055: if ($args->{'js_ready'}) {
1.713 kaisler 8056: $result = &js_ready($result);
1.315 albertel 8057: }
1.320 albertel 8058: if ($args->{'html_encode'}) {
1.713 kaisler 8059: $result = &html_encode($result);
8060: }
8061:
1.813 bisitz 8062: # Preparation for new and consistent functionlist at top of screen
8063: # if ($args->{'functionlist'}) {
8064: # $result .= &build_functionlist();
8065: #}
8066:
1.964 droeschl 8067: # Don't add anything more if only_body wanted or in const space
8068: return $result if $args->{'only_body'}
8069: || $env{'request.state'} eq 'construct';
1.813 bisitz 8070:
8071: #Breadcrumbs
1.758 kaisler 8072: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8073: &Apache::lonhtmlcommon::clear_breadcrumbs();
8074: #if any br links exists, add them to the breadcrumbs
8075: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8076: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8077: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8078: }
8079: }
1.1075.2.19 raeburn 8080: # if @advtools array contains items add then to the breadcrumbs
8081: if (@advtools > 0) {
8082: &Apache::lonmenu::advtools_crumbs(@advtools);
8083: }
1.758 kaisler 8084:
8085: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8086: if(exists($args->{'bread_crumbs_component'})){
8087: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
8088: }else{
8089: $result .= &Apache::lonhtmlcommon::breadcrumbs();
8090: }
1.1075.2.24 raeburn 8091: } elsif (($env{'environment.remote'} eq 'on') &&
8092: ($env{'form.inhibitmenu'} ne 'yes') &&
8093: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8094: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8095: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8096: }
1.315 albertel 8097: return $result;
1.306 albertel 8098: }
8099:
8100: sub end_page {
1.315 albertel 8101: my ($args) = @_;
8102: $env{'internal.end_page'}++;
1.330 albertel 8103: my $result;
1.335 albertel 8104: if ($args->{'discussion'}) {
8105: my ($target,$parser);
8106: if (ref($args->{'discussion'})) {
8107: ($target,$parser) =($args->{'discussion'}{'target'},
8108: $args->{'discussion'}{'parser'});
8109: }
8110: $result .= &Apache::lonxml::xmlend($target,$parser);
8111: }
1.330 albertel 8112: if ($args->{'frameset'}) {
8113: $result .= '</frameset>';
8114: } else {
1.635 raeburn 8115: $result .= &endbodytag($args);
1.330 albertel 8116: }
1.1075.2.6 raeburn 8117: unless ($args->{'notbody'}) {
8118: $result .= "\n</html>";
8119: }
1.330 albertel 8120:
1.315 albertel 8121: if ($args->{'js_ready'}) {
1.317 albertel 8122: $result = &js_ready($result);
1.315 albertel 8123: }
1.335 albertel 8124:
1.320 albertel 8125: if ($args->{'html_encode'}) {
8126: $result = &html_encode($result);
8127: }
1.335 albertel 8128:
1.315 albertel 8129: return $result;
8130: }
8131:
1.1034 www 8132: sub wishlist_window {
8133: return(<<'ENDWISHLIST');
1.1046 raeburn 8134: <script type="text/javascript">
1.1034 www 8135: // <![CDATA[
8136: // <!-- BEGIN LON-CAPA Internal
8137: function set_wishlistlink(title, path) {
8138: if (!title) {
8139: title = document.title;
8140: title = title.replace(/^LON-CAPA /,'');
8141: }
1.1075.2.65 raeburn 8142: title = encodeURIComponent(title);
1.1075.2.83 raeburn 8143: title = title.replace("'","\\\'");
1.1034 www 8144: if (!path) {
8145: path = location.pathname;
8146: }
1.1075.2.65 raeburn 8147: path = encodeURIComponent(path);
1.1075.2.83 raeburn 8148: path = path.replace("'","\\\'");
1.1034 www 8149: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8150: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8151: }
8152: // END LON-CAPA Internal -->
8153: // ]]>
8154: </script>
8155: ENDWISHLIST
8156: }
8157:
1.1030 www 8158: sub modal_window {
8159: return(<<'ENDMODAL');
1.1046 raeburn 8160: <script type="text/javascript">
1.1030 www 8161: // <![CDATA[
8162: // <!-- BEGIN LON-CAPA Internal
8163: var modalWindow = {
8164: parent:"body",
8165: windowId:null,
8166: content:null,
8167: width:null,
8168: height:null,
8169: close:function()
8170: {
8171: $(".LCmodal-window").remove();
8172: $(".LCmodal-overlay").remove();
8173: },
8174: open:function()
8175: {
8176: var modal = "";
8177: modal += "<div class=\"LCmodal-overlay\"></div>";
8178: 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;\">";
8179: modal += this.content;
8180: modal += "</div>";
8181:
8182: $(this.parent).append(modal);
8183:
8184: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8185: $(".LCclose-window").click(function(){modalWindow.close();});
8186: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8187: }
8188: };
1.1075.2.42 raeburn 8189: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8190: {
1.1075.2.83 raeburn 8191: source = source.replace("'","'");
1.1030 www 8192: modalWindow.windowId = "myModal";
8193: modalWindow.width = width;
8194: modalWindow.height = height;
1.1075.2.80 raeburn 8195: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8196: modalWindow.open();
1.1075.2.87 raeburn 8197: };
1.1030 www 8198: // END LON-CAPA Internal -->
8199: // ]]>
8200: </script>
8201: ENDMODAL
8202: }
8203:
8204: sub modal_link {
1.1075.2.42 raeburn 8205: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8206: unless ($width) { $width=480; }
8207: unless ($height) { $height=400; }
1.1031 www 8208: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 8209: unless ($transparency) { $transparency='true'; }
8210:
1.1074 raeburn 8211: my $target_attr;
8212: if (defined($target)) {
8213: $target_attr = 'target="'.$target.'"';
8214: }
8215: return <<"ENDLINK";
1.1075.2.42 raeburn 8216: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8217: $linktext</a>
8218: ENDLINK
1.1030 www 8219: }
8220:
1.1032 www 8221: sub modal_adhoc_script {
8222: my ($funcname,$width,$height,$content)=@_;
8223: return (<<ENDADHOC);
1.1046 raeburn 8224: <script type="text/javascript">
1.1032 www 8225: // <![CDATA[
8226: var $funcname = function()
8227: {
8228: modalWindow.windowId = "myModal";
8229: modalWindow.width = $width;
8230: modalWindow.height = $height;
8231: modalWindow.content = '$content';
8232: modalWindow.open();
8233: };
8234: // ]]>
8235: </script>
8236: ENDADHOC
8237: }
8238:
1.1041 www 8239: sub modal_adhoc_inner {
8240: my ($funcname,$width,$height,$content)=@_;
8241: my $innerwidth=$width-20;
8242: $content=&js_ready(
1.1042 www 8243: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 8244: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8245: $content.
1.1041 www 8246: &end_scrollbox().
1.1075.2.42 raeburn 8247: &end_page()
1.1041 www 8248: );
8249: return &modal_adhoc_script($funcname,$width,$height,$content);
8250: }
8251:
8252: sub modal_adhoc_window {
8253: my ($funcname,$width,$height,$content,$linktext)=@_;
8254: return &modal_adhoc_inner($funcname,$width,$height,$content).
8255: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8256: }
8257:
8258: sub modal_adhoc_launch {
8259: my ($funcname,$width,$height,$content)=@_;
8260: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8261: <script type="text/javascript">
8262: // <![CDATA[
8263: $funcname();
8264: // ]]>
8265: </script>
8266: ENDLAUNCH
8267: }
8268:
8269: sub modal_adhoc_close {
8270: return (<<ENDCLOSE);
8271: <script type="text/javascript">
8272: // <![CDATA[
8273: modalWindow.close();
8274: // ]]>
8275: </script>
8276: ENDCLOSE
8277: }
8278:
1.1038 www 8279: sub togglebox_script {
8280: return(<<ENDTOGGLE);
8281: <script type="text/javascript">
8282: // <![CDATA[
8283: function LCtoggleDisplay(id,hidetext,showtext) {
8284: link = document.getElementById(id + "link").childNodes[0];
8285: with (document.getElementById(id).style) {
8286: if (display == "none" ) {
8287: display = "inline";
8288: link.nodeValue = hidetext;
8289: } else {
8290: display = "none";
8291: link.nodeValue = showtext;
8292: }
8293: }
8294: }
8295: // ]]>
8296: </script>
8297: ENDTOGGLE
8298: }
8299:
1.1039 www 8300: sub start_togglebox {
8301: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8302: unless ($heading) { $heading=''; } else { $heading.=' '; }
8303: unless ($showtext) { $showtext=&mt('show'); }
8304: unless ($hidetext) { $hidetext=&mt('hide'); }
8305: unless ($headerbg) { $headerbg='#FFFFFF'; }
8306: return &start_data_table().
8307: &start_data_table_header_row().
8308: '<td bgcolor="'.$headerbg.'">'.$heading.
8309: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8310: $showtext.'\')">'.$showtext.'</a>]</td>'.
8311: &end_data_table_header_row().
8312: '<tr id="'.$id.'" style="display:none""><td>';
8313: }
8314:
8315: sub end_togglebox {
8316: return '</td></tr>'.&end_data_table();
8317: }
8318:
1.1041 www 8319: sub LCprogressbar_script {
1.1045 www 8320: my ($id)=@_;
1.1041 www 8321: return(<<ENDPROGRESS);
8322: <script type="text/javascript">
8323: // <![CDATA[
1.1045 www 8324: \$('#progressbar$id').progressbar({
1.1041 www 8325: value: 0,
8326: change: function(event, ui) {
8327: var newVal = \$(this).progressbar('option', 'value');
8328: \$('.pblabel', this).text(LCprogressTxt);
8329: }
8330: });
8331: // ]]>
8332: </script>
8333: ENDPROGRESS
8334: }
8335:
8336: sub LCprogressbarUpdate_script {
8337: return(<<ENDPROGRESSUPDATE);
8338: <style type="text/css">
8339: .ui-progressbar { position:relative; }
8340: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8341: </style>
8342: <script type="text/javascript">
8343: // <![CDATA[
1.1045 www 8344: var LCprogressTxt='---';
8345:
8346: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8347: LCprogressTxt=progresstext;
1.1045 www 8348: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8349: }
8350: // ]]>
8351: </script>
8352: ENDPROGRESSUPDATE
8353: }
8354:
1.1042 www 8355: my $LClastpercent;
1.1045 www 8356: my $LCidcnt;
8357: my $LCcurrentid;
1.1042 www 8358:
1.1041 www 8359: sub LCprogressbar {
1.1042 www 8360: my ($r)=(@_);
8361: $LClastpercent=0;
1.1045 www 8362: $LCidcnt++;
8363: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8364: my $starting=&mt('Starting');
8365: my $content=(<<ENDPROGBAR);
1.1045 www 8366: <div id="progressbar$LCcurrentid">
1.1041 www 8367: <span class="pblabel">$starting</span>
8368: </div>
8369: ENDPROGBAR
1.1045 www 8370: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8371: }
8372:
8373: sub LCprogressbarUpdate {
1.1042 www 8374: my ($r,$val,$text)=@_;
8375: unless ($val) {
8376: if ($LClastpercent) {
8377: $val=$LClastpercent;
8378: } else {
8379: $val=0;
8380: }
8381: }
1.1041 www 8382: if ($val<0) { $val=0; }
8383: if ($val>100) { $val=0; }
1.1042 www 8384: $LClastpercent=$val;
1.1041 www 8385: unless ($text) { $text=$val.'%'; }
8386: $text=&js_ready($text);
1.1044 www 8387: &r_print($r,<<ENDUPDATE);
1.1041 www 8388: <script type="text/javascript">
8389: // <![CDATA[
1.1045 www 8390: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8391: // ]]>
8392: </script>
8393: ENDUPDATE
1.1035 www 8394: }
8395:
1.1042 www 8396: sub LCprogressbarClose {
8397: my ($r)=@_;
8398: $LClastpercent=0;
1.1044 www 8399: &r_print($r,<<ENDCLOSE);
1.1042 www 8400: <script type="text/javascript">
8401: // <![CDATA[
1.1045 www 8402: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8403: // ]]>
8404: </script>
8405: ENDCLOSE
1.1044 www 8406: }
8407:
8408: sub r_print {
8409: my ($r,$to_print)=@_;
8410: if ($r) {
8411: $r->print($to_print);
8412: $r->rflush();
8413: } else {
8414: print($to_print);
8415: }
1.1042 www 8416: }
8417:
1.320 albertel 8418: sub html_encode {
8419: my ($result) = @_;
8420:
1.322 albertel 8421: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8422:
8423: return $result;
8424: }
1.1044 www 8425:
1.317 albertel 8426: sub js_ready {
8427: my ($result) = @_;
8428:
1.323 albertel 8429: $result =~ s/[\n\r]/ /xmsg;
8430: $result =~ s/\\/\\\\/xmsg;
8431: $result =~ s/'/\\'/xmsg;
1.372 albertel 8432: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8433:
8434: return $result;
8435: }
8436:
1.315 albertel 8437: sub validate_page {
8438: if ( exists($env{'internal.start_page'})
1.316 albertel 8439: && $env{'internal.start_page'} > 1) {
8440: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8441: $env{'internal.start_page'}.' '.
1.316 albertel 8442: $ENV{'request.filename'});
1.315 albertel 8443: }
8444: if ( exists($env{'internal.end_page'})
1.316 albertel 8445: && $env{'internal.end_page'} > 1) {
8446: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8447: $env{'internal.end_page'}.' '.
1.316 albertel 8448: $env{'request.filename'});
1.315 albertel 8449: }
8450: if ( exists($env{'internal.start_page'})
8451: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8452: &Apache::lonnet::logthis('start_page called without end_page '.
8453: $env{'request.filename'});
1.315 albertel 8454: }
8455: if ( ! exists($env{'internal.start_page'})
8456: && exists($env{'internal.end_page'})) {
1.316 albertel 8457: &Apache::lonnet::logthis('end_page called without start_page'.
8458: $env{'request.filename'});
1.315 albertel 8459: }
1.306 albertel 8460: }
1.315 albertel 8461:
1.996 www 8462:
8463: sub start_scrollbox {
1.1075.2.56 raeburn 8464: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8465: unless ($outerwidth) { $outerwidth='520px'; }
8466: unless ($width) { $width='500px'; }
8467: unless ($height) { $height='200px'; }
1.1075 raeburn 8468: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8469: if ($id ne '') {
1.1075.2.42 raeburn 8470: $table_id = ' id="table_'.$id.'"';
8471: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8472: }
1.1075 raeburn 8473: if ($bgcolor ne '') {
8474: $tdcol = "background-color: $bgcolor;";
8475: }
1.1075.2.42 raeburn 8476: my $nicescroll_js;
8477: if ($env{'browser.mobile'}) {
8478: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8479: }
1.1075 raeburn 8480: return <<"END";
1.1075.2.42 raeburn 8481: $nicescroll_js
8482:
8483: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8484: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8485: END
1.996 www 8486: }
8487:
8488: sub end_scrollbox {
1.1036 www 8489: return '</div></td></tr></table>';
1.996 www 8490: }
8491:
1.1075.2.42 raeburn 8492: sub nicescroll_javascript {
8493: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8494: my %options;
8495: if (ref($cursor) eq 'HASH') {
8496: %options = %{$cursor};
8497: }
8498: unless ($options{'railalign'} =~ /^left|right$/) {
8499: $options{'railalign'} = 'left';
8500: }
8501: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8502: my $function = &get_users_function();
8503: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8504: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8505: $options{'cursorcolor'} = '#00F';
8506: }
8507: }
8508: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8509: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8510: $options{'cursoropacity'}='1.0';
8511: }
8512: } else {
8513: $options{'cursoropacity'}='1.0';
8514: }
8515: if ($options{'cursorfixedheight'} eq 'none') {
8516: delete($options{'cursorfixedheight'});
8517: } else {
8518: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8519: }
8520: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8521: delete($options{'railoffset'});
8522: }
8523: my @niceoptions;
8524: while (my($key,$value) = each(%options)) {
8525: if ($value =~ /^\{.+\}$/) {
8526: push(@niceoptions,$key.':'.$value);
8527: } else {
8528: push(@niceoptions,$key.':"'.$value.'"');
8529: }
8530: }
8531: my $nicescroll_js = '
8532: $(document).ready(
8533: function() {
8534: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8535: }
8536: );
8537: ';
8538: if ($framecheck) {
8539: $nicescroll_js .= '
8540: function expand_div(caller) {
8541: if (top === self) {
8542: document.getElementById("'.$id.'").style.width = "auto";
8543: document.getElementById("'.$id.'").style.height = "auto";
8544: } else {
8545: try {
8546: if (parent.frames) {
8547: if (parent.frames.length > 1) {
8548: var framesrc = parent.frames[1].location.href;
8549: var currsrc = framesrc.replace(/\#.*$/,"");
8550: if ((caller == "search") || (currsrc == "'.$location.'")) {
8551: document.getElementById("'.$id.'").style.width = "auto";
8552: document.getElementById("'.$id.'").style.height = "auto";
8553: }
8554: }
8555: }
8556: } catch (e) {
8557: return;
8558: }
8559: }
8560: return;
8561: }
8562: ';
8563: }
8564: if ($needjsready) {
8565: $nicescroll_js = '
8566: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8567: } else {
8568: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8569: }
8570: return $nicescroll_js;
8571: }
8572:
1.318 albertel 8573: sub simple_error_page {
1.1075.2.49 raeburn 8574: my ($r,$title,$msg,$args) = @_;
8575: if (ref($args) eq 'HASH') {
8576: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8577: } else {
8578: $msg = &mt($msg);
8579: }
8580:
1.318 albertel 8581: my $page =
8582: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8583: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8584: &Apache::loncommon::end_page();
8585: if (ref($r)) {
8586: $r->print($page);
1.327 albertel 8587: return;
1.318 albertel 8588: }
8589: return $page;
8590: }
1.347 albertel 8591:
8592: {
1.610 albertel 8593: my @row_count;
1.961 onken 8594:
8595: sub start_data_table_count {
8596: unshift(@row_count, 0);
8597: return;
8598: }
8599:
8600: sub end_data_table_count {
8601: shift(@row_count);
8602: return;
8603: }
8604:
1.347 albertel 8605: sub start_data_table {
1.1018 raeburn 8606: my ($add_class,$id) = @_;
1.422 albertel 8607: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8608: my $table_id;
8609: if (defined($id)) {
8610: $table_id = ' id="'.$id.'"';
8611: }
1.961 onken 8612: &start_data_table_count();
1.1018 raeburn 8613: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8614: }
8615:
8616: sub end_data_table {
1.961 onken 8617: &end_data_table_count();
1.389 albertel 8618: return '</table>'."\n";;
1.347 albertel 8619: }
8620:
8621: sub start_data_table_row {
1.974 wenzelju 8622: my ($add_class, $id) = @_;
1.610 albertel 8623: $row_count[0]++;
8624: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8625: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8626: $id = (' id="'.$id.'"') unless ($id eq '');
8627: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8628: }
1.471 banghart 8629:
8630: sub continue_data_table_row {
1.974 wenzelju 8631: my ($add_class, $id) = @_;
1.610 albertel 8632: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8633: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8634: $id = (' id="'.$id.'"') unless ($id eq '');
8635: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8636: }
1.347 albertel 8637:
8638: sub end_data_table_row {
1.389 albertel 8639: return '</tr>'."\n";;
1.347 albertel 8640: }
1.367 www 8641:
1.421 albertel 8642: sub start_data_table_empty_row {
1.707 bisitz 8643: # $row_count[0]++;
1.421 albertel 8644: return '<tr class="LC_empty_row" >'."\n";;
8645: }
8646:
8647: sub end_data_table_empty_row {
8648: return '</tr>'."\n";;
8649: }
8650:
1.367 www 8651: sub start_data_table_header_row {
1.389 albertel 8652: return '<tr class="LC_header_row">'."\n";;
1.367 www 8653: }
8654:
8655: sub end_data_table_header_row {
1.389 albertel 8656: return '</tr>'."\n";;
1.367 www 8657: }
1.890 droeschl 8658:
8659: sub data_table_caption {
8660: my $caption = shift;
8661: return "<caption class=\"LC_caption\">$caption</caption>";
8662: }
1.347 albertel 8663: }
8664:
1.548 albertel 8665: =pod
8666:
8667: =item * &inhibit_menu_check($arg)
8668:
8669: Checks for a inhibitmenu state and generates output to preserve it
8670:
8671: Inputs: $arg - can be any of
8672: - undef - in which case the return value is a string
8673: to add into arguments list of a uri
8674: - 'input' - in which case the return value is a HTML
8675: <form> <input> field of type hidden to
8676: preserve the value
8677: - a url - in which case the return value is the url with
8678: the neccesary cgi args added to preserve the
8679: inhibitmenu state
8680: - a ref to a url - no return value, but the string is
8681: updated to include the neccessary cgi
8682: args to preserve the inhibitmenu state
8683:
8684: =cut
8685:
8686: sub inhibit_menu_check {
8687: my ($arg) = @_;
8688: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8689: if ($arg eq 'input') {
8690: if ($env{'form.inhibitmenu'}) {
8691: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8692: } else {
8693: return
8694: }
8695: }
8696: if ($env{'form.inhibitmenu'}) {
8697: if (ref($arg)) {
8698: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8699: } elsif ($arg eq '') {
8700: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8701: } else {
8702: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8703: }
8704: }
8705: if (!ref($arg)) {
8706: return $arg;
8707: }
8708: }
8709:
1.251 albertel 8710: ###############################################
1.182 matthew 8711:
8712: =pod
8713:
1.549 albertel 8714: =back
8715:
8716: =head1 User Information Routines
8717:
8718: =over 4
8719:
1.405 albertel 8720: =item * &get_users_function()
1.182 matthew 8721:
8722: Used by &bodytag to determine the current users primary role.
8723: Returns either 'student','coordinator','admin', or 'author'.
8724:
8725: =cut
8726:
8727: ###############################################
8728: sub get_users_function {
1.815 tempelho 8729: my $function = 'norole';
1.818 tempelho 8730: if ($env{'request.role'}=~/^(st)/) {
8731: $function='student';
8732: }
1.907 raeburn 8733: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8734: $function='coordinator';
8735: }
1.258 albertel 8736: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8737: $function='admin';
8738: }
1.826 bisitz 8739: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8740: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8741: $function='author';
8742: }
8743: return $function;
1.54 www 8744: }
1.99 www 8745:
8746: ###############################################
8747:
1.233 raeburn 8748: =pod
8749:
1.821 raeburn 8750: =item * &show_course()
8751:
8752: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8753: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8754:
8755: Inputs:
8756: None
8757:
8758: Outputs:
8759: Scalar: 1 if 'Course' to be used, 0 otherwise.
8760:
8761: =cut
8762:
8763: ###############################################
8764: sub show_course {
8765: my $course = !$env{'user.adv'};
8766: if (!$env{'user.adv'}) {
8767: foreach my $env (keys(%env)) {
8768: next if ($env !~ m/^user\.priv\./);
8769: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8770: $course = 0;
8771: last;
8772: }
8773: }
8774: }
8775: return $course;
8776: }
8777:
8778: ###############################################
8779:
8780: =pod
8781:
1.542 raeburn 8782: =item * &check_user_status()
1.274 raeburn 8783:
8784: Determines current status of supplied role for a
8785: specific user. Roles can be active, previous or future.
8786:
8787: Inputs:
8788: user's domain, user's username, course's domain,
1.375 raeburn 8789: course's number, optional section ID.
1.274 raeburn 8790:
8791: Outputs:
8792: role status: active, previous or future.
8793:
8794: =cut
8795:
8796: sub check_user_status {
1.412 raeburn 8797: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8798: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 8799: my @uroles = keys(%userinfo);
1.274 raeburn 8800: my $srchstr;
8801: my $active_chk = 'none';
1.412 raeburn 8802: my $now = time;
1.274 raeburn 8803: if (@uroles > 0) {
1.908 raeburn 8804: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8805: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8806: } else {
1.412 raeburn 8807: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8808: }
8809: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8810: my $role_end = 0;
8811: my $role_start = 0;
8812: $active_chk = 'active';
1.412 raeburn 8813: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8814: $role_end = $1;
8815: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8816: $role_start = $1;
1.274 raeburn 8817: }
8818: }
8819: if ($role_start > 0) {
1.412 raeburn 8820: if ($now < $role_start) {
1.274 raeburn 8821: $active_chk = 'future';
8822: }
8823: }
8824: if ($role_end > 0) {
1.412 raeburn 8825: if ($now > $role_end) {
1.274 raeburn 8826: $active_chk = 'previous';
8827: }
8828: }
8829: }
8830: }
8831: return $active_chk;
8832: }
8833:
8834: ###############################################
8835:
8836: =pod
8837:
1.405 albertel 8838: =item * &get_sections()
1.233 raeburn 8839:
8840: Determines all the sections for a course including
8841: sections with students and sections containing other roles.
1.419 raeburn 8842: Incoming parameters:
8843:
8844: 1. domain
8845: 2. course number
8846: 3. reference to array containing roles for which sections should
8847: be gathered (optional).
8848: 4. reference to array containing status types for which sections
8849: should be gathered (optional).
8850:
8851: If the third argument is undefined, sections are gathered for any role.
8852: If the fourth argument is undefined, sections are gathered for any status.
8853: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8854:
1.374 raeburn 8855: Returns section hash (keys are section IDs, values are
8856: number of users in each section), subject to the
1.419 raeburn 8857: optional roles filter, optional status filter
1.233 raeburn 8858:
8859: =cut
8860:
8861: ###############################################
8862: sub get_sections {
1.419 raeburn 8863: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8864: if (!defined($cdom) || !defined($cnum)) {
8865: my $cid = $env{'request.course.id'};
8866:
8867: return if (!defined($cid));
8868:
8869: $cdom = $env{'course.'.$cid.'.domain'};
8870: $cnum = $env{'course.'.$cid.'.num'};
8871: }
8872:
8873: my %sectioncount;
1.419 raeburn 8874: my $now = time;
1.240 albertel 8875:
1.1075.2.33 raeburn 8876: my $check_students = 1;
8877: my $only_students = 0;
8878: if (ref($possible_roles) eq 'ARRAY') {
8879: if (grep(/^st$/,@{$possible_roles})) {
8880: if (@{$possible_roles} == 1) {
8881: $only_students = 1;
8882: }
8883: } else {
8884: $check_students = 0;
8885: }
8886: }
8887:
8888: if ($check_students) {
1.276 albertel 8889: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8890: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8891: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8892: my $start_index = &Apache::loncoursedata::CL_START();
8893: my $end_index = &Apache::loncoursedata::CL_END();
8894: my $status;
1.366 albertel 8895: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8896: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8897: $data->[$status_index],
8898: $data->[$start_index],
8899: $data->[$end_index]);
8900: if ($stu_status eq 'Active') {
8901: $status = 'active';
8902: } elsif ($end < $now) {
8903: $status = 'previous';
8904: } elsif ($start > $now) {
8905: $status = 'future';
8906: }
8907: if ($section ne '-1' && $section !~ /^\s*$/) {
8908: if ((!defined($possible_status)) || (($status ne '') &&
8909: (grep/^\Q$status\E$/,@{$possible_status}))) {
8910: $sectioncount{$section}++;
8911: }
1.240 albertel 8912: }
8913: }
8914: }
1.1075.2.33 raeburn 8915: if ($only_students) {
8916: return %sectioncount;
8917: }
1.240 albertel 8918: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8919: foreach my $user (sort(keys(%courseroles))) {
8920: if ($user !~ /^(\w{2})/) { next; }
8921: my ($role) = ($user =~ /^(\w{2})/);
8922: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8923: my ($section,$status);
1.240 albertel 8924: if ($role eq 'cr' &&
8925: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8926: $section=$1;
8927: }
8928: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8929: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8930: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8931: if ($end == -1 && $start == -1) {
8932: next; #deleted role
8933: }
8934: if (!defined($possible_status)) {
8935: $sectioncount{$section}++;
8936: } else {
8937: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8938: $status = 'active';
8939: } elsif ($end < $now) {
8940: $status = 'future';
8941: } elsif ($start > $now) {
8942: $status = 'previous';
8943: }
8944: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8945: $sectioncount{$section}++;
8946: }
8947: }
1.233 raeburn 8948: }
1.366 albertel 8949: return %sectioncount;
1.233 raeburn 8950: }
8951:
1.274 raeburn 8952: ###############################################
1.294 raeburn 8953:
8954: =pod
1.405 albertel 8955:
8956: =item * &get_course_users()
8957:
1.275 raeburn 8958: Retrieves usernames:domains for users in the specified course
8959: with specific role(s), and access status.
8960:
8961: Incoming parameters:
1.277 albertel 8962: 1. course domain
8963: 2. course number
8964: 3. access status: users must have - either active,
1.275 raeburn 8965: previous, future, or all.
1.277 albertel 8966: 4. reference to array of permissible roles
1.288 raeburn 8967: 5. reference to array of section restrictions (optional)
8968: 6. reference to results object (hash of hashes).
8969: 7. reference to optional userdata hash
1.609 raeburn 8970: 8. reference to optional statushash
1.630 raeburn 8971: 9. flag if privileged users (except those set to unhide in
8972: course settings) should be excluded
1.609 raeburn 8973: Keys of top level results hash are roles.
1.275 raeburn 8974: Keys of inner hashes are username:domain, with
8975: values set to access type.
1.288 raeburn 8976: Optional userdata hash returns an array with arguments in the
8977: same order as loncoursedata::get_classlist() for student data.
8978:
1.609 raeburn 8979: Optional statushash returns
8980:
1.288 raeburn 8981: Entries for end, start, section and status are blank because
8982: of the possibility of multiple values for non-student roles.
8983:
1.275 raeburn 8984: =cut
1.405 albertel 8985:
1.275 raeburn 8986: ###############################################
1.405 albertel 8987:
1.275 raeburn 8988: sub get_course_users {
1.630 raeburn 8989: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8990: my %idx = ();
1.419 raeburn 8991: my %seclists;
1.288 raeburn 8992:
8993: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8994: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8995: $idx{end} = &Apache::loncoursedata::CL_END();
8996: $idx{start} = &Apache::loncoursedata::CL_START();
8997: $idx{id} = &Apache::loncoursedata::CL_ID();
8998: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8999: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9000: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9001:
1.290 albertel 9002: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9003: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9004: my $now = time;
1.277 albertel 9005: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9006: my $match = 0;
1.412 raeburn 9007: my $secmatch = 0;
1.419 raeburn 9008: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9009: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9010: if ($section eq '') {
9011: $section = 'none';
9012: }
1.291 albertel 9013: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9014: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9015: $secmatch = 1;
9016: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9017: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9018: $secmatch = 1;
9019: }
9020: } else {
1.419 raeburn 9021: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9022: $secmatch = 1;
9023: }
1.290 albertel 9024: }
1.412 raeburn 9025: if (!$secmatch) {
9026: next;
9027: }
1.419 raeburn 9028: }
1.275 raeburn 9029: if (defined($$types{'active'})) {
1.288 raeburn 9030: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9031: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9032: $match = 1;
1.275 raeburn 9033: }
9034: }
9035: if (defined($$types{'previous'})) {
1.609 raeburn 9036: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9037: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9038: $match = 1;
1.275 raeburn 9039: }
9040: }
9041: if (defined($$types{'future'})) {
1.609 raeburn 9042: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9043: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9044: $match = 1;
1.275 raeburn 9045: }
9046: }
1.609 raeburn 9047: if ($match) {
9048: push(@{$seclists{$student}},$section);
9049: if (ref($userdata) eq 'HASH') {
9050: $$userdata{$student} = $$classlist{$student};
9051: }
9052: if (ref($statushash) eq 'HASH') {
9053: $statushash->{$student}{'st'}{$section} = $status;
9054: }
1.288 raeburn 9055: }
1.275 raeburn 9056: }
9057: }
1.412 raeburn 9058: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9059: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9060: my $now = time;
1.609 raeburn 9061: my %displaystatus = ( previous => 'Expired',
9062: active => 'Active',
9063: future => 'Future',
9064: );
1.1075.2.36 raeburn 9065: my (%nothide,@possdoms);
1.630 raeburn 9066: if ($hidepriv) {
9067: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9068: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9069: if ($user !~ /:/) {
9070: $nothide{join(':',split(/[\@]/,$user))}=1;
9071: } else {
9072: $nothide{$user} = 1;
9073: }
9074: }
1.1075.2.36 raeburn 9075: my @possdoms = ($cdom);
9076: if ($coursehash{'checkforpriv'}) {
9077: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9078: }
1.630 raeburn 9079: }
1.439 raeburn 9080: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9081: my $match = 0;
1.412 raeburn 9082: my $secmatch = 0;
1.439 raeburn 9083: my $status;
1.412 raeburn 9084: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9085: $user =~ s/:$//;
1.439 raeburn 9086: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9087: if ($end == -1 || $start == -1) {
9088: next;
9089: }
9090: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9091: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9092: my ($uname,$udom) = split(/:/,$user);
9093: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9094: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9095: $secmatch = 1;
9096: } elsif ($usec eq '') {
1.420 albertel 9097: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9098: $secmatch = 1;
9099: }
9100: } else {
9101: if (grep(/^\Q$usec\E$/,@{$sections})) {
9102: $secmatch = 1;
9103: }
9104: }
9105: if (!$secmatch) {
9106: next;
9107: }
1.288 raeburn 9108: }
1.419 raeburn 9109: if ($usec eq '') {
9110: $usec = 'none';
9111: }
1.275 raeburn 9112: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9113: if ($hidepriv) {
1.1075.2.36 raeburn 9114: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9115: (!$nothide{$uname.':'.$udom})) {
9116: next;
9117: }
9118: }
1.503 raeburn 9119: if ($end > 0 && $end < $now) {
1.439 raeburn 9120: $status = 'previous';
9121: } elsif ($start > $now) {
9122: $status = 'future';
9123: } else {
9124: $status = 'active';
9125: }
1.277 albertel 9126: foreach my $type (keys(%{$types})) {
1.275 raeburn 9127: if ($status eq $type) {
1.420 albertel 9128: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9129: push(@{$$users{$role}{$user}},$type);
9130: }
1.288 raeburn 9131: $match = 1;
9132: }
9133: }
1.419 raeburn 9134: if (($match) && (ref($userdata) eq 'HASH')) {
9135: if (!exists($$userdata{$uname.':'.$udom})) {
9136: &get_user_info($udom,$uname,\%idx,$userdata);
9137: }
1.420 albertel 9138: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9139: push(@{$seclists{$uname.':'.$udom}},$usec);
9140: }
1.609 raeburn 9141: if (ref($statushash) eq 'HASH') {
9142: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9143: }
1.275 raeburn 9144: }
9145: }
9146: }
9147: }
1.290 albertel 9148: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9149: if ((defined($cdom)) && (defined($cnum))) {
9150: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9151: if ( defined($csettings{'internal.courseowner'}) ) {
9152: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9153: next if ($owner eq '');
9154: my ($ownername,$ownerdom);
9155: if ($owner =~ /^([^:]+):([^:]+)$/) {
9156: $ownername = $1;
9157: $ownerdom = $2;
9158: } else {
9159: $ownername = $owner;
9160: $ownerdom = $cdom;
9161: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9162: }
9163: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9164: if (defined($userdata) &&
1.609 raeburn 9165: !exists($$userdata{$owner})) {
9166: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9167: if (!grep(/^none$/,@{$seclists{$owner}})) {
9168: push(@{$seclists{$owner}},'none');
9169: }
9170: if (ref($statushash) eq 'HASH') {
9171: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9172: }
1.290 albertel 9173: }
1.279 raeburn 9174: }
9175: }
9176: }
1.419 raeburn 9177: foreach my $user (keys(%seclists)) {
9178: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9179: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9180: }
1.275 raeburn 9181: }
9182: return;
9183: }
9184:
1.288 raeburn 9185: sub get_user_info {
9186: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9187: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9188: &plainname($uname,$udom,'lastname');
1.291 albertel 9189: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9190: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9191: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9192: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9193: return;
9194: }
1.275 raeburn 9195:
1.472 raeburn 9196: ###############################################
9197:
9198: =pod
9199:
9200: =item * &get_user_quota()
9201:
1.1075.2.41 raeburn 9202: Retrieves quota assigned for storage of user files.
9203: Default is to report quota for portfolio files.
1.472 raeburn 9204:
9205: Incoming parameters:
9206: 1. user's username
9207: 2. user's domain
1.1075.2.41 raeburn 9208: 3. quota name - portfolio, author, or course
9209: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 9210: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 9211: course
1.472 raeburn 9212:
9213: Returns:
1.1075.2.58 raeburn 9214: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9215: 2. (Optional) Type of setting: custom or default
9216: (individually assigned or default for user's
9217: institutional status).
9218: 3. (Optional) - User's institutional status (e.g., faculty, staff
9219: or student - types as defined in localenroll::inst_usertypes
9220: for user's domain, which determines default quota for user.
9221: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9222:
9223: If a value has been stored in the user's environment,
1.536 raeburn 9224: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 9225: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9226:
9227: =cut
9228:
9229: ###############################################
9230:
9231:
9232: sub get_user_quota {
1.1075.2.42 raeburn 9233: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9234: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9235: if (!defined($udom)) {
9236: $udom = $env{'user.domain'};
9237: }
9238: if (!defined($uname)) {
9239: $uname = $env{'user.name'};
9240: }
9241: if (($udom eq '' || $uname eq '') ||
9242: ($udom eq 'public') && ($uname eq 'public')) {
9243: $quota = 0;
1.536 raeburn 9244: $quotatype = 'default';
9245: $defquota = 0;
1.472 raeburn 9246: } else {
1.536 raeburn 9247: my $inststatus;
1.1075.2.41 raeburn 9248: if ($quotaname eq 'course') {
9249: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9250: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9251: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9252: } else {
9253: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9254: $quota = $cenv{'internal.uploadquota'};
9255: }
1.536 raeburn 9256: } else {
1.1075.2.41 raeburn 9257: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9258: if ($quotaname eq 'author') {
9259: $quota = $env{'environment.authorquota'};
9260: } else {
9261: $quota = $env{'environment.portfolioquota'};
9262: }
9263: $inststatus = $env{'environment.inststatus'};
9264: } else {
9265: my %userenv =
9266: &Apache::lonnet::get('environment',['portfolioquota',
9267: 'authorquota','inststatus'],$udom,$uname);
9268: my ($tmp) = keys(%userenv);
9269: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9270: if ($quotaname eq 'author') {
9271: $quota = $userenv{'authorquota'};
9272: } else {
9273: $quota = $userenv{'portfolioquota'};
9274: }
9275: $inststatus = $userenv{'inststatus'};
9276: } else {
9277: undef(%userenv);
9278: }
9279: }
9280: }
9281: if ($quota eq '' || wantarray) {
9282: if ($quotaname eq 'course') {
9283: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9284: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9285: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9286: $defquota = $domdefs{$crstype.'quota'};
9287: }
9288: if ($defquota eq '') {
9289: $defquota = 500;
9290: }
1.1075.2.41 raeburn 9291: } else {
9292: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9293: }
9294: if ($quota eq '') {
9295: $quota = $defquota;
9296: $quotatype = 'default';
9297: } else {
9298: $quotatype = 'custom';
9299: }
1.472 raeburn 9300: }
9301: }
1.536 raeburn 9302: if (wantarray) {
9303: return ($quota,$quotatype,$settingstatus,$defquota);
9304: } else {
9305: return $quota;
9306: }
1.472 raeburn 9307: }
9308:
9309: ###############################################
9310:
9311: =pod
9312:
9313: =item * &default_quota()
9314:
1.536 raeburn 9315: Retrieves default quota assigned for storage of user portfolio files,
9316: given an (optional) user's institutional status.
1.472 raeburn 9317:
9318: Incoming parameters:
1.1075.2.42 raeburn 9319:
1.472 raeburn 9320: 1. domain
1.536 raeburn 9321: 2. (Optional) institutional status(es). This is a : separated list of
9322: status types (e.g., faculty, staff, student etc.)
9323: which apply to the user for whom the default is being retrieved.
9324: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9325: default quota will be returned.
9326: 3. quota name - portfolio, author, or course
9327: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9328:
9329: Returns:
1.1075.2.42 raeburn 9330:
1.1075.2.58 raeburn 9331: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9332: 2. (Optional) institutional type which determined the value of the
9333: default quota.
1.472 raeburn 9334:
9335: If a value has been stored in the domain's configuration db,
9336: it will return that, otherwise it returns 20 (for backwards
9337: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9338: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9339:
1.536 raeburn 9340: If the user's status includes multiple types (e.g., staff and student),
9341: the largest default quota which applies to the user determines the
9342: default quota returned.
9343:
1.472 raeburn 9344: =cut
9345:
9346: ###############################################
9347:
9348:
9349: sub default_quota {
1.1075.2.41 raeburn 9350: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9351: my ($defquota,$settingstatus);
9352: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9353: ['quotas'],$udom);
1.1075.2.41 raeburn 9354: my $key = 'defaultquota';
9355: if ($quotaname eq 'author') {
9356: $key = 'authorquota';
9357: }
1.622 raeburn 9358: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9359: if ($inststatus ne '') {
1.765 raeburn 9360: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9361: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9362: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9363: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9364: if ($defquota eq '') {
1.1075.2.41 raeburn 9365: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9366: $settingstatus = $item;
1.1075.2.41 raeburn 9367: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9368: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9369: $settingstatus = $item;
9370: }
9371: }
1.1075.2.41 raeburn 9372: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9373: if ($quotahash{'quotas'}{$item} ne '') {
9374: if ($defquota eq '') {
9375: $defquota = $quotahash{'quotas'}{$item};
9376: $settingstatus = $item;
9377: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9378: $defquota = $quotahash{'quotas'}{$item};
9379: $settingstatus = $item;
9380: }
1.536 raeburn 9381: }
9382: }
9383: }
9384: }
9385: if ($defquota eq '') {
1.1075.2.41 raeburn 9386: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9387: $defquota = $quotahash{'quotas'}{$key}{'default'};
9388: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9389: $defquota = $quotahash{'quotas'}{'default'};
9390: }
1.536 raeburn 9391: $settingstatus = 'default';
1.1075.2.42 raeburn 9392: if ($defquota eq '') {
9393: if ($quotaname eq 'author') {
9394: $defquota = 500;
9395: }
9396: }
1.536 raeburn 9397: }
9398: } else {
9399: $settingstatus = 'default';
1.1075.2.41 raeburn 9400: if ($quotaname eq 'author') {
9401: $defquota = 500;
9402: } else {
9403: $defquota = 20;
9404: }
1.536 raeburn 9405: }
9406: if (wantarray) {
9407: return ($defquota,$settingstatus);
1.472 raeburn 9408: } else {
1.536 raeburn 9409: return $defquota;
1.472 raeburn 9410: }
9411: }
9412:
1.1075.2.41 raeburn 9413: ###############################################
9414:
9415: =pod
9416:
1.1075.2.42 raeburn 9417: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9418:
9419: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9420: of existing file within authoring space will cause quota for the authoring
9421: space to be exceeded.
9422:
9423: Same, if upload of a file directly to a course/community via Course Editor
9424: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9425:
1.1075.2.61 raeburn 9426: Inputs: 7
1.1075.2.42 raeburn 9427: 1. username or coursenum
1.1075.2.41 raeburn 9428: 2. domain
1.1075.2.42 raeburn 9429: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9430: 4. filename of file for which action is being requested
9431: 5. filesize (kB) of file
9432: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9433: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9434:
9435: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9436: otherwise return null.
9437:
1.1075.2.42 raeburn 9438: =back
9439:
1.1075.2.41 raeburn 9440: =cut
9441:
1.1075.2.42 raeburn 9442: sub excess_filesize_warning {
1.1075.2.59 raeburn 9443: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9444: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9445: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9446: if ($context eq 'author') {
9447: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9448: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9449: } else {
9450: foreach my $subdir ('docs','supplemental') {
9451: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9452: }
9453: }
1.1075.2.41 raeburn 9454: $disk_quota = int($disk_quota * 1000);
9455: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9456: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9457: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9458: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9459: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9460: $disk_quota,$current_disk_usage).
9461: '</p>';
9462: }
9463: return;
9464: }
9465:
9466: ###############################################
9467:
9468:
1.384 raeburn 9469: sub get_secgrprole_info {
9470: my ($cdom,$cnum,$needroles,$type) = @_;
9471: my %sections_count = &get_sections($cdom,$cnum);
9472: my @sections = (sort {$a <=> $b} keys(%sections_count));
9473: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9474: my @groups = sort(keys(%curr_groups));
9475: my $allroles = [];
9476: my $rolehash;
9477: my $accesshash = {
9478: active => 'Currently has access',
9479: future => 'Will have future access',
9480: previous => 'Previously had access',
9481: };
9482: if ($needroles) {
9483: $rolehash = {'all' => 'all'};
1.385 albertel 9484: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9485: if (&Apache::lonnet::error(%user_roles)) {
9486: undef(%user_roles);
9487: }
9488: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9489: my ($role)=split(/\:/,$item,2);
9490: if ($role eq 'cr') { next; }
9491: if ($role =~ /^cr/) {
9492: $$rolehash{$role} = (split('/',$role))[3];
9493: } else {
9494: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9495: }
9496: }
9497: foreach my $key (sort(keys(%{$rolehash}))) {
9498: push(@{$allroles},$key);
9499: }
9500: push (@{$allroles},'st');
9501: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9502: }
9503: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9504: }
9505:
1.555 raeburn 9506: sub user_picker {
1.994 raeburn 9507: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 9508: my $currdom = $dom;
9509: my %curr_selected = (
9510: srchin => 'dom',
1.580 raeburn 9511: srchby => 'lastname',
1.555 raeburn 9512: );
9513: my $srchterm;
1.625 raeburn 9514: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9515: if ($srch->{'srchby'} ne '') {
9516: $curr_selected{'srchby'} = $srch->{'srchby'};
9517: }
9518: if ($srch->{'srchin'} ne '') {
9519: $curr_selected{'srchin'} = $srch->{'srchin'};
9520: }
9521: if ($srch->{'srchtype'} ne '') {
9522: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9523: }
9524: if ($srch->{'srchdomain'} ne '') {
9525: $currdom = $srch->{'srchdomain'};
9526: }
9527: $srchterm = $srch->{'srchterm'};
9528: }
1.1075.2.98 raeburn 9529: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9530: 'usr' => 'Search criteria',
1.563 raeburn 9531: 'doma' => 'Domain/institution to search',
1.558 albertel 9532: 'uname' => 'username',
9533: 'lastname' => 'last name',
1.555 raeburn 9534: 'lastfirst' => 'last name, first name',
1.558 albertel 9535: 'crs' => 'in this course',
1.576 raeburn 9536: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9537: 'alc' => 'all LON-CAPA',
1.573 raeburn 9538: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9539: 'exact' => 'is',
9540: 'contains' => 'contains',
1.569 raeburn 9541: 'begins' => 'begins with',
1.1075.2.98 raeburn 9542: );
9543: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9544: 'youm' => "You must include some text to search for.",
9545: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9546: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9547: 'yomc' => "You must choose a domain when using an institutional directory search.",
9548: 'ymcd' => "You must choose a domain when using a domain search.",
9549: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9550: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9551: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9552: );
1.1075.2.98 raeburn 9553: &html_escape(\%html_lt);
9554: &js_escape(\%js_lt);
1.563 raeburn 9555: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9556: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9557:
9558: my @srchins = ('crs','dom','alc','instd');
9559:
9560: foreach my $option (@srchins) {
9561: # FIXME 'alc' option unavailable until
9562: # loncreateuser::print_user_query_page()
9563: # has been completed.
9564: next if ($option eq 'alc');
1.880 raeburn 9565: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9566: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9567: if ($curr_selected{'srchin'} eq $option) {
9568: $srchinsel .= '
1.1075.2.98 raeburn 9569: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 9570: } else {
9571: $srchinsel .= '
1.1075.2.98 raeburn 9572: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 9573: }
1.555 raeburn 9574: }
1.563 raeburn 9575: $srchinsel .= "\n </select>\n";
1.555 raeburn 9576:
9577: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9578: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9579: if ($curr_selected{'srchby'} eq $option) {
9580: $srchbysel .= '
1.1075.2.98 raeburn 9581: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9582: } else {
9583: $srchbysel .= '
1.1075.2.98 raeburn 9584: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9585: }
9586: }
9587: $srchbysel .= "\n </select>\n";
9588:
9589: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9590: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9591: if ($curr_selected{'srchtype'} eq $option) {
9592: $srchtypesel .= '
1.1075.2.98 raeburn 9593: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9594: } else {
9595: $srchtypesel .= '
1.1075.2.98 raeburn 9596: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9597: }
9598: }
9599: $srchtypesel .= "\n </select>\n";
9600:
1.558 albertel 9601: my ($newuserscript,$new_user_create);
1.994 raeburn 9602: my $context_dom = $env{'request.role.domain'};
9603: if ($context eq 'requestcrs') {
9604: if ($env{'form.coursedom'} ne '') {
9605: $context_dom = $env{'form.coursedom'};
9606: }
9607: }
1.556 raeburn 9608: if ($forcenewuser) {
1.576 raeburn 9609: if (ref($srch) eq 'HASH') {
1.994 raeburn 9610: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9611: if ($cancreate) {
9612: $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>';
9613: } else {
1.799 bisitz 9614: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9615: my %usertypetext = (
9616: official => 'institutional',
9617: unofficial => 'non-institutional',
9618: );
1.799 bisitz 9619: $new_user_create = '<p class="LC_warning">'
9620: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9621: .' '
9622: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9623: ,'<a href="'.$helplink.'">','</a>')
9624: .'</p><br />';
1.627 raeburn 9625: }
1.576 raeburn 9626: }
9627: }
9628:
1.556 raeburn 9629: $newuserscript = <<"ENDSCRIPT";
9630:
1.570 raeburn 9631: function setSearch(createnew,callingForm) {
1.556 raeburn 9632: if (createnew == 1) {
1.570 raeburn 9633: for (var i=0; i<callingForm.srchby.length; i++) {
9634: if (callingForm.srchby.options[i].value == 'uname') {
9635: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9636: }
9637: }
1.570 raeburn 9638: for (var i=0; i<callingForm.srchin.length; i++) {
9639: if ( callingForm.srchin.options[i].value == 'dom') {
9640: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9641: }
9642: }
1.570 raeburn 9643: for (var i=0; i<callingForm.srchtype.length; i++) {
9644: if (callingForm.srchtype.options[i].value == 'exact') {
9645: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9646: }
9647: }
1.570 raeburn 9648: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9649: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9650: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9651: }
9652: }
9653: }
9654: }
9655: ENDSCRIPT
1.558 albertel 9656:
1.556 raeburn 9657: }
9658:
1.555 raeburn 9659: my $output = <<"END_BLOCK";
1.556 raeburn 9660: <script type="text/javascript">
1.824 bisitz 9661: // <![CDATA[
1.570 raeburn 9662: function validateEntry(callingForm) {
1.558 albertel 9663:
1.556 raeburn 9664: var checkok = 1;
1.558 albertel 9665: var srchin;
1.570 raeburn 9666: for (var i=0; i<callingForm.srchin.length; i++) {
9667: if ( callingForm.srchin[i].checked ) {
9668: srchin = callingForm.srchin[i].value;
1.558 albertel 9669: }
9670: }
9671:
1.570 raeburn 9672: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9673: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9674: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9675: var srchterm = callingForm.srchterm.value;
9676: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9677: var msg = "";
9678:
9679: if (srchterm == "") {
9680: checkok = 0;
1.1075.2.98 raeburn 9681: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 9682: }
9683:
1.569 raeburn 9684: if (srchtype== 'begins') {
9685: if (srchterm.length < 2) {
9686: checkok = 0;
1.1075.2.98 raeburn 9687: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 9688: }
9689: }
9690:
1.556 raeburn 9691: if (srchtype== 'contains') {
9692: if (srchterm.length < 3) {
9693: checkok = 0;
1.1075.2.98 raeburn 9694: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 9695: }
9696: }
9697: if (srchin == 'instd') {
9698: if (srchdomain == '') {
9699: checkok = 0;
1.1075.2.98 raeburn 9700: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 9701: }
9702: }
9703: if (srchin == 'dom') {
9704: if (srchdomain == '') {
9705: checkok = 0;
1.1075.2.98 raeburn 9706: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 9707: }
9708: }
9709: if (srchby == 'lastfirst') {
9710: if (srchterm.indexOf(",") == -1) {
9711: checkok = 0;
1.1075.2.98 raeburn 9712: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 9713: }
9714: if (srchterm.indexOf(",") == srchterm.length -1) {
9715: checkok = 0;
1.1075.2.98 raeburn 9716: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 9717: }
9718: }
9719: if (checkok == 0) {
1.1075.2.98 raeburn 9720: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 9721: return;
9722: }
9723: if (checkok == 1) {
1.570 raeburn 9724: callingForm.submit();
1.556 raeburn 9725: }
9726: }
9727:
9728: $newuserscript
9729:
1.824 bisitz 9730: // ]]>
1.556 raeburn 9731: </script>
1.558 albertel 9732:
9733: $new_user_create
9734:
1.555 raeburn 9735: END_BLOCK
1.558 albertel 9736:
1.876 raeburn 9737: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 9738: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 9739: $domform.
9740: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 9741: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 9742: $srchbysel.
9743: $srchtypesel.
9744: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9745: $srchinsel.
9746: &Apache::lonhtmlcommon::row_closure(1).
9747: &Apache::lonhtmlcommon::end_pick_box().
9748: '<br />';
1.555 raeburn 9749: return $output;
9750: }
9751:
1.612 raeburn 9752: sub user_rule_check {
1.615 raeburn 9753: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 9754: my ($response,%inst_response);
1.612 raeburn 9755: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 9756: if (keys(%{$usershash}) > 1) {
9757: my (%by_username,%by_id,%userdoms);
9758: my $checkid;
1.612 raeburn 9759: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 9760: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
9761: $checkid = 1;
9762: }
9763: }
9764: foreach my $user (keys(%{$usershash})) {
9765: my ($uname,$udom) = split(/:/,$user);
9766: if ($checkid) {
9767: if (ref($usershash->{$user}) eq 'HASH') {
9768: if ($usershash->{$user}->{'id'} ne '') {
9769: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
9770: $userdoms{$udom} = 1;
9771: if (ref($inst_results) eq 'HASH') {
9772: $inst_results->{$uname.':'.$udom} = {};
9773: }
9774: }
9775: }
9776: } else {
9777: $by_username{$udom}{$uname} = 1;
9778: $userdoms{$udom} = 1;
9779: if (ref($inst_results) eq 'HASH') {
9780: $inst_results->{$uname.':'.$udom} = {};
9781: }
9782: }
9783: }
9784: foreach my $udom (keys(%userdoms)) {
9785: if (!$got_rules->{$udom}) {
9786: my %domconfig = &Apache::lonnet::get_dom('configuration',
9787: ['usercreation'],$udom);
9788: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9789: foreach my $item ('username','id') {
9790: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9791: $$curr_rules{$udom}{$item} =
9792: $domconfig{'usercreation'}{$item.'_rule'};
9793: }
9794: }
9795: }
9796: $got_rules->{$udom} = 1;
9797: }
9798: }
9799: if ($checkid) {
9800: foreach my $udom (keys(%by_id)) {
9801: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
9802: if ($outcome eq 'ok') {
9803: foreach my $id (keys(%{$by_id{$udom}})) {
9804: my $uname = $by_id{$udom}{$id};
9805: $inst_response{$uname.':'.$udom} = $outcome;
9806: }
9807: if (ref($results) eq 'HASH') {
9808: foreach my $uname (keys(%{$results})) {
9809: if (exists($inst_response{$uname.':'.$udom})) {
9810: $inst_response{$uname.':'.$udom} = $outcome;
9811: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9812: }
9813: }
9814: }
9815: }
1.612 raeburn 9816: }
1.615 raeburn 9817: } else {
1.1075.2.99 raeburn 9818: foreach my $udom (keys(%by_username)) {
9819: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
9820: if ($outcome eq 'ok') {
9821: foreach my $uname (keys(%{$by_username{$udom}})) {
9822: $inst_response{$uname.':'.$udom} = $outcome;
9823: }
9824: if (ref($results) eq 'HASH') {
9825: foreach my $uname (keys(%{$results})) {
9826: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9827: }
9828: }
9829: }
9830: }
1.612 raeburn 9831: }
1.1075.2.99 raeburn 9832: } elsif (keys(%{$usershash}) == 1) {
9833: my $user = (keys(%{$usershash}))[0];
9834: my ($uname,$udom) = split(/:/,$user);
9835: if (($udom ne '') && ($uname ne '')) {
9836: if (ref($usershash->{$user}) eq 'HASH') {
9837: if (ref($checks) eq 'HASH') {
9838: if (defined($checks->{'username'})) {
9839: ($inst_response{$user},%{$inst_results->{$user}}) =
9840: &Apache::lonnet::get_instuser($udom,$uname);
9841: } elsif (defined($checks->{'id'})) {
9842: if ($usershash->{$user}->{'id'} ne '') {
9843: ($inst_response{$user},%{$inst_results->{$user}}) =
9844: &Apache::lonnet::get_instuser($udom,undef,
9845: $usershash->{$user}->{'id'});
9846: } else {
9847: ($inst_response{$user},%{$inst_results->{$user}}) =
9848: &Apache::lonnet::get_instuser($udom,$uname);
9849: }
9850: }
9851: } else {
9852: ($inst_response{$user},%{$inst_results->{$user}}) =
9853: &Apache::lonnet::get_instuser($udom,$uname);
9854: return;
9855: }
9856: if (!$got_rules->{$udom}) {
9857: my %domconfig = &Apache::lonnet::get_dom('configuration',
9858: ['usercreation'],$udom);
9859: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9860: foreach my $item ('username','id') {
9861: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9862: $$curr_rules{$udom}{$item} =
9863: $domconfig{'usercreation'}{$item.'_rule'};
9864: }
9865: }
1.585 raeburn 9866: }
1.1075.2.99 raeburn 9867: $got_rules->{$udom} = 1;
1.585 raeburn 9868: }
9869: }
1.1075.2.99 raeburn 9870: } else {
9871: return;
9872: }
9873: } else {
9874: return;
9875: }
9876: foreach my $user (keys(%{$usershash})) {
9877: my ($uname,$udom) = split(/:/,$user);
9878: next if (($udom eq '') || ($uname eq ''));
9879: my $id;
9880: if (ref($inst_results) eq 'HASH') {
9881: if (ref($inst_results->{$user}) eq 'HASH') {
9882: $id = $inst_results->{$user}->{'id'};
9883: }
9884: }
9885: if ($id eq '') {
9886: if (ref($usershash->{$user})) {
9887: $id = $usershash->{$user}->{'id'};
9888: }
1.585 raeburn 9889: }
1.612 raeburn 9890: foreach my $item (keys(%{$checks})) {
9891: if (ref($$curr_rules{$udom}) eq 'HASH') {
9892: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9893: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 9894: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
9895: $$curr_rules{$udom}{$item});
1.612 raeburn 9896: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9897: if ($rule_check{$rule}) {
9898: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 9899: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 9900: if (ref($inst_results) eq 'HASH') {
9901: if (ref($inst_results->{$user}) eq 'HASH') {
9902: if (keys(%{$inst_results->{$user}}) == 0) {
9903: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 9904: } elsif ($item eq 'id') {
9905: if ($inst_results->{$user}->{'id'} eq '') {
9906: $$alerts{$item}{$udom}{$uname} = 1;
9907: }
1.615 raeburn 9908: }
1.612 raeburn 9909: }
9910: }
1.615 raeburn 9911: }
9912: last;
1.585 raeburn 9913: }
9914: }
9915: }
9916: }
9917: }
9918: }
9919: }
9920: }
1.612 raeburn 9921: return;
9922: }
9923:
9924: sub user_rule_formats {
9925: my ($domain,$domdesc,$curr_rules,$check) = @_;
9926: my %text = (
9927: 'username' => 'Usernames',
9928: 'id' => 'IDs',
9929: );
9930: my $output;
9931: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9932: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9933: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 9934: $output = '<br />'.
9935: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9936: '<span class="LC_cusr_emph">','</span>',$domdesc).
9937: ' <ul>';
1.612 raeburn 9938: foreach my $rule (@{$ruleorder}) {
9939: if (ref($curr_rules) eq 'ARRAY') {
9940: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9941: if (ref($rules->{$rule}) eq 'HASH') {
9942: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9943: $rules->{$rule}{'desc'}.'</li>';
9944: }
9945: }
9946: }
9947: }
9948: $output .= '</ul>';
9949: }
9950: }
9951: return $output;
9952: }
9953:
9954: sub instrule_disallow_msg {
1.615 raeburn 9955: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9956: my $response;
9957: my %text = (
9958: item => 'username',
9959: items => 'usernames',
9960: match => 'matches',
9961: do => 'does',
9962: action => 'a username',
9963: one => 'one',
9964: );
9965: if ($count > 1) {
9966: $text{'item'} = 'usernames';
9967: $text{'match'} ='match';
9968: $text{'do'} = 'do';
9969: $text{'action'} = 'usernames',
9970: $text{'one'} = 'ones';
9971: }
9972: if ($checkitem eq 'id') {
9973: $text{'items'} = 'IDs';
9974: $text{'item'} = 'ID';
9975: $text{'action'} = 'an ID';
1.615 raeburn 9976: if ($count > 1) {
9977: $text{'item'} = 'IDs';
9978: $text{'action'} = 'IDs';
9979: }
1.612 raeburn 9980: }
1.674 bisitz 9981: $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 9982: if ($mode eq 'upload') {
9983: if ($checkitem eq 'username') {
9984: $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'}.");
9985: } elsif ($checkitem eq 'id') {
1.674 bisitz 9986: $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 9987: }
1.669 raeburn 9988: } elsif ($mode eq 'selfcreate') {
9989: if ($checkitem eq 'id') {
9990: $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.");
9991: }
1.615 raeburn 9992: } else {
9993: if ($checkitem eq 'username') {
9994: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9995: } elsif ($checkitem eq 'id') {
9996: $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.");
9997: }
1.612 raeburn 9998: }
9999: return $response;
1.585 raeburn 10000: }
10001:
1.624 raeburn 10002: sub personal_data_fieldtitles {
10003: my %fieldtitles = &Apache::lonlocal::texthash (
10004: id => 'Student/Employee ID',
10005: permanentemail => 'E-mail address',
10006: lastname => 'Last Name',
10007: firstname => 'First Name',
10008: middlename => 'Middle Name',
10009: generation => 'Generation',
10010: gen => 'Generation',
1.765 raeburn 10011: inststatus => 'Affiliation',
1.624 raeburn 10012: );
10013: return %fieldtitles;
10014: }
10015:
1.642 raeburn 10016: sub sorted_inst_types {
10017: my ($dom) = @_;
1.1075.2.70 raeburn 10018: my ($usertypes,$order);
10019: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10020: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10021: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10022: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10023: } else {
10024: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10025: }
1.642 raeburn 10026: my $othertitle = &mt('All users');
10027: if ($env{'request.course.id'}) {
1.668 raeburn 10028: $othertitle = &mt('Any users');
1.642 raeburn 10029: }
10030: my @types;
10031: if (ref($order) eq 'ARRAY') {
10032: @types = @{$order};
10033: }
10034: if (@types == 0) {
10035: if (ref($usertypes) eq 'HASH') {
10036: @types = sort(keys(%{$usertypes}));
10037: }
10038: }
10039: if (keys(%{$usertypes}) > 0) {
10040: $othertitle = &mt('Other users');
10041: }
10042: return ($othertitle,$usertypes,\@types);
10043: }
10044:
1.645 raeburn 10045: sub get_institutional_codes {
10046: my ($settings,$allcourses,$LC_code) = @_;
10047: # Get complete list of course sections to update
10048: my @currsections = ();
10049: my @currxlists = ();
10050: my $coursecode = $$settings{'internal.coursecode'};
10051:
10052: if ($$settings{'internal.sectionnums'} ne '') {
10053: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10054: }
10055:
10056: if ($$settings{'internal.crosslistings'} ne '') {
10057: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10058: }
10059:
10060: if (@currxlists > 0) {
10061: foreach (@currxlists) {
10062: if (m/^([^:]+):(\w*)$/) {
10063: unless (grep/^$1$/,@{$allcourses}) {
10064: push @{$allcourses},$1;
10065: $$LC_code{$1} = $2;
10066: }
10067: }
10068: }
10069: }
10070:
10071: if (@currsections > 0) {
10072: foreach (@currsections) {
10073: if (m/^(\w+):(\w*)$/) {
10074: my $sec = $coursecode.$1;
10075: my $lc_sec = $2;
10076: unless (grep/^$sec$/,@{$allcourses}) {
10077: push @{$allcourses},$sec;
10078: $$LC_code{$sec} = $lc_sec;
10079: }
10080: }
10081: }
10082: }
10083: return;
10084: }
10085:
1.971 raeburn 10086: sub get_standard_codeitems {
10087: return ('Year','Semester','Department','Number','Section');
10088: }
10089:
1.112 bowersj2 10090: =pod
10091:
1.780 raeburn 10092: =head1 Slot Helpers
10093:
10094: =over 4
10095:
10096: =item * sorted_slots()
10097:
1.1040 raeburn 10098: Sorts an array of slot names in order of an optional sort key,
10099: default sort is by slot start time (earliest first).
1.780 raeburn 10100:
10101: Inputs:
10102:
10103: =over 4
10104:
10105: slotsarr - Reference to array of unsorted slot names.
10106:
10107: slots - Reference to hash of hash, where outer hash keys are slot names.
10108:
1.1040 raeburn 10109: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10110:
1.549 albertel 10111: =back
10112:
1.780 raeburn 10113: Returns:
10114:
10115: =over 4
10116:
1.1040 raeburn 10117: sorted - An array of slot names sorted by a specified sort key
10118: (default sort key is start time of the slot).
1.780 raeburn 10119:
10120: =back
10121:
10122: =cut
10123:
10124:
10125: sub sorted_slots {
1.1040 raeburn 10126: my ($slotsarr,$slots,$sortkey) = @_;
10127: if ($sortkey eq '') {
10128: $sortkey = 'starttime';
10129: }
1.780 raeburn 10130: my @sorted;
10131: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10132: @sorted =
10133: sort {
10134: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10135: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10136: }
10137: if (ref($slots->{$a})) { return -1;}
10138: if (ref($slots->{$b})) { return 1;}
10139: return 0;
10140: } @{$slotsarr};
10141: }
10142: return @sorted;
10143: }
10144:
1.1040 raeburn 10145: =pod
10146:
10147: =item * get_future_slots()
10148:
10149: Inputs:
10150:
10151: =over 4
10152:
10153: cnum - course number
10154:
10155: cdom - course domain
10156:
10157: now - current UNIX time
10158:
10159: symb - optional symb
10160:
10161: =back
10162:
10163: Returns:
10164:
10165: =over 4
10166:
10167: sorted_reservable - ref to array of student_schedulable slots currently
10168: reservable, ordered by end date of reservation period.
10169:
10170: reservable_now - ref to hash of student_schedulable slots currently
10171: reservable.
10172:
10173: Keys in inner hash are:
10174: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 10175: (b) endreserve: end date of reservation period.
10176: (c) uniqueperiod: start,end dates when slot is to be uniquely
10177: selected.
1.1040 raeburn 10178:
10179: sorted_future - ref to array of student_schedulable slots reservable in
10180: the future, ordered by start date of reservation period.
10181:
10182: future_reservable - ref to hash of student_schedulable slots reservable
10183: in the future.
10184:
10185: Keys in inner hash are:
10186: (a) symb: either blank or symb to which slot use is restricted.
10187: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 10188: (c) uniqueperiod: start,end dates when slot is to be uniquely
10189: selected.
1.1040 raeburn 10190:
10191: =back
10192:
10193: =cut
10194:
10195: sub get_future_slots {
10196: my ($cnum,$cdom,$now,$symb) = @_;
10197: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10198: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10199: foreach my $slot (keys(%slots)) {
10200: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10201: if ($symb) {
10202: next if (($slots{$slot}->{'symb'} ne '') &&
10203: ($slots{$slot}->{'symb'} ne $symb));
10204: }
10205: if (($slots{$slot}->{'starttime'} > $now) &&
10206: ($slots{$slot}->{'endtime'} > $now)) {
10207: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10208: my $userallowed = 0;
10209: if ($slots{$slot}->{'allowedsections'}) {
10210: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10211: if (!defined($env{'request.role.sec'})
10212: && grep(/^No section assigned$/,@allowed_sec)) {
10213: $userallowed=1;
10214: } else {
10215: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10216: $userallowed=1;
10217: }
10218: }
10219: unless ($userallowed) {
10220: if (defined($env{'request.course.groups'})) {
10221: my @groups = split(/:/,$env{'request.course.groups'});
10222: foreach my $group (@groups) {
10223: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10224: $userallowed=1;
10225: last;
10226: }
10227: }
10228: }
10229: }
10230: }
10231: if ($slots{$slot}->{'allowedusers'}) {
10232: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10233: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10234: if (grep(/^\Q$user\E$/,@allowed_users)) {
10235: $userallowed = 1;
10236: }
10237: }
10238: next unless($userallowed);
10239: }
10240: my $startreserve = $slots{$slot}->{'startreserve'};
10241: my $endreserve = $slots{$slot}->{'endreserve'};
10242: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 10243: my $uniqueperiod;
10244: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10245: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10246: }
1.1040 raeburn 10247: if (($startreserve < $now) &&
10248: (!$endreserve || $endreserve > $now)) {
10249: my $lastres = $endreserve;
10250: if (!$lastres) {
10251: $lastres = $slots{$slot}->{'starttime'};
10252: }
10253: $reservable_now{$slot} = {
10254: symb => $symb,
1.1075.2.104 raeburn 10255: endreserve => $lastres,
10256: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10257: };
10258: } elsif (($startreserve > $now) &&
10259: (!$endreserve || $endreserve > $startreserve)) {
10260: $future_reservable{$slot} = {
10261: symb => $symb,
1.1075.2.104 raeburn 10262: startreserve => $startreserve,
10263: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10264: };
10265: }
10266: }
10267: }
10268: my @unsorted_reservable = keys(%reservable_now);
10269: if (@unsorted_reservable > 0) {
10270: @sorted_reservable =
10271: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10272: }
10273: my @unsorted_future = keys(%future_reservable);
10274: if (@unsorted_future > 0) {
10275: @sorted_future =
10276: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10277: }
10278: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10279: }
1.780 raeburn 10280:
10281: =pod
10282:
1.1057 foxr 10283: =back
10284:
1.549 albertel 10285: =head1 HTTP Helpers
10286:
10287: =over 4
10288:
1.648 raeburn 10289: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10290:
1.258 albertel 10291: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10292: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10293: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10294:
10295: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10296: $possible_names is an ref to an array of form element names. As an example:
10297: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10298: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10299:
10300: =cut
1.1 albertel 10301:
1.6 albertel 10302: sub get_unprocessed_cgi {
1.25 albertel 10303: my ($query,$possible_names)= @_;
1.26 matthew 10304: # $Apache::lonxml::debug=1;
1.356 albertel 10305: foreach my $pair (split(/&/,$query)) {
10306: my ($name, $value) = split(/=/,$pair);
1.369 www 10307: $name = &unescape($name);
1.25 albertel 10308: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10309: $value =~ tr/+/ /;
10310: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10311: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10312: }
1.16 harris41 10313: }
1.6 albertel 10314: }
10315:
1.112 bowersj2 10316: =pod
10317:
1.648 raeburn 10318: =item * &cacheheader()
1.112 bowersj2 10319:
10320: returns cache-controlling header code
10321:
10322: =cut
10323:
1.7 albertel 10324: sub cacheheader {
1.258 albertel 10325: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10326: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10327: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10328: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10329: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10330: return $output;
1.7 albertel 10331: }
10332:
1.112 bowersj2 10333: =pod
10334:
1.648 raeburn 10335: =item * &no_cache($r)
1.112 bowersj2 10336:
10337: specifies header code to not have cache
10338:
10339: =cut
10340:
1.9 albertel 10341: sub no_cache {
1.216 albertel 10342: my ($r) = @_;
10343: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10344: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10345: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10346: $r->no_cache(1);
10347: $r->header_out("Expires" => $date);
10348: $r->header_out("Pragma" => "no-cache");
1.123 www 10349: }
10350:
10351: sub content_type {
1.181 albertel 10352: my ($r,$type,$charset) = @_;
1.299 foxr 10353: if ($r) {
10354: # Note that printout.pl calls this with undef for $r.
10355: &no_cache($r);
10356: }
1.258 albertel 10357: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10358: unless ($charset) {
10359: $charset=&Apache::lonlocal::current_encoding;
10360: }
10361: if ($charset) { $type.='; charset='.$charset; }
10362: if ($r) {
10363: $r->content_type($type);
10364: } else {
10365: print("Content-type: $type\n\n");
10366: }
1.9 albertel 10367: }
1.25 albertel 10368:
1.112 bowersj2 10369: =pod
10370:
1.648 raeburn 10371: =item * &add_to_env($name,$value)
1.112 bowersj2 10372:
1.258 albertel 10373: adds $name to the %env hash with value
1.112 bowersj2 10374: $value, if $name already exists, the entry is converted to an array
10375: reference and $value is added to the array.
10376:
10377: =cut
10378:
1.25 albertel 10379: sub add_to_env {
10380: my ($name,$value)=@_;
1.258 albertel 10381: if (defined($env{$name})) {
10382: if (ref($env{$name})) {
1.25 albertel 10383: #already have multiple values
1.258 albertel 10384: push(@{ $env{$name} },$value);
1.25 albertel 10385: } else {
10386: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10387: my $first=$env{$name};
10388: undef($env{$name});
10389: push(@{ $env{$name} },$first,$value);
1.25 albertel 10390: }
10391: } else {
1.258 albertel 10392: $env{$name}=$value;
1.25 albertel 10393: }
1.31 albertel 10394: }
1.149 albertel 10395:
10396: =pod
10397:
1.648 raeburn 10398: =item * &get_env_multiple($name)
1.149 albertel 10399:
1.258 albertel 10400: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10401: values may be defined and end up as an array ref.
10402:
10403: returns an array of values
10404:
10405: =cut
10406:
10407: sub get_env_multiple {
10408: my ($name) = @_;
10409: my @values;
1.258 albertel 10410: if (defined($env{$name})) {
1.149 albertel 10411: # exists is it an array
1.258 albertel 10412: if (ref($env{$name})) {
10413: @values=@{ $env{$name} };
1.149 albertel 10414: } else {
1.258 albertel 10415: $values[0]=$env{$name};
1.149 albertel 10416: }
10417: }
10418: return(@values);
10419: }
10420:
1.660 raeburn 10421: sub ask_for_embedded_content {
10422: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10423: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 10424: %currsubfile,%unused,$rem);
1.1071 raeburn 10425: my $counter = 0;
10426: my $numnew = 0;
1.987 raeburn 10427: my $numremref = 0;
10428: my $numinvalid = 0;
10429: my $numpathchg = 0;
10430: my $numexisting = 0;
1.1071 raeburn 10431: my $numunused = 0;
10432: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 10433: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10434: my $heading = &mt('Upload embedded files');
10435: my $buttontext = &mt('Upload');
10436:
1.1075.2.11 raeburn 10437: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 10438: if ($actionurl eq '/adm/dependencies') {
10439: $navmap = Apache::lonnavmaps::navmap->new();
10440: }
10441: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10442: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 10443: }
1.1075.2.35 raeburn 10444: if (($actionurl eq '/adm/portfolio') ||
10445: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10446: my $current_path='/';
10447: if ($env{'form.currentpath'}) {
10448: $current_path = $env{'form.currentpath'};
10449: }
10450: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 10451: $udom = $cdom;
10452: $uname = $cnum;
1.984 raeburn 10453: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10454: } else {
10455: $udom = $env{'user.domain'};
10456: $uname = $env{'user.name'};
10457: $url = '/userfiles/portfolio';
10458: }
1.987 raeburn 10459: $toplevel = $url.'/';
1.984 raeburn 10460: $url .= $current_path;
10461: $getpropath = 1;
1.987 raeburn 10462: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10463: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10464: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10465: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10466: $toplevel = $url;
1.984 raeburn 10467: if ($rest ne '') {
1.987 raeburn 10468: $url .= $rest;
10469: }
10470: } elsif ($actionurl eq '/adm/coursedocs') {
10471: if (ref($args) eq 'HASH') {
1.1071 raeburn 10472: $url = $args->{'docs_url'};
10473: $toplevel = $url;
1.1075.2.11 raeburn 10474: if ($args->{'context'} eq 'paste') {
10475: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10476: ($path) =
10477: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10478: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10479: $fileloc =~ s{^/}{};
10480: }
1.1071 raeburn 10481: }
10482: } elsif ($actionurl eq '/adm/dependencies') {
10483: if ($env{'request.course.id'} ne '') {
10484: if (ref($args) eq 'HASH') {
10485: $url = $args->{'docs_url'};
10486: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 10487: $toplevel = $url;
10488: unless ($toplevel =~ m{^/}) {
10489: $toplevel = "/$url";
10490: }
1.1075.2.11 raeburn 10491: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 10492: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10493: $path = $1;
10494: } else {
10495: ($path) =
10496: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10497: }
1.1075.2.79 raeburn 10498: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10499: $fileloc = $toplevel;
10500: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10501: my ($udom,$uname,$fname) =
10502: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10503: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10504: } else {
10505: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10506: }
1.1071 raeburn 10507: $fileloc =~ s{^/}{};
10508: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10509: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10510: }
1.987 raeburn 10511: }
1.1075.2.35 raeburn 10512: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10513: $udom = $cdom;
10514: $uname = $cnum;
10515: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10516: $toplevel = $url;
10517: $path = $url;
10518: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10519: $fileloc =~ s{^/}{};
10520: }
10521: foreach my $file (keys(%{$allfiles})) {
10522: my $embed_file;
10523: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10524: $embed_file = $1;
10525: } else {
10526: $embed_file = $file;
10527: }
1.1075.2.55 raeburn 10528: my ($absolutepath,$cleaned_file);
10529: if ($embed_file =~ m{^\w+://}) {
10530: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 10531: $newfiles{$cleaned_file} = 1;
10532: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10533: } else {
1.1075.2.55 raeburn 10534: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10535: if ($embed_file =~ m{^/}) {
10536: $absolutepath = $embed_file;
10537: }
1.1075.2.47 raeburn 10538: if ($cleaned_file =~ m{/}) {
10539: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10540: $path = &check_for_traversal($path,$url,$toplevel);
10541: my $item = $fname;
10542: if ($path ne '') {
10543: $item = $path.'/'.$fname;
10544: $subdependencies{$path}{$fname} = 1;
10545: } else {
10546: $dependencies{$item} = 1;
10547: }
10548: if ($absolutepath) {
10549: $mapping{$item} = $absolutepath;
10550: } else {
10551: $mapping{$item} = $embed_file;
10552: }
10553: } else {
10554: $dependencies{$embed_file} = 1;
10555: if ($absolutepath) {
1.1075.2.47 raeburn 10556: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10557: } else {
1.1075.2.47 raeburn 10558: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10559: }
10560: }
1.984 raeburn 10561: }
10562: }
1.1071 raeburn 10563: my $dirptr = 16384;
1.984 raeburn 10564: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10565: $currsubfile{$path} = {};
1.1075.2.35 raeburn 10566: if (($actionurl eq '/adm/portfolio') ||
10567: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10568: my ($sublistref,$listerror) =
10569: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10570: if (ref($sublistref) eq 'ARRAY') {
10571: foreach my $line (@{$sublistref}) {
10572: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10573: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10574: }
1.984 raeburn 10575: }
1.987 raeburn 10576: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10577: if (opendir(my $dir,$url.'/'.$path)) {
10578: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10579: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10580: }
1.1075.2.11 raeburn 10581: } elsif (($actionurl eq '/adm/dependencies') ||
10582: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10583: ($args->{'context'} eq 'paste')) ||
10584: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10585: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 10586: my $dir;
10587: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10588: $dir = $fileloc;
10589: } else {
10590: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10591: }
1.1071 raeburn 10592: if ($dir ne '') {
10593: my ($sublistref,$listerror) =
10594: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10595: if (ref($sublistref) eq 'ARRAY') {
10596: foreach my $line (@{$sublistref}) {
10597: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10598: undef,$mtime)=split(/\&/,$line,12);
10599: unless (($testdir&$dirptr) ||
10600: ($file_name =~ /^\.\.?$/)) {
10601: $currsubfile{$path}{$file_name} = [$size,$mtime];
10602: }
10603: }
10604: }
10605: }
1.984 raeburn 10606: }
10607: }
10608: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10609: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10610: my $item = $path.'/'.$file;
10611: unless ($mapping{$item} eq $item) {
10612: $pathchanges{$item} = 1;
10613: }
10614: $existing{$item} = 1;
10615: $numexisting ++;
10616: } else {
10617: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10618: }
10619: }
1.1071 raeburn 10620: if ($actionurl eq '/adm/dependencies') {
10621: foreach my $path (keys(%currsubfile)) {
10622: if (ref($currsubfile{$path}) eq 'HASH') {
10623: foreach my $file (keys(%{$currsubfile{$path}})) {
10624: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10625: next if (($rem ne '') &&
10626: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10627: (ref($navmap) &&
10628: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10629: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10630: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10631: $unused{$path.'/'.$file} = 1;
10632: }
10633: }
10634: }
10635: }
10636: }
1.984 raeburn 10637: }
1.987 raeburn 10638: my %currfile;
1.1075.2.35 raeburn 10639: if (($actionurl eq '/adm/portfolio') ||
10640: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10641: my ($dirlistref,$listerror) =
10642: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10643: if (ref($dirlistref) eq 'ARRAY') {
10644: foreach my $line (@{$dirlistref}) {
10645: my ($file_name,$rest) = split(/\&/,$line,2);
10646: $currfile{$file_name} = 1;
10647: }
1.984 raeburn 10648: }
1.987 raeburn 10649: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10650: if (opendir(my $dir,$url)) {
1.987 raeburn 10651: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10652: map {$currfile{$_} = 1;} @dir_list;
10653: }
1.1075.2.11 raeburn 10654: } elsif (($actionurl eq '/adm/dependencies') ||
10655: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10656: ($args->{'context'} eq 'paste')) ||
10657: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10658: if ($env{'request.course.id'} ne '') {
10659: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10660: if ($dir ne '') {
10661: my ($dirlistref,$listerror) =
10662: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10663: if (ref($dirlistref) eq 'ARRAY') {
10664: foreach my $line (@{$dirlistref}) {
10665: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10666: $size,undef,$mtime)=split(/\&/,$line,12);
10667: unless (($testdir&$dirptr) ||
10668: ($file_name =~ /^\.\.?$/)) {
10669: $currfile{$file_name} = [$size,$mtime];
10670: }
10671: }
10672: }
10673: }
10674: }
1.984 raeburn 10675: }
10676: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10677: if (exists($currfile{$file})) {
1.987 raeburn 10678: unless ($mapping{$file} eq $file) {
10679: $pathchanges{$file} = 1;
10680: }
10681: $existing{$file} = 1;
10682: $numexisting ++;
10683: } else {
1.984 raeburn 10684: $newfiles{$file} = 1;
10685: }
10686: }
1.1071 raeburn 10687: foreach my $file (keys(%currfile)) {
10688: unless (($file eq $filename) ||
10689: ($file eq $filename.'.bak') ||
10690: ($dependencies{$file})) {
1.1075.2.11 raeburn 10691: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10692: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10693: next if (($rem ne '') &&
10694: (($env{"httpref.$rem".$file} ne '') ||
10695: (ref($navmap) &&
10696: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10697: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10698: ($navmap->getResourceByUrl($rem.$1)))))));
10699: }
1.1075.2.11 raeburn 10700: }
1.1071 raeburn 10701: $unused{$file} = 1;
10702: }
10703: }
1.1075.2.11 raeburn 10704: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10705: ($args->{'context'} eq 'paste')) {
10706: $counter = scalar(keys(%existing));
10707: $numpathchg = scalar(keys(%pathchanges));
10708: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10709: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10710: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10711: $counter = scalar(keys(%existing));
10712: $numpathchg = scalar(keys(%pathchanges));
10713: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10714: }
1.984 raeburn 10715: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10716: if ($actionurl eq '/adm/dependencies') {
10717: next if ($embed_file =~ m{^\w+://});
10718: }
1.660 raeburn 10719: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10720: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10721: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10722: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10723: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10724: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10725: }
1.1075.2.35 raeburn 10726: $upload_output .= '</td>';
1.1071 raeburn 10727: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10728: $upload_output.='<td align="right">'.
10729: '<span class="LC_info LC_fontsize_medium">'.
10730: &mt("URL points to web address").'</span>';
1.987 raeburn 10731: $numremref++;
1.660 raeburn 10732: } elsif ($args->{'error_on_invalid_names'}
10733: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10734: $upload_output.='<td align="right"><span class="LC_warning">'.
10735: &mt('Invalid characters').'</span>';
1.987 raeburn 10736: $numinvalid++;
1.660 raeburn 10737: } else {
1.1075.2.35 raeburn 10738: $upload_output .= '<td>'.
10739: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10740: $embed_file,\%mapping,
1.1071 raeburn 10741: $allfiles,$codebase,'upload');
10742: $counter ++;
10743: $numnew ++;
1.987 raeburn 10744: }
10745: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10746: }
10747: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10748: if ($actionurl eq '/adm/dependencies') {
10749: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10750: $modify_output .= &start_data_table_row().
10751: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10752: '<img src="'.&icon($embed_file).'" border="0" />'.
10753: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10754: '<td>'.$size.'</td>'.
10755: '<td>'.$mtime.'</td>'.
10756: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10757: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10758: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10759: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10760: &embedded_file_element('upload_embedded',$counter,
10761: $embed_file,\%mapping,
10762: $allfiles,$codebase,'modify').
10763: '</div></td>'.
10764: &end_data_table_row()."\n";
10765: $counter ++;
10766: } else {
10767: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10768: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10769: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10770: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10771: &Apache::loncommon::end_data_table_row()."\n";
10772: }
10773: }
10774: my $delidx = $counter;
10775: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10776: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10777: $delete_output .= &start_data_table_row().
10778: '<td><img src="'.&icon($oldfile).'" />'.
10779: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10780: '<td>'.$size.'</td>'.
10781: '<td>'.$mtime.'</td>'.
10782: '<td><label><input type="checkbox" name="del_upload_dep" '.
10783: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10784: &embedded_file_element('upload_embedded',$delidx,
10785: $oldfile,\%mapping,$allfiles,
10786: $codebase,'delete').'</td>'.
10787: &end_data_table_row()."\n";
10788: $numunused ++;
10789: $delidx ++;
1.987 raeburn 10790: }
10791: if ($upload_output) {
10792: $upload_output = &start_data_table().
10793: $upload_output.
10794: &end_data_table()."\n";
10795: }
1.1071 raeburn 10796: if ($modify_output) {
10797: $modify_output = &start_data_table().
10798: &start_data_table_header_row().
10799: '<th>'.&mt('File').'</th>'.
10800: '<th>'.&mt('Size (KB)').'</th>'.
10801: '<th>'.&mt('Modified').'</th>'.
10802: '<th>'.&mt('Upload replacement?').'</th>'.
10803: &end_data_table_header_row().
10804: $modify_output.
10805: &end_data_table()."\n";
10806: }
10807: if ($delete_output) {
10808: $delete_output = &start_data_table().
10809: &start_data_table_header_row().
10810: '<th>'.&mt('File').'</th>'.
10811: '<th>'.&mt('Size (KB)').'</th>'.
10812: '<th>'.&mt('Modified').'</th>'.
10813: '<th>'.&mt('Delete?').'</th>'.
10814: &end_data_table_header_row().
10815: $delete_output.
10816: &end_data_table()."\n";
10817: }
1.987 raeburn 10818: my $applies = 0;
10819: if ($numremref) {
10820: $applies ++;
10821: }
10822: if ($numinvalid) {
10823: $applies ++;
10824: }
10825: if ($numexisting) {
10826: $applies ++;
10827: }
1.1071 raeburn 10828: if ($counter || $numunused) {
1.987 raeburn 10829: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10830: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10831: $state.'<h3>'.$heading.'</h3>';
10832: if ($actionurl eq '/adm/dependencies') {
10833: if ($numnew) {
10834: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10835: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10836: $upload_output.'<br />'."\n";
10837: }
10838: if ($numexisting) {
10839: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10840: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10841: $modify_output.'<br />'."\n";
10842: $buttontext = &mt('Save changes');
10843: }
10844: if ($numunused) {
10845: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10846: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10847: $delete_output.'<br />'."\n";
10848: $buttontext = &mt('Save changes');
10849: }
10850: } else {
10851: $output .= $upload_output.'<br />'."\n";
10852: }
10853: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10854: $counter.'" />'."\n";
10855: if ($actionurl eq '/adm/dependencies') {
10856: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10857: $numnew.'" />'."\n";
10858: } elsif ($actionurl eq '') {
1.987 raeburn 10859: $output .= '<input type="hidden" name="phase" value="three" />';
10860: }
10861: } elsif ($applies) {
10862: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10863: if ($applies > 1) {
10864: $output .=
1.1075.2.35 raeburn 10865: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10866: if ($numremref) {
10867: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10868: }
10869: if ($numinvalid) {
10870: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10871: }
10872: if ($numexisting) {
10873: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10874: }
10875: $output .= '</ul><br />';
10876: } elsif ($numremref) {
10877: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10878: } elsif ($numinvalid) {
10879: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10880: } elsif ($numexisting) {
10881: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10882: }
10883: $output .= $upload_output.'<br />';
10884: }
10885: my ($pathchange_output,$chgcount);
1.1071 raeburn 10886: $chgcount = $counter;
1.987 raeburn 10887: if (keys(%pathchanges) > 0) {
10888: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10889: if ($counter) {
1.987 raeburn 10890: $output .= &embedded_file_element('pathchange',$chgcount,
10891: $embed_file,\%mapping,
1.1071 raeburn 10892: $allfiles,$codebase,'change');
1.987 raeburn 10893: } else {
10894: $pathchange_output .=
10895: &start_data_table_row().
10896: '<td><input type ="checkbox" name="namechange" value="'.
10897: $chgcount.'" checked="checked" /></td>'.
10898: '<td>'.$mapping{$embed_file}.'</td>'.
10899: '<td>'.$embed_file.
10900: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10901: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10902: '</td>'.&end_data_table_row();
1.660 raeburn 10903: }
1.987 raeburn 10904: $numpathchg ++;
10905: $chgcount ++;
1.660 raeburn 10906: }
10907: }
1.1075.2.35 raeburn 10908: if (($counter) || ($numunused)) {
1.987 raeburn 10909: if ($numpathchg) {
10910: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10911: $numpathchg.'" />'."\n";
10912: }
10913: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10914: ($actionurl eq '/adm/imsimport')) {
10915: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10916: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10917: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10918: } elsif ($actionurl eq '/adm/dependencies') {
10919: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10920: }
1.1075.2.35 raeburn 10921: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10922: } elsif ($numpathchg) {
10923: my %pathchange = ();
10924: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10925: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10926: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 10927: }
1.987 raeburn 10928: }
1.1071 raeburn 10929: return ($output,$counter,$numpathchg);
1.987 raeburn 10930: }
10931:
1.1075.2.47 raeburn 10932: =pod
10933:
10934: =item * clean_path($name)
10935:
10936: Performs clean-up of directories, subdirectories and filename in an
10937: embedded object, referenced in an HTML file which is being uploaded
10938: to a course or portfolio, where
10939: "Upload embedded images/multimedia files if HTML file" checkbox was
10940: checked.
10941:
10942: Clean-up is similar to replacements in lonnet::clean_filename()
10943: except each / between sub-directory and next level is preserved.
10944:
10945: =cut
10946:
10947: sub clean_path {
10948: my ($embed_file) = @_;
10949: $embed_file =~s{^/+}{};
10950: my @contents;
10951: if ($embed_file =~ m{/}) {
10952: @contents = split(/\//,$embed_file);
10953: } else {
10954: @contents = ($embed_file);
10955: }
10956: my $lastidx = scalar(@contents)-1;
10957: for (my $i=0; $i<=$lastidx; $i++) {
10958: $contents[$i]=~s{\\}{/}g;
10959: $contents[$i]=~s/\s+/\_/g;
10960: $contents[$i]=~s{[^/\w\.\-]}{}g;
10961: if ($i == $lastidx) {
10962: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10963: }
10964: }
10965: if ($lastidx > 0) {
10966: return join('/',@contents);
10967: } else {
10968: return $contents[0];
10969: }
10970: }
10971:
1.987 raeburn 10972: sub embedded_file_element {
1.1071 raeburn 10973: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10974: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10975: (ref($codebase) eq 'HASH'));
10976: my $output;
1.1071 raeburn 10977: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10978: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10979: }
10980: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10981: &escape($embed_file).'" />';
10982: unless (($context eq 'upload_embedded') &&
10983: ($mapping->{$embed_file} eq $embed_file)) {
10984: $output .='
10985: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10986: }
10987: my $attrib;
10988: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10989: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10990: }
10991: $output .=
10992: "\n\t\t".
10993: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10994: $attrib.'" />';
10995: if (exists($codebase->{$mapping->{$embed_file}})) {
10996: $output .=
10997: "\n\t\t".
10998: '<input name="codebase_'.$num.'" type="hidden" value="'.
10999: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11000: }
1.987 raeburn 11001: return $output;
1.660 raeburn 11002: }
11003:
1.1071 raeburn 11004: sub get_dependency_details {
11005: my ($currfile,$currsubfile,$embed_file) = @_;
11006: my ($size,$mtime,$showsize,$showmtime);
11007: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11008: if ($embed_file =~ m{/}) {
11009: my ($path,$fname) = split(/\//,$embed_file);
11010: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11011: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11012: }
11013: } else {
11014: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11015: ($size,$mtime) = @{$currfile->{$embed_file}};
11016: }
11017: }
11018: $showsize = $size/1024.0;
11019: $showsize = sprintf("%.1f",$showsize);
11020: if ($mtime > 0) {
11021: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11022: }
11023: }
11024: return ($showsize,$showmtime);
11025: }
11026:
11027: sub ask_embedded_js {
11028: return <<"END";
11029: <script type="text/javascript"">
11030: // <![CDATA[
11031: function toggleBrowse(counter) {
11032: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11033: var fileid = document.getElementById('embedded_item_'+counter);
11034: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11035: if (chkboxid.checked == true) {
11036: uploaddivid.style.display='block';
11037: } else {
11038: uploaddivid.style.display='none';
11039: fileid.value = '';
11040: }
11041: }
11042: // ]]>
11043: </script>
11044:
11045: END
11046: }
11047:
1.661 raeburn 11048: sub upload_embedded {
11049: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11050: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11051: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11052: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11053: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11054: my $orig_uploaded_filename =
11055: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11056: foreach my $type ('orig','ref','attrib','codebase') {
11057: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11058: $env{'form.embedded_'.$type.'_'.$i} =
11059: &unescape($env{'form.embedded_'.$type.'_'.$i});
11060: }
11061: }
1.661 raeburn 11062: my ($path,$fname) =
11063: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11064: # no path, whole string is fname
11065: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11066: $fname = &Apache::lonnet::clean_filename($fname);
11067: # See if there is anything left
11068: next if ($fname eq '');
11069:
11070: # Check if file already exists as a file or directory.
11071: my ($state,$msg);
11072: if ($context eq 'portfolio') {
11073: my $port_path = $dirpath;
11074: if ($group ne '') {
11075: $port_path = "groups/$group/$port_path";
11076: }
1.987 raeburn 11077: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11078: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11079: $dir_root,$port_path,$disk_quota,
11080: $current_disk_usage,$uname,$udom);
11081: if ($state eq 'will_exceed_quota'
1.984 raeburn 11082: || $state eq 'file_locked') {
1.661 raeburn 11083: $output .= $msg;
11084: next;
11085: }
11086: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11087: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11088: if ($state eq 'exists') {
11089: $output .= $msg;
11090: next;
11091: }
11092: }
11093: # Check if extension is valid
11094: if (($fname =~ /\.(\w+)$/) &&
11095: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 11096: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11097: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11098: next;
11099: } elsif (($fname =~ /\.(\w+)$/) &&
11100: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11101: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11102: next;
11103: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 11104: $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 11105: next;
11106: }
11107: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 11108: my $subdir = $path;
11109: $subdir =~ s{/+$}{};
1.661 raeburn 11110: if ($context eq 'portfolio') {
1.984 raeburn 11111: my $result;
11112: if ($state eq 'existingfile') {
11113: $result=
11114: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 11115: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11116: } else {
1.984 raeburn 11117: $result=
11118: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11119: $dirpath.
1.1075.2.35 raeburn 11120: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11121: if ($result !~ m|^/uploaded/|) {
11122: $output .= '<span class="LC_error">'
11123: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11124: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11125: .'</span><br />';
11126: next;
11127: } else {
1.987 raeburn 11128: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11129: $path.$fname.'</span>').'<br />';
1.984 raeburn 11130: }
1.661 raeburn 11131: }
1.1075.2.35 raeburn 11132: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
11133: my $extendedsubdir = $dirpath.'/'.$subdir;
11134: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11135: my $result =
1.1075.2.35 raeburn 11136: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11137: if ($result !~ m|^/uploaded/|) {
11138: $output .= '<span class="LC_error">'
11139: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11140: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11141: .'</span><br />';
11142: next;
11143: } else {
11144: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11145: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 11146: if ($context eq 'syllabus') {
11147: &Apache::lonnet::make_public_indefinitely($result);
11148: }
1.987 raeburn 11149: }
1.661 raeburn 11150: } else {
11151: # Save the file
11152: my $target = $env{'form.embedded_item_'.$i};
11153: my $fullpath = $dir_root.$dirpath.'/'.$path;
11154: my $dest = $fullpath.$fname;
11155: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11156: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11157: my $count;
11158: my $filepath = $dir_root;
1.1027 raeburn 11159: foreach my $subdir (@parts) {
11160: $filepath .= "/$subdir";
11161: if (!-e $filepath) {
1.661 raeburn 11162: mkdir($filepath,0770);
11163: }
11164: }
11165: my $fh;
11166: if (!open($fh,'>'.$dest)) {
11167: &Apache::lonnet::logthis('Failed to create '.$dest);
11168: $output .= '<span class="LC_error">'.
1.1071 raeburn 11169: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11170: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11171: '</span><br />';
11172: } else {
11173: if (!print $fh $env{'form.embedded_item_'.$i}) {
11174: &Apache::lonnet::logthis('Failed to write to '.$dest);
11175: $output .= '<span class="LC_error">'.
1.1071 raeburn 11176: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11177: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11178: '</span><br />';
11179: } else {
1.987 raeburn 11180: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11181: $url.'</span>').'<br />';
11182: unless ($context eq 'testbank') {
11183: $footer .= &mt('View embedded file: [_1]',
11184: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11185: }
11186: }
11187: close($fh);
11188: }
11189: }
11190: if ($env{'form.embedded_ref_'.$i}) {
11191: $pathchange{$i} = 1;
11192: }
11193: }
11194: if ($output) {
11195: $output = '<p>'.$output.'</p>';
11196: }
11197: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11198: $returnflag = 'ok';
1.1071 raeburn 11199: my $numpathchgs = scalar(keys(%pathchange));
11200: if ($numpathchgs > 0) {
1.987 raeburn 11201: if ($context eq 'portfolio') {
11202: $output .= '<p>'.&mt('or').'</p>';
11203: } elsif ($context eq 'testbank') {
1.1071 raeburn 11204: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11205: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11206: $returnflag = 'modify_orightml';
11207: }
11208: }
1.1071 raeburn 11209: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11210: }
11211:
11212: sub modify_html_form {
11213: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11214: my $end = 0;
11215: my $modifyform;
11216: if ($context eq 'upload_embedded') {
11217: return unless (ref($pathchange) eq 'HASH');
11218: if ($env{'form.number_embedded_items'}) {
11219: $end += $env{'form.number_embedded_items'};
11220: }
11221: if ($env{'form.number_pathchange_items'}) {
11222: $end += $env{'form.number_pathchange_items'};
11223: }
11224: if ($end) {
11225: for (my $i=0; $i<$end; $i++) {
11226: if ($i < $env{'form.number_embedded_items'}) {
11227: next unless($pathchange->{$i});
11228: }
11229: $modifyform .=
11230: &start_data_table_row().
11231: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11232: 'checked="checked" /></td>'.
11233: '<td>'.$env{'form.embedded_ref_'.$i}.
11234: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11235: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11236: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11237: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11238: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11239: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11240: '<td>'.$env{'form.embedded_orig_'.$i}.
11241: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11242: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11243: &end_data_table_row();
1.1071 raeburn 11244: }
1.987 raeburn 11245: }
11246: } else {
11247: $modifyform = $pathchgtable;
11248: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11249: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11250: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11251: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11252: }
11253: }
11254: if ($modifyform) {
1.1071 raeburn 11255: if ($actionurl eq '/adm/dependencies') {
11256: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11257: }
1.987 raeburn 11258: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11259: '<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".
11260: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11261: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11262: '</ol></p>'."\n".'<p>'.
11263: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11264: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11265: &start_data_table()."\n".
11266: &start_data_table_header_row().
11267: '<th>'.&mt('Change?').'</th>'.
11268: '<th>'.&mt('Current reference').'</th>'.
11269: '<th>'.&mt('Required reference').'</th>'.
11270: &end_data_table_header_row()."\n".
11271: $modifyform.
11272: &end_data_table().'<br />'."\n".$hiddenstate.
11273: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11274: '</form>'."\n";
11275: }
11276: return;
11277: }
11278:
11279: sub modify_html_refs {
1.1075.2.35 raeburn 11280: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11281: my $container;
11282: if ($context eq 'portfolio') {
11283: $container = $env{'form.container'};
11284: } elsif ($context eq 'coursedoc') {
11285: $container = $env{'form.primaryurl'};
1.1071 raeburn 11286: } elsif ($context eq 'manage_dependencies') {
11287: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11288: $container = "/$container";
1.1075.2.35 raeburn 11289: } elsif ($context eq 'syllabus') {
11290: $container = $url;
1.987 raeburn 11291: } else {
1.1027 raeburn 11292: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11293: }
11294: my (%allfiles,%codebase,$output,$content);
11295: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11296: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11297: if (wantarray) {
11298: return ('',0,0);
11299: } else {
11300: return;
11301: }
11302: }
11303: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11304: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11305: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11306: if (wantarray) {
11307: return ('',0,0);
11308: } else {
11309: return;
11310: }
11311: }
1.987 raeburn 11312: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11313: if ($content eq '-1') {
11314: if (wantarray) {
11315: return ('',0,0);
11316: } else {
11317: return;
11318: }
11319: }
1.987 raeburn 11320: } else {
1.1071 raeburn 11321: unless ($container =~ /^\Q$dir_root\E/) {
11322: if (wantarray) {
11323: return ('',0,0);
11324: } else {
11325: return;
11326: }
11327: }
1.987 raeburn 11328: if (open(my $fh,"<$container")) {
11329: $content = join('', <$fh>);
11330: close($fh);
11331: } else {
1.1071 raeburn 11332: if (wantarray) {
11333: return ('',0,0);
11334: } else {
11335: return;
11336: }
1.987 raeburn 11337: }
11338: }
11339: my ($count,$codebasecount) = (0,0);
11340: my $mm = new File::MMagic;
11341: my $mime_type = $mm->checktype_contents($content);
11342: if ($mime_type eq 'text/html') {
11343: my $parse_result =
11344: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11345: \%codebase,\$content);
11346: if ($parse_result eq 'ok') {
11347: foreach my $i (@changes) {
11348: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11349: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11350: if ($allfiles{$ref}) {
11351: my $newname = $orig;
11352: my ($attrib_regexp,$codebase);
1.1006 raeburn 11353: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11354: if ($attrib_regexp =~ /:/) {
11355: $attrib_regexp =~ s/\:/|/g;
11356: }
11357: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11358: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11359: $count += $numchg;
1.1075.2.35 raeburn 11360: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11361: delete($allfiles{$ref});
1.987 raeburn 11362: }
11363: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11364: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11365: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11366: $codebasecount ++;
11367: }
11368: }
11369: }
1.1075.2.35 raeburn 11370: my $skiprewrites;
1.987 raeburn 11371: if ($count || $codebasecount) {
11372: my $saveresult;
1.1071 raeburn 11373: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11374: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11375: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11376: if ($url eq $container) {
11377: my ($fname) = ($container =~ m{/([^/]+)$});
11378: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11379: $count,'<span class="LC_filename">'.
1.1071 raeburn 11380: $fname.'</span>').'</p>';
1.987 raeburn 11381: } else {
11382: $output = '<p class="LC_error">'.
11383: &mt('Error: update failed for: [_1].',
11384: '<span class="LC_filename">'.
11385: $container.'</span>').'</p>';
11386: }
1.1075.2.35 raeburn 11387: if ($context eq 'syllabus') {
11388: unless ($saveresult eq 'ok') {
11389: $skiprewrites = 1;
11390: }
11391: }
1.987 raeburn 11392: } else {
11393: if (open(my $fh,">$container")) {
11394: print $fh $content;
11395: close($fh);
11396: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11397: $count,'<span class="LC_filename">'.
11398: $container.'</span>').'</p>';
1.661 raeburn 11399: } else {
1.987 raeburn 11400: $output = '<p class="LC_error">'.
11401: &mt('Error: could not update [_1].',
11402: '<span class="LC_filename">'.
11403: $container.'</span>').'</p>';
1.661 raeburn 11404: }
11405: }
11406: }
1.1075.2.35 raeburn 11407: if (($context eq 'syllabus') && (!$skiprewrites)) {
11408: my ($actionurl,$state);
11409: $actionurl = "/public/$udom/$uname/syllabus";
11410: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11411: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11412: \%codebase,
11413: {'context' => 'rewrites',
11414: 'ignore_remote_references' => 1,});
11415: if (ref($mapping) eq 'HASH') {
11416: my $rewrites = 0;
11417: foreach my $key (keys(%{$mapping})) {
11418: next if ($key =~ m{^https?://});
11419: my $ref = $mapping->{$key};
11420: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11421: my $attrib;
11422: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11423: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11424: }
11425: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11426: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11427: $rewrites += $numchg;
11428: }
11429: }
11430: if ($rewrites) {
11431: my $saveresult;
11432: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11433: if ($url eq $container) {
11434: my ($fname) = ($container =~ m{/([^/]+)$});
11435: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11436: $count,'<span class="LC_filename">'.
11437: $fname.'</span>').'</p>';
11438: } else {
11439: $output .= '<p class="LC_error">'.
11440: &mt('Error: could not update links in [_1].',
11441: '<span class="LC_filename">'.
11442: $container.'</span>').'</p>';
11443:
11444: }
11445: }
11446: }
11447: }
1.987 raeburn 11448: } else {
11449: &logthis('Failed to parse '.$container.
11450: ' to modify references: '.$parse_result);
1.661 raeburn 11451: }
11452: }
1.1071 raeburn 11453: if (wantarray) {
11454: return ($output,$count,$codebasecount);
11455: } else {
11456: return $output;
11457: }
1.661 raeburn 11458: }
11459:
11460: sub check_for_existing {
11461: my ($path,$fname,$element) = @_;
11462: my ($state,$msg);
11463: if (-d $path.'/'.$fname) {
11464: $state = 'exists';
11465: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11466: } elsif (-e $path.'/'.$fname) {
11467: $state = 'exists';
11468: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11469: }
11470: if ($state eq 'exists') {
11471: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11472: }
11473: return ($state,$msg);
11474: }
11475:
11476: sub check_for_upload {
11477: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11478: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11479: my $filesize = length($env{'form.'.$element});
11480: if (!$filesize) {
11481: my $msg = '<span class="LC_error">'.
11482: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11483: '<span class="LC_filename">'.$fname.'</span>',
11484: $filesize).'<br />'.
1.1007 raeburn 11485: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11486: '</span>';
11487: return ('zero_bytes',$msg);
11488: }
11489: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11490: my $getpropath = 1;
1.1021 raeburn 11491: my ($dirlistref,$listerror) =
11492: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11493: my $found_file = 0;
11494: my $locked_file = 0;
1.991 raeburn 11495: my @lockers;
11496: my $navmap;
11497: if ($env{'request.course.id'}) {
11498: $navmap = Apache::lonnavmaps::navmap->new();
11499: }
1.1021 raeburn 11500: if (ref($dirlistref) eq 'ARRAY') {
11501: foreach my $line (@{$dirlistref}) {
11502: my ($file_name,$rest)=split(/\&/,$line,2);
11503: if ($file_name eq $fname){
11504: $file_name = $path.$file_name;
11505: if ($group ne '') {
11506: $file_name = $group.$file_name;
11507: }
11508: $found_file = 1;
11509: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11510: foreach my $lock (@lockers) {
11511: if (ref($lock) eq 'ARRAY') {
11512: my ($symb,$crsid) = @{$lock};
11513: if ($crsid eq $env{'request.course.id'}) {
11514: if (ref($navmap)) {
11515: my $res = $navmap->getBySymb($symb);
11516: foreach my $part (@{$res->parts()}) {
11517: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11518: unless (($slot_status == $res->RESERVED) ||
11519: ($slot_status == $res->RESERVED_LOCATION)) {
11520: $locked_file = 1;
11521: }
1.991 raeburn 11522: }
1.1021 raeburn 11523: } else {
11524: $locked_file = 1;
1.991 raeburn 11525: }
11526: } else {
11527: $locked_file = 1;
11528: }
11529: }
1.1021 raeburn 11530: }
11531: } else {
11532: my @info = split(/\&/,$rest);
11533: my $currsize = $info[6]/1000;
11534: if ($currsize < $filesize) {
11535: my $extra = $filesize - $currsize;
11536: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 11537: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11538: &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 11539: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11540: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11541: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11542: return ('will_exceed_quota',$msg);
11543: }
1.984 raeburn 11544: }
11545: }
1.661 raeburn 11546: }
11547: }
11548: }
11549: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 11550: my $msg = '<p class="LC_warning">'.
11551: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
11552: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11553: return ('will_exceed_quota',$msg);
11554: } elsif ($found_file) {
11555: if ($locked_file) {
1.1075.2.69 raeburn 11556: my $msg = '<p class="LC_warning">';
1.661 raeburn 11557: $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 11558: $msg .= '</p>';
1.661 raeburn 11559: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11560: return ('file_locked',$msg);
11561: } else {
1.1075.2.69 raeburn 11562: my $msg = '<p class="LC_error">';
1.984 raeburn 11563: $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 11564: $msg .= '</p>';
1.984 raeburn 11565: return ('existingfile',$msg);
1.661 raeburn 11566: }
11567: }
11568: }
11569:
1.987 raeburn 11570: sub check_for_traversal {
11571: my ($path,$url,$toplevel) = @_;
11572: my @parts=split(/\//,$path);
11573: my $cleanpath;
11574: my $fullpath = $url;
11575: for (my $i=0;$i<@parts;$i++) {
11576: next if ($parts[$i] eq '.');
11577: if ($parts[$i] eq '..') {
11578: $fullpath =~ s{([^/]+/)$}{};
11579: } else {
11580: $fullpath .= $parts[$i].'/';
11581: }
11582: }
11583: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11584: $cleanpath = $1;
11585: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11586: my $curr_toprel = $1;
11587: my @parts = split(/\//,$curr_toprel);
11588: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11589: my @urlparts = split(/\//,$url_toprel);
11590: my $doubledots;
11591: my $startdiff = -1;
11592: for (my $i=0; $i<@urlparts; $i++) {
11593: if ($startdiff == -1) {
11594: unless ($urlparts[$i] eq $parts[$i]) {
11595: $startdiff = $i;
11596: $doubledots .= '../';
11597: }
11598: } else {
11599: $doubledots .= '../';
11600: }
11601: }
11602: if ($startdiff > -1) {
11603: $cleanpath = $doubledots;
11604: for (my $i=$startdiff; $i<@parts; $i++) {
11605: $cleanpath .= $parts[$i].'/';
11606: }
11607: }
11608: }
11609: $cleanpath =~ s{(/)$}{};
11610: return $cleanpath;
11611: }
1.31 albertel 11612:
1.1053 raeburn 11613: sub is_archive_file {
11614: my ($mimetype) = @_;
11615: if (($mimetype eq 'application/octet-stream') ||
11616: ($mimetype eq 'application/x-stuffit') ||
11617: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11618: return 1;
11619: }
11620: return;
11621: }
11622:
11623: sub decompress_form {
1.1065 raeburn 11624: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11625: my %lt = &Apache::lonlocal::texthash (
11626: this => 'This file is an archive file.',
1.1067 raeburn 11627: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11628: itsc => 'Its contents are as follows:',
1.1053 raeburn 11629: youm => 'You may wish to extract its contents.',
11630: extr => 'Extract contents',
1.1067 raeburn 11631: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11632: proa => 'Process automatically?',
1.1053 raeburn 11633: yes => 'Yes',
11634: no => 'No',
1.1067 raeburn 11635: fold => 'Title for folder containing movie',
11636: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11637: );
1.1065 raeburn 11638: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11639: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11640: my $info = &list_archive_contents($fileloc,\@paths);
11641: if (@paths) {
11642: foreach my $path (@paths) {
11643: $path =~ s{^/}{};
1.1067 raeburn 11644: if ($path =~ m{^([^/]+)/$}) {
11645: $topdir = $1;
11646: }
1.1065 raeburn 11647: if ($path =~ m{^([^/]+)/}) {
11648: $toplevel{$1} = $path;
11649: } else {
11650: $toplevel{$path} = $path;
11651: }
11652: }
11653: }
1.1067 raeburn 11654: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 11655: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11656: "$topdir/media/",
11657: "$topdir/media/$topdir.mp4",
11658: "$topdir/media/FirstFrame.png",
11659: "$topdir/media/player.swf",
11660: "$topdir/media/swfobject.js",
11661: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 11662: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 11663: "$topdir/$topdir.mp4",
11664: "$topdir/$topdir\_config.xml",
11665: "$topdir/$topdir\_controller.swf",
11666: "$topdir/$topdir\_embed.css",
11667: "$topdir/$topdir\_First_Frame.png",
11668: "$topdir/$topdir\_player.html",
11669: "$topdir/$topdir\_Thumbnails.png",
11670: "$topdir/playerProductInstall.swf",
11671: "$topdir/scripts/",
11672: "$topdir/scripts/config_xml.js",
11673: "$topdir/scripts/handlebars.js",
11674: "$topdir/scripts/jquery-1.7.1.min.js",
11675: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11676: "$topdir/scripts/modernizr.js",
11677: "$topdir/scripts/player-min.js",
11678: "$topdir/scripts/swfobject.js",
11679: "$topdir/skins/",
11680: "$topdir/skins/configuration_express.xml",
11681: "$topdir/skins/express_show/",
11682: "$topdir/skins/express_show/player-min.css",
11683: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 11684: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11685: "$topdir/$topdir.mp4",
11686: "$topdir/$topdir\_config.xml",
11687: "$topdir/$topdir\_controller.swf",
11688: "$topdir/$topdir\_embed.css",
11689: "$topdir/$topdir\_First_Frame.png",
11690: "$topdir/$topdir\_player.html",
11691: "$topdir/$topdir\_Thumbnails.png",
11692: "$topdir/playerProductInstall.swf",
11693: "$topdir/scripts/",
11694: "$topdir/scripts/config_xml.js",
11695: "$topdir/scripts/techsmith-smart-player.min.js",
11696: "$topdir/skins/",
11697: "$topdir/skins/configuration_express.xml",
11698: "$topdir/skins/express_show/",
11699: "$topdir/skins/express_show/spritesheet.min.css",
11700: "$topdir/skins/express_show/spritesheet.png",
11701: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 11702: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11703: if (@diffs == 0) {
1.1075.2.59 raeburn 11704: $is_camtasia = 6;
11705: } else {
1.1075.2.81 raeburn 11706: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 11707: if (@diffs == 0) {
11708: $is_camtasia = 8;
1.1075.2.81 raeburn 11709: } else {
11710: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
11711: if (@diffs == 0) {
11712: $is_camtasia = 8;
11713: }
1.1075.2.59 raeburn 11714: }
1.1067 raeburn 11715: }
11716: }
11717: my $output;
11718: if ($is_camtasia) {
11719: $output = <<"ENDCAM";
11720: <script type="text/javascript" language="Javascript">
11721: // <![CDATA[
11722:
11723: function camtasiaToggle() {
11724: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11725: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 11726: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11727: document.getElementById('camtasia_titles').style.display='block';
11728: } else {
11729: document.getElementById('camtasia_titles').style.display='none';
11730: }
11731: }
11732: }
11733: return;
11734: }
11735:
11736: // ]]>
11737: </script>
11738: <p>$lt{'camt'}</p>
11739: ENDCAM
1.1065 raeburn 11740: } else {
1.1067 raeburn 11741: $output = '<p>'.$lt{'this'};
11742: if ($info eq '') {
11743: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11744: } else {
11745: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11746: '<div><pre>'.$info.'</pre></div>';
11747: }
1.1065 raeburn 11748: }
1.1067 raeburn 11749: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11750: my $duplicates;
11751: my $num = 0;
11752: if (ref($dirlist) eq 'ARRAY') {
11753: foreach my $item (@{$dirlist}) {
11754: if (ref($item) eq 'ARRAY') {
11755: if (exists($toplevel{$item->[0]})) {
11756: $duplicates .=
11757: &start_data_table_row().
11758: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11759: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11760: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11761: 'value="1" />'.&mt('Yes').'</label>'.
11762: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11763: '<td>'.$item->[0].'</td>';
11764: if ($item->[2]) {
11765: $duplicates .= '<td>'.&mt('Directory').'</td>';
11766: } else {
11767: $duplicates .= '<td>'.&mt('File').'</td>';
11768: }
11769: $duplicates .= '<td>'.$item->[3].'</td>'.
11770: '<td>'.
11771: &Apache::lonlocal::locallocaltime($item->[4]).
11772: '</td>'.
11773: &end_data_table_row();
11774: $num ++;
11775: }
11776: }
11777: }
11778: }
11779: my $itemcount;
11780: if (@paths > 0) {
11781: $itemcount = scalar(@paths);
11782: } else {
11783: $itemcount = 1;
11784: }
1.1067 raeburn 11785: if ($is_camtasia) {
11786: $output .= $lt{'auto'}.'<br />'.
11787: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 11788: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11789: $lt{'yes'}.'</label> <label>'.
11790: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11791: $lt{'no'}.'</label></span><br />'.
11792: '<div id="camtasia_titles" style="display:block">'.
11793: &Apache::lonhtmlcommon::start_pick_box().
11794: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11795: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11796: &Apache::lonhtmlcommon::row_closure().
11797: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11798: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11799: &Apache::lonhtmlcommon::row_closure(1).
11800: &Apache::lonhtmlcommon::end_pick_box().
11801: '</div>';
11802: }
1.1065 raeburn 11803: $output .=
11804: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11805: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11806: "\n";
1.1065 raeburn 11807: if ($duplicates ne '') {
11808: $output .= '<p><span class="LC_warning">'.
11809: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11810: &start_data_table().
11811: &start_data_table_header_row().
11812: '<th>'.&mt('Overwrite?').'</th>'.
11813: '<th>'.&mt('Name').'</th>'.
11814: '<th>'.&mt('Type').'</th>'.
11815: '<th>'.&mt('Size').'</th>'.
11816: '<th>'.&mt('Last modified').'</th>'.
11817: &end_data_table_header_row().
11818: $duplicates.
11819: &end_data_table().
11820: '</p>';
11821: }
1.1067 raeburn 11822: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11823: if (ref($hiddenelements) eq 'HASH') {
11824: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11825: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11826: }
11827: }
11828: $output .= <<"END";
1.1067 raeburn 11829: <br />
1.1053 raeburn 11830: <input type="submit" name="decompress" value="$lt{'extr'}" />
11831: </form>
11832: $noextract
11833: END
11834: return $output;
11835: }
11836:
1.1065 raeburn 11837: sub decompression_utility {
11838: my ($program) = @_;
11839: my @utilities = ('tar','gunzip','bunzip2','unzip');
11840: my $location;
11841: if (grep(/^\Q$program\E$/,@utilities)) {
11842: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11843: '/usr/sbin/') {
11844: if (-x $dir.$program) {
11845: $location = $dir.$program;
11846: last;
11847: }
11848: }
11849: }
11850: return $location;
11851: }
11852:
11853: sub list_archive_contents {
11854: my ($file,$pathsref) = @_;
11855: my (@cmd,$output);
11856: my $needsregexp;
11857: if ($file =~ /\.zip$/) {
11858: @cmd = (&decompression_utility('unzip'),"-l");
11859: $needsregexp = 1;
11860: } elsif (($file =~ m/\.tar\.gz$/) ||
11861: ($file =~ /\.tgz$/)) {
11862: @cmd = (&decompression_utility('tar'),"-ztf");
11863: } elsif ($file =~ /\.tar\.bz2$/) {
11864: @cmd = (&decompression_utility('tar'),"-jtf");
11865: } elsif ($file =~ m|\.tar$|) {
11866: @cmd = (&decompression_utility('tar'),"-tf");
11867: }
11868: if (@cmd) {
11869: undef($!);
11870: undef($@);
11871: if (open(my $fh,"-|", @cmd, $file)) {
11872: while (my $line = <$fh>) {
11873: $output .= $line;
11874: chomp($line);
11875: my $item;
11876: if ($needsregexp) {
11877: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11878: } else {
11879: $item = $line;
11880: }
11881: if ($item ne '') {
11882: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11883: push(@{$pathsref},$item);
11884: }
11885: }
11886: }
11887: close($fh);
11888: }
11889: }
11890: return $output;
11891: }
11892:
1.1053 raeburn 11893: sub decompress_uploaded_file {
11894: my ($file,$dir) = @_;
11895: &Apache::lonnet::appenv({'cgi.file' => $file});
11896: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11897: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11898: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11899: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11900: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11901: my $decompressed = $env{'cgi.decompressed'};
11902: &Apache::lonnet::delenv('cgi.file');
11903: &Apache::lonnet::delenv('cgi.dir');
11904: &Apache::lonnet::delenv('cgi.decompressed');
11905: return ($decompressed,$result);
11906: }
11907:
1.1055 raeburn 11908: sub process_decompression {
11909: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11910: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 11911: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 11912: $error = &mt('Filename not a supported archive file type.').
11913: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11914: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11915: } else {
11916: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11917: if ($docuhome eq 'no_host') {
11918: $error = &mt('Could not determine home server for course.');
11919: } else {
11920: my @ids=&Apache::lonnet::current_machine_ids();
11921: my $currdir = "$dir_root/$destination";
11922: if (grep(/^\Q$docuhome\E$/,@ids)) {
11923: $dir = &LONCAPA::propath($docudom,$docuname).
11924: "$dir_root/$destination";
11925: } else {
11926: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11927: "$dir_root/$docudom/$docuname/$destination";
11928: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11929: $error = &mt('Archive file not found.');
11930: }
11931: }
1.1065 raeburn 11932: my (@to_overwrite,@to_skip);
11933: if ($env{'form.archive_overwrite_total'} > 0) {
11934: my $total = $env{'form.archive_overwrite_total'};
11935: for (my $i=0; $i<$total; $i++) {
11936: if ($env{'form.archive_overwrite_'.$i} == 1) {
11937: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11938: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11939: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11940: }
11941: }
11942: }
11943: my $numskip = scalar(@to_skip);
11944: if (($numskip > 0) &&
11945: ($numskip == $env{'form.archive_itemcount'})) {
11946: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11947: } elsif ($dir eq '') {
1.1055 raeburn 11948: $error = &mt('Directory containing archive file unavailable.');
11949: } elsif (!$error) {
1.1065 raeburn 11950: my ($decompressed,$display);
11951: if ($numskip > 0) {
11952: my $tempdir = time.'_'.$$.int(rand(10000));
11953: mkdir("$dir/$tempdir",0755);
11954: system("mv $dir/$file $dir/$tempdir/$file");
11955: ($decompressed,$display) =
11956: &decompress_uploaded_file($file,"$dir/$tempdir");
11957: foreach my $item (@to_skip) {
11958: if (($item ne '') && ($item !~ /\.\./)) {
11959: if (-f "$dir/$tempdir/$item") {
11960: unlink("$dir/$tempdir/$item");
11961: } elsif (-d "$dir/$tempdir/$item") {
11962: system("rm -rf $dir/$tempdir/$item");
11963: }
11964: }
11965: }
11966: system("mv $dir/$tempdir/* $dir");
11967: rmdir("$dir/$tempdir");
11968: } else {
11969: ($decompressed,$display) =
11970: &decompress_uploaded_file($file,$dir);
11971: }
1.1055 raeburn 11972: if ($decompressed eq 'ok') {
1.1065 raeburn 11973: $output = '<p class="LC_info">'.
11974: &mt('Files extracted successfully from archive.').
11975: '</p>'."\n";
1.1055 raeburn 11976: my ($warning,$result,@contents);
11977: my ($newdirlistref,$newlisterror) =
11978: &Apache::lonnet::dirlist($currdir,$docudom,
11979: $docuname,1);
11980: my (%is_dir,%changes,@newitems);
11981: my $dirptr = 16384;
1.1065 raeburn 11982: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11983: foreach my $dir_line (@{$newdirlistref}) {
11984: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11985: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11986: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11987: push(@newitems,$item);
11988: if ($dirptr&$testdir) {
11989: $is_dir{$item} = 1;
11990: }
11991: $changes{$item} = 1;
11992: }
11993: }
11994: }
11995: if (keys(%changes) > 0) {
11996: foreach my $item (sort(@newitems)) {
11997: if ($changes{$item}) {
11998: push(@contents,$item);
11999: }
12000: }
12001: }
12002: if (@contents > 0) {
1.1067 raeburn 12003: my $wantform;
12004: unless ($env{'form.autoextract_camtasia'}) {
12005: $wantform = 1;
12006: }
1.1056 raeburn 12007: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12008: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12009: $currdir,\%is_dir,
12010: \%children,\%parent,
1.1056 raeburn 12011: \@contents,\%dirorder,
12012: \%titles,$wantform);
1.1055 raeburn 12013: if ($datatable ne '') {
12014: $output .= &archive_options_form('decompressed',$datatable,
12015: $count,$hiddenelem);
1.1065 raeburn 12016: my $startcount = 6;
1.1055 raeburn 12017: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12018: \%titles,\%children);
1.1055 raeburn 12019: }
1.1067 raeburn 12020: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 12021: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12022: my %displayed;
12023: my $total = 1;
12024: $env{'form.archive_directory'} = [];
12025: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12026: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12027: $path =~ s{/$}{};
12028: my $item;
12029: if ($path ne '') {
12030: $item = "$path/$titles{$i}";
12031: } else {
12032: $item = $titles{$i};
12033: }
12034: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12035: if ($item eq $contents[0]) {
12036: push(@{$env{'form.archive_directory'}},$i);
12037: $env{'form.archive_'.$i} = 'display';
12038: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12039: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 12040: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12041: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12042: $env{'form.archive_'.$i} = 'display';
12043: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12044: $displayed{'web'} = $i;
12045: } else {
1.1075.2.59 raeburn 12046: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12047: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12048: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12049: push(@{$env{'form.archive_directory'}},$i);
12050: }
12051: $env{'form.archive_'.$i} = 'dependency';
12052: }
12053: $total ++;
12054: }
12055: for (my $i=1; $i<$total; $i++) {
12056: next if ($i == $displayed{'web'});
12057: next if ($i == $displayed{'folder'});
12058: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12059: }
12060: $env{'form.phase'} = 'decompress_cleanup';
12061: $env{'form.archivedelete'} = 1;
12062: $env{'form.archive_count'} = $total-1;
12063: $output .=
12064: &process_extracted_files('coursedocs',$docudom,
12065: $docuname,$destination,
12066: $dir_root,$hiddenelem);
12067: }
1.1055 raeburn 12068: } else {
12069: $warning = &mt('No new items extracted from archive file.');
12070: }
12071: } else {
12072: $output = $display;
12073: $error = &mt('An error occurred during extraction from the archive file.');
12074: }
12075: }
12076: }
12077: }
12078: if ($error) {
12079: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12080: $error.'</p>'."\n";
12081: }
12082: if ($warning) {
12083: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12084: }
12085: return $output;
12086: }
12087:
12088: sub get_extracted {
1.1056 raeburn 12089: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12090: $titles,$wantform) = @_;
1.1055 raeburn 12091: my $count = 0;
12092: my $depth = 0;
12093: my $datatable;
1.1056 raeburn 12094: my @hierarchy;
1.1055 raeburn 12095: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12096: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12097: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12098: foreach my $item (@{$contents}) {
12099: $count ++;
1.1056 raeburn 12100: @{$dirorder->{$count}} = @hierarchy;
12101: $titles->{$count} = $item;
1.1055 raeburn 12102: &archive_hierarchy($depth,$count,$parent,$children);
12103: if ($wantform) {
12104: $datatable .= &archive_row($is_dir->{$item},$item,
12105: $currdir,$depth,$count);
12106: }
12107: if ($is_dir->{$item}) {
12108: $depth ++;
1.1056 raeburn 12109: push(@hierarchy,$count);
12110: $parent->{$depth} = $count;
1.1055 raeburn 12111: $datatable .=
12112: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12113: \$depth,\$count,\@hierarchy,$dirorder,
12114: $children,$parent,$titles,$wantform);
1.1055 raeburn 12115: $depth --;
1.1056 raeburn 12116: pop(@hierarchy);
1.1055 raeburn 12117: }
12118: }
12119: return ($count,$datatable);
12120: }
12121:
12122: sub recurse_extracted_archive {
1.1056 raeburn 12123: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12124: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12125: my $result='';
1.1056 raeburn 12126: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12127: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12128: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12129: return $result;
12130: }
12131: my $dirptr = 16384;
12132: my ($newdirlistref,$newlisterror) =
12133: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12134: if (ref($newdirlistref) eq 'ARRAY') {
12135: foreach my $dir_line (@{$newdirlistref}) {
12136: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12137: unless ($item =~ /^\.+$/) {
12138: $$count ++;
1.1056 raeburn 12139: @{$dirorder->{$$count}} = @{$hierarchy};
12140: $titles->{$$count} = $item;
1.1055 raeburn 12141: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12142:
1.1055 raeburn 12143: my $is_dir;
12144: if ($dirptr&$testdir) {
12145: $is_dir = 1;
12146: }
12147: if ($wantform) {
12148: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12149: }
12150: if ($is_dir) {
12151: $$depth ++;
1.1056 raeburn 12152: push(@{$hierarchy},$$count);
12153: $parent->{$$depth} = $$count;
1.1055 raeburn 12154: $result .=
12155: &recurse_extracted_archive("$currdir/$item",$docudom,
12156: $docuname,$depth,$count,
1.1056 raeburn 12157: $hierarchy,$dirorder,$children,
12158: $parent,$titles,$wantform);
1.1055 raeburn 12159: $$depth --;
1.1056 raeburn 12160: pop(@{$hierarchy});
1.1055 raeburn 12161: }
12162: }
12163: }
12164: }
12165: return $result;
12166: }
12167:
12168: sub archive_hierarchy {
12169: my ($depth,$count,$parent,$children) =@_;
12170: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12171: if (exists($parent->{$depth})) {
12172: $children->{$parent->{$depth}} .= $count.':';
12173: }
12174: }
12175: return;
12176: }
12177:
12178: sub archive_row {
12179: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12180: my ($name) = ($item =~ m{([^/]+)$});
12181: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12182: 'display' => 'Add as file',
1.1055 raeburn 12183: 'dependency' => 'Include as dependency',
12184: 'discard' => 'Discard',
12185: );
12186: if ($is_dir) {
1.1059 raeburn 12187: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12188: }
1.1056 raeburn 12189: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12190: my $offset = 0;
1.1055 raeburn 12191: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12192: $offset ++;
1.1065 raeburn 12193: if ($action ne 'display') {
12194: $offset ++;
12195: }
1.1055 raeburn 12196: $output .= '<td><span class="LC_nobreak">'.
12197: '<label><input type="radio" name="archive_'.$count.
12198: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12199: my $text = $choices{$action};
12200: if ($is_dir) {
12201: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12202: if ($action eq 'display') {
1.1059 raeburn 12203: $text = &mt('Add as folder');
1.1055 raeburn 12204: }
1.1056 raeburn 12205: } else {
12206: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12207:
12208: }
12209: $output .= ' /> '.$choices{$action}.'</label></span>';
12210: if ($action eq 'dependency') {
12211: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12212: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12213: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12214: '<option value=""></option>'."\n".
12215: '</select>'."\n".
12216: '</div>';
1.1059 raeburn 12217: } elsif ($action eq 'display') {
12218: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12219: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12220: '</div>';
1.1055 raeburn 12221: }
1.1056 raeburn 12222: $output .= '</td>';
1.1055 raeburn 12223: }
12224: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12225: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12226: for (my $i=0; $i<$depth; $i++) {
12227: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12228: }
12229: if ($is_dir) {
12230: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12231: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12232: } else {
12233: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12234: }
12235: $output .= ' '.$name.'</td>'."\n".
12236: &end_data_table_row();
12237: return $output;
12238: }
12239:
12240: sub archive_options_form {
1.1065 raeburn 12241: my ($form,$display,$count,$hiddenelem) = @_;
12242: my %lt = &Apache::lonlocal::texthash(
12243: perm => 'Permanently remove archive file?',
12244: hows => 'How should each extracted item be incorporated in the course?',
12245: cont => 'Content actions for all',
12246: addf => 'Add as folder/file',
12247: incd => 'Include as dependency for a displayed file',
12248: disc => 'Discard',
12249: no => 'No',
12250: yes => 'Yes',
12251: save => 'Save',
12252: );
12253: my $output = <<"END";
12254: <form name="$form" method="post" action="">
12255: <p><span class="LC_nobreak">$lt{'perm'}
12256: <label>
12257: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12258: </label>
12259:
12260: <label>
12261: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12262: </span>
12263: </p>
12264: <input type="hidden" name="phase" value="decompress_cleanup" />
12265: <br />$lt{'hows'}
12266: <div class="LC_columnSection">
12267: <fieldset>
12268: <legend>$lt{'cont'}</legend>
12269: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12270: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12271: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12272: </fieldset>
12273: </div>
12274: END
12275: return $output.
1.1055 raeburn 12276: &start_data_table()."\n".
1.1065 raeburn 12277: $display."\n".
1.1055 raeburn 12278: &end_data_table()."\n".
12279: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12280: $hiddenelem.
1.1065 raeburn 12281: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12282: '</form>';
12283: }
12284:
12285: sub archive_javascript {
1.1056 raeburn 12286: my ($startcount,$numitems,$titles,$children) = @_;
12287: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12288: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12289: my $scripttag = <<START;
12290: <script type="text/javascript">
12291: // <![CDATA[
12292:
12293: function checkAll(form,prefix) {
12294: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12295: for (var i=0; i < form.elements.length; i++) {
12296: var id = form.elements[i].id;
12297: if ((id != '') && (id != undefined)) {
12298: if (idstr.test(id)) {
12299: if (form.elements[i].type == 'radio') {
12300: form.elements[i].checked = true;
1.1056 raeburn 12301: var nostart = i-$startcount;
1.1059 raeburn 12302: var offset = nostart%7;
12303: var count = (nostart-offset)/7;
1.1056 raeburn 12304: dependencyCheck(form,count,offset);
1.1055 raeburn 12305: }
12306: }
12307: }
12308: }
12309: }
12310:
12311: function propagateCheck(form,count) {
12312: if (count > 0) {
1.1059 raeburn 12313: var startelement = $startcount + ((count-1) * 7);
12314: for (var j=1; j<6; j++) {
12315: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12316: var item = startelement + j;
12317: if (form.elements[item].type == 'radio') {
12318: if (form.elements[item].checked) {
12319: containerCheck(form,count,j);
12320: break;
12321: }
1.1055 raeburn 12322: }
12323: }
12324: }
12325: }
12326: }
12327:
12328: numitems = $numitems
1.1056 raeburn 12329: var titles = new Array(numitems);
12330: var parents = new Array(numitems);
1.1055 raeburn 12331: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12332: parents[i] = new Array;
1.1055 raeburn 12333: }
1.1059 raeburn 12334: var maintitle = '$maintitle';
1.1055 raeburn 12335:
12336: START
12337:
1.1056 raeburn 12338: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12339: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12340: for (my $i=0; $i<@contents; $i ++) {
12341: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12342: }
12343: }
12344:
1.1056 raeburn 12345: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12346: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12347: }
12348:
1.1055 raeburn 12349: $scripttag .= <<END;
12350:
12351: function containerCheck(form,count,offset) {
12352: if (count > 0) {
1.1056 raeburn 12353: dependencyCheck(form,count,offset);
1.1059 raeburn 12354: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12355: form.elements[item].checked = true;
12356: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12357: if (parents[count].length > 0) {
12358: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12359: containerCheck(form,parents[count][j],offset);
12360: }
12361: }
12362: }
12363: }
12364: }
12365:
12366: function dependencyCheck(form,count,offset) {
12367: if (count > 0) {
1.1059 raeburn 12368: var chosen = (offset+$startcount)+7*(count-1);
12369: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12370: var currtype = form.elements[depitem].type;
12371: if (form.elements[chosen].value == 'dependency') {
12372: document.getElementById('arc_depon_'+count).style.display='block';
12373: form.elements[depitem].options.length = 0;
12374: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12375: for (var i=1; i<=numitems; i++) {
12376: if (i == count) {
12377: continue;
12378: }
1.1059 raeburn 12379: var startelement = $startcount + (i-1) * 7;
12380: for (var j=1; j<6; j++) {
12381: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12382: var item = startelement + j;
12383: if (form.elements[item].type == 'radio') {
12384: if (form.elements[item].checked) {
12385: if (form.elements[item].value == 'display') {
12386: var n = form.elements[depitem].options.length;
12387: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12388: }
12389: }
12390: }
12391: }
12392: }
12393: }
12394: } else {
12395: document.getElementById('arc_depon_'+count).style.display='none';
12396: form.elements[depitem].options.length = 0;
12397: form.elements[depitem].options[0] = new Option('Select','',true,true);
12398: }
1.1059 raeburn 12399: titleCheck(form,count,offset);
1.1056 raeburn 12400: }
12401: }
12402:
12403: function propagateSelect(form,count,offset) {
12404: if (count > 0) {
1.1065 raeburn 12405: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12406: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12407: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12408: if (parents[count].length > 0) {
12409: for (var j=0; j<parents[count].length; j++) {
12410: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12411: }
12412: }
12413: }
12414: }
12415: }
1.1056 raeburn 12416:
12417: function containerSelect(form,count,offset,picked) {
12418: if (count > 0) {
1.1065 raeburn 12419: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12420: if (form.elements[item].type == 'radio') {
12421: if (form.elements[item].value == 'dependency') {
12422: if (form.elements[item+1].type == 'select-one') {
12423: for (var i=0; i<form.elements[item+1].options.length; i++) {
12424: if (form.elements[item+1].options[i].value == picked) {
12425: form.elements[item+1].selectedIndex = i;
12426: break;
12427: }
12428: }
12429: }
12430: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12431: if (parents[count].length > 0) {
12432: for (var j=0; j<parents[count].length; j++) {
12433: containerSelect(form,parents[count][j],offset,picked);
12434: }
12435: }
12436: }
12437: }
12438: }
12439: }
12440: }
12441:
1.1059 raeburn 12442: function titleCheck(form,count,offset) {
12443: if (count > 0) {
12444: var chosen = (offset+$startcount)+7*(count-1);
12445: var depitem = $startcount + ((count-1) * 7) + 2;
12446: var currtype = form.elements[depitem].type;
12447: if (form.elements[chosen].value == 'display') {
12448: document.getElementById('arc_title_'+count).style.display='block';
12449: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12450: document.getElementById('archive_title_'+count).value=maintitle;
12451: }
12452: } else {
12453: document.getElementById('arc_title_'+count).style.display='none';
12454: if (currtype == 'text') {
12455: document.getElementById('archive_title_'+count).value='';
12456: }
12457: }
12458: }
12459: return;
12460: }
12461:
1.1055 raeburn 12462: // ]]>
12463: </script>
12464: END
12465: return $scripttag;
12466: }
12467:
12468: sub process_extracted_files {
1.1067 raeburn 12469: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12470: my $numitems = $env{'form.archive_count'};
12471: return unless ($numitems);
12472: my @ids=&Apache::lonnet::current_machine_ids();
12473: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12474: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12475: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12476: if (grep(/^\Q$docuhome\E$/,@ids)) {
12477: $prefix = &LONCAPA::propath($docudom,$docuname);
12478: $pathtocheck = "$dir_root/$destination";
12479: $dir = $dir_root;
12480: $ishome = 1;
12481: } else {
12482: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12483: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
12484: $dir = "$dir_root/$docudom/$docuname";
12485: }
12486: my $currdir = "$dir_root/$destination";
12487: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12488: if ($env{'form.folderpath'}) {
12489: my @items = split('&',$env{'form.folderpath'});
12490: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 12491: if ($env{'form.folderpath'} =~ /\:1$/) {
12492: $containers{'0'}='page';
12493: } else {
12494: $containers{'0'}='sequence';
12495: }
1.1055 raeburn 12496: }
12497: my @archdirs = &get_env_multiple('form.archive_directory');
12498: if ($numitems) {
12499: for (my $i=1; $i<=$numitems; $i++) {
12500: my $path = $env{'form.archive_content_'.$i};
12501: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12502: my $item = $1;
12503: $toplevelitems{$item} = $i;
12504: if (grep(/^\Q$i\E$/,@archdirs)) {
12505: $is_dir{$item} = 1;
12506: }
12507: }
12508: }
12509: }
1.1067 raeburn 12510: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12511: if (keys(%toplevelitems) > 0) {
12512: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12513: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12514: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12515: }
1.1066 raeburn 12516: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12517: if ($numitems) {
12518: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 12519: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12520: my $path = $env{'form.archive_content_'.$i};
12521: if ($path =~ /^\Q$pathtocheck\E/) {
12522: if ($env{'form.archive_'.$i} eq 'discard') {
12523: if ($prefix ne '' && $path ne '') {
12524: if (-e $prefix.$path) {
1.1066 raeburn 12525: if ((@archdirs > 0) &&
12526: (grep(/^\Q$i\E$/,@archdirs))) {
12527: $todeletedir{$prefix.$path} = 1;
12528: } else {
12529: $todelete{$prefix.$path} = 1;
12530: }
1.1055 raeburn 12531: }
12532: }
12533: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12534: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12535: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12536: $docstitle = $env{'form.archive_title_'.$i};
12537: if ($docstitle eq '') {
12538: $docstitle = $title;
12539: }
1.1055 raeburn 12540: $outer = 0;
1.1056 raeburn 12541: if (ref($dirorder{$i}) eq 'ARRAY') {
12542: if (@{$dirorder{$i}} > 0) {
12543: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12544: if ($env{'form.archive_'.$item} eq 'display') {
12545: $outer = $item;
12546: last;
12547: }
12548: }
12549: }
12550: }
12551: my ($errtext,$fatal) =
12552: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12553: '/'.$folders{$outer}.'.'.
12554: $containers{$outer});
12555: next if ($fatal);
12556: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12557: if ($context eq 'coursedocs') {
1.1056 raeburn 12558: $mapinner{$i} = time;
1.1055 raeburn 12559: $folders{$i} = 'default_'.$mapinner{$i};
12560: $containers{$i} = 'sequence';
12561: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12562: $folders{$i}.'.'.$containers{$i};
12563: my $newidx = &LONCAPA::map::getresidx();
12564: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12565: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12566: push(@LONCAPA::map::order,$newidx);
12567: my ($outtext,$errtext) =
12568: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12569: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12570: '.'.$containers{$outer},1,1);
1.1056 raeburn 12571: $newseqid{$i} = $newidx;
1.1067 raeburn 12572: unless ($errtext) {
12573: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
12574: }
1.1055 raeburn 12575: }
12576: } else {
12577: if ($context eq 'coursedocs') {
12578: my $newidx=&LONCAPA::map::getresidx();
12579: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12580: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12581: $title;
12582: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12583: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
12584: }
12585: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12586: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12587: }
12588: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12589: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 12590: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 12591: unless ($ishome) {
12592: my $fetch = "$newdest{$i}/$title";
12593: $fetch =~ s/^\Q$prefix$dir\E//;
12594: $prompttofetch{$fetch} = 1;
12595: }
1.1055 raeburn 12596: }
12597: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12598: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12599: push(@LONCAPA::map::order, $newidx);
12600: my ($outtext,$errtext)=
12601: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12602: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12603: '.'.$containers{$outer},1,1);
1.1067 raeburn 12604: unless ($errtext) {
12605: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
12606: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
12607: }
12608: }
1.1055 raeburn 12609: }
12610: }
1.1075.2.11 raeburn 12611: }
12612: } else {
12613: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12614: }
12615: }
12616: for (my $i=1; $i<=$numitems; $i++) {
12617: next unless ($env{'form.archive_'.$i} eq 'dependency');
12618: my $path = $env{'form.archive_content_'.$i};
12619: if ($path =~ /^\Q$pathtocheck\E/) {
12620: my ($title) = ($path =~ m{/([^/]+)$});
12621: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12622: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12623: if (ref($dirorder{$i}) eq 'ARRAY') {
12624: my ($itemidx,$fullpath,$relpath);
12625: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12626: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12627: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 12628: if ($dirorder{$i}->[$j] eq $container) {
12629: $itemidx = $j;
1.1056 raeburn 12630: }
12631: }
1.1075.2.11 raeburn 12632: }
12633: if ($itemidx eq '') {
12634: $itemidx = 0;
12635: }
12636: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12637: if ($mapinner{$referrer{$i}}) {
12638: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12639: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12640: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12641: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12642: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12643: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12644: if (!-e $fullpath) {
12645: mkdir($fullpath,0755);
1.1056 raeburn 12646: }
12647: }
1.1075.2.11 raeburn 12648: } else {
12649: last;
1.1056 raeburn 12650: }
1.1075.2.11 raeburn 12651: }
12652: }
12653: } elsif ($newdest{$referrer{$i}}) {
12654: $fullpath = $newdest{$referrer{$i}};
12655: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12656: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12657: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12658: last;
12659: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12660: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12661: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12662: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12663: if (!-e $fullpath) {
12664: mkdir($fullpath,0755);
1.1056 raeburn 12665: }
12666: }
1.1075.2.11 raeburn 12667: } else {
12668: last;
1.1056 raeburn 12669: }
1.1075.2.11 raeburn 12670: }
12671: }
12672: if ($fullpath ne '') {
12673: if (-e "$prefix$path") {
12674: system("mv $prefix$path $fullpath/$title");
12675: }
12676: if (-e "$fullpath/$title") {
12677: my $showpath;
12678: if ($relpath ne '') {
12679: $showpath = "$relpath/$title";
12680: } else {
12681: $showpath = "/$title";
1.1056 raeburn 12682: }
1.1075.2.11 raeburn 12683: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12684: }
12685: unless ($ishome) {
12686: my $fetch = "$fullpath/$title";
12687: $fetch =~ s/^\Q$prefix$dir\E//;
12688: $prompttofetch{$fetch} = 1;
1.1055 raeburn 12689: }
12690: }
12691: }
1.1075.2.11 raeburn 12692: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12693: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12694: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12695: }
12696: } else {
1.1075.2.11 raeburn 12697: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055 raeburn 12698: }
12699: }
12700: if (keys(%todelete)) {
12701: foreach my $key (keys(%todelete)) {
12702: unlink($key);
1.1066 raeburn 12703: }
12704: }
12705: if (keys(%todeletedir)) {
12706: foreach my $key (keys(%todeletedir)) {
12707: rmdir($key);
12708: }
12709: }
12710: foreach my $dir (sort(keys(%is_dir))) {
12711: if (($pathtocheck ne '') && ($dir ne '')) {
12712: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12713: }
12714: }
1.1067 raeburn 12715: if ($result ne '') {
12716: $output .= '<ul>'."\n".
12717: $result."\n".
12718: '</ul>';
12719: }
12720: unless ($ishome) {
12721: my $replicationfail;
12722: foreach my $item (keys(%prompttofetch)) {
12723: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12724: unless ($fetchresult eq 'ok') {
12725: $replicationfail .= '<li>'.$item.'</li>'."\n";
12726: }
12727: }
12728: if ($replicationfail) {
12729: $output .= '<p class="LC_error">'.
12730: &mt('Course home server failed to retrieve:').'<ul>'.
12731: $replicationfail.
12732: '</ul></p>';
12733: }
12734: }
1.1055 raeburn 12735: } else {
12736: $warning = &mt('No items found in archive.');
12737: }
12738: if ($error) {
12739: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12740: $error.'</p>'."\n";
12741: }
12742: if ($warning) {
12743: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12744: }
12745: return $output;
12746: }
12747:
1.1066 raeburn 12748: sub cleanup_empty_dirs {
12749: my ($path) = @_;
12750: if (($path ne '') && (-d $path)) {
12751: if (opendir(my $dirh,$path)) {
12752: my @dircontents = grep(!/^\./,readdir($dirh));
12753: my $numitems = 0;
12754: foreach my $item (@dircontents) {
12755: if (-d "$path/$item") {
1.1075.2.28 raeburn 12756: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12757: if (-e "$path/$item") {
12758: $numitems ++;
12759: }
12760: } else {
12761: $numitems ++;
12762: }
12763: }
12764: if ($numitems == 0) {
12765: rmdir($path);
12766: }
12767: closedir($dirh);
12768: }
12769: }
12770: return;
12771: }
12772:
1.41 ng 12773: =pod
1.45 matthew 12774:
1.1075.2.56 raeburn 12775: =item * &get_folder_hierarchy()
1.1068 raeburn 12776:
12777: Provides hierarchy of names of folders/sub-folders containing the current
12778: item,
12779:
12780: Inputs: 3
12781: - $navmap - navmaps object
12782:
12783: - $map - url for map (either the trigger itself, or map containing
12784: the resource, which is the trigger).
12785:
12786: - $showitem - 1 => show title for map itself; 0 => do not show.
12787:
12788: Outputs: 1 @pathitems - array of folder/subfolder names.
12789:
12790: =cut
12791:
12792: sub get_folder_hierarchy {
12793: my ($navmap,$map,$showitem) = @_;
12794: my @pathitems;
12795: if (ref($navmap)) {
12796: my $mapres = $navmap->getResourceByUrl($map);
12797: if (ref($mapres)) {
12798: my $pcslist = $mapres->map_hierarchy();
12799: if ($pcslist ne '') {
12800: my @pcs = split(/,/,$pcslist);
12801: foreach my $pc (@pcs) {
12802: if ($pc == 1) {
1.1075.2.38 raeburn 12803: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12804: } else {
12805: my $res = $navmap->getByMapPc($pc);
12806: if (ref($res)) {
12807: my $title = $res->compTitle();
12808: $title =~ s/\W+/_/g;
12809: if ($title ne '') {
12810: push(@pathitems,$title);
12811: }
12812: }
12813: }
12814: }
12815: }
1.1071 raeburn 12816: if ($showitem) {
12817: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 12818: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12819: } else {
12820: my $maptitle = $mapres->compTitle();
12821: $maptitle =~ s/\W+/_/g;
12822: if ($maptitle ne '') {
12823: push(@pathitems,$maptitle);
12824: }
1.1068 raeburn 12825: }
12826: }
12827: }
12828: }
12829: return @pathitems;
12830: }
12831:
12832: =pod
12833:
1.1015 raeburn 12834: =item * &get_turnedin_filepath()
12835:
12836: Determines path in a user's portfolio file for storage of files uploaded
12837: to a specific essayresponse or dropbox item.
12838:
12839: Inputs: 3 required + 1 optional.
12840: $symb is symb for resource, $uname and $udom are for current user (required).
12841: $caller is optional (can be "submission", if routine is called when storing
12842: an upoaded file when "Submit Answer" button was pressed).
12843:
12844: Returns array containing $path and $multiresp.
12845: $path is path in portfolio. $multiresp is 1 if this resource contains more
12846: than one file upload item. Callers of routine should append partid as a
12847: subdirectory to $path in cases where $multiresp is 1.
12848:
12849: Called by: homework/essayresponse.pm and homework/structuretags.pm
12850:
12851: =cut
12852:
12853: sub get_turnedin_filepath {
12854: my ($symb,$uname,$udom,$caller) = @_;
12855: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12856: my $turnindir;
12857: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12858: $turnindir = $userhash{'turnindir'};
12859: my ($path,$multiresp);
12860: if ($turnindir eq '') {
12861: if ($caller eq 'submission') {
12862: $turnindir = &mt('turned in');
12863: $turnindir =~ s/\W+/_/g;
12864: my %newhash = (
12865: 'turnindir' => $turnindir,
12866: );
12867: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12868: }
12869: }
12870: if ($turnindir ne '') {
12871: $path = '/'.$turnindir.'/';
12872: my ($multipart,$turnin,@pathitems);
12873: my $navmap = Apache::lonnavmaps::navmap->new();
12874: if (defined($navmap)) {
12875: my $mapres = $navmap->getResourceByUrl($map);
12876: if (ref($mapres)) {
12877: my $pcslist = $mapres->map_hierarchy();
12878: if ($pcslist ne '') {
12879: foreach my $pc (split(/,/,$pcslist)) {
12880: my $res = $navmap->getByMapPc($pc);
12881: if (ref($res)) {
12882: my $title = $res->compTitle();
12883: $title =~ s/\W+/_/g;
12884: if ($title ne '') {
1.1075.2.48 raeburn 12885: if (($pc > 1) && (length($title) > 12)) {
12886: $title = substr($title,0,12);
12887: }
1.1015 raeburn 12888: push(@pathitems,$title);
12889: }
12890: }
12891: }
12892: }
12893: my $maptitle = $mapres->compTitle();
12894: $maptitle =~ s/\W+/_/g;
12895: if ($maptitle ne '') {
1.1075.2.48 raeburn 12896: if (length($maptitle) > 12) {
12897: $maptitle = substr($maptitle,0,12);
12898: }
1.1015 raeburn 12899: push(@pathitems,$maptitle);
12900: }
12901: unless ($env{'request.state'} eq 'construct') {
12902: my $res = $navmap->getBySymb($symb);
12903: if (ref($res)) {
12904: my $partlist = $res->parts();
12905: my $totaluploads = 0;
12906: if (ref($partlist) eq 'ARRAY') {
12907: foreach my $part (@{$partlist}) {
12908: my @types = $res->responseType($part);
12909: my @ids = $res->responseIds($part);
12910: for (my $i=0; $i < scalar(@ids); $i++) {
12911: if ($types[$i] eq 'essay') {
12912: my $partid = $part.'_'.$ids[$i];
12913: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12914: $totaluploads ++;
12915: }
12916: }
12917: }
12918: }
12919: if ($totaluploads > 1) {
12920: $multiresp = 1;
12921: }
12922: }
12923: }
12924: }
12925: } else {
12926: return;
12927: }
12928: } else {
12929: return;
12930: }
12931: my $restitle=&Apache::lonnet::gettitle($symb);
12932: $restitle =~ s/\W+/_/g;
12933: if ($restitle eq '') {
12934: $restitle = ($resurl =~ m{/[^/]+$});
12935: if ($restitle eq '') {
12936: $restitle = time;
12937: }
12938: }
1.1075.2.48 raeburn 12939: if (length($restitle) > 12) {
12940: $restitle = substr($restitle,0,12);
12941: }
1.1015 raeburn 12942: push(@pathitems,$restitle);
12943: $path .= join('/',@pathitems);
12944: }
12945: return ($path,$multiresp);
12946: }
12947:
12948: =pod
12949:
1.464 albertel 12950: =back
1.41 ng 12951:
1.112 bowersj2 12952: =head1 CSV Upload/Handling functions
1.38 albertel 12953:
1.41 ng 12954: =over 4
12955:
1.648 raeburn 12956: =item * &upfile_store($r)
1.41 ng 12957:
12958: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12959: needs $env{'form.upfile'}
1.41 ng 12960: returns $datatoken to be put into hidden field
12961:
12962: =cut
1.31 albertel 12963:
12964: sub upfile_store {
12965: my $r=shift;
1.258 albertel 12966: $env{'form.upfile'}=~s/\r/\n/gs;
12967: $env{'form.upfile'}=~s/\f/\n/gs;
12968: $env{'form.upfile'}=~s/\n+/\n/gs;
12969: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12970:
1.258 albertel 12971: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12972: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12973: {
1.158 raeburn 12974: my $datafile = $r->dir_config('lonDaemons').
12975: '/tmp/'.$datatoken.'.tmp';
12976: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12977: print $fh $env{'form.upfile'};
1.158 raeburn 12978: close($fh);
12979: }
1.31 albertel 12980: }
12981: return $datatoken;
12982: }
12983:
1.56 matthew 12984: =pod
12985:
1.648 raeburn 12986: =item * &load_tmp_file($r)
1.41 ng 12987:
12988: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12989: needs $env{'form.datatoken'},
12990: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12991:
12992: =cut
1.31 albertel 12993:
12994: sub load_tmp_file {
12995: my $r=shift;
12996: my @studentdata=();
12997: {
1.158 raeburn 12998: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12999: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 13000: if ( open(my $fh,"<$studentfile") ) {
13001: @studentdata=<$fh>;
13002: close($fh);
13003: }
1.31 albertel 13004: }
1.258 albertel 13005: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13006: }
13007:
1.56 matthew 13008: =pod
13009:
1.648 raeburn 13010: =item * &upfile_record_sep()
1.41 ng 13011:
13012: Separate uploaded file into records
13013: returns array of records,
1.258 albertel 13014: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13015:
13016: =cut
1.31 albertel 13017:
13018: sub upfile_record_sep {
1.258 albertel 13019: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13020: } else {
1.248 albertel 13021: my @records;
1.258 albertel 13022: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13023: if ($line=~/^\s*$/) { next; }
13024: push(@records,$line);
13025: }
13026: return @records;
1.31 albertel 13027: }
13028: }
13029:
1.56 matthew 13030: =pod
13031:
1.648 raeburn 13032: =item * &record_sep($record)
1.41 ng 13033:
1.258 albertel 13034: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13035:
13036: =cut
13037:
1.263 www 13038: sub takeleft {
13039: my $index=shift;
13040: return substr('0000'.$index,-4,4);
13041: }
13042:
1.31 albertel 13043: sub record_sep {
13044: my $record=shift;
13045: my %components=();
1.258 albertel 13046: if ($env{'form.upfiletype'} eq 'xml') {
13047: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13048: my $i=0;
1.356 albertel 13049: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13050: $field=~s/^(\"|\')//;
13051: $field=~s/(\"|\')$//;
1.263 www 13052: $components{&takeleft($i)}=$field;
1.31 albertel 13053: $i++;
13054: }
1.258 albertel 13055: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13056: my $i=0;
1.356 albertel 13057: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13058: $field=~s/^(\"|\')//;
13059: $field=~s/(\"|\')$//;
1.263 www 13060: $components{&takeleft($i)}=$field;
1.31 albertel 13061: $i++;
13062: }
13063: } else {
1.561 www 13064: my $separator=',';
1.480 banghart 13065: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13066: $separator=';';
1.480 banghart 13067: }
1.31 albertel 13068: my $i=0;
1.561 www 13069: # the character we are looking for to indicate the end of a quote or a record
13070: my $looking_for=$separator;
13071: # do not add the characters to the fields
13072: my $ignore=0;
13073: # we just encountered a separator (or the beginning of the record)
13074: my $just_found_separator=1;
13075: # store the field we are working on here
13076: my $field='';
13077: # work our way through all characters in record
13078: foreach my $character ($record=~/(.)/g) {
13079: if ($character eq $looking_for) {
13080: if ($character ne $separator) {
13081: # Found the end of a quote, again looking for separator
13082: $looking_for=$separator;
13083: $ignore=1;
13084: } else {
13085: # Found a separator, store away what we got
13086: $components{&takeleft($i)}=$field;
13087: $i++;
13088: $just_found_separator=1;
13089: $ignore=0;
13090: $field='';
13091: }
13092: next;
13093: }
13094: # single or double quotation marks after a separator indicate beginning of a quote
13095: # we are now looking for the end of the quote and need to ignore separators
13096: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13097: $looking_for=$character;
13098: next;
13099: }
13100: # ignore would be true after we reached the end of a quote
13101: if ($ignore) { next; }
13102: if (($just_found_separator) && ($character=~/\s/)) { next; }
13103: $field.=$character;
13104: $just_found_separator=0;
1.31 albertel 13105: }
1.561 www 13106: # catch the very last entry, since we never encountered the separator
13107: $components{&takeleft($i)}=$field;
1.31 albertel 13108: }
13109: return %components;
13110: }
13111:
1.144 matthew 13112: ######################################################
13113: ######################################################
13114:
1.56 matthew 13115: =pod
13116:
1.648 raeburn 13117: =item * &upfile_select_html()
1.41 ng 13118:
1.144 matthew 13119: Return HTML code to select a file from the users machine and specify
13120: the file type.
1.41 ng 13121:
13122: =cut
13123:
1.144 matthew 13124: ######################################################
13125: ######################################################
1.31 albertel 13126: sub upfile_select_html {
1.144 matthew 13127: my %Types = (
13128: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13129: semisv => &mt('Semicolon separated values'),
1.144 matthew 13130: space => &mt('Space separated'),
13131: tab => &mt('Tabulator separated'),
13132: # xml => &mt('HTML/XML'),
13133: );
13134: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13135: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13136: foreach my $type (sort(keys(%Types))) {
13137: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13138: }
13139: $Str .= "</select>\n";
13140: return $Str;
1.31 albertel 13141: }
13142:
1.301 albertel 13143: sub get_samples {
13144: my ($records,$toget) = @_;
13145: my @samples=({});
13146: my $got=0;
13147: foreach my $rec (@$records) {
13148: my %temp = &record_sep($rec);
13149: if (! grep(/\S/, values(%temp))) { next; }
13150: if (%temp) {
13151: $samples[$got]=\%temp;
13152: $got++;
13153: if ($got == $toget) { last; }
13154: }
13155: }
13156: return \@samples;
13157: }
13158:
1.144 matthew 13159: ######################################################
13160: ######################################################
13161:
1.56 matthew 13162: =pod
13163:
1.648 raeburn 13164: =item * &csv_print_samples($r,$records)
1.41 ng 13165:
13166: Prints a table of sample values from each column uploaded $r is an
13167: Apache Request ref, $records is an arrayref from
13168: &Apache::loncommon::upfile_record_sep
13169:
13170: =cut
13171:
1.144 matthew 13172: ######################################################
13173: ######################################################
1.31 albertel 13174: sub csv_print_samples {
13175: my ($r,$records) = @_;
1.662 bisitz 13176: my $samples = &get_samples($records,5);
1.301 albertel 13177:
1.594 raeburn 13178: $r->print(&mt('Samples').'<br />'.&start_data_table().
13179: &start_data_table_header_row());
1.356 albertel 13180: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13181: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13182: $r->print(&end_data_table_header_row());
1.301 albertel 13183: foreach my $hash (@$samples) {
1.594 raeburn 13184: $r->print(&start_data_table_row());
1.356 albertel 13185: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13186: $r->print('<td>');
1.356 albertel 13187: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13188: $r->print('</td>');
13189: }
1.594 raeburn 13190: $r->print(&end_data_table_row());
1.31 albertel 13191: }
1.594 raeburn 13192: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13193: }
13194:
1.144 matthew 13195: ######################################################
13196: ######################################################
13197:
1.56 matthew 13198: =pod
13199:
1.648 raeburn 13200: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13201:
13202: Prints a table to create associations between values and table columns.
1.144 matthew 13203:
1.41 ng 13204: $r is an Apache Request ref,
13205: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13206: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13207:
13208: =cut
13209:
1.144 matthew 13210: ######################################################
13211: ######################################################
1.31 albertel 13212: sub csv_print_select_table {
13213: my ($r,$records,$d) = @_;
1.301 albertel 13214: my $i=0;
13215: my $samples = &get_samples($records,1);
1.144 matthew 13216: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13217: &start_data_table().&start_data_table_header_row().
1.144 matthew 13218: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13219: '<th>'.&mt('Column').'</th>'.
13220: &end_data_table_header_row()."\n");
1.356 albertel 13221: foreach my $array_ref (@$d) {
13222: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13223: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13224:
1.875 bisitz 13225: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13226: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13227: $r->print('<option value="none"></option>');
1.356 albertel 13228: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13229: $r->print('<option value="'.$sample.'"'.
13230: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13231: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13232: }
1.594 raeburn 13233: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13234: $i++;
13235: }
1.594 raeburn 13236: $r->print(&end_data_table());
1.31 albertel 13237: $i--;
13238: return $i;
13239: }
1.56 matthew 13240:
1.144 matthew 13241: ######################################################
13242: ######################################################
13243:
1.56 matthew 13244: =pod
1.31 albertel 13245:
1.648 raeburn 13246: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13247:
13248: Prints a table of sample values from the upload and can make associate samples to internal names.
13249:
13250: $r is an Apache Request ref,
13251: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13252: $d is an array of 2 element arrays (internal name, displayed name)
13253:
13254: =cut
13255:
1.144 matthew 13256: ######################################################
13257: ######################################################
1.31 albertel 13258: sub csv_samples_select_table {
13259: my ($r,$records,$d) = @_;
13260: my $i=0;
1.144 matthew 13261: #
1.662 bisitz 13262: my $max_samples = 5;
13263: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13264: $r->print(&start_data_table().
13265: &start_data_table_header_row().'<th>'.
13266: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13267: &end_data_table_header_row());
1.301 albertel 13268:
13269: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13270: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13271: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13272: foreach my $option (@$d) {
13273: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13274: $r->print('<option value="'.$value.'"'.
1.253 albertel 13275: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13276: $display.'</option>');
1.31 albertel 13277: }
13278: $r->print('</select></td><td>');
1.662 bisitz 13279: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13280: if (defined($samples->[$line]{$key})) {
13281: $r->print($samples->[$line]{$key}."<br />\n");
13282: }
13283: }
1.594 raeburn 13284: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13285: $i++;
13286: }
1.594 raeburn 13287: $r->print(&end_data_table());
1.31 albertel 13288: $i--;
13289: return($i);
1.115 matthew 13290: }
13291:
1.144 matthew 13292: ######################################################
13293: ######################################################
13294:
1.115 matthew 13295: =pod
13296:
1.648 raeburn 13297: =item * &clean_excel_name($name)
1.115 matthew 13298:
13299: Returns a replacement for $name which does not contain any illegal characters.
13300:
13301: =cut
13302:
1.144 matthew 13303: ######################################################
13304: ######################################################
1.115 matthew 13305: sub clean_excel_name {
13306: my ($name) = @_;
13307: $name =~ s/[:\*\?\/\\]//g;
13308: if (length($name) > 31) {
13309: $name = substr($name,0,31);
13310: }
13311: return $name;
1.25 albertel 13312: }
1.84 albertel 13313:
1.85 albertel 13314: =pod
13315:
1.648 raeburn 13316: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13317:
13318: Returns either 1 or undef
13319:
13320: 1 if the part is to be hidden, undef if it is to be shown
13321:
13322: Arguments are:
13323:
13324: $id the id of the part to be checked
13325: $symb, optional the symb of the resource to check
13326: $udom, optional the domain of the user to check for
13327: $uname, optional the username of the user to check for
13328:
13329: =cut
1.84 albertel 13330:
13331: sub check_if_partid_hidden {
13332: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13333: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13334: $symb,$udom,$uname);
1.141 albertel 13335: my $truth=1;
13336: #if the string starts with !, then the list is the list to show not hide
13337: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13338: my @hiddenlist=split(/,/,$hiddenparts);
13339: foreach my $checkid (@hiddenlist) {
1.141 albertel 13340: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13341: }
1.141 albertel 13342: return !$truth;
1.84 albertel 13343: }
1.127 matthew 13344:
1.138 matthew 13345:
13346: ############################################################
13347: ############################################################
13348:
13349: =pod
13350:
1.157 matthew 13351: =back
13352:
1.138 matthew 13353: =head1 cgi-bin script and graphing routines
13354:
1.157 matthew 13355: =over 4
13356:
1.648 raeburn 13357: =item * &get_cgi_id()
1.138 matthew 13358:
13359: Inputs: none
13360:
13361: Returns an id which can be used to pass environment variables
13362: to various cgi-bin scripts. These environment variables will
13363: be removed from the users environment after a given time by
13364: the routine &Apache::lonnet::transfer_profile_to_env.
13365:
13366: =cut
13367:
13368: ############################################################
13369: ############################################################
1.152 albertel 13370: my $uniq=0;
1.136 matthew 13371: sub get_cgi_id {
1.154 albertel 13372: $uniq=($uniq+1)%100000;
1.280 albertel 13373: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13374: }
13375:
1.127 matthew 13376: ############################################################
13377: ############################################################
13378:
13379: =pod
13380:
1.648 raeburn 13381: =item * &DrawBarGraph()
1.127 matthew 13382:
1.138 matthew 13383: Facilitates the plotting of data in a (stacked) bar graph.
13384: Puts plot definition data into the users environment in order for
13385: graph.png to plot it. Returns an <img> tag for the plot.
13386: The bars on the plot are labeled '1','2',...,'n'.
13387:
13388: Inputs:
13389:
13390: =over 4
13391:
13392: =item $Title: string, the title of the plot
13393:
13394: =item $xlabel: string, text describing the X-axis of the plot
13395:
13396: =item $ylabel: string, text describing the Y-axis of the plot
13397:
13398: =item $Max: scalar, the maximum Y value to use in the plot
13399: If $Max is < any data point, the graph will not be rendered.
13400:
1.140 matthew 13401: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13402: they are plotted. If undefined, default values will be used.
13403:
1.178 matthew 13404: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13405:
1.138 matthew 13406: =item @Values: An array of array references. Each array reference holds data
13407: to be plotted in a stacked bar chart.
13408:
1.239 matthew 13409: =item If the final element of @Values is a hash reference the key/value
13410: pairs will be added to the graph definition.
13411:
1.138 matthew 13412: =back
13413:
13414: Returns:
13415:
13416: An <img> tag which references graph.png and the appropriate identifying
13417: information for the plot.
13418:
1.127 matthew 13419: =cut
13420:
13421: ############################################################
13422: ############################################################
1.134 matthew 13423: sub DrawBarGraph {
1.178 matthew 13424: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13425: #
13426: if (! defined($colors)) {
13427: $colors = ['#33ff00',
13428: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13429: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13430: ];
13431: }
1.228 matthew 13432: my $extra_settings = {};
13433: if (ref($Values[-1]) eq 'HASH') {
13434: $extra_settings = pop(@Values);
13435: }
1.127 matthew 13436: #
1.136 matthew 13437: my $identifier = &get_cgi_id();
13438: my $id = 'cgi.'.$identifier;
1.129 matthew 13439: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13440: return '';
13441: }
1.225 matthew 13442: #
13443: my @Labels;
13444: if (defined($labels)) {
13445: @Labels = @$labels;
13446: } else {
13447: for (my $i=0;$i<@{$Values[0]};$i++) {
13448: push (@Labels,$i+1);
13449: }
13450: }
13451: #
1.129 matthew 13452: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13453: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13454: my %ValuesHash;
13455: my $NumSets=1;
13456: foreach my $array (@Values) {
13457: next if (! ref($array));
1.136 matthew 13458: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13459: join(',',@$array);
1.129 matthew 13460: }
1.127 matthew 13461: #
1.136 matthew 13462: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13463: if ($NumBars < 3) {
13464: $width = 120+$NumBars*32;
1.220 matthew 13465: $xskip = 1;
1.225 matthew 13466: $bar_width = 30;
13467: } elsif ($NumBars < 5) {
13468: $width = 120+$NumBars*20;
13469: $xskip = 1;
13470: $bar_width = 20;
1.220 matthew 13471: } elsif ($NumBars < 10) {
1.136 matthew 13472: $width = 120+$NumBars*15;
13473: $xskip = 1;
13474: $bar_width = 15;
13475: } elsif ($NumBars <= 25) {
13476: $width = 120+$NumBars*11;
13477: $xskip = 5;
13478: $bar_width = 8;
13479: } elsif ($NumBars <= 50) {
13480: $width = 120+$NumBars*8;
13481: $xskip = 5;
13482: $bar_width = 4;
13483: } else {
13484: $width = 120+$NumBars*8;
13485: $xskip = 5;
13486: $bar_width = 4;
13487: }
13488: #
1.137 matthew 13489: $Max = 1 if ($Max < 1);
13490: if ( int($Max) < $Max ) {
13491: $Max++;
13492: $Max = int($Max);
13493: }
1.127 matthew 13494: $Title = '' if (! defined($Title));
13495: $xlabel = '' if (! defined($xlabel));
13496: $ylabel = '' if (! defined($ylabel));
1.369 www 13497: $ValuesHash{$id.'.title'} = &escape($Title);
13498: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13499: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13500: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13501: $ValuesHash{$id.'.NumBars'} = $NumBars;
13502: $ValuesHash{$id.'.NumSets'} = $NumSets;
13503: $ValuesHash{$id.'.PlotType'} = 'bar';
13504: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13505: $ValuesHash{$id.'.height'} = $height;
13506: $ValuesHash{$id.'.width'} = $width;
13507: $ValuesHash{$id.'.xskip'} = $xskip;
13508: $ValuesHash{$id.'.bar_width'} = $bar_width;
13509: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13510: #
1.228 matthew 13511: # Deal with other parameters
13512: while (my ($key,$value) = each(%$extra_settings)) {
13513: $ValuesHash{$id.'.'.$key} = $value;
13514: }
13515: #
1.646 raeburn 13516: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13517: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13518: }
13519:
13520: ############################################################
13521: ############################################################
13522:
13523: =pod
13524:
1.648 raeburn 13525: =item * &DrawXYGraph()
1.137 matthew 13526:
1.138 matthew 13527: Facilitates the plotting of data in an XY graph.
13528: Puts plot definition data into the users environment in order for
13529: graph.png to plot it. Returns an <img> tag for the plot.
13530:
13531: Inputs:
13532:
13533: =over 4
13534:
13535: =item $Title: string, the title of the plot
13536:
13537: =item $xlabel: string, text describing the X-axis of the plot
13538:
13539: =item $ylabel: string, text describing the Y-axis of the plot
13540:
13541: =item $Max: scalar, the maximum Y value to use in the plot
13542: If $Max is < any data point, the graph will not be rendered.
13543:
13544: =item $colors: Array ref containing the hex color codes for the data to be
13545: plotted in. If undefined, default values will be used.
13546:
13547: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13548:
13549: =item $Ydata: Array ref containing Array refs.
1.185 www 13550: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13551:
13552: =item %Values: hash indicating or overriding any default values which are
13553: passed to graph.png.
13554: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13555:
13556: =back
13557:
13558: Returns:
13559:
13560: An <img> tag which references graph.png and the appropriate identifying
13561: information for the plot.
13562:
1.137 matthew 13563: =cut
13564:
13565: ############################################################
13566: ############################################################
13567: sub DrawXYGraph {
13568: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13569: #
13570: # Create the identifier for the graph
13571: my $identifier = &get_cgi_id();
13572: my $id = 'cgi.'.$identifier;
13573: #
13574: $Title = '' if (! defined($Title));
13575: $xlabel = '' if (! defined($xlabel));
13576: $ylabel = '' if (! defined($ylabel));
13577: my %ValuesHash =
13578: (
1.369 www 13579: $id.'.title' => &escape($Title),
13580: $id.'.xlabel' => &escape($xlabel),
13581: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13582: $id.'.y_max_value'=> $Max,
13583: $id.'.labels' => join(',',@$Xlabels),
13584: $id.'.PlotType' => 'XY',
13585: );
13586: #
13587: if (defined($colors) && ref($colors) eq 'ARRAY') {
13588: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13589: }
13590: #
13591: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13592: return '';
13593: }
13594: my $NumSets=1;
1.138 matthew 13595: foreach my $array (@{$Ydata}){
1.137 matthew 13596: next if (! ref($array));
13597: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13598: }
1.138 matthew 13599: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13600: #
13601: # Deal with other parameters
13602: while (my ($key,$value) = each(%Values)) {
13603: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13604: }
13605: #
1.646 raeburn 13606: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13607: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13608: }
13609:
13610: ############################################################
13611: ############################################################
13612:
13613: =pod
13614:
1.648 raeburn 13615: =item * &DrawXYYGraph()
1.138 matthew 13616:
13617: Facilitates the plotting of data in an XY graph with two Y axes.
13618: Puts plot definition data into the users environment in order for
13619: graph.png to plot it. Returns an <img> tag for the plot.
13620:
13621: Inputs:
13622:
13623: =over 4
13624:
13625: =item $Title: string, the title of the plot
13626:
13627: =item $xlabel: string, text describing the X-axis of the plot
13628:
13629: =item $ylabel: string, text describing the Y-axis of the plot
13630:
13631: =item $colors: Array ref containing the hex color codes for the data to be
13632: plotted in. If undefined, default values will be used.
13633:
13634: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13635:
13636: =item $Ydata1: The first data set
13637:
13638: =item $Min1: The minimum value of the left Y-axis
13639:
13640: =item $Max1: The maximum value of the left Y-axis
13641:
13642: =item $Ydata2: The second data set
13643:
13644: =item $Min2: The minimum value of the right Y-axis
13645:
13646: =item $Max2: The maximum value of the left Y-axis
13647:
13648: =item %Values: hash indicating or overriding any default values which are
13649: passed to graph.png.
13650: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13651:
13652: =back
13653:
13654: Returns:
13655:
13656: An <img> tag which references graph.png and the appropriate identifying
13657: information for the plot.
1.136 matthew 13658:
13659: =cut
13660:
13661: ############################################################
13662: ############################################################
1.137 matthew 13663: sub DrawXYYGraph {
13664: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13665: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13666: #
13667: # Create the identifier for the graph
13668: my $identifier = &get_cgi_id();
13669: my $id = 'cgi.'.$identifier;
13670: #
13671: $Title = '' if (! defined($Title));
13672: $xlabel = '' if (! defined($xlabel));
13673: $ylabel = '' if (! defined($ylabel));
13674: my %ValuesHash =
13675: (
1.369 www 13676: $id.'.title' => &escape($Title),
13677: $id.'.xlabel' => &escape($xlabel),
13678: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13679: $id.'.labels' => join(',',@$Xlabels),
13680: $id.'.PlotType' => 'XY',
13681: $id.'.NumSets' => 2,
1.137 matthew 13682: $id.'.two_axes' => 1,
13683: $id.'.y1_max_value' => $Max1,
13684: $id.'.y1_min_value' => $Min1,
13685: $id.'.y2_max_value' => $Max2,
13686: $id.'.y2_min_value' => $Min2,
1.136 matthew 13687: );
13688: #
1.137 matthew 13689: if (defined($colors) && ref($colors) eq 'ARRAY') {
13690: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13691: }
13692: #
13693: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13694: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13695: return '';
13696: }
13697: my $NumSets=1;
1.137 matthew 13698: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13699: next if (! ref($array));
13700: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13701: }
13702: #
13703: # Deal with other parameters
13704: while (my ($key,$value) = each(%Values)) {
13705: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13706: }
13707: #
1.646 raeburn 13708: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13709: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13710: }
13711:
13712: ############################################################
13713: ############################################################
13714:
13715: =pod
13716:
1.157 matthew 13717: =back
13718:
1.139 matthew 13719: =head1 Statistics helper routines?
13720:
13721: Bad place for them but what the hell.
13722:
1.157 matthew 13723: =over 4
13724:
1.648 raeburn 13725: =item * &chartlink()
1.139 matthew 13726:
13727: Returns a link to the chart for a specific student.
13728:
13729: Inputs:
13730:
13731: =over 4
13732:
13733: =item $linktext: The text of the link
13734:
13735: =item $sname: The students username
13736:
13737: =item $sdomain: The students domain
13738:
13739: =back
13740:
1.157 matthew 13741: =back
13742:
1.139 matthew 13743: =cut
13744:
13745: ############################################################
13746: ############################################################
13747: sub chartlink {
13748: my ($linktext, $sname, $sdomain) = @_;
13749: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13750: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13751: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13752: '">'.$linktext.'</a>';
1.153 matthew 13753: }
13754:
13755: #######################################################
13756: #######################################################
13757:
13758: =pod
13759:
13760: =head1 Course Environment Routines
1.157 matthew 13761:
13762: =over 4
1.153 matthew 13763:
1.648 raeburn 13764: =item * &restore_course_settings()
1.153 matthew 13765:
1.648 raeburn 13766: =item * &store_course_settings()
1.153 matthew 13767:
13768: Restores/Store indicated form parameters from the course environment.
13769: Will not overwrite existing values of the form parameters.
13770:
13771: Inputs:
13772: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13773:
13774: a hash ref describing the data to be stored. For example:
13775:
13776: %Save_Parameters = ('Status' => 'scalar',
13777: 'chartoutputmode' => 'scalar',
13778: 'chartoutputdata' => 'scalar',
13779: 'Section' => 'array',
1.373 raeburn 13780: 'Group' => 'array',
1.153 matthew 13781: 'StudentData' => 'array',
13782: 'Maps' => 'array');
13783:
13784: Returns: both routines return nothing
13785:
1.631 raeburn 13786: =back
13787:
1.153 matthew 13788: =cut
13789:
13790: #######################################################
13791: #######################################################
13792: sub store_course_settings {
1.496 albertel 13793: return &store_settings($env{'request.course.id'},@_);
13794: }
13795:
13796: sub store_settings {
1.153 matthew 13797: # save to the environment
13798: # appenv the same items, just to be safe
1.300 albertel 13799: my $udom = $env{'user.domain'};
13800: my $uname = $env{'user.name'};
1.496 albertel 13801: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13802: my %SaveHash;
13803: my %AppHash;
13804: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13805: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13806: my $envname = 'environment.'.$basename;
1.258 albertel 13807: if (exists($env{'form.'.$setting})) {
1.153 matthew 13808: # Save this value away
13809: if ($type eq 'scalar' &&
1.258 albertel 13810: (! exists($env{$envname}) ||
13811: $env{$envname} ne $env{'form.'.$setting})) {
13812: $SaveHash{$basename} = $env{'form.'.$setting};
13813: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13814: } elsif ($type eq 'array') {
13815: my $stored_form;
1.258 albertel 13816: if (ref($env{'form.'.$setting})) {
1.153 matthew 13817: $stored_form = join(',',
13818: map {
1.369 www 13819: &escape($_);
1.258 albertel 13820: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13821: } else {
13822: $stored_form =
1.369 www 13823: &escape($env{'form.'.$setting});
1.153 matthew 13824: }
13825: # Determine if the array contents are the same.
1.258 albertel 13826: if ($stored_form ne $env{$envname}) {
1.153 matthew 13827: $SaveHash{$basename} = $stored_form;
13828: $AppHash{$envname} = $stored_form;
13829: }
13830: }
13831: }
13832: }
13833: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13834: $udom,$uname);
1.153 matthew 13835: if ($put_result !~ /^(ok|delayed)/) {
13836: &Apache::lonnet::logthis('unable to save form parameters, '.
13837: 'got error:'.$put_result);
13838: }
13839: # Make sure these settings stick around in this session, too
1.646 raeburn 13840: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13841: return;
13842: }
13843:
13844: sub restore_course_settings {
1.499 albertel 13845: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13846: }
13847:
13848: sub restore_settings {
13849: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13850: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13851: next if (exists($env{'form.'.$setting}));
1.496 albertel 13852: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13853: '.'.$setting;
1.258 albertel 13854: if (exists($env{$envname})) {
1.153 matthew 13855: if ($type eq 'scalar') {
1.258 albertel 13856: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13857: } elsif ($type eq 'array') {
1.258 albertel 13858: $env{'form.'.$setting} = [
1.153 matthew 13859: map {
1.369 www 13860: &unescape($_);
1.258 albertel 13861: } split(',',$env{$envname})
1.153 matthew 13862: ];
13863: }
13864: }
13865: }
1.127 matthew 13866: }
13867:
1.618 raeburn 13868: #######################################################
13869: #######################################################
13870:
13871: =pod
13872:
13873: =head1 Domain E-mail Routines
13874:
13875: =over 4
13876:
1.648 raeburn 13877: =item * &build_recipient_list()
1.618 raeburn 13878:
1.1075.2.44 raeburn 13879: Build recipient lists for following types of e-mail:
1.766 raeburn 13880: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 13881: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13882: module change checking, student/employee ID conflict checks, as
13883: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13884: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13885:
13886: Inputs:
1.1075.2.44 raeburn 13887: defmail (scalar - email address of default recipient),
13888: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13889: requestsmail, updatesmail, or idconflictsmail).
13890:
1.619 raeburn 13891: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 13892:
13893: origmail (scalar - email address of recipient from loncapa.conf,
13894: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13895:
1.655 raeburn 13896: Returns: comma separated list of addresses to which to send e-mail.
13897:
13898: =back
1.618 raeburn 13899:
13900: =cut
13901:
13902: ############################################################
13903: ############################################################
13904: sub build_recipient_list {
1.619 raeburn 13905: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13906: my @recipients;
13907: my $otheremails;
13908: my %domconfig =
13909: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13910: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13911: if (exists($domconfig{'contacts'}{$mailing})) {
13912: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13913: my @contacts = ('adminemail','supportemail');
13914: foreach my $item (@contacts) {
13915: if ($domconfig{'contacts'}{$mailing}{$item}) {
13916: my $addr = $domconfig{'contacts'}{$item};
13917: if (!grep(/^\Q$addr\E$/,@recipients)) {
13918: push(@recipients,$addr);
13919: }
1.619 raeburn 13920: }
1.766 raeburn 13921: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13922: }
13923: }
1.766 raeburn 13924: } elsif ($origmail ne '') {
13925: push(@recipients,$origmail);
1.618 raeburn 13926: }
1.619 raeburn 13927: } elsif ($origmail ne '') {
13928: push(@recipients,$origmail);
1.618 raeburn 13929: }
1.688 raeburn 13930: if (defined($defmail)) {
13931: if ($defmail ne '') {
13932: push(@recipients,$defmail);
13933: }
1.618 raeburn 13934: }
13935: if ($otheremails) {
1.619 raeburn 13936: my @others;
13937: if ($otheremails =~ /,/) {
13938: @others = split(/,/,$otheremails);
1.618 raeburn 13939: } else {
1.619 raeburn 13940: push(@others,$otheremails);
13941: }
13942: foreach my $addr (@others) {
13943: if (!grep(/^\Q$addr\E$/,@recipients)) {
13944: push(@recipients,$addr);
13945: }
1.618 raeburn 13946: }
13947: }
1.619 raeburn 13948: my $recipientlist = join(',',@recipients);
1.618 raeburn 13949: return $recipientlist;
13950: }
13951:
1.127 matthew 13952: ############################################################
13953: ############################################################
1.154 albertel 13954:
1.655 raeburn 13955: =pod
13956:
13957: =head1 Course Catalog Routines
13958:
13959: =over 4
13960:
13961: =item * &gather_categories()
13962:
13963: Converts category definitions - keys of categories hash stored in
13964: coursecategories in configuration.db on the primary library server in a
13965: domain - to an array. Also generates javascript and idx hash used to
13966: generate Domain Coordinator interface for editing Course Categories.
13967:
13968: Inputs:
1.663 raeburn 13969:
1.655 raeburn 13970: categories (reference to hash of category definitions).
1.663 raeburn 13971:
1.655 raeburn 13972: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13973: categories and subcategories).
1.663 raeburn 13974:
1.655 raeburn 13975: idx (reference to hash of counters used in Domain Coordinator interface for
13976: editing Course Categories).
1.663 raeburn 13977:
1.655 raeburn 13978: jsarray (reference to array of categories used to create Javascript arrays for
13979: Domain Coordinator interface for editing Course Categories).
13980:
13981: Returns: nothing
13982:
13983: Side effects: populates cats, idx and jsarray.
13984:
13985: =cut
13986:
13987: sub gather_categories {
13988: my ($categories,$cats,$idx,$jsarray) = @_;
13989: my %counters;
13990: my $num = 0;
13991: foreach my $item (keys(%{$categories})) {
13992: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13993: if ($container eq '' && $depth == 0) {
13994: $cats->[$depth][$categories->{$item}] = $cat;
13995: } else {
13996: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13997: }
13998: my ($escitem,$tail) = split(/:/,$item,2);
13999: if ($counters{$tail} eq '') {
14000: $counters{$tail} = $num;
14001: $num ++;
14002: }
14003: if (ref($idx) eq 'HASH') {
14004: $idx->{$item} = $counters{$tail};
14005: }
14006: if (ref($jsarray) eq 'ARRAY') {
14007: push(@{$jsarray->[$counters{$tail}]},$item);
14008: }
14009: }
14010: return;
14011: }
14012:
14013: =pod
14014:
14015: =item * &extract_categories()
14016:
14017: Used to generate breadcrumb trails for course categories.
14018:
14019: Inputs:
1.663 raeburn 14020:
1.655 raeburn 14021: categories (reference to hash of category definitions).
1.663 raeburn 14022:
1.655 raeburn 14023: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14024: categories and subcategories).
1.663 raeburn 14025:
1.655 raeburn 14026: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14027:
1.655 raeburn 14028: allitems (reference to hash - key is category key
14029: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14030:
1.655 raeburn 14031: idx (reference to hash of counters used in Domain Coordinator interface for
14032: editing Course Categories).
1.663 raeburn 14033:
1.655 raeburn 14034: jsarray (reference to array of categories used to create Javascript arrays for
14035: Domain Coordinator interface for editing Course Categories).
14036:
1.665 raeburn 14037: subcats (reference to hash of arrays containing all subcategories within each
14038: category, -recursive)
14039:
1.655 raeburn 14040: Returns: nothing
14041:
14042: Side effects: populates trails and allitems hash references.
14043:
14044: =cut
14045:
14046: sub extract_categories {
1.665 raeburn 14047: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 14048: if (ref($categories) eq 'HASH') {
14049: &gather_categories($categories,$cats,$idx,$jsarray);
14050: if (ref($cats->[0]) eq 'ARRAY') {
14051: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14052: my $name = $cats->[0][$i];
14053: my $item = &escape($name).'::0';
14054: my $trailstr;
14055: if ($name eq 'instcode') {
14056: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14057: } elsif ($name eq 'communities') {
14058: $trailstr = &mt('Communities');
1.655 raeburn 14059: } else {
14060: $trailstr = $name;
14061: }
14062: if ($allitems->{$item} eq '') {
14063: push(@{$trails},$trailstr);
14064: $allitems->{$item} = scalar(@{$trails})-1;
14065: }
14066: my @parents = ($name);
14067: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14068: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14069: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14070: if (ref($subcats) eq 'HASH') {
14071: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14072: }
14073: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
14074: }
14075: } else {
14076: if (ref($subcats) eq 'HASH') {
14077: $subcats->{$item} = [];
1.655 raeburn 14078: }
14079: }
14080: }
14081: }
14082: }
14083: return;
14084: }
14085:
14086: =pod
14087:
1.1075.2.56 raeburn 14088: =item * &recurse_categories()
1.655 raeburn 14089:
14090: Recursively used to generate breadcrumb trails for course categories.
14091:
14092: Inputs:
1.663 raeburn 14093:
1.655 raeburn 14094: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14095: categories and subcategories).
1.663 raeburn 14096:
1.655 raeburn 14097: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14098:
14099: category (current course category, for which breadcrumb trail is being generated).
14100:
14101: trails (reference to array of breadcrumb trails for each category).
14102:
1.655 raeburn 14103: allitems (reference to hash - key is category key
14104: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14105:
1.655 raeburn 14106: parents (array containing containers directories for current category,
14107: back to top level).
14108:
14109: Returns: nothing
14110:
14111: Side effects: populates trails and allitems hash references
14112:
14113: =cut
14114:
14115: sub recurse_categories {
1.665 raeburn 14116: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 14117: my $shallower = $depth - 1;
14118: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14119: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14120: my $name = $cats->[$depth]{$category}[$k];
14121: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14122: my $trailstr = join(' -> ',(@{$parents},$category));
14123: if ($allitems->{$item} eq '') {
14124: push(@{$trails},$trailstr);
14125: $allitems->{$item} = scalar(@{$trails})-1;
14126: }
14127: my $deeper = $depth+1;
14128: push(@{$parents},$category);
1.665 raeburn 14129: if (ref($subcats) eq 'HASH') {
14130: my $subcat = &escape($name).':'.$category.':'.$depth;
14131: for (my $j=@{$parents}; $j>=0; $j--) {
14132: my $higher;
14133: if ($j > 0) {
14134: $higher = &escape($parents->[$j]).':'.
14135: &escape($parents->[$j-1]).':'.$j;
14136: } else {
14137: $higher = &escape($parents->[$j]).'::'.$j;
14138: }
14139: push(@{$subcats->{$higher}},$subcat);
14140: }
14141: }
14142: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
14143: $subcats);
1.655 raeburn 14144: pop(@{$parents});
14145: }
14146: } else {
14147: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14148: my $trailstr = join(' -> ',(@{$parents},$category));
14149: if ($allitems->{$item} eq '') {
14150: push(@{$trails},$trailstr);
14151: $allitems->{$item} = scalar(@{$trails})-1;
14152: }
14153: }
14154: return;
14155: }
14156:
1.663 raeburn 14157: =pod
14158:
1.1075.2.56 raeburn 14159: =item * &assign_categories_table()
1.663 raeburn 14160:
14161: Create a datatable for display of hierarchical categories in a domain,
14162: with checkboxes to allow a course to be categorized.
14163:
14164: Inputs:
14165:
14166: cathash - reference to hash of categories defined for the domain (from
14167: configuration.db)
14168:
14169: currcat - scalar with an & separated list of categories assigned to a course.
14170:
1.919 raeburn 14171: type - scalar contains course type (Course or Community).
14172:
1.663 raeburn 14173: Returns: $output (markup to be displayed)
14174:
14175: =cut
14176:
14177: sub assign_categories_table {
1.919 raeburn 14178: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 14179: my $output;
14180: if (ref($cathash) eq 'HASH') {
14181: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
14182: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
14183: $maxdepth = scalar(@cats);
14184: if (@cats > 0) {
14185: my $itemcount = 0;
14186: if (ref($cats[0]) eq 'ARRAY') {
14187: my @currcategories;
14188: if ($currcat ne '') {
14189: @currcategories = split('&',$currcat);
14190: }
1.919 raeburn 14191: my $table;
1.663 raeburn 14192: for (my $i=0; $i<@{$cats[0]}; $i++) {
14193: my $parent = $cats[0][$i];
1.919 raeburn 14194: next if ($parent eq 'instcode');
14195: if ($type eq 'Community') {
14196: next unless ($parent eq 'communities');
14197: } else {
14198: next if ($parent eq 'communities');
14199: }
1.663 raeburn 14200: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14201: my $item = &escape($parent).'::0';
14202: my $checked = '';
14203: if (@currcategories > 0) {
14204: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14205: $checked = ' checked="checked"';
1.663 raeburn 14206: }
14207: }
1.919 raeburn 14208: my $parent_title = $parent;
14209: if ($parent eq 'communities') {
14210: $parent_title = &mt('Communities');
14211: }
14212: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14213: '<input type="checkbox" name="usecategory" value="'.
14214: $item.'"'.$checked.' />'.$parent_title.'</span>'.
14215: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14216: my $depth = 1;
14217: push(@path,$parent);
1.919 raeburn 14218: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 14219: pop(@path);
1.919 raeburn 14220: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14221: $itemcount ++;
14222: }
1.919 raeburn 14223: if ($itemcount) {
14224: $output = &Apache::loncommon::start_data_table().
14225: $table.
14226: &Apache::loncommon::end_data_table();
14227: }
1.663 raeburn 14228: }
14229: }
14230: }
14231: return $output;
14232: }
14233:
14234: =pod
14235:
1.1075.2.56 raeburn 14236: =item * &assign_category_rows()
1.663 raeburn 14237:
14238: Create a datatable row for display of nested categories in a domain,
14239: with checkboxes to allow a course to be categorized,called recursively.
14240:
14241: Inputs:
14242:
14243: itemcount - track row number for alternating colors
14244:
14245: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14246: categories and subcategories.
14247:
14248: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14249:
14250: parent - parent of current category item
14251:
14252: path - Array containing all categories back up through the hierarchy from the
14253: current category to the top level.
14254:
14255: currcategories - reference to array of current categories assigned to the course
14256:
14257: Returns: $output (markup to be displayed).
14258:
14259: =cut
14260:
14261: sub assign_category_rows {
14262: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
14263: my ($text,$name,$item,$chgstr);
14264: if (ref($cats) eq 'ARRAY') {
14265: my $maxdepth = scalar(@{$cats});
14266: if (ref($cats->[$depth]) eq 'HASH') {
14267: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14268: my $numchildren = @{$cats->[$depth]{$parent}};
14269: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 14270: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14271: for (my $j=0; $j<$numchildren; $j++) {
14272: $name = $cats->[$depth]{$parent}[$j];
14273: $item = &escape($name).':'.&escape($parent).':'.$depth;
14274: my $deeper = $depth+1;
14275: my $checked = '';
14276: if (ref($currcategories) eq 'ARRAY') {
14277: if (@{$currcategories} > 0) {
14278: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14279: $checked = ' checked="checked"';
1.663 raeburn 14280: }
14281: }
14282: }
1.664 raeburn 14283: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14284: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 14285: $item.'"'.$checked.' />'.$name.'</label></span>'.
14286: '<input type="hidden" name="catname" value="'.$name.'" />'.
14287: '</td><td>';
1.663 raeburn 14288: if (ref($path) eq 'ARRAY') {
14289: push(@{$path},$name);
14290: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
14291: pop(@{$path});
14292: }
14293: $text .= '</td></tr>';
14294: }
14295: $text .= '</table></td>';
14296: }
14297: }
14298: }
14299: return $text;
14300: }
14301:
1.1075.2.69 raeburn 14302: =pod
14303:
14304: =back
14305:
14306: =cut
14307:
1.655 raeburn 14308: ############################################################
14309: ############################################################
14310:
14311:
1.443 albertel 14312: sub commit_customrole {
1.664 raeburn 14313: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14314: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14315: ($start?', '.&mt('starting').' '.localtime($start):'').
14316: ($end?', ending '.localtime($end):'').': <b>'.
14317: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14318: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14319: '</b><br />';
14320: return $output;
14321: }
14322:
14323: sub commit_standardrole {
1.1075.2.31 raeburn 14324: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14325: my ($output,$logmsg,$linefeed);
14326: if ($context eq 'auto') {
14327: $linefeed = "\n";
14328: } else {
14329: $linefeed = "<br />\n";
14330: }
1.443 albertel 14331: if ($three eq 'st') {
1.541 raeburn 14332: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 14333: $one,$two,$sec,$context,$credits);
1.541 raeburn 14334: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14335: ($result eq 'unknown_course') || ($result eq 'refused')) {
14336: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14337: } else {
1.541 raeburn 14338: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14339: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14340: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14341: if ($context eq 'auto') {
14342: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14343: } else {
14344: $output .= '<b>'.$result.'</b>'.$linefeed.
14345: &mt('Add to classlist').': <b>ok</b>';
14346: }
14347: $output .= $linefeed;
1.443 albertel 14348: }
14349: } else {
14350: $output = &mt('Assigning').' '.$three.' in '.$url.
14351: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14352: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 14353: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 14354: if ($context eq 'auto') {
14355: $output .= $result.$linefeed;
14356: } else {
14357: $output .= '<b>'.$result.'</b>'.$linefeed;
14358: }
1.443 albertel 14359: }
14360: return $output;
14361: }
14362:
14363: sub commit_studentrole {
1.1075.2.31 raeburn 14364: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
14365: $credits) = @_;
1.626 raeburn 14366: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 14367: if ($context eq 'auto') {
14368: $linefeed = "\n";
14369: } else {
14370: $linefeed = '<br />'."\n";
14371: }
1.443 albertel 14372: if (defined($one) && defined($two)) {
14373: my $cid=$one.'_'.$two;
14374: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
14375: my $secchange = 0;
14376: my $expire_role_result;
14377: my $modify_section_result;
1.628 raeburn 14378: if ($oldsec ne '-1') {
14379: if ($oldsec ne $sec) {
1.443 albertel 14380: $secchange = 1;
1.628 raeburn 14381: my $now = time;
1.443 albertel 14382: my $uurl='/'.$cid;
14383: $uurl=~s/\_/\//g;
14384: if ($oldsec) {
14385: $uurl.='/'.$oldsec;
14386: }
1.626 raeburn 14387: $oldsecurl = $uurl;
1.628 raeburn 14388: $expire_role_result =
1.652 raeburn 14389: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 14390: if ($env{'request.course.sec'} ne '') {
14391: if ($expire_role_result eq 'refused') {
14392: my @roles = ('st');
14393: my @statuses = ('previous');
14394: my @roledoms = ($one);
14395: my $withsec = 1;
14396: my %roleshash =
14397: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
14398: \@statuses,\@roles,\@roledoms,$withsec);
14399: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
14400: my ($oldstart,$oldend) =
14401: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
14402: if ($oldend > 0 && $oldend <= $now) {
14403: $expire_role_result = 'ok';
14404: }
14405: }
14406: }
14407: }
1.443 albertel 14408: $result = $expire_role_result;
14409: }
14410: }
14411: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 14412: $modify_section_result =
14413: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
14414: undef,undef,undef,$sec,
14415: $end,$start,'','',$cid,
14416: '',$context,$credits);
1.443 albertel 14417: if ($modify_section_result =~ /^ok/) {
14418: if ($secchange == 1) {
1.628 raeburn 14419: if ($sec eq '') {
14420: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
14421: } else {
14422: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
14423: }
1.443 albertel 14424: } elsif ($oldsec eq '-1') {
1.628 raeburn 14425: if ($sec eq '') {
14426: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
14427: } else {
14428: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14429: }
1.443 albertel 14430: } else {
1.628 raeburn 14431: if ($sec eq '') {
14432: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
14433: } else {
14434: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14435: }
1.443 albertel 14436: }
14437: } else {
1.628 raeburn 14438: if ($secchange) {
14439: $$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;
14440: } else {
14441: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
14442: }
1.443 albertel 14443: }
14444: $result = $modify_section_result;
14445: } elsif ($secchange == 1) {
1.628 raeburn 14446: if ($oldsec eq '') {
1.1075.2.20 raeburn 14447: $$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 14448: } else {
14449: $$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;
14450: }
1.626 raeburn 14451: if ($expire_role_result eq 'refused') {
14452: my $newsecurl = '/'.$cid;
14453: $newsecurl =~ s/\_/\//g;
14454: if ($sec ne '') {
14455: $newsecurl.='/'.$sec;
14456: }
14457: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
14458: if ($sec eq '') {
14459: $$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;
14460: } else {
14461: $$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;
14462: }
14463: }
14464: }
1.443 albertel 14465: }
14466: } else {
1.626 raeburn 14467: $$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 14468: $result = "error: incomplete course id\n";
14469: }
14470: return $result;
14471: }
14472:
1.1075.2.25 raeburn 14473: sub show_role_extent {
14474: my ($scope,$context,$role) = @_;
14475: $scope =~ s{^/}{};
14476: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
14477: push(@courseroles,'co');
14478: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
14479: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
14480: $scope =~ s{/}{_};
14481: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
14482: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
14483: my ($audom,$auname) = split(/\//,$scope);
14484: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
14485: &Apache::loncommon::plainname($auname,$audom).'</span>');
14486: } else {
14487: $scope =~ s{/$}{};
14488: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
14489: &Apache::lonnet::domain($scope,'description').'</span>');
14490: }
14491: }
14492:
1.443 albertel 14493: ############################################################
14494: ############################################################
14495:
1.566 albertel 14496: sub check_clone {
1.578 raeburn 14497: my ($args,$linefeed) = @_;
1.566 albertel 14498: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
14499: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
14500: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
14501: my $clonemsg;
14502: my $can_clone = 0;
1.944 raeburn 14503: my $lctype = lc($args->{'crstype'});
1.908 raeburn 14504: if ($lctype ne 'community') {
14505: $lctype = 'course';
14506: }
1.566 albertel 14507: if ($clonehome eq 'no_host') {
1.944 raeburn 14508: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14509: $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'});
14510: } else {
14511: $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'});
14512: }
1.566 albertel 14513: } else {
14514: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 14515: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14516: if ($clonedesc{'type'} ne 'Community') {
14517: $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'});
14518: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14519: }
14520: }
1.882 raeburn 14521: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
14522: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 14523: $can_clone = 1;
14524: } else {
1.1075.2.95 raeburn 14525: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 14526: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 14527: if ($clonehash{'cloners'} eq '') {
14528: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
14529: if ($domdefs{'canclone'}) {
14530: unless ($domdefs{'canclone'} eq 'none') {
14531: if ($domdefs{'canclone'} eq 'domain') {
14532: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
14533: $can_clone = 1;
14534: }
14535: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14536: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
14537: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
14538: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
14539: $can_clone = 1;
14540: }
14541: }
14542: }
1.908 raeburn 14543: }
1.1075.2.95 raeburn 14544: } else {
14545: my @cloners = split(/,/,$clonehash{'cloners'});
14546: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 14547: $can_clone = 1;
1.1075.2.95 raeburn 14548: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 14549: $can_clone = 1;
1.1075.2.96 raeburn 14550: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
14551: $can_clone = 1;
1.1075.2.95 raeburn 14552: }
14553: unless ($can_clone) {
1.1075.2.96 raeburn 14554: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14555: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 14556: my (%gotdomdefaults,%gotcodedefaults);
14557: foreach my $cloner (@cloners) {
14558: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
14559: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
14560: my (%codedefaults,@code_order);
14561: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
14562: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
14563: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
14564: }
14565: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
14566: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
14567: }
14568: } else {
14569: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
14570: \%codedefaults,
14571: \@code_order);
14572: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
14573: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
14574: }
14575: if (@code_order > 0) {
14576: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
14577: $cloner,$clonehash{'internal.coursecode'},
14578: $args->{'crscode'})) {
14579: $can_clone = 1;
14580: last;
14581: }
14582: }
14583: }
14584: }
14585: }
1.1075.2.96 raeburn 14586: }
14587: }
14588: unless ($can_clone) {
14589: my $ccrole = 'cc';
14590: if ($args->{'crstype'} eq 'Community') {
14591: $ccrole = 'co';
14592: }
14593: my %roleshash =
14594: &Apache::lonnet::get_my_roles($args->{'ccuname'},
14595: $args->{'ccdomain'},
14596: 'userroles',['active'],[$ccrole],
14597: [$args->{'clonedomain'}]);
14598: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
14599: $can_clone = 1;
14600: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
14601: $args->{'ccuname'},$args->{'ccdomain'})) {
14602: $can_clone = 1;
1.1075.2.95 raeburn 14603: }
14604: }
14605: unless ($can_clone) {
14606: if ($args->{'crstype'} eq 'Community') {
14607: $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'});
14608: } else {
14609: $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 14610: }
1.566 albertel 14611: }
1.578 raeburn 14612: }
1.566 albertel 14613: }
14614: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14615: }
14616:
1.444 albertel 14617: sub construct_course {
1.1075.2.59 raeburn 14618: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 14619: my $outcome;
1.541 raeburn 14620: my $linefeed = '<br />'."\n";
14621: if ($context eq 'auto') {
14622: $linefeed = "\n";
14623: }
1.566 albertel 14624:
14625: #
14626: # Are we cloning?
14627: #
14628: my ($can_clone, $clonemsg, $cloneid, $clonehome);
14629: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 14630: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 14631: if ($context ne 'auto') {
1.578 raeburn 14632: if ($clonemsg ne '') {
14633: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
14634: }
1.566 albertel 14635: }
14636: $outcome .= $clonemsg.$linefeed;
14637:
14638: if (!$can_clone) {
14639: return (0,$outcome);
14640: }
14641: }
14642:
1.444 albertel 14643: #
14644: # Open course
14645: #
14646: my $crstype = lc($args->{'crstype'});
14647: my %cenv=();
14648: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
14649: $args->{'cdescr'},
14650: $args->{'curl'},
14651: $args->{'course_home'},
14652: $args->{'nonstandard'},
14653: $args->{'crscode'},
14654: $args->{'ccuname'}.':'.
14655: $args->{'ccdomain'},
1.882 raeburn 14656: $args->{'crstype'},
1.885 raeburn 14657: $cnum,$context,$category);
1.444 albertel 14658:
14659: # Note: The testing routines depend on this being output; see
14660: # Utils::Course. This needs to at least be output as a comment
14661: # if anyone ever decides to not show this, and Utils::Course::new
14662: # will need to be suitably modified.
1.541 raeburn 14663: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 14664: if ($$courseid =~ /^error:/) {
14665: return (0,$outcome);
14666: }
14667:
1.444 albertel 14668: #
14669: # Check if created correctly
14670: #
1.479 albertel 14671: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 14672: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 14673: if ($crsuhome eq 'no_host') {
14674: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
14675: return (0,$outcome);
14676: }
1.541 raeburn 14677: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 14678:
1.444 albertel 14679: #
1.566 albertel 14680: # Do the cloning
14681: #
14682: if ($can_clone && $cloneid) {
14683: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
14684: if ($context ne 'auto') {
14685: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
14686: }
14687: $outcome .= $clonemsg.$linefeed;
14688: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 14689: # Copy all files
1.637 www 14690: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 14691: # Restore URL
1.566 albertel 14692: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 14693: # Restore title
1.566 albertel 14694: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 14695: # Restore creation date, creator and creation context.
14696: $cenv{'internal.created'}=$oldcenv{'internal.created'};
14697: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
14698: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 14699: # Mark as cloned
1.566 albertel 14700: $cenv{'clonedfrom'}=$cloneid;
1.638 www 14701: # Need to clone grading mode
14702: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
14703: $cenv{'grading'}=$newenv{'grading'};
14704: # Do not clone these environment entries
14705: &Apache::lonnet::del('environment',
14706: ['default_enrollment_start_date',
14707: 'default_enrollment_end_date',
14708: 'question.email',
14709: 'policy.email',
14710: 'comment.email',
14711: 'pch.users.denied',
1.725 raeburn 14712: 'plc.users.denied',
14713: 'hidefromcat',
1.1075.2.36 raeburn 14714: 'checkforpriv',
1.1075.2.59 raeburn 14715: 'categories',
14716: 'internal.uniquecode'],
1.638 www 14717: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 14718: if ($args->{'textbook'}) {
14719: $cenv{'internal.textbook'} = $args->{'textbook'};
14720: }
1.444 albertel 14721: }
1.566 albertel 14722:
1.444 albertel 14723: #
14724: # Set environment (will override cloned, if existing)
14725: #
14726: my @sections = ();
14727: my @xlists = ();
14728: if ($args->{'crstype'}) {
14729: $cenv{'type'}=$args->{'crstype'};
14730: }
14731: if ($args->{'crsid'}) {
14732: $cenv{'courseid'}=$args->{'crsid'};
14733: }
14734: if ($args->{'crscode'}) {
14735: $cenv{'internal.coursecode'}=$args->{'crscode'};
14736: }
14737: if ($args->{'crsquota'} ne '') {
14738: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14739: } else {
14740: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14741: }
14742: if ($args->{'ccuname'}) {
14743: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14744: ':'.$args->{'ccdomain'};
14745: } else {
14746: $cenv{'internal.courseowner'} = $args->{'curruser'};
14747: }
1.1075.2.31 raeburn 14748: if ($args->{'defaultcredits'}) {
14749: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14750: }
1.444 albertel 14751: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14752: if ($args->{'crssections'}) {
14753: $cenv{'internal.sectionnums'} = '';
14754: if ($args->{'crssections'} =~ m/,/) {
14755: @sections = split/,/,$args->{'crssections'};
14756: } else {
14757: $sections[0] = $args->{'crssections'};
14758: }
14759: if (@sections > 0) {
14760: foreach my $item (@sections) {
14761: my ($sec,$gp) = split/:/,$item;
14762: my $class = $args->{'crscode'}.$sec;
14763: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14764: $cenv{'internal.sectionnums'} .= $item.',';
14765: unless ($addcheck eq 'ok') {
14766: push @badclasses, $class;
14767: }
14768: }
14769: $cenv{'internal.sectionnums'} =~ s/,$//;
14770: }
14771: }
14772: # do not hide course coordinator from staff listing,
14773: # even if privileged
14774: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 14775: # add course coordinator's domain to domains to check for privileged users
14776: # if different to course domain
14777: if ($$crsudom ne $args->{'ccdomain'}) {
14778: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14779: }
1.444 albertel 14780: # add crosslistings
14781: if ($args->{'crsxlist'}) {
14782: $cenv{'internal.crosslistings'}='';
14783: if ($args->{'crsxlist'} =~ m/,/) {
14784: @xlists = split/,/,$args->{'crsxlist'};
14785: } else {
14786: $xlists[0] = $args->{'crsxlist'};
14787: }
14788: if (@xlists > 0) {
14789: foreach my $item (@xlists) {
14790: my ($xl,$gp) = split/:/,$item;
14791: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14792: $cenv{'internal.crosslistings'} .= $item.',';
14793: unless ($addcheck eq 'ok') {
14794: push @badclasses, $xl;
14795: }
14796: }
14797: $cenv{'internal.crosslistings'} =~ s/,$//;
14798: }
14799: }
14800: if ($args->{'autoadds'}) {
14801: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14802: }
14803: if ($args->{'autodrops'}) {
14804: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14805: }
14806: # check for notification of enrollment changes
14807: my @notified = ();
14808: if ($args->{'notify_owner'}) {
14809: if ($args->{'ccuname'} ne '') {
14810: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14811: }
14812: }
14813: if ($args->{'notify_dc'}) {
14814: if ($uname ne '') {
1.630 raeburn 14815: push(@notified,$uname.':'.$udom);
1.444 albertel 14816: }
14817: }
14818: if (@notified > 0) {
14819: my $notifylist;
14820: if (@notified > 1) {
14821: $notifylist = join(',',@notified);
14822: } else {
14823: $notifylist = $notified[0];
14824: }
14825: $cenv{'internal.notifylist'} = $notifylist;
14826: }
14827: if (@badclasses > 0) {
14828: my %lt=&Apache::lonlocal::texthash(
14829: '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',
14830: 'dnhr' => 'does not have rights to access enrollment in these classes',
14831: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14832: );
1.541 raeburn 14833: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14834: ' ('.$lt{'adby'}.')';
14835: if ($context eq 'auto') {
14836: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14837: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14838: foreach my $item (@badclasses) {
14839: if ($context eq 'auto') {
14840: $outcome .= " - $item\n";
14841: } else {
14842: $outcome .= "<li>$item</li>\n";
14843: }
14844: }
14845: if ($context eq 'auto') {
14846: $outcome .= $linefeed;
14847: } else {
1.566 albertel 14848: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14849: }
14850: }
1.444 albertel 14851: }
14852: if ($args->{'no_end_date'}) {
14853: $args->{'endaccess'} = 0;
14854: }
14855: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14856: $cenv{'internal.autoend'}=$args->{'enrollend'};
14857: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14858: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14859: if ($args->{'showphotos'}) {
14860: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14861: }
14862: $cenv{'internal.authtype'} = $args->{'authtype'};
14863: $cenv{'internal.autharg'} = $args->{'autharg'};
14864: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14865: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14866: 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');
14867: if ($context eq 'auto') {
14868: $outcome .= $krb_msg;
14869: } else {
1.566 albertel 14870: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14871: }
14872: $outcome .= $linefeed;
1.444 albertel 14873: }
14874: }
14875: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14876: if ($args->{'setpolicy'}) {
14877: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14878: }
14879: if ($args->{'setcontent'}) {
14880: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14881: }
1.1075.2.110 raeburn 14882: if ($args->{'setcomment'}) {
14883: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14884: }
1.444 albertel 14885: }
14886: if ($args->{'reshome'}) {
14887: $cenv{'reshome'}=$args->{'reshome'}.'/';
14888: $cenv{'reshome'}=~s/\/+$/\//;
14889: }
14890: #
14891: # course has keyed access
14892: #
14893: if ($args->{'setkeys'}) {
14894: $cenv{'keyaccess'}='yes';
14895: }
14896: # if specified, key authority is not course, but user
14897: # only active if keyaccess is yes
14898: if ($args->{'keyauth'}) {
1.487 albertel 14899: my ($user,$domain) = split(':',$args->{'keyauth'});
14900: $user = &LONCAPA::clean_username($user);
14901: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14902: if ($user ne '' && $domain ne '') {
1.487 albertel 14903: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14904: }
14905: }
14906:
1.1075.2.59 raeburn 14907: #
14908: # generate and store uniquecode (available to course requester), if course should have one.
14909: #
14910: if ($args->{'uniquecode'}) {
14911: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
14912: if ($code) {
14913: $cenv{'internal.uniquecode'} = $code;
14914: my %crsinfo =
14915: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
14916: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
14917: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
14918: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
14919: }
14920: if (ref($coderef)) {
14921: $$coderef = $code;
14922: }
14923: }
14924: }
14925:
1.444 albertel 14926: if ($args->{'disresdis'}) {
14927: $cenv{'pch.roles.denied'}='st';
14928: }
14929: if ($args->{'disablechat'}) {
14930: $cenv{'plc.roles.denied'}='st';
14931: }
14932:
14933: # Record we've not yet viewed the Course Initialization Helper for this
14934: # course
14935: $cenv{'course.helper.not.run'} = 1;
14936: #
14937: # Use new Randomseed
14938: #
14939: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14940: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14941: #
14942: # The encryption code and receipt prefix for this course
14943: #
14944: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14945: $cenv{'internal.encpref'}=100+int(9*rand(99));
14946: #
14947: # By default, use standard grading
14948: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14949:
1.541 raeburn 14950: $outcome .= $linefeed.&mt('Setting environment').': '.
14951: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14952: #
14953: # Open all assignments
14954: #
14955: if ($args->{'openall'}) {
14956: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14957: my %storecontent = ($storeunder => time,
14958: $storeunder.'.type' => 'date_start');
14959:
14960: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14961: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14962: }
14963: #
14964: # Set first page
14965: #
14966: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14967: || ($cloneid)) {
1.445 albertel 14968: use LONCAPA::map;
1.444 albertel 14969: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14970:
14971: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14972: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14973:
1.444 albertel 14974: $outcome .= ($fatal?$errtext:'read ok').' - ';
14975: my $title; my $url;
14976: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14977: $title=&mt('Syllabus');
1.444 albertel 14978: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14979: } else {
1.963 raeburn 14980: $title=&mt('Table of Contents');
1.444 albertel 14981: $url='/adm/navmaps';
14982: }
1.445 albertel 14983:
14984: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14985: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14986:
14987: if ($errtext) { $fatal=2; }
1.541 raeburn 14988: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14989: }
1.566 albertel 14990:
14991: return (1,$outcome);
1.444 albertel 14992: }
14993:
1.1075.2.59 raeburn 14994: sub make_unique_code {
14995: my ($cdom,$cnum) = @_;
14996: # get lock on uniquecodes db
14997: my $lockhash = {
14998: $cnum."\0".'uniquecodes' => $env{'user.name'}.
14999: ':'.$env{'user.domain'},
15000: };
15001: my $tries = 0;
15002: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15003: my ($code,$error);
15004:
15005: while (($gotlock ne 'ok') && ($tries<3)) {
15006: $tries ++;
15007: sleep 1;
15008: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15009: }
15010: if ($gotlock eq 'ok') {
15011: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15012: my $gotcode;
15013: my $attempts = 0;
15014: while ((!$gotcode) && ($attempts < 100)) {
15015: $code = &generate_code();
15016: if (!exists($currcodes{$code})) {
15017: $gotcode = 1;
15018: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15019: $error = 'nostore';
15020: }
15021: }
15022: $attempts ++;
15023: }
15024: my @del_lock = ($cnum."\0".'uniquecodes');
15025: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15026: } else {
15027: $error = 'nolock';
15028: }
15029: return ($code,$error);
15030: }
15031:
15032: sub generate_code {
15033: my $code;
15034: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15035: for (my $i=0; $i<6; $i++) {
15036: my $lettnum = int (rand 2);
15037: my $item = '';
15038: if ($lettnum) {
15039: $item = $letts[int( rand(18) )];
15040: } else {
15041: $item = 1+int( rand(8) );
15042: }
15043: $code .= $item;
15044: }
15045: return $code;
15046: }
15047:
1.444 albertel 15048: ############################################################
15049: ############################################################
15050:
1.953 droeschl 15051: #SD
15052: # only Community and Course, or anything else?
1.378 raeburn 15053: sub course_type {
15054: my ($cid) = @_;
15055: if (!defined($cid)) {
15056: $cid = $env{'request.course.id'};
15057: }
1.404 albertel 15058: if (defined($env{'course.'.$cid.'.type'})) {
15059: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15060: } else {
15061: return 'Course';
1.377 raeburn 15062: }
15063: }
1.156 albertel 15064:
1.406 raeburn 15065: sub group_term {
15066: my $crstype = &course_type();
15067: my %names = (
15068: 'Course' => 'group',
1.865 raeburn 15069: 'Community' => 'group',
1.406 raeburn 15070: );
15071: return $names{$crstype};
15072: }
15073:
1.902 raeburn 15074: sub course_types {
1.1075.2.59 raeburn 15075: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15076: my %typename = (
15077: official => 'Official course',
15078: unofficial => 'Unofficial course',
15079: community => 'Community',
1.1075.2.59 raeburn 15080: textbook => 'Textbook course',
1.902 raeburn 15081: );
15082: return (\@types,\%typename);
15083: }
15084:
1.156 albertel 15085: sub icon {
15086: my ($file)=@_;
1.505 albertel 15087: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15088: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15089: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15090: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15091: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15092: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15093: $curfext.".gif") {
15094: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15095: $curfext.".gif";
15096: }
15097: }
1.249 albertel 15098: return &lonhttpdurl($iconname);
1.154 albertel 15099: }
1.84 albertel 15100:
1.575 albertel 15101: sub lonhttpdurl {
1.692 www 15102: #
15103: # Had been used for "small fry" static images on separate port 8080.
15104: # Modify here if lightweight http functionality desired again.
15105: # Currently eliminated due to increasing firewall issues.
15106: #
1.575 albertel 15107: my ($url)=@_;
1.692 www 15108: return $url;
1.215 albertel 15109: }
15110:
1.213 albertel 15111: sub connection_aborted {
15112: my ($r)=@_;
15113: $r->print(" ");$r->rflush();
15114: my $c = $r->connection;
15115: return $c->aborted();
15116: }
15117:
1.221 foxr 15118: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15119: # strings as 'strings'.
15120: sub escape_single {
1.221 foxr 15121: my ($input) = @_;
1.223 albertel 15122: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15123: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15124: return $input;
15125: }
1.223 albertel 15126:
1.222 foxr 15127: # Same as escape_single, but escape's "'s This
15128: # can be used for "strings"
15129: sub escape_double {
15130: my ($input) = @_;
15131: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15132: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15133: return $input;
15134: }
1.223 albertel 15135:
1.222 foxr 15136: # Escapes the last element of a full URL.
15137: sub escape_url {
15138: my ($url) = @_;
1.238 raeburn 15139: my @urlslices = split(/\//, $url,-1);
1.369 www 15140: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 15141: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15142: }
1.462 albertel 15143:
1.820 raeburn 15144: sub compare_arrays {
15145: my ($arrayref1,$arrayref2) = @_;
15146: my (@difference,%count);
15147: @difference = ();
15148: %count = ();
15149: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15150: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15151: foreach my $element (keys(%count)) {
15152: if ($count{$element} == 1) {
15153: push(@difference,$element);
15154: }
15155: }
15156: }
15157: return @difference;
15158: }
15159:
1.817 bisitz 15160: # -------------------------------------------------------- Initialize user login
1.462 albertel 15161: sub init_user_environment {
1.463 albertel 15162: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15163: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15164:
15165: my $public=($username eq 'public' && $domain eq 'public');
15166:
15167: # See if old ID present, if so, remove
15168:
1.1062 raeburn 15169: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15170: my $now=time;
15171:
15172: if ($public) {
15173: my $max_public=100;
15174: my $oldest;
15175: my $oldest_time=0;
15176: for(my $next=1;$next<=$max_public;$next++) {
15177: if (-e $lonids."/publicuser_$next.id") {
15178: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15179: if ($mtime<$oldest_time || !$oldest_time) {
15180: $oldest_time=$mtime;
15181: $oldest=$next;
15182: }
15183: } else {
15184: $cookie="publicuser_$next";
15185: last;
15186: }
15187: }
15188: if (!$cookie) { $cookie="publicuser_$oldest"; }
15189: } else {
1.463 albertel 15190: # if this isn't a robot, kill any existing non-robot sessions
15191: if (!$args->{'robot'}) {
15192: opendir(DIR,$lonids);
15193: while ($filename=readdir(DIR)) {
15194: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
15195: unlink($lonids.'/'.$filename);
15196: }
1.462 albertel 15197: }
1.463 albertel 15198: closedir(DIR);
1.1075.2.84 raeburn 15199: # If there is a undeleted lockfile for the user's paste buffer remove it.
15200: my $namespace = 'nohist_courseeditor';
15201: my $lockingkey = 'paste'."\0".'locked_num';
15202: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15203: $domain,$username);
15204: if (exists($lockhash{$lockingkey})) {
15205: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15206: unless ($delresult eq 'ok') {
15207: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15208: }
15209: }
1.462 albertel 15210: }
15211: # Give them a new cookie
1.463 albertel 15212: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15213: : $now.$$.int(rand(10000)));
1.463 albertel 15214: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15215:
15216: # Initialize roles
15217:
1.1062 raeburn 15218: ($userroles,$firstaccenv,$timerintenv) =
15219: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15220: }
15221: # ------------------------------------ Check browser type and MathML capability
15222:
1.1075.2.77 raeburn 15223: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15224: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15225:
15226: # ------------------------------------------------------------- Get environment
15227:
15228: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15229: my ($tmp) = keys(%userenv);
15230: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15231: } else {
15232: undef(%userenv);
15233: }
15234: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15235: $form->{'interface'}=$userenv{'interface'};
15236: }
15237: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15238:
15239: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15240: foreach my $option ('interface','localpath','localres') {
15241: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15242: }
15243: # --------------------------------------------------------- Write first profile
15244:
15245: {
15246: my %initial_env =
15247: ("user.name" => $username,
15248: "user.domain" => $domain,
15249: "user.home" => $authhost,
15250: "browser.type" => $clientbrowser,
15251: "browser.version" => $clientversion,
15252: "browser.mathml" => $clientmathml,
15253: "browser.unicode" => $clientunicode,
15254: "browser.os" => $clientos,
1.1075.2.42 raeburn 15255: "browser.mobile" => $clientmobile,
15256: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 15257: "browser.osversion" => $clientosversion,
1.462 albertel 15258: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15259: "request.course.fn" => '',
15260: "request.course.uri" => '',
15261: "request.course.sec" => '',
15262: "request.role" => 'cm',
15263: "request.role.adv" => $env{'user.adv'},
15264: "request.host" => $ENV{'REMOTE_ADDR'},);
15265:
15266: if ($form->{'localpath'}) {
15267: $initial_env{"browser.localpath"} = $form->{'localpath'};
15268: $initial_env{"browser.localres"} = $form->{'localres'};
15269: }
15270:
15271: if ($form->{'interface'}) {
15272: $form->{'interface'}=~s/\W//gs;
15273: $initial_env{"browser.interface"} = $form->{'interface'};
15274: $env{'browser.interface'}=$form->{'interface'};
15275: }
15276:
1.1075.2.54 raeburn 15277: if ($form->{'iptoken'}) {
15278: my $lonhost = $r->dir_config('lonHostID');
15279: $initial_env{"user.noloadbalance"} = $lonhost;
15280: $env{'user.noloadbalance'} = $lonhost;
15281: }
15282:
1.981 raeburn 15283: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 15284: my %domdef;
15285: unless ($domain eq 'public') {
15286: %domdef = &Apache::lonnet::get_domain_defaults($domain);
15287: }
1.980 raeburn 15288:
1.1075.2.7 raeburn 15289: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 15290: $userenv{'availabletools.'.$tool} =
1.980 raeburn 15291: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15292: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 15293: }
15294:
1.1075.2.59 raeburn 15295: foreach my $crstype ('official','unofficial','community','textbook') {
1.765 raeburn 15296: $userenv{'canrequest.'.$crstype} =
15297: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 15298: 'reload','requestcourses',
15299: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 15300: }
15301:
1.1075.2.14 raeburn 15302: $userenv{'canrequest.author'} =
15303: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15304: 'reload','requestauthor',
15305: \%userenv,\%domdef,\%is_adv);
15306: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15307: $domain,$username);
15308: my $reqstatus = $reqauthor{'author_status'};
15309: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15310: if (ref($reqauthor{'author'}) eq 'HASH') {
15311: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15312: $reqauthor{'author'}{'timestamp'};
15313: }
15314: }
15315:
1.462 albertel 15316: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15317:
1.462 albertel 15318: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
15319: &GDBM_WRCREAT(),0640)) {
15320: &_add_to_env(\%disk_env,\%initial_env);
15321: &_add_to_env(\%disk_env,\%userenv,'environment.');
15322: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 15323: if (ref($firstaccenv) eq 'HASH') {
15324: &_add_to_env(\%disk_env,$firstaccenv);
15325: }
15326: if (ref($timerintenv) eq 'HASH') {
15327: &_add_to_env(\%disk_env,$timerintenv);
15328: }
1.463 albertel 15329: if (ref($args->{'extra_env'})) {
15330: &_add_to_env(\%disk_env,$args->{'extra_env'});
15331: }
1.462 albertel 15332: untie(%disk_env);
15333: } else {
1.705 tempelho 15334: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
15335: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 15336: return 'error: '.$!;
15337: }
15338: }
15339: $env{'request.role'}='cm';
15340: $env{'request.role.adv'}=$env{'user.adv'};
15341: $env{'browser.type'}=$clientbrowser;
15342:
15343: return $cookie;
15344:
15345: }
15346:
15347: sub _add_to_env {
15348: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 15349: if (ref($env_data) eq 'HASH') {
15350: while (my ($key,$value) = each(%$env_data)) {
15351: $idf->{$prefix.$key} = $value;
15352: $env{$prefix.$key} = $value;
15353: }
1.462 albertel 15354: }
15355: }
15356:
1.685 tempelho 15357: # --- Get the symbolic name of a problem and the url
15358: sub get_symb {
15359: my ($request,$silent) = @_;
1.726 raeburn 15360: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 15361: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
15362: if ($symb eq '') {
15363: if (!$silent) {
1.1071 raeburn 15364: if (ref($request)) {
15365: $request->print("Unable to handle ambiguous references:$url:.");
15366: }
1.685 tempelho 15367: return ();
15368: }
15369: }
15370: &Apache::lonenc::check_decrypt(\$symb);
15371: return ($symb);
15372: }
15373:
15374: # --------------------------------------------------------------Get annotation
15375:
15376: sub get_annotation {
15377: my ($symb,$enc) = @_;
15378:
15379: my $key = $symb;
15380: if (!$enc) {
15381: $key =
15382: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
15383: }
15384: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
15385: return $annotation{$key};
15386: }
15387:
15388: sub clean_symb {
1.731 raeburn 15389: my ($symb,$delete_enc) = @_;
1.685 tempelho 15390:
15391: &Apache::lonenc::check_decrypt(\$symb);
15392: my $enc = $env{'request.enc'};
1.731 raeburn 15393: if ($delete_enc) {
1.730 raeburn 15394: delete($env{'request.enc'});
15395: }
1.685 tempelho 15396:
15397: return ($symb,$enc);
15398: }
1.462 albertel 15399:
1.1075.2.69 raeburn 15400: ############################################################
15401: ############################################################
15402:
15403: =pod
15404:
15405: =head1 Routines for building display used to search for courses
15406:
15407:
15408: =over 4
15409:
15410: =item * &build_filters()
15411:
15412: Create markup for a table used to set filters to use when selecting
15413: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
15414: and quotacheck.pl
15415:
15416:
15417: Inputs:
15418:
15419: filterlist - anonymous array of fields to include as potential filters
15420:
15421: crstype - course type
15422:
15423: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
15424: to pop-open a course selector (will contain "extra element").
15425:
15426: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
15427:
15428: filter - anonymous hash of criteria and their values
15429:
15430: action - form action
15431:
15432: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
15433:
15434: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
15435:
15436: cloneruname - username of owner of new course who wants to clone
15437:
15438: clonerudom - domain of owner of new course who wants to clone
15439:
15440: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
15441:
15442: codetitlesref - reference to array of titles of components in institutional codes (official courses)
15443:
15444: codedom - domain
15445:
15446: formname - value of form element named "form".
15447:
15448: fixeddom - domain, if fixed.
15449:
15450: prevphase - value to assign to form element named "phase" when going back to the previous screen
15451:
15452: cnameelement - name of form element in form on opener page which will receive title of selected course
15453:
15454: cnumelement - name of form element in form on opener page which will receive courseID of selected course
15455:
15456: cdomelement - name of form element in form on opener page which will receive domain of selected course
15457:
15458: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
15459:
15460: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
15461:
15462: clonewarning - warning message about missing information for intended course owner when DC creates a course
15463:
15464:
15465: Returns: $output - HTML for display of search criteria, and hidden form elements.
15466:
15467:
15468: Side Effects: None
15469:
15470: =cut
15471:
15472: # ---------------------------------------------- search for courses based on last activity etc.
15473:
15474: sub build_filters {
15475: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
15476: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
15477: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
15478: $cnameelement,$cnumelement,$cdomelement,$setroles,
15479: $clonetext,$clonewarning) = @_;
15480: my ($list,$jscript);
15481: my $onchange = 'javascript:updateFilters(this)';
15482: my ($domainselectform,$sincefilterform,$createdfilterform,
15483: $ownerdomselectform,$persondomselectform,$instcodeform,
15484: $typeselectform,$instcodetitle);
15485: if ($formname eq '') {
15486: $formname = $caller;
15487: }
15488: foreach my $item (@{$filterlist}) {
15489: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
15490: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
15491: if ($item eq 'domainfilter') {
15492: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
15493: } elsif ($item eq 'coursefilter') {
15494: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
15495: } elsif ($item eq 'ownerfilter') {
15496: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15497: } elsif ($item eq 'ownerdomfilter') {
15498: $filter->{'ownerdomfilter'} =
15499: &LONCAPA::clean_domain($filter->{$item});
15500: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
15501: 'ownerdomfilter',1);
15502: } elsif ($item eq 'personfilter') {
15503: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15504: } elsif ($item eq 'persondomfilter') {
15505: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
15506: 'persondomfilter',1);
15507: } else {
15508: $filter->{$item} =~ s/\W//g;
15509: }
15510: if (!$filter->{$item}) {
15511: $filter->{$item} = '';
15512: }
15513: }
15514: if ($item eq 'domainfilter') {
15515: my $allow_blank = 1;
15516: if ($formname eq 'portform') {
15517: $allow_blank=0;
15518: } elsif ($formname eq 'studentform') {
15519: $allow_blank=0;
15520: }
15521: if ($fixeddom) {
15522: $domainselectform = '<input type="hidden" name="domainfilter"'.
15523: ' value="'.$codedom.'" />'.
15524: &Apache::lonnet::domain($codedom,'description');
15525: } else {
15526: $domainselectform = &select_dom_form($filter->{$item},
15527: 'domainfilter',
15528: $allow_blank,'',$onchange);
15529: }
15530: } else {
15531: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
15532: }
15533: }
15534:
15535: # last course activity filter and selection
15536: $sincefilterform = &timebased_select_form('sincefilter',$filter);
15537:
15538: # course created filter and selection
15539: if (exists($filter->{'createdfilter'})) {
15540: $createdfilterform = &timebased_select_form('createdfilter',$filter);
15541: }
15542:
15543: my %lt = &Apache::lonlocal::texthash(
15544: 'cac' => "$crstype Activity",
15545: 'ccr' => "$crstype Created",
15546: 'cde' => "$crstype Title",
15547: 'cdo' => "$crstype Domain",
15548: 'ins' => 'Institutional Code',
15549: 'inc' => 'Institutional Categorization',
15550: 'cow' => "$crstype Owner/Co-owner",
15551: 'cop' => "$crstype Personnel Includes",
15552: 'cog' => 'Type',
15553: );
15554:
15555: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15556: my $typeval = 'Course';
15557: if ($crstype eq 'Community') {
15558: $typeval = 'Community';
15559: }
15560: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
15561: } else {
15562: $typeselectform = '<select name="type" size="1"';
15563: if ($onchange) {
15564: $typeselectform .= ' onchange="'.$onchange.'"';
15565: }
15566: $typeselectform .= '>'."\n";
15567: foreach my $posstype ('Course','Community') {
15568: $typeselectform.='<option value="'.$posstype.'"'.
15569: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
15570: }
15571: $typeselectform.="</select>";
15572: }
15573:
15574: my ($cloneableonlyform,$cloneabletitle);
15575: if (exists($filter->{'cloneableonly'})) {
15576: my $cloneableon = '';
15577: my $cloneableoff = ' checked="checked"';
15578: if ($filter->{'cloneableonly'}) {
15579: $cloneableon = $cloneableoff;
15580: $cloneableoff = '';
15581: }
15582: $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>';
15583: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 15584: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 15585: } else {
15586: $cloneabletitle = &mt('Cloneable by you');
15587: }
15588: }
15589: my $officialjs;
15590: if ($crstype eq 'Course') {
15591: if (exists($filter->{'instcodefilter'})) {
15592: # if (($fixeddom) || ($formname eq 'requestcrs') ||
15593: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
15594: if ($codedom) {
15595: $officialjs = 1;
15596: ($instcodeform,$jscript,$$numtitlesref) =
15597: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
15598: $officialjs,$codetitlesref);
15599: if ($jscript) {
15600: $jscript = '<script type="text/javascript">'."\n".
15601: '// <![CDATA['."\n".
15602: $jscript."\n".
15603: '// ]]>'."\n".
15604: '</script>'."\n";
15605: }
15606: }
15607: if ($instcodeform eq '') {
15608: $instcodeform =
15609: '<input type="text" name="instcodefilter" size="10" value="'.
15610: $list->{'instcodefilter'}.'" />';
15611: $instcodetitle = $lt{'ins'};
15612: } else {
15613: $instcodetitle = $lt{'inc'};
15614: }
15615: if ($fixeddom) {
15616: $instcodetitle .= '<br />('.$codedom.')';
15617: }
15618: }
15619: }
15620: my $output = qq|
15621: <form method="post" name="filterpicker" action="$action">
15622: <input type="hidden" name="form" value="$formname" />
15623: |;
15624: if ($formname eq 'modifycourse') {
15625: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
15626: '<input type="hidden" name="prevphase" value="'.
15627: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 15628: } elsif ($formname eq 'quotacheck') {
15629: $output .= qq|
15630: <input type="hidden" name="sortby" value="" />
15631: <input type="hidden" name="sortorder" value="" />
15632: |;
15633: } else {
1.1075.2.69 raeburn 15634: my $name_input;
15635: if ($cnameelement ne '') {
15636: $name_input = '<input type="hidden" name="cnameelement" value="'.
15637: $cnameelement.'" />';
15638: }
15639: $output .= qq|
15640: <input type="hidden" name="cnumelement" value="$cnumelement" />
15641: <input type="hidden" name="cdomelement" value="$cdomelement" />
15642: $name_input
15643: $roleelement
15644: $multelement
15645: $typeelement
15646: |;
15647: if ($formname eq 'portform') {
15648: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
15649: }
15650: }
15651: if ($fixeddom) {
15652: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
15653: }
15654: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
15655: if ($sincefilterform) {
15656: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
15657: .$sincefilterform
15658: .&Apache::lonhtmlcommon::row_closure();
15659: }
15660: if ($createdfilterform) {
15661: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
15662: .$createdfilterform
15663: .&Apache::lonhtmlcommon::row_closure();
15664: }
15665: if ($domainselectform) {
15666: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
15667: .$domainselectform
15668: .&Apache::lonhtmlcommon::row_closure();
15669: }
15670: if ($typeselectform) {
15671: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15672: $output .= $typeselectform;
15673: } else {
15674: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
15675: .$typeselectform
15676: .&Apache::lonhtmlcommon::row_closure();
15677: }
15678: }
15679: if ($instcodeform) {
15680: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
15681: .$instcodeform
15682: .&Apache::lonhtmlcommon::row_closure();
15683: }
15684: if (exists($filter->{'ownerfilter'})) {
15685: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
15686: '<table><tr><td>'.&mt('Username').'<br />'.
15687: '<input type="text" name="ownerfilter" size="20" value="'.
15688: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15689: $ownerdomselectform.'</td></tr></table>'.
15690: &Apache::lonhtmlcommon::row_closure();
15691: }
15692: if (exists($filter->{'personfilter'})) {
15693: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
15694: '<table><tr><td>'.&mt('Username').'<br />'.
15695: '<input type="text" name="personfilter" size="20" value="'.
15696: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15697: $persondomselectform.'</td></tr></table>'.
15698: &Apache::lonhtmlcommon::row_closure();
15699: }
15700: if (exists($filter->{'coursefilter'})) {
15701: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
15702: .'<input type="text" name="coursefilter" size="25" value="'
15703: .$list->{'coursefilter'}.'" />'
15704: .&Apache::lonhtmlcommon::row_closure();
15705: }
15706: if ($cloneableonlyform) {
15707: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
15708: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
15709: }
15710: if (exists($filter->{'descriptfilter'})) {
15711: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
15712: .'<input type="text" name="descriptfilter" size="40" value="'
15713: .$list->{'descriptfilter'}.'" />'
15714: .&Apache::lonhtmlcommon::row_closure(1);
15715: }
15716: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
15717: '<input type="hidden" name="updater" value="" />'."\n".
15718: '<input type="submit" name="gosearch" value="'.
15719: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
15720: return $jscript.$clonewarning.$output;
15721: }
15722:
15723: =pod
15724:
15725: =item * &timebased_select_form()
15726:
15727: Create markup for a dropdown list used to select a time-based
15728: filter e.g., Course Activity, Course Created, when searching for courses
15729: or communities
15730:
15731: Inputs:
15732:
15733: item - name of form element (sincefilter or createdfilter)
15734:
15735: filter - anonymous hash of criteria and their values
15736:
15737: Returns: HTML for a select box contained a blank, then six time selections,
15738: with value set in incoming form variables currently selected.
15739:
15740: Side Effects: None
15741:
15742: =cut
15743:
15744: sub timebased_select_form {
15745: my ($item,$filter) = @_;
15746: if (ref($filter) eq 'HASH') {
15747: $filter->{$item} =~ s/[^\d-]//g;
15748: if (!$filter->{$item}) { $filter->{$item}=-1; }
15749: return &select_form(
15750: $filter->{$item},
15751: $item,
15752: { '-1' => '',
15753: '86400' => &mt('today'),
15754: '604800' => &mt('last week'),
15755: '2592000' => &mt('last month'),
15756: '7776000' => &mt('last three months'),
15757: '15552000' => &mt('last six months'),
15758: '31104000' => &mt('last year'),
15759: 'select_form_order' =>
15760: ['-1','86400','604800','2592000','7776000',
15761: '15552000','31104000']});
15762: }
15763: }
15764:
15765: =pod
15766:
15767: =item * &js_changer()
15768:
15769: Create script tag containing Javascript used to submit course search form
15770: when course type or domain is changed, and also to hide 'Searching ...' on
15771: page load completion for page showing search result.
15772:
15773: Inputs: None
15774:
15775: Returns: markup containing updateFilters() and hideSearching() javascript functions.
15776:
15777: Side Effects: None
15778:
15779: =cut
15780:
15781: sub js_changer {
15782: return <<ENDJS;
15783: <script type="text/javascript">
15784: // <![CDATA[
15785: function updateFilters(caller) {
15786: if (typeof(caller) != "undefined") {
15787: document.filterpicker.updater.value = caller.name;
15788: }
15789: document.filterpicker.submit();
15790: }
15791:
15792: function hideSearching() {
15793: if (document.getElementById('searching')) {
15794: document.getElementById('searching').style.display = 'none';
15795: }
15796: return;
15797: }
15798:
15799: // ]]>
15800: </script>
15801:
15802: ENDJS
15803: }
15804:
15805: =pod
15806:
15807: =item * &search_courses()
15808:
15809: Process selected filters form course search form and pass to lonnet::courseiddump
15810: to retrieve a hash for which keys are courseIDs which match the selected filters.
15811:
15812: Inputs:
15813:
15814: dom - domain being searched
15815:
15816: type - course type ('Course' or 'Community' or '.' if any).
15817:
15818: filter - anonymous hash of criteria and their values
15819:
15820: numtitles - for institutional codes - number of categories
15821:
15822: cloneruname - optional username of new course owner
15823:
15824: clonerudom - optional domain of new course owner
15825:
1.1075.2.95 raeburn 15826: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 15827: (used when DC is using course creation form)
15828:
15829: codetitles - reference to array of titles of components in institutional codes (official courses).
15830:
1.1075.2.95 raeburn 15831: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
15832: (and so can clone automatically)
15833:
15834: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
15835:
15836: reqinstcode - institutional code of new course, where search_courses is used to identify potential
15837: courses to clone
1.1075.2.69 raeburn 15838:
15839: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
15840:
15841:
15842: Side Effects: None
15843:
15844: =cut
15845:
15846:
15847: sub search_courses {
1.1075.2.95 raeburn 15848: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
15849: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 15850: my (%courses,%showcourses,$cloner);
15851: if (($filter->{'ownerfilter'} ne '') ||
15852: ($filter->{'ownerdomfilter'} ne '')) {
15853: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
15854: $filter->{'ownerdomfilter'};
15855: }
15856: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
15857: if (!$filter->{$item}) {
15858: $filter->{$item}='.';
15859: }
15860: }
15861: my $now = time;
15862: my $timefilter =
15863: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
15864: my ($createdbefore,$createdafter);
15865: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
15866: $createdbefore = $now;
15867: $createdafter = $now-$filter->{'createdfilter'};
15868: }
15869: my ($instcodefilter,$regexpok);
15870: if ($numtitles) {
15871: if ($env{'form.official'} eq 'on') {
15872: $instcodefilter =
15873: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15874: $regexpok = 1;
15875: } elsif ($env{'form.official'} eq 'off') {
15876: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15877: unless ($instcodefilter eq '') {
15878: $regexpok = -1;
15879: }
15880: }
15881: } else {
15882: $instcodefilter = $filter->{'instcodefilter'};
15883: }
15884: if ($instcodefilter eq '') { $instcodefilter = '.'; }
15885: if ($type eq '') { $type = '.'; }
15886:
15887: if (($clonerudom ne '') && ($cloneruname ne '')) {
15888: $cloner = $cloneruname.':'.$clonerudom;
15889: }
15890: %courses = &Apache::lonnet::courseiddump($dom,
15891: $filter->{'descriptfilter'},
15892: $timefilter,
15893: $instcodefilter,
15894: $filter->{'combownerfilter'},
15895: $filter->{'coursefilter'},
15896: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 15897: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 15898: $filter->{'cloneableonly'},
15899: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 15900: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 15901: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
15902: my $ccrole;
15903: if ($type eq 'Community') {
15904: $ccrole = 'co';
15905: } else {
15906: $ccrole = 'cc';
15907: }
15908: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
15909: $filter->{'persondomfilter'},
15910: 'userroles',undef,
15911: [$ccrole,'in','ad','ep','ta','cr'],
15912: $dom);
15913: foreach my $role (keys(%rolehash)) {
15914: my ($cnum,$cdom,$courserole) = split(':',$role);
15915: my $cid = $cdom.'_'.$cnum;
15916: if (exists($courses{$cid})) {
15917: if (ref($courses{$cid}) eq 'HASH') {
15918: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
15919: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
15920: push (@{$courses{$cid}{roles}},$courserole);
15921: }
15922: } else {
15923: $courses{$cid}{roles} = [$courserole];
15924: }
15925: $showcourses{$cid} = $courses{$cid};
15926: }
15927: }
15928: }
15929: %courses = %showcourses;
15930: }
15931: return %courses;
15932: }
15933:
15934: =pod
15935:
15936: =back
15937:
1.1075.2.88 raeburn 15938: =head1 Routines for version requirements for current course.
15939:
15940: =over 4
15941:
15942: =item * &check_release_required()
15943:
15944: Compares required LON-CAPA version with version on server, and
15945: if required version is newer looks for a server with the required version.
15946:
15947: Looks first at servers in user's owen domain; if none suitable, looks at
15948: servers in course's domain are permitted to host sessions for user's domain.
15949:
15950: Inputs:
15951:
15952: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
15953:
15954: $courseid - Course ID of current course
15955:
15956: $rolecode - User's current role in course (for switchserver query string).
15957:
15958: $required - LON-CAPA version needed by course (format: Major.Minor).
15959:
15960:
15961: Returns:
15962:
15963: $switchserver - query string tp append to /adm/switchserver call (if
15964: current server's LON-CAPA version is too old.
15965:
15966: $warning - Message is displayed if no suitable server could be found.
15967:
15968: =cut
15969:
15970: sub check_release_required {
15971: my ($loncaparev,$courseid,$rolecode,$required) = @_;
15972: my ($switchserver,$warning);
15973: if ($required ne '') {
15974: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
15975: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
15976: if ($reqdmajor ne '' && $reqdminor ne '') {
15977: my $otherserver;
15978: if (($major eq '' && $minor eq '') ||
15979: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
15980: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
15981: my $switchlcrev =
15982: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
15983: $userdomserver);
15984: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
15985: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
15986: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
15987: my $cdom = $env{'course.'.$courseid.'.domain'};
15988: if ($cdom ne $env{'user.domain'}) {
15989: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
15990: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
15991: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
15992: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
15993: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
15994: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
15995: my $canhost =
15996: &Apache::lonnet::can_host_session($env{'user.domain'},
15997: $coursedomserver,
15998: $remoterev,
15999: $udomdefaults{'remotesessions'},
16000: $defdomdefaults{'hostedsessions'});
16001:
16002: if ($canhost) {
16003: $otherserver = $coursedomserver;
16004: } else {
16005: $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.");
16006: }
16007: } else {
16008: $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).");
16009: }
16010: } else {
16011: $otherserver = $userdomserver;
16012: }
16013: }
16014: if ($otherserver ne '') {
16015: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16016: }
16017: }
16018: }
16019: return ($switchserver,$warning);
16020: }
16021:
16022: =pod
16023:
16024: =item * &check_release_result()
16025:
16026: Inputs:
16027:
16028: $switchwarning - Warning message if no suitable server found to host session.
16029:
16030: $switchserver - query string to append to /adm/switchserver containing lonHostID
16031: and current role.
16032:
16033: Returns: HTML to display with information about requirement to switch server.
16034: Either displaying warning with link to Roles/Courses screen or
16035: display link to switchserver.
16036:
1.1075.2.69 raeburn 16037: =cut
16038:
1.1075.2.88 raeburn 16039: sub check_release_result {
16040: my ($switchwarning,$switchserver) = @_;
16041: my $output = &start_page('Selected course unavailable on this server').
16042: '<p class="LC_warning">';
16043: if ($switchwarning) {
16044: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16045: if (&show_course()) {
16046: $output .= &mt('Display courses');
16047: } else {
16048: $output .= &mt('Display roles');
16049: }
16050: $output .= '</a>';
16051: } elsif ($switchserver) {
16052: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16053: '<br />'.
16054: '<a href="/adm/switchserver?'.$switchserver.'">'.
16055: &mt('Switch Server').
16056: '</a>';
16057: }
16058: $output .= '</p>'.&end_page();
16059: return $output;
16060: }
16061:
16062: =pod
16063:
16064: =item * &needs_coursereinit()
16065:
16066: Determine if course contents stored for user's session needs to be
16067: refreshed, because content has changed since "Big Hash" last tied.
16068:
16069: Check for change is made if time last checked is more than 10 minutes ago
16070: (by default).
16071:
16072: Inputs:
16073:
16074: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16075:
16076: $interval (optional) - Time which may elapse (in s) between last check for content
16077: change in current course. (default: 600 s).
16078:
16079: Returns: an array; first element is:
16080:
16081: =over 4
16082:
16083: 'switch' - if content updates mean user's session
16084: needs to be switched to a server running a newer LON-CAPA version
16085:
16086: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16087: on current server hosting user's session
16088:
16089: '' - if no action required.
16090:
16091: =back
16092:
16093: If first item element is 'switch':
16094:
16095: second item is $switchwarning - Warning message if no suitable server found to host session.
16096:
16097: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16098: and current role.
16099:
16100: otherwise: no other elements returned.
16101:
16102: =back
16103:
16104: =cut
16105:
16106: sub needs_coursereinit {
16107: my ($loncaparev,$interval) = @_;
16108: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16109: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16110: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16111: my $now = time;
16112: if ($interval eq '') {
16113: $interval = 600;
16114: }
16115: if (($now-$env{'request.course.timechecked'})>$interval) {
16116: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16117: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16118: if ($lastchange > $env{'request.course.tied'}) {
16119: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16120: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16121: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16122: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16123: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16124: $curr_reqd_hash{'internal.releaserequired'}});
16125: my ($switchserver,$switchwarning) =
16126: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16127: $curr_reqd_hash{'internal.releaserequired'});
16128: if ($switchwarning ne '' || $switchserver ne '') {
16129: return ('switch',$switchwarning,$switchserver);
16130: }
16131: }
16132: }
16133: return ('update');
16134: }
16135: }
16136: return ();
16137: }
1.1075.2.69 raeburn 16138:
1.1075.2.11 raeburn 16139: sub update_content_constraints {
16140: my ($cdom,$cnum,$chome,$cid) = @_;
16141: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16142: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16143: my %checkresponsetypes;
16144: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
16145: my ($item,$name,$value) = split(/:/,$key);
16146: if ($item eq 'resourcetag') {
16147: if ($name eq 'responsetype') {
16148: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16149: }
16150: }
16151: }
16152: my $navmap = Apache::lonnavmaps::navmap->new();
16153: if (defined($navmap)) {
16154: my %allresponses;
16155: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16156: my %responses = $res->responseTypes();
16157: foreach my $key (keys(%responses)) {
16158: next unless(exists($checkresponsetypes{$key}));
16159: $allresponses{$key} += $responses{$key};
16160: }
16161: }
16162: foreach my $key (keys(%allresponses)) {
16163: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16164: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16165: ($reqdmajor,$reqdminor) = ($major,$minor);
16166: }
16167: }
16168: undef($navmap);
16169: }
16170: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16171: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16172: }
16173: return;
16174: }
16175:
1.1075.2.27 raeburn 16176: sub allmaps_incourse {
16177: my ($cdom,$cnum,$chome,$cid) = @_;
16178: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16179: $cid = $env{'request.course.id'};
16180: $cdom = $env{'course.'.$cid.'.domain'};
16181: $cnum = $env{'course.'.$cid.'.num'};
16182: $chome = $env{'course.'.$cid.'.home'};
16183: }
16184: my %allmaps = ();
16185: my $lastchange =
16186: &Apache::lonnet::get_coursechange($cdom,$cnum);
16187: if ($lastchange > $env{'request.course.tied'}) {
16188: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16189: unless ($ferr) {
16190: &update_content_constraints($cdom,$cnum,$chome,$cid);
16191: }
16192: }
16193: my $navmap = Apache::lonnavmaps::navmap->new();
16194: if (defined($navmap)) {
16195: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16196: $allmaps{$res->src()} = 1;
16197: }
16198: }
16199: return \%allmaps;
16200: }
16201:
1.1075.2.11 raeburn 16202: sub parse_supplemental_title {
16203: my ($title) = @_;
16204:
16205: my ($foldertitle,$renametitle);
16206: if ($title =~ /&&&/) {
16207: $title = &HTML::Entites::decode($title);
16208: }
16209: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16210: $renametitle=$4;
16211: my ($time,$uname,$udom) = ($1,$2,$3);
16212: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16213: my $name = &plainname($uname,$udom);
16214: $name = &HTML::Entities::encode($name,'"<>&\'');
16215: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16216: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16217: $name.': <br />'.$foldertitle;
16218: }
16219: if (wantarray) {
16220: return ($title,$foldertitle,$renametitle);
16221: }
16222: return $title;
16223: }
16224:
1.1075.2.43 raeburn 16225: sub recurse_supplemental {
16226: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16227: if ($suppmap) {
16228: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16229: if ($fatal) {
16230: $errors ++;
16231: } else {
16232: if ($#LONCAPA::map::resources > 0) {
16233: foreach my $res (@LONCAPA::map::resources) {
16234: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16235: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 16236: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16237: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 16238: } else {
16239: $numfiles ++;
16240: }
16241: }
16242: }
16243: }
16244: }
16245: }
16246: return ($numfiles,$errors);
16247: }
16248:
1.1075.2.18 raeburn 16249: sub symb_to_docspath {
16250: my ($symb) = @_;
16251: return unless ($symb);
16252: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16253: if ($resurl=~/\.(sequence|page)$/) {
16254: $mapurl=$resurl;
16255: } elsif ($resurl eq 'adm/navmaps') {
16256: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
16257: }
16258: my $mapresobj;
16259: my $navmap = Apache::lonnavmaps::navmap->new();
16260: if (ref($navmap)) {
16261: $mapresobj = $navmap->getResourceByUrl($mapurl);
16262: }
16263: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
16264: my $type=$2;
16265: my $path;
16266: if (ref($mapresobj)) {
16267: my $pcslist = $mapresobj->map_hierarchy();
16268: if ($pcslist ne '') {
16269: foreach my $pc (split(/,/,$pcslist)) {
16270: next if ($pc <= 1);
16271: my $res = $navmap->getByMapPc($pc);
16272: if (ref($res)) {
16273: my $thisurl = $res->src();
16274: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
16275: my $thistitle = $res->title();
16276: $path .= '&'.
16277: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 16278: &escape($thistitle).
1.1075.2.18 raeburn 16279: ':'.$res->randompick().
16280: ':'.$res->randomout().
16281: ':'.$res->encrypted().
16282: ':'.$res->randomorder().
16283: ':'.$res->is_page();
16284: }
16285: }
16286: }
16287: $path =~ s/^\&//;
16288: my $maptitle = $mapresobj->title();
16289: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16290: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16291: }
16292: $path .= (($path ne '')? '&' : '').
16293: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16294: &escape($maptitle).
1.1075.2.18 raeburn 16295: ':'.$mapresobj->randompick().
16296: ':'.$mapresobj->randomout().
16297: ':'.$mapresobj->encrypted().
16298: ':'.$mapresobj->randomorder().
16299: ':'.$mapresobj->is_page();
16300: } else {
16301: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16302: my $ispage = (($type eq 'page')? 1 : '');
16303: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16304: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16305: }
16306: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16307: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 16308: }
16309: unless ($mapurl eq 'default') {
16310: $path = 'default&'.
1.1075.2.46 raeburn 16311: &escape('Main Content').
1.1075.2.18 raeburn 16312: ':::::&'.$path;
16313: }
16314: return $path;
16315: }
16316:
1.1075.2.14 raeburn 16317: sub captcha_display {
16318: my ($context,$lonhost) = @_;
16319: my ($output,$error);
1.1075.2.107 raeburn 16320: my ($captcha,$pubkey,$privkey,$version) =
16321: &get_captcha_config($context,$lonhost);
1.1075.2.14 raeburn 16322: if ($captcha eq 'original') {
16323: $output = &create_captcha();
16324: unless ($output) {
16325: $error = 'captcha';
16326: }
16327: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16328: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 16329: unless ($output) {
16330: $error = 'recaptcha';
16331: }
16332: }
1.1075.2.107 raeburn 16333: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 16334: }
16335:
16336: sub captcha_response {
16337: my ($context,$lonhost) = @_;
16338: my ($captcha_chk,$captcha_error);
1.1075.2.109 raeburn 16339: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1075.2.14 raeburn 16340: if ($captcha eq 'original') {
16341: ($captcha_chk,$captcha_error) = &check_captcha();
16342: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16343: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 16344: } else {
16345: $captcha_chk = 1;
16346: }
16347: return ($captcha_chk,$captcha_error);
16348: }
16349:
16350: sub get_captcha_config {
16351: my ($context,$lonhost) = @_;
1.1075.2.107 raeburn 16352: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 16353: my $hostname = &Apache::lonnet::hostname($lonhost);
16354: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
16355: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16356: if ($context eq 'usercreation') {
16357: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
16358: if (ref($domconfig{$context}) eq 'HASH') {
16359: $hashtocheck = $domconfig{$context}{'cancreate'};
16360: if (ref($hashtocheck) eq 'HASH') {
16361: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
16362: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
16363: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
16364: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
16365: }
16366: if ($privkey && $pubkey) {
16367: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16368: $version = $hashtocheck->{'recaptchaversion'};
16369: if ($version ne '2') {
16370: $version = 1;
16371: }
1.1075.2.14 raeburn 16372: } else {
16373: $captcha = 'original';
16374: }
16375: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
16376: $captcha = 'original';
16377: }
16378: }
16379: } else {
16380: $captcha = 'captcha';
16381: }
16382: } elsif ($context eq 'login') {
16383: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
16384: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
16385: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
16386: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
16387: if ($privkey && $pubkey) {
16388: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16389: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
16390: if ($version ne '2') {
16391: $version = 1;
16392: }
1.1075.2.14 raeburn 16393: } else {
16394: $captcha = 'original';
16395: }
16396: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
16397: $captcha = 'original';
16398: }
16399: }
1.1075.2.107 raeburn 16400: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 16401: }
16402:
16403: sub create_captcha {
16404: my %captcha_params = &captcha_settings();
16405: my ($output,$maxtries,$tries) = ('',10,0);
16406: while ($tries < $maxtries) {
16407: $tries ++;
16408: my $captcha = Authen::Captcha->new (
16409: output_folder => $captcha_params{'output_dir'},
16410: data_folder => $captcha_params{'db_dir'},
16411: );
16412: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
16413:
16414: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
16415: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
16416: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 16417: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
16418: '<br />'.
16419: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 16420: last;
16421: }
16422: }
16423: return $output;
16424: }
16425:
16426: sub captcha_settings {
16427: my %captcha_params = (
16428: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
16429: www_output_dir => "/captchaspool",
16430: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
16431: numchars => '5',
16432: );
16433: return %captcha_params;
16434: }
16435:
16436: sub check_captcha {
16437: my ($captcha_chk,$captcha_error);
16438: my $code = $env{'form.code'};
16439: my $md5sum = $env{'form.crypt'};
16440: my %captcha_params = &captcha_settings();
16441: my $captcha = Authen::Captcha->new(
16442: output_folder => $captcha_params{'output_dir'},
16443: data_folder => $captcha_params{'db_dir'},
16444: );
1.1075.2.26 raeburn 16445: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 16446: my %captcha_hash = (
16447: 0 => 'Code not checked (file error)',
16448: -1 => 'Failed: code expired',
16449: -2 => 'Failed: invalid code (not in database)',
16450: -3 => 'Failed: invalid code (code does not match crypt)',
16451: );
16452: if ($captcha_chk != 1) {
16453: $captcha_error = $captcha_hash{$captcha_chk}
16454: }
16455: return ($captcha_chk,$captcha_error);
16456: }
16457:
16458: sub create_recaptcha {
1.1075.2.107 raeburn 16459: my ($pubkey,$version) = @_;
16460: if ($version >= 2) {
16461: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
16462: } else {
16463: my $use_ssl;
16464: if ($ENV{'SERVER_PORT'} == 443) {
16465: $use_ssl = 1;
16466: }
16467: my $captcha = Captcha::reCAPTCHA->new;
16468: return $captcha->get_options_setter({theme => 'white'})."\n".
16469: $captcha->get_html($pubkey,undef,$use_ssl).
16470: &mt('If the text is hard to read, [_1] will replace them.',
16471: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
16472: '<br /><br />';
16473: }
1.1075.2.14 raeburn 16474: }
16475:
16476: sub check_recaptcha {
1.1075.2.107 raeburn 16477: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 16478: my $captcha_chk;
1.1075.2.107 raeburn 16479: if ($version >= 2) {
16480: my $ua = LWP::UserAgent->new;
16481: $ua->timeout(10);
16482: my %info = (
16483: secret => $privkey,
16484: response => $env{'form.g-recaptcha-response'},
16485: remoteip => $ENV{'REMOTE_ADDR'},
16486: );
16487: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
16488: if ($response->is_success) {
16489: my $data = JSON::DWIW->from_json($response->decoded_content);
16490: if (ref($data) eq 'HASH') {
16491: if ($data->{'success'}) {
16492: $captcha_chk = 1;
16493: }
16494: }
16495: }
16496: } else {
16497: my $captcha = Captcha::reCAPTCHA->new;
16498: my $captcha_result =
16499: $captcha->check_answer(
16500: $privkey,
16501: $ENV{'REMOTE_ADDR'},
16502: $env{'form.recaptcha_challenge_field'},
16503: $env{'form.recaptcha_response_field'},
16504: );
16505: if ($captcha_result->{is_valid}) {
16506: $captcha_chk = 1;
16507: }
1.1075.2.14 raeburn 16508: }
16509: return $captcha_chk;
16510: }
16511:
1.1075.2.64 raeburn 16512: sub emailusername_info {
1.1075.2.103 raeburn 16513: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 16514: my %titles = &Apache::lonlocal::texthash (
16515: lastname => 'Last Name',
16516: firstname => 'First Name',
16517: institution => 'School/college/university',
16518: location => "School's city, state/province, country",
16519: web => "School's web address",
16520: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 16521: id => 'Student/Employee ID',
1.1075.2.64 raeburn 16522: );
16523: return (\@fields,\%titles);
16524: }
16525:
1.1075.2.56 raeburn 16526: sub cleanup_html {
16527: my ($incoming) = @_;
16528: my $outgoing;
16529: if ($incoming ne '') {
16530: $outgoing = $incoming;
16531: $outgoing =~ s/;/;/g;
16532: $outgoing =~ s/\#/#/g;
16533: $outgoing =~ s/\&/&/g;
16534: $outgoing =~ s/</</g;
16535: $outgoing =~ s/>/>/g;
16536: $outgoing =~ s/\(/(/g;
16537: $outgoing =~ s/\)/)/g;
16538: $outgoing =~ s/"/"/g;
16539: $outgoing =~ s/'/'/g;
16540: $outgoing =~ s/\$/$/g;
16541: $outgoing =~ s{/}{/}g;
16542: $outgoing =~ s/=/=/g;
16543: $outgoing =~ s/\\/\/g
16544: }
16545: return $outgoing;
16546: }
16547:
1.1075.2.74 raeburn 16548: # Checks for critical messages and returns a redirect url if one exists.
16549: # $interval indicates how often to check for messages.
16550: sub critical_redirect {
16551: my ($interval) = @_;
16552: if ((time-$env{'user.criticalcheck.time'})>$interval) {
16553: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
16554: $env{'user.name'});
16555: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
16556: my $redirecturl;
16557: if ($what[0]) {
16558: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
16559: $redirecturl='/adm/email?critical=display';
16560: my $url=&Apache::lonnet::absolute_url().$redirecturl;
16561: return (1, $url);
16562: }
16563: }
16564: }
16565: return ();
16566: }
16567:
1.1075.2.64 raeburn 16568: # Use:
16569: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
16570: #
16571: ##################################################
16572: # password associated functions #
16573: ##################################################
16574: sub des_keys {
16575: # Make a new key for DES encryption.
16576: # Each key has two parts which are returned separately.
16577: # Please note: Each key must be passed through the &hex function
16578: # before it is output to the web browser. The hex versions cannot
16579: # be used to decrypt.
16580: my @hexstr=('0','1','2','3','4','5','6','7',
16581: '8','9','a','b','c','d','e','f');
16582: my $lkey='';
16583: for (0..7) {
16584: $lkey.=$hexstr[rand(15)];
16585: }
16586: my $ukey='';
16587: for (0..7) {
16588: $ukey.=$hexstr[rand(15)];
16589: }
16590: return ($lkey,$ukey);
16591: }
16592:
16593: sub des_decrypt {
16594: my ($key,$cyphertext) = @_;
16595: my $keybin=pack("H16",$key);
16596: my $cypher;
16597: if ($Crypt::DES::VERSION>=2.03) {
16598: $cypher=new Crypt::DES $keybin;
16599: } else {
16600: $cypher=new DES $keybin;
16601: }
1.1075.2.106 raeburn 16602: my $plaintext='';
16603: my $cypherlength = length($cyphertext);
16604: my $numchunks = int($cypherlength/32);
16605: for (my $j=0; $j<$numchunks; $j++) {
16606: my $start = $j*32;
16607: my $cypherblock = substr($cyphertext,$start,32);
16608: my $chunk =
16609: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
16610: $chunk .=
16611: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
16612: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
16613: $plaintext .= $chunk;
16614: }
1.1075.2.64 raeburn 16615: return $plaintext;
16616: }
16617:
1.112 bowersj2 16618: 1;
16619: __END__;
1.41 ng 16620:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>