Annotation of loncom/interface/loncommon.pm, revision 1.1274
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1274 ! raeburn 4: # $Id: loncommon.pm,v 1.1273 2017/02/17 16:04:22 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.1241 raeburn 75: use DateTime::Locale;
1.1220 raeburn 76: use Encode();
1.1091 foxr 77: use Text::Aspell;
1.1094 raeburn 78: use Authen::Captcha;
79: use Captcha::reCAPTCHA;
1.1234 raeburn 80: use JSON::DWIW;
81: use LWP::UserAgent;
1.1174 raeburn 82: use Crypt::DES;
83: use DynaLoader; # for Crypt::DES version
1.1223 musolffc 84: use MIME::Lite;
85: use MIME::Types;
1.117 www 86:
1.517 raeburn 87: # ---------------------------------------------- Designs
88: use vars qw(%defaultdesign);
89:
1.22 www 90: my $readit;
91:
1.517 raeburn 92:
1.157 matthew 93: ##
94: ## Global Variables
95: ##
1.46 matthew 96:
1.643 foxr 97:
98: # ----------------------------------------------- SSI with retries:
99: #
100:
101: =pod
102:
1.648 raeburn 103: =head1 Server Side include with retries:
1.643 foxr 104:
105: =over 4
106:
1.648 raeburn 107: =item * &ssi_with_retries(resource,retries form)
1.643 foxr 108:
109: Performs an ssi with some number of retries. Retries continue either
110: until the result is ok or until the retry count supplied by the
111: caller is exhausted.
112:
113: Inputs:
1.648 raeburn 114:
115: =over 4
116:
1.643 foxr 117: resource - Identifies the resource to insert.
1.648 raeburn 118:
1.643 foxr 119: retries - Count of the number of retries allowed.
1.648 raeburn 120:
1.643 foxr 121: form - Hash that identifies the rendering options.
122:
1.648 raeburn 123: =back
124:
125: Returns:
126:
127: =over 4
128:
1.643 foxr 129: content - The content of the response. If retries were exhausted this is empty.
1.648 raeburn 130:
1.643 foxr 131: response - The response from the last attempt (which may or may not have been successful.
132:
1.648 raeburn 133: =back
134:
135: =back
136:
1.643 foxr 137: =cut
138:
139: sub ssi_with_retries {
140: my ($resource, $retries, %form) = @_;
141:
142:
143: my $ok = 0; # True if we got a good response.
144: my $content;
145: my $response;
146:
147: # Try to get the ssi done. within the retries count:
148:
149: do {
150: ($content, $response) = &Apache::lonnet::ssi($resource, %form);
151: $ok = $response->is_success;
1.650 www 152: if (!$ok) {
153: &Apache::lonnet::logthis("Failed ssi_with_retries on $resource: ".$response->is_success.', '.$response->code.', '.$response->message);
154: }
1.643 foxr 155: $retries--;
156: } while (!$ok && ($retries > 0));
157:
158: if (!$ok) {
159: $content = ''; # On error return an empty content.
160: }
161: return ($content, $response);
162:
163: }
164:
165:
166:
1.20 www 167: # ----------------------------------------------- Filetypes/Languages/Copyright
1.12 harris41 168: my %language;
1.124 www 169: my %supported_language;
1.1088 foxr 170: my %supported_codes;
1.1048 foxr 171: my %latex_language; # For choosing hyphenation in <transl..>
172: my %latex_language_bykey; # for choosing hyphenation from metadata
1.12 harris41 173: my %cprtag;
1.192 taceyjo1 174: my %scprtag;
1.351 www 175: my %fe; my %fd; my %fm;
1.41 ng 176: my %category_extensions;
1.12 harris41 177:
1.46 matthew 178: # ---------------------------------------------- Thesaurus variables
1.144 matthew 179: #
180: # %Keywords:
181: # A hash used by &keyword to determine if a word is considered a keyword.
182: # $thesaurus_db_file
183: # Scalar containing the full path to the thesaurus database.
1.46 matthew 184:
185: my %Keywords;
186: my $thesaurus_db_file;
187:
1.144 matthew 188: #
189: # Initialize values from language.tab, copyright.tab, filetypes.tab,
190: # thesaurus.tab, and filecategories.tab.
191: #
1.18 www 192: BEGIN {
1.46 matthew 193: # Variable initialization
194: $thesaurus_db_file = $Apache::lonnet::perlvar{'lonTabDir'}."/thesaurus.db";
195: #
1.22 www 196: unless ($readit) {
1.12 harris41 197: # ------------------------------------------------------------------- languages
198: {
1.158 raeburn 199: my $langtabfile = $Apache::lonnet::perlvar{'lonTabDir'}.
200: '/language.tab';
201: if ( open(my $fh,"<$langtabfile") ) {
1.356 albertel 202: while (my $line = <$fh>) {
203: next if ($line=~/^\#/);
204: chomp($line);
1.1088 foxr 205: my ($key,$code,$country,$three,$enc,$val,$sup,$latex)=(split(/\t/,$line));
1.158 raeburn 206: $language{$key}=$val.' - '.$enc;
207: if ($sup) {
208: $supported_language{$key}=$sup;
1.1088 foxr 209: $supported_codes{$key} = $code;
1.158 raeburn 210: }
1.1048 foxr 211: if ($latex) {
212: $latex_language_bykey{$key} = $latex;
1.1088 foxr 213: $latex_language{$code} = $latex;
1.1048 foxr 214: }
1.158 raeburn 215: }
216: close($fh);
217: }
1.12 harris41 218: }
219: # ------------------------------------------------------------------ copyrights
220: {
1.158 raeburn 221: my $copyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
222: '/copyright.tab';
223: if ( open (my $fh,"<$copyrightfile") ) {
1.356 albertel 224: while (my $line = <$fh>) {
225: next if ($line=~/^\#/);
226: chomp($line);
227: my ($key,$val)=(split(/\s+/,$line,2));
1.158 raeburn 228: $cprtag{$key}=$val;
229: }
230: close($fh);
231: }
1.12 harris41 232: }
1.351 www 233: # ----------------------------------------------------------- source copyrights
1.192 taceyjo1 234: {
235: my $sourcecopyrightfile = $Apache::lonnet::perlvar{'lonIncludes'}.
236: '/source_copyright.tab';
237: if ( open (my $fh,"<$sourcecopyrightfile") ) {
1.356 albertel 238: while (my $line = <$fh>) {
239: next if ($line =~ /^\#/);
240: chomp($line);
241: my ($key,$val)=(split(/\s+/,$line,2));
1.192 taceyjo1 242: $scprtag{$key}=$val;
243: }
244: close($fh);
245: }
246: }
1.63 www 247:
1.517 raeburn 248: # -------------------------------------------------------------- default domain designs
1.63 www 249: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
1.517 raeburn 250: my $designfile = $designdir.'/default.tab';
251: if ( open (my $fh,"<$designfile") ) {
252: while (my $line = <$fh>) {
253: next if ($line =~ /^\#/);
254: chomp($line);
255: my ($key,$val)=(split(/\=/,$line));
256: if ($val) { $defaultdesign{$key}=$val; }
257: }
258: close($fh);
1.63 www 259: }
260:
1.15 harris41 261: # ------------------------------------------------------------- file categories
262: {
1.158 raeburn 263: my $categoryfile = $Apache::lonnet::perlvar{'lonTabDir'}.
264: '/filecategories.tab';
265: if ( open (my $fh,"<$categoryfile") ) {
1.356 albertel 266: while (my $line = <$fh>) {
267: next if ($line =~ /^\#/);
268: chomp($line);
269: my ($extension,$category)=(split(/\s+/,$line,2));
1.1263 raeburn 270: push(@{$category_extensions{lc($category)}},$extension);
1.158 raeburn 271: }
272: close($fh);
273: }
274:
1.15 harris41 275: }
1.12 harris41 276: # ------------------------------------------------------------------ file types
277: {
1.158 raeburn 278: my $typesfile = $Apache::lonnet::perlvar{'lonTabDir'}.
279: '/filetypes.tab';
280: if ( open (my $fh,"<$typesfile") ) {
1.356 albertel 281: while (my $line = <$fh>) {
282: next if ($line =~ /^\#/);
283: chomp($line);
284: my ($ending,$emb,$mime,$descr)=split(/\s+/,$line,4);
1.158 raeburn 285: if ($descr ne '') {
286: $fe{$ending}=lc($emb);
287: $fd{$ending}=$descr;
1.351 www 288: if ($mime ne 'unk') { $fm{$ending}=$mime; }
1.158 raeburn 289: }
290: }
291: close($fh);
292: }
1.12 harris41 293: }
1.22 www 294: &Apache::lonnet::logthis(
1.705 tempelho 295: "<span style='color:yellow;'>INFO: Read file types</span>");
1.22 www 296: $readit=1;
1.46 matthew 297: } # end of unless($readit)
1.32 matthew 298:
299: }
1.112 bowersj2 300:
1.42 matthew 301: ###############################################################
302: ## HTML and Javascript Helper Functions ##
303: ###############################################################
304:
305: =pod
306:
1.112 bowersj2 307: =head1 HTML and Javascript Functions
1.42 matthew 308:
1.112 bowersj2 309: =over 4
310:
1.648 raeburn 311: =item * &browser_and_searcher_javascript()
1.112 bowersj2 312:
313: X<browsing, javascript>X<searching, javascript>Returns a string
314: containing javascript with two functions, C<openbrowser> and
315: C<opensearcher>. Returned string does not contain E<lt>scriptE<gt>
316: tags.
1.42 matthew 317:
1.648 raeburn 318: =item * &openbrowser(formname,elementname,only,omit) [javascript]
1.42 matthew 319:
320: inputs: formname, elementname, only, omit
321:
322: formname and elementname indicate the name of the html form and name of
323: the element that the results of the browsing selection are to be placed in.
324:
325: Specifying 'only' will restrict the browser to displaying only files
1.185 www 326: with the given extension. Can be a comma separated list.
1.42 matthew 327:
328: Specifying 'omit' will restrict the browser to NOT displaying files
1.185 www 329: with the given extension. Can be a comma separated list.
1.42 matthew 330:
1.648 raeburn 331: =item * &opensearcher(formname,elementname) [javascript]
1.42 matthew 332:
333: Inputs: formname, elementname
334:
335: formname and elementname specify the name of the html form and the name
336: of the element the selection from the search results will be placed in.
1.542 raeburn 337:
1.42 matthew 338: =cut
339:
340: sub browser_and_searcher_javascript {
1.199 albertel 341: my ($mode)=@_;
342: if (!defined($mode)) { $mode='edit'; }
1.453 albertel 343: my $resurl=&escape_single(&lastresurl());
1.42 matthew 344: return <<END;
1.219 albertel 345: // <!-- BEGIN LON-CAPA Internal
1.50 matthew 346: var editbrowser = null;
1.135 albertel 347: function openbrowser(formname,elementname,only,omit,titleelement) {
1.170 www 348: var url = '$resurl/?';
1.42 matthew 349: if (editbrowser == null) {
350: url += 'launch=1&';
351: }
352: url += 'catalogmode=interactive&';
1.199 albertel 353: url += 'mode=$mode&';
1.611 albertel 354: url += 'inhibitmenu=yes&';
1.42 matthew 355: url += 'form=' + formname + '&';
356: if (only != null) {
357: url += 'only=' + only + '&';
1.217 albertel 358: } else {
359: url += 'only=&';
360: }
1.42 matthew 361: if (omit != null) {
362: url += 'omit=' + omit + '&';
1.217 albertel 363: } else {
364: url += 'omit=&';
365: }
1.135 albertel 366: if (titleelement != null) {
367: url += 'titleelement=' + titleelement + '&';
1.217 albertel 368: } else {
369: url += 'titleelement=&';
370: }
1.42 matthew 371: url += 'element=' + elementname + '';
372: var title = 'Browser';
1.435 albertel 373: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 374: options += ',width=700,height=600';
375: editbrowser = open(url,title,options,'1');
376: editbrowser.focus();
377: }
378: var editsearcher;
1.135 albertel 379: function opensearcher(formname,elementname,titleelement) {
1.42 matthew 380: var url = '/adm/searchcat?';
381: if (editsearcher == null) {
382: url += 'launch=1&';
383: }
384: url += 'catalogmode=interactive&';
1.199 albertel 385: url += 'mode=$mode&';
1.42 matthew 386: url += 'form=' + formname + '&';
1.135 albertel 387: if (titleelement != null) {
388: url += 'titleelement=' + titleelement + '&';
1.217 albertel 389: } else {
390: url += 'titleelement=&';
391: }
1.42 matthew 392: url += 'element=' + elementname + '';
393: var title = 'Search';
1.435 albertel 394: var options = 'scrollbars=1,resizable=1,menubar=0,toolbar=1,location=1';
1.42 matthew 395: options += ',width=700,height=600';
396: editsearcher = open(url,title,options,'1');
397: editsearcher.focus();
398: }
1.219 albertel 399: // END LON-CAPA Internal -->
1.42 matthew 400: END
1.170 www 401: }
402:
403: sub lastresurl {
1.258 albertel 404: if ($env{'environment.lastresurl'}) {
405: return $env{'environment.lastresurl'}
1.170 www 406: } else {
407: return '/res';
408: }
409: }
410:
411: sub storeresurl {
412: my $resurl=&Apache::lonnet::clutter(shift);
413: unless ($resurl=~/^\/res/) { return 0; }
414: $resurl=~s/\/$//;
415: &Apache::lonnet::put('environment',{'lastresurl' => $resurl});
1.646 raeburn 416: &Apache::lonnet::appenv({'environment.lastresurl' => $resurl});
1.170 www 417: return 1;
1.42 matthew 418: }
419:
1.74 www 420: sub studentbrowser_javascript {
1.111 www 421: unless (
1.258 albertel 422: (($env{'request.course.id'}) &&
1.302 albertel 423: (&Apache::lonnet::allowed('srm',$env{'request.course.id'})
424: || &Apache::lonnet::allowed('srm',$env{'request.course.id'}.
425: '/'.$env{'request.course.sec'})
426: ))
1.258 albertel 427: || ($env{'request.role'}=~/^(au|dc|su)/)
1.111 www 428: ) { return ''; }
1.74 www 429: return (<<'ENDSTDBRW');
1.776 bisitz 430: <script type="text/javascript" language="Javascript">
1.824 bisitz 431: // <![CDATA[
1.74 www 432: var stdeditbrowser;
1.999 www 433: function openstdbrowser(formname,uname,udom,clicker,roleflag,ignorefilter,courseadvonly) {
1.74 www 434: var url = '/adm/pickstudent?';
435: var filter;
1.558 albertel 436: if (!ignorefilter) {
437: eval('filter=document.'+formname+'.'+uname+'.value;');
438: }
1.74 www 439: if (filter != null) {
440: if (filter != '') {
441: url += 'filter='+filter+'&';
442: }
443: }
444: url += 'form=' + formname + '&unameelement='+uname+
1.999 www 445: '&udomelement='+udom+
446: '&clicker='+clicker;
1.111 www 447: if (roleflag) { url+="&roles=1"; }
1.793 raeburn 448: if (courseadvonly) { url+="&courseadvonly=1"; }
1.102 www 449: var title = 'Student_Browser';
1.74 www 450: var options = 'scrollbars=1,resizable=1,menubar=0';
451: options += ',width=700,height=600';
452: stdeditbrowser = open(url,title,options,'1');
453: stdeditbrowser.focus();
454: }
1.824 bisitz 455: // ]]>
1.74 www 456: </script>
457: ENDSTDBRW
458: }
1.42 matthew 459:
1.1003 www 460: sub resourcebrowser_javascript {
461: unless ($env{'request.course.id'}) { return ''; }
1.1004 www 462: return (<<'ENDRESBRW');
1.1003 www 463: <script type="text/javascript" language="Javascript">
464: // <![CDATA[
465: var reseditbrowser;
1.1004 www 466: function openresbrowser(formname,reslink) {
1.1005 www 467: var url = '/adm/pickresource?form='+formname+'&reslink='+reslink;
1.1003 www 468: var title = 'Resource_Browser';
469: var options = 'scrollbars=1,resizable=1,menubar=0';
1.1005 www 470: options += ',width=700,height=500';
1.1004 www 471: reseditbrowser = open(url,title,options,'1');
472: reseditbrowser.focus();
1.1003 www 473: }
474: // ]]>
475: </script>
1.1004 www 476: ENDRESBRW
1.1003 www 477: }
478:
1.74 www 479: sub selectstudent_link {
1.999 www 480: my ($form,$unameele,$udomele,$courseadvonly,$clickerid)=@_;
481: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
482: &Apache::lonhtmlcommon::entity_encode($unameele)."','".
483: &Apache::lonhtmlcommon::entity_encode($udomele)."'";
1.258 albertel 484: if ($env{'request.course.id'}) {
1.302 albertel 485: if (!&Apache::lonnet::allowed('srm',$env{'request.course.id'})
486: && !&Apache::lonnet::allowed('srm',$env{'request.course.id'}.
487: '/'.$env{'request.course.sec'})) {
1.111 www 488: return '';
489: }
1.999 www 490: $callargs.=",'".&Apache::lonhtmlcommon::entity_encode($clickerid)."'";
1.793 raeburn 491: if ($courseadvonly) {
492: $callargs .= ",'',1,1";
493: }
494: return '<span class="LC_nobreak">'.
495: '<a href="javascript:openstdbrowser('.$callargs.');">'.
496: &mt('Select User').'</a></span>';
1.74 www 497: }
1.258 albertel 498: if ($env{'request.role'}=~/^(au|dc|su)/) {
1.1012 www 499: $callargs .= ",'',1";
1.793 raeburn 500: return '<span class="LC_nobreak">'.
501: '<a href="javascript:openstdbrowser('.$callargs.');">'.
502: &mt('Select User').'</a></span>';
1.111 www 503: }
504: return '';
1.91 www 505: }
506:
1.1004 www 507: sub selectresource_link {
508: my ($form,$reslink,$arg)=@_;
509:
510: my $callargs = "'".&Apache::lonhtmlcommon::entity_encode($form)."','".
511: &Apache::lonhtmlcommon::entity_encode($reslink)."'";
512: unless ($env{'request.course.id'}) { return $arg; }
513: return '<span class="LC_nobreak">'.
514: '<a href="javascript:openresbrowser('.$callargs.');">'.
515: $arg.'</a></span>';
516: }
517:
518:
519:
1.653 raeburn 520: sub authorbrowser_javascript {
521: return <<"ENDAUTHORBRW";
1.776 bisitz 522: <script type="text/javascript" language="JavaScript">
1.824 bisitz 523: // <![CDATA[
1.653 raeburn 524: var stdeditbrowser;
525:
526: function openauthorbrowser(formname,udom) {
527: var url = '/adm/pickauthor?';
528: url += 'form='+formname+'&roledom='+udom;
529: var title = 'Author_Browser';
530: var options = 'scrollbars=1,resizable=1,menubar=0';
531: options += ',width=700,height=600';
532: stdeditbrowser = open(url,title,options,'1');
533: stdeditbrowser.focus();
534: }
535:
1.824 bisitz 536: // ]]>
1.653 raeburn 537: </script>
538: ENDAUTHORBRW
539: }
540:
1.91 www 541: sub coursebrowser_javascript {
1.1116 raeburn 542: my ($domainfilter,$sec_element,$formname,$role_element,$crstype,
1.1221 raeburn 543: $credits_element,$instcode) = @_;
1.932 raeburn 544: my $wintitle = 'Course_Browser';
1.931 raeburn 545: if ($crstype eq 'Community') {
1.932 raeburn 546: $wintitle = 'Community_Browser';
1.909 raeburn 547: }
1.876 raeburn 548: my $id_functions = &javascript_index_functions();
549: my $output = '
1.776 bisitz 550: <script type="text/javascript" language="JavaScript">
1.824 bisitz 551: // <![CDATA[
1.468 raeburn 552: var stdeditbrowser;'."\n";
1.876 raeburn 553:
554: $output .= <<"ENDSTDBRW";
1.909 raeburn 555: function opencrsbrowser(formname,uname,udom,desc,extra_element,multflag,type,type_elem) {
1.91 www 556: var url = '/adm/pickcourse?';
1.895 raeburn 557: var formid = getFormIdByName(formname);
1.876 raeburn 558: var domainfilter = getDomainFromSelectbox(formname,udom);
1.128 albertel 559: if (domainfilter != null) {
560: if (domainfilter != '') {
561: url += 'domainfilter='+domainfilter+'&';
562: }
563: }
1.91 www 564: url += 'form=' + formname + '&cnumelement='+uname+
1.187 albertel 565: '&cdomelement='+udom+
566: '&cnameelement='+desc;
1.468 raeburn 567: if (extra_element !=null && extra_element != '') {
1.594 raeburn 568: if (formname == 'rolechoice' || formname == 'studentform') {
1.468 raeburn 569: url += '&roleelement='+extra_element;
570: if (domainfilter == null || domainfilter == '') {
571: url += '&domainfilter='+extra_element;
572: }
1.234 raeburn 573: }
1.468 raeburn 574: else {
575: if (formname == 'portform') {
576: url += '&setroles='+extra_element;
1.800 raeburn 577: } else {
578: if (formname == 'rules') {
579: url += '&fixeddom='+extra_element;
580: }
1.468 raeburn 581: }
582: }
1.230 raeburn 583: }
1.909 raeburn 584: if (type != null && type != '') {
585: url += '&type='+type;
586: }
587: if (type_elem != null && type_elem != '') {
588: url += '&typeelement='+type_elem;
589: }
1.872 raeburn 590: if (formname == 'ccrs') {
591: var ownername = document.forms[formid].ccuname.value;
592: var ownerdom = document.forms[formid].ccdomain.options[document.forms[formid].ccdomain.selectedIndex].value;
1.1238 raeburn 593: url += '&cloner='+ownername+':'+ownerdom;
594: if (type == 'Course') {
595: url += '&crscode='+document.forms[formid].crscode.value;
596: }
1.1221 raeburn 597: }
598: if (formname == 'requestcrs') {
599: url += '&crsdom=$domainfilter&crscode=$instcode';
1.872 raeburn 600: }
1.293 raeburn 601: if (multflag !=null && multflag != '') {
602: url += '&multiple='+multflag;
603: }
1.909 raeburn 604: var title = '$wintitle';
1.91 www 605: var options = 'scrollbars=1,resizable=1,menubar=0';
606: options += ',width=700,height=600';
607: stdeditbrowser = open(url,title,options,'1');
608: stdeditbrowser.focus();
609: }
1.876 raeburn 610: $id_functions
611: ENDSTDBRW
1.1116 raeburn 612: if (($sec_element ne '') || ($role_element ne '') || ($credits_element ne '')) {
613: $output .= &setsec_javascript($sec_element,$formname,$role_element,
614: $credits_element);
1.876 raeburn 615: }
616: $output .= '
617: // ]]>
618: </script>';
619: return $output;
620: }
621:
622: sub javascript_index_functions {
623: return <<"ENDJS";
624:
625: function getFormIdByName(formname) {
626: for (var i=0;i<document.forms.length;i++) {
627: if (document.forms[i].name == formname) {
628: return i;
629: }
630: }
631: return -1;
632: }
633:
634: function getIndexByName(formid,item) {
635: for (var i=0;i<document.forms[formid].elements.length;i++) {
636: if (document.forms[formid].elements[i].name == item) {
637: return i;
638: }
639: }
640: return -1;
641: }
1.468 raeburn 642:
1.876 raeburn 643: function getDomainFromSelectbox(formname,udom) {
644: var userdom;
645: var formid = getFormIdByName(formname);
646: if (formid > -1) {
647: var domid = getIndexByName(formid,udom);
648: if (domid > -1) {
649: if (document.forms[formid].elements[domid].type == 'select-one') {
650: userdom=document.forms[formid].elements[domid].options[document.forms[formid].elements[domid].selectedIndex].value;
651: }
652: if (document.forms[formid].elements[domid].type == 'hidden') {
653: userdom=document.forms[formid].elements[domid].value;
1.468 raeburn 654: }
655: }
656: }
1.876 raeburn 657: return userdom;
658: }
659:
660: ENDJS
1.468 raeburn 661:
1.876 raeburn 662: }
663:
1.1017 raeburn 664: sub javascript_array_indexof {
1.1018 raeburn 665: return <<ENDJS;
1.1017 raeburn 666: <script type="text/javascript" language="JavaScript">
667: // <![CDATA[
668:
669: if (!Array.prototype.indexOf) {
670: Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
671: "use strict";
672: if (this === void 0 || this === null) {
673: throw new TypeError();
674: }
675: var t = Object(this);
676: var len = t.length >>> 0;
677: if (len === 0) {
678: return -1;
679: }
680: var n = 0;
681: if (arguments.length > 0) {
682: n = Number(arguments[1]);
1.1088 foxr 683: if (n !== n) { // shortcut for verifying if it is NaN
1.1017 raeburn 684: n = 0;
685: } else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) {
686: n = (n > 0 || -1) * Math.floor(Math.abs(n));
687: }
688: }
689: if (n >= len) {
690: return -1;
691: }
692: var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
693: for (; k < len; k++) {
694: if (k in t && t[k] === searchElement) {
695: return k;
696: }
697: }
698: return -1;
699: }
700: }
701:
702: // ]]>
703: </script>
704:
705: ENDJS
706:
707: }
708:
1.876 raeburn 709: sub userbrowser_javascript {
710: my $id_functions = &javascript_index_functions();
711: return <<"ENDUSERBRW";
712:
1.888 raeburn 713: function openuserbrowser(formname,uname,udom,ulast,ufirst,uemail,hideudom,crsdom,caller) {
1.876 raeburn 714: var url = '/adm/pickuser?';
715: var userdom = getDomainFromSelectbox(formname,udom);
716: if (userdom != null) {
717: if (userdom != '') {
718: url += 'srchdom='+userdom+'&';
719: }
720: }
721: url += 'form=' + formname + '&unameelement='+uname+
722: '&udomelement='+udom+
723: '&ulastelement='+ulast+
724: '&ufirstelement='+ufirst+
725: '&uemailelement='+uemail+
1.881 raeburn 726: '&hideudomelement='+hideudom+
727: '&coursedom='+crsdom;
1.888 raeburn 728: if ((caller != null) && (caller != undefined)) {
729: url += '&caller='+caller;
730: }
1.876 raeburn 731: var title = 'User_Browser';
732: var options = 'scrollbars=1,resizable=1,menubar=0';
733: options += ',width=700,height=600';
734: var stdeditbrowser = open(url,title,options,'1');
735: stdeditbrowser.focus();
736: }
737:
1.888 raeburn 738: function fix_domain (formname,udom,origdom,uname) {
1.876 raeburn 739: var formid = getFormIdByName(formname);
740: if (formid > -1) {
1.888 raeburn 741: var unameid = getIndexByName(formid,uname);
1.876 raeburn 742: var domid = getIndexByName(formid,udom);
743: var hidedomid = getIndexByName(formid,origdom);
744: if (hidedomid > -1) {
745: var fixeddom = document.forms[formid].elements[hidedomid].value;
1.888 raeburn 746: var unameval = document.forms[formid].elements[unameid].value;
747: if ((fixeddom != '') && (fixeddom != undefined) && (fixeddom != null) && (unameval != '') && (unameval != undefined) && (unameval != null)) {
748: if (domid > -1) {
749: var slct = document.forms[formid].elements[domid];
750: if (slct.type == 'select-one') {
751: var i;
752: for (i=0;i<slct.length;i++) {
753: if (slct.options[i].value==fixeddom) { slct.selectedIndex=i; }
754: }
755: }
756: if (slct.type == 'hidden') {
757: slct.value = fixeddom;
1.876 raeburn 758: }
759: }
1.468 raeburn 760: }
761: }
762: }
1.876 raeburn 763: return;
764: }
765:
766: $id_functions
767: ENDUSERBRW
1.468 raeburn 768: }
769:
770: sub setsec_javascript {
1.1116 raeburn 771: my ($sec_element,$formname,$role_element,$credits_element) = @_;
1.905 raeburn 772: my (@courserolenames,@communityrolenames,$rolestr,$courserolestr,
773: $communityrolestr);
774: if ($role_element ne '') {
775: my @allroles = ('st','ta','ep','in','ad');
776: foreach my $crstype ('Course','Community') {
777: if ($crstype eq 'Community') {
778: foreach my $role (@allroles) {
779: push(@communityrolenames,&Apache::lonnet::plaintext($role,$crstype));
780: }
781: push(@communityrolenames,&Apache::lonnet::plaintext('co'));
782: } else {
783: foreach my $role (@allroles) {
784: push(@courserolenames,&Apache::lonnet::plaintext($role,$crstype));
785: }
786: push(@courserolenames,&Apache::lonnet::plaintext('cc'));
787: }
788: }
789: $rolestr = '"'.join('","',@allroles).'"';
790: $courserolestr = '"'.join('","',@courserolenames).'"';
791: $communityrolestr = '"'.join('","',@communityrolenames).'"';
792: }
1.468 raeburn 793: my $setsections = qq|
794: function setSect(sectionlist) {
1.629 raeburn 795: var sectionsArray = new Array();
796: if ((sectionlist != '') && (typeof sectionlist != "undefined")) {
797: sectionsArray = sectionlist.split(",");
798: }
1.468 raeburn 799: var numSections = sectionsArray.length;
800: document.$formname.$sec_element.length = 0;
801: if (numSections == 0) {
802: document.$formname.$sec_element.multiple=false;
803: document.$formname.$sec_element.size=1;
804: document.$formname.$sec_element.options[0] = new Option('No existing sections','',false,false)
805: } else {
806: if (numSections == 1) {
807: document.$formname.$sec_element.multiple=false;
808: document.$formname.$sec_element.size=1;
809: document.$formname.$sec_element.options[0] = new Option('Select','',true,true);
810: document.$formname.$sec_element.options[1] = new Option('No section','',false,false)
811: document.$formname.$sec_element.options[2] = new Option(sectionsArray[0],sectionsArray[0],false,false);
812: } else {
813: for (var i=0; i<numSections; i++) {
814: document.$formname.$sec_element.options[i] = new Option(sectionsArray[i],sectionsArray[i],false,false)
815: }
816: document.$formname.$sec_element.multiple=true
817: if (numSections < 3) {
818: document.$formname.$sec_element.size=numSections;
819: } else {
820: document.$formname.$sec_element.size=3;
821: }
822: document.$formname.$sec_element.options[0].selected = false
823: }
824: }
1.91 www 825: }
1.905 raeburn 826:
827: function setRole(crstype) {
1.468 raeburn 828: |;
1.905 raeburn 829: if ($role_element eq '') {
830: $setsections .= ' return;
831: }
832: ';
833: } else {
834: $setsections .= qq|
835: var elementLength = document.$formname.$role_element.length;
836: var allroles = Array($rolestr);
837: var courserolenames = Array($courserolestr);
838: var communityrolenames = Array($communityrolestr);
839: if (elementLength != undefined) {
840: if (document.$formname.$role_element.options[5].value == 'cc') {
841: if (crstype == 'Course') {
842: return;
843: } else {
844: allroles[5] = 'co';
845: for (var i=0; i<6; i++) {
846: document.$formname.$role_element.options[i].value = allroles[i];
847: document.$formname.$role_element.options[i].text = communityrolenames[i];
848: }
849: }
850: } else {
851: if (crstype == 'Community') {
852: return;
853: } else {
854: allroles[5] = 'cc';
855: for (var i=0; i<6; i++) {
856: document.$formname.$role_element.options[i].value = allroles[i];
857: document.$formname.$role_element.options[i].text = courserolenames[i];
858: }
859: }
860: }
861: }
862: return;
863: }
864: |;
865: }
1.1116 raeburn 866: if ($credits_element) {
867: $setsections .= qq|
868: function setCredits(defaultcredits) {
869: document.$formname.$credits_element.value = defaultcredits;
870: return;
871: }
872: |;
873: }
1.468 raeburn 874: return $setsections;
875: }
876:
1.91 www 877: sub selectcourse_link {
1.909 raeburn 878: my ($form,$unameele,$udomele,$desc,$extra_element,$multflag,$selecttype,
879: $typeelement) = @_;
880: my $type = $selecttype;
1.871 raeburn 881: my $linktext = &mt('Select Course');
882: if ($selecttype eq 'Community') {
1.909 raeburn 883: $linktext = &mt('Select Community');
1.1239 raeburn 884: } elsif ($selecttype eq 'Placement') {
885: $linktext = &mt('Select Placement Test');
1.906 raeburn 886: } elsif ($selecttype eq 'Course/Community') {
887: $linktext = &mt('Select Course/Community');
1.909 raeburn 888: $type = '';
1.1019 raeburn 889: } elsif ($selecttype eq 'Select') {
890: $linktext = &mt('Select');
891: $type = '';
1.871 raeburn 892: }
1.787 bisitz 893: return '<span class="LC_nobreak">'
894: ."<a href='"
895: .'javascript:opencrsbrowser("'.$form.'","'.$unameele
896: .'","'.$udomele.'","'.$desc.'","'.$extra_element
1.909 raeburn 897: .'","'.$multflag.'","'.$type.'","'.$typeelement.'");'
1.871 raeburn 898: ."'>".$linktext.'</a>'
1.787 bisitz 899: .'</span>';
1.74 www 900: }
1.42 matthew 901:
1.653 raeburn 902: sub selectauthor_link {
903: my ($form,$udom)=@_;
904: return '<a href="javascript:openauthorbrowser('."'$form','$udom'".');">'.
905: &mt('Select Author').'</a>';
906: }
907:
1.876 raeburn 908: sub selectuser_link {
1.881 raeburn 909: my ($form,$unameelem,$domelem,$lastelem,$firstelem,$emailelem,$hdomelem,
1.888 raeburn 910: $coursedom,$linktext,$caller) = @_;
1.876 raeburn 911: return '<a href="javascript:openuserbrowser('."'$form','$unameelem','$domelem',".
1.888 raeburn 912: "'$lastelem','$firstelem','$emailelem','$hdomelem','$coursedom','$caller'".
1.881 raeburn 913: ');">'.$linktext.'</a>';
1.876 raeburn 914: }
915:
1.273 raeburn 916: sub check_uncheck_jscript {
917: my $jscript = <<"ENDSCRT";
918: function checkAll(field) {
919: if (field.length > 0) {
920: for (i = 0; i < field.length; i++) {
1.1093 raeburn 921: if (!field[i].disabled) {
922: field[i].checked = true;
923: }
1.273 raeburn 924: }
925: } else {
1.1093 raeburn 926: if (!field.disabled) {
927: field.checked = true;
928: }
1.273 raeburn 929: }
930: }
931:
932: function uncheckAll(field) {
933: if (field.length > 0) {
934: for (i = 0; i < field.length; i++) {
935: field[i].checked = false ;
1.543 albertel 936: }
937: } else {
1.273 raeburn 938: field.checked = false ;
939: }
940: }
941: ENDSCRT
942: return $jscript;
943: }
944:
1.656 www 945: sub select_timezone {
1.1256 raeburn 946: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
947: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.659 raeburn 948: if ($includeempty) {
949: $output .= '<option value=""';
950: if (($selected eq '') || ($selected eq 'local')) {
951: $output .= ' selected="selected" ';
952: }
953: $output .= '> </option>';
954: }
1.657 raeburn 955: my @timezones = DateTime::TimeZone->all_names;
956: foreach my $tzone (@timezones) {
957: $output.= '<option value="'.$tzone.'"';
958: if ($tzone eq $selected) {
959: $output.=' selected="selected"';
960: }
961: $output.=">$tzone</option>\n";
1.656 www 962: }
963: $output.="</select>";
964: return $output;
965: }
1.273 raeburn 966:
1.687 raeburn 967: sub select_datelocale {
1.1256 raeburn 968: my ($name,$selected,$onchange,$includeempty,$disabled)=@_;
969: my $output='<select name="'.$name.'" '.$onchange.$disabled.'>'."\n";
1.687 raeburn 970: if ($includeempty) {
971: $output .= '<option value=""';
972: if ($selected eq '') {
973: $output .= ' selected="selected" ';
974: }
975: $output .= '> </option>';
976: }
1.1241 raeburn 977: my @languages = &Apache::lonlocal::preferred_languages();
1.687 raeburn 978: my (@possibles,%locale_names);
1.1241 raeburn 979: my @locales = DateTime::Locale->ids();
980: foreach my $id (@locales) {
981: if ($id ne '') {
982: my ($en_terr,$native_terr);
983: my $loc = DateTime::Locale->load($id);
984: if (ref($loc)) {
985: $en_terr = $loc->name();
986: $native_terr = $loc->native_name();
1.687 raeburn 987: if (grep(/^en$/,@languages) || !@languages) {
988: if ($en_terr ne '') {
989: $locale_names{$id} = '('.$en_terr.')';
990: } elsif ($native_terr ne '') {
991: $locale_names{$id} = $native_terr;
992: }
993: } else {
994: if ($native_terr ne '') {
995: $locale_names{$id} = $native_terr.' ';
996: } elsif ($en_terr ne '') {
997: $locale_names{$id} = '('.$en_terr.')';
998: }
999: }
1.1220 raeburn 1000: $locale_names{$id} = Encode::encode('UTF-8',$locale_names{$id});
1.1241 raeburn 1001: push(@possibles,$id);
1002: }
1.687 raeburn 1003: }
1004: }
1005: foreach my $item (sort(@possibles)) {
1006: $output.= '<option value="'.$item.'"';
1007: if ($item eq $selected) {
1008: $output.=' selected="selected"';
1009: }
1010: $output.=">$item";
1011: if ($locale_names{$item} ne '') {
1.1220 raeburn 1012: $output.=' '.$locale_names{$item};
1.687 raeburn 1013: }
1014: $output.="</option>\n";
1015: }
1016: $output.="</select>";
1017: return $output;
1018: }
1019:
1.792 raeburn 1020: sub select_language {
1.1256 raeburn 1021: my ($name,$selected,$includeempty,$noedit) = @_;
1.792 raeburn 1022: my %langchoices;
1023: if ($includeempty) {
1.1117 raeburn 1024: %langchoices = ('' => 'No language preference');
1.792 raeburn 1025: }
1026: foreach my $id (&languageids()) {
1027: my $code = &supportedlanguagecode($id);
1028: if ($code) {
1029: $langchoices{$code} = &plainlanguagedescription($id);
1030: }
1031: }
1.1117 raeburn 1032: %langchoices = &Apache::lonlocal::texthash(%langchoices);
1.1256 raeburn 1033: return &select_form($selected,$name,\%langchoices,undef,$noedit);
1.792 raeburn 1034: }
1035:
1.42 matthew 1036: =pod
1.36 matthew 1037:
1.1088 foxr 1038:
1039: =item * &list_languages()
1040:
1041: Returns an array reference that is suitable for use in language prompters.
1042: Each array element is itself a two element array. The first element
1043: is the language code. The second element a descsriptiuon of the
1044: language itself. This is suitable for use in e.g.
1045: &Apache::edit::select_arg (once dereferenced that is).
1046:
1047: =cut
1048:
1049: sub list_languages {
1050: my @lang_choices;
1051:
1052: foreach my $id (&languageids()) {
1053: my $code = &supportedlanguagecode($id);
1054: if ($code) {
1055: my $selector = $supported_codes{$id};
1056: my $description = &plainlanguagedescription($id);
1.1263 raeburn 1057: push(@lang_choices, [$selector, $description]);
1.1088 foxr 1058: }
1059: }
1060: return \@lang_choices;
1061: }
1062:
1063: =pod
1064:
1.648 raeburn 1065: =item * &linked_select_forms(...)
1.36 matthew 1066:
1067: linked_select_forms returns a string containing a <script></script> block
1068: and html for two <select> menus. The select menus will be linked in that
1069: changing the value of the first menu will result in new values being placed
1070: in the second menu. The values in the select menu will appear in alphabetical
1.609 raeburn 1071: order unless a defined order is provided.
1.36 matthew 1072:
1073: linked_select_forms takes the following ordered inputs:
1074:
1075: =over 4
1076:
1.112 bowersj2 1077: =item * $formname, the name of the <form> tag
1.36 matthew 1078:
1.112 bowersj2 1079: =item * $middletext, the text which appears between the <select> tags
1.36 matthew 1080:
1.112 bowersj2 1081: =item * $firstdefault, the default value for the first menu
1.36 matthew 1082:
1.112 bowersj2 1083: =item * $firstselectname, the name of the first <select> tag
1.36 matthew 1084:
1.112 bowersj2 1085: =item * $secondselectname, the name of the second <select> tag
1.36 matthew 1086:
1.112 bowersj2 1087: =item * $hashref, a reference to a hash containing the data for the menus.
1.36 matthew 1088:
1.609 raeburn 1089: =item * $menuorder, the order of values in the first menu
1090:
1.1115 raeburn 1091: =item * $onchangefirst, additional javascript call to execute for an onchange
1092: event for the first <select> tag
1093:
1094: =item * $onchangesecond, additional javascript call to execute for an onchange
1095: event for the second <select> tag
1096:
1.1245 raeburn 1097: =item * $suffix, to differentiate separate uses of select2data javascript
1098: objects in a page.
1099:
1.41 ng 1100: =back
1101:
1.36 matthew 1102: Below is an example of such a hash. Only the 'text', 'default', and
1103: 'select2' keys must appear as stated. keys(%menu) are the possible
1104: values for the first select menu. The text that coincides with the
1.41 ng 1105: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1106: and text for the second menu are given in the hash pointed to by
1107: $menu{$choice1}->{'select2'}.
1108:
1.112 bowersj2 1109: my %menu = ( A1 => { text =>"Choice A1" ,
1110: default => "B3",
1111: select2 => {
1112: B1 => "Choice B1",
1113: B2 => "Choice B2",
1114: B3 => "Choice B3",
1115: B4 => "Choice B4"
1.609 raeburn 1116: },
1117: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1118: },
1119: A2 => { text =>"Choice A2" ,
1120: default => "C2",
1121: select2 => {
1122: C1 => "Choice C1",
1123: C2 => "Choice C2",
1124: C3 => "Choice C3"
1.609 raeburn 1125: },
1126: order => ['C2','C1','C3'],
1.112 bowersj2 1127: },
1128: A3 => { text =>"Choice A3" ,
1129: default => "D6",
1130: select2 => {
1131: D1 => "Choice D1",
1132: D2 => "Choice D2",
1133: D3 => "Choice D3",
1134: D4 => "Choice D4",
1135: D5 => "Choice D5",
1136: D6 => "Choice D6",
1137: D7 => "Choice D7"
1.609 raeburn 1138: },
1139: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1140: }
1141: );
1.36 matthew 1142:
1143: =cut
1144:
1145: sub linked_select_forms {
1146: my ($formname,
1147: $middletext,
1148: $firstdefault,
1149: $firstselectname,
1150: $secondselectname,
1.609 raeburn 1151: $hashref,
1152: $menuorder,
1.1115 raeburn 1153: $onchangefirst,
1.1245 raeburn 1154: $onchangesecond,
1155: $suffix
1.36 matthew 1156: ) = @_;
1157: my $second = "document.$formname.$secondselectname";
1158: my $first = "document.$formname.$firstselectname";
1159: # output the javascript to do the changing
1160: my $result = '';
1.776 bisitz 1161: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1162: $result.="// <![CDATA[\n";
1.1245 raeburn 1163: $result.="var select2data${suffix} = new Object();\n";
1.36 matthew 1164: $" = '","';
1165: my $debug = '';
1166: foreach my $s1 (sort(keys(%$hashref))) {
1.1245 raeburn 1167: $result.="select2data${suffix}['d_$s1'] = new Object();\n";
1168: $result.="select2data${suffix}['d_$s1'].def = new String('".
1.36 matthew 1169: $hashref->{$s1}->{'default'}."');\n";
1.1245 raeburn 1170: $result.="select2data${suffix}['d_$s1'].values = new Array(";
1.36 matthew 1171: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1172: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1173: @s2values = @{$hashref->{$s1}->{'order'}};
1174: }
1.36 matthew 1175: $result.="\"@s2values\");\n";
1.1245 raeburn 1176: $result.="select2data${suffix}['d_$s1'].texts = new Array(";
1.36 matthew 1177: my @s2texts;
1178: foreach my $value (@s2values) {
1.1263 raeburn 1179: push(@s2texts, $hashref->{$s1}->{'select2'}->{$value});
1.36 matthew 1180: }
1181: $result.="\"@s2texts\");\n";
1182: }
1183: $"=' ';
1184: $result.= <<"END";
1185:
1.1245 raeburn 1186: function select1${suffix}_changed() {
1.36 matthew 1187: // Determine new choice
1.1245 raeburn 1188: var newvalue = "d_" + $first.options[$first.selectedIndex].value;
1.36 matthew 1189: // update select2
1.1245 raeburn 1190: var values = select2data${suffix}[newvalue].values;
1191: var texts = select2data${suffix}[newvalue].texts;
1192: var select2def = select2data${suffix}[newvalue].def;
1.36 matthew 1193: var i;
1194: // out with the old
1.1245 raeburn 1195: $second.options.length = 0;
1196: // in with the new
1.36 matthew 1197: for (i=0;i<values.length; i++) {
1198: $second.options[i] = new Option(values[i]);
1.143 matthew 1199: $second.options[i].value = values[i];
1.36 matthew 1200: $second.options[i].text = texts[i];
1201: if (values[i] == select2def) {
1202: $second.options[i].selected = true;
1203: }
1204: }
1205: }
1.824 bisitz 1206: // ]]>
1.36 matthew 1207: </script>
1208: END
1209: # output the initial values for the selection lists
1.1245 raeburn 1210: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1${suffix}_changed();$onchangefirst\">\n";
1.609 raeburn 1211: my @order = sort(keys(%{$hashref}));
1212: if (ref($menuorder) eq 'ARRAY') {
1213: @order = @{$menuorder};
1214: }
1215: foreach my $value (@order) {
1.36 matthew 1216: $result.=" <option value=\"$value\" ";
1.253 albertel 1217: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1218: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1219: }
1220: $result .= "</select>\n";
1221: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1222: $result .= $middletext;
1.1115 raeburn 1223: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1224: if ($onchangesecond) {
1225: $result .= ' onchange="'.$onchangesecond.'"';
1226: }
1227: $result .= ">\n";
1.36 matthew 1228: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1229:
1230: my @secondorder = sort(keys(%select2));
1231: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1232: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1233: }
1234: foreach my $value (@secondorder) {
1.36 matthew 1235: $result.=" <option value=\"$value\" ";
1.253 albertel 1236: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1237: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1238: }
1239: $result .= "</select>\n";
1240: # return $debug;
1241: return $result;
1242: } # end of sub linked_select_forms {
1243:
1.45 matthew 1244: =pod
1.44 bowersj2 1245:
1.973 raeburn 1246: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1247:
1.112 bowersj2 1248: Returns a string corresponding to an HTML link to the given help
1249: $topic, where $topic corresponds to the name of a .tex file in
1250: /home/httpd/html/adm/help/tex, with underscores replaced by
1251: spaces.
1252:
1253: $text will optionally be linked to the same topic, allowing you to
1254: link text in addition to the graphic. If you do not want to link
1255: text, but wish to specify one of the later parameters, pass an
1256: empty string.
1257:
1258: $stayOnPage is a value that will be interpreted as a boolean. If true,
1259: the link will not open a new window. If false, the link will open
1260: a new window using Javascript. (Default is false.)
1261:
1262: $width and $height are optional numerical parameters that will
1263: override the width and height of the popped up window, which may
1.973 raeburn 1264: be useful for certain help topics with big pictures included.
1265:
1266: $imgid is the id of the img tag used for the help icon. This may be
1267: used in a javascript call to switch the image src. See
1268: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1269:
1270: =cut
1271:
1272: sub help_open_topic {
1.973 raeburn 1273: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1274: $text = "" if (not defined $text);
1.44 bowersj2 1275: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1276: $width = 500 if (not defined $width);
1.44 bowersj2 1277: $height = 400 if (not defined $height);
1278: my $filename = $topic;
1279: $filename =~ s/ /_/g;
1280:
1.48 bowersj2 1281: my $template = "";
1282: my $link;
1.572 banghart 1283:
1.159 www 1284: $topic=~s/\W/\_/g;
1.44 bowersj2 1285:
1.572 banghart 1286: if (!$stayOnPage) {
1.1033 www 1287: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1288: } elsif ($stayOnPage eq 'popup') {
1289: $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 1290: } else {
1.48 bowersj2 1291: $link = "/adm/help/${filename}.hlp";
1292: }
1293:
1294: # Add the text
1.755 neumanie 1295: if ($text ne "") {
1.763 bisitz 1296: $template.='<span class="LC_help_open_topic">'
1297: .'<a target="_top" href="'.$link.'">'
1298: .$text.'</a>';
1.48 bowersj2 1299: }
1300:
1.763 bisitz 1301: # (Always) Add the graphic
1.179 matthew 1302: my $title = &mt('Online Help');
1.667 raeburn 1303: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1304: if ($imgid ne '') {
1305: $imgid = ' id="'.$imgid.'"';
1306: }
1.763 bisitz 1307: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1308: .'<img src="'.$helpicon.'" border="0"'
1309: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1310: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1311: .' /></a>';
1312: if ($text ne "") {
1313: $template.='</span>';
1314: }
1.44 bowersj2 1315: return $template;
1316:
1.106 bowersj2 1317: }
1318:
1319: # This is a quicky function for Latex cheatsheet editing, since it
1320: # appears in at least four places
1321: sub helpLatexCheatsheet {
1.1037 www 1322: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1323: my $out;
1.106 bowersj2 1324: my $addOther = '';
1.732 raeburn 1325: if ($topic) {
1.1037 www 1326: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1327: }
1328: $out = '<span>' # Start cheatsheet
1329: .$addOther
1330: .'<span>'
1.1037 www 1331: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1332: .'</span> <span>'
1.1037 www 1333: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1334: .'</span>';
1.732 raeburn 1335: unless ($not_author) {
1.1186 kruse 1336: $out .= '<span>'
1337: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1338: .'</span> <span>'
1339: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1340: .'</span>';
1.732 raeburn 1341: }
1.763 bisitz 1342: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1343: return $out;
1.172 www 1344: }
1345:
1.430 albertel 1346: sub general_help {
1347: my $helptopic='Student_Intro';
1348: if ($env{'request.role'}=~/^(ca|au)/) {
1349: $helptopic='Authoring_Intro';
1.907 raeburn 1350: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1351: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1352: } elsif ($env{'request.role'}=~/^dc/) {
1353: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1354: }
1355: return $helptopic;
1356: }
1357:
1358: sub update_help_link {
1359: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1360: my $origurl = $ENV{'REQUEST_URI'};
1361: $origurl=~s|^/~|/priv/|;
1362: my $timestamp = time;
1363: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1364: $$datum = &escape($$datum);
1365: }
1366:
1367: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1368: my $output .= <<"ENDOUTPUT";
1369: <script type="text/javascript">
1.824 bisitz 1370: // <![CDATA[
1.430 albertel 1371: banner_link = '$banner_link';
1.824 bisitz 1372: // ]]>
1.430 albertel 1373: </script>
1374: ENDOUTPUT
1375: return $output;
1376: }
1377:
1378: # now just updates the help link and generates a blue icon
1.193 raeburn 1379: sub help_open_menu {
1.430 albertel 1380: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1381: = @_;
1.949 droeschl 1382: $stayOnPage = 1;
1.430 albertel 1383: my $output;
1384: if ($component_help) {
1385: if (!$text) {
1386: $output=&help_open_topic($component_help,undef,$stayOnPage,
1387: $width,$height);
1388: } else {
1389: my $help_text;
1390: $help_text=&unescape($topic);
1391: $output='<table><tr><td>'.
1392: &help_open_topic($component_help,$help_text,$stayOnPage,
1393: $width,$height).'</td></tr></table>';
1394: }
1395: }
1396: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1397: return $output.$banner_link;
1398: }
1399:
1400: sub top_nav_help {
1401: my ($text) = @_;
1.436 albertel 1402: $text = &mt($text);
1.949 droeschl 1403: my $stay_on_page = 1;
1404:
1.1168 raeburn 1405: my ($link,$banner_link);
1406: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1407: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1408: : "javascript:helpMenu('open')";
1409: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1410: }
1.201 raeburn 1411: my $title = &mt('Get help');
1.1168 raeburn 1412: if ($link) {
1413: return <<"END";
1.436 albertel 1414: $banner_link
1.1159 raeburn 1415: <a href="$link" title="$title">$text</a>
1.436 albertel 1416: END
1.1168 raeburn 1417: } else {
1418: return ' '.$text.' ';
1419: }
1.436 albertel 1420: }
1421:
1422: sub help_menu_js {
1.1154 raeburn 1423: my ($httphost) = @_;
1.949 droeschl 1424: my $stayOnPage = 1;
1.436 albertel 1425: my $width = 620;
1426: my $height = 600;
1.430 albertel 1427: my $helptopic=&general_help();
1.1154 raeburn 1428: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1429: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1430: my $start_page =
1431: &Apache::loncommon::start_page('Help Menu', undef,
1432: {'frameset' => 1,
1433: 'js_ready' => 1,
1.1154 raeburn 1434: 'use_absolute' => $httphost,
1.331 albertel 1435: 'add_entries' => {
1.1168 raeburn 1436: 'border' => '0',
1.579 raeburn 1437: 'rows' => "110,*",},});
1.331 albertel 1438: my $end_page =
1439: &Apache::loncommon::end_page({'frameset' => 1,
1440: 'js_ready' => 1,});
1441:
1.436 albertel 1442: my $template .= <<"ENDTEMPLATE";
1443: <script type="text/javascript">
1.877 bisitz 1444: // <![CDATA[
1.253 albertel 1445: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1446: var banner_link = '';
1.243 raeburn 1447: function helpMenu(target) {
1448: var caller = this;
1449: if (target == 'open') {
1450: var newWindow = null;
1451: try {
1.262 albertel 1452: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1453: }
1454: catch(error) {
1455: writeHelp(caller);
1456: return;
1457: }
1458: if (newWindow) {
1459: caller = newWindow;
1460: }
1.193 raeburn 1461: }
1.243 raeburn 1462: writeHelp(caller);
1463: return;
1464: }
1465: function writeHelp(caller) {
1.1168 raeburn 1466: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1467: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1468: caller.document.close();
1469: caller.focus();
1.193 raeburn 1470: }
1.877 bisitz 1471: // END LON-CAPA Internal -->
1.253 albertel 1472: // ]]>
1.436 albertel 1473: </script>
1.193 raeburn 1474: ENDTEMPLATE
1475: return $template;
1476: }
1477:
1.172 www 1478: sub help_open_bug {
1479: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1480: unless ($env{'user.adv'}) { return ''; }
1.172 www 1481: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1482: $text = "" if (not defined $text);
1483: $stayOnPage=1;
1.184 albertel 1484: $width = 600 if (not defined $width);
1485: $height = 600 if (not defined $height);
1.172 www 1486:
1487: $topic=~s/\W+/\+/g;
1488: my $link='';
1489: my $template='';
1.379 albertel 1490: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1491: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1492: if (!$stayOnPage)
1493: {
1494: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1495: }
1496: else
1497: {
1498: $link = $url;
1499: }
1500: # Add the text
1501: if ($text ne "")
1502: {
1503: $template .=
1504: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1505: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1506: }
1507:
1508: # Add the graphic
1.179 matthew 1509: my $title = &mt('Report a Bug');
1.215 albertel 1510: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1511: $template .= <<"ENDTEMPLATE";
1.436 albertel 1512: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1513: ENDTEMPLATE
1514: if ($text ne '') { $template.='</td></tr></table>' };
1515: return $template;
1516:
1517: }
1518:
1519: sub help_open_faq {
1520: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1521: unless ($env{'user.adv'}) { return ''; }
1.172 www 1522: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1523: $text = "" if (not defined $text);
1524: $stayOnPage=1;
1525: $width = 350 if (not defined $width);
1526: $height = 400 if (not defined $height);
1527:
1528: $topic=~s/\W+/\+/g;
1529: my $link='';
1530: my $template='';
1531: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1532: if (!$stayOnPage)
1533: {
1534: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1535: }
1536: else
1537: {
1538: $link = $url;
1539: }
1540:
1541: # Add the text
1542: if ($text ne "")
1543: {
1544: $template .=
1.173 www 1545: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1546: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1547: }
1548:
1549: # Add the graphic
1.179 matthew 1550: my $title = &mt('View the FAQ');
1.215 albertel 1551: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1552: $template .= <<"ENDTEMPLATE";
1.436 albertel 1553: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1554: ENDTEMPLATE
1555: if ($text ne '') { $template.='</td></tr></table>' };
1556: return $template;
1557:
1.44 bowersj2 1558: }
1.37 matthew 1559:
1.180 matthew 1560: ###############################################################
1561: ###############################################################
1562:
1.45 matthew 1563: =pod
1564:
1.648 raeburn 1565: =item * &change_content_javascript():
1.256 matthew 1566:
1567: This and the next function allow you to create small sections of an
1568: otherwise static HTML page that you can update on the fly with
1569: Javascript, even in Netscape 4.
1570:
1571: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1572: must be written to the HTML page once. It will prove the Javascript
1573: function "change(name, content)". Calling the change function with the
1574: name of the section
1575: you want to update, matching the name passed to C<changable_area>, and
1576: the new content you want to put in there, will put the content into
1577: that area.
1578:
1579: B<Note>: Netscape 4 only reserves enough space for the changable area
1580: to contain room for the original contents. You need to "make space"
1581: for whatever changes you wish to make, and be B<sure> to check your
1582: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1583: it's adequate for updating a one-line status display, but little more.
1584: This script will set the space to 100% width, so you only need to
1585: worry about height in Netscape 4.
1586:
1587: Modern browsers are much less limiting, and if you can commit to the
1588: user not using Netscape 4, this feature may be used freely with
1589: pretty much any HTML.
1590:
1591: =cut
1592:
1593: sub change_content_javascript {
1594: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1595: if ($env{'browser.type'} eq 'netscape' &&
1596: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1597: return (<<NETSCAPE4);
1598: function change(name, content) {
1599: doc = document.layers[name+"___escape"].layers[0].document;
1600: doc.open();
1601: doc.write(content);
1602: doc.close();
1603: }
1604: NETSCAPE4
1605: } else {
1606: # Otherwise, we need to use semi-standards-compliant code
1607: # (technically, "innerHTML" isn't standard but the equivalent
1608: # is really scary, and every useful browser supports it
1609: return (<<DOMBASED);
1610: function change(name, content) {
1611: element = document.getElementById(name);
1612: element.innerHTML = content;
1613: }
1614: DOMBASED
1615: }
1616: }
1617:
1618: =pod
1619:
1.648 raeburn 1620: =item * &changable_area($name,$origContent):
1.256 matthew 1621:
1622: This provides a "changable area" that can be modified on the fly via
1623: the Javascript code provided in C<change_content_javascript>. $name is
1624: the name you will use to reference the area later; do not repeat the
1625: same name on a given HTML page more then once. $origContent is what
1626: the area will originally contain, which can be left blank.
1627:
1628: =cut
1629:
1630: sub changable_area {
1631: my ($name, $origContent) = @_;
1632:
1.258 albertel 1633: if ($env{'browser.type'} eq 'netscape' &&
1634: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1635: # If this is netscape 4, we need to use the Layer tag
1636: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1637: } else {
1638: return "<span id='$name'>$origContent</span>";
1639: }
1640: }
1641:
1642: =pod
1643:
1.648 raeburn 1644: =item * &viewport_geometry_js
1.590 raeburn 1645:
1646: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1647:
1648: =cut
1649:
1650:
1651: sub viewport_geometry_js {
1652: return <<"GEOMETRY";
1653: var Geometry = {};
1654: function init_geometry() {
1655: if (Geometry.init) { return };
1656: Geometry.init=1;
1657: if (window.innerHeight) {
1658: Geometry.getViewportHeight = function() { return window.innerHeight; };
1659: Geometry.getViewportWidth = function() { return window.innerWidth; };
1660: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1661: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1662: }
1663: else if (document.documentElement && document.documentElement.clientHeight) {
1664: Geometry.getViewportHeight =
1665: function() { return document.documentElement.clientHeight; };
1666: Geometry.getViewportWidth =
1667: function() { return document.documentElement.clientWidth; };
1668:
1669: Geometry.getHorizontalScroll =
1670: function() { return document.documentElement.scrollLeft; };
1671: Geometry.getVerticalScroll =
1672: function() { return document.documentElement.scrollTop; };
1673: }
1674: else if (document.body.clientHeight) {
1675: Geometry.getViewportHeight =
1676: function() { return document.body.clientHeight; };
1677: Geometry.getViewportWidth =
1678: function() { return document.body.clientWidth; };
1679: Geometry.getHorizontalScroll =
1680: function() { return document.body.scrollLeft; };
1681: Geometry.getVerticalScroll =
1682: function() { return document.body.scrollTop; };
1683: }
1684: }
1685:
1686: GEOMETRY
1687: }
1688:
1689: =pod
1690:
1.648 raeburn 1691: =item * &viewport_size_js()
1.590 raeburn 1692:
1693: 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.
1694:
1695: =cut
1696:
1697: sub viewport_size_js {
1698: my $geometry = &viewport_geometry_js();
1699: return <<"DIMS";
1700:
1701: $geometry
1702:
1703: function getViewportDims(width,height) {
1704: init_geometry();
1705: width.value = Geometry.getViewportWidth();
1706: height.value = Geometry.getViewportHeight();
1707: return;
1708: }
1709:
1710: DIMS
1711: }
1712:
1713: =pod
1714:
1.648 raeburn 1715: =item * &resize_textarea_js()
1.565 albertel 1716:
1717: emits the needed javascript to resize a textarea to be as big as possible
1718:
1719: creates a function resize_textrea that takes two IDs first should be
1720: the id of the element to resize, second should be the id of a div that
1721: surrounds everything that comes after the textarea, this routine needs
1722: to be attached to the <body> for the onload and onresize events.
1723:
1.648 raeburn 1724: =back
1.565 albertel 1725:
1726: =cut
1727:
1728: sub resize_textarea_js {
1.590 raeburn 1729: my $geometry = &viewport_geometry_js();
1.565 albertel 1730: return <<"RESIZE";
1731: <script type="text/javascript">
1.824 bisitz 1732: // <![CDATA[
1.590 raeburn 1733: $geometry
1.565 albertel 1734:
1.588 albertel 1735: function getX(element) {
1736: var x = 0;
1737: while (element) {
1738: x += element.offsetLeft;
1739: element = element.offsetParent;
1740: }
1741: return x;
1742: }
1743: function getY(element) {
1744: var y = 0;
1745: while (element) {
1746: y += element.offsetTop;
1747: element = element.offsetParent;
1748: }
1749: return y;
1750: }
1751:
1752:
1.565 albertel 1753: function resize_textarea(textarea_id,bottom_id) {
1754: init_geometry();
1755: var textarea = document.getElementById(textarea_id);
1756: //alert(textarea);
1757:
1.588 albertel 1758: var textarea_top = getY(textarea);
1.565 albertel 1759: var textarea_height = textarea.offsetHeight;
1760: var bottom = document.getElementById(bottom_id);
1.588 albertel 1761: var bottom_top = getY(bottom);
1.565 albertel 1762: var bottom_height = bottom.offsetHeight;
1763: var window_height = Geometry.getViewportHeight();
1.588 albertel 1764: var fudge = 23;
1.565 albertel 1765: var new_height = window_height-fudge-textarea_top-bottom_height;
1766: if (new_height < 300) {
1767: new_height = 300;
1768: }
1769: textarea.style.height=new_height+'px';
1770: }
1.824 bisitz 1771: // ]]>
1.565 albertel 1772: </script>
1773: RESIZE
1774:
1775: }
1776:
1.1205 golterma 1777: sub colorfuleditor_js {
1.1248 raeburn 1778: my $browse_or_search;
1779: my $respath;
1780: my ($cnum,$cdom) = &crsauthor_url();
1781: if ($cnum) {
1782: $respath = "/res/$cdom/$cnum/";
1783: my %js_lt = &Apache::lonlocal::texthash(
1784: sunm => 'Sub-directory name',
1785: save => 'Save page to make this permanent',
1786: );
1787: &js_escape(\%js_lt);
1788: $browse_or_search = <<"END";
1789:
1790: function toggleChooser(form,element,titleid,only,search) {
1791: var disp = 'none';
1792: if (document.getElementById('chooser_'+element)) {
1793: var curr = document.getElementById('chooser_'+element).style.display;
1794: if (curr == 'none') {
1795: disp='inline';
1796: if (form.elements['chooser_'+element].length) {
1797: for (var i=0; i<form.elements['chooser_'+element].length; i++) {
1798: form.elements['chooser_'+element][i].checked = false;
1799: }
1800: }
1801: toggleResImport(form,element);
1802: }
1803: document.getElementById('chooser_'+element).style.display = disp;
1804: }
1805: }
1806:
1807: function toggleCrsFile(form,element,numdirs) {
1808: if (document.getElementById('chooser_'+element+'_crsres')) {
1809: var curr = document.getElementById('chooser_'+element+'_crsres').style.display;
1810: if (curr == 'none') {
1811: if (numdirs) {
1812: form.elements['coursepath_'+element].selectedIndex = 0;
1813: if (numdirs > 1) {
1814: window['select1'+element+'_changed']();
1815: }
1816: }
1817: }
1818: document.getElementById('chooser_'+element+'_crsres').style.display = 'block';
1819:
1820: }
1821: if (document.getElementById('chooser_'+element+'_upload')) {
1822: document.getElementById('chooser_'+element+'_upload').style.display = 'none';
1823: if (document.getElementById('uploadcrsres_'+element)) {
1824: document.getElementById('uploadcrsres_'+element).value = '';
1825: }
1826: }
1827: return;
1828: }
1829:
1830: function toggleCrsUpload(form,element,numcrsdirs) {
1831: if (document.getElementById('chooser_'+element+'_crsres')) {
1832: document.getElementById('chooser_'+element+'_crsres').style.display = 'none';
1833: }
1834: if (document.getElementById('chooser_'+element+'_upload')) {
1835: var curr = document.getElementById('chooser_'+element+'_upload').style.display;
1836: if (curr == 'none') {
1837: if (numcrsdirs) {
1838: form.elements['crsauthorpath_'+element].selectedIndex = 0;
1839: form.elements['newsubdir_'+element][0].checked = true;
1840: toggleNewsubdir(form,element);
1841: }
1842: }
1843: document.getElementById('chooser_'+element+'_upload').style.display = 'block';
1844: }
1845: return;
1846: }
1847:
1848: function toggleResImport(form,element) {
1849: var choices = new Array('crsres','upload');
1850: for (var i=0; i<choices.length; i++) {
1851: if (document.getElementById('chooser_'+element+'_'+choices[i])) {
1852: document.getElementById('chooser_'+element+'_'+choices[i]).style.display = 'none';
1853: }
1854: }
1855: }
1856:
1857: function toggleNewsubdir(form,element) {
1858: var newsub = form.elements['newsubdir_'+element];
1859: if (newsub) {
1860: if (newsub.length) {
1861: for (var j=0; j<newsub.length; j++) {
1862: if (newsub[j].checked) {
1863: if (document.getElementById('newsubdirname_'+element)) {
1864: if (newsub[j].value == '1') {
1865: document.getElementById('newsubdirname_'+element).type = "text";
1866: if (document.getElementById('newsubdir_'+element)) {
1867: document.getElementById('newsubdir_'+element).innerHTML = '<br />$js_lt{sunm}';
1868: }
1869: } else {
1870: document.getElementById('newsubdirname_'+element).type = "hidden";
1871: document.getElementById('newsubdirname_'+element).value = "";
1872: document.getElementById('newsubdir_'+element).innerHTML = "";
1873: }
1874: }
1875: break;
1876: }
1877: }
1878: }
1879: }
1880: }
1881:
1882: function updateCrsFile(form,element) {
1883: var directory = form.elements['coursepath_'+element];
1884: var filename = form.elements['coursefile_'+element];
1885: var path = directory.options[directory.selectedIndex].value;
1886: var file = filename.options[filename.selectedIndex].value;
1887: form.elements[element].value = '$respath';
1888: if (path == '/') {
1889: form.elements[element].value += file;
1890: } else {
1891: form.elements[element].value += path+'/'+file;
1892: }
1893: unClean();
1894: if (document.getElementById('previewimg_'+element)) {
1895: document.getElementById('previewimg_'+element).src = form.elements[element].value;
1896: var newsrc = document.getElementById('previewimg_'+element).src;
1897: }
1898: if (document.getElementById('showimg_'+element)) {
1899: document.getElementById('showimg_'+element).innerHTML = '($js_lt{save})';
1900: }
1901: toggleChooser(form,element);
1902: return;
1903: }
1904:
1905: function uploadDone(suffix,name) {
1906: if (name) {
1907: document.forms["lonhomework"].elements[suffix].value = name;
1908: unClean();
1909: toggleChooser(document.forms["lonhomework"],suffix);
1910: }
1911: }
1912:
1913: \$(document).ready(function(){
1914:
1915: \$(document).delegate('form :submit', 'click', function( event ) {
1916: if ( \$( this ).hasClass( "LC_uploadcrsres" ) ) {
1917: var buttonId = this.id;
1918: var suffix = buttonId.toString();
1919: suffix = suffix.replace(/^crsupload_/,'');
1920: event.preventDefault();
1921: document.lonhomework.target = 'crsupload_target_'+suffix;
1922: document.lonhomework.action = '/adm/coursepub?LC_uploadcrsres='+suffix;
1923: \$(this.form).submit();
1924: document.lonhomework.target = '';
1925: if (document.getElementById('crsuploadto_'+suffix)) {
1926: document.lonhomework.action = document.getElementById('crsuploadto_'+suffix).value;
1927: }
1928: return false;
1929: }
1930: });
1931: });
1932: END
1933: }
1.1205 golterma 1934: return <<"COLORFULEDIT"
1935: <script type="text/javascript">
1936: // <![CDATA[>
1937: function fold_box(curDepth, lastresource){
1938:
1939: // we need a list because there can be several blocks you need to fold in one tag
1940: var block = document.getElementsByName('foldblock_'+curDepth);
1941: // but there is only one folding button per tag
1942: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1943:
1944: if(block.item(0).style.display == 'none'){
1945:
1946: foldbutton.value = '@{[&mt("Hide")]}';
1947: for (i = 0; i < block.length; i++){
1948: block.item(i).style.display = '';
1949: }
1950: }else{
1951:
1952: foldbutton.value = '@{[&mt("Show")]}';
1953: for (i = 0; i < block.length; i++){
1954: // block.item(i).style.visibility = 'collapse';
1955: block.item(i).style.display = 'none';
1956: }
1957: };
1958: saveState(lastresource);
1959: }
1960:
1961: function saveState (lastresource) {
1962:
1963: var tag_list = getTagList();
1964: if(tag_list != null){
1965: var timestamp = new Date().getTime();
1966: var key = lastresource;
1967:
1968: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1969: // starting with timestamp
1970: var value = timestamp+';';
1971:
1972: // building the list of key-value pairs
1973: for(var i = 0; i < tag_list.length; i++){
1974: value += tag_list[i]+',';
1975: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1976: }
1977:
1978: // only iterate whole storage if nothing to override
1979: if(localStorage.getItem(key) == null){
1980:
1981: // prevent storage from growing large
1982: if(localStorage.length > 50){
1983: var regex_getTimestamp = /^(?:\d)+;/;
1984: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1985: var oldest_key;
1986:
1987: for(var i = 1; i < localStorage.length; i++){
1988: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1989: oldest_key = localStorage.key(i);
1990: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1991: }
1992: }
1993: localStorage.removeItem(oldest_key);
1994: }
1995: }
1996: localStorage.setItem(key,value);
1997: }
1998: }
1999:
2000: // restore folding status of blocks (on page load)
2001: function restoreState (lastresource) {
2002: if(localStorage.getItem(lastresource) != null){
2003: var key = lastresource;
2004: var value = localStorage.getItem(key);
2005: var regex_delTimestamp = /^\d+;/;
2006:
2007: value.replace(regex_delTimestamp, '');
2008:
2009: var valueArr = value.split(';');
2010: var pairs;
2011: var elements;
2012: for (var i = 0; i < valueArr.length; i++){
2013: pairs = valueArr[i].split(',');
2014: elements = document.getElementsByName(pairs[0]);
2015:
2016: for (var j = 0; j < elements.length; j++){
2017: elements[j].style.display = pairs[1];
2018: if (pairs[1] == "none"){
2019: var regex_id = /([_\\d]+)\$/;
2020: regex_id.exec(pairs[0]);
2021: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
2022: }
2023: }
2024: }
2025: }
2026: }
2027:
2028: function getTagList () {
2029:
2030: var stringToSearch = document.lonhomework.innerHTML;
2031:
2032: var ret = new Array();
2033: var regex_findBlock = /(foldblock_.*?)"/g;
2034: var tag_list = stringToSearch.match(regex_findBlock);
2035:
2036: if(tag_list != null){
2037: for(var i = 0; i < tag_list.length; i++){
2038: ret.push(tag_list[i].replace(/"/, ''));
2039: }
2040: }
2041: return ret;
2042: }
2043:
2044: function saveScrollPosition (resource) {
2045: var tag_list = getTagList();
2046:
2047: // we dont always want to jump to the first block
2048: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
2049: if(\$(window).scrollTop() > 170){
2050: if(tag_list != null){
2051: var result;
2052: for(var i = 0; i < tag_list.length; i++){
2053: if(isElementInViewport(tag_list[i])){
2054: result += tag_list[i]+';';
2055: }
2056: }
2057: sessionStorage.setItem('anchor_'+resource, result);
2058: }
2059: } else {
2060: // we dont need to save zero, just delete the item to leave everything tidy
2061: sessionStorage.removeItem('anchor_'+resource);
2062: }
2063: }
2064:
2065: function restoreScrollPosition(resource){
2066:
2067: var elem = sessionStorage.getItem('anchor_'+resource);
2068: if(elem != null){
2069: var tag_list = elem.split(';');
2070: var elem_list;
2071:
2072: for(var i = 0; i < tag_list.length; i++){
2073: elem_list = document.getElementsByName(tag_list[i]);
2074:
2075: if(elem_list.length > 0){
2076: elem = elem_list[0];
2077: break;
2078: }
2079: }
2080: elem.scrollIntoView();
2081: }
2082: }
2083:
2084: function isElementInViewport(el) {
2085:
2086: // change to last element instead of first
2087: var elem = document.getElementsByName(el);
2088: var rect = elem[0].getBoundingClientRect();
2089:
2090: return (
2091: rect.top >= 0 &&
2092: rect.left >= 0 &&
2093: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
2094: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
2095: );
2096: }
2097:
2098: function autosize(depth){
2099: var cmInst = window['cm'+depth];
2100: var fitsizeButton = document.getElementById('fitsize'+depth);
2101:
2102: // is fixed size, switching to dynamic
2103: if (sessionStorage.getItem("autosized_"+depth) == null) {
2104: cmInst.setSize("","auto");
2105: fitsizeButton.value = "@{[&mt('Fixed size')]}";
2106: sessionStorage.setItem("autosized_"+depth, "yes");
2107:
2108: // is dynamic size, switching to fixed
2109: } else {
2110: cmInst.setSize("","300px");
2111: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
2112: sessionStorage.removeItem("autosized_"+depth);
2113: }
2114: }
2115:
1.1248 raeburn 2116: $browse_or_search
1.1205 golterma 2117:
2118: // ]]>
2119: </script>
2120: COLORFULEDIT
2121: }
2122:
2123: sub xmleditor_js {
2124: return <<XMLEDIT
2125: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
2126: <script type="text/javascript">
2127: // <![CDATA[>
2128:
2129: function saveScrollPosition (resource) {
2130:
2131: var scrollPos = \$(window).scrollTop();
2132: sessionStorage.setItem(resource,scrollPos);
2133: }
2134:
2135: function restoreScrollPosition(resource){
2136:
2137: var scrollPos = sessionStorage.getItem(resource);
2138: \$(window).scrollTop(scrollPos);
2139: }
2140:
2141: // unless internet explorer
2142: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
2143:
2144: \$(document).ready(function() {
2145: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
2146: });
2147: }
2148:
2149: // inserts text at cursor position into codemirror (xml editor only)
2150: function insertText(text){
2151: cm.focus();
2152: var curPos = cm.getCursor();
2153: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
2154: }
2155: // ]]>
2156: </script>
2157: XMLEDIT
2158: }
2159:
2160: sub insert_folding_button {
2161: my $curDepth = $Apache::lonxml::curdepth;
2162: my $lastresource = $env{'request.ambiguous'};
2163:
2164: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2165: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2166: }
2167:
1.1248 raeburn 2168: sub crsauthor_url {
2169: my ($url) = @_;
2170: if ($url eq '') {
2171: $url = $ENV{'REQUEST_URI'};
2172: }
2173: my ($cnum,$cdom);
2174: if ($env{'request.course.id'}) {
2175: my ($audom,$auname) = ($url =~ m{^/priv/($match_domain)/($match_name)/});
2176: if ($audom ne '' && $auname ne '') {
2177: if (($env{'course.'.$env{'request.course.id'}.'.num'} eq $auname) &&
2178: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $audom)) {
2179: $cnum = $auname;
2180: $cdom = $audom;
2181: }
2182: }
2183: }
2184: return ($cnum,$cdom);
2185: }
2186:
2187: sub import_crsauthor_form {
1.1265 raeburn 2188: my ($form,$firstselectname,$secondselectname,$onchangefirst,$only,$suffix,$disabled) = @_;
1.1248 raeburn 2189: return (0) unless ($env{'request.course.id'});
2190: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
2191: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
2192: my $crshome = $env{'course.'.$env{'request.course.id'}.'.home'};
2193: return (0) unless (($cnum ne '') && ($cdom ne ''));
2194: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
2195: my @ids=&Apache::lonnet::current_machine_ids();
2196: my ($output,$is_home,$relpath,%subdirs,%files,%selimport_menus);
2197:
2198: if (grep(/^\Q$crshome\E$/,@ids)) {
2199: $is_home = 1;
2200: }
2201: $relpath = "/priv/$cdom/$cnum";
2202: &Apache::lonnet::recursedirs($is_home,'priv',$londocroot,$relpath,'',\%subdirs,\%files);
2203: my %lt = &Apache::lonlocal::texthash (
2204: fnam => 'Filename',
2205: dire => 'Directory',
2206: );
2207: my $numdirs = scalar(keys(%files));
2208: my (%possexts,$singledir,@singledirfiles);
2209: if ($only) {
2210: map { $possexts{$_} = 1; } split(/\s*,\s*/,$only);
2211: }
2212: my (%nonemptydirs,$possdirs);
2213: if ($numdirs > 1) {
2214: my @order;
2215: foreach my $key (sort { lc($a) cmp lc($b) } (keys(%files))) {
2216: if (ref($files{$key}) eq 'HASH') {
2217: my $shown = $key;
2218: if ($key eq '') {
2219: $shown = '/';
2220: }
2221: my @ordered = ();
2222: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$key}}))) {
2223: if ($only) {
2224: my ($ext) = ($file =~ /\.([^.]+)$/);
2225: unless ($possexts{lc($ext)}) {
2226: next;
2227: }
2228: }
2229: $selimport_menus{$key}->{'select2'}->{$file} = $file;
2230: push(@ordered,$file);
2231: }
2232: if (@ordered) {
2233: push(@order,$key);
2234: $nonemptydirs{$key} = 1;
2235: $selimport_menus{$key}->{'text'} = $shown;
2236: $selimport_menus{$key}->{'default'} = '';
2237: $selimport_menus{$key}->{'select2'}->{''} = '';
2238: $selimport_menus{$key}->{'order'} = \@ordered;
2239: }
2240: }
2241: }
2242: $possdirs = scalar(keys(%nonemptydirs));
2243: if ($possdirs > 1) {
2244: my @order = sort { lc($a) cmp lc($b) } (keys(%nonemptydirs));
2245: $output = $lt{'dire'}.
2246: &linked_select_forms($form,'<br />'.
2247: $lt{'fnam'},'',
2248: $firstselectname,$secondselectname,
2249: \%selimport_menus,\@order,
2250: $onchangefirst,'',$suffix).'<br />';
2251: } elsif ($possdirs == 1) {
2252: $singledir = (keys(%nonemptydirs))[0];
2253: if (ref($selimport_menus{$singledir}->{'order'}) eq 'ARRAY') {
2254: @singledirfiles = @{$selimport_menus{$singledir}->{'order'}};
2255: }
2256: delete($selimport_menus{$singledir});
2257: }
2258: } elsif ($numdirs == 1) {
2259: $singledir = (keys(%files))[0];
2260: foreach my $file (sort { lc($a) cmp lc($b) } (keys(%{$files{$singledir}}))) {
2261: if ($only) {
2262: my ($ext) = ($file =~ /\.([^.]+)$/);
2263: unless ($possexts{lc($ext)}) {
2264: next;
2265: }
2266: }
2267: push(@singledirfiles,$file);
2268: }
2269: if (@singledirfiles) {
2270: $possdirs == 1;
2271: }
2272: }
2273: if (($possdirs == 1) && (@singledirfiles)) {
2274: my $showdir = $singledir;
2275: if ($singledir eq '') {
2276: $showdir = '/';
2277: }
2278: $output = $lt{'dire'}.
2279: '<select name="'.$firstselectname.'">'.
2280: '<option value="'.$singledir.'">'.$showdir.'</option>'."\n".
2281: '</select><br />'.
2282: $lt{'fnam'}.'<select name="'.$secondselectname.'">'."\n".
2283: '<option value="" selected="selected">'.$lt{'se'}.'</option>'."\n";
2284: foreach my $file (@singledirfiles) {
2285: $output .= '<option value="'.$file.'">'.$file.'</option>'."\n";
2286: }
2287: $output .= '</select><br />'."\n";
2288: }
2289: return ($possdirs,$output);
2290: }
2291:
1.565 albertel 2292: =pod
2293:
1.256 matthew 2294: =head1 Excel and CSV file utility routines
2295:
2296: =cut
2297:
2298: ###############################################################
2299: ###############################################################
2300:
2301: =pod
2302:
1.1162 raeburn 2303: =over 4
2304:
1.648 raeburn 2305: =item * &csv_translate($text)
1.37 matthew 2306:
1.185 www 2307: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2308: format.
2309:
2310: =cut
2311:
1.180 matthew 2312: ###############################################################
2313: ###############################################################
1.37 matthew 2314: sub csv_translate {
2315: my $text = shift;
2316: $text =~ s/\"/\"\"/g;
1.209 albertel 2317: $text =~ s/\n/ /g;
1.37 matthew 2318: return $text;
2319: }
1.180 matthew 2320:
2321: ###############################################################
2322: ###############################################################
2323:
2324: =pod
2325:
1.648 raeburn 2326: =item * &define_excel_formats()
1.180 matthew 2327:
2328: Define some commonly used Excel cell formats.
2329:
2330: Currently supported formats:
2331:
2332: =over 4
2333:
2334: =item header
2335:
2336: =item bold
2337:
2338: =item h1
2339:
2340: =item h2
2341:
2342: =item h3
2343:
1.256 matthew 2344: =item h4
2345:
2346: =item i
2347:
1.180 matthew 2348: =item date
2349:
2350: =back
2351:
2352: Inputs: $workbook
2353:
2354: Returns: $format, a hash reference.
2355:
1.1057 foxr 2356:
1.180 matthew 2357: =cut
2358:
2359: ###############################################################
2360: ###############################################################
2361: sub define_excel_formats {
2362: my ($workbook) = @_;
2363: my $format;
2364: $format->{'header'} = $workbook->add_format(bold => 1,
2365: bottom => 1,
2366: align => 'center');
2367: $format->{'bold'} = $workbook->add_format(bold=>1);
2368: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2369: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2370: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2371: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2372: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2373: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2374: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2375: return $format;
2376: }
2377:
2378: ###############################################################
2379: ###############################################################
1.113 bowersj2 2380:
2381: =pod
2382:
1.648 raeburn 2383: =item * &create_workbook()
1.255 matthew 2384:
2385: Create an Excel worksheet. If it fails, output message on the
2386: request object and return undefs.
2387:
2388: Inputs: Apache request object
2389:
2390: Returns (undef) on failure,
2391: Excel worksheet object, scalar with filename, and formats
2392: from &Apache::loncommon::define_excel_formats on success
2393:
2394: =cut
2395:
2396: ###############################################################
2397: ###############################################################
2398: sub create_workbook {
2399: my ($r) = @_;
2400: #
2401: # Create the excel spreadsheet
2402: my $filename = '/prtspool/'.
1.258 albertel 2403: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2404: time.'_'.rand(1000000000).'.xls';
2405: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2406: if (! defined($workbook)) {
2407: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2408: $r->print(
2409: '<p class="LC_error">'
2410: .&mt('Problems occurred in creating the new Excel file.')
2411: .' '.&mt('This error has been logged.')
2412: .' '.&mt('Please alert your LON-CAPA administrator.')
2413: .'</p>'
2414: );
1.255 matthew 2415: return (undef);
2416: }
2417: #
1.1014 foxr 2418: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2419: #
2420: my $format = &Apache::loncommon::define_excel_formats($workbook);
2421: return ($workbook,$filename,$format);
2422: }
2423:
2424: ###############################################################
2425: ###############################################################
2426:
2427: =pod
2428:
1.648 raeburn 2429: =item * &create_text_file()
1.113 bowersj2 2430:
1.542 raeburn 2431: Create a file to write to and eventually make available to the user.
1.256 matthew 2432: If file creation fails, outputs an error message on the request object and
2433: return undefs.
1.113 bowersj2 2434:
1.256 matthew 2435: Inputs: Apache request object, and file suffix
1.113 bowersj2 2436:
1.256 matthew 2437: Returns (undef) on failure,
2438: Filehandle and filename on success.
1.113 bowersj2 2439:
2440: =cut
2441:
1.256 matthew 2442: ###############################################################
2443: ###############################################################
2444: sub create_text_file {
2445: my ($r,$suffix) = @_;
2446: if (! defined($suffix)) { $suffix = 'txt'; };
2447: my $fh;
2448: my $filename = '/prtspool/'.
1.258 albertel 2449: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2450: time.'_'.rand(1000000000).'.'.$suffix;
2451: $fh = Apache::File->new('>/home/httpd'.$filename);
2452: if (! defined($fh)) {
2453: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2454: $r->print(
2455: '<p class="LC_error">'
2456: .&mt('Problems occurred in creating the output file.')
2457: .' '.&mt('This error has been logged.')
2458: .' '.&mt('Please alert your LON-CAPA administrator.')
2459: .'</p>'
2460: );
1.113 bowersj2 2461: }
1.256 matthew 2462: return ($fh,$filename)
1.113 bowersj2 2463: }
2464:
2465:
1.256 matthew 2466: =pod
1.113 bowersj2 2467:
2468: =back
2469:
2470: =cut
1.37 matthew 2471:
2472: ###############################################################
1.33 matthew 2473: ## Home server <option> list generating code ##
2474: ###############################################################
1.35 matthew 2475:
1.169 www 2476: # ------------------------------------------
2477:
2478: sub domain_select {
2479: my ($name,$value,$multiple)=@_;
2480: my %domains=map {
1.514 albertel 2481: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2482: } &Apache::lonnet::all_domains();
1.169 www 2483: if ($multiple) {
2484: $domains{''}=&mt('Any domain');
1.550 albertel 2485: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2486: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2487: } else {
1.550 albertel 2488: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2489: return &select_form($name,$value,\%domains);
1.169 www 2490: }
2491: }
2492:
1.282 albertel 2493: #-------------------------------------------
2494:
2495: =pod
2496:
1.519 raeburn 2497: =head1 Routines for form select boxes
2498:
2499: =over 4
2500:
1.648 raeburn 2501: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2502:
2503: Returns a string containing a <select> element int multiple mode
2504:
2505:
2506: Args:
2507: $name - name of the <select> element
1.506 raeburn 2508: $value - scalar or array ref of values that should already be selected
1.282 albertel 2509: $size - number of rows long the select element is
1.283 albertel 2510: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2511: (shown text should already have been &mt())
1.506 raeburn 2512: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2513:
1.282 albertel 2514: =cut
2515:
2516: #-------------------------------------------
1.169 www 2517: sub multiple_select_form {
1.284 albertel 2518: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2519: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2520: my $output='';
1.191 matthew 2521: if (! defined($size)) {
2522: $size = 4;
1.283 albertel 2523: if (scalar(keys(%$hash))<4) {
2524: $size = scalar(keys(%$hash));
1.191 matthew 2525: }
2526: }
1.734 bisitz 2527: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2528: my @order;
1.506 raeburn 2529: if (ref($order) eq 'ARRAY') {
2530: @order = @{$order};
2531: } else {
2532: @order = sort(keys(%$hash));
1.501 banghart 2533: }
2534: if (exists($$hash{'select_form_order'})) {
2535: @order = @{$$hash{'select_form_order'}};
2536: }
2537:
1.284 albertel 2538: foreach my $key (@order) {
1.356 albertel 2539: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2540: $output.='selected="selected" ' if ($selected{$key});
2541: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2542: }
2543: $output.="</select>\n";
2544: return $output;
2545: }
2546:
1.88 www 2547: #-------------------------------------------
2548:
2549: =pod
2550:
1.1254 raeburn 2551: =item * &select_form($defdom,$name,$hashref,$onchange,$readonly)
1.88 www 2552:
2553: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2554: allow a user to select options from a ref to a hash containing:
2555: option_name => displayed text. An optional $onchange can include
1.1254 raeburn 2556: a javascript onchange item, e.g., onchange="this.form.submit();".
2557: An optional arg -- $readonly -- if true will cause the select form
2558: to be disabled, e.g., for the case where an instructor has a section-
2559: specific role, and is viewing/modifying parameters.
1.970 raeburn 2560:
1.88 www 2561: See lonrights.pm for an example invocation and use.
2562:
2563: =cut
2564:
2565: #-------------------------------------------
2566: sub select_form {
1.1228 raeburn 2567: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2568: return unless (ref($hashref) eq 'HASH');
2569: if ($onchange) {
2570: $onchange = ' onchange="'.$onchange.'"';
2571: }
1.1228 raeburn 2572: my $disabled;
2573: if ($readonly) {
2574: $disabled = ' disabled="disabled"';
2575: }
2576: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2577: my @keys;
1.970 raeburn 2578: if (exists($hashref->{'select_form_order'})) {
2579: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2580: } else {
1.970 raeburn 2581: @keys=sort(keys(%{$hashref}));
1.128 albertel 2582: }
1.356 albertel 2583: foreach my $key (@keys) {
2584: $selectform.=
2585: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2586: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2587: ">".$hashref->{$key}."</option>\n";
1.88 www 2588: }
2589: $selectform.="</select>";
2590: return $selectform;
2591: }
2592:
1.475 www 2593: # For display filters
2594:
2595: sub display_filter {
1.1074 raeburn 2596: my ($context) = @_;
1.475 www 2597: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2598: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2599: my $phraseinput = 'hidden';
2600: my $includeinput = 'hidden';
2601: my ($checked,$includetypestext);
2602: if ($env{'form.displayfilter'} eq 'containing') {
2603: $phraseinput = 'text';
2604: if ($context eq 'parmslog') {
2605: $includeinput = 'checkbox';
2606: if ($env{'form.includetypes'}) {
2607: $checked = ' checked="checked"';
2608: }
2609: $includetypestext = &mt('Include parameter types');
2610: }
2611: } else {
2612: $includetypestext = ' ';
2613: }
2614: my ($additional,$secondid,$thirdid);
2615: if ($context eq 'parmslog') {
2616: $additional =
2617: '<label><input type="'.$includeinput.'" name="includetypes"'.
2618: $checked.' name="includetypes" value="1" id="includetypes" />'.
2619: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2620: '</label>';
2621: $secondid = 'includetypes';
2622: $thirdid = 'includetypestext';
2623: }
2624: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2625: '$secondid','$thirdid')";
2626: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2627: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2628: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2629: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2630: &mt('Filter: [_1]',
1.477 www 2631: &select_form($env{'form.displayfilter'},
2632: 'displayfilter',
1.970 raeburn 2633: {'currentfolder' => 'Current folder/page',
1.477 www 2634: 'containing' => 'Containing phrase',
1.1074 raeburn 2635: 'none' => 'None'},$onchange)).' '.
2636: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2637: &HTML::Entities::encode($env{'form.containingphrase'}).
2638: '" />'.$additional;
2639: }
2640:
2641: sub display_filter_js {
2642: my $includetext = &mt('Include parameter types');
2643: return <<"ENDJS";
2644:
2645: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2646: var firstType = 'hidden';
2647: if (setter.options[setter.selectedIndex].value == 'containing') {
2648: firstType = 'text';
2649: }
2650: firstObject = document.getElementById(firstid);
2651: if (typeof(firstObject) == 'object') {
2652: if (firstObject.type != firstType) {
2653: changeInputType(firstObject,firstType);
2654: }
2655: }
2656: if (context == 'parmslog') {
2657: var secondType = 'hidden';
2658: if (firstType == 'text') {
2659: secondType = 'checkbox';
2660: }
2661: secondObject = document.getElementById(secondid);
2662: if (typeof(secondObject) == 'object') {
2663: if (secondObject.type != secondType) {
2664: changeInputType(secondObject,secondType);
2665: }
2666: }
2667: var textItem = document.getElementById(thirdid);
2668: var currtext = textItem.innerHTML;
2669: var newtext;
2670: if (firstType == 'text') {
2671: newtext = '$includetext';
2672: } else {
2673: newtext = ' ';
2674: }
2675: if (currtext != newtext) {
2676: textItem.innerHTML = newtext;
2677: }
2678: }
2679: return;
2680: }
2681:
2682: function changeInputType(oldObject,newType) {
2683: var newObject = document.createElement('input');
2684: newObject.type = newType;
2685: if (oldObject.size) {
2686: newObject.size = oldObject.size;
2687: }
2688: if (oldObject.value) {
2689: newObject.value = oldObject.value;
2690: }
2691: if (oldObject.name) {
2692: newObject.name = oldObject.name;
2693: }
2694: if (oldObject.id) {
2695: newObject.id = oldObject.id;
2696: }
2697: oldObject.parentNode.replaceChild(newObject,oldObject);
2698: return;
2699: }
2700:
2701: ENDJS
1.475 www 2702: }
2703:
1.167 www 2704: sub gradeleveldescription {
2705: my $gradelevel=shift;
2706: my %gradelevels=(0 => 'Not specified',
2707: 1 => 'Grade 1',
2708: 2 => 'Grade 2',
2709: 3 => 'Grade 3',
2710: 4 => 'Grade 4',
2711: 5 => 'Grade 5',
2712: 6 => 'Grade 6',
2713: 7 => 'Grade 7',
2714: 8 => 'Grade 8',
2715: 9 => 'Grade 9',
2716: 10 => 'Grade 10',
2717: 11 => 'Grade 11',
2718: 12 => 'Grade 12',
2719: 13 => 'Grade 13',
2720: 14 => '100 Level',
2721: 15 => '200 Level',
2722: 16 => '300 Level',
2723: 17 => '400 Level',
2724: 18 => 'Graduate Level');
2725: return &mt($gradelevels{$gradelevel});
2726: }
2727:
1.163 www 2728: sub select_level_form {
2729: my ($deflevel,$name)=@_;
2730: unless ($deflevel) { $deflevel=0; }
1.167 www 2731: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2732: for (my $i=0; $i<=18; $i++) {
2733: $selectform.="<option value=\"$i\" ".
1.253 albertel 2734: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2735: ">".&gradeleveldescription($i)."</option>\n";
2736: }
2737: $selectform.="</select>";
2738: return $selectform;
1.163 www 2739: }
1.167 www 2740:
1.35 matthew 2741: #-------------------------------------------
2742:
1.45 matthew 2743: =pod
2744:
1.1256 raeburn 2745: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled)
1.35 matthew 2746:
2747: Returns a string containing a <select name='$name' size='1'> form to
2748: allow a user to select the domain to preform an operation in.
2749: See loncreateuser.pm for an example invocation and use.
2750:
1.90 www 2751: If the $includeempty flag is set, it also includes an empty choice ("no domain
2752: selected");
2753:
1.743 raeburn 2754: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2755:
1.910 raeburn 2756: 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.
2757:
1.1121 raeburn 2758: The optional $incdoms is a reference to an array of domains which will be the only available options.
2759:
2760: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2761:
1.1256 raeburn 2762: The optional $disabled argument, if true, adds the disabled attribute to the select tag.
2763:
1.35 matthew 2764: =cut
2765:
2766: #-------------------------------------------
1.34 matthew 2767: sub select_dom_form {
1.1256 raeburn 2768: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms,$disabled) = @_;
1.872 raeburn 2769: if ($onchange) {
1.874 raeburn 2770: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2771: }
1.1256 raeburn 2772: if ($disabled) {
2773: $disabled = ' disabled="disabled"';
2774: }
1.1121 raeburn 2775: my (@domains,%exclude);
1.910 raeburn 2776: if (ref($incdoms) eq 'ARRAY') {
2777: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2778: } else {
2779: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2780: }
1.90 www 2781: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2782: if (ref($excdoms) eq 'ARRAY') {
2783: map { $exclude{$_} = 1; } @{$excdoms};
2784: }
1.1256 raeburn 2785: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.356 albertel 2786: foreach my $dom (@domains) {
1.1121 raeburn 2787: next if ($exclude{$dom});
1.356 albertel 2788: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2789: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2790: if ($showdomdesc) {
2791: if ($dom ne '') {
2792: my $domdesc = &Apache::lonnet::domain($dom,'description');
2793: if ($domdesc ne '') {
2794: $selectdomain .= ' ('.$domdesc.')';
2795: }
2796: }
2797: }
2798: $selectdomain .= "</option>\n";
1.34 matthew 2799: }
2800: $selectdomain.="</select>";
2801: return $selectdomain;
2802: }
2803:
1.35 matthew 2804: #-------------------------------------------
2805:
1.45 matthew 2806: =pod
2807:
1.648 raeburn 2808: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2809:
1.586 raeburn 2810: input: 4 arguments (two required, two optional) -
2811: $domain - domain of new user
2812: $name - name of form element
2813: $default - Value of 'default' causes a default item to be first
2814: option, and selected by default.
2815: $hide - Value of 'hide' causes hiding of the name of the server,
2816: if 1 server found, or default, if 0 found.
1.594 raeburn 2817: output: returns 2 items:
1.586 raeburn 2818: (a) form element which contains either:
2819: (i) <select name="$name">
2820: <option value="$hostid1">$hostid $servers{$hostid}</option>
2821: <option value="$hostid2">$hostid $servers{$hostid}</option>
2822: </select>
2823: form item if there are multiple library servers in $domain, or
2824: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2825: if there is only one library server in $domain.
2826:
2827: (b) number of library servers found.
2828:
2829: See loncreateuser.pm for example of use.
1.35 matthew 2830:
2831: =cut
2832:
2833: #-------------------------------------------
1.586 raeburn 2834: sub home_server_form_item {
2835: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2836: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2837: my $result;
2838: my $numlib = keys(%servers);
2839: if ($numlib > 1) {
2840: $result .= '<select name="'.$name.'" />'."\n";
2841: if ($default) {
1.804 bisitz 2842: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2843: '</option>'."\n";
2844: }
2845: foreach my $hostid (sort(keys(%servers))) {
2846: $result.= '<option value="'.$hostid.'">'.
2847: $hostid.' '.$servers{$hostid}."</option>\n";
2848: }
2849: $result .= '</select>'."\n";
2850: } elsif ($numlib == 1) {
2851: my $hostid;
2852: foreach my $item (keys(%servers)) {
2853: $hostid = $item;
2854: }
2855: $result .= '<input type="hidden" name="'.$name.'" value="'.
2856: $hostid.'" />';
2857: if (!$hide) {
2858: $result .= $hostid.' '.$servers{$hostid};
2859: }
2860: $result .= "\n";
2861: } elsif ($default) {
2862: $result .= '<input type="hidden" name="'.$name.
2863: '" value="default" />';
2864: if (!$hide) {
2865: $result .= &mt('default');
2866: }
2867: $result .= "\n";
1.33 matthew 2868: }
1.586 raeburn 2869: return ($result,$numlib);
1.33 matthew 2870: }
1.112 bowersj2 2871:
2872: =pod
2873:
1.534 albertel 2874: =back
2875:
1.112 bowersj2 2876: =cut
1.87 matthew 2877:
2878: ###############################################################
1.112 bowersj2 2879: ## Decoding User Agent ##
1.87 matthew 2880: ###############################################################
2881:
2882: =pod
2883:
1.112 bowersj2 2884: =head1 Decoding the User Agent
2885:
2886: =over 4
2887:
2888: =item * &decode_user_agent()
1.87 matthew 2889:
2890: Inputs: $r
2891:
2892: Outputs:
2893:
2894: =over 4
2895:
1.112 bowersj2 2896: =item * $httpbrowser
1.87 matthew 2897:
1.112 bowersj2 2898: =item * $clientbrowser
1.87 matthew 2899:
1.112 bowersj2 2900: =item * $clientversion
1.87 matthew 2901:
1.112 bowersj2 2902: =item * $clientmathml
1.87 matthew 2903:
1.112 bowersj2 2904: =item * $clientunicode
1.87 matthew 2905:
1.112 bowersj2 2906: =item * $clientos
1.87 matthew 2907:
1.1137 raeburn 2908: =item * $clientmobile
2909:
1.1141 raeburn 2910: =item * $clientinfo
2911:
1.1194 raeburn 2912: =item * $clientosversion
2913:
1.87 matthew 2914: =back
2915:
1.157 matthew 2916: =back
2917:
1.87 matthew 2918: =cut
2919:
2920: ###############################################################
2921: ###############################################################
2922: sub decode_user_agent {
1.247 albertel 2923: my ($r)=@_;
1.87 matthew 2924: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2925: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2926: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2927: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2928: my $clientbrowser='unknown';
2929: my $clientversion='0';
2930: my $clientmathml='';
2931: my $clientunicode='0';
1.1137 raeburn 2932: my $clientmobile=0;
1.1194 raeburn 2933: my $clientosversion='';
1.87 matthew 2934: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2935: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2936: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2937: $clientbrowser=$bname;
2938: $httpbrowser=~/$vreg/i;
2939: $clientversion=$1;
2940: $clientmathml=($clientversion>=$minv);
2941: $clientunicode=($clientversion>=$univ);
2942: }
2943: }
2944: my $clientos='unknown';
1.1141 raeburn 2945: my $clientinfo;
1.87 matthew 2946: if (($httpbrowser=~/linux/i) ||
2947: ($httpbrowser=~/unix/i) ||
2948: ($httpbrowser=~/ux/i) ||
2949: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2950: if (($httpbrowser=~/vax/i) ||
2951: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2952: if ($httpbrowser=~/next/i) { $clientos='next'; }
2953: if (($httpbrowser=~/mac/i) ||
2954: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2955: if ($httpbrowser=~/win/i) {
2956: $clientos='win';
2957: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2958: $clientosversion = $1;
2959: }
2960: }
1.87 matthew 2961: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2962: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2963: $clientmobile=lc($1);
2964: }
1.1141 raeburn 2965: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2966: $clientinfo = 'firefox-'.$1;
2967: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2968: $clientinfo = 'chromeframe-'.$1;
2969: }
1.87 matthew 2970: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 2971: $clientunicode,$clientos,$clientmobile,$clientinfo,
2972: $clientosversion);
1.87 matthew 2973: }
2974:
1.32 matthew 2975: ###############################################################
2976: ## Authentication changing form generation subroutines ##
2977: ###############################################################
2978: ##
2979: ## All of the authform_xxxxxxx subroutines take their inputs in a
2980: ## hash, and have reasonable default values.
2981: ##
2982: ## formname = the name given in the <form> tag.
1.35 matthew 2983: #-------------------------------------------
2984:
1.45 matthew 2985: =pod
2986:
1.112 bowersj2 2987: =head1 Authentication Routines
2988:
2989: =over 4
2990:
1.648 raeburn 2991: =item * &authform_xxxxxx()
1.35 matthew 2992:
2993: The authform_xxxxxx subroutines provide javascript and html forms which
2994: handle some of the conveniences required for authentication forms.
2995: This is not an optimal method, but it works.
2996:
2997: =over 4
2998:
1.112 bowersj2 2999: =item * authform_header
1.35 matthew 3000:
1.112 bowersj2 3001: =item * authform_authorwarning
1.35 matthew 3002:
1.112 bowersj2 3003: =item * authform_nochange
1.35 matthew 3004:
1.112 bowersj2 3005: =item * authform_kerberos
1.35 matthew 3006:
1.112 bowersj2 3007: =item * authform_internal
1.35 matthew 3008:
1.112 bowersj2 3009: =item * authform_filesystem
1.35 matthew 3010:
3011: =back
3012:
1.648 raeburn 3013: See loncreateuser.pm for invocation and use examples.
1.157 matthew 3014:
1.35 matthew 3015: =cut
3016:
3017: #-------------------------------------------
1.32 matthew 3018: sub authform_header{
3019: my %in = (
3020: formname => 'cu',
1.80 albertel 3021: kerb_def_dom => '',
1.32 matthew 3022: @_,
3023: );
3024: $in{'formname'} = 'document.' . $in{'formname'};
3025: my $result='';
1.80 albertel 3026:
3027: #---------------------------------------------- Code for upper case translation
3028: my $Javascript_toUpperCase;
3029: unless ($in{kerb_def_dom}) {
3030: $Javascript_toUpperCase =<<"END";
3031: switch (choice) {
3032: case 'krb': currentform.elements[choicearg].value =
3033: currentform.elements[choicearg].value.toUpperCase();
3034: break;
3035: default:
3036: }
3037: END
3038: } else {
3039: $Javascript_toUpperCase = "";
3040: }
3041:
1.165 raeburn 3042: my $radioval = "'nochange'";
1.591 raeburn 3043: if (defined($in{'curr_authtype'})) {
3044: if ($in{'curr_authtype'} ne '') {
3045: $radioval = "'".$in{'curr_authtype'}."arg'";
3046: }
1.174 matthew 3047: }
1.165 raeburn 3048: my $argfield = 'null';
1.591 raeburn 3049: if (defined($in{'mode'})) {
1.165 raeburn 3050: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 3051: if (defined($in{'curr_autharg'})) {
3052: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 3053: $argfield = "'$in{'curr_autharg'}'";
3054: }
3055: }
3056: }
3057: }
3058:
1.32 matthew 3059: $result.=<<"END";
3060: var current = new Object();
1.165 raeburn 3061: current.radiovalue = $radioval;
3062: current.argfield = $argfield;
1.32 matthew 3063:
3064: function changed_radio(choice,currentform) {
3065: var choicearg = choice + 'arg';
3066: // If a radio button in changed, we need to change the argfield
3067: if (current.radiovalue != choice) {
3068: current.radiovalue = choice;
3069: if (current.argfield != null) {
3070: currentform.elements[current.argfield].value = '';
3071: }
3072: if (choice == 'nochange') {
3073: current.argfield = null;
3074: } else {
3075: current.argfield = choicearg;
3076: switch(choice) {
3077: case 'krb':
3078: currentform.elements[current.argfield].value =
3079: "$in{'kerb_def_dom'}";
3080: break;
3081: default:
3082: break;
3083: }
3084: }
3085: }
3086: return;
3087: }
1.22 www 3088:
1.32 matthew 3089: function changed_text(choice,currentform) {
3090: var choicearg = choice + 'arg';
3091: if (currentform.elements[choicearg].value !='') {
1.80 albertel 3092: $Javascript_toUpperCase
1.32 matthew 3093: // clear old field
3094: if ((current.argfield != choicearg) && (current.argfield != null)) {
3095: currentform.elements[current.argfield].value = '';
3096: }
3097: current.argfield = choicearg;
3098: }
3099: set_auth_radio_buttons(choice,currentform);
3100: return;
1.20 www 3101: }
1.32 matthew 3102:
3103: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 3104: var numauthchoices = currentform.login.length;
3105: if (typeof numauthchoices == "undefined") {
3106: return;
3107: }
1.32 matthew 3108: var i=0;
1.986 raeburn 3109: while (i < numauthchoices) {
1.32 matthew 3110: if (currentform.login[i].value == newvalue) { break; }
3111: i++;
3112: }
1.986 raeburn 3113: if (i == numauthchoices) {
1.32 matthew 3114: return;
3115: }
3116: current.radiovalue = newvalue;
3117: currentform.login[i].checked = true;
3118: return;
3119: }
3120: END
3121: return $result;
3122: }
3123:
1.1106 raeburn 3124: sub authform_authorwarning {
1.32 matthew 3125: my $result='';
1.144 matthew 3126: $result='<i>'.
3127: &mt('As a general rule, only authors or co-authors should be '.
3128: 'filesystem authenticated '.
3129: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 3130: return $result;
3131: }
3132:
1.1106 raeburn 3133: sub authform_nochange {
1.32 matthew 3134: my %in = (
3135: formname => 'document.cu',
3136: kerb_def_dom => 'MSU.EDU',
3137: @_,
3138: );
1.1106 raeburn 3139: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 3140: my $result;
1.1104 raeburn 3141: if (!$authnum) {
1.1105 raeburn 3142: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 3143: } else {
3144: $result = '<label>'.&mt('[_1] Do not change login data',
3145: '<input type="radio" name="login" value="nochange" '.
3146: 'checked="checked" onclick="'.
1.281 albertel 3147: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
3148: '</label>';
1.586 raeburn 3149: }
1.32 matthew 3150: return $result;
3151: }
3152:
1.591 raeburn 3153: sub authform_kerberos {
1.32 matthew 3154: my %in = (
3155: formname => 'document.cu',
3156: kerb_def_dom => 'MSU.EDU',
1.80 albertel 3157: kerb_def_auth => 'krb4',
1.32 matthew 3158: @_,
3159: );
1.586 raeburn 3160: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
1.1259 raeburn 3161: $autharg,$jscall,$disabled);
1.1106 raeburn 3162: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 3163: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 3164: $check5 = ' checked="checked"';
1.80 albertel 3165: } else {
1.772 bisitz 3166: $check4 = ' checked="checked"';
1.80 albertel 3167: }
1.1259 raeburn 3168: if ($in{'readonly'}) {
3169: $disabled = ' disabled="disabled"';
3170: }
1.165 raeburn 3171: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 3172: if (defined($in{'curr_authtype'})) {
3173: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 3174: $krbcheck = ' checked="checked"';
1.623 raeburn 3175: if (defined($in{'mode'})) {
3176: if ($in{'mode'} eq 'modifyuser') {
3177: $krbcheck = '';
3178: }
3179: }
1.591 raeburn 3180: if (defined($in{'curr_kerb_ver'})) {
3181: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 3182: $check5 = ' checked="checked"';
1.591 raeburn 3183: $check4 = '';
3184: } else {
1.772 bisitz 3185: $check4 = ' checked="checked"';
1.591 raeburn 3186: $check5 = '';
3187: }
1.586 raeburn 3188: }
1.591 raeburn 3189: if (defined($in{'curr_autharg'})) {
1.165 raeburn 3190: $krbarg = $in{'curr_autharg'};
3191: }
1.586 raeburn 3192: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 3193: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3194: $result =
3195: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
3196: $in{'curr_autharg'},$krbver);
3197: } else {
3198: $result =
3199: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
3200: }
3201: return $result;
3202: }
3203: }
3204: } else {
3205: if ($authnum == 1) {
1.784 bisitz 3206: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 3207: }
3208: }
1.586 raeburn 3209: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
3210: return;
1.587 raeburn 3211: } elsif ($authtype eq '') {
1.591 raeburn 3212: if (defined($in{'mode'})) {
1.587 raeburn 3213: if ($in{'mode'} eq 'modifycourse') {
3214: if ($authnum == 1) {
1.1259 raeburn 3215: $authtype = '<input type="radio" name="login" value="krb"'.$disabled.' />';
1.587 raeburn 3216: }
3217: }
3218: }
1.586 raeburn 3219: }
3220: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
3221: if ($authtype eq '') {
3222: $authtype = '<input type="radio" name="login" value="krb" '.
3223: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
1.1259 raeburn 3224: $krbcheck.$disabled.' />';
1.586 raeburn 3225: }
3226: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 3227: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 3228: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 3229: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 3230: $in{'curr_authtype'} eq 'krb4')) {
3231: $result .= &mt
1.144 matthew 3232: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 3233: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 3234: '<label>'.$authtype,
1.281 albertel 3235: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 3236: 'value="'.$krbarg.'" '.
1.1259 raeburn 3237: 'onchange="'.$jscall.'"'.$disabled.' />',
3238: '<label><input type="radio" name="krbver" value="4" '.$check4.$disabled.' />',
3239: '</label><label><input type="radio" name="krbver" value="5" '.$check5.$disabled.' />',
1.281 albertel 3240: '</label>');
1.586 raeburn 3241: } elsif ($can_assign{'krb4'}) {
3242: $result .= &mt
3243: ('[_1] Kerberos authenticated with domain [_2] '.
3244: '[_3] Version 4 [_4]',
3245: '<label>'.$authtype,
3246: '</label><input type="text" size="10" name="krbarg" '.
3247: 'value="'.$krbarg.'" '.
1.1259 raeburn 3248: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3249: '<label><input type="hidden" name="krbver" value="4" />',
3250: '</label>');
3251: } elsif ($can_assign{'krb5'}) {
3252: $result .= &mt
3253: ('[_1] Kerberos authenticated with domain [_2] '.
3254: '[_3] Version 5 [_4]',
3255: '<label>'.$authtype,
3256: '</label><input type="text" size="10" name="krbarg" '.
3257: 'value="'.$krbarg.'" '.
1.1259 raeburn 3258: 'onchange="'.$jscall.'"'.$disabled.' />',
1.586 raeburn 3259: '<label><input type="hidden" name="krbver" value="5" />',
3260: '</label>');
3261: }
1.32 matthew 3262: return $result;
3263: }
3264:
1.1106 raeburn 3265: sub authform_internal {
1.586 raeburn 3266: my %in = (
1.32 matthew 3267: formname => 'document.cu',
3268: kerb_def_dom => 'MSU.EDU',
3269: @_,
3270: );
1.1259 raeburn 3271: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3272: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3273: if ($in{'readonly'}) {
3274: $disabled = ' disabled="disabled"';
3275: }
1.591 raeburn 3276: if (defined($in{'curr_authtype'})) {
3277: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 3278: if ($can_assign{'int'}) {
1.772 bisitz 3279: $intcheck = 'checked="checked" ';
1.623 raeburn 3280: if (defined($in{'mode'})) {
3281: if ($in{'mode'} eq 'modifyuser') {
3282: $intcheck = '';
3283: }
3284: }
1.591 raeburn 3285: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3286: $intarg = $in{'curr_autharg'};
3287: }
3288: } else {
3289: $result = &mt('Currently internally authenticated.');
3290: return $result;
1.165 raeburn 3291: }
3292: }
1.586 raeburn 3293: } else {
3294: if ($authnum == 1) {
1.784 bisitz 3295: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3296: }
3297: }
3298: if (!$can_assign{'int'}) {
3299: return;
1.587 raeburn 3300: } elsif ($authtype eq '') {
1.591 raeburn 3301: if (defined($in{'mode'})) {
1.587 raeburn 3302: if ($in{'mode'} eq 'modifycourse') {
3303: if ($authnum == 1) {
1.1259 raeburn 3304: $authtype = '<input type="radio" name="login" value="int"'.$disabled.' />';
1.587 raeburn 3305: }
3306: }
3307: }
1.165 raeburn 3308: }
1.586 raeburn 3309: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3310: if ($authtype eq '') {
3311: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
1.1259 raeburn 3312: ' onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3313: }
1.605 bisitz 3314: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.1259 raeburn 3315: $intarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3316: $result = &mt
1.144 matthew 3317: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3318: '<label>'.$authtype,'</label>'.$autharg);
1.1259 raeburn 3319: $result.='<label><input type="checkbox" name="visible" onclick="if (this.checked) { this.form.intarg.type='."'text'".' } else { this.form.intarg.type='."'password'".' }"'.$disabled.' />'.&mt('Visible input').'</label>';
1.32 matthew 3320: return $result;
3321: }
3322:
1.1104 raeburn 3323: sub authform_local {
1.32 matthew 3324: my %in = (
3325: formname => 'document.cu',
3326: kerb_def_dom => 'MSU.EDU',
3327: @_,
3328: );
1.1259 raeburn 3329: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3330: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3331: if ($in{'readonly'}) {
3332: $disabled = ' disabled="disabled"';
3333: }
1.591 raeburn 3334: if (defined($in{'curr_authtype'})) {
3335: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3336: if ($can_assign{'loc'}) {
1.772 bisitz 3337: $loccheck = 'checked="checked" ';
1.623 raeburn 3338: if (defined($in{'mode'})) {
3339: if ($in{'mode'} eq 'modifyuser') {
3340: $loccheck = '';
3341: }
3342: }
1.591 raeburn 3343: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3344: $locarg = $in{'curr_autharg'};
3345: }
3346: } else {
3347: $result = &mt('Currently using local (institutional) authentication.');
3348: return $result;
1.165 raeburn 3349: }
3350: }
1.586 raeburn 3351: } else {
3352: if ($authnum == 1) {
1.784 bisitz 3353: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3354: }
3355: }
3356: if (!$can_assign{'loc'}) {
3357: return;
1.587 raeburn 3358: } elsif ($authtype eq '') {
1.591 raeburn 3359: if (defined($in{'mode'})) {
1.587 raeburn 3360: if ($in{'mode'} eq 'modifycourse') {
3361: if ($authnum == 1) {
1.1259 raeburn 3362: $authtype = '<input type="radio" name="login" value="loc"'.$disabled.' />';
1.587 raeburn 3363: }
3364: }
3365: }
1.165 raeburn 3366: }
1.586 raeburn 3367: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3368: if ($authtype eq '') {
3369: $authtype = '<input type="radio" name="login" value="loc" '.
3370: $loccheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3371: $jscall.'"'.$disabled.' />';
1.586 raeburn 3372: }
3373: $autharg = '<input type="text" size="10" name="locarg" value="'.
1.1259 raeburn 3374: $locarg.'" onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3375: $result = &mt('[_1] Local Authentication with argument [_2]',
3376: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3377: return $result;
3378: }
3379:
1.1106 raeburn 3380: sub authform_filesystem {
1.32 matthew 3381: my %in = (
3382: formname => 'document.cu',
3383: kerb_def_dom => 'MSU.EDU',
3384: @_,
3385: );
1.1259 raeburn 3386: my ($fsyscheck,$result,$authtype,$autharg,$jscall,$disabled);
1.1106 raeburn 3387: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.1259 raeburn 3388: if ($in{'readonly'}) {
3389: $disabled = ' disabled="disabled"';
3390: }
1.591 raeburn 3391: if (defined($in{'curr_authtype'})) {
3392: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3393: if ($can_assign{'fsys'}) {
1.772 bisitz 3394: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3395: if (defined($in{'mode'})) {
3396: if ($in{'mode'} eq 'modifyuser') {
3397: $fsyscheck = '';
3398: }
3399: }
1.586 raeburn 3400: } else {
3401: $result = &mt('Currently Filesystem Authenticated.');
3402: return $result;
1.1259 raeburn 3403: }
1.586 raeburn 3404: }
3405: } else {
3406: if ($authnum == 1) {
1.784 bisitz 3407: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3408: }
3409: }
3410: if (!$can_assign{'fsys'}) {
3411: return;
1.587 raeburn 3412: } elsif ($authtype eq '') {
1.591 raeburn 3413: if (defined($in{'mode'})) {
1.587 raeburn 3414: if ($in{'mode'} eq 'modifycourse') {
3415: if ($authnum == 1) {
1.1259 raeburn 3416: $authtype = '<input type="radio" name="login" value="fsys"'.$disabled.' />';
1.587 raeburn 3417: }
3418: }
3419: }
1.586 raeburn 3420: }
3421: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3422: if ($authtype eq '') {
3423: $authtype = '<input type="radio" name="login" value="fsys" '.
3424: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
1.1259 raeburn 3425: $jscall.'"'.$disabled.' />';
1.586 raeburn 3426: }
3427: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
1.1259 raeburn 3428: ' onchange="'.$jscall.'"'.$disabled.' />';
1.586 raeburn 3429: $result = &mt
1.144 matthew 3430: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 3431: '<label><input type="radio" name="login" value="fsys" '.
1.1259 raeburn 3432: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'"'.$disabled.' />',
1.605 bisitz 3433: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.1259 raeburn 3434: 'onchange="'.$jscall.'"'.$disabled.' />');
1.32 matthew 3435: return $result;
3436: }
3437:
1.586 raeburn 3438: sub get_assignable_auth {
3439: my ($dom) = @_;
3440: if ($dom eq '') {
3441: $dom = $env{'request.role.domain'};
3442: }
3443: my %can_assign = (
3444: krb4 => 1,
3445: krb5 => 1,
3446: int => 1,
3447: loc => 1,
3448: );
3449: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3450: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3451: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3452: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3453: my $context;
3454: if ($env{'request.role'} =~ /^au/) {
3455: $context = 'author';
1.1259 raeburn 3456: } elsif ($env{'request.role'} =~ /^(dc|dh)/) {
1.586 raeburn 3457: $context = 'domain';
3458: } elsif ($env{'request.course.id'}) {
3459: $context = 'course';
3460: }
3461: if ($context) {
3462: if (ref($authhash->{$context}) eq 'HASH') {
3463: %can_assign = %{$authhash->{$context}};
3464: }
3465: }
3466: }
3467: }
3468: my $authnum = 0;
3469: foreach my $key (keys(%can_assign)) {
3470: if ($can_assign{$key}) {
3471: $authnum ++;
3472: }
3473: }
3474: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3475: $authnum --;
3476: }
3477: return ($authnum,%can_assign);
3478: }
3479:
1.80 albertel 3480: ###############################################################
3481: ## Get Kerberos Defaults for Domain ##
3482: ###############################################################
3483: ##
3484: ## Returns default kerberos version and an associated argument
3485: ## as listed in file domain.tab. If not listed, provides
3486: ## appropriate default domain and kerberos version.
3487: ##
3488: #-------------------------------------------
3489:
3490: =pod
3491:
1.648 raeburn 3492: =item * &get_kerberos_defaults()
1.80 albertel 3493:
3494: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3495: version and domain. If not found, it defaults to version 4 and the
3496: domain of the server.
1.80 albertel 3497:
1.648 raeburn 3498: =over 4
3499:
1.80 albertel 3500: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3501:
1.648 raeburn 3502: =back
3503:
3504: =back
3505:
1.80 albertel 3506: =cut
3507:
3508: #-------------------------------------------
3509: sub get_kerberos_defaults {
3510: my $domain=shift;
1.641 raeburn 3511: my ($krbdef,$krbdefdom);
3512: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3513: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3514: $krbdef = $domdefaults{'auth_def'};
3515: $krbdefdom = $domdefaults{'auth_arg_def'};
3516: } else {
1.80 albertel 3517: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3518: my $krbdefdom=$1;
3519: $krbdefdom=~tr/a-z/A-Z/;
3520: $krbdef = "krb4";
3521: }
3522: return ($krbdef,$krbdefdom);
3523: }
1.112 bowersj2 3524:
1.32 matthew 3525:
1.46 matthew 3526: ###############################################################
3527: ## Thesaurus Functions ##
3528: ###############################################################
1.20 www 3529:
1.46 matthew 3530: =pod
1.20 www 3531:
1.112 bowersj2 3532: =head1 Thesaurus Functions
3533:
3534: =over 4
3535:
1.648 raeburn 3536: =item * &initialize_keywords()
1.46 matthew 3537:
3538: Initializes the package variable %Keywords if it is empty. Uses the
3539: package variable $thesaurus_db_file.
3540:
3541: =cut
3542:
3543: ###################################################
3544:
3545: sub initialize_keywords {
3546: return 1 if (scalar keys(%Keywords));
3547: # If we are here, %Keywords is empty, so fill it up
3548: # Make sure the file we need exists...
3549: if (! -e $thesaurus_db_file) {
3550: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3551: " failed because it does not exist");
3552: return 0;
3553: }
3554: # Set up the hash as a database
3555: my %thesaurus_db;
3556: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3557: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3558: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3559: $thesaurus_db_file);
3560: return 0;
3561: }
3562: # Get the average number of appearances of a word.
3563: my $avecount = $thesaurus_db{'average.count'};
3564: # Put keywords (those that appear > average) into %Keywords
3565: while (my ($word,$data)=each (%thesaurus_db)) {
3566: my ($count,undef) = split /:/,$data;
3567: $Keywords{$word}++ if ($count > $avecount);
3568: }
3569: untie %thesaurus_db;
3570: # Remove special values from %Keywords.
1.356 albertel 3571: foreach my $value ('total.count','average.count') {
3572: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3573: }
1.46 matthew 3574: return 1;
3575: }
3576:
3577: ###################################################
3578:
3579: =pod
3580:
1.648 raeburn 3581: =item * &keyword($word)
1.46 matthew 3582:
3583: Returns true if $word is a keyword. A keyword is a word that appears more
3584: than the average number of times in the thesaurus database. Calls
3585: &initialize_keywords
3586:
3587: =cut
3588:
3589: ###################################################
1.20 www 3590:
3591: sub keyword {
1.46 matthew 3592: return if (!&initialize_keywords());
3593: my $word=lc(shift());
3594: $word=~s/\W//g;
3595: return exists($Keywords{$word});
1.20 www 3596: }
1.46 matthew 3597:
3598: ###############################################################
3599:
3600: =pod
1.20 www 3601:
1.648 raeburn 3602: =item * &get_related_words()
1.46 matthew 3603:
1.160 matthew 3604: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3605: an array of words. If the keyword is not in the thesaurus, an empty array
3606: will be returned. The order of the words returned is determined by the
3607: database which holds them.
3608:
3609: Uses global $thesaurus_db_file.
3610:
1.1057 foxr 3611:
1.46 matthew 3612: =cut
3613:
3614: ###############################################################
3615: sub get_related_words {
3616: my $keyword = shift;
3617: my %thesaurus_db;
3618: if (! -e $thesaurus_db_file) {
3619: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3620: "failed because the file does not exist");
3621: return ();
3622: }
3623: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3624: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3625: return ();
3626: }
3627: my @Words=();
1.429 www 3628: my $count=0;
1.46 matthew 3629: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3630: # The first element is the number of times
3631: # the word appears. We do not need it now.
1.429 www 3632: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3633: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3634: my $threshold=$mostfrequentcount/10;
3635: foreach my $possibleword (@RelatedWords) {
3636: my ($word,$wordcount)=split(/\,/,$possibleword);
3637: if ($wordcount>$threshold) {
3638: push(@Words,$word);
3639: $count++;
3640: if ($count>10) { last; }
3641: }
1.20 www 3642: }
3643: }
1.46 matthew 3644: untie %thesaurus_db;
3645: return @Words;
1.14 harris41 3646: }
1.1090 foxr 3647: ###############################################################
3648: #
3649: # Spell checking
3650: #
3651:
3652: =pod
3653:
1.1142 raeburn 3654: =back
3655:
1.1090 foxr 3656: =head1 Spell checking
3657:
3658: =over 4
3659:
3660: =item * &check_spelling($wordlist $language)
3661:
3662: Takes a string containing words and feeds it to an external
3663: spellcheck program via a pipeline. Returns a string containing
3664: them mis-spelled words.
3665:
3666: Parameters:
3667:
3668: =over 4
3669:
3670: =item - $wordlist
3671:
3672: String that will be fed into the spellcheck program.
3673:
3674: =item - $language
3675:
3676: Language string that specifies the language for which the spell
3677: check will be performed.
3678:
3679: =back
3680:
3681: =back
3682:
3683: Note: This sub assumes that aspell is installed.
3684:
3685:
3686: =cut
3687:
1.46 matthew 3688:
1.1090 foxr 3689: sub check_spelling {
3690: my ($wordlist, $language) = @_;
1.1091 foxr 3691: my @misspellings;
3692:
3693: # Generate the speller and set the langauge.
3694: # if explicitly selected:
1.1090 foxr 3695:
1.1091 foxr 3696: my $speller = Text::Aspell->new;
1.1090 foxr 3697: if ($language) {
1.1091 foxr 3698: $speller->set_option('lang', $language);
1.1090 foxr 3699: }
3700:
1.1091 foxr 3701: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3702:
1.1091 foxr 3703: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3704:
1.1091 foxr 3705: foreach my $word (@words) {
3706: if(! $speller->check($word)) {
3707: push(@misspellings, $word);
1.1090 foxr 3708: }
3709: }
1.1091 foxr 3710: return join(' ', @misspellings);
3711:
1.1090 foxr 3712: }
3713:
1.61 www 3714: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3715: =pod
3716:
1.112 bowersj2 3717: =head1 User Name Functions
3718:
3719: =over 4
3720:
1.648 raeburn 3721: =item * &plainname($uname,$udom,$first)
1.81 albertel 3722:
1.112 bowersj2 3723: Takes a users logon name and returns it as a string in
1.226 albertel 3724: "first middle last generation" form
3725: if $first is set to 'lastname' then it returns it as
3726: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3727:
3728: =cut
1.61 www 3729:
1.295 www 3730:
1.81 albertel 3731: ###############################################################
1.61 www 3732: sub plainname {
1.226 albertel 3733: my ($uname,$udom,$first)=@_;
1.537 albertel 3734: return if (!defined($uname) || !defined($udom));
1.295 www 3735: my %names=&getnames($uname,$udom);
1.226 albertel 3736: my $name=&Apache::lonnet::format_name($names{'firstname'},
3737: $names{'middlename'},
3738: $names{'lastname'},
3739: $names{'generation'},$first);
3740: $name=~s/^\s+//;
1.62 www 3741: $name=~s/\s+$//;
3742: $name=~s/\s+/ /g;
1.353 albertel 3743: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3744: return $name;
1.61 www 3745: }
1.66 www 3746:
3747: # -------------------------------------------------------------------- Nickname
1.81 albertel 3748: =pod
3749:
1.648 raeburn 3750: =item * &nickname($uname,$udom)
1.81 albertel 3751:
3752: Gets a users name and returns it as a string as
3753:
3754: ""nickname""
1.66 www 3755:
1.81 albertel 3756: if the user has a nickname or
3757:
3758: "first middle last generation"
3759:
3760: if the user does not
3761:
3762: =cut
1.66 www 3763:
3764: sub nickname {
3765: my ($uname,$udom)=@_;
1.537 albertel 3766: return if (!defined($uname) || !defined($udom));
1.295 www 3767: my %names=&getnames($uname,$udom);
1.68 albertel 3768: my $name=$names{'nickname'};
1.66 www 3769: if ($name) {
3770: $name='"'.$name.'"';
3771: } else {
3772: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3773: $names{'lastname'}.' '.$names{'generation'};
3774: $name=~s/\s+$//;
3775: $name=~s/\s+/ /g;
3776: }
3777: return $name;
3778: }
3779:
1.295 www 3780: sub getnames {
3781: my ($uname,$udom)=@_;
1.537 albertel 3782: return if (!defined($uname) || !defined($udom));
1.433 albertel 3783: if ($udom eq 'public' && $uname eq 'public') {
3784: return ('lastname' => &mt('Public'));
3785: }
1.295 www 3786: my $id=$uname.':'.$udom;
3787: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3788: if ($cached) {
3789: return %{$names};
3790: } else {
3791: my %loadnames=&Apache::lonnet::get('environment',
3792: ['firstname','middlename','lastname','generation','nickname'],
3793: $udom,$uname);
3794: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3795: return %loadnames;
3796: }
3797: }
1.61 www 3798:
1.542 raeburn 3799: # -------------------------------------------------------------------- getemails
1.648 raeburn 3800:
1.542 raeburn 3801: =pod
3802:
1.648 raeburn 3803: =item * &getemails($uname,$udom)
1.542 raeburn 3804:
3805: Gets a user's email information and returns it as a hash with keys:
3806: notification, critnotification, permanentemail
3807:
3808: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3809: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3810:
1.648 raeburn 3811:
1.542 raeburn 3812: =cut
3813:
1.648 raeburn 3814:
1.466 albertel 3815: sub getemails {
3816: my ($uname,$udom)=@_;
3817: if ($udom eq 'public' && $uname eq 'public') {
3818: return;
3819: }
1.467 www 3820: if (!$udom) { $udom=$env{'user.domain'}; }
3821: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3822: my $id=$uname.':'.$udom;
3823: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3824: if ($cached) {
3825: return %{$names};
3826: } else {
3827: my %loadnames=&Apache::lonnet::get('environment',
3828: ['notification','critnotification',
3829: 'permanentemail'],
3830: $udom,$uname);
3831: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3832: return %loadnames;
3833: }
3834: }
3835:
1.551 albertel 3836: sub flush_email_cache {
3837: my ($uname,$udom)=@_;
3838: if (!$udom) { $udom =$env{'user.domain'}; }
3839: if (!$uname) { $uname=$env{'user.name'}; }
3840: return if ($udom eq 'public' && $uname eq 'public');
3841: my $id=$uname.':'.$udom;
3842: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3843: }
3844:
1.728 raeburn 3845: # -------------------------------------------------------------------- getlangs
3846:
3847: =pod
3848:
3849: =item * &getlangs($uname,$udom)
3850:
3851: Gets a user's language preference and returns it as a hash with key:
3852: language.
3853:
3854: =cut
3855:
3856:
3857: sub getlangs {
3858: my ($uname,$udom) = @_;
3859: if (!$udom) { $udom =$env{'user.domain'}; }
3860: if (!$uname) { $uname=$env{'user.name'}; }
3861: my $id=$uname.':'.$udom;
3862: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3863: if ($cached) {
3864: return %{$langs};
3865: } else {
3866: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3867: $udom,$uname);
3868: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3869: return %loadlangs;
3870: }
3871: }
3872:
3873: sub flush_langs_cache {
3874: my ($uname,$udom)=@_;
3875: if (!$udom) { $udom =$env{'user.domain'}; }
3876: if (!$uname) { $uname=$env{'user.name'}; }
3877: return if ($udom eq 'public' && $uname eq 'public');
3878: my $id=$uname.':'.$udom;
3879: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3880: }
3881:
1.61 www 3882: # ------------------------------------------------------------------ Screenname
1.81 albertel 3883:
3884: =pod
3885:
1.648 raeburn 3886: =item * &screenname($uname,$udom)
1.81 albertel 3887:
3888: Gets a users screenname and returns it as a string
3889:
3890: =cut
1.61 www 3891:
3892: sub screenname {
3893: my ($uname,$udom)=@_;
1.258 albertel 3894: if ($uname eq $env{'user.name'} &&
3895: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3896: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3897: return $names{'screenname'};
1.62 www 3898: }
3899:
1.212 albertel 3900:
1.802 bisitz 3901: # ------------------------------------------------------------- Confirm Wrapper
3902: =pod
3903:
1.1142 raeburn 3904: =item * &confirmwrapper($message)
1.802 bisitz 3905:
3906: Wrap messages about completion of operation in box
3907:
3908: =cut
3909:
3910: sub confirmwrapper {
3911: my ($message)=@_;
3912: if ($message) {
3913: return "\n".'<div class="LC_confirm_box">'."\n"
3914: .$message."\n"
3915: .'</div>'."\n";
3916: } else {
3917: return $message;
3918: }
3919: }
3920:
1.62 www 3921: # ------------------------------------------------------------- Message Wrapper
3922:
3923: sub messagewrapper {
1.369 www 3924: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3925: return
1.441 albertel 3926: '<a href="/adm/email?compose=individual&'.
3927: 'recname='.$username.'&recdom='.$domain.
3928: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3929: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3930: }
1.802 bisitz 3931:
1.74 www 3932: # --------------------------------------------------------------- Notes Wrapper
3933:
3934: sub noteswrapper {
3935: my ($link,$un,$do)=@_;
3936: return
1.896 amueller 3937: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3938: }
1.802 bisitz 3939:
1.62 www 3940: # ------------------------------------------------------------- Aboutme Wrapper
3941:
3942: sub aboutmewrapper {
1.1070 raeburn 3943: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3944: if (!defined($username) && !defined($domain)) {
3945: return;
3946: }
1.1096 raeburn 3947: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3948: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3949: }
3950:
3951: # ------------------------------------------------------------ Syllabus Wrapper
3952:
3953: sub syllabuswrapper {
1.707 bisitz 3954: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3955: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3956: }
1.14 harris41 3957:
1.802 bisitz 3958: # -----------------------------------------------------------------------------
3959:
1.208 matthew 3960: sub track_student_link {
1.887 raeburn 3961: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3962: my $link ="/adm/trackstudent?";
1.208 matthew 3963: my $title = 'View recent activity';
3964: if (defined($sname) && $sname !~ /^\s*$/ &&
3965: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3966: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3967: $title .= ' of this student';
1.268 albertel 3968: }
1.208 matthew 3969: if (defined($target) && $target !~ /^\s*$/) {
3970: $target = qq{target="$target"};
3971: } else {
3972: $target = '';
3973: }
1.268 albertel 3974: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3975: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3976: $title = &mt($title);
3977: $linktext = &mt($linktext);
1.448 albertel 3978: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3979: &help_open_topic('View_recent_activity');
1.208 matthew 3980: }
3981:
1.781 raeburn 3982: sub slot_reservations_link {
3983: my ($linktext,$sname,$sdom,$target) = @_;
3984: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3985: my $title = 'View slot reservation history';
3986: if (defined($sname) && $sname !~ /^\s*$/ &&
3987: defined($sdom) && $sdom !~ /^\s*$/) {
3988: $link .= "&uname=$sname&udom=$sdom";
3989: $title .= ' of this student';
3990: }
3991: if (defined($target) && $target !~ /^\s*$/) {
3992: $target = qq{target="$target"};
3993: } else {
3994: $target = '';
3995: }
3996: $title = &mt($title);
3997: $linktext = &mt($linktext);
3998: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3999: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
4000:
4001: }
4002:
1.508 www 4003: # ===================================================== Display a student photo
4004:
4005:
1.509 albertel 4006: sub student_image_tag {
1.508 www 4007: my ($domain,$user)=@_;
4008: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
4009: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
4010: return '<img src="'.$imgsrc.'" align="right" />';
4011: } else {
4012: return '';
4013: }
4014: }
4015:
1.112 bowersj2 4016: =pod
4017:
4018: =back
4019:
4020: =head1 Access .tab File Data
4021:
4022: =over 4
4023:
1.648 raeburn 4024: =item * &languageids()
1.112 bowersj2 4025:
4026: returns list of all language ids
4027:
4028: =cut
4029:
1.14 harris41 4030: sub languageids {
1.16 harris41 4031: return sort(keys(%language));
1.14 harris41 4032: }
4033:
1.112 bowersj2 4034: =pod
4035:
1.648 raeburn 4036: =item * &languagedescription()
1.112 bowersj2 4037:
4038: returns description of a specified language id
4039:
4040: =cut
4041:
1.14 harris41 4042: sub languagedescription {
1.125 www 4043: my $code=shift;
4044: return ($supported_language{$code}?'* ':'').
4045: $language{$code}.
1.126 www 4046: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 4047: }
4048:
1.1048 foxr 4049: =pod
4050:
4051: =item * &plainlanguagedescription
4052:
4053: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
4054: and the language character encoding (e.g. ISO) separated by a ' - ' string.
4055:
4056: =cut
4057:
1.145 www 4058: sub plainlanguagedescription {
4059: my $code=shift;
4060: return $language{$code};
4061: }
4062:
1.1048 foxr 4063: =pod
4064:
4065: =item * &supportedlanguagecode
4066:
4067: Returns the supported language code (e.g. sptutf maps to pt) given a language
4068: code.
4069:
4070: =cut
4071:
1.145 www 4072: sub supportedlanguagecode {
4073: my $code=shift;
4074: return $supported_language{$code};
1.97 www 4075: }
4076:
1.112 bowersj2 4077: =pod
4078:
1.1048 foxr 4079: =item * &latexlanguage()
4080:
4081: Given a language key code returns the correspondnig language to use
4082: to select the correct hyphenation on LaTeX printouts. This is undef if there
4083: is no supported hyphenation for the language code.
4084:
4085: =cut
4086:
4087: sub latexlanguage {
4088: my $code = shift;
4089: return $latex_language{$code};
4090: }
4091:
4092: =pod
4093:
4094: =item * &latexhyphenation()
4095:
4096: Same as above but what's supplied is the language as it might be stored
4097: in the metadata.
4098:
4099: =cut
4100:
4101: sub latexhyphenation {
4102: my $key = shift;
4103: return $latex_language_bykey{$key};
4104: }
4105:
4106: =pod
4107:
1.648 raeburn 4108: =item * ©rightids()
1.112 bowersj2 4109:
4110: returns list of all copyrights
4111:
4112: =cut
4113:
4114: sub copyrightids {
4115: return sort(keys(%cprtag));
4116: }
4117:
4118: =pod
4119:
1.648 raeburn 4120: =item * ©rightdescription()
1.112 bowersj2 4121:
4122: returns description of a specified copyright id
4123:
4124: =cut
4125:
4126: sub copyrightdescription {
1.166 www 4127: return &mt($cprtag{shift(@_)});
1.112 bowersj2 4128: }
1.197 matthew 4129:
4130: =pod
4131:
1.648 raeburn 4132: =item * &source_copyrightids()
1.192 taceyjo1 4133:
4134: returns list of all source copyrights
4135:
4136: =cut
4137:
4138: sub source_copyrightids {
4139: return sort(keys(%scprtag));
4140: }
4141:
4142: =pod
4143:
1.648 raeburn 4144: =item * &source_copyrightdescription()
1.192 taceyjo1 4145:
4146: returns description of a specified source copyright id
4147:
4148: =cut
4149:
4150: sub source_copyrightdescription {
4151: return &mt($scprtag{shift(@_)});
4152: }
1.112 bowersj2 4153:
4154: =pod
4155:
1.648 raeburn 4156: =item * &filecategories()
1.112 bowersj2 4157:
4158: returns list of all file categories
4159:
4160: =cut
4161:
4162: sub filecategories {
4163: return sort(keys(%category_extensions));
4164: }
4165:
4166: =pod
4167:
1.648 raeburn 4168: =item * &filecategorytypes()
1.112 bowersj2 4169:
4170: returns list of file types belonging to a given file
4171: category
4172:
4173: =cut
4174:
4175: sub filecategorytypes {
1.356 albertel 4176: my ($cat) = @_;
1.1248 raeburn 4177: if (ref($category_extensions{lc($cat)}) eq 'ARRAY') {
4178: return @{$category_extensions{lc($cat)}};
4179: } else {
4180: return ();
4181: }
1.112 bowersj2 4182: }
4183:
4184: =pod
4185:
1.648 raeburn 4186: =item * &fileembstyle()
1.112 bowersj2 4187:
4188: returns embedding style for a specified file type
4189:
4190: =cut
4191:
4192: sub fileembstyle {
4193: return $fe{lc(shift(@_))};
1.169 www 4194: }
4195:
1.351 www 4196: sub filemimetype {
4197: return $fm{lc(shift(@_))};
4198: }
4199:
1.169 www 4200:
4201: sub filecategoryselect {
4202: my ($name,$value)=@_;
1.189 matthew 4203: return &select_form($value,$name,
1.970 raeburn 4204: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 4205: }
4206:
4207: =pod
4208:
1.648 raeburn 4209: =item * &filedescription()
1.112 bowersj2 4210:
4211: returns description for a specified file type
4212:
4213: =cut
4214:
4215: sub filedescription {
1.188 matthew 4216: my $file_description = $fd{lc(shift())};
4217: $file_description =~ s:([\[\]]):~$1:g;
4218: return &mt($file_description);
1.112 bowersj2 4219: }
4220:
4221: =pod
4222:
1.648 raeburn 4223: =item * &filedescriptionex()
1.112 bowersj2 4224:
4225: returns description for a specified file type with
4226: extra formatting
4227:
4228: =cut
4229:
4230: sub filedescriptionex {
4231: my $ex=shift;
1.188 matthew 4232: my $file_description = $fd{lc($ex)};
4233: $file_description =~ s:([\[\]]):~$1:g;
4234: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 4235: }
4236:
4237: # End of .tab access
4238: =pod
4239:
4240: =back
4241:
4242: =cut
4243:
4244: # ------------------------------------------------------------------ File Types
4245: sub fileextensions {
4246: return sort(keys(%fe));
4247: }
4248:
1.97 www 4249: # ----------------------------------------------------------- Display Languages
4250: # returns a hash with all desired display languages
4251: #
4252:
4253: sub display_languages {
4254: my %languages=();
1.695 raeburn 4255: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 4256: $languages{$lang}=1;
1.97 www 4257: }
4258: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 4259: if ($env{'form.displaylanguage'}) {
1.356 albertel 4260: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
4261: $languages{$lang}=1;
1.97 www 4262: }
4263: }
4264: return %languages;
1.14 harris41 4265: }
4266:
1.582 albertel 4267: sub languages {
4268: my ($possible_langs) = @_;
1.695 raeburn 4269: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 4270: if (!ref($possible_langs)) {
4271: if( wantarray ) {
4272: return @preferred_langs;
4273: } else {
4274: return $preferred_langs[0];
4275: }
4276: }
4277: my %possibilities = map { $_ => 1 } (@$possible_langs);
4278: my @preferred_possibilities;
4279: foreach my $preferred_lang (@preferred_langs) {
4280: if (exists($possibilities{$preferred_lang})) {
4281: push(@preferred_possibilities, $preferred_lang);
4282: }
4283: }
4284: if( wantarray ) {
4285: return @preferred_possibilities;
4286: }
4287: return $preferred_possibilities[0];
4288: }
4289:
1.742 raeburn 4290: sub user_lang {
4291: my ($touname,$toudom,$fromcid) = @_;
4292: my @userlangs;
4293: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
4294: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
4295: $env{'course.'.$fromcid.'.languages'}));
4296: } else {
4297: my %langhash = &getlangs($touname,$toudom);
4298: if ($langhash{'languages'} ne '') {
4299: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
4300: } else {
4301: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
4302: if ($domdefs{'lang_def'} ne '') {
4303: @userlangs = ($domdefs{'lang_def'});
4304: }
4305: }
4306: }
4307: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4308: my $user_lh = Apache::localize->get_handle(@languages);
4309: return $user_lh;
4310: }
4311:
4312:
1.112 bowersj2 4313: ###############################################################
4314: ## Student Answer Attempts ##
4315: ###############################################################
4316:
4317: =pod
4318:
4319: =head1 Alternate Problem Views
4320:
4321: =over 4
4322:
1.648 raeburn 4323: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4324: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4325:
4326: Return string with previous attempt on problem. Arguments:
4327:
4328: =over 4
4329:
4330: =item * $symb: Problem, including path
4331:
4332: =item * $username: username of the desired student
4333:
4334: =item * $domain: domain of the desired student
1.14 harris41 4335:
1.112 bowersj2 4336: =item * $course: Course ID
1.14 harris41 4337:
1.112 bowersj2 4338: =item * $getattempt: Leave blank for all attempts, otherwise put
4339: something
1.14 harris41 4340:
1.112 bowersj2 4341: =item * $regexp: if string matches this regexp, the string will be
4342: sent to $gradesub
1.14 harris41 4343:
1.112 bowersj2 4344: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4345:
1.1199 raeburn 4346: =item * $usec: section of the desired student
4347:
4348: =item * $identifier: counter for student (multiple students one problem) or
4349: problem (one student; whole sequence).
4350:
1.112 bowersj2 4351: =back
1.14 harris41 4352:
1.112 bowersj2 4353: The output string is a table containing all desired attempts, if any.
1.16 harris41 4354:
1.112 bowersj2 4355: =cut
1.1 albertel 4356:
4357: sub get_previous_attempt {
1.1199 raeburn 4358: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4359: my $prevattempts='';
1.43 ng 4360: no strict 'refs';
1.1 albertel 4361: if ($symb) {
1.3 albertel 4362: my (%returnhash)=
4363: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4364: if ($returnhash{'version'}) {
4365: my %lasthash=();
4366: my $version;
4367: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4368: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4369: if ($key =~ /\.rawrndseed$/) {
4370: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4371: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4372: } else {
4373: $lasthash{$key}=$returnhash{$version.':'.$key};
4374: }
1.19 harris41 4375: }
1.1 albertel 4376: }
1.596 albertel 4377: $prevattempts=&start_data_table().&start_data_table_header_row();
4378: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4379: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4380: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4381: foreach my $key (sort(keys(%lasthash))) {
4382: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4383: if ($#parts > 0) {
1.31 albertel 4384: my $data=$parts[-1];
1.989 raeburn 4385: next if ($data eq 'foilorder');
1.31 albertel 4386: pop(@parts);
1.1010 www 4387: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4388: if ($data eq 'type') {
4389: unless ($showsurv) {
4390: my $id = join(',',@parts);
4391: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4392: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4393: $lasthidden{$ign.'.'.$id} = 1;
4394: }
1.945 raeburn 4395: }
1.1199 raeburn 4396: if ($identifier ne '') {
4397: my $id = join(',',@parts);
4398: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4399: $domain,$username,$usec,undef,$course) =~ /^no/) {
4400: $hidestatus{$ign.'.'.$id} = 1;
4401: }
4402: }
4403: } elsif ($data eq 'regrader') {
4404: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4405: my $id = join(',',@parts);
4406: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4407: }
1.1010 www 4408: }
1.31 albertel 4409: } else {
1.41 ng 4410: if ($#parts == 0) {
4411: $prevattempts.='<th>'.$parts[0].'</th>';
4412: } else {
4413: $prevattempts.='<th>'.$ign.'</th>';
4414: }
1.31 albertel 4415: }
1.16 harris41 4416: }
1.596 albertel 4417: $prevattempts.=&end_data_table_header_row();
1.40 ng 4418: if ($getattempt eq '') {
1.1199 raeburn 4419: my (%solved,%resets,%probstatus);
1.1200 raeburn 4420: if (($identifier ne '') && (keys(%regraded) > 0)) {
4421: for ($version=1;$version<=$returnhash{'version'};$version++) {
4422: foreach my $id (keys(%regraded)) {
4423: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4424: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4425: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4426: push(@{$resets{$id}},$version);
1.1199 raeburn 4427: }
4428: }
4429: }
1.1200 raeburn 4430: }
4431: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4432: my (@hidden,@unsolved);
1.945 raeburn 4433: if (%typeparts) {
4434: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4435: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4436: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4437: push(@hidden,$id);
1.1199 raeburn 4438: } elsif ($identifier ne '') {
4439: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4440: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4441: ($hidestatus{$id})) {
1.1200 raeburn 4442: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4443: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4444: push(@{$solved{$id}},$version);
4445: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4446: (ref($solved{$id}) eq 'ARRAY')) {
4447: my $skip;
4448: if (ref($resets{$id}) eq 'ARRAY') {
4449: foreach my $reset (@{$resets{$id}}) {
4450: if ($reset > $solved{$id}[-1]) {
4451: $skip=1;
4452: last;
4453: }
4454: }
4455: }
4456: unless ($skip) {
4457: my ($ign,$partslist) = split(/\./,$id,2);
4458: push(@unsolved,$partslist);
4459: }
4460: }
4461: }
1.945 raeburn 4462: }
4463: }
4464: }
4465: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4466: '<td>'.&mt('Transaction [_1]',$version);
4467: if (@unsolved) {
4468: $prevattempts .= '<span class="LC_nobreak"><label>'.
4469: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4470: &mt('Hide').'</label></span>';
4471: }
4472: $prevattempts .= '</td>';
1.945 raeburn 4473: if (@hidden) {
4474: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4475: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4476: my $hide;
4477: foreach my $id (@hidden) {
4478: if ($key =~ /^\Q$id\E/) {
4479: $hide = 1;
4480: last;
4481: }
4482: }
4483: if ($hide) {
4484: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4485: if (($data eq 'award') || ($data eq 'awarddetail')) {
4486: my $value = &format_previous_attempt_value($key,
4487: $returnhash{$version.':'.$key});
1.1173 kruse 4488: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4489: } else {
4490: $prevattempts.='<td> </td>';
4491: }
4492: } else {
4493: if ($key =~ /\./) {
1.1212 raeburn 4494: my $value = $returnhash{$version.':'.$key};
4495: if ($key =~ /\.rndseed$/) {
4496: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4497: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4498: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4499: }
4500: }
4501: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4502: ' </td>';
1.945 raeburn 4503: } else {
4504: $prevattempts.='<td> </td>';
4505: }
4506: }
4507: }
4508: } else {
4509: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4510: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4511: my $value = $returnhash{$version.':'.$key};
4512: if ($key =~ /\.rndseed$/) {
4513: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4514: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4515: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4516: }
4517: }
4518: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4519: ' </td>';
1.945 raeburn 4520: }
4521: }
4522: $prevattempts.=&end_data_table_row();
1.40 ng 4523: }
1.1 albertel 4524: }
1.945 raeburn 4525: my @currhidden = keys(%lasthidden);
1.596 albertel 4526: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4527: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4528: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4529: if (%typeparts) {
4530: my $hidden;
4531: foreach my $id (@currhidden) {
4532: if ($key =~ /^\Q$id\E/) {
4533: $hidden = 1;
4534: last;
4535: }
4536: }
4537: if ($hidden) {
4538: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4539: if (($data eq 'award') || ($data eq 'awarddetail')) {
4540: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4541: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4542: $value = &$gradesub($value);
4543: }
1.1173 kruse 4544: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4545: } else {
4546: $prevattempts.='<td> </td>';
4547: }
4548: } else {
4549: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4550: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4551: $value = &$gradesub($value);
4552: }
1.1173 kruse 4553: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4554: }
4555: } else {
4556: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4557: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4558: $value = &$gradesub($value);
4559: }
1.1173 kruse 4560: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4561: }
1.16 harris41 4562: }
1.596 albertel 4563: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4564: } else {
1.596 albertel 4565: $prevattempts=
4566: &start_data_table().&start_data_table_row().
4567: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4568: &end_data_table_row().&end_data_table();
1.1 albertel 4569: }
4570: } else {
1.596 albertel 4571: $prevattempts=
4572: &start_data_table().&start_data_table_row().
4573: '<td>'.&mt('No data.').'</td>'.
4574: &end_data_table_row().&end_data_table();
1.1 albertel 4575: }
1.10 albertel 4576: }
4577:
1.581 albertel 4578: sub format_previous_attempt_value {
4579: my ($key,$value) = @_;
1.1011 www 4580: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4581: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4582: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4583: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4584: } elsif ($key =~ /answerstring$/) {
4585: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4586: my @answer = %answers;
4587: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4588: my @anskeys = sort(keys(%answers));
4589: if (@anskeys == 1) {
4590: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4591: if ($answer =~ m{\0}) {
4592: $answer =~ s{\0}{,}g;
1.988 raeburn 4593: }
4594: my $tag_internal_answer_name = 'INTERNAL';
4595: if ($anskeys[0] eq $tag_internal_answer_name) {
4596: $value = $answer;
4597: } else {
4598: $value = $anskeys[0].'='.$answer;
4599: }
4600: } else {
4601: foreach my $ans (@anskeys) {
4602: my $answer = $answers{$ans};
1.1001 raeburn 4603: if ($answer =~ m{\0}) {
4604: $answer =~ s{\0}{,}g;
1.988 raeburn 4605: }
4606: $value .= $ans.'='.$answer.'<br />';;
4607: }
4608: }
1.581 albertel 4609: } else {
1.1173 kruse 4610: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4611: }
4612: return $value;
4613: }
4614:
4615:
1.107 albertel 4616: sub relative_to_absolute {
4617: my ($url,$output)=@_;
4618: my $parser=HTML::TokeParser->new(\$output);
4619: my $token;
4620: my $thisdir=$url;
4621: my @rlinks=();
4622: while ($token=$parser->get_token) {
4623: if ($token->[0] eq 'S') {
4624: if ($token->[1] eq 'a') {
4625: if ($token->[2]->{'href'}) {
4626: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4627: }
4628: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4629: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4630: } elsif ($token->[1] eq 'base') {
4631: $thisdir=$token->[2]->{'href'};
4632: }
4633: }
4634: }
4635: $thisdir=~s-/[^/]*$--;
1.356 albertel 4636: foreach my $link (@rlinks) {
1.726 raeburn 4637: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4638: ($link=~/^\//) ||
4639: ($link=~/^javascript:/i) ||
4640: ($link=~/^mailto:/i) ||
4641: ($link=~/^\#/)) {
4642: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4643: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4644: }
4645: }
4646: # -------------------------------------------------- Deal with Applet codebases
4647: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4648: return $output;
4649: }
4650:
1.112 bowersj2 4651: =pod
4652:
1.648 raeburn 4653: =item * &get_student_view()
1.112 bowersj2 4654:
4655: show a snapshot of what student was looking at
4656:
4657: =cut
4658:
1.10 albertel 4659: sub get_student_view {
1.186 albertel 4660: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4661: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4662: my (%form);
1.10 albertel 4663: my @elements=('symb','courseid','domain','username');
4664: foreach my $element (@elements) {
1.186 albertel 4665: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4666: }
1.186 albertel 4667: if (defined($moreenv)) {
4668: %form=(%form,%{$moreenv});
4669: }
1.236 albertel 4670: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4671: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4672: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4673: $userview=~s/\<body[^\>]*\>//gi;
4674: $userview=~s/\<\/body\>//gi;
4675: $userview=~s/\<html\>//gi;
4676: $userview=~s/\<\/html\>//gi;
4677: $userview=~s/\<head\>//gi;
4678: $userview=~s/\<\/head\>//gi;
4679: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4680: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4681: if (wantarray) {
4682: return ($userview,$response);
4683: } else {
4684: return $userview;
4685: }
4686: }
4687:
4688: sub get_student_view_with_retries {
4689: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4690:
4691: my $ok = 0; # True if we got a good response.
4692: my $content;
4693: my $response;
4694:
4695: # Try to get the student_view done. within the retries count:
4696:
4697: do {
4698: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4699: $ok = $response->is_success;
4700: if (!$ok) {
4701: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4702: }
4703: $retries--;
4704: } while (!$ok && ($retries > 0));
4705:
4706: if (!$ok) {
4707: $content = ''; # On error return an empty content.
4708: }
1.651 www 4709: if (wantarray) {
4710: return ($content, $response);
4711: } else {
4712: return $content;
4713: }
1.11 albertel 4714: }
4715:
1.112 bowersj2 4716: =pod
4717:
1.648 raeburn 4718: =item * &get_student_answers()
1.112 bowersj2 4719:
4720: show a snapshot of how student was answering problem
4721:
4722: =cut
4723:
1.11 albertel 4724: sub get_student_answers {
1.100 sakharuk 4725: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4726: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4727: my (%moreenv);
1.11 albertel 4728: my @elements=('symb','courseid','domain','username');
4729: foreach my $element (@elements) {
1.186 albertel 4730: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4731: }
1.186 albertel 4732: $moreenv{'grade_target'}='answer';
4733: %moreenv=(%form,%moreenv);
1.497 raeburn 4734: $feedurl = &Apache::lonnet::clutter($feedurl);
4735: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4736: return $userview;
1.1 albertel 4737: }
1.116 albertel 4738:
4739: =pod
4740:
4741: =item * &submlink()
4742:
1.242 albertel 4743: Inputs: $text $uname $udom $symb $target
1.116 albertel 4744:
4745: Returns: A link to grades.pm such as to see the SUBM view of a student
4746:
4747: =cut
4748:
4749: ###############################################
4750: sub submlink {
1.242 albertel 4751: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4752: if (!($uname && $udom)) {
4753: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4754: &Apache::lonnet::whichuser($symb);
1.116 albertel 4755: if (!$symb) { $symb=$cursymb; }
4756: }
1.254 matthew 4757: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4758: $symb=&escape($symb);
1.960 bisitz 4759: if ($target) { $target=" target=\"$target\""; }
4760: return
4761: '<a href="/adm/grades?command=submission'.
4762: '&symb='.$symb.
4763: '&student='.$uname.
4764: '&userdom='.$udom.'"'.
4765: $target.'>'.$text.'</a>';
1.242 albertel 4766: }
4767: ##############################################
4768:
4769: =pod
4770:
4771: =item * &pgrdlink()
4772:
4773: Inputs: $text $uname $udom $symb $target
4774:
4775: Returns: A link to grades.pm such as to see the PGRD view of a student
4776:
4777: =cut
4778:
4779: ###############################################
4780: sub pgrdlink {
4781: my $link=&submlink(@_);
4782: $link=~s/(&command=submission)/$1&showgrading=yes/;
4783: return $link;
4784: }
4785: ##############################################
4786:
4787: =pod
4788:
4789: =item * &pprmlink()
4790:
4791: Inputs: $text $uname $udom $symb $target
4792:
4793: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4794: student and a specific resource
1.242 albertel 4795:
4796: =cut
4797:
4798: ###############################################
4799: sub pprmlink {
4800: my ($text,$uname,$udom,$symb,$target)=@_;
4801: if (!($uname && $udom)) {
4802: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4803: &Apache::lonnet::whichuser($symb);
1.242 albertel 4804: if (!$symb) { $symb=$cursymb; }
4805: }
1.254 matthew 4806: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4807: $symb=&escape($symb);
1.242 albertel 4808: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4809: return '<a href="/adm/parmset?command=set&'.
4810: 'symb='.$symb.'&uname='.$uname.
4811: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4812: }
4813: ##############################################
1.37 matthew 4814:
1.112 bowersj2 4815: =pod
4816:
4817: =back
4818:
4819: =cut
4820:
1.37 matthew 4821: ###############################################
1.51 www 4822:
4823:
4824: sub timehash {
1.687 raeburn 4825: my ($thistime) = @_;
4826: my $timezone = &Apache::lonlocal::gettimezone();
4827: my $dt = DateTime->from_epoch(epoch => $thistime)
4828: ->set_time_zone($timezone);
4829: my $wday = $dt->day_of_week();
4830: if ($wday == 7) { $wday = 0; }
4831: return ( 'second' => $dt->second(),
4832: 'minute' => $dt->minute(),
4833: 'hour' => $dt->hour(),
4834: 'day' => $dt->day_of_month(),
4835: 'month' => $dt->month(),
4836: 'year' => $dt->year(),
4837: 'weekday' => $wday,
4838: 'dayyear' => $dt->day_of_year(),
4839: 'dlsav' => $dt->is_dst() );
1.51 www 4840: }
4841:
1.370 www 4842: sub utc_string {
4843: my ($date)=@_;
1.371 www 4844: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4845: }
4846:
1.51 www 4847: sub maketime {
4848: my %th=@_;
1.687 raeburn 4849: my ($epoch_time,$timezone,$dt);
4850: $timezone = &Apache::lonlocal::gettimezone();
4851: eval {
4852: $dt = DateTime->new( year => $th{'year'},
4853: month => $th{'month'},
4854: day => $th{'day'},
4855: hour => $th{'hour'},
4856: minute => $th{'minute'},
4857: second => $th{'second'},
4858: time_zone => $timezone,
4859: );
4860: };
4861: if (!$@) {
4862: $epoch_time = $dt->epoch;
4863: if ($epoch_time) {
4864: return $epoch_time;
4865: }
4866: }
1.51 www 4867: return POSIX::mktime(
4868: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4869: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4870: }
4871:
4872: #########################################
1.51 www 4873:
4874: sub findallcourses {
1.482 raeburn 4875: my ($roles,$uname,$udom) = @_;
1.355 albertel 4876: my %roles;
4877: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4878: my %courses;
1.51 www 4879: my $now=time;
1.482 raeburn 4880: if (!defined($uname)) {
4881: $uname = $env{'user.name'};
4882: }
4883: if (!defined($udom)) {
4884: $udom = $env{'user.domain'};
4885: }
4886: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4887: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4888: if (!%roles) {
4889: %roles = (
4890: cc => 1,
1.907 raeburn 4891: co => 1,
1.482 raeburn 4892: in => 1,
4893: ep => 1,
4894: ta => 1,
4895: cr => 1,
4896: st => 1,
4897: );
4898: }
4899: foreach my $entry (keys(%roleshash)) {
4900: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4901: if ($trole =~ /^cr/) {
4902: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4903: } else {
4904: next if (!exists($roles{$trole}));
4905: }
4906: if ($tend) {
4907: next if ($tend < $now);
4908: }
4909: if ($tstart) {
4910: next if ($tstart > $now);
4911: }
1.1058 raeburn 4912: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4913: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4914: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4915: if ($secpart eq '') {
4916: ($cnum,$role) = split(/_/,$cnumpart);
4917: $sec = 'none';
1.1058 raeburn 4918: $value .= $cnum.'/';
1.482 raeburn 4919: } else {
4920: $cnum = $cnumpart;
4921: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4922: $value .= $cnum.'/'.$sec;
4923: }
4924: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4925: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4926: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4927: }
4928: } else {
4929: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4930: }
1.482 raeburn 4931: }
4932: } else {
4933: foreach my $key (keys(%env)) {
1.483 albertel 4934: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4935: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4936: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4937: next if ($role eq 'ca' || $role eq 'aa');
4938: next if (%roles && !exists($roles{$role}));
4939: my ($starttime,$endtime)=split(/\./,$env{$key});
4940: my $active=1;
4941: if ($starttime) {
4942: if ($now<$starttime) { $active=0; }
4943: }
4944: if ($endtime) {
4945: if ($now>$endtime) { $active=0; }
4946: }
4947: if ($active) {
1.1058 raeburn 4948: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4949: if ($sec eq '') {
4950: $sec = 'none';
1.1058 raeburn 4951: } else {
4952: $value .= $sec;
4953: }
4954: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4955: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4956: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4957: }
4958: } else {
4959: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4960: }
1.474 raeburn 4961: }
4962: }
1.51 www 4963: }
4964: }
1.474 raeburn 4965: return %courses;
1.51 www 4966: }
1.37 matthew 4967:
1.54 www 4968: ###############################################
1.474 raeburn 4969:
4970: sub blockcheck {
1.1189 raeburn 4971: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4972:
1.1189 raeburn 4973: if (defined($udom) && defined($uname)) {
4974: # If uname and udom are for a course, check for blocks in the course.
4975: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4976: my ($startblock,$endblock,$triggerblock) =
4977: &get_blocks($setters,$activity,$udom,$uname,$url);
4978: return ($startblock,$endblock,$triggerblock);
4979: }
4980: } else {
1.490 raeburn 4981: $udom = $env{'user.domain'};
4982: $uname = $env{'user.name'};
4983: }
4984:
1.502 raeburn 4985: my $startblock = 0;
4986: my $endblock = 0;
1.1062 raeburn 4987: my $triggerblock = '';
1.482 raeburn 4988: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4989:
1.490 raeburn 4990: # If uname is for a user, and activity is course-specific, i.e.,
4991: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4992:
1.490 raeburn 4993: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1189 raeburn 4994: $activity eq 'groups' || $activity eq 'printout') &&
4995: ($env{'request.course.id'})) {
1.490 raeburn 4996: foreach my $key (keys(%live_courses)) {
4997: if ($key ne $env{'request.course.id'}) {
4998: delete($live_courses{$key});
4999: }
5000: }
5001: }
5002:
5003: my $otheruser = 0;
5004: my %own_courses;
5005: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
5006: # Resource belongs to user other than current user.
5007: $otheruser = 1;
5008: # Gather courses for current user
5009: %own_courses =
5010: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
5011: }
5012:
5013: # Gather active course roles - course coordinator, instructor,
5014: # exam proctor, ta, student, or custom role.
1.474 raeburn 5015:
5016: foreach my $course (keys(%live_courses)) {
1.482 raeburn 5017: my ($cdom,$cnum);
5018: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
5019: $cdom = $env{'course.'.$course.'.domain'};
5020: $cnum = $env{'course.'.$course.'.num'};
5021: } else {
1.490 raeburn 5022: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 5023: }
5024: my $no_ownblock = 0;
5025: my $no_userblock = 0;
1.533 raeburn 5026: if ($otheruser && $activity ne 'com') {
1.490 raeburn 5027: # Check if current user has 'evb' priv for this
5028: if (defined($own_courses{$course})) {
5029: foreach my $sec (keys(%{$own_courses{$course}})) {
5030: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
5031: if ($sec ne 'none') {
5032: $checkrole .= '/'.$sec;
5033: }
5034: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5035: $no_ownblock = 1;
5036: last;
5037: }
5038: }
5039: }
5040: # if they have 'evb' priv and are currently not playing student
5041: next if (($no_ownblock) &&
5042: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
5043: }
1.474 raeburn 5044: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 5045: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 5046: if ($sec ne 'none') {
1.482 raeburn 5047: $checkrole .= '/'.$sec;
1.474 raeburn 5048: }
1.490 raeburn 5049: if ($otheruser) {
5050: # Resource belongs to user other than current user.
5051: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 5052: my (%allroles,%userroles);
5053: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
5054: foreach my $entry (@{$live_courses{$course}{$sec}}) {
5055: my ($trole,$tdom,$tnum,$tsec);
5056: if ($entry =~ /^cr/) {
5057: ($trole,$tdom,$tnum,$tsec) =
5058: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
5059: } else {
5060: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
5061: }
5062: my ($spec,$area,$trest);
5063: $area = '/'.$tdom.'/'.$tnum;
5064: $trest = $tnum;
5065: if ($tsec ne '') {
5066: $area .= '/'.$tsec;
5067: $trest .= '/'.$tsec;
5068: }
5069: $spec = $trole.'.'.$area;
5070: if ($trole =~ /^cr/) {
5071: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
5072: $tdom,$spec,$trest,$area);
5073: } else {
5074: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
5075: $tdom,$spec,$trest,$area);
5076: }
5077: }
5078: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
5079: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
5080: if ($1) {
5081: $no_userblock = 1;
5082: last;
5083: }
1.486 raeburn 5084: }
5085: }
1.490 raeburn 5086: } else {
5087: # Resource belongs to current user
5088: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 5089: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
5090: $no_ownblock = 1;
5091: last;
5092: }
1.474 raeburn 5093: }
5094: }
5095: # if they have the evb priv and are currently not playing student
1.482 raeburn 5096: next if (($no_ownblock) &&
1.491 albertel 5097: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 5098: next if ($no_userblock);
1.474 raeburn 5099:
1.866 kalberla 5100: # Retrieve blocking times and identity of locker for course
1.490 raeburn 5101: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 5102:
1.1062 raeburn 5103: my ($start,$end,$trigger) =
5104: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 5105: if (($start != 0) &&
5106: (($startblock == 0) || ($startblock > $start))) {
5107: $startblock = $start;
1.1062 raeburn 5108: if ($trigger ne '') {
5109: $triggerblock = $trigger;
5110: }
1.502 raeburn 5111: }
5112: if (($end != 0) &&
5113: (($endblock == 0) || ($endblock < $end))) {
5114: $endblock = $end;
1.1062 raeburn 5115: if ($trigger ne '') {
5116: $triggerblock = $trigger;
5117: }
1.502 raeburn 5118: }
1.490 raeburn 5119: }
1.1062 raeburn 5120: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 5121: }
5122:
5123: sub get_blocks {
1.1062 raeburn 5124: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 5125: my $startblock = 0;
5126: my $endblock = 0;
1.1062 raeburn 5127: my $triggerblock = '';
1.490 raeburn 5128: my $course = $cdom.'_'.$cnum;
5129: $setters->{$course} = {};
5130: $setters->{$course}{'staff'} = [];
5131: $setters->{$course}{'times'} = [];
1.1062 raeburn 5132: $setters->{$course}{'triggers'} = [];
5133: my (@blockers,%triggered);
5134: my $now = time;
5135: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
5136: if ($activity eq 'docs') {
5137: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
5138: foreach my $block (@blockers) {
5139: if ($block =~ /^firstaccess____(.+)$/) {
5140: my $item = $1;
5141: my $type = 'map';
5142: my $timersymb = $item;
5143: if ($item eq 'course') {
5144: $type = 'course';
5145: } elsif ($item =~ /___\d+___/) {
5146: $type = 'resource';
5147: } else {
5148: $timersymb = &Apache::lonnet::symbread($item);
5149: }
5150: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5151: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5152: $triggered{$block} = {
5153: start => $start,
5154: end => $end,
5155: type => $type,
5156: };
5157: }
5158: }
5159: } else {
5160: foreach my $block (keys(%commblocks)) {
5161: if ($block =~ m/^(\d+)____(\d+)$/) {
5162: my ($start,$end) = ($1,$2);
5163: if ($start <= time && $end >= time) {
5164: if (ref($commblocks{$block}) eq 'HASH') {
5165: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
5166: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
5167: unless(grep(/^\Q$block\E$/,@blockers)) {
5168: push(@blockers,$block);
5169: }
5170: }
5171: }
5172: }
5173: }
5174: } elsif ($block =~ /^firstaccess____(.+)$/) {
5175: my $item = $1;
5176: my $timersymb = $item;
5177: my $type = 'map';
5178: if ($item eq 'course') {
5179: $type = 'course';
5180: } elsif ($item =~ /___\d+___/) {
5181: $type = 'resource';
5182: } else {
5183: $timersymb = &Apache::lonnet::symbread($item);
5184: }
5185: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
5186: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
5187: if ($start && $end) {
5188: if (($start <= time) && ($end >= time)) {
5189: unless (grep(/^\Q$block\E$/,@blockers)) {
5190: push(@blockers,$block);
5191: $triggered{$block} = {
5192: start => $start,
5193: end => $end,
5194: type => $type,
5195: };
5196: }
5197: }
1.490 raeburn 5198: }
1.1062 raeburn 5199: }
5200: }
5201: }
5202: foreach my $blocker (@blockers) {
5203: my ($staff_name,$staff_dom,$title,$blocks) =
5204: &parse_block_record($commblocks{$blocker});
5205: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
5206: my ($start,$end,$triggertype);
5207: if ($blocker =~ m/^(\d+)____(\d+)$/) {
5208: ($start,$end) = ($1,$2);
5209: } elsif (ref($triggered{$blocker}) eq 'HASH') {
5210: $start = $triggered{$blocker}{'start'};
5211: $end = $triggered{$blocker}{'end'};
5212: $triggertype = $triggered{$blocker}{'type'};
5213: }
5214: if ($start) {
5215: push(@{$$setters{$course}{'times'}}, [$start,$end]);
5216: if ($triggertype) {
5217: push(@{$$setters{$course}{'triggers'}},$triggertype);
5218: } else {
5219: push(@{$$setters{$course}{'triggers'}},0);
5220: }
5221: if ( ($startblock == 0) || ($startblock > $start) ) {
5222: $startblock = $start;
5223: if ($triggertype) {
5224: $triggerblock = $blocker;
1.474 raeburn 5225: }
5226: }
1.1062 raeburn 5227: if ( ($endblock == 0) || ($endblock < $end) ) {
5228: $endblock = $end;
5229: if ($triggertype) {
5230: $triggerblock = $blocker;
5231: }
5232: }
1.474 raeburn 5233: }
5234: }
1.1062 raeburn 5235: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 5236: }
5237:
5238: sub parse_block_record {
5239: my ($record) = @_;
5240: my ($setuname,$setudom,$title,$blocks);
5241: if (ref($record) eq 'HASH') {
5242: ($setuname,$setudom) = split(/:/,$record->{'setter'});
5243: $title = &unescape($record->{'event'});
5244: $blocks = $record->{'blocks'};
5245: } else {
5246: my @data = split(/:/,$record,3);
5247: if (scalar(@data) eq 2) {
5248: $title = $data[1];
5249: ($setuname,$setudom) = split(/@/,$data[0]);
5250: } else {
5251: ($setuname,$setudom,$title) = @data;
5252: }
5253: $blocks = { 'com' => 'on' };
5254: }
5255: return ($setuname,$setudom,$title,$blocks);
5256: }
5257:
1.854 kalberla 5258: sub blocking_status {
1.1189 raeburn 5259: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 5260: my %setters;
1.890 droeschl 5261:
1.1061 raeburn 5262: # check for active blocking
1.1062 raeburn 5263: my ($startblock,$endblock,$triggerblock) =
1.1189 raeburn 5264: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 5265: my $blocked = 0;
5266: if ($startblock && $endblock) {
5267: $blocked = 1;
5268: }
1.890 droeschl 5269:
1.1061 raeburn 5270: # caller just wants to know whether a block is active
5271: if (!wantarray) { return $blocked; }
5272:
5273: # build a link to a popup window containing the details
5274: my $querystring = "?activity=$activity";
5275: # $uname and $udom decide whose portfolio the user is trying to look at
1.1232 raeburn 5276: if (($activity eq 'port') || ($activity eq 'passwd')) {
5277: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
5278: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 5279: } elsif ($activity eq 'docs') {
5280: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
5281: }
1.1061 raeburn 5282:
5283: my $output .= <<'END_MYBLOCK';
5284: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
5285: var options = "width=" + w + ",height=" + h + ",";
5286: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
5287: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
5288: var newWin = window.open(url, wdwName, options);
5289: newWin.focus();
5290: }
1.890 droeschl 5291: END_MYBLOCK
1.854 kalberla 5292:
1.1061 raeburn 5293: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 5294:
1.1061 raeburn 5295: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 5296: my $text = &mt('Communication Blocked');
1.1217 raeburn 5297: my $class = 'LC_comblock';
1.1062 raeburn 5298: if ($activity eq 'docs') {
5299: $text = &mt('Content Access Blocked');
1.1217 raeburn 5300: $class = '';
1.1063 raeburn 5301: } elsif ($activity eq 'printout') {
5302: $text = &mt('Printing Blocked');
1.1232 raeburn 5303: } elsif ($activity eq 'passwd') {
5304: $text = &mt('Password Changing Blocked');
1.1062 raeburn 5305: }
1.1061 raeburn 5306: $output .= <<"END_BLOCK";
1.1217 raeburn 5307: <div class='$class'>
1.869 kalberla 5308: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5309: title='$text'>
5310: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5311: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5312: title='$text'>$text</a>
1.867 kalberla 5313: </div>
5314:
5315: END_BLOCK
1.474 raeburn 5316:
1.1061 raeburn 5317: return ($blocked, $output);
1.854 kalberla 5318: }
1.490 raeburn 5319:
1.60 matthew 5320: ###############################################
5321:
1.682 raeburn 5322: sub check_ip_acc {
1.1201 raeburn 5323: my ($acc,$clientip)=@_;
1.682 raeburn 5324: &Apache::lonxml::debug("acc is $acc");
5325: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5326: return 1;
5327: }
1.1219 raeburn 5328: my $allowed;
1.1252 raeburn 5329: my $ip=$ENV{'REMOTE_ADDR'} || $clientip || $env{'request.host'};
1.682 raeburn 5330:
5331: my $name;
1.1219 raeburn 5332: my %access = (
5333: allowfrom => 1,
5334: denyfrom => 0,
5335: );
5336: my @allows;
5337: my @denies;
5338: foreach my $item (split(',',$acc)) {
5339: $item =~ s/^\s*//;
5340: $item =~ s/\s*$//;
5341: my $pattern;
5342: if ($item =~ /^\!(.+)$/) {
5343: push(@denies,$1);
5344: } else {
5345: push(@allows,$item);
5346: }
5347: }
5348: my $numdenies = scalar(@denies);
5349: my $numallows = scalar(@allows);
5350: my $count = 0;
5351: foreach my $pattern (@denies,@allows) {
5352: $count ++;
5353: my $acctype = 'allowfrom';
5354: if ($count <= $numdenies) {
5355: $acctype = 'denyfrom';
5356: }
1.682 raeburn 5357: if ($pattern =~ /\*$/) {
5358: #35.8.*
5359: $pattern=~s/\*//;
1.1219 raeburn 5360: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5361: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5362: #35.8.3.[34-56]
5363: my $low=$2;
5364: my $high=$3;
5365: $pattern=$1;
5366: if ($ip =~ /^\Q$pattern\E/) {
5367: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5368: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5369: }
5370: } elsif ($pattern =~ /^\*/) {
5371: #*.msu.edu
5372: $pattern=~s/\*//;
5373: if (!defined($name)) {
5374: use Socket;
5375: my $netaddr=inet_aton($ip);
5376: ($name)=gethostbyaddr($netaddr,AF_INET);
5377: }
1.1219 raeburn 5378: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5379: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5380: #127.0.0.1
1.1219 raeburn 5381: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5382: } else {
5383: #some.name.com
5384: if (!defined($name)) {
5385: use Socket;
5386: my $netaddr=inet_aton($ip);
5387: ($name)=gethostbyaddr($netaddr,AF_INET);
5388: }
1.1219 raeburn 5389: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5390: }
5391: if ($allowed =~ /^(0|1)$/) { last; }
5392: }
5393: if ($allowed eq '') {
5394: if ($numdenies && !$numallows) {
5395: $allowed = 1;
5396: } else {
5397: $allowed = 0;
1.682 raeburn 5398: }
5399: }
5400: return $allowed;
5401: }
5402:
5403: ###############################################
5404:
1.60 matthew 5405: =pod
5406:
1.112 bowersj2 5407: =head1 Domain Template Functions
5408:
5409: =over 4
5410:
5411: =item * &determinedomain()
1.60 matthew 5412:
5413: Inputs: $domain (usually will be undef)
5414:
1.63 www 5415: Returns: Determines which domain should be used for designs
1.60 matthew 5416:
5417: =cut
1.54 www 5418:
1.60 matthew 5419: ###############################################
1.63 www 5420: sub determinedomain {
5421: my $domain=shift;
1.531 albertel 5422: if (! $domain) {
1.60 matthew 5423: # Determine domain if we have not been given one
1.893 raeburn 5424: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5425: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5426: if ($env{'request.role.domain'}) {
5427: $domain=$env{'request.role.domain'};
1.60 matthew 5428: }
5429: }
1.63 www 5430: return $domain;
5431: }
5432: ###############################################
1.517 raeburn 5433:
1.518 albertel 5434: sub devalidate_domconfig_cache {
5435: my ($udom)=@_;
5436: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5437: }
5438:
5439: # ---------------------- Get domain configuration for a domain
5440: sub get_domainconf {
5441: my ($udom) = @_;
5442: my $cachetime=1800;
5443: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5444: if (defined($cached)) { return %{$result}; }
5445:
5446: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5447: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5448: my (%designhash,%legacy);
1.518 albertel 5449: if (keys(%domconfig) > 0) {
5450: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5451: if (keys(%{$domconfig{'login'}})) {
5452: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5453: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5454: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5455: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5456: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5457: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5458: if ($key eq 'loginvia') {
5459: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5460: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5461: $designhash{$udom.'.login.loginvia'} = $server;
5462: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5463:
5464: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5465: } else {
5466: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5467: }
1.948 raeburn 5468: }
1.1208 raeburn 5469: } elsif ($key eq 'headtag') {
5470: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5471: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5472: }
1.946 raeburn 5473: }
1.1208 raeburn 5474: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5475: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5476: }
1.946 raeburn 5477: }
5478: }
5479: }
5480: } else {
5481: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5482: $designhash{$udom.'.login.'.$key.'_'.$img} =
5483: $domconfig{'login'}{$key}{$img};
5484: }
1.699 raeburn 5485: }
5486: } else {
5487: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5488: }
1.632 raeburn 5489: }
5490: } else {
5491: $legacy{'login'} = 1;
1.518 albertel 5492: }
1.632 raeburn 5493: } else {
5494: $legacy{'login'} = 1;
1.518 albertel 5495: }
5496: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5497: if (keys(%{$domconfig{'rolecolors'}})) {
5498: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5499: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5500: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5501: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5502: }
1.518 albertel 5503: }
5504: }
1.632 raeburn 5505: } else {
5506: $legacy{'rolecolors'} = 1;
1.518 albertel 5507: }
1.632 raeburn 5508: } else {
5509: $legacy{'rolecolors'} = 1;
1.518 albertel 5510: }
1.948 raeburn 5511: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5512: if ($domconfig{'autoenroll'}{'co-owners'}) {
5513: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5514: }
5515: }
1.632 raeburn 5516: if (keys(%legacy) > 0) {
5517: my %legacyhash = &get_legacy_domconf($udom);
5518: foreach my $item (keys(%legacyhash)) {
5519: if ($item =~ /^\Q$udom\E\.login/) {
5520: if ($legacy{'login'}) {
5521: $designhash{$item} = $legacyhash{$item};
5522: }
5523: } else {
5524: if ($legacy{'rolecolors'}) {
5525: $designhash{$item} = $legacyhash{$item};
5526: }
1.518 albertel 5527: }
5528: }
5529: }
1.632 raeburn 5530: } else {
5531: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5532: }
5533: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5534: $cachetime);
5535: return %designhash;
5536: }
5537:
1.632 raeburn 5538: sub get_legacy_domconf {
5539: my ($udom) = @_;
5540: my %legacyhash;
5541: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5542: my $designfile = $designdir.'/'.$udom.'.tab';
5543: if (-e $designfile) {
5544: if ( open (my $fh,"<$designfile") ) {
5545: while (my $line = <$fh>) {
5546: next if ($line =~ /^\#/);
5547: chomp($line);
5548: my ($key,$val)=(split(/\=/,$line));
5549: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5550: }
5551: close($fh);
5552: }
5553: }
1.1026 raeburn 5554: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5555: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5556: }
5557: return %legacyhash;
5558: }
5559:
1.63 www 5560: =pod
5561:
1.112 bowersj2 5562: =item * &domainlogo()
1.63 www 5563:
5564: Inputs: $domain (usually will be undef)
5565:
5566: Returns: A link to a domain logo, if the domain logo exists.
5567: If the domain logo does not exist, a description of the domain.
5568:
5569: =cut
1.112 bowersj2 5570:
1.63 www 5571: ###############################################
5572: sub domainlogo {
1.517 raeburn 5573: my $domain = &determinedomain(shift);
1.518 albertel 5574: my %designhash = &get_domainconf($domain);
1.517 raeburn 5575: # See if there is a logo
5576: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5577: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5578: if ($imgsrc =~ m{^/(adm|res)/}) {
5579: if ($imgsrc =~ m{^/res/}) {
5580: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5581: &Apache::lonnet::repcopy($local_name);
5582: }
5583: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5584: }
5585: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5586: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5587: return &Apache::lonnet::domain($domain,'description');
1.59 www 5588: } else {
1.60 matthew 5589: return '';
1.59 www 5590: }
5591: }
1.63 www 5592: ##############################################
5593:
5594: =pod
5595:
1.112 bowersj2 5596: =item * &designparm()
1.63 www 5597:
5598: Inputs: $which parameter; $domain (usually will be undef)
5599:
5600: Returns: value of designparamter $which
5601:
5602: =cut
1.112 bowersj2 5603:
1.397 albertel 5604:
1.400 albertel 5605: ##############################################
1.397 albertel 5606: sub designparm {
5607: my ($which,$domain)=@_;
5608: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5609: return $env{'environment.color.'.$which};
1.96 www 5610: }
1.63 www 5611: $domain=&determinedomain($domain);
1.1016 raeburn 5612: my %domdesign;
5613: unless ($domain eq 'public') {
5614: %domdesign = &get_domainconf($domain);
5615: }
1.520 raeburn 5616: my $output;
1.517 raeburn 5617: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5618: $output = $domdesign{$domain.'.'.$which};
1.63 www 5619: } else {
1.520 raeburn 5620: $output = $defaultdesign{$which};
5621: }
5622: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5623: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5624: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5625: if ($output =~ m{^/res/}) {
5626: my $local_name = &Apache::lonnet::filelocation('',$output);
5627: &Apache::lonnet::repcopy($local_name);
5628: }
1.520 raeburn 5629: $output = &lonhttpdurl($output);
5630: }
1.63 www 5631: }
1.520 raeburn 5632: return $output;
1.63 www 5633: }
1.59 www 5634:
1.822 bisitz 5635: ##############################################
5636: =pod
5637:
1.832 bisitz 5638: =item * &authorspace()
5639:
1.1028 raeburn 5640: Inputs: $url (usually will be undef).
1.832 bisitz 5641:
1.1132 raeburn 5642: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5643: directory being viewed (or for which action is being taken).
5644: If $url is provided, and begins /priv/<domain>/<uname>
5645: the path will be that portion of the $context argument.
5646: Otherwise the path will be for the author space of the current
5647: user when the current role is author, or for that of the
5648: co-author/assistant co-author space when the current role
5649: is co-author or assistant co-author.
1.832 bisitz 5650:
5651: =cut
5652:
5653: sub authorspace {
1.1028 raeburn 5654: my ($url) = @_;
5655: if ($url ne '') {
5656: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5657: return $1;
5658: }
5659: }
1.832 bisitz 5660: my $caname = '';
1.1024 www 5661: my $cadom = '';
1.1028 raeburn 5662: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5663: ($cadom,$caname) =
1.832 bisitz 5664: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5665: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5666: $caname = $env{'user.name'};
1.1024 www 5667: $cadom = $env{'user.domain'};
1.832 bisitz 5668: }
1.1028 raeburn 5669: if (($caname ne '') && ($cadom ne '')) {
5670: return "/priv/$cadom/$caname/";
5671: }
5672: return;
1.832 bisitz 5673: }
5674:
5675: ##############################################
5676: =pod
5677:
1.822 bisitz 5678: =item * &head_subbox()
5679:
5680: Inputs: $content (contains HTML code with page functions, etc.)
5681:
5682: Returns: HTML div with $content
5683: To be included in page header
5684:
5685: =cut
5686:
5687: sub head_subbox {
5688: my ($content)=@_;
5689: my $output =
1.993 raeburn 5690: '<div class="LC_head_subbox">'
1.822 bisitz 5691: .$content
5692: .'</div>'
5693: }
5694:
5695: ##############################################
5696: =pod
5697:
5698: =item * &CSTR_pageheader()
5699:
1.1026 raeburn 5700: Input: (optional) filename from which breadcrumb trail is built.
5701: In most cases no input as needed, as $env{'request.filename'}
5702: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5703:
5704: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5705: To be included on Authoring Space pages
1.822 bisitz 5706:
5707: =cut
5708:
5709: sub CSTR_pageheader {
1.1026 raeburn 5710: my ($trailfile) = @_;
5711: if ($trailfile eq '') {
5712: $trailfile = $env{'request.filename'};
5713: }
5714:
5715: # this is for resources; directories have customtitle, and crumbs
5716: # and select recent are created in lonpubdir.pm
5717:
5718: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5719: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5720: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5721: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5722: $formaction =~ s{/+}{/}g;
1.822 bisitz 5723:
5724: my $parentpath = '';
5725: my $lastitem = '';
5726: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5727: $parentpath = $1;
5728: $lastitem = $2;
5729: } else {
5730: $lastitem = $thisdisfn;
5731: }
1.921 bisitz 5732:
1.1246 raeburn 5733: my ($crsauthor,$title);
5734: if (($env{'request.course.id'}) &&
5735: ($env{'course.'.$env{'request.course.id'}.'.num'} eq $uname) &&
1.1247 raeburn 5736: ($env{'course.'.$env{'request.course.id'}.'.domain'} eq $udom)) {
1.1246 raeburn 5737: $crsauthor = 1;
5738: $title = &mt('Course Authoring Space');
5739: } else {
5740: $title = &mt('Authoring Space');
5741: }
5742:
1.921 bisitz 5743: my $output =
1.822 bisitz 5744: '<div>'
5745: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1246 raeburn 5746: .'<b>'.$title.'</b> '
1.822 bisitz 5747: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5748: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5749: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5750:
5751: if ($lastitem) {
5752: $output .=
5753: '<span class="LC_filename">'
5754: .$lastitem
5755: .'</span>';
5756: }
1.1245 raeburn 5757:
1.1246 raeburn 5758: if ($crsauthor) {
5759: $output .= '</form>'.&Apache::lonmenu::constspaceform();
5760: } else {
5761: $output .=
5762: '<br />'
5763: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5764: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5765: .'</form>'
5766: .&Apache::lonmenu::constspaceform();
5767: }
5768: $output .= '</div>';
1.921 bisitz 5769:
5770: return $output;
1.822 bisitz 5771: }
5772:
1.60 matthew 5773: ###############################################
5774: ###############################################
5775:
5776: =pod
5777:
1.112 bowersj2 5778: =back
5779:
1.549 albertel 5780: =head1 HTML Helpers
1.112 bowersj2 5781:
5782: =over 4
5783:
5784: =item * &bodytag()
1.60 matthew 5785:
5786: Returns a uniform header for LON-CAPA web pages.
5787:
5788: Inputs:
5789:
1.112 bowersj2 5790: =over 4
5791:
5792: =item * $title, A title to be displayed on the page.
5793:
5794: =item * $function, the current role (can be undef).
5795:
5796: =item * $addentries, extra parameters for the <body> tag.
5797:
5798: =item * $bodyonly, if defined, only return the <body> tag.
5799:
5800: =item * $domain, if defined, force a given domain.
5801:
5802: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5803: text interface only)
1.60 matthew 5804:
1.814 bisitz 5805: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5806: navigational links
1.317 albertel 5807:
1.338 albertel 5808: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5809:
1.460 albertel 5810: =item * $args, optional argument valid values are
5811: no_auto_mt_title -> prevents &mt()ing the title arg
1.1274 ! raeburn 5812: use_absolute -> for external resource or syllabus, this will
! 5813: contain https://<hostname> if server uses
! 5814: https (as per hosts.tab), but request is for http
! 5815: hostname -> hostname, from $r->hostname().
1.460 albertel 5816:
1.1096 raeburn 5817: =item * $advtoolsref, optional argument, ref to an array containing
5818: inlineremote items to be added in "Functions" menu below
5819: breadcrumbs.
5820:
1.112 bowersj2 5821: =back
5822:
1.60 matthew 5823: Returns: A uniform header for LON-CAPA web pages.
5824: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5825: If $bodyonly is undef or zero, an html string containing a <body> tag and
5826: other decorations will be returned.
5827:
5828: =cut
5829:
1.54 www 5830: sub bodytag {
1.831 bisitz 5831: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5832: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5833:
1.954 raeburn 5834: my $public;
5835: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5836: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5837: $public = 1;
5838: }
1.460 albertel 5839: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 5840: my $httphost = $args->{'use_absolute'};
1.1274 ! raeburn 5841: my $hostname = $args->{'hostname'};
1.339 albertel 5842:
1.183 matthew 5843: $function = &get_users_function() if (!$function);
1.339 albertel 5844: my $img = &designparm($function.'.img',$domain);
5845: my $font = &designparm($function.'.font',$domain);
5846: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5847:
1.803 bisitz 5848: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5849: 'bgcolor' => $pgbg,
1.339 albertel 5850: 'text' => $font,
5851: 'alink' => &designparm($function.'.alink',$domain),
5852: 'vlink' => &designparm($function.'.vlink',$domain),
5853: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5854: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5855:
1.63 www 5856: # role and realm
1.1178 raeburn 5857: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5858: if ($realm) {
5859: $realm = '/'.$realm;
5860: }
1.378 raeburn 5861: if ($role eq 'ca') {
1.479 albertel 5862: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5863: $realm = &plainname($rname,$rdom);
1.378 raeburn 5864: }
1.55 www 5865: # realm
1.258 albertel 5866: if ($env{'request.course.id'}) {
1.378 raeburn 5867: if ($env{'request.role'} !~ /^cr/) {
5868: $role = &Apache::lonnet::plaintext($role,&course_type());
1.1257 raeburn 5869: } elsif ($role =~ m{^cr/($match_domain)/\1-domainconfig/(\w+)$}) {
1.1269 raeburn 5870: if ($env{'request.role.desc'}) {
5871: $role = $env{'request.role.desc'};
5872: } else {
5873: $role = &mt('Helpdesk[_1]',' '.$2);
5874: }
1.1257 raeburn 5875: } else {
5876: $role = (split(/\//,$role,4))[-1];
1.378 raeburn 5877: }
1.898 raeburn 5878: if ($env{'request.course.sec'}) {
5879: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5880: }
1.359 albertel 5881: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5882: } else {
5883: $role = &Apache::lonnet::plaintext($role);
1.54 www 5884: }
1.433 albertel 5885:
1.359 albertel 5886: if (!$realm) { $realm=' '; }
1.330 albertel 5887:
1.438 albertel 5888: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5889:
1.101 www 5890: # construct main body tag
1.359 albertel 5891: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 5892: &Apache::lontexconvert::init_math_support();
1.252 albertel 5893:
1.1131 raeburn 5894: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5895:
1.1130 raeburn 5896: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5897: return $bodytag;
1.1130 raeburn 5898: }
1.359 albertel 5899:
1.954 raeburn 5900: if ($public) {
1.433 albertel 5901: undef($role);
5902: }
1.359 albertel 5903:
1.762 bisitz 5904: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5905: #
5906: # Extra info if you are the DC
5907: my $dc_info = '';
5908: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5909: $env{'course.'.$env{'request.course.id'}.
5910: '.domain'}.'/'})) {
5911: my $cid = $env{'request.course.id'};
1.917 raeburn 5912: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5913: $dc_info =~ s/\s+$//;
1.359 albertel 5914: }
5915:
1.1237 raeburn 5916: my $crstype;
5917: if ($env{'request.course.id'}) {
5918: $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
5919: } elsif ($args->{'crstype'}) {
5920: $crstype = $args->{'crstype'};
5921: }
5922: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
5923: undef($role);
5924: } else {
1.1242 raeburn 5925: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 5926: }
1.853 droeschl 5927:
1.903 droeschl 5928: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5929:
5930: # if ($env{'request.state'} eq 'construct') {
5931: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5932: # }
5933:
1.1130 raeburn 5934: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 5935: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5936:
1.1237 raeburn 5937: my ($left,$right) = Apache::lonmenu::primary_menu($crstype);
1.359 albertel 5938:
1.916 droeschl 5939: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5940: if ($dc_info) {
5941: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5942: }
1.1130 raeburn 5943: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 5944: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5945: return $bodytag;
5946: }
1.894 droeschl 5947:
1.927 raeburn 5948: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 5949: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5950: }
1.916 droeschl 5951:
1.1130 raeburn 5952: $bodytag .= $right;
1.852 droeschl 5953:
1.917 raeburn 5954: if ($dc_info) {
5955: $dc_info = &dc_courseid_toggle($dc_info);
5956: }
5957: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5958:
1.1169 raeburn 5959: #if directed to not display the secondary menu, don't.
1.1168 raeburn 5960: if ($args->{'no_secondary_menu'}) {
5961: return $bodytag;
5962: }
1.1169 raeburn 5963: #don't show menus for public users
1.954 raeburn 5964: if (!$public){
1.1154 raeburn 5965: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5966: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5967: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5968: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5969: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.1274 ! raeburn 5970: $args->{'bread_crumbs'},'','',$hostname);
1.1096 raeburn 5971: } elsif ($forcereg) {
5972: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
1.1258 raeburn 5973: $args->{'group'},
1.1274 ! raeburn 5974: $args->{'hide_buttons'},
! 5975: $hostname);
1.1096 raeburn 5976: } else {
5977: $bodytag .=
5978: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5979: $forcereg,$args->{'group'},
5980: $args->{'bread_crumbs'},
1.1274 ! raeburn 5981: $advtoolsref,'',$hostname);
1.920 raeburn 5982: }
1.903 droeschl 5983: }else{
5984: # this is to seperate menu from content when there's no secondary
5985: # menu. Especially needed for public accessible ressources.
5986: $bodytag .= '<hr style="clear:both" />';
5987: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5988: }
1.903 droeschl 5989:
1.235 raeburn 5990: return $bodytag;
1.182 matthew 5991: }
5992:
1.917 raeburn 5993: sub dc_courseid_toggle {
5994: my ($dc_info) = @_;
1.980 raeburn 5995: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5996: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5997: &mt('(More ...)').'</a></span>'.
5998: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5999: }
6000:
1.330 albertel 6001: sub make_attr_string {
6002: my ($register,$attr_ref) = @_;
6003:
6004: if ($attr_ref && !ref($attr_ref)) {
6005: die("addentries Must be a hash ref ".
6006: join(':',caller(1))." ".
6007: join(':',caller(0))." ");
6008: }
6009:
6010: if ($register) {
1.339 albertel 6011: my ($on_load,$on_unload);
6012: foreach my $key (keys(%{$attr_ref})) {
6013: if (lc($key) eq 'onload') {
6014: $on_load.=$attr_ref->{$key}.';';
6015: delete($attr_ref->{$key});
6016:
6017: } elsif (lc($key) eq 'onunload') {
6018: $on_unload.=$attr_ref->{$key}.';';
6019: delete($attr_ref->{$key});
6020: }
6021: }
1.953 droeschl 6022: $attr_ref->{'onload'} = $on_load;
6023: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 6024: }
1.339 albertel 6025:
1.330 albertel 6026: my $attr_string;
1.1159 raeburn 6027: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 6028: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
6029: }
6030: return $attr_string;
6031: }
6032:
6033:
1.182 matthew 6034: ###############################################
1.251 albertel 6035: ###############################################
6036:
6037: =pod
6038:
6039: =item * &endbodytag()
6040:
6041: Returns a uniform footer for LON-CAPA web pages.
6042:
1.635 raeburn 6043: Inputs: 1 - optional reference to an args hash
6044: If in the hash, key for noredirectlink has a value which evaluates to true,
6045: a 'Continue' link is not displayed if the page contains an
6046: internal redirect in the <head></head> section,
6047: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 6048:
6049: =cut
6050:
6051: sub endbodytag {
1.635 raeburn 6052: my ($args) = @_;
1.1080 raeburn 6053: my $endbodytag;
6054: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
6055: $endbodytag='</body>';
6056: }
1.315 albertel 6057: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 6058: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
6059: $endbodytag=
6060: "<br /><a href=\"$env{'internal.head.redirect'}\">".
6061: &mt('Continue').'</a>'.
6062: $endbodytag;
6063: }
1.315 albertel 6064: }
1.251 albertel 6065: return $endbodytag;
6066: }
6067:
1.352 albertel 6068: =pod
6069:
6070: =item * &standard_css()
6071:
6072: Returns a style sheet
6073:
6074: Inputs: (all optional)
6075: domain -> force to color decorate a page for a specific
6076: domain
6077: function -> force usage of a specific rolish color scheme
6078: bgcolor -> override the default page bgcolor
6079:
6080: =cut
6081:
1.343 albertel 6082: sub standard_css {
1.345 albertel 6083: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 6084: $function = &get_users_function() if (!$function);
6085: my $img = &designparm($function.'.img', $domain);
6086: my $tabbg = &designparm($function.'.tabbg', $domain);
6087: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 6088: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 6089: #second colour for later usage
1.345 albertel 6090: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 6091: my $pgbg_or_bgcolor =
6092: $bgcolor ||
1.352 albertel 6093: &designparm($function.'.pgbg', $domain);
1.382 albertel 6094: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 6095: my $alink = &designparm($function.'.alink', $domain);
6096: my $vlink = &designparm($function.'.vlink', $domain);
6097: my $link = &designparm($function.'.link', $domain);
6098:
1.602 albertel 6099: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 6100: my $mono = 'monospace';
1.850 bisitz 6101: my $data_table_head = $sidebg;
6102: my $data_table_light = '#FAFAFA';
1.1060 bisitz 6103: my $data_table_dark = '#E0E0E0';
1.470 banghart 6104: my $data_table_darker = '#CCCCCC';
1.349 albertel 6105: my $data_table_highlight = '#FFFF00';
1.352 albertel 6106: my $mail_new = '#FFBB77';
6107: my $mail_new_hover = '#DD9955';
6108: my $mail_read = '#BBBB77';
6109: my $mail_read_hover = '#999944';
6110: my $mail_replied = '#AAAA88';
6111: my $mail_replied_hover = '#888855';
6112: my $mail_other = '#99BBBB';
6113: my $mail_other_hover = '#669999';
1.391 albertel 6114: my $table_header = '#DDDDDD';
1.489 raeburn 6115: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 6116: my $lg_border_color = '#C8C8C8';
1.952 onken 6117: my $button_hover = '#BF2317';
1.392 albertel 6118:
1.608 albertel 6119: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 6120: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
6121: : '0 3px 0 4px';
1.448 albertel 6122:
1.523 albertel 6123:
1.343 albertel 6124: return <<END;
1.947 droeschl 6125:
6126: /* needed for iframe to allow 100% height in FF */
6127: body, html {
6128: margin: 0;
6129: padding: 0 0.5%;
6130: height: 99%; /* to avoid scrollbars */
6131: }
6132:
1.795 www 6133: body {
1.911 bisitz 6134: font-family: $sans;
6135: line-height:130%;
6136: font-size:0.83em;
6137: color:$font;
1.795 www 6138: }
6139:
1.959 onken 6140: a:focus,
6141: a:focus img {
1.795 www 6142: color: red;
6143: }
1.698 harmsja 6144:
1.911 bisitz 6145: form, .inline {
6146: display: inline;
1.795 www 6147: }
1.721 harmsja 6148:
1.795 www 6149: .LC_right {
1.911 bisitz 6150: text-align:right;
1.795 www 6151: }
6152:
6153: .LC_middle {
1.911 bisitz 6154: vertical-align:middle;
1.795 www 6155: }
1.721 harmsja 6156:
1.1130 raeburn 6157: .LC_floatleft {
6158: float: left;
6159: }
6160:
6161: .LC_floatright {
6162: float: right;
6163: }
6164:
1.911 bisitz 6165: .LC_400Box {
6166: width:400px;
6167: }
1.721 harmsja 6168:
1.947 droeschl 6169: .LC_iframecontainer {
6170: width: 98%;
6171: margin: 0;
6172: position: fixed;
6173: top: 8.5em;
6174: bottom: 0;
6175: }
6176:
6177: .LC_iframecontainer iframe{
6178: border: none;
6179: width: 100%;
6180: height: 100%;
6181: }
6182:
1.778 bisitz 6183: .LC_filename {
6184: font-family: $mono;
6185: white-space:pre;
1.921 bisitz 6186: font-size: 120%;
1.778 bisitz 6187: }
6188:
6189: .LC_fileicon {
6190: border: none;
6191: height: 1.3em;
6192: vertical-align: text-bottom;
6193: margin-right: 0.3em;
6194: text-decoration:none;
6195: }
6196:
1.1008 www 6197: .LC_setting {
6198: text-decoration:underline;
6199: }
6200:
1.350 albertel 6201: .LC_error {
6202: color: red;
6203: }
1.795 www 6204:
1.1097 bisitz 6205: .LC_warning {
6206: color: darkorange;
6207: }
6208:
1.457 albertel 6209: .LC_diff_removed {
1.733 bisitz 6210: color: red;
1.394 albertel 6211: }
1.532 albertel 6212:
6213: .LC_info,
1.457 albertel 6214: .LC_success,
6215: .LC_diff_added {
1.350 albertel 6216: color: green;
6217: }
1.795 www 6218:
1.802 bisitz 6219: div.LC_confirm_box {
6220: background-color: #FAFAFA;
6221: border: 1px solid $lg_border_color;
6222: margin-right: 0;
6223: padding: 5px;
6224: }
6225:
6226: div.LC_confirm_box .LC_error img,
6227: div.LC_confirm_box .LC_success img {
6228: vertical-align: middle;
6229: }
6230:
1.1242 raeburn 6231: .LC_maxwidth {
6232: max-width: 100%;
6233: height: auto;
6234: }
6235:
1.1243 raeburn 6236: .LC_textsize_mobile {
6237: \@media only screen and (max-device-width: 480px) {
6238: -webkit-text-size-adjust:100%; -moz-text-size-adjust:100%; -ms-text-size-adjust:100%;
6239: }
6240: }
6241:
1.440 albertel 6242: .LC_icon {
1.771 droeschl 6243: border: none;
1.790 droeschl 6244: vertical-align: middle;
1.771 droeschl 6245: }
6246:
1.543 albertel 6247: .LC_docs_spacer {
6248: width: 25px;
6249: height: 1px;
1.771 droeschl 6250: border: none;
1.543 albertel 6251: }
1.346 albertel 6252:
1.532 albertel 6253: .LC_internal_info {
1.735 bisitz 6254: color: #999999;
1.532 albertel 6255: }
6256:
1.794 www 6257: .LC_discussion {
1.1050 www 6258: background: $data_table_dark;
1.911 bisitz 6259: border: 1px solid black;
6260: margin: 2px;
1.794 www 6261: }
6262:
6263: .LC_disc_action_left {
1.1050 www 6264: background: $sidebg;
1.911 bisitz 6265: text-align: left;
1.1050 www 6266: padding: 4px;
6267: margin: 2px;
1.794 www 6268: }
6269:
6270: .LC_disc_action_right {
1.1050 www 6271: background: $sidebg;
1.911 bisitz 6272: text-align: right;
1.1050 www 6273: padding: 4px;
6274: margin: 2px;
1.794 www 6275: }
6276:
6277: .LC_disc_new_item {
1.911 bisitz 6278: background: white;
6279: border: 2px solid red;
1.1050 www 6280: margin: 4px;
6281: padding: 4px;
1.794 www 6282: }
6283:
6284: .LC_disc_old_item {
1.911 bisitz 6285: background: white;
1.1050 www 6286: margin: 4px;
6287: padding: 4px;
1.794 www 6288: }
6289:
1.458 albertel 6290: table.LC_pastsubmission {
6291: border: 1px solid black;
6292: margin: 2px;
6293: }
6294:
1.924 bisitz 6295: table#LC_menubuttons {
1.345 albertel 6296: width: 100%;
6297: background: $pgbg;
1.392 albertel 6298: border: 2px;
1.402 albertel 6299: border-collapse: separate;
1.803 bisitz 6300: padding: 0;
1.345 albertel 6301: }
1.392 albertel 6302:
1.801 tempelho 6303: table#LC_title_bar a {
6304: color: $fontmenu;
6305: }
1.836 bisitz 6306:
1.807 droeschl 6307: table#LC_title_bar {
1.819 tempelho 6308: clear: both;
1.836 bisitz 6309: display: none;
1.807 droeschl 6310: }
6311:
1.795 www 6312: table#LC_title_bar,
1.933 droeschl 6313: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 6314: table#LC_title_bar.LC_with_remote {
1.359 albertel 6315: width: 100%;
1.392 albertel 6316: border-color: $pgbg;
6317: border-style: solid;
6318: border-width: $border;
1.379 albertel 6319: background: $pgbg;
1.801 tempelho 6320: color: $fontmenu;
1.392 albertel 6321: border-collapse: collapse;
1.803 bisitz 6322: padding: 0;
1.819 tempelho 6323: margin: 0;
1.359 albertel 6324: }
1.795 www 6325:
1.933 droeschl 6326: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 6327: margin: 0;
6328: padding: 0;
1.933 droeschl 6329: position: relative;
6330: list-style: none;
1.913 droeschl 6331: }
1.933 droeschl 6332: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 6333: display: inline;
6334: }
1.933 droeschl 6335:
6336: .LC_breadcrumb_tools_navigation {
1.913 droeschl 6337: padding: 0;
1.933 droeschl 6338: margin: 0;
6339: float: left;
1.913 droeschl 6340: }
1.933 droeschl 6341: .LC_breadcrumb_tools_tools {
6342: padding: 0;
6343: margin: 0;
1.913 droeschl 6344: float: right;
6345: }
6346:
1.1240 raeburn 6347: .LC_placement_prog {
6348: padding-right: 20px;
6349: font-weight: bold;
6350: font-size: 90%;
6351: }
6352:
1.359 albertel 6353: table#LC_title_bar td {
6354: background: $tabbg;
6355: }
1.795 www 6356:
1.911 bisitz 6357: table#LC_menubuttons img {
1.803 bisitz 6358: border: none;
1.346 albertel 6359: }
1.795 www 6360:
1.842 droeschl 6361: .LC_breadcrumbs_component {
1.911 bisitz 6362: float: right;
6363: margin: 0 1em;
1.357 albertel 6364: }
1.842 droeschl 6365: .LC_breadcrumbs_component img {
1.911 bisitz 6366: vertical-align: middle;
1.777 tempelho 6367: }
1.795 www 6368:
1.1243 raeburn 6369: .LC_breadcrumbs_hoverable {
6370: background: $sidebg;
6371: }
6372:
1.383 albertel 6373: td.LC_table_cell_checkbox {
6374: text-align: center;
6375: }
1.795 www 6376:
6377: .LC_fontsize_small {
1.911 bisitz 6378: font-size: 70%;
1.705 tempelho 6379: }
6380:
1.844 bisitz 6381: #LC_breadcrumbs {
1.911 bisitz 6382: clear:both;
6383: background: $sidebg;
6384: border-bottom: 1px solid $lg_border_color;
6385: line-height: 2.5em;
1.933 droeschl 6386: overflow: hidden;
1.911 bisitz 6387: margin: 0;
6388: padding: 0;
1.995 raeburn 6389: text-align: left;
1.819 tempelho 6390: }
1.862 bisitz 6391:
1.1098 bisitz 6392: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6393: clear:both;
6394: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6395: border: 1px solid $sidebg;
1.1098 bisitz 6396: margin: 0 0 10px 0;
1.966 bisitz 6397: padding: 3px;
1.995 raeburn 6398: text-align: left;
1.822 bisitz 6399: }
6400:
1.795 www 6401: .LC_fontsize_medium {
1.911 bisitz 6402: font-size: 85%;
1.705 tempelho 6403: }
6404:
1.795 www 6405: .LC_fontsize_large {
1.911 bisitz 6406: font-size: 120%;
1.705 tempelho 6407: }
6408:
1.346 albertel 6409: .LC_menubuttons_inline_text {
6410: color: $font;
1.698 harmsja 6411: font-size: 90%;
1.701 harmsja 6412: padding-left:3px;
1.346 albertel 6413: }
6414:
1.934 droeschl 6415: .LC_menubuttons_inline_text img{
6416: vertical-align: middle;
6417: }
6418:
1.1051 www 6419: li.LC_menubuttons_inline_text img {
1.951 onken 6420: cursor:pointer;
1.1002 droeschl 6421: text-decoration: none;
1.951 onken 6422: }
6423:
1.526 www 6424: .LC_menubuttons_link {
6425: text-decoration: none;
6426: }
1.795 www 6427:
1.522 albertel 6428: .LC_menubuttons_category {
1.521 www 6429: color: $font;
1.526 www 6430: background: $pgbg;
1.521 www 6431: font-size: larger;
6432: font-weight: bold;
6433: }
6434:
1.346 albertel 6435: td.LC_menubuttons_text {
1.911 bisitz 6436: color: $font;
1.346 albertel 6437: }
1.706 harmsja 6438:
1.346 albertel 6439: .LC_current_location {
6440: background: $tabbg;
6441: }
1.795 www 6442:
1.938 bisitz 6443: table.LC_data_table {
1.347 albertel 6444: border: 1px solid #000000;
1.402 albertel 6445: border-collapse: separate;
1.426 albertel 6446: border-spacing: 1px;
1.610 albertel 6447: background: $pgbg;
1.347 albertel 6448: }
1.795 www 6449:
1.422 albertel 6450: .LC_data_table_dense {
6451: font-size: small;
6452: }
1.795 www 6453:
1.507 raeburn 6454: table.LC_nested_outer {
6455: border: 1px solid #000000;
1.589 raeburn 6456: border-collapse: collapse;
1.803 bisitz 6457: border-spacing: 0;
1.507 raeburn 6458: width: 100%;
6459: }
1.795 www 6460:
1.879 raeburn 6461: table.LC_innerpickbox,
1.507 raeburn 6462: table.LC_nested {
1.803 bisitz 6463: border: none;
1.589 raeburn 6464: border-collapse: collapse;
1.803 bisitz 6465: border-spacing: 0;
1.507 raeburn 6466: width: 100%;
6467: }
1.795 www 6468:
1.911 bisitz 6469: table.LC_data_table tr th,
6470: table.LC_calendar tr th,
1.879 raeburn 6471: table.LC_prior_tries tr th,
6472: table.LC_innerpickbox tr th {
1.349 albertel 6473: font-weight: bold;
6474: background-color: $data_table_head;
1.801 tempelho 6475: color:$fontmenu;
1.701 harmsja 6476: font-size:90%;
1.347 albertel 6477: }
1.795 www 6478:
1.879 raeburn 6479: table.LC_innerpickbox tr th,
6480: table.LC_innerpickbox tr td {
6481: vertical-align: top;
6482: }
6483:
1.711 raeburn 6484: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6485: background-color: #CCCCCC;
1.711 raeburn 6486: font-weight: bold;
6487: text-align: left;
6488: }
1.795 www 6489:
1.912 bisitz 6490: table.LC_data_table tr.LC_odd_row > td {
6491: background-color: $data_table_light;
6492: padding: 2px;
6493: vertical-align: top;
6494: }
6495:
1.809 bisitz 6496: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6497: background-color: $data_table_light;
1.912 bisitz 6498: vertical-align: top;
6499: }
6500:
6501: table.LC_data_table tr.LC_even_row > td {
6502: background-color: $data_table_dark;
1.425 albertel 6503: padding: 2px;
1.900 bisitz 6504: vertical-align: top;
1.347 albertel 6505: }
1.795 www 6506:
1.809 bisitz 6507: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6508: background-color: $data_table_dark;
1.900 bisitz 6509: vertical-align: top;
1.347 albertel 6510: }
1.795 www 6511:
1.425 albertel 6512: table.LC_data_table tr.LC_data_table_highlight td {
6513: background-color: $data_table_darker;
6514: }
1.795 www 6515:
1.639 raeburn 6516: table.LC_data_table tr td.LC_leftcol_header {
6517: background-color: $data_table_head;
6518: font-weight: bold;
6519: }
1.795 www 6520:
1.451 albertel 6521: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6522: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6523: font-weight: bold;
6524: font-style: italic;
6525: text-align: center;
6526: padding: 8px;
1.347 albertel 6527: }
1.795 www 6528:
1.1114 raeburn 6529: table.LC_data_table tr.LC_empty_row td,
6530: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6531: background-color: $sidebg;
6532: }
6533:
6534: table.LC_nested tr.LC_empty_row td {
6535: background-color: #FFFFFF;
6536: }
6537:
1.890 droeschl 6538: table.LC_caption {
6539: }
6540:
1.507 raeburn 6541: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6542: padding: 4ex
6543: }
1.795 www 6544:
1.507 raeburn 6545: table.LC_nested_outer tr th {
6546: font-weight: bold;
1.801 tempelho 6547: color:$fontmenu;
1.507 raeburn 6548: background-color: $data_table_head;
1.701 harmsja 6549: font-size: small;
1.507 raeburn 6550: border-bottom: 1px solid #000000;
6551: }
1.795 www 6552:
1.507 raeburn 6553: table.LC_nested_outer tr td.LC_subheader {
6554: background-color: $data_table_head;
6555: font-weight: bold;
6556: font-size: small;
6557: border-bottom: 1px solid #000000;
6558: text-align: right;
1.451 albertel 6559: }
1.795 www 6560:
1.507 raeburn 6561: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6562: background-color: #CCCCCC;
1.451 albertel 6563: font-weight: bold;
6564: font-size: small;
1.507 raeburn 6565: text-align: center;
6566: }
1.795 www 6567:
1.589 raeburn 6568: table.LC_nested tr.LC_info_row td.LC_left_item,
6569: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6570: text-align: left;
1.451 albertel 6571: }
1.795 www 6572:
1.507 raeburn 6573: table.LC_nested td {
1.735 bisitz 6574: background-color: #FFFFFF;
1.451 albertel 6575: font-size: small;
1.507 raeburn 6576: }
1.795 www 6577:
1.507 raeburn 6578: table.LC_nested_outer tr th.LC_right_item,
6579: table.LC_nested tr.LC_info_row td.LC_right_item,
6580: table.LC_nested tr.LC_odd_row td.LC_right_item,
6581: table.LC_nested tr td.LC_right_item {
1.451 albertel 6582: text-align: right;
6583: }
6584:
1.507 raeburn 6585: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6586: background-color: #EEEEEE;
1.451 albertel 6587: }
6588:
1.473 raeburn 6589: table.LC_createuser {
6590: }
6591:
6592: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6593: font-size: small;
1.473 raeburn 6594: }
6595:
6596: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6597: background-color: #CCCCCC;
1.473 raeburn 6598: font-weight: bold;
6599: text-align: center;
6600: }
6601:
1.349 albertel 6602: table.LC_calendar {
6603: border: 1px solid #000000;
6604: border-collapse: collapse;
1.917 raeburn 6605: width: 98%;
1.349 albertel 6606: }
1.795 www 6607:
1.349 albertel 6608: table.LC_calendar_pickdate {
6609: font-size: xx-small;
6610: }
1.795 www 6611:
1.349 albertel 6612: table.LC_calendar tr td {
6613: border: 1px solid #000000;
6614: vertical-align: top;
1.917 raeburn 6615: width: 14%;
1.349 albertel 6616: }
1.795 www 6617:
1.349 albertel 6618: table.LC_calendar tr td.LC_calendar_day_empty {
6619: background-color: $data_table_dark;
6620: }
1.795 www 6621:
1.779 bisitz 6622: table.LC_calendar tr td.LC_calendar_day_current {
6623: background-color: $data_table_highlight;
1.777 tempelho 6624: }
1.795 www 6625:
1.938 bisitz 6626: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6627: background-color: $mail_new;
6628: }
1.795 www 6629:
1.938 bisitz 6630: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6631: background-color: $mail_new_hover;
6632: }
1.795 www 6633:
1.938 bisitz 6634: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6635: background-color: $mail_read;
6636: }
1.795 www 6637:
1.938 bisitz 6638: /*
6639: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6640: background-color: $mail_read_hover;
6641: }
1.938 bisitz 6642: */
1.795 www 6643:
1.938 bisitz 6644: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6645: background-color: $mail_replied;
6646: }
1.795 www 6647:
1.938 bisitz 6648: /*
6649: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6650: background-color: $mail_replied_hover;
6651: }
1.938 bisitz 6652: */
1.795 www 6653:
1.938 bisitz 6654: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6655: background-color: $mail_other;
6656: }
1.795 www 6657:
1.938 bisitz 6658: /*
6659: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6660: background-color: $mail_other_hover;
6661: }
1.938 bisitz 6662: */
1.494 raeburn 6663:
1.777 tempelho 6664: table.LC_data_table tr > td.LC_browser_file,
6665: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6666: background: #AAEE77;
1.389 albertel 6667: }
1.795 www 6668:
1.777 tempelho 6669: table.LC_data_table tr > td.LC_browser_file_locked,
6670: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6671: background: #FFAA99;
1.387 albertel 6672: }
1.795 www 6673:
1.777 tempelho 6674: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6675: background: #888888;
1.779 bisitz 6676: }
1.795 www 6677:
1.777 tempelho 6678: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6679: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6680: background: #F8F866;
1.777 tempelho 6681: }
1.795 www 6682:
1.696 bisitz 6683: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6684: background: #E0E8FF;
1.387 albertel 6685: }
1.696 bisitz 6686:
1.707 bisitz 6687: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6688: /* background: #77FF77; */
1.707 bisitz 6689: }
1.795 www 6690:
1.707 bisitz 6691: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6692: border-right: 8px solid #FFFF77;
1.707 bisitz 6693: }
1.795 www 6694:
1.707 bisitz 6695: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6696: border-right: 8px solid #FFAA77;
1.707 bisitz 6697: }
1.795 www 6698:
1.707 bisitz 6699: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6700: border-right: 8px solid #FF7777;
1.707 bisitz 6701: }
1.795 www 6702:
1.707 bisitz 6703: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6704: border-right: 8px solid #AAFF77;
1.707 bisitz 6705: }
1.795 www 6706:
1.707 bisitz 6707: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6708: border-right: 8px solid #11CC55;
1.707 bisitz 6709: }
6710:
1.388 albertel 6711: span.LC_current_location {
1.701 harmsja 6712: font-size:larger;
1.388 albertel 6713: background: $pgbg;
6714: }
1.387 albertel 6715:
1.1029 www 6716: span.LC_current_nav_location {
6717: font-weight:bold;
6718: background: $sidebg;
6719: }
6720:
1.395 albertel 6721: span.LC_parm_menu_item {
6722: font-size: larger;
6723: }
1.795 www 6724:
1.395 albertel 6725: span.LC_parm_scope_all {
6726: color: red;
6727: }
1.795 www 6728:
1.395 albertel 6729: span.LC_parm_scope_folder {
6730: color: green;
6731: }
1.795 www 6732:
1.395 albertel 6733: span.LC_parm_scope_resource {
6734: color: orange;
6735: }
1.795 www 6736:
1.395 albertel 6737: span.LC_parm_part {
6738: color: blue;
6739: }
1.795 www 6740:
1.911 bisitz 6741: span.LC_parm_folder,
6742: span.LC_parm_symb {
1.395 albertel 6743: font-size: x-small;
6744: font-family: $mono;
6745: color: #AAAAAA;
6746: }
6747:
1.977 bisitz 6748: ul.LC_parm_parmlist li {
6749: display: inline-block;
6750: padding: 0.3em 0.8em;
6751: vertical-align: top;
6752: width: 150px;
6753: border-top:1px solid $lg_border_color;
6754: }
6755:
1.795 www 6756: td.LC_parm_overview_level_menu,
6757: td.LC_parm_overview_map_menu,
6758: td.LC_parm_overview_parm_selectors,
6759: td.LC_parm_overview_restrictions {
1.396 albertel 6760: border: 1px solid black;
6761: border-collapse: collapse;
6762: }
1.795 www 6763:
1.396 albertel 6764: table.LC_parm_overview_restrictions td {
6765: border-width: 1px 4px 1px 4px;
6766: border-style: solid;
6767: border-color: $pgbg;
6768: text-align: center;
6769: }
1.795 www 6770:
1.396 albertel 6771: table.LC_parm_overview_restrictions th {
6772: background: $tabbg;
6773: border-width: 1px 4px 1px 4px;
6774: border-style: solid;
6775: border-color: $pgbg;
6776: }
1.795 www 6777:
1.398 albertel 6778: table#LC_helpmenu {
1.803 bisitz 6779: border: none;
1.398 albertel 6780: height: 55px;
1.803 bisitz 6781: border-spacing: 0;
1.398 albertel 6782: }
6783:
6784: table#LC_helpmenu fieldset legend {
6785: font-size: larger;
6786: }
1.795 www 6787:
1.397 albertel 6788: table#LC_helpmenu_links {
6789: width: 100%;
6790: border: 1px solid black;
6791: background: $pgbg;
1.803 bisitz 6792: padding: 0;
1.397 albertel 6793: border-spacing: 1px;
6794: }
1.795 www 6795:
1.397 albertel 6796: table#LC_helpmenu_links tr td {
6797: padding: 1px;
6798: background: $tabbg;
1.399 albertel 6799: text-align: center;
6800: font-weight: bold;
1.397 albertel 6801: }
1.396 albertel 6802:
1.795 www 6803: table#LC_helpmenu_links a:link,
6804: table#LC_helpmenu_links a:visited,
1.397 albertel 6805: table#LC_helpmenu_links a:active {
6806: text-decoration: none;
6807: color: $font;
6808: }
1.795 www 6809:
1.397 albertel 6810: table#LC_helpmenu_links a:hover {
6811: text-decoration: underline;
6812: color: $vlink;
6813: }
1.396 albertel 6814:
1.417 albertel 6815: .LC_chrt_popup_exists {
6816: border: 1px solid #339933;
6817: margin: -1px;
6818: }
1.795 www 6819:
1.417 albertel 6820: .LC_chrt_popup_up {
6821: border: 1px solid yellow;
6822: margin: -1px;
6823: }
1.795 www 6824:
1.417 albertel 6825: .LC_chrt_popup {
6826: border: 1px solid #8888FF;
6827: background: #CCCCFF;
6828: }
1.795 www 6829:
1.421 albertel 6830: table.LC_pick_box {
6831: border-collapse: separate;
6832: background: white;
6833: border: 1px solid black;
6834: border-spacing: 1px;
6835: }
1.795 www 6836:
1.421 albertel 6837: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6838: background: $sidebg;
1.421 albertel 6839: font-weight: bold;
1.900 bisitz 6840: text-align: left;
1.740 bisitz 6841: vertical-align: top;
1.421 albertel 6842: width: 184px;
6843: padding: 8px;
6844: }
1.795 www 6845:
1.579 raeburn 6846: table.LC_pick_box td.LC_pick_box_value {
6847: text-align: left;
6848: padding: 8px;
6849: }
1.795 www 6850:
1.579 raeburn 6851: table.LC_pick_box td.LC_pick_box_select {
6852: text-align: left;
6853: padding: 8px;
6854: }
1.795 www 6855:
1.424 albertel 6856: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6857: padding: 0;
1.421 albertel 6858: height: 1px;
6859: background: black;
6860: }
1.795 www 6861:
1.421 albertel 6862: table.LC_pick_box td.LC_pick_box_submit {
6863: text-align: right;
6864: }
1.795 www 6865:
1.579 raeburn 6866: table.LC_pick_box td.LC_evenrow_value {
6867: text-align: left;
6868: padding: 8px;
6869: background-color: $data_table_light;
6870: }
1.795 www 6871:
1.579 raeburn 6872: table.LC_pick_box td.LC_oddrow_value {
6873: text-align: left;
6874: padding: 8px;
6875: background-color: $data_table_light;
6876: }
1.795 www 6877:
1.579 raeburn 6878: span.LC_helpform_receipt_cat {
6879: font-weight: bold;
6880: }
1.795 www 6881:
1.424 albertel 6882: table.LC_group_priv_box {
6883: background: white;
6884: border: 1px solid black;
6885: border-spacing: 1px;
6886: }
1.795 www 6887:
1.424 albertel 6888: table.LC_group_priv_box td.LC_pick_box_title {
6889: background: $tabbg;
6890: font-weight: bold;
6891: text-align: right;
6892: width: 184px;
6893: }
1.795 www 6894:
1.424 albertel 6895: table.LC_group_priv_box td.LC_groups_fixed {
6896: background: $data_table_light;
6897: text-align: center;
6898: }
1.795 www 6899:
1.424 albertel 6900: table.LC_group_priv_box td.LC_groups_optional {
6901: background: $data_table_dark;
6902: text-align: center;
6903: }
1.795 www 6904:
1.424 albertel 6905: table.LC_group_priv_box td.LC_groups_functionality {
6906: background: $data_table_darker;
6907: text-align: center;
6908: font-weight: bold;
6909: }
1.795 www 6910:
1.424 albertel 6911: table.LC_group_priv td {
6912: text-align: left;
1.803 bisitz 6913: padding: 0;
1.424 albertel 6914: }
6915:
6916: .LC_navbuttons {
6917: margin: 2ex 0ex 2ex 0ex;
6918: }
1.795 www 6919:
1.423 albertel 6920: .LC_topic_bar {
6921: font-weight: bold;
6922: background: $tabbg;
1.918 wenzelju 6923: margin: 1em 0em 1em 2em;
1.805 bisitz 6924: padding: 3px;
1.918 wenzelju 6925: font-size: 1.2em;
1.423 albertel 6926: }
1.795 www 6927:
1.423 albertel 6928: .LC_topic_bar span {
1.918 wenzelju 6929: left: 0.5em;
6930: position: absolute;
1.423 albertel 6931: vertical-align: middle;
1.918 wenzelju 6932: font-size: 1.2em;
1.423 albertel 6933: }
1.795 www 6934:
1.423 albertel 6935: table.LC_course_group_status {
6936: margin: 20px;
6937: }
1.795 www 6938:
1.423 albertel 6939: table.LC_status_selector td {
6940: vertical-align: top;
6941: text-align: center;
1.424 albertel 6942: padding: 4px;
6943: }
1.795 www 6944:
1.599 albertel 6945: div.LC_feedback_link {
1.616 albertel 6946: clear: both;
1.829 kalberla 6947: background: $sidebg;
1.779 bisitz 6948: width: 100%;
1.829 kalberla 6949: padding-bottom: 10px;
6950: border: 1px $tabbg solid;
1.833 kalberla 6951: height: 22px;
6952: line-height: 22px;
6953: padding-top: 5px;
6954: }
6955:
6956: div.LC_feedback_link img {
6957: height: 22px;
1.867 kalberla 6958: vertical-align:middle;
1.829 kalberla 6959: }
6960:
1.911 bisitz 6961: div.LC_feedback_link a {
1.829 kalberla 6962: text-decoration: none;
1.489 raeburn 6963: }
1.795 www 6964:
1.867 kalberla 6965: div.LC_comblock {
1.911 bisitz 6966: display:inline;
1.867 kalberla 6967: color:$font;
6968: font-size:90%;
6969: }
6970:
6971: div.LC_feedback_link div.LC_comblock {
6972: padding-left:5px;
6973: }
6974:
6975: div.LC_feedback_link div.LC_comblock a {
6976: color:$font;
6977: }
6978:
1.489 raeburn 6979: span.LC_feedback_link {
1.858 bisitz 6980: /* background: $feedback_link_bg; */
1.599 albertel 6981: font-size: larger;
6982: }
1.795 www 6983:
1.599 albertel 6984: span.LC_message_link {
1.858 bisitz 6985: /* background: $feedback_link_bg; */
1.599 albertel 6986: font-size: larger;
6987: position: absolute;
6988: right: 1em;
1.489 raeburn 6989: }
1.421 albertel 6990:
1.515 albertel 6991: table.LC_prior_tries {
1.524 albertel 6992: border: 1px solid #000000;
6993: border-collapse: separate;
6994: border-spacing: 1px;
1.515 albertel 6995: }
1.523 albertel 6996:
1.515 albertel 6997: table.LC_prior_tries td {
1.524 albertel 6998: padding: 2px;
1.515 albertel 6999: }
1.523 albertel 7000:
7001: .LC_answer_correct {
1.795 www 7002: background: lightgreen;
7003: color: darkgreen;
7004: padding: 6px;
1.523 albertel 7005: }
1.795 www 7006:
1.523 albertel 7007: .LC_answer_charged_try {
1.797 www 7008: background: #FFAAAA;
1.795 www 7009: color: darkred;
7010: padding: 6px;
1.523 albertel 7011: }
1.795 www 7012:
1.779 bisitz 7013: .LC_answer_not_charged_try,
1.523 albertel 7014: .LC_answer_no_grade,
7015: .LC_answer_late {
1.795 www 7016: background: lightyellow;
1.523 albertel 7017: color: black;
1.795 www 7018: padding: 6px;
1.523 albertel 7019: }
1.795 www 7020:
1.523 albertel 7021: .LC_answer_previous {
1.795 www 7022: background: lightblue;
7023: color: darkblue;
7024: padding: 6px;
1.523 albertel 7025: }
1.795 www 7026:
1.779 bisitz 7027: .LC_answer_no_message {
1.777 tempelho 7028: background: #FFFFFF;
7029: color: black;
1.795 www 7030: padding: 6px;
1.779 bisitz 7031: }
1.795 www 7032:
1.779 bisitz 7033: .LC_answer_unknown {
7034: background: orange;
7035: color: black;
1.795 www 7036: padding: 6px;
1.777 tempelho 7037: }
1.795 www 7038:
1.529 albertel 7039: span.LC_prior_numerical,
7040: span.LC_prior_string,
7041: span.LC_prior_custom,
7042: span.LC_prior_reaction,
7043: span.LC_prior_math {
1.925 bisitz 7044: font-family: $mono;
1.523 albertel 7045: white-space: pre;
7046: }
7047:
1.525 albertel 7048: span.LC_prior_string {
1.925 bisitz 7049: font-family: $mono;
1.525 albertel 7050: white-space: pre;
7051: }
7052:
1.523 albertel 7053: table.LC_prior_option {
7054: width: 100%;
7055: border-collapse: collapse;
7056: }
1.795 www 7057:
1.911 bisitz 7058: table.LC_prior_rank,
1.795 www 7059: table.LC_prior_match {
1.528 albertel 7060: border-collapse: collapse;
7061: }
1.795 www 7062:
1.528 albertel 7063: table.LC_prior_option tr td,
7064: table.LC_prior_rank tr td,
7065: table.LC_prior_match tr td {
1.524 albertel 7066: border: 1px solid #000000;
1.515 albertel 7067: }
7068:
1.855 bisitz 7069: .LC_nobreak {
1.544 albertel 7070: white-space: nowrap;
1.519 raeburn 7071: }
7072:
1.576 raeburn 7073: span.LC_cusr_emph {
7074: font-style: italic;
7075: }
7076:
1.633 raeburn 7077: span.LC_cusr_subheading {
7078: font-weight: normal;
7079: font-size: 85%;
7080: }
7081:
1.861 bisitz 7082: div.LC_docs_entry_move {
1.859 bisitz 7083: border: 1px solid #BBBBBB;
1.545 albertel 7084: background: #DDDDDD;
1.861 bisitz 7085: width: 22px;
1.859 bisitz 7086: padding: 1px;
7087: margin: 0;
1.545 albertel 7088: }
7089:
1.861 bisitz 7090: table.LC_data_table tr > td.LC_docs_entry_commands,
7091: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 7092: font-size: x-small;
7093: }
1.795 www 7094:
1.861 bisitz 7095: .LC_docs_entry_parameter {
7096: white-space: nowrap;
7097: }
7098:
1.544 albertel 7099: .LC_docs_copy {
1.545 albertel 7100: color: #000099;
1.544 albertel 7101: }
1.795 www 7102:
1.544 albertel 7103: .LC_docs_cut {
1.545 albertel 7104: color: #550044;
1.544 albertel 7105: }
1.795 www 7106:
1.544 albertel 7107: .LC_docs_rename {
1.545 albertel 7108: color: #009900;
1.544 albertel 7109: }
1.795 www 7110:
1.544 albertel 7111: .LC_docs_remove {
1.545 albertel 7112: color: #990000;
7113: }
7114:
1.547 albertel 7115: .LC_docs_reinit_warn,
7116: .LC_docs_ext_edit {
7117: font-size: x-small;
7118: }
7119:
1.545 albertel 7120: table.LC_docs_adddocs td,
7121: table.LC_docs_adddocs th {
7122: border: 1px solid #BBBBBB;
7123: padding: 4px;
7124: background: #DDDDDD;
1.543 albertel 7125: }
7126:
1.584 albertel 7127: table.LC_sty_begin {
7128: background: #BBFFBB;
7129: }
1.795 www 7130:
1.584 albertel 7131: table.LC_sty_end {
7132: background: #FFBBBB;
7133: }
7134:
1.589 raeburn 7135: table.LC_double_column {
1.803 bisitz 7136: border-width: 0;
1.589 raeburn 7137: border-collapse: collapse;
7138: width: 100%;
7139: padding: 2px;
7140: }
7141:
7142: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 7143: top: 2px;
1.589 raeburn 7144: left: 2px;
7145: width: 47%;
7146: vertical-align: top;
7147: }
7148:
7149: table.LC_double_column tr td.LC_right_col {
7150: top: 2px;
1.779 bisitz 7151: right: 2px;
1.589 raeburn 7152: width: 47%;
7153: vertical-align: top;
7154: }
7155:
1.591 raeburn 7156: div.LC_left_float {
7157: float: left;
7158: padding-right: 5%;
1.597 albertel 7159: padding-bottom: 4px;
1.591 raeburn 7160: }
7161:
7162: div.LC_clear_float_header {
1.597 albertel 7163: padding-bottom: 2px;
1.591 raeburn 7164: }
7165:
7166: div.LC_clear_float_footer {
1.597 albertel 7167: padding-top: 10px;
1.591 raeburn 7168: clear: both;
7169: }
7170:
1.597 albertel 7171: div.LC_grade_show_user {
1.941 bisitz 7172: /* border-left: 5px solid $sidebg; */
7173: border-top: 5px solid #000000;
7174: margin: 50px 0 0 0;
1.936 bisitz 7175: padding: 15px 0 5px 10px;
1.597 albertel 7176: }
1.795 www 7177:
1.936 bisitz 7178: div.LC_grade_show_user_odd_row {
1.941 bisitz 7179: /* border-left: 5px solid #000000; */
7180: }
7181:
7182: div.LC_grade_show_user div.LC_Box {
7183: margin-right: 50px;
1.597 albertel 7184: }
7185:
7186: div.LC_grade_submissions,
7187: div.LC_grade_message_center,
1.936 bisitz 7188: div.LC_grade_info_links {
1.597 albertel 7189: margin: 5px;
7190: width: 99%;
7191: background: #FFFFFF;
7192: }
1.795 www 7193:
1.597 albertel 7194: div.LC_grade_submissions_header,
1.936 bisitz 7195: div.LC_grade_message_center_header {
1.705 tempelho 7196: font-weight: bold;
7197: font-size: large;
1.597 albertel 7198: }
1.795 www 7199:
1.597 albertel 7200: div.LC_grade_submissions_body,
1.936 bisitz 7201: div.LC_grade_message_center_body {
1.597 albertel 7202: border: 1px solid black;
7203: width: 99%;
7204: background: #FFFFFF;
7205: }
1.795 www 7206:
1.613 albertel 7207: table.LC_scantron_action {
7208: width: 100%;
7209: }
1.795 www 7210:
1.613 albertel 7211: table.LC_scantron_action tr th {
1.698 harmsja 7212: font-weight:bold;
7213: font-style:normal;
1.613 albertel 7214: }
1.795 www 7215:
1.779 bisitz 7216: .LC_edit_problem_header,
1.614 albertel 7217: div.LC_edit_problem_footer {
1.705 tempelho 7218: font-weight: normal;
7219: font-size: medium;
1.602 albertel 7220: margin: 2px;
1.1060 bisitz 7221: background-color: $sidebg;
1.600 albertel 7222: }
1.795 www 7223:
1.600 albertel 7224: div.LC_edit_problem_header,
1.602 albertel 7225: div.LC_edit_problem_header div,
1.614 albertel 7226: div.LC_edit_problem_footer,
7227: div.LC_edit_problem_footer div,
1.602 albertel 7228: div.LC_edit_problem_editxml_header,
7229: div.LC_edit_problem_editxml_header div {
1.1205 golterma 7230: z-index: 100;
1.600 albertel 7231: }
1.795 www 7232:
1.600 albertel 7233: div.LC_edit_problem_header_title {
1.705 tempelho 7234: font-weight: bold;
7235: font-size: larger;
1.602 albertel 7236: background: $tabbg;
7237: padding: 3px;
1.1060 bisitz 7238: margin: 0 0 5px 0;
1.602 albertel 7239: }
1.795 www 7240:
1.602 albertel 7241: table.LC_edit_problem_header_title {
7242: width: 100%;
1.600 albertel 7243: background: $tabbg;
1.602 albertel 7244: }
7245:
1.1205 golterma 7246: div.LC_edit_actionbar {
7247: background-color: $sidebg;
1.1218 droeschl 7248: margin: 0;
7249: padding: 0;
7250: line-height: 200%;
1.602 albertel 7251: }
1.795 www 7252:
1.1218 droeschl 7253: div.LC_edit_actionbar div{
7254: padding: 0;
7255: margin: 0;
7256: display: inline-block;
1.600 albertel 7257: }
1.795 www 7258:
1.1124 bisitz 7259: .LC_edit_opt {
7260: padding-left: 1em;
7261: white-space: nowrap;
7262: }
7263:
1.1152 golterma 7264: .LC_edit_problem_latexhelper{
7265: text-align: right;
7266: }
7267:
7268: #LC_edit_problem_colorful div{
7269: margin-left: 40px;
7270: }
7271:
1.1205 golterma 7272: #LC_edit_problem_codemirror div{
7273: margin-left: 0px;
7274: }
7275:
1.911 bisitz 7276: img.stift {
1.803 bisitz 7277: border-width: 0;
7278: vertical-align: middle;
1.677 riegler 7279: }
1.680 riegler 7280:
1.923 bisitz 7281: table td.LC_mainmenu_col_fieldset {
1.680 riegler 7282: vertical-align: top;
1.777 tempelho 7283: }
1.795 www 7284:
1.716 raeburn 7285: div.LC_createcourse {
1.911 bisitz 7286: margin: 10px 10px 10px 10px;
1.716 raeburn 7287: }
7288:
1.917 raeburn 7289: .LC_dccid {
1.1130 raeburn 7290: float: right;
1.917 raeburn 7291: margin: 0.2em 0 0 0;
7292: padding: 0;
7293: font-size: 90%;
7294: display:none;
7295: }
7296:
1.897 wenzelju 7297: ol.LC_primary_menu a:hover,
1.721 harmsja 7298: ol#LC_MenuBreadcrumbs a:hover,
7299: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 7300: ul#LC_secondary_menu a:hover,
1.721 harmsja 7301: .LC_FormSectionClearButton input:hover
1.795 www 7302: ul.LC_TabContent li:hover a {
1.952 onken 7303: color:$button_hover;
1.911 bisitz 7304: text-decoration:none;
1.693 droeschl 7305: }
7306:
1.779 bisitz 7307: h1 {
1.911 bisitz 7308: padding: 0;
7309: line-height:130%;
1.693 droeschl 7310: }
1.698 harmsja 7311:
1.911 bisitz 7312: h2,
7313: h3,
7314: h4,
7315: h5,
7316: h6 {
7317: margin: 5px 0 5px 0;
7318: padding: 0;
7319: line-height:130%;
1.693 droeschl 7320: }
1.795 www 7321:
7322: .LC_hcell {
1.911 bisitz 7323: padding:3px 15px 3px 15px;
7324: margin: 0;
7325: background-color:$tabbg;
7326: color:$fontmenu;
7327: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 7328: }
1.795 www 7329:
1.840 bisitz 7330: .LC_Box > .LC_hcell {
1.911 bisitz 7331: margin: 0 -10px 10px -10px;
1.835 bisitz 7332: }
7333:
1.721 harmsja 7334: .LC_noBorder {
1.911 bisitz 7335: border: 0;
1.698 harmsja 7336: }
1.693 droeschl 7337:
1.721 harmsja 7338: .LC_FormSectionClearButton input {
1.911 bisitz 7339: background-color:transparent;
7340: border: none;
7341: cursor:pointer;
7342: text-decoration:underline;
1.693 droeschl 7343: }
1.763 bisitz 7344:
7345: .LC_help_open_topic {
1.911 bisitz 7346: color: #FFFFFF;
7347: background-color: #EEEEFF;
7348: margin: 1px;
7349: padding: 4px;
7350: border: 1px solid #000033;
7351: white-space: nowrap;
7352: /* vertical-align: middle; */
1.759 neumanie 7353: }
1.693 droeschl 7354:
1.911 bisitz 7355: dl,
7356: ul,
7357: div,
7358: fieldset {
7359: margin: 10px 10px 10px 0;
7360: /* overflow: hidden; */
1.693 droeschl 7361: }
1.795 www 7362:
1.1211 raeburn 7363: article.geogebraweb div {
7364: margin: 0;
7365: }
7366:
1.838 bisitz 7367: fieldset > legend {
1.911 bisitz 7368: font-weight: bold;
7369: padding: 0 5px 0 5px;
1.838 bisitz 7370: }
7371:
1.813 bisitz 7372: #LC_nav_bar {
1.911 bisitz 7373: float: left;
1.995 raeburn 7374: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7375: margin: 0 0 2px 0;
1.807 droeschl 7376: }
7377:
1.916 droeschl 7378: #LC_realm {
7379: margin: 0.2em 0 0 0;
7380: padding: 0;
7381: font-weight: bold;
7382: text-align: center;
1.995 raeburn 7383: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7384: }
7385:
1.911 bisitz 7386: #LC_nav_bar em {
7387: font-weight: bold;
7388: font-style: normal;
1.807 droeschl 7389: }
7390:
1.897 wenzelju 7391: ol.LC_primary_menu {
1.934 droeschl 7392: margin: 0;
1.1076 raeburn 7393: padding: 0;
1.807 droeschl 7394: }
7395:
1.852 droeschl 7396: ol#LC_PathBreadcrumbs {
1.911 bisitz 7397: margin: 0;
1.693 droeschl 7398: }
7399:
1.897 wenzelju 7400: ol.LC_primary_menu li {
1.1076 raeburn 7401: color: RGB(80, 80, 80);
7402: vertical-align: middle;
7403: text-align: left;
7404: list-style: none;
1.1205 golterma 7405: position: relative;
1.1076 raeburn 7406: float: left;
1.1205 golterma 7407: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7408: line-height: 1.5em;
1.1076 raeburn 7409: }
7410:
1.1205 golterma 7411: ol.LC_primary_menu li a,
7412: ol.LC_primary_menu li p {
1.1076 raeburn 7413: display: block;
7414: margin: 0;
7415: padding: 0 5px 0 10px;
7416: text-decoration: none;
7417: }
7418:
1.1205 golterma 7419: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7420: display: inline-block;
7421: width: 95%;
7422: text-align: left;
7423: }
7424:
7425: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7426: display: inline-block;
7427: width: 5%;
7428: float: right;
7429: text-align: right;
7430: font-size: 70%;
7431: }
7432:
7433: ol.LC_primary_menu ul {
1.1076 raeburn 7434: display: none;
1.1205 golterma 7435: width: 15em;
1.1076 raeburn 7436: background-color: $data_table_light;
1.1205 golterma 7437: position: absolute;
7438: top: 100%;
1.1076 raeburn 7439: }
7440:
1.1205 golterma 7441: ol.LC_primary_menu ul ul {
7442: left: 100%;
7443: top: 0;
7444: }
7445:
7446: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7447: display: block;
7448: position: absolute;
7449: margin: 0;
7450: padding: 0;
1.1078 raeburn 7451: z-index: 2;
1.1076 raeburn 7452: }
7453:
7454: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7455: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7456: font-size: 90%;
1.911 bisitz 7457: vertical-align: top;
1.1076 raeburn 7458: float: none;
1.1079 raeburn 7459: border-left: 1px solid black;
7460: border-right: 1px solid black;
1.1205 golterma 7461: /* A dark bottom border to visualize different menu options;
7462: overwritten in the create_submenu routine for the last border-bottom of the menu */
7463: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7464: }
7465:
1.1205 golterma 7466: ol.LC_primary_menu li li p:hover {
7467: color:$button_hover;
7468: text-decoration:none;
7469: background-color:$data_table_dark;
1.1076 raeburn 7470: }
7471:
7472: ol.LC_primary_menu li li a:hover {
7473: color:$button_hover;
7474: background-color:$data_table_dark;
1.693 droeschl 7475: }
7476:
1.1205 golterma 7477: /* Font-size equal to the size of the predecessors*/
7478: ol.LC_primary_menu li:hover li li {
7479: font-size: 100%;
7480: }
7481:
1.897 wenzelju 7482: ol.LC_primary_menu li img {
1.911 bisitz 7483: vertical-align: bottom;
1.934 droeschl 7484: height: 1.1em;
1.1077 raeburn 7485: margin: 0.2em 0 0 0;
1.693 droeschl 7486: }
7487:
1.897 wenzelju 7488: ol.LC_primary_menu a {
1.911 bisitz 7489: color: RGB(80, 80, 80);
7490: text-decoration: none;
1.693 droeschl 7491: }
1.795 www 7492:
1.949 droeschl 7493: ol.LC_primary_menu a.LC_new_message {
7494: font-weight:bold;
7495: color: darkred;
7496: }
7497:
1.975 raeburn 7498: ol.LC_docs_parameters {
7499: margin-left: 0;
7500: padding: 0;
7501: list-style: none;
7502: }
7503:
7504: ol.LC_docs_parameters li {
7505: margin: 0;
7506: padding-right: 20px;
7507: display: inline;
7508: }
7509:
1.976 raeburn 7510: ol.LC_docs_parameters li:before {
7511: content: "\\002022 \\0020";
7512: }
7513:
7514: li.LC_docs_parameters_title {
7515: font-weight: bold;
7516: }
7517:
7518: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7519: content: "";
7520: }
7521:
1.897 wenzelju 7522: ul#LC_secondary_menu {
1.1107 raeburn 7523: clear: right;
1.911 bisitz 7524: color: $fontmenu;
7525: background: $tabbg;
7526: list-style: none;
7527: padding: 0;
7528: margin: 0;
7529: width: 100%;
1.995 raeburn 7530: text-align: left;
1.1107 raeburn 7531: float: left;
1.808 droeschl 7532: }
7533:
1.897 wenzelju 7534: ul#LC_secondary_menu li {
1.911 bisitz 7535: font-weight: bold;
7536: line-height: 1.8em;
1.1107 raeburn 7537: border-right: 1px solid black;
7538: float: left;
7539: }
7540:
7541: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7542: background-color: $data_table_light;
7543: }
7544:
7545: ul#LC_secondary_menu li a {
1.911 bisitz 7546: padding: 0 0.8em;
1.1107 raeburn 7547: }
7548:
7549: ul#LC_secondary_menu li ul {
7550: display: none;
7551: }
7552:
7553: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7554: display: block;
7555: position: absolute;
7556: margin: 0;
7557: padding: 0;
7558: list-style:none;
7559: float: none;
7560: background-color: $data_table_light;
7561: z-index: 2;
7562: margin-left: -1px;
7563: }
7564:
7565: ul#LC_secondary_menu li ul li {
7566: font-size: 90%;
7567: vertical-align: top;
7568: border-left: 1px solid black;
1.911 bisitz 7569: border-right: 1px solid black;
1.1119 raeburn 7570: background-color: $data_table_light;
1.1107 raeburn 7571: list-style:none;
7572: float: none;
7573: }
7574:
7575: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7576: background-color: $data_table_dark;
1.807 droeschl 7577: }
7578:
1.847 tempelho 7579: ul.LC_TabContent {
1.911 bisitz 7580: display:block;
7581: background: $sidebg;
7582: border-bottom: solid 1px $lg_border_color;
7583: list-style:none;
1.1020 raeburn 7584: margin: -1px -10px 0 -10px;
1.911 bisitz 7585: padding: 0;
1.693 droeschl 7586: }
7587:
1.795 www 7588: ul.LC_TabContent li,
7589: ul.LC_TabContentBigger li {
1.911 bisitz 7590: float:left;
1.741 harmsja 7591: }
1.795 www 7592:
1.897 wenzelju 7593: ul#LC_secondary_menu li a {
1.911 bisitz 7594: color: $fontmenu;
7595: text-decoration: none;
1.693 droeschl 7596: }
1.795 www 7597:
1.721 harmsja 7598: ul.LC_TabContent {
1.952 onken 7599: min-height:20px;
1.721 harmsja 7600: }
1.795 www 7601:
7602: ul.LC_TabContent li {
1.911 bisitz 7603: vertical-align:middle;
1.959 onken 7604: padding: 0 16px 0 10px;
1.911 bisitz 7605: background-color:$tabbg;
7606: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7607: border-left: solid 1px $font;
1.721 harmsja 7608: }
1.795 www 7609:
1.847 tempelho 7610: ul.LC_TabContent .right {
1.911 bisitz 7611: float:right;
1.847 tempelho 7612: }
7613:
1.911 bisitz 7614: ul.LC_TabContent li a,
7615: ul.LC_TabContent li {
7616: color:rgb(47,47,47);
7617: text-decoration:none;
7618: font-size:95%;
7619: font-weight:bold;
1.952 onken 7620: min-height:20px;
7621: }
7622:
1.959 onken 7623: ul.LC_TabContent li a:hover,
7624: ul.LC_TabContent li a:focus {
1.952 onken 7625: color: $button_hover;
1.959 onken 7626: background:none;
7627: outline:none;
1.952 onken 7628: }
7629:
7630: ul.LC_TabContent li:hover {
7631: color: $button_hover;
7632: cursor:pointer;
1.721 harmsja 7633: }
1.795 www 7634:
1.911 bisitz 7635: ul.LC_TabContent li.active {
1.952 onken 7636: color: $font;
1.911 bisitz 7637: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7638: border-bottom:solid 1px #FFFFFF;
7639: cursor: default;
1.744 ehlerst 7640: }
1.795 www 7641:
1.959 onken 7642: ul.LC_TabContent li.active a {
7643: color:$font;
7644: background:#FFFFFF;
7645: outline: none;
7646: }
1.1047 raeburn 7647:
7648: ul.LC_TabContent li.goback {
7649: float: left;
7650: border-left: none;
7651: }
7652:
1.870 tempelho 7653: #maincoursedoc {
1.911 bisitz 7654: clear:both;
1.870 tempelho 7655: }
7656:
7657: ul.LC_TabContentBigger {
1.911 bisitz 7658: display:block;
7659: list-style:none;
7660: padding: 0;
1.870 tempelho 7661: }
7662:
1.795 www 7663: ul.LC_TabContentBigger li {
1.911 bisitz 7664: vertical-align:bottom;
7665: height: 30px;
7666: font-size:110%;
7667: font-weight:bold;
7668: color: #737373;
1.841 tempelho 7669: }
7670:
1.957 onken 7671: ul.LC_TabContentBigger li.active {
7672: position: relative;
7673: top: 1px;
7674: }
7675:
1.870 tempelho 7676: ul.LC_TabContentBigger li a {
1.911 bisitz 7677: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7678: height: 30px;
7679: line-height: 30px;
7680: text-align: center;
7681: display: block;
7682: text-decoration: none;
1.958 onken 7683: outline: none;
1.741 harmsja 7684: }
1.795 www 7685:
1.870 tempelho 7686: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7687: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7688: color:$font;
1.744 ehlerst 7689: }
1.795 www 7690:
1.870 tempelho 7691: ul.LC_TabContentBigger li b {
1.911 bisitz 7692: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7693: display: block;
7694: float: left;
7695: padding: 0 30px;
1.957 onken 7696: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7697: }
7698:
1.956 onken 7699: ul.LC_TabContentBigger li:hover b {
7700: color:$button_hover;
7701: }
7702:
1.870 tempelho 7703: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7704: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7705: color:$font;
1.957 onken 7706: border: 0;
1.741 harmsja 7707: }
1.693 droeschl 7708:
1.870 tempelho 7709:
1.862 bisitz 7710: ul.LC_CourseBreadcrumbs {
7711: background: $sidebg;
1.1020 raeburn 7712: height: 2em;
1.862 bisitz 7713: padding-left: 10px;
1.1020 raeburn 7714: margin: 0;
1.862 bisitz 7715: list-style-position: inside;
7716: }
7717:
1.911 bisitz 7718: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7719: ol#LC_PathBreadcrumbs {
1.911 bisitz 7720: padding-left: 10px;
7721: margin: 0;
1.933 droeschl 7722: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7723: }
7724:
1.911 bisitz 7725: ol#LC_MenuBreadcrumbs li,
7726: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7727: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7728: display: inline;
1.933 droeschl 7729: white-space: normal;
1.693 droeschl 7730: }
7731:
1.823 bisitz 7732: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7733: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7734: text-decoration: none;
7735: font-size:90%;
1.693 droeschl 7736: }
1.795 www 7737:
1.969 droeschl 7738: ol#LC_MenuBreadcrumbs h1 {
7739: display: inline;
7740: font-size: 90%;
7741: line-height: 2.5em;
7742: margin: 0;
7743: padding: 0;
7744: }
7745:
1.795 www 7746: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7747: text-decoration:none;
7748: font-size:100%;
7749: font-weight:bold;
1.693 droeschl 7750: }
1.795 www 7751:
1.840 bisitz 7752: .LC_Box {
1.911 bisitz 7753: border: solid 1px $lg_border_color;
7754: padding: 0 10px 10px 10px;
1.746 neumanie 7755: }
1.795 www 7756:
1.1020 raeburn 7757: .LC_DocsBox {
7758: border: solid 1px $lg_border_color;
7759: padding: 0 0 10px 10px;
7760: }
7761:
1.795 www 7762: .LC_AboutMe_Image {
1.911 bisitz 7763: float:left;
7764: margin-right:10px;
1.747 neumanie 7765: }
1.795 www 7766:
7767: .LC_Clear_AboutMe_Image {
1.911 bisitz 7768: clear:left;
1.747 neumanie 7769: }
1.795 www 7770:
1.721 harmsja 7771: dl.LC_ListStyleClean dt {
1.911 bisitz 7772: padding-right: 5px;
7773: display: table-header-group;
1.693 droeschl 7774: }
7775:
1.721 harmsja 7776: dl.LC_ListStyleClean dd {
1.911 bisitz 7777: display: table-row;
1.693 droeschl 7778: }
7779:
1.721 harmsja 7780: .LC_ListStyleClean,
7781: .LC_ListStyleSimple,
7782: .LC_ListStyleNormal,
1.795 www 7783: .LC_ListStyleSpecial {
1.911 bisitz 7784: /* display:block; */
7785: list-style-position: inside;
7786: list-style-type: none;
7787: overflow: hidden;
7788: padding: 0;
1.693 droeschl 7789: }
7790:
1.721 harmsja 7791: .LC_ListStyleSimple li,
7792: .LC_ListStyleSimple dd,
7793: .LC_ListStyleNormal li,
7794: .LC_ListStyleNormal dd,
7795: .LC_ListStyleSpecial li,
1.795 www 7796: .LC_ListStyleSpecial dd {
1.911 bisitz 7797: margin: 0;
7798: padding: 5px 5px 5px 10px;
7799: clear: both;
1.693 droeschl 7800: }
7801:
1.721 harmsja 7802: .LC_ListStyleClean li,
7803: .LC_ListStyleClean dd {
1.911 bisitz 7804: padding-top: 0;
7805: padding-bottom: 0;
1.693 droeschl 7806: }
7807:
1.721 harmsja 7808: .LC_ListStyleSimple dd,
1.795 www 7809: .LC_ListStyleSimple li {
1.911 bisitz 7810: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7811: }
7812:
1.721 harmsja 7813: .LC_ListStyleSpecial li,
7814: .LC_ListStyleSpecial dd {
1.911 bisitz 7815: list-style-type: none;
7816: background-color: RGB(220, 220, 220);
7817: margin-bottom: 4px;
1.693 droeschl 7818: }
7819:
1.721 harmsja 7820: table.LC_SimpleTable {
1.911 bisitz 7821: margin:5px;
7822: border:solid 1px $lg_border_color;
1.795 www 7823: }
1.693 droeschl 7824:
1.721 harmsja 7825: table.LC_SimpleTable tr {
1.911 bisitz 7826: padding: 0;
7827: border:solid 1px $lg_border_color;
1.693 droeschl 7828: }
1.795 www 7829:
7830: table.LC_SimpleTable thead {
1.911 bisitz 7831: background:rgb(220,220,220);
1.693 droeschl 7832: }
7833:
1.721 harmsja 7834: div.LC_columnSection {
1.911 bisitz 7835: display: block;
7836: clear: both;
7837: overflow: hidden;
7838: margin: 0;
1.693 droeschl 7839: }
7840:
1.721 harmsja 7841: div.LC_columnSection>* {
1.911 bisitz 7842: float: left;
7843: margin: 10px 20px 10px 0;
7844: overflow:hidden;
1.693 droeschl 7845: }
1.721 harmsja 7846:
1.795 www 7847: table em {
1.911 bisitz 7848: font-weight: bold;
7849: font-style: normal;
1.748 schulted 7850: }
1.795 www 7851:
1.779 bisitz 7852: table.LC_tableBrowseRes,
1.795 www 7853: table.LC_tableOfContent {
1.911 bisitz 7854: border:none;
7855: border-spacing: 1px;
7856: padding: 3px;
7857: background-color: #FFFFFF;
7858: font-size: 90%;
1.753 droeschl 7859: }
1.789 droeschl 7860:
1.911 bisitz 7861: table.LC_tableOfContent {
7862: border-collapse: collapse;
1.789 droeschl 7863: }
7864:
1.771 droeschl 7865: table.LC_tableBrowseRes a,
1.768 schulted 7866: table.LC_tableOfContent a {
1.911 bisitz 7867: background-color: transparent;
7868: text-decoration: none;
1.753 droeschl 7869: }
7870:
1.795 www 7871: table.LC_tableOfContent img {
1.911 bisitz 7872: border: none;
7873: height: 1.3em;
7874: vertical-align: text-bottom;
7875: margin-right: 0.3em;
1.753 droeschl 7876: }
1.757 schulted 7877:
1.795 www 7878: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7879: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7880: }
7881:
1.795 www 7882: a#LC_content_toolbar_everything {
1.911 bisitz 7883: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7884: }
7885:
1.795 www 7886: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7887: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7888: }
7889:
1.795 www 7890: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7891: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7892: }
7893:
1.795 www 7894: a#LC_content_toolbar_changefolder {
1.911 bisitz 7895: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7896: }
7897:
1.795 www 7898: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7899: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7900: }
7901:
1.1043 raeburn 7902: a#LC_content_toolbar_edittoplevel {
7903: background-image:url(/res/adm/pages/edittoplevel.gif);
7904: }
7905:
1.795 www 7906: ul#LC_toolbar li a:hover {
1.911 bisitz 7907: background-position: bottom center;
1.757 schulted 7908: }
7909:
1.795 www 7910: ul#LC_toolbar {
1.911 bisitz 7911: padding: 0;
7912: margin: 2px;
7913: list-style:none;
7914: position:relative;
7915: background-color:white;
1.1082 raeburn 7916: overflow: auto;
1.757 schulted 7917: }
7918:
1.795 www 7919: ul#LC_toolbar li {
1.911 bisitz 7920: border:1px solid white;
7921: padding: 0;
7922: margin: 0;
7923: float: left;
7924: display:inline;
7925: vertical-align:middle;
1.1082 raeburn 7926: white-space: nowrap;
1.911 bisitz 7927: }
1.757 schulted 7928:
1.783 amueller 7929:
1.795 www 7930: a.LC_toolbarItem {
1.911 bisitz 7931: display:block;
7932: padding: 0;
7933: margin: 0;
7934: height: 32px;
7935: width: 32px;
7936: color:white;
7937: border: none;
7938: background-repeat:no-repeat;
7939: background-color:transparent;
1.757 schulted 7940: }
7941:
1.915 droeschl 7942: ul.LC_funclist {
7943: margin: 0;
7944: padding: 0.5em 1em 0.5em 0;
7945: }
7946:
1.933 droeschl 7947: ul.LC_funclist > li:first-child {
7948: font-weight:bold;
7949: margin-left:0.8em;
7950: }
7951:
1.915 droeschl 7952: ul.LC_funclist + ul.LC_funclist {
7953: /*
7954: left border as a seperator if we have more than
7955: one list
7956: */
7957: border-left: 1px solid $sidebg;
7958: /*
7959: this hides the left border behind the border of the
7960: outer box if element is wrapped to the next 'line'
7961: */
7962: margin-left: -1px;
7963: }
7964:
1.843 bisitz 7965: ul.LC_funclist li {
1.915 droeschl 7966: display: inline;
1.782 bisitz 7967: white-space: nowrap;
1.915 droeschl 7968: margin: 0 0 0 25px;
7969: line-height: 150%;
1.782 bisitz 7970: }
7971:
1.974 wenzelju 7972: .LC_hidden {
7973: display: none;
7974: }
7975:
1.1030 www 7976: .LCmodal-overlay {
7977: position:fixed;
7978: top:0;
7979: right:0;
7980: bottom:0;
7981: left:0;
7982: height:100%;
7983: width:100%;
7984: margin:0;
7985: padding:0;
7986: background:#999;
7987: opacity:.75;
7988: filter: alpha(opacity=75);
7989: -moz-opacity: 0.75;
7990: z-index:101;
7991: }
7992:
7993: * html .LCmodal-overlay {
7994: position: absolute;
7995: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7996: }
7997:
7998: .LCmodal-window {
7999: position:fixed;
8000: top:50%;
8001: left:50%;
8002: margin:0;
8003: padding:0;
8004: z-index:102;
8005: }
8006:
8007: * html .LCmodal-window {
8008: position:absolute;
8009: }
8010:
8011: .LCclose-window {
8012: position:absolute;
8013: width:32px;
8014: height:32px;
8015: right:8px;
8016: top:8px;
8017: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
8018: text-indent:-99999px;
8019: overflow:hidden;
8020: cursor:pointer;
8021: }
8022:
1.1100 raeburn 8023: /*
1.1231 damieng 8024: styles used for response display
8025: */
8026: div.LC_radiofoil, div.LC_rankfoil {
8027: margin: .5em 0em .5em 0em;
8028: }
8029: table.LC_itemgroup {
8030: margin-top: 1em;
8031: }
8032:
8033: /*
1.1100 raeburn 8034: styles used by TTH when "Default set of options to pass to tth/m
8035: when converting TeX" in course settings has been set
8036:
8037: option passed: -t
8038:
8039: */
8040:
8041: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
8042: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
8043: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
8044: td div.norm {line-height:normal;}
8045:
8046: /*
8047: option passed -y3
8048: */
8049:
8050: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
8051: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
8052: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
8053:
1.1230 damieng 8054: /*
8055: sections with roles, for content only
8056: */
8057: section[class^="role-"] {
8058: padding-left: 10px;
8059: padding-right: 5px;
8060: margin-top: 8px;
8061: margin-bottom: 8px;
8062: border: 1px solid #2A4;
8063: border-radius: 5px;
8064: box-shadow: 0px 1px 1px #BBB;
8065: }
8066: section[class^="role-"]>h1 {
8067: position: relative;
8068: margin: 0px;
8069: padding-top: 10px;
8070: padding-left: 40px;
8071: }
8072: section[class^="role-"]>h1:before {
8073: position: absolute;
8074: left: -5px;
8075: top: 5px;
8076: }
8077: section.role-activity>h1:before {
8078: content:url('/adm/daxe/images/section_icons/activity.png');
8079: }
8080: section.role-advice>h1:before {
8081: content:url('/adm/daxe/images/section_icons/advice.png');
8082: }
8083: section.role-bibliography>h1:before {
8084: content:url('/adm/daxe/images/section_icons/bibliography.png');
8085: }
8086: section.role-citation>h1:before {
8087: content:url('/adm/daxe/images/section_icons/citation.png');
8088: }
8089: section.role-conclusion>h1:before {
8090: content:url('/adm/daxe/images/section_icons/conclusion.png');
8091: }
8092: section.role-definition>h1:before {
8093: content:url('/adm/daxe/images/section_icons/definition.png');
8094: }
8095: section.role-demonstration>h1:before {
8096: content:url('/adm/daxe/images/section_icons/demonstration.png');
8097: }
8098: section.role-example>h1:before {
8099: content:url('/adm/daxe/images/section_icons/example.png');
8100: }
8101: section.role-explanation>h1:before {
8102: content:url('/adm/daxe/images/section_icons/explanation.png');
8103: }
8104: section.role-introduction>h1:before {
8105: content:url('/adm/daxe/images/section_icons/introduction.png');
8106: }
8107: section.role-method>h1:before {
8108: content:url('/adm/daxe/images/section_icons/method.png');
8109: }
8110: section.role-more_information>h1:before {
8111: content:url('/adm/daxe/images/section_icons/more_information.png');
8112: }
8113: section.role-objectives>h1:before {
8114: content:url('/adm/daxe/images/section_icons/objectives.png');
8115: }
8116: section.role-prerequisites>h1:before {
8117: content:url('/adm/daxe/images/section_icons/prerequisites.png');
8118: }
8119: section.role-remark>h1:before {
8120: content:url('/adm/daxe/images/section_icons/remark.png');
8121: }
8122: section.role-reminder>h1:before {
8123: content:url('/adm/daxe/images/section_icons/reminder.png');
8124: }
8125: section.role-summary>h1:before {
8126: content:url('/adm/daxe/images/section_icons/summary.png');
8127: }
8128: section.role-syntax>h1:before {
8129: content:url('/adm/daxe/images/section_icons/syntax.png');
8130: }
8131: section.role-warning>h1:before {
8132: content:url('/adm/daxe/images/section_icons/warning.png');
8133: }
8134:
1.1269 raeburn 8135: #LC_minitab_header {
8136: float:left;
8137: width:100%;
8138: background:#DAE0D2 url("/res/adm/pages/minitabmenu_bg.gif") repeat-x bottom;
8139: font-size:93%;
8140: line-height:normal;
8141: margin: 0.5em 0 0.5em 0;
8142: }
8143: #LC_minitab_header ul {
8144: margin:0;
8145: padding:10px 10px 0;
8146: list-style:none;
8147: }
8148: #LC_minitab_header li {
8149: float:left;
8150: background:url("/res/adm/pages/minitabmenu_left.gif") no-repeat left top;
8151: margin:0;
8152: padding:0 0 0 9px;
8153: }
8154: #LC_minitab_header a {
8155: display:block;
8156: background:url("/res/adm/pages/minitabmenu_right.gif") no-repeat right top;
8157: padding:5px 15px 4px 6px;
8158: }
8159: #LC_minitab_header #LC_current_minitab {
8160: background-image:url("/res/adm/pages/minitabmenu_left_on.gif");
8161: }
8162: #LC_minitab_header #LC_current_minitab a {
8163: background-image:url("/res/adm/pages/minitabmenu_right_on.gif");
8164: padding-bottom:5px;
8165: }
8166:
8167:
1.343 albertel 8168: END
8169: }
8170:
1.306 albertel 8171: =pod
8172:
8173: =item * &headtag()
8174:
8175: Returns a uniform footer for LON-CAPA web pages.
8176:
1.307 albertel 8177: Inputs: $title - optional title for the head
8178: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 8179: $args - optional arguments
1.319 albertel 8180: force_register - if is true call registerurl so the remote is
8181: informed
1.415 albertel 8182: redirect -> array ref of
8183: 1- seconds before redirect occurs
8184: 2- url to redirect to
8185: 3- whether the side effect should occur
1.315 albertel 8186: (side effect of setting
8187: $env{'internal.head.redirect'} to the url
8188: redirected too)
1.352 albertel 8189: domain -> force to color decorate a page for a specific
8190: domain
8191: function -> force usage of a specific rolish color scheme
8192: bgcolor -> override the default page bgcolor
1.460 albertel 8193: no_auto_mt_title
8194: -> prevent &mt()ing the title arg
1.464 albertel 8195:
1.306 albertel 8196: =cut
8197:
8198: sub headtag {
1.313 albertel 8199: my ($title,$head_extra,$args) = @_;
1.306 albertel 8200:
1.363 albertel 8201: my $function = $args->{'function'} || &get_users_function();
8202: my $domain = $args->{'domain'} || &determinedomain();
8203: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 8204: my $httphost = $args->{'use_absolute'};
1.418 albertel 8205: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 8206: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 8207: #time(),
1.418 albertel 8208: $env{'environment.color.timestamp'},
1.363 albertel 8209: $function,$domain,$bgcolor);
8210:
1.369 www 8211: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 8212:
1.308 albertel 8213: my $result =
8214: '<head>'.
1.1160 raeburn 8215: &font_settings($args);
1.319 albertel 8216:
1.1188 raeburn 8217: my $inhibitprint;
8218: if ($args->{'print_suppress'}) {
8219: $inhibitprint = &print_suppression();
8220: }
1.1064 raeburn 8221:
1.461 albertel 8222: if (!$args->{'frameset'}) {
8223: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
8224: }
1.962 droeschl 8225: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
8226: $result .= Apache::lonxml::display_title();
1.319 albertel 8227: }
1.436 albertel 8228: if (!$args->{'no_nav_bar'}
8229: && !$args->{'only_body'}
8230: && !$args->{'frameset'}) {
1.1154 raeburn 8231: $result .= &help_menu_js($httphost);
1.1032 www 8232: $result.=&modal_window();
1.1038 www 8233: $result.=&togglebox_script();
1.1034 www 8234: $result.=&wishlist_window();
1.1041 www 8235: $result.=&LCprogressbarUpdate_script();
1.1034 www 8236: } else {
8237: if ($args->{'add_modal'}) {
8238: $result.=&modal_window();
8239: }
8240: if ($args->{'add_wishlist'}) {
8241: $result.=&wishlist_window();
8242: }
1.1038 www 8243: if ($args->{'add_togglebox'}) {
8244: $result.=&togglebox_script();
8245: }
1.1041 www 8246: if ($args->{'add_progressbar'}) {
8247: $result.=&LCprogressbarUpdate_script();
8248: }
1.436 albertel 8249: }
1.314 albertel 8250: if (ref($args->{'redirect'})) {
1.414 albertel 8251: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 8252: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 8253: if (!$inhibit_continue) {
8254: $env{'internal.head.redirect'} = $url;
8255: }
1.313 albertel 8256: $result.=<<ADDMETA
8257: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 8258: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 8259: ADDMETA
1.1210 raeburn 8260: } else {
8261: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
8262: my $requrl = $env{'request.uri'};
8263: if ($requrl eq '') {
8264: $requrl = $ENV{'REQUEST_URI'};
8265: $requrl =~ s/\?.+$//;
8266: }
8267: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
8268: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
8269: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
8270: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
8271: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
8272: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
8273: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
8274: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
8275: if ($domdefs{'offloadnow'}{$lonhost}) {
8276: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
8277: if (($newserver) && ($newserver ne $lonhost)) {
8278: my $numsec = 5;
8279: my $timeout = $numsec * 1000;
8280: my ($newurl,$locknum,%locks,$msg);
8281: if ($env{'request.role.adv'}) {
8282: ($locknum,%locks) = &Apache::lonnet::get_locks();
8283: }
8284: my $disable_submit = 0;
8285: if ($requrl =~ /$LONCAPA::assess_re/) {
8286: $disable_submit = 1;
8287: }
8288: if ($locknum) {
8289: my @lockinfo = sort(values(%locks));
8290: $msg = &mt('Once the following tasks are complete: ')."\\n".
8291: join(", ",sort(values(%locks)))."\\n".
8292: &mt('your session will be transferred to a different server, after you click "Roles".');
8293: } else {
8294: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
8295: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
8296: }
8297: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
8298: $newurl = '/adm/switchserver?otherserver='.$newserver;
8299: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
8300: $newurl .= '&role='.$env{'request.role'};
8301: }
8302: if ($env{'request.symb'}) {
8303: $newurl .= '&symb='.$env{'request.symb'};
8304: } else {
8305: $newurl .= '&origurl='.$requrl;
8306: }
8307: }
1.1222 damieng 8308: &js_escape(\$msg);
1.1210 raeburn 8309: $result.=<<OFFLOAD
8310: <meta http-equiv="pragma" content="no-cache" />
8311: <script type="text/javascript">
1.1215 raeburn 8312: // <![CDATA[
1.1210 raeburn 8313: function LC_Offload_Now() {
8314: var dest = "$newurl";
8315: if (dest != '') {
8316: window.location.href="$newurl";
8317: }
8318: }
1.1214 raeburn 8319: \$(document).ready(function () {
8320: window.alert('$msg');
8321: if ($disable_submit) {
1.1210 raeburn 8322: \$(".LC_hwk_submit").prop("disabled", true);
8323: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 8324: }
8325: setTimeout('LC_Offload_Now()', $timeout);
8326: });
1.1215 raeburn 8327: // ]]>
1.1210 raeburn 8328: </script>
8329: OFFLOAD
8330: }
8331: }
8332: }
8333: }
8334: }
8335: }
1.313 albertel 8336: }
1.306 albertel 8337: if (!defined($title)) {
8338: $title = 'The LearningOnline Network with CAPA';
8339: }
1.460 albertel 8340: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
8341: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 8342: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
8343: if (!$args->{'frameset'}) {
8344: $result .= ' /';
8345: }
8346: $result .= '>'
1.1064 raeburn 8347: .$inhibitprint
1.414 albertel 8348: .$head_extra;
1.1242 raeburn 8349: my $clientmobile;
8350: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
8351: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
8352: } else {
8353: $clientmobile = $env{'browser.mobile'};
8354: }
8355: if ($clientmobile) {
1.1137 raeburn 8356: $result .= '
8357: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
8358: <meta name="apple-mobile-web-app-capable" content="yes" />';
8359: }
1.962 droeschl 8360: return $result.'</head>';
1.306 albertel 8361: }
8362:
8363: =pod
8364:
1.340 albertel 8365: =item * &font_settings()
8366:
8367: Returns neccessary <meta> to set the proper encoding
8368:
1.1160 raeburn 8369: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 8370:
8371: =cut
8372:
8373: sub font_settings {
1.1160 raeburn 8374: my ($args) = @_;
1.340 albertel 8375: my $headerstring='';
1.1160 raeburn 8376: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
8377: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 8378: $headerstring.=
8379: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8380: if (!$args->{'frameset'}) {
8381: $headerstring.= ' /';
8382: }
8383: $headerstring .= '>'."\n";
1.340 albertel 8384: }
8385: return $headerstring;
8386: }
8387:
1.341 albertel 8388: =pod
8389:
1.1064 raeburn 8390: =item * &print_suppression()
8391:
8392: In course context returns css which causes the body to be blank when media="print",
8393: if printout generation is unavailable for the current resource.
8394:
8395: This could be because:
8396:
8397: (a) printstartdate is in the future
8398:
8399: (b) printenddate is in the past
8400:
8401: (c) there is an active exam block with "printout"
8402: functionality blocked
8403:
8404: Users with pav, pfo or evb privileges are exempt.
8405:
8406: Inputs: none
8407:
8408: =cut
8409:
8410:
8411: sub print_suppression {
8412: my $noprint;
8413: if ($env{'request.course.id'}) {
8414: my $scope = $env{'request.course.id'};
8415: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8416: (&Apache::lonnet::allowed('pfo',$scope))) {
8417: return;
8418: }
8419: if ($env{'request.course.sec'} ne '') {
8420: $scope .= "/$env{'request.course.sec'}";
8421: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8422: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8423: return;
1.1064 raeburn 8424: }
8425: }
8426: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8427: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8428: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8429: if ($blocked) {
8430: my $checkrole = "cm./$cdom/$cnum";
8431: if ($env{'request.course.sec'} ne '') {
8432: $checkrole .= "/$env{'request.course.sec'}";
8433: }
8434: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8435: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8436: $noprint = 1;
8437: }
8438: }
8439: unless ($noprint) {
8440: my $symb = &Apache::lonnet::symbread();
8441: if ($symb ne '') {
8442: my $navmap = Apache::lonnavmaps::navmap->new();
8443: if (ref($navmap)) {
8444: my $res = $navmap->getBySymb($symb);
8445: if (ref($res)) {
8446: if (!$res->resprintable()) {
8447: $noprint = 1;
8448: }
8449: }
8450: }
8451: }
8452: }
8453: if ($noprint) {
8454: return <<"ENDSTYLE";
8455: <style type="text/css" media="print">
8456: body { display:none }
8457: </style>
8458: ENDSTYLE
8459: }
8460: }
8461: return;
8462: }
8463:
8464: =pod
8465:
1.341 albertel 8466: =item * &xml_begin()
8467:
8468: Returns the needed doctype and <html>
8469:
8470: Inputs: none
8471:
8472: =cut
8473:
8474: sub xml_begin {
1.1168 raeburn 8475: my ($is_frameset) = @_;
1.341 albertel 8476: my $output='';
8477:
8478: if ($env{'browser.mathml'}) {
8479: $output='<?xml version="1.0"?>'
8480: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8481: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8482:
8483: # .'<!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">] >'
8484: .'<!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">'
8485: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8486: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8487: } elsif ($is_frameset) {
8488: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8489: '<html>'."\n";
1.341 albertel 8490: } else {
1.1168 raeburn 8491: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8492: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8493: }
8494: return $output;
8495: }
1.340 albertel 8496:
8497: =pod
8498:
1.306 albertel 8499: =item * &start_page()
8500:
8501: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8502:
1.648 raeburn 8503: Inputs:
8504:
8505: =over 4
8506:
8507: $title - optional title for the page
8508:
8509: $head_extra - optional extra HTML to incude inside the <head>
8510:
8511: $args - additional optional args supported are:
8512:
8513: =over 8
8514:
8515: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8516: arg on
1.814 bisitz 8517: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8518: add_entries -> additional attributes to add to the <body>
8519: domain -> force to color decorate a page for a
1.317 albertel 8520: specific domain
1.648 raeburn 8521: function -> force usage of a specific rolish color
1.317 albertel 8522: scheme
1.648 raeburn 8523: redirect -> see &headtag()
8524: bgcolor -> override the default page bg color
8525: js_ready -> return a string ready for being used in
1.317 albertel 8526: a javascript writeln
1.648 raeburn 8527: html_encode -> return a string ready for being used in
1.320 albertel 8528: a html attribute
1.648 raeburn 8529: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8530: $forcereg arg
1.648 raeburn 8531: frameset -> if true will start with a <frameset>
1.330 albertel 8532: rather than <body>
1.648 raeburn 8533: skip_phases -> hash ref of
1.338 albertel 8534: head -> skip the <html><head> generation
8535: body -> skip all <body> generation
1.648 raeburn 8536: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8537: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8538: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1272 raeburn 8539: bread_crumbs_nomenu -> if true will pass false as the value of $menulink
8540: to lonhtmlcommon::breadcrumbs
1.1096 raeburn 8541: group -> includes the current group, if page is for a
1.1274 ! raeburn 8542: specific group
! 8543: use_absolute -> for request for external resource or syllabus, this
! 8544: will contain https://<hostname> if server uses
! 8545: https (as per hosts.tab), but request is for http
! 8546: hostname -> hostname, originally from $r->hostname(), (optional).
1.361 albertel 8547:
1.648 raeburn 8548: =back
1.460 albertel 8549:
1.648 raeburn 8550: =back
1.562 albertel 8551:
1.306 albertel 8552: =cut
8553:
8554: sub start_page {
1.309 albertel 8555: my ($title,$head_extra,$args) = @_;
1.318 albertel 8556: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8557:
1.315 albertel 8558: $env{'internal.start_page'}++;
1.1096 raeburn 8559: my ($result,@advtools);
1.964 droeschl 8560:
1.338 albertel 8561: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8562: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8563: }
8564:
8565: if (! exists($args->{'skip_phases'}{'body'}) ) {
8566: if ($args->{'frameset'}) {
8567: my $attr_string = &make_attr_string($args->{'force_register'},
8568: $args->{'add_entries'});
8569: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8570: } else {
8571: $result .=
8572: &bodytag($title,
8573: $args->{'function'}, $args->{'add_entries'},
8574: $args->{'only_body'}, $args->{'domain'},
8575: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8576: $args->{'bgcolor'}, $args,
8577: \@advtools);
1.831 bisitz 8578: }
1.330 albertel 8579: }
1.338 albertel 8580:
1.315 albertel 8581: if ($args->{'js_ready'}) {
1.713 kaisler 8582: $result = &js_ready($result);
1.315 albertel 8583: }
1.320 albertel 8584: if ($args->{'html_encode'}) {
1.713 kaisler 8585: $result = &html_encode($result);
8586: }
8587:
1.813 bisitz 8588: # Preparation for new and consistent functionlist at top of screen
8589: # if ($args->{'functionlist'}) {
8590: # $result .= &build_functionlist();
8591: #}
8592:
1.964 droeschl 8593: # Don't add anything more if only_body wanted or in const space
8594: return $result if $args->{'only_body'}
8595: || $env{'request.state'} eq 'construct';
1.813 bisitz 8596:
8597: #Breadcrumbs
1.758 kaisler 8598: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8599: &Apache::lonhtmlcommon::clear_breadcrumbs();
8600: #if any br links exists, add them to the breadcrumbs
8601: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8602: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8603: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8604: }
8605: }
1.1096 raeburn 8606: # if @advtools array contains items add then to the breadcrumbs
8607: if (@advtools > 0) {
8608: &Apache::lonmenu::advtools_crumbs(@advtools);
8609: }
1.1272 raeburn 8610: my $menulink;
8611: # if arg: bread_crumbs_nomenu is true pass 0 as $menulink item.
8612: if ((exists($args->{'bread_crumbs_nomenu'})) ||
8613: ((($args->{'crstype'} eq 'Placement') || (($env{'request.course.id'}) &&
8614: ($env{'course.'.$env{'request.course.id'}.'.type'} eq 'Placement'))) &&
8615: (!$env{'request.role.adv'}))) {
8616: $menulink = 0;
8617: } else {
8618: undef($menulink);
8619: }
1.758 kaisler 8620: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8621: if(exists($args->{'bread_crumbs_component'})){
1.1272 raeburn 8622: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'},'',$menulink);
1.1237 raeburn 8623: } else {
1.1272 raeburn 8624: $result .= &Apache::lonhtmlcommon::breadcrumbs('','',$menulink);
1.758 kaisler 8625: }
1.320 albertel 8626: }
1.315 albertel 8627: return $result;
1.306 albertel 8628: }
8629:
8630: sub end_page {
1.315 albertel 8631: my ($args) = @_;
8632: $env{'internal.end_page'}++;
1.330 albertel 8633: my $result;
1.335 albertel 8634: if ($args->{'discussion'}) {
8635: my ($target,$parser);
8636: if (ref($args->{'discussion'})) {
8637: ($target,$parser) =($args->{'discussion'}{'target'},
8638: $args->{'discussion'}{'parser'});
8639: }
8640: $result .= &Apache::lonxml::xmlend($target,$parser);
8641: }
1.330 albertel 8642: if ($args->{'frameset'}) {
8643: $result .= '</frameset>';
8644: } else {
1.635 raeburn 8645: $result .= &endbodytag($args);
1.330 albertel 8646: }
1.1080 raeburn 8647: unless ($args->{'notbody'}) {
8648: $result .= "\n</html>";
8649: }
1.330 albertel 8650:
1.315 albertel 8651: if ($args->{'js_ready'}) {
1.317 albertel 8652: $result = &js_ready($result);
1.315 albertel 8653: }
1.335 albertel 8654:
1.320 albertel 8655: if ($args->{'html_encode'}) {
8656: $result = &html_encode($result);
8657: }
1.335 albertel 8658:
1.315 albertel 8659: return $result;
8660: }
8661:
1.1034 www 8662: sub wishlist_window {
8663: return(<<'ENDWISHLIST');
1.1046 raeburn 8664: <script type="text/javascript">
1.1034 www 8665: // <![CDATA[
8666: // <!-- BEGIN LON-CAPA Internal
8667: function set_wishlistlink(title, path) {
8668: if (!title) {
8669: title = document.title;
8670: title = title.replace(/^LON-CAPA /,'');
8671: }
1.1175 raeburn 8672: title = encodeURIComponent(title);
1.1203 raeburn 8673: title = title.replace("'","\\\'");
1.1034 www 8674: if (!path) {
8675: path = location.pathname;
8676: }
1.1175 raeburn 8677: path = encodeURIComponent(path);
1.1203 raeburn 8678: path = path.replace("'","\\\'");
1.1034 www 8679: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8680: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8681: }
8682: // END LON-CAPA Internal -->
8683: // ]]>
8684: </script>
8685: ENDWISHLIST
8686: }
8687:
1.1030 www 8688: sub modal_window {
8689: return(<<'ENDMODAL');
1.1046 raeburn 8690: <script type="text/javascript">
1.1030 www 8691: // <![CDATA[
8692: // <!-- BEGIN LON-CAPA Internal
8693: var modalWindow = {
8694: parent:"body",
8695: windowId:null,
8696: content:null,
8697: width:null,
8698: height:null,
8699: close:function()
8700: {
8701: $(".LCmodal-window").remove();
8702: $(".LCmodal-overlay").remove();
8703: },
8704: open:function()
8705: {
8706: var modal = "";
8707: modal += "<div class=\"LCmodal-overlay\"></div>";
8708: 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;\">";
8709: modal += this.content;
8710: modal += "</div>";
8711:
8712: $(this.parent).append(modal);
8713:
8714: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8715: $(".LCclose-window").click(function(){modalWindow.close();});
8716: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8717: }
8718: };
1.1140 raeburn 8719: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8720: {
1.1266 raeburn 8721: source = source.replace(/'/g,"'");
1.1030 www 8722: modalWindow.windowId = "myModal";
8723: modalWindow.width = width;
8724: modalWindow.height = height;
1.1196 raeburn 8725: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8726: modalWindow.open();
1.1208 raeburn 8727: };
1.1030 www 8728: // END LON-CAPA Internal -->
8729: // ]]>
8730: </script>
8731: ENDMODAL
8732: }
8733:
8734: sub modal_link {
1.1140 raeburn 8735: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8736: unless ($width) { $width=480; }
8737: unless ($height) { $height=400; }
1.1031 www 8738: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 8739: unless ($transparency) { $transparency='true'; }
8740:
1.1074 raeburn 8741: my $target_attr;
8742: if (defined($target)) {
8743: $target_attr = 'target="'.$target.'"';
8744: }
8745: return <<"ENDLINK";
1.1140 raeburn 8746: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8747: $linktext</a>
8748: ENDLINK
1.1030 www 8749: }
8750:
1.1032 www 8751: sub modal_adhoc_script {
8752: my ($funcname,$width,$height,$content)=@_;
8753: return (<<ENDADHOC);
1.1046 raeburn 8754: <script type="text/javascript">
1.1032 www 8755: // <![CDATA[
8756: var $funcname = function()
8757: {
8758: modalWindow.windowId = "myModal";
8759: modalWindow.width = $width;
8760: modalWindow.height = $height;
8761: modalWindow.content = '$content';
8762: modalWindow.open();
8763: };
8764: // ]]>
8765: </script>
8766: ENDADHOC
8767: }
8768:
1.1041 www 8769: sub modal_adhoc_inner {
8770: my ($funcname,$width,$height,$content)=@_;
8771: my $innerwidth=$width-20;
8772: $content=&js_ready(
1.1140 raeburn 8773: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
8774: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8775: $content.
1.1041 www 8776: &end_scrollbox().
1.1140 raeburn 8777: &end_page()
1.1041 www 8778: );
8779: return &modal_adhoc_script($funcname,$width,$height,$content);
8780: }
8781:
8782: sub modal_adhoc_window {
8783: my ($funcname,$width,$height,$content,$linktext)=@_;
8784: return &modal_adhoc_inner($funcname,$width,$height,$content).
8785: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8786: }
8787:
8788: sub modal_adhoc_launch {
8789: my ($funcname,$width,$height,$content)=@_;
8790: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8791: <script type="text/javascript">
8792: // <![CDATA[
8793: $funcname();
8794: // ]]>
8795: </script>
8796: ENDLAUNCH
8797: }
8798:
8799: sub modal_adhoc_close {
8800: return (<<ENDCLOSE);
8801: <script type="text/javascript">
8802: // <![CDATA[
8803: modalWindow.close();
8804: // ]]>
8805: </script>
8806: ENDCLOSE
8807: }
8808:
1.1038 www 8809: sub togglebox_script {
8810: return(<<ENDTOGGLE);
8811: <script type="text/javascript">
8812: // <![CDATA[
8813: function LCtoggleDisplay(id,hidetext,showtext) {
8814: link = document.getElementById(id + "link").childNodes[0];
8815: with (document.getElementById(id).style) {
8816: if (display == "none" ) {
8817: display = "inline";
8818: link.nodeValue = hidetext;
8819: } else {
8820: display = "none";
8821: link.nodeValue = showtext;
8822: }
8823: }
8824: }
8825: // ]]>
8826: </script>
8827: ENDTOGGLE
8828: }
8829:
1.1039 www 8830: sub start_togglebox {
8831: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8832: unless ($heading) { $heading=''; } else { $heading.=' '; }
8833: unless ($showtext) { $showtext=&mt('show'); }
8834: unless ($hidetext) { $hidetext=&mt('hide'); }
8835: unless ($headerbg) { $headerbg='#FFFFFF'; }
8836: return &start_data_table().
8837: &start_data_table_header_row().
8838: '<td bgcolor="'.$headerbg.'">'.$heading.
8839: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8840: $showtext.'\')">'.$showtext.'</a>]</td>'.
8841: &end_data_table_header_row().
8842: '<tr id="'.$id.'" style="display:none""><td>';
8843: }
8844:
8845: sub end_togglebox {
8846: return '</td></tr>'.&end_data_table();
8847: }
8848:
1.1041 www 8849: sub LCprogressbar_script {
1.1045 www 8850: my ($id)=@_;
1.1041 www 8851: return(<<ENDPROGRESS);
8852: <script type="text/javascript">
8853: // <![CDATA[
1.1045 www 8854: \$('#progressbar$id').progressbar({
1.1041 www 8855: value: 0,
8856: change: function(event, ui) {
8857: var newVal = \$(this).progressbar('option', 'value');
8858: \$('.pblabel', this).text(LCprogressTxt);
8859: }
8860: });
8861: // ]]>
8862: </script>
8863: ENDPROGRESS
8864: }
8865:
8866: sub LCprogressbarUpdate_script {
8867: return(<<ENDPROGRESSUPDATE);
8868: <style type="text/css">
8869: .ui-progressbar { position:relative; }
8870: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8871: </style>
8872: <script type="text/javascript">
8873: // <![CDATA[
1.1045 www 8874: var LCprogressTxt='---';
8875:
8876: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8877: LCprogressTxt=progresstext;
1.1045 www 8878: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8879: }
8880: // ]]>
8881: </script>
8882: ENDPROGRESSUPDATE
8883: }
8884:
1.1042 www 8885: my $LClastpercent;
1.1045 www 8886: my $LCidcnt;
8887: my $LCcurrentid;
1.1042 www 8888:
1.1041 www 8889: sub LCprogressbar {
1.1042 www 8890: my ($r)=(@_);
8891: $LClastpercent=0;
1.1045 www 8892: $LCidcnt++;
8893: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8894: my $starting=&mt('Starting');
8895: my $content=(<<ENDPROGBAR);
1.1045 www 8896: <div id="progressbar$LCcurrentid">
1.1041 www 8897: <span class="pblabel">$starting</span>
8898: </div>
8899: ENDPROGBAR
1.1045 www 8900: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8901: }
8902:
8903: sub LCprogressbarUpdate {
1.1042 www 8904: my ($r,$val,$text)=@_;
8905: unless ($val) {
8906: if ($LClastpercent) {
8907: $val=$LClastpercent;
8908: } else {
8909: $val=0;
8910: }
8911: }
1.1041 www 8912: if ($val<0) { $val=0; }
8913: if ($val>100) { $val=0; }
1.1042 www 8914: $LClastpercent=$val;
1.1041 www 8915: unless ($text) { $text=$val.'%'; }
8916: $text=&js_ready($text);
1.1044 www 8917: &r_print($r,<<ENDUPDATE);
1.1041 www 8918: <script type="text/javascript">
8919: // <![CDATA[
1.1045 www 8920: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8921: // ]]>
8922: </script>
8923: ENDUPDATE
1.1035 www 8924: }
8925:
1.1042 www 8926: sub LCprogressbarClose {
8927: my ($r)=@_;
8928: $LClastpercent=0;
1.1044 www 8929: &r_print($r,<<ENDCLOSE);
1.1042 www 8930: <script type="text/javascript">
8931: // <![CDATA[
1.1045 www 8932: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8933: // ]]>
8934: </script>
8935: ENDCLOSE
1.1044 www 8936: }
8937:
8938: sub r_print {
8939: my ($r,$to_print)=@_;
8940: if ($r) {
8941: $r->print($to_print);
8942: $r->rflush();
8943: } else {
8944: print($to_print);
8945: }
1.1042 www 8946: }
8947:
1.320 albertel 8948: sub html_encode {
8949: my ($result) = @_;
8950:
1.322 albertel 8951: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8952:
8953: return $result;
8954: }
1.1044 www 8955:
1.317 albertel 8956: sub js_ready {
8957: my ($result) = @_;
8958:
1.323 albertel 8959: $result =~ s/[\n\r]/ /xmsg;
8960: $result =~ s/\\/\\\\/xmsg;
8961: $result =~ s/'/\\'/xmsg;
1.372 albertel 8962: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8963:
8964: return $result;
8965: }
8966:
1.315 albertel 8967: sub validate_page {
8968: if ( exists($env{'internal.start_page'})
1.316 albertel 8969: && $env{'internal.start_page'} > 1) {
8970: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8971: $env{'internal.start_page'}.' '.
1.316 albertel 8972: $ENV{'request.filename'});
1.315 albertel 8973: }
8974: if ( exists($env{'internal.end_page'})
1.316 albertel 8975: && $env{'internal.end_page'} > 1) {
8976: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8977: $env{'internal.end_page'}.' '.
1.316 albertel 8978: $env{'request.filename'});
1.315 albertel 8979: }
8980: if ( exists($env{'internal.start_page'})
8981: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8982: &Apache::lonnet::logthis('start_page called without end_page '.
8983: $env{'request.filename'});
1.315 albertel 8984: }
8985: if ( ! exists($env{'internal.start_page'})
8986: && exists($env{'internal.end_page'})) {
1.316 albertel 8987: &Apache::lonnet::logthis('end_page called without start_page'.
8988: $env{'request.filename'});
1.315 albertel 8989: }
1.306 albertel 8990: }
1.315 albertel 8991:
1.996 www 8992:
8993: sub start_scrollbox {
1.1140 raeburn 8994: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8995: unless ($outerwidth) { $outerwidth='520px'; }
8996: unless ($width) { $width='500px'; }
8997: unless ($height) { $height='200px'; }
1.1075 raeburn 8998: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8999: if ($id ne '') {
1.1140 raeburn 9000: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 9001: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 9002: }
1.1075 raeburn 9003: if ($bgcolor ne '') {
9004: $tdcol = "background-color: $bgcolor;";
9005: }
1.1137 raeburn 9006: my $nicescroll_js;
9007: if ($env{'browser.mobile'}) {
1.1140 raeburn 9008: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
9009: }
9010: return <<"END";
9011: $nicescroll_js
9012:
9013: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
9014: <div style="overflow:auto; width:$width; height:$height;"$div_id>
9015: END
9016: }
9017:
9018: sub end_scrollbox {
9019: return '</div></td></tr></table>';
9020: }
9021:
9022: sub nicescroll_javascript {
9023: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
9024: my %options;
9025: if (ref($cursor) eq 'HASH') {
9026: %options = %{$cursor};
9027: }
9028: unless ($options{'railalign'} =~ /^left|right$/) {
9029: $options{'railalign'} = 'left';
9030: }
9031: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
9032: my $function = &get_users_function();
9033: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 9034: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 9035: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 9036: }
1.1140 raeburn 9037: }
9038: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
9039: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 9040: $options{'cursoropacity'}='1.0';
9041: }
1.1140 raeburn 9042: } else {
9043: $options{'cursoropacity'}='1.0';
9044: }
9045: if ($options{'cursorfixedheight'} eq 'none') {
9046: delete($options{'cursorfixedheight'});
9047: } else {
9048: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
9049: }
9050: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
9051: delete($options{'railoffset'});
9052: }
9053: my @niceoptions;
9054: while (my($key,$value) = each(%options)) {
9055: if ($value =~ /^\{.+\}$/) {
9056: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 9057: } else {
1.1140 raeburn 9058: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 9059: }
1.1140 raeburn 9060: }
9061: my $nicescroll_js = '
1.1137 raeburn 9062: $(document).ready(
1.1140 raeburn 9063: function() {
9064: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
9065: }
1.1137 raeburn 9066: );
9067: ';
1.1140 raeburn 9068: if ($framecheck) {
9069: $nicescroll_js .= '
9070: function expand_div(caller) {
9071: if (top === self) {
9072: document.getElementById("'.$id.'").style.width = "auto";
9073: document.getElementById("'.$id.'").style.height = "auto";
9074: } else {
9075: try {
9076: if (parent.frames) {
9077: if (parent.frames.length > 1) {
9078: var framesrc = parent.frames[1].location.href;
9079: var currsrc = framesrc.replace(/\#.*$/,"");
9080: if ((caller == "search") || (currsrc == "'.$location.'")) {
9081: document.getElementById("'.$id.'").style.width = "auto";
9082: document.getElementById("'.$id.'").style.height = "auto";
9083: }
9084: }
9085: }
9086: } catch (e) {
9087: return;
9088: }
1.1137 raeburn 9089: }
1.1140 raeburn 9090: return;
1.996 www 9091: }
1.1140 raeburn 9092: ';
9093: }
9094: if ($needjsready) {
9095: $nicescroll_js = '
9096: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
9097: } else {
9098: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
9099: }
9100: return $nicescroll_js;
1.996 www 9101: }
9102:
1.318 albertel 9103: sub simple_error_page {
1.1150 bisitz 9104: my ($r,$title,$msg,$args) = @_;
1.1151 raeburn 9105: if (ref($args) eq 'HASH') {
9106: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
9107: } else {
9108: $msg = &mt($msg);
9109: }
1.1150 bisitz 9110:
1.318 albertel 9111: my $page =
9112: &Apache::loncommon::start_page($title).
1.1150 bisitz 9113: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 9114: &Apache::loncommon::end_page();
9115: if (ref($r)) {
9116: $r->print($page);
1.327 albertel 9117: return;
1.318 albertel 9118: }
9119: return $page;
9120: }
1.347 albertel 9121:
9122: {
1.610 albertel 9123: my @row_count;
1.961 onken 9124:
9125: sub start_data_table_count {
9126: unshift(@row_count, 0);
9127: return;
9128: }
9129:
9130: sub end_data_table_count {
9131: shift(@row_count);
9132: return;
9133: }
9134:
1.347 albertel 9135: sub start_data_table {
1.1018 raeburn 9136: my ($add_class,$id) = @_;
1.422 albertel 9137: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 9138: my $table_id;
9139: if (defined($id)) {
9140: $table_id = ' id="'.$id.'"';
9141: }
1.961 onken 9142: &start_data_table_count();
1.1018 raeburn 9143: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 9144: }
9145:
9146: sub end_data_table {
1.961 onken 9147: &end_data_table_count();
1.389 albertel 9148: return '</table>'."\n";;
1.347 albertel 9149: }
9150:
9151: sub start_data_table_row {
1.974 wenzelju 9152: my ($add_class, $id) = @_;
1.610 albertel 9153: $row_count[0]++;
9154: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 9155: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 9156: $id = (' id="'.$id.'"') unless ($id eq '');
9157: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 9158: }
1.471 banghart 9159:
9160: sub continue_data_table_row {
1.974 wenzelju 9161: my ($add_class, $id) = @_;
1.610 albertel 9162: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 9163: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
9164: $id = (' id="'.$id.'"') unless ($id eq '');
9165: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 9166: }
1.347 albertel 9167:
9168: sub end_data_table_row {
1.389 albertel 9169: return '</tr>'."\n";;
1.347 albertel 9170: }
1.367 www 9171:
1.421 albertel 9172: sub start_data_table_empty_row {
1.707 bisitz 9173: # $row_count[0]++;
1.421 albertel 9174: return '<tr class="LC_empty_row" >'."\n";;
9175: }
9176:
9177: sub end_data_table_empty_row {
9178: return '</tr>'."\n";;
9179: }
9180:
1.367 www 9181: sub start_data_table_header_row {
1.389 albertel 9182: return '<tr class="LC_header_row">'."\n";;
1.367 www 9183: }
9184:
9185: sub end_data_table_header_row {
1.389 albertel 9186: return '</tr>'."\n";;
1.367 www 9187: }
1.890 droeschl 9188:
9189: sub data_table_caption {
9190: my $caption = shift;
9191: return "<caption class=\"LC_caption\">$caption</caption>";
9192: }
1.347 albertel 9193: }
9194:
1.548 albertel 9195: =pod
9196:
9197: =item * &inhibit_menu_check($arg)
9198:
9199: Checks for a inhibitmenu state and generates output to preserve it
9200:
9201: Inputs: $arg - can be any of
9202: - undef - in which case the return value is a string
9203: to add into arguments list of a uri
9204: - 'input' - in which case the return value is a HTML
9205: <form> <input> field of type hidden to
9206: preserve the value
9207: - a url - in which case the return value is the url with
9208: the neccesary cgi args added to preserve the
9209: inhibitmenu state
9210: - a ref to a url - no return value, but the string is
9211: updated to include the neccessary cgi
9212: args to preserve the inhibitmenu state
9213:
9214: =cut
9215:
9216: sub inhibit_menu_check {
9217: my ($arg) = @_;
9218: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
9219: if ($arg eq 'input') {
9220: if ($env{'form.inhibitmenu'}) {
9221: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
9222: } else {
9223: return
9224: }
9225: }
9226: if ($env{'form.inhibitmenu'}) {
9227: if (ref($arg)) {
9228: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9229: } elsif ($arg eq '') {
9230: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
9231: } else {
9232: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
9233: }
9234: }
9235: if (!ref($arg)) {
9236: return $arg;
9237: }
9238: }
9239:
1.251 albertel 9240: ###############################################
1.182 matthew 9241:
9242: =pod
9243:
1.549 albertel 9244: =back
9245:
9246: =head1 User Information Routines
9247:
9248: =over 4
9249:
1.405 albertel 9250: =item * &get_users_function()
1.182 matthew 9251:
9252: Used by &bodytag to determine the current users primary role.
9253: Returns either 'student','coordinator','admin', or 'author'.
9254:
9255: =cut
9256:
9257: ###############################################
9258: sub get_users_function {
1.815 tempelho 9259: my $function = 'norole';
1.818 tempelho 9260: if ($env{'request.role'}=~/^(st)/) {
9261: $function='student';
9262: }
1.907 raeburn 9263: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 9264: $function='coordinator';
9265: }
1.258 albertel 9266: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 9267: $function='admin';
9268: }
1.826 bisitz 9269: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 9270: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 9271: $function='author';
9272: }
9273: return $function;
1.54 www 9274: }
1.99 www 9275:
9276: ###############################################
9277:
1.233 raeburn 9278: =pod
9279:
1.821 raeburn 9280: =item * &show_course()
9281:
9282: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
9283: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
9284:
9285: Inputs:
9286: None
9287:
9288: Outputs:
9289: Scalar: 1 if 'Course' to be used, 0 otherwise.
9290:
9291: =cut
9292:
9293: ###############################################
9294: sub show_course {
9295: my $course = !$env{'user.adv'};
9296: if (!$env{'user.adv'}) {
9297: foreach my $env (keys(%env)) {
9298: next if ($env !~ m/^user\.priv\./);
9299: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
9300: $course = 0;
9301: last;
9302: }
9303: }
9304: }
9305: return $course;
9306: }
9307:
9308: ###############################################
9309:
9310: =pod
9311:
1.542 raeburn 9312: =item * &check_user_status()
1.274 raeburn 9313:
9314: Determines current status of supplied role for a
9315: specific user. Roles can be active, previous or future.
9316:
9317: Inputs:
9318: user's domain, user's username, course's domain,
1.375 raeburn 9319: course's number, optional section ID.
1.274 raeburn 9320:
9321: Outputs:
9322: role status: active, previous or future.
9323:
9324: =cut
9325:
9326: sub check_user_status {
1.412 raeburn 9327: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 9328: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 9329: my @uroles = keys(%userinfo);
1.274 raeburn 9330: my $srchstr;
9331: my $active_chk = 'none';
1.412 raeburn 9332: my $now = time;
1.274 raeburn 9333: if (@uroles > 0) {
1.908 raeburn 9334: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 9335: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
9336: } else {
1.412 raeburn 9337: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
9338: }
9339: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 9340: my $role_end = 0;
9341: my $role_start = 0;
9342: $active_chk = 'active';
1.412 raeburn 9343: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
9344: $role_end = $1;
9345: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
9346: $role_start = $1;
1.274 raeburn 9347: }
9348: }
9349: if ($role_start > 0) {
1.412 raeburn 9350: if ($now < $role_start) {
1.274 raeburn 9351: $active_chk = 'future';
9352: }
9353: }
9354: if ($role_end > 0) {
1.412 raeburn 9355: if ($now > $role_end) {
1.274 raeburn 9356: $active_chk = 'previous';
9357: }
9358: }
9359: }
9360: }
9361: return $active_chk;
9362: }
9363:
9364: ###############################################
9365:
9366: =pod
9367:
1.405 albertel 9368: =item * &get_sections()
1.233 raeburn 9369:
9370: Determines all the sections for a course including
9371: sections with students and sections containing other roles.
1.419 raeburn 9372: Incoming parameters:
9373:
9374: 1. domain
9375: 2. course number
9376: 3. reference to array containing roles for which sections should
9377: be gathered (optional).
9378: 4. reference to array containing status types for which sections
9379: should be gathered (optional).
9380:
9381: If the third argument is undefined, sections are gathered for any role.
9382: If the fourth argument is undefined, sections are gathered for any status.
9383: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 9384:
1.374 raeburn 9385: Returns section hash (keys are section IDs, values are
9386: number of users in each section), subject to the
1.419 raeburn 9387: optional roles filter, optional status filter
1.233 raeburn 9388:
9389: =cut
9390:
9391: ###############################################
9392: sub get_sections {
1.419 raeburn 9393: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9394: if (!defined($cdom) || !defined($cnum)) {
9395: my $cid = $env{'request.course.id'};
9396:
9397: return if (!defined($cid));
9398:
9399: $cdom = $env{'course.'.$cid.'.domain'};
9400: $cnum = $env{'course.'.$cid.'.num'};
9401: }
9402:
9403: my %sectioncount;
1.419 raeburn 9404: my $now = time;
1.240 albertel 9405:
1.1118 raeburn 9406: my $check_students = 1;
9407: my $only_students = 0;
9408: if (ref($possible_roles) eq 'ARRAY') {
9409: if (grep(/^st$/,@{$possible_roles})) {
9410: if (@{$possible_roles} == 1) {
9411: $only_students = 1;
9412: }
9413: } else {
9414: $check_students = 0;
9415: }
9416: }
9417:
9418: if ($check_students) {
1.276 albertel 9419: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9420: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9421: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9422: my $start_index = &Apache::loncoursedata::CL_START();
9423: my $end_index = &Apache::loncoursedata::CL_END();
9424: my $status;
1.366 albertel 9425: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9426: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9427: $data->[$status_index],
9428: $data->[$start_index],
9429: $data->[$end_index]);
9430: if ($stu_status eq 'Active') {
9431: $status = 'active';
9432: } elsif ($end < $now) {
9433: $status = 'previous';
9434: } elsif ($start > $now) {
9435: $status = 'future';
9436: }
9437: if ($section ne '-1' && $section !~ /^\s*$/) {
9438: if ((!defined($possible_status)) || (($status ne '') &&
9439: (grep/^\Q$status\E$/,@{$possible_status}))) {
9440: $sectioncount{$section}++;
9441: }
1.240 albertel 9442: }
9443: }
9444: }
1.1118 raeburn 9445: if ($only_students) {
9446: return %sectioncount;
9447: }
1.240 albertel 9448: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9449: foreach my $user (sort(keys(%courseroles))) {
9450: if ($user !~ /^(\w{2})/) { next; }
9451: my ($role) = ($user =~ /^(\w{2})/);
9452: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9453: my ($section,$status);
1.240 albertel 9454: if ($role eq 'cr' &&
9455: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9456: $section=$1;
9457: }
9458: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9459: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9460: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9461: if ($end == -1 && $start == -1) {
9462: next; #deleted role
9463: }
9464: if (!defined($possible_status)) {
9465: $sectioncount{$section}++;
9466: } else {
9467: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9468: $status = 'active';
9469: } elsif ($end < $now) {
9470: $status = 'future';
9471: } elsif ($start > $now) {
9472: $status = 'previous';
9473: }
9474: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9475: $sectioncount{$section}++;
9476: }
9477: }
1.233 raeburn 9478: }
1.366 albertel 9479: return %sectioncount;
1.233 raeburn 9480: }
9481:
1.274 raeburn 9482: ###############################################
1.294 raeburn 9483:
9484: =pod
1.405 albertel 9485:
9486: =item * &get_course_users()
9487:
1.275 raeburn 9488: Retrieves usernames:domains for users in the specified course
9489: with specific role(s), and access status.
9490:
9491: Incoming parameters:
1.277 albertel 9492: 1. course domain
9493: 2. course number
9494: 3. access status: users must have - either active,
1.275 raeburn 9495: previous, future, or all.
1.277 albertel 9496: 4. reference to array of permissible roles
1.288 raeburn 9497: 5. reference to array of section restrictions (optional)
9498: 6. reference to results object (hash of hashes).
9499: 7. reference to optional userdata hash
1.609 raeburn 9500: 8. reference to optional statushash
1.630 raeburn 9501: 9. flag if privileged users (except those set to unhide in
9502: course settings) should be excluded
1.609 raeburn 9503: Keys of top level results hash are roles.
1.275 raeburn 9504: Keys of inner hashes are username:domain, with
9505: values set to access type.
1.288 raeburn 9506: Optional userdata hash returns an array with arguments in the
9507: same order as loncoursedata::get_classlist() for student data.
9508:
1.609 raeburn 9509: Optional statushash returns
9510:
1.288 raeburn 9511: Entries for end, start, section and status are blank because
9512: of the possibility of multiple values for non-student roles.
9513:
1.275 raeburn 9514: =cut
1.405 albertel 9515:
1.275 raeburn 9516: ###############################################
1.405 albertel 9517:
1.275 raeburn 9518: sub get_course_users {
1.630 raeburn 9519: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9520: my %idx = ();
1.419 raeburn 9521: my %seclists;
1.288 raeburn 9522:
9523: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9524: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9525: $idx{end} = &Apache::loncoursedata::CL_END();
9526: $idx{start} = &Apache::loncoursedata::CL_START();
9527: $idx{id} = &Apache::loncoursedata::CL_ID();
9528: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9529: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9530: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9531:
1.290 albertel 9532: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9533: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9534: my $now = time;
1.277 albertel 9535: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9536: my $match = 0;
1.412 raeburn 9537: my $secmatch = 0;
1.419 raeburn 9538: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9539: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9540: if ($section eq '') {
9541: $section = 'none';
9542: }
1.291 albertel 9543: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9544: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9545: $secmatch = 1;
9546: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9547: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9548: $secmatch = 1;
9549: }
9550: } else {
1.419 raeburn 9551: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9552: $secmatch = 1;
9553: }
1.290 albertel 9554: }
1.412 raeburn 9555: if (!$secmatch) {
9556: next;
9557: }
1.419 raeburn 9558: }
1.275 raeburn 9559: if (defined($$types{'active'})) {
1.288 raeburn 9560: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9561: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9562: $match = 1;
1.275 raeburn 9563: }
9564: }
9565: if (defined($$types{'previous'})) {
1.609 raeburn 9566: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9567: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9568: $match = 1;
1.275 raeburn 9569: }
9570: }
9571: if (defined($$types{'future'})) {
1.609 raeburn 9572: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9573: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9574: $match = 1;
1.275 raeburn 9575: }
9576: }
1.609 raeburn 9577: if ($match) {
9578: push(@{$seclists{$student}},$section);
9579: if (ref($userdata) eq 'HASH') {
9580: $$userdata{$student} = $$classlist{$student};
9581: }
9582: if (ref($statushash) eq 'HASH') {
9583: $statushash->{$student}{'st'}{$section} = $status;
9584: }
1.288 raeburn 9585: }
1.275 raeburn 9586: }
9587: }
1.412 raeburn 9588: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9589: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9590: my $now = time;
1.609 raeburn 9591: my %displaystatus = ( previous => 'Expired',
9592: active => 'Active',
9593: future => 'Future',
9594: );
1.1121 raeburn 9595: my (%nothide,@possdoms);
1.630 raeburn 9596: if ($hidepriv) {
9597: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9598: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9599: if ($user !~ /:/) {
9600: $nothide{join(':',split(/[\@]/,$user))}=1;
9601: } else {
9602: $nothide{$user} = 1;
9603: }
9604: }
1.1121 raeburn 9605: my @possdoms = ($cdom);
9606: if ($coursehash{'checkforpriv'}) {
9607: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9608: }
1.630 raeburn 9609: }
1.439 raeburn 9610: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9611: my $match = 0;
1.412 raeburn 9612: my $secmatch = 0;
1.439 raeburn 9613: my $status;
1.412 raeburn 9614: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9615: $user =~ s/:$//;
1.439 raeburn 9616: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9617: if ($end == -1 || $start == -1) {
9618: next;
9619: }
9620: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9621: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9622: my ($uname,$udom) = split(/:/,$user);
9623: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9624: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9625: $secmatch = 1;
9626: } elsif ($usec eq '') {
1.420 albertel 9627: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9628: $secmatch = 1;
9629: }
9630: } else {
9631: if (grep(/^\Q$usec\E$/,@{$sections})) {
9632: $secmatch = 1;
9633: }
9634: }
9635: if (!$secmatch) {
9636: next;
9637: }
1.288 raeburn 9638: }
1.419 raeburn 9639: if ($usec eq '') {
9640: $usec = 'none';
9641: }
1.275 raeburn 9642: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9643: if ($hidepriv) {
1.1121 raeburn 9644: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9645: (!$nothide{$uname.':'.$udom})) {
9646: next;
9647: }
9648: }
1.503 raeburn 9649: if ($end > 0 && $end < $now) {
1.439 raeburn 9650: $status = 'previous';
9651: } elsif ($start > $now) {
9652: $status = 'future';
9653: } else {
9654: $status = 'active';
9655: }
1.277 albertel 9656: foreach my $type (keys(%{$types})) {
1.275 raeburn 9657: if ($status eq $type) {
1.420 albertel 9658: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9659: push(@{$$users{$role}{$user}},$type);
9660: }
1.288 raeburn 9661: $match = 1;
9662: }
9663: }
1.419 raeburn 9664: if (($match) && (ref($userdata) eq 'HASH')) {
9665: if (!exists($$userdata{$uname.':'.$udom})) {
9666: &get_user_info($udom,$uname,\%idx,$userdata);
9667: }
1.420 albertel 9668: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9669: push(@{$seclists{$uname.':'.$udom}},$usec);
9670: }
1.609 raeburn 9671: if (ref($statushash) eq 'HASH') {
9672: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9673: }
1.275 raeburn 9674: }
9675: }
9676: }
9677: }
1.290 albertel 9678: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9679: if ((defined($cdom)) && (defined($cnum))) {
9680: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9681: if ( defined($csettings{'internal.courseowner'}) ) {
9682: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9683: next if ($owner eq '');
9684: my ($ownername,$ownerdom);
9685: if ($owner =~ /^([^:]+):([^:]+)$/) {
9686: $ownername = $1;
9687: $ownerdom = $2;
9688: } else {
9689: $ownername = $owner;
9690: $ownerdom = $cdom;
9691: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9692: }
9693: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9694: if (defined($userdata) &&
1.609 raeburn 9695: !exists($$userdata{$owner})) {
9696: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9697: if (!grep(/^none$/,@{$seclists{$owner}})) {
9698: push(@{$seclists{$owner}},'none');
9699: }
9700: if (ref($statushash) eq 'HASH') {
9701: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9702: }
1.290 albertel 9703: }
1.279 raeburn 9704: }
9705: }
9706: }
1.419 raeburn 9707: foreach my $user (keys(%seclists)) {
9708: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9709: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9710: }
1.275 raeburn 9711: }
9712: return;
9713: }
9714:
1.288 raeburn 9715: sub get_user_info {
9716: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9717: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9718: &plainname($uname,$udom,'lastname');
1.291 albertel 9719: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9720: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9721: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9722: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9723: return;
9724: }
1.275 raeburn 9725:
1.472 raeburn 9726: ###############################################
9727:
9728: =pod
9729:
9730: =item * &get_user_quota()
9731:
1.1134 raeburn 9732: Retrieves quota assigned for storage of user files.
9733: Default is to report quota for portfolio files.
1.472 raeburn 9734:
9735: Incoming parameters:
9736: 1. user's username
9737: 2. user's domain
1.1134 raeburn 9738: 3. quota name - portfolio, author, or course
1.1136 raeburn 9739: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 9740: 4. crstype - official, unofficial, textbook, placement or community,
9741: if quota name is course
1.472 raeburn 9742:
9743: Returns:
1.1163 raeburn 9744: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9745: 2. (Optional) Type of setting: custom or default
9746: (individually assigned or default for user's
9747: institutional status).
9748: 3. (Optional) - User's institutional status (e.g., faculty, staff
9749: or student - types as defined in localenroll::inst_usertypes
9750: for user's domain, which determines default quota for user.
9751: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9752:
9753: If a value has been stored in the user's environment,
1.536 raeburn 9754: it will return that, otherwise it returns the maximal default
1.1134 raeburn 9755: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9756:
9757: =cut
9758:
9759: ###############################################
9760:
9761:
9762: sub get_user_quota {
1.1136 raeburn 9763: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9764: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9765: if (!defined($udom)) {
9766: $udom = $env{'user.domain'};
9767: }
9768: if (!defined($uname)) {
9769: $uname = $env{'user.name'};
9770: }
9771: if (($udom eq '' || $uname eq '') ||
9772: ($udom eq 'public') && ($uname eq 'public')) {
9773: $quota = 0;
1.536 raeburn 9774: $quotatype = 'default';
9775: $defquota = 0;
1.472 raeburn 9776: } else {
1.536 raeburn 9777: my $inststatus;
1.1134 raeburn 9778: if ($quotaname eq 'course') {
9779: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9780: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9781: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9782: } else {
9783: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9784: $quota = $cenv{'internal.uploadquota'};
9785: }
1.536 raeburn 9786: } else {
1.1134 raeburn 9787: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9788: if ($quotaname eq 'author') {
9789: $quota = $env{'environment.authorquota'};
9790: } else {
9791: $quota = $env{'environment.portfolioquota'};
9792: }
9793: $inststatus = $env{'environment.inststatus'};
9794: } else {
9795: my %userenv =
9796: &Apache::lonnet::get('environment',['portfolioquota',
9797: 'authorquota','inststatus'],$udom,$uname);
9798: my ($tmp) = keys(%userenv);
9799: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9800: if ($quotaname eq 'author') {
9801: $quota = $userenv{'authorquota'};
9802: } else {
9803: $quota = $userenv{'portfolioquota'};
9804: }
9805: $inststatus = $userenv{'inststatus'};
9806: } else {
9807: undef(%userenv);
9808: }
9809: }
9810: }
9811: if ($quota eq '' || wantarray) {
9812: if ($quotaname eq 'course') {
9813: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 9814: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 9815: ($crstype eq 'community') || ($crstype eq 'textbook') ||
9816: ($crstype eq 'placement')) {
1.1136 raeburn 9817: $defquota = $domdefs{$crstype.'quota'};
9818: }
9819: if ($defquota eq '') {
9820: $defquota = 500;
9821: }
1.1134 raeburn 9822: } else {
9823: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9824: }
9825: if ($quota eq '') {
9826: $quota = $defquota;
9827: $quotatype = 'default';
9828: } else {
9829: $quotatype = 'custom';
9830: }
1.472 raeburn 9831: }
9832: }
1.536 raeburn 9833: if (wantarray) {
9834: return ($quota,$quotatype,$settingstatus,$defquota);
9835: } else {
9836: return $quota;
9837: }
1.472 raeburn 9838: }
9839:
9840: ###############################################
9841:
9842: =pod
9843:
9844: =item * &default_quota()
9845:
1.536 raeburn 9846: Retrieves default quota assigned for storage of user portfolio files,
9847: given an (optional) user's institutional status.
1.472 raeburn 9848:
9849: Incoming parameters:
1.1142 raeburn 9850:
1.472 raeburn 9851: 1. domain
1.536 raeburn 9852: 2. (Optional) institutional status(es). This is a : separated list of
9853: status types (e.g., faculty, staff, student etc.)
9854: which apply to the user for whom the default is being retrieved.
9855: If the institutional status string in undefined, the domain
1.1134 raeburn 9856: default quota will be returned.
9857: 3. quota name - portfolio, author, or course
9858: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9859:
9860: Returns:
1.1142 raeburn 9861:
1.1163 raeburn 9862: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9863: 2. (Optional) institutional type which determined the value of the
9864: default quota.
1.472 raeburn 9865:
9866: If a value has been stored in the domain's configuration db,
9867: it will return that, otherwise it returns 20 (for backwards
9868: compatibility with domains which have not set up a configuration
1.1163 raeburn 9869: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9870:
1.536 raeburn 9871: If the user's status includes multiple types (e.g., staff and student),
9872: the largest default quota which applies to the user determines the
9873: default quota returned.
9874:
1.472 raeburn 9875: =cut
9876:
9877: ###############################################
9878:
9879:
9880: sub default_quota {
1.1134 raeburn 9881: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9882: my ($defquota,$settingstatus);
9883: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9884: ['quotas'],$udom);
1.1134 raeburn 9885: my $key = 'defaultquota';
9886: if ($quotaname eq 'author') {
9887: $key = 'authorquota';
9888: }
1.622 raeburn 9889: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9890: if ($inststatus ne '') {
1.765 raeburn 9891: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9892: foreach my $item (@statuses) {
1.1134 raeburn 9893: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9894: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9895: if ($defquota eq '') {
1.1134 raeburn 9896: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9897: $settingstatus = $item;
1.1134 raeburn 9898: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9899: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9900: $settingstatus = $item;
9901: }
9902: }
1.1134 raeburn 9903: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9904: if ($quotahash{'quotas'}{$item} ne '') {
9905: if ($defquota eq '') {
9906: $defquota = $quotahash{'quotas'}{$item};
9907: $settingstatus = $item;
9908: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9909: $defquota = $quotahash{'quotas'}{$item};
9910: $settingstatus = $item;
9911: }
1.536 raeburn 9912: }
9913: }
9914: }
9915: }
9916: if ($defquota eq '') {
1.1134 raeburn 9917: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9918: $defquota = $quotahash{'quotas'}{$key}{'default'};
9919: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9920: $defquota = $quotahash{'quotas'}{'default'};
9921: }
1.536 raeburn 9922: $settingstatus = 'default';
1.1139 raeburn 9923: if ($defquota eq '') {
9924: if ($quotaname eq 'author') {
9925: $defquota = 500;
9926: }
9927: }
1.536 raeburn 9928: }
9929: } else {
9930: $settingstatus = 'default';
1.1134 raeburn 9931: if ($quotaname eq 'author') {
9932: $defquota = 500;
9933: } else {
9934: $defquota = 20;
9935: }
1.536 raeburn 9936: }
9937: if (wantarray) {
9938: return ($defquota,$settingstatus);
1.472 raeburn 9939: } else {
1.536 raeburn 9940: return $defquota;
1.472 raeburn 9941: }
9942: }
9943:
1.1135 raeburn 9944: ###############################################
9945:
9946: =pod
9947:
1.1136 raeburn 9948: =item * &excess_filesize_warning()
1.1135 raeburn 9949:
9950: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 9951: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 9952: space to be exceeded.
1.1136 raeburn 9953:
9954: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 9955: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 9956:
1.1165 raeburn 9957: Inputs: 7
1.1136 raeburn 9958: 1. username or coursenum
1.1135 raeburn 9959: 2. domain
1.1136 raeburn 9960: 3. context ('author' or 'course')
1.1135 raeburn 9961: 4. filename of file for which action is being requested
9962: 5. filesize (kB) of file
9963: 6. action being taken: copy or upload.
1.1237 raeburn 9964: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 9965:
9966: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 9967: otherwise return null.
9968:
9969: =back
1.1135 raeburn 9970:
9971: =cut
9972:
1.1136 raeburn 9973: sub excess_filesize_warning {
1.1165 raeburn 9974: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 9975: my $current_disk_usage = 0;
1.1165 raeburn 9976: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 9977: if ($context eq 'author') {
9978: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9979: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9980: } else {
9981: foreach my $subdir ('docs','supplemental') {
9982: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9983: }
9984: }
1.1135 raeburn 9985: $disk_quota = int($disk_quota * 1000);
9986: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 9987: return '<p class="LC_warning">'.
1.1135 raeburn 9988: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 9989: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9990: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 9991: $disk_quota,$current_disk_usage).
9992: '</p>';
9993: }
9994: return;
9995: }
9996:
9997: ###############################################
9998:
9999:
1.1136 raeburn 10000:
10001:
1.384 raeburn 10002: sub get_secgrprole_info {
10003: my ($cdom,$cnum,$needroles,$type) = @_;
10004: my %sections_count = &get_sections($cdom,$cnum);
10005: my @sections = (sort {$a <=> $b} keys(%sections_count));
10006: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
10007: my @groups = sort(keys(%curr_groups));
10008: my $allroles = [];
10009: my $rolehash;
10010: my $accesshash = {
10011: active => 'Currently has access',
10012: future => 'Will have future access',
10013: previous => 'Previously had access',
10014: };
10015: if ($needroles) {
10016: $rolehash = {'all' => 'all'};
1.385 albertel 10017: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
10018: if (&Apache::lonnet::error(%user_roles)) {
10019: undef(%user_roles);
10020: }
10021: foreach my $item (keys(%user_roles)) {
1.384 raeburn 10022: my ($role)=split(/\:/,$item,2);
10023: if ($role eq 'cr') { next; }
10024: if ($role =~ /^cr/) {
10025: $$rolehash{$role} = (split('/',$role))[3];
10026: } else {
10027: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
10028: }
10029: }
10030: foreach my $key (sort(keys(%{$rolehash}))) {
10031: push(@{$allroles},$key);
10032: }
10033: push (@{$allroles},'st');
10034: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
10035: }
10036: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
10037: }
10038:
1.555 raeburn 10039: sub user_picker {
1.1255 raeburn 10040: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context,$fixeddom) = @_;
1.555 raeburn 10041: my $currdom = $dom;
1.1253 raeburn 10042: my @alldoms = &Apache::lonnet::all_domains();
10043: if (@alldoms == 1) {
10044: my %domsrch = &Apache::lonnet::get_dom('configuration',
10045: ['directorysrch'],$alldoms[0]);
10046: my $domdesc = &Apache::lonnet::domain($alldoms[0],'description');
10047: my $showdom = $domdesc;
10048: if ($showdom eq '') {
10049: $showdom = $dom;
10050: }
10051: if (ref($domsrch{'directorysrch'}) eq 'HASH') {
10052: if ((!$domsrch{'directorysrch'}{'available'}) &&
10053: ($domsrch{'directorysrch'}{'lcavailable'} eq '0')) {
10054: return (&mt('LON-CAPA directory search is not available in domain: [_1]',$showdom),0);
10055: }
10056: }
10057: }
1.555 raeburn 10058: my %curr_selected = (
10059: srchin => 'dom',
1.580 raeburn 10060: srchby => 'lastname',
1.555 raeburn 10061: );
10062: my $srchterm;
1.625 raeburn 10063: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 10064: if ($srch->{'srchby'} ne '') {
10065: $curr_selected{'srchby'} = $srch->{'srchby'};
10066: }
10067: if ($srch->{'srchin'} ne '') {
10068: $curr_selected{'srchin'} = $srch->{'srchin'};
10069: }
10070: if ($srch->{'srchtype'} ne '') {
10071: $curr_selected{'srchtype'} = $srch->{'srchtype'};
10072: }
10073: if ($srch->{'srchdomain'} ne '') {
10074: $currdom = $srch->{'srchdomain'};
10075: }
10076: $srchterm = $srch->{'srchterm'};
10077: }
1.1222 damieng 10078: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 10079: 'usr' => 'Search criteria',
1.563 raeburn 10080: 'doma' => 'Domain/institution to search',
1.558 albertel 10081: 'uname' => 'username',
10082: 'lastname' => 'last name',
1.555 raeburn 10083: 'lastfirst' => 'last name, first name',
1.558 albertel 10084: 'crs' => 'in this course',
1.576 raeburn 10085: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 10086: 'alc' => 'all LON-CAPA',
1.573 raeburn 10087: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 10088: 'exact' => 'is',
10089: 'contains' => 'contains',
1.569 raeburn 10090: 'begins' => 'begins with',
1.1222 damieng 10091: );
10092: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 10093: 'youm' => "You must include some text to search for.",
10094: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
10095: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
10096: 'yomc' => "You must choose a domain when using an institutional directory search.",
10097: 'ymcd' => "You must choose a domain when using a domain search.",
10098: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
10099: 'whse' => "When searching by last,first you must include at least one character in the first name.",
10100: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 10101: );
1.1222 damieng 10102: &html_escape(\%html_lt);
10103: &js_escape(\%js_lt);
1.1255 raeburn 10104: my $domform;
10105: if ($fixeddom) {
10106: $domform = &select_dom_form($currdom,'srchdomain',1,1,undef,[$currdom]);
10107: } else {
10108: $domform = &select_dom_form($currdom,'srchdomain',1,1);
10109: }
1.563 raeburn 10110: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 10111:
10112: my @srchins = ('crs','dom','alc','instd');
10113:
10114: foreach my $option (@srchins) {
10115: # FIXME 'alc' option unavailable until
10116: # loncreateuser::print_user_query_page()
10117: # has been completed.
10118: next if ($option eq 'alc');
1.880 raeburn 10119: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 10120: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 10121: if ($curr_selected{'srchin'} eq $option) {
10122: $srchinsel .= '
1.1222 damieng 10123: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 10124: } else {
10125: $srchinsel .= '
1.1222 damieng 10126: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 10127: }
1.555 raeburn 10128: }
1.563 raeburn 10129: $srchinsel .= "\n </select>\n";
1.555 raeburn 10130:
10131: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 10132: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 10133: if ($curr_selected{'srchby'} eq $option) {
10134: $srchbysel .= '
1.1222 damieng 10135: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10136: } else {
10137: $srchbysel .= '
1.1222 damieng 10138: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10139: }
10140: }
10141: $srchbysel .= "\n </select>\n";
10142:
10143: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 10144: foreach my $option ('begins','contains','exact') {
1.555 raeburn 10145: if ($curr_selected{'srchtype'} eq $option) {
10146: $srchtypesel .= '
1.1222 damieng 10147: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 10148: } else {
10149: $srchtypesel .= '
1.1222 damieng 10150: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 10151: }
10152: }
10153: $srchtypesel .= "\n </select>\n";
10154:
1.558 albertel 10155: my ($newuserscript,$new_user_create);
1.994 raeburn 10156: my $context_dom = $env{'request.role.domain'};
10157: if ($context eq 'requestcrs') {
10158: if ($env{'form.coursedom'} ne '') {
10159: $context_dom = $env{'form.coursedom'};
10160: }
10161: }
1.556 raeburn 10162: if ($forcenewuser) {
1.576 raeburn 10163: if (ref($srch) eq 'HASH') {
1.994 raeburn 10164: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 10165: if ($cancreate) {
10166: $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>';
10167: } else {
1.799 bisitz 10168: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 10169: my %usertypetext = (
10170: official => 'institutional',
10171: unofficial => 'non-institutional',
10172: );
1.799 bisitz 10173: $new_user_create = '<p class="LC_warning">'
10174: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
10175: .' '
10176: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
10177: ,'<a href="'.$helplink.'">','</a>')
10178: .'</p><br />';
1.627 raeburn 10179: }
1.576 raeburn 10180: }
10181: }
10182:
1.556 raeburn 10183: $newuserscript = <<"ENDSCRIPT";
10184:
1.570 raeburn 10185: function setSearch(createnew,callingForm) {
1.556 raeburn 10186: if (createnew == 1) {
1.570 raeburn 10187: for (var i=0; i<callingForm.srchby.length; i++) {
10188: if (callingForm.srchby.options[i].value == 'uname') {
10189: callingForm.srchby.selectedIndex = i;
1.556 raeburn 10190: }
10191: }
1.570 raeburn 10192: for (var i=0; i<callingForm.srchin.length; i++) {
10193: if ( callingForm.srchin.options[i].value == 'dom') {
10194: callingForm.srchin.selectedIndex = i;
1.556 raeburn 10195: }
10196: }
1.570 raeburn 10197: for (var i=0; i<callingForm.srchtype.length; i++) {
10198: if (callingForm.srchtype.options[i].value == 'exact') {
10199: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 10200: }
10201: }
1.570 raeburn 10202: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 10203: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 10204: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 10205: }
10206: }
10207: }
10208: }
10209: ENDSCRIPT
1.558 albertel 10210:
1.556 raeburn 10211: }
10212:
1.555 raeburn 10213: my $output = <<"END_BLOCK";
1.556 raeburn 10214: <script type="text/javascript">
1.824 bisitz 10215: // <![CDATA[
1.570 raeburn 10216: function validateEntry(callingForm) {
1.558 albertel 10217:
1.556 raeburn 10218: var checkok = 1;
1.558 albertel 10219: var srchin;
1.570 raeburn 10220: for (var i=0; i<callingForm.srchin.length; i++) {
10221: if ( callingForm.srchin[i].checked ) {
10222: srchin = callingForm.srchin[i].value;
1.558 albertel 10223: }
10224: }
10225:
1.570 raeburn 10226: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
10227: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
10228: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
10229: var srchterm = callingForm.srchterm.value;
10230: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 10231: var msg = "";
10232:
10233: if (srchterm == "") {
10234: checkok = 0;
1.1222 damieng 10235: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 10236: }
10237:
1.569 raeburn 10238: if (srchtype== 'begins') {
10239: if (srchterm.length < 2) {
10240: checkok = 0;
1.1222 damieng 10241: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 10242: }
10243: }
10244:
1.556 raeburn 10245: if (srchtype== 'contains') {
10246: if (srchterm.length < 3) {
10247: checkok = 0;
1.1222 damieng 10248: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 10249: }
10250: }
10251: if (srchin == 'instd') {
10252: if (srchdomain == '') {
10253: checkok = 0;
1.1222 damieng 10254: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 10255: }
10256: }
10257: if (srchin == 'dom') {
10258: if (srchdomain == '') {
10259: checkok = 0;
1.1222 damieng 10260: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 10261: }
10262: }
10263: if (srchby == 'lastfirst') {
10264: if (srchterm.indexOf(",") == -1) {
10265: checkok = 0;
1.1222 damieng 10266: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 10267: }
10268: if (srchterm.indexOf(",") == srchterm.length -1) {
10269: checkok = 0;
1.1222 damieng 10270: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 10271: }
10272: }
10273: if (checkok == 0) {
1.1222 damieng 10274: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 10275: return;
10276: }
10277: if (checkok == 1) {
1.570 raeburn 10278: callingForm.submit();
1.556 raeburn 10279: }
10280: }
10281:
10282: $newuserscript
10283:
1.824 bisitz 10284: // ]]>
1.556 raeburn 10285: </script>
1.558 albertel 10286:
10287: $new_user_create
10288:
1.555 raeburn 10289: END_BLOCK
1.558 albertel 10290:
1.876 raeburn 10291: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 10292: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 10293: $domform.
10294: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 10295: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 10296: $srchbysel.
10297: $srchtypesel.
10298: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
10299: $srchinsel.
10300: &Apache::lonhtmlcommon::row_closure(1).
10301: &Apache::lonhtmlcommon::end_pick_box().
10302: '<br />';
1.1253 raeburn 10303: return ($output,1);
1.555 raeburn 10304: }
10305:
1.612 raeburn 10306: sub user_rule_check {
1.615 raeburn 10307: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 10308: my ($response,%inst_response);
1.612 raeburn 10309: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 10310: if (keys(%{$usershash}) > 1) {
10311: my (%by_username,%by_id,%userdoms);
10312: my $checkid;
10313: if (ref($checks) eq 'HASH') {
10314: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
10315: $checkid = 1;
10316: }
10317: }
10318: foreach my $user (keys(%{$usershash})) {
10319: my ($uname,$udom) = split(/:/,$user);
10320: if ($checkid) {
10321: if (ref($usershash->{$user}) eq 'HASH') {
10322: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 10323: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 10324: $userdoms{$udom} = 1;
1.1227 raeburn 10325: if (ref($inst_results) eq 'HASH') {
10326: $inst_results->{$uname.':'.$udom} = {};
10327: }
1.1226 raeburn 10328: }
10329: }
10330: } else {
10331: $by_username{$udom}{$uname} = 1;
10332: $userdoms{$udom} = 1;
1.1227 raeburn 10333: if (ref($inst_results) eq 'HASH') {
10334: $inst_results->{$uname.':'.$udom} = {};
10335: }
1.1226 raeburn 10336: }
10337: }
10338: foreach my $udom (keys(%userdoms)) {
10339: if (!$got_rules->{$udom}) {
10340: my %domconfig = &Apache::lonnet::get_dom('configuration',
10341: ['usercreation'],$udom);
10342: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10343: foreach my $item ('username','id') {
10344: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 10345: $$curr_rules{$udom}{$item} =
10346: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 10347: }
10348: }
10349: }
10350: $got_rules->{$udom} = 1;
10351: }
1.612 raeburn 10352: }
1.1226 raeburn 10353: if ($checkid) {
10354: foreach my $udom (keys(%by_id)) {
10355: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
10356: if ($outcome eq 'ok') {
1.1227 raeburn 10357: foreach my $id (keys(%{$by_id{$udom}})) {
10358: my $uname = $by_id{$udom}{$id};
10359: $inst_response{$uname.':'.$udom} = $outcome;
10360: }
1.1226 raeburn 10361: if (ref($results) eq 'HASH') {
10362: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 10363: if (exists($inst_response{$uname.':'.$udom})) {
10364: $inst_response{$uname.':'.$udom} = $outcome;
10365: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10366: }
1.1226 raeburn 10367: }
10368: }
10369: }
1.612 raeburn 10370: }
1.615 raeburn 10371: } else {
1.1226 raeburn 10372: foreach my $udom (keys(%by_username)) {
10373: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
10374: if ($outcome eq 'ok') {
1.1227 raeburn 10375: foreach my $uname (keys(%{$by_username{$udom}})) {
10376: $inst_response{$uname.':'.$udom} = $outcome;
10377: }
1.1226 raeburn 10378: if (ref($results) eq 'HASH') {
10379: foreach my $uname (keys(%{$results})) {
10380: $inst_results->{$uname.':'.$udom} = $results->{$uname};
10381: }
10382: }
10383: }
10384: }
1.612 raeburn 10385: }
1.1226 raeburn 10386: } elsif (keys(%{$usershash}) == 1) {
10387: my $user = (keys(%{$usershash}))[0];
10388: my ($uname,$udom) = split(/:/,$user);
10389: if (($udom ne '') && ($uname ne '')) {
10390: if (ref($usershash->{$user}) eq 'HASH') {
10391: if (ref($checks) eq 'HASH') {
10392: if (defined($checks->{'username'})) {
10393: ($inst_response{$user},%{$inst_results->{$user}}) =
10394: &Apache::lonnet::get_instuser($udom,$uname);
10395: } elsif (defined($checks->{'id'})) {
10396: if ($usershash->{$user}->{'id'} ne '') {
10397: ($inst_response{$user},%{$inst_results->{$user}}) =
10398: &Apache::lonnet::get_instuser($udom,undef,
10399: $usershash->{$user}->{'id'});
10400: } else {
10401: ($inst_response{$user},%{$inst_results->{$user}}) =
10402: &Apache::lonnet::get_instuser($udom,$uname);
10403: }
1.585 raeburn 10404: }
1.1226 raeburn 10405: } else {
10406: ($inst_response{$user},%{$inst_results->{$user}}) =
10407: &Apache::lonnet::get_instuser($udom,$uname);
10408: return;
10409: }
10410: if (!$got_rules->{$udom}) {
10411: my %domconfig = &Apache::lonnet::get_dom('configuration',
10412: ['usercreation'],$udom);
10413: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10414: foreach my $item ('username','id') {
10415: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10416: $$curr_rules{$udom}{$item} =
10417: $domconfig{'usercreation'}{$item.'_rule'};
10418: }
10419: }
10420: }
10421: $got_rules->{$udom} = 1;
1.585 raeburn 10422: }
10423: }
1.1226 raeburn 10424: } else {
10425: return;
10426: }
10427: } else {
10428: return;
10429: }
10430: foreach my $user (keys(%{$usershash})) {
10431: my ($uname,$udom) = split(/:/,$user);
10432: next if (($udom eq '') || ($uname eq ''));
10433: my $id;
1.1227 raeburn 10434: if (ref($inst_results) eq 'HASH') {
10435: if (ref($inst_results->{$user}) eq 'HASH') {
10436: $id = $inst_results->{$user}->{'id'};
10437: }
10438: }
10439: if ($id eq '') {
10440: if (ref($usershash->{$user})) {
10441: $id = $usershash->{$user}->{'id'};
10442: }
1.585 raeburn 10443: }
1.612 raeburn 10444: foreach my $item (keys(%{$checks})) {
10445: if (ref($$curr_rules{$udom}) eq 'HASH') {
10446: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10447: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10448: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10449: $$curr_rules{$udom}{$item});
1.612 raeburn 10450: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10451: if ($rule_check{$rule}) {
10452: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10453: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10454: if (ref($inst_results) eq 'HASH') {
10455: if (ref($inst_results->{$user}) eq 'HASH') {
10456: if (keys(%{$inst_results->{$user}}) == 0) {
10457: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10458: } elsif ($item eq 'id') {
10459: if ($inst_results->{$user}->{'id'} eq '') {
10460: $$alerts{$item}{$udom}{$uname} = 1;
10461: }
1.615 raeburn 10462: }
1.612 raeburn 10463: }
10464: }
1.615 raeburn 10465: }
10466: last;
1.585 raeburn 10467: }
10468: }
10469: }
10470: }
10471: }
10472: }
10473: }
10474: }
1.612 raeburn 10475: return;
10476: }
10477:
10478: sub user_rule_formats {
10479: my ($domain,$domdesc,$curr_rules,$check) = @_;
10480: my %text = (
10481: 'username' => 'Usernames',
10482: 'id' => 'IDs',
10483: );
10484: my $output;
10485: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10486: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10487: if (@{$ruleorder} > 0) {
1.1102 raeburn 10488: $output = '<br />'.
10489: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10490: '<span class="LC_cusr_emph">','</span>',$domdesc).
10491: ' <ul>';
1.612 raeburn 10492: foreach my $rule (@{$ruleorder}) {
10493: if (ref($curr_rules) eq 'ARRAY') {
10494: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10495: if (ref($rules->{$rule}) eq 'HASH') {
10496: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10497: $rules->{$rule}{'desc'}.'</li>';
10498: }
10499: }
10500: }
10501: }
10502: $output .= '</ul>';
10503: }
10504: }
10505: return $output;
10506: }
10507:
10508: sub instrule_disallow_msg {
1.615 raeburn 10509: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10510: my $response;
10511: my %text = (
10512: item => 'username',
10513: items => 'usernames',
10514: match => 'matches',
10515: do => 'does',
10516: action => 'a username',
10517: one => 'one',
10518: );
10519: if ($count > 1) {
10520: $text{'item'} = 'usernames';
10521: $text{'match'} ='match';
10522: $text{'do'} = 'do';
10523: $text{'action'} = 'usernames',
10524: $text{'one'} = 'ones';
10525: }
10526: if ($checkitem eq 'id') {
10527: $text{'items'} = 'IDs';
10528: $text{'item'} = 'ID';
10529: $text{'action'} = 'an ID';
1.615 raeburn 10530: if ($count > 1) {
10531: $text{'item'} = 'IDs';
10532: $text{'action'} = 'IDs';
10533: }
1.612 raeburn 10534: }
1.674 bisitz 10535: $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 10536: if ($mode eq 'upload') {
10537: if ($checkitem eq 'username') {
10538: $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'}.");
10539: } elsif ($checkitem eq 'id') {
1.674 bisitz 10540: $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 10541: }
1.669 raeburn 10542: } elsif ($mode eq 'selfcreate') {
10543: if ($checkitem eq 'id') {
10544: $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.");
10545: }
1.615 raeburn 10546: } else {
10547: if ($checkitem eq 'username') {
10548: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10549: } elsif ($checkitem eq 'id') {
10550: $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.");
10551: }
1.612 raeburn 10552: }
10553: return $response;
1.585 raeburn 10554: }
10555:
1.624 raeburn 10556: sub personal_data_fieldtitles {
10557: my %fieldtitles = &Apache::lonlocal::texthash (
10558: id => 'Student/Employee ID',
10559: permanentemail => 'E-mail address',
10560: lastname => 'Last Name',
10561: firstname => 'First Name',
10562: middlename => 'Middle Name',
10563: generation => 'Generation',
10564: gen => 'Generation',
1.765 raeburn 10565: inststatus => 'Affiliation',
1.624 raeburn 10566: );
10567: return %fieldtitles;
10568: }
10569:
1.642 raeburn 10570: sub sorted_inst_types {
10571: my ($dom) = @_;
1.1185 raeburn 10572: my ($usertypes,$order);
10573: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10574: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10575: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10576: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10577: } else {
10578: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10579: }
1.642 raeburn 10580: my $othertitle = &mt('All users');
10581: if ($env{'request.course.id'}) {
1.668 raeburn 10582: $othertitle = &mt('Any users');
1.642 raeburn 10583: }
10584: my @types;
10585: if (ref($order) eq 'ARRAY') {
10586: @types = @{$order};
10587: }
10588: if (@types == 0) {
10589: if (ref($usertypes) eq 'HASH') {
10590: @types = sort(keys(%{$usertypes}));
10591: }
10592: }
10593: if (keys(%{$usertypes}) > 0) {
10594: $othertitle = &mt('Other users');
10595: }
10596: return ($othertitle,$usertypes,\@types);
10597: }
10598:
1.645 raeburn 10599: sub get_institutional_codes {
10600: my ($settings,$allcourses,$LC_code) = @_;
10601: # Get complete list of course sections to update
10602: my @currsections = ();
10603: my @currxlists = ();
10604: my $coursecode = $$settings{'internal.coursecode'};
10605:
10606: if ($$settings{'internal.sectionnums'} ne '') {
10607: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10608: }
10609:
10610: if ($$settings{'internal.crosslistings'} ne '') {
10611: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10612: }
10613:
10614: if (@currxlists > 0) {
10615: foreach (@currxlists) {
10616: if (m/^([^:]+):(\w*)$/) {
10617: unless (grep/^$1$/,@{$allcourses}) {
1.1263 raeburn 10618: push(@{$allcourses},$1);
1.645 raeburn 10619: $$LC_code{$1} = $2;
10620: }
10621: }
10622: }
10623: }
10624:
10625: if (@currsections > 0) {
10626: foreach (@currsections) {
10627: if (m/^(\w+):(\w*)$/) {
10628: my $sec = $coursecode.$1;
10629: my $lc_sec = $2;
10630: unless (grep/^$sec$/,@{$allcourses}) {
1.1263 raeburn 10631: push(@{$allcourses},$sec);
1.645 raeburn 10632: $$LC_code{$sec} = $lc_sec;
10633: }
10634: }
10635: }
10636: }
10637: return;
10638: }
10639:
1.971 raeburn 10640: sub get_standard_codeitems {
10641: return ('Year','Semester','Department','Number','Section');
10642: }
10643:
1.112 bowersj2 10644: =pod
10645:
1.780 raeburn 10646: =head1 Slot Helpers
10647:
10648: =over 4
10649:
10650: =item * sorted_slots()
10651:
1.1040 raeburn 10652: Sorts an array of slot names in order of an optional sort key,
10653: default sort is by slot start time (earliest first).
1.780 raeburn 10654:
10655: Inputs:
10656:
10657: =over 4
10658:
10659: slotsarr - Reference to array of unsorted slot names.
10660:
10661: slots - Reference to hash of hash, where outer hash keys are slot names.
10662:
1.1040 raeburn 10663: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10664:
1.549 albertel 10665: =back
10666:
1.780 raeburn 10667: Returns:
10668:
10669: =over 4
10670:
1.1040 raeburn 10671: sorted - An array of slot names sorted by a specified sort key
10672: (default sort key is start time of the slot).
1.780 raeburn 10673:
10674: =back
10675:
10676: =cut
10677:
10678:
10679: sub sorted_slots {
1.1040 raeburn 10680: my ($slotsarr,$slots,$sortkey) = @_;
10681: if ($sortkey eq '') {
10682: $sortkey = 'starttime';
10683: }
1.780 raeburn 10684: my @sorted;
10685: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10686: @sorted =
10687: sort {
10688: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10689: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10690: }
10691: if (ref($slots->{$a})) { return -1;}
10692: if (ref($slots->{$b})) { return 1;}
10693: return 0;
10694: } @{$slotsarr};
10695: }
10696: return @sorted;
10697: }
10698:
1.1040 raeburn 10699: =pod
10700:
10701: =item * get_future_slots()
10702:
10703: Inputs:
10704:
10705: =over 4
10706:
10707: cnum - course number
10708:
10709: cdom - course domain
10710:
10711: now - current UNIX time
10712:
10713: symb - optional symb
10714:
10715: =back
10716:
10717: Returns:
10718:
10719: =over 4
10720:
10721: sorted_reservable - ref to array of student_schedulable slots currently
10722: reservable, ordered by end date of reservation period.
10723:
10724: reservable_now - ref to hash of student_schedulable slots currently
10725: reservable.
10726:
10727: Keys in inner hash are:
10728: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10729: (b) endreserve: end date of reservation period.
10730: (c) uniqueperiod: start,end dates when slot is to be uniquely
10731: selected.
1.1040 raeburn 10732:
10733: sorted_future - ref to array of student_schedulable slots reservable in
10734: the future, ordered by start date of reservation period.
10735:
10736: future_reservable - ref to hash of student_schedulable slots reservable
10737: in the future.
10738:
10739: Keys in inner hash are:
10740: (a) symb: either blank or symb to which slot use is restricted.
1.1250 raeburn 10741: (b) startreserve: start date of reservation period.
10742: (c) uniqueperiod: start,end dates when slot is to be uniquely
10743: selected.
1.1040 raeburn 10744:
10745: =back
10746:
10747: =cut
10748:
10749: sub get_future_slots {
10750: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 10751: my $map;
10752: if ($symb) {
10753: ($map) = &Apache::lonnet::decode_symb($symb);
10754: }
1.1040 raeburn 10755: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10756: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10757: foreach my $slot (keys(%slots)) {
10758: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10759: if ($symb) {
1.1229 raeburn 10760: if ($slots{$slot}->{'symb'} ne '') {
10761: my $canuse;
10762: my %oksymbs;
10763: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
10764: map { $oksymbs{$_} = 1; } @slotsymbs;
10765: if ($oksymbs{$symb}) {
10766: $canuse = 1;
10767: } else {
10768: foreach my $item (@slotsymbs) {
10769: if ($item =~ /\.(page|sequence)$/) {
10770: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
10771: if (($map ne '') && ($map eq $sloturl)) {
10772: $canuse = 1;
10773: last;
10774: }
10775: }
10776: }
10777: }
10778: next unless ($canuse);
10779: }
1.1040 raeburn 10780: }
10781: if (($slots{$slot}->{'starttime'} > $now) &&
10782: ($slots{$slot}->{'endtime'} > $now)) {
10783: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10784: my $userallowed = 0;
10785: if ($slots{$slot}->{'allowedsections'}) {
10786: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10787: if (!defined($env{'request.role.sec'})
10788: && grep(/^No section assigned$/,@allowed_sec)) {
10789: $userallowed=1;
10790: } else {
10791: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10792: $userallowed=1;
10793: }
10794: }
10795: unless ($userallowed) {
10796: if (defined($env{'request.course.groups'})) {
10797: my @groups = split(/:/,$env{'request.course.groups'});
10798: foreach my $group (@groups) {
10799: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10800: $userallowed=1;
10801: last;
10802: }
10803: }
10804: }
10805: }
10806: }
10807: if ($slots{$slot}->{'allowedusers'}) {
10808: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10809: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10810: if (grep(/^\Q$user\E$/,@allowed_users)) {
10811: $userallowed = 1;
10812: }
10813: }
10814: next unless($userallowed);
10815: }
10816: my $startreserve = $slots{$slot}->{'startreserve'};
10817: my $endreserve = $slots{$slot}->{'endreserve'};
10818: my $symb = $slots{$slot}->{'symb'};
1.1250 raeburn 10819: my $uniqueperiod;
10820: if (ref($slots{$slot}->{'uniqueperiod'}) eq 'ARRAY') {
10821: $uniqueperiod = join(',',@{$slots{$slot}->{'uniqueperiod'}});
10822: }
1.1040 raeburn 10823: if (($startreserve < $now) &&
10824: (!$endreserve || $endreserve > $now)) {
10825: my $lastres = $endreserve;
10826: if (!$lastres) {
10827: $lastres = $slots{$slot}->{'starttime'};
10828: }
10829: $reservable_now{$slot} = {
10830: symb => $symb,
1.1250 raeburn 10831: endreserve => $lastres,
10832: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10833: };
10834: } elsif (($startreserve > $now) &&
10835: (!$endreserve || $endreserve > $startreserve)) {
10836: $future_reservable{$slot} = {
10837: symb => $symb,
1.1250 raeburn 10838: startreserve => $startreserve,
10839: uniqueperiod => $uniqueperiod,
1.1040 raeburn 10840: };
10841: }
10842: }
10843: }
10844: my @unsorted_reservable = keys(%reservable_now);
10845: if (@unsorted_reservable > 0) {
10846: @sorted_reservable =
10847: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10848: }
10849: my @unsorted_future = keys(%future_reservable);
10850: if (@unsorted_future > 0) {
10851: @sorted_future =
10852: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10853: }
10854: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10855: }
1.780 raeburn 10856:
10857: =pod
10858:
1.1057 foxr 10859: =back
10860:
1.549 albertel 10861: =head1 HTTP Helpers
10862:
10863: =over 4
10864:
1.648 raeburn 10865: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10866:
1.258 albertel 10867: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10868: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10869: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10870:
10871: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10872: $possible_names is an ref to an array of form element names. As an example:
10873: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10874: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10875:
10876: =cut
1.1 albertel 10877:
1.6 albertel 10878: sub get_unprocessed_cgi {
1.25 albertel 10879: my ($query,$possible_names)= @_;
1.26 matthew 10880: # $Apache::lonxml::debug=1;
1.356 albertel 10881: foreach my $pair (split(/&/,$query)) {
10882: my ($name, $value) = split(/=/,$pair);
1.369 www 10883: $name = &unescape($name);
1.25 albertel 10884: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10885: $value =~ tr/+/ /;
10886: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10887: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10888: }
1.16 harris41 10889: }
1.6 albertel 10890: }
10891:
1.112 bowersj2 10892: =pod
10893:
1.648 raeburn 10894: =item * &cacheheader()
1.112 bowersj2 10895:
10896: returns cache-controlling header code
10897:
10898: =cut
10899:
1.7 albertel 10900: sub cacheheader {
1.258 albertel 10901: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10902: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10903: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10904: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10905: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10906: return $output;
1.7 albertel 10907: }
10908:
1.112 bowersj2 10909: =pod
10910:
1.648 raeburn 10911: =item * &no_cache($r)
1.112 bowersj2 10912:
10913: specifies header code to not have cache
10914:
10915: =cut
10916:
1.9 albertel 10917: sub no_cache {
1.216 albertel 10918: my ($r) = @_;
10919: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10920: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10921: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10922: $r->no_cache(1);
10923: $r->header_out("Expires" => $date);
10924: $r->header_out("Pragma" => "no-cache");
1.123 www 10925: }
10926:
10927: sub content_type {
1.181 albertel 10928: my ($r,$type,$charset) = @_;
1.299 foxr 10929: if ($r) {
10930: # Note that printout.pl calls this with undef for $r.
10931: &no_cache($r);
10932: }
1.258 albertel 10933: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10934: unless ($charset) {
10935: $charset=&Apache::lonlocal::current_encoding;
10936: }
10937: if ($charset) { $type.='; charset='.$charset; }
10938: if ($r) {
10939: $r->content_type($type);
10940: } else {
10941: print("Content-type: $type\n\n");
10942: }
1.9 albertel 10943: }
1.25 albertel 10944:
1.112 bowersj2 10945: =pod
10946:
1.648 raeburn 10947: =item * &add_to_env($name,$value)
1.112 bowersj2 10948:
1.258 albertel 10949: adds $name to the %env hash with value
1.112 bowersj2 10950: $value, if $name already exists, the entry is converted to an array
10951: reference and $value is added to the array.
10952:
10953: =cut
10954:
1.25 albertel 10955: sub add_to_env {
10956: my ($name,$value)=@_;
1.258 albertel 10957: if (defined($env{$name})) {
10958: if (ref($env{$name})) {
1.25 albertel 10959: #already have multiple values
1.258 albertel 10960: push(@{ $env{$name} },$value);
1.25 albertel 10961: } else {
10962: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10963: my $first=$env{$name};
10964: undef($env{$name});
10965: push(@{ $env{$name} },$first,$value);
1.25 albertel 10966: }
10967: } else {
1.258 albertel 10968: $env{$name}=$value;
1.25 albertel 10969: }
1.31 albertel 10970: }
1.149 albertel 10971:
10972: =pod
10973:
1.648 raeburn 10974: =item * &get_env_multiple($name)
1.149 albertel 10975:
1.258 albertel 10976: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10977: values may be defined and end up as an array ref.
10978:
10979: returns an array of values
10980:
10981: =cut
10982:
10983: sub get_env_multiple {
10984: my ($name) = @_;
10985: my @values;
1.258 albertel 10986: if (defined($env{$name})) {
1.149 albertel 10987: # exists is it an array
1.258 albertel 10988: if (ref($env{$name})) {
10989: @values=@{ $env{$name} };
1.149 albertel 10990: } else {
1.258 albertel 10991: $values[0]=$env{$name};
1.149 albertel 10992: }
10993: }
10994: return(@values);
10995: }
10996:
1.1249 damieng 10997: # Looks at given dependencies, and returns something depending on the context.
10998: # For coursedocs paste, returns (undef, $counter, $numpathchg, \%existing).
10999: # For syllabus rewrites, returns (undef, $counter, $numpathchg, \%existing, \%mapping).
11000: # For all other contexts, returns ($output, $counter, $numpathchg).
11001: # $output: string with the HTML output. Can contain missing dependencies with an upload form, existing dependencies, and dependencies no longer in use.
11002: # $counter: integer with the number of existing dependencies when no HTML output is returned, and the number of missing dependencies when an HTML output is returned.
11003: # $numpathchg: integer with the number of cleaned up dependency paths.
11004: # \%existing: hash reference clean path -> 1 only for existing dependencies.
11005: # \%mapping: hash reference clean path -> original path for all dependencies.
11006: # @param {string} actionurl - The path to the handler, indicative of the context.
11007: # @param {string} state - Can contain HTML with hidden inputs that will be added to the output form.
11008: # @param {hash reference} allfiles - List of file info from lonnet::extract_embedded_items
11009: # @param {hash reference} codebase - undef, not modified by lonnet::extract_embedded_items ?
11010: # @param {hash reference} args - More parameters ! Possible keys: error_on_invalid_names (boolean), ignore_remote_references (boolean), current_path (string), docs_url (string), docs_title (string), context (string)
11011: # @return {Array} - array depending on the context (not a reference)
1.660 raeburn 11012: sub ask_for_embedded_content {
1.1249 damieng 11013: # NOTE: documentation was added afterwards, it could be wrong
1.660 raeburn 11014: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 11015: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 11016: %currsubfile,%unused,$rem);
1.1071 raeburn 11017: my $counter = 0;
11018: my $numnew = 0;
1.987 raeburn 11019: my $numremref = 0;
11020: my $numinvalid = 0;
11021: my $numpathchg = 0;
11022: my $numexisting = 0;
1.1071 raeburn 11023: my $numunused = 0;
11024: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 11025: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 11026: my $heading = &mt('Upload embedded files');
11027: my $buttontext = &mt('Upload');
11028:
1.1249 damieng 11029: # fills these variables based on the context:
11030: # $navmap, $cdom, $cnum, $udom, $uname, $url, $toplevel, $getpropath,
11031: # $path, $fileloc, $title, $rem, $filename
1.1085 raeburn 11032: if ($env{'request.course.id'}) {
1.1123 raeburn 11033: if ($actionurl eq '/adm/dependencies') {
11034: $navmap = Apache::lonnavmaps::navmap->new();
11035: }
11036: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
11037: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 11038: }
1.1123 raeburn 11039: if (($actionurl eq '/adm/portfolio') ||
11040: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 11041: my $current_path='/';
11042: if ($env{'form.currentpath'}) {
11043: $current_path = $env{'form.currentpath'};
11044: }
11045: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 11046: $udom = $cdom;
11047: $uname = $cnum;
1.984 raeburn 11048: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
11049: } else {
11050: $udom = $env{'user.domain'};
11051: $uname = $env{'user.name'};
11052: $url = '/userfiles/portfolio';
11053: }
1.987 raeburn 11054: $toplevel = $url.'/';
1.984 raeburn 11055: $url .= $current_path;
11056: $getpropath = 1;
1.987 raeburn 11057: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11058: ($actionurl eq '/adm/imsimport')) {
1.1022 www 11059: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 11060: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 11061: $toplevel = $url;
1.984 raeburn 11062: if ($rest ne '') {
1.987 raeburn 11063: $url .= $rest;
11064: }
11065: } elsif ($actionurl eq '/adm/coursedocs') {
11066: if (ref($args) eq 'HASH') {
1.1071 raeburn 11067: $url = $args->{'docs_url'};
11068: $toplevel = $url;
1.1084 raeburn 11069: if ($args->{'context'} eq 'paste') {
11070: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
11071: ($path) =
11072: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11073: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11074: $fileloc =~ s{^/}{};
11075: }
1.1071 raeburn 11076: }
1.1084 raeburn 11077: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 11078: if ($env{'request.course.id'} ne '') {
11079: if (ref($args) eq 'HASH') {
11080: $url = $args->{'docs_url'};
11081: $title = $args->{'docs_title'};
1.1126 raeburn 11082: $toplevel = $url;
11083: unless ($toplevel =~ m{^/}) {
11084: $toplevel = "/$url";
11085: }
1.1085 raeburn 11086: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 11087: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
11088: $path = $1;
11089: } else {
11090: ($path) =
11091: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
11092: }
1.1195 raeburn 11093: if ($toplevel=~/^\/*(uploaded|editupload)/) {
11094: $fileloc = $toplevel;
11095: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
11096: my ($udom,$uname,$fname) =
11097: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
11098: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
11099: } else {
11100: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
11101: }
1.1071 raeburn 11102: $fileloc =~ s{^/}{};
11103: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
11104: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
11105: }
1.987 raeburn 11106: }
1.1123 raeburn 11107: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11108: $udom = $cdom;
11109: $uname = $cnum;
11110: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
11111: $toplevel = $url;
11112: $path = $url;
11113: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
11114: $fileloc =~ s{^/}{};
1.987 raeburn 11115: }
1.1249 damieng 11116:
11117: # parses the dependency paths to get some info
11118: # fills $newfiles, $mapping, $subdependencies, $dependencies
11119: # $newfiles: hash URL -> 1 for new files or external URLs
11120: # (will be completed later)
11121: # $mapping:
11122: # for external URLs: external URL -> external URL
11123: # for relative paths: clean path -> original path
11124: # $subdependencies: hash clean path -> clean file name -> 1 for relative paths in subdirectories
11125: # $dependencies: hash clean or not file name -> 1 for relative paths not in subdirectories
1.1126 raeburn 11126: foreach my $file (keys(%{$allfiles})) {
11127: my $embed_file;
11128: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
11129: $embed_file = $1;
11130: } else {
11131: $embed_file = $file;
11132: }
1.1158 raeburn 11133: my ($absolutepath,$cleaned_file);
11134: if ($embed_file =~ m{^\w+://}) {
11135: $cleaned_file = $embed_file;
1.1147 raeburn 11136: $newfiles{$cleaned_file} = 1;
11137: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11138: } else {
1.1158 raeburn 11139: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 11140: if ($embed_file =~ m{^/}) {
11141: $absolutepath = $embed_file;
11142: }
1.1147 raeburn 11143: if ($cleaned_file =~ m{/}) {
11144: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 11145: $path = &check_for_traversal($path,$url,$toplevel);
11146: my $item = $fname;
11147: if ($path ne '') {
11148: $item = $path.'/'.$fname;
11149: $subdependencies{$path}{$fname} = 1;
11150: } else {
11151: $dependencies{$item} = 1;
11152: }
11153: if ($absolutepath) {
11154: $mapping{$item} = $absolutepath;
11155: } else {
11156: $mapping{$item} = $embed_file;
11157: }
11158: } else {
11159: $dependencies{$embed_file} = 1;
11160: if ($absolutepath) {
1.1147 raeburn 11161: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 11162: } else {
1.1147 raeburn 11163: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 11164: }
11165: }
1.984 raeburn 11166: }
11167: }
1.1249 damieng 11168:
11169: # looks for all existing files in dependency subdirectories (from $subdependencies filled above)
11170: # and lists
11171: # fills $currsubfile, $pathchanges, $existing, $numexisting, $newfiles, $unused
11172: # $currsubfile: hash clean path -> file name -> 1 for all existing files in the path
11173: # $pathchanges: hash clean path -> 1 if the file in subdirectory exists and
11174: # the path had to be cleaned up
11175: # $existing: hash clean path -> 1 if the file exists
11176: # $numexisting: number of keys in $existing
11177: # $newfiles: updated with clean path -> 1 for files in subdirectories that do not exist
11178: # $unused: only for /adm/dependencies, hash clean path -> 1 for existing files in
11179: # dependency subdirectories that are
11180: # not listed as dependencies, with some exceptions using $rem
1.1071 raeburn 11181: my $dirptr = 16384;
1.984 raeburn 11182: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 11183: $currsubfile{$path} = {};
1.1123 raeburn 11184: if (($actionurl eq '/adm/portfolio') ||
11185: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11186: my ($sublistref,$listerror) =
11187: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
11188: if (ref($sublistref) eq 'ARRAY') {
11189: foreach my $line (@{$sublistref}) {
11190: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 11191: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 11192: }
1.984 raeburn 11193: }
1.987 raeburn 11194: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11195: if (opendir(my $dir,$url.'/'.$path)) {
11196: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 11197: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
11198: }
1.1084 raeburn 11199: } elsif (($actionurl eq '/adm/dependencies') ||
11200: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11201: ($args->{'context'} eq 'paste')) ||
11202: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11203: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 11204: my $dir;
11205: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
11206: $dir = $fileloc;
11207: } else {
11208: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11209: }
1.1071 raeburn 11210: if ($dir ne '') {
11211: my ($sublistref,$listerror) =
11212: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
11213: if (ref($sublistref) eq 'ARRAY') {
11214: foreach my $line (@{$sublistref}) {
11215: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
11216: undef,$mtime)=split(/\&/,$line,12);
11217: unless (($testdir&$dirptr) ||
11218: ($file_name =~ /^\.\.?$/)) {
11219: $currsubfile{$path}{$file_name} = [$size,$mtime];
11220: }
11221: }
11222: }
11223: }
1.984 raeburn 11224: }
11225: }
11226: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 11227: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 11228: my $item = $path.'/'.$file;
11229: unless ($mapping{$item} eq $item) {
11230: $pathchanges{$item} = 1;
11231: }
11232: $existing{$item} = 1;
11233: $numexisting ++;
11234: } else {
11235: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 11236: }
11237: }
1.1071 raeburn 11238: if ($actionurl eq '/adm/dependencies') {
11239: foreach my $path (keys(%currsubfile)) {
11240: if (ref($currsubfile{$path}) eq 'HASH') {
11241: foreach my $file (keys(%{$currsubfile{$path}})) {
11242: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 11243: next if (($rem ne '') &&
11244: (($env{"httpref.$rem"."$path/$file"} ne '') ||
11245: (ref($navmap) &&
11246: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
11247: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11248: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 11249: $unused{$path.'/'.$file} = 1;
11250: }
11251: }
11252: }
11253: }
11254: }
1.984 raeburn 11255: }
1.1249 damieng 11256:
11257: # fills $currfile, hash file name -> 1 or [$size,$mtime]
11258: # for files in $url or $fileloc (target directory) in some contexts
1.987 raeburn 11259: my %currfile;
1.1123 raeburn 11260: if (($actionurl eq '/adm/portfolio') ||
11261: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 11262: my ($dirlistref,$listerror) =
11263: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
11264: if (ref($dirlistref) eq 'ARRAY') {
11265: foreach my $line (@{$dirlistref}) {
11266: my ($file_name,$rest) = split(/\&/,$line,2);
11267: $currfile{$file_name} = 1;
11268: }
1.984 raeburn 11269: }
1.987 raeburn 11270: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 11271: if (opendir(my $dir,$url)) {
1.987 raeburn 11272: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 11273: map {$currfile{$_} = 1;} @dir_list;
11274: }
1.1084 raeburn 11275: } elsif (($actionurl eq '/adm/dependencies') ||
11276: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 11277: ($args->{'context'} eq 'paste')) ||
11278: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 11279: if ($env{'request.course.id'} ne '') {
11280: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
11281: if ($dir ne '') {
11282: my ($dirlistref,$listerror) =
11283: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
11284: if (ref($dirlistref) eq 'ARRAY') {
11285: foreach my $line (@{$dirlistref}) {
11286: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
11287: $size,undef,$mtime)=split(/\&/,$line,12);
11288: unless (($testdir&$dirptr) ||
11289: ($file_name =~ /^\.\.?$/)) {
11290: $currfile{$file_name} = [$size,$mtime];
11291: }
11292: }
11293: }
11294: }
11295: }
1.984 raeburn 11296: }
1.1249 damieng 11297: # updates $pathchanges, $existing, $numexisting, $newfiles and $unused for files that
11298: # are not in subdirectories, using $currfile
1.984 raeburn 11299: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 11300: if (exists($currfile{$file})) {
1.987 raeburn 11301: unless ($mapping{$file} eq $file) {
11302: $pathchanges{$file} = 1;
11303: }
11304: $existing{$file} = 1;
11305: $numexisting ++;
11306: } else {
1.984 raeburn 11307: $newfiles{$file} = 1;
11308: }
11309: }
1.1071 raeburn 11310: foreach my $file (keys(%currfile)) {
11311: unless (($file eq $filename) ||
11312: ($file eq $filename.'.bak') ||
11313: ($dependencies{$file})) {
1.1085 raeburn 11314: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 11315: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
11316: next if (($rem ne '') &&
11317: (($env{"httpref.$rem".$file} ne '') ||
11318: (ref($navmap) &&
11319: (($navmap->getResourceByUrl($rem.$file) ne '') ||
11320: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
11321: ($navmap->getResourceByUrl($rem.$1)))))));
11322: }
1.1085 raeburn 11323: }
1.1071 raeburn 11324: $unused{$file} = 1;
11325: }
11326: }
1.1249 damieng 11327:
11328: # returns some results for coursedocs paste and syllabus rewrites ($output is undef)
1.1084 raeburn 11329: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
11330: ($args->{'context'} eq 'paste')) {
11331: $counter = scalar(keys(%existing));
11332: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 11333: return ($output,$counter,$numpathchg,\%existing);
11334: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
11335: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
11336: $counter = scalar(keys(%existing));
11337: $numpathchg = scalar(keys(%pathchanges));
11338: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 11339: }
1.1249 damieng 11340:
11341: # returns HTML otherwise, with dependency results and to ask for more uploads
11342:
11343: # $upload_output: missing dependencies (with upload form)
11344: # $modify_output: uploaded dependencies (in use)
11345: # $delete_output: files no longer in use (unused files are not listed for londocs, bug?)
1.984 raeburn 11346: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 11347: if ($actionurl eq '/adm/dependencies') {
11348: next if ($embed_file =~ m{^\w+://});
11349: }
1.660 raeburn 11350: $upload_output .= &start_data_table_row().
1.1123 raeburn 11351: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 11352: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 11353: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 11354: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
11355: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 11356: }
1.1123 raeburn 11357: $upload_output .= '</td>';
1.1071 raeburn 11358: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 11359: $upload_output.='<td align="right">'.
11360: '<span class="LC_info LC_fontsize_medium">'.
11361: &mt("URL points to web address").'</span>';
1.987 raeburn 11362: $numremref++;
1.660 raeburn 11363: } elsif ($args->{'error_on_invalid_names'}
11364: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 11365: $upload_output.='<td align="right"><span class="LC_warning">'.
11366: &mt('Invalid characters').'</span>';
1.987 raeburn 11367: $numinvalid++;
1.660 raeburn 11368: } else {
1.1123 raeburn 11369: $upload_output .= '<td>'.
11370: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 11371: $embed_file,\%mapping,
1.1071 raeburn 11372: $allfiles,$codebase,'upload');
11373: $counter ++;
11374: $numnew ++;
1.987 raeburn 11375: }
11376: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
11377: }
11378: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 11379: if ($actionurl eq '/adm/dependencies') {
11380: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
11381: $modify_output .= &start_data_table_row().
11382: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
11383: '<img src="'.&icon($embed_file).'" border="0" />'.
11384: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
11385: '<td>'.$size.'</td>'.
11386: '<td>'.$mtime.'</td>'.
11387: '<td><label><input type="checkbox" name="mod_upload_dep" '.
11388: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
11389: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
11390: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
11391: &embedded_file_element('upload_embedded',$counter,
11392: $embed_file,\%mapping,
11393: $allfiles,$codebase,'modify').
11394: '</div></td>'.
11395: &end_data_table_row()."\n";
11396: $counter ++;
11397: } else {
11398: $upload_output .= &start_data_table_row().
1.1123 raeburn 11399: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
11400: '<span class="LC_filename">'.$embed_file.'</span></td>'.
11401: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 11402: &Apache::loncommon::end_data_table_row()."\n";
11403: }
11404: }
11405: my $delidx = $counter;
11406: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
11407: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
11408: $delete_output .= &start_data_table_row().
11409: '<td><img src="'.&icon($oldfile).'" />'.
11410: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
11411: '<td>'.$size.'</td>'.
11412: '<td>'.$mtime.'</td>'.
11413: '<td><label><input type="checkbox" name="del_upload_dep" '.
11414: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
11415: &embedded_file_element('upload_embedded',$delidx,
11416: $oldfile,\%mapping,$allfiles,
11417: $codebase,'delete').'</td>'.
11418: &end_data_table_row()."\n";
11419: $numunused ++;
11420: $delidx ++;
1.987 raeburn 11421: }
11422: if ($upload_output) {
11423: $upload_output = &start_data_table().
11424: $upload_output.
11425: &end_data_table()."\n";
11426: }
1.1071 raeburn 11427: if ($modify_output) {
11428: $modify_output = &start_data_table().
11429: &start_data_table_header_row().
11430: '<th>'.&mt('File').'</th>'.
11431: '<th>'.&mt('Size (KB)').'</th>'.
11432: '<th>'.&mt('Modified').'</th>'.
11433: '<th>'.&mt('Upload replacement?').'</th>'.
11434: &end_data_table_header_row().
11435: $modify_output.
11436: &end_data_table()."\n";
11437: }
11438: if ($delete_output) {
11439: $delete_output = &start_data_table().
11440: &start_data_table_header_row().
11441: '<th>'.&mt('File').'</th>'.
11442: '<th>'.&mt('Size (KB)').'</th>'.
11443: '<th>'.&mt('Modified').'</th>'.
11444: '<th>'.&mt('Delete?').'</th>'.
11445: &end_data_table_header_row().
11446: $delete_output.
11447: &end_data_table()."\n";
11448: }
1.987 raeburn 11449: my $applies = 0;
11450: if ($numremref) {
11451: $applies ++;
11452: }
11453: if ($numinvalid) {
11454: $applies ++;
11455: }
11456: if ($numexisting) {
11457: $applies ++;
11458: }
1.1071 raeburn 11459: if ($counter || $numunused) {
1.987 raeburn 11460: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
11461: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 11462: $state.'<h3>'.$heading.'</h3>';
11463: if ($actionurl eq '/adm/dependencies') {
11464: if ($numnew) {
11465: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
11466: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
11467: $upload_output.'<br />'."\n";
11468: }
11469: if ($numexisting) {
11470: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
11471: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
11472: $modify_output.'<br />'."\n";
11473: $buttontext = &mt('Save changes');
11474: }
11475: if ($numunused) {
11476: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11477: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11478: $delete_output.'<br />'."\n";
11479: $buttontext = &mt('Save changes');
11480: }
11481: } else {
11482: $output .= $upload_output.'<br />'."\n";
11483: }
11484: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11485: $counter.'" />'."\n";
11486: if ($actionurl eq '/adm/dependencies') {
11487: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11488: $numnew.'" />'."\n";
11489: } elsif ($actionurl eq '') {
1.987 raeburn 11490: $output .= '<input type="hidden" name="phase" value="three" />';
11491: }
11492: } elsif ($applies) {
11493: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11494: if ($applies > 1) {
11495: $output .=
1.1123 raeburn 11496: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11497: if ($numremref) {
11498: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11499: }
11500: if ($numinvalid) {
11501: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11502: }
11503: if ($numexisting) {
11504: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11505: }
11506: $output .= '</ul><br />';
11507: } elsif ($numremref) {
11508: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11509: } elsif ($numinvalid) {
11510: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11511: } elsif ($numexisting) {
11512: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11513: }
11514: $output .= $upload_output.'<br />';
11515: }
11516: my ($pathchange_output,$chgcount);
1.1071 raeburn 11517: $chgcount = $counter;
1.987 raeburn 11518: if (keys(%pathchanges) > 0) {
11519: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11520: if ($counter) {
1.987 raeburn 11521: $output .= &embedded_file_element('pathchange',$chgcount,
11522: $embed_file,\%mapping,
1.1071 raeburn 11523: $allfiles,$codebase,'change');
1.987 raeburn 11524: } else {
11525: $pathchange_output .=
11526: &start_data_table_row().
11527: '<td><input type ="checkbox" name="namechange" value="'.
11528: $chgcount.'" checked="checked" /></td>'.
11529: '<td>'.$mapping{$embed_file}.'</td>'.
11530: '<td>'.$embed_file.
11531: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11532: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11533: '</td>'.&end_data_table_row();
1.660 raeburn 11534: }
1.987 raeburn 11535: $numpathchg ++;
11536: $chgcount ++;
1.660 raeburn 11537: }
11538: }
1.1127 raeburn 11539: if (($counter) || ($numunused)) {
1.987 raeburn 11540: if ($numpathchg) {
11541: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11542: $numpathchg.'" />'."\n";
11543: }
11544: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11545: ($actionurl eq '/adm/imsimport')) {
11546: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11547: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11548: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11549: } elsif ($actionurl eq '/adm/dependencies') {
11550: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11551: }
1.1123 raeburn 11552: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11553: } elsif ($numpathchg) {
11554: my %pathchange = ();
11555: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11556: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11557: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11558: }
1.987 raeburn 11559: }
1.1071 raeburn 11560: return ($output,$counter,$numpathchg);
1.987 raeburn 11561: }
11562:
1.1147 raeburn 11563: =pod
11564:
11565: =item * clean_path($name)
11566:
11567: Performs clean-up of directories, subdirectories and filename in an
11568: embedded object, referenced in an HTML file which is being uploaded
11569: to a course or portfolio, where
11570: "Upload embedded images/multimedia files if HTML file" checkbox was
11571: checked.
11572:
11573: Clean-up is similar to replacements in lonnet::clean_filename()
11574: except each / between sub-directory and next level is preserved.
11575:
11576: =cut
11577:
11578: sub clean_path {
11579: my ($embed_file) = @_;
11580: $embed_file =~s{^/+}{};
11581: my @contents;
11582: if ($embed_file =~ m{/}) {
11583: @contents = split(/\//,$embed_file);
11584: } else {
11585: @contents = ($embed_file);
11586: }
11587: my $lastidx = scalar(@contents)-1;
11588: for (my $i=0; $i<=$lastidx; $i++) {
11589: $contents[$i]=~s{\\}{/}g;
11590: $contents[$i]=~s/\s+/\_/g;
11591: $contents[$i]=~s{[^/\w\.\-]}{}g;
11592: if ($i == $lastidx) {
11593: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11594: }
11595: }
11596: if ($lastidx > 0) {
11597: return join('/',@contents);
11598: } else {
11599: return $contents[0];
11600: }
11601: }
11602:
1.987 raeburn 11603: sub embedded_file_element {
1.1071 raeburn 11604: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11605: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11606: (ref($codebase) eq 'HASH'));
11607: my $output;
1.1071 raeburn 11608: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11609: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11610: }
11611: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11612: &escape($embed_file).'" />';
11613: unless (($context eq 'upload_embedded') &&
11614: ($mapping->{$embed_file} eq $embed_file)) {
11615: $output .='
11616: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11617: }
11618: my $attrib;
11619: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11620: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11621: }
11622: $output .=
11623: "\n\t\t".
11624: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11625: $attrib.'" />';
11626: if (exists($codebase->{$mapping->{$embed_file}})) {
11627: $output .=
11628: "\n\t\t".
11629: '<input name="codebase_'.$num.'" type="hidden" value="'.
11630: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11631: }
1.987 raeburn 11632: return $output;
1.660 raeburn 11633: }
11634:
1.1071 raeburn 11635: sub get_dependency_details {
11636: my ($currfile,$currsubfile,$embed_file) = @_;
11637: my ($size,$mtime,$showsize,$showmtime);
11638: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11639: if ($embed_file =~ m{/}) {
11640: my ($path,$fname) = split(/\//,$embed_file);
11641: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11642: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11643: }
11644: } else {
11645: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11646: ($size,$mtime) = @{$currfile->{$embed_file}};
11647: }
11648: }
11649: $showsize = $size/1024.0;
11650: $showsize = sprintf("%.1f",$showsize);
11651: if ($mtime > 0) {
11652: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11653: }
11654: }
11655: return ($showsize,$showmtime);
11656: }
11657:
11658: sub ask_embedded_js {
11659: return <<"END";
11660: <script type="text/javascript"">
11661: // <![CDATA[
11662: function toggleBrowse(counter) {
11663: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11664: var fileid = document.getElementById('embedded_item_'+counter);
11665: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11666: if (chkboxid.checked == true) {
11667: uploaddivid.style.display='block';
11668: } else {
11669: uploaddivid.style.display='none';
11670: fileid.value = '';
11671: }
11672: }
11673: // ]]>
11674: </script>
11675:
11676: END
11677: }
11678:
1.661 raeburn 11679: sub upload_embedded {
11680: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11681: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11682: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11683: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11684: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11685: my $orig_uploaded_filename =
11686: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11687: foreach my $type ('orig','ref','attrib','codebase') {
11688: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11689: $env{'form.embedded_'.$type.'_'.$i} =
11690: &unescape($env{'form.embedded_'.$type.'_'.$i});
11691: }
11692: }
1.661 raeburn 11693: my ($path,$fname) =
11694: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11695: # no path, whole string is fname
11696: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11697: $fname = &Apache::lonnet::clean_filename($fname);
11698: # See if there is anything left
11699: next if ($fname eq '');
11700:
11701: # Check if file already exists as a file or directory.
11702: my ($state,$msg);
11703: if ($context eq 'portfolio') {
11704: my $port_path = $dirpath;
11705: if ($group ne '') {
11706: $port_path = "groups/$group/$port_path";
11707: }
1.987 raeburn 11708: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11709: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11710: $dir_root,$port_path,$disk_quota,
11711: $current_disk_usage,$uname,$udom);
11712: if ($state eq 'will_exceed_quota'
1.984 raeburn 11713: || $state eq 'file_locked') {
1.661 raeburn 11714: $output .= $msg;
11715: next;
11716: }
11717: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11718: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11719: if ($state eq 'exists') {
11720: $output .= $msg;
11721: next;
11722: }
11723: }
11724: # Check if extension is valid
11725: if (($fname =~ /\.(\w+)$/) &&
11726: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 11727: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11728: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11729: next;
11730: } elsif (($fname =~ /\.(\w+)$/) &&
11731: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11732: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11733: next;
11734: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 11735: $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 11736: next;
11737: }
11738: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 11739: my $subdir = $path;
11740: $subdir =~ s{/+$}{};
1.661 raeburn 11741: if ($context eq 'portfolio') {
1.984 raeburn 11742: my $result;
11743: if ($state eq 'existingfile') {
11744: $result=
11745: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 11746: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11747: } else {
1.984 raeburn 11748: $result=
11749: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11750: $dirpath.
1.1123 raeburn 11751: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11752: if ($result !~ m|^/uploaded/|) {
11753: $output .= '<span class="LC_error">'
11754: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11755: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11756: .'</span><br />';
11757: next;
11758: } else {
1.987 raeburn 11759: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11760: $path.$fname.'</span>').'<br />';
1.984 raeburn 11761: }
1.661 raeburn 11762: }
1.1123 raeburn 11763: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 11764: my $extendedsubdir = $dirpath.'/'.$subdir;
11765: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11766: my $result =
1.1126 raeburn 11767: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11768: if ($result !~ m|^/uploaded/|) {
11769: $output .= '<span class="LC_error">'
11770: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11771: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11772: .'</span><br />';
11773: next;
11774: } else {
11775: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11776: $path.$fname.'</span>').'<br />';
1.1125 raeburn 11777: if ($context eq 'syllabus') {
11778: &Apache::lonnet::make_public_indefinitely($result);
11779: }
1.987 raeburn 11780: }
1.661 raeburn 11781: } else {
11782: # Save the file
11783: my $target = $env{'form.embedded_item_'.$i};
11784: my $fullpath = $dir_root.$dirpath.'/'.$path;
11785: my $dest = $fullpath.$fname;
11786: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11787: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11788: my $count;
11789: my $filepath = $dir_root;
1.1027 raeburn 11790: foreach my $subdir (@parts) {
11791: $filepath .= "/$subdir";
11792: if (!-e $filepath) {
1.661 raeburn 11793: mkdir($filepath,0770);
11794: }
11795: }
11796: my $fh;
11797: if (!open($fh,'>'.$dest)) {
11798: &Apache::lonnet::logthis('Failed to create '.$dest);
11799: $output .= '<span class="LC_error">'.
1.1071 raeburn 11800: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11801: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11802: '</span><br />';
11803: } else {
11804: if (!print $fh $env{'form.embedded_item_'.$i}) {
11805: &Apache::lonnet::logthis('Failed to write to '.$dest);
11806: $output .= '<span class="LC_error">'.
1.1071 raeburn 11807: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11808: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11809: '</span><br />';
11810: } else {
1.987 raeburn 11811: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11812: $url.'</span>').'<br />';
11813: unless ($context eq 'testbank') {
11814: $footer .= &mt('View embedded file: [_1]',
11815: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11816: }
11817: }
11818: close($fh);
11819: }
11820: }
11821: if ($env{'form.embedded_ref_'.$i}) {
11822: $pathchange{$i} = 1;
11823: }
11824: }
11825: if ($output) {
11826: $output = '<p>'.$output.'</p>';
11827: }
11828: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11829: $returnflag = 'ok';
1.1071 raeburn 11830: my $numpathchgs = scalar(keys(%pathchange));
11831: if ($numpathchgs > 0) {
1.987 raeburn 11832: if ($context eq 'portfolio') {
11833: $output .= '<p>'.&mt('or').'</p>';
11834: } elsif ($context eq 'testbank') {
1.1071 raeburn 11835: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11836: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11837: $returnflag = 'modify_orightml';
11838: }
11839: }
1.1071 raeburn 11840: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11841: }
11842:
11843: sub modify_html_form {
11844: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11845: my $end = 0;
11846: my $modifyform;
11847: if ($context eq 'upload_embedded') {
11848: return unless (ref($pathchange) eq 'HASH');
11849: if ($env{'form.number_embedded_items'}) {
11850: $end += $env{'form.number_embedded_items'};
11851: }
11852: if ($env{'form.number_pathchange_items'}) {
11853: $end += $env{'form.number_pathchange_items'};
11854: }
11855: if ($end) {
11856: for (my $i=0; $i<$end; $i++) {
11857: if ($i < $env{'form.number_embedded_items'}) {
11858: next unless($pathchange->{$i});
11859: }
11860: $modifyform .=
11861: &start_data_table_row().
11862: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11863: 'checked="checked" /></td>'.
11864: '<td>'.$env{'form.embedded_ref_'.$i}.
11865: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11866: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11867: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11868: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11869: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11870: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11871: '<td>'.$env{'form.embedded_orig_'.$i}.
11872: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11873: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11874: &end_data_table_row();
1.1071 raeburn 11875: }
1.987 raeburn 11876: }
11877: } else {
11878: $modifyform = $pathchgtable;
11879: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11880: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11881: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11882: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11883: }
11884: }
11885: if ($modifyform) {
1.1071 raeburn 11886: if ($actionurl eq '/adm/dependencies') {
11887: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11888: }
1.987 raeburn 11889: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11890: '<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".
11891: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11892: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11893: '</ol></p>'."\n".'<p>'.
11894: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11895: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11896: &start_data_table()."\n".
11897: &start_data_table_header_row().
11898: '<th>'.&mt('Change?').'</th>'.
11899: '<th>'.&mt('Current reference').'</th>'.
11900: '<th>'.&mt('Required reference').'</th>'.
11901: &end_data_table_header_row()."\n".
11902: $modifyform.
11903: &end_data_table().'<br />'."\n".$hiddenstate.
11904: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11905: '</form>'."\n";
11906: }
11907: return;
11908: }
11909:
11910: sub modify_html_refs {
1.1123 raeburn 11911: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11912: my $container;
11913: if ($context eq 'portfolio') {
11914: $container = $env{'form.container'};
11915: } elsif ($context eq 'coursedoc') {
11916: $container = $env{'form.primaryurl'};
1.1071 raeburn 11917: } elsif ($context eq 'manage_dependencies') {
11918: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11919: $container = "/$container";
1.1123 raeburn 11920: } elsif ($context eq 'syllabus') {
11921: $container = $url;
1.987 raeburn 11922: } else {
1.1027 raeburn 11923: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11924: }
11925: my (%allfiles,%codebase,$output,$content);
11926: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 11927: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11928: if (wantarray) {
11929: return ('',0,0);
11930: } else {
11931: return;
11932: }
11933: }
11934: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11935: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11936: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11937: if (wantarray) {
11938: return ('',0,0);
11939: } else {
11940: return;
11941: }
11942: }
1.987 raeburn 11943: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11944: if ($content eq '-1') {
11945: if (wantarray) {
11946: return ('',0,0);
11947: } else {
11948: return;
11949: }
11950: }
1.987 raeburn 11951: } else {
1.1071 raeburn 11952: unless ($container =~ /^\Q$dir_root\E/) {
11953: if (wantarray) {
11954: return ('',0,0);
11955: } else {
11956: return;
11957: }
11958: }
1.987 raeburn 11959: if (open(my $fh,"<$container")) {
11960: $content = join('', <$fh>);
11961: close($fh);
11962: } else {
1.1071 raeburn 11963: if (wantarray) {
11964: return ('',0,0);
11965: } else {
11966: return;
11967: }
1.987 raeburn 11968: }
11969: }
11970: my ($count,$codebasecount) = (0,0);
11971: my $mm = new File::MMagic;
11972: my $mime_type = $mm->checktype_contents($content);
11973: if ($mime_type eq 'text/html') {
11974: my $parse_result =
11975: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11976: \%codebase,\$content);
11977: if ($parse_result eq 'ok') {
11978: foreach my $i (@changes) {
11979: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11980: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11981: if ($allfiles{$ref}) {
11982: my $newname = $orig;
11983: my ($attrib_regexp,$codebase);
1.1006 raeburn 11984: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11985: if ($attrib_regexp =~ /:/) {
11986: $attrib_regexp =~ s/\:/|/g;
11987: }
11988: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11989: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11990: $count += $numchg;
1.1123 raeburn 11991: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 11992: delete($allfiles{$ref});
1.987 raeburn 11993: }
11994: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11995: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11996: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11997: $codebasecount ++;
11998: }
11999: }
12000: }
1.1123 raeburn 12001: my $skiprewrites;
1.987 raeburn 12002: if ($count || $codebasecount) {
12003: my $saveresult;
1.1071 raeburn 12004: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 12005: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 12006: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12007: if ($url eq $container) {
12008: my ($fname) = ($container =~ m{/([^/]+)$});
12009: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12010: $count,'<span class="LC_filename">'.
1.1071 raeburn 12011: $fname.'</span>').'</p>';
1.987 raeburn 12012: } else {
12013: $output = '<p class="LC_error">'.
12014: &mt('Error: update failed for: [_1].',
12015: '<span class="LC_filename">'.
12016: $container.'</span>').'</p>';
12017: }
1.1123 raeburn 12018: if ($context eq 'syllabus') {
12019: unless ($saveresult eq 'ok') {
12020: $skiprewrites = 1;
12021: }
12022: }
1.987 raeburn 12023: } else {
12024: if (open(my $fh,">$container")) {
12025: print $fh $content;
12026: close($fh);
12027: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
12028: $count,'<span class="LC_filename">'.
12029: $container.'</span>').'</p>';
1.661 raeburn 12030: } else {
1.987 raeburn 12031: $output = '<p class="LC_error">'.
12032: &mt('Error: could not update [_1].',
12033: '<span class="LC_filename">'.
12034: $container.'</span>').'</p>';
1.661 raeburn 12035: }
12036: }
12037: }
1.1123 raeburn 12038: if (($context eq 'syllabus') && (!$skiprewrites)) {
12039: my ($actionurl,$state);
12040: $actionurl = "/public/$udom/$uname/syllabus";
12041: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
12042: &ask_for_embedded_content($actionurl,$state,\%allfiles,
12043: \%codebase,
12044: {'context' => 'rewrites',
12045: 'ignore_remote_references' => 1,});
12046: if (ref($mapping) eq 'HASH') {
12047: my $rewrites = 0;
12048: foreach my $key (keys(%{$mapping})) {
12049: next if ($key =~ m{^https?://});
12050: my $ref = $mapping->{$key};
12051: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
12052: my $attrib;
12053: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
12054: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
12055: }
12056: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
12057: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
12058: $rewrites += $numchg;
12059: }
12060: }
12061: if ($rewrites) {
12062: my $saveresult;
12063: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
12064: if ($url eq $container) {
12065: my ($fname) = ($container =~ m{/([^/]+)$});
12066: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
12067: $count,'<span class="LC_filename">'.
12068: $fname.'</span>').'</p>';
12069: } else {
12070: $output .= '<p class="LC_error">'.
12071: &mt('Error: could not update links in [_1].',
12072: '<span class="LC_filename">'.
12073: $container.'</span>').'</p>';
12074:
12075: }
12076: }
12077: }
12078: }
1.987 raeburn 12079: } else {
12080: &logthis('Failed to parse '.$container.
12081: ' to modify references: '.$parse_result);
1.661 raeburn 12082: }
12083: }
1.1071 raeburn 12084: if (wantarray) {
12085: return ($output,$count,$codebasecount);
12086: } else {
12087: return $output;
12088: }
1.661 raeburn 12089: }
12090:
12091: sub check_for_existing {
12092: my ($path,$fname,$element) = @_;
12093: my ($state,$msg);
12094: if (-d $path.'/'.$fname) {
12095: $state = 'exists';
12096: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12097: } elsif (-e $path.'/'.$fname) {
12098: $state = 'exists';
12099: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
12100: }
12101: if ($state eq 'exists') {
12102: $msg = '<span class="LC_error">'.$msg.'</span><br />';
12103: }
12104: return ($state,$msg);
12105: }
12106:
12107: sub check_for_upload {
12108: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
12109: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 12110: my $filesize = length($env{'form.'.$element});
12111: if (!$filesize) {
12112: my $msg = '<span class="LC_error">'.
12113: &mt('Unable to upload [_1]. (size = [_2] bytes)',
12114: '<span class="LC_filename">'.$fname.'</span>',
12115: $filesize).'<br />'.
1.1007 raeburn 12116: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 12117: '</span>';
12118: return ('zero_bytes',$msg);
12119: }
12120: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 12121: my $getpropath = 1;
1.1021 raeburn 12122: my ($dirlistref,$listerror) =
12123: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 12124: my $found_file = 0;
12125: my $locked_file = 0;
1.991 raeburn 12126: my @lockers;
12127: my $navmap;
12128: if ($env{'request.course.id'}) {
12129: $navmap = Apache::lonnavmaps::navmap->new();
12130: }
1.1021 raeburn 12131: if (ref($dirlistref) eq 'ARRAY') {
12132: foreach my $line (@{$dirlistref}) {
12133: my ($file_name,$rest)=split(/\&/,$line,2);
12134: if ($file_name eq $fname){
12135: $file_name = $path.$file_name;
12136: if ($group ne '') {
12137: $file_name = $group.$file_name;
12138: }
12139: $found_file = 1;
12140: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
12141: foreach my $lock (@lockers) {
12142: if (ref($lock) eq 'ARRAY') {
12143: my ($symb,$crsid) = @{$lock};
12144: if ($crsid eq $env{'request.course.id'}) {
12145: if (ref($navmap)) {
12146: my $res = $navmap->getBySymb($symb);
12147: foreach my $part (@{$res->parts()}) {
12148: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
12149: unless (($slot_status == $res->RESERVED) ||
12150: ($slot_status == $res->RESERVED_LOCATION)) {
12151: $locked_file = 1;
12152: }
1.991 raeburn 12153: }
1.1021 raeburn 12154: } else {
12155: $locked_file = 1;
1.991 raeburn 12156: }
12157: } else {
12158: $locked_file = 1;
12159: }
12160: }
1.1021 raeburn 12161: }
12162: } else {
12163: my @info = split(/\&/,$rest);
12164: my $currsize = $info[6]/1000;
12165: if ($currsize < $filesize) {
12166: my $extra = $filesize - $currsize;
12167: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 12168: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 12169: &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 12170: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
12171: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
12172: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 12173: return ('will_exceed_quota',$msg);
12174: }
1.984 raeburn 12175: }
12176: }
1.661 raeburn 12177: }
12178: }
12179: }
12180: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 12181: my $msg = '<p class="LC_warning">'.
12182: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 12183: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 12184: return ('will_exceed_quota',$msg);
12185: } elsif ($found_file) {
12186: if ($locked_file) {
1.1179 bisitz 12187: my $msg = '<p class="LC_warning">';
1.661 raeburn 12188: $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 12189: $msg .= '</p>';
1.661 raeburn 12190: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
12191: return ('file_locked',$msg);
12192: } else {
1.1179 bisitz 12193: my $msg = '<p class="LC_error">';
1.984 raeburn 12194: $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 12195: $msg .= '</p>';
1.984 raeburn 12196: return ('existingfile',$msg);
1.661 raeburn 12197: }
12198: }
12199: }
12200:
1.987 raeburn 12201: sub check_for_traversal {
12202: my ($path,$url,$toplevel) = @_;
12203: my @parts=split(/\//,$path);
12204: my $cleanpath;
12205: my $fullpath = $url;
12206: for (my $i=0;$i<@parts;$i++) {
12207: next if ($parts[$i] eq '.');
12208: if ($parts[$i] eq '..') {
12209: $fullpath =~ s{([^/]+/)$}{};
12210: } else {
12211: $fullpath .= $parts[$i].'/';
12212: }
12213: }
12214: if ($fullpath =~ /^\Q$url\E(.*)$/) {
12215: $cleanpath = $1;
12216: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
12217: my $curr_toprel = $1;
12218: my @parts = split(/\//,$curr_toprel);
12219: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
12220: my @urlparts = split(/\//,$url_toprel);
12221: my $doubledots;
12222: my $startdiff = -1;
12223: for (my $i=0; $i<@urlparts; $i++) {
12224: if ($startdiff == -1) {
12225: unless ($urlparts[$i] eq $parts[$i]) {
12226: $startdiff = $i;
12227: $doubledots .= '../';
12228: }
12229: } else {
12230: $doubledots .= '../';
12231: }
12232: }
12233: if ($startdiff > -1) {
12234: $cleanpath = $doubledots;
12235: for (my $i=$startdiff; $i<@parts; $i++) {
12236: $cleanpath .= $parts[$i].'/';
12237: }
12238: }
12239: }
12240: $cleanpath =~ s{(/)$}{};
12241: return $cleanpath;
12242: }
1.31 albertel 12243:
1.1053 raeburn 12244: sub is_archive_file {
12245: my ($mimetype) = @_;
12246: if (($mimetype eq 'application/octet-stream') ||
12247: ($mimetype eq 'application/x-stuffit') ||
12248: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
12249: return 1;
12250: }
12251: return;
12252: }
12253:
12254: sub decompress_form {
1.1065 raeburn 12255: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 12256: my %lt = &Apache::lonlocal::texthash (
12257: this => 'This file is an archive file.',
1.1067 raeburn 12258: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 12259: itsc => 'Its contents are as follows:',
1.1053 raeburn 12260: youm => 'You may wish to extract its contents.',
12261: extr => 'Extract contents',
1.1067 raeburn 12262: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
12263: proa => 'Process automatically?',
1.1053 raeburn 12264: yes => 'Yes',
12265: no => 'No',
1.1067 raeburn 12266: fold => 'Title for folder containing movie',
12267: movi => 'Title for page containing embedded movie',
1.1053 raeburn 12268: );
1.1065 raeburn 12269: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 12270: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 12271: my $info = &list_archive_contents($fileloc,\@paths);
12272: if (@paths) {
12273: foreach my $path (@paths) {
12274: $path =~ s{^/}{};
1.1067 raeburn 12275: if ($path =~ m{^([^/]+)/$}) {
12276: $topdir = $1;
12277: }
1.1065 raeburn 12278: if ($path =~ m{^([^/]+)/}) {
12279: $toplevel{$1} = $path;
12280: } else {
12281: $toplevel{$path} = $path;
12282: }
12283: }
12284: }
1.1067 raeburn 12285: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 12286: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 12287: "$topdir/media/",
12288: "$topdir/media/$topdir.mp4",
12289: "$topdir/media/FirstFrame.png",
12290: "$topdir/media/player.swf",
12291: "$topdir/media/swfobject.js",
12292: "$topdir/media/expressInstall.swf");
1.1197 raeburn 12293: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 12294: "$topdir/$topdir.mp4",
12295: "$topdir/$topdir\_config.xml",
12296: "$topdir/$topdir\_controller.swf",
12297: "$topdir/$topdir\_embed.css",
12298: "$topdir/$topdir\_First_Frame.png",
12299: "$topdir/$topdir\_player.html",
12300: "$topdir/$topdir\_Thumbnails.png",
12301: "$topdir/playerProductInstall.swf",
12302: "$topdir/scripts/",
12303: "$topdir/scripts/config_xml.js",
12304: "$topdir/scripts/handlebars.js",
12305: "$topdir/scripts/jquery-1.7.1.min.js",
12306: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
12307: "$topdir/scripts/modernizr.js",
12308: "$topdir/scripts/player-min.js",
12309: "$topdir/scripts/swfobject.js",
12310: "$topdir/skins/",
12311: "$topdir/skins/configuration_express.xml",
12312: "$topdir/skins/express_show/",
12313: "$topdir/skins/express_show/player-min.css",
12314: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 12315: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
12316: "$topdir/$topdir.mp4",
12317: "$topdir/$topdir\_config.xml",
12318: "$topdir/$topdir\_controller.swf",
12319: "$topdir/$topdir\_embed.css",
12320: "$topdir/$topdir\_First_Frame.png",
12321: "$topdir/$topdir\_player.html",
12322: "$topdir/$topdir\_Thumbnails.png",
12323: "$topdir/playerProductInstall.swf",
12324: "$topdir/scripts/",
12325: "$topdir/scripts/config_xml.js",
12326: "$topdir/scripts/techsmith-smart-player.min.js",
12327: "$topdir/skins/",
12328: "$topdir/skins/configuration_express.xml",
12329: "$topdir/skins/express_show/",
12330: "$topdir/skins/express_show/spritesheet.min.css",
12331: "$topdir/skins/express_show/spritesheet.png",
12332: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 12333: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 12334: if (@diffs == 0) {
1.1164 raeburn 12335: $is_camtasia = 6;
12336: } else {
1.1197 raeburn 12337: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 12338: if (@diffs == 0) {
12339: $is_camtasia = 8;
1.1197 raeburn 12340: } else {
12341: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
12342: if (@diffs == 0) {
12343: $is_camtasia = 8;
12344: }
1.1164 raeburn 12345: }
1.1067 raeburn 12346: }
12347: }
12348: my $output;
12349: if ($is_camtasia) {
12350: $output = <<"ENDCAM";
12351: <script type="text/javascript" language="Javascript">
12352: // <![CDATA[
12353:
12354: function camtasiaToggle() {
12355: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
12356: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 12357: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 12358: document.getElementById('camtasia_titles').style.display='block';
12359: } else {
12360: document.getElementById('camtasia_titles').style.display='none';
12361: }
12362: }
12363: }
12364: return;
12365: }
12366:
12367: // ]]>
12368: </script>
12369: <p>$lt{'camt'}</p>
12370: ENDCAM
1.1065 raeburn 12371: } else {
1.1067 raeburn 12372: $output = '<p>'.$lt{'this'};
12373: if ($info eq '') {
12374: $output .= ' '.$lt{'youm'}.'</p>'."\n";
12375: } else {
12376: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
12377: '<div><pre>'.$info.'</pre></div>';
12378: }
1.1065 raeburn 12379: }
1.1067 raeburn 12380: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 12381: my $duplicates;
12382: my $num = 0;
12383: if (ref($dirlist) eq 'ARRAY') {
12384: foreach my $item (@{$dirlist}) {
12385: if (ref($item) eq 'ARRAY') {
12386: if (exists($toplevel{$item->[0]})) {
12387: $duplicates .=
12388: &start_data_table_row().
12389: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
12390: 'value="0" checked="checked" />'.&mt('No').'</label>'.
12391: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
12392: 'value="1" />'.&mt('Yes').'</label>'.
12393: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
12394: '<td>'.$item->[0].'</td>';
12395: if ($item->[2]) {
12396: $duplicates .= '<td>'.&mt('Directory').'</td>';
12397: } else {
12398: $duplicates .= '<td>'.&mt('File').'</td>';
12399: }
12400: $duplicates .= '<td>'.$item->[3].'</td>'.
12401: '<td>'.
12402: &Apache::lonlocal::locallocaltime($item->[4]).
12403: '</td>'.
12404: &end_data_table_row();
12405: $num ++;
12406: }
12407: }
12408: }
12409: }
12410: my $itemcount;
12411: if (@paths > 0) {
12412: $itemcount = scalar(@paths);
12413: } else {
12414: $itemcount = 1;
12415: }
1.1067 raeburn 12416: if ($is_camtasia) {
12417: $output .= $lt{'auto'}.'<br />'.
12418: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 12419: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 12420: $lt{'yes'}.'</label> <label>'.
12421: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
12422: $lt{'no'}.'</label></span><br />'.
12423: '<div id="camtasia_titles" style="display:block">'.
12424: &Apache::lonhtmlcommon::start_pick_box().
12425: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
12426: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
12427: &Apache::lonhtmlcommon::row_closure().
12428: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
12429: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
12430: &Apache::lonhtmlcommon::row_closure(1).
12431: &Apache::lonhtmlcommon::end_pick_box().
12432: '</div>';
12433: }
1.1065 raeburn 12434: $output .=
12435: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 12436: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
12437: "\n";
1.1065 raeburn 12438: if ($duplicates ne '') {
12439: $output .= '<p><span class="LC_warning">'.
12440: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
12441: &start_data_table().
12442: &start_data_table_header_row().
12443: '<th>'.&mt('Overwrite?').'</th>'.
12444: '<th>'.&mt('Name').'</th>'.
12445: '<th>'.&mt('Type').'</th>'.
12446: '<th>'.&mt('Size').'</th>'.
12447: '<th>'.&mt('Last modified').'</th>'.
12448: &end_data_table_header_row().
12449: $duplicates.
12450: &end_data_table().
12451: '</p>';
12452: }
1.1067 raeburn 12453: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 12454: if (ref($hiddenelements) eq 'HASH') {
12455: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
12456: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
12457: }
12458: }
12459: $output .= <<"END";
1.1067 raeburn 12460: <br />
1.1053 raeburn 12461: <input type="submit" name="decompress" value="$lt{'extr'}" />
12462: </form>
12463: $noextract
12464: END
12465: return $output;
12466: }
12467:
1.1065 raeburn 12468: sub decompression_utility {
12469: my ($program) = @_;
12470: my @utilities = ('tar','gunzip','bunzip2','unzip');
12471: my $location;
12472: if (grep(/^\Q$program\E$/,@utilities)) {
12473: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
12474: '/usr/sbin/') {
12475: if (-x $dir.$program) {
12476: $location = $dir.$program;
12477: last;
12478: }
12479: }
12480: }
12481: return $location;
12482: }
12483:
12484: sub list_archive_contents {
12485: my ($file,$pathsref) = @_;
12486: my (@cmd,$output);
12487: my $needsregexp;
12488: if ($file =~ /\.zip$/) {
12489: @cmd = (&decompression_utility('unzip'),"-l");
12490: $needsregexp = 1;
12491: } elsif (($file =~ m/\.tar\.gz$/) ||
12492: ($file =~ /\.tgz$/)) {
12493: @cmd = (&decompression_utility('tar'),"-ztf");
12494: } elsif ($file =~ /\.tar\.bz2$/) {
12495: @cmd = (&decompression_utility('tar'),"-jtf");
12496: } elsif ($file =~ m|\.tar$|) {
12497: @cmd = (&decompression_utility('tar'),"-tf");
12498: }
12499: if (@cmd) {
12500: undef($!);
12501: undef($@);
12502: if (open(my $fh,"-|", @cmd, $file)) {
12503: while (my $line = <$fh>) {
12504: $output .= $line;
12505: chomp($line);
12506: my $item;
12507: if ($needsregexp) {
12508: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12509: } else {
12510: $item = $line;
12511: }
12512: if ($item ne '') {
12513: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12514: push(@{$pathsref},$item);
12515: }
12516: }
12517: }
12518: close($fh);
12519: }
12520: }
12521: return $output;
12522: }
12523:
1.1053 raeburn 12524: sub decompress_uploaded_file {
12525: my ($file,$dir) = @_;
12526: &Apache::lonnet::appenv({'cgi.file' => $file});
12527: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12528: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12529: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12530: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12531: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12532: my $decompressed = $env{'cgi.decompressed'};
12533: &Apache::lonnet::delenv('cgi.file');
12534: &Apache::lonnet::delenv('cgi.dir');
12535: &Apache::lonnet::delenv('cgi.decompressed');
12536: return ($decompressed,$result);
12537: }
12538:
1.1055 raeburn 12539: sub process_decompression {
12540: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
12541: my ($dir,$error,$warning,$output);
1.1180 raeburn 12542: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12543: $error = &mt('Filename not a supported archive file type.').
12544: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12545: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12546: } else {
12547: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12548: if ($docuhome eq 'no_host') {
12549: $error = &mt('Could not determine home server for course.');
12550: } else {
12551: my @ids=&Apache::lonnet::current_machine_ids();
12552: my $currdir = "$dir_root/$destination";
12553: if (grep(/^\Q$docuhome\E$/,@ids)) {
12554: $dir = &LONCAPA::propath($docudom,$docuname).
12555: "$dir_root/$destination";
12556: } else {
12557: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12558: "$dir_root/$docudom/$docuname/$destination";
12559: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12560: $error = &mt('Archive file not found.');
12561: }
12562: }
1.1065 raeburn 12563: my (@to_overwrite,@to_skip);
12564: if ($env{'form.archive_overwrite_total'} > 0) {
12565: my $total = $env{'form.archive_overwrite_total'};
12566: for (my $i=0; $i<$total; $i++) {
12567: if ($env{'form.archive_overwrite_'.$i} == 1) {
12568: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12569: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12570: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12571: }
12572: }
12573: }
12574: my $numskip = scalar(@to_skip);
12575: if (($numskip > 0) &&
12576: ($numskip == $env{'form.archive_itemcount'})) {
12577: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12578: } elsif ($dir eq '') {
1.1055 raeburn 12579: $error = &mt('Directory containing archive file unavailable.');
12580: } elsif (!$error) {
1.1065 raeburn 12581: my ($decompressed,$display);
12582: if ($numskip > 0) {
12583: my $tempdir = time.'_'.$$.int(rand(10000));
12584: mkdir("$dir/$tempdir",0755);
12585: system("mv $dir/$file $dir/$tempdir/$file");
12586: ($decompressed,$display) =
12587: &decompress_uploaded_file($file,"$dir/$tempdir");
12588: foreach my $item (@to_skip) {
12589: if (($item ne '') && ($item !~ /\.\./)) {
12590: if (-f "$dir/$tempdir/$item") {
12591: unlink("$dir/$tempdir/$item");
12592: } elsif (-d "$dir/$tempdir/$item") {
12593: system("rm -rf $dir/$tempdir/$item");
12594: }
12595: }
12596: }
12597: system("mv $dir/$tempdir/* $dir");
12598: rmdir("$dir/$tempdir");
12599: } else {
12600: ($decompressed,$display) =
12601: &decompress_uploaded_file($file,$dir);
12602: }
1.1055 raeburn 12603: if ($decompressed eq 'ok') {
1.1065 raeburn 12604: $output = '<p class="LC_info">'.
12605: &mt('Files extracted successfully from archive.').
12606: '</p>'."\n";
1.1055 raeburn 12607: my ($warning,$result,@contents);
12608: my ($newdirlistref,$newlisterror) =
12609: &Apache::lonnet::dirlist($currdir,$docudom,
12610: $docuname,1);
12611: my (%is_dir,%changes,@newitems);
12612: my $dirptr = 16384;
1.1065 raeburn 12613: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12614: foreach my $dir_line (@{$newdirlistref}) {
12615: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 12616: unless (($item =~ /^\.+$/) || ($item eq $file) ||
12617: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 12618: push(@newitems,$item);
12619: if ($dirptr&$testdir) {
12620: $is_dir{$item} = 1;
12621: }
12622: $changes{$item} = 1;
12623: }
12624: }
12625: }
12626: if (keys(%changes) > 0) {
12627: foreach my $item (sort(@newitems)) {
12628: if ($changes{$item}) {
12629: push(@contents,$item);
12630: }
12631: }
12632: }
12633: if (@contents > 0) {
1.1067 raeburn 12634: my $wantform;
12635: unless ($env{'form.autoextract_camtasia'}) {
12636: $wantform = 1;
12637: }
1.1056 raeburn 12638: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12639: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12640: $currdir,\%is_dir,
12641: \%children,\%parent,
1.1056 raeburn 12642: \@contents,\%dirorder,
12643: \%titles,$wantform);
1.1055 raeburn 12644: if ($datatable ne '') {
12645: $output .= &archive_options_form('decompressed',$datatable,
12646: $count,$hiddenelem);
1.1065 raeburn 12647: my $startcount = 6;
1.1055 raeburn 12648: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12649: \%titles,\%children);
1.1055 raeburn 12650: }
1.1067 raeburn 12651: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 12652: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12653: my %displayed;
12654: my $total = 1;
12655: $env{'form.archive_directory'} = [];
12656: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12657: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12658: $path =~ s{/$}{};
12659: my $item;
12660: if ($path ne '') {
12661: $item = "$path/$titles{$i}";
12662: } else {
12663: $item = $titles{$i};
12664: }
12665: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12666: if ($item eq $contents[0]) {
12667: push(@{$env{'form.archive_directory'}},$i);
12668: $env{'form.archive_'.$i} = 'display';
12669: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12670: $displayed{'folder'} = $i;
1.1164 raeburn 12671: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12672: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12673: $env{'form.archive_'.$i} = 'display';
12674: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12675: $displayed{'web'} = $i;
12676: } else {
1.1164 raeburn 12677: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12678: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12679: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12680: push(@{$env{'form.archive_directory'}},$i);
12681: }
12682: $env{'form.archive_'.$i} = 'dependency';
12683: }
12684: $total ++;
12685: }
12686: for (my $i=1; $i<$total; $i++) {
12687: next if ($i == $displayed{'web'});
12688: next if ($i == $displayed{'folder'});
12689: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12690: }
12691: $env{'form.phase'} = 'decompress_cleanup';
12692: $env{'form.archivedelete'} = 1;
12693: $env{'form.archive_count'} = $total-1;
12694: $output .=
12695: &process_extracted_files('coursedocs',$docudom,
12696: $docuname,$destination,
12697: $dir_root,$hiddenelem);
12698: }
1.1055 raeburn 12699: } else {
12700: $warning = &mt('No new items extracted from archive file.');
12701: }
12702: } else {
12703: $output = $display;
12704: $error = &mt('An error occurred during extraction from the archive file.');
12705: }
12706: }
12707: }
12708: }
12709: if ($error) {
12710: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12711: $error.'</p>'."\n";
12712: }
12713: if ($warning) {
12714: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12715: }
12716: return $output;
12717: }
12718:
12719: sub get_extracted {
1.1056 raeburn 12720: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12721: $titles,$wantform) = @_;
1.1055 raeburn 12722: my $count = 0;
12723: my $depth = 0;
12724: my $datatable;
1.1056 raeburn 12725: my @hierarchy;
1.1055 raeburn 12726: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12727: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12728: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12729: foreach my $item (@{$contents}) {
12730: $count ++;
1.1056 raeburn 12731: @{$dirorder->{$count}} = @hierarchy;
12732: $titles->{$count} = $item;
1.1055 raeburn 12733: &archive_hierarchy($depth,$count,$parent,$children);
12734: if ($wantform) {
12735: $datatable .= &archive_row($is_dir->{$item},$item,
12736: $currdir,$depth,$count);
12737: }
12738: if ($is_dir->{$item}) {
12739: $depth ++;
1.1056 raeburn 12740: push(@hierarchy,$count);
12741: $parent->{$depth} = $count;
1.1055 raeburn 12742: $datatable .=
12743: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12744: \$depth,\$count,\@hierarchy,$dirorder,
12745: $children,$parent,$titles,$wantform);
1.1055 raeburn 12746: $depth --;
1.1056 raeburn 12747: pop(@hierarchy);
1.1055 raeburn 12748: }
12749: }
12750: return ($count,$datatable);
12751: }
12752:
12753: sub recurse_extracted_archive {
1.1056 raeburn 12754: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12755: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12756: my $result='';
1.1056 raeburn 12757: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12758: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12759: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12760: return $result;
12761: }
12762: my $dirptr = 16384;
12763: my ($newdirlistref,$newlisterror) =
12764: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12765: if (ref($newdirlistref) eq 'ARRAY') {
12766: foreach my $dir_line (@{$newdirlistref}) {
12767: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12768: unless ($item =~ /^\.+$/) {
12769: $$count ++;
1.1056 raeburn 12770: @{$dirorder->{$$count}} = @{$hierarchy};
12771: $titles->{$$count} = $item;
1.1055 raeburn 12772: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12773:
1.1055 raeburn 12774: my $is_dir;
12775: if ($dirptr&$testdir) {
12776: $is_dir = 1;
12777: }
12778: if ($wantform) {
12779: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12780: }
12781: if ($is_dir) {
12782: $$depth ++;
1.1056 raeburn 12783: push(@{$hierarchy},$$count);
12784: $parent->{$$depth} = $$count;
1.1055 raeburn 12785: $result .=
12786: &recurse_extracted_archive("$currdir/$item",$docudom,
12787: $docuname,$depth,$count,
1.1056 raeburn 12788: $hierarchy,$dirorder,$children,
12789: $parent,$titles,$wantform);
1.1055 raeburn 12790: $$depth --;
1.1056 raeburn 12791: pop(@{$hierarchy});
1.1055 raeburn 12792: }
12793: }
12794: }
12795: }
12796: return $result;
12797: }
12798:
12799: sub archive_hierarchy {
12800: my ($depth,$count,$parent,$children) =@_;
12801: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12802: if (exists($parent->{$depth})) {
12803: $children->{$parent->{$depth}} .= $count.':';
12804: }
12805: }
12806: return;
12807: }
12808:
12809: sub archive_row {
12810: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12811: my ($name) = ($item =~ m{([^/]+)$});
12812: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12813: 'display' => 'Add as file',
1.1055 raeburn 12814: 'dependency' => 'Include as dependency',
12815: 'discard' => 'Discard',
12816: );
12817: if ($is_dir) {
1.1059 raeburn 12818: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12819: }
1.1056 raeburn 12820: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12821: my $offset = 0;
1.1055 raeburn 12822: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12823: $offset ++;
1.1065 raeburn 12824: if ($action ne 'display') {
12825: $offset ++;
12826: }
1.1055 raeburn 12827: $output .= '<td><span class="LC_nobreak">'.
12828: '<label><input type="radio" name="archive_'.$count.
12829: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12830: my $text = $choices{$action};
12831: if ($is_dir) {
12832: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12833: if ($action eq 'display') {
1.1059 raeburn 12834: $text = &mt('Add as folder');
1.1055 raeburn 12835: }
1.1056 raeburn 12836: } else {
12837: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12838:
12839: }
12840: $output .= ' /> '.$choices{$action}.'</label></span>';
12841: if ($action eq 'dependency') {
12842: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12843: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12844: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12845: '<option value=""></option>'."\n".
12846: '</select>'."\n".
12847: '</div>';
1.1059 raeburn 12848: } elsif ($action eq 'display') {
12849: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12850: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12851: '</div>';
1.1055 raeburn 12852: }
1.1056 raeburn 12853: $output .= '</td>';
1.1055 raeburn 12854: }
12855: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12856: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12857: for (my $i=0; $i<$depth; $i++) {
12858: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12859: }
12860: if ($is_dir) {
12861: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12862: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12863: } else {
12864: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12865: }
12866: $output .= ' '.$name.'</td>'."\n".
12867: &end_data_table_row();
12868: return $output;
12869: }
12870:
12871: sub archive_options_form {
1.1065 raeburn 12872: my ($form,$display,$count,$hiddenelem) = @_;
12873: my %lt = &Apache::lonlocal::texthash(
12874: perm => 'Permanently remove archive file?',
12875: hows => 'How should each extracted item be incorporated in the course?',
12876: cont => 'Content actions for all',
12877: addf => 'Add as folder/file',
12878: incd => 'Include as dependency for a displayed file',
12879: disc => 'Discard',
12880: no => 'No',
12881: yes => 'Yes',
12882: save => 'Save',
12883: );
12884: my $output = <<"END";
12885: <form name="$form" method="post" action="">
12886: <p><span class="LC_nobreak">$lt{'perm'}
12887: <label>
12888: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12889: </label>
12890:
12891: <label>
12892: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12893: </span>
12894: </p>
12895: <input type="hidden" name="phase" value="decompress_cleanup" />
12896: <br />$lt{'hows'}
12897: <div class="LC_columnSection">
12898: <fieldset>
12899: <legend>$lt{'cont'}</legend>
12900: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12901: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12902: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12903: </fieldset>
12904: </div>
12905: END
12906: return $output.
1.1055 raeburn 12907: &start_data_table()."\n".
1.1065 raeburn 12908: $display."\n".
1.1055 raeburn 12909: &end_data_table()."\n".
12910: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12911: $hiddenelem.
1.1065 raeburn 12912: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12913: '</form>';
12914: }
12915:
12916: sub archive_javascript {
1.1056 raeburn 12917: my ($startcount,$numitems,$titles,$children) = @_;
12918: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12919: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12920: my $scripttag = <<START;
12921: <script type="text/javascript">
12922: // <![CDATA[
12923:
12924: function checkAll(form,prefix) {
12925: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12926: for (var i=0; i < form.elements.length; i++) {
12927: var id = form.elements[i].id;
12928: if ((id != '') && (id != undefined)) {
12929: if (idstr.test(id)) {
12930: if (form.elements[i].type == 'radio') {
12931: form.elements[i].checked = true;
1.1056 raeburn 12932: var nostart = i-$startcount;
1.1059 raeburn 12933: var offset = nostart%7;
12934: var count = (nostart-offset)/7;
1.1056 raeburn 12935: dependencyCheck(form,count,offset);
1.1055 raeburn 12936: }
12937: }
12938: }
12939: }
12940: }
12941:
12942: function propagateCheck(form,count) {
12943: if (count > 0) {
1.1059 raeburn 12944: var startelement = $startcount + ((count-1) * 7);
12945: for (var j=1; j<6; j++) {
12946: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12947: var item = startelement + j;
12948: if (form.elements[item].type == 'radio') {
12949: if (form.elements[item].checked) {
12950: containerCheck(form,count,j);
12951: break;
12952: }
1.1055 raeburn 12953: }
12954: }
12955: }
12956: }
12957: }
12958:
12959: numitems = $numitems
1.1056 raeburn 12960: var titles = new Array(numitems);
12961: var parents = new Array(numitems);
1.1055 raeburn 12962: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12963: parents[i] = new Array;
1.1055 raeburn 12964: }
1.1059 raeburn 12965: var maintitle = '$maintitle';
1.1055 raeburn 12966:
12967: START
12968:
1.1056 raeburn 12969: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12970: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12971: for (my $i=0; $i<@contents; $i ++) {
12972: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12973: }
12974: }
12975:
1.1056 raeburn 12976: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12977: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12978: }
12979:
1.1055 raeburn 12980: $scripttag .= <<END;
12981:
12982: function containerCheck(form,count,offset) {
12983: if (count > 0) {
1.1056 raeburn 12984: dependencyCheck(form,count,offset);
1.1059 raeburn 12985: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12986: form.elements[item].checked = true;
12987: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12988: if (parents[count].length > 0) {
12989: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12990: containerCheck(form,parents[count][j],offset);
12991: }
12992: }
12993: }
12994: }
12995: }
12996:
12997: function dependencyCheck(form,count,offset) {
12998: if (count > 0) {
1.1059 raeburn 12999: var chosen = (offset+$startcount)+7*(count-1);
13000: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 13001: var currtype = form.elements[depitem].type;
13002: if (form.elements[chosen].value == 'dependency') {
13003: document.getElementById('arc_depon_'+count).style.display='block';
13004: form.elements[depitem].options.length = 0;
13005: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 13006: for (var i=1; i<=numitems; i++) {
13007: if (i == count) {
13008: continue;
13009: }
1.1059 raeburn 13010: var startelement = $startcount + (i-1) * 7;
13011: for (var j=1; j<6; j++) {
13012: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 13013: var item = startelement + j;
13014: if (form.elements[item].type == 'radio') {
13015: if (form.elements[item].checked) {
13016: if (form.elements[item].value == 'display') {
13017: var n = form.elements[depitem].options.length;
13018: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
13019: }
13020: }
13021: }
13022: }
13023: }
13024: }
13025: } else {
13026: document.getElementById('arc_depon_'+count).style.display='none';
13027: form.elements[depitem].options.length = 0;
13028: form.elements[depitem].options[0] = new Option('Select','',true,true);
13029: }
1.1059 raeburn 13030: titleCheck(form,count,offset);
1.1056 raeburn 13031: }
13032: }
13033:
13034: function propagateSelect(form,count,offset) {
13035: if (count > 0) {
1.1065 raeburn 13036: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 13037: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
13038: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13039: if (parents[count].length > 0) {
13040: for (var j=0; j<parents[count].length; j++) {
13041: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 13042: }
13043: }
13044: }
13045: }
13046: }
1.1056 raeburn 13047:
13048: function containerSelect(form,count,offset,picked) {
13049: if (count > 0) {
1.1065 raeburn 13050: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 13051: if (form.elements[item].type == 'radio') {
13052: if (form.elements[item].value == 'dependency') {
13053: if (form.elements[item+1].type == 'select-one') {
13054: for (var i=0; i<form.elements[item+1].options.length; i++) {
13055: if (form.elements[item+1].options[i].value == picked) {
13056: form.elements[item+1].selectedIndex = i;
13057: break;
13058: }
13059: }
13060: }
13061: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
13062: if (parents[count].length > 0) {
13063: for (var j=0; j<parents[count].length; j++) {
13064: containerSelect(form,parents[count][j],offset,picked);
13065: }
13066: }
13067: }
13068: }
13069: }
13070: }
13071: }
13072:
1.1059 raeburn 13073: function titleCheck(form,count,offset) {
13074: if (count > 0) {
13075: var chosen = (offset+$startcount)+7*(count-1);
13076: var depitem = $startcount + ((count-1) * 7) + 2;
13077: var currtype = form.elements[depitem].type;
13078: if (form.elements[chosen].value == 'display') {
13079: document.getElementById('arc_title_'+count).style.display='block';
13080: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
13081: document.getElementById('archive_title_'+count).value=maintitle;
13082: }
13083: } else {
13084: document.getElementById('arc_title_'+count).style.display='none';
13085: if (currtype == 'text') {
13086: document.getElementById('archive_title_'+count).value='';
13087: }
13088: }
13089: }
13090: return;
13091: }
13092:
1.1055 raeburn 13093: // ]]>
13094: </script>
13095: END
13096: return $scripttag;
13097: }
13098:
13099: sub process_extracted_files {
1.1067 raeburn 13100: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 13101: my $numitems = $env{'form.archive_count'};
13102: return unless ($numitems);
13103: my @ids=&Apache::lonnet::current_machine_ids();
13104: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 13105: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 13106: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
13107: if (grep(/^\Q$docuhome\E$/,@ids)) {
13108: $prefix = &LONCAPA::propath($docudom,$docuname);
13109: $pathtocheck = "$dir_root/$destination";
13110: $dir = $dir_root;
13111: $ishome = 1;
13112: } else {
13113: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
13114: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
13115: $dir = "$dir_root/$docudom/$docuname";
13116: }
13117: my $currdir = "$dir_root/$destination";
13118: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
13119: if ($env{'form.folderpath'}) {
13120: my @items = split('&',$env{'form.folderpath'});
13121: $folders{'0'} = $items[-2];
1.1099 raeburn 13122: if ($env{'form.folderpath'} =~ /\:1$/) {
13123: $containers{'0'}='page';
13124: } else {
13125: $containers{'0'}='sequence';
13126: }
1.1055 raeburn 13127: }
13128: my @archdirs = &get_env_multiple('form.archive_directory');
13129: if ($numitems) {
13130: for (my $i=1; $i<=$numitems; $i++) {
13131: my $path = $env{'form.archive_content_'.$i};
13132: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
13133: my $item = $1;
13134: $toplevelitems{$item} = $i;
13135: if (grep(/^\Q$i\E$/,@archdirs)) {
13136: $is_dir{$item} = 1;
13137: }
13138: }
13139: }
13140: }
1.1067 raeburn 13141: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 13142: if (keys(%toplevelitems) > 0) {
13143: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 13144: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
13145: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 13146: }
1.1066 raeburn 13147: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 13148: if ($numitems) {
13149: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 13150: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 13151: my $path = $env{'form.archive_content_'.$i};
13152: if ($path =~ /^\Q$pathtocheck\E/) {
13153: if ($env{'form.archive_'.$i} eq 'discard') {
13154: if ($prefix ne '' && $path ne '') {
13155: if (-e $prefix.$path) {
1.1066 raeburn 13156: if ((@archdirs > 0) &&
13157: (grep(/^\Q$i\E$/,@archdirs))) {
13158: $todeletedir{$prefix.$path} = 1;
13159: } else {
13160: $todelete{$prefix.$path} = 1;
13161: }
1.1055 raeburn 13162: }
13163: }
13164: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 13165: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 13166: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 13167: $docstitle = $env{'form.archive_title_'.$i};
13168: if ($docstitle eq '') {
13169: $docstitle = $title;
13170: }
1.1055 raeburn 13171: $outer = 0;
1.1056 raeburn 13172: if (ref($dirorder{$i}) eq 'ARRAY') {
13173: if (@{$dirorder{$i}} > 0) {
13174: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 13175: if ($env{'form.archive_'.$item} eq 'display') {
13176: $outer = $item;
13177: last;
13178: }
13179: }
13180: }
13181: }
13182: my ($errtext,$fatal) =
13183: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
13184: '/'.$folders{$outer}.'.'.
13185: $containers{$outer});
13186: next if ($fatal);
13187: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
13188: if ($context eq 'coursedocs') {
1.1056 raeburn 13189: $mapinner{$i} = time;
1.1055 raeburn 13190: $folders{$i} = 'default_'.$mapinner{$i};
13191: $containers{$i} = 'sequence';
13192: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13193: $folders{$i}.'.'.$containers{$i};
13194: my $newidx = &LONCAPA::map::getresidx();
13195: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13196: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13197: push(@LONCAPA::map::order,$newidx);
13198: my ($outtext,$errtext) =
13199: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13200: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13201: '.'.$containers{$outer},1,1);
1.1056 raeburn 13202: $newseqid{$i} = $newidx;
1.1067 raeburn 13203: unless ($errtext) {
13204: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
13205: }
1.1055 raeburn 13206: }
13207: } else {
13208: if ($context eq 'coursedocs') {
13209: my $newidx=&LONCAPA::map::getresidx();
13210: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
13211: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
13212: $title;
13213: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
13214: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
13215: }
13216: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13217: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
13218: }
13219: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
13220: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 13221: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 13222: unless ($ishome) {
13223: my $fetch = "$newdest{$i}/$title";
13224: $fetch =~ s/^\Q$prefix$dir\E//;
13225: $prompttofetch{$fetch} = 1;
13226: }
1.1055 raeburn 13227: }
13228: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 13229: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 13230: push(@LONCAPA::map::order, $newidx);
13231: my ($outtext,$errtext)=
13232: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
13233: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 13234: '.'.$containers{$outer},1,1);
1.1067 raeburn 13235: unless ($errtext) {
13236: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
13237: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
13238: }
13239: }
1.1055 raeburn 13240: }
13241: }
1.1086 raeburn 13242: }
13243: } else {
13244: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
13245: }
13246: }
13247: for (my $i=1; $i<=$numitems; $i++) {
13248: next unless ($env{'form.archive_'.$i} eq 'dependency');
13249: my $path = $env{'form.archive_content_'.$i};
13250: if ($path =~ /^\Q$pathtocheck\E/) {
13251: my ($title) = ($path =~ m{/([^/]+)$});
13252: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
13253: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
13254: if (ref($dirorder{$i}) eq 'ARRAY') {
13255: my ($itemidx,$fullpath,$relpath);
13256: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
13257: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 13258: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 13259: if ($dirorder{$i}->[$j] eq $container) {
13260: $itemidx = $j;
1.1056 raeburn 13261: }
13262: }
1.1086 raeburn 13263: }
13264: if ($itemidx eq '') {
13265: $itemidx = 0;
13266: }
13267: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
13268: if ($mapinner{$referrer{$i}}) {
13269: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
13270: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13271: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13272: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13273: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13274: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13275: if (!-e $fullpath) {
13276: mkdir($fullpath,0755);
1.1056 raeburn 13277: }
13278: }
1.1086 raeburn 13279: } else {
13280: last;
1.1056 raeburn 13281: }
1.1086 raeburn 13282: }
13283: }
13284: } elsif ($newdest{$referrer{$i}}) {
13285: $fullpath = $newdest{$referrer{$i}};
13286: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
13287: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
13288: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
13289: last;
13290: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
13291: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
13292: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
13293: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
13294: if (!-e $fullpath) {
13295: mkdir($fullpath,0755);
1.1056 raeburn 13296: }
13297: }
1.1086 raeburn 13298: } else {
13299: last;
1.1056 raeburn 13300: }
1.1055 raeburn 13301: }
13302: }
1.1086 raeburn 13303: if ($fullpath ne '') {
13304: if (-e "$prefix$path") {
13305: system("mv $prefix$path $fullpath/$title");
13306: }
13307: if (-e "$fullpath/$title") {
13308: my $showpath;
13309: if ($relpath ne '') {
13310: $showpath = "$relpath/$title";
13311: } else {
13312: $showpath = "/$title";
13313: }
13314: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
13315: }
13316: unless ($ishome) {
13317: my $fetch = "$fullpath/$title";
13318: $fetch =~ s/^\Q$prefix$dir\E//;
13319: $prompttofetch{$fetch} = 1;
13320: }
13321: }
1.1055 raeburn 13322: }
1.1086 raeburn 13323: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
13324: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
13325: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 13326: }
13327: } else {
13328: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
13329: }
13330: }
13331: if (keys(%todelete)) {
13332: foreach my $key (keys(%todelete)) {
13333: unlink($key);
1.1066 raeburn 13334: }
13335: }
13336: if (keys(%todeletedir)) {
13337: foreach my $key (keys(%todeletedir)) {
13338: rmdir($key);
13339: }
13340: }
13341: foreach my $dir (sort(keys(%is_dir))) {
13342: if (($pathtocheck ne '') && ($dir ne '')) {
13343: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 13344: }
13345: }
1.1067 raeburn 13346: if ($result ne '') {
13347: $output .= '<ul>'."\n".
13348: $result."\n".
13349: '</ul>';
13350: }
13351: unless ($ishome) {
13352: my $replicationfail;
13353: foreach my $item (keys(%prompttofetch)) {
13354: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
13355: unless ($fetchresult eq 'ok') {
13356: $replicationfail .= '<li>'.$item.'</li>'."\n";
13357: }
13358: }
13359: if ($replicationfail) {
13360: $output .= '<p class="LC_error">'.
13361: &mt('Course home server failed to retrieve:').'<ul>'.
13362: $replicationfail.
13363: '</ul></p>';
13364: }
13365: }
1.1055 raeburn 13366: } else {
13367: $warning = &mt('No items found in archive.');
13368: }
13369: if ($error) {
13370: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
13371: $error.'</p>'."\n";
13372: }
13373: if ($warning) {
13374: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
13375: }
13376: return $output;
13377: }
13378:
1.1066 raeburn 13379: sub cleanup_empty_dirs {
13380: my ($path) = @_;
13381: if (($path ne '') && (-d $path)) {
13382: if (opendir(my $dirh,$path)) {
13383: my @dircontents = grep(!/^\./,readdir($dirh));
13384: my $numitems = 0;
13385: foreach my $item (@dircontents) {
13386: if (-d "$path/$item") {
1.1111 raeburn 13387: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 13388: if (-e "$path/$item") {
13389: $numitems ++;
13390: }
13391: } else {
13392: $numitems ++;
13393: }
13394: }
13395: if ($numitems == 0) {
13396: rmdir($path);
13397: }
13398: closedir($dirh);
13399: }
13400: }
13401: return;
13402: }
13403:
1.41 ng 13404: =pod
1.45 matthew 13405:
1.1162 raeburn 13406: =item * &get_folder_hierarchy()
1.1068 raeburn 13407:
13408: Provides hierarchy of names of folders/sub-folders containing the current
13409: item,
13410:
13411: Inputs: 3
13412: - $navmap - navmaps object
13413:
13414: - $map - url for map (either the trigger itself, or map containing
13415: the resource, which is the trigger).
13416:
13417: - $showitem - 1 => show title for map itself; 0 => do not show.
13418:
13419: Outputs: 1 @pathitems - array of folder/subfolder names.
13420:
13421: =cut
13422:
13423: sub get_folder_hierarchy {
13424: my ($navmap,$map,$showitem) = @_;
13425: my @pathitems;
13426: if (ref($navmap)) {
13427: my $mapres = $navmap->getResourceByUrl($map);
13428: if (ref($mapres)) {
13429: my $pcslist = $mapres->map_hierarchy();
13430: if ($pcslist ne '') {
13431: my @pcs = split(/,/,$pcslist);
13432: foreach my $pc (@pcs) {
13433: if ($pc == 1) {
1.1129 raeburn 13434: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 13435: } else {
13436: my $res = $navmap->getByMapPc($pc);
13437: if (ref($res)) {
13438: my $title = $res->compTitle();
13439: $title =~ s/\W+/_/g;
13440: if ($title ne '') {
13441: push(@pathitems,$title);
13442: }
13443: }
13444: }
13445: }
13446: }
1.1071 raeburn 13447: if ($showitem) {
13448: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 13449: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 13450: } else {
13451: my $maptitle = $mapres->compTitle();
13452: $maptitle =~ s/\W+/_/g;
13453: if ($maptitle ne '') {
13454: push(@pathitems,$maptitle);
13455: }
1.1068 raeburn 13456: }
13457: }
13458: }
13459: }
13460: return @pathitems;
13461: }
13462:
13463: =pod
13464:
1.1015 raeburn 13465: =item * &get_turnedin_filepath()
13466:
13467: Determines path in a user's portfolio file for storage of files uploaded
13468: to a specific essayresponse or dropbox item.
13469:
13470: Inputs: 3 required + 1 optional.
13471: $symb is symb for resource, $uname and $udom are for current user (required).
13472: $caller is optional (can be "submission", if routine is called when storing
13473: an upoaded file when "Submit Answer" button was pressed).
13474:
13475: Returns array containing $path and $multiresp.
13476: $path is path in portfolio. $multiresp is 1 if this resource contains more
13477: than one file upload item. Callers of routine should append partid as a
13478: subdirectory to $path in cases where $multiresp is 1.
13479:
13480: Called by: homework/essayresponse.pm and homework/structuretags.pm
13481:
13482: =cut
13483:
13484: sub get_turnedin_filepath {
13485: my ($symb,$uname,$udom,$caller) = @_;
13486: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13487: my $turnindir;
13488: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13489: $turnindir = $userhash{'turnindir'};
13490: my ($path,$multiresp);
13491: if ($turnindir eq '') {
13492: if ($caller eq 'submission') {
13493: $turnindir = &mt('turned in');
13494: $turnindir =~ s/\W+/_/g;
13495: my %newhash = (
13496: 'turnindir' => $turnindir,
13497: );
13498: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13499: }
13500: }
13501: if ($turnindir ne '') {
13502: $path = '/'.$turnindir.'/';
13503: my ($multipart,$turnin,@pathitems);
13504: my $navmap = Apache::lonnavmaps::navmap->new();
13505: if (defined($navmap)) {
13506: my $mapres = $navmap->getResourceByUrl($map);
13507: if (ref($mapres)) {
13508: my $pcslist = $mapres->map_hierarchy();
13509: if ($pcslist ne '') {
13510: foreach my $pc (split(/,/,$pcslist)) {
13511: my $res = $navmap->getByMapPc($pc);
13512: if (ref($res)) {
13513: my $title = $res->compTitle();
13514: $title =~ s/\W+/_/g;
13515: if ($title ne '') {
1.1149 raeburn 13516: if (($pc > 1) && (length($title) > 12)) {
13517: $title = substr($title,0,12);
13518: }
1.1015 raeburn 13519: push(@pathitems,$title);
13520: }
13521: }
13522: }
13523: }
13524: my $maptitle = $mapres->compTitle();
13525: $maptitle =~ s/\W+/_/g;
13526: if ($maptitle ne '') {
1.1149 raeburn 13527: if (length($maptitle) > 12) {
13528: $maptitle = substr($maptitle,0,12);
13529: }
1.1015 raeburn 13530: push(@pathitems,$maptitle);
13531: }
13532: unless ($env{'request.state'} eq 'construct') {
13533: my $res = $navmap->getBySymb($symb);
13534: if (ref($res)) {
13535: my $partlist = $res->parts();
13536: my $totaluploads = 0;
13537: if (ref($partlist) eq 'ARRAY') {
13538: foreach my $part (@{$partlist}) {
13539: my @types = $res->responseType($part);
13540: my @ids = $res->responseIds($part);
13541: for (my $i=0; $i < scalar(@ids); $i++) {
13542: if ($types[$i] eq 'essay') {
13543: my $partid = $part.'_'.$ids[$i];
13544: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13545: $totaluploads ++;
13546: }
13547: }
13548: }
13549: }
13550: if ($totaluploads > 1) {
13551: $multiresp = 1;
13552: }
13553: }
13554: }
13555: }
13556: } else {
13557: return;
13558: }
13559: } else {
13560: return;
13561: }
13562: my $restitle=&Apache::lonnet::gettitle($symb);
13563: $restitle =~ s/\W+/_/g;
13564: if ($restitle eq '') {
13565: $restitle = ($resurl =~ m{/[^/]+$});
13566: if ($restitle eq '') {
13567: $restitle = time;
13568: }
13569: }
1.1149 raeburn 13570: if (length($restitle) > 12) {
13571: $restitle = substr($restitle,0,12);
13572: }
1.1015 raeburn 13573: push(@pathitems,$restitle);
13574: $path .= join('/',@pathitems);
13575: }
13576: return ($path,$multiresp);
13577: }
13578:
13579: =pod
13580:
1.464 albertel 13581: =back
1.41 ng 13582:
1.112 bowersj2 13583: =head1 CSV Upload/Handling functions
1.38 albertel 13584:
1.41 ng 13585: =over 4
13586:
1.648 raeburn 13587: =item * &upfile_store($r)
1.41 ng 13588:
13589: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13590: needs $env{'form.upfile'}
1.41 ng 13591: returns $datatoken to be put into hidden field
13592:
13593: =cut
1.31 albertel 13594:
13595: sub upfile_store {
13596: my $r=shift;
1.258 albertel 13597: $env{'form.upfile'}=~s/\r/\n/gs;
13598: $env{'form.upfile'}=~s/\f/\n/gs;
13599: $env{'form.upfile'}=~s/\n+/\n/gs;
13600: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13601:
1.258 albertel 13602: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
13603: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 13604: {
1.158 raeburn 13605: my $datafile = $r->dir_config('lonDaemons').
13606: '/tmp/'.$datatoken.'.tmp';
13607: if ( open(my $fh,">$datafile") ) {
1.258 albertel 13608: print $fh $env{'form.upfile'};
1.158 raeburn 13609: close($fh);
13610: }
1.31 albertel 13611: }
13612: return $datatoken;
13613: }
13614:
1.56 matthew 13615: =pod
13616:
1.648 raeburn 13617: =item * &load_tmp_file($r)
1.41 ng 13618:
13619: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 13620: needs $env{'form.datatoken'},
13621: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13622:
13623: =cut
1.31 albertel 13624:
13625: sub load_tmp_file {
13626: my $r=shift;
13627: my @studentdata=();
13628: {
1.158 raeburn 13629: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 13630: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 13631: if ( open(my $fh,"<$studentfile") ) {
13632: @studentdata=<$fh>;
13633: close($fh);
13634: }
1.31 albertel 13635: }
1.258 albertel 13636: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13637: }
13638:
1.56 matthew 13639: =pod
13640:
1.648 raeburn 13641: =item * &upfile_record_sep()
1.41 ng 13642:
13643: Separate uploaded file into records
13644: returns array of records,
1.258 albertel 13645: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13646:
13647: =cut
1.31 albertel 13648:
13649: sub upfile_record_sep {
1.258 albertel 13650: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13651: } else {
1.248 albertel 13652: my @records;
1.258 albertel 13653: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13654: if ($line=~/^\s*$/) { next; }
13655: push(@records,$line);
13656: }
13657: return @records;
1.31 albertel 13658: }
13659: }
13660:
1.56 matthew 13661: =pod
13662:
1.648 raeburn 13663: =item * &record_sep($record)
1.41 ng 13664:
1.258 albertel 13665: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13666:
13667: =cut
13668:
1.263 www 13669: sub takeleft {
13670: my $index=shift;
13671: return substr('0000'.$index,-4,4);
13672: }
13673:
1.31 albertel 13674: sub record_sep {
13675: my $record=shift;
13676: my %components=();
1.258 albertel 13677: if ($env{'form.upfiletype'} eq 'xml') {
13678: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13679: my $i=0;
1.356 albertel 13680: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13681: $field=~s/^(\"|\')//;
13682: $field=~s/(\"|\')$//;
1.263 www 13683: $components{&takeleft($i)}=$field;
1.31 albertel 13684: $i++;
13685: }
1.258 albertel 13686: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13687: my $i=0;
1.356 albertel 13688: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13689: $field=~s/^(\"|\')//;
13690: $field=~s/(\"|\')$//;
1.263 www 13691: $components{&takeleft($i)}=$field;
1.31 albertel 13692: $i++;
13693: }
13694: } else {
1.561 www 13695: my $separator=',';
1.480 banghart 13696: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13697: $separator=';';
1.480 banghart 13698: }
1.31 albertel 13699: my $i=0;
1.561 www 13700: # the character we are looking for to indicate the end of a quote or a record
13701: my $looking_for=$separator;
13702: # do not add the characters to the fields
13703: my $ignore=0;
13704: # we just encountered a separator (or the beginning of the record)
13705: my $just_found_separator=1;
13706: # store the field we are working on here
13707: my $field='';
13708: # work our way through all characters in record
13709: foreach my $character ($record=~/(.)/g) {
13710: if ($character eq $looking_for) {
13711: if ($character ne $separator) {
13712: # Found the end of a quote, again looking for separator
13713: $looking_for=$separator;
13714: $ignore=1;
13715: } else {
13716: # Found a separator, store away what we got
13717: $components{&takeleft($i)}=$field;
13718: $i++;
13719: $just_found_separator=1;
13720: $ignore=0;
13721: $field='';
13722: }
13723: next;
13724: }
13725: # single or double quotation marks after a separator indicate beginning of a quote
13726: # we are now looking for the end of the quote and need to ignore separators
13727: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13728: $looking_for=$character;
13729: next;
13730: }
13731: # ignore would be true after we reached the end of a quote
13732: if ($ignore) { next; }
13733: if (($just_found_separator) && ($character=~/\s/)) { next; }
13734: $field.=$character;
13735: $just_found_separator=0;
1.31 albertel 13736: }
1.561 www 13737: # catch the very last entry, since we never encountered the separator
13738: $components{&takeleft($i)}=$field;
1.31 albertel 13739: }
13740: return %components;
13741: }
13742:
1.144 matthew 13743: ######################################################
13744: ######################################################
13745:
1.56 matthew 13746: =pod
13747:
1.648 raeburn 13748: =item * &upfile_select_html()
1.41 ng 13749:
1.144 matthew 13750: Return HTML code to select a file from the users machine and specify
13751: the file type.
1.41 ng 13752:
13753: =cut
13754:
1.144 matthew 13755: ######################################################
13756: ######################################################
1.31 albertel 13757: sub upfile_select_html {
1.144 matthew 13758: my %Types = (
13759: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13760: semisv => &mt('Semicolon separated values'),
1.144 matthew 13761: space => &mt('Space separated'),
13762: tab => &mt('Tabulator separated'),
13763: # xml => &mt('HTML/XML'),
13764: );
13765: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13766: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13767: foreach my $type (sort(keys(%Types))) {
13768: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13769: }
13770: $Str .= "</select>\n";
13771: return $Str;
1.31 albertel 13772: }
13773:
1.301 albertel 13774: sub get_samples {
13775: my ($records,$toget) = @_;
13776: my @samples=({});
13777: my $got=0;
13778: foreach my $rec (@$records) {
13779: my %temp = &record_sep($rec);
13780: if (! grep(/\S/, values(%temp))) { next; }
13781: if (%temp) {
13782: $samples[$got]=\%temp;
13783: $got++;
13784: if ($got == $toget) { last; }
13785: }
13786: }
13787: return \@samples;
13788: }
13789:
1.144 matthew 13790: ######################################################
13791: ######################################################
13792:
1.56 matthew 13793: =pod
13794:
1.648 raeburn 13795: =item * &csv_print_samples($r,$records)
1.41 ng 13796:
13797: Prints a table of sample values from each column uploaded $r is an
13798: Apache Request ref, $records is an arrayref from
13799: &Apache::loncommon::upfile_record_sep
13800:
13801: =cut
13802:
1.144 matthew 13803: ######################################################
13804: ######################################################
1.31 albertel 13805: sub csv_print_samples {
13806: my ($r,$records) = @_;
1.662 bisitz 13807: my $samples = &get_samples($records,5);
1.301 albertel 13808:
1.594 raeburn 13809: $r->print(&mt('Samples').'<br />'.&start_data_table().
13810: &start_data_table_header_row());
1.356 albertel 13811: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13812: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13813: $r->print(&end_data_table_header_row());
1.301 albertel 13814: foreach my $hash (@$samples) {
1.594 raeburn 13815: $r->print(&start_data_table_row());
1.356 albertel 13816: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13817: $r->print('<td>');
1.356 albertel 13818: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13819: $r->print('</td>');
13820: }
1.594 raeburn 13821: $r->print(&end_data_table_row());
1.31 albertel 13822: }
1.594 raeburn 13823: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13824: }
13825:
1.144 matthew 13826: ######################################################
13827: ######################################################
13828:
1.56 matthew 13829: =pod
13830:
1.648 raeburn 13831: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13832:
13833: Prints a table to create associations between values and table columns.
1.144 matthew 13834:
1.41 ng 13835: $r is an Apache Request ref,
13836: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13837: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13838:
13839: =cut
13840:
1.144 matthew 13841: ######################################################
13842: ######################################################
1.31 albertel 13843: sub csv_print_select_table {
13844: my ($r,$records,$d) = @_;
1.301 albertel 13845: my $i=0;
13846: my $samples = &get_samples($records,1);
1.144 matthew 13847: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13848: &start_data_table().&start_data_table_header_row().
1.144 matthew 13849: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13850: '<th>'.&mt('Column').'</th>'.
13851: &end_data_table_header_row()."\n");
1.356 albertel 13852: foreach my $array_ref (@$d) {
13853: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13854: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13855:
1.875 bisitz 13856: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13857: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13858: $r->print('<option value="none"></option>');
1.356 albertel 13859: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13860: $r->print('<option value="'.$sample.'"'.
13861: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13862: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13863: }
1.594 raeburn 13864: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13865: $i++;
13866: }
1.594 raeburn 13867: $r->print(&end_data_table());
1.31 albertel 13868: $i--;
13869: return $i;
13870: }
1.56 matthew 13871:
1.144 matthew 13872: ######################################################
13873: ######################################################
13874:
1.56 matthew 13875: =pod
1.31 albertel 13876:
1.648 raeburn 13877: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13878:
13879: Prints a table of sample values from the upload and can make associate samples to internal names.
13880:
13881: $r is an Apache Request ref,
13882: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13883: $d is an array of 2 element arrays (internal name, displayed name)
13884:
13885: =cut
13886:
1.144 matthew 13887: ######################################################
13888: ######################################################
1.31 albertel 13889: sub csv_samples_select_table {
13890: my ($r,$records,$d) = @_;
13891: my $i=0;
1.144 matthew 13892: #
1.662 bisitz 13893: my $max_samples = 5;
13894: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13895: $r->print(&start_data_table().
13896: &start_data_table_header_row().'<th>'.
13897: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13898: &end_data_table_header_row());
1.301 albertel 13899:
13900: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13901: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13902: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13903: foreach my $option (@$d) {
13904: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13905: $r->print('<option value="'.$value.'"'.
1.253 albertel 13906: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13907: $display.'</option>');
1.31 albertel 13908: }
13909: $r->print('</select></td><td>');
1.662 bisitz 13910: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13911: if (defined($samples->[$line]{$key})) {
13912: $r->print($samples->[$line]{$key}."<br />\n");
13913: }
13914: }
1.594 raeburn 13915: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13916: $i++;
13917: }
1.594 raeburn 13918: $r->print(&end_data_table());
1.31 albertel 13919: $i--;
13920: return($i);
1.115 matthew 13921: }
13922:
1.144 matthew 13923: ######################################################
13924: ######################################################
13925:
1.115 matthew 13926: =pod
13927:
1.648 raeburn 13928: =item * &clean_excel_name($name)
1.115 matthew 13929:
13930: Returns a replacement for $name which does not contain any illegal characters.
13931:
13932: =cut
13933:
1.144 matthew 13934: ######################################################
13935: ######################################################
1.115 matthew 13936: sub clean_excel_name {
13937: my ($name) = @_;
13938: $name =~ s/[:\*\?\/\\]//g;
13939: if (length($name) > 31) {
13940: $name = substr($name,0,31);
13941: }
13942: return $name;
1.25 albertel 13943: }
1.84 albertel 13944:
1.85 albertel 13945: =pod
13946:
1.648 raeburn 13947: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13948:
13949: Returns either 1 or undef
13950:
13951: 1 if the part is to be hidden, undef if it is to be shown
13952:
13953: Arguments are:
13954:
13955: $id the id of the part to be checked
13956: $symb, optional the symb of the resource to check
13957: $udom, optional the domain of the user to check for
13958: $uname, optional the username of the user to check for
13959:
13960: =cut
1.84 albertel 13961:
13962: sub check_if_partid_hidden {
13963: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13964: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13965: $symb,$udom,$uname);
1.141 albertel 13966: my $truth=1;
13967: #if the string starts with !, then the list is the list to show not hide
13968: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13969: my @hiddenlist=split(/,/,$hiddenparts);
13970: foreach my $checkid (@hiddenlist) {
1.141 albertel 13971: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13972: }
1.141 albertel 13973: return !$truth;
1.84 albertel 13974: }
1.127 matthew 13975:
1.138 matthew 13976:
13977: ############################################################
13978: ############################################################
13979:
13980: =pod
13981:
1.157 matthew 13982: =back
13983:
1.138 matthew 13984: =head1 cgi-bin script and graphing routines
13985:
1.157 matthew 13986: =over 4
13987:
1.648 raeburn 13988: =item * &get_cgi_id()
1.138 matthew 13989:
13990: Inputs: none
13991:
13992: Returns an id which can be used to pass environment variables
13993: to various cgi-bin scripts. These environment variables will
13994: be removed from the users environment after a given time by
13995: the routine &Apache::lonnet::transfer_profile_to_env.
13996:
13997: =cut
13998:
13999: ############################################################
14000: ############################################################
1.152 albertel 14001: my $uniq=0;
1.136 matthew 14002: sub get_cgi_id {
1.154 albertel 14003: $uniq=($uniq+1)%100000;
1.280 albertel 14004: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 14005: }
14006:
1.127 matthew 14007: ############################################################
14008: ############################################################
14009:
14010: =pod
14011:
1.648 raeburn 14012: =item * &DrawBarGraph()
1.127 matthew 14013:
1.138 matthew 14014: Facilitates the plotting of data in a (stacked) bar graph.
14015: Puts plot definition data into the users environment in order for
14016: graph.png to plot it. Returns an <img> tag for the plot.
14017: The bars on the plot are labeled '1','2',...,'n'.
14018:
14019: Inputs:
14020:
14021: =over 4
14022:
14023: =item $Title: string, the title of the plot
14024:
14025: =item $xlabel: string, text describing the X-axis of the plot
14026:
14027: =item $ylabel: string, text describing the Y-axis of the plot
14028:
14029: =item $Max: scalar, the maximum Y value to use in the plot
14030: If $Max is < any data point, the graph will not be rendered.
14031:
1.140 matthew 14032: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 14033: they are plotted. If undefined, default values will be used.
14034:
1.178 matthew 14035: =item $labels: array ref holding the labels to use on the x-axis for the bars.
14036:
1.138 matthew 14037: =item @Values: An array of array references. Each array reference holds data
14038: to be plotted in a stacked bar chart.
14039:
1.239 matthew 14040: =item If the final element of @Values is a hash reference the key/value
14041: pairs will be added to the graph definition.
14042:
1.138 matthew 14043: =back
14044:
14045: Returns:
14046:
14047: An <img> tag which references graph.png and the appropriate identifying
14048: information for the plot.
14049:
1.127 matthew 14050: =cut
14051:
14052: ############################################################
14053: ############################################################
1.134 matthew 14054: sub DrawBarGraph {
1.178 matthew 14055: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 14056: #
14057: if (! defined($colors)) {
14058: $colors = ['#33ff00',
14059: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
14060: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
14061: ];
14062: }
1.228 matthew 14063: my $extra_settings = {};
14064: if (ref($Values[-1]) eq 'HASH') {
14065: $extra_settings = pop(@Values);
14066: }
1.127 matthew 14067: #
1.136 matthew 14068: my $identifier = &get_cgi_id();
14069: my $id = 'cgi.'.$identifier;
1.129 matthew 14070: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 14071: return '';
14072: }
1.225 matthew 14073: #
14074: my @Labels;
14075: if (defined($labels)) {
14076: @Labels = @$labels;
14077: } else {
14078: for (my $i=0;$i<@{$Values[0]};$i++) {
1.1263 raeburn 14079: push(@Labels,$i+1);
1.225 matthew 14080: }
14081: }
14082: #
1.129 matthew 14083: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 14084: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 14085: my %ValuesHash;
14086: my $NumSets=1;
14087: foreach my $array (@Values) {
14088: next if (! ref($array));
1.136 matthew 14089: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 14090: join(',',@$array);
1.129 matthew 14091: }
1.127 matthew 14092: #
1.136 matthew 14093: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 14094: if ($NumBars < 3) {
14095: $width = 120+$NumBars*32;
1.220 matthew 14096: $xskip = 1;
1.225 matthew 14097: $bar_width = 30;
14098: } elsif ($NumBars < 5) {
14099: $width = 120+$NumBars*20;
14100: $xskip = 1;
14101: $bar_width = 20;
1.220 matthew 14102: } elsif ($NumBars < 10) {
1.136 matthew 14103: $width = 120+$NumBars*15;
14104: $xskip = 1;
14105: $bar_width = 15;
14106: } elsif ($NumBars <= 25) {
14107: $width = 120+$NumBars*11;
14108: $xskip = 5;
14109: $bar_width = 8;
14110: } elsif ($NumBars <= 50) {
14111: $width = 120+$NumBars*8;
14112: $xskip = 5;
14113: $bar_width = 4;
14114: } else {
14115: $width = 120+$NumBars*8;
14116: $xskip = 5;
14117: $bar_width = 4;
14118: }
14119: #
1.137 matthew 14120: $Max = 1 if ($Max < 1);
14121: if ( int($Max) < $Max ) {
14122: $Max++;
14123: $Max = int($Max);
14124: }
1.127 matthew 14125: $Title = '' if (! defined($Title));
14126: $xlabel = '' if (! defined($xlabel));
14127: $ylabel = '' if (! defined($ylabel));
1.369 www 14128: $ValuesHash{$id.'.title'} = &escape($Title);
14129: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
14130: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 14131: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 14132: $ValuesHash{$id.'.NumBars'} = $NumBars;
14133: $ValuesHash{$id.'.NumSets'} = $NumSets;
14134: $ValuesHash{$id.'.PlotType'} = 'bar';
14135: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14136: $ValuesHash{$id.'.height'} = $height;
14137: $ValuesHash{$id.'.width'} = $width;
14138: $ValuesHash{$id.'.xskip'} = $xskip;
14139: $ValuesHash{$id.'.bar_width'} = $bar_width;
14140: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 14141: #
1.228 matthew 14142: # Deal with other parameters
14143: while (my ($key,$value) = each(%$extra_settings)) {
14144: $ValuesHash{$id.'.'.$key} = $value;
14145: }
14146: #
1.646 raeburn 14147: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 14148: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14149: }
14150:
14151: ############################################################
14152: ############################################################
14153:
14154: =pod
14155:
1.648 raeburn 14156: =item * &DrawXYGraph()
1.137 matthew 14157:
1.138 matthew 14158: Facilitates the plotting of data in an XY graph.
14159: Puts plot definition data into the users environment in order for
14160: graph.png to plot it. Returns an <img> tag for the plot.
14161:
14162: Inputs:
14163:
14164: =over 4
14165:
14166: =item $Title: string, the title of the plot
14167:
14168: =item $xlabel: string, text describing the X-axis of the plot
14169:
14170: =item $ylabel: string, text describing the Y-axis of the plot
14171:
14172: =item $Max: scalar, the maximum Y value to use in the plot
14173: If $Max is < any data point, the graph will not be rendered.
14174:
14175: =item $colors: Array ref containing the hex color codes for the data to be
14176: plotted in. If undefined, default values will be used.
14177:
14178: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14179:
14180: =item $Ydata: Array ref containing Array refs.
1.185 www 14181: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 14182:
14183: =item %Values: hash indicating or overriding any default values which are
14184: passed to graph.png.
14185: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14186:
14187: =back
14188:
14189: Returns:
14190:
14191: An <img> tag which references graph.png and the appropriate identifying
14192: information for the plot.
14193:
1.137 matthew 14194: =cut
14195:
14196: ############################################################
14197: ############################################################
14198: sub DrawXYGraph {
14199: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
14200: #
14201: # Create the identifier for the graph
14202: my $identifier = &get_cgi_id();
14203: my $id = 'cgi.'.$identifier;
14204: #
14205: $Title = '' if (! defined($Title));
14206: $xlabel = '' if (! defined($xlabel));
14207: $ylabel = '' if (! defined($ylabel));
14208: my %ValuesHash =
14209: (
1.369 www 14210: $id.'.title' => &escape($Title),
14211: $id.'.xlabel' => &escape($xlabel),
14212: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 14213: $id.'.y_max_value'=> $Max,
14214: $id.'.labels' => join(',',@$Xlabels),
14215: $id.'.PlotType' => 'XY',
14216: );
14217: #
14218: if (defined($colors) && ref($colors) eq 'ARRAY') {
14219: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14220: }
14221: #
14222: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
14223: return '';
14224: }
14225: my $NumSets=1;
1.138 matthew 14226: foreach my $array (@{$Ydata}){
1.137 matthew 14227: next if (! ref($array));
14228: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
14229: }
1.138 matthew 14230: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 14231: #
14232: # Deal with other parameters
14233: while (my ($key,$value) = each(%Values)) {
14234: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 14235: }
14236: #
1.646 raeburn 14237: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 14238: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
14239: }
14240:
14241: ############################################################
14242: ############################################################
14243:
14244: =pod
14245:
1.648 raeburn 14246: =item * &DrawXYYGraph()
1.138 matthew 14247:
14248: Facilitates the plotting of data in an XY graph with two Y axes.
14249: Puts plot definition data into the users environment in order for
14250: graph.png to plot it. Returns an <img> tag for the plot.
14251:
14252: Inputs:
14253:
14254: =over 4
14255:
14256: =item $Title: string, the title of the plot
14257:
14258: =item $xlabel: string, text describing the X-axis of the plot
14259:
14260: =item $ylabel: string, text describing the Y-axis of the plot
14261:
14262: =item $colors: Array ref containing the hex color codes for the data to be
14263: plotted in. If undefined, default values will be used.
14264:
14265: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
14266:
14267: =item $Ydata1: The first data set
14268:
14269: =item $Min1: The minimum value of the left Y-axis
14270:
14271: =item $Max1: The maximum value of the left Y-axis
14272:
14273: =item $Ydata2: The second data set
14274:
14275: =item $Min2: The minimum value of the right Y-axis
14276:
14277: =item $Max2: The maximum value of the left Y-axis
14278:
14279: =item %Values: hash indicating or overriding any default values which are
14280: passed to graph.png.
14281: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
14282:
14283: =back
14284:
14285: Returns:
14286:
14287: An <img> tag which references graph.png and the appropriate identifying
14288: information for the plot.
1.136 matthew 14289:
14290: =cut
14291:
14292: ############################################################
14293: ############################################################
1.137 matthew 14294: sub DrawXYYGraph {
14295: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
14296: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 14297: #
14298: # Create the identifier for the graph
14299: my $identifier = &get_cgi_id();
14300: my $id = 'cgi.'.$identifier;
14301: #
14302: $Title = '' if (! defined($Title));
14303: $xlabel = '' if (! defined($xlabel));
14304: $ylabel = '' if (! defined($ylabel));
14305: my %ValuesHash =
14306: (
1.369 www 14307: $id.'.title' => &escape($Title),
14308: $id.'.xlabel' => &escape($xlabel),
14309: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 14310: $id.'.labels' => join(',',@$Xlabels),
14311: $id.'.PlotType' => 'XY',
14312: $id.'.NumSets' => 2,
1.137 matthew 14313: $id.'.two_axes' => 1,
14314: $id.'.y1_max_value' => $Max1,
14315: $id.'.y1_min_value' => $Min1,
14316: $id.'.y2_max_value' => $Max2,
14317: $id.'.y2_min_value' => $Min2,
1.136 matthew 14318: );
14319: #
1.137 matthew 14320: if (defined($colors) && ref($colors) eq 'ARRAY') {
14321: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
14322: }
14323: #
14324: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
14325: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 14326: return '';
14327: }
14328: my $NumSets=1;
1.137 matthew 14329: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 14330: next if (! ref($array));
14331: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 14332: }
14333: #
14334: # Deal with other parameters
14335: while (my ($key,$value) = each(%Values)) {
14336: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 14337: }
14338: #
1.646 raeburn 14339: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 14340: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 14341: }
14342:
14343: ############################################################
14344: ############################################################
14345:
14346: =pod
14347:
1.157 matthew 14348: =back
14349:
1.139 matthew 14350: =head1 Statistics helper routines?
14351:
14352: Bad place for them but what the hell.
14353:
1.157 matthew 14354: =over 4
14355:
1.648 raeburn 14356: =item * &chartlink()
1.139 matthew 14357:
14358: Returns a link to the chart for a specific student.
14359:
14360: Inputs:
14361:
14362: =over 4
14363:
14364: =item $linktext: The text of the link
14365:
14366: =item $sname: The students username
14367:
14368: =item $sdomain: The students domain
14369:
14370: =back
14371:
1.157 matthew 14372: =back
14373:
1.139 matthew 14374: =cut
14375:
14376: ############################################################
14377: ############################################################
14378: sub chartlink {
14379: my ($linktext, $sname, $sdomain) = @_;
14380: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 14381: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 14382: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 14383: '">'.$linktext.'</a>';
1.153 matthew 14384: }
14385:
14386: #######################################################
14387: #######################################################
14388:
14389: =pod
14390:
14391: =head1 Course Environment Routines
1.157 matthew 14392:
14393: =over 4
1.153 matthew 14394:
1.648 raeburn 14395: =item * &restore_course_settings()
1.153 matthew 14396:
1.648 raeburn 14397: =item * &store_course_settings()
1.153 matthew 14398:
14399: Restores/Store indicated form parameters from the course environment.
14400: Will not overwrite existing values of the form parameters.
14401:
14402: Inputs:
14403: a scalar describing the data (e.g. 'chart', 'problem_analysis')
14404:
14405: a hash ref describing the data to be stored. For example:
14406:
14407: %Save_Parameters = ('Status' => 'scalar',
14408: 'chartoutputmode' => 'scalar',
14409: 'chartoutputdata' => 'scalar',
14410: 'Section' => 'array',
1.373 raeburn 14411: 'Group' => 'array',
1.153 matthew 14412: 'StudentData' => 'array',
14413: 'Maps' => 'array');
14414:
14415: Returns: both routines return nothing
14416:
1.631 raeburn 14417: =back
14418:
1.153 matthew 14419: =cut
14420:
14421: #######################################################
14422: #######################################################
14423: sub store_course_settings {
1.496 albertel 14424: return &store_settings($env{'request.course.id'},@_);
14425: }
14426:
14427: sub store_settings {
1.153 matthew 14428: # save to the environment
14429: # appenv the same items, just to be safe
1.300 albertel 14430: my $udom = $env{'user.domain'};
14431: my $uname = $env{'user.name'};
1.496 albertel 14432: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14433: my %SaveHash;
14434: my %AppHash;
14435: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 14436: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 14437: my $envname = 'environment.'.$basename;
1.258 albertel 14438: if (exists($env{'form.'.$setting})) {
1.153 matthew 14439: # Save this value away
14440: if ($type eq 'scalar' &&
1.258 albertel 14441: (! exists($env{$envname}) ||
14442: $env{$envname} ne $env{'form.'.$setting})) {
14443: $SaveHash{$basename} = $env{'form.'.$setting};
14444: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 14445: } elsif ($type eq 'array') {
14446: my $stored_form;
1.258 albertel 14447: if (ref($env{'form.'.$setting})) {
1.153 matthew 14448: $stored_form = join(',',
14449: map {
1.369 www 14450: &escape($_);
1.258 albertel 14451: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 14452: } else {
14453: $stored_form =
1.369 www 14454: &escape($env{'form.'.$setting});
1.153 matthew 14455: }
14456: # Determine if the array contents are the same.
1.258 albertel 14457: if ($stored_form ne $env{$envname}) {
1.153 matthew 14458: $SaveHash{$basename} = $stored_form;
14459: $AppHash{$envname} = $stored_form;
14460: }
14461: }
14462: }
14463: }
14464: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 14465: $udom,$uname);
1.153 matthew 14466: if ($put_result !~ /^(ok|delayed)/) {
14467: &Apache::lonnet::logthis('unable to save form parameters, '.
14468: 'got error:'.$put_result);
14469: }
14470: # Make sure these settings stick around in this session, too
1.646 raeburn 14471: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 14472: return;
14473: }
14474:
14475: sub restore_course_settings {
1.499 albertel 14476: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14477: }
14478:
14479: sub restore_settings {
14480: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14481: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14482: next if (exists($env{'form.'.$setting}));
1.496 albertel 14483: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14484: '.'.$setting;
1.258 albertel 14485: if (exists($env{$envname})) {
1.153 matthew 14486: if ($type eq 'scalar') {
1.258 albertel 14487: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14488: } elsif ($type eq 'array') {
1.258 albertel 14489: $env{'form.'.$setting} = [
1.153 matthew 14490: map {
1.369 www 14491: &unescape($_);
1.258 albertel 14492: } split(',',$env{$envname})
1.153 matthew 14493: ];
14494: }
14495: }
14496: }
1.127 matthew 14497: }
14498:
1.618 raeburn 14499: #######################################################
14500: #######################################################
14501:
14502: =pod
14503:
14504: =head1 Domain E-mail Routines
14505:
14506: =over 4
14507:
1.648 raeburn 14508: =item * &build_recipient_list()
1.618 raeburn 14509:
1.1144 raeburn 14510: Build recipient lists for following types of e-mail:
1.766 raeburn 14511: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14512: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14513: module change checking, student/employee ID conflict checks, as
14514: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14515: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14516:
14517: Inputs:
1.619 raeburn 14518: defmail (scalar - email address of default recipient),
1.1144 raeburn 14519: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14520: requestsmail, updatesmail, or idconflictsmail).
14521:
1.619 raeburn 14522: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14523:
1.619 raeburn 14524: origmail (scalar - email address of recipient from loncapa.conf,
14525: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14526:
1.655 raeburn 14527: Returns: comma separated list of addresses to which to send e-mail.
14528:
14529: =back
1.618 raeburn 14530:
14531: =cut
14532:
14533: ############################################################
14534: ############################################################
14535: sub build_recipient_list {
1.619 raeburn 14536: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 14537: my @recipients;
1.1270 raeburn 14538: my ($otheremails,$lastresort,$allbcc,$addtext);
1.618 raeburn 14539: my %domconfig =
1.1270 raeburn 14540: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
1.618 raeburn 14541: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14542: if (exists($domconfig{'contacts'}{$mailing})) {
14543: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14544: my @contacts = ('adminemail','supportemail');
14545: foreach my $item (@contacts) {
14546: if ($domconfig{'contacts'}{$mailing}{$item}) {
14547: my $addr = $domconfig{'contacts'}{$item};
14548: if (!grep(/^\Q$addr\E$/,@recipients)) {
14549: push(@recipients,$addr);
14550: }
1.619 raeburn 14551: }
1.1270 raeburn 14552: }
14553: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
14554: if ($mailing eq 'helpdeskmail') {
14555: if ($domconfig{'contacts'}{$mailing}{'bcc'}) {
14556: my @bccs = split(/,/,$domconfig{'contacts'}{$mailing}{'bcc'});
14557: my @ok_bccs;
14558: foreach my $bcc (@bccs) {
14559: $bcc =~ s/^\s+//g;
14560: $bcc =~ s/\s+$//g;
14561: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14562: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14563: push(@ok_bccs,$bcc);
14564: }
14565: }
14566: }
14567: if (@ok_bccs > 0) {
14568: $allbcc = join(', ',@ok_bccs);
14569: }
14570: }
14571: $addtext = $domconfig{'contacts'}{$mailing}{'include'};
1.618 raeburn 14572: }
14573: }
1.766 raeburn 14574: } elsif ($origmail ne '') {
1.1270 raeburn 14575: $lastresort = $origmail;
1.618 raeburn 14576: }
1.619 raeburn 14577: } elsif ($origmail ne '') {
1.1270 raeburn 14578: $lastresort = $origmail;
14579: }
14580:
14581: if (($mailing eq 'helpdesk') && ($lastresort ne '')) {
14582: unless (grep(/^\Q$defdom\E$/,&Apache::lonnet::current_machine_domains())) {
14583: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
14584: my $machinedom = $Apache::lonnet::perlvar{'lonDefDomain'};
14585: my %what = (
14586: perlvar => 1,
14587: );
14588: my $primary = &Apache::lonnet::domain($defdom,'primary');
14589: if ($primary) {
14590: my $gotaddr;
14591: my ($result,$returnhash) =
14592: &Apache::lonnet::get_remote_globals($primary,{ perlvar => 1 });
14593: if (($result eq 'ok') && (ref($returnhash) eq 'HASH')) {
14594: if ($returnhash->{'lonSupportEMail'} =~ /^[^\@]+\@[^\@]+$/) {
14595: $lastresort = $returnhash->{'lonSupportEMail'};
14596: $gotaddr = 1;
14597: }
14598: }
14599: unless ($gotaddr) {
14600: my $uintdom = &Apache::lonnet::internet_dom($primary);
14601: my $intdom = &Apache::lonnet::internet_dom($lonhost);
14602: unless ($uintdom eq $intdom) {
14603: my %domconfig =
14604: &Apache::lonnet::get_dom('configuration',['contacts'],$machinedom);
14605: if (ref($domconfig{'contacts'}) eq 'HASH') {
14606: if (ref($domconfig{'contacts'}{'otherdomsmail'}) eq 'HASH') {
14607: my @contacts = ('adminemail','supportemail');
14608: foreach my $item (@contacts) {
14609: if ($domconfig{'contacts'}{'otherdomsmail'}{$item}) {
14610: my $addr = $domconfig{'contacts'}{$item};
14611: if (!grep(/^\Q$addr\E$/,@recipients)) {
14612: push(@recipients,$addr);
14613: }
14614: }
14615: }
14616: if ($domconfig{'contacts'}{'otherdomsmail'}{'others'}) {
14617: $otheremails = $domconfig{'contacts'}{'otherdomsmail'}{'others'};
14618: }
14619: if ($domconfig{'contacts'}{'otherdomsmail'}{'bcc'}) {
14620: my @bccs = split(/,/,$domconfig{'contacts'}{'otherdomsmail'}{'bcc'});
14621: my @ok_bccs;
14622: foreach my $bcc (@bccs) {
14623: $bcc =~ s/^\s+//g;
14624: $bcc =~ s/\s+$//g;
14625: if ($bcc =~ m/^[^\@]+\@[^\@]+$/) {
14626: if (!(grep(/^\Q$bcc\E$/,@ok_bccs))) {
14627: push(@ok_bccs,$bcc);
14628: }
14629: }
14630: }
14631: if (@ok_bccs > 0) {
14632: $allbcc = join(', ',@ok_bccs);
14633: }
14634: }
14635: $addtext = $domconfig{'contacts'}{'otherdomsmail'}{'include'};
14636: }
14637: }
14638: }
14639: }
14640: }
14641: }
1.618 raeburn 14642: }
1.688 raeburn 14643: if (defined($defmail)) {
14644: if ($defmail ne '') {
14645: push(@recipients,$defmail);
14646: }
1.618 raeburn 14647: }
14648: if ($otheremails) {
1.619 raeburn 14649: my @others;
14650: if ($otheremails =~ /,/) {
14651: @others = split(/,/,$otheremails);
1.618 raeburn 14652: } else {
1.619 raeburn 14653: push(@others,$otheremails);
14654: }
14655: foreach my $addr (@others) {
14656: if (!grep(/^\Q$addr\E$/,@recipients)) {
14657: push(@recipients,$addr);
14658: }
1.618 raeburn 14659: }
14660: }
1.1270 raeburn 14661: if ($mailing eq 'helpdesk') {
14662: if ((!@recipients) && ($lastresort ne '')) {
14663: push(@recipients,$lastresort);
14664: }
14665: } elsif ($lastresort ne '') {
14666: if (!grep(/^\Q$lastresort\E$/,@recipients)) {
14667: push(@recipients,$lastresort);
14668: }
14669: }
1.1271 raeburn 14670: my $recipientlist = join(',',@recipients);
1.1270 raeburn 14671: if (wantarray) {
14672: return ($recipientlist,$allbcc,$addtext);
14673: } else {
14674: return $recipientlist;
14675: }
1.618 raeburn 14676: }
14677:
1.127 matthew 14678: ############################################################
14679: ############################################################
1.154 albertel 14680:
1.655 raeburn 14681: =pod
14682:
1.1224 musolffc 14683: =over 4
14684:
1.1223 musolffc 14685: =item * &mime_email()
14686:
14687: Sends an email with a possible attachment
14688:
14689: Inputs:
14690:
14691: =over 4
14692:
14693: from - Sender's email address
14694:
14695: to - Email address of recipient
14696:
14697: subject - Subject of email
14698:
14699: body - Body of email
14700:
14701: cc_string - Carbon copy email address
14702:
14703: bcc - Blind carbon copy email address
14704:
14705: type - File type of attachment
14706:
14707: attachment_path - Path of file to be attached
14708:
14709: file_name - Name of file to be attached
14710:
14711: attachment_text - The body of an attachment of type "TEXT"
14712:
14713: =back
14714:
14715: =back
14716:
14717: =cut
14718:
14719: ############################################################
14720: ############################################################
14721:
14722: sub mime_email {
14723: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
14724: $file_name, $attachment_text) = @_;
14725: my $msg = MIME::Lite->new(
14726: From => $from,
14727: To => $to,
14728: Subject => $subject,
14729: Type =>'TEXT',
14730: Data => $body,
14731: );
14732: if ($cc_string ne '') {
14733: $msg->add("Cc" => $cc_string);
14734: }
14735: if ($bcc ne '') {
14736: $msg->add("Bcc" => $bcc);
14737: }
14738: $msg->attr("content-type" => "text/plain");
14739: $msg->attr("content-type.charset" => "UTF-8");
14740: # Attach file if given
14741: if ($attachment_path) {
14742: unless ($file_name) {
14743: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
14744: }
14745: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
14746: $msg->attach(Type => $type,
14747: Path => $attachment_path,
14748: Filename => $file_name
14749: );
14750: # Otherwise attach text if given
14751: } elsif ($attachment_text) {
14752: $msg->attach(Type => 'TEXT',
14753: Data => $attachment_text);
14754: }
14755: # Send it
14756: $msg->send('sendmail');
14757: }
14758:
14759: ############################################################
14760: ############################################################
14761:
14762: =pod
14763:
1.655 raeburn 14764: =head1 Course Catalog Routines
14765:
14766: =over 4
14767:
14768: =item * &gather_categories()
14769:
14770: Converts category definitions - keys of categories hash stored in
14771: coursecategories in configuration.db on the primary library server in a
14772: domain - to an array. Also generates javascript and idx hash used to
14773: generate Domain Coordinator interface for editing Course Categories.
14774:
14775: Inputs:
1.663 raeburn 14776:
1.655 raeburn 14777: categories (reference to hash of category definitions).
1.663 raeburn 14778:
1.655 raeburn 14779: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14780: categories and subcategories).
1.663 raeburn 14781:
1.655 raeburn 14782: idx (reference to hash of counters used in Domain Coordinator interface for
14783: editing Course Categories).
1.663 raeburn 14784:
1.655 raeburn 14785: jsarray (reference to array of categories used to create Javascript arrays for
14786: Domain Coordinator interface for editing Course Categories).
14787:
14788: Returns: nothing
14789:
14790: Side effects: populates cats, idx and jsarray.
14791:
14792: =cut
14793:
14794: sub gather_categories {
14795: my ($categories,$cats,$idx,$jsarray) = @_;
14796: my %counters;
14797: my $num = 0;
14798: foreach my $item (keys(%{$categories})) {
14799: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14800: if ($container eq '' && $depth == 0) {
14801: $cats->[$depth][$categories->{$item}] = $cat;
14802: } else {
14803: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14804: }
14805: my ($escitem,$tail) = split(/:/,$item,2);
14806: if ($counters{$tail} eq '') {
14807: $counters{$tail} = $num;
14808: $num ++;
14809: }
14810: if (ref($idx) eq 'HASH') {
14811: $idx->{$item} = $counters{$tail};
14812: }
14813: if (ref($jsarray) eq 'ARRAY') {
14814: push(@{$jsarray->[$counters{$tail}]},$item);
14815: }
14816: }
14817: return;
14818: }
14819:
14820: =pod
14821:
14822: =item * &extract_categories()
14823:
14824: Used to generate breadcrumb trails for course categories.
14825:
14826: Inputs:
1.663 raeburn 14827:
1.655 raeburn 14828: categories (reference to hash of category definitions).
1.663 raeburn 14829:
1.655 raeburn 14830: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14831: categories and subcategories).
1.663 raeburn 14832:
1.655 raeburn 14833: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14834:
1.655 raeburn 14835: allitems (reference to hash - key is category key
14836: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14837:
1.655 raeburn 14838: idx (reference to hash of counters used in Domain Coordinator interface for
14839: editing Course Categories).
1.663 raeburn 14840:
1.655 raeburn 14841: jsarray (reference to array of categories used to create Javascript arrays for
14842: Domain Coordinator interface for editing Course Categories).
14843:
1.665 raeburn 14844: subcats (reference to hash of arrays containing all subcategories within each
14845: category, -recursive)
14846:
1.655 raeburn 14847: Returns: nothing
14848:
14849: Side effects: populates trails and allitems hash references.
14850:
14851: =cut
14852:
14853: sub extract_categories {
1.665 raeburn 14854: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 14855: if (ref($categories) eq 'HASH') {
14856: &gather_categories($categories,$cats,$idx,$jsarray);
14857: if (ref($cats->[0]) eq 'ARRAY') {
14858: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14859: my $name = $cats->[0][$i];
14860: my $item = &escape($name).'::0';
14861: my $trailstr;
14862: if ($name eq 'instcode') {
14863: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14864: } elsif ($name eq 'communities') {
14865: $trailstr = &mt('Communities');
1.1239 raeburn 14866: } elsif ($name eq 'placement') {
14867: $trailstr = &mt('Placement Tests');
1.655 raeburn 14868: } else {
14869: $trailstr = $name;
14870: }
14871: if ($allitems->{$item} eq '') {
14872: push(@{$trails},$trailstr);
14873: $allitems->{$item} = scalar(@{$trails})-1;
14874: }
14875: my @parents = ($name);
14876: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14877: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14878: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14879: if (ref($subcats) eq 'HASH') {
14880: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14881: }
14882: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
14883: }
14884: } else {
14885: if (ref($subcats) eq 'HASH') {
14886: $subcats->{$item} = [];
1.655 raeburn 14887: }
14888: }
14889: }
14890: }
14891: }
14892: return;
14893: }
14894:
14895: =pod
14896:
1.1162 raeburn 14897: =item * &recurse_categories()
1.655 raeburn 14898:
14899: Recursively used to generate breadcrumb trails for course categories.
14900:
14901: Inputs:
1.663 raeburn 14902:
1.655 raeburn 14903: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14904: categories and subcategories).
1.663 raeburn 14905:
1.655 raeburn 14906: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14907:
14908: category (current course category, for which breadcrumb trail is being generated).
14909:
14910: trails (reference to array of breadcrumb trails for each category).
14911:
1.655 raeburn 14912: allitems (reference to hash - key is category key
14913: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14914:
1.655 raeburn 14915: parents (array containing containers directories for current category,
14916: back to top level).
14917:
14918: Returns: nothing
14919:
14920: Side effects: populates trails and allitems hash references
14921:
14922: =cut
14923:
14924: sub recurse_categories {
1.665 raeburn 14925: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 14926: my $shallower = $depth - 1;
14927: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14928: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14929: my $name = $cats->[$depth]{$category}[$k];
14930: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14931: my $trailstr = join(' -> ',(@{$parents},$category));
14932: if ($allitems->{$item} eq '') {
14933: push(@{$trails},$trailstr);
14934: $allitems->{$item} = scalar(@{$trails})-1;
14935: }
14936: my $deeper = $depth+1;
14937: push(@{$parents},$category);
1.665 raeburn 14938: if (ref($subcats) eq 'HASH') {
14939: my $subcat = &escape($name).':'.$category.':'.$depth;
14940: for (my $j=@{$parents}; $j>=0; $j--) {
14941: my $higher;
14942: if ($j > 0) {
14943: $higher = &escape($parents->[$j]).':'.
14944: &escape($parents->[$j-1]).':'.$j;
14945: } else {
14946: $higher = &escape($parents->[$j]).'::'.$j;
14947: }
14948: push(@{$subcats->{$higher}},$subcat);
14949: }
14950: }
14951: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
14952: $subcats);
1.655 raeburn 14953: pop(@{$parents});
14954: }
14955: } else {
14956: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14957: my $trailstr = join(' -> ',(@{$parents},$category));
14958: if ($allitems->{$item} eq '') {
14959: push(@{$trails},$trailstr);
14960: $allitems->{$item} = scalar(@{$trails})-1;
14961: }
14962: }
14963: return;
14964: }
14965:
1.663 raeburn 14966: =pod
14967:
1.1162 raeburn 14968: =item * &assign_categories_table()
1.663 raeburn 14969:
14970: Create a datatable for display of hierarchical categories in a domain,
14971: with checkboxes to allow a course to be categorized.
14972:
14973: Inputs:
14974:
14975: cathash - reference to hash of categories defined for the domain (from
14976: configuration.db)
14977:
14978: currcat - scalar with an & separated list of categories assigned to a course.
14979:
1.919 raeburn 14980: type - scalar contains course type (Course or Community).
14981:
1.1260 raeburn 14982: disabled - scalar (optional) contains disabled="disabled" if input elements are
14983: to be readonly (e.g., Domain Helpdesk role viewing course settings).
14984:
1.663 raeburn 14985: Returns: $output (markup to be displayed)
14986:
14987: =cut
14988:
14989: sub assign_categories_table {
1.1259 raeburn 14990: my ($cathash,$currcat,$type,$disabled) = @_;
1.663 raeburn 14991: my $output;
14992: if (ref($cathash) eq 'HASH') {
14993: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
14994: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
14995: $maxdepth = scalar(@cats);
14996: if (@cats > 0) {
14997: my $itemcount = 0;
14998: if (ref($cats[0]) eq 'ARRAY') {
14999: my @currcategories;
15000: if ($currcat ne '') {
15001: @currcategories = split('&',$currcat);
15002: }
1.919 raeburn 15003: my $table;
1.663 raeburn 15004: for (my $i=0; $i<@{$cats[0]}; $i++) {
15005: my $parent = $cats[0][$i];
1.919 raeburn 15006: next if ($parent eq 'instcode');
15007: if ($type eq 'Community') {
15008: next unless ($parent eq 'communities');
1.1239 raeburn 15009: } elsif ($type eq 'Placement') {
15010: next unless ($parent eq 'placement');
1.919 raeburn 15011: } else {
1.1239 raeburn 15012: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 15013: }
1.663 raeburn 15014: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
15015: my $item = &escape($parent).'::0';
15016: my $checked = '';
15017: if (@currcategories > 0) {
15018: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 15019: $checked = ' checked="checked"';
1.663 raeburn 15020: }
15021: }
1.919 raeburn 15022: my $parent_title = $parent;
15023: if ($parent eq 'communities') {
15024: $parent_title = &mt('Communities');
1.1239 raeburn 15025: } elsif ($parent eq 'placement') {
15026: $parent_title = &mt('Placement Tests');
1.919 raeburn 15027: }
15028: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
15029: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15030: $item.'"'.$checked.$disabled.' />'.$parent_title.'</span>'.
1.919 raeburn 15031: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 15032: my $depth = 1;
15033: push(@path,$parent);
1.1259 raeburn 15034: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories,$disabled);
1.663 raeburn 15035: pop(@path);
1.919 raeburn 15036: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 15037: $itemcount ++;
15038: }
1.919 raeburn 15039: if ($itemcount) {
15040: $output = &Apache::loncommon::start_data_table().
15041: $table.
15042: &Apache::loncommon::end_data_table();
15043: }
1.663 raeburn 15044: }
15045: }
15046: }
15047: return $output;
15048: }
15049:
15050: =pod
15051:
1.1162 raeburn 15052: =item * &assign_category_rows()
1.663 raeburn 15053:
15054: Create a datatable row for display of nested categories in a domain,
15055: with checkboxes to allow a course to be categorized,called recursively.
15056:
15057: Inputs:
15058:
15059: itemcount - track row number for alternating colors
15060:
15061: cats - reference to array of arrays/hashes which encapsulates hierarchy of
15062: categories and subcategories.
15063:
15064: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
15065:
15066: parent - parent of current category item
15067:
15068: path - Array containing all categories back up through the hierarchy from the
15069: current category to the top level.
15070:
15071: currcategories - reference to array of current categories assigned to the course
15072:
1.1260 raeburn 15073: disabled - scalar (optional) contains disabled="disabled" if input elements are
15074: to be readonly (e.g., Domain Helpdesk role viewing course settings).
15075:
1.663 raeburn 15076: Returns: $output (markup to be displayed).
15077:
15078: =cut
15079:
15080: sub assign_category_rows {
1.1259 raeburn 15081: my ($itemcount,$cats,$depth,$parent,$path,$currcategories,$disabled) = @_;
1.663 raeburn 15082: my ($text,$name,$item,$chgstr);
15083: if (ref($cats) eq 'ARRAY') {
15084: my $maxdepth = scalar(@{$cats});
15085: if (ref($cats->[$depth]) eq 'HASH') {
15086: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
15087: my $numchildren = @{$cats->[$depth]{$parent}};
15088: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 15089: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 15090: for (my $j=0; $j<$numchildren; $j++) {
15091: $name = $cats->[$depth]{$parent}[$j];
15092: $item = &escape($name).':'.&escape($parent).':'.$depth;
15093: my $deeper = $depth+1;
15094: my $checked = '';
15095: if (ref($currcategories) eq 'ARRAY') {
15096: if (@{$currcategories} > 0) {
15097: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 15098: $checked = ' checked="checked"';
1.663 raeburn 15099: }
15100: }
15101: }
1.664 raeburn 15102: $text .= '<tr><td><span class="LC_nobreak"><label>'.
15103: '<input type="checkbox" name="usecategory" value="'.
1.1259 raeburn 15104: $item.'"'.$checked.$disabled.' />'.$name.'</label></span>'.
1.675 raeburn 15105: '<input type="hidden" name="catname" value="'.$name.'" />'.
15106: '</td><td>';
1.663 raeburn 15107: if (ref($path) eq 'ARRAY') {
15108: push(@{$path},$name);
1.1259 raeburn 15109: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories,$disabled);
1.663 raeburn 15110: pop(@{$path});
15111: }
15112: $text .= '</td></tr>';
15113: }
15114: $text .= '</table></td>';
15115: }
15116: }
15117: }
15118: return $text;
15119: }
15120:
1.1181 raeburn 15121: =pod
15122:
15123: =back
15124:
15125: =cut
15126:
1.655 raeburn 15127: ############################################################
15128: ############################################################
15129:
15130:
1.443 albertel 15131: sub commit_customrole {
1.664 raeburn 15132: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 15133: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 15134: ($start?', '.&mt('starting').' '.localtime($start):'').
15135: ($end?', ending '.localtime($end):'').': <b>'.
15136: &Apache::lonnet::assigncustomrole(
1.664 raeburn 15137: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 15138: '</b><br />';
15139: return $output;
15140: }
15141:
15142: sub commit_standardrole {
1.1116 raeburn 15143: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 15144: my ($output,$logmsg,$linefeed);
15145: if ($context eq 'auto') {
15146: $linefeed = "\n";
15147: } else {
15148: $linefeed = "<br />\n";
15149: }
1.443 albertel 15150: if ($three eq 'st') {
1.541 raeburn 15151: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 15152: $one,$two,$sec,$context,$credits);
1.541 raeburn 15153: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 15154: ($result eq 'unknown_course') || ($result eq 'refused')) {
15155: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 15156: } else {
1.541 raeburn 15157: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 15158: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15159: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
15160: if ($context eq 'auto') {
15161: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
15162: } else {
15163: $output .= '<b>'.$result.'</b>'.$linefeed.
15164: &mt('Add to classlist').': <b>ok</b>';
15165: }
15166: $output .= $linefeed;
1.443 albertel 15167: }
15168: } else {
15169: $output = &mt('Assigning').' '.$three.' in '.$url.
15170: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 15171: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 15172: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 15173: if ($context eq 'auto') {
15174: $output .= $result.$linefeed;
15175: } else {
15176: $output .= '<b>'.$result.'</b>'.$linefeed;
15177: }
1.443 albertel 15178: }
15179: return $output;
15180: }
15181:
15182: sub commit_studentrole {
1.1116 raeburn 15183: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
15184: $credits) = @_;
1.626 raeburn 15185: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 15186: if ($context eq 'auto') {
15187: $linefeed = "\n";
15188: } else {
15189: $linefeed = '<br />'."\n";
15190: }
1.443 albertel 15191: if (defined($one) && defined($two)) {
15192: my $cid=$one.'_'.$two;
15193: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
15194: my $secchange = 0;
15195: my $expire_role_result;
15196: my $modify_section_result;
1.628 raeburn 15197: if ($oldsec ne '-1') {
15198: if ($oldsec ne $sec) {
1.443 albertel 15199: $secchange = 1;
1.628 raeburn 15200: my $now = time;
1.443 albertel 15201: my $uurl='/'.$cid;
15202: $uurl=~s/\_/\//g;
15203: if ($oldsec) {
15204: $uurl.='/'.$oldsec;
15205: }
1.626 raeburn 15206: $oldsecurl = $uurl;
1.628 raeburn 15207: $expire_role_result =
1.652 raeburn 15208: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 15209: if ($env{'request.course.sec'} ne '') {
15210: if ($expire_role_result eq 'refused') {
15211: my @roles = ('st');
15212: my @statuses = ('previous');
15213: my @roledoms = ($one);
15214: my $withsec = 1;
15215: my %roleshash =
15216: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
15217: \@statuses,\@roles,\@roledoms,$withsec);
15218: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
15219: my ($oldstart,$oldend) =
15220: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
15221: if ($oldend > 0 && $oldend <= $now) {
15222: $expire_role_result = 'ok';
15223: }
15224: }
15225: }
15226: }
1.443 albertel 15227: $result = $expire_role_result;
15228: }
15229: }
15230: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 15231: $modify_section_result =
15232: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
15233: undef,undef,undef,$sec,
15234: $end,$start,'','',$cid,
15235: '',$context,$credits);
1.443 albertel 15236: if ($modify_section_result =~ /^ok/) {
15237: if ($secchange == 1) {
1.628 raeburn 15238: if ($sec eq '') {
15239: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
15240: } else {
15241: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
15242: }
1.443 albertel 15243: } elsif ($oldsec eq '-1') {
1.628 raeburn 15244: if ($sec eq '') {
15245: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
15246: } else {
15247: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15248: }
1.443 albertel 15249: } else {
1.628 raeburn 15250: if ($sec eq '') {
15251: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
15252: } else {
15253: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
15254: }
1.443 albertel 15255: }
15256: } else {
1.1115 raeburn 15257: if ($secchange) {
1.628 raeburn 15258: $$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;
15259: } else {
15260: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
15261: }
1.443 albertel 15262: }
15263: $result = $modify_section_result;
15264: } elsif ($secchange == 1) {
1.628 raeburn 15265: if ($oldsec eq '') {
1.1103 raeburn 15266: $$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 15267: } else {
15268: $$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;
15269: }
1.626 raeburn 15270: if ($expire_role_result eq 'refused') {
15271: my $newsecurl = '/'.$cid;
15272: $newsecurl =~ s/\_/\//g;
15273: if ($sec ne '') {
15274: $newsecurl.='/'.$sec;
15275: }
15276: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
15277: if ($sec eq '') {
15278: $$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;
15279: } else {
15280: $$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;
15281: }
15282: }
15283: }
1.443 albertel 15284: }
15285: } else {
1.626 raeburn 15286: $$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 15287: $result = "error: incomplete course id\n";
15288: }
15289: return $result;
15290: }
15291:
1.1108 raeburn 15292: sub show_role_extent {
15293: my ($scope,$context,$role) = @_;
15294: $scope =~ s{^/}{};
15295: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
15296: push(@courseroles,'co');
15297: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
15298: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
15299: $scope =~ s{/}{_};
15300: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
15301: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
15302: my ($audom,$auname) = split(/\//,$scope);
15303: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
15304: &Apache::loncommon::plainname($auname,$audom).'</span>');
15305: } else {
15306: $scope =~ s{/$}{};
15307: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
15308: &Apache::lonnet::domain($scope,'description').'</span>');
15309: }
15310: }
15311:
1.443 albertel 15312: ############################################################
15313: ############################################################
15314:
1.566 albertel 15315: sub check_clone {
1.578 raeburn 15316: my ($args,$linefeed) = @_;
1.566 albertel 15317: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
15318: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
15319: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
15320: my $clonemsg;
15321: my $can_clone = 0;
1.944 raeburn 15322: my $lctype = lc($args->{'crstype'});
1.908 raeburn 15323: if ($lctype ne 'community') {
15324: $lctype = 'course';
15325: }
1.566 albertel 15326: if ($clonehome eq 'no_host') {
1.944 raeburn 15327: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15328: $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'});
15329: } else {
15330: $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'});
15331: }
1.566 albertel 15332: } else {
15333: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 15334: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 15335: if ($clonedesc{'type'} ne 'Community') {
1.1262 raeburn 15336: $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'});
1.908 raeburn 15337: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15338: }
15339: }
1.1262 raeburn 15340: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
1.882 raeburn 15341: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 15342: $can_clone = 1;
15343: } else {
1.1221 raeburn 15344: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 15345: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 15346: if ($clonehash{'cloners'} eq '') {
15347: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
15348: if ($domdefs{'canclone'}) {
15349: unless ($domdefs{'canclone'} eq 'none') {
15350: if ($domdefs{'canclone'} eq 'domain') {
15351: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
15352: $can_clone = 1;
15353: }
15354: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15355: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
15356: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
15357: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
15358: $can_clone = 1;
15359: }
15360: }
15361: }
15362: }
1.578 raeburn 15363: } else {
1.1221 raeburn 15364: my @cloners = split(/,/,$clonehash{'cloners'});
15365: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 15366: $can_clone = 1;
1.1221 raeburn 15367: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 15368: $can_clone = 1;
1.1225 raeburn 15369: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
15370: $can_clone = 1;
1.1221 raeburn 15371: }
15372: unless ($can_clone) {
1.1225 raeburn 15373: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
15374: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 15375: my (%gotdomdefaults,%gotcodedefaults);
15376: foreach my $cloner (@cloners) {
15377: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
15378: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
15379: my (%codedefaults,@code_order);
15380: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
15381: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
15382: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
15383: }
15384: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
15385: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
15386: }
15387: } else {
15388: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
15389: \%codedefaults,
15390: \@code_order);
15391: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
15392: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
15393: }
15394: if (@code_order > 0) {
15395: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
15396: $cloner,$clonehash{'internal.coursecode'},
15397: $args->{'crscode'})) {
15398: $can_clone = 1;
15399: last;
15400: }
15401: }
15402: }
15403: }
15404: }
1.1225 raeburn 15405: }
15406: }
15407: unless ($can_clone) {
15408: my $ccrole = 'cc';
15409: if ($args->{'crstype'} eq 'Community') {
15410: $ccrole = 'co';
15411: }
15412: my %roleshash =
15413: &Apache::lonnet::get_my_roles($args->{'ccuname'},
15414: $args->{'ccdomain'},
15415: 'userroles',['active'],[$ccrole],
15416: [$args->{'clonedomain'}]);
15417: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
15418: $can_clone = 1;
15419: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
15420: $args->{'ccuname'},$args->{'ccdomain'})) {
15421: $can_clone = 1;
1.1221 raeburn 15422: }
15423: }
15424: unless ($can_clone) {
15425: if ($args->{'crstype'} eq 'Community') {
15426: $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'});
1.942 raeburn 15427: } else {
1.1221 raeburn 15428: $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'});
15429: }
1.566 albertel 15430: }
1.578 raeburn 15431: }
1.566 albertel 15432: }
15433: return ($can_clone, $clonemsg, $cloneid, $clonehome);
15434: }
15435:
1.444 albertel 15436: sub construct_course {
1.1262 raeburn 15437: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,
15438: $cnum,$category,$coderef) = @_;
1.444 albertel 15439: my $outcome;
1.541 raeburn 15440: my $linefeed = '<br />'."\n";
15441: if ($context eq 'auto') {
15442: $linefeed = "\n";
15443: }
1.566 albertel 15444:
15445: #
15446: # Are we cloning?
15447: #
15448: my ($can_clone, $clonemsg, $cloneid, $clonehome);
15449: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 15450: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 15451: if ($context ne 'auto') {
1.578 raeburn 15452: if ($clonemsg ne '') {
15453: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
15454: }
1.566 albertel 15455: }
15456: $outcome .= $clonemsg.$linefeed;
15457:
15458: if (!$can_clone) {
15459: return (0,$outcome);
15460: }
15461: }
15462:
1.444 albertel 15463: #
15464: # Open course
15465: #
1.1239 raeburn 15466: my $showncrstype;
15467: if ($args->{'crstype'} eq 'Placement') {
15468: $showncrstype = 'placement test';
15469: } else {
15470: $showncrstype = lc($args->{'crstype'});
15471: }
1.444 albertel 15472: my %cenv=();
15473: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
15474: $args->{'cdescr'},
15475: $args->{'curl'},
15476: $args->{'course_home'},
15477: $args->{'nonstandard'},
15478: $args->{'crscode'},
15479: $args->{'ccuname'}.':'.
15480: $args->{'ccdomain'},
1.882 raeburn 15481: $args->{'crstype'},
1.885 raeburn 15482: $cnum,$context,$category);
1.444 albertel 15483:
15484: # Note: The testing routines depend on this being output; see
15485: # Utils::Course. This needs to at least be output as a comment
15486: # if anyone ever decides to not show this, and Utils::Course::new
15487: # will need to be suitably modified.
1.1239 raeburn 15488: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
1.943 raeburn 15489: if ($$courseid =~ /^error:/) {
15490: return (0,$outcome);
15491: }
15492:
1.444 albertel 15493: #
15494: # Check if created correctly
15495: #
1.479 albertel 15496: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 15497: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 15498: if ($crsuhome eq 'no_host') {
15499: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
15500: return (0,$outcome);
15501: }
1.541 raeburn 15502: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 15503:
1.444 albertel 15504: #
1.566 albertel 15505: # Do the cloning
15506: #
15507: if ($can_clone && $cloneid) {
1.1239 raeburn 15508: $clonemsg = &mt('Cloning [_1] from [_2]',$showncrstype,$clonehome);
1.566 albertel 15509: if ($context ne 'auto') {
15510: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
15511: }
15512: $outcome .= $clonemsg.$linefeed;
15513: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 15514: # Copy all files
1.637 www 15515: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 15516: # Restore URL
1.566 albertel 15517: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 15518: # Restore title
1.566 albertel 15519: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 15520: # Restore creation date, creator and creation context.
15521: $cenv{'internal.created'}=$oldcenv{'internal.created'};
15522: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
15523: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 15524: # Mark as cloned
1.566 albertel 15525: $cenv{'clonedfrom'}=$cloneid;
1.638 www 15526: # Need to clone grading mode
15527: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
15528: $cenv{'grading'}=$newenv{'grading'};
15529: # Do not clone these environment entries
15530: &Apache::lonnet::del('environment',
15531: ['default_enrollment_start_date',
15532: 'default_enrollment_end_date',
15533: 'question.email',
15534: 'policy.email',
15535: 'comment.email',
15536: 'pch.users.denied',
1.725 raeburn 15537: 'plc.users.denied',
15538: 'hidefromcat',
1.1121 raeburn 15539: 'checkforpriv',
1.1166 raeburn 15540: 'categories',
15541: 'internal.uniquecode'],
1.638 www 15542: $$crsudom,$$crsunum);
1.1170 raeburn 15543: if ($args->{'textbook'}) {
15544: $cenv{'internal.textbook'} = $args->{'textbook'};
15545: }
1.444 albertel 15546: }
1.566 albertel 15547:
1.444 albertel 15548: #
15549: # Set environment (will override cloned, if existing)
15550: #
15551: my @sections = ();
15552: my @xlists = ();
15553: if ($args->{'crstype'}) {
15554: $cenv{'type'}=$args->{'crstype'};
15555: }
15556: if ($args->{'crsid'}) {
15557: $cenv{'courseid'}=$args->{'crsid'};
15558: }
15559: if ($args->{'crscode'}) {
15560: $cenv{'internal.coursecode'}=$args->{'crscode'};
15561: }
15562: if ($args->{'crsquota'} ne '') {
15563: $cenv{'internal.coursequota'}=$args->{'crsquota'};
15564: } else {
15565: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
15566: }
15567: if ($args->{'ccuname'}) {
15568: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
15569: ':'.$args->{'ccdomain'};
15570: } else {
15571: $cenv{'internal.courseowner'} = $args->{'curruser'};
15572: }
1.1116 raeburn 15573: if ($args->{'defaultcredits'}) {
15574: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
15575: }
1.444 albertel 15576: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
15577: if ($args->{'crssections'}) {
15578: $cenv{'internal.sectionnums'} = '';
15579: if ($args->{'crssections'} =~ m/,/) {
15580: @sections = split/,/,$args->{'crssections'};
15581: } else {
15582: $sections[0] = $args->{'crssections'};
15583: }
15584: if (@sections > 0) {
15585: foreach my $item (@sections) {
15586: my ($sec,$gp) = split/:/,$item;
15587: my $class = $args->{'crscode'}.$sec;
15588: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15589: $cenv{'internal.sectionnums'} .= $item.',';
15590: unless ($addcheck eq 'ok') {
1.1263 raeburn 15591: push(@badclasses,$class);
1.444 albertel 15592: }
15593: }
15594: $cenv{'internal.sectionnums'} =~ s/,$//;
15595: }
15596: }
15597: # do not hide course coordinator from staff listing,
15598: # even if privileged
15599: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 15600: # add course coordinator's domain to domains to check for privileged users
15601: # if different to course domain
15602: if ($$crsudom ne $args->{'ccdomain'}) {
15603: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15604: }
1.444 albertel 15605: # add crosslistings
15606: if ($args->{'crsxlist'}) {
15607: $cenv{'internal.crosslistings'}='';
15608: if ($args->{'crsxlist'} =~ m/,/) {
15609: @xlists = split/,/,$args->{'crsxlist'};
15610: } else {
15611: $xlists[0] = $args->{'crsxlist'};
15612: }
15613: if (@xlists > 0) {
15614: foreach my $item (@xlists) {
15615: my ($xl,$gp) = split/:/,$item;
15616: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15617: $cenv{'internal.crosslistings'} .= $item.',';
15618: unless ($addcheck eq 'ok') {
1.1263 raeburn 15619: push(@badclasses,$xl);
1.444 albertel 15620: }
15621: }
15622: $cenv{'internal.crosslistings'} =~ s/,$//;
15623: }
15624: }
15625: if ($args->{'autoadds'}) {
15626: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15627: }
15628: if ($args->{'autodrops'}) {
15629: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15630: }
15631: # check for notification of enrollment changes
15632: my @notified = ();
15633: if ($args->{'notify_owner'}) {
15634: if ($args->{'ccuname'} ne '') {
15635: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15636: }
15637: }
15638: if ($args->{'notify_dc'}) {
15639: if ($uname ne '') {
1.630 raeburn 15640: push(@notified,$uname.':'.$udom);
1.444 albertel 15641: }
15642: }
15643: if (@notified > 0) {
15644: my $notifylist;
15645: if (@notified > 1) {
15646: $notifylist = join(',',@notified);
15647: } else {
15648: $notifylist = $notified[0];
15649: }
15650: $cenv{'internal.notifylist'} = $notifylist;
15651: }
15652: if (@badclasses > 0) {
15653: my %lt=&Apache::lonlocal::texthash(
1.1264 raeburn 15654: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course.',
15655: 'howi' => 'However, if automated course roster updates are enabled for this class, these particular sections/crosslistings are not guaranteed to contribute towards enrollment.',
15656: 'itis' => 'It is possible that rights to access enrollment for these classes will be available through assignment of co-owners.',
1.444 albertel 15657: );
1.1264 raeburn 15658: my $badclass_msg = $lt{'tclb'}.$linefeed.$lt{'howi'}.$linefeed.
15659: &mt('That is because the user identified as the course owner ([_1]) does not have rights to access enrollment in these classes, as determined by the policies of your institution on access to official classlists',$cenv{'internal.courseowner'}).$linefeed.$lt{'itis'};
1.541 raeburn 15660: if ($context eq 'auto') {
15661: $outcome .= $badclass_msg.$linefeed;
1.1261 raeburn 15662: } else {
1.566 albertel 15663: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.1261 raeburn 15664: }
15665: foreach my $item (@badclasses) {
1.541 raeburn 15666: if ($context eq 'auto') {
1.1261 raeburn 15667: $outcome .= " - $item\n";
1.541 raeburn 15668: } else {
1.1261 raeburn 15669: $outcome .= "<li>$item</li>\n";
1.541 raeburn 15670: }
1.1261 raeburn 15671: }
15672: if ($context eq 'auto') {
15673: $outcome .= $linefeed;
15674: } else {
15675: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 15676: }
1.444 albertel 15677: }
15678: if ($args->{'no_end_date'}) {
15679: $args->{'endaccess'} = 0;
15680: }
15681: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15682: $cenv{'internal.autoend'}=$args->{'enrollend'};
15683: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15684: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15685: if ($args->{'showphotos'}) {
15686: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15687: }
15688: $cenv{'internal.authtype'} = $args->{'authtype'};
15689: $cenv{'internal.autharg'} = $args->{'autharg'};
15690: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15691: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15692: 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');
15693: if ($context eq 'auto') {
15694: $outcome .= $krb_msg;
15695: } else {
1.566 albertel 15696: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15697: }
15698: $outcome .= $linefeed;
1.444 albertel 15699: }
15700: }
15701: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15702: if ($args->{'setpolicy'}) {
15703: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15704: }
15705: if ($args->{'setcontent'}) {
15706: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15707: }
1.1251 raeburn 15708: if ($args->{'setcomment'}) {
15709: $cenv{'comment.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15710: }
1.444 albertel 15711: }
15712: if ($args->{'reshome'}) {
15713: $cenv{'reshome'}=$args->{'reshome'}.'/';
15714: $cenv{'reshome'}=~s/\/+$/\//;
15715: }
15716: #
15717: # course has keyed access
15718: #
15719: if ($args->{'setkeys'}) {
15720: $cenv{'keyaccess'}='yes';
15721: }
15722: # if specified, key authority is not course, but user
15723: # only active if keyaccess is yes
15724: if ($args->{'keyauth'}) {
1.487 albertel 15725: my ($user,$domain) = split(':',$args->{'keyauth'});
15726: $user = &LONCAPA::clean_username($user);
15727: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15728: if ($user ne '' && $domain ne '') {
1.487 albertel 15729: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15730: }
15731: }
15732:
1.1166 raeburn 15733: #
1.1167 raeburn 15734: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 15735: #
15736: if ($args->{'uniquecode'}) {
15737: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15738: if ($code) {
15739: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 15740: my %crsinfo =
15741: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15742: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15743: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15744: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15745: }
1.1166 raeburn 15746: if (ref($coderef)) {
15747: $$coderef = $code;
15748: }
15749: }
15750: }
15751:
1.444 albertel 15752: if ($args->{'disresdis'}) {
15753: $cenv{'pch.roles.denied'}='st';
15754: }
15755: if ($args->{'disablechat'}) {
15756: $cenv{'plc.roles.denied'}='st';
15757: }
15758:
15759: # Record we've not yet viewed the Course Initialization Helper for this
15760: # course
15761: $cenv{'course.helper.not.run'} = 1;
15762: #
15763: # Use new Randomseed
15764: #
15765: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15766: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15767: #
15768: # The encryption code and receipt prefix for this course
15769: #
15770: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15771: $cenv{'internal.encpref'}=100+int(9*rand(99));
15772: #
15773: # By default, use standard grading
15774: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15775:
1.541 raeburn 15776: $outcome .= $linefeed.&mt('Setting environment').': '.
15777: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15778: #
15779: # Open all assignments
15780: #
15781: if ($args->{'openall'}) {
15782: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15783: my %storecontent = ($storeunder => time,
15784: $storeunder.'.type' => 'date_start');
15785:
15786: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15787: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15788: }
15789: #
15790: # Set first page
15791: #
15792: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15793: || ($cloneid)) {
1.445 albertel 15794: use LONCAPA::map;
1.444 albertel 15795: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15796:
15797: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15798: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15799:
1.444 albertel 15800: $outcome .= ($fatal?$errtext:'read ok').' - ';
15801: my $title; my $url;
15802: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15803: $title=&mt('Syllabus');
1.444 albertel 15804: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15805: } else {
1.963 raeburn 15806: $title=&mt('Table of Contents');
1.444 albertel 15807: $url='/adm/navmaps';
15808: }
1.445 albertel 15809:
15810: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15811: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15812:
15813: if ($errtext) { $fatal=2; }
1.541 raeburn 15814: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15815: }
1.566 albertel 15816:
1.1237 raeburn 15817: #
15818: # Set params for Placement Tests
15819: #
1.1239 raeburn 15820: if ($args->{'crstype'} eq 'Placement') {
15821: my %storecontent;
15822: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
15823: my %defaults = (
15824: buttonshide => { value => 'yes',
15825: type => 'string_yesno',},
15826: type => { value => 'randomizetry',
15827: type => 'string_questiontype',},
15828: maxtries => { value => 1,
15829: type => 'int_pos',},
15830: problemstatus => { value => 'no',
15831: type => 'string_problemstatus',},
15832: );
15833: foreach my $key (keys(%defaults)) {
15834: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
15835: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
15836: }
1.1237 raeburn 15837: &Apache::lonnet::cput
15838: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
15839: }
15840:
1.566 albertel 15841: return (1,$outcome);
1.444 albertel 15842: }
15843:
1.1166 raeburn 15844: sub make_unique_code {
15845: my ($cdom,$cnum) = @_;
15846: # get lock on uniquecodes db
15847: my $lockhash = {
15848: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15849: ':'.$env{'user.domain'},
15850: };
15851: my $tries = 0;
15852: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15853: my ($code,$error);
15854:
15855: while (($gotlock ne 'ok') && ($tries<3)) {
15856: $tries ++;
15857: sleep 1;
15858: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15859: }
15860: if ($gotlock eq 'ok') {
15861: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15862: my $gotcode;
15863: my $attempts = 0;
15864: while ((!$gotcode) && ($attempts < 100)) {
15865: $code = &generate_code();
15866: if (!exists($currcodes{$code})) {
15867: $gotcode = 1;
15868: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15869: $error = 'nostore';
15870: }
15871: }
15872: $attempts ++;
15873: }
15874: my @del_lock = ($cnum."\0".'uniquecodes');
15875: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15876: } else {
15877: $error = 'nolock';
15878: }
15879: return ($code,$error);
15880: }
15881:
15882: sub generate_code {
15883: my $code;
15884: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15885: for (my $i=0; $i<6; $i++) {
15886: my $lettnum = int (rand 2);
15887: my $item = '';
15888: if ($lettnum) {
15889: $item = $letts[int( rand(18) )];
15890: } else {
15891: $item = 1+int( rand(8) );
15892: }
15893: $code .= $item;
15894: }
15895: return $code;
15896: }
15897:
1.444 albertel 15898: ############################################################
15899: ############################################################
15900:
1.1237 raeburn 15901: # Community, Course and Placement Test
1.378 raeburn 15902: sub course_type {
15903: my ($cid) = @_;
15904: if (!defined($cid)) {
15905: $cid = $env{'request.course.id'};
15906: }
1.404 albertel 15907: if (defined($env{'course.'.$cid.'.type'})) {
15908: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15909: } else {
15910: return 'Course';
1.377 raeburn 15911: }
15912: }
1.156 albertel 15913:
1.406 raeburn 15914: sub group_term {
15915: my $crstype = &course_type();
15916: my %names = (
15917: 'Course' => 'group',
1.865 raeburn 15918: 'Community' => 'group',
1.1237 raeburn 15919: 'Placement' => 'group',
1.406 raeburn 15920: );
15921: return $names{$crstype};
15922: }
15923:
1.902 raeburn 15924: sub course_types {
1.1237 raeburn 15925: my @types = ('official','unofficial','community','textbook','placement');
1.902 raeburn 15926: my %typename = (
15927: official => 'Official course',
15928: unofficial => 'Unofficial course',
15929: community => 'Community',
1.1165 raeburn 15930: textbook => 'Textbook course',
1.1237 raeburn 15931: placement => 'Placement test',
1.902 raeburn 15932: );
15933: return (\@types,\%typename);
15934: }
15935:
1.156 albertel 15936: sub icon {
15937: my ($file)=@_;
1.505 albertel 15938: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15939: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15940: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15941: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15942: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15943: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15944: $curfext.".gif") {
15945: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15946: $curfext.".gif";
15947: }
15948: }
1.249 albertel 15949: return &lonhttpdurl($iconname);
1.154 albertel 15950: }
1.84 albertel 15951:
1.575 albertel 15952: sub lonhttpdurl {
1.692 www 15953: #
15954: # Had been used for "small fry" static images on separate port 8080.
15955: # Modify here if lightweight http functionality desired again.
15956: # Currently eliminated due to increasing firewall issues.
15957: #
1.575 albertel 15958: my ($url)=@_;
1.692 www 15959: return $url;
1.215 albertel 15960: }
15961:
1.213 albertel 15962: sub connection_aborted {
15963: my ($r)=@_;
15964: $r->print(" ");$r->rflush();
15965: my $c = $r->connection;
15966: return $c->aborted();
15967: }
15968:
1.221 foxr 15969: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15970: # strings as 'strings'.
15971: sub escape_single {
1.221 foxr 15972: my ($input) = @_;
1.223 albertel 15973: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15974: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15975: return $input;
15976: }
1.223 albertel 15977:
1.222 foxr 15978: # Same as escape_single, but escape's "'s This
15979: # can be used for "strings"
15980: sub escape_double {
15981: my ($input) = @_;
15982: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15983: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15984: return $input;
15985: }
1.223 albertel 15986:
1.222 foxr 15987: # Escapes the last element of a full URL.
15988: sub escape_url {
15989: my ($url) = @_;
1.238 raeburn 15990: my @urlslices = split(/\//, $url,-1);
1.369 www 15991: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 15992: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15993: }
1.462 albertel 15994:
1.820 raeburn 15995: sub compare_arrays {
15996: my ($arrayref1,$arrayref2) = @_;
15997: my (@difference,%count);
15998: @difference = ();
15999: %count = ();
16000: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
16001: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
16002: foreach my $element (keys(%count)) {
16003: if ($count{$element} == 1) {
16004: push(@difference,$element);
16005: }
16006: }
16007: }
16008: return @difference;
16009: }
16010:
1.817 bisitz 16011: # -------------------------------------------------------- Initialize user login
1.462 albertel 16012: sub init_user_environment {
1.463 albertel 16013: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 16014: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
16015:
16016: my $public=($username eq 'public' && $domain eq 'public');
16017:
16018: # See if old ID present, if so, remove
16019:
1.1062 raeburn 16020: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 16021: my $now=time;
16022:
16023: if ($public) {
16024: my $max_public=100;
16025: my $oldest;
16026: my $oldest_time=0;
16027: for(my $next=1;$next<=$max_public;$next++) {
16028: if (-e $lonids."/publicuser_$next.id") {
16029: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
16030: if ($mtime<$oldest_time || !$oldest_time) {
16031: $oldest_time=$mtime;
16032: $oldest=$next;
16033: }
16034: } else {
16035: $cookie="publicuser_$next";
16036: last;
16037: }
16038: }
16039: if (!$cookie) { $cookie="publicuser_$oldest"; }
16040: } else {
1.463 albertel 16041: # if this isn't a robot, kill any existing non-robot sessions
16042: if (!$args->{'robot'}) {
16043: opendir(DIR,$lonids);
16044: while ($filename=readdir(DIR)) {
16045: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
16046: unlink($lonids.'/'.$filename);
16047: }
1.462 albertel 16048: }
1.463 albertel 16049: closedir(DIR);
1.1204 raeburn 16050: # If there is a undeleted lockfile for the user's paste buffer remove it.
16051: my $namespace = 'nohist_courseeditor';
16052: my $lockingkey = 'paste'."\0".'locked_num';
16053: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
16054: $domain,$username);
16055: if (exists($lockhash{$lockingkey})) {
16056: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
16057: unless ($delresult eq 'ok') {
16058: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
16059: }
16060: }
1.462 albertel 16061: }
16062: # Give them a new cookie
1.463 albertel 16063: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 16064: : $now.$$.int(rand(10000)));
1.463 albertel 16065: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 16066:
16067: # Initialize roles
16068:
1.1062 raeburn 16069: ($userroles,$firstaccenv,$timerintenv) =
16070: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 16071: }
16072: # ------------------------------------ Check browser type and MathML capability
16073:
1.1194 raeburn 16074: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
16075: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 16076:
16077: # ------------------------------------------------------------- Get environment
16078:
16079: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
16080: my ($tmp) = keys(%userenv);
16081: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
16082: } else {
16083: undef(%userenv);
16084: }
16085: if (($userenv{'interface'}) && (!$form->{'interface'})) {
16086: $form->{'interface'}=$userenv{'interface'};
16087: }
16088: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
16089:
16090: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 16091: foreach my $option ('interface','localpath','localres') {
16092: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 16093: }
16094: # --------------------------------------------------------- Write first profile
16095:
16096: {
16097: my %initial_env =
16098: ("user.name" => $username,
16099: "user.domain" => $domain,
16100: "user.home" => $authhost,
16101: "browser.type" => $clientbrowser,
16102: "browser.version" => $clientversion,
16103: "browser.mathml" => $clientmathml,
16104: "browser.unicode" => $clientunicode,
16105: "browser.os" => $clientos,
1.1137 raeburn 16106: "browser.mobile" => $clientmobile,
1.1141 raeburn 16107: "browser.info" => $clientinfo,
1.1194 raeburn 16108: "browser.osversion" => $clientosversion,
1.462 albertel 16109: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
16110: "request.course.fn" => '',
16111: "request.course.uri" => '',
16112: "request.course.sec" => '',
16113: "request.role" => 'cm',
16114: "request.role.adv" => $env{'user.adv'},
16115: "request.host" => $ENV{'REMOTE_ADDR'},);
16116:
16117: if ($form->{'localpath'}) {
16118: $initial_env{"browser.localpath"} = $form->{'localpath'};
16119: $initial_env{"browser.localres"} = $form->{'localres'};
16120: }
16121:
16122: if ($form->{'interface'}) {
16123: $form->{'interface'}=~s/\W//gs;
16124: $initial_env{"browser.interface"} = $form->{'interface'};
16125: $env{'browser.interface'}=$form->{'interface'};
16126: }
16127:
1.1157 raeburn 16128: if ($form->{'iptoken'}) {
16129: my $lonhost = $r->dir_config('lonHostID');
16130: $initial_env{"user.noloadbalance"} = $lonhost;
16131: $env{'user.noloadbalance'} = $lonhost;
16132: }
16133:
1.1268 raeburn 16134: if ($form->{'noloadbalance'}) {
16135: my @hosts = &Apache::lonnet::current_machine_ids();
16136: my $hosthere = $form->{'noloadbalance'};
16137: if (grep(/^\Q$hosthere\E$/,@hosts)) {
16138: $initial_env{"user.noloadbalance"} = $hosthere;
16139: $env{'user.noloadbalance'} = $hosthere;
16140: }
16141: }
16142:
1.1016 raeburn 16143: unless ($domain eq 'public') {
1.1273 raeburn 16144: my %is_adv = ( is_adv => $env{'user.adv'} );
16145: my %domdef = &Apache::lonnet::get_domain_defaults($domain);
16146:
16147: foreach my $tool ('aboutme','blog','webdav','portfolio') {
16148: $userenv{'availabletools.'.$tool} =
16149: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
16150: undef,\%userenv,\%domdef,\%is_adv);
16151: }
1.980 raeburn 16152:
1.1273 raeburn 16153: foreach my $crstype ('official','unofficial','community','textbook','placement') {
16154: $userenv{'canrequest.'.$crstype} =
16155: &Apache::lonnet::usertools_access($username,$domain,$crstype,
16156: 'reload','requestcourses',
16157: \%userenv,\%domdef,\%is_adv);
16158: }
1.724 raeburn 16159:
1.1273 raeburn 16160: $userenv{'canrequest.author'} =
16161: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
16162: 'reload','requestauthor',
1.980 raeburn 16163: \%userenv,\%domdef,\%is_adv);
1.1273 raeburn 16164: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
16165: $domain,$username);
16166: my $reqstatus = $reqauthor{'author_status'};
16167: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
16168: if (ref($reqauthor{'author'}) eq 'HASH') {
16169: $userenv{'requestauthorqueued'} = $reqstatus.':'.
16170: $reqauthor{'author'}{'timestamp'};
16171: }
1.1092 raeburn 16172: }
16173: }
16174:
1.462 albertel 16175: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 16176:
1.462 albertel 16177: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
16178: &GDBM_WRCREAT(),0640)) {
16179: &_add_to_env(\%disk_env,\%initial_env);
16180: &_add_to_env(\%disk_env,\%userenv,'environment.');
16181: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 16182: if (ref($firstaccenv) eq 'HASH') {
16183: &_add_to_env(\%disk_env,$firstaccenv);
16184: }
16185: if (ref($timerintenv) eq 'HASH') {
16186: &_add_to_env(\%disk_env,$timerintenv);
16187: }
1.463 albertel 16188: if (ref($args->{'extra_env'})) {
16189: &_add_to_env(\%disk_env,$args->{'extra_env'});
16190: }
1.462 albertel 16191: untie(%disk_env);
16192: } else {
1.705 tempelho 16193: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
16194: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 16195: return 'error: '.$!;
16196: }
16197: }
16198: $env{'request.role'}='cm';
16199: $env{'request.role.adv'}=$env{'user.adv'};
16200: $env{'browser.type'}=$clientbrowser;
16201:
16202: return $cookie;
16203:
16204: }
16205:
16206: sub _add_to_env {
16207: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 16208: if (ref($env_data) eq 'HASH') {
16209: while (my ($key,$value) = each(%$env_data)) {
16210: $idf->{$prefix.$key} = $value;
16211: $env{$prefix.$key} = $value;
16212: }
1.462 albertel 16213: }
16214: }
16215:
1.685 tempelho 16216: # --- Get the symbolic name of a problem and the url
16217: sub get_symb {
16218: my ($request,$silent) = @_;
1.726 raeburn 16219: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 16220: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
16221: if ($symb eq '') {
16222: if (!$silent) {
1.1071 raeburn 16223: if (ref($request)) {
16224: $request->print("Unable to handle ambiguous references:$url:.");
16225: }
1.685 tempelho 16226: return ();
16227: }
16228: }
16229: &Apache::lonenc::check_decrypt(\$symb);
16230: return ($symb);
16231: }
16232:
16233: # --------------------------------------------------------------Get annotation
16234:
16235: sub get_annotation {
16236: my ($symb,$enc) = @_;
16237:
16238: my $key = $symb;
16239: if (!$enc) {
16240: $key =
16241: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
16242: }
16243: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
16244: return $annotation{$key};
16245: }
16246:
16247: sub clean_symb {
1.731 raeburn 16248: my ($symb,$delete_enc) = @_;
1.685 tempelho 16249:
16250: &Apache::lonenc::check_decrypt(\$symb);
16251: my $enc = $env{'request.enc'};
1.731 raeburn 16252: if ($delete_enc) {
1.730 raeburn 16253: delete($env{'request.enc'});
16254: }
1.685 tempelho 16255:
16256: return ($symb,$enc);
16257: }
1.462 albertel 16258:
1.1181 raeburn 16259: ############################################################
16260: ############################################################
16261:
16262: =pod
16263:
16264: =head1 Routines for building display used to search for courses
16265:
16266:
16267: =over 4
16268:
16269: =item * &build_filters()
16270:
16271: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 16272: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
16273: and quotacheck.pl
16274:
1.1181 raeburn 16275:
16276: Inputs:
16277:
16278: filterlist - anonymous array of fields to include as potential filters
16279:
16280: crstype - course type
16281:
16282: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
16283: to pop-open a course selector (will contain "extra element").
16284:
16285: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
16286:
16287: filter - anonymous hash of criteria and their values
16288:
16289: action - form action
16290:
16291: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
16292:
1.1182 raeburn 16293: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 16294:
16295: cloneruname - username of owner of new course who wants to clone
16296:
16297: clonerudom - domain of owner of new course who wants to clone
16298:
16299: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
16300:
16301: codetitlesref - reference to array of titles of components in institutional codes (official courses)
16302:
16303: codedom - domain
16304:
16305: formname - value of form element named "form".
16306:
16307: fixeddom - domain, if fixed.
16308:
16309: prevphase - value to assign to form element named "phase" when going back to the previous screen
16310:
16311: cnameelement - name of form element in form on opener page which will receive title of selected course
16312:
16313: cnumelement - name of form element in form on opener page which will receive courseID of selected course
16314:
16315: cdomelement - name of form element in form on opener page which will receive domain of selected course
16316:
16317: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
16318:
16319: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
16320:
16321: clonewarning - warning message about missing information for intended course owner when DC creates a course
16322:
1.1182 raeburn 16323:
1.1181 raeburn 16324: Returns: $output - HTML for display of search criteria, and hidden form elements.
16325:
1.1182 raeburn 16326:
1.1181 raeburn 16327: Side Effects: None
16328:
16329: =cut
16330:
16331: # ---------------------------------------------- search for courses based on last activity etc.
16332:
16333: sub build_filters {
16334: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
16335: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
16336: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
16337: $cnameelement,$cnumelement,$cdomelement,$setroles,
16338: $clonetext,$clonewarning) = @_;
1.1182 raeburn 16339: my ($list,$jscript);
1.1181 raeburn 16340: my $onchange = 'javascript:updateFilters(this)';
16341: my ($domainselectform,$sincefilterform,$createdfilterform,
16342: $ownerdomselectform,$persondomselectform,$instcodeform,
16343: $typeselectform,$instcodetitle);
16344: if ($formname eq '') {
16345: $formname = $caller;
16346: }
16347: foreach my $item (@{$filterlist}) {
16348: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
16349: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
16350: if ($item eq 'domainfilter') {
16351: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
16352: } elsif ($item eq 'coursefilter') {
16353: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
16354: } elsif ($item eq 'ownerfilter') {
16355: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16356: } elsif ($item eq 'ownerdomfilter') {
16357: $filter->{'ownerdomfilter'} =
16358: &LONCAPA::clean_domain($filter->{$item});
16359: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
16360: 'ownerdomfilter',1);
16361: } elsif ($item eq 'personfilter') {
16362: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
16363: } elsif ($item eq 'persondomfilter') {
16364: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
16365: 'persondomfilter',1);
16366: } else {
16367: $filter->{$item} =~ s/\W//g;
16368: }
16369: if (!$filter->{$item}) {
16370: $filter->{$item} = '';
16371: }
16372: }
16373: if ($item eq 'domainfilter') {
16374: my $allow_blank = 1;
16375: if ($formname eq 'portform') {
16376: $allow_blank=0;
16377: } elsif ($formname eq 'studentform') {
16378: $allow_blank=0;
16379: }
16380: if ($fixeddom) {
16381: $domainselectform = '<input type="hidden" name="domainfilter"'.
16382: ' value="'.$codedom.'" />'.
16383: &Apache::lonnet::domain($codedom,'description');
16384: } else {
16385: $domainselectform = &select_dom_form($filter->{$item},
16386: 'domainfilter',
16387: $allow_blank,'',$onchange);
16388: }
16389: } else {
16390: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
16391: }
16392: }
16393:
16394: # last course activity filter and selection
16395: $sincefilterform = &timebased_select_form('sincefilter',$filter);
16396:
16397: # course created filter and selection
16398: if (exists($filter->{'createdfilter'})) {
16399: $createdfilterform = &timebased_select_form('createdfilter',$filter);
16400: }
16401:
1.1239 raeburn 16402: my $prefix = $crstype;
16403: if ($crstype eq 'Placement') {
16404: $prefix = 'Placement Test'
16405: }
1.1181 raeburn 16406: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 16407: 'cac' => "$prefix Activity",
16408: 'ccr' => "$prefix Created",
16409: 'cde' => "$prefix Title",
16410: 'cdo' => "$prefix Domain",
1.1181 raeburn 16411: 'ins' => 'Institutional Code',
16412: 'inc' => 'Institutional Categorization',
1.1239 raeburn 16413: 'cow' => "$prefix Owner/Co-owner",
16414: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 16415: 'cog' => 'Type',
16416: );
16417:
16418: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16419: my $typeval = 'Course';
16420: if ($crstype eq 'Community') {
16421: $typeval = 'Community';
1.1239 raeburn 16422: } elsif ($crstype eq 'Placement') {
16423: $typeval = 'Placement';
1.1181 raeburn 16424: }
16425: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
16426: } else {
16427: $typeselectform = '<select name="type" size="1"';
16428: if ($onchange) {
16429: $typeselectform .= ' onchange="'.$onchange.'"';
16430: }
16431: $typeselectform .= '>'."\n";
1.1237 raeburn 16432: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 16433: my $shown;
16434: if ($posstype eq 'Placement') {
16435: $shown = &mt('Placement Test');
16436: } else {
16437: $shown = &mt($posstype);
16438: }
1.1181 raeburn 16439: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 16440: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 16441: }
16442: $typeselectform.="</select>";
16443: }
16444:
16445: my ($cloneableonlyform,$cloneabletitle);
16446: if (exists($filter->{'cloneableonly'})) {
16447: my $cloneableon = '';
16448: my $cloneableoff = ' checked="checked"';
16449: if ($filter->{'cloneableonly'}) {
16450: $cloneableon = $cloneableoff;
16451: $cloneableoff = '';
16452: }
16453: $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>';
16454: if ($formname eq 'ccrs') {
1.1187 bisitz 16455: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 16456: } else {
16457: $cloneabletitle = &mt('Cloneable by you');
16458: }
16459: }
16460: my $officialjs;
16461: if ($crstype eq 'Course') {
16462: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 16463: # if (($fixeddom) || ($formname eq 'requestcrs') ||
16464: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
16465: if ($codedom) {
1.1181 raeburn 16466: $officialjs = 1;
16467: ($instcodeform,$jscript,$$numtitlesref) =
16468: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
16469: $officialjs,$codetitlesref);
16470: if ($jscript) {
1.1182 raeburn 16471: $jscript = '<script type="text/javascript">'."\n".
16472: '// <![CDATA['."\n".
16473: $jscript."\n".
16474: '// ]]>'."\n".
16475: '</script>'."\n";
1.1181 raeburn 16476: }
16477: }
16478: if ($instcodeform eq '') {
16479: $instcodeform =
16480: '<input type="text" name="instcodefilter" size="10" value="'.
16481: $list->{'instcodefilter'}.'" />';
16482: $instcodetitle = $lt{'ins'};
16483: } else {
16484: $instcodetitle = $lt{'inc'};
16485: }
16486: if ($fixeddom) {
16487: $instcodetitle .= '<br />('.$codedom.')';
16488: }
16489: }
16490: }
16491: my $output = qq|
16492: <form method="post" name="filterpicker" action="$action">
16493: <input type="hidden" name="form" value="$formname" />
16494: |;
16495: if ($formname eq 'modifycourse') {
16496: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
16497: '<input type="hidden" name="prevphase" value="'.
16498: $prevphase.'" />'."\n";
1.1198 musolffc 16499: } elsif ($formname eq 'quotacheck') {
16500: $output .= qq|
16501: <input type="hidden" name="sortby" value="" />
16502: <input type="hidden" name="sortorder" value="" />
16503: |;
16504: } else {
1.1181 raeburn 16505: my $name_input;
16506: if ($cnameelement ne '') {
16507: $name_input = '<input type="hidden" name="cnameelement" value="'.
16508: $cnameelement.'" />';
16509: }
16510: $output .= qq|
1.1182 raeburn 16511: <input type="hidden" name="cnumelement" value="$cnumelement" />
16512: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 16513: $name_input
16514: $roleelement
16515: $multelement
16516: $typeelement
16517: |;
16518: if ($formname eq 'portform') {
16519: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
16520: }
16521: }
16522: if ($fixeddom) {
16523: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
16524: }
16525: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
16526: if ($sincefilterform) {
16527: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
16528: .$sincefilterform
16529: .&Apache::lonhtmlcommon::row_closure();
16530: }
16531: if ($createdfilterform) {
16532: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
16533: .$createdfilterform
16534: .&Apache::lonhtmlcommon::row_closure();
16535: }
16536: if ($domainselectform) {
16537: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
16538: .$domainselectform
16539: .&Apache::lonhtmlcommon::row_closure();
16540: }
16541: if ($typeselectform) {
16542: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
16543: $output .= $typeselectform;
16544: } else {
16545: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
16546: .$typeselectform
16547: .&Apache::lonhtmlcommon::row_closure();
16548: }
16549: }
16550: if ($instcodeform) {
16551: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
16552: .$instcodeform
16553: .&Apache::lonhtmlcommon::row_closure();
16554: }
16555: if (exists($filter->{'ownerfilter'})) {
16556: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
16557: '<table><tr><td>'.&mt('Username').'<br />'.
16558: '<input type="text" name="ownerfilter" size="20" value="'.
16559: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16560: $ownerdomselectform.'</td></tr></table>'.
16561: &Apache::lonhtmlcommon::row_closure();
16562: }
16563: if (exists($filter->{'personfilter'})) {
16564: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
16565: '<table><tr><td>'.&mt('Username').'<br />'.
16566: '<input type="text" name="personfilter" size="20" value="'.
16567: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
16568: $persondomselectform.'</td></tr></table>'.
16569: &Apache::lonhtmlcommon::row_closure();
16570: }
16571: if (exists($filter->{'coursefilter'})) {
16572: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
16573: .'<input type="text" name="coursefilter" size="25" value="'
16574: .$list->{'coursefilter'}.'" />'
16575: .&Apache::lonhtmlcommon::row_closure();
16576: }
16577: if ($cloneableonlyform) {
16578: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
16579: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
16580: }
16581: if (exists($filter->{'descriptfilter'})) {
16582: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
16583: .'<input type="text" name="descriptfilter" size="40" value="'
16584: .$list->{'descriptfilter'}.'" />'
16585: .&Apache::lonhtmlcommon::row_closure(1);
16586: }
16587: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
16588: '<input type="hidden" name="updater" value="" />'."\n".
16589: '<input type="submit" name="gosearch" value="'.
16590: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16591: return $jscript.$clonewarning.$output;
16592: }
16593:
16594: =pod
16595:
16596: =item * &timebased_select_form()
16597:
1.1182 raeburn 16598: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 16599: filter e.g., Course Activity, Course Created, when searching for courses
16600: or communities
16601:
16602: Inputs:
16603:
16604: item - name of form element (sincefilter or createdfilter)
16605:
16606: filter - anonymous hash of criteria and their values
16607:
16608: Returns: HTML for a select box contained a blank, then six time selections,
16609: with value set in incoming form variables currently selected.
16610:
16611: Side Effects: None
16612:
16613: =cut
16614:
16615: sub timebased_select_form {
16616: my ($item,$filter) = @_;
16617: if (ref($filter) eq 'HASH') {
16618: $filter->{$item} =~ s/[^\d-]//g;
16619: if (!$filter->{$item}) { $filter->{$item}=-1; }
16620: return &select_form(
16621: $filter->{$item},
16622: $item,
16623: { '-1' => '',
16624: '86400' => &mt('today'),
16625: '604800' => &mt('last week'),
16626: '2592000' => &mt('last month'),
16627: '7776000' => &mt('last three months'),
16628: '15552000' => &mt('last six months'),
16629: '31104000' => &mt('last year'),
16630: 'select_form_order' =>
16631: ['-1','86400','604800','2592000','7776000',
16632: '15552000','31104000']});
16633: }
16634: }
16635:
16636: =pod
16637:
16638: =item * &js_changer()
16639:
16640: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 16641: when course type or domain is changed, and also to hide 'Searching ...' on
16642: page load completion for page showing search result.
1.1181 raeburn 16643:
16644: Inputs: None
16645:
1.1183 raeburn 16646: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 16647:
16648: Side Effects: None
16649:
16650: =cut
16651:
16652: sub js_changer {
16653: return <<ENDJS;
16654: <script type="text/javascript">
16655: // <![CDATA[
16656: function updateFilters(caller) {
16657: if (typeof(caller) != "undefined") {
16658: document.filterpicker.updater.value = caller.name;
16659: }
16660: document.filterpicker.submit();
16661: }
1.1183 raeburn 16662:
16663: function hideSearching() {
16664: if (document.getElementById('searching')) {
16665: document.getElementById('searching').style.display = 'none';
16666: }
16667: return;
16668: }
16669:
1.1181 raeburn 16670: // ]]>
16671: </script>
16672:
16673: ENDJS
16674: }
16675:
16676: =pod
16677:
1.1182 raeburn 16678: =item * &search_courses()
16679:
16680: Process selected filters form course search form and pass to lonnet::courseiddump
16681: to retrieve a hash for which keys are courseIDs which match the selected filters.
16682:
16683: Inputs:
16684:
16685: dom - domain being searched
16686:
16687: type - course type ('Course' or 'Community' or '.' if any).
16688:
16689: filter - anonymous hash of criteria and their values
16690:
16691: numtitles - for institutional codes - number of categories
16692:
16693: cloneruname - optional username of new course owner
16694:
16695: clonerudom - optional domain of new course owner
16696:
1.1221 raeburn 16697: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 16698: (used when DC is using course creation form)
16699:
16700: codetitles - reference to array of titles of components in institutional codes (official courses).
16701:
1.1221 raeburn 16702: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16703: (and so can clone automatically)
16704:
16705: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16706:
16707: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16708: courses to clone
1.1182 raeburn 16709:
16710: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16711:
16712:
16713: Side Effects: None
16714:
16715: =cut
16716:
16717:
16718: sub search_courses {
1.1221 raeburn 16719: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16720: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 16721: my (%courses,%showcourses,$cloner);
16722: if (($filter->{'ownerfilter'} ne '') ||
16723: ($filter->{'ownerdomfilter'} ne '')) {
16724: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16725: $filter->{'ownerdomfilter'};
16726: }
16727: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16728: if (!$filter->{$item}) {
16729: $filter->{$item}='.';
16730: }
16731: }
16732: my $now = time;
16733: my $timefilter =
16734: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16735: my ($createdbefore,$createdafter);
16736: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16737: $createdbefore = $now;
16738: $createdafter = $now-$filter->{'createdfilter'};
16739: }
16740: my ($instcodefilter,$regexpok);
16741: if ($numtitles) {
16742: if ($env{'form.official'} eq 'on') {
16743: $instcodefilter =
16744: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16745: $regexpok = 1;
16746: } elsif ($env{'form.official'} eq 'off') {
16747: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16748: unless ($instcodefilter eq '') {
16749: $regexpok = -1;
16750: }
16751: }
16752: } else {
16753: $instcodefilter = $filter->{'instcodefilter'};
16754: }
16755: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16756: if ($type eq '') { $type = '.'; }
16757:
16758: if (($clonerudom ne '') && ($cloneruname ne '')) {
16759: $cloner = $cloneruname.':'.$clonerudom;
16760: }
16761: %courses = &Apache::lonnet::courseiddump($dom,
16762: $filter->{'descriptfilter'},
16763: $timefilter,
16764: $instcodefilter,
16765: $filter->{'combownerfilter'},
16766: $filter->{'coursefilter'},
16767: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 16768: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 16769: $filter->{'cloneableonly'},
16770: $createdbefore,$createdafter,undef,
1.1221 raeburn 16771: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 16772: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16773: my $ccrole;
16774: if ($type eq 'Community') {
16775: $ccrole = 'co';
16776: } else {
16777: $ccrole = 'cc';
16778: }
16779: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16780: $filter->{'persondomfilter'},
16781: 'userroles',undef,
16782: [$ccrole,'in','ad','ep','ta','cr'],
16783: $dom);
16784: foreach my $role (keys(%rolehash)) {
16785: my ($cnum,$cdom,$courserole) = split(':',$role);
16786: my $cid = $cdom.'_'.$cnum;
16787: if (exists($courses{$cid})) {
16788: if (ref($courses{$cid}) eq 'HASH') {
16789: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16790: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
1.1263 raeburn 16791: push(@{$courses{$cid}{roles}},$courserole);
1.1182 raeburn 16792: }
16793: } else {
16794: $courses{$cid}{roles} = [$courserole];
16795: }
16796: $showcourses{$cid} = $courses{$cid};
16797: }
16798: }
16799: }
16800: %courses = %showcourses;
16801: }
16802: return %courses;
16803: }
16804:
16805: =pod
16806:
1.1181 raeburn 16807: =back
16808:
1.1207 raeburn 16809: =head1 Routines for version requirements for current course.
16810:
16811: =over 4
16812:
16813: =item * &check_release_required()
16814:
16815: Compares required LON-CAPA version with version on server, and
16816: if required version is newer looks for a server with the required version.
16817:
16818: Looks first at servers in user's owen domain; if none suitable, looks at
16819: servers in course's domain are permitted to host sessions for user's domain.
16820:
16821: Inputs:
16822:
16823: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16824:
16825: $courseid - Course ID of current course
16826:
16827: $rolecode - User's current role in course (for switchserver query string).
16828:
16829: $required - LON-CAPA version needed by course (format: Major.Minor).
16830:
16831:
16832: Returns:
16833:
16834: $switchserver - query string tp append to /adm/switchserver call (if
16835: current server's LON-CAPA version is too old.
16836:
16837: $warning - Message is displayed if no suitable server could be found.
16838:
16839: =cut
16840:
16841: sub check_release_required {
16842: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16843: my ($switchserver,$warning);
16844: if ($required ne '') {
16845: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16846: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16847: if ($reqdmajor ne '' && $reqdminor ne '') {
16848: my $otherserver;
16849: if (($major eq '' && $minor eq '') ||
16850: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16851: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16852: my $switchlcrev =
16853: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16854: $userdomserver);
16855: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16856: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16857: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16858: my $cdom = $env{'course.'.$courseid.'.domain'};
16859: if ($cdom ne $env{'user.domain'}) {
16860: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16861: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16862: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16863: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16864: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16865: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16866: my $canhost =
16867: &Apache::lonnet::can_host_session($env{'user.domain'},
16868: $coursedomserver,
16869: $remoterev,
16870: $udomdefaults{'remotesessions'},
16871: $defdomdefaults{'hostedsessions'});
16872:
16873: if ($canhost) {
16874: $otherserver = $coursedomserver;
16875: } else {
16876: $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$courseid.'.internal.releaserequired'}).'<br />'. &mt("No suitable server could be found amongst servers in either your own domain or in the course's domain.");
16877: }
16878: } else {
16879: $warning = &mt('Requires LON-CAPA version [_1].',$env{'course.'.$courseid.'.internal.releaserequired'}).'<br />'.&mt("No suitable server could be found amongst servers in your own domain (which is also the course's domain).");
16880: }
16881: } else {
16882: $otherserver = $userdomserver;
16883: }
16884: }
16885: if ($otherserver ne '') {
16886: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16887: }
16888: }
16889: }
16890: return ($switchserver,$warning);
16891: }
16892:
16893: =pod
16894:
16895: =item * &check_release_result()
16896:
16897: Inputs:
16898:
16899: $switchwarning - Warning message if no suitable server found to host session.
16900:
16901: $switchserver - query string to append to /adm/switchserver containing lonHostID
16902: and current role.
16903:
16904: Returns: HTML to display with information about requirement to switch server.
16905: Either displaying warning with link to Roles/Courses screen or
16906: display link to switchserver.
16907:
1.1181 raeburn 16908: =cut
16909:
1.1207 raeburn 16910: sub check_release_result {
16911: my ($switchwarning,$switchserver) = @_;
16912: my $output = &start_page('Selected course unavailable on this server').
16913: '<p class="LC_warning">';
16914: if ($switchwarning) {
16915: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16916: if (&show_course()) {
16917: $output .= &mt('Display courses');
16918: } else {
16919: $output .= &mt('Display roles');
16920: }
16921: $output .= '</a>';
16922: } elsif ($switchserver) {
16923: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16924: '<br />'.
16925: '<a href="/adm/switchserver?'.$switchserver.'">'.
16926: &mt('Switch Server').
16927: '</a>';
16928: }
16929: $output .= '</p>'.&end_page();
16930: return $output;
16931: }
16932:
16933: =pod
16934:
16935: =item * &needs_coursereinit()
16936:
16937: Determine if course contents stored for user's session needs to be
16938: refreshed, because content has changed since "Big Hash" last tied.
16939:
16940: Check for change is made if time last checked is more than 10 minutes ago
16941: (by default).
16942:
16943: Inputs:
16944:
16945: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16946:
16947: $interval (optional) - Time which may elapse (in s) between last check for content
16948: change in current course. (default: 600 s).
16949:
16950: Returns: an array; first element is:
16951:
16952: =over 4
16953:
16954: 'switch' - if content updates mean user's session
16955: needs to be switched to a server running a newer LON-CAPA version
16956:
16957: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16958: on current server hosting user's session
16959:
16960: '' - if no action required.
16961:
16962: =back
16963:
16964: If first item element is 'switch':
16965:
16966: second item is $switchwarning - Warning message if no suitable server found to host session.
16967:
16968: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16969: and current role.
16970:
16971: otherwise: no other elements returned.
16972:
16973: =back
16974:
16975: =cut
16976:
16977: sub needs_coursereinit {
16978: my ($loncaparev,$interval) = @_;
16979: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16980: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16981: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16982: my $now = time;
16983: if ($interval eq '') {
16984: $interval = 600;
16985: }
16986: if (($now-$env{'request.course.timechecked'})>$interval) {
16987: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16988: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16989: if ($lastchange > $env{'request.course.tied'}) {
16990: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16991: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16992: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16993: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16994: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16995: $curr_reqd_hash{'internal.releaserequired'}});
16996: my ($switchserver,$switchwarning) =
16997: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16998: $curr_reqd_hash{'internal.releaserequired'});
16999: if ($switchwarning ne '' || $switchserver ne '') {
17000: return ('switch',$switchwarning,$switchserver);
17001: }
17002: }
17003: }
17004: return ('update');
17005: }
17006: }
17007: return ();
17008: }
1.1181 raeburn 17009:
1.1083 raeburn 17010: sub update_content_constraints {
17011: my ($cdom,$cnum,$chome,$cid) = @_;
17012: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
17013: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
17014: my %checkresponsetypes;
17015: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 17016: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 17017: if ($item eq 'resourcetag') {
17018: if ($name eq 'responsetype') {
17019: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
17020: }
17021: }
17022: }
17023: my $navmap = Apache::lonnavmaps::navmap->new();
17024: if (defined($navmap)) {
17025: my %allresponses;
17026: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
17027: my %responses = $res->responseTypes();
17028: foreach my $key (keys(%responses)) {
17029: next unless(exists($checkresponsetypes{$key}));
17030: $allresponses{$key} += $responses{$key};
17031: }
17032: }
17033: foreach my $key (keys(%allresponses)) {
17034: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
17035: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
17036: ($reqdmajor,$reqdminor) = ($major,$minor);
17037: }
17038: }
17039: undef($navmap);
17040: }
17041: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
17042: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
17043: }
17044: return;
17045: }
17046:
1.1110 raeburn 17047: sub allmaps_incourse {
17048: my ($cdom,$cnum,$chome,$cid) = @_;
17049: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
17050: $cid = $env{'request.course.id'};
17051: $cdom = $env{'course.'.$cid.'.domain'};
17052: $cnum = $env{'course.'.$cid.'.num'};
17053: $chome = $env{'course.'.$cid.'.home'};
17054: }
17055: my %allmaps = ();
17056: my $lastchange =
17057: &Apache::lonnet::get_coursechange($cdom,$cnum);
17058: if ($lastchange > $env{'request.course.tied'}) {
17059: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
17060: unless ($ferr) {
17061: &update_content_constraints($cdom,$cnum,$chome,$cid);
17062: }
17063: }
17064: my $navmap = Apache::lonnavmaps::navmap->new();
17065: if (defined($navmap)) {
17066: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
17067: $allmaps{$res->src()} = 1;
17068: }
17069: }
17070: return \%allmaps;
17071: }
17072:
1.1083 raeburn 17073: sub parse_supplemental_title {
17074: my ($title) = @_;
17075:
17076: my ($foldertitle,$renametitle);
17077: if ($title =~ /&&&/) {
17078: $title = &HTML::Entites::decode($title);
17079: }
17080: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
17081: $renametitle=$4;
17082: my ($time,$uname,$udom) = ($1,$2,$3);
17083: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
17084: my $name = &plainname($uname,$udom);
17085: $name = &HTML::Entities::encode($name,'"<>&\'');
17086: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
17087: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
17088: $name.': <br />'.$foldertitle;
17089: }
17090: if (wantarray) {
17091: return ($title,$foldertitle,$renametitle);
17092: }
17093: return $title;
17094: }
17095:
1.1143 raeburn 17096: sub recurse_supplemental {
17097: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
17098: if ($suppmap) {
17099: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
17100: if ($fatal) {
17101: $errors ++;
17102: } else {
17103: if ($#LONCAPA::map::resources > 0) {
17104: foreach my $res (@LONCAPA::map::resources) {
17105: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
17106: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 17107: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
17108: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1143 raeburn 17109: } else {
17110: $numfiles ++;
17111: }
17112: }
17113: }
17114: }
17115: }
17116: }
17117: return ($numfiles,$errors);
17118: }
17119:
1.1101 raeburn 17120: sub symb_to_docspath {
1.1267 raeburn 17121: my ($symb,$navmapref) = @_;
17122: return unless ($symb && ref($navmapref));
1.1101 raeburn 17123: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
17124: if ($resurl=~/\.(sequence|page)$/) {
17125: $mapurl=$resurl;
17126: } elsif ($resurl eq 'adm/navmaps') {
17127: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
17128: }
17129: my $mapresobj;
1.1267 raeburn 17130: unless (ref($$navmapref)) {
17131: $$navmapref = Apache::lonnavmaps::navmap->new();
17132: }
17133: if (ref($$navmapref)) {
17134: $mapresobj = $$navmapref->getResourceByUrl($mapurl);
1.1101 raeburn 17135: }
17136: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
17137: my $type=$2;
17138: my $path;
17139: if (ref($mapresobj)) {
17140: my $pcslist = $mapresobj->map_hierarchy();
17141: if ($pcslist ne '') {
17142: foreach my $pc (split(/,/,$pcslist)) {
17143: next if ($pc <= 1);
1.1267 raeburn 17144: my $res = $$navmapref->getByMapPc($pc);
1.1101 raeburn 17145: if (ref($res)) {
17146: my $thisurl = $res->src();
17147: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
17148: my $thistitle = $res->title();
17149: $path .= '&'.
17150: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 17151: &escape($thistitle).
1.1101 raeburn 17152: ':'.$res->randompick().
17153: ':'.$res->randomout().
17154: ':'.$res->encrypted().
17155: ':'.$res->randomorder().
17156: ':'.$res->is_page();
17157: }
17158: }
17159: }
17160: $path =~ s/^\&//;
17161: my $maptitle = $mapresobj->title();
17162: if ($mapurl eq 'default') {
1.1129 raeburn 17163: $maptitle = 'Main Content';
1.1101 raeburn 17164: }
17165: $path .= (($path ne '')? '&' : '').
17166: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17167: &escape($maptitle).
1.1101 raeburn 17168: ':'.$mapresobj->randompick().
17169: ':'.$mapresobj->randomout().
17170: ':'.$mapresobj->encrypted().
17171: ':'.$mapresobj->randomorder().
17172: ':'.$mapresobj->is_page();
17173: } else {
17174: my $maptitle = &Apache::lonnet::gettitle($mapurl);
17175: my $ispage = (($type eq 'page')? 1 : '');
17176: if ($mapurl eq 'default') {
1.1129 raeburn 17177: $maptitle = 'Main Content';
1.1101 raeburn 17178: }
17179: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 17180: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 17181: }
17182: unless ($mapurl eq 'default') {
17183: $path = 'default&'.
1.1146 raeburn 17184: &escape('Main Content').
1.1101 raeburn 17185: ':::::&'.$path;
17186: }
17187: return $path;
17188: }
17189:
1.1094 raeburn 17190: sub captcha_display {
17191: my ($context,$lonhost) = @_;
17192: my ($output,$error);
1.1234 raeburn 17193: my ($captcha,$pubkey,$privkey,$version) =
17194: &get_captcha_config($context,$lonhost);
1.1095 raeburn 17195: if ($captcha eq 'original') {
1.1094 raeburn 17196: $output = &create_captcha();
17197: unless ($output) {
1.1172 raeburn 17198: $error = 'captcha';
1.1094 raeburn 17199: }
17200: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17201: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 17202: unless ($output) {
1.1172 raeburn 17203: $error = 'recaptcha';
1.1094 raeburn 17204: }
17205: }
1.1234 raeburn 17206: return ($output,$error,$captcha,$version);
1.1094 raeburn 17207: }
17208:
17209: sub captcha_response {
17210: my ($context,$lonhost) = @_;
17211: my ($captcha_chk,$captcha_error);
1.1234 raeburn 17212: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 17213: if ($captcha eq 'original') {
1.1094 raeburn 17214: ($captcha_chk,$captcha_error) = &check_captcha();
17215: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 17216: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 17217: } else {
17218: $captcha_chk = 1;
17219: }
17220: return ($captcha_chk,$captcha_error);
17221: }
17222:
17223: sub get_captcha_config {
17224: my ($context,$lonhost) = @_;
1.1234 raeburn 17225: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 17226: my $hostname = &Apache::lonnet::hostname($lonhost);
17227: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
17228: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 17229: if ($context eq 'usercreation') {
17230: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
17231: if (ref($domconfig{$context}) eq 'HASH') {
17232: $hashtocheck = $domconfig{$context}{'cancreate'};
17233: if (ref($hashtocheck) eq 'HASH') {
17234: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
17235: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
17236: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
17237: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
17238: }
17239: if ($privkey && $pubkey) {
17240: $captcha = 'recaptcha';
1.1234 raeburn 17241: $version = $hashtocheck->{'recaptchaversion'};
17242: if ($version ne '2') {
17243: $version = 1;
17244: }
1.1095 raeburn 17245: } else {
17246: $captcha = 'original';
17247: }
17248: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
17249: $captcha = 'original';
17250: }
1.1094 raeburn 17251: }
1.1095 raeburn 17252: } else {
17253: $captcha = 'captcha';
17254: }
17255: } elsif ($context eq 'login') {
17256: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
17257: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
17258: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
17259: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 17260: if ($privkey && $pubkey) {
17261: $captcha = 'recaptcha';
1.1234 raeburn 17262: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
17263: if ($version ne '2') {
17264: $version = 1;
17265: }
1.1095 raeburn 17266: } else {
17267: $captcha = 'original';
1.1094 raeburn 17268: }
1.1095 raeburn 17269: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
17270: $captcha = 'original';
1.1094 raeburn 17271: }
17272: }
1.1234 raeburn 17273: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 17274: }
17275:
17276: sub create_captcha {
17277: my %captcha_params = &captcha_settings();
17278: my ($output,$maxtries,$tries) = ('',10,0);
17279: while ($tries < $maxtries) {
17280: $tries ++;
17281: my $captcha = Authen::Captcha->new (
17282: output_folder => $captcha_params{'output_dir'},
17283: data_folder => $captcha_params{'db_dir'},
17284: );
17285: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
17286:
17287: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
17288: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
17289: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 17290: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
17291: '<br />'.
17292: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 17293: last;
17294: }
17295: }
17296: return $output;
17297: }
17298:
17299: sub captcha_settings {
17300: my %captcha_params = (
17301: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
17302: www_output_dir => "/captchaspool",
17303: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
17304: numchars => '5',
17305: );
17306: return %captcha_params;
17307: }
17308:
17309: sub check_captcha {
17310: my ($captcha_chk,$captcha_error);
17311: my $code = $env{'form.code'};
17312: my $md5sum = $env{'form.crypt'};
17313: my %captcha_params = &captcha_settings();
17314: my $captcha = Authen::Captcha->new(
17315: output_folder => $captcha_params{'output_dir'},
17316: data_folder => $captcha_params{'db_dir'},
17317: );
1.1109 raeburn 17318: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 17319: my %captcha_hash = (
17320: 0 => 'Code not checked (file error)',
17321: -1 => 'Failed: code expired',
17322: -2 => 'Failed: invalid code (not in database)',
17323: -3 => 'Failed: invalid code (code does not match crypt)',
17324: );
17325: if ($captcha_chk != 1) {
17326: $captcha_error = $captcha_hash{$captcha_chk}
17327: }
17328: return ($captcha_chk,$captcha_error);
17329: }
17330:
17331: sub create_recaptcha {
1.1234 raeburn 17332: my ($pubkey,$version) = @_;
17333: if ($version >= 2) {
17334: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
17335: } else {
17336: my $use_ssl;
17337: if ($ENV{'SERVER_PORT'} == 443) {
17338: $use_ssl = 1;
17339: }
17340: my $captcha = Captcha::reCAPTCHA->new;
17341: return $captcha->get_options_setter({theme => 'white'})."\n".
17342: $captcha->get_html($pubkey,undef,$use_ssl).
17343: &mt('If the text is hard to read, [_1] will replace them.',
17344: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
17345: '<br /><br />';
17346: }
1.1094 raeburn 17347: }
17348:
17349: sub check_recaptcha {
1.1234 raeburn 17350: my ($privkey,$version) = @_;
1.1094 raeburn 17351: my $captcha_chk;
1.1234 raeburn 17352: if ($version >= 2) {
17353: my $ua = LWP::UserAgent->new;
17354: $ua->timeout(10);
17355: my %info = (
17356: secret => $privkey,
17357: response => $env{'form.g-recaptcha-response'},
17358: remoteip => $ENV{'REMOTE_ADDR'},
17359: );
17360: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
17361: if ($response->is_success) {
17362: my $data = JSON::DWIW->from_json($response->decoded_content);
17363: if (ref($data) eq 'HASH') {
17364: if ($data->{'success'}) {
17365: $captcha_chk = 1;
17366: }
17367: }
17368: }
17369: } else {
17370: my $captcha = Captcha::reCAPTCHA->new;
17371: my $captcha_result =
17372: $captcha->check_answer(
17373: $privkey,
17374: $ENV{'REMOTE_ADDR'},
17375: $env{'form.recaptcha_challenge_field'},
17376: $env{'form.recaptcha_response_field'},
17377: );
17378: if ($captcha_result->{is_valid}) {
17379: $captcha_chk = 1;
17380: }
1.1094 raeburn 17381: }
17382: return $captcha_chk;
17383: }
17384:
1.1174 raeburn 17385: sub emailusername_info {
1.1244 raeburn 17386: my @fields = ('firstname','lastname','institution','web','location','officialemail','id');
1.1174 raeburn 17387: my %titles = &Apache::lonlocal::texthash (
17388: lastname => 'Last Name',
17389: firstname => 'First Name',
17390: institution => 'School/college/university',
17391: location => "School's city, state/province, country",
17392: web => "School's web address",
17393: officialemail => 'E-mail address at institution (if different)',
1.1244 raeburn 17394: id => 'Student/Employee ID',
1.1174 raeburn 17395: );
17396: return (\@fields,\%titles);
17397: }
17398:
1.1161 raeburn 17399: sub cleanup_html {
17400: my ($incoming) = @_;
17401: my $outgoing;
17402: if ($incoming ne '') {
17403: $outgoing = $incoming;
17404: $outgoing =~ s/;/;/g;
17405: $outgoing =~ s/\#/#/g;
17406: $outgoing =~ s/\&/&/g;
17407: $outgoing =~ s/</</g;
17408: $outgoing =~ s/>/>/g;
17409: $outgoing =~ s/\(/(/g;
17410: $outgoing =~ s/\)/)/g;
17411: $outgoing =~ s/"/"/g;
17412: $outgoing =~ s/'/'/g;
17413: $outgoing =~ s/\$/$/g;
17414: $outgoing =~ s{/}{/}g;
17415: $outgoing =~ s/=/=/g;
17416: $outgoing =~ s/\\/\/g
17417: }
17418: return $outgoing;
17419: }
17420:
1.1190 musolffc 17421: # Checks for critical messages and returns a redirect url if one exists.
17422: # $interval indicates how often to check for messages.
17423: sub critical_redirect {
17424: my ($interval) = @_;
17425: if ((time-$env{'user.criticalcheck.time'})>$interval) {
17426: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
17427: $env{'user.name'});
17428: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 17429: my $redirecturl;
1.1190 musolffc 17430: if ($what[0]) {
17431: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
17432: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 17433: my $url=&Apache::lonnet::absolute_url().$redirecturl;
17434: return (1, $url);
1.1190 musolffc 17435: }
1.1191 raeburn 17436: }
17437: }
17438: return ();
1.1190 musolffc 17439: }
17440:
1.1174 raeburn 17441: # Use:
17442: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
17443: #
17444: ##################################################
17445: # password associated functions #
17446: ##################################################
17447: sub des_keys {
17448: # Make a new key for DES encryption.
17449: # Each key has two parts which are returned separately.
17450: # Please note: Each key must be passed through the &hex function
17451: # before it is output to the web browser. The hex versions cannot
17452: # be used to decrypt.
17453: my @hexstr=('0','1','2','3','4','5','6','7',
17454: '8','9','a','b','c','d','e','f');
17455: my $lkey='';
17456: for (0..7) {
17457: $lkey.=$hexstr[rand(15)];
17458: }
17459: my $ukey='';
17460: for (0..7) {
17461: $ukey.=$hexstr[rand(15)];
17462: }
17463: return ($lkey,$ukey);
17464: }
17465:
17466: sub des_decrypt {
17467: my ($key,$cyphertext) = @_;
17468: my $keybin=pack("H16",$key);
17469: my $cypher;
17470: if ($Crypt::DES::VERSION>=2.03) {
17471: $cypher=new Crypt::DES $keybin;
17472: } else {
17473: $cypher=new DES $keybin;
17474: }
1.1233 raeburn 17475: my $plaintext='';
17476: my $cypherlength = length($cyphertext);
17477: my $numchunks = int($cypherlength/32);
17478: for (my $j=0; $j<$numchunks; $j++) {
17479: my $start = $j*32;
17480: my $cypherblock = substr($cyphertext,$start,32);
17481: my $chunk =
17482: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
17483: $chunk .=
17484: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
17485: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
17486: $plaintext .= $chunk;
17487: }
1.1174 raeburn 17488: return $plaintext;
17489: }
17490:
1.112 bowersj2 17491: 1;
17492: __END__;
1.41 ng 17493:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>