Annotation of loncom/interface/loncommon.pm, revision 1.1075.2.127.6.1
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. .1(raebu 4:19): # $Id: loncommon.pm,v 1.1075.2.127 2017/04/02 03:09:27 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: }
1.1075.2.127. .1(raebu 4949:19): my $allowed;
1.1075.2.111 raeburn 4950: my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682 raeburn 4951:
4952: my $name;
1.1075.2.127. .1(raebu 4953:19): my %access = (
4954:19): allowfrom => 1,
4955:19): denyfrom => 0,
4956:19): );
4957:19): my @allows;
4958:19): my @denies;
4959:19): foreach my $item (split(',',$acc)) {
4960:19): $item =~ s/^\s*//;
4961:19): $item =~ s/\s*$//;
4962:19): if ($item =~ /^\!(.+)$/) {
4963:19): push(@denies,$1);
4964:19): } else {
4965:19): push(@allows,$item);
4966:19): }
4967:19): }
4968:19): my $numdenies = scalar(@denies);
4969:19): my $numallows = scalar(@allows);
4970:19): my $count = 0;
4971:19): foreach my $pattern (@denies,@allows) {
4972:19): $count ++;
4973:19): my $acctype = 'allowfrom';
4974:19): if ($count <= $numdenies) {
4975:19): $acctype = 'denyfrom';
4976:19): }
1.682 raeburn 4977: if ($pattern =~ /\*$/) {
4978: #35.8.*
4979: $pattern=~s/\*//;
1.1075.2.127. .1(raebu 4980:19): if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 4981: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4982: #35.8.3.[34-56]
4983: my $low=$2;
4984: my $high=$3;
4985: $pattern=$1;
4986: if ($ip =~ /^\Q$pattern\E/) {
4987: my $last=(split(/\./,$ip))[3];
1.1075.2.127. .1(raebu 4988:19): if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 4989: }
4990: } elsif ($pattern =~ /^\*/) {
4991: #*.msu.edu
4992: $pattern=~s/\*//;
4993: if (!defined($name)) {
4994: use Socket;
4995: my $netaddr=inet_aton($ip);
4996: ($name)=gethostbyaddr($netaddr,AF_INET);
4997: }
1.1075.2.127. .1(raebu 4998:19): if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 4999: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5000: #127.0.0.1
1.1075.2.127. .1(raebu 5001:19): if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5002: } else {
5003: #some.name.com
5004: if (!defined($name)) {
5005: use Socket;
5006: my $netaddr=inet_aton($ip);
5007: ($name)=gethostbyaddr($netaddr,AF_INET);
5008: }
1.1075.2.127. .1(raebu 5009:19): if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5010:19): }
5011:19): if ($allowed =~ /^(0|1)$/) { last; }
5012:19): }
5013:19): if ($allowed eq '') {
5014:19): if ($numdenies && !$numallows) {
5015:19): $allowed = 1;
5016:19): } else {
5017:19): $allowed = 0;
1.682 raeburn 5018: }
5019: }
5020: return $allowed;
5021: }
5022:
5023: ###############################################
5024:
1.60 matthew 5025: =pod
5026:
1.112 bowersj2 5027: =head1 Domain Template Functions
5028:
5029: =over 4
5030:
5031: =item * &determinedomain()
1.60 matthew 5032:
5033: Inputs: $domain (usually will be undef)
5034:
1.63 www 5035: Returns: Determines which domain should be used for designs
1.60 matthew 5036:
5037: =cut
1.54 www 5038:
1.60 matthew 5039: ###############################################
1.63 www 5040: sub determinedomain {
5041: my $domain=shift;
1.531 albertel 5042: if (! $domain) {
1.60 matthew 5043: # Determine domain if we have not been given one
1.893 raeburn 5044: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5045: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5046: if ($env{'request.role.domain'}) {
5047: $domain=$env{'request.role.domain'};
1.60 matthew 5048: }
5049: }
1.63 www 5050: return $domain;
5051: }
5052: ###############################################
1.517 raeburn 5053:
1.518 albertel 5054: sub devalidate_domconfig_cache {
5055: my ($udom)=@_;
5056: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5057: }
5058:
5059: # ---------------------- Get domain configuration for a domain
5060: sub get_domainconf {
5061: my ($udom) = @_;
5062: my $cachetime=1800;
5063: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5064: if (defined($cached)) { return %{$result}; }
5065:
5066: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5067: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5068: my (%designhash,%legacy);
1.518 albertel 5069: if (keys(%domconfig) > 0) {
5070: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5071: if (keys(%{$domconfig{'login'}})) {
5072: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5073: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1075.2.87 raeburn 5074: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5075: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5076: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5077: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5078: if ($key eq 'loginvia') {
5079: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5080: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5081: $designhash{$udom.'.login.loginvia'} = $server;
5082: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5083: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5084: } else {
5085: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5086: }
1.948 raeburn 5087: }
1.1075.2.87 raeburn 5088: } elsif ($key eq 'headtag') {
5089: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5090: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5091: }
1.946 raeburn 5092: }
1.1075.2.87 raeburn 5093: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5094: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5095: }
1.946 raeburn 5096: }
5097: }
5098: }
5099: } else {
5100: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5101: $designhash{$udom.'.login.'.$key.'_'.$img} =
5102: $domconfig{'login'}{$key}{$img};
5103: }
1.699 raeburn 5104: }
5105: } else {
5106: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5107: }
1.632 raeburn 5108: }
5109: } else {
5110: $legacy{'login'} = 1;
1.518 albertel 5111: }
1.632 raeburn 5112: } else {
5113: $legacy{'login'} = 1;
1.518 albertel 5114: }
5115: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5116: if (keys(%{$domconfig{'rolecolors'}})) {
5117: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5118: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5119: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5120: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5121: }
1.518 albertel 5122: }
5123: }
1.632 raeburn 5124: } else {
5125: $legacy{'rolecolors'} = 1;
1.518 albertel 5126: }
1.632 raeburn 5127: } else {
5128: $legacy{'rolecolors'} = 1;
1.518 albertel 5129: }
1.948 raeburn 5130: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5131: if ($domconfig{'autoenroll'}{'co-owners'}) {
5132: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5133: }
5134: }
1.632 raeburn 5135: if (keys(%legacy) > 0) {
5136: my %legacyhash = &get_legacy_domconf($udom);
5137: foreach my $item (keys(%legacyhash)) {
5138: if ($item =~ /^\Q$udom\E\.login/) {
5139: if ($legacy{'login'}) {
5140: $designhash{$item} = $legacyhash{$item};
5141: }
5142: } else {
5143: if ($legacy{'rolecolors'}) {
5144: $designhash{$item} = $legacyhash{$item};
5145: }
1.518 albertel 5146: }
5147: }
5148: }
1.632 raeburn 5149: } else {
5150: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5151: }
5152: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5153: $cachetime);
5154: return %designhash;
5155: }
5156:
1.632 raeburn 5157: sub get_legacy_domconf {
5158: my ($udom) = @_;
5159: my %legacyhash;
5160: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5161: my $designfile = $designdir.'/'.$udom.'.tab';
5162: if (-e $designfile) {
5163: if ( open (my $fh,"<$designfile") ) {
5164: while (my $line = <$fh>) {
5165: next if ($line =~ /^\#/);
5166: chomp($line);
5167: my ($key,$val)=(split(/\=/,$line));
5168: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5169: }
5170: close($fh);
5171: }
5172: }
1.1026 raeburn 5173: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5174: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5175: }
5176: return %legacyhash;
5177: }
5178:
1.63 www 5179: =pod
5180:
1.112 bowersj2 5181: =item * &domainlogo()
1.63 www 5182:
5183: Inputs: $domain (usually will be undef)
5184:
5185: Returns: A link to a domain logo, if the domain logo exists.
5186: If the domain logo does not exist, a description of the domain.
5187:
5188: =cut
1.112 bowersj2 5189:
1.63 www 5190: ###############################################
5191: sub domainlogo {
1.517 raeburn 5192: my $domain = &determinedomain(shift);
1.518 albertel 5193: my %designhash = &get_domainconf($domain);
1.517 raeburn 5194: # See if there is a logo
5195: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5196: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5197: if ($imgsrc =~ m{^/(adm|res)/}) {
5198: if ($imgsrc =~ m{^/res/}) {
5199: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5200: &Apache::lonnet::repcopy($local_name);
5201: }
5202: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5203: }
5204: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5205: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5206: return &Apache::lonnet::domain($domain,'description');
1.59 www 5207: } else {
1.60 matthew 5208: return '';
1.59 www 5209: }
5210: }
1.63 www 5211: ##############################################
5212:
5213: =pod
5214:
1.112 bowersj2 5215: =item * &designparm()
1.63 www 5216:
5217: Inputs: $which parameter; $domain (usually will be undef)
5218:
5219: Returns: value of designparamter $which
5220:
5221: =cut
1.112 bowersj2 5222:
1.397 albertel 5223:
1.400 albertel 5224: ##############################################
1.397 albertel 5225: sub designparm {
5226: my ($which,$domain)=@_;
5227: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5228: return $env{'environment.color.'.$which};
1.96 www 5229: }
1.63 www 5230: $domain=&determinedomain($domain);
1.1016 raeburn 5231: my %domdesign;
5232: unless ($domain eq 'public') {
5233: %domdesign = &get_domainconf($domain);
5234: }
1.520 raeburn 5235: my $output;
1.517 raeburn 5236: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5237: $output = $domdesign{$domain.'.'.$which};
1.63 www 5238: } else {
1.520 raeburn 5239: $output = $defaultdesign{$which};
5240: }
5241: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5242: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5243: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5244: if ($output =~ m{^/res/}) {
5245: my $local_name = &Apache::lonnet::filelocation('',$output);
5246: &Apache::lonnet::repcopy($local_name);
5247: }
1.520 raeburn 5248: $output = &lonhttpdurl($output);
5249: }
1.63 www 5250: }
1.520 raeburn 5251: return $output;
1.63 www 5252: }
1.59 www 5253:
1.822 bisitz 5254: ##############################################
5255: =pod
5256:
1.832 bisitz 5257: =item * &authorspace()
5258:
1.1028 raeburn 5259: Inputs: $url (usually will be undef).
1.832 bisitz 5260:
1.1075.2.40 raeburn 5261: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5262: directory being viewed (or for which action is being taken).
5263: If $url is provided, and begins /priv/<domain>/<uname>
5264: the path will be that portion of the $context argument.
5265: Otherwise the path will be for the author space of the current
5266: user when the current role is author, or for that of the
5267: co-author/assistant co-author space when the current role
5268: is co-author or assistant co-author.
1.832 bisitz 5269:
5270: =cut
5271:
5272: sub authorspace {
1.1028 raeburn 5273: my ($url) = @_;
5274: if ($url ne '') {
5275: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5276: return $1;
5277: }
5278: }
1.832 bisitz 5279: my $caname = '';
1.1024 www 5280: my $cadom = '';
1.1028 raeburn 5281: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5282: ($cadom,$caname) =
1.832 bisitz 5283: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5284: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5285: $caname = $env{'user.name'};
1.1024 www 5286: $cadom = $env{'user.domain'};
1.832 bisitz 5287: }
1.1028 raeburn 5288: if (($caname ne '') && ($cadom ne '')) {
5289: return "/priv/$cadom/$caname/";
5290: }
5291: return;
1.832 bisitz 5292: }
5293:
5294: ##############################################
5295: =pod
5296:
1.822 bisitz 5297: =item * &head_subbox()
5298:
5299: Inputs: $content (contains HTML code with page functions, etc.)
5300:
5301: Returns: HTML div with $content
5302: To be included in page header
5303:
5304: =cut
5305:
5306: sub head_subbox {
5307: my ($content)=@_;
5308: my $output =
1.993 raeburn 5309: '<div class="LC_head_subbox">'
1.822 bisitz 5310: .$content
5311: .'</div>'
5312: }
5313:
5314: ##############################################
5315: =pod
5316:
5317: =item * &CSTR_pageheader()
5318:
1.1026 raeburn 5319: Input: (optional) filename from which breadcrumb trail is built.
5320: In most cases no input as needed, as $env{'request.filename'}
5321: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5322:
5323: Returns: HTML div with CSTR path and recent box
1.1075.2.40 raeburn 5324: To be included on Authoring Space pages
1.822 bisitz 5325:
5326: =cut
5327:
5328: sub CSTR_pageheader {
1.1026 raeburn 5329: my ($trailfile) = @_;
5330: if ($trailfile eq '') {
5331: $trailfile = $env{'request.filename'};
5332: }
5333:
5334: # this is for resources; directories have customtitle, and crumbs
5335: # and select recent are created in lonpubdir.pm
5336:
5337: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5338: my ($udom,$uname,$thisdisfn)=
1.1075.2.29 raeburn 5339: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5340: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5341: $formaction =~ s{/+}{/}g;
1.822 bisitz 5342:
5343: my $parentpath = '';
5344: my $lastitem = '';
5345: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5346: $parentpath = $1;
5347: $lastitem = $2;
5348: } else {
5349: $lastitem = $thisdisfn;
5350: }
1.921 bisitz 5351:
5352: my $output =
1.822 bisitz 5353: '<div>'
5354: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1075.2.40 raeburn 5355: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5356: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5357: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5358: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5359:
5360: if ($lastitem) {
5361: $output .=
5362: '<span class="LC_filename">'
5363: .$lastitem
5364: .'</span>';
5365: }
5366: $output .=
5367: '<br />'
1.822 bisitz 5368: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5369: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5370: .'</form>'
5371: .&Apache::lonmenu::constspaceform()
5372: .'</div>';
1.921 bisitz 5373:
5374: return $output;
1.822 bisitz 5375: }
5376:
1.60 matthew 5377: ###############################################
5378: ###############################################
5379:
5380: =pod
5381:
1.112 bowersj2 5382: =back
5383:
1.549 albertel 5384: =head1 HTML Helpers
1.112 bowersj2 5385:
5386: =over 4
5387:
5388: =item * &bodytag()
1.60 matthew 5389:
5390: Returns a uniform header for LON-CAPA web pages.
5391:
5392: Inputs:
5393:
1.112 bowersj2 5394: =over 4
5395:
5396: =item * $title, A title to be displayed on the page.
5397:
5398: =item * $function, the current role (can be undef).
5399:
5400: =item * $addentries, extra parameters for the <body> tag.
5401:
5402: =item * $bodyonly, if defined, only return the <body> tag.
5403:
5404: =item * $domain, if defined, force a given domain.
5405:
5406: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5407: text interface only)
1.60 matthew 5408:
1.814 bisitz 5409: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5410: navigational links
1.317 albertel 5411:
1.338 albertel 5412: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5413:
1.1075.2.12 raeburn 5414: =item * $no_inline_link, if true and in remote mode, don't show the
5415: 'Switch To Inline Menu' link
5416:
1.460 albertel 5417: =item * $args, optional argument valid values are
5418: no_auto_mt_title -> prevents &mt()ing the title arg
5419:
1.1075.2.15 raeburn 5420: =item * $advtoolsref, optional argument, ref to an array containing
5421: inlineremote items to be added in "Functions" menu below
5422: breadcrumbs.
5423:
1.112 bowersj2 5424: =back
5425:
1.60 matthew 5426: Returns: A uniform header for LON-CAPA web pages.
5427: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5428: If $bodyonly is undef or zero, an html string containing a <body> tag and
5429: other decorations will be returned.
5430:
5431: =cut
5432:
1.54 www 5433: sub bodytag {
1.831 bisitz 5434: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1075.2.15 raeburn 5435: $no_nav_bar,$bgcolor,$no_inline_link,$args,$advtoolsref)=@_;
1.339 albertel 5436:
1.954 raeburn 5437: my $public;
5438: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5439: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5440: $public = 1;
5441: }
1.460 albertel 5442: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1075.2.52 raeburn 5443: my $httphost = $args->{'use_absolute'};
1.339 albertel 5444:
1.183 matthew 5445: $function = &get_users_function() if (!$function);
1.339 albertel 5446: my $img = &designparm($function.'.img',$domain);
5447: my $font = &designparm($function.'.font',$domain);
5448: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5449:
1.803 bisitz 5450: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5451: 'bgcolor' => $pgbg,
1.339 albertel 5452: 'text' => $font,
5453: 'alink' => &designparm($function.'.alink',$domain),
5454: 'vlink' => &designparm($function.'.vlink',$domain),
5455: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5456: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5457:
1.63 www 5458: # role and realm
1.1075.2.68 raeburn 5459: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5460: if ($realm) {
5461: $realm = '/'.$realm;
5462: }
1.378 raeburn 5463: if ($role eq 'ca') {
1.479 albertel 5464: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5465: $realm = &plainname($rname,$rdom);
1.378 raeburn 5466: }
1.55 www 5467: # realm
1.258 albertel 5468: if ($env{'request.course.id'}) {
1.378 raeburn 5469: if ($env{'request.role'} !~ /^cr/) {
5470: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1075.2.115 raeburn 5471: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1075.2.121 raeburn 5472: if ($env{'request.role.desc'}) {
5473: $role = $env{'request.role.desc'};
5474: } else {
5475: $role = &mt('Helpdesk[_1]',' '.$2);
5476: }
1.1075.2.115 raeburn 5477: } else {
5478: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5479: }
1.898 raeburn 5480: if ($env{'request.course.sec'}) {
5481: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5482: }
1.359 albertel 5483: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5484: } else {
5485: $role = &Apache::lonnet::plaintext($role);
1.54 www 5486: }
1.433 albertel 5487:
1.359 albertel 5488: if (!$realm) { $realm=' '; }
1.330 albertel 5489:
1.438 albertel 5490: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5491:
1.101 www 5492: # construct main body tag
1.359 albertel 5493: my $bodytag = "<body $extra_body_attr>".
1.1075.2.100 raeburn 5494: &Apache::lontexconvert::init_math_support();
1.252 albertel 5495:
1.1075.2.38 raeburn 5496: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5497:
5498: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5499: return $bodytag;
1.1075.2.38 raeburn 5500: }
1.359 albertel 5501:
1.954 raeburn 5502: if ($public) {
1.433 albertel 5503: undef($role);
5504: }
1.359 albertel 5505:
1.762 bisitz 5506: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5507: #
5508: # Extra info if you are the DC
5509: my $dc_info = '';
5510: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5511: $env{'course.'.$env{'request.course.id'}.
5512: '.domain'}.'/'})) {
5513: my $cid = $env{'request.course.id'};
1.917 raeburn 5514: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5515: $dc_info =~ s/\s+$//;
1.359 albertel 5516: }
5517:
1.1075.2.108 raeburn 5518: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.903 droeschl 5519:
1.1075.2.13 raeburn 5520: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5521:
1.1075.2.38 raeburn 5522:
5523:
1.1075.2.21 raeburn 5524: my $funclist;
5525: if (($env{'environment.remote'} eq 'on') && ($env{'request.state'} ne 'construct')) {
1.1075.2.52 raeburn 5526: $bodytag .= Apache::lonhtmlcommon::scripttag(Apache::lonmenu::utilityfunctions($httphost), 'start')."\n".
1.1075.2.21 raeburn 5527: Apache::lonmenu::serverform();
5528: my $forbodytag;
5529: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5530: $forcereg,$args->{'group'},
5531: $args->{'bread_crumbs'},
5532: $advtoolsref,'',\$forbodytag);
5533: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5534: $funclist = $forbodytag;
5535: }
5536: } else {
1.903 droeschl 5537:
5538: # if ($env{'request.state'} eq 'construct') {
5539: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5540: # }
5541:
1.1075.2.38 raeburn 5542: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5543: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5544:
1.1075.2.38 raeburn 5545: my ($left,$right) = Apache::lonmenu::primary_menu();
1.1075.2.2 raeburn 5546:
1.916 droeschl 5547: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.1075.2.22 raeburn 5548: if ($dc_info) {
5549: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
1.1075.2.1 raeburn 5550: }
1.1075.2.38 raeburn 5551: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.1075.2.22 raeburn 5552: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5553: return $bodytag;
5554: }
1.894 droeschl 5555:
1.927 raeburn 5556: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1075.2.38 raeburn 5557: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5558: }
1.916 droeschl 5559:
1.1075.2.38 raeburn 5560: $bodytag .= $right;
1.852 droeschl 5561:
1.917 raeburn 5562: if ($dc_info) {
5563: $dc_info = &dc_courseid_toggle($dc_info);
5564: }
5565: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5566:
1.1075.2.61 raeburn 5567: #if directed to not display the secondary menu, don't.
5568: if ($args->{'no_secondary_menu'}) {
5569: return $bodytag;
5570: }
1.903 droeschl 5571: #don't show menus for public users
1.954 raeburn 5572: if (!$public){
1.1075.2.52 raeburn 5573: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5574: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5575: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5576: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5577: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5578: $args->{'bread_crumbs'});
1.1075.2.116 raeburn 5579: } elsif ($forcereg) {
1.1075.2.22 raeburn 5580: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1075.2.116 raeburn 5581: $args->{'group'},
5582: $args->{'hide_buttons'});
1.1075.2.15 raeburn 5583: } else {
1.1075.2.21 raeburn 5584: my $forbodytag;
5585: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5586: $forcereg,$args->{'group'},
5587: $args->{'bread_crumbs'},
5588: $advtoolsref,'',\$forbodytag);
5589: unless (ref($args->{'bread_crumbs'}) eq 'ARRAY') {
5590: $bodytag .= $forbodytag;
5591: }
1.920 raeburn 5592: }
1.903 droeschl 5593: }else{
5594: # this is to seperate menu from content when there's no secondary
5595: # menu. Especially needed for public accessible ressources.
5596: $bodytag .= '<hr style="clear:both" />';
5597: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5598: }
1.903 droeschl 5599:
1.235 raeburn 5600: return $bodytag;
1.1075.2.12 raeburn 5601: }
5602:
5603: #
5604: # Top frame rendering, Remote is up
5605: #
5606:
5607: my $imgsrc = $img;
5608: if ($img =~ /^\/adm/) {
5609: $imgsrc = &lonhttpdurl($img);
5610: }
5611: my $upperleft='<img src="'.$imgsrc.'" alt="'.$function.'" />';
5612:
1.1075.2.60 raeburn 5613: my $help=($no_inline_link?''
5614: :&Apache::loncommon::top_nav_help('Help'));
5615:
1.1075.2.12 raeburn 5616: # Explicit link to get inline menu
5617: my $menu= ($no_inline_link?''
5618: :'<a href="/adm/remote?action=collapse" target="_top">'.&mt('Switch to Inline Menu Mode').'</a>');
5619:
5620: if ($dc_info) {
5621: $dc_info = qq|<span class="LC_cusr_subheading">($dc_info)</span>|;
5622: }
5623:
1.1075.2.38 raeburn 5624: my $name = &plainname($env{'user.name'},$env{'user.domain'});
5625: unless ($public) {
5626: $name = &aboutmewrapper($name,$env{'user.name'},$env{'user.domain'},
5627: undef,'LC_menubuttons_link');
5628: }
5629:
1.1075.2.12 raeburn 5630: unless ($env{'form.inhibitmenu'}) {
5631: $bodytag .= qq|<div id="LC_nav_bar">$name $role</div>
1.1075.2.38 raeburn 5632: <ol class="LC_primary_menu LC_floatright LC_right">
1.1075.2.60 raeburn 5633: <li>$help</li>
1.1075.2.12 raeburn 5634: <li>$menu</li>
5635: </ol><div id="LC_realm"> $realm $dc_info</div>|;
5636: }
1.1075.2.13 raeburn 5637: if ($env{'request.state'} eq 'construct') {
5638: if (!$public){
5639: if ($env{'request.state'} eq 'construct') {
5640: $funclist = &Apache::lonhtmlcommon::scripttag(
1.1075.2.52 raeburn 5641: &Apache::lonmenu::utilityfunctions($httphost), 'start').
1.1075.2.13 raeburn 5642: &Apache::lonhtmlcommon::scripttag('','end').
5643: &Apache::lonmenu::innerregister($forcereg,
5644: $args->{'bread_crumbs'});
5645: }
5646: }
5647: }
1.1075.2.21 raeburn 5648: return $bodytag."\n".$funclist;
1.182 matthew 5649: }
5650:
1.917 raeburn 5651: sub dc_courseid_toggle {
5652: my ($dc_info) = @_;
1.980 raeburn 5653: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5654: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5655: &mt('(More ...)').'</a></span>'.
5656: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5657: }
5658:
1.330 albertel 5659: sub make_attr_string {
5660: my ($register,$attr_ref) = @_;
5661:
5662: if ($attr_ref && !ref($attr_ref)) {
5663: die("addentries Must be a hash ref ".
5664: join(':',caller(1))." ".
5665: join(':',caller(0))." ");
5666: }
5667:
5668: if ($register) {
1.339 albertel 5669: my ($on_load,$on_unload);
5670: foreach my $key (keys(%{$attr_ref})) {
5671: if (lc($key) eq 'onload') {
5672: $on_load.=$attr_ref->{$key}.';';
5673: delete($attr_ref->{$key});
5674:
5675: } elsif (lc($key) eq 'onunload') {
5676: $on_unload.=$attr_ref->{$key}.';';
5677: delete($attr_ref->{$key});
5678: }
5679: }
1.1075.2.12 raeburn 5680: if ($env{'environment.remote'} eq 'on') {
5681: $attr_ref->{'onload'} =
5682: &Apache::lonmenu::loadevents(). $on_load;
5683: $attr_ref->{'onunload'}=
5684: &Apache::lonmenu::unloadevents().$on_unload;
5685: } else {
5686: $attr_ref->{'onload'} = $on_load;
5687: $attr_ref->{'onunload'}= $on_unload;
5688: }
1.330 albertel 5689: }
1.339 albertel 5690:
1.330 albertel 5691: my $attr_string;
1.1075.2.56 raeburn 5692: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5693: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5694: }
5695: return $attr_string;
5696: }
5697:
5698:
1.182 matthew 5699: ###############################################
1.251 albertel 5700: ###############################################
5701:
5702: =pod
5703:
5704: =item * &endbodytag()
5705:
5706: Returns a uniform footer for LON-CAPA web pages.
5707:
1.635 raeburn 5708: Inputs: 1 - optional reference to an args hash
5709: If in the hash, key for noredirectlink has a value which evaluates to true,
5710: a 'Continue' link is not displayed if the page contains an
5711: internal redirect in the <head></head> section,
5712: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5713:
5714: =cut
5715:
5716: sub endbodytag {
1.635 raeburn 5717: my ($args) = @_;
1.1075.2.6 raeburn 5718: my $endbodytag;
5719: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5720: $endbodytag='</body>';
5721: }
1.315 albertel 5722: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5723: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5724: $endbodytag=
5725: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5726: &mt('Continue').'</a>'.
5727: $endbodytag;
5728: }
1.315 albertel 5729: }
1.251 albertel 5730: return $endbodytag;
5731: }
5732:
1.352 albertel 5733: =pod
5734:
5735: =item * &standard_css()
5736:
5737: Returns a style sheet
5738:
5739: Inputs: (all optional)
5740: domain -> force to color decorate a page for a specific
5741: domain
5742: function -> force usage of a specific rolish color scheme
5743: bgcolor -> override the default page bgcolor
5744:
5745: =cut
5746:
1.343 albertel 5747: sub standard_css {
1.345 albertel 5748: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5749: $function = &get_users_function() if (!$function);
5750: my $img = &designparm($function.'.img', $domain);
5751: my $tabbg = &designparm($function.'.tabbg', $domain);
5752: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5753: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5754: #second colour for later usage
1.345 albertel 5755: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5756: my $pgbg_or_bgcolor =
5757: $bgcolor ||
1.352 albertel 5758: &designparm($function.'.pgbg', $domain);
1.382 albertel 5759: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5760: my $alink = &designparm($function.'.alink', $domain);
5761: my $vlink = &designparm($function.'.vlink', $domain);
5762: my $link = &designparm($function.'.link', $domain);
5763:
1.602 albertel 5764: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5765: my $mono = 'monospace';
1.850 bisitz 5766: my $data_table_head = $sidebg;
5767: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5768: my $data_table_dark = '#E0E0E0';
1.470 banghart 5769: my $data_table_darker = '#CCCCCC';
1.349 albertel 5770: my $data_table_highlight = '#FFFF00';
1.352 albertel 5771: my $mail_new = '#FFBB77';
5772: my $mail_new_hover = '#DD9955';
5773: my $mail_read = '#BBBB77';
5774: my $mail_read_hover = '#999944';
5775: my $mail_replied = '#AAAA88';
5776: my $mail_replied_hover = '#888855';
5777: my $mail_other = '#99BBBB';
5778: my $mail_other_hover = '#669999';
1.391 albertel 5779: my $table_header = '#DDDDDD';
1.489 raeburn 5780: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5781: my $lg_border_color = '#C8C8C8';
1.952 onken 5782: my $button_hover = '#BF2317';
1.392 albertel 5783:
1.608 albertel 5784: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5785: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5786: : '0 3px 0 4px';
1.448 albertel 5787:
1.523 albertel 5788:
1.343 albertel 5789: return <<END;
1.947 droeschl 5790:
5791: /* needed for iframe to allow 100% height in FF */
5792: body, html {
5793: margin: 0;
5794: padding: 0 0.5%;
5795: height: 99%; /* to avoid scrollbars */
5796: }
5797:
1.795 www 5798: body {
1.911 bisitz 5799: font-family: $sans;
5800: line-height:130%;
5801: font-size:0.83em;
5802: color:$font;
1.795 www 5803: }
5804:
1.959 onken 5805: a:focus,
5806: a:focus img {
1.795 www 5807: color: red;
5808: }
1.698 harmsja 5809:
1.911 bisitz 5810: form, .inline {
5811: display: inline;
1.795 www 5812: }
1.721 harmsja 5813:
1.795 www 5814: .LC_right {
1.911 bisitz 5815: text-align:right;
1.795 www 5816: }
5817:
5818: .LC_middle {
1.911 bisitz 5819: vertical-align:middle;
1.795 www 5820: }
1.721 harmsja 5821:
1.1075.2.38 raeburn 5822: .LC_floatleft {
5823: float: left;
5824: }
5825:
5826: .LC_floatright {
5827: float: right;
5828: }
5829:
1.911 bisitz 5830: .LC_400Box {
5831: width:400px;
5832: }
1.721 harmsja 5833:
1.947 droeschl 5834: .LC_iframecontainer {
5835: width: 98%;
5836: margin: 0;
5837: position: fixed;
5838: top: 8.5em;
5839: bottom: 0;
5840: }
5841:
5842: .LC_iframecontainer iframe{
5843: border: none;
5844: width: 100%;
5845: height: 100%;
5846: }
5847:
1.778 bisitz 5848: .LC_filename {
5849: font-family: $mono;
5850: white-space:pre;
1.921 bisitz 5851: font-size: 120%;
1.778 bisitz 5852: }
5853:
5854: .LC_fileicon {
5855: border: none;
5856: height: 1.3em;
5857: vertical-align: text-bottom;
5858: margin-right: 0.3em;
5859: text-decoration:none;
5860: }
5861:
1.1008 www 5862: .LC_setting {
5863: text-decoration:underline;
5864: }
5865:
1.350 albertel 5866: .LC_error {
5867: color: red;
5868: }
1.795 www 5869:
1.1075.2.15 raeburn 5870: .LC_warning {
5871: color: darkorange;
5872: }
5873:
1.457 albertel 5874: .LC_diff_removed {
1.733 bisitz 5875: color: red;
1.394 albertel 5876: }
1.532 albertel 5877:
5878: .LC_info,
1.457 albertel 5879: .LC_success,
5880: .LC_diff_added {
1.350 albertel 5881: color: green;
5882: }
1.795 www 5883:
1.802 bisitz 5884: div.LC_confirm_box {
5885: background-color: #FAFAFA;
5886: border: 1px solid $lg_border_color;
5887: margin-right: 0;
5888: padding: 5px;
5889: }
5890:
5891: div.LC_confirm_box .LC_error img,
5892: div.LC_confirm_box .LC_success img {
5893: vertical-align: middle;
5894: }
5895:
1.1075.2.108 raeburn 5896: .LC_maxwidth {
5897: max-width: 100%;
5898: height: auto;
5899: }
5900:
5901: .LC_textsize_mobile {
5902: \@media only screen and (max-device-width: 480px) {
5903: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
5904: }
5905: }
5906:
1.440 albertel 5907: .LC_icon {
1.771 droeschl 5908: border: none;
1.790 droeschl 5909: vertical-align: middle;
1.771 droeschl 5910: }
5911:
1.543 albertel 5912: .LC_docs_spacer {
5913: width: 25px;
5914: height: 1px;
1.771 droeschl 5915: border: none;
1.543 albertel 5916: }
1.346 albertel 5917:
1.532 albertel 5918: .LC_internal_info {
1.735 bisitz 5919: color: #999999;
1.532 albertel 5920: }
5921:
1.794 www 5922: .LC_discussion {
1.1050 www 5923: background: $data_table_dark;
1.911 bisitz 5924: border: 1px solid black;
5925: margin: 2px;
1.794 www 5926: }
5927:
5928: .LC_disc_action_left {
1.1050 www 5929: background: $sidebg;
1.911 bisitz 5930: text-align: left;
1.1050 www 5931: padding: 4px;
5932: margin: 2px;
1.794 www 5933: }
5934:
5935: .LC_disc_action_right {
1.1050 www 5936: background: $sidebg;
1.911 bisitz 5937: text-align: right;
1.1050 www 5938: padding: 4px;
5939: margin: 2px;
1.794 www 5940: }
5941:
5942: .LC_disc_new_item {
1.911 bisitz 5943: background: white;
5944: border: 2px solid red;
1.1050 www 5945: margin: 4px;
5946: padding: 4px;
1.794 www 5947: }
5948:
5949: .LC_disc_old_item {
1.911 bisitz 5950: background: white;
1.1050 www 5951: margin: 4px;
5952: padding: 4px;
1.794 www 5953: }
5954:
1.458 albertel 5955: table.LC_pastsubmission {
5956: border: 1px solid black;
5957: margin: 2px;
5958: }
5959:
1.924 bisitz 5960: table#LC_menubuttons {
1.345 albertel 5961: width: 100%;
5962: background: $pgbg;
1.392 albertel 5963: border: 2px;
1.402 albertel 5964: border-collapse: separate;
1.803 bisitz 5965: padding: 0;
1.345 albertel 5966: }
1.392 albertel 5967:
1.801 tempelho 5968: table#LC_title_bar a {
5969: color: $fontmenu;
5970: }
1.836 bisitz 5971:
1.807 droeschl 5972: table#LC_title_bar {
1.819 tempelho 5973: clear: both;
1.836 bisitz 5974: display: none;
1.807 droeschl 5975: }
5976:
1.795 www 5977: table#LC_title_bar,
1.933 droeschl 5978: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5979: table#LC_title_bar.LC_with_remote {
1.359 albertel 5980: width: 100%;
1.392 albertel 5981: border-color: $pgbg;
5982: border-style: solid;
5983: border-width: $border;
1.379 albertel 5984: background: $pgbg;
1.801 tempelho 5985: color: $fontmenu;
1.392 albertel 5986: border-collapse: collapse;
1.803 bisitz 5987: padding: 0;
1.819 tempelho 5988: margin: 0;
1.359 albertel 5989: }
1.795 www 5990:
1.933 droeschl 5991: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5992: margin: 0;
5993: padding: 0;
1.933 droeschl 5994: position: relative;
5995: list-style: none;
1.913 droeschl 5996: }
1.933 droeschl 5997: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5998: display: inline;
5999: }
1.933 droeschl 6000:
6001: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6002: padding: 0;
1.933 droeschl 6003: margin: 0;
6004: float: left;
1.913 droeschl 6005: }
1.933 droeschl 6006: .LC_breadcrumb_tools_tools {
6007: padding: 0;
6008: margin: 0;
1.913 droeschl 6009: float: right;
6010: }
6011:
1.359 albertel 6012: table#LC_title_bar td {
6013: background: $tabbg;
6014: }
1.795 www 6015:
1.911 bisitz 6016: table#LC_menubuttons img {
1.803 bisitz 6017: border: none;
1.346 albertel 6018: }
1.795 www 6019:
1.842 droeschl 6020: .LC_breadcrumbs_component {
1.911 bisitz 6021: float: right;
6022: margin: 0 1em;
1.357 albertel 6023: }
1.842 droeschl 6024: .LC_breadcrumbs_component img {
1.911 bisitz 6025: vertical-align: middle;
1.777 tempelho 6026: }
1.795 www 6027:
1.1075.2.108 raeburn 6028: .LC_breadcrumbs_hoverable {
6029: background: $sidebg;
6030: }
6031:
1.383 albertel 6032: td.LC_table_cell_checkbox {
6033: text-align: center;
6034: }
1.795 www 6035:
6036: .LC_fontsize_small {
1.911 bisitz 6037: font-size: 70%;
1.705 tempelho 6038: }
6039:
1.844 bisitz 6040: #LC_breadcrumbs {
1.911 bisitz 6041: clear:both;
6042: background: $sidebg;
6043: border-bottom: 1px solid $lg_border_color;
6044: line-height: 2.5em;
1.933 droeschl 6045: overflow: hidden;
1.911 bisitz 6046: margin: 0;
6047: padding: 0;
1.995 raeburn 6048: text-align: left;
1.819 tempelho 6049: }
1.862 bisitz 6050:
1.1075.2.16 raeburn 6051: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6052: clear:both;
6053: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6054: border: 1px solid $sidebg;
1.1075.2.16 raeburn 6055: margin: 0 0 10px 0;
1.966 bisitz 6056: padding: 3px;
1.995 raeburn 6057: text-align: left;
1.822 bisitz 6058: }
6059:
1.795 www 6060: .LC_fontsize_medium {
1.911 bisitz 6061: font-size: 85%;
1.705 tempelho 6062: }
6063:
1.795 www 6064: .LC_fontsize_large {
1.911 bisitz 6065: font-size: 120%;
1.705 tempelho 6066: }
6067:
1.346 albertel 6068: .LC_menubuttons_inline_text {
6069: color: $font;
1.698 harmsja 6070: font-size: 90%;
1.701 harmsja 6071: padding-left:3px;
1.346 albertel 6072: }
6073:
1.934 droeschl 6074: .LC_menubuttons_inline_text img{
6075: vertical-align: middle;
6076: }
6077:
1.1051 www 6078: li.LC_menubuttons_inline_text img {
1.951 onken 6079: cursor:pointer;
1.1002 droeschl 6080: text-decoration: none;
1.951 onken 6081: }
6082:
1.526 www 6083: .LC_menubuttons_link {
6084: text-decoration: none;
6085: }
1.795 www 6086:
1.522 albertel 6087: .LC_menubuttons_category {
1.521 www 6088: color: $font;
1.526 www 6089: background: $pgbg;
1.521 www 6090: font-size: larger;
6091: font-weight: bold;
6092: }
6093:
1.346 albertel 6094: td.LC_menubuttons_text {
1.911 bisitz 6095: color: $font;
1.346 albertel 6096: }
1.706 harmsja 6097:
1.346 albertel 6098: .LC_current_location {
6099: background: $tabbg;
6100: }
1.795 www 6101:
1.938 bisitz 6102: table.LC_data_table {
1.347 albertel 6103: border: 1px solid #000000;
1.402 albertel 6104: border-collapse: separate;
1.426 albertel 6105: border-spacing: 1px;
1.610 albertel 6106: background: $pgbg;
1.347 albertel 6107: }
1.795 www 6108:
1.422 albertel 6109: .LC_data_table_dense {
6110: font-size: small;
6111: }
1.795 www 6112:
1.507 raeburn 6113: table.LC_nested_outer {
6114: border: 1px solid #000000;
1.589 raeburn 6115: border-collapse: collapse;
1.803 bisitz 6116: border-spacing: 0;
1.507 raeburn 6117: width: 100%;
6118: }
1.795 www 6119:
1.879 raeburn 6120: table.LC_innerpickbox,
1.507 raeburn 6121: table.LC_nested {
1.803 bisitz 6122: border: none;
1.589 raeburn 6123: border-collapse: collapse;
1.803 bisitz 6124: border-spacing: 0;
1.507 raeburn 6125: width: 100%;
6126: }
1.795 www 6127:
1.911 bisitz 6128: table.LC_data_table tr th,
6129: table.LC_calendar tr th,
1.879 raeburn 6130: table.LC_prior_tries tr th,
6131: table.LC_innerpickbox tr th {
1.349 albertel 6132: font-weight: bold;
6133: background-color: $data_table_head;
1.801 tempelho 6134: color:$fontmenu;
1.701 harmsja 6135: font-size:90%;
1.347 albertel 6136: }
1.795 www 6137:
1.879 raeburn 6138: table.LC_innerpickbox tr th,
6139: table.LC_innerpickbox tr td {
6140: vertical-align: top;
6141: }
6142:
1.711 raeburn 6143: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6144: background-color: #CCCCCC;
1.711 raeburn 6145: font-weight: bold;
6146: text-align: left;
6147: }
1.795 www 6148:
1.912 bisitz 6149: table.LC_data_table tr.LC_odd_row > td {
6150: background-color: $data_table_light;
6151: padding: 2px;
6152: vertical-align: top;
6153: }
6154:
1.809 bisitz 6155: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6156: background-color: $data_table_light;
1.912 bisitz 6157: vertical-align: top;
6158: }
6159:
6160: table.LC_data_table tr.LC_even_row > td {
6161: background-color: $data_table_dark;
1.425 albertel 6162: padding: 2px;
1.900 bisitz 6163: vertical-align: top;
1.347 albertel 6164: }
1.795 www 6165:
1.809 bisitz 6166: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6167: background-color: $data_table_dark;
1.900 bisitz 6168: vertical-align: top;
1.347 albertel 6169: }
1.795 www 6170:
1.425 albertel 6171: table.LC_data_table tr.LC_data_table_highlight td {
6172: background-color: $data_table_darker;
6173: }
1.795 www 6174:
1.639 raeburn 6175: table.LC_data_table tr td.LC_leftcol_header {
6176: background-color: $data_table_head;
6177: font-weight: bold;
6178: }
1.795 www 6179:
1.451 albertel 6180: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6181: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6182: font-weight: bold;
6183: font-style: italic;
6184: text-align: center;
6185: padding: 8px;
1.347 albertel 6186: }
1.795 www 6187:
1.1075.2.30 raeburn 6188: table.LC_data_table tr.LC_empty_row td,
6189: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6190: background-color: $sidebg;
6191: }
6192:
6193: table.LC_nested tr.LC_empty_row td {
6194: background-color: #FFFFFF;
6195: }
6196:
1.890 droeschl 6197: table.LC_caption {
6198: }
6199:
1.507 raeburn 6200: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6201: padding: 4ex
6202: }
1.795 www 6203:
1.507 raeburn 6204: table.LC_nested_outer tr th {
6205: font-weight: bold;
1.801 tempelho 6206: color:$fontmenu;
1.507 raeburn 6207: background-color: $data_table_head;
1.701 harmsja 6208: font-size: small;
1.507 raeburn 6209: border-bottom: 1px solid #000000;
6210: }
1.795 www 6211:
1.507 raeburn 6212: table.LC_nested_outer tr td.LC_subheader {
6213: background-color: $data_table_head;
6214: font-weight: bold;
6215: font-size: small;
6216: border-bottom: 1px solid #000000;
6217: text-align: right;
1.451 albertel 6218: }
1.795 www 6219:
1.507 raeburn 6220: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6221: background-color: #CCCCCC;
1.451 albertel 6222: font-weight: bold;
6223: font-size: small;
1.507 raeburn 6224: text-align: center;
6225: }
1.795 www 6226:
1.589 raeburn 6227: table.LC_nested tr.LC_info_row td.LC_left_item,
6228: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6229: text-align: left;
1.451 albertel 6230: }
1.795 www 6231:
1.507 raeburn 6232: table.LC_nested td {
1.735 bisitz 6233: background-color: #FFFFFF;
1.451 albertel 6234: font-size: small;
1.507 raeburn 6235: }
1.795 www 6236:
1.507 raeburn 6237: table.LC_nested_outer tr th.LC_right_item,
6238: table.LC_nested tr.LC_info_row td.LC_right_item,
6239: table.LC_nested tr.LC_odd_row td.LC_right_item,
6240: table.LC_nested tr td.LC_right_item {
1.451 albertel 6241: text-align: right;
6242: }
6243:
1.507 raeburn 6244: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6245: background-color: #EEEEEE;
1.451 albertel 6246: }
6247:
1.473 raeburn 6248: table.LC_createuser {
6249: }
6250:
6251: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6252: font-size: small;
1.473 raeburn 6253: }
6254:
6255: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6256: background-color: #CCCCCC;
1.473 raeburn 6257: font-weight: bold;
6258: text-align: center;
6259: }
6260:
1.349 albertel 6261: table.LC_calendar {
6262: border: 1px solid #000000;
6263: border-collapse: collapse;
1.917 raeburn 6264: width: 98%;
1.349 albertel 6265: }
1.795 www 6266:
1.349 albertel 6267: table.LC_calendar_pickdate {
6268: font-size: xx-small;
6269: }
1.795 www 6270:
1.349 albertel 6271: table.LC_calendar tr td {
6272: border: 1px solid #000000;
6273: vertical-align: top;
1.917 raeburn 6274: width: 14%;
1.349 albertel 6275: }
1.795 www 6276:
1.349 albertel 6277: table.LC_calendar tr td.LC_calendar_day_empty {
6278: background-color: $data_table_dark;
6279: }
1.795 www 6280:
1.779 bisitz 6281: table.LC_calendar tr td.LC_calendar_day_current {
6282: background-color: $data_table_highlight;
1.777 tempelho 6283: }
1.795 www 6284:
1.938 bisitz 6285: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6286: background-color: $mail_new;
6287: }
1.795 www 6288:
1.938 bisitz 6289: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6290: background-color: $mail_new_hover;
6291: }
1.795 www 6292:
1.938 bisitz 6293: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6294: background-color: $mail_read;
6295: }
1.795 www 6296:
1.938 bisitz 6297: /*
6298: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6299: background-color: $mail_read_hover;
6300: }
1.938 bisitz 6301: */
1.795 www 6302:
1.938 bisitz 6303: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6304: background-color: $mail_replied;
6305: }
1.795 www 6306:
1.938 bisitz 6307: /*
6308: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6309: background-color: $mail_replied_hover;
6310: }
1.938 bisitz 6311: */
1.795 www 6312:
1.938 bisitz 6313: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6314: background-color: $mail_other;
6315: }
1.795 www 6316:
1.938 bisitz 6317: /*
6318: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6319: background-color: $mail_other_hover;
6320: }
1.938 bisitz 6321: */
1.494 raeburn 6322:
1.777 tempelho 6323: table.LC_data_table tr > td.LC_browser_file,
6324: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6325: background: #AAEE77;
1.389 albertel 6326: }
1.795 www 6327:
1.777 tempelho 6328: table.LC_data_table tr > td.LC_browser_file_locked,
6329: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6330: background: #FFAA99;
1.387 albertel 6331: }
1.795 www 6332:
1.777 tempelho 6333: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6334: background: #888888;
1.779 bisitz 6335: }
1.795 www 6336:
1.777 tempelho 6337: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6338: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6339: background: #F8F866;
1.777 tempelho 6340: }
1.795 www 6341:
1.696 bisitz 6342: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6343: background: #E0E8FF;
1.387 albertel 6344: }
1.696 bisitz 6345:
1.707 bisitz 6346: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6347: /* background: #77FF77; */
1.707 bisitz 6348: }
1.795 www 6349:
1.707 bisitz 6350: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6351: border-right: 8px solid #FFFF77;
1.707 bisitz 6352: }
1.795 www 6353:
1.707 bisitz 6354: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6355: border-right: 8px solid #FFAA77;
1.707 bisitz 6356: }
1.795 www 6357:
1.707 bisitz 6358: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6359: border-right: 8px solid #FF7777;
1.707 bisitz 6360: }
1.795 www 6361:
1.707 bisitz 6362: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6363: border-right: 8px solid #AAFF77;
1.707 bisitz 6364: }
1.795 www 6365:
1.707 bisitz 6366: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6367: border-right: 8px solid #11CC55;
1.707 bisitz 6368: }
6369:
1.388 albertel 6370: span.LC_current_location {
1.701 harmsja 6371: font-size:larger;
1.388 albertel 6372: background: $pgbg;
6373: }
1.387 albertel 6374:
1.1029 www 6375: span.LC_current_nav_location {
6376: font-weight:bold;
6377: background: $sidebg;
6378: }
6379:
1.395 albertel 6380: span.LC_parm_menu_item {
6381: font-size: larger;
6382: }
1.795 www 6383:
1.395 albertel 6384: span.LC_parm_scope_all {
6385: color: red;
6386: }
1.795 www 6387:
1.395 albertel 6388: span.LC_parm_scope_folder {
6389: color: green;
6390: }
1.795 www 6391:
1.395 albertel 6392: span.LC_parm_scope_resource {
6393: color: orange;
6394: }
1.795 www 6395:
1.395 albertel 6396: span.LC_parm_part {
6397: color: blue;
6398: }
1.795 www 6399:
1.911 bisitz 6400: span.LC_parm_folder,
6401: span.LC_parm_symb {
1.395 albertel 6402: font-size: x-small;
6403: font-family: $mono;
6404: color: #AAAAAA;
6405: }
6406:
1.977 bisitz 6407: ul.LC_parm_parmlist li {
6408: display: inline-block;
6409: padding: 0.3em 0.8em;
6410: vertical-align: top;
6411: width: 150px;
6412: border-top:1px solid $lg_border_color;
6413: }
6414:
1.795 www 6415: td.LC_parm_overview_level_menu,
6416: td.LC_parm_overview_map_menu,
6417: td.LC_parm_overview_parm_selectors,
6418: td.LC_parm_overview_restrictions {
1.396 albertel 6419: border: 1px solid black;
6420: border-collapse: collapse;
6421: }
1.795 www 6422:
1.396 albertel 6423: table.LC_parm_overview_restrictions td {
6424: border-width: 1px 4px 1px 4px;
6425: border-style: solid;
6426: border-color: $pgbg;
6427: text-align: center;
6428: }
1.795 www 6429:
1.396 albertel 6430: table.LC_parm_overview_restrictions th {
6431: background: $tabbg;
6432: border-width: 1px 4px 1px 4px;
6433: border-style: solid;
6434: border-color: $pgbg;
6435: }
1.795 www 6436:
1.398 albertel 6437: table#LC_helpmenu {
1.803 bisitz 6438: border: none;
1.398 albertel 6439: height: 55px;
1.803 bisitz 6440: border-spacing: 0;
1.398 albertel 6441: }
6442:
6443: table#LC_helpmenu fieldset legend {
6444: font-size: larger;
6445: }
1.795 www 6446:
1.397 albertel 6447: table#LC_helpmenu_links {
6448: width: 100%;
6449: border: 1px solid black;
6450: background: $pgbg;
1.803 bisitz 6451: padding: 0;
1.397 albertel 6452: border-spacing: 1px;
6453: }
1.795 www 6454:
1.397 albertel 6455: table#LC_helpmenu_links tr td {
6456: padding: 1px;
6457: background: $tabbg;
1.399 albertel 6458: text-align: center;
6459: font-weight: bold;
1.397 albertel 6460: }
1.396 albertel 6461:
1.795 www 6462: table#LC_helpmenu_links a:link,
6463: table#LC_helpmenu_links a:visited,
1.397 albertel 6464: table#LC_helpmenu_links a:active {
6465: text-decoration: none;
6466: color: $font;
6467: }
1.795 www 6468:
1.397 albertel 6469: table#LC_helpmenu_links a:hover {
6470: text-decoration: underline;
6471: color: $vlink;
6472: }
1.396 albertel 6473:
1.417 albertel 6474: .LC_chrt_popup_exists {
6475: border: 1px solid #339933;
6476: margin: -1px;
6477: }
1.795 www 6478:
1.417 albertel 6479: .LC_chrt_popup_up {
6480: border: 1px solid yellow;
6481: margin: -1px;
6482: }
1.795 www 6483:
1.417 albertel 6484: .LC_chrt_popup {
6485: border: 1px solid #8888FF;
6486: background: #CCCCFF;
6487: }
1.795 www 6488:
1.421 albertel 6489: table.LC_pick_box {
6490: border-collapse: separate;
6491: background: white;
6492: border: 1px solid black;
6493: border-spacing: 1px;
6494: }
1.795 www 6495:
1.421 albertel 6496: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6497: background: $sidebg;
1.421 albertel 6498: font-weight: bold;
1.900 bisitz 6499: text-align: left;
1.740 bisitz 6500: vertical-align: top;
1.421 albertel 6501: width: 184px;
6502: padding: 8px;
6503: }
1.795 www 6504:
1.579 raeburn 6505: table.LC_pick_box td.LC_pick_box_value {
6506: text-align: left;
6507: padding: 8px;
6508: }
1.795 www 6509:
1.579 raeburn 6510: table.LC_pick_box td.LC_pick_box_select {
6511: text-align: left;
6512: padding: 8px;
6513: }
1.795 www 6514:
1.424 albertel 6515: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6516: padding: 0;
1.421 albertel 6517: height: 1px;
6518: background: black;
6519: }
1.795 www 6520:
1.421 albertel 6521: table.LC_pick_box td.LC_pick_box_submit {
6522: text-align: right;
6523: }
1.795 www 6524:
1.579 raeburn 6525: table.LC_pick_box td.LC_evenrow_value {
6526: text-align: left;
6527: padding: 8px;
6528: background-color: $data_table_light;
6529: }
1.795 www 6530:
1.579 raeburn 6531: table.LC_pick_box td.LC_oddrow_value {
6532: text-align: left;
6533: padding: 8px;
6534: background-color: $data_table_light;
6535: }
1.795 www 6536:
1.579 raeburn 6537: span.LC_helpform_receipt_cat {
6538: font-weight: bold;
6539: }
1.795 www 6540:
1.424 albertel 6541: table.LC_group_priv_box {
6542: background: white;
6543: border: 1px solid black;
6544: border-spacing: 1px;
6545: }
1.795 www 6546:
1.424 albertel 6547: table.LC_group_priv_box td.LC_pick_box_title {
6548: background: $tabbg;
6549: font-weight: bold;
6550: text-align: right;
6551: width: 184px;
6552: }
1.795 www 6553:
1.424 albertel 6554: table.LC_group_priv_box td.LC_groups_fixed {
6555: background: $data_table_light;
6556: text-align: center;
6557: }
1.795 www 6558:
1.424 albertel 6559: table.LC_group_priv_box td.LC_groups_optional {
6560: background: $data_table_dark;
6561: text-align: center;
6562: }
1.795 www 6563:
1.424 albertel 6564: table.LC_group_priv_box td.LC_groups_functionality {
6565: background: $data_table_darker;
6566: text-align: center;
6567: font-weight: bold;
6568: }
1.795 www 6569:
1.424 albertel 6570: table.LC_group_priv td {
6571: text-align: left;
1.803 bisitz 6572: padding: 0;
1.424 albertel 6573: }
6574:
6575: .LC_navbuttons {
6576: margin: 2ex 0ex 2ex 0ex;
6577: }
1.795 www 6578:
1.423 albertel 6579: .LC_topic_bar {
6580: font-weight: bold;
6581: background: $tabbg;
1.918 wenzelju 6582: margin: 1em 0em 1em 2em;
1.805 bisitz 6583: padding: 3px;
1.918 wenzelju 6584: font-size: 1.2em;
1.423 albertel 6585: }
1.795 www 6586:
1.423 albertel 6587: .LC_topic_bar span {
1.918 wenzelju 6588: left: 0.5em;
6589: position: absolute;
1.423 albertel 6590: vertical-align: middle;
1.918 wenzelju 6591: font-size: 1.2em;
1.423 albertel 6592: }
1.795 www 6593:
1.423 albertel 6594: table.LC_course_group_status {
6595: margin: 20px;
6596: }
1.795 www 6597:
1.423 albertel 6598: table.LC_status_selector td {
6599: vertical-align: top;
6600: text-align: center;
1.424 albertel 6601: padding: 4px;
6602: }
1.795 www 6603:
1.599 albertel 6604: div.LC_feedback_link {
1.616 albertel 6605: clear: both;
1.829 kalberla 6606: background: $sidebg;
1.779 bisitz 6607: width: 100%;
1.829 kalberla 6608: padding-bottom: 10px;
6609: border: 1px $tabbg solid;
1.833 kalberla 6610: height: 22px;
6611: line-height: 22px;
6612: padding-top: 5px;
6613: }
6614:
6615: div.LC_feedback_link img {
6616: height: 22px;
1.867 kalberla 6617: vertical-align:middle;
1.829 kalberla 6618: }
6619:
1.911 bisitz 6620: div.LC_feedback_link a {
1.829 kalberla 6621: text-decoration: none;
1.489 raeburn 6622: }
1.795 www 6623:
1.867 kalberla 6624: div.LC_comblock {
1.911 bisitz 6625: display:inline;
1.867 kalberla 6626: color:$font;
6627: font-size:90%;
6628: }
6629:
6630: div.LC_feedback_link div.LC_comblock {
6631: padding-left:5px;
6632: }
6633:
6634: div.LC_feedback_link div.LC_comblock a {
6635: color:$font;
6636: }
6637:
1.489 raeburn 6638: span.LC_feedback_link {
1.858 bisitz 6639: /* background: $feedback_link_bg; */
1.599 albertel 6640: font-size: larger;
6641: }
1.795 www 6642:
1.599 albertel 6643: span.LC_message_link {
1.858 bisitz 6644: /* background: $feedback_link_bg; */
1.599 albertel 6645: font-size: larger;
6646: position: absolute;
6647: right: 1em;
1.489 raeburn 6648: }
1.421 albertel 6649:
1.515 albertel 6650: table.LC_prior_tries {
1.524 albertel 6651: border: 1px solid #000000;
6652: border-collapse: separate;
6653: border-spacing: 1px;
1.515 albertel 6654: }
1.523 albertel 6655:
1.515 albertel 6656: table.LC_prior_tries td {
1.524 albertel 6657: padding: 2px;
1.515 albertel 6658: }
1.523 albertel 6659:
6660: .LC_answer_correct {
1.795 www 6661: background: lightgreen;
6662: color: darkgreen;
6663: padding: 6px;
1.523 albertel 6664: }
1.795 www 6665:
1.523 albertel 6666: .LC_answer_charged_try {
1.797 www 6667: background: #FFAAAA;
1.795 www 6668: color: darkred;
6669: padding: 6px;
1.523 albertel 6670: }
1.795 www 6671:
1.779 bisitz 6672: .LC_answer_not_charged_try,
1.523 albertel 6673: .LC_answer_no_grade,
6674: .LC_answer_late {
1.795 www 6675: background: lightyellow;
1.523 albertel 6676: color: black;
1.795 www 6677: padding: 6px;
1.523 albertel 6678: }
1.795 www 6679:
1.523 albertel 6680: .LC_answer_previous {
1.795 www 6681: background: lightblue;
6682: color: darkblue;
6683: padding: 6px;
1.523 albertel 6684: }
1.795 www 6685:
1.779 bisitz 6686: .LC_answer_no_message {
1.777 tempelho 6687: background: #FFFFFF;
6688: color: black;
1.795 www 6689: padding: 6px;
1.779 bisitz 6690: }
1.795 www 6691:
1.779 bisitz 6692: .LC_answer_unknown {
6693: background: orange;
6694: color: black;
1.795 www 6695: padding: 6px;
1.777 tempelho 6696: }
1.795 www 6697:
1.529 albertel 6698: span.LC_prior_numerical,
6699: span.LC_prior_string,
6700: span.LC_prior_custom,
6701: span.LC_prior_reaction,
6702: span.LC_prior_math {
1.925 bisitz 6703: font-family: $mono;
1.523 albertel 6704: white-space: pre;
6705: }
6706:
1.525 albertel 6707: span.LC_prior_string {
1.925 bisitz 6708: font-family: $mono;
1.525 albertel 6709: white-space: pre;
6710: }
6711:
1.523 albertel 6712: table.LC_prior_option {
6713: width: 100%;
6714: border-collapse: collapse;
6715: }
1.795 www 6716:
1.911 bisitz 6717: table.LC_prior_rank,
1.795 www 6718: table.LC_prior_match {
1.528 albertel 6719: border-collapse: collapse;
6720: }
1.795 www 6721:
1.528 albertel 6722: table.LC_prior_option tr td,
6723: table.LC_prior_rank tr td,
6724: table.LC_prior_match tr td {
1.524 albertel 6725: border: 1px solid #000000;
1.515 albertel 6726: }
6727:
1.855 bisitz 6728: .LC_nobreak {
1.544 albertel 6729: white-space: nowrap;
1.519 raeburn 6730: }
6731:
1.576 raeburn 6732: span.LC_cusr_emph {
6733: font-style: italic;
6734: }
6735:
1.633 raeburn 6736: span.LC_cusr_subheading {
6737: font-weight: normal;
6738: font-size: 85%;
6739: }
6740:
1.861 bisitz 6741: div.LC_docs_entry_move {
1.859 bisitz 6742: border: 1px solid #BBBBBB;
1.545 albertel 6743: background: #DDDDDD;
1.861 bisitz 6744: width: 22px;
1.859 bisitz 6745: padding: 1px;
6746: margin: 0;
1.545 albertel 6747: }
6748:
1.861 bisitz 6749: table.LC_data_table tr > td.LC_docs_entry_commands,
6750: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6751: font-size: x-small;
6752: }
1.795 www 6753:
1.861 bisitz 6754: .LC_docs_entry_parameter {
6755: white-space: nowrap;
6756: }
6757:
1.544 albertel 6758: .LC_docs_copy {
1.545 albertel 6759: color: #000099;
1.544 albertel 6760: }
1.795 www 6761:
1.544 albertel 6762: .LC_docs_cut {
1.545 albertel 6763: color: #550044;
1.544 albertel 6764: }
1.795 www 6765:
1.544 albertel 6766: .LC_docs_rename {
1.545 albertel 6767: color: #009900;
1.544 albertel 6768: }
1.795 www 6769:
1.544 albertel 6770: .LC_docs_remove {
1.545 albertel 6771: color: #990000;
6772: }
6773:
1.547 albertel 6774: .LC_docs_reinit_warn,
6775: .LC_docs_ext_edit {
6776: font-size: x-small;
6777: }
6778:
1.545 albertel 6779: table.LC_docs_adddocs td,
6780: table.LC_docs_adddocs th {
6781: border: 1px solid #BBBBBB;
6782: padding: 4px;
6783: background: #DDDDDD;
1.543 albertel 6784: }
6785:
1.584 albertel 6786: table.LC_sty_begin {
6787: background: #BBFFBB;
6788: }
1.795 www 6789:
1.584 albertel 6790: table.LC_sty_end {
6791: background: #FFBBBB;
6792: }
6793:
1.589 raeburn 6794: table.LC_double_column {
1.803 bisitz 6795: border-width: 0;
1.589 raeburn 6796: border-collapse: collapse;
6797: width: 100%;
6798: padding: 2px;
6799: }
6800:
6801: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6802: top: 2px;
1.589 raeburn 6803: left: 2px;
6804: width: 47%;
6805: vertical-align: top;
6806: }
6807:
6808: table.LC_double_column tr td.LC_right_col {
6809: top: 2px;
1.779 bisitz 6810: right: 2px;
1.589 raeburn 6811: width: 47%;
6812: vertical-align: top;
6813: }
6814:
1.591 raeburn 6815: div.LC_left_float {
6816: float: left;
6817: padding-right: 5%;
1.597 albertel 6818: padding-bottom: 4px;
1.591 raeburn 6819: }
6820:
6821: div.LC_clear_float_header {
1.597 albertel 6822: padding-bottom: 2px;
1.591 raeburn 6823: }
6824:
6825: div.LC_clear_float_footer {
1.597 albertel 6826: padding-top: 10px;
1.591 raeburn 6827: clear: both;
6828: }
6829:
1.597 albertel 6830: div.LC_grade_show_user {
1.941 bisitz 6831: /* border-left: 5px solid $sidebg; */
6832: border-top: 5px solid #000000;
6833: margin: 50px 0 0 0;
1.936 bisitz 6834: padding: 15px 0 5px 10px;
1.597 albertel 6835: }
1.795 www 6836:
1.936 bisitz 6837: div.LC_grade_show_user_odd_row {
1.941 bisitz 6838: /* border-left: 5px solid #000000; */
6839: }
6840:
6841: div.LC_grade_show_user div.LC_Box {
6842: margin-right: 50px;
1.597 albertel 6843: }
6844:
6845: div.LC_grade_submissions,
6846: div.LC_grade_message_center,
1.936 bisitz 6847: div.LC_grade_info_links {
1.597 albertel 6848: margin: 5px;
6849: width: 99%;
6850: background: #FFFFFF;
6851: }
1.795 www 6852:
1.597 albertel 6853: div.LC_grade_submissions_header,
1.936 bisitz 6854: div.LC_grade_message_center_header {
1.705 tempelho 6855: font-weight: bold;
6856: font-size: large;
1.597 albertel 6857: }
1.795 www 6858:
1.597 albertel 6859: div.LC_grade_submissions_body,
1.936 bisitz 6860: div.LC_grade_message_center_body {
1.597 albertel 6861: border: 1px solid black;
6862: width: 99%;
6863: background: #FFFFFF;
6864: }
1.795 www 6865:
1.613 albertel 6866: table.LC_scantron_action {
6867: width: 100%;
6868: }
1.795 www 6869:
1.613 albertel 6870: table.LC_scantron_action tr th {
1.698 harmsja 6871: font-weight:bold;
6872: font-style:normal;
1.613 albertel 6873: }
1.795 www 6874:
1.779 bisitz 6875: .LC_edit_problem_header,
1.614 albertel 6876: div.LC_edit_problem_footer {
1.705 tempelho 6877: font-weight: normal;
6878: font-size: medium;
1.602 albertel 6879: margin: 2px;
1.1060 bisitz 6880: background-color: $sidebg;
1.600 albertel 6881: }
1.795 www 6882:
1.600 albertel 6883: div.LC_edit_problem_header,
1.602 albertel 6884: div.LC_edit_problem_header div,
1.614 albertel 6885: div.LC_edit_problem_footer,
6886: div.LC_edit_problem_footer div,
1.602 albertel 6887: div.LC_edit_problem_editxml_header,
6888: div.LC_edit_problem_editxml_header div {
1.1075.2.112 raeburn 6889: z-index: 100;
1.600 albertel 6890: }
1.795 www 6891:
1.600 albertel 6892: div.LC_edit_problem_header_title {
1.705 tempelho 6893: font-weight: bold;
6894: font-size: larger;
1.602 albertel 6895: background: $tabbg;
6896: padding: 3px;
1.1060 bisitz 6897: margin: 0 0 5px 0;
1.602 albertel 6898: }
1.795 www 6899:
1.602 albertel 6900: table.LC_edit_problem_header_title {
6901: width: 100%;
1.600 albertel 6902: background: $tabbg;
1.602 albertel 6903: }
6904:
1.1075.2.112 raeburn 6905: div.LC_edit_actionbar {
6906: background-color: $sidebg;
6907: margin: 0;
6908: padding: 0;
6909: line-height: 200%;
1.602 albertel 6910: }
1.795 www 6911:
1.1075.2.112 raeburn 6912: div.LC_edit_actionbar div{
6913: padding: 0;
6914: margin: 0;
6915: display: inline-block;
1.600 albertel 6916: }
1.795 www 6917:
1.1075.2.34 raeburn 6918: .LC_edit_opt {
6919: padding-left: 1em;
6920: white-space: nowrap;
6921: }
6922:
1.1075.2.57 raeburn 6923: .LC_edit_problem_latexhelper{
6924: text-align: right;
6925: }
6926:
6927: #LC_edit_problem_colorful div{
6928: margin-left: 40px;
6929: }
6930:
1.1075.2.112 raeburn 6931: #LC_edit_problem_codemirror div{
6932: margin-left: 0px;
6933: }
6934:
1.911 bisitz 6935: img.stift {
1.803 bisitz 6936: border-width: 0;
6937: vertical-align: middle;
1.677 riegler 6938: }
1.680 riegler 6939:
1.923 bisitz 6940: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6941: vertical-align: top;
1.777 tempelho 6942: }
1.795 www 6943:
1.716 raeburn 6944: div.LC_createcourse {
1.911 bisitz 6945: margin: 10px 10px 10px 10px;
1.716 raeburn 6946: }
6947:
1.917 raeburn 6948: .LC_dccid {
1.1075.2.38 raeburn 6949: float: right;
1.917 raeburn 6950: margin: 0.2em 0 0 0;
6951: padding: 0;
6952: font-size: 90%;
6953: display:none;
6954: }
6955:
1.897 wenzelju 6956: ol.LC_primary_menu a:hover,
1.721 harmsja 6957: ol#LC_MenuBreadcrumbs a:hover,
6958: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6959: ul#LC_secondary_menu a:hover,
1.721 harmsja 6960: .LC_FormSectionClearButton input:hover
1.795 www 6961: ul.LC_TabContent li:hover a {
1.952 onken 6962: color:$button_hover;
1.911 bisitz 6963: text-decoration:none;
1.693 droeschl 6964: }
6965:
1.779 bisitz 6966: h1 {
1.911 bisitz 6967: padding: 0;
6968: line-height:130%;
1.693 droeschl 6969: }
1.698 harmsja 6970:
1.911 bisitz 6971: h2,
6972: h3,
6973: h4,
6974: h5,
6975: h6 {
6976: margin: 5px 0 5px 0;
6977: padding: 0;
6978: line-height:130%;
1.693 droeschl 6979: }
1.795 www 6980:
6981: .LC_hcell {
1.911 bisitz 6982: padding:3px 15px 3px 15px;
6983: margin: 0;
6984: background-color:$tabbg;
6985: color:$fontmenu;
6986: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6987: }
1.795 www 6988:
1.840 bisitz 6989: .LC_Box > .LC_hcell {
1.911 bisitz 6990: margin: 0 -10px 10px -10px;
1.835 bisitz 6991: }
6992:
1.721 harmsja 6993: .LC_noBorder {
1.911 bisitz 6994: border: 0;
1.698 harmsja 6995: }
1.693 droeschl 6996:
1.721 harmsja 6997: .LC_FormSectionClearButton input {
1.911 bisitz 6998: background-color:transparent;
6999: border: none;
7000: cursor:pointer;
7001: text-decoration:underline;
1.693 droeschl 7002: }
1.763 bisitz 7003:
7004: .LC_help_open_topic {
1.911 bisitz 7005: color: #FFFFFF;
7006: background-color: #EEEEFF;
7007: margin: 1px;
7008: padding: 4px;
7009: border: 1px solid #000033;
7010: white-space: nowrap;
7011: /* vertical-align: middle; */
1.759 neumanie 7012: }
1.693 droeschl 7013:
1.911 bisitz 7014: dl,
7015: ul,
7016: div,
7017: fieldset {
7018: margin: 10px 10px 10px 0;
7019: /* overflow: hidden; */
1.693 droeschl 7020: }
1.795 www 7021:
1.1075.2.90 raeburn 7022: article.geogebraweb div {
7023: margin: 0;
7024: }
7025:
1.838 bisitz 7026: fieldset > legend {
1.911 bisitz 7027: font-weight: bold;
7028: padding: 0 5px 0 5px;
1.838 bisitz 7029: }
7030:
1.813 bisitz 7031: #LC_nav_bar {
1.911 bisitz 7032: float: left;
1.995 raeburn 7033: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7034: margin: 0 0 2px 0;
1.807 droeschl 7035: }
7036:
1.916 droeschl 7037: #LC_realm {
7038: margin: 0.2em 0 0 0;
7039: padding: 0;
7040: font-weight: bold;
7041: text-align: center;
1.995 raeburn 7042: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7043: }
7044:
1.911 bisitz 7045: #LC_nav_bar em {
7046: font-weight: bold;
7047: font-style: normal;
1.807 droeschl 7048: }
7049:
1.897 wenzelju 7050: ol.LC_primary_menu {
1.934 droeschl 7051: margin: 0;
1.1075.2.2 raeburn 7052: padding: 0;
1.807 droeschl 7053: }
7054:
1.852 droeschl 7055: ol#LC_PathBreadcrumbs {
1.911 bisitz 7056: margin: 0;
1.693 droeschl 7057: }
7058:
1.897 wenzelju 7059: ol.LC_primary_menu li {
1.1075.2.2 raeburn 7060: color: RGB(80, 80, 80);
7061: vertical-align: middle;
7062: text-align: left;
7063: list-style: none;
1.1075.2.112 raeburn 7064: position: relative;
1.1075.2.2 raeburn 7065: float: left;
1.1075.2.112 raeburn 7066: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7067: line-height: 1.5em;
1.1075.2.2 raeburn 7068: }
7069:
1.1075.2.113 raeburn 7070: ol.LC_primary_menu li a,
1.1075.2.112 raeburn 7071: ol.LC_primary_menu li p {
1.1075.2.2 raeburn 7072: display: block;
7073: margin: 0;
7074: padding: 0 5px 0 10px;
7075: text-decoration: none;
7076: }
7077:
1.1075.2.112 raeburn 7078: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7079: display: inline-block;
7080: width: 95%;
7081: text-align: left;
7082: }
7083:
7084: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7085: display: inline-block;
7086: width: 5%;
7087: float: right;
7088: text-align: right;
7089: font-size: 70%;
7090: }
7091:
7092: ol.LC_primary_menu ul {
1.1075.2.2 raeburn 7093: display: none;
1.1075.2.112 raeburn 7094: width: 15em;
1.1075.2.2 raeburn 7095: background-color: $data_table_light;
1.1075.2.112 raeburn 7096: position: absolute;
7097: top: 100%;
7098: }
7099:
7100: ol.LC_primary_menu ul ul {
7101: left: 100%;
7102: top: 0;
1.1075.2.2 raeburn 7103: }
7104:
1.1075.2.112 raeburn 7105: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1075.2.2 raeburn 7106: display: block;
7107: position: absolute;
7108: margin: 0;
7109: padding: 0;
1.1075.2.5 raeburn 7110: z-index: 2;
1.1075.2.2 raeburn 7111: }
7112:
7113: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1075.2.112 raeburn 7114: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1075.2.2 raeburn 7115: font-size: 90%;
1.911 bisitz 7116: vertical-align: top;
1.1075.2.2 raeburn 7117: float: none;
1.1075.2.5 raeburn 7118: border-left: 1px solid black;
7119: border-right: 1px solid black;
1.1075.2.112 raeburn 7120: /* A dark bottom border to visualize different menu options;
7121: overwritten in the create_submenu routine for the last border-bottom of the menu */
7122: border-bottom: 1px solid $data_table_dark;
1.1075.2.2 raeburn 7123: }
7124:
1.1075.2.112 raeburn 7125: ol.LC_primary_menu li li p:hover {
7126: color:$button_hover;
7127: text-decoration:none;
7128: background-color:$data_table_dark;
1.1075.2.2 raeburn 7129: }
7130:
7131: ol.LC_primary_menu li li a:hover {
7132: color:$button_hover;
7133: background-color:$data_table_dark;
1.693 droeschl 7134: }
7135:
1.1075.2.112 raeburn 7136: /* Font-size equal to the size of the predecessors*/
7137: ol.LC_primary_menu li:hover li li {
7138: font-size: 100%;
7139: }
7140:
1.897 wenzelju 7141: ol.LC_primary_menu li img {
1.911 bisitz 7142: vertical-align: bottom;
1.934 droeschl 7143: height: 1.1em;
1.1075.2.3 raeburn 7144: margin: 0.2em 0 0 0;
1.693 droeschl 7145: }
7146:
1.897 wenzelju 7147: ol.LC_primary_menu a {
1.911 bisitz 7148: color: RGB(80, 80, 80);
7149: text-decoration: none;
1.693 droeschl 7150: }
1.795 www 7151:
1.949 droeschl 7152: ol.LC_primary_menu a.LC_new_message {
7153: font-weight:bold;
7154: color: darkred;
7155: }
7156:
1.975 raeburn 7157: ol.LC_docs_parameters {
7158: margin-left: 0;
7159: padding: 0;
7160: list-style: none;
7161: }
7162:
7163: ol.LC_docs_parameters li {
7164: margin: 0;
7165: padding-right: 20px;
7166: display: inline;
7167: }
7168:
1.976 raeburn 7169: ol.LC_docs_parameters li:before {
7170: content: "\\002022 \\0020";
7171: }
7172:
7173: li.LC_docs_parameters_title {
7174: font-weight: bold;
7175: }
7176:
7177: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7178: content: "";
7179: }
7180:
1.897 wenzelju 7181: ul#LC_secondary_menu {
1.1075.2.23 raeburn 7182: clear: right;
1.911 bisitz 7183: color: $fontmenu;
7184: background: $tabbg;
7185: list-style: none;
7186: padding: 0;
7187: margin: 0;
7188: width: 100%;
1.995 raeburn 7189: text-align: left;
1.1075.2.4 raeburn 7190: float: left;
1.808 droeschl 7191: }
7192:
1.897 wenzelju 7193: ul#LC_secondary_menu li {
1.911 bisitz 7194: font-weight: bold;
7195: line-height: 1.8em;
7196: border-right: 1px solid black;
1.1075.2.4 raeburn 7197: float: left;
7198: }
7199:
7200: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7201: background-color: $data_table_light;
7202: }
7203:
7204: ul#LC_secondary_menu li a {
7205: padding: 0 0.8em;
7206: }
7207:
7208: ul#LC_secondary_menu li ul {
7209: display: none;
7210: }
7211:
7212: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7213: display: block;
7214: position: absolute;
7215: margin: 0;
7216: padding: 0;
7217: list-style:none;
7218: float: none;
7219: background-color: $data_table_light;
1.1075.2.5 raeburn 7220: z-index: 2;
1.1075.2.10 raeburn 7221: margin-left: -1px;
1.1075.2.4 raeburn 7222: }
7223:
7224: ul#LC_secondary_menu li ul li {
7225: font-size: 90%;
7226: vertical-align: top;
7227: border-left: 1px solid black;
7228: border-right: 1px solid black;
1.1075.2.33 raeburn 7229: background-color: $data_table_light;
1.1075.2.4 raeburn 7230: list-style:none;
7231: float: none;
7232: }
7233:
7234: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7235: background-color: $data_table_dark;
1.807 droeschl 7236: }
7237:
1.847 tempelho 7238: ul.LC_TabContent {
1.911 bisitz 7239: display:block;
7240: background: $sidebg;
7241: border-bottom: solid 1px $lg_border_color;
7242: list-style:none;
1.1020 raeburn 7243: margin: -1px -10px 0 -10px;
1.911 bisitz 7244: padding: 0;
1.693 droeschl 7245: }
7246:
1.795 www 7247: ul.LC_TabContent li,
7248: ul.LC_TabContentBigger li {
1.911 bisitz 7249: float:left;
1.741 harmsja 7250: }
1.795 www 7251:
1.897 wenzelju 7252: ul#LC_secondary_menu li a {
1.911 bisitz 7253: color: $fontmenu;
7254: text-decoration: none;
1.693 droeschl 7255: }
1.795 www 7256:
1.721 harmsja 7257: ul.LC_TabContent {
1.952 onken 7258: min-height:20px;
1.721 harmsja 7259: }
1.795 www 7260:
7261: ul.LC_TabContent li {
1.911 bisitz 7262: vertical-align:middle;
1.959 onken 7263: padding: 0 16px 0 10px;
1.911 bisitz 7264: background-color:$tabbg;
7265: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7266: border-left: solid 1px $font;
1.721 harmsja 7267: }
1.795 www 7268:
1.847 tempelho 7269: ul.LC_TabContent .right {
1.911 bisitz 7270: float:right;
1.847 tempelho 7271: }
7272:
1.911 bisitz 7273: ul.LC_TabContent li a,
7274: ul.LC_TabContent li {
7275: color:rgb(47,47,47);
7276: text-decoration:none;
7277: font-size:95%;
7278: font-weight:bold;
1.952 onken 7279: min-height:20px;
7280: }
7281:
1.959 onken 7282: ul.LC_TabContent li a:hover,
7283: ul.LC_TabContent li a:focus {
1.952 onken 7284: color: $button_hover;
1.959 onken 7285: background:none;
7286: outline:none;
1.952 onken 7287: }
7288:
7289: ul.LC_TabContent li:hover {
7290: color: $button_hover;
7291: cursor:pointer;
1.721 harmsja 7292: }
1.795 www 7293:
1.911 bisitz 7294: ul.LC_TabContent li.active {
1.952 onken 7295: color: $font;
1.911 bisitz 7296: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7297: border-bottom:solid 1px #FFFFFF;
7298: cursor: default;
1.744 ehlerst 7299: }
1.795 www 7300:
1.959 onken 7301: ul.LC_TabContent li.active a {
7302: color:$font;
7303: background:#FFFFFF;
7304: outline: none;
7305: }
1.1047 raeburn 7306:
7307: ul.LC_TabContent li.goback {
7308: float: left;
7309: border-left: none;
7310: }
7311:
1.870 tempelho 7312: #maincoursedoc {
1.911 bisitz 7313: clear:both;
1.870 tempelho 7314: }
7315:
7316: ul.LC_TabContentBigger {
1.911 bisitz 7317: display:block;
7318: list-style:none;
7319: padding: 0;
1.870 tempelho 7320: }
7321:
1.795 www 7322: ul.LC_TabContentBigger li {
1.911 bisitz 7323: vertical-align:bottom;
7324: height: 30px;
7325: font-size:110%;
7326: font-weight:bold;
7327: color: #737373;
1.841 tempelho 7328: }
7329:
1.957 onken 7330: ul.LC_TabContentBigger li.active {
7331: position: relative;
7332: top: 1px;
7333: }
7334:
1.870 tempelho 7335: ul.LC_TabContentBigger li a {
1.911 bisitz 7336: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7337: height: 30px;
7338: line-height: 30px;
7339: text-align: center;
7340: display: block;
7341: text-decoration: none;
1.958 onken 7342: outline: none;
1.741 harmsja 7343: }
1.795 www 7344:
1.870 tempelho 7345: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7346: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7347: color:$font;
1.744 ehlerst 7348: }
1.795 www 7349:
1.870 tempelho 7350: ul.LC_TabContentBigger li b {
1.911 bisitz 7351: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7352: display: block;
7353: float: left;
7354: padding: 0 30px;
1.957 onken 7355: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7356: }
7357:
1.956 onken 7358: ul.LC_TabContentBigger li:hover b {
7359: color:$button_hover;
7360: }
7361:
1.870 tempelho 7362: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7363: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7364: color:$font;
1.957 onken 7365: border: 0;
1.741 harmsja 7366: }
1.693 droeschl 7367:
1.870 tempelho 7368:
1.862 bisitz 7369: ul.LC_CourseBreadcrumbs {
7370: background: $sidebg;
1.1020 raeburn 7371: height: 2em;
1.862 bisitz 7372: padding-left: 10px;
1.1020 raeburn 7373: margin: 0;
1.862 bisitz 7374: list-style-position: inside;
7375: }
7376:
1.911 bisitz 7377: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7378: ol#LC_PathBreadcrumbs {
1.911 bisitz 7379: padding-left: 10px;
7380: margin: 0;
1.933 droeschl 7381: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7382: }
7383:
1.911 bisitz 7384: ol#LC_MenuBreadcrumbs li,
7385: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7386: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7387: display: inline;
1.933 droeschl 7388: white-space: normal;
1.693 droeschl 7389: }
7390:
1.823 bisitz 7391: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7392: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7393: text-decoration: none;
7394: font-size:90%;
1.693 droeschl 7395: }
1.795 www 7396:
1.969 droeschl 7397: ol#LC_MenuBreadcrumbs h1 {
7398: display: inline;
7399: font-size: 90%;
7400: line-height: 2.5em;
7401: margin: 0;
7402: padding: 0;
7403: }
7404:
1.795 www 7405: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7406: text-decoration:none;
7407: font-size:100%;
7408: font-weight:bold;
1.693 droeschl 7409: }
1.795 www 7410:
1.840 bisitz 7411: .LC_Box {
1.911 bisitz 7412: border: solid 1px $lg_border_color;
7413: padding: 0 10px 10px 10px;
1.746 neumanie 7414: }
1.795 www 7415:
1.1020 raeburn 7416: .LC_DocsBox {
7417: border: solid 1px $lg_border_color;
7418: padding: 0 0 10px 10px;
7419: }
7420:
1.795 www 7421: .LC_AboutMe_Image {
1.911 bisitz 7422: float:left;
7423: margin-right:10px;
1.747 neumanie 7424: }
1.795 www 7425:
7426: .LC_Clear_AboutMe_Image {
1.911 bisitz 7427: clear:left;
1.747 neumanie 7428: }
1.795 www 7429:
1.721 harmsja 7430: dl.LC_ListStyleClean dt {
1.911 bisitz 7431: padding-right: 5px;
7432: display: table-header-group;
1.693 droeschl 7433: }
7434:
1.721 harmsja 7435: dl.LC_ListStyleClean dd {
1.911 bisitz 7436: display: table-row;
1.693 droeschl 7437: }
7438:
1.721 harmsja 7439: .LC_ListStyleClean,
7440: .LC_ListStyleSimple,
7441: .LC_ListStyleNormal,
1.795 www 7442: .LC_ListStyleSpecial {
1.911 bisitz 7443: /* display:block; */
7444: list-style-position: inside;
7445: list-style-type: none;
7446: overflow: hidden;
7447: padding: 0;
1.693 droeschl 7448: }
7449:
1.721 harmsja 7450: .LC_ListStyleSimple li,
7451: .LC_ListStyleSimple dd,
7452: .LC_ListStyleNormal li,
7453: .LC_ListStyleNormal dd,
7454: .LC_ListStyleSpecial li,
1.795 www 7455: .LC_ListStyleSpecial dd {
1.911 bisitz 7456: margin: 0;
7457: padding: 5px 5px 5px 10px;
7458: clear: both;
1.693 droeschl 7459: }
7460:
1.721 harmsja 7461: .LC_ListStyleClean li,
7462: .LC_ListStyleClean dd {
1.911 bisitz 7463: padding-top: 0;
7464: padding-bottom: 0;
1.693 droeschl 7465: }
7466:
1.721 harmsja 7467: .LC_ListStyleSimple dd,
1.795 www 7468: .LC_ListStyleSimple li {
1.911 bisitz 7469: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7470: }
7471:
1.721 harmsja 7472: .LC_ListStyleSpecial li,
7473: .LC_ListStyleSpecial dd {
1.911 bisitz 7474: list-style-type: none;
7475: background-color: RGB(220, 220, 220);
7476: margin-bottom: 4px;
1.693 droeschl 7477: }
7478:
1.721 harmsja 7479: table.LC_SimpleTable {
1.911 bisitz 7480: margin:5px;
7481: border:solid 1px $lg_border_color;
1.795 www 7482: }
1.693 droeschl 7483:
1.721 harmsja 7484: table.LC_SimpleTable tr {
1.911 bisitz 7485: padding: 0;
7486: border:solid 1px $lg_border_color;
1.693 droeschl 7487: }
1.795 www 7488:
7489: table.LC_SimpleTable thead {
1.911 bisitz 7490: background:rgb(220,220,220);
1.693 droeschl 7491: }
7492:
1.721 harmsja 7493: div.LC_columnSection {
1.911 bisitz 7494: display: block;
7495: clear: both;
7496: overflow: hidden;
7497: margin: 0;
1.693 droeschl 7498: }
7499:
1.721 harmsja 7500: div.LC_columnSection>* {
1.911 bisitz 7501: float: left;
7502: margin: 10px 20px 10px 0;
7503: overflow:hidden;
1.693 droeschl 7504: }
1.721 harmsja 7505:
1.795 www 7506: table em {
1.911 bisitz 7507: font-weight: bold;
7508: font-style: normal;
1.748 schulted 7509: }
1.795 www 7510:
1.779 bisitz 7511: table.LC_tableBrowseRes,
1.795 www 7512: table.LC_tableOfContent {
1.911 bisitz 7513: border:none;
7514: border-spacing: 1px;
7515: padding: 3px;
7516: background-color: #FFFFFF;
7517: font-size: 90%;
1.753 droeschl 7518: }
1.789 droeschl 7519:
1.911 bisitz 7520: table.LC_tableOfContent {
7521: border-collapse: collapse;
1.789 droeschl 7522: }
7523:
1.771 droeschl 7524: table.LC_tableBrowseRes a,
1.768 schulted 7525: table.LC_tableOfContent a {
1.911 bisitz 7526: background-color: transparent;
7527: text-decoration: none;
1.753 droeschl 7528: }
7529:
1.795 www 7530: table.LC_tableOfContent img {
1.911 bisitz 7531: border: none;
7532: height: 1.3em;
7533: vertical-align: text-bottom;
7534: margin-right: 0.3em;
1.753 droeschl 7535: }
1.757 schulted 7536:
1.795 www 7537: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7538: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7539: }
7540:
1.795 www 7541: a#LC_content_toolbar_everything {
1.911 bisitz 7542: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7543: }
7544:
1.795 www 7545: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7546: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7547: }
7548:
1.795 www 7549: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7550: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7551: }
7552:
1.795 www 7553: a#LC_content_toolbar_changefolder {
1.911 bisitz 7554: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7555: }
7556:
1.795 www 7557: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7558: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7559: }
7560:
1.1043 raeburn 7561: a#LC_content_toolbar_edittoplevel {
7562: background-image:url(/res/adm/pages/edittoplevel.gif);
7563: }
7564:
1.795 www 7565: ul#LC_toolbar li a:hover {
1.911 bisitz 7566: background-position: bottom center;
1.757 schulted 7567: }
7568:
1.795 www 7569: ul#LC_toolbar {
1.911 bisitz 7570: padding: 0;
7571: margin: 2px;
7572: list-style:none;
7573: position:relative;
7574: background-color:white;
1.1075.2.9 raeburn 7575: overflow: auto;
1.757 schulted 7576: }
7577:
1.795 www 7578: ul#LC_toolbar li {
1.911 bisitz 7579: border:1px solid white;
7580: padding: 0;
7581: margin: 0;
7582: float: left;
7583: display:inline;
7584: vertical-align:middle;
1.1075.2.9 raeburn 7585: white-space: nowrap;
1.911 bisitz 7586: }
1.757 schulted 7587:
1.783 amueller 7588:
1.795 www 7589: a.LC_toolbarItem {
1.911 bisitz 7590: display:block;
7591: padding: 0;
7592: margin: 0;
7593: height: 32px;
7594: width: 32px;
7595: color:white;
7596: border: none;
7597: background-repeat:no-repeat;
7598: background-color:transparent;
1.757 schulted 7599: }
7600:
1.915 droeschl 7601: ul.LC_funclist {
7602: margin: 0;
7603: padding: 0.5em 1em 0.5em 0;
7604: }
7605:
1.933 droeschl 7606: ul.LC_funclist > li:first-child {
7607: font-weight:bold;
7608: margin-left:0.8em;
7609: }
7610:
1.915 droeschl 7611: ul.LC_funclist + ul.LC_funclist {
7612: /*
7613: left border as a seperator if we have more than
7614: one list
7615: */
7616: border-left: 1px solid $sidebg;
7617: /*
7618: this hides the left border behind the border of the
7619: outer box if element is wrapped to the next 'line'
7620: */
7621: margin-left: -1px;
7622: }
7623:
1.843 bisitz 7624: ul.LC_funclist li {
1.915 droeschl 7625: display: inline;
1.782 bisitz 7626: white-space: nowrap;
1.915 droeschl 7627: margin: 0 0 0 25px;
7628: line-height: 150%;
1.782 bisitz 7629: }
7630:
1.974 wenzelju 7631: .LC_hidden {
7632: display: none;
7633: }
7634:
1.1030 www 7635: .LCmodal-overlay {
7636: position:fixed;
7637: top:0;
7638: right:0;
7639: bottom:0;
7640: left:0;
7641: height:100%;
7642: width:100%;
7643: margin:0;
7644: padding:0;
7645: background:#999;
7646: opacity:.75;
7647: filter: alpha(opacity=75);
7648: -moz-opacity: 0.75;
7649: z-index:101;
7650: }
7651:
7652: * html .LCmodal-overlay {
7653: position: absolute;
7654: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7655: }
7656:
7657: .LCmodal-window {
7658: position:fixed;
7659: top:50%;
7660: left:50%;
7661: margin:0;
7662: padding:0;
7663: z-index:102;
7664: }
7665:
7666: * html .LCmodal-window {
7667: position:absolute;
7668: }
7669:
7670: .LCclose-window {
7671: position:absolute;
7672: width:32px;
7673: height:32px;
7674: right:8px;
7675: top:8px;
7676: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7677: text-indent:-99999px;
7678: overflow:hidden;
7679: cursor:pointer;
7680: }
7681:
1.1075.2.17 raeburn 7682: /*
7683: styles used by TTH when "Default set of options to pass to tth/m
7684: when converting TeX" in course settings has been set
7685:
7686: option passed: -t
7687:
7688: */
7689:
7690: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7691: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7692: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7693: td div.norm {line-height:normal;}
7694:
7695: /*
7696: option passed -y3
7697: */
7698:
7699: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7700: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7701: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7702:
1.1075.2.121 raeburn 7703: #LC_minitab_header {
7704: float:left;
7705: width:100%;
7706: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
7707: font-size:93%;
7708: line-height:normal;
7709: margin: 0.5em 0 0.5em 0;
7710: }
7711: #LC_minitab_header ul {
7712: margin:0;
7713: padding:10px 10px 0;
7714: list-style:none;
7715: }
7716: #LC_minitab_header li {
7717: float:left;
7718: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
7719: margin:0;
7720: padding:0 0 0 9px;
7721: }
7722: #LC_minitab_header a {
7723: display:block;
7724: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
7725: padding:5px 15px 4px 6px;
7726: }
7727: #LC_minitab_header #LC_current_minitab {
7728: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
7729: }
7730: #LC_minitab_header #LC_current_minitab a {
7731: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
7732: padding-bottom:5px;
7733: }
7734:
7735:
1.343 albertel 7736: END
7737: }
7738:
1.306 albertel 7739: =pod
7740:
7741: =item * &headtag()
7742:
7743: Returns a uniform footer for LON-CAPA web pages.
7744:
1.307 albertel 7745: Inputs: $title - optional title for the head
7746: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7747: $args - optional arguments
1.319 albertel 7748: force_register - if is true call registerurl so the remote is
7749: informed
1.415 albertel 7750: redirect -> array ref of
7751: 1- seconds before redirect occurs
7752: 2- url to redirect to
7753: 3- whether the side effect should occur
1.315 albertel 7754: (side effect of setting
7755: $env{'internal.head.redirect'} to the url
7756: redirected too)
1.352 albertel 7757: domain -> force to color decorate a page for a specific
7758: domain
7759: function -> force usage of a specific rolish color scheme
7760: bgcolor -> override the default page bgcolor
1.460 albertel 7761: no_auto_mt_title
7762: -> prevent &mt()ing the title arg
1.464 albertel 7763:
1.306 albertel 7764: =cut
7765:
7766: sub headtag {
1.313 albertel 7767: my ($title,$head_extra,$args) = @_;
1.306 albertel 7768:
1.363 albertel 7769: my $function = $args->{'function'} || &get_users_function();
7770: my $domain = $args->{'domain'} || &determinedomain();
7771: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1075.2.52 raeburn 7772: my $httphost = $args->{'use_absolute'};
1.418 albertel 7773: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7774: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7775: #time(),
1.418 albertel 7776: $env{'environment.color.timestamp'},
1.363 albertel 7777: $function,$domain,$bgcolor);
7778:
1.369 www 7779: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7780:
1.308 albertel 7781: my $result =
7782: '<head>'.
1.1075.2.56 raeburn 7783: &font_settings($args);
1.319 albertel 7784:
1.1075.2.72 raeburn 7785: my $inhibitprint;
7786: if ($args->{'print_suppress'}) {
7787: $inhibitprint = &print_suppression();
7788: }
1.1064 raeburn 7789:
1.461 albertel 7790: if (!$args->{'frameset'}) {
7791: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7792: }
1.1075.2.12 raeburn 7793: if ($args->{'force_register'}) {
7794: $result .= &Apache::lonmenu::registerurl(1);
1.319 albertel 7795: }
1.436 albertel 7796: if (!$args->{'no_nav_bar'}
7797: && !$args->{'only_body'}
7798: && !$args->{'frameset'}) {
1.1075.2.52 raeburn 7799: $result .= &help_menu_js($httphost);
1.1032 www 7800: $result.=&modal_window();
1.1038 www 7801: $result.=&togglebox_script();
1.1034 www 7802: $result.=&wishlist_window();
1.1041 www 7803: $result.=&LCprogressbarUpdate_script();
1.1034 www 7804: } else {
7805: if ($args->{'add_modal'}) {
7806: $result.=&modal_window();
7807: }
7808: if ($args->{'add_wishlist'}) {
7809: $result.=&wishlist_window();
7810: }
1.1038 www 7811: if ($args->{'add_togglebox'}) {
7812: $result.=&togglebox_script();
7813: }
1.1041 www 7814: if ($args->{'add_progressbar'}) {
7815: $result.=&LCprogressbarUpdate_script();
7816: }
1.436 albertel 7817: }
1.314 albertel 7818: if (ref($args->{'redirect'})) {
1.414 albertel 7819: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7820: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7821: if (!$inhibit_continue) {
7822: $env{'internal.head.redirect'} = $url;
7823: }
1.313 albertel 7824: $result.=<<ADDMETA
7825: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7826: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7827: ADDMETA
1.1075.2.89 raeburn 7828: } else {
7829: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
7830: my $requrl = $env{'request.uri'};
7831: if ($requrl eq '') {
7832: $requrl = $ENV{'REQUEST_URI'};
7833: $requrl =~ s/\?.+$//;
7834: }
7835: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
7836: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
7837: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
7838: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
7839: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
7840: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
7841: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
7842: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7843: if ($domdefs{'offloadnow'}{$lonhost}) {
7844: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
7845: if (($newserver) && ($newserver ne $lonhost)) {
7846: my $numsec = 5;
7847: my $timeout = $numsec * 1000;
7848: my ($newurl,$locknum,%locks,$msg);
7849: if ($env{'request.role.adv'}) {
7850: ($locknum,%locks) = &Apache::lonnet::get_locks();
7851: }
7852: my $disable_submit = 0;
7853: if ($requrl =~ /$LONCAPA::assess_re/) {
7854: $disable_submit = 1;
7855: }
7856: if ($locknum) {
7857: my @lockinfo = sort(values(%locks));
7858: $msg = &mt('Once the following tasks are complete: ')."\\n".
7859: join(", ",sort(values(%locks)))."\\n".
7860: &mt('your session will be transferred to a different server, after you click "Roles".');
7861: } else {
7862: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
7863: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
7864: }
7865: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
7866: $newurl = '/adm/switchserver?otherserver='.$newserver;
7867: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
7868: $newurl .= '&role='.$env{'request.role'};
7869: }
7870: if ($env{'request.symb'}) {
7871: $newurl .= '&symb='.$env{'request.symb'};
7872: } else {
7873: $newurl .= '&origurl='.$requrl;
7874: }
7875: }
1.1075.2.98 raeburn 7876: &js_escape(\$msg);
1.1075.2.89 raeburn 7877: $result.=<<OFFLOAD
7878: <meta http-equiv="pragma" content="no-cache" />
7879: <script type="text/javascript">
1.1075.2.92 raeburn 7880: // <![CDATA[
1.1075.2.89 raeburn 7881: function LC_Offload_Now() {
7882: var dest = "$newurl";
7883: if (dest != '') {
7884: window.location.href="$newurl";
7885: }
7886: }
1.1075.2.92 raeburn 7887: \$(document).ready(function () {
7888: window.alert('$msg');
7889: if ($disable_submit) {
1.1075.2.89 raeburn 7890: \$(".LC_hwk_submit").prop("disabled", true);
7891: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1075.2.92 raeburn 7892: }
7893: setTimeout('LC_Offload_Now()', $timeout);
7894: });
7895: // ]]>
1.1075.2.89 raeburn 7896: </script>
7897: OFFLOAD
7898: }
7899: }
7900: }
7901: }
7902: }
7903: }
1.313 albertel 7904: }
1.306 albertel 7905: if (!defined($title)) {
7906: $title = 'The LearningOnline Network with CAPA';
7907: }
1.460 albertel 7908: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7909: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1075.2.61 raeburn 7910: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7911: if (!$args->{'frameset'}) {
7912: $result .= ' /';
7913: }
7914: $result .= '>'
1.1064 raeburn 7915: .$inhibitprint
1.414 albertel 7916: .$head_extra;
1.1075.2.108 raeburn 7917: my $clientmobile;
7918: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
7919: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
7920: } else {
7921: $clientmobile = $env{'browser.mobile'};
7922: }
7923: if ($clientmobile) {
1.1075.2.42 raeburn 7924: $result .= '
7925: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7926: <meta name="apple-mobile-web-app-capable" content="yes" />';
7927: }
1.1075.2.126 raeburn 7928: $result .= '<meta name="google" content="notranslate" />'."\n";
1.962 droeschl 7929: return $result.'</head>';
1.306 albertel 7930: }
7931:
7932: =pod
7933:
1.340 albertel 7934: =item * &font_settings()
7935:
7936: Returns neccessary <meta> to set the proper encoding
7937:
1.1075.2.56 raeburn 7938: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7939:
7940: =cut
7941:
7942: sub font_settings {
1.1075.2.56 raeburn 7943: my ($args) = @_;
1.340 albertel 7944: my $headerstring='';
1.1075.2.56 raeburn 7945: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7946: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.340 albertel 7947: $headerstring.=
1.1075.2.61 raeburn 7948: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7949: if (!$args->{'frameset'}) {
7950: $headerstring.= ' /';
7951: }
7952: $headerstring .= '>'."\n";
1.340 albertel 7953: }
7954: return $headerstring;
7955: }
7956:
1.341 albertel 7957: =pod
7958:
1.1064 raeburn 7959: =item * &print_suppression()
7960:
7961: In course context returns css which causes the body to be blank when media="print",
7962: if printout generation is unavailable for the current resource.
7963:
7964: This could be because:
7965:
7966: (a) printstartdate is in the future
7967:
7968: (b) printenddate is in the past
7969:
7970: (c) there is an active exam block with "printout"
7971: functionality blocked
7972:
7973: Users with pav, pfo or evb privileges are exempt.
7974:
7975: Inputs: none
7976:
7977: =cut
7978:
7979:
7980: sub print_suppression {
7981: my $noprint;
7982: if ($env{'request.course.id'}) {
7983: my $scope = $env{'request.course.id'};
7984: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7985: (&Apache::lonnet::allowed('pfo',$scope))) {
7986: return;
7987: }
7988: if ($env{'request.course.sec'} ne '') {
7989: $scope .= "/$env{'request.course.sec'}";
7990: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7991: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7992: return;
1.1064 raeburn 7993: }
7994: }
7995: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7996: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.73 raeburn 7997: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 7998: if ($blocked) {
7999: my $checkrole = "cm./$cdom/$cnum";
8000: if ($env{'request.course.sec'} ne '') {
8001: $checkrole .= "/$env{'request.course.sec'}";
8002: }
8003: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8004: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8005: $noprint = 1;
8006: }
8007: }
8008: unless ($noprint) {
8009: my $symb = &Apache::lonnet::symbread();
8010: if ($symb ne '') {
8011: my $navmap = Apache::lonnavmaps::navmap->new();
8012: if (ref($navmap)) {
8013: my $res = $navmap->getBySymb($symb);
8014: if (ref($res)) {
8015: if (!$res->resprintable()) {
8016: $noprint = 1;
8017: }
8018: }
8019: }
8020: }
8021: }
8022: if ($noprint) {
8023: return <<"ENDSTYLE";
8024: <style type="text/css" media="print">
8025: body { display:none }
8026: </style>
8027: ENDSTYLE
8028: }
8029: }
8030: return;
8031: }
8032:
8033: =pod
8034:
1.341 albertel 8035: =item * &xml_begin()
8036:
8037: Returns the needed doctype and <html>
8038:
8039: Inputs: none
8040:
8041: =cut
8042:
8043: sub xml_begin {
1.1075.2.61 raeburn 8044: my ($is_frameset) = @_;
1.341 albertel 8045: my $output='';
8046:
8047: if ($env{'browser.mathml'}) {
8048: $output='<?xml version="1.0"?>'
8049: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8050: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8051:
8052: # .'<!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">] >'
8053: .'<!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">'
8054: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8055: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1075.2.61 raeburn 8056: } elsif ($is_frameset) {
8057: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8058: '<html>'."\n";
1.341 albertel 8059: } else {
1.1075.2.61 raeburn 8060: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8061: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8062: }
8063: return $output;
8064: }
1.340 albertel 8065:
8066: =pod
8067:
1.306 albertel 8068: =item * &start_page()
8069:
8070: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8071:
1.648 raeburn 8072: Inputs:
8073:
8074: =over 4
8075:
8076: $title - optional title for the page
8077:
8078: $head_extra - optional extra HTML to incude inside the <head>
8079:
8080: $args - additional optional args supported are:
8081:
8082: =over 8
8083:
8084: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8085: arg on
1.814 bisitz 8086: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8087: add_entries -> additional attributes to add to the <body>
8088: domain -> force to color decorate a page for a
1.317 albertel 8089: specific domain
1.648 raeburn 8090: function -> force usage of a specific rolish color
1.317 albertel 8091: scheme
1.648 raeburn 8092: redirect -> see &headtag()
8093: bgcolor -> override the default page bg color
8094: js_ready -> return a string ready for being used in
1.317 albertel 8095: a javascript writeln
1.648 raeburn 8096: html_encode -> return a string ready for being used in
1.320 albertel 8097: a html attribute
1.648 raeburn 8098: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8099: $forcereg arg
1.648 raeburn 8100: frameset -> if true will start with a <frameset>
1.330 albertel 8101: rather than <body>
1.648 raeburn 8102: skip_phases -> hash ref of
1.338 albertel 8103: head -> skip the <html><head> generation
8104: body -> skip all <body> generation
1.1075.2.12 raeburn 8105: no_inline_link -> if true and in remote mode, don't show the
8106: 'Switch To Inline Menu' link
1.648 raeburn 8107: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8108: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8109: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1075.2.123 raeburn 8110: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8111: to lonhtmlcommon::breadcrumbs
1.1075.2.15 raeburn 8112: group -> includes the current group, if page is for a
8113: specific group
1.361 albertel 8114:
1.648 raeburn 8115: =back
1.460 albertel 8116:
1.648 raeburn 8117: =back
1.562 albertel 8118:
1.306 albertel 8119: =cut
8120:
8121: sub start_page {
1.309 albertel 8122: my ($title,$head_extra,$args) = @_;
1.318 albertel 8123: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8124:
1.315 albertel 8125: $env{'internal.start_page'}++;
1.1075.2.15 raeburn 8126: my ($result,@advtools);
1.964 droeschl 8127:
1.338 albertel 8128: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1075.2.62 raeburn 8129: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8130: }
8131:
8132: if (! exists($args->{'skip_phases'}{'body'}) ) {
8133: if ($args->{'frameset'}) {
8134: my $attr_string = &make_attr_string($args->{'force_register'},
8135: $args->{'add_entries'});
8136: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8137: } else {
8138: $result .=
8139: &bodytag($title,
8140: $args->{'function'}, $args->{'add_entries'},
8141: $args->{'only_body'}, $args->{'domain'},
8142: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1075.2.12 raeburn 8143: $args->{'bgcolor'}, $args->{'no_inline_link'},
1.1075.2.15 raeburn 8144: $args, \@advtools);
1.831 bisitz 8145: }
1.330 albertel 8146: }
1.338 albertel 8147:
1.315 albertel 8148: if ($args->{'js_ready'}) {
1.713 kaisler 8149: $result = &js_ready($result);
1.315 albertel 8150: }
1.320 albertel 8151: if ($args->{'html_encode'}) {
1.713 kaisler 8152: $result = &html_encode($result);
8153: }
8154:
1.813 bisitz 8155: # Preparation for new and consistent functionlist at top of screen
8156: # if ($args->{'functionlist'}) {
8157: # $result .= &build_functionlist();
8158: #}
8159:
1.964 droeschl 8160: # Don't add anything more if only_body wanted or in const space
8161: return $result if $args->{'only_body'}
8162: || $env{'request.state'} eq 'construct';
1.813 bisitz 8163:
8164: #Breadcrumbs
1.758 kaisler 8165: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8166: &Apache::lonhtmlcommon::clear_breadcrumbs();
8167: #if any br links exists, add them to the breadcrumbs
8168: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8169: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8170: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8171: }
8172: }
1.1075.2.19 raeburn 8173: # if @advtools array contains items add then to the breadcrumbs
8174: if (@advtools > 0) {
8175: &Apache::lonmenu::advtools_crumbs(@advtools);
8176: }
1.1075.2.123 raeburn 8177: my $menulink;
8178: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8179: if (exists($args->{'bread_crumbs_nomenu'})) {
8180: $menulink = 0;
8181: } else {
8182: undef($menulink);
8183: }
1.758 kaisler 8184: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8185: if(exists($args->{'bread_crumbs_component'})){
1.1075.2.123 raeburn 8186: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.758 kaisler 8187: }else{
1.1075.2.123 raeburn 8188: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8189: }
1.1075.2.24 raeburn 8190: } elsif (($env{'environment.remote'} eq 'on') &&
8191: ($env{'form.inhibitmenu'} ne 'yes') &&
8192: ($env{'request.noversionuri'} =~ m{^/res/}) &&
8193: ($env{'request.noversionuri'} !~ m{^/res/adm/pages/})) {
1.1075.2.21 raeburn 8194: $result .= '<div style="padding:0;margin:0;clear:both"><hr /></div>';
1.320 albertel 8195: }
1.315 albertel 8196: return $result;
1.306 albertel 8197: }
8198:
8199: sub end_page {
1.315 albertel 8200: my ($args) = @_;
8201: $env{'internal.end_page'}++;
1.330 albertel 8202: my $result;
1.335 albertel 8203: if ($args->{'discussion'}) {
8204: my ($target,$parser);
8205: if (ref($args->{'discussion'})) {
8206: ($target,$parser) =($args->{'discussion'}{'target'},
8207: $args->{'discussion'}{'parser'});
8208: }
8209: $result .= &Apache::lonxml::xmlend($target,$parser);
8210: }
1.330 albertel 8211: if ($args->{'frameset'}) {
8212: $result .= '</frameset>';
8213: } else {
1.635 raeburn 8214: $result .= &endbodytag($args);
1.330 albertel 8215: }
1.1075.2.6 raeburn 8216: unless ($args->{'notbody'}) {
8217: $result .= "\n</html>";
8218: }
1.330 albertel 8219:
1.315 albertel 8220: if ($args->{'js_ready'}) {
1.317 albertel 8221: $result = &js_ready($result);
1.315 albertel 8222: }
1.335 albertel 8223:
1.320 albertel 8224: if ($args->{'html_encode'}) {
8225: $result = &html_encode($result);
8226: }
1.335 albertel 8227:
1.315 albertel 8228: return $result;
8229: }
8230:
1.1034 www 8231: sub wishlist_window {
8232: return(<<'ENDWISHLIST');
1.1046 raeburn 8233: <script type="text/javascript">
1.1034 www 8234: // <![CDATA[
8235: // <!-- BEGIN LON-CAPA Internal
8236: function set_wishlistlink(title, path) {
8237: if (!title) {
8238: title = document.title;
8239: title = title.replace(/^LON-CAPA /,'');
8240: }
1.1075.2.65 raeburn 8241: title = encodeURIComponent(title);
1.1075.2.83 raeburn 8242: title = title.replace("'","\\\'");
1.1034 www 8243: if (!path) {
8244: path = location.pathname;
8245: }
1.1075.2.65 raeburn 8246: path = encodeURIComponent(path);
1.1075.2.83 raeburn 8247: path = path.replace("'","\\\'");
1.1034 www 8248: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8249: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8250: }
8251: // END LON-CAPA Internal -->
8252: // ]]>
8253: </script>
8254: ENDWISHLIST
8255: }
8256:
1.1030 www 8257: sub modal_window {
8258: return(<<'ENDMODAL');
1.1046 raeburn 8259: <script type="text/javascript">
1.1030 www 8260: // <![CDATA[
8261: // <!-- BEGIN LON-CAPA Internal
8262: var modalWindow = {
8263: parent:"body",
8264: windowId:null,
8265: content:null,
8266: width:null,
8267: height:null,
8268: close:function()
8269: {
8270: $(".LCmodal-window").remove();
8271: $(".LCmodal-overlay").remove();
8272: },
8273: open:function()
8274: {
8275: var modal = "";
8276: modal += "<div class=\"LCmodal-overlay\"></div>";
8277: 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;\">";
8278: modal += this.content;
8279: modal += "</div>";
8280:
8281: $(this.parent).append(modal);
8282:
8283: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8284: $(".LCclose-window").click(function(){modalWindow.close();});
8285: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8286: }
8287: };
1.1075.2.42 raeburn 8288: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8289: {
1.1075.2.119 raeburn 8290: source = source.replace(/'/g,"'");
1.1030 www 8291: modalWindow.windowId = "myModal";
8292: modalWindow.width = width;
8293: modalWindow.height = height;
1.1075.2.80 raeburn 8294: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8295: modalWindow.open();
1.1075.2.87 raeburn 8296: };
1.1030 www 8297: // END LON-CAPA Internal -->
8298: // ]]>
8299: </script>
8300: ENDMODAL
8301: }
8302:
8303: sub modal_link {
1.1075.2.42 raeburn 8304: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8305: unless ($width) { $width=480; }
8306: unless ($height) { $height=400; }
1.1031 www 8307: unless ($scrolling) { $scrolling='yes'; }
1.1075.2.42 raeburn 8308: unless ($transparency) { $transparency='true'; }
8309:
1.1074 raeburn 8310: my $target_attr;
8311: if (defined($target)) {
8312: $target_attr = 'target="'.$target.'"';
8313: }
8314: return <<"ENDLINK";
1.1075.2.42 raeburn 8315: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8316: $linktext</a>
8317: ENDLINK
1.1030 www 8318: }
8319:
1.1032 www 8320: sub modal_adhoc_script {
8321: my ($funcname,$width,$height,$content)=@_;
8322: return (<<ENDADHOC);
1.1046 raeburn 8323: <script type="text/javascript">
1.1032 www 8324: // <![CDATA[
8325: var $funcname = function()
8326: {
8327: modalWindow.windowId = "myModal";
8328: modalWindow.width = $width;
8329: modalWindow.height = $height;
8330: modalWindow.content = '$content';
8331: modalWindow.open();
8332: };
8333: // ]]>
8334: </script>
8335: ENDADHOC
8336: }
8337:
1.1041 www 8338: sub modal_adhoc_inner {
8339: my ($funcname,$width,$height,$content)=@_;
8340: my $innerwidth=$width-20;
8341: $content=&js_ready(
1.1042 www 8342: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
1.1075.2.42 raeburn 8343: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8344: $content.
1.1041 www 8345: &end_scrollbox().
1.1075.2.42 raeburn 8346: &end_page()
1.1041 www 8347: );
8348: return &modal_adhoc_script($funcname,$width,$height,$content);
8349: }
8350:
8351: sub modal_adhoc_window {
8352: my ($funcname,$width,$height,$content,$linktext)=@_;
8353: return &modal_adhoc_inner($funcname,$width,$height,$content).
8354: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8355: }
8356:
8357: sub modal_adhoc_launch {
8358: my ($funcname,$width,$height,$content)=@_;
8359: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8360: <script type="text/javascript">
8361: // <![CDATA[
8362: $funcname();
8363: // ]]>
8364: </script>
8365: ENDLAUNCH
8366: }
8367:
8368: sub modal_adhoc_close {
8369: return (<<ENDCLOSE);
8370: <script type="text/javascript">
8371: // <![CDATA[
8372: modalWindow.close();
8373: // ]]>
8374: </script>
8375: ENDCLOSE
8376: }
8377:
1.1038 www 8378: sub togglebox_script {
8379: return(<<ENDTOGGLE);
8380: <script type="text/javascript">
8381: // <![CDATA[
8382: function LCtoggleDisplay(id,hidetext,showtext) {
8383: link = document.getElementById(id + "link").childNodes[0];
8384: with (document.getElementById(id).style) {
8385: if (display == "none" ) {
8386: display = "inline";
8387: link.nodeValue = hidetext;
8388: } else {
8389: display = "none";
8390: link.nodeValue = showtext;
8391: }
8392: }
8393: }
8394: // ]]>
8395: </script>
8396: ENDTOGGLE
8397: }
8398:
1.1039 www 8399: sub start_togglebox {
8400: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8401: unless ($heading) { $heading=''; } else { $heading.=' '; }
8402: unless ($showtext) { $showtext=&mt('show'); }
8403: unless ($hidetext) { $hidetext=&mt('hide'); }
8404: unless ($headerbg) { $headerbg='#FFFFFF'; }
8405: return &start_data_table().
8406: &start_data_table_header_row().
8407: '<td bgcolor="'.$headerbg.'">'.$heading.
8408: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8409: $showtext.'\')">'.$showtext.'</a>]</td>'.
8410: &end_data_table_header_row().
8411: '<tr id="'.$id.'" style="display:none""><td>';
8412: }
8413:
8414: sub end_togglebox {
8415: return '</td></tr>'.&end_data_table();
8416: }
8417:
1.1041 www 8418: sub LCprogressbar_script {
1.1045 www 8419: my ($id)=@_;
1.1041 www 8420: return(<<ENDPROGRESS);
8421: <script type="text/javascript">
8422: // <![CDATA[
1.1045 www 8423: \$('#progressbar$id').progressbar({
1.1041 www 8424: value: 0,
8425: change: function(event, ui) {
8426: var newVal = \$(this).progressbar('option', 'value');
8427: \$('.pblabel', this).text(LCprogressTxt);
8428: }
8429: });
8430: // ]]>
8431: </script>
8432: ENDPROGRESS
8433: }
8434:
8435: sub LCprogressbarUpdate_script {
8436: return(<<ENDPROGRESSUPDATE);
8437: <style type="text/css">
8438: .ui-progressbar { position:relative; }
8439: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8440: </style>
8441: <script type="text/javascript">
8442: // <![CDATA[
1.1045 www 8443: var LCprogressTxt='---';
8444:
8445: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8446: LCprogressTxt=progresstext;
1.1045 www 8447: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8448: }
8449: // ]]>
8450: </script>
8451: ENDPROGRESSUPDATE
8452: }
8453:
1.1042 www 8454: my $LClastpercent;
1.1045 www 8455: my $LCidcnt;
8456: my $LCcurrentid;
1.1042 www 8457:
1.1041 www 8458: sub LCprogressbar {
1.1042 www 8459: my ($r)=(@_);
8460: $LClastpercent=0;
1.1045 www 8461: $LCidcnt++;
8462: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8463: my $starting=&mt('Starting');
8464: my $content=(<<ENDPROGBAR);
1.1045 www 8465: <div id="progressbar$LCcurrentid">
1.1041 www 8466: <span class="pblabel">$starting</span>
8467: </div>
8468: ENDPROGBAR
1.1045 www 8469: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8470: }
8471:
8472: sub LCprogressbarUpdate {
1.1042 www 8473: my ($r,$val,$text)=@_;
8474: unless ($val) {
8475: if ($LClastpercent) {
8476: $val=$LClastpercent;
8477: } else {
8478: $val=0;
8479: }
8480: }
1.1041 www 8481: if ($val<0) { $val=0; }
8482: if ($val>100) { $val=0; }
1.1042 www 8483: $LClastpercent=$val;
1.1041 www 8484: unless ($text) { $text=$val.'%'; }
8485: $text=&js_ready($text);
1.1044 www 8486: &r_print($r,<<ENDUPDATE);
1.1041 www 8487: <script type="text/javascript">
8488: // <![CDATA[
1.1045 www 8489: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8490: // ]]>
8491: </script>
8492: ENDUPDATE
1.1035 www 8493: }
8494:
1.1042 www 8495: sub LCprogressbarClose {
8496: my ($r)=@_;
8497: $LClastpercent=0;
1.1044 www 8498: &r_print($r,<<ENDCLOSE);
1.1042 www 8499: <script type="text/javascript">
8500: // <![CDATA[
1.1045 www 8501: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8502: // ]]>
8503: </script>
8504: ENDCLOSE
1.1044 www 8505: }
8506:
8507: sub r_print {
8508: my ($r,$to_print)=@_;
8509: if ($r) {
8510: $r->print($to_print);
8511: $r->rflush();
8512: } else {
8513: print($to_print);
8514: }
1.1042 www 8515: }
8516:
1.320 albertel 8517: sub html_encode {
8518: my ($result) = @_;
8519:
1.322 albertel 8520: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8521:
8522: return $result;
8523: }
1.1044 www 8524:
1.317 albertel 8525: sub js_ready {
8526: my ($result) = @_;
8527:
1.323 albertel 8528: $result =~ s/[\n\r]/ /xmsg;
8529: $result =~ s/\\/\\\\/xmsg;
8530: $result =~ s/'/\\'/xmsg;
1.372 albertel 8531: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8532:
8533: return $result;
8534: }
8535:
1.315 albertel 8536: sub validate_page {
8537: if ( exists($env{'internal.start_page'})
1.316 albertel 8538: && $env{'internal.start_page'} > 1) {
8539: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8540: $env{'internal.start_page'}.' '.
1.316 albertel 8541: $ENV{'request.filename'});
1.315 albertel 8542: }
8543: if ( exists($env{'internal.end_page'})
1.316 albertel 8544: && $env{'internal.end_page'} > 1) {
8545: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8546: $env{'internal.end_page'}.' '.
1.316 albertel 8547: $env{'request.filename'});
1.315 albertel 8548: }
8549: if ( exists($env{'internal.start_page'})
8550: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8551: &Apache::lonnet::logthis('start_page called without end_page '.
8552: $env{'request.filename'});
1.315 albertel 8553: }
8554: if ( ! exists($env{'internal.start_page'})
8555: && exists($env{'internal.end_page'})) {
1.316 albertel 8556: &Apache::lonnet::logthis('end_page called without start_page'.
8557: $env{'request.filename'});
1.315 albertel 8558: }
1.306 albertel 8559: }
1.315 albertel 8560:
1.996 www 8561:
8562: sub start_scrollbox {
1.1075.2.56 raeburn 8563: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8564: unless ($outerwidth) { $outerwidth='520px'; }
8565: unless ($width) { $width='500px'; }
8566: unless ($height) { $height='200px'; }
1.1075 raeburn 8567: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8568: if ($id ne '') {
1.1075.2.42 raeburn 8569: $table_id = ' id="table_'.$id.'"';
8570: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8571: }
1.1075 raeburn 8572: if ($bgcolor ne '') {
8573: $tdcol = "background-color: $bgcolor;";
8574: }
1.1075.2.42 raeburn 8575: my $nicescroll_js;
8576: if ($env{'browser.mobile'}) {
8577: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8578: }
1.1075 raeburn 8579: return <<"END";
1.1075.2.42 raeburn 8580: $nicescroll_js
8581:
8582: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
1.1075.2.56 raeburn 8583: <div style="overflow:auto; width:$width; height:$height;"$div_id>
1.1075 raeburn 8584: END
1.996 www 8585: }
8586:
8587: sub end_scrollbox {
1.1036 www 8588: return '</div></td></tr></table>';
1.996 www 8589: }
8590:
1.1075.2.42 raeburn 8591: sub nicescroll_javascript {
8592: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8593: my %options;
8594: if (ref($cursor) eq 'HASH') {
8595: %options = %{$cursor};
8596: }
8597: unless ($options{'railalign'} =~ /^left|right$/) {
8598: $options{'railalign'} = 'left';
8599: }
8600: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8601: my $function = &get_users_function();
8602: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
8603: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8604: $options{'cursorcolor'} = '#00F';
8605: }
8606: }
8607: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8608: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
8609: $options{'cursoropacity'}='1.0';
8610: }
8611: } else {
8612: $options{'cursoropacity'}='1.0';
8613: }
8614: if ($options{'cursorfixedheight'} eq 'none') {
8615: delete($options{'cursorfixedheight'});
8616: } else {
8617: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8618: }
8619: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8620: delete($options{'railoffset'});
8621: }
8622: my @niceoptions;
8623: while (my($key,$value) = each(%options)) {
8624: if ($value =~ /^\{.+\}$/) {
8625: push(@niceoptions,$key.':'.$value);
8626: } else {
8627: push(@niceoptions,$key.':"'.$value.'"');
8628: }
8629: }
8630: my $nicescroll_js = '
8631: $(document).ready(
8632: function() {
8633: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8634: }
8635: );
8636: ';
8637: if ($framecheck) {
8638: $nicescroll_js .= '
8639: function expand_div(caller) {
8640: if (top === self) {
8641: document.getElementById("'.$id.'").style.width = "auto";
8642: document.getElementById("'.$id.'").style.height = "auto";
8643: } else {
8644: try {
8645: if (parent.frames) {
8646: if (parent.frames.length > 1) {
8647: var framesrc = parent.frames[1].location.href;
8648: var currsrc = framesrc.replace(/\#.*$/,"");
8649: if ((caller == "search") || (currsrc == "'.$location.'")) {
8650: document.getElementById("'.$id.'").style.width = "auto";
8651: document.getElementById("'.$id.'").style.height = "auto";
8652: }
8653: }
8654: }
8655: } catch (e) {
8656: return;
8657: }
8658: }
8659: return;
8660: }
8661: ';
8662: }
8663: if ($needjsready) {
8664: $nicescroll_js = '
8665: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8666: } else {
8667: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8668: }
8669: return $nicescroll_js;
8670: }
8671:
1.318 albertel 8672: sub simple_error_page {
1.1075.2.49 raeburn 8673: my ($r,$title,$msg,$args) = @_;
8674: if (ref($args) eq 'HASH') {
8675: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8676: } else {
8677: $msg = &mt($msg);
8678: }
8679:
1.318 albertel 8680: my $page =
8681: &Apache::loncommon::start_page($title).
1.1075.2.49 raeburn 8682: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8683: &Apache::loncommon::end_page();
8684: if (ref($r)) {
8685: $r->print($page);
1.327 albertel 8686: return;
1.318 albertel 8687: }
8688: return $page;
8689: }
1.347 albertel 8690:
8691: {
1.610 albertel 8692: my @row_count;
1.961 onken 8693:
8694: sub start_data_table_count {
8695: unshift(@row_count, 0);
8696: return;
8697: }
8698:
8699: sub end_data_table_count {
8700: shift(@row_count);
8701: return;
8702: }
8703:
1.347 albertel 8704: sub start_data_table {
1.1018 raeburn 8705: my ($add_class,$id) = @_;
1.422 albertel 8706: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8707: my $table_id;
8708: if (defined($id)) {
8709: $table_id = ' id="'.$id.'"';
8710: }
1.961 onken 8711: &start_data_table_count();
1.1018 raeburn 8712: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8713: }
8714:
8715: sub end_data_table {
1.961 onken 8716: &end_data_table_count();
1.389 albertel 8717: return '</table>'."\n";;
1.347 albertel 8718: }
8719:
8720: sub start_data_table_row {
1.974 wenzelju 8721: my ($add_class, $id) = @_;
1.610 albertel 8722: $row_count[0]++;
8723: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8724: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8725: $id = (' id="'.$id.'"') unless ($id eq '');
8726: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8727: }
1.471 banghart 8728:
8729: sub continue_data_table_row {
1.974 wenzelju 8730: my ($add_class, $id) = @_;
1.610 albertel 8731: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8732: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8733: $id = (' id="'.$id.'"') unless ($id eq '');
8734: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8735: }
1.347 albertel 8736:
8737: sub end_data_table_row {
1.389 albertel 8738: return '</tr>'."\n";;
1.347 albertel 8739: }
1.367 www 8740:
1.421 albertel 8741: sub start_data_table_empty_row {
1.707 bisitz 8742: # $row_count[0]++;
1.421 albertel 8743: return '<tr class="LC_empty_row" >'."\n";;
8744: }
8745:
8746: sub end_data_table_empty_row {
8747: return '</tr>'."\n";;
8748: }
8749:
1.367 www 8750: sub start_data_table_header_row {
1.389 albertel 8751: return '<tr class="LC_header_row">'."\n";;
1.367 www 8752: }
8753:
8754: sub end_data_table_header_row {
1.389 albertel 8755: return '</tr>'."\n";;
1.367 www 8756: }
1.890 droeschl 8757:
8758: sub data_table_caption {
8759: my $caption = shift;
8760: return "<caption class=\"LC_caption\">$caption</caption>";
8761: }
1.347 albertel 8762: }
8763:
1.548 albertel 8764: =pod
8765:
8766: =item * &inhibit_menu_check($arg)
8767:
8768: Checks for a inhibitmenu state and generates output to preserve it
8769:
8770: Inputs: $arg - can be any of
8771: - undef - in which case the return value is a string
8772: to add into arguments list of a uri
8773: - 'input' - in which case the return value is a HTML
8774: <form> <input> field of type hidden to
8775: preserve the value
8776: - a url - in which case the return value is the url with
8777: the neccesary cgi args added to preserve the
8778: inhibitmenu state
8779: - a ref to a url - no return value, but the string is
8780: updated to include the neccessary cgi
8781: args to preserve the inhibitmenu state
8782:
8783: =cut
8784:
8785: sub inhibit_menu_check {
8786: my ($arg) = @_;
8787: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8788: if ($arg eq 'input') {
8789: if ($env{'form.inhibitmenu'}) {
8790: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8791: } else {
8792: return
8793: }
8794: }
8795: if ($env{'form.inhibitmenu'}) {
8796: if (ref($arg)) {
8797: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8798: } elsif ($arg eq '') {
8799: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8800: } else {
8801: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8802: }
8803: }
8804: if (!ref($arg)) {
8805: return $arg;
8806: }
8807: }
8808:
1.251 albertel 8809: ###############################################
1.182 matthew 8810:
8811: =pod
8812:
1.549 albertel 8813: =back
8814:
8815: =head1 User Information Routines
8816:
8817: =over 4
8818:
1.405 albertel 8819: =item * &get_users_function()
1.182 matthew 8820:
8821: Used by &bodytag to determine the current users primary role.
8822: Returns either 'student','coordinator','admin', or 'author'.
8823:
8824: =cut
8825:
8826: ###############################################
8827: sub get_users_function {
1.815 tempelho 8828: my $function = 'norole';
1.818 tempelho 8829: if ($env{'request.role'}=~/^(st)/) {
8830: $function='student';
8831: }
1.907 raeburn 8832: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8833: $function='coordinator';
8834: }
1.258 albertel 8835: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8836: $function='admin';
8837: }
1.826 bisitz 8838: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8839: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8840: $function='author';
8841: }
8842: return $function;
1.54 www 8843: }
1.99 www 8844:
8845: ###############################################
8846:
1.233 raeburn 8847: =pod
8848:
1.821 raeburn 8849: =item * &show_course()
8850:
8851: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8852: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8853:
8854: Inputs:
8855: None
8856:
8857: Outputs:
8858: Scalar: 1 if 'Course' to be used, 0 otherwise.
8859:
8860: =cut
8861:
8862: ###############################################
8863: sub show_course {
8864: my $course = !$env{'user.adv'};
8865: if (!$env{'user.adv'}) {
8866: foreach my $env (keys(%env)) {
8867: next if ($env !~ m/^user\.priv\./);
8868: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8869: $course = 0;
8870: last;
8871: }
8872: }
8873: }
8874: return $course;
8875: }
8876:
8877: ###############################################
8878:
8879: =pod
8880:
1.542 raeburn 8881: =item * &check_user_status()
1.274 raeburn 8882:
8883: Determines current status of supplied role for a
8884: specific user. Roles can be active, previous or future.
8885:
8886: Inputs:
8887: user's domain, user's username, course's domain,
1.375 raeburn 8888: course's number, optional section ID.
1.274 raeburn 8889:
8890: Outputs:
8891: role status: active, previous or future.
8892:
8893: =cut
8894:
8895: sub check_user_status {
1.412 raeburn 8896: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8897: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1075.2.85 raeburn 8898: my @uroles = keys(%userinfo);
1.274 raeburn 8899: my $srchstr;
8900: my $active_chk = 'none';
1.412 raeburn 8901: my $now = time;
1.274 raeburn 8902: if (@uroles > 0) {
1.908 raeburn 8903: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8904: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8905: } else {
1.412 raeburn 8906: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8907: }
8908: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8909: my $role_end = 0;
8910: my $role_start = 0;
8911: $active_chk = 'active';
1.412 raeburn 8912: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8913: $role_end = $1;
8914: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8915: $role_start = $1;
1.274 raeburn 8916: }
8917: }
8918: if ($role_start > 0) {
1.412 raeburn 8919: if ($now < $role_start) {
1.274 raeburn 8920: $active_chk = 'future';
8921: }
8922: }
8923: if ($role_end > 0) {
1.412 raeburn 8924: if ($now > $role_end) {
1.274 raeburn 8925: $active_chk = 'previous';
8926: }
8927: }
8928: }
8929: }
8930: return $active_chk;
8931: }
8932:
8933: ###############################################
8934:
8935: =pod
8936:
1.405 albertel 8937: =item * &get_sections()
1.233 raeburn 8938:
8939: Determines all the sections for a course including
8940: sections with students and sections containing other roles.
1.419 raeburn 8941: Incoming parameters:
8942:
8943: 1. domain
8944: 2. course number
8945: 3. reference to array containing roles for which sections should
8946: be gathered (optional).
8947: 4. reference to array containing status types for which sections
8948: should be gathered (optional).
8949:
8950: If the third argument is undefined, sections are gathered for any role.
8951: If the fourth argument is undefined, sections are gathered for any status.
8952: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8953:
1.374 raeburn 8954: Returns section hash (keys are section IDs, values are
8955: number of users in each section), subject to the
1.419 raeburn 8956: optional roles filter, optional status filter
1.233 raeburn 8957:
8958: =cut
8959:
8960: ###############################################
8961: sub get_sections {
1.419 raeburn 8962: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8963: if (!defined($cdom) || !defined($cnum)) {
8964: my $cid = $env{'request.course.id'};
8965:
8966: return if (!defined($cid));
8967:
8968: $cdom = $env{'course.'.$cid.'.domain'};
8969: $cnum = $env{'course.'.$cid.'.num'};
8970: }
8971:
8972: my %sectioncount;
1.419 raeburn 8973: my $now = time;
1.240 albertel 8974:
1.1075.2.33 raeburn 8975: my $check_students = 1;
8976: my $only_students = 0;
8977: if (ref($possible_roles) eq 'ARRAY') {
8978: if (grep(/^st$/,@{$possible_roles})) {
8979: if (@{$possible_roles} == 1) {
8980: $only_students = 1;
8981: }
8982: } else {
8983: $check_students = 0;
8984: }
8985: }
8986:
8987: if ($check_students) {
1.276 albertel 8988: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8989: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8990: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8991: my $start_index = &Apache::loncoursedata::CL_START();
8992: my $end_index = &Apache::loncoursedata::CL_END();
8993: my $status;
1.366 albertel 8994: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8995: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8996: $data->[$status_index],
8997: $data->[$start_index],
8998: $data->[$end_index]);
8999: if ($stu_status eq 'Active') {
9000: $status = 'active';
9001: } elsif ($end < $now) {
9002: $status = 'previous';
9003: } elsif ($start > $now) {
9004: $status = 'future';
9005: }
9006: if ($section ne '-1' && $section !~ /^\s*$/) {
9007: if ((!defined($possible_status)) || (($status ne '') &&
9008: (grep/^\Q$status\E$/,@{$possible_status}))) {
9009: $sectioncount{$section}++;
9010: }
1.240 albertel 9011: }
9012: }
9013: }
1.1075.2.33 raeburn 9014: if ($only_students) {
9015: return %sectioncount;
9016: }
1.240 albertel 9017: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9018: foreach my $user (sort(keys(%courseroles))) {
9019: if ($user !~ /^(\w{2})/) { next; }
9020: my ($role) = ($user =~ /^(\w{2})/);
9021: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9022: my ($section,$status);
1.240 albertel 9023: if ($role eq 'cr' &&
9024: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9025: $section=$1;
9026: }
9027: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9028: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9029: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9030: if ($end == -1 && $start == -1) {
9031: next; #deleted role
9032: }
9033: if (!defined($possible_status)) {
9034: $sectioncount{$section}++;
9035: } else {
9036: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9037: $status = 'active';
9038: } elsif ($end < $now) {
9039: $status = 'future';
9040: } elsif ($start > $now) {
9041: $status = 'previous';
9042: }
9043: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9044: $sectioncount{$section}++;
9045: }
9046: }
1.233 raeburn 9047: }
1.366 albertel 9048: return %sectioncount;
1.233 raeburn 9049: }
9050:
1.274 raeburn 9051: ###############################################
1.294 raeburn 9052:
9053: =pod
1.405 albertel 9054:
9055: =item * &get_course_users()
9056:
1.275 raeburn 9057: Retrieves usernames:domains for users in the specified course
9058: with specific role(s), and access status.
9059:
9060: Incoming parameters:
1.277 albertel 9061: 1. course domain
9062: 2. course number
9063: 3. access status: users must have - either active,
1.275 raeburn 9064: previous, future, or all.
1.277 albertel 9065: 4. reference to array of permissible roles
1.288 raeburn 9066: 5. reference to array of section restrictions (optional)
9067: 6. reference to results object (hash of hashes).
9068: 7. reference to optional userdata hash
1.609 raeburn 9069: 8. reference to optional statushash
1.630 raeburn 9070: 9. flag if privileged users (except those set to unhide in
9071: course settings) should be excluded
1.609 raeburn 9072: Keys of top level results hash are roles.
1.275 raeburn 9073: Keys of inner hashes are username:domain, with
9074: values set to access type.
1.288 raeburn 9075: Optional userdata hash returns an array with arguments in the
9076: same order as loncoursedata::get_classlist() for student data.
9077:
1.609 raeburn 9078: Optional statushash returns
9079:
1.288 raeburn 9080: Entries for end, start, section and status are blank because
9081: of the possibility of multiple values for non-student roles.
9082:
1.275 raeburn 9083: =cut
1.405 albertel 9084:
1.275 raeburn 9085: ###############################################
1.405 albertel 9086:
1.275 raeburn 9087: sub get_course_users {
1.630 raeburn 9088: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9089: my %idx = ();
1.419 raeburn 9090: my %seclists;
1.288 raeburn 9091:
9092: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9093: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9094: $idx{end} = &Apache::loncoursedata::CL_END();
9095: $idx{start} = &Apache::loncoursedata::CL_START();
9096: $idx{id} = &Apache::loncoursedata::CL_ID();
9097: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9098: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9099: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9100:
1.290 albertel 9101: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9102: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9103: my $now = time;
1.277 albertel 9104: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9105: my $match = 0;
1.412 raeburn 9106: my $secmatch = 0;
1.419 raeburn 9107: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9108: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9109: if ($section eq '') {
9110: $section = 'none';
9111: }
1.291 albertel 9112: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9113: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9114: $secmatch = 1;
9115: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9116: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9117: $secmatch = 1;
9118: }
9119: } else {
1.419 raeburn 9120: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9121: $secmatch = 1;
9122: }
1.290 albertel 9123: }
1.412 raeburn 9124: if (!$secmatch) {
9125: next;
9126: }
1.419 raeburn 9127: }
1.275 raeburn 9128: if (defined($$types{'active'})) {
1.288 raeburn 9129: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9130: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9131: $match = 1;
1.275 raeburn 9132: }
9133: }
9134: if (defined($$types{'previous'})) {
1.609 raeburn 9135: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9136: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9137: $match = 1;
1.275 raeburn 9138: }
9139: }
9140: if (defined($$types{'future'})) {
1.609 raeburn 9141: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9142: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9143: $match = 1;
1.275 raeburn 9144: }
9145: }
1.609 raeburn 9146: if ($match) {
9147: push(@{$seclists{$student}},$section);
9148: if (ref($userdata) eq 'HASH') {
9149: $$userdata{$student} = $$classlist{$student};
9150: }
9151: if (ref($statushash) eq 'HASH') {
9152: $statushash->{$student}{'st'}{$section} = $status;
9153: }
1.288 raeburn 9154: }
1.275 raeburn 9155: }
9156: }
1.412 raeburn 9157: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9158: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9159: my $now = time;
1.609 raeburn 9160: my %displaystatus = ( previous => 'Expired',
9161: active => 'Active',
9162: future => 'Future',
9163: );
1.1075.2.36 raeburn 9164: my (%nothide,@possdoms);
1.630 raeburn 9165: if ($hidepriv) {
9166: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9167: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9168: if ($user !~ /:/) {
9169: $nothide{join(':',split(/[\@]/,$user))}=1;
9170: } else {
9171: $nothide{$user} = 1;
9172: }
9173: }
1.1075.2.36 raeburn 9174: my @possdoms = ($cdom);
9175: if ($coursehash{'checkforpriv'}) {
9176: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9177: }
1.630 raeburn 9178: }
1.439 raeburn 9179: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9180: my $match = 0;
1.412 raeburn 9181: my $secmatch = 0;
1.439 raeburn 9182: my $status;
1.412 raeburn 9183: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9184: $user =~ s/:$//;
1.439 raeburn 9185: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9186: if ($end == -1 || $start == -1) {
9187: next;
9188: }
9189: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9190: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9191: my ($uname,$udom) = split(/:/,$user);
9192: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9193: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9194: $secmatch = 1;
9195: } elsif ($usec eq '') {
1.420 albertel 9196: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9197: $secmatch = 1;
9198: }
9199: } else {
9200: if (grep(/^\Q$usec\E$/,@{$sections})) {
9201: $secmatch = 1;
9202: }
9203: }
9204: if (!$secmatch) {
9205: next;
9206: }
1.288 raeburn 9207: }
1.419 raeburn 9208: if ($usec eq '') {
9209: $usec = 'none';
9210: }
1.275 raeburn 9211: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9212: if ($hidepriv) {
1.1075.2.36 raeburn 9213: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9214: (!$nothide{$uname.':'.$udom})) {
9215: next;
9216: }
9217: }
1.503 raeburn 9218: if ($end > 0 && $end < $now) {
1.439 raeburn 9219: $status = 'previous';
9220: } elsif ($start > $now) {
9221: $status = 'future';
9222: } else {
9223: $status = 'active';
9224: }
1.277 albertel 9225: foreach my $type (keys(%{$types})) {
1.275 raeburn 9226: if ($status eq $type) {
1.420 albertel 9227: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9228: push(@{$$users{$role}{$user}},$type);
9229: }
1.288 raeburn 9230: $match = 1;
9231: }
9232: }
1.419 raeburn 9233: if (($match) && (ref($userdata) eq 'HASH')) {
9234: if (!exists($$userdata{$uname.':'.$udom})) {
9235: &get_user_info($udom,$uname,\%idx,$userdata);
9236: }
1.420 albertel 9237: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9238: push(@{$seclists{$uname.':'.$udom}},$usec);
9239: }
1.609 raeburn 9240: if (ref($statushash) eq 'HASH') {
9241: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9242: }
1.275 raeburn 9243: }
9244: }
9245: }
9246: }
1.290 albertel 9247: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9248: if ((defined($cdom)) && (defined($cnum))) {
9249: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9250: if ( defined($csettings{'internal.courseowner'}) ) {
9251: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9252: next if ($owner eq '');
9253: my ($ownername,$ownerdom);
9254: if ($owner =~ /^([^:]+):([^:]+)$/) {
9255: $ownername = $1;
9256: $ownerdom = $2;
9257: } else {
9258: $ownername = $owner;
9259: $ownerdom = $cdom;
9260: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9261: }
9262: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9263: if (defined($userdata) &&
1.609 raeburn 9264: !exists($$userdata{$owner})) {
9265: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9266: if (!grep(/^none$/,@{$seclists{$owner}})) {
9267: push(@{$seclists{$owner}},'none');
9268: }
9269: if (ref($statushash) eq 'HASH') {
9270: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9271: }
1.290 albertel 9272: }
1.279 raeburn 9273: }
9274: }
9275: }
1.419 raeburn 9276: foreach my $user (keys(%seclists)) {
9277: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9278: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9279: }
1.275 raeburn 9280: }
9281: return;
9282: }
9283:
1.288 raeburn 9284: sub get_user_info {
9285: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9286: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9287: &plainname($uname,$udom,'lastname');
1.291 albertel 9288: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9289: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9290: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9291: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9292: return;
9293: }
1.275 raeburn 9294:
1.472 raeburn 9295: ###############################################
9296:
9297: =pod
9298:
9299: =item * &get_user_quota()
9300:
1.1075.2.41 raeburn 9301: Retrieves quota assigned for storage of user files.
9302: Default is to report quota for portfolio files.
1.472 raeburn 9303:
9304: Incoming parameters:
9305: 1. user's username
9306: 2. user's domain
1.1075.2.41 raeburn 9307: 3. quota name - portfolio, author, or course
9308: (if no quota name provided, defaults to portfolio).
1.1075.2.59 raeburn 9309: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1075.2.42 raeburn 9310: course
1.472 raeburn 9311:
9312: Returns:
1.1075.2.58 raeburn 9313: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9314: 2. (Optional) Type of setting: custom or default
9315: (individually assigned or default for user's
9316: institutional status).
9317: 3. (Optional) - User's institutional status (e.g., faculty, staff
9318: or student - types as defined in localenroll::inst_usertypes
9319: for user's domain, which determines default quota for user.
9320: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9321:
9322: If a value has been stored in the user's environment,
1.536 raeburn 9323: it will return that, otherwise it returns the maximal default
1.1075.2.41 raeburn 9324: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9325:
9326: =cut
9327:
9328: ###############################################
9329:
9330:
9331: sub get_user_quota {
1.1075.2.42 raeburn 9332: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9333: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9334: if (!defined($udom)) {
9335: $udom = $env{'user.domain'};
9336: }
9337: if (!defined($uname)) {
9338: $uname = $env{'user.name'};
9339: }
9340: if (($udom eq '' || $uname eq '') ||
9341: ($udom eq 'public') && ($uname eq 'public')) {
9342: $quota = 0;
1.536 raeburn 9343: $quotatype = 'default';
9344: $defquota = 0;
1.472 raeburn 9345: } else {
1.536 raeburn 9346: my $inststatus;
1.1075.2.41 raeburn 9347: if ($quotaname eq 'course') {
9348: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9349: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9350: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9351: } else {
9352: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9353: $quota = $cenv{'internal.uploadquota'};
9354: }
1.536 raeburn 9355: } else {
1.1075.2.41 raeburn 9356: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9357: if ($quotaname eq 'author') {
9358: $quota = $env{'environment.authorquota'};
9359: } else {
9360: $quota = $env{'environment.portfolioquota'};
9361: }
9362: $inststatus = $env{'environment.inststatus'};
9363: } else {
9364: my %userenv =
9365: &Apache::lonnet::get('environment',['portfolioquota',
9366: 'authorquota','inststatus'],$udom,$uname);
9367: my ($tmp) = keys(%userenv);
9368: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9369: if ($quotaname eq 'author') {
9370: $quota = $userenv{'authorquota'};
9371: } else {
9372: $quota = $userenv{'portfolioquota'};
9373: }
9374: $inststatus = $userenv{'inststatus'};
9375: } else {
9376: undef(%userenv);
9377: }
9378: }
9379: }
9380: if ($quota eq '' || wantarray) {
9381: if ($quotaname eq 'course') {
9382: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1075.2.59 raeburn 9383: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
9384: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1075.2.42 raeburn 9385: $defquota = $domdefs{$crstype.'quota'};
9386: }
9387: if ($defquota eq '') {
9388: $defquota = 500;
9389: }
1.1075.2.41 raeburn 9390: } else {
9391: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9392: }
9393: if ($quota eq '') {
9394: $quota = $defquota;
9395: $quotatype = 'default';
9396: } else {
9397: $quotatype = 'custom';
9398: }
1.472 raeburn 9399: }
9400: }
1.536 raeburn 9401: if (wantarray) {
9402: return ($quota,$quotatype,$settingstatus,$defquota);
9403: } else {
9404: return $quota;
9405: }
1.472 raeburn 9406: }
9407:
9408: ###############################################
9409:
9410: =pod
9411:
9412: =item * &default_quota()
9413:
1.536 raeburn 9414: Retrieves default quota assigned for storage of user portfolio files,
9415: given an (optional) user's institutional status.
1.472 raeburn 9416:
9417: Incoming parameters:
1.1075.2.42 raeburn 9418:
1.472 raeburn 9419: 1. domain
1.536 raeburn 9420: 2. (Optional) institutional status(es). This is a : separated list of
9421: status types (e.g., faculty, staff, student etc.)
9422: which apply to the user for whom the default is being retrieved.
9423: If the institutional status string in undefined, the domain
1.1075.2.41 raeburn 9424: default quota will be returned.
9425: 3. quota name - portfolio, author, or course
9426: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9427:
9428: Returns:
1.1075.2.42 raeburn 9429:
1.1075.2.58 raeburn 9430: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9431: 2. (Optional) institutional type which determined the value of the
9432: default quota.
1.472 raeburn 9433:
9434: If a value has been stored in the domain's configuration db,
9435: it will return that, otherwise it returns 20 (for backwards
9436: compatibility with domains which have not set up a configuration
1.1075.2.58 raeburn 9437: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9438:
1.536 raeburn 9439: If the user's status includes multiple types (e.g., staff and student),
9440: the largest default quota which applies to the user determines the
9441: default quota returned.
9442:
1.472 raeburn 9443: =cut
9444:
9445: ###############################################
9446:
9447:
9448: sub default_quota {
1.1075.2.41 raeburn 9449: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9450: my ($defquota,$settingstatus);
9451: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9452: ['quotas'],$udom);
1.1075.2.41 raeburn 9453: my $key = 'defaultquota';
9454: if ($quotaname eq 'author') {
9455: $key = 'authorquota';
9456: }
1.622 raeburn 9457: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9458: if ($inststatus ne '') {
1.765 raeburn 9459: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9460: foreach my $item (@statuses) {
1.1075.2.41 raeburn 9461: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9462: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9463: if ($defquota eq '') {
1.1075.2.41 raeburn 9464: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9465: $settingstatus = $item;
1.1075.2.41 raeburn 9466: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9467: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9468: $settingstatus = $item;
9469: }
9470: }
1.1075.2.41 raeburn 9471: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9472: if ($quotahash{'quotas'}{$item} ne '') {
9473: if ($defquota eq '') {
9474: $defquota = $quotahash{'quotas'}{$item};
9475: $settingstatus = $item;
9476: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9477: $defquota = $quotahash{'quotas'}{$item};
9478: $settingstatus = $item;
9479: }
1.536 raeburn 9480: }
9481: }
9482: }
9483: }
9484: if ($defquota eq '') {
1.1075.2.41 raeburn 9485: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9486: $defquota = $quotahash{'quotas'}{$key}{'default'};
9487: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9488: $defquota = $quotahash{'quotas'}{'default'};
9489: }
1.536 raeburn 9490: $settingstatus = 'default';
1.1075.2.42 raeburn 9491: if ($defquota eq '') {
9492: if ($quotaname eq 'author') {
9493: $defquota = 500;
9494: }
9495: }
1.536 raeburn 9496: }
9497: } else {
9498: $settingstatus = 'default';
1.1075.2.41 raeburn 9499: if ($quotaname eq 'author') {
9500: $defquota = 500;
9501: } else {
9502: $defquota = 20;
9503: }
1.536 raeburn 9504: }
9505: if (wantarray) {
9506: return ($defquota,$settingstatus);
1.472 raeburn 9507: } else {
1.536 raeburn 9508: return $defquota;
1.472 raeburn 9509: }
9510: }
9511:
1.1075.2.41 raeburn 9512: ###############################################
9513:
9514: =pod
9515:
1.1075.2.42 raeburn 9516: =item * &excess_filesize_warning()
1.1075.2.41 raeburn 9517:
9518: Returns warning message if upload of file to authoring space, or copying
1.1075.2.42 raeburn 9519: of existing file within authoring space will cause quota for the authoring
9520: space to be exceeded.
9521:
9522: Same, if upload of a file directly to a course/community via Course Editor
9523: will cause quota for uploaded content for the course to be exceeded.
1.1075.2.41 raeburn 9524:
1.1075.2.61 raeburn 9525: Inputs: 7
1.1075.2.42 raeburn 9526: 1. username or coursenum
1.1075.2.41 raeburn 9527: 2. domain
1.1075.2.42 raeburn 9528: 3. context ('author' or 'course')
1.1075.2.41 raeburn 9529: 4. filename of file for which action is being requested
9530: 5. filesize (kB) of file
9531: 6. action being taken: copy or upload.
1.1075.2.59 raeburn 9532: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1075.2.41 raeburn 9533:
9534: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
9535: otherwise return null.
9536:
1.1075.2.42 raeburn 9537: =back
9538:
1.1075.2.41 raeburn 9539: =cut
9540:
1.1075.2.42 raeburn 9541: sub excess_filesize_warning {
1.1075.2.59 raeburn 9542: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1075.2.42 raeburn 9543: my $current_disk_usage = 0;
1.1075.2.59 raeburn 9544: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1075.2.42 raeburn 9545: if ($context eq 'author') {
9546: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9547: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9548: } else {
9549: foreach my $subdir ('docs','supplemental') {
9550: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9551: }
9552: }
1.1075.2.41 raeburn 9553: $disk_quota = int($disk_quota * 1000);
9554: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1075.2.69 raeburn 9555: return '<p class="LC_warning">'.
1.1075.2.41 raeburn 9556: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1075.2.69 raeburn 9557: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9558: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1075.2.41 raeburn 9559: $disk_quota,$current_disk_usage).
9560: '</p>';
9561: }
9562: return;
9563: }
9564:
9565: ###############################################
9566:
9567:
1.384 raeburn 9568: sub get_secgrprole_info {
9569: my ($cdom,$cnum,$needroles,$type) = @_;
9570: my %sections_count = &get_sections($cdom,$cnum);
9571: my @sections = (sort {$a <=> $b} keys(%sections_count));
9572: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9573: my @groups = sort(keys(%curr_groups));
9574: my $allroles = [];
9575: my $rolehash;
9576: my $accesshash = {
9577: active => 'Currently has access',
9578: future => 'Will have future access',
9579: previous => 'Previously had access',
9580: };
9581: if ($needroles) {
9582: $rolehash = {'all' => 'all'};
1.385 albertel 9583: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9584: if (&Apache::lonnet::error(%user_roles)) {
9585: undef(%user_roles);
9586: }
9587: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9588: my ($role)=split(/\:/,$item,2);
9589: if ($role eq 'cr') { next; }
9590: if ($role =~ /^cr/) {
9591: $$rolehash{$role} = (split('/',$role))[3];
9592: } else {
9593: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9594: }
9595: }
9596: foreach my $key (sort(keys(%{$rolehash}))) {
9597: push(@{$allroles},$key);
9598: }
9599: push (@{$allroles},'st');
9600: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9601: }
9602: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9603: }
9604:
1.555 raeburn 9605: sub user_picker {
1.1075.2.127 raeburn 9606: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom,$noinstd) = @_;
1.555 raeburn 9607: my $currdom = $dom;
1.1075.2.114 raeburn 9608: my @alldoms = &Apache::lonnet::all_domains();
9609: if (@alldoms == 1) {
9610: my %domsrch = &Apache::lonnet::get_dom('configuration',
9611: ['directorysrch'],$alldoms[0]);
9612: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
9613: my $showdom = $domdesc;
9614: if ($showdom eq '') {
9615: $showdom = $dom;
9616: }
9617: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
9618: if ((!$domsrch{'directorysrch'}{'available'}) &&
9619: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
9620: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
9621: }
9622: }
9623: }
1.555 raeburn 9624: my %curr_selected = (
9625: srchin => 'dom',
1.580 raeburn 9626: srchby => 'lastname',
1.555 raeburn 9627: );
9628: my $srchterm;
1.625 raeburn 9629: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9630: if ($srch->{'srchby'} ne '') {
9631: $curr_selected{'srchby'} = $srch->{'srchby'};
9632: }
9633: if ($srch->{'srchin'} ne '') {
9634: $curr_selected{'srchin'} = $srch->{'srchin'};
9635: }
9636: if ($srch->{'srchtype'} ne '') {
9637: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9638: }
9639: if ($srch->{'srchdomain'} ne '') {
9640: $currdom = $srch->{'srchdomain'};
9641: }
9642: $srchterm = $srch->{'srchterm'};
9643: }
1.1075.2.98 raeburn 9644: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9645: 'usr' => 'Search criteria',
1.563 raeburn 9646: 'doma' => 'Domain/institution to search',
1.558 albertel 9647: 'uname' => 'username',
9648: 'lastname' => 'last name',
1.555 raeburn 9649: 'lastfirst' => 'last name, first name',
1.558 albertel 9650: 'crs' => 'in this course',
1.576 raeburn 9651: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9652: 'alc' => 'all LON-CAPA',
1.573 raeburn 9653: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9654: 'exact' => 'is',
9655: 'contains' => 'contains',
1.569 raeburn 9656: 'begins' => 'begins with',
1.1075.2.98 raeburn 9657: );
9658: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9659: 'youm' => "You must include some text to search for.",
9660: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9661: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9662: 'yomc' => "You must choose a domain when using an institutional directory search.",
9663: 'ymcd' => "You must choose a domain when using a domain search.",
9664: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9665: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9666: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9667: );
1.1075.2.98 raeburn 9668: &html_escape(\%html_lt);
9669: &js_escape(\%js_lt);
1.1075.2.115 raeburn 9670: my $domform;
1.1075.2.126 raeburn 9671: my $allow_blank = 1;
1.1075.2.115 raeburn 9672: if ($fixeddom) {
1.1075.2.126 raeburn 9673: $allow_blank = 0;
9674: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1,undef,[$currdom]);
1.1075.2.115 raeburn 9675: } else {
1.1075.2.126 raeburn 9676: $domform = &select_dom_form($currdom,'srchdomain',$allow_blank,1);
1.1075.2.115 raeburn 9677: }
1.563 raeburn 9678: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9679:
9680: my @srchins = ('crs','dom','alc','instd');
9681:
9682: foreach my $option (@srchins) {
9683: # FIXME 'alc' option unavailable until
9684: # loncreateuser::print_user_query_page()
9685: # has been completed.
9686: next if ($option eq 'alc');
1.880 raeburn 9687: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9688: next if ($option eq 'crs' && !$env{'request.course.id'});
1.1075.2.127 raeburn 9689: next if (($option eq 'instd') && ($noinstd));
1.563 raeburn 9690: if ($curr_selected{'srchin'} eq $option) {
9691: $srchinsel .= '
1.1075.2.98 raeburn 9692: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 9693: } else {
9694: $srchinsel .= '
1.1075.2.98 raeburn 9695: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 9696: }
1.555 raeburn 9697: }
1.563 raeburn 9698: $srchinsel .= "\n </select>\n";
1.555 raeburn 9699:
9700: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9701: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9702: if ($curr_selected{'srchby'} eq $option) {
9703: $srchbysel .= '
1.1075.2.98 raeburn 9704: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9705: } else {
9706: $srchbysel .= '
1.1075.2.98 raeburn 9707: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9708: }
9709: }
9710: $srchbysel .= "\n </select>\n";
9711:
9712: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9713: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9714: if ($curr_selected{'srchtype'} eq $option) {
9715: $srchtypesel .= '
1.1075.2.98 raeburn 9716: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9717: } else {
9718: $srchtypesel .= '
1.1075.2.98 raeburn 9719: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9720: }
9721: }
9722: $srchtypesel .= "\n </select>\n";
9723:
1.558 albertel 9724: my ($newuserscript,$new_user_create);
1.994 raeburn 9725: my $context_dom = $env{'request.role.domain'};
9726: if ($context eq 'requestcrs') {
9727: if ($env{'form.coursedom'} ne '') {
9728: $context_dom = $env{'form.coursedom'};
9729: }
9730: }
1.556 raeburn 9731: if ($forcenewuser) {
1.576 raeburn 9732: if (ref($srch) eq 'HASH') {
1.994 raeburn 9733: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9734: if ($cancreate) {
9735: $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>';
9736: } else {
1.799 bisitz 9737: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9738: my %usertypetext = (
9739: official => 'institutional',
9740: unofficial => 'non-institutional',
9741: );
1.799 bisitz 9742: $new_user_create = '<p class="LC_warning">'
9743: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9744: .' '
9745: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9746: ,'<a href="'.$helplink.'">','</a>')
9747: .'</p><br />';
1.627 raeburn 9748: }
1.576 raeburn 9749: }
9750: }
9751:
1.556 raeburn 9752: $newuserscript = <<"ENDSCRIPT";
9753:
1.570 raeburn 9754: function setSearch(createnew,callingForm) {
1.556 raeburn 9755: if (createnew == 1) {
1.570 raeburn 9756: for (var i=0; i<callingForm.srchby.length; i++) {
9757: if (callingForm.srchby.options[i].value == 'uname') {
9758: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9759: }
9760: }
1.570 raeburn 9761: for (var i=0; i<callingForm.srchin.length; i++) {
9762: if ( callingForm.srchin.options[i].value == 'dom') {
9763: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9764: }
9765: }
1.570 raeburn 9766: for (var i=0; i<callingForm.srchtype.length; i++) {
9767: if (callingForm.srchtype.options[i].value == 'exact') {
9768: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9769: }
9770: }
1.570 raeburn 9771: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9772: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9773: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9774: }
9775: }
9776: }
9777: }
9778: ENDSCRIPT
1.558 albertel 9779:
1.556 raeburn 9780: }
9781:
1.555 raeburn 9782: my $output = <<"END_BLOCK";
1.556 raeburn 9783: <script type="text/javascript">
1.824 bisitz 9784: // <![CDATA[
1.570 raeburn 9785: function validateEntry(callingForm) {
1.558 albertel 9786:
1.556 raeburn 9787: var checkok = 1;
1.558 albertel 9788: var srchin;
1.570 raeburn 9789: for (var i=0; i<callingForm.srchin.length; i++) {
9790: if ( callingForm.srchin[i].checked ) {
9791: srchin = callingForm.srchin[i].value;
1.558 albertel 9792: }
9793: }
9794:
1.570 raeburn 9795: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9796: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9797: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9798: var srchterm = callingForm.srchterm.value;
9799: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9800: var msg = "";
9801:
9802: if (srchterm == "") {
9803: checkok = 0;
1.1075.2.98 raeburn 9804: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 9805: }
9806:
1.569 raeburn 9807: if (srchtype== 'begins') {
9808: if (srchterm.length < 2) {
9809: checkok = 0;
1.1075.2.98 raeburn 9810: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 9811: }
9812: }
9813:
1.556 raeburn 9814: if (srchtype== 'contains') {
9815: if (srchterm.length < 3) {
9816: checkok = 0;
1.1075.2.98 raeburn 9817: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 9818: }
9819: }
9820: if (srchin == 'instd') {
9821: if (srchdomain == '') {
9822: checkok = 0;
1.1075.2.98 raeburn 9823: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 9824: }
9825: }
9826: if (srchin == 'dom') {
9827: if (srchdomain == '') {
9828: checkok = 0;
1.1075.2.98 raeburn 9829: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 9830: }
9831: }
9832: if (srchby == 'lastfirst') {
9833: if (srchterm.indexOf(",") == -1) {
9834: checkok = 0;
1.1075.2.98 raeburn 9835: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 9836: }
9837: if (srchterm.indexOf(",") == srchterm.length -1) {
9838: checkok = 0;
1.1075.2.98 raeburn 9839: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 9840: }
9841: }
9842: if (checkok == 0) {
1.1075.2.98 raeburn 9843: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 9844: return;
9845: }
9846: if (checkok == 1) {
1.570 raeburn 9847: callingForm.submit();
1.556 raeburn 9848: }
9849: }
9850:
9851: $newuserscript
9852:
1.824 bisitz 9853: // ]]>
1.556 raeburn 9854: </script>
1.558 albertel 9855:
9856: $new_user_create
9857:
1.555 raeburn 9858: END_BLOCK
1.558 albertel 9859:
1.876 raeburn 9860: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1075.2.98 raeburn 9861: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 9862: $domform.
9863: &Apache::lonhtmlcommon::row_closure().
1.1075.2.98 raeburn 9864: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 9865: $srchbysel.
9866: $srchtypesel.
9867: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9868: $srchinsel.
9869: &Apache::lonhtmlcommon::row_closure(1).
9870: &Apache::lonhtmlcommon::end_pick_box().
9871: '<br />';
1.1075.2.114 raeburn 9872: return ($output,1);
1.555 raeburn 9873: }
9874:
1.612 raeburn 9875: sub user_rule_check {
1.615 raeburn 9876: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1075.2.99 raeburn 9877: my ($response,%inst_response);
1.612 raeburn 9878: if (ref($usershash) eq 'HASH') {
1.1075.2.99 raeburn 9879: if (keys(%{$usershash}) > 1) {
9880: my (%by_username,%by_id,%userdoms);
9881: my $checkid;
1.612 raeburn 9882: if (ref($checks) eq 'HASH') {
1.1075.2.99 raeburn 9883: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
9884: $checkid = 1;
9885: }
9886: }
9887: foreach my $user (keys(%{$usershash})) {
9888: my ($uname,$udom) = split(/:/,$user);
9889: if ($checkid) {
9890: if (ref($usershash->{$user}) eq 'HASH') {
9891: if ($usershash->{$user}->{'id'} ne '') {
9892: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
9893: $userdoms{$udom} = 1;
9894: if (ref($inst_results) eq 'HASH') {
9895: $inst_results->{$uname.':'.$udom} = {};
9896: }
9897: }
9898: }
9899: } else {
9900: $by_username{$udom}{$uname} = 1;
9901: $userdoms{$udom} = 1;
9902: if (ref($inst_results) eq 'HASH') {
9903: $inst_results->{$uname.':'.$udom} = {};
9904: }
9905: }
9906: }
9907: foreach my $udom (keys(%userdoms)) {
9908: if (!$got_rules->{$udom}) {
9909: my %domconfig = &Apache::lonnet::get_dom('configuration',
9910: ['usercreation'],$udom);
9911: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9912: foreach my $item ('username','id') {
9913: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9914: $$curr_rules{$udom}{$item} =
9915: $domconfig{'usercreation'}{$item.'_rule'};
9916: }
9917: }
9918: }
9919: $got_rules->{$udom} = 1;
9920: }
9921: }
9922: if ($checkid) {
9923: foreach my $udom (keys(%by_id)) {
9924: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
9925: if ($outcome eq 'ok') {
9926: foreach my $id (keys(%{$by_id{$udom}})) {
9927: my $uname = $by_id{$udom}{$id};
9928: $inst_response{$uname.':'.$udom} = $outcome;
9929: }
9930: if (ref($results) eq 'HASH') {
9931: foreach my $uname (keys(%{$results})) {
9932: if (exists($inst_response{$uname.':'.$udom})) {
9933: $inst_response{$uname.':'.$udom} = $outcome;
9934: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9935: }
9936: }
9937: }
9938: }
1.612 raeburn 9939: }
1.615 raeburn 9940: } else {
1.1075.2.99 raeburn 9941: foreach my $udom (keys(%by_username)) {
9942: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
9943: if ($outcome eq 'ok') {
9944: foreach my $uname (keys(%{$by_username{$udom}})) {
9945: $inst_response{$uname.':'.$udom} = $outcome;
9946: }
9947: if (ref($results) eq 'HASH') {
9948: foreach my $uname (keys(%{$results})) {
9949: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9950: }
9951: }
9952: }
9953: }
1.612 raeburn 9954: }
1.1075.2.99 raeburn 9955: } elsif (keys(%{$usershash}) == 1) {
9956: my $user = (keys(%{$usershash}))[0];
9957: my ($uname,$udom) = split(/:/,$user);
9958: if (($udom ne '') && ($uname ne '')) {
9959: if (ref($usershash->{$user}) eq 'HASH') {
9960: if (ref($checks) eq 'HASH') {
9961: if (defined($checks->{'username'})) {
9962: ($inst_response{$user},%{$inst_results->{$user}}) =
9963: &Apache::lonnet::get_instuser($udom,$uname);
9964: } elsif (defined($checks->{'id'})) {
9965: if ($usershash->{$user}->{'id'} ne '') {
9966: ($inst_response{$user},%{$inst_results->{$user}}) =
9967: &Apache::lonnet::get_instuser($udom,undef,
9968: $usershash->{$user}->{'id'});
9969: } else {
9970: ($inst_response{$user},%{$inst_results->{$user}}) =
9971: &Apache::lonnet::get_instuser($udom,$uname);
9972: }
9973: }
9974: } else {
9975: ($inst_response{$user},%{$inst_results->{$user}}) =
9976: &Apache::lonnet::get_instuser($udom,$uname);
9977: return;
9978: }
9979: if (!$got_rules->{$udom}) {
9980: my %domconfig = &Apache::lonnet::get_dom('configuration',
9981: ['usercreation'],$udom);
9982: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9983: foreach my $item ('username','id') {
9984: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9985: $$curr_rules{$udom}{$item} =
9986: $domconfig{'usercreation'}{$item.'_rule'};
9987: }
9988: }
1.585 raeburn 9989: }
1.1075.2.99 raeburn 9990: $got_rules->{$udom} = 1;
1.585 raeburn 9991: }
9992: }
1.1075.2.99 raeburn 9993: } else {
9994: return;
9995: }
9996: } else {
9997: return;
9998: }
9999: foreach my $user (keys(%{$usershash})) {
10000: my ($uname,$udom) = split(/:/,$user);
10001: next if (($udom eq '') || ($uname eq ''));
10002: my $id;
10003: if (ref($inst_results) eq 'HASH') {
10004: if (ref($inst_results->{$user}) eq 'HASH') {
10005: $id = $inst_results->{$user}->{'id'};
10006: }
10007: }
10008: if ($id eq '') {
10009: if (ref($usershash->{$user})) {
10010: $id = $usershash->{$user}->{'id'};
10011: }
1.585 raeburn 10012: }
1.612 raeburn 10013: foreach my $item (keys(%{$checks})) {
10014: if (ref($$curr_rules{$udom}) eq 'HASH') {
10015: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10016: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1075.2.99 raeburn 10017: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10018: $$curr_rules{$udom}{$item});
1.612 raeburn 10019: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10020: if ($rule_check{$rule}) {
10021: $$rulematch{$user}{$item} = $rule;
1.1075.2.99 raeburn 10022: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10023: if (ref($inst_results) eq 'HASH') {
10024: if (ref($inst_results->{$user}) eq 'HASH') {
10025: if (keys(%{$inst_results->{$user}}) == 0) {
10026: $$alerts{$item}{$udom}{$uname} = 1;
1.1075.2.99 raeburn 10027: } elsif ($item eq 'id') {
10028: if ($inst_results->{$user}->{'id'} eq '') {
10029: $$alerts{$item}{$udom}{$uname} = 1;
10030: }
1.615 raeburn 10031: }
1.612 raeburn 10032: }
10033: }
1.615 raeburn 10034: }
10035: last;
1.585 raeburn 10036: }
10037: }
10038: }
10039: }
10040: }
10041: }
10042: }
10043: }
1.612 raeburn 10044: return;
10045: }
10046:
10047: sub user_rule_formats {
10048: my ($domain,$domdesc,$curr_rules,$check) = @_;
10049: my %text = (
10050: 'username' => 'Usernames',
10051: 'id' => 'IDs',
10052: );
10053: my $output;
10054: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10055: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10056: if (@{$ruleorder} > 0) {
1.1075.2.20 raeburn 10057: $output = '<br />'.
10058: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10059: '<span class="LC_cusr_emph">','</span>',$domdesc).
10060: ' <ul>';
1.612 raeburn 10061: foreach my $rule (@{$ruleorder}) {
10062: if (ref($curr_rules) eq 'ARRAY') {
10063: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10064: if (ref($rules->{$rule}) eq 'HASH') {
10065: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10066: $rules->{$rule}{'desc'}.'</li>';
10067: }
10068: }
10069: }
10070: }
10071: $output .= '</ul>';
10072: }
10073: }
10074: return $output;
10075: }
10076:
10077: sub instrule_disallow_msg {
1.615 raeburn 10078: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10079: my $response;
10080: my %text = (
10081: item => 'username',
10082: items => 'usernames',
10083: match => 'matches',
10084: do => 'does',
10085: action => 'a username',
10086: one => 'one',
10087: );
10088: if ($count > 1) {
10089: $text{'item'} = 'usernames';
10090: $text{'match'} ='match';
10091: $text{'do'} = 'do';
10092: $text{'action'} = 'usernames',
10093: $text{'one'} = 'ones';
10094: }
10095: if ($checkitem eq 'id') {
10096: $text{'items'} = 'IDs';
10097: $text{'item'} = 'ID';
10098: $text{'action'} = 'an ID';
1.615 raeburn 10099: if ($count > 1) {
10100: $text{'item'} = 'IDs';
10101: $text{'action'} = 'IDs';
10102: }
1.612 raeburn 10103: }
1.674 bisitz 10104: $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 10105: if ($mode eq 'upload') {
10106: if ($checkitem eq 'username') {
10107: $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'}.");
10108: } elsif ($checkitem eq 'id') {
1.674 bisitz 10109: $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 10110: }
1.669 raeburn 10111: } elsif ($mode eq 'selfcreate') {
10112: if ($checkitem eq 'id') {
10113: $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.");
10114: }
1.615 raeburn 10115: } else {
10116: if ($checkitem eq 'username') {
10117: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10118: } elsif ($checkitem eq 'id') {
10119: $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.");
10120: }
1.612 raeburn 10121: }
10122: return $response;
1.585 raeburn 10123: }
10124:
1.624 raeburn 10125: sub personal_data_fieldtitles {
10126: my %fieldtitles = &Apache::lonlocal::texthash (
10127: id => 'Student/Employee ID',
10128: permanentemail => 'E-mail address',
10129: lastname => 'Last Name',
10130: firstname => 'First Name',
10131: middlename => 'Middle Name',
10132: generation => 'Generation',
10133: gen => 'Generation',
1.765 raeburn 10134: inststatus => 'Affiliation',
1.624 raeburn 10135: );
10136: return %fieldtitles;
10137: }
10138:
1.642 raeburn 10139: sub sorted_inst_types {
10140: my ($dom) = @_;
1.1075.2.70 raeburn 10141: my ($usertypes,$order);
10142: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10143: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10144: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10145: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10146: } else {
10147: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10148: }
1.642 raeburn 10149: my $othertitle = &mt('All users');
10150: if ($env{'request.course.id'}) {
1.668 raeburn 10151: $othertitle = &mt('Any users');
1.642 raeburn 10152: }
10153: my @types;
10154: if (ref($order) eq 'ARRAY') {
10155: @types = @{$order};
10156: }
10157: if (@types == 0) {
10158: if (ref($usertypes) eq 'HASH') {
10159: @types = sort(keys(%{$usertypes}));
10160: }
10161: }
10162: if (keys(%{$usertypes}) > 0) {
10163: $othertitle = &mt('Other users');
10164: }
10165: return ($othertitle,$usertypes,\@types);
10166: }
10167:
1.645 raeburn 10168: sub get_institutional_codes {
10169: my ($settings,$allcourses,$LC_code) = @_;
10170: # Get complete list of course sections to update
10171: my @currsections = ();
10172: my @currxlists = ();
10173: my $coursecode = $$settings{'internal.coursecode'};
10174:
10175: if ($$settings{'internal.sectionnums'} ne '') {
10176: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10177: }
10178:
10179: if ($$settings{'internal.crosslistings'} ne '') {
10180: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10181: }
10182:
10183: if (@currxlists > 0) {
10184: foreach (@currxlists) {
10185: if (m/^([^:]+):(\w*)$/) {
10186: unless (grep/^$1$/,@{$allcourses}) {
1.1075.2.119 raeburn 10187: push(@{$allcourses},$1);
1.645 raeburn 10188: $$LC_code{$1} = $2;
10189: }
10190: }
10191: }
10192: }
10193:
10194: if (@currsections > 0) {
10195: foreach (@currsections) {
10196: if (m/^(\w+):(\w*)$/) {
10197: my $sec = $coursecode.$1;
10198: my $lc_sec = $2;
10199: unless (grep/^$sec$/,@{$allcourses}) {
1.1075.2.119 raeburn 10200: push(@{$allcourses},$sec);
1.645 raeburn 10201: $$LC_code{$sec} = $lc_sec;
10202: }
10203: }
10204: }
10205: }
10206: return;
10207: }
10208:
1.971 raeburn 10209: sub get_standard_codeitems {
10210: return ('Year','Semester','Department','Number','Section');
10211: }
10212:
1.112 bowersj2 10213: =pod
10214:
1.780 raeburn 10215: =head1 Slot Helpers
10216:
10217: =over 4
10218:
10219: =item * sorted_slots()
10220:
1.1040 raeburn 10221: Sorts an array of slot names in order of an optional sort key,
10222: default sort is by slot start time (earliest first).
1.780 raeburn 10223:
10224: Inputs:
10225:
10226: =over 4
10227:
10228: slotsarr - Reference to array of unsorted slot names.
10229:
10230: slots - Reference to hash of hash, where outer hash keys are slot names.
10231:
1.1040 raeburn 10232: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10233:
1.549 albertel 10234: =back
10235:
1.780 raeburn 10236: Returns:
10237:
10238: =over 4
10239:
1.1040 raeburn 10240: sorted - An array of slot names sorted by a specified sort key
10241: (default sort key is start time of the slot).
1.780 raeburn 10242:
10243: =back
10244:
10245: =cut
10246:
10247:
10248: sub sorted_slots {
1.1040 raeburn 10249: my ($slotsarr,$slots,$sortkey) = @_;
10250: if ($sortkey eq '') {
10251: $sortkey = 'starttime';
10252: }
1.780 raeburn 10253: my @sorted;
10254: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10255: @sorted =
10256: sort {
10257: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10258: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10259: }
10260: if (ref($slots->{$a})) { return -1;}
10261: if (ref($slots->{$b})) { return 1;}
10262: return 0;
10263: } @{$slotsarr};
10264: }
10265: return @sorted;
10266: }
10267:
1.1040 raeburn 10268: =pod
10269:
10270: =item * get_future_slots()
10271:
10272: Inputs:
10273:
10274: =over 4
10275:
10276: cnum - course number
10277:
10278: cdom - course domain
10279:
10280: now - current UNIX time
10281:
10282: symb - optional symb
10283:
10284: =back
10285:
10286: Returns:
10287:
10288: =over 4
10289:
10290: sorted_reservable - ref to array of student_schedulable slots currently
10291: reservable, ordered by end date of reservation period.
10292:
10293: reservable_now - ref to hash of student_schedulable slots currently
10294: reservable.
10295:
10296: Keys in inner hash are:
10297: (a) symb: either blank or symb to which slot use is restricted.
1.1075.2.104 raeburn 10298: (b) endreserve: end date of reservation period.
10299: (c) uniqueperiod: start,end dates when slot is to be uniquely
10300: selected.
1.1040 raeburn 10301:
10302: sorted_future - ref to array of student_schedulable slots reservable in
10303: the future, ordered by start date of reservation period.
10304:
10305: future_reservable - ref to hash of student_schedulable slots reservable
10306: in the future.
10307:
10308: Keys in inner hash are:
10309: (a) symb: either blank or symb to which slot use is restricted.
10310: (b) startreserve: start date of reservation period.
1.1075.2.104 raeburn 10311: (c) uniqueperiod: start,end dates when slot is to be uniquely
10312: selected.
1.1040 raeburn 10313:
10314: =back
10315:
10316: =cut
10317:
10318: sub get_future_slots {
10319: my ($cnum,$cdom,$now,$symb) = @_;
10320: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10321: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10322: foreach my $slot (keys(%slots)) {
10323: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10324: if ($symb) {
10325: next if (($slots{$slot}->{'symb'} ne '') &&
10326: ($slots{$slot}->{'symb'} ne $symb));
10327: }
10328: if (($slots{$slot}->{'starttime'} > $now) &&
10329: ($slots{$slot}->{'endtime'} > $now)) {
10330: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10331: my $userallowed = 0;
10332: if ($slots{$slot}->{'allowedsections'}) {
10333: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10334: if (!defined($env{'request.role.sec'})
10335: && grep(/^No section assigned$/,@allowed_sec)) {
10336: $userallowed=1;
10337: } else {
10338: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10339: $userallowed=1;
10340: }
10341: }
10342: unless ($userallowed) {
10343: if (defined($env{'request.course.groups'})) {
10344: my @groups = split(/:/,$env{'request.course.groups'});
10345: foreach my $group (@groups) {
10346: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10347: $userallowed=1;
10348: last;
10349: }
10350: }
10351: }
10352: }
10353: }
10354: if ($slots{$slot}->{'allowedusers'}) {
10355: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10356: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10357: if (grep(/^\Q$user\E$/,@allowed_users)) {
10358: $userallowed = 1;
10359: }
10360: }
10361: next unless($userallowed);
10362: }
10363: my $startreserve = $slots{$slot}->{'startreserve'};
10364: my $endreserve = $slots{$slot}->{'endreserve'};
10365: my $symb = $slots{$slot}->{'symb'};
1.1075.2.104 raeburn 10366: my $uniqueperiod;
10367: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10368: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10369: }
1.1040 raeburn 10370: if (($startreserve < $now) &&
10371: (!$endreserve || $endreserve > $now)) {
10372: my $lastres = $endreserve;
10373: if (!$lastres) {
10374: $lastres = $slots{$slot}->{'starttime'};
10375: }
10376: $reservable_now{$slot} = {
10377: symb => $symb,
1.1075.2.104 raeburn 10378: endreserve => $lastres,
10379: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10380: };
10381: } elsif (($startreserve > $now) &&
10382: (!$endreserve || $endreserve > $startreserve)) {
10383: $future_reservable{$slot} = {
10384: symb => $symb,
1.1075.2.104 raeburn 10385: startreserve => $startreserve,
10386: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10387: };
10388: }
10389: }
10390: }
10391: my @unsorted_reservable = keys(%reservable_now);
10392: if (@unsorted_reservable > 0) {
10393: @sorted_reservable =
10394: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10395: }
10396: my @unsorted_future = keys(%future_reservable);
10397: if (@unsorted_future > 0) {
10398: @sorted_future =
10399: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10400: }
10401: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10402: }
1.780 raeburn 10403:
10404: =pod
10405:
1.1057 foxr 10406: =back
10407:
1.549 albertel 10408: =head1 HTTP Helpers
10409:
10410: =over 4
10411:
1.648 raeburn 10412: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10413:
1.258 albertel 10414: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10415: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10416: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10417:
10418: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10419: $possible_names is an ref to an array of form element names. As an example:
10420: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10421: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10422:
10423: =cut
1.1 albertel 10424:
1.6 albertel 10425: sub get_unprocessed_cgi {
1.25 albertel 10426: my ($query,$possible_names)= @_;
1.26 matthew 10427: # $Apache::lonxml::debug=1;
1.356 albertel 10428: foreach my $pair (split(/&/,$query)) {
10429: my ($name, $value) = split(/=/,$pair);
1.369 www 10430: $name = &unescape($name);
1.25 albertel 10431: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10432: $value =~ tr/+/ /;
10433: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10434: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10435: }
1.16 harris41 10436: }
1.6 albertel 10437: }
10438:
1.112 bowersj2 10439: =pod
10440:
1.648 raeburn 10441: =item * &cacheheader()
1.112 bowersj2 10442:
10443: returns cache-controlling header code
10444:
10445: =cut
10446:
1.7 albertel 10447: sub cacheheader {
1.258 albertel 10448: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10449: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10450: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10451: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10452: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10453: return $output;
1.7 albertel 10454: }
10455:
1.112 bowersj2 10456: =pod
10457:
1.648 raeburn 10458: =item * &no_cache($r)
1.112 bowersj2 10459:
10460: specifies header code to not have cache
10461:
10462: =cut
10463:
1.9 albertel 10464: sub no_cache {
1.216 albertel 10465: my ($r) = @_;
10466: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10467: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10468: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10469: $r->no_cache(1);
10470: $r->header_out("Expires" => $date);
10471: $r->header_out("Pragma" => "no-cache");
1.123 www 10472: }
10473:
10474: sub content_type {
1.181 albertel 10475: my ($r,$type,$charset) = @_;
1.299 foxr 10476: if ($r) {
10477: # Note that printout.pl calls this with undef for $r.
10478: &no_cache($r);
10479: }
1.258 albertel 10480: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10481: unless ($charset) {
10482: $charset=&Apache::lonlocal::current_encoding;
10483: }
10484: if ($charset) { $type.='; charset='.$charset; }
10485: if ($r) {
10486: $r->content_type($type);
10487: } else {
10488: print("Content-type: $type\n\n");
10489: }
1.9 albertel 10490: }
1.25 albertel 10491:
1.112 bowersj2 10492: =pod
10493:
1.648 raeburn 10494: =item * &add_to_env($name,$value)
1.112 bowersj2 10495:
1.258 albertel 10496: adds $name to the %env hash with value
1.112 bowersj2 10497: $value, if $name already exists, the entry is converted to an array
10498: reference and $value is added to the array.
10499:
10500: =cut
10501:
1.25 albertel 10502: sub add_to_env {
10503: my ($name,$value)=@_;
1.258 albertel 10504: if (defined($env{$name})) {
10505: if (ref($env{$name})) {
1.25 albertel 10506: #already have multiple values
1.258 albertel 10507: push(@{ $env{$name} },$value);
1.25 albertel 10508: } else {
10509: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10510: my $first=$env{$name};
10511: undef($env{$name});
10512: push(@{ $env{$name} },$first,$value);
1.25 albertel 10513: }
10514: } else {
1.258 albertel 10515: $env{$name}=$value;
1.25 albertel 10516: }
1.31 albertel 10517: }
1.149 albertel 10518:
10519: =pod
10520:
1.648 raeburn 10521: =item * &get_env_multiple($name)
1.149 albertel 10522:
1.258 albertel 10523: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10524: values may be defined and end up as an array ref.
10525:
10526: returns an array of values
10527:
10528: =cut
10529:
10530: sub get_env_multiple {
10531: my ($name) = @_;
10532: my @values;
1.258 albertel 10533: if (defined($env{$name})) {
1.149 albertel 10534: # exists is it an array
1.258 albertel 10535: if (ref($env{$name})) {
10536: @values=@{ $env{$name} };
1.149 albertel 10537: } else {
1.258 albertel 10538: $values[0]=$env{$name};
1.149 albertel 10539: }
10540: }
10541: return(@values);
10542: }
10543:
1.660 raeburn 10544: sub ask_for_embedded_content {
10545: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10546: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1075.2.11 raeburn 10547: %currsubfile,%unused,$rem);
1.1071 raeburn 10548: my $counter = 0;
10549: my $numnew = 0;
1.987 raeburn 10550: my $numremref = 0;
10551: my $numinvalid = 0;
10552: my $numpathchg = 0;
10553: my $numexisting = 0;
1.1071 raeburn 10554: my $numunused = 0;
10555: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1075.2.53 raeburn 10556: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10557: my $heading = &mt('Upload embedded files');
10558: my $buttontext = &mt('Upload');
10559:
1.1075.2.11 raeburn 10560: if ($env{'request.course.id'}) {
1.1075.2.35 raeburn 10561: if ($actionurl eq '/adm/dependencies') {
10562: $navmap = Apache::lonnavmaps::navmap->new();
10563: }
10564: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10565: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1075.2.11 raeburn 10566: }
1.1075.2.35 raeburn 10567: if (($actionurl eq '/adm/portfolio') ||
10568: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10569: my $current_path='/';
10570: if ($env{'form.currentpath'}) {
10571: $current_path = $env{'form.currentpath'};
10572: }
10573: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1075.2.35 raeburn 10574: $udom = $cdom;
10575: $uname = $cnum;
1.984 raeburn 10576: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10577: } else {
10578: $udom = $env{'user.domain'};
10579: $uname = $env{'user.name'};
10580: $url = '/userfiles/portfolio';
10581: }
1.987 raeburn 10582: $toplevel = $url.'/';
1.984 raeburn 10583: $url .= $current_path;
10584: $getpropath = 1;
1.987 raeburn 10585: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10586: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10587: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10588: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10589: $toplevel = $url;
1.984 raeburn 10590: if ($rest ne '') {
1.987 raeburn 10591: $url .= $rest;
10592: }
10593: } elsif ($actionurl eq '/adm/coursedocs') {
10594: if (ref($args) eq 'HASH') {
1.1071 raeburn 10595: $url = $args->{'docs_url'};
10596: $toplevel = $url;
1.1075.2.11 raeburn 10597: if ($args->{'context'} eq 'paste') {
10598: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10599: ($path) =
10600: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10601: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10602: $fileloc =~ s{^/}{};
10603: }
1.1071 raeburn 10604: }
10605: } elsif ($actionurl eq '/adm/dependencies') {
10606: if ($env{'request.course.id'} ne '') {
10607: if (ref($args) eq 'HASH') {
10608: $url = $args->{'docs_url'};
10609: $title = $args->{'docs_title'};
1.1075.2.35 raeburn 10610: $toplevel = $url;
10611: unless ($toplevel =~ m{^/}) {
10612: $toplevel = "/$url";
10613: }
1.1075.2.11 raeburn 10614: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1075.2.35 raeburn 10615: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10616: $path = $1;
10617: } else {
10618: ($path) =
10619: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10620: }
1.1075.2.79 raeburn 10621: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10622: $fileloc = $toplevel;
10623: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10624: my ($udom,$uname,$fname) =
10625: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10626: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10627: } else {
10628: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10629: }
1.1071 raeburn 10630: $fileloc =~ s{^/}{};
10631: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10632: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10633: }
1.987 raeburn 10634: }
1.1075.2.35 raeburn 10635: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10636: $udom = $cdom;
10637: $uname = $cnum;
10638: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10639: $toplevel = $url;
10640: $path = $url;
10641: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10642: $fileloc =~ s{^/}{};
10643: }
10644: foreach my $file (keys(%{$allfiles})) {
10645: my $embed_file;
10646: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10647: $embed_file = $1;
10648: } else {
10649: $embed_file = $file;
10650: }
1.1075.2.55 raeburn 10651: my ($absolutepath,$cleaned_file);
10652: if ($embed_file =~ m{^\w+://}) {
10653: $cleaned_file = $embed_file;
1.1075.2.47 raeburn 10654: $newfiles{$cleaned_file} = 1;
10655: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10656: } else {
1.1075.2.55 raeburn 10657: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10658: if ($embed_file =~ m{^/}) {
10659: $absolutepath = $embed_file;
10660: }
1.1075.2.47 raeburn 10661: if ($cleaned_file =~ m{/}) {
10662: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10663: $path = &check_for_traversal($path,$url,$toplevel);
10664: my $item = $fname;
10665: if ($path ne '') {
10666: $item = $path.'/'.$fname;
10667: $subdependencies{$path}{$fname} = 1;
10668: } else {
10669: $dependencies{$item} = 1;
10670: }
10671: if ($absolutepath) {
10672: $mapping{$item} = $absolutepath;
10673: } else {
10674: $mapping{$item} = $embed_file;
10675: }
10676: } else {
10677: $dependencies{$embed_file} = 1;
10678: if ($absolutepath) {
1.1075.2.47 raeburn 10679: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10680: } else {
1.1075.2.47 raeburn 10681: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10682: }
10683: }
1.984 raeburn 10684: }
10685: }
1.1071 raeburn 10686: my $dirptr = 16384;
1.984 raeburn 10687: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10688: $currsubfile{$path} = {};
1.1075.2.35 raeburn 10689: if (($actionurl eq '/adm/portfolio') ||
10690: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10691: my ($sublistref,$listerror) =
10692: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10693: if (ref($sublistref) eq 'ARRAY') {
10694: foreach my $line (@{$sublistref}) {
10695: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10696: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10697: }
1.984 raeburn 10698: }
1.987 raeburn 10699: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10700: if (opendir(my $dir,$url.'/'.$path)) {
10701: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10702: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10703: }
1.1075.2.11 raeburn 10704: } elsif (($actionurl eq '/adm/dependencies') ||
10705: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10706: ($args->{'context'} eq 'paste')) ||
10707: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10708: if ($env{'request.course.id'} ne '') {
1.1075.2.35 raeburn 10709: my $dir;
10710: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10711: $dir = $fileloc;
10712: } else {
10713: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10714: }
1.1071 raeburn 10715: if ($dir ne '') {
10716: my ($sublistref,$listerror) =
10717: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10718: if (ref($sublistref) eq 'ARRAY') {
10719: foreach my $line (@{$sublistref}) {
10720: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10721: undef,$mtime)=split(/\&/,$line,12);
10722: unless (($testdir&$dirptr) ||
10723: ($file_name =~ /^\.\.?$/)) {
10724: $currsubfile{$path}{$file_name} = [$size,$mtime];
10725: }
10726: }
10727: }
10728: }
1.984 raeburn 10729: }
10730: }
10731: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10732: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10733: my $item = $path.'/'.$file;
10734: unless ($mapping{$item} eq $item) {
10735: $pathchanges{$item} = 1;
10736: }
10737: $existing{$item} = 1;
10738: $numexisting ++;
10739: } else {
10740: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10741: }
10742: }
1.1071 raeburn 10743: if ($actionurl eq '/adm/dependencies') {
10744: foreach my $path (keys(%currsubfile)) {
10745: if (ref($currsubfile{$path}) eq 'HASH') {
10746: foreach my $file (keys(%{$currsubfile{$path}})) {
10747: unless ($subdependencies{$path}{$file}) {
1.1075.2.11 raeburn 10748: next if (($rem ne '') &&
10749: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10750: (ref($navmap) &&
10751: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10752: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10753: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10754: $unused{$path.'/'.$file} = 1;
10755: }
10756: }
10757: }
10758: }
10759: }
1.984 raeburn 10760: }
1.987 raeburn 10761: my %currfile;
1.1075.2.35 raeburn 10762: if (($actionurl eq '/adm/portfolio') ||
10763: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10764: my ($dirlistref,$listerror) =
10765: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10766: if (ref($dirlistref) eq 'ARRAY') {
10767: foreach my $line (@{$dirlistref}) {
10768: my ($file_name,$rest) = split(/\&/,$line,2);
10769: $currfile{$file_name} = 1;
10770: }
1.984 raeburn 10771: }
1.987 raeburn 10772: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10773: if (opendir(my $dir,$url)) {
1.987 raeburn 10774: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10775: map {$currfile{$_} = 1;} @dir_list;
10776: }
1.1075.2.11 raeburn 10777: } elsif (($actionurl eq '/adm/dependencies') ||
10778: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1075.2.35 raeburn 10779: ($args->{'context'} eq 'paste')) ||
10780: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10781: if ($env{'request.course.id'} ne '') {
10782: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10783: if ($dir ne '') {
10784: my ($dirlistref,$listerror) =
10785: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10786: if (ref($dirlistref) eq 'ARRAY') {
10787: foreach my $line (@{$dirlistref}) {
10788: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10789: $size,undef,$mtime)=split(/\&/,$line,12);
10790: unless (($testdir&$dirptr) ||
10791: ($file_name =~ /^\.\.?$/)) {
10792: $currfile{$file_name} = [$size,$mtime];
10793: }
10794: }
10795: }
10796: }
10797: }
1.984 raeburn 10798: }
10799: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10800: if (exists($currfile{$file})) {
1.987 raeburn 10801: unless ($mapping{$file} eq $file) {
10802: $pathchanges{$file} = 1;
10803: }
10804: $existing{$file} = 1;
10805: $numexisting ++;
10806: } else {
1.984 raeburn 10807: $newfiles{$file} = 1;
10808: }
10809: }
1.1071 raeburn 10810: foreach my $file (keys(%currfile)) {
10811: unless (($file eq $filename) ||
10812: ($file eq $filename.'.bak') ||
10813: ($dependencies{$file})) {
1.1075.2.11 raeburn 10814: if ($actionurl eq '/adm/dependencies') {
1.1075.2.35 raeburn 10815: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10816: next if (($rem ne '') &&
10817: (($env{"httpref.$rem".$file} ne '') ||
10818: (ref($navmap) &&
10819: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10820: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10821: ($navmap->getResourceByUrl($rem.$1)))))));
10822: }
1.1075.2.11 raeburn 10823: }
1.1071 raeburn 10824: $unused{$file} = 1;
10825: }
10826: }
1.1075.2.11 raeburn 10827: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10828: ($args->{'context'} eq 'paste')) {
10829: $counter = scalar(keys(%existing));
10830: $numpathchg = scalar(keys(%pathchanges));
10831: return ($output,$counter,$numpathchg,\%existing);
1.1075.2.35 raeburn 10832: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10833: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10834: $counter = scalar(keys(%existing));
10835: $numpathchg = scalar(keys(%pathchanges));
10836: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1075.2.11 raeburn 10837: }
1.984 raeburn 10838: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10839: if ($actionurl eq '/adm/dependencies') {
10840: next if ($embed_file =~ m{^\w+://});
10841: }
1.660 raeburn 10842: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10843: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10844: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10845: unless ($mapping{$embed_file} eq $embed_file) {
1.1075.2.35 raeburn 10846: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10847: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10848: }
1.1075.2.35 raeburn 10849: $upload_output .= '</td>';
1.1071 raeburn 10850: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1075.2.35 raeburn 10851: $upload_output.='<td align="right">'.
10852: '<span class="LC_info LC_fontsize_medium">'.
10853: &mt("URL points to web address").'</span>';
1.987 raeburn 10854: $numremref++;
1.660 raeburn 10855: } elsif ($args->{'error_on_invalid_names'}
10856: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1075.2.35 raeburn 10857: $upload_output.='<td align="right"><span class="LC_warning">'.
10858: &mt('Invalid characters').'</span>';
1.987 raeburn 10859: $numinvalid++;
1.660 raeburn 10860: } else {
1.1075.2.35 raeburn 10861: $upload_output .= '<td>'.
10862: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10863: $embed_file,\%mapping,
1.1071 raeburn 10864: $allfiles,$codebase,'upload');
10865: $counter ++;
10866: $numnew ++;
1.987 raeburn 10867: }
10868: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10869: }
10870: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10871: if ($actionurl eq '/adm/dependencies') {
10872: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10873: $modify_output .= &start_data_table_row().
10874: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10875: '<img src="'.&icon($embed_file).'" border="0" />'.
10876: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10877: '<td>'.$size.'</td>'.
10878: '<td>'.$mtime.'</td>'.
10879: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10880: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10881: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10882: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10883: &embedded_file_element('upload_embedded',$counter,
10884: $embed_file,\%mapping,
10885: $allfiles,$codebase,'modify').
10886: '</div></td>'.
10887: &end_data_table_row()."\n";
10888: $counter ++;
10889: } else {
10890: $upload_output .= &start_data_table_row().
1.1075.2.35 raeburn 10891: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10892: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10893: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10894: &Apache::loncommon::end_data_table_row()."\n";
10895: }
10896: }
10897: my $delidx = $counter;
10898: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10899: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10900: $delete_output .= &start_data_table_row().
10901: '<td><img src="'.&icon($oldfile).'" />'.
10902: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10903: '<td>'.$size.'</td>'.
10904: '<td>'.$mtime.'</td>'.
10905: '<td><label><input type="checkbox" name="del_upload_dep" '.
10906: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10907: &embedded_file_element('upload_embedded',$delidx,
10908: $oldfile,\%mapping,$allfiles,
10909: $codebase,'delete').'</td>'.
10910: &end_data_table_row()."\n";
10911: $numunused ++;
10912: $delidx ++;
1.987 raeburn 10913: }
10914: if ($upload_output) {
10915: $upload_output = &start_data_table().
10916: $upload_output.
10917: &end_data_table()."\n";
10918: }
1.1071 raeburn 10919: if ($modify_output) {
10920: $modify_output = &start_data_table().
10921: &start_data_table_header_row().
10922: '<th>'.&mt('File').'</th>'.
10923: '<th>'.&mt('Size (KB)').'</th>'.
10924: '<th>'.&mt('Modified').'</th>'.
10925: '<th>'.&mt('Upload replacement?').'</th>'.
10926: &end_data_table_header_row().
10927: $modify_output.
10928: &end_data_table()."\n";
10929: }
10930: if ($delete_output) {
10931: $delete_output = &start_data_table().
10932: &start_data_table_header_row().
10933: '<th>'.&mt('File').'</th>'.
10934: '<th>'.&mt('Size (KB)').'</th>'.
10935: '<th>'.&mt('Modified').'</th>'.
10936: '<th>'.&mt('Delete?').'</th>'.
10937: &end_data_table_header_row().
10938: $delete_output.
10939: &end_data_table()."\n";
10940: }
1.987 raeburn 10941: my $applies = 0;
10942: if ($numremref) {
10943: $applies ++;
10944: }
10945: if ($numinvalid) {
10946: $applies ++;
10947: }
10948: if ($numexisting) {
10949: $applies ++;
10950: }
1.1071 raeburn 10951: if ($counter || $numunused) {
1.987 raeburn 10952: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10953: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10954: $state.'<h3>'.$heading.'</h3>';
10955: if ($actionurl eq '/adm/dependencies') {
10956: if ($numnew) {
10957: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10958: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10959: $upload_output.'<br />'."\n";
10960: }
10961: if ($numexisting) {
10962: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10963: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10964: $modify_output.'<br />'."\n";
10965: $buttontext = &mt('Save changes');
10966: }
10967: if ($numunused) {
10968: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10969: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10970: $delete_output.'<br />'."\n";
10971: $buttontext = &mt('Save changes');
10972: }
10973: } else {
10974: $output .= $upload_output.'<br />'."\n";
10975: }
10976: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10977: $counter.'" />'."\n";
10978: if ($actionurl eq '/adm/dependencies') {
10979: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10980: $numnew.'" />'."\n";
10981: } elsif ($actionurl eq '') {
1.987 raeburn 10982: $output .= '<input type="hidden" name="phase" value="three" />';
10983: }
10984: } elsif ($applies) {
10985: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10986: if ($applies > 1) {
10987: $output .=
1.1075.2.35 raeburn 10988: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10989: if ($numremref) {
10990: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10991: }
10992: if ($numinvalid) {
10993: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10994: }
10995: if ($numexisting) {
10996: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10997: }
10998: $output .= '</ul><br />';
10999: } elsif ($numremref) {
11000: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11001: } elsif ($numinvalid) {
11002: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11003: } elsif ($numexisting) {
11004: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11005: }
11006: $output .= $upload_output.'<br />';
11007: }
11008: my ($pathchange_output,$chgcount);
1.1071 raeburn 11009: $chgcount = $counter;
1.987 raeburn 11010: if (keys(%pathchanges) > 0) {
11011: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11012: if ($counter) {
1.987 raeburn 11013: $output .= &embedded_file_element('pathchange',$chgcount,
11014: $embed_file,\%mapping,
1.1071 raeburn 11015: $allfiles,$codebase,'change');
1.987 raeburn 11016: } else {
11017: $pathchange_output .=
11018: &start_data_table_row().
11019: '<td><input type ="checkbox" name="namechange" value="'.
11020: $chgcount.'" checked="checked" /></td>'.
11021: '<td>'.$mapping{$embed_file}.'</td>'.
11022: '<td>'.$embed_file.
11023: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11024: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11025: '</td>'.&end_data_table_row();
1.660 raeburn 11026: }
1.987 raeburn 11027: $numpathchg ++;
11028: $chgcount ++;
1.660 raeburn 11029: }
11030: }
1.1075.2.35 raeburn 11031: if (($counter) || ($numunused)) {
1.987 raeburn 11032: if ($numpathchg) {
11033: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11034: $numpathchg.'" />'."\n";
11035: }
11036: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11037: ($actionurl eq '/adm/imsimport')) {
11038: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11039: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11040: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11041: } elsif ($actionurl eq '/adm/dependencies') {
11042: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11043: }
1.1075.2.35 raeburn 11044: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11045: } elsif ($numpathchg) {
11046: my %pathchange = ();
11047: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11048: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11049: $output .= '<p>'.&mt('or').'</p>';
1.1075.2.35 raeburn 11050: }
1.987 raeburn 11051: }
1.1071 raeburn 11052: return ($output,$counter,$numpathchg);
1.987 raeburn 11053: }
11054:
1.1075.2.47 raeburn 11055: =pod
11056:
11057: =item * clean_path($name)
11058:
11059: Performs clean-up of directories, subdirectories and filename in an
11060: embedded object, referenced in an HTML file which is being uploaded
11061: to a course or portfolio, where
11062: "Upload embedded images/multimedia files if HTML file" checkbox was
11063: checked.
11064:
11065: Clean-up is similar to replacements in lonnet::clean_filename()
11066: except each / between sub-directory and next level is preserved.
11067:
11068: =cut
11069:
11070: sub clean_path {
11071: my ($embed_file) = @_;
11072: $embed_file =~s{^/+}{};
11073: my @contents;
11074: if ($embed_file =~ m{/}) {
11075: @contents = split(/\//,$embed_file);
11076: } else {
11077: @contents = ($embed_file);
11078: }
11079: my $lastidx = scalar(@contents)-1;
11080: for (my $i=0; $i<=$lastidx; $i++) {
11081: $contents[$i]=~s{\\}{/}g;
11082: $contents[$i]=~s/\s+/\_/g;
11083: $contents[$i]=~s{[^/\w\.\-]}{}g;
11084: if ($i == $lastidx) {
11085: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11086: }
11087: }
11088: if ($lastidx > 0) {
11089: return join('/',@contents);
11090: } else {
11091: return $contents[0];
11092: }
11093: }
11094:
1.987 raeburn 11095: sub embedded_file_element {
1.1071 raeburn 11096: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11097: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11098: (ref($codebase) eq 'HASH'));
11099: my $output;
1.1071 raeburn 11100: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11101: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11102: }
11103: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11104: &escape($embed_file).'" />';
11105: unless (($context eq 'upload_embedded') &&
11106: ($mapping->{$embed_file} eq $embed_file)) {
11107: $output .='
11108: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11109: }
11110: my $attrib;
11111: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11112: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11113: }
11114: $output .=
11115: "\n\t\t".
11116: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11117: $attrib.'" />';
11118: if (exists($codebase->{$mapping->{$embed_file}})) {
11119: $output .=
11120: "\n\t\t".
11121: '<input name="codebase_'.$num.'" type="hidden" value="'.
11122: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11123: }
1.987 raeburn 11124: return $output;
1.660 raeburn 11125: }
11126:
1.1071 raeburn 11127: sub get_dependency_details {
11128: my ($currfile,$currsubfile,$embed_file) = @_;
11129: my ($size,$mtime,$showsize,$showmtime);
11130: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11131: if ($embed_file =~ m{/}) {
11132: my ($path,$fname) = split(/\//,$embed_file);
11133: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11134: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11135: }
11136: } else {
11137: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11138: ($size,$mtime) = @{$currfile->{$embed_file}};
11139: }
11140: }
11141: $showsize = $size/1024.0;
11142: $showsize = sprintf("%.1f",$showsize);
11143: if ($mtime > 0) {
11144: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11145: }
11146: }
11147: return ($showsize,$showmtime);
11148: }
11149:
11150: sub ask_embedded_js {
11151: return <<"END";
11152: <script type="text/javascript"">
11153: // <![CDATA[
11154: function toggleBrowse(counter) {
11155: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11156: var fileid = document.getElementById('embedded_item_'+counter);
11157: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11158: if (chkboxid.checked == true) {
11159: uploaddivid.style.display='block';
11160: } else {
11161: uploaddivid.style.display='none';
11162: fileid.value = '';
11163: }
11164: }
11165: // ]]>
11166: </script>
11167:
11168: END
11169: }
11170:
1.661 raeburn 11171: sub upload_embedded {
11172: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11173: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11174: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11175: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11176: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11177: my $orig_uploaded_filename =
11178: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11179: foreach my $type ('orig','ref','attrib','codebase') {
11180: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11181: $env{'form.embedded_'.$type.'_'.$i} =
11182: &unescape($env{'form.embedded_'.$type.'_'.$i});
11183: }
11184: }
1.661 raeburn 11185: my ($path,$fname) =
11186: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11187: # no path, whole string is fname
11188: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11189: $fname = &Apache::lonnet::clean_filename($fname);
11190: # See if there is anything left
11191: next if ($fname eq '');
11192:
11193: # Check if file already exists as a file or directory.
11194: my ($state,$msg);
11195: if ($context eq 'portfolio') {
11196: my $port_path = $dirpath;
11197: if ($group ne '') {
11198: $port_path = "groups/$group/$port_path";
11199: }
1.987 raeburn 11200: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11201: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11202: $dir_root,$port_path,$disk_quota,
11203: $current_disk_usage,$uname,$udom);
11204: if ($state eq 'will_exceed_quota'
1.984 raeburn 11205: || $state eq 'file_locked') {
1.661 raeburn 11206: $output .= $msg;
11207: next;
11208: }
11209: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11210: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11211: if ($state eq 'exists') {
11212: $output .= $msg;
11213: next;
11214: }
11215: }
11216: # Check if extension is valid
11217: if (($fname =~ /\.(\w+)$/) &&
11218: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1075.2.53 raeburn 11219: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11220: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11221: next;
11222: } elsif (($fname =~ /\.(\w+)$/) &&
11223: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11224: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11225: next;
11226: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1075.2.34 raeburn 11227: $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 11228: next;
11229: }
11230: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1075.2.35 raeburn 11231: my $subdir = $path;
11232: $subdir =~ s{/+$}{};
1.661 raeburn 11233: if ($context eq 'portfolio') {
1.984 raeburn 11234: my $result;
11235: if ($state eq 'existingfile') {
11236: $result=
11237: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1075.2.35 raeburn 11238: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11239: } else {
1.984 raeburn 11240: $result=
11241: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11242: $dirpath.
1.1075.2.35 raeburn 11243: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11244: if ($result !~ m|^/uploaded/|) {
11245: $output .= '<span class="LC_error">'
11246: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11247: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11248: .'</span><br />';
11249: next;
11250: } else {
1.987 raeburn 11251: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11252: $path.$fname.'</span>').'<br />';
1.984 raeburn 11253: }
1.661 raeburn 11254: }
1.1075.2.35 raeburn 11255: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
11256: my $extendedsubdir = $dirpath.'/'.$subdir;
11257: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11258: my $result =
1.1075.2.35 raeburn 11259: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11260: if ($result !~ m|^/uploaded/|) {
11261: $output .= '<span class="LC_error">'
11262: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11263: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11264: .'</span><br />';
11265: next;
11266: } else {
11267: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11268: $path.$fname.'</span>').'<br />';
1.1075.2.35 raeburn 11269: if ($context eq 'syllabus') {
11270: &Apache::lonnet::make_public_indefinitely($result);
11271: }
1.987 raeburn 11272: }
1.661 raeburn 11273: } else {
11274: # Save the file
11275: my $target = $env{'form.embedded_item_'.$i};
11276: my $fullpath = $dir_root.$dirpath.'/'.$path;
11277: my $dest = $fullpath.$fname;
11278: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11279: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11280: my $count;
11281: my $filepath = $dir_root;
1.1027 raeburn 11282: foreach my $subdir (@parts) {
11283: $filepath .= "/$subdir";
11284: if (!-e $filepath) {
1.661 raeburn 11285: mkdir($filepath,0770);
11286: }
11287: }
11288: my $fh;
11289: if (!open($fh,'>'.$dest)) {
11290: &Apache::lonnet::logthis('Failed to create '.$dest);
11291: $output .= '<span class="LC_error">'.
1.1071 raeburn 11292: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11293: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11294: '</span><br />';
11295: } else {
11296: if (!print $fh $env{'form.embedded_item_'.$i}) {
11297: &Apache::lonnet::logthis('Failed to write to '.$dest);
11298: $output .= '<span class="LC_error">'.
1.1071 raeburn 11299: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11300: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11301: '</span><br />';
11302: } else {
1.987 raeburn 11303: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11304: $url.'</span>').'<br />';
11305: unless ($context eq 'testbank') {
11306: $footer .= &mt('View embedded file: [_1]',
11307: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11308: }
11309: }
11310: close($fh);
11311: }
11312: }
11313: if ($env{'form.embedded_ref_'.$i}) {
11314: $pathchange{$i} = 1;
11315: }
11316: }
11317: if ($output) {
11318: $output = '<p>'.$output.'</p>';
11319: }
11320: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11321: $returnflag = 'ok';
1.1071 raeburn 11322: my $numpathchgs = scalar(keys(%pathchange));
11323: if ($numpathchgs > 0) {
1.987 raeburn 11324: if ($context eq 'portfolio') {
11325: $output .= '<p>'.&mt('or').'</p>';
11326: } elsif ($context eq 'testbank') {
1.1071 raeburn 11327: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11328: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11329: $returnflag = 'modify_orightml';
11330: }
11331: }
1.1071 raeburn 11332: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11333: }
11334:
11335: sub modify_html_form {
11336: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11337: my $end = 0;
11338: my $modifyform;
11339: if ($context eq 'upload_embedded') {
11340: return unless (ref($pathchange) eq 'HASH');
11341: if ($env{'form.number_embedded_items'}) {
11342: $end += $env{'form.number_embedded_items'};
11343: }
11344: if ($env{'form.number_pathchange_items'}) {
11345: $end += $env{'form.number_pathchange_items'};
11346: }
11347: if ($end) {
11348: for (my $i=0; $i<$end; $i++) {
11349: if ($i < $env{'form.number_embedded_items'}) {
11350: next unless($pathchange->{$i});
11351: }
11352: $modifyform .=
11353: &start_data_table_row().
11354: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11355: 'checked="checked" /></td>'.
11356: '<td>'.$env{'form.embedded_ref_'.$i}.
11357: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11358: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11359: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11360: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11361: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11362: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11363: '<td>'.$env{'form.embedded_orig_'.$i}.
11364: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11365: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11366: &end_data_table_row();
1.1071 raeburn 11367: }
1.987 raeburn 11368: }
11369: } else {
11370: $modifyform = $pathchgtable;
11371: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11372: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11373: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11374: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11375: }
11376: }
11377: if ($modifyform) {
1.1071 raeburn 11378: if ($actionurl eq '/adm/dependencies') {
11379: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11380: }
1.987 raeburn 11381: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11382: '<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".
11383: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11384: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11385: '</ol></p>'."\n".'<p>'.
11386: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11387: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11388: &start_data_table()."\n".
11389: &start_data_table_header_row().
11390: '<th>'.&mt('Change?').'</th>'.
11391: '<th>'.&mt('Current reference').'</th>'.
11392: '<th>'.&mt('Required reference').'</th>'.
11393: &end_data_table_header_row()."\n".
11394: $modifyform.
11395: &end_data_table().'<br />'."\n".$hiddenstate.
11396: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11397: '</form>'."\n";
11398: }
11399: return;
11400: }
11401:
11402: sub modify_html_refs {
1.1075.2.35 raeburn 11403: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11404: my $container;
11405: if ($context eq 'portfolio') {
11406: $container = $env{'form.container'};
11407: } elsif ($context eq 'coursedoc') {
11408: $container = $env{'form.primaryurl'};
1.1071 raeburn 11409: } elsif ($context eq 'manage_dependencies') {
11410: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11411: $container = "/$container";
1.1075.2.35 raeburn 11412: } elsif ($context eq 'syllabus') {
11413: $container = $url;
1.987 raeburn 11414: } else {
1.1027 raeburn 11415: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11416: }
11417: my (%allfiles,%codebase,$output,$content);
11418: my @changes = &get_env_multiple('form.namechange');
1.1075.2.35 raeburn 11419: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11420: if (wantarray) {
11421: return ('',0,0);
11422: } else {
11423: return;
11424: }
11425: }
11426: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11427: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11428: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11429: if (wantarray) {
11430: return ('',0,0);
11431: } else {
11432: return;
11433: }
11434: }
1.987 raeburn 11435: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11436: if ($content eq '-1') {
11437: if (wantarray) {
11438: return ('',0,0);
11439: } else {
11440: return;
11441: }
11442: }
1.987 raeburn 11443: } else {
1.1071 raeburn 11444: unless ($container =~ /^\Q$dir_root\E/) {
11445: if (wantarray) {
11446: return ('',0,0);
11447: } else {
11448: return;
11449: }
11450: }
1.987 raeburn 11451: if (open(my $fh,"<$container")) {
11452: $content = join('', <$fh>);
11453: close($fh);
11454: } else {
1.1071 raeburn 11455: if (wantarray) {
11456: return ('',0,0);
11457: } else {
11458: return;
11459: }
1.987 raeburn 11460: }
11461: }
11462: my ($count,$codebasecount) = (0,0);
11463: my $mm = new File::MMagic;
11464: my $mime_type = $mm->checktype_contents($content);
11465: if ($mime_type eq 'text/html') {
11466: my $parse_result =
11467: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11468: \%codebase,\$content);
11469: if ($parse_result eq 'ok') {
11470: foreach my $i (@changes) {
11471: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11472: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11473: if ($allfiles{$ref}) {
11474: my $newname = $orig;
11475: my ($attrib_regexp,$codebase);
1.1006 raeburn 11476: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11477: if ($attrib_regexp =~ /:/) {
11478: $attrib_regexp =~ s/\:/|/g;
11479: }
11480: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11481: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11482: $count += $numchg;
1.1075.2.35 raeburn 11483: $allfiles{$newname} = $allfiles{$ref};
1.1075.2.48 raeburn 11484: delete($allfiles{$ref});
1.987 raeburn 11485: }
11486: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11487: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11488: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11489: $codebasecount ++;
11490: }
11491: }
11492: }
1.1075.2.35 raeburn 11493: my $skiprewrites;
1.987 raeburn 11494: if ($count || $codebasecount) {
11495: my $saveresult;
1.1071 raeburn 11496: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1075.2.35 raeburn 11497: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11498: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11499: if ($url eq $container) {
11500: my ($fname) = ($container =~ m{/([^/]+)$});
11501: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11502: $count,'<span class="LC_filename">'.
1.1071 raeburn 11503: $fname.'</span>').'</p>';
1.987 raeburn 11504: } else {
11505: $output = '<p class="LC_error">'.
11506: &mt('Error: update failed for: [_1].',
11507: '<span class="LC_filename">'.
11508: $container.'</span>').'</p>';
11509: }
1.1075.2.35 raeburn 11510: if ($context eq 'syllabus') {
11511: unless ($saveresult eq 'ok') {
11512: $skiprewrites = 1;
11513: }
11514: }
1.987 raeburn 11515: } else {
11516: if (open(my $fh,">$container")) {
11517: print $fh $content;
11518: close($fh);
11519: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11520: $count,'<span class="LC_filename">'.
11521: $container.'</span>').'</p>';
1.661 raeburn 11522: } else {
1.987 raeburn 11523: $output = '<p class="LC_error">'.
11524: &mt('Error: could not update [_1].',
11525: '<span class="LC_filename">'.
11526: $container.'</span>').'</p>';
1.661 raeburn 11527: }
11528: }
11529: }
1.1075.2.35 raeburn 11530: if (($context eq 'syllabus') && (!$skiprewrites)) {
11531: my ($actionurl,$state);
11532: $actionurl = "/public/$udom/$uname/syllabus";
11533: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11534: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11535: \%codebase,
11536: {'context' => 'rewrites',
11537: 'ignore_remote_references' => 1,});
11538: if (ref($mapping) eq 'HASH') {
11539: my $rewrites = 0;
11540: foreach my $key (keys(%{$mapping})) {
11541: next if ($key =~ m{^https?://});
11542: my $ref = $mapping->{$key};
11543: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11544: my $attrib;
11545: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11546: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11547: }
11548: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11549: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11550: $rewrites += $numchg;
11551: }
11552: }
11553: if ($rewrites) {
11554: my $saveresult;
11555: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11556: if ($url eq $container) {
11557: my ($fname) = ($container =~ m{/([^/]+)$});
11558: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11559: $count,'<span class="LC_filename">'.
11560: $fname.'</span>').'</p>';
11561: } else {
11562: $output .= '<p class="LC_error">'.
11563: &mt('Error: could not update links in [_1].',
11564: '<span class="LC_filename">'.
11565: $container.'</span>').'</p>';
11566:
11567: }
11568: }
11569: }
11570: }
1.987 raeburn 11571: } else {
11572: &logthis('Failed to parse '.$container.
11573: ' to modify references: '.$parse_result);
1.661 raeburn 11574: }
11575: }
1.1071 raeburn 11576: if (wantarray) {
11577: return ($output,$count,$codebasecount);
11578: } else {
11579: return $output;
11580: }
1.661 raeburn 11581: }
11582:
11583: sub check_for_existing {
11584: my ($path,$fname,$element) = @_;
11585: my ($state,$msg);
11586: if (-d $path.'/'.$fname) {
11587: $state = 'exists';
11588: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11589: } elsif (-e $path.'/'.$fname) {
11590: $state = 'exists';
11591: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11592: }
11593: if ($state eq 'exists') {
11594: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11595: }
11596: return ($state,$msg);
11597: }
11598:
11599: sub check_for_upload {
11600: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11601: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11602: my $filesize = length($env{'form.'.$element});
11603: if (!$filesize) {
11604: my $msg = '<span class="LC_error">'.
11605: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11606: '<span class="LC_filename">'.$fname.'</span>',
11607: $filesize).'<br />'.
1.1007 raeburn 11608: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11609: '</span>';
11610: return ('zero_bytes',$msg);
11611: }
11612: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11613: my $getpropath = 1;
1.1021 raeburn 11614: my ($dirlistref,$listerror) =
11615: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11616: my $found_file = 0;
11617: my $locked_file = 0;
1.991 raeburn 11618: my @lockers;
11619: my $navmap;
11620: if ($env{'request.course.id'}) {
11621: $navmap = Apache::lonnavmaps::navmap->new();
11622: }
1.1021 raeburn 11623: if (ref($dirlistref) eq 'ARRAY') {
11624: foreach my $line (@{$dirlistref}) {
11625: my ($file_name,$rest)=split(/\&/,$line,2);
11626: if ($file_name eq $fname){
11627: $file_name = $path.$file_name;
11628: if ($group ne '') {
11629: $file_name = $group.$file_name;
11630: }
11631: $found_file = 1;
11632: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11633: foreach my $lock (@lockers) {
11634: if (ref($lock) eq 'ARRAY') {
11635: my ($symb,$crsid) = @{$lock};
11636: if ($crsid eq $env{'request.course.id'}) {
11637: if (ref($navmap)) {
11638: my $res = $navmap->getBySymb($symb);
11639: foreach my $part (@{$res->parts()}) {
11640: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11641: unless (($slot_status == $res->RESERVED) ||
11642: ($slot_status == $res->RESERVED_LOCATION)) {
11643: $locked_file = 1;
11644: }
1.991 raeburn 11645: }
1.1021 raeburn 11646: } else {
11647: $locked_file = 1;
1.991 raeburn 11648: }
11649: } else {
11650: $locked_file = 1;
11651: }
11652: }
1.1021 raeburn 11653: }
11654: } else {
11655: my @info = split(/\&/,$rest);
11656: my $currsize = $info[6]/1000;
11657: if ($currsize < $filesize) {
11658: my $extra = $filesize - $currsize;
11659: if (($current_disk_usage + $extra) > $disk_quota) {
1.1075.2.69 raeburn 11660: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11661: &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 11662: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11663: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11664: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11665: return ('will_exceed_quota',$msg);
11666: }
1.984 raeburn 11667: }
11668: }
1.661 raeburn 11669: }
11670: }
11671: }
11672: if (($current_disk_usage + $filesize) > $disk_quota){
1.1075.2.69 raeburn 11673: my $msg = '<p class="LC_warning">'.
11674: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
11675: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11676: return ('will_exceed_quota',$msg);
11677: } elsif ($found_file) {
11678: if ($locked_file) {
1.1075.2.69 raeburn 11679: my $msg = '<p class="LC_warning">';
1.661 raeburn 11680: $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 11681: $msg .= '</p>';
1.661 raeburn 11682: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11683: return ('file_locked',$msg);
11684: } else {
1.1075.2.69 raeburn 11685: my $msg = '<p class="LC_error">';
1.984 raeburn 11686: $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 11687: $msg .= '</p>';
1.984 raeburn 11688: return ('existingfile',$msg);
1.661 raeburn 11689: }
11690: }
11691: }
11692:
1.987 raeburn 11693: sub check_for_traversal {
11694: my ($path,$url,$toplevel) = @_;
11695: my @parts=split(/\//,$path);
11696: my $cleanpath;
11697: my $fullpath = $url;
11698: for (my $i=0;$i<@parts;$i++) {
11699: next if ($parts[$i] eq '.');
11700: if ($parts[$i] eq '..') {
11701: $fullpath =~ s{([^/]+/)$}{};
11702: } else {
11703: $fullpath .= $parts[$i].'/';
11704: }
11705: }
11706: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11707: $cleanpath = $1;
11708: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11709: my $curr_toprel = $1;
11710: my @parts = split(/\//,$curr_toprel);
11711: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11712: my @urlparts = split(/\//,$url_toprel);
11713: my $doubledots;
11714: my $startdiff = -1;
11715: for (my $i=0; $i<@urlparts; $i++) {
11716: if ($startdiff == -1) {
11717: unless ($urlparts[$i] eq $parts[$i]) {
11718: $startdiff = $i;
11719: $doubledots .= '../';
11720: }
11721: } else {
11722: $doubledots .= '../';
11723: }
11724: }
11725: if ($startdiff > -1) {
11726: $cleanpath = $doubledots;
11727: for (my $i=$startdiff; $i<@parts; $i++) {
11728: $cleanpath .= $parts[$i].'/';
11729: }
11730: }
11731: }
11732: $cleanpath =~ s{(/)$}{};
11733: return $cleanpath;
11734: }
1.31 albertel 11735:
1.1053 raeburn 11736: sub is_archive_file {
11737: my ($mimetype) = @_;
11738: if (($mimetype eq 'application/octet-stream') ||
11739: ($mimetype eq 'application/x-stuffit') ||
11740: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11741: return 1;
11742: }
11743: return;
11744: }
11745:
11746: sub decompress_form {
1.1065 raeburn 11747: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11748: my %lt = &Apache::lonlocal::texthash (
11749: this => 'This file is an archive file.',
1.1067 raeburn 11750: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11751: itsc => 'Its contents are as follows:',
1.1053 raeburn 11752: youm => 'You may wish to extract its contents.',
11753: extr => 'Extract contents',
1.1067 raeburn 11754: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11755: proa => 'Process automatically?',
1.1053 raeburn 11756: yes => 'Yes',
11757: no => 'No',
1.1067 raeburn 11758: fold => 'Title for folder containing movie',
11759: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11760: );
1.1065 raeburn 11761: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11762: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11763: my $info = &list_archive_contents($fileloc,\@paths);
11764: if (@paths) {
11765: foreach my $path (@paths) {
11766: $path =~ s{^/}{};
1.1067 raeburn 11767: if ($path =~ m{^([^/]+)/$}) {
11768: $topdir = $1;
11769: }
1.1065 raeburn 11770: if ($path =~ m{^([^/]+)/}) {
11771: $toplevel{$1} = $path;
11772: } else {
11773: $toplevel{$path} = $path;
11774: }
11775: }
11776: }
1.1067 raeburn 11777: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1075.2.59 raeburn 11778: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11779: "$topdir/media/",
11780: "$topdir/media/$topdir.mp4",
11781: "$topdir/media/FirstFrame.png",
11782: "$topdir/media/player.swf",
11783: "$topdir/media/swfobject.js",
11784: "$topdir/media/expressInstall.swf");
1.1075.2.81 raeburn 11785: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1075.2.59 raeburn 11786: "$topdir/$topdir.mp4",
11787: "$topdir/$topdir\_config.xml",
11788: "$topdir/$topdir\_controller.swf",
11789: "$topdir/$topdir\_embed.css",
11790: "$topdir/$topdir\_First_Frame.png",
11791: "$topdir/$topdir\_player.html",
11792: "$topdir/$topdir\_Thumbnails.png",
11793: "$topdir/playerProductInstall.swf",
11794: "$topdir/scripts/",
11795: "$topdir/scripts/config_xml.js",
11796: "$topdir/scripts/handlebars.js",
11797: "$topdir/scripts/jquery-1.7.1.min.js",
11798: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11799: "$topdir/scripts/modernizr.js",
11800: "$topdir/scripts/player-min.js",
11801: "$topdir/scripts/swfobject.js",
11802: "$topdir/skins/",
11803: "$topdir/skins/configuration_express.xml",
11804: "$topdir/skins/express_show/",
11805: "$topdir/skins/express_show/player-min.css",
11806: "$topdir/skins/express_show/spritesheet.png");
1.1075.2.81 raeburn 11807: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11808: "$topdir/$topdir.mp4",
11809: "$topdir/$topdir\_config.xml",
11810: "$topdir/$topdir\_controller.swf",
11811: "$topdir/$topdir\_embed.css",
11812: "$topdir/$topdir\_First_Frame.png",
11813: "$topdir/$topdir\_player.html",
11814: "$topdir/$topdir\_Thumbnails.png",
11815: "$topdir/playerProductInstall.swf",
11816: "$topdir/scripts/",
11817: "$topdir/scripts/config_xml.js",
11818: "$topdir/scripts/techsmith-smart-player.min.js",
11819: "$topdir/skins/",
11820: "$topdir/skins/configuration_express.xml",
11821: "$topdir/skins/express_show/",
11822: "$topdir/skins/express_show/spritesheet.min.css",
11823: "$topdir/skins/express_show/spritesheet.png",
11824: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1075.2.59 raeburn 11825: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11826: if (@diffs == 0) {
1.1075.2.59 raeburn 11827: $is_camtasia = 6;
11828: } else {
1.1075.2.81 raeburn 11829: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1075.2.59 raeburn 11830: if (@diffs == 0) {
11831: $is_camtasia = 8;
1.1075.2.81 raeburn 11832: } else {
11833: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
11834: if (@diffs == 0) {
11835: $is_camtasia = 8;
11836: }
1.1075.2.59 raeburn 11837: }
1.1067 raeburn 11838: }
11839: }
11840: my $output;
11841: if ($is_camtasia) {
11842: $output = <<"ENDCAM";
11843: <script type="text/javascript" language="Javascript">
11844: // <![CDATA[
11845:
11846: function camtasiaToggle() {
11847: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11848: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1075.2.59 raeburn 11849: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11850: document.getElementById('camtasia_titles').style.display='block';
11851: } else {
11852: document.getElementById('camtasia_titles').style.display='none';
11853: }
11854: }
11855: }
11856: return;
11857: }
11858:
11859: // ]]>
11860: </script>
11861: <p>$lt{'camt'}</p>
11862: ENDCAM
1.1065 raeburn 11863: } else {
1.1067 raeburn 11864: $output = '<p>'.$lt{'this'};
11865: if ($info eq '') {
11866: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11867: } else {
11868: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11869: '<div><pre>'.$info.'</pre></div>';
11870: }
1.1065 raeburn 11871: }
1.1067 raeburn 11872: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11873: my $duplicates;
11874: my $num = 0;
11875: if (ref($dirlist) eq 'ARRAY') {
11876: foreach my $item (@{$dirlist}) {
11877: if (ref($item) eq 'ARRAY') {
11878: if (exists($toplevel{$item->[0]})) {
11879: $duplicates .=
11880: &start_data_table_row().
11881: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11882: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11883: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11884: 'value="1" />'.&mt('Yes').'</label>'.
11885: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11886: '<td>'.$item->[0].'</td>';
11887: if ($item->[2]) {
11888: $duplicates .= '<td>'.&mt('Directory').'</td>';
11889: } else {
11890: $duplicates .= '<td>'.&mt('File').'</td>';
11891: }
11892: $duplicates .= '<td>'.$item->[3].'</td>'.
11893: '<td>'.
11894: &Apache::lonlocal::locallocaltime($item->[4]).
11895: '</td>'.
11896: &end_data_table_row();
11897: $num ++;
11898: }
11899: }
11900: }
11901: }
11902: my $itemcount;
11903: if (@paths > 0) {
11904: $itemcount = scalar(@paths);
11905: } else {
11906: $itemcount = 1;
11907: }
1.1067 raeburn 11908: if ($is_camtasia) {
11909: $output .= $lt{'auto'}.'<br />'.
11910: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1075.2.59 raeburn 11911: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11912: $lt{'yes'}.'</label> <label>'.
11913: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11914: $lt{'no'}.'</label></span><br />'.
11915: '<div id="camtasia_titles" style="display:block">'.
11916: &Apache::lonhtmlcommon::start_pick_box().
11917: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11918: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11919: &Apache::lonhtmlcommon::row_closure().
11920: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11921: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11922: &Apache::lonhtmlcommon::row_closure(1).
11923: &Apache::lonhtmlcommon::end_pick_box().
11924: '</div>';
11925: }
1.1065 raeburn 11926: $output .=
11927: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11928: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11929: "\n";
1.1065 raeburn 11930: if ($duplicates ne '') {
11931: $output .= '<p><span class="LC_warning">'.
11932: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11933: &start_data_table().
11934: &start_data_table_header_row().
11935: '<th>'.&mt('Overwrite?').'</th>'.
11936: '<th>'.&mt('Name').'</th>'.
11937: '<th>'.&mt('Type').'</th>'.
11938: '<th>'.&mt('Size').'</th>'.
11939: '<th>'.&mt('Last modified').'</th>'.
11940: &end_data_table_header_row().
11941: $duplicates.
11942: &end_data_table().
11943: '</p>';
11944: }
1.1067 raeburn 11945: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11946: if (ref($hiddenelements) eq 'HASH') {
11947: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11948: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11949: }
11950: }
11951: $output .= <<"END";
1.1067 raeburn 11952: <br />
1.1053 raeburn 11953: <input type="submit" name="decompress" value="$lt{'extr'}" />
11954: </form>
11955: $noextract
11956: END
11957: return $output;
11958: }
11959:
1.1065 raeburn 11960: sub decompression_utility {
11961: my ($program) = @_;
11962: my @utilities = ('tar','gunzip','bunzip2','unzip');
11963: my $location;
11964: if (grep(/^\Q$program\E$/,@utilities)) {
11965: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11966: '/usr/sbin/') {
11967: if (-x $dir.$program) {
11968: $location = $dir.$program;
11969: last;
11970: }
11971: }
11972: }
11973: return $location;
11974: }
11975:
11976: sub list_archive_contents {
11977: my ($file,$pathsref) = @_;
11978: my (@cmd,$output);
11979: my $needsregexp;
11980: if ($file =~ /\.zip$/) {
11981: @cmd = (&decompression_utility('unzip'),"-l");
11982: $needsregexp = 1;
11983: } elsif (($file =~ m/\.tar\.gz$/) ||
11984: ($file =~ /\.tgz$/)) {
11985: @cmd = (&decompression_utility('tar'),"-ztf");
11986: } elsif ($file =~ /\.tar\.bz2$/) {
11987: @cmd = (&decompression_utility('tar'),"-jtf");
11988: } elsif ($file =~ m|\.tar$|) {
11989: @cmd = (&decompression_utility('tar'),"-tf");
11990: }
11991: if (@cmd) {
11992: undef($!);
11993: undef($@);
11994: if (open(my $fh,"-|", @cmd, $file)) {
11995: while (my $line = <$fh>) {
11996: $output .= $line;
11997: chomp($line);
11998: my $item;
11999: if ($needsregexp) {
12000: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12001: } else {
12002: $item = $line;
12003: }
12004: if ($item ne '') {
12005: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12006: push(@{$pathsref},$item);
12007: }
12008: }
12009: }
12010: close($fh);
12011: }
12012: }
12013: return $output;
12014: }
12015:
1.1053 raeburn 12016: sub decompress_uploaded_file {
12017: my ($file,$dir) = @_;
12018: &Apache::lonnet::appenv({'cgi.file' => $file});
12019: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12020: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12021: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12022: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12023: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12024: my $decompressed = $env{'cgi.decompressed'};
12025: &Apache::lonnet::delenv('cgi.file');
12026: &Apache::lonnet::delenv('cgi.dir');
12027: &Apache::lonnet::delenv('cgi.decompressed');
12028: return ($decompressed,$result);
12029: }
12030:
1.1055 raeburn 12031: sub process_decompression {
12032: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
12033: my ($dir,$error,$warning,$output);
1.1075.2.69 raeburn 12034: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1075.2.34 raeburn 12035: $error = &mt('Filename not a supported archive file type.').
12036: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12037: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12038: } else {
12039: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12040: if ($docuhome eq 'no_host') {
12041: $error = &mt('Could not determine home server for course.');
12042: } else {
12043: my @ids=&Apache::lonnet::current_machine_ids();
12044: my $currdir = "$dir_root/$destination";
12045: if (grep(/^\Q$docuhome\E$/,@ids)) {
12046: $dir = &LONCAPA::propath($docudom,$docuname).
12047: "$dir_root/$destination";
12048: } else {
12049: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12050: "$dir_root/$docudom/$docuname/$destination";
12051: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12052: $error = &mt('Archive file not found.');
12053: }
12054: }
1.1065 raeburn 12055: my (@to_overwrite,@to_skip);
12056: if ($env{'form.archive_overwrite_total'} > 0) {
12057: my $total = $env{'form.archive_overwrite_total'};
12058: for (my $i=0; $i<$total; $i++) {
12059: if ($env{'form.archive_overwrite_'.$i} == 1) {
12060: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12061: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12062: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12063: }
12064: }
12065: }
12066: my $numskip = scalar(@to_skip);
12067: if (($numskip > 0) &&
12068: ($numskip == $env{'form.archive_itemcount'})) {
12069: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12070: } elsif ($dir eq '') {
1.1055 raeburn 12071: $error = &mt('Directory containing archive file unavailable.');
12072: } elsif (!$error) {
1.1065 raeburn 12073: my ($decompressed,$display);
12074: if ($numskip > 0) {
12075: my $tempdir = time.'_'.$$.int(rand(10000));
12076: mkdir("$dir/$tempdir",0755);
12077: system("mv $dir/$file $dir/$tempdir/$file");
12078: ($decompressed,$display) =
12079: &decompress_uploaded_file($file,"$dir/$tempdir");
12080: foreach my $item (@to_skip) {
12081: if (($item ne '') && ($item !~ /\.\./)) {
12082: if (-f "$dir/$tempdir/$item") {
12083: unlink("$dir/$tempdir/$item");
12084: } elsif (-d "$dir/$tempdir/$item") {
12085: system("rm -rf $dir/$tempdir/$item");
12086: }
12087: }
12088: }
12089: system("mv $dir/$tempdir/* $dir");
12090: rmdir("$dir/$tempdir");
12091: } else {
12092: ($decompressed,$display) =
12093: &decompress_uploaded_file($file,$dir);
12094: }
1.1055 raeburn 12095: if ($decompressed eq 'ok') {
1.1065 raeburn 12096: $output = '<p class="LC_info">'.
12097: &mt('Files extracted successfully from archive.').
12098: '</p>'."\n";
1.1055 raeburn 12099: my ($warning,$result,@contents);
12100: my ($newdirlistref,$newlisterror) =
12101: &Apache::lonnet::dirlist($currdir,$docudom,
12102: $docuname,1);
12103: my (%is_dir,%changes,@newitems);
12104: my $dirptr = 16384;
1.1065 raeburn 12105: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12106: foreach my $dir_line (@{$newdirlistref}) {
12107: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 12108: unless (($item =~ /^\.+$/) || ($item eq $file) ||
12109: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 12110: push(@newitems,$item);
12111: if ($dirptr&$testdir) {
12112: $is_dir{$item} = 1;
12113: }
12114: $changes{$item} = 1;
12115: }
12116: }
12117: }
12118: if (keys(%changes) > 0) {
12119: foreach my $item (sort(@newitems)) {
12120: if ($changes{$item}) {
12121: push(@contents,$item);
12122: }
12123: }
12124: }
12125: if (@contents > 0) {
1.1067 raeburn 12126: my $wantform;
12127: unless ($env{'form.autoextract_camtasia'}) {
12128: $wantform = 1;
12129: }
1.1056 raeburn 12130: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12131: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12132: $currdir,\%is_dir,
12133: \%children,\%parent,
1.1056 raeburn 12134: \@contents,\%dirorder,
12135: \%titles,$wantform);
1.1055 raeburn 12136: if ($datatable ne '') {
12137: $output .= &archive_options_form('decompressed',$datatable,
12138: $count,$hiddenelem);
1.1065 raeburn 12139: my $startcount = 6;
1.1055 raeburn 12140: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12141: \%titles,\%children);
1.1055 raeburn 12142: }
1.1067 raeburn 12143: if ($env{'form.autoextract_camtasia'}) {
1.1075.2.59 raeburn 12144: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12145: my %displayed;
12146: my $total = 1;
12147: $env{'form.archive_directory'} = [];
12148: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12149: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12150: $path =~ s{/$}{};
12151: my $item;
12152: if ($path ne '') {
12153: $item = "$path/$titles{$i}";
12154: } else {
12155: $item = $titles{$i};
12156: }
12157: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12158: if ($item eq $contents[0]) {
12159: push(@{$env{'form.archive_directory'}},$i);
12160: $env{'form.archive_'.$i} = 'display';
12161: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12162: $displayed{'folder'} = $i;
1.1075.2.59 raeburn 12163: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12164: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12165: $env{'form.archive_'.$i} = 'display';
12166: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12167: $displayed{'web'} = $i;
12168: } else {
1.1075.2.59 raeburn 12169: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12170: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12171: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12172: push(@{$env{'form.archive_directory'}},$i);
12173: }
12174: $env{'form.archive_'.$i} = 'dependency';
12175: }
12176: $total ++;
12177: }
12178: for (my $i=1; $i<$total; $i++) {
12179: next if ($i == $displayed{'web'});
12180: next if ($i == $displayed{'folder'});
12181: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12182: }
12183: $env{'form.phase'} = 'decompress_cleanup';
12184: $env{'form.archivedelete'} = 1;
12185: $env{'form.archive_count'} = $total-1;
12186: $output .=
12187: &process_extracted_files('coursedocs',$docudom,
12188: $docuname,$destination,
12189: $dir_root,$hiddenelem);
12190: }
1.1055 raeburn 12191: } else {
12192: $warning = &mt('No new items extracted from archive file.');
12193: }
12194: } else {
12195: $output = $display;
12196: $error = &mt('An error occurred during extraction from the archive file.');
12197: }
12198: }
12199: }
12200: }
12201: if ($error) {
12202: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12203: $error.'</p>'."\n";
12204: }
12205: if ($warning) {
12206: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12207: }
12208: return $output;
12209: }
12210:
12211: sub get_extracted {
1.1056 raeburn 12212: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12213: $titles,$wantform) = @_;
1.1055 raeburn 12214: my $count = 0;
12215: my $depth = 0;
12216: my $datatable;
1.1056 raeburn 12217: my @hierarchy;
1.1055 raeburn 12218: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12219: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12220: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12221: foreach my $item (@{$contents}) {
12222: $count ++;
1.1056 raeburn 12223: @{$dirorder->{$count}} = @hierarchy;
12224: $titles->{$count} = $item;
1.1055 raeburn 12225: &archive_hierarchy($depth,$count,$parent,$children);
12226: if ($wantform) {
12227: $datatable .= &archive_row($is_dir->{$item},$item,
12228: $currdir,$depth,$count);
12229: }
12230: if ($is_dir->{$item}) {
12231: $depth ++;
1.1056 raeburn 12232: push(@hierarchy,$count);
12233: $parent->{$depth} = $count;
1.1055 raeburn 12234: $datatable .=
12235: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12236: \$depth,\$count,\@hierarchy,$dirorder,
12237: $children,$parent,$titles,$wantform);
1.1055 raeburn 12238: $depth --;
1.1056 raeburn 12239: pop(@hierarchy);
1.1055 raeburn 12240: }
12241: }
12242: return ($count,$datatable);
12243: }
12244:
12245: sub recurse_extracted_archive {
1.1056 raeburn 12246: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12247: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12248: my $result='';
1.1056 raeburn 12249: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12250: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12251: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12252: return $result;
12253: }
12254: my $dirptr = 16384;
12255: my ($newdirlistref,$newlisterror) =
12256: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12257: if (ref($newdirlistref) eq 'ARRAY') {
12258: foreach my $dir_line (@{$newdirlistref}) {
12259: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12260: unless ($item =~ /^\.+$/) {
12261: $$count ++;
1.1056 raeburn 12262: @{$dirorder->{$$count}} = @{$hierarchy};
12263: $titles->{$$count} = $item;
1.1055 raeburn 12264: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12265:
1.1055 raeburn 12266: my $is_dir;
12267: if ($dirptr&$testdir) {
12268: $is_dir = 1;
12269: }
12270: if ($wantform) {
12271: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12272: }
12273: if ($is_dir) {
12274: $$depth ++;
1.1056 raeburn 12275: push(@{$hierarchy},$$count);
12276: $parent->{$$depth} = $$count;
1.1055 raeburn 12277: $result .=
12278: &recurse_extracted_archive("$currdir/$item",$docudom,
12279: $docuname,$depth,$count,
1.1056 raeburn 12280: $hierarchy,$dirorder,$children,
12281: $parent,$titles,$wantform);
1.1055 raeburn 12282: $$depth --;
1.1056 raeburn 12283: pop(@{$hierarchy});
1.1055 raeburn 12284: }
12285: }
12286: }
12287: }
12288: return $result;
12289: }
12290:
12291: sub archive_hierarchy {
12292: my ($depth,$count,$parent,$children) =@_;
12293: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12294: if (exists($parent->{$depth})) {
12295: $children->{$parent->{$depth}} .= $count.':';
12296: }
12297: }
12298: return;
12299: }
12300:
12301: sub archive_row {
12302: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12303: my ($name) = ($item =~ m{([^/]+)$});
12304: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12305: 'display' => 'Add as file',
1.1055 raeburn 12306: 'dependency' => 'Include as dependency',
12307: 'discard' => 'Discard',
12308: );
12309: if ($is_dir) {
1.1059 raeburn 12310: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12311: }
1.1056 raeburn 12312: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12313: my $offset = 0;
1.1055 raeburn 12314: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12315: $offset ++;
1.1065 raeburn 12316: if ($action ne 'display') {
12317: $offset ++;
12318: }
1.1055 raeburn 12319: $output .= '<td><span class="LC_nobreak">'.
12320: '<label><input type="radio" name="archive_'.$count.
12321: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12322: my $text = $choices{$action};
12323: if ($is_dir) {
12324: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12325: if ($action eq 'display') {
1.1059 raeburn 12326: $text = &mt('Add as folder');
1.1055 raeburn 12327: }
1.1056 raeburn 12328: } else {
12329: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12330:
12331: }
12332: $output .= ' /> '.$choices{$action}.'</label></span>';
12333: if ($action eq 'dependency') {
12334: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12335: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12336: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12337: '<option value=""></option>'."\n".
12338: '</select>'."\n".
12339: '</div>';
1.1059 raeburn 12340: } elsif ($action eq 'display') {
12341: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12342: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12343: '</div>';
1.1055 raeburn 12344: }
1.1056 raeburn 12345: $output .= '</td>';
1.1055 raeburn 12346: }
12347: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12348: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12349: for (my $i=0; $i<$depth; $i++) {
12350: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12351: }
12352: if ($is_dir) {
12353: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12354: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12355: } else {
12356: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12357: }
12358: $output .= ' '.$name.'</td>'."\n".
12359: &end_data_table_row();
12360: return $output;
12361: }
12362:
12363: sub archive_options_form {
1.1065 raeburn 12364: my ($form,$display,$count,$hiddenelem) = @_;
12365: my %lt = &Apache::lonlocal::texthash(
12366: perm => 'Permanently remove archive file?',
12367: hows => 'How should each extracted item be incorporated in the course?',
12368: cont => 'Content actions for all',
12369: addf => 'Add as folder/file',
12370: incd => 'Include as dependency for a displayed file',
12371: disc => 'Discard',
12372: no => 'No',
12373: yes => 'Yes',
12374: save => 'Save',
12375: );
12376: my $output = <<"END";
12377: <form name="$form" method="post" action="">
12378: <p><span class="LC_nobreak">$lt{'perm'}
12379: <label>
12380: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12381: </label>
12382:
12383: <label>
12384: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12385: </span>
12386: </p>
12387: <input type="hidden" name="phase" value="decompress_cleanup" />
12388: <br />$lt{'hows'}
12389: <div class="LC_columnSection">
12390: <fieldset>
12391: <legend>$lt{'cont'}</legend>
12392: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12393: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12394: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12395: </fieldset>
12396: </div>
12397: END
12398: return $output.
1.1055 raeburn 12399: &start_data_table()."\n".
1.1065 raeburn 12400: $display."\n".
1.1055 raeburn 12401: &end_data_table()."\n".
12402: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12403: $hiddenelem.
1.1065 raeburn 12404: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12405: '</form>';
12406: }
12407:
12408: sub archive_javascript {
1.1056 raeburn 12409: my ($startcount,$numitems,$titles,$children) = @_;
12410: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12411: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12412: my $scripttag = <<START;
12413: <script type="text/javascript">
12414: // <![CDATA[
12415:
12416: function checkAll(form,prefix) {
12417: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12418: for (var i=0; i < form.elements.length; i++) {
12419: var id = form.elements[i].id;
12420: if ((id != '') && (id != undefined)) {
12421: if (idstr.test(id)) {
12422: if (form.elements[i].type == 'radio') {
12423: form.elements[i].checked = true;
1.1056 raeburn 12424: var nostart = i-$startcount;
1.1059 raeburn 12425: var offset = nostart%7;
12426: var count = (nostart-offset)/7;
1.1056 raeburn 12427: dependencyCheck(form,count,offset);
1.1055 raeburn 12428: }
12429: }
12430: }
12431: }
12432: }
12433:
12434: function propagateCheck(form,count) {
12435: if (count > 0) {
1.1059 raeburn 12436: var startelement = $startcount + ((count-1) * 7);
12437: for (var j=1; j<6; j++) {
12438: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12439: var item = startelement + j;
12440: if (form.elements[item].type == 'radio') {
12441: if (form.elements[item].checked) {
12442: containerCheck(form,count,j);
12443: break;
12444: }
1.1055 raeburn 12445: }
12446: }
12447: }
12448: }
12449: }
12450:
12451: numitems = $numitems
1.1056 raeburn 12452: var titles = new Array(numitems);
12453: var parents = new Array(numitems);
1.1055 raeburn 12454: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12455: parents[i] = new Array;
1.1055 raeburn 12456: }
1.1059 raeburn 12457: var maintitle = '$maintitle';
1.1055 raeburn 12458:
12459: START
12460:
1.1056 raeburn 12461: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12462: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12463: for (my $i=0; $i<@contents; $i ++) {
12464: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12465: }
12466: }
12467:
1.1056 raeburn 12468: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12469: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12470: }
12471:
1.1055 raeburn 12472: $scripttag .= <<END;
12473:
12474: function containerCheck(form,count,offset) {
12475: if (count > 0) {
1.1056 raeburn 12476: dependencyCheck(form,count,offset);
1.1059 raeburn 12477: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12478: form.elements[item].checked = true;
12479: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12480: if (parents[count].length > 0) {
12481: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12482: containerCheck(form,parents[count][j],offset);
12483: }
12484: }
12485: }
12486: }
12487: }
12488:
12489: function dependencyCheck(form,count,offset) {
12490: if (count > 0) {
1.1059 raeburn 12491: var chosen = (offset+$startcount)+7*(count-1);
12492: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12493: var currtype = form.elements[depitem].type;
12494: if (form.elements[chosen].value == 'dependency') {
12495: document.getElementById('arc_depon_'+count).style.display='block';
12496: form.elements[depitem].options.length = 0;
12497: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1075.2.11 raeburn 12498: for (var i=1; i<=numitems; i++) {
12499: if (i == count) {
12500: continue;
12501: }
1.1059 raeburn 12502: var startelement = $startcount + (i-1) * 7;
12503: for (var j=1; j<6; j++) {
12504: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12505: var item = startelement + j;
12506: if (form.elements[item].type == 'radio') {
12507: if (form.elements[item].checked) {
12508: if (form.elements[item].value == 'display') {
12509: var n = form.elements[depitem].options.length;
12510: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12511: }
12512: }
12513: }
12514: }
12515: }
12516: }
12517: } else {
12518: document.getElementById('arc_depon_'+count).style.display='none';
12519: form.elements[depitem].options.length = 0;
12520: form.elements[depitem].options[0] = new Option('Select','',true,true);
12521: }
1.1059 raeburn 12522: titleCheck(form,count,offset);
1.1056 raeburn 12523: }
12524: }
12525:
12526: function propagateSelect(form,count,offset) {
12527: if (count > 0) {
1.1065 raeburn 12528: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12529: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12530: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12531: if (parents[count].length > 0) {
12532: for (var j=0; j<parents[count].length; j++) {
12533: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12534: }
12535: }
12536: }
12537: }
12538: }
1.1056 raeburn 12539:
12540: function containerSelect(form,count,offset,picked) {
12541: if (count > 0) {
1.1065 raeburn 12542: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12543: if (form.elements[item].type == 'radio') {
12544: if (form.elements[item].value == 'dependency') {
12545: if (form.elements[item+1].type == 'select-one') {
12546: for (var i=0; i<form.elements[item+1].options.length; i++) {
12547: if (form.elements[item+1].options[i].value == picked) {
12548: form.elements[item+1].selectedIndex = i;
12549: break;
12550: }
12551: }
12552: }
12553: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12554: if (parents[count].length > 0) {
12555: for (var j=0; j<parents[count].length; j++) {
12556: containerSelect(form,parents[count][j],offset,picked);
12557: }
12558: }
12559: }
12560: }
12561: }
12562: }
12563: }
12564:
1.1059 raeburn 12565: function titleCheck(form,count,offset) {
12566: if (count > 0) {
12567: var chosen = (offset+$startcount)+7*(count-1);
12568: var depitem = $startcount + ((count-1) * 7) + 2;
12569: var currtype = form.elements[depitem].type;
12570: if (form.elements[chosen].value == 'display') {
12571: document.getElementById('arc_title_'+count).style.display='block';
12572: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12573: document.getElementById('archive_title_'+count).value=maintitle;
12574: }
12575: } else {
12576: document.getElementById('arc_title_'+count).style.display='none';
12577: if (currtype == 'text') {
12578: document.getElementById('archive_title_'+count).value='';
12579: }
12580: }
12581: }
12582: return;
12583: }
12584:
1.1055 raeburn 12585: // ]]>
12586: </script>
12587: END
12588: return $scripttag;
12589: }
12590:
12591: sub process_extracted_files {
1.1067 raeburn 12592: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12593: my $numitems = $env{'form.archive_count'};
12594: return unless ($numitems);
12595: my @ids=&Apache::lonnet::current_machine_ids();
12596: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12597: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12598: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12599: if (grep(/^\Q$docuhome\E$/,@ids)) {
12600: $prefix = &LONCAPA::propath($docudom,$docuname);
12601: $pathtocheck = "$dir_root/$destination";
12602: $dir = $dir_root;
12603: $ishome = 1;
12604: } else {
12605: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12606: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
12607: $dir = "$dir_root/$docudom/$docuname";
12608: }
12609: my $currdir = "$dir_root/$destination";
12610: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12611: if ($env{'form.folderpath'}) {
12612: my @items = split('&',$env{'form.folderpath'});
12613: $folders{'0'} = $items[-2];
1.1075.2.17 raeburn 12614: if ($env{'form.folderpath'} =~ /\:1$/) {
12615: $containers{'0'}='page';
12616: } else {
12617: $containers{'0'}='sequence';
12618: }
1.1055 raeburn 12619: }
12620: my @archdirs = &get_env_multiple('form.archive_directory');
12621: if ($numitems) {
12622: for (my $i=1; $i<=$numitems; $i++) {
12623: my $path = $env{'form.archive_content_'.$i};
12624: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12625: my $item = $1;
12626: $toplevelitems{$item} = $i;
12627: if (grep(/^\Q$i\E$/,@archdirs)) {
12628: $is_dir{$item} = 1;
12629: }
12630: }
12631: }
12632: }
1.1067 raeburn 12633: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12634: if (keys(%toplevelitems) > 0) {
12635: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12636: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12637: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12638: }
1.1066 raeburn 12639: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12640: if ($numitems) {
12641: for (my $i=1; $i<=$numitems; $i++) {
1.1075.2.11 raeburn 12642: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12643: my $path = $env{'form.archive_content_'.$i};
12644: if ($path =~ /^\Q$pathtocheck\E/) {
12645: if ($env{'form.archive_'.$i} eq 'discard') {
12646: if ($prefix ne '' && $path ne '') {
12647: if (-e $prefix.$path) {
1.1066 raeburn 12648: if ((@archdirs > 0) &&
12649: (grep(/^\Q$i\E$/,@archdirs))) {
12650: $todeletedir{$prefix.$path} = 1;
12651: } else {
12652: $todelete{$prefix.$path} = 1;
12653: }
1.1055 raeburn 12654: }
12655: }
12656: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12657: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12658: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12659: $docstitle = $env{'form.archive_title_'.$i};
12660: if ($docstitle eq '') {
12661: $docstitle = $title;
12662: }
1.1055 raeburn 12663: $outer = 0;
1.1056 raeburn 12664: if (ref($dirorder{$i}) eq 'ARRAY') {
12665: if (@{$dirorder{$i}} > 0) {
12666: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12667: if ($env{'form.archive_'.$item} eq 'display') {
12668: $outer = $item;
12669: last;
12670: }
12671: }
12672: }
12673: }
12674: my ($errtext,$fatal) =
12675: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12676: '/'.$folders{$outer}.'.'.
12677: $containers{$outer});
12678: next if ($fatal);
12679: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12680: if ($context eq 'coursedocs') {
1.1056 raeburn 12681: $mapinner{$i} = time;
1.1055 raeburn 12682: $folders{$i} = 'default_'.$mapinner{$i};
12683: $containers{$i} = 'sequence';
12684: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12685: $folders{$i}.'.'.$containers{$i};
12686: my $newidx = &LONCAPA::map::getresidx();
12687: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12688: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12689: push(@LONCAPA::map::order,$newidx);
12690: my ($outtext,$errtext) =
12691: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12692: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12693: '.'.$containers{$outer},1,1);
1.1056 raeburn 12694: $newseqid{$i} = $newidx;
1.1067 raeburn 12695: unless ($errtext) {
12696: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
12697: }
1.1055 raeburn 12698: }
12699: } else {
12700: if ($context eq 'coursedocs') {
12701: my $newidx=&LONCAPA::map::getresidx();
12702: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12703: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12704: $title;
12705: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12706: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
12707: }
12708: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12709: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12710: }
12711: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12712: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 12713: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 12714: unless ($ishome) {
12715: my $fetch = "$newdest{$i}/$title";
12716: $fetch =~ s/^\Q$prefix$dir\E//;
12717: $prompttofetch{$fetch} = 1;
12718: }
1.1055 raeburn 12719: }
12720: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12721: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12722: push(@LONCAPA::map::order, $newidx);
12723: my ($outtext,$errtext)=
12724: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12725: $docuname.'/'.$folders{$outer}.
1.1075.2.11 raeburn 12726: '.'.$containers{$outer},1,1);
1.1067 raeburn 12727: unless ($errtext) {
12728: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
12729: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
12730: }
12731: }
1.1055 raeburn 12732: }
12733: }
1.1075.2.11 raeburn 12734: }
12735: } else {
12736: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12737: }
12738: }
12739: for (my $i=1; $i<=$numitems; $i++) {
12740: next unless ($env{'form.archive_'.$i} eq 'dependency');
12741: my $path = $env{'form.archive_content_'.$i};
12742: if ($path =~ /^\Q$pathtocheck\E/) {
12743: my ($title) = ($path =~ m{/([^/]+)$});
12744: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12745: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12746: if (ref($dirorder{$i}) eq 'ARRAY') {
12747: my ($itemidx,$fullpath,$relpath);
12748: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12749: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12750: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1075.2.11 raeburn 12751: if ($dirorder{$i}->[$j] eq $container) {
12752: $itemidx = $j;
1.1056 raeburn 12753: }
12754: }
1.1075.2.11 raeburn 12755: }
12756: if ($itemidx eq '') {
12757: $itemidx = 0;
12758: }
12759: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12760: if ($mapinner{$referrer{$i}}) {
12761: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12762: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12763: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12764: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12765: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12766: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12767: if (!-e $fullpath) {
12768: mkdir($fullpath,0755);
1.1056 raeburn 12769: }
12770: }
1.1075.2.11 raeburn 12771: } else {
12772: last;
1.1056 raeburn 12773: }
1.1075.2.11 raeburn 12774: }
12775: }
12776: } elsif ($newdest{$referrer{$i}}) {
12777: $fullpath = $newdest{$referrer{$i}};
12778: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12779: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12780: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12781: last;
12782: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12783: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12784: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12785: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12786: if (!-e $fullpath) {
12787: mkdir($fullpath,0755);
1.1056 raeburn 12788: }
12789: }
1.1075.2.11 raeburn 12790: } else {
12791: last;
1.1056 raeburn 12792: }
1.1075.2.11 raeburn 12793: }
12794: }
12795: if ($fullpath ne '') {
12796: if (-e "$prefix$path") {
12797: system("mv $prefix$path $fullpath/$title");
12798: }
12799: if (-e "$fullpath/$title") {
12800: my $showpath;
12801: if ($relpath ne '') {
12802: $showpath = "$relpath/$title";
12803: } else {
12804: $showpath = "/$title";
1.1056 raeburn 12805: }
1.1075.2.11 raeburn 12806: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12807: }
12808: unless ($ishome) {
12809: my $fetch = "$fullpath/$title";
12810: $fetch =~ s/^\Q$prefix$dir\E//;
12811: $prompttofetch{$fetch} = 1;
1.1055 raeburn 12812: }
12813: }
12814: }
1.1075.2.11 raeburn 12815: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12816: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12817: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12818: }
12819: } else {
1.1075.2.11 raeburn 12820: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
1.1055 raeburn 12821: }
12822: }
12823: if (keys(%todelete)) {
12824: foreach my $key (keys(%todelete)) {
12825: unlink($key);
1.1066 raeburn 12826: }
12827: }
12828: if (keys(%todeletedir)) {
12829: foreach my $key (keys(%todeletedir)) {
12830: rmdir($key);
12831: }
12832: }
12833: foreach my $dir (sort(keys(%is_dir))) {
12834: if (($pathtocheck ne '') && ($dir ne '')) {
12835: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12836: }
12837: }
1.1067 raeburn 12838: if ($result ne '') {
12839: $output .= '<ul>'."\n".
12840: $result."\n".
12841: '</ul>';
12842: }
12843: unless ($ishome) {
12844: my $replicationfail;
12845: foreach my $item (keys(%prompttofetch)) {
12846: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12847: unless ($fetchresult eq 'ok') {
12848: $replicationfail .= '<li>'.$item.'</li>'."\n";
12849: }
12850: }
12851: if ($replicationfail) {
12852: $output .= '<p class="LC_error">'.
12853: &mt('Course home server failed to retrieve:').'<ul>'.
12854: $replicationfail.
12855: '</ul></p>';
12856: }
12857: }
1.1055 raeburn 12858: } else {
12859: $warning = &mt('No items found in archive.');
12860: }
12861: if ($error) {
12862: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12863: $error.'</p>'."\n";
12864: }
12865: if ($warning) {
12866: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12867: }
12868: return $output;
12869: }
12870:
1.1066 raeburn 12871: sub cleanup_empty_dirs {
12872: my ($path) = @_;
12873: if (($path ne '') && (-d $path)) {
12874: if (opendir(my $dirh,$path)) {
12875: my @dircontents = grep(!/^\./,readdir($dirh));
12876: my $numitems = 0;
12877: foreach my $item (@dircontents) {
12878: if (-d "$path/$item") {
1.1075.2.28 raeburn 12879: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12880: if (-e "$path/$item") {
12881: $numitems ++;
12882: }
12883: } else {
12884: $numitems ++;
12885: }
12886: }
12887: if ($numitems == 0) {
12888: rmdir($path);
12889: }
12890: closedir($dirh);
12891: }
12892: }
12893: return;
12894: }
12895:
1.41 ng 12896: =pod
1.45 matthew 12897:
1.1075.2.56 raeburn 12898: =item * &get_folder_hierarchy()
1.1068 raeburn 12899:
12900: Provides hierarchy of names of folders/sub-folders containing the current
12901: item,
12902:
12903: Inputs: 3
12904: - $navmap - navmaps object
12905:
12906: - $map - url for map (either the trigger itself, or map containing
12907: the resource, which is the trigger).
12908:
12909: - $showitem - 1 => show title for map itself; 0 => do not show.
12910:
12911: Outputs: 1 @pathitems - array of folder/subfolder names.
12912:
12913: =cut
12914:
12915: sub get_folder_hierarchy {
12916: my ($navmap,$map,$showitem) = @_;
12917: my @pathitems;
12918: if (ref($navmap)) {
12919: my $mapres = $navmap->getResourceByUrl($map);
12920: if (ref($mapres)) {
12921: my $pcslist = $mapres->map_hierarchy();
12922: if ($pcslist ne '') {
12923: my @pcs = split(/,/,$pcslist);
12924: foreach my $pc (@pcs) {
12925: if ($pc == 1) {
1.1075.2.38 raeburn 12926: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12927: } else {
12928: my $res = $navmap->getByMapPc($pc);
12929: if (ref($res)) {
12930: my $title = $res->compTitle();
12931: $title =~ s/\W+/_/g;
12932: if ($title ne '') {
12933: push(@pathitems,$title);
12934: }
12935: }
12936: }
12937: }
12938: }
1.1071 raeburn 12939: if ($showitem) {
12940: if ($mapres->{ID} eq '0.0') {
1.1075.2.38 raeburn 12941: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12942: } else {
12943: my $maptitle = $mapres->compTitle();
12944: $maptitle =~ s/\W+/_/g;
12945: if ($maptitle ne '') {
12946: push(@pathitems,$maptitle);
12947: }
1.1068 raeburn 12948: }
12949: }
12950: }
12951: }
12952: return @pathitems;
12953: }
12954:
12955: =pod
12956:
1.1015 raeburn 12957: =item * &get_turnedin_filepath()
12958:
12959: Determines path in a user's portfolio file for storage of files uploaded
12960: to a specific essayresponse or dropbox item.
12961:
12962: Inputs: 3 required + 1 optional.
12963: $symb is symb for resource, $uname and $udom are for current user (required).
12964: $caller is optional (can be "submission", if routine is called when storing
12965: an upoaded file when "Submit Answer" button was pressed).
12966:
12967: Returns array containing $path and $multiresp.
12968: $path is path in portfolio. $multiresp is 1 if this resource contains more
12969: than one file upload item. Callers of routine should append partid as a
12970: subdirectory to $path in cases where $multiresp is 1.
12971:
12972: Called by: homework/essayresponse.pm and homework/structuretags.pm
12973:
12974: =cut
12975:
12976: sub get_turnedin_filepath {
12977: my ($symb,$uname,$udom,$caller) = @_;
12978: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12979: my $turnindir;
12980: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12981: $turnindir = $userhash{'turnindir'};
12982: my ($path,$multiresp);
12983: if ($turnindir eq '') {
12984: if ($caller eq 'submission') {
12985: $turnindir = &mt('turned in');
12986: $turnindir =~ s/\W+/_/g;
12987: my %newhash = (
12988: 'turnindir' => $turnindir,
12989: );
12990: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12991: }
12992: }
12993: if ($turnindir ne '') {
12994: $path = '/'.$turnindir.'/';
12995: my ($multipart,$turnin,@pathitems);
12996: my $navmap = Apache::lonnavmaps::navmap->new();
12997: if (defined($navmap)) {
12998: my $mapres = $navmap->getResourceByUrl($map);
12999: if (ref($mapres)) {
13000: my $pcslist = $mapres->map_hierarchy();
13001: if ($pcslist ne '') {
13002: foreach my $pc (split(/,/,$pcslist)) {
13003: my $res = $navmap->getByMapPc($pc);
13004: if (ref($res)) {
13005: my $title = $res->compTitle();
13006: $title =~ s/\W+/_/g;
13007: if ($title ne '') {
1.1075.2.48 raeburn 13008: if (($pc > 1) && (length($title) > 12)) {
13009: $title = substr($title,0,12);
13010: }
1.1015 raeburn 13011: push(@pathitems,$title);
13012: }
13013: }
13014: }
13015: }
13016: my $maptitle = $mapres->compTitle();
13017: $maptitle =~ s/\W+/_/g;
13018: if ($maptitle ne '') {
1.1075.2.48 raeburn 13019: if (length($maptitle) > 12) {
13020: $maptitle = substr($maptitle,0,12);
13021: }
1.1015 raeburn 13022: push(@pathitems,$maptitle);
13023: }
13024: unless ($env{'request.state'} eq 'construct') {
13025: my $res = $navmap->getBySymb($symb);
13026: if (ref($res)) {
13027: my $partlist = $res->parts();
13028: my $totaluploads = 0;
13029: if (ref($partlist) eq 'ARRAY') {
13030: foreach my $part (@{$partlist}) {
13031: my @types = $res->responseType($part);
13032: my @ids = $res->responseIds($part);
13033: for (my $i=0; $i < scalar(@ids); $i++) {
13034: if ($types[$i] eq 'essay') {
13035: my $partid = $part.'_'.$ids[$i];
13036: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13037: $totaluploads ++;
13038: }
13039: }
13040: }
13041: }
13042: if ($totaluploads > 1) {
13043: $multiresp = 1;
13044: }
13045: }
13046: }
13047: }
13048: } else {
13049: return;
13050: }
13051: } else {
13052: return;
13053: }
13054: my $restitle=&Apache::lonnet::gettitle($symb);
13055: $restitle =~ s/\W+/_/g;
13056: if ($restitle eq '') {
13057: $restitle = ($resurl =~ m{/[^/]+$});
13058: if ($restitle eq '') {
13059: $restitle = time;
13060: }
13061: }
1.1075.2.48 raeburn 13062: if (length($restitle) > 12) {
13063: $restitle = substr($restitle,0,12);
13064: }
1.1015 raeburn 13065: push(@pathitems,$restitle);
13066: $path .= join('/',@pathitems);
13067: }
13068: return ($path,$multiresp);
13069: }
13070:
13071: =pod
13072:
1.464 albertel 13073: =back
1.41 ng 13074:
1.112 bowersj2 13075: =head1 CSV Upload/Handling functions
1.38 albertel 13076:
1.41 ng 13077: =over 4
13078:
1.648 raeburn 13079: =item * &upfile_store($r)
1.41 ng 13080:
13081: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13082: needs $env{'form.upfile'}
1.41 ng 13083: returns $datatoken to be put into hidden field
13084:
13085: =cut
1.31 albertel 13086:
13087: sub upfile_store {
13088: my $r=shift;
1.258 albertel 13089: $env{'form.upfile'}=~s/\r/\n/gs;
13090: $env{'form.upfile'}=~s/\f/\n/gs;
13091: $env{'form.upfile'}=~s/\n+/\n/gs;
13092: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13093:
1.258 albertel 13094: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
13095: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 13096: {
1.158 raeburn 13097: my $datafile = $r->dir_config('lonDaemons').
13098: '/tmp/'.$datatoken.'.tmp';
13099: if ( open(my $fh,">$datafile") ) {
1.258 albertel 13100: print $fh $env{'form.upfile'};
1.158 raeburn 13101: close($fh);
13102: }
1.31 albertel 13103: }
13104: return $datatoken;
13105: }
13106:
1.56 matthew 13107: =pod
13108:
1.648 raeburn 13109: =item * &load_tmp_file($r)
1.41 ng 13110:
13111: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 13112: needs $env{'form.datatoken'},
13113: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13114:
13115: =cut
1.31 albertel 13116:
13117: sub load_tmp_file {
13118: my $r=shift;
13119: my @studentdata=();
13120: {
1.158 raeburn 13121: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 13122: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 13123: if ( open(my $fh,"<$studentfile") ) {
13124: @studentdata=<$fh>;
13125: close($fh);
13126: }
1.31 albertel 13127: }
1.258 albertel 13128: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13129: }
13130:
1.56 matthew 13131: =pod
13132:
1.648 raeburn 13133: =item * &upfile_record_sep()
1.41 ng 13134:
13135: Separate uploaded file into records
13136: returns array of records,
1.258 albertel 13137: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13138:
13139: =cut
1.31 albertel 13140:
13141: sub upfile_record_sep {
1.258 albertel 13142: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13143: } else {
1.248 albertel 13144: my @records;
1.258 albertel 13145: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13146: if ($line=~/^\s*$/) { next; }
13147: push(@records,$line);
13148: }
13149: return @records;
1.31 albertel 13150: }
13151: }
13152:
1.56 matthew 13153: =pod
13154:
1.648 raeburn 13155: =item * &record_sep($record)
1.41 ng 13156:
1.258 albertel 13157: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13158:
13159: =cut
13160:
1.263 www 13161: sub takeleft {
13162: my $index=shift;
13163: return substr('0000'.$index,-4,4);
13164: }
13165:
1.31 albertel 13166: sub record_sep {
13167: my $record=shift;
13168: my %components=();
1.258 albertel 13169: if ($env{'form.upfiletype'} eq 'xml') {
13170: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13171: my $i=0;
1.356 albertel 13172: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13173: $field=~s/^(\"|\')//;
13174: $field=~s/(\"|\')$//;
1.263 www 13175: $components{&takeleft($i)}=$field;
1.31 albertel 13176: $i++;
13177: }
1.258 albertel 13178: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13179: my $i=0;
1.356 albertel 13180: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13181: $field=~s/^(\"|\')//;
13182: $field=~s/(\"|\')$//;
1.263 www 13183: $components{&takeleft($i)}=$field;
1.31 albertel 13184: $i++;
13185: }
13186: } else {
1.561 www 13187: my $separator=',';
1.480 banghart 13188: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13189: $separator=';';
1.480 banghart 13190: }
1.31 albertel 13191: my $i=0;
1.561 www 13192: # the character we are looking for to indicate the end of a quote or a record
13193: my $looking_for=$separator;
13194: # do not add the characters to the fields
13195: my $ignore=0;
13196: # we just encountered a separator (or the beginning of the record)
13197: my $just_found_separator=1;
13198: # store the field we are working on here
13199: my $field='';
13200: # work our way through all characters in record
13201: foreach my $character ($record=~/(.)/g) {
13202: if ($character eq $looking_for) {
13203: if ($character ne $separator) {
13204: # Found the end of a quote, again looking for separator
13205: $looking_for=$separator;
13206: $ignore=1;
13207: } else {
13208: # Found a separator, store away what we got
13209: $components{&takeleft($i)}=$field;
13210: $i++;
13211: $just_found_separator=1;
13212: $ignore=0;
13213: $field='';
13214: }
13215: next;
13216: }
13217: # single or double quotation marks after a separator indicate beginning of a quote
13218: # we are now looking for the end of the quote and need to ignore separators
13219: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13220: $looking_for=$character;
13221: next;
13222: }
13223: # ignore would be true after we reached the end of a quote
13224: if ($ignore) { next; }
13225: if (($just_found_separator) && ($character=~/\s/)) { next; }
13226: $field.=$character;
13227: $just_found_separator=0;
1.31 albertel 13228: }
1.561 www 13229: # catch the very last entry, since we never encountered the separator
13230: $components{&takeleft($i)}=$field;
1.31 albertel 13231: }
13232: return %components;
13233: }
13234:
1.144 matthew 13235: ######################################################
13236: ######################################################
13237:
1.56 matthew 13238: =pod
13239:
1.648 raeburn 13240: =item * &upfile_select_html()
1.41 ng 13241:
1.144 matthew 13242: Return HTML code to select a file from the users machine and specify
13243: the file type.
1.41 ng 13244:
13245: =cut
13246:
1.144 matthew 13247: ######################################################
13248: ######################################################
1.31 albertel 13249: sub upfile_select_html {
1.144 matthew 13250: my %Types = (
13251: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13252: semisv => &mt('Semicolon separated values'),
1.144 matthew 13253: space => &mt('Space separated'),
13254: tab => &mt('Tabulator separated'),
13255: # xml => &mt('HTML/XML'),
13256: );
13257: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13258: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13259: foreach my $type (sort(keys(%Types))) {
13260: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13261: }
13262: $Str .= "</select>\n";
13263: return $Str;
1.31 albertel 13264: }
13265:
1.301 albertel 13266: sub get_samples {
13267: my ($records,$toget) = @_;
13268: my @samples=({});
13269: my $got=0;
13270: foreach my $rec (@$records) {
13271: my %temp = &record_sep($rec);
13272: if (! grep(/\S/, values(%temp))) { next; }
13273: if (%temp) {
13274: $samples[$got]=\%temp;
13275: $got++;
13276: if ($got == $toget) { last; }
13277: }
13278: }
13279: return \@samples;
13280: }
13281:
1.144 matthew 13282: ######################################################
13283: ######################################################
13284:
1.56 matthew 13285: =pod
13286:
1.648 raeburn 13287: =item * &csv_print_samples($r,$records)
1.41 ng 13288:
13289: Prints a table of sample values from each column uploaded $r is an
13290: Apache Request ref, $records is an arrayref from
13291: &Apache::loncommon::upfile_record_sep
13292:
13293: =cut
13294:
1.144 matthew 13295: ######################################################
13296: ######################################################
1.31 albertel 13297: sub csv_print_samples {
13298: my ($r,$records) = @_;
1.662 bisitz 13299: my $samples = &get_samples($records,5);
1.301 albertel 13300:
1.594 raeburn 13301: $r->print(&mt('Samples').'<br />'.&start_data_table().
13302: &start_data_table_header_row());
1.356 albertel 13303: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13304: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13305: $r->print(&end_data_table_header_row());
1.301 albertel 13306: foreach my $hash (@$samples) {
1.594 raeburn 13307: $r->print(&start_data_table_row());
1.356 albertel 13308: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13309: $r->print('<td>');
1.356 albertel 13310: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13311: $r->print('</td>');
13312: }
1.594 raeburn 13313: $r->print(&end_data_table_row());
1.31 albertel 13314: }
1.594 raeburn 13315: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13316: }
13317:
1.144 matthew 13318: ######################################################
13319: ######################################################
13320:
1.56 matthew 13321: =pod
13322:
1.648 raeburn 13323: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13324:
13325: Prints a table to create associations between values and table columns.
1.144 matthew 13326:
1.41 ng 13327: $r is an Apache Request ref,
13328: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13329: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13330:
13331: =cut
13332:
1.144 matthew 13333: ######################################################
13334: ######################################################
1.31 albertel 13335: sub csv_print_select_table {
13336: my ($r,$records,$d) = @_;
1.301 albertel 13337: my $i=0;
13338: my $samples = &get_samples($records,1);
1.144 matthew 13339: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13340: &start_data_table().&start_data_table_header_row().
1.144 matthew 13341: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13342: '<th>'.&mt('Column').'</th>'.
13343: &end_data_table_header_row()."\n");
1.356 albertel 13344: foreach my $array_ref (@$d) {
13345: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13346: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13347:
1.875 bisitz 13348: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13349: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13350: $r->print('<option value="none"></option>');
1.356 albertel 13351: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13352: $r->print('<option value="'.$sample.'"'.
13353: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13354: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13355: }
1.594 raeburn 13356: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13357: $i++;
13358: }
1.594 raeburn 13359: $r->print(&end_data_table());
1.31 albertel 13360: $i--;
13361: return $i;
13362: }
1.56 matthew 13363:
1.144 matthew 13364: ######################################################
13365: ######################################################
13366:
1.56 matthew 13367: =pod
1.31 albertel 13368:
1.648 raeburn 13369: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13370:
13371: Prints a table of sample values from the upload and can make associate samples to internal names.
13372:
13373: $r is an Apache Request ref,
13374: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13375: $d is an array of 2 element arrays (internal name, displayed name)
13376:
13377: =cut
13378:
1.144 matthew 13379: ######################################################
13380: ######################################################
1.31 albertel 13381: sub csv_samples_select_table {
13382: my ($r,$records,$d) = @_;
13383: my $i=0;
1.144 matthew 13384: #
1.662 bisitz 13385: my $max_samples = 5;
13386: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13387: $r->print(&start_data_table().
13388: &start_data_table_header_row().'<th>'.
13389: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13390: &end_data_table_header_row());
1.301 albertel 13391:
13392: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13393: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13394: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13395: foreach my $option (@$d) {
13396: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13397: $r->print('<option value="'.$value.'"'.
1.253 albertel 13398: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13399: $display.'</option>');
1.31 albertel 13400: }
13401: $r->print('</select></td><td>');
1.662 bisitz 13402: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13403: if (defined($samples->[$line]{$key})) {
13404: $r->print($samples->[$line]{$key}."<br />\n");
13405: }
13406: }
1.594 raeburn 13407: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13408: $i++;
13409: }
1.594 raeburn 13410: $r->print(&end_data_table());
1.31 albertel 13411: $i--;
13412: return($i);
1.115 matthew 13413: }
13414:
1.144 matthew 13415: ######################################################
13416: ######################################################
13417:
1.115 matthew 13418: =pod
13419:
1.648 raeburn 13420: =item * &clean_excel_name($name)
1.115 matthew 13421:
13422: Returns a replacement for $name which does not contain any illegal characters.
13423:
13424: =cut
13425:
1.144 matthew 13426: ######################################################
13427: ######################################################
1.115 matthew 13428: sub clean_excel_name {
13429: my ($name) = @_;
13430: $name =~ s/[:\*\?\/\\]//g;
13431: if (length($name) > 31) {
13432: $name = substr($name,0,31);
13433: }
13434: return $name;
1.25 albertel 13435: }
1.84 albertel 13436:
1.85 albertel 13437: =pod
13438:
1.648 raeburn 13439: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13440:
13441: Returns either 1 or undef
13442:
13443: 1 if the part is to be hidden, undef if it is to be shown
13444:
13445: Arguments are:
13446:
13447: $id the id of the part to be checked
13448: $symb, optional the symb of the resource to check
13449: $udom, optional the domain of the user to check for
13450: $uname, optional the username of the user to check for
13451:
13452: =cut
1.84 albertel 13453:
13454: sub check_if_partid_hidden {
13455: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13456: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13457: $symb,$udom,$uname);
1.141 albertel 13458: my $truth=1;
13459: #if the string starts with !, then the list is the list to show not hide
13460: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13461: my @hiddenlist=split(/,/,$hiddenparts);
13462: foreach my $checkid (@hiddenlist) {
1.141 albertel 13463: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13464: }
1.141 albertel 13465: return !$truth;
1.84 albertel 13466: }
1.127 matthew 13467:
1.138 matthew 13468:
13469: ############################################################
13470: ############################################################
13471:
13472: =pod
13473:
1.157 matthew 13474: =back
13475:
1.138 matthew 13476: =head1 cgi-bin script and graphing routines
13477:
1.157 matthew 13478: =over 4
13479:
1.648 raeburn 13480: =item * &get_cgi_id()
1.138 matthew 13481:
13482: Inputs: none
13483:
13484: Returns an id which can be used to pass environment variables
13485: to various cgi-bin scripts. These environment variables will
13486: be removed from the users environment after a given time by
13487: the routine &Apache::lonnet::transfer_profile_to_env.
13488:
13489: =cut
13490:
13491: ############################################################
13492: ############################################################
1.152 albertel 13493: my $uniq=0;
1.136 matthew 13494: sub get_cgi_id {
1.154 albertel 13495: $uniq=($uniq+1)%100000;
1.280 albertel 13496: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13497: }
13498:
1.127 matthew 13499: ############################################################
13500: ############################################################
13501:
13502: =pod
13503:
1.648 raeburn 13504: =item * &DrawBarGraph()
1.127 matthew 13505:
1.138 matthew 13506: Facilitates the plotting of data in a (stacked) bar graph.
13507: Puts plot definition data into the users environment in order for
13508: graph.png to plot it. Returns an <img> tag for the plot.
13509: The bars on the plot are labeled '1','2',...,'n'.
13510:
13511: Inputs:
13512:
13513: =over 4
13514:
13515: =item $Title: string, the title of the plot
13516:
13517: =item $xlabel: string, text describing the X-axis of the plot
13518:
13519: =item $ylabel: string, text describing the Y-axis of the plot
13520:
13521: =item $Max: scalar, the maximum Y value to use in the plot
13522: If $Max is < any data point, the graph will not be rendered.
13523:
1.140 matthew 13524: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13525: they are plotted. If undefined, default values will be used.
13526:
1.178 matthew 13527: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13528:
1.138 matthew 13529: =item @Values: An array of array references. Each array reference holds data
13530: to be plotted in a stacked bar chart.
13531:
1.239 matthew 13532: =item If the final element of @Values is a hash reference the key/value
13533: pairs will be added to the graph definition.
13534:
1.138 matthew 13535: =back
13536:
13537: Returns:
13538:
13539: An <img> tag which references graph.png and the appropriate identifying
13540: information for the plot.
13541:
1.127 matthew 13542: =cut
13543:
13544: ############################################################
13545: ############################################################
1.134 matthew 13546: sub DrawBarGraph {
1.178 matthew 13547: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13548: #
13549: if (! defined($colors)) {
13550: $colors = ['#33ff00',
13551: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13552: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13553: ];
13554: }
1.228 matthew 13555: my $extra_settings = {};
13556: if (ref($Values[-1]) eq 'HASH') {
13557: $extra_settings = pop(@Values);
13558: }
1.127 matthew 13559: #
1.136 matthew 13560: my $identifier = &get_cgi_id();
13561: my $id = 'cgi.'.$identifier;
1.129 matthew 13562: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13563: return '';
13564: }
1.225 matthew 13565: #
13566: my @Labels;
13567: if (defined($labels)) {
13568: @Labels = @$labels;
13569: } else {
13570: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1075.2.119 raeburn 13571: push(@Labels,$i+1);
1.225 matthew 13572: }
13573: }
13574: #
1.129 matthew 13575: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13576: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13577: my %ValuesHash;
13578: my $NumSets=1;
13579: foreach my $array (@Values) {
13580: next if (! ref($array));
1.136 matthew 13581: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13582: join(',',@$array);
1.129 matthew 13583: }
1.127 matthew 13584: #
1.136 matthew 13585: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13586: if ($NumBars < 3) {
13587: $width = 120+$NumBars*32;
1.220 matthew 13588: $xskip = 1;
1.225 matthew 13589: $bar_width = 30;
13590: } elsif ($NumBars < 5) {
13591: $width = 120+$NumBars*20;
13592: $xskip = 1;
13593: $bar_width = 20;
1.220 matthew 13594: } elsif ($NumBars < 10) {
1.136 matthew 13595: $width = 120+$NumBars*15;
13596: $xskip = 1;
13597: $bar_width = 15;
13598: } elsif ($NumBars <= 25) {
13599: $width = 120+$NumBars*11;
13600: $xskip = 5;
13601: $bar_width = 8;
13602: } elsif ($NumBars <= 50) {
13603: $width = 120+$NumBars*8;
13604: $xskip = 5;
13605: $bar_width = 4;
13606: } else {
13607: $width = 120+$NumBars*8;
13608: $xskip = 5;
13609: $bar_width = 4;
13610: }
13611: #
1.137 matthew 13612: $Max = 1 if ($Max < 1);
13613: if ( int($Max) < $Max ) {
13614: $Max++;
13615: $Max = int($Max);
13616: }
1.127 matthew 13617: $Title = '' if (! defined($Title));
13618: $xlabel = '' if (! defined($xlabel));
13619: $ylabel = '' if (! defined($ylabel));
1.369 www 13620: $ValuesHash{$id.'.title'} = &escape($Title);
13621: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13622: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13623: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13624: $ValuesHash{$id.'.NumBars'} = $NumBars;
13625: $ValuesHash{$id.'.NumSets'} = $NumSets;
13626: $ValuesHash{$id.'.PlotType'} = 'bar';
13627: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13628: $ValuesHash{$id.'.height'} = $height;
13629: $ValuesHash{$id.'.width'} = $width;
13630: $ValuesHash{$id.'.xskip'} = $xskip;
13631: $ValuesHash{$id.'.bar_width'} = $bar_width;
13632: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13633: #
1.228 matthew 13634: # Deal with other parameters
13635: while (my ($key,$value) = each(%$extra_settings)) {
13636: $ValuesHash{$id.'.'.$key} = $value;
13637: }
13638: #
1.646 raeburn 13639: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13640: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13641: }
13642:
13643: ############################################################
13644: ############################################################
13645:
13646: =pod
13647:
1.648 raeburn 13648: =item * &DrawXYGraph()
1.137 matthew 13649:
1.138 matthew 13650: Facilitates the plotting of data in an XY graph.
13651: Puts plot definition data into the users environment in order for
13652: graph.png to plot it. Returns an <img> tag for the plot.
13653:
13654: Inputs:
13655:
13656: =over 4
13657:
13658: =item $Title: string, the title of the plot
13659:
13660: =item $xlabel: string, text describing the X-axis of the plot
13661:
13662: =item $ylabel: string, text describing the Y-axis of the plot
13663:
13664: =item $Max: scalar, the maximum Y value to use in the plot
13665: If $Max is < any data point, the graph will not be rendered.
13666:
13667: =item $colors: Array ref containing the hex color codes for the data to be
13668: plotted in. If undefined, default values will be used.
13669:
13670: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13671:
13672: =item $Ydata: Array ref containing Array refs.
1.185 www 13673: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13674:
13675: =item %Values: hash indicating or overriding any default values which are
13676: passed to graph.png.
13677: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13678:
13679: =back
13680:
13681: Returns:
13682:
13683: An <img> tag which references graph.png and the appropriate identifying
13684: information for the plot.
13685:
1.137 matthew 13686: =cut
13687:
13688: ############################################################
13689: ############################################################
13690: sub DrawXYGraph {
13691: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13692: #
13693: # Create the identifier for the graph
13694: my $identifier = &get_cgi_id();
13695: my $id = 'cgi.'.$identifier;
13696: #
13697: $Title = '' if (! defined($Title));
13698: $xlabel = '' if (! defined($xlabel));
13699: $ylabel = '' if (! defined($ylabel));
13700: my %ValuesHash =
13701: (
1.369 www 13702: $id.'.title' => &escape($Title),
13703: $id.'.xlabel' => &escape($xlabel),
13704: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13705: $id.'.y_max_value'=> $Max,
13706: $id.'.labels' => join(',',@$Xlabels),
13707: $id.'.PlotType' => 'XY',
13708: );
13709: #
13710: if (defined($colors) && ref($colors) eq 'ARRAY') {
13711: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13712: }
13713: #
13714: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13715: return '';
13716: }
13717: my $NumSets=1;
1.138 matthew 13718: foreach my $array (@{$Ydata}){
1.137 matthew 13719: next if (! ref($array));
13720: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13721: }
1.138 matthew 13722: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13723: #
13724: # Deal with other parameters
13725: while (my ($key,$value) = each(%Values)) {
13726: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13727: }
13728: #
1.646 raeburn 13729: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13730: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13731: }
13732:
13733: ############################################################
13734: ############################################################
13735:
13736: =pod
13737:
1.648 raeburn 13738: =item * &DrawXYYGraph()
1.138 matthew 13739:
13740: Facilitates the plotting of data in an XY graph with two Y axes.
13741: Puts plot definition data into the users environment in order for
13742: graph.png to plot it. Returns an <img> tag for the plot.
13743:
13744: Inputs:
13745:
13746: =over 4
13747:
13748: =item $Title: string, the title of the plot
13749:
13750: =item $xlabel: string, text describing the X-axis of the plot
13751:
13752: =item $ylabel: string, text describing the Y-axis of the plot
13753:
13754: =item $colors: Array ref containing the hex color codes for the data to be
13755: plotted in. If undefined, default values will be used.
13756:
13757: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13758:
13759: =item $Ydata1: The first data set
13760:
13761: =item $Min1: The minimum value of the left Y-axis
13762:
13763: =item $Max1: The maximum value of the left Y-axis
13764:
13765: =item $Ydata2: The second data set
13766:
13767: =item $Min2: The minimum value of the right Y-axis
13768:
13769: =item $Max2: The maximum value of the left Y-axis
13770:
13771: =item %Values: hash indicating or overriding any default values which are
13772: passed to graph.png.
13773: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13774:
13775: =back
13776:
13777: Returns:
13778:
13779: An <img> tag which references graph.png and the appropriate identifying
13780: information for the plot.
1.136 matthew 13781:
13782: =cut
13783:
13784: ############################################################
13785: ############################################################
1.137 matthew 13786: sub DrawXYYGraph {
13787: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13788: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13789: #
13790: # Create the identifier for the graph
13791: my $identifier = &get_cgi_id();
13792: my $id = 'cgi.'.$identifier;
13793: #
13794: $Title = '' if (! defined($Title));
13795: $xlabel = '' if (! defined($xlabel));
13796: $ylabel = '' if (! defined($ylabel));
13797: my %ValuesHash =
13798: (
1.369 www 13799: $id.'.title' => &escape($Title),
13800: $id.'.xlabel' => &escape($xlabel),
13801: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13802: $id.'.labels' => join(',',@$Xlabels),
13803: $id.'.PlotType' => 'XY',
13804: $id.'.NumSets' => 2,
1.137 matthew 13805: $id.'.two_axes' => 1,
13806: $id.'.y1_max_value' => $Max1,
13807: $id.'.y1_min_value' => $Min1,
13808: $id.'.y2_max_value' => $Max2,
13809: $id.'.y2_min_value' => $Min2,
1.136 matthew 13810: );
13811: #
1.137 matthew 13812: if (defined($colors) && ref($colors) eq 'ARRAY') {
13813: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13814: }
13815: #
13816: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13817: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13818: return '';
13819: }
13820: my $NumSets=1;
1.137 matthew 13821: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13822: next if (! ref($array));
13823: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13824: }
13825: #
13826: # Deal with other parameters
13827: while (my ($key,$value) = each(%Values)) {
13828: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13829: }
13830: #
1.646 raeburn 13831: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13832: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13833: }
13834:
13835: ############################################################
13836: ############################################################
13837:
13838: =pod
13839:
1.157 matthew 13840: =back
13841:
1.139 matthew 13842: =head1 Statistics helper routines?
13843:
13844: Bad place for them but what the hell.
13845:
1.157 matthew 13846: =over 4
13847:
1.648 raeburn 13848: =item * &chartlink()
1.139 matthew 13849:
13850: Returns a link to the chart for a specific student.
13851:
13852: Inputs:
13853:
13854: =over 4
13855:
13856: =item $linktext: The text of the link
13857:
13858: =item $sname: The students username
13859:
13860: =item $sdomain: The students domain
13861:
13862: =back
13863:
1.157 matthew 13864: =back
13865:
1.139 matthew 13866: =cut
13867:
13868: ############################################################
13869: ############################################################
13870: sub chartlink {
13871: my ($linktext, $sname, $sdomain) = @_;
13872: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13873: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13874: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13875: '">'.$linktext.'</a>';
1.153 matthew 13876: }
13877:
13878: #######################################################
13879: #######################################################
13880:
13881: =pod
13882:
13883: =head1 Course Environment Routines
1.157 matthew 13884:
13885: =over 4
1.153 matthew 13886:
1.648 raeburn 13887: =item * &restore_course_settings()
1.153 matthew 13888:
1.648 raeburn 13889: =item * &store_course_settings()
1.153 matthew 13890:
13891: Restores/Store indicated form parameters from the course environment.
13892: Will not overwrite existing values of the form parameters.
13893:
13894: Inputs:
13895: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13896:
13897: a hash ref describing the data to be stored. For example:
13898:
13899: %Save_Parameters = ('Status' => 'scalar',
13900: 'chartoutputmode' => 'scalar',
13901: 'chartoutputdata' => 'scalar',
13902: 'Section' => 'array',
1.373 raeburn 13903: 'Group' => 'array',
1.153 matthew 13904: 'StudentData' => 'array',
13905: 'Maps' => 'array');
13906:
13907: Returns: both routines return nothing
13908:
1.631 raeburn 13909: =back
13910:
1.153 matthew 13911: =cut
13912:
13913: #######################################################
13914: #######################################################
13915: sub store_course_settings {
1.496 albertel 13916: return &store_settings($env{'request.course.id'},@_);
13917: }
13918:
13919: sub store_settings {
1.153 matthew 13920: # save to the environment
13921: # appenv the same items, just to be safe
1.300 albertel 13922: my $udom = $env{'user.domain'};
13923: my $uname = $env{'user.name'};
1.496 albertel 13924: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13925: my %SaveHash;
13926: my %AppHash;
13927: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13928: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13929: my $envname = 'environment.'.$basename;
1.258 albertel 13930: if (exists($env{'form.'.$setting})) {
1.153 matthew 13931: # Save this value away
13932: if ($type eq 'scalar' &&
1.258 albertel 13933: (! exists($env{$envname}) ||
13934: $env{$envname} ne $env{'form.'.$setting})) {
13935: $SaveHash{$basename} = $env{'form.'.$setting};
13936: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13937: } elsif ($type eq 'array') {
13938: my $stored_form;
1.258 albertel 13939: if (ref($env{'form.'.$setting})) {
1.153 matthew 13940: $stored_form = join(',',
13941: map {
1.369 www 13942: &escape($_);
1.258 albertel 13943: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13944: } else {
13945: $stored_form =
1.369 www 13946: &escape($env{'form.'.$setting});
1.153 matthew 13947: }
13948: # Determine if the array contents are the same.
1.258 albertel 13949: if ($stored_form ne $env{$envname}) {
1.153 matthew 13950: $SaveHash{$basename} = $stored_form;
13951: $AppHash{$envname} = $stored_form;
13952: }
13953: }
13954: }
13955: }
13956: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13957: $udom,$uname);
1.153 matthew 13958: if ($put_result !~ /^(ok|delayed)/) {
13959: &Apache::lonnet::logthis('unable to save form parameters, '.
13960: 'got error:'.$put_result);
13961: }
13962: # Make sure these settings stick around in this session, too
1.646 raeburn 13963: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13964: return;
13965: }
13966:
13967: sub restore_course_settings {
1.499 albertel 13968: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13969: }
13970:
13971: sub restore_settings {
13972: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13973: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13974: next if (exists($env{'form.'.$setting}));
1.496 albertel 13975: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13976: '.'.$setting;
1.258 albertel 13977: if (exists($env{$envname})) {
1.153 matthew 13978: if ($type eq 'scalar') {
1.258 albertel 13979: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13980: } elsif ($type eq 'array') {
1.258 albertel 13981: $env{'form.'.$setting} = [
1.153 matthew 13982: map {
1.369 www 13983: &unescape($_);
1.258 albertel 13984: } split(',',$env{$envname})
1.153 matthew 13985: ];
13986: }
13987: }
13988: }
1.127 matthew 13989: }
13990:
1.618 raeburn 13991: #######################################################
13992: #######################################################
13993:
13994: =pod
13995:
13996: =head1 Domain E-mail Routines
13997:
13998: =over 4
13999:
1.648 raeburn 14000: =item * &build_recipient_list()
1.618 raeburn 14001:
1.1075.2.44 raeburn 14002: Build recipient lists for following types of e-mail:
1.766 raeburn 14003: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1075.2.44 raeburn 14004: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14005: module change checking, student/employee ID conflict checks, as
14006: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14007: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14008:
14009: Inputs:
1.1075.2.44 raeburn 14010: defmail (scalar - email address of default recipient),
14011: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14012: requestsmail, updatesmail, or idconflictsmail).
14013:
1.619 raeburn 14014: defdom (domain for which to retrieve configuration settings),
1.1075.2.44 raeburn 14015:
14016: origmail (scalar - email address of recipient from loncapa.conf,
14017: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14018:
1.655 raeburn 14019: Returns: comma separated list of addresses to which to send e-mail.
14020:
14021: =back
1.618 raeburn 14022:
14023: =cut
14024:
14025: ############################################################
14026: ############################################################
14027: sub build_recipient_list {
1.619 raeburn 14028: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 14029: my @recipients;
1.1075.2.122 raeburn 14030: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14031: my %domconfig =
1.1075.2.122 raeburn 14032: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14033: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14034: if (exists($domconfig{'contacts'}{$mailing})) {
14035: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14036: my @contacts = ('adminemail','supportemail');
14037: foreach my $item (@contacts) {
14038: if ($domconfig{'contacts'}{$mailing}{$item}) {
14039: my $addr = $domconfig{'contacts'}{$item};
14040: if (!grep(/^\Q$addr\E$/,@recipients)) {
14041: push(@recipients,$addr);
14042: }
1.619 raeburn 14043: }
1.1075.2.122 raeburn 14044: }
14045: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14046: if ($mailing eq 'helpdeskmail') {
14047: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14048: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14049: my @ok_bccs;
14050: foreach my $bcc (@bccs) {
14051: $bcc =~ s/^\s+//g;
14052: $bcc =~ s/\s+$//g;
14053: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14054: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14055: push(@ok_bccs,$bcc);
14056: }
14057: }
14058: }
14059: if (@ok_bccs > 0) {
14060: $allbcc = join(', ',@ok_bccs);
14061: }
14062: }
14063: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14064: }
14065: }
1.766 raeburn 14066: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14067: $lastresort = $origmail;
1.618 raeburn 14068: }
1.619 raeburn 14069: } elsif ($origmail ne '') {
1.1075.2.122 raeburn 14070: $lastresort = $origmail;
14071: }
14072:
14073: if (($mailing eq 'helpdesk') && ($lastresort ne '')) {
14074: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14075: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14076: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14077: my %what = (
14078: perlvar => 1,
14079: );
14080: my $primary = &Apache::lonnet::domain($defdom,'primary');
14081: if ($primary) {
14082: my $gotaddr;
14083: my ($result,$returnhash) =
14084: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14085: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14086: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14087: $lastresort = $returnhash->{'lonSupportEMail'};
14088: $gotaddr = 1;
14089: }
14090: }
14091: unless ($gotaddr) {
14092: my $uintdom = &Apache::lonnet::internet_dom($primary);
14093: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14094: unless ($uintdom eq $intdom) {
14095: my %domconfig =
14096: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14097: if (ref($domconfig{'contacts'}) eq 'HASH') {
14098: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14099: my @contacts = ('adminemail','supportemail');
14100: foreach my $item (@contacts) {
14101: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14102: my $addr = $domconfig{'contacts'}{$item};
14103: if (!grep(/^\Q$addr\E$/,@recipients)) {
14104: push(@recipients,$addr);
14105: }
14106: }
14107: }
14108: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14109: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14110: }
14111: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14112: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14113: my @ok_bccs;
14114: foreach my $bcc (@bccs) {
14115: $bcc =~ s/^\s+//g;
14116: $bcc =~ s/\s+$//g;
14117: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14118: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14119: push(@ok_bccs,$bcc);
14120: }
14121: }
14122: }
14123: if (@ok_bccs > 0) {
14124: $allbcc = join(', ',@ok_bccs);
14125: }
14126: }
14127: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14128: }
14129: }
14130: }
14131: }
14132: }
14133: }
1.618 raeburn 14134: }
1.688 raeburn 14135: if (defined($defmail)) {
14136: if ($defmail ne '') {
14137: push(@recipients,$defmail);
14138: }
1.618 raeburn 14139: }
14140: if ($otheremails) {
1.619 raeburn 14141: my @others;
14142: if ($otheremails =~ /,/) {
14143: @others = split(/,/,$otheremails);
1.618 raeburn 14144: } else {
1.619 raeburn 14145: push(@others,$otheremails);
14146: }
14147: foreach my $addr (@others) {
14148: if (!grep(/^\Q$addr\E$/,@recipients)) {
14149: push(@recipients,$addr);
14150: }
1.618 raeburn 14151: }
14152: }
1.1075.2.122 raeburn 14153: if ($mailing eq 'helpdesk') {
14154: if ((!@recipients) && ($lastresort ne '')) {
14155: push(@recipients,$lastresort);
14156: }
14157: } elsif ($lastresort ne '') {
14158: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14159: push(@recipients,$lastresort);
14160: }
14161: }
14162: my $recipientlist = join(',',@recipients);
14163: if (wantarray) {
14164: return ($recipientlist,$allbcc,$addtext);
14165: } else {
14166: return $recipientlist;
14167: }
1.618 raeburn 14168: }
14169:
1.127 matthew 14170: ############################################################
14171: ############################################################
1.154 albertel 14172:
1.655 raeburn 14173: =pod
14174:
14175: =head1 Course Catalog Routines
14176:
14177: =over 4
14178:
14179: =item * &gather_categories()
14180:
14181: Converts category definitions - keys of categories hash stored in
14182: coursecategories in configuration.db on the primary library server in a
14183: domain - to an array. Also generates javascript and idx hash used to
14184: generate Domain Coordinator interface for editing Course Categories.
14185:
14186: Inputs:
1.663 raeburn 14187:
1.655 raeburn 14188: categories (reference to hash of category definitions).
1.663 raeburn 14189:
1.655 raeburn 14190: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14191: categories and subcategories).
1.663 raeburn 14192:
1.655 raeburn 14193: idx (reference to hash of counters used in Domain Coordinator interface for
14194: editing Course Categories).
1.663 raeburn 14195:
1.655 raeburn 14196: jsarray (reference to array of categories used to create Javascript arrays for
14197: Domain Coordinator interface for editing Course Categories).
14198:
14199: Returns: nothing
14200:
14201: Side effects: populates cats, idx and jsarray.
14202:
14203: =cut
14204:
14205: sub gather_categories {
14206: my ($categories,$cats,$idx,$jsarray) = @_;
14207: my %counters;
14208: my $num = 0;
14209: foreach my $item (keys(%{$categories})) {
14210: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14211: if ($container eq '' && $depth == 0) {
14212: $cats->[$depth][$categories->{$item}] = $cat;
14213: } else {
14214: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14215: }
14216: my ($escitem,$tail) = split(/:/,$item,2);
14217: if ($counters{$tail} eq '') {
14218: $counters{$tail} = $num;
14219: $num ++;
14220: }
14221: if (ref($idx) eq 'HASH') {
14222: $idx->{$item} = $counters{$tail};
14223: }
14224: if (ref($jsarray) eq 'ARRAY') {
14225: push(@{$jsarray->[$counters{$tail}]},$item);
14226: }
14227: }
14228: return;
14229: }
14230:
14231: =pod
14232:
14233: =item * &extract_categories()
14234:
14235: Used to generate breadcrumb trails for course categories.
14236:
14237: Inputs:
1.663 raeburn 14238:
1.655 raeburn 14239: categories (reference to hash of category definitions).
1.663 raeburn 14240:
1.655 raeburn 14241: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14242: categories and subcategories).
1.663 raeburn 14243:
1.655 raeburn 14244: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14245:
1.655 raeburn 14246: allitems (reference to hash - key is category key
14247: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14248:
1.655 raeburn 14249: idx (reference to hash of counters used in Domain Coordinator interface for
14250: editing Course Categories).
1.663 raeburn 14251:
1.655 raeburn 14252: jsarray (reference to array of categories used to create Javascript arrays for
14253: Domain Coordinator interface for editing Course Categories).
14254:
1.665 raeburn 14255: subcats (reference to hash of arrays containing all subcategories within each
14256: category, -recursive)
14257:
1.655 raeburn 14258: Returns: nothing
14259:
14260: Side effects: populates trails and allitems hash references.
14261:
14262: =cut
14263:
14264: sub extract_categories {
1.665 raeburn 14265: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 14266: if (ref($categories) eq 'HASH') {
14267: &gather_categories($categories,$cats,$idx,$jsarray);
14268: if (ref($cats->[0]) eq 'ARRAY') {
14269: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14270: my $name = $cats->[0][$i];
14271: my $item = &escape($name).'::0';
14272: my $trailstr;
14273: if ($name eq 'instcode') {
14274: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14275: } elsif ($name eq 'communities') {
14276: $trailstr = &mt('Communities');
1.655 raeburn 14277: } else {
14278: $trailstr = $name;
14279: }
14280: if ($allitems->{$item} eq '') {
14281: push(@{$trails},$trailstr);
14282: $allitems->{$item} = scalar(@{$trails})-1;
14283: }
14284: my @parents = ($name);
14285: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14286: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14287: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14288: if (ref($subcats) eq 'HASH') {
14289: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14290: }
14291: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
14292: }
14293: } else {
14294: if (ref($subcats) eq 'HASH') {
14295: $subcats->{$item} = [];
1.655 raeburn 14296: }
14297: }
14298: }
14299: }
14300: }
14301: return;
14302: }
14303:
14304: =pod
14305:
1.1075.2.56 raeburn 14306: =item * &recurse_categories()
1.655 raeburn 14307:
14308: Recursively used to generate breadcrumb trails for course categories.
14309:
14310: Inputs:
1.663 raeburn 14311:
1.655 raeburn 14312: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14313: categories and subcategories).
1.663 raeburn 14314:
1.655 raeburn 14315: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14316:
14317: category (current course category, for which breadcrumb trail is being generated).
14318:
14319: trails (reference to array of breadcrumb trails for each category).
14320:
1.655 raeburn 14321: allitems (reference to hash - key is category key
14322: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14323:
1.655 raeburn 14324: parents (array containing containers directories for current category,
14325: back to top level).
14326:
14327: Returns: nothing
14328:
14329: Side effects: populates trails and allitems hash references
14330:
14331: =cut
14332:
14333: sub recurse_categories {
1.665 raeburn 14334: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 14335: my $shallower = $depth - 1;
14336: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14337: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14338: my $name = $cats->[$depth]{$category}[$k];
14339: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14340: my $trailstr = join(' -> ',(@{$parents},$category));
14341: if ($allitems->{$item} eq '') {
14342: push(@{$trails},$trailstr);
14343: $allitems->{$item} = scalar(@{$trails})-1;
14344: }
14345: my $deeper = $depth+1;
14346: push(@{$parents},$category);
1.665 raeburn 14347: if (ref($subcats) eq 'HASH') {
14348: my $subcat = &escape($name).':'.$category.':'.$depth;
14349: for (my $j=@{$parents}; $j>=0; $j--) {
14350: my $higher;
14351: if ($j > 0) {
14352: $higher = &escape($parents->[$j]).':'.
14353: &escape($parents->[$j-1]).':'.$j;
14354: } else {
14355: $higher = &escape($parents->[$j]).'::'.$j;
14356: }
14357: push(@{$subcats->{$higher}},$subcat);
14358: }
14359: }
14360: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
14361: $subcats);
1.655 raeburn 14362: pop(@{$parents});
14363: }
14364: } else {
14365: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14366: my $trailstr = join(' -> ',(@{$parents},$category));
14367: if ($allitems->{$item} eq '') {
14368: push(@{$trails},$trailstr);
14369: $allitems->{$item} = scalar(@{$trails})-1;
14370: }
14371: }
14372: return;
14373: }
14374:
1.663 raeburn 14375: =pod
14376:
1.1075.2.56 raeburn 14377: =item * &assign_categories_table()
1.663 raeburn 14378:
14379: Create a datatable for display of hierarchical categories in a domain,
14380: with checkboxes to allow a course to be categorized.
14381:
14382: Inputs:
14383:
14384: cathash - reference to hash of categories defined for the domain (from
14385: configuration.db)
14386:
14387: currcat - scalar with an & separated list of categories assigned to a course.
14388:
1.919 raeburn 14389: type - scalar contains course type (Course or Community).
14390:
1.1075.2.117 raeburn 14391: disabled - scalar (optional) contains disabled="disabled" if input elements are
14392: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14393:
1.663 raeburn 14394: Returns: $output (markup to be displayed)
14395:
14396: =cut
14397:
14398: sub assign_categories_table {
1.1075.2.117 raeburn 14399: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 14400: my $output;
14401: if (ref($cathash) eq 'HASH') {
14402: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
14403: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
14404: $maxdepth = scalar(@cats);
14405: if (@cats > 0) {
14406: my $itemcount = 0;
14407: if (ref($cats[0]) eq 'ARRAY') {
14408: my @currcategories;
14409: if ($currcat ne '') {
14410: @currcategories = split('&',$currcat);
14411: }
1.919 raeburn 14412: my $table;
1.663 raeburn 14413: for (my $i=0; $i<@{$cats[0]}; $i++) {
14414: my $parent = $cats[0][$i];
1.919 raeburn 14415: next if ($parent eq 'instcode');
14416: if ($type eq 'Community') {
14417: next unless ($parent eq 'communities');
14418: } else {
14419: next if ($parent eq 'communities');
14420: }
1.663 raeburn 14421: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14422: my $item = &escape($parent).'::0';
14423: my $checked = '';
14424: if (@currcategories > 0) {
14425: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14426: $checked = ' checked="checked"';
1.663 raeburn 14427: }
14428: }
1.919 raeburn 14429: my $parent_title = $parent;
14430: if ($parent eq 'communities') {
14431: $parent_title = &mt('Communities');
14432: }
14433: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14434: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14435: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 14436: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14437: my $depth = 1;
14438: push(@path,$parent);
1.1075.2.117 raeburn 14439: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 14440: pop(@path);
1.919 raeburn 14441: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14442: $itemcount ++;
14443: }
1.919 raeburn 14444: if ($itemcount) {
14445: $output = &Apache::loncommon::start_data_table().
14446: $table.
14447: &Apache::loncommon::end_data_table();
14448: }
1.663 raeburn 14449: }
14450: }
14451: }
14452: return $output;
14453: }
14454:
14455: =pod
14456:
1.1075.2.56 raeburn 14457: =item * &assign_category_rows()
1.663 raeburn 14458:
14459: Create a datatable row for display of nested categories in a domain,
14460: with checkboxes to allow a course to be categorized,called recursively.
14461:
14462: Inputs:
14463:
14464: itemcount - track row number for alternating colors
14465:
14466: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14467: categories and subcategories.
14468:
14469: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14470:
14471: parent - parent of current category item
14472:
14473: path - Array containing all categories back up through the hierarchy from the
14474: current category to the top level.
14475:
14476: currcategories - reference to array of current categories assigned to the course
14477:
1.1075.2.117 raeburn 14478: disabled - scalar (optional) contains disabled="disabled" if input elements are
14479: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14480:
1.663 raeburn 14481: Returns: $output (markup to be displayed).
14482:
14483: =cut
14484:
14485: sub assign_category_rows {
1.1075.2.117 raeburn 14486: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 14487: my ($text,$name,$item,$chgstr);
14488: if (ref($cats) eq 'ARRAY') {
14489: my $maxdepth = scalar(@{$cats});
14490: if (ref($cats->[$depth]) eq 'HASH') {
14491: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14492: my $numchildren = @{$cats->[$depth]{$parent}};
14493: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1075.2.45 raeburn 14494: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14495: for (my $j=0; $j<$numchildren; $j++) {
14496: $name = $cats->[$depth]{$parent}[$j];
14497: $item = &escape($name).':'.&escape($parent).':'.$depth;
14498: my $deeper = $depth+1;
14499: my $checked = '';
14500: if (ref($currcategories) eq 'ARRAY') {
14501: if (@{$currcategories} > 0) {
14502: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14503: $checked = ' checked="checked"';
1.663 raeburn 14504: }
14505: }
14506: }
1.664 raeburn 14507: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14508: '<input type="checkbox" name="usecategory" value="'.
1.1075.2.117 raeburn 14509: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 14510: '<input type="hidden" name="catname" value="'.$name.'" />'.
14511: '</td><td>';
1.663 raeburn 14512: if (ref($path) eq 'ARRAY') {
14513: push(@{$path},$name);
1.1075.2.117 raeburn 14514: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 14515: pop(@{$path});
14516: }
14517: $text .= '</td></tr>';
14518: }
14519: $text .= '</table></td>';
14520: }
14521: }
14522: }
14523: return $text;
14524: }
14525:
1.1075.2.69 raeburn 14526: =pod
14527:
14528: =back
14529:
14530: =cut
14531:
1.655 raeburn 14532: ############################################################
14533: ############################################################
14534:
14535:
1.443 albertel 14536: sub commit_customrole {
1.664 raeburn 14537: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14538: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14539: ($start?', '.&mt('starting').' '.localtime($start):'').
14540: ($end?', ending '.localtime($end):'').': <b>'.
14541: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14542: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14543: '</b><br />';
14544: return $output;
14545: }
14546:
14547: sub commit_standardrole {
1.1075.2.31 raeburn 14548: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14549: my ($output,$logmsg,$linefeed);
14550: if ($context eq 'auto') {
14551: $linefeed = "\n";
14552: } else {
14553: $linefeed = "<br />\n";
14554: }
1.443 albertel 14555: if ($three eq 'st') {
1.541 raeburn 14556: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1075.2.31 raeburn 14557: $one,$two,$sec,$context,$credits);
1.541 raeburn 14558: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14559: ($result eq 'unknown_course') || ($result eq 'refused')) {
14560: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14561: } else {
1.541 raeburn 14562: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14563: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14564: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14565: if ($context eq 'auto') {
14566: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14567: } else {
14568: $output .= '<b>'.$result.'</b>'.$linefeed.
14569: &mt('Add to classlist').': <b>ok</b>';
14570: }
14571: $output .= $linefeed;
1.443 albertel 14572: }
14573: } else {
14574: $output = &mt('Assigning').' '.$three.' in '.$url.
14575: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14576: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 14577: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 14578: if ($context eq 'auto') {
14579: $output .= $result.$linefeed;
14580: } else {
14581: $output .= '<b>'.$result.'</b>'.$linefeed;
14582: }
1.443 albertel 14583: }
14584: return $output;
14585: }
14586:
14587: sub commit_studentrole {
1.1075.2.31 raeburn 14588: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
14589: $credits) = @_;
1.626 raeburn 14590: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 14591: if ($context eq 'auto') {
14592: $linefeed = "\n";
14593: } else {
14594: $linefeed = '<br />'."\n";
14595: }
1.443 albertel 14596: if (defined($one) && defined($two)) {
14597: my $cid=$one.'_'.$two;
14598: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
14599: my $secchange = 0;
14600: my $expire_role_result;
14601: my $modify_section_result;
1.628 raeburn 14602: if ($oldsec ne '-1') {
14603: if ($oldsec ne $sec) {
1.443 albertel 14604: $secchange = 1;
1.628 raeburn 14605: my $now = time;
1.443 albertel 14606: my $uurl='/'.$cid;
14607: $uurl=~s/\_/\//g;
14608: if ($oldsec) {
14609: $uurl.='/'.$oldsec;
14610: }
1.626 raeburn 14611: $oldsecurl = $uurl;
1.628 raeburn 14612: $expire_role_result =
1.652 raeburn 14613: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 14614: if ($env{'request.course.sec'} ne '') {
14615: if ($expire_role_result eq 'refused') {
14616: my @roles = ('st');
14617: my @statuses = ('previous');
14618: my @roledoms = ($one);
14619: my $withsec = 1;
14620: my %roleshash =
14621: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
14622: \@statuses,\@roles,\@roledoms,$withsec);
14623: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
14624: my ($oldstart,$oldend) =
14625: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
14626: if ($oldend > 0 && $oldend <= $now) {
14627: $expire_role_result = 'ok';
14628: }
14629: }
14630: }
14631: }
1.443 albertel 14632: $result = $expire_role_result;
14633: }
14634: }
14635: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1075.2.31 raeburn 14636: $modify_section_result =
14637: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
14638: undef,undef,undef,$sec,
14639: $end,$start,'','',$cid,
14640: '',$context,$credits);
1.443 albertel 14641: if ($modify_section_result =~ /^ok/) {
14642: if ($secchange == 1) {
1.628 raeburn 14643: if ($sec eq '') {
14644: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
14645: } else {
14646: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
14647: }
1.443 albertel 14648: } elsif ($oldsec eq '-1') {
1.628 raeburn 14649: if ($sec eq '') {
14650: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
14651: } else {
14652: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14653: }
1.443 albertel 14654: } else {
1.628 raeburn 14655: if ($sec eq '') {
14656: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
14657: } else {
14658: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14659: }
1.443 albertel 14660: }
14661: } else {
1.628 raeburn 14662: if ($secchange) {
14663: $$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;
14664: } else {
14665: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
14666: }
1.443 albertel 14667: }
14668: $result = $modify_section_result;
14669: } elsif ($secchange == 1) {
1.628 raeburn 14670: if ($oldsec eq '') {
1.1075.2.20 raeburn 14671: $$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 14672: } else {
14673: $$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;
14674: }
1.626 raeburn 14675: if ($expire_role_result eq 'refused') {
14676: my $newsecurl = '/'.$cid;
14677: $newsecurl =~ s/\_/\//g;
14678: if ($sec ne '') {
14679: $newsecurl.='/'.$sec;
14680: }
14681: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
14682: if ($sec eq '') {
14683: $$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;
14684: } else {
14685: $$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;
14686: }
14687: }
14688: }
1.443 albertel 14689: }
14690: } else {
1.626 raeburn 14691: $$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 14692: $result = "error: incomplete course id\n";
14693: }
14694: return $result;
14695: }
14696:
1.1075.2.25 raeburn 14697: sub show_role_extent {
14698: my ($scope,$context,$role) = @_;
14699: $scope =~ s{^/}{};
14700: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
14701: push(@courseroles,'co');
14702: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
14703: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
14704: $scope =~ s{/}{_};
14705: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
14706: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
14707: my ($audom,$auname) = split(/\//,$scope);
14708: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
14709: &Apache::loncommon::plainname($auname,$audom).'</span>');
14710: } else {
14711: $scope =~ s{/$}{};
14712: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
14713: &Apache::lonnet::domain($scope,'description').'</span>');
14714: }
14715: }
14716:
1.443 albertel 14717: ############################################################
14718: ############################################################
14719:
1.566 albertel 14720: sub check_clone {
1.578 raeburn 14721: my ($args,$linefeed) = @_;
1.566 albertel 14722: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
14723: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
14724: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
14725: my $clonemsg;
14726: my $can_clone = 0;
1.944 raeburn 14727: my $lctype = lc($args->{'crstype'});
1.908 raeburn 14728: if ($lctype ne 'community') {
14729: $lctype = 'course';
14730: }
1.566 albertel 14731: if ($clonehome eq 'no_host') {
1.944 raeburn 14732: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14733: $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'});
14734: } else {
14735: $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'});
14736: }
1.566 albertel 14737: } else {
14738: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 14739: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14740: if ($clonedesc{'type'} ne 'Community') {
14741: $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'});
14742: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14743: }
14744: }
1.1075.2.119 raeburn 14745: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 14746: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 14747: $can_clone = 1;
14748: } else {
1.1075.2.95 raeburn 14749: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 14750: $args->{'clonedomain'},$args->{'clonecourse'});
1.1075.2.95 raeburn 14751: if ($clonehash{'cloners'} eq '') {
14752: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
14753: if ($domdefs{'canclone'}) {
14754: unless ($domdefs{'canclone'} eq 'none') {
14755: if ($domdefs{'canclone'} eq 'domain') {
14756: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
14757: $can_clone = 1;
14758: }
14759: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14760: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
14761: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
14762: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
14763: $can_clone = 1;
14764: }
14765: }
14766: }
1.908 raeburn 14767: }
1.1075.2.95 raeburn 14768: } else {
14769: my @cloners = split(/,/,$clonehash{'cloners'});
14770: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 14771: $can_clone = 1;
1.1075.2.95 raeburn 14772: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 14773: $can_clone = 1;
1.1075.2.96 raeburn 14774: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
14775: $can_clone = 1;
1.1075.2.95 raeburn 14776: }
14777: unless ($can_clone) {
1.1075.2.96 raeburn 14778: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14779: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1075.2.95 raeburn 14780: my (%gotdomdefaults,%gotcodedefaults);
14781: foreach my $cloner (@cloners) {
14782: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
14783: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
14784: my (%codedefaults,@code_order);
14785: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
14786: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
14787: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
14788: }
14789: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
14790: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
14791: }
14792: } else {
14793: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
14794: \%codedefaults,
14795: \@code_order);
14796: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
14797: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
14798: }
14799: if (@code_order > 0) {
14800: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
14801: $cloner,$clonehash{'internal.coursecode'},
14802: $args->{'crscode'})) {
14803: $can_clone = 1;
14804: last;
14805: }
14806: }
14807: }
14808: }
14809: }
1.1075.2.96 raeburn 14810: }
14811: }
14812: unless ($can_clone) {
14813: my $ccrole = 'cc';
14814: if ($args->{'crstype'} eq 'Community') {
14815: $ccrole = 'co';
14816: }
14817: my %roleshash =
14818: &Apache::lonnet::get_my_roles($args->{'ccuname'},
14819: $args->{'ccdomain'},
14820: 'userroles',['active'],[$ccrole],
14821: [$args->{'clonedomain'}]);
14822: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
14823: $can_clone = 1;
14824: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
14825: $args->{'ccuname'},$args->{'ccdomain'})) {
14826: $can_clone = 1;
1.1075.2.95 raeburn 14827: }
14828: }
14829: unless ($can_clone) {
14830: if ($args->{'crstype'} eq 'Community') {
14831: $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'});
14832: } else {
14833: $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 14834: }
1.566 albertel 14835: }
1.578 raeburn 14836: }
1.566 albertel 14837: }
14838: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14839: }
14840:
1.444 albertel 14841: sub construct_course {
1.1075.2.119 raeburn 14842: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
14843: $cnum,$category,$coderef) = @_;
1.444 albertel 14844: my $outcome;
1.541 raeburn 14845: my $linefeed = '<br />'."\n";
14846: if ($context eq 'auto') {
14847: $linefeed = "\n";
14848: }
1.566 albertel 14849:
14850: #
14851: # Are we cloning?
14852: #
14853: my ($can_clone, $clonemsg, $cloneid, $clonehome);
14854: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 14855: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 14856: if ($context ne 'auto') {
1.578 raeburn 14857: if ($clonemsg ne '') {
14858: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
14859: }
1.566 albertel 14860: }
14861: $outcome .= $clonemsg.$linefeed;
14862:
14863: if (!$can_clone) {
14864: return (0,$outcome);
14865: }
14866: }
14867:
1.444 albertel 14868: #
14869: # Open course
14870: #
14871: my $crstype = lc($args->{'crstype'});
14872: my %cenv=();
14873: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
14874: $args->{'cdescr'},
14875: $args->{'curl'},
14876: $args->{'course_home'},
14877: $args->{'nonstandard'},
14878: $args->{'crscode'},
14879: $args->{'ccuname'}.':'.
14880: $args->{'ccdomain'},
1.882 raeburn 14881: $args->{'crstype'},
1.885 raeburn 14882: $cnum,$context,$category);
1.444 albertel 14883:
14884: # Note: The testing routines depend on this being output; see
14885: # Utils::Course. This needs to at least be output as a comment
14886: # if anyone ever decides to not show this, and Utils::Course::new
14887: # will need to be suitably modified.
1.541 raeburn 14888: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 14889: if ($$courseid =~ /^error:/) {
14890: return (0,$outcome);
14891: }
14892:
1.444 albertel 14893: #
14894: # Check if created correctly
14895: #
1.479 albertel 14896: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 14897: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 14898: if ($crsuhome eq 'no_host') {
14899: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
14900: return (0,$outcome);
14901: }
1.541 raeburn 14902: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 14903:
1.444 albertel 14904: #
1.566 albertel 14905: # Do the cloning
14906: #
14907: if ($can_clone && $cloneid) {
14908: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
14909: if ($context ne 'auto') {
14910: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
14911: }
14912: $outcome .= $clonemsg.$linefeed;
14913: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 14914: # Copy all files
1.637 www 14915: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 14916: # Restore URL
1.566 albertel 14917: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 14918: # Restore title
1.566 albertel 14919: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 14920: # Restore creation date, creator and creation context.
14921: $cenv{'internal.created'}=$oldcenv{'internal.created'};
14922: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
14923: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 14924: # Mark as cloned
1.566 albertel 14925: $cenv{'clonedfrom'}=$cloneid;
1.638 www 14926: # Need to clone grading mode
14927: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
14928: $cenv{'grading'}=$newenv{'grading'};
14929: # Do not clone these environment entries
14930: &Apache::lonnet::del('environment',
14931: ['default_enrollment_start_date',
14932: 'default_enrollment_end_date',
14933: 'question.email',
14934: 'policy.email',
14935: 'comment.email',
14936: 'pch.users.denied',
1.725 raeburn 14937: 'plc.users.denied',
14938: 'hidefromcat',
1.1075.2.36 raeburn 14939: 'checkforpriv',
1.1075.2.59 raeburn 14940: 'categories',
14941: 'internal.uniquecode'],
1.638 www 14942: $$crsudom,$$crsunum);
1.1075.2.63 raeburn 14943: if ($args->{'textbook'}) {
14944: $cenv{'internal.textbook'} = $args->{'textbook'};
14945: }
1.444 albertel 14946: }
1.566 albertel 14947:
1.444 albertel 14948: #
14949: # Set environment (will override cloned, if existing)
14950: #
14951: my @sections = ();
14952: my @xlists = ();
14953: if ($args->{'crstype'}) {
14954: $cenv{'type'}=$args->{'crstype'};
14955: }
14956: if ($args->{'crsid'}) {
14957: $cenv{'courseid'}=$args->{'crsid'};
14958: }
14959: if ($args->{'crscode'}) {
14960: $cenv{'internal.coursecode'}=$args->{'crscode'};
14961: }
14962: if ($args->{'crsquota'} ne '') {
14963: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14964: } else {
14965: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14966: }
14967: if ($args->{'ccuname'}) {
14968: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14969: ':'.$args->{'ccdomain'};
14970: } else {
14971: $cenv{'internal.courseowner'} = $args->{'curruser'};
14972: }
1.1075.2.31 raeburn 14973: if ($args->{'defaultcredits'}) {
14974: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14975: }
1.444 albertel 14976: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14977: if ($args->{'crssections'}) {
14978: $cenv{'internal.sectionnums'} = '';
14979: if ($args->{'crssections'} =~ m/,/) {
14980: @sections = split/,/,$args->{'crssections'};
14981: } else {
14982: $sections[0] = $args->{'crssections'};
14983: }
14984: if (@sections > 0) {
14985: foreach my $item (@sections) {
14986: my ($sec,$gp) = split/:/,$item;
14987: my $class = $args->{'crscode'}.$sec;
14988: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14989: $cenv{'internal.sectionnums'} .= $item.',';
14990: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 14991: push(@badclasses,$class);
1.444 albertel 14992: }
14993: }
14994: $cenv{'internal.sectionnums'} =~ s/,$//;
14995: }
14996: }
14997: # do not hide course coordinator from staff listing,
14998: # even if privileged
14999: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1075.2.36 raeburn 15000: # add course coordinator's domain to domains to check for privileged users
15001: # if different to course domain
15002: if ($$crsudom ne $args->{'ccdomain'}) {
15003: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15004: }
1.444 albertel 15005: # add crosslistings
15006: if ($args->{'crsxlist'}) {
15007: $cenv{'internal.crosslistings'}='';
15008: if ($args->{'crsxlist'} =~ m/,/) {
15009: @xlists = split/,/,$args->{'crsxlist'};
15010: } else {
15011: $xlists[0] = $args->{'crsxlist'};
15012: }
15013: if (@xlists > 0) {
15014: foreach my $item (@xlists) {
15015: my ($xl,$gp) = split/:/,$item;
15016: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15017: $cenv{'internal.crosslistings'} .= $item.',';
15018: unless ($addcheck eq 'ok') {
1.1075.2.119 raeburn 15019: push(@badclasses,$xl);
1.444 albertel 15020: }
15021: }
15022: $cenv{'internal.crosslistings'} =~ s/,$//;
15023: }
15024: }
15025: if ($args->{'autoadds'}) {
15026: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15027: }
15028: if ($args->{'autodrops'}) {
15029: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15030: }
15031: # check for notification of enrollment changes
15032: my @notified = ();
15033: if ($args->{'notify_owner'}) {
15034: if ($args->{'ccuname'} ne '') {
15035: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15036: }
15037: }
15038: if ($args->{'notify_dc'}) {
15039: if ($uname ne '') {
1.630 raeburn 15040: push(@notified,$uname.':'.$udom);
1.444 albertel 15041: }
15042: }
15043: if (@notified > 0) {
15044: my $notifylist;
15045: if (@notified > 1) {
15046: $notifylist = join(',',@notified);
15047: } else {
15048: $notifylist = $notified[0];
15049: }
15050: $cenv{'internal.notifylist'} = $notifylist;
15051: }
15052: if (@badclasses > 0) {
15053: my %lt=&Apache::lonlocal::texthash(
1.1075.2.119 raeburn 15054: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15055: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15056: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15057: );
1.1075.2.119 raeburn 15058: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15059: &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 15060: if ($context eq 'auto') {
15061: $outcome .= $badclass_msg.$linefeed;
1.1075.2.119 raeburn 15062: } else {
1.566 albertel 15063: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1075.2.119 raeburn 15064: }
15065: foreach my $item (@badclasses) {
1.541 raeburn 15066: if ($context eq 'auto') {
1.1075.2.119 raeburn 15067: $outcome .= " - $item\n";
1.541 raeburn 15068: } else {
1.1075.2.119 raeburn 15069: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15070: }
1.1075.2.119 raeburn 15071: }
15072: if ($context eq 'auto') {
15073: $outcome .= $linefeed;
15074: } else {
15075: $outcome .= "</ul><br /><br /></div>\n";
15076: }
1.444 albertel 15077: }
15078: if ($args->{'no_end_date'}) {
15079: $args->{'endaccess'} = 0;
15080: }
15081: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15082: $cenv{'internal.autoend'}=$args->{'enrollend'};
15083: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15084: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15085: if ($args->{'showphotos'}) {
15086: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15087: }
15088: $cenv{'internal.authtype'} = $args->{'authtype'};
15089: $cenv{'internal.autharg'} = $args->{'autharg'};
15090: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15091: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15092: 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');
15093: if ($context eq 'auto') {
15094: $outcome .= $krb_msg;
15095: } else {
1.566 albertel 15096: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15097: }
15098: $outcome .= $linefeed;
1.444 albertel 15099: }
15100: }
15101: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15102: if ($args->{'setpolicy'}) {
15103: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15104: }
15105: if ($args->{'setcontent'}) {
15106: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15107: }
1.1075.2.110 raeburn 15108: if ($args->{'setcomment'}) {
15109: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15110: }
1.444 albertel 15111: }
15112: if ($args->{'reshome'}) {
15113: $cenv{'reshome'}=$args->{'reshome'}.'/';
15114: $cenv{'reshome'}=~s/\/+$/\//;
15115: }
15116: #
15117: # course has keyed access
15118: #
15119: if ($args->{'setkeys'}) {
15120: $cenv{'keyaccess'}='yes';
15121: }
15122: # if specified, key authority is not course, but user
15123: # only active if keyaccess is yes
15124: if ($args->{'keyauth'}) {
1.487 albertel 15125: my ($user,$domain) = split(':',$args->{'keyauth'});
15126: $user = &LONCAPA::clean_username($user);
15127: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15128: if ($user ne '' && $domain ne '') {
1.487 albertel 15129: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15130: }
15131: }
15132:
1.1075.2.59 raeburn 15133: #
15134: # generate and store uniquecode (available to course requester), if course should have one.
15135: #
15136: if ($args->{'uniquecode'}) {
15137: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15138: if ($code) {
15139: $cenv{'internal.uniquecode'} = $code;
15140: my %crsinfo =
15141: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15142: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15143: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15144: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15145: }
15146: if (ref($coderef)) {
15147: $$coderef = $code;
15148: }
15149: }
15150: }
15151:
1.444 albertel 15152: if ($args->{'disresdis'}) {
15153: $cenv{'pch.roles.denied'}='st';
15154: }
15155: if ($args->{'disablechat'}) {
15156: $cenv{'plc.roles.denied'}='st';
15157: }
15158:
15159: # Record we've not yet viewed the Course Initialization Helper for this
15160: # course
15161: $cenv{'course.helper.not.run'} = 1;
15162: #
15163: # Use new Randomseed
15164: #
15165: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15166: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15167: #
15168: # The encryption code and receipt prefix for this course
15169: #
15170: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15171: $cenv{'internal.encpref'}=100+int(9*rand(99));
15172: #
15173: # By default, use standard grading
15174: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15175:
1.541 raeburn 15176: $outcome .= $linefeed.&mt('Setting environment').': '.
15177: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15178: #
15179: # Open all assignments
15180: #
15181: if ($args->{'openall'}) {
15182: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15183: my %storecontent = ($storeunder => time,
15184: $storeunder.'.type' => 'date_start');
15185:
15186: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15187: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15188: }
15189: #
15190: # Set first page
15191: #
15192: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15193: || ($cloneid)) {
1.445 albertel 15194: use LONCAPA::map;
1.444 albertel 15195: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15196:
15197: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15198: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15199:
1.444 albertel 15200: $outcome .= ($fatal?$errtext:'read ok').' - ';
15201: my $title; my $url;
15202: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15203: $title=&mt('Syllabus');
1.444 albertel 15204: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15205: } else {
1.963 raeburn 15206: $title=&mt('Table of Contents');
1.444 albertel 15207: $url='/adm/navmaps';
15208: }
1.445 albertel 15209:
15210: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15211: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15212:
15213: if ($errtext) { $fatal=2; }
1.541 raeburn 15214: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15215: }
1.566 albertel 15216:
15217: return (1,$outcome);
1.444 albertel 15218: }
15219:
1.1075.2.59 raeburn 15220: sub make_unique_code {
15221: my ($cdom,$cnum) = @_;
15222: # get lock on uniquecodes db
15223: my $lockhash = {
15224: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15225: ':'.$env{'user.domain'},
15226: };
15227: my $tries = 0;
15228: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15229: my ($code,$error);
15230:
15231: while (($gotlock ne 'ok') && ($tries<3)) {
15232: $tries ++;
15233: sleep 1;
15234: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15235: }
15236: if ($gotlock eq 'ok') {
15237: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15238: my $gotcode;
15239: my $attempts = 0;
15240: while ((!$gotcode) && ($attempts < 100)) {
15241: $code = &generate_code();
15242: if (!exists($currcodes{$code})) {
15243: $gotcode = 1;
15244: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15245: $error = 'nostore';
15246: }
15247: }
15248: $attempts ++;
15249: }
15250: my @del_lock = ($cnum."\0".'uniquecodes');
15251: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15252: } else {
15253: $error = 'nolock';
15254: }
15255: return ($code,$error);
15256: }
15257:
15258: sub generate_code {
15259: my $code;
15260: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15261: for (my $i=0; $i<6; $i++) {
15262: my $lettnum = int (rand 2);
15263: my $item = '';
15264: if ($lettnum) {
15265: $item = $letts[int( rand(18) )];
15266: } else {
15267: $item = 1+int( rand(8) );
15268: }
15269: $code .= $item;
15270: }
15271: return $code;
15272: }
15273:
1.444 albertel 15274: ############################################################
15275: ############################################################
15276:
1.953 droeschl 15277: #SD
15278: # only Community and Course, or anything else?
1.378 raeburn 15279: sub course_type {
15280: my ($cid) = @_;
15281: if (!defined($cid)) {
15282: $cid = $env{'request.course.id'};
15283: }
1.404 albertel 15284: if (defined($env{'course.'.$cid.'.type'})) {
15285: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15286: } else {
15287: return 'Course';
1.377 raeburn 15288: }
15289: }
1.156 albertel 15290:
1.406 raeburn 15291: sub group_term {
15292: my $crstype = &course_type();
15293: my %names = (
15294: 'Course' => 'group',
1.865 raeburn 15295: 'Community' => 'group',
1.406 raeburn 15296: );
15297: return $names{$crstype};
15298: }
15299:
1.902 raeburn 15300: sub course_types {
1.1075.2.59 raeburn 15301: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 15302: my %typename = (
15303: official => 'Official course',
15304: unofficial => 'Unofficial course',
15305: community => 'Community',
1.1075.2.59 raeburn 15306: textbook => 'Textbook course',
1.902 raeburn 15307: );
15308: return (\@types,\%typename);
15309: }
15310:
1.156 albertel 15311: sub icon {
15312: my ($file)=@_;
1.505 albertel 15313: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15314: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15315: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15316: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15317: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15318: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15319: $curfext.".gif") {
15320: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15321: $curfext.".gif";
15322: }
15323: }
1.249 albertel 15324: return &lonhttpdurl($iconname);
1.154 albertel 15325: }
1.84 albertel 15326:
1.575 albertel 15327: sub lonhttpdurl {
1.692 www 15328: #
15329: # Had been used for "small fry" static images on separate port 8080.
15330: # Modify here if lightweight http functionality desired again.
15331: # Currently eliminated due to increasing firewall issues.
15332: #
1.575 albertel 15333: my ($url)=@_;
1.692 www 15334: return $url;
1.215 albertel 15335: }
15336:
1.213 albertel 15337: sub connection_aborted {
15338: my ($r)=@_;
15339: $r->print(" ");$r->rflush();
15340: my $c = $r->connection;
15341: return $c->aborted();
15342: }
15343:
1.221 foxr 15344: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15345: # strings as 'strings'.
15346: sub escape_single {
1.221 foxr 15347: my ($input) = @_;
1.223 albertel 15348: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15349: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15350: return $input;
15351: }
1.223 albertel 15352:
1.222 foxr 15353: # Same as escape_single, but escape's "'s This
15354: # can be used for "strings"
15355: sub escape_double {
15356: my ($input) = @_;
15357: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15358: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15359: return $input;
15360: }
1.223 albertel 15361:
1.222 foxr 15362: # Escapes the last element of a full URL.
15363: sub escape_url {
15364: my ($url) = @_;
1.238 raeburn 15365: my @urlslices = split(/\//, $url,-1);
1.369 www 15366: my $lastitem = &escape(pop(@urlslices));
1.1075.2.83 raeburn 15367: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15368: }
1.462 albertel 15369:
1.820 raeburn 15370: sub compare_arrays {
15371: my ($arrayref1,$arrayref2) = @_;
15372: my (@difference,%count);
15373: @difference = ();
15374: %count = ();
15375: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15376: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15377: foreach my $element (keys(%count)) {
15378: if ($count{$element} == 1) {
15379: push(@difference,$element);
15380: }
15381: }
15382: }
15383: return @difference;
15384: }
15385:
1.817 bisitz 15386: # -------------------------------------------------------- Initialize user login
1.462 albertel 15387: sub init_user_environment {
1.463 albertel 15388: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15389: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15390:
15391: my $public=($username eq 'public' && $domain eq 'public');
15392:
15393: # See if old ID present, if so, remove
15394:
1.1062 raeburn 15395: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15396: my $now=time;
15397:
15398: if ($public) {
15399: my $max_public=100;
15400: my $oldest;
15401: my $oldest_time=0;
15402: for(my $next=1;$next<=$max_public;$next++) {
15403: if (-e $lonids."/publicuser_$next.id") {
15404: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15405: if ($mtime<$oldest_time || !$oldest_time) {
15406: $oldest_time=$mtime;
15407: $oldest=$next;
15408: }
15409: } else {
15410: $cookie="publicuser_$next";
15411: last;
15412: }
15413: }
15414: if (!$cookie) { $cookie="publicuser_$oldest"; }
15415: } else {
1.463 albertel 15416: # if this isn't a robot, kill any existing non-robot sessions
15417: if (!$args->{'robot'}) {
15418: opendir(DIR,$lonids);
15419: while ($filename=readdir(DIR)) {
15420: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
15421: unlink($lonids.'/'.$filename);
15422: }
1.462 albertel 15423: }
1.463 albertel 15424: closedir(DIR);
1.1075.2.84 raeburn 15425: # If there is a undeleted lockfile for the user's paste buffer remove it.
15426: my $namespace = 'nohist_courseeditor';
15427: my $lockingkey = 'paste'."\0".'locked_num';
15428: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15429: $domain,$username);
15430: if (exists($lockhash{$lockingkey})) {
15431: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15432: unless ($delresult eq 'ok') {
15433: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15434: }
15435: }
1.462 albertel 15436: }
15437: # Give them a new cookie
1.463 albertel 15438: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15439: : $now.$$.int(rand(10000)));
1.463 albertel 15440: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15441:
15442: # Initialize roles
15443:
1.1062 raeburn 15444: ($userroles,$firstaccenv,$timerintenv) =
15445: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15446: }
15447: # ------------------------------------ Check browser type and MathML capability
15448:
1.1075.2.77 raeburn 15449: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15450: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15451:
15452: # ------------------------------------------------------------- Get environment
15453:
15454: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15455: my ($tmp) = keys(%userenv);
15456: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15457: } else {
15458: undef(%userenv);
15459: }
15460: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15461: $form->{'interface'}=$userenv{'interface'};
15462: }
15463: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15464:
15465: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15466: foreach my $option ('interface','localpath','localres') {
15467: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15468: }
15469: # --------------------------------------------------------- Write first profile
15470:
15471: {
15472: my %initial_env =
15473: ("user.name" => $username,
15474: "user.domain" => $domain,
15475: "user.home" => $authhost,
15476: "browser.type" => $clientbrowser,
15477: "browser.version" => $clientversion,
15478: "browser.mathml" => $clientmathml,
15479: "browser.unicode" => $clientunicode,
15480: "browser.os" => $clientos,
1.1075.2.42 raeburn 15481: "browser.mobile" => $clientmobile,
15482: "browser.info" => $clientinfo,
1.1075.2.77 raeburn 15483: "browser.osversion" => $clientosversion,
1.462 albertel 15484: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15485: "request.course.fn" => '',
15486: "request.course.uri" => '',
15487: "request.course.sec" => '',
15488: "request.role" => 'cm',
15489: "request.role.adv" => $env{'user.adv'},
15490: "request.host" => $ENV{'REMOTE_ADDR'},);
15491:
15492: if ($form->{'localpath'}) {
15493: $initial_env{"browser.localpath"} = $form->{'localpath'};
15494: $initial_env{"browser.localres"} = $form->{'localres'};
15495: }
15496:
15497: if ($form->{'interface'}) {
15498: $form->{'interface'}=~s/\W//gs;
15499: $initial_env{"browser.interface"} = $form->{'interface'};
15500: $env{'browser.interface'}=$form->{'interface'};
15501: }
15502:
1.1075.2.54 raeburn 15503: if ($form->{'iptoken'}) {
15504: my $lonhost = $r->dir_config('lonHostID');
15505: $initial_env{"user.noloadbalance"} = $lonhost;
15506: $env{'user.noloadbalance'} = $lonhost;
15507: }
15508:
1.1075.2.120 raeburn 15509: if ($form->{'noloadbalance'}) {
15510: my @hosts = &Apache::lonnet::current_machine_ids();
15511: my $hosthere = $form->{'noloadbalance'};
15512: if (grep(/^\Q$hosthere\E$/,@hosts)) {
15513: $initial_env{"user.noloadbalance"} = $hosthere;
15514: $env{'user.noloadbalance'} = $hosthere;
15515: }
15516: }
15517:
1.1016 raeburn 15518: unless ($domain eq 'public') {
1.1075.2.125 raeburn 15519: my %is_adv = ( is_adv => $env{'user.adv'} );
15520: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
1.980 raeburn 15521:
1.1075.2.125 raeburn 15522: foreach my $tool ('aboutme','blog','webdav','portfolio') {
15523: $userenv{'availabletools.'.$tool} =
15524: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15525: undef,\%userenv,\%domdef,\%is_adv);
15526: }
1.724 raeburn 15527:
1.1075.2.125 raeburn 15528: foreach my $crstype ('official','unofficial','community','textbook') {
15529: $userenv{'canrequest.'.$crstype} =
15530: &Apache::lonnet::usertools_access($username,$domain,$crstype,
15531: 'reload','requestcourses',
15532: \%userenv,\%domdef,\%is_adv);
15533: }
1.765 raeburn 15534:
1.1075.2.125 raeburn 15535: $userenv{'canrequest.author'} =
15536: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15537: 'reload','requestauthor',
15538: \%userenv,\%domdef,\%is_adv);
15539: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15540: $domain,$username);
15541: my $reqstatus = $reqauthor{'author_status'};
15542: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15543: if (ref($reqauthor{'author'}) eq 'HASH') {
15544: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15545: $reqauthor{'author'}{'timestamp'};
15546: }
1.1075.2.14 raeburn 15547: }
15548: }
15549:
1.462 albertel 15550: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15551:
1.462 albertel 15552: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
15553: &GDBM_WRCREAT(),0640)) {
15554: &_add_to_env(\%disk_env,\%initial_env);
15555: &_add_to_env(\%disk_env,\%userenv,'environment.');
15556: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 15557: if (ref($firstaccenv) eq 'HASH') {
15558: &_add_to_env(\%disk_env,$firstaccenv);
15559: }
15560: if (ref($timerintenv) eq 'HASH') {
15561: &_add_to_env(\%disk_env,$timerintenv);
15562: }
1.463 albertel 15563: if (ref($args->{'extra_env'})) {
15564: &_add_to_env(\%disk_env,$args->{'extra_env'});
15565: }
1.462 albertel 15566: untie(%disk_env);
15567: } else {
1.705 tempelho 15568: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
15569: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 15570: return 'error: '.$!;
15571: }
15572: }
15573: $env{'request.role'}='cm';
15574: $env{'request.role.adv'}=$env{'user.adv'};
15575: $env{'browser.type'}=$clientbrowser;
15576:
15577: return $cookie;
15578:
15579: }
15580:
15581: sub _add_to_env {
15582: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 15583: if (ref($env_data) eq 'HASH') {
15584: while (my ($key,$value) = each(%$env_data)) {
15585: $idf->{$prefix.$key} = $value;
15586: $env{$prefix.$key} = $value;
15587: }
1.462 albertel 15588: }
15589: }
15590:
1.685 tempelho 15591: # --- Get the symbolic name of a problem and the url
15592: sub get_symb {
15593: my ($request,$silent) = @_;
1.726 raeburn 15594: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 15595: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
15596: if ($symb eq '') {
15597: if (!$silent) {
1.1071 raeburn 15598: if (ref($request)) {
15599: $request->print("Unable to handle ambiguous references:$url:.");
15600: }
1.685 tempelho 15601: return ();
15602: }
15603: }
15604: &Apache::lonenc::check_decrypt(\$symb);
15605: return ($symb);
15606: }
15607:
15608: # --------------------------------------------------------------Get annotation
15609:
15610: sub get_annotation {
15611: my ($symb,$enc) = @_;
15612:
15613: my $key = $symb;
15614: if (!$enc) {
15615: $key =
15616: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
15617: }
15618: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
15619: return $annotation{$key};
15620: }
15621:
15622: sub clean_symb {
1.731 raeburn 15623: my ($symb,$delete_enc) = @_;
1.685 tempelho 15624:
15625: &Apache::lonenc::check_decrypt(\$symb);
15626: my $enc = $env{'request.enc'};
1.731 raeburn 15627: if ($delete_enc) {
1.730 raeburn 15628: delete($env{'request.enc'});
15629: }
1.685 tempelho 15630:
15631: return ($symb,$enc);
15632: }
1.462 albertel 15633:
1.1075.2.69 raeburn 15634: ############################################################
15635: ############################################################
15636:
15637: =pod
15638:
15639: =head1 Routines for building display used to search for courses
15640:
15641:
15642: =over 4
15643:
15644: =item * &build_filters()
15645:
15646: Create markup for a table used to set filters to use when selecting
15647: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
15648: and quotacheck.pl
15649:
15650:
15651: Inputs:
15652:
15653: filterlist - anonymous array of fields to include as potential filters
15654:
15655: crstype - course type
15656:
15657: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
15658: to pop-open a course selector (will contain "extra element").
15659:
15660: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
15661:
15662: filter - anonymous hash of criteria and their values
15663:
15664: action - form action
15665:
15666: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
15667:
15668: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
15669:
15670: cloneruname - username of owner of new course who wants to clone
15671:
15672: clonerudom - domain of owner of new course who wants to clone
15673:
15674: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
15675:
15676: codetitlesref - reference to array of titles of components in institutional codes (official courses)
15677:
15678: codedom - domain
15679:
15680: formname - value of form element named "form".
15681:
15682: fixeddom - domain, if fixed.
15683:
15684: prevphase - value to assign to form element named "phase" when going back to the previous screen
15685:
15686: cnameelement - name of form element in form on opener page which will receive title of selected course
15687:
15688: cnumelement - name of form element in form on opener page which will receive courseID of selected course
15689:
15690: cdomelement - name of form element in form on opener page which will receive domain of selected course
15691:
15692: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
15693:
15694: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
15695:
15696: clonewarning - warning message about missing information for intended course owner when DC creates a course
15697:
15698:
15699: Returns: $output - HTML for display of search criteria, and hidden form elements.
15700:
15701:
15702: Side Effects: None
15703:
15704: =cut
15705:
15706: # ---------------------------------------------- search for courses based on last activity etc.
15707:
15708: sub build_filters {
15709: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
15710: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
15711: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
15712: $cnameelement,$cnumelement,$cdomelement,$setroles,
15713: $clonetext,$clonewarning) = @_;
15714: my ($list,$jscript);
15715: my $onchange = 'javascript:updateFilters(this)';
15716: my ($domainselectform,$sincefilterform,$createdfilterform,
15717: $ownerdomselectform,$persondomselectform,$instcodeform,
15718: $typeselectform,$instcodetitle);
15719: if ($formname eq '') {
15720: $formname = $caller;
15721: }
15722: foreach my $item (@{$filterlist}) {
15723: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
15724: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
15725: if ($item eq 'domainfilter') {
15726: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
15727: } elsif ($item eq 'coursefilter') {
15728: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
15729: } elsif ($item eq 'ownerfilter') {
15730: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15731: } elsif ($item eq 'ownerdomfilter') {
15732: $filter->{'ownerdomfilter'} =
15733: &LONCAPA::clean_domain($filter->{$item});
15734: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
15735: 'ownerdomfilter',1);
15736: } elsif ($item eq 'personfilter') {
15737: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15738: } elsif ($item eq 'persondomfilter') {
15739: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
15740: 'persondomfilter',1);
15741: } else {
15742: $filter->{$item} =~ s/\W//g;
15743: }
15744: if (!$filter->{$item}) {
15745: $filter->{$item} = '';
15746: }
15747: }
15748: if ($item eq 'domainfilter') {
15749: my $allow_blank = 1;
15750: if ($formname eq 'portform') {
15751: $allow_blank=0;
15752: } elsif ($formname eq 'studentform') {
15753: $allow_blank=0;
15754: }
15755: if ($fixeddom) {
15756: $domainselectform = '<input type="hidden" name="domainfilter"'.
15757: ' value="'.$codedom.'" />'.
15758: &Apache::lonnet::domain($codedom,'description');
15759: } else {
15760: $domainselectform = &select_dom_form($filter->{$item},
15761: 'domainfilter',
15762: $allow_blank,'',$onchange);
15763: }
15764: } else {
15765: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
15766: }
15767: }
15768:
15769: # last course activity filter and selection
15770: $sincefilterform = &timebased_select_form('sincefilter',$filter);
15771:
15772: # course created filter and selection
15773: if (exists($filter->{'createdfilter'})) {
15774: $createdfilterform = &timebased_select_form('createdfilter',$filter);
15775: }
15776:
15777: my %lt = &Apache::lonlocal::texthash(
15778: 'cac' => "$crstype Activity",
15779: 'ccr' => "$crstype Created",
15780: 'cde' => "$crstype Title",
15781: 'cdo' => "$crstype Domain",
15782: 'ins' => 'Institutional Code',
15783: 'inc' => 'Institutional Categorization',
15784: 'cow' => "$crstype Owner/Co-owner",
15785: 'cop' => "$crstype Personnel Includes",
15786: 'cog' => 'Type',
15787: );
15788:
15789: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15790: my $typeval = 'Course';
15791: if ($crstype eq 'Community') {
15792: $typeval = 'Community';
15793: }
15794: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
15795: } else {
15796: $typeselectform = '<select name="type" size="1"';
15797: if ($onchange) {
15798: $typeselectform .= ' onchange="'.$onchange.'"';
15799: }
15800: $typeselectform .= '>'."\n";
15801: foreach my $posstype ('Course','Community') {
15802: $typeselectform.='<option value="'.$posstype.'"'.
15803: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
15804: }
15805: $typeselectform.="</select>";
15806: }
15807:
15808: my ($cloneableonlyform,$cloneabletitle);
15809: if (exists($filter->{'cloneableonly'})) {
15810: my $cloneableon = '';
15811: my $cloneableoff = ' checked="checked"';
15812: if ($filter->{'cloneableonly'}) {
15813: $cloneableon = $cloneableoff;
15814: $cloneableoff = '';
15815: }
15816: $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>';
15817: if ($formname eq 'ccrs') {
1.1075.2.71 raeburn 15818: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1075.2.69 raeburn 15819: } else {
15820: $cloneabletitle = &mt('Cloneable by you');
15821: }
15822: }
15823: my $officialjs;
15824: if ($crstype eq 'Course') {
15825: if (exists($filter->{'instcodefilter'})) {
15826: # if (($fixeddom) || ($formname eq 'requestcrs') ||
15827: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
15828: if ($codedom) {
15829: $officialjs = 1;
15830: ($instcodeform,$jscript,$$numtitlesref) =
15831: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
15832: $officialjs,$codetitlesref);
15833: if ($jscript) {
15834: $jscript = '<script type="text/javascript">'."\n".
15835: '// <![CDATA['."\n".
15836: $jscript."\n".
15837: '// ]]>'."\n".
15838: '</script>'."\n";
15839: }
15840: }
15841: if ($instcodeform eq '') {
15842: $instcodeform =
15843: '<input type="text" name="instcodefilter" size="10" value="'.
15844: $list->{'instcodefilter'}.'" />';
15845: $instcodetitle = $lt{'ins'};
15846: } else {
15847: $instcodetitle = $lt{'inc'};
15848: }
15849: if ($fixeddom) {
15850: $instcodetitle .= '<br />('.$codedom.')';
15851: }
15852: }
15853: }
15854: my $output = qq|
15855: <form method="post" name="filterpicker" action="$action">
15856: <input type="hidden" name="form" value="$formname" />
15857: |;
15858: if ($formname eq 'modifycourse') {
15859: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
15860: '<input type="hidden" name="prevphase" value="'.
15861: $prevphase.'" />'."\n";
1.1075.2.82 raeburn 15862: } elsif ($formname eq 'quotacheck') {
15863: $output .= qq|
15864: <input type="hidden" name="sortby" value="" />
15865: <input type="hidden" name="sortorder" value="" />
15866: |;
15867: } else {
1.1075.2.69 raeburn 15868: my $name_input;
15869: if ($cnameelement ne '') {
15870: $name_input = '<input type="hidden" name="cnameelement" value="'.
15871: $cnameelement.'" />';
15872: }
15873: $output .= qq|
15874: <input type="hidden" name="cnumelement" value="$cnumelement" />
15875: <input type="hidden" name="cdomelement" value="$cdomelement" />
15876: $name_input
15877: $roleelement
15878: $multelement
15879: $typeelement
15880: |;
15881: if ($formname eq 'portform') {
15882: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
15883: }
15884: }
15885: if ($fixeddom) {
15886: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
15887: }
15888: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
15889: if ($sincefilterform) {
15890: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
15891: .$sincefilterform
15892: .&Apache::lonhtmlcommon::row_closure();
15893: }
15894: if ($createdfilterform) {
15895: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
15896: .$createdfilterform
15897: .&Apache::lonhtmlcommon::row_closure();
15898: }
15899: if ($domainselectform) {
15900: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
15901: .$domainselectform
15902: .&Apache::lonhtmlcommon::row_closure();
15903: }
15904: if ($typeselectform) {
15905: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15906: $output .= $typeselectform;
15907: } else {
15908: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
15909: .$typeselectform
15910: .&Apache::lonhtmlcommon::row_closure();
15911: }
15912: }
15913: if ($instcodeform) {
15914: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
15915: .$instcodeform
15916: .&Apache::lonhtmlcommon::row_closure();
15917: }
15918: if (exists($filter->{'ownerfilter'})) {
15919: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
15920: '<table><tr><td>'.&mt('Username').'<br />'.
15921: '<input type="text" name="ownerfilter" size="20" value="'.
15922: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15923: $ownerdomselectform.'</td></tr></table>'.
15924: &Apache::lonhtmlcommon::row_closure();
15925: }
15926: if (exists($filter->{'personfilter'})) {
15927: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
15928: '<table><tr><td>'.&mt('Username').'<br />'.
15929: '<input type="text" name="personfilter" size="20" value="'.
15930: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15931: $persondomselectform.'</td></tr></table>'.
15932: &Apache::lonhtmlcommon::row_closure();
15933: }
15934: if (exists($filter->{'coursefilter'})) {
15935: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
15936: .'<input type="text" name="coursefilter" size="25" value="'
15937: .$list->{'coursefilter'}.'" />'
15938: .&Apache::lonhtmlcommon::row_closure();
15939: }
15940: if ($cloneableonlyform) {
15941: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
15942: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
15943: }
15944: if (exists($filter->{'descriptfilter'})) {
15945: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
15946: .'<input type="text" name="descriptfilter" size="40" value="'
15947: .$list->{'descriptfilter'}.'" />'
15948: .&Apache::lonhtmlcommon::row_closure(1);
15949: }
15950: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
15951: '<input type="hidden" name="updater" value="" />'."\n".
15952: '<input type="submit" name="gosearch" value="'.
15953: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
15954: return $jscript.$clonewarning.$output;
15955: }
15956:
15957: =pod
15958:
15959: =item * &timebased_select_form()
15960:
15961: Create markup for a dropdown list used to select a time-based
15962: filter e.g., Course Activity, Course Created, when searching for courses
15963: or communities
15964:
15965: Inputs:
15966:
15967: item - name of form element (sincefilter or createdfilter)
15968:
15969: filter - anonymous hash of criteria and their values
15970:
15971: Returns: HTML for a select box contained a blank, then six time selections,
15972: with value set in incoming form variables currently selected.
15973:
15974: Side Effects: None
15975:
15976: =cut
15977:
15978: sub timebased_select_form {
15979: my ($item,$filter) = @_;
15980: if (ref($filter) eq 'HASH') {
15981: $filter->{$item} =~ s/[^\d-]//g;
15982: if (!$filter->{$item}) { $filter->{$item}=-1; }
15983: return &select_form(
15984: $filter->{$item},
15985: $item,
15986: { '-1' => '',
15987: '86400' => &mt('today'),
15988: '604800' => &mt('last week'),
15989: '2592000' => &mt('last month'),
15990: '7776000' => &mt('last three months'),
15991: '15552000' => &mt('last six months'),
15992: '31104000' => &mt('last year'),
15993: 'select_form_order' =>
15994: ['-1','86400','604800','2592000','7776000',
15995: '15552000','31104000']});
15996: }
15997: }
15998:
15999: =pod
16000:
16001: =item * &js_changer()
16002:
16003: Create script tag containing Javascript used to submit course search form
16004: when course type or domain is changed, and also to hide 'Searching ...' on
16005: page load completion for page showing search result.
16006:
16007: Inputs: None
16008:
16009: Returns: markup containing updateFilters() and hideSearching() javascript functions.
16010:
16011: Side Effects: None
16012:
16013: =cut
16014:
16015: sub js_changer {
16016: return <<ENDJS;
16017: <script type="text/javascript">
16018: // <![CDATA[
16019: function updateFilters(caller) {
16020: if (typeof(caller) != "undefined") {
16021: document.filterpicker.updater.value = caller.name;
16022: }
16023: document.filterpicker.submit();
16024: }
16025:
16026: function hideSearching() {
16027: if (document.getElementById('searching')) {
16028: document.getElementById('searching').style.display = 'none';
16029: }
16030: return;
16031: }
16032:
16033: // ]]>
16034: </script>
16035:
16036: ENDJS
16037: }
16038:
16039: =pod
16040:
16041: =item * &search_courses()
16042:
16043: Process selected filters form course search form and pass to lonnet::courseiddump
16044: to retrieve a hash for which keys are courseIDs which match the selected filters.
16045:
16046: Inputs:
16047:
16048: dom - domain being searched
16049:
16050: type - course type ('Course' or 'Community' or '.' if any).
16051:
16052: filter - anonymous hash of criteria and their values
16053:
16054: numtitles - for institutional codes - number of categories
16055:
16056: cloneruname - optional username of new course owner
16057:
16058: clonerudom - optional domain of new course owner
16059:
1.1075.2.95 raeburn 16060: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1075.2.69 raeburn 16061: (used when DC is using course creation form)
16062:
16063: codetitles - reference to array of titles of components in institutional codes (official courses).
16064:
1.1075.2.95 raeburn 16065: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16066: (and so can clone automatically)
16067:
16068: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16069:
16070: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16071: courses to clone
1.1075.2.69 raeburn 16072:
16073: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16074:
16075:
16076: Side Effects: None
16077:
16078: =cut
16079:
16080:
16081: sub search_courses {
1.1075.2.95 raeburn 16082: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16083: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1075.2.69 raeburn 16084: my (%courses,%showcourses,$cloner);
16085: if (($filter->{'ownerfilter'} ne '') ||
16086: ($filter->{'ownerdomfilter'} ne '')) {
16087: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16088: $filter->{'ownerdomfilter'};
16089: }
16090: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16091: if (!$filter->{$item}) {
16092: $filter->{$item}='.';
16093: }
16094: }
16095: my $now = time;
16096: my $timefilter =
16097: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16098: my ($createdbefore,$createdafter);
16099: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16100: $createdbefore = $now;
16101: $createdafter = $now-$filter->{'createdfilter'};
16102: }
16103: my ($instcodefilter,$regexpok);
16104: if ($numtitles) {
16105: if ($env{'form.official'} eq 'on') {
16106: $instcodefilter =
16107: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16108: $regexpok = 1;
16109: } elsif ($env{'form.official'} eq 'off') {
16110: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16111: unless ($instcodefilter eq '') {
16112: $regexpok = -1;
16113: }
16114: }
16115: } else {
16116: $instcodefilter = $filter->{'instcodefilter'};
16117: }
16118: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16119: if ($type eq '') { $type = '.'; }
16120:
16121: if (($clonerudom ne '') && ($cloneruname ne '')) {
16122: $cloner = $cloneruname.':'.$clonerudom;
16123: }
16124: %courses = &Apache::lonnet::courseiddump($dom,
16125: $filter->{'descriptfilter'},
16126: $timefilter,
16127: $instcodefilter,
16128: $filter->{'combownerfilter'},
16129: $filter->{'coursefilter'},
16130: undef,undef,$type,$regexpok,undef,undef,
1.1075.2.95 raeburn 16131: undef,undef,$cloner,$cc_clone,
1.1075.2.69 raeburn 16132: $filter->{'cloneableonly'},
16133: $createdbefore,$createdafter,undef,
1.1075.2.95 raeburn 16134: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1075.2.69 raeburn 16135: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16136: my $ccrole;
16137: if ($type eq 'Community') {
16138: $ccrole = 'co';
16139: } else {
16140: $ccrole = 'cc';
16141: }
16142: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16143: $filter->{'persondomfilter'},
16144: 'userroles',undef,
16145: [$ccrole,'in','ad','ep','ta','cr'],
16146: $dom);
16147: foreach my $role (keys(%rolehash)) {
16148: my ($cnum,$cdom,$courserole) = split(':',$role);
16149: my $cid = $cdom.'_'.$cnum;
16150: if (exists($courses{$cid})) {
16151: if (ref($courses{$cid}) eq 'HASH') {
16152: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16153: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1075.2.119 raeburn 16154: push(@{$courses{$cid}{roles}},$courserole);
1.1075.2.69 raeburn 16155: }
16156: } else {
16157: $courses{$cid}{roles} = [$courserole];
16158: }
16159: $showcourses{$cid} = $courses{$cid};
16160: }
16161: }
16162: }
16163: %courses = %showcourses;
16164: }
16165: return %courses;
16166: }
16167:
16168: =pod
16169:
16170: =back
16171:
1.1075.2.88 raeburn 16172: =head1 Routines for version requirements for current course.
16173:
16174: =over 4
16175:
16176: =item * &check_release_required()
16177:
16178: Compares required LON-CAPA version with version on server, and
16179: if required version is newer looks for a server with the required version.
16180:
16181: Looks first at servers in user's owen domain; if none suitable, looks at
16182: servers in course's domain are permitted to host sessions for user's domain.
16183:
16184: Inputs:
16185:
16186: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16187:
16188: $courseid - Course ID of current course
16189:
16190: $rolecode - User's current role in course (for switchserver query string).
16191:
16192: $required - LON-CAPA version needed by course (format: Major.Minor).
16193:
16194:
16195: Returns:
16196:
16197: $switchserver - query string tp append to /adm/switchserver call (if
16198: current server's LON-CAPA version is too old.
16199:
16200: $warning - Message is displayed if no suitable server could be found.
16201:
16202: =cut
16203:
16204: sub check_release_required {
16205: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16206: my ($switchserver,$warning);
16207: if ($required ne '') {
16208: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16209: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16210: if ($reqdmajor ne '' && $reqdminor ne '') {
16211: my $otherserver;
16212: if (($major eq '' && $minor eq '') ||
16213: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16214: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16215: my $switchlcrev =
16216: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16217: $userdomserver);
16218: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16219: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16220: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16221: my $cdom = $env{'course.'.$courseid.'.domain'};
16222: if ($cdom ne $env{'user.domain'}) {
16223: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16224: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16225: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16226: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16227: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16228: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16229: my $canhost =
16230: &Apache::lonnet::can_host_session($env{'user.domain'},
16231: $coursedomserver,
16232: $remoterev,
16233: $udomdefaults{'remotesessions'},
16234: $defdomdefaults{'hostedsessions'});
16235:
16236: if ($canhost) {
16237: $otherserver = $coursedomserver;
16238: } else {
16239: $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.");
16240: }
16241: } else {
16242: $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).");
16243: }
16244: } else {
16245: $otherserver = $userdomserver;
16246: }
16247: }
16248: if ($otherserver ne '') {
16249: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16250: }
16251: }
16252: }
16253: return ($switchserver,$warning);
16254: }
16255:
16256: =pod
16257:
16258: =item * &check_release_result()
16259:
16260: Inputs:
16261:
16262: $switchwarning - Warning message if no suitable server found to host session.
16263:
16264: $switchserver - query string to append to /adm/switchserver containing lonHostID
16265: and current role.
16266:
16267: Returns: HTML to display with information about requirement to switch server.
16268: Either displaying warning with link to Roles/Courses screen or
16269: display link to switchserver.
16270:
1.1075.2.69 raeburn 16271: =cut
16272:
1.1075.2.88 raeburn 16273: sub check_release_result {
16274: my ($switchwarning,$switchserver) = @_;
16275: my $output = &start_page('Selected course unavailable on this server').
16276: '<p class="LC_warning">';
16277: if ($switchwarning) {
16278: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16279: if (&show_course()) {
16280: $output .= &mt('Display courses');
16281: } else {
16282: $output .= &mt('Display roles');
16283: }
16284: $output .= '</a>';
16285: } elsif ($switchserver) {
16286: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16287: '<br />'.
16288: '<a href="/adm/switchserver?'.$switchserver.'">'.
16289: &mt('Switch Server').
16290: '</a>';
16291: }
16292: $output .= '</p>'.&end_page();
16293: return $output;
16294: }
16295:
16296: =pod
16297:
16298: =item * &needs_coursereinit()
16299:
16300: Determine if course contents stored for user's session needs to be
16301: refreshed, because content has changed since "Big Hash" last tied.
16302:
16303: Check for change is made if time last checked is more than 10 minutes ago
16304: (by default).
16305:
16306: Inputs:
16307:
16308: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16309:
16310: $interval (optional) - Time which may elapse (in s) between last check for content
16311: change in current course. (default: 600 s).
16312:
16313: Returns: an array; first element is:
16314:
16315: =over 4
16316:
16317: 'switch' - if content updates mean user's session
16318: needs to be switched to a server running a newer LON-CAPA version
16319:
16320: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16321: on current server hosting user's session
16322:
16323: '' - if no action required.
16324:
16325: =back
16326:
16327: If first item element is 'switch':
16328:
16329: second item is $switchwarning - Warning message if no suitable server found to host session.
16330:
16331: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16332: and current role.
16333:
16334: otherwise: no other elements returned.
16335:
16336: =back
16337:
16338: =cut
16339:
16340: sub needs_coursereinit {
16341: my ($loncaparev,$interval) = @_;
16342: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16343: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16344: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16345: my $now = time;
16346: if ($interval eq '') {
16347: $interval = 600;
16348: }
16349: if (($now-$env{'request.course.timechecked'})>$interval) {
16350: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16351: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16352: if ($lastchange > $env{'request.course.tied'}) {
16353: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16354: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16355: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16356: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16357: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16358: $curr_reqd_hash{'internal.releaserequired'}});
16359: my ($switchserver,$switchwarning) =
16360: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16361: $curr_reqd_hash{'internal.releaserequired'});
16362: if ($switchwarning ne '' || $switchserver ne '') {
16363: return ('switch',$switchwarning,$switchserver);
16364: }
16365: }
16366: }
16367: return ('update');
16368: }
16369: }
16370: return ();
16371: }
1.1075.2.69 raeburn 16372:
1.1075.2.11 raeburn 16373: sub update_content_constraints {
16374: my ($cdom,$cnum,$chome,$cid) = @_;
16375: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16376: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16377: my %checkresponsetypes;
16378: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
16379: my ($item,$name,$value) = split(/:/,$key);
16380: if ($item eq 'resourcetag') {
16381: if ($name eq 'responsetype') {
16382: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16383: }
16384: }
16385: }
16386: my $navmap = Apache::lonnavmaps::navmap->new();
16387: if (defined($navmap)) {
16388: my %allresponses;
16389: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16390: my %responses = $res->responseTypes();
16391: foreach my $key (keys(%responses)) {
16392: next unless(exists($checkresponsetypes{$key}));
16393: $allresponses{$key} += $responses{$key};
16394: }
16395: }
16396: foreach my $key (keys(%allresponses)) {
16397: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16398: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16399: ($reqdmajor,$reqdminor) = ($major,$minor);
16400: }
16401: }
16402: undef($navmap);
16403: }
16404: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16405: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16406: }
16407: return;
16408: }
16409:
1.1075.2.27 raeburn 16410: sub allmaps_incourse {
16411: my ($cdom,$cnum,$chome,$cid) = @_;
16412: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16413: $cid = $env{'request.course.id'};
16414: $cdom = $env{'course.'.$cid.'.domain'};
16415: $cnum = $env{'course.'.$cid.'.num'};
16416: $chome = $env{'course.'.$cid.'.home'};
16417: }
16418: my %allmaps = ();
16419: my $lastchange =
16420: &Apache::lonnet::get_coursechange($cdom,$cnum);
16421: if ($lastchange > $env{'request.course.tied'}) {
16422: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16423: unless ($ferr) {
16424: &update_content_constraints($cdom,$cnum,$chome,$cid);
16425: }
16426: }
16427: my $navmap = Apache::lonnavmaps::navmap->new();
16428: if (defined($navmap)) {
16429: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16430: $allmaps{$res->src()} = 1;
16431: }
16432: }
16433: return \%allmaps;
16434: }
16435:
1.1075.2.11 raeburn 16436: sub parse_supplemental_title {
16437: my ($title) = @_;
16438:
16439: my ($foldertitle,$renametitle);
16440: if ($title =~ /&&&/) {
16441: $title = &HTML::Entites::decode($title);
16442: }
16443: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16444: $renametitle=$4;
16445: my ($time,$uname,$udom) = ($1,$2,$3);
16446: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16447: my $name = &plainname($uname,$udom);
16448: $name = &HTML::Entities::encode($name,'"<>&\'');
16449: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16450: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16451: $name.': <br />'.$foldertitle;
16452: }
16453: if (wantarray) {
16454: return ($title,$foldertitle,$renametitle);
16455: }
16456: return $title;
16457: }
16458:
1.1075.2.43 raeburn 16459: sub recurse_supplemental {
16460: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16461: if ($suppmap) {
16462: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16463: if ($fatal) {
16464: $errors ++;
16465: } else {
16466: if ($#LONCAPA::map::resources > 0) {
16467: foreach my $res (@LONCAPA::map::resources) {
16468: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16469: if (($src ne '') && ($status eq 'res')) {
1.1075.2.46 raeburn 16470: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16471: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1075.2.43 raeburn 16472: } else {
16473: $numfiles ++;
16474: }
16475: }
16476: }
16477: }
16478: }
16479: }
16480: return ($numfiles,$errors);
16481: }
16482:
1.1075.2.18 raeburn 16483: sub symb_to_docspath {
1.1075.2.119 raeburn 16484: my ($symb,$navmapref) = @_;
16485: return unless ($symb && ref($navmapref));
1.1075.2.18 raeburn 16486: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16487: if ($resurl=~/\.(sequence|page)$/) {
16488: $mapurl=$resurl;
16489: } elsif ($resurl eq 'adm/navmaps') {
16490: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
16491: }
16492: my $mapresobj;
1.1075.2.119 raeburn 16493: unless (ref($$navmapref)) {
16494: $$navmapref = Apache::lonnavmaps::navmap->new();
16495: }
16496: if (ref($$navmapref)) {
16497: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1075.2.18 raeburn 16498: }
16499: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
16500: my $type=$2;
16501: my $path;
16502: if (ref($mapresobj)) {
16503: my $pcslist = $mapresobj->map_hierarchy();
16504: if ($pcslist ne '') {
16505: foreach my $pc (split(/,/,$pcslist)) {
16506: next if ($pc <= 1);
1.1075.2.119 raeburn 16507: my $res = $$navmapref->getByMapPc($pc);
1.1075.2.18 raeburn 16508: if (ref($res)) {
16509: my $thisurl = $res->src();
16510: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
16511: my $thistitle = $res->title();
16512: $path .= '&'.
16513: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1075.2.46 raeburn 16514: &escape($thistitle).
1.1075.2.18 raeburn 16515: ':'.$res->randompick().
16516: ':'.$res->randomout().
16517: ':'.$res->encrypted().
16518: ':'.$res->randomorder().
16519: ':'.$res->is_page();
16520: }
16521: }
16522: }
16523: $path =~ s/^\&//;
16524: my $maptitle = $mapresobj->title();
16525: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16526: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16527: }
16528: $path .= (($path ne '')? '&' : '').
16529: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16530: &escape($maptitle).
1.1075.2.18 raeburn 16531: ':'.$mapresobj->randompick().
16532: ':'.$mapresobj->randomout().
16533: ':'.$mapresobj->encrypted().
16534: ':'.$mapresobj->randomorder().
16535: ':'.$mapresobj->is_page();
16536: } else {
16537: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16538: my $ispage = (($type eq 'page')? 1 : '');
16539: if ($mapurl eq 'default') {
1.1075.2.38 raeburn 16540: $maptitle = 'Main Content';
1.1075.2.18 raeburn 16541: }
16542: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1075.2.46 raeburn 16543: &escape($maptitle).':::::'.$ispage;
1.1075.2.18 raeburn 16544: }
16545: unless ($mapurl eq 'default') {
16546: $path = 'default&'.
1.1075.2.46 raeburn 16547: &escape('Main Content').
1.1075.2.18 raeburn 16548: ':::::&'.$path;
16549: }
16550: return $path;
16551: }
16552:
1.1075.2.14 raeburn 16553: sub captcha_display {
16554: my ($context,$lonhost) = @_;
16555: my ($output,$error);
1.1075.2.107 raeburn 16556: my ($captcha,$pubkey,$privkey,$version) =
16557: &get_captcha_config($context,$lonhost);
1.1075.2.14 raeburn 16558: if ($captcha eq 'original') {
16559: $output = &create_captcha();
16560: unless ($output) {
16561: $error = 'captcha';
16562: }
16563: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16564: $output = &create_recaptcha($pubkey,$version);
1.1075.2.14 raeburn 16565: unless ($output) {
16566: $error = 'recaptcha';
16567: }
16568: }
1.1075.2.107 raeburn 16569: return ($output,$error,$captcha,$version);
1.1075.2.14 raeburn 16570: }
16571:
16572: sub captcha_response {
16573: my ($context,$lonhost) = @_;
16574: my ($captcha_chk,$captcha_error);
1.1075.2.109 raeburn 16575: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1075.2.14 raeburn 16576: if ($captcha eq 'original') {
16577: ($captcha_chk,$captcha_error) = &check_captcha();
16578: } elsif ($captcha eq 'recaptcha') {
1.1075.2.107 raeburn 16579: $captcha_chk = &check_recaptcha($privkey,$version);
1.1075.2.14 raeburn 16580: } else {
16581: $captcha_chk = 1;
16582: }
16583: return ($captcha_chk,$captcha_error);
16584: }
16585:
16586: sub get_captcha_config {
16587: my ($context,$lonhost) = @_;
1.1075.2.107 raeburn 16588: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1075.2.14 raeburn 16589: my $hostname = &Apache::lonnet::hostname($lonhost);
16590: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
16591: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16592: if ($context eq 'usercreation') {
16593: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
16594: if (ref($domconfig{$context}) eq 'HASH') {
16595: $hashtocheck = $domconfig{$context}{'cancreate'};
16596: if (ref($hashtocheck) eq 'HASH') {
16597: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
16598: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
16599: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
16600: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
16601: }
16602: if ($privkey && $pubkey) {
16603: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16604: $version = $hashtocheck->{'recaptchaversion'};
16605: if ($version ne '2') {
16606: $version = 1;
16607: }
1.1075.2.14 raeburn 16608: } else {
16609: $captcha = 'original';
16610: }
16611: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
16612: $captcha = 'original';
16613: }
16614: }
16615: } else {
16616: $captcha = 'captcha';
16617: }
16618: } elsif ($context eq 'login') {
16619: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
16620: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
16621: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
16622: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
16623: if ($privkey && $pubkey) {
16624: $captcha = 'recaptcha';
1.1075.2.107 raeburn 16625: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
16626: if ($version ne '2') {
16627: $version = 1;
16628: }
1.1075.2.14 raeburn 16629: } else {
16630: $captcha = 'original';
16631: }
16632: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
16633: $captcha = 'original';
16634: }
16635: }
1.1075.2.107 raeburn 16636: return ($captcha,$pubkey,$privkey,$version);
1.1075.2.14 raeburn 16637: }
16638:
16639: sub create_captcha {
16640: my %captcha_params = &captcha_settings();
16641: my ($output,$maxtries,$tries) = ('',10,0);
16642: while ($tries < $maxtries) {
16643: $tries ++;
16644: my $captcha = Authen::Captcha->new (
16645: output_folder => $captcha_params{'output_dir'},
16646: data_folder => $captcha_params{'db_dir'},
16647: );
16648: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
16649:
16650: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
16651: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
16652: &mt('Type in the letters/numbers shown below').' '.
1.1075.2.66 raeburn 16653: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
16654: '<br />'.
16655: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1075.2.14 raeburn 16656: last;
16657: }
16658: }
16659: return $output;
16660: }
16661:
16662: sub captcha_settings {
16663: my %captcha_params = (
16664: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
16665: www_output_dir => "/captchaspool",
16666: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
16667: numchars => '5',
16668: );
16669: return %captcha_params;
16670: }
16671:
16672: sub check_captcha {
16673: my ($captcha_chk,$captcha_error);
16674: my $code = $env{'form.code'};
16675: my $md5sum = $env{'form.crypt'};
16676: my %captcha_params = &captcha_settings();
16677: my $captcha = Authen::Captcha->new(
16678: output_folder => $captcha_params{'output_dir'},
16679: data_folder => $captcha_params{'db_dir'},
16680: );
1.1075.2.26 raeburn 16681: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1075.2.14 raeburn 16682: my %captcha_hash = (
16683: 0 => 'Code not checked (file error)',
16684: -1 => 'Failed: code expired',
16685: -2 => 'Failed: invalid code (not in database)',
16686: -3 => 'Failed: invalid code (code does not match crypt)',
16687: );
16688: if ($captcha_chk != 1) {
16689: $captcha_error = $captcha_hash{$captcha_chk}
16690: }
16691: return ($captcha_chk,$captcha_error);
16692: }
16693:
16694: sub create_recaptcha {
1.1075.2.107 raeburn 16695: my ($pubkey,$version) = @_;
16696: if ($version >= 2) {
16697: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
16698: } else {
16699: my $use_ssl;
16700: if ($ENV{'SERVER_PORT'} == 443) {
16701: $use_ssl = 1;
16702: }
16703: my $captcha = Captcha::reCAPTCHA->new;
16704: return $captcha->get_options_setter({theme => 'white'})."\n".
16705: $captcha->get_html($pubkey,undef,$use_ssl).
16706: &mt('If the text is hard to read, [_1] will replace them.',
16707: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
16708: '<br /><br />';
16709: }
1.1075.2.14 raeburn 16710: }
16711:
16712: sub check_recaptcha {
1.1075.2.107 raeburn 16713: my ($privkey,$version) = @_;
1.1075.2.14 raeburn 16714: my $captcha_chk;
1.1075.2.107 raeburn 16715: if ($version >= 2) {
16716: my $ua = LWP::UserAgent->new;
16717: $ua->timeout(10);
16718: my %info = (
16719: secret => $privkey,
16720: response => $env{'form.g-recaptcha-response'},
16721: remoteip => $ENV{'REMOTE_ADDR'},
16722: );
16723: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
16724: if ($response->is_success) {
16725: my $data = JSON::DWIW->from_json($response->decoded_content);
16726: if (ref($data) eq 'HASH') {
16727: if ($data->{'success'}) {
16728: $captcha_chk = 1;
16729: }
16730: }
16731: }
16732: } else {
16733: my $captcha = Captcha::reCAPTCHA->new;
16734: my $captcha_result =
16735: $captcha->check_answer(
16736: $privkey,
16737: $ENV{'REMOTE_ADDR'},
16738: $env{'form.recaptcha_challenge_field'},
16739: $env{'form.recaptcha_response_field'},
16740: );
16741: if ($captcha_result->{is_valid}) {
16742: $captcha_chk = 1;
16743: }
1.1075.2.14 raeburn 16744: }
16745: return $captcha_chk;
16746: }
16747:
1.1075.2.64 raeburn 16748: sub emailusername_info {
1.1075.2.103 raeburn 16749: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1075.2.64 raeburn 16750: my %titles = &Apache::lonlocal::texthash (
16751: lastname => 'Last Name',
16752: firstname => 'First Name',
16753: institution => 'School/college/university',
16754: location => "School's city, state/province, country",
16755: web => "School's web address",
16756: officialemail => 'E-mail address at institution (if different)',
1.1075.2.103 raeburn 16757: id => 'Student/Employee ID',
1.1075.2.64 raeburn 16758: );
16759: return (\@fields,\%titles);
16760: }
16761:
1.1075.2.56 raeburn 16762: sub cleanup_html {
16763: my ($incoming) = @_;
16764: my $outgoing;
16765: if ($incoming ne '') {
16766: $outgoing = $incoming;
16767: $outgoing =~ s/;/;/g;
16768: $outgoing =~ s/\#/#/g;
16769: $outgoing =~ s/\&/&/g;
16770: $outgoing =~ s/</</g;
16771: $outgoing =~ s/>/>/g;
16772: $outgoing =~ s/\(/(/g;
16773: $outgoing =~ s/\)/)/g;
16774: $outgoing =~ s/"/"/g;
16775: $outgoing =~ s/'/'/g;
16776: $outgoing =~ s/\$/$/g;
16777: $outgoing =~ s{/}{/}g;
16778: $outgoing =~ s/=/=/g;
16779: $outgoing =~ s/\\/\/g
16780: }
16781: return $outgoing;
16782: }
16783:
1.1075.2.74 raeburn 16784: # Checks for critical messages and returns a redirect url if one exists.
16785: # $interval indicates how often to check for messages.
16786: sub critical_redirect {
16787: my ($interval) = @_;
16788: if ((time-$env{'user.criticalcheck.time'})>$interval) {
16789: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
16790: $env{'user.name'});
16791: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
16792: my $redirecturl;
16793: if ($what[0]) {
16794: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
16795: $redirecturl='/adm/email?critical=display';
16796: my $url=&Apache::lonnet::absolute_url().$redirecturl;
16797: return (1, $url);
16798: }
16799: }
16800: }
16801: return ();
16802: }
16803:
1.1075.2.64 raeburn 16804: # Use:
16805: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
16806: #
16807: ##################################################
16808: # password associated functions #
16809: ##################################################
16810: sub des_keys {
16811: # Make a new key for DES encryption.
16812: # Each key has two parts which are returned separately.
16813: # Please note: Each key must be passed through the &hex function
16814: # before it is output to the web browser. The hex versions cannot
16815: # be used to decrypt.
16816: my @hexstr=('0','1','2','3','4','5','6','7',
16817: '8','9','a','b','c','d','e','f');
16818: my $lkey='';
16819: for (0..7) {
16820: $lkey.=$hexstr[rand(15)];
16821: }
16822: my $ukey='';
16823: for (0..7) {
16824: $ukey.=$hexstr[rand(15)];
16825: }
16826: return ($lkey,$ukey);
16827: }
16828:
16829: sub des_decrypt {
16830: my ($key,$cyphertext) = @_;
16831: my $keybin=pack("H16",$key);
16832: my $cypher;
16833: if ($Crypt::DES::VERSION>=2.03) {
16834: $cypher=new Crypt::DES $keybin;
16835: } else {
16836: $cypher=new DES $keybin;
16837: }
1.1075.2.106 raeburn 16838: my $plaintext='';
16839: my $cypherlength = length($cyphertext);
16840: my $numchunks = int($cypherlength/32);
16841: for (my $j=0; $j<$numchunks; $j++) {
16842: my $start = $j*32;
16843: my $cypherblock = substr($cyphertext,$start,32);
16844: my $chunk =
16845: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
16846: $chunk .=
16847: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
16848: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
16849: $plaintext .= $chunk;
16850: }
1.1075.2.64 raeburn 16851: return $plaintext;
16852: }
16853:
1.112 bowersj2 16854: 1;
16855: __END__;
1.41 ng 16856:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>