Annotation of loncom/interface/loncommon.pm, revision 1.1196
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1196 ! raeburn 4: # $Id: loncommon.pm,v 1.1195 2014/06/22 13:26:19 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.1108 raeburn 70: use Apache::lonuserutils();
1.1110 raeburn 71: use Apache::lonuserstate();
1.1182 raeburn 72: use Apache::courseclassifier();
1.479 albertel 73: use LONCAPA qw(:DEFAULT :match);
1.657 raeburn 74: use DateTime::TimeZone;
1.687 raeburn 75: use DateTime::Locale::Catalog;
1.1091 foxr 76: use Text::Aspell;
1.1094 raeburn 77: use Authen::Captcha;
78: use Captcha::reCAPTCHA;
1.1174 raeburn 79: use Crypt::DES;
80: use DynaLoader; # for Crypt::DES version
1.117 www 81:
1.517 raeburn 82: # ---------------------------------------------- Designs
83: use vars qw(%defaultdesign);
84:
1.22 www 85: my $readit;
86:
1.517 raeburn 87:
1.157 matthew 88: ##
89: ## Global Variables
90: ##
1.46 matthew 91:
1.643 foxr 92:
93: # ----------------------------------------------- SSI with retries:
94: #
95:
96: =pod
97:
1.648 raeburn 98: =head1 Server Side include with retries:
1.643 foxr 99:
100: =over 4
101:
1.648 raeburn 102: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 103:
104: Performs an ssi with some number of retries. Retries continue either
105: until the result is ok or until the retry count supplied by the
106: caller is exhausted.
107:
108: Inputs:
1.648 raeburn 109:
110: =over 4
111:
1.643 foxr 112: resource - Identifies the resource to insert.
1.648 raeburn 113:
1.643 foxr 114: retries - Count of the number of retries allowed.
1.648 raeburn 115:
1.643 foxr 116: form - Hash that identifies the rendering options.
117:
1.648 raeburn 118: =back
119:
120: Returns:
121:
122: =over 4
123:
1.643 foxr 124: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 125:
1.643 foxr 126: response - The response from the last attempt (which may or may not have been successful.
127:
1.648 raeburn 128: =back
129:
130: =back
131:
1.643 foxr 132: =cut
133:
134: sub ssi_with_retries {
135: my ($resource, $retries, %form) = @_;
136:
137:
138: my $ok = 0; # True if we got a good response.
139: my $content;
140: my $response;
141:
142: # Try to get the ssi done. within the retries count:
143:
144: do {
145: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
146: $ok = $response->is_success;
1.650 www 147: if (!$ok) {
148: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
149: }
1.643 foxr 150: $retries--;
151: } while (!$ok && ($retries > 0));
152:
153: if (!$ok) {
154: $content = ''; # On error return an empty content.
155: }
156: return ($content, $response);
157:
158: }
159:
160:
161:
1.20 www 162: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 163: my %language;
1.124 www 164: my %supported_language;
1.1088 foxr 165: my %supported_codes;
1.1048 foxr 166: my %latex_language; # For choosing hyphenation in <transl..>
167: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 168: my %cprtag;
1.192 taceyjo1 169: my %scprtag;
1.351 www 170: my %fe; my %fd; my %fm;
1.41 ng 171: my %category_extensions;
1.12 harris41 172:
1.46 matthew 173: # ---------------------------------------------- Thesaurus variables
1.144 matthew 174: #
175: # %Keywords:
176: # A hash used by &keyword to determine if a word is considered a keyword.
177: # $thesaurus_db_file
178: # Scalar containing the full path to the thesaurus database.
1.46 matthew 179:
180: my %Keywords;
181: my $thesaurus_db_file;
182:
1.144 matthew 183: #
184: # Initialize values from language.tab, copyright.tab, filetypes.tab,
185: # thesaurus.tab, and filecategories.tab.
186: #
1.18 www 187: BEGIN {
1.46 matthew 188: # Variable initialization
189: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
190: #
1.22 www 191: unless ($readit) {
1.12 harris41 192: # ------------------------------------------------------------------- languages
193: {
1.158 raeburn 194: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
195: '/language.tab';
196: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 197: while (my $line = <$fh>) {
198: next if ($line=~/^\#/);
199: chomp($line);
1.1088 foxr 200: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 201: $language{$key}=$val.' - '.$enc;
202: if ($sup) {
203: $supported_language{$key}=$sup;
1.1088 foxr 204: $supported_codes{$key} = $code;
1.158 raeburn 205: }
1.1048 foxr 206: if ($latex) {
207: $latex_language_bykey{$key} = $latex;
1.1088 foxr 208: $latex_language{$code} = $latex;
1.1048 foxr 209: }
1.158 raeburn 210: }
211: close($fh);
212: }
1.12 harris41 213: }
214: # ------------------------------------------------------------------ copyrights
215: {
1.158 raeburn 216: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
217: '/copyright.tab';
218: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 219: while (my $line = <$fh>) {
220: next if ($line=~/^\#/);
221: chomp($line);
222: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 223: $cprtag{$key}=$val;
224: }
225: close($fh);
226: }
1.12 harris41 227: }
1.351 www 228: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 229: {
230: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
231: '/source_copyright.tab';
232: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 233: while (my $line = <$fh>) {
234: next if ($line =~ /^\#/);
235: chomp($line);
236: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 237: $scprtag{$key}=$val;
238: }
239: close($fh);
240: }
241: }
1.63 www 242:
1.517 raeburn 243: # -------------------------------------------------------------- default domain designs
1.63 www 244: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 245: my $designfile = $designdir.'/default.tab';
246: if ( open (my $fh,"<$designfile") ) {
247: while (my $line = <$fh>) {
248: next if ($line =~ /^\#/);
249: chomp($line);
250: my ($key,$val)=(split(/\=/,$line));
251: if ($val) { $defaultdesign{$key}=$val; }
252: }
253: close($fh);
1.63 www 254: }
255:
1.15 harris41 256: # ------------------------------------------------------------- file categories
257: {
1.158 raeburn 258: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
259: '/filecategories.tab';
260: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 261: while (my $line = <$fh>) {
262: next if ($line =~ /^\#/);
263: chomp($line);
264: my ($extension,$category)=(split(/\s+/,$line,2));
1.158 raeburn 265: push @{$category_extensions{lc($category)}},$extension;
266: }
267: close($fh);
268: }
269:
1.15 harris41 270: }
1.12 harris41 271: # ------------------------------------------------------------------ file types
272: {
1.158 raeburn 273: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
274: '/filetypes.tab';
275: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 276: while (my $line = <$fh>) {
277: next if ($line =~ /^\#/);
278: chomp($line);
279: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 280: if ($descr ne '') {
281: $fe{$ending}=lc($emb);
282: $fd{$ending}=$descr;
1.351 www 283: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 284: }
285: }
286: close($fh);
287: }
1.12 harris41 288: }
1.22 www 289: &Apache::lonnet::logthis(
1.705 tempelho 290: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 291: $readit=1;
1.46 matthew 292: } # end of unless($readit)
1.32 matthew 293:
294: }
1.112 bowersj2 295:
1.42 matthew 296: ###############################################################
297: ## HTML and Javascript Helper Functions ##
298: ###############################################################
299:
300: =pod
301:
1.112 bowersj2 302: =head1 HTML and Javascript Functions
1.42 matthew 303:
1.112 bowersj2 304: =over 4
305:
1.648 raeburn 306: =item * &browser_and_searcher_javascript()
1.112 bowersj2 307:
308: X<browsing, javascript>X<searching, javascript>Returns a string
309: containing javascript with two functions, C<openbrowser> and
310: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
311: tags.
1.42 matthew 312:
1.648 raeburn 313: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 314:
315: inputs: formname, elementname, only, omit
316:
317: formname and elementname indicate the name of the html form and name of
318: the element that the results of the browsing selection are to be placed in.
319:
320: Specifying 'only' will restrict the browser to displaying only files
1.185 www 321: with the given extension. Can be a comma separated list.
1.42 matthew 322:
323: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 324: with the given extension. Can be a comma separated list.
1.42 matthew 325:
1.648 raeburn 326: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 327:
328: Inputs: formname, elementname
329:
330: formname and elementname specify the name of the html form and the name
331: of the element the selection from the search results will be placed in.
1.542 raeburn 332:
1.42 matthew 333: =cut
334:
335: sub browser_and_searcher_javascript {
1.199 albertel 336: my ($mode)=@_;
337: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 338: my $resurl=&escape_single(&lastresurl());
1.42 matthew 339: return <<END;
1.219 albertel 340: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 341: var editbrowser = null;
1.135 albertel 342: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 343: var url = '$resurl/?';
1.42 matthew 344: if (editbrowser == null) {
345: url += 'launch=1&';
346: }
347: url += 'catalogmode=interactive&';
1.199 albertel 348: url += 'mode=$mode&';
1.611 albertel 349: url += 'inhibitmenu=yes&';
1.42 matthew 350: url += 'form=' + formname + '&';
351: if (only != null) {
352: url += 'only=' + only + '&';
1.217 albertel 353: } else {
354: url += 'only=&';
355: }
1.42 matthew 356: if (omit != null) {
357: url += 'omit=' + omit + '&';
1.217 albertel 358: } else {
359: url += 'omit=&';
360: }
1.135 albertel 361: if (titleelement != null) {
362: url += 'titleelement=' + titleelement + '&';
1.217 albertel 363: } else {
364: url += 'titleelement=&';
365: }
1.42 matthew 366: url += 'element=' + elementname + '';
367: var title = 'Browser';
1.435 albertel 368: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 369: options += ',width=700,height=600';
370: editbrowser = open(url,title,options,'1');
371: editbrowser.focus();
372: }
373: var editsearcher;
1.135 albertel 374: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 375: var url = '/adm/searchcat?';
376: if (editsearcher == null) {
377: url += 'launch=1&';
378: }
379: url += 'catalogmode=interactive&';
1.199 albertel 380: url += 'mode=$mode&';
1.42 matthew 381: url += 'form=' + formname + '&';
1.135 albertel 382: if (titleelement != null) {
383: url += 'titleelement=' + titleelement + '&';
1.217 albertel 384: } else {
385: url += 'titleelement=&';
386: }
1.42 matthew 387: url += 'element=' + elementname + '';
388: var title = 'Search';
1.435 albertel 389: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 390: options += ',width=700,height=600';
391: editsearcher = open(url,title,options,'1');
392: editsearcher.focus();
393: }
1.219 albertel 394: // END LON-CAPA Internal -->
1.42 matthew 395: END
1.170 www 396: }
397:
398: sub lastresurl {
1.258 albertel 399: if ($env{'environment.lastresurl'}) {
400: return $env{'environment.lastresurl'}
1.170 www 401: } else {
402: return '/res';
403: }
404: }
405:
406: sub storeresurl {
407: my $resurl=&Apache::lonnet::clutter(shift);
408: unless ($resurl=~/^\/res/) { return 0; }
409: $resurl=~s/\/$//;
410: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 411: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 412: return 1;
1.42 matthew 413: }
414:
1.74 www 415: sub studentbrowser_javascript {
1.111 www 416: unless (
1.258 albertel 417: (($env{'request.course.id'}) &&
1.302 albertel 418: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
419: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
420: '/'.$env{'request.course.sec'})
421: ))
1.258 albertel 422: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 423: ) { return ''; }
1.74 www 424: return (<<'ENDSTDBRW');
1.776 bisitz 425: <script type="text/javascript" language="Javascript">
1.824 bisitz 426: // <![CDATA[
1.74 www 427: var stdeditbrowser;
1.999 www 428: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 429: var url = '/adm/pickstudent?';
430: var filter;
1.558 albertel 431: if (!ignorefilter) {
432: eval('filter=document.'+formname+'.'+uname+'.value;');
433: }
1.74 www 434: if (filter != null) {
435: if (filter != '') {
436: url += 'filter='+filter+'&';
437: }
438: }
439: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 440: '&udomelement='+udom+
441: '&clicker='+clicker;
1.111 www 442: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 443: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 444: var title = 'Student_Browser';
1.74 www 445: var options = 'scrollbars=1,resizable=1,menubar=0';
446: options += ',width=700,height=600';
447: stdeditbrowser = open(url,title,options,'1');
448: stdeditbrowser.focus();
449: }
1.824 bisitz 450: // ]]>
1.74 www 451: </script>
452: ENDSTDBRW
453: }
1.42 matthew 454:
1.1003 www 455: sub resourcebrowser_javascript {
456: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 457: return (<<'ENDRESBRW');
1.1003 www 458: <script type="text/javascript" language="Javascript">
459: // <![CDATA[
460: var reseditbrowser;
1.1004 www 461: function openresbrowser(formname,reslink) {
1.1005 www 462: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 463: var title = 'Resource_Browser';
464: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 465: options += ',width=700,height=500';
1.1004 www 466: reseditbrowser = open(url,title,options,'1');
467: reseditbrowser.focus();
1.1003 www 468: }
469: // ]]>
470: </script>
1.1004 www 471: ENDRESBRW
1.1003 www 472: }
473:
1.74 www 474: sub selectstudent_link {
1.999 www 475: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
476: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
477: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
478: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 479: if ($env{'request.course.id'}) {
1.302 albertel 480: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
481: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
482: '/'.$env{'request.course.sec'})) {
1.111 www 483: return '';
484: }
1.999 www 485: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 486: if ($courseadvonly) {
487: $callargs .= ",'',1,1";
488: }
489: return '<span class="LC_nobreak">'.
490: '<a href="javascript:openstdbrowser('.$callargs.');">'.
491: &mt('Select User').'</a></span>';
1.74 www 492: }
1.258 albertel 493: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 494: $callargs .= ",'',1";
1.793 raeburn 495: return '<span class="LC_nobreak">'.
496: '<a href="javascript:openstdbrowser('.$callargs.');">'.
497: &mt('Select User').'</a></span>';
1.111 www 498: }
499: return '';
1.91 www 500: }
501:
1.1004 www 502: sub selectresource_link {
503: my ($form,$reslink,$arg)=@_;
504:
505: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
506: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
507: unless ($env{'request.course.id'}) { return $arg; }
508: return '<span class="LC_nobreak">'.
509: '<a href="javascript:openresbrowser('.$callargs.');">'.
510: $arg.'</a></span>';
511: }
512:
513:
514:
1.653 raeburn 515: sub authorbrowser_javascript {
516: return <<"ENDAUTHORBRW";
1.776 bisitz 517: <script type="text/javascript" language="JavaScript">
1.824 bisitz 518: // <![CDATA[
1.653 raeburn 519: var stdeditbrowser;
520:
521: function openauthorbrowser(formname,udom) {
522: var url = '/adm/pickauthor?';
523: url += 'form='+formname+'&roledom='+udom;
524: var title = 'Author_Browser';
525: var options = 'scrollbars=1,resizable=1,menubar=0';
526: options += ',width=700,height=600';
527: stdeditbrowser = open(url,title,options,'1');
528: stdeditbrowser.focus();
529: }
530:
1.824 bisitz 531: // ]]>
1.653 raeburn 532: </script>
533: ENDAUTHORBRW
534: }
535:
1.91 www 536: sub coursebrowser_javascript {
1.1116 raeburn 537: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
538: $credits_element) = @_;
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;
588: url += '&cloner='+ownername+':'+ownerdom;
589: }
1.293 raeburn 590: if (multflag !=null && multflag != '') {
591: url += '&multiple='+multflag;
592: }
1.909 raeburn 593: var title = '$wintitle';
1.91 www 594: var options = 'scrollbars=1,resizable=1,menubar=0';
595: options += ',width=700,height=600';
596: stdeditbrowser = open(url,title,options,'1');
597: stdeditbrowser.focus();
598: }
1.876 raeburn 599: $id_functions
600: ENDSTDBRW
1.1116 raeburn 601: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
602: $output .= &setsec_javascript($sec_element,$formname,$role_element,
603: $credits_element);
1.876 raeburn 604: }
605: $output .= '
606: // ]]>
607: </script>';
608: return $output;
609: }
610:
611: sub javascript_index_functions {
612: return <<"ENDJS";
613:
614: function getFormIdByName(formname) {
615: for (var i=0;i<document.forms.length;i++) {
616: if (document.forms[i].name == formname) {
617: return i;
618: }
619: }
620: return -1;
621: }
622:
623: function getIndexByName(formid,item) {
624: for (var i=0;i<document.forms[formid].elements.length;i++) {
625: if (document.forms[formid].elements[i].name == item) {
626: return i;
627: }
628: }
629: return -1;
630: }
1.468 raeburn 631:
1.876 raeburn 632: function getDomainFromSelectbox(formname,udom) {
633: var userdom;
634: var formid = getFormIdByName(formname);
635: if (formid > -1) {
636: var domid = getIndexByName(formid,udom);
637: if (domid > -1) {
638: if (document.forms[formid].elements[domid].type == 'select-one') {
639: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
640: }
641: if (document.forms[formid].elements[domid].type == 'hidden') {
642: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 643: }
644: }
645: }
1.876 raeburn 646: return userdom;
647: }
648:
649: ENDJS
1.468 raeburn 650:
1.876 raeburn 651: }
652:
1.1017 raeburn 653: sub javascript_array_indexof {
1.1018 raeburn 654: return <<ENDJS;
1.1017 raeburn 655: <script type="text/javascript" language="JavaScript">
656: // <![CDATA[
657:
658: if (!Array.prototype.indexOf) {
659: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
660: "use strict";
661: if (this === void 0 || this === null) {
662: throw new TypeError();
663: }
664: var t = Object(this);
665: var len = t.length >>> 0;
666: if (len === 0) {
667: return -1;
668: }
669: var n = 0;
670: if (arguments.length > 0) {
671: n = Number(arguments[1]);
1.1088 foxr 672: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 673: n = 0;
674: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
675: n = (n > 0 || -1) * Math.floor(Math.abs(n));
676: }
677: }
678: if (n >= len) {
679: return -1;
680: }
681: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
682: for (; k < len; k++) {
683: if (k in t && t[k] === searchElement) {
684: return k;
685: }
686: }
687: return -1;
688: }
689: }
690:
691: // ]]>
692: </script>
693:
694: ENDJS
695:
696: }
697:
1.876 raeburn 698: sub userbrowser_javascript {
699: my $id_functions = &javascript_index_functions();
700: return <<"ENDUSERBRW";
701:
1.888 raeburn 702: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 703: var url = '/adm/pickuser?';
704: var userdom = getDomainFromSelectbox(formname,udom);
705: if (userdom != null) {
706: if (userdom != '') {
707: url += 'srchdom='+userdom+'&';
708: }
709: }
710: url += 'form=' + formname + '&unameelement='+uname+
711: '&udomelement='+udom+
712: '&ulastelement='+ulast+
713: '&ufirstelement='+ufirst+
714: '&uemailelement='+uemail+
1.881 raeburn 715: '&hideudomelement='+hideudom+
716: '&coursedom='+crsdom;
1.888 raeburn 717: if ((caller != null) && (caller != undefined)) {
718: url += '&caller='+caller;
719: }
1.876 raeburn 720: var title = 'User_Browser';
721: var options = 'scrollbars=1,resizable=1,menubar=0';
722: options += ',width=700,height=600';
723: var stdeditbrowser = open(url,title,options,'1');
724: stdeditbrowser.focus();
725: }
726:
1.888 raeburn 727: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 728: var formid = getFormIdByName(formname);
729: if (formid > -1) {
1.888 raeburn 730: var unameid = getIndexByName(formid,uname);
1.876 raeburn 731: var domid = getIndexByName(formid,udom);
732: var hidedomid = getIndexByName(formid,origdom);
733: if (hidedomid > -1) {
734: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 735: var unameval = document.forms[formid].elements[unameid].value;
736: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
737: if (domid > -1) {
738: var slct = document.forms[formid].elements[domid];
739: if (slct.type == 'select-one') {
740: var i;
741: for (i=0;i<slct.length;i++) {
742: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
743: }
744: }
745: if (slct.type == 'hidden') {
746: slct.value = fixeddom;
1.876 raeburn 747: }
748: }
1.468 raeburn 749: }
750: }
751: }
1.876 raeburn 752: return;
753: }
754:
755: $id_functions
756: ENDUSERBRW
1.468 raeburn 757: }
758:
759: sub setsec_javascript {
1.1116 raeburn 760: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 761: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
762: $communityrolestr);
763: if ($role_element ne '') {
764: my @allroles = ('st','ta','ep','in','ad');
765: foreach my $crstype ('Course','Community') {
766: if ($crstype eq 'Community') {
767: foreach my $role (@allroles) {
768: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
769: }
770: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
771: } else {
772: foreach my $role (@allroles) {
773: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
774: }
775: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
776: }
777: }
778: $rolestr = '"'.join('","',@allroles).'"';
779: $courserolestr = '"'.join('","',@courserolenames).'"';
780: $communityrolestr = '"'.join('","',@communityrolenames).'"';
781: }
1.468 raeburn 782: my $setsections = qq|
783: function setSect(sectionlist) {
1.629 raeburn 784: var sectionsArray = new Array();
785: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
786: sectionsArray = sectionlist.split(",");
787: }
1.468 raeburn 788: var numSections = sectionsArray.length;
789: document.$formname.$sec_element.length = 0;
790: if (numSections == 0) {
791: document.$formname.$sec_element.multiple=false;
792: document.$formname.$sec_element.size=1;
793: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
794: } else {
795: if (numSections == 1) {
796: document.$formname.$sec_element.multiple=false;
797: document.$formname.$sec_element.size=1;
798: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
799: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
800: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
801: } else {
802: for (var i=0; i<numSections; i++) {
803: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
804: }
805: document.$formname.$sec_element.multiple=true
806: if (numSections < 3) {
807: document.$formname.$sec_element.size=numSections;
808: } else {
809: document.$formname.$sec_element.size=3;
810: }
811: document.$formname.$sec_element.options[0].selected = false
812: }
813: }
1.91 www 814: }
1.905 raeburn 815:
816: function setRole(crstype) {
1.468 raeburn 817: |;
1.905 raeburn 818: if ($role_element eq '') {
819: $setsections .= ' return;
820: }
821: ';
822: } else {
823: $setsections .= qq|
824: var elementLength = document.$formname.$role_element.length;
825: var allroles = Array($rolestr);
826: var courserolenames = Array($courserolestr);
827: var communityrolenames = Array($communityrolestr);
828: if (elementLength != undefined) {
829: if (document.$formname.$role_element.options[5].value == 'cc') {
830: if (crstype == 'Course') {
831: return;
832: } else {
833: allroles[5] = 'co';
834: for (var i=0; i<6; i++) {
835: document.$formname.$role_element.options[i].value = allroles[i];
836: document.$formname.$role_element.options[i].text = communityrolenames[i];
837: }
838: }
839: } else {
840: if (crstype == 'Community') {
841: return;
842: } else {
843: allroles[5] = 'cc';
844: for (var i=0; i<6; i++) {
845: document.$formname.$role_element.options[i].value = allroles[i];
846: document.$formname.$role_element.options[i].text = courserolenames[i];
847: }
848: }
849: }
850: }
851: return;
852: }
853: |;
854: }
1.1116 raeburn 855: if ($credits_element) {
856: $setsections .= qq|
857: function setCredits(defaultcredits) {
858: document.$formname.$credits_element.value = defaultcredits;
859: return;
860: }
861: |;
862: }
1.468 raeburn 863: return $setsections;
864: }
865:
1.91 www 866: sub selectcourse_link {
1.909 raeburn 867: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
868: $typeelement) = @_;
869: my $type = $selecttype;
1.871 raeburn 870: my $linktext = &mt('Select Course');
871: if ($selecttype eq 'Community') {
1.909 raeburn 872: $linktext = &mt('Select Community');
1.906 raeburn 873: } elsif ($selecttype eq 'Course/Community') {
874: $linktext = &mt('Select Course/Community');
1.909 raeburn 875: $type = '';
1.1019 raeburn 876: } elsif ($selecttype eq 'Select') {
877: $linktext = &mt('Select');
878: $type = '';
1.871 raeburn 879: }
1.787 bisitz 880: return '<span class="LC_nobreak">'
881: ."<a href='"
882: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
883: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 884: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 885: ."'>".$linktext.'</a>'
1.787 bisitz 886: .'</span>';
1.74 www 887: }
1.42 matthew 888:
1.653 raeburn 889: sub selectauthor_link {
890: my ($form,$udom)=@_;
891: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
892: &mt('Select Author').'</a>';
893: }
894:
1.876 raeburn 895: sub selectuser_link {
1.881 raeburn 896: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 897: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 898: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 899: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 900: ');">'.$linktext.'</a>';
1.876 raeburn 901: }
902:
1.273 raeburn 903: sub check_uncheck_jscript {
904: my $jscript = <<"ENDSCRT";
905: function checkAll(field) {
906: if (field.length > 0) {
907: for (i = 0; i < field.length; i++) {
1.1093 raeburn 908: if (!field[i].disabled) {
909: field[i].checked = true;
910: }
1.273 raeburn 911: }
912: } else {
1.1093 raeburn 913: if (!field.disabled) {
914: field.checked = true;
915: }
1.273 raeburn 916: }
917: }
918:
919: function uncheckAll(field) {
920: if (field.length > 0) {
921: for (i = 0; i < field.length; i++) {
922: field[i].checked = false ;
1.543 albertel 923: }
924: } else {
1.273 raeburn 925: field.checked = false ;
926: }
927: }
928: ENDSCRT
929: return $jscript;
930: }
931:
1.656 www 932: sub select_timezone {
1.659 raeburn 933: my ($name,$selected,$onchange,$includeempty)=@_;
934: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
935: if ($includeempty) {
936: $output .= '<option value=""';
937: if (($selected eq '') || ($selected eq 'local')) {
938: $output .= ' selected="selected" ';
939: }
940: $output .= '> </option>';
941: }
1.657 raeburn 942: my @timezones = DateTime::TimeZone->all_names;
943: foreach my $tzone (@timezones) {
944: $output.= '<option value="'.$tzone.'"';
945: if ($tzone eq $selected) {
946: $output.=' selected="selected"';
947: }
948: $output.=">$tzone</option>\n";
1.656 www 949: }
950: $output.="</select>";
951: return $output;
952: }
1.273 raeburn 953:
1.687 raeburn 954: sub select_datelocale {
955: my ($name,$selected,$onchange,$includeempty)=@_;
956: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
957: if ($includeempty) {
958: $output .= '<option value=""';
959: if ($selected eq '') {
960: $output .= ' selected="selected" ';
961: }
962: $output .= '> </option>';
963: }
964: my (@possibles,%locale_names);
965: my @locales = DateTime::Locale::Catalog::Locales;
966: foreach my $locale (@locales) {
967: if (ref($locale) eq 'HASH') {
968: my $id = $locale->{'id'};
969: if ($id ne '') {
970: my $en_terr = $locale->{'en_territory'};
971: my $native_terr = $locale->{'native_territory'};
1.695 raeburn 972: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 973: if (grep(/^en$/,@languages) || !@languages) {
974: if ($en_terr ne '') {
975: $locale_names{$id} = '('.$en_terr.')';
976: } elsif ($native_terr ne '') {
977: $locale_names{$id} = $native_terr;
978: }
979: } else {
980: if ($native_terr ne '') {
981: $locale_names{$id} = $native_terr.' ';
982: } elsif ($en_terr ne '') {
983: $locale_names{$id} = '('.$en_terr.')';
984: }
985: }
986: push (@possibles,$id);
987: }
988: }
989: }
990: foreach my $item (sort(@possibles)) {
991: $output.= '<option value="'.$item.'"';
992: if ($item eq $selected) {
993: $output.=' selected="selected"';
994: }
995: $output.=">$item";
996: if ($locale_names{$item} ne '') {
997: $output.=" $locale_names{$item}</option>\n";
998: }
999: $output.="</option>\n";
1000: }
1001: $output.="</select>";
1002: return $output;
1003: }
1004:
1.792 raeburn 1005: sub select_language {
1006: my ($name,$selected,$includeempty) = @_;
1007: my %langchoices;
1008: if ($includeempty) {
1.1117 raeburn 1009: %langchoices = ('' => 'No language preference');
1.792 raeburn 1010: }
1011: foreach my $id (&languageids()) {
1012: my $code = &supportedlanguagecode($id);
1013: if ($code) {
1014: $langchoices{$code} = &plainlanguagedescription($id);
1015: }
1016: }
1.1117 raeburn 1017: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.970 raeburn 1018: return &select_form($selected,$name,\%langchoices);
1.792 raeburn 1019: }
1020:
1.42 matthew 1021: =pod
1.36 matthew 1022:
1.1088 foxr 1023:
1024: =item * &list_languages()
1025:
1026: Returns an array reference that is suitable for use in language prompters.
1027: Each array element is itself a two element array. The first element
1028: is the language code. The second element a descsriptiuon of the
1029: language itself. This is suitable for use in e.g.
1030: &Apache::edit::select_arg (once dereferenced that is).
1031:
1032: =cut
1033:
1034: sub list_languages {
1035: my @lang_choices;
1036:
1037: foreach my $id (&languageids()) {
1038: my $code = &supportedlanguagecode($id);
1039: if ($code) {
1040: my $selector = $supported_codes{$id};
1041: my $description = &plainlanguagedescription($id);
1042: push (@lang_choices, [$selector, $description]);
1043: }
1044: }
1045: return \@lang_choices;
1046: }
1047:
1048: =pod
1049:
1.648 raeburn 1050: =item * &linked_select_forms(...)
1.36 matthew 1051:
1052: linked_select_forms returns a string containing a <script></script> block
1053: and html for two <select> menus. The select menus will be linked in that
1054: changing the value of the first menu will result in new values being placed
1055: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1056: order unless a defined order is provided.
1.36 matthew 1057:
1058: linked_select_forms takes the following ordered inputs:
1059:
1060: =over 4
1061:
1.112 bowersj2 1062: =item * $formname, the name of the <form> tag
1.36 matthew 1063:
1.112 bowersj2 1064: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1065:
1.112 bowersj2 1066: =item * $firstdefault, the default value for the first menu
1.36 matthew 1067:
1.112 bowersj2 1068: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1069:
1.112 bowersj2 1070: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1071:
1.112 bowersj2 1072: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1073:
1.609 raeburn 1074: =item * $menuorder, the order of values in the first menu
1075:
1.1115 raeburn 1076: =item * $onchangefirst, additional javascript call to execute for an onchange
1077: event for the first <select> tag
1078:
1079: =item * $onchangesecond, additional javascript call to execute for an onchange
1080: event for the second <select> tag
1081:
1.41 ng 1082: =back
1083:
1.36 matthew 1084: Below is an example of such a hash. Only the 'text', 'default', and
1085: 'select2' keys must appear as stated. keys(%menu) are the possible
1086: values for the first select menu. The text that coincides with the
1.41 ng 1087: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1088: and text for the second menu are given in the hash pointed to by
1089: $menu{$choice1}->{'select2'}.
1090:
1.112 bowersj2 1091: my %menu = ( A1 => { text =>"Choice A1" ,
1092: default => "B3",
1093: select2 => {
1094: B1 => "Choice B1",
1095: B2 => "Choice B2",
1096: B3 => "Choice B3",
1097: B4 => "Choice B4"
1.609 raeburn 1098: },
1099: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1100: },
1101: A2 => { text =>"Choice A2" ,
1102: default => "C2",
1103: select2 => {
1104: C1 => "Choice C1",
1105: C2 => "Choice C2",
1106: C3 => "Choice C3"
1.609 raeburn 1107: },
1108: order => ['C2','C1','C3'],
1.112 bowersj2 1109: },
1110: A3 => { text =>"Choice A3" ,
1111: default => "D6",
1112: select2 => {
1113: D1 => "Choice D1",
1114: D2 => "Choice D2",
1115: D3 => "Choice D3",
1116: D4 => "Choice D4",
1117: D5 => "Choice D5",
1118: D6 => "Choice D6",
1119: D7 => "Choice D7"
1.609 raeburn 1120: },
1121: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1122: }
1123: );
1.36 matthew 1124:
1125: =cut
1126:
1127: sub linked_select_forms {
1128: my ($formname,
1129: $middletext,
1130: $firstdefault,
1131: $firstselectname,
1132: $secondselectname,
1.609 raeburn 1133: $hashref,
1134: $menuorder,
1.1115 raeburn 1135: $onchangefirst,
1136: $onchangesecond
1.36 matthew 1137: ) = @_;
1138: my $second = "document.$formname.$secondselectname";
1139: my $first = "document.$formname.$firstselectname";
1140: # output the javascript to do the changing
1141: my $result = '';
1.776 bisitz 1142: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1143: $result.="// <![CDATA[\n";
1.36 matthew 1144: $result.="var select2data = new Object();\n";
1145: $" = '","';
1146: my $debug = '';
1147: foreach my $s1 (sort(keys(%$hashref))) {
1148: $result.="select2data.d_$s1 = new Object();\n";
1149: $result.="select2data.d_$s1.def = new String('".
1150: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1151: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1152: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1153: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1154: @s2values = @{$hashref->{$s1}->{'order'}};
1155: }
1.36 matthew 1156: $result.="\"@s2values\");\n";
1157: $result.="select2data.d_$s1.texts = new Array(";
1158: my @s2texts;
1159: foreach my $value (@s2values) {
1160: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1161: }
1162: $result.="\"@s2texts\");\n";
1163: }
1164: $"=' ';
1165: $result.= <<"END";
1166:
1167: function select1_changed() {
1168: // Determine new choice
1169: var newvalue = "d_" + $first.value;
1170: // update select2
1171: var values = select2data[newvalue].values;
1172: var texts = select2data[newvalue].texts;
1173: var select2def = select2data[newvalue].def;
1174: var i;
1175: // out with the old
1176: for (i = 0; i < $second.options.length; i++) {
1177: $second.options[i] = null;
1178: }
1179: // in with the nuclear
1180: for (i=0;i<values.length; i++) {
1181: $second.options[i] = new Option(values[i]);
1.143 matthew 1182: $second.options[i].value = values[i];
1.36 matthew 1183: $second.options[i].text = texts[i];
1184: if (values[i] == select2def) {
1185: $second.options[i].selected = true;
1186: }
1187: }
1188: }
1.824 bisitz 1189: // ]]>
1.36 matthew 1190: </script>
1191: END
1192: # output the initial values for the selection lists
1.1115 raeburn 1193: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1194: my @order = sort(keys(%{$hashref}));
1195: if (ref($menuorder) eq 'ARRAY') {
1196: @order = @{$menuorder};
1197: }
1198: foreach my $value (@order) {
1.36 matthew 1199: $result.=" <option value=\"$value\" ";
1.253 albertel 1200: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1201: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1202: }
1203: $result .= "</select>\n";
1204: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1205: $result .= $middletext;
1.1115 raeburn 1206: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1207: if ($onchangesecond) {
1208: $result .= ' onchange="'.$onchangesecond.'"';
1209: }
1210: $result .= ">\n";
1.36 matthew 1211: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1212:
1213: my @secondorder = sort(keys(%select2));
1214: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1215: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1216: }
1217: foreach my $value (@secondorder) {
1.36 matthew 1218: $result.=" <option value=\"$value\" ";
1.253 albertel 1219: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1220: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1221: }
1222: $result .= "</select>\n";
1223: # return $debug;
1224: return $result;
1225: } # end of sub linked_select_forms {
1226:
1.45 matthew 1227: =pod
1.44 bowersj2 1228:
1.973 raeburn 1229: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1230:
1.112 bowersj2 1231: Returns a string corresponding to an HTML link to the given help
1232: $topic, where $topic corresponds to the name of a .tex file in
1233: /home/httpd/html/adm/help/tex, with underscores replaced by
1234: spaces.
1235:
1236: $text will optionally be linked to the same topic, allowing you to
1237: link text in addition to the graphic. If you do not want to link
1238: text, but wish to specify one of the later parameters, pass an
1239: empty string.
1240:
1241: $stayOnPage is a value that will be interpreted as a boolean. If true,
1242: the link will not open a new window. If false, the link will open
1243: a new window using Javascript. (Default is false.)
1244:
1245: $width and $height are optional numerical parameters that will
1246: override the width and height of the popped up window, which may
1.973 raeburn 1247: be useful for certain help topics with big pictures included.
1248:
1249: $imgid is the id of the img tag used for the help icon. This may be
1250: used in a javascript call to switch the image src. See
1251: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1252:
1253: =cut
1254:
1255: sub help_open_topic {
1.973 raeburn 1256: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1257: $text = "" if (not defined $text);
1.44 bowersj2 1258: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1259: $width = 500 if (not defined $width);
1.44 bowersj2 1260: $height = 400 if (not defined $height);
1261: my $filename = $topic;
1262: $filename =~ s/ /_/g;
1263:
1.48 bowersj2 1264: my $template = "";
1265: my $link;
1.572 banghart 1266:
1.159 www 1267: $topic=~s/\W/\_/g;
1.44 bowersj2 1268:
1.572 banghart 1269: if (!$stayOnPage) {
1.1033 www 1270: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1271: } elsif ($stayOnPage eq 'popup') {
1272: $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 1273: } else {
1.48 bowersj2 1274: $link = "/adm/help/${filename}.hlp";
1275: }
1276:
1277: # Add the text
1.755 neumanie 1278: if ($text ne "") {
1.763 bisitz 1279: $template.='<span class="LC_help_open_topic">'
1280: .'<a target="_top" href="'.$link.'">'
1281: .$text.'</a>';
1.48 bowersj2 1282: }
1283:
1.763 bisitz 1284: # (Always) Add the graphic
1.179 matthew 1285: my $title = &mt('Online Help');
1.667 raeburn 1286: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1287: if ($imgid ne '') {
1288: $imgid = ' id="'.$imgid.'"';
1289: }
1.763 bisitz 1290: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1291: .'<img src="'.$helpicon.'" border="0"'
1292: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1293: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1294: .' /></a>';
1295: if ($text ne "") {
1296: $template.='</span>';
1297: }
1.44 bowersj2 1298: return $template;
1299:
1.106 bowersj2 1300: }
1301:
1302: # This is a quicky function for Latex cheatsheet editing, since it
1303: # appears in at least four places
1304: sub helpLatexCheatsheet {
1.1037 www 1305: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1306: my $out;
1.106 bowersj2 1307: my $addOther = '';
1.732 raeburn 1308: if ($topic) {
1.1037 www 1309: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1310: }
1311: $out = '<span>' # Start cheatsheet
1312: .$addOther
1313: .'<span>'
1.1037 www 1314: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1315: .'</span> <span>'
1.1037 www 1316: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1317: .'</span>';
1.732 raeburn 1318: unless ($not_author) {
1.1186 kruse 1319: $out .= '<span>'
1320: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1321: .'</span> <span>'
1322: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1323: .'</span>';
1.732 raeburn 1324: }
1.763 bisitz 1325: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1326: return $out;
1.172 www 1327: }
1328:
1.430 albertel 1329: sub general_help {
1330: my $helptopic='Student_Intro';
1331: if ($env{'request.role'}=~/^(ca|au)/) {
1332: $helptopic='Authoring_Intro';
1.907 raeburn 1333: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1334: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1335: } elsif ($env{'request.role'}=~/^dc/) {
1336: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1337: }
1338: return $helptopic;
1339: }
1340:
1341: sub update_help_link {
1342: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1343: my $origurl = $ENV{'REQUEST_URI'};
1344: $origurl=~s|^/~|/priv/|;
1345: my $timestamp = time;
1346: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1347: $$datum = &escape($$datum);
1348: }
1349:
1350: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1351: my $output .= <<"ENDOUTPUT";
1352: <script type="text/javascript">
1.824 bisitz 1353: // <![CDATA[
1.430 albertel 1354: banner_link = '$banner_link';
1.824 bisitz 1355: // ]]>
1.430 albertel 1356: </script>
1357: ENDOUTPUT
1358: return $output;
1359: }
1360:
1361: # now just updates the help link and generates a blue icon
1.193 raeburn 1362: sub help_open_menu {
1.430 albertel 1363: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1364: = @_;
1.949 droeschl 1365: $stayOnPage = 1;
1.430 albertel 1366: my $output;
1367: if ($component_help) {
1368: if (!$text) {
1369: $output=&help_open_topic($component_help,undef,$stayOnPage,
1370: $width,$height);
1371: } else {
1372: my $help_text;
1373: $help_text=&unescape($topic);
1374: $output='<table><tr><td>'.
1375: &help_open_topic($component_help,$help_text,$stayOnPage,
1376: $width,$height).'</td></tr></table>';
1377: }
1378: }
1379: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1380: return $output.$banner_link;
1381: }
1382:
1383: sub top_nav_help {
1384: my ($text) = @_;
1.436 albertel 1385: $text = &mt($text);
1.949 droeschl 1386: my $stay_on_page = 1;
1387:
1.1168 raeburn 1388: my ($link,$banner_link);
1389: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1390: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1391: : "javascript:helpMenu('open')";
1392: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1393: }
1.201 raeburn 1394: my $title = &mt('Get help');
1.1168 raeburn 1395: if ($link) {
1396: return <<"END";
1.436 albertel 1397: $banner_link
1.1159 raeburn 1398: <a href="$link" title="$title">$text</a>
1.436 albertel 1399: END
1.1168 raeburn 1400: } else {
1401: return ' '.$text.' ';
1402: }
1.436 albertel 1403: }
1404:
1405: sub help_menu_js {
1.1154 raeburn 1406: my ($httphost) = @_;
1.949 droeschl 1407: my $stayOnPage = 1;
1.436 albertel 1408: my $width = 620;
1409: my $height = 600;
1.430 albertel 1410: my $helptopic=&general_help();
1.1154 raeburn 1411: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1412: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1413: my $start_page =
1414: &Apache::loncommon::start_page('Help Menu', undef,
1415: {'frameset' => 1,
1416: 'js_ready' => 1,
1.1154 raeburn 1417: 'use_absolute' => $httphost,
1.331 albertel 1418: 'add_entries' => {
1.1168 raeburn 1419: 'border' => '0',
1.579 raeburn 1420: 'rows' => "110,*",},});
1.331 albertel 1421: my $end_page =
1422: &Apache::loncommon::end_page({'frameset' => 1,
1423: 'js_ready' => 1,});
1424:
1.436 albertel 1425: my $template .= <<"ENDTEMPLATE";
1426: <script type="text/javascript">
1.877 bisitz 1427: // <![CDATA[
1.253 albertel 1428: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1429: var banner_link = '';
1.243 raeburn 1430: function helpMenu(target) {
1431: var caller = this;
1432: if (target == 'open') {
1433: var newWindow = null;
1434: try {
1.262 albertel 1435: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1436: }
1437: catch(error) {
1438: writeHelp(caller);
1439: return;
1440: }
1441: if (newWindow) {
1442: caller = newWindow;
1443: }
1.193 raeburn 1444: }
1.243 raeburn 1445: writeHelp(caller);
1446: return;
1447: }
1448: function writeHelp(caller) {
1.1168 raeburn 1449: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1450: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1451: caller.document.close();
1452: caller.focus();
1.193 raeburn 1453: }
1.877 bisitz 1454: // END LON-CAPA Internal -->
1.253 albertel 1455: // ]]>
1.436 albertel 1456: </script>
1.193 raeburn 1457: ENDTEMPLATE
1458: return $template;
1459: }
1460:
1.172 www 1461: sub help_open_bug {
1462: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1463: unless ($env{'user.adv'}) { return ''; }
1.172 www 1464: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1465: $text = "" if (not defined $text);
1466: $stayOnPage=1;
1.184 albertel 1467: $width = 600 if (not defined $width);
1468: $height = 600 if (not defined $height);
1.172 www 1469:
1470: $topic=~s/\W+/\+/g;
1471: my $link='';
1472: my $template='';
1.379 albertel 1473: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1474: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1475: if (!$stayOnPage)
1476: {
1477: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1478: }
1479: else
1480: {
1481: $link = $url;
1482: }
1483: # Add the text
1484: if ($text ne "")
1485: {
1486: $template .=
1487: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1488: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1489: }
1490:
1491: # Add the graphic
1.179 matthew 1492: my $title = &mt('Report a Bug');
1.215 albertel 1493: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1494: $template .= <<"ENDTEMPLATE";
1.436 albertel 1495: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1496: ENDTEMPLATE
1497: if ($text ne '') { $template.='</td></tr></table>' };
1498: return $template;
1499:
1500: }
1501:
1502: sub help_open_faq {
1503: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1504: unless ($env{'user.adv'}) { return ''; }
1.172 www 1505: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1506: $text = "" if (not defined $text);
1507: $stayOnPage=1;
1508: $width = 350 if (not defined $width);
1509: $height = 400 if (not defined $height);
1510:
1511: $topic=~s/\W+/\+/g;
1512: my $link='';
1513: my $template='';
1514: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1515: if (!$stayOnPage)
1516: {
1517: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1518: }
1519: else
1520: {
1521: $link = $url;
1522: }
1523:
1524: # Add the text
1525: if ($text ne "")
1526: {
1527: $template .=
1.173 www 1528: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1529: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1530: }
1531:
1532: # Add the graphic
1.179 matthew 1533: my $title = &mt('View the FAQ');
1.215 albertel 1534: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1535: $template .= <<"ENDTEMPLATE";
1.436 albertel 1536: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1537: ENDTEMPLATE
1538: if ($text ne '') { $template.='</td></tr></table>' };
1539: return $template;
1540:
1.44 bowersj2 1541: }
1.37 matthew 1542:
1.180 matthew 1543: ###############################################################
1544: ###############################################################
1545:
1.45 matthew 1546: =pod
1547:
1.648 raeburn 1548: =item * &change_content_javascript():
1.256 matthew 1549:
1550: This and the next function allow you to create small sections of an
1551: otherwise static HTML page that you can update on the fly with
1552: Javascript, even in Netscape 4.
1553:
1554: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1555: must be written to the HTML page once. It will prove the Javascript
1556: function "change(name, content)". Calling the change function with the
1557: name of the section
1558: you want to update, matching the name passed to C<changable_area>, and
1559: the new content you want to put in there, will put the content into
1560: that area.
1561:
1562: B<Note>: Netscape 4 only reserves enough space for the changable area
1563: to contain room for the original contents. You need to "make space"
1564: for whatever changes you wish to make, and be B<sure> to check your
1565: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1566: it's adequate for updating a one-line status display, but little more.
1567: This script will set the space to 100% width, so you only need to
1568: worry about height in Netscape 4.
1569:
1570: Modern browsers are much less limiting, and if you can commit to the
1571: user not using Netscape 4, this feature may be used freely with
1572: pretty much any HTML.
1573:
1574: =cut
1575:
1576: sub change_content_javascript {
1577: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1578: if ($env{'browser.type'} eq 'netscape' &&
1579: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1580: return (<<NETSCAPE4);
1581: function change(name, content) {
1582: doc = document.layers[name+"___escape"].layers[0].document;
1583: doc.open();
1584: doc.write(content);
1585: doc.close();
1586: }
1587: NETSCAPE4
1588: } else {
1589: # Otherwise, we need to use semi-standards-compliant code
1590: # (technically, "innerHTML" isn't standard but the equivalent
1591: # is really scary, and every useful browser supports it
1592: return (<<DOMBASED);
1593: function change(name, content) {
1594: element = document.getElementById(name);
1595: element.innerHTML = content;
1596: }
1597: DOMBASED
1598: }
1599: }
1600:
1601: =pod
1602:
1.648 raeburn 1603: =item * &changable_area($name,$origContent):
1.256 matthew 1604:
1605: This provides a "changable area" that can be modified on the fly via
1606: the Javascript code provided in C<change_content_javascript>. $name is
1607: the name you will use to reference the area later; do not repeat the
1608: same name on a given HTML page more then once. $origContent is what
1609: the area will originally contain, which can be left blank.
1610:
1611: =cut
1612:
1613: sub changable_area {
1614: my ($name, $origContent) = @_;
1615:
1.258 albertel 1616: if ($env{'browser.type'} eq 'netscape' &&
1617: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1618: # If this is netscape 4, we need to use the Layer tag
1619: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1620: } else {
1621: return "<span id='$name'>$origContent</span>";
1622: }
1623: }
1624:
1625: =pod
1626:
1.648 raeburn 1627: =item * &viewport_geometry_js
1.590 raeburn 1628:
1629: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1630:
1631: =cut
1632:
1633:
1634: sub viewport_geometry_js {
1635: return <<"GEOMETRY";
1636: var Geometry = {};
1637: function init_geometry() {
1638: if (Geometry.init) { return };
1639: Geometry.init=1;
1640: if (window.innerHeight) {
1641: Geometry.getViewportHeight = function() { return window.innerHeight; };
1642: Geometry.getViewportWidth = function() { return window.innerWidth; };
1643: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1644: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1645: }
1646: else if (document.documentElement && document.documentElement.clientHeight) {
1647: Geometry.getViewportHeight =
1648: function() { return document.documentElement.clientHeight; };
1649: Geometry.getViewportWidth =
1650: function() { return document.documentElement.clientWidth; };
1651:
1652: Geometry.getHorizontalScroll =
1653: function() { return document.documentElement.scrollLeft; };
1654: Geometry.getVerticalScroll =
1655: function() { return document.documentElement.scrollTop; };
1656: }
1657: else if (document.body.clientHeight) {
1658: Geometry.getViewportHeight =
1659: function() { return document.body.clientHeight; };
1660: Geometry.getViewportWidth =
1661: function() { return document.body.clientWidth; };
1662: Geometry.getHorizontalScroll =
1663: function() { return document.body.scrollLeft; };
1664: Geometry.getVerticalScroll =
1665: function() { return document.body.scrollTop; };
1666: }
1667: }
1668:
1669: GEOMETRY
1670: }
1671:
1672: =pod
1673:
1.648 raeburn 1674: =item * &viewport_size_js()
1.590 raeburn 1675:
1676: 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.
1677:
1678: =cut
1679:
1680: sub viewport_size_js {
1681: my $geometry = &viewport_geometry_js();
1682: return <<"DIMS";
1683:
1684: $geometry
1685:
1686: function getViewportDims(width,height) {
1687: init_geometry();
1688: width.value = Geometry.getViewportWidth();
1689: height.value = Geometry.getViewportHeight();
1690: return;
1691: }
1692:
1693: DIMS
1694: }
1695:
1696: =pod
1697:
1.648 raeburn 1698: =item * &resize_textarea_js()
1.565 albertel 1699:
1700: emits the needed javascript to resize a textarea to be as big as possible
1701:
1702: creates a function resize_textrea that takes two IDs first should be
1703: the id of the element to resize, second should be the id of a div that
1704: surrounds everything that comes after the textarea, this routine needs
1705: to be attached to the <body> for the onload and onresize events.
1706:
1.648 raeburn 1707: =back
1.565 albertel 1708:
1709: =cut
1710:
1711: sub resize_textarea_js {
1.590 raeburn 1712: my $geometry = &viewport_geometry_js();
1.565 albertel 1713: return <<"RESIZE";
1714: <script type="text/javascript">
1.824 bisitz 1715: // <![CDATA[
1.590 raeburn 1716: $geometry
1.565 albertel 1717:
1.588 albertel 1718: function getX(element) {
1719: var x = 0;
1720: while (element) {
1721: x += element.offsetLeft;
1722: element = element.offsetParent;
1723: }
1724: return x;
1725: }
1726: function getY(element) {
1727: var y = 0;
1728: while (element) {
1729: y += element.offsetTop;
1730: element = element.offsetParent;
1731: }
1732: return y;
1733: }
1734:
1735:
1.565 albertel 1736: function resize_textarea(textarea_id,bottom_id) {
1737: init_geometry();
1738: var textarea = document.getElementById(textarea_id);
1739: //alert(textarea);
1740:
1.588 albertel 1741: var textarea_top = getY(textarea);
1.565 albertel 1742: var textarea_height = textarea.offsetHeight;
1743: var bottom = document.getElementById(bottom_id);
1.588 albertel 1744: var bottom_top = getY(bottom);
1.565 albertel 1745: var bottom_height = bottom.offsetHeight;
1746: var window_height = Geometry.getViewportHeight();
1.588 albertel 1747: var fudge = 23;
1.565 albertel 1748: var new_height = window_height-fudge-textarea_top-bottom_height;
1749: if (new_height < 300) {
1750: new_height = 300;
1751: }
1752: textarea.style.height=new_height+'px';
1753: }
1.824 bisitz 1754: // ]]>
1.565 albertel 1755: </script>
1756: RESIZE
1757:
1758: }
1759:
1760: =pod
1761:
1.256 matthew 1762: =head1 Excel and CSV file utility routines
1763:
1764: =cut
1765:
1766: ###############################################################
1767: ###############################################################
1768:
1769: =pod
1770:
1.1162 raeburn 1771: =over 4
1772:
1.648 raeburn 1773: =item * &csv_translate($text)
1.37 matthew 1774:
1.185 www 1775: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 1776: format.
1777:
1778: =cut
1779:
1.180 matthew 1780: ###############################################################
1781: ###############################################################
1.37 matthew 1782: sub csv_translate {
1783: my $text = shift;
1784: $text =~ s/\"/\"\"/g;
1.209 albertel 1785: $text =~ s/\n/ /g;
1.37 matthew 1786: return $text;
1787: }
1.180 matthew 1788:
1789: ###############################################################
1790: ###############################################################
1791:
1792: =pod
1793:
1.648 raeburn 1794: =item * &define_excel_formats()
1.180 matthew 1795:
1796: Define some commonly used Excel cell formats.
1797:
1798: Currently supported formats:
1799:
1800: =over 4
1801:
1802: =item header
1803:
1804: =item bold
1805:
1806: =item h1
1807:
1808: =item h2
1809:
1810: =item h3
1811:
1.256 matthew 1812: =item h4
1813:
1814: =item i
1815:
1.180 matthew 1816: =item date
1817:
1818: =back
1819:
1820: Inputs: $workbook
1821:
1822: Returns: $format, a hash reference.
1823:
1.1057 foxr 1824:
1.180 matthew 1825: =cut
1826:
1827: ###############################################################
1828: ###############################################################
1829: sub define_excel_formats {
1830: my ($workbook) = @_;
1831: my $format;
1832: $format->{'header'} = $workbook->add_format(bold => 1,
1833: bottom => 1,
1834: align => 'center');
1835: $format->{'bold'} = $workbook->add_format(bold=>1);
1836: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
1837: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
1838: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 1839: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 1840: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 1841: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 1842: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 1843: return $format;
1844: }
1845:
1846: ###############################################################
1847: ###############################################################
1.113 bowersj2 1848:
1849: =pod
1850:
1.648 raeburn 1851: =item * &create_workbook()
1.255 matthew 1852:
1853: Create an Excel worksheet. If it fails, output message on the
1854: request object and return undefs.
1855:
1856: Inputs: Apache request object
1857:
1858: Returns (undef) on failure,
1859: Excel worksheet object, scalar with filename, and formats
1860: from &Apache::loncommon::define_excel_formats on success
1861:
1862: =cut
1863:
1864: ###############################################################
1865: ###############################################################
1866: sub create_workbook {
1867: my ($r) = @_;
1868: #
1869: # Create the excel spreadsheet
1870: my $filename = '/prtspool/'.
1.258 albertel 1871: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 1872: time.'_'.rand(1000000000).'.xls';
1873: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
1874: if (! defined($workbook)) {
1875: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 1876: $r->print(
1877: '<p class="LC_error">'
1878: .&mt('Problems occurred in creating the new Excel file.')
1879: .' '.&mt('This error has been logged.')
1880: .' '.&mt('Please alert your LON-CAPA administrator.')
1881: .'</p>'
1882: );
1.255 matthew 1883: return (undef);
1884: }
1885: #
1.1014 foxr 1886: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 1887: #
1888: my $format = &Apache::loncommon::define_excel_formats($workbook);
1889: return ($workbook,$filename,$format);
1890: }
1891:
1892: ###############################################################
1893: ###############################################################
1894:
1895: =pod
1896:
1.648 raeburn 1897: =item * &create_text_file()
1.113 bowersj2 1898:
1.542 raeburn 1899: Create a file to write to and eventually make available to the user.
1.256 matthew 1900: If file creation fails, outputs an error message on the request object and
1901: return undefs.
1.113 bowersj2 1902:
1.256 matthew 1903: Inputs: Apache request object, and file suffix
1.113 bowersj2 1904:
1.256 matthew 1905: Returns (undef) on failure,
1906: Filehandle and filename on success.
1.113 bowersj2 1907:
1908: =cut
1909:
1.256 matthew 1910: ###############################################################
1911: ###############################################################
1912: sub create_text_file {
1913: my ($r,$suffix) = @_;
1914: if (! defined($suffix)) { $suffix = 'txt'; };
1915: my $fh;
1916: my $filename = '/prtspool/'.
1.258 albertel 1917: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 1918: time.'_'.rand(1000000000).'.'.$suffix;
1919: $fh = Apache::File->new('>/home/httpd'.$filename);
1920: if (! defined($fh)) {
1921: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 1922: $r->print(
1923: '<p class="LC_error">'
1924: .&mt('Problems occurred in creating the output file.')
1925: .' '.&mt('This error has been logged.')
1926: .' '.&mt('Please alert your LON-CAPA administrator.')
1927: .'</p>'
1928: );
1.113 bowersj2 1929: }
1.256 matthew 1930: return ($fh,$filename)
1.113 bowersj2 1931: }
1932:
1933:
1.256 matthew 1934: =pod
1.113 bowersj2 1935:
1936: =back
1937:
1938: =cut
1.37 matthew 1939:
1940: ###############################################################
1.33 matthew 1941: ## Home server <option> list generating code ##
1942: ###############################################################
1.35 matthew 1943:
1.169 www 1944: # ------------------------------------------
1945:
1946: sub domain_select {
1947: my ($name,$value,$multiple)=@_;
1948: my %domains=map {
1.514 albertel 1949: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 1950: } &Apache::lonnet::all_domains();
1.169 www 1951: if ($multiple) {
1952: $domains{''}=&mt('Any domain');
1.550 albertel 1953: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 1954: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 1955: } else {
1.550 albertel 1956: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 1957: return &select_form($name,$value,\%domains);
1.169 www 1958: }
1959: }
1960:
1.282 albertel 1961: #-------------------------------------------
1962:
1963: =pod
1964:
1.519 raeburn 1965: =head1 Routines for form select boxes
1966:
1967: =over 4
1968:
1.648 raeburn 1969: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 1970:
1971: Returns a string containing a <select> element int multiple mode
1972:
1973:
1974: Args:
1975: $name - name of the <select> element
1.506 raeburn 1976: $value - scalar or array ref of values that should already be selected
1.282 albertel 1977: $size - number of rows long the select element is
1.283 albertel 1978: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 1979: (shown text should already have been &mt())
1.506 raeburn 1980: $order - (optional) array ref of the order to show the elements in
1.283 albertel 1981:
1.282 albertel 1982: =cut
1983:
1984: #-------------------------------------------
1.169 www 1985: sub multiple_select_form {
1.284 albertel 1986: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 1987: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
1988: my $output='';
1.191 matthew 1989: if (! defined($size)) {
1990: $size = 4;
1.283 albertel 1991: if (scalar(keys(%$hash))<4) {
1992: $size = scalar(keys(%$hash));
1.191 matthew 1993: }
1994: }
1.734 bisitz 1995: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 1996: my @order;
1.506 raeburn 1997: if (ref($order) eq 'ARRAY') {
1998: @order = @{$order};
1999: } else {
2000: @order = sort(keys(%$hash));
1.501 banghart 2001: }
2002: if (exists($$hash{'select_form_order'})) {
2003: @order = @{$$hash{'select_form_order'}};
2004: }
2005:
1.284 albertel 2006: foreach my $key (@order) {
1.356 albertel 2007: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2008: $output.='selected="selected" ' if ($selected{$key});
2009: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2010: }
2011: $output.="</select>\n";
2012: return $output;
2013: }
2014:
1.88 www 2015: #-------------------------------------------
2016:
2017: =pod
2018:
1.970 raeburn 2019: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 2020:
2021: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2022: allow a user to select options from a ref to a hash containing:
2023: option_name => displayed text. An optional $onchange can include
2024: a javascript onchange item, e.g., onchange="this.form.submit();"
2025:
1.88 www 2026: See lonrights.pm for an example invocation and use.
2027:
2028: =cut
2029:
2030: #-------------------------------------------
2031: sub select_form {
1.970 raeburn 2032: my ($def,$name,$hashref,$onchange) = @_;
2033: return unless (ref($hashref) eq 'HASH');
2034: if ($onchange) {
2035: $onchange = ' onchange="'.$onchange.'"';
2036: }
2037: my $selectform = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.128 albertel 2038: my @keys;
1.970 raeburn 2039: if (exists($hashref->{'select_form_order'})) {
2040: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2041: } else {
1.970 raeburn 2042: @keys=sort(keys(%{$hashref}));
1.128 albertel 2043: }
1.356 albertel 2044: foreach my $key (@keys) {
2045: $selectform.=
2046: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2047: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2048: ">".$hashref->{$key}."</option>\n";
1.88 www 2049: }
2050: $selectform.="</select>";
2051: return $selectform;
2052: }
2053:
1.475 www 2054: # For display filters
2055:
2056: sub display_filter {
1.1074 raeburn 2057: my ($context) = @_;
1.475 www 2058: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2059: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2060: my $phraseinput = 'hidden';
2061: my $includeinput = 'hidden';
2062: my ($checked,$includetypestext);
2063: if ($env{'form.displayfilter'} eq 'containing') {
2064: $phraseinput = 'text';
2065: if ($context eq 'parmslog') {
2066: $includeinput = 'checkbox';
2067: if ($env{'form.includetypes'}) {
2068: $checked = ' checked="checked"';
2069: }
2070: $includetypestext = &mt('Include parameter types');
2071: }
2072: } else {
2073: $includetypestext = ' ';
2074: }
2075: my ($additional,$secondid,$thirdid);
2076: if ($context eq 'parmslog') {
2077: $additional =
2078: '<label><input type="'.$includeinput.'" name="includetypes"'.
2079: $checked.' name="includetypes" value="1" id="includetypes" />'.
2080: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2081: '</label>';
2082: $secondid = 'includetypes';
2083: $thirdid = 'includetypestext';
2084: }
2085: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2086: '$secondid','$thirdid')";
2087: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2088: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2089: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2090: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2091: &mt('Filter: [_1]',
1.477 www 2092: &select_form($env{'form.displayfilter'},
2093: 'displayfilter',
1.970 raeburn 2094: {'currentfolder' => 'Current folder/page',
1.477 www 2095: 'containing' => 'Containing phrase',
1.1074 raeburn 2096: 'none' => 'None'},$onchange)).' '.
2097: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2098: &HTML::Entities::encode($env{'form.containingphrase'}).
2099: '" />'.$additional;
2100: }
2101:
2102: sub display_filter_js {
2103: my $includetext = &mt('Include parameter types');
2104: return <<"ENDJS";
2105:
2106: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2107: var firstType = 'hidden';
2108: if (setter.options[setter.selectedIndex].value == 'containing') {
2109: firstType = 'text';
2110: }
2111: firstObject = document.getElementById(firstid);
2112: if (typeof(firstObject) == 'object') {
2113: if (firstObject.type != firstType) {
2114: changeInputType(firstObject,firstType);
2115: }
2116: }
2117: if (context == 'parmslog') {
2118: var secondType = 'hidden';
2119: if (firstType == 'text') {
2120: secondType = 'checkbox';
2121: }
2122: secondObject = document.getElementById(secondid);
2123: if (typeof(secondObject) == 'object') {
2124: if (secondObject.type != secondType) {
2125: changeInputType(secondObject,secondType);
2126: }
2127: }
2128: var textItem = document.getElementById(thirdid);
2129: var currtext = textItem.innerHTML;
2130: var newtext;
2131: if (firstType == 'text') {
2132: newtext = '$includetext';
2133: } else {
2134: newtext = ' ';
2135: }
2136: if (currtext != newtext) {
2137: textItem.innerHTML = newtext;
2138: }
2139: }
2140: return;
2141: }
2142:
2143: function changeInputType(oldObject,newType) {
2144: var newObject = document.createElement('input');
2145: newObject.type = newType;
2146: if (oldObject.size) {
2147: newObject.size = oldObject.size;
2148: }
2149: if (oldObject.value) {
2150: newObject.value = oldObject.value;
2151: }
2152: if (oldObject.name) {
2153: newObject.name = oldObject.name;
2154: }
2155: if (oldObject.id) {
2156: newObject.id = oldObject.id;
2157: }
2158: oldObject.parentNode.replaceChild(newObject,oldObject);
2159: return;
2160: }
2161:
2162: ENDJS
1.475 www 2163: }
2164:
1.167 www 2165: sub gradeleveldescription {
2166: my $gradelevel=shift;
2167: my %gradelevels=(0 => 'Not specified',
2168: 1 => 'Grade 1',
2169: 2 => 'Grade 2',
2170: 3 => 'Grade 3',
2171: 4 => 'Grade 4',
2172: 5 => 'Grade 5',
2173: 6 => 'Grade 6',
2174: 7 => 'Grade 7',
2175: 8 => 'Grade 8',
2176: 9 => 'Grade 9',
2177: 10 => 'Grade 10',
2178: 11 => 'Grade 11',
2179: 12 => 'Grade 12',
2180: 13 => 'Grade 13',
2181: 14 => '100 Level',
2182: 15 => '200 Level',
2183: 16 => '300 Level',
2184: 17 => '400 Level',
2185: 18 => 'Graduate Level');
2186: return &mt($gradelevels{$gradelevel});
2187: }
2188:
1.163 www 2189: sub select_level_form {
2190: my ($deflevel,$name)=@_;
2191: unless ($deflevel) { $deflevel=0; }
1.167 www 2192: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2193: for (my $i=0; $i<=18; $i++) {
2194: $selectform.="<option value=\"$i\" ".
1.253 albertel 2195: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2196: ">".&gradeleveldescription($i)."</option>\n";
2197: }
2198: $selectform.="</select>";
2199: return $selectform;
1.163 www 2200: }
1.167 www 2201:
1.35 matthew 2202: #-------------------------------------------
2203:
1.45 matthew 2204: =pod
2205:
1.1121 raeburn 2206: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35 matthew 2207:
2208: Returns a string containing a <select name='$name' size='1'> form to
2209: allow a user to select the domain to preform an operation in.
2210: See loncreateuser.pm for an example invocation and use.
2211:
1.90 www 2212: If the $includeempty flag is set, it also includes an empty choice ("no domain
2213: selected");
2214:
1.743 raeburn 2215: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2216:
1.910 raeburn 2217: 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.
2218:
1.1121 raeburn 2219: The optional $incdoms is a reference to an array of domains which will be the only available options.
2220:
2221: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2222:
1.35 matthew 2223: =cut
2224:
2225: #-------------------------------------------
1.34 matthew 2226: sub select_dom_form {
1.1121 raeburn 2227: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2228: if ($onchange) {
1.874 raeburn 2229: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2230: }
1.1121 raeburn 2231: my (@domains,%exclude);
1.910 raeburn 2232: if (ref($incdoms) eq 'ARRAY') {
2233: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2234: } else {
2235: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2236: }
1.90 www 2237: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2238: if (ref($excdoms) eq 'ARRAY') {
2239: map { $exclude{$_} = 1; } @{$excdoms};
2240: }
1.743 raeburn 2241: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2242: foreach my $dom (@domains) {
1.1121 raeburn 2243: next if ($exclude{$dom});
1.356 albertel 2244: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2245: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2246: if ($showdomdesc) {
2247: if ($dom ne '') {
2248: my $domdesc = &Apache::lonnet::domain($dom,'description');
2249: if ($domdesc ne '') {
2250: $selectdomain .= ' ('.$domdesc.')';
2251: }
2252: }
2253: }
2254: $selectdomain .= "</option>\n";
1.34 matthew 2255: }
2256: $selectdomain.="</select>";
2257: return $selectdomain;
2258: }
2259:
1.35 matthew 2260: #-------------------------------------------
2261:
1.45 matthew 2262: =pod
2263:
1.648 raeburn 2264: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2265:
1.586 raeburn 2266: input: 4 arguments (two required, two optional) -
2267: $domain - domain of new user
2268: $name - name of form element
2269: $default - Value of 'default' causes a default item to be first
2270: option, and selected by default.
2271: $hide - Value of 'hide' causes hiding of the name of the server,
2272: if 1 server found, or default, if 0 found.
1.594 raeburn 2273: output: returns 2 items:
1.586 raeburn 2274: (a) form element which contains either:
2275: (i) <select name="$name">
2276: <option value="$hostid1">$hostid $servers{$hostid}</option>
2277: <option value="$hostid2">$hostid $servers{$hostid}</option>
2278: </select>
2279: form item if there are multiple library servers in $domain, or
2280: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2281: if there is only one library server in $domain.
2282:
2283: (b) number of library servers found.
2284:
2285: See loncreateuser.pm for example of use.
1.35 matthew 2286:
2287: =cut
2288:
2289: #-------------------------------------------
1.586 raeburn 2290: sub home_server_form_item {
2291: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2292: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2293: my $result;
2294: my $numlib = keys(%servers);
2295: if ($numlib > 1) {
2296: $result .= '<select name="'.$name.'" />'."\n";
2297: if ($default) {
1.804 bisitz 2298: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2299: '</option>'."\n";
2300: }
2301: foreach my $hostid (sort(keys(%servers))) {
2302: $result.= '<option value="'.$hostid.'">'.
2303: $hostid.' '.$servers{$hostid}."</option>\n";
2304: }
2305: $result .= '</select>'."\n";
2306: } elsif ($numlib == 1) {
2307: my $hostid;
2308: foreach my $item (keys(%servers)) {
2309: $hostid = $item;
2310: }
2311: $result .= '<input type="hidden" name="'.$name.'" value="'.
2312: $hostid.'" />';
2313: if (!$hide) {
2314: $result .= $hostid.' '.$servers{$hostid};
2315: }
2316: $result .= "\n";
2317: } elsif ($default) {
2318: $result .= '<input type="hidden" name="'.$name.
2319: '" value="default" />';
2320: if (!$hide) {
2321: $result .= &mt('default');
2322: }
2323: $result .= "\n";
1.33 matthew 2324: }
1.586 raeburn 2325: return ($result,$numlib);
1.33 matthew 2326: }
1.112 bowersj2 2327:
2328: =pod
2329:
1.534 albertel 2330: =back
2331:
1.112 bowersj2 2332: =cut
1.87 matthew 2333:
2334: ###############################################################
1.112 bowersj2 2335: ## Decoding User Agent ##
1.87 matthew 2336: ###############################################################
2337:
2338: =pod
2339:
1.112 bowersj2 2340: =head1 Decoding the User Agent
2341:
2342: =over 4
2343:
2344: =item * &decode_user_agent()
1.87 matthew 2345:
2346: Inputs: $r
2347:
2348: Outputs:
2349:
2350: =over 4
2351:
1.112 bowersj2 2352: =item * $httpbrowser
1.87 matthew 2353:
1.112 bowersj2 2354: =item * $clientbrowser
1.87 matthew 2355:
1.112 bowersj2 2356: =item * $clientversion
1.87 matthew 2357:
1.112 bowersj2 2358: =item * $clientmathml
1.87 matthew 2359:
1.112 bowersj2 2360: =item * $clientunicode
1.87 matthew 2361:
1.112 bowersj2 2362: =item * $clientos
1.87 matthew 2363:
1.1137 raeburn 2364: =item * $clientmobile
2365:
1.1141 raeburn 2366: =item * $clientinfo
2367:
1.1194 raeburn 2368: =item * $clientosversion
2369:
1.87 matthew 2370: =back
2371:
1.157 matthew 2372: =back
2373:
1.87 matthew 2374: =cut
2375:
2376: ###############################################################
2377: ###############################################################
2378: sub decode_user_agent {
1.247 albertel 2379: my ($r)=@_;
1.87 matthew 2380: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2381: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2382: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2383: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2384: my $clientbrowser='unknown';
2385: my $clientversion='0';
2386: my $clientmathml='';
2387: my $clientunicode='0';
1.1137 raeburn 2388: my $clientmobile=0;
1.1194 raeburn 2389: my $clientosversion='';
1.87 matthew 2390: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2391: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2392: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2393: $clientbrowser=$bname;
2394: $httpbrowser=~/$vreg/i;
2395: $clientversion=$1;
2396: $clientmathml=($clientversion>=$minv);
2397: $clientunicode=($clientversion>=$univ);
2398: }
2399: }
2400: my $clientos='unknown';
1.1141 raeburn 2401: my $clientinfo;
1.87 matthew 2402: if (($httpbrowser=~/linux/i) ||
2403: ($httpbrowser=~/unix/i) ||
2404: ($httpbrowser=~/ux/i) ||
2405: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2406: if (($httpbrowser=~/vax/i) ||
2407: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2408: if ($httpbrowser=~/next/i) { $clientos='next'; }
2409: if (($httpbrowser=~/mac/i) ||
2410: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2411: if ($httpbrowser=~/win/i) {
2412: $clientos='win';
2413: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2414: $clientosversion = $1;
2415: }
2416: }
1.87 matthew 2417: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2418: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2419: $clientmobile=lc($1);
2420: }
1.1141 raeburn 2421: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2422: $clientinfo = 'firefox-'.$1;
2423: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2424: $clientinfo = 'chromeframe-'.$1;
2425: }
1.87 matthew 2426: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 2427: $clientunicode,$clientos,$clientmobile,$clientinfo,
2428: $clientosversion);
1.87 matthew 2429: }
2430:
1.32 matthew 2431: ###############################################################
2432: ## Authentication changing form generation subroutines ##
2433: ###############################################################
2434: ##
2435: ## All of the authform_xxxxxxx subroutines take their inputs in a
2436: ## hash, and have reasonable default values.
2437: ##
2438: ## formname = the name given in the <form> tag.
1.35 matthew 2439: #-------------------------------------------
2440:
1.45 matthew 2441: =pod
2442:
1.112 bowersj2 2443: =head1 Authentication Routines
2444:
2445: =over 4
2446:
1.648 raeburn 2447: =item * &authform_xxxxxx()
1.35 matthew 2448:
2449: The authform_xxxxxx subroutines provide javascript and html forms which
2450: handle some of the conveniences required for authentication forms.
2451: This is not an optimal method, but it works.
2452:
2453: =over 4
2454:
1.112 bowersj2 2455: =item * authform_header
1.35 matthew 2456:
1.112 bowersj2 2457: =item * authform_authorwarning
1.35 matthew 2458:
1.112 bowersj2 2459: =item * authform_nochange
1.35 matthew 2460:
1.112 bowersj2 2461: =item * authform_kerberos
1.35 matthew 2462:
1.112 bowersj2 2463: =item * authform_internal
1.35 matthew 2464:
1.112 bowersj2 2465: =item * authform_filesystem
1.35 matthew 2466:
2467: =back
2468:
1.648 raeburn 2469: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2470:
1.35 matthew 2471: =cut
2472:
2473: #-------------------------------------------
1.32 matthew 2474: sub authform_header{
2475: my %in = (
2476: formname => 'cu',
1.80 albertel 2477: kerb_def_dom => '',
1.32 matthew 2478: @_,
2479: );
2480: $in{'formname'} = 'document.' . $in{'formname'};
2481: my $result='';
1.80 albertel 2482:
2483: #---------------------------------------------- Code for upper case translation
2484: my $Javascript_toUpperCase;
2485: unless ($in{kerb_def_dom}) {
2486: $Javascript_toUpperCase =<<"END";
2487: switch (choice) {
2488: case 'krb': currentform.elements[choicearg].value =
2489: currentform.elements[choicearg].value.toUpperCase();
2490: break;
2491: default:
2492: }
2493: END
2494: } else {
2495: $Javascript_toUpperCase = "";
2496: }
2497:
1.165 raeburn 2498: my $radioval = "'nochange'";
1.591 raeburn 2499: if (defined($in{'curr_authtype'})) {
2500: if ($in{'curr_authtype'} ne '') {
2501: $radioval = "'".$in{'curr_authtype'}."arg'";
2502: }
1.174 matthew 2503: }
1.165 raeburn 2504: my $argfield = 'null';
1.591 raeburn 2505: if (defined($in{'mode'})) {
1.165 raeburn 2506: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2507: if (defined($in{'curr_autharg'})) {
2508: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2509: $argfield = "'$in{'curr_autharg'}'";
2510: }
2511: }
2512: }
2513: }
2514:
1.32 matthew 2515: $result.=<<"END";
2516: var current = new Object();
1.165 raeburn 2517: current.radiovalue = $radioval;
2518: current.argfield = $argfield;
1.32 matthew 2519:
2520: function changed_radio(choice,currentform) {
2521: var choicearg = choice + 'arg';
2522: // If a radio button in changed, we need to change the argfield
2523: if (current.radiovalue != choice) {
2524: current.radiovalue = choice;
2525: if (current.argfield != null) {
2526: currentform.elements[current.argfield].value = '';
2527: }
2528: if (choice == 'nochange') {
2529: current.argfield = null;
2530: } else {
2531: current.argfield = choicearg;
2532: switch(choice) {
2533: case 'krb':
2534: currentform.elements[current.argfield].value =
2535: "$in{'kerb_def_dom'}";
2536: break;
2537: default:
2538: break;
2539: }
2540: }
2541: }
2542: return;
2543: }
1.22 www 2544:
1.32 matthew 2545: function changed_text(choice,currentform) {
2546: var choicearg = choice + 'arg';
2547: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2548: $Javascript_toUpperCase
1.32 matthew 2549: // clear old field
2550: if ((current.argfield != choicearg) && (current.argfield != null)) {
2551: currentform.elements[current.argfield].value = '';
2552: }
2553: current.argfield = choicearg;
2554: }
2555: set_auth_radio_buttons(choice,currentform);
2556: return;
1.20 www 2557: }
1.32 matthew 2558:
2559: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2560: var numauthchoices = currentform.login.length;
2561: if (typeof numauthchoices == "undefined") {
2562: return;
2563: }
1.32 matthew 2564: var i=0;
1.986 raeburn 2565: while (i < numauthchoices) {
1.32 matthew 2566: if (currentform.login[i].value == newvalue) { break; }
2567: i++;
2568: }
1.986 raeburn 2569: if (i == numauthchoices) {
1.32 matthew 2570: return;
2571: }
2572: current.radiovalue = newvalue;
2573: currentform.login[i].checked = true;
2574: return;
2575: }
2576: END
2577: return $result;
2578: }
2579:
1.1106 raeburn 2580: sub authform_authorwarning {
1.32 matthew 2581: my $result='';
1.144 matthew 2582: $result='<i>'.
2583: &mt('As a general rule, only authors or co-authors should be '.
2584: 'filesystem authenticated '.
2585: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2586: return $result;
2587: }
2588:
1.1106 raeburn 2589: sub authform_nochange {
1.32 matthew 2590: my %in = (
2591: formname => 'document.cu',
2592: kerb_def_dom => 'MSU.EDU',
2593: @_,
2594: );
1.1106 raeburn 2595: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2596: my $result;
1.1104 raeburn 2597: if (!$authnum) {
1.1105 raeburn 2598: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2599: } else {
2600: $result = '<label>'.&mt('[_1] Do not change login data',
2601: '<input type="radio" name="login" value="nochange" '.
2602: 'checked="checked" onclick="'.
1.281 albertel 2603: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2604: '</label>';
1.586 raeburn 2605: }
1.32 matthew 2606: return $result;
2607: }
2608:
1.591 raeburn 2609: sub authform_kerberos {
1.32 matthew 2610: my %in = (
2611: formname => 'document.cu',
2612: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2613: kerb_def_auth => 'krb4',
1.32 matthew 2614: @_,
2615: );
1.586 raeburn 2616: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2617: $autharg,$jscall);
1.1106 raeburn 2618: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2619: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2620: $check5 = ' checked="checked"';
1.80 albertel 2621: } else {
1.772 bisitz 2622: $check4 = ' checked="checked"';
1.80 albertel 2623: }
1.165 raeburn 2624: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2625: if (defined($in{'curr_authtype'})) {
2626: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2627: $krbcheck = ' checked="checked"';
1.623 raeburn 2628: if (defined($in{'mode'})) {
2629: if ($in{'mode'} eq 'modifyuser') {
2630: $krbcheck = '';
2631: }
2632: }
1.591 raeburn 2633: if (defined($in{'curr_kerb_ver'})) {
2634: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2635: $check5 = ' checked="checked"';
1.591 raeburn 2636: $check4 = '';
2637: } else {
1.772 bisitz 2638: $check4 = ' checked="checked"';
1.591 raeburn 2639: $check5 = '';
2640: }
1.586 raeburn 2641: }
1.591 raeburn 2642: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2643: $krbarg = $in{'curr_autharg'};
2644: }
1.586 raeburn 2645: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2646: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2647: $result =
2648: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2649: $in{'curr_autharg'},$krbver);
2650: } else {
2651: $result =
2652: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2653: }
2654: return $result;
2655: }
2656: }
2657: } else {
2658: if ($authnum == 1) {
1.784 bisitz 2659: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2660: }
2661: }
1.586 raeburn 2662: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2663: return;
1.587 raeburn 2664: } elsif ($authtype eq '') {
1.591 raeburn 2665: if (defined($in{'mode'})) {
1.587 raeburn 2666: if ($in{'mode'} eq 'modifycourse') {
2667: if ($authnum == 1) {
1.1104 raeburn 2668: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2669: }
2670: }
2671: }
1.586 raeburn 2672: }
2673: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2674: if ($authtype eq '') {
2675: $authtype = '<input type="radio" name="login" value="krb" '.
2676: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2677: $krbcheck.' />';
2678: }
2679: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 2680: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2681: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 2682: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2683: $in{'curr_authtype'} eq 'krb4')) {
2684: $result .= &mt
1.144 matthew 2685: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2686: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2687: '<label>'.$authtype,
1.281 albertel 2688: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2689: 'value="'.$krbarg.'" '.
1.144 matthew 2690: 'onchange="'.$jscall.'" />',
1.281 albertel 2691: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2692: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2693: '</label>');
1.586 raeburn 2694: } elsif ($can_assign{'krb4'}) {
2695: $result .= &mt
2696: ('[_1] Kerberos authenticated with domain [_2] '.
2697: '[_3] Version 4 [_4]',
2698: '<label>'.$authtype,
2699: '</label><input type="text" size="10" name="krbarg" '.
2700: 'value="'.$krbarg.'" '.
2701: 'onchange="'.$jscall.'" />',
2702: '<label><input type="hidden" name="krbver" value="4" />',
2703: '</label>');
2704: } elsif ($can_assign{'krb5'}) {
2705: $result .= &mt
2706: ('[_1] Kerberos authenticated with domain [_2] '.
2707: '[_3] Version 5 [_4]',
2708: '<label>'.$authtype,
2709: '</label><input type="text" size="10" name="krbarg" '.
2710: 'value="'.$krbarg.'" '.
2711: 'onchange="'.$jscall.'" />',
2712: '<label><input type="hidden" name="krbver" value="5" />',
2713: '</label>');
2714: }
1.32 matthew 2715: return $result;
2716: }
2717:
1.1106 raeburn 2718: sub authform_internal {
1.586 raeburn 2719: my %in = (
1.32 matthew 2720: formname => 'document.cu',
2721: kerb_def_dom => 'MSU.EDU',
2722: @_,
2723: );
1.586 raeburn 2724: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2725: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2726: if (defined($in{'curr_authtype'})) {
2727: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2728: if ($can_assign{'int'}) {
1.772 bisitz 2729: $intcheck = 'checked="checked" ';
1.623 raeburn 2730: if (defined($in{'mode'})) {
2731: if ($in{'mode'} eq 'modifyuser') {
2732: $intcheck = '';
2733: }
2734: }
1.591 raeburn 2735: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2736: $intarg = $in{'curr_autharg'};
2737: }
2738: } else {
2739: $result = &mt('Currently internally authenticated.');
2740: return $result;
1.165 raeburn 2741: }
2742: }
1.586 raeburn 2743: } else {
2744: if ($authnum == 1) {
1.784 bisitz 2745: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 2746: }
2747: }
2748: if (!$can_assign{'int'}) {
2749: return;
1.587 raeburn 2750: } elsif ($authtype eq '') {
1.591 raeburn 2751: if (defined($in{'mode'})) {
1.587 raeburn 2752: if ($in{'mode'} eq 'modifycourse') {
2753: if ($authnum == 1) {
1.1104 raeburn 2754: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 2755: }
2756: }
2757: }
1.165 raeburn 2758: }
1.586 raeburn 2759: $jscall = "javascript:changed_radio('int',$in{'formname'});";
2760: if ($authtype eq '') {
2761: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
2762: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
2763: }
1.605 bisitz 2764: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 2765: $intarg.'" onchange="'.$jscall.'" />';
2766: $result = &mt
1.144 matthew 2767: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 2768: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 2769: $result.="<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 2770: return $result;
2771: }
2772:
1.1104 raeburn 2773: sub authform_local {
1.32 matthew 2774: my %in = (
2775: formname => 'document.cu',
2776: kerb_def_dom => 'MSU.EDU',
2777: @_,
2778: );
1.586 raeburn 2779: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2780: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2781: if (defined($in{'curr_authtype'})) {
2782: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 2783: if ($can_assign{'loc'}) {
1.772 bisitz 2784: $loccheck = 'checked="checked" ';
1.623 raeburn 2785: if (defined($in{'mode'})) {
2786: if ($in{'mode'} eq 'modifyuser') {
2787: $loccheck = '';
2788: }
2789: }
1.591 raeburn 2790: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2791: $locarg = $in{'curr_autharg'};
2792: }
2793: } else {
2794: $result = &mt('Currently using local (institutional) authentication.');
2795: return $result;
1.165 raeburn 2796: }
2797: }
1.586 raeburn 2798: } else {
2799: if ($authnum == 1) {
1.784 bisitz 2800: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 2801: }
2802: }
2803: if (!$can_assign{'loc'}) {
2804: return;
1.587 raeburn 2805: } elsif ($authtype eq '') {
1.591 raeburn 2806: if (defined($in{'mode'})) {
1.587 raeburn 2807: if ($in{'mode'} eq 'modifycourse') {
2808: if ($authnum == 1) {
1.1104 raeburn 2809: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 2810: }
2811: }
2812: }
1.165 raeburn 2813: }
1.586 raeburn 2814: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
2815: if ($authtype eq '') {
2816: $authtype = '<input type="radio" name="login" value="loc" '.
2817: $loccheck.' onchange="'.$jscall.'" onclick="'.
2818: $jscall.'" />';
2819: }
2820: $autharg = '<input type="text" size="10" name="locarg" value="'.
2821: $locarg.'" onchange="'.$jscall.'" />';
2822: $result = &mt('[_1] Local Authentication with argument [_2]',
2823: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 2824: return $result;
2825: }
2826:
1.1106 raeburn 2827: sub authform_filesystem {
1.32 matthew 2828: my %in = (
2829: formname => 'document.cu',
2830: kerb_def_dom => 'MSU.EDU',
2831: @_,
2832: );
1.586 raeburn 2833: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2834: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2835: if (defined($in{'curr_authtype'})) {
2836: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 2837: if ($can_assign{'fsys'}) {
1.772 bisitz 2838: $fsyscheck = 'checked="checked" ';
1.623 raeburn 2839: if (defined($in{'mode'})) {
2840: if ($in{'mode'} eq 'modifyuser') {
2841: $fsyscheck = '';
2842: }
2843: }
1.586 raeburn 2844: } else {
2845: $result = &mt('Currently Filesystem Authenticated.');
2846: return $result;
2847: }
2848: }
2849: } else {
2850: if ($authnum == 1) {
1.784 bisitz 2851: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 2852: }
2853: }
2854: if (!$can_assign{'fsys'}) {
2855: return;
1.587 raeburn 2856: } elsif ($authtype eq '') {
1.591 raeburn 2857: if (defined($in{'mode'})) {
1.587 raeburn 2858: if ($in{'mode'} eq 'modifycourse') {
2859: if ($authnum == 1) {
1.1104 raeburn 2860: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 2861: }
2862: }
2863: }
1.586 raeburn 2864: }
2865: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
2866: if ($authtype eq '') {
2867: $authtype = '<input type="radio" name="login" value="fsys" '.
2868: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
2869: $jscall.'" />';
2870: }
2871: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
2872: ' onchange="'.$jscall.'" />';
2873: $result = &mt
1.144 matthew 2874: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 2875: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 2876: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 2877: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 2878: 'onchange="'.$jscall.'" />');
1.32 matthew 2879: return $result;
2880: }
2881:
1.586 raeburn 2882: sub get_assignable_auth {
2883: my ($dom) = @_;
2884: if ($dom eq '') {
2885: $dom = $env{'request.role.domain'};
2886: }
2887: my %can_assign = (
2888: krb4 => 1,
2889: krb5 => 1,
2890: int => 1,
2891: loc => 1,
2892: );
2893: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
2894: if (ref($domconfig{'usercreation'}) eq 'HASH') {
2895: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
2896: my $authhash = $domconfig{'usercreation'}{'authtypes'};
2897: my $context;
2898: if ($env{'request.role'} =~ /^au/) {
2899: $context = 'author';
2900: } elsif ($env{'request.role'} =~ /^dc/) {
2901: $context = 'domain';
2902: } elsif ($env{'request.course.id'}) {
2903: $context = 'course';
2904: }
2905: if ($context) {
2906: if (ref($authhash->{$context}) eq 'HASH') {
2907: %can_assign = %{$authhash->{$context}};
2908: }
2909: }
2910: }
2911: }
2912: my $authnum = 0;
2913: foreach my $key (keys(%can_assign)) {
2914: if ($can_assign{$key}) {
2915: $authnum ++;
2916: }
2917: }
2918: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
2919: $authnum --;
2920: }
2921: return ($authnum,%can_assign);
2922: }
2923:
1.80 albertel 2924: ###############################################################
2925: ## Get Kerberos Defaults for Domain ##
2926: ###############################################################
2927: ##
2928: ## Returns default kerberos version and an associated argument
2929: ## as listed in file domain.tab. If not listed, provides
2930: ## appropriate default domain and kerberos version.
2931: ##
2932: #-------------------------------------------
2933:
2934: =pod
2935:
1.648 raeburn 2936: =item * &get_kerberos_defaults()
1.80 albertel 2937:
2938: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 2939: version and domain. If not found, it defaults to version 4 and the
2940: domain of the server.
1.80 albertel 2941:
1.648 raeburn 2942: =over 4
2943:
1.80 albertel 2944: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
2945:
1.648 raeburn 2946: =back
2947:
2948: =back
2949:
1.80 albertel 2950: =cut
2951:
2952: #-------------------------------------------
2953: sub get_kerberos_defaults {
2954: my $domain=shift;
1.641 raeburn 2955: my ($krbdef,$krbdefdom);
2956: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
2957: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
2958: $krbdef = $domdefaults{'auth_def'};
2959: $krbdefdom = $domdefaults{'auth_arg_def'};
2960: } else {
1.80 albertel 2961: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
2962: my $krbdefdom=$1;
2963: $krbdefdom=~tr/a-z/A-Z/;
2964: $krbdef = "krb4";
2965: }
2966: return ($krbdef,$krbdefdom);
2967: }
1.112 bowersj2 2968:
1.32 matthew 2969:
1.46 matthew 2970: ###############################################################
2971: ## Thesaurus Functions ##
2972: ###############################################################
1.20 www 2973:
1.46 matthew 2974: =pod
1.20 www 2975:
1.112 bowersj2 2976: =head1 Thesaurus Functions
2977:
2978: =over 4
2979:
1.648 raeburn 2980: =item * &initialize_keywords()
1.46 matthew 2981:
2982: Initializes the package variable %Keywords if it is empty. Uses the
2983: package variable $thesaurus_db_file.
2984:
2985: =cut
2986:
2987: ###################################################
2988:
2989: sub initialize_keywords {
2990: return 1 if (scalar keys(%Keywords));
2991: # If we are here, %Keywords is empty, so fill it up
2992: # Make sure the file we need exists...
2993: if (! -e $thesaurus_db_file) {
2994: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
2995: " failed because it does not exist");
2996: return 0;
2997: }
2998: # Set up the hash as a database
2999: my %thesaurus_db;
3000: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3001: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3002: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3003: $thesaurus_db_file);
3004: return 0;
3005: }
3006: # Get the average number of appearances of a word.
3007: my $avecount = $thesaurus_db{'average.count'};
3008: # Put keywords (those that appear > average) into %Keywords
3009: while (my ($word,$data)=each (%thesaurus_db)) {
3010: my ($count,undef) = split /:/,$data;
3011: $Keywords{$word}++ if ($count > $avecount);
3012: }
3013: untie %thesaurus_db;
3014: # Remove special values from %Keywords.
1.356 albertel 3015: foreach my $value ('total.count','average.count') {
3016: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3017: }
1.46 matthew 3018: return 1;
3019: }
3020:
3021: ###################################################
3022:
3023: =pod
3024:
1.648 raeburn 3025: =item * &keyword($word)
1.46 matthew 3026:
3027: Returns true if $word is a keyword. A keyword is a word that appears more
3028: than the average number of times in the thesaurus database. Calls
3029: &initialize_keywords
3030:
3031: =cut
3032:
3033: ###################################################
1.20 www 3034:
3035: sub keyword {
1.46 matthew 3036: return if (!&initialize_keywords());
3037: my $word=lc(shift());
3038: $word=~s/\W//g;
3039: return exists($Keywords{$word});
1.20 www 3040: }
1.46 matthew 3041:
3042: ###############################################################
3043:
3044: =pod
1.20 www 3045:
1.648 raeburn 3046: =item * &get_related_words()
1.46 matthew 3047:
1.160 matthew 3048: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3049: an array of words. If the keyword is not in the thesaurus, an empty array
3050: will be returned. The order of the words returned is determined by the
3051: database which holds them.
3052:
3053: Uses global $thesaurus_db_file.
3054:
1.1057 foxr 3055:
1.46 matthew 3056: =cut
3057:
3058: ###############################################################
3059: sub get_related_words {
3060: my $keyword = shift;
3061: my %thesaurus_db;
3062: if (! -e $thesaurus_db_file) {
3063: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3064: "failed because the file does not exist");
3065: return ();
3066: }
3067: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3068: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3069: return ();
3070: }
3071: my @Words=();
1.429 www 3072: my $count=0;
1.46 matthew 3073: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3074: # The first element is the number of times
3075: # the word appears. We do not need it now.
1.429 www 3076: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3077: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3078: my $threshold=$mostfrequentcount/10;
3079: foreach my $possibleword (@RelatedWords) {
3080: my ($word,$wordcount)=split(/\,/,$possibleword);
3081: if ($wordcount>$threshold) {
3082: push(@Words,$word);
3083: $count++;
3084: if ($count>10) { last; }
3085: }
1.20 www 3086: }
3087: }
1.46 matthew 3088: untie %thesaurus_db;
3089: return @Words;
1.14 harris41 3090: }
1.1090 foxr 3091: ###############################################################
3092: #
3093: # Spell checking
3094: #
3095:
3096: =pod
3097:
1.1142 raeburn 3098: =back
3099:
1.1090 foxr 3100: =head1 Spell checking
3101:
3102: =over 4
3103:
3104: =item * &check_spelling($wordlist $language)
3105:
3106: Takes a string containing words and feeds it to an external
3107: spellcheck program via a pipeline. Returns a string containing
3108: them mis-spelled words.
3109:
3110: Parameters:
3111:
3112: =over 4
3113:
3114: =item - $wordlist
3115:
3116: String that will be fed into the spellcheck program.
3117:
3118: =item - $language
3119:
3120: Language string that specifies the language for which the spell
3121: check will be performed.
3122:
3123: =back
3124:
3125: =back
3126:
3127: Note: This sub assumes that aspell is installed.
3128:
3129:
3130: =cut
3131:
1.46 matthew 3132:
1.1090 foxr 3133: sub check_spelling {
3134: my ($wordlist, $language) = @_;
1.1091 foxr 3135: my @misspellings;
3136:
3137: # Generate the speller and set the langauge.
3138: # if explicitly selected:
1.1090 foxr 3139:
1.1091 foxr 3140: my $speller = Text::Aspell->new;
1.1090 foxr 3141: if ($language) {
1.1091 foxr 3142: $speller->set_option('lang', $language);
1.1090 foxr 3143: }
3144:
1.1091 foxr 3145: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3146:
1.1091 foxr 3147: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3148:
1.1091 foxr 3149: foreach my $word (@words) {
3150: if(! $speller->check($word)) {
3151: push(@misspellings, $word);
1.1090 foxr 3152: }
3153: }
1.1091 foxr 3154: return join(' ', @misspellings);
3155:
1.1090 foxr 3156: }
3157:
1.61 www 3158: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3159: =pod
3160:
1.112 bowersj2 3161: =head1 User Name Functions
3162:
3163: =over 4
3164:
1.648 raeburn 3165: =item * &plainname($uname,$udom,$first)
1.81 albertel 3166:
1.112 bowersj2 3167: Takes a users logon name and returns it as a string in
1.226 albertel 3168: "first middle last generation" form
3169: if $first is set to 'lastname' then it returns it as
3170: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3171:
3172: =cut
1.61 www 3173:
1.295 www 3174:
1.81 albertel 3175: ###############################################################
1.61 www 3176: sub plainname {
1.226 albertel 3177: my ($uname,$udom,$first)=@_;
1.537 albertel 3178: return if (!defined($uname) || !defined($udom));
1.295 www 3179: my %names=&getnames($uname,$udom);
1.226 albertel 3180: my $name=&Apache::lonnet::format_name($names{'firstname'},
3181: $names{'middlename'},
3182: $names{'lastname'},
3183: $names{'generation'},$first);
3184: $name=~s/^\s+//;
1.62 www 3185: $name=~s/\s+$//;
3186: $name=~s/\s+/ /g;
1.353 albertel 3187: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3188: return $name;
1.61 www 3189: }
1.66 www 3190:
3191: # -------------------------------------------------------------------- Nickname
1.81 albertel 3192: =pod
3193:
1.648 raeburn 3194: =item * &nickname($uname,$udom)
1.81 albertel 3195:
3196: Gets a users name and returns it as a string as
3197:
3198: ""nickname""
1.66 www 3199:
1.81 albertel 3200: if the user has a nickname or
3201:
3202: "first middle last generation"
3203:
3204: if the user does not
3205:
3206: =cut
1.66 www 3207:
3208: sub nickname {
3209: my ($uname,$udom)=@_;
1.537 albertel 3210: return if (!defined($uname) || !defined($udom));
1.295 www 3211: my %names=&getnames($uname,$udom);
1.68 albertel 3212: my $name=$names{'nickname'};
1.66 www 3213: if ($name) {
3214: $name='"'.$name.'"';
3215: } else {
3216: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3217: $names{'lastname'}.' '.$names{'generation'};
3218: $name=~s/\s+$//;
3219: $name=~s/\s+/ /g;
3220: }
3221: return $name;
3222: }
3223:
1.295 www 3224: sub getnames {
3225: my ($uname,$udom)=@_;
1.537 albertel 3226: return if (!defined($uname) || !defined($udom));
1.433 albertel 3227: if ($udom eq 'public' && $uname eq 'public') {
3228: return ('lastname' => &mt('Public'));
3229: }
1.295 www 3230: my $id=$uname.':'.$udom;
3231: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3232: if ($cached) {
3233: return %{$names};
3234: } else {
3235: my %loadnames=&Apache::lonnet::get('environment',
3236: ['firstname','middlename','lastname','generation','nickname'],
3237: $udom,$uname);
3238: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3239: return %loadnames;
3240: }
3241: }
1.61 www 3242:
1.542 raeburn 3243: # -------------------------------------------------------------------- getemails
1.648 raeburn 3244:
1.542 raeburn 3245: =pod
3246:
1.648 raeburn 3247: =item * &getemails($uname,$udom)
1.542 raeburn 3248:
3249: Gets a user's email information and returns it as a hash with keys:
3250: notification, critnotification, permanentemail
3251:
3252: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3253: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3254:
1.648 raeburn 3255:
1.542 raeburn 3256: =cut
3257:
1.648 raeburn 3258:
1.466 albertel 3259: sub getemails {
3260: my ($uname,$udom)=@_;
3261: if ($udom eq 'public' && $uname eq 'public') {
3262: return;
3263: }
1.467 www 3264: if (!$udom) { $udom=$env{'user.domain'}; }
3265: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3266: my $id=$uname.':'.$udom;
3267: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3268: if ($cached) {
3269: return %{$names};
3270: } else {
3271: my %loadnames=&Apache::lonnet::get('environment',
3272: ['notification','critnotification',
3273: 'permanentemail'],
3274: $udom,$uname);
3275: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3276: return %loadnames;
3277: }
3278: }
3279:
1.551 albertel 3280: sub flush_email_cache {
3281: my ($uname,$udom)=@_;
3282: if (!$udom) { $udom =$env{'user.domain'}; }
3283: if (!$uname) { $uname=$env{'user.name'}; }
3284: return if ($udom eq 'public' && $uname eq 'public');
3285: my $id=$uname.':'.$udom;
3286: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3287: }
3288:
1.728 raeburn 3289: # -------------------------------------------------------------------- getlangs
3290:
3291: =pod
3292:
3293: =item * &getlangs($uname,$udom)
3294:
3295: Gets a user's language preference and returns it as a hash with key:
3296: language.
3297:
3298: =cut
3299:
3300:
3301: sub getlangs {
3302: my ($uname,$udom) = @_;
3303: if (!$udom) { $udom =$env{'user.domain'}; }
3304: if (!$uname) { $uname=$env{'user.name'}; }
3305: my $id=$uname.':'.$udom;
3306: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3307: if ($cached) {
3308: return %{$langs};
3309: } else {
3310: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3311: $udom,$uname);
3312: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3313: return %loadlangs;
3314: }
3315: }
3316:
3317: sub flush_langs_cache {
3318: my ($uname,$udom)=@_;
3319: if (!$udom) { $udom =$env{'user.domain'}; }
3320: if (!$uname) { $uname=$env{'user.name'}; }
3321: return if ($udom eq 'public' && $uname eq 'public');
3322: my $id=$uname.':'.$udom;
3323: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3324: }
3325:
1.61 www 3326: # ------------------------------------------------------------------ Screenname
1.81 albertel 3327:
3328: =pod
3329:
1.648 raeburn 3330: =item * &screenname($uname,$udom)
1.81 albertel 3331:
3332: Gets a users screenname and returns it as a string
3333:
3334: =cut
1.61 www 3335:
3336: sub screenname {
3337: my ($uname,$udom)=@_;
1.258 albertel 3338: if ($uname eq $env{'user.name'} &&
3339: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3340: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3341: return $names{'screenname'};
1.62 www 3342: }
3343:
1.212 albertel 3344:
1.802 bisitz 3345: # ------------------------------------------------------------- Confirm Wrapper
3346: =pod
3347:
1.1142 raeburn 3348: =item * &confirmwrapper($message)
1.802 bisitz 3349:
3350: Wrap messages about completion of operation in box
3351:
3352: =cut
3353:
3354: sub confirmwrapper {
3355: my ($message)=@_;
3356: if ($message) {
3357: return "\n".'<div class="LC_confirm_box">'."\n"
3358: .$message."\n"
3359: .'</div>'."\n";
3360: } else {
3361: return $message;
3362: }
3363: }
3364:
1.62 www 3365: # ------------------------------------------------------------- Message Wrapper
3366:
3367: sub messagewrapper {
1.369 www 3368: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3369: return
1.441 albertel 3370: '<a href="/adm/email?compose=individual&'.
3371: 'recname='.$username.'&recdom='.$domain.
3372: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3373: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3374: }
1.802 bisitz 3375:
1.74 www 3376: # --------------------------------------------------------------- Notes Wrapper
3377:
3378: sub noteswrapper {
3379: my ($link,$un,$do)=@_;
3380: return
1.896 amueller 3381: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3382: }
1.802 bisitz 3383:
1.62 www 3384: # ------------------------------------------------------------- Aboutme Wrapper
3385:
3386: sub aboutmewrapper {
1.1070 raeburn 3387: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3388: if (!defined($username) && !defined($domain)) {
3389: return;
3390: }
1.1096 raeburn 3391: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3392: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3393: }
3394:
3395: # ------------------------------------------------------------ Syllabus Wrapper
3396:
3397: sub syllabuswrapper {
1.707 bisitz 3398: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3399: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3400: }
1.14 harris41 3401:
1.802 bisitz 3402: # -----------------------------------------------------------------------------
3403:
1.208 matthew 3404: sub track_student_link {
1.887 raeburn 3405: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3406: my $link ="/adm/trackstudent?";
1.208 matthew 3407: my $title = 'View recent activity';
3408: if (defined($sname) && $sname !~ /^\s*$/ &&
3409: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3410: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3411: $title .= ' of this student';
1.268 albertel 3412: }
1.208 matthew 3413: if (defined($target) && $target !~ /^\s*$/) {
3414: $target = qq{target="$target"};
3415: } else {
3416: $target = '';
3417: }
1.268 albertel 3418: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3419: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3420: $title = &mt($title);
3421: $linktext = &mt($linktext);
1.448 albertel 3422: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3423: &help_open_topic('View_recent_activity');
1.208 matthew 3424: }
3425:
1.781 raeburn 3426: sub slot_reservations_link {
3427: my ($linktext,$sname,$sdom,$target) = @_;
3428: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3429: my $title = 'View slot reservation history';
3430: if (defined($sname) && $sname !~ /^\s*$/ &&
3431: defined($sdom) && $sdom !~ /^\s*$/) {
3432: $link .= "&uname=$sname&udom=$sdom";
3433: $title .= ' of this student';
3434: }
3435: if (defined($target) && $target !~ /^\s*$/) {
3436: $target = qq{target="$target"};
3437: } else {
3438: $target = '';
3439: }
3440: $title = &mt($title);
3441: $linktext = &mt($linktext);
3442: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3443: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3444:
3445: }
3446:
1.508 www 3447: # ===================================================== Display a student photo
3448:
3449:
1.509 albertel 3450: sub student_image_tag {
1.508 www 3451: my ($domain,$user)=@_;
3452: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3453: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3454: return '<img src="'.$imgsrc.'" align="right" />';
3455: } else {
3456: return '';
3457: }
3458: }
3459:
1.112 bowersj2 3460: =pod
3461:
3462: =back
3463:
3464: =head1 Access .tab File Data
3465:
3466: =over 4
3467:
1.648 raeburn 3468: =item * &languageids()
1.112 bowersj2 3469:
3470: returns list of all language ids
3471:
3472: =cut
3473:
1.14 harris41 3474: sub languageids {
1.16 harris41 3475: return sort(keys(%language));
1.14 harris41 3476: }
3477:
1.112 bowersj2 3478: =pod
3479:
1.648 raeburn 3480: =item * &languagedescription()
1.112 bowersj2 3481:
3482: returns description of a specified language id
3483:
3484: =cut
3485:
1.14 harris41 3486: sub languagedescription {
1.125 www 3487: my $code=shift;
3488: return ($supported_language{$code}?'* ':'').
3489: $language{$code}.
1.126 www 3490: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3491: }
3492:
1.1048 foxr 3493: =pod
3494:
3495: =item * &plainlanguagedescription
3496:
3497: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3498: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3499:
3500: =cut
3501:
1.145 www 3502: sub plainlanguagedescription {
3503: my $code=shift;
3504: return $language{$code};
3505: }
3506:
1.1048 foxr 3507: =pod
3508:
3509: =item * &supportedlanguagecode
3510:
3511: Returns the supported language code (e.g. sptutf maps to pt) given a language
3512: code.
3513:
3514: =cut
3515:
1.145 www 3516: sub supportedlanguagecode {
3517: my $code=shift;
3518: return $supported_language{$code};
1.97 www 3519: }
3520:
1.112 bowersj2 3521: =pod
3522:
1.1048 foxr 3523: =item * &latexlanguage()
3524:
3525: Given a language key code returns the correspondnig language to use
3526: to select the correct hyphenation on LaTeX printouts. This is undef if there
3527: is no supported hyphenation for the language code.
3528:
3529: =cut
3530:
3531: sub latexlanguage {
3532: my $code = shift;
3533: return $latex_language{$code};
3534: }
3535:
3536: =pod
3537:
3538: =item * &latexhyphenation()
3539:
3540: Same as above but what's supplied is the language as it might be stored
3541: in the metadata.
3542:
3543: =cut
3544:
3545: sub latexhyphenation {
3546: my $key = shift;
3547: return $latex_language_bykey{$key};
3548: }
3549:
3550: =pod
3551:
1.648 raeburn 3552: =item * ©rightids()
1.112 bowersj2 3553:
3554: returns list of all copyrights
3555:
3556: =cut
3557:
3558: sub copyrightids {
3559: return sort(keys(%cprtag));
3560: }
3561:
3562: =pod
3563:
1.648 raeburn 3564: =item * ©rightdescription()
1.112 bowersj2 3565:
3566: returns description of a specified copyright id
3567:
3568: =cut
3569:
3570: sub copyrightdescription {
1.166 www 3571: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3572: }
1.197 matthew 3573:
3574: =pod
3575:
1.648 raeburn 3576: =item * &source_copyrightids()
1.192 taceyjo1 3577:
3578: returns list of all source copyrights
3579:
3580: =cut
3581:
3582: sub source_copyrightids {
3583: return sort(keys(%scprtag));
3584: }
3585:
3586: =pod
3587:
1.648 raeburn 3588: =item * &source_copyrightdescription()
1.192 taceyjo1 3589:
3590: returns description of a specified source copyright id
3591:
3592: =cut
3593:
3594: sub source_copyrightdescription {
3595: return &mt($scprtag{shift(@_)});
3596: }
1.112 bowersj2 3597:
3598: =pod
3599:
1.648 raeburn 3600: =item * &filecategories()
1.112 bowersj2 3601:
3602: returns list of all file categories
3603:
3604: =cut
3605:
3606: sub filecategories {
3607: return sort(keys(%category_extensions));
3608: }
3609:
3610: =pod
3611:
1.648 raeburn 3612: =item * &filecategorytypes()
1.112 bowersj2 3613:
3614: returns list of file types belonging to a given file
3615: category
3616:
3617: =cut
3618:
3619: sub filecategorytypes {
1.356 albertel 3620: my ($cat) = @_;
3621: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3622: }
3623:
3624: =pod
3625:
1.648 raeburn 3626: =item * &fileembstyle()
1.112 bowersj2 3627:
3628: returns embedding style for a specified file type
3629:
3630: =cut
3631:
3632: sub fileembstyle {
3633: return $fe{lc(shift(@_))};
1.169 www 3634: }
3635:
1.351 www 3636: sub filemimetype {
3637: return $fm{lc(shift(@_))};
3638: }
3639:
1.169 www 3640:
3641: sub filecategoryselect {
3642: my ($name,$value)=@_;
1.189 matthew 3643: return &select_form($value,$name,
1.970 raeburn 3644: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3645: }
3646:
3647: =pod
3648:
1.648 raeburn 3649: =item * &filedescription()
1.112 bowersj2 3650:
3651: returns description for a specified file type
3652:
3653: =cut
3654:
3655: sub filedescription {
1.188 matthew 3656: my $file_description = $fd{lc(shift())};
3657: $file_description =~ s:([\[\]]):~$1:g;
3658: return &mt($file_description);
1.112 bowersj2 3659: }
3660:
3661: =pod
3662:
1.648 raeburn 3663: =item * &filedescriptionex()
1.112 bowersj2 3664:
3665: returns description for a specified file type with
3666: extra formatting
3667:
3668: =cut
3669:
3670: sub filedescriptionex {
3671: my $ex=shift;
1.188 matthew 3672: my $file_description = $fd{lc($ex)};
3673: $file_description =~ s:([\[\]]):~$1:g;
3674: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3675: }
3676:
3677: # End of .tab access
3678: =pod
3679:
3680: =back
3681:
3682: =cut
3683:
3684: # ------------------------------------------------------------------ File Types
3685: sub fileextensions {
3686: return sort(keys(%fe));
3687: }
3688:
1.97 www 3689: # ----------------------------------------------------------- Display Languages
3690: # returns a hash with all desired display languages
3691: #
3692:
3693: sub display_languages {
3694: my %languages=();
1.695 raeburn 3695: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3696: $languages{$lang}=1;
1.97 www 3697: }
3698: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3699: if ($env{'form.displaylanguage'}) {
1.356 albertel 3700: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3701: $languages{$lang}=1;
1.97 www 3702: }
3703: }
3704: return %languages;
1.14 harris41 3705: }
3706:
1.582 albertel 3707: sub languages {
3708: my ($possible_langs) = @_;
1.695 raeburn 3709: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3710: if (!ref($possible_langs)) {
3711: if( wantarray ) {
3712: return @preferred_langs;
3713: } else {
3714: return $preferred_langs[0];
3715: }
3716: }
3717: my %possibilities = map { $_ => 1 } (@$possible_langs);
3718: my @preferred_possibilities;
3719: foreach my $preferred_lang (@preferred_langs) {
3720: if (exists($possibilities{$preferred_lang})) {
3721: push(@preferred_possibilities, $preferred_lang);
3722: }
3723: }
3724: if( wantarray ) {
3725: return @preferred_possibilities;
3726: }
3727: return $preferred_possibilities[0];
3728: }
3729:
1.742 raeburn 3730: sub user_lang {
3731: my ($touname,$toudom,$fromcid) = @_;
3732: my @userlangs;
3733: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3734: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3735: $env{'course.'.$fromcid.'.languages'}));
3736: } else {
3737: my %langhash = &getlangs($touname,$toudom);
3738: if ($langhash{'languages'} ne '') {
3739: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3740: } else {
3741: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3742: if ($domdefs{'lang_def'} ne '') {
3743: @userlangs = ($domdefs{'lang_def'});
3744: }
3745: }
3746: }
3747: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
3748: my $user_lh = Apache::localize->get_handle(@languages);
3749: return $user_lh;
3750: }
3751:
3752:
1.112 bowersj2 3753: ###############################################################
3754: ## Student Answer Attempts ##
3755: ###############################################################
3756:
3757: =pod
3758:
3759: =head1 Alternate Problem Views
3760:
3761: =over 4
3762:
1.648 raeburn 3763: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.112 bowersj2 3764: $getattempt, $regexp, $gradesub)
3765:
3766: Return string with previous attempt on problem. Arguments:
3767:
3768: =over 4
3769:
3770: =item * $symb: Problem, including path
3771:
3772: =item * $username: username of the desired student
3773:
3774: =item * $domain: domain of the desired student
1.14 harris41 3775:
1.112 bowersj2 3776: =item * $course: Course ID
1.14 harris41 3777:
1.112 bowersj2 3778: =item * $getattempt: Leave blank for all attempts, otherwise put
3779: something
1.14 harris41 3780:
1.112 bowersj2 3781: =item * $regexp: if string matches this regexp, the string will be
3782: sent to $gradesub
1.14 harris41 3783:
1.112 bowersj2 3784: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 3785:
1.112 bowersj2 3786: =back
1.14 harris41 3787:
1.112 bowersj2 3788: The output string is a table containing all desired attempts, if any.
1.16 harris41 3789:
1.112 bowersj2 3790: =cut
1.1 albertel 3791:
3792: sub get_previous_attempt {
1.43 ng 3793: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub)=@_;
1.1 albertel 3794: my $prevattempts='';
1.43 ng 3795: no strict 'refs';
1.1 albertel 3796: if ($symb) {
1.3 albertel 3797: my (%returnhash)=
3798: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 3799: if ($returnhash{'version'}) {
3800: my %lasthash=();
3801: my $version;
3802: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.356 albertel 3803: foreach my $key (sort(split(/\:/,$returnhash{$version.':keys'}))) {
3804: $lasthash{$key}=$returnhash{$version.':'.$key};
1.19 harris41 3805: }
1.1 albertel 3806: }
1.596 albertel 3807: $prevattempts=&start_data_table().&start_data_table_header_row();
3808: $prevattempts.='<th>'.&mt('History').'</th>';
1.978 raeburn 3809: my (%typeparts,%lasthidden);
1.945 raeburn 3810: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 3811: foreach my $key (sort(keys(%lasthash))) {
3812: my ($ign,@parts) = split(/\./,$key);
1.41 ng 3813: if ($#parts > 0) {
1.31 albertel 3814: my $data=$parts[-1];
1.989 raeburn 3815: next if ($data eq 'foilorder');
1.31 albertel 3816: pop(@parts);
1.1010 www 3817: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 3818: if ($data eq 'type') {
3819: unless ($showsurv) {
3820: my $id = join(',',@parts);
3821: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 3822: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
3823: $lasthidden{$ign.'.'.$id} = 1;
3824: }
1.945 raeburn 3825: }
1.1010 www 3826: }
1.31 albertel 3827: } else {
1.41 ng 3828: if ($#parts == 0) {
3829: $prevattempts.='<th>'.$parts[0].'</th>';
3830: } else {
3831: $prevattempts.='<th>'.$ign.'</th>';
3832: }
1.31 albertel 3833: }
1.16 harris41 3834: }
1.596 albertel 3835: $prevattempts.=&end_data_table_header_row();
1.40 ng 3836: if ($getattempt eq '') {
3837: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.945 raeburn 3838: my @hidden;
3839: if (%typeparts) {
3840: foreach my $id (keys(%typeparts)) {
3841: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') || ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
3842: push(@hidden,$id);
3843: }
3844: }
3845: }
3846: $prevattempts.=&start_data_table_row().
3847: '<td>'.&mt('Transaction [_1]',$version).'</td>';
3848: if (@hidden) {
3849: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3850: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3851: my $hide;
3852: foreach my $id (@hidden) {
3853: if ($key =~ /^\Q$id\E/) {
3854: $hide = 1;
3855: last;
3856: }
3857: }
3858: if ($hide) {
3859: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3860: if (($data eq 'award') || ($data eq 'awarddetail')) {
3861: my $value = &format_previous_attempt_value($key,
3862: $returnhash{$version.':'.$key});
1.1173 kruse 3863: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 3864: } else {
3865: $prevattempts.='<td> </td>';
3866: }
3867: } else {
3868: if ($key =~ /\./) {
3869: my $value = &format_previous_attempt_value($key,
3870: $returnhash{$version.':'.$key});
1.1173 kruse 3871: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 3872: } else {
3873: $prevattempts.='<td> </td>';
3874: }
3875: }
3876: }
3877: } else {
3878: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3879: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3880: my $value = &format_previous_attempt_value($key,
3881: $returnhash{$version.':'.$key});
1.1173 kruse 3882: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 3883: }
3884: }
3885: $prevattempts.=&end_data_table_row();
1.40 ng 3886: }
1.1 albertel 3887: }
1.945 raeburn 3888: my @currhidden = keys(%lasthidden);
1.596 albertel 3889: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 3890: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 3891: next if ($key =~ /\.foilorder$/);
1.945 raeburn 3892: if (%typeparts) {
3893: my $hidden;
3894: foreach my $id (@currhidden) {
3895: if ($key =~ /^\Q$id\E/) {
3896: $hidden = 1;
3897: last;
3898: }
3899: }
3900: if ($hidden) {
3901: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
3902: if (($data eq 'award') || ($data eq 'awarddetail')) {
3903: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3904: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3905: $value = &$gradesub($value);
3906: }
1.1173 kruse 3907: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 3908: } else {
3909: $prevattempts.='<td> </td>';
3910: }
3911: } else {
3912: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3913: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3914: $value = &$gradesub($value);
3915: }
1.1173 kruse 3916: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 3917: }
3918: } else {
3919: my $value = &format_previous_attempt_value($key,$lasthash{$key});
3920: if ($key =~/$regexp$/ && (defined &$gradesub)) {
3921: $value = &$gradesub($value);
3922: }
1.1173 kruse 3923: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 3924: }
1.16 harris41 3925: }
1.596 albertel 3926: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 3927: } else {
1.596 albertel 3928: $prevattempts=
3929: &start_data_table().&start_data_table_row().
3930: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
3931: &end_data_table_row().&end_data_table();
1.1 albertel 3932: }
3933: } else {
1.596 albertel 3934: $prevattempts=
3935: &start_data_table().&start_data_table_row().
3936: '<td>'.&mt('No data.').'</td>'.
3937: &end_data_table_row().&end_data_table();
1.1 albertel 3938: }
1.10 albertel 3939: }
3940:
1.581 albertel 3941: sub format_previous_attempt_value {
3942: my ($key,$value) = @_;
1.1011 www 3943: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 3944: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 3945: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 3946: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 3947: } elsif ($key =~ /answerstring$/) {
3948: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 3949: my @answer = %answers;
3950: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 3951: my @anskeys = sort(keys(%answers));
3952: if (@anskeys == 1) {
3953: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 3954: if ($answer =~ m{\0}) {
3955: $answer =~ s{\0}{,}g;
1.988 raeburn 3956: }
3957: my $tag_internal_answer_name = 'INTERNAL';
3958: if ($anskeys[0] eq $tag_internal_answer_name) {
3959: $value = $answer;
3960: } else {
3961: $value = $anskeys[0].'='.$answer;
3962: }
3963: } else {
3964: foreach my $ans (@anskeys) {
3965: my $answer = $answers{$ans};
1.1001 raeburn 3966: if ($answer =~ m{\0}) {
3967: $answer =~ s{\0}{,}g;
1.988 raeburn 3968: }
3969: $value .= $ans.'='.$answer.'<br />';;
3970: }
3971: }
1.581 albertel 3972: } else {
1.1173 kruse 3973: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 3974: }
3975: return $value;
3976: }
3977:
3978:
1.107 albertel 3979: sub relative_to_absolute {
3980: my ($url,$output)=@_;
3981: my $parser=HTML::TokeParser->new(\$output);
3982: my $token;
3983: my $thisdir=$url;
3984: my @rlinks=();
3985: while ($token=$parser->get_token) {
3986: if ($token->[0] eq 'S') {
3987: if ($token->[1] eq 'a') {
3988: if ($token->[2]->{'href'}) {
3989: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
3990: }
3991: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
3992: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
3993: } elsif ($token->[1] eq 'base') {
3994: $thisdir=$token->[2]->{'href'};
3995: }
3996: }
3997: }
3998: $thisdir=~s-/[^/]*$--;
1.356 albertel 3999: foreach my $link (@rlinks) {
1.726 raeburn 4000: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4001: ($link=~/^\//) ||
4002: ($link=~/^javascript:/i) ||
4003: ($link=~/^mailto:/i) ||
4004: ($link=~/^\#/)) {
4005: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4006: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4007: }
4008: }
4009: # -------------------------------------------------- Deal with Applet codebases
4010: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4011: return $output;
4012: }
4013:
1.112 bowersj2 4014: =pod
4015:
1.648 raeburn 4016: =item * &get_student_view()
1.112 bowersj2 4017:
4018: show a snapshot of what student was looking at
4019:
4020: =cut
4021:
1.10 albertel 4022: sub get_student_view {
1.186 albertel 4023: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4024: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4025: my (%form);
1.10 albertel 4026: my @elements=('symb','courseid','domain','username');
4027: foreach my $element (@elements) {
1.186 albertel 4028: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4029: }
1.186 albertel 4030: if (defined($moreenv)) {
4031: %form=(%form,%{$moreenv});
4032: }
1.236 albertel 4033: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4034: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4035: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4036: $userview=~s/\<body[^\>]*\>//gi;
4037: $userview=~s/\<\/body\>//gi;
4038: $userview=~s/\<html\>//gi;
4039: $userview=~s/\<\/html\>//gi;
4040: $userview=~s/\<head\>//gi;
4041: $userview=~s/\<\/head\>//gi;
4042: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4043: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4044: if (wantarray) {
4045: return ($userview,$response);
4046: } else {
4047: return $userview;
4048: }
4049: }
4050:
4051: sub get_student_view_with_retries {
4052: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4053:
4054: my $ok = 0; # True if we got a good response.
4055: my $content;
4056: my $response;
4057:
4058: # Try to get the student_view done. within the retries count:
4059:
4060: do {
4061: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4062: $ok = $response->is_success;
4063: if (!$ok) {
4064: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4065: }
4066: $retries--;
4067: } while (!$ok && ($retries > 0));
4068:
4069: if (!$ok) {
4070: $content = ''; # On error return an empty content.
4071: }
1.651 www 4072: if (wantarray) {
4073: return ($content, $response);
4074: } else {
4075: return $content;
4076: }
1.11 albertel 4077: }
4078:
1.112 bowersj2 4079: =pod
4080:
1.648 raeburn 4081: =item * &get_student_answers()
1.112 bowersj2 4082:
4083: show a snapshot of how student was answering problem
4084:
4085: =cut
4086:
1.11 albertel 4087: sub get_student_answers {
1.100 sakharuk 4088: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4089: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4090: my (%moreenv);
1.11 albertel 4091: my @elements=('symb','courseid','domain','username');
4092: foreach my $element (@elements) {
1.186 albertel 4093: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4094: }
1.186 albertel 4095: $moreenv{'grade_target'}='answer';
4096: %moreenv=(%form,%moreenv);
1.497 raeburn 4097: $feedurl = &Apache::lonnet::clutter($feedurl);
4098: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4099: return $userview;
1.1 albertel 4100: }
1.116 albertel 4101:
4102: =pod
4103:
4104: =item * &submlink()
4105:
1.242 albertel 4106: Inputs: $text $uname $udom $symb $target
1.116 albertel 4107:
4108: Returns: A link to grades.pm such as to see the SUBM view of a student
4109:
4110: =cut
4111:
4112: ###############################################
4113: sub submlink {
1.242 albertel 4114: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4115: if (!($uname && $udom)) {
4116: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4117: &Apache::lonnet::whichuser($symb);
1.116 albertel 4118: if (!$symb) { $symb=$cursymb; }
4119: }
1.254 matthew 4120: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4121: $symb=&escape($symb);
1.960 bisitz 4122: if ($target) { $target=" target=\"$target\""; }
4123: return
4124: '<a href="/adm/grades?command=submission'.
4125: '&symb='.$symb.
4126: '&student='.$uname.
4127: '&userdom='.$udom.'"'.
4128: $target.'>'.$text.'</a>';
1.242 albertel 4129: }
4130: ##############################################
4131:
4132: =pod
4133:
4134: =item * &pgrdlink()
4135:
4136: Inputs: $text $uname $udom $symb $target
4137:
4138: Returns: A link to grades.pm such as to see the PGRD view of a student
4139:
4140: =cut
4141:
4142: ###############################################
4143: sub pgrdlink {
4144: my $link=&submlink(@_);
4145: $link=~s/(&command=submission)/$1&showgrading=yes/;
4146: return $link;
4147: }
4148: ##############################################
4149:
4150: =pod
4151:
4152: =item * &pprmlink()
4153:
4154: Inputs: $text $uname $udom $symb $target
4155:
4156: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4157: student and a specific resource
1.242 albertel 4158:
4159: =cut
4160:
4161: ###############################################
4162: sub pprmlink {
4163: my ($text,$uname,$udom,$symb,$target)=@_;
4164: if (!($uname && $udom)) {
4165: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4166: &Apache::lonnet::whichuser($symb);
1.242 albertel 4167: if (!$symb) { $symb=$cursymb; }
4168: }
1.254 matthew 4169: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4170: $symb=&escape($symb);
1.242 albertel 4171: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4172: return '<a href="/adm/parmset?command=set&'.
4173: 'symb='.$symb.'&uname='.$uname.
4174: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4175: }
4176: ##############################################
1.37 matthew 4177:
1.112 bowersj2 4178: =pod
4179:
4180: =back
4181:
4182: =cut
4183:
1.37 matthew 4184: ###############################################
1.51 www 4185:
4186:
4187: sub timehash {
1.687 raeburn 4188: my ($thistime) = @_;
4189: my $timezone = &Apache::lonlocal::gettimezone();
4190: my $dt = DateTime->from_epoch(epoch => $thistime)
4191: ->set_time_zone($timezone);
4192: my $wday = $dt->day_of_week();
4193: if ($wday == 7) { $wday = 0; }
4194: return ( 'second' => $dt->second(),
4195: 'minute' => $dt->minute(),
4196: 'hour' => $dt->hour(),
4197: 'day' => $dt->day_of_month(),
4198: 'month' => $dt->month(),
4199: 'year' => $dt->year(),
4200: 'weekday' => $wday,
4201: 'dayyear' => $dt->day_of_year(),
4202: 'dlsav' => $dt->is_dst() );
1.51 www 4203: }
4204:
1.370 www 4205: sub utc_string {
4206: my ($date)=@_;
1.371 www 4207: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4208: }
4209:
1.51 www 4210: sub maketime {
4211: my %th=@_;
1.687 raeburn 4212: my ($epoch_time,$timezone,$dt);
4213: $timezone = &Apache::lonlocal::gettimezone();
4214: eval {
4215: $dt = DateTime->new( year => $th{'year'},
4216: month => $th{'month'},
4217: day => $th{'day'},
4218: hour => $th{'hour'},
4219: minute => $th{'minute'},
4220: second => $th{'second'},
4221: time_zone => $timezone,
4222: );
4223: };
4224: if (!$@) {
4225: $epoch_time = $dt->epoch;
4226: if ($epoch_time) {
4227: return $epoch_time;
4228: }
4229: }
1.51 www 4230: return POSIX::mktime(
4231: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4232: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4233: }
4234:
4235: #########################################
1.51 www 4236:
4237: sub findallcourses {
1.482 raeburn 4238: my ($roles,$uname,$udom) = @_;
1.355 albertel 4239: my %roles;
4240: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4241: my %courses;
1.51 www 4242: my $now=time;
1.482 raeburn 4243: if (!defined($uname)) {
4244: $uname = $env{'user.name'};
4245: }
4246: if (!defined($udom)) {
4247: $udom = $env{'user.domain'};
4248: }
4249: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4250: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4251: if (!%roles) {
4252: %roles = (
4253: cc => 1,
1.907 raeburn 4254: co => 1,
1.482 raeburn 4255: in => 1,
4256: ep => 1,
4257: ta => 1,
4258: cr => 1,
4259: st => 1,
4260: );
4261: }
4262: foreach my $entry (keys(%roleshash)) {
4263: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4264: if ($trole =~ /^cr/) {
4265: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4266: } else {
4267: next if (!exists($roles{$trole}));
4268: }
4269: if ($tend) {
4270: next if ($tend < $now);
4271: }
4272: if ($tstart) {
4273: next if ($tstart > $now);
4274: }
1.1058 raeburn 4275: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4276: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4277: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4278: if ($secpart eq '') {
4279: ($cnum,$role) = split(/_/,$cnumpart);
4280: $sec = 'none';
1.1058 raeburn 4281: $value .= $cnum.'/';
1.482 raeburn 4282: } else {
4283: $cnum = $cnumpart;
4284: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4285: $value .= $cnum.'/'.$sec;
4286: }
4287: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4288: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4289: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4290: }
4291: } else {
4292: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4293: }
1.482 raeburn 4294: }
4295: } else {
4296: foreach my $key (keys(%env)) {
1.483 albertel 4297: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4298: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4299: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4300: next if ($role eq 'ca' || $role eq 'aa');
4301: next if (%roles && !exists($roles{$role}));
4302: my ($starttime,$endtime)=split(/\./,$env{$key});
4303: my $active=1;
4304: if ($starttime) {
4305: if ($now<$starttime) { $active=0; }
4306: }
4307: if ($endtime) {
4308: if ($now>$endtime) { $active=0; }
4309: }
4310: if ($active) {
1.1058 raeburn 4311: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4312: if ($sec eq '') {
4313: $sec = 'none';
1.1058 raeburn 4314: } else {
4315: $value .= $sec;
4316: }
4317: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4318: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4319: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4320: }
4321: } else {
4322: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4323: }
1.474 raeburn 4324: }
4325: }
1.51 www 4326: }
4327: }
1.474 raeburn 4328: return %courses;
1.51 www 4329: }
1.37 matthew 4330:
1.54 www 4331: ###############################################
1.474 raeburn 4332:
4333: sub blockcheck {
1.1189 raeburn 4334: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4335:
1.1189 raeburn 4336: if (defined($udom) && defined($uname)) {
4337: # If uname and udom are for a course, check for blocks in the course.
4338: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4339: my ($startblock,$endblock,$triggerblock) =
4340: &get_blocks($setters,$activity,$udom,$uname,$url);
4341: return ($startblock,$endblock,$triggerblock);
4342: }
4343: } else {
1.490 raeburn 4344: $udom = $env{'user.domain'};
4345: $uname = $env{'user.name'};
4346: }
4347:
1.502 raeburn 4348: my $startblock = 0;
4349: my $endblock = 0;
1.1062 raeburn 4350: my $triggerblock = '';
1.482 raeburn 4351: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4352:
1.490 raeburn 4353: # If uname is for a user, and activity is course-specific, i.e.,
4354: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4355:
1.490 raeburn 4356: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1189 raeburn 4357: $activity eq 'groups' || $activity eq 'printout') &&
4358: ($env{'request.course.id'})) {
1.490 raeburn 4359: foreach my $key (keys(%live_courses)) {
4360: if ($key ne $env{'request.course.id'}) {
4361: delete($live_courses{$key});
4362: }
4363: }
4364: }
4365:
4366: my $otheruser = 0;
4367: my %own_courses;
4368: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4369: # Resource belongs to user other than current user.
4370: $otheruser = 1;
4371: # Gather courses for current user
4372: %own_courses =
4373: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4374: }
4375:
4376: # Gather active course roles - course coordinator, instructor,
4377: # exam proctor, ta, student, or custom role.
1.474 raeburn 4378:
4379: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4380: my ($cdom,$cnum);
4381: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4382: $cdom = $env{'course.'.$course.'.domain'};
4383: $cnum = $env{'course.'.$course.'.num'};
4384: } else {
1.490 raeburn 4385: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4386: }
4387: my $no_ownblock = 0;
4388: my $no_userblock = 0;
1.533 raeburn 4389: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4390: # Check if current user has 'evb' priv for this
4391: if (defined($own_courses{$course})) {
4392: foreach my $sec (keys(%{$own_courses{$course}})) {
4393: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4394: if ($sec ne 'none') {
4395: $checkrole .= '/'.$sec;
4396: }
4397: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4398: $no_ownblock = 1;
4399: last;
4400: }
4401: }
4402: }
4403: # if they have 'evb' priv and are currently not playing student
4404: next if (($no_ownblock) &&
4405: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4406: }
1.474 raeburn 4407: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4408: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4409: if ($sec ne 'none') {
1.482 raeburn 4410: $checkrole .= '/'.$sec;
1.474 raeburn 4411: }
1.490 raeburn 4412: if ($otheruser) {
4413: # Resource belongs to user other than current user.
4414: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4415: my (%allroles,%userroles);
4416: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4417: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4418: my ($trole,$tdom,$tnum,$tsec);
4419: if ($entry =~ /^cr/) {
4420: ($trole,$tdom,$tnum,$tsec) =
4421: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4422: } else {
4423: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4424: }
4425: my ($spec,$area,$trest);
4426: $area = '/'.$tdom.'/'.$tnum;
4427: $trest = $tnum;
4428: if ($tsec ne '') {
4429: $area .= '/'.$tsec;
4430: $trest .= '/'.$tsec;
4431: }
4432: $spec = $trole.'.'.$area;
4433: if ($trole =~ /^cr/) {
4434: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4435: $tdom,$spec,$trest,$area);
4436: } else {
4437: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4438: $tdom,$spec,$trest,$area);
4439: }
4440: }
4441: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4442: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4443: if ($1) {
4444: $no_userblock = 1;
4445: last;
4446: }
1.486 raeburn 4447: }
4448: }
1.490 raeburn 4449: } else {
4450: # Resource belongs to current user
4451: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4452: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4453: $no_ownblock = 1;
4454: last;
4455: }
1.474 raeburn 4456: }
4457: }
4458: # if they have the evb priv and are currently not playing student
1.482 raeburn 4459: next if (($no_ownblock) &&
1.491 albertel 4460: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4461: next if ($no_userblock);
1.474 raeburn 4462:
1.866 kalberla 4463: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4464: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4465:
1.1062 raeburn 4466: my ($start,$end,$trigger) =
4467: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4468: if (($start != 0) &&
4469: (($startblock == 0) || ($startblock > $start))) {
4470: $startblock = $start;
1.1062 raeburn 4471: if ($trigger ne '') {
4472: $triggerblock = $trigger;
4473: }
1.502 raeburn 4474: }
4475: if (($end != 0) &&
4476: (($endblock == 0) || ($endblock < $end))) {
4477: $endblock = $end;
1.1062 raeburn 4478: if ($trigger ne '') {
4479: $triggerblock = $trigger;
4480: }
1.502 raeburn 4481: }
1.490 raeburn 4482: }
1.1062 raeburn 4483: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4484: }
4485:
4486: sub get_blocks {
1.1062 raeburn 4487: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4488: my $startblock = 0;
4489: my $endblock = 0;
1.1062 raeburn 4490: my $triggerblock = '';
1.490 raeburn 4491: my $course = $cdom.'_'.$cnum;
4492: $setters->{$course} = {};
4493: $setters->{$course}{'staff'} = [];
4494: $setters->{$course}{'times'} = [];
1.1062 raeburn 4495: $setters->{$course}{'triggers'} = [];
4496: my (@blockers,%triggered);
4497: my $now = time;
4498: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4499: if ($activity eq 'docs') {
4500: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4501: foreach my $block (@blockers) {
4502: if ($block =~ /^firstaccess____(.+)$/) {
4503: my $item = $1;
4504: my $type = 'map';
4505: my $timersymb = $item;
4506: if ($item eq 'course') {
4507: $type = 'course';
4508: } elsif ($item =~ /___\d+___/) {
4509: $type = 'resource';
4510: } else {
4511: $timersymb = &Apache::lonnet::symbread($item);
4512: }
4513: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4514: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4515: $triggered{$block} = {
4516: start => $start,
4517: end => $end,
4518: type => $type,
4519: };
4520: }
4521: }
4522: } else {
4523: foreach my $block (keys(%commblocks)) {
4524: if ($block =~ m/^(\d+)____(\d+)$/) {
4525: my ($start,$end) = ($1,$2);
4526: if ($start <= time && $end >= time) {
4527: if (ref($commblocks{$block}) eq 'HASH') {
4528: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4529: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4530: unless(grep(/^\Q$block\E$/,@blockers)) {
4531: push(@blockers,$block);
4532: }
4533: }
4534: }
4535: }
4536: }
4537: } elsif ($block =~ /^firstaccess____(.+)$/) {
4538: my $item = $1;
4539: my $timersymb = $item;
4540: my $type = 'map';
4541: if ($item eq 'course') {
4542: $type = 'course';
4543: } elsif ($item =~ /___\d+___/) {
4544: $type = 'resource';
4545: } else {
4546: $timersymb = &Apache::lonnet::symbread($item);
4547: }
4548: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4549: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4550: if ($start && $end) {
4551: if (($start <= time) && ($end >= time)) {
4552: unless (grep(/^\Q$block\E$/,@blockers)) {
4553: push(@blockers,$block);
4554: $triggered{$block} = {
4555: start => $start,
4556: end => $end,
4557: type => $type,
4558: };
4559: }
4560: }
1.490 raeburn 4561: }
1.1062 raeburn 4562: }
4563: }
4564: }
4565: foreach my $blocker (@blockers) {
4566: my ($staff_name,$staff_dom,$title,$blocks) =
4567: &parse_block_record($commblocks{$blocker});
4568: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4569: my ($start,$end,$triggertype);
4570: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4571: ($start,$end) = ($1,$2);
4572: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4573: $start = $triggered{$blocker}{'start'};
4574: $end = $triggered{$blocker}{'end'};
4575: $triggertype = $triggered{$blocker}{'type'};
4576: }
4577: if ($start) {
4578: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4579: if ($triggertype) {
4580: push(@{$$setters{$course}{'triggers'}},$triggertype);
4581: } else {
4582: push(@{$$setters{$course}{'triggers'}},0);
4583: }
4584: if ( ($startblock == 0) || ($startblock > $start) ) {
4585: $startblock = $start;
4586: if ($triggertype) {
4587: $triggerblock = $blocker;
1.474 raeburn 4588: }
4589: }
1.1062 raeburn 4590: if ( ($endblock == 0) || ($endblock < $end) ) {
4591: $endblock = $end;
4592: if ($triggertype) {
4593: $triggerblock = $blocker;
4594: }
4595: }
1.474 raeburn 4596: }
4597: }
1.1062 raeburn 4598: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4599: }
4600:
4601: sub parse_block_record {
4602: my ($record) = @_;
4603: my ($setuname,$setudom,$title,$blocks);
4604: if (ref($record) eq 'HASH') {
4605: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4606: $title = &unescape($record->{'event'});
4607: $blocks = $record->{'blocks'};
4608: } else {
4609: my @data = split(/:/,$record,3);
4610: if (scalar(@data) eq 2) {
4611: $title = $data[1];
4612: ($setuname,$setudom) = split(/@/,$data[0]);
4613: } else {
4614: ($setuname,$setudom,$title) = @data;
4615: }
4616: $blocks = { 'com' => 'on' };
4617: }
4618: return ($setuname,$setudom,$title,$blocks);
4619: }
4620:
1.854 kalberla 4621: sub blocking_status {
1.1189 raeburn 4622: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 4623: my %setters;
1.890 droeschl 4624:
1.1061 raeburn 4625: # check for active blocking
1.1062 raeburn 4626: my ($startblock,$endblock,$triggerblock) =
1.1189 raeburn 4627: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 4628: my $blocked = 0;
4629: if ($startblock && $endblock) {
4630: $blocked = 1;
4631: }
1.890 droeschl 4632:
1.1061 raeburn 4633: # caller just wants to know whether a block is active
4634: if (!wantarray) { return $blocked; }
4635:
4636: # build a link to a popup window containing the details
4637: my $querystring = "?activity=$activity";
4638: # $uname and $udom decide whose portfolio the user is trying to look at
1.1062 raeburn 4639: if ($activity eq 'port') {
4640: $querystring .= "&udom=$udom" if $udom;
4641: $querystring .= "&uname=$uname" if $uname;
4642: } elsif ($activity eq 'docs') {
4643: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4644: }
1.1061 raeburn 4645:
4646: my $output .= <<'END_MYBLOCK';
4647: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4648: var options = "width=" + w + ",height=" + h + ",";
4649: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4650: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4651: var newWin = window.open(url, wdwName, options);
4652: newWin.focus();
4653: }
1.890 droeschl 4654: END_MYBLOCK
1.854 kalberla 4655:
1.1061 raeburn 4656: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4657:
1.1061 raeburn 4658: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4659: my $text = &mt('Communication Blocked');
4660: if ($activity eq 'docs') {
4661: $text = &mt('Content Access Blocked');
1.1063 raeburn 4662: } elsif ($activity eq 'printout') {
4663: $text = &mt('Printing Blocked');
1.1062 raeburn 4664: }
1.1061 raeburn 4665: $output .= <<"END_BLOCK";
1.867 kalberla 4666: <div class='LC_comblock'>
1.869 kalberla 4667: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4668: title='$text'>
4669: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 4670: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 4671: title='$text'>$text</a>
1.867 kalberla 4672: </div>
4673:
4674: END_BLOCK
1.474 raeburn 4675:
1.1061 raeburn 4676: return ($blocked, $output);
1.854 kalberla 4677: }
1.490 raeburn 4678:
1.60 matthew 4679: ###############################################
4680:
1.682 raeburn 4681: sub check_ip_acc {
4682: my ($acc)=@_;
4683: &Apache::lonxml::debug("acc is $acc");
4684: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
4685: return 1;
4686: }
4687: my $allowed=0;
4688: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'};
4689:
4690: my $name;
4691: foreach my $pattern (split(',',$acc)) {
4692: $pattern =~ s/^\s*//;
4693: $pattern =~ s/\s*$//;
4694: if ($pattern =~ /\*$/) {
4695: #35.8.*
4696: $pattern=~s/\*//;
4697: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4698: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
4699: #35.8.3.[34-56]
4700: my $low=$2;
4701: my $high=$3;
4702: $pattern=$1;
4703: if ($ip =~ /^\Q$pattern\E/) {
4704: my $last=(split(/\./,$ip))[3];
4705: if ($last <=$high && $last >=$low) { $allowed=1; }
4706: }
4707: } elsif ($pattern =~ /^\*/) {
4708: #*.msu.edu
4709: $pattern=~s/\*//;
4710: if (!defined($name)) {
4711: use Socket;
4712: my $netaddr=inet_aton($ip);
4713: ($name)=gethostbyaddr($netaddr,AF_INET);
4714: }
4715: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4716: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
4717: #127.0.0.1
4718: if ($ip =~ /^\Q$pattern\E/) { $allowed=1; }
4719: } else {
4720: #some.name.com
4721: if (!defined($name)) {
4722: use Socket;
4723: my $netaddr=inet_aton($ip);
4724: ($name)=gethostbyaddr($netaddr,AF_INET);
4725: }
4726: if ($name =~ /\Q$pattern\E$/i) { $allowed=1; }
4727: }
4728: if ($allowed) { last; }
4729: }
4730: return $allowed;
4731: }
4732:
4733: ###############################################
4734:
1.60 matthew 4735: =pod
4736:
1.112 bowersj2 4737: =head1 Domain Template Functions
4738:
4739: =over 4
4740:
4741: =item * &determinedomain()
1.60 matthew 4742:
4743: Inputs: $domain (usually will be undef)
4744:
1.63 www 4745: Returns: Determines which domain should be used for designs
1.60 matthew 4746:
4747: =cut
1.54 www 4748:
1.60 matthew 4749: ###############################################
1.63 www 4750: sub determinedomain {
4751: my $domain=shift;
1.531 albertel 4752: if (! $domain) {
1.60 matthew 4753: # Determine domain if we have not been given one
1.893 raeburn 4754: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 4755: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
4756: if ($env{'request.role.domain'}) {
4757: $domain=$env{'request.role.domain'};
1.60 matthew 4758: }
4759: }
1.63 www 4760: return $domain;
4761: }
4762: ###############################################
1.517 raeburn 4763:
1.518 albertel 4764: sub devalidate_domconfig_cache {
4765: my ($udom)=@_;
4766: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
4767: }
4768:
4769: # ---------------------- Get domain configuration for a domain
4770: sub get_domainconf {
4771: my ($udom) = @_;
4772: my $cachetime=1800;
4773: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
4774: if (defined($cached)) { return %{$result}; }
4775:
4776: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 4777: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 4778: my (%designhash,%legacy);
1.518 albertel 4779: if (keys(%domconfig) > 0) {
4780: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 4781: if (keys(%{$domconfig{'login'}})) {
4782: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 4783: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.946 raeburn 4784: if ($key eq 'loginvia') {
4785: if (ref($domconfig{'login'}{'loginvia'}) eq 'HASH') {
1.1013 raeburn 4786: foreach my $hostname (keys(%{$domconfig{'login'}{'loginvia'}})) {
1.948 raeburn 4787: if (ref($domconfig{'login'}{'loginvia'}{$hostname}) eq 'HASH') {
4788: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
4789: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
4790: $designhash{$udom.'.login.loginvia'} = $server;
4791: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
4792:
4793: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
4794: } else {
1.1013 raeburn 4795: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
1.948 raeburn 4796: }
4797: if ($domconfig{'login'}{'loginvia'}{$hostname}{'exempt'}) {
4798: $designhash{$udom.'.login.loginvia_exempt_'.$hostname} = $domconfig{'login'}{'loginvia'}{$hostname}{'exempt'};
4799: }
1.946 raeburn 4800: }
4801: }
4802: }
4803: }
4804: } else {
4805: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
4806: $designhash{$udom.'.login.'.$key.'_'.$img} =
4807: $domconfig{'login'}{$key}{$img};
4808: }
1.699 raeburn 4809: }
4810: } else {
4811: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
4812: }
1.632 raeburn 4813: }
4814: } else {
4815: $legacy{'login'} = 1;
1.518 albertel 4816: }
1.632 raeburn 4817: } else {
4818: $legacy{'login'} = 1;
1.518 albertel 4819: }
4820: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 4821: if (keys(%{$domconfig{'rolecolors'}})) {
4822: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
4823: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
4824: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
4825: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
4826: }
1.518 albertel 4827: }
4828: }
1.632 raeburn 4829: } else {
4830: $legacy{'rolecolors'} = 1;
1.518 albertel 4831: }
1.632 raeburn 4832: } else {
4833: $legacy{'rolecolors'} = 1;
1.518 albertel 4834: }
1.948 raeburn 4835: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
4836: if ($domconfig{'autoenroll'}{'co-owners'}) {
4837: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
4838: }
4839: }
1.632 raeburn 4840: if (keys(%legacy) > 0) {
4841: my %legacyhash = &get_legacy_domconf($udom);
4842: foreach my $item (keys(%legacyhash)) {
4843: if ($item =~ /^\Q$udom\E\.login/) {
4844: if ($legacy{'login'}) {
4845: $designhash{$item} = $legacyhash{$item};
4846: }
4847: } else {
4848: if ($legacy{'rolecolors'}) {
4849: $designhash{$item} = $legacyhash{$item};
4850: }
1.518 albertel 4851: }
4852: }
4853: }
1.632 raeburn 4854: } else {
4855: %designhash = &get_legacy_domconf($udom);
1.518 albertel 4856: }
4857: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
4858: $cachetime);
4859: return %designhash;
4860: }
4861:
1.632 raeburn 4862: sub get_legacy_domconf {
4863: my ($udom) = @_;
4864: my %legacyhash;
4865: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
4866: my $designfile = $designdir.'/'.$udom.'.tab';
4867: if (-e $designfile) {
4868: if ( open (my $fh,"<$designfile") ) {
4869: while (my $line = <$fh>) {
4870: next if ($line =~ /^\#/);
4871: chomp($line);
4872: my ($key,$val)=(split(/\=/,$line));
4873: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
4874: }
4875: close($fh);
4876: }
4877: }
1.1026 raeburn 4878: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 4879: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
4880: }
4881: return %legacyhash;
4882: }
4883:
1.63 www 4884: =pod
4885:
1.112 bowersj2 4886: =item * &domainlogo()
1.63 www 4887:
4888: Inputs: $domain (usually will be undef)
4889:
4890: Returns: A link to a domain logo, if the domain logo exists.
4891: If the domain logo does not exist, a description of the domain.
4892:
4893: =cut
1.112 bowersj2 4894:
1.63 www 4895: ###############################################
4896: sub domainlogo {
1.517 raeburn 4897: my $domain = &determinedomain(shift);
1.518 albertel 4898: my %designhash = &get_domainconf($domain);
1.517 raeburn 4899: # See if there is a logo
4900: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 4901: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 4902: if ($imgsrc =~ m{^/(adm|res)/}) {
4903: if ($imgsrc =~ m{^/res/}) {
4904: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
4905: &Apache::lonnet::repcopy($local_name);
4906: }
4907: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 4908: }
4909: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 4910: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
4911: return &Apache::lonnet::domain($domain,'description');
1.59 www 4912: } else {
1.60 matthew 4913: return '';
1.59 www 4914: }
4915: }
1.63 www 4916: ##############################################
4917:
4918: =pod
4919:
1.112 bowersj2 4920: =item * &designparm()
1.63 www 4921:
4922: Inputs: $which parameter; $domain (usually will be undef)
4923:
4924: Returns: value of designparamter $which
4925:
4926: =cut
1.112 bowersj2 4927:
1.397 albertel 4928:
1.400 albertel 4929: ##############################################
1.397 albertel 4930: sub designparm {
4931: my ($which,$domain)=@_;
4932: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 4933: return $env{'environment.color.'.$which};
1.96 www 4934: }
1.63 www 4935: $domain=&determinedomain($domain);
1.1016 raeburn 4936: my %domdesign;
4937: unless ($domain eq 'public') {
4938: %domdesign = &get_domainconf($domain);
4939: }
1.520 raeburn 4940: my $output;
1.517 raeburn 4941: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 4942: $output = $domdesign{$domain.'.'.$which};
1.63 www 4943: } else {
1.520 raeburn 4944: $output = $defaultdesign{$which};
4945: }
4946: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 4947: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 4948: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 4949: if ($output =~ m{^/res/}) {
4950: my $local_name = &Apache::lonnet::filelocation('',$output);
4951: &Apache::lonnet::repcopy($local_name);
4952: }
1.520 raeburn 4953: $output = &lonhttpdurl($output);
4954: }
1.63 www 4955: }
1.520 raeburn 4956: return $output;
1.63 www 4957: }
1.59 www 4958:
1.822 bisitz 4959: ##############################################
4960: =pod
4961:
1.832 bisitz 4962: =item * &authorspace()
4963:
1.1028 raeburn 4964: Inputs: $url (usually will be undef).
1.832 bisitz 4965:
1.1132 raeburn 4966: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 4967: directory being viewed (or for which action is being taken).
4968: If $url is provided, and begins /priv/<domain>/<uname>
4969: the path will be that portion of the $context argument.
4970: Otherwise the path will be for the author space of the current
4971: user when the current role is author, or for that of the
4972: co-author/assistant co-author space when the current role
4973: is co-author or assistant co-author.
1.832 bisitz 4974:
4975: =cut
4976:
4977: sub authorspace {
1.1028 raeburn 4978: my ($url) = @_;
4979: if ($url ne '') {
4980: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
4981: return $1;
4982: }
4983: }
1.832 bisitz 4984: my $caname = '';
1.1024 www 4985: my $cadom = '';
1.1028 raeburn 4986: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 4987: ($cadom,$caname) =
1.832 bisitz 4988: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 4989: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 4990: $caname = $env{'user.name'};
1.1024 www 4991: $cadom = $env{'user.domain'};
1.832 bisitz 4992: }
1.1028 raeburn 4993: if (($caname ne '') && ($cadom ne '')) {
4994: return "/priv/$cadom/$caname/";
4995: }
4996: return;
1.832 bisitz 4997: }
4998:
4999: ##############################################
5000: =pod
5001:
1.822 bisitz 5002: =item * &head_subbox()
5003:
5004: Inputs: $content (contains HTML code with page functions, etc.)
5005:
5006: Returns: HTML div with $content
5007: To be included in page header
5008:
5009: =cut
5010:
5011: sub head_subbox {
5012: my ($content)=@_;
5013: my $output =
1.993 raeburn 5014: '<div class="LC_head_subbox">'
1.822 bisitz 5015: .$content
5016: .'</div>'
5017: }
5018:
5019: ##############################################
5020: =pod
5021:
5022: =item * &CSTR_pageheader()
5023:
1.1026 raeburn 5024: Input: (optional) filename from which breadcrumb trail is built.
5025: In most cases no input as needed, as $env{'request.filename'}
5026: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5027:
5028: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5029: To be included on Authoring Space pages
1.822 bisitz 5030:
5031: =cut
5032:
5033: sub CSTR_pageheader {
1.1026 raeburn 5034: my ($trailfile) = @_;
5035: if ($trailfile eq '') {
5036: $trailfile = $env{'request.filename'};
5037: }
5038:
5039: # this is for resources; directories have customtitle, and crumbs
5040: # and select recent are created in lonpubdir.pm
5041:
5042: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5043: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5044: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5045: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5046: $formaction =~ s{/+}{/}g;
1.822 bisitz 5047:
5048: my $parentpath = '';
5049: my $lastitem = '';
5050: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5051: $parentpath = $1;
5052: $lastitem = $2;
5053: } else {
5054: $lastitem = $thisdisfn;
5055: }
1.921 bisitz 5056:
5057: my $output =
1.822 bisitz 5058: '<div>'
5059: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1132 raeburn 5060: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5061: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5062: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5063: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5064:
5065: if ($lastitem) {
5066: $output .=
5067: '<span class="LC_filename">'
5068: .$lastitem
5069: .'</span>';
5070: }
5071: $output .=
5072: '<br />'
1.822 bisitz 5073: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5074: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5075: .'</form>'
5076: .&Apache::lonmenu::constspaceform()
5077: .'</div>';
1.921 bisitz 5078:
5079: return $output;
1.822 bisitz 5080: }
5081:
1.60 matthew 5082: ###############################################
5083: ###############################################
5084:
5085: =pod
5086:
1.112 bowersj2 5087: =back
5088:
1.549 albertel 5089: =head1 HTML Helpers
1.112 bowersj2 5090:
5091: =over 4
5092:
5093: =item * &bodytag()
1.60 matthew 5094:
5095: Returns a uniform header for LON-CAPA web pages.
5096:
5097: Inputs:
5098:
1.112 bowersj2 5099: =over 4
5100:
5101: =item * $title, A title to be displayed on the page.
5102:
5103: =item * $function, the current role (can be undef).
5104:
5105: =item * $addentries, extra parameters for the <body> tag.
5106:
5107: =item * $bodyonly, if defined, only return the <body> tag.
5108:
5109: =item * $domain, if defined, force a given domain.
5110:
5111: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5112: text interface only)
1.60 matthew 5113:
1.814 bisitz 5114: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5115: navigational links
1.317 albertel 5116:
1.338 albertel 5117: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5118:
1.460 albertel 5119: =item * $args, optional argument valid values are
5120: no_auto_mt_title -> prevents &mt()ing the title arg
1.562 albertel 5121: inherit_jsmath -> when creating popup window in a page,
5122: should it have jsmath forced on by the
5123: current page
1.460 albertel 5124:
1.1096 raeburn 5125: =item * $advtoolsref, optional argument, ref to an array containing
5126: inlineremote items to be added in "Functions" menu below
5127: breadcrumbs.
5128:
1.112 bowersj2 5129: =back
5130:
1.60 matthew 5131: Returns: A uniform header for LON-CAPA web pages.
5132: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5133: If $bodyonly is undef or zero, an html string containing a <body> tag and
5134: other decorations will be returned.
5135:
5136: =cut
5137:
1.54 www 5138: sub bodytag {
1.831 bisitz 5139: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5140: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5141:
1.954 raeburn 5142: my $public;
5143: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5144: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5145: $public = 1;
5146: }
1.460 albertel 5147: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 5148: my $httphost = $args->{'use_absolute'};
1.339 albertel 5149:
1.183 matthew 5150: $function = &get_users_function() if (!$function);
1.339 albertel 5151: my $img = &designparm($function.'.img',$domain);
5152: my $font = &designparm($function.'.font',$domain);
5153: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5154:
1.803 bisitz 5155: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5156: 'bgcolor' => $pgbg,
1.339 albertel 5157: 'text' => $font,
5158: 'alink' => &designparm($function.'.alink',$domain),
5159: 'vlink' => &designparm($function.'.vlink',$domain),
5160: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5161: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5162:
1.63 www 5163: # role and realm
1.1178 raeburn 5164: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5165: if ($realm) {
5166: $realm = '/'.$realm;
5167: }
1.378 raeburn 5168: if ($role eq 'ca') {
1.479 albertel 5169: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5170: $realm = &plainname($rname,$rdom);
1.378 raeburn 5171: }
1.55 www 5172: # realm
1.258 albertel 5173: if ($env{'request.course.id'}) {
1.378 raeburn 5174: if ($env{'request.role'} !~ /^cr/) {
5175: $role = &Apache::lonnet::plaintext($role,&course_type());
5176: }
1.898 raeburn 5177: if ($env{'request.course.sec'}) {
5178: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5179: }
1.359 albertel 5180: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5181: } else {
5182: $role = &Apache::lonnet::plaintext($role);
1.54 www 5183: }
1.433 albertel 5184:
1.359 albertel 5185: if (!$realm) { $realm=' '; }
1.330 albertel 5186:
1.438 albertel 5187: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5188:
1.101 www 5189: # construct main body tag
1.359 albertel 5190: my $bodytag = "<body $extra_body_attr>".
1.562 albertel 5191: &Apache::lontexconvert::init_math_support($args->{'inherit_jsmath'});
1.252 albertel 5192:
1.1131 raeburn 5193: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5194:
1.1130 raeburn 5195: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5196: return $bodytag;
1.1130 raeburn 5197: }
1.359 albertel 5198:
1.954 raeburn 5199: if ($public) {
1.433 albertel 5200: undef($role);
5201: }
1.359 albertel 5202:
1.762 bisitz 5203: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5204: #
5205: # Extra info if you are the DC
5206: my $dc_info = '';
5207: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5208: $env{'course.'.$env{'request.course.id'}.
5209: '.domain'}.'/'})) {
5210: my $cid = $env{'request.course.id'};
1.917 raeburn 5211: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5212: $dc_info =~ s/\s+$//;
1.359 albertel 5213: }
5214:
1.898 raeburn 5215: $role = '<span class="LC_nobreak">('.$role.')</span>' if $role;
1.853 droeschl 5216:
1.903 droeschl 5217: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5218:
5219: # if ($env{'request.state'} eq 'construct') {
5220: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5221: # }
5222:
1.1130 raeburn 5223: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 5224: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5225:
1.1130 raeburn 5226: my ($left,$right) = Apache::lonmenu::primary_menu();
1.359 albertel 5227:
1.916 droeschl 5228: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5229: if ($dc_info) {
5230: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5231: }
1.1130 raeburn 5232: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 5233: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5234: return $bodytag;
5235: }
1.894 droeschl 5236:
1.927 raeburn 5237: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 5238: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5239: }
1.916 droeschl 5240:
1.1130 raeburn 5241: $bodytag .= $right;
1.852 droeschl 5242:
1.917 raeburn 5243: if ($dc_info) {
5244: $dc_info = &dc_courseid_toggle($dc_info);
5245: }
5246: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5247:
1.1169 raeburn 5248: #if directed to not display the secondary menu, don't.
1.1168 raeburn 5249: if ($args->{'no_secondary_menu'}) {
5250: return $bodytag;
5251: }
1.1169 raeburn 5252: #don't show menus for public users
1.954 raeburn 5253: if (!$public){
1.1154 raeburn 5254: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5255: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5256: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5257: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5258: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5259: $args->{'bread_crumbs'});
1.1096 raeburn 5260: } elsif ($forcereg) {
5261: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5262: $args->{'group'});
5263: } else {
5264: $bodytag .=
5265: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5266: $forcereg,$args->{'group'},
5267: $args->{'bread_crumbs'},
5268: $advtoolsref);
1.920 raeburn 5269: }
1.903 droeschl 5270: }else{
5271: # this is to seperate menu from content when there's no secondary
5272: # menu. Especially needed for public accessible ressources.
5273: $bodytag .= '<hr style="clear:both" />';
5274: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5275: }
1.903 droeschl 5276:
1.235 raeburn 5277: return $bodytag;
1.182 matthew 5278: }
5279:
1.917 raeburn 5280: sub dc_courseid_toggle {
5281: my ($dc_info) = @_;
1.980 raeburn 5282: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5283: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5284: &mt('(More ...)').'</a></span>'.
5285: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5286: }
5287:
1.330 albertel 5288: sub make_attr_string {
5289: my ($register,$attr_ref) = @_;
5290:
5291: if ($attr_ref && !ref($attr_ref)) {
5292: die("addentries Must be a hash ref ".
5293: join(':',caller(1))." ".
5294: join(':',caller(0))." ");
5295: }
5296:
5297: if ($register) {
1.339 albertel 5298: my ($on_load,$on_unload);
5299: foreach my $key (keys(%{$attr_ref})) {
5300: if (lc($key) eq 'onload') {
5301: $on_load.=$attr_ref->{$key}.';';
5302: delete($attr_ref->{$key});
5303:
5304: } elsif (lc($key) eq 'onunload') {
5305: $on_unload.=$attr_ref->{$key}.';';
5306: delete($attr_ref->{$key});
5307: }
5308: }
1.953 droeschl 5309: $attr_ref->{'onload'} = $on_load;
5310: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 5311: }
1.339 albertel 5312:
1.330 albertel 5313: my $attr_string;
1.1159 raeburn 5314: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5315: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5316: }
5317: return $attr_string;
5318: }
5319:
5320:
1.182 matthew 5321: ###############################################
1.251 albertel 5322: ###############################################
5323:
5324: =pod
5325:
5326: =item * &endbodytag()
5327:
5328: Returns a uniform footer for LON-CAPA web pages.
5329:
1.635 raeburn 5330: Inputs: 1 - optional reference to an args hash
5331: If in the hash, key for noredirectlink has a value which evaluates to true,
5332: a 'Continue' link is not displayed if the page contains an
5333: internal redirect in the <head></head> section,
5334: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5335:
5336: =cut
5337:
5338: sub endbodytag {
1.635 raeburn 5339: my ($args) = @_;
1.1080 raeburn 5340: my $endbodytag;
5341: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5342: $endbodytag='</body>';
5343: }
1.269 albertel 5344: $endbodytag=&Apache::lontexconvert::jsMath_process()."\n".$endbodytag;
1.315 albertel 5345: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5346: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5347: $endbodytag=
5348: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5349: &mt('Continue').'</a>'.
5350: $endbodytag;
5351: }
1.315 albertel 5352: }
1.251 albertel 5353: return $endbodytag;
5354: }
5355:
1.352 albertel 5356: =pod
5357:
5358: =item * &standard_css()
5359:
5360: Returns a style sheet
5361:
5362: Inputs: (all optional)
5363: domain -> force to color decorate a page for a specific
5364: domain
5365: function -> force usage of a specific rolish color scheme
5366: bgcolor -> override the default page bgcolor
5367:
5368: =cut
5369:
1.343 albertel 5370: sub standard_css {
1.345 albertel 5371: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5372: $function = &get_users_function() if (!$function);
5373: my $img = &designparm($function.'.img', $domain);
5374: my $tabbg = &designparm($function.'.tabbg', $domain);
5375: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5376: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5377: #second colour for later usage
1.345 albertel 5378: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5379: my $pgbg_or_bgcolor =
5380: $bgcolor ||
1.352 albertel 5381: &designparm($function.'.pgbg', $domain);
1.382 albertel 5382: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5383: my $alink = &designparm($function.'.alink', $domain);
5384: my $vlink = &designparm($function.'.vlink', $domain);
5385: my $link = &designparm($function.'.link', $domain);
5386:
1.602 albertel 5387: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5388: my $mono = 'monospace';
1.850 bisitz 5389: my $data_table_head = $sidebg;
5390: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5391: my $data_table_dark = '#E0E0E0';
1.470 banghart 5392: my $data_table_darker = '#CCCCCC';
1.349 albertel 5393: my $data_table_highlight = '#FFFF00';
1.352 albertel 5394: my $mail_new = '#FFBB77';
5395: my $mail_new_hover = '#DD9955';
5396: my $mail_read = '#BBBB77';
5397: my $mail_read_hover = '#999944';
5398: my $mail_replied = '#AAAA88';
5399: my $mail_replied_hover = '#888855';
5400: my $mail_other = '#99BBBB';
5401: my $mail_other_hover = '#669999';
1.391 albertel 5402: my $table_header = '#DDDDDD';
1.489 raeburn 5403: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5404: my $lg_border_color = '#C8C8C8';
1.952 onken 5405: my $button_hover = '#BF2317';
1.392 albertel 5406:
1.608 albertel 5407: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5408: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5409: : '0 3px 0 4px';
1.448 albertel 5410:
1.523 albertel 5411:
1.343 albertel 5412: return <<END;
1.947 droeschl 5413:
5414: /* needed for iframe to allow 100% height in FF */
5415: body, html {
5416: margin: 0;
5417: padding: 0 0.5%;
5418: height: 99%; /* to avoid scrollbars */
5419: }
5420:
1.795 www 5421: body {
1.911 bisitz 5422: font-family: $sans;
5423: line-height:130%;
5424: font-size:0.83em;
5425: color:$font;
1.795 www 5426: }
5427:
1.959 onken 5428: a:focus,
5429: a:focus img {
1.795 www 5430: color: red;
5431: }
1.698 harmsja 5432:
1.911 bisitz 5433: form, .inline {
5434: display: inline;
1.795 www 5435: }
1.721 harmsja 5436:
1.795 www 5437: .LC_right {
1.911 bisitz 5438: text-align:right;
1.795 www 5439: }
5440:
5441: .LC_middle {
1.911 bisitz 5442: vertical-align:middle;
1.795 www 5443: }
1.721 harmsja 5444:
1.1130 raeburn 5445: .LC_floatleft {
5446: float: left;
5447: }
5448:
5449: .LC_floatright {
5450: float: right;
5451: }
5452:
1.911 bisitz 5453: .LC_400Box {
5454: width:400px;
5455: }
1.721 harmsja 5456:
1.947 droeschl 5457: .LC_iframecontainer {
5458: width: 98%;
5459: margin: 0;
5460: position: fixed;
5461: top: 8.5em;
5462: bottom: 0;
5463: }
5464:
5465: .LC_iframecontainer iframe{
5466: border: none;
5467: width: 100%;
5468: height: 100%;
5469: }
5470:
1.778 bisitz 5471: .LC_filename {
5472: font-family: $mono;
5473: white-space:pre;
1.921 bisitz 5474: font-size: 120%;
1.778 bisitz 5475: }
5476:
5477: .LC_fileicon {
5478: border: none;
5479: height: 1.3em;
5480: vertical-align: text-bottom;
5481: margin-right: 0.3em;
5482: text-decoration:none;
5483: }
5484:
1.1008 www 5485: .LC_setting {
5486: text-decoration:underline;
5487: }
5488:
1.350 albertel 5489: .LC_error {
5490: color: red;
5491: }
1.795 www 5492:
1.1097 bisitz 5493: .LC_warning {
5494: color: darkorange;
5495: }
5496:
1.457 albertel 5497: .LC_diff_removed {
1.733 bisitz 5498: color: red;
1.394 albertel 5499: }
1.532 albertel 5500:
5501: .LC_info,
1.457 albertel 5502: .LC_success,
5503: .LC_diff_added {
1.350 albertel 5504: color: green;
5505: }
1.795 www 5506:
1.802 bisitz 5507: div.LC_confirm_box {
5508: background-color: #FAFAFA;
5509: border: 1px solid $lg_border_color;
5510: margin-right: 0;
5511: padding: 5px;
5512: }
5513:
5514: div.LC_confirm_box .LC_error img,
5515: div.LC_confirm_box .LC_success img {
5516: vertical-align: middle;
5517: }
5518:
1.440 albertel 5519: .LC_icon {
1.771 droeschl 5520: border: none;
1.790 droeschl 5521: vertical-align: middle;
1.771 droeschl 5522: }
5523:
1.543 albertel 5524: .LC_docs_spacer {
5525: width: 25px;
5526: height: 1px;
1.771 droeschl 5527: border: none;
1.543 albertel 5528: }
1.346 albertel 5529:
1.532 albertel 5530: .LC_internal_info {
1.735 bisitz 5531: color: #999999;
1.532 albertel 5532: }
5533:
1.794 www 5534: .LC_discussion {
1.1050 www 5535: background: $data_table_dark;
1.911 bisitz 5536: border: 1px solid black;
5537: margin: 2px;
1.794 www 5538: }
5539:
5540: .LC_disc_action_left {
1.1050 www 5541: background: $sidebg;
1.911 bisitz 5542: text-align: left;
1.1050 www 5543: padding: 4px;
5544: margin: 2px;
1.794 www 5545: }
5546:
5547: .LC_disc_action_right {
1.1050 www 5548: background: $sidebg;
1.911 bisitz 5549: text-align: right;
1.1050 www 5550: padding: 4px;
5551: margin: 2px;
1.794 www 5552: }
5553:
5554: .LC_disc_new_item {
1.911 bisitz 5555: background: white;
5556: border: 2px solid red;
1.1050 www 5557: margin: 4px;
5558: padding: 4px;
1.794 www 5559: }
5560:
5561: .LC_disc_old_item {
1.911 bisitz 5562: background: white;
1.1050 www 5563: margin: 4px;
5564: padding: 4px;
1.794 www 5565: }
5566:
1.458 albertel 5567: table.LC_pastsubmission {
5568: border: 1px solid black;
5569: margin: 2px;
5570: }
5571:
1.924 bisitz 5572: table#LC_menubuttons {
1.345 albertel 5573: width: 100%;
5574: background: $pgbg;
1.392 albertel 5575: border: 2px;
1.402 albertel 5576: border-collapse: separate;
1.803 bisitz 5577: padding: 0;
1.345 albertel 5578: }
1.392 albertel 5579:
1.801 tempelho 5580: table#LC_title_bar a {
5581: color: $fontmenu;
5582: }
1.836 bisitz 5583:
1.807 droeschl 5584: table#LC_title_bar {
1.819 tempelho 5585: clear: both;
1.836 bisitz 5586: display: none;
1.807 droeschl 5587: }
5588:
1.795 www 5589: table#LC_title_bar,
1.933 droeschl 5590: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5591: table#LC_title_bar.LC_with_remote {
1.359 albertel 5592: width: 100%;
1.392 albertel 5593: border-color: $pgbg;
5594: border-style: solid;
5595: border-width: $border;
1.379 albertel 5596: background: $pgbg;
1.801 tempelho 5597: color: $fontmenu;
1.392 albertel 5598: border-collapse: collapse;
1.803 bisitz 5599: padding: 0;
1.819 tempelho 5600: margin: 0;
1.359 albertel 5601: }
1.795 www 5602:
1.933 droeschl 5603: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5604: margin: 0;
5605: padding: 0;
1.933 droeschl 5606: position: relative;
5607: list-style: none;
1.913 droeschl 5608: }
1.933 droeschl 5609: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5610: display: inline;
5611: }
1.933 droeschl 5612:
5613: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5614: padding: 0;
1.933 droeschl 5615: margin: 0;
5616: float: left;
1.913 droeschl 5617: }
1.933 droeschl 5618: .LC_breadcrumb_tools_tools {
5619: padding: 0;
5620: margin: 0;
1.913 droeschl 5621: float: right;
5622: }
5623:
1.359 albertel 5624: table#LC_title_bar td {
5625: background: $tabbg;
5626: }
1.795 www 5627:
1.911 bisitz 5628: table#LC_menubuttons img {
1.803 bisitz 5629: border: none;
1.346 albertel 5630: }
1.795 www 5631:
1.842 droeschl 5632: .LC_breadcrumbs_component {
1.911 bisitz 5633: float: right;
5634: margin: 0 1em;
1.357 albertel 5635: }
1.842 droeschl 5636: .LC_breadcrumbs_component img {
1.911 bisitz 5637: vertical-align: middle;
1.777 tempelho 5638: }
1.795 www 5639:
1.383 albertel 5640: td.LC_table_cell_checkbox {
5641: text-align: center;
5642: }
1.795 www 5643:
5644: .LC_fontsize_small {
1.911 bisitz 5645: font-size: 70%;
1.705 tempelho 5646: }
5647:
1.844 bisitz 5648: #LC_breadcrumbs {
1.911 bisitz 5649: clear:both;
5650: background: $sidebg;
5651: border-bottom: 1px solid $lg_border_color;
5652: line-height: 2.5em;
1.933 droeschl 5653: overflow: hidden;
1.911 bisitz 5654: margin: 0;
5655: padding: 0;
1.995 raeburn 5656: text-align: left;
1.819 tempelho 5657: }
1.862 bisitz 5658:
1.1098 bisitz 5659: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 5660: clear:both;
5661: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 5662: border: 1px solid $sidebg;
1.1098 bisitz 5663: margin: 0 0 10px 0;
1.966 bisitz 5664: padding: 3px;
1.995 raeburn 5665: text-align: left;
1.822 bisitz 5666: }
5667:
1.795 www 5668: .LC_fontsize_medium {
1.911 bisitz 5669: font-size: 85%;
1.705 tempelho 5670: }
5671:
1.795 www 5672: .LC_fontsize_large {
1.911 bisitz 5673: font-size: 120%;
1.705 tempelho 5674: }
5675:
1.346 albertel 5676: .LC_menubuttons_inline_text {
5677: color: $font;
1.698 harmsja 5678: font-size: 90%;
1.701 harmsja 5679: padding-left:3px;
1.346 albertel 5680: }
5681:
1.934 droeschl 5682: .LC_menubuttons_inline_text img{
5683: vertical-align: middle;
5684: }
5685:
1.1051 www 5686: li.LC_menubuttons_inline_text img {
1.951 onken 5687: cursor:pointer;
1.1002 droeschl 5688: text-decoration: none;
1.951 onken 5689: }
5690:
1.526 www 5691: .LC_menubuttons_link {
5692: text-decoration: none;
5693: }
1.795 www 5694:
1.522 albertel 5695: .LC_menubuttons_category {
1.521 www 5696: color: $font;
1.526 www 5697: background: $pgbg;
1.521 www 5698: font-size: larger;
5699: font-weight: bold;
5700: }
5701:
1.346 albertel 5702: td.LC_menubuttons_text {
1.911 bisitz 5703: color: $font;
1.346 albertel 5704: }
1.706 harmsja 5705:
1.346 albertel 5706: .LC_current_location {
5707: background: $tabbg;
5708: }
1.795 www 5709:
1.938 bisitz 5710: table.LC_data_table {
1.347 albertel 5711: border: 1px solid #000000;
1.402 albertel 5712: border-collapse: separate;
1.426 albertel 5713: border-spacing: 1px;
1.610 albertel 5714: background: $pgbg;
1.347 albertel 5715: }
1.795 www 5716:
1.422 albertel 5717: .LC_data_table_dense {
5718: font-size: small;
5719: }
1.795 www 5720:
1.507 raeburn 5721: table.LC_nested_outer {
5722: border: 1px solid #000000;
1.589 raeburn 5723: border-collapse: collapse;
1.803 bisitz 5724: border-spacing: 0;
1.507 raeburn 5725: width: 100%;
5726: }
1.795 www 5727:
1.879 raeburn 5728: table.LC_innerpickbox,
1.507 raeburn 5729: table.LC_nested {
1.803 bisitz 5730: border: none;
1.589 raeburn 5731: border-collapse: collapse;
1.803 bisitz 5732: border-spacing: 0;
1.507 raeburn 5733: width: 100%;
5734: }
1.795 www 5735:
1.911 bisitz 5736: table.LC_data_table tr th,
5737: table.LC_calendar tr th,
1.879 raeburn 5738: table.LC_prior_tries tr th,
5739: table.LC_innerpickbox tr th {
1.349 albertel 5740: font-weight: bold;
5741: background-color: $data_table_head;
1.801 tempelho 5742: color:$fontmenu;
1.701 harmsja 5743: font-size:90%;
1.347 albertel 5744: }
1.795 www 5745:
1.879 raeburn 5746: table.LC_innerpickbox tr th,
5747: table.LC_innerpickbox tr td {
5748: vertical-align: top;
5749: }
5750:
1.711 raeburn 5751: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 5752: background-color: #CCCCCC;
1.711 raeburn 5753: font-weight: bold;
5754: text-align: left;
5755: }
1.795 www 5756:
1.912 bisitz 5757: table.LC_data_table tr.LC_odd_row > td {
5758: background-color: $data_table_light;
5759: padding: 2px;
5760: vertical-align: top;
5761: }
5762:
1.809 bisitz 5763: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 5764: background-color: $data_table_light;
1.912 bisitz 5765: vertical-align: top;
5766: }
5767:
5768: table.LC_data_table tr.LC_even_row > td {
5769: background-color: $data_table_dark;
1.425 albertel 5770: padding: 2px;
1.900 bisitz 5771: vertical-align: top;
1.347 albertel 5772: }
1.795 www 5773:
1.809 bisitz 5774: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 5775: background-color: $data_table_dark;
1.900 bisitz 5776: vertical-align: top;
1.347 albertel 5777: }
1.795 www 5778:
1.425 albertel 5779: table.LC_data_table tr.LC_data_table_highlight td {
5780: background-color: $data_table_darker;
5781: }
1.795 www 5782:
1.639 raeburn 5783: table.LC_data_table tr td.LC_leftcol_header {
5784: background-color: $data_table_head;
5785: font-weight: bold;
5786: }
1.795 www 5787:
1.451 albertel 5788: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 5789: table.LC_nested tr.LC_empty_row td {
1.421 albertel 5790: font-weight: bold;
5791: font-style: italic;
5792: text-align: center;
5793: padding: 8px;
1.347 albertel 5794: }
1.795 www 5795:
1.1114 raeburn 5796: table.LC_data_table tr.LC_empty_row td,
5797: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 5798: background-color: $sidebg;
5799: }
5800:
5801: table.LC_nested tr.LC_empty_row td {
5802: background-color: #FFFFFF;
5803: }
5804:
1.890 droeschl 5805: table.LC_caption {
5806: }
5807:
1.507 raeburn 5808: table.LC_nested tr.LC_empty_row td {
1.465 albertel 5809: padding: 4ex
5810: }
1.795 www 5811:
1.507 raeburn 5812: table.LC_nested_outer tr th {
5813: font-weight: bold;
1.801 tempelho 5814: color:$fontmenu;
1.507 raeburn 5815: background-color: $data_table_head;
1.701 harmsja 5816: font-size: small;
1.507 raeburn 5817: border-bottom: 1px solid #000000;
5818: }
1.795 www 5819:
1.507 raeburn 5820: table.LC_nested_outer tr td.LC_subheader {
5821: background-color: $data_table_head;
5822: font-weight: bold;
5823: font-size: small;
5824: border-bottom: 1px solid #000000;
5825: text-align: right;
1.451 albertel 5826: }
1.795 www 5827:
1.507 raeburn 5828: table.LC_nested tr.LC_info_row td {
1.735 bisitz 5829: background-color: #CCCCCC;
1.451 albertel 5830: font-weight: bold;
5831: font-size: small;
1.507 raeburn 5832: text-align: center;
5833: }
1.795 www 5834:
1.589 raeburn 5835: table.LC_nested tr.LC_info_row td.LC_left_item,
5836: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 5837: text-align: left;
1.451 albertel 5838: }
1.795 www 5839:
1.507 raeburn 5840: table.LC_nested td {
1.735 bisitz 5841: background-color: #FFFFFF;
1.451 albertel 5842: font-size: small;
1.507 raeburn 5843: }
1.795 www 5844:
1.507 raeburn 5845: table.LC_nested_outer tr th.LC_right_item,
5846: table.LC_nested tr.LC_info_row td.LC_right_item,
5847: table.LC_nested tr.LC_odd_row td.LC_right_item,
5848: table.LC_nested tr td.LC_right_item {
1.451 albertel 5849: text-align: right;
5850: }
5851:
1.507 raeburn 5852: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 5853: background-color: #EEEEEE;
1.451 albertel 5854: }
5855:
1.473 raeburn 5856: table.LC_createuser {
5857: }
5858:
5859: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 5860: font-size: small;
1.473 raeburn 5861: }
5862:
5863: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 5864: background-color: #CCCCCC;
1.473 raeburn 5865: font-weight: bold;
5866: text-align: center;
5867: }
5868:
1.349 albertel 5869: table.LC_calendar {
5870: border: 1px solid #000000;
5871: border-collapse: collapse;
1.917 raeburn 5872: width: 98%;
1.349 albertel 5873: }
1.795 www 5874:
1.349 albertel 5875: table.LC_calendar_pickdate {
5876: font-size: xx-small;
5877: }
1.795 www 5878:
1.349 albertel 5879: table.LC_calendar tr td {
5880: border: 1px solid #000000;
5881: vertical-align: top;
1.917 raeburn 5882: width: 14%;
1.349 albertel 5883: }
1.795 www 5884:
1.349 albertel 5885: table.LC_calendar tr td.LC_calendar_day_empty {
5886: background-color: $data_table_dark;
5887: }
1.795 www 5888:
1.779 bisitz 5889: table.LC_calendar tr td.LC_calendar_day_current {
5890: background-color: $data_table_highlight;
1.777 tempelho 5891: }
1.795 www 5892:
1.938 bisitz 5893: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 5894: background-color: $mail_new;
5895: }
1.795 www 5896:
1.938 bisitz 5897: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 5898: background-color: $mail_new_hover;
5899: }
1.795 www 5900:
1.938 bisitz 5901: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 5902: background-color: $mail_read;
5903: }
1.795 www 5904:
1.938 bisitz 5905: /*
5906: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 5907: background-color: $mail_read_hover;
5908: }
1.938 bisitz 5909: */
1.795 www 5910:
1.938 bisitz 5911: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 5912: background-color: $mail_replied;
5913: }
1.795 www 5914:
1.938 bisitz 5915: /*
5916: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 5917: background-color: $mail_replied_hover;
5918: }
1.938 bisitz 5919: */
1.795 www 5920:
1.938 bisitz 5921: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 5922: background-color: $mail_other;
5923: }
1.795 www 5924:
1.938 bisitz 5925: /*
5926: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 5927: background-color: $mail_other_hover;
5928: }
1.938 bisitz 5929: */
1.494 raeburn 5930:
1.777 tempelho 5931: table.LC_data_table tr > td.LC_browser_file,
5932: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 5933: background: #AAEE77;
1.389 albertel 5934: }
1.795 www 5935:
1.777 tempelho 5936: table.LC_data_table tr > td.LC_browser_file_locked,
5937: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 5938: background: #FFAA99;
1.387 albertel 5939: }
1.795 www 5940:
1.777 tempelho 5941: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 5942: background: #888888;
1.779 bisitz 5943: }
1.795 www 5944:
1.777 tempelho 5945: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 5946: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 5947: background: #F8F866;
1.777 tempelho 5948: }
1.795 www 5949:
1.696 bisitz 5950: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 5951: background: #E0E8FF;
1.387 albertel 5952: }
1.696 bisitz 5953:
1.707 bisitz 5954: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 5955: /* background: #77FF77; */
1.707 bisitz 5956: }
1.795 www 5957:
1.707 bisitz 5958: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 5959: border-right: 8px solid #FFFF77;
1.707 bisitz 5960: }
1.795 www 5961:
1.707 bisitz 5962: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 5963: border-right: 8px solid #FFAA77;
1.707 bisitz 5964: }
1.795 www 5965:
1.707 bisitz 5966: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 5967: border-right: 8px solid #FF7777;
1.707 bisitz 5968: }
1.795 www 5969:
1.707 bisitz 5970: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 5971: border-right: 8px solid #AAFF77;
1.707 bisitz 5972: }
1.795 www 5973:
1.707 bisitz 5974: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 5975: border-right: 8px solid #11CC55;
1.707 bisitz 5976: }
5977:
1.388 albertel 5978: span.LC_current_location {
1.701 harmsja 5979: font-size:larger;
1.388 albertel 5980: background: $pgbg;
5981: }
1.387 albertel 5982:
1.1029 www 5983: span.LC_current_nav_location {
5984: font-weight:bold;
5985: background: $sidebg;
5986: }
5987:
1.395 albertel 5988: span.LC_parm_menu_item {
5989: font-size: larger;
5990: }
1.795 www 5991:
1.395 albertel 5992: span.LC_parm_scope_all {
5993: color: red;
5994: }
1.795 www 5995:
1.395 albertel 5996: span.LC_parm_scope_folder {
5997: color: green;
5998: }
1.795 www 5999:
1.395 albertel 6000: span.LC_parm_scope_resource {
6001: color: orange;
6002: }
1.795 www 6003:
1.395 albertel 6004: span.LC_parm_part {
6005: color: blue;
6006: }
1.795 www 6007:
1.911 bisitz 6008: span.LC_parm_folder,
6009: span.LC_parm_symb {
1.395 albertel 6010: font-size: x-small;
6011: font-family: $mono;
6012: color: #AAAAAA;
6013: }
6014:
1.977 bisitz 6015: ul.LC_parm_parmlist li {
6016: display: inline-block;
6017: padding: 0.3em 0.8em;
6018: vertical-align: top;
6019: width: 150px;
6020: border-top:1px solid $lg_border_color;
6021: }
6022:
1.795 www 6023: td.LC_parm_overview_level_menu,
6024: td.LC_parm_overview_map_menu,
6025: td.LC_parm_overview_parm_selectors,
6026: td.LC_parm_overview_restrictions {
1.396 albertel 6027: border: 1px solid black;
6028: border-collapse: collapse;
6029: }
1.795 www 6030:
1.396 albertel 6031: table.LC_parm_overview_restrictions td {
6032: border-width: 1px 4px 1px 4px;
6033: border-style: solid;
6034: border-color: $pgbg;
6035: text-align: center;
6036: }
1.795 www 6037:
1.396 albertel 6038: table.LC_parm_overview_restrictions th {
6039: background: $tabbg;
6040: border-width: 1px 4px 1px 4px;
6041: border-style: solid;
6042: border-color: $pgbg;
6043: }
1.795 www 6044:
1.398 albertel 6045: table#LC_helpmenu {
1.803 bisitz 6046: border: none;
1.398 albertel 6047: height: 55px;
1.803 bisitz 6048: border-spacing: 0;
1.398 albertel 6049: }
6050:
6051: table#LC_helpmenu fieldset legend {
6052: font-size: larger;
6053: }
1.795 www 6054:
1.397 albertel 6055: table#LC_helpmenu_links {
6056: width: 100%;
6057: border: 1px solid black;
6058: background: $pgbg;
1.803 bisitz 6059: padding: 0;
1.397 albertel 6060: border-spacing: 1px;
6061: }
1.795 www 6062:
1.397 albertel 6063: table#LC_helpmenu_links tr td {
6064: padding: 1px;
6065: background: $tabbg;
1.399 albertel 6066: text-align: center;
6067: font-weight: bold;
1.397 albertel 6068: }
1.396 albertel 6069:
1.795 www 6070: table#LC_helpmenu_links a:link,
6071: table#LC_helpmenu_links a:visited,
1.397 albertel 6072: table#LC_helpmenu_links a:active {
6073: text-decoration: none;
6074: color: $font;
6075: }
1.795 www 6076:
1.397 albertel 6077: table#LC_helpmenu_links a:hover {
6078: text-decoration: underline;
6079: color: $vlink;
6080: }
1.396 albertel 6081:
1.417 albertel 6082: .LC_chrt_popup_exists {
6083: border: 1px solid #339933;
6084: margin: -1px;
6085: }
1.795 www 6086:
1.417 albertel 6087: .LC_chrt_popup_up {
6088: border: 1px solid yellow;
6089: margin: -1px;
6090: }
1.795 www 6091:
1.417 albertel 6092: .LC_chrt_popup {
6093: border: 1px solid #8888FF;
6094: background: #CCCCFF;
6095: }
1.795 www 6096:
1.421 albertel 6097: table.LC_pick_box {
6098: border-collapse: separate;
6099: background: white;
6100: border: 1px solid black;
6101: border-spacing: 1px;
6102: }
1.795 www 6103:
1.421 albertel 6104: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6105: background: $sidebg;
1.421 albertel 6106: font-weight: bold;
1.900 bisitz 6107: text-align: left;
1.740 bisitz 6108: vertical-align: top;
1.421 albertel 6109: width: 184px;
6110: padding: 8px;
6111: }
1.795 www 6112:
1.579 raeburn 6113: table.LC_pick_box td.LC_pick_box_value {
6114: text-align: left;
6115: padding: 8px;
6116: }
1.795 www 6117:
1.579 raeburn 6118: table.LC_pick_box td.LC_pick_box_select {
6119: text-align: left;
6120: padding: 8px;
6121: }
1.795 www 6122:
1.424 albertel 6123: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6124: padding: 0;
1.421 albertel 6125: height: 1px;
6126: background: black;
6127: }
1.795 www 6128:
1.421 albertel 6129: table.LC_pick_box td.LC_pick_box_submit {
6130: text-align: right;
6131: }
1.795 www 6132:
1.579 raeburn 6133: table.LC_pick_box td.LC_evenrow_value {
6134: text-align: left;
6135: padding: 8px;
6136: background-color: $data_table_light;
6137: }
1.795 www 6138:
1.579 raeburn 6139: table.LC_pick_box td.LC_oddrow_value {
6140: text-align: left;
6141: padding: 8px;
6142: background-color: $data_table_light;
6143: }
1.795 www 6144:
1.579 raeburn 6145: span.LC_helpform_receipt_cat {
6146: font-weight: bold;
6147: }
1.795 www 6148:
1.424 albertel 6149: table.LC_group_priv_box {
6150: background: white;
6151: border: 1px solid black;
6152: border-spacing: 1px;
6153: }
1.795 www 6154:
1.424 albertel 6155: table.LC_group_priv_box td.LC_pick_box_title {
6156: background: $tabbg;
6157: font-weight: bold;
6158: text-align: right;
6159: width: 184px;
6160: }
1.795 www 6161:
1.424 albertel 6162: table.LC_group_priv_box td.LC_groups_fixed {
6163: background: $data_table_light;
6164: text-align: center;
6165: }
1.795 www 6166:
1.424 albertel 6167: table.LC_group_priv_box td.LC_groups_optional {
6168: background: $data_table_dark;
6169: text-align: center;
6170: }
1.795 www 6171:
1.424 albertel 6172: table.LC_group_priv_box td.LC_groups_functionality {
6173: background: $data_table_darker;
6174: text-align: center;
6175: font-weight: bold;
6176: }
1.795 www 6177:
1.424 albertel 6178: table.LC_group_priv td {
6179: text-align: left;
1.803 bisitz 6180: padding: 0;
1.424 albertel 6181: }
6182:
6183: .LC_navbuttons {
6184: margin: 2ex 0ex 2ex 0ex;
6185: }
1.795 www 6186:
1.423 albertel 6187: .LC_topic_bar {
6188: font-weight: bold;
6189: background: $tabbg;
1.918 wenzelju 6190: margin: 1em 0em 1em 2em;
1.805 bisitz 6191: padding: 3px;
1.918 wenzelju 6192: font-size: 1.2em;
1.423 albertel 6193: }
1.795 www 6194:
1.423 albertel 6195: .LC_topic_bar span {
1.918 wenzelju 6196: left: 0.5em;
6197: position: absolute;
1.423 albertel 6198: vertical-align: middle;
1.918 wenzelju 6199: font-size: 1.2em;
1.423 albertel 6200: }
1.795 www 6201:
1.423 albertel 6202: table.LC_course_group_status {
6203: margin: 20px;
6204: }
1.795 www 6205:
1.423 albertel 6206: table.LC_status_selector td {
6207: vertical-align: top;
6208: text-align: center;
1.424 albertel 6209: padding: 4px;
6210: }
1.795 www 6211:
1.599 albertel 6212: div.LC_feedback_link {
1.616 albertel 6213: clear: both;
1.829 kalberla 6214: background: $sidebg;
1.779 bisitz 6215: width: 100%;
1.829 kalberla 6216: padding-bottom: 10px;
6217: border: 1px $tabbg solid;
1.833 kalberla 6218: height: 22px;
6219: line-height: 22px;
6220: padding-top: 5px;
6221: }
6222:
6223: div.LC_feedback_link img {
6224: height: 22px;
1.867 kalberla 6225: vertical-align:middle;
1.829 kalberla 6226: }
6227:
1.911 bisitz 6228: div.LC_feedback_link a {
1.829 kalberla 6229: text-decoration: none;
1.489 raeburn 6230: }
1.795 www 6231:
1.867 kalberla 6232: div.LC_comblock {
1.911 bisitz 6233: display:inline;
1.867 kalberla 6234: color:$font;
6235: font-size:90%;
6236: }
6237:
6238: div.LC_feedback_link div.LC_comblock {
6239: padding-left:5px;
6240: }
6241:
6242: div.LC_feedback_link div.LC_comblock a {
6243: color:$font;
6244: }
6245:
1.489 raeburn 6246: span.LC_feedback_link {
1.858 bisitz 6247: /* background: $feedback_link_bg; */
1.599 albertel 6248: font-size: larger;
6249: }
1.795 www 6250:
1.599 albertel 6251: span.LC_message_link {
1.858 bisitz 6252: /* background: $feedback_link_bg; */
1.599 albertel 6253: font-size: larger;
6254: position: absolute;
6255: right: 1em;
1.489 raeburn 6256: }
1.421 albertel 6257:
1.515 albertel 6258: table.LC_prior_tries {
1.524 albertel 6259: border: 1px solid #000000;
6260: border-collapse: separate;
6261: border-spacing: 1px;
1.515 albertel 6262: }
1.523 albertel 6263:
1.515 albertel 6264: table.LC_prior_tries td {
1.524 albertel 6265: padding: 2px;
1.515 albertel 6266: }
1.523 albertel 6267:
6268: .LC_answer_correct {
1.795 www 6269: background: lightgreen;
6270: color: darkgreen;
6271: padding: 6px;
1.523 albertel 6272: }
1.795 www 6273:
1.523 albertel 6274: .LC_answer_charged_try {
1.797 www 6275: background: #FFAAAA;
1.795 www 6276: color: darkred;
6277: padding: 6px;
1.523 albertel 6278: }
1.795 www 6279:
1.779 bisitz 6280: .LC_answer_not_charged_try,
1.523 albertel 6281: .LC_answer_no_grade,
6282: .LC_answer_late {
1.795 www 6283: background: lightyellow;
1.523 albertel 6284: color: black;
1.795 www 6285: padding: 6px;
1.523 albertel 6286: }
1.795 www 6287:
1.523 albertel 6288: .LC_answer_previous {
1.795 www 6289: background: lightblue;
6290: color: darkblue;
6291: padding: 6px;
1.523 albertel 6292: }
1.795 www 6293:
1.779 bisitz 6294: .LC_answer_no_message {
1.777 tempelho 6295: background: #FFFFFF;
6296: color: black;
1.795 www 6297: padding: 6px;
1.779 bisitz 6298: }
1.795 www 6299:
1.779 bisitz 6300: .LC_answer_unknown {
6301: background: orange;
6302: color: black;
1.795 www 6303: padding: 6px;
1.777 tempelho 6304: }
1.795 www 6305:
1.529 albertel 6306: span.LC_prior_numerical,
6307: span.LC_prior_string,
6308: span.LC_prior_custom,
6309: span.LC_prior_reaction,
6310: span.LC_prior_math {
1.925 bisitz 6311: font-family: $mono;
1.523 albertel 6312: white-space: pre;
6313: }
6314:
1.525 albertel 6315: span.LC_prior_string {
1.925 bisitz 6316: font-family: $mono;
1.525 albertel 6317: white-space: pre;
6318: }
6319:
1.523 albertel 6320: table.LC_prior_option {
6321: width: 100%;
6322: border-collapse: collapse;
6323: }
1.795 www 6324:
1.911 bisitz 6325: table.LC_prior_rank,
1.795 www 6326: table.LC_prior_match {
1.528 albertel 6327: border-collapse: collapse;
6328: }
1.795 www 6329:
1.528 albertel 6330: table.LC_prior_option tr td,
6331: table.LC_prior_rank tr td,
6332: table.LC_prior_match tr td {
1.524 albertel 6333: border: 1px solid #000000;
1.515 albertel 6334: }
6335:
1.855 bisitz 6336: .LC_nobreak {
1.544 albertel 6337: white-space: nowrap;
1.519 raeburn 6338: }
6339:
1.576 raeburn 6340: span.LC_cusr_emph {
6341: font-style: italic;
6342: }
6343:
1.633 raeburn 6344: span.LC_cusr_subheading {
6345: font-weight: normal;
6346: font-size: 85%;
6347: }
6348:
1.861 bisitz 6349: div.LC_docs_entry_move {
1.859 bisitz 6350: border: 1px solid #BBBBBB;
1.545 albertel 6351: background: #DDDDDD;
1.861 bisitz 6352: width: 22px;
1.859 bisitz 6353: padding: 1px;
6354: margin: 0;
1.545 albertel 6355: }
6356:
1.861 bisitz 6357: table.LC_data_table tr > td.LC_docs_entry_commands,
6358: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6359: font-size: x-small;
6360: }
1.795 www 6361:
1.861 bisitz 6362: .LC_docs_entry_parameter {
6363: white-space: nowrap;
6364: }
6365:
1.544 albertel 6366: .LC_docs_copy {
1.545 albertel 6367: color: #000099;
1.544 albertel 6368: }
1.795 www 6369:
1.544 albertel 6370: .LC_docs_cut {
1.545 albertel 6371: color: #550044;
1.544 albertel 6372: }
1.795 www 6373:
1.544 albertel 6374: .LC_docs_rename {
1.545 albertel 6375: color: #009900;
1.544 albertel 6376: }
1.795 www 6377:
1.544 albertel 6378: .LC_docs_remove {
1.545 albertel 6379: color: #990000;
6380: }
6381:
1.547 albertel 6382: .LC_docs_reinit_warn,
6383: .LC_docs_ext_edit {
6384: font-size: x-small;
6385: }
6386:
1.545 albertel 6387: table.LC_docs_adddocs td,
6388: table.LC_docs_adddocs th {
6389: border: 1px solid #BBBBBB;
6390: padding: 4px;
6391: background: #DDDDDD;
1.543 albertel 6392: }
6393:
1.584 albertel 6394: table.LC_sty_begin {
6395: background: #BBFFBB;
6396: }
1.795 www 6397:
1.584 albertel 6398: table.LC_sty_end {
6399: background: #FFBBBB;
6400: }
6401:
1.589 raeburn 6402: table.LC_double_column {
1.803 bisitz 6403: border-width: 0;
1.589 raeburn 6404: border-collapse: collapse;
6405: width: 100%;
6406: padding: 2px;
6407: }
6408:
6409: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6410: top: 2px;
1.589 raeburn 6411: left: 2px;
6412: width: 47%;
6413: vertical-align: top;
6414: }
6415:
6416: table.LC_double_column tr td.LC_right_col {
6417: top: 2px;
1.779 bisitz 6418: right: 2px;
1.589 raeburn 6419: width: 47%;
6420: vertical-align: top;
6421: }
6422:
1.591 raeburn 6423: div.LC_left_float {
6424: float: left;
6425: padding-right: 5%;
1.597 albertel 6426: padding-bottom: 4px;
1.591 raeburn 6427: }
6428:
6429: div.LC_clear_float_header {
1.597 albertel 6430: padding-bottom: 2px;
1.591 raeburn 6431: }
6432:
6433: div.LC_clear_float_footer {
1.597 albertel 6434: padding-top: 10px;
1.591 raeburn 6435: clear: both;
6436: }
6437:
1.597 albertel 6438: div.LC_grade_show_user {
1.941 bisitz 6439: /* border-left: 5px solid $sidebg; */
6440: border-top: 5px solid #000000;
6441: margin: 50px 0 0 0;
1.936 bisitz 6442: padding: 15px 0 5px 10px;
1.597 albertel 6443: }
1.795 www 6444:
1.936 bisitz 6445: div.LC_grade_show_user_odd_row {
1.941 bisitz 6446: /* border-left: 5px solid #000000; */
6447: }
6448:
6449: div.LC_grade_show_user div.LC_Box {
6450: margin-right: 50px;
1.597 albertel 6451: }
6452:
6453: div.LC_grade_submissions,
6454: div.LC_grade_message_center,
1.936 bisitz 6455: div.LC_grade_info_links {
1.597 albertel 6456: margin: 5px;
6457: width: 99%;
6458: background: #FFFFFF;
6459: }
1.795 www 6460:
1.597 albertel 6461: div.LC_grade_submissions_header,
1.936 bisitz 6462: div.LC_grade_message_center_header {
1.705 tempelho 6463: font-weight: bold;
6464: font-size: large;
1.597 albertel 6465: }
1.795 www 6466:
1.597 albertel 6467: div.LC_grade_submissions_body,
1.936 bisitz 6468: div.LC_grade_message_center_body {
1.597 albertel 6469: border: 1px solid black;
6470: width: 99%;
6471: background: #FFFFFF;
6472: }
1.795 www 6473:
1.613 albertel 6474: table.LC_scantron_action {
6475: width: 100%;
6476: }
1.795 www 6477:
1.613 albertel 6478: table.LC_scantron_action tr th {
1.698 harmsja 6479: font-weight:bold;
6480: font-style:normal;
1.613 albertel 6481: }
1.795 www 6482:
1.779 bisitz 6483: .LC_edit_problem_header,
1.614 albertel 6484: div.LC_edit_problem_footer {
1.705 tempelho 6485: font-weight: normal;
6486: font-size: medium;
1.602 albertel 6487: margin: 2px;
1.1060 bisitz 6488: background-color: $sidebg;
1.600 albertel 6489: }
1.795 www 6490:
1.600 albertel 6491: div.LC_edit_problem_header,
1.602 albertel 6492: div.LC_edit_problem_header div,
1.614 albertel 6493: div.LC_edit_problem_footer,
6494: div.LC_edit_problem_footer div,
1.602 albertel 6495: div.LC_edit_problem_editxml_header,
6496: div.LC_edit_problem_editxml_header div {
1.600 albertel 6497: margin-top: 5px;
6498: }
1.795 www 6499:
1.600 albertel 6500: div.LC_edit_problem_header_title {
1.705 tempelho 6501: font-weight: bold;
6502: font-size: larger;
1.602 albertel 6503: background: $tabbg;
6504: padding: 3px;
1.1060 bisitz 6505: margin: 0 0 5px 0;
1.602 albertel 6506: }
1.795 www 6507:
1.602 albertel 6508: table.LC_edit_problem_header_title {
6509: width: 100%;
1.600 albertel 6510: background: $tabbg;
1.602 albertel 6511: }
6512:
6513: div.LC_edit_problem_discards {
6514: float: left;
6515: padding-bottom: 5px;
6516: }
1.795 www 6517:
1.602 albertel 6518: div.LC_edit_problem_saves {
6519: float: right;
6520: padding-bottom: 5px;
1.600 albertel 6521: }
1.795 www 6522:
1.1124 bisitz 6523: .LC_edit_opt {
6524: padding-left: 1em;
6525: white-space: nowrap;
6526: }
6527:
1.1152 golterma 6528: .LC_edit_problem_latexhelper{
6529: text-align: right;
6530: }
6531:
6532: #LC_edit_problem_colorful div{
6533: margin-left: 40px;
6534: }
6535:
1.911 bisitz 6536: img.stift {
1.803 bisitz 6537: border-width: 0;
6538: vertical-align: middle;
1.677 riegler 6539: }
1.680 riegler 6540:
1.923 bisitz 6541: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6542: vertical-align: top;
1.777 tempelho 6543: }
1.795 www 6544:
1.716 raeburn 6545: div.LC_createcourse {
1.911 bisitz 6546: margin: 10px 10px 10px 10px;
1.716 raeburn 6547: }
6548:
1.917 raeburn 6549: .LC_dccid {
1.1130 raeburn 6550: float: right;
1.917 raeburn 6551: margin: 0.2em 0 0 0;
6552: padding: 0;
6553: font-size: 90%;
6554: display:none;
6555: }
6556:
1.897 wenzelju 6557: ol.LC_primary_menu a:hover,
1.721 harmsja 6558: ol#LC_MenuBreadcrumbs a:hover,
6559: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6560: ul#LC_secondary_menu a:hover,
1.721 harmsja 6561: .LC_FormSectionClearButton input:hover
1.795 www 6562: ul.LC_TabContent li:hover a {
1.952 onken 6563: color:$button_hover;
1.911 bisitz 6564: text-decoration:none;
1.693 droeschl 6565: }
6566:
1.779 bisitz 6567: h1 {
1.911 bisitz 6568: padding: 0;
6569: line-height:130%;
1.693 droeschl 6570: }
1.698 harmsja 6571:
1.911 bisitz 6572: h2,
6573: h3,
6574: h4,
6575: h5,
6576: h6 {
6577: margin: 5px 0 5px 0;
6578: padding: 0;
6579: line-height:130%;
1.693 droeschl 6580: }
1.795 www 6581:
6582: .LC_hcell {
1.911 bisitz 6583: padding:3px 15px 3px 15px;
6584: margin: 0;
6585: background-color:$tabbg;
6586: color:$fontmenu;
6587: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6588: }
1.795 www 6589:
1.840 bisitz 6590: .LC_Box > .LC_hcell {
1.911 bisitz 6591: margin: 0 -10px 10px -10px;
1.835 bisitz 6592: }
6593:
1.721 harmsja 6594: .LC_noBorder {
1.911 bisitz 6595: border: 0;
1.698 harmsja 6596: }
1.693 droeschl 6597:
1.721 harmsja 6598: .LC_FormSectionClearButton input {
1.911 bisitz 6599: background-color:transparent;
6600: border: none;
6601: cursor:pointer;
6602: text-decoration:underline;
1.693 droeschl 6603: }
1.763 bisitz 6604:
6605: .LC_help_open_topic {
1.911 bisitz 6606: color: #FFFFFF;
6607: background-color: #EEEEFF;
6608: margin: 1px;
6609: padding: 4px;
6610: border: 1px solid #000033;
6611: white-space: nowrap;
6612: /* vertical-align: middle; */
1.759 neumanie 6613: }
1.693 droeschl 6614:
1.911 bisitz 6615: dl,
6616: ul,
6617: div,
6618: fieldset {
6619: margin: 10px 10px 10px 0;
6620: /* overflow: hidden; */
1.693 droeschl 6621: }
1.795 www 6622:
1.838 bisitz 6623: fieldset > legend {
1.911 bisitz 6624: font-weight: bold;
6625: padding: 0 5px 0 5px;
1.838 bisitz 6626: }
6627:
1.813 bisitz 6628: #LC_nav_bar {
1.911 bisitz 6629: float: left;
1.995 raeburn 6630: background-color: $pgbg_or_bgcolor;
1.966 bisitz 6631: margin: 0 0 2px 0;
1.807 droeschl 6632: }
6633:
1.916 droeschl 6634: #LC_realm {
6635: margin: 0.2em 0 0 0;
6636: padding: 0;
6637: font-weight: bold;
6638: text-align: center;
1.995 raeburn 6639: background-color: $pgbg_or_bgcolor;
1.916 droeschl 6640: }
6641:
1.911 bisitz 6642: #LC_nav_bar em {
6643: font-weight: bold;
6644: font-style: normal;
1.807 droeschl 6645: }
6646:
1.897 wenzelju 6647: ol.LC_primary_menu {
1.934 droeschl 6648: margin: 0;
1.1076 raeburn 6649: padding: 0;
1.995 raeburn 6650: background-color: $pgbg_or_bgcolor;
1.807 droeschl 6651: }
6652:
1.852 droeschl 6653: ol#LC_PathBreadcrumbs {
1.911 bisitz 6654: margin: 0;
1.693 droeschl 6655: }
6656:
1.897 wenzelju 6657: ol.LC_primary_menu li {
1.1076 raeburn 6658: color: RGB(80, 80, 80);
6659: vertical-align: middle;
6660: text-align: left;
6661: list-style: none;
6662: float: left;
6663: }
6664:
6665: ol.LC_primary_menu li a {
6666: display: block;
6667: margin: 0;
6668: padding: 0 5px 0 10px;
6669: text-decoration: none;
6670: }
6671:
6672: ol.LC_primary_menu li ul {
6673: display: none;
6674: width: 10em;
6675: background-color: $data_table_light;
6676: }
6677:
6678: ol.LC_primary_menu li:hover ul, ol.LC_primary_menu li.hover ul {
6679: display: block;
6680: position: absolute;
6681: margin: 0;
6682: padding: 0;
1.1078 raeburn 6683: z-index: 2;
1.1076 raeburn 6684: }
6685:
6686: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
6687: font-size: 90%;
1.911 bisitz 6688: vertical-align: top;
1.1076 raeburn 6689: float: none;
1.1079 raeburn 6690: border-left: 1px solid black;
6691: border-right: 1px solid black;
1.1076 raeburn 6692: }
6693:
6694: ol.LC_primary_menu li:hover li a, ol.LC_primary_menu li.hover li a {
1.1078 raeburn 6695: background-color:$data_table_light;
1.1076 raeburn 6696: }
6697:
6698: ol.LC_primary_menu li li a:hover {
6699: color:$button_hover;
6700: background-color:$data_table_dark;
1.693 droeschl 6701: }
6702:
1.897 wenzelju 6703: ol.LC_primary_menu li img {
1.911 bisitz 6704: vertical-align: bottom;
1.934 droeschl 6705: height: 1.1em;
1.1077 raeburn 6706: margin: 0.2em 0 0 0;
1.693 droeschl 6707: }
6708:
1.897 wenzelju 6709: ol.LC_primary_menu a {
1.911 bisitz 6710: color: RGB(80, 80, 80);
6711: text-decoration: none;
1.693 droeschl 6712: }
1.795 www 6713:
1.949 droeschl 6714: ol.LC_primary_menu a.LC_new_message {
6715: font-weight:bold;
6716: color: darkred;
6717: }
6718:
1.975 raeburn 6719: ol.LC_docs_parameters {
6720: margin-left: 0;
6721: padding: 0;
6722: list-style: none;
6723: }
6724:
6725: ol.LC_docs_parameters li {
6726: margin: 0;
6727: padding-right: 20px;
6728: display: inline;
6729: }
6730:
1.976 raeburn 6731: ol.LC_docs_parameters li:before {
6732: content: "\\002022 \\0020";
6733: }
6734:
6735: li.LC_docs_parameters_title {
6736: font-weight: bold;
6737: }
6738:
6739: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
6740: content: "";
6741: }
6742:
1.897 wenzelju 6743: ul#LC_secondary_menu {
1.1107 raeburn 6744: clear: right;
1.911 bisitz 6745: color: $fontmenu;
6746: background: $tabbg;
6747: list-style: none;
6748: padding: 0;
6749: margin: 0;
6750: width: 100%;
1.995 raeburn 6751: text-align: left;
1.1107 raeburn 6752: float: left;
1.808 droeschl 6753: }
6754:
1.897 wenzelju 6755: ul#LC_secondary_menu li {
1.911 bisitz 6756: font-weight: bold;
6757: line-height: 1.8em;
1.1107 raeburn 6758: border-right: 1px solid black;
6759: float: left;
6760: }
6761:
6762: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
6763: background-color: $data_table_light;
6764: }
6765:
6766: ul#LC_secondary_menu li a {
1.911 bisitz 6767: padding: 0 0.8em;
1.1107 raeburn 6768: }
6769:
6770: ul#LC_secondary_menu li ul {
6771: display: none;
6772: }
6773:
6774: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
6775: display: block;
6776: position: absolute;
6777: margin: 0;
6778: padding: 0;
6779: list-style:none;
6780: float: none;
6781: background-color: $data_table_light;
6782: z-index: 2;
6783: margin-left: -1px;
6784: }
6785:
6786: ul#LC_secondary_menu li ul li {
6787: font-size: 90%;
6788: vertical-align: top;
6789: border-left: 1px solid black;
1.911 bisitz 6790: border-right: 1px solid black;
1.1119 raeburn 6791: background-color: $data_table_light;
1.1107 raeburn 6792: list-style:none;
6793: float: none;
6794: }
6795:
6796: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
6797: background-color: $data_table_dark;
1.807 droeschl 6798: }
6799:
1.847 tempelho 6800: ul.LC_TabContent {
1.911 bisitz 6801: display:block;
6802: background: $sidebg;
6803: border-bottom: solid 1px $lg_border_color;
6804: list-style:none;
1.1020 raeburn 6805: margin: -1px -10px 0 -10px;
1.911 bisitz 6806: padding: 0;
1.693 droeschl 6807: }
6808:
1.795 www 6809: ul.LC_TabContent li,
6810: ul.LC_TabContentBigger li {
1.911 bisitz 6811: float:left;
1.741 harmsja 6812: }
1.795 www 6813:
1.897 wenzelju 6814: ul#LC_secondary_menu li a {
1.911 bisitz 6815: color: $fontmenu;
6816: text-decoration: none;
1.693 droeschl 6817: }
1.795 www 6818:
1.721 harmsja 6819: ul.LC_TabContent {
1.952 onken 6820: min-height:20px;
1.721 harmsja 6821: }
1.795 www 6822:
6823: ul.LC_TabContent li {
1.911 bisitz 6824: vertical-align:middle;
1.959 onken 6825: padding: 0 16px 0 10px;
1.911 bisitz 6826: background-color:$tabbg;
6827: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 6828: border-left: solid 1px $font;
1.721 harmsja 6829: }
1.795 www 6830:
1.847 tempelho 6831: ul.LC_TabContent .right {
1.911 bisitz 6832: float:right;
1.847 tempelho 6833: }
6834:
1.911 bisitz 6835: ul.LC_TabContent li a,
6836: ul.LC_TabContent li {
6837: color:rgb(47,47,47);
6838: text-decoration:none;
6839: font-size:95%;
6840: font-weight:bold;
1.952 onken 6841: min-height:20px;
6842: }
6843:
1.959 onken 6844: ul.LC_TabContent li a:hover,
6845: ul.LC_TabContent li a:focus {
1.952 onken 6846: color: $button_hover;
1.959 onken 6847: background:none;
6848: outline:none;
1.952 onken 6849: }
6850:
6851: ul.LC_TabContent li:hover {
6852: color: $button_hover;
6853: cursor:pointer;
1.721 harmsja 6854: }
1.795 www 6855:
1.911 bisitz 6856: ul.LC_TabContent li.active {
1.952 onken 6857: color: $font;
1.911 bisitz 6858: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 6859: border-bottom:solid 1px #FFFFFF;
6860: cursor: default;
1.744 ehlerst 6861: }
1.795 www 6862:
1.959 onken 6863: ul.LC_TabContent li.active a {
6864: color:$font;
6865: background:#FFFFFF;
6866: outline: none;
6867: }
1.1047 raeburn 6868:
6869: ul.LC_TabContent li.goback {
6870: float: left;
6871: border-left: none;
6872: }
6873:
1.870 tempelho 6874: #maincoursedoc {
1.911 bisitz 6875: clear:both;
1.870 tempelho 6876: }
6877:
6878: ul.LC_TabContentBigger {
1.911 bisitz 6879: display:block;
6880: list-style:none;
6881: padding: 0;
1.870 tempelho 6882: }
6883:
1.795 www 6884: ul.LC_TabContentBigger li {
1.911 bisitz 6885: vertical-align:bottom;
6886: height: 30px;
6887: font-size:110%;
6888: font-weight:bold;
6889: color: #737373;
1.841 tempelho 6890: }
6891:
1.957 onken 6892: ul.LC_TabContentBigger li.active {
6893: position: relative;
6894: top: 1px;
6895: }
6896:
1.870 tempelho 6897: ul.LC_TabContentBigger li a {
1.911 bisitz 6898: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
6899: height: 30px;
6900: line-height: 30px;
6901: text-align: center;
6902: display: block;
6903: text-decoration: none;
1.958 onken 6904: outline: none;
1.741 harmsja 6905: }
1.795 www 6906:
1.870 tempelho 6907: ul.LC_TabContentBigger li.active a {
1.911 bisitz 6908: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
6909: color:$font;
1.744 ehlerst 6910: }
1.795 www 6911:
1.870 tempelho 6912: ul.LC_TabContentBigger li b {
1.911 bisitz 6913: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
6914: display: block;
6915: float: left;
6916: padding: 0 30px;
1.957 onken 6917: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 6918: }
6919:
1.956 onken 6920: ul.LC_TabContentBigger li:hover b {
6921: color:$button_hover;
6922: }
6923:
1.870 tempelho 6924: ul.LC_TabContentBigger li.active b {
1.911 bisitz 6925: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
6926: color:$font;
1.957 onken 6927: border: 0;
1.741 harmsja 6928: }
1.693 droeschl 6929:
1.870 tempelho 6930:
1.862 bisitz 6931: ul.LC_CourseBreadcrumbs {
6932: background: $sidebg;
1.1020 raeburn 6933: height: 2em;
1.862 bisitz 6934: padding-left: 10px;
1.1020 raeburn 6935: margin: 0;
1.862 bisitz 6936: list-style-position: inside;
6937: }
6938:
1.911 bisitz 6939: ol#LC_MenuBreadcrumbs,
1.862 bisitz 6940: ol#LC_PathBreadcrumbs {
1.911 bisitz 6941: padding-left: 10px;
6942: margin: 0;
1.933 droeschl 6943: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 6944: }
6945:
1.911 bisitz 6946: ol#LC_MenuBreadcrumbs li,
6947: ol#LC_PathBreadcrumbs li,
1.862 bisitz 6948: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 6949: display: inline;
1.933 droeschl 6950: white-space: normal;
1.693 droeschl 6951: }
6952:
1.823 bisitz 6953: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 6954: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 6955: text-decoration: none;
6956: font-size:90%;
1.693 droeschl 6957: }
1.795 www 6958:
1.969 droeschl 6959: ol#LC_MenuBreadcrumbs h1 {
6960: display: inline;
6961: font-size: 90%;
6962: line-height: 2.5em;
6963: margin: 0;
6964: padding: 0;
6965: }
6966:
1.795 www 6967: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 6968: text-decoration:none;
6969: font-size:100%;
6970: font-weight:bold;
1.693 droeschl 6971: }
1.795 www 6972:
1.840 bisitz 6973: .LC_Box {
1.911 bisitz 6974: border: solid 1px $lg_border_color;
6975: padding: 0 10px 10px 10px;
1.746 neumanie 6976: }
1.795 www 6977:
1.1020 raeburn 6978: .LC_DocsBox {
6979: border: solid 1px $lg_border_color;
6980: padding: 0 0 10px 10px;
6981: }
6982:
1.795 www 6983: .LC_AboutMe_Image {
1.911 bisitz 6984: float:left;
6985: margin-right:10px;
1.747 neumanie 6986: }
1.795 www 6987:
6988: .LC_Clear_AboutMe_Image {
1.911 bisitz 6989: clear:left;
1.747 neumanie 6990: }
1.795 www 6991:
1.721 harmsja 6992: dl.LC_ListStyleClean dt {
1.911 bisitz 6993: padding-right: 5px;
6994: display: table-header-group;
1.693 droeschl 6995: }
6996:
1.721 harmsja 6997: dl.LC_ListStyleClean dd {
1.911 bisitz 6998: display: table-row;
1.693 droeschl 6999: }
7000:
1.721 harmsja 7001: .LC_ListStyleClean,
7002: .LC_ListStyleSimple,
7003: .LC_ListStyleNormal,
1.795 www 7004: .LC_ListStyleSpecial {
1.911 bisitz 7005: /* display:block; */
7006: list-style-position: inside;
7007: list-style-type: none;
7008: overflow: hidden;
7009: padding: 0;
1.693 droeschl 7010: }
7011:
1.721 harmsja 7012: .LC_ListStyleSimple li,
7013: .LC_ListStyleSimple dd,
7014: .LC_ListStyleNormal li,
7015: .LC_ListStyleNormal dd,
7016: .LC_ListStyleSpecial li,
1.795 www 7017: .LC_ListStyleSpecial dd {
1.911 bisitz 7018: margin: 0;
7019: padding: 5px 5px 5px 10px;
7020: clear: both;
1.693 droeschl 7021: }
7022:
1.721 harmsja 7023: .LC_ListStyleClean li,
7024: .LC_ListStyleClean dd {
1.911 bisitz 7025: padding-top: 0;
7026: padding-bottom: 0;
1.693 droeschl 7027: }
7028:
1.721 harmsja 7029: .LC_ListStyleSimple dd,
1.795 www 7030: .LC_ListStyleSimple li {
1.911 bisitz 7031: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7032: }
7033:
1.721 harmsja 7034: .LC_ListStyleSpecial li,
7035: .LC_ListStyleSpecial dd {
1.911 bisitz 7036: list-style-type: none;
7037: background-color: RGB(220, 220, 220);
7038: margin-bottom: 4px;
1.693 droeschl 7039: }
7040:
1.721 harmsja 7041: table.LC_SimpleTable {
1.911 bisitz 7042: margin:5px;
7043: border:solid 1px $lg_border_color;
1.795 www 7044: }
1.693 droeschl 7045:
1.721 harmsja 7046: table.LC_SimpleTable tr {
1.911 bisitz 7047: padding: 0;
7048: border:solid 1px $lg_border_color;
1.693 droeschl 7049: }
1.795 www 7050:
7051: table.LC_SimpleTable thead {
1.911 bisitz 7052: background:rgb(220,220,220);
1.693 droeschl 7053: }
7054:
1.721 harmsja 7055: div.LC_columnSection {
1.911 bisitz 7056: display: block;
7057: clear: both;
7058: overflow: hidden;
7059: margin: 0;
1.693 droeschl 7060: }
7061:
1.721 harmsja 7062: div.LC_columnSection>* {
1.911 bisitz 7063: float: left;
7064: margin: 10px 20px 10px 0;
7065: overflow:hidden;
1.693 droeschl 7066: }
1.721 harmsja 7067:
1.795 www 7068: table em {
1.911 bisitz 7069: font-weight: bold;
7070: font-style: normal;
1.748 schulted 7071: }
1.795 www 7072:
1.779 bisitz 7073: table.LC_tableBrowseRes,
1.795 www 7074: table.LC_tableOfContent {
1.911 bisitz 7075: border:none;
7076: border-spacing: 1px;
7077: padding: 3px;
7078: background-color: #FFFFFF;
7079: font-size: 90%;
1.753 droeschl 7080: }
1.789 droeschl 7081:
1.911 bisitz 7082: table.LC_tableOfContent {
7083: border-collapse: collapse;
1.789 droeschl 7084: }
7085:
1.771 droeschl 7086: table.LC_tableBrowseRes a,
1.768 schulted 7087: table.LC_tableOfContent a {
1.911 bisitz 7088: background-color: transparent;
7089: text-decoration: none;
1.753 droeschl 7090: }
7091:
1.795 www 7092: table.LC_tableOfContent img {
1.911 bisitz 7093: border: none;
7094: height: 1.3em;
7095: vertical-align: text-bottom;
7096: margin-right: 0.3em;
1.753 droeschl 7097: }
1.757 schulted 7098:
1.795 www 7099: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7100: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7101: }
7102:
1.795 www 7103: a#LC_content_toolbar_everything {
1.911 bisitz 7104: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7105: }
7106:
1.795 www 7107: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7108: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7109: }
7110:
1.795 www 7111: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7112: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7113: }
7114:
1.795 www 7115: a#LC_content_toolbar_changefolder {
1.911 bisitz 7116: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7117: }
7118:
1.795 www 7119: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7120: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7121: }
7122:
1.1043 raeburn 7123: a#LC_content_toolbar_edittoplevel {
7124: background-image:url(/res/adm/pages/edittoplevel.gif);
7125: }
7126:
1.795 www 7127: ul#LC_toolbar li a:hover {
1.911 bisitz 7128: background-position: bottom center;
1.757 schulted 7129: }
7130:
1.795 www 7131: ul#LC_toolbar {
1.911 bisitz 7132: padding: 0;
7133: margin: 2px;
7134: list-style:none;
7135: position:relative;
7136: background-color:white;
1.1082 raeburn 7137: overflow: auto;
1.757 schulted 7138: }
7139:
1.795 www 7140: ul#LC_toolbar li {
1.911 bisitz 7141: border:1px solid white;
7142: padding: 0;
7143: margin: 0;
7144: float: left;
7145: display:inline;
7146: vertical-align:middle;
1.1082 raeburn 7147: white-space: nowrap;
1.911 bisitz 7148: }
1.757 schulted 7149:
1.783 amueller 7150:
1.795 www 7151: a.LC_toolbarItem {
1.911 bisitz 7152: display:block;
7153: padding: 0;
7154: margin: 0;
7155: height: 32px;
7156: width: 32px;
7157: color:white;
7158: border: none;
7159: background-repeat:no-repeat;
7160: background-color:transparent;
1.757 schulted 7161: }
7162:
1.915 droeschl 7163: ul.LC_funclist {
7164: margin: 0;
7165: padding: 0.5em 1em 0.5em 0;
7166: }
7167:
1.933 droeschl 7168: ul.LC_funclist > li:first-child {
7169: font-weight:bold;
7170: margin-left:0.8em;
7171: }
7172:
1.915 droeschl 7173: ul.LC_funclist + ul.LC_funclist {
7174: /*
7175: left border as a seperator if we have more than
7176: one list
7177: */
7178: border-left: 1px solid $sidebg;
7179: /*
7180: this hides the left border behind the border of the
7181: outer box if element is wrapped to the next 'line'
7182: */
7183: margin-left: -1px;
7184: }
7185:
1.843 bisitz 7186: ul.LC_funclist li {
1.915 droeschl 7187: display: inline;
1.782 bisitz 7188: white-space: nowrap;
1.915 droeschl 7189: margin: 0 0 0 25px;
7190: line-height: 150%;
1.782 bisitz 7191: }
7192:
1.974 wenzelju 7193: .LC_hidden {
7194: display: none;
7195: }
7196:
1.1030 www 7197: .LCmodal-overlay {
7198: position:fixed;
7199: top:0;
7200: right:0;
7201: bottom:0;
7202: left:0;
7203: height:100%;
7204: width:100%;
7205: margin:0;
7206: padding:0;
7207: background:#999;
7208: opacity:.75;
7209: filter: alpha(opacity=75);
7210: -moz-opacity: 0.75;
7211: z-index:101;
7212: }
7213:
7214: * html .LCmodal-overlay {
7215: position: absolute;
7216: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7217: }
7218:
7219: .LCmodal-window {
7220: position:fixed;
7221: top:50%;
7222: left:50%;
7223: margin:0;
7224: padding:0;
7225: z-index:102;
7226: }
7227:
7228: * html .LCmodal-window {
7229: position:absolute;
7230: }
7231:
7232: .LCclose-window {
7233: position:absolute;
7234: width:32px;
7235: height:32px;
7236: right:8px;
7237: top:8px;
7238: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7239: text-indent:-99999px;
7240: overflow:hidden;
7241: cursor:pointer;
7242: }
7243:
1.1100 raeburn 7244: /*
7245: styles used by TTH when "Default set of options to pass to tth/m
7246: when converting TeX" in course settings has been set
7247:
7248: option passed: -t
7249:
7250: */
7251:
7252: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7253: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7254: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7255: td div.norm {line-height:normal;}
7256:
7257: /*
7258: option passed -y3
7259: */
7260:
7261: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7262: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7263: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7264:
1.343 albertel 7265: END
7266: }
7267:
1.306 albertel 7268: =pod
7269:
7270: =item * &headtag()
7271:
7272: Returns a uniform footer for LON-CAPA web pages.
7273:
1.307 albertel 7274: Inputs: $title - optional title for the head
7275: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7276: $args - optional arguments
1.319 albertel 7277: force_register - if is true call registerurl so the remote is
7278: informed
1.415 albertel 7279: redirect -> array ref of
7280: 1- seconds before redirect occurs
7281: 2- url to redirect to
7282: 3- whether the side effect should occur
1.315 albertel 7283: (side effect of setting
7284: $env{'internal.head.redirect'} to the url
7285: redirected too)
1.352 albertel 7286: domain -> force to color decorate a page for a specific
7287: domain
7288: function -> force usage of a specific rolish color scheme
7289: bgcolor -> override the default page bgcolor
1.460 albertel 7290: no_auto_mt_title
7291: -> prevent &mt()ing the title arg
1.464 albertel 7292:
1.306 albertel 7293: =cut
7294:
7295: sub headtag {
1.313 albertel 7296: my ($title,$head_extra,$args) = @_;
1.306 albertel 7297:
1.363 albertel 7298: my $function = $args->{'function'} || &get_users_function();
7299: my $domain = $args->{'domain'} || &determinedomain();
7300: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 7301: my $httphost = $args->{'use_absolute'};
1.418 albertel 7302: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7303: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7304: #time(),
1.418 albertel 7305: $env{'environment.color.timestamp'},
1.363 albertel 7306: $function,$domain,$bgcolor);
7307:
1.369 www 7308: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7309:
1.308 albertel 7310: my $result =
7311: '<head>'.
1.1160 raeburn 7312: &font_settings($args);
1.319 albertel 7313:
1.1188 raeburn 7314: my $inhibitprint;
7315: if ($args->{'print_suppress'}) {
7316: $inhibitprint = &print_suppression();
7317: }
1.1064 raeburn 7318:
1.461 albertel 7319: if (!$args->{'frameset'}) {
7320: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7321: }
1.962 droeschl 7322: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
7323: $result .= Apache::lonxml::display_title();
1.319 albertel 7324: }
1.436 albertel 7325: if (!$args->{'no_nav_bar'}
7326: && !$args->{'only_body'}
7327: && !$args->{'frameset'}) {
1.1154 raeburn 7328: $result .= &help_menu_js($httphost);
1.1032 www 7329: $result.=&modal_window();
1.1038 www 7330: $result.=&togglebox_script();
1.1034 www 7331: $result.=&wishlist_window();
1.1041 www 7332: $result.=&LCprogressbarUpdate_script();
1.1034 www 7333: } else {
7334: if ($args->{'add_modal'}) {
7335: $result.=&modal_window();
7336: }
7337: if ($args->{'add_wishlist'}) {
7338: $result.=&wishlist_window();
7339: }
1.1038 www 7340: if ($args->{'add_togglebox'}) {
7341: $result.=&togglebox_script();
7342: }
1.1041 www 7343: if ($args->{'add_progressbar'}) {
7344: $result.=&LCprogressbarUpdate_script();
7345: }
1.436 albertel 7346: }
1.314 albertel 7347: if (ref($args->{'redirect'})) {
1.414 albertel 7348: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7349: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7350: if (!$inhibit_continue) {
7351: $env{'internal.head.redirect'} = $url;
7352: }
1.313 albertel 7353: $result.=<<ADDMETA
7354: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7355: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7356: ADDMETA
7357: }
1.306 albertel 7358: if (!defined($title)) {
7359: $title = 'The LearningOnline Network with CAPA';
7360: }
1.460 albertel 7361: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7362: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 7363: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7364: if (!$args->{'frameset'}) {
7365: $result .= ' /';
7366: }
7367: $result .= '>'
1.1064 raeburn 7368: .$inhibitprint
1.414 albertel 7369: .$head_extra;
1.1137 raeburn 7370: if ($env{'browser.mobile'}) {
7371: $result .= '
7372: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7373: <meta name="apple-mobile-web-app-capable" content="yes" />';
7374: }
1.962 droeschl 7375: return $result.'</head>';
1.306 albertel 7376: }
7377:
7378: =pod
7379:
1.340 albertel 7380: =item * &font_settings()
7381:
7382: Returns neccessary <meta> to set the proper encoding
7383:
1.1160 raeburn 7384: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7385:
7386: =cut
7387:
7388: sub font_settings {
1.1160 raeburn 7389: my ($args) = @_;
1.340 albertel 7390: my $headerstring='';
1.1160 raeburn 7391: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7392: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 7393: $headerstring.=
7394: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
7395: if (!$args->{'frameset'}) {
7396: $headerstring.= ' /';
7397: }
7398: $headerstring .= '>'."\n";
1.340 albertel 7399: }
7400: return $headerstring;
7401: }
7402:
1.341 albertel 7403: =pod
7404:
1.1064 raeburn 7405: =item * &print_suppression()
7406:
7407: In course context returns css which causes the body to be blank when media="print",
7408: if printout generation is unavailable for the current resource.
7409:
7410: This could be because:
7411:
7412: (a) printstartdate is in the future
7413:
7414: (b) printenddate is in the past
7415:
7416: (c) there is an active exam block with "printout"
7417: functionality blocked
7418:
7419: Users with pav, pfo or evb privileges are exempt.
7420:
7421: Inputs: none
7422:
7423: =cut
7424:
7425:
7426: sub print_suppression {
7427: my $noprint;
7428: if ($env{'request.course.id'}) {
7429: my $scope = $env{'request.course.id'};
7430: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7431: (&Apache::lonnet::allowed('pfo',$scope))) {
7432: return;
7433: }
7434: if ($env{'request.course.sec'} ne '') {
7435: $scope .= "/$env{'request.course.sec'}";
7436: if ((&Apache::lonnet::allowed('pav',$scope)) ||
7437: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 7438: return;
1.1064 raeburn 7439: }
7440: }
7441: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
7442: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 7443: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 7444: if ($blocked) {
7445: my $checkrole = "cm./$cdom/$cnum";
7446: if ($env{'request.course.sec'} ne '') {
7447: $checkrole .= "/$env{'request.course.sec'}";
7448: }
7449: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
7450: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
7451: $noprint = 1;
7452: }
7453: }
7454: unless ($noprint) {
7455: my $symb = &Apache::lonnet::symbread();
7456: if ($symb ne '') {
7457: my $navmap = Apache::lonnavmaps::navmap->new();
7458: if (ref($navmap)) {
7459: my $res = $navmap->getBySymb($symb);
7460: if (ref($res)) {
7461: if (!$res->resprintable()) {
7462: $noprint = 1;
7463: }
7464: }
7465: }
7466: }
7467: }
7468: if ($noprint) {
7469: return <<"ENDSTYLE";
7470: <style type="text/css" media="print">
7471: body { display:none }
7472: </style>
7473: ENDSTYLE
7474: }
7475: }
7476: return;
7477: }
7478:
7479: =pod
7480:
1.341 albertel 7481: =item * &xml_begin()
7482:
7483: Returns the needed doctype and <html>
7484:
7485: Inputs: none
7486:
7487: =cut
7488:
7489: sub xml_begin {
1.1168 raeburn 7490: my ($is_frameset) = @_;
1.341 albertel 7491: my $output='';
7492:
7493: if ($env{'browser.mathml'}) {
7494: $output='<?xml version="1.0"?>'
7495: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
7496: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
7497:
7498: # .'<!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">] >'
7499: .'<!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">'
7500: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
7501: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 7502: } elsif ($is_frameset) {
7503: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
7504: '<html>'."\n";
1.341 albertel 7505: } else {
1.1168 raeburn 7506: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
7507: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 7508: }
7509: return $output;
7510: }
1.340 albertel 7511:
7512: =pod
7513:
1.306 albertel 7514: =item * &start_page()
7515:
7516: Returns a complete <html> .. <body> section for LON-CAPA web pages.
7517:
1.648 raeburn 7518: Inputs:
7519:
7520: =over 4
7521:
7522: $title - optional title for the page
7523:
7524: $head_extra - optional extra HTML to incude inside the <head>
7525:
7526: $args - additional optional args supported are:
7527:
7528: =over 8
7529:
7530: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 7531: arg on
1.814 bisitz 7532: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 7533: add_entries -> additional attributes to add to the <body>
7534: domain -> force to color decorate a page for a
1.317 albertel 7535: specific domain
1.648 raeburn 7536: function -> force usage of a specific rolish color
1.317 albertel 7537: scheme
1.648 raeburn 7538: redirect -> see &headtag()
7539: bgcolor -> override the default page bg color
7540: js_ready -> return a string ready for being used in
1.317 albertel 7541: a javascript writeln
1.648 raeburn 7542: html_encode -> return a string ready for being used in
1.320 albertel 7543: a html attribute
1.648 raeburn 7544: force_register -> if is true will turn on the &bodytag()
1.317 albertel 7545: $forcereg arg
1.648 raeburn 7546: frameset -> if true will start with a <frameset>
1.330 albertel 7547: rather than <body>
1.648 raeburn 7548: skip_phases -> hash ref of
1.338 albertel 7549: head -> skip the <html><head> generation
7550: body -> skip all <body> generation
1.648 raeburn 7551: no_auto_mt_title -> prevent &mt()ing the title arg
7552: inherit_jsmath -> when creating popup window in a page,
7553: should it have jsmath forced on by the
7554: current page
1.867 kalberla 7555: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 7556: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1096 raeburn 7557: group -> includes the current group, if page is for a
7558: specific group
1.361 albertel 7559:
1.648 raeburn 7560: =back
1.460 albertel 7561:
1.648 raeburn 7562: =back
1.562 albertel 7563:
1.306 albertel 7564: =cut
7565:
7566: sub start_page {
1.309 albertel 7567: my ($title,$head_extra,$args) = @_;
1.318 albertel 7568: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 7569:
1.315 albertel 7570: $env{'internal.start_page'}++;
1.1096 raeburn 7571: my ($result,@advtools);
1.964 droeschl 7572:
1.338 albertel 7573: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 7574: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 7575: }
7576:
7577: if (! exists($args->{'skip_phases'}{'body'}) ) {
7578: if ($args->{'frameset'}) {
7579: my $attr_string = &make_attr_string($args->{'force_register'},
7580: $args->{'add_entries'});
7581: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 7582: } else {
7583: $result .=
7584: &bodytag($title,
7585: $args->{'function'}, $args->{'add_entries'},
7586: $args->{'only_body'}, $args->{'domain'},
7587: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 7588: $args->{'bgcolor'}, $args,
7589: \@advtools);
1.831 bisitz 7590: }
1.330 albertel 7591: }
1.338 albertel 7592:
1.315 albertel 7593: if ($args->{'js_ready'}) {
1.713 kaisler 7594: $result = &js_ready($result);
1.315 albertel 7595: }
1.320 albertel 7596: if ($args->{'html_encode'}) {
1.713 kaisler 7597: $result = &html_encode($result);
7598: }
7599:
1.813 bisitz 7600: # Preparation for new and consistent functionlist at top of screen
7601: # if ($args->{'functionlist'}) {
7602: # $result .= &build_functionlist();
7603: #}
7604:
1.964 droeschl 7605: # Don't add anything more if only_body wanted or in const space
7606: return $result if $args->{'only_body'}
7607: || $env{'request.state'} eq 'construct';
1.813 bisitz 7608:
7609: #Breadcrumbs
1.758 kaisler 7610: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
7611: &Apache::lonhtmlcommon::clear_breadcrumbs();
7612: #if any br links exists, add them to the breadcrumbs
7613: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
7614: foreach my $crumb (@{$args->{'bread_crumbs'}}){
7615: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
7616: }
7617: }
1.1096 raeburn 7618: # if @advtools array contains items add then to the breadcrumbs
7619: if (@advtools > 0) {
7620: &Apache::lonmenu::advtools_crumbs(@advtools);
7621: }
1.758 kaisler 7622:
7623: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
7624: if(exists($args->{'bread_crumbs_component'})){
7625: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
7626: }else{
7627: $result .= &Apache::lonhtmlcommon::breadcrumbs();
7628: }
1.320 albertel 7629: }
1.315 albertel 7630: return $result;
1.306 albertel 7631: }
7632:
7633: sub end_page {
1.315 albertel 7634: my ($args) = @_;
7635: $env{'internal.end_page'}++;
1.330 albertel 7636: my $result;
1.335 albertel 7637: if ($args->{'discussion'}) {
7638: my ($target,$parser);
7639: if (ref($args->{'discussion'})) {
7640: ($target,$parser) =($args->{'discussion'}{'target'},
7641: $args->{'discussion'}{'parser'});
7642: }
7643: $result .= &Apache::lonxml::xmlend($target,$parser);
7644: }
1.330 albertel 7645: if ($args->{'frameset'}) {
7646: $result .= '</frameset>';
7647: } else {
1.635 raeburn 7648: $result .= &endbodytag($args);
1.330 albertel 7649: }
1.1080 raeburn 7650: unless ($args->{'notbody'}) {
7651: $result .= "\n</html>";
7652: }
1.330 albertel 7653:
1.315 albertel 7654: if ($args->{'js_ready'}) {
1.317 albertel 7655: $result = &js_ready($result);
1.315 albertel 7656: }
1.335 albertel 7657:
1.320 albertel 7658: if ($args->{'html_encode'}) {
7659: $result = &html_encode($result);
7660: }
1.335 albertel 7661:
1.315 albertel 7662: return $result;
7663: }
7664:
1.1034 www 7665: sub wishlist_window {
7666: return(<<'ENDWISHLIST');
1.1046 raeburn 7667: <script type="text/javascript">
1.1034 www 7668: // <![CDATA[
7669: // <!-- BEGIN LON-CAPA Internal
7670: function set_wishlistlink(title, path) {
7671: if (!title) {
7672: title = document.title;
7673: title = title.replace(/^LON-CAPA /,'');
7674: }
1.1175 raeburn 7675: title = encodeURIComponent(title);
1.1034 www 7676: if (!path) {
7677: path = location.pathname;
7678: }
1.1175 raeburn 7679: path = encodeURIComponent(path);
1.1034 www 7680: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
7681: 'wishlistNewLink','width=560,height=350,scrollbars=0');
7682: }
7683: // END LON-CAPA Internal -->
7684: // ]]>
7685: </script>
7686: ENDWISHLIST
7687: }
7688:
1.1030 www 7689: sub modal_window {
7690: return(<<'ENDMODAL');
1.1046 raeburn 7691: <script type="text/javascript">
1.1030 www 7692: // <![CDATA[
7693: // <!-- BEGIN LON-CAPA Internal
7694: var modalWindow = {
7695: parent:"body",
7696: windowId:null,
7697: content:null,
7698: width:null,
7699: height:null,
7700: close:function()
7701: {
7702: $(".LCmodal-window").remove();
7703: $(".LCmodal-overlay").remove();
7704: },
7705: open:function()
7706: {
7707: var modal = "";
7708: modal += "<div class=\"LCmodal-overlay\"></div>";
7709: 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;\">";
7710: modal += this.content;
7711: modal += "</div>";
7712:
7713: $(this.parent).append(modal);
7714:
7715: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
7716: $(".LCclose-window").click(function(){modalWindow.close();});
7717: $(".LCmodal-overlay").click(function(){modalWindow.close();});
7718: }
7719: };
1.1140 raeburn 7720: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 7721: {
7722: modalWindow.windowId = "myModal";
7723: modalWindow.width = width;
7724: modalWindow.height = height;
1.1196 ! raeburn 7725: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 7726: modalWindow.open();
7727: };
7728: // END LON-CAPA Internal -->
7729: // ]]>
7730: </script>
7731: ENDMODAL
7732: }
7733:
7734: sub modal_link {
1.1140 raeburn 7735: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 7736: unless ($width) { $width=480; }
7737: unless ($height) { $height=400; }
1.1031 www 7738: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 7739: unless ($transparency) { $transparency='true'; }
7740:
1.1074 raeburn 7741: my $target_attr;
7742: if (defined($target)) {
7743: $target_attr = 'target="'.$target.'"';
7744: }
7745: return <<"ENDLINK";
1.1140 raeburn 7746: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 7747: $linktext</a>
7748: ENDLINK
1.1030 www 7749: }
7750:
1.1032 www 7751: sub modal_adhoc_script {
7752: my ($funcname,$width,$height,$content)=@_;
7753: return (<<ENDADHOC);
1.1046 raeburn 7754: <script type="text/javascript">
1.1032 www 7755: // <![CDATA[
7756: var $funcname = function()
7757: {
7758: modalWindow.windowId = "myModal";
7759: modalWindow.width = $width;
7760: modalWindow.height = $height;
7761: modalWindow.content = '$content';
7762: modalWindow.open();
7763: };
7764: // ]]>
7765: </script>
7766: ENDADHOC
7767: }
7768:
1.1041 www 7769: sub modal_adhoc_inner {
7770: my ($funcname,$width,$height,$content)=@_;
7771: my $innerwidth=$width-20;
7772: $content=&js_ready(
1.1140 raeburn 7773: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
7774: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
7775: $content.
1.1041 www 7776: &end_scrollbox().
1.1140 raeburn 7777: &end_page()
1.1041 www 7778: );
7779: return &modal_adhoc_script($funcname,$width,$height,$content);
7780: }
7781:
7782: sub modal_adhoc_window {
7783: my ($funcname,$width,$height,$content,$linktext)=@_;
7784: return &modal_adhoc_inner($funcname,$width,$height,$content).
7785: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
7786: }
7787:
7788: sub modal_adhoc_launch {
7789: my ($funcname,$width,$height,$content)=@_;
7790: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
7791: <script type="text/javascript">
7792: // <![CDATA[
7793: $funcname();
7794: // ]]>
7795: </script>
7796: ENDLAUNCH
7797: }
7798:
7799: sub modal_adhoc_close {
7800: return (<<ENDCLOSE);
7801: <script type="text/javascript">
7802: // <![CDATA[
7803: modalWindow.close();
7804: // ]]>
7805: </script>
7806: ENDCLOSE
7807: }
7808:
1.1038 www 7809: sub togglebox_script {
7810: return(<<ENDTOGGLE);
7811: <script type="text/javascript">
7812: // <![CDATA[
7813: function LCtoggleDisplay(id,hidetext,showtext) {
7814: link = document.getElementById(id + "link").childNodes[0];
7815: with (document.getElementById(id).style) {
7816: if (display == "none" ) {
7817: display = "inline";
7818: link.nodeValue = hidetext;
7819: } else {
7820: display = "none";
7821: link.nodeValue = showtext;
7822: }
7823: }
7824: }
7825: // ]]>
7826: </script>
7827: ENDTOGGLE
7828: }
7829:
1.1039 www 7830: sub start_togglebox {
7831: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
7832: unless ($heading) { $heading=''; } else { $heading.=' '; }
7833: unless ($showtext) { $showtext=&mt('show'); }
7834: unless ($hidetext) { $hidetext=&mt('hide'); }
7835: unless ($headerbg) { $headerbg='#FFFFFF'; }
7836: return &start_data_table().
7837: &start_data_table_header_row().
7838: '<td bgcolor="'.$headerbg.'">'.$heading.
7839: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
7840: $showtext.'\')">'.$showtext.'</a>]</td>'.
7841: &end_data_table_header_row().
7842: '<tr id="'.$id.'" style="display:none""><td>';
7843: }
7844:
7845: sub end_togglebox {
7846: return '</td></tr>'.&end_data_table();
7847: }
7848:
1.1041 www 7849: sub LCprogressbar_script {
1.1045 www 7850: my ($id)=@_;
1.1041 www 7851: return(<<ENDPROGRESS);
7852: <script type="text/javascript">
7853: // <![CDATA[
1.1045 www 7854: \$('#progressbar$id').progressbar({
1.1041 www 7855: value: 0,
7856: change: function(event, ui) {
7857: var newVal = \$(this).progressbar('option', 'value');
7858: \$('.pblabel', this).text(LCprogressTxt);
7859: }
7860: });
7861: // ]]>
7862: </script>
7863: ENDPROGRESS
7864: }
7865:
7866: sub LCprogressbarUpdate_script {
7867: return(<<ENDPROGRESSUPDATE);
7868: <style type="text/css">
7869: .ui-progressbar { position:relative; }
7870: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
7871: </style>
7872: <script type="text/javascript">
7873: // <![CDATA[
1.1045 www 7874: var LCprogressTxt='---';
7875:
7876: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 7877: LCprogressTxt=progresstext;
1.1045 www 7878: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 7879: }
7880: // ]]>
7881: </script>
7882: ENDPROGRESSUPDATE
7883: }
7884:
1.1042 www 7885: my $LClastpercent;
1.1045 www 7886: my $LCidcnt;
7887: my $LCcurrentid;
1.1042 www 7888:
1.1041 www 7889: sub LCprogressbar {
1.1042 www 7890: my ($r)=(@_);
7891: $LClastpercent=0;
1.1045 www 7892: $LCidcnt++;
7893: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 7894: my $starting=&mt('Starting');
7895: my $content=(<<ENDPROGBAR);
1.1045 www 7896: <div id="progressbar$LCcurrentid">
1.1041 www 7897: <span class="pblabel">$starting</span>
7898: </div>
7899: ENDPROGBAR
1.1045 www 7900: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 7901: }
7902:
7903: sub LCprogressbarUpdate {
1.1042 www 7904: my ($r,$val,$text)=@_;
7905: unless ($val) {
7906: if ($LClastpercent) {
7907: $val=$LClastpercent;
7908: } else {
7909: $val=0;
7910: }
7911: }
1.1041 www 7912: if ($val<0) { $val=0; }
7913: if ($val>100) { $val=0; }
1.1042 www 7914: $LClastpercent=$val;
1.1041 www 7915: unless ($text) { $text=$val.'%'; }
7916: $text=&js_ready($text);
1.1044 www 7917: &r_print($r,<<ENDUPDATE);
1.1041 www 7918: <script type="text/javascript">
7919: // <![CDATA[
1.1045 www 7920: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 7921: // ]]>
7922: </script>
7923: ENDUPDATE
1.1035 www 7924: }
7925:
1.1042 www 7926: sub LCprogressbarClose {
7927: my ($r)=@_;
7928: $LClastpercent=0;
1.1044 www 7929: &r_print($r,<<ENDCLOSE);
1.1042 www 7930: <script type="text/javascript">
7931: // <![CDATA[
1.1045 www 7932: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 7933: // ]]>
7934: </script>
7935: ENDCLOSE
1.1044 www 7936: }
7937:
7938: sub r_print {
7939: my ($r,$to_print)=@_;
7940: if ($r) {
7941: $r->print($to_print);
7942: $r->rflush();
7943: } else {
7944: print($to_print);
7945: }
1.1042 www 7946: }
7947:
1.320 albertel 7948: sub html_encode {
7949: my ($result) = @_;
7950:
1.322 albertel 7951: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 7952:
7953: return $result;
7954: }
1.1044 www 7955:
1.317 albertel 7956: sub js_ready {
7957: my ($result) = @_;
7958:
1.323 albertel 7959: $result =~ s/[\n\r]/ /xmsg;
7960: $result =~ s/\\/\\\\/xmsg;
7961: $result =~ s/'/\\'/xmsg;
1.372 albertel 7962: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 7963:
7964: return $result;
7965: }
7966:
1.315 albertel 7967: sub validate_page {
7968: if ( exists($env{'internal.start_page'})
1.316 albertel 7969: && $env{'internal.start_page'} > 1) {
7970: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 7971: $env{'internal.start_page'}.' '.
1.316 albertel 7972: $ENV{'request.filename'});
1.315 albertel 7973: }
7974: if ( exists($env{'internal.end_page'})
1.316 albertel 7975: && $env{'internal.end_page'} > 1) {
7976: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 7977: $env{'internal.end_page'}.' '.
1.316 albertel 7978: $env{'request.filename'});
1.315 albertel 7979: }
7980: if ( exists($env{'internal.start_page'})
7981: && ! exists($env{'internal.end_page'})) {
1.316 albertel 7982: &Apache::lonnet::logthis('start_page called without end_page '.
7983: $env{'request.filename'});
1.315 albertel 7984: }
7985: if ( ! exists($env{'internal.start_page'})
7986: && exists($env{'internal.end_page'})) {
1.316 albertel 7987: &Apache::lonnet::logthis('end_page called without start_page'.
7988: $env{'request.filename'});
1.315 albertel 7989: }
1.306 albertel 7990: }
1.315 albertel 7991:
1.996 www 7992:
7993: sub start_scrollbox {
1.1140 raeburn 7994: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 7995: unless ($outerwidth) { $outerwidth='520px'; }
7996: unless ($width) { $width='500px'; }
7997: unless ($height) { $height='200px'; }
1.1075 raeburn 7998: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 7999: if ($id ne '') {
1.1140 raeburn 8000: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 8001: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8002: }
1.1075 raeburn 8003: if ($bgcolor ne '') {
8004: $tdcol = "background-color: $bgcolor;";
8005: }
1.1137 raeburn 8006: my $nicescroll_js;
8007: if ($env{'browser.mobile'}) {
1.1140 raeburn 8008: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8009: }
8010: return <<"END";
8011: $nicescroll_js
8012:
8013: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
8014: <div style="overflow:auto; width:$width; height:$height;"$div_id>
8015: END
8016: }
8017:
8018: sub end_scrollbox {
8019: return '</div></td></tr></table>';
8020: }
8021:
8022: sub nicescroll_javascript {
8023: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8024: my %options;
8025: if (ref($cursor) eq 'HASH') {
8026: %options = %{$cursor};
8027: }
8028: unless ($options{'railalign'} =~ /^left|right$/) {
8029: $options{'railalign'} = 'left';
8030: }
8031: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8032: my $function = &get_users_function();
8033: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 8034: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 8035: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 8036: }
1.1140 raeburn 8037: }
8038: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8039: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 8040: $options{'cursoropacity'}='1.0';
8041: }
1.1140 raeburn 8042: } else {
8043: $options{'cursoropacity'}='1.0';
8044: }
8045: if ($options{'cursorfixedheight'} eq 'none') {
8046: delete($options{'cursorfixedheight'});
8047: } else {
8048: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8049: }
8050: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8051: delete($options{'railoffset'});
8052: }
8053: my @niceoptions;
8054: while (my($key,$value) = each(%options)) {
8055: if ($value =~ /^\{.+\}$/) {
8056: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 8057: } else {
1.1140 raeburn 8058: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 8059: }
1.1140 raeburn 8060: }
8061: my $nicescroll_js = '
1.1137 raeburn 8062: $(document).ready(
1.1140 raeburn 8063: function() {
8064: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8065: }
1.1137 raeburn 8066: );
8067: ';
1.1140 raeburn 8068: if ($framecheck) {
8069: $nicescroll_js .= '
8070: function expand_div(caller) {
8071: if (top === self) {
8072: document.getElementById("'.$id.'").style.width = "auto";
8073: document.getElementById("'.$id.'").style.height = "auto";
8074: } else {
8075: try {
8076: if (parent.frames) {
8077: if (parent.frames.length > 1) {
8078: var framesrc = parent.frames[1].location.href;
8079: var currsrc = framesrc.replace(/\#.*$/,"");
8080: if ((caller == "search") || (currsrc == "'.$location.'")) {
8081: document.getElementById("'.$id.'").style.width = "auto";
8082: document.getElementById("'.$id.'").style.height = "auto";
8083: }
8084: }
8085: }
8086: } catch (e) {
8087: return;
8088: }
1.1137 raeburn 8089: }
1.1140 raeburn 8090: return;
1.996 www 8091: }
1.1140 raeburn 8092: ';
8093: }
8094: if ($needjsready) {
8095: $nicescroll_js = '
8096: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8097: } else {
8098: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8099: }
8100: return $nicescroll_js;
1.996 www 8101: }
8102:
1.318 albertel 8103: sub simple_error_page {
1.1150 bisitz 8104: my ($r,$title,$msg,$args) = @_;
1.1151 raeburn 8105: if (ref($args) eq 'HASH') {
8106: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8107: } else {
8108: $msg = &mt($msg);
8109: }
1.1150 bisitz 8110:
1.318 albertel 8111: my $page =
8112: &Apache::loncommon::start_page($title).
1.1150 bisitz 8113: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8114: &Apache::loncommon::end_page();
8115: if (ref($r)) {
8116: $r->print($page);
1.327 albertel 8117: return;
1.318 albertel 8118: }
8119: return $page;
8120: }
1.347 albertel 8121:
8122: {
1.610 albertel 8123: my @row_count;
1.961 onken 8124:
8125: sub start_data_table_count {
8126: unshift(@row_count, 0);
8127: return;
8128: }
8129:
8130: sub end_data_table_count {
8131: shift(@row_count);
8132: return;
8133: }
8134:
1.347 albertel 8135: sub start_data_table {
1.1018 raeburn 8136: my ($add_class,$id) = @_;
1.422 albertel 8137: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8138: my $table_id;
8139: if (defined($id)) {
8140: $table_id = ' id="'.$id.'"';
8141: }
1.961 onken 8142: &start_data_table_count();
1.1018 raeburn 8143: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8144: }
8145:
8146: sub end_data_table {
1.961 onken 8147: &end_data_table_count();
1.389 albertel 8148: return '</table>'."\n";;
1.347 albertel 8149: }
8150:
8151: sub start_data_table_row {
1.974 wenzelju 8152: my ($add_class, $id) = @_;
1.610 albertel 8153: $row_count[0]++;
8154: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8155: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8156: $id = (' id="'.$id.'"') unless ($id eq '');
8157: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8158: }
1.471 banghart 8159:
8160: sub continue_data_table_row {
1.974 wenzelju 8161: my ($add_class, $id) = @_;
1.610 albertel 8162: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8163: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8164: $id = (' id="'.$id.'"') unless ($id eq '');
8165: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8166: }
1.347 albertel 8167:
8168: sub end_data_table_row {
1.389 albertel 8169: return '</tr>'."\n";;
1.347 albertel 8170: }
1.367 www 8171:
1.421 albertel 8172: sub start_data_table_empty_row {
1.707 bisitz 8173: # $row_count[0]++;
1.421 albertel 8174: return '<tr class="LC_empty_row" >'."\n";;
8175: }
8176:
8177: sub end_data_table_empty_row {
8178: return '</tr>'."\n";;
8179: }
8180:
1.367 www 8181: sub start_data_table_header_row {
1.389 albertel 8182: return '<tr class="LC_header_row">'."\n";;
1.367 www 8183: }
8184:
8185: sub end_data_table_header_row {
1.389 albertel 8186: return '</tr>'."\n";;
1.367 www 8187: }
1.890 droeschl 8188:
8189: sub data_table_caption {
8190: my $caption = shift;
8191: return "<caption class=\"LC_caption\">$caption</caption>";
8192: }
1.347 albertel 8193: }
8194:
1.548 albertel 8195: =pod
8196:
8197: =item * &inhibit_menu_check($arg)
8198:
8199: Checks for a inhibitmenu state and generates output to preserve it
8200:
8201: Inputs: $arg - can be any of
8202: - undef - in which case the return value is a string
8203: to add into arguments list of a uri
8204: - 'input' - in which case the return value is a HTML
8205: <form> <input> field of type hidden to
8206: preserve the value
8207: - a url - in which case the return value is the url with
8208: the neccesary cgi args added to preserve the
8209: inhibitmenu state
8210: - a ref to a url - no return value, but the string is
8211: updated to include the neccessary cgi
8212: args to preserve the inhibitmenu state
8213:
8214: =cut
8215:
8216: sub inhibit_menu_check {
8217: my ($arg) = @_;
8218: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8219: if ($arg eq 'input') {
8220: if ($env{'form.inhibitmenu'}) {
8221: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8222: } else {
8223: return
8224: }
8225: }
8226: if ($env{'form.inhibitmenu'}) {
8227: if (ref($arg)) {
8228: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8229: } elsif ($arg eq '') {
8230: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8231: } else {
8232: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8233: }
8234: }
8235: if (!ref($arg)) {
8236: return $arg;
8237: }
8238: }
8239:
1.251 albertel 8240: ###############################################
1.182 matthew 8241:
8242: =pod
8243:
1.549 albertel 8244: =back
8245:
8246: =head1 User Information Routines
8247:
8248: =over 4
8249:
1.405 albertel 8250: =item * &get_users_function()
1.182 matthew 8251:
8252: Used by &bodytag to determine the current users primary role.
8253: Returns either 'student','coordinator','admin', or 'author'.
8254:
8255: =cut
8256:
8257: ###############################################
8258: sub get_users_function {
1.815 tempelho 8259: my $function = 'norole';
1.818 tempelho 8260: if ($env{'request.role'}=~/^(st)/) {
8261: $function='student';
8262: }
1.907 raeburn 8263: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8264: $function='coordinator';
8265: }
1.258 albertel 8266: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8267: $function='admin';
8268: }
1.826 bisitz 8269: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8270: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8271: $function='author';
8272: }
8273: return $function;
1.54 www 8274: }
1.99 www 8275:
8276: ###############################################
8277:
1.233 raeburn 8278: =pod
8279:
1.821 raeburn 8280: =item * &show_course()
8281:
8282: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8283: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8284:
8285: Inputs:
8286: None
8287:
8288: Outputs:
8289: Scalar: 1 if 'Course' to be used, 0 otherwise.
8290:
8291: =cut
8292:
8293: ###############################################
8294: sub show_course {
8295: my $course = !$env{'user.adv'};
8296: if (!$env{'user.adv'}) {
8297: foreach my $env (keys(%env)) {
8298: next if ($env !~ m/^user\.priv\./);
8299: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8300: $course = 0;
8301: last;
8302: }
8303: }
8304: }
8305: return $course;
8306: }
8307:
8308: ###############################################
8309:
8310: =pod
8311:
1.542 raeburn 8312: =item * &check_user_status()
1.274 raeburn 8313:
8314: Determines current status of supplied role for a
8315: specific user. Roles can be active, previous or future.
8316:
8317: Inputs:
8318: user's domain, user's username, course's domain,
1.375 raeburn 8319: course's number, optional section ID.
1.274 raeburn 8320:
8321: Outputs:
8322: role status: active, previous or future.
8323:
8324: =cut
8325:
8326: sub check_user_status {
1.412 raeburn 8327: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8328: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.274 raeburn 8329: my @uroles = keys %userinfo;
8330: my $srchstr;
8331: my $active_chk = 'none';
1.412 raeburn 8332: my $now = time;
1.274 raeburn 8333: if (@uroles > 0) {
1.908 raeburn 8334: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8335: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8336: } else {
1.412 raeburn 8337: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8338: }
8339: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8340: my $role_end = 0;
8341: my $role_start = 0;
8342: $active_chk = 'active';
1.412 raeburn 8343: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8344: $role_end = $1;
8345: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8346: $role_start = $1;
1.274 raeburn 8347: }
8348: }
8349: if ($role_start > 0) {
1.412 raeburn 8350: if ($now < $role_start) {
1.274 raeburn 8351: $active_chk = 'future';
8352: }
8353: }
8354: if ($role_end > 0) {
1.412 raeburn 8355: if ($now > $role_end) {
1.274 raeburn 8356: $active_chk = 'previous';
8357: }
8358: }
8359: }
8360: }
8361: return $active_chk;
8362: }
8363:
8364: ###############################################
8365:
8366: =pod
8367:
1.405 albertel 8368: =item * &get_sections()
1.233 raeburn 8369:
8370: Determines all the sections for a course including
8371: sections with students and sections containing other roles.
1.419 raeburn 8372: Incoming parameters:
8373:
8374: 1. domain
8375: 2. course number
8376: 3. reference to array containing roles for which sections should
8377: be gathered (optional).
8378: 4. reference to array containing status types for which sections
8379: should be gathered (optional).
8380:
8381: If the third argument is undefined, sections are gathered for any role.
8382: If the fourth argument is undefined, sections are gathered for any status.
8383: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8384:
1.374 raeburn 8385: Returns section hash (keys are section IDs, values are
8386: number of users in each section), subject to the
1.419 raeburn 8387: optional roles filter, optional status filter
1.233 raeburn 8388:
8389: =cut
8390:
8391: ###############################################
8392: sub get_sections {
1.419 raeburn 8393: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 8394: if (!defined($cdom) || !defined($cnum)) {
8395: my $cid = $env{'request.course.id'};
8396:
8397: return if (!defined($cid));
8398:
8399: $cdom = $env{'course.'.$cid.'.domain'};
8400: $cnum = $env{'course.'.$cid.'.num'};
8401: }
8402:
8403: my %sectioncount;
1.419 raeburn 8404: my $now = time;
1.240 albertel 8405:
1.1118 raeburn 8406: my $check_students = 1;
8407: my $only_students = 0;
8408: if (ref($possible_roles) eq 'ARRAY') {
8409: if (grep(/^st$/,@{$possible_roles})) {
8410: if (@{$possible_roles} == 1) {
8411: $only_students = 1;
8412: }
8413: } else {
8414: $check_students = 0;
8415: }
8416: }
8417:
8418: if ($check_students) {
1.276 albertel 8419: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 8420: my $sec_index = &Apache::loncoursedata::CL_SECTION();
8421: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 8422: my $start_index = &Apache::loncoursedata::CL_START();
8423: my $end_index = &Apache::loncoursedata::CL_END();
8424: my $status;
1.366 albertel 8425: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 8426: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
8427: $data->[$status_index],
8428: $data->[$start_index],
8429: $data->[$end_index]);
8430: if ($stu_status eq 'Active') {
8431: $status = 'active';
8432: } elsif ($end < $now) {
8433: $status = 'previous';
8434: } elsif ($start > $now) {
8435: $status = 'future';
8436: }
8437: if ($section ne '-1' && $section !~ /^\s*$/) {
8438: if ((!defined($possible_status)) || (($status ne '') &&
8439: (grep/^\Q$status\E$/,@{$possible_status}))) {
8440: $sectioncount{$section}++;
8441: }
1.240 albertel 8442: }
8443: }
8444: }
1.1118 raeburn 8445: if ($only_students) {
8446: return %sectioncount;
8447: }
1.240 albertel 8448: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8449: foreach my $user (sort(keys(%courseroles))) {
8450: if ($user !~ /^(\w{2})/) { next; }
8451: my ($role) = ($user =~ /^(\w{2})/);
8452: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 8453: my ($section,$status);
1.240 albertel 8454: if ($role eq 'cr' &&
8455: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
8456: $section=$1;
8457: }
8458: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
8459: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 8460: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
8461: if ($end == -1 && $start == -1) {
8462: next; #deleted role
8463: }
8464: if (!defined($possible_status)) {
8465: $sectioncount{$section}++;
8466: } else {
8467: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
8468: $status = 'active';
8469: } elsif ($end < $now) {
8470: $status = 'future';
8471: } elsif ($start > $now) {
8472: $status = 'previous';
8473: }
8474: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
8475: $sectioncount{$section}++;
8476: }
8477: }
1.233 raeburn 8478: }
1.366 albertel 8479: return %sectioncount;
1.233 raeburn 8480: }
8481:
1.274 raeburn 8482: ###############################################
1.294 raeburn 8483:
8484: =pod
1.405 albertel 8485:
8486: =item * &get_course_users()
8487:
1.275 raeburn 8488: Retrieves usernames:domains for users in the specified course
8489: with specific role(s), and access status.
8490:
8491: Incoming parameters:
1.277 albertel 8492: 1. course domain
8493: 2. course number
8494: 3. access status: users must have - either active,
1.275 raeburn 8495: previous, future, or all.
1.277 albertel 8496: 4. reference to array of permissible roles
1.288 raeburn 8497: 5. reference to array of section restrictions (optional)
8498: 6. reference to results object (hash of hashes).
8499: 7. reference to optional userdata hash
1.609 raeburn 8500: 8. reference to optional statushash
1.630 raeburn 8501: 9. flag if privileged users (except those set to unhide in
8502: course settings) should be excluded
1.609 raeburn 8503: Keys of top level results hash are roles.
1.275 raeburn 8504: Keys of inner hashes are username:domain, with
8505: values set to access type.
1.288 raeburn 8506: Optional userdata hash returns an array with arguments in the
8507: same order as loncoursedata::get_classlist() for student data.
8508:
1.609 raeburn 8509: Optional statushash returns
8510:
1.288 raeburn 8511: Entries for end, start, section and status are blank because
8512: of the possibility of multiple values for non-student roles.
8513:
1.275 raeburn 8514: =cut
1.405 albertel 8515:
1.275 raeburn 8516: ###############################################
1.405 albertel 8517:
1.275 raeburn 8518: sub get_course_users {
1.630 raeburn 8519: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 8520: my %idx = ();
1.419 raeburn 8521: my %seclists;
1.288 raeburn 8522:
8523: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
8524: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
8525: $idx{end} = &Apache::loncoursedata::CL_END();
8526: $idx{start} = &Apache::loncoursedata::CL_START();
8527: $idx{id} = &Apache::loncoursedata::CL_ID();
8528: $idx{section} = &Apache::loncoursedata::CL_SECTION();
8529: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
8530: $idx{status} = &Apache::loncoursedata::CL_STATUS();
8531:
1.290 albertel 8532: if (grep(/^st$/,@{$roles})) {
1.276 albertel 8533: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 8534: my $now = time;
1.277 albertel 8535: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 8536: my $match = 0;
1.412 raeburn 8537: my $secmatch = 0;
1.419 raeburn 8538: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 8539: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 8540: if ($section eq '') {
8541: $section = 'none';
8542: }
1.291 albertel 8543: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8544: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8545: $secmatch = 1;
8546: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 8547: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8548: $secmatch = 1;
8549: }
8550: } else {
1.419 raeburn 8551: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 8552: $secmatch = 1;
8553: }
1.290 albertel 8554: }
1.412 raeburn 8555: if (!$secmatch) {
8556: next;
8557: }
1.419 raeburn 8558: }
1.275 raeburn 8559: if (defined($$types{'active'})) {
1.288 raeburn 8560: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 8561: push(@{$$users{st}{$student}},'active');
1.288 raeburn 8562: $match = 1;
1.275 raeburn 8563: }
8564: }
8565: if (defined($$types{'previous'})) {
1.609 raeburn 8566: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 8567: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 8568: $match = 1;
1.275 raeburn 8569: }
8570: }
8571: if (defined($$types{'future'})) {
1.609 raeburn 8572: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 8573: push(@{$$users{st}{$student}},'future');
1.288 raeburn 8574: $match = 1;
1.275 raeburn 8575: }
8576: }
1.609 raeburn 8577: if ($match) {
8578: push(@{$seclists{$student}},$section);
8579: if (ref($userdata) eq 'HASH') {
8580: $$userdata{$student} = $$classlist{$student};
8581: }
8582: if (ref($statushash) eq 'HASH') {
8583: $statushash->{$student}{'st'}{$section} = $status;
8584: }
1.288 raeburn 8585: }
1.275 raeburn 8586: }
8587: }
1.412 raeburn 8588: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 8589: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
8590: my $now = time;
1.609 raeburn 8591: my %displaystatus = ( previous => 'Expired',
8592: active => 'Active',
8593: future => 'Future',
8594: );
1.1121 raeburn 8595: my (%nothide,@possdoms);
1.630 raeburn 8596: if ($hidepriv) {
8597: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
8598: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
8599: if ($user !~ /:/) {
8600: $nothide{join(':',split(/[\@]/,$user))}=1;
8601: } else {
8602: $nothide{$user} = 1;
8603: }
8604: }
1.1121 raeburn 8605: my @possdoms = ($cdom);
8606: if ($coursehash{'checkforpriv'}) {
8607: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
8608: }
1.630 raeburn 8609: }
1.439 raeburn 8610: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 8611: my $match = 0;
1.412 raeburn 8612: my $secmatch = 0;
1.439 raeburn 8613: my $status;
1.412 raeburn 8614: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 8615: $user =~ s/:$//;
1.439 raeburn 8616: my ($end,$start) = split(/:/,$coursepersonnel{$person});
8617: if ($end == -1 || $start == -1) {
8618: next;
8619: }
8620: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
8621: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 8622: my ($uname,$udom) = split(/:/,$user);
8623: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 8624: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 8625: $secmatch = 1;
8626: } elsif ($usec eq '') {
1.420 albertel 8627: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 8628: $secmatch = 1;
8629: }
8630: } else {
8631: if (grep(/^\Q$usec\E$/,@{$sections})) {
8632: $secmatch = 1;
8633: }
8634: }
8635: if (!$secmatch) {
8636: next;
8637: }
1.288 raeburn 8638: }
1.419 raeburn 8639: if ($usec eq '') {
8640: $usec = 'none';
8641: }
1.275 raeburn 8642: if ($uname ne '' && $udom ne '') {
1.630 raeburn 8643: if ($hidepriv) {
1.1121 raeburn 8644: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 8645: (!$nothide{$uname.':'.$udom})) {
8646: next;
8647: }
8648: }
1.503 raeburn 8649: if ($end > 0 && $end < $now) {
1.439 raeburn 8650: $status = 'previous';
8651: } elsif ($start > $now) {
8652: $status = 'future';
8653: } else {
8654: $status = 'active';
8655: }
1.277 albertel 8656: foreach my $type (keys(%{$types})) {
1.275 raeburn 8657: if ($status eq $type) {
1.420 albertel 8658: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 8659: push(@{$$users{$role}{$user}},$type);
8660: }
1.288 raeburn 8661: $match = 1;
8662: }
8663: }
1.419 raeburn 8664: if (($match) && (ref($userdata) eq 'HASH')) {
8665: if (!exists($$userdata{$uname.':'.$udom})) {
8666: &get_user_info($udom,$uname,\%idx,$userdata);
8667: }
1.420 albertel 8668: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 8669: push(@{$seclists{$uname.':'.$udom}},$usec);
8670: }
1.609 raeburn 8671: if (ref($statushash) eq 'HASH') {
8672: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
8673: }
1.275 raeburn 8674: }
8675: }
8676: }
8677: }
1.290 albertel 8678: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 8679: if ((defined($cdom)) && (defined($cnum))) {
8680: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
8681: if ( defined($csettings{'internal.courseowner'}) ) {
8682: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 8683: next if ($owner eq '');
8684: my ($ownername,$ownerdom);
8685: if ($owner =~ /^([^:]+):([^:]+)$/) {
8686: $ownername = $1;
8687: $ownerdom = $2;
8688: } else {
8689: $ownername = $owner;
8690: $ownerdom = $cdom;
8691: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 8692: }
8693: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 8694: if (defined($userdata) &&
1.609 raeburn 8695: !exists($$userdata{$owner})) {
8696: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
8697: if (!grep(/^none$/,@{$seclists{$owner}})) {
8698: push(@{$seclists{$owner}},'none');
8699: }
8700: if (ref($statushash) eq 'HASH') {
8701: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 8702: }
1.290 albertel 8703: }
1.279 raeburn 8704: }
8705: }
8706: }
1.419 raeburn 8707: foreach my $user (keys(%seclists)) {
8708: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
8709: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
8710: }
1.275 raeburn 8711: }
8712: return;
8713: }
8714:
1.288 raeburn 8715: sub get_user_info {
8716: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 8717: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
8718: &plainname($uname,$udom,'lastname');
1.291 albertel 8719: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 8720: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 8721: my %idhash = &Apache::lonnet::idrget($udom,($uname));
8722: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 8723: return;
8724: }
1.275 raeburn 8725:
1.472 raeburn 8726: ###############################################
8727:
8728: =pod
8729:
8730: =item * &get_user_quota()
8731:
1.1134 raeburn 8732: Retrieves quota assigned for storage of user files.
8733: Default is to report quota for portfolio files.
1.472 raeburn 8734:
8735: Incoming parameters:
8736: 1. user's username
8737: 2. user's domain
1.1134 raeburn 8738: 3. quota name - portfolio, author, or course
1.1136 raeburn 8739: (if no quota name provided, defaults to portfolio).
1.1165 raeburn 8740: 4. crstype - official, unofficial, textbook or community, if quota name is
1.1136 raeburn 8741: course
1.472 raeburn 8742:
8743: Returns:
1.1163 raeburn 8744: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 8745: 2. (Optional) Type of setting: custom or default
8746: (individually assigned or default for user's
8747: institutional status).
8748: 3. (Optional) - User's institutional status (e.g., faculty, staff
8749: or student - types as defined in localenroll::inst_usertypes
8750: for user's domain, which determines default quota for user.
8751: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 8752:
8753: If a value has been stored in the user's environment,
1.536 raeburn 8754: it will return that, otherwise it returns the maximal default
1.1134 raeburn 8755: defined for the user's institutional status(es) in the domain.
1.472 raeburn 8756:
8757: =cut
8758:
8759: ###############################################
8760:
8761:
8762: sub get_user_quota {
1.1136 raeburn 8763: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 8764: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 8765: if (!defined($udom)) {
8766: $udom = $env{'user.domain'};
8767: }
8768: if (!defined($uname)) {
8769: $uname = $env{'user.name'};
8770: }
8771: if (($udom eq '' || $uname eq '') ||
8772: ($udom eq 'public') && ($uname eq 'public')) {
8773: $quota = 0;
1.536 raeburn 8774: $quotatype = 'default';
8775: $defquota = 0;
1.472 raeburn 8776: } else {
1.536 raeburn 8777: my $inststatus;
1.1134 raeburn 8778: if ($quotaname eq 'course') {
8779: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
8780: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
8781: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
8782: } else {
8783: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
8784: $quota = $cenv{'internal.uploadquota'};
8785: }
1.536 raeburn 8786: } else {
1.1134 raeburn 8787: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
8788: if ($quotaname eq 'author') {
8789: $quota = $env{'environment.authorquota'};
8790: } else {
8791: $quota = $env{'environment.portfolioquota'};
8792: }
8793: $inststatus = $env{'environment.inststatus'};
8794: } else {
8795: my %userenv =
8796: &Apache::lonnet::get('environment',['portfolioquota',
8797: 'authorquota','inststatus'],$udom,$uname);
8798: my ($tmp) = keys(%userenv);
8799: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
8800: if ($quotaname eq 'author') {
8801: $quota = $userenv{'authorquota'};
8802: } else {
8803: $quota = $userenv{'portfolioquota'};
8804: }
8805: $inststatus = $userenv{'inststatus'};
8806: } else {
8807: undef(%userenv);
8808: }
8809: }
8810: }
8811: if ($quota eq '' || wantarray) {
8812: if ($quotaname eq 'course') {
8813: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 8814: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
8815: ($crstype eq 'community') || ($crstype eq 'textbook')) {
1.1136 raeburn 8816: $defquota = $domdefs{$crstype.'quota'};
8817: }
8818: if ($defquota eq '') {
8819: $defquota = 500;
8820: }
1.1134 raeburn 8821: } else {
8822: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
8823: }
8824: if ($quota eq '') {
8825: $quota = $defquota;
8826: $quotatype = 'default';
8827: } else {
8828: $quotatype = 'custom';
8829: }
1.472 raeburn 8830: }
8831: }
1.536 raeburn 8832: if (wantarray) {
8833: return ($quota,$quotatype,$settingstatus,$defquota);
8834: } else {
8835: return $quota;
8836: }
1.472 raeburn 8837: }
8838:
8839: ###############################################
8840:
8841: =pod
8842:
8843: =item * &default_quota()
8844:
1.536 raeburn 8845: Retrieves default quota assigned for storage of user portfolio files,
8846: given an (optional) user's institutional status.
1.472 raeburn 8847:
8848: Incoming parameters:
1.1142 raeburn 8849:
1.472 raeburn 8850: 1. domain
1.536 raeburn 8851: 2. (Optional) institutional status(es). This is a : separated list of
8852: status types (e.g., faculty, staff, student etc.)
8853: which apply to the user for whom the default is being retrieved.
8854: If the institutional status string in undefined, the domain
1.1134 raeburn 8855: default quota will be returned.
8856: 3. quota name - portfolio, author, or course
8857: (if no quota name provided, defaults to portfolio).
1.472 raeburn 8858:
8859: Returns:
1.1142 raeburn 8860:
1.1163 raeburn 8861: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 8862: 2. (Optional) institutional type which determined the value of the
8863: default quota.
1.472 raeburn 8864:
8865: If a value has been stored in the domain's configuration db,
8866: it will return that, otherwise it returns 20 (for backwards
8867: compatibility with domains which have not set up a configuration
1.1163 raeburn 8868: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 8869:
1.536 raeburn 8870: If the user's status includes multiple types (e.g., staff and student),
8871: the largest default quota which applies to the user determines the
8872: default quota returned.
8873:
1.472 raeburn 8874: =cut
8875:
8876: ###############################################
8877:
8878:
8879: sub default_quota {
1.1134 raeburn 8880: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 8881: my ($defquota,$settingstatus);
8882: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 8883: ['quotas'],$udom);
1.1134 raeburn 8884: my $key = 'defaultquota';
8885: if ($quotaname eq 'author') {
8886: $key = 'authorquota';
8887: }
1.622 raeburn 8888: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 8889: if ($inststatus ne '') {
1.765 raeburn 8890: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 8891: foreach my $item (@statuses) {
1.1134 raeburn 8892: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8893: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 8894: if ($defquota eq '') {
1.1134 raeburn 8895: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8896: $settingstatus = $item;
1.1134 raeburn 8897: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
8898: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 8899: $settingstatus = $item;
8900: }
8901: }
1.1134 raeburn 8902: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8903: if ($quotahash{'quotas'}{$item} ne '') {
8904: if ($defquota eq '') {
8905: $defquota = $quotahash{'quotas'}{$item};
8906: $settingstatus = $item;
8907: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
8908: $defquota = $quotahash{'quotas'}{$item};
8909: $settingstatus = $item;
8910: }
1.536 raeburn 8911: }
8912: }
8913: }
8914: }
8915: if ($defquota eq '') {
1.1134 raeburn 8916: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
8917: $defquota = $quotahash{'quotas'}{$key}{'default'};
8918: } elsif ($key eq 'defaultquota') {
1.711 raeburn 8919: $defquota = $quotahash{'quotas'}{'default'};
8920: }
1.536 raeburn 8921: $settingstatus = 'default';
1.1139 raeburn 8922: if ($defquota eq '') {
8923: if ($quotaname eq 'author') {
8924: $defquota = 500;
8925: }
8926: }
1.536 raeburn 8927: }
8928: } else {
8929: $settingstatus = 'default';
1.1134 raeburn 8930: if ($quotaname eq 'author') {
8931: $defquota = 500;
8932: } else {
8933: $defquota = 20;
8934: }
1.536 raeburn 8935: }
8936: if (wantarray) {
8937: return ($defquota,$settingstatus);
1.472 raeburn 8938: } else {
1.536 raeburn 8939: return $defquota;
1.472 raeburn 8940: }
8941: }
8942:
1.1135 raeburn 8943: ###############################################
8944:
8945: =pod
8946:
1.1136 raeburn 8947: =item * &excess_filesize_warning()
1.1135 raeburn 8948:
8949: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 8950: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 8951: space to be exceeded.
1.1136 raeburn 8952:
8953: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 8954: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 8955:
1.1165 raeburn 8956: Inputs: 7
1.1136 raeburn 8957: 1. username or coursenum
1.1135 raeburn 8958: 2. domain
1.1136 raeburn 8959: 3. context ('author' or 'course')
1.1135 raeburn 8960: 4. filename of file for which action is being requested
8961: 5. filesize (kB) of file
8962: 6. action being taken: copy or upload.
1.1165 raeburn 8963: 7. quotatype (in course context -- official, unofficial, community or textbook).
1.1135 raeburn 8964:
8965: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 8966: otherwise return null.
8967:
8968: =back
1.1135 raeburn 8969:
8970: =cut
8971:
1.1136 raeburn 8972: sub excess_filesize_warning {
1.1165 raeburn 8973: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 8974: my $current_disk_usage = 0;
1.1165 raeburn 8975: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 8976: if ($context eq 'author') {
8977: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
8978: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
8979: } else {
8980: foreach my $subdir ('docs','supplemental') {
8981: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
8982: }
8983: }
1.1135 raeburn 8984: $disk_quota = int($disk_quota * 1000);
8985: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 8986: return '<p class="LC_warning">'.
1.1135 raeburn 8987: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 8988: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
8989: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 8990: $disk_quota,$current_disk_usage).
8991: '</p>';
8992: }
8993: return;
8994: }
8995:
8996: ###############################################
8997:
8998:
1.1136 raeburn 8999:
9000:
1.384 raeburn 9001: sub get_secgrprole_info {
9002: my ($cdom,$cnum,$needroles,$type) = @_;
9003: my %sections_count = &get_sections($cdom,$cnum);
9004: my @sections = (sort {$a <=> $b} keys(%sections_count));
9005: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9006: my @groups = sort(keys(%curr_groups));
9007: my $allroles = [];
9008: my $rolehash;
9009: my $accesshash = {
9010: active => 'Currently has access',
9011: future => 'Will have future access',
9012: previous => 'Previously had access',
9013: };
9014: if ($needroles) {
9015: $rolehash = {'all' => 'all'};
1.385 albertel 9016: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9017: if (&Apache::lonnet::error(%user_roles)) {
9018: undef(%user_roles);
9019: }
9020: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9021: my ($role)=split(/\:/,$item,2);
9022: if ($role eq 'cr') { next; }
9023: if ($role =~ /^cr/) {
9024: $$rolehash{$role} = (split('/',$role))[3];
9025: } else {
9026: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9027: }
9028: }
9029: foreach my $key (sort(keys(%{$rolehash}))) {
9030: push(@{$allroles},$key);
9031: }
9032: push (@{$allroles},'st');
9033: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9034: }
9035: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9036: }
9037:
1.555 raeburn 9038: sub user_picker {
1.994 raeburn 9039: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 9040: my $currdom = $dom;
9041: my %curr_selected = (
9042: srchin => 'dom',
1.580 raeburn 9043: srchby => 'lastname',
1.555 raeburn 9044: );
9045: my $srchterm;
1.625 raeburn 9046: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9047: if ($srch->{'srchby'} ne '') {
9048: $curr_selected{'srchby'} = $srch->{'srchby'};
9049: }
9050: if ($srch->{'srchin'} ne '') {
9051: $curr_selected{'srchin'} = $srch->{'srchin'};
9052: }
9053: if ($srch->{'srchtype'} ne '') {
9054: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9055: }
9056: if ($srch->{'srchdomain'} ne '') {
9057: $currdom = $srch->{'srchdomain'};
9058: }
9059: $srchterm = $srch->{'srchterm'};
9060: }
9061: my %lt=&Apache::lonlocal::texthash(
1.573 raeburn 9062: 'usr' => 'Search criteria',
1.563 raeburn 9063: 'doma' => 'Domain/institution to search',
1.558 albertel 9064: 'uname' => 'username',
9065: 'lastname' => 'last name',
1.555 raeburn 9066: 'lastfirst' => 'last name, first name',
1.558 albertel 9067: 'crs' => 'in this course',
1.576 raeburn 9068: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9069: 'alc' => 'all LON-CAPA',
1.573 raeburn 9070: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9071: 'exact' => 'is',
9072: 'contains' => 'contains',
1.569 raeburn 9073: 'begins' => 'begins with',
1.571 raeburn 9074: 'youm' => "You must include some text to search for.",
9075: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9076: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9077: 'yomc' => "You must choose a domain when using an institutional directory search.",
9078: 'ymcd' => "You must choose a domain when using a domain search.",
9079: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9080: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9081: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9082: );
1.563 raeburn 9083: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9084: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9085:
9086: my @srchins = ('crs','dom','alc','instd');
9087:
9088: foreach my $option (@srchins) {
9089: # FIXME 'alc' option unavailable until
9090: # loncreateuser::print_user_query_page()
9091: # has been completed.
9092: next if ($option eq 'alc');
1.880 raeburn 9093: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9094: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9095: if ($curr_selected{'srchin'} eq $option) {
9096: $srchinsel .= '
9097: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9098: } else {
9099: $srchinsel .= '
9100: <option value="'.$option.'">'.$lt{$option}.'</option>';
9101: }
1.555 raeburn 9102: }
1.563 raeburn 9103: $srchinsel .= "\n </select>\n";
1.555 raeburn 9104:
9105: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9106: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9107: if ($curr_selected{'srchby'} eq $option) {
9108: $srchbysel .= '
9109: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9110: } else {
9111: $srchbysel .= '
9112: <option value="'.$option.'">'.$lt{$option}.'</option>';
9113: }
9114: }
9115: $srchbysel .= "\n </select>\n";
9116:
9117: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9118: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9119: if ($curr_selected{'srchtype'} eq $option) {
9120: $srchtypesel .= '
9121: <option value="'.$option.'" selected="selected">'.$lt{$option}.'</option>';
9122: } else {
9123: $srchtypesel .= '
9124: <option value="'.$option.'">'.$lt{$option}.'</option>';
9125: }
9126: }
9127: $srchtypesel .= "\n </select>\n";
9128:
1.558 albertel 9129: my ($newuserscript,$new_user_create);
1.994 raeburn 9130: my $context_dom = $env{'request.role.domain'};
9131: if ($context eq 'requestcrs') {
9132: if ($env{'form.coursedom'} ne '') {
9133: $context_dom = $env{'form.coursedom'};
9134: }
9135: }
1.556 raeburn 9136: if ($forcenewuser) {
1.576 raeburn 9137: if (ref($srch) eq 'HASH') {
1.994 raeburn 9138: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9139: if ($cancreate) {
9140: $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>';
9141: } else {
1.799 bisitz 9142: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9143: my %usertypetext = (
9144: official => 'institutional',
9145: unofficial => 'non-institutional',
9146: );
1.799 bisitz 9147: $new_user_create = '<p class="LC_warning">'
9148: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9149: .' '
9150: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9151: ,'<a href="'.$helplink.'">','</a>')
9152: .'</p><br />';
1.627 raeburn 9153: }
1.576 raeburn 9154: }
9155: }
9156:
1.556 raeburn 9157: $newuserscript = <<"ENDSCRIPT";
9158:
1.570 raeburn 9159: function setSearch(createnew,callingForm) {
1.556 raeburn 9160: if (createnew == 1) {
1.570 raeburn 9161: for (var i=0; i<callingForm.srchby.length; i++) {
9162: if (callingForm.srchby.options[i].value == 'uname') {
9163: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9164: }
9165: }
1.570 raeburn 9166: for (var i=0; i<callingForm.srchin.length; i++) {
9167: if ( callingForm.srchin.options[i].value == 'dom') {
9168: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9169: }
9170: }
1.570 raeburn 9171: for (var i=0; i<callingForm.srchtype.length; i++) {
9172: if (callingForm.srchtype.options[i].value == 'exact') {
9173: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9174: }
9175: }
1.570 raeburn 9176: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9177: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9178: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9179: }
9180: }
9181: }
9182: }
9183: ENDSCRIPT
1.558 albertel 9184:
1.556 raeburn 9185: }
9186:
1.555 raeburn 9187: my $output = <<"END_BLOCK";
1.556 raeburn 9188: <script type="text/javascript">
1.824 bisitz 9189: // <![CDATA[
1.570 raeburn 9190: function validateEntry(callingForm) {
1.558 albertel 9191:
1.556 raeburn 9192: var checkok = 1;
1.558 albertel 9193: var srchin;
1.570 raeburn 9194: for (var i=0; i<callingForm.srchin.length; i++) {
9195: if ( callingForm.srchin[i].checked ) {
9196: srchin = callingForm.srchin[i].value;
1.558 albertel 9197: }
9198: }
9199:
1.570 raeburn 9200: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9201: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9202: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9203: var srchterm = callingForm.srchterm.value;
9204: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9205: var msg = "";
9206:
9207: if (srchterm == "") {
9208: checkok = 0;
1.571 raeburn 9209: msg += "$lt{'youm'}\\n";
1.556 raeburn 9210: }
9211:
1.569 raeburn 9212: if (srchtype== 'begins') {
9213: if (srchterm.length < 2) {
9214: checkok = 0;
1.571 raeburn 9215: msg += "$lt{'thte'}\\n";
1.569 raeburn 9216: }
9217: }
9218:
1.556 raeburn 9219: if (srchtype== 'contains') {
9220: if (srchterm.length < 3) {
9221: checkok = 0;
1.571 raeburn 9222: msg += "$lt{'thet'}\\n";
1.556 raeburn 9223: }
9224: }
9225: if (srchin == 'instd') {
9226: if (srchdomain == '') {
9227: checkok = 0;
1.571 raeburn 9228: msg += "$lt{'yomc'}\\n";
1.556 raeburn 9229: }
9230: }
9231: if (srchin == 'dom') {
9232: if (srchdomain == '') {
9233: checkok = 0;
1.571 raeburn 9234: msg += "$lt{'ymcd'}\\n";
1.556 raeburn 9235: }
9236: }
9237: if (srchby == 'lastfirst') {
9238: if (srchterm.indexOf(",") == -1) {
9239: checkok = 0;
1.571 raeburn 9240: msg += "$lt{'whus'}\\n";
1.556 raeburn 9241: }
9242: if (srchterm.indexOf(",") == srchterm.length -1) {
9243: checkok = 0;
1.571 raeburn 9244: msg += "$lt{'whse'}\\n";
1.556 raeburn 9245: }
9246: }
9247: if (checkok == 0) {
1.571 raeburn 9248: alert("$lt{'thfo'}\\n"+msg);
1.556 raeburn 9249: return;
9250: }
9251: if (checkok == 1) {
1.570 raeburn 9252: callingForm.submit();
1.556 raeburn 9253: }
9254: }
9255:
9256: $newuserscript
9257:
1.824 bisitz 9258: // ]]>
1.556 raeburn 9259: </script>
1.558 albertel 9260:
9261: $new_user_create
9262:
1.555 raeburn 9263: END_BLOCK
1.558 albertel 9264:
1.876 raeburn 9265: $output .= &Apache::lonhtmlcommon::start_pick_box().
9266: &Apache::lonhtmlcommon::row_title($lt{'doma'}).
9267: $domform.
9268: &Apache::lonhtmlcommon::row_closure().
9269: &Apache::lonhtmlcommon::row_title($lt{'usr'}).
9270: $srchbysel.
9271: $srchtypesel.
9272: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9273: $srchinsel.
9274: &Apache::lonhtmlcommon::row_closure(1).
9275: &Apache::lonhtmlcommon::end_pick_box().
9276: '<br />';
1.555 raeburn 9277: return $output;
9278: }
9279:
1.612 raeburn 9280: sub user_rule_check {
1.615 raeburn 9281: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.612 raeburn 9282: my $response;
9283: if (ref($usershash) eq 'HASH') {
9284: foreach my $user (keys(%{$usershash})) {
9285: my ($uname,$udom) = split(/:/,$user);
9286: next if ($udom eq '' || $uname eq '');
1.615 raeburn 9287: my ($id,$newuser);
1.612 raeburn 9288: if (ref($usershash->{$user}) eq 'HASH') {
1.615 raeburn 9289: $newuser = $usershash->{$user}->{'newuser'};
1.612 raeburn 9290: $id = $usershash->{$user}->{'id'};
9291: }
9292: my $inst_response;
9293: if (ref($checks) eq 'HASH') {
9294: if (defined($checks->{'username'})) {
1.615 raeburn 9295: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9296: &Apache::lonnet::get_instuser($udom,$uname);
9297: } elsif (defined($checks->{'id'})) {
1.615 raeburn 9298: ($inst_response,%{$inst_results->{$user}}) =
1.612 raeburn 9299: &Apache::lonnet::get_instuser($udom,undef,$id);
9300: }
1.615 raeburn 9301: } else {
9302: ($inst_response,%{$inst_results->{$user}}) =
9303: &Apache::lonnet::get_instuser($udom,$uname);
9304: return;
1.612 raeburn 9305: }
1.615 raeburn 9306: if (!$got_rules->{$udom}) {
1.612 raeburn 9307: my %domconfig = &Apache::lonnet::get_dom('configuration',
9308: ['usercreation'],$udom);
9309: if (ref($domconfig{'usercreation'}) eq 'HASH') {
1.615 raeburn 9310: foreach my $item ('username','id') {
1.612 raeburn 9311: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
9312: $$curr_rules{$udom}{$item} =
9313: $domconfig{'usercreation'}{$item.'_rule'};
1.585 raeburn 9314: }
9315: }
9316: }
1.615 raeburn 9317: $got_rules->{$udom} = 1;
1.585 raeburn 9318: }
1.612 raeburn 9319: foreach my $item (keys(%{$checks})) {
9320: if (ref($$curr_rules{$udom}) eq 'HASH') {
9321: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
9322: if (@{$$curr_rules{$udom}{$item}} > 0) {
9323: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,$$curr_rules{$udom}{$item});
9324: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
9325: if ($rule_check{$rule}) {
9326: $$rulematch{$user}{$item} = $rule;
9327: if ($inst_response eq 'ok') {
1.615 raeburn 9328: if (ref($inst_results) eq 'HASH') {
9329: if (ref($inst_results->{$user}) eq 'HASH') {
9330: if (keys(%{$inst_results->{$user}}) == 0) {
9331: $$alerts{$item}{$udom}{$uname} = 1;
9332: }
1.612 raeburn 9333: }
9334: }
1.615 raeburn 9335: }
9336: last;
1.585 raeburn 9337: }
9338: }
9339: }
9340: }
9341: }
9342: }
9343: }
9344: }
1.612 raeburn 9345: return;
9346: }
9347:
9348: sub user_rule_formats {
9349: my ($domain,$domdesc,$curr_rules,$check) = @_;
9350: my %text = (
9351: 'username' => 'Usernames',
9352: 'id' => 'IDs',
9353: );
9354: my $output;
9355: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
9356: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
9357: if (@{$ruleorder} > 0) {
1.1102 raeburn 9358: $output = '<br />'.
9359: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
9360: '<span class="LC_cusr_emph">','</span>',$domdesc).
9361: ' <ul>';
1.612 raeburn 9362: foreach my $rule (@{$ruleorder}) {
9363: if (ref($curr_rules) eq 'ARRAY') {
9364: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
9365: if (ref($rules->{$rule}) eq 'HASH') {
9366: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
9367: $rules->{$rule}{'desc'}.'</li>';
9368: }
9369: }
9370: }
9371: }
9372: $output .= '</ul>';
9373: }
9374: }
9375: return $output;
9376: }
9377:
9378: sub instrule_disallow_msg {
1.615 raeburn 9379: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 9380: my $response;
9381: my %text = (
9382: item => 'username',
9383: items => 'usernames',
9384: match => 'matches',
9385: do => 'does',
9386: action => 'a username',
9387: one => 'one',
9388: );
9389: if ($count > 1) {
9390: $text{'item'} = 'usernames';
9391: $text{'match'} ='match';
9392: $text{'do'} = 'do';
9393: $text{'action'} = 'usernames',
9394: $text{'one'} = 'ones';
9395: }
9396: if ($checkitem eq 'id') {
9397: $text{'items'} = 'IDs';
9398: $text{'item'} = 'ID';
9399: $text{'action'} = 'an ID';
1.615 raeburn 9400: if ($count > 1) {
9401: $text{'item'} = 'IDs';
9402: $text{'action'} = 'IDs';
9403: }
1.612 raeburn 9404: }
1.674 bisitz 9405: $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 9406: if ($mode eq 'upload') {
9407: if ($checkitem eq 'username') {
9408: $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'}.");
9409: } elsif ($checkitem eq 'id') {
1.674 bisitz 9410: $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 9411: }
1.669 raeburn 9412: } elsif ($mode eq 'selfcreate') {
9413: if ($checkitem eq 'id') {
9414: $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.");
9415: }
1.615 raeburn 9416: } else {
9417: if ($checkitem eq 'username') {
9418: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
9419: } elsif ($checkitem eq 'id') {
9420: $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.");
9421: }
1.612 raeburn 9422: }
9423: return $response;
1.585 raeburn 9424: }
9425:
1.624 raeburn 9426: sub personal_data_fieldtitles {
9427: my %fieldtitles = &Apache::lonlocal::texthash (
9428: id => 'Student/Employee ID',
9429: permanentemail => 'E-mail address',
9430: lastname => 'Last Name',
9431: firstname => 'First Name',
9432: middlename => 'Middle Name',
9433: generation => 'Generation',
9434: gen => 'Generation',
1.765 raeburn 9435: inststatus => 'Affiliation',
1.624 raeburn 9436: );
9437: return %fieldtitles;
9438: }
9439:
1.642 raeburn 9440: sub sorted_inst_types {
9441: my ($dom) = @_;
1.1185 raeburn 9442: my ($usertypes,$order);
9443: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
9444: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
9445: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
9446: $order = $domdefaults{'inststatus'}{'inststatusorder'};
9447: } else {
9448: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
9449: }
1.642 raeburn 9450: my $othertitle = &mt('All users');
9451: if ($env{'request.course.id'}) {
1.668 raeburn 9452: $othertitle = &mt('Any users');
1.642 raeburn 9453: }
9454: my @types;
9455: if (ref($order) eq 'ARRAY') {
9456: @types = @{$order};
9457: }
9458: if (@types == 0) {
9459: if (ref($usertypes) eq 'HASH') {
9460: @types = sort(keys(%{$usertypes}));
9461: }
9462: }
9463: if (keys(%{$usertypes}) > 0) {
9464: $othertitle = &mt('Other users');
9465: }
9466: return ($othertitle,$usertypes,\@types);
9467: }
9468:
1.645 raeburn 9469: sub get_institutional_codes {
9470: my ($settings,$allcourses,$LC_code) = @_;
9471: # Get complete list of course sections to update
9472: my @currsections = ();
9473: my @currxlists = ();
9474: my $coursecode = $$settings{'internal.coursecode'};
9475:
9476: if ($$settings{'internal.sectionnums'} ne '') {
9477: @currsections = split(/,/,$$settings{'internal.sectionnums'});
9478: }
9479:
9480: if ($$settings{'internal.crosslistings'} ne '') {
9481: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
9482: }
9483:
9484: if (@currxlists > 0) {
9485: foreach (@currxlists) {
9486: if (m/^([^:]+):(\w*)$/) {
9487: unless (grep/^$1$/,@{$allcourses}) {
9488: push @{$allcourses},$1;
9489: $$LC_code{$1} = $2;
9490: }
9491: }
9492: }
9493: }
9494:
9495: if (@currsections > 0) {
9496: foreach (@currsections) {
9497: if (m/^(\w+):(\w*)$/) {
9498: my $sec = $coursecode.$1;
9499: my $lc_sec = $2;
9500: unless (grep/^$sec$/,@{$allcourses}) {
9501: push @{$allcourses},$sec;
9502: $$LC_code{$sec} = $lc_sec;
9503: }
9504: }
9505: }
9506: }
9507: return;
9508: }
9509:
1.971 raeburn 9510: sub get_standard_codeitems {
9511: return ('Year','Semester','Department','Number','Section');
9512: }
9513:
1.112 bowersj2 9514: =pod
9515:
1.780 raeburn 9516: =head1 Slot Helpers
9517:
9518: =over 4
9519:
9520: =item * sorted_slots()
9521:
1.1040 raeburn 9522: Sorts an array of slot names in order of an optional sort key,
9523: default sort is by slot start time (earliest first).
1.780 raeburn 9524:
9525: Inputs:
9526:
9527: =over 4
9528:
9529: slotsarr - Reference to array of unsorted slot names.
9530:
9531: slots - Reference to hash of hash, where outer hash keys are slot names.
9532:
1.1040 raeburn 9533: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
9534:
1.549 albertel 9535: =back
9536:
1.780 raeburn 9537: Returns:
9538:
9539: =over 4
9540:
1.1040 raeburn 9541: sorted - An array of slot names sorted by a specified sort key
9542: (default sort key is start time of the slot).
1.780 raeburn 9543:
9544: =back
9545:
9546: =cut
9547:
9548:
9549: sub sorted_slots {
1.1040 raeburn 9550: my ($slotsarr,$slots,$sortkey) = @_;
9551: if ($sortkey eq '') {
9552: $sortkey = 'starttime';
9553: }
1.780 raeburn 9554: my @sorted;
9555: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
9556: @sorted =
9557: sort {
9558: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 9559: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 9560: }
9561: if (ref($slots->{$a})) { return -1;}
9562: if (ref($slots->{$b})) { return 1;}
9563: return 0;
9564: } @{$slotsarr};
9565: }
9566: return @sorted;
9567: }
9568:
1.1040 raeburn 9569: =pod
9570:
9571: =item * get_future_slots()
9572:
9573: Inputs:
9574:
9575: =over 4
9576:
9577: cnum - course number
9578:
9579: cdom - course domain
9580:
9581: now - current UNIX time
9582:
9583: symb - optional symb
9584:
9585: =back
9586:
9587: Returns:
9588:
9589: =over 4
9590:
9591: sorted_reservable - ref to array of student_schedulable slots currently
9592: reservable, ordered by end date of reservation period.
9593:
9594: reservable_now - ref to hash of student_schedulable slots currently
9595: reservable.
9596:
9597: Keys in inner hash are:
9598: (a) symb: either blank or symb to which slot use is restricted.
9599: (b) endreserve: end date of reservation period.
9600:
9601: sorted_future - ref to array of student_schedulable slots reservable in
9602: the future, ordered by start date of reservation period.
9603:
9604: future_reservable - ref to hash of student_schedulable slots reservable
9605: in the future.
9606:
9607: Keys in inner hash are:
9608: (a) symb: either blank or symb to which slot use is restricted.
9609: (b) startreserve: start date of reservation period.
9610:
9611: =back
9612:
9613: =cut
9614:
9615: sub get_future_slots {
9616: my ($cnum,$cdom,$now,$symb) = @_;
9617: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
9618: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
9619: foreach my $slot (keys(%slots)) {
9620: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
9621: if ($symb) {
9622: next if (($slots{$slot}->{'symb'} ne '') &&
9623: ($slots{$slot}->{'symb'} ne $symb));
9624: }
9625: if (($slots{$slot}->{'starttime'} > $now) &&
9626: ($slots{$slot}->{'endtime'} > $now)) {
9627: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
9628: my $userallowed = 0;
9629: if ($slots{$slot}->{'allowedsections'}) {
9630: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
9631: if (!defined($env{'request.role.sec'})
9632: && grep(/^No section assigned$/,@allowed_sec)) {
9633: $userallowed=1;
9634: } else {
9635: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
9636: $userallowed=1;
9637: }
9638: }
9639: unless ($userallowed) {
9640: if (defined($env{'request.course.groups'})) {
9641: my @groups = split(/:/,$env{'request.course.groups'});
9642: foreach my $group (@groups) {
9643: if (grep(/^\Q$group\E$/,@allowed_sec)) {
9644: $userallowed=1;
9645: last;
9646: }
9647: }
9648: }
9649: }
9650: }
9651: if ($slots{$slot}->{'allowedusers'}) {
9652: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
9653: my $user = $env{'user.name'}.':'.$env{'user.domain'};
9654: if (grep(/^\Q$user\E$/,@allowed_users)) {
9655: $userallowed = 1;
9656: }
9657: }
9658: next unless($userallowed);
9659: }
9660: my $startreserve = $slots{$slot}->{'startreserve'};
9661: my $endreserve = $slots{$slot}->{'endreserve'};
9662: my $symb = $slots{$slot}->{'symb'};
9663: if (($startreserve < $now) &&
9664: (!$endreserve || $endreserve > $now)) {
9665: my $lastres = $endreserve;
9666: if (!$lastres) {
9667: $lastres = $slots{$slot}->{'starttime'};
9668: }
9669: $reservable_now{$slot} = {
9670: symb => $symb,
9671: endreserve => $lastres
9672: };
9673: } elsif (($startreserve > $now) &&
9674: (!$endreserve || $endreserve > $startreserve)) {
9675: $future_reservable{$slot} = {
9676: symb => $symb,
9677: startreserve => $startreserve
9678: };
9679: }
9680: }
9681: }
9682: my @unsorted_reservable = keys(%reservable_now);
9683: if (@unsorted_reservable > 0) {
9684: @sorted_reservable =
9685: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
9686: }
9687: my @unsorted_future = keys(%future_reservable);
9688: if (@unsorted_future > 0) {
9689: @sorted_future =
9690: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
9691: }
9692: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
9693: }
1.780 raeburn 9694:
9695: =pod
9696:
1.1057 foxr 9697: =back
9698:
1.549 albertel 9699: =head1 HTTP Helpers
9700:
9701: =over 4
9702:
1.648 raeburn 9703: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 9704:
1.258 albertel 9705: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 9706: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 9707: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 9708:
9709: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
9710: $possible_names is an ref to an array of form element names. As an example:
9711: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 9712: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 9713:
9714: =cut
1.1 albertel 9715:
1.6 albertel 9716: sub get_unprocessed_cgi {
1.25 albertel 9717: my ($query,$possible_names)= @_;
1.26 matthew 9718: # $Apache::lonxml::debug=1;
1.356 albertel 9719: foreach my $pair (split(/&/,$query)) {
9720: my ($name, $value) = split(/=/,$pair);
1.369 www 9721: $name = &unescape($name);
1.25 albertel 9722: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
9723: $value =~ tr/+/ /;
9724: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 9725: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 9726: }
1.16 harris41 9727: }
1.6 albertel 9728: }
9729:
1.112 bowersj2 9730: =pod
9731:
1.648 raeburn 9732: =item * &cacheheader()
1.112 bowersj2 9733:
9734: returns cache-controlling header code
9735:
9736: =cut
9737:
1.7 albertel 9738: sub cacheheader {
1.258 albertel 9739: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 9740: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
9741: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 9742: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
9743: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 9744: return $output;
1.7 albertel 9745: }
9746:
1.112 bowersj2 9747: =pod
9748:
1.648 raeburn 9749: =item * &no_cache($r)
1.112 bowersj2 9750:
9751: specifies header code to not have cache
9752:
9753: =cut
9754:
1.9 albertel 9755: sub no_cache {
1.216 albertel 9756: my ($r) = @_;
9757: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 9758: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 9759: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
9760: $r->no_cache(1);
9761: $r->header_out("Expires" => $date);
9762: $r->header_out("Pragma" => "no-cache");
1.123 www 9763: }
9764:
9765: sub content_type {
1.181 albertel 9766: my ($r,$type,$charset) = @_;
1.299 foxr 9767: if ($r) {
9768: # Note that printout.pl calls this with undef for $r.
9769: &no_cache($r);
9770: }
1.258 albertel 9771: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 9772: unless ($charset) {
9773: $charset=&Apache::lonlocal::current_encoding;
9774: }
9775: if ($charset) { $type.='; charset='.$charset; }
9776: if ($r) {
9777: $r->content_type($type);
9778: } else {
9779: print("Content-type: $type\n\n");
9780: }
1.9 albertel 9781: }
1.25 albertel 9782:
1.112 bowersj2 9783: =pod
9784:
1.648 raeburn 9785: =item * &add_to_env($name,$value)
1.112 bowersj2 9786:
1.258 albertel 9787: adds $name to the %env hash with value
1.112 bowersj2 9788: $value, if $name already exists, the entry is converted to an array
9789: reference and $value is added to the array.
9790:
9791: =cut
9792:
1.25 albertel 9793: sub add_to_env {
9794: my ($name,$value)=@_;
1.258 albertel 9795: if (defined($env{$name})) {
9796: if (ref($env{$name})) {
1.25 albertel 9797: #already have multiple values
1.258 albertel 9798: push(@{ $env{$name} },$value);
1.25 albertel 9799: } else {
9800: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 9801: my $first=$env{$name};
9802: undef($env{$name});
9803: push(@{ $env{$name} },$first,$value);
1.25 albertel 9804: }
9805: } else {
1.258 albertel 9806: $env{$name}=$value;
1.25 albertel 9807: }
1.31 albertel 9808: }
1.149 albertel 9809:
9810: =pod
9811:
1.648 raeburn 9812: =item * &get_env_multiple($name)
1.149 albertel 9813:
1.258 albertel 9814: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 9815: values may be defined and end up as an array ref.
9816:
9817: returns an array of values
9818:
9819: =cut
9820:
9821: sub get_env_multiple {
9822: my ($name) = @_;
9823: my @values;
1.258 albertel 9824: if (defined($env{$name})) {
1.149 albertel 9825: # exists is it an array
1.258 albertel 9826: if (ref($env{$name})) {
9827: @values=@{ $env{$name} };
1.149 albertel 9828: } else {
1.258 albertel 9829: $values[0]=$env{$name};
1.149 albertel 9830: }
9831: }
9832: return(@values);
9833: }
9834:
1.660 raeburn 9835: sub ask_for_embedded_content {
9836: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 9837: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 9838: %currsubfile,%unused,$rem);
1.1071 raeburn 9839: my $counter = 0;
9840: my $numnew = 0;
1.987 raeburn 9841: my $numremref = 0;
9842: my $numinvalid = 0;
9843: my $numpathchg = 0;
9844: my $numexisting = 0;
1.1071 raeburn 9845: my $numunused = 0;
9846: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 9847: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 9848: my $heading = &mt('Upload embedded files');
9849: my $buttontext = &mt('Upload');
9850:
1.1085 raeburn 9851: if ($env{'request.course.id'}) {
1.1123 raeburn 9852: if ($actionurl eq '/adm/dependencies') {
9853: $navmap = Apache::lonnavmaps::navmap->new();
9854: }
9855: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
9856: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 9857: }
1.1123 raeburn 9858: if (($actionurl eq '/adm/portfolio') ||
9859: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 9860: my $current_path='/';
9861: if ($env{'form.currentpath'}) {
9862: $current_path = $env{'form.currentpath'};
9863: }
9864: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 9865: $udom = $cdom;
9866: $uname = $cnum;
1.984 raeburn 9867: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
9868: } else {
9869: $udom = $env{'user.domain'};
9870: $uname = $env{'user.name'};
9871: $url = '/userfiles/portfolio';
9872: }
1.987 raeburn 9873: $toplevel = $url.'/';
1.984 raeburn 9874: $url .= $current_path;
9875: $getpropath = 1;
1.987 raeburn 9876: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
9877: ($actionurl eq '/adm/imsimport')) {
1.1022 www 9878: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 9879: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 9880: $toplevel = $url;
1.984 raeburn 9881: if ($rest ne '') {
1.987 raeburn 9882: $url .= $rest;
9883: }
9884: } elsif ($actionurl eq '/adm/coursedocs') {
9885: if (ref($args) eq 'HASH') {
1.1071 raeburn 9886: $url = $args->{'docs_url'};
9887: $toplevel = $url;
1.1084 raeburn 9888: if ($args->{'context'} eq 'paste') {
9889: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
9890: ($path) =
9891: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9892: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9893: $fileloc =~ s{^/}{};
9894: }
1.1071 raeburn 9895: }
1.1084 raeburn 9896: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 9897: if ($env{'request.course.id'} ne '') {
9898: if (ref($args) eq 'HASH') {
9899: $url = $args->{'docs_url'};
9900: $title = $args->{'docs_title'};
1.1126 raeburn 9901: $toplevel = $url;
9902: unless ($toplevel =~ m{^/}) {
9903: $toplevel = "/$url";
9904: }
1.1085 raeburn 9905: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 9906: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
9907: $path = $1;
9908: } else {
9909: ($path) =
9910: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
9911: }
1.1195 raeburn 9912: if ($toplevel=~/^\/*(uploaded|editupload)/) {
9913: $fileloc = $toplevel;
9914: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
9915: my ($udom,$uname,$fname) =
9916: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
9917: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
9918: } else {
9919: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
9920: }
1.1071 raeburn 9921: $fileloc =~ s{^/}{};
9922: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
9923: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
9924: }
1.987 raeburn 9925: }
1.1123 raeburn 9926: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
9927: $udom = $cdom;
9928: $uname = $cnum;
9929: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
9930: $toplevel = $url;
9931: $path = $url;
9932: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
9933: $fileloc =~ s{^/}{};
1.987 raeburn 9934: }
1.1126 raeburn 9935: foreach my $file (keys(%{$allfiles})) {
9936: my $embed_file;
9937: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
9938: $embed_file = $1;
9939: } else {
9940: $embed_file = $file;
9941: }
1.1158 raeburn 9942: my ($absolutepath,$cleaned_file);
9943: if ($embed_file =~ m{^\w+://}) {
9944: $cleaned_file = $embed_file;
1.1147 raeburn 9945: $newfiles{$cleaned_file} = 1;
9946: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9947: } else {
1.1158 raeburn 9948: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 9949: if ($embed_file =~ m{^/}) {
9950: $absolutepath = $embed_file;
9951: }
1.1147 raeburn 9952: if ($cleaned_file =~ m{/}) {
9953: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 9954: $path = &check_for_traversal($path,$url,$toplevel);
9955: my $item = $fname;
9956: if ($path ne '') {
9957: $item = $path.'/'.$fname;
9958: $subdependencies{$path}{$fname} = 1;
9959: } else {
9960: $dependencies{$item} = 1;
9961: }
9962: if ($absolutepath) {
9963: $mapping{$item} = $absolutepath;
9964: } else {
9965: $mapping{$item} = $embed_file;
9966: }
9967: } else {
9968: $dependencies{$embed_file} = 1;
9969: if ($absolutepath) {
1.1147 raeburn 9970: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 9971: } else {
1.1147 raeburn 9972: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 9973: }
9974: }
1.984 raeburn 9975: }
9976: }
1.1071 raeburn 9977: my $dirptr = 16384;
1.984 raeburn 9978: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 9979: $currsubfile{$path} = {};
1.1123 raeburn 9980: if (($actionurl eq '/adm/portfolio') ||
9981: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 9982: my ($sublistref,$listerror) =
9983: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
9984: if (ref($sublistref) eq 'ARRAY') {
9985: foreach my $line (@{$sublistref}) {
9986: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 9987: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 9988: }
1.984 raeburn 9989: }
1.987 raeburn 9990: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 9991: if (opendir(my $dir,$url.'/'.$path)) {
9992: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 9993: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
9994: }
1.1084 raeburn 9995: } elsif (($actionurl eq '/adm/dependencies') ||
9996: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 9997: ($args->{'context'} eq 'paste')) ||
9998: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 9999: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 10000: my $dir;
10001: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10002: $dir = $fileloc;
10003: } else {
10004: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10005: }
1.1071 raeburn 10006: if ($dir ne '') {
10007: my ($sublistref,$listerror) =
10008: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10009: if (ref($sublistref) eq 'ARRAY') {
10010: foreach my $line (@{$sublistref}) {
10011: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10012: undef,$mtime)=split(/\&/,$line,12);
10013: unless (($testdir&$dirptr) ||
10014: ($file_name =~ /^\.\.?$/)) {
10015: $currsubfile{$path}{$file_name} = [$size,$mtime];
10016: }
10017: }
10018: }
10019: }
1.984 raeburn 10020: }
10021: }
10022: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10023: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10024: my $item = $path.'/'.$file;
10025: unless ($mapping{$item} eq $item) {
10026: $pathchanges{$item} = 1;
10027: }
10028: $existing{$item} = 1;
10029: $numexisting ++;
10030: } else {
10031: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10032: }
10033: }
1.1071 raeburn 10034: if ($actionurl eq '/adm/dependencies') {
10035: foreach my $path (keys(%currsubfile)) {
10036: if (ref($currsubfile{$path}) eq 'HASH') {
10037: foreach my $file (keys(%{$currsubfile{$path}})) {
10038: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 10039: next if (($rem ne '') &&
10040: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10041: (ref($navmap) &&
10042: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10043: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10044: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10045: $unused{$path.'/'.$file} = 1;
10046: }
10047: }
10048: }
10049: }
10050: }
1.984 raeburn 10051: }
1.987 raeburn 10052: my %currfile;
1.1123 raeburn 10053: if (($actionurl eq '/adm/portfolio') ||
10054: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10055: my ($dirlistref,$listerror) =
10056: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10057: if (ref($dirlistref) eq 'ARRAY') {
10058: foreach my $line (@{$dirlistref}) {
10059: my ($file_name,$rest) = split(/\&/,$line,2);
10060: $currfile{$file_name} = 1;
10061: }
1.984 raeburn 10062: }
1.987 raeburn 10063: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10064: if (opendir(my $dir,$url)) {
1.987 raeburn 10065: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10066: map {$currfile{$_} = 1;} @dir_list;
10067: }
1.1084 raeburn 10068: } elsif (($actionurl eq '/adm/dependencies') ||
10069: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 10070: ($args->{'context'} eq 'paste')) ||
10071: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10072: if ($env{'request.course.id'} ne '') {
10073: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10074: if ($dir ne '') {
10075: my ($dirlistref,$listerror) =
10076: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10077: if (ref($dirlistref) eq 'ARRAY') {
10078: foreach my $line (@{$dirlistref}) {
10079: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10080: $size,undef,$mtime)=split(/\&/,$line,12);
10081: unless (($testdir&$dirptr) ||
10082: ($file_name =~ /^\.\.?$/)) {
10083: $currfile{$file_name} = [$size,$mtime];
10084: }
10085: }
10086: }
10087: }
10088: }
1.984 raeburn 10089: }
10090: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10091: if (exists($currfile{$file})) {
1.987 raeburn 10092: unless ($mapping{$file} eq $file) {
10093: $pathchanges{$file} = 1;
10094: }
10095: $existing{$file} = 1;
10096: $numexisting ++;
10097: } else {
1.984 raeburn 10098: $newfiles{$file} = 1;
10099: }
10100: }
1.1071 raeburn 10101: foreach my $file (keys(%currfile)) {
10102: unless (($file eq $filename) ||
10103: ($file eq $filename.'.bak') ||
10104: ($dependencies{$file})) {
1.1085 raeburn 10105: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 10106: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10107: next if (($rem ne '') &&
10108: (($env{"httpref.$rem".$file} ne '') ||
10109: (ref($navmap) &&
10110: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10111: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10112: ($navmap->getResourceByUrl($rem.$1)))))));
10113: }
1.1085 raeburn 10114: }
1.1071 raeburn 10115: $unused{$file} = 1;
10116: }
10117: }
1.1084 raeburn 10118: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10119: ($args->{'context'} eq 'paste')) {
10120: $counter = scalar(keys(%existing));
10121: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 10122: return ($output,$counter,$numpathchg,\%existing);
10123: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10124: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10125: $counter = scalar(keys(%existing));
10126: $numpathchg = scalar(keys(%pathchanges));
10127: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 10128: }
1.984 raeburn 10129: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10130: if ($actionurl eq '/adm/dependencies') {
10131: next if ($embed_file =~ m{^\w+://});
10132: }
1.660 raeburn 10133: $upload_output .= &start_data_table_row().
1.1123 raeburn 10134: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10135: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10136: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 10137: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10138: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10139: }
1.1123 raeburn 10140: $upload_output .= '</td>';
1.1071 raeburn 10141: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 10142: $upload_output.='<td align="right">'.
10143: '<span class="LC_info LC_fontsize_medium">'.
10144: &mt("URL points to web address").'</span>';
1.987 raeburn 10145: $numremref++;
1.660 raeburn 10146: } elsif ($args->{'error_on_invalid_names'}
10147: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 10148: $upload_output.='<td align="right"><span class="LC_warning">'.
10149: &mt('Invalid characters').'</span>';
1.987 raeburn 10150: $numinvalid++;
1.660 raeburn 10151: } else {
1.1123 raeburn 10152: $upload_output .= '<td>'.
10153: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10154: $embed_file,\%mapping,
1.1071 raeburn 10155: $allfiles,$codebase,'upload');
10156: $counter ++;
10157: $numnew ++;
1.987 raeburn 10158: }
10159: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10160: }
10161: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10162: if ($actionurl eq '/adm/dependencies') {
10163: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10164: $modify_output .= &start_data_table_row().
10165: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10166: '<img src="'.&icon($embed_file).'" border="0" />'.
10167: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10168: '<td>'.$size.'</td>'.
10169: '<td>'.$mtime.'</td>'.
10170: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10171: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10172: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10173: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10174: &embedded_file_element('upload_embedded',$counter,
10175: $embed_file,\%mapping,
10176: $allfiles,$codebase,'modify').
10177: '</div></td>'.
10178: &end_data_table_row()."\n";
10179: $counter ++;
10180: } else {
10181: $upload_output .= &start_data_table_row().
1.1123 raeburn 10182: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10183: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10184: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10185: &Apache::loncommon::end_data_table_row()."\n";
10186: }
10187: }
10188: my $delidx = $counter;
10189: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10190: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10191: $delete_output .= &start_data_table_row().
10192: '<td><img src="'.&icon($oldfile).'" />'.
10193: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10194: '<td>'.$size.'</td>'.
10195: '<td>'.$mtime.'</td>'.
10196: '<td><label><input type="checkbox" name="del_upload_dep" '.
10197: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10198: &embedded_file_element('upload_embedded',$delidx,
10199: $oldfile,\%mapping,$allfiles,
10200: $codebase,'delete').'</td>'.
10201: &end_data_table_row()."\n";
10202: $numunused ++;
10203: $delidx ++;
1.987 raeburn 10204: }
10205: if ($upload_output) {
10206: $upload_output = &start_data_table().
10207: $upload_output.
10208: &end_data_table()."\n";
10209: }
1.1071 raeburn 10210: if ($modify_output) {
10211: $modify_output = &start_data_table().
10212: &start_data_table_header_row().
10213: '<th>'.&mt('File').'</th>'.
10214: '<th>'.&mt('Size (KB)').'</th>'.
10215: '<th>'.&mt('Modified').'</th>'.
10216: '<th>'.&mt('Upload replacement?').'</th>'.
10217: &end_data_table_header_row().
10218: $modify_output.
10219: &end_data_table()."\n";
10220: }
10221: if ($delete_output) {
10222: $delete_output = &start_data_table().
10223: &start_data_table_header_row().
10224: '<th>'.&mt('File').'</th>'.
10225: '<th>'.&mt('Size (KB)').'</th>'.
10226: '<th>'.&mt('Modified').'</th>'.
10227: '<th>'.&mt('Delete?').'</th>'.
10228: &end_data_table_header_row().
10229: $delete_output.
10230: &end_data_table()."\n";
10231: }
1.987 raeburn 10232: my $applies = 0;
10233: if ($numremref) {
10234: $applies ++;
10235: }
10236: if ($numinvalid) {
10237: $applies ++;
10238: }
10239: if ($numexisting) {
10240: $applies ++;
10241: }
1.1071 raeburn 10242: if ($counter || $numunused) {
1.987 raeburn 10243: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10244: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10245: $state.'<h3>'.$heading.'</h3>';
10246: if ($actionurl eq '/adm/dependencies') {
10247: if ($numnew) {
10248: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10249: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10250: $upload_output.'<br />'."\n";
10251: }
10252: if ($numexisting) {
10253: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10254: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10255: $modify_output.'<br />'."\n";
10256: $buttontext = &mt('Save changes');
10257: }
10258: if ($numunused) {
10259: $output .= '<h4>'.&mt('Unused files').'</h4>'.
10260: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
10261: $delete_output.'<br />'."\n";
10262: $buttontext = &mt('Save changes');
10263: }
10264: } else {
10265: $output .= $upload_output.'<br />'."\n";
10266: }
10267: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
10268: $counter.'" />'."\n";
10269: if ($actionurl eq '/adm/dependencies') {
10270: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
10271: $numnew.'" />'."\n";
10272: } elsif ($actionurl eq '') {
1.987 raeburn 10273: $output .= '<input type="hidden" name="phase" value="three" />';
10274: }
10275: } elsif ($applies) {
10276: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
10277: if ($applies > 1) {
10278: $output .=
1.1123 raeburn 10279: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 10280: if ($numremref) {
10281: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
10282: }
10283: if ($numinvalid) {
10284: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
10285: }
10286: if ($numexisting) {
10287: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
10288: }
10289: $output .= '</ul><br />';
10290: } elsif ($numremref) {
10291: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
10292: } elsif ($numinvalid) {
10293: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
10294: } elsif ($numexisting) {
10295: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
10296: }
10297: $output .= $upload_output.'<br />';
10298: }
10299: my ($pathchange_output,$chgcount);
1.1071 raeburn 10300: $chgcount = $counter;
1.987 raeburn 10301: if (keys(%pathchanges) > 0) {
10302: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 10303: if ($counter) {
1.987 raeburn 10304: $output .= &embedded_file_element('pathchange',$chgcount,
10305: $embed_file,\%mapping,
1.1071 raeburn 10306: $allfiles,$codebase,'change');
1.987 raeburn 10307: } else {
10308: $pathchange_output .=
10309: &start_data_table_row().
10310: '<td><input type ="checkbox" name="namechange" value="'.
10311: $chgcount.'" checked="checked" /></td>'.
10312: '<td>'.$mapping{$embed_file}.'</td>'.
10313: '<td>'.$embed_file.
10314: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 10315: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 10316: '</td>'.&end_data_table_row();
1.660 raeburn 10317: }
1.987 raeburn 10318: $numpathchg ++;
10319: $chgcount ++;
1.660 raeburn 10320: }
10321: }
1.1127 raeburn 10322: if (($counter) || ($numunused)) {
1.987 raeburn 10323: if ($numpathchg) {
10324: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
10325: $numpathchg.'" />'."\n";
10326: }
10327: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10328: ($actionurl eq '/adm/imsimport')) {
10329: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
10330: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
10331: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 10332: } elsif ($actionurl eq '/adm/dependencies') {
10333: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 10334: }
1.1123 raeburn 10335: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 10336: } elsif ($numpathchg) {
10337: my %pathchange = ();
10338: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
10339: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10340: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 10341: }
1.987 raeburn 10342: }
1.1071 raeburn 10343: return ($output,$counter,$numpathchg);
1.987 raeburn 10344: }
10345:
1.1147 raeburn 10346: =pod
10347:
10348: =item * clean_path($name)
10349:
10350: Performs clean-up of directories, subdirectories and filename in an
10351: embedded object, referenced in an HTML file which is being uploaded
10352: to a course or portfolio, where
10353: "Upload embedded images/multimedia files if HTML file" checkbox was
10354: checked.
10355:
10356: Clean-up is similar to replacements in lonnet::clean_filename()
10357: except each / between sub-directory and next level is preserved.
10358:
10359: =cut
10360:
10361: sub clean_path {
10362: my ($embed_file) = @_;
10363: $embed_file =~s{^/+}{};
10364: my @contents;
10365: if ($embed_file =~ m{/}) {
10366: @contents = split(/\//,$embed_file);
10367: } else {
10368: @contents = ($embed_file);
10369: }
10370: my $lastidx = scalar(@contents)-1;
10371: for (my $i=0; $i<=$lastidx; $i++) {
10372: $contents[$i]=~s{\\}{/}g;
10373: $contents[$i]=~s/\s+/\_/g;
10374: $contents[$i]=~s{[^/\w\.\-]}{}g;
10375: if ($i == $lastidx) {
10376: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
10377: }
10378: }
10379: if ($lastidx > 0) {
10380: return join('/',@contents);
10381: } else {
10382: return $contents[0];
10383: }
10384: }
10385:
1.987 raeburn 10386: sub embedded_file_element {
1.1071 raeburn 10387: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 10388: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
10389: (ref($codebase) eq 'HASH'));
10390: my $output;
1.1071 raeburn 10391: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 10392: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
10393: }
10394: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
10395: &escape($embed_file).'" />';
10396: unless (($context eq 'upload_embedded') &&
10397: ($mapping->{$embed_file} eq $embed_file)) {
10398: $output .='
10399: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
10400: }
10401: my $attrib;
10402: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
10403: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
10404: }
10405: $output .=
10406: "\n\t\t".
10407: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
10408: $attrib.'" />';
10409: if (exists($codebase->{$mapping->{$embed_file}})) {
10410: $output .=
10411: "\n\t\t".
10412: '<input name="codebase_'.$num.'" type="hidden" value="'.
10413: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 10414: }
1.987 raeburn 10415: return $output;
1.660 raeburn 10416: }
10417:
1.1071 raeburn 10418: sub get_dependency_details {
10419: my ($currfile,$currsubfile,$embed_file) = @_;
10420: my ($size,$mtime,$showsize,$showmtime);
10421: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
10422: if ($embed_file =~ m{/}) {
10423: my ($path,$fname) = split(/\//,$embed_file);
10424: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
10425: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
10426: }
10427: } else {
10428: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
10429: ($size,$mtime) = @{$currfile->{$embed_file}};
10430: }
10431: }
10432: $showsize = $size/1024.0;
10433: $showsize = sprintf("%.1f",$showsize);
10434: if ($mtime > 0) {
10435: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
10436: }
10437: }
10438: return ($showsize,$showmtime);
10439: }
10440:
10441: sub ask_embedded_js {
10442: return <<"END";
10443: <script type="text/javascript"">
10444: // <![CDATA[
10445: function toggleBrowse(counter) {
10446: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
10447: var fileid = document.getElementById('embedded_item_'+counter);
10448: var uploaddivid = document.getElementById('moduploaddep_'+counter);
10449: if (chkboxid.checked == true) {
10450: uploaddivid.style.display='block';
10451: } else {
10452: uploaddivid.style.display='none';
10453: fileid.value = '';
10454: }
10455: }
10456: // ]]>
10457: </script>
10458:
10459: END
10460: }
10461:
1.661 raeburn 10462: sub upload_embedded {
10463: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 10464: $current_disk_usage,$hiddenstate,$actionurl) = @_;
10465: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 10466: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
10467: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
10468: my $orig_uploaded_filename =
10469: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 10470: foreach my $type ('orig','ref','attrib','codebase') {
10471: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
10472: $env{'form.embedded_'.$type.'_'.$i} =
10473: &unescape($env{'form.embedded_'.$type.'_'.$i});
10474: }
10475: }
1.661 raeburn 10476: my ($path,$fname) =
10477: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
10478: # no path, whole string is fname
10479: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
10480: $fname = &Apache::lonnet::clean_filename($fname);
10481: # See if there is anything left
10482: next if ($fname eq '');
10483:
10484: # Check if file already exists as a file or directory.
10485: my ($state,$msg);
10486: if ($context eq 'portfolio') {
10487: my $port_path = $dirpath;
10488: if ($group ne '') {
10489: $port_path = "groups/$group/$port_path";
10490: }
1.987 raeburn 10491: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
10492: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 10493: $dir_root,$port_path,$disk_quota,
10494: $current_disk_usage,$uname,$udom);
10495: if ($state eq 'will_exceed_quota'
1.984 raeburn 10496: || $state eq 'file_locked') {
1.661 raeburn 10497: $output .= $msg;
10498: next;
10499: }
10500: } elsif (($context eq 'author') || ($context eq 'testbank')) {
10501: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
10502: if ($state eq 'exists') {
10503: $output .= $msg;
10504: next;
10505: }
10506: }
10507: # Check if extension is valid
10508: if (($fname =~ /\.(\w+)$/) &&
10509: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 10510: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
10511: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 10512: next;
10513: } elsif (($fname =~ /\.(\w+)$/) &&
10514: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 10515: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 10516: next;
10517: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 10518: $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 10519: next;
10520: }
10521: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 10522: my $subdir = $path;
10523: $subdir =~ s{/+$}{};
1.661 raeburn 10524: if ($context eq 'portfolio') {
1.984 raeburn 10525: my $result;
10526: if ($state eq 'existingfile') {
10527: $result=
10528: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 10529: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 10530: } else {
1.984 raeburn 10531: $result=
10532: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 10533: $dirpath.
1.1123 raeburn 10534: $env{'form.currentpath'}.$subdir);
1.984 raeburn 10535: if ($result !~ m|^/uploaded/|) {
10536: $output .= '<span class="LC_error">'
10537: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10538: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10539: .'</span><br />';
10540: next;
10541: } else {
1.987 raeburn 10542: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10543: $path.$fname.'</span>').'<br />';
1.984 raeburn 10544: }
1.661 raeburn 10545: }
1.1123 raeburn 10546: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 10547: my $extendedsubdir = $dirpath.'/'.$subdir;
10548: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 10549: my $result =
1.1126 raeburn 10550: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 10551: if ($result !~ m|^/uploaded/|) {
10552: $output .= '<span class="LC_error">'
10553: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
10554: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
10555: .'</span><br />';
10556: next;
10557: } else {
10558: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10559: $path.$fname.'</span>').'<br />';
1.1125 raeburn 10560: if ($context eq 'syllabus') {
10561: &Apache::lonnet::make_public_indefinitely($result);
10562: }
1.987 raeburn 10563: }
1.661 raeburn 10564: } else {
10565: # Save the file
10566: my $target = $env{'form.embedded_item_'.$i};
10567: my $fullpath = $dir_root.$dirpath.'/'.$path;
10568: my $dest = $fullpath.$fname;
10569: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 10570: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 10571: my $count;
10572: my $filepath = $dir_root;
1.1027 raeburn 10573: foreach my $subdir (@parts) {
10574: $filepath .= "/$subdir";
10575: if (!-e $filepath) {
1.661 raeburn 10576: mkdir($filepath,0770);
10577: }
10578: }
10579: my $fh;
10580: if (!open($fh,'>'.$dest)) {
10581: &Apache::lonnet::logthis('Failed to create '.$dest);
10582: $output .= '<span class="LC_error">'.
1.1071 raeburn 10583: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
10584: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10585: '</span><br />';
10586: } else {
10587: if (!print $fh $env{'form.embedded_item_'.$i}) {
10588: &Apache::lonnet::logthis('Failed to write to '.$dest);
10589: $output .= '<span class="LC_error">'.
1.1071 raeburn 10590: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
10591: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 10592: '</span><br />';
10593: } else {
1.987 raeburn 10594: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
10595: $url.'</span>').'<br />';
10596: unless ($context eq 'testbank') {
10597: $footer .= &mt('View embedded file: [_1]',
10598: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
10599: }
10600: }
10601: close($fh);
10602: }
10603: }
10604: if ($env{'form.embedded_ref_'.$i}) {
10605: $pathchange{$i} = 1;
10606: }
10607: }
10608: if ($output) {
10609: $output = '<p>'.$output.'</p>';
10610: }
10611: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
10612: $returnflag = 'ok';
1.1071 raeburn 10613: my $numpathchgs = scalar(keys(%pathchange));
10614: if ($numpathchgs > 0) {
1.987 raeburn 10615: if ($context eq 'portfolio') {
10616: $output .= '<p>'.&mt('or').'</p>';
10617: } elsif ($context eq 'testbank') {
1.1071 raeburn 10618: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
10619: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 10620: $returnflag = 'modify_orightml';
10621: }
10622: }
1.1071 raeburn 10623: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 10624: }
10625:
10626: sub modify_html_form {
10627: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
10628: my $end = 0;
10629: my $modifyform;
10630: if ($context eq 'upload_embedded') {
10631: return unless (ref($pathchange) eq 'HASH');
10632: if ($env{'form.number_embedded_items'}) {
10633: $end += $env{'form.number_embedded_items'};
10634: }
10635: if ($env{'form.number_pathchange_items'}) {
10636: $end += $env{'form.number_pathchange_items'};
10637: }
10638: if ($end) {
10639: for (my $i=0; $i<$end; $i++) {
10640: if ($i < $env{'form.number_embedded_items'}) {
10641: next unless($pathchange->{$i});
10642: }
10643: $modifyform .=
10644: &start_data_table_row().
10645: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
10646: 'checked="checked" /></td>'.
10647: '<td>'.$env{'form.embedded_ref_'.$i}.
10648: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
10649: &escape($env{'form.embedded_ref_'.$i}).'" />'.
10650: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
10651: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
10652: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
10653: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
10654: '<td>'.$env{'form.embedded_orig_'.$i}.
10655: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
10656: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
10657: &end_data_table_row();
1.1071 raeburn 10658: }
1.987 raeburn 10659: }
10660: } else {
10661: $modifyform = $pathchgtable;
10662: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
10663: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
10664: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
10665: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
10666: }
10667: }
10668: if ($modifyform) {
1.1071 raeburn 10669: if ($actionurl eq '/adm/dependencies') {
10670: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
10671: }
1.987 raeburn 10672: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
10673: '<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".
10674: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
10675: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
10676: '</ol></p>'."\n".'<p>'.
10677: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
10678: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
10679: &start_data_table()."\n".
10680: &start_data_table_header_row().
10681: '<th>'.&mt('Change?').'</th>'.
10682: '<th>'.&mt('Current reference').'</th>'.
10683: '<th>'.&mt('Required reference').'</th>'.
10684: &end_data_table_header_row()."\n".
10685: $modifyform.
10686: &end_data_table().'<br />'."\n".$hiddenstate.
10687: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
10688: '</form>'."\n";
10689: }
10690: return;
10691: }
10692:
10693: sub modify_html_refs {
1.1123 raeburn 10694: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 10695: my $container;
10696: if ($context eq 'portfolio') {
10697: $container = $env{'form.container'};
10698: } elsif ($context eq 'coursedoc') {
10699: $container = $env{'form.primaryurl'};
1.1071 raeburn 10700: } elsif ($context eq 'manage_dependencies') {
10701: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
10702: $container = "/$container";
1.1123 raeburn 10703: } elsif ($context eq 'syllabus') {
10704: $container = $url;
1.987 raeburn 10705: } else {
1.1027 raeburn 10706: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 10707: }
10708: my (%allfiles,%codebase,$output,$content);
10709: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 10710: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 10711: if (wantarray) {
10712: return ('',0,0);
10713: } else {
10714: return;
10715: }
10716: }
10717: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 10718: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 10719: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
10720: if (wantarray) {
10721: return ('',0,0);
10722: } else {
10723: return;
10724: }
10725: }
1.987 raeburn 10726: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 10727: if ($content eq '-1') {
10728: if (wantarray) {
10729: return ('',0,0);
10730: } else {
10731: return;
10732: }
10733: }
1.987 raeburn 10734: } else {
1.1071 raeburn 10735: unless ($container =~ /^\Q$dir_root\E/) {
10736: if (wantarray) {
10737: return ('',0,0);
10738: } else {
10739: return;
10740: }
10741: }
1.987 raeburn 10742: if (open(my $fh,"<$container")) {
10743: $content = join('', <$fh>);
10744: close($fh);
10745: } else {
1.1071 raeburn 10746: if (wantarray) {
10747: return ('',0,0);
10748: } else {
10749: return;
10750: }
1.987 raeburn 10751: }
10752: }
10753: my ($count,$codebasecount) = (0,0);
10754: my $mm = new File::MMagic;
10755: my $mime_type = $mm->checktype_contents($content);
10756: if ($mime_type eq 'text/html') {
10757: my $parse_result =
10758: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
10759: \%codebase,\$content);
10760: if ($parse_result eq 'ok') {
10761: foreach my $i (@changes) {
10762: my $orig = &unescape($env{'form.embedded_orig_'.$i});
10763: my $ref = &unescape($env{'form.embedded_ref_'.$i});
10764: if ($allfiles{$ref}) {
10765: my $newname = $orig;
10766: my ($attrib_regexp,$codebase);
1.1006 raeburn 10767: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 10768: if ($attrib_regexp =~ /:/) {
10769: $attrib_regexp =~ s/\:/|/g;
10770: }
10771: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10772: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10773: $count += $numchg;
1.1123 raeburn 10774: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 10775: delete($allfiles{$ref});
1.987 raeburn 10776: }
10777: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 10778: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 10779: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
10780: $codebasecount ++;
10781: }
10782: }
10783: }
1.1123 raeburn 10784: my $skiprewrites;
1.987 raeburn 10785: if ($count || $codebasecount) {
10786: my $saveresult;
1.1071 raeburn 10787: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 10788: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 10789: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10790: if ($url eq $container) {
10791: my ($fname) = ($container =~ m{/([^/]+)$});
10792: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10793: $count,'<span class="LC_filename">'.
1.1071 raeburn 10794: $fname.'</span>').'</p>';
1.987 raeburn 10795: } else {
10796: $output = '<p class="LC_error">'.
10797: &mt('Error: update failed for: [_1].',
10798: '<span class="LC_filename">'.
10799: $container.'</span>').'</p>';
10800: }
1.1123 raeburn 10801: if ($context eq 'syllabus') {
10802: unless ($saveresult eq 'ok') {
10803: $skiprewrites = 1;
10804: }
10805: }
1.987 raeburn 10806: } else {
10807: if (open(my $fh,">$container")) {
10808: print $fh $content;
10809: close($fh);
10810: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
10811: $count,'<span class="LC_filename">'.
10812: $container.'</span>').'</p>';
1.661 raeburn 10813: } else {
1.987 raeburn 10814: $output = '<p class="LC_error">'.
10815: &mt('Error: could not update [_1].',
10816: '<span class="LC_filename">'.
10817: $container.'</span>').'</p>';
1.661 raeburn 10818: }
10819: }
10820: }
1.1123 raeburn 10821: if (($context eq 'syllabus') && (!$skiprewrites)) {
10822: my ($actionurl,$state);
10823: $actionurl = "/public/$udom/$uname/syllabus";
10824: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
10825: &ask_for_embedded_content($actionurl,$state,\%allfiles,
10826: \%codebase,
10827: {'context' => 'rewrites',
10828: 'ignore_remote_references' => 1,});
10829: if (ref($mapping) eq 'HASH') {
10830: my $rewrites = 0;
10831: foreach my $key (keys(%{$mapping})) {
10832: next if ($key =~ m{^https?://});
10833: my $ref = $mapping->{$key};
10834: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
10835: my $attrib;
10836: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
10837: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
10838: }
10839: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
10840: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
10841: $rewrites += $numchg;
10842: }
10843: }
10844: if ($rewrites) {
10845: my $saveresult;
10846: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
10847: if ($url eq $container) {
10848: my ($fname) = ($container =~ m{/([^/]+)$});
10849: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
10850: $count,'<span class="LC_filename">'.
10851: $fname.'</span>').'</p>';
10852: } else {
10853: $output .= '<p class="LC_error">'.
10854: &mt('Error: could not update links in [_1].',
10855: '<span class="LC_filename">'.
10856: $container.'</span>').'</p>';
10857:
10858: }
10859: }
10860: }
10861: }
1.987 raeburn 10862: } else {
10863: &logthis('Failed to parse '.$container.
10864: ' to modify references: '.$parse_result);
1.661 raeburn 10865: }
10866: }
1.1071 raeburn 10867: if (wantarray) {
10868: return ($output,$count,$codebasecount);
10869: } else {
10870: return $output;
10871: }
1.661 raeburn 10872: }
10873:
10874: sub check_for_existing {
10875: my ($path,$fname,$element) = @_;
10876: my ($state,$msg);
10877: if (-d $path.'/'.$fname) {
10878: $state = 'exists';
10879: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10880: } elsif (-e $path.'/'.$fname) {
10881: $state = 'exists';
10882: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
10883: }
10884: if ($state eq 'exists') {
10885: $msg = '<span class="LC_error">'.$msg.'</span><br />';
10886: }
10887: return ($state,$msg);
10888: }
10889:
10890: sub check_for_upload {
10891: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
10892: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 10893: my $filesize = length($env{'form.'.$element});
10894: if (!$filesize) {
10895: my $msg = '<span class="LC_error">'.
10896: &mt('Unable to upload [_1]. (size = [_2] bytes)',
10897: '<span class="LC_filename">'.$fname.'</span>',
10898: $filesize).'<br />'.
1.1007 raeburn 10899: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 10900: '</span>';
10901: return ('zero_bytes',$msg);
10902: }
10903: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 10904: my $getpropath = 1;
1.1021 raeburn 10905: my ($dirlistref,$listerror) =
10906: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 10907: my $found_file = 0;
10908: my $locked_file = 0;
1.991 raeburn 10909: my @lockers;
10910: my $navmap;
10911: if ($env{'request.course.id'}) {
10912: $navmap = Apache::lonnavmaps::navmap->new();
10913: }
1.1021 raeburn 10914: if (ref($dirlistref) eq 'ARRAY') {
10915: foreach my $line (@{$dirlistref}) {
10916: my ($file_name,$rest)=split(/\&/,$line,2);
10917: if ($file_name eq $fname){
10918: $file_name = $path.$file_name;
10919: if ($group ne '') {
10920: $file_name = $group.$file_name;
10921: }
10922: $found_file = 1;
10923: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
10924: foreach my $lock (@lockers) {
10925: if (ref($lock) eq 'ARRAY') {
10926: my ($symb,$crsid) = @{$lock};
10927: if ($crsid eq $env{'request.course.id'}) {
10928: if (ref($navmap)) {
10929: my $res = $navmap->getBySymb($symb);
10930: foreach my $part (@{$res->parts()}) {
10931: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
10932: unless (($slot_status == $res->RESERVED) ||
10933: ($slot_status == $res->RESERVED_LOCATION)) {
10934: $locked_file = 1;
10935: }
1.991 raeburn 10936: }
1.1021 raeburn 10937: } else {
10938: $locked_file = 1;
1.991 raeburn 10939: }
10940: } else {
10941: $locked_file = 1;
10942: }
10943: }
1.1021 raeburn 10944: }
10945: } else {
10946: my @info = split(/\&/,$rest);
10947: my $currsize = $info[6]/1000;
10948: if ($currsize < $filesize) {
10949: my $extra = $filesize - $currsize;
10950: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 10951: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 10952: &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.1179 bisitz 10953: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
10954: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
10955: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 10956: return ('will_exceed_quota',$msg);
10957: }
1.984 raeburn 10958: }
10959: }
1.661 raeburn 10960: }
10961: }
10962: }
10963: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 10964: my $msg = '<p class="LC_warning">'.
10965: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 10966: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 10967: return ('will_exceed_quota',$msg);
10968: } elsif ($found_file) {
10969: if ($locked_file) {
1.1179 bisitz 10970: my $msg = '<p class="LC_warning">';
1.661 raeburn 10971: $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.1179 bisitz 10972: $msg .= '</p>';
1.661 raeburn 10973: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
10974: return ('file_locked',$msg);
10975: } else {
1.1179 bisitz 10976: my $msg = '<p class="LC_error">';
1.984 raeburn 10977: $msg .= &mt(' A file by that name: [_1] was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$port_path.$env{'form.currentpath'});
1.1179 bisitz 10978: $msg .= '</p>';
1.984 raeburn 10979: return ('existingfile',$msg);
1.661 raeburn 10980: }
10981: }
10982: }
10983:
1.987 raeburn 10984: sub check_for_traversal {
10985: my ($path,$url,$toplevel) = @_;
10986: my @parts=split(/\//,$path);
10987: my $cleanpath;
10988: my $fullpath = $url;
10989: for (my $i=0;$i<@parts;$i++) {
10990: next if ($parts[$i] eq '.');
10991: if ($parts[$i] eq '..') {
10992: $fullpath =~ s{([^/]+/)$}{};
10993: } else {
10994: $fullpath .= $parts[$i].'/';
10995: }
10996: }
10997: if ($fullpath =~ /^\Q$url\E(.*)$/) {
10998: $cleanpath = $1;
10999: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11000: my $curr_toprel = $1;
11001: my @parts = split(/\//,$curr_toprel);
11002: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11003: my @urlparts = split(/\//,$url_toprel);
11004: my $doubledots;
11005: my $startdiff = -1;
11006: for (my $i=0; $i<@urlparts; $i++) {
11007: if ($startdiff == -1) {
11008: unless ($urlparts[$i] eq $parts[$i]) {
11009: $startdiff = $i;
11010: $doubledots .= '../';
11011: }
11012: } else {
11013: $doubledots .= '../';
11014: }
11015: }
11016: if ($startdiff > -1) {
11017: $cleanpath = $doubledots;
11018: for (my $i=$startdiff; $i<@parts; $i++) {
11019: $cleanpath .= $parts[$i].'/';
11020: }
11021: }
11022: }
11023: $cleanpath =~ s{(/)$}{};
11024: return $cleanpath;
11025: }
1.31 albertel 11026:
1.1053 raeburn 11027: sub is_archive_file {
11028: my ($mimetype) = @_;
11029: if (($mimetype eq 'application/octet-stream') ||
11030: ($mimetype eq 'application/x-stuffit') ||
11031: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11032: return 1;
11033: }
11034: return;
11035: }
11036:
11037: sub decompress_form {
1.1065 raeburn 11038: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11039: my %lt = &Apache::lonlocal::texthash (
11040: this => 'This file is an archive file.',
1.1067 raeburn 11041: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11042: itsc => 'Its contents are as follows:',
1.1053 raeburn 11043: youm => 'You may wish to extract its contents.',
11044: extr => 'Extract contents',
1.1067 raeburn 11045: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11046: proa => 'Process automatically?',
1.1053 raeburn 11047: yes => 'Yes',
11048: no => 'No',
1.1067 raeburn 11049: fold => 'Title for folder containing movie',
11050: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11051: );
1.1065 raeburn 11052: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11053: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11054: my $info = &list_archive_contents($fileloc,\@paths);
11055: if (@paths) {
11056: foreach my $path (@paths) {
11057: $path =~ s{^/}{};
1.1067 raeburn 11058: if ($path =~ m{^([^/]+)/$}) {
11059: $topdir = $1;
11060: }
1.1065 raeburn 11061: if ($path =~ m{^([^/]+)/}) {
11062: $toplevel{$1} = $path;
11063: } else {
11064: $toplevel{$path} = $path;
11065: }
11066: }
11067: }
1.1067 raeburn 11068: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 11069: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11070: "$topdir/media/",
11071: "$topdir/media/$topdir.mp4",
11072: "$topdir/media/FirstFrame.png",
11073: "$topdir/media/player.swf",
11074: "$topdir/media/swfobject.js",
11075: "$topdir/media/expressInstall.swf");
1.1164 raeburn 11076: my @camtasia8 = ("$topdir/","$topdir/$topdir.html",
11077: "$topdir/$topdir.mp4",
11078: "$topdir/$topdir\_config.xml",
11079: "$topdir/$topdir\_controller.swf",
11080: "$topdir/$topdir\_embed.css",
11081: "$topdir/$topdir\_First_Frame.png",
11082: "$topdir/$topdir\_player.html",
11083: "$topdir/$topdir\_Thumbnails.png",
11084: "$topdir/playerProductInstall.swf",
11085: "$topdir/scripts/",
11086: "$topdir/scripts/config_xml.js",
11087: "$topdir/scripts/handlebars.js",
11088: "$topdir/scripts/jquery-1.7.1.min.js",
11089: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11090: "$topdir/scripts/modernizr.js",
11091: "$topdir/scripts/player-min.js",
11092: "$topdir/scripts/swfobject.js",
11093: "$topdir/skins/",
11094: "$topdir/skins/configuration_express.xml",
11095: "$topdir/skins/express_show/",
11096: "$topdir/skins/express_show/player-min.css",
11097: "$topdir/skins/express_show/spritesheet.png");
11098: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11099: if (@diffs == 0) {
1.1164 raeburn 11100: $is_camtasia = 6;
11101: } else {
11102: @diffs = &compare_arrays(\@paths,\@camtasia8);
11103: if (@diffs == 0) {
11104: $is_camtasia = 8;
11105: }
1.1067 raeburn 11106: }
11107: }
11108: my $output;
11109: if ($is_camtasia) {
11110: $output = <<"ENDCAM";
11111: <script type="text/javascript" language="Javascript">
11112: // <![CDATA[
11113:
11114: function camtasiaToggle() {
11115: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11116: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 11117: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11118:
11119: document.getElementById('camtasia_titles').style.display='block';
11120: } else {
11121: document.getElementById('camtasia_titles').style.display='none';
11122: }
11123: }
11124: }
11125: return;
11126: }
11127:
11128: // ]]>
11129: </script>
11130: <p>$lt{'camt'}</p>
11131: ENDCAM
1.1065 raeburn 11132: } else {
1.1067 raeburn 11133: $output = '<p>'.$lt{'this'};
11134: if ($info eq '') {
11135: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11136: } else {
11137: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11138: '<div><pre>'.$info.'</pre></div>';
11139: }
1.1065 raeburn 11140: }
1.1067 raeburn 11141: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11142: my $duplicates;
11143: my $num = 0;
11144: if (ref($dirlist) eq 'ARRAY') {
11145: foreach my $item (@{$dirlist}) {
11146: if (ref($item) eq 'ARRAY') {
11147: if (exists($toplevel{$item->[0]})) {
11148: $duplicates .=
11149: &start_data_table_row().
11150: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11151: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11152: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11153: 'value="1" />'.&mt('Yes').'</label>'.
11154: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11155: '<td>'.$item->[0].'</td>';
11156: if ($item->[2]) {
11157: $duplicates .= '<td>'.&mt('Directory').'</td>';
11158: } else {
11159: $duplicates .= '<td>'.&mt('File').'</td>';
11160: }
11161: $duplicates .= '<td>'.$item->[3].'</td>'.
11162: '<td>'.
11163: &Apache::lonlocal::locallocaltime($item->[4]).
11164: '</td>'.
11165: &end_data_table_row();
11166: $num ++;
11167: }
11168: }
11169: }
11170: }
11171: my $itemcount;
11172: if (@paths > 0) {
11173: $itemcount = scalar(@paths);
11174: } else {
11175: $itemcount = 1;
11176: }
1.1067 raeburn 11177: if ($is_camtasia) {
11178: $output .= $lt{'auto'}.'<br />'.
11179: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 11180: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11181: $lt{'yes'}.'</label> <label>'.
11182: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11183: $lt{'no'}.'</label></span><br />'.
11184: '<div id="camtasia_titles" style="display:block">'.
11185: &Apache::lonhtmlcommon::start_pick_box().
11186: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11187: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11188: &Apache::lonhtmlcommon::row_closure().
11189: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11190: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11191: &Apache::lonhtmlcommon::row_closure(1).
11192: &Apache::lonhtmlcommon::end_pick_box().
11193: '</div>';
11194: }
1.1065 raeburn 11195: $output .=
11196: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11197: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11198: "\n";
1.1065 raeburn 11199: if ($duplicates ne '') {
11200: $output .= '<p><span class="LC_warning">'.
11201: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11202: &start_data_table().
11203: &start_data_table_header_row().
11204: '<th>'.&mt('Overwrite?').'</th>'.
11205: '<th>'.&mt('Name').'</th>'.
11206: '<th>'.&mt('Type').'</th>'.
11207: '<th>'.&mt('Size').'</th>'.
11208: '<th>'.&mt('Last modified').'</th>'.
11209: &end_data_table_header_row().
11210: $duplicates.
11211: &end_data_table().
11212: '</p>';
11213: }
1.1067 raeburn 11214: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11215: if (ref($hiddenelements) eq 'HASH') {
11216: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11217: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11218: }
11219: }
11220: $output .= <<"END";
1.1067 raeburn 11221: <br />
1.1053 raeburn 11222: <input type="submit" name="decompress" value="$lt{'extr'}" />
11223: </form>
11224: $noextract
11225: END
11226: return $output;
11227: }
11228:
1.1065 raeburn 11229: sub decompression_utility {
11230: my ($program) = @_;
11231: my @utilities = ('tar','gunzip','bunzip2','unzip');
11232: my $location;
11233: if (grep(/^\Q$program\E$/,@utilities)) {
11234: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11235: '/usr/sbin/') {
11236: if (-x $dir.$program) {
11237: $location = $dir.$program;
11238: last;
11239: }
11240: }
11241: }
11242: return $location;
11243: }
11244:
11245: sub list_archive_contents {
11246: my ($file,$pathsref) = @_;
11247: my (@cmd,$output);
11248: my $needsregexp;
11249: if ($file =~ /\.zip$/) {
11250: @cmd = (&decompression_utility('unzip'),"-l");
11251: $needsregexp = 1;
11252: } elsif (($file =~ m/\.tar\.gz$/) ||
11253: ($file =~ /\.tgz$/)) {
11254: @cmd = (&decompression_utility('tar'),"-ztf");
11255: } elsif ($file =~ /\.tar\.bz2$/) {
11256: @cmd = (&decompression_utility('tar'),"-jtf");
11257: } elsif ($file =~ m|\.tar$|) {
11258: @cmd = (&decompression_utility('tar'),"-tf");
11259: }
11260: if (@cmd) {
11261: undef($!);
11262: undef($@);
11263: if (open(my $fh,"-|", @cmd, $file)) {
11264: while (my $line = <$fh>) {
11265: $output .= $line;
11266: chomp($line);
11267: my $item;
11268: if ($needsregexp) {
11269: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
11270: } else {
11271: $item = $line;
11272: }
11273: if ($item ne '') {
11274: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
11275: push(@{$pathsref},$item);
11276: }
11277: }
11278: }
11279: close($fh);
11280: }
11281: }
11282: return $output;
11283: }
11284:
1.1053 raeburn 11285: sub decompress_uploaded_file {
11286: my ($file,$dir) = @_;
11287: &Apache::lonnet::appenv({'cgi.file' => $file});
11288: &Apache::lonnet::appenv({'cgi.dir' => $dir});
11289: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
11290: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
11291: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
11292: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
11293: my $decompressed = $env{'cgi.decompressed'};
11294: &Apache::lonnet::delenv('cgi.file');
11295: &Apache::lonnet::delenv('cgi.dir');
11296: &Apache::lonnet::delenv('cgi.decompressed');
11297: return ($decompressed,$result);
11298: }
11299:
1.1055 raeburn 11300: sub process_decompression {
11301: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
11302: my ($dir,$error,$warning,$output);
1.1180 raeburn 11303: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 11304: $error = &mt('Filename not a supported archive file type.').
11305: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 11306: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
11307: } else {
11308: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11309: if ($docuhome eq 'no_host') {
11310: $error = &mt('Could not determine home server for course.');
11311: } else {
11312: my @ids=&Apache::lonnet::current_machine_ids();
11313: my $currdir = "$dir_root/$destination";
11314: if (grep(/^\Q$docuhome\E$/,@ids)) {
11315: $dir = &LONCAPA::propath($docudom,$docuname).
11316: "$dir_root/$destination";
11317: } else {
11318: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
11319: "$dir_root/$docudom/$docuname/$destination";
11320: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
11321: $error = &mt('Archive file not found.');
11322: }
11323: }
1.1065 raeburn 11324: my (@to_overwrite,@to_skip);
11325: if ($env{'form.archive_overwrite_total'} > 0) {
11326: my $total = $env{'form.archive_overwrite_total'};
11327: for (my $i=0; $i<$total; $i++) {
11328: if ($env{'form.archive_overwrite_'.$i} == 1) {
11329: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
11330: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
11331: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
11332: }
11333: }
11334: }
11335: my $numskip = scalar(@to_skip);
11336: if (($numskip > 0) &&
11337: ($numskip == $env{'form.archive_itemcount'})) {
11338: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
11339: } elsif ($dir eq '') {
1.1055 raeburn 11340: $error = &mt('Directory containing archive file unavailable.');
11341: } elsif (!$error) {
1.1065 raeburn 11342: my ($decompressed,$display);
11343: if ($numskip > 0) {
11344: my $tempdir = time.'_'.$$.int(rand(10000));
11345: mkdir("$dir/$tempdir",0755);
11346: system("mv $dir/$file $dir/$tempdir/$file");
11347: ($decompressed,$display) =
11348: &decompress_uploaded_file($file,"$dir/$tempdir");
11349: foreach my $item (@to_skip) {
11350: if (($item ne '') && ($item !~ /\.\./)) {
11351: if (-f "$dir/$tempdir/$item") {
11352: unlink("$dir/$tempdir/$item");
11353: } elsif (-d "$dir/$tempdir/$item") {
11354: system("rm -rf $dir/$tempdir/$item");
11355: }
11356: }
11357: }
11358: system("mv $dir/$tempdir/* $dir");
11359: rmdir("$dir/$tempdir");
11360: } else {
11361: ($decompressed,$display) =
11362: &decompress_uploaded_file($file,$dir);
11363: }
1.1055 raeburn 11364: if ($decompressed eq 'ok') {
1.1065 raeburn 11365: $output = '<p class="LC_info">'.
11366: &mt('Files extracted successfully from archive.').
11367: '</p>'."\n";
1.1055 raeburn 11368: my ($warning,$result,@contents);
11369: my ($newdirlistref,$newlisterror) =
11370: &Apache::lonnet::dirlist($currdir,$docudom,
11371: $docuname,1);
11372: my (%is_dir,%changes,@newitems);
11373: my $dirptr = 16384;
1.1065 raeburn 11374: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 11375: foreach my $dir_line (@{$newdirlistref}) {
11376: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 11377: unless (($item =~ /^\.+$/) || ($item eq $file) ||
11378: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 11379: push(@newitems,$item);
11380: if ($dirptr&$testdir) {
11381: $is_dir{$item} = 1;
11382: }
11383: $changes{$item} = 1;
11384: }
11385: }
11386: }
11387: if (keys(%changes) > 0) {
11388: foreach my $item (sort(@newitems)) {
11389: if ($changes{$item}) {
11390: push(@contents,$item);
11391: }
11392: }
11393: }
11394: if (@contents > 0) {
1.1067 raeburn 11395: my $wantform;
11396: unless ($env{'form.autoextract_camtasia'}) {
11397: $wantform = 1;
11398: }
1.1056 raeburn 11399: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 11400: my ($count,$datatable) = &get_extracted($docudom,$docuname,
11401: $currdir,\%is_dir,
11402: \%children,\%parent,
1.1056 raeburn 11403: \@contents,\%dirorder,
11404: \%titles,$wantform);
1.1055 raeburn 11405: if ($datatable ne '') {
11406: $output .= &archive_options_form('decompressed',$datatable,
11407: $count,$hiddenelem);
1.1065 raeburn 11408: my $startcount = 6;
1.1055 raeburn 11409: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 11410: \%titles,\%children);
1.1055 raeburn 11411: }
1.1067 raeburn 11412: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 11413: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 11414: my %displayed;
11415: my $total = 1;
11416: $env{'form.archive_directory'} = [];
11417: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
11418: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
11419: $path =~ s{/$}{};
11420: my $item;
11421: if ($path ne '') {
11422: $item = "$path/$titles{$i}";
11423: } else {
11424: $item = $titles{$i};
11425: }
11426: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
11427: if ($item eq $contents[0]) {
11428: push(@{$env{'form.archive_directory'}},$i);
11429: $env{'form.archive_'.$i} = 'display';
11430: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
11431: $displayed{'folder'} = $i;
1.1164 raeburn 11432: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
11433: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 11434: $env{'form.archive_'.$i} = 'display';
11435: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
11436: $displayed{'web'} = $i;
11437: } else {
1.1164 raeburn 11438: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
11439: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
11440: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 11441: push(@{$env{'form.archive_directory'}},$i);
11442: }
11443: $env{'form.archive_'.$i} = 'dependency';
11444: }
11445: $total ++;
11446: }
11447: for (my $i=1; $i<$total; $i++) {
11448: next if ($i == $displayed{'web'});
11449: next if ($i == $displayed{'folder'});
11450: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
11451: }
11452: $env{'form.phase'} = 'decompress_cleanup';
11453: $env{'form.archivedelete'} = 1;
11454: $env{'form.archive_count'} = $total-1;
11455: $output .=
11456: &process_extracted_files('coursedocs',$docudom,
11457: $docuname,$destination,
11458: $dir_root,$hiddenelem);
11459: }
1.1055 raeburn 11460: } else {
11461: $warning = &mt('No new items extracted from archive file.');
11462: }
11463: } else {
11464: $output = $display;
11465: $error = &mt('An error occurred during extraction from the archive file.');
11466: }
11467: }
11468: }
11469: }
11470: if ($error) {
11471: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
11472: $error.'</p>'."\n";
11473: }
11474: if ($warning) {
11475: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
11476: }
11477: return $output;
11478: }
11479:
11480: sub get_extracted {
1.1056 raeburn 11481: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
11482: $titles,$wantform) = @_;
1.1055 raeburn 11483: my $count = 0;
11484: my $depth = 0;
11485: my $datatable;
1.1056 raeburn 11486: my @hierarchy;
1.1055 raeburn 11487: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 11488: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
11489: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 11490: foreach my $item (@{$contents}) {
11491: $count ++;
1.1056 raeburn 11492: @{$dirorder->{$count}} = @hierarchy;
11493: $titles->{$count} = $item;
1.1055 raeburn 11494: &archive_hierarchy($depth,$count,$parent,$children);
11495: if ($wantform) {
11496: $datatable .= &archive_row($is_dir->{$item},$item,
11497: $currdir,$depth,$count);
11498: }
11499: if ($is_dir->{$item}) {
11500: $depth ++;
1.1056 raeburn 11501: push(@hierarchy,$count);
11502: $parent->{$depth} = $count;
1.1055 raeburn 11503: $datatable .=
11504: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 11505: \$depth,\$count,\@hierarchy,$dirorder,
11506: $children,$parent,$titles,$wantform);
1.1055 raeburn 11507: $depth --;
1.1056 raeburn 11508: pop(@hierarchy);
1.1055 raeburn 11509: }
11510: }
11511: return ($count,$datatable);
11512: }
11513:
11514: sub recurse_extracted_archive {
1.1056 raeburn 11515: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
11516: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 11517: my $result='';
1.1056 raeburn 11518: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
11519: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
11520: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 11521: return $result;
11522: }
11523: my $dirptr = 16384;
11524: my ($newdirlistref,$newlisterror) =
11525: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
11526: if (ref($newdirlistref) eq 'ARRAY') {
11527: foreach my $dir_line (@{$newdirlistref}) {
11528: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
11529: unless ($item =~ /^\.+$/) {
11530: $$count ++;
1.1056 raeburn 11531: @{$dirorder->{$$count}} = @{$hierarchy};
11532: $titles->{$$count} = $item;
1.1055 raeburn 11533: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 11534:
1.1055 raeburn 11535: my $is_dir;
11536: if ($dirptr&$testdir) {
11537: $is_dir = 1;
11538: }
11539: if ($wantform) {
11540: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
11541: }
11542: if ($is_dir) {
11543: $$depth ++;
1.1056 raeburn 11544: push(@{$hierarchy},$$count);
11545: $parent->{$$depth} = $$count;
1.1055 raeburn 11546: $result .=
11547: &recurse_extracted_archive("$currdir/$item",$docudom,
11548: $docuname,$depth,$count,
1.1056 raeburn 11549: $hierarchy,$dirorder,$children,
11550: $parent,$titles,$wantform);
1.1055 raeburn 11551: $$depth --;
1.1056 raeburn 11552: pop(@{$hierarchy});
1.1055 raeburn 11553: }
11554: }
11555: }
11556: }
11557: return $result;
11558: }
11559:
11560: sub archive_hierarchy {
11561: my ($depth,$count,$parent,$children) =@_;
11562: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
11563: if (exists($parent->{$depth})) {
11564: $children->{$parent->{$depth}} .= $count.':';
11565: }
11566: }
11567: return;
11568: }
11569:
11570: sub archive_row {
11571: my ($is_dir,$item,$currdir,$depth,$count) = @_;
11572: my ($name) = ($item =~ m{([^/]+)$});
11573: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 11574: 'display' => 'Add as file',
1.1055 raeburn 11575: 'dependency' => 'Include as dependency',
11576: 'discard' => 'Discard',
11577: );
11578: if ($is_dir) {
1.1059 raeburn 11579: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 11580: }
1.1056 raeburn 11581: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
11582: my $offset = 0;
1.1055 raeburn 11583: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 11584: $offset ++;
1.1065 raeburn 11585: if ($action ne 'display') {
11586: $offset ++;
11587: }
1.1055 raeburn 11588: $output .= '<td><span class="LC_nobreak">'.
11589: '<label><input type="radio" name="archive_'.$count.
11590: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
11591: my $text = $choices{$action};
11592: if ($is_dir) {
11593: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
11594: if ($action eq 'display') {
1.1059 raeburn 11595: $text = &mt('Add as folder');
1.1055 raeburn 11596: }
1.1056 raeburn 11597: } else {
11598: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
11599:
11600: }
11601: $output .= ' /> '.$choices{$action}.'</label></span>';
11602: if ($action eq 'dependency') {
11603: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
11604: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
11605: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
11606: '<option value=""></option>'."\n".
11607: '</select>'."\n".
11608: '</div>';
1.1059 raeburn 11609: } elsif ($action eq 'display') {
11610: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
11611: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
11612: '</div>';
1.1055 raeburn 11613: }
1.1056 raeburn 11614: $output .= '</td>';
1.1055 raeburn 11615: }
11616: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
11617: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
11618: for (my $i=0; $i<$depth; $i++) {
11619: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
11620: }
11621: if ($is_dir) {
11622: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
11623: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
11624: } else {
11625: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
11626: }
11627: $output .= ' '.$name.'</td>'."\n".
11628: &end_data_table_row();
11629: return $output;
11630: }
11631:
11632: sub archive_options_form {
1.1065 raeburn 11633: my ($form,$display,$count,$hiddenelem) = @_;
11634: my %lt = &Apache::lonlocal::texthash(
11635: perm => 'Permanently remove archive file?',
11636: hows => 'How should each extracted item be incorporated in the course?',
11637: cont => 'Content actions for all',
11638: addf => 'Add as folder/file',
11639: incd => 'Include as dependency for a displayed file',
11640: disc => 'Discard',
11641: no => 'No',
11642: yes => 'Yes',
11643: save => 'Save',
11644: );
11645: my $output = <<"END";
11646: <form name="$form" method="post" action="">
11647: <p><span class="LC_nobreak">$lt{'perm'}
11648: <label>
11649: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
11650: </label>
11651:
11652: <label>
11653: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
11654: </span>
11655: </p>
11656: <input type="hidden" name="phase" value="decompress_cleanup" />
11657: <br />$lt{'hows'}
11658: <div class="LC_columnSection">
11659: <fieldset>
11660: <legend>$lt{'cont'}</legend>
11661: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
11662: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
11663: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
11664: </fieldset>
11665: </div>
11666: END
11667: return $output.
1.1055 raeburn 11668: &start_data_table()."\n".
1.1065 raeburn 11669: $display."\n".
1.1055 raeburn 11670: &end_data_table()."\n".
11671: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
11672: $hiddenelem.
1.1065 raeburn 11673: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 11674: '</form>';
11675: }
11676:
11677: sub archive_javascript {
1.1056 raeburn 11678: my ($startcount,$numitems,$titles,$children) = @_;
11679: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 11680: my $maintitle = $env{'form.comment'};
1.1055 raeburn 11681: my $scripttag = <<START;
11682: <script type="text/javascript">
11683: // <![CDATA[
11684:
11685: function checkAll(form,prefix) {
11686: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
11687: for (var i=0; i < form.elements.length; i++) {
11688: var id = form.elements[i].id;
11689: if ((id != '') && (id != undefined)) {
11690: if (idstr.test(id)) {
11691: if (form.elements[i].type == 'radio') {
11692: form.elements[i].checked = true;
1.1056 raeburn 11693: var nostart = i-$startcount;
1.1059 raeburn 11694: var offset = nostart%7;
11695: var count = (nostart-offset)/7;
1.1056 raeburn 11696: dependencyCheck(form,count,offset);
1.1055 raeburn 11697: }
11698: }
11699: }
11700: }
11701: }
11702:
11703: function propagateCheck(form,count) {
11704: if (count > 0) {
1.1059 raeburn 11705: var startelement = $startcount + ((count-1) * 7);
11706: for (var j=1; j<6; j++) {
11707: if ((j != 2) && (j != 4)) {
1.1056 raeburn 11708: var item = startelement + j;
11709: if (form.elements[item].type == 'radio') {
11710: if (form.elements[item].checked) {
11711: containerCheck(form,count,j);
11712: break;
11713: }
1.1055 raeburn 11714: }
11715: }
11716: }
11717: }
11718: }
11719:
11720: numitems = $numitems
1.1056 raeburn 11721: var titles = new Array(numitems);
11722: var parents = new Array(numitems);
1.1055 raeburn 11723: for (var i=0; i<numitems; i++) {
1.1056 raeburn 11724: parents[i] = new Array;
1.1055 raeburn 11725: }
1.1059 raeburn 11726: var maintitle = '$maintitle';
1.1055 raeburn 11727:
11728: START
11729:
1.1056 raeburn 11730: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
11731: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 11732: for (my $i=0; $i<@contents; $i ++) {
11733: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
11734: }
11735: }
11736:
1.1056 raeburn 11737: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
11738: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
11739: }
11740:
1.1055 raeburn 11741: $scripttag .= <<END;
11742:
11743: function containerCheck(form,count,offset) {
11744: if (count > 0) {
1.1056 raeburn 11745: dependencyCheck(form,count,offset);
1.1059 raeburn 11746: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 11747: form.elements[item].checked = true;
11748: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
11749: if (parents[count].length > 0) {
11750: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 11751: containerCheck(form,parents[count][j],offset);
11752: }
11753: }
11754: }
11755: }
11756: }
11757:
11758: function dependencyCheck(form,count,offset) {
11759: if (count > 0) {
1.1059 raeburn 11760: var chosen = (offset+$startcount)+7*(count-1);
11761: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 11762: var currtype = form.elements[depitem].type;
11763: if (form.elements[chosen].value == 'dependency') {
11764: document.getElementById('arc_depon_'+count).style.display='block';
11765: form.elements[depitem].options.length = 0;
11766: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 11767: for (var i=1; i<=numitems; i++) {
11768: if (i == count) {
11769: continue;
11770: }
1.1059 raeburn 11771: var startelement = $startcount + (i-1) * 7;
11772: for (var j=1; j<6; j++) {
11773: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 11774: var item = startelement + j;
11775: if (form.elements[item].type == 'radio') {
11776: if (form.elements[item].checked) {
11777: if (form.elements[item].value == 'display') {
11778: var n = form.elements[depitem].options.length;
11779: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
11780: }
11781: }
11782: }
11783: }
11784: }
11785: }
11786: } else {
11787: document.getElementById('arc_depon_'+count).style.display='none';
11788: form.elements[depitem].options.length = 0;
11789: form.elements[depitem].options[0] = new Option('Select','',true,true);
11790: }
1.1059 raeburn 11791: titleCheck(form,count,offset);
1.1056 raeburn 11792: }
11793: }
11794:
11795: function propagateSelect(form,count,offset) {
11796: if (count > 0) {
1.1065 raeburn 11797: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 11798: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
11799: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11800: if (parents[count].length > 0) {
11801: for (var j=0; j<parents[count].length; j++) {
11802: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 11803: }
11804: }
11805: }
11806: }
11807: }
1.1056 raeburn 11808:
11809: function containerSelect(form,count,offset,picked) {
11810: if (count > 0) {
1.1065 raeburn 11811: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 11812: if (form.elements[item].type == 'radio') {
11813: if (form.elements[item].value == 'dependency') {
11814: if (form.elements[item+1].type == 'select-one') {
11815: for (var i=0; i<form.elements[item+1].options.length; i++) {
11816: if (form.elements[item+1].options[i].value == picked) {
11817: form.elements[item+1].selectedIndex = i;
11818: break;
11819: }
11820: }
11821: }
11822: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
11823: if (parents[count].length > 0) {
11824: for (var j=0; j<parents[count].length; j++) {
11825: containerSelect(form,parents[count][j],offset,picked);
11826: }
11827: }
11828: }
11829: }
11830: }
11831: }
11832: }
11833:
1.1059 raeburn 11834: function titleCheck(form,count,offset) {
11835: if (count > 0) {
11836: var chosen = (offset+$startcount)+7*(count-1);
11837: var depitem = $startcount + ((count-1) * 7) + 2;
11838: var currtype = form.elements[depitem].type;
11839: if (form.elements[chosen].value == 'display') {
11840: document.getElementById('arc_title_'+count).style.display='block';
11841: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
11842: document.getElementById('archive_title_'+count).value=maintitle;
11843: }
11844: } else {
11845: document.getElementById('arc_title_'+count).style.display='none';
11846: if (currtype == 'text') {
11847: document.getElementById('archive_title_'+count).value='';
11848: }
11849: }
11850: }
11851: return;
11852: }
11853:
1.1055 raeburn 11854: // ]]>
11855: </script>
11856: END
11857: return $scripttag;
11858: }
11859:
11860: sub process_extracted_files {
1.1067 raeburn 11861: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 11862: my $numitems = $env{'form.archive_count'};
11863: return unless ($numitems);
11864: my @ids=&Apache::lonnet::current_machine_ids();
11865: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 11866: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 11867: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
11868: if (grep(/^\Q$docuhome\E$/,@ids)) {
11869: $prefix = &LONCAPA::propath($docudom,$docuname);
11870: $pathtocheck = "$dir_root/$destination";
11871: $dir = $dir_root;
11872: $ishome = 1;
11873: } else {
11874: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
11875: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
11876: $dir = "$dir_root/$docudom/$docuname";
11877: }
11878: my $currdir = "$dir_root/$destination";
11879: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
11880: if ($env{'form.folderpath'}) {
11881: my @items = split('&',$env{'form.folderpath'});
11882: $folders{'0'} = $items[-2];
1.1099 raeburn 11883: if ($env{'form.folderpath'} =~ /\:1$/) {
11884: $containers{'0'}='page';
11885: } else {
11886: $containers{'0'}='sequence';
11887: }
1.1055 raeburn 11888: }
11889: my @archdirs = &get_env_multiple('form.archive_directory');
11890: if ($numitems) {
11891: for (my $i=1; $i<=$numitems; $i++) {
11892: my $path = $env{'form.archive_content_'.$i};
11893: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
11894: my $item = $1;
11895: $toplevelitems{$item} = $i;
11896: if (grep(/^\Q$i\E$/,@archdirs)) {
11897: $is_dir{$item} = 1;
11898: }
11899: }
11900: }
11901: }
1.1067 raeburn 11902: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 11903: if (keys(%toplevelitems) > 0) {
11904: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 11905: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
11906: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 11907: }
1.1066 raeburn 11908: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 11909: if ($numitems) {
11910: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 11911: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 11912: my $path = $env{'form.archive_content_'.$i};
11913: if ($path =~ /^\Q$pathtocheck\E/) {
11914: if ($env{'form.archive_'.$i} eq 'discard') {
11915: if ($prefix ne '' && $path ne '') {
11916: if (-e $prefix.$path) {
1.1066 raeburn 11917: if ((@archdirs > 0) &&
11918: (grep(/^\Q$i\E$/,@archdirs))) {
11919: $todeletedir{$prefix.$path} = 1;
11920: } else {
11921: $todelete{$prefix.$path} = 1;
11922: }
1.1055 raeburn 11923: }
11924: }
11925: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 11926: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 11927: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 11928: $docstitle = $env{'form.archive_title_'.$i};
11929: if ($docstitle eq '') {
11930: $docstitle = $title;
11931: }
1.1055 raeburn 11932: $outer = 0;
1.1056 raeburn 11933: if (ref($dirorder{$i}) eq 'ARRAY') {
11934: if (@{$dirorder{$i}} > 0) {
11935: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 11936: if ($env{'form.archive_'.$item} eq 'display') {
11937: $outer = $item;
11938: last;
11939: }
11940: }
11941: }
11942: }
11943: my ($errtext,$fatal) =
11944: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
11945: '/'.$folders{$outer}.'.'.
11946: $containers{$outer});
11947: next if ($fatal);
11948: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
11949: if ($context eq 'coursedocs') {
1.1056 raeburn 11950: $mapinner{$i} = time;
1.1055 raeburn 11951: $folders{$i} = 'default_'.$mapinner{$i};
11952: $containers{$i} = 'sequence';
11953: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11954: $folders{$i}.'.'.$containers{$i};
11955: my $newidx = &LONCAPA::map::getresidx();
11956: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11957: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11958: push(@LONCAPA::map::order,$newidx);
11959: my ($outtext,$errtext) =
11960: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11961: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11962: '.'.$containers{$outer},1,1);
1.1056 raeburn 11963: $newseqid{$i} = $newidx;
1.1067 raeburn 11964: unless ($errtext) {
11965: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
11966: }
1.1055 raeburn 11967: }
11968: } else {
11969: if ($context eq 'coursedocs') {
11970: my $newidx=&LONCAPA::map::getresidx();
11971: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
11972: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
11973: $title;
11974: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
11975: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
11976: }
11977: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11978: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
11979: }
11980: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
11981: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 11982: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 11983: unless ($ishome) {
11984: my $fetch = "$newdest{$i}/$title";
11985: $fetch =~ s/^\Q$prefix$dir\E//;
11986: $prompttofetch{$fetch} = 1;
11987: }
1.1055 raeburn 11988: }
11989: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 11990: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 11991: push(@LONCAPA::map::order, $newidx);
11992: my ($outtext,$errtext)=
11993: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
11994: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 11995: '.'.$containers{$outer},1,1);
1.1067 raeburn 11996: unless ($errtext) {
11997: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
11998: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
11999: }
12000: }
1.1055 raeburn 12001: }
12002: }
1.1086 raeburn 12003: }
12004: } else {
12005: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12006: }
12007: }
12008: for (my $i=1; $i<=$numitems; $i++) {
12009: next unless ($env{'form.archive_'.$i} eq 'dependency');
12010: my $path = $env{'form.archive_content_'.$i};
12011: if ($path =~ /^\Q$pathtocheck\E/) {
12012: my ($title) = ($path =~ m{/([^/]+)$});
12013: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12014: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12015: if (ref($dirorder{$i}) eq 'ARRAY') {
12016: my ($itemidx,$fullpath,$relpath);
12017: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12018: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12019: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 12020: if ($dirorder{$i}->[$j] eq $container) {
12021: $itemidx = $j;
1.1056 raeburn 12022: }
12023: }
1.1086 raeburn 12024: }
12025: if ($itemidx eq '') {
12026: $itemidx = 0;
12027: }
12028: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12029: if ($mapinner{$referrer{$i}}) {
12030: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12031: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12032: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12033: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12034: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12035: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12036: if (!-e $fullpath) {
12037: mkdir($fullpath,0755);
1.1056 raeburn 12038: }
12039: }
1.1086 raeburn 12040: } else {
12041: last;
1.1056 raeburn 12042: }
1.1086 raeburn 12043: }
12044: }
12045: } elsif ($newdest{$referrer{$i}}) {
12046: $fullpath = $newdest{$referrer{$i}};
12047: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12048: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12049: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12050: last;
12051: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12052: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12053: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12054: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12055: if (!-e $fullpath) {
12056: mkdir($fullpath,0755);
1.1056 raeburn 12057: }
12058: }
1.1086 raeburn 12059: } else {
12060: last;
1.1056 raeburn 12061: }
1.1055 raeburn 12062: }
12063: }
1.1086 raeburn 12064: if ($fullpath ne '') {
12065: if (-e "$prefix$path") {
12066: system("mv $prefix$path $fullpath/$title");
12067: }
12068: if (-e "$fullpath/$title") {
12069: my $showpath;
12070: if ($relpath ne '') {
12071: $showpath = "$relpath/$title";
12072: } else {
12073: $showpath = "/$title";
12074: }
12075: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12076: }
12077: unless ($ishome) {
12078: my $fetch = "$fullpath/$title";
12079: $fetch =~ s/^\Q$prefix$dir\E//;
12080: $prompttofetch{$fetch} = 1;
12081: }
12082: }
1.1055 raeburn 12083: }
1.1086 raeburn 12084: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12085: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12086: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12087: }
12088: } else {
12089: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12090: }
12091: }
12092: if (keys(%todelete)) {
12093: foreach my $key (keys(%todelete)) {
12094: unlink($key);
1.1066 raeburn 12095: }
12096: }
12097: if (keys(%todeletedir)) {
12098: foreach my $key (keys(%todeletedir)) {
12099: rmdir($key);
12100: }
12101: }
12102: foreach my $dir (sort(keys(%is_dir))) {
12103: if (($pathtocheck ne '') && ($dir ne '')) {
12104: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12105: }
12106: }
1.1067 raeburn 12107: if ($result ne '') {
12108: $output .= '<ul>'."\n".
12109: $result."\n".
12110: '</ul>';
12111: }
12112: unless ($ishome) {
12113: my $replicationfail;
12114: foreach my $item (keys(%prompttofetch)) {
12115: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12116: unless ($fetchresult eq 'ok') {
12117: $replicationfail .= '<li>'.$item.'</li>'."\n";
12118: }
12119: }
12120: if ($replicationfail) {
12121: $output .= '<p class="LC_error">'.
12122: &mt('Course home server failed to retrieve:').'<ul>'.
12123: $replicationfail.
12124: '</ul></p>';
12125: }
12126: }
1.1055 raeburn 12127: } else {
12128: $warning = &mt('No items found in archive.');
12129: }
12130: if ($error) {
12131: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12132: $error.'</p>'."\n";
12133: }
12134: if ($warning) {
12135: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12136: }
12137: return $output;
12138: }
12139:
1.1066 raeburn 12140: sub cleanup_empty_dirs {
12141: my ($path) = @_;
12142: if (($path ne '') && (-d $path)) {
12143: if (opendir(my $dirh,$path)) {
12144: my @dircontents = grep(!/^\./,readdir($dirh));
12145: my $numitems = 0;
12146: foreach my $item (@dircontents) {
12147: if (-d "$path/$item") {
1.1111 raeburn 12148: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12149: if (-e "$path/$item") {
12150: $numitems ++;
12151: }
12152: } else {
12153: $numitems ++;
12154: }
12155: }
12156: if ($numitems == 0) {
12157: rmdir($path);
12158: }
12159: closedir($dirh);
12160: }
12161: }
12162: return;
12163: }
12164:
1.41 ng 12165: =pod
1.45 matthew 12166:
1.1162 raeburn 12167: =item * &get_folder_hierarchy()
1.1068 raeburn 12168:
12169: Provides hierarchy of names of folders/sub-folders containing the current
12170: item,
12171:
12172: Inputs: 3
12173: - $navmap - navmaps object
12174:
12175: - $map - url for map (either the trigger itself, or map containing
12176: the resource, which is the trigger).
12177:
12178: - $showitem - 1 => show title for map itself; 0 => do not show.
12179:
12180: Outputs: 1 @pathitems - array of folder/subfolder names.
12181:
12182: =cut
12183:
12184: sub get_folder_hierarchy {
12185: my ($navmap,$map,$showitem) = @_;
12186: my @pathitems;
12187: if (ref($navmap)) {
12188: my $mapres = $navmap->getResourceByUrl($map);
12189: if (ref($mapres)) {
12190: my $pcslist = $mapres->map_hierarchy();
12191: if ($pcslist ne '') {
12192: my @pcs = split(/,/,$pcslist);
12193: foreach my $pc (@pcs) {
12194: if ($pc == 1) {
1.1129 raeburn 12195: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12196: } else {
12197: my $res = $navmap->getByMapPc($pc);
12198: if (ref($res)) {
12199: my $title = $res->compTitle();
12200: $title =~ s/\W+/_/g;
12201: if ($title ne '') {
12202: push(@pathitems,$title);
12203: }
12204: }
12205: }
12206: }
12207: }
1.1071 raeburn 12208: if ($showitem) {
12209: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 12210: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12211: } else {
12212: my $maptitle = $mapres->compTitle();
12213: $maptitle =~ s/\W+/_/g;
12214: if ($maptitle ne '') {
12215: push(@pathitems,$maptitle);
12216: }
1.1068 raeburn 12217: }
12218: }
12219: }
12220: }
12221: return @pathitems;
12222: }
12223:
12224: =pod
12225:
1.1015 raeburn 12226: =item * &get_turnedin_filepath()
12227:
12228: Determines path in a user's portfolio file for storage of files uploaded
12229: to a specific essayresponse or dropbox item.
12230:
12231: Inputs: 3 required + 1 optional.
12232: $symb is symb for resource, $uname and $udom are for current user (required).
12233: $caller is optional (can be "submission", if routine is called when storing
12234: an upoaded file when "Submit Answer" button was pressed).
12235:
12236: Returns array containing $path and $multiresp.
12237: $path is path in portfolio. $multiresp is 1 if this resource contains more
12238: than one file upload item. Callers of routine should append partid as a
12239: subdirectory to $path in cases where $multiresp is 1.
12240:
12241: Called by: homework/essayresponse.pm and homework/structuretags.pm
12242:
12243: =cut
12244:
12245: sub get_turnedin_filepath {
12246: my ($symb,$uname,$udom,$caller) = @_;
12247: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
12248: my $turnindir;
12249: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
12250: $turnindir = $userhash{'turnindir'};
12251: my ($path,$multiresp);
12252: if ($turnindir eq '') {
12253: if ($caller eq 'submission') {
12254: $turnindir = &mt('turned in');
12255: $turnindir =~ s/\W+/_/g;
12256: my %newhash = (
12257: 'turnindir' => $turnindir,
12258: );
12259: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
12260: }
12261: }
12262: if ($turnindir ne '') {
12263: $path = '/'.$turnindir.'/';
12264: my ($multipart,$turnin,@pathitems);
12265: my $navmap = Apache::lonnavmaps::navmap->new();
12266: if (defined($navmap)) {
12267: my $mapres = $navmap->getResourceByUrl($map);
12268: if (ref($mapres)) {
12269: my $pcslist = $mapres->map_hierarchy();
12270: if ($pcslist ne '') {
12271: foreach my $pc (split(/,/,$pcslist)) {
12272: my $res = $navmap->getByMapPc($pc);
12273: if (ref($res)) {
12274: my $title = $res->compTitle();
12275: $title =~ s/\W+/_/g;
12276: if ($title ne '') {
1.1149 raeburn 12277: if (($pc > 1) && (length($title) > 12)) {
12278: $title = substr($title,0,12);
12279: }
1.1015 raeburn 12280: push(@pathitems,$title);
12281: }
12282: }
12283: }
12284: }
12285: my $maptitle = $mapres->compTitle();
12286: $maptitle =~ s/\W+/_/g;
12287: if ($maptitle ne '') {
1.1149 raeburn 12288: if (length($maptitle) > 12) {
12289: $maptitle = substr($maptitle,0,12);
12290: }
1.1015 raeburn 12291: push(@pathitems,$maptitle);
12292: }
12293: unless ($env{'request.state'} eq 'construct') {
12294: my $res = $navmap->getBySymb($symb);
12295: if (ref($res)) {
12296: my $partlist = $res->parts();
12297: my $totaluploads = 0;
12298: if (ref($partlist) eq 'ARRAY') {
12299: foreach my $part (@{$partlist}) {
12300: my @types = $res->responseType($part);
12301: my @ids = $res->responseIds($part);
12302: for (my $i=0; $i < scalar(@ids); $i++) {
12303: if ($types[$i] eq 'essay') {
12304: my $partid = $part.'_'.$ids[$i];
12305: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
12306: $totaluploads ++;
12307: }
12308: }
12309: }
12310: }
12311: if ($totaluploads > 1) {
12312: $multiresp = 1;
12313: }
12314: }
12315: }
12316: }
12317: } else {
12318: return;
12319: }
12320: } else {
12321: return;
12322: }
12323: my $restitle=&Apache::lonnet::gettitle($symb);
12324: $restitle =~ s/\W+/_/g;
12325: if ($restitle eq '') {
12326: $restitle = ($resurl =~ m{/[^/]+$});
12327: if ($restitle eq '') {
12328: $restitle = time;
12329: }
12330: }
1.1149 raeburn 12331: if (length($restitle) > 12) {
12332: $restitle = substr($restitle,0,12);
12333: }
1.1015 raeburn 12334: push(@pathitems,$restitle);
12335: $path .= join('/',@pathitems);
12336: }
12337: return ($path,$multiresp);
12338: }
12339:
12340: =pod
12341:
1.464 albertel 12342: =back
1.41 ng 12343:
1.112 bowersj2 12344: =head1 CSV Upload/Handling functions
1.38 albertel 12345:
1.41 ng 12346: =over 4
12347:
1.648 raeburn 12348: =item * &upfile_store($r)
1.41 ng 12349:
12350: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 12351: needs $env{'form.upfile'}
1.41 ng 12352: returns $datatoken to be put into hidden field
12353:
12354: =cut
1.31 albertel 12355:
12356: sub upfile_store {
12357: my $r=shift;
1.258 albertel 12358: $env{'form.upfile'}=~s/\r/\n/gs;
12359: $env{'form.upfile'}=~s/\f/\n/gs;
12360: $env{'form.upfile'}=~s/\n+/\n/gs;
12361: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 12362:
1.258 albertel 12363: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
12364: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 12365: {
1.158 raeburn 12366: my $datafile = $r->dir_config('lonDaemons').
12367: '/tmp/'.$datatoken.'.tmp';
12368: if ( open(my $fh,">$datafile") ) {
1.258 albertel 12369: print $fh $env{'form.upfile'};
1.158 raeburn 12370: close($fh);
12371: }
1.31 albertel 12372: }
12373: return $datatoken;
12374: }
12375:
1.56 matthew 12376: =pod
12377:
1.648 raeburn 12378: =item * &load_tmp_file($r)
1.41 ng 12379:
12380: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 12381: needs $env{'form.datatoken'},
12382: sets $env{'form.upfile'} to the contents of the file
1.41 ng 12383:
12384: =cut
1.31 albertel 12385:
12386: sub load_tmp_file {
12387: my $r=shift;
12388: my @studentdata=();
12389: {
1.158 raeburn 12390: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 12391: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 12392: if ( open(my $fh,"<$studentfile") ) {
12393: @studentdata=<$fh>;
12394: close($fh);
12395: }
1.31 albertel 12396: }
1.258 albertel 12397: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 12398: }
12399:
1.56 matthew 12400: =pod
12401:
1.648 raeburn 12402: =item * &upfile_record_sep()
1.41 ng 12403:
12404: Separate uploaded file into records
12405: returns array of records,
1.258 albertel 12406: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 12407:
12408: =cut
1.31 albertel 12409:
12410: sub upfile_record_sep {
1.258 albertel 12411: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 12412: } else {
1.248 albertel 12413: my @records;
1.258 albertel 12414: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 12415: if ($line=~/^\s*$/) { next; }
12416: push(@records,$line);
12417: }
12418: return @records;
1.31 albertel 12419: }
12420: }
12421:
1.56 matthew 12422: =pod
12423:
1.648 raeburn 12424: =item * &record_sep($record)
1.41 ng 12425:
1.258 albertel 12426: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 12427:
12428: =cut
12429:
1.263 www 12430: sub takeleft {
12431: my $index=shift;
12432: return substr('0000'.$index,-4,4);
12433: }
12434:
1.31 albertel 12435: sub record_sep {
12436: my $record=shift;
12437: my %components=();
1.258 albertel 12438: if ($env{'form.upfiletype'} eq 'xml') {
12439: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 12440: my $i=0;
1.356 albertel 12441: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 12442: $field=~s/^(\"|\')//;
12443: $field=~s/(\"|\')$//;
1.263 www 12444: $components{&takeleft($i)}=$field;
1.31 albertel 12445: $i++;
12446: }
1.258 albertel 12447: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 12448: my $i=0;
1.356 albertel 12449: foreach my $field (split(/\t/,$record)) {
1.31 albertel 12450: $field=~s/^(\"|\')//;
12451: $field=~s/(\"|\')$//;
1.263 www 12452: $components{&takeleft($i)}=$field;
1.31 albertel 12453: $i++;
12454: }
12455: } else {
1.561 www 12456: my $separator=',';
1.480 banghart 12457: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 12458: $separator=';';
1.480 banghart 12459: }
1.31 albertel 12460: my $i=0;
1.561 www 12461: # the character we are looking for to indicate the end of a quote or a record
12462: my $looking_for=$separator;
12463: # do not add the characters to the fields
12464: my $ignore=0;
12465: # we just encountered a separator (or the beginning of the record)
12466: my $just_found_separator=1;
12467: # store the field we are working on here
12468: my $field='';
12469: # work our way through all characters in record
12470: foreach my $character ($record=~/(.)/g) {
12471: if ($character eq $looking_for) {
12472: if ($character ne $separator) {
12473: # Found the end of a quote, again looking for separator
12474: $looking_for=$separator;
12475: $ignore=1;
12476: } else {
12477: # Found a separator, store away what we got
12478: $components{&takeleft($i)}=$field;
12479: $i++;
12480: $just_found_separator=1;
12481: $ignore=0;
12482: $field='';
12483: }
12484: next;
12485: }
12486: # single or double quotation marks after a separator indicate beginning of a quote
12487: # we are now looking for the end of the quote and need to ignore separators
12488: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
12489: $looking_for=$character;
12490: next;
12491: }
12492: # ignore would be true after we reached the end of a quote
12493: if ($ignore) { next; }
12494: if (($just_found_separator) && ($character=~/\s/)) { next; }
12495: $field.=$character;
12496: $just_found_separator=0;
1.31 albertel 12497: }
1.561 www 12498: # catch the very last entry, since we never encountered the separator
12499: $components{&takeleft($i)}=$field;
1.31 albertel 12500: }
12501: return %components;
12502: }
12503:
1.144 matthew 12504: ######################################################
12505: ######################################################
12506:
1.56 matthew 12507: =pod
12508:
1.648 raeburn 12509: =item * &upfile_select_html()
1.41 ng 12510:
1.144 matthew 12511: Return HTML code to select a file from the users machine and specify
12512: the file type.
1.41 ng 12513:
12514: =cut
12515:
1.144 matthew 12516: ######################################################
12517: ######################################################
1.31 albertel 12518: sub upfile_select_html {
1.144 matthew 12519: my %Types = (
12520: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 12521: semisv => &mt('Semicolon separated values'),
1.144 matthew 12522: space => &mt('Space separated'),
12523: tab => &mt('Tabulator separated'),
12524: # xml => &mt('HTML/XML'),
12525: );
12526: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 12527: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 12528: foreach my $type (sort(keys(%Types))) {
12529: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
12530: }
12531: $Str .= "</select>\n";
12532: return $Str;
1.31 albertel 12533: }
12534:
1.301 albertel 12535: sub get_samples {
12536: my ($records,$toget) = @_;
12537: my @samples=({});
12538: my $got=0;
12539: foreach my $rec (@$records) {
12540: my %temp = &record_sep($rec);
12541: if (! grep(/\S/, values(%temp))) { next; }
12542: if (%temp) {
12543: $samples[$got]=\%temp;
12544: $got++;
12545: if ($got == $toget) { last; }
12546: }
12547: }
12548: return \@samples;
12549: }
12550:
1.144 matthew 12551: ######################################################
12552: ######################################################
12553:
1.56 matthew 12554: =pod
12555:
1.648 raeburn 12556: =item * &csv_print_samples($r,$records)
1.41 ng 12557:
12558: Prints a table of sample values from each column uploaded $r is an
12559: Apache Request ref, $records is an arrayref from
12560: &Apache::loncommon::upfile_record_sep
12561:
12562: =cut
12563:
1.144 matthew 12564: ######################################################
12565: ######################################################
1.31 albertel 12566: sub csv_print_samples {
12567: my ($r,$records) = @_;
1.662 bisitz 12568: my $samples = &get_samples($records,5);
1.301 albertel 12569:
1.594 raeburn 12570: $r->print(&mt('Samples').'<br />'.&start_data_table().
12571: &start_data_table_header_row());
1.356 albertel 12572: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 12573: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 12574: $r->print(&end_data_table_header_row());
1.301 albertel 12575: foreach my $hash (@$samples) {
1.594 raeburn 12576: $r->print(&start_data_table_row());
1.356 albertel 12577: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 12578: $r->print('<td>');
1.356 albertel 12579: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 12580: $r->print('</td>');
12581: }
1.594 raeburn 12582: $r->print(&end_data_table_row());
1.31 albertel 12583: }
1.594 raeburn 12584: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 12585: }
12586:
1.144 matthew 12587: ######################################################
12588: ######################################################
12589:
1.56 matthew 12590: =pod
12591:
1.648 raeburn 12592: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 12593:
12594: Prints a table to create associations between values and table columns.
1.144 matthew 12595:
1.41 ng 12596: $r is an Apache Request ref,
12597: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 12598: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 12599:
12600: =cut
12601:
1.144 matthew 12602: ######################################################
12603: ######################################################
1.31 albertel 12604: sub csv_print_select_table {
12605: my ($r,$records,$d) = @_;
1.301 albertel 12606: my $i=0;
12607: my $samples = &get_samples($records,1);
1.144 matthew 12608: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 12609: &start_data_table().&start_data_table_header_row().
1.144 matthew 12610: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 12611: '<th>'.&mt('Column').'</th>'.
12612: &end_data_table_header_row()."\n");
1.356 albertel 12613: foreach my $array_ref (@$d) {
12614: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 12615: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 12616:
1.875 bisitz 12617: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 12618: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 12619: $r->print('<option value="none"></option>');
1.356 albertel 12620: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
12621: $r->print('<option value="'.$sample.'"'.
12622: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 12623: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 12624: }
1.594 raeburn 12625: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 12626: $i++;
12627: }
1.594 raeburn 12628: $r->print(&end_data_table());
1.31 albertel 12629: $i--;
12630: return $i;
12631: }
1.56 matthew 12632:
1.144 matthew 12633: ######################################################
12634: ######################################################
12635:
1.56 matthew 12636: =pod
1.31 albertel 12637:
1.648 raeburn 12638: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 12639:
12640: Prints a table of sample values from the upload and can make associate samples to internal names.
12641:
12642: $r is an Apache Request ref,
12643: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
12644: $d is an array of 2 element arrays (internal name, displayed name)
12645:
12646: =cut
12647:
1.144 matthew 12648: ######################################################
12649: ######################################################
1.31 albertel 12650: sub csv_samples_select_table {
12651: my ($r,$records,$d) = @_;
12652: my $i=0;
1.144 matthew 12653: #
1.662 bisitz 12654: my $max_samples = 5;
12655: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 12656: $r->print(&start_data_table().
12657: &start_data_table_header_row().'<th>'.
12658: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
12659: &end_data_table_header_row());
1.301 albertel 12660:
12661: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 12662: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 12663: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 12664: foreach my $option (@$d) {
12665: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 12666: $r->print('<option value="'.$value.'"'.
1.253 albertel 12667: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 12668: $display.'</option>');
1.31 albertel 12669: }
12670: $r->print('</select></td><td>');
1.662 bisitz 12671: foreach my $line (0..($max_samples-1)) {
1.301 albertel 12672: if (defined($samples->[$line]{$key})) {
12673: $r->print($samples->[$line]{$key}."<br />\n");
12674: }
12675: }
1.594 raeburn 12676: $r->print('</td>'.&end_data_table_row());
1.31 albertel 12677: $i++;
12678: }
1.594 raeburn 12679: $r->print(&end_data_table());
1.31 albertel 12680: $i--;
12681: return($i);
1.115 matthew 12682: }
12683:
1.144 matthew 12684: ######################################################
12685: ######################################################
12686:
1.115 matthew 12687: =pod
12688:
1.648 raeburn 12689: =item * &clean_excel_name($name)
1.115 matthew 12690:
12691: Returns a replacement for $name which does not contain any illegal characters.
12692:
12693: =cut
12694:
1.144 matthew 12695: ######################################################
12696: ######################################################
1.115 matthew 12697: sub clean_excel_name {
12698: my ($name) = @_;
12699: $name =~ s/[:\*\?\/\\]//g;
12700: if (length($name) > 31) {
12701: $name = substr($name,0,31);
12702: }
12703: return $name;
1.25 albertel 12704: }
1.84 albertel 12705:
1.85 albertel 12706: =pod
12707:
1.648 raeburn 12708: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 12709:
12710: Returns either 1 or undef
12711:
12712: 1 if the part is to be hidden, undef if it is to be shown
12713:
12714: Arguments are:
12715:
12716: $id the id of the part to be checked
12717: $symb, optional the symb of the resource to check
12718: $udom, optional the domain of the user to check for
12719: $uname, optional the username of the user to check for
12720:
12721: =cut
1.84 albertel 12722:
12723: sub check_if_partid_hidden {
12724: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 12725: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 12726: $symb,$udom,$uname);
1.141 albertel 12727: my $truth=1;
12728: #if the string starts with !, then the list is the list to show not hide
12729: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 12730: my @hiddenlist=split(/,/,$hiddenparts);
12731: foreach my $checkid (@hiddenlist) {
1.141 albertel 12732: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 12733: }
1.141 albertel 12734: return !$truth;
1.84 albertel 12735: }
1.127 matthew 12736:
1.138 matthew 12737:
12738: ############################################################
12739: ############################################################
12740:
12741: =pod
12742:
1.157 matthew 12743: =back
12744:
1.138 matthew 12745: =head1 cgi-bin script and graphing routines
12746:
1.157 matthew 12747: =over 4
12748:
1.648 raeburn 12749: =item * &get_cgi_id()
1.138 matthew 12750:
12751: Inputs: none
12752:
12753: Returns an id which can be used to pass environment variables
12754: to various cgi-bin scripts. These environment variables will
12755: be removed from the users environment after a given time by
12756: the routine &Apache::lonnet::transfer_profile_to_env.
12757:
12758: =cut
12759:
12760: ############################################################
12761: ############################################################
1.152 albertel 12762: my $uniq=0;
1.136 matthew 12763: sub get_cgi_id {
1.154 albertel 12764: $uniq=($uniq+1)%100000;
1.280 albertel 12765: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 12766: }
12767:
1.127 matthew 12768: ############################################################
12769: ############################################################
12770:
12771: =pod
12772:
1.648 raeburn 12773: =item * &DrawBarGraph()
1.127 matthew 12774:
1.138 matthew 12775: Facilitates the plotting of data in a (stacked) bar graph.
12776: Puts plot definition data into the users environment in order for
12777: graph.png to plot it. Returns an <img> tag for the plot.
12778: The bars on the plot are labeled '1','2',...,'n'.
12779:
12780: Inputs:
12781:
12782: =over 4
12783:
12784: =item $Title: string, the title of the plot
12785:
12786: =item $xlabel: string, text describing the X-axis of the plot
12787:
12788: =item $ylabel: string, text describing the Y-axis of the plot
12789:
12790: =item $Max: scalar, the maximum Y value to use in the plot
12791: If $Max is < any data point, the graph will not be rendered.
12792:
1.140 matthew 12793: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 12794: they are plotted. If undefined, default values will be used.
12795:
1.178 matthew 12796: =item $labels: array ref holding the labels to use on the x-axis for the bars.
12797:
1.138 matthew 12798: =item @Values: An array of array references. Each array reference holds data
12799: to be plotted in a stacked bar chart.
12800:
1.239 matthew 12801: =item If the final element of @Values is a hash reference the key/value
12802: pairs will be added to the graph definition.
12803:
1.138 matthew 12804: =back
12805:
12806: Returns:
12807:
12808: An <img> tag which references graph.png and the appropriate identifying
12809: information for the plot.
12810:
1.127 matthew 12811: =cut
12812:
12813: ############################################################
12814: ############################################################
1.134 matthew 12815: sub DrawBarGraph {
1.178 matthew 12816: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 12817: #
12818: if (! defined($colors)) {
12819: $colors = ['#33ff00',
12820: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
12821: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
12822: ];
12823: }
1.228 matthew 12824: my $extra_settings = {};
12825: if (ref($Values[-1]) eq 'HASH') {
12826: $extra_settings = pop(@Values);
12827: }
1.127 matthew 12828: #
1.136 matthew 12829: my $identifier = &get_cgi_id();
12830: my $id = 'cgi.'.$identifier;
1.129 matthew 12831: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 12832: return '';
12833: }
1.225 matthew 12834: #
12835: my @Labels;
12836: if (defined($labels)) {
12837: @Labels = @$labels;
12838: } else {
12839: for (my $i=0;$i<@{$Values[0]};$i++) {
12840: push (@Labels,$i+1);
12841: }
12842: }
12843: #
1.129 matthew 12844: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 12845: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 12846: my %ValuesHash;
12847: my $NumSets=1;
12848: foreach my $array (@Values) {
12849: next if (! ref($array));
1.136 matthew 12850: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 12851: join(',',@$array);
1.129 matthew 12852: }
1.127 matthew 12853: #
1.136 matthew 12854: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 12855: if ($NumBars < 3) {
12856: $width = 120+$NumBars*32;
1.220 matthew 12857: $xskip = 1;
1.225 matthew 12858: $bar_width = 30;
12859: } elsif ($NumBars < 5) {
12860: $width = 120+$NumBars*20;
12861: $xskip = 1;
12862: $bar_width = 20;
1.220 matthew 12863: } elsif ($NumBars < 10) {
1.136 matthew 12864: $width = 120+$NumBars*15;
12865: $xskip = 1;
12866: $bar_width = 15;
12867: } elsif ($NumBars <= 25) {
12868: $width = 120+$NumBars*11;
12869: $xskip = 5;
12870: $bar_width = 8;
12871: } elsif ($NumBars <= 50) {
12872: $width = 120+$NumBars*8;
12873: $xskip = 5;
12874: $bar_width = 4;
12875: } else {
12876: $width = 120+$NumBars*8;
12877: $xskip = 5;
12878: $bar_width = 4;
12879: }
12880: #
1.137 matthew 12881: $Max = 1 if ($Max < 1);
12882: if ( int($Max) < $Max ) {
12883: $Max++;
12884: $Max = int($Max);
12885: }
1.127 matthew 12886: $Title = '' if (! defined($Title));
12887: $xlabel = '' if (! defined($xlabel));
12888: $ylabel = '' if (! defined($ylabel));
1.369 www 12889: $ValuesHash{$id.'.title'} = &escape($Title);
12890: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
12891: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 12892: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 12893: $ValuesHash{$id.'.NumBars'} = $NumBars;
12894: $ValuesHash{$id.'.NumSets'} = $NumSets;
12895: $ValuesHash{$id.'.PlotType'} = 'bar';
12896: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12897: $ValuesHash{$id.'.height'} = $height;
12898: $ValuesHash{$id.'.width'} = $width;
12899: $ValuesHash{$id.'.xskip'} = $xskip;
12900: $ValuesHash{$id.'.bar_width'} = $bar_width;
12901: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 12902: #
1.228 matthew 12903: # Deal with other parameters
12904: while (my ($key,$value) = each(%$extra_settings)) {
12905: $ValuesHash{$id.'.'.$key} = $value;
12906: }
12907: #
1.646 raeburn 12908: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 12909: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
12910: }
12911:
12912: ############################################################
12913: ############################################################
12914:
12915: =pod
12916:
1.648 raeburn 12917: =item * &DrawXYGraph()
1.137 matthew 12918:
1.138 matthew 12919: Facilitates the plotting of data in an XY graph.
12920: Puts plot definition data into the users environment in order for
12921: graph.png to plot it. Returns an <img> tag for the plot.
12922:
12923: Inputs:
12924:
12925: =over 4
12926:
12927: =item $Title: string, the title of the plot
12928:
12929: =item $xlabel: string, text describing the X-axis of the plot
12930:
12931: =item $ylabel: string, text describing the Y-axis of the plot
12932:
12933: =item $Max: scalar, the maximum Y value to use in the plot
12934: If $Max is < any data point, the graph will not be rendered.
12935:
12936: =item $colors: Array ref containing the hex color codes for the data to be
12937: plotted in. If undefined, default values will be used.
12938:
12939: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
12940:
12941: =item $Ydata: Array ref containing Array refs.
1.185 www 12942: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 12943:
12944: =item %Values: hash indicating or overriding any default values which are
12945: passed to graph.png.
12946: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
12947:
12948: =back
12949:
12950: Returns:
12951:
12952: An <img> tag which references graph.png and the appropriate identifying
12953: information for the plot.
12954:
1.137 matthew 12955: =cut
12956:
12957: ############################################################
12958: ############################################################
12959: sub DrawXYGraph {
12960: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
12961: #
12962: # Create the identifier for the graph
12963: my $identifier = &get_cgi_id();
12964: my $id = 'cgi.'.$identifier;
12965: #
12966: $Title = '' if (! defined($Title));
12967: $xlabel = '' if (! defined($xlabel));
12968: $ylabel = '' if (! defined($ylabel));
12969: my %ValuesHash =
12970: (
1.369 www 12971: $id.'.title' => &escape($Title),
12972: $id.'.xlabel' => &escape($xlabel),
12973: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 12974: $id.'.y_max_value'=> $Max,
12975: $id.'.labels' => join(',',@$Xlabels),
12976: $id.'.PlotType' => 'XY',
12977: );
12978: #
12979: if (defined($colors) && ref($colors) eq 'ARRAY') {
12980: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
12981: }
12982: #
12983: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
12984: return '';
12985: }
12986: my $NumSets=1;
1.138 matthew 12987: foreach my $array (@{$Ydata}){
1.137 matthew 12988: next if (! ref($array));
12989: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
12990: }
1.138 matthew 12991: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 12992: #
12993: # Deal with other parameters
12994: while (my ($key,$value) = each(%Values)) {
12995: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 12996: }
12997: #
1.646 raeburn 12998: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 12999: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13000: }
13001:
13002: ############################################################
13003: ############################################################
13004:
13005: =pod
13006:
1.648 raeburn 13007: =item * &DrawXYYGraph()
1.138 matthew 13008:
13009: Facilitates the plotting of data in an XY graph with two Y axes.
13010: Puts plot definition data into the users environment in order for
13011: graph.png to plot it. Returns an <img> tag for the plot.
13012:
13013: Inputs:
13014:
13015: =over 4
13016:
13017: =item $Title: string, the title of the plot
13018:
13019: =item $xlabel: string, text describing the X-axis of the plot
13020:
13021: =item $ylabel: string, text describing the Y-axis of the plot
13022:
13023: =item $colors: Array ref containing the hex color codes for the data to be
13024: plotted in. If undefined, default values will be used.
13025:
13026: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13027:
13028: =item $Ydata1: The first data set
13029:
13030: =item $Min1: The minimum value of the left Y-axis
13031:
13032: =item $Max1: The maximum value of the left Y-axis
13033:
13034: =item $Ydata2: The second data set
13035:
13036: =item $Min2: The minimum value of the right Y-axis
13037:
13038: =item $Max2: The maximum value of the left Y-axis
13039:
13040: =item %Values: hash indicating or overriding any default values which are
13041: passed to graph.png.
13042: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13043:
13044: =back
13045:
13046: Returns:
13047:
13048: An <img> tag which references graph.png and the appropriate identifying
13049: information for the plot.
1.136 matthew 13050:
13051: =cut
13052:
13053: ############################################################
13054: ############################################################
1.137 matthew 13055: sub DrawXYYGraph {
13056: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13057: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13058: #
13059: # Create the identifier for the graph
13060: my $identifier = &get_cgi_id();
13061: my $id = 'cgi.'.$identifier;
13062: #
13063: $Title = '' if (! defined($Title));
13064: $xlabel = '' if (! defined($xlabel));
13065: $ylabel = '' if (! defined($ylabel));
13066: my %ValuesHash =
13067: (
1.369 www 13068: $id.'.title' => &escape($Title),
13069: $id.'.xlabel' => &escape($xlabel),
13070: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13071: $id.'.labels' => join(',',@$Xlabels),
13072: $id.'.PlotType' => 'XY',
13073: $id.'.NumSets' => 2,
1.137 matthew 13074: $id.'.two_axes' => 1,
13075: $id.'.y1_max_value' => $Max1,
13076: $id.'.y1_min_value' => $Min1,
13077: $id.'.y2_max_value' => $Max2,
13078: $id.'.y2_min_value' => $Min2,
1.136 matthew 13079: );
13080: #
1.137 matthew 13081: if (defined($colors) && ref($colors) eq 'ARRAY') {
13082: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13083: }
13084: #
13085: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13086: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13087: return '';
13088: }
13089: my $NumSets=1;
1.137 matthew 13090: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13091: next if (! ref($array));
13092: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13093: }
13094: #
13095: # Deal with other parameters
13096: while (my ($key,$value) = each(%Values)) {
13097: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13098: }
13099: #
1.646 raeburn 13100: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13101: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13102: }
13103:
13104: ############################################################
13105: ############################################################
13106:
13107: =pod
13108:
1.157 matthew 13109: =back
13110:
1.139 matthew 13111: =head1 Statistics helper routines?
13112:
13113: Bad place for them but what the hell.
13114:
1.157 matthew 13115: =over 4
13116:
1.648 raeburn 13117: =item * &chartlink()
1.139 matthew 13118:
13119: Returns a link to the chart for a specific student.
13120:
13121: Inputs:
13122:
13123: =over 4
13124:
13125: =item $linktext: The text of the link
13126:
13127: =item $sname: The students username
13128:
13129: =item $sdomain: The students domain
13130:
13131: =back
13132:
1.157 matthew 13133: =back
13134:
1.139 matthew 13135: =cut
13136:
13137: ############################################################
13138: ############################################################
13139: sub chartlink {
13140: my ($linktext, $sname, $sdomain) = @_;
13141: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13142: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13143: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13144: '">'.$linktext.'</a>';
1.153 matthew 13145: }
13146:
13147: #######################################################
13148: #######################################################
13149:
13150: =pod
13151:
13152: =head1 Course Environment Routines
1.157 matthew 13153:
13154: =over 4
1.153 matthew 13155:
1.648 raeburn 13156: =item * &restore_course_settings()
1.153 matthew 13157:
1.648 raeburn 13158: =item * &store_course_settings()
1.153 matthew 13159:
13160: Restores/Store indicated form parameters from the course environment.
13161: Will not overwrite existing values of the form parameters.
13162:
13163: Inputs:
13164: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13165:
13166: a hash ref describing the data to be stored. For example:
13167:
13168: %Save_Parameters = ('Status' => 'scalar',
13169: 'chartoutputmode' => 'scalar',
13170: 'chartoutputdata' => 'scalar',
13171: 'Section' => 'array',
1.373 raeburn 13172: 'Group' => 'array',
1.153 matthew 13173: 'StudentData' => 'array',
13174: 'Maps' => 'array');
13175:
13176: Returns: both routines return nothing
13177:
1.631 raeburn 13178: =back
13179:
1.153 matthew 13180: =cut
13181:
13182: #######################################################
13183: #######################################################
13184: sub store_course_settings {
1.496 albertel 13185: return &store_settings($env{'request.course.id'},@_);
13186: }
13187:
13188: sub store_settings {
1.153 matthew 13189: # save to the environment
13190: # appenv the same items, just to be safe
1.300 albertel 13191: my $udom = $env{'user.domain'};
13192: my $uname = $env{'user.name'};
1.496 albertel 13193: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13194: my %SaveHash;
13195: my %AppHash;
13196: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13197: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13198: my $envname = 'environment.'.$basename;
1.258 albertel 13199: if (exists($env{'form.'.$setting})) {
1.153 matthew 13200: # Save this value away
13201: if ($type eq 'scalar' &&
1.258 albertel 13202: (! exists($env{$envname}) ||
13203: $env{$envname} ne $env{'form.'.$setting})) {
13204: $SaveHash{$basename} = $env{'form.'.$setting};
13205: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13206: } elsif ($type eq 'array') {
13207: my $stored_form;
1.258 albertel 13208: if (ref($env{'form.'.$setting})) {
1.153 matthew 13209: $stored_form = join(',',
13210: map {
1.369 www 13211: &escape($_);
1.258 albertel 13212: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13213: } else {
13214: $stored_form =
1.369 www 13215: &escape($env{'form.'.$setting});
1.153 matthew 13216: }
13217: # Determine if the array contents are the same.
1.258 albertel 13218: if ($stored_form ne $env{$envname}) {
1.153 matthew 13219: $SaveHash{$basename} = $stored_form;
13220: $AppHash{$envname} = $stored_form;
13221: }
13222: }
13223: }
13224: }
13225: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13226: $udom,$uname);
1.153 matthew 13227: if ($put_result !~ /^(ok|delayed)/) {
13228: &Apache::lonnet::logthis('unable to save form parameters, '.
13229: 'got error:'.$put_result);
13230: }
13231: # Make sure these settings stick around in this session, too
1.646 raeburn 13232: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13233: return;
13234: }
13235:
13236: sub restore_course_settings {
1.499 albertel 13237: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 13238: }
13239:
13240: sub restore_settings {
13241: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13242: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 13243: next if (exists($env{'form.'.$setting}));
1.496 albertel 13244: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 13245: '.'.$setting;
1.258 albertel 13246: if (exists($env{$envname})) {
1.153 matthew 13247: if ($type eq 'scalar') {
1.258 albertel 13248: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 13249: } elsif ($type eq 'array') {
1.258 albertel 13250: $env{'form.'.$setting} = [
1.153 matthew 13251: map {
1.369 www 13252: &unescape($_);
1.258 albertel 13253: } split(',',$env{$envname})
1.153 matthew 13254: ];
13255: }
13256: }
13257: }
1.127 matthew 13258: }
13259:
1.618 raeburn 13260: #######################################################
13261: #######################################################
13262:
13263: =pod
13264:
13265: =head1 Domain E-mail Routines
13266:
13267: =over 4
13268:
1.648 raeburn 13269: =item * &build_recipient_list()
1.618 raeburn 13270:
1.1144 raeburn 13271: Build recipient lists for following types of e-mail:
1.766 raeburn 13272: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 13273: (d) Help requests, (e) Course requests needing approval, (f) loncapa
13274: module change checking, student/employee ID conflict checks, as
13275: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
13276: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 13277:
13278: Inputs:
1.619 raeburn 13279: defmail (scalar - email address of default recipient),
1.1144 raeburn 13280: mailing type (scalar: errormail, packagesmail, helpdeskmail,
13281: requestsmail, updatesmail, or idconflictsmail).
13282:
1.619 raeburn 13283: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 13284:
1.619 raeburn 13285: origmail (scalar - email address of recipient from loncapa.conf,
13286: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 13287:
1.655 raeburn 13288: Returns: comma separated list of addresses to which to send e-mail.
13289:
13290: =back
1.618 raeburn 13291:
13292: =cut
13293:
13294: ############################################################
13295: ############################################################
13296: sub build_recipient_list {
1.619 raeburn 13297: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 13298: my @recipients;
13299: my $otheremails;
13300: my %domconfig =
13301: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
13302: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 13303: if (exists($domconfig{'contacts'}{$mailing})) {
13304: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
13305: my @contacts = ('adminemail','supportemail');
13306: foreach my $item (@contacts) {
13307: if ($domconfig{'contacts'}{$mailing}{$item}) {
13308: my $addr = $domconfig{'contacts'}{$item};
13309: if (!grep(/^\Q$addr\E$/,@recipients)) {
13310: push(@recipients,$addr);
13311: }
1.619 raeburn 13312: }
1.766 raeburn 13313: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 13314: }
13315: }
1.766 raeburn 13316: } elsif ($origmail ne '') {
13317: push(@recipients,$origmail);
1.618 raeburn 13318: }
1.619 raeburn 13319: } elsif ($origmail ne '') {
13320: push(@recipients,$origmail);
1.618 raeburn 13321: }
1.688 raeburn 13322: if (defined($defmail)) {
13323: if ($defmail ne '') {
13324: push(@recipients,$defmail);
13325: }
1.618 raeburn 13326: }
13327: if ($otheremails) {
1.619 raeburn 13328: my @others;
13329: if ($otheremails =~ /,/) {
13330: @others = split(/,/,$otheremails);
1.618 raeburn 13331: } else {
1.619 raeburn 13332: push(@others,$otheremails);
13333: }
13334: foreach my $addr (@others) {
13335: if (!grep(/^\Q$addr\E$/,@recipients)) {
13336: push(@recipients,$addr);
13337: }
1.618 raeburn 13338: }
13339: }
1.619 raeburn 13340: my $recipientlist = join(',',@recipients);
1.618 raeburn 13341: return $recipientlist;
13342: }
13343:
1.127 matthew 13344: ############################################################
13345: ############################################################
1.154 albertel 13346:
1.655 raeburn 13347: =pod
13348:
13349: =head1 Course Catalog Routines
13350:
13351: =over 4
13352:
13353: =item * &gather_categories()
13354:
13355: Converts category definitions - keys of categories hash stored in
13356: coursecategories in configuration.db on the primary library server in a
13357: domain - to an array. Also generates javascript and idx hash used to
13358: generate Domain Coordinator interface for editing Course Categories.
13359:
13360: Inputs:
1.663 raeburn 13361:
1.655 raeburn 13362: categories (reference to hash of category definitions).
1.663 raeburn 13363:
1.655 raeburn 13364: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13365: categories and subcategories).
1.663 raeburn 13366:
1.655 raeburn 13367: idx (reference to hash of counters used in Domain Coordinator interface for
13368: editing Course Categories).
1.663 raeburn 13369:
1.655 raeburn 13370: jsarray (reference to array of categories used to create Javascript arrays for
13371: Domain Coordinator interface for editing Course Categories).
13372:
13373: Returns: nothing
13374:
13375: Side effects: populates cats, idx and jsarray.
13376:
13377: =cut
13378:
13379: sub gather_categories {
13380: my ($categories,$cats,$idx,$jsarray) = @_;
13381: my %counters;
13382: my $num = 0;
13383: foreach my $item (keys(%{$categories})) {
13384: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
13385: if ($container eq '' && $depth == 0) {
13386: $cats->[$depth][$categories->{$item}] = $cat;
13387: } else {
13388: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
13389: }
13390: my ($escitem,$tail) = split(/:/,$item,2);
13391: if ($counters{$tail} eq '') {
13392: $counters{$tail} = $num;
13393: $num ++;
13394: }
13395: if (ref($idx) eq 'HASH') {
13396: $idx->{$item} = $counters{$tail};
13397: }
13398: if (ref($jsarray) eq 'ARRAY') {
13399: push(@{$jsarray->[$counters{$tail}]},$item);
13400: }
13401: }
13402: return;
13403: }
13404:
13405: =pod
13406:
13407: =item * &extract_categories()
13408:
13409: Used to generate breadcrumb trails for course categories.
13410:
13411: Inputs:
1.663 raeburn 13412:
1.655 raeburn 13413: categories (reference to hash of category definitions).
1.663 raeburn 13414:
1.655 raeburn 13415: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13416: categories and subcategories).
1.663 raeburn 13417:
1.655 raeburn 13418: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 13419:
1.655 raeburn 13420: allitems (reference to hash - key is category key
13421: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13422:
1.655 raeburn 13423: idx (reference to hash of counters used in Domain Coordinator interface for
13424: editing Course Categories).
1.663 raeburn 13425:
1.655 raeburn 13426: jsarray (reference to array of categories used to create Javascript arrays for
13427: Domain Coordinator interface for editing Course Categories).
13428:
1.665 raeburn 13429: subcats (reference to hash of arrays containing all subcategories within each
13430: category, -recursive)
13431:
1.655 raeburn 13432: Returns: nothing
13433:
13434: Side effects: populates trails and allitems hash references.
13435:
13436: =cut
13437:
13438: sub extract_categories {
1.665 raeburn 13439: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 13440: if (ref($categories) eq 'HASH') {
13441: &gather_categories($categories,$cats,$idx,$jsarray);
13442: if (ref($cats->[0]) eq 'ARRAY') {
13443: for (my $i=0; $i<@{$cats->[0]}; $i++) {
13444: my $name = $cats->[0][$i];
13445: my $item = &escape($name).'::0';
13446: my $trailstr;
13447: if ($name eq 'instcode') {
13448: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 13449: } elsif ($name eq 'communities') {
13450: $trailstr = &mt('Communities');
1.655 raeburn 13451: } else {
13452: $trailstr = $name;
13453: }
13454: if ($allitems->{$item} eq '') {
13455: push(@{$trails},$trailstr);
13456: $allitems->{$item} = scalar(@{$trails})-1;
13457: }
13458: my @parents = ($name);
13459: if (ref($cats->[1]{$name}) eq 'ARRAY') {
13460: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
13461: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 13462: if (ref($subcats) eq 'HASH') {
13463: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
13464: }
13465: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
13466: }
13467: } else {
13468: if (ref($subcats) eq 'HASH') {
13469: $subcats->{$item} = [];
1.655 raeburn 13470: }
13471: }
13472: }
13473: }
13474: }
13475: return;
13476: }
13477:
13478: =pod
13479:
1.1162 raeburn 13480: =item * &recurse_categories()
1.655 raeburn 13481:
13482: Recursively used to generate breadcrumb trails for course categories.
13483:
13484: Inputs:
1.663 raeburn 13485:
1.655 raeburn 13486: cats (reference to array of arrays/hashes which encapsulates hierarchy of
13487: categories and subcategories).
1.663 raeburn 13488:
1.655 raeburn 13489: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 13490:
13491: category (current course category, for which breadcrumb trail is being generated).
13492:
13493: trails (reference to array of breadcrumb trails for each category).
13494:
1.655 raeburn 13495: allitems (reference to hash - key is category key
13496: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 13497:
1.655 raeburn 13498: parents (array containing containers directories for current category,
13499: back to top level).
13500:
13501: Returns: nothing
13502:
13503: Side effects: populates trails and allitems hash references
13504:
13505: =cut
13506:
13507: sub recurse_categories {
1.665 raeburn 13508: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 13509: my $shallower = $depth - 1;
13510: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
13511: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
13512: my $name = $cats->[$depth]{$category}[$k];
13513: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13514: my $trailstr = join(' -> ',(@{$parents},$category));
13515: if ($allitems->{$item} eq '') {
13516: push(@{$trails},$trailstr);
13517: $allitems->{$item} = scalar(@{$trails})-1;
13518: }
13519: my $deeper = $depth+1;
13520: push(@{$parents},$category);
1.665 raeburn 13521: if (ref($subcats) eq 'HASH') {
13522: my $subcat = &escape($name).':'.$category.':'.$depth;
13523: for (my $j=@{$parents}; $j>=0; $j--) {
13524: my $higher;
13525: if ($j > 0) {
13526: $higher = &escape($parents->[$j]).':'.
13527: &escape($parents->[$j-1]).':'.$j;
13528: } else {
13529: $higher = &escape($parents->[$j]).'::'.$j;
13530: }
13531: push(@{$subcats->{$higher}},$subcat);
13532: }
13533: }
13534: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
13535: $subcats);
1.655 raeburn 13536: pop(@{$parents});
13537: }
13538: } else {
13539: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
13540: my $trailstr = join(' -> ',(@{$parents},$category));
13541: if ($allitems->{$item} eq '') {
13542: push(@{$trails},$trailstr);
13543: $allitems->{$item} = scalar(@{$trails})-1;
13544: }
13545: }
13546: return;
13547: }
13548:
1.663 raeburn 13549: =pod
13550:
1.1162 raeburn 13551: =item * &assign_categories_table()
1.663 raeburn 13552:
13553: Create a datatable for display of hierarchical categories in a domain,
13554: with checkboxes to allow a course to be categorized.
13555:
13556: Inputs:
13557:
13558: cathash - reference to hash of categories defined for the domain (from
13559: configuration.db)
13560:
13561: currcat - scalar with an & separated list of categories assigned to a course.
13562:
1.919 raeburn 13563: type - scalar contains course type (Course or Community).
13564:
1.663 raeburn 13565: Returns: $output (markup to be displayed)
13566:
13567: =cut
13568:
13569: sub assign_categories_table {
1.919 raeburn 13570: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 13571: my $output;
13572: if (ref($cathash) eq 'HASH') {
13573: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
13574: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
13575: $maxdepth = scalar(@cats);
13576: if (@cats > 0) {
13577: my $itemcount = 0;
13578: if (ref($cats[0]) eq 'ARRAY') {
13579: my @currcategories;
13580: if ($currcat ne '') {
13581: @currcategories = split('&',$currcat);
13582: }
1.919 raeburn 13583: my $table;
1.663 raeburn 13584: for (my $i=0; $i<@{$cats[0]}; $i++) {
13585: my $parent = $cats[0][$i];
1.919 raeburn 13586: next if ($parent eq 'instcode');
13587: if ($type eq 'Community') {
13588: next unless ($parent eq 'communities');
13589: } else {
13590: next if ($parent eq 'communities');
13591: }
1.663 raeburn 13592: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
13593: my $item = &escape($parent).'::0';
13594: my $checked = '';
13595: if (@currcategories > 0) {
13596: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 13597: $checked = ' checked="checked"';
1.663 raeburn 13598: }
13599: }
1.919 raeburn 13600: my $parent_title = $parent;
13601: if ($parent eq 'communities') {
13602: $parent_title = &mt('Communities');
13603: }
13604: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
13605: '<input type="checkbox" name="usecategory" value="'.
13606: $item.'"'.$checked.' />'.$parent_title.'</span>'.
13607: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 13608: my $depth = 1;
13609: push(@path,$parent);
1.919 raeburn 13610: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 13611: pop(@path);
1.919 raeburn 13612: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 13613: $itemcount ++;
13614: }
1.919 raeburn 13615: if ($itemcount) {
13616: $output = &Apache::loncommon::start_data_table().
13617: $table.
13618: &Apache::loncommon::end_data_table();
13619: }
1.663 raeburn 13620: }
13621: }
13622: }
13623: return $output;
13624: }
13625:
13626: =pod
13627:
1.1162 raeburn 13628: =item * &assign_category_rows()
1.663 raeburn 13629:
13630: Create a datatable row for display of nested categories in a domain,
13631: with checkboxes to allow a course to be categorized,called recursively.
13632:
13633: Inputs:
13634:
13635: itemcount - track row number for alternating colors
13636:
13637: cats - reference to array of arrays/hashes which encapsulates hierarchy of
13638: categories and subcategories.
13639:
13640: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
13641:
13642: parent - parent of current category item
13643:
13644: path - Array containing all categories back up through the hierarchy from the
13645: current category to the top level.
13646:
13647: currcategories - reference to array of current categories assigned to the course
13648:
13649: Returns: $output (markup to be displayed).
13650:
13651: =cut
13652:
13653: sub assign_category_rows {
13654: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
13655: my ($text,$name,$item,$chgstr);
13656: if (ref($cats) eq 'ARRAY') {
13657: my $maxdepth = scalar(@{$cats});
13658: if (ref($cats->[$depth]) eq 'HASH') {
13659: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
13660: my $numchildren = @{$cats->[$depth]{$parent}};
13661: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 13662: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 13663: for (my $j=0; $j<$numchildren; $j++) {
13664: $name = $cats->[$depth]{$parent}[$j];
13665: $item = &escape($name).':'.&escape($parent).':'.$depth;
13666: my $deeper = $depth+1;
13667: my $checked = '';
13668: if (ref($currcategories) eq 'ARRAY') {
13669: if (@{$currcategories} > 0) {
13670: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 13671: $checked = ' checked="checked"';
1.663 raeburn 13672: }
13673: }
13674: }
1.664 raeburn 13675: $text .= '<tr><td><span class="LC_nobreak"><label>'.
13676: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 13677: $item.'"'.$checked.' />'.$name.'</label></span>'.
13678: '<input type="hidden" name="catname" value="'.$name.'" />'.
13679: '</td><td>';
1.663 raeburn 13680: if (ref($path) eq 'ARRAY') {
13681: push(@{$path},$name);
13682: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
13683: pop(@{$path});
13684: }
13685: $text .= '</td></tr>';
13686: }
13687: $text .= '</table></td>';
13688: }
13689: }
13690: }
13691: return $text;
13692: }
13693:
1.1181 raeburn 13694: =pod
13695:
13696: =back
13697:
13698: =cut
13699:
1.655 raeburn 13700: ############################################################
13701: ############################################################
13702:
13703:
1.443 albertel 13704: sub commit_customrole {
1.664 raeburn 13705: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 13706: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 13707: ($start?', '.&mt('starting').' '.localtime($start):'').
13708: ($end?', ending '.localtime($end):'').': <b>'.
13709: &Apache::lonnet::assigncustomrole(
1.664 raeburn 13710: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 13711: '</b><br />';
13712: return $output;
13713: }
13714:
13715: sub commit_standardrole {
1.1116 raeburn 13716: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 13717: my ($output,$logmsg,$linefeed);
13718: if ($context eq 'auto') {
13719: $linefeed = "\n";
13720: } else {
13721: $linefeed = "<br />\n";
13722: }
1.443 albertel 13723: if ($three eq 'st') {
1.541 raeburn 13724: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 13725: $one,$two,$sec,$context,$credits);
1.541 raeburn 13726: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 13727: ($result eq 'unknown_course') || ($result eq 'refused')) {
13728: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 13729: } else {
1.541 raeburn 13730: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 13731: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13732: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
13733: if ($context eq 'auto') {
13734: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
13735: } else {
13736: $output .= '<b>'.$result.'</b>'.$linefeed.
13737: &mt('Add to classlist').': <b>ok</b>';
13738: }
13739: $output .= $linefeed;
1.443 albertel 13740: }
13741: } else {
13742: $output = &mt('Assigning').' '.$three.' in '.$url.
13743: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 13744: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 13745: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 13746: if ($context eq 'auto') {
13747: $output .= $result.$linefeed;
13748: } else {
13749: $output .= '<b>'.$result.'</b>'.$linefeed;
13750: }
1.443 albertel 13751: }
13752: return $output;
13753: }
13754:
13755: sub commit_studentrole {
1.1116 raeburn 13756: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
13757: $credits) = @_;
1.626 raeburn 13758: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 13759: if ($context eq 'auto') {
13760: $linefeed = "\n";
13761: } else {
13762: $linefeed = '<br />'."\n";
13763: }
1.443 albertel 13764: if (defined($one) && defined($two)) {
13765: my $cid=$one.'_'.$two;
13766: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
13767: my $secchange = 0;
13768: my $expire_role_result;
13769: my $modify_section_result;
1.628 raeburn 13770: if ($oldsec ne '-1') {
13771: if ($oldsec ne $sec) {
1.443 albertel 13772: $secchange = 1;
1.628 raeburn 13773: my $now = time;
1.443 albertel 13774: my $uurl='/'.$cid;
13775: $uurl=~s/\_/\//g;
13776: if ($oldsec) {
13777: $uurl.='/'.$oldsec;
13778: }
1.626 raeburn 13779: $oldsecurl = $uurl;
1.628 raeburn 13780: $expire_role_result =
1.652 raeburn 13781: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 13782: if ($env{'request.course.sec'} ne '') {
13783: if ($expire_role_result eq 'refused') {
13784: my @roles = ('st');
13785: my @statuses = ('previous');
13786: my @roledoms = ($one);
13787: my $withsec = 1;
13788: my %roleshash =
13789: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
13790: \@statuses,\@roles,\@roledoms,$withsec);
13791: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
13792: my ($oldstart,$oldend) =
13793: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
13794: if ($oldend > 0 && $oldend <= $now) {
13795: $expire_role_result = 'ok';
13796: }
13797: }
13798: }
13799: }
1.443 albertel 13800: $result = $expire_role_result;
13801: }
13802: }
13803: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 13804: $modify_section_result =
13805: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
13806: undef,undef,undef,$sec,
13807: $end,$start,'','',$cid,
13808: '',$context,$credits);
1.443 albertel 13809: if ($modify_section_result =~ /^ok/) {
13810: if ($secchange == 1) {
1.628 raeburn 13811: if ($sec eq '') {
13812: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
13813: } else {
13814: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
13815: }
1.443 albertel 13816: } elsif ($oldsec eq '-1') {
1.628 raeburn 13817: if ($sec eq '') {
13818: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
13819: } else {
13820: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13821: }
1.443 albertel 13822: } else {
1.628 raeburn 13823: if ($sec eq '') {
13824: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
13825: } else {
13826: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
13827: }
1.443 albertel 13828: }
13829: } else {
1.1115 raeburn 13830: if ($secchange) {
1.628 raeburn 13831: $$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;
13832: } else {
13833: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
13834: }
1.443 albertel 13835: }
13836: $result = $modify_section_result;
13837: } elsif ($secchange == 1) {
1.628 raeburn 13838: if ($oldsec eq '') {
1.1103 raeburn 13839: $$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 13840: } else {
13841: $$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;
13842: }
1.626 raeburn 13843: if ($expire_role_result eq 'refused') {
13844: my $newsecurl = '/'.$cid;
13845: $newsecurl =~ s/\_/\//g;
13846: if ($sec ne '') {
13847: $newsecurl.='/'.$sec;
13848: }
13849: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
13850: if ($sec eq '') {
13851: $$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;
13852: } else {
13853: $$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;
13854: }
13855: }
13856: }
1.443 albertel 13857: }
13858: } else {
1.626 raeburn 13859: $$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 13860: $result = "error: incomplete course id\n";
13861: }
13862: return $result;
13863: }
13864:
1.1108 raeburn 13865: sub show_role_extent {
13866: my ($scope,$context,$role) = @_;
13867: $scope =~ s{^/}{};
13868: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
13869: push(@courseroles,'co');
13870: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
13871: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
13872: $scope =~ s{/}{_};
13873: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
13874: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
13875: my ($audom,$auname) = split(/\//,$scope);
13876: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
13877: &Apache::loncommon::plainname($auname,$audom).'</span>');
13878: } else {
13879: $scope =~ s{/$}{};
13880: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
13881: &Apache::lonnet::domain($scope,'description').'</span>');
13882: }
13883: }
13884:
1.443 albertel 13885: ############################################################
13886: ############################################################
13887:
1.566 albertel 13888: sub check_clone {
1.578 raeburn 13889: my ($args,$linefeed) = @_;
1.566 albertel 13890: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
13891: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
13892: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
13893: my $clonemsg;
13894: my $can_clone = 0;
1.944 raeburn 13895: my $lctype = lc($args->{'crstype'});
1.908 raeburn 13896: if ($lctype ne 'community') {
13897: $lctype = 'course';
13898: }
1.566 albertel 13899: if ($clonehome eq 'no_host') {
1.944 raeburn 13900: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13901: $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'});
13902: } else {
13903: $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'});
13904: }
1.566 albertel 13905: } else {
13906: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 13907: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13908: if ($clonedesc{'type'} ne 'Community') {
13909: $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'});
13910: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13911: }
13912: }
1.882 raeburn 13913: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
13914: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 13915: $can_clone = 1;
13916: } else {
13917: my %clonehash = &Apache::lonnet::get('environment',['cloners'],
13918: $args->{'clonedomain'},$args->{'clonecourse'});
13919: my @cloners = split(/,/,$clonehash{'cloners'});
1.578 raeburn 13920: if (grep(/^\*$/,@cloners)) {
13921: $can_clone = 1;
13922: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
13923: $can_clone = 1;
13924: } else {
1.908 raeburn 13925: my $ccrole = 'cc';
1.944 raeburn 13926: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13927: $ccrole = 'co';
13928: }
1.578 raeburn 13929: my %roleshash =
13930: &Apache::lonnet::get_my_roles($args->{'ccuname'},
13931: $args->{'ccdomain'},
1.908 raeburn 13932: 'userroles',['active'],[$ccrole],
1.578 raeburn 13933: [$args->{'clonedomain'}]);
1.908 raeburn 13934: if (($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) || (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners))) {
1.942 raeburn 13935: $can_clone = 1;
13936: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},$args->{'ccuname'},$args->{'ccdomain'})) {
13937: $can_clone = 1;
13938: } else {
1.944 raeburn 13939: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 13940: $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'});
13941: } else {
13942: $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'});
13943: }
1.578 raeburn 13944: }
1.566 albertel 13945: }
1.578 raeburn 13946: }
1.566 albertel 13947: }
13948: return ($can_clone, $clonemsg, $cloneid, $clonehome);
13949: }
13950:
1.444 albertel 13951: sub construct_course {
1.1166 raeburn 13952: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 13953: my $outcome;
1.541 raeburn 13954: my $linefeed = '<br />'."\n";
13955: if ($context eq 'auto') {
13956: $linefeed = "\n";
13957: }
1.566 albertel 13958:
13959: #
13960: # Are we cloning?
13961: #
13962: my ($can_clone, $clonemsg, $cloneid, $clonehome);
13963: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 13964: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 13965: if ($context ne 'auto') {
1.578 raeburn 13966: if ($clonemsg ne '') {
13967: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
13968: }
1.566 albertel 13969: }
13970: $outcome .= $clonemsg.$linefeed;
13971:
13972: if (!$can_clone) {
13973: return (0,$outcome);
13974: }
13975: }
13976:
1.444 albertel 13977: #
13978: # Open course
13979: #
13980: my $crstype = lc($args->{'crstype'});
13981: my %cenv=();
13982: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
13983: $args->{'cdescr'},
13984: $args->{'curl'},
13985: $args->{'course_home'},
13986: $args->{'nonstandard'},
13987: $args->{'crscode'},
13988: $args->{'ccuname'}.':'.
13989: $args->{'ccdomain'},
1.882 raeburn 13990: $args->{'crstype'},
1.885 raeburn 13991: $cnum,$context,$category);
1.444 albertel 13992:
13993: # Note: The testing routines depend on this being output; see
13994: # Utils::Course. This needs to at least be output as a comment
13995: # if anyone ever decides to not show this, and Utils::Course::new
13996: # will need to be suitably modified.
1.541 raeburn 13997: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$crstype,$$courseid).$linefeed;
1.943 raeburn 13998: if ($$courseid =~ /^error:/) {
13999: return (0,$outcome);
14000: }
14001:
1.444 albertel 14002: #
14003: # Check if created correctly
14004: #
1.479 albertel 14005: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 14006: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 14007: if ($crsuhome eq 'no_host') {
14008: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
14009: return (0,$outcome);
14010: }
1.541 raeburn 14011: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 14012:
1.444 albertel 14013: #
1.566 albertel 14014: # Do the cloning
14015: #
14016: if ($can_clone && $cloneid) {
14017: $clonemsg = &mt('Cloning [_1] from [_2]',$crstype,$clonehome);
14018: if ($context ne 'auto') {
14019: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
14020: }
14021: $outcome .= $clonemsg.$linefeed;
14022: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 14023: # Copy all files
1.637 www 14024: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 14025: # Restore URL
1.566 albertel 14026: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 14027: # Restore title
1.566 albertel 14028: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 14029: # Restore creation date, creator and creation context.
14030: $cenv{'internal.created'}=$oldcenv{'internal.created'};
14031: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
14032: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 14033: # Mark as cloned
1.566 albertel 14034: $cenv{'clonedfrom'}=$cloneid;
1.638 www 14035: # Need to clone grading mode
14036: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
14037: $cenv{'grading'}=$newenv{'grading'};
14038: # Do not clone these environment entries
14039: &Apache::lonnet::del('environment',
14040: ['default_enrollment_start_date',
14041: 'default_enrollment_end_date',
14042: 'question.email',
14043: 'policy.email',
14044: 'comment.email',
14045: 'pch.users.denied',
1.725 raeburn 14046: 'plc.users.denied',
14047: 'hidefromcat',
1.1121 raeburn 14048: 'checkforpriv',
1.1166 raeburn 14049: 'categories',
14050: 'internal.uniquecode'],
1.638 www 14051: $$crsudom,$$crsunum);
1.1170 raeburn 14052: if ($args->{'textbook'}) {
14053: $cenv{'internal.textbook'} = $args->{'textbook'};
14054: }
1.444 albertel 14055: }
1.566 albertel 14056:
1.444 albertel 14057: #
14058: # Set environment (will override cloned, if existing)
14059: #
14060: my @sections = ();
14061: my @xlists = ();
14062: if ($args->{'crstype'}) {
14063: $cenv{'type'}=$args->{'crstype'};
14064: }
14065: if ($args->{'crsid'}) {
14066: $cenv{'courseid'}=$args->{'crsid'};
14067: }
14068: if ($args->{'crscode'}) {
14069: $cenv{'internal.coursecode'}=$args->{'crscode'};
14070: }
14071: if ($args->{'crsquota'} ne '') {
14072: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14073: } else {
14074: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14075: }
14076: if ($args->{'ccuname'}) {
14077: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14078: ':'.$args->{'ccdomain'};
14079: } else {
14080: $cenv{'internal.courseowner'} = $args->{'curruser'};
14081: }
1.1116 raeburn 14082: if ($args->{'defaultcredits'}) {
14083: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14084: }
1.444 albertel 14085: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14086: if ($args->{'crssections'}) {
14087: $cenv{'internal.sectionnums'} = '';
14088: if ($args->{'crssections'} =~ m/,/) {
14089: @sections = split/,/,$args->{'crssections'};
14090: } else {
14091: $sections[0] = $args->{'crssections'};
14092: }
14093: if (@sections > 0) {
14094: foreach my $item (@sections) {
14095: my ($sec,$gp) = split/:/,$item;
14096: my $class = $args->{'crscode'}.$sec;
14097: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
14098: $cenv{'internal.sectionnums'} .= $item.',';
14099: unless ($addcheck eq 'ok') {
14100: push @badclasses, $class;
14101: }
14102: }
14103: $cenv{'internal.sectionnums'} =~ s/,$//;
14104: }
14105: }
14106: # do not hide course coordinator from staff listing,
14107: # even if privileged
14108: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 14109: # add course coordinator's domain to domains to check for privileged users
14110: # if different to course domain
14111: if ($$crsudom ne $args->{'ccdomain'}) {
14112: $cenv{'checkforpriv'} = $args->{'ccdomain'};
14113: }
1.444 albertel 14114: # add crosslistings
14115: if ($args->{'crsxlist'}) {
14116: $cenv{'internal.crosslistings'}='';
14117: if ($args->{'crsxlist'} =~ m/,/) {
14118: @xlists = split/,/,$args->{'crsxlist'};
14119: } else {
14120: $xlists[0] = $args->{'crsxlist'};
14121: }
14122: if (@xlists > 0) {
14123: foreach my $item (@xlists) {
14124: my ($xl,$gp) = split/:/,$item;
14125: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
14126: $cenv{'internal.crosslistings'} .= $item.',';
14127: unless ($addcheck eq 'ok') {
14128: push @badclasses, $xl;
14129: }
14130: }
14131: $cenv{'internal.crosslistings'} =~ s/,$//;
14132: }
14133: }
14134: if ($args->{'autoadds'}) {
14135: $cenv{'internal.autoadds'}=$args->{'autoadds'};
14136: }
14137: if ($args->{'autodrops'}) {
14138: $cenv{'internal.autodrops'}=$args->{'autodrops'};
14139: }
14140: # check for notification of enrollment changes
14141: my @notified = ();
14142: if ($args->{'notify_owner'}) {
14143: if ($args->{'ccuname'} ne '') {
14144: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
14145: }
14146: }
14147: if ($args->{'notify_dc'}) {
14148: if ($uname ne '') {
1.630 raeburn 14149: push(@notified,$uname.':'.$udom);
1.444 albertel 14150: }
14151: }
14152: if (@notified > 0) {
14153: my $notifylist;
14154: if (@notified > 1) {
14155: $notifylist = join(',',@notified);
14156: } else {
14157: $notifylist = $notified[0];
14158: }
14159: $cenv{'internal.notifylist'} = $notifylist;
14160: }
14161: if (@badclasses > 0) {
14162: my %lt=&Apache::lonlocal::texthash(
14163: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course. However, if automated course roster updates are enabled for this class, these particular sections/crosslistings will not contribute towards enrollment, because the user identified as the course owner for this LON-CAPA course',
14164: 'dnhr' => 'does not have rights to access enrollment in these classes',
14165: 'adby' => 'as determined by the policies of your institution on access to official classlists'
14166: );
1.541 raeburn 14167: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
14168: ' ('.$lt{'adby'}.')';
14169: if ($context eq 'auto') {
14170: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 14171: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 14172: foreach my $item (@badclasses) {
14173: if ($context eq 'auto') {
14174: $outcome .= " - $item\n";
14175: } else {
14176: $outcome .= "<li>$item</li>\n";
14177: }
14178: }
14179: if ($context eq 'auto') {
14180: $outcome .= $linefeed;
14181: } else {
1.566 albertel 14182: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 14183: }
14184: }
1.444 albertel 14185: }
14186: if ($args->{'no_end_date'}) {
14187: $args->{'endaccess'} = 0;
14188: }
14189: $cenv{'internal.autostart'}=$args->{'enrollstart'};
14190: $cenv{'internal.autoend'}=$args->{'enrollend'};
14191: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
14192: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
14193: if ($args->{'showphotos'}) {
14194: $cenv{'internal.showphotos'}=$args->{'showphotos'};
14195: }
14196: $cenv{'internal.authtype'} = $args->{'authtype'};
14197: $cenv{'internal.autharg'} = $args->{'autharg'};
14198: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
14199: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 14200: 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');
14201: if ($context eq 'auto') {
14202: $outcome .= $krb_msg;
14203: } else {
1.566 albertel 14204: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 14205: }
14206: $outcome .= $linefeed;
1.444 albertel 14207: }
14208: }
14209: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
14210: if ($args->{'setpolicy'}) {
14211: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14212: }
14213: if ($args->{'setcontent'}) {
14214: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
14215: }
14216: }
14217: if ($args->{'reshome'}) {
14218: $cenv{'reshome'}=$args->{'reshome'}.'/';
14219: $cenv{'reshome'}=~s/\/+$/\//;
14220: }
14221: #
14222: # course has keyed access
14223: #
14224: if ($args->{'setkeys'}) {
14225: $cenv{'keyaccess'}='yes';
14226: }
14227: # if specified, key authority is not course, but user
14228: # only active if keyaccess is yes
14229: if ($args->{'keyauth'}) {
1.487 albertel 14230: my ($user,$domain) = split(':',$args->{'keyauth'});
14231: $user = &LONCAPA::clean_username($user);
14232: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 14233: if ($user ne '' && $domain ne '') {
1.487 albertel 14234: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 14235: }
14236: }
14237:
1.1166 raeburn 14238: #
1.1167 raeburn 14239: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 14240: #
14241: if ($args->{'uniquecode'}) {
14242: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
14243: if ($code) {
14244: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 14245: my %crsinfo =
14246: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
14247: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
14248: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
14249: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
14250: }
1.1166 raeburn 14251: if (ref($coderef)) {
14252: $$coderef = $code;
14253: }
14254: }
14255: }
14256:
1.444 albertel 14257: if ($args->{'disresdis'}) {
14258: $cenv{'pch.roles.denied'}='st';
14259: }
14260: if ($args->{'disablechat'}) {
14261: $cenv{'plc.roles.denied'}='st';
14262: }
14263:
14264: # Record we've not yet viewed the Course Initialization Helper for this
14265: # course
14266: $cenv{'course.helper.not.run'} = 1;
14267: #
14268: # Use new Randomseed
14269: #
14270: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
14271: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
14272: #
14273: # The encryption code and receipt prefix for this course
14274: #
14275: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
14276: $cenv{'internal.encpref'}=100+int(9*rand(99));
14277: #
14278: # By default, use standard grading
14279: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
14280:
1.541 raeburn 14281: $outcome .= $linefeed.&mt('Setting environment').': '.
14282: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14283: #
14284: # Open all assignments
14285: #
14286: if ($args->{'openall'}) {
14287: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
14288: my %storecontent = ($storeunder => time,
14289: $storeunder.'.type' => 'date_start');
14290:
14291: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 14292: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 14293: }
14294: #
14295: # Set first page
14296: #
14297: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
14298: || ($cloneid)) {
1.445 albertel 14299: use LONCAPA::map;
1.444 albertel 14300: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 14301:
14302: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
14303: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
14304:
1.444 albertel 14305: $outcome .= ($fatal?$errtext:'read ok').' - ';
14306: my $title; my $url;
14307: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 14308: $title=&mt('Syllabus');
1.444 albertel 14309: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
14310: } else {
1.963 raeburn 14311: $title=&mt('Table of Contents');
1.444 albertel 14312: $url='/adm/navmaps';
14313: }
1.445 albertel 14314:
14315: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
14316: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
14317:
14318: if ($errtext) { $fatal=2; }
1.541 raeburn 14319: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 14320: }
1.566 albertel 14321:
14322: return (1,$outcome);
1.444 albertel 14323: }
14324:
1.1166 raeburn 14325: sub make_unique_code {
14326: my ($cdom,$cnum) = @_;
14327: # get lock on uniquecodes db
14328: my $lockhash = {
14329: $cnum."\0".'uniquecodes' => $env{'user.name'}.
14330: ':'.$env{'user.domain'},
14331: };
14332: my $tries = 0;
14333: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14334: my ($code,$error);
14335:
14336: while (($gotlock ne 'ok') && ($tries<3)) {
14337: $tries ++;
14338: sleep 1;
14339: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
14340: }
14341: if ($gotlock eq 'ok') {
14342: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
14343: my $gotcode;
14344: my $attempts = 0;
14345: while ((!$gotcode) && ($attempts < 100)) {
14346: $code = &generate_code();
14347: if (!exists($currcodes{$code})) {
14348: $gotcode = 1;
14349: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
14350: $error = 'nostore';
14351: }
14352: }
14353: $attempts ++;
14354: }
14355: my @del_lock = ($cnum."\0".'uniquecodes');
14356: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
14357: } else {
14358: $error = 'nolock';
14359: }
14360: return ($code,$error);
14361: }
14362:
14363: sub generate_code {
14364: my $code;
14365: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
14366: for (my $i=0; $i<6; $i++) {
14367: my $lettnum = int (rand 2);
14368: my $item = '';
14369: if ($lettnum) {
14370: $item = $letts[int( rand(18) )];
14371: } else {
14372: $item = 1+int( rand(8) );
14373: }
14374: $code .= $item;
14375: }
14376: return $code;
14377: }
14378:
1.444 albertel 14379: ############################################################
14380: ############################################################
14381:
1.953 droeschl 14382: #SD
14383: # only Community and Course, or anything else?
1.378 raeburn 14384: sub course_type {
14385: my ($cid) = @_;
14386: if (!defined($cid)) {
14387: $cid = $env{'request.course.id'};
14388: }
1.404 albertel 14389: if (defined($env{'course.'.$cid.'.type'})) {
14390: return $env{'course.'.$cid.'.type'};
1.378 raeburn 14391: } else {
14392: return 'Course';
1.377 raeburn 14393: }
14394: }
1.156 albertel 14395:
1.406 raeburn 14396: sub group_term {
14397: my $crstype = &course_type();
14398: my %names = (
14399: 'Course' => 'group',
1.865 raeburn 14400: 'Community' => 'group',
1.406 raeburn 14401: );
14402: return $names{$crstype};
14403: }
14404:
1.902 raeburn 14405: sub course_types {
1.1165 raeburn 14406: my @types = ('official','unofficial','community','textbook');
1.902 raeburn 14407: my %typename = (
14408: official => 'Official course',
14409: unofficial => 'Unofficial course',
14410: community => 'Community',
1.1165 raeburn 14411: textbook => 'Textbook course',
1.902 raeburn 14412: );
14413: return (\@types,\%typename);
14414: }
14415:
1.156 albertel 14416: sub icon {
14417: my ($file)=@_;
1.505 albertel 14418: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 14419: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 14420: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 14421: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
14422: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
14423: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14424: $curfext.".gif") {
14425: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
14426: $curfext.".gif";
14427: }
14428: }
1.249 albertel 14429: return &lonhttpdurl($iconname);
1.154 albertel 14430: }
1.84 albertel 14431:
1.575 albertel 14432: sub lonhttpdurl {
1.692 www 14433: #
14434: # Had been used for "small fry" static images on separate port 8080.
14435: # Modify here if lightweight http functionality desired again.
14436: # Currently eliminated due to increasing firewall issues.
14437: #
1.575 albertel 14438: my ($url)=@_;
1.692 www 14439: return $url;
1.215 albertel 14440: }
14441:
1.213 albertel 14442: sub connection_aborted {
14443: my ($r)=@_;
14444: $r->print(" ");$r->rflush();
14445: my $c = $r->connection;
14446: return $c->aborted();
14447: }
14448:
1.221 foxr 14449: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 14450: # strings as 'strings'.
14451: sub escape_single {
1.221 foxr 14452: my ($input) = @_;
1.223 albertel 14453: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 14454: $input =~ s/\'/\\\'/g; # Esacpe the 's....
14455: return $input;
14456: }
1.223 albertel 14457:
1.222 foxr 14458: # Same as escape_single, but escape's "'s This
14459: # can be used for "strings"
14460: sub escape_double {
14461: my ($input) = @_;
14462: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
14463: $input =~ s/\"/\\\"/g; # Esacpe the "s....
14464: return $input;
14465: }
1.223 albertel 14466:
1.222 foxr 14467: # Escapes the last element of a full URL.
14468: sub escape_url {
14469: my ($url) = @_;
1.238 raeburn 14470: my @urlslices = split(/\//, $url,-1);
1.369 www 14471: my $lastitem = &escape(pop(@urlslices));
1.223 albertel 14472: return join('/',@urlslices).'/'.$lastitem;
1.222 foxr 14473: }
1.462 albertel 14474:
1.820 raeburn 14475: sub compare_arrays {
14476: my ($arrayref1,$arrayref2) = @_;
14477: my (@difference,%count);
14478: @difference = ();
14479: %count = ();
14480: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
14481: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
14482: foreach my $element (keys(%count)) {
14483: if ($count{$element} == 1) {
14484: push(@difference,$element);
14485: }
14486: }
14487: }
14488: return @difference;
14489: }
14490:
1.817 bisitz 14491: # -------------------------------------------------------- Initialize user login
1.462 albertel 14492: sub init_user_environment {
1.463 albertel 14493: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 14494: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
14495:
14496: my $public=($username eq 'public' && $domain eq 'public');
14497:
14498: # See if old ID present, if so, remove
14499:
1.1062 raeburn 14500: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 14501: my $now=time;
14502:
14503: if ($public) {
14504: my $max_public=100;
14505: my $oldest;
14506: my $oldest_time=0;
14507: for(my $next=1;$next<=$max_public;$next++) {
14508: if (-e $lonids."/publicuser_$next.id") {
14509: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
14510: if ($mtime<$oldest_time || !$oldest_time) {
14511: $oldest_time=$mtime;
14512: $oldest=$next;
14513: }
14514: } else {
14515: $cookie="publicuser_$next";
14516: last;
14517: }
14518: }
14519: if (!$cookie) { $cookie="publicuser_$oldest"; }
14520: } else {
1.463 albertel 14521: # if this isn't a robot, kill any existing non-robot sessions
14522: if (!$args->{'robot'}) {
14523: opendir(DIR,$lonids);
14524: while ($filename=readdir(DIR)) {
14525: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
14526: unlink($lonids.'/'.$filename);
14527: }
1.462 albertel 14528: }
1.463 albertel 14529: closedir(DIR);
1.462 albertel 14530: }
14531: # Give them a new cookie
1.463 albertel 14532: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 14533: : $now.$$.int(rand(10000)));
1.463 albertel 14534: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 14535:
14536: # Initialize roles
14537:
1.1062 raeburn 14538: ($userroles,$firstaccenv,$timerintenv) =
14539: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 14540: }
14541: # ------------------------------------ Check browser type and MathML capability
14542:
1.1194 raeburn 14543: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
14544: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 14545:
14546: # ------------------------------------------------------------- Get environment
14547:
14548: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
14549: my ($tmp) = keys(%userenv);
14550: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
14551: } else {
14552: undef(%userenv);
14553: }
14554: if (($userenv{'interface'}) && (!$form->{'interface'})) {
14555: $form->{'interface'}=$userenv{'interface'};
14556: }
14557: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
14558:
14559: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 14560: foreach my $option ('interface','localpath','localres') {
14561: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 14562: }
14563: # --------------------------------------------------------- Write first profile
14564:
14565: {
14566: my %initial_env =
14567: ("user.name" => $username,
14568: "user.domain" => $domain,
14569: "user.home" => $authhost,
14570: "browser.type" => $clientbrowser,
14571: "browser.version" => $clientversion,
14572: "browser.mathml" => $clientmathml,
14573: "browser.unicode" => $clientunicode,
14574: "browser.os" => $clientos,
1.1137 raeburn 14575: "browser.mobile" => $clientmobile,
1.1141 raeburn 14576: "browser.info" => $clientinfo,
1.1194 raeburn 14577: "browser.osversion" => $clientosversion,
1.462 albertel 14578: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
14579: "request.course.fn" => '',
14580: "request.course.uri" => '',
14581: "request.course.sec" => '',
14582: "request.role" => 'cm',
14583: "request.role.adv" => $env{'user.adv'},
14584: "request.host" => $ENV{'REMOTE_ADDR'},);
14585:
14586: if ($form->{'localpath'}) {
14587: $initial_env{"browser.localpath"} = $form->{'localpath'};
14588: $initial_env{"browser.localres"} = $form->{'localres'};
14589: }
14590:
14591: if ($form->{'interface'}) {
14592: $form->{'interface'}=~s/\W//gs;
14593: $initial_env{"browser.interface"} = $form->{'interface'};
14594: $env{'browser.interface'}=$form->{'interface'};
14595: }
14596:
1.1157 raeburn 14597: if ($form->{'iptoken'}) {
14598: my $lonhost = $r->dir_config('lonHostID');
14599: $initial_env{"user.noloadbalance"} = $lonhost;
14600: $env{'user.noloadbalance'} = $lonhost;
14601: }
14602:
1.981 raeburn 14603: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 14604: my %domdef;
14605: unless ($domain eq 'public') {
14606: %domdef = &Apache::lonnet::get_domain_defaults($domain);
14607: }
1.980 raeburn 14608:
1.1081 raeburn 14609: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 14610: $userenv{'availabletools.'.$tool} =
1.980 raeburn 14611: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
14612: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 14613: }
14614:
1.1165 raeburn 14615: foreach my $crstype ('official','unofficial','community','textbook') {
1.765 raeburn 14616: $userenv{'canrequest.'.$crstype} =
14617: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 14618: 'reload','requestcourses',
14619: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 14620: }
14621:
1.1092 raeburn 14622: $userenv{'canrequest.author'} =
14623: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
14624: 'reload','requestauthor',
14625: \%userenv,\%domdef,\%is_adv);
14626: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
14627: $domain,$username);
14628: my $reqstatus = $reqauthor{'author_status'};
14629: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
14630: if (ref($reqauthor{'author'}) eq 'HASH') {
14631: $userenv{'requestauthorqueued'} = $reqstatus.':'.
14632: $reqauthor{'author'}{'timestamp'};
14633: }
14634: }
14635:
1.462 albertel 14636: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 14637:
1.462 albertel 14638: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
14639: &GDBM_WRCREAT(),0640)) {
14640: &_add_to_env(\%disk_env,\%initial_env);
14641: &_add_to_env(\%disk_env,\%userenv,'environment.');
14642: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 14643: if (ref($firstaccenv) eq 'HASH') {
14644: &_add_to_env(\%disk_env,$firstaccenv);
14645: }
14646: if (ref($timerintenv) eq 'HASH') {
14647: &_add_to_env(\%disk_env,$timerintenv);
14648: }
1.463 albertel 14649: if (ref($args->{'extra_env'})) {
14650: &_add_to_env(\%disk_env,$args->{'extra_env'});
14651: }
1.462 albertel 14652: untie(%disk_env);
14653: } else {
1.705 tempelho 14654: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
14655: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 14656: return 'error: '.$!;
14657: }
14658: }
14659: $env{'request.role'}='cm';
14660: $env{'request.role.adv'}=$env{'user.adv'};
14661: $env{'browser.type'}=$clientbrowser;
14662:
14663: return $cookie;
14664:
14665: }
14666:
14667: sub _add_to_env {
14668: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 14669: if (ref($env_data) eq 'HASH') {
14670: while (my ($key,$value) = each(%$env_data)) {
14671: $idf->{$prefix.$key} = $value;
14672: $env{$prefix.$key} = $value;
14673: }
1.462 albertel 14674: }
14675: }
14676:
1.685 tempelho 14677: # --- Get the symbolic name of a problem and the url
14678: sub get_symb {
14679: my ($request,$silent) = @_;
1.726 raeburn 14680: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 14681: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
14682: if ($symb eq '') {
14683: if (!$silent) {
1.1071 raeburn 14684: if (ref($request)) {
14685: $request->print("Unable to handle ambiguous references:$url:.");
14686: }
1.685 tempelho 14687: return ();
14688: }
14689: }
14690: &Apache::lonenc::check_decrypt(\$symb);
14691: return ($symb);
14692: }
14693:
14694: # --------------------------------------------------------------Get annotation
14695:
14696: sub get_annotation {
14697: my ($symb,$enc) = @_;
14698:
14699: my $key = $symb;
14700: if (!$enc) {
14701: $key =
14702: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
14703: }
14704: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
14705: return $annotation{$key};
14706: }
14707:
14708: sub clean_symb {
1.731 raeburn 14709: my ($symb,$delete_enc) = @_;
1.685 tempelho 14710:
14711: &Apache::lonenc::check_decrypt(\$symb);
14712: my $enc = $env{'request.enc'};
1.731 raeburn 14713: if ($delete_enc) {
1.730 raeburn 14714: delete($env{'request.enc'});
14715: }
1.685 tempelho 14716:
14717: return ($symb,$enc);
14718: }
1.462 albertel 14719:
1.1181 raeburn 14720: ############################################################
14721: ############################################################
14722:
14723: =pod
14724:
14725: =head1 Routines for building display used to search for courses
14726:
14727:
14728: =over 4
14729:
14730: =item * &build_filters()
14731:
14732: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 14733: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
14734: and quotacheck.pl
14735:
1.1181 raeburn 14736:
14737: Inputs:
14738:
14739: filterlist - anonymous array of fields to include as potential filters
14740:
14741: crstype - course type
14742:
14743: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
14744: to pop-open a course selector (will contain "extra element").
14745:
14746: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
14747:
14748: filter - anonymous hash of criteria and their values
14749:
14750: action - form action
14751:
14752: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
14753:
1.1182 raeburn 14754: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 14755:
14756: cloneruname - username of owner of new course who wants to clone
14757:
14758: clonerudom - domain of owner of new course who wants to clone
14759:
14760: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
14761:
14762: codetitlesref - reference to array of titles of components in institutional codes (official courses)
14763:
14764: codedom - domain
14765:
14766: formname - value of form element named "form".
14767:
14768: fixeddom - domain, if fixed.
14769:
14770: prevphase - value to assign to form element named "phase" when going back to the previous screen
14771:
14772: cnameelement - name of form element in form on opener page which will receive title of selected course
14773:
14774: cnumelement - name of form element in form on opener page which will receive courseID of selected course
14775:
14776: cdomelement - name of form element in form on opener page which will receive domain of selected course
14777:
14778: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
14779:
14780: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
14781:
14782: clonewarning - warning message about missing information for intended course owner when DC creates a course
14783:
1.1182 raeburn 14784:
1.1181 raeburn 14785: Returns: $output - HTML for display of search criteria, and hidden form elements.
14786:
1.1182 raeburn 14787:
1.1181 raeburn 14788: Side Effects: None
14789:
14790: =cut
14791:
14792: # ---------------------------------------------- search for courses based on last activity etc.
14793:
14794: sub build_filters {
14795: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
14796: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
14797: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
14798: $cnameelement,$cnumelement,$cdomelement,$setroles,
14799: $clonetext,$clonewarning) = @_;
1.1182 raeburn 14800: my ($list,$jscript);
1.1181 raeburn 14801: my $onchange = 'javascript:updateFilters(this)';
14802: my ($domainselectform,$sincefilterform,$createdfilterform,
14803: $ownerdomselectform,$persondomselectform,$instcodeform,
14804: $typeselectform,$instcodetitle);
14805: if ($formname eq '') {
14806: $formname = $caller;
14807: }
14808: foreach my $item (@{$filterlist}) {
14809: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
14810: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
14811: if ($item eq 'domainfilter') {
14812: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
14813: } elsif ($item eq 'coursefilter') {
14814: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
14815: } elsif ($item eq 'ownerfilter') {
14816: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
14817: } elsif ($item eq 'ownerdomfilter') {
14818: $filter->{'ownerdomfilter'} =
14819: &LONCAPA::clean_domain($filter->{$item});
14820: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
14821: 'ownerdomfilter',1);
14822: } elsif ($item eq 'personfilter') {
14823: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
14824: } elsif ($item eq 'persondomfilter') {
14825: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
14826: 'persondomfilter',1);
14827: } else {
14828: $filter->{$item} =~ s/\W//g;
14829: }
14830: if (!$filter->{$item}) {
14831: $filter->{$item} = '';
14832: }
14833: }
14834: if ($item eq 'domainfilter') {
14835: my $allow_blank = 1;
14836: if ($formname eq 'portform') {
14837: $allow_blank=0;
14838: } elsif ($formname eq 'studentform') {
14839: $allow_blank=0;
14840: }
14841: if ($fixeddom) {
14842: $domainselectform = '<input type="hidden" name="domainfilter"'.
14843: ' value="'.$codedom.'" />'.
14844: &Apache::lonnet::domain($codedom,'description');
14845: } else {
14846: $domainselectform = &select_dom_form($filter->{$item},
14847: 'domainfilter',
14848: $allow_blank,'',$onchange);
14849: }
14850: } else {
14851: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
14852: }
14853: }
14854:
14855: # last course activity filter and selection
14856: $sincefilterform = &timebased_select_form('sincefilter',$filter);
14857:
14858: # course created filter and selection
14859: if (exists($filter->{'createdfilter'})) {
14860: $createdfilterform = &timebased_select_form('createdfilter',$filter);
14861: }
14862:
14863: my %lt = &Apache::lonlocal::texthash(
14864: 'cac' => "$crstype Activity",
14865: 'ccr' => "$crstype Created",
14866: 'cde' => "$crstype Title",
14867: 'cdo' => "$crstype Domain",
14868: 'ins' => 'Institutional Code',
14869: 'inc' => 'Institutional Categorization',
14870: 'cow' => "$crstype Owner/Co-owner",
14871: 'cop' => "$crstype Personnel Includes",
14872: 'cog' => 'Type',
14873: );
14874:
14875: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
14876: my $typeval = 'Course';
14877: if ($crstype eq 'Community') {
14878: $typeval = 'Community';
14879: }
14880: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
14881: } else {
14882: $typeselectform = '<select name="type" size="1"';
14883: if ($onchange) {
14884: $typeselectform .= ' onchange="'.$onchange.'"';
14885: }
14886: $typeselectform .= '>'."\n";
14887: foreach my $posstype ('Course','Community') {
14888: $typeselectform.='<option value="'.$posstype.'"'.
14889: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".&mt($posstype)."</option>\n";
14890: }
14891: $typeselectform.="</select>";
14892: }
14893:
14894: my ($cloneableonlyform,$cloneabletitle);
14895: if (exists($filter->{'cloneableonly'})) {
14896: my $cloneableon = '';
14897: my $cloneableoff = ' checked="checked"';
14898: if ($filter->{'cloneableonly'}) {
14899: $cloneableon = $cloneableoff;
14900: $cloneableoff = '';
14901: }
14902: $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>';
14903: if ($formname eq 'ccrs') {
1.1187 bisitz 14904: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 14905: } else {
14906: $cloneabletitle = &mt('Cloneable by you');
14907: }
14908: }
14909: my $officialjs;
14910: if ($crstype eq 'Course') {
14911: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 14912: # if (($fixeddom) || ($formname eq 'requestcrs') ||
14913: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
14914: if ($codedom) {
1.1181 raeburn 14915: $officialjs = 1;
14916: ($instcodeform,$jscript,$$numtitlesref) =
14917: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
14918: $officialjs,$codetitlesref);
14919: if ($jscript) {
1.1182 raeburn 14920: $jscript = '<script type="text/javascript">'."\n".
14921: '// <![CDATA['."\n".
14922: $jscript."\n".
14923: '// ]]>'."\n".
14924: '</script>'."\n";
1.1181 raeburn 14925: }
14926: }
14927: if ($instcodeform eq '') {
14928: $instcodeform =
14929: '<input type="text" name="instcodefilter" size="10" value="'.
14930: $list->{'instcodefilter'}.'" />';
14931: $instcodetitle = $lt{'ins'};
14932: } else {
14933: $instcodetitle = $lt{'inc'};
14934: }
14935: if ($fixeddom) {
14936: $instcodetitle .= '<br />('.$codedom.')';
14937: }
14938: }
14939: }
14940: my $output = qq|
14941: <form method="post" name="filterpicker" action="$action">
14942: <input type="hidden" name="form" value="$formname" />
14943: |;
14944: if ($formname eq 'modifycourse') {
14945: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
14946: '<input type="hidden" name="prevphase" value="'.
14947: $prevphase.'" />'."\n";
1.1182 raeburn 14948: } elsif ($formname ne 'quotacheck') {
1.1181 raeburn 14949: my $name_input;
14950: if ($cnameelement ne '') {
14951: $name_input = '<input type="hidden" name="cnameelement" value="'.
14952: $cnameelement.'" />';
14953: }
14954: $output .= qq|
1.1182 raeburn 14955: <input type="hidden" name="cnumelement" value="$cnumelement" />
14956: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 14957: $name_input
14958: $roleelement
14959: $multelement
14960: $typeelement
14961: |;
14962: if ($formname eq 'portform') {
14963: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
14964: }
14965: }
14966: if ($fixeddom) {
14967: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
14968: }
14969: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
14970: if ($sincefilterform) {
14971: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
14972: .$sincefilterform
14973: .&Apache::lonhtmlcommon::row_closure();
14974: }
14975: if ($createdfilterform) {
14976: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
14977: .$createdfilterform
14978: .&Apache::lonhtmlcommon::row_closure();
14979: }
14980: if ($domainselectform) {
14981: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
14982: .$domainselectform
14983: .&Apache::lonhtmlcommon::row_closure();
14984: }
14985: if ($typeselectform) {
14986: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
14987: $output .= $typeselectform;
14988: } else {
14989: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
14990: .$typeselectform
14991: .&Apache::lonhtmlcommon::row_closure();
14992: }
14993: }
14994: if ($instcodeform) {
14995: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
14996: .$instcodeform
14997: .&Apache::lonhtmlcommon::row_closure();
14998: }
14999: if (exists($filter->{'ownerfilter'})) {
15000: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
15001: '<table><tr><td>'.&mt('Username').'<br />'.
15002: '<input type="text" name="ownerfilter" size="20" value="'.
15003: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15004: $ownerdomselectform.'</td></tr></table>'.
15005: &Apache::lonhtmlcommon::row_closure();
15006: }
15007: if (exists($filter->{'personfilter'})) {
15008: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
15009: '<table><tr><td>'.&mt('Username').'<br />'.
15010: '<input type="text" name="personfilter" size="20" value="'.
15011: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15012: $persondomselectform.'</td></tr></table>'.
15013: &Apache::lonhtmlcommon::row_closure();
15014: }
15015: if (exists($filter->{'coursefilter'})) {
15016: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
15017: .'<input type="text" name="coursefilter" size="25" value="'
15018: .$list->{'coursefilter'}.'" />'
15019: .&Apache::lonhtmlcommon::row_closure();
15020: }
15021: if ($cloneableonlyform) {
15022: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
15023: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
15024: }
15025: if (exists($filter->{'descriptfilter'})) {
15026: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
15027: .'<input type="text" name="descriptfilter" size="40" value="'
15028: .$list->{'descriptfilter'}.'" />'
15029: .&Apache::lonhtmlcommon::row_closure(1);
15030: }
15031: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
15032: '<input type="hidden" name="updater" value="" />'."\n".
15033: '<input type="submit" name="gosearch" value="'.
15034: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
15035: return $jscript.$clonewarning.$output;
15036: }
15037:
15038: =pod
15039:
15040: =item * &timebased_select_form()
15041:
1.1182 raeburn 15042: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 15043: filter e.g., Course Activity, Course Created, when searching for courses
15044: or communities
15045:
15046: Inputs:
15047:
15048: item - name of form element (sincefilter or createdfilter)
15049:
15050: filter - anonymous hash of criteria and their values
15051:
15052: Returns: HTML for a select box contained a blank, then six time selections,
15053: with value set in incoming form variables currently selected.
15054:
15055: Side Effects: None
15056:
15057: =cut
15058:
15059: sub timebased_select_form {
15060: my ($item,$filter) = @_;
15061: if (ref($filter) eq 'HASH') {
15062: $filter->{$item} =~ s/[^\d-]//g;
15063: if (!$filter->{$item}) { $filter->{$item}=-1; }
15064: return &select_form(
15065: $filter->{$item},
15066: $item,
15067: { '-1' => '',
15068: '86400' => &mt('today'),
15069: '604800' => &mt('last week'),
15070: '2592000' => &mt('last month'),
15071: '7776000' => &mt('last three months'),
15072: '15552000' => &mt('last six months'),
15073: '31104000' => &mt('last year'),
15074: 'select_form_order' =>
15075: ['-1','86400','604800','2592000','7776000',
15076: '15552000','31104000']});
15077: }
15078: }
15079:
15080: =pod
15081:
15082: =item * &js_changer()
15083:
15084: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 15085: when course type or domain is changed, and also to hide 'Searching ...' on
15086: page load completion for page showing search result.
1.1181 raeburn 15087:
15088: Inputs: None
15089:
1.1183 raeburn 15090: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 15091:
15092: Side Effects: None
15093:
15094: =cut
15095:
15096: sub js_changer {
15097: return <<ENDJS;
15098: <script type="text/javascript">
15099: // <![CDATA[
15100: function updateFilters(caller) {
15101: if (typeof(caller) != "undefined") {
15102: document.filterpicker.updater.value = caller.name;
15103: }
15104: document.filterpicker.submit();
15105: }
1.1183 raeburn 15106:
15107: function hideSearching() {
15108: if (document.getElementById('searching')) {
15109: document.getElementById('searching').style.display = 'none';
15110: }
15111: return;
15112: }
15113:
1.1181 raeburn 15114: // ]]>
15115: </script>
15116:
15117: ENDJS
15118: }
15119:
15120: =pod
15121:
1.1182 raeburn 15122: =item * &search_courses()
15123:
15124: Process selected filters form course search form and pass to lonnet::courseiddump
15125: to retrieve a hash for which keys are courseIDs which match the selected filters.
15126:
15127: Inputs:
15128:
15129: dom - domain being searched
15130:
15131: type - course type ('Course' or 'Community' or '.' if any).
15132:
15133: filter - anonymous hash of criteria and their values
15134:
15135: numtitles - for institutional codes - number of categories
15136:
15137: cloneruname - optional username of new course owner
15138:
15139: clonerudom - optional domain of new course owner
15140:
15141: domcloner - Optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
15142: (used when DC is using course creation form)
15143:
15144: codetitles - reference to array of titles of components in institutional codes (official courses).
15145:
15146:
15147: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
15148:
15149:
15150: Side Effects: None
15151:
15152: =cut
15153:
15154:
15155: sub search_courses {
15156: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles) = @_;
15157: my (%courses,%showcourses,$cloner);
15158: if (($filter->{'ownerfilter'} ne '') ||
15159: ($filter->{'ownerdomfilter'} ne '')) {
15160: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
15161: $filter->{'ownerdomfilter'};
15162: }
15163: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
15164: if (!$filter->{$item}) {
15165: $filter->{$item}='.';
15166: }
15167: }
15168: my $now = time;
15169: my $timefilter =
15170: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
15171: my ($createdbefore,$createdafter);
15172: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
15173: $createdbefore = $now;
15174: $createdafter = $now-$filter->{'createdfilter'};
15175: }
15176: my ($instcodefilter,$regexpok);
15177: if ($numtitles) {
15178: if ($env{'form.official'} eq 'on') {
15179: $instcodefilter =
15180: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15181: $regexpok = 1;
15182: } elsif ($env{'form.official'} eq 'off') {
15183: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
15184: unless ($instcodefilter eq '') {
15185: $regexpok = -1;
15186: }
15187: }
15188: } else {
15189: $instcodefilter = $filter->{'instcodefilter'};
15190: }
15191: if ($instcodefilter eq '') { $instcodefilter = '.'; }
15192: if ($type eq '') { $type = '.'; }
15193:
15194: if (($clonerudom ne '') && ($cloneruname ne '')) {
15195: $cloner = $cloneruname.':'.$clonerudom;
15196: }
15197: %courses = &Apache::lonnet::courseiddump($dom,
15198: $filter->{'descriptfilter'},
15199: $timefilter,
15200: $instcodefilter,
15201: $filter->{'combownerfilter'},
15202: $filter->{'coursefilter'},
15203: undef,undef,$type,$regexpok,undef,undef,
15204: undef,undef,$cloner,$env{'form.cc_clone'},
15205: $filter->{'cloneableonly'},
15206: $createdbefore,$createdafter,undef,
15207: $domcloner);
15208: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
15209: my $ccrole;
15210: if ($type eq 'Community') {
15211: $ccrole = 'co';
15212: } else {
15213: $ccrole = 'cc';
15214: }
15215: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
15216: $filter->{'persondomfilter'},
15217: 'userroles',undef,
15218: [$ccrole,'in','ad','ep','ta','cr'],
15219: $dom);
15220: foreach my $role (keys(%rolehash)) {
15221: my ($cnum,$cdom,$courserole) = split(':',$role);
15222: my $cid = $cdom.'_'.$cnum;
15223: if (exists($courses{$cid})) {
15224: if (ref($courses{$cid}) eq 'HASH') {
15225: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
15226: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
15227: push (@{$courses{$cid}{roles}},$courserole);
15228: }
15229: } else {
15230: $courses{$cid}{roles} = [$courserole];
15231: }
15232: $showcourses{$cid} = $courses{$cid};
15233: }
15234: }
15235: }
15236: %courses = %showcourses;
15237: }
15238: return %courses;
15239: }
15240:
15241:
15242: =pod
15243:
1.1181 raeburn 15244: =back
15245:
15246: =cut
15247:
15248:
1.1083 raeburn 15249: sub update_content_constraints {
15250: my ($cdom,$cnum,$chome,$cid) = @_;
15251: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
15252: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
15253: my %checkresponsetypes;
15254: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
15255: my ($item,$name,$value) = split(/:/,$key);
15256: if ($item eq 'resourcetag') {
15257: if ($name eq 'responsetype') {
15258: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
15259: }
15260: }
15261: }
15262: my $navmap = Apache::lonnavmaps::navmap->new();
15263: if (defined($navmap)) {
15264: my %allresponses;
15265: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
15266: my %responses = $res->responseTypes();
15267: foreach my $key (keys(%responses)) {
15268: next unless(exists($checkresponsetypes{$key}));
15269: $allresponses{$key} += $responses{$key};
15270: }
15271: }
15272: foreach my $key (keys(%allresponses)) {
15273: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
15274: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
15275: ($reqdmajor,$reqdminor) = ($major,$minor);
15276: }
15277: }
15278: undef($navmap);
15279: }
15280: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
15281: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
15282: }
15283: return;
15284: }
15285:
1.1110 raeburn 15286: sub allmaps_incourse {
15287: my ($cdom,$cnum,$chome,$cid) = @_;
15288: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
15289: $cid = $env{'request.course.id'};
15290: $cdom = $env{'course.'.$cid.'.domain'};
15291: $cnum = $env{'course.'.$cid.'.num'};
15292: $chome = $env{'course.'.$cid.'.home'};
15293: }
15294: my %allmaps = ();
15295: my $lastchange =
15296: &Apache::lonnet::get_coursechange($cdom,$cnum);
15297: if ($lastchange > $env{'request.course.tied'}) {
15298: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
15299: unless ($ferr) {
15300: &update_content_constraints($cdom,$cnum,$chome,$cid);
15301: }
15302: }
15303: my $navmap = Apache::lonnavmaps::navmap->new();
15304: if (defined($navmap)) {
15305: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
15306: $allmaps{$res->src()} = 1;
15307: }
15308: }
15309: return \%allmaps;
15310: }
15311:
1.1083 raeburn 15312: sub parse_supplemental_title {
15313: my ($title) = @_;
15314:
15315: my ($foldertitle,$renametitle);
15316: if ($title =~ /&&&/) {
15317: $title = &HTML::Entites::decode($title);
15318: }
15319: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
15320: $renametitle=$4;
15321: my ($time,$uname,$udom) = ($1,$2,$3);
15322: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
15323: my $name = &plainname($uname,$udom);
15324: $name = &HTML::Entities::encode($name,'"<>&\'');
15325: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
15326: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
15327: $name.': <br />'.$foldertitle;
15328: }
15329: if (wantarray) {
15330: return ($title,$foldertitle,$renametitle);
15331: }
15332: return $title;
15333: }
15334:
1.1143 raeburn 15335: sub recurse_supplemental {
15336: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
15337: if ($suppmap) {
15338: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
15339: if ($fatal) {
15340: $errors ++;
15341: } else {
15342: if ($#LONCAPA::map::resources > 0) {
15343: foreach my $res (@LONCAPA::map::resources) {
15344: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
15345: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 15346: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
15347: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1143 raeburn 15348: } else {
15349: $numfiles ++;
15350: }
15351: }
15352: }
15353: }
15354: }
15355: }
15356: return ($numfiles,$errors);
15357: }
15358:
1.1101 raeburn 15359: sub symb_to_docspath {
15360: my ($symb) = @_;
15361: return unless ($symb);
15362: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
15363: if ($resurl=~/\.(sequence|page)$/) {
15364: $mapurl=$resurl;
15365: } elsif ($resurl eq 'adm/navmaps') {
15366: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
15367: }
15368: my $mapresobj;
15369: my $navmap = Apache::lonnavmaps::navmap->new();
15370: if (ref($navmap)) {
15371: $mapresobj = $navmap->getResourceByUrl($mapurl);
15372: }
15373: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
15374: my $type=$2;
15375: my $path;
15376: if (ref($mapresobj)) {
15377: my $pcslist = $mapresobj->map_hierarchy();
15378: if ($pcslist ne '') {
15379: foreach my $pc (split(/,/,$pcslist)) {
15380: next if ($pc <= 1);
15381: my $res = $navmap->getByMapPc($pc);
15382: if (ref($res)) {
15383: my $thisurl = $res->src();
15384: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
15385: my $thistitle = $res->title();
15386: $path .= '&'.
15387: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 15388: &escape($thistitle).
1.1101 raeburn 15389: ':'.$res->randompick().
15390: ':'.$res->randomout().
15391: ':'.$res->encrypted().
15392: ':'.$res->randomorder().
15393: ':'.$res->is_page();
15394: }
15395: }
15396: }
15397: $path =~ s/^\&//;
15398: my $maptitle = $mapresobj->title();
15399: if ($mapurl eq 'default') {
1.1129 raeburn 15400: $maptitle = 'Main Content';
1.1101 raeburn 15401: }
15402: $path .= (($path ne '')? '&' : '').
15403: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 15404: &escape($maptitle).
1.1101 raeburn 15405: ':'.$mapresobj->randompick().
15406: ':'.$mapresobj->randomout().
15407: ':'.$mapresobj->encrypted().
15408: ':'.$mapresobj->randomorder().
15409: ':'.$mapresobj->is_page();
15410: } else {
15411: my $maptitle = &Apache::lonnet::gettitle($mapurl);
15412: my $ispage = (($type eq 'page')? 1 : '');
15413: if ($mapurl eq 'default') {
1.1129 raeburn 15414: $maptitle = 'Main Content';
1.1101 raeburn 15415: }
15416: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 15417: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 15418: }
15419: unless ($mapurl eq 'default') {
15420: $path = 'default&'.
1.1146 raeburn 15421: &escape('Main Content').
1.1101 raeburn 15422: ':::::&'.$path;
15423: }
15424: return $path;
15425: }
15426:
1.1094 raeburn 15427: sub captcha_display {
15428: my ($context,$lonhost) = @_;
15429: my ($output,$error);
15430: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 15431: if ($captcha eq 'original') {
1.1094 raeburn 15432: $output = &create_captcha();
15433: unless ($output) {
1.1172 raeburn 15434: $error = 'captcha';
1.1094 raeburn 15435: }
15436: } elsif ($captcha eq 'recaptcha') {
15437: $output = &create_recaptcha($pubkey);
15438: unless ($output) {
1.1172 raeburn 15439: $error = 'recaptcha';
1.1094 raeburn 15440: }
15441: }
1.1176 raeburn 15442: return ($output,$error,$captcha);
1.1094 raeburn 15443: }
15444:
15445: sub captcha_response {
15446: my ($context,$lonhost) = @_;
15447: my ($captcha_chk,$captcha_error);
15448: my ($captcha,$pubkey,$privkey) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 15449: if ($captcha eq 'original') {
1.1094 raeburn 15450: ($captcha_chk,$captcha_error) = &check_captcha();
15451: } elsif ($captcha eq 'recaptcha') {
15452: $captcha_chk = &check_recaptcha($privkey);
15453: } else {
15454: $captcha_chk = 1;
15455: }
15456: return ($captcha_chk,$captcha_error);
15457: }
15458:
15459: sub get_captcha_config {
15460: my ($context,$lonhost) = @_;
1.1095 raeburn 15461: my ($captcha,$pubkey,$privkey,$hashtocheck);
1.1094 raeburn 15462: my $hostname = &Apache::lonnet::hostname($lonhost);
15463: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
15464: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 15465: if ($context eq 'usercreation') {
15466: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
15467: if (ref($domconfig{$context}) eq 'HASH') {
15468: $hashtocheck = $domconfig{$context}{'cancreate'};
15469: if (ref($hashtocheck) eq 'HASH') {
15470: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
15471: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
15472: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
15473: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
15474: }
15475: if ($privkey && $pubkey) {
15476: $captcha = 'recaptcha';
15477: } else {
15478: $captcha = 'original';
15479: }
15480: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
15481: $captcha = 'original';
15482: }
1.1094 raeburn 15483: }
1.1095 raeburn 15484: } else {
15485: $captcha = 'captcha';
15486: }
15487: } elsif ($context eq 'login') {
15488: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
15489: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
15490: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
15491: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 15492: if ($privkey && $pubkey) {
15493: $captcha = 'recaptcha';
1.1095 raeburn 15494: } else {
15495: $captcha = 'original';
1.1094 raeburn 15496: }
1.1095 raeburn 15497: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
15498: $captcha = 'original';
1.1094 raeburn 15499: }
15500: }
15501: return ($captcha,$pubkey,$privkey);
15502: }
15503:
15504: sub create_captcha {
15505: my %captcha_params = &captcha_settings();
15506: my ($output,$maxtries,$tries) = ('',10,0);
15507: while ($tries < $maxtries) {
15508: $tries ++;
15509: my $captcha = Authen::Captcha->new (
15510: output_folder => $captcha_params{'output_dir'},
15511: data_folder => $captcha_params{'db_dir'},
15512: );
15513: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
15514:
15515: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
15516: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
15517: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 15518: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
15519: '<br />'.
15520: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 15521: last;
15522: }
15523: }
15524: return $output;
15525: }
15526:
15527: sub captcha_settings {
15528: my %captcha_params = (
15529: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
15530: www_output_dir => "/captchaspool",
15531: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
15532: numchars => '5',
15533: );
15534: return %captcha_params;
15535: }
15536:
15537: sub check_captcha {
15538: my ($captcha_chk,$captcha_error);
15539: my $code = $env{'form.code'};
15540: my $md5sum = $env{'form.crypt'};
15541: my %captcha_params = &captcha_settings();
15542: my $captcha = Authen::Captcha->new(
15543: output_folder => $captcha_params{'output_dir'},
15544: data_folder => $captcha_params{'db_dir'},
15545: );
1.1109 raeburn 15546: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 15547: my %captcha_hash = (
15548: 0 => 'Code not checked (file error)',
15549: -1 => 'Failed: code expired',
15550: -2 => 'Failed: invalid code (not in database)',
15551: -3 => 'Failed: invalid code (code does not match crypt)',
15552: );
15553: if ($captcha_chk != 1) {
15554: $captcha_error = $captcha_hash{$captcha_chk}
15555: }
15556: return ($captcha_chk,$captcha_error);
15557: }
15558:
15559: sub create_recaptcha {
15560: my ($pubkey) = @_;
1.1153 raeburn 15561: my $use_ssl;
15562: if ($ENV{'SERVER_PORT'} == 443) {
15563: $use_ssl = 1;
15564: }
1.1094 raeburn 15565: my $captcha = Captcha::reCAPTCHA->new;
15566: return $captcha->get_options_setter({theme => 'white'})."\n".
1.1153 raeburn 15567: $captcha->get_html($pubkey,undef,$use_ssl).
1.1094 raeburn 15568: &mt('If either word is hard to read, [_1] will replace them.',
1.1133 raeburn 15569: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
1.1094 raeburn 15570: '<br /><br />';
15571: }
15572:
15573: sub check_recaptcha {
15574: my ($privkey) = @_;
15575: my $captcha_chk;
15576: my $captcha = Captcha::reCAPTCHA->new;
15577: my $captcha_result =
15578: $captcha->check_answer(
15579: $privkey,
15580: $ENV{'REMOTE_ADDR'},
15581: $env{'form.recaptcha_challenge_field'},
15582: $env{'form.recaptcha_response_field'},
15583: );
15584: if ($captcha_result->{is_valid}) {
15585: $captcha_chk = 1;
15586: }
15587: return $captcha_chk;
15588: }
15589:
1.1174 raeburn 15590: sub emailusername_info {
1.1177 raeburn 15591: my @fields = ('firstname','lastname','institution','web','location','officialemail');
1.1174 raeburn 15592: my %titles = &Apache::lonlocal::texthash (
15593: lastname => 'Last Name',
15594: firstname => 'First Name',
15595: institution => 'School/college/university',
15596: location => "School's city, state/province, country",
15597: web => "School's web address",
15598: officialemail => 'E-mail address at institution (if different)',
15599: );
15600: return (\@fields,\%titles);
15601: }
15602:
1.1161 raeburn 15603: sub cleanup_html {
15604: my ($incoming) = @_;
15605: my $outgoing;
15606: if ($incoming ne '') {
15607: $outgoing = $incoming;
15608: $outgoing =~ s/;/;/g;
15609: $outgoing =~ s/\#/#/g;
15610: $outgoing =~ s/\&/&/g;
15611: $outgoing =~ s/</</g;
15612: $outgoing =~ s/>/>/g;
15613: $outgoing =~ s/\(/(/g;
15614: $outgoing =~ s/\)/)/g;
15615: $outgoing =~ s/"/"/g;
15616: $outgoing =~ s/'/'/g;
15617: $outgoing =~ s/\$/$/g;
15618: $outgoing =~ s{/}{/}g;
15619: $outgoing =~ s/=/=/g;
15620: $outgoing =~ s/\\/\/g
15621: }
15622: return $outgoing;
15623: }
15624:
1.1190 musolffc 15625: # Checks for critical messages and returns a redirect url if one exists.
15626: # $interval indicates how often to check for messages.
15627: sub critical_redirect {
15628: my ($interval) = @_;
15629: if ((time-$env{'user.criticalcheck.time'})>$interval) {
15630: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
15631: $env{'user.name'});
15632: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 15633: my $redirecturl;
1.1190 musolffc 15634: if ($what[0]) {
15635: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
15636: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 15637: my $url=&Apache::lonnet::absolute_url().$redirecturl;
15638: return (1, $url);
1.1190 musolffc 15639: }
1.1191 raeburn 15640: }
15641: }
15642: return ();
1.1190 musolffc 15643: }
15644:
1.1174 raeburn 15645: # Use:
15646: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
15647: #
15648: ##################################################
15649: # password associated functions #
15650: ##################################################
15651: sub des_keys {
15652: # Make a new key for DES encryption.
15653: # Each key has two parts which are returned separately.
15654: # Please note: Each key must be passed through the &hex function
15655: # before it is output to the web browser. The hex versions cannot
15656: # be used to decrypt.
15657: my @hexstr=('0','1','2','3','4','5','6','7',
15658: '8','9','a','b','c','d','e','f');
15659: my $lkey='';
15660: for (0..7) {
15661: $lkey.=$hexstr[rand(15)];
15662: }
15663: my $ukey='';
15664: for (0..7) {
15665: $ukey.=$hexstr[rand(15)];
15666: }
15667: return ($lkey,$ukey);
15668: }
15669:
15670: sub des_decrypt {
15671: my ($key,$cyphertext) = @_;
15672: my $keybin=pack("H16",$key);
15673: my $cypher;
15674: if ($Crypt::DES::VERSION>=2.03) {
15675: $cypher=new Crypt::DES $keybin;
15676: } else {
15677: $cypher=new DES $keybin;
15678: }
15679: my $plaintext=
15680: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,0,16))));
15681: $plaintext.=
15682: $cypher->decrypt(unpack("a8",pack("H16",substr($cyphertext,16,16))));
15683: $plaintext=substr($plaintext,1,ord(substr($plaintext,0,1)) );
15684: return $plaintext;
15685: }
15686:
1.112 bowersj2 15687: 1;
15688: __END__;
1.41 ng 15689:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>