Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.127
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.127! raeburn 4: # $Id: loncommon.pm,v 1.1075.2.126 2017/03/26 23:47:28 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.1075.2.119 raeburn 265: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 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.1075.2.115 raeburn 939: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
940: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 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 {
1.1075.2.115 raeburn 961: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
962: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 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 {
1.1075.2.115 raeburn 1014: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 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.1075.2.115 raeburn 1026: return &select_form($selected,$name,\%langchoices,undef,$noedit);
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) {
1.1075.2.119 raeburn 1141: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 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.1075.2.115 raeburn 2242: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
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
1.1075.2.115 raeburn 2247: a javascript onchange item, e.g., onchange="this.form.submit();".
2248: An optional arg -- $readonly -- if true will cause the select form
2249: to be disabled, e.g., for the case where an instructor has a section-
2250: specific role, and is viewing/modifying parameters.
1.970 raeburn 2251:
1.88 www 2252: See lonrights.pm for an example invocation and use.
2253:
2254: =cut
2255:
2256: #-------------------------------------------
2257: sub select_form {
1.1075.2.115 raeburn 2258: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2259: return unless (ref($hashref) eq 'HASH');
2260: if ($onchange) {
2261: $onchange = ' onchange="'.$onchange.'"';
2262: }
2263: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2264: my @keys;
1.970 raeburn 2265: if (exists($hashref->{'select_form_order'})) {
2266: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2267: } else {
1.970 raeburn 2268: @keys=sort(keys(%{$hashref}));
1.128 albertel 2269: }
1.356 albertel 2270: foreach my $key (@keys) {
2271: $selectform.=
2272: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2273: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2274: ">".$hashref->{$key}."</option>\n";
1.88 www 2275: }
2276: $selectform.="</select>";
2277: return $selectform;
2278: }
2279:
1.475 www 2280: # For display filters
2281:
2282: sub display_filter {
1.1074 raeburn 2283: my ($context) = @_;
1.475 www 2284: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2285: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2286: my $phraseinput = 'hidden';
2287: my $includeinput = 'hidden';
2288: my ($checked,$includetypestext);
2289: if ($env{'form.displayfilter'} eq 'containing') {
2290: $phraseinput = 'text';
2291: if ($context eq 'parmslog') {
2292: $includeinput = 'checkbox';
2293: if ($env{'form.includetypes'}) {
2294: $checked = ' checked="checked"';
2295: }
2296: $includetypestext = &mt('Include parameter types');
2297: }
2298: } else {
2299: $includetypestext = ' ';
2300: }
2301: my ($additional,$secondid,$thirdid);
2302: if ($context eq 'parmslog') {
2303: $additional =
2304: '<label><input type="'.$includeinput.'" name="includetypes"'.
2305: $checked.' name="includetypes" value="1" id="includetypes" />'.
2306: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2307: '</label>';
2308: $secondid = 'includetypes';
2309: $thirdid = 'includetypestext';
2310: }
2311: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2312: '$secondid','$thirdid')";
2313: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2314: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2315: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2316: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2317: &mt('Filter: [_1]',
1.477 www 2318: &select_form($env{'form.displayfilter'},
2319: 'displayfilter',
1.970 raeburn 2320: {'currentfolder' => 'Current folder/page',
1.477 www 2321: 'containing' => 'Containing phrase',
1.1074 raeburn 2322: 'none' => 'None'},$onchange)).' '.
2323: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2324: &HTML::Entities::encode($env{'form.containingphrase'}).
2325: '" />'.$additional;
2326: }
2327:
2328: sub display_filter_js {
2329: my $includetext = &mt('Include parameter types');
2330: return <<"ENDJS";
2331:
2332: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2333: var firstType = 'hidden';
2334: if (setter.options[setter.selectedIndex].value == 'containing') {
2335: firstType = 'text';
2336: }
2337: firstObject = document.getElementById(firstid);
2338: if (typeof(firstObject) == 'object') {
2339: if (firstObject.type != firstType) {
2340: changeInputType(firstObject,firstType);
2341: }
2342: }
2343: if (context == 'parmslog') {
2344: var secondType = 'hidden';
2345: if (firstType == 'text') {
2346: secondType = 'checkbox';
2347: }
2348: secondObject = document.getElementById(secondid);
2349: if (typeof(secondObject) == 'object') {
2350: if (secondObject.type != secondType) {
2351: changeInputType(secondObject,secondType);
2352: }
2353: }
2354: var textItem = document.getElementById(thirdid);
2355: var currtext = textItem.innerHTML;
2356: var newtext;
2357: if (firstType == 'text') {
2358: newtext = '$includetext';
2359: } else {
2360: newtext = ' ';
2361: }
2362: if (currtext != newtext) {
2363: textItem.innerHTML = newtext;
2364: }
2365: }
2366: return;
2367: }
2368:
2369: function changeInputType(oldObject,newType) {
2370: var newObject = document.createElement('input');
2371: newObject.type = newType;
2372: if (oldObject.size) {
2373: newObject.size = oldObject.size;
2374: }
2375: if (oldObject.value) {
2376: newObject.value = oldObject.value;
2377: }
2378: if (oldObject.name) {
2379: newObject.name = oldObject.name;
2380: }
2381: if (oldObject.id) {
2382: newObject.id = oldObject.id;
2383: }
2384: oldObject.parentNode.replaceChild(newObject,oldObject);
2385: return;
2386: }
2387:
2388: ENDJS
1.475 www 2389: }
2390:
1.167 www 2391: sub gradeleveldescription {
2392: my $gradelevel=shift;
2393: my %gradelevels=(0 => 'Not specified',
2394: 1 => 'Grade 1',
2395: 2 => 'Grade 2',
2396: 3 => 'Grade 3',
2397: 4 => 'Grade 4',
2398: 5 => 'Grade 5',
2399: 6 => 'Grade 6',
2400: 7 => 'Grade 7',
2401: 8 => 'Grade 8',
2402: 9 => 'Grade 9',
2403: 10 => 'Grade 10',
2404: 11 => 'Grade 11',
2405: 12 => 'Grade 12',
2406: 13 => 'Grade 13',
2407: 14 => '100 Level',
2408: 15 => '200 Level',
2409: 16 => '300 Level',
2410: 17 => '400 Level',
2411: 18 => 'Graduate Level');
2412: return &mt($gradelevels{$gradelevel});
2413: }
2414:
1.163 www 2415: sub select_level_form {
2416: my ($deflevel,$name)=@_;
2417: unless ($deflevel) { $deflevel=0; }
1.167 www 2418: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2419: for (my $i=0; $i<=18; $i++) {
2420: $selectform.="<option value=\"$i\" ".
1.253 albertel 2421: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2422: ">".&gradeleveldescription($i)."</option>\n";
2423: }
2424: $selectform.="</select>";
2425: return $selectform;
1.163 www 2426: }
1.167 www 2427:
1.35 matthew 2428: #-------------------------------------------
2429:
1.45 matthew 2430: =pod
2431:
1.1075.2.115 raeburn 2432: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2433:
2434: Returns a string containing a <select name='$name' size='1'> form to
2435: allow a user to select the domain to preform an operation in.
2436: See loncreateuser.pm for an example invocation and use.
2437:
1.90 www 2438: If the $includeempty flag is set, it also includes an empty choice ("no domain
2439: selected");
2440:
1.743 raeburn 2441: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2442:
1.910 raeburn 2443: 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.
2444:
1.1075.2.36 raeburn 2445: The optional $incdoms is a reference to an array of domains which will be the only available options.
2446:
1.1075.2.115 raeburn 2447: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
2448:
2449: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
1.563 raeburn 2450:
1.35 matthew 2451: =cut
2452:
2453: #-------------------------------------------
1.34 matthew 2454: sub select_dom_form {
1.1075.2.115 raeburn 2455: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2456: if ($onchange) {
1.874 raeburn 2457: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2458: }
1.1075.2.115 raeburn 2459: if ($disabled) {
2460: $disabled = ' disabled="disabled"';
2461: }
1.1075.2.36 raeburn 2462: my (@domains,%exclude);
1.910 raeburn 2463: if (ref($incdoms) eq 'ARRAY') {
2464: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2465: } else {
2466: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2467: }
1.90 www 2468: if ($includeempty) { @domains=('',@domains); }
1.1075.2.36 raeburn 2469: if (ref($excdoms) eq 'ARRAY') {
2470: map { $exclude{$_} = 1; } @{$excdoms};
2471: }
1.1075.2.115 raeburn 2472: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2473: foreach my $dom (@domains) {
1.1075.2.36 raeburn 2474: next if ($exclude{$dom});
1.356 albertel 2475: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2476: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2477: if ($showdomdesc) {
2478: if ($dom ne '') {
2479: my $domdesc = &Apache::lonnet::domain($dom,'description');
2480: if ($domdesc ne '') {
2481: $selectdomain .= ' ('.$domdesc.')';
2482: }
2483: }
2484: }
2485: $selectdomain .= "</option>\n";
1.34 matthew 2486: }
2487: $selectdomain.="</select>";
2488: return $selectdomain;
2489: }
2490:
1.35 matthew 2491: #-------------------------------------------
2492:
1.45 matthew 2493: =pod
2494:
1.648 raeburn 2495: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2496:
1.586 raeburn 2497: input: 4 arguments (two required, two optional) -
2498: $domain - domain of new user
2499: $name - name of form element
2500: $default - Value of 'default' causes a default item to be first
2501: option, and selected by default.
2502: $hide - Value of 'hide' causes hiding of the name of the server,
2503: if 1 server found, or default, if 0 found.
1.594 raeburn 2504: output: returns 2 items:
1.586 raeburn 2505: (a) form element which contains either:
2506: (i) <select name="$name">
2507: <option value="$hostid1">$hostid $servers{$hostid}</option>
2508: <option value="$hostid2">$hostid $servers{$hostid}</option>
2509: </select>
2510: form item if there are multiple library servers in $domain, or
2511: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2512: if there is only one library server in $domain.
2513:
2514: (b) number of library servers found.
2515:
2516: See loncreateuser.pm for example of use.
1.35 matthew 2517:
2518: =cut
2519:
2520: #-------------------------------------------
1.586 raeburn 2521: sub home_server_form_item {
2522: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2523: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2524: my $result;
2525: my $numlib = keys(%servers);
2526: if ($numlib > 1) {
2527: $result .= '<select name="'.$name.'" />'."\n";
2528: if ($default) {
1.804 bisitz 2529: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2530: '</option>'."\n";
2531: }
2532: foreach my $hostid (sort(keys(%servers))) {
2533: $result.= '<option value="'.$hostid.'">'.
2534: $hostid.' '.$servers{$hostid}."</option>\n";
2535: }
2536: $result .= '</select>'."\n";
2537: } elsif ($numlib == 1) {
2538: my $hostid;
2539: foreach my $item (keys(%servers)) {
2540: $hostid = $item;
2541: }
2542: $result .= '<input type="hidden" name="'.$name.'" value="'.
2543: $hostid.'" />';
2544: if (!$hide) {
2545: $result .= $hostid.' '.$servers{$hostid};
2546: }
2547: $result .= "\n";
2548: } elsif ($default) {
2549: $result .= '<input type="hidden" name="'.$name.
2550: '" value="default" />';
2551: if (!$hide) {
2552: $result .= &mt('default');
2553: }
2554: $result .= "\n";
1.33 matthew 2555: }
1.586 raeburn 2556: return ($result,$numlib);
1.33 matthew 2557: }
1.112 bowersj2 2558:
2559: =pod
2560:
1.534 albertel 2561: =back
2562:
1.112 bowersj2 2563: =cut
1.87 matthew 2564:
2565: ###############################################################
1.112 bowersj2 2566: ## Decoding User Agent ##
1.87 matthew 2567: ###############################################################
2568:
2569: =pod
2570:
1.112 bowersj2 2571: =head1 Decoding the User Agent
2572:
2573: =over 4
2574:
2575: =item * &decode_user_agent()
1.87 matthew 2576:
2577: Inputs: $r
2578:
2579: Outputs:
2580:
2581: =over 4
2582:
1.112 bowersj2 2583: =item * $httpbrowser
1.87 matthew 2584:
1.112 bowersj2 2585: =item * $clientbrowser
1.87 matthew 2586:
1.112 bowersj2 2587: =item * $clientversion
1.87 matthew 2588:
1.112 bowersj2 2589: =item * $clientmathml
1.87 matthew 2590:
1.112 bowersj2 2591: =item * $clientunicode
1.87 matthew 2592:
1.112 bowersj2 2593: =item * $clientos
1.87 matthew 2594:
1.1075.2.42 raeburn 2595: =item * $clientmobile
2596:
2597: =item * $clientinfo
2598:
1.1075.2.77 raeburn 2599: =item * $clientosversion
2600:
1.87 matthew 2601: =back
2602:
1.157 matthew 2603: =back
2604:
1.87 matthew 2605: =cut
2606:
2607: ###############################################################
2608: ###############################################################
2609: sub decode_user_agent {
1.247 albertel 2610: my ($r)=@_;
1.87 matthew 2611: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2612: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2613: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2614: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2615: my $clientbrowser='unknown';
2616: my $clientversion='0';
2617: my $clientmathml='';
2618: my $clientunicode='0';
1.1075.2.42 raeburn 2619: my $clientmobile=0;
1.1075.2.77 raeburn 2620: my $clientosversion='';
1.87 matthew 2621: for (my $i=0;$i<=$#browsertype;$i++) {
1.1075.2.76 raeburn 2622: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2623: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2624: $clientbrowser=$bname;
2625: $httpbrowser=~/$vreg/i;
2626: $clientversion=$1;
2627: $clientmathml=($clientversion>=$minv);
2628: $clientunicode=($clientversion>=$univ);
2629: }
2630: }
2631: my $clientos='unknown';
1.1075.2.42 raeburn 2632: my $clientinfo;
1.87 matthew 2633: if (($httpbrowser=~/linux/i) ||
2634: ($httpbrowser=~/unix/i) ||
2635: ($httpbrowser=~/ux/i) ||
2636: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2637: if (($httpbrowser=~/vax/i) ||
2638: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2639: if ($httpbrowser=~/next/i) { $clientos='next'; }
2640: if (($httpbrowser=~/mac/i) ||
2641: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1075.2.77 raeburn 2642: if ($httpbrowser=~/win/i) {
2643: $clientos='win';
2644: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2645: $clientosversion = $1;
2646: }
2647: }
1.87 matthew 2648: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1075.2.42 raeburn 2649: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2650: $clientmobile=lc($1);
2651: }
2652: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2653: $clientinfo = 'firefox-'.$1;
2654: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2655: $clientinfo = 'chromeframe-'.$1;
2656: }
1.87 matthew 2657: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1075.2.77 raeburn 2658: $clientunicode,$clientos,$clientmobile,$clientinfo,
2659: $clientosversion);
1.87 matthew 2660: }
2661:
1.32 matthew 2662: ###############################################################
2663: ## Authentication changing form generation subroutines ##
2664: ###############################################################
2665: ##
2666: ## All of the authform_xxxxxxx subroutines take their inputs in a
2667: ## hash, and have reasonable default values.
2668: ##
2669: ## formname = the name given in the <form> tag.
1.35 matthew 2670: #-------------------------------------------
2671:
1.45 matthew 2672: =pod
2673:
1.112 bowersj2 2674: =head1 Authentication Routines
2675:
2676: =over 4
2677:
1.648 raeburn 2678: =item * &authform_xxxxxx()
1.35 matthew 2679:
2680: The authform_xxxxxx subroutines provide javascript and html forms which
2681: handle some of the conveniences required for authentication forms.
2682: This is not an optimal method, but it works.
2683:
2684: =over 4
2685:
1.112 bowersj2 2686: =item * authform_header
1.35 matthew 2687:
1.112 bowersj2 2688: =item * authform_authorwarning
1.35 matthew 2689:
1.112 bowersj2 2690: =item * authform_nochange
1.35 matthew 2691:
1.112 bowersj2 2692: =item * authform_kerberos
1.35 matthew 2693:
1.112 bowersj2 2694: =item * authform_internal
1.35 matthew 2695:
1.112 bowersj2 2696: =item * authform_filesystem
1.35 matthew 2697:
2698: =back
2699:
1.648 raeburn 2700: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2701:
1.35 matthew 2702: =cut
2703:
2704: #-------------------------------------------
1.32 matthew 2705: sub authform_header{
2706: my %in = (
2707: formname => 'cu',
1.80 albertel 2708: kerb_def_dom => '',
1.32 matthew 2709: @_,
2710: );
2711: $in{'formname'} = 'document.' . $in{'formname'};
2712: my $result='';
1.80 albertel 2713:
2714: #---------------------------------------------- Code for upper case translation
2715: my $Javascript_toUpperCase;
2716: unless ($in{kerb_def_dom}) {
2717: $Javascript_toUpperCase =<<"END";
2718: switch (choice) {
2719: case 'krb': currentform.elements[choicearg].value =
2720: currentform.elements[choicearg].value.toUpperCase();
2721: break;
2722: default:
2723: }
2724: END
2725: } else {
2726: $Javascript_toUpperCase = "";
2727: }
2728:
1.165 raeburn 2729: my $radioval = "'nochange'";
1.591 raeburn 2730: if (defined($in{'curr_authtype'})) {
2731: if ($in{'curr_authtype'} ne '') {
2732: $radioval = "'".$in{'curr_authtype'}."arg'";
2733: }
1.174 matthew 2734: }
1.165 raeburn 2735: my $argfield = 'null';
1.591 raeburn 2736: if (defined($in{'mode'})) {
1.165 raeburn 2737: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2738: if (defined($in{'curr_autharg'})) {
2739: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2740: $argfield = "'$in{'curr_autharg'}'";
2741: }
2742: }
2743: }
2744: }
2745:
1.32 matthew 2746: $result.=<<"END";
2747: var current = new Object();
1.165 raeburn 2748: current.radiovalue = $radioval;
2749: current.argfield = $argfield;
1.32 matthew 2750:
2751: function changed_radio(choice,currentform) {
2752: var choicearg = choice + 'arg';
2753: // If a radio button in changed, we need to change the argfield
2754: if (current.radiovalue != choice) {
2755: current.radiovalue = choice;
2756: if (current.argfield != null) {
2757: currentform.elements[current.argfield].value = '';
2758: }
2759: if (choice == 'nochange') {
2760: current.argfield = null;
2761: } else {
2762: current.argfield = choicearg;
2763: switch(choice) {
2764: case 'krb':
2765: currentform.elements[current.argfield].value =
2766: "$in{'kerb_def_dom'}";
2767: break;
2768: default:
2769: break;
2770: }
2771: }
2772: }
2773: return;
2774: }
1.22 www 2775:
1.32 matthew 2776: function changed_text(choice,currentform) {
2777: var choicearg = choice + 'arg';
2778: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2779: $Javascript_toUpperCase
1.32 matthew 2780: // clear old field
2781: if ((current.argfield != choicearg) && (current.argfield != null)) {
2782: currentform.elements[current.argfield].value = '';
2783: }
2784: current.argfield = choicearg;
2785: }
2786: set_auth_radio_buttons(choice,currentform);
2787: return;
1.20 www 2788: }
1.32 matthew 2789:
2790: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2791: var numauthchoices = currentform.login.length;
2792: if (typeof numauthchoices == "undefined") {
2793: return;
2794: }
1.32 matthew 2795: var i=0;
1.986 raeburn 2796: while (i < numauthchoices) {
1.32 matthew 2797: if (currentform.login[i].value == newvalue) { break; }
2798: i++;
2799: }
1.986 raeburn 2800: if (i == numauthchoices) {
1.32 matthew 2801: return;
2802: }
2803: current.radiovalue = newvalue;
2804: currentform.login[i].checked = true;
2805: return;
2806: }
2807: END
2808: return $result;
2809: }
2810:
1.1075.2.20 raeburn 2811: sub authform_authorwarning {
1.32 matthew 2812: my $result='';
1.144 matthew 2813: $result='<i>'.
2814: &mt('As a general rule, only authors or co-authors should be '.
2815: 'filesystem authenticated '.
2816: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2817: return $result;
2818: }
2819:
1.1075.2.20 raeburn 2820: sub authform_nochange {
1.32 matthew 2821: my %in = (
2822: formname => 'document.cu',
2823: kerb_def_dom => 'MSU.EDU',
2824: @_,
2825: );
1.1075.2.20 raeburn 2826: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2827: my $result;
1.1075.2.20 raeburn 2828: if (!$authnum) {
2829: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2830: } else {
2831: $result = '<label>'.&mt('[_1] Do not change login data',
2832: '<input type="radio" name="login" value="nochange" '.
2833: 'checked="checked" onclick="'.
1.281 albertel 2834: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2835: '</label>';
1.586 raeburn 2836: }
1.32 matthew 2837: return $result;
2838: }
2839:
1.591 raeburn 2840: sub authform_kerberos {
1.32 matthew 2841: my %in = (
2842: formname => 'document.cu',
2843: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2844: kerb_def_auth => 'krb4',
1.32 matthew 2845: @_,
2846: );
1.586 raeburn 2847: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1075.2.117 raeburn 2848: $autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2849: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2850: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2851: $check5 = ' checked="checked"';
1.80 albertel 2852: } else {
1.772 bisitz 2853: $check4 = ' checked="checked"';
1.80 albertel 2854: }
1.1075.2.117 raeburn 2855: if ($in{'readonly'}) {
2856: $disabled = ' disabled="disabled"';
2857: }
1.165 raeburn 2858: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2859: if (defined($in{'curr_authtype'})) {
2860: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2861: $krbcheck = ' checked="checked"';
1.623 raeburn 2862: if (defined($in{'mode'})) {
2863: if ($in{'mode'} eq 'modifyuser') {
2864: $krbcheck = '';
2865: }
2866: }
1.591 raeburn 2867: if (defined($in{'curr_kerb_ver'})) {
2868: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2869: $check5 = ' checked="checked"';
1.591 raeburn 2870: $check4 = '';
2871: } else {
1.772 bisitz 2872: $check4 = ' checked="checked"';
1.591 raeburn 2873: $check5 = '';
2874: }
1.586 raeburn 2875: }
1.591 raeburn 2876: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2877: $krbarg = $in{'curr_autharg'};
2878: }
1.586 raeburn 2879: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2880: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2881: $result =
2882: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2883: $in{'curr_autharg'},$krbver);
2884: } else {
2885: $result =
2886: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2887: }
2888: return $result;
2889: }
2890: }
2891: } else {
2892: if ($authnum == 1) {
1.784 bisitz 2893: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2894: }
2895: }
1.586 raeburn 2896: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2897: return;
1.587 raeburn 2898: } elsif ($authtype eq '') {
1.591 raeburn 2899: if (defined($in{'mode'})) {
1.587 raeburn 2900: if ($in{'mode'} eq 'modifycourse') {
2901: if ($authnum == 1) {
1.1075.2.117 raeburn 2902: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 2903: }
2904: }
2905: }
1.586 raeburn 2906: }
2907: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2908: if ($authtype eq '') {
2909: $authtype = '<input type="radio" name="login" value="krb" '.
2910: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1075.2.117 raeburn 2911: $krbcheck.$disabled.' />';
1.586 raeburn 2912: }
2913: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1075.2.20 raeburn 2914: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2915: $in{'curr_authtype'} eq 'krb5') ||
1.1075.2.20 raeburn 2916: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2917: $in{'curr_authtype'} eq 'krb4')) {
2918: $result .= &mt
1.144 matthew 2919: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2920: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2921: '<label>'.$authtype,
1.281 albertel 2922: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2923: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2924: 'onchange="'.$jscall.'"'.$disabled.' />',
2925: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
2926: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 2927: '</label>');
1.586 raeburn 2928: } elsif ($can_assign{'krb4'}) {
2929: $result .= &mt
2930: ('[_1] Kerberos authenticated with domain [_2] '.
2931: '[_3] Version 4 [_4]',
2932: '<label>'.$authtype,
2933: '</label><input type="text" size="10" name="krbarg" '.
2934: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2935: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2936: '<label><input type="hidden" name="krbver" value="4" />',
2937: '</label>');
2938: } elsif ($can_assign{'krb5'}) {
2939: $result .= &mt
2940: ('[_1] Kerberos authenticated with domain [_2] '.
2941: '[_3] Version 5 [_4]',
2942: '<label>'.$authtype,
2943: '</label><input type="text" size="10" name="krbarg" '.
2944: 'value="'.$krbarg.'" '.
1.1075.2.117 raeburn 2945: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 2946: '<label><input type="hidden" name="krbver" value="5" />',
2947: '</label>');
2948: }
1.32 matthew 2949: return $result;
2950: }
2951:
1.1075.2.20 raeburn 2952: sub authform_internal {
1.586 raeburn 2953: my %in = (
1.32 matthew 2954: formname => 'document.cu',
2955: kerb_def_dom => 'MSU.EDU',
2956: @_,
2957: );
1.1075.2.117 raeburn 2958: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 2959: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 2960: if ($in{'readonly'}) {
2961: $disabled = ' disabled="disabled"';
2962: }
1.591 raeburn 2963: if (defined($in{'curr_authtype'})) {
2964: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2965: if ($can_assign{'int'}) {
1.772 bisitz 2966: $intcheck = 'checked="checked" ';
1.623 raeburn 2967: if (defined($in{'mode'})) {
2968: if ($in{'mode'} eq 'modifyuser') {
2969: $intcheck = '';
2970: }
2971: }
1.591 raeburn 2972: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2973: $intarg = $in{'curr_autharg'};
2974: }
2975: } else {
2976: $result = &mt('Currently internally authenticated.');
2977: return $result;
1.165 raeburn 2978: }
2979: }
1.586 raeburn 2980: } else {
2981: if ($authnum == 1) {
1.784 bisitz 2982: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2983: }
2984: }
2985: if (!$can_assign{'int'}) {
2986: return;
1.587 raeburn 2987: } elsif ($authtype eq '') {
1.591 raeburn 2988: if (defined($in{'mode'})) {
1.587 raeburn 2989: if ($in{'mode'} eq 'modifycourse') {
2990: if ($authnum == 1) {
1.1075.2.117 raeburn 2991: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 2992: }
2993: }
2994: }
1.165 raeburn 2995: }
1.586 raeburn 2996: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2997: if ($authtype eq '') {
2998: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1075.2.117 raeburn 2999: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3000: }
1.605 bisitz 3001: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1075.2.117 raeburn 3002: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3003: $result = &mt
1.144 matthew 3004: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3005: '<label>'.$authtype,'</label>'.$autharg);
1.1075.2.118 raeburn 3006: $result.='<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.intarg.type='."'text'".' } else { this.form.intarg.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>';
1.32 matthew 3007: return $result;
3008: }
3009:
1.1075.2.20 raeburn 3010: sub authform_local {
1.32 matthew 3011: my %in = (
3012: formname => 'document.cu',
3013: kerb_def_dom => 'MSU.EDU',
3014: @_,
3015: );
1.1075.2.117 raeburn 3016: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3017: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3018: if ($in{'readonly'}) {
3019: $disabled = ' disabled="disabled"';
3020: }
1.591 raeburn 3021: if (defined($in{'curr_authtype'})) {
3022: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3023: if ($can_assign{'loc'}) {
1.772 bisitz 3024: $loccheck = 'checked="checked" ';
1.623 raeburn 3025: if (defined($in{'mode'})) {
3026: if ($in{'mode'} eq 'modifyuser') {
3027: $loccheck = '';
3028: }
3029: }
1.591 raeburn 3030: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3031: $locarg = $in{'curr_autharg'};
3032: }
3033: } else {
3034: $result = &mt('Currently using local (institutional) authentication.');
3035: return $result;
1.165 raeburn 3036: }
3037: }
1.586 raeburn 3038: } else {
3039: if ($authnum == 1) {
1.784 bisitz 3040: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3041: }
3042: }
3043: if (!$can_assign{'loc'}) {
3044: return;
1.587 raeburn 3045: } elsif ($authtype eq '') {
1.591 raeburn 3046: if (defined($in{'mode'})) {
1.587 raeburn 3047: if ($in{'mode'} eq 'modifycourse') {
3048: if ($authnum == 1) {
1.1075.2.117 raeburn 3049: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3050: }
3051: }
3052: }
1.165 raeburn 3053: }
1.586 raeburn 3054: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3055: if ($authtype eq '') {
3056: $authtype = '<input type="radio" name="login" value="loc" '.
3057: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3058: $jscall.'"'.$disabled.' />';
1.586 raeburn 3059: }
3060: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1075.2.117 raeburn 3061: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3062: $result = &mt('[_1] Local Authentication with argument [_2]',
3063: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3064: return $result;
3065: }
3066:
1.1075.2.20 raeburn 3067: sub authform_filesystem {
1.32 matthew 3068: my %in = (
3069: formname => 'document.cu',
3070: kerb_def_dom => 'MSU.EDU',
3071: @_,
3072: );
1.1075.2.117 raeburn 3073: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1075.2.20 raeburn 3074: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1075.2.117 raeburn 3075: if ($in{'readonly'}) {
3076: $disabled = ' disabled="disabled"';
3077: }
1.591 raeburn 3078: if (defined($in{'curr_authtype'})) {
3079: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3080: if ($can_assign{'fsys'}) {
1.772 bisitz 3081: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3082: if (defined($in{'mode'})) {
3083: if ($in{'mode'} eq 'modifyuser') {
3084: $fsyscheck = '';
3085: }
3086: }
1.586 raeburn 3087: } else {
3088: $result = &mt('Currently Filesystem Authenticated.');
3089: return $result;
3090: }
3091: }
3092: } else {
3093: if ($authnum == 1) {
1.784 bisitz 3094: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3095: }
3096: }
3097: if (!$can_assign{'fsys'}) {
3098: return;
1.587 raeburn 3099: } elsif ($authtype eq '') {
1.591 raeburn 3100: if (defined($in{'mode'})) {
1.587 raeburn 3101: if ($in{'mode'} eq 'modifycourse') {
3102: if ($authnum == 1) {
1.1075.2.117 raeburn 3103: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3104: }
3105: }
3106: }
1.586 raeburn 3107: }
3108: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3109: if ($authtype eq '') {
3110: $authtype = '<input type="radio" name="login" value="fsys" '.
3111: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1075.2.117 raeburn 3112: $jscall.'"'.$disabled.' />';
1.586 raeburn 3113: }
3114: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
1.1075.2.117 raeburn 3115: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3116: $result = &mt
1.144 matthew 3117: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 3118: '<label><input type="radio" name="login" value="fsys" '.
1.1075.2.117 raeburn 3119: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />',
1.605 bisitz 3120: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.1075.2.117 raeburn 3121: 'onchange="'.$jscall.'"'.$disabled.' />');
1.32 matthew 3122: return $result;
3123: }
3124:
1.586 raeburn 3125: sub get_assignable_auth {
3126: my ($dom) = @_;
3127: if ($dom eq '') {
3128: $dom = $env{'request.role.domain'};
3129: }
3130: my %can_assign = (
3131: krb4 => 1,
3132: krb5 => 1,
3133: int => 1,
3134: loc => 1,
3135: );
3136: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3137: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3138: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3139: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3140: my $context;
3141: if ($env{'request.role'} =~ /^au/) {
3142: $context = 'author';
1.1075.2.117 raeburn 3143: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3144: $context = 'domain';
3145: } elsif ($env{'request.course.id'}) {
3146: $context = 'course';
3147: }
3148: if ($context) {
3149: if (ref($authhash->{$context}) eq 'HASH') {
3150: %can_assign = %{$authhash->{$context}};
3151: }
3152: }
3153: }
3154: }
3155: my $authnum = 0;
3156: foreach my $key (keys(%can_assign)) {
3157: if ($can_assign{$key}) {
3158: $authnum ++;
3159: }
3160: }
3161: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3162: $authnum --;
3163: }
3164: return ($authnum,%can_assign);
3165: }
3166:
1.80 albertel 3167: ###############################################################
3168: ## Get Kerberos Defaults for Domain ##
3169: ###############################################################
3170: ##
3171: ## Returns default kerberos version and an associated argument
3172: ## as listed in file domain.tab. If not listed, provides
3173: ## appropriate default domain and kerberos version.
3174: ##
3175: #-------------------------------------------
3176:
3177: =pod
3178:
1.648 raeburn 3179: =item * &get_kerberos_defaults()
1.80 albertel 3180:
3181: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3182: version and domain. If not found, it defaults to version 4 and the
3183: domain of the server.
1.80 albertel 3184:
1.648 raeburn 3185: =over 4
3186:
1.80 albertel 3187: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3188:
1.648 raeburn 3189: =back
3190:
3191: =back
3192:
1.80 albertel 3193: =cut
3194:
3195: #-------------------------------------------
3196: sub get_kerberos_defaults {
3197: my $domain=shift;
1.641 raeburn 3198: my ($krbdef,$krbdefdom);
3199: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3200: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3201: $krbdef = $domdefaults{'auth_def'};
3202: $krbdefdom = $domdefaults{'auth_arg_def'};
3203: } else {
1.80 albertel 3204: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3205: my $krbdefdom=$1;
3206: $krbdefdom=~tr/a-z/A-Z/;
3207: $krbdef = "krb4";
3208: }
3209: return ($krbdef,$krbdefdom);
3210: }
1.112 bowersj2 3211:
1.32 matthew 3212:
1.46 matthew 3213: ###############################################################
3214: ## Thesaurus Functions ##
3215: ###############################################################
1.20 www 3216:
1.46 matthew 3217: =pod
1.20 www 3218:
1.112 bowersj2 3219: =head1 Thesaurus Functions
3220:
3221: =over 4
3222:
1.648 raeburn 3223: =item * &initialize_keywords()
1.46 matthew 3224:
3225: Initializes the package variable %Keywords if it is empty. Uses the
3226: package variable $thesaurus_db_file.
3227:
3228: =cut
3229:
3230: ###################################################
3231:
3232: sub initialize_keywords {
3233: return 1 if (scalar keys(%Keywords));
3234: # If we are here, %Keywords is empty, so fill it up
3235: # Make sure the file we need exists...
3236: if (! -e $thesaurus_db_file) {
3237: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3238: " failed because it does not exist");
3239: return 0;
3240: }
3241: # Set up the hash as a database
3242: my %thesaurus_db;
3243: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3244: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3245: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3246: $thesaurus_db_file);
3247: return 0;
3248: }
3249: # Get the average number of appearances of a word.
3250: my $avecount = $thesaurus_db{'average.count'};
3251: # Put keywords (those that appear > average) into %Keywords
3252: while (my ($word,$data)=each (%thesaurus_db)) {
3253: my ($count,undef) = split /:/,$data;
3254: $Keywords{$word}++ if ($count > $avecount);
3255: }
3256: untie %thesaurus_db;
3257: # Remove special values from %Keywords.
1.356 albertel 3258: foreach my $value ('total.count','average.count') {
3259: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3260: }
1.46 matthew 3261: return 1;
3262: }
3263:
3264: ###################################################
3265:
3266: =pod
3267:
1.648 raeburn 3268: =item * &keyword($word)
1.46 matthew 3269:
3270: Returns true if $word is a keyword. A keyword is a word that appears more
3271: than the average number of times in the thesaurus database. Calls
3272: &initialize_keywords
3273:
3274: =cut
3275:
3276: ###################################################
1.20 www 3277:
3278: sub keyword {
1.46 matthew 3279: return if (!&initialize_keywords());
3280: my $word=lc(shift());
3281: $word=~s/\W//g;
3282: return exists($Keywords{$word});
1.20 www 3283: }
1.46 matthew 3284:
3285: ###############################################################
3286:
3287: =pod
1.20 www 3288:
1.648 raeburn 3289: =item * &get_related_words()
1.46 matthew 3290:
1.160 matthew 3291: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3292: an array of words. If the keyword is not in the thesaurus, an empty array
3293: will be returned. The order of the words returned is determined by the
3294: database which holds them.
3295:
3296: Uses global $thesaurus_db_file.
3297:
1.1057 foxr 3298:
1.46 matthew 3299: =cut
3300:
3301: ###############################################################
3302: sub get_related_words {
3303: my $keyword = shift;
3304: my %thesaurus_db;
3305: if (! -e $thesaurus_db_file) {
3306: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3307: "failed because the file does not exist");
3308: return ();
3309: }
3310: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3311: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3312: return ();
3313: }
3314: my @Words=();
1.429 www 3315: my $count=0;
1.46 matthew 3316: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3317: # The first element is the number of times
3318: # the word appears. We do not need it now.
1.429 www 3319: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3320: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3321: my $threshold=$mostfrequentcount/10;
3322: foreach my $possibleword (@RelatedWords) {
3323: my ($word,$wordcount)=split(/\,/,$possibleword);
3324: if ($wordcount>$threshold) {
3325: push(@Words,$word);
3326: $count++;
3327: if ($count>10) { last; }
3328: }
1.20 www 3329: }
3330: }
1.46 matthew 3331: untie %thesaurus_db;
3332: return @Words;
1.14 harris41 3333: }
1.46 matthew 3334:
1.112 bowersj2 3335: =pod
3336:
3337: =back
3338:
3339: =cut
1.61 www 3340:
3341: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3342: =pod
3343:
1.112 bowersj2 3344: =head1 User Name Functions
3345:
3346: =over 4
3347:
1.648 raeburn 3348: =item * &plainname($uname,$udom,$first)
1.81 albertel 3349:
1.112 bowersj2 3350: Takes a users logon name and returns it as a string in
1.226 albertel 3351: "first middle last generation" form
3352: if $first is set to 'lastname' then it returns it as
3353: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3354:
3355: =cut
1.61 www 3356:
1.295 www 3357:
1.81 albertel 3358: ###############################################################
1.61 www 3359: sub plainname {
1.226 albertel 3360: my ($uname,$udom,$first)=@_;
1.537 albertel 3361: return if (!defined($uname) || !defined($udom));
1.295 www 3362: my %names=&getnames($uname,$udom);
1.226 albertel 3363: my $name=&Apache::lonnet::format_name($names{'firstname'},
3364: $names{'middlename'},
3365: $names{'lastname'},
3366: $names{'generation'},$first);
3367: $name=~s/^\s+//;
1.62 www 3368: $name=~s/\s+$//;
3369: $name=~s/\s+/ /g;
1.353 albertel 3370: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3371: return $name;
1.61 www 3372: }
1.66 www 3373:
3374: # -------------------------------------------------------------------- Nickname
1.81 albertel 3375: =pod
3376:
1.648 raeburn 3377: =item * &nickname($uname,$udom)
1.81 albertel 3378:
3379: Gets a users name and returns it as a string as
3380:
3381: ""nickname""
1.66 www 3382:
1.81 albertel 3383: if the user has a nickname or
3384:
3385: "first middle last generation"
3386:
3387: if the user does not
3388:
3389: =cut
1.66 www 3390:
3391: sub nickname {
3392: my ($uname,$udom)=@_;
1.537 albertel 3393: return if (!defined($uname) || !defined($udom));
1.295 www 3394: my %names=&getnames($uname,$udom);
1.68 albertel 3395: my $name=$names{'nickname'};
1.66 www 3396: if ($name) {
3397: $name='"'.$name.'"';
3398: } else {
3399: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3400: $names{'lastname'}.' '.$names{'generation'};
3401: $name=~s/\s+$//;
3402: $name=~s/\s+/ /g;
3403: }
3404: return $name;
3405: }
3406:
1.295 www 3407: sub getnames {
3408: my ($uname,$udom)=@_;
1.537 albertel 3409: return if (!defined($uname) || !defined($udom));
1.433 albertel 3410: if ($udom eq 'public' && $uname eq 'public') {
3411: return ('lastname' => &mt('Public'));
3412: }
1.295 www 3413: my $id=$uname.':'.$udom;
3414: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3415: if ($cached) {
3416: return %{$names};
3417: } else {
3418: my %loadnames=&Apache::lonnet::get('environment',
3419: ['firstname','middlename','lastname','generation','nickname'],
3420: $udom,$uname);
3421: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3422: return %loadnames;
3423: }
3424: }
1.61 www 3425:
1.542 raeburn 3426: # -------------------------------------------------------------------- getemails
1.648 raeburn 3427:
1.542 raeburn 3428: =pod
3429:
1.648 raeburn 3430: =item * &getemails($uname,$udom)
1.542 raeburn 3431:
3432: Gets a user's email information and returns it as a hash with keys:
3433: notification, critnotification, permanentemail
3434:
3435: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3436: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3437:
1.648 raeburn 3438:
1.542 raeburn 3439: =cut
3440:
1.648 raeburn 3441:
1.466 albertel 3442: sub getemails {
3443: my ($uname,$udom)=@_;
3444: if ($udom eq 'public' && $uname eq 'public') {
3445: return;
3446: }
1.467 www 3447: if (!$udom) { $udom=$env{'user.domain'}; }
3448: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3449: my $id=$uname.':'.$udom;
3450: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3451: if ($cached) {
3452: return %{$names};
3453: } else {
3454: my %loadnames=&Apache::lonnet::get('environment',
3455: ['notification','critnotification',
3456: 'permanentemail'],
3457: $udom,$uname);
3458: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3459: return %loadnames;
3460: }
3461: }
3462:
1.551 albertel 3463: sub flush_email_cache {
3464: my ($uname,$udom)=@_;
3465: if (!$udom) { $udom =$env{'user.domain'}; }
3466: if (!$uname) { $uname=$env{'user.name'}; }
3467: return if ($udom eq 'public' && $uname eq 'public');
3468: my $id=$uname.':'.$udom;
3469: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3470: }
3471:
1.728 raeburn 3472: # -------------------------------------------------------------------- getlangs
3473:
3474: =pod
3475:
3476: =item * &getlangs($uname,$udom)
3477:
3478: Gets a user's language preference and returns it as a hash with key:
3479: language.
3480:
3481: =cut
3482:
3483:
3484: sub getlangs {
3485: my ($uname,$udom) = @_;
3486: if (!$udom) { $udom =$env{'user.domain'}; }
3487: if (!$uname) { $uname=$env{'user.name'}; }
3488: my $id=$uname.':'.$udom;
3489: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3490: if ($cached) {
3491: return %{$langs};
3492: } else {
3493: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3494: $udom,$uname);
3495: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3496: return %loadlangs;
3497: }
3498: }
3499:
3500: sub flush_langs_cache {
3501: my ($uname,$udom)=@_;
3502: if (!$udom) { $udom =$env{'user.domain'}; }
3503: if (!$uname) { $uname=$env{'user.name'}; }
3504: return if ($udom eq 'public' && $uname eq 'public');
3505: my $id=$uname.':'.$udom;
3506: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3507: }
3508:
1.61 www 3509: # ------------------------------------------------------------------ Screenname
1.81 albertel 3510:
3511: =pod
3512:
1.648 raeburn 3513: =item * &screenname($uname,$udom)
1.81 albertel 3514:
3515: Gets a users screenname and returns it as a string
3516:
3517: =cut
1.61 www 3518:
3519: sub screenname {
3520: my ($uname,$udom)=@_;
1.258 albertel 3521: if ($uname eq $env{'user.name'} &&
3522: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3523: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3524: return $names{'screenname'};
1.62 www 3525: }
3526:
1.212 albertel 3527:
1.802 bisitz 3528: # ------------------------------------------------------------- Confirm Wrapper
3529: =pod
3530:
1.1075.2.42 raeburn 3531: =item * &confirmwrapper($message)
1.802 bisitz 3532:
3533: Wrap messages about completion of operation in box
3534:
3535: =cut
3536:
3537: sub confirmwrapper {
3538: my ($message)=@_;
3539: if ($message) {
3540: return "\n".'<div class="LC_confirm_box">'."\n"
3541: .$message."\n"
3542: .'</div>'."\n";
3543: } else {
3544: return $message;
3545: }
3546: }
3547:
1.62 www 3548: # ------------------------------------------------------------- Message Wrapper
3549:
3550: sub messagewrapper {
1.369 www 3551: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3552: return
1.441 albertel 3553: '<a href="/adm/email?compose=individual&'.
3554: 'recname='.$username.'&recdom='.$domain.
3555: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3556: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3557: }
1.802 bisitz 3558:
1.74 www 3559: # --------------------------------------------------------------- Notes Wrapper
3560:
3561: sub noteswrapper {
3562: my ($link,$un,$do)=@_;
3563: return
1.896 amueller 3564: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3565: }
1.802 bisitz 3566:
1.62 www 3567: # ------------------------------------------------------------- Aboutme Wrapper
3568:
3569: sub aboutmewrapper {
1.1070 raeburn 3570: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3571: if (!defined($username) && !defined($domain)) {
3572: return;
3573: }
1.1075.2.15 raeburn 3574: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3575: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3576: }
3577:
3578: # ------------------------------------------------------------ Syllabus Wrapper
3579:
3580: sub syllabuswrapper {
1.707 bisitz 3581: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3582: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3583: }
1.14 harris41 3584:
1.802 bisitz 3585: # -----------------------------------------------------------------------------
3586:
1.208 matthew 3587: sub track_student_link {
1.887 raeburn 3588: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3589: my $link ="/adm/trackstudent?";
1.208 matthew 3590: my $title = 'View recent activity';
3591: if (defined($sname) && $sname !~ /^\s*$/ &&
3592: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3593: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3594: $title .= ' of this student';
1.268 albertel 3595: }
1.208 matthew 3596: if (defined($target) && $target !~ /^\s*$/) {
3597: $target = qq{target="$target"};
3598: } else {
3599: $target = '';
3600: }
1.268 albertel 3601: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3602: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3603: $title = &mt($title);
3604: $linktext = &mt($linktext);
1.448 albertel 3605: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3606: &help_open_topic('View_recent_activity');
1.208 matthew 3607: }
3608:
1.781 raeburn 3609: sub slot_reservations_link {
3610: my ($linktext,$sname,$sdom,$target) = @_;
3611: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3612: my $title = 'View slot reservation history';
3613: if (defined($sname) && $sname !~ /^\s*$/ &&
3614: defined($sdom) && $sdom !~ /^\s*$/) {
3615: $link .= "&uname=$sname&udom=$sdom";
3616: $title .= ' of this student';
3617: }
3618: if (defined($target) && $target !~ /^\s*$/) {
3619: $target = qq{target="$target"};
3620: } else {
3621: $target = '';
3622: }
3623: $title = &mt($title);
3624: $linktext = &mt($linktext);
3625: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3626: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3627:
3628: }
3629:
1.508 www 3630: # ===================================================== Display a student photo
3631:
3632:
1.509 albertel 3633: sub student_image_tag {
1.508 www 3634: my ($domain,$user)=@_;
3635: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3636: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3637: return '<img src="'.$imgsrc.'" align="right" />';
3638: } else {
3639: return '';
3640: }
3641: }
3642:
1.112 bowersj2 3643: =pod
3644:
3645: =back
3646:
3647: =head1 Access .tab File Data
3648:
3649: =over 4
3650:
1.648 raeburn 3651: =item * &languageids()
1.112 bowersj2 3652:
3653: returns list of all language ids
3654:
3655: =cut
3656:
1.14 harris41 3657: sub languageids {
1.16 harris41 3658: return sort(keys(%language));
1.14 harris41 3659: }
3660:
1.112 bowersj2 3661: =pod
3662:
1.648 raeburn 3663: =item * &languagedescription()
1.112 bowersj2 3664:
3665: returns description of a specified language id
3666:
3667: =cut
3668:
1.14 harris41 3669: sub languagedescription {
1.125 www 3670: my $code=shift;
3671: return ($supported_language{$code}?'* ':'').
3672: $language{$code}.
1.126 www 3673: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3674: }
3675:
1.1048 foxr 3676: =pod
3677:
3678: =item * &plainlanguagedescription
3679:
3680: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3681: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3682:
3683: =cut
3684:
1.145 www 3685: sub plainlanguagedescription {
3686: my $code=shift;
3687: return $language{$code};
3688: }
3689:
1.1048 foxr 3690: =pod
3691:
3692: =item * &supportedlanguagecode
3693:
3694: Returns the supported language code (e.g. sptutf maps to pt) given a language
3695: code.
3696:
3697: =cut
3698:
1.145 www 3699: sub supportedlanguagecode {
3700: my $code=shift;
3701: return $supported_language{$code};
1.97 www 3702: }
3703:
1.112 bowersj2 3704: =pod
3705:
1.1048 foxr 3706: =item * &latexlanguage()
3707:
3708: Given a language key code returns the correspondnig language to use
3709: to select the correct hyphenation on LaTeX printouts. This is undef if there
3710: is no supported hyphenation for the language code.
3711:
3712: =cut
3713:
3714: sub latexlanguage {
3715: my $code = shift;
3716: return $latex_language{$code};
3717: }
3718:
3719: =pod
3720:
3721: =item * &latexhyphenation()
3722:
3723: Same as above but what's supplied is the language as it might be stored
3724: in the metadata.
3725:
3726: =cut
3727:
3728: sub latexhyphenation {
3729: my $key = shift;
3730: return $latex_language_bykey{$key};
3731: }
3732:
3733: =pod
3734:
1.648 raeburn 3735: =item * ©rightids()
1.112 bowersj2 3736:
3737: returns list of all copyrights
3738:
3739: =cut
3740:
3741: sub copyrightids {
3742: return sort(keys(%cprtag));
3743: }
3744:
3745: =pod
3746:
1.648 raeburn 3747: =item * ©rightdescription()
1.112 bowersj2 3748:
3749: returns description of a specified copyright id
3750:
3751: =cut
3752:
3753: sub copyrightdescription {
1.166 www 3754: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3755: }
1.197 matthew 3756:
3757: =pod
3758:
1.648 raeburn 3759: =item * &source_copyrightids()
1.192 taceyjo1 3760:
3761: returns list of all source copyrights
3762:
3763: =cut
3764:
3765: sub source_copyrightids {
3766: return sort(keys(%scprtag));
3767: }
3768:
3769: =pod
3770:
1.648 raeburn 3771: =item * &source_copyrightdescription()
1.192 taceyjo1 3772:
3773: returns description of a specified source copyright id
3774:
3775: =cut
3776:
3777: sub source_copyrightdescription {
3778: return &mt($scprtag{shift(@_)});
3779: }
1.112 bowersj2 3780:
3781: =pod
3782:
1.648 raeburn 3783: =item * &filecategories()
1.112 bowersj2 3784:
3785: returns list of all file categories
3786:
3787: =cut
3788:
3789: sub filecategories {
3790: return sort(keys(%category_extensions));
3791: }
3792:
3793: =pod
3794:
1.648 raeburn 3795: =item * &filecategorytypes()
1.112 bowersj2 3796:
3797: returns list of file types belonging to a given file
3798: category
3799:
3800: =cut
3801:
3802: sub filecategorytypes {
1.356 albertel 3803: my ($cat) = @_;
3804: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3805: }
3806:
3807: =pod
3808:
1.648 raeburn 3809: =item * &fileembstyle()
1.112 bowersj2 3810:
3811: returns embedding style for a specified file type
3812:
3813: =cut
3814:
3815: sub fileembstyle {
3816: return $fe{lc(shift(@_))};
1.169 www 3817: }
3818:
1.351 www 3819: sub filemimetype {
3820: return $fm{lc(shift(@_))};
3821: }
3822:
1.169 www 3823:
3824: sub filecategoryselect {
3825: my ($name,$value)=@_;
1.189 matthew 3826: return &select_form($value,$name,
1.970 raeburn 3827: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3828: }
3829:
3830: =pod
3831:
1.648 raeburn 3832: =item * &filedescription()
1.112 bowersj2 3833:
3834: returns description for a specified file type
3835:
3836: =cut
3837:
3838: sub filedescription {
1.188 matthew 3839: my $file_description = $fd{lc(shift())};
3840: $file_description =~ s:([\[\]]):~$1:g;
3841: return &mt($file_description);
1.112 bowersj2 3842: }
3843:
3844: =pod
3845:
1.648 raeburn 3846: =item * &filedescriptionex()
1.112 bowersj2 3847:
3848: returns description for a specified file type with
3849: extra formatting
3850:
3851: =cut
3852:
3853: sub filedescriptionex {
3854: my $ex=shift;
1.188 matthew 3855: my $file_description = $fd{lc($ex)};
3856: $file_description =~ s:([\[\]]):~$1:g;
3857: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3858: }
3859:
3860: # End of .tab access
3861: =pod
3862:
3863: =back
3864:
3865: =cut
3866:
3867: # ------------------------------------------------------------------ File Types
3868: sub fileextensions {
3869: return sort(keys(%fe));
3870: }
3871:
1.97 www 3872: # ----------------------------------------------------------- Display Languages
3873: # returns a hash with all desired display languages
3874: #
3875:
3876: sub display_languages {
3877: my %languages=();
1.695 raeburn 3878: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3879: $languages{$lang}=1;
1.97 www 3880: }
3881: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3882: if ($env{'form.displaylanguage'}) {
1.356 albertel 3883: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3884: $languages{$lang}=1;
1.97 www 3885: }
3886: }
3887: return %languages;
1.14 harris41 3888: }
3889:
1.582 albertel 3890: sub languages {
3891: my ($possible_langs) = @_;
1.695 raeburn 3892: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3893: if (!ref($possible_langs)) {
3894: if( wantarray ) {
3895: return @preferred_langs;
3896: } else {
3897: return $preferred_langs[0];
3898: }
3899: }
3900: my %possibilities = map { $_ => 1 } (@$possible_langs);
3901: my @preferred_possibilities;
3902: foreach my $preferred_lang (@preferred_langs) {
3903: if (exists($possibilities{$preferred_lang})) {
3904: push(@preferred_possibilities, $preferred_lang);
3905: }
3906: }
3907: if( wantarray ) {
3908: return @preferred_possibilities;
3909: }
3910: return $preferred_possibilities[0];
3911: }
3912:
1.742 raeburn 3913: sub user_lang {
3914: my ($touname,$toudom,$fromcid) = @_;
3915: my @userlangs;
3916: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3917: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3918: $env{'course.'.$fromcid.'.languages'}));
3919: } else {
3920: my %langhash = &getlangs($touname,$toudom);
3921: if ($langhash{'languages'} ne '') {
3922: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3923: } else {
3924: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3925: if ($domdefs{'lang_def'} ne '') {
3926: @userlangs = ($domdefs{'lang_def'});
3927: }
3928: }
3929: }
3930: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3931: my $user_lh = Apache::localize->get_handle(@languages);
3932: return $user_lh;
3933: }
3934:
3935:
1.112 bowersj2 3936: ###############################################################
3937: ## Student Answer Attempts ##
3938: ###############################################################
3939:
3940: =pod
3941:
3942: =head1 Alternate Problem Views
3943:
3944: =over 4
3945:
1.648 raeburn 3946: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1075.2.86 raeburn 3947: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 3948:
3949: Return string with previous attempt on problem. Arguments:
3950:
3951: =over 4
3952:
3953: =item * $symb: Problem, including path
3954:
3955: =item * $username: username of the desired student
3956:
3957: =item * $domain: domain of the desired student
1.14 harris41 3958:
1.112 bowersj2 3959: =item * $course: Course ID
1.14 harris41 3960:
1.112 bowersj2 3961: =item * $getattempt: Leave blank for all attempts, otherwise put
3962: something
1.14 harris41 3963:
1.112 bowersj2 3964: =item * $regexp: if string matches this regexp, the string will be
3965: sent to $gradesub
1.14 harris41 3966:
1.112 bowersj2 3967: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3968:
1.1075.2.86 raeburn 3969: =item * $usec: section of the desired student
3970:
3971: =item * $identifier: counter for student (multiple students one problem) or
3972: problem (one student; whole sequence).
3973:
1.112 bowersj2 3974: =back
1.14 harris41 3975:
1.112 bowersj2 3976: The output string is a table containing all desired attempts, if any.
1.16 harris41 3977:
1.112 bowersj2 3978: =cut
1.1 albertel 3979:
3980: sub get_previous_attempt {
1.1075.2.86 raeburn 3981: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 3982: my $prevattempts='';
1.43 ng 3983: no strict 'refs';
1.1 albertel 3984: if ($symb) {
1.3 albertel 3985: my (%returnhash)=
3986: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3987: if ($returnhash{'version'}) {
3988: my %lasthash=();
3989: my $version;
3990: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.91 raeburn 3991: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
3992: if ($key =~ /\.rawrndseed$/) {
3993: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
3994: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
3995: } else {
3996: $lasthash{$key}=$returnhash{$version.':'.$key};
3997: }
1.19 harris41 3998: }
1.1 albertel 3999: }
1.596 albertel 4000: $prevattempts=&start_data_table().&start_data_table_header_row();
4001: $prevattempts.='<th>'.&mt('History').'</th>';
1.1075.2.86 raeburn 4002: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4003: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4004: foreach my $key (sort(keys(%lasthash))) {
4005: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4006: if ($#parts > 0) {
1.31 albertel 4007: my $data=$parts[-1];
1.989 raeburn 4008: next if ($data eq 'foilorder');
1.31 albertel 4009: pop(@parts);
1.1010 www 4010: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4011: if ($data eq 'type') {
4012: unless ($showsurv) {
4013: my $id = join(',',@parts);
4014: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4015: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4016: $lasthidden{$ign.'.'.$id} = 1;
4017: }
1.945 raeburn 4018: }
1.1075.2.86 raeburn 4019: if ($identifier ne '') {
4020: my $id = join(',',@parts);
4021: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4022: $domain,$username,$usec,undef,$course) =~ /^no/) {
4023: $hidestatus{$ign.'.'.$id} = 1;
4024: }
4025: }
4026: } elsif ($data eq 'regrader') {
4027: if (($identifier ne '') && (@parts)) {
4028: my $id = join(',',@parts);
4029: $regraded{$ign.'.'.$id} = 1;
4030: }
1.1010 www 4031: }
1.31 albertel 4032: } else {
1.41 ng 4033: if ($#parts == 0) {
4034: $prevattempts.='<th>'.$parts[0].'</th>';
4035: } else {
4036: $prevattempts.='<th>'.$ign.'</th>';
4037: }
1.31 albertel 4038: }
1.16 harris41 4039: }
1.596 albertel 4040: $prevattempts.=&end_data_table_header_row();
1.40 ng 4041: if ($getattempt eq '') {
1.1075.2.86 raeburn 4042: my (%solved,%resets,%probstatus);
4043: if (($identifier ne '') && (keys(%regraded) > 0)) {
4044: for ($version=1;$version<=$returnhash{'version'};$version++) {
4045: foreach my $id (keys(%regraded)) {
4046: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4047: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4048: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4049: push(@{$resets{$id}},$version);
4050: }
4051: }
4052: }
4053: }
1.40 ng 4054: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1075.2.86 raeburn 4055: my (@hidden,@unsolved);
1.945 raeburn 4056: if (%typeparts) {
4057: foreach my $id (keys(%typeparts)) {
1.1075.2.86 raeburn 4058: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4059: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4060: push(@hidden,$id);
1.1075.2.86 raeburn 4061: } elsif ($identifier ne '') {
4062: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4063: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4064: ($hidestatus{$id})) {
4065: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
4066: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4067: push(@{$solved{$id}},$version);
4068: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4069: (ref($solved{$id}) eq 'ARRAY')) {
4070: my $skip;
4071: if (ref($resets{$id}) eq 'ARRAY') {
4072: foreach my $reset (@{$resets{$id}}) {
4073: if ($reset > $solved{$id}[-1]) {
4074: $skip=1;
4075: last;
4076: }
4077: }
4078: }
4079: unless ($skip) {
4080: my ($ign,$partslist) = split(/\./,$id,2);
4081: push(@unsolved,$partslist);
4082: }
4083: }
4084: }
1.945 raeburn 4085: }
4086: }
4087: }
4088: $prevattempts.=&start_data_table_row().
1.1075.2.86 raeburn 4089: '<td>'.&mt('Transaction [_1]',$version);
4090: if (@unsolved) {
4091: $prevattempts .= '<span class="LC_nobreak"><label>'.
4092: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4093: &mt('Hide').'</label></span>';
4094: }
4095: $prevattempts .= '</td>';
1.945 raeburn 4096: if (@hidden) {
4097: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4098: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4099: my $hide;
4100: foreach my $id (@hidden) {
4101: if ($key =~ /^\Q$id\E/) {
4102: $hide = 1;
4103: last;
4104: }
4105: }
4106: if ($hide) {
4107: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4108: if (($data eq 'award') || ($data eq 'awarddetail')) {
4109: my $value = &format_previous_attempt_value($key,
4110: $returnhash{$version.':'.$key});
4111: $prevattempts.='<td>'.$value.' </td>';
4112: } else {
4113: $prevattempts.='<td> </td>';
4114: }
4115: } else {
4116: if ($key =~ /\./) {
1.1075.2.91 raeburn 4117: my $value = $returnhash{$version.':'.$key};
4118: if ($key =~ /\.rndseed$/) {
4119: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4120: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4121: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4122: }
4123: }
4124: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4125: ' </td>';
1.945 raeburn 4126: } else {
4127: $prevattempts.='<td> </td>';
4128: }
4129: }
4130: }
4131: } else {
4132: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4133: next if ($key =~ /\.foilorder$/);
1.1075.2.91 raeburn 4134: my $value = $returnhash{$version.':'.$key};
4135: if ($key =~ /\.rndseed$/) {
4136: my ($id) = ($key =~ /^(.+)\.rndseed$/);
4137: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4138: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4139: }
4140: }
4141: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4142: ' </td>';
1.945 raeburn 4143: }
4144: }
4145: $prevattempts.=&end_data_table_row();
1.40 ng 4146: }
1.1 albertel 4147: }
1.945 raeburn 4148: my @currhidden = keys(%lasthidden);
1.596 albertel 4149: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4150: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4151: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4152: if (%typeparts) {
4153: my $hidden;
4154: foreach my $id (@currhidden) {
4155: if ($key =~ /^\Q$id\E/) {
4156: $hidden = 1;
4157: last;
4158: }
4159: }
4160: if ($hidden) {
4161: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4162: if (($data eq 'award') || ($data eq 'awarddetail')) {
4163: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4164: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4165: $value = &$gradesub($value);
4166: }
4167: $prevattempts.='<td>'.$value.' </td>';
4168: } else {
4169: $prevattempts.='<td> </td>';
4170: }
4171: } else {
4172: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4173: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4174: $value = &$gradesub($value);
4175: }
4176: $prevattempts.='<td>'.$value.' </td>';
4177: }
4178: } else {
4179: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4180: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4181: $value = &$gradesub($value);
4182: }
4183: $prevattempts.='<td>'.$value.' </td>';
4184: }
1.16 harris41 4185: }
1.596 albertel 4186: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4187: } else {
1.596 albertel 4188: $prevattempts=
4189: &start_data_table().&start_data_table_row().
4190: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4191: &end_data_table_row().&end_data_table();
1.1 albertel 4192: }
4193: } else {
1.596 albertel 4194: $prevattempts=
4195: &start_data_table().&start_data_table_row().
4196: '<td>'.&mt('No data.').'</td>'.
4197: &end_data_table_row().&end_data_table();
1.1 albertel 4198: }
1.10 albertel 4199: }
4200:
1.581 albertel 4201: sub format_previous_attempt_value {
4202: my ($key,$value) = @_;
1.1011 www 4203: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.581 albertel 4204: $value = &Apache::lonlocal::locallocaltime($value);
4205: } elsif (ref($value) eq 'ARRAY') {
4206: $value = '('.join(', ', @{ $value }).')';
1.988 raeburn 4207: } elsif ($key =~ /answerstring$/) {
4208: my %answers = &Apache::lonnet::str2hash($value);
4209: my @anskeys = sort(keys(%answers));
4210: if (@anskeys == 1) {
4211: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4212: if ($answer =~ m{\0}) {
4213: $answer =~ s{\0}{,}g;
1.988 raeburn 4214: }
4215: my $tag_internal_answer_name = 'INTERNAL';
4216: if ($anskeys[0] eq $tag_internal_answer_name) {
4217: $value = $answer;
4218: } else {
4219: $value = $anskeys[0].'='.$answer;
4220: }
4221: } else {
4222: foreach my $ans (@anskeys) {
4223: my $answer = $answers{$ans};
1.1001 raeburn 4224: if ($answer =~ m{\0}) {
4225: $answer =~ s{\0}{,}g;
1.988 raeburn 4226: }
4227: $value .= $ans.'='.$answer.'<br />';;
4228: }
4229: }
1.581 albertel 4230: } else {
4231: $value = &unescape($value);
4232: }
4233: return $value;
4234: }
4235:
4236:
1.107 albertel 4237: sub relative_to_absolute {
4238: my ($url,$output)=@_;
4239: my $parser=HTML::TokeParser->new(\$output);
4240: my $token;
4241: my $thisdir=$url;
4242: my @rlinks=();
4243: while ($token=$parser->get_token) {
4244: if ($token->[0] eq 'S') {
4245: if ($token->[1] eq 'a') {
4246: if ($token->[2]->{'href'}) {
4247: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4248: }
4249: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4250: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4251: } elsif ($token->[1] eq 'base') {
4252: $thisdir=$token->[2]->{'href'};
4253: }
4254: }
4255: }
4256: $thisdir=~s-/[^/]*$--;
1.356 albertel 4257: foreach my $link (@rlinks) {
1.726 raeburn 4258: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4259: ($link=~/^\//) ||
4260: ($link=~/^javascript:/i) ||
4261: ($link=~/^mailto:/i) ||
4262: ($link=~/^\#/)) {
4263: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4264: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4265: }
4266: }
4267: # -------------------------------------------------- Deal with Applet codebases
4268: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4269: return $output;
4270: }
4271:
1.112 bowersj2 4272: =pod
4273:
1.648 raeburn 4274: =item * &get_student_view()
1.112 bowersj2 4275:
4276: show a snapshot of what student was looking at
4277:
4278: =cut
4279:
1.10 albertel 4280: sub get_student_view {
1.186 albertel 4281: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4282: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4283: my (%form);
1.10 albertel 4284: my @elements=('symb','courseid','domain','username');
4285: foreach my $element (@elements) {
1.186 albertel 4286: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4287: }
1.186 albertel 4288: if (defined($moreenv)) {
4289: %form=(%form,%{$moreenv});
4290: }
1.236 albertel 4291: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4292: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4293: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4294: $userview=~s/\<body[^\>]*\>//gi;
4295: $userview=~s/\<\/body\>//gi;
4296: $userview=~s/\<html\>//gi;
4297: $userview=~s/\<\/html\>//gi;
4298: $userview=~s/\<head\>//gi;
4299: $userview=~s/\<\/head\>//gi;
4300: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4301: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4302: if (wantarray) {
4303: return ($userview,$response);
4304: } else {
4305: return $userview;
4306: }
4307: }
4308:
4309: sub get_student_view_with_retries {
4310: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4311:
4312: my $ok = 0; # True if we got a good response.
4313: my $content;
4314: my $response;
4315:
4316: # Try to get the student_view done. within the retries count:
4317:
4318: do {
4319: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4320: $ok = $response->is_success;
4321: if (!$ok) {
4322: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4323: }
4324: $retries--;
4325: } while (!$ok && ($retries > 0));
4326:
4327: if (!$ok) {
4328: $content = ''; # On error return an empty content.
4329: }
1.651 www 4330: if (wantarray) {
4331: return ($content, $response);
4332: } else {
4333: return $content;
4334: }
1.11 albertel 4335: }
4336:
1.112 bowersj2 4337: =pod
4338:
1.648 raeburn 4339: =item * &get_student_answers()
1.112 bowersj2 4340:
4341: show a snapshot of how student was answering problem
4342:
4343: =cut
4344:
1.11 albertel 4345: sub get_student_answers {
1.100 sakharuk 4346: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4347: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4348: my (%moreenv);
1.11 albertel 4349: my @elements=('symb','courseid','domain','username');
4350: foreach my $element (@elements) {
1.186 albertel 4351: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4352: }
1.186 albertel 4353: $moreenv{'grade_target'}='answer';
4354: %moreenv=(%form,%moreenv);
1.497 raeburn 4355: $feedurl = &Apache::lonnet::clutter($feedurl);
4356: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4357: return $userview;
1.1 albertel 4358: }
1.116 albertel 4359:
4360: =pod
4361:
4362: =item * &submlink()
4363:
1.242 albertel 4364: Inputs: $text $uname $udom $symb $target
1.116 albertel 4365:
4366: Returns: A link to grades.pm such as to see the SUBM view of a student
4367:
4368: =cut
4369:
4370: ###############################################
4371: sub submlink {
1.242 albertel 4372: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4373: if (!($uname && $udom)) {
4374: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4375: &Apache::lonnet::whichuser($symb);
1.116 albertel 4376: if (!$symb) { $symb=$cursymb; }
4377: }
1.254 matthew 4378: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4379: $symb=&escape($symb);
1.960 bisitz 4380: if ($target) { $target=" target=\"$target\""; }
4381: return
4382: '<a href="/adm/grades?command=submission'.
4383: '&symb='.$symb.
4384: '&student='.$uname.
4385: '&userdom='.$udom.'"'.
4386: $target.'>'.$text.'</a>';
1.242 albertel 4387: }
4388: ##############################################
4389:
4390: =pod
4391:
4392: =item * &pgrdlink()
4393:
4394: Inputs: $text $uname $udom $symb $target
4395:
4396: Returns: A link to grades.pm such as to see the PGRD view of a student
4397:
4398: =cut
4399:
4400: ###############################################
4401: sub pgrdlink {
4402: my $link=&submlink(@_);
4403: $link=~s/(&command=submission)/$1&showgrading=yes/;
4404: return $link;
4405: }
4406: ##############################################
4407:
4408: =pod
4409:
4410: =item * &pprmlink()
4411:
4412: Inputs: $text $uname $udom $symb $target
4413:
4414: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4415: student and a specific resource
1.242 albertel 4416:
4417: =cut
4418:
4419: ###############################################
4420: sub pprmlink {
4421: my ($text,$uname,$udom,$symb,$target)=@_;
4422: if (!($uname && $udom)) {
4423: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4424: &Apache::lonnet::whichuser($symb);
1.242 albertel 4425: if (!$symb) { $symb=$cursymb; }
4426: }
1.254 matthew 4427: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4428: $symb=&escape($symb);
1.242 albertel 4429: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4430: return '<a href="/adm/parmset?command=set&'.
4431: 'symb='.$symb.'&uname='.$uname.
4432: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4433: }
4434: ##############################################
1.37 matthew 4435:
1.112 bowersj2 4436: =pod
4437:
4438: =back
4439:
4440: =cut
4441:
1.37 matthew 4442: ###############################################
1.51 www 4443:
4444:
4445: sub timehash {
1.687 raeburn 4446: my ($thistime) = @_;
4447: my $timezone = &Apache::lonlocal::gettimezone();
4448: my $dt = DateTime->from_epoch(epoch => $thistime)
4449: ->set_time_zone($timezone);
4450: my $wday = $dt->day_of_week();
4451: if ($wday == 7) { $wday = 0; }
4452: return ( 'second' => $dt->second(),
4453: 'minute' => $dt->minute(),
4454: 'hour' => $dt->hour(),
4455: 'day' => $dt->day_of_month(),
4456: 'month' => $dt->month(),
4457: 'year' => $dt->year(),
4458: 'weekday' => $wday,
4459: 'dayyear' => $dt->day_of_year(),
4460: 'dlsav' => $dt->is_dst() );
1.51 www 4461: }
4462:
1.370 www 4463: sub utc_string {
4464: my ($date)=@_;
1.371 www 4465: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4466: }
4467:
1.51 www 4468: sub maketime {
4469: my %th=@_;
1.687 raeburn 4470: my ($epoch_time,$timezone,$dt);
4471: $timezone = &Apache::lonlocal::gettimezone();
4472: eval {
4473: $dt = DateTime->new( year => $th{'year'},
4474: month => $th{'month'},
4475: day => $th{'day'},
4476: hour => $th{'hour'},
4477: minute => $th{'minute'},
4478: second => $th{'second'},
4479: time_zone => $timezone,
4480: );
4481: };
4482: if (!$@) {
4483: $epoch_time = $dt->epoch;
4484: if ($epoch_time) {
4485: return $epoch_time;
4486: }
4487: }
1.51 www 4488: return POSIX::mktime(
4489: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4490: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4491: }
4492:
4493: #########################################
1.51 www 4494:
4495: sub findallcourses {
1.482 raeburn 4496: my ($roles,$uname,$udom) = @_;
1.355 albertel 4497: my %roles;
4498: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4499: my %courses;
1.51 www 4500: my $now=time;
1.482 raeburn 4501: if (!defined($uname)) {
4502: $uname = $env{'user.name'};
4503: }
4504: if (!defined($udom)) {
4505: $udom = $env{'user.domain'};
4506: }
4507: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4508: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4509: if (!%roles) {
4510: %roles = (
4511: cc => 1,
1.907 raeburn 4512: co => 1,
1.482 raeburn 4513: in => 1,
4514: ep => 1,
4515: ta => 1,
4516: cr => 1,
4517: st => 1,
4518: );
4519: }
4520: foreach my $entry (keys(%roleshash)) {
4521: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4522: if ($trole =~ /^cr/) {
4523: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4524: } else {
4525: next if (!exists($roles{$trole}));
4526: }
4527: if ($tend) {
4528: next if ($tend < $now);
4529: }
4530: if ($tstart) {
4531: next if ($tstart > $now);
4532: }
1.1058 raeburn 4533: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4534: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4535: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4536: if ($secpart eq '') {
4537: ($cnum,$role) = split(/_/,$cnumpart);
4538: $sec = 'none';
1.1058 raeburn 4539: $value .= $cnum.'/';
1.482 raeburn 4540: } else {
4541: $cnum = $cnumpart;
4542: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4543: $value .= $cnum.'/'.$sec;
4544: }
4545: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4546: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4547: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4548: }
4549: } else {
4550: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4551: }
1.482 raeburn 4552: }
4553: } else {
4554: foreach my $key (keys(%env)) {
1.483 albertel 4555: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4556: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4557: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4558: next if ($role eq 'ca' || $role eq 'aa');
4559: next if (%roles && !exists($roles{$role}));
4560: my ($starttime,$endtime)=split(/\./,$env{$key});
4561: my $active=1;
4562: if ($starttime) {
4563: if ($now<$starttime) { $active=0; }
4564: }
4565: if ($endtime) {
4566: if ($now>$endtime) { $active=0; }
4567: }
4568: if ($active) {
1.1058 raeburn 4569: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4570: if ($sec eq '') {
4571: $sec = 'none';
1.1058 raeburn 4572: } else {
4573: $value .= $sec;
4574: }
4575: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4576: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4577: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4578: }
4579: } else {
4580: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4581: }
1.474 raeburn 4582: }
4583: }
1.51 www 4584: }
4585: }
1.474 raeburn 4586: return %courses;
1.51 www 4587: }
1.37 matthew 4588:
1.54 www 4589: ###############################################
1.474 raeburn 4590:
4591: sub blockcheck {
1.1075.2.73 raeburn 4592: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4593:
1.1075.2.73 raeburn 4594: if (defined($udom) && defined($uname)) {
4595: # If uname and udom are for a course, check for blocks in the course.
4596: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4597: my ($startblock,$endblock,$triggerblock) =
4598: &get_blocks($setters,$activity,$udom,$uname,$url);
4599: return ($startblock,$endblock,$triggerblock);
4600: }
4601: } else {
1.490 raeburn 4602: $udom = $env{'user.domain'};
4603: $uname = $env{'user.name'};
4604: }
4605:
1.502 raeburn 4606: my $startblock = 0;
4607: my $endblock = 0;
1.1062 raeburn 4608: my $triggerblock = '';
1.482 raeburn 4609: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4610:
1.490 raeburn 4611: # If uname is for a user, and activity is course-specific, i.e.,
4612: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4613:
1.490 raeburn 4614: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1075.2.73 raeburn 4615: $activity eq 'groups' || $activity eq 'printout') &&
4616: ($env{'request.course.id'})) {
1.490 raeburn 4617: foreach my $key (keys(%live_courses)) {
4618: if ($key ne $env{'request.course.id'}) {
4619: delete($live_courses{$key});
4620: }
4621: }
4622: }
4623:
4624: my $otheruser = 0;
4625: my %own_courses;
4626: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4627: # Resource belongs to user other than current user.
4628: $otheruser = 1;
4629: # Gather courses for current user
4630: %own_courses =
4631: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4632: }
4633:
4634: # Gather active course roles - course coordinator, instructor,
4635: # exam proctor, ta, student, or custom role.
1.474 raeburn 4636:
4637: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4638: my ($cdom,$cnum);
4639: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4640: $cdom = $env{'course.'.$course.'.domain'};
4641: $cnum = $env{'course.'.$course.'.num'};
4642: } else {
1.490 raeburn 4643: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4644: }
4645: my $no_ownblock = 0;
4646: my $no_userblock = 0;
1.533 raeburn 4647: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4648: # Check if current user has 'evb' priv for this
4649: if (defined($own_courses{$course})) {
4650: foreach my $sec (keys(%{$own_courses{$course}})) {
4651: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4652: if ($sec ne 'none') {
4653: $checkrole .= '/'.$sec;
4654: }
4655: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4656: $no_ownblock = 1;
4657: last;
4658: }
4659: }
4660: }
4661: # if they have 'evb' priv and are currently not playing student
4662: next if (($no_ownblock) &&
4663: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4664: }
1.474 raeburn 4665: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4666: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4667: if ($sec ne 'none') {
1.482 raeburn 4668: $checkrole .= '/'.$sec;
1.474 raeburn 4669: }
1.490 raeburn 4670: if ($otheruser) {
4671: # Resource belongs to user other than current user.
4672: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4673: my (%allroles,%userroles);
4674: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4675: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4676: my ($trole,$tdom,$tnum,$tsec);
4677: if ($entry =~ /^cr/) {
4678: ($trole,$tdom,$tnum,$tsec) =
4679: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4680: } else {
4681: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4682: }
4683: my ($spec,$area,$trest);
4684: $area = '/'.$tdom.'/'.$tnum;
4685: $trest = $tnum;
4686: if ($tsec ne '') {
4687: $area .= '/'.$tsec;
4688: $trest .= '/'.$tsec;
4689: }
4690: $spec = $trole.'.'.$area;
4691: if ($trole =~ /^cr/) {
4692: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4693: $tdom,$spec,$trest,$area);
4694: } else {
4695: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4696: $tdom,$spec,$trest,$area);
4697: }
4698: }
1.1075.2.124 raeburn 4699: my ($author,$adv,$rar) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
1.1058 raeburn 4700: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4701: if ($1) {
4702: $no_userblock = 1;
4703: last;
4704: }
1.486 raeburn 4705: }
4706: }
1.490 raeburn 4707: } else {
4708: # Resource belongs to current user
4709: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4710: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4711: $no_ownblock = 1;
4712: last;
4713: }
1.474 raeburn 4714: }
4715: }
4716: # if they have the evb priv and are currently not playing student
1.482 raeburn 4717: next if (($no_ownblock) &&
1.491 albertel 4718: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4719: next if ($no_userblock);
1.474 raeburn 4720:
1.866 kalberla 4721: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4722: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4723:
1.1062 raeburn 4724: my ($start,$end,$trigger) =
4725: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4726: if (($start != 0) &&
4727: (($startblock == 0) || ($startblock > $start))) {
4728: $startblock = $start;
1.1062 raeburn 4729: if ($trigger ne '') {
4730: $triggerblock = $trigger;
4731: }
1.502 raeburn 4732: }
4733: if (($end != 0) &&
4734: (($endblock == 0) || ($endblock < $end))) {
4735: $endblock = $end;
1.1062 raeburn 4736: if ($trigger ne '') {
4737: $triggerblock = $trigger;
4738: }
1.502 raeburn 4739: }
1.490 raeburn 4740: }
1.1062 raeburn 4741: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4742: }
4743:
4744: sub get_blocks {
1.1062 raeburn 4745: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4746: my $startblock = 0;
4747: my $endblock = 0;
1.1062 raeburn 4748: my $triggerblock = '';
1.490 raeburn 4749: my $course = $cdom.'_'.$cnum;
4750: $setters->{$course} = {};
4751: $setters->{$course}{'staff'} = [];
4752: $setters->{$course}{'times'} = [];
1.1062 raeburn 4753: $setters->{$course}{'triggers'} = [];
4754: my (@blockers,%triggered);
4755: my $now = time;
4756: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4757: if ($activity eq 'docs') {
4758: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4759: foreach my $block (@blockers) {
4760: if ($block =~ /^firstaccess____(.+)$/) {
4761: my $item = $1;
4762: my $type = 'map';
4763: my $timersymb = $item;
4764: if ($item eq 'course') {
4765: $type = 'course';
4766: } elsif ($item =~ /___\d+___/) {
4767: $type = 'resource';
4768: } else {
4769: $timersymb = &Apache::lonnet::symbread($item);
4770: }
4771: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4772: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4773: $triggered{$block} = {
4774: start => $start,
4775: end => $end,
4776: type => $type,
4777: };
4778: }
4779: }
4780: } else {
4781: foreach my $block (keys(%commblocks)) {
4782: if ($block =~ m/^(\d+)____(\d+)$/) {
4783: my ($start,$end) = ($1,$2);
4784: if ($start <= time && $end >= time) {
4785: if (ref($commblocks{$block}) eq 'HASH') {
4786: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4787: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4788: unless(grep(/^\Q$block\E$/,@blockers)) {
4789: push(@blockers,$block);
4790: }
4791: }
4792: }
4793: }
4794: }
4795: } elsif ($block =~ /^firstaccess____(.+)$/) {
4796: my $item = $1;
4797: my $timersymb = $item;
4798: my $type = 'map';
4799: if ($item eq 'course') {
4800: $type = 'course';
4801: } elsif ($item =~ /___\d+___/) {
4802: $type = 'resource';
4803: } else {
4804: $timersymb = &Apache::lonnet::symbread($item);
4805: }
4806: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4807: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4808: if ($start && $end) {
4809: if (($start <= time) && ($end >= time)) {
4810: unless (grep(/^\Q$block\E$/,@blockers)) {
4811: push(@blockers,$block);
4812: $triggered{$block} = {
4813: start => $start,
4814: end => $end,
4815: type => $type,
4816: };
4817: }
4818: }
1.490 raeburn 4819: }
1.1062 raeburn 4820: }
4821: }
4822: }
4823: foreach my $blocker (@blockers) {
4824: my ($staff_name,$staff_dom,$title,$blocks) =
4825: &parse_block_record($commblocks{$blocker});
4826: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4827: my ($start,$end,$triggertype);
4828: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4829: ($start,$end) = ($1,$2);
4830: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4831: $start = $triggered{$blocker}{'start'};
4832: $end = $triggered{$blocker}{'end'};
4833: $triggertype = $triggered{$blocker}{'type'};
4834: }
4835: if ($start) {
4836: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4837: if ($triggertype) {
4838: push(@{$$setters{$course}{'triggers'}},$triggertype);
4839: } else {
4840: push(@{$$setters{$course}{'triggers'}},0);
4841: }
4842: if ( ($startblock == 0) || ($startblock > $start) ) {
4843: $startblock = $start;
4844: if ($triggertype) {
4845: $triggerblock = $blocker;
1.474 raeburn 4846: }
4847: }
1.1062 raeburn 4848: if ( ($endblock == 0) || ($endblock < $end) ) {
4849: $endblock = $end;
4850: if ($triggertype) {
4851: $triggerblock = $blocker;
4852: }
4853: }
1.474 raeburn 4854: }
4855: }
1.1062 raeburn 4856: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4857: }
4858:
4859: sub parse_block_record {
4860: my ($record) = @_;
4861: my ($setuname,$setudom,$title,$blocks);
4862: if (ref($record) eq 'HASH') {
4863: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4864: $title = &unescape($record->{'event'});
4865: $blocks = $record->{'blocks'};
4866: } else {
4867: my @data = split(/:/,$record,3);
4868: if (scalar(@data) eq 2) {
4869: $title = $data[1];
4870: ($setuname,$setudom) = split(/@/,$data[0]);
4871: } else {
4872: ($setuname,$setudom,$title) = @data;
4873: }
4874: $blocks = { 'com' => 'on' };
4875: }
4876: return ($setuname,$setudom,$title,$blocks);
4877: }
4878:
1.854 kalberla 4879: sub blocking_status {
1.1075.2.73 raeburn 4880: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 4881: my %setters;
1.890 droeschl 4882:
1.1061 raeburn 4883: # check for active blocking
1.1062 raeburn 4884: my ($startblock,$endblock,$triggerblock) =
1.1075.2.73 raeburn 4885: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 4886: my $blocked = 0;
4887: if ($startblock && $endblock) {
4888: $blocked = 1;
4889: }
1.890 droeschl 4890:
1.1061 raeburn 4891: # caller just wants to know whether a block is active
4892: if (!wantarray) { return $blocked; }
4893:
4894: # build a link to a popup window containing the details
4895: my $querystring = "?activity=$activity";
4896: # $uname and $udom decide whose portfolio the user is trying to look at
1.1075.2.97 raeburn 4897: if (($activity eq 'port') || ($activity eq 'passwd')) {
4898: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
4899: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 4900: } elsif ($activity eq 'docs') {
4901: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4902: }
1.1061 raeburn 4903:
4904: my $output .= <<'END_MYBLOCK';
4905: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4906: var options = "width=" + w + ",height=" + h + ",";
4907: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4908: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4909: var newWin = window.open(url, wdwName, options);
4910: newWin.focus();
4911: }
1.890 droeschl 4912: END_MYBLOCK
1.854 kalberla 4913:
1.1061 raeburn 4914: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4915:
1.1061 raeburn 4916: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4917: my $text = &mt('Communication Blocked');
1.1075.2.93 raeburn 4918: my $class = 'LC_comblock';
1.1062 raeburn 4919: if ($activity eq 'docs') {
4920: $text = &mt('Content Access Blocked');
1.1075.2.93 raeburn 4921: $class = '';
1.1063 raeburn 4922: } elsif ($activity eq 'printout') {
4923: $text = &mt('Printing Blocked');
1.1075.2.97 raeburn 4924: } elsif ($activity eq 'passwd') {
4925: $text = &mt('Password Changing Blocked');
1.1062 raeburn 4926: }
1.1061 raeburn 4927: $output .= <<"END_BLOCK";
1.1075.2.93 raeburn 4928: <div class='$class'>
1.869 kalberla 4929: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4930: title='$text'>
4931: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4932: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4933: title='$text'>$text</a>
1.867 kalberla 4934: </div>
4935:
4936: END_BLOCK
1.474 raeburn 4937:
1.1061 raeburn 4938: return ($blocked, $output);
1.854 kalberla 4939: }
1.490 raeburn 4940:
1.60 matthew 4941: ###############################################
4942:
1.682 raeburn 4943: sub check_ip_acc {
1.1075.2.105 raeburn 4944: my ($acc,$clientip)=@_;
1.682 raeburn 4945: &Apache::lonxml::debug("acc is $acc");
4946: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4947: return 1;
4948: }
4949: my $allowed=0;
1.1075.2.111 raeburn 4950: my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682 raeburn 4951:
4952: my $name;
4953: foreach my $pattern (split(',',$acc)) {
4954: $pattern =~ s/^\s*//;
4955: $pattern =~ s/\s*$//;
4956: if ($pattern =~ /\*$/) {
4957: #35.8.*
4958: $pattern=~s/\*//;
4959: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4960: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4961: #35.8.3.[34-56]
4962: my $low=$2;
4963: my $high=$3;
4964: $pattern=$1;
4965: if ($ip =~ /^\Q$pattern\E/) {
4966: my $last=(split(/\./,$ip))[3];
4967: if ($last <=$high && $last >=$low) { $allowed=1; }
4968: }
4969: } elsif ($pattern =~ /^\*/) {
4970: #*.msu.edu
4971: $pattern=~s/\*//;
4972: if (!defined($name)) {
4973: use Socket;
4974: my $netaddr=inet_aton($ip);
4975: ($name)=gethostbyaddr($netaddr,AF_INET);
4976: }
4977: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4978: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4979: #127.0.0.1
4980: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4981: } else {
4982: #some.name.com
4983: if (!defined($name)) {
4984: use Socket;
4985: my $netaddr=inet_aton($ip);
4986: ($name)=gethostbyaddr($netaddr,AF_INET);
4987: }
4988: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4989: }
4990: if ($allowed) { last; }
4991: }
4992: return $allowed;
4993: }
4994:
4995: ###############################################
4996:
1.60 matthew 4997: =pod
4998:
1.112 bowersj2 4999: =head1 Domain Template Functions
5000:
5001: =over 4
5002:
5003: =item * &determinedomain()
1.60 matthew 5004:
5005: Inputs: $domain (usually will be undef)
5006:
1.63 www 5007: Returns: Determines which domain should be used for designs
1.60 matthew 5008:
5009: =cut
1.54 www 5010:
1.60 matthew 5011: ###############################################
1.63 www 5012: sub determinedomain {
5013: my $domain=shift;
1.531 albertel 5014: if (! $domain) {
1.60 matthew 5015: # Determine domain if we have not been given one
1.893 raeburn 5016: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5017: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5018: if ($env{'request.role.domain'}) {
5019: $domain=$env{'request.role.domain'};
1.60 matthew 5020: }
5021: }
1.63 www 5022: return $domain;
5023: }
5024: ###############################################
1.517 raeburn 5025:
1.518 albertel 5026: sub devalidate_domconfig_cache {
5027: my ($udom)=@_;
5028: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5029: }
5030:
5031: # ---------------------- Get domain configuration for a domain
5032: sub get_domainconf {
5033: my ($udom) = @_;
5034: my $cachetime=1800;
5035: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5036: if (defined($cached)) { return %{$result}; }
5037:
5038: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5039: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5040: my (%designhash,%legacy);
1.518 albertel 5041: if (keys(%domconfig) > 0) {
5042: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5043: if (keys(%{$domconfig{'login'}})) {
5044: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5045: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 5046: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5047: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5048: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5049: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5050: if ($key eq 'loginvia') {
5051: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5052: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5053: $designhash{$udom.'.login.loginvia'} = $server;
5054: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5055: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5056: } else {
5057: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5058: }
1.948 raeburn 5059: }
1.1075.2.87 raeburn 5060: } elsif ($key eq 'headtag') {
5061: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5062: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5063: }
1.946 raeburn 5064: }
1.1075.2.87 raeburn 5065: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5066: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5067: }
1.946 raeburn 5068: }
5069: }
5070: }
5071: } else {
5072: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5073: $designhash{$udom.'.login.'.$key.'_'.$img} =
5074: $domconfig{'login'}{$key}{$img};
5075: }
1.699 raeburn 5076: }
5077: } else {
5078: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5079: }
1.632 raeburn 5080: }
5081: } else {
5082: $legacy{'login'} = 1;
1.518 albertel 5083: }
1.632 raeburn 5084: } else {
5085: $legacy{'login'} = 1;
1.518 albertel 5086: }
5087: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5088: if (keys(%{$domconfig{'rolecolors'}})) {
5089: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5090: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5091: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5092: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5093: }
1.518 albertel 5094: }
5095: }
1.632 raeburn 5096: } else {
5097: $legacy{'rolecolors'} = 1;
1.518 albertel 5098: }
1.632 raeburn 5099: } else {
5100: $legacy{'rolecolors'} = 1;
1.518 albertel 5101: }
1.948 raeburn 5102: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5103: if ($domconfig{'autoenroll'}{'co-owners'}) {
5104: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5105: }
5106: }
1.632 raeburn 5107: if (keys(%legacy) > 0) {
5108: my %legacyhash = &get_legacy_domconf($udom);
5109: foreach my $item (keys(%legacyhash)) {
5110: if ($item =~ /^\Q$udom\E\.login/) {
5111: if ($legacy{'login'}) {
5112: $designhash{$item} = $legacyhash{$item};
5113: }
5114: } else {
5115: if ($legacy{'rolecolors'}) {
5116: $designhash{$item} = $legacyhash{$item};
5117: }
1.518 albertel 5118: }
5119: }
5120: }
1.632 raeburn 5121: } else {
5122: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5123: }
5124: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5125: $cachetime);
5126: return %designhash;
5127: }
5128:
1.632 raeburn 5129: sub get_legacy_domconf {
5130: my ($udom) = @_;
5131: my %legacyhash;
5132: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5133: my $designfile = $designdir.'/'.$udom.'.tab';
5134: if (-e $designfile) {
5135: if ( open (my $fh,"<$designfile") ) {
5136: while (my $line = <$fh>) {
5137: next if ($line =~ /^\#/);
5138: chomp($line);
5139: my ($key,$val)=(split(/\=/,$line));
5140: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5141: }
5142: close($fh);
5143: }
5144: }
1.1026 raeburn 5145: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5146: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5147: }
5148: return %legacyhash;
5149: }
5150:
1.63 www 5151: =pod
5152:
1.112 bowersj2 5153: =item * &domainlogo()
1.63 www 5154:
5155: Inputs: $domain (usually will be undef)
5156:
5157: Returns: A link to a domain logo, if the domain logo exists.
5158: If the domain logo does not exist, a description of the domain.
5159:
5160: =cut
1.112 bowersj2 5161:
1.63 www 5162: ###############################################
5163: sub domainlogo {
1.517 raeburn 5164: my $domain = &determinedomain(shift);
1.518 albertel 5165: my %designhash = &get_domainconf($domain);
1.517 raeburn 5166: # See if there is a logo
5167: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5168: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5169: if ($imgsrc =~ m{^/(adm|res)/}) {
5170: if ($imgsrc =~ m{^/res/}) {
5171: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5172: &Apache::lonnet::repcopy($local_name);
5173: }
5174: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5175: }
5176: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5177: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5178: return &Apache::lonnet::domain($domain,'description');
1.59 www 5179: } else {
1.60 matthew 5180: return '';
1.59 www 5181: }
5182: }
1.63 www 5183: ##############################################
5184:
5185: =pod
5186:
1.112 bowersj2 5187: =item * &designparm()
1.63 www 5188:
5189: Inputs: $which parameter; $domain (usually will be undef)
5190:
5191: Returns: value of designparamter $which
5192:
5193: =cut
1.112 bowersj2 5194:
1.397 albertel 5195:
1.400 albertel 5196: ##############################################
1.397 albertel 5197: sub designparm {
5198: my ($which,$domain)=@_;
5199: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5200: return $env{'environment.color.'.$which};
1.96 www 5201: }
1.63 www 5202: $domain=&determinedomain($domain);
1.1016 raeburn 5203: my %domdesign;
5204: unless ($domain eq 'public') {
5205: %domdesign = &get_domainconf($domain);
5206: }
1.520 raeburn 5207: my $output;
1.517 raeburn 5208: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5209: $output = $domdesign{$domain.'.'.$which};
1.63 www 5210: } else {
1.520 raeburn 5211: $output = $defaultdesign{$which};
5212: }
5213: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5214: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5215: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5216: if ($output =~ m{^/res/}) {
5217: my $local_name = &Apache::lonnet::filelocation('',$output);
5218: &Apache::lonnet::repcopy($local_name);
5219: }
1.520 raeburn 5220: $output = &lonhttpdurl($output);
5221: }
1.63 www 5222: }
1.520 raeburn 5223: return $output;
1.63 www 5224: }
1.59 www 5225:
1.822 bisitz 5226: ##############################################
5227: =pod
5228:
1.832 bisitz 5229: =item * &authorspace()
5230:
1.1028 raeburn 5231: Inputs: $url (usually will be undef).
1.832 bisitz 5232:
1.1075.2.40 raeburn 5233: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5234: directory being viewed (or for which action is being taken).
5235: If $url is provided, and begins /priv/<domain>/<uname>
5236: the path will be that portion of the $context argument.
5237: Otherwise the path will be for the author space of the current
5238: user when the current role is author, or for that of the
5239: co-author/assistant co-author space when the current role
5240: is co-author or assistant co-author.
1.832 bisitz 5241:
5242: =cut
5243:
5244: sub authorspace {
1.1028 raeburn 5245: my ($url) = @_;
5246: if ($url ne '') {
5247: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5248: return $1;
5249: }
5250: }
1.832 bisitz 5251: my $caname = '';
1.1024 www 5252: my $cadom = '';
1.1028 raeburn 5253: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5254: ($cadom,$caname) =
1.832 bisitz 5255: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5256: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5257: $caname = $env{'user.name'};
1.1024 www 5258: $cadom = $env{'user.domain'};
1.832 bisitz 5259: }
1.1028 raeburn 5260: if (($caname ne '') && ($cadom ne '')) {
5261: return "/priv/$cadom/$caname/";
5262: }
5263: return;
1.832 bisitz 5264: }
5265:
5266: ##############################################
5267: =pod
5268:
1.822 bisitz 5269: =item * &head_subbox()
5270:
5271: Inputs: $content (contains HTML code with page functions, etc.)
5272:
5273: Returns: HTML div with $content
5274: To be included in page header
5275:
5276: =cut
5277:
5278: sub head_subbox {
5279: my ($content)=@_;
5280: my $output =
1.993 raeburn 5281: '<div class="LC_head_subbox">'
1.822 bisitz 5282: .$content
5283: .'</div>'
5284: }
5285:
5286: ##############################################
5287: =pod
5288:
5289: =item * &CSTR_pageheader()
5290:
1.1026 raeburn 5291: Input: (optional) filename from which breadcrumb trail is built.
5292: In most cases no input as needed, as $env{'request.filename'}
5293: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5294:
5295: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5296: To be included on Authoring Space pages
1.822 bisitz 5297:
5298: =cut
5299:
5300: sub CSTR_pageheader {
1.1026 raeburn 5301: my ($trailfile) = @_;
5302: if ($trailfile eq '') {
5303: $trailfile = $env{'request.filename'};
5304: }
5305:
5306: # this is for resources; directories have customtitle, and crumbs
5307: # and select recent are created in lonpubdir.pm
5308:
5309: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5310: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5311: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5312: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5313: $formaction =~ s{/+}{/}g;
1.822 bisitz 5314:
5315: my $parentpath = '';
5316: my $lastitem = '';
5317: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5318: $parentpath = $1;
5319: $lastitem = $2;
5320: } else {
5321: $lastitem = $thisdisfn;
5322: }
1.921 bisitz 5323:
5324: my $output =
1.822 bisitz 5325: '<div>'
5326: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5327: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5328: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5329: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5330: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5331:
5332: if ($lastitem) {
5333: $output .=
5334: '<span class="LC_filename">'
5335: .$lastitem
5336: .'</span>';
5337: }
5338: $output .=
5339: '<br />'
1.822 bisitz 5340: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5341: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5342: .'</form>'
5343: .&Apache::lonmenu::constspaceform()
5344: .'</div>';
1.921 bisitz 5345:
5346: return $output;
1.822 bisitz 5347: }
5348:
1.60 matthew 5349: ###############################################
5350: ###############################################
5351:
5352: =pod
5353:
1.112 bowersj2 5354: =back
5355:
1.549 albertel 5356: =head1 HTML Helpers
1.112 bowersj2 5357:
5358: =over 4
5359:
5360: =item * &bodytag()
1.60 matthew 5361:
5362: Returns a uniform header for LON-CAPA web pages.
5363:
5364: Inputs:
5365:
1.112 bowersj2 5366: =over 4
5367:
5368: =item * $title, A title to be displayed on the page.
5369:
5370: =item * $function, the current role (can be undef).
5371:
5372: =item * $addentries, extra parameters for the <body> tag.
5373:
5374: =item * $bodyonly, if defined, only return the <body> tag.
5375:
5376: =item * $domain, if defined, force a given domain.
5377:
5378: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5379: text interface only)
1.60 matthew 5380:
1.814 bisitz 5381: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5382: navigational links
1.317 albertel 5383:
1.338 albertel 5384: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5385:
1.1075.2.12 raeburn 5386: =item * $no_inline_link, if true and in remote mode, don't show the
5387: 'Switch To Inline Menu' link
5388:
1.460 albertel 5389: =item * $args, optional argument valid values are
5390: no_auto_mt_title -> prevents &mt()ing the title arg
5391:
1.1075.2.15 raeburn 5392: =item * $advtoolsref, optional argument, ref to an array containing
5393: inlineremote items to be added in "Functions" menu below
5394: breadcrumbs.
5395:
1.112 bowersj2 5396: =back
5397:
1.60 matthew 5398: Returns: A uniform header for LON-CAPA web pages.
5399: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5400: If $bodyonly is undef or zero, an html string containing a <body> tag and
5401: other decorations will be returned.
5402:
5403: =cut
5404:
1.54 www 5405: sub bodytag {
1.831 bisitz 5406: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5407: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5408:
1.954 raeburn 5409: my $public;
5410: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5411: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5412: $public = 1;
5413: }
1.460 albertel 5414: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5415: my $httphost = $args->{'use_absolute'};
1.339 albertel 5416:
1.183 matthew 5417: $function = &get_users_function() if (!$function);
1.339 albertel 5418: my $img = &designparm($function.'.img',$domain);
5419: my $font = &designparm($function.'.font',$domain);
5420: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5421:
1.803 bisitz 5422: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5423: 'bgcolor' => $pgbg,
1.339 albertel 5424: 'text' => $font,
5425: 'alink' => &designparm($function.'.alink',$domain),
5426: 'vlink' => &designparm($function.'.vlink',$domain),
5427: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5428: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5429:
1.63 www 5430: # role and realm
1.1075.2.68 raeburn 5431: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5432: if ($realm) {
5433: $realm = '/'.$realm;
5434: }
1.378 raeburn 5435: if ($role eq 'ca') {
1.479 albertel 5436: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5437: $realm = &plainname($rname,$rdom);
1.378 raeburn 5438: }
1.55 www 5439: # realm
1.258 albertel 5440: if ($env{'request.course.id'}) {
1.378 raeburn 5441: if ($env{'request.role'} !~ /^cr/) {
5442: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115 raeburn 5443: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1075.2.121 raeburn 5444: if ($env{'request.role.desc'}) {
5445: $role = $env{'request.role.desc'};
5446: } else {
5447: $role = &mt('Helpdesk[_1]',' '.$2);
5448: }
1.1075.2.115 raeburn 5449: } else {
5450: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5451: }
1.898 raeburn 5452: if ($env{'request.course.sec'}) {
5453: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5454: }
1.359 albertel 5455: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5456: } else {
5457: $role = &Apache::lonnet::plaintext($role);
1.54 www 5458: }
1.433 albertel 5459:
1.359 albertel 5460: if (!$realm) { $realm=' '; }
1.330 albertel 5461:
1.438 albertel 5462: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5463:
1.101 www 5464: # construct main body tag
1.359 albertel 5465: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 5466: &Apache::lontexconvert::init_math_support();
1.252 albertel 5467:
1.1075.2.38 raeburn 5468: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5469:
5470: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5471: return $bodytag;
1.1075.2.38 raeburn 5472: }
1.359 albertel 5473:
1.954 raeburn 5474: if ($public) {
1.433 albertel 5475: undef($role);
5476: }
1.359 albertel 5477:
1.762 bisitz 5478: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5479: #
5480: # Extra info if you are the DC
5481: my $dc_info = '';
5482: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5483: $env{'course.'.$env{'request.course.id'}.
5484: '.domain'}.'/'})) {
5485: my $cid = $env{'request.course.id'};
1.917 raeburn 5486: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5487: $dc_info =~ s/\s+$//;
1.359 albertel 5488: }
5489:
1.1075.2.108 raeburn 5490: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 5491:
1.1075.2.13 raeburn 5492: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5493:
1.1075.2.38 raeburn 5494:
5495:
1.1075.2.21 raeburn 5496: my $funclist;
5497: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5498: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5499: Apache::lonmenu::serverform();
5500: my $forbodytag;
5501: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5502: $forcereg,$args->{'group'},
5503: $args->{'bread_crumbs'},
5504: $advtoolsref,'',\$forbodytag);
5505: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5506: $funclist = $forbodytag;
5507: }
5508: } else {
1.903 droeschl 5509:
5510: # if ($env{'request.state'} eq 'construct') {
5511: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5512: # }
5513:
1.1075.2.38 raeburn 5514: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5515: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5516:
1.1075.2.38 raeburn 5517: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5518:
1.916 droeschl 5519: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5520: if ($dc_info) {
5521: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5522: }
1.1075.2.38 raeburn 5523: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5524: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5525: return $bodytag;
5526: }
1.894 droeschl 5527:
1.927 raeburn 5528: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5529: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5530: }
1.916 droeschl 5531:
1.1075.2.38 raeburn 5532: $bodytag .= $right;
1.852 droeschl 5533:
1.917 raeburn 5534: if ($dc_info) {
5535: $dc_info = &dc_courseid_toggle($dc_info);
5536: }
5537: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5538:
1.1075.2.61 raeburn 5539: #if directed to not display the secondary menu, don't.
5540: if ($args->{'no_secondary_menu'}) {
5541: return $bodytag;
5542: }
1.903 droeschl 5543: #don't show menus for public users
1.954 raeburn 5544: if (!$public){
1.1075.2.52 raeburn 5545: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5546: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5547: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5548: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5549: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5550: $args->{'bread_crumbs'});
1.1075.2.116 raeburn 5551: } elsif ($forcereg) {
1.1075.2.22 raeburn 5552: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.116 raeburn 5553: $args->{'group'},
5554: $args->{'hide_buttons'});
1.1075.2.15 raeburn 5555: } else {
1.1075.2.21 raeburn 5556: my $forbodytag;
5557: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5558: $forcereg,$args->{'group'},
5559: $args->{'bread_crumbs'},
5560: $advtoolsref,'',\$forbodytag);
5561: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5562: $bodytag .= $forbodytag;
5563: }
1.920 raeburn 5564: }
1.903 droeschl 5565: }else{
5566: # this is to seperate menu from content when there's no secondary
5567: # menu. Especially needed for public accessible ressources.
5568: $bodytag .= '<hr style="clear:both" />';
5569: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5570: }
1.903 droeschl 5571:
1.235 raeburn 5572: return $bodytag;
1.1075.2.12 raeburn 5573: }
5574:
5575: #
5576: # Top frame rendering, Remote is up
5577: #
5578:
5579: my $imgsrc = $img;
5580: if ($img =~ /^\/adm/) {
5581: $imgsrc = &lonhttpdurl($img);
5582: }
5583: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5584:
1.1075.2.60 raeburn 5585: my $help=($no_inline_link?''
5586: :&Apache::loncommon::top_nav_help('Help'));
5587:
1.1075.2.12 raeburn 5588: # Explicit link to get inline menu
5589: my $menu= ($no_inline_link?''
5590: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5591:
5592: if ($dc_info) {
5593: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5594: }
5595:
1.1075.2.38 raeburn 5596: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5597: unless ($public) {
5598: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5599: undef,'LC_menubuttons_link');
5600: }
5601:
1.1075.2.12 raeburn 5602: unless ($env{'form.inhibitmenu'}) {
5603: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5604: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5605: <li>$help</li>
1.1075.2.12 raeburn 5606: <li>$menu</li>
5607: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5608: }
1.1075.2.13 raeburn 5609: if ($env{'request.state'} eq 'construct') {
5610: if (!$public){
5611: if ($env{'request.state'} eq 'construct') {
5612: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5613: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5614: &Apache::lonhtmlcommon::scripttag('','end').
5615: &Apache::lonmenu::innerregister($forcereg,
5616: $args->{'bread_crumbs'});
5617: }
5618: }
5619: }
1.1075.2.21 raeburn 5620: return $bodytag."\n".$funclist;
1.182 matthew 5621: }
5622:
1.917 raeburn 5623: sub dc_courseid_toggle {
5624: my ($dc_info) = @_;
1.980 raeburn 5625: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5626: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5627: &mt('(More ...)').'</a></span>'.
5628: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5629: }
5630:
1.330 albertel 5631: sub make_attr_string {
5632: my ($register,$attr_ref) = @_;
5633:
5634: if ($attr_ref && !ref($attr_ref)) {
5635: die("addentries Must be a hash ref ".
5636: join(':',caller(1))." ".
5637: join(':',caller(0))." ");
5638: }
5639:
5640: if ($register) {
1.339 albertel 5641: my ($on_load,$on_unload);
5642: foreach my $key (keys(%{$attr_ref})) {
5643: if (lc($key) eq 'onload') {
5644: $on_load.=$attr_ref->{$key}.';';
5645: delete($attr_ref->{$key});
5646:
5647: } elsif (lc($key) eq 'onunload') {
5648: $on_unload.=$attr_ref->{$key}.';';
5649: delete($attr_ref->{$key});
5650: }
5651: }
1.1075.2.12 raeburn 5652: if ($env{'environment.remote'} eq 'on') {
5653: $attr_ref->{'onload'} =
5654: &Apache::lonmenu::loadevents(). $on_load;
5655: $attr_ref->{'onunload'}=
5656: &Apache::lonmenu::unloadevents().$on_unload;
5657: } else {
5658: $attr_ref->{'onload'} = $on_load;
5659: $attr_ref->{'onunload'}= $on_unload;
5660: }
1.330 albertel 5661: }
1.339 albertel 5662:
1.330 albertel 5663: my $attr_string;
1.1075.2.56 raeburn 5664: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5665: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5666: }
5667: return $attr_string;
5668: }
5669:
5670:
1.182 matthew 5671: ###############################################
1.251 albertel 5672: ###############################################
5673:
5674: =pod
5675:
5676: =item * &endbodytag()
5677:
5678: Returns a uniform footer for LON-CAPA web pages.
5679:
1.635 raeburn 5680: Inputs: 1 - optional reference to an args hash
5681: If in the hash, key for noredirectlink has a value which evaluates to true,
5682: a 'Continue' link is not displayed if the page contains an
5683: internal redirect in the <head></head> section,
5684: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5685:
5686: =cut
5687:
5688: sub endbodytag {
1.635 raeburn 5689: my ($args) = @_;
1.1075.2.6 raeburn 5690: my $endbodytag;
5691: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5692: $endbodytag='</body>';
5693: }
1.315 albertel 5694: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5695: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5696: $endbodytag=
5697: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5698: &mt('Continue').'</a>'.
5699: $endbodytag;
5700: }
1.315 albertel 5701: }
1.251 albertel 5702: return $endbodytag;
5703: }
5704:
1.352 albertel 5705: =pod
5706:
5707: =item * &standard_css()
5708:
5709: Returns a style sheet
5710:
5711: Inputs: (all optional)
5712: domain -> force to color decorate a page for a specific
5713: domain
5714: function -> force usage of a specific rolish color scheme
5715: bgcolor -> override the default page bgcolor
5716:
5717: =cut
5718:
1.343 albertel 5719: sub standard_css {
1.345 albertel 5720: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5721: $function = &get_users_function() if (!$function);
5722: my $img = &designparm($function.'.img', $domain);
5723: my $tabbg = &designparm($function.'.tabbg', $domain);
5724: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5725: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5726: #second colour for later usage
1.345 albertel 5727: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5728: my $pgbg_or_bgcolor =
5729: $bgcolor ||
1.352 albertel 5730: &designparm($function.'.pgbg', $domain);
1.382 albertel 5731: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5732: my $alink = &designparm($function.'.alink', $domain);
5733: my $vlink = &designparm($function.'.vlink', $domain);
5734: my $link = &designparm($function.'.link', $domain);
5735:
1.602 albertel 5736: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5737: my $mono = 'monospace';
1.850 bisitz 5738: my $data_table_head = $sidebg;
5739: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5740: my $data_table_dark = '#E0E0E0';
1.470 banghart 5741: my $data_table_darker = '#CCCCCC';
1.349 albertel 5742: my $data_table_highlight = '#FFFF00';
1.352 albertel 5743: my $mail_new = '#FFBB77';
5744: my $mail_new_hover = '#DD9955';
5745: my $mail_read = '#BBBB77';
5746: my $mail_read_hover = '#999944';
5747: my $mail_replied = '#AAAA88';
5748: my $mail_replied_hover = '#888855';
5749: my $mail_other = '#99BBBB';
5750: my $mail_other_hover = '#669999';
1.391 albertel 5751: my $table_header = '#DDDDDD';
1.489 raeburn 5752: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5753: my $lg_border_color = '#C8C8C8';
1.952 onken 5754: my $button_hover = '#BF2317';
1.392 albertel 5755:
1.608 albertel 5756: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5757: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5758: : '0 3px 0 4px';
1.448 albertel 5759:
1.523 albertel 5760:
1.343 albertel 5761: return <<END;
1.947 droeschl 5762:
5763: /* needed for iframe to allow 100% height in FF */
5764: body, html {
5765: margin: 0;
5766: padding: 0 0.5%;
5767: height: 99%; /* to avoid scrollbars */
5768: }
5769:
1.795 www 5770: body {
1.911 bisitz 5771: font-family: $sans;
5772: line-height:130%;
5773: font-size:0.83em;
5774: color:$font;
1.795 www 5775: }
5776:
1.959 onken 5777: a:focus,
5778: a:focus img {
1.795 www 5779: color: red;
5780: }
1.698 harmsja 5781:
1.911 bisitz 5782: form, .inline {
5783: display: inline;
1.795 www 5784: }
1.721 harmsja 5785:
1.795 www 5786: .LC_right {
1.911 bisitz 5787: text-align:right;
1.795 www 5788: }
5789:
5790: .LC_middle {
1.911 bisitz 5791: vertical-align:middle;
1.795 www 5792: }
1.721 harmsja 5793:
1.1075.2.38 raeburn 5794: .LC_floatleft {
5795: float: left;
5796: }
5797:
5798: .LC_floatright {
5799: float: right;
5800: }
5801:
1.911 bisitz 5802: .LC_400Box {
5803: width:400px;
5804: }
1.721 harmsja 5805:
1.947 droeschl 5806: .LC_iframecontainer {
5807: width: 98%;
5808: margin: 0;
5809: position: fixed;
5810: top: 8.5em;
5811: bottom: 0;
5812: }
5813:
5814: .LC_iframecontainer iframe{
5815: border: none;
5816: width: 100%;
5817: height: 100%;
5818: }
5819:
1.778 bisitz 5820: .LC_filename {
5821: font-family: $mono;
5822: white-space:pre;
1.921 bisitz 5823: font-size: 120%;
1.778 bisitz 5824: }
5825:
5826: .LC_fileicon {
5827: border: none;
5828: height: 1.3em;
5829: vertical-align: text-bottom;
5830: margin-right: 0.3em;
5831: text-decoration:none;
5832: }
5833:
1.1008 www 5834: .LC_setting {
5835: text-decoration:underline;
5836: }
5837:
1.350 albertel 5838: .LC_error {
5839: color: red;
5840: }
1.795 www 5841:
1.1075.2.15 raeburn 5842: .LC_warning {
5843: color: darkorange;
5844: }
5845:
1.457 albertel 5846: .LC_diff_removed {
1.733 bisitz 5847: color: red;
1.394 albertel 5848: }
1.532 albertel 5849:
5850: .LC_info,
1.457 albertel 5851: .LC_success,
5852: .LC_diff_added {
1.350 albertel 5853: color: green;
5854: }
1.795 www 5855:
1.802 bisitz 5856: div.LC_confirm_box {
5857: background-color: #FAFAFA;
5858: border: 1px solid $lg_border_color;
5859: margin-right: 0;
5860: padding: 5px;
5861: }
5862:
5863: div.LC_confirm_box .LC_error img,
5864: div.LC_confirm_box .LC_success img {
5865: vertical-align: middle;
5866: }
5867:
1.1075.2.108 raeburn 5868: .LC_maxwidth {
5869: max-width: 100%;
5870: height: auto;
5871: }
5872:
5873: .LC_textsize_mobile {
5874: \@media only screen and (max-device-width: 480px) {
5875: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
5876: }
5877: }
5878:
1.440 albertel 5879: .LC_icon {
1.771 droeschl 5880: border: none;
1.790 droeschl 5881: vertical-align: middle;
1.771 droeschl 5882: }
5883:
1.543 albertel 5884: .LC_docs_spacer {
5885: width: 25px;
5886: height: 1px;
1.771 droeschl 5887: border: none;
1.543 albertel 5888: }
1.346 albertel 5889:
1.532 albertel 5890: .LC_internal_info {
1.735 bisitz 5891: color: #999999;
1.532 albertel 5892: }
5893:
1.794 www 5894: .LC_discussion {
1.1050 www 5895: background: $data_table_dark;
1.911 bisitz 5896: border: 1px solid black;
5897: margin: 2px;
1.794 www 5898: }
5899:
5900: .LC_disc_action_left {
1.1050 www 5901: background: $sidebg;
1.911 bisitz 5902: text-align: left;
1.1050 www 5903: padding: 4px;
5904: margin: 2px;
1.794 www 5905: }
5906:
5907: .LC_disc_action_right {
1.1050 www 5908: background: $sidebg;
1.911 bisitz 5909: text-align: right;
1.1050 www 5910: padding: 4px;
5911: margin: 2px;
1.794 www 5912: }
5913:
5914: .LC_disc_new_item {
1.911 bisitz 5915: background: white;
5916: border: 2px solid red;
1.1050 www 5917: margin: 4px;
5918: padding: 4px;
1.794 www 5919: }
5920:
5921: .LC_disc_old_item {
1.911 bisitz 5922: background: white;
1.1050 www 5923: margin: 4px;
5924: padding: 4px;
1.794 www 5925: }
5926:
1.458 albertel 5927: table.LC_pastsubmission {
5928: border: 1px solid black;
5929: margin: 2px;
5930: }
5931:
1.924 bisitz 5932: table#LC_menubuttons {
1.345 albertel 5933: width: 100%;
5934: background: $pgbg;
1.392 albertel 5935: border: 2px;
1.402 albertel 5936: border-collapse: separate;
1.803 bisitz 5937: padding: 0;
1.345 albertel 5938: }
1.392 albertel 5939:
1.801 tempelho 5940: table#LC_title_bar a {
5941: color: $fontmenu;
5942: }
1.836 bisitz 5943:
1.807 droeschl 5944: table#LC_title_bar {
1.819 tempelho 5945: clear: both;
1.836 bisitz 5946: display: none;
1.807 droeschl 5947: }
5948:
1.795 www 5949: table#LC_title_bar,
1.933 droeschl 5950: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5951: table#LC_title_bar.LC_with_remote {
1.359 albertel 5952: width: 100%;
1.392 albertel 5953: border-color: $pgbg;
5954: border-style: solid;
5955: border-width: $border;
1.379 albertel 5956: background: $pgbg;
1.801 tempelho 5957: color: $fontmenu;
1.392 albertel 5958: border-collapse: collapse;
1.803 bisitz 5959: padding: 0;
1.819 tempelho 5960: margin: 0;
1.359 albertel 5961: }
1.795 www 5962:
1.933 droeschl 5963: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5964: margin: 0;
5965: padding: 0;
1.933 droeschl 5966: position: relative;
5967: list-style: none;
1.913 droeschl 5968: }
1.933 droeschl 5969: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5970: display: inline;
5971: }
1.933 droeschl 5972:
5973: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5974: padding: 0;
1.933 droeschl 5975: margin: 0;
5976: float: left;
1.913 droeschl 5977: }
1.933 droeschl 5978: .LC_breadcrumb_tools_tools {
5979: padding: 0;
5980: margin: 0;
1.913 droeschl 5981: float: right;
5982: }
5983:
1.359 albertel 5984: table#LC_title_bar td {
5985: background: $tabbg;
5986: }
1.795 www 5987:
1.911 bisitz 5988: table#LC_menubuttons img {
1.803 bisitz 5989: border: none;
1.346 albertel 5990: }
1.795 www 5991:
1.842 droeschl 5992: .LC_breadcrumbs_component {
1.911 bisitz 5993: float: right;
5994: margin: 0 1em;
1.357 albertel 5995: }
1.842 droeschl 5996: .LC_breadcrumbs_component img {
1.911 bisitz 5997: vertical-align: middle;
1.777 tempelho 5998: }
1.795 www 5999:
1.1075.2.108 raeburn 6000: .LC_breadcrumbs_hoverable {
6001: background: $sidebg;
6002: }
6003:
1.383 albertel 6004: td.LC_table_cell_checkbox {
6005: text-align: center;
6006: }
1.795 www 6007:
6008: .LC_fontsize_small {
1.911 bisitz 6009: font-size: 70%;
1.705 tempelho 6010: }
6011:
1.844 bisitz 6012: #LC_breadcrumbs {
1.911 bisitz 6013: clear:both;
6014: background: $sidebg;
6015: border-bottom: 1px solid $lg_border_color;
6016: line-height: 2.5em;
1.933 droeschl 6017: overflow: hidden;
1.911 bisitz 6018: margin: 0;
6019: padding: 0;
1.995 raeburn 6020: text-align: left;
1.819 tempelho 6021: }
1.862 bisitz 6022:
1.1075.2.16 raeburn 6023: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6024: clear:both;
6025: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6026: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6027: margin: 0 0 10px 0;
1.966 bisitz 6028: padding: 3px;
1.995 raeburn 6029: text-align: left;
1.822 bisitz 6030: }
6031:
1.795 www 6032: .LC_fontsize_medium {
1.911 bisitz 6033: font-size: 85%;
1.705 tempelho 6034: }
6035:
1.795 www 6036: .LC_fontsize_large {
1.911 bisitz 6037: font-size: 120%;
1.705 tempelho 6038: }
6039:
1.346 albertel 6040: .LC_menubuttons_inline_text {
6041: color: $font;
1.698 harmsja 6042: font-size: 90%;
1.701 harmsja 6043: padding-left:3px;
1.346 albertel 6044: }
6045:
1.934 droeschl 6046: .LC_menubuttons_inline_text img{
6047: vertical-align: middle;
6048: }
6049:
1.1051 www 6050: li.LC_menubuttons_inline_text img {
1.951 onken 6051: cursor:pointer;
1.1002 droeschl 6052: text-decoration: none;
1.951 onken 6053: }
6054:
1.526 www 6055: .LC_menubuttons_link {
6056: text-decoration: none;
6057: }
1.795 www 6058:
1.522 albertel 6059: .LC_menubuttons_category {
1.521 www 6060: color: $font;
1.526 www 6061: background: $pgbg;
1.521 www 6062: font-size: larger;
6063: font-weight: bold;
6064: }
6065:
1.346 albertel 6066: td.LC_menubuttons_text {
1.911 bisitz 6067: color: $font;
1.346 albertel 6068: }
1.706 harmsja 6069:
1.346 albertel 6070: .LC_current_location {
6071: background: $tabbg;
6072: }
1.795 www 6073:
1.938 bisitz 6074: table.LC_data_table {
1.347 albertel 6075: border: 1px solid #000000;
1.402 albertel 6076: border-collapse: separate;
1.426 albertel 6077: border-spacing: 1px;
1.610 albertel 6078: background: $pgbg;
1.347 albertel 6079: }
1.795 www 6080:
1.422 albertel 6081: .LC_data_table_dense {
6082: font-size: small;
6083: }
1.795 www 6084:
1.507 raeburn 6085: table.LC_nested_outer {
6086: border: 1px solid #000000;
1.589 raeburn 6087: border-collapse: collapse;
1.803 bisitz 6088: border-spacing: 0;
1.507 raeburn 6089: width: 100%;
6090: }
1.795 www 6091:
1.879 raeburn 6092: table.LC_innerpickbox,
1.507 raeburn 6093: table.LC_nested {
1.803 bisitz 6094: border: none;
1.589 raeburn 6095: border-collapse: collapse;
1.803 bisitz 6096: border-spacing: 0;
1.507 raeburn 6097: width: 100%;
6098: }
1.795 www 6099:
1.911 bisitz 6100: table.LC_data_table tr th,
6101: table.LC_calendar tr th,
1.879 raeburn 6102: table.LC_prior_tries tr th,
6103: table.LC_innerpickbox tr th {
1.349 albertel 6104: font-weight: bold;
6105: background-color: $data_table_head;
1.801 tempelho 6106: color:$fontmenu;
1.701 harmsja 6107: font-size:90%;
1.347 albertel 6108: }
1.795 www 6109:
1.879 raeburn 6110: table.LC_innerpickbox tr th,
6111: table.LC_innerpickbox tr td {
6112: vertical-align: top;
6113: }
6114:
1.711 raeburn 6115: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6116: background-color: #CCCCCC;
1.711 raeburn 6117: font-weight: bold;
6118: text-align: left;
6119: }
1.795 www 6120:
1.912 bisitz 6121: table.LC_data_table tr.LC_odd_row > td {
6122: background-color: $data_table_light;
6123: padding: 2px;
6124: vertical-align: top;
6125: }
6126:
1.809 bisitz 6127: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6128: background-color: $data_table_light;
1.912 bisitz 6129: vertical-align: top;
6130: }
6131:
6132: table.LC_data_table tr.LC_even_row > td {
6133: background-color: $data_table_dark;
1.425 albertel 6134: padding: 2px;
1.900 bisitz 6135: vertical-align: top;
1.347 albertel 6136: }
1.795 www 6137:
1.809 bisitz 6138: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6139: background-color: $data_table_dark;
1.900 bisitz 6140: vertical-align: top;
1.347 albertel 6141: }
1.795 www 6142:
1.425 albertel 6143: table.LC_data_table tr.LC_data_table_highlight td {
6144: background-color: $data_table_darker;
6145: }
1.795 www 6146:
1.639 raeburn 6147: table.LC_data_table tr td.LC_leftcol_header {
6148: background-color: $data_table_head;
6149: font-weight: bold;
6150: }
1.795 www 6151:
1.451 albertel 6152: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6153: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6154: font-weight: bold;
6155: font-style: italic;
6156: text-align: center;
6157: padding: 8px;
1.347 albertel 6158: }
1.795 www 6159:
1.1075.2.30 raeburn 6160: table.LC_data_table tr.LC_empty_row td,
6161: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6162: background-color: $sidebg;
6163: }
6164:
6165: table.LC_nested tr.LC_empty_row td {
6166: background-color: #FFFFFF;
6167: }
6168:
1.890 droeschl 6169: table.LC_caption {
6170: }
6171:
1.507 raeburn 6172: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6173: padding: 4ex
6174: }
1.795 www 6175:
1.507 raeburn 6176: table.LC_nested_outer tr th {
6177: font-weight: bold;
1.801 tempelho 6178: color:$fontmenu;
1.507 raeburn 6179: background-color: $data_table_head;
1.701 harmsja 6180: font-size: small;
1.507 raeburn 6181: border-bottom: 1px solid #000000;
6182: }
1.795 www 6183:
1.507 raeburn 6184: table.LC_nested_outer tr td.LC_subheader {
6185: background-color: $data_table_head;
6186: font-weight: bold;
6187: font-size: small;
6188: border-bottom: 1px solid #000000;
6189: text-align: right;
1.451 albertel 6190: }
1.795 www 6191:
1.507 raeburn 6192: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6193: background-color: #CCCCCC;
1.451 albertel 6194: font-weight: bold;
6195: font-size: small;
1.507 raeburn 6196: text-align: center;
6197: }
1.795 www 6198:
1.589 raeburn 6199: table.LC_nested tr.LC_info_row td.LC_left_item,
6200: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6201: text-align: left;
1.451 albertel 6202: }
1.795 www 6203:
1.507 raeburn 6204: table.LC_nested td {
1.735 bisitz 6205: background-color: #FFFFFF;
1.451 albertel 6206: font-size: small;
1.507 raeburn 6207: }
1.795 www 6208:
1.507 raeburn 6209: table.LC_nested_outer tr th.LC_right_item,
6210: table.LC_nested tr.LC_info_row td.LC_right_item,
6211: table.LC_nested tr.LC_odd_row td.LC_right_item,
6212: table.LC_nested tr td.LC_right_item {
1.451 albertel 6213: text-align: right;
6214: }
6215:
1.507 raeburn 6216: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6217: background-color: #EEEEEE;
1.451 albertel 6218: }
6219:
1.473 raeburn 6220: table.LC_createuser {
6221: }
6222:
6223: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6224: font-size: small;
1.473 raeburn 6225: }
6226:
6227: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6228: background-color: #CCCCCC;
1.473 raeburn 6229: font-weight: bold;
6230: text-align: center;
6231: }
6232:
1.349 albertel 6233: table.LC_calendar {
6234: border: 1px solid #000000;
6235: border-collapse: collapse;
1.917 raeburn 6236: width: 98%;
1.349 albertel 6237: }
1.795 www 6238:
1.349 albertel 6239: table.LC_calendar_pickdate {
6240: font-size: xx-small;
6241: }
1.795 www 6242:
1.349 albertel 6243: table.LC_calendar tr td {
6244: border: 1px solid #000000;
6245: vertical-align: top;
1.917 raeburn 6246: width: 14%;
1.349 albertel 6247: }
1.795 www 6248:
1.349 albertel 6249: table.LC_calendar tr td.LC_calendar_day_empty {
6250: background-color: $data_table_dark;
6251: }
1.795 www 6252:
1.779 bisitz 6253: table.LC_calendar tr td.LC_calendar_day_current {
6254: background-color: $data_table_highlight;
1.777 tempelho 6255: }
1.795 www 6256:
1.938 bisitz 6257: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6258: background-color: $mail_new;
6259: }
1.795 www 6260:
1.938 bisitz 6261: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6262: background-color: $mail_new_hover;
6263: }
1.795 www 6264:
1.938 bisitz 6265: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6266: background-color: $mail_read;
6267: }
1.795 www 6268:
1.938 bisitz 6269: /*
6270: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6271: background-color: $mail_read_hover;
6272: }
1.938 bisitz 6273: */
1.795 www 6274:
1.938 bisitz 6275: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6276: background-color: $mail_replied;
6277: }
1.795 www 6278:
1.938 bisitz 6279: /*
6280: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6281: background-color: $mail_replied_hover;
6282: }
1.938 bisitz 6283: */
1.795 www 6284:
1.938 bisitz 6285: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6286: background-color: $mail_other;
6287: }
1.795 www 6288:
1.938 bisitz 6289: /*
6290: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6291: background-color: $mail_other_hover;
6292: }
1.938 bisitz 6293: */
1.494 raeburn 6294:
1.777 tempelho 6295: table.LC_data_table tr > td.LC_browser_file,
6296: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6297: background: #AAEE77;
1.389 albertel 6298: }
1.795 www 6299:
1.777 tempelho 6300: table.LC_data_table tr > td.LC_browser_file_locked,
6301: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6302: background: #FFAA99;
1.387 albertel 6303: }
1.795 www 6304:
1.777 tempelho 6305: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6306: background: #888888;
1.779 bisitz 6307: }
1.795 www 6308:
1.777 tempelho 6309: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6310: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6311: background: #F8F866;
1.777 tempelho 6312: }
1.795 www 6313:
1.696 bisitz 6314: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6315: background: #E0E8FF;
1.387 albertel 6316: }
1.696 bisitz 6317:
1.707 bisitz 6318: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6319: /* background: #77FF77; */
1.707 bisitz 6320: }
1.795 www 6321:
1.707 bisitz 6322: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6323: border-right: 8px solid #FFFF77;
1.707 bisitz 6324: }
1.795 www 6325:
1.707 bisitz 6326: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6327: border-right: 8px solid #FFAA77;
1.707 bisitz 6328: }
1.795 www 6329:
1.707 bisitz 6330: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6331: border-right: 8px solid #FF7777;
1.707 bisitz 6332: }
1.795 www 6333:
1.707 bisitz 6334: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6335: border-right: 8px solid #AAFF77;
1.707 bisitz 6336: }
1.795 www 6337:
1.707 bisitz 6338: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6339: border-right: 8px solid #11CC55;
1.707 bisitz 6340: }
6341:
1.388 albertel 6342: span.LC_current_location {
1.701 harmsja 6343: font-size:larger;
1.388 albertel 6344: background: $pgbg;
6345: }
1.387 albertel 6346:
1.1029 www 6347: span.LC_current_nav_location {
6348: font-weight:bold;
6349: background: $sidebg;
6350: }
6351:
1.395 albertel 6352: span.LC_parm_menu_item {
6353: font-size: larger;
6354: }
1.795 www 6355:
1.395 albertel 6356: span.LC_parm_scope_all {
6357: color: red;
6358: }
1.795 www 6359:
1.395 albertel 6360: span.LC_parm_scope_folder {
6361: color: green;
6362: }
1.795 www 6363:
1.395 albertel 6364: span.LC_parm_scope_resource {
6365: color: orange;
6366: }
1.795 www 6367:
1.395 albertel 6368: span.LC_parm_part {
6369: color: blue;
6370: }
1.795 www 6371:
1.911 bisitz 6372: span.LC_parm_folder,
6373: span.LC_parm_symb {
1.395 albertel 6374: font-size: x-small;
6375: font-family: $mono;
6376: color: #AAAAAA;
6377: }
6378:
1.977 bisitz 6379: ul.LC_parm_parmlist li {
6380: display: inline-block;
6381: padding: 0.3em 0.8em;
6382: vertical-align: top;
6383: width: 150px;
6384: border-top:1px solid $lg_border_color;
6385: }
6386:
1.795 www 6387: td.LC_parm_overview_level_menu,
6388: td.LC_parm_overview_map_menu,
6389: td.LC_parm_overview_parm_selectors,
6390: td.LC_parm_overview_restrictions {
1.396 albertel 6391: border: 1px solid black;
6392: border-collapse: collapse;
6393: }
1.795 www 6394:
1.396 albertel 6395: table.LC_parm_overview_restrictions td {
6396: border-width: 1px 4px 1px 4px;
6397: border-style: solid;
6398: border-color: $pgbg;
6399: text-align: center;
6400: }
1.795 www 6401:
1.396 albertel 6402: table.LC_parm_overview_restrictions th {
6403: background: $tabbg;
6404: border-width: 1px 4px 1px 4px;
6405: border-style: solid;
6406: border-color: $pgbg;
6407: }
1.795 www 6408:
1.398 albertel 6409: table#LC_helpmenu {
1.803 bisitz 6410: border: none;
1.398 albertel 6411: height: 55px;
1.803 bisitz 6412: border-spacing: 0;
1.398 albertel 6413: }
6414:
6415: table#LC_helpmenu fieldset legend {
6416: font-size: larger;
6417: }
1.795 www 6418:
1.397 albertel 6419: table#LC_helpmenu_links {
6420: width: 100%;
6421: border: 1px solid black;
6422: background: $pgbg;
1.803 bisitz 6423: padding: 0;
1.397 albertel 6424: border-spacing: 1px;
6425: }
1.795 www 6426:
1.397 albertel 6427: table#LC_helpmenu_links tr td {
6428: padding: 1px;
6429: background: $tabbg;
1.399 albertel 6430: text-align: center;
6431: font-weight: bold;
1.397 albertel 6432: }
1.396 albertel 6433:
1.795 www 6434: table#LC_helpmenu_links a:link,
6435: table#LC_helpmenu_links a:visited,
1.397 albertel 6436: table#LC_helpmenu_links a:active {
6437: text-decoration: none;
6438: color: $font;
6439: }
1.795 www 6440:
1.397 albertel 6441: table#LC_helpmenu_links a:hover {
6442: text-decoration: underline;
6443: color: $vlink;
6444: }
1.396 albertel 6445:
1.417 albertel 6446: .LC_chrt_popup_exists {
6447: border: 1px solid #339933;
6448: margin: -1px;
6449: }
1.795 www 6450:
1.417 albertel 6451: .LC_chrt_popup_up {
6452: border: 1px solid yellow;
6453: margin: -1px;
6454: }
1.795 www 6455:
1.417 albertel 6456: .LC_chrt_popup {
6457: border: 1px solid #8888FF;
6458: background: #CCCCFF;
6459: }
1.795 www 6460:
1.421 albertel 6461: table.LC_pick_box {
6462: border-collapse: separate;
6463: background: white;
6464: border: 1px solid black;
6465: border-spacing: 1px;
6466: }
1.795 www 6467:
1.421 albertel 6468: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6469: background: $sidebg;
1.421 albertel 6470: font-weight: bold;
1.900 bisitz 6471: text-align: left;
1.740 bisitz 6472: vertical-align: top;
1.421 albertel 6473: width: 184px;
6474: padding: 8px;
6475: }
1.795 www 6476:
1.579 raeburn 6477: table.LC_pick_box td.LC_pick_box_value {
6478: text-align: left;
6479: padding: 8px;
6480: }
1.795 www 6481:
1.579 raeburn 6482: table.LC_pick_box td.LC_pick_box_select {
6483: text-align: left;
6484: padding: 8px;
6485: }
1.795 www 6486:
1.424 albertel 6487: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6488: padding: 0;
1.421 albertel 6489: height: 1px;
6490: background: black;
6491: }
1.795 www 6492:
1.421 albertel 6493: table.LC_pick_box td.LC_pick_box_submit {
6494: text-align: right;
6495: }
1.795 www 6496:
1.579 raeburn 6497: table.LC_pick_box td.LC_evenrow_value {
6498: text-align: left;
6499: padding: 8px;
6500: background-color: $data_table_light;
6501: }
1.795 www 6502:
1.579 raeburn 6503: table.LC_pick_box td.LC_oddrow_value {
6504: text-align: left;
6505: padding: 8px;
6506: background-color: $data_table_light;
6507: }
1.795 www 6508:
1.579 raeburn 6509: span.LC_helpform_receipt_cat {
6510: font-weight: bold;
6511: }
1.795 www 6512:
1.424 albertel 6513: table.LC_group_priv_box {
6514: background: white;
6515: border: 1px solid black;
6516: border-spacing: 1px;
6517: }
1.795 www 6518:
1.424 albertel 6519: table.LC_group_priv_box td.LC_pick_box_title {
6520: background: $tabbg;
6521: font-weight: bold;
6522: text-align: right;
6523: width: 184px;
6524: }
1.795 www 6525:
1.424 albertel 6526: table.LC_group_priv_box td.LC_groups_fixed {
6527: background: $data_table_light;
6528: text-align: center;
6529: }
1.795 www 6530:
1.424 albertel 6531: table.LC_group_priv_box td.LC_groups_optional {
6532: background: $data_table_dark;
6533: text-align: center;
6534: }
1.795 www 6535:
1.424 albertel 6536: table.LC_group_priv_box td.LC_groups_functionality {
6537: background: $data_table_darker;
6538: text-align: center;
6539: font-weight: bold;
6540: }
1.795 www 6541:
1.424 albertel 6542: table.LC_group_priv td {
6543: text-align: left;
1.803 bisitz 6544: padding: 0;
1.424 albertel 6545: }
6546:
6547: .LC_navbuttons {
6548: margin: 2ex 0ex 2ex 0ex;
6549: }
1.795 www 6550:
1.423 albertel 6551: .LC_topic_bar {
6552: font-weight: bold;
6553: background: $tabbg;
1.918 wenzelju 6554: margin: 1em 0em 1em 2em;
1.805 bisitz 6555: padding: 3px;
1.918 wenzelju 6556: font-size: 1.2em;
1.423 albertel 6557: }
1.795 www 6558:
1.423 albertel 6559: .LC_topic_bar span {
1.918 wenzelju 6560: left: 0.5em;
6561: position: absolute;
1.423 albertel 6562: vertical-align: middle;
1.918 wenzelju 6563: font-size: 1.2em;
1.423 albertel 6564: }
1.795 www 6565:
1.423 albertel 6566: table.LC_course_group_status {
6567: margin: 20px;
6568: }
1.795 www 6569:
1.423 albertel 6570: table.LC_status_selector td {
6571: vertical-align: top;
6572: text-align: center;
1.424 albertel 6573: padding: 4px;
6574: }
1.795 www 6575:
1.599 albertel 6576: div.LC_feedback_link {
1.616 albertel 6577: clear: both;
1.829 kalberla 6578: background: $sidebg;
1.779 bisitz 6579: width: 100%;
1.829 kalberla 6580: padding-bottom: 10px;
6581: border: 1px $tabbg solid;
1.833 kalberla 6582: height: 22px;
6583: line-height: 22px;
6584: padding-top: 5px;
6585: }
6586:
6587: div.LC_feedback_link img {
6588: height: 22px;
1.867 kalberla 6589: vertical-align:middle;
1.829 kalberla 6590: }
6591:
1.911 bisitz 6592: div.LC_feedback_link a {
1.829 kalberla 6593: text-decoration: none;
1.489 raeburn 6594: }
1.795 www 6595:
1.867 kalberla 6596: div.LC_comblock {
1.911 bisitz 6597: display:inline;
1.867 kalberla 6598: color:$font;
6599: font-size:90%;
6600: }
6601:
6602: div.LC_feedback_link div.LC_comblock {
6603: padding-left:5px;
6604: }
6605:
6606: div.LC_feedback_link div.LC_comblock a {
6607: color:$font;
6608: }
6609:
1.489 raeburn 6610: span.LC_feedback_link {
1.858 bisitz 6611: /* background: $feedback_link_bg; */
1.599 albertel 6612: font-size: larger;
6613: }
1.795 www 6614:
1.599 albertel 6615: span.LC_message_link {
1.858 bisitz 6616: /* background: $feedback_link_bg; */
1.599 albertel 6617: font-size: larger;
6618: position: absolute;
6619: right: 1em;
1.489 raeburn 6620: }
1.421 albertel 6621:
1.515 albertel 6622: table.LC_prior_tries {
1.524 albertel 6623: border: 1px solid #000000;
6624: border-collapse: separate;
6625: border-spacing: 1px;
1.515 albertel 6626: }
1.523 albertel 6627:
1.515 albertel 6628: table.LC_prior_tries td {
1.524 albertel 6629: padding: 2px;
1.515 albertel 6630: }
1.523 albertel 6631:
6632: .LC_answer_correct {
1.795 www 6633: background: lightgreen;
6634: color: darkgreen;
6635: padding: 6px;
1.523 albertel 6636: }
1.795 www 6637:
1.523 albertel 6638: .LC_answer_charged_try {
1.797 www 6639: background: #FFAAAA;
1.795 www 6640: color: darkred;
6641: padding: 6px;
1.523 albertel 6642: }
1.795 www 6643:
1.779 bisitz 6644: .LC_answer_not_charged_try,
1.523 albertel 6645: .LC_answer_no_grade,
6646: .LC_answer_late {
1.795 www 6647: background: lightyellow;
1.523 albertel 6648: color: black;
1.795 www 6649: padding: 6px;
1.523 albertel 6650: }
1.795 www 6651:
1.523 albertel 6652: .LC_answer_previous {
1.795 www 6653: background: lightblue;
6654: color: darkblue;
6655: padding: 6px;
1.523 albertel 6656: }
1.795 www 6657:
1.779 bisitz 6658: .LC_answer_no_message {
1.777 tempelho 6659: background: #FFFFFF;
6660: color: black;
1.795 www 6661: padding: 6px;
1.779 bisitz 6662: }
1.795 www 6663:
1.779 bisitz 6664: .LC_answer_unknown {
6665: background: orange;
6666: color: black;
1.795 www 6667: padding: 6px;
1.777 tempelho 6668: }
1.795 www 6669:
1.529 albertel 6670: span.LC_prior_numerical,
6671: span.LC_prior_string,
6672: span.LC_prior_custom,
6673: span.LC_prior_reaction,
6674: span.LC_prior_math {
1.925 bisitz 6675: font-family: $mono;
1.523 albertel 6676: white-space: pre;
6677: }
6678:
1.525 albertel 6679: span.LC_prior_string {
1.925 bisitz 6680: font-family: $mono;
1.525 albertel 6681: white-space: pre;
6682: }
6683:
1.523 albertel 6684: table.LC_prior_option {
6685: width: 100%;
6686: border-collapse: collapse;
6687: }
1.795 www 6688:
1.911 bisitz 6689: table.LC_prior_rank,
1.795 www 6690: table.LC_prior_match {
1.528 albertel 6691: border-collapse: collapse;
6692: }
1.795 www 6693:
1.528 albertel 6694: table.LC_prior_option tr td,
6695: table.LC_prior_rank tr td,
6696: table.LC_prior_match tr td {
1.524 albertel 6697: border: 1px solid #000000;
1.515 albertel 6698: }
6699:
1.855 bisitz 6700: .LC_nobreak {
1.544 albertel 6701: white-space: nowrap;
1.519 raeburn 6702: }
6703:
1.576 raeburn 6704: span.LC_cusr_emph {
6705: font-style: italic;
6706: }
6707:
1.633 raeburn 6708: span.LC_cusr_subheading {
6709: font-weight: normal;
6710: font-size: 85%;
6711: }
6712:
1.861 bisitz 6713: div.LC_docs_entry_move {
1.859 bisitz 6714: border: 1px solid #BBBBBB;
1.545 albertel 6715: background: #DDDDDD;
1.861 bisitz 6716: width: 22px;
1.859 bisitz 6717: padding: 1px;
6718: margin: 0;
1.545 albertel 6719: }
6720:
1.861 bisitz 6721: table.LC_data_table tr > td.LC_docs_entry_commands,
6722: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6723: font-size: x-small;
6724: }
1.795 www 6725:
1.861 bisitz 6726: .LC_docs_entry_parameter {
6727: white-space: nowrap;
6728: }
6729:
1.544 albertel 6730: .LC_docs_copy {
1.545 albertel 6731: color: #000099;
1.544 albertel 6732: }
1.795 www 6733:
1.544 albertel 6734: .LC_docs_cut {
1.545 albertel 6735: color: #550044;
1.544 albertel 6736: }
1.795 www 6737:
1.544 albertel 6738: .LC_docs_rename {
1.545 albertel 6739: color: #009900;
1.544 albertel 6740: }
1.795 www 6741:
1.544 albertel 6742: .LC_docs_remove {
1.545 albertel 6743: color: #990000;
6744: }
6745:
1.547 albertel 6746: .LC_docs_reinit_warn,
6747: .LC_docs_ext_edit {
6748: font-size: x-small;
6749: }
6750:
1.545 albertel 6751: table.LC_docs_adddocs td,
6752: table.LC_docs_adddocs th {
6753: border: 1px solid #BBBBBB;
6754: padding: 4px;
6755: background: #DDDDDD;
1.543 albertel 6756: }
6757:
1.584 albertel 6758: table.LC_sty_begin {
6759: background: #BBFFBB;
6760: }
1.795 www 6761:
1.584 albertel 6762: table.LC_sty_end {
6763: background: #FFBBBB;
6764: }
6765:
1.589 raeburn 6766: table.LC_double_column {
1.803 bisitz 6767: border-width: 0;
1.589 raeburn 6768: border-collapse: collapse;
6769: width: 100%;
6770: padding: 2px;
6771: }
6772:
6773: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6774: top: 2px;
1.589 raeburn 6775: left: 2px;
6776: width: 47%;
6777: vertical-align: top;
6778: }
6779:
6780: table.LC_double_column tr td.LC_right_col {
6781: top: 2px;
1.779 bisitz 6782: right: 2px;
1.589 raeburn 6783: width: 47%;
6784: vertical-align: top;
6785: }
6786:
1.591 raeburn 6787: div.LC_left_float {
6788: float: left;
6789: padding-right: 5%;
1.597 albertel 6790: padding-bottom: 4px;
1.591 raeburn 6791: }
6792:
6793: div.LC_clear_float_header {
1.597 albertel 6794: padding-bottom: 2px;
1.591 raeburn 6795: }
6796:
6797: div.LC_clear_float_footer {
1.597 albertel 6798: padding-top: 10px;
1.591 raeburn 6799: clear: both;
6800: }
6801:
1.597 albertel 6802: div.LC_grade_show_user {
1.941 bisitz 6803: /* border-left: 5px solid $sidebg; */
6804: border-top: 5px solid #000000;
6805: margin: 50px 0 0 0;
1.936 bisitz 6806: padding: 15px 0 5px 10px;
1.597 albertel 6807: }
1.795 www 6808:
1.936 bisitz 6809: div.LC_grade_show_user_odd_row {
1.941 bisitz 6810: /* border-left: 5px solid #000000; */
6811: }
6812:
6813: div.LC_grade_show_user div.LC_Box {
6814: margin-right: 50px;
1.597 albertel 6815: }
6816:
6817: div.LC_grade_submissions,
6818: div.LC_grade_message_center,
1.936 bisitz 6819: div.LC_grade_info_links {
1.597 albertel 6820: margin: 5px;
6821: width: 99%;
6822: background: #FFFFFF;
6823: }
1.795 www 6824:
1.597 albertel 6825: div.LC_grade_submissions_header,
1.936 bisitz 6826: div.LC_grade_message_center_header {
1.705 tempelho 6827: font-weight: bold;
6828: font-size: large;
1.597 albertel 6829: }
1.795 www 6830:
1.597 albertel 6831: div.LC_grade_submissions_body,
1.936 bisitz 6832: div.LC_grade_message_center_body {
1.597 albertel 6833: border: 1px solid black;
6834: width: 99%;
6835: background: #FFFFFF;
6836: }
1.795 www 6837:
1.613 albertel 6838: table.LC_scantron_action {
6839: width: 100%;
6840: }
1.795 www 6841:
1.613 albertel 6842: table.LC_scantron_action tr th {
1.698 harmsja 6843: font-weight:bold;
6844: font-style:normal;
1.613 albertel 6845: }
1.795 www 6846:
1.779 bisitz 6847: .LC_edit_problem_header,
1.614 albertel 6848: div.LC_edit_problem_footer {
1.705 tempelho 6849: font-weight: normal;
6850: font-size: medium;
1.602 albertel 6851: margin: 2px;
1.1060 bisitz 6852: background-color: $sidebg;
1.600 albertel 6853: }
1.795 www 6854:
1.600 albertel 6855: div.LC_edit_problem_header,
1.602 albertel 6856: div.LC_edit_problem_header div,
1.614 albertel 6857: div.LC_edit_problem_footer,
6858: div.LC_edit_problem_footer div,
1.602 albertel 6859: div.LC_edit_problem_editxml_header,
6860: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 6861: z-index: 100;
1.600 albertel 6862: }
1.795 www 6863:
1.600 albertel 6864: div.LC_edit_problem_header_title {
1.705 tempelho 6865: font-weight: bold;
6866: font-size: larger;
1.602 albertel 6867: background: $tabbg;
6868: padding: 3px;
1.1060 bisitz 6869: margin: 0 0 5px 0;
1.602 albertel 6870: }
1.795 www 6871:
1.602 albertel 6872: table.LC_edit_problem_header_title {
6873: width: 100%;
1.600 albertel 6874: background: $tabbg;
1.602 albertel 6875: }
6876:
1.1075.2.112 raeburn 6877: div.LC_edit_actionbar {
6878: background-color: $sidebg;
6879: margin: 0;
6880: padding: 0;
6881: line-height: 200%;
1.602 albertel 6882: }
1.795 www 6883:
1.1075.2.112 raeburn 6884: div.LC_edit_actionbar div{
6885: padding: 0;
6886: margin: 0;
6887: display: inline-block;
1.600 albertel 6888: }
1.795 www 6889:
1.1075.2.34 raeburn 6890: .LC_edit_opt {
6891: padding-left: 1em;
6892: white-space: nowrap;
6893: }
6894:
1.1075.2.57 raeburn 6895: .LC_edit_problem_latexhelper{
6896: text-align: right;
6897: }
6898:
6899: #LC_edit_problem_colorful div{
6900: margin-left: 40px;
6901: }
6902:
1.1075.2.112 raeburn 6903: #LC_edit_problem_codemirror div{
6904: margin-left: 0px;
6905: }
6906:
1.911 bisitz 6907: img.stift {
1.803 bisitz 6908: border-width: 0;
6909: vertical-align: middle;
1.677 riegler 6910: }
1.680 riegler 6911:
1.923 bisitz 6912: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6913: vertical-align: top;
1.777 tempelho 6914: }
1.795 www 6915:
1.716 raeburn 6916: div.LC_createcourse {
1.911 bisitz 6917: margin: 10px 10px 10px 10px;
1.716 raeburn 6918: }
6919:
1.917 raeburn 6920: .LC_dccid {
1.1075.2.38 raeburn 6921: float: right;
1.917 raeburn 6922: margin: 0.2em 0 0 0;
6923: padding: 0;
6924: font-size: 90%;
6925: display:none;
6926: }
6927:
1.897 wenzelju 6928: ol.LC_primary_menu a:hover,
1.721 harmsja 6929: ol#LC_MenuBreadcrumbs a:hover,
6930: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6931: ul#LC_secondary_menu a:hover,
1.721 harmsja 6932: .LC_FormSectionClearButton input:hover
1.795 www 6933: ul.LC_TabContent li:hover a {
1.952 onken 6934: color:$button_hover;
1.911 bisitz 6935: text-decoration:none;
1.693 droeschl 6936: }
6937:
1.779 bisitz 6938: h1 {
1.911 bisitz 6939: padding: 0;
6940: line-height:130%;
1.693 droeschl 6941: }
1.698 harmsja 6942:
1.911 bisitz 6943: h2,
6944: h3,
6945: h4,
6946: h5,
6947: h6 {
6948: margin: 5px 0 5px 0;
6949: padding: 0;
6950: line-height:130%;
1.693 droeschl 6951: }
1.795 www 6952:
6953: .LC_hcell {
1.911 bisitz 6954: padding:3px 15px 3px 15px;
6955: margin: 0;
6956: background-color:$tabbg;
6957: color:$fontmenu;
6958: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6959: }
1.795 www 6960:
1.840 bisitz 6961: .LC_Box > .LC_hcell {
1.911 bisitz 6962: margin: 0 -10px 10px -10px;
1.835 bisitz 6963: }
6964:
1.721 harmsja 6965: .LC_noBorder {
1.911 bisitz 6966: border: 0;
1.698 harmsja 6967: }
1.693 droeschl 6968:
1.721 harmsja 6969: .LC_FormSectionClearButton input {
1.911 bisitz 6970: background-color:transparent;
6971: border: none;
6972: cursor:pointer;
6973: text-decoration:underline;
1.693 droeschl 6974: }
1.763 bisitz 6975:
6976: .LC_help_open_topic {
1.911 bisitz 6977: color: #FFFFFF;
6978: background-color: #EEEEFF;
6979: margin: 1px;
6980: padding: 4px;
6981: border: 1px solid #000033;
6982: white-space: nowrap;
6983: /* vertical-align: middle; */
1.759 neumanie 6984: }
1.693 droeschl 6985:
1.911 bisitz 6986: dl,
6987: ul,
6988: div,
6989: fieldset {
6990: margin: 10px 10px 10px 0;
6991: /* overflow: hidden; */
1.693 droeschl 6992: }
1.795 www 6993:
1.1075.2.90 raeburn 6994: article.geogebraweb div {
6995: margin: 0;
6996: }
6997:
1.838 bisitz 6998: fieldset > legend {
1.911 bisitz 6999: font-weight: bold;
7000: padding: 0 5px 0 5px;
1.838 bisitz 7001: }
7002:
1.813 bisitz 7003: #LC_nav_bar {
1.911 bisitz 7004: float: left;
1.995 raeburn 7005: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7006: margin: 0 0 2px 0;
1.807 droeschl 7007: }
7008:
1.916 droeschl 7009: #LC_realm {
7010: margin: 0.2em 0 0 0;
7011: padding: 0;
7012: font-weight: bold;
7013: text-align: center;
1.995 raeburn 7014: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7015: }
7016:
1.911 bisitz 7017: #LC_nav_bar em {
7018: font-weight: bold;
7019: font-style: normal;
1.807 droeschl 7020: }
7021:
1.897 wenzelju 7022: ol.LC_primary_menu {
1.934 droeschl 7023: margin: 0;
1.1075.2.2 raeburn 7024: padding: 0;
1.807 droeschl 7025: }
7026:
1.852 droeschl 7027: ol#LC_PathBreadcrumbs {
1.911 bisitz 7028: margin: 0;
1.693 droeschl 7029: }
7030:
1.897 wenzelju 7031: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7032: color: RGB(80, 80, 80);
7033: vertical-align: middle;
7034: text-align: left;
7035: list-style: none;
1.1075.2.112 raeburn 7036: position: relative;
1.1075.2.2 raeburn 7037: float: left;
1.1075.2.112 raeburn 7038: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7039: line-height: 1.5em;
1.1075.2.2 raeburn 7040: }
7041:
1.1075.2.113 raeburn 7042: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7043: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7044: display: block;
7045: margin: 0;
7046: padding: 0 5px 0 10px;
7047: text-decoration: none;
7048: }
7049:
1.1075.2.112 raeburn 7050: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7051: display: inline-block;
7052: width: 95%;
7053: text-align: left;
7054: }
7055:
7056: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7057: display: inline-block;
7058: width: 5%;
7059: float: right;
7060: text-align: right;
7061: font-size: 70%;
7062: }
7063:
7064: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7065: display: none;
1.1075.2.112 raeburn 7066: width: 15em;
1.1075.2.2 raeburn 7067: background-color: $data_table_light;
1.1075.2.112 raeburn 7068: position: absolute;
7069: top: 100%;
7070: }
7071:
7072: ol.LC_primary_menu ul ul {
7073: left: 100%;
7074: top: 0;
1.1075.2.2 raeburn 7075: }
7076:
1.1075.2.112 raeburn 7077: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7078: display: block;
7079: position: absolute;
7080: margin: 0;
7081: padding: 0;
1.1075.2.5 raeburn 7082: z-index: 2;
1.1075.2.2 raeburn 7083: }
7084:
7085: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7086: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7087: font-size: 90%;
1.911 bisitz 7088: vertical-align: top;
1.1075.2.2 raeburn 7089: float: none;
1.1075.2.5 raeburn 7090: border-left: 1px solid black;
7091: border-right: 1px solid black;
1.1075.2.112 raeburn 7092: /* A dark bottom border to visualize different menu options;
7093: overwritten in the create_submenu routine for the last border-bottom of the menu */
7094: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7095: }
7096:
1.1075.2.112 raeburn 7097: ol.LC_primary_menu li li p:hover {
7098: color:$button_hover;
7099: text-decoration:none;
7100: background-color:$data_table_dark;
1.1075.2.2 raeburn 7101: }
7102:
7103: ol.LC_primary_menu li li a:hover {
7104: color:$button_hover;
7105: background-color:$data_table_dark;
1.693 droeschl 7106: }
7107:
1.1075.2.112 raeburn 7108: /* Font-size equal to the size of the predecessors*/
7109: ol.LC_primary_menu li:hover li li {
7110: font-size: 100%;
7111: }
7112:
1.897 wenzelju 7113: ol.LC_primary_menu li img {
1.911 bisitz 7114: vertical-align: bottom;
1.934 droeschl 7115: height: 1.1em;
1.1075.2.3 raeburn 7116: margin: 0.2em 0 0 0;
1.693 droeschl 7117: }
7118:
1.897 wenzelju 7119: ol.LC_primary_menu a {
1.911 bisitz 7120: color: RGB(80, 80, 80);
7121: text-decoration: none;
1.693 droeschl 7122: }
1.795 www 7123:
1.949 droeschl 7124: ol.LC_primary_menu a.LC_new_message {
7125: font-weight:bold;
7126: color: darkred;
7127: }
7128:
1.975 raeburn 7129: ol.LC_docs_parameters {
7130: margin-left: 0;
7131: padding: 0;
7132: list-style: none;
7133: }
7134:
7135: ol.LC_docs_parameters li {
7136: margin: 0;
7137: padding-right: 20px;
7138: display: inline;
7139: }
7140:
1.976 raeburn 7141: ol.LC_docs_parameters li:before {
7142: content: "\\002022 \\0020";
7143: }
7144:
7145: li.LC_docs_parameters_title {
7146: font-weight: bold;
7147: }
7148:
7149: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7150: content: "";
7151: }
7152:
1.897 wenzelju 7153: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7154: clear: right;
1.911 bisitz 7155: color: $fontmenu;
7156: background: $tabbg;
7157: list-style: none;
7158: padding: 0;
7159: margin: 0;
7160: width: 100%;
1.995 raeburn 7161: text-align: left;
1.1075.2.4 raeburn 7162: float: left;
1.808 droeschl 7163: }
7164:
1.897 wenzelju 7165: ul#LC_secondary_menu li {
1.911 bisitz 7166: font-weight: bold;
7167: line-height: 1.8em;
7168: border-right: 1px solid black;
1.1075.2.4 raeburn 7169: float: left;
7170: }
7171:
7172: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7173: background-color: $data_table_light;
7174: }
7175:
7176: ul#LC_secondary_menu li a {
7177: padding: 0 0.8em;
7178: }
7179:
7180: ul#LC_secondary_menu li ul {
7181: display: none;
7182: }
7183:
7184: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7185: display: block;
7186: position: absolute;
7187: margin: 0;
7188: padding: 0;
7189: list-style:none;
7190: float: none;
7191: background-color: $data_table_light;
1.1075.2.5 raeburn 7192: z-index: 2;
1.1075.2.10 raeburn 7193: margin-left: -1px;
1.1075.2.4 raeburn 7194: }
7195:
7196: ul#LC_secondary_menu li ul li {
7197: font-size: 90%;
7198: vertical-align: top;
7199: border-left: 1px solid black;
7200: border-right: 1px solid black;
1.1075.2.33 raeburn 7201: background-color: $data_table_light;
1.1075.2.4 raeburn 7202: list-style:none;
7203: float: none;
7204: }
7205:
7206: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7207: background-color: $data_table_dark;
1.807 droeschl 7208: }
7209:
1.847 tempelho 7210: ul.LC_TabContent {
1.911 bisitz 7211: display:block;
7212: background: $sidebg;
7213: border-bottom: solid 1px $lg_border_color;
7214: list-style:none;
1.1020 raeburn 7215: margin: -1px -10px 0 -10px;
1.911 bisitz 7216: padding: 0;
1.693 droeschl 7217: }
7218:
1.795 www 7219: ul.LC_TabContent li,
7220: ul.LC_TabContentBigger li {
1.911 bisitz 7221: float:left;
1.741 harmsja 7222: }
1.795 www 7223:
1.897 wenzelju 7224: ul#LC_secondary_menu li a {
1.911 bisitz 7225: color: $fontmenu;
7226: text-decoration: none;
1.693 droeschl 7227: }
1.795 www 7228:
1.721 harmsja 7229: ul.LC_TabContent {
1.952 onken 7230: min-height:20px;
1.721 harmsja 7231: }
1.795 www 7232:
7233: ul.LC_TabContent li {
1.911 bisitz 7234: vertical-align:middle;
1.959 onken 7235: padding: 0 16px 0 10px;
1.911 bisitz 7236: background-color:$tabbg;
7237: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7238: border-left: solid 1px $font;
1.721 harmsja 7239: }
1.795 www 7240:
1.847 tempelho 7241: ul.LC_TabContent .right {
1.911 bisitz 7242: float:right;
1.847 tempelho 7243: }
7244:
1.911 bisitz 7245: ul.LC_TabContent li a,
7246: ul.LC_TabContent li {
7247: color:rgb(47,47,47);
7248: text-decoration:none;
7249: font-size:95%;
7250: font-weight:bold;
1.952 onken 7251: min-height:20px;
7252: }
7253:
1.959 onken 7254: ul.LC_TabContent li a:hover,
7255: ul.LC_TabContent li a:focus {
1.952 onken 7256: color: $button_hover;
1.959 onken 7257: background:none;
7258: outline:none;
1.952 onken 7259: }
7260:
7261: ul.LC_TabContent li:hover {
7262: color: $button_hover;
7263: cursor:pointer;
1.721 harmsja 7264: }
1.795 www 7265:
1.911 bisitz 7266: ul.LC_TabContent li.active {
1.952 onken 7267: color: $font;
1.911 bisitz 7268: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7269: border-bottom:solid 1px #FFFFFF;
7270: cursor: default;
1.744 ehlerst 7271: }
1.795 www 7272:
1.959 onken 7273: ul.LC_TabContent li.active a {
7274: color:$font;
7275: background:#FFFFFF;
7276: outline: none;
7277: }
1.1047 raeburn 7278:
7279: ul.LC_TabContent li.goback {
7280: float: left;
7281: border-left: none;
7282: }
7283:
1.870 tempelho 7284: #maincoursedoc {
1.911 bisitz 7285: clear:both;
1.870 tempelho 7286: }
7287:
7288: ul.LC_TabContentBigger {
1.911 bisitz 7289: display:block;
7290: list-style:none;
7291: padding: 0;
1.870 tempelho 7292: }
7293:
1.795 www 7294: ul.LC_TabContentBigger li {
1.911 bisitz 7295: vertical-align:bottom;
7296: height: 30px;
7297: font-size:110%;
7298: font-weight:bold;
7299: color: #737373;
1.841 tempelho 7300: }
7301:
1.957 onken 7302: ul.LC_TabContentBigger li.active {
7303: position: relative;
7304: top: 1px;
7305: }
7306:
1.870 tempelho 7307: ul.LC_TabContentBigger li a {
1.911 bisitz 7308: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7309: height: 30px;
7310: line-height: 30px;
7311: text-align: center;
7312: display: block;
7313: text-decoration: none;
1.958 onken 7314: outline: none;
1.741 harmsja 7315: }
1.795 www 7316:
1.870 tempelho 7317: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7318: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7319: color:$font;
1.744 ehlerst 7320: }
1.795 www 7321:
1.870 tempelho 7322: ul.LC_TabContentBigger li b {
1.911 bisitz 7323: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7324: display: block;
7325: float: left;
7326: padding: 0 30px;
1.957 onken 7327: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7328: }
7329:
1.956 onken 7330: ul.LC_TabContentBigger li:hover b {
7331: color:$button_hover;
7332: }
7333:
1.870 tempelho 7334: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7335: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7336: color:$font;
1.957 onken 7337: border: 0;
1.741 harmsja 7338: }
1.693 droeschl 7339:
1.870 tempelho 7340:
1.862 bisitz 7341: ul.LC_CourseBreadcrumbs {
7342: background: $sidebg;
1.1020 raeburn 7343: height: 2em;
1.862 bisitz 7344: padding-left: 10px;
1.1020 raeburn 7345: margin: 0;
1.862 bisitz 7346: list-style-position: inside;
7347: }
7348:
1.911 bisitz 7349: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7350: ol#LC_PathBreadcrumbs {
1.911 bisitz 7351: padding-left: 10px;
7352: margin: 0;
1.933 droeschl 7353: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7354: }
7355:
1.911 bisitz 7356: ol#LC_MenuBreadcrumbs li,
7357: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7358: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7359: display: inline;
1.933 droeschl 7360: white-space: normal;
1.693 droeschl 7361: }
7362:
1.823 bisitz 7363: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7364: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7365: text-decoration: none;
7366: font-size:90%;
1.693 droeschl 7367: }
1.795 www 7368:
1.969 droeschl 7369: ol#LC_MenuBreadcrumbs h1 {
7370: display: inline;
7371: font-size: 90%;
7372: line-height: 2.5em;
7373: margin: 0;
7374: padding: 0;
7375: }
7376:
1.795 www 7377: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7378: text-decoration:none;
7379: font-size:100%;
7380: font-weight:bold;
1.693 droeschl 7381: }
1.795 www 7382:
1.840 bisitz 7383: .LC_Box {
1.911 bisitz 7384: border: solid 1px $lg_border_color;
7385: padding: 0 10px 10px 10px;
1.746 neumanie 7386: }
1.795 www 7387:
1.1020 raeburn 7388: .LC_DocsBox {
7389: border: solid 1px $lg_border_color;
7390: padding: 0 0 10px 10px;
7391: }
7392:
1.795 www 7393: .LC_AboutMe_Image {
1.911 bisitz 7394: float:left;
7395: margin-right:10px;
1.747 neumanie 7396: }
1.795 www 7397:
7398: .LC_Clear_AboutMe_Image {
1.911 bisitz 7399: clear:left;
1.747 neumanie 7400: }
1.795 www 7401:
1.721 harmsja 7402: dl.LC_ListStyleClean dt {
1.911 bisitz 7403: padding-right: 5px;
7404: display: table-header-group;
1.693 droeschl 7405: }
7406:
1.721 harmsja 7407: dl.LC_ListStyleClean dd {
1.911 bisitz 7408: display: table-row;
1.693 droeschl 7409: }
7410:
1.721 harmsja 7411: .LC_ListStyleClean,
7412: .LC_ListStyleSimple,
7413: .LC_ListStyleNormal,
1.795 www 7414: .LC_ListStyleSpecial {
1.911 bisitz 7415: /* display:block; */
7416: list-style-position: inside;
7417: list-style-type: none;
7418: overflow: hidden;
7419: padding: 0;
1.693 droeschl 7420: }
7421:
1.721 harmsja 7422: .LC_ListStyleSimple li,
7423: .LC_ListStyleSimple dd,
7424: .LC_ListStyleNormal li,
7425: .LC_ListStyleNormal dd,
7426: .LC_ListStyleSpecial li,
1.795 www 7427: .LC_ListStyleSpecial dd {
1.911 bisitz 7428: margin: 0;
7429: padding: 5px 5px 5px 10px;
7430: clear: both;
1.693 droeschl 7431: }
7432:
1.721 harmsja 7433: .LC_ListStyleClean li,
7434: .LC_ListStyleClean dd {
1.911 bisitz 7435: padding-top: 0;
7436: padding-bottom: 0;
1.693 droeschl 7437: }
7438:
1.721 harmsja 7439: .LC_ListStyleSimple dd,
1.795 www 7440: .LC_ListStyleSimple li {
1.911 bisitz 7441: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7442: }
7443:
1.721 harmsja 7444: .LC_ListStyleSpecial li,
7445: .LC_ListStyleSpecial dd {
1.911 bisitz 7446: list-style-type: none;
7447: background-color: RGB(220, 220, 220);
7448: margin-bottom: 4px;
1.693 droeschl 7449: }
7450:
1.721 harmsja 7451: table.LC_SimpleTable {
1.911 bisitz 7452: margin:5px;
7453: border:solid 1px $lg_border_color;
1.795 www 7454: }
1.693 droeschl 7455:
1.721 harmsja 7456: table.LC_SimpleTable tr {
1.911 bisitz 7457: padding: 0;
7458: border:solid 1px $lg_border_color;
1.693 droeschl 7459: }
1.795 www 7460:
7461: table.LC_SimpleTable thead {
1.911 bisitz 7462: background:rgb(220,220,220);
1.693 droeschl 7463: }
7464:
1.721 harmsja 7465: div.LC_columnSection {
1.911 bisitz 7466: display: block;
7467: clear: both;
7468: overflow: hidden;
7469: margin: 0;
1.693 droeschl 7470: }
7471:
1.721 harmsja 7472: div.LC_columnSection>* {
1.911 bisitz 7473: float: left;
7474: margin: 10px 20px 10px 0;
7475: overflow:hidden;
1.693 droeschl 7476: }
1.721 harmsja 7477:
1.795 www 7478: table em {
1.911 bisitz 7479: font-weight: bold;
7480: font-style: normal;
1.748 schulted 7481: }
1.795 www 7482:
1.779 bisitz 7483: table.LC_tableBrowseRes,
1.795 www 7484: table.LC_tableOfContent {
1.911 bisitz 7485: border:none;
7486: border-spacing: 1px;
7487: padding: 3px;
7488: background-color: #FFFFFF;
7489: font-size: 90%;
1.753 droeschl 7490: }
1.789 droeschl 7491:
1.911 bisitz 7492: table.LC_tableOfContent {
7493: border-collapse: collapse;
1.789 droeschl 7494: }
7495:
1.771 droeschl 7496: table.LC_tableBrowseRes a,
1.768 schulted 7497: table.LC_tableOfContent a {
1.911 bisitz 7498: background-color: transparent;
7499: text-decoration: none;
1.753 droeschl 7500: }
7501:
1.795 www 7502: table.LC_tableOfContent img {
1.911 bisitz 7503: border: none;
7504: height: 1.3em;
7505: vertical-align: text-bottom;
7506: margin-right: 0.3em;
1.753 droeschl 7507: }
1.757 schulted 7508:
1.795 www 7509: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7510: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7511: }
7512:
1.795 www 7513: a#LC_content_toolbar_everything {
1.911 bisitz 7514: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7515: }
7516:
1.795 www 7517: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7518: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7519: }
7520:
1.795 www 7521: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7522: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7523: }
7524:
1.795 www 7525: a#LC_content_toolbar_changefolder {
1.911 bisitz 7526: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7527: }
7528:
1.795 www 7529: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7530: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7531: }
7532:
1.1043 raeburn 7533: a#LC_content_toolbar_edittoplevel {
7534: background-image:url(/res/adm/pages/edittoplevel.gif);
7535: }
7536:
1.795 www 7537: ul#LC_toolbar li a:hover {
1.911 bisitz 7538: background-position: bottom center;
1.757 schulted 7539: }
7540:
1.795 www 7541: ul#LC_toolbar {
1.911 bisitz 7542: padding: 0;
7543: margin: 2px;
7544: list-style:none;
7545: position:relative;
7546: background-color:white;
1.1075.2.9 raeburn 7547: overflow: auto;
1.757 schulted 7548: }
7549:
1.795 www 7550: ul#LC_toolbar li {
1.911 bisitz 7551: border:1px solid white;
7552: padding: 0;
7553: margin: 0;
7554: float: left;
7555: display:inline;
7556: vertical-align:middle;
1.1075.2.9 raeburn 7557: white-space: nowrap;
1.911 bisitz 7558: }
1.757 schulted 7559:
1.783 amueller 7560:
1.795 www 7561: a.LC_toolbarItem {
1.911 bisitz 7562: display:block;
7563: padding: 0;
7564: margin: 0;
7565: height: 32px;
7566: width: 32px;
7567: color:white;
7568: border: none;
7569: background-repeat:no-repeat;
7570: background-color:transparent;
1.757 schulted 7571: }
7572:
1.915 droeschl 7573: ul.LC_funclist {
7574: margin: 0;
7575: padding: 0.5em 1em 0.5em 0;
7576: }
7577:
1.933 droeschl 7578: ul.LC_funclist > li:first-child {
7579: font-weight:bold;
7580: margin-left:0.8em;
7581: }
7582:
1.915 droeschl 7583: ul.LC_funclist + ul.LC_funclist {
7584: /*
7585: left border as a seperator if we have more than
7586: one list
7587: */
7588: border-left: 1px solid $sidebg;
7589: /*
7590: this hides the left border behind the border of the
7591: outer box if element is wrapped to the next 'line'
7592: */
7593: margin-left: -1px;
7594: }
7595:
1.843 bisitz 7596: ul.LC_funclist li {
1.915 droeschl 7597: display: inline;
1.782 bisitz 7598: white-space: nowrap;
1.915 droeschl 7599: margin: 0 0 0 25px;
7600: line-height: 150%;
1.782 bisitz 7601: }
7602:
1.974 wenzelju 7603: .LC_hidden {
7604: display: none;
7605: }
7606:
1.1030 www 7607: .LCmodal-overlay {
7608: position:fixed;
7609: top:0;
7610: right:0;
7611: bottom:0;
7612: left:0;
7613: height:100%;
7614: width:100%;
7615: margin:0;
7616: padding:0;
7617: background:#999;
7618: opacity:.75;
7619: filter: alpha(opacity=75);
7620: -moz-opacity: 0.75;
7621: z-index:101;
7622: }
7623:
7624: * html .LCmodal-overlay {
7625: position: absolute;
7626: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7627: }
7628:
7629: .LCmodal-window {
7630: position:fixed;
7631: top:50%;
7632: left:50%;
7633: margin:0;
7634: padding:0;
7635: z-index:102;
7636: }
7637:
7638: * html .LCmodal-window {
7639: position:absolute;
7640: }
7641:
7642: .LCclose-window {
7643: position:absolute;
7644: width:32px;
7645: height:32px;
7646: right:8px;
7647: top:8px;
7648: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7649: text-indent:-99999px;
7650: overflow:hidden;
7651: cursor:pointer;
7652: }
7653:
1.1075.2.17 raeburn 7654: /*
7655: styles used by TTH when "Default set of options to pass to tth/m
7656: when converting TeX" in course settings has been set
7657:
7658: option passed: -t
7659:
7660: */
7661:
7662: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7663: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7664: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7665: td div.norm {line-height:normal;}
7666:
7667: /*
7668: option passed -y3
7669: */
7670:
7671: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7672: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7673: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7674:
1.1075.2.121 raeburn 7675: #LC_minitab_header {
7676: float:left;
7677: width:100%;
7678: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
7679: font-size:93%;
7680: line-height:normal;
7681: margin: 0.5em 0 0.5em 0;
7682: }
7683: #LC_minitab_header ul {
7684: margin:0;
7685: padding:10px 10px 0;
7686: list-style:none;
7687: }
7688: #LC_minitab_header li {
7689: float:left;
7690: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
7691: margin:0;
7692: padding:0 0 0 9px;
7693: }
7694: #LC_minitab_header a {
7695: display:block;
7696: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
7697: padding:5px 15px 4px 6px;
7698: }
7699: #LC_minitab_header #LC_current_minitab {
7700: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
7701: }
7702: #LC_minitab_header #LC_current_minitab a {
7703: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
7704: padding-bottom:5px;
7705: }
7706:
7707:
1.343 albertel 7708: END
7709: }
7710:
1.306 albertel 7711: =pod
7712:
7713: =item * &headtag()
7714:
7715: Returns a uniform footer for LON-CAPA web pages.
7716:
1.307 albertel 7717: Inputs: $title - optional title for the head
7718: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7719: $args - optional arguments
1.319 albertel 7720: force_register - if is true call registerurl so the remote is
7721: informed
1.415 albertel 7722: redirect -> array ref of
7723: 1- seconds before redirect occurs
7724: 2- url to redirect to
7725: 3- whether the side effect should occur
1.315 albertel 7726: (side effect of setting
7727: $env{'internal.head.redirect'} to the url
7728: redirected too)
1.352 albertel 7729: domain -> force to color decorate a page for a specific
7730: domain
7731: function -> force usage of a specific rolish color scheme
7732: bgcolor -> override the default page bgcolor
1.460 albertel 7733: no_auto_mt_title
7734: -> prevent &mt()ing the title arg
1.464 albertel 7735:
1.306 albertel 7736: =cut
7737:
7738: sub headtag {
1.313 albertel 7739: my ($title,$head_extra,$args) = @_;
1.306 albertel 7740:
1.363 albertel 7741: my $function = $args->{'function'} || &get_users_function();
7742: my $domain = $args->{'domain'} || &determinedomain();
7743: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7744: my $httphost = $args->{'use_absolute'};
1.418 albertel 7745: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7746: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7747: #time(),
1.418 albertel 7748: $env{'environment.color.timestamp'},
1.363 albertel 7749: $function,$domain,$bgcolor);
7750:
1.369 www 7751: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7752:
1.308 albertel 7753: my $result =
7754: '<head>'.
1.1075.2.56 raeburn 7755: &font_settings($args);
1.319 albertel 7756:
1.1075.2.72 raeburn 7757: my $inhibitprint;
7758: if ($args->{'print_suppress'}) {
7759: $inhibitprint = &print_suppression();
7760: }
1.1064 raeburn 7761:
1.461 albertel 7762: if (!$args->{'frameset'}) {
7763: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7764: }
1.1075.2.12 raeburn 7765: if ($args->{'force_register'}) {
7766: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7767: }
1.436 albertel 7768: if (!$args->{'no_nav_bar'}
7769: && !$args->{'only_body'}
7770: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7771: $result .= &help_menu_js($httphost);
1.1032 www 7772: $result.=&modal_window();
1.1038 www 7773: $result.=&togglebox_script();
1.1034 www 7774: $result.=&wishlist_window();
1.1041 www 7775: $result.=&LCprogressbarUpdate_script();
1.1034 www 7776: } else {
7777: if ($args->{'add_modal'}) {
7778: $result.=&modal_window();
7779: }
7780: if ($args->{'add_wishlist'}) {
7781: $result.=&wishlist_window();
7782: }
1.1038 www 7783: if ($args->{'add_togglebox'}) {
7784: $result.=&togglebox_script();
7785: }
1.1041 www 7786: if ($args->{'add_progressbar'}) {
7787: $result.=&LCprogressbarUpdate_script();
7788: }
1.436 albertel 7789: }
1.314 albertel 7790: if (ref($args->{'redirect'})) {
1.414 albertel 7791: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7792: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7793: if (!$inhibit_continue) {
7794: $env{'internal.head.redirect'} = $url;
7795: }
1.313 albertel 7796: $result.=<<ADDMETA
7797: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7798: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7799: ADDMETA
1.1075.2.89 raeburn 7800: } else {
7801: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
7802: my $requrl = $env{'request.uri'};
7803: if ($requrl eq '') {
7804: $requrl = $ENV{'REQUEST_URI'};
7805: $requrl =~ s/\?.+$//;
7806: }
7807: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
7808: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
7809: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
7810: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
7811: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
7812: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
7813: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
7814: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7815: if ($domdefs{'offloadnow'}{$lonhost}) {
7816: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
7817: if (($newserver) && ($newserver ne $lonhost)) {
7818: my $numsec = 5;
7819: my $timeout = $numsec * 1000;
7820: my ($newurl,$locknum,%locks,$msg);
7821: if ($env{'request.role.adv'}) {
7822: ($locknum,%locks) = &Apache::lonnet::get_locks();
7823: }
7824: my $disable_submit = 0;
7825: if ($requrl =~ /$LONCAPA::assess_re/) {
7826: $disable_submit = 1;
7827: }
7828: if ($locknum) {
7829: my @lockinfo = sort(values(%locks));
7830: $msg = &mt('Once the following tasks are complete: ')."\\n".
7831: join(", ",sort(values(%locks)))."\\n".
7832: &mt('your session will be transferred to a different server, after you click "Roles".');
7833: } else {
7834: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
7835: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
7836: }
7837: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
7838: $newurl = '/adm/switchserver?otherserver='.$newserver;
7839: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
7840: $newurl .= '&role='.$env{'request.role'};
7841: }
7842: if ($env{'request.symb'}) {
7843: $newurl .= '&symb='.$env{'request.symb'};
7844: } else {
7845: $newurl .= '&origurl='.$requrl;
7846: }
7847: }
1.1075.2.98 raeburn 7848: &js_escape(\$msg);
1.1075.2.89 raeburn 7849: $result.=<<OFFLOAD
7850: <meta http-equiv="pragma" content="no-cache" />
7851: <script type="text/javascript">
1.1075.2.92 raeburn 7852: // <![CDATA[
1.1075.2.89 raeburn 7853: function LC_Offload_Now() {
7854: var dest = "$newurl";
7855: if (dest != '') {
7856: window.location.href="$newurl";
7857: }
7858: }
1.1075.2.92 raeburn 7859: \$(document).ready(function () {
7860: window.alert('$msg');
7861: if ($disable_submit) {
1.1075.2.89 raeburn 7862: \$(".LC_hwk_submit").prop("disabled", true);
7863: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 7864: }
7865: setTimeout('LC_Offload_Now()', $timeout);
7866: });
7867: // ]]>
1.1075.2.89 raeburn 7868: </script>
7869: OFFLOAD
7870: }
7871: }
7872: }
7873: }
7874: }
7875: }
1.313 albertel 7876: }
1.306 albertel 7877: if (!defined($title)) {
7878: $title = 'The LearningOnline Network with CAPA';
7879: }
1.460 albertel 7880: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7881: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 7882: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7883: if (!$args->{'frameset'}) {
7884: $result .= ' /';
7885: }
7886: $result .= '>'
1.1064 raeburn 7887: .$inhibitprint
1.414 albertel 7888: .$head_extra;
1.1075.2.108 raeburn 7889: my $clientmobile;
7890: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
7891: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
7892: } else {
7893: $clientmobile = $env{'browser.mobile'};
7894: }
7895: if ($clientmobile) {
1.1075.2.42 raeburn 7896: $result .= '
7897: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7898: <meta name="apple-mobile-web-app-capable" content="yes" />';
7899: }
1.1075.2.126 raeburn 7900: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 7901: return $result.'</head>';
1.306 albertel 7902: }
7903:
7904: =pod
7905:
1.340 albertel 7906: =item * &font_settings()
7907:
7908: Returns neccessary <meta> to set the proper encoding
7909:
1.1075.2.56 raeburn 7910: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7911:
7912: =cut
7913:
7914: sub font_settings {
1.1075.2.56 raeburn 7915: my ($args) = @_;
1.340 albertel 7916: my $headerstring='';
1.1075.2.56 raeburn 7917: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7918: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 7919: $headerstring.=
1.1075.2.61 raeburn 7920: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7921: if (!$args->{'frameset'}) {
7922: $headerstring.= ' /';
7923: }
7924: $headerstring .= '>'."\n";
1.340 albertel 7925: }
7926: return $headerstring;
7927: }
7928:
1.341 albertel 7929: =pod
7930:
1.1064 raeburn 7931: =item * &print_suppression()
7932:
7933: In course context returns css which causes the body to be blank when media="print",
7934: if printout generation is unavailable for the current resource.
7935:
7936: This could be because:
7937:
7938: (a) printstartdate is in the future
7939:
7940: (b) printenddate is in the past
7941:
7942: (c) there is an active exam block with "printout"
7943: functionality blocked
7944:
7945: Users with pav, pfo or evb privileges are exempt.
7946:
7947: Inputs: none
7948:
7949: =cut
7950:
7951:
7952: sub print_suppression {
7953: my $noprint;
7954: if ($env{'request.course.id'}) {
7955: my $scope = $env{'request.course.id'};
7956: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7957: (&Apache::lonnet::allowed('pfo',$scope))) {
7958: return;
7959: }
7960: if ($env{'request.course.sec'} ne '') {
7961: $scope .= "/$env{'request.course.sec'}";
7962: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7963: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7964: return;
1.1064 raeburn 7965: }
7966: }
7967: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7968: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73 raeburn 7969: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 7970: if ($blocked) {
7971: my $checkrole = "cm./$cdom/$cnum";
7972: if ($env{'request.course.sec'} ne '') {
7973: $checkrole .= "/$env{'request.course.sec'}";
7974: }
7975: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7976: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7977: $noprint = 1;
7978: }
7979: }
7980: unless ($noprint) {
7981: my $symb = &Apache::lonnet::symbread();
7982: if ($symb ne '') {
7983: my $navmap = Apache::lonnavmaps::navmap->new();
7984: if (ref($navmap)) {
7985: my $res = $navmap->getBySymb($symb);
7986: if (ref($res)) {
7987: if (!$res->resprintable()) {
7988: $noprint = 1;
7989: }
7990: }
7991: }
7992: }
7993: }
7994: if ($noprint) {
7995: return <<"ENDSTYLE";
7996: <style type="text/css" media="print">
7997: body { display:none }
7998: </style>
7999: ENDSTYLE
8000: }
8001: }
8002: return;
8003: }
8004:
8005: =pod
8006:
1.341 albertel 8007: =item * &xml_begin()
8008:
8009: Returns the needed doctype and <html>
8010:
8011: Inputs: none
8012:
8013: =cut
8014:
8015: sub xml_begin {
1.1075.2.61 raeburn 8016: my ($is_frameset) = @_;
1.341 albertel 8017: my $output='';
8018:
8019: if ($env{'browser.mathml'}) {
8020: $output='<?xml version="1.0"?>'
8021: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8022: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8023:
8024: # .'<!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">] >'
8025: .'<!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">'
8026: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8027: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8028: } elsif ($is_frameset) {
8029: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8030: '<html>'."\n";
1.341 albertel 8031: } else {
1.1075.2.61 raeburn 8032: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8033: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8034: }
8035: return $output;
8036: }
1.340 albertel 8037:
8038: =pod
8039:
1.306 albertel 8040: =item * &start_page()
8041:
8042: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8043:
1.648 raeburn 8044: Inputs:
8045:
8046: =over 4
8047:
8048: $title - optional title for the page
8049:
8050: $head_extra - optional extra HTML to incude inside the <head>
8051:
8052: $args - additional optional args supported are:
8053:
8054: =over 8
8055:
8056: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8057: arg on
1.814 bisitz 8058: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8059: add_entries -> additional attributes to add to the <body>
8060: domain -> force to color decorate a page for a
1.317 albertel 8061: specific domain
1.648 raeburn 8062: function -> force usage of a specific rolish color
1.317 albertel 8063: scheme
1.648 raeburn 8064: redirect -> see &headtag()
8065: bgcolor -> override the default page bg color
8066: js_ready -> return a string ready for being used in
1.317 albertel 8067: a javascript writeln
1.648 raeburn 8068: html_encode -> return a string ready for being used in
1.320 albertel 8069: a html attribute
1.648 raeburn 8070: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8071: $forcereg arg
1.648 raeburn 8072: frameset -> if true will start with a <frameset>
1.330 albertel 8073: rather than <body>
1.648 raeburn 8074: skip_phases -> hash ref of
1.338 albertel 8075: head -> skip the <html><head> generation
8076: body -> skip all <body> generation
1.1075.2.12 raeburn 8077: no_inline_link -> if true and in remote mode, don't show the
8078: 'Switch To Inline Menu' link
1.648 raeburn 8079: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8080: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8081: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8082: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8083: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8084: group -> includes the current group, if page is for a
8085: specific group
1.361 albertel 8086:
1.648 raeburn 8087: =back
1.460 albertel 8088:
1.648 raeburn 8089: =back
1.562 albertel 8090:
1.306 albertel 8091: =cut
8092:
8093: sub start_page {
1.309 albertel 8094: my ($title,$head_extra,$args) = @_;
1.318 albertel 8095: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8096:
1.315 albertel 8097: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 8098: my ($result,@advtools);
1.964 droeschl 8099:
1.338 albertel 8100: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8101: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8102: }
8103:
8104: if (! exists($args->{'skip_phases'}{'body'}) ) {
8105: if ($args->{'frameset'}) {
8106: my $attr_string = &make_attr_string($args->{'force_register'},
8107: $args->{'add_entries'});
8108: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8109: } else {
8110: $result .=
8111: &bodytag($title,
8112: $args->{'function'}, $args->{'add_entries'},
8113: $args->{'only_body'}, $args->{'domain'},
8114: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8115: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 8116: $args, \@advtools);
1.831 bisitz 8117: }
1.330 albertel 8118: }
1.338 albertel 8119:
1.315 albertel 8120: if ($args->{'js_ready'}) {
1.713 kaisler 8121: $result = &js_ready($result);
1.315 albertel 8122: }
1.320 albertel 8123: if ($args->{'html_encode'}) {
1.713 kaisler 8124: $result = &html_encode($result);
8125: }
8126:
1.813 bisitz 8127: # Preparation for new and consistent functionlist at top of screen
8128: # if ($args->{'functionlist'}) {
8129: # $result .= &build_functionlist();
8130: #}
8131:
1.964 droeschl 8132: # Don't add anything more if only_body wanted or in const space
8133: return $result if $args->{'only_body'}
8134: || $env{'request.state'} eq 'construct';
1.813 bisitz 8135:
8136: #Breadcrumbs
1.758 kaisler 8137: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8138: &Apache::lonhtmlcommon::clear_breadcrumbs();
8139: #if any br links exists, add them to the breadcrumbs
8140: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8141: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8142: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8143: }
8144: }
1.1075.2.19 raeburn 8145: # if @advtools array contains items add then to the breadcrumbs
8146: if (@advtools > 0) {
8147: &Apache::lonmenu::advtools_crumbs(@advtools);
8148: }
1.1075.2.123 raeburn 8149: my $menulink;
8150: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8151: if (exists($args->{'bread_crumbs_nomenu'})) {
8152: $menulink = 0;
8153: } else {
8154: undef($menulink);
8155: }
1.758 kaisler 8156: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8157: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 8158: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.758 kaisler 8159: }else{
1.1075.2.123 raeburn 8160: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8161: }
1.1075.2.24 raeburn 8162: } elsif (($env{'environment.remote'} eq 'on') &&
8163: ($env{'form.inhibitmenu'} ne 'yes') &&
8164: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8165: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8166: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8167: }
1.315 albertel 8168: return $result;
1.306 albertel 8169: }
8170:
8171: sub end_page {
1.315 albertel 8172: my ($args) = @_;
8173: $env{'internal.end_page'}++;
1.330 albertel 8174: my $result;
1.335 albertel 8175: if ($args->{'discussion'}) {
8176: my ($target,$parser);
8177: if (ref($args->{'discussion'})) {
8178: ($target,$parser) =($args->{'discussion'}{'target'},
8179: $args->{'discussion'}{'parser'});
8180: }
8181: $result .= &Apache::lonxml::xmlend($target,$parser);
8182: }
1.330 albertel 8183: if ($args->{'frameset'}) {
8184: $result .= '</frameset>';
8185: } else {
1.635 raeburn 8186: $result .= &endbodytag($args);
1.330 albertel 8187: }
1.1075.2.6 raeburn 8188: unless ($args->{'notbody'}) {
8189: $result .= "\n</html>";
8190: }
1.330 albertel 8191:
1.315 albertel 8192: if ($args->{'js_ready'}) {
1.317 albertel 8193: $result = &js_ready($result);
1.315 albertel 8194: }
1.335 albertel 8195:
1.320 albertel 8196: if ($args->{'html_encode'}) {
8197: $result = &html_encode($result);
8198: }
1.335 albertel 8199:
1.315 albertel 8200: return $result;
8201: }
8202:
1.1034 www 8203: sub wishlist_window {
8204: return(<<'ENDWISHLIST');
1.1046 raeburn 8205: <script type="text/javascript">
1.1034 www 8206: // <![CDATA[
8207: // <!-- BEGIN LON-CAPA Internal
8208: function set_wishlistlink(title, path) {
8209: if (!title) {
8210: title = document.title;
8211: title = title.replace(/^LON-CAPA /,'');
8212: }
1.1075.2.65 raeburn 8213: title = encodeURIComponent(title);
1.1075.2.83 raeburn 8214: title = title.replace("'","\\\'");
1.1034 www 8215: if (!path) {
8216: path = location.pathname;
8217: }
1.1075.2.65 raeburn 8218: path = encodeURIComponent(path);
1.1075.2.83 raeburn 8219: path = path.replace("'","\\\'");
1.1034 www 8220: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8221: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8222: }
8223: // END LON-CAPA Internal -->
8224: // ]]>
8225: </script>
8226: ENDWISHLIST
8227: }
8228:
1.1030 www 8229: sub modal_window {
8230: return(<<'ENDMODAL');
1.1046 raeburn 8231: <script type="text/javascript">
1.1030 www 8232: // <![CDATA[
8233: // <!-- BEGIN LON-CAPA Internal
8234: var modalWindow = {
8235: parent:"body",
8236: windowId:null,
8237: content:null,
8238: width:null,
8239: height:null,
8240: close:function()
8241: {
8242: $(".LCmodal-window").remove();
8243: $(".LCmodal-overlay").remove();
8244: },
8245: open:function()
8246: {
8247: var modal = "";
8248: modal += "<div class=\"LCmodal-overlay\"></div>";
8249: 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;\">";
8250: modal += this.content;
8251: modal += "</div>";
8252:
8253: $(this.parent).append(modal);
8254:
8255: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8256: $(".LCclose-window").click(function(){modalWindow.close();});
8257: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8258: }
8259: };
1.1075.2.42 raeburn 8260: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8261: {
1.1075.2.119 raeburn 8262: source = source.replace(/'/g,"'");
1.1030 www 8263: modalWindow.windowId = "myModal";
8264: modalWindow.width = width;
8265: modalWindow.height = height;
1.1075.2.80 raeburn 8266: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8267: modalWindow.open();
1.1075.2.87 raeburn 8268: };
1.1030 www 8269: // END LON-CAPA Internal -->
8270: // ]]>
8271: </script>
8272: ENDMODAL
8273: }
8274:
8275: sub modal_link {
1.1075.2.42 raeburn 8276: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8277: unless ($width) { $width=480; }
8278: unless ($height) { $height=400; }
1.1031 www 8279: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 8280: unless ($transparency) { $transparency='true'; }
8281:
1.1074 raeburn 8282: my $target_attr;
8283: if (defined($target)) {
8284: $target_attr = 'target="'.$target.'"';
8285: }
8286: return <<"ENDLINK";
1.1075.2.42 raeburn 8287: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8288: $linktext</a>
8289: ENDLINK
1.1030 www 8290: }
8291:
1.1032 www 8292: sub modal_adhoc_script {
8293: my ($funcname,$width,$height,$content)=@_;
8294: return (<<ENDADHOC);
1.1046 raeburn 8295: <script type="text/javascript">
1.1032 www 8296: // <![CDATA[
8297: var $funcname = function()
8298: {
8299: modalWindow.windowId = "myModal";
8300: modalWindow.width = $width;
8301: modalWindow.height = $height;
8302: modalWindow.content = '$content';
8303: modalWindow.open();
8304: };
8305: // ]]>
8306: </script>
8307: ENDADHOC
8308: }
8309:
1.1041 www 8310: sub modal_adhoc_inner {
8311: my ($funcname,$width,$height,$content)=@_;
8312: my $innerwidth=$width-20;
8313: $content=&js_ready(
1.1042 www 8314: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 8315: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8316: $content.
1.1041 www 8317: &end_scrollbox().
1.1075.2.42 raeburn 8318: &end_page()
1.1041 www 8319: );
8320: return &modal_adhoc_script($funcname,$width,$height,$content);
8321: }
8322:
8323: sub modal_adhoc_window {
8324: my ($funcname,$width,$height,$content,$linktext)=@_;
8325: return &modal_adhoc_inner($funcname,$width,$height,$content).
8326: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8327: }
8328:
8329: sub modal_adhoc_launch {
8330: my ($funcname,$width,$height,$content)=@_;
8331: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8332: <script type="text/javascript">
8333: // <![CDATA[
8334: $funcname();
8335: // ]]>
8336: </script>
8337: ENDLAUNCH
8338: }
8339:
8340: sub modal_adhoc_close {
8341: return (<<ENDCLOSE);
8342: <script type="text/javascript">
8343: // <![CDATA[
8344: modalWindow.close();
8345: // ]]>
8346: </script>
8347: ENDCLOSE
8348: }
8349:
1.1038 www 8350: sub togglebox_script {
8351: return(<<ENDTOGGLE);
8352: <script type="text/javascript">
8353: // <![CDATA[
8354: function LCtoggleDisplay(id,hidetext,showtext) {
8355: link = document.getElementById(id + "link").childNodes[0];
8356: with (document.getElementById(id).style) {
8357: if (display == "none" ) {
8358: display = "inline";
8359: link.nodeValue = hidetext;
8360: } else {
8361: display = "none";
8362: link.nodeValue = showtext;
8363: }
8364: }
8365: }
8366: // ]]>
8367: </script>
8368: ENDTOGGLE
8369: }
8370:
1.1039 www 8371: sub start_togglebox {
8372: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8373: unless ($heading) { $heading=''; } else { $heading.=' '; }
8374: unless ($showtext) { $showtext=&mt('show'); }
8375: unless ($hidetext) { $hidetext=&mt('hide'); }
8376: unless ($headerbg) { $headerbg='#FFFFFF'; }
8377: return &start_data_table().
8378: &start_data_table_header_row().
8379: '<td bgcolor="'.$headerbg.'">'.$heading.
8380: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8381: $showtext.'\')">'.$showtext.'</a>]</td>'.
8382: &end_data_table_header_row().
8383: '<tr id="'.$id.'" style="display:none""><td>';
8384: }
8385:
8386: sub end_togglebox {
8387: return '</td></tr>'.&end_data_table();
8388: }
8389:
1.1041 www 8390: sub LCprogressbar_script {
1.1045 www 8391: my ($id)=@_;
1.1041 www 8392: return(<<ENDPROGRESS);
8393: <script type="text/javascript">
8394: // <![CDATA[
1.1045 www 8395: \$('#progressbar$id').progressbar({
1.1041 www 8396: value: 0,
8397: change: function(event, ui) {
8398: var newVal = \$(this).progressbar('option', 'value');
8399: \$('.pblabel', this).text(LCprogressTxt);
8400: }
8401: });
8402: // ]]>
8403: </script>
8404: ENDPROGRESS
8405: }
8406:
8407: sub LCprogressbarUpdate_script {
8408: return(<<ENDPROGRESSUPDATE);
8409: <style type="text/css">
8410: .ui-progressbar { position:relative; }
8411: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8412: </style>
8413: <script type="text/javascript">
8414: // <![CDATA[
1.1045 www 8415: var LCprogressTxt='---';
8416:
8417: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8418: LCprogressTxt=progresstext;
1.1045 www 8419: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8420: }
8421: // ]]>
8422: </script>
8423: ENDPROGRESSUPDATE
8424: }
8425:
1.1042 www 8426: my $LClastpercent;
1.1045 www 8427: my $LCidcnt;
8428: my $LCcurrentid;
1.1042 www 8429:
1.1041 www 8430: sub LCprogressbar {
1.1042 www 8431: my ($r)=(@_);
8432: $LClastpercent=0;
1.1045 www 8433: $LCidcnt++;
8434: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8435: my $starting=&mt('Starting');
8436: my $content=(<<ENDPROGBAR);
1.1045 www 8437: <div id="progressbar$LCcurrentid">
1.1041 www 8438: <span class="pblabel">$starting</span>
8439: </div>
8440: ENDPROGBAR
1.1045 www 8441: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8442: }
8443:
8444: sub LCprogressbarUpdate {
1.1042 www 8445: my ($r,$val,$text)=@_;
8446: unless ($val) {
8447: if ($LClastpercent) {
8448: $val=$LClastpercent;
8449: } else {
8450: $val=0;
8451: }
8452: }
1.1041 www 8453: if ($val<0) { $val=0; }
8454: if ($val>100) { $val=0; }
1.1042 www 8455: $LClastpercent=$val;
1.1041 www 8456: unless ($text) { $text=$val.'%'; }
8457: $text=&js_ready($text);
1.1044 www 8458: &r_print($r,<<ENDUPDATE);
1.1041 www 8459: <script type="text/javascript">
8460: // <![CDATA[
1.1045 www 8461: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8462: // ]]>
8463: </script>
8464: ENDUPDATE
1.1035 www 8465: }
8466:
1.1042 www 8467: sub LCprogressbarClose {
8468: my ($r)=@_;
8469: $LClastpercent=0;
1.1044 www 8470: &r_print($r,<<ENDCLOSE);
1.1042 www 8471: <script type="text/javascript">
8472: // <![CDATA[
1.1045 www 8473: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8474: // ]]>
8475: </script>
8476: ENDCLOSE
1.1044 www 8477: }
8478:
8479: sub r_print {
8480: my ($r,$to_print)=@_;
8481: if ($r) {
8482: $r->print($to_print);
8483: $r->rflush();
8484: } else {
8485: print($to_print);
8486: }
1.1042 www 8487: }
8488:
1.320 albertel 8489: sub html_encode {
8490: my ($result) = @_;
8491:
1.322 albertel 8492: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8493:
8494: return $result;
8495: }
1.1044 www 8496:
1.317 albertel 8497: sub js_ready {
8498: my ($result) = @_;
8499:
1.323 albertel 8500: $result =~ s/[\n\r]/ /xmsg;
8501: $result =~ s/\\/\\\\/xmsg;
8502: $result =~ s/'/\\'/xmsg;
1.372 albertel 8503: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8504:
8505: return $result;
8506: }
8507:
1.315 albertel 8508: sub validate_page {
8509: if ( exists($env{'internal.start_page'})
1.316 albertel 8510: && $env{'internal.start_page'} > 1) {
8511: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8512: $env{'internal.start_page'}.' '.
1.316 albertel 8513: $ENV{'request.filename'});
1.315 albertel 8514: }
8515: if ( exists($env{'internal.end_page'})
1.316 albertel 8516: && $env{'internal.end_page'} > 1) {
8517: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8518: $env{'internal.end_page'}.' '.
1.316 albertel 8519: $env{'request.filename'});
1.315 albertel 8520: }
8521: if ( exists($env{'internal.start_page'})
8522: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8523: &Apache::lonnet::logthis('start_page called without end_page '.
8524: $env{'request.filename'});
1.315 albertel 8525: }
8526: if ( ! exists($env{'internal.start_page'})
8527: && exists($env{'internal.end_page'})) {
1.316 albertel 8528: &Apache::lonnet::logthis('end_page called without start_page'.
8529: $env{'request.filename'});
1.315 albertel 8530: }
1.306 albertel 8531: }
1.315 albertel 8532:
1.996 www 8533:
8534: sub start_scrollbox {
1.1075.2.56 raeburn 8535: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8536: unless ($outerwidth) { $outerwidth='520px'; }
8537: unless ($width) { $width='500px'; }
8538: unless ($height) { $height='200px'; }
1.1075 raeburn 8539: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8540: if ($id ne '') {
1.1075.2.42 raeburn 8541: $table_id = ' id="table_'.$id.'"';
8542: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8543: }
1.1075 raeburn 8544: if ($bgcolor ne '') {
8545: $tdcol = "background-color: $bgcolor;";
8546: }
1.1075.2.42 raeburn 8547: my $nicescroll_js;
8548: if ($env{'browser.mobile'}) {
8549: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8550: }
1.1075 raeburn 8551: return <<"END";
1.1075.2.42 raeburn 8552: $nicescroll_js
8553:
8554: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8555: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8556: END
1.996 www 8557: }
8558:
8559: sub end_scrollbox {
1.1036 www 8560: return '</div></td></tr></table>';
1.996 www 8561: }
8562:
1.1075.2.42 raeburn 8563: sub nicescroll_javascript {
8564: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8565: my %options;
8566: if (ref($cursor) eq 'HASH') {
8567: %options = %{$cursor};
8568: }
8569: unless ($options{'railalign'} =~ /^left|right$/) {
8570: $options{'railalign'} = 'left';
8571: }
8572: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8573: my $function = &get_users_function();
8574: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8575: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8576: $options{'cursorcolor'} = '#00F';
8577: }
8578: }
8579: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8580: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8581: $options{'cursoropacity'}='1.0';
8582: }
8583: } else {
8584: $options{'cursoropacity'}='1.0';
8585: }
8586: if ($options{'cursorfixedheight'} eq 'none') {
8587: delete($options{'cursorfixedheight'});
8588: } else {
8589: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8590: }
8591: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8592: delete($options{'railoffset'});
8593: }
8594: my @niceoptions;
8595: while (my($key,$value) = each(%options)) {
8596: if ($value =~ /^\{.+\}$/) {
8597: push(@niceoptions,$key.':'.$value);
8598: } else {
8599: push(@niceoptions,$key.':"'.$value.'"');
8600: }
8601: }
8602: my $nicescroll_js = '
8603: $(document).ready(
8604: function() {
8605: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8606: }
8607: );
8608: ';
8609: if ($framecheck) {
8610: $nicescroll_js .= '
8611: function expand_div(caller) {
8612: if (top === self) {
8613: document.getElementById("'.$id.'").style.width = "auto";
8614: document.getElementById("'.$id.'").style.height = "auto";
8615: } else {
8616: try {
8617: if (parent.frames) {
8618: if (parent.frames.length > 1) {
8619: var framesrc = parent.frames[1].location.href;
8620: var currsrc = framesrc.replace(/\#.*$/,"");
8621: if ((caller == "search") || (currsrc == "'.$location.'")) {
8622: document.getElementById("'.$id.'").style.width = "auto";
8623: document.getElementById("'.$id.'").style.height = "auto";
8624: }
8625: }
8626: }
8627: } catch (e) {
8628: return;
8629: }
8630: }
8631: return;
8632: }
8633: ';
8634: }
8635: if ($needjsready) {
8636: $nicescroll_js = '
8637: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8638: } else {
8639: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8640: }
8641: return $nicescroll_js;
8642: }
8643:
1.318 albertel 8644: sub simple_error_page {
1.1075.2.49 raeburn 8645: my ($r,$title,$msg,$args) = @_;
8646: if (ref($args) eq 'HASH') {
8647: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8648: } else {
8649: $msg = &mt($msg);
8650: }
8651:
1.318 albertel 8652: my $page =
8653: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8654: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8655: &Apache::loncommon::end_page();
8656: if (ref($r)) {
8657: $r->print($page);
1.327 albertel 8658: return;
1.318 albertel 8659: }
8660: return $page;
8661: }
1.347 albertel 8662:
8663: {
1.610 albertel 8664: my @row_count;
1.961 onken 8665:
8666: sub start_data_table_count {
8667: unshift(@row_count, 0);
8668: return;
8669: }
8670:
8671: sub end_data_table_count {
8672: shift(@row_count);
8673: return;
8674: }
8675:
1.347 albertel 8676: sub start_data_table {
1.1018 raeburn 8677: my ($add_class,$id) = @_;
1.422 albertel 8678: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8679: my $table_id;
8680: if (defined($id)) {
8681: $table_id = ' id="'.$id.'"';
8682: }
1.961 onken 8683: &start_data_table_count();
1.1018 raeburn 8684: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8685: }
8686:
8687: sub end_data_table {
1.961 onken 8688: &end_data_table_count();
1.389 albertel 8689: return '</table>'."\n";;
1.347 albertel 8690: }
8691:
8692: sub start_data_table_row {
1.974 wenzelju 8693: my ($add_class, $id) = @_;
1.610 albertel 8694: $row_count[0]++;
8695: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8696: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8697: $id = (' id="'.$id.'"') unless ($id eq '');
8698: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8699: }
1.471 banghart 8700:
8701: sub continue_data_table_row {
1.974 wenzelju 8702: my ($add_class, $id) = @_;
1.610 albertel 8703: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8704: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8705: $id = (' id="'.$id.'"') unless ($id eq '');
8706: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8707: }
1.347 albertel 8708:
8709: sub end_data_table_row {
1.389 albertel 8710: return '</tr>'."\n";;
1.347 albertel 8711: }
1.367 www 8712:
1.421 albertel 8713: sub start_data_table_empty_row {
1.707 bisitz 8714: # $row_count[0]++;
1.421 albertel 8715: return '<tr class="LC_empty_row" >'."\n";;
8716: }
8717:
8718: sub end_data_table_empty_row {
8719: return '</tr>'."\n";;
8720: }
8721:
1.367 www 8722: sub start_data_table_header_row {
1.389 albertel 8723: return '<tr class="LC_header_row">'."\n";;
1.367 www 8724: }
8725:
8726: sub end_data_table_header_row {
1.389 albertel 8727: return '</tr>'."\n";;
1.367 www 8728: }
1.890 droeschl 8729:
8730: sub data_table_caption {
8731: my $caption = shift;
8732: return "<caption class=\"LC_caption\">$caption</caption>";
8733: }
1.347 albertel 8734: }
8735:
1.548 albertel 8736: =pod
8737:
8738: =item * &inhibit_menu_check($arg)
8739:
8740: Checks for a inhibitmenu state and generates output to preserve it
8741:
8742: Inputs: $arg - can be any of
8743: - undef - in which case the return value is a string
8744: to add into arguments list of a uri
8745: - 'input' - in which case the return value is a HTML
8746: <form> <input> field of type hidden to
8747: preserve the value
8748: - a url - in which case the return value is the url with
8749: the neccesary cgi args added to preserve the
8750: inhibitmenu state
8751: - a ref to a url - no return value, but the string is
8752: updated to include the neccessary cgi
8753: args to preserve the inhibitmenu state
8754:
8755: =cut
8756:
8757: sub inhibit_menu_check {
8758: my ($arg) = @_;
8759: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8760: if ($arg eq 'input') {
8761: if ($env{'form.inhibitmenu'}) {
8762: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8763: } else {
8764: return
8765: }
8766: }
8767: if ($env{'form.inhibitmenu'}) {
8768: if (ref($arg)) {
8769: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8770: } elsif ($arg eq '') {
8771: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8772: } else {
8773: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8774: }
8775: }
8776: if (!ref($arg)) {
8777: return $arg;
8778: }
8779: }
8780:
1.251 albertel 8781: ###############################################
1.182 matthew 8782:
8783: =pod
8784:
1.549 albertel 8785: =back
8786:
8787: =head1 User Information Routines
8788:
8789: =over 4
8790:
1.405 albertel 8791: =item * &get_users_function()
1.182 matthew 8792:
8793: Used by &bodytag to determine the current users primary role.
8794: Returns either 'student','coordinator','admin', or 'author'.
8795:
8796: =cut
8797:
8798: ###############################################
8799: sub get_users_function {
1.815 tempelho 8800: my $function = 'norole';
1.818 tempelho 8801: if ($env{'request.role'}=~/^(st)/) {
8802: $function='student';
8803: }
1.907 raeburn 8804: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8805: $function='coordinator';
8806: }
1.258 albertel 8807: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8808: $function='admin';
8809: }
1.826 bisitz 8810: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8811: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8812: $function='author';
8813: }
8814: return $function;
1.54 www 8815: }
1.99 www 8816:
8817: ###############################################
8818:
1.233 raeburn 8819: =pod
8820:
1.821 raeburn 8821: =item * &show_course()
8822:
8823: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8824: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8825:
8826: Inputs:
8827: None
8828:
8829: Outputs:
8830: Scalar: 1 if 'Course' to be used, 0 otherwise.
8831:
8832: =cut
8833:
8834: ###############################################
8835: sub show_course {
8836: my $course = !$env{'user.adv'};
8837: if (!$env{'user.adv'}) {
8838: foreach my $env (keys(%env)) {
8839: next if ($env !~ m/^user\.priv\./);
8840: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8841: $course = 0;
8842: last;
8843: }
8844: }
8845: }
8846: return $course;
8847: }
8848:
8849: ###############################################
8850:
8851: =pod
8852:
1.542 raeburn 8853: =item * &check_user_status()
1.274 raeburn 8854:
8855: Determines current status of supplied role for a
8856: specific user. Roles can be active, previous or future.
8857:
8858: Inputs:
8859: user's domain, user's username, course's domain,
1.375 raeburn 8860: course's number, optional section ID.
1.274 raeburn 8861:
8862: Outputs:
8863: role status: active, previous or future.
8864:
8865: =cut
8866:
8867: sub check_user_status {
1.412 raeburn 8868: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8869: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 8870: my @uroles = keys(%userinfo);
1.274 raeburn 8871: my $srchstr;
8872: my $active_chk = 'none';
1.412 raeburn 8873: my $now = time;
1.274 raeburn 8874: if (@uroles > 0) {
1.908 raeburn 8875: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8876: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8877: } else {
1.412 raeburn 8878: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8879: }
8880: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8881: my $role_end = 0;
8882: my $role_start = 0;
8883: $active_chk = 'active';
1.412 raeburn 8884: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8885: $role_end = $1;
8886: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8887: $role_start = $1;
1.274 raeburn 8888: }
8889: }
8890: if ($role_start > 0) {
1.412 raeburn 8891: if ($now < $role_start) {
1.274 raeburn 8892: $active_chk = 'future';
8893: }
8894: }
8895: if ($role_end > 0) {
1.412 raeburn 8896: if ($now > $role_end) {
1.274 raeburn 8897: $active_chk = 'previous';
8898: }
8899: }
8900: }
8901: }
8902: return $active_chk;
8903: }
8904:
8905: ###############################################
8906:
8907: =pod
8908:
1.405 albertel 8909: =item * &get_sections()
1.233 raeburn 8910:
8911: Determines all the sections for a course including
8912: sections with students and sections containing other roles.
1.419 raeburn 8913: Incoming parameters:
8914:
8915: 1. domain
8916: 2. course number
8917: 3. reference to array containing roles for which sections should
8918: be gathered (optional).
8919: 4. reference to array containing status types for which sections
8920: should be gathered (optional).
8921:
8922: If the third argument is undefined, sections are gathered for any role.
8923: If the fourth argument is undefined, sections are gathered for any status.
8924: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8925:
1.374 raeburn 8926: Returns section hash (keys are section IDs, values are
8927: number of users in each section), subject to the
1.419 raeburn 8928: optional roles filter, optional status filter
1.233 raeburn 8929:
8930: =cut
8931:
8932: ###############################################
8933: sub get_sections {
1.419 raeburn 8934: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8935: if (!defined($cdom) || !defined($cnum)) {
8936: my $cid = $env{'request.course.id'};
8937:
8938: return if (!defined($cid));
8939:
8940: $cdom = $env{'course.'.$cid.'.domain'};
8941: $cnum = $env{'course.'.$cid.'.num'};
8942: }
8943:
8944: my %sectioncount;
1.419 raeburn 8945: my $now = time;
1.240 albertel 8946:
1.1075.2.33 raeburn 8947: my $check_students = 1;
8948: my $only_students = 0;
8949: if (ref($possible_roles) eq 'ARRAY') {
8950: if (grep(/^st$/,@{$possible_roles})) {
8951: if (@{$possible_roles} == 1) {
8952: $only_students = 1;
8953: }
8954: } else {
8955: $check_students = 0;
8956: }
8957: }
8958:
8959: if ($check_students) {
1.276 albertel 8960: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8961: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8962: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8963: my $start_index = &Apache::loncoursedata::CL_START();
8964: my $end_index = &Apache::loncoursedata::CL_END();
8965: my $status;
1.366 albertel 8966: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8967: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8968: $data->[$status_index],
8969: $data->[$start_index],
8970: $data->[$end_index]);
8971: if ($stu_status eq 'Active') {
8972: $status = 'active';
8973: } elsif ($end < $now) {
8974: $status = 'previous';
8975: } elsif ($start > $now) {
8976: $status = 'future';
8977: }
8978: if ($section ne '-1' && $section !~ /^\s*$/) {
8979: if ((!defined($possible_status)) || (($status ne '') &&
8980: (grep/^\Q$status\E$/,@{$possible_status}))) {
8981: $sectioncount{$section}++;
8982: }
1.240 albertel 8983: }
8984: }
8985: }
1.1075.2.33 raeburn 8986: if ($only_students) {
8987: return %sectioncount;
8988: }
1.240 albertel 8989: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8990: foreach my $user (sort(keys(%courseroles))) {
8991: if ($user !~ /^(\w{2})/) { next; }
8992: my ($role) = ($user =~ /^(\w{2})/);
8993: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8994: my ($section,$status);
1.240 albertel 8995: if ($role eq 'cr' &&
8996: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8997: $section=$1;
8998: }
8999: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9000: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9001: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9002: if ($end == -1 && $start == -1) {
9003: next; #deleted role
9004: }
9005: if (!defined($possible_status)) {
9006: $sectioncount{$section}++;
9007: } else {
9008: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9009: $status = 'active';
9010: } elsif ($end < $now) {
9011: $status = 'future';
9012: } elsif ($start > $now) {
9013: $status = 'previous';
9014: }
9015: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9016: $sectioncount{$section}++;
9017: }
9018: }
1.233 raeburn 9019: }
1.366 albertel 9020: return %sectioncount;
1.233 raeburn 9021: }
9022:
1.274 raeburn 9023: ###############################################
1.294 raeburn 9024:
9025: =pod
1.405 albertel 9026:
9027: =item * &get_course_users()
9028:
1.275 raeburn 9029: Retrieves usernames:domains for users in the specified course
9030: with specific role(s), and access status.
9031:
9032: Incoming parameters:
1.277 albertel 9033: 1. course domain
9034: 2. course number
9035: 3. access status: users must have - either active,
1.275 raeburn 9036: previous, future, or all.
1.277 albertel 9037: 4. reference to array of permissible roles
1.288 raeburn 9038: 5. reference to array of section restrictions (optional)
9039: 6. reference to results object (hash of hashes).
9040: 7. reference to optional userdata hash
1.609 raeburn 9041: 8. reference to optional statushash
1.630 raeburn 9042: 9. flag if privileged users (except those set to unhide in
9043: course settings) should be excluded
1.609 raeburn 9044: Keys of top level results hash are roles.
1.275 raeburn 9045: Keys of inner hashes are username:domain, with
9046: values set to access type.
1.288 raeburn 9047: Optional userdata hash returns an array with arguments in the
9048: same order as loncoursedata::get_classlist() for student data.
9049:
1.609 raeburn 9050: Optional statushash returns
9051:
1.288 raeburn 9052: Entries for end, start, section and status are blank because
9053: of the possibility of multiple values for non-student roles.
9054:
1.275 raeburn 9055: =cut
1.405 albertel 9056:
1.275 raeburn 9057: ###############################################
1.405 albertel 9058:
1.275 raeburn 9059: sub get_course_users {
1.630 raeburn 9060: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9061: my %idx = ();
1.419 raeburn 9062: my %seclists;
1.288 raeburn 9063:
9064: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9065: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9066: $idx{end} = &Apache::loncoursedata::CL_END();
9067: $idx{start} = &Apache::loncoursedata::CL_START();
9068: $idx{id} = &Apache::loncoursedata::CL_ID();
9069: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9070: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9071: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9072:
1.290 albertel 9073: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9074: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9075: my $now = time;
1.277 albertel 9076: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9077: my $match = 0;
1.412 raeburn 9078: my $secmatch = 0;
1.419 raeburn 9079: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9080: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9081: if ($section eq '') {
9082: $section = 'none';
9083: }
1.291 albertel 9084: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9085: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9086: $secmatch = 1;
9087: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9088: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9089: $secmatch = 1;
9090: }
9091: } else {
1.419 raeburn 9092: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9093: $secmatch = 1;
9094: }
1.290 albertel 9095: }
1.412 raeburn 9096: if (!$secmatch) {
9097: next;
9098: }
1.419 raeburn 9099: }
1.275 raeburn 9100: if (defined($$types{'active'})) {
1.288 raeburn 9101: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9102: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9103: $match = 1;
1.275 raeburn 9104: }
9105: }
9106: if (defined($$types{'previous'})) {
1.609 raeburn 9107: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9108: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9109: $match = 1;
1.275 raeburn 9110: }
9111: }
9112: if (defined($$types{'future'})) {
1.609 raeburn 9113: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9114: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9115: $match = 1;
1.275 raeburn 9116: }
9117: }
1.609 raeburn 9118: if ($match) {
9119: push(@{$seclists{$student}},$section);
9120: if (ref($userdata) eq 'HASH') {
9121: $$userdata{$student} = $$classlist{$student};
9122: }
9123: if (ref($statushash) eq 'HASH') {
9124: $statushash->{$student}{'st'}{$section} = $status;
9125: }
1.288 raeburn 9126: }
1.275 raeburn 9127: }
9128: }
1.412 raeburn 9129: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9130: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9131: my $now = time;
1.609 raeburn 9132: my %displaystatus = ( previous => 'Expired',
9133: active => 'Active',
9134: future => 'Future',
9135: );
1.1075.2.36 raeburn 9136: my (%nothide,@possdoms);
1.630 raeburn 9137: if ($hidepriv) {
9138: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9139: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9140: if ($user !~ /:/) {
9141: $nothide{join(':',split(/[\@]/,$user))}=1;
9142: } else {
9143: $nothide{$user} = 1;
9144: }
9145: }
1.1075.2.36 raeburn 9146: my @possdoms = ($cdom);
9147: if ($coursehash{'checkforpriv'}) {
9148: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9149: }
1.630 raeburn 9150: }
1.439 raeburn 9151: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9152: my $match = 0;
1.412 raeburn 9153: my $secmatch = 0;
1.439 raeburn 9154: my $status;
1.412 raeburn 9155: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9156: $user =~ s/:$//;
1.439 raeburn 9157: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9158: if ($end == -1 || $start == -1) {
9159: next;
9160: }
9161: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9162: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9163: my ($uname,$udom) = split(/:/,$user);
9164: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9165: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9166: $secmatch = 1;
9167: } elsif ($usec eq '') {
1.420 albertel 9168: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9169: $secmatch = 1;
9170: }
9171: } else {
9172: if (grep(/^\Q$usec\E$/,@{$sections})) {
9173: $secmatch = 1;
9174: }
9175: }
9176: if (!$secmatch) {
9177: next;
9178: }
1.288 raeburn 9179: }
1.419 raeburn 9180: if ($usec eq '') {
9181: $usec = 'none';
9182: }
1.275 raeburn 9183: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9184: if ($hidepriv) {
1.1075.2.36 raeburn 9185: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9186: (!$nothide{$uname.':'.$udom})) {
9187: next;
9188: }
9189: }
1.503 raeburn 9190: if ($end > 0 && $end < $now) {
1.439 raeburn 9191: $status = 'previous';
9192: } elsif ($start > $now) {
9193: $status = 'future';
9194: } else {
9195: $status = 'active';
9196: }
1.277 albertel 9197: foreach my $type (keys(%{$types})) {
1.275 raeburn 9198: if ($status eq $type) {
1.420 albertel 9199: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9200: push(@{$$users{$role}{$user}},$type);
9201: }
1.288 raeburn 9202: $match = 1;
9203: }
9204: }
1.419 raeburn 9205: if (($match) && (ref($userdata) eq 'HASH')) {
9206: if (!exists($$userdata{$uname.':'.$udom})) {
9207: &get_user_info($udom,$uname,\%idx,$userdata);
9208: }
1.420 albertel 9209: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9210: push(@{$seclists{$uname.':'.$udom}},$usec);
9211: }
1.609 raeburn 9212: if (ref($statushash) eq 'HASH') {
9213: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9214: }
1.275 raeburn 9215: }
9216: }
9217: }
9218: }
1.290 albertel 9219: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9220: if ((defined($cdom)) && (defined($cnum))) {
9221: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9222: if ( defined($csettings{'internal.courseowner'}) ) {
9223: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9224: next if ($owner eq '');
9225: my ($ownername,$ownerdom);
9226: if ($owner =~ /^([^:]+):([^:]+)$/) {
9227: $ownername = $1;
9228: $ownerdom = $2;
9229: } else {
9230: $ownername = $owner;
9231: $ownerdom = $cdom;
9232: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9233: }
9234: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9235: if (defined($userdata) &&
1.609 raeburn 9236: !exists($$userdata{$owner})) {
9237: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9238: if (!grep(/^none$/,@{$seclists{$owner}})) {
9239: push(@{$seclists{$owner}},'none');
9240: }
9241: if (ref($statushash) eq 'HASH') {
9242: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9243: }
1.290 albertel 9244: }
1.279 raeburn 9245: }
9246: }
9247: }
1.419 raeburn 9248: foreach my $user (keys(%seclists)) {
9249: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9250: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9251: }
1.275 raeburn 9252: }
9253: return;
9254: }
9255:
1.288 raeburn 9256: sub get_user_info {
9257: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9258: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9259: &plainname($uname,$udom,'lastname');
1.291 albertel 9260: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9261: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9262: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9263: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9264: return;
9265: }
1.275 raeburn 9266:
1.472 raeburn 9267: ###############################################
9268:
9269: =pod
9270:
9271: =item * &get_user_quota()
9272:
1.1075.2.41 raeburn 9273: Retrieves quota assigned for storage of user files.
9274: Default is to report quota for portfolio files.
1.472 raeburn 9275:
9276: Incoming parameters:
9277: 1. user's username
9278: 2. user's domain
1.1075.2.41 raeburn 9279: 3. quota name - portfolio, author, or course
9280: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 9281: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 9282: course
1.472 raeburn 9283:
9284: Returns:
1.1075.2.58 raeburn 9285: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9286: 2. (Optional) Type of setting: custom or default
9287: (individually assigned or default for user's
9288: institutional status).
9289: 3. (Optional) - User's institutional status (e.g., faculty, staff
9290: or student - types as defined in localenroll::inst_usertypes
9291: for user's domain, which determines default quota for user.
9292: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9293:
9294: If a value has been stored in the user's environment,
1.536 raeburn 9295: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 9296: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9297:
9298: =cut
9299:
9300: ###############################################
9301:
9302:
9303: sub get_user_quota {
1.1075.2.42 raeburn 9304: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9305: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9306: if (!defined($udom)) {
9307: $udom = $env{'user.domain'};
9308: }
9309: if (!defined($uname)) {
9310: $uname = $env{'user.name'};
9311: }
9312: if (($udom eq '' || $uname eq '') ||
9313: ($udom eq 'public') && ($uname eq 'public')) {
9314: $quota = 0;
1.536 raeburn 9315: $quotatype = 'default';
9316: $defquota = 0;
1.472 raeburn 9317: } else {
1.536 raeburn 9318: my $inststatus;
1.1075.2.41 raeburn 9319: if ($quotaname eq 'course') {
9320: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9321: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9322: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9323: } else {
9324: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9325: $quota = $cenv{'internal.uploadquota'};
9326: }
1.536 raeburn 9327: } else {
1.1075.2.41 raeburn 9328: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9329: if ($quotaname eq 'author') {
9330: $quota = $env{'environment.authorquota'};
9331: } else {
9332: $quota = $env{'environment.portfolioquota'};
9333: }
9334: $inststatus = $env{'environment.inststatus'};
9335: } else {
9336: my %userenv =
9337: &Apache::lonnet::get('environment',['portfolioquota',
9338: 'authorquota','inststatus'],$udom,$uname);
9339: my ($tmp) = keys(%userenv);
9340: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9341: if ($quotaname eq 'author') {
9342: $quota = $userenv{'authorquota'};
9343: } else {
9344: $quota = $userenv{'portfolioquota'};
9345: }
9346: $inststatus = $userenv{'inststatus'};
9347: } else {
9348: undef(%userenv);
9349: }
9350: }
9351: }
9352: if ($quota eq '' || wantarray) {
9353: if ($quotaname eq 'course') {
9354: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9355: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9356: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9357: $defquota = $domdefs{$crstype.'quota'};
9358: }
9359: if ($defquota eq '') {
9360: $defquota = 500;
9361: }
1.1075.2.41 raeburn 9362: } else {
9363: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9364: }
9365: if ($quota eq '') {
9366: $quota = $defquota;
9367: $quotatype = 'default';
9368: } else {
9369: $quotatype = 'custom';
9370: }
1.472 raeburn 9371: }
9372: }
1.536 raeburn 9373: if (wantarray) {
9374: return ($quota,$quotatype,$settingstatus,$defquota);
9375: } else {
9376: return $quota;
9377: }
1.472 raeburn 9378: }
9379:
9380: ###############################################
9381:
9382: =pod
9383:
9384: =item * &default_quota()
9385:
1.536 raeburn 9386: Retrieves default quota assigned for storage of user portfolio files,
9387: given an (optional) user's institutional status.
1.472 raeburn 9388:
9389: Incoming parameters:
1.1075.2.42 raeburn 9390:
1.472 raeburn 9391: 1. domain
1.536 raeburn 9392: 2. (Optional) institutional status(es). This is a : separated list of
9393: status types (e.g., faculty, staff, student etc.)
9394: which apply to the user for whom the default is being retrieved.
9395: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9396: default quota will be returned.
9397: 3. quota name - portfolio, author, or course
9398: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9399:
9400: Returns:
1.1075.2.42 raeburn 9401:
1.1075.2.58 raeburn 9402: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9403: 2. (Optional) institutional type which determined the value of the
9404: default quota.
1.472 raeburn 9405:
9406: If a value has been stored in the domain's configuration db,
9407: it will return that, otherwise it returns 20 (for backwards
9408: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9409: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9410:
1.536 raeburn 9411: If the user's status includes multiple types (e.g., staff and student),
9412: the largest default quota which applies to the user determines the
9413: default quota returned.
9414:
1.472 raeburn 9415: =cut
9416:
9417: ###############################################
9418:
9419:
9420: sub default_quota {
1.1075.2.41 raeburn 9421: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9422: my ($defquota,$settingstatus);
9423: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9424: ['quotas'],$udom);
1.1075.2.41 raeburn 9425: my $key = 'defaultquota';
9426: if ($quotaname eq 'author') {
9427: $key = 'authorquota';
9428: }
1.622 raeburn 9429: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9430: if ($inststatus ne '') {
1.765 raeburn 9431: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9432: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9433: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9434: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9435: if ($defquota eq '') {
1.1075.2.41 raeburn 9436: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9437: $settingstatus = $item;
1.1075.2.41 raeburn 9438: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9439: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9440: $settingstatus = $item;
9441: }
9442: }
1.1075.2.41 raeburn 9443: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9444: if ($quotahash{'quotas'}{$item} ne '') {
9445: if ($defquota eq '') {
9446: $defquota = $quotahash{'quotas'}{$item};
9447: $settingstatus = $item;
9448: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9449: $defquota = $quotahash{'quotas'}{$item};
9450: $settingstatus = $item;
9451: }
1.536 raeburn 9452: }
9453: }
9454: }
9455: }
9456: if ($defquota eq '') {
1.1075.2.41 raeburn 9457: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9458: $defquota = $quotahash{'quotas'}{$key}{'default'};
9459: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9460: $defquota = $quotahash{'quotas'}{'default'};
9461: }
1.536 raeburn 9462: $settingstatus = 'default';
1.1075.2.42 raeburn 9463: if ($defquota eq '') {
9464: if ($quotaname eq 'author') {
9465: $defquota = 500;
9466: }
9467: }
1.536 raeburn 9468: }
9469: } else {
9470: $settingstatus = 'default';
1.1075.2.41 raeburn 9471: if ($quotaname eq 'author') {
9472: $defquota = 500;
9473: } else {
9474: $defquota = 20;
9475: }
1.536 raeburn 9476: }
9477: if (wantarray) {
9478: return ($defquota,$settingstatus);
1.472 raeburn 9479: } else {
1.536 raeburn 9480: return $defquota;
1.472 raeburn 9481: }
9482: }
9483:
1.1075.2.41 raeburn 9484: ###############################################
9485:
9486: =pod
9487:
1.1075.2.42 raeburn 9488: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9489:
9490: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9491: of existing file within authoring space will cause quota for the authoring
9492: space to be exceeded.
9493:
9494: Same, if upload of a file directly to a course/community via Course Editor
9495: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9496:
1.1075.2.61 raeburn 9497: Inputs: 7
1.1075.2.42 raeburn 9498: 1. username or coursenum
1.1075.2.41 raeburn 9499: 2. domain
1.1075.2.42 raeburn 9500: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9501: 4. filename of file for which action is being requested
9502: 5. filesize (kB) of file
9503: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9504: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9505:
9506: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9507: otherwise return null.
9508:
1.1075.2.42 raeburn 9509: =back
9510:
1.1075.2.41 raeburn 9511: =cut
9512:
1.1075.2.42 raeburn 9513: sub excess_filesize_warning {
1.1075.2.59 raeburn 9514: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9515: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9516: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9517: if ($context eq 'author') {
9518: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9519: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9520: } else {
9521: foreach my $subdir ('docs','supplemental') {
9522: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9523: }
9524: }
1.1075.2.41 raeburn 9525: $disk_quota = int($disk_quota * 1000);
9526: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9527: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9528: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9529: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9530: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9531: $disk_quota,$current_disk_usage).
9532: '</p>';
9533: }
9534: return;
9535: }
9536:
9537: ###############################################
9538:
9539:
1.384 raeburn 9540: sub get_secgrprole_info {
9541: my ($cdom,$cnum,$needroles,$type) = @_;
9542: my %sections_count = &get_sections($cdom,$cnum);
9543: my @sections = (sort {$a <=> $b} keys(%sections_count));
9544: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9545: my @groups = sort(keys(%curr_groups));
9546: my $allroles = [];
9547: my $rolehash;
9548: my $accesshash = {
9549: active => 'Currently has access',
9550: future => 'Will have future access',
9551: previous => 'Previously had access',
9552: };
9553: if ($needroles) {
9554: $rolehash = {'all' => 'all'};
1.385 albertel 9555: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9556: if (&Apache::lonnet::error(%user_roles)) {
9557: undef(%user_roles);
9558: }
9559: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9560: my ($role)=split(/\:/,$item,2);
9561: if ($role eq 'cr') { next; }
9562: if ($role =~ /^cr/) {
9563: $$rolehash{$role} = (split('/',$role))[3];
9564: } else {
9565: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9566: }
9567: }
9568: foreach my $key (sort(keys(%{$rolehash}))) {
9569: push(@{$allroles},$key);
9570: }
9571: push (@{$allroles},'st');
9572: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9573: }
9574: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9575: }
9576:
1.555 raeburn 9577: sub user_picker {
1.1075.2.127! raeburn 9578: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 9579: my $currdom = $dom;
1.1075.2.114 raeburn 9580: my @alldoms = &Apache::lonnet::all_domains();
9581: if (@alldoms == 1) {
9582: my %domsrch = &Apache::lonnet::get_dom('configuration',
9583: ['directorysrch'],$alldoms[0]);
9584: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
9585: my $showdom = $domdesc;
9586: if ($showdom eq '') {
9587: $showdom = $dom;
9588: }
9589: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
9590: if ((!$domsrch{'directorysrch'}{'available'}) &&
9591: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
9592: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
9593: }
9594: }
9595: }
1.555 raeburn 9596: my %curr_selected = (
9597: srchin => 'dom',
1.580 raeburn 9598: srchby => 'lastname',
1.555 raeburn 9599: );
9600: my $srchterm;
1.625 raeburn 9601: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9602: if ($srch->{'srchby'} ne '') {
9603: $curr_selected{'srchby'} = $srch->{'srchby'};
9604: }
9605: if ($srch->{'srchin'} ne '') {
9606: $curr_selected{'srchin'} = $srch->{'srchin'};
9607: }
9608: if ($srch->{'srchtype'} ne '') {
9609: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9610: }
9611: if ($srch->{'srchdomain'} ne '') {
9612: $currdom = $srch->{'srchdomain'};
9613: }
9614: $srchterm = $srch->{'srchterm'};
9615: }
1.1075.2.98 raeburn 9616: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9617: 'usr' => 'Search criteria',
1.563 raeburn 9618: 'doma' => 'Domain/institution to search',
1.558 albertel 9619: 'uname' => 'username',
9620: 'lastname' => 'last name',
1.555 raeburn 9621: 'lastfirst' => 'last name, first name',
1.558 albertel 9622: 'crs' => 'in this course',
1.576 raeburn 9623: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9624: 'alc' => 'all LON-CAPA',
1.573 raeburn 9625: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9626: 'exact' => 'is',
9627: 'contains' => 'contains',
1.569 raeburn 9628: 'begins' => 'begins with',
1.1075.2.98 raeburn 9629: );
9630: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9631: 'youm' => "You must include some text to search for.",
9632: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9633: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9634: 'yomc' => "You must choose a domain when using an institutional directory search.",
9635: 'ymcd' => "You must choose a domain when using a domain search.",
9636: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9637: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9638: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9639: );
1.1075.2.98 raeburn 9640: &html_escape(\%html_lt);
9641: &js_escape(\%js_lt);
1.1075.2.115 raeburn 9642: my $domform;
1.1075.2.126 raeburn 9643: my $allow_blank = 1;
1.1075.2.115 raeburn 9644: if ($fixeddom) {
1.1075.2.126 raeburn 9645: $allow_blank = 0;
9646: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 9647: } else {
1.1075.2.126 raeburn 9648: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 9649: }
1.563 raeburn 9650: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9651:
9652: my @srchins = ('crs','dom','alc','instd');
9653:
9654: foreach my $option (@srchins) {
9655: # FIXME 'alc' option unavailable until
9656: # loncreateuser::print_user_query_page()
9657: # has been completed.
9658: next if ($option eq 'alc');
1.880 raeburn 9659: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9660: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127! raeburn 9661: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 9662: if ($curr_selected{'srchin'} eq $option) {
9663: $srchinsel .= '
1.1075.2.98 raeburn 9664: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 9665: } else {
9666: $srchinsel .= '
1.1075.2.98 raeburn 9667: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 9668: }
1.555 raeburn 9669: }
1.563 raeburn 9670: $srchinsel .= "\n </select>\n";
1.555 raeburn 9671:
9672: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9673: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9674: if ($curr_selected{'srchby'} eq $option) {
9675: $srchbysel .= '
1.1075.2.98 raeburn 9676: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9677: } else {
9678: $srchbysel .= '
1.1075.2.98 raeburn 9679: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9680: }
9681: }
9682: $srchbysel .= "\n </select>\n";
9683:
9684: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9685: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9686: if ($curr_selected{'srchtype'} eq $option) {
9687: $srchtypesel .= '
1.1075.2.98 raeburn 9688: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9689: } else {
9690: $srchtypesel .= '
1.1075.2.98 raeburn 9691: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9692: }
9693: }
9694: $srchtypesel .= "\n </select>\n";
9695:
1.558 albertel 9696: my ($newuserscript,$new_user_create);
1.994 raeburn 9697: my $context_dom = $env{'request.role.domain'};
9698: if ($context eq 'requestcrs') {
9699: if ($env{'form.coursedom'} ne '') {
9700: $context_dom = $env{'form.coursedom'};
9701: }
9702: }
1.556 raeburn 9703: if ($forcenewuser) {
1.576 raeburn 9704: if (ref($srch) eq 'HASH') {
1.994 raeburn 9705: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9706: if ($cancreate) {
9707: $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>';
9708: } else {
1.799 bisitz 9709: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9710: my %usertypetext = (
9711: official => 'institutional',
9712: unofficial => 'non-institutional',
9713: );
1.799 bisitz 9714: $new_user_create = '<p class="LC_warning">'
9715: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9716: .' '
9717: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9718: ,'<a href="'.$helplink.'">','</a>')
9719: .'</p><br />';
1.627 raeburn 9720: }
1.576 raeburn 9721: }
9722: }
9723:
1.556 raeburn 9724: $newuserscript = <<"ENDSCRIPT";
9725:
1.570 raeburn 9726: function setSearch(createnew,callingForm) {
1.556 raeburn 9727: if (createnew == 1) {
1.570 raeburn 9728: for (var i=0; i<callingForm.srchby.length; i++) {
9729: if (callingForm.srchby.options[i].value == 'uname') {
9730: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9731: }
9732: }
1.570 raeburn 9733: for (var i=0; i<callingForm.srchin.length; i++) {
9734: if ( callingForm.srchin.options[i].value == 'dom') {
9735: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9736: }
9737: }
1.570 raeburn 9738: for (var i=0; i<callingForm.srchtype.length; i++) {
9739: if (callingForm.srchtype.options[i].value == 'exact') {
9740: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9741: }
9742: }
1.570 raeburn 9743: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9744: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9745: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9746: }
9747: }
9748: }
9749: }
9750: ENDSCRIPT
1.558 albertel 9751:
1.556 raeburn 9752: }
9753:
1.555 raeburn 9754: my $output = <<"END_BLOCK";
1.556 raeburn 9755: <script type="text/javascript">
1.824 bisitz 9756: // <![CDATA[
1.570 raeburn 9757: function validateEntry(callingForm) {
1.558 albertel 9758:
1.556 raeburn 9759: var checkok = 1;
1.558 albertel 9760: var srchin;
1.570 raeburn 9761: for (var i=0; i<callingForm.srchin.length; i++) {
9762: if ( callingForm.srchin[i].checked ) {
9763: srchin = callingForm.srchin[i].value;
1.558 albertel 9764: }
9765: }
9766:
1.570 raeburn 9767: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9768: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9769: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9770: var srchterm = callingForm.srchterm.value;
9771: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9772: var msg = "";
9773:
9774: if (srchterm == "") {
9775: checkok = 0;
1.1075.2.98 raeburn 9776: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 9777: }
9778:
1.569 raeburn 9779: if (srchtype== 'begins') {
9780: if (srchterm.length < 2) {
9781: checkok = 0;
1.1075.2.98 raeburn 9782: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 9783: }
9784: }
9785:
1.556 raeburn 9786: if (srchtype== 'contains') {
9787: if (srchterm.length < 3) {
9788: checkok = 0;
1.1075.2.98 raeburn 9789: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 9790: }
9791: }
9792: if (srchin == 'instd') {
9793: if (srchdomain == '') {
9794: checkok = 0;
1.1075.2.98 raeburn 9795: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 9796: }
9797: }
9798: if (srchin == 'dom') {
9799: if (srchdomain == '') {
9800: checkok = 0;
1.1075.2.98 raeburn 9801: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 9802: }
9803: }
9804: if (srchby == 'lastfirst') {
9805: if (srchterm.indexOf(",") == -1) {
9806: checkok = 0;
1.1075.2.98 raeburn 9807: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 9808: }
9809: if (srchterm.indexOf(",") == srchterm.length -1) {
9810: checkok = 0;
1.1075.2.98 raeburn 9811: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 9812: }
9813: }
9814: if (checkok == 0) {
1.1075.2.98 raeburn 9815: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 9816: return;
9817: }
9818: if (checkok == 1) {
1.570 raeburn 9819: callingForm.submit();
1.556 raeburn 9820: }
9821: }
9822:
9823: $newuserscript
9824:
1.824 bisitz 9825: // ]]>
1.556 raeburn 9826: </script>
1.558 albertel 9827:
9828: $new_user_create
9829:
1.555 raeburn 9830: END_BLOCK
1.558 albertel 9831:
1.876 raeburn 9832: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 9833: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 9834: $domform.
9835: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 9836: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 9837: $srchbysel.
9838: $srchtypesel.
9839: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9840: $srchinsel.
9841: &Apache::lonhtmlcommon::row_closure(1).
9842: &Apache::lonhtmlcommon::end_pick_box().
9843: '<br />';
1.1075.2.114 raeburn 9844: return ($output,1);
1.555 raeburn 9845: }
9846:
1.612 raeburn 9847: sub user_rule_check {
1.615 raeburn 9848: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 9849: my ($response,%inst_response);
1.612 raeburn 9850: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 9851: if (keys(%{$usershash}) > 1) {
9852: my (%by_username,%by_id,%userdoms);
9853: my $checkid;
1.612 raeburn 9854: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 9855: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
9856: $checkid = 1;
9857: }
9858: }
9859: foreach my $user (keys(%{$usershash})) {
9860: my ($uname,$udom) = split(/:/,$user);
9861: if ($checkid) {
9862: if (ref($usershash->{$user}) eq 'HASH') {
9863: if ($usershash->{$user}->{'id'} ne '') {
9864: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
9865: $userdoms{$udom} = 1;
9866: if (ref($inst_results) eq 'HASH') {
9867: $inst_results->{$uname.':'.$udom} = {};
9868: }
9869: }
9870: }
9871: } else {
9872: $by_username{$udom}{$uname} = 1;
9873: $userdoms{$udom} = 1;
9874: if (ref($inst_results) eq 'HASH') {
9875: $inst_results->{$uname.':'.$udom} = {};
9876: }
9877: }
9878: }
9879: foreach my $udom (keys(%userdoms)) {
9880: if (!$got_rules->{$udom}) {
9881: my %domconfig = &Apache::lonnet::get_dom('configuration',
9882: ['usercreation'],$udom);
9883: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9884: foreach my $item ('username','id') {
9885: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9886: $$curr_rules{$udom}{$item} =
9887: $domconfig{'usercreation'}{$item.'_rule'};
9888: }
9889: }
9890: }
9891: $got_rules->{$udom} = 1;
9892: }
9893: }
9894: if ($checkid) {
9895: foreach my $udom (keys(%by_id)) {
9896: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
9897: if ($outcome eq 'ok') {
9898: foreach my $id (keys(%{$by_id{$udom}})) {
9899: my $uname = $by_id{$udom}{$id};
9900: $inst_response{$uname.':'.$udom} = $outcome;
9901: }
9902: if (ref($results) eq 'HASH') {
9903: foreach my $uname (keys(%{$results})) {
9904: if (exists($inst_response{$uname.':'.$udom})) {
9905: $inst_response{$uname.':'.$udom} = $outcome;
9906: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9907: }
9908: }
9909: }
9910: }
1.612 raeburn 9911: }
1.615 raeburn 9912: } else {
1.1075.2.99 raeburn 9913: foreach my $udom (keys(%by_username)) {
9914: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
9915: if ($outcome eq 'ok') {
9916: foreach my $uname (keys(%{$by_username{$udom}})) {
9917: $inst_response{$uname.':'.$udom} = $outcome;
9918: }
9919: if (ref($results) eq 'HASH') {
9920: foreach my $uname (keys(%{$results})) {
9921: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9922: }
9923: }
9924: }
9925: }
1.612 raeburn 9926: }
1.1075.2.99 raeburn 9927: } elsif (keys(%{$usershash}) == 1) {
9928: my $user = (keys(%{$usershash}))[0];
9929: my ($uname,$udom) = split(/:/,$user);
9930: if (($udom ne '') && ($uname ne '')) {
9931: if (ref($usershash->{$user}) eq 'HASH') {
9932: if (ref($checks) eq 'HASH') {
9933: if (defined($checks->{'username'})) {
9934: ($inst_response{$user},%{$inst_results->{$user}}) =
9935: &Apache::lonnet::get_instuser($udom,$uname);
9936: } elsif (defined($checks->{'id'})) {
9937: if ($usershash->{$user}->{'id'} ne '') {
9938: ($inst_response{$user},%{$inst_results->{$user}}) =
9939: &Apache::lonnet::get_instuser($udom,undef,
9940: $usershash->{$user}->{'id'});
9941: } else {
9942: ($inst_response{$user},%{$inst_results->{$user}}) =
9943: &Apache::lonnet::get_instuser($udom,$uname);
9944: }
9945: }
9946: } else {
9947: ($inst_response{$user},%{$inst_results->{$user}}) =
9948: &Apache::lonnet::get_instuser($udom,$uname);
9949: return;
9950: }
9951: if (!$got_rules->{$udom}) {
9952: my %domconfig = &Apache::lonnet::get_dom('configuration',
9953: ['usercreation'],$udom);
9954: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9955: foreach my $item ('username','id') {
9956: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9957: $$curr_rules{$udom}{$item} =
9958: $domconfig{'usercreation'}{$item.'_rule'};
9959: }
9960: }
1.585 raeburn 9961: }
1.1075.2.99 raeburn 9962: $got_rules->{$udom} = 1;
1.585 raeburn 9963: }
9964: }
1.1075.2.99 raeburn 9965: } else {
9966: return;
9967: }
9968: } else {
9969: return;
9970: }
9971: foreach my $user (keys(%{$usershash})) {
9972: my ($uname,$udom) = split(/:/,$user);
9973: next if (($udom eq '') || ($uname eq ''));
9974: my $id;
9975: if (ref($inst_results) eq 'HASH') {
9976: if (ref($inst_results->{$user}) eq 'HASH') {
9977: $id = $inst_results->{$user}->{'id'};
9978: }
9979: }
9980: if ($id eq '') {
9981: if (ref($usershash->{$user})) {
9982: $id = $usershash->{$user}->{'id'};
9983: }
1.585 raeburn 9984: }
1.612 raeburn 9985: foreach my $item (keys(%{$checks})) {
9986: if (ref($$curr_rules{$udom}) eq 'HASH') {
9987: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9988: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 9989: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
9990: $$curr_rules{$udom}{$item});
1.612 raeburn 9991: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9992: if ($rule_check{$rule}) {
9993: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 9994: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 9995: if (ref($inst_results) eq 'HASH') {
9996: if (ref($inst_results->{$user}) eq 'HASH') {
9997: if (keys(%{$inst_results->{$user}}) == 0) {
9998: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 9999: } elsif ($item eq 'id') {
10000: if ($inst_results->{$user}->{'id'} eq '') {
10001: $$alerts{$item}{$udom}{$uname} = 1;
10002: }
1.615 raeburn 10003: }
1.612 raeburn 10004: }
10005: }
1.615 raeburn 10006: }
10007: last;
1.585 raeburn 10008: }
10009: }
10010: }
10011: }
10012: }
10013: }
10014: }
10015: }
1.612 raeburn 10016: return;
10017: }
10018:
10019: sub user_rule_formats {
10020: my ($domain,$domdesc,$curr_rules,$check) = @_;
10021: my %text = (
10022: 'username' => 'Usernames',
10023: 'id' => 'IDs',
10024: );
10025: my $output;
10026: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10027: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10028: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 10029: $output = '<br />'.
10030: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10031: '<span class="LC_cusr_emph">','</span>',$domdesc).
10032: ' <ul>';
1.612 raeburn 10033: foreach my $rule (@{$ruleorder}) {
10034: if (ref($curr_rules) eq 'ARRAY') {
10035: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10036: if (ref($rules->{$rule}) eq 'HASH') {
10037: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10038: $rules->{$rule}{'desc'}.'</li>';
10039: }
10040: }
10041: }
10042: }
10043: $output .= '</ul>';
10044: }
10045: }
10046: return $output;
10047: }
10048:
10049: sub instrule_disallow_msg {
1.615 raeburn 10050: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10051: my $response;
10052: my %text = (
10053: item => 'username',
10054: items => 'usernames',
10055: match => 'matches',
10056: do => 'does',
10057: action => 'a username',
10058: one => 'one',
10059: );
10060: if ($count > 1) {
10061: $text{'item'} = 'usernames';
10062: $text{'match'} ='match';
10063: $text{'do'} = 'do';
10064: $text{'action'} = 'usernames',
10065: $text{'one'} = 'ones';
10066: }
10067: if ($checkitem eq 'id') {
10068: $text{'items'} = 'IDs';
10069: $text{'item'} = 'ID';
10070: $text{'action'} = 'an ID';
1.615 raeburn 10071: if ($count > 1) {
10072: $text{'item'} = 'IDs';
10073: $text{'action'} = 'IDs';
10074: }
1.612 raeburn 10075: }
1.674 bisitz 10076: $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 10077: if ($mode eq 'upload') {
10078: if ($checkitem eq 'username') {
10079: $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'}.");
10080: } elsif ($checkitem eq 'id') {
1.674 bisitz 10081: $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 10082: }
1.669 raeburn 10083: } elsif ($mode eq 'selfcreate') {
10084: if ($checkitem eq 'id') {
10085: $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.");
10086: }
1.615 raeburn 10087: } else {
10088: if ($checkitem eq 'username') {
10089: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10090: } elsif ($checkitem eq 'id') {
10091: $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.");
10092: }
1.612 raeburn 10093: }
10094: return $response;
1.585 raeburn 10095: }
10096:
1.624 raeburn 10097: sub personal_data_fieldtitles {
10098: my %fieldtitles = &Apache::lonlocal::texthash (
10099: id => 'Student/Employee ID',
10100: permanentemail => 'E-mail address',
10101: lastname => 'Last Name',
10102: firstname => 'First Name',
10103: middlename => 'Middle Name',
10104: generation => 'Generation',
10105: gen => 'Generation',
1.765 raeburn 10106: inststatus => 'Affiliation',
1.624 raeburn 10107: );
10108: return %fieldtitles;
10109: }
10110:
1.642 raeburn 10111: sub sorted_inst_types {
10112: my ($dom) = @_;
1.1075.2.70 raeburn 10113: my ($usertypes,$order);
10114: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10115: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10116: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10117: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10118: } else {
10119: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10120: }
1.642 raeburn 10121: my $othertitle = &mt('All users');
10122: if ($env{'request.course.id'}) {
1.668 raeburn 10123: $othertitle = &mt('Any users');
1.642 raeburn 10124: }
10125: my @types;
10126: if (ref($order) eq 'ARRAY') {
10127: @types = @{$order};
10128: }
10129: if (@types == 0) {
10130: if (ref($usertypes) eq 'HASH') {
10131: @types = sort(keys(%{$usertypes}));
10132: }
10133: }
10134: if (keys(%{$usertypes}) > 0) {
10135: $othertitle = &mt('Other users');
10136: }
10137: return ($othertitle,$usertypes,\@types);
10138: }
10139:
1.645 raeburn 10140: sub get_institutional_codes {
10141: my ($settings,$allcourses,$LC_code) = @_;
10142: # Get complete list of course sections to update
10143: my @currsections = ();
10144: my @currxlists = ();
10145: my $coursecode = $$settings{'internal.coursecode'};
10146:
10147: if ($$settings{'internal.sectionnums'} ne '') {
10148: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10149: }
10150:
10151: if ($$settings{'internal.crosslistings'} ne '') {
10152: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10153: }
10154:
10155: if (@currxlists > 0) {
10156: foreach (@currxlists) {
10157: if (m/^([^:]+):(\w*)$/) {
10158: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 10159: push(@{$allcourses},$1);
1.645 raeburn 10160: $$LC_code{$1} = $2;
10161: }
10162: }
10163: }
10164: }
10165:
10166: if (@currsections > 0) {
10167: foreach (@currsections) {
10168: if (m/^(\w+):(\w*)$/) {
10169: my $sec = $coursecode.$1;
10170: my $lc_sec = $2;
10171: unless (grep/^$sec$/,@{$allcourses}) {
1.1075.2.119 raeburn 10172: push(@{$allcourses},$sec);
1.645 raeburn 10173: $$LC_code{$sec} = $lc_sec;
10174: }
10175: }
10176: }
10177: }
10178: return;
10179: }
10180:
1.971 raeburn 10181: sub get_standard_codeitems {
10182: return ('Year','Semester','Department','Number','Section');
10183: }
10184:
1.112 bowersj2 10185: =pod
10186:
1.780 raeburn 10187: =head1 Slot Helpers
10188:
10189: =over 4
10190:
10191: =item * sorted_slots()
10192:
1.1040 raeburn 10193: Sorts an array of slot names in order of an optional sort key,
10194: default sort is by slot start time (earliest first).
1.780 raeburn 10195:
10196: Inputs:
10197:
10198: =over 4
10199:
10200: slotsarr - Reference to array of unsorted slot names.
10201:
10202: slots - Reference to hash of hash, where outer hash keys are slot names.
10203:
1.1040 raeburn 10204: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10205:
1.549 albertel 10206: =back
10207:
1.780 raeburn 10208: Returns:
10209:
10210: =over 4
10211:
1.1040 raeburn 10212: sorted - An array of slot names sorted by a specified sort key
10213: (default sort key is start time of the slot).
1.780 raeburn 10214:
10215: =back
10216:
10217: =cut
10218:
10219:
10220: sub sorted_slots {
1.1040 raeburn 10221: my ($slotsarr,$slots,$sortkey) = @_;
10222: if ($sortkey eq '') {
10223: $sortkey = 'starttime';
10224: }
1.780 raeburn 10225: my @sorted;
10226: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10227: @sorted =
10228: sort {
10229: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10230: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10231: }
10232: if (ref($slots->{$a})) { return -1;}
10233: if (ref($slots->{$b})) { return 1;}
10234: return 0;
10235: } @{$slotsarr};
10236: }
10237: return @sorted;
10238: }
10239:
1.1040 raeburn 10240: =pod
10241:
10242: =item * get_future_slots()
10243:
10244: Inputs:
10245:
10246: =over 4
10247:
10248: cnum - course number
10249:
10250: cdom - course domain
10251:
10252: now - current UNIX time
10253:
10254: symb - optional symb
10255:
10256: =back
10257:
10258: Returns:
10259:
10260: =over 4
10261:
10262: sorted_reservable - ref to array of student_schedulable slots currently
10263: reservable, ordered by end date of reservation period.
10264:
10265: reservable_now - ref to hash of student_schedulable slots currently
10266: reservable.
10267:
10268: Keys in inner hash are:
10269: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 10270: (b) endreserve: end date of reservation period.
10271: (c) uniqueperiod: start,end dates when slot is to be uniquely
10272: selected.
1.1040 raeburn 10273:
10274: sorted_future - ref to array of student_schedulable slots reservable in
10275: the future, ordered by start date of reservation period.
10276:
10277: future_reservable - ref to hash of student_schedulable slots reservable
10278: in the future.
10279:
10280: Keys in inner hash are:
10281: (a) symb: either blank or symb to which slot use is restricted.
10282: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 10283: (c) uniqueperiod: start,end dates when slot is to be uniquely
10284: selected.
1.1040 raeburn 10285:
10286: =back
10287:
10288: =cut
10289:
10290: sub get_future_slots {
10291: my ($cnum,$cdom,$now,$symb) = @_;
10292: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10293: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10294: foreach my $slot (keys(%slots)) {
10295: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10296: if ($symb) {
10297: next if (($slots{$slot}->{'symb'} ne '') &&
10298: ($slots{$slot}->{'symb'} ne $symb));
10299: }
10300: if (($slots{$slot}->{'starttime'} > $now) &&
10301: ($slots{$slot}->{'endtime'} > $now)) {
10302: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10303: my $userallowed = 0;
10304: if ($slots{$slot}->{'allowedsections'}) {
10305: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10306: if (!defined($env{'request.role.sec'})
10307: && grep(/^No section assigned$/,@allowed_sec)) {
10308: $userallowed=1;
10309: } else {
10310: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10311: $userallowed=1;
10312: }
10313: }
10314: unless ($userallowed) {
10315: if (defined($env{'request.course.groups'})) {
10316: my @groups = split(/:/,$env{'request.course.groups'});
10317: foreach my $group (@groups) {
10318: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10319: $userallowed=1;
10320: last;
10321: }
10322: }
10323: }
10324: }
10325: }
10326: if ($slots{$slot}->{'allowedusers'}) {
10327: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10328: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10329: if (grep(/^\Q$user\E$/,@allowed_users)) {
10330: $userallowed = 1;
10331: }
10332: }
10333: next unless($userallowed);
10334: }
10335: my $startreserve = $slots{$slot}->{'startreserve'};
10336: my $endreserve = $slots{$slot}->{'endreserve'};
10337: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 10338: my $uniqueperiod;
10339: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10340: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10341: }
1.1040 raeburn 10342: if (($startreserve < $now) &&
10343: (!$endreserve || $endreserve > $now)) {
10344: my $lastres = $endreserve;
10345: if (!$lastres) {
10346: $lastres = $slots{$slot}->{'starttime'};
10347: }
10348: $reservable_now{$slot} = {
10349: symb => $symb,
1.1075.2.104 raeburn 10350: endreserve => $lastres,
10351: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10352: };
10353: } elsif (($startreserve > $now) &&
10354: (!$endreserve || $endreserve > $startreserve)) {
10355: $future_reservable{$slot} = {
10356: symb => $symb,
1.1075.2.104 raeburn 10357: startreserve => $startreserve,
10358: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10359: };
10360: }
10361: }
10362: }
10363: my @unsorted_reservable = keys(%reservable_now);
10364: if (@unsorted_reservable > 0) {
10365: @sorted_reservable =
10366: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10367: }
10368: my @unsorted_future = keys(%future_reservable);
10369: if (@unsorted_future > 0) {
10370: @sorted_future =
10371: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10372: }
10373: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10374: }
1.780 raeburn 10375:
10376: =pod
10377:
1.1057 foxr 10378: =back
10379:
1.549 albertel 10380: =head1 HTTP Helpers
10381:
10382: =over 4
10383:
1.648 raeburn 10384: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10385:
1.258 albertel 10386: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10387: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10388: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10389:
10390: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10391: $possible_names is an ref to an array of form element names. As an example:
10392: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10393: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10394:
10395: =cut
1.1 albertel 10396:
1.6 albertel 10397: sub get_unprocessed_cgi {
1.25 albertel 10398: my ($query,$possible_names)= @_;
1.26 matthew 10399: # $Apache::lonxml::debug=1;
1.356 albertel 10400: foreach my $pair (split(/&/,$query)) {
10401: my ($name, $value) = split(/=/,$pair);
1.369 www 10402: $name = &unescape($name);
1.25 albertel 10403: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10404: $value =~ tr/+/ /;
10405: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10406: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10407: }
1.16 harris41 10408: }
1.6 albertel 10409: }
10410:
1.112 bowersj2 10411: =pod
10412:
1.648 raeburn 10413: =item * &cacheheader()
1.112 bowersj2 10414:
10415: returns cache-controlling header code
10416:
10417: =cut
10418:
1.7 albertel 10419: sub cacheheader {
1.258 albertel 10420: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10421: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10422: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10423: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10424: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10425: return $output;
1.7 albertel 10426: }
10427:
1.112 bowersj2 10428: =pod
10429:
1.648 raeburn 10430: =item * &no_cache($r)
1.112 bowersj2 10431:
10432: specifies header code to not have cache
10433:
10434: =cut
10435:
1.9 albertel 10436: sub no_cache {
1.216 albertel 10437: my ($r) = @_;
10438: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10439: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10440: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10441: $r->no_cache(1);
10442: $r->header_out("Expires" => $date);
10443: $r->header_out("Pragma" => "no-cache");
1.123 www 10444: }
10445:
10446: sub content_type {
1.181 albertel 10447: my ($r,$type,$charset) = @_;
1.299 foxr 10448: if ($r) {
10449: # Note that printout.pl calls this with undef for $r.
10450: &no_cache($r);
10451: }
1.258 albertel 10452: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10453: unless ($charset) {
10454: $charset=&Apache::lonlocal::current_encoding;
10455: }
10456: if ($charset) { $type.='; charset='.$charset; }
10457: if ($r) {
10458: $r->content_type($type);
10459: } else {
10460: print("Content-type: $type\n\n");
10461: }
1.9 albertel 10462: }
1.25 albertel 10463:
1.112 bowersj2 10464: =pod
10465:
1.648 raeburn 10466: =item * &add_to_env($name,$value)
1.112 bowersj2 10467:
1.258 albertel 10468: adds $name to the %env hash with value
1.112 bowersj2 10469: $value, if $name already exists, the entry is converted to an array
10470: reference and $value is added to the array.
10471:
10472: =cut
10473:
1.25 albertel 10474: sub add_to_env {
10475: my ($name,$value)=@_;
1.258 albertel 10476: if (defined($env{$name})) {
10477: if (ref($env{$name})) {
1.25 albertel 10478: #already have multiple values
1.258 albertel 10479: push(@{ $env{$name} },$value);
1.25 albertel 10480: } else {
10481: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10482: my $first=$env{$name};
10483: undef($env{$name});
10484: push(@{ $env{$name} },$first,$value);
1.25 albertel 10485: }
10486: } else {
1.258 albertel 10487: $env{$name}=$value;
1.25 albertel 10488: }
1.31 albertel 10489: }
1.149 albertel 10490:
10491: =pod
10492:
1.648 raeburn 10493: =item * &get_env_multiple($name)
1.149 albertel 10494:
1.258 albertel 10495: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10496: values may be defined and end up as an array ref.
10497:
10498: returns an array of values
10499:
10500: =cut
10501:
10502: sub get_env_multiple {
10503: my ($name) = @_;
10504: my @values;
1.258 albertel 10505: if (defined($env{$name})) {
1.149 albertel 10506: # exists is it an array
1.258 albertel 10507: if (ref($env{$name})) {
10508: @values=@{ $env{$name} };
1.149 albertel 10509: } else {
1.258 albertel 10510: $values[0]=$env{$name};
1.149 albertel 10511: }
10512: }
10513: return(@values);
10514: }
10515:
1.660 raeburn 10516: sub ask_for_embedded_content {
10517: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10518: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 10519: %currsubfile,%unused,$rem);
1.1071 raeburn 10520: my $counter = 0;
10521: my $numnew = 0;
1.987 raeburn 10522: my $numremref = 0;
10523: my $numinvalid = 0;
10524: my $numpathchg = 0;
10525: my $numexisting = 0;
1.1071 raeburn 10526: my $numunused = 0;
10527: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 10528: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10529: my $heading = &mt('Upload embedded files');
10530: my $buttontext = &mt('Upload');
10531:
1.1075.2.11 raeburn 10532: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 10533: if ($actionurl eq '/adm/dependencies') {
10534: $navmap = Apache::lonnavmaps::navmap->new();
10535: }
10536: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10537: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 10538: }
1.1075.2.35 raeburn 10539: if (($actionurl eq '/adm/portfolio') ||
10540: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10541: my $current_path='/';
10542: if ($env{'form.currentpath'}) {
10543: $current_path = $env{'form.currentpath'};
10544: }
10545: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 10546: $udom = $cdom;
10547: $uname = $cnum;
1.984 raeburn 10548: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10549: } else {
10550: $udom = $env{'user.domain'};
10551: $uname = $env{'user.name'};
10552: $url = '/userfiles/portfolio';
10553: }
1.987 raeburn 10554: $toplevel = $url.'/';
1.984 raeburn 10555: $url .= $current_path;
10556: $getpropath = 1;
1.987 raeburn 10557: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10558: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10559: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10560: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10561: $toplevel = $url;
1.984 raeburn 10562: if ($rest ne '') {
1.987 raeburn 10563: $url .= $rest;
10564: }
10565: } elsif ($actionurl eq '/adm/coursedocs') {
10566: if (ref($args) eq 'HASH') {
1.1071 raeburn 10567: $url = $args->{'docs_url'};
10568: $toplevel = $url;
1.1075.2.11 raeburn 10569: if ($args->{'context'} eq 'paste') {
10570: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10571: ($path) =
10572: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10573: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10574: $fileloc =~ s{^/}{};
10575: }
1.1071 raeburn 10576: }
10577: } elsif ($actionurl eq '/adm/dependencies') {
10578: if ($env{'request.course.id'} ne '') {
10579: if (ref($args) eq 'HASH') {
10580: $url = $args->{'docs_url'};
10581: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 10582: $toplevel = $url;
10583: unless ($toplevel =~ m{^/}) {
10584: $toplevel = "/$url";
10585: }
1.1075.2.11 raeburn 10586: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 10587: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10588: $path = $1;
10589: } else {
10590: ($path) =
10591: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10592: }
1.1075.2.79 raeburn 10593: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10594: $fileloc = $toplevel;
10595: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10596: my ($udom,$uname,$fname) =
10597: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10598: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10599: } else {
10600: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10601: }
1.1071 raeburn 10602: $fileloc =~ s{^/}{};
10603: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10604: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10605: }
1.987 raeburn 10606: }
1.1075.2.35 raeburn 10607: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10608: $udom = $cdom;
10609: $uname = $cnum;
10610: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10611: $toplevel = $url;
10612: $path = $url;
10613: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10614: $fileloc =~ s{^/}{};
10615: }
10616: foreach my $file (keys(%{$allfiles})) {
10617: my $embed_file;
10618: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10619: $embed_file = $1;
10620: } else {
10621: $embed_file = $file;
10622: }
1.1075.2.55 raeburn 10623: my ($absolutepath,$cleaned_file);
10624: if ($embed_file =~ m{^\w+://}) {
10625: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 10626: $newfiles{$cleaned_file} = 1;
10627: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10628: } else {
1.1075.2.55 raeburn 10629: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10630: if ($embed_file =~ m{^/}) {
10631: $absolutepath = $embed_file;
10632: }
1.1075.2.47 raeburn 10633: if ($cleaned_file =~ m{/}) {
10634: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10635: $path = &check_for_traversal($path,$url,$toplevel);
10636: my $item = $fname;
10637: if ($path ne '') {
10638: $item = $path.'/'.$fname;
10639: $subdependencies{$path}{$fname} = 1;
10640: } else {
10641: $dependencies{$item} = 1;
10642: }
10643: if ($absolutepath) {
10644: $mapping{$item} = $absolutepath;
10645: } else {
10646: $mapping{$item} = $embed_file;
10647: }
10648: } else {
10649: $dependencies{$embed_file} = 1;
10650: if ($absolutepath) {
1.1075.2.47 raeburn 10651: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10652: } else {
1.1075.2.47 raeburn 10653: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10654: }
10655: }
1.984 raeburn 10656: }
10657: }
1.1071 raeburn 10658: my $dirptr = 16384;
1.984 raeburn 10659: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10660: $currsubfile{$path} = {};
1.1075.2.35 raeburn 10661: if (($actionurl eq '/adm/portfolio') ||
10662: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10663: my ($sublistref,$listerror) =
10664: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10665: if (ref($sublistref) eq 'ARRAY') {
10666: foreach my $line (@{$sublistref}) {
10667: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10668: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10669: }
1.984 raeburn 10670: }
1.987 raeburn 10671: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10672: if (opendir(my $dir,$url.'/'.$path)) {
10673: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10674: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10675: }
1.1075.2.11 raeburn 10676: } elsif (($actionurl eq '/adm/dependencies') ||
10677: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10678: ($args->{'context'} eq 'paste')) ||
10679: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10680: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 10681: my $dir;
10682: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10683: $dir = $fileloc;
10684: } else {
10685: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10686: }
1.1071 raeburn 10687: if ($dir ne '') {
10688: my ($sublistref,$listerror) =
10689: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10690: if (ref($sublistref) eq 'ARRAY') {
10691: foreach my $line (@{$sublistref}) {
10692: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10693: undef,$mtime)=split(/\&/,$line,12);
10694: unless (($testdir&$dirptr) ||
10695: ($file_name =~ /^\.\.?$/)) {
10696: $currsubfile{$path}{$file_name} = [$size,$mtime];
10697: }
10698: }
10699: }
10700: }
1.984 raeburn 10701: }
10702: }
10703: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10704: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10705: my $item = $path.'/'.$file;
10706: unless ($mapping{$item} eq $item) {
10707: $pathchanges{$item} = 1;
10708: }
10709: $existing{$item} = 1;
10710: $numexisting ++;
10711: } else {
10712: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10713: }
10714: }
1.1071 raeburn 10715: if ($actionurl eq '/adm/dependencies') {
10716: foreach my $path (keys(%currsubfile)) {
10717: if (ref($currsubfile{$path}) eq 'HASH') {
10718: foreach my $file (keys(%{$currsubfile{$path}})) {
10719: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10720: next if (($rem ne '') &&
10721: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10722: (ref($navmap) &&
10723: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10724: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10725: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10726: $unused{$path.'/'.$file} = 1;
10727: }
10728: }
10729: }
10730: }
10731: }
1.984 raeburn 10732: }
1.987 raeburn 10733: my %currfile;
1.1075.2.35 raeburn 10734: if (($actionurl eq '/adm/portfolio') ||
10735: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10736: my ($dirlistref,$listerror) =
10737: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10738: if (ref($dirlistref) eq 'ARRAY') {
10739: foreach my $line (@{$dirlistref}) {
10740: my ($file_name,$rest) = split(/\&/,$line,2);
10741: $currfile{$file_name} = 1;
10742: }
1.984 raeburn 10743: }
1.987 raeburn 10744: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10745: if (opendir(my $dir,$url)) {
1.987 raeburn 10746: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10747: map {$currfile{$_} = 1;} @dir_list;
10748: }
1.1075.2.11 raeburn 10749: } elsif (($actionurl eq '/adm/dependencies') ||
10750: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10751: ($args->{'context'} eq 'paste')) ||
10752: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10753: if ($env{'request.course.id'} ne '') {
10754: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10755: if ($dir ne '') {
10756: my ($dirlistref,$listerror) =
10757: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10758: if (ref($dirlistref) eq 'ARRAY') {
10759: foreach my $line (@{$dirlistref}) {
10760: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10761: $size,undef,$mtime)=split(/\&/,$line,12);
10762: unless (($testdir&$dirptr) ||
10763: ($file_name =~ /^\.\.?$/)) {
10764: $currfile{$file_name} = [$size,$mtime];
10765: }
10766: }
10767: }
10768: }
10769: }
1.984 raeburn 10770: }
10771: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10772: if (exists($currfile{$file})) {
1.987 raeburn 10773: unless ($mapping{$file} eq $file) {
10774: $pathchanges{$file} = 1;
10775: }
10776: $existing{$file} = 1;
10777: $numexisting ++;
10778: } else {
1.984 raeburn 10779: $newfiles{$file} = 1;
10780: }
10781: }
1.1071 raeburn 10782: foreach my $file (keys(%currfile)) {
10783: unless (($file eq $filename) ||
10784: ($file eq $filename.'.bak') ||
10785: ($dependencies{$file})) {
1.1075.2.11 raeburn 10786: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10787: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10788: next if (($rem ne '') &&
10789: (($env{"httpref.$rem".$file} ne '') ||
10790: (ref($navmap) &&
10791: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10792: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10793: ($navmap->getResourceByUrl($rem.$1)))))));
10794: }
1.1075.2.11 raeburn 10795: }
1.1071 raeburn 10796: $unused{$file} = 1;
10797: }
10798: }
1.1075.2.11 raeburn 10799: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10800: ($args->{'context'} eq 'paste')) {
10801: $counter = scalar(keys(%existing));
10802: $numpathchg = scalar(keys(%pathchanges));
10803: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10804: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10805: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10806: $counter = scalar(keys(%existing));
10807: $numpathchg = scalar(keys(%pathchanges));
10808: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10809: }
1.984 raeburn 10810: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10811: if ($actionurl eq '/adm/dependencies') {
10812: next if ($embed_file =~ m{^\w+://});
10813: }
1.660 raeburn 10814: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10815: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10816: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10817: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10818: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10819: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10820: }
1.1075.2.35 raeburn 10821: $upload_output .= '</td>';
1.1071 raeburn 10822: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10823: $upload_output.='<td align="right">'.
10824: '<span class="LC_info LC_fontsize_medium">'.
10825: &mt("URL points to web address").'</span>';
1.987 raeburn 10826: $numremref++;
1.660 raeburn 10827: } elsif ($args->{'error_on_invalid_names'}
10828: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10829: $upload_output.='<td align="right"><span class="LC_warning">'.
10830: &mt('Invalid characters').'</span>';
1.987 raeburn 10831: $numinvalid++;
1.660 raeburn 10832: } else {
1.1075.2.35 raeburn 10833: $upload_output .= '<td>'.
10834: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10835: $embed_file,\%mapping,
1.1071 raeburn 10836: $allfiles,$codebase,'upload');
10837: $counter ++;
10838: $numnew ++;
1.987 raeburn 10839: }
10840: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10841: }
10842: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10843: if ($actionurl eq '/adm/dependencies') {
10844: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10845: $modify_output .= &start_data_table_row().
10846: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10847: '<img src="'.&icon($embed_file).'" border="0" />'.
10848: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10849: '<td>'.$size.'</td>'.
10850: '<td>'.$mtime.'</td>'.
10851: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10852: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10853: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10854: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10855: &embedded_file_element('upload_embedded',$counter,
10856: $embed_file,\%mapping,
10857: $allfiles,$codebase,'modify').
10858: '</div></td>'.
10859: &end_data_table_row()."\n";
10860: $counter ++;
10861: } else {
10862: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10863: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10864: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10865: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10866: &Apache::loncommon::end_data_table_row()."\n";
10867: }
10868: }
10869: my $delidx = $counter;
10870: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10871: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10872: $delete_output .= &start_data_table_row().
10873: '<td><img src="'.&icon($oldfile).'" />'.
10874: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10875: '<td>'.$size.'</td>'.
10876: '<td>'.$mtime.'</td>'.
10877: '<td><label><input type="checkbox" name="del_upload_dep" '.
10878: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10879: &embedded_file_element('upload_embedded',$delidx,
10880: $oldfile,\%mapping,$allfiles,
10881: $codebase,'delete').'</td>'.
10882: &end_data_table_row()."\n";
10883: $numunused ++;
10884: $delidx ++;
1.987 raeburn 10885: }
10886: if ($upload_output) {
10887: $upload_output = &start_data_table().
10888: $upload_output.
10889: &end_data_table()."\n";
10890: }
1.1071 raeburn 10891: if ($modify_output) {
10892: $modify_output = &start_data_table().
10893: &start_data_table_header_row().
10894: '<th>'.&mt('File').'</th>'.
10895: '<th>'.&mt('Size (KB)').'</th>'.
10896: '<th>'.&mt('Modified').'</th>'.
10897: '<th>'.&mt('Upload replacement?').'</th>'.
10898: &end_data_table_header_row().
10899: $modify_output.
10900: &end_data_table()."\n";
10901: }
10902: if ($delete_output) {
10903: $delete_output = &start_data_table().
10904: &start_data_table_header_row().
10905: '<th>'.&mt('File').'</th>'.
10906: '<th>'.&mt('Size (KB)').'</th>'.
10907: '<th>'.&mt('Modified').'</th>'.
10908: '<th>'.&mt('Delete?').'</th>'.
10909: &end_data_table_header_row().
10910: $delete_output.
10911: &end_data_table()."\n";
10912: }
1.987 raeburn 10913: my $applies = 0;
10914: if ($numremref) {
10915: $applies ++;
10916: }
10917: if ($numinvalid) {
10918: $applies ++;
10919: }
10920: if ($numexisting) {
10921: $applies ++;
10922: }
1.1071 raeburn 10923: if ($counter || $numunused) {
1.987 raeburn 10924: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10925: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10926: $state.'<h3>'.$heading.'</h3>';
10927: if ($actionurl eq '/adm/dependencies') {
10928: if ($numnew) {
10929: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10930: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10931: $upload_output.'<br />'."\n";
10932: }
10933: if ($numexisting) {
10934: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10935: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10936: $modify_output.'<br />'."\n";
10937: $buttontext = &mt('Save changes');
10938: }
10939: if ($numunused) {
10940: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10941: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10942: $delete_output.'<br />'."\n";
10943: $buttontext = &mt('Save changes');
10944: }
10945: } else {
10946: $output .= $upload_output.'<br />'."\n";
10947: }
10948: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10949: $counter.'" />'."\n";
10950: if ($actionurl eq '/adm/dependencies') {
10951: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10952: $numnew.'" />'."\n";
10953: } elsif ($actionurl eq '') {
1.987 raeburn 10954: $output .= '<input type="hidden" name="phase" value="three" />';
10955: }
10956: } elsif ($applies) {
10957: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10958: if ($applies > 1) {
10959: $output .=
1.1075.2.35 raeburn 10960: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10961: if ($numremref) {
10962: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10963: }
10964: if ($numinvalid) {
10965: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10966: }
10967: if ($numexisting) {
10968: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10969: }
10970: $output .= '</ul><br />';
10971: } elsif ($numremref) {
10972: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10973: } elsif ($numinvalid) {
10974: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10975: } elsif ($numexisting) {
10976: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10977: }
10978: $output .= $upload_output.'<br />';
10979: }
10980: my ($pathchange_output,$chgcount);
1.1071 raeburn 10981: $chgcount = $counter;
1.987 raeburn 10982: if (keys(%pathchanges) > 0) {
10983: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10984: if ($counter) {
1.987 raeburn 10985: $output .= &embedded_file_element('pathchange',$chgcount,
10986: $embed_file,\%mapping,
1.1071 raeburn 10987: $allfiles,$codebase,'change');
1.987 raeburn 10988: } else {
10989: $pathchange_output .=
10990: &start_data_table_row().
10991: '<td><input type ="checkbox" name="namechange" value="'.
10992: $chgcount.'" checked="checked" /></td>'.
10993: '<td>'.$mapping{$embed_file}.'</td>'.
10994: '<td>'.$embed_file.
10995: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10996: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10997: '</td>'.&end_data_table_row();
1.660 raeburn 10998: }
1.987 raeburn 10999: $numpathchg ++;
11000: $chgcount ++;
1.660 raeburn 11001: }
11002: }
1.1075.2.35 raeburn 11003: if (($counter) || ($numunused)) {
1.987 raeburn 11004: if ($numpathchg) {
11005: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11006: $numpathchg.'" />'."\n";
11007: }
11008: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11009: ($actionurl eq '/adm/imsimport')) {
11010: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11011: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11012: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11013: } elsif ($actionurl eq '/adm/dependencies') {
11014: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11015: }
1.1075.2.35 raeburn 11016: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11017: } elsif ($numpathchg) {
11018: my %pathchange = ();
11019: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11020: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11021: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 11022: }
1.987 raeburn 11023: }
1.1071 raeburn 11024: return ($output,$counter,$numpathchg);
1.987 raeburn 11025: }
11026:
1.1075.2.47 raeburn 11027: =pod
11028:
11029: =item * clean_path($name)
11030:
11031: Performs clean-up of directories, subdirectories and filename in an
11032: embedded object, referenced in an HTML file which is being uploaded
11033: to a course or portfolio, where
11034: "Upload embedded images/multimedia files if HTML file" checkbox was
11035: checked.
11036:
11037: Clean-up is similar to replacements in lonnet::clean_filename()
11038: except each / between sub-directory and next level is preserved.
11039:
11040: =cut
11041:
11042: sub clean_path {
11043: my ($embed_file) = @_;
11044: $embed_file =~s{^/+}{};
11045: my @contents;
11046: if ($embed_file =~ m{/}) {
11047: @contents = split(/\//,$embed_file);
11048: } else {
11049: @contents = ($embed_file);
11050: }
11051: my $lastidx = scalar(@contents)-1;
11052: for (my $i=0; $i<=$lastidx; $i++) {
11053: $contents[$i]=~s{\\}{/}g;
11054: $contents[$i]=~s/\s+/\_/g;
11055: $contents[$i]=~s{[^/\w\.\-]}{}g;
11056: if ($i == $lastidx) {
11057: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11058: }
11059: }
11060: if ($lastidx > 0) {
11061: return join('/',@contents);
11062: } else {
11063: return $contents[0];
11064: }
11065: }
11066:
1.987 raeburn 11067: sub embedded_file_element {
1.1071 raeburn 11068: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11069: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11070: (ref($codebase) eq 'HASH'));
11071: my $output;
1.1071 raeburn 11072: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11073: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11074: }
11075: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11076: &escape($embed_file).'" />';
11077: unless (($context eq 'upload_embedded') &&
11078: ($mapping->{$embed_file} eq $embed_file)) {
11079: $output .='
11080: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11081: }
11082: my $attrib;
11083: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11084: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11085: }
11086: $output .=
11087: "\n\t\t".
11088: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11089: $attrib.'" />';
11090: if (exists($codebase->{$mapping->{$embed_file}})) {
11091: $output .=
11092: "\n\t\t".
11093: '<input name="codebase_'.$num.'" type="hidden" value="'.
11094: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11095: }
1.987 raeburn 11096: return $output;
1.660 raeburn 11097: }
11098:
1.1071 raeburn 11099: sub get_dependency_details {
11100: my ($currfile,$currsubfile,$embed_file) = @_;
11101: my ($size,$mtime,$showsize,$showmtime);
11102: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11103: if ($embed_file =~ m{/}) {
11104: my ($path,$fname) = split(/\//,$embed_file);
11105: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11106: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11107: }
11108: } else {
11109: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11110: ($size,$mtime) = @{$currfile->{$embed_file}};
11111: }
11112: }
11113: $showsize = $size/1024.0;
11114: $showsize = sprintf("%.1f",$showsize);
11115: if ($mtime > 0) {
11116: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11117: }
11118: }
11119: return ($showsize,$showmtime);
11120: }
11121:
11122: sub ask_embedded_js {
11123: return <<"END";
11124: <script type="text/javascript"">
11125: // <![CDATA[
11126: function toggleBrowse(counter) {
11127: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11128: var fileid = document.getElementById('embedded_item_'+counter);
11129: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11130: if (chkboxid.checked == true) {
11131: uploaddivid.style.display='block';
11132: } else {
11133: uploaddivid.style.display='none';
11134: fileid.value = '';
11135: }
11136: }
11137: // ]]>
11138: </script>
11139:
11140: END
11141: }
11142:
1.661 raeburn 11143: sub upload_embedded {
11144: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11145: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11146: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11147: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11148: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11149: my $orig_uploaded_filename =
11150: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11151: foreach my $type ('orig','ref','attrib','codebase') {
11152: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11153: $env{'form.embedded_'.$type.'_'.$i} =
11154: &unescape($env{'form.embedded_'.$type.'_'.$i});
11155: }
11156: }
1.661 raeburn 11157: my ($path,$fname) =
11158: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11159: # no path, whole string is fname
11160: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11161: $fname = &Apache::lonnet::clean_filename($fname);
11162: # See if there is anything left
11163: next if ($fname eq '');
11164:
11165: # Check if file already exists as a file or directory.
11166: my ($state,$msg);
11167: if ($context eq 'portfolio') {
11168: my $port_path = $dirpath;
11169: if ($group ne '') {
11170: $port_path = "groups/$group/$port_path";
11171: }
1.987 raeburn 11172: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11173: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11174: $dir_root,$port_path,$disk_quota,
11175: $current_disk_usage,$uname,$udom);
11176: if ($state eq 'will_exceed_quota'
1.984 raeburn 11177: || $state eq 'file_locked') {
1.661 raeburn 11178: $output .= $msg;
11179: next;
11180: }
11181: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11182: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11183: if ($state eq 'exists') {
11184: $output .= $msg;
11185: next;
11186: }
11187: }
11188: # Check if extension is valid
11189: if (($fname =~ /\.(\w+)$/) &&
11190: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 11191: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11192: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11193: next;
11194: } elsif (($fname =~ /\.(\w+)$/) &&
11195: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11196: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11197: next;
11198: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 11199: $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 11200: next;
11201: }
11202: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 11203: my $subdir = $path;
11204: $subdir =~ s{/+$}{};
1.661 raeburn 11205: if ($context eq 'portfolio') {
1.984 raeburn 11206: my $result;
11207: if ($state eq 'existingfile') {
11208: $result=
11209: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 11210: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11211: } else {
1.984 raeburn 11212: $result=
11213: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11214: $dirpath.
1.1075.2.35 raeburn 11215: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11216: if ($result !~ m|^/uploaded/|) {
11217: $output .= '<span class="LC_error">'
11218: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11219: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11220: .'</span><br />';
11221: next;
11222: } else {
1.987 raeburn 11223: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11224: $path.$fname.'</span>').'<br />';
1.984 raeburn 11225: }
1.661 raeburn 11226: }
1.1075.2.35 raeburn 11227: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
11228: my $extendedsubdir = $dirpath.'/'.$subdir;
11229: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11230: my $result =
1.1075.2.35 raeburn 11231: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11232: if ($result !~ m|^/uploaded/|) {
11233: $output .= '<span class="LC_error">'
11234: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11235: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11236: .'</span><br />';
11237: next;
11238: } else {
11239: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11240: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 11241: if ($context eq 'syllabus') {
11242: &Apache::lonnet::make_public_indefinitely($result);
11243: }
1.987 raeburn 11244: }
1.661 raeburn 11245: } else {
11246: # Save the file
11247: my $target = $env{'form.embedded_item_'.$i};
11248: my $fullpath = $dir_root.$dirpath.'/'.$path;
11249: my $dest = $fullpath.$fname;
11250: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11251: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11252: my $count;
11253: my $filepath = $dir_root;
1.1027 raeburn 11254: foreach my $subdir (@parts) {
11255: $filepath .= "/$subdir";
11256: if (!-e $filepath) {
1.661 raeburn 11257: mkdir($filepath,0770);
11258: }
11259: }
11260: my $fh;
11261: if (!open($fh,'>'.$dest)) {
11262: &Apache::lonnet::logthis('Failed to create '.$dest);
11263: $output .= '<span class="LC_error">'.
1.1071 raeburn 11264: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11265: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11266: '</span><br />';
11267: } else {
11268: if (!print $fh $env{'form.embedded_item_'.$i}) {
11269: &Apache::lonnet::logthis('Failed to write to '.$dest);
11270: $output .= '<span class="LC_error">'.
1.1071 raeburn 11271: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11272: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11273: '</span><br />';
11274: } else {
1.987 raeburn 11275: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11276: $url.'</span>').'<br />';
11277: unless ($context eq 'testbank') {
11278: $footer .= &mt('View embedded file: [_1]',
11279: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11280: }
11281: }
11282: close($fh);
11283: }
11284: }
11285: if ($env{'form.embedded_ref_'.$i}) {
11286: $pathchange{$i} = 1;
11287: }
11288: }
11289: if ($output) {
11290: $output = '<p>'.$output.'</p>';
11291: }
11292: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11293: $returnflag = 'ok';
1.1071 raeburn 11294: my $numpathchgs = scalar(keys(%pathchange));
11295: if ($numpathchgs > 0) {
1.987 raeburn 11296: if ($context eq 'portfolio') {
11297: $output .= '<p>'.&mt('or').'</p>';
11298: } elsif ($context eq 'testbank') {
1.1071 raeburn 11299: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11300: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11301: $returnflag = 'modify_orightml';
11302: }
11303: }
1.1071 raeburn 11304: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11305: }
11306:
11307: sub modify_html_form {
11308: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11309: my $end = 0;
11310: my $modifyform;
11311: if ($context eq 'upload_embedded') {
11312: return unless (ref($pathchange) eq 'HASH');
11313: if ($env{'form.number_embedded_items'}) {
11314: $end += $env{'form.number_embedded_items'};
11315: }
11316: if ($env{'form.number_pathchange_items'}) {
11317: $end += $env{'form.number_pathchange_items'};
11318: }
11319: if ($end) {
11320: for (my $i=0; $i<$end; $i++) {
11321: if ($i < $env{'form.number_embedded_items'}) {
11322: next unless($pathchange->{$i});
11323: }
11324: $modifyform .=
11325: &start_data_table_row().
11326: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11327: 'checked="checked" /></td>'.
11328: '<td>'.$env{'form.embedded_ref_'.$i}.
11329: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11330: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11331: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11332: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11333: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11334: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11335: '<td>'.$env{'form.embedded_orig_'.$i}.
11336: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11337: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11338: &end_data_table_row();
1.1071 raeburn 11339: }
1.987 raeburn 11340: }
11341: } else {
11342: $modifyform = $pathchgtable;
11343: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11344: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11345: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11346: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11347: }
11348: }
11349: if ($modifyform) {
1.1071 raeburn 11350: if ($actionurl eq '/adm/dependencies') {
11351: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11352: }
1.987 raeburn 11353: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11354: '<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".
11355: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11356: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11357: '</ol></p>'."\n".'<p>'.
11358: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11359: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11360: &start_data_table()."\n".
11361: &start_data_table_header_row().
11362: '<th>'.&mt('Change?').'</th>'.
11363: '<th>'.&mt('Current reference').'</th>'.
11364: '<th>'.&mt('Required reference').'</th>'.
11365: &end_data_table_header_row()."\n".
11366: $modifyform.
11367: &end_data_table().'<br />'."\n".$hiddenstate.
11368: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11369: '</form>'."\n";
11370: }
11371: return;
11372: }
11373:
11374: sub modify_html_refs {
1.1075.2.35 raeburn 11375: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11376: my $container;
11377: if ($context eq 'portfolio') {
11378: $container = $env{'form.container'};
11379: } elsif ($context eq 'coursedoc') {
11380: $container = $env{'form.primaryurl'};
1.1071 raeburn 11381: } elsif ($context eq 'manage_dependencies') {
11382: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11383: $container = "/$container";
1.1075.2.35 raeburn 11384: } elsif ($context eq 'syllabus') {
11385: $container = $url;
1.987 raeburn 11386: } else {
1.1027 raeburn 11387: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11388: }
11389: my (%allfiles,%codebase,$output,$content);
11390: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11391: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11392: if (wantarray) {
11393: return ('',0,0);
11394: } else {
11395: return;
11396: }
11397: }
11398: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11399: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11400: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11401: if (wantarray) {
11402: return ('',0,0);
11403: } else {
11404: return;
11405: }
11406: }
1.987 raeburn 11407: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11408: if ($content eq '-1') {
11409: if (wantarray) {
11410: return ('',0,0);
11411: } else {
11412: return;
11413: }
11414: }
1.987 raeburn 11415: } else {
1.1071 raeburn 11416: unless ($container =~ /^\Q$dir_root\E/) {
11417: if (wantarray) {
11418: return ('',0,0);
11419: } else {
11420: return;
11421: }
11422: }
1.987 raeburn 11423: if (open(my $fh,"<$container")) {
11424: $content = join('', <$fh>);
11425: close($fh);
11426: } else {
1.1071 raeburn 11427: if (wantarray) {
11428: return ('',0,0);
11429: } else {
11430: return;
11431: }
1.987 raeburn 11432: }
11433: }
11434: my ($count,$codebasecount) = (0,0);
11435: my $mm = new File::MMagic;
11436: my $mime_type = $mm->checktype_contents($content);
11437: if ($mime_type eq 'text/html') {
11438: my $parse_result =
11439: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11440: \%codebase,\$content);
11441: if ($parse_result eq 'ok') {
11442: foreach my $i (@changes) {
11443: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11444: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11445: if ($allfiles{$ref}) {
11446: my $newname = $orig;
11447: my ($attrib_regexp,$codebase);
1.1006 raeburn 11448: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11449: if ($attrib_regexp =~ /:/) {
11450: $attrib_regexp =~ s/\:/|/g;
11451: }
11452: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11453: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11454: $count += $numchg;
1.1075.2.35 raeburn 11455: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11456: delete($allfiles{$ref});
1.987 raeburn 11457: }
11458: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11459: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11460: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11461: $codebasecount ++;
11462: }
11463: }
11464: }
1.1075.2.35 raeburn 11465: my $skiprewrites;
1.987 raeburn 11466: if ($count || $codebasecount) {
11467: my $saveresult;
1.1071 raeburn 11468: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11469: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11470: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11471: if ($url eq $container) {
11472: my ($fname) = ($container =~ m{/([^/]+)$});
11473: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11474: $count,'<span class="LC_filename">'.
1.1071 raeburn 11475: $fname.'</span>').'</p>';
1.987 raeburn 11476: } else {
11477: $output = '<p class="LC_error">'.
11478: &mt('Error: update failed for: [_1].',
11479: '<span class="LC_filename">'.
11480: $container.'</span>').'</p>';
11481: }
1.1075.2.35 raeburn 11482: if ($context eq 'syllabus') {
11483: unless ($saveresult eq 'ok') {
11484: $skiprewrites = 1;
11485: }
11486: }
1.987 raeburn 11487: } else {
11488: if (open(my $fh,">$container")) {
11489: print $fh $content;
11490: close($fh);
11491: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11492: $count,'<span class="LC_filename">'.
11493: $container.'</span>').'</p>';
1.661 raeburn 11494: } else {
1.987 raeburn 11495: $output = '<p class="LC_error">'.
11496: &mt('Error: could not update [_1].',
11497: '<span class="LC_filename">'.
11498: $container.'</span>').'</p>';
1.661 raeburn 11499: }
11500: }
11501: }
1.1075.2.35 raeburn 11502: if (($context eq 'syllabus') && (!$skiprewrites)) {
11503: my ($actionurl,$state);
11504: $actionurl = "/public/$udom/$uname/syllabus";
11505: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11506: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11507: \%codebase,
11508: {'context' => 'rewrites',
11509: 'ignore_remote_references' => 1,});
11510: if (ref($mapping) eq 'HASH') {
11511: my $rewrites = 0;
11512: foreach my $key (keys(%{$mapping})) {
11513: next if ($key =~ m{^https?://});
11514: my $ref = $mapping->{$key};
11515: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11516: my $attrib;
11517: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11518: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11519: }
11520: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11521: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11522: $rewrites += $numchg;
11523: }
11524: }
11525: if ($rewrites) {
11526: my $saveresult;
11527: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11528: if ($url eq $container) {
11529: my ($fname) = ($container =~ m{/([^/]+)$});
11530: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11531: $count,'<span class="LC_filename">'.
11532: $fname.'</span>').'</p>';
11533: } else {
11534: $output .= '<p class="LC_error">'.
11535: &mt('Error: could not update links in [_1].',
11536: '<span class="LC_filename">'.
11537: $container.'</span>').'</p>';
11538:
11539: }
11540: }
11541: }
11542: }
1.987 raeburn 11543: } else {
11544: &logthis('Failed to parse '.$container.
11545: ' to modify references: '.$parse_result);
1.661 raeburn 11546: }
11547: }
1.1071 raeburn 11548: if (wantarray) {
11549: return ($output,$count,$codebasecount);
11550: } else {
11551: return $output;
11552: }
1.661 raeburn 11553: }
11554:
11555: sub check_for_existing {
11556: my ($path,$fname,$element) = @_;
11557: my ($state,$msg);
11558: if (-d $path.'/'.$fname) {
11559: $state = 'exists';
11560: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11561: } elsif (-e $path.'/'.$fname) {
11562: $state = 'exists';
11563: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11564: }
11565: if ($state eq 'exists') {
11566: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11567: }
11568: return ($state,$msg);
11569: }
11570:
11571: sub check_for_upload {
11572: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11573: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11574: my $filesize = length($env{'form.'.$element});
11575: if (!$filesize) {
11576: my $msg = '<span class="LC_error">'.
11577: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11578: '<span class="LC_filename">'.$fname.'</span>',
11579: $filesize).'<br />'.
1.1007 raeburn 11580: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11581: '</span>';
11582: return ('zero_bytes',$msg);
11583: }
11584: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11585: my $getpropath = 1;
1.1021 raeburn 11586: my ($dirlistref,$listerror) =
11587: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11588: my $found_file = 0;
11589: my $locked_file = 0;
1.991 raeburn 11590: my @lockers;
11591: my $navmap;
11592: if ($env{'request.course.id'}) {
11593: $navmap = Apache::lonnavmaps::navmap->new();
11594: }
1.1021 raeburn 11595: if (ref($dirlistref) eq 'ARRAY') {
11596: foreach my $line (@{$dirlistref}) {
11597: my ($file_name,$rest)=split(/\&/,$line,2);
11598: if ($file_name eq $fname){
11599: $file_name = $path.$file_name;
11600: if ($group ne '') {
11601: $file_name = $group.$file_name;
11602: }
11603: $found_file = 1;
11604: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11605: foreach my $lock (@lockers) {
11606: if (ref($lock) eq 'ARRAY') {
11607: my ($symb,$crsid) = @{$lock};
11608: if ($crsid eq $env{'request.course.id'}) {
11609: if (ref($navmap)) {
11610: my $res = $navmap->getBySymb($symb);
11611: foreach my $part (@{$res->parts()}) {
11612: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11613: unless (($slot_status == $res->RESERVED) ||
11614: ($slot_status == $res->RESERVED_LOCATION)) {
11615: $locked_file = 1;
11616: }
1.991 raeburn 11617: }
1.1021 raeburn 11618: } else {
11619: $locked_file = 1;
1.991 raeburn 11620: }
11621: } else {
11622: $locked_file = 1;
11623: }
11624: }
1.1021 raeburn 11625: }
11626: } else {
11627: my @info = split(/\&/,$rest);
11628: my $currsize = $info[6]/1000;
11629: if ($currsize < $filesize) {
11630: my $extra = $filesize - $currsize;
11631: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 11632: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11633: &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 11634: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11635: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11636: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11637: return ('will_exceed_quota',$msg);
11638: }
1.984 raeburn 11639: }
11640: }
1.661 raeburn 11641: }
11642: }
11643: }
11644: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 11645: my $msg = '<p class="LC_warning">'.
11646: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
11647: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11648: return ('will_exceed_quota',$msg);
11649: } elsif ($found_file) {
11650: if ($locked_file) {
1.1075.2.69 raeburn 11651: my $msg = '<p class="LC_warning">';
1.661 raeburn 11652: $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 11653: $msg .= '</p>';
1.661 raeburn 11654: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11655: return ('file_locked',$msg);
11656: } else {
1.1075.2.69 raeburn 11657: my $msg = '<p class="LC_error">';
1.984 raeburn 11658: $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 11659: $msg .= '</p>';
1.984 raeburn 11660: return ('existingfile',$msg);
1.661 raeburn 11661: }
11662: }
11663: }
11664:
1.987 raeburn 11665: sub check_for_traversal {
11666: my ($path,$url,$toplevel) = @_;
11667: my @parts=split(/\//,$path);
11668: my $cleanpath;
11669: my $fullpath = $url;
11670: for (my $i=0;$i<@parts;$i++) {
11671: next if ($parts[$i] eq '.');
11672: if ($parts[$i] eq '..') {
11673: $fullpath =~ s{([^/]+/)$}{};
11674: } else {
11675: $fullpath .= $parts[$i].'/';
11676: }
11677: }
11678: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11679: $cleanpath = $1;
11680: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11681: my $curr_toprel = $1;
11682: my @parts = split(/\//,$curr_toprel);
11683: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11684: my @urlparts = split(/\//,$url_toprel);
11685: my $doubledots;
11686: my $startdiff = -1;
11687: for (my $i=0; $i<@urlparts; $i++) {
11688: if ($startdiff == -1) {
11689: unless ($urlparts[$i] eq $parts[$i]) {
11690: $startdiff = $i;
11691: $doubledots .= '../';
11692: }
11693: } else {
11694: $doubledots .= '../';
11695: }
11696: }
11697: if ($startdiff > -1) {
11698: $cleanpath = $doubledots;
11699: for (my $i=$startdiff; $i<@parts; $i++) {
11700: $cleanpath .= $parts[$i].'/';
11701: }
11702: }
11703: }
11704: $cleanpath =~ s{(/)$}{};
11705: return $cleanpath;
11706: }
1.31 albertel 11707:
1.1053 raeburn 11708: sub is_archive_file {
11709: my ($mimetype) = @_;
11710: if (($mimetype eq 'application/octet-stream') ||
11711: ($mimetype eq 'application/x-stuffit') ||
11712: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11713: return 1;
11714: }
11715: return;
11716: }
11717:
11718: sub decompress_form {
1.1065 raeburn 11719: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11720: my %lt = &Apache::lonlocal::texthash (
11721: this => 'This file is an archive file.',
1.1067 raeburn 11722: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11723: itsc => 'Its contents are as follows:',
1.1053 raeburn 11724: youm => 'You may wish to extract its contents.',
11725: extr => 'Extract contents',
1.1067 raeburn 11726: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11727: proa => 'Process automatically?',
1.1053 raeburn 11728: yes => 'Yes',
11729: no => 'No',
1.1067 raeburn 11730: fold => 'Title for folder containing movie',
11731: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11732: );
1.1065 raeburn 11733: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11734: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11735: my $info = &list_archive_contents($fileloc,\@paths);
11736: if (@paths) {
11737: foreach my $path (@paths) {
11738: $path =~ s{^/}{};
1.1067 raeburn 11739: if ($path =~ m{^([^/]+)/$}) {
11740: $topdir = $1;
11741: }
1.1065 raeburn 11742: if ($path =~ m{^([^/]+)/}) {
11743: $toplevel{$1} = $path;
11744: } else {
11745: $toplevel{$path} = $path;
11746: }
11747: }
11748: }
1.1067 raeburn 11749: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 11750: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11751: "$topdir/media/",
11752: "$topdir/media/$topdir.mp4",
11753: "$topdir/media/FirstFrame.png",
11754: "$topdir/media/player.swf",
11755: "$topdir/media/swfobject.js",
11756: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 11757: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 11758: "$topdir/$topdir.mp4",
11759: "$topdir/$topdir\_config.xml",
11760: "$topdir/$topdir\_controller.swf",
11761: "$topdir/$topdir\_embed.css",
11762: "$topdir/$topdir\_First_Frame.png",
11763: "$topdir/$topdir\_player.html",
11764: "$topdir/$topdir\_Thumbnails.png",
11765: "$topdir/playerProductInstall.swf",
11766: "$topdir/scripts/",
11767: "$topdir/scripts/config_xml.js",
11768: "$topdir/scripts/handlebars.js",
11769: "$topdir/scripts/jquery-1.7.1.min.js",
11770: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11771: "$topdir/scripts/modernizr.js",
11772: "$topdir/scripts/player-min.js",
11773: "$topdir/scripts/swfobject.js",
11774: "$topdir/skins/",
11775: "$topdir/skins/configuration_express.xml",
11776: "$topdir/skins/express_show/",
11777: "$topdir/skins/express_show/player-min.css",
11778: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 11779: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11780: "$topdir/$topdir.mp4",
11781: "$topdir/$topdir\_config.xml",
11782: "$topdir/$topdir\_controller.swf",
11783: "$topdir/$topdir\_embed.css",
11784: "$topdir/$topdir\_First_Frame.png",
11785: "$topdir/$topdir\_player.html",
11786: "$topdir/$topdir\_Thumbnails.png",
11787: "$topdir/playerProductInstall.swf",
11788: "$topdir/scripts/",
11789: "$topdir/scripts/config_xml.js",
11790: "$topdir/scripts/techsmith-smart-player.min.js",
11791: "$topdir/skins/",
11792: "$topdir/skins/configuration_express.xml",
11793: "$topdir/skins/express_show/",
11794: "$topdir/skins/express_show/spritesheet.min.css",
11795: "$topdir/skins/express_show/spritesheet.png",
11796: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 11797: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11798: if (@diffs == 0) {
1.1075.2.59 raeburn 11799: $is_camtasia = 6;
11800: } else {
1.1075.2.81 raeburn 11801: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 11802: if (@diffs == 0) {
11803: $is_camtasia = 8;
1.1075.2.81 raeburn 11804: } else {
11805: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
11806: if (@diffs == 0) {
11807: $is_camtasia = 8;
11808: }
1.1075.2.59 raeburn 11809: }
1.1067 raeburn 11810: }
11811: }
11812: my $output;
11813: if ($is_camtasia) {
11814: $output = <<"ENDCAM";
11815: <script type="text/javascript" language="Javascript">
11816: // <![CDATA[
11817:
11818: function camtasiaToggle() {
11819: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11820: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 11821: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11822: document.getElementById('camtasia_titles').style.display='block';
11823: } else {
11824: document.getElementById('camtasia_titles').style.display='none';
11825: }
11826: }
11827: }
11828: return;
11829: }
11830:
11831: // ]]>
11832: </script>
11833: <p>$lt{'camt'}</p>
11834: ENDCAM
1.1065 raeburn 11835: } else {
1.1067 raeburn 11836: $output = '<p>'.$lt{'this'};
11837: if ($info eq '') {
11838: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11839: } else {
11840: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11841: '<div><pre>'.$info.'</pre></div>';
11842: }
1.1065 raeburn 11843: }
1.1067 raeburn 11844: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11845: my $duplicates;
11846: my $num = 0;
11847: if (ref($dirlist) eq 'ARRAY') {
11848: foreach my $item (@{$dirlist}) {
11849: if (ref($item) eq 'ARRAY') {
11850: if (exists($toplevel{$item->[0]})) {
11851: $duplicates .=
11852: &start_data_table_row().
11853: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11854: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11855: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11856: 'value="1" />'.&mt('Yes').'</label>'.
11857: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11858: '<td>'.$item->[0].'</td>';
11859: if ($item->[2]) {
11860: $duplicates .= '<td>'.&mt('Directory').'</td>';
11861: } else {
11862: $duplicates .= '<td>'.&mt('File').'</td>';
11863: }
11864: $duplicates .= '<td>'.$item->[3].'</td>'.
11865: '<td>'.
11866: &Apache::lonlocal::locallocaltime($item->[4]).
11867: '</td>'.
11868: &end_data_table_row();
11869: $num ++;
11870: }
11871: }
11872: }
11873: }
11874: my $itemcount;
11875: if (@paths > 0) {
11876: $itemcount = scalar(@paths);
11877: } else {
11878: $itemcount = 1;
11879: }
1.1067 raeburn 11880: if ($is_camtasia) {
11881: $output .= $lt{'auto'}.'<br />'.
11882: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 11883: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11884: $lt{'yes'}.'</label> <label>'.
11885: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11886: $lt{'no'}.'</label></span><br />'.
11887: '<div id="camtasia_titles" style="display:block">'.
11888: &Apache::lonhtmlcommon::start_pick_box().
11889: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11890: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11891: &Apache::lonhtmlcommon::row_closure().
11892: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11893: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11894: &Apache::lonhtmlcommon::row_closure(1).
11895: &Apache::lonhtmlcommon::end_pick_box().
11896: '</div>';
11897: }
1.1065 raeburn 11898: $output .=
11899: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11900: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11901: "\n";
1.1065 raeburn 11902: if ($duplicates ne '') {
11903: $output .= '<p><span class="LC_warning">'.
11904: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11905: &start_data_table().
11906: &start_data_table_header_row().
11907: '<th>'.&mt('Overwrite?').'</th>'.
11908: '<th>'.&mt('Name').'</th>'.
11909: '<th>'.&mt('Type').'</th>'.
11910: '<th>'.&mt('Size').'</th>'.
11911: '<th>'.&mt('Last modified').'</th>'.
11912: &end_data_table_header_row().
11913: $duplicates.
11914: &end_data_table().
11915: '</p>';
11916: }
1.1067 raeburn 11917: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11918: if (ref($hiddenelements) eq 'HASH') {
11919: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11920: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11921: }
11922: }
11923: $output .= <<"END";
1.1067 raeburn 11924: <br />
1.1053 raeburn 11925: <input type="submit" name="decompress" value="$lt{'extr'}" />
11926: </form>
11927: $noextract
11928: END
11929: return $output;
11930: }
11931:
1.1065 raeburn 11932: sub decompression_utility {
11933: my ($program) = @_;
11934: my @utilities = ('tar','gunzip','bunzip2','unzip');
11935: my $location;
11936: if (grep(/^\Q$program\E$/,@utilities)) {
11937: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11938: '/usr/sbin/') {
11939: if (-x $dir.$program) {
11940: $location = $dir.$program;
11941: last;
11942: }
11943: }
11944: }
11945: return $location;
11946: }
11947:
11948: sub list_archive_contents {
11949: my ($file,$pathsref) = @_;
11950: my (@cmd,$output);
11951: my $needsregexp;
11952: if ($file =~ /\.zip$/) {
11953: @cmd = (&decompression_utility('unzip'),"-l");
11954: $needsregexp = 1;
11955: } elsif (($file =~ m/\.tar\.gz$/) ||
11956: ($file =~ /\.tgz$/)) {
11957: @cmd = (&decompression_utility('tar'),"-ztf");
11958: } elsif ($file =~ /\.tar\.bz2$/) {
11959: @cmd = (&decompression_utility('tar'),"-jtf");
11960: } elsif ($file =~ m|\.tar$|) {
11961: @cmd = (&decompression_utility('tar'),"-tf");
11962: }
11963: if (@cmd) {
11964: undef($!);
11965: undef($@);
11966: if (open(my $fh,"-|", @cmd, $file)) {
11967: while (my $line = <$fh>) {
11968: $output .= $line;
11969: chomp($line);
11970: my $item;
11971: if ($needsregexp) {
11972: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11973: } else {
11974: $item = $line;
11975: }
11976: if ($item ne '') {
11977: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11978: push(@{$pathsref},$item);
11979: }
11980: }
11981: }
11982: close($fh);
11983: }
11984: }
11985: return $output;
11986: }
11987:
1.1053 raeburn 11988: sub decompress_uploaded_file {
11989: my ($file,$dir) = @_;
11990: &Apache::lonnet::appenv({'cgi.file' => $file});
11991: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11992: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11993: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11994: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11995: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11996: my $decompressed = $env{'cgi.decompressed'};
11997: &Apache::lonnet::delenv('cgi.file');
11998: &Apache::lonnet::delenv('cgi.dir');
11999: &Apache::lonnet::delenv('cgi.decompressed');
12000: return ($decompressed,$result);
12001: }
12002:
1.1055 raeburn 12003: sub process_decompression {
12004: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
12005: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 12006: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 12007: $error = &mt('Filename not a supported archive file type.').
12008: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12009: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12010: } else {
12011: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12012: if ($docuhome eq 'no_host') {
12013: $error = &mt('Could not determine home server for course.');
12014: } else {
12015: my @ids=&Apache::lonnet::current_machine_ids();
12016: my $currdir = "$dir_root/$destination";
12017: if (grep(/^\Q$docuhome\E$/,@ids)) {
12018: $dir = &LONCAPA::propath($docudom,$docuname).
12019: "$dir_root/$destination";
12020: } else {
12021: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12022: "$dir_root/$docudom/$docuname/$destination";
12023: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12024: $error = &mt('Archive file not found.');
12025: }
12026: }
1.1065 raeburn 12027: my (@to_overwrite,@to_skip);
12028: if ($env{'form.archive_overwrite_total'} > 0) {
12029: my $total = $env{'form.archive_overwrite_total'};
12030: for (my $i=0; $i<$total; $i++) {
12031: if ($env{'form.archive_overwrite_'.$i} == 1) {
12032: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12033: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12034: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12035: }
12036: }
12037: }
12038: my $numskip = scalar(@to_skip);
12039: if (($numskip > 0) &&
12040: ($numskip == $env{'form.archive_itemcount'})) {
12041: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12042: } elsif ($dir eq '') {
1.1055 raeburn 12043: $error = &mt('Directory containing archive file unavailable.');
12044: } elsif (!$error) {
1.1065 raeburn 12045: my ($decompressed,$display);
12046: if ($numskip > 0) {
12047: my $tempdir = time.'_'.$$.int(rand(10000));
12048: mkdir("$dir/$tempdir",0755);
12049: system("mv $dir/$file $dir/$tempdir/$file");
12050: ($decompressed,$display) =
12051: &decompress_uploaded_file($file,"$dir/$tempdir");
12052: foreach my $item (@to_skip) {
12053: if (($item ne '') && ($item !~ /\.\./)) {
12054: if (-f "$dir/$tempdir/$item") {
12055: unlink("$dir/$tempdir/$item");
12056: } elsif (-d "$dir/$tempdir/$item") {
12057: system("rm -rf $dir/$tempdir/$item");
12058: }
12059: }
12060: }
12061: system("mv $dir/$tempdir/* $dir");
12062: rmdir("$dir/$tempdir");
12063: } else {
12064: ($decompressed,$display) =
12065: &decompress_uploaded_file($file,$dir);
12066: }
1.1055 raeburn 12067: if ($decompressed eq 'ok') {
1.1065 raeburn 12068: $output = '<p class="LC_info">'.
12069: &mt('Files extracted successfully from archive.').
12070: '</p>'."\n";
1.1055 raeburn 12071: my ($warning,$result,@contents);
12072: my ($newdirlistref,$newlisterror) =
12073: &Apache::lonnet::dirlist($currdir,$docudom,
12074: $docuname,1);
12075: my (%is_dir,%changes,@newitems);
12076: my $dirptr = 16384;
1.1065 raeburn 12077: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12078: foreach my $dir_line (@{$newdirlistref}) {
12079: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 12080: unless (($item =~ /^\.+$/) || ($item eq $file) ||
12081: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 12082: push(@newitems,$item);
12083: if ($dirptr&$testdir) {
12084: $is_dir{$item} = 1;
12085: }
12086: $changes{$item} = 1;
12087: }
12088: }
12089: }
12090: if (keys(%changes) > 0) {
12091: foreach my $item (sort(@newitems)) {
12092: if ($changes{$item}) {
12093: push(@contents,$item);
12094: }
12095: }
12096: }
12097: if (@contents > 0) {
1.1067 raeburn 12098: my $wantform;
12099: unless ($env{'form.autoextract_camtasia'}) {
12100: $wantform = 1;
12101: }
1.1056 raeburn 12102: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12103: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12104: $currdir,\%is_dir,
12105: \%children,\%parent,
1.1056 raeburn 12106: \@contents,\%dirorder,
12107: \%titles,$wantform);
1.1055 raeburn 12108: if ($datatable ne '') {
12109: $output .= &archive_options_form('decompressed',$datatable,
12110: $count,$hiddenelem);
1.1065 raeburn 12111: my $startcount = 6;
1.1055 raeburn 12112: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12113: \%titles,\%children);
1.1055 raeburn 12114: }
1.1067 raeburn 12115: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 12116: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12117: my %displayed;
12118: my $total = 1;
12119: $env{'form.archive_directory'} = [];
12120: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12121: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12122: $path =~ s{/$}{};
12123: my $item;
12124: if ($path ne '') {
12125: $item = "$path/$titles{$i}";
12126: } else {
12127: $item = $titles{$i};
12128: }
12129: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12130: if ($item eq $contents[0]) {
12131: push(@{$env{'form.archive_directory'}},$i);
12132: $env{'form.archive_'.$i} = 'display';
12133: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12134: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 12135: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12136: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12137: $env{'form.archive_'.$i} = 'display';
12138: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12139: $displayed{'web'} = $i;
12140: } else {
1.1075.2.59 raeburn 12141: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12142: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12143: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12144: push(@{$env{'form.archive_directory'}},$i);
12145: }
12146: $env{'form.archive_'.$i} = 'dependency';
12147: }
12148: $total ++;
12149: }
12150: for (my $i=1; $i<$total; $i++) {
12151: next if ($i == $displayed{'web'});
12152: next if ($i == $displayed{'folder'});
12153: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12154: }
12155: $env{'form.phase'} = 'decompress_cleanup';
12156: $env{'form.archivedelete'} = 1;
12157: $env{'form.archive_count'} = $total-1;
12158: $output .=
12159: &process_extracted_files('coursedocs',$docudom,
12160: $docuname,$destination,
12161: $dir_root,$hiddenelem);
12162: }
1.1055 raeburn 12163: } else {
12164: $warning = &mt('No new items extracted from archive file.');
12165: }
12166: } else {
12167: $output = $display;
12168: $error = &mt('An error occurred during extraction from the archive file.');
12169: }
12170: }
12171: }
12172: }
12173: if ($error) {
12174: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12175: $error.'</p>'."\n";
12176: }
12177: if ($warning) {
12178: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12179: }
12180: return $output;
12181: }
12182:
12183: sub get_extracted {
1.1056 raeburn 12184: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12185: $titles,$wantform) = @_;
1.1055 raeburn 12186: my $count = 0;
12187: my $depth = 0;
12188: my $datatable;
1.1056 raeburn 12189: my @hierarchy;
1.1055 raeburn 12190: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12191: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12192: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12193: foreach my $item (@{$contents}) {
12194: $count ++;
1.1056 raeburn 12195: @{$dirorder->{$count}} = @hierarchy;
12196: $titles->{$count} = $item;
1.1055 raeburn 12197: &archive_hierarchy($depth,$count,$parent,$children);
12198: if ($wantform) {
12199: $datatable .= &archive_row($is_dir->{$item},$item,
12200: $currdir,$depth,$count);
12201: }
12202: if ($is_dir->{$item}) {
12203: $depth ++;
1.1056 raeburn 12204: push(@hierarchy,$count);
12205: $parent->{$depth} = $count;
1.1055 raeburn 12206: $datatable .=
12207: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12208: \$depth,\$count,\@hierarchy,$dirorder,
12209: $children,$parent,$titles,$wantform);
1.1055 raeburn 12210: $depth --;
1.1056 raeburn 12211: pop(@hierarchy);
1.1055 raeburn 12212: }
12213: }
12214: return ($count,$datatable);
12215: }
12216:
12217: sub recurse_extracted_archive {
1.1056 raeburn 12218: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12219: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12220: my $result='';
1.1056 raeburn 12221: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12222: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12223: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12224: return $result;
12225: }
12226: my $dirptr = 16384;
12227: my ($newdirlistref,$newlisterror) =
12228: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12229: if (ref($newdirlistref) eq 'ARRAY') {
12230: foreach my $dir_line (@{$newdirlistref}) {
12231: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12232: unless ($item =~ /^\.+$/) {
12233: $$count ++;
1.1056 raeburn 12234: @{$dirorder->{$$count}} = @{$hierarchy};
12235: $titles->{$$count} = $item;
1.1055 raeburn 12236: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12237:
1.1055 raeburn 12238: my $is_dir;
12239: if ($dirptr&$testdir) {
12240: $is_dir = 1;
12241: }
12242: if ($wantform) {
12243: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12244: }
12245: if ($is_dir) {
12246: $$depth ++;
1.1056 raeburn 12247: push(@{$hierarchy},$$count);
12248: $parent->{$$depth} = $$count;
1.1055 raeburn 12249: $result .=
12250: &recurse_extracted_archive("$currdir/$item",$docudom,
12251: $docuname,$depth,$count,
1.1056 raeburn 12252: $hierarchy,$dirorder,$children,
12253: $parent,$titles,$wantform);
1.1055 raeburn 12254: $$depth --;
1.1056 raeburn 12255: pop(@{$hierarchy});
1.1055 raeburn 12256: }
12257: }
12258: }
12259: }
12260: return $result;
12261: }
12262:
12263: sub archive_hierarchy {
12264: my ($depth,$count,$parent,$children) =@_;
12265: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12266: if (exists($parent->{$depth})) {
12267: $children->{$parent->{$depth}} .= $count.':';
12268: }
12269: }
12270: return;
12271: }
12272:
12273: sub archive_row {
12274: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12275: my ($name) = ($item =~ m{([^/]+)$});
12276: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12277: 'display' => 'Add as file',
1.1055 raeburn 12278: 'dependency' => 'Include as dependency',
12279: 'discard' => 'Discard',
12280: );
12281: if ($is_dir) {
1.1059 raeburn 12282: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12283: }
1.1056 raeburn 12284: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12285: my $offset = 0;
1.1055 raeburn 12286: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12287: $offset ++;
1.1065 raeburn 12288: if ($action ne 'display') {
12289: $offset ++;
12290: }
1.1055 raeburn 12291: $output .= '<td><span class="LC_nobreak">'.
12292: '<label><input type="radio" name="archive_'.$count.
12293: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12294: my $text = $choices{$action};
12295: if ($is_dir) {
12296: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12297: if ($action eq 'display') {
1.1059 raeburn 12298: $text = &mt('Add as folder');
1.1055 raeburn 12299: }
1.1056 raeburn 12300: } else {
12301: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12302:
12303: }
12304: $output .= ' /> '.$choices{$action}.'</label></span>';
12305: if ($action eq 'dependency') {
12306: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12307: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12308: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12309: '<option value=""></option>'."\n".
12310: '</select>'."\n".
12311: '</div>';
1.1059 raeburn 12312: } elsif ($action eq 'display') {
12313: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12314: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12315: '</div>';
1.1055 raeburn 12316: }
1.1056 raeburn 12317: $output .= '</td>';
1.1055 raeburn 12318: }
12319: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12320: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12321: for (my $i=0; $i<$depth; $i++) {
12322: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12323: }
12324: if ($is_dir) {
12325: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12326: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12327: } else {
12328: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12329: }
12330: $output .= ' '.$name.'</td>'."\n".
12331: &end_data_table_row();
12332: return $output;
12333: }
12334:
12335: sub archive_options_form {
1.1065 raeburn 12336: my ($form,$display,$count,$hiddenelem) = @_;
12337: my %lt = &Apache::lonlocal::texthash(
12338: perm => 'Permanently remove archive file?',
12339: hows => 'How should each extracted item be incorporated in the course?',
12340: cont => 'Content actions for all',
12341: addf => 'Add as folder/file',
12342: incd => 'Include as dependency for a displayed file',
12343: disc => 'Discard',
12344: no => 'No',
12345: yes => 'Yes',
12346: save => 'Save',
12347: );
12348: my $output = <<"END";
12349: <form name="$form" method="post" action="">
12350: <p><span class="LC_nobreak">$lt{'perm'}
12351: <label>
12352: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12353: </label>
12354:
12355: <label>
12356: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12357: </span>
12358: </p>
12359: <input type="hidden" name="phase" value="decompress_cleanup" />
12360: <br />$lt{'hows'}
12361: <div class="LC_columnSection">
12362: <fieldset>
12363: <legend>$lt{'cont'}</legend>
12364: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12365: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12366: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12367: </fieldset>
12368: </div>
12369: END
12370: return $output.
1.1055 raeburn 12371: &start_data_table()."\n".
1.1065 raeburn 12372: $display."\n".
1.1055 raeburn 12373: &end_data_table()."\n".
12374: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12375: $hiddenelem.
1.1065 raeburn 12376: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12377: '</form>';
12378: }
12379:
12380: sub archive_javascript {
1.1056 raeburn 12381: my ($startcount,$numitems,$titles,$children) = @_;
12382: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12383: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12384: my $scripttag = <<START;
12385: <script type="text/javascript">
12386: // <![CDATA[
12387:
12388: function checkAll(form,prefix) {
12389: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12390: for (var i=0; i < form.elements.length; i++) {
12391: var id = form.elements[i].id;
12392: if ((id != '') && (id != undefined)) {
12393: if (idstr.test(id)) {
12394: if (form.elements[i].type == 'radio') {
12395: form.elements[i].checked = true;
1.1056 raeburn 12396: var nostart = i-$startcount;
1.1059 raeburn 12397: var offset = nostart%7;
12398: var count = (nostart-offset)/7;
1.1056 raeburn 12399: dependencyCheck(form,count,offset);
1.1055 raeburn 12400: }
12401: }
12402: }
12403: }
12404: }
12405:
12406: function propagateCheck(form,count) {
12407: if (count > 0) {
1.1059 raeburn 12408: var startelement = $startcount + ((count-1) * 7);
12409: for (var j=1; j<6; j++) {
12410: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12411: var item = startelement + j;
12412: if (form.elements[item].type == 'radio') {
12413: if (form.elements[item].checked) {
12414: containerCheck(form,count,j);
12415: break;
12416: }
1.1055 raeburn 12417: }
12418: }
12419: }
12420: }
12421: }
12422:
12423: numitems = $numitems
1.1056 raeburn 12424: var titles = new Array(numitems);
12425: var parents = new Array(numitems);
1.1055 raeburn 12426: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12427: parents[i] = new Array;
1.1055 raeburn 12428: }
1.1059 raeburn 12429: var maintitle = '$maintitle';
1.1055 raeburn 12430:
12431: START
12432:
1.1056 raeburn 12433: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12434: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12435: for (my $i=0; $i<@contents; $i ++) {
12436: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12437: }
12438: }
12439:
1.1056 raeburn 12440: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12441: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12442: }
12443:
1.1055 raeburn 12444: $scripttag .= <<END;
12445:
12446: function containerCheck(form,count,offset) {
12447: if (count > 0) {
1.1056 raeburn 12448: dependencyCheck(form,count,offset);
1.1059 raeburn 12449: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12450: form.elements[item].checked = true;
12451: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12452: if (parents[count].length > 0) {
12453: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12454: containerCheck(form,parents[count][j],offset);
12455: }
12456: }
12457: }
12458: }
12459: }
12460:
12461: function dependencyCheck(form,count,offset) {
12462: if (count > 0) {
1.1059 raeburn 12463: var chosen = (offset+$startcount)+7*(count-1);
12464: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12465: var currtype = form.elements[depitem].type;
12466: if (form.elements[chosen].value == 'dependency') {
12467: document.getElementById('arc_depon_'+count).style.display='block';
12468: form.elements[depitem].options.length = 0;
12469: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12470: for (var i=1; i<=numitems; i++) {
12471: if (i == count) {
12472: continue;
12473: }
1.1059 raeburn 12474: var startelement = $startcount + (i-1) * 7;
12475: for (var j=1; j<6; j++) {
12476: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12477: var item = startelement + j;
12478: if (form.elements[item].type == 'radio') {
12479: if (form.elements[item].checked) {
12480: if (form.elements[item].value == 'display') {
12481: var n = form.elements[depitem].options.length;
12482: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12483: }
12484: }
12485: }
12486: }
12487: }
12488: }
12489: } else {
12490: document.getElementById('arc_depon_'+count).style.display='none';
12491: form.elements[depitem].options.length = 0;
12492: form.elements[depitem].options[0] = new Option('Select','',true,true);
12493: }
1.1059 raeburn 12494: titleCheck(form,count,offset);
1.1056 raeburn 12495: }
12496: }
12497:
12498: function propagateSelect(form,count,offset) {
12499: if (count > 0) {
1.1065 raeburn 12500: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12501: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12502: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12503: if (parents[count].length > 0) {
12504: for (var j=0; j<parents[count].length; j++) {
12505: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12506: }
12507: }
12508: }
12509: }
12510: }
1.1056 raeburn 12511:
12512: function containerSelect(form,count,offset,picked) {
12513: if (count > 0) {
1.1065 raeburn 12514: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12515: if (form.elements[item].type == 'radio') {
12516: if (form.elements[item].value == 'dependency') {
12517: if (form.elements[item+1].type == 'select-one') {
12518: for (var i=0; i<form.elements[item+1].options.length; i++) {
12519: if (form.elements[item+1].options[i].value == picked) {
12520: form.elements[item+1].selectedIndex = i;
12521: break;
12522: }
12523: }
12524: }
12525: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12526: if (parents[count].length > 0) {
12527: for (var j=0; j<parents[count].length; j++) {
12528: containerSelect(form,parents[count][j],offset,picked);
12529: }
12530: }
12531: }
12532: }
12533: }
12534: }
12535: }
12536:
1.1059 raeburn 12537: function titleCheck(form,count,offset) {
12538: if (count > 0) {
12539: var chosen = (offset+$startcount)+7*(count-1);
12540: var depitem = $startcount + ((count-1) * 7) + 2;
12541: var currtype = form.elements[depitem].type;
12542: if (form.elements[chosen].value == 'display') {
12543: document.getElementById('arc_title_'+count).style.display='block';
12544: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12545: document.getElementById('archive_title_'+count).value=maintitle;
12546: }
12547: } else {
12548: document.getElementById('arc_title_'+count).style.display='none';
12549: if (currtype == 'text') {
12550: document.getElementById('archive_title_'+count).value='';
12551: }
12552: }
12553: }
12554: return;
12555: }
12556:
1.1055 raeburn 12557: // ]]>
12558: </script>
12559: END
12560: return $scripttag;
12561: }
12562:
12563: sub process_extracted_files {
1.1067 raeburn 12564: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12565: my $numitems = $env{'form.archive_count'};
12566: return unless ($numitems);
12567: my @ids=&Apache::lonnet::current_machine_ids();
12568: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12569: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12570: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12571: if (grep(/^\Q$docuhome\E$/,@ids)) {
12572: $prefix = &LONCAPA::propath($docudom,$docuname);
12573: $pathtocheck = "$dir_root/$destination";
12574: $dir = $dir_root;
12575: $ishome = 1;
12576: } else {
12577: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12578: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
12579: $dir = "$dir_root/$docudom/$docuname";
12580: }
12581: my $currdir = "$dir_root/$destination";
12582: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12583: if ($env{'form.folderpath'}) {
12584: my @items = split('&',$env{'form.folderpath'});
12585: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 12586: if ($env{'form.folderpath'} =~ /\:1$/) {
12587: $containers{'0'}='page';
12588: } else {
12589: $containers{'0'}='sequence';
12590: }
1.1055 raeburn 12591: }
12592: my @archdirs = &get_env_multiple('form.archive_directory');
12593: if ($numitems) {
12594: for (my $i=1; $i<=$numitems; $i++) {
12595: my $path = $env{'form.archive_content_'.$i};
12596: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12597: my $item = $1;
12598: $toplevelitems{$item} = $i;
12599: if (grep(/^\Q$i\E$/,@archdirs)) {
12600: $is_dir{$item} = 1;
12601: }
12602: }
12603: }
12604: }
1.1067 raeburn 12605: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12606: if (keys(%toplevelitems) > 0) {
12607: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12608: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12609: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12610: }
1.1066 raeburn 12611: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12612: if ($numitems) {
12613: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 12614: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12615: my $path = $env{'form.archive_content_'.$i};
12616: if ($path =~ /^\Q$pathtocheck\E/) {
12617: if ($env{'form.archive_'.$i} eq 'discard') {
12618: if ($prefix ne '' && $path ne '') {
12619: if (-e $prefix.$path) {
1.1066 raeburn 12620: if ((@archdirs > 0) &&
12621: (grep(/^\Q$i\E$/,@archdirs))) {
12622: $todeletedir{$prefix.$path} = 1;
12623: } else {
12624: $todelete{$prefix.$path} = 1;
12625: }
1.1055 raeburn 12626: }
12627: }
12628: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12629: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12630: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12631: $docstitle = $env{'form.archive_title_'.$i};
12632: if ($docstitle eq '') {
12633: $docstitle = $title;
12634: }
1.1055 raeburn 12635: $outer = 0;
1.1056 raeburn 12636: if (ref($dirorder{$i}) eq 'ARRAY') {
12637: if (@{$dirorder{$i}} > 0) {
12638: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12639: if ($env{'form.archive_'.$item} eq 'display') {
12640: $outer = $item;
12641: last;
12642: }
12643: }
12644: }
12645: }
12646: my ($errtext,$fatal) =
12647: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12648: '/'.$folders{$outer}.'.'.
12649: $containers{$outer});
12650: next if ($fatal);
12651: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12652: if ($context eq 'coursedocs') {
1.1056 raeburn 12653: $mapinner{$i} = time;
1.1055 raeburn 12654: $folders{$i} = 'default_'.$mapinner{$i};
12655: $containers{$i} = 'sequence';
12656: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12657: $folders{$i}.'.'.$containers{$i};
12658: my $newidx = &LONCAPA::map::getresidx();
12659: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12660: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12661: push(@LONCAPA::map::order,$newidx);
12662: my ($outtext,$errtext) =
12663: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12664: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12665: '.'.$containers{$outer},1,1);
1.1056 raeburn 12666: $newseqid{$i} = $newidx;
1.1067 raeburn 12667: unless ($errtext) {
12668: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
12669: }
1.1055 raeburn 12670: }
12671: } else {
12672: if ($context eq 'coursedocs') {
12673: my $newidx=&LONCAPA::map::getresidx();
12674: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12675: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12676: $title;
12677: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12678: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
12679: }
12680: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12681: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12682: }
12683: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12684: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 12685: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 12686: unless ($ishome) {
12687: my $fetch = "$newdest{$i}/$title";
12688: $fetch =~ s/^\Q$prefix$dir\E//;
12689: $prompttofetch{$fetch} = 1;
12690: }
1.1055 raeburn 12691: }
12692: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12693: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12694: push(@LONCAPA::map::order, $newidx);
12695: my ($outtext,$errtext)=
12696: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12697: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12698: '.'.$containers{$outer},1,1);
1.1067 raeburn 12699: unless ($errtext) {
12700: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
12701: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
12702: }
12703: }
1.1055 raeburn 12704: }
12705: }
1.1075.2.11 raeburn 12706: }
12707: } else {
12708: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12709: }
12710: }
12711: for (my $i=1; $i<=$numitems; $i++) {
12712: next unless ($env{'form.archive_'.$i} eq 'dependency');
12713: my $path = $env{'form.archive_content_'.$i};
12714: if ($path =~ /^\Q$pathtocheck\E/) {
12715: my ($title) = ($path =~ m{/([^/]+)$});
12716: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12717: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12718: if (ref($dirorder{$i}) eq 'ARRAY') {
12719: my ($itemidx,$fullpath,$relpath);
12720: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12721: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12722: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 12723: if ($dirorder{$i}->[$j] eq $container) {
12724: $itemidx = $j;
1.1056 raeburn 12725: }
12726: }
1.1075.2.11 raeburn 12727: }
12728: if ($itemidx eq '') {
12729: $itemidx = 0;
12730: }
12731: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12732: if ($mapinner{$referrer{$i}}) {
12733: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12734: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12735: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12736: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12737: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12738: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12739: if (!-e $fullpath) {
12740: mkdir($fullpath,0755);
1.1056 raeburn 12741: }
12742: }
1.1075.2.11 raeburn 12743: } else {
12744: last;
1.1056 raeburn 12745: }
1.1075.2.11 raeburn 12746: }
12747: }
12748: } elsif ($newdest{$referrer{$i}}) {
12749: $fullpath = $newdest{$referrer{$i}};
12750: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12751: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12752: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12753: last;
12754: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12755: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12756: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12757: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12758: if (!-e $fullpath) {
12759: mkdir($fullpath,0755);
1.1056 raeburn 12760: }
12761: }
1.1075.2.11 raeburn 12762: } else {
12763: last;
1.1056 raeburn 12764: }
1.1075.2.11 raeburn 12765: }
12766: }
12767: if ($fullpath ne '') {
12768: if (-e "$prefix$path") {
12769: system("mv $prefix$path $fullpath/$title");
12770: }
12771: if (-e "$fullpath/$title") {
12772: my $showpath;
12773: if ($relpath ne '') {
12774: $showpath = "$relpath/$title";
12775: } else {
12776: $showpath = "/$title";
1.1056 raeburn 12777: }
1.1075.2.11 raeburn 12778: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12779: }
12780: unless ($ishome) {
12781: my $fetch = "$fullpath/$title";
12782: $fetch =~ s/^\Q$prefix$dir\E//;
12783: $prompttofetch{$fetch} = 1;
1.1055 raeburn 12784: }
12785: }
12786: }
1.1075.2.11 raeburn 12787: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12788: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12789: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12790: }
12791: } else {
1.1075.2.11 raeburn 12792: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055 raeburn 12793: }
12794: }
12795: if (keys(%todelete)) {
12796: foreach my $key (keys(%todelete)) {
12797: unlink($key);
1.1066 raeburn 12798: }
12799: }
12800: if (keys(%todeletedir)) {
12801: foreach my $key (keys(%todeletedir)) {
12802: rmdir($key);
12803: }
12804: }
12805: foreach my $dir (sort(keys(%is_dir))) {
12806: if (($pathtocheck ne '') && ($dir ne '')) {
12807: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12808: }
12809: }
1.1067 raeburn 12810: if ($result ne '') {
12811: $output .= '<ul>'."\n".
12812: $result."\n".
12813: '</ul>';
12814: }
12815: unless ($ishome) {
12816: my $replicationfail;
12817: foreach my $item (keys(%prompttofetch)) {
12818: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12819: unless ($fetchresult eq 'ok') {
12820: $replicationfail .= '<li>'.$item.'</li>'."\n";
12821: }
12822: }
12823: if ($replicationfail) {
12824: $output .= '<p class="LC_error">'.
12825: &mt('Course home server failed to retrieve:').'<ul>'.
12826: $replicationfail.
12827: '</ul></p>';
12828: }
12829: }
1.1055 raeburn 12830: } else {
12831: $warning = &mt('No items found in archive.');
12832: }
12833: if ($error) {
12834: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12835: $error.'</p>'."\n";
12836: }
12837: if ($warning) {
12838: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12839: }
12840: return $output;
12841: }
12842:
1.1066 raeburn 12843: sub cleanup_empty_dirs {
12844: my ($path) = @_;
12845: if (($path ne '') && (-d $path)) {
12846: if (opendir(my $dirh,$path)) {
12847: my @dircontents = grep(!/^\./,readdir($dirh));
12848: my $numitems = 0;
12849: foreach my $item (@dircontents) {
12850: if (-d "$path/$item") {
1.1075.2.28 raeburn 12851: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12852: if (-e "$path/$item") {
12853: $numitems ++;
12854: }
12855: } else {
12856: $numitems ++;
12857: }
12858: }
12859: if ($numitems == 0) {
12860: rmdir($path);
12861: }
12862: closedir($dirh);
12863: }
12864: }
12865: return;
12866: }
12867:
1.41 ng 12868: =pod
1.45 matthew 12869:
1.1075.2.56 raeburn 12870: =item * &get_folder_hierarchy()
1.1068 raeburn 12871:
12872: Provides hierarchy of names of folders/sub-folders containing the current
12873: item,
12874:
12875: Inputs: 3
12876: - $navmap - navmaps object
12877:
12878: - $map - url for map (either the trigger itself, or map containing
12879: the resource, which is the trigger).
12880:
12881: - $showitem - 1 => show title for map itself; 0 => do not show.
12882:
12883: Outputs: 1 @pathitems - array of folder/subfolder names.
12884:
12885: =cut
12886:
12887: sub get_folder_hierarchy {
12888: my ($navmap,$map,$showitem) = @_;
12889: my @pathitems;
12890: if (ref($navmap)) {
12891: my $mapres = $navmap->getResourceByUrl($map);
12892: if (ref($mapres)) {
12893: my $pcslist = $mapres->map_hierarchy();
12894: if ($pcslist ne '') {
12895: my @pcs = split(/,/,$pcslist);
12896: foreach my $pc (@pcs) {
12897: if ($pc == 1) {
1.1075.2.38 raeburn 12898: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12899: } else {
12900: my $res = $navmap->getByMapPc($pc);
12901: if (ref($res)) {
12902: my $title = $res->compTitle();
12903: $title =~ s/\W+/_/g;
12904: if ($title ne '') {
12905: push(@pathitems,$title);
12906: }
12907: }
12908: }
12909: }
12910: }
1.1071 raeburn 12911: if ($showitem) {
12912: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 12913: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12914: } else {
12915: my $maptitle = $mapres->compTitle();
12916: $maptitle =~ s/\W+/_/g;
12917: if ($maptitle ne '') {
12918: push(@pathitems,$maptitle);
12919: }
1.1068 raeburn 12920: }
12921: }
12922: }
12923: }
12924: return @pathitems;
12925: }
12926:
12927: =pod
12928:
1.1015 raeburn 12929: =item * &get_turnedin_filepath()
12930:
12931: Determines path in a user's portfolio file for storage of files uploaded
12932: to a specific essayresponse or dropbox item.
12933:
12934: Inputs: 3 required + 1 optional.
12935: $symb is symb for resource, $uname and $udom are for current user (required).
12936: $caller is optional (can be "submission", if routine is called when storing
12937: an upoaded file when "Submit Answer" button was pressed).
12938:
12939: Returns array containing $path and $multiresp.
12940: $path is path in portfolio. $multiresp is 1 if this resource contains more
12941: than one file upload item. Callers of routine should append partid as a
12942: subdirectory to $path in cases where $multiresp is 1.
12943:
12944: Called by: homework/essayresponse.pm and homework/structuretags.pm
12945:
12946: =cut
12947:
12948: sub get_turnedin_filepath {
12949: my ($symb,$uname,$udom,$caller) = @_;
12950: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12951: my $turnindir;
12952: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12953: $turnindir = $userhash{'turnindir'};
12954: my ($path,$multiresp);
12955: if ($turnindir eq '') {
12956: if ($caller eq 'submission') {
12957: $turnindir = &mt('turned in');
12958: $turnindir =~ s/\W+/_/g;
12959: my %newhash = (
12960: 'turnindir' => $turnindir,
12961: );
12962: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12963: }
12964: }
12965: if ($turnindir ne '') {
12966: $path = '/'.$turnindir.'/';
12967: my ($multipart,$turnin,@pathitems);
12968: my $navmap = Apache::lonnavmaps::navmap->new();
12969: if (defined($navmap)) {
12970: my $mapres = $navmap->getResourceByUrl($map);
12971: if (ref($mapres)) {
12972: my $pcslist = $mapres->map_hierarchy();
12973: if ($pcslist ne '') {
12974: foreach my $pc (split(/,/,$pcslist)) {
12975: my $res = $navmap->getByMapPc($pc);
12976: if (ref($res)) {
12977: my $title = $res->compTitle();
12978: $title =~ s/\W+/_/g;
12979: if ($title ne '') {
1.1075.2.48 raeburn 12980: if (($pc > 1) && (length($title) > 12)) {
12981: $title = substr($title,0,12);
12982: }
1.1015 raeburn 12983: push(@pathitems,$title);
12984: }
12985: }
12986: }
12987: }
12988: my $maptitle = $mapres->compTitle();
12989: $maptitle =~ s/\W+/_/g;
12990: if ($maptitle ne '') {
1.1075.2.48 raeburn 12991: if (length($maptitle) > 12) {
12992: $maptitle = substr($maptitle,0,12);
12993: }
1.1015 raeburn 12994: push(@pathitems,$maptitle);
12995: }
12996: unless ($env{'request.state'} eq 'construct') {
12997: my $res = $navmap->getBySymb($symb);
12998: if (ref($res)) {
12999: my $partlist = $res->parts();
13000: my $totaluploads = 0;
13001: if (ref($partlist) eq 'ARRAY') {
13002: foreach my $part (@{$partlist}) {
13003: my @types = $res->responseType($part);
13004: my @ids = $res->responseIds($part);
13005: for (my $i=0; $i < scalar(@ids); $i++) {
13006: if ($types[$i] eq 'essay') {
13007: my $partid = $part.'_'.$ids[$i];
13008: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13009: $totaluploads ++;
13010: }
13011: }
13012: }
13013: }
13014: if ($totaluploads > 1) {
13015: $multiresp = 1;
13016: }
13017: }
13018: }
13019: }
13020: } else {
13021: return;
13022: }
13023: } else {
13024: return;
13025: }
13026: my $restitle=&Apache::lonnet::gettitle($symb);
13027: $restitle =~ s/\W+/_/g;
13028: if ($restitle eq '') {
13029: $restitle = ($resurl =~ m{/[^/]+$});
13030: if ($restitle eq '') {
13031: $restitle = time;
13032: }
13033: }
1.1075.2.48 raeburn 13034: if (length($restitle) > 12) {
13035: $restitle = substr($restitle,0,12);
13036: }
1.1015 raeburn 13037: push(@pathitems,$restitle);
13038: $path .= join('/',@pathitems);
13039: }
13040: return ($path,$multiresp);
13041: }
13042:
13043: =pod
13044:
1.464 albertel 13045: =back
1.41 ng 13046:
1.112 bowersj2 13047: =head1 CSV Upload/Handling functions
1.38 albertel 13048:
1.41 ng 13049: =over 4
13050:
1.648 raeburn 13051: =item * &upfile_store($r)
1.41 ng 13052:
13053: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13054: needs $env{'form.upfile'}
1.41 ng 13055: returns $datatoken to be put into hidden field
13056:
13057: =cut
1.31 albertel 13058:
13059: sub upfile_store {
13060: my $r=shift;
1.258 albertel 13061: $env{'form.upfile'}=~s/\r/\n/gs;
13062: $env{'form.upfile'}=~s/\f/\n/gs;
13063: $env{'form.upfile'}=~s/\n+/\n/gs;
13064: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13065:
1.258 albertel 13066: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
13067: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 13068: {
1.158 raeburn 13069: my $datafile = $r->dir_config('lonDaemons').
13070: '/tmp/'.$datatoken.'.tmp';
13071: if ( open(my $fh,">$datafile") ) {
1.258 albertel 13072: print $fh $env{'form.upfile'};
1.158 raeburn 13073: close($fh);
13074: }
1.31 albertel 13075: }
13076: return $datatoken;
13077: }
13078:
1.56 matthew 13079: =pod
13080:
1.648 raeburn 13081: =item * &load_tmp_file($r)
1.41 ng 13082:
13083: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 13084: needs $env{'form.datatoken'},
13085: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13086:
13087: =cut
1.31 albertel 13088:
13089: sub load_tmp_file {
13090: my $r=shift;
13091: my @studentdata=();
13092: {
1.158 raeburn 13093: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 13094: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 13095: if ( open(my $fh,"<$studentfile") ) {
13096: @studentdata=<$fh>;
13097: close($fh);
13098: }
1.31 albertel 13099: }
1.258 albertel 13100: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13101: }
13102:
1.56 matthew 13103: =pod
13104:
1.648 raeburn 13105: =item * &upfile_record_sep()
1.41 ng 13106:
13107: Separate uploaded file into records
13108: returns array of records,
1.258 albertel 13109: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13110:
13111: =cut
1.31 albertel 13112:
13113: sub upfile_record_sep {
1.258 albertel 13114: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13115: } else {
1.248 albertel 13116: my @records;
1.258 albertel 13117: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13118: if ($line=~/^\s*$/) { next; }
13119: push(@records,$line);
13120: }
13121: return @records;
1.31 albertel 13122: }
13123: }
13124:
1.56 matthew 13125: =pod
13126:
1.648 raeburn 13127: =item * &record_sep($record)
1.41 ng 13128:
1.258 albertel 13129: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13130:
13131: =cut
13132:
1.263 www 13133: sub takeleft {
13134: my $index=shift;
13135: return substr('0000'.$index,-4,4);
13136: }
13137:
1.31 albertel 13138: sub record_sep {
13139: my $record=shift;
13140: my %components=();
1.258 albertel 13141: if ($env{'form.upfiletype'} eq 'xml') {
13142: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13143: my $i=0;
1.356 albertel 13144: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13145: $field=~s/^(\"|\')//;
13146: $field=~s/(\"|\')$//;
1.263 www 13147: $components{&takeleft($i)}=$field;
1.31 albertel 13148: $i++;
13149: }
1.258 albertel 13150: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13151: my $i=0;
1.356 albertel 13152: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13153: $field=~s/^(\"|\')//;
13154: $field=~s/(\"|\')$//;
1.263 www 13155: $components{&takeleft($i)}=$field;
1.31 albertel 13156: $i++;
13157: }
13158: } else {
1.561 www 13159: my $separator=',';
1.480 banghart 13160: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13161: $separator=';';
1.480 banghart 13162: }
1.31 albertel 13163: my $i=0;
1.561 www 13164: # the character we are looking for to indicate the end of a quote or a record
13165: my $looking_for=$separator;
13166: # do not add the characters to the fields
13167: my $ignore=0;
13168: # we just encountered a separator (or the beginning of the record)
13169: my $just_found_separator=1;
13170: # store the field we are working on here
13171: my $field='';
13172: # work our way through all characters in record
13173: foreach my $character ($record=~/(.)/g) {
13174: if ($character eq $looking_for) {
13175: if ($character ne $separator) {
13176: # Found the end of a quote, again looking for separator
13177: $looking_for=$separator;
13178: $ignore=1;
13179: } else {
13180: # Found a separator, store away what we got
13181: $components{&takeleft($i)}=$field;
13182: $i++;
13183: $just_found_separator=1;
13184: $ignore=0;
13185: $field='';
13186: }
13187: next;
13188: }
13189: # single or double quotation marks after a separator indicate beginning of a quote
13190: # we are now looking for the end of the quote and need to ignore separators
13191: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13192: $looking_for=$character;
13193: next;
13194: }
13195: # ignore would be true after we reached the end of a quote
13196: if ($ignore) { next; }
13197: if (($just_found_separator) && ($character=~/\s/)) { next; }
13198: $field.=$character;
13199: $just_found_separator=0;
1.31 albertel 13200: }
1.561 www 13201: # catch the very last entry, since we never encountered the separator
13202: $components{&takeleft($i)}=$field;
1.31 albertel 13203: }
13204: return %components;
13205: }
13206:
1.144 matthew 13207: ######################################################
13208: ######################################################
13209:
1.56 matthew 13210: =pod
13211:
1.648 raeburn 13212: =item * &upfile_select_html()
1.41 ng 13213:
1.144 matthew 13214: Return HTML code to select a file from the users machine and specify
13215: the file type.
1.41 ng 13216:
13217: =cut
13218:
1.144 matthew 13219: ######################################################
13220: ######################################################
1.31 albertel 13221: sub upfile_select_html {
1.144 matthew 13222: my %Types = (
13223: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13224: semisv => &mt('Semicolon separated values'),
1.144 matthew 13225: space => &mt('Space separated'),
13226: tab => &mt('Tabulator separated'),
13227: # xml => &mt('HTML/XML'),
13228: );
13229: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13230: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13231: foreach my $type (sort(keys(%Types))) {
13232: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13233: }
13234: $Str .= "</select>\n";
13235: return $Str;
1.31 albertel 13236: }
13237:
1.301 albertel 13238: sub get_samples {
13239: my ($records,$toget) = @_;
13240: my @samples=({});
13241: my $got=0;
13242: foreach my $rec (@$records) {
13243: my %temp = &record_sep($rec);
13244: if (! grep(/\S/, values(%temp))) { next; }
13245: if (%temp) {
13246: $samples[$got]=\%temp;
13247: $got++;
13248: if ($got == $toget) { last; }
13249: }
13250: }
13251: return \@samples;
13252: }
13253:
1.144 matthew 13254: ######################################################
13255: ######################################################
13256:
1.56 matthew 13257: =pod
13258:
1.648 raeburn 13259: =item * &csv_print_samples($r,$records)
1.41 ng 13260:
13261: Prints a table of sample values from each column uploaded $r is an
13262: Apache Request ref, $records is an arrayref from
13263: &Apache::loncommon::upfile_record_sep
13264:
13265: =cut
13266:
1.144 matthew 13267: ######################################################
13268: ######################################################
1.31 albertel 13269: sub csv_print_samples {
13270: my ($r,$records) = @_;
1.662 bisitz 13271: my $samples = &get_samples($records,5);
1.301 albertel 13272:
1.594 raeburn 13273: $r->print(&mt('Samples').'<br />'.&start_data_table().
13274: &start_data_table_header_row());
1.356 albertel 13275: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13276: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13277: $r->print(&end_data_table_header_row());
1.301 albertel 13278: foreach my $hash (@$samples) {
1.594 raeburn 13279: $r->print(&start_data_table_row());
1.356 albertel 13280: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13281: $r->print('<td>');
1.356 albertel 13282: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13283: $r->print('</td>');
13284: }
1.594 raeburn 13285: $r->print(&end_data_table_row());
1.31 albertel 13286: }
1.594 raeburn 13287: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13288: }
13289:
1.144 matthew 13290: ######################################################
13291: ######################################################
13292:
1.56 matthew 13293: =pod
13294:
1.648 raeburn 13295: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13296:
13297: Prints a table to create associations between values and table columns.
1.144 matthew 13298:
1.41 ng 13299: $r is an Apache Request ref,
13300: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13301: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13302:
13303: =cut
13304:
1.144 matthew 13305: ######################################################
13306: ######################################################
1.31 albertel 13307: sub csv_print_select_table {
13308: my ($r,$records,$d) = @_;
1.301 albertel 13309: my $i=0;
13310: my $samples = &get_samples($records,1);
1.144 matthew 13311: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13312: &start_data_table().&start_data_table_header_row().
1.144 matthew 13313: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13314: '<th>'.&mt('Column').'</th>'.
13315: &end_data_table_header_row()."\n");
1.356 albertel 13316: foreach my $array_ref (@$d) {
13317: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13318: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13319:
1.875 bisitz 13320: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13321: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13322: $r->print('<option value="none"></option>');
1.356 albertel 13323: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13324: $r->print('<option value="'.$sample.'"'.
13325: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13326: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13327: }
1.594 raeburn 13328: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13329: $i++;
13330: }
1.594 raeburn 13331: $r->print(&end_data_table());
1.31 albertel 13332: $i--;
13333: return $i;
13334: }
1.56 matthew 13335:
1.144 matthew 13336: ######################################################
13337: ######################################################
13338:
1.56 matthew 13339: =pod
1.31 albertel 13340:
1.648 raeburn 13341: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13342:
13343: Prints a table of sample values from the upload and can make associate samples to internal names.
13344:
13345: $r is an Apache Request ref,
13346: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13347: $d is an array of 2 element arrays (internal name, displayed name)
13348:
13349: =cut
13350:
1.144 matthew 13351: ######################################################
13352: ######################################################
1.31 albertel 13353: sub csv_samples_select_table {
13354: my ($r,$records,$d) = @_;
13355: my $i=0;
1.144 matthew 13356: #
1.662 bisitz 13357: my $max_samples = 5;
13358: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13359: $r->print(&start_data_table().
13360: &start_data_table_header_row().'<th>'.
13361: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13362: &end_data_table_header_row());
1.301 albertel 13363:
13364: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13365: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13366: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13367: foreach my $option (@$d) {
13368: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13369: $r->print('<option value="'.$value.'"'.
1.253 albertel 13370: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13371: $display.'</option>');
1.31 albertel 13372: }
13373: $r->print('</select></td><td>');
1.662 bisitz 13374: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13375: if (defined($samples->[$line]{$key})) {
13376: $r->print($samples->[$line]{$key}."<br />\n");
13377: }
13378: }
1.594 raeburn 13379: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13380: $i++;
13381: }
1.594 raeburn 13382: $r->print(&end_data_table());
1.31 albertel 13383: $i--;
13384: return($i);
1.115 matthew 13385: }
13386:
1.144 matthew 13387: ######################################################
13388: ######################################################
13389:
1.115 matthew 13390: =pod
13391:
1.648 raeburn 13392: =item * &clean_excel_name($name)
1.115 matthew 13393:
13394: Returns a replacement for $name which does not contain any illegal characters.
13395:
13396: =cut
13397:
1.144 matthew 13398: ######################################################
13399: ######################################################
1.115 matthew 13400: sub clean_excel_name {
13401: my ($name) = @_;
13402: $name =~ s/[:\*\?\/\\]//g;
13403: if (length($name) > 31) {
13404: $name = substr($name,0,31);
13405: }
13406: return $name;
1.25 albertel 13407: }
1.84 albertel 13408:
1.85 albertel 13409: =pod
13410:
1.648 raeburn 13411: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13412:
13413: Returns either 1 or undef
13414:
13415: 1 if the part is to be hidden, undef if it is to be shown
13416:
13417: Arguments are:
13418:
13419: $id the id of the part to be checked
13420: $symb, optional the symb of the resource to check
13421: $udom, optional the domain of the user to check for
13422: $uname, optional the username of the user to check for
13423:
13424: =cut
1.84 albertel 13425:
13426: sub check_if_partid_hidden {
13427: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13428: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13429: $symb,$udom,$uname);
1.141 albertel 13430: my $truth=1;
13431: #if the string starts with !, then the list is the list to show not hide
13432: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13433: my @hiddenlist=split(/,/,$hiddenparts);
13434: foreach my $checkid (@hiddenlist) {
1.141 albertel 13435: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13436: }
1.141 albertel 13437: return !$truth;
1.84 albertel 13438: }
1.127 matthew 13439:
1.138 matthew 13440:
13441: ############################################################
13442: ############################################################
13443:
13444: =pod
13445:
1.157 matthew 13446: =back
13447:
1.138 matthew 13448: =head1 cgi-bin script and graphing routines
13449:
1.157 matthew 13450: =over 4
13451:
1.648 raeburn 13452: =item * &get_cgi_id()
1.138 matthew 13453:
13454: Inputs: none
13455:
13456: Returns an id which can be used to pass environment variables
13457: to various cgi-bin scripts. These environment variables will
13458: be removed from the users environment after a given time by
13459: the routine &Apache::lonnet::transfer_profile_to_env.
13460:
13461: =cut
13462:
13463: ############################################################
13464: ############################################################
1.152 albertel 13465: my $uniq=0;
1.136 matthew 13466: sub get_cgi_id {
1.154 albertel 13467: $uniq=($uniq+1)%100000;
1.280 albertel 13468: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13469: }
13470:
1.127 matthew 13471: ############################################################
13472: ############################################################
13473:
13474: =pod
13475:
1.648 raeburn 13476: =item * &DrawBarGraph()
1.127 matthew 13477:
1.138 matthew 13478: Facilitates the plotting of data in a (stacked) bar graph.
13479: Puts plot definition data into the users environment in order for
13480: graph.png to plot it. Returns an <img> tag for the plot.
13481: The bars on the plot are labeled '1','2',...,'n'.
13482:
13483: Inputs:
13484:
13485: =over 4
13486:
13487: =item $Title: string, the title of the plot
13488:
13489: =item $xlabel: string, text describing the X-axis of the plot
13490:
13491: =item $ylabel: string, text describing the Y-axis of the plot
13492:
13493: =item $Max: scalar, the maximum Y value to use in the plot
13494: If $Max is < any data point, the graph will not be rendered.
13495:
1.140 matthew 13496: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13497: they are plotted. If undefined, default values will be used.
13498:
1.178 matthew 13499: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13500:
1.138 matthew 13501: =item @Values: An array of array references. Each array reference holds data
13502: to be plotted in a stacked bar chart.
13503:
1.239 matthew 13504: =item If the final element of @Values is a hash reference the key/value
13505: pairs will be added to the graph definition.
13506:
1.138 matthew 13507: =back
13508:
13509: Returns:
13510:
13511: An <img> tag which references graph.png and the appropriate identifying
13512: information for the plot.
13513:
1.127 matthew 13514: =cut
13515:
13516: ############################################################
13517: ############################################################
1.134 matthew 13518: sub DrawBarGraph {
1.178 matthew 13519: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13520: #
13521: if (! defined($colors)) {
13522: $colors = ['#33ff00',
13523: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13524: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13525: ];
13526: }
1.228 matthew 13527: my $extra_settings = {};
13528: if (ref($Values[-1]) eq 'HASH') {
13529: $extra_settings = pop(@Values);
13530: }
1.127 matthew 13531: #
1.136 matthew 13532: my $identifier = &get_cgi_id();
13533: my $id = 'cgi.'.$identifier;
1.129 matthew 13534: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13535: return '';
13536: }
1.225 matthew 13537: #
13538: my @Labels;
13539: if (defined($labels)) {
13540: @Labels = @$labels;
13541: } else {
13542: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 13543: push(@Labels,$i+1);
1.225 matthew 13544: }
13545: }
13546: #
1.129 matthew 13547: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13548: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13549: my %ValuesHash;
13550: my $NumSets=1;
13551: foreach my $array (@Values) {
13552: next if (! ref($array));
1.136 matthew 13553: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13554: join(',',@$array);
1.129 matthew 13555: }
1.127 matthew 13556: #
1.136 matthew 13557: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13558: if ($NumBars < 3) {
13559: $width = 120+$NumBars*32;
1.220 matthew 13560: $xskip = 1;
1.225 matthew 13561: $bar_width = 30;
13562: } elsif ($NumBars < 5) {
13563: $width = 120+$NumBars*20;
13564: $xskip = 1;
13565: $bar_width = 20;
1.220 matthew 13566: } elsif ($NumBars < 10) {
1.136 matthew 13567: $width = 120+$NumBars*15;
13568: $xskip = 1;
13569: $bar_width = 15;
13570: } elsif ($NumBars <= 25) {
13571: $width = 120+$NumBars*11;
13572: $xskip = 5;
13573: $bar_width = 8;
13574: } elsif ($NumBars <= 50) {
13575: $width = 120+$NumBars*8;
13576: $xskip = 5;
13577: $bar_width = 4;
13578: } else {
13579: $width = 120+$NumBars*8;
13580: $xskip = 5;
13581: $bar_width = 4;
13582: }
13583: #
1.137 matthew 13584: $Max = 1 if ($Max < 1);
13585: if ( int($Max) < $Max ) {
13586: $Max++;
13587: $Max = int($Max);
13588: }
1.127 matthew 13589: $Title = '' if (! defined($Title));
13590: $xlabel = '' if (! defined($xlabel));
13591: $ylabel = '' if (! defined($ylabel));
1.369 www 13592: $ValuesHash{$id.'.title'} = &escape($Title);
13593: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13594: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13595: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13596: $ValuesHash{$id.'.NumBars'} = $NumBars;
13597: $ValuesHash{$id.'.NumSets'} = $NumSets;
13598: $ValuesHash{$id.'.PlotType'} = 'bar';
13599: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13600: $ValuesHash{$id.'.height'} = $height;
13601: $ValuesHash{$id.'.width'} = $width;
13602: $ValuesHash{$id.'.xskip'} = $xskip;
13603: $ValuesHash{$id.'.bar_width'} = $bar_width;
13604: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13605: #
1.228 matthew 13606: # Deal with other parameters
13607: while (my ($key,$value) = each(%$extra_settings)) {
13608: $ValuesHash{$id.'.'.$key} = $value;
13609: }
13610: #
1.646 raeburn 13611: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13612: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13613: }
13614:
13615: ############################################################
13616: ############################################################
13617:
13618: =pod
13619:
1.648 raeburn 13620: =item * &DrawXYGraph()
1.137 matthew 13621:
1.138 matthew 13622: Facilitates the plotting of data in an XY graph.
13623: Puts plot definition data into the users environment in order for
13624: graph.png to plot it. Returns an <img> tag for the plot.
13625:
13626: Inputs:
13627:
13628: =over 4
13629:
13630: =item $Title: string, the title of the plot
13631:
13632: =item $xlabel: string, text describing the X-axis of the plot
13633:
13634: =item $ylabel: string, text describing the Y-axis of the plot
13635:
13636: =item $Max: scalar, the maximum Y value to use in the plot
13637: If $Max is < any data point, the graph will not be rendered.
13638:
13639: =item $colors: Array ref containing the hex color codes for the data to be
13640: plotted in. If undefined, default values will be used.
13641:
13642: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13643:
13644: =item $Ydata: Array ref containing Array refs.
1.185 www 13645: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13646:
13647: =item %Values: hash indicating or overriding any default values which are
13648: passed to graph.png.
13649: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13650:
13651: =back
13652:
13653: Returns:
13654:
13655: An <img> tag which references graph.png and the appropriate identifying
13656: information for the plot.
13657:
1.137 matthew 13658: =cut
13659:
13660: ############################################################
13661: ############################################################
13662: sub DrawXYGraph {
13663: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13664: #
13665: # Create the identifier for the graph
13666: my $identifier = &get_cgi_id();
13667: my $id = 'cgi.'.$identifier;
13668: #
13669: $Title = '' if (! defined($Title));
13670: $xlabel = '' if (! defined($xlabel));
13671: $ylabel = '' if (! defined($ylabel));
13672: my %ValuesHash =
13673: (
1.369 www 13674: $id.'.title' => &escape($Title),
13675: $id.'.xlabel' => &escape($xlabel),
13676: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13677: $id.'.y_max_value'=> $Max,
13678: $id.'.labels' => join(',',@$Xlabels),
13679: $id.'.PlotType' => 'XY',
13680: );
13681: #
13682: if (defined($colors) && ref($colors) eq 'ARRAY') {
13683: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13684: }
13685: #
13686: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13687: return '';
13688: }
13689: my $NumSets=1;
1.138 matthew 13690: foreach my $array (@{$Ydata}){
1.137 matthew 13691: next if (! ref($array));
13692: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13693: }
1.138 matthew 13694: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13695: #
13696: # Deal with other parameters
13697: while (my ($key,$value) = each(%Values)) {
13698: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13699: }
13700: #
1.646 raeburn 13701: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13702: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13703: }
13704:
13705: ############################################################
13706: ############################################################
13707:
13708: =pod
13709:
1.648 raeburn 13710: =item * &DrawXYYGraph()
1.138 matthew 13711:
13712: Facilitates the plotting of data in an XY graph with two Y axes.
13713: Puts plot definition data into the users environment in order for
13714: graph.png to plot it. Returns an <img> tag for the plot.
13715:
13716: Inputs:
13717:
13718: =over 4
13719:
13720: =item $Title: string, the title of the plot
13721:
13722: =item $xlabel: string, text describing the X-axis of the plot
13723:
13724: =item $ylabel: string, text describing the Y-axis of the plot
13725:
13726: =item $colors: Array ref containing the hex color codes for the data to be
13727: plotted in. If undefined, default values will be used.
13728:
13729: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13730:
13731: =item $Ydata1: The first data set
13732:
13733: =item $Min1: The minimum value of the left Y-axis
13734:
13735: =item $Max1: The maximum value of the left Y-axis
13736:
13737: =item $Ydata2: The second data set
13738:
13739: =item $Min2: The minimum value of the right Y-axis
13740:
13741: =item $Max2: The maximum value of the left Y-axis
13742:
13743: =item %Values: hash indicating or overriding any default values which are
13744: passed to graph.png.
13745: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13746:
13747: =back
13748:
13749: Returns:
13750:
13751: An <img> tag which references graph.png and the appropriate identifying
13752: information for the plot.
1.136 matthew 13753:
13754: =cut
13755:
13756: ############################################################
13757: ############################################################
1.137 matthew 13758: sub DrawXYYGraph {
13759: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13760: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13761: #
13762: # Create the identifier for the graph
13763: my $identifier = &get_cgi_id();
13764: my $id = 'cgi.'.$identifier;
13765: #
13766: $Title = '' if (! defined($Title));
13767: $xlabel = '' if (! defined($xlabel));
13768: $ylabel = '' if (! defined($ylabel));
13769: my %ValuesHash =
13770: (
1.369 www 13771: $id.'.title' => &escape($Title),
13772: $id.'.xlabel' => &escape($xlabel),
13773: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13774: $id.'.labels' => join(',',@$Xlabels),
13775: $id.'.PlotType' => 'XY',
13776: $id.'.NumSets' => 2,
1.137 matthew 13777: $id.'.two_axes' => 1,
13778: $id.'.y1_max_value' => $Max1,
13779: $id.'.y1_min_value' => $Min1,
13780: $id.'.y2_max_value' => $Max2,
13781: $id.'.y2_min_value' => $Min2,
1.136 matthew 13782: );
13783: #
1.137 matthew 13784: if (defined($colors) && ref($colors) eq 'ARRAY') {
13785: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13786: }
13787: #
13788: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13789: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13790: return '';
13791: }
13792: my $NumSets=1;
1.137 matthew 13793: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13794: next if (! ref($array));
13795: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13796: }
13797: #
13798: # Deal with other parameters
13799: while (my ($key,$value) = each(%Values)) {
13800: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13801: }
13802: #
1.646 raeburn 13803: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13804: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13805: }
13806:
13807: ############################################################
13808: ############################################################
13809:
13810: =pod
13811:
1.157 matthew 13812: =back
13813:
1.139 matthew 13814: =head1 Statistics helper routines?
13815:
13816: Bad place for them but what the hell.
13817:
1.157 matthew 13818: =over 4
13819:
1.648 raeburn 13820: =item * &chartlink()
1.139 matthew 13821:
13822: Returns a link to the chart for a specific student.
13823:
13824: Inputs:
13825:
13826: =over 4
13827:
13828: =item $linktext: The text of the link
13829:
13830: =item $sname: The students username
13831:
13832: =item $sdomain: The students domain
13833:
13834: =back
13835:
1.157 matthew 13836: =back
13837:
1.139 matthew 13838: =cut
13839:
13840: ############################################################
13841: ############################################################
13842: sub chartlink {
13843: my ($linktext, $sname, $sdomain) = @_;
13844: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13845: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13846: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13847: '">'.$linktext.'</a>';
1.153 matthew 13848: }
13849:
13850: #######################################################
13851: #######################################################
13852:
13853: =pod
13854:
13855: =head1 Course Environment Routines
1.157 matthew 13856:
13857: =over 4
1.153 matthew 13858:
1.648 raeburn 13859: =item * &restore_course_settings()
1.153 matthew 13860:
1.648 raeburn 13861: =item * &store_course_settings()
1.153 matthew 13862:
13863: Restores/Store indicated form parameters from the course environment.
13864: Will not overwrite existing values of the form parameters.
13865:
13866: Inputs:
13867: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13868:
13869: a hash ref describing the data to be stored. For example:
13870:
13871: %Save_Parameters = ('Status' => 'scalar',
13872: 'chartoutputmode' => 'scalar',
13873: 'chartoutputdata' => 'scalar',
13874: 'Section' => 'array',
1.373 raeburn 13875: 'Group' => 'array',
1.153 matthew 13876: 'StudentData' => 'array',
13877: 'Maps' => 'array');
13878:
13879: Returns: both routines return nothing
13880:
1.631 raeburn 13881: =back
13882:
1.153 matthew 13883: =cut
13884:
13885: #######################################################
13886: #######################################################
13887: sub store_course_settings {
1.496 albertel 13888: return &store_settings($env{'request.course.id'},@_);
13889: }
13890:
13891: sub store_settings {
1.153 matthew 13892: # save to the environment
13893: # appenv the same items, just to be safe
1.300 albertel 13894: my $udom = $env{'user.domain'};
13895: my $uname = $env{'user.name'};
1.496 albertel 13896: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13897: my %SaveHash;
13898: my %AppHash;
13899: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13900: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13901: my $envname = 'environment.'.$basename;
1.258 albertel 13902: if (exists($env{'form.'.$setting})) {
1.153 matthew 13903: # Save this value away
13904: if ($type eq 'scalar' &&
1.258 albertel 13905: (! exists($env{$envname}) ||
13906: $env{$envname} ne $env{'form.'.$setting})) {
13907: $SaveHash{$basename} = $env{'form.'.$setting};
13908: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13909: } elsif ($type eq 'array') {
13910: my $stored_form;
1.258 albertel 13911: if (ref($env{'form.'.$setting})) {
1.153 matthew 13912: $stored_form = join(',',
13913: map {
1.369 www 13914: &escape($_);
1.258 albertel 13915: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13916: } else {
13917: $stored_form =
1.369 www 13918: &escape($env{'form.'.$setting});
1.153 matthew 13919: }
13920: # Determine if the array contents are the same.
1.258 albertel 13921: if ($stored_form ne $env{$envname}) {
1.153 matthew 13922: $SaveHash{$basename} = $stored_form;
13923: $AppHash{$envname} = $stored_form;
13924: }
13925: }
13926: }
13927: }
13928: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13929: $udom,$uname);
1.153 matthew 13930: if ($put_result !~ /^(ok|delayed)/) {
13931: &Apache::lonnet::logthis('unable to save form parameters, '.
13932: 'got error:'.$put_result);
13933: }
13934: # Make sure these settings stick around in this session, too
1.646 raeburn 13935: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13936: return;
13937: }
13938:
13939: sub restore_course_settings {
1.499 albertel 13940: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13941: }
13942:
13943: sub restore_settings {
13944: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13945: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13946: next if (exists($env{'form.'.$setting}));
1.496 albertel 13947: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13948: '.'.$setting;
1.258 albertel 13949: if (exists($env{$envname})) {
1.153 matthew 13950: if ($type eq 'scalar') {
1.258 albertel 13951: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13952: } elsif ($type eq 'array') {
1.258 albertel 13953: $env{'form.'.$setting} = [
1.153 matthew 13954: map {
1.369 www 13955: &unescape($_);
1.258 albertel 13956: } split(',',$env{$envname})
1.153 matthew 13957: ];
13958: }
13959: }
13960: }
1.127 matthew 13961: }
13962:
1.618 raeburn 13963: #######################################################
13964: #######################################################
13965:
13966: =pod
13967:
13968: =head1 Domain E-mail Routines
13969:
13970: =over 4
13971:
1.648 raeburn 13972: =item * &build_recipient_list()
1.618 raeburn 13973:
1.1075.2.44 raeburn 13974: Build recipient lists for following types of e-mail:
1.766 raeburn 13975: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 13976: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13977: module change checking, student/employee ID conflict checks, as
13978: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13979: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13980:
13981: Inputs:
1.1075.2.44 raeburn 13982: defmail (scalar - email address of default recipient),
13983: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13984: requestsmail, updatesmail, or idconflictsmail).
13985:
1.619 raeburn 13986: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 13987:
13988: origmail (scalar - email address of recipient from loncapa.conf,
13989: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13990:
1.655 raeburn 13991: Returns: comma separated list of addresses to which to send e-mail.
13992:
13993: =back
1.618 raeburn 13994:
13995: =cut
13996:
13997: ############################################################
13998: ############################################################
13999: sub build_recipient_list {
1.619 raeburn 14000: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 14001: my @recipients;
1.1075.2.122 raeburn 14002: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14003: my %domconfig =
1.1075.2.122 raeburn 14004: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14005: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14006: if (exists($domconfig{'contacts'}{$mailing})) {
14007: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14008: my @contacts = ('adminemail','supportemail');
14009: foreach my $item (@contacts) {
14010: if ($domconfig{'contacts'}{$mailing}{$item}) {
14011: my $addr = $domconfig{'contacts'}{$item};
14012: if (!grep(/^\Q$addr\E$/,@recipients)) {
14013: push(@recipients,$addr);
14014: }
1.619 raeburn 14015: }
1.1075.2.122 raeburn 14016: }
14017: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14018: if ($mailing eq 'helpdeskmail') {
14019: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14020: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14021: my @ok_bccs;
14022: foreach my $bcc (@bccs) {
14023: $bcc =~ s/^\s+//g;
14024: $bcc =~ s/\s+$//g;
14025: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14026: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14027: push(@ok_bccs,$bcc);
14028: }
14029: }
14030: }
14031: if (@ok_bccs > 0) {
14032: $allbcc = join(', ',@ok_bccs);
14033: }
14034: }
14035: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14036: }
14037: }
1.766 raeburn 14038: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14039: $lastresort = $origmail;
1.618 raeburn 14040: }
1.619 raeburn 14041: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14042: $lastresort = $origmail;
14043: }
14044:
14045: if (($mailing eq 'helpdesk') && ($lastresort ne '')) {
14046: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14047: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14048: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14049: my %what = (
14050: perlvar => 1,
14051: );
14052: my $primary = &Apache::lonnet::domain($defdom,'primary');
14053: if ($primary) {
14054: my $gotaddr;
14055: my ($result,$returnhash) =
14056: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14057: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14058: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14059: $lastresort = $returnhash->{'lonSupportEMail'};
14060: $gotaddr = 1;
14061: }
14062: }
14063: unless ($gotaddr) {
14064: my $uintdom = &Apache::lonnet::internet_dom($primary);
14065: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14066: unless ($uintdom eq $intdom) {
14067: my %domconfig =
14068: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14069: if (ref($domconfig{'contacts'}) eq 'HASH') {
14070: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14071: my @contacts = ('adminemail','supportemail');
14072: foreach my $item (@contacts) {
14073: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14074: my $addr = $domconfig{'contacts'}{$item};
14075: if (!grep(/^\Q$addr\E$/,@recipients)) {
14076: push(@recipients,$addr);
14077: }
14078: }
14079: }
14080: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14081: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14082: }
14083: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14084: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14085: my @ok_bccs;
14086: foreach my $bcc (@bccs) {
14087: $bcc =~ s/^\s+//g;
14088: $bcc =~ s/\s+$//g;
14089: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14090: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14091: push(@ok_bccs,$bcc);
14092: }
14093: }
14094: }
14095: if (@ok_bccs > 0) {
14096: $allbcc = join(', ',@ok_bccs);
14097: }
14098: }
14099: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14100: }
14101: }
14102: }
14103: }
14104: }
14105: }
1.618 raeburn 14106: }
1.688 raeburn 14107: if (defined($defmail)) {
14108: if ($defmail ne '') {
14109: push(@recipients,$defmail);
14110: }
1.618 raeburn 14111: }
14112: if ($otheremails) {
1.619 raeburn 14113: my @others;
14114: if ($otheremails =~ /,/) {
14115: @others = split(/,/,$otheremails);
1.618 raeburn 14116: } else {
1.619 raeburn 14117: push(@others,$otheremails);
14118: }
14119: foreach my $addr (@others) {
14120: if (!grep(/^\Q$addr\E$/,@recipients)) {
14121: push(@recipients,$addr);
14122: }
1.618 raeburn 14123: }
14124: }
1.1075.2.122 raeburn 14125: if ($mailing eq 'helpdesk') {
14126: if ((!@recipients) && ($lastresort ne '')) {
14127: push(@recipients,$lastresort);
14128: }
14129: } elsif ($lastresort ne '') {
14130: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14131: push(@recipients,$lastresort);
14132: }
14133: }
14134: my $recipientlist = join(',',@recipients);
14135: if (wantarray) {
14136: return ($recipientlist,$allbcc,$addtext);
14137: } else {
14138: return $recipientlist;
14139: }
1.618 raeburn 14140: }
14141:
1.127 matthew 14142: ############################################################
14143: ############################################################
1.154 albertel 14144:
1.655 raeburn 14145: =pod
14146:
14147: =head1 Course Catalog Routines
14148:
14149: =over 4
14150:
14151: =item * &gather_categories()
14152:
14153: Converts category definitions - keys of categories hash stored in
14154: coursecategories in configuration.db on the primary library server in a
14155: domain - to an array. Also generates javascript and idx hash used to
14156: generate Domain Coordinator interface for editing Course Categories.
14157:
14158: Inputs:
1.663 raeburn 14159:
1.655 raeburn 14160: categories (reference to hash of category definitions).
1.663 raeburn 14161:
1.655 raeburn 14162: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14163: categories and subcategories).
1.663 raeburn 14164:
1.655 raeburn 14165: idx (reference to hash of counters used in Domain Coordinator interface for
14166: editing Course Categories).
1.663 raeburn 14167:
1.655 raeburn 14168: jsarray (reference to array of categories used to create Javascript arrays for
14169: Domain Coordinator interface for editing Course Categories).
14170:
14171: Returns: nothing
14172:
14173: Side effects: populates cats, idx and jsarray.
14174:
14175: =cut
14176:
14177: sub gather_categories {
14178: my ($categories,$cats,$idx,$jsarray) = @_;
14179: my %counters;
14180: my $num = 0;
14181: foreach my $item (keys(%{$categories})) {
14182: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14183: if ($container eq '' && $depth == 0) {
14184: $cats->[$depth][$categories->{$item}] = $cat;
14185: } else {
14186: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14187: }
14188: my ($escitem,$tail) = split(/:/,$item,2);
14189: if ($counters{$tail} eq '') {
14190: $counters{$tail} = $num;
14191: $num ++;
14192: }
14193: if (ref($idx) eq 'HASH') {
14194: $idx->{$item} = $counters{$tail};
14195: }
14196: if (ref($jsarray) eq 'ARRAY') {
14197: push(@{$jsarray->[$counters{$tail}]},$item);
14198: }
14199: }
14200: return;
14201: }
14202:
14203: =pod
14204:
14205: =item * &extract_categories()
14206:
14207: Used to generate breadcrumb trails for course categories.
14208:
14209: Inputs:
1.663 raeburn 14210:
1.655 raeburn 14211: categories (reference to hash of category definitions).
1.663 raeburn 14212:
1.655 raeburn 14213: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14214: categories and subcategories).
1.663 raeburn 14215:
1.655 raeburn 14216: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14217:
1.655 raeburn 14218: allitems (reference to hash - key is category key
14219: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14220:
1.655 raeburn 14221: idx (reference to hash of counters used in Domain Coordinator interface for
14222: editing Course Categories).
1.663 raeburn 14223:
1.655 raeburn 14224: jsarray (reference to array of categories used to create Javascript arrays for
14225: Domain Coordinator interface for editing Course Categories).
14226:
1.665 raeburn 14227: subcats (reference to hash of arrays containing all subcategories within each
14228: category, -recursive)
14229:
1.655 raeburn 14230: Returns: nothing
14231:
14232: Side effects: populates trails and allitems hash references.
14233:
14234: =cut
14235:
14236: sub extract_categories {
1.665 raeburn 14237: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 14238: if (ref($categories) eq 'HASH') {
14239: &gather_categories($categories,$cats,$idx,$jsarray);
14240: if (ref($cats->[0]) eq 'ARRAY') {
14241: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14242: my $name = $cats->[0][$i];
14243: my $item = &escape($name).'::0';
14244: my $trailstr;
14245: if ($name eq 'instcode') {
14246: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14247: } elsif ($name eq 'communities') {
14248: $trailstr = &mt('Communities');
1.655 raeburn 14249: } else {
14250: $trailstr = $name;
14251: }
14252: if ($allitems->{$item} eq '') {
14253: push(@{$trails},$trailstr);
14254: $allitems->{$item} = scalar(@{$trails})-1;
14255: }
14256: my @parents = ($name);
14257: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14258: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14259: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14260: if (ref($subcats) eq 'HASH') {
14261: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14262: }
14263: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
14264: }
14265: } else {
14266: if (ref($subcats) eq 'HASH') {
14267: $subcats->{$item} = [];
1.655 raeburn 14268: }
14269: }
14270: }
14271: }
14272: }
14273: return;
14274: }
14275:
14276: =pod
14277:
1.1075.2.56 raeburn 14278: =item * &recurse_categories()
1.655 raeburn 14279:
14280: Recursively used to generate breadcrumb trails for course categories.
14281:
14282: Inputs:
1.663 raeburn 14283:
1.655 raeburn 14284: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14285: categories and subcategories).
1.663 raeburn 14286:
1.655 raeburn 14287: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14288:
14289: category (current course category, for which breadcrumb trail is being generated).
14290:
14291: trails (reference to array of breadcrumb trails for each category).
14292:
1.655 raeburn 14293: allitems (reference to hash - key is category key
14294: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14295:
1.655 raeburn 14296: parents (array containing containers directories for current category,
14297: back to top level).
14298:
14299: Returns: nothing
14300:
14301: Side effects: populates trails and allitems hash references
14302:
14303: =cut
14304:
14305: sub recurse_categories {
1.665 raeburn 14306: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 14307: my $shallower = $depth - 1;
14308: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14309: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14310: my $name = $cats->[$depth]{$category}[$k];
14311: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14312: my $trailstr = join(' -> ',(@{$parents},$category));
14313: if ($allitems->{$item} eq '') {
14314: push(@{$trails},$trailstr);
14315: $allitems->{$item} = scalar(@{$trails})-1;
14316: }
14317: my $deeper = $depth+1;
14318: push(@{$parents},$category);
1.665 raeburn 14319: if (ref($subcats) eq 'HASH') {
14320: my $subcat = &escape($name).':'.$category.':'.$depth;
14321: for (my $j=@{$parents}; $j>=0; $j--) {
14322: my $higher;
14323: if ($j > 0) {
14324: $higher = &escape($parents->[$j]).':'.
14325: &escape($parents->[$j-1]).':'.$j;
14326: } else {
14327: $higher = &escape($parents->[$j]).'::'.$j;
14328: }
14329: push(@{$subcats->{$higher}},$subcat);
14330: }
14331: }
14332: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
14333: $subcats);
1.655 raeburn 14334: pop(@{$parents});
14335: }
14336: } else {
14337: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14338: my $trailstr = join(' -> ',(@{$parents},$category));
14339: if ($allitems->{$item} eq '') {
14340: push(@{$trails},$trailstr);
14341: $allitems->{$item} = scalar(@{$trails})-1;
14342: }
14343: }
14344: return;
14345: }
14346:
1.663 raeburn 14347: =pod
14348:
1.1075.2.56 raeburn 14349: =item * &assign_categories_table()
1.663 raeburn 14350:
14351: Create a datatable for display of hierarchical categories in a domain,
14352: with checkboxes to allow a course to be categorized.
14353:
14354: Inputs:
14355:
14356: cathash - reference to hash of categories defined for the domain (from
14357: configuration.db)
14358:
14359: currcat - scalar with an & separated list of categories assigned to a course.
14360:
1.919 raeburn 14361: type - scalar contains course type (Course or Community).
14362:
1.1075.2.117 raeburn 14363: disabled - scalar (optional) contains disabled="disabled" if input elements are
14364: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14365:
1.663 raeburn 14366: Returns: $output (markup to be displayed)
14367:
14368: =cut
14369:
14370: sub assign_categories_table {
1.1075.2.117 raeburn 14371: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 14372: my $output;
14373: if (ref($cathash) eq 'HASH') {
14374: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
14375: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
14376: $maxdepth = scalar(@cats);
14377: if (@cats > 0) {
14378: my $itemcount = 0;
14379: if (ref($cats[0]) eq 'ARRAY') {
14380: my @currcategories;
14381: if ($currcat ne '') {
14382: @currcategories = split('&',$currcat);
14383: }
1.919 raeburn 14384: my $table;
1.663 raeburn 14385: for (my $i=0; $i<@{$cats[0]}; $i++) {
14386: my $parent = $cats[0][$i];
1.919 raeburn 14387: next if ($parent eq 'instcode');
14388: if ($type eq 'Community') {
14389: next unless ($parent eq 'communities');
14390: } else {
14391: next if ($parent eq 'communities');
14392: }
1.663 raeburn 14393: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14394: my $item = &escape($parent).'::0';
14395: my $checked = '';
14396: if (@currcategories > 0) {
14397: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14398: $checked = ' checked="checked"';
1.663 raeburn 14399: }
14400: }
1.919 raeburn 14401: my $parent_title = $parent;
14402: if ($parent eq 'communities') {
14403: $parent_title = &mt('Communities');
14404: }
14405: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14406: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14407: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 14408: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14409: my $depth = 1;
14410: push(@path,$parent);
1.1075.2.117 raeburn 14411: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 14412: pop(@path);
1.919 raeburn 14413: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14414: $itemcount ++;
14415: }
1.919 raeburn 14416: if ($itemcount) {
14417: $output = &Apache::loncommon::start_data_table().
14418: $table.
14419: &Apache::loncommon::end_data_table();
14420: }
1.663 raeburn 14421: }
14422: }
14423: }
14424: return $output;
14425: }
14426:
14427: =pod
14428:
1.1075.2.56 raeburn 14429: =item * &assign_category_rows()
1.663 raeburn 14430:
14431: Create a datatable row for display of nested categories in a domain,
14432: with checkboxes to allow a course to be categorized,called recursively.
14433:
14434: Inputs:
14435:
14436: itemcount - track row number for alternating colors
14437:
14438: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14439: categories and subcategories.
14440:
14441: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14442:
14443: parent - parent of current category item
14444:
14445: path - Array containing all categories back up through the hierarchy from the
14446: current category to the top level.
14447:
14448: currcategories - reference to array of current categories assigned to the course
14449:
1.1075.2.117 raeburn 14450: disabled - scalar (optional) contains disabled="disabled" if input elements are
14451: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14452:
1.663 raeburn 14453: Returns: $output (markup to be displayed).
14454:
14455: =cut
14456:
14457: sub assign_category_rows {
1.1075.2.117 raeburn 14458: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 14459: my ($text,$name,$item,$chgstr);
14460: if (ref($cats) eq 'ARRAY') {
14461: my $maxdepth = scalar(@{$cats});
14462: if (ref($cats->[$depth]) eq 'HASH') {
14463: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14464: my $numchildren = @{$cats->[$depth]{$parent}};
14465: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 14466: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14467: for (my $j=0; $j<$numchildren; $j++) {
14468: $name = $cats->[$depth]{$parent}[$j];
14469: $item = &escape($name).':'.&escape($parent).':'.$depth;
14470: my $deeper = $depth+1;
14471: my $checked = '';
14472: if (ref($currcategories) eq 'ARRAY') {
14473: if (@{$currcategories} > 0) {
14474: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14475: $checked = ' checked="checked"';
1.663 raeburn 14476: }
14477: }
14478: }
1.664 raeburn 14479: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14480: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14481: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 14482: '<input type="hidden" name="catname" value="'.$name.'" />'.
14483: '</td><td>';
1.663 raeburn 14484: if (ref($path) eq 'ARRAY') {
14485: push(@{$path},$name);
1.1075.2.117 raeburn 14486: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 14487: pop(@{$path});
14488: }
14489: $text .= '</td></tr>';
14490: }
14491: $text .= '</table></td>';
14492: }
14493: }
14494: }
14495: return $text;
14496: }
14497:
1.1075.2.69 raeburn 14498: =pod
14499:
14500: =back
14501:
14502: =cut
14503:
1.655 raeburn 14504: ############################################################
14505: ############################################################
14506:
14507:
1.443 albertel 14508: sub commit_customrole {
1.664 raeburn 14509: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14510: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14511: ($start?', '.&mt('starting').' '.localtime($start):'').
14512: ($end?', ending '.localtime($end):'').': <b>'.
14513: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14514: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14515: '</b><br />';
14516: return $output;
14517: }
14518:
14519: sub commit_standardrole {
1.1075.2.31 raeburn 14520: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14521: my ($output,$logmsg,$linefeed);
14522: if ($context eq 'auto') {
14523: $linefeed = "\n";
14524: } else {
14525: $linefeed = "<br />\n";
14526: }
1.443 albertel 14527: if ($three eq 'st') {
1.541 raeburn 14528: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 14529: $one,$two,$sec,$context,$credits);
1.541 raeburn 14530: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14531: ($result eq 'unknown_course') || ($result eq 'refused')) {
14532: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14533: } else {
1.541 raeburn 14534: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14535: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14536: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14537: if ($context eq 'auto') {
14538: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14539: } else {
14540: $output .= '<b>'.$result.'</b>'.$linefeed.
14541: &mt('Add to classlist').': <b>ok</b>';
14542: }
14543: $output .= $linefeed;
1.443 albertel 14544: }
14545: } else {
14546: $output = &mt('Assigning').' '.$three.' in '.$url.
14547: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14548: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 14549: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 14550: if ($context eq 'auto') {
14551: $output .= $result.$linefeed;
14552: } else {
14553: $output .= '<b>'.$result.'</b>'.$linefeed;
14554: }
1.443 albertel 14555: }
14556: return $output;
14557: }
14558:
14559: sub commit_studentrole {
1.1075.2.31 raeburn 14560: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
14561: $credits) = @_;
1.626 raeburn 14562: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 14563: if ($context eq 'auto') {
14564: $linefeed = "\n";
14565: } else {
14566: $linefeed = '<br />'."\n";
14567: }
1.443 albertel 14568: if (defined($one) && defined($two)) {
14569: my $cid=$one.'_'.$two;
14570: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
14571: my $secchange = 0;
14572: my $expire_role_result;
14573: my $modify_section_result;
1.628 raeburn 14574: if ($oldsec ne '-1') {
14575: if ($oldsec ne $sec) {
1.443 albertel 14576: $secchange = 1;
1.628 raeburn 14577: my $now = time;
1.443 albertel 14578: my $uurl='/'.$cid;
14579: $uurl=~s/\_/\//g;
14580: if ($oldsec) {
14581: $uurl.='/'.$oldsec;
14582: }
1.626 raeburn 14583: $oldsecurl = $uurl;
1.628 raeburn 14584: $expire_role_result =
1.652 raeburn 14585: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 14586: if ($env{'request.course.sec'} ne '') {
14587: if ($expire_role_result eq 'refused') {
14588: my @roles = ('st');
14589: my @statuses = ('previous');
14590: my @roledoms = ($one);
14591: my $withsec = 1;
14592: my %roleshash =
14593: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
14594: \@statuses,\@roles,\@roledoms,$withsec);
14595: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
14596: my ($oldstart,$oldend) =
14597: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
14598: if ($oldend > 0 && $oldend <= $now) {
14599: $expire_role_result = 'ok';
14600: }
14601: }
14602: }
14603: }
1.443 albertel 14604: $result = $expire_role_result;
14605: }
14606: }
14607: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 14608: $modify_section_result =
14609: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
14610: undef,undef,undef,$sec,
14611: $end,$start,'','',$cid,
14612: '',$context,$credits);
1.443 albertel 14613: if ($modify_section_result =~ /^ok/) {
14614: if ($secchange == 1) {
1.628 raeburn 14615: if ($sec eq '') {
14616: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
14617: } else {
14618: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
14619: }
1.443 albertel 14620: } elsif ($oldsec eq '-1') {
1.628 raeburn 14621: if ($sec eq '') {
14622: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
14623: } else {
14624: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14625: }
1.443 albertel 14626: } else {
1.628 raeburn 14627: if ($sec eq '') {
14628: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
14629: } else {
14630: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14631: }
1.443 albertel 14632: }
14633: } else {
1.628 raeburn 14634: if ($secchange) {
14635: $$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;
14636: } else {
14637: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
14638: }
1.443 albertel 14639: }
14640: $result = $modify_section_result;
14641: } elsif ($secchange == 1) {
1.628 raeburn 14642: if ($oldsec eq '') {
1.1075.2.20 raeburn 14643: $$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 14644: } else {
14645: $$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;
14646: }
1.626 raeburn 14647: if ($expire_role_result eq 'refused') {
14648: my $newsecurl = '/'.$cid;
14649: $newsecurl =~ s/\_/\//g;
14650: if ($sec ne '') {
14651: $newsecurl.='/'.$sec;
14652: }
14653: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
14654: if ($sec eq '') {
14655: $$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;
14656: } else {
14657: $$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;
14658: }
14659: }
14660: }
1.443 albertel 14661: }
14662: } else {
1.626 raeburn 14663: $$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 14664: $result = "error: incomplete course id\n";
14665: }
14666: return $result;
14667: }
14668:
1.1075.2.25 raeburn 14669: sub show_role_extent {
14670: my ($scope,$context,$role) = @_;
14671: $scope =~ s{^/}{};
14672: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
14673: push(@courseroles,'co');
14674: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
14675: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
14676: $scope =~ s{/}{_};
14677: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
14678: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
14679: my ($audom,$auname) = split(/\//,$scope);
14680: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
14681: &Apache::loncommon::plainname($auname,$audom).'</span>');
14682: } else {
14683: $scope =~ s{/$}{};
14684: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
14685: &Apache::lonnet::domain($scope,'description').'</span>');
14686: }
14687: }
14688:
1.443 albertel 14689: ############################################################
14690: ############################################################
14691:
1.566 albertel 14692: sub check_clone {
1.578 raeburn 14693: my ($args,$linefeed) = @_;
1.566 albertel 14694: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
14695: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
14696: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
14697: my $clonemsg;
14698: my $can_clone = 0;
1.944 raeburn 14699: my $lctype = lc($args->{'crstype'});
1.908 raeburn 14700: if ($lctype ne 'community') {
14701: $lctype = 'course';
14702: }
1.566 albertel 14703: if ($clonehome eq 'no_host') {
1.944 raeburn 14704: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14705: $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'});
14706: } else {
14707: $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'});
14708: }
1.566 albertel 14709: } else {
14710: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 14711: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14712: if ($clonedesc{'type'} ne 'Community') {
14713: $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'});
14714: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14715: }
14716: }
1.1075.2.119 raeburn 14717: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 14718: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 14719: $can_clone = 1;
14720: } else {
1.1075.2.95 raeburn 14721: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 14722: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 14723: if ($clonehash{'cloners'} eq '') {
14724: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
14725: if ($domdefs{'canclone'}) {
14726: unless ($domdefs{'canclone'} eq 'none') {
14727: if ($domdefs{'canclone'} eq 'domain') {
14728: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
14729: $can_clone = 1;
14730: }
14731: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14732: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
14733: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
14734: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
14735: $can_clone = 1;
14736: }
14737: }
14738: }
1.908 raeburn 14739: }
1.1075.2.95 raeburn 14740: } else {
14741: my @cloners = split(/,/,$clonehash{'cloners'});
14742: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 14743: $can_clone = 1;
1.1075.2.95 raeburn 14744: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 14745: $can_clone = 1;
1.1075.2.96 raeburn 14746: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
14747: $can_clone = 1;
1.1075.2.95 raeburn 14748: }
14749: unless ($can_clone) {
1.1075.2.96 raeburn 14750: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14751: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 14752: my (%gotdomdefaults,%gotcodedefaults);
14753: foreach my $cloner (@cloners) {
14754: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
14755: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
14756: my (%codedefaults,@code_order);
14757: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
14758: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
14759: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
14760: }
14761: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
14762: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
14763: }
14764: } else {
14765: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
14766: \%codedefaults,
14767: \@code_order);
14768: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
14769: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
14770: }
14771: if (@code_order > 0) {
14772: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
14773: $cloner,$clonehash{'internal.coursecode'},
14774: $args->{'crscode'})) {
14775: $can_clone = 1;
14776: last;
14777: }
14778: }
14779: }
14780: }
14781: }
1.1075.2.96 raeburn 14782: }
14783: }
14784: unless ($can_clone) {
14785: my $ccrole = 'cc';
14786: if ($args->{'crstype'} eq 'Community') {
14787: $ccrole = 'co';
14788: }
14789: my %roleshash =
14790: &Apache::lonnet::get_my_roles($args->{'ccuname'},
14791: $args->{'ccdomain'},
14792: 'userroles',['active'],[$ccrole],
14793: [$args->{'clonedomain'}]);
14794: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
14795: $can_clone = 1;
14796: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
14797: $args->{'ccuname'},$args->{'ccdomain'})) {
14798: $can_clone = 1;
1.1075.2.95 raeburn 14799: }
14800: }
14801: unless ($can_clone) {
14802: if ($args->{'crstype'} eq 'Community') {
14803: $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'});
14804: } else {
14805: $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 14806: }
1.566 albertel 14807: }
1.578 raeburn 14808: }
1.566 albertel 14809: }
14810: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14811: }
14812:
1.444 albertel 14813: sub construct_course {
1.1075.2.119 raeburn 14814: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
14815: $cnum,$category,$coderef) = @_;
1.444 albertel 14816: my $outcome;
1.541 raeburn 14817: my $linefeed = '<br />'."\n";
14818: if ($context eq 'auto') {
14819: $linefeed = "\n";
14820: }
1.566 albertel 14821:
14822: #
14823: # Are we cloning?
14824: #
14825: my ($can_clone, $clonemsg, $cloneid, $clonehome);
14826: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 14827: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 14828: if ($context ne 'auto') {
1.578 raeburn 14829: if ($clonemsg ne '') {
14830: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
14831: }
1.566 albertel 14832: }
14833: $outcome .= $clonemsg.$linefeed;
14834:
14835: if (!$can_clone) {
14836: return (0,$outcome);
14837: }
14838: }
14839:
1.444 albertel 14840: #
14841: # Open course
14842: #
14843: my $crstype = lc($args->{'crstype'});
14844: my %cenv=();
14845: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
14846: $args->{'cdescr'},
14847: $args->{'curl'},
14848: $args->{'course_home'},
14849: $args->{'nonstandard'},
14850: $args->{'crscode'},
14851: $args->{'ccuname'}.':'.
14852: $args->{'ccdomain'},
1.882 raeburn 14853: $args->{'crstype'},
1.885 raeburn 14854: $cnum,$context,$category);
1.444 albertel 14855:
14856: # Note: The testing routines depend on this being output; see
14857: # Utils::Course. This needs to at least be output as a comment
14858: # if anyone ever decides to not show this, and Utils::Course::new
14859: # will need to be suitably modified.
1.541 raeburn 14860: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 14861: if ($$courseid =~ /^error:/) {
14862: return (0,$outcome);
14863: }
14864:
1.444 albertel 14865: #
14866: # Check if created correctly
14867: #
1.479 albertel 14868: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 14869: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 14870: if ($crsuhome eq 'no_host') {
14871: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
14872: return (0,$outcome);
14873: }
1.541 raeburn 14874: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 14875:
1.444 albertel 14876: #
1.566 albertel 14877: # Do the cloning
14878: #
14879: if ($can_clone && $cloneid) {
14880: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
14881: if ($context ne 'auto') {
14882: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
14883: }
14884: $outcome .= $clonemsg.$linefeed;
14885: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 14886: # Copy all files
1.637 www 14887: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 14888: # Restore URL
1.566 albertel 14889: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 14890: # Restore title
1.566 albertel 14891: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 14892: # Restore creation date, creator and creation context.
14893: $cenv{'internal.created'}=$oldcenv{'internal.created'};
14894: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
14895: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 14896: # Mark as cloned
1.566 albertel 14897: $cenv{'clonedfrom'}=$cloneid;
1.638 www 14898: # Need to clone grading mode
14899: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
14900: $cenv{'grading'}=$newenv{'grading'};
14901: # Do not clone these environment entries
14902: &Apache::lonnet::del('environment',
14903: ['default_enrollment_start_date',
14904: 'default_enrollment_end_date',
14905: 'question.email',
14906: 'policy.email',
14907: 'comment.email',
14908: 'pch.users.denied',
1.725 raeburn 14909: 'plc.users.denied',
14910: 'hidefromcat',
1.1075.2.36 raeburn 14911: 'checkforpriv',
1.1075.2.59 raeburn 14912: 'categories',
14913: 'internal.uniquecode'],
1.638 www 14914: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 14915: if ($args->{'textbook'}) {
14916: $cenv{'internal.textbook'} = $args->{'textbook'};
14917: }
1.444 albertel 14918: }
1.566 albertel 14919:
1.444 albertel 14920: #
14921: # Set environment (will override cloned, if existing)
14922: #
14923: my @sections = ();
14924: my @xlists = ();
14925: if ($args->{'crstype'}) {
14926: $cenv{'type'}=$args->{'crstype'};
14927: }
14928: if ($args->{'crsid'}) {
14929: $cenv{'courseid'}=$args->{'crsid'};
14930: }
14931: if ($args->{'crscode'}) {
14932: $cenv{'internal.coursecode'}=$args->{'crscode'};
14933: }
14934: if ($args->{'crsquota'} ne '') {
14935: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14936: } else {
14937: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14938: }
14939: if ($args->{'ccuname'}) {
14940: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14941: ':'.$args->{'ccdomain'};
14942: } else {
14943: $cenv{'internal.courseowner'} = $args->{'curruser'};
14944: }
1.1075.2.31 raeburn 14945: if ($args->{'defaultcredits'}) {
14946: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14947: }
1.444 albertel 14948: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14949: if ($args->{'crssections'}) {
14950: $cenv{'internal.sectionnums'} = '';
14951: if ($args->{'crssections'} =~ m/,/) {
14952: @sections = split/,/,$args->{'crssections'};
14953: } else {
14954: $sections[0] = $args->{'crssections'};
14955: }
14956: if (@sections > 0) {
14957: foreach my $item (@sections) {
14958: my ($sec,$gp) = split/:/,$item;
14959: my $class = $args->{'crscode'}.$sec;
14960: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14961: $cenv{'internal.sectionnums'} .= $item.',';
14962: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 14963: push(@badclasses,$class);
1.444 albertel 14964: }
14965: }
14966: $cenv{'internal.sectionnums'} =~ s/,$//;
14967: }
14968: }
14969: # do not hide course coordinator from staff listing,
14970: # even if privileged
14971: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 14972: # add course coordinator's domain to domains to check for privileged users
14973: # if different to course domain
14974: if ($$crsudom ne $args->{'ccdomain'}) {
14975: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14976: }
1.444 albertel 14977: # add crosslistings
14978: if ($args->{'crsxlist'}) {
14979: $cenv{'internal.crosslistings'}='';
14980: if ($args->{'crsxlist'} =~ m/,/) {
14981: @xlists = split/,/,$args->{'crsxlist'};
14982: } else {
14983: $xlists[0] = $args->{'crsxlist'};
14984: }
14985: if (@xlists > 0) {
14986: foreach my $item (@xlists) {
14987: my ($xl,$gp) = split/:/,$item;
14988: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14989: $cenv{'internal.crosslistings'} .= $item.',';
14990: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 14991: push(@badclasses,$xl);
1.444 albertel 14992: }
14993: }
14994: $cenv{'internal.crosslistings'} =~ s/,$//;
14995: }
14996: }
14997: if ($args->{'autoadds'}) {
14998: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14999: }
15000: if ($args->{'autodrops'}) {
15001: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15002: }
15003: # check for notification of enrollment changes
15004: my @notified = ();
15005: if ($args->{'notify_owner'}) {
15006: if ($args->{'ccuname'} ne '') {
15007: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15008: }
15009: }
15010: if ($args->{'notify_dc'}) {
15011: if ($uname ne '') {
1.630 raeburn 15012: push(@notified,$uname.':'.$udom);
1.444 albertel 15013: }
15014: }
15015: if (@notified > 0) {
15016: my $notifylist;
15017: if (@notified > 1) {
15018: $notifylist = join(',',@notified);
15019: } else {
15020: $notifylist = $notified[0];
15021: }
15022: $cenv{'internal.notifylist'} = $notifylist;
15023: }
15024: if (@badclasses > 0) {
15025: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 15026: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15027: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15028: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15029: );
1.1075.2.119 raeburn 15030: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15031: &mt('That is because the user identified as the course owner ([_1]) does not have rights to access enrollment in these classes, as determined by the policies of your institution on access to official classlists',$cenv{'internal.courseowner'}).$linefeed.$lt{'itis'};
1.541 raeburn 15032: if ($context eq 'auto') {
15033: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 15034: } else {
1.566 albertel 15035: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 15036: }
15037: foreach my $item (@badclasses) {
1.541 raeburn 15038: if ($context eq 'auto') {
1.1075.2.119 raeburn 15039: $outcome .= " - $item\n";
1.541 raeburn 15040: } else {
1.1075.2.119 raeburn 15041: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15042: }
1.1075.2.119 raeburn 15043: }
15044: if ($context eq 'auto') {
15045: $outcome .= $linefeed;
15046: } else {
15047: $outcome .= "</ul><br /><br /></div>\n";
15048: }
1.444 albertel 15049: }
15050: if ($args->{'no_end_date'}) {
15051: $args->{'endaccess'} = 0;
15052: }
15053: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15054: $cenv{'internal.autoend'}=$args->{'enrollend'};
15055: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15056: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15057: if ($args->{'showphotos'}) {
15058: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15059: }
15060: $cenv{'internal.authtype'} = $args->{'authtype'};
15061: $cenv{'internal.autharg'} = $args->{'autharg'};
15062: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15063: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15064: 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');
15065: if ($context eq 'auto') {
15066: $outcome .= $krb_msg;
15067: } else {
1.566 albertel 15068: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15069: }
15070: $outcome .= $linefeed;
1.444 albertel 15071: }
15072: }
15073: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15074: if ($args->{'setpolicy'}) {
15075: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15076: }
15077: if ($args->{'setcontent'}) {
15078: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15079: }
1.1075.2.110 raeburn 15080: if ($args->{'setcomment'}) {
15081: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15082: }
1.444 albertel 15083: }
15084: if ($args->{'reshome'}) {
15085: $cenv{'reshome'}=$args->{'reshome'}.'/';
15086: $cenv{'reshome'}=~s/\/+$/\//;
15087: }
15088: #
15089: # course has keyed access
15090: #
15091: if ($args->{'setkeys'}) {
15092: $cenv{'keyaccess'}='yes';
15093: }
15094: # if specified, key authority is not course, but user
15095: # only active if keyaccess is yes
15096: if ($args->{'keyauth'}) {
1.487 albertel 15097: my ($user,$domain) = split(':',$args->{'keyauth'});
15098: $user = &LONCAPA::clean_username($user);
15099: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15100: if ($user ne '' && $domain ne '') {
1.487 albertel 15101: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15102: }
15103: }
15104:
1.1075.2.59 raeburn 15105: #
15106: # generate and store uniquecode (available to course requester), if course should have one.
15107: #
15108: if ($args->{'uniquecode'}) {
15109: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15110: if ($code) {
15111: $cenv{'internal.uniquecode'} = $code;
15112: my %crsinfo =
15113: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15114: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15115: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15116: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15117: }
15118: if (ref($coderef)) {
15119: $$coderef = $code;
15120: }
15121: }
15122: }
15123:
1.444 albertel 15124: if ($args->{'disresdis'}) {
15125: $cenv{'pch.roles.denied'}='st';
15126: }
15127: if ($args->{'disablechat'}) {
15128: $cenv{'plc.roles.denied'}='st';
15129: }
15130:
15131: # Record we've not yet viewed the Course Initialization Helper for this
15132: # course
15133: $cenv{'course.helper.not.run'} = 1;
15134: #
15135: # Use new Randomseed
15136: #
15137: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15138: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15139: #
15140: # The encryption code and receipt prefix for this course
15141: #
15142: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15143: $cenv{'internal.encpref'}=100+int(9*rand(99));
15144: #
15145: # By default, use standard grading
15146: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15147:
1.541 raeburn 15148: $outcome .= $linefeed.&mt('Setting environment').': '.
15149: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15150: #
15151: # Open all assignments
15152: #
15153: if ($args->{'openall'}) {
15154: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15155: my %storecontent = ($storeunder => time,
15156: $storeunder.'.type' => 'date_start');
15157:
15158: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15159: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15160: }
15161: #
15162: # Set first page
15163: #
15164: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15165: || ($cloneid)) {
1.445 albertel 15166: use LONCAPA::map;
1.444 albertel 15167: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15168:
15169: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15170: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15171:
1.444 albertel 15172: $outcome .= ($fatal?$errtext:'read ok').' - ';
15173: my $title; my $url;
15174: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15175: $title=&mt('Syllabus');
1.444 albertel 15176: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15177: } else {
1.963 raeburn 15178: $title=&mt('Table of Contents');
1.444 albertel 15179: $url='/adm/navmaps';
15180: }
1.445 albertel 15181:
15182: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15183: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15184:
15185: if ($errtext) { $fatal=2; }
1.541 raeburn 15186: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15187: }
1.566 albertel 15188:
15189: return (1,$outcome);
1.444 albertel 15190: }
15191:
1.1075.2.59 raeburn 15192: sub make_unique_code {
15193: my ($cdom,$cnum) = @_;
15194: # get lock on uniquecodes db
15195: my $lockhash = {
15196: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15197: ':'.$env{'user.domain'},
15198: };
15199: my $tries = 0;
15200: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15201: my ($code,$error);
15202:
15203: while (($gotlock ne 'ok') && ($tries<3)) {
15204: $tries ++;
15205: sleep 1;
15206: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15207: }
15208: if ($gotlock eq 'ok') {
15209: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15210: my $gotcode;
15211: my $attempts = 0;
15212: while ((!$gotcode) && ($attempts < 100)) {
15213: $code = &generate_code();
15214: if (!exists($currcodes{$code})) {
15215: $gotcode = 1;
15216: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15217: $error = 'nostore';
15218: }
15219: }
15220: $attempts ++;
15221: }
15222: my @del_lock = ($cnum."\0".'uniquecodes');
15223: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15224: } else {
15225: $error = 'nolock';
15226: }
15227: return ($code,$error);
15228: }
15229:
15230: sub generate_code {
15231: my $code;
15232: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15233: for (my $i=0; $i<6; $i++) {
15234: my $lettnum = int (rand 2);
15235: my $item = '';
15236: if ($lettnum) {
15237: $item = $letts[int( rand(18) )];
15238: } else {
15239: $item = 1+int( rand(8) );
15240: }
15241: $code .= $item;
15242: }
15243: return $code;
15244: }
15245:
1.444 albertel 15246: ############################################################
15247: ############################################################
15248:
1.953 droeschl 15249: #SD
15250: # only Community and Course, or anything else?
1.378 raeburn 15251: sub course_type {
15252: my ($cid) = @_;
15253: if (!defined($cid)) {
15254: $cid = $env{'request.course.id'};
15255: }
1.404 albertel 15256: if (defined($env{'course.'.$cid.'.type'})) {
15257: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15258: } else {
15259: return 'Course';
1.377 raeburn 15260: }
15261: }
1.156 albertel 15262:
1.406 raeburn 15263: sub group_term {
15264: my $crstype = &course_type();
15265: my %names = (
15266: 'Course' => 'group',
1.865 raeburn 15267: 'Community' => 'group',
1.406 raeburn 15268: );
15269: return $names{$crstype};
15270: }
15271:
1.902 raeburn 15272: sub course_types {
1.1075.2.59 raeburn 15273: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15274: my %typename = (
15275: official => 'Official course',
15276: unofficial => 'Unofficial course',
15277: community => 'Community',
1.1075.2.59 raeburn 15278: textbook => 'Textbook course',
1.902 raeburn 15279: );
15280: return (\@types,\%typename);
15281: }
15282:
1.156 albertel 15283: sub icon {
15284: my ($file)=@_;
1.505 albertel 15285: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15286: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15287: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15288: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15289: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15290: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15291: $curfext.".gif") {
15292: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15293: $curfext.".gif";
15294: }
15295: }
1.249 albertel 15296: return &lonhttpdurl($iconname);
1.154 albertel 15297: }
1.84 albertel 15298:
1.575 albertel 15299: sub lonhttpdurl {
1.692 www 15300: #
15301: # Had been used for "small fry" static images on separate port 8080.
15302: # Modify here if lightweight http functionality desired again.
15303: # Currently eliminated due to increasing firewall issues.
15304: #
1.575 albertel 15305: my ($url)=@_;
1.692 www 15306: return $url;
1.215 albertel 15307: }
15308:
1.213 albertel 15309: sub connection_aborted {
15310: my ($r)=@_;
15311: $r->print(" ");$r->rflush();
15312: my $c = $r->connection;
15313: return $c->aborted();
15314: }
15315:
1.221 foxr 15316: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15317: # strings as 'strings'.
15318: sub escape_single {
1.221 foxr 15319: my ($input) = @_;
1.223 albertel 15320: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15321: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15322: return $input;
15323: }
1.223 albertel 15324:
1.222 foxr 15325: # Same as escape_single, but escape's "'s This
15326: # can be used for "strings"
15327: sub escape_double {
15328: my ($input) = @_;
15329: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15330: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15331: return $input;
15332: }
1.223 albertel 15333:
1.222 foxr 15334: # Escapes the last element of a full URL.
15335: sub escape_url {
15336: my ($url) = @_;
1.238 raeburn 15337: my @urlslices = split(/\//, $url,-1);
1.369 www 15338: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 15339: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15340: }
1.462 albertel 15341:
1.820 raeburn 15342: sub compare_arrays {
15343: my ($arrayref1,$arrayref2) = @_;
15344: my (@difference,%count);
15345: @difference = ();
15346: %count = ();
15347: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15348: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15349: foreach my $element (keys(%count)) {
15350: if ($count{$element} == 1) {
15351: push(@difference,$element);
15352: }
15353: }
15354: }
15355: return @difference;
15356: }
15357:
1.817 bisitz 15358: # -------------------------------------------------------- Initialize user login
1.462 albertel 15359: sub init_user_environment {
1.463 albertel 15360: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15361: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15362:
15363: my $public=($username eq 'public' && $domain eq 'public');
15364:
15365: # See if old ID present, if so, remove
15366:
1.1062 raeburn 15367: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15368: my $now=time;
15369:
15370: if ($public) {
15371: my $max_public=100;
15372: my $oldest;
15373: my $oldest_time=0;
15374: for(my $next=1;$next<=$max_public;$next++) {
15375: if (-e $lonids."/publicuser_$next.id") {
15376: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15377: if ($mtime<$oldest_time || !$oldest_time) {
15378: $oldest_time=$mtime;
15379: $oldest=$next;
15380: }
15381: } else {
15382: $cookie="publicuser_$next";
15383: last;
15384: }
15385: }
15386: if (!$cookie) { $cookie="publicuser_$oldest"; }
15387: } else {
1.463 albertel 15388: # if this isn't a robot, kill any existing non-robot sessions
15389: if (!$args->{'robot'}) {
15390: opendir(DIR,$lonids);
15391: while ($filename=readdir(DIR)) {
15392: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
15393: unlink($lonids.'/'.$filename);
15394: }
1.462 albertel 15395: }
1.463 albertel 15396: closedir(DIR);
1.1075.2.84 raeburn 15397: # If there is a undeleted lockfile for the user's paste buffer remove it.
15398: my $namespace = 'nohist_courseeditor';
15399: my $lockingkey = 'paste'."\0".'locked_num';
15400: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15401: $domain,$username);
15402: if (exists($lockhash{$lockingkey})) {
15403: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15404: unless ($delresult eq 'ok') {
15405: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15406: }
15407: }
1.462 albertel 15408: }
15409: # Give them a new cookie
1.463 albertel 15410: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15411: : $now.$$.int(rand(10000)));
1.463 albertel 15412: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15413:
15414: # Initialize roles
15415:
1.1062 raeburn 15416: ($userroles,$firstaccenv,$timerintenv) =
15417: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15418: }
15419: # ------------------------------------ Check browser type and MathML capability
15420:
1.1075.2.77 raeburn 15421: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15422: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15423:
15424: # ------------------------------------------------------------- Get environment
15425:
15426: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15427: my ($tmp) = keys(%userenv);
15428: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15429: } else {
15430: undef(%userenv);
15431: }
15432: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15433: $form->{'interface'}=$userenv{'interface'};
15434: }
15435: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15436:
15437: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15438: foreach my $option ('interface','localpath','localres') {
15439: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15440: }
15441: # --------------------------------------------------------- Write first profile
15442:
15443: {
15444: my %initial_env =
15445: ("user.name" => $username,
15446: "user.domain" => $domain,
15447: "user.home" => $authhost,
15448: "browser.type" => $clientbrowser,
15449: "browser.version" => $clientversion,
15450: "browser.mathml" => $clientmathml,
15451: "browser.unicode" => $clientunicode,
15452: "browser.os" => $clientos,
1.1075.2.42 raeburn 15453: "browser.mobile" => $clientmobile,
15454: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 15455: "browser.osversion" => $clientosversion,
1.462 albertel 15456: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15457: "request.course.fn" => '',
15458: "request.course.uri" => '',
15459: "request.course.sec" => '',
15460: "request.role" => 'cm',
15461: "request.role.adv" => $env{'user.adv'},
15462: "request.host" => $ENV{'REMOTE_ADDR'},);
15463:
15464: if ($form->{'localpath'}) {
15465: $initial_env{"browser.localpath"} = $form->{'localpath'};
15466: $initial_env{"browser.localres"} = $form->{'localres'};
15467: }
15468:
15469: if ($form->{'interface'}) {
15470: $form->{'interface'}=~s/\W//gs;
15471: $initial_env{"browser.interface"} = $form->{'interface'};
15472: $env{'browser.interface'}=$form->{'interface'};
15473: }
15474:
1.1075.2.54 raeburn 15475: if ($form->{'iptoken'}) {
15476: my $lonhost = $r->dir_config('lonHostID');
15477: $initial_env{"user.noloadbalance"} = $lonhost;
15478: $env{'user.noloadbalance'} = $lonhost;
15479: }
15480:
1.1075.2.120 raeburn 15481: if ($form->{'noloadbalance'}) {
15482: my @hosts = &Apache::lonnet::current_machine_ids();
15483: my $hosthere = $form->{'noloadbalance'};
15484: if (grep(/^\Q$hosthere\E$/,@hosts)) {
15485: $initial_env{"user.noloadbalance"} = $hosthere;
15486: $env{'user.noloadbalance'} = $hosthere;
15487: }
15488: }
15489:
1.1016 raeburn 15490: unless ($domain eq 'public') {
1.1075.2.125 raeburn 15491: my %is_adv = ( is_adv => $env{'user.adv'} );
15492: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 15493:
1.1075.2.125 raeburn 15494: foreach my $tool ('aboutme','blog','webdav','portfolio') {
15495: $userenv{'availabletools.'.$tool} =
15496: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15497: undef,\%userenv,\%domdef,\%is_adv);
15498: }
1.724 raeburn 15499:
1.1075.2.125 raeburn 15500: foreach my $crstype ('official','unofficial','community','textbook') {
15501: $userenv{'canrequest.'.$crstype} =
15502: &Apache::lonnet::usertools_access($username,$domain,$crstype,
15503: 'reload','requestcourses',
15504: \%userenv,\%domdef,\%is_adv);
15505: }
1.765 raeburn 15506:
1.1075.2.125 raeburn 15507: $userenv{'canrequest.author'} =
15508: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15509: 'reload','requestauthor',
15510: \%userenv,\%domdef,\%is_adv);
15511: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15512: $domain,$username);
15513: my $reqstatus = $reqauthor{'author_status'};
15514: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15515: if (ref($reqauthor{'author'}) eq 'HASH') {
15516: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15517: $reqauthor{'author'}{'timestamp'};
15518: }
1.1075.2.14 raeburn 15519: }
15520: }
15521:
1.462 albertel 15522: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15523:
1.462 albertel 15524: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
15525: &GDBM_WRCREAT(),0640)) {
15526: &_add_to_env(\%disk_env,\%initial_env);
15527: &_add_to_env(\%disk_env,\%userenv,'environment.');
15528: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 15529: if (ref($firstaccenv) eq 'HASH') {
15530: &_add_to_env(\%disk_env,$firstaccenv);
15531: }
15532: if (ref($timerintenv) eq 'HASH') {
15533: &_add_to_env(\%disk_env,$timerintenv);
15534: }
1.463 albertel 15535: if (ref($args->{'extra_env'})) {
15536: &_add_to_env(\%disk_env,$args->{'extra_env'});
15537: }
1.462 albertel 15538: untie(%disk_env);
15539: } else {
1.705 tempelho 15540: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
15541: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 15542: return 'error: '.$!;
15543: }
15544: }
15545: $env{'request.role'}='cm';
15546: $env{'request.role.adv'}=$env{'user.adv'};
15547: $env{'browser.type'}=$clientbrowser;
15548:
15549: return $cookie;
15550:
15551: }
15552:
15553: sub _add_to_env {
15554: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 15555: if (ref($env_data) eq 'HASH') {
15556: while (my ($key,$value) = each(%$env_data)) {
15557: $idf->{$prefix.$key} = $value;
15558: $env{$prefix.$key} = $value;
15559: }
1.462 albertel 15560: }
15561: }
15562:
1.685 tempelho 15563: # --- Get the symbolic name of a problem and the url
15564: sub get_symb {
15565: my ($request,$silent) = @_;
1.726 raeburn 15566: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 15567: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
15568: if ($symb eq '') {
15569: if (!$silent) {
1.1071 raeburn 15570: if (ref($request)) {
15571: $request->print("Unable to handle ambiguous references:$url:.");
15572: }
1.685 tempelho 15573: return ();
15574: }
15575: }
15576: &Apache::lonenc::check_decrypt(\$symb);
15577: return ($symb);
15578: }
15579:
15580: # --------------------------------------------------------------Get annotation
15581:
15582: sub get_annotation {
15583: my ($symb,$enc) = @_;
15584:
15585: my $key = $symb;
15586: if (!$enc) {
15587: $key =
15588: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
15589: }
15590: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
15591: return $annotation{$key};
15592: }
15593:
15594: sub clean_symb {
1.731 raeburn 15595: my ($symb,$delete_enc) = @_;
1.685 tempelho 15596:
15597: &Apache::lonenc::check_decrypt(\$symb);
15598: my $enc = $env{'request.enc'};
1.731 raeburn 15599: if ($delete_enc) {
1.730 raeburn 15600: delete($env{'request.enc'});
15601: }
1.685 tempelho 15602:
15603: return ($symb,$enc);
15604: }
1.462 albertel 15605:
1.1075.2.69 raeburn 15606: ############################################################
15607: ############################################################
15608:
15609: =pod
15610:
15611: =head1 Routines for building display used to search for courses
15612:
15613:
15614: =over 4
15615:
15616: =item * &build_filters()
15617:
15618: Create markup for a table used to set filters to use when selecting
15619: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
15620: and quotacheck.pl
15621:
15622:
15623: Inputs:
15624:
15625: filterlist - anonymous array of fields to include as potential filters
15626:
15627: crstype - course type
15628:
15629: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
15630: to pop-open a course selector (will contain "extra element").
15631:
15632: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
15633:
15634: filter - anonymous hash of criteria and their values
15635:
15636: action - form action
15637:
15638: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
15639:
15640: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
15641:
15642: cloneruname - username of owner of new course who wants to clone
15643:
15644: clonerudom - domain of owner of new course who wants to clone
15645:
15646: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
15647:
15648: codetitlesref - reference to array of titles of components in institutional codes (official courses)
15649:
15650: codedom - domain
15651:
15652: formname - value of form element named "form".
15653:
15654: fixeddom - domain, if fixed.
15655:
15656: prevphase - value to assign to form element named "phase" when going back to the previous screen
15657:
15658: cnameelement - name of form element in form on opener page which will receive title of selected course
15659:
15660: cnumelement - name of form element in form on opener page which will receive courseID of selected course
15661:
15662: cdomelement - name of form element in form on opener page which will receive domain of selected course
15663:
15664: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
15665:
15666: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
15667:
15668: clonewarning - warning message about missing information for intended course owner when DC creates a course
15669:
15670:
15671: Returns: $output - HTML for display of search criteria, and hidden form elements.
15672:
15673:
15674: Side Effects: None
15675:
15676: =cut
15677:
15678: # ---------------------------------------------- search for courses based on last activity etc.
15679:
15680: sub build_filters {
15681: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
15682: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
15683: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
15684: $cnameelement,$cnumelement,$cdomelement,$setroles,
15685: $clonetext,$clonewarning) = @_;
15686: my ($list,$jscript);
15687: my $onchange = 'javascript:updateFilters(this)';
15688: my ($domainselectform,$sincefilterform,$createdfilterform,
15689: $ownerdomselectform,$persondomselectform,$instcodeform,
15690: $typeselectform,$instcodetitle);
15691: if ($formname eq '') {
15692: $formname = $caller;
15693: }
15694: foreach my $item (@{$filterlist}) {
15695: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
15696: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
15697: if ($item eq 'domainfilter') {
15698: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
15699: } elsif ($item eq 'coursefilter') {
15700: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
15701: } elsif ($item eq 'ownerfilter') {
15702: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15703: } elsif ($item eq 'ownerdomfilter') {
15704: $filter->{'ownerdomfilter'} =
15705: &LONCAPA::clean_domain($filter->{$item});
15706: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
15707: 'ownerdomfilter',1);
15708: } elsif ($item eq 'personfilter') {
15709: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15710: } elsif ($item eq 'persondomfilter') {
15711: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
15712: 'persondomfilter',1);
15713: } else {
15714: $filter->{$item} =~ s/\W//g;
15715: }
15716: if (!$filter->{$item}) {
15717: $filter->{$item} = '';
15718: }
15719: }
15720: if ($item eq 'domainfilter') {
15721: my $allow_blank = 1;
15722: if ($formname eq 'portform') {
15723: $allow_blank=0;
15724: } elsif ($formname eq 'studentform') {
15725: $allow_blank=0;
15726: }
15727: if ($fixeddom) {
15728: $domainselectform = '<input type="hidden" name="domainfilter"'.
15729: ' value="'.$codedom.'" />'.
15730: &Apache::lonnet::domain($codedom,'description');
15731: } else {
15732: $domainselectform = &select_dom_form($filter->{$item},
15733: 'domainfilter',
15734: $allow_blank,'',$onchange);
15735: }
15736: } else {
15737: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
15738: }
15739: }
15740:
15741: # last course activity filter and selection
15742: $sincefilterform = &timebased_select_form('sincefilter',$filter);
15743:
15744: # course created filter and selection
15745: if (exists($filter->{'createdfilter'})) {
15746: $createdfilterform = &timebased_select_form('createdfilter',$filter);
15747: }
15748:
15749: my %lt = &Apache::lonlocal::texthash(
15750: 'cac' => "$crstype Activity",
15751: 'ccr' => "$crstype Created",
15752: 'cde' => "$crstype Title",
15753: 'cdo' => "$crstype Domain",
15754: 'ins' => 'Institutional Code',
15755: 'inc' => 'Institutional Categorization',
15756: 'cow' => "$crstype Owner/Co-owner",
15757: 'cop' => "$crstype Personnel Includes",
15758: 'cog' => 'Type',
15759: );
15760:
15761: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15762: my $typeval = 'Course';
15763: if ($crstype eq 'Community') {
15764: $typeval = 'Community';
15765: }
15766: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
15767: } else {
15768: $typeselectform = '<select name="type" size="1"';
15769: if ($onchange) {
15770: $typeselectform .= ' onchange="'.$onchange.'"';
15771: }
15772: $typeselectform .= '>'."\n";
15773: foreach my $posstype ('Course','Community') {
15774: $typeselectform.='<option value="'.$posstype.'"'.
15775: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
15776: }
15777: $typeselectform.="</select>";
15778: }
15779:
15780: my ($cloneableonlyform,$cloneabletitle);
15781: if (exists($filter->{'cloneableonly'})) {
15782: my $cloneableon = '';
15783: my $cloneableoff = ' checked="checked"';
15784: if ($filter->{'cloneableonly'}) {
15785: $cloneableon = $cloneableoff;
15786: $cloneableoff = '';
15787: }
15788: $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>';
15789: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 15790: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 15791: } else {
15792: $cloneabletitle = &mt('Cloneable by you');
15793: }
15794: }
15795: my $officialjs;
15796: if ($crstype eq 'Course') {
15797: if (exists($filter->{'instcodefilter'})) {
15798: # if (($fixeddom) || ($formname eq 'requestcrs') ||
15799: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
15800: if ($codedom) {
15801: $officialjs = 1;
15802: ($instcodeform,$jscript,$$numtitlesref) =
15803: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
15804: $officialjs,$codetitlesref);
15805: if ($jscript) {
15806: $jscript = '<script type="text/javascript">'."\n".
15807: '// <![CDATA['."\n".
15808: $jscript."\n".
15809: '// ]]>'."\n".
15810: '</script>'."\n";
15811: }
15812: }
15813: if ($instcodeform eq '') {
15814: $instcodeform =
15815: '<input type="text" name="instcodefilter" size="10" value="'.
15816: $list->{'instcodefilter'}.'" />';
15817: $instcodetitle = $lt{'ins'};
15818: } else {
15819: $instcodetitle = $lt{'inc'};
15820: }
15821: if ($fixeddom) {
15822: $instcodetitle .= '<br />('.$codedom.')';
15823: }
15824: }
15825: }
15826: my $output = qq|
15827: <form method="post" name="filterpicker" action="$action">
15828: <input type="hidden" name="form" value="$formname" />
15829: |;
15830: if ($formname eq 'modifycourse') {
15831: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
15832: '<input type="hidden" name="prevphase" value="'.
15833: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 15834: } elsif ($formname eq 'quotacheck') {
15835: $output .= qq|
15836: <input type="hidden" name="sortby" value="" />
15837: <input type="hidden" name="sortorder" value="" />
15838: |;
15839: } else {
1.1075.2.69 raeburn 15840: my $name_input;
15841: if ($cnameelement ne '') {
15842: $name_input = '<input type="hidden" name="cnameelement" value="'.
15843: $cnameelement.'" />';
15844: }
15845: $output .= qq|
15846: <input type="hidden" name="cnumelement" value="$cnumelement" />
15847: <input type="hidden" name="cdomelement" value="$cdomelement" />
15848: $name_input
15849: $roleelement
15850: $multelement
15851: $typeelement
15852: |;
15853: if ($formname eq 'portform') {
15854: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
15855: }
15856: }
15857: if ($fixeddom) {
15858: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
15859: }
15860: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
15861: if ($sincefilterform) {
15862: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
15863: .$sincefilterform
15864: .&Apache::lonhtmlcommon::row_closure();
15865: }
15866: if ($createdfilterform) {
15867: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
15868: .$createdfilterform
15869: .&Apache::lonhtmlcommon::row_closure();
15870: }
15871: if ($domainselectform) {
15872: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
15873: .$domainselectform
15874: .&Apache::lonhtmlcommon::row_closure();
15875: }
15876: if ($typeselectform) {
15877: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15878: $output .= $typeselectform;
15879: } else {
15880: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
15881: .$typeselectform
15882: .&Apache::lonhtmlcommon::row_closure();
15883: }
15884: }
15885: if ($instcodeform) {
15886: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
15887: .$instcodeform
15888: .&Apache::lonhtmlcommon::row_closure();
15889: }
15890: if (exists($filter->{'ownerfilter'})) {
15891: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
15892: '<table><tr><td>'.&mt('Username').'<br />'.
15893: '<input type="text" name="ownerfilter" size="20" value="'.
15894: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15895: $ownerdomselectform.'</td></tr></table>'.
15896: &Apache::lonhtmlcommon::row_closure();
15897: }
15898: if (exists($filter->{'personfilter'})) {
15899: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
15900: '<table><tr><td>'.&mt('Username').'<br />'.
15901: '<input type="text" name="personfilter" size="20" value="'.
15902: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15903: $persondomselectform.'</td></tr></table>'.
15904: &Apache::lonhtmlcommon::row_closure();
15905: }
15906: if (exists($filter->{'coursefilter'})) {
15907: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
15908: .'<input type="text" name="coursefilter" size="25" value="'
15909: .$list->{'coursefilter'}.'" />'
15910: .&Apache::lonhtmlcommon::row_closure();
15911: }
15912: if ($cloneableonlyform) {
15913: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
15914: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
15915: }
15916: if (exists($filter->{'descriptfilter'})) {
15917: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
15918: .'<input type="text" name="descriptfilter" size="40" value="'
15919: .$list->{'descriptfilter'}.'" />'
15920: .&Apache::lonhtmlcommon::row_closure(1);
15921: }
15922: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
15923: '<input type="hidden" name="updater" value="" />'."\n".
15924: '<input type="submit" name="gosearch" value="'.
15925: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
15926: return $jscript.$clonewarning.$output;
15927: }
15928:
15929: =pod
15930:
15931: =item * &timebased_select_form()
15932:
15933: Create markup for a dropdown list used to select a time-based
15934: filter e.g., Course Activity, Course Created, when searching for courses
15935: or communities
15936:
15937: Inputs:
15938:
15939: item - name of form element (sincefilter or createdfilter)
15940:
15941: filter - anonymous hash of criteria and their values
15942:
15943: Returns: HTML for a select box contained a blank, then six time selections,
15944: with value set in incoming form variables currently selected.
15945:
15946: Side Effects: None
15947:
15948: =cut
15949:
15950: sub timebased_select_form {
15951: my ($item,$filter) = @_;
15952: if (ref($filter) eq 'HASH') {
15953: $filter->{$item} =~ s/[^\d-]//g;
15954: if (!$filter->{$item}) { $filter->{$item}=-1; }
15955: return &select_form(
15956: $filter->{$item},
15957: $item,
15958: { '-1' => '',
15959: '86400' => &mt('today'),
15960: '604800' => &mt('last week'),
15961: '2592000' => &mt('last month'),
15962: '7776000' => &mt('last three months'),
15963: '15552000' => &mt('last six months'),
15964: '31104000' => &mt('last year'),
15965: 'select_form_order' =>
15966: ['-1','86400','604800','2592000','7776000',
15967: '15552000','31104000']});
15968: }
15969: }
15970:
15971: =pod
15972:
15973: =item * &js_changer()
15974:
15975: Create script tag containing Javascript used to submit course search form
15976: when course type or domain is changed, and also to hide 'Searching ...' on
15977: page load completion for page showing search result.
15978:
15979: Inputs: None
15980:
15981: Returns: markup containing updateFilters() and hideSearching() javascript functions.
15982:
15983: Side Effects: None
15984:
15985: =cut
15986:
15987: sub js_changer {
15988: return <<ENDJS;
15989: <script type="text/javascript">
15990: // <![CDATA[
15991: function updateFilters(caller) {
15992: if (typeof(caller) != "undefined") {
15993: document.filterpicker.updater.value = caller.name;
15994: }
15995: document.filterpicker.submit();
15996: }
15997:
15998: function hideSearching() {
15999: if (document.getElementById('searching')) {
16000: document.getElementById('searching').style.display = 'none';
16001: }
16002: return;
16003: }
16004:
16005: // ]]>
16006: </script>
16007:
16008: ENDJS
16009: }
16010:
16011: =pod
16012:
16013: =item * &search_courses()
16014:
16015: Process selected filters form course search form and pass to lonnet::courseiddump
16016: to retrieve a hash for which keys are courseIDs which match the selected filters.
16017:
16018: Inputs:
16019:
16020: dom - domain being searched
16021:
16022: type - course type ('Course' or 'Community' or '.' if any).
16023:
16024: filter - anonymous hash of criteria and their values
16025:
16026: numtitles - for institutional codes - number of categories
16027:
16028: cloneruname - optional username of new course owner
16029:
16030: clonerudom - optional domain of new course owner
16031:
1.1075.2.95 raeburn 16032: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 16033: (used when DC is using course creation form)
16034:
16035: codetitles - reference to array of titles of components in institutional codes (official courses).
16036:
1.1075.2.95 raeburn 16037: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16038: (and so can clone automatically)
16039:
16040: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16041:
16042: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16043: courses to clone
1.1075.2.69 raeburn 16044:
16045: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16046:
16047:
16048: Side Effects: None
16049:
16050: =cut
16051:
16052:
16053: sub search_courses {
1.1075.2.95 raeburn 16054: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16055: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 16056: my (%courses,%showcourses,$cloner);
16057: if (($filter->{'ownerfilter'} ne '') ||
16058: ($filter->{'ownerdomfilter'} ne '')) {
16059: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16060: $filter->{'ownerdomfilter'};
16061: }
16062: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16063: if (!$filter->{$item}) {
16064: $filter->{$item}='.';
16065: }
16066: }
16067: my $now = time;
16068: my $timefilter =
16069: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16070: my ($createdbefore,$createdafter);
16071: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16072: $createdbefore = $now;
16073: $createdafter = $now-$filter->{'createdfilter'};
16074: }
16075: my ($instcodefilter,$regexpok);
16076: if ($numtitles) {
16077: if ($env{'form.official'} eq 'on') {
16078: $instcodefilter =
16079: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16080: $regexpok = 1;
16081: } elsif ($env{'form.official'} eq 'off') {
16082: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16083: unless ($instcodefilter eq '') {
16084: $regexpok = -1;
16085: }
16086: }
16087: } else {
16088: $instcodefilter = $filter->{'instcodefilter'};
16089: }
16090: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16091: if ($type eq '') { $type = '.'; }
16092:
16093: if (($clonerudom ne '') && ($cloneruname ne '')) {
16094: $cloner = $cloneruname.':'.$clonerudom;
16095: }
16096: %courses = &Apache::lonnet::courseiddump($dom,
16097: $filter->{'descriptfilter'},
16098: $timefilter,
16099: $instcodefilter,
16100: $filter->{'combownerfilter'},
16101: $filter->{'coursefilter'},
16102: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 16103: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 16104: $filter->{'cloneableonly'},
16105: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 16106: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 16107: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16108: my $ccrole;
16109: if ($type eq 'Community') {
16110: $ccrole = 'co';
16111: } else {
16112: $ccrole = 'cc';
16113: }
16114: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16115: $filter->{'persondomfilter'},
16116: 'userroles',undef,
16117: [$ccrole,'in','ad','ep','ta','cr'],
16118: $dom);
16119: foreach my $role (keys(%rolehash)) {
16120: my ($cnum,$cdom,$courserole) = split(':',$role);
16121: my $cid = $cdom.'_'.$cnum;
16122: if (exists($courses{$cid})) {
16123: if (ref($courses{$cid}) eq 'HASH') {
16124: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16125: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 16126: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 16127: }
16128: } else {
16129: $courses{$cid}{roles} = [$courserole];
16130: }
16131: $showcourses{$cid} = $courses{$cid};
16132: }
16133: }
16134: }
16135: %courses = %showcourses;
16136: }
16137: return %courses;
16138: }
16139:
16140: =pod
16141:
16142: =back
16143:
1.1075.2.88 raeburn 16144: =head1 Routines for version requirements for current course.
16145:
16146: =over 4
16147:
16148: =item * &check_release_required()
16149:
16150: Compares required LON-CAPA version with version on server, and
16151: if required version is newer looks for a server with the required version.
16152:
16153: Looks first at servers in user's owen domain; if none suitable, looks at
16154: servers in course's domain are permitted to host sessions for user's domain.
16155:
16156: Inputs:
16157:
16158: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16159:
16160: $courseid - Course ID of current course
16161:
16162: $rolecode - User's current role in course (for switchserver query string).
16163:
16164: $required - LON-CAPA version needed by course (format: Major.Minor).
16165:
16166:
16167: Returns:
16168:
16169: $switchserver - query string tp append to /adm/switchserver call (if
16170: current server's LON-CAPA version is too old.
16171:
16172: $warning - Message is displayed if no suitable server could be found.
16173:
16174: =cut
16175:
16176: sub check_release_required {
16177: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16178: my ($switchserver,$warning);
16179: if ($required ne '') {
16180: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16181: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16182: if ($reqdmajor ne '' && $reqdminor ne '') {
16183: my $otherserver;
16184: if (($major eq '' && $minor eq '') ||
16185: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16186: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16187: my $switchlcrev =
16188: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16189: $userdomserver);
16190: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16191: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16192: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16193: my $cdom = $env{'course.'.$courseid.'.domain'};
16194: if ($cdom ne $env{'user.domain'}) {
16195: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16196: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16197: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16198: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16199: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16200: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16201: my $canhost =
16202: &Apache::lonnet::can_host_session($env{'user.domain'},
16203: $coursedomserver,
16204: $remoterev,
16205: $udomdefaults{'remotesessions'},
16206: $defdomdefaults{'hostedsessions'});
16207:
16208: if ($canhost) {
16209: $otherserver = $coursedomserver;
16210: } else {
16211: $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.");
16212: }
16213: } else {
16214: $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).");
16215: }
16216: } else {
16217: $otherserver = $userdomserver;
16218: }
16219: }
16220: if ($otherserver ne '') {
16221: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16222: }
16223: }
16224: }
16225: return ($switchserver,$warning);
16226: }
16227:
16228: =pod
16229:
16230: =item * &check_release_result()
16231:
16232: Inputs:
16233:
16234: $switchwarning - Warning message if no suitable server found to host session.
16235:
16236: $switchserver - query string to append to /adm/switchserver containing lonHostID
16237: and current role.
16238:
16239: Returns: HTML to display with information about requirement to switch server.
16240: Either displaying warning with link to Roles/Courses screen or
16241: display link to switchserver.
16242:
1.1075.2.69 raeburn 16243: =cut
16244:
1.1075.2.88 raeburn 16245: sub check_release_result {
16246: my ($switchwarning,$switchserver) = @_;
16247: my $output = &start_page('Selected course unavailable on this server').
16248: '<p class="LC_warning">';
16249: if ($switchwarning) {
16250: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16251: if (&show_course()) {
16252: $output .= &mt('Display courses');
16253: } else {
16254: $output .= &mt('Display roles');
16255: }
16256: $output .= '</a>';
16257: } elsif ($switchserver) {
16258: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16259: '<br />'.
16260: '<a href="/adm/switchserver?'.$switchserver.'">'.
16261: &mt('Switch Server').
16262: '</a>';
16263: }
16264: $output .= '</p>'.&end_page();
16265: return $output;
16266: }
16267:
16268: =pod
16269:
16270: =item * &needs_coursereinit()
16271:
16272: Determine if course contents stored for user's session needs to be
16273: refreshed, because content has changed since "Big Hash" last tied.
16274:
16275: Check for change is made if time last checked is more than 10 minutes ago
16276: (by default).
16277:
16278: Inputs:
16279:
16280: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16281:
16282: $interval (optional) - Time which may elapse (in s) between last check for content
16283: change in current course. (default: 600 s).
16284:
16285: Returns: an array; first element is:
16286:
16287: =over 4
16288:
16289: 'switch' - if content updates mean user's session
16290: needs to be switched to a server running a newer LON-CAPA version
16291:
16292: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16293: on current server hosting user's session
16294:
16295: '' - if no action required.
16296:
16297: =back
16298:
16299: If first item element is 'switch':
16300:
16301: second item is $switchwarning - Warning message if no suitable server found to host session.
16302:
16303: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16304: and current role.
16305:
16306: otherwise: no other elements returned.
16307:
16308: =back
16309:
16310: =cut
16311:
16312: sub needs_coursereinit {
16313: my ($loncaparev,$interval) = @_;
16314: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16315: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16316: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16317: my $now = time;
16318: if ($interval eq '') {
16319: $interval = 600;
16320: }
16321: if (($now-$env{'request.course.timechecked'})>$interval) {
16322: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16323: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16324: if ($lastchange > $env{'request.course.tied'}) {
16325: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16326: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16327: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16328: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16329: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16330: $curr_reqd_hash{'internal.releaserequired'}});
16331: my ($switchserver,$switchwarning) =
16332: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16333: $curr_reqd_hash{'internal.releaserequired'});
16334: if ($switchwarning ne '' || $switchserver ne '') {
16335: return ('switch',$switchwarning,$switchserver);
16336: }
16337: }
16338: }
16339: return ('update');
16340: }
16341: }
16342: return ();
16343: }
1.1075.2.69 raeburn 16344:
1.1075.2.11 raeburn 16345: sub update_content_constraints {
16346: my ($cdom,$cnum,$chome,$cid) = @_;
16347: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16348: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16349: my %checkresponsetypes;
16350: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
16351: my ($item,$name,$value) = split(/:/,$key);
16352: if ($item eq 'resourcetag') {
16353: if ($name eq 'responsetype') {
16354: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16355: }
16356: }
16357: }
16358: my $navmap = Apache::lonnavmaps::navmap->new();
16359: if (defined($navmap)) {
16360: my %allresponses;
16361: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16362: my %responses = $res->responseTypes();
16363: foreach my $key (keys(%responses)) {
16364: next unless(exists($checkresponsetypes{$key}));
16365: $allresponses{$key} += $responses{$key};
16366: }
16367: }
16368: foreach my $key (keys(%allresponses)) {
16369: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16370: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16371: ($reqdmajor,$reqdminor) = ($major,$minor);
16372: }
16373: }
16374: undef($navmap);
16375: }
16376: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16377: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16378: }
16379: return;
16380: }
16381:
1.1075.2.27 raeburn 16382: sub allmaps_incourse {
16383: my ($cdom,$cnum,$chome,$cid) = @_;
16384: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16385: $cid = $env{'request.course.id'};
16386: $cdom = $env{'course.'.$cid.'.domain'};
16387: $cnum = $env{'course.'.$cid.'.num'};
16388: $chome = $env{'course.'.$cid.'.home'};
16389: }
16390: my %allmaps = ();
16391: my $lastchange =
16392: &Apache::lonnet::get_coursechange($cdom,$cnum);
16393: if ($lastchange > $env{'request.course.tied'}) {
16394: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16395: unless ($ferr) {
16396: &update_content_constraints($cdom,$cnum,$chome,$cid);
16397: }
16398: }
16399: my $navmap = Apache::lonnavmaps::navmap->new();
16400: if (defined($navmap)) {
16401: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16402: $allmaps{$res->src()} = 1;
16403: }
16404: }
16405: return \%allmaps;
16406: }
16407:
1.1075.2.11 raeburn 16408: sub parse_supplemental_title {
16409: my ($title) = @_;
16410:
16411: my ($foldertitle,$renametitle);
16412: if ($title =~ /&&&/) {
16413: $title = &HTML::Entites::decode($title);
16414: }
16415: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16416: $renametitle=$4;
16417: my ($time,$uname,$udom) = ($1,$2,$3);
16418: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16419: my $name = &plainname($uname,$udom);
16420: $name = &HTML::Entities::encode($name,'"<>&\'');
16421: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16422: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16423: $name.': <br />'.$foldertitle;
16424: }
16425: if (wantarray) {
16426: return ($title,$foldertitle,$renametitle);
16427: }
16428: return $title;
16429: }
16430:
1.1075.2.43 raeburn 16431: sub recurse_supplemental {
16432: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16433: if ($suppmap) {
16434: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16435: if ($fatal) {
16436: $errors ++;
16437: } else {
16438: if ($#LONCAPA::map::resources > 0) {
16439: foreach my $res (@LONCAPA::map::resources) {
16440: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16441: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 16442: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16443: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 16444: } else {
16445: $numfiles ++;
16446: }
16447: }
16448: }
16449: }
16450: }
16451: }
16452: return ($numfiles,$errors);
16453: }
16454:
1.1075.2.18 raeburn 16455: sub symb_to_docspath {
1.1075.2.119 raeburn 16456: my ($symb,$navmapref) = @_;
16457: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 16458: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16459: if ($resurl=~/\.(sequence|page)$/) {
16460: $mapurl=$resurl;
16461: } elsif ($resurl eq 'adm/navmaps') {
16462: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
16463: }
16464: my $mapresobj;
1.1075.2.119 raeburn 16465: unless (ref($$navmapref)) {
16466: $$navmapref = Apache::lonnavmaps::navmap->new();
16467: }
16468: if (ref($$navmapref)) {
16469: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 16470: }
16471: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
16472: my $type=$2;
16473: my $path;
16474: if (ref($mapresobj)) {
16475: my $pcslist = $mapresobj->map_hierarchy();
16476: if ($pcslist ne '') {
16477: foreach my $pc (split(/,/,$pcslist)) {
16478: next if ($pc <= 1);
1.1075.2.119 raeburn 16479: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 16480: if (ref($res)) {
16481: my $thisurl = $res->src();
16482: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
16483: my $thistitle = $res->title();
16484: $path .= '&'.
16485: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 16486: &escape($thistitle).
1.1075.2.18 raeburn 16487: ':'.$res->randompick().
16488: ':'.$res->randomout().
16489: ':'.$res->encrypted().
16490: ':'.$res->randomorder().
16491: ':'.$res->is_page();
16492: }
16493: }
16494: }
16495: $path =~ s/^\&//;
16496: my $maptitle = $mapresobj->title();
16497: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16498: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16499: }
16500: $path .= (($path ne '')? '&' : '').
16501: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16502: &escape($maptitle).
1.1075.2.18 raeburn 16503: ':'.$mapresobj->randompick().
16504: ':'.$mapresobj->randomout().
16505: ':'.$mapresobj->encrypted().
16506: ':'.$mapresobj->randomorder().
16507: ':'.$mapresobj->is_page();
16508: } else {
16509: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16510: my $ispage = (($type eq 'page')? 1 : '');
16511: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16512: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16513: }
16514: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16515: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 16516: }
16517: unless ($mapurl eq 'default') {
16518: $path = 'default&'.
1.1075.2.46 raeburn 16519: &escape('Main Content').
1.1075.2.18 raeburn 16520: ':::::&'.$path;
16521: }
16522: return $path;
16523: }
16524:
1.1075.2.14 raeburn 16525: sub captcha_display {
16526: my ($context,$lonhost) = @_;
16527: my ($output,$error);
1.1075.2.107 raeburn 16528: my ($captcha,$pubkey,$privkey,$version) =
16529: &get_captcha_config($context,$lonhost);
1.1075.2.14 raeburn 16530: if ($captcha eq 'original') {
16531: $output = &create_captcha();
16532: unless ($output) {
16533: $error = 'captcha';
16534: }
16535: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16536: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 16537: unless ($output) {
16538: $error = 'recaptcha';
16539: }
16540: }
1.1075.2.107 raeburn 16541: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 16542: }
16543:
16544: sub captcha_response {
16545: my ($context,$lonhost) = @_;
16546: my ($captcha_chk,$captcha_error);
1.1075.2.109 raeburn 16547: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1075.2.14 raeburn 16548: if ($captcha eq 'original') {
16549: ($captcha_chk,$captcha_error) = &check_captcha();
16550: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16551: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 16552: } else {
16553: $captcha_chk = 1;
16554: }
16555: return ($captcha_chk,$captcha_error);
16556: }
16557:
16558: sub get_captcha_config {
16559: my ($context,$lonhost) = @_;
1.1075.2.107 raeburn 16560: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 16561: my $hostname = &Apache::lonnet::hostname($lonhost);
16562: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
16563: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16564: if ($context eq 'usercreation') {
16565: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
16566: if (ref($domconfig{$context}) eq 'HASH') {
16567: $hashtocheck = $domconfig{$context}{'cancreate'};
16568: if (ref($hashtocheck) eq 'HASH') {
16569: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
16570: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
16571: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
16572: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
16573: }
16574: if ($privkey && $pubkey) {
16575: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16576: $version = $hashtocheck->{'recaptchaversion'};
16577: if ($version ne '2') {
16578: $version = 1;
16579: }
1.1075.2.14 raeburn 16580: } else {
16581: $captcha = 'original';
16582: }
16583: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
16584: $captcha = 'original';
16585: }
16586: }
16587: } else {
16588: $captcha = 'captcha';
16589: }
16590: } elsif ($context eq 'login') {
16591: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
16592: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
16593: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
16594: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
16595: if ($privkey && $pubkey) {
16596: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16597: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
16598: if ($version ne '2') {
16599: $version = 1;
16600: }
1.1075.2.14 raeburn 16601: } else {
16602: $captcha = 'original';
16603: }
16604: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
16605: $captcha = 'original';
16606: }
16607: }
1.1075.2.107 raeburn 16608: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 16609: }
16610:
16611: sub create_captcha {
16612: my %captcha_params = &captcha_settings();
16613: my ($output,$maxtries,$tries) = ('',10,0);
16614: while ($tries < $maxtries) {
16615: $tries ++;
16616: my $captcha = Authen::Captcha->new (
16617: output_folder => $captcha_params{'output_dir'},
16618: data_folder => $captcha_params{'db_dir'},
16619: );
16620: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
16621:
16622: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
16623: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
16624: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 16625: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
16626: '<br />'.
16627: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 16628: last;
16629: }
16630: }
16631: return $output;
16632: }
16633:
16634: sub captcha_settings {
16635: my %captcha_params = (
16636: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
16637: www_output_dir => "/captchaspool",
16638: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
16639: numchars => '5',
16640: );
16641: return %captcha_params;
16642: }
16643:
16644: sub check_captcha {
16645: my ($captcha_chk,$captcha_error);
16646: my $code = $env{'form.code'};
16647: my $md5sum = $env{'form.crypt'};
16648: my %captcha_params = &captcha_settings();
16649: my $captcha = Authen::Captcha->new(
16650: output_folder => $captcha_params{'output_dir'},
16651: data_folder => $captcha_params{'db_dir'},
16652: );
1.1075.2.26 raeburn 16653: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 16654: my %captcha_hash = (
16655: 0 => 'Code not checked (file error)',
16656: -1 => 'Failed: code expired',
16657: -2 => 'Failed: invalid code (not in database)',
16658: -3 => 'Failed: invalid code (code does not match crypt)',
16659: );
16660: if ($captcha_chk != 1) {
16661: $captcha_error = $captcha_hash{$captcha_chk}
16662: }
16663: return ($captcha_chk,$captcha_error);
16664: }
16665:
16666: sub create_recaptcha {
1.1075.2.107 raeburn 16667: my ($pubkey,$version) = @_;
16668: if ($version >= 2) {
16669: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
16670: } else {
16671: my $use_ssl;
16672: if ($ENV{'SERVER_PORT'} == 443) {
16673: $use_ssl = 1;
16674: }
16675: my $captcha = Captcha::reCAPTCHA->new;
16676: return $captcha->get_options_setter({theme => 'white'})."\n".
16677: $captcha->get_html($pubkey,undef,$use_ssl).
16678: &mt('If the text is hard to read, [_1] will replace them.',
16679: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
16680: '<br /><br />';
16681: }
1.1075.2.14 raeburn 16682: }
16683:
16684: sub check_recaptcha {
1.1075.2.107 raeburn 16685: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 16686: my $captcha_chk;
1.1075.2.107 raeburn 16687: if ($version >= 2) {
16688: my $ua = LWP::UserAgent->new;
16689: $ua->timeout(10);
16690: my %info = (
16691: secret => $privkey,
16692: response => $env{'form.g-recaptcha-response'},
16693: remoteip => $ENV{'REMOTE_ADDR'},
16694: );
16695: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
16696: if ($response->is_success) {
16697: my $data = JSON::DWIW->from_json($response->decoded_content);
16698: if (ref($data) eq 'HASH') {
16699: if ($data->{'success'}) {
16700: $captcha_chk = 1;
16701: }
16702: }
16703: }
16704: } else {
16705: my $captcha = Captcha::reCAPTCHA->new;
16706: my $captcha_result =
16707: $captcha->check_answer(
16708: $privkey,
16709: $ENV{'REMOTE_ADDR'},
16710: $env{'form.recaptcha_challenge_field'},
16711: $env{'form.recaptcha_response_field'},
16712: );
16713: if ($captcha_result->{is_valid}) {
16714: $captcha_chk = 1;
16715: }
1.1075.2.14 raeburn 16716: }
16717: return $captcha_chk;
16718: }
16719:
1.1075.2.64 raeburn 16720: sub emailusername_info {
1.1075.2.103 raeburn 16721: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 16722: my %titles = &Apache::lonlocal::texthash (
16723: lastname => 'Last Name',
16724: firstname => 'First Name',
16725: institution => 'School/college/university',
16726: location => "School's city, state/province, country",
16727: web => "School's web address",
16728: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 16729: id => 'Student/Employee ID',
1.1075.2.64 raeburn 16730: );
16731: return (\@fields,\%titles);
16732: }
16733:
1.1075.2.56 raeburn 16734: sub cleanup_html {
16735: my ($incoming) = @_;
16736: my $outgoing;
16737: if ($incoming ne '') {
16738: $outgoing = $incoming;
16739: $outgoing =~ s/;/;/g;
16740: $outgoing =~ s/\#/#/g;
16741: $outgoing =~ s/\&/&/g;
16742: $outgoing =~ s/</</g;
16743: $outgoing =~ s/>/>/g;
16744: $outgoing =~ s/\(/(/g;
16745: $outgoing =~ s/\)/)/g;
16746: $outgoing =~ s/"/"/g;
16747: $outgoing =~ s/'/'/g;
16748: $outgoing =~ s/\$/$/g;
16749: $outgoing =~ s{/}{/}g;
16750: $outgoing =~ s/=/=/g;
16751: $outgoing =~ s/\\/\/g
16752: }
16753: return $outgoing;
16754: }
16755:
1.1075.2.74 raeburn 16756: # Checks for critical messages and returns a redirect url if one exists.
16757: # $interval indicates how often to check for messages.
16758: sub critical_redirect {
16759: my ($interval) = @_;
16760: if ((time-$env{'user.criticalcheck.time'})>$interval) {
16761: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
16762: $env{'user.name'});
16763: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
16764: my $redirecturl;
16765: if ($what[0]) {
16766: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
16767: $redirecturl='/adm/email?critical=display';
16768: my $url=&Apache::lonnet::absolute_url().$redirecturl;
16769: return (1, $url);
16770: }
16771: }
16772: }
16773: return ();
16774: }
16775:
1.1075.2.64 raeburn 16776: # Use:
16777: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
16778: #
16779: ##################################################
16780: # password associated functions #
16781: ##################################################
16782: sub des_keys {
16783: # Make a new key for DES encryption.
16784: # Each key has two parts which are returned separately.
16785: # Please note: Each key must be passed through the &hex function
16786: # before it is output to the web browser. The hex versions cannot
16787: # be used to decrypt.
16788: my @hexstr=('0','1','2','3','4','5','6','7',
16789: '8','9','a','b','c','d','e','f');
16790: my $lkey='';
16791: for (0..7) {
16792: $lkey.=$hexstr[rand(15)];
16793: }
16794: my $ukey='';
16795: for (0..7) {
16796: $ukey.=$hexstr[rand(15)];
16797: }
16798: return ($lkey,$ukey);
16799: }
16800:
16801: sub des_decrypt {
16802: my ($key,$cyphertext) = @_;
16803: my $keybin=pack("H16",$key);
16804: my $cypher;
16805: if ($Crypt::DES::VERSION>=2.03) {
16806: $cypher=new Crypt::DES $keybin;
16807: } else {
16808: $cypher=new DES $keybin;
16809: }
1.1075.2.106 raeburn 16810: my $plaintext='';
16811: my $cypherlength = length($cyphertext);
16812: my $numchunks = int($cypherlength/32);
16813: for (my $j=0; $j<$numchunks; $j++) {
16814: my $start = $j*32;
16815: my $cypherblock = substr($cyphertext,$start,32);
16816: my $chunk =
16817: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
16818: $chunk .=
16819: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
16820: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
16821: $plaintext .= $chunk;
16822: }
1.1075.2.64 raeburn 16823: return $plaintext;
16824: }
16825:
1.112 bowersj2 16826: 1;
16827: __END__;
1.41 ng 16828:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>