Annotation of loncom/interface/loncommon.pm, revision 1.1242
1.10 albertel 1: # The LearningOnline Network with CAPA
1.1 albertel 2: # a pile of common routines
1.10 albertel 3: #
1.1242 ! raeburn 4: # $Id: loncommon.pm,v 1.1241 2016/04/09 18:43:32 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.158 raeburn 270: push @{$category_extensions{lc($category)}},$extension;
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.659 raeburn 946: my ($name,$selected,$onchange,$includeempty)=@_;
947: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
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 {
968: my ($name,$selected,$onchange,$includeempty)=@_;
969: my $output='<select name="'.$name.'" '.$onchange.'>'."\n";
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 {
1021: my ($name,$selected,$includeempty) = @_;
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.970 raeburn 1033: return &select_form($selected,$name,\%langchoices);
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);
1057: push (@lang_choices, [$selector, $description]);
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.41 ng 1097: =back
1098:
1.36 matthew 1099: Below is an example of such a hash. Only the 'text', 'default', and
1100: 'select2' keys must appear as stated. keys(%menu) are the possible
1101: values for the first select menu. The text that coincides with the
1.41 ng 1102: first menu value is given in $menu{$choice1}->{'text'}. The values
1.36 matthew 1103: and text for the second menu are given in the hash pointed to by
1104: $menu{$choice1}->{'select2'}.
1105:
1.112 bowersj2 1106: my %menu = ( A1 => { text =>"Choice A1" ,
1107: default => "B3",
1108: select2 => {
1109: B1 => "Choice B1",
1110: B2 => "Choice B2",
1111: B3 => "Choice B3",
1112: B4 => "Choice B4"
1.609 raeburn 1113: },
1114: order => ['B4','B3','B1','B2'],
1.112 bowersj2 1115: },
1116: A2 => { text =>"Choice A2" ,
1117: default => "C2",
1118: select2 => {
1119: C1 => "Choice C1",
1120: C2 => "Choice C2",
1121: C3 => "Choice C3"
1.609 raeburn 1122: },
1123: order => ['C2','C1','C3'],
1.112 bowersj2 1124: },
1125: A3 => { text =>"Choice A3" ,
1126: default => "D6",
1127: select2 => {
1128: D1 => "Choice D1",
1129: D2 => "Choice D2",
1130: D3 => "Choice D3",
1131: D4 => "Choice D4",
1132: D5 => "Choice D5",
1133: D6 => "Choice D6",
1134: D7 => "Choice D7"
1.609 raeburn 1135: },
1136: order => ['D4','D3','D2','D1','D7','D6','D5'],
1.112 bowersj2 1137: }
1138: );
1.36 matthew 1139:
1140: =cut
1141:
1142: sub linked_select_forms {
1143: my ($formname,
1144: $middletext,
1145: $firstdefault,
1146: $firstselectname,
1147: $secondselectname,
1.609 raeburn 1148: $hashref,
1149: $menuorder,
1.1115 raeburn 1150: $onchangefirst,
1151: $onchangesecond
1.36 matthew 1152: ) = @_;
1153: my $second = "document.$formname.$secondselectname";
1154: my $first = "document.$formname.$firstselectname";
1155: # output the javascript to do the changing
1156: my $result = '';
1.776 bisitz 1157: $result.='<script type="text/javascript" language="JavaScript">'."\n";
1.824 bisitz 1158: $result.="// <![CDATA[\n";
1.36 matthew 1159: $result.="var select2data = new Object();\n";
1160: $" = '","';
1161: my $debug = '';
1162: foreach my $s1 (sort(keys(%$hashref))) {
1163: $result.="select2data.d_$s1 = new Object();\n";
1164: $result.="select2data.d_$s1.def = new String('".
1165: $hashref->{$s1}->{'default'}."');\n";
1.609 raeburn 1166: $result.="select2data.d_$s1.values = new Array(";
1.36 matthew 1167: my @s2values = sort(keys( %{ $hashref->{$s1}->{'select2'} } ));
1.609 raeburn 1168: if (ref($hashref->{$s1}->{'order'}) eq 'ARRAY') {
1169: @s2values = @{$hashref->{$s1}->{'order'}};
1170: }
1.36 matthew 1171: $result.="\"@s2values\");\n";
1172: $result.="select2data.d_$s1.texts = new Array(";
1173: my @s2texts;
1174: foreach my $value (@s2values) {
1175: push @s2texts, $hashref->{$s1}->{'select2'}->{$value};
1176: }
1177: $result.="\"@s2texts\");\n";
1178: }
1179: $"=' ';
1180: $result.= <<"END";
1181:
1182: function select1_changed() {
1183: // Determine new choice
1184: var newvalue = "d_" + $first.value;
1185: // update select2
1186: var values = select2data[newvalue].values;
1187: var texts = select2data[newvalue].texts;
1188: var select2def = select2data[newvalue].def;
1189: var i;
1190: // out with the old
1191: for (i = 0; i < $second.options.length; i++) {
1192: $second.options[i] = null;
1193: }
1194: // in with the nuclear
1195: for (i=0;i<values.length; i++) {
1196: $second.options[i] = new Option(values[i]);
1.143 matthew 1197: $second.options[i].value = values[i];
1.36 matthew 1198: $second.options[i].text = texts[i];
1199: if (values[i] == select2def) {
1200: $second.options[i].selected = true;
1201: }
1202: }
1203: }
1.824 bisitz 1204: // ]]>
1.36 matthew 1205: </script>
1206: END
1207: # output the initial values for the selection lists
1.1115 raeburn 1208: $result .= "<select size=\"1\" name=\"$firstselectname\" onchange=\"select1_changed();$onchangefirst\">\n";
1.609 raeburn 1209: my @order = sort(keys(%{$hashref}));
1210: if (ref($menuorder) eq 'ARRAY') {
1211: @order = @{$menuorder};
1212: }
1213: foreach my $value (@order) {
1.36 matthew 1214: $result.=" <option value=\"$value\" ";
1.253 albertel 1215: $result.=" selected=\"selected\" " if ($value eq $firstdefault);
1.119 www 1216: $result.=">".&mt($hashref->{$value}->{'text'})."</option>\n";
1.36 matthew 1217: }
1218: $result .= "</select>\n";
1219: my %select2 = %{$hashref->{$firstdefault}->{'select2'}};
1220: $result .= $middletext;
1.1115 raeburn 1221: $result .= "<select size=\"1\" name=\"$secondselectname\"";
1222: if ($onchangesecond) {
1223: $result .= ' onchange="'.$onchangesecond.'"';
1224: }
1225: $result .= ">\n";
1.36 matthew 1226: my $seconddefault = $hashref->{$firstdefault}->{'default'};
1.609 raeburn 1227:
1228: my @secondorder = sort(keys(%select2));
1229: if (ref($hashref->{$firstdefault}->{'order'}) eq 'ARRAY') {
1230: @secondorder = @{$hashref->{$firstdefault}->{'order'}};
1231: }
1232: foreach my $value (@secondorder) {
1.36 matthew 1233: $result.=" <option value=\"$value\" ";
1.253 albertel 1234: $result.=" selected=\"selected\" " if ($value eq $seconddefault);
1.119 www 1235: $result.=">".&mt($select2{$value})."</option>\n";
1.36 matthew 1236: }
1237: $result .= "</select>\n";
1238: # return $debug;
1239: return $result;
1240: } # end of sub linked_select_forms {
1241:
1.45 matthew 1242: =pod
1.44 bowersj2 1243:
1.973 raeburn 1244: =item * &help_open_topic($topic,$text,$stayOnPage,$width,$height,$imgid)
1.44 bowersj2 1245:
1.112 bowersj2 1246: Returns a string corresponding to an HTML link to the given help
1247: $topic, where $topic corresponds to the name of a .tex file in
1248: /home/httpd/html/adm/help/tex, with underscores replaced by
1249: spaces.
1250:
1251: $text will optionally be linked to the same topic, allowing you to
1252: link text in addition to the graphic. If you do not want to link
1253: text, but wish to specify one of the later parameters, pass an
1254: empty string.
1255:
1256: $stayOnPage is a value that will be interpreted as a boolean. If true,
1257: the link will not open a new window. If false, the link will open
1258: a new window using Javascript. (Default is false.)
1259:
1260: $width and $height are optional numerical parameters that will
1261: override the width and height of the popped up window, which may
1.973 raeburn 1262: be useful for certain help topics with big pictures included.
1263:
1264: $imgid is the id of the img tag used for the help icon. This may be
1265: used in a javascript call to switch the image src. See
1266: lonhtmlcommon::htmlareaselectactive() for an example.
1.44 bowersj2 1267:
1268: =cut
1269:
1270: sub help_open_topic {
1.973 raeburn 1271: my ($topic, $text, $stayOnPage, $width, $height, $imgid) = @_;
1.48 bowersj2 1272: $text = "" if (not defined $text);
1.44 bowersj2 1273: $stayOnPage = 0 if (not defined $stayOnPage);
1.1033 www 1274: $width = 500 if (not defined $width);
1.44 bowersj2 1275: $height = 400 if (not defined $height);
1276: my $filename = $topic;
1277: $filename =~ s/ /_/g;
1278:
1.48 bowersj2 1279: my $template = "";
1280: my $link;
1.572 banghart 1281:
1.159 www 1282: $topic=~s/\W/\_/g;
1.44 bowersj2 1283:
1.572 banghart 1284: if (!$stayOnPage) {
1.1033 www 1285: $link = "javascript:openMyModal('/adm/help/${filename}.hlp',$width,$height,'yes');";
1.1037 www 1286: } elsif ($stayOnPage eq 'popup') {
1287: $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 1288: } else {
1.48 bowersj2 1289: $link = "/adm/help/${filename}.hlp";
1290: }
1291:
1292: # Add the text
1.755 neumanie 1293: if ($text ne "") {
1.763 bisitz 1294: $template.='<span class="LC_help_open_topic">'
1295: .'<a target="_top" href="'.$link.'">'
1296: .$text.'</a>';
1.48 bowersj2 1297: }
1298:
1.763 bisitz 1299: # (Always) Add the graphic
1.179 matthew 1300: my $title = &mt('Online Help');
1.667 raeburn 1301: my $helpicon=&lonhttpdurl("/adm/help/help.png");
1.973 raeburn 1302: if ($imgid ne '') {
1303: $imgid = ' id="'.$imgid.'"';
1304: }
1.763 bisitz 1305: $template.=' <a target="_top" href="'.$link.'" title="'.$title.'">'
1306: .'<img src="'.$helpicon.'" border="0"'
1307: .' alt="'.&mt('Help: [_1]',$topic).'"'
1.973 raeburn 1308: .' title="'.$title.'" style="vertical-align:middle;"'.$imgid
1.763 bisitz 1309: .' /></a>';
1310: if ($text ne "") {
1311: $template.='</span>';
1312: }
1.44 bowersj2 1313: return $template;
1314:
1.106 bowersj2 1315: }
1316:
1317: # This is a quicky function for Latex cheatsheet editing, since it
1318: # appears in at least four places
1319: sub helpLatexCheatsheet {
1.1037 www 1320: my ($topic,$text,$not_author,$stayOnPage) = @_;
1.732 raeburn 1321: my $out;
1.106 bowersj2 1322: my $addOther = '';
1.732 raeburn 1323: if ($topic) {
1.1037 www 1324: $addOther = '<span>'.&help_open_topic($topic,&mt($text),$stayOnPage, undef, 600).'</span> ';
1.763 bisitz 1325: }
1326: $out = '<span>' # Start cheatsheet
1327: .$addOther
1328: .'<span>'
1.1037 www 1329: .&help_open_topic('Greek_Symbols',&mt('Greek Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1330: .'</span> <span>'
1.1037 www 1331: .&help_open_topic('Other_Symbols',&mt('Other Symbols'),$stayOnPage,undef,600)
1.763 bisitz 1332: .'</span>';
1.732 raeburn 1333: unless ($not_author) {
1.1186 kruse 1334: $out .= '<span>'
1335: .&help_open_topic('Authoring_Output_Tags',&mt('Output Tags'),$stayOnPage,undef,600)
1336: .'</span> <span>'
1337: .&help_open_topic('Authoring_Multilingual_Problems',&mt('How to create problems in different languages'),$stayOnPage,undef,600)
1.763 bisitz 1338: .'</span>';
1.732 raeburn 1339: }
1.763 bisitz 1340: $out .= '</span>'; # End cheatsheet
1.732 raeburn 1341: return $out;
1.172 www 1342: }
1343:
1.430 albertel 1344: sub general_help {
1345: my $helptopic='Student_Intro';
1346: if ($env{'request.role'}=~/^(ca|au)/) {
1347: $helptopic='Authoring_Intro';
1.907 raeburn 1348: } elsif ($env{'request.role'}=~/^(cc|co)/) {
1.430 albertel 1349: $helptopic='Course_Coordination_Intro';
1.672 raeburn 1350: } elsif ($env{'request.role'}=~/^dc/) {
1351: $helptopic='Domain_Coordination_Intro';
1.430 albertel 1352: }
1353: return $helptopic;
1354: }
1355:
1356: sub update_help_link {
1357: my ($topic,$component_help,$faq,$bug,$stayOnPage) = @_;
1358: my $origurl = $ENV{'REQUEST_URI'};
1359: $origurl=~s|^/~|/priv/|;
1360: my $timestamp = time;
1361: foreach my $datum (\$topic,\$component_help,\$faq,\$bug,\$origurl) {
1362: $$datum = &escape($$datum);
1363: }
1364:
1365: my $banner_link = "/adm/helpmenu?page=banner&topic=$topic&component_help=$component_help&faq=$faq&bug=$bug&origurl=$origurl&stamp=$timestamp&stayonpage=$stayOnPage";
1366: my $output .= <<"ENDOUTPUT";
1367: <script type="text/javascript">
1.824 bisitz 1368: // <![CDATA[
1.430 albertel 1369: banner_link = '$banner_link';
1.824 bisitz 1370: // ]]>
1.430 albertel 1371: </script>
1372: ENDOUTPUT
1373: return $output;
1374: }
1375:
1376: # now just updates the help link and generates a blue icon
1.193 raeburn 1377: sub help_open_menu {
1.430 albertel 1378: my ($topic,$component_help,$faq,$bug,$stayOnPage,$width,$height,$text)
1.552 banghart 1379: = @_;
1.949 droeschl 1380: $stayOnPage = 1;
1.430 albertel 1381: my $output;
1382: if ($component_help) {
1383: if (!$text) {
1384: $output=&help_open_topic($component_help,undef,$stayOnPage,
1385: $width,$height);
1386: } else {
1387: my $help_text;
1388: $help_text=&unescape($topic);
1389: $output='<table><tr><td>'.
1390: &help_open_topic($component_help,$help_text,$stayOnPage,
1391: $width,$height).'</td></tr></table>';
1392: }
1393: }
1394: my $banner_link = &update_help_link($topic,$component_help,$faq,$bug,$stayOnPage);
1395: return $output.$banner_link;
1396: }
1397:
1398: sub top_nav_help {
1399: my ($text) = @_;
1.436 albertel 1400: $text = &mt($text);
1.949 droeschl 1401: my $stay_on_page = 1;
1402:
1.1168 raeburn 1403: my ($link,$banner_link);
1404: unless ($env{'request.noversionuri'} =~ m{^/adm/helpmenu}) {
1405: $link = ($stay_on_page) ? "javascript:helpMenu('display')"
1406: : "javascript:helpMenu('open')";
1407: $banner_link = &update_help_link(undef,undef,undef,undef,$stay_on_page);
1408: }
1.201 raeburn 1409: my $title = &mt('Get help');
1.1168 raeburn 1410: if ($link) {
1411: return <<"END";
1.436 albertel 1412: $banner_link
1.1159 raeburn 1413: <a href="$link" title="$title">$text</a>
1.436 albertel 1414: END
1.1168 raeburn 1415: } else {
1416: return ' '.$text.' ';
1417: }
1.436 albertel 1418: }
1419:
1420: sub help_menu_js {
1.1154 raeburn 1421: my ($httphost) = @_;
1.949 droeschl 1422: my $stayOnPage = 1;
1.436 albertel 1423: my $width = 620;
1424: my $height = 600;
1.430 albertel 1425: my $helptopic=&general_help();
1.1154 raeburn 1426: my $details_link = $httphost.'/adm/help/'.$helptopic.'.hlp';
1.261 albertel 1427: my $nothing=&Apache::lonhtmlcommon::javascript_nothing();
1.331 albertel 1428: my $start_page =
1429: &Apache::loncommon::start_page('Help Menu', undef,
1430: {'frameset' => 1,
1431: 'js_ready' => 1,
1.1154 raeburn 1432: 'use_absolute' => $httphost,
1.331 albertel 1433: 'add_entries' => {
1.1168 raeburn 1434: 'border' => '0',
1.579 raeburn 1435: 'rows' => "110,*",},});
1.331 albertel 1436: my $end_page =
1437: &Apache::loncommon::end_page({'frameset' => 1,
1438: 'js_ready' => 1,});
1439:
1.436 albertel 1440: my $template .= <<"ENDTEMPLATE";
1441: <script type="text/javascript">
1.877 bisitz 1442: // <![CDATA[
1.253 albertel 1443: // <!-- BEGIN LON-CAPA Internal
1.430 albertel 1444: var banner_link = '';
1.243 raeburn 1445: function helpMenu(target) {
1446: var caller = this;
1447: if (target == 'open') {
1448: var newWindow = null;
1449: try {
1.262 albertel 1450: newWindow = window.open($nothing,"helpmenu","HEIGHT=$height,WIDTH=$width,resizable=yes,scrollbars=yes" )
1.243 raeburn 1451: }
1452: catch(error) {
1453: writeHelp(caller);
1454: return;
1455: }
1456: if (newWindow) {
1457: caller = newWindow;
1458: }
1.193 raeburn 1459: }
1.243 raeburn 1460: writeHelp(caller);
1461: return;
1462: }
1463: function writeHelp(caller) {
1.1168 raeburn 1464: caller.document.writeln('$start_page\\n<frame name="bannerframe" src="'+banner_link+'" marginwidth="0" marginheight="0" frameborder="0">\\n');
1465: caller.document.writeln('<frame name="bodyframe" src="$details_link" marginwidth="0" marginheight="0" frameborder="0">\\n$end_page');
1466: caller.document.close();
1467: caller.focus();
1.193 raeburn 1468: }
1.877 bisitz 1469: // END LON-CAPA Internal -->
1.253 albertel 1470: // ]]>
1.436 albertel 1471: </script>
1.193 raeburn 1472: ENDTEMPLATE
1473: return $template;
1474: }
1475:
1.172 www 1476: sub help_open_bug {
1477: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1478: unless ($env{'user.adv'}) { return ''; }
1.172 www 1479: unless ($Apache::lonnet::perlvar{'BugzillaHost'}) { return ''; }
1480: $text = "" if (not defined $text);
1481: $stayOnPage=1;
1.184 albertel 1482: $width = 600 if (not defined $width);
1483: $height = 600 if (not defined $height);
1.172 www 1484:
1485: $topic=~s/\W+/\+/g;
1486: my $link='';
1487: my $template='';
1.379 albertel 1488: my $url=$Apache::lonnet::perlvar{'BugzillaHost'}.'enter_bug.cgi?product=LON-CAPA&bug_file_loc='.
1489: &escape($ENV{'REQUEST_URI'}).'&component='.$topic;
1.172 www 1490: if (!$stayOnPage)
1491: {
1492: $link = "javascript:void(open('$url', 'Bugzilla', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1493: }
1494: else
1495: {
1496: $link = $url;
1497: }
1498: # Add the text
1499: if ($text ne "")
1500: {
1501: $template .=
1502: "<table bgcolor='#AA3333' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1503: "<td bgcolor='#FF5555'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF;font-size:10pt;\">$text</span></a>";
1.172 www 1504: }
1505:
1506: # Add the graphic
1.179 matthew 1507: my $title = &mt('Report a Bug');
1.215 albertel 1508: my $bugicon=&lonhttpdurl("/adm/lonMisc/smallBug.gif");
1.172 www 1509: $template .= <<"ENDTEMPLATE";
1.436 albertel 1510: <a target="_top" href="$link" title="$title"><img src="$bugicon" border="0" alt="(Bug: $topic)" /></a>
1.172 www 1511: ENDTEMPLATE
1512: if ($text ne '') { $template.='</td></tr></table>' };
1513: return $template;
1514:
1515: }
1516:
1517: sub help_open_faq {
1518: my ($topic, $text, $stayOnPage, $width, $height) = @_;
1.258 albertel 1519: unless ($env{'user.adv'}) { return ''; }
1.172 www 1520: unless ($Apache::lonnet::perlvar{'FAQHost'}) { return ''; }
1521: $text = "" if (not defined $text);
1522: $stayOnPage=1;
1523: $width = 350 if (not defined $width);
1524: $height = 400 if (not defined $height);
1525:
1526: $topic=~s/\W+/\+/g;
1527: my $link='';
1528: my $template='';
1529: my $url=$Apache::lonnet::perlvar{'FAQHost'}.'/fom/cache/'.$topic.'.html';
1530: if (!$stayOnPage)
1531: {
1532: $link = "javascript:void(open('$url', 'FAQ-O-Matic', 'menubar=0,toolbar=1,scrollbars=1,width=$width,height=$height,resizable=yes'))";
1533: }
1534: else
1535: {
1536: $link = $url;
1537: }
1538:
1539: # Add the text
1540: if ($text ne "")
1541: {
1542: $template .=
1.173 www 1543: "<table bgcolor='#337733' cellspacing='1' cellpadding='1' border='0'><tr>".
1.705 tempelho 1544: "<td bgcolor='#448844'><a target=\"_top\" href=\"$link\"><span style=\"color:#FFFFFF; font-size:10pt;\">$text</span></a>";
1.172 www 1545: }
1546:
1547: # Add the graphic
1.179 matthew 1548: my $title = &mt('View the FAQ');
1.215 albertel 1549: my $faqicon=&lonhttpdurl("/adm/lonMisc/smallFAQ.gif");
1.172 www 1550: $template .= <<"ENDTEMPLATE";
1.436 albertel 1551: <a target="_top" href="$link" title="$title"><img src="$faqicon" border="0" alt="(FAQ: $topic)" /></a>
1.172 www 1552: ENDTEMPLATE
1553: if ($text ne '') { $template.='</td></tr></table>' };
1554: return $template;
1555:
1.44 bowersj2 1556: }
1.37 matthew 1557:
1.180 matthew 1558: ###############################################################
1559: ###############################################################
1560:
1.45 matthew 1561: =pod
1562:
1.648 raeburn 1563: =item * &change_content_javascript():
1.256 matthew 1564:
1565: This and the next function allow you to create small sections of an
1566: otherwise static HTML page that you can update on the fly with
1567: Javascript, even in Netscape 4.
1568:
1569: The Javascript fragment returned by this function (no E<lt>scriptE<gt> tag)
1570: must be written to the HTML page once. It will prove the Javascript
1571: function "change(name, content)". Calling the change function with the
1572: name of the section
1573: you want to update, matching the name passed to C<changable_area>, and
1574: the new content you want to put in there, will put the content into
1575: that area.
1576:
1577: B<Note>: Netscape 4 only reserves enough space for the changable area
1578: to contain room for the original contents. You need to "make space"
1579: for whatever changes you wish to make, and be B<sure> to check your
1580: code in Netscape 4. This feature in Netscape 4 is B<not> powerful;
1581: it's adequate for updating a one-line status display, but little more.
1582: This script will set the space to 100% width, so you only need to
1583: worry about height in Netscape 4.
1584:
1585: Modern browsers are much less limiting, and if you can commit to the
1586: user not using Netscape 4, this feature may be used freely with
1587: pretty much any HTML.
1588:
1589: =cut
1590:
1591: sub change_content_javascript {
1592: # If we're on Netscape 4, we need to use Layer-based code
1.258 albertel 1593: if ($env{'browser.type'} eq 'netscape' &&
1594: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1595: return (<<NETSCAPE4);
1596: function change(name, content) {
1597: doc = document.layers[name+"___escape"].layers[0].document;
1598: doc.open();
1599: doc.write(content);
1600: doc.close();
1601: }
1602: NETSCAPE4
1603: } else {
1604: # Otherwise, we need to use semi-standards-compliant code
1605: # (technically, "innerHTML" isn't standard but the equivalent
1606: # is really scary, and every useful browser supports it
1607: return (<<DOMBASED);
1608: function change(name, content) {
1609: element = document.getElementById(name);
1610: element.innerHTML = content;
1611: }
1612: DOMBASED
1613: }
1614: }
1615:
1616: =pod
1617:
1.648 raeburn 1618: =item * &changable_area($name,$origContent):
1.256 matthew 1619:
1620: This provides a "changable area" that can be modified on the fly via
1621: the Javascript code provided in C<change_content_javascript>. $name is
1622: the name you will use to reference the area later; do not repeat the
1623: same name on a given HTML page more then once. $origContent is what
1624: the area will originally contain, which can be left blank.
1625:
1626: =cut
1627:
1628: sub changable_area {
1629: my ($name, $origContent) = @_;
1630:
1.258 albertel 1631: if ($env{'browser.type'} eq 'netscape' &&
1632: $env{'browser.version'} =~ /^4\./) {
1.256 matthew 1633: # If this is netscape 4, we need to use the Layer tag
1634: return "<ilayer width='100%' id='${name}___escape' overflow='none'><layer width='100%' id='$name' overflow='none'>$origContent</layer></ilayer>";
1635: } else {
1636: return "<span id='$name'>$origContent</span>";
1637: }
1638: }
1639:
1640: =pod
1641:
1.648 raeburn 1642: =item * &viewport_geometry_js
1.590 raeburn 1643:
1644: Provides javascript object (Geometry) which can provide information about the viewport geometry for the client browser.
1645:
1646: =cut
1647:
1648:
1649: sub viewport_geometry_js {
1650: return <<"GEOMETRY";
1651: var Geometry = {};
1652: function init_geometry() {
1653: if (Geometry.init) { return };
1654: Geometry.init=1;
1655: if (window.innerHeight) {
1656: Geometry.getViewportHeight = function() { return window.innerHeight; };
1657: Geometry.getViewportWidth = function() { return window.innerWidth; };
1658: Geometry.getHorizontalScroll = function() { return window.pageXOffset; };
1659: Geometry.getVerticalScroll = function() { return window.pageYOffset; };
1660: }
1661: else if (document.documentElement && document.documentElement.clientHeight) {
1662: Geometry.getViewportHeight =
1663: function() { return document.documentElement.clientHeight; };
1664: Geometry.getViewportWidth =
1665: function() { return document.documentElement.clientWidth; };
1666:
1667: Geometry.getHorizontalScroll =
1668: function() { return document.documentElement.scrollLeft; };
1669: Geometry.getVerticalScroll =
1670: function() { return document.documentElement.scrollTop; };
1671: }
1672: else if (document.body.clientHeight) {
1673: Geometry.getViewportHeight =
1674: function() { return document.body.clientHeight; };
1675: Geometry.getViewportWidth =
1676: function() { return document.body.clientWidth; };
1677: Geometry.getHorizontalScroll =
1678: function() { return document.body.scrollLeft; };
1679: Geometry.getVerticalScroll =
1680: function() { return document.body.scrollTop; };
1681: }
1682: }
1683:
1684: GEOMETRY
1685: }
1686:
1687: =pod
1688:
1.648 raeburn 1689: =item * &viewport_size_js()
1.590 raeburn 1690:
1691: 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.
1692:
1693: =cut
1694:
1695: sub viewport_size_js {
1696: my $geometry = &viewport_geometry_js();
1697: return <<"DIMS";
1698:
1699: $geometry
1700:
1701: function getViewportDims(width,height) {
1702: init_geometry();
1703: width.value = Geometry.getViewportWidth();
1704: height.value = Geometry.getViewportHeight();
1705: return;
1706: }
1707:
1708: DIMS
1709: }
1710:
1711: =pod
1712:
1.648 raeburn 1713: =item * &resize_textarea_js()
1.565 albertel 1714:
1715: emits the needed javascript to resize a textarea to be as big as possible
1716:
1717: creates a function resize_textrea that takes two IDs first should be
1718: the id of the element to resize, second should be the id of a div that
1719: surrounds everything that comes after the textarea, this routine needs
1720: to be attached to the <body> for the onload and onresize events.
1721:
1.648 raeburn 1722: =back
1.565 albertel 1723:
1724: =cut
1725:
1726: sub resize_textarea_js {
1.590 raeburn 1727: my $geometry = &viewport_geometry_js();
1.565 albertel 1728: return <<"RESIZE";
1729: <script type="text/javascript">
1.824 bisitz 1730: // <![CDATA[
1.590 raeburn 1731: $geometry
1.565 albertel 1732:
1.588 albertel 1733: function getX(element) {
1734: var x = 0;
1735: while (element) {
1736: x += element.offsetLeft;
1737: element = element.offsetParent;
1738: }
1739: return x;
1740: }
1741: function getY(element) {
1742: var y = 0;
1743: while (element) {
1744: y += element.offsetTop;
1745: element = element.offsetParent;
1746: }
1747: return y;
1748: }
1749:
1750:
1.565 albertel 1751: function resize_textarea(textarea_id,bottom_id) {
1752: init_geometry();
1753: var textarea = document.getElementById(textarea_id);
1754: //alert(textarea);
1755:
1.588 albertel 1756: var textarea_top = getY(textarea);
1.565 albertel 1757: var textarea_height = textarea.offsetHeight;
1758: var bottom = document.getElementById(bottom_id);
1.588 albertel 1759: var bottom_top = getY(bottom);
1.565 albertel 1760: var bottom_height = bottom.offsetHeight;
1761: var window_height = Geometry.getViewportHeight();
1.588 albertel 1762: var fudge = 23;
1.565 albertel 1763: var new_height = window_height-fudge-textarea_top-bottom_height;
1764: if (new_height < 300) {
1765: new_height = 300;
1766: }
1767: textarea.style.height=new_height+'px';
1768: }
1.824 bisitz 1769: // ]]>
1.565 albertel 1770: </script>
1771: RESIZE
1772:
1773: }
1774:
1.1205 golterma 1775: sub colorfuleditor_js {
1776: return <<"COLORFULEDIT"
1777: <script type="text/javascript">
1778: // <![CDATA[>
1779: function fold_box(curDepth, lastresource){
1780:
1781: // we need a list because there can be several blocks you need to fold in one tag
1782: var block = document.getElementsByName('foldblock_'+curDepth);
1783: // but there is only one folding button per tag
1784: var foldbutton = document.getElementById('folding_btn_'+curDepth);
1785:
1786: if(block.item(0).style.display == 'none'){
1787:
1788: foldbutton.value = '@{[&mt("Hide")]}';
1789: for (i = 0; i < block.length; i++){
1790: block.item(i).style.display = '';
1791: }
1792: }else{
1793:
1794: foldbutton.value = '@{[&mt("Show")]}';
1795: for (i = 0; i < block.length; i++){
1796: // block.item(i).style.visibility = 'collapse';
1797: block.item(i).style.display = 'none';
1798: }
1799: };
1800: saveState(lastresource);
1801: }
1802:
1803: function saveState (lastresource) {
1804:
1805: var tag_list = getTagList();
1806: if(tag_list != null){
1807: var timestamp = new Date().getTime();
1808: var key = lastresource;
1809:
1810: // the value pattern is: 'time;key1,value1;key2,value2; ... '
1811: // starting with timestamp
1812: var value = timestamp+';';
1813:
1814: // building the list of key-value pairs
1815: for(var i = 0; i < tag_list.length; i++){
1816: value += tag_list[i]+',';
1817: value += document.getElementsByName(tag_list[i])[0].style.display+';';
1818: }
1819:
1820: // only iterate whole storage if nothing to override
1821: if(localStorage.getItem(key) == null){
1822:
1823: // prevent storage from growing large
1824: if(localStorage.length > 50){
1825: var regex_getTimestamp = /^(?:\d)+;/;
1826: var oldest_timestamp = regex_getTimestamp.exec(localStorage.key(0));
1827: var oldest_key;
1828:
1829: for(var i = 1; i < localStorage.length; i++){
1830: if (regex_getTimestamp.exec(localStorage.key(i)) < oldest_timestamp) {
1831: oldest_key = localStorage.key(i);
1832: oldest_timestamp = regex_getTimestamp.exec(oldest_key);
1833: }
1834: }
1835: localStorage.removeItem(oldest_key);
1836: }
1837: }
1838: localStorage.setItem(key,value);
1839: }
1840: }
1841:
1842: // restore folding status of blocks (on page load)
1843: function restoreState (lastresource) {
1844: if(localStorage.getItem(lastresource) != null){
1845: var key = lastresource;
1846: var value = localStorage.getItem(key);
1847: var regex_delTimestamp = /^\d+;/;
1848:
1849: value.replace(regex_delTimestamp, '');
1850:
1851: var valueArr = value.split(';');
1852: var pairs;
1853: var elements;
1854: for (var i = 0; i < valueArr.length; i++){
1855: pairs = valueArr[i].split(',');
1856: elements = document.getElementsByName(pairs[0]);
1857:
1858: for (var j = 0; j < elements.length; j++){
1859: elements[j].style.display = pairs[1];
1860: if (pairs[1] == "none"){
1861: var regex_id = /([_\\d]+)\$/;
1862: regex_id.exec(pairs[0]);
1863: document.getElementById("folding_btn"+RegExp.\$1).value = "Show";
1864: }
1865: }
1866: }
1867: }
1868: }
1869:
1870: function getTagList () {
1871:
1872: var stringToSearch = document.lonhomework.innerHTML;
1873:
1874: var ret = new Array();
1875: var regex_findBlock = /(foldblock_.*?)"/g;
1876: var tag_list = stringToSearch.match(regex_findBlock);
1877:
1878: if(tag_list != null){
1879: for(var i = 0; i < tag_list.length; i++){
1880: ret.push(tag_list[i].replace(/"/, ''));
1881: }
1882: }
1883: return ret;
1884: }
1885:
1886: function saveScrollPosition (resource) {
1887: var tag_list = getTagList();
1888:
1889: // we dont always want to jump to the first block
1890: // 170 is roughly above the "Problem Editing" header. we just want to save if the user scrolled down further than this
1891: if(\$(window).scrollTop() > 170){
1892: if(tag_list != null){
1893: var result;
1894: for(var i = 0; i < tag_list.length; i++){
1895: if(isElementInViewport(tag_list[i])){
1896: result += tag_list[i]+';';
1897: }
1898: }
1899: sessionStorage.setItem('anchor_'+resource, result);
1900: }
1901: } else {
1902: // we dont need to save zero, just delete the item to leave everything tidy
1903: sessionStorage.removeItem('anchor_'+resource);
1904: }
1905: }
1906:
1907: function restoreScrollPosition(resource){
1908:
1909: var elem = sessionStorage.getItem('anchor_'+resource);
1910: if(elem != null){
1911: var tag_list = elem.split(';');
1912: var elem_list;
1913:
1914: for(var i = 0; i < tag_list.length; i++){
1915: elem_list = document.getElementsByName(tag_list[i]);
1916:
1917: if(elem_list.length > 0){
1918: elem = elem_list[0];
1919: break;
1920: }
1921: }
1922: elem.scrollIntoView();
1923: }
1924: }
1925:
1926: function isElementInViewport(el) {
1927:
1928: // change to last element instead of first
1929: var elem = document.getElementsByName(el);
1930: var rect = elem[0].getBoundingClientRect();
1931:
1932: return (
1933: rect.top >= 0 &&
1934: rect.left >= 0 &&
1935: rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) && /*or $(window).height() */
1936: rect.right <= (window.innerWidth || document.documentElement.clientWidth) /*or $(window).width() */
1937: );
1938: }
1939:
1940: function autosize(depth){
1941: var cmInst = window['cm'+depth];
1942: var fitsizeButton = document.getElementById('fitsize'+depth);
1943:
1944: // is fixed size, switching to dynamic
1945: if (sessionStorage.getItem("autosized_"+depth) == null) {
1946: cmInst.setSize("","auto");
1947: fitsizeButton.value = "@{[&mt('Fixed size')]}";
1948: sessionStorage.setItem("autosized_"+depth, "yes");
1949:
1950: // is dynamic size, switching to fixed
1951: } else {
1952: cmInst.setSize("","300px");
1953: fitsizeButton.value = "@{[&mt('Dynamic size')]}";
1954: sessionStorage.removeItem("autosized_"+depth);
1955: }
1956: }
1957:
1958:
1959:
1960: // ]]>
1961: </script>
1962: COLORFULEDIT
1963: }
1964:
1965: sub xmleditor_js {
1966: return <<XMLEDIT
1967: <script type="text/javascript" src="/adm/jQuery/addons/jquery-scrolltofixed.js"></script>
1968: <script type="text/javascript">
1969: // <![CDATA[>
1970:
1971: function saveScrollPosition (resource) {
1972:
1973: var scrollPos = \$(window).scrollTop();
1974: sessionStorage.setItem(resource,scrollPos);
1975: }
1976:
1977: function restoreScrollPosition(resource){
1978:
1979: var scrollPos = sessionStorage.getItem(resource);
1980: \$(window).scrollTop(scrollPos);
1981: }
1982:
1983: // unless internet explorer
1984: if (!(window.navigator.appName == "Microsoft Internet Explorer" && (document.documentMode || document.compatMode))){
1985:
1986: \$(document).ready(function() {
1987: \$(".LC_edit_actionbar").scrollToFixed(\{zIndex: 100\});
1988: });
1989: }
1990:
1991: // inserts text at cursor position into codemirror (xml editor only)
1992: function insertText(text){
1993: cm.focus();
1994: var curPos = cm.getCursor();
1995: cm.replaceRange(text.replace(/ESCAPEDSCRIPT/g,'script'), {line: curPos.line,ch: curPos.ch});
1996: }
1997: // ]]>
1998: </script>
1999: XMLEDIT
2000: }
2001:
2002: sub insert_folding_button {
2003: my $curDepth = $Apache::lonxml::curdepth;
2004: my $lastresource = $env{'request.ambiguous'};
2005:
2006: return "<input type=\"button\" id=\"folding_btn_$curDepth\"
2007: value=\"".&mt('Hide')."\" onclick=\"fold_box('$curDepth','$lastresource')\">";
2008: }
2009:
1.565 albertel 2010: =pod
2011:
1.256 matthew 2012: =head1 Excel and CSV file utility routines
2013:
2014: =cut
2015:
2016: ###############################################################
2017: ###############################################################
2018:
2019: =pod
2020:
1.1162 raeburn 2021: =over 4
2022:
1.648 raeburn 2023: =item * &csv_translate($text)
1.37 matthew 2024:
1.185 www 2025: Translate $text to allow it to be output as a 'comma separated values'
1.37 matthew 2026: format.
2027:
2028: =cut
2029:
1.180 matthew 2030: ###############################################################
2031: ###############################################################
1.37 matthew 2032: sub csv_translate {
2033: my $text = shift;
2034: $text =~ s/\"/\"\"/g;
1.209 albertel 2035: $text =~ s/\n/ /g;
1.37 matthew 2036: return $text;
2037: }
1.180 matthew 2038:
2039: ###############################################################
2040: ###############################################################
2041:
2042: =pod
2043:
1.648 raeburn 2044: =item * &define_excel_formats()
1.180 matthew 2045:
2046: Define some commonly used Excel cell formats.
2047:
2048: Currently supported formats:
2049:
2050: =over 4
2051:
2052: =item header
2053:
2054: =item bold
2055:
2056: =item h1
2057:
2058: =item h2
2059:
2060: =item h3
2061:
1.256 matthew 2062: =item h4
2063:
2064: =item i
2065:
1.180 matthew 2066: =item date
2067:
2068: =back
2069:
2070: Inputs: $workbook
2071:
2072: Returns: $format, a hash reference.
2073:
1.1057 foxr 2074:
1.180 matthew 2075: =cut
2076:
2077: ###############################################################
2078: ###############################################################
2079: sub define_excel_formats {
2080: my ($workbook) = @_;
2081: my $format;
2082: $format->{'header'} = $workbook->add_format(bold => 1,
2083: bottom => 1,
2084: align => 'center');
2085: $format->{'bold'} = $workbook->add_format(bold=>1);
2086: $format->{'h1'} = $workbook->add_format(bold=>1, size=>18);
2087: $format->{'h2'} = $workbook->add_format(bold=>1, size=>16);
2088: $format->{'h3'} = $workbook->add_format(bold=>1, size=>14);
1.255 matthew 2089: $format->{'h4'} = $workbook->add_format(bold=>1, size=>12);
1.246 matthew 2090: $format->{'i'} = $workbook->add_format(italic=>1);
1.180 matthew 2091: $format->{'date'} = $workbook->add_format(num_format=>
1.207 matthew 2092: 'mm/dd/yyyy hh:mm:ss');
1.180 matthew 2093: return $format;
2094: }
2095:
2096: ###############################################################
2097: ###############################################################
1.113 bowersj2 2098:
2099: =pod
2100:
1.648 raeburn 2101: =item * &create_workbook()
1.255 matthew 2102:
2103: Create an Excel worksheet. If it fails, output message on the
2104: request object and return undefs.
2105:
2106: Inputs: Apache request object
2107:
2108: Returns (undef) on failure,
2109: Excel worksheet object, scalar with filename, and formats
2110: from &Apache::loncommon::define_excel_formats on success
2111:
2112: =cut
2113:
2114: ###############################################################
2115: ###############################################################
2116: sub create_workbook {
2117: my ($r) = @_;
2118: #
2119: # Create the excel spreadsheet
2120: my $filename = '/prtspool/'.
1.258 albertel 2121: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.255 matthew 2122: time.'_'.rand(1000000000).'.xls';
2123: my $workbook = Spreadsheet::WriteExcel->new('/home/httpd'.$filename);
2124: if (! defined($workbook)) {
2125: $r->log_error("Error creating excel spreadsheet $filename: $!");
1.928 bisitz 2126: $r->print(
2127: '<p class="LC_error">'
2128: .&mt('Problems occurred in creating the new Excel file.')
2129: .' '.&mt('This error has been logged.')
2130: .' '.&mt('Please alert your LON-CAPA administrator.')
2131: .'</p>'
2132: );
1.255 matthew 2133: return (undef);
2134: }
2135: #
1.1014 foxr 2136: $workbook->set_tempdir(LONCAPA::tempdir());
1.255 matthew 2137: #
2138: my $format = &Apache::loncommon::define_excel_formats($workbook);
2139: return ($workbook,$filename,$format);
2140: }
2141:
2142: ###############################################################
2143: ###############################################################
2144:
2145: =pod
2146:
1.648 raeburn 2147: =item * &create_text_file()
1.113 bowersj2 2148:
1.542 raeburn 2149: Create a file to write to and eventually make available to the user.
1.256 matthew 2150: If file creation fails, outputs an error message on the request object and
2151: return undefs.
1.113 bowersj2 2152:
1.256 matthew 2153: Inputs: Apache request object, and file suffix
1.113 bowersj2 2154:
1.256 matthew 2155: Returns (undef) on failure,
2156: Filehandle and filename on success.
1.113 bowersj2 2157:
2158: =cut
2159:
1.256 matthew 2160: ###############################################################
2161: ###############################################################
2162: sub create_text_file {
2163: my ($r,$suffix) = @_;
2164: if (! defined($suffix)) { $suffix = 'txt'; };
2165: my $fh;
2166: my $filename = '/prtspool/'.
1.258 albertel 2167: $env{'user.name'}.'_'.$env{'user.domain'}.'_'.
1.256 matthew 2168: time.'_'.rand(1000000000).'.'.$suffix;
2169: $fh = Apache::File->new('>/home/httpd'.$filename);
2170: if (! defined($fh)) {
2171: $r->log_error("Couldn't open $filename for output $!");
1.928 bisitz 2172: $r->print(
2173: '<p class="LC_error">'
2174: .&mt('Problems occurred in creating the output file.')
2175: .' '.&mt('This error has been logged.')
2176: .' '.&mt('Please alert your LON-CAPA administrator.')
2177: .'</p>'
2178: );
1.113 bowersj2 2179: }
1.256 matthew 2180: return ($fh,$filename)
1.113 bowersj2 2181: }
2182:
2183:
1.256 matthew 2184: =pod
1.113 bowersj2 2185:
2186: =back
2187:
2188: =cut
1.37 matthew 2189:
2190: ###############################################################
1.33 matthew 2191: ## Home server <option> list generating code ##
2192: ###############################################################
1.35 matthew 2193:
1.169 www 2194: # ------------------------------------------
2195:
2196: sub domain_select {
2197: my ($name,$value,$multiple)=@_;
2198: my %domains=map {
1.514 albertel 2199: $_ => $_.' '. &Apache::lonnet::domain($_,'description')
1.512 albertel 2200: } &Apache::lonnet::all_domains();
1.169 www 2201: if ($multiple) {
2202: $domains{''}=&mt('Any domain');
1.550 albertel 2203: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.287 albertel 2204: return &multiple_select_form($name,$value,4,\%domains);
1.169 www 2205: } else {
1.550 albertel 2206: $domains{'select_form_order'} = [sort {lc($a) cmp lc($b) } (keys(%domains))];
1.970 raeburn 2207: return &select_form($name,$value,\%domains);
1.169 www 2208: }
2209: }
2210:
1.282 albertel 2211: #-------------------------------------------
2212:
2213: =pod
2214:
1.519 raeburn 2215: =head1 Routines for form select boxes
2216:
2217: =over 4
2218:
1.648 raeburn 2219: =item * &multiple_select_form($name,$value,$size,$hash,$order)
1.282 albertel 2220:
2221: Returns a string containing a <select> element int multiple mode
2222:
2223:
2224: Args:
2225: $name - name of the <select> element
1.506 raeburn 2226: $value - scalar or array ref of values that should already be selected
1.282 albertel 2227: $size - number of rows long the select element is
1.283 albertel 2228: $hash - the elements should be 'option' => 'shown text'
1.282 albertel 2229: (shown text should already have been &mt())
1.506 raeburn 2230: $order - (optional) array ref of the order to show the elements in
1.283 albertel 2231:
1.282 albertel 2232: =cut
2233:
2234: #-------------------------------------------
1.169 www 2235: sub multiple_select_form {
1.284 albertel 2236: my ($name,$value,$size,$hash,$order)=@_;
1.169 www 2237: my %selected = map { $_ => 1 } ref($value)?@{$value}:($value);
2238: my $output='';
1.191 matthew 2239: if (! defined($size)) {
2240: $size = 4;
1.283 albertel 2241: if (scalar(keys(%$hash))<4) {
2242: $size = scalar(keys(%$hash));
1.191 matthew 2243: }
2244: }
1.734 bisitz 2245: $output.="\n".'<select name="'.$name.'" size="'.$size.'" multiple="multiple">';
1.501 banghart 2246: my @order;
1.506 raeburn 2247: if (ref($order) eq 'ARRAY') {
2248: @order = @{$order};
2249: } else {
2250: @order = sort(keys(%$hash));
1.501 banghart 2251: }
2252: if (exists($$hash{'select_form_order'})) {
2253: @order = @{$$hash{'select_form_order'}};
2254: }
2255:
1.284 albertel 2256: foreach my $key (@order) {
1.356 albertel 2257: $output.='<option value="'.&HTML::Entities::encode($key,'"<>&').'" ';
1.284 albertel 2258: $output.='selected="selected" ' if ($selected{$key});
2259: $output.='>'.$hash->{$key}."</option>\n";
1.169 www 2260: }
2261: $output.="</select>\n";
2262: return $output;
2263: }
2264:
1.88 www 2265: #-------------------------------------------
2266:
2267: =pod
2268:
1.970 raeburn 2269: =item * &select_form($defdom,$name,$hashref,$onchange)
1.88 www 2270:
2271: Returns a string containing a <select name='$name' size='1'> form to
1.970 raeburn 2272: allow a user to select options from a ref to a hash containing:
2273: option_name => displayed text. An optional $onchange can include
2274: a javascript onchange item, e.g., onchange="this.form.submit();"
2275:
1.88 www 2276: See lonrights.pm for an example invocation and use.
2277:
2278: =cut
2279:
2280: #-------------------------------------------
2281: sub select_form {
1.1228 raeburn 2282: my ($def,$name,$hashref,$onchange,$readonly) = @_;
1.970 raeburn 2283: return unless (ref($hashref) eq 'HASH');
2284: if ($onchange) {
2285: $onchange = ' onchange="'.$onchange.'"';
2286: }
1.1228 raeburn 2287: my $disabled;
2288: if ($readonly) {
2289: $disabled = ' disabled="disabled"';
2290: }
2291: my $selectform = "<select name=\"$name\" size=\"1\"$onchange$disabled>\n";
1.128 albertel 2292: my @keys;
1.970 raeburn 2293: if (exists($hashref->{'select_form_order'})) {
2294: @keys=@{$hashref->{'select_form_order'}};
1.128 albertel 2295: } else {
1.970 raeburn 2296: @keys=sort(keys(%{$hashref}));
1.128 albertel 2297: }
1.356 albertel 2298: foreach my $key (@keys) {
2299: $selectform.=
2300: '<option value="'.&HTML::Entities::encode($key,'"<>&').'" '.
2301: ($key eq $def ? 'selected="selected" ' : '').
1.970 raeburn 2302: ">".$hashref->{$key}."</option>\n";
1.88 www 2303: }
2304: $selectform.="</select>";
2305: return $selectform;
2306: }
2307:
1.475 www 2308: # For display filters
2309:
2310: sub display_filter {
1.1074 raeburn 2311: my ($context) = @_;
1.475 www 2312: if (!$env{'form.show'}) { $env{'form.show'}=10; }
1.477 www 2313: if (!$env{'form.displayfilter'}) { $env{'form.displayfilter'}='currentfolder'; }
1.1074 raeburn 2314: my $phraseinput = 'hidden';
2315: my $includeinput = 'hidden';
2316: my ($checked,$includetypestext);
2317: if ($env{'form.displayfilter'} eq 'containing') {
2318: $phraseinput = 'text';
2319: if ($context eq 'parmslog') {
2320: $includeinput = 'checkbox';
2321: if ($env{'form.includetypes'}) {
2322: $checked = ' checked="checked"';
2323: }
2324: $includetypestext = &mt('Include parameter types');
2325: }
2326: } else {
2327: $includetypestext = ' ';
2328: }
2329: my ($additional,$secondid,$thirdid);
2330: if ($context eq 'parmslog') {
2331: $additional =
2332: '<label><input type="'.$includeinput.'" name="includetypes"'.
2333: $checked.' name="includetypes" value="1" id="includetypes" />'.
2334: ' <span id="includetypestext">'.$includetypestext.'</span>'.
2335: '</label>';
2336: $secondid = 'includetypes';
2337: $thirdid = 'includetypestext';
2338: }
2339: my $onchange = "javascript:toggleHistoryOptions(this,'containingphrase','$context',
2340: '$secondid','$thirdid')";
2341: return '<span class="LC_nobreak"><label>'.&mt('Records: [_1]',
1.475 www 2342: &Apache::lonmeta::selectbox('show',$env{'form.show'},undef,
2343: (&mt('all'),10,20,50,100,1000,10000))).
1.714 bisitz 2344: '</label></span> <span class="LC_nobreak">'.
1.1074 raeburn 2345: &mt('Filter: [_1]',
1.477 www 2346: &select_form($env{'form.displayfilter'},
2347: 'displayfilter',
1.970 raeburn 2348: {'currentfolder' => 'Current folder/page',
1.477 www 2349: 'containing' => 'Containing phrase',
1.1074 raeburn 2350: 'none' => 'None'},$onchange)).' '.
2351: '<input type="'.$phraseinput.'" name="containingphrase" id="containingphrase" size="30" value="'.
2352: &HTML::Entities::encode($env{'form.containingphrase'}).
2353: '" />'.$additional;
2354: }
2355:
2356: sub display_filter_js {
2357: my $includetext = &mt('Include parameter types');
2358: return <<"ENDJS";
2359:
2360: function toggleHistoryOptions(setter,firstid,context,secondid,thirdid) {
2361: var firstType = 'hidden';
2362: if (setter.options[setter.selectedIndex].value == 'containing') {
2363: firstType = 'text';
2364: }
2365: firstObject = document.getElementById(firstid);
2366: if (typeof(firstObject) == 'object') {
2367: if (firstObject.type != firstType) {
2368: changeInputType(firstObject,firstType);
2369: }
2370: }
2371: if (context == 'parmslog') {
2372: var secondType = 'hidden';
2373: if (firstType == 'text') {
2374: secondType = 'checkbox';
2375: }
2376: secondObject = document.getElementById(secondid);
2377: if (typeof(secondObject) == 'object') {
2378: if (secondObject.type != secondType) {
2379: changeInputType(secondObject,secondType);
2380: }
2381: }
2382: var textItem = document.getElementById(thirdid);
2383: var currtext = textItem.innerHTML;
2384: var newtext;
2385: if (firstType == 'text') {
2386: newtext = '$includetext';
2387: } else {
2388: newtext = ' ';
2389: }
2390: if (currtext != newtext) {
2391: textItem.innerHTML = newtext;
2392: }
2393: }
2394: return;
2395: }
2396:
2397: function changeInputType(oldObject,newType) {
2398: var newObject = document.createElement('input');
2399: newObject.type = newType;
2400: if (oldObject.size) {
2401: newObject.size = oldObject.size;
2402: }
2403: if (oldObject.value) {
2404: newObject.value = oldObject.value;
2405: }
2406: if (oldObject.name) {
2407: newObject.name = oldObject.name;
2408: }
2409: if (oldObject.id) {
2410: newObject.id = oldObject.id;
2411: }
2412: oldObject.parentNode.replaceChild(newObject,oldObject);
2413: return;
2414: }
2415:
2416: ENDJS
1.475 www 2417: }
2418:
1.167 www 2419: sub gradeleveldescription {
2420: my $gradelevel=shift;
2421: my %gradelevels=(0 => 'Not specified',
2422: 1 => 'Grade 1',
2423: 2 => 'Grade 2',
2424: 3 => 'Grade 3',
2425: 4 => 'Grade 4',
2426: 5 => 'Grade 5',
2427: 6 => 'Grade 6',
2428: 7 => 'Grade 7',
2429: 8 => 'Grade 8',
2430: 9 => 'Grade 9',
2431: 10 => 'Grade 10',
2432: 11 => 'Grade 11',
2433: 12 => 'Grade 12',
2434: 13 => 'Grade 13',
2435: 14 => '100 Level',
2436: 15 => '200 Level',
2437: 16 => '300 Level',
2438: 17 => '400 Level',
2439: 18 => 'Graduate Level');
2440: return &mt($gradelevels{$gradelevel});
2441: }
2442:
1.163 www 2443: sub select_level_form {
2444: my ($deflevel,$name)=@_;
2445: unless ($deflevel) { $deflevel=0; }
1.167 www 2446: my $selectform = "<select name=\"$name\" size=\"1\">\n";
2447: for (my $i=0; $i<=18; $i++) {
2448: $selectform.="<option value=\"$i\" ".
1.253 albertel 2449: ($i==$deflevel ? 'selected="selected" ' : '').
1.167 www 2450: ">".&gradeleveldescription($i)."</option>\n";
2451: }
2452: $selectform.="</select>";
2453: return $selectform;
1.163 www 2454: }
1.167 www 2455:
1.35 matthew 2456: #-------------------------------------------
2457:
1.45 matthew 2458: =pod
2459:
1.1121 raeburn 2460: =item * &select_dom_form($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms)
1.35 matthew 2461:
2462: Returns a string containing a <select name='$name' size='1'> form to
2463: allow a user to select the domain to preform an operation in.
2464: See loncreateuser.pm for an example invocation and use.
2465:
1.90 www 2466: If the $includeempty flag is set, it also includes an empty choice ("no domain
2467: selected");
2468:
1.743 raeburn 2469: If the $showdomdesc flag is set, the domain name is followed by the domain description.
2470:
1.910 raeburn 2471: 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.
2472:
1.1121 raeburn 2473: The optional $incdoms is a reference to an array of domains which will be the only available options.
2474:
2475: The optional $excdoms is a reference to an array of domains which will be excluded from the available options.
1.563 raeburn 2476:
1.35 matthew 2477: =cut
2478:
2479: #-------------------------------------------
1.34 matthew 2480: sub select_dom_form {
1.1121 raeburn 2481: my ($defdom,$name,$includeempty,$showdomdesc,$onchange,$incdoms,$excdoms) = @_;
1.872 raeburn 2482: if ($onchange) {
1.874 raeburn 2483: $onchange = ' onchange="'.$onchange.'"';
1.743 raeburn 2484: }
1.1121 raeburn 2485: my (@domains,%exclude);
1.910 raeburn 2486: if (ref($incdoms) eq 'ARRAY') {
2487: @domains = sort {lc($a) cmp lc($b)} (@{$incdoms});
2488: } else {
2489: @domains = sort {lc($a) cmp lc($b)} (&Apache::lonnet::all_domains());
2490: }
1.90 www 2491: if ($includeempty) { @domains=('',@domains); }
1.1121 raeburn 2492: if (ref($excdoms) eq 'ARRAY') {
2493: map { $exclude{$_} = 1; } @{$excdoms};
2494: }
1.743 raeburn 2495: my $selectdomain = "<select name=\"$name\" size=\"1\"$onchange>\n";
1.356 albertel 2496: foreach my $dom (@domains) {
1.1121 raeburn 2497: next if ($exclude{$dom});
1.356 albertel 2498: $selectdomain.="<option value=\"$dom\" ".
1.563 raeburn 2499: ($dom eq $defdom ? 'selected="selected" ' : '').'>'.$dom;
2500: if ($showdomdesc) {
2501: if ($dom ne '') {
2502: my $domdesc = &Apache::lonnet::domain($dom,'description');
2503: if ($domdesc ne '') {
2504: $selectdomain .= ' ('.$domdesc.')';
2505: }
2506: }
2507: }
2508: $selectdomain .= "</option>\n";
1.34 matthew 2509: }
2510: $selectdomain.="</select>";
2511: return $selectdomain;
2512: }
2513:
1.35 matthew 2514: #-------------------------------------------
2515:
1.45 matthew 2516: =pod
2517:
1.648 raeburn 2518: =item * &home_server_form_item($domain,$name,$defaultflag)
1.35 matthew 2519:
1.586 raeburn 2520: input: 4 arguments (two required, two optional) -
2521: $domain - domain of new user
2522: $name - name of form element
2523: $default - Value of 'default' causes a default item to be first
2524: option, and selected by default.
2525: $hide - Value of 'hide' causes hiding of the name of the server,
2526: if 1 server found, or default, if 0 found.
1.594 raeburn 2527: output: returns 2 items:
1.586 raeburn 2528: (a) form element which contains either:
2529: (i) <select name="$name">
2530: <option value="$hostid1">$hostid $servers{$hostid}</option>
2531: <option value="$hostid2">$hostid $servers{$hostid}</option>
2532: </select>
2533: form item if there are multiple library servers in $domain, or
2534: (ii) an <input type="hidden" name="$name" value="$hostid" /> form item
2535: if there is only one library server in $domain.
2536:
2537: (b) number of library servers found.
2538:
2539: See loncreateuser.pm for example of use.
1.35 matthew 2540:
2541: =cut
2542:
2543: #-------------------------------------------
1.586 raeburn 2544: sub home_server_form_item {
2545: my ($domain,$name,$default,$hide) = @_;
1.513 albertel 2546: my %servers = &Apache::lonnet::get_servers($domain,'library');
1.586 raeburn 2547: my $result;
2548: my $numlib = keys(%servers);
2549: if ($numlib > 1) {
2550: $result .= '<select name="'.$name.'" />'."\n";
2551: if ($default) {
1.804 bisitz 2552: $result .= '<option value="default" selected="selected">'.&mt('default').
1.586 raeburn 2553: '</option>'."\n";
2554: }
2555: foreach my $hostid (sort(keys(%servers))) {
2556: $result.= '<option value="'.$hostid.'">'.
2557: $hostid.' '.$servers{$hostid}."</option>\n";
2558: }
2559: $result .= '</select>'."\n";
2560: } elsif ($numlib == 1) {
2561: my $hostid;
2562: foreach my $item (keys(%servers)) {
2563: $hostid = $item;
2564: }
2565: $result .= '<input type="hidden" name="'.$name.'" value="'.
2566: $hostid.'" />';
2567: if (!$hide) {
2568: $result .= $hostid.' '.$servers{$hostid};
2569: }
2570: $result .= "\n";
2571: } elsif ($default) {
2572: $result .= '<input type="hidden" name="'.$name.
2573: '" value="default" />';
2574: if (!$hide) {
2575: $result .= &mt('default');
2576: }
2577: $result .= "\n";
1.33 matthew 2578: }
1.586 raeburn 2579: return ($result,$numlib);
1.33 matthew 2580: }
1.112 bowersj2 2581:
2582: =pod
2583:
1.534 albertel 2584: =back
2585:
1.112 bowersj2 2586: =cut
1.87 matthew 2587:
2588: ###############################################################
1.112 bowersj2 2589: ## Decoding User Agent ##
1.87 matthew 2590: ###############################################################
2591:
2592: =pod
2593:
1.112 bowersj2 2594: =head1 Decoding the User Agent
2595:
2596: =over 4
2597:
2598: =item * &decode_user_agent()
1.87 matthew 2599:
2600: Inputs: $r
2601:
2602: Outputs:
2603:
2604: =over 4
2605:
1.112 bowersj2 2606: =item * $httpbrowser
1.87 matthew 2607:
1.112 bowersj2 2608: =item * $clientbrowser
1.87 matthew 2609:
1.112 bowersj2 2610: =item * $clientversion
1.87 matthew 2611:
1.112 bowersj2 2612: =item * $clientmathml
1.87 matthew 2613:
1.112 bowersj2 2614: =item * $clientunicode
1.87 matthew 2615:
1.112 bowersj2 2616: =item * $clientos
1.87 matthew 2617:
1.1137 raeburn 2618: =item * $clientmobile
2619:
1.1141 raeburn 2620: =item * $clientinfo
2621:
1.1194 raeburn 2622: =item * $clientosversion
2623:
1.87 matthew 2624: =back
2625:
1.157 matthew 2626: =back
2627:
1.87 matthew 2628: =cut
2629:
2630: ###############################################################
2631: ###############################################################
2632: sub decode_user_agent {
1.247 albertel 2633: my ($r)=@_;
1.87 matthew 2634: my @browsertype=split(/\&/,$Apache::lonnet::perlvar{"lonBrowsDet"});
2635: my %mathcap=split(/\&/,$$Apache::lonnet::perlvar{"lonMathML"});
2636: my $httpbrowser=$ENV{"HTTP_USER_AGENT"};
1.247 albertel 2637: if (!$httpbrowser && $r) { $httpbrowser=$r->header_in('User-Agent'); }
1.87 matthew 2638: my $clientbrowser='unknown';
2639: my $clientversion='0';
2640: my $clientmathml='';
2641: my $clientunicode='0';
1.1137 raeburn 2642: my $clientmobile=0;
1.1194 raeburn 2643: my $clientosversion='';
1.87 matthew 2644: for (my $i=0;$i<=$#browsertype;$i++) {
1.1193 raeburn 2645: my ($bname,$match,$notmatch,$vreg,$minv,$univ)=split(/\%/,$browsertype[$i]);
1.87 matthew 2646: if (($httpbrowser=~/$match/i) && ($httpbrowser!~/$notmatch/i)) {
2647: $clientbrowser=$bname;
2648: $httpbrowser=~/$vreg/i;
2649: $clientversion=$1;
2650: $clientmathml=($clientversion>=$minv);
2651: $clientunicode=($clientversion>=$univ);
2652: }
2653: }
2654: my $clientos='unknown';
1.1141 raeburn 2655: my $clientinfo;
1.87 matthew 2656: if (($httpbrowser=~/linux/i) ||
2657: ($httpbrowser=~/unix/i) ||
2658: ($httpbrowser=~/ux/i) ||
2659: ($httpbrowser=~/solaris/i)) { $clientos='unix'; }
2660: if (($httpbrowser=~/vax/i) ||
2661: ($httpbrowser=~/vms/i)) { $clientos='vms'; }
2662: if ($httpbrowser=~/next/i) { $clientos='next'; }
2663: if (($httpbrowser=~/mac/i) ||
2664: ($httpbrowser=~/powerpc/i)) { $clientos='mac'; }
1.1194 raeburn 2665: if ($httpbrowser=~/win/i) {
2666: $clientos='win';
2667: if ($httpbrowser =~/Windows\s+NT\s+(\d+\.\d+)/i) {
2668: $clientosversion = $1;
2669: }
2670: }
1.87 matthew 2671: if ($httpbrowser=~/embed/i) { $clientos='pda'; }
1.1137 raeburn 2672: if ($httpbrowser=~/(Android|iPod|iPad|iPhone|webOS|Blackberry|Windows Phone|Opera m(?:ob|in)|Fennec)/i) {
2673: $clientmobile=lc($1);
2674: }
1.1141 raeburn 2675: if ($httpbrowser=~ m{Firefox/(\d+\.\d+)}) {
2676: $clientinfo = 'firefox-'.$1;
2677: } elsif ($httpbrowser=~ m{chromeframe/(\d+\.\d+)\.}) {
2678: $clientinfo = 'chromeframe-'.$1;
2679: }
1.87 matthew 2680: return ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,
1.1194 raeburn 2681: $clientunicode,$clientos,$clientmobile,$clientinfo,
2682: $clientosversion);
1.87 matthew 2683: }
2684:
1.32 matthew 2685: ###############################################################
2686: ## Authentication changing form generation subroutines ##
2687: ###############################################################
2688: ##
2689: ## All of the authform_xxxxxxx subroutines take their inputs in a
2690: ## hash, and have reasonable default values.
2691: ##
2692: ## formname = the name given in the <form> tag.
1.35 matthew 2693: #-------------------------------------------
2694:
1.45 matthew 2695: =pod
2696:
1.112 bowersj2 2697: =head1 Authentication Routines
2698:
2699: =over 4
2700:
1.648 raeburn 2701: =item * &authform_xxxxxx()
1.35 matthew 2702:
2703: The authform_xxxxxx subroutines provide javascript and html forms which
2704: handle some of the conveniences required for authentication forms.
2705: This is not an optimal method, but it works.
2706:
2707: =over 4
2708:
1.112 bowersj2 2709: =item * authform_header
1.35 matthew 2710:
1.112 bowersj2 2711: =item * authform_authorwarning
1.35 matthew 2712:
1.112 bowersj2 2713: =item * authform_nochange
1.35 matthew 2714:
1.112 bowersj2 2715: =item * authform_kerberos
1.35 matthew 2716:
1.112 bowersj2 2717: =item * authform_internal
1.35 matthew 2718:
1.112 bowersj2 2719: =item * authform_filesystem
1.35 matthew 2720:
2721: =back
2722:
1.648 raeburn 2723: See loncreateuser.pm for invocation and use examples.
1.157 matthew 2724:
1.35 matthew 2725: =cut
2726:
2727: #-------------------------------------------
1.32 matthew 2728: sub authform_header{
2729: my %in = (
2730: formname => 'cu',
1.80 albertel 2731: kerb_def_dom => '',
1.32 matthew 2732: @_,
2733: );
2734: $in{'formname'} = 'document.' . $in{'formname'};
2735: my $result='';
1.80 albertel 2736:
2737: #---------------------------------------------- Code for upper case translation
2738: my $Javascript_toUpperCase;
2739: unless ($in{kerb_def_dom}) {
2740: $Javascript_toUpperCase =<<"END";
2741: switch (choice) {
2742: case 'krb': currentform.elements[choicearg].value =
2743: currentform.elements[choicearg].value.toUpperCase();
2744: break;
2745: default:
2746: }
2747: END
2748: } else {
2749: $Javascript_toUpperCase = "";
2750: }
2751:
1.165 raeburn 2752: my $radioval = "'nochange'";
1.591 raeburn 2753: if (defined($in{'curr_authtype'})) {
2754: if ($in{'curr_authtype'} ne '') {
2755: $radioval = "'".$in{'curr_authtype'}."arg'";
2756: }
1.174 matthew 2757: }
1.165 raeburn 2758: my $argfield = 'null';
1.591 raeburn 2759: if (defined($in{'mode'})) {
1.165 raeburn 2760: if ($in{'mode'} eq 'modifycourse') {
1.591 raeburn 2761: if (defined($in{'curr_autharg'})) {
2762: if ($in{'curr_autharg'} ne '') {
1.165 raeburn 2763: $argfield = "'$in{'curr_autharg'}'";
2764: }
2765: }
2766: }
2767: }
2768:
1.32 matthew 2769: $result.=<<"END";
2770: var current = new Object();
1.165 raeburn 2771: current.radiovalue = $radioval;
2772: current.argfield = $argfield;
1.32 matthew 2773:
2774: function changed_radio(choice,currentform) {
2775: var choicearg = choice + 'arg';
2776: // If a radio button in changed, we need to change the argfield
2777: if (current.radiovalue != choice) {
2778: current.radiovalue = choice;
2779: if (current.argfield != null) {
2780: currentform.elements[current.argfield].value = '';
2781: }
2782: if (choice == 'nochange') {
2783: current.argfield = null;
2784: } else {
2785: current.argfield = choicearg;
2786: switch(choice) {
2787: case 'krb':
2788: currentform.elements[current.argfield].value =
2789: "$in{'kerb_def_dom'}";
2790: break;
2791: default:
2792: break;
2793: }
2794: }
2795: }
2796: return;
2797: }
1.22 www 2798:
1.32 matthew 2799: function changed_text(choice,currentform) {
2800: var choicearg = choice + 'arg';
2801: if (currentform.elements[choicearg].value !='') {
1.80 albertel 2802: $Javascript_toUpperCase
1.32 matthew 2803: // clear old field
2804: if ((current.argfield != choicearg) && (current.argfield != null)) {
2805: currentform.elements[current.argfield].value = '';
2806: }
2807: current.argfield = choicearg;
2808: }
2809: set_auth_radio_buttons(choice,currentform);
2810: return;
1.20 www 2811: }
1.32 matthew 2812:
2813: function set_auth_radio_buttons(newvalue,currentform) {
1.986 raeburn 2814: var numauthchoices = currentform.login.length;
2815: if (typeof numauthchoices == "undefined") {
2816: return;
2817: }
1.32 matthew 2818: var i=0;
1.986 raeburn 2819: while (i < numauthchoices) {
1.32 matthew 2820: if (currentform.login[i].value == newvalue) { break; }
2821: i++;
2822: }
1.986 raeburn 2823: if (i == numauthchoices) {
1.32 matthew 2824: return;
2825: }
2826: current.radiovalue = newvalue;
2827: currentform.login[i].checked = true;
2828: return;
2829: }
2830: END
2831: return $result;
2832: }
2833:
1.1106 raeburn 2834: sub authform_authorwarning {
1.32 matthew 2835: my $result='';
1.144 matthew 2836: $result='<i>'.
2837: &mt('As a general rule, only authors or co-authors should be '.
2838: 'filesystem authenticated '.
2839: '(which allows access to the server filesystem).')."</i>\n";
1.32 matthew 2840: return $result;
2841: }
2842:
1.1106 raeburn 2843: sub authform_nochange {
1.32 matthew 2844: my %in = (
2845: formname => 'document.cu',
2846: kerb_def_dom => 'MSU.EDU',
2847: @_,
2848: );
1.1106 raeburn 2849: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.586 raeburn 2850: my $result;
1.1104 raeburn 2851: if (!$authnum) {
1.1105 raeburn 2852: $result = &mt('Under your current role you are not permitted to change login settings for this user');
1.586 raeburn 2853: } else {
2854: $result = '<label>'.&mt('[_1] Do not change login data',
2855: '<input type="radio" name="login" value="nochange" '.
2856: 'checked="checked" onclick="'.
1.281 albertel 2857: "javascript:changed_radio('nochange',$in{'formname'});".'" />').
2858: '</label>';
1.586 raeburn 2859: }
1.32 matthew 2860: return $result;
2861: }
2862:
1.591 raeburn 2863: sub authform_kerberos {
1.32 matthew 2864: my %in = (
2865: formname => 'document.cu',
2866: kerb_def_dom => 'MSU.EDU',
1.80 albertel 2867: kerb_def_auth => 'krb4',
1.32 matthew 2868: @_,
2869: );
1.586 raeburn 2870: my ($check4,$check5,$krbcheck,$krbarg,$krbver,$result,$authtype,
2871: $autharg,$jscall);
1.1106 raeburn 2872: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.80 albertel 2873: if ($in{'kerb_def_auth'} eq 'krb5') {
1.772 bisitz 2874: $check5 = ' checked="checked"';
1.80 albertel 2875: } else {
1.772 bisitz 2876: $check4 = ' checked="checked"';
1.80 albertel 2877: }
1.165 raeburn 2878: $krbarg = $in{'kerb_def_dom'};
1.591 raeburn 2879: if (defined($in{'curr_authtype'})) {
2880: if ($in{'curr_authtype'} eq 'krb') {
1.772 bisitz 2881: $krbcheck = ' checked="checked"';
1.623 raeburn 2882: if (defined($in{'mode'})) {
2883: if ($in{'mode'} eq 'modifyuser') {
2884: $krbcheck = '';
2885: }
2886: }
1.591 raeburn 2887: if (defined($in{'curr_kerb_ver'})) {
2888: if ($in{'curr_krb_ver'} eq '5') {
1.772 bisitz 2889: $check5 = ' checked="checked"';
1.591 raeburn 2890: $check4 = '';
2891: } else {
1.772 bisitz 2892: $check4 = ' checked="checked"';
1.591 raeburn 2893: $check5 = '';
2894: }
1.586 raeburn 2895: }
1.591 raeburn 2896: if (defined($in{'curr_autharg'})) {
1.165 raeburn 2897: $krbarg = $in{'curr_autharg'};
2898: }
1.586 raeburn 2899: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
1.591 raeburn 2900: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2901: $result =
2902: &mt('Currently Kerberos authenticated with domain [_1] Version [_2].',
2903: $in{'curr_autharg'},$krbver);
2904: } else {
2905: $result =
2906: &mt('Currently Kerberos authenticated, Version [_1].',$krbver);
2907: }
2908: return $result;
2909: }
2910: }
2911: } else {
2912: if ($authnum == 1) {
1.784 bisitz 2913: $authtype = '<input type="hidden" name="login" value="krb" />';
1.165 raeburn 2914: }
2915: }
1.586 raeburn 2916: if (!$can_assign{'krb4'} && !$can_assign{'krb5'}) {
2917: return;
1.587 raeburn 2918: } elsif ($authtype eq '') {
1.591 raeburn 2919: if (defined($in{'mode'})) {
1.587 raeburn 2920: if ($in{'mode'} eq 'modifycourse') {
2921: if ($authnum == 1) {
1.1104 raeburn 2922: $authtype = '<input type="radio" name="login" value="krb" />';
1.587 raeburn 2923: }
2924: }
2925: }
1.586 raeburn 2926: }
2927: $jscall = "javascript:changed_radio('krb',$in{'formname'});";
2928: if ($authtype eq '') {
2929: $authtype = '<input type="radio" name="login" value="krb" '.
2930: 'onclick="'.$jscall.'" onchange="'.$jscall.'"'.
2931: $krbcheck.' />';
2932: }
2933: if (($can_assign{'krb4'} && $can_assign{'krb5'}) ||
1.1106 raeburn 2934: ($can_assign{'krb4'} && !$can_assign{'krb5'} &&
1.586 raeburn 2935: $in{'curr_authtype'} eq 'krb5') ||
1.1106 raeburn 2936: (!$can_assign{'krb4'} && $can_assign{'krb5'} &&
1.586 raeburn 2937: $in{'curr_authtype'} eq 'krb4')) {
2938: $result .= &mt
1.144 matthew 2939: ('[_1] Kerberos authenticated with domain [_2] '.
1.281 albertel 2940: '[_3] Version 4 [_4] Version 5 [_5]',
1.586 raeburn 2941: '<label>'.$authtype,
1.281 albertel 2942: '</label><input type="text" size="10" name="krbarg" '.
1.165 raeburn 2943: 'value="'.$krbarg.'" '.
1.144 matthew 2944: 'onchange="'.$jscall.'" />',
1.281 albertel 2945: '<label><input type="radio" name="krbver" value="4" '.$check4.' />',
2946: '</label><label><input type="radio" name="krbver" value="5" '.$check5.' />',
2947: '</label>');
1.586 raeburn 2948: } elsif ($can_assign{'krb4'}) {
2949: $result .= &mt
2950: ('[_1] Kerberos authenticated with domain [_2] '.
2951: '[_3] Version 4 [_4]',
2952: '<label>'.$authtype,
2953: '</label><input type="text" size="10" name="krbarg" '.
2954: 'value="'.$krbarg.'" '.
2955: 'onchange="'.$jscall.'" />',
2956: '<label><input type="hidden" name="krbver" value="4" />',
2957: '</label>');
2958: } elsif ($can_assign{'krb5'}) {
2959: $result .= &mt
2960: ('[_1] Kerberos authenticated with domain [_2] '.
2961: '[_3] Version 5 [_4]',
2962: '<label>'.$authtype,
2963: '</label><input type="text" size="10" name="krbarg" '.
2964: 'value="'.$krbarg.'" '.
2965: 'onchange="'.$jscall.'" />',
2966: '<label><input type="hidden" name="krbver" value="5" />',
2967: '</label>');
2968: }
1.32 matthew 2969: return $result;
2970: }
2971:
1.1106 raeburn 2972: sub authform_internal {
1.586 raeburn 2973: my %in = (
1.32 matthew 2974: formname => 'document.cu',
2975: kerb_def_dom => 'MSU.EDU',
2976: @_,
2977: );
1.586 raeburn 2978: my ($intcheck,$intarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 2979: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 2980: if (defined($in{'curr_authtype'})) {
2981: if ($in{'curr_authtype'} eq 'int') {
1.586 raeburn 2982: if ($can_assign{'int'}) {
1.772 bisitz 2983: $intcheck = 'checked="checked" ';
1.623 raeburn 2984: if (defined($in{'mode'})) {
2985: if ($in{'mode'} eq 'modifyuser') {
2986: $intcheck = '';
2987: }
2988: }
1.591 raeburn 2989: if (defined($in{'curr_autharg'})) {
1.586 raeburn 2990: $intarg = $in{'curr_autharg'};
2991: }
2992: } else {
2993: $result = &mt('Currently internally authenticated.');
2994: return $result;
1.165 raeburn 2995: }
2996: }
1.586 raeburn 2997: } else {
2998: if ($authnum == 1) {
1.784 bisitz 2999: $authtype = '<input type="hidden" name="login" value="int" />';
1.586 raeburn 3000: }
3001: }
3002: if (!$can_assign{'int'}) {
3003: return;
1.587 raeburn 3004: } elsif ($authtype eq '') {
1.591 raeburn 3005: if (defined($in{'mode'})) {
1.587 raeburn 3006: if ($in{'mode'} eq 'modifycourse') {
3007: if ($authnum == 1) {
1.1104 raeburn 3008: $authtype = '<input type="radio" name="login" value="int" />';
1.587 raeburn 3009: }
3010: }
3011: }
1.165 raeburn 3012: }
1.586 raeburn 3013: $jscall = "javascript:changed_radio('int',$in{'formname'});";
3014: if ($authtype eq '') {
3015: $authtype = '<input type="radio" name="login" value="int" '.$intcheck.
3016: ' onchange="'.$jscall.'" onclick="'.$jscall.'" />';
3017: }
1.605 bisitz 3018: $autharg = '<input type="password" size="10" name="intarg" value="'.
1.586 raeburn 3019: $intarg.'" onchange="'.$jscall.'" />';
3020: $result = &mt
1.144 matthew 3021: ('[_1] Internally authenticated (with initial password [_2])',
1.586 raeburn 3022: '<label>'.$authtype,'</label>'.$autharg);
1.824 bisitz 3023: $result.="<label><input type=\"checkbox\" name=\"visible\" onclick='if (this.checked) { this.form.intarg.type=\"text\" } else { this.form.intarg.type=\"password\" }' />".&mt('Visible input').'</label>';
1.32 matthew 3024: return $result;
3025: }
3026:
1.1104 raeburn 3027: sub authform_local {
1.32 matthew 3028: my %in = (
3029: formname => 'document.cu',
3030: kerb_def_dom => 'MSU.EDU',
3031: @_,
3032: );
1.586 raeburn 3033: my ($loccheck,$locarg,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 3034: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 3035: if (defined($in{'curr_authtype'})) {
3036: if ($in{'curr_authtype'} eq 'loc') {
1.586 raeburn 3037: if ($can_assign{'loc'}) {
1.772 bisitz 3038: $loccheck = 'checked="checked" ';
1.623 raeburn 3039: if (defined($in{'mode'})) {
3040: if ($in{'mode'} eq 'modifyuser') {
3041: $loccheck = '';
3042: }
3043: }
1.591 raeburn 3044: if (defined($in{'curr_autharg'})) {
1.586 raeburn 3045: $locarg = $in{'curr_autharg'};
3046: }
3047: } else {
3048: $result = &mt('Currently using local (institutional) authentication.');
3049: return $result;
1.165 raeburn 3050: }
3051: }
1.586 raeburn 3052: } else {
3053: if ($authnum == 1) {
1.784 bisitz 3054: $authtype = '<input type="hidden" name="login" value="loc" />';
1.586 raeburn 3055: }
3056: }
3057: if (!$can_assign{'loc'}) {
3058: return;
1.587 raeburn 3059: } elsif ($authtype eq '') {
1.591 raeburn 3060: if (defined($in{'mode'})) {
1.587 raeburn 3061: if ($in{'mode'} eq 'modifycourse') {
3062: if ($authnum == 1) {
1.1104 raeburn 3063: $authtype = '<input type="radio" name="login" value="loc" />';
1.587 raeburn 3064: }
3065: }
3066: }
1.165 raeburn 3067: }
1.586 raeburn 3068: $jscall = "javascript:changed_radio('loc',$in{'formname'});";
3069: if ($authtype eq '') {
3070: $authtype = '<input type="radio" name="login" value="loc" '.
3071: $loccheck.' onchange="'.$jscall.'" onclick="'.
3072: $jscall.'" />';
3073: }
3074: $autharg = '<input type="text" size="10" name="locarg" value="'.
3075: $locarg.'" onchange="'.$jscall.'" />';
3076: $result = &mt('[_1] Local Authentication with argument [_2]',
3077: '<label>'.$authtype,'</label>'.$autharg);
1.32 matthew 3078: return $result;
3079: }
3080:
1.1106 raeburn 3081: sub authform_filesystem {
1.32 matthew 3082: my %in = (
3083: formname => 'document.cu',
3084: kerb_def_dom => 'MSU.EDU',
3085: @_,
3086: );
1.586 raeburn 3087: my ($fsyscheck,$result,$authtype,$autharg,$jscall);
1.1106 raeburn 3088: my ($authnum,%can_assign) = &get_assignable_auth($in{'domain'});
1.591 raeburn 3089: if (defined($in{'curr_authtype'})) {
3090: if ($in{'curr_authtype'} eq 'fsys') {
1.586 raeburn 3091: if ($can_assign{'fsys'}) {
1.772 bisitz 3092: $fsyscheck = 'checked="checked" ';
1.623 raeburn 3093: if (defined($in{'mode'})) {
3094: if ($in{'mode'} eq 'modifyuser') {
3095: $fsyscheck = '';
3096: }
3097: }
1.586 raeburn 3098: } else {
3099: $result = &mt('Currently Filesystem Authenticated.');
3100: return $result;
3101: }
3102: }
3103: } else {
3104: if ($authnum == 1) {
1.784 bisitz 3105: $authtype = '<input type="hidden" name="login" value="fsys" />';
1.586 raeburn 3106: }
3107: }
3108: if (!$can_assign{'fsys'}) {
3109: return;
1.587 raeburn 3110: } elsif ($authtype eq '') {
1.591 raeburn 3111: if (defined($in{'mode'})) {
1.587 raeburn 3112: if ($in{'mode'} eq 'modifycourse') {
3113: if ($authnum == 1) {
1.1104 raeburn 3114: $authtype = '<input type="radio" name="login" value="fsys" />';
1.587 raeburn 3115: }
3116: }
3117: }
1.586 raeburn 3118: }
3119: $jscall = "javascript:changed_radio('fsys',$in{'formname'});";
3120: if ($authtype eq '') {
3121: $authtype = '<input type="radio" name="login" value="fsys" '.
3122: $fsyscheck.' onchange="'.$jscall.'" onclick="'.
3123: $jscall.'" />';
3124: }
3125: $autharg = '<input type="text" size="10" name="fsysarg" value=""'.
3126: ' onchange="'.$jscall.'" />';
3127: $result = &mt
1.144 matthew 3128: ('[_1] Filesystem Authenticated (with initial password [_2])',
1.281 albertel 3129: '<label><input type="radio" name="login" value="fsys" '.
1.586 raeburn 3130: $fsyscheck.'onchange="'.$jscall.'" onclick="'.$jscall.'" />',
1.605 bisitz 3131: '</label><input type="password" size="10" name="fsysarg" value="" '.
1.144 matthew 3132: 'onchange="'.$jscall.'" />');
1.32 matthew 3133: return $result;
3134: }
3135:
1.586 raeburn 3136: sub get_assignable_auth {
3137: my ($dom) = @_;
3138: if ($dom eq '') {
3139: $dom = $env{'request.role.domain'};
3140: }
3141: my %can_assign = (
3142: krb4 => 1,
3143: krb5 => 1,
3144: int => 1,
3145: loc => 1,
3146: );
3147: my %domconfig = &Apache::lonnet::get_dom('configuration',['usercreation'],$dom);
3148: if (ref($domconfig{'usercreation'}) eq 'HASH') {
3149: if (ref($domconfig{'usercreation'}{'authtypes'}) eq 'HASH') {
3150: my $authhash = $domconfig{'usercreation'}{'authtypes'};
3151: my $context;
3152: if ($env{'request.role'} =~ /^au/) {
3153: $context = 'author';
3154: } elsif ($env{'request.role'} =~ /^dc/) {
3155: $context = 'domain';
3156: } elsif ($env{'request.course.id'}) {
3157: $context = 'course';
3158: }
3159: if ($context) {
3160: if (ref($authhash->{$context}) eq 'HASH') {
3161: %can_assign = %{$authhash->{$context}};
3162: }
3163: }
3164: }
3165: }
3166: my $authnum = 0;
3167: foreach my $key (keys(%can_assign)) {
3168: if ($can_assign{$key}) {
3169: $authnum ++;
3170: }
3171: }
3172: if ($can_assign{'krb4'} && $can_assign{'krb5'}) {
3173: $authnum --;
3174: }
3175: return ($authnum,%can_assign);
3176: }
3177:
1.80 albertel 3178: ###############################################################
3179: ## Get Kerberos Defaults for Domain ##
3180: ###############################################################
3181: ##
3182: ## Returns default kerberos version and an associated argument
3183: ## as listed in file domain.tab. If not listed, provides
3184: ## appropriate default domain and kerberos version.
3185: ##
3186: #-------------------------------------------
3187:
3188: =pod
3189:
1.648 raeburn 3190: =item * &get_kerberos_defaults()
1.80 albertel 3191:
3192: get_kerberos_defaults($target_domain) returns the default kerberos
1.641 raeburn 3193: version and domain. If not found, it defaults to version 4 and the
3194: domain of the server.
1.80 albertel 3195:
1.648 raeburn 3196: =over 4
3197:
1.80 albertel 3198: ($def_version, $def_krb_domain) = &get_kerberos_defaults($target_domain);
3199:
1.648 raeburn 3200: =back
3201:
3202: =back
3203:
1.80 albertel 3204: =cut
3205:
3206: #-------------------------------------------
3207: sub get_kerberos_defaults {
3208: my $domain=shift;
1.641 raeburn 3209: my ($krbdef,$krbdefdom);
3210: my %domdefaults = &Apache::lonnet::get_domain_defaults($domain);
3211: if (($domdefaults{'auth_def'} =~/^krb(4|5)$/) && ($domdefaults{'auth_arg_def'} ne '')) {
3212: $krbdef = $domdefaults{'auth_def'};
3213: $krbdefdom = $domdefaults{'auth_arg_def'};
3214: } else {
1.80 albertel 3215: $ENV{'SERVER_NAME'}=~/(\w+\.\w+)$/;
3216: my $krbdefdom=$1;
3217: $krbdefdom=~tr/a-z/A-Z/;
3218: $krbdef = "krb4";
3219: }
3220: return ($krbdef,$krbdefdom);
3221: }
1.112 bowersj2 3222:
1.32 matthew 3223:
1.46 matthew 3224: ###############################################################
3225: ## Thesaurus Functions ##
3226: ###############################################################
1.20 www 3227:
1.46 matthew 3228: =pod
1.20 www 3229:
1.112 bowersj2 3230: =head1 Thesaurus Functions
3231:
3232: =over 4
3233:
1.648 raeburn 3234: =item * &initialize_keywords()
1.46 matthew 3235:
3236: Initializes the package variable %Keywords if it is empty. Uses the
3237: package variable $thesaurus_db_file.
3238:
3239: =cut
3240:
3241: ###################################################
3242:
3243: sub initialize_keywords {
3244: return 1 if (scalar keys(%Keywords));
3245: # If we are here, %Keywords is empty, so fill it up
3246: # Make sure the file we need exists...
3247: if (! -e $thesaurus_db_file) {
3248: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file".
3249: " failed because it does not exist");
3250: return 0;
3251: }
3252: # Set up the hash as a database
3253: my %thesaurus_db;
3254: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3255: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3256: &Apache::lonnet::logthis("Could not tie \%thesaurus_db to ".
3257: $thesaurus_db_file);
3258: return 0;
3259: }
3260: # Get the average number of appearances of a word.
3261: my $avecount = $thesaurus_db{'average.count'};
3262: # Put keywords (those that appear > average) into %Keywords
3263: while (my ($word,$data)=each (%thesaurus_db)) {
3264: my ($count,undef) = split /:/,$data;
3265: $Keywords{$word}++ if ($count > $avecount);
3266: }
3267: untie %thesaurus_db;
3268: # Remove special values from %Keywords.
1.356 albertel 3269: foreach my $value ('total.count','average.count') {
3270: delete($Keywords{$value}) if (exists($Keywords{$value}));
1.586 raeburn 3271: }
1.46 matthew 3272: return 1;
3273: }
3274:
3275: ###################################################
3276:
3277: =pod
3278:
1.648 raeburn 3279: =item * &keyword($word)
1.46 matthew 3280:
3281: Returns true if $word is a keyword. A keyword is a word that appears more
3282: than the average number of times in the thesaurus database. Calls
3283: &initialize_keywords
3284:
3285: =cut
3286:
3287: ###################################################
1.20 www 3288:
3289: sub keyword {
1.46 matthew 3290: return if (!&initialize_keywords());
3291: my $word=lc(shift());
3292: $word=~s/\W//g;
3293: return exists($Keywords{$word});
1.20 www 3294: }
1.46 matthew 3295:
3296: ###############################################################
3297:
3298: =pod
1.20 www 3299:
1.648 raeburn 3300: =item * &get_related_words()
1.46 matthew 3301:
1.160 matthew 3302: Look up a word in the thesaurus. Takes a scalar argument and returns
1.46 matthew 3303: an array of words. If the keyword is not in the thesaurus, an empty array
3304: will be returned. The order of the words returned is determined by the
3305: database which holds them.
3306:
3307: Uses global $thesaurus_db_file.
3308:
1.1057 foxr 3309:
1.46 matthew 3310: =cut
3311:
3312: ###############################################################
3313: sub get_related_words {
3314: my $keyword = shift;
3315: my %thesaurus_db;
3316: if (! -e $thesaurus_db_file) {
3317: &Apache::lonnet::logthis("Attempt to access $thesaurus_db_file ".
3318: "failed because the file does not exist");
3319: return ();
3320: }
3321: if (! tie(%thesaurus_db,'GDBM_File',
1.53 albertel 3322: $thesaurus_db_file,&GDBM_READER(),0640)){
1.46 matthew 3323: return ();
3324: }
3325: my @Words=();
1.429 www 3326: my $count=0;
1.46 matthew 3327: if (exists($thesaurus_db{$keyword})) {
1.356 albertel 3328: # The first element is the number of times
3329: # the word appears. We do not need it now.
1.429 www 3330: my (undef,@RelatedWords) = (split(/:/,$thesaurus_db{$keyword}));
3331: my (undef,$mostfrequentcount)=split(/\,/,$RelatedWords[0]);
3332: my $threshold=$mostfrequentcount/10;
3333: foreach my $possibleword (@RelatedWords) {
3334: my ($word,$wordcount)=split(/\,/,$possibleword);
3335: if ($wordcount>$threshold) {
3336: push(@Words,$word);
3337: $count++;
3338: if ($count>10) { last; }
3339: }
1.20 www 3340: }
3341: }
1.46 matthew 3342: untie %thesaurus_db;
3343: return @Words;
1.14 harris41 3344: }
1.1090 foxr 3345: ###############################################################
3346: #
3347: # Spell checking
3348: #
3349:
3350: =pod
3351:
1.1142 raeburn 3352: =back
3353:
1.1090 foxr 3354: =head1 Spell checking
3355:
3356: =over 4
3357:
3358: =item * &check_spelling($wordlist $language)
3359:
3360: Takes a string containing words and feeds it to an external
3361: spellcheck program via a pipeline. Returns a string containing
3362: them mis-spelled words.
3363:
3364: Parameters:
3365:
3366: =over 4
3367:
3368: =item - $wordlist
3369:
3370: String that will be fed into the spellcheck program.
3371:
3372: =item - $language
3373:
3374: Language string that specifies the language for which the spell
3375: check will be performed.
3376:
3377: =back
3378:
3379: =back
3380:
3381: Note: This sub assumes that aspell is installed.
3382:
3383:
3384: =cut
3385:
1.46 matthew 3386:
1.1090 foxr 3387: sub check_spelling {
3388: my ($wordlist, $language) = @_;
1.1091 foxr 3389: my @misspellings;
3390:
3391: # Generate the speller and set the langauge.
3392: # if explicitly selected:
1.1090 foxr 3393:
1.1091 foxr 3394: my $speller = Text::Aspell->new;
1.1090 foxr 3395: if ($language) {
1.1091 foxr 3396: $speller->set_option('lang', $language);
1.1090 foxr 3397: }
3398:
1.1091 foxr 3399: # Turn the word list into an array of words by splittingon whitespace
1.1090 foxr 3400:
1.1091 foxr 3401: my @words = split(/\s+/, $wordlist);
1.1090 foxr 3402:
1.1091 foxr 3403: foreach my $word (@words) {
3404: if(! $speller->check($word)) {
3405: push(@misspellings, $word);
1.1090 foxr 3406: }
3407: }
1.1091 foxr 3408: return join(' ', @misspellings);
3409:
1.1090 foxr 3410: }
3411:
1.61 www 3412: # -------------------------------------------------------------- Plaintext name
1.81 albertel 3413: =pod
3414:
1.112 bowersj2 3415: =head1 User Name Functions
3416:
3417: =over 4
3418:
1.648 raeburn 3419: =item * &plainname($uname,$udom,$first)
1.81 albertel 3420:
1.112 bowersj2 3421: Takes a users logon name and returns it as a string in
1.226 albertel 3422: "first middle last generation" form
3423: if $first is set to 'lastname' then it returns it as
3424: 'lastname generation, firstname middlename' if their is a lastname
1.81 albertel 3425:
3426: =cut
1.61 www 3427:
1.295 www 3428:
1.81 albertel 3429: ###############################################################
1.61 www 3430: sub plainname {
1.226 albertel 3431: my ($uname,$udom,$first)=@_;
1.537 albertel 3432: return if (!defined($uname) || !defined($udom));
1.295 www 3433: my %names=&getnames($uname,$udom);
1.226 albertel 3434: my $name=&Apache::lonnet::format_name($names{'firstname'},
3435: $names{'middlename'},
3436: $names{'lastname'},
3437: $names{'generation'},$first);
3438: $name=~s/^\s+//;
1.62 www 3439: $name=~s/\s+$//;
3440: $name=~s/\s+/ /g;
1.353 albertel 3441: if ($name !~ /\S/) { $name=$uname.':'.$udom; }
1.62 www 3442: return $name;
1.61 www 3443: }
1.66 www 3444:
3445: # -------------------------------------------------------------------- Nickname
1.81 albertel 3446: =pod
3447:
1.648 raeburn 3448: =item * &nickname($uname,$udom)
1.81 albertel 3449:
3450: Gets a users name and returns it as a string as
3451:
3452: ""nickname""
1.66 www 3453:
1.81 albertel 3454: if the user has a nickname or
3455:
3456: "first middle last generation"
3457:
3458: if the user does not
3459:
3460: =cut
1.66 www 3461:
3462: sub nickname {
3463: my ($uname,$udom)=@_;
1.537 albertel 3464: return if (!defined($uname) || !defined($udom));
1.295 www 3465: my %names=&getnames($uname,$udom);
1.68 albertel 3466: my $name=$names{'nickname'};
1.66 www 3467: if ($name) {
3468: $name='"'.$name.'"';
3469: } else {
3470: $name=$names{'firstname'}.' '.$names{'middlename'}.' '.
3471: $names{'lastname'}.' '.$names{'generation'};
3472: $name=~s/\s+$//;
3473: $name=~s/\s+/ /g;
3474: }
3475: return $name;
3476: }
3477:
1.295 www 3478: sub getnames {
3479: my ($uname,$udom)=@_;
1.537 albertel 3480: return if (!defined($uname) || !defined($udom));
1.433 albertel 3481: if ($udom eq 'public' && $uname eq 'public') {
3482: return ('lastname' => &mt('Public'));
3483: }
1.295 www 3484: my $id=$uname.':'.$udom;
3485: my ($names,$cached)=&Apache::lonnet::is_cached_new('namescache',$id);
3486: if ($cached) {
3487: return %{$names};
3488: } else {
3489: my %loadnames=&Apache::lonnet::get('environment',
3490: ['firstname','middlename','lastname','generation','nickname'],
3491: $udom,$uname);
3492: &Apache::lonnet::do_cache_new('namescache',$id,\%loadnames);
3493: return %loadnames;
3494: }
3495: }
1.61 www 3496:
1.542 raeburn 3497: # -------------------------------------------------------------------- getemails
1.648 raeburn 3498:
1.542 raeburn 3499: =pod
3500:
1.648 raeburn 3501: =item * &getemails($uname,$udom)
1.542 raeburn 3502:
3503: Gets a user's email information and returns it as a hash with keys:
3504: notification, critnotification, permanentemail
3505:
3506: For notification and critnotification, values are comma-separated lists
1.648 raeburn 3507: of e-mail addresses; for permanentemail, value is a single e-mail address.
1.542 raeburn 3508:
1.648 raeburn 3509:
1.542 raeburn 3510: =cut
3511:
1.648 raeburn 3512:
1.466 albertel 3513: sub getemails {
3514: my ($uname,$udom)=@_;
3515: if ($udom eq 'public' && $uname eq 'public') {
3516: return;
3517: }
1.467 www 3518: if (!$udom) { $udom=$env{'user.domain'}; }
3519: if (!$uname) { $uname=$env{'user.name'}; }
1.466 albertel 3520: my $id=$uname.':'.$udom;
3521: my ($names,$cached)=&Apache::lonnet::is_cached_new('emailscache',$id);
3522: if ($cached) {
3523: return %{$names};
3524: } else {
3525: my %loadnames=&Apache::lonnet::get('environment',
3526: ['notification','critnotification',
3527: 'permanentemail'],
3528: $udom,$uname);
3529: &Apache::lonnet::do_cache_new('emailscache',$id,\%loadnames);
3530: return %loadnames;
3531: }
3532: }
3533:
1.551 albertel 3534: sub flush_email_cache {
3535: my ($uname,$udom)=@_;
3536: if (!$udom) { $udom =$env{'user.domain'}; }
3537: if (!$uname) { $uname=$env{'user.name'}; }
3538: return if ($udom eq 'public' && $uname eq 'public');
3539: my $id=$uname.':'.$udom;
3540: &Apache::lonnet::devalidate_cache_new('emailscache',$id);
3541: }
3542:
1.728 raeburn 3543: # -------------------------------------------------------------------- getlangs
3544:
3545: =pod
3546:
3547: =item * &getlangs($uname,$udom)
3548:
3549: Gets a user's language preference and returns it as a hash with key:
3550: language.
3551:
3552: =cut
3553:
3554:
3555: sub getlangs {
3556: my ($uname,$udom) = @_;
3557: if (!$udom) { $udom =$env{'user.domain'}; }
3558: if (!$uname) { $uname=$env{'user.name'}; }
3559: my $id=$uname.':'.$udom;
3560: my ($langs,$cached)=&Apache::lonnet::is_cached_new('userlangs',$id);
3561: if ($cached) {
3562: return %{$langs};
3563: } else {
3564: my %loadlangs=&Apache::lonnet::get('environment',['languages'],
3565: $udom,$uname);
3566: &Apache::lonnet::do_cache_new('userlangs',$id,\%loadlangs);
3567: return %loadlangs;
3568: }
3569: }
3570:
3571: sub flush_langs_cache {
3572: my ($uname,$udom)=@_;
3573: if (!$udom) { $udom =$env{'user.domain'}; }
3574: if (!$uname) { $uname=$env{'user.name'}; }
3575: return if ($udom eq 'public' && $uname eq 'public');
3576: my $id=$uname.':'.$udom;
3577: &Apache::lonnet::devalidate_cache_new('userlangs',$id);
3578: }
3579:
1.61 www 3580: # ------------------------------------------------------------------ Screenname
1.81 albertel 3581:
3582: =pod
3583:
1.648 raeburn 3584: =item * &screenname($uname,$udom)
1.81 albertel 3585:
3586: Gets a users screenname and returns it as a string
3587:
3588: =cut
1.61 www 3589:
3590: sub screenname {
3591: my ($uname,$udom)=@_;
1.258 albertel 3592: if ($uname eq $env{'user.name'} &&
3593: $udom eq $env{'user.domain'}) {return $env{'environment.screenname'};}
1.212 albertel 3594: my %names=&Apache::lonnet::get('environment',['screenname'],$udom,$uname);
1.68 albertel 3595: return $names{'screenname'};
1.62 www 3596: }
3597:
1.212 albertel 3598:
1.802 bisitz 3599: # ------------------------------------------------------------- Confirm Wrapper
3600: =pod
3601:
1.1142 raeburn 3602: =item * &confirmwrapper($message)
1.802 bisitz 3603:
3604: Wrap messages about completion of operation in box
3605:
3606: =cut
3607:
3608: sub confirmwrapper {
3609: my ($message)=@_;
3610: if ($message) {
3611: return "\n".'<div class="LC_confirm_box">'."\n"
3612: .$message."\n"
3613: .'</div>'."\n";
3614: } else {
3615: return $message;
3616: }
3617: }
3618:
1.62 www 3619: # ------------------------------------------------------------- Message Wrapper
3620:
3621: sub messagewrapper {
1.369 www 3622: my ($link,$username,$domain,$subject,$text)=@_;
1.62 www 3623: return
1.441 albertel 3624: '<a href="/adm/email?compose=individual&'.
3625: 'recname='.$username.'&recdom='.$domain.
3626: '&subject='.&escape($subject).'&text='.&escape($text).'" '.
1.200 matthew 3627: 'title="'.&mt('Send message').'">'.$link.'</a>';
1.74 www 3628: }
1.802 bisitz 3629:
1.74 www 3630: # --------------------------------------------------------------- Notes Wrapper
3631:
3632: sub noteswrapper {
3633: my ($link,$un,$do)=@_;
3634: return
1.896 amueller 3635: "<a href='/adm/email?recordftf=retrieve&recname=$un&recdom=$do'>$link</a>";
1.62 www 3636: }
1.802 bisitz 3637:
1.62 www 3638: # ------------------------------------------------------------- Aboutme Wrapper
3639:
3640: sub aboutmewrapper {
1.1070 raeburn 3641: my ($link,$username,$domain,$target,$class)=@_;
1.447 raeburn 3642: if (!defined($username) && !defined($domain)) {
3643: return;
3644: }
1.1096 raeburn 3645: return '<a href="/adm/'.$domain.'/'.$username.'/aboutme"'.
1.1070 raeburn 3646: ($target?' target="'.$target.'"':'').($class?' class="'.$class.'"':'').' title="'.&mt("View this user's personal information page").'">'.$link.'</a>';
1.62 www 3647: }
3648:
3649: # ------------------------------------------------------------ Syllabus Wrapper
3650:
3651: sub syllabuswrapper {
1.707 bisitz 3652: my ($linktext,$coursedir,$domain)=@_;
1.208 matthew 3653: return qq{<a href="/public/$domain/$coursedir/syllabus">$linktext</a>};
1.61 www 3654: }
1.14 harris41 3655:
1.802 bisitz 3656: # -----------------------------------------------------------------------------
3657:
1.208 matthew 3658: sub track_student_link {
1.887 raeburn 3659: my ($linktext,$sname,$sdom,$target,$start,$only_body) = @_;
1.268 albertel 3660: my $link ="/adm/trackstudent?";
1.208 matthew 3661: my $title = 'View recent activity';
3662: if (defined($sname) && $sname !~ /^\s*$/ &&
3663: defined($sdom) && $sdom !~ /^\s*$/) {
1.268 albertel 3664: $link .= "selected_student=$sname:$sdom";
1.208 matthew 3665: $title .= ' of this student';
1.268 albertel 3666: }
1.208 matthew 3667: if (defined($target) && $target !~ /^\s*$/) {
3668: $target = qq{target="$target"};
3669: } else {
3670: $target = '';
3671: }
1.268 albertel 3672: if ($start) { $link.='&start='.$start; }
1.887 raeburn 3673: if ($only_body) { $link .= '&only_body=1'; }
1.554 albertel 3674: $title = &mt($title);
3675: $linktext = &mt($linktext);
1.448 albertel 3676: return qq{<a href="$link" title="$title" $target>$linktext</a>}.
3677: &help_open_topic('View_recent_activity');
1.208 matthew 3678: }
3679:
1.781 raeburn 3680: sub slot_reservations_link {
3681: my ($linktext,$sname,$sdom,$target) = @_;
3682: my $link ="/adm/slotrequest?command=showresv&origin=aboutme";
3683: my $title = 'View slot reservation history';
3684: if (defined($sname) && $sname !~ /^\s*$/ &&
3685: defined($sdom) && $sdom !~ /^\s*$/) {
3686: $link .= "&uname=$sname&udom=$sdom";
3687: $title .= ' of this student';
3688: }
3689: if (defined($target) && $target !~ /^\s*$/) {
3690: $target = qq{target="$target"};
3691: } else {
3692: $target = '';
3693: }
3694: $title = &mt($title);
3695: $linktext = &mt($linktext);
3696: return qq{<a href="$link" title="$title" $target>$linktext</a>};
3697: # FIXME uncomment when help item created: &help_open_topic('Slot_Reservation_History');
3698:
3699: }
3700:
1.508 www 3701: # ===================================================== Display a student photo
3702:
3703:
1.509 albertel 3704: sub student_image_tag {
1.508 www 3705: my ($domain,$user)=@_;
3706: my $imgsrc=&Apache::lonnet::studentphoto($domain,$user,'jpg');
3707: if (($imgsrc) && ($imgsrc ne '/adm/lonKaputt/lonlogo_broken.gif')) {
3708: return '<img src="'.$imgsrc.'" align="right" />';
3709: } else {
3710: return '';
3711: }
3712: }
3713:
1.112 bowersj2 3714: =pod
3715:
3716: =back
3717:
3718: =head1 Access .tab File Data
3719:
3720: =over 4
3721:
1.648 raeburn 3722: =item * &languageids()
1.112 bowersj2 3723:
3724: returns list of all language ids
3725:
3726: =cut
3727:
1.14 harris41 3728: sub languageids {
1.16 harris41 3729: return sort(keys(%language));
1.14 harris41 3730: }
3731:
1.112 bowersj2 3732: =pod
3733:
1.648 raeburn 3734: =item * &languagedescription()
1.112 bowersj2 3735:
3736: returns description of a specified language id
3737:
3738: =cut
3739:
1.14 harris41 3740: sub languagedescription {
1.125 www 3741: my $code=shift;
3742: return ($supported_language{$code}?'* ':'').
3743: $language{$code}.
1.126 www 3744: ($supported_language{$code}?' ('.&mt('interface available').')':'');
1.145 www 3745: }
3746:
1.1048 foxr 3747: =pod
3748:
3749: =item * &plainlanguagedescription
3750:
3751: Returns both the plain language description (e.g. 'Creoles and Pidgins, English-based (Other)')
3752: and the language character encoding (e.g. ISO) separated by a ' - ' string.
3753:
3754: =cut
3755:
1.145 www 3756: sub plainlanguagedescription {
3757: my $code=shift;
3758: return $language{$code};
3759: }
3760:
1.1048 foxr 3761: =pod
3762:
3763: =item * &supportedlanguagecode
3764:
3765: Returns the supported language code (e.g. sptutf maps to pt) given a language
3766: code.
3767:
3768: =cut
3769:
1.145 www 3770: sub supportedlanguagecode {
3771: my $code=shift;
3772: return $supported_language{$code};
1.97 www 3773: }
3774:
1.112 bowersj2 3775: =pod
3776:
1.1048 foxr 3777: =item * &latexlanguage()
3778:
3779: Given a language key code returns the correspondnig language to use
3780: to select the correct hyphenation on LaTeX printouts. This is undef if there
3781: is no supported hyphenation for the language code.
3782:
3783: =cut
3784:
3785: sub latexlanguage {
3786: my $code = shift;
3787: return $latex_language{$code};
3788: }
3789:
3790: =pod
3791:
3792: =item * &latexhyphenation()
3793:
3794: Same as above but what's supplied is the language as it might be stored
3795: in the metadata.
3796:
3797: =cut
3798:
3799: sub latexhyphenation {
3800: my $key = shift;
3801: return $latex_language_bykey{$key};
3802: }
3803:
3804: =pod
3805:
1.648 raeburn 3806: =item * ©rightids()
1.112 bowersj2 3807:
3808: returns list of all copyrights
3809:
3810: =cut
3811:
3812: sub copyrightids {
3813: return sort(keys(%cprtag));
3814: }
3815:
3816: =pod
3817:
1.648 raeburn 3818: =item * ©rightdescription()
1.112 bowersj2 3819:
3820: returns description of a specified copyright id
3821:
3822: =cut
3823:
3824: sub copyrightdescription {
1.166 www 3825: return &mt($cprtag{shift(@_)});
1.112 bowersj2 3826: }
1.197 matthew 3827:
3828: =pod
3829:
1.648 raeburn 3830: =item * &source_copyrightids()
1.192 taceyjo1 3831:
3832: returns list of all source copyrights
3833:
3834: =cut
3835:
3836: sub source_copyrightids {
3837: return sort(keys(%scprtag));
3838: }
3839:
3840: =pod
3841:
1.648 raeburn 3842: =item * &source_copyrightdescription()
1.192 taceyjo1 3843:
3844: returns description of a specified source copyright id
3845:
3846: =cut
3847:
3848: sub source_copyrightdescription {
3849: return &mt($scprtag{shift(@_)});
3850: }
1.112 bowersj2 3851:
3852: =pod
3853:
1.648 raeburn 3854: =item * &filecategories()
1.112 bowersj2 3855:
3856: returns list of all file categories
3857:
3858: =cut
3859:
3860: sub filecategories {
3861: return sort(keys(%category_extensions));
3862: }
3863:
3864: =pod
3865:
1.648 raeburn 3866: =item * &filecategorytypes()
1.112 bowersj2 3867:
3868: returns list of file types belonging to a given file
3869: category
3870:
3871: =cut
3872:
3873: sub filecategorytypes {
1.356 albertel 3874: my ($cat) = @_;
3875: return @{$category_extensions{lc($cat)}};
1.112 bowersj2 3876: }
3877:
3878: =pod
3879:
1.648 raeburn 3880: =item * &fileembstyle()
1.112 bowersj2 3881:
3882: returns embedding style for a specified file type
3883:
3884: =cut
3885:
3886: sub fileembstyle {
3887: return $fe{lc(shift(@_))};
1.169 www 3888: }
3889:
1.351 www 3890: sub filemimetype {
3891: return $fm{lc(shift(@_))};
3892: }
3893:
1.169 www 3894:
3895: sub filecategoryselect {
3896: my ($name,$value)=@_;
1.189 matthew 3897: return &select_form($value,$name,
1.970 raeburn 3898: {'' => &mt('Any category'), map { $_,$_ } sort(keys(%category_extensions))});
1.112 bowersj2 3899: }
3900:
3901: =pod
3902:
1.648 raeburn 3903: =item * &filedescription()
1.112 bowersj2 3904:
3905: returns description for a specified file type
3906:
3907: =cut
3908:
3909: sub filedescription {
1.188 matthew 3910: my $file_description = $fd{lc(shift())};
3911: $file_description =~ s:([\[\]]):~$1:g;
3912: return &mt($file_description);
1.112 bowersj2 3913: }
3914:
3915: =pod
3916:
1.648 raeburn 3917: =item * &filedescriptionex()
1.112 bowersj2 3918:
3919: returns description for a specified file type with
3920: extra formatting
3921:
3922: =cut
3923:
3924: sub filedescriptionex {
3925: my $ex=shift;
1.188 matthew 3926: my $file_description = $fd{lc($ex)};
3927: $file_description =~ s:([\[\]]):~$1:g;
3928: return '.'.$ex.' '.&mt($file_description);
1.112 bowersj2 3929: }
3930:
3931: # End of .tab access
3932: =pod
3933:
3934: =back
3935:
3936: =cut
3937:
3938: # ------------------------------------------------------------------ File Types
3939: sub fileextensions {
3940: return sort(keys(%fe));
3941: }
3942:
1.97 www 3943: # ----------------------------------------------------------- Display Languages
3944: # returns a hash with all desired display languages
3945: #
3946:
3947: sub display_languages {
3948: my %languages=();
1.695 raeburn 3949: foreach my $lang (&Apache::lonlocal::preferred_languages()) {
1.356 albertel 3950: $languages{$lang}=1;
1.97 www 3951: }
3952: &get_unprocessed_cgi($ENV{'QUERY_STRING'},['displaylanguage']);
1.258 albertel 3953: if ($env{'form.displaylanguage'}) {
1.356 albertel 3954: foreach my $lang (split(/\s*(\,|\;|\:)\s*/,$env{'form.displaylanguage'})) {
3955: $languages{$lang}=1;
1.97 www 3956: }
3957: }
3958: return %languages;
1.14 harris41 3959: }
3960:
1.582 albertel 3961: sub languages {
3962: my ($possible_langs) = @_;
1.695 raeburn 3963: my @preferred_langs = &Apache::lonlocal::preferred_languages();
1.582 albertel 3964: if (!ref($possible_langs)) {
3965: if( wantarray ) {
3966: return @preferred_langs;
3967: } else {
3968: return $preferred_langs[0];
3969: }
3970: }
3971: my %possibilities = map { $_ => 1 } (@$possible_langs);
3972: my @preferred_possibilities;
3973: foreach my $preferred_lang (@preferred_langs) {
3974: if (exists($possibilities{$preferred_lang})) {
3975: push(@preferred_possibilities, $preferred_lang);
3976: }
3977: }
3978: if( wantarray ) {
3979: return @preferred_possibilities;
3980: }
3981: return $preferred_possibilities[0];
3982: }
3983:
1.742 raeburn 3984: sub user_lang {
3985: my ($touname,$toudom,$fromcid) = @_;
3986: my @userlangs;
3987: if (($fromcid ne '') && ($env{'course.'.$fromcid.'.languages'} ne '')) {
3988: @userlangs=(@userlangs,split(/\s*(\,|\;|\:)\s*/,
3989: $env{'course.'.$fromcid.'.languages'}));
3990: } else {
3991: my %langhash = &getlangs($touname,$toudom);
3992: if ($langhash{'languages'} ne '') {
3993: @userlangs = split(/\s*(\,|\;|\:)\s*/,$langhash{'languages'});
3994: } else {
3995: my %domdefs = &Apache::lonnet::get_domain_defaults($toudom);
3996: if ($domdefs{'lang_def'} ne '') {
3997: @userlangs = ($domdefs{'lang_def'});
3998: }
3999: }
4000: }
4001: my @languages=&Apache::lonlocal::get_genlanguages(@userlangs);
4002: my $user_lh = Apache::localize->get_handle(@languages);
4003: return $user_lh;
4004: }
4005:
4006:
1.112 bowersj2 4007: ###############################################################
4008: ## Student Answer Attempts ##
4009: ###############################################################
4010:
4011: =pod
4012:
4013: =head1 Alternate Problem Views
4014:
4015: =over 4
4016:
1.648 raeburn 4017: =item * &get_previous_attempt($symb, $username, $domain, $course,
1.1199 raeburn 4018: $getattempt, $regexp, $gradesub, $usec, $identifier)
1.112 bowersj2 4019:
4020: Return string with previous attempt on problem. Arguments:
4021:
4022: =over 4
4023:
4024: =item * $symb: Problem, including path
4025:
4026: =item * $username: username of the desired student
4027:
4028: =item * $domain: domain of the desired student
1.14 harris41 4029:
1.112 bowersj2 4030: =item * $course: Course ID
1.14 harris41 4031:
1.112 bowersj2 4032: =item * $getattempt: Leave blank for all attempts, otherwise put
4033: something
1.14 harris41 4034:
1.112 bowersj2 4035: =item * $regexp: if string matches this regexp, the string will be
4036: sent to $gradesub
1.14 harris41 4037:
1.112 bowersj2 4038: =item * $gradesub: routine that processes the string if it matches $regexp
1.14 harris41 4039:
1.1199 raeburn 4040: =item * $usec: section of the desired student
4041:
4042: =item * $identifier: counter for student (multiple students one problem) or
4043: problem (one student; whole sequence).
4044:
1.112 bowersj2 4045: =back
1.14 harris41 4046:
1.112 bowersj2 4047: The output string is a table containing all desired attempts, if any.
1.16 harris41 4048:
1.112 bowersj2 4049: =cut
1.1 albertel 4050:
4051: sub get_previous_attempt {
1.1199 raeburn 4052: my ($symb,$username,$domain,$course,$getattempt,$regexp,$gradesub,$usec,$identifier)=@_;
1.1 albertel 4053: my $prevattempts='';
1.43 ng 4054: no strict 'refs';
1.1 albertel 4055: if ($symb) {
1.3 albertel 4056: my (%returnhash)=
4057: &Apache::lonnet::restore($symb,$course,$domain,$username);
1.1 albertel 4058: if ($returnhash{'version'}) {
4059: my %lasthash=();
4060: my $version;
4061: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1212 raeburn 4062: foreach my $key (reverse(sort(split(/\:/,$returnhash{$version.':keys'})))) {
4063: if ($key =~ /\.rawrndseed$/) {
4064: my ($id) = ($key =~ /^(.+)\.rawrndseed$/);
4065: $lasthash{$id.'.rndseed'} = $returnhash{$version.':'.$key};
4066: } else {
4067: $lasthash{$key}=$returnhash{$version.':'.$key};
4068: }
1.19 harris41 4069: }
1.1 albertel 4070: }
1.596 albertel 4071: $prevattempts=&start_data_table().&start_data_table_header_row();
4072: $prevattempts.='<th>'.&mt('History').'</th>';
1.1199 raeburn 4073: my (%typeparts,%lasthidden,%regraded,%hidestatus);
1.945 raeburn 4074: my $showsurv=&Apache::lonnet::allowed('vas',$env{'request.course.id'});
1.356 albertel 4075: foreach my $key (sort(keys(%lasthash))) {
4076: my ($ign,@parts) = split(/\./,$key);
1.41 ng 4077: if ($#parts > 0) {
1.31 albertel 4078: my $data=$parts[-1];
1.989 raeburn 4079: next if ($data eq 'foilorder');
1.31 albertel 4080: pop(@parts);
1.1010 www 4081: $prevattempts.='<th>'.&mt('Part ').join('.',@parts).'<br />'.$data.' </th>';
1.945 raeburn 4082: if ($data eq 'type') {
4083: unless ($showsurv) {
4084: my $id = join(',',@parts);
4085: $typeparts{$ign.'.'.$id} = $lasthash{$key};
1.978 raeburn 4086: if (($lasthash{$key} eq 'anonsurvey') || ($lasthash{$key} eq 'anonsurveycred')) {
4087: $lasthidden{$ign.'.'.$id} = 1;
4088: }
1.945 raeburn 4089: }
1.1199 raeburn 4090: if ($identifier ne '') {
4091: my $id = join(',',@parts);
4092: if (&Apache::lonnet::EXT("resource.$id.problemstatus",$symb,
4093: $domain,$username,$usec,undef,$course) =~ /^no/) {
4094: $hidestatus{$ign.'.'.$id} = 1;
4095: }
4096: }
4097: } elsif ($data eq 'regrader') {
4098: if (($identifier ne '') && (@parts)) {
1.1200 raeburn 4099: my $id = join(',',@parts);
4100: $regraded{$ign.'.'.$id} = 1;
1.1199 raeburn 4101: }
1.1010 www 4102: }
1.31 albertel 4103: } else {
1.41 ng 4104: if ($#parts == 0) {
4105: $prevattempts.='<th>'.$parts[0].'</th>';
4106: } else {
4107: $prevattempts.='<th>'.$ign.'</th>';
4108: }
1.31 albertel 4109: }
1.16 harris41 4110: }
1.596 albertel 4111: $prevattempts.=&end_data_table_header_row();
1.40 ng 4112: if ($getattempt eq '') {
1.1199 raeburn 4113: my (%solved,%resets,%probstatus);
1.1200 raeburn 4114: if (($identifier ne '') && (keys(%regraded) > 0)) {
4115: for ($version=1;$version<=$returnhash{'version'};$version++) {
4116: foreach my $id (keys(%regraded)) {
4117: if (($returnhash{$version.':'.$id.'.regrader'}) &&
4118: ($returnhash{$version.':'.$id.'.tries'} eq '') &&
4119: ($returnhash{$version.':'.$id.'.award'} eq '')) {
4120: push(@{$resets{$id}},$version);
1.1199 raeburn 4121: }
4122: }
4123: }
1.1200 raeburn 4124: }
4125: for ($version=1;$version<=$returnhash{'version'};$version++) {
1.1199 raeburn 4126: my (@hidden,@unsolved);
1.945 raeburn 4127: if (%typeparts) {
4128: foreach my $id (keys(%typeparts)) {
1.1199 raeburn 4129: if (($returnhash{$version.':'.$id.'.type'} eq 'anonsurvey') ||
4130: ($returnhash{$version.':'.$id.'.type'} eq 'anonsurveycred')) {
1.945 raeburn 4131: push(@hidden,$id);
1.1199 raeburn 4132: } elsif ($identifier ne '') {
4133: unless (($returnhash{$version.':'.$id.'.type'} eq 'survey') ||
4134: ($returnhash{$version.':'.$id.'.type'} eq 'surveycred') ||
4135: ($hidestatus{$id})) {
1.1200 raeburn 4136: next if ((ref($resets{$id}) eq 'ARRAY') && grep(/^\Q$version\E$/,@{$resets{$id}}));
1.1199 raeburn 4137: if ($returnhash{$version.':'.$id.'.solved'} eq 'correct_by_student') {
4138: push(@{$solved{$id}},$version);
4139: } elsif (($returnhash{$version.':'.$id.'.solved'} ne '') &&
4140: (ref($solved{$id}) eq 'ARRAY')) {
4141: my $skip;
4142: if (ref($resets{$id}) eq 'ARRAY') {
4143: foreach my $reset (@{$resets{$id}}) {
4144: if ($reset > $solved{$id}[-1]) {
4145: $skip=1;
4146: last;
4147: }
4148: }
4149: }
4150: unless ($skip) {
4151: my ($ign,$partslist) = split(/\./,$id,2);
4152: push(@unsolved,$partslist);
4153: }
4154: }
4155: }
1.945 raeburn 4156: }
4157: }
4158: }
4159: $prevattempts.=&start_data_table_row().
1.1199 raeburn 4160: '<td>'.&mt('Transaction [_1]',$version);
4161: if (@unsolved) {
4162: $prevattempts .= '<span class="LC_nobreak"><label>'.
4163: '<input type="checkbox" name="HIDE'.$identifier.'" value="'.$version.':'.join('_',@unsolved).'" />'.
4164: &mt('Hide').'</label></span>';
4165: }
4166: $prevattempts .= '</td>';
1.945 raeburn 4167: if (@hidden) {
4168: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4169: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4170: my $hide;
4171: foreach my $id (@hidden) {
4172: if ($key =~ /^\Q$id\E/) {
4173: $hide = 1;
4174: last;
4175: }
4176: }
4177: if ($hide) {
4178: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4179: if (($data eq 'award') || ($data eq 'awarddetail')) {
4180: my $value = &format_previous_attempt_value($key,
4181: $returnhash{$version.':'.$key});
1.1173 kruse 4182: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4183: } else {
4184: $prevattempts.='<td> </td>';
4185: }
4186: } else {
4187: if ($key =~ /\./) {
1.1212 raeburn 4188: my $value = $returnhash{$version.':'.$key};
4189: if ($key =~ /\.rndseed$/) {
4190: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4191: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4192: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4193: }
4194: }
4195: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4196: ' </td>';
1.945 raeburn 4197: } else {
4198: $prevattempts.='<td> </td>';
4199: }
4200: }
4201: }
4202: } else {
4203: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4204: next if ($key =~ /\.foilorder$/);
1.1212 raeburn 4205: my $value = $returnhash{$version.':'.$key};
4206: if ($key =~ /\.rndseed$/) {
4207: my ($id) = ($key =~ /^(.+)\.[^.]+$/);
4208: if (exists($returnhash{$version.':'.$id.'.rawrndseed'})) {
4209: $value = $returnhash{$version.':'.$id.'.rawrndseed'};
4210: }
4211: }
4212: $prevattempts.='<td>'.&format_previous_attempt_value($key,$value).
4213: ' </td>';
1.945 raeburn 4214: }
4215: }
4216: $prevattempts.=&end_data_table_row();
1.40 ng 4217: }
1.1 albertel 4218: }
1.945 raeburn 4219: my @currhidden = keys(%lasthidden);
1.596 albertel 4220: $prevattempts.=&start_data_table_row().'<td>'.&mt('Current').'</td>';
1.356 albertel 4221: foreach my $key (sort(keys(%lasthash))) {
1.989 raeburn 4222: next if ($key =~ /\.foilorder$/);
1.945 raeburn 4223: if (%typeparts) {
4224: my $hidden;
4225: foreach my $id (@currhidden) {
4226: if ($key =~ /^\Q$id\E/) {
4227: $hidden = 1;
4228: last;
4229: }
4230: }
4231: if ($hidden) {
4232: my ($id,$data) = ($key =~ /^(.+)\.([^.]+)$/);
4233: if (($data eq 'award') || ($data eq 'awarddetail')) {
4234: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4235: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4236: $value = &$gradesub($value);
4237: }
1.1173 kruse 4238: $prevattempts.='<td>'. $value.' </td>';
1.945 raeburn 4239: } else {
4240: $prevattempts.='<td> </td>';
4241: }
4242: } else {
4243: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4244: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4245: $value = &$gradesub($value);
4246: }
1.1173 kruse 4247: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4248: }
4249: } else {
4250: my $value = &format_previous_attempt_value($key,$lasthash{$key});
4251: if ($key =~/$regexp$/ && (defined &$gradesub)) {
4252: $value = &$gradesub($value);
4253: }
1.1173 kruse 4254: $prevattempts.='<td>'.$value.' </td>';
1.945 raeburn 4255: }
1.16 harris41 4256: }
1.596 albertel 4257: $prevattempts.= &end_data_table_row().&end_data_table();
1.1 albertel 4258: } else {
1.596 albertel 4259: $prevattempts=
4260: &start_data_table().&start_data_table_row().
4261: '<td>'.&mt('Nothing submitted - no attempts.').'</td>'.
4262: &end_data_table_row().&end_data_table();
1.1 albertel 4263: }
4264: } else {
1.596 albertel 4265: $prevattempts=
4266: &start_data_table().&start_data_table_row().
4267: '<td>'.&mt('No data.').'</td>'.
4268: &end_data_table_row().&end_data_table();
1.1 albertel 4269: }
1.10 albertel 4270: }
4271:
1.581 albertel 4272: sub format_previous_attempt_value {
4273: my ($key,$value) = @_;
1.1011 www 4274: if (($key =~ /timestamp/) || ($key=~/duedate/)) {
1.1173 kruse 4275: $value = &Apache::lonlocal::locallocaltime($value);
1.581 albertel 4276: } elsif (ref($value) eq 'ARRAY') {
1.1173 kruse 4277: $value = &HTML::Entities::encode('('.join(', ', @{ $value }).')','"<>&');
1.988 raeburn 4278: } elsif ($key =~ /answerstring$/) {
4279: my %answers = &Apache::lonnet::str2hash($value);
1.1173 kruse 4280: my @answer = %answers;
4281: %answers = map {&HTML::Entities::encode($_, '"<>&')} @answer;
1.988 raeburn 4282: my @anskeys = sort(keys(%answers));
4283: if (@anskeys == 1) {
4284: my $answer = $answers{$anskeys[0]};
1.1001 raeburn 4285: if ($answer =~ m{\0}) {
4286: $answer =~ s{\0}{,}g;
1.988 raeburn 4287: }
4288: my $tag_internal_answer_name = 'INTERNAL';
4289: if ($anskeys[0] eq $tag_internal_answer_name) {
4290: $value = $answer;
4291: } else {
4292: $value = $anskeys[0].'='.$answer;
4293: }
4294: } else {
4295: foreach my $ans (@anskeys) {
4296: my $answer = $answers{$ans};
1.1001 raeburn 4297: if ($answer =~ m{\0}) {
4298: $answer =~ s{\0}{,}g;
1.988 raeburn 4299: }
4300: $value .= $ans.'='.$answer.'<br />';;
4301: }
4302: }
1.581 albertel 4303: } else {
1.1173 kruse 4304: $value = &HTML::Entities::encode(&unescape($value), '"<>&');
1.581 albertel 4305: }
4306: return $value;
4307: }
4308:
4309:
1.107 albertel 4310: sub relative_to_absolute {
4311: my ($url,$output)=@_;
4312: my $parser=HTML::TokeParser->new(\$output);
4313: my $token;
4314: my $thisdir=$url;
4315: my @rlinks=();
4316: while ($token=$parser->get_token) {
4317: if ($token->[0] eq 'S') {
4318: if ($token->[1] eq 'a') {
4319: if ($token->[2]->{'href'}) {
4320: $rlinks[$#rlinks+1]=$token->[2]->{'href'};
4321: }
4322: } elsif ($token->[1] eq 'img' || $token->[1] eq 'embed' ) {
4323: $rlinks[$#rlinks+1]=$token->[2]->{'src'};
4324: } elsif ($token->[1] eq 'base') {
4325: $thisdir=$token->[2]->{'href'};
4326: }
4327: }
4328: }
4329: $thisdir=~s-/[^/]*$--;
1.356 albertel 4330: foreach my $link (@rlinks) {
1.726 raeburn 4331: unless (($link=~/^https?\:\/\//i) ||
1.356 albertel 4332: ($link=~/^\//) ||
4333: ($link=~/^javascript:/i) ||
4334: ($link=~/^mailto:/i) ||
4335: ($link=~/^\#/)) {
4336: my $newlocation=&Apache::lonnet::hreflocation($thisdir,$link);
4337: $output=~s/(\"|\'|\=\s*)\Q$link\E(\"|\'|\s|\>)/$1$newlocation$2/;
1.107 albertel 4338: }
4339: }
4340: # -------------------------------------------------- Deal with Applet codebases
4341: $output=~s/(\<applet[^\>]+)(codebase\=[^\S\>]+)*([^\>]*)\>/$1.($2?$2:' codebase="'.$thisdir.'"').$3.'>'/gei;
4342: return $output;
4343: }
4344:
1.112 bowersj2 4345: =pod
4346:
1.648 raeburn 4347: =item * &get_student_view()
1.112 bowersj2 4348:
4349: show a snapshot of what student was looking at
4350:
4351: =cut
4352:
1.10 albertel 4353: sub get_student_view {
1.186 albertel 4354: my ($symb,$username,$domain,$courseid,$target,$moreenv) = @_;
1.114 www 4355: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4356: my (%form);
1.10 albertel 4357: my @elements=('symb','courseid','domain','username');
4358: foreach my $element (@elements) {
1.186 albertel 4359: $form{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4360: }
1.186 albertel 4361: if (defined($moreenv)) {
4362: %form=(%form,%{$moreenv});
4363: }
1.236 albertel 4364: if (defined($target)) { $form{'grade_target'} = $target; }
1.107 albertel 4365: $feedurl=&Apache::lonnet::clutter($feedurl);
1.650 www 4366: my ($userview,$response)=&Apache::lonnet::ssi_body($feedurl,%form);
1.11 albertel 4367: $userview=~s/\<body[^\>]*\>//gi;
4368: $userview=~s/\<\/body\>//gi;
4369: $userview=~s/\<html\>//gi;
4370: $userview=~s/\<\/html\>//gi;
4371: $userview=~s/\<head\>//gi;
4372: $userview=~s/\<\/head\>//gi;
4373: $userview=~s/action\s*\=/would_be_action\=/gi;
1.107 albertel 4374: $userview=&relative_to_absolute($feedurl,$userview);
1.650 www 4375: if (wantarray) {
4376: return ($userview,$response);
4377: } else {
4378: return $userview;
4379: }
4380: }
4381:
4382: sub get_student_view_with_retries {
4383: my ($symb,$retries,$username,$domain,$courseid,$target,$moreenv) = @_;
4384:
4385: my $ok = 0; # True if we got a good response.
4386: my $content;
4387: my $response;
4388:
4389: # Try to get the student_view done. within the retries count:
4390:
4391: do {
4392: ($content, $response) = &get_student_view($symb,$username,$domain,$courseid,$target,$moreenv);
4393: $ok = $response->is_success;
4394: if (!$ok) {
4395: &Apache::lonnet::logthis("Failed get_student_view_with_retries on $symb: ".$response->is_success.', '.$response->code.', '.$response->message);
4396: }
4397: $retries--;
4398: } while (!$ok && ($retries > 0));
4399:
4400: if (!$ok) {
4401: $content = ''; # On error return an empty content.
4402: }
1.651 www 4403: if (wantarray) {
4404: return ($content, $response);
4405: } else {
4406: return $content;
4407: }
1.11 albertel 4408: }
4409:
1.112 bowersj2 4410: =pod
4411:
1.648 raeburn 4412: =item * &get_student_answers()
1.112 bowersj2 4413:
4414: show a snapshot of how student was answering problem
4415:
4416: =cut
4417:
1.11 albertel 4418: sub get_student_answers {
1.100 sakharuk 4419: my ($symb,$username,$domain,$courseid,%form) = @_;
1.114 www 4420: my ($map,$id,$feedurl) = &Apache::lonnet::decode_symb($symb);
1.186 albertel 4421: my (%moreenv);
1.11 albertel 4422: my @elements=('symb','courseid','domain','username');
4423: foreach my $element (@elements) {
1.186 albertel 4424: $moreenv{'grade_'.$element}=eval '$'.$element #'
1.10 albertel 4425: }
1.186 albertel 4426: $moreenv{'grade_target'}='answer';
4427: %moreenv=(%form,%moreenv);
1.497 raeburn 4428: $feedurl = &Apache::lonnet::clutter($feedurl);
4429: my $userview=&Apache::lonnet::ssi($feedurl,%moreenv);
1.10 albertel 4430: return $userview;
1.1 albertel 4431: }
1.116 albertel 4432:
4433: =pod
4434:
4435: =item * &submlink()
4436:
1.242 albertel 4437: Inputs: $text $uname $udom $symb $target
1.116 albertel 4438:
4439: Returns: A link to grades.pm such as to see the SUBM view of a student
4440:
4441: =cut
4442:
4443: ###############################################
4444: sub submlink {
1.242 albertel 4445: my ($text,$uname,$udom,$symb,$target)=@_;
1.116 albertel 4446: if (!($uname && $udom)) {
4447: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4448: &Apache::lonnet::whichuser($symb);
1.116 albertel 4449: if (!$symb) { $symb=$cursymb; }
4450: }
1.254 matthew 4451: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4452: $symb=&escape($symb);
1.960 bisitz 4453: if ($target) { $target=" target=\"$target\""; }
4454: return
4455: '<a href="/adm/grades?command=submission'.
4456: '&symb='.$symb.
4457: '&student='.$uname.
4458: '&userdom='.$udom.'"'.
4459: $target.'>'.$text.'</a>';
1.242 albertel 4460: }
4461: ##############################################
4462:
4463: =pod
4464:
4465: =item * &pgrdlink()
4466:
4467: Inputs: $text $uname $udom $symb $target
4468:
4469: Returns: A link to grades.pm such as to see the PGRD view of a student
4470:
4471: =cut
4472:
4473: ###############################################
4474: sub pgrdlink {
4475: my $link=&submlink(@_);
4476: $link=~s/(&command=submission)/$1&showgrading=yes/;
4477: return $link;
4478: }
4479: ##############################################
4480:
4481: =pod
4482:
4483: =item * &pprmlink()
4484:
4485: Inputs: $text $uname $udom $symb $target
4486:
4487: Returns: A link to parmset.pm such as to see the PPRM view of a
1.283 albertel 4488: student and a specific resource
1.242 albertel 4489:
4490: =cut
4491:
4492: ###############################################
4493: sub pprmlink {
4494: my ($text,$uname,$udom,$symb,$target)=@_;
4495: if (!($uname && $udom)) {
4496: (my $cursymb, my $courseid,$udom,$uname)=
1.463 albertel 4497: &Apache::lonnet::whichuser($symb);
1.242 albertel 4498: if (!$symb) { $symb=$cursymb; }
4499: }
1.254 matthew 4500: if (!$symb) { $symb=&Apache::lonnet::symbread(); }
1.369 www 4501: $symb=&escape($symb);
1.242 albertel 4502: if ($target) { $target="target=\"$target\""; }
1.595 albertel 4503: return '<a href="/adm/parmset?command=set&'.
4504: 'symb='.$symb.'&uname='.$uname.
4505: '&udom='.$udom.'" '.$target.'>'.$text.'</a>';
1.116 albertel 4506: }
4507: ##############################################
1.37 matthew 4508:
1.112 bowersj2 4509: =pod
4510:
4511: =back
4512:
4513: =cut
4514:
1.37 matthew 4515: ###############################################
1.51 www 4516:
4517:
4518: sub timehash {
1.687 raeburn 4519: my ($thistime) = @_;
4520: my $timezone = &Apache::lonlocal::gettimezone();
4521: my $dt = DateTime->from_epoch(epoch => $thistime)
4522: ->set_time_zone($timezone);
4523: my $wday = $dt->day_of_week();
4524: if ($wday == 7) { $wday = 0; }
4525: return ( 'second' => $dt->second(),
4526: 'minute' => $dt->minute(),
4527: 'hour' => $dt->hour(),
4528: 'day' => $dt->day_of_month(),
4529: 'month' => $dt->month(),
4530: 'year' => $dt->year(),
4531: 'weekday' => $wday,
4532: 'dayyear' => $dt->day_of_year(),
4533: 'dlsav' => $dt->is_dst() );
1.51 www 4534: }
4535:
1.370 www 4536: sub utc_string {
4537: my ($date)=@_;
1.371 www 4538: return strftime("%Y%m%dT%H%M%SZ",gmtime($date));
1.370 www 4539: }
4540:
1.51 www 4541: sub maketime {
4542: my %th=@_;
1.687 raeburn 4543: my ($epoch_time,$timezone,$dt);
4544: $timezone = &Apache::lonlocal::gettimezone();
4545: eval {
4546: $dt = DateTime->new( year => $th{'year'},
4547: month => $th{'month'},
4548: day => $th{'day'},
4549: hour => $th{'hour'},
4550: minute => $th{'minute'},
4551: second => $th{'second'},
4552: time_zone => $timezone,
4553: );
4554: };
4555: if (!$@) {
4556: $epoch_time = $dt->epoch;
4557: if ($epoch_time) {
4558: return $epoch_time;
4559: }
4560: }
1.51 www 4561: return POSIX::mktime(
4562: ($th{'seconds'},$th{'minutes'},$th{'hours'},
1.210 www 4563: $th{'day'},$th{'month'}-1,$th{'year'}-1900,0,0,-1));
1.70 www 4564: }
4565:
4566: #########################################
1.51 www 4567:
4568: sub findallcourses {
1.482 raeburn 4569: my ($roles,$uname,$udom) = @_;
1.355 albertel 4570: my %roles;
4571: if (ref($roles)) { %roles = map { $_ => 1 } @{$roles}; }
1.348 albertel 4572: my %courses;
1.51 www 4573: my $now=time;
1.482 raeburn 4574: if (!defined($uname)) {
4575: $uname = $env{'user.name'};
4576: }
4577: if (!defined($udom)) {
4578: $udom = $env{'user.domain'};
4579: }
4580: if (($uname ne $env{'user.name'}) || ($udom ne $env{'user.domain'})) {
1.1073 raeburn 4581: my %roleshash = &Apache::lonnet::dump('roles',$udom,$uname);
1.482 raeburn 4582: if (!%roles) {
4583: %roles = (
4584: cc => 1,
1.907 raeburn 4585: co => 1,
1.482 raeburn 4586: in => 1,
4587: ep => 1,
4588: ta => 1,
4589: cr => 1,
4590: st => 1,
4591: );
4592: }
4593: foreach my $entry (keys(%roleshash)) {
4594: my ($trole,$tend,$tstart) = split(/_/,$roleshash{$entry});
4595: if ($trole =~ /^cr/) {
4596: next if (!exists($roles{$trole}) && !exists($roles{'cr'}));
4597: } else {
4598: next if (!exists($roles{$trole}));
4599: }
4600: if ($tend) {
4601: next if ($tend < $now);
4602: }
4603: if ($tstart) {
4604: next if ($tstart > $now);
4605: }
1.1058 raeburn 4606: my ($cdom,$cnum,$sec,$cnumpart,$secpart,$role);
1.482 raeburn 4607: (undef,$cdom,$cnumpart,$secpart) = split(/\//,$entry);
1.1058 raeburn 4608: my $value = $trole.'/'.$cdom.'/';
1.482 raeburn 4609: if ($secpart eq '') {
4610: ($cnum,$role) = split(/_/,$cnumpart);
4611: $sec = 'none';
1.1058 raeburn 4612: $value .= $cnum.'/';
1.482 raeburn 4613: } else {
4614: $cnum = $cnumpart;
4615: ($sec,$role) = split(/_/,$secpart);
1.1058 raeburn 4616: $value .= $cnum.'/'.$sec;
4617: }
4618: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4619: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4620: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4621: }
4622: } else {
4623: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.490 raeburn 4624: }
1.482 raeburn 4625: }
4626: } else {
4627: foreach my $key (keys(%env)) {
1.483 albertel 4628: if ( $key=~m{^user\.role\.(\w+)\./($match_domain)/($match_courseid)/?(\w*)$} ||
4629: $key=~m{^user\.role\.(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_courseid)/?(\w*)$}) {
1.482 raeburn 4630: my ($role,$cdom,$cnum,$sec) = ($1,$2,$3,$4);
4631: next if ($role eq 'ca' || $role eq 'aa');
4632: next if (%roles && !exists($roles{$role}));
4633: my ($starttime,$endtime)=split(/\./,$env{$key});
4634: my $active=1;
4635: if ($starttime) {
4636: if ($now<$starttime) { $active=0; }
4637: }
4638: if ($endtime) {
4639: if ($now>$endtime) { $active=0; }
4640: }
4641: if ($active) {
1.1058 raeburn 4642: my $value = $role.'/'.$cdom.'/'.$cnum.'/';
1.482 raeburn 4643: if ($sec eq '') {
4644: $sec = 'none';
1.1058 raeburn 4645: } else {
4646: $value .= $sec;
4647: }
4648: if (ref($courses{$cdom.'_'.$cnum}{$sec}) eq 'ARRAY') {
4649: unless (grep(/^\Q$value\E$/,@{$courses{$cdom.'_'.$cnum}{$sec}})) {
4650: push(@{$courses{$cdom.'_'.$cnum}{$sec}},$value);
4651: }
4652: } else {
4653: @{$courses{$cdom.'_'.$cnum}{$sec}} = ($value);
1.482 raeburn 4654: }
1.474 raeburn 4655: }
4656: }
1.51 www 4657: }
4658: }
1.474 raeburn 4659: return %courses;
1.51 www 4660: }
1.37 matthew 4661:
1.54 www 4662: ###############################################
1.474 raeburn 4663:
4664: sub blockcheck {
1.1189 raeburn 4665: my ($setters,$activity,$uname,$udom,$url,$is_course) = @_;
1.490 raeburn 4666:
1.1189 raeburn 4667: if (defined($udom) && defined($uname)) {
4668: # If uname and udom are for a course, check for blocks in the course.
4669: if (($is_course) || (&Apache::lonnet::is_course($udom,$uname))) {
4670: my ($startblock,$endblock,$triggerblock) =
4671: &get_blocks($setters,$activity,$udom,$uname,$url);
4672: return ($startblock,$endblock,$triggerblock);
4673: }
4674: } else {
1.490 raeburn 4675: $udom = $env{'user.domain'};
4676: $uname = $env{'user.name'};
4677: }
4678:
1.502 raeburn 4679: my $startblock = 0;
4680: my $endblock = 0;
1.1062 raeburn 4681: my $triggerblock = '';
1.482 raeburn 4682: my %live_courses = &findallcourses(undef,$uname,$udom);
1.474 raeburn 4683:
1.490 raeburn 4684: # If uname is for a user, and activity is course-specific, i.e.,
4685: # boards, chat or groups, check for blocking in current course only.
1.474 raeburn 4686:
1.490 raeburn 4687: if (($activity eq 'boards' || $activity eq 'chat' ||
1.1189 raeburn 4688: $activity eq 'groups' || $activity eq 'printout') &&
4689: ($env{'request.course.id'})) {
1.490 raeburn 4690: foreach my $key (keys(%live_courses)) {
4691: if ($key ne $env{'request.course.id'}) {
4692: delete($live_courses{$key});
4693: }
4694: }
4695: }
4696:
4697: my $otheruser = 0;
4698: my %own_courses;
4699: if ((($uname ne $env{'user.name'})) || ($udom ne $env{'user.domain'})) {
4700: # Resource belongs to user other than current user.
4701: $otheruser = 1;
4702: # Gather courses for current user
4703: %own_courses =
4704: &findallcourses(undef,$env{'user.name'},$env{'user.domain'});
4705: }
4706:
4707: # Gather active course roles - course coordinator, instructor,
4708: # exam proctor, ta, student, or custom role.
1.474 raeburn 4709:
4710: foreach my $course (keys(%live_courses)) {
1.482 raeburn 4711: my ($cdom,$cnum);
4712: if ((defined($env{'course.'.$course.'.domain'})) && (defined($env{'course.'.$course.'.num'}))) {
4713: $cdom = $env{'course.'.$course.'.domain'};
4714: $cnum = $env{'course.'.$course.'.num'};
4715: } else {
1.490 raeburn 4716: ($cdom,$cnum) = split(/_/,$course);
1.482 raeburn 4717: }
4718: my $no_ownblock = 0;
4719: my $no_userblock = 0;
1.533 raeburn 4720: if ($otheruser && $activity ne 'com') {
1.490 raeburn 4721: # Check if current user has 'evb' priv for this
4722: if (defined($own_courses{$course})) {
4723: foreach my $sec (keys(%{$own_courses{$course}})) {
4724: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
4725: if ($sec ne 'none') {
4726: $checkrole .= '/'.$sec;
4727: }
4728: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4729: $no_ownblock = 1;
4730: last;
4731: }
4732: }
4733: }
4734: # if they have 'evb' priv and are currently not playing student
4735: next if (($no_ownblock) &&
4736: ($env{'request.role'} !~ m{^st\./$cdom/$cnum}));
4737: }
1.474 raeburn 4738: foreach my $sec (keys(%{$live_courses{$course}})) {
1.482 raeburn 4739: my $checkrole = 'cm./'.$cdom.'/'.$cnum;
1.474 raeburn 4740: if ($sec ne 'none') {
1.482 raeburn 4741: $checkrole .= '/'.$sec;
1.474 raeburn 4742: }
1.490 raeburn 4743: if ($otheruser) {
4744: # Resource belongs to user other than current user.
4745: # Assemble privs for that user, and check for 'evb' priv.
1.1058 raeburn 4746: my (%allroles,%userroles);
4747: if (ref($live_courses{$course}{$sec}) eq 'ARRAY') {
4748: foreach my $entry (@{$live_courses{$course}{$sec}}) {
4749: my ($trole,$tdom,$tnum,$tsec);
4750: if ($entry =~ /^cr/) {
4751: ($trole,$tdom,$tnum,$tsec) =
4752: ($entry =~ m|^(cr/$match_domain/$match_username/\w+)\./($match_domain)/($match_username)/?(\w*)$|);
4753: } else {
4754: ($trole,$tdom,$tnum,$tsec) = split(/\//,$entry);
4755: }
4756: my ($spec,$area,$trest);
4757: $area = '/'.$tdom.'/'.$tnum;
4758: $trest = $tnum;
4759: if ($tsec ne '') {
4760: $area .= '/'.$tsec;
4761: $trest .= '/'.$tsec;
4762: }
4763: $spec = $trole.'.'.$area;
4764: if ($trole =~ /^cr/) {
4765: &Apache::lonnet::custom_roleprivs(\%allroles,$trole,
4766: $tdom,$spec,$trest,$area);
4767: } else {
4768: &Apache::lonnet::standard_roleprivs(\%allroles,$trole,
4769: $tdom,$spec,$trest,$area);
4770: }
4771: }
4772: my ($author,$adv) = &Apache::lonnet::set_userprivs(\%userroles,\%allroles);
4773: if ($userroles{'user.priv.'.$checkrole} =~ /evb\&([^\:]*)/) {
4774: if ($1) {
4775: $no_userblock = 1;
4776: last;
4777: }
1.486 raeburn 4778: }
4779: }
1.490 raeburn 4780: } else {
4781: # Resource belongs to current user
4782: # Check for 'evb' priv via lonnet::allowed().
1.482 raeburn 4783: if (&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) {
4784: $no_ownblock = 1;
4785: last;
4786: }
1.474 raeburn 4787: }
4788: }
4789: # if they have the evb priv and are currently not playing student
1.482 raeburn 4790: next if (($no_ownblock) &&
1.491 albertel 4791: ($env{'request.role'} !~ m{^st\./\Q$cdom\E/\Q$cnum\E}));
1.482 raeburn 4792: next if ($no_userblock);
1.474 raeburn 4793:
1.866 kalberla 4794: # Retrieve blocking times and identity of locker for course
1.490 raeburn 4795: # of specified user, unless user has 'evb' privilege.
1.502 raeburn 4796:
1.1062 raeburn 4797: my ($start,$end,$trigger) =
4798: &get_blocks($setters,$activity,$cdom,$cnum,$url);
1.502 raeburn 4799: if (($start != 0) &&
4800: (($startblock == 0) || ($startblock > $start))) {
4801: $startblock = $start;
1.1062 raeburn 4802: if ($trigger ne '') {
4803: $triggerblock = $trigger;
4804: }
1.502 raeburn 4805: }
4806: if (($end != 0) &&
4807: (($endblock == 0) || ($endblock < $end))) {
4808: $endblock = $end;
1.1062 raeburn 4809: if ($trigger ne '') {
4810: $triggerblock = $trigger;
4811: }
1.502 raeburn 4812: }
1.490 raeburn 4813: }
1.1062 raeburn 4814: return ($startblock,$endblock,$triggerblock);
1.490 raeburn 4815: }
4816:
4817: sub get_blocks {
1.1062 raeburn 4818: my ($setters,$activity,$cdom,$cnum,$url) = @_;
1.490 raeburn 4819: my $startblock = 0;
4820: my $endblock = 0;
1.1062 raeburn 4821: my $triggerblock = '';
1.490 raeburn 4822: my $course = $cdom.'_'.$cnum;
4823: $setters->{$course} = {};
4824: $setters->{$course}{'staff'} = [];
4825: $setters->{$course}{'times'} = [];
1.1062 raeburn 4826: $setters->{$course}{'triggers'} = [];
4827: my (@blockers,%triggered);
4828: my $now = time;
4829: my %commblocks = &Apache::lonnet::get_comm_blocks($cdom,$cnum);
4830: if ($activity eq 'docs') {
4831: @blockers = &Apache::lonnet::has_comm_blocking('bre',undef,$url,\%commblocks);
4832: foreach my $block (@blockers) {
4833: if ($block =~ /^firstaccess____(.+)$/) {
4834: my $item = $1;
4835: my $type = 'map';
4836: my $timersymb = $item;
4837: if ($item eq 'course') {
4838: $type = 'course';
4839: } elsif ($item =~ /___\d+___/) {
4840: $type = 'resource';
4841: } else {
4842: $timersymb = &Apache::lonnet::symbread($item);
4843: }
4844: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4845: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4846: $triggered{$block} = {
4847: start => $start,
4848: end => $end,
4849: type => $type,
4850: };
4851: }
4852: }
4853: } else {
4854: foreach my $block (keys(%commblocks)) {
4855: if ($block =~ m/^(\d+)____(\d+)$/) {
4856: my ($start,$end) = ($1,$2);
4857: if ($start <= time && $end >= time) {
4858: if (ref($commblocks{$block}) eq 'HASH') {
4859: if (ref($commblocks{$block}{'blocks'}) eq 'HASH') {
4860: if ($commblocks{$block}{'blocks'}{$activity} eq 'on') {
4861: unless(grep(/^\Q$block\E$/,@blockers)) {
4862: push(@blockers,$block);
4863: }
4864: }
4865: }
4866: }
4867: }
4868: } elsif ($block =~ /^firstaccess____(.+)$/) {
4869: my $item = $1;
4870: my $timersymb = $item;
4871: my $type = 'map';
4872: if ($item eq 'course') {
4873: $type = 'course';
4874: } elsif ($item =~ /___\d+___/) {
4875: $type = 'resource';
4876: } else {
4877: $timersymb = &Apache::lonnet::symbread($item);
4878: }
4879: my $start = $env{'course.'.$cdom.'_'.$cnum.'.firstaccess.'.$timersymb};
4880: my $end = $start + $env{'course.'.$cdom.'_'.$cnum.'.timerinterval.'.$timersymb};
4881: if ($start && $end) {
4882: if (($start <= time) && ($end >= time)) {
4883: unless (grep(/^\Q$block\E$/,@blockers)) {
4884: push(@blockers,$block);
4885: $triggered{$block} = {
4886: start => $start,
4887: end => $end,
4888: type => $type,
4889: };
4890: }
4891: }
1.490 raeburn 4892: }
1.1062 raeburn 4893: }
4894: }
4895: }
4896: foreach my $blocker (@blockers) {
4897: my ($staff_name,$staff_dom,$title,$blocks) =
4898: &parse_block_record($commblocks{$blocker});
4899: push(@{$$setters{$course}{'staff'}},[$staff_name,$staff_dom]);
4900: my ($start,$end,$triggertype);
4901: if ($blocker =~ m/^(\d+)____(\d+)$/) {
4902: ($start,$end) = ($1,$2);
4903: } elsif (ref($triggered{$blocker}) eq 'HASH') {
4904: $start = $triggered{$blocker}{'start'};
4905: $end = $triggered{$blocker}{'end'};
4906: $triggertype = $triggered{$blocker}{'type'};
4907: }
4908: if ($start) {
4909: push(@{$$setters{$course}{'times'}}, [$start,$end]);
4910: if ($triggertype) {
4911: push(@{$$setters{$course}{'triggers'}},$triggertype);
4912: } else {
4913: push(@{$$setters{$course}{'triggers'}},0);
4914: }
4915: if ( ($startblock == 0) || ($startblock > $start) ) {
4916: $startblock = $start;
4917: if ($triggertype) {
4918: $triggerblock = $blocker;
1.474 raeburn 4919: }
4920: }
1.1062 raeburn 4921: if ( ($endblock == 0) || ($endblock < $end) ) {
4922: $endblock = $end;
4923: if ($triggertype) {
4924: $triggerblock = $blocker;
4925: }
4926: }
1.474 raeburn 4927: }
4928: }
1.1062 raeburn 4929: return ($startblock,$endblock,$triggerblock);
1.474 raeburn 4930: }
4931:
4932: sub parse_block_record {
4933: my ($record) = @_;
4934: my ($setuname,$setudom,$title,$blocks);
4935: if (ref($record) eq 'HASH') {
4936: ($setuname,$setudom) = split(/:/,$record->{'setter'});
4937: $title = &unescape($record->{'event'});
4938: $blocks = $record->{'blocks'};
4939: } else {
4940: my @data = split(/:/,$record,3);
4941: if (scalar(@data) eq 2) {
4942: $title = $data[1];
4943: ($setuname,$setudom) = split(/@/,$data[0]);
4944: } else {
4945: ($setuname,$setudom,$title) = @data;
4946: }
4947: $blocks = { 'com' => 'on' };
4948: }
4949: return ($setuname,$setudom,$title,$blocks);
4950: }
4951:
1.854 kalberla 4952: sub blocking_status {
1.1189 raeburn 4953: my ($activity,$uname,$udom,$url,$is_course) = @_;
1.1061 raeburn 4954: my %setters;
1.890 droeschl 4955:
1.1061 raeburn 4956: # check for active blocking
1.1062 raeburn 4957: my ($startblock,$endblock,$triggerblock) =
1.1189 raeburn 4958: &blockcheck(\%setters,$activity,$uname,$udom,$url,$is_course);
1.1062 raeburn 4959: my $blocked = 0;
4960: if ($startblock && $endblock) {
4961: $blocked = 1;
4962: }
1.890 droeschl 4963:
1.1061 raeburn 4964: # caller just wants to know whether a block is active
4965: if (!wantarray) { return $blocked; }
4966:
4967: # build a link to a popup window containing the details
4968: my $querystring = "?activity=$activity";
4969: # $uname and $udom decide whose portfolio the user is trying to look at
1.1232 raeburn 4970: if (($activity eq 'port') || ($activity eq 'passwd')) {
4971: $querystring .= "&udom=$udom" if ($udom =~ /^$match_domain$/);
4972: $querystring .= "&uname=$uname" if ($uname =~ /^$match_username$/);
1.1062 raeburn 4973: } elsif ($activity eq 'docs') {
4974: $querystring .= '&url='.&HTML::Entities::encode($url,'&"');
4975: }
1.1061 raeburn 4976:
4977: my $output .= <<'END_MYBLOCK';
4978: function openWindow(url, wdwName, w, h, toolbar,scrollbar) {
4979: var options = "width=" + w + ",height=" + h + ",";
4980: options += "resizable=yes,scrollbars="+scrollbar+",status=no,";
4981: options += "menubar=no,toolbar="+toolbar+",location=no,directories=no";
4982: var newWin = window.open(url, wdwName, options);
4983: newWin.focus();
4984: }
1.890 droeschl 4985: END_MYBLOCK
1.854 kalberla 4986:
1.1061 raeburn 4987: $output = Apache::lonhtmlcommon::scripttag($output);
1.890 droeschl 4988:
1.1061 raeburn 4989: my $popupUrl = "/adm/blockingstatus/$querystring";
1.1062 raeburn 4990: my $text = &mt('Communication Blocked');
1.1217 raeburn 4991: my $class = 'LC_comblock';
1.1062 raeburn 4992: if ($activity eq 'docs') {
4993: $text = &mt('Content Access Blocked');
1.1217 raeburn 4994: $class = '';
1.1063 raeburn 4995: } elsif ($activity eq 'printout') {
4996: $text = &mt('Printing Blocked');
1.1232 raeburn 4997: } elsif ($activity eq 'passwd') {
4998: $text = &mt('Password Changing Blocked');
1.1062 raeburn 4999: }
1.1061 raeburn 5000: $output .= <<"END_BLOCK";
1.1217 raeburn 5001: <div class='$class'>
1.869 kalberla 5002: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5003: title='$text'>
5004: <img class='LC_noBorder LC_middle' title='$text' src='/res/adm/pages/comblock.png' alt='$text'/></a>
1.869 kalberla 5005: <a onclick='openWindow("$popupUrl","Blocking Table",600,300,"no","no");return false;' href='/adm/blockingstatus/$querystring'
1.890 droeschl 5006: title='$text'>$text</a>
1.867 kalberla 5007: </div>
5008:
5009: END_BLOCK
1.474 raeburn 5010:
1.1061 raeburn 5011: return ($blocked, $output);
1.854 kalberla 5012: }
1.490 raeburn 5013:
1.60 matthew 5014: ###############################################
5015:
1.682 raeburn 5016: sub check_ip_acc {
1.1201 raeburn 5017: my ($acc,$clientip)=@_;
1.682 raeburn 5018: &Apache::lonxml::debug("acc is $acc");
5019: if (!defined($acc) || $acc =~ /^\s*$/ || $acc =~/^\s*no\s*$/i) {
5020: return 1;
5021: }
1.1219 raeburn 5022: my $allowed;
1.1201 raeburn 5023: my $ip=$env{'request.host'} || $ENV{'REMOTE_ADDR'} || $clientip;
1.682 raeburn 5024:
5025: my $name;
1.1219 raeburn 5026: my %access = (
5027: allowfrom => 1,
5028: denyfrom => 0,
5029: );
5030: my @allows;
5031: my @denies;
5032: foreach my $item (split(',',$acc)) {
5033: $item =~ s/^\s*//;
5034: $item =~ s/\s*$//;
5035: my $pattern;
5036: if ($item =~ /^\!(.+)$/) {
5037: push(@denies,$1);
5038: } else {
5039: push(@allows,$item);
5040: }
5041: }
5042: my $numdenies = scalar(@denies);
5043: my $numallows = scalar(@allows);
5044: my $count = 0;
5045: foreach my $pattern (@denies,@allows) {
5046: $count ++;
5047: my $acctype = 'allowfrom';
5048: if ($count <= $numdenies) {
5049: $acctype = 'denyfrom';
5050: }
1.682 raeburn 5051: if ($pattern =~ /\*$/) {
5052: #35.8.*
5053: $pattern=~s/\*//;
1.1219 raeburn 5054: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5055: } elsif ($pattern =~ /(\d+\.\d+\.\d+)\.\[(\d+)-(\d+)\]$/) {
5056: #35.8.3.[34-56]
5057: my $low=$2;
5058: my $high=$3;
5059: $pattern=$1;
5060: if ($ip =~ /^\Q$pattern\E/) {
5061: my $last=(split(/\./,$ip))[3];
1.1219 raeburn 5062: if ($last <=$high && $last >=$low) { $allowed=$access{$acctype}; }
1.682 raeburn 5063: }
5064: } elsif ($pattern =~ /^\*/) {
5065: #*.msu.edu
5066: $pattern=~s/\*//;
5067: if (!defined($name)) {
5068: use Socket;
5069: my $netaddr=inet_aton($ip);
5070: ($name)=gethostbyaddr($netaddr,AF_INET);
5071: }
1.1219 raeburn 5072: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
1.682 raeburn 5073: } elsif ($pattern =~ /\d+\.\d+\.\d+\.\d+/) {
5074: #127.0.0.1
1.1219 raeburn 5075: if ($ip =~ /^\Q$pattern\E/) { $allowed=$access{$acctype}; }
1.682 raeburn 5076: } else {
5077: #some.name.com
5078: if (!defined($name)) {
5079: use Socket;
5080: my $netaddr=inet_aton($ip);
5081: ($name)=gethostbyaddr($netaddr,AF_INET);
5082: }
1.1219 raeburn 5083: if ($name =~ /\Q$pattern\E$/i) { $allowed=$access{$acctype}; }
5084: }
5085: if ($allowed =~ /^(0|1)$/) { last; }
5086: }
5087: if ($allowed eq '') {
5088: if ($numdenies && !$numallows) {
5089: $allowed = 1;
5090: } else {
5091: $allowed = 0;
1.682 raeburn 5092: }
5093: }
5094: return $allowed;
5095: }
5096:
5097: ###############################################
5098:
1.60 matthew 5099: =pod
5100:
1.112 bowersj2 5101: =head1 Domain Template Functions
5102:
5103: =over 4
5104:
5105: =item * &determinedomain()
1.60 matthew 5106:
5107: Inputs: $domain (usually will be undef)
5108:
1.63 www 5109: Returns: Determines which domain should be used for designs
1.60 matthew 5110:
5111: =cut
1.54 www 5112:
1.60 matthew 5113: ###############################################
1.63 www 5114: sub determinedomain {
5115: my $domain=shift;
1.531 albertel 5116: if (! $domain) {
1.60 matthew 5117: # Determine domain if we have not been given one
1.893 raeburn 5118: $domain = &Apache::lonnet::default_login_domain();
1.258 albertel 5119: if ($env{'user.domain'}) { $domain=$env{'user.domain'}; }
5120: if ($env{'request.role.domain'}) {
5121: $domain=$env{'request.role.domain'};
1.60 matthew 5122: }
5123: }
1.63 www 5124: return $domain;
5125: }
5126: ###############################################
1.517 raeburn 5127:
1.518 albertel 5128: sub devalidate_domconfig_cache {
5129: my ($udom)=@_;
5130: &Apache::lonnet::devalidate_cache_new('domainconfig',$udom);
5131: }
5132:
5133: # ---------------------- Get domain configuration for a domain
5134: sub get_domainconf {
5135: my ($udom) = @_;
5136: my $cachetime=1800;
5137: my ($result,$cached)=&Apache::lonnet::is_cached_new('domainconfig',$udom);
5138: if (defined($cached)) { return %{$result}; }
5139:
5140: my %domconfig = &Apache::lonnet::get_dom('configuration',
1.948 raeburn 5141: ['login','rolecolors','autoenroll'],$udom);
1.632 raeburn 5142: my (%designhash,%legacy);
1.518 albertel 5143: if (keys(%domconfig) > 0) {
5144: if (ref($domconfig{'login'}) eq 'HASH') {
1.632 raeburn 5145: if (keys(%{$domconfig{'login'}})) {
5146: foreach my $key (keys(%{$domconfig{'login'}})) {
1.699 raeburn 5147: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
1.1208 raeburn 5148: if (($key eq 'loginvia') || ($key eq 'headtag')) {
5149: if (ref($domconfig{'login'}{$key}) eq 'HASH') {
5150: foreach my $hostname (keys(%{$domconfig{'login'}{$key}})) {
5151: if (ref($domconfig{'login'}{$key}{$hostname}) eq 'HASH') {
5152: if ($key eq 'loginvia') {
5153: if ($domconfig{'login'}{'loginvia'}{$hostname}{'server'}) {
5154: my $server = $domconfig{'login'}{'loginvia'}{$hostname}{'server'};
5155: $designhash{$udom.'.login.loginvia'} = $server;
5156: if ($domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'} eq 'custom') {
5157:
5158: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'custompath'};
5159: } else {
5160: $designhash{$udom.'.login.loginvia_'.$hostname} = $server.':'.$domconfig{'login'}{'loginvia'}{$hostname}{'serverpath'};
5161: }
1.948 raeburn 5162: }
1.1208 raeburn 5163: } elsif ($key eq 'headtag') {
5164: if ($domconfig{'login'}{'headtag'}{$hostname}{'url'}) {
5165: $designhash{$udom.'.login.headtag_'.$hostname} = $domconfig{'login'}{'headtag'}{$hostname}{'url'};
1.948 raeburn 5166: }
1.946 raeburn 5167: }
1.1208 raeburn 5168: if ($domconfig{'login'}{$key}{$hostname}{'exempt'}) {
5169: $designhash{$udom.'.login.'.$key.'_exempt_'.$hostname} = $domconfig{'login'}{$key}{$hostname}{'exempt'};
5170: }
1.946 raeburn 5171: }
5172: }
5173: }
5174: } else {
5175: foreach my $img (keys(%{$domconfig{'login'}{$key}})) {
5176: $designhash{$udom.'.login.'.$key.'_'.$img} =
5177: $domconfig{'login'}{$key}{$img};
5178: }
1.699 raeburn 5179: }
5180: } else {
5181: $designhash{$udom.'.login.'.$key}=$domconfig{'login'}{$key};
5182: }
1.632 raeburn 5183: }
5184: } else {
5185: $legacy{'login'} = 1;
1.518 albertel 5186: }
1.632 raeburn 5187: } else {
5188: $legacy{'login'} = 1;
1.518 albertel 5189: }
5190: if (ref($domconfig{'rolecolors'}) eq 'HASH') {
1.632 raeburn 5191: if (keys(%{$domconfig{'rolecolors'}})) {
5192: foreach my $role (keys(%{$domconfig{'rolecolors'}})) {
5193: if (ref($domconfig{'rolecolors'}{$role}) eq 'HASH') {
5194: foreach my $item (keys(%{$domconfig{'rolecolors'}{$role}})) {
5195: $designhash{$udom.'.'.$role.'.'.$item}=$domconfig{'rolecolors'}{$role}{$item};
5196: }
1.518 albertel 5197: }
5198: }
1.632 raeburn 5199: } else {
5200: $legacy{'rolecolors'} = 1;
1.518 albertel 5201: }
1.632 raeburn 5202: } else {
5203: $legacy{'rolecolors'} = 1;
1.518 albertel 5204: }
1.948 raeburn 5205: if (ref($domconfig{'autoenroll'}) eq 'HASH') {
5206: if ($domconfig{'autoenroll'}{'co-owners'}) {
5207: $designhash{$udom.'.autoassign.co-owners'}=$domconfig{'autoenroll'}{'co-owners'};
5208: }
5209: }
1.632 raeburn 5210: if (keys(%legacy) > 0) {
5211: my %legacyhash = &get_legacy_domconf($udom);
5212: foreach my $item (keys(%legacyhash)) {
5213: if ($item =~ /^\Q$udom\E\.login/) {
5214: if ($legacy{'login'}) {
5215: $designhash{$item} = $legacyhash{$item};
5216: }
5217: } else {
5218: if ($legacy{'rolecolors'}) {
5219: $designhash{$item} = $legacyhash{$item};
5220: }
1.518 albertel 5221: }
5222: }
5223: }
1.632 raeburn 5224: } else {
5225: %designhash = &get_legacy_domconf($udom);
1.518 albertel 5226: }
5227: &Apache::lonnet::do_cache_new('domainconfig',$udom,\%designhash,
5228: $cachetime);
5229: return %designhash;
5230: }
5231:
1.632 raeburn 5232: sub get_legacy_domconf {
5233: my ($udom) = @_;
5234: my %legacyhash;
5235: my $designdir=$Apache::lonnet::perlvar{'lonTabDir'}.'/lonDomColors';
5236: my $designfile = $designdir.'/'.$udom.'.tab';
5237: if (-e $designfile) {
5238: if ( open (my $fh,"<$designfile") ) {
5239: while (my $line = <$fh>) {
5240: next if ($line =~ /^\#/);
5241: chomp($line);
5242: my ($key,$val)=(split(/\=/,$line));
5243: if ($val) { $legacyhash{$udom.'.'.$key}=$val; }
5244: }
5245: close($fh);
5246: }
5247: }
1.1026 raeburn 5248: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/adm/lonDomLogos/'.$udom.'.gif') {
1.632 raeburn 5249: $legacyhash{$udom.'.login.domlogo'} = "/adm/lonDomLogos/$udom.gif";
5250: }
5251: return %legacyhash;
5252: }
5253:
1.63 www 5254: =pod
5255:
1.112 bowersj2 5256: =item * &domainlogo()
1.63 www 5257:
5258: Inputs: $domain (usually will be undef)
5259:
5260: Returns: A link to a domain logo, if the domain logo exists.
5261: If the domain logo does not exist, a description of the domain.
5262:
5263: =cut
1.112 bowersj2 5264:
1.63 www 5265: ###############################################
5266: sub domainlogo {
1.517 raeburn 5267: my $domain = &determinedomain(shift);
1.518 albertel 5268: my %designhash = &get_domainconf($domain);
1.517 raeburn 5269: # See if there is a logo
5270: if ($designhash{$domain.'.login.domlogo'} ne '') {
1.519 raeburn 5271: my $imgsrc = $designhash{$domain.'.login.domlogo'};
1.538 albertel 5272: if ($imgsrc =~ m{^/(adm|res)/}) {
5273: if ($imgsrc =~ m{^/res/}) {
5274: my $local_name = &Apache::lonnet::filelocation('',$imgsrc);
5275: &Apache::lonnet::repcopy($local_name);
5276: }
5277: $imgsrc = &lonhttpdurl($imgsrc);
1.519 raeburn 5278: }
5279: return '<img src="'.$imgsrc.'" alt="'.$domain.'" />';
1.514 albertel 5280: } elsif (defined(&Apache::lonnet::domain($domain,'description'))) {
5281: return &Apache::lonnet::domain($domain,'description');
1.59 www 5282: } else {
1.60 matthew 5283: return '';
1.59 www 5284: }
5285: }
1.63 www 5286: ##############################################
5287:
5288: =pod
5289:
1.112 bowersj2 5290: =item * &designparm()
1.63 www 5291:
5292: Inputs: $which parameter; $domain (usually will be undef)
5293:
5294: Returns: value of designparamter $which
5295:
5296: =cut
1.112 bowersj2 5297:
1.397 albertel 5298:
1.400 albertel 5299: ##############################################
1.397 albertel 5300: sub designparm {
5301: my ($which,$domain)=@_;
5302: if (exists($env{'environment.color.'.$which})) {
1.817 bisitz 5303: return $env{'environment.color.'.$which};
1.96 www 5304: }
1.63 www 5305: $domain=&determinedomain($domain);
1.1016 raeburn 5306: my %domdesign;
5307: unless ($domain eq 'public') {
5308: %domdesign = &get_domainconf($domain);
5309: }
1.520 raeburn 5310: my $output;
1.517 raeburn 5311: if ($domdesign{$domain.'.'.$which} ne '') {
1.817 bisitz 5312: $output = $domdesign{$domain.'.'.$which};
1.63 www 5313: } else {
1.520 raeburn 5314: $output = $defaultdesign{$which};
5315: }
5316: if (($which =~ /^(student|coordinator|author|admin)\.img$/) ||
1.635 raeburn 5317: ($which =~ /login\.(img|logo|domlogo|login)/)) {
1.538 albertel 5318: if ($output =~ m{^/(adm|res)/}) {
1.817 bisitz 5319: if ($output =~ m{^/res/}) {
5320: my $local_name = &Apache::lonnet::filelocation('',$output);
5321: &Apache::lonnet::repcopy($local_name);
5322: }
1.520 raeburn 5323: $output = &lonhttpdurl($output);
5324: }
1.63 www 5325: }
1.520 raeburn 5326: return $output;
1.63 www 5327: }
1.59 www 5328:
1.822 bisitz 5329: ##############################################
5330: =pod
5331:
1.832 bisitz 5332: =item * &authorspace()
5333:
1.1028 raeburn 5334: Inputs: $url (usually will be undef).
1.832 bisitz 5335:
1.1132 raeburn 5336: Returns: Path to Authoring Space containing the resource or
1.1028 raeburn 5337: directory being viewed (or for which action is being taken).
5338: If $url is provided, and begins /priv/<domain>/<uname>
5339: the path will be that portion of the $context argument.
5340: Otherwise the path will be for the author space of the current
5341: user when the current role is author, or for that of the
5342: co-author/assistant co-author space when the current role
5343: is co-author or assistant co-author.
1.832 bisitz 5344:
5345: =cut
5346:
5347: sub authorspace {
1.1028 raeburn 5348: my ($url) = @_;
5349: if ($url ne '') {
5350: if ($url =~ m{^(/priv/$match_domain/$match_username/)}) {
5351: return $1;
5352: }
5353: }
1.832 bisitz 5354: my $caname = '';
1.1024 www 5355: my $cadom = '';
1.1028 raeburn 5356: if ($env{'request.role'} =~ /^(?:ca|aa)/) {
1.1024 www 5357: ($cadom,$caname) =
1.832 bisitz 5358: ($env{'request.role'}=~/($match_domain)\/($match_username)$/);
1.1028 raeburn 5359: } elsif ($env{'request.role'} =~ m{^au\./($match_domain)/}) {
1.832 bisitz 5360: $caname = $env{'user.name'};
1.1024 www 5361: $cadom = $env{'user.domain'};
1.832 bisitz 5362: }
1.1028 raeburn 5363: if (($caname ne '') && ($cadom ne '')) {
5364: return "/priv/$cadom/$caname/";
5365: }
5366: return;
1.832 bisitz 5367: }
5368:
5369: ##############################################
5370: =pod
5371:
1.822 bisitz 5372: =item * &head_subbox()
5373:
5374: Inputs: $content (contains HTML code with page functions, etc.)
5375:
5376: Returns: HTML div with $content
5377: To be included in page header
5378:
5379: =cut
5380:
5381: sub head_subbox {
5382: my ($content)=@_;
5383: my $output =
1.993 raeburn 5384: '<div class="LC_head_subbox">'
1.822 bisitz 5385: .$content
5386: .'</div>'
5387: }
5388:
5389: ##############################################
5390: =pod
5391:
5392: =item * &CSTR_pageheader()
5393:
1.1026 raeburn 5394: Input: (optional) filename from which breadcrumb trail is built.
5395: In most cases no input as needed, as $env{'request.filename'}
5396: is appropriate for use in building the breadcrumb trail.
1.822 bisitz 5397:
5398: Returns: HTML div with CSTR path and recent box
1.1132 raeburn 5399: To be included on Authoring Space pages
1.822 bisitz 5400:
5401: =cut
5402:
5403: sub CSTR_pageheader {
1.1026 raeburn 5404: my ($trailfile) = @_;
5405: if ($trailfile eq '') {
5406: $trailfile = $env{'request.filename'};
5407: }
5408:
5409: # this is for resources; directories have customtitle, and crumbs
5410: # and select recent are created in lonpubdir.pm
5411:
5412: my $londocroot = $Apache::lonnet::perlvar{'lonDocRoot'};
1.1022 www 5413: my ($udom,$uname,$thisdisfn)=
1.1113 raeburn 5414: ($trailfile =~ m{^\Q$londocroot\E/priv/([^/]+)/([^/]+)(?:|/(.*))$});
1.1026 raeburn 5415: my $formaction = "/priv/$udom/$uname/$thisdisfn";
5416: $formaction =~ s{/+}{/}g;
1.822 bisitz 5417:
5418: my $parentpath = '';
5419: my $lastitem = '';
5420: if ($thisdisfn =~ m-(.+/)([^/]*)$-) {
5421: $parentpath = $1;
5422: $lastitem = $2;
5423: } else {
5424: $lastitem = $thisdisfn;
5425: }
1.921 bisitz 5426:
5427: my $output =
1.822 bisitz 5428: '<div>'
5429: .&Apache::loncommon::help_open_menu('','',3,'Authoring') #FIXME: Broken? Where is it?
1.1132 raeburn 5430: .'<b>'.&mt('Authoring Space:').'</b> '
1.822 bisitz 5431: .'<form name="dirs" method="post" action="'.$formaction
1.921 bisitz 5432: .'" target="_top">' #FIXME lonpubdir: target="_parent"
1.1024 www 5433: .&Apache::lonhtmlcommon::crumbs($uname.'/'.$parentpath,'_top','/priv/'.$udom,undef,undef);
1.921 bisitz 5434:
5435: if ($lastitem) {
5436: $output .=
5437: '<span class="LC_filename">'
5438: .$lastitem
5439: .'</span>';
5440: }
5441: $output .=
5442: '<br />'
1.822 bisitz 5443: #FIXME lonpubdir: &Apache::lonhtmlcommon::crumbs($uname.$thisdisfn.'/','_top','/priv','','+1',1)."</b></tt><br />"
5444: .&Apache::lonhtmlcommon::select_recent('construct','recent','this.form.action=this.form.recent.value;this.form.submit()')
5445: .'</form>'
5446: .&Apache::lonmenu::constspaceform()
5447: .'</div>';
1.921 bisitz 5448:
5449: return $output;
1.822 bisitz 5450: }
5451:
1.60 matthew 5452: ###############################################
5453: ###############################################
5454:
5455: =pod
5456:
1.112 bowersj2 5457: =back
5458:
1.549 albertel 5459: =head1 HTML Helpers
1.112 bowersj2 5460:
5461: =over 4
5462:
5463: =item * &bodytag()
1.60 matthew 5464:
5465: Returns a uniform header for LON-CAPA web pages.
5466:
5467: Inputs:
5468:
1.112 bowersj2 5469: =over 4
5470:
5471: =item * $title, A title to be displayed on the page.
5472:
5473: =item * $function, the current role (can be undef).
5474:
5475: =item * $addentries, extra parameters for the <body> tag.
5476:
5477: =item * $bodyonly, if defined, only return the <body> tag.
5478:
5479: =item * $domain, if defined, force a given domain.
5480:
5481: =item * $forcereg, if page should register as content page (relevant for
1.86 www 5482: text interface only)
1.60 matthew 5483:
1.814 bisitz 5484: =item * $no_nav_bar, if true, keep the 'what is this' info but remove the
5485: navigational links
1.317 albertel 5486:
1.338 albertel 5487: =item * $bgcolor, used to override the bgcolor on a webpage to a specific value
5488:
1.460 albertel 5489: =item * $args, optional argument valid values are
5490: no_auto_mt_title -> prevents &mt()ing the title arg
5491:
1.1096 raeburn 5492: =item * $advtoolsref, optional argument, ref to an array containing
5493: inlineremote items to be added in "Functions" menu below
5494: breadcrumbs.
5495:
1.112 bowersj2 5496: =back
5497:
1.60 matthew 5498: Returns: A uniform header for LON-CAPA web pages.
5499: If $bodyonly is nonzero, a string containing a <body> tag will be returned.
5500: If $bodyonly is undef or zero, an html string containing a <body> tag and
5501: other decorations will be returned.
5502:
5503: =cut
5504:
1.54 www 5505: sub bodytag {
1.831 bisitz 5506: my ($title,$function,$addentries,$bodyonly,$domain,$forcereg,
1.1096 raeburn 5507: $no_nav_bar,$bgcolor,$args,$advtoolsref)=@_;
1.339 albertel 5508:
1.954 raeburn 5509: my $public;
5510: if ((($env{'user.name'} eq 'public') && ($env{'user.domain'} eq 'public'))
5511: || ($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
5512: $public = 1;
5513: }
1.460 albertel 5514: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
1.1154 raeburn 5515: my $httphost = $args->{'use_absolute'};
1.339 albertel 5516:
1.183 matthew 5517: $function = &get_users_function() if (!$function);
1.339 albertel 5518: my $img = &designparm($function.'.img',$domain);
5519: my $font = &designparm($function.'.font',$domain);
5520: my $pgbg = $bgcolor || &designparm($function.'.pgbg',$domain);
5521:
1.803 bisitz 5522: my %design = ( 'style' => 'margin-top: 0',
1.535 albertel 5523: 'bgcolor' => $pgbg,
1.339 albertel 5524: 'text' => $font,
5525: 'alink' => &designparm($function.'.alink',$domain),
5526: 'vlink' => &designparm($function.'.vlink',$domain),
5527: 'link' => &designparm($function.'.link',$domain),);
1.438 albertel 5528: @design{keys(%$addentries)} = @$addentries{keys(%$addentries)};
1.339 albertel 5529:
1.63 www 5530: # role and realm
1.1178 raeburn 5531: my ($role,$realm) = split(m{\./},$env{'request.role'},2);
5532: if ($realm) {
5533: $realm = '/'.$realm;
5534: }
1.378 raeburn 5535: if ($role eq 'ca') {
1.479 albertel 5536: my ($rdom,$rname) = ($realm =~ m{^/($match_domain)/($match_username)$});
1.500 albertel 5537: $realm = &plainname($rname,$rdom);
1.378 raeburn 5538: }
1.55 www 5539: # realm
1.258 albertel 5540: if ($env{'request.course.id'}) {
1.378 raeburn 5541: if ($env{'request.role'} !~ /^cr/) {
5542: $role = &Apache::lonnet::plaintext($role,&course_type());
5543: }
1.898 raeburn 5544: if ($env{'request.course.sec'}) {
5545: $role .= (' 'x2).'- '.&mt('section:').' '.$env{'request.course.sec'};
5546: }
1.359 albertel 5547: $realm = $env{'course.'.$env{'request.course.id'}.'.description'};
1.378 raeburn 5548: } else {
5549: $role = &Apache::lonnet::plaintext($role);
1.54 www 5550: }
1.433 albertel 5551:
1.359 albertel 5552: if (!$realm) { $realm=' '; }
1.330 albertel 5553:
1.438 albertel 5554: my $extra_body_attr = &make_attr_string($forcereg,\%design);
1.329 albertel 5555:
1.101 www 5556: # construct main body tag
1.359 albertel 5557: my $bodytag = "<body $extra_body_attr>".
1.1235 raeburn 5558: &Apache::lontexconvert::init_math_support();
1.252 albertel 5559:
1.1131 raeburn 5560: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
5561:
1.1130 raeburn 5562: if (($bodyonly) || ($no_nav_bar) || ($env{'form.inhibitmenu'} eq 'yes')) {
1.60 matthew 5563: return $bodytag;
1.1130 raeburn 5564: }
1.359 albertel 5565:
1.954 raeburn 5566: if ($public) {
1.433 albertel 5567: undef($role);
5568: }
1.359 albertel 5569:
1.762 bisitz 5570: my $titleinfo = '<h1>'.$title.'</h1>';
1.359 albertel 5571: #
5572: # Extra info if you are the DC
5573: my $dc_info = '';
5574: if ($env{'user.adv'} && exists($env{'user.role.dc./'.
5575: $env{'course.'.$env{'request.course.id'}.
5576: '.domain'}.'/'})) {
5577: my $cid = $env{'request.course.id'};
1.917 raeburn 5578: $dc_info = $cid.' '.$env{'course.'.$cid.'.internal.coursecode'};
1.380 www 5579: $dc_info =~ s/\s+$//;
1.359 albertel 5580: }
5581:
1.1237 raeburn 5582: my $crstype;
5583: if ($env{'request.course.id'}) {
5584: $crstype = $env{'course.'.$env{'request.course.id'}.'.type'};
5585: } elsif ($args->{'crstype'}) {
5586: $crstype = $args->{'crstype'};
5587: }
5588: if (($crstype eq 'Placement') && (!$env{'request.role.adv'})) {
5589: undef($role);
5590: } else {
1.1242 ! raeburn 5591: $role = '<span class="LC_nobreak">('.$role.')</span>' if ($role && !$env{'browser.mobile'});
1.1237 raeburn 5592: }
1.853 droeschl 5593:
1.903 droeschl 5594: if ($env{'request.state'} eq 'construct') { $forcereg=1; }
5595:
5596: # if ($env{'request.state'} eq 'construct') {
5597: # $titleinfo = &CSTR_pageheader(); #FIXME: Will be removed once all scripts have their own calls
5598: # }
5599:
1.1130 raeburn 5600: $bodytag .= Apache::lonhtmlcommon::scripttag(
1.1154 raeburn 5601: Apache::lonmenu::utilityfunctions($httphost), 'start');
1.359 albertel 5602:
1.1237 raeburn 5603: my ($left,$right) = Apache::lonmenu::primary_menu($crstype);
1.359 albertel 5604:
1.916 droeschl 5605: if ($env{'request.noversionuri'} =~ m{^/res/adm/pages/}) {
1.917 raeburn 5606: if ($dc_info) {
5607: $dc_info = qq|<span class="LC_cusr_subheading">$dc_info</span>|;
5608: }
1.1130 raeburn 5609: $bodytag .= qq|<div id="LC_nav_bar">$left $role<br />
1.916 droeschl 5610: <em>$realm</em> $dc_info</div>|;
1.903 droeschl 5611: return $bodytag;
5612: }
1.894 droeschl 5613:
1.927 raeburn 5614: unless ($env{'request.symb'} =~ m/\.page___\d+___/) {
1.1130 raeburn 5615: $bodytag .= qq|<div id="LC_nav_bar">$left $role</div>|;
1.927 raeburn 5616: }
1.916 droeschl 5617:
1.1130 raeburn 5618: $bodytag .= $right;
1.852 droeschl 5619:
1.917 raeburn 5620: if ($dc_info) {
5621: $dc_info = &dc_courseid_toggle($dc_info);
5622: }
5623: $bodytag .= qq|<div id="LC_realm">$realm $dc_info</div>|;
1.916 droeschl 5624:
1.1169 raeburn 5625: #if directed to not display the secondary menu, don't.
1.1168 raeburn 5626: if ($args->{'no_secondary_menu'}) {
5627: return $bodytag;
5628: }
1.1169 raeburn 5629: #don't show menus for public users
1.954 raeburn 5630: if (!$public){
1.1154 raeburn 5631: $bodytag .= Apache::lonmenu::secondary_menu($httphost);
1.903 droeschl 5632: $bodytag .= Apache::lonmenu::serverform();
1.920 raeburn 5633: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
5634: if ($env{'request.state'} eq 'construct') {
1.962 droeschl 5635: $bodytag .= &Apache::lonmenu::innerregister($forcereg,
1.920 raeburn 5636: $args->{'bread_crumbs'});
1.1096 raeburn 5637: } elsif ($forcereg) {
5638: $bodytag .= &Apache::lonmenu::innerregister($forcereg,undef,
5639: $args->{'group'});
5640: } else {
5641: $bodytag .=
5642: &Apache::lonmenu::prepare_functions($env{'request.noversionuri'},
5643: $forcereg,$args->{'group'},
5644: $args->{'bread_crumbs'},
5645: $advtoolsref);
1.920 raeburn 5646: }
1.903 droeschl 5647: }else{
5648: # this is to seperate menu from content when there's no secondary
5649: # menu. Especially needed for public accessible ressources.
5650: $bodytag .= '<hr style="clear:both" />';
5651: $bodytag .= Apache::lonhtmlcommon::scripttag('', 'end');
1.235 raeburn 5652: }
1.903 droeschl 5653:
1.235 raeburn 5654: return $bodytag;
1.182 matthew 5655: }
5656:
1.917 raeburn 5657: sub dc_courseid_toggle {
5658: my ($dc_info) = @_;
1.980 raeburn 5659: return ' <span id="dccidtext" class="LC_cusr_subheading LC_nobreak">'.
1.1069 raeburn 5660: '<a href="javascript:showCourseID();" class="LC_menubuttons_link">'.
1.917 raeburn 5661: &mt('(More ...)').'</a></span>'.
5662: '<div id="dccid" class="LC_dccid">'.$dc_info.'</div>';
5663: }
5664:
1.330 albertel 5665: sub make_attr_string {
5666: my ($register,$attr_ref) = @_;
5667:
5668: if ($attr_ref && !ref($attr_ref)) {
5669: die("addentries Must be a hash ref ".
5670: join(':',caller(1))." ".
5671: join(':',caller(0))." ");
5672: }
5673:
5674: if ($register) {
1.339 albertel 5675: my ($on_load,$on_unload);
5676: foreach my $key (keys(%{$attr_ref})) {
5677: if (lc($key) eq 'onload') {
5678: $on_load.=$attr_ref->{$key}.';';
5679: delete($attr_ref->{$key});
5680:
5681: } elsif (lc($key) eq 'onunload') {
5682: $on_unload.=$attr_ref->{$key}.';';
5683: delete($attr_ref->{$key});
5684: }
5685: }
1.953 droeschl 5686: $attr_ref->{'onload'} = $on_load;
5687: $attr_ref->{'onunload'}= $on_unload;
1.330 albertel 5688: }
1.339 albertel 5689:
1.330 albertel 5690: my $attr_string;
1.1159 raeburn 5691: foreach my $attr (sort(keys(%$attr_ref))) {
1.330 albertel 5692: $attr_string .= " $attr=\"".$attr_ref->{$attr}.'" ';
5693: }
5694: return $attr_string;
5695: }
5696:
5697:
1.182 matthew 5698: ###############################################
1.251 albertel 5699: ###############################################
5700:
5701: =pod
5702:
5703: =item * &endbodytag()
5704:
5705: Returns a uniform footer for LON-CAPA web pages.
5706:
1.635 raeburn 5707: Inputs: 1 - optional reference to an args hash
5708: If in the hash, key for noredirectlink has a value which evaluates to true,
5709: a 'Continue' link is not displayed if the page contains an
5710: internal redirect in the <head></head> section,
5711: i.e., $env{'internal.head.redirect'} exists
1.251 albertel 5712:
5713: =cut
5714:
5715: sub endbodytag {
1.635 raeburn 5716: my ($args) = @_;
1.1080 raeburn 5717: my $endbodytag;
5718: unless ((ref($args) eq 'HASH') && ($args->{'notbody'})) {
5719: $endbodytag='</body>';
5720: }
1.315 albertel 5721: if ( exists( $env{'internal.head.redirect'} ) ) {
1.635 raeburn 5722: if (!(ref($args) eq 'HASH' && $args->{'noredirectlink'})) {
5723: $endbodytag=
5724: "<br /><a href=\"$env{'internal.head.redirect'}\">".
5725: &mt('Continue').'</a>'.
5726: $endbodytag;
5727: }
1.315 albertel 5728: }
1.251 albertel 5729: return $endbodytag;
5730: }
5731:
1.352 albertel 5732: =pod
5733:
5734: =item * &standard_css()
5735:
5736: Returns a style sheet
5737:
5738: Inputs: (all optional)
5739: domain -> force to color decorate a page for a specific
5740: domain
5741: function -> force usage of a specific rolish color scheme
5742: bgcolor -> override the default page bgcolor
5743:
5744: =cut
5745:
1.343 albertel 5746: sub standard_css {
1.345 albertel 5747: my ($function,$domain,$bgcolor) = @_;
1.352 albertel 5748: $function = &get_users_function() if (!$function);
5749: my $img = &designparm($function.'.img', $domain);
5750: my $tabbg = &designparm($function.'.tabbg', $domain);
5751: my $font = &designparm($function.'.font', $domain);
1.801 tempelho 5752: my $fontmenu = &designparm($function.'.fontmenu', $domain);
1.791 tempelho 5753: #second colour for later usage
1.345 albertel 5754: my $sidebg = &designparm($function.'.sidebg',$domain);
1.382 albertel 5755: my $pgbg_or_bgcolor =
5756: $bgcolor ||
1.352 albertel 5757: &designparm($function.'.pgbg', $domain);
1.382 albertel 5758: my $pgbg = &designparm($function.'.pgbg', $domain);
1.352 albertel 5759: my $alink = &designparm($function.'.alink', $domain);
5760: my $vlink = &designparm($function.'.vlink', $domain);
5761: my $link = &designparm($function.'.link', $domain);
5762:
1.602 albertel 5763: my $sans = 'Verdana,Arial,Helvetica,sans-serif';
1.395 albertel 5764: my $mono = 'monospace';
1.850 bisitz 5765: my $data_table_head = $sidebg;
5766: my $data_table_light = '#FAFAFA';
1.1060 bisitz 5767: my $data_table_dark = '#E0E0E0';
1.470 banghart 5768: my $data_table_darker = '#CCCCCC';
1.349 albertel 5769: my $data_table_highlight = '#FFFF00';
1.352 albertel 5770: my $mail_new = '#FFBB77';
5771: my $mail_new_hover = '#DD9955';
5772: my $mail_read = '#BBBB77';
5773: my $mail_read_hover = '#999944';
5774: my $mail_replied = '#AAAA88';
5775: my $mail_replied_hover = '#888855';
5776: my $mail_other = '#99BBBB';
5777: my $mail_other_hover = '#669999';
1.391 albertel 5778: my $table_header = '#DDDDDD';
1.489 raeburn 5779: my $feedback_link_bg = '#BBBBBB';
1.911 bisitz 5780: my $lg_border_color = '#C8C8C8';
1.952 onken 5781: my $button_hover = '#BF2317';
1.392 albertel 5782:
1.608 albertel 5783: my $border = ($env{'browser.type'} eq 'explorer' ||
1.911 bisitz 5784: $env{'browser.type'} eq 'safari' ) ? '0 2px 0 2px'
5785: : '0 3px 0 4px';
1.448 albertel 5786:
1.523 albertel 5787:
1.343 albertel 5788: return <<END;
1.947 droeschl 5789:
5790: /* needed for iframe to allow 100% height in FF */
5791: body, html {
5792: margin: 0;
5793: padding: 0 0.5%;
5794: height: 99%; /* to avoid scrollbars */
5795: }
5796:
1.795 www 5797: body {
1.911 bisitz 5798: font-family: $sans;
5799: line-height:130%;
5800: font-size:0.83em;
5801: color:$font;
1.795 www 5802: }
5803:
1.959 onken 5804: a:focus,
5805: a:focus img {
1.795 www 5806: color: red;
5807: }
1.698 harmsja 5808:
1.911 bisitz 5809: form, .inline {
5810: display: inline;
1.795 www 5811: }
1.721 harmsja 5812:
1.795 www 5813: .LC_right {
1.911 bisitz 5814: text-align:right;
1.795 www 5815: }
5816:
5817: .LC_middle {
1.911 bisitz 5818: vertical-align:middle;
1.795 www 5819: }
1.721 harmsja 5820:
1.1130 raeburn 5821: .LC_floatleft {
5822: float: left;
5823: }
5824:
5825: .LC_floatright {
5826: float: right;
5827: }
5828:
1.911 bisitz 5829: .LC_400Box {
5830: width:400px;
5831: }
1.721 harmsja 5832:
1.947 droeschl 5833: .LC_iframecontainer {
5834: width: 98%;
5835: margin: 0;
5836: position: fixed;
5837: top: 8.5em;
5838: bottom: 0;
5839: }
5840:
5841: .LC_iframecontainer iframe{
5842: border: none;
5843: width: 100%;
5844: height: 100%;
5845: }
5846:
1.778 bisitz 5847: .LC_filename {
5848: font-family: $mono;
5849: white-space:pre;
1.921 bisitz 5850: font-size: 120%;
1.778 bisitz 5851: }
5852:
5853: .LC_fileicon {
5854: border: none;
5855: height: 1.3em;
5856: vertical-align: text-bottom;
5857: margin-right: 0.3em;
5858: text-decoration:none;
5859: }
5860:
1.1008 www 5861: .LC_setting {
5862: text-decoration:underline;
5863: }
5864:
1.350 albertel 5865: .LC_error {
5866: color: red;
5867: }
1.795 www 5868:
1.1097 bisitz 5869: .LC_warning {
5870: color: darkorange;
5871: }
5872:
1.457 albertel 5873: .LC_diff_removed {
1.733 bisitz 5874: color: red;
1.394 albertel 5875: }
1.532 albertel 5876:
5877: .LC_info,
1.457 albertel 5878: .LC_success,
5879: .LC_diff_added {
1.350 albertel 5880: color: green;
5881: }
1.795 www 5882:
1.802 bisitz 5883: div.LC_confirm_box {
5884: background-color: #FAFAFA;
5885: border: 1px solid $lg_border_color;
5886: margin-right: 0;
5887: padding: 5px;
5888: }
5889:
5890: div.LC_confirm_box .LC_error img,
5891: div.LC_confirm_box .LC_success img {
5892: vertical-align: middle;
5893: }
5894:
1.1242 ! raeburn 5895: .LC_maxwidth {
! 5896: max-width: 100%;
! 5897: height: auto;
! 5898: }
! 5899:
1.440 albertel 5900: .LC_icon {
1.771 droeschl 5901: border: none;
1.790 droeschl 5902: vertical-align: middle;
1.771 droeschl 5903: }
5904:
1.543 albertel 5905: .LC_docs_spacer {
5906: width: 25px;
5907: height: 1px;
1.771 droeschl 5908: border: none;
1.543 albertel 5909: }
1.346 albertel 5910:
1.532 albertel 5911: .LC_internal_info {
1.735 bisitz 5912: color: #999999;
1.532 albertel 5913: }
5914:
1.794 www 5915: .LC_discussion {
1.1050 www 5916: background: $data_table_dark;
1.911 bisitz 5917: border: 1px solid black;
5918: margin: 2px;
1.794 www 5919: }
5920:
5921: .LC_disc_action_left {
1.1050 www 5922: background: $sidebg;
1.911 bisitz 5923: text-align: left;
1.1050 www 5924: padding: 4px;
5925: margin: 2px;
1.794 www 5926: }
5927:
5928: .LC_disc_action_right {
1.1050 www 5929: background: $sidebg;
1.911 bisitz 5930: text-align: right;
1.1050 www 5931: padding: 4px;
5932: margin: 2px;
1.794 www 5933: }
5934:
5935: .LC_disc_new_item {
1.911 bisitz 5936: background: white;
5937: border: 2px solid red;
1.1050 www 5938: margin: 4px;
5939: padding: 4px;
1.794 www 5940: }
5941:
5942: .LC_disc_old_item {
1.911 bisitz 5943: background: white;
1.1050 www 5944: margin: 4px;
5945: padding: 4px;
1.794 www 5946: }
5947:
1.458 albertel 5948: table.LC_pastsubmission {
5949: border: 1px solid black;
5950: margin: 2px;
5951: }
5952:
1.924 bisitz 5953: table#LC_menubuttons {
1.345 albertel 5954: width: 100%;
5955: background: $pgbg;
1.392 albertel 5956: border: 2px;
1.402 albertel 5957: border-collapse: separate;
1.803 bisitz 5958: padding: 0;
1.345 albertel 5959: }
1.392 albertel 5960:
1.801 tempelho 5961: table#LC_title_bar a {
5962: color: $fontmenu;
5963: }
1.836 bisitz 5964:
1.807 droeschl 5965: table#LC_title_bar {
1.819 tempelho 5966: clear: both;
1.836 bisitz 5967: display: none;
1.807 droeschl 5968: }
5969:
1.795 www 5970: table#LC_title_bar,
1.933 droeschl 5971: table.LC_breadcrumbs, /* obsolete? */
1.393 albertel 5972: table#LC_title_bar.LC_with_remote {
1.359 albertel 5973: width: 100%;
1.392 albertel 5974: border-color: $pgbg;
5975: border-style: solid;
5976: border-width: $border;
1.379 albertel 5977: background: $pgbg;
1.801 tempelho 5978: color: $fontmenu;
1.392 albertel 5979: border-collapse: collapse;
1.803 bisitz 5980: padding: 0;
1.819 tempelho 5981: margin: 0;
1.359 albertel 5982: }
1.795 www 5983:
1.933 droeschl 5984: ul.LC_breadcrumb_tools_outerlist {
1.913 droeschl 5985: margin: 0;
5986: padding: 0;
1.933 droeschl 5987: position: relative;
5988: list-style: none;
1.913 droeschl 5989: }
1.933 droeschl 5990: ul.LC_breadcrumb_tools_outerlist li {
1.913 droeschl 5991: display: inline;
5992: }
1.933 droeschl 5993:
5994: .LC_breadcrumb_tools_navigation {
1.913 droeschl 5995: padding: 0;
1.933 droeschl 5996: margin: 0;
5997: float: left;
1.913 droeschl 5998: }
1.933 droeschl 5999: .LC_breadcrumb_tools_tools {
6000: padding: 0;
6001: margin: 0;
1.913 droeschl 6002: float: right;
6003: }
6004:
1.1240 raeburn 6005: .LC_placement_prog {
6006: padding-right: 20px;
6007: font-weight: bold;
6008: font-size: 90%;
6009: }
6010:
1.359 albertel 6011: table#LC_title_bar td {
6012: background: $tabbg;
6013: }
1.795 www 6014:
1.911 bisitz 6015: table#LC_menubuttons img {
1.803 bisitz 6016: border: none;
1.346 albertel 6017: }
1.795 www 6018:
1.842 droeschl 6019: .LC_breadcrumbs_component {
1.911 bisitz 6020: float: right;
6021: margin: 0 1em;
1.357 albertel 6022: }
1.842 droeschl 6023: .LC_breadcrumbs_component img {
1.911 bisitz 6024: vertical-align: middle;
1.777 tempelho 6025: }
1.795 www 6026:
1.383 albertel 6027: td.LC_table_cell_checkbox {
6028: text-align: center;
6029: }
1.795 www 6030:
6031: .LC_fontsize_small {
1.911 bisitz 6032: font-size: 70%;
1.705 tempelho 6033: }
6034:
1.844 bisitz 6035: #LC_breadcrumbs {
1.911 bisitz 6036: clear:both;
6037: background: $sidebg;
6038: border-bottom: 1px solid $lg_border_color;
6039: line-height: 2.5em;
1.933 droeschl 6040: overflow: hidden;
1.911 bisitz 6041: margin: 0;
6042: padding: 0;
1.995 raeburn 6043: text-align: left;
1.819 tempelho 6044: }
1.862 bisitz 6045:
1.1098 bisitz 6046: .LC_head_subbox, .LC_actionbox {
1.911 bisitz 6047: clear:both;
6048: background: #F8F8F8; /* $sidebg; */
1.915 droeschl 6049: border: 1px solid $sidebg;
1.1098 bisitz 6050: margin: 0 0 10px 0;
1.966 bisitz 6051: padding: 3px;
1.995 raeburn 6052: text-align: left;
1.822 bisitz 6053: }
6054:
1.795 www 6055: .LC_fontsize_medium {
1.911 bisitz 6056: font-size: 85%;
1.705 tempelho 6057: }
6058:
1.795 www 6059: .LC_fontsize_large {
1.911 bisitz 6060: font-size: 120%;
1.705 tempelho 6061: }
6062:
1.346 albertel 6063: .LC_menubuttons_inline_text {
6064: color: $font;
1.698 harmsja 6065: font-size: 90%;
1.701 harmsja 6066: padding-left:3px;
1.346 albertel 6067: }
6068:
1.934 droeschl 6069: .LC_menubuttons_inline_text img{
6070: vertical-align: middle;
6071: }
6072:
1.1051 www 6073: li.LC_menubuttons_inline_text img {
1.951 onken 6074: cursor:pointer;
1.1002 droeschl 6075: text-decoration: none;
1.951 onken 6076: }
6077:
1.526 www 6078: .LC_menubuttons_link {
6079: text-decoration: none;
6080: }
1.795 www 6081:
1.522 albertel 6082: .LC_menubuttons_category {
1.521 www 6083: color: $font;
1.526 www 6084: background: $pgbg;
1.521 www 6085: font-size: larger;
6086: font-weight: bold;
6087: }
6088:
1.346 albertel 6089: td.LC_menubuttons_text {
1.911 bisitz 6090: color: $font;
1.346 albertel 6091: }
1.706 harmsja 6092:
1.346 albertel 6093: .LC_current_location {
6094: background: $tabbg;
6095: }
1.795 www 6096:
1.938 bisitz 6097: table.LC_data_table {
1.347 albertel 6098: border: 1px solid #000000;
1.402 albertel 6099: border-collapse: separate;
1.426 albertel 6100: border-spacing: 1px;
1.610 albertel 6101: background: $pgbg;
1.347 albertel 6102: }
1.795 www 6103:
1.422 albertel 6104: .LC_data_table_dense {
6105: font-size: small;
6106: }
1.795 www 6107:
1.507 raeburn 6108: table.LC_nested_outer {
6109: border: 1px solid #000000;
1.589 raeburn 6110: border-collapse: collapse;
1.803 bisitz 6111: border-spacing: 0;
1.507 raeburn 6112: width: 100%;
6113: }
1.795 www 6114:
1.879 raeburn 6115: table.LC_innerpickbox,
1.507 raeburn 6116: table.LC_nested {
1.803 bisitz 6117: border: none;
1.589 raeburn 6118: border-collapse: collapse;
1.803 bisitz 6119: border-spacing: 0;
1.507 raeburn 6120: width: 100%;
6121: }
1.795 www 6122:
1.911 bisitz 6123: table.LC_data_table tr th,
6124: table.LC_calendar tr th,
1.879 raeburn 6125: table.LC_prior_tries tr th,
6126: table.LC_innerpickbox tr th {
1.349 albertel 6127: font-weight: bold;
6128: background-color: $data_table_head;
1.801 tempelho 6129: color:$fontmenu;
1.701 harmsja 6130: font-size:90%;
1.347 albertel 6131: }
1.795 www 6132:
1.879 raeburn 6133: table.LC_innerpickbox tr th,
6134: table.LC_innerpickbox tr td {
6135: vertical-align: top;
6136: }
6137:
1.711 raeburn 6138: table.LC_data_table tr.LC_info_row > td {
1.735 bisitz 6139: background-color: #CCCCCC;
1.711 raeburn 6140: font-weight: bold;
6141: text-align: left;
6142: }
1.795 www 6143:
1.912 bisitz 6144: table.LC_data_table tr.LC_odd_row > td {
6145: background-color: $data_table_light;
6146: padding: 2px;
6147: vertical-align: top;
6148: }
6149:
1.809 bisitz 6150: table.LC_pick_box tr > td.LC_odd_row {
1.349 albertel 6151: background-color: $data_table_light;
1.912 bisitz 6152: vertical-align: top;
6153: }
6154:
6155: table.LC_data_table tr.LC_even_row > td {
6156: background-color: $data_table_dark;
1.425 albertel 6157: padding: 2px;
1.900 bisitz 6158: vertical-align: top;
1.347 albertel 6159: }
1.795 www 6160:
1.809 bisitz 6161: table.LC_pick_box tr > td.LC_even_row {
1.349 albertel 6162: background-color: $data_table_dark;
1.900 bisitz 6163: vertical-align: top;
1.347 albertel 6164: }
1.795 www 6165:
1.425 albertel 6166: table.LC_data_table tr.LC_data_table_highlight td {
6167: background-color: $data_table_darker;
6168: }
1.795 www 6169:
1.639 raeburn 6170: table.LC_data_table tr td.LC_leftcol_header {
6171: background-color: $data_table_head;
6172: font-weight: bold;
6173: }
1.795 www 6174:
1.451 albertel 6175: table.LC_data_table tr.LC_empty_row td,
1.507 raeburn 6176: table.LC_nested tr.LC_empty_row td {
1.421 albertel 6177: font-weight: bold;
6178: font-style: italic;
6179: text-align: center;
6180: padding: 8px;
1.347 albertel 6181: }
1.795 www 6182:
1.1114 raeburn 6183: table.LC_data_table tr.LC_empty_row td,
6184: table.LC_data_table tr.LC_footer_row td {
1.940 bisitz 6185: background-color: $sidebg;
6186: }
6187:
6188: table.LC_nested tr.LC_empty_row td {
6189: background-color: #FFFFFF;
6190: }
6191:
1.890 droeschl 6192: table.LC_caption {
6193: }
6194:
1.507 raeburn 6195: table.LC_nested tr.LC_empty_row td {
1.465 albertel 6196: padding: 4ex
6197: }
1.795 www 6198:
1.507 raeburn 6199: table.LC_nested_outer tr th {
6200: font-weight: bold;
1.801 tempelho 6201: color:$fontmenu;
1.507 raeburn 6202: background-color: $data_table_head;
1.701 harmsja 6203: font-size: small;
1.507 raeburn 6204: border-bottom: 1px solid #000000;
6205: }
1.795 www 6206:
1.507 raeburn 6207: table.LC_nested_outer tr td.LC_subheader {
6208: background-color: $data_table_head;
6209: font-weight: bold;
6210: font-size: small;
6211: border-bottom: 1px solid #000000;
6212: text-align: right;
1.451 albertel 6213: }
1.795 www 6214:
1.507 raeburn 6215: table.LC_nested tr.LC_info_row td {
1.735 bisitz 6216: background-color: #CCCCCC;
1.451 albertel 6217: font-weight: bold;
6218: font-size: small;
1.507 raeburn 6219: text-align: center;
6220: }
1.795 www 6221:
1.589 raeburn 6222: table.LC_nested tr.LC_info_row td.LC_left_item,
6223: table.LC_nested_outer tr th.LC_left_item {
1.507 raeburn 6224: text-align: left;
1.451 albertel 6225: }
1.795 www 6226:
1.507 raeburn 6227: table.LC_nested td {
1.735 bisitz 6228: background-color: #FFFFFF;
1.451 albertel 6229: font-size: small;
1.507 raeburn 6230: }
1.795 www 6231:
1.507 raeburn 6232: table.LC_nested_outer tr th.LC_right_item,
6233: table.LC_nested tr.LC_info_row td.LC_right_item,
6234: table.LC_nested tr.LC_odd_row td.LC_right_item,
6235: table.LC_nested tr td.LC_right_item {
1.451 albertel 6236: text-align: right;
6237: }
6238:
1.507 raeburn 6239: table.LC_nested tr.LC_odd_row td {
1.735 bisitz 6240: background-color: #EEEEEE;
1.451 albertel 6241: }
6242:
1.473 raeburn 6243: table.LC_createuser {
6244: }
6245:
6246: table.LC_createuser tr.LC_section_row td {
1.701 harmsja 6247: font-size: small;
1.473 raeburn 6248: }
6249:
6250: table.LC_createuser tr.LC_info_row td {
1.735 bisitz 6251: background-color: #CCCCCC;
1.473 raeburn 6252: font-weight: bold;
6253: text-align: center;
6254: }
6255:
1.349 albertel 6256: table.LC_calendar {
6257: border: 1px solid #000000;
6258: border-collapse: collapse;
1.917 raeburn 6259: width: 98%;
1.349 albertel 6260: }
1.795 www 6261:
1.349 albertel 6262: table.LC_calendar_pickdate {
6263: font-size: xx-small;
6264: }
1.795 www 6265:
1.349 albertel 6266: table.LC_calendar tr td {
6267: border: 1px solid #000000;
6268: vertical-align: top;
1.917 raeburn 6269: width: 14%;
1.349 albertel 6270: }
1.795 www 6271:
1.349 albertel 6272: table.LC_calendar tr td.LC_calendar_day_empty {
6273: background-color: $data_table_dark;
6274: }
1.795 www 6275:
1.779 bisitz 6276: table.LC_calendar tr td.LC_calendar_day_current {
6277: background-color: $data_table_highlight;
1.777 tempelho 6278: }
1.795 www 6279:
1.938 bisitz 6280: table.LC_data_table tr td.LC_mail_new {
1.349 albertel 6281: background-color: $mail_new;
6282: }
1.795 www 6283:
1.938 bisitz 6284: table.LC_data_table tr.LC_mail_new:hover {
1.349 albertel 6285: background-color: $mail_new_hover;
6286: }
1.795 www 6287:
1.938 bisitz 6288: table.LC_data_table tr td.LC_mail_read {
1.349 albertel 6289: background-color: $mail_read;
6290: }
1.795 www 6291:
1.938 bisitz 6292: /*
6293: table.LC_data_table tr.LC_mail_read:hover {
1.349 albertel 6294: background-color: $mail_read_hover;
6295: }
1.938 bisitz 6296: */
1.795 www 6297:
1.938 bisitz 6298: table.LC_data_table tr td.LC_mail_replied {
1.349 albertel 6299: background-color: $mail_replied;
6300: }
1.795 www 6301:
1.938 bisitz 6302: /*
6303: table.LC_data_table tr.LC_mail_replied:hover {
1.349 albertel 6304: background-color: $mail_replied_hover;
6305: }
1.938 bisitz 6306: */
1.795 www 6307:
1.938 bisitz 6308: table.LC_data_table tr td.LC_mail_other {
1.349 albertel 6309: background-color: $mail_other;
6310: }
1.795 www 6311:
1.938 bisitz 6312: /*
6313: table.LC_data_table tr.LC_mail_other:hover {
1.349 albertel 6314: background-color: $mail_other_hover;
6315: }
1.938 bisitz 6316: */
1.494 raeburn 6317:
1.777 tempelho 6318: table.LC_data_table tr > td.LC_browser_file,
6319: table.LC_data_table tr > td.LC_browser_file_published {
1.899 bisitz 6320: background: #AAEE77;
1.389 albertel 6321: }
1.795 www 6322:
1.777 tempelho 6323: table.LC_data_table tr > td.LC_browser_file_locked,
6324: table.LC_data_table tr > td.LC_browser_file_unpublished {
1.389 albertel 6325: background: #FFAA99;
1.387 albertel 6326: }
1.795 www 6327:
1.777 tempelho 6328: table.LC_data_table tr > td.LC_browser_file_obsolete {
1.899 bisitz 6329: background: #888888;
1.779 bisitz 6330: }
1.795 www 6331:
1.777 tempelho 6332: table.LC_data_table tr > td.LC_browser_file_modified,
1.779 bisitz 6333: table.LC_data_table tr > td.LC_browser_file_metamodified {
1.899 bisitz 6334: background: #F8F866;
1.777 tempelho 6335: }
1.795 www 6336:
1.696 bisitz 6337: table.LC_data_table tr.LC_browser_folder > td {
1.899 bisitz 6338: background: #E0E8FF;
1.387 albertel 6339: }
1.696 bisitz 6340:
1.707 bisitz 6341: table.LC_data_table tr > td.LC_roles_is {
1.911 bisitz 6342: /* background: #77FF77; */
1.707 bisitz 6343: }
1.795 www 6344:
1.707 bisitz 6345: table.LC_data_table tr > td.LC_roles_future {
1.939 bisitz 6346: border-right: 8px solid #FFFF77;
1.707 bisitz 6347: }
1.795 www 6348:
1.707 bisitz 6349: table.LC_data_table tr > td.LC_roles_will {
1.939 bisitz 6350: border-right: 8px solid #FFAA77;
1.707 bisitz 6351: }
1.795 www 6352:
1.707 bisitz 6353: table.LC_data_table tr > td.LC_roles_expired {
1.939 bisitz 6354: border-right: 8px solid #FF7777;
1.707 bisitz 6355: }
1.795 www 6356:
1.707 bisitz 6357: table.LC_data_table tr > td.LC_roles_will_not {
1.939 bisitz 6358: border-right: 8px solid #AAFF77;
1.707 bisitz 6359: }
1.795 www 6360:
1.707 bisitz 6361: table.LC_data_table tr > td.LC_roles_selected {
1.939 bisitz 6362: border-right: 8px solid #11CC55;
1.707 bisitz 6363: }
6364:
1.388 albertel 6365: span.LC_current_location {
1.701 harmsja 6366: font-size:larger;
1.388 albertel 6367: background: $pgbg;
6368: }
1.387 albertel 6369:
1.1029 www 6370: span.LC_current_nav_location {
6371: font-weight:bold;
6372: background: $sidebg;
6373: }
6374:
1.395 albertel 6375: span.LC_parm_menu_item {
6376: font-size: larger;
6377: }
1.795 www 6378:
1.395 albertel 6379: span.LC_parm_scope_all {
6380: color: red;
6381: }
1.795 www 6382:
1.395 albertel 6383: span.LC_parm_scope_folder {
6384: color: green;
6385: }
1.795 www 6386:
1.395 albertel 6387: span.LC_parm_scope_resource {
6388: color: orange;
6389: }
1.795 www 6390:
1.395 albertel 6391: span.LC_parm_part {
6392: color: blue;
6393: }
1.795 www 6394:
1.911 bisitz 6395: span.LC_parm_folder,
6396: span.LC_parm_symb {
1.395 albertel 6397: font-size: x-small;
6398: font-family: $mono;
6399: color: #AAAAAA;
6400: }
6401:
1.977 bisitz 6402: ul.LC_parm_parmlist li {
6403: display: inline-block;
6404: padding: 0.3em 0.8em;
6405: vertical-align: top;
6406: width: 150px;
6407: border-top:1px solid $lg_border_color;
6408: }
6409:
1.795 www 6410: td.LC_parm_overview_level_menu,
6411: td.LC_parm_overview_map_menu,
6412: td.LC_parm_overview_parm_selectors,
6413: td.LC_parm_overview_restrictions {
1.396 albertel 6414: border: 1px solid black;
6415: border-collapse: collapse;
6416: }
1.795 www 6417:
1.396 albertel 6418: table.LC_parm_overview_restrictions td {
6419: border-width: 1px 4px 1px 4px;
6420: border-style: solid;
6421: border-color: $pgbg;
6422: text-align: center;
6423: }
1.795 www 6424:
1.396 albertel 6425: table.LC_parm_overview_restrictions th {
6426: background: $tabbg;
6427: border-width: 1px 4px 1px 4px;
6428: border-style: solid;
6429: border-color: $pgbg;
6430: }
1.795 www 6431:
1.398 albertel 6432: table#LC_helpmenu {
1.803 bisitz 6433: border: none;
1.398 albertel 6434: height: 55px;
1.803 bisitz 6435: border-spacing: 0;
1.398 albertel 6436: }
6437:
6438: table#LC_helpmenu fieldset legend {
6439: font-size: larger;
6440: }
1.795 www 6441:
1.397 albertel 6442: table#LC_helpmenu_links {
6443: width: 100%;
6444: border: 1px solid black;
6445: background: $pgbg;
1.803 bisitz 6446: padding: 0;
1.397 albertel 6447: border-spacing: 1px;
6448: }
1.795 www 6449:
1.397 albertel 6450: table#LC_helpmenu_links tr td {
6451: padding: 1px;
6452: background: $tabbg;
1.399 albertel 6453: text-align: center;
6454: font-weight: bold;
1.397 albertel 6455: }
1.396 albertel 6456:
1.795 www 6457: table#LC_helpmenu_links a:link,
6458: table#LC_helpmenu_links a:visited,
1.397 albertel 6459: table#LC_helpmenu_links a:active {
6460: text-decoration: none;
6461: color: $font;
6462: }
1.795 www 6463:
1.397 albertel 6464: table#LC_helpmenu_links a:hover {
6465: text-decoration: underline;
6466: color: $vlink;
6467: }
1.396 albertel 6468:
1.417 albertel 6469: .LC_chrt_popup_exists {
6470: border: 1px solid #339933;
6471: margin: -1px;
6472: }
1.795 www 6473:
1.417 albertel 6474: .LC_chrt_popup_up {
6475: border: 1px solid yellow;
6476: margin: -1px;
6477: }
1.795 www 6478:
1.417 albertel 6479: .LC_chrt_popup {
6480: border: 1px solid #8888FF;
6481: background: #CCCCFF;
6482: }
1.795 www 6483:
1.421 albertel 6484: table.LC_pick_box {
6485: border-collapse: separate;
6486: background: white;
6487: border: 1px solid black;
6488: border-spacing: 1px;
6489: }
1.795 www 6490:
1.421 albertel 6491: table.LC_pick_box td.LC_pick_box_title {
1.850 bisitz 6492: background: $sidebg;
1.421 albertel 6493: font-weight: bold;
1.900 bisitz 6494: text-align: left;
1.740 bisitz 6495: vertical-align: top;
1.421 albertel 6496: width: 184px;
6497: padding: 8px;
6498: }
1.795 www 6499:
1.579 raeburn 6500: table.LC_pick_box td.LC_pick_box_value {
6501: text-align: left;
6502: padding: 8px;
6503: }
1.795 www 6504:
1.579 raeburn 6505: table.LC_pick_box td.LC_pick_box_select {
6506: text-align: left;
6507: padding: 8px;
6508: }
1.795 www 6509:
1.424 albertel 6510: table.LC_pick_box td.LC_pick_box_separator {
1.803 bisitz 6511: padding: 0;
1.421 albertel 6512: height: 1px;
6513: background: black;
6514: }
1.795 www 6515:
1.421 albertel 6516: table.LC_pick_box td.LC_pick_box_submit {
6517: text-align: right;
6518: }
1.795 www 6519:
1.579 raeburn 6520: table.LC_pick_box td.LC_evenrow_value {
6521: text-align: left;
6522: padding: 8px;
6523: background-color: $data_table_light;
6524: }
1.795 www 6525:
1.579 raeburn 6526: table.LC_pick_box td.LC_oddrow_value {
6527: text-align: left;
6528: padding: 8px;
6529: background-color: $data_table_light;
6530: }
1.795 www 6531:
1.579 raeburn 6532: span.LC_helpform_receipt_cat {
6533: font-weight: bold;
6534: }
1.795 www 6535:
1.424 albertel 6536: table.LC_group_priv_box {
6537: background: white;
6538: border: 1px solid black;
6539: border-spacing: 1px;
6540: }
1.795 www 6541:
1.424 albertel 6542: table.LC_group_priv_box td.LC_pick_box_title {
6543: background: $tabbg;
6544: font-weight: bold;
6545: text-align: right;
6546: width: 184px;
6547: }
1.795 www 6548:
1.424 albertel 6549: table.LC_group_priv_box td.LC_groups_fixed {
6550: background: $data_table_light;
6551: text-align: center;
6552: }
1.795 www 6553:
1.424 albertel 6554: table.LC_group_priv_box td.LC_groups_optional {
6555: background: $data_table_dark;
6556: text-align: center;
6557: }
1.795 www 6558:
1.424 albertel 6559: table.LC_group_priv_box td.LC_groups_functionality {
6560: background: $data_table_darker;
6561: text-align: center;
6562: font-weight: bold;
6563: }
1.795 www 6564:
1.424 albertel 6565: table.LC_group_priv td {
6566: text-align: left;
1.803 bisitz 6567: padding: 0;
1.424 albertel 6568: }
6569:
6570: .LC_navbuttons {
6571: margin: 2ex 0ex 2ex 0ex;
6572: }
1.795 www 6573:
1.423 albertel 6574: .LC_topic_bar {
6575: font-weight: bold;
6576: background: $tabbg;
1.918 wenzelju 6577: margin: 1em 0em 1em 2em;
1.805 bisitz 6578: padding: 3px;
1.918 wenzelju 6579: font-size: 1.2em;
1.423 albertel 6580: }
1.795 www 6581:
1.423 albertel 6582: .LC_topic_bar span {
1.918 wenzelju 6583: left: 0.5em;
6584: position: absolute;
1.423 albertel 6585: vertical-align: middle;
1.918 wenzelju 6586: font-size: 1.2em;
1.423 albertel 6587: }
1.795 www 6588:
1.423 albertel 6589: table.LC_course_group_status {
6590: margin: 20px;
6591: }
1.795 www 6592:
1.423 albertel 6593: table.LC_status_selector td {
6594: vertical-align: top;
6595: text-align: center;
1.424 albertel 6596: padding: 4px;
6597: }
1.795 www 6598:
1.599 albertel 6599: div.LC_feedback_link {
1.616 albertel 6600: clear: both;
1.829 kalberla 6601: background: $sidebg;
1.779 bisitz 6602: width: 100%;
1.829 kalberla 6603: padding-bottom: 10px;
6604: border: 1px $tabbg solid;
1.833 kalberla 6605: height: 22px;
6606: line-height: 22px;
6607: padding-top: 5px;
6608: }
6609:
6610: div.LC_feedback_link img {
6611: height: 22px;
1.867 kalberla 6612: vertical-align:middle;
1.829 kalberla 6613: }
6614:
1.911 bisitz 6615: div.LC_feedback_link a {
1.829 kalberla 6616: text-decoration: none;
1.489 raeburn 6617: }
1.795 www 6618:
1.867 kalberla 6619: div.LC_comblock {
1.911 bisitz 6620: display:inline;
1.867 kalberla 6621: color:$font;
6622: font-size:90%;
6623: }
6624:
6625: div.LC_feedback_link div.LC_comblock {
6626: padding-left:5px;
6627: }
6628:
6629: div.LC_feedback_link div.LC_comblock a {
6630: color:$font;
6631: }
6632:
1.489 raeburn 6633: span.LC_feedback_link {
1.858 bisitz 6634: /* background: $feedback_link_bg; */
1.599 albertel 6635: font-size: larger;
6636: }
1.795 www 6637:
1.599 albertel 6638: span.LC_message_link {
1.858 bisitz 6639: /* background: $feedback_link_bg; */
1.599 albertel 6640: font-size: larger;
6641: position: absolute;
6642: right: 1em;
1.489 raeburn 6643: }
1.421 albertel 6644:
1.515 albertel 6645: table.LC_prior_tries {
1.524 albertel 6646: border: 1px solid #000000;
6647: border-collapse: separate;
6648: border-spacing: 1px;
1.515 albertel 6649: }
1.523 albertel 6650:
1.515 albertel 6651: table.LC_prior_tries td {
1.524 albertel 6652: padding: 2px;
1.515 albertel 6653: }
1.523 albertel 6654:
6655: .LC_answer_correct {
1.795 www 6656: background: lightgreen;
6657: color: darkgreen;
6658: padding: 6px;
1.523 albertel 6659: }
1.795 www 6660:
1.523 albertel 6661: .LC_answer_charged_try {
1.797 www 6662: background: #FFAAAA;
1.795 www 6663: color: darkred;
6664: padding: 6px;
1.523 albertel 6665: }
1.795 www 6666:
1.779 bisitz 6667: .LC_answer_not_charged_try,
1.523 albertel 6668: .LC_answer_no_grade,
6669: .LC_answer_late {
1.795 www 6670: background: lightyellow;
1.523 albertel 6671: color: black;
1.795 www 6672: padding: 6px;
1.523 albertel 6673: }
1.795 www 6674:
1.523 albertel 6675: .LC_answer_previous {
1.795 www 6676: background: lightblue;
6677: color: darkblue;
6678: padding: 6px;
1.523 albertel 6679: }
1.795 www 6680:
1.779 bisitz 6681: .LC_answer_no_message {
1.777 tempelho 6682: background: #FFFFFF;
6683: color: black;
1.795 www 6684: padding: 6px;
1.779 bisitz 6685: }
1.795 www 6686:
1.779 bisitz 6687: .LC_answer_unknown {
6688: background: orange;
6689: color: black;
1.795 www 6690: padding: 6px;
1.777 tempelho 6691: }
1.795 www 6692:
1.529 albertel 6693: span.LC_prior_numerical,
6694: span.LC_prior_string,
6695: span.LC_prior_custom,
6696: span.LC_prior_reaction,
6697: span.LC_prior_math {
1.925 bisitz 6698: font-family: $mono;
1.523 albertel 6699: white-space: pre;
6700: }
6701:
1.525 albertel 6702: span.LC_prior_string {
1.925 bisitz 6703: font-family: $mono;
1.525 albertel 6704: white-space: pre;
6705: }
6706:
1.523 albertel 6707: table.LC_prior_option {
6708: width: 100%;
6709: border-collapse: collapse;
6710: }
1.795 www 6711:
1.911 bisitz 6712: table.LC_prior_rank,
1.795 www 6713: table.LC_prior_match {
1.528 albertel 6714: border-collapse: collapse;
6715: }
1.795 www 6716:
1.528 albertel 6717: table.LC_prior_option tr td,
6718: table.LC_prior_rank tr td,
6719: table.LC_prior_match tr td {
1.524 albertel 6720: border: 1px solid #000000;
1.515 albertel 6721: }
6722:
1.855 bisitz 6723: .LC_nobreak {
1.544 albertel 6724: white-space: nowrap;
1.519 raeburn 6725: }
6726:
1.576 raeburn 6727: span.LC_cusr_emph {
6728: font-style: italic;
6729: }
6730:
1.633 raeburn 6731: span.LC_cusr_subheading {
6732: font-weight: normal;
6733: font-size: 85%;
6734: }
6735:
1.861 bisitz 6736: div.LC_docs_entry_move {
1.859 bisitz 6737: border: 1px solid #BBBBBB;
1.545 albertel 6738: background: #DDDDDD;
1.861 bisitz 6739: width: 22px;
1.859 bisitz 6740: padding: 1px;
6741: margin: 0;
1.545 albertel 6742: }
6743:
1.861 bisitz 6744: table.LC_data_table tr > td.LC_docs_entry_commands,
6745: table.LC_data_table tr > td.LC_docs_entry_parameter {
1.545 albertel 6746: font-size: x-small;
6747: }
1.795 www 6748:
1.861 bisitz 6749: .LC_docs_entry_parameter {
6750: white-space: nowrap;
6751: }
6752:
1.544 albertel 6753: .LC_docs_copy {
1.545 albertel 6754: color: #000099;
1.544 albertel 6755: }
1.795 www 6756:
1.544 albertel 6757: .LC_docs_cut {
1.545 albertel 6758: color: #550044;
1.544 albertel 6759: }
1.795 www 6760:
1.544 albertel 6761: .LC_docs_rename {
1.545 albertel 6762: color: #009900;
1.544 albertel 6763: }
1.795 www 6764:
1.544 albertel 6765: .LC_docs_remove {
1.545 albertel 6766: color: #990000;
6767: }
6768:
1.547 albertel 6769: .LC_docs_reinit_warn,
6770: .LC_docs_ext_edit {
6771: font-size: x-small;
6772: }
6773:
1.545 albertel 6774: table.LC_docs_adddocs td,
6775: table.LC_docs_adddocs th {
6776: border: 1px solid #BBBBBB;
6777: padding: 4px;
6778: background: #DDDDDD;
1.543 albertel 6779: }
6780:
1.584 albertel 6781: table.LC_sty_begin {
6782: background: #BBFFBB;
6783: }
1.795 www 6784:
1.584 albertel 6785: table.LC_sty_end {
6786: background: #FFBBBB;
6787: }
6788:
1.589 raeburn 6789: table.LC_double_column {
1.803 bisitz 6790: border-width: 0;
1.589 raeburn 6791: border-collapse: collapse;
6792: width: 100%;
6793: padding: 2px;
6794: }
6795:
6796: table.LC_double_column tr td.LC_left_col {
1.590 raeburn 6797: top: 2px;
1.589 raeburn 6798: left: 2px;
6799: width: 47%;
6800: vertical-align: top;
6801: }
6802:
6803: table.LC_double_column tr td.LC_right_col {
6804: top: 2px;
1.779 bisitz 6805: right: 2px;
1.589 raeburn 6806: width: 47%;
6807: vertical-align: top;
6808: }
6809:
1.591 raeburn 6810: div.LC_left_float {
6811: float: left;
6812: padding-right: 5%;
1.597 albertel 6813: padding-bottom: 4px;
1.591 raeburn 6814: }
6815:
6816: div.LC_clear_float_header {
1.597 albertel 6817: padding-bottom: 2px;
1.591 raeburn 6818: }
6819:
6820: div.LC_clear_float_footer {
1.597 albertel 6821: padding-top: 10px;
1.591 raeburn 6822: clear: both;
6823: }
6824:
1.597 albertel 6825: div.LC_grade_show_user {
1.941 bisitz 6826: /* border-left: 5px solid $sidebg; */
6827: border-top: 5px solid #000000;
6828: margin: 50px 0 0 0;
1.936 bisitz 6829: padding: 15px 0 5px 10px;
1.597 albertel 6830: }
1.795 www 6831:
1.936 bisitz 6832: div.LC_grade_show_user_odd_row {
1.941 bisitz 6833: /* border-left: 5px solid #000000; */
6834: }
6835:
6836: div.LC_grade_show_user div.LC_Box {
6837: margin-right: 50px;
1.597 albertel 6838: }
6839:
6840: div.LC_grade_submissions,
6841: div.LC_grade_message_center,
1.936 bisitz 6842: div.LC_grade_info_links {
1.597 albertel 6843: margin: 5px;
6844: width: 99%;
6845: background: #FFFFFF;
6846: }
1.795 www 6847:
1.597 albertel 6848: div.LC_grade_submissions_header,
1.936 bisitz 6849: div.LC_grade_message_center_header {
1.705 tempelho 6850: font-weight: bold;
6851: font-size: large;
1.597 albertel 6852: }
1.795 www 6853:
1.597 albertel 6854: div.LC_grade_submissions_body,
1.936 bisitz 6855: div.LC_grade_message_center_body {
1.597 albertel 6856: border: 1px solid black;
6857: width: 99%;
6858: background: #FFFFFF;
6859: }
1.795 www 6860:
1.613 albertel 6861: table.LC_scantron_action {
6862: width: 100%;
6863: }
1.795 www 6864:
1.613 albertel 6865: table.LC_scantron_action tr th {
1.698 harmsja 6866: font-weight:bold;
6867: font-style:normal;
1.613 albertel 6868: }
1.795 www 6869:
1.779 bisitz 6870: .LC_edit_problem_header,
1.614 albertel 6871: div.LC_edit_problem_footer {
1.705 tempelho 6872: font-weight: normal;
6873: font-size: medium;
1.602 albertel 6874: margin: 2px;
1.1060 bisitz 6875: background-color: $sidebg;
1.600 albertel 6876: }
1.795 www 6877:
1.600 albertel 6878: div.LC_edit_problem_header,
1.602 albertel 6879: div.LC_edit_problem_header div,
1.614 albertel 6880: div.LC_edit_problem_footer,
6881: div.LC_edit_problem_footer div,
1.602 albertel 6882: div.LC_edit_problem_editxml_header,
6883: div.LC_edit_problem_editxml_header div {
1.1205 golterma 6884: z-index: 100;
1.600 albertel 6885: }
1.795 www 6886:
1.600 albertel 6887: div.LC_edit_problem_header_title {
1.705 tempelho 6888: font-weight: bold;
6889: font-size: larger;
1.602 albertel 6890: background: $tabbg;
6891: padding: 3px;
1.1060 bisitz 6892: margin: 0 0 5px 0;
1.602 albertel 6893: }
1.795 www 6894:
1.602 albertel 6895: table.LC_edit_problem_header_title {
6896: width: 100%;
1.600 albertel 6897: background: $tabbg;
1.602 albertel 6898: }
6899:
1.1205 golterma 6900: div.LC_edit_actionbar {
6901: background-color: $sidebg;
1.1218 droeschl 6902: margin: 0;
6903: padding: 0;
6904: line-height: 200%;
1.602 albertel 6905: }
1.795 www 6906:
1.1218 droeschl 6907: div.LC_edit_actionbar div{
6908: padding: 0;
6909: margin: 0;
6910: display: inline-block;
1.600 albertel 6911: }
1.795 www 6912:
1.1124 bisitz 6913: .LC_edit_opt {
6914: padding-left: 1em;
6915: white-space: nowrap;
6916: }
6917:
1.1152 golterma 6918: .LC_edit_problem_latexhelper{
6919: text-align: right;
6920: }
6921:
6922: #LC_edit_problem_colorful div{
6923: margin-left: 40px;
6924: }
6925:
1.1205 golterma 6926: #LC_edit_problem_codemirror div{
6927: margin-left: 0px;
6928: }
6929:
1.911 bisitz 6930: img.stift {
1.803 bisitz 6931: border-width: 0;
6932: vertical-align: middle;
1.677 riegler 6933: }
1.680 riegler 6934:
1.923 bisitz 6935: table td.LC_mainmenu_col_fieldset {
1.680 riegler 6936: vertical-align: top;
1.777 tempelho 6937: }
1.795 www 6938:
1.716 raeburn 6939: div.LC_createcourse {
1.911 bisitz 6940: margin: 10px 10px 10px 10px;
1.716 raeburn 6941: }
6942:
1.917 raeburn 6943: .LC_dccid {
1.1130 raeburn 6944: float: right;
1.917 raeburn 6945: margin: 0.2em 0 0 0;
6946: padding: 0;
6947: font-size: 90%;
6948: display:none;
6949: }
6950:
1.897 wenzelju 6951: ol.LC_primary_menu a:hover,
1.721 harmsja 6952: ol#LC_MenuBreadcrumbs a:hover,
6953: ol#LC_PathBreadcrumbs a:hover,
1.897 wenzelju 6954: ul#LC_secondary_menu a:hover,
1.721 harmsja 6955: .LC_FormSectionClearButton input:hover
1.795 www 6956: ul.LC_TabContent li:hover a {
1.952 onken 6957: color:$button_hover;
1.911 bisitz 6958: text-decoration:none;
1.693 droeschl 6959: }
6960:
1.779 bisitz 6961: h1 {
1.911 bisitz 6962: padding: 0;
6963: line-height:130%;
1.693 droeschl 6964: }
1.698 harmsja 6965:
1.911 bisitz 6966: h2,
6967: h3,
6968: h4,
6969: h5,
6970: h6 {
6971: margin: 5px 0 5px 0;
6972: padding: 0;
6973: line-height:130%;
1.693 droeschl 6974: }
1.795 www 6975:
6976: .LC_hcell {
1.911 bisitz 6977: padding:3px 15px 3px 15px;
6978: margin: 0;
6979: background-color:$tabbg;
6980: color:$fontmenu;
6981: border-bottom:solid 1px $lg_border_color;
1.693 droeschl 6982: }
1.795 www 6983:
1.840 bisitz 6984: .LC_Box > .LC_hcell {
1.911 bisitz 6985: margin: 0 -10px 10px -10px;
1.835 bisitz 6986: }
6987:
1.721 harmsja 6988: .LC_noBorder {
1.911 bisitz 6989: border: 0;
1.698 harmsja 6990: }
1.693 droeschl 6991:
1.721 harmsja 6992: .LC_FormSectionClearButton input {
1.911 bisitz 6993: background-color:transparent;
6994: border: none;
6995: cursor:pointer;
6996: text-decoration:underline;
1.693 droeschl 6997: }
1.763 bisitz 6998:
6999: .LC_help_open_topic {
1.911 bisitz 7000: color: #FFFFFF;
7001: background-color: #EEEEFF;
7002: margin: 1px;
7003: padding: 4px;
7004: border: 1px solid #000033;
7005: white-space: nowrap;
7006: /* vertical-align: middle; */
1.759 neumanie 7007: }
1.693 droeschl 7008:
1.911 bisitz 7009: dl,
7010: ul,
7011: div,
7012: fieldset {
7013: margin: 10px 10px 10px 0;
7014: /* overflow: hidden; */
1.693 droeschl 7015: }
1.795 www 7016:
1.1211 raeburn 7017: article.geogebraweb div {
7018: margin: 0;
7019: }
7020:
1.838 bisitz 7021: fieldset > legend {
1.911 bisitz 7022: font-weight: bold;
7023: padding: 0 5px 0 5px;
1.838 bisitz 7024: }
7025:
1.813 bisitz 7026: #LC_nav_bar {
1.911 bisitz 7027: float: left;
1.995 raeburn 7028: background-color: $pgbg_or_bgcolor;
1.966 bisitz 7029: margin: 0 0 2px 0;
1.807 droeschl 7030: }
7031:
1.916 droeschl 7032: #LC_realm {
7033: margin: 0.2em 0 0 0;
7034: padding: 0;
7035: font-weight: bold;
7036: text-align: center;
1.995 raeburn 7037: background-color: $pgbg_or_bgcolor;
1.916 droeschl 7038: }
7039:
1.911 bisitz 7040: #LC_nav_bar em {
7041: font-weight: bold;
7042: font-style: normal;
1.807 droeschl 7043: }
7044:
1.897 wenzelju 7045: ol.LC_primary_menu {
1.934 droeschl 7046: margin: 0;
1.1076 raeburn 7047: padding: 0;
1.807 droeschl 7048: }
7049:
1.852 droeschl 7050: ol#LC_PathBreadcrumbs {
1.911 bisitz 7051: margin: 0;
1.693 droeschl 7052: }
7053:
1.897 wenzelju 7054: ol.LC_primary_menu li {
1.1076 raeburn 7055: color: RGB(80, 80, 80);
7056: vertical-align: middle;
7057: text-align: left;
7058: list-style: none;
1.1205 golterma 7059: position: relative;
1.1076 raeburn 7060: float: left;
1.1205 golterma 7061: z-index: 100; /* will be displayed above codemirror and underneath the help-layer */
7062: line-height: 1.5em;
1.1076 raeburn 7063: }
7064:
1.1205 golterma 7065: ol.LC_primary_menu li a,
7066: ol.LC_primary_menu li p {
1.1076 raeburn 7067: display: block;
7068: margin: 0;
7069: padding: 0 5px 0 10px;
7070: text-decoration: none;
7071: }
7072:
1.1205 golterma 7073: ol.LC_primary_menu li p span.LC_primary_menu_innertitle {
7074: display: inline-block;
7075: width: 95%;
7076: text-align: left;
7077: }
7078:
7079: ol.LC_primary_menu li p span.LC_primary_menu_innerarrow {
7080: display: inline-block;
7081: width: 5%;
7082: float: right;
7083: text-align: right;
7084: font-size: 70%;
7085: }
7086:
7087: ol.LC_primary_menu ul {
1.1076 raeburn 7088: display: none;
1.1205 golterma 7089: width: 15em;
1.1076 raeburn 7090: background-color: $data_table_light;
1.1205 golterma 7091: position: absolute;
7092: top: 100%;
1.1076 raeburn 7093: }
7094:
1.1205 golterma 7095: ol.LC_primary_menu ul ul {
7096: left: 100%;
7097: top: 0;
7098: }
7099:
7100: ol.LC_primary_menu li:hover > ul, ol.LC_primary_menu li.hover > ul {
1.1076 raeburn 7101: display: block;
7102: position: absolute;
7103: margin: 0;
7104: padding: 0;
1.1078 raeburn 7105: z-index: 2;
1.1076 raeburn 7106: }
7107:
7108: ol.LC_primary_menu li:hover li, ol.LC_primary_menu li.hover li {
1.1205 golterma 7109: /* First Submenu -> size should be smaller than the menu title of the whole menu */
1.1076 raeburn 7110: font-size: 90%;
1.911 bisitz 7111: vertical-align: top;
1.1076 raeburn 7112: float: none;
1.1079 raeburn 7113: border-left: 1px solid black;
7114: border-right: 1px solid black;
1.1205 golterma 7115: /* A dark bottom border to visualize different menu options;
7116: overwritten in the create_submenu routine for the last border-bottom of the menu */
7117: border-bottom: 1px solid $data_table_dark;
1.1076 raeburn 7118: }
7119:
1.1205 golterma 7120: ol.LC_primary_menu li li p:hover {
7121: color:$button_hover;
7122: text-decoration:none;
7123: background-color:$data_table_dark;
1.1076 raeburn 7124: }
7125:
7126: ol.LC_primary_menu li li a:hover {
7127: color:$button_hover;
7128: background-color:$data_table_dark;
1.693 droeschl 7129: }
7130:
1.1205 golterma 7131: /* Font-size equal to the size of the predecessors*/
7132: ol.LC_primary_menu li:hover li li {
7133: font-size: 100%;
7134: }
7135:
1.897 wenzelju 7136: ol.LC_primary_menu li img {
1.911 bisitz 7137: vertical-align: bottom;
1.934 droeschl 7138: height: 1.1em;
1.1077 raeburn 7139: margin: 0.2em 0 0 0;
1.693 droeschl 7140: }
7141:
1.897 wenzelju 7142: ol.LC_primary_menu a {
1.911 bisitz 7143: color: RGB(80, 80, 80);
7144: text-decoration: none;
1.693 droeschl 7145: }
1.795 www 7146:
1.949 droeschl 7147: ol.LC_primary_menu a.LC_new_message {
7148: font-weight:bold;
7149: color: darkred;
7150: }
7151:
1.975 raeburn 7152: ol.LC_docs_parameters {
7153: margin-left: 0;
7154: padding: 0;
7155: list-style: none;
7156: }
7157:
7158: ol.LC_docs_parameters li {
7159: margin: 0;
7160: padding-right: 20px;
7161: display: inline;
7162: }
7163:
1.976 raeburn 7164: ol.LC_docs_parameters li:before {
7165: content: "\\002022 \\0020";
7166: }
7167:
7168: li.LC_docs_parameters_title {
7169: font-weight: bold;
7170: }
7171:
7172: ol.LC_docs_parameters li.LC_docs_parameters_title:before {
7173: content: "";
7174: }
7175:
1.897 wenzelju 7176: ul#LC_secondary_menu {
1.1107 raeburn 7177: clear: right;
1.911 bisitz 7178: color: $fontmenu;
7179: background: $tabbg;
7180: list-style: none;
7181: padding: 0;
7182: margin: 0;
7183: width: 100%;
1.995 raeburn 7184: text-align: left;
1.1107 raeburn 7185: float: left;
1.808 droeschl 7186: }
7187:
1.897 wenzelju 7188: ul#LC_secondary_menu li {
1.911 bisitz 7189: font-weight: bold;
7190: line-height: 1.8em;
1.1107 raeburn 7191: border-right: 1px solid black;
7192: float: left;
7193: }
7194:
7195: ul#LC_secondary_menu li.LC_hoverable:hover, ul#LC_secondary_menu li.hover {
7196: background-color: $data_table_light;
7197: }
7198:
7199: ul#LC_secondary_menu li a {
1.911 bisitz 7200: padding: 0 0.8em;
1.1107 raeburn 7201: }
7202:
7203: ul#LC_secondary_menu li ul {
7204: display: none;
7205: }
7206:
7207: ul#LC_secondary_menu li:hover ul, ul#LC_secondary_menu li.hover ul {
7208: display: block;
7209: position: absolute;
7210: margin: 0;
7211: padding: 0;
7212: list-style:none;
7213: float: none;
7214: background-color: $data_table_light;
7215: z-index: 2;
7216: margin-left: -1px;
7217: }
7218:
7219: ul#LC_secondary_menu li ul li {
7220: font-size: 90%;
7221: vertical-align: top;
7222: border-left: 1px solid black;
1.911 bisitz 7223: border-right: 1px solid black;
1.1119 raeburn 7224: background-color: $data_table_light;
1.1107 raeburn 7225: list-style:none;
7226: float: none;
7227: }
7228:
7229: ul#LC_secondary_menu li ul li:hover, ul#LC_secondary_menu li ul li.hover {
7230: background-color: $data_table_dark;
1.807 droeschl 7231: }
7232:
1.847 tempelho 7233: ul.LC_TabContent {
1.911 bisitz 7234: display:block;
7235: background: $sidebg;
7236: border-bottom: solid 1px $lg_border_color;
7237: list-style:none;
1.1020 raeburn 7238: margin: -1px -10px 0 -10px;
1.911 bisitz 7239: padding: 0;
1.693 droeschl 7240: }
7241:
1.795 www 7242: ul.LC_TabContent li,
7243: ul.LC_TabContentBigger li {
1.911 bisitz 7244: float:left;
1.741 harmsja 7245: }
1.795 www 7246:
1.897 wenzelju 7247: ul#LC_secondary_menu li a {
1.911 bisitz 7248: color: $fontmenu;
7249: text-decoration: none;
1.693 droeschl 7250: }
1.795 www 7251:
1.721 harmsja 7252: ul.LC_TabContent {
1.952 onken 7253: min-height:20px;
1.721 harmsja 7254: }
1.795 www 7255:
7256: ul.LC_TabContent li {
1.911 bisitz 7257: vertical-align:middle;
1.959 onken 7258: padding: 0 16px 0 10px;
1.911 bisitz 7259: background-color:$tabbg;
7260: border-bottom:solid 1px $lg_border_color;
1.1020 raeburn 7261: border-left: solid 1px $font;
1.721 harmsja 7262: }
1.795 www 7263:
1.847 tempelho 7264: ul.LC_TabContent .right {
1.911 bisitz 7265: float:right;
1.847 tempelho 7266: }
7267:
1.911 bisitz 7268: ul.LC_TabContent li a,
7269: ul.LC_TabContent li {
7270: color:rgb(47,47,47);
7271: text-decoration:none;
7272: font-size:95%;
7273: font-weight:bold;
1.952 onken 7274: min-height:20px;
7275: }
7276:
1.959 onken 7277: ul.LC_TabContent li a:hover,
7278: ul.LC_TabContent li a:focus {
1.952 onken 7279: color: $button_hover;
1.959 onken 7280: background:none;
7281: outline:none;
1.952 onken 7282: }
7283:
7284: ul.LC_TabContent li:hover {
7285: color: $button_hover;
7286: cursor:pointer;
1.721 harmsja 7287: }
1.795 www 7288:
1.911 bisitz 7289: ul.LC_TabContent li.active {
1.952 onken 7290: color: $font;
1.911 bisitz 7291: background:#FFFFFF url(/adm/lonIcons/open.gif) no-repeat scroll right center;
1.952 onken 7292: border-bottom:solid 1px #FFFFFF;
7293: cursor: default;
1.744 ehlerst 7294: }
1.795 www 7295:
1.959 onken 7296: ul.LC_TabContent li.active a {
7297: color:$font;
7298: background:#FFFFFF;
7299: outline: none;
7300: }
1.1047 raeburn 7301:
7302: ul.LC_TabContent li.goback {
7303: float: left;
7304: border-left: none;
7305: }
7306:
1.870 tempelho 7307: #maincoursedoc {
1.911 bisitz 7308: clear:both;
1.870 tempelho 7309: }
7310:
7311: ul.LC_TabContentBigger {
1.911 bisitz 7312: display:block;
7313: list-style:none;
7314: padding: 0;
1.870 tempelho 7315: }
7316:
1.795 www 7317: ul.LC_TabContentBigger li {
1.911 bisitz 7318: vertical-align:bottom;
7319: height: 30px;
7320: font-size:110%;
7321: font-weight:bold;
7322: color: #737373;
1.841 tempelho 7323: }
7324:
1.957 onken 7325: ul.LC_TabContentBigger li.active {
7326: position: relative;
7327: top: 1px;
7328: }
7329:
1.870 tempelho 7330: ul.LC_TabContentBigger li a {
1.911 bisitz 7331: background:url('/adm/lonIcons/tabbgleft.gif') left bottom no-repeat;
7332: height: 30px;
7333: line-height: 30px;
7334: text-align: center;
7335: display: block;
7336: text-decoration: none;
1.958 onken 7337: outline: none;
1.741 harmsja 7338: }
1.795 www 7339:
1.870 tempelho 7340: ul.LC_TabContentBigger li.active a {
1.911 bisitz 7341: background:url('/adm/lonIcons/tabbgleft.gif') left top no-repeat;
7342: color:$font;
1.744 ehlerst 7343: }
1.795 www 7344:
1.870 tempelho 7345: ul.LC_TabContentBigger li b {
1.911 bisitz 7346: background: url('/adm/lonIcons/tabbgright.gif') no-repeat right bottom;
7347: display: block;
7348: float: left;
7349: padding: 0 30px;
1.957 onken 7350: border-bottom: 1px solid $lg_border_color;
1.870 tempelho 7351: }
7352:
1.956 onken 7353: ul.LC_TabContentBigger li:hover b {
7354: color:$button_hover;
7355: }
7356:
1.870 tempelho 7357: ul.LC_TabContentBigger li.active b {
1.911 bisitz 7358: background:url('/adm/lonIcons/tabbgright.gif') right top no-repeat;
7359: color:$font;
1.957 onken 7360: border: 0;
1.741 harmsja 7361: }
1.693 droeschl 7362:
1.870 tempelho 7363:
1.862 bisitz 7364: ul.LC_CourseBreadcrumbs {
7365: background: $sidebg;
1.1020 raeburn 7366: height: 2em;
1.862 bisitz 7367: padding-left: 10px;
1.1020 raeburn 7368: margin: 0;
1.862 bisitz 7369: list-style-position: inside;
7370: }
7371:
1.911 bisitz 7372: ol#LC_MenuBreadcrumbs,
1.862 bisitz 7373: ol#LC_PathBreadcrumbs {
1.911 bisitz 7374: padding-left: 10px;
7375: margin: 0;
1.933 droeschl 7376: height: 2.5em; /* equal to #LC_breadcrumbs line-height */
1.693 droeschl 7377: }
7378:
1.911 bisitz 7379: ol#LC_MenuBreadcrumbs li,
7380: ol#LC_PathBreadcrumbs li,
1.862 bisitz 7381: ul.LC_CourseBreadcrumbs li {
1.911 bisitz 7382: display: inline;
1.933 droeschl 7383: white-space: normal;
1.693 droeschl 7384: }
7385:
1.823 bisitz 7386: ol#LC_MenuBreadcrumbs li a,
1.862 bisitz 7387: ul.LC_CourseBreadcrumbs li a {
1.911 bisitz 7388: text-decoration: none;
7389: font-size:90%;
1.693 droeschl 7390: }
1.795 www 7391:
1.969 droeschl 7392: ol#LC_MenuBreadcrumbs h1 {
7393: display: inline;
7394: font-size: 90%;
7395: line-height: 2.5em;
7396: margin: 0;
7397: padding: 0;
7398: }
7399:
1.795 www 7400: ol#LC_PathBreadcrumbs li a {
1.911 bisitz 7401: text-decoration:none;
7402: font-size:100%;
7403: font-weight:bold;
1.693 droeschl 7404: }
1.795 www 7405:
1.840 bisitz 7406: .LC_Box {
1.911 bisitz 7407: border: solid 1px $lg_border_color;
7408: padding: 0 10px 10px 10px;
1.746 neumanie 7409: }
1.795 www 7410:
1.1020 raeburn 7411: .LC_DocsBox {
7412: border: solid 1px $lg_border_color;
7413: padding: 0 0 10px 10px;
7414: }
7415:
1.795 www 7416: .LC_AboutMe_Image {
1.911 bisitz 7417: float:left;
7418: margin-right:10px;
1.747 neumanie 7419: }
1.795 www 7420:
7421: .LC_Clear_AboutMe_Image {
1.911 bisitz 7422: clear:left;
1.747 neumanie 7423: }
1.795 www 7424:
1.721 harmsja 7425: dl.LC_ListStyleClean dt {
1.911 bisitz 7426: padding-right: 5px;
7427: display: table-header-group;
1.693 droeschl 7428: }
7429:
1.721 harmsja 7430: dl.LC_ListStyleClean dd {
1.911 bisitz 7431: display: table-row;
1.693 droeschl 7432: }
7433:
1.721 harmsja 7434: .LC_ListStyleClean,
7435: .LC_ListStyleSimple,
7436: .LC_ListStyleNormal,
1.795 www 7437: .LC_ListStyleSpecial {
1.911 bisitz 7438: /* display:block; */
7439: list-style-position: inside;
7440: list-style-type: none;
7441: overflow: hidden;
7442: padding: 0;
1.693 droeschl 7443: }
7444:
1.721 harmsja 7445: .LC_ListStyleSimple li,
7446: .LC_ListStyleSimple dd,
7447: .LC_ListStyleNormal li,
7448: .LC_ListStyleNormal dd,
7449: .LC_ListStyleSpecial li,
1.795 www 7450: .LC_ListStyleSpecial dd {
1.911 bisitz 7451: margin: 0;
7452: padding: 5px 5px 5px 10px;
7453: clear: both;
1.693 droeschl 7454: }
7455:
1.721 harmsja 7456: .LC_ListStyleClean li,
7457: .LC_ListStyleClean dd {
1.911 bisitz 7458: padding-top: 0;
7459: padding-bottom: 0;
1.693 droeschl 7460: }
7461:
1.721 harmsja 7462: .LC_ListStyleSimple dd,
1.795 www 7463: .LC_ListStyleSimple li {
1.911 bisitz 7464: border-bottom: solid 1px $lg_border_color;
1.693 droeschl 7465: }
7466:
1.721 harmsja 7467: .LC_ListStyleSpecial li,
7468: .LC_ListStyleSpecial dd {
1.911 bisitz 7469: list-style-type: none;
7470: background-color: RGB(220, 220, 220);
7471: margin-bottom: 4px;
1.693 droeschl 7472: }
7473:
1.721 harmsja 7474: table.LC_SimpleTable {
1.911 bisitz 7475: margin:5px;
7476: border:solid 1px $lg_border_color;
1.795 www 7477: }
1.693 droeschl 7478:
1.721 harmsja 7479: table.LC_SimpleTable tr {
1.911 bisitz 7480: padding: 0;
7481: border:solid 1px $lg_border_color;
1.693 droeschl 7482: }
1.795 www 7483:
7484: table.LC_SimpleTable thead {
1.911 bisitz 7485: background:rgb(220,220,220);
1.693 droeschl 7486: }
7487:
1.721 harmsja 7488: div.LC_columnSection {
1.911 bisitz 7489: display: block;
7490: clear: both;
7491: overflow: hidden;
7492: margin: 0;
1.693 droeschl 7493: }
7494:
1.721 harmsja 7495: div.LC_columnSection>* {
1.911 bisitz 7496: float: left;
7497: margin: 10px 20px 10px 0;
7498: overflow:hidden;
1.693 droeschl 7499: }
1.721 harmsja 7500:
1.795 www 7501: table em {
1.911 bisitz 7502: font-weight: bold;
7503: font-style: normal;
1.748 schulted 7504: }
1.795 www 7505:
1.779 bisitz 7506: table.LC_tableBrowseRes,
1.795 www 7507: table.LC_tableOfContent {
1.911 bisitz 7508: border:none;
7509: border-spacing: 1px;
7510: padding: 3px;
7511: background-color: #FFFFFF;
7512: font-size: 90%;
1.753 droeschl 7513: }
1.789 droeschl 7514:
1.911 bisitz 7515: table.LC_tableOfContent {
7516: border-collapse: collapse;
1.789 droeschl 7517: }
7518:
1.771 droeschl 7519: table.LC_tableBrowseRes a,
1.768 schulted 7520: table.LC_tableOfContent a {
1.911 bisitz 7521: background-color: transparent;
7522: text-decoration: none;
1.753 droeschl 7523: }
7524:
1.795 www 7525: table.LC_tableOfContent img {
1.911 bisitz 7526: border: none;
7527: height: 1.3em;
7528: vertical-align: text-bottom;
7529: margin-right: 0.3em;
1.753 droeschl 7530: }
1.757 schulted 7531:
1.795 www 7532: a#LC_content_toolbar_firsthomework {
1.911 bisitz 7533: background-image:url(/res/adm/pages/open-first-problem.gif);
1.774 ehlerst 7534: }
7535:
1.795 www 7536: a#LC_content_toolbar_everything {
1.911 bisitz 7537: background-image:url(/res/adm/pages/show-all.gif);
1.774 ehlerst 7538: }
7539:
1.795 www 7540: a#LC_content_toolbar_uncompleted {
1.911 bisitz 7541: background-image:url(/res/adm/pages/show-incomplete-problems.gif);
1.774 ehlerst 7542: }
7543:
1.795 www 7544: #LC_content_toolbar_clearbubbles {
1.911 bisitz 7545: background-image:url(/res/adm/pages/mark-discussionentries-read.gif);
1.774 ehlerst 7546: }
7547:
1.795 www 7548: a#LC_content_toolbar_changefolder {
1.911 bisitz 7549: background : url(/res/adm/pages/close-all-folders.gif) top center ;
1.757 schulted 7550: }
7551:
1.795 www 7552: a#LC_content_toolbar_changefolder_toggled {
1.911 bisitz 7553: background-image:url(/res/adm/pages/open-all-folders.gif);
1.757 schulted 7554: }
7555:
1.1043 raeburn 7556: a#LC_content_toolbar_edittoplevel {
7557: background-image:url(/res/adm/pages/edittoplevel.gif);
7558: }
7559:
1.795 www 7560: ul#LC_toolbar li a:hover {
1.911 bisitz 7561: background-position: bottom center;
1.757 schulted 7562: }
7563:
1.795 www 7564: ul#LC_toolbar {
1.911 bisitz 7565: padding: 0;
7566: margin: 2px;
7567: list-style:none;
7568: position:relative;
7569: background-color:white;
1.1082 raeburn 7570: overflow: auto;
1.757 schulted 7571: }
7572:
1.795 www 7573: ul#LC_toolbar li {
1.911 bisitz 7574: border:1px solid white;
7575: padding: 0;
7576: margin: 0;
7577: float: left;
7578: display:inline;
7579: vertical-align:middle;
1.1082 raeburn 7580: white-space: nowrap;
1.911 bisitz 7581: }
1.757 schulted 7582:
1.783 amueller 7583:
1.795 www 7584: a.LC_toolbarItem {
1.911 bisitz 7585: display:block;
7586: padding: 0;
7587: margin: 0;
7588: height: 32px;
7589: width: 32px;
7590: color:white;
7591: border: none;
7592: background-repeat:no-repeat;
7593: background-color:transparent;
1.757 schulted 7594: }
7595:
1.915 droeschl 7596: ul.LC_funclist {
7597: margin: 0;
7598: padding: 0.5em 1em 0.5em 0;
7599: }
7600:
1.933 droeschl 7601: ul.LC_funclist > li:first-child {
7602: font-weight:bold;
7603: margin-left:0.8em;
7604: }
7605:
1.915 droeschl 7606: ul.LC_funclist + ul.LC_funclist {
7607: /*
7608: left border as a seperator if we have more than
7609: one list
7610: */
7611: border-left: 1px solid $sidebg;
7612: /*
7613: this hides the left border behind the border of the
7614: outer box if element is wrapped to the next 'line'
7615: */
7616: margin-left: -1px;
7617: }
7618:
1.843 bisitz 7619: ul.LC_funclist li {
1.915 droeschl 7620: display: inline;
1.782 bisitz 7621: white-space: nowrap;
1.915 droeschl 7622: margin: 0 0 0 25px;
7623: line-height: 150%;
1.782 bisitz 7624: }
7625:
1.974 wenzelju 7626: .LC_hidden {
7627: display: none;
7628: }
7629:
1.1030 www 7630: .LCmodal-overlay {
7631: position:fixed;
7632: top:0;
7633: right:0;
7634: bottom:0;
7635: left:0;
7636: height:100%;
7637: width:100%;
7638: margin:0;
7639: padding:0;
7640: background:#999;
7641: opacity:.75;
7642: filter: alpha(opacity=75);
7643: -moz-opacity: 0.75;
7644: z-index:101;
7645: }
7646:
7647: * html .LCmodal-overlay {
7648: position: absolute;
7649: height: expression(document.body.scrollHeight > document.body.offsetHeight ? document.body.scrollHeight : document.body.offsetHeight + 'px');
7650: }
7651:
7652: .LCmodal-window {
7653: position:fixed;
7654: top:50%;
7655: left:50%;
7656: margin:0;
7657: padding:0;
7658: z-index:102;
7659: }
7660:
7661: * html .LCmodal-window {
7662: position:absolute;
7663: }
7664:
7665: .LCclose-window {
7666: position:absolute;
7667: width:32px;
7668: height:32px;
7669: right:8px;
7670: top:8px;
7671: background:transparent url('/res/adm/pages/process-stop.png') no-repeat scroll right top;
7672: text-indent:-99999px;
7673: overflow:hidden;
7674: cursor:pointer;
7675: }
7676:
1.1100 raeburn 7677: /*
1.1231 damieng 7678: styles used for response display
7679: */
7680: div.LC_radiofoil, div.LC_rankfoil {
7681: margin: .5em 0em .5em 0em;
7682: }
7683: table.LC_itemgroup {
7684: margin-top: 1em;
7685: }
7686:
7687: /*
1.1100 raeburn 7688: styles used by TTH when "Default set of options to pass to tth/m
7689: when converting TeX" in course settings has been set
7690:
7691: option passed: -t
7692:
7693: */
7694:
7695: td div.comp { margin-top: -0.6ex; margin-bottom: -1ex;}
7696: td div.comb { margin-top: -0.6ex; margin-bottom: -.6ex;}
7697: td div.hrcomp { line-height: 0.9; margin-top: -0.8ex; margin-bottom: -1ex;}
7698: td div.norm {line-height:normal;}
7699:
7700: /*
7701: option passed -y3
7702: */
7703:
7704: span.roman {font-family: serif; font-style: normal; font-weight: normal;}
7705: span.overacc2 {position: relative; left: .8em; top: -1.2ex;}
7706: span.overacc1 {position: relative; left: .6em; top: -1.2ex;}
7707:
1.1230 damieng 7708: /*
7709: sections with roles, for content only
7710: */
7711: section[class^="role-"] {
7712: padding-left: 10px;
7713: padding-right: 5px;
7714: margin-top: 8px;
7715: margin-bottom: 8px;
7716: border: 1px solid #2A4;
7717: border-radius: 5px;
7718: box-shadow: 0px 1px 1px #BBB;
7719: }
7720: section[class^="role-"]>h1 {
7721: position: relative;
7722: margin: 0px;
7723: padding-top: 10px;
7724: padding-left: 40px;
7725: }
7726: section[class^="role-"]>h1:before {
7727: position: absolute;
7728: left: -5px;
7729: top: 5px;
7730: }
7731: section.role-activity>h1:before {
7732: content:url('/adm/daxe/images/section_icons/activity.png');
7733: }
7734: section.role-advice>h1:before {
7735: content:url('/adm/daxe/images/section_icons/advice.png');
7736: }
7737: section.role-bibliography>h1:before {
7738: content:url('/adm/daxe/images/section_icons/bibliography.png');
7739: }
7740: section.role-citation>h1:before {
7741: content:url('/adm/daxe/images/section_icons/citation.png');
7742: }
7743: section.role-conclusion>h1:before {
7744: content:url('/adm/daxe/images/section_icons/conclusion.png');
7745: }
7746: section.role-definition>h1:before {
7747: content:url('/adm/daxe/images/section_icons/definition.png');
7748: }
7749: section.role-demonstration>h1:before {
7750: content:url('/adm/daxe/images/section_icons/demonstration.png');
7751: }
7752: section.role-example>h1:before {
7753: content:url('/adm/daxe/images/section_icons/example.png');
7754: }
7755: section.role-explanation>h1:before {
7756: content:url('/adm/daxe/images/section_icons/explanation.png');
7757: }
7758: section.role-introduction>h1:before {
7759: content:url('/adm/daxe/images/section_icons/introduction.png');
7760: }
7761: section.role-method>h1:before {
7762: content:url('/adm/daxe/images/section_icons/method.png');
7763: }
7764: section.role-more_information>h1:before {
7765: content:url('/adm/daxe/images/section_icons/more_information.png');
7766: }
7767: section.role-objectives>h1:before {
7768: content:url('/adm/daxe/images/section_icons/objectives.png');
7769: }
7770: section.role-prerequisites>h1:before {
7771: content:url('/adm/daxe/images/section_icons/prerequisites.png');
7772: }
7773: section.role-remark>h1:before {
7774: content:url('/adm/daxe/images/section_icons/remark.png');
7775: }
7776: section.role-reminder>h1:before {
7777: content:url('/adm/daxe/images/section_icons/reminder.png');
7778: }
7779: section.role-summary>h1:before {
7780: content:url('/adm/daxe/images/section_icons/summary.png');
7781: }
7782: section.role-syntax>h1:before {
7783: content:url('/adm/daxe/images/section_icons/syntax.png');
7784: }
7785: section.role-warning>h1:before {
7786: content:url('/adm/daxe/images/section_icons/warning.png');
7787: }
7788:
1.343 albertel 7789: END
7790: }
7791:
1.306 albertel 7792: =pod
7793:
7794: =item * &headtag()
7795:
7796: Returns a uniform footer for LON-CAPA web pages.
7797:
1.307 albertel 7798: Inputs: $title - optional title for the head
7799: $head_extra - optional extra HTML to put inside the <head>
1.315 albertel 7800: $args - optional arguments
1.319 albertel 7801: force_register - if is true call registerurl so the remote is
7802: informed
1.415 albertel 7803: redirect -> array ref of
7804: 1- seconds before redirect occurs
7805: 2- url to redirect to
7806: 3- whether the side effect should occur
1.315 albertel 7807: (side effect of setting
7808: $env{'internal.head.redirect'} to the url
7809: redirected too)
1.352 albertel 7810: domain -> force to color decorate a page for a specific
7811: domain
7812: function -> force usage of a specific rolish color scheme
7813: bgcolor -> override the default page bgcolor
1.460 albertel 7814: no_auto_mt_title
7815: -> prevent &mt()ing the title arg
1.464 albertel 7816:
1.306 albertel 7817: =cut
7818:
7819: sub headtag {
1.313 albertel 7820: my ($title,$head_extra,$args) = @_;
1.306 albertel 7821:
1.363 albertel 7822: my $function = $args->{'function'} || &get_users_function();
7823: my $domain = $args->{'domain'} || &determinedomain();
7824: my $bgcolor = $args->{'bgcolor'} || &designparm($function.'.pgbg',$domain);
1.1154 raeburn 7825: my $httphost = $args->{'use_absolute'};
1.418 albertel 7826: my $url = join(':',$env{'user.name'},$env{'user.domain'},
1.458 albertel 7827: $Apache::lonnet::perlvar{'lonVersion'},
1.531 albertel 7828: #time(),
1.418 albertel 7829: $env{'environment.color.timestamp'},
1.363 albertel 7830: $function,$domain,$bgcolor);
7831:
1.369 www 7832: $url = '/adm/css/'.&escape($url).'.css';
1.363 albertel 7833:
1.308 albertel 7834: my $result =
7835: '<head>'.
1.1160 raeburn 7836: &font_settings($args);
1.319 albertel 7837:
1.1188 raeburn 7838: my $inhibitprint;
7839: if ($args->{'print_suppress'}) {
7840: $inhibitprint = &print_suppression();
7841: }
1.1064 raeburn 7842:
1.461 albertel 7843: if (!$args->{'frameset'}) {
7844: $result .= &Apache::lonhtmlcommon::htmlareaheaders();
7845: }
1.962 droeschl 7846: if ($args->{'force_register'} && $env{'request.noversionuri'} !~ m{^/res/adm/pages/}) {
7847: $result .= Apache::lonxml::display_title();
1.319 albertel 7848: }
1.436 albertel 7849: if (!$args->{'no_nav_bar'}
7850: && !$args->{'only_body'}
7851: && !$args->{'frameset'}) {
1.1154 raeburn 7852: $result .= &help_menu_js($httphost);
1.1032 www 7853: $result.=&modal_window();
1.1038 www 7854: $result.=&togglebox_script();
1.1034 www 7855: $result.=&wishlist_window();
1.1041 www 7856: $result.=&LCprogressbarUpdate_script();
1.1034 www 7857: } else {
7858: if ($args->{'add_modal'}) {
7859: $result.=&modal_window();
7860: }
7861: if ($args->{'add_wishlist'}) {
7862: $result.=&wishlist_window();
7863: }
1.1038 www 7864: if ($args->{'add_togglebox'}) {
7865: $result.=&togglebox_script();
7866: }
1.1041 www 7867: if ($args->{'add_progressbar'}) {
7868: $result.=&LCprogressbarUpdate_script();
7869: }
1.436 albertel 7870: }
1.314 albertel 7871: if (ref($args->{'redirect'})) {
1.414 albertel 7872: my ($time,$url,$inhibit_continue) = @{$args->{'redirect'}};
1.315 albertel 7873: $url = &Apache::lonenc::check_encrypt($url);
1.414 albertel 7874: if (!$inhibit_continue) {
7875: $env{'internal.head.redirect'} = $url;
7876: }
1.313 albertel 7877: $result.=<<ADDMETA
7878: <meta http-equiv="pragma" content="no-cache" />
1.344 albertel 7879: <meta http-equiv="Refresh" content="$time; url=$url" />
1.313 albertel 7880: ADDMETA
1.1210 raeburn 7881: } else {
7882: unless (($args->{'frameset'}) || ($args->{'js_ready'}) || ($args->{'only_body'}) || ($args->{'no_nav_bar'})) {
7883: my $requrl = $env{'request.uri'};
7884: if ($requrl eq '') {
7885: $requrl = $ENV{'REQUEST_URI'};
7886: $requrl =~ s/\?.+$//;
7887: }
7888: unless (($requrl =~ m{^/adm/(?:switchserver|login|authenticate|logout|groupsort|cleanup|helper|slotrequest|grades)(\?|$)}) ||
7889: (($requrl =~ m{^/res/}) && (($env{'form.submitted'} eq 'scantron') ||
7890: ($env{'form.grade_symb'}) || ($Apache::lonhomework::scantronmode)))) {
7891: my $dom_in_use = $Apache::lonnet::perlvar{'lonDefDomain'};
7892: unless (&Apache::lonnet::allowed('mau',$dom_in_use)) {
7893: my %domdefs = &Apache::lonnet::get_domain_defaults($dom_in_use);
7894: if (ref($domdefs{'offloadnow'}) eq 'HASH') {
7895: my $lonhost = $Apache::lonnet::perlvar{'lonHostID'};
7896: if ($domdefs{'offloadnow'}{$lonhost}) {
7897: my $newserver = &Apache::lonnet::spareserver(30000,undef,1,$dom_in_use);
7898: if (($newserver) && ($newserver ne $lonhost)) {
7899: my $numsec = 5;
7900: my $timeout = $numsec * 1000;
7901: my ($newurl,$locknum,%locks,$msg);
7902: if ($env{'request.role.adv'}) {
7903: ($locknum,%locks) = &Apache::lonnet::get_locks();
7904: }
7905: my $disable_submit = 0;
7906: if ($requrl =~ /$LONCAPA::assess_re/) {
7907: $disable_submit = 1;
7908: }
7909: if ($locknum) {
7910: my @lockinfo = sort(values(%locks));
7911: $msg = &mt('Once the following tasks are complete: ')."\\n".
7912: join(", ",sort(values(%locks)))."\\n".
7913: &mt('your session will be transferred to a different server, after you click "Roles".');
7914: } else {
7915: if (($requrl =~ m{^/res/}) && ($env{'form.submitted'} =~ /^part_/)) {
7916: $msg = &mt('Your LON-CAPA submission has been recorded')."\\n";
7917: }
7918: $msg .= &mt('Your current LON-CAPA session will be transferred to a different server in [quant,_1,second].',$numsec);
7919: $newurl = '/adm/switchserver?otherserver='.$newserver;
7920: if (($env{'request.role'}) && ($env{'request.role'} ne 'cm')) {
7921: $newurl .= '&role='.$env{'request.role'};
7922: }
7923: if ($env{'request.symb'}) {
7924: $newurl .= '&symb='.$env{'request.symb'};
7925: } else {
7926: $newurl .= '&origurl='.$requrl;
7927: }
7928: }
1.1222 damieng 7929: &js_escape(\$msg);
1.1210 raeburn 7930: $result.=<<OFFLOAD
7931: <meta http-equiv="pragma" content="no-cache" />
7932: <script type="text/javascript">
1.1215 raeburn 7933: // <![CDATA[
1.1210 raeburn 7934: function LC_Offload_Now() {
7935: var dest = "$newurl";
7936: if (dest != '') {
7937: window.location.href="$newurl";
7938: }
7939: }
1.1214 raeburn 7940: \$(document).ready(function () {
7941: window.alert('$msg');
7942: if ($disable_submit) {
1.1210 raeburn 7943: \$(".LC_hwk_submit").prop("disabled", true);
7944: \$( ".LC_textline" ).prop( "readonly", "readonly");
1.1214 raeburn 7945: }
7946: setTimeout('LC_Offload_Now()', $timeout);
7947: });
1.1215 raeburn 7948: // ]]>
1.1210 raeburn 7949: </script>
7950: OFFLOAD
7951: }
7952: }
7953: }
7954: }
7955: }
7956: }
1.313 albertel 7957: }
1.306 albertel 7958: if (!defined($title)) {
7959: $title = 'The LearningOnline Network with CAPA';
7960: }
1.460 albertel 7961: if (!$args->{'no_auto_mt_title'}) { $title = &mt($title); }
7962: $result .= '<title> LON-CAPA '.$title.'</title>'
1.1168 raeburn 7963: .'<link rel="stylesheet" type="text/css" href="'.$url.'"';
7964: if (!$args->{'frameset'}) {
7965: $result .= ' /';
7966: }
7967: $result .= '>'
1.1064 raeburn 7968: .$inhibitprint
1.414 albertel 7969: .$head_extra;
1.1242 ! raeburn 7970: my $clientmobile;
! 7971: if (($env{'user.name'} eq '') && ($env{'user.domain'} eq '')) {
! 7972: (undef,undef,undef,undef,undef,undef,$clientmobile) = &decode_user_agent();
! 7973: } else {
! 7974: $clientmobile = $env{'browser.mobile'};
! 7975: }
! 7976: if ($clientmobile) {
1.1137 raeburn 7977: $result .= '
7978: <meta name="viewport" content="width=device-width, initial-scale=1.0, user-scalable=0, minimum-scale=1.0, maximum-scale=1.0">
7979: <meta name="apple-mobile-web-app-capable" content="yes" />';
7980: }
1.962 droeschl 7981: return $result.'</head>';
1.306 albertel 7982: }
7983:
7984: =pod
7985:
1.340 albertel 7986: =item * &font_settings()
7987:
7988: Returns neccessary <meta> to set the proper encoding
7989:
1.1160 raeburn 7990: Inputs: optional reference to HASH -- $args passed to &headtag()
1.340 albertel 7991:
7992: =cut
7993:
7994: sub font_settings {
1.1160 raeburn 7995: my ($args) = @_;
1.340 albertel 7996: my $headerstring='';
1.1160 raeburn 7997: if ((!$env{'browser.mathml'} && $env{'browser.unicode'}) ||
7998: ((ref($args) eq 'HASH') && ($args->{'browser.unicode'}))) {
1.1168 raeburn 7999: $headerstring.=
8000: '<meta http-equiv="Content-Type" content="text/html; charset=utf-8"';
8001: if (!$args->{'frameset'}) {
8002: $headerstring.= ' /';
8003: }
8004: $headerstring .= '>'."\n";
1.340 albertel 8005: }
8006: return $headerstring;
8007: }
8008:
1.341 albertel 8009: =pod
8010:
1.1064 raeburn 8011: =item * &print_suppression()
8012:
8013: In course context returns css which causes the body to be blank when media="print",
8014: if printout generation is unavailable for the current resource.
8015:
8016: This could be because:
8017:
8018: (a) printstartdate is in the future
8019:
8020: (b) printenddate is in the past
8021:
8022: (c) there is an active exam block with "printout"
8023: functionality blocked
8024:
8025: Users with pav, pfo or evb privileges are exempt.
8026:
8027: Inputs: none
8028:
8029: =cut
8030:
8031:
8032: sub print_suppression {
8033: my $noprint;
8034: if ($env{'request.course.id'}) {
8035: my $scope = $env{'request.course.id'};
8036: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8037: (&Apache::lonnet::allowed('pfo',$scope))) {
8038: return;
8039: }
8040: if ($env{'request.course.sec'} ne '') {
8041: $scope .= "/$env{'request.course.sec'}";
8042: if ((&Apache::lonnet::allowed('pav',$scope)) ||
8043: (&Apache::lonnet::allowed('pfo',$scope))) {
1.1065 raeburn 8044: return;
1.1064 raeburn 8045: }
8046: }
8047: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
8048: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1189 raeburn 8049: my $blocked = &blocking_status('printout',$cnum,$cdom,undef,1);
1.1064 raeburn 8050: if ($blocked) {
8051: my $checkrole = "cm./$cdom/$cnum";
8052: if ($env{'request.course.sec'} ne '') {
8053: $checkrole .= "/$env{'request.course.sec'}";
8054: }
8055: unless ((&Apache::lonnet::allowed('evb',undef,undef,$checkrole)) &&
8056: ($env{'request.role'} !~ m{^st\./$cdom/$cnum})) {
8057: $noprint = 1;
8058: }
8059: }
8060: unless ($noprint) {
8061: my $symb = &Apache::lonnet::symbread();
8062: if ($symb ne '') {
8063: my $navmap = Apache::lonnavmaps::navmap->new();
8064: if (ref($navmap)) {
8065: my $res = $navmap->getBySymb($symb);
8066: if (ref($res)) {
8067: if (!$res->resprintable()) {
8068: $noprint = 1;
8069: }
8070: }
8071: }
8072: }
8073: }
8074: if ($noprint) {
8075: return <<"ENDSTYLE";
8076: <style type="text/css" media="print">
8077: body { display:none }
8078: </style>
8079: ENDSTYLE
8080: }
8081: }
8082: return;
8083: }
8084:
8085: =pod
8086:
1.341 albertel 8087: =item * &xml_begin()
8088:
8089: Returns the needed doctype and <html>
8090:
8091: Inputs: none
8092:
8093: =cut
8094:
8095: sub xml_begin {
1.1168 raeburn 8096: my ($is_frameset) = @_;
1.341 albertel 8097: my $output='';
8098:
8099: if ($env{'browser.mathml'}) {
8100: $output='<?xml version="1.0"?>'
8101: #.'<?xml-stylesheet type="text/css" href="/adm/MathML/mathml.css"?>'."\n"
8102: # .'<!DOCTYPE html SYSTEM "/adm/MathML/mathml.dtd" '
8103:
8104: # .'<!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">] >'
8105: .'<!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">'
8106: .'<html xmlns:math="http://www.w3.org/1998/Math/MathML" '
8107: .'xmlns="http://www.w3.org/1999/xhtml">';
1.1168 raeburn 8108: } elsif ($is_frameset) {
8109: $output='<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Frameset//EN" "http://www.w3.org/TR/html4/frameset.dtd">'."\n".
8110: '<html>'."\n";
1.341 albertel 8111: } else {
1.1168 raeburn 8112: $output='<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">'."\n".
8113: '<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">'."\n";
1.341 albertel 8114: }
8115: return $output;
8116: }
1.340 albertel 8117:
8118: =pod
8119:
1.306 albertel 8120: =item * &start_page()
8121:
8122: Returns a complete <html> .. <body> section for LON-CAPA web pages.
8123:
1.648 raeburn 8124: Inputs:
8125:
8126: =over 4
8127:
8128: $title - optional title for the page
8129:
8130: $head_extra - optional extra HTML to incude inside the <head>
8131:
8132: $args - additional optional args supported are:
8133:
8134: =over 8
8135:
8136: only_body -> is true will set &bodytag() onlybodytag
1.317 albertel 8137: arg on
1.814 bisitz 8138: no_nav_bar -> is true will set &bodytag() no_nav_bar arg on
1.648 raeburn 8139: add_entries -> additional attributes to add to the <body>
8140: domain -> force to color decorate a page for a
1.317 albertel 8141: specific domain
1.648 raeburn 8142: function -> force usage of a specific rolish color
1.317 albertel 8143: scheme
1.648 raeburn 8144: redirect -> see &headtag()
8145: bgcolor -> override the default page bg color
8146: js_ready -> return a string ready for being used in
1.317 albertel 8147: a javascript writeln
1.648 raeburn 8148: html_encode -> return a string ready for being used in
1.320 albertel 8149: a html attribute
1.648 raeburn 8150: force_register -> if is true will turn on the &bodytag()
1.317 albertel 8151: $forcereg arg
1.648 raeburn 8152: frameset -> if true will start with a <frameset>
1.330 albertel 8153: rather than <body>
1.648 raeburn 8154: skip_phases -> hash ref of
1.338 albertel 8155: head -> skip the <html><head> generation
8156: body -> skip all <body> generation
1.648 raeburn 8157: no_auto_mt_title -> prevent &mt()ing the title arg
1.867 kalberla 8158: bread_crumbs -> Array containing breadcrumbs
1.983 raeburn 8159: bread_crumbs_component -> if exists show it as headline else show only the breadcrumbs
1.1096 raeburn 8160: group -> includes the current group, if page is for a
8161: specific group
1.361 albertel 8162:
1.648 raeburn 8163: =back
1.460 albertel 8164:
1.648 raeburn 8165: =back
1.562 albertel 8166:
1.306 albertel 8167: =cut
8168:
8169: sub start_page {
1.309 albertel 8170: my ($title,$head_extra,$args) = @_;
1.318 albertel 8171: #&Apache::lonnet::logthis("start_page ".join(':',caller(0)));
1.319 albertel 8172:
1.315 albertel 8173: $env{'internal.start_page'}++;
1.1096 raeburn 8174: my ($result,@advtools);
1.964 droeschl 8175:
1.338 albertel 8176: if (! exists($args->{'skip_phases'}{'head'}) ) {
1.1168 raeburn 8177: $result .= &xml_begin($args->{'frameset'}) . &headtag($title, $head_extra, $args);
1.338 albertel 8178: }
8179:
8180: if (! exists($args->{'skip_phases'}{'body'}) ) {
8181: if ($args->{'frameset'}) {
8182: my $attr_string = &make_attr_string($args->{'force_register'},
8183: $args->{'add_entries'});
8184: $result .= "\n<frameset $attr_string>\n";
1.831 bisitz 8185: } else {
8186: $result .=
8187: &bodytag($title,
8188: $args->{'function'}, $args->{'add_entries'},
8189: $args->{'only_body'}, $args->{'domain'},
8190: $args->{'force_register'}, $args->{'no_nav_bar'},
1.1096 raeburn 8191: $args->{'bgcolor'}, $args,
8192: \@advtools);
1.831 bisitz 8193: }
1.330 albertel 8194: }
1.338 albertel 8195:
1.315 albertel 8196: if ($args->{'js_ready'}) {
1.713 kaisler 8197: $result = &js_ready($result);
1.315 albertel 8198: }
1.320 albertel 8199: if ($args->{'html_encode'}) {
1.713 kaisler 8200: $result = &html_encode($result);
8201: }
8202:
1.813 bisitz 8203: # Preparation for new and consistent functionlist at top of screen
8204: # if ($args->{'functionlist'}) {
8205: # $result .= &build_functionlist();
8206: #}
8207:
1.964 droeschl 8208: # Don't add anything more if only_body wanted or in const space
8209: return $result if $args->{'only_body'}
8210: || $env{'request.state'} eq 'construct';
1.813 bisitz 8211:
8212: #Breadcrumbs
1.758 kaisler 8213: if (exists($args->{'bread_crumbs'}) or exists($args->{'bread_crumbs_component'})) {
8214: &Apache::lonhtmlcommon::clear_breadcrumbs();
8215: #if any br links exists, add them to the breadcrumbs
8216: if (exists($args->{'bread_crumbs'}) and ref($args->{'bread_crumbs'}) eq 'ARRAY') {
8217: foreach my $crumb (@{$args->{'bread_crumbs'}}){
8218: &Apache::lonhtmlcommon::add_breadcrumb($crumb);
8219: }
8220: }
1.1096 raeburn 8221: # if @advtools array contains items add then to the breadcrumbs
8222: if (@advtools > 0) {
8223: &Apache::lonmenu::advtools_crumbs(@advtools);
8224: }
1.758 kaisler 8225:
8226: #if bread_crumbs_component exists show it as headline else show only the breadcrumbs
8227: if(exists($args->{'bread_crumbs_component'})){
8228: $result .= &Apache::lonhtmlcommon::breadcrumbs($args->{'bread_crumbs_component'});
1.1237 raeburn 8229: } elsif ($args->{'crstype'} eq 'Placement') {
8230: $result .= &Apache::lonhtmlcommon::breadcrumbs('','','','','','','','','',
8231: $args->{'crstype'});
8232: } else {
1.758 kaisler 8233: $result .= &Apache::lonhtmlcommon::breadcrumbs();
8234: }
1.320 albertel 8235: }
1.315 albertel 8236: return $result;
1.306 albertel 8237: }
8238:
8239: sub end_page {
1.315 albertel 8240: my ($args) = @_;
8241: $env{'internal.end_page'}++;
1.330 albertel 8242: my $result;
1.335 albertel 8243: if ($args->{'discussion'}) {
8244: my ($target,$parser);
8245: if (ref($args->{'discussion'})) {
8246: ($target,$parser) =($args->{'discussion'}{'target'},
8247: $args->{'discussion'}{'parser'});
8248: }
8249: $result .= &Apache::lonxml::xmlend($target,$parser);
8250: }
1.330 albertel 8251: if ($args->{'frameset'}) {
8252: $result .= '</frameset>';
8253: } else {
1.635 raeburn 8254: $result .= &endbodytag($args);
1.330 albertel 8255: }
1.1080 raeburn 8256: unless ($args->{'notbody'}) {
8257: $result .= "\n</html>";
8258: }
1.330 albertel 8259:
1.315 albertel 8260: if ($args->{'js_ready'}) {
1.317 albertel 8261: $result = &js_ready($result);
1.315 albertel 8262: }
1.335 albertel 8263:
1.320 albertel 8264: if ($args->{'html_encode'}) {
8265: $result = &html_encode($result);
8266: }
1.335 albertel 8267:
1.315 albertel 8268: return $result;
8269: }
8270:
1.1034 www 8271: sub wishlist_window {
8272: return(<<'ENDWISHLIST');
1.1046 raeburn 8273: <script type="text/javascript">
1.1034 www 8274: // <![CDATA[
8275: // <!-- BEGIN LON-CAPA Internal
8276: function set_wishlistlink(title, path) {
8277: if (!title) {
8278: title = document.title;
8279: title = title.replace(/^LON-CAPA /,'');
8280: }
1.1175 raeburn 8281: title = encodeURIComponent(title);
1.1203 raeburn 8282: title = title.replace("'","\\\'");
1.1034 www 8283: if (!path) {
8284: path = location.pathname;
8285: }
1.1175 raeburn 8286: path = encodeURIComponent(path);
1.1203 raeburn 8287: path = path.replace("'","\\\'");
1.1034 www 8288: Win = window.open('/adm/wishlist?mode=newLink&setTitle='+title+'&setPath='+path,
8289: 'wishlistNewLink','width=560,height=350,scrollbars=0');
8290: }
8291: // END LON-CAPA Internal -->
8292: // ]]>
8293: </script>
8294: ENDWISHLIST
8295: }
8296:
1.1030 www 8297: sub modal_window {
8298: return(<<'ENDMODAL');
1.1046 raeburn 8299: <script type="text/javascript">
1.1030 www 8300: // <![CDATA[
8301: // <!-- BEGIN LON-CAPA Internal
8302: var modalWindow = {
8303: parent:"body",
8304: windowId:null,
8305: content:null,
8306: width:null,
8307: height:null,
8308: close:function()
8309: {
8310: $(".LCmodal-window").remove();
8311: $(".LCmodal-overlay").remove();
8312: },
8313: open:function()
8314: {
8315: var modal = "";
8316: modal += "<div class=\"LCmodal-overlay\"></div>";
8317: 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;\">";
8318: modal += this.content;
8319: modal += "</div>";
8320:
8321: $(this.parent).append(modal);
8322:
8323: $(".LCmodal-window").append("<a class=\"LCclose-window\"></a>");
8324: $(".LCclose-window").click(function(){modalWindow.close();});
8325: $(".LCmodal-overlay").click(function(){modalWindow.close();});
8326: }
8327: };
1.1140 raeburn 8328: var openMyModal = function(source,width,height,scrolling,transparency,style)
1.1030 www 8329: {
1.1203 raeburn 8330: source = source.replace("'","'");
1.1030 www 8331: modalWindow.windowId = "myModal";
8332: modalWindow.width = width;
8333: modalWindow.height = height;
1.1196 raeburn 8334: modalWindow.content = "<iframe width='"+width+"' height='"+height+"' frameborder='0' scrolling='"+scrolling+"' allowtransparency='"+transparency+"' src='" + source + "' style='"+style+"'></iframe>";
1.1030 www 8335: modalWindow.open();
1.1208 raeburn 8336: };
1.1030 www 8337: // END LON-CAPA Internal -->
8338: // ]]>
8339: </script>
8340: ENDMODAL
8341: }
8342:
8343: sub modal_link {
1.1140 raeburn 8344: my ($link,$linktext,$width,$height,$target,$scrolling,$title,$transparency,$style)=@_;
1.1030 www 8345: unless ($width) { $width=480; }
8346: unless ($height) { $height=400; }
1.1031 www 8347: unless ($scrolling) { $scrolling='yes'; }
1.1140 raeburn 8348: unless ($transparency) { $transparency='true'; }
8349:
1.1074 raeburn 8350: my $target_attr;
8351: if (defined($target)) {
8352: $target_attr = 'target="'.$target.'"';
8353: }
8354: return <<"ENDLINK";
1.1140 raeburn 8355: <a href="$link" $target_attr title="$title" onclick="javascript:openMyModal('$link',$width,$height,'$scrolling','$transparency','$style'); return false;">
1.1074 raeburn 8356: $linktext</a>
8357: ENDLINK
1.1030 www 8358: }
8359:
1.1032 www 8360: sub modal_adhoc_script {
8361: my ($funcname,$width,$height,$content)=@_;
8362: return (<<ENDADHOC);
1.1046 raeburn 8363: <script type="text/javascript">
1.1032 www 8364: // <![CDATA[
8365: var $funcname = function()
8366: {
8367: modalWindow.windowId = "myModal";
8368: modalWindow.width = $width;
8369: modalWindow.height = $height;
8370: modalWindow.content = '$content';
8371: modalWindow.open();
8372: };
8373: // ]]>
8374: </script>
8375: ENDADHOC
8376: }
8377:
1.1041 www 8378: sub modal_adhoc_inner {
8379: my ($funcname,$width,$height,$content)=@_;
8380: my $innerwidth=$width-20;
8381: $content=&js_ready(
1.1140 raeburn 8382: &start_page('Dialog',undef,{'only_body'=>1,'bgcolor'=>'#FFFFFF'}).
8383: &start_scrollbox($width.'px',$innerwidth.'px',$height.'px','myModal','#FFFFFF',undef,1).
8384: $content.
1.1041 www 8385: &end_scrollbox().
1.1140 raeburn 8386: &end_page()
1.1041 www 8387: );
8388: return &modal_adhoc_script($funcname,$width,$height,$content);
8389: }
8390:
8391: sub modal_adhoc_window {
8392: my ($funcname,$width,$height,$content,$linktext)=@_;
8393: return &modal_adhoc_inner($funcname,$width,$height,$content).
8394: "<a href=\"javascript:$funcname();void(0);\">".$linktext."</a>";
8395: }
8396:
8397: sub modal_adhoc_launch {
8398: my ($funcname,$width,$height,$content)=@_;
8399: return &modal_adhoc_inner($funcname,$width,$height,$content).(<<ENDLAUNCH);
8400: <script type="text/javascript">
8401: // <![CDATA[
8402: $funcname();
8403: // ]]>
8404: </script>
8405: ENDLAUNCH
8406: }
8407:
8408: sub modal_adhoc_close {
8409: return (<<ENDCLOSE);
8410: <script type="text/javascript">
8411: // <![CDATA[
8412: modalWindow.close();
8413: // ]]>
8414: </script>
8415: ENDCLOSE
8416: }
8417:
1.1038 www 8418: sub togglebox_script {
8419: return(<<ENDTOGGLE);
8420: <script type="text/javascript">
8421: // <![CDATA[
8422: function LCtoggleDisplay(id,hidetext,showtext) {
8423: link = document.getElementById(id + "link").childNodes[0];
8424: with (document.getElementById(id).style) {
8425: if (display == "none" ) {
8426: display = "inline";
8427: link.nodeValue = hidetext;
8428: } else {
8429: display = "none";
8430: link.nodeValue = showtext;
8431: }
8432: }
8433: }
8434: // ]]>
8435: </script>
8436: ENDTOGGLE
8437: }
8438:
1.1039 www 8439: sub start_togglebox {
8440: my ($id,$heading,$headerbg,$hidetext,$showtext)=@_;
8441: unless ($heading) { $heading=''; } else { $heading.=' '; }
8442: unless ($showtext) { $showtext=&mt('show'); }
8443: unless ($hidetext) { $hidetext=&mt('hide'); }
8444: unless ($headerbg) { $headerbg='#FFFFFF'; }
8445: return &start_data_table().
8446: &start_data_table_header_row().
8447: '<td bgcolor="'.$headerbg.'">'.$heading.
8448: '[<a id="'.$id.'link" href="javascript:LCtoggleDisplay(\''.$id.'\',\''.$hidetext.'\',\''.
8449: $showtext.'\')">'.$showtext.'</a>]</td>'.
8450: &end_data_table_header_row().
8451: '<tr id="'.$id.'" style="display:none""><td>';
8452: }
8453:
8454: sub end_togglebox {
8455: return '</td></tr>'.&end_data_table();
8456: }
8457:
1.1041 www 8458: sub LCprogressbar_script {
1.1045 www 8459: my ($id)=@_;
1.1041 www 8460: return(<<ENDPROGRESS);
8461: <script type="text/javascript">
8462: // <![CDATA[
1.1045 www 8463: \$('#progressbar$id').progressbar({
1.1041 www 8464: value: 0,
8465: change: function(event, ui) {
8466: var newVal = \$(this).progressbar('option', 'value');
8467: \$('.pblabel', this).text(LCprogressTxt);
8468: }
8469: });
8470: // ]]>
8471: </script>
8472: ENDPROGRESS
8473: }
8474:
8475: sub LCprogressbarUpdate_script {
8476: return(<<ENDPROGRESSUPDATE);
8477: <style type="text/css">
8478: .ui-progressbar { position:relative; }
8479: .pblabel { position: absolute; width: 100%; text-align: center; line-height: 1.9em; }
8480: </style>
8481: <script type="text/javascript">
8482: // <![CDATA[
1.1045 www 8483: var LCprogressTxt='---';
8484:
8485: function LCupdateProgress(percent,progresstext,id) {
1.1041 www 8486: LCprogressTxt=progresstext;
1.1045 www 8487: \$('#progressbar'+id).progressbar('value',percent);
1.1041 www 8488: }
8489: // ]]>
8490: </script>
8491: ENDPROGRESSUPDATE
8492: }
8493:
1.1042 www 8494: my $LClastpercent;
1.1045 www 8495: my $LCidcnt;
8496: my $LCcurrentid;
1.1042 www 8497:
1.1041 www 8498: sub LCprogressbar {
1.1042 www 8499: my ($r)=(@_);
8500: $LClastpercent=0;
1.1045 www 8501: $LCidcnt++;
8502: $LCcurrentid=$$.'_'.$LCidcnt;
1.1041 www 8503: my $starting=&mt('Starting');
8504: my $content=(<<ENDPROGBAR);
1.1045 www 8505: <div id="progressbar$LCcurrentid">
1.1041 www 8506: <span class="pblabel">$starting</span>
8507: </div>
8508: ENDPROGBAR
1.1045 www 8509: &r_print($r,$content.&LCprogressbar_script($LCcurrentid));
1.1041 www 8510: }
8511:
8512: sub LCprogressbarUpdate {
1.1042 www 8513: my ($r,$val,$text)=@_;
8514: unless ($val) {
8515: if ($LClastpercent) {
8516: $val=$LClastpercent;
8517: } else {
8518: $val=0;
8519: }
8520: }
1.1041 www 8521: if ($val<0) { $val=0; }
8522: if ($val>100) { $val=0; }
1.1042 www 8523: $LClastpercent=$val;
1.1041 www 8524: unless ($text) { $text=$val.'%'; }
8525: $text=&js_ready($text);
1.1044 www 8526: &r_print($r,<<ENDUPDATE);
1.1041 www 8527: <script type="text/javascript">
8528: // <![CDATA[
1.1045 www 8529: LCupdateProgress($val,'$text','$LCcurrentid');
1.1041 www 8530: // ]]>
8531: </script>
8532: ENDUPDATE
1.1035 www 8533: }
8534:
1.1042 www 8535: sub LCprogressbarClose {
8536: my ($r)=@_;
8537: $LClastpercent=0;
1.1044 www 8538: &r_print($r,<<ENDCLOSE);
1.1042 www 8539: <script type="text/javascript">
8540: // <![CDATA[
1.1045 www 8541: \$("#progressbar$LCcurrentid").hide('slow');
1.1042 www 8542: // ]]>
8543: </script>
8544: ENDCLOSE
1.1044 www 8545: }
8546:
8547: sub r_print {
8548: my ($r,$to_print)=@_;
8549: if ($r) {
8550: $r->print($to_print);
8551: $r->rflush();
8552: } else {
8553: print($to_print);
8554: }
1.1042 www 8555: }
8556:
1.320 albertel 8557: sub html_encode {
8558: my ($result) = @_;
8559:
1.322 albertel 8560: $result = &HTML::Entities::encode($result,'<>&"');
1.320 albertel 8561:
8562: return $result;
8563: }
1.1044 www 8564:
1.317 albertel 8565: sub js_ready {
8566: my ($result) = @_;
8567:
1.323 albertel 8568: $result =~ s/[\n\r]/ /xmsg;
8569: $result =~ s/\\/\\\\/xmsg;
8570: $result =~ s/'/\\'/xmsg;
1.372 albertel 8571: $result =~ s{</}{<\\/}xmsg;
1.317 albertel 8572:
8573: return $result;
8574: }
8575:
1.315 albertel 8576: sub validate_page {
8577: if ( exists($env{'internal.start_page'})
1.316 albertel 8578: && $env{'internal.start_page'} > 1) {
8579: &Apache::lonnet::logthis('start_page called multiple times '.
1.318 albertel 8580: $env{'internal.start_page'}.' '.
1.316 albertel 8581: $ENV{'request.filename'});
1.315 albertel 8582: }
8583: if ( exists($env{'internal.end_page'})
1.316 albertel 8584: && $env{'internal.end_page'} > 1) {
8585: &Apache::lonnet::logthis('end_page called multiple times '.
1.318 albertel 8586: $env{'internal.end_page'}.' '.
1.316 albertel 8587: $env{'request.filename'});
1.315 albertel 8588: }
8589: if ( exists($env{'internal.start_page'})
8590: && ! exists($env{'internal.end_page'})) {
1.316 albertel 8591: &Apache::lonnet::logthis('start_page called without end_page '.
8592: $env{'request.filename'});
1.315 albertel 8593: }
8594: if ( ! exists($env{'internal.start_page'})
8595: && exists($env{'internal.end_page'})) {
1.316 albertel 8596: &Apache::lonnet::logthis('end_page called without start_page'.
8597: $env{'request.filename'});
1.315 albertel 8598: }
1.306 albertel 8599: }
1.315 albertel 8600:
1.996 www 8601:
8602: sub start_scrollbox {
1.1140 raeburn 8603: my ($outerwidth,$width,$height,$id,$bgcolor,$cursor,$needjsready) = @_;
1.998 raeburn 8604: unless ($outerwidth) { $outerwidth='520px'; }
8605: unless ($width) { $width='500px'; }
8606: unless ($height) { $height='200px'; }
1.1075 raeburn 8607: my ($table_id,$div_id,$tdcol);
1.1018 raeburn 8608: if ($id ne '') {
1.1140 raeburn 8609: $table_id = ' id="table_'.$id.'"';
1.1137 raeburn 8610: $div_id = ' id="div_'.$id.'"';
1.1018 raeburn 8611: }
1.1075 raeburn 8612: if ($bgcolor ne '') {
8613: $tdcol = "background-color: $bgcolor;";
8614: }
1.1137 raeburn 8615: my $nicescroll_js;
8616: if ($env{'browser.mobile'}) {
1.1140 raeburn 8617: $nicescroll_js = &nicescroll_javascript('div_'.$id,$cursor,$needjsready);
8618: }
8619: return <<"END";
8620: $nicescroll_js
8621:
8622: <table style="width: $outerwidth; border: 1px solid none;"$table_id><tr><td style="width: $width;$tdcol">
8623: <div style="overflow:auto; width:$width; height:$height;"$div_id>
8624: END
8625: }
8626:
8627: sub end_scrollbox {
8628: return '</div></td></tr></table>';
8629: }
8630:
8631: sub nicescroll_javascript {
8632: my ($id,$cursor,$needjsready,$framecheck,$location) = @_;
8633: my %options;
8634: if (ref($cursor) eq 'HASH') {
8635: %options = %{$cursor};
8636: }
8637: unless ($options{'railalign'} =~ /^left|right$/) {
8638: $options{'railalign'} = 'left';
8639: }
8640: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
8641: my $function = &get_users_function();
8642: $options{'cursorcolor'} = &designparm($function.'.sidebg',$env{'request.role.domain'});
1.1138 raeburn 8643: unless ($options{'cursorcolor'} =~ /^\#\w+$/) {
1.1140 raeburn 8644: $options{'cursorcolor'} = '#00F';
1.1138 raeburn 8645: }
1.1140 raeburn 8646: }
8647: if ($options{'cursoropacity'} =~ /^[\d.]+$/) {
8648: unless ($options{'cursoropacity'} >= 0.0 && $options{'cursoropacity'} <=1.0) {
1.1138 raeburn 8649: $options{'cursoropacity'}='1.0';
8650: }
1.1140 raeburn 8651: } else {
8652: $options{'cursoropacity'}='1.0';
8653: }
8654: if ($options{'cursorfixedheight'} eq 'none') {
8655: delete($options{'cursorfixedheight'});
8656: } else {
8657: unless ($options{'cursorfixedheight'} =~ /^\d+$/) { $options{'cursorfixedheight'}='50'; }
8658: }
8659: unless ($options{'railoffset'} =~ /^{[\w\:\d\-,]+}$/) {
8660: delete($options{'railoffset'});
8661: }
8662: my @niceoptions;
8663: while (my($key,$value) = each(%options)) {
8664: if ($value =~ /^\{.+\}$/) {
8665: push(@niceoptions,$key.':'.$value);
1.1138 raeburn 8666: } else {
1.1140 raeburn 8667: push(@niceoptions,$key.':"'.$value.'"');
1.1138 raeburn 8668: }
1.1140 raeburn 8669: }
8670: my $nicescroll_js = '
1.1137 raeburn 8671: $(document).ready(
1.1140 raeburn 8672: function() {
8673: $("#'.$id.'").niceScroll({'.join(',',@niceoptions).'});
8674: }
1.1137 raeburn 8675: );
8676: ';
1.1140 raeburn 8677: if ($framecheck) {
8678: $nicescroll_js .= '
8679: function expand_div(caller) {
8680: if (top === self) {
8681: document.getElementById("'.$id.'").style.width = "auto";
8682: document.getElementById("'.$id.'").style.height = "auto";
8683: } else {
8684: try {
8685: if (parent.frames) {
8686: if (parent.frames.length > 1) {
8687: var framesrc = parent.frames[1].location.href;
8688: var currsrc = framesrc.replace(/\#.*$/,"");
8689: if ((caller == "search") || (currsrc == "'.$location.'")) {
8690: document.getElementById("'.$id.'").style.width = "auto";
8691: document.getElementById("'.$id.'").style.height = "auto";
8692: }
8693: }
8694: }
8695: } catch (e) {
8696: return;
8697: }
1.1137 raeburn 8698: }
1.1140 raeburn 8699: return;
1.996 www 8700: }
1.1140 raeburn 8701: ';
8702: }
8703: if ($needjsready) {
8704: $nicescroll_js = '
8705: <script type="text/javascript">'."\n".$nicescroll_js."\n</script>\n";
8706: } else {
8707: $nicescroll_js = &Apache::lonhtmlcommon::scripttag($nicescroll_js);
8708: }
8709: return $nicescroll_js;
1.996 www 8710: }
8711:
1.318 albertel 8712: sub simple_error_page {
1.1150 bisitz 8713: my ($r,$title,$msg,$args) = @_;
1.1151 raeburn 8714: if (ref($args) eq 'HASH') {
8715: if (!$args->{'no_auto_mt_msg'}) { $msg = &mt($msg); }
8716: } else {
8717: $msg = &mt($msg);
8718: }
1.1150 bisitz 8719:
1.318 albertel 8720: my $page =
8721: &Apache::loncommon::start_page($title).
1.1150 bisitz 8722: '<p class="LC_error">'.$msg.'</p>'.
1.318 albertel 8723: &Apache::loncommon::end_page();
8724: if (ref($r)) {
8725: $r->print($page);
1.327 albertel 8726: return;
1.318 albertel 8727: }
8728: return $page;
8729: }
1.347 albertel 8730:
8731: {
1.610 albertel 8732: my @row_count;
1.961 onken 8733:
8734: sub start_data_table_count {
8735: unshift(@row_count, 0);
8736: return;
8737: }
8738:
8739: sub end_data_table_count {
8740: shift(@row_count);
8741: return;
8742: }
8743:
1.347 albertel 8744: sub start_data_table {
1.1018 raeburn 8745: my ($add_class,$id) = @_;
1.422 albertel 8746: my $css_class = (join(' ','LC_data_table',$add_class));
1.1018 raeburn 8747: my $table_id;
8748: if (defined($id)) {
8749: $table_id = ' id="'.$id.'"';
8750: }
1.961 onken 8751: &start_data_table_count();
1.1018 raeburn 8752: return '<table class="'.$css_class.'"'.$table_id.'>'."\n";
1.347 albertel 8753: }
8754:
8755: sub end_data_table {
1.961 onken 8756: &end_data_table_count();
1.389 albertel 8757: return '</table>'."\n";;
1.347 albertel 8758: }
8759:
8760: sub start_data_table_row {
1.974 wenzelju 8761: my ($add_class, $id) = @_;
1.610 albertel 8762: $row_count[0]++;
8763: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.900 bisitz 8764: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
1.974 wenzelju 8765: $id = (' id="'.$id.'"') unless ($id eq '');
8766: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.347 albertel 8767: }
1.471 banghart 8768:
8769: sub continue_data_table_row {
1.974 wenzelju 8770: my ($add_class, $id) = @_;
1.610 albertel 8771: my $css_class = ($row_count[0] % 2)?'LC_odd_row':'LC_even_row';
1.974 wenzelju 8772: $css_class = (join(' ',$css_class,$add_class)) unless ($add_class eq '');
8773: $id = (' id="'.$id.'"') unless ($id eq '');
8774: return '<tr class="'.$css_class.'"'.$id.'>'."\n";
1.471 banghart 8775: }
1.347 albertel 8776:
8777: sub end_data_table_row {
1.389 albertel 8778: return '</tr>'."\n";;
1.347 albertel 8779: }
1.367 www 8780:
1.421 albertel 8781: sub start_data_table_empty_row {
1.707 bisitz 8782: # $row_count[0]++;
1.421 albertel 8783: return '<tr class="LC_empty_row" >'."\n";;
8784: }
8785:
8786: sub end_data_table_empty_row {
8787: return '</tr>'."\n";;
8788: }
8789:
1.367 www 8790: sub start_data_table_header_row {
1.389 albertel 8791: return '<tr class="LC_header_row">'."\n";;
1.367 www 8792: }
8793:
8794: sub end_data_table_header_row {
1.389 albertel 8795: return '</tr>'."\n";;
1.367 www 8796: }
1.890 droeschl 8797:
8798: sub data_table_caption {
8799: my $caption = shift;
8800: return "<caption class=\"LC_caption\">$caption</caption>";
8801: }
1.347 albertel 8802: }
8803:
1.548 albertel 8804: =pod
8805:
8806: =item * &inhibit_menu_check($arg)
8807:
8808: Checks for a inhibitmenu state and generates output to preserve it
8809:
8810: Inputs: $arg - can be any of
8811: - undef - in which case the return value is a string
8812: to add into arguments list of a uri
8813: - 'input' - in which case the return value is a HTML
8814: <form> <input> field of type hidden to
8815: preserve the value
8816: - a url - in which case the return value is the url with
8817: the neccesary cgi args added to preserve the
8818: inhibitmenu state
8819: - a ref to a url - no return value, but the string is
8820: updated to include the neccessary cgi
8821: args to preserve the inhibitmenu state
8822:
8823: =cut
8824:
8825: sub inhibit_menu_check {
8826: my ($arg) = @_;
8827: &get_unprocessed_cgi($ENV{'QUERY_STRING'}, ['inhibitmenu']);
8828: if ($arg eq 'input') {
8829: if ($env{'form.inhibitmenu'}) {
8830: return '<input type="hidden" name="inhibitmenu" value="'.$env{'form.inhibitmenu'}.'" />';
8831: } else {
8832: return
8833: }
8834: }
8835: if ($env{'form.inhibitmenu'}) {
8836: if (ref($arg)) {
8837: $$arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8838: } elsif ($arg eq '') {
8839: $arg .= 'inhibitmenu='.$env{'form.inhibitmenu'};
8840: } else {
8841: $arg .= '?inhibitmenu='.$env{'form.inhibitmenu'};
8842: }
8843: }
8844: if (!ref($arg)) {
8845: return $arg;
8846: }
8847: }
8848:
1.251 albertel 8849: ###############################################
1.182 matthew 8850:
8851: =pod
8852:
1.549 albertel 8853: =back
8854:
8855: =head1 User Information Routines
8856:
8857: =over 4
8858:
1.405 albertel 8859: =item * &get_users_function()
1.182 matthew 8860:
8861: Used by &bodytag to determine the current users primary role.
8862: Returns either 'student','coordinator','admin', or 'author'.
8863:
8864: =cut
8865:
8866: ###############################################
8867: sub get_users_function {
1.815 tempelho 8868: my $function = 'norole';
1.818 tempelho 8869: if ($env{'request.role'}=~/^(st)/) {
8870: $function='student';
8871: }
1.907 raeburn 8872: if ($env{'request.role'}=~/^(cc|co|in|ta|ep)/) {
1.182 matthew 8873: $function='coordinator';
8874: }
1.258 albertel 8875: if ($env{'request.role'}=~/^(su|dc|ad|li)/) {
1.182 matthew 8876: $function='admin';
8877: }
1.826 bisitz 8878: if (($env{'request.role'}=~/^(au|ca|aa)/) ||
1.1025 raeburn 8879: ($ENV{'REQUEST_URI'}=~ m{/^(/priv)})) {
1.182 matthew 8880: $function='author';
8881: }
8882: return $function;
1.54 www 8883: }
1.99 www 8884:
8885: ###############################################
8886:
1.233 raeburn 8887: =pod
8888:
1.821 raeburn 8889: =item * &show_course()
8890:
8891: Used by lonmenu.pm and lonroles.pm to determine whether to use the word
8892: 'Courses' or 'Roles' in inline navigation and on screen displaying user's roles.
8893:
8894: Inputs:
8895: None
8896:
8897: Outputs:
8898: Scalar: 1 if 'Course' to be used, 0 otherwise.
8899:
8900: =cut
8901:
8902: ###############################################
8903: sub show_course {
8904: my $course = !$env{'user.adv'};
8905: if (!$env{'user.adv'}) {
8906: foreach my $env (keys(%env)) {
8907: next if ($env !~ m/^user\.priv\./);
8908: if ($env !~ m/^user\.priv\.(?:st|cm)/) {
8909: $course = 0;
8910: last;
8911: }
8912: }
8913: }
8914: return $course;
8915: }
8916:
8917: ###############################################
8918:
8919: =pod
8920:
1.542 raeburn 8921: =item * &check_user_status()
1.274 raeburn 8922:
8923: Determines current status of supplied role for a
8924: specific user. Roles can be active, previous or future.
8925:
8926: Inputs:
8927: user's domain, user's username, course's domain,
1.375 raeburn 8928: course's number, optional section ID.
1.274 raeburn 8929:
8930: Outputs:
8931: role status: active, previous or future.
8932:
8933: =cut
8934:
8935: sub check_user_status {
1.412 raeburn 8936: my ($udom,$uname,$cdom,$crs,$role,$sec) = @_;
1.1073 raeburn 8937: my %userinfo = &Apache::lonnet::dump('roles',$udom,$uname);
1.1202 raeburn 8938: my @uroles = keys(%userinfo);
1.274 raeburn 8939: my $srchstr;
8940: my $active_chk = 'none';
1.412 raeburn 8941: my $now = time;
1.274 raeburn 8942: if (@uroles > 0) {
1.908 raeburn 8943: if (($role eq 'cc') || ($role eq 'co') || ($sec eq '') || (!defined($sec))) {
1.274 raeburn 8944: $srchstr = '/'.$cdom.'/'.$crs.'_'.$role;
8945: } else {
1.412 raeburn 8946: $srchstr = '/'.$cdom.'/'.$crs.'/'.$sec.'_'.$role;
8947: }
8948: if (grep/^\Q$srchstr\E$/,@uroles) {
1.274 raeburn 8949: my $role_end = 0;
8950: my $role_start = 0;
8951: $active_chk = 'active';
1.412 raeburn 8952: if ($userinfo{$srchstr} =~ m/^\Q$role\E_(\d+)/) {
8953: $role_end = $1;
8954: if ($userinfo{$srchstr} =~ m/^\Q$role\E_\Q$role_end\E_(\d+)$/) {
8955: $role_start = $1;
1.274 raeburn 8956: }
8957: }
8958: if ($role_start > 0) {
1.412 raeburn 8959: if ($now < $role_start) {
1.274 raeburn 8960: $active_chk = 'future';
8961: }
8962: }
8963: if ($role_end > 0) {
1.412 raeburn 8964: if ($now > $role_end) {
1.274 raeburn 8965: $active_chk = 'previous';
8966: }
8967: }
8968: }
8969: }
8970: return $active_chk;
8971: }
8972:
8973: ###############################################
8974:
8975: =pod
8976:
1.405 albertel 8977: =item * &get_sections()
1.233 raeburn 8978:
8979: Determines all the sections for a course including
8980: sections with students and sections containing other roles.
1.419 raeburn 8981: Incoming parameters:
8982:
8983: 1. domain
8984: 2. course number
8985: 3. reference to array containing roles for which sections should
8986: be gathered (optional).
8987: 4. reference to array containing status types for which sections
8988: should be gathered (optional).
8989:
8990: If the third argument is undefined, sections are gathered for any role.
8991: If the fourth argument is undefined, sections are gathered for any status.
8992: Permissible values are 'active' or 'future' or 'previous'.
1.233 raeburn 8993:
1.374 raeburn 8994: Returns section hash (keys are section IDs, values are
8995: number of users in each section), subject to the
1.419 raeburn 8996: optional roles filter, optional status filter
1.233 raeburn 8997:
8998: =cut
8999:
9000: ###############################################
9001: sub get_sections {
1.419 raeburn 9002: my ($cdom,$cnum,$possible_roles,$possible_status) = @_;
1.366 albertel 9003: if (!defined($cdom) || !defined($cnum)) {
9004: my $cid = $env{'request.course.id'};
9005:
9006: return if (!defined($cid));
9007:
9008: $cdom = $env{'course.'.$cid.'.domain'};
9009: $cnum = $env{'course.'.$cid.'.num'};
9010: }
9011:
9012: my %sectioncount;
1.419 raeburn 9013: my $now = time;
1.240 albertel 9014:
1.1118 raeburn 9015: my $check_students = 1;
9016: my $only_students = 0;
9017: if (ref($possible_roles) eq 'ARRAY') {
9018: if (grep(/^st$/,@{$possible_roles})) {
9019: if (@{$possible_roles} == 1) {
9020: $only_students = 1;
9021: }
9022: } else {
9023: $check_students = 0;
9024: }
9025: }
9026:
9027: if ($check_students) {
1.276 albertel 9028: my ($classlist) = &Apache::loncoursedata::get_classlist($cdom,$cnum);
1.240 albertel 9029: my $sec_index = &Apache::loncoursedata::CL_SECTION();
9030: my $status_index = &Apache::loncoursedata::CL_STATUS();
1.419 raeburn 9031: my $start_index = &Apache::loncoursedata::CL_START();
9032: my $end_index = &Apache::loncoursedata::CL_END();
9033: my $status;
1.366 albertel 9034: while (my ($student,$data) = each(%$classlist)) {
1.419 raeburn 9035: my ($section,$stu_status,$start,$end) = ($data->[$sec_index],
9036: $data->[$status_index],
9037: $data->[$start_index],
9038: $data->[$end_index]);
9039: if ($stu_status eq 'Active') {
9040: $status = 'active';
9041: } elsif ($end < $now) {
9042: $status = 'previous';
9043: } elsif ($start > $now) {
9044: $status = 'future';
9045: }
9046: if ($section ne '-1' && $section !~ /^\s*$/) {
9047: if ((!defined($possible_status)) || (($status ne '') &&
9048: (grep/^\Q$status\E$/,@{$possible_status}))) {
9049: $sectioncount{$section}++;
9050: }
1.240 albertel 9051: }
9052: }
9053: }
1.1118 raeburn 9054: if ($only_students) {
9055: return %sectioncount;
9056: }
1.240 albertel 9057: my %courseroles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9058: foreach my $user (sort(keys(%courseroles))) {
9059: if ($user !~ /^(\w{2})/) { next; }
9060: my ($role) = ($user =~ /^(\w{2})/);
9061: if ($possible_roles && !(grep(/^$role$/,@$possible_roles))) { next; }
1.419 raeburn 9062: my ($section,$status);
1.240 albertel 9063: if ($role eq 'cr' &&
9064: $user =~ m-^$role/[^/]*/[^/]*/[^/]*:[^:]*:[^:]*:(\w+)-) {
9065: $section=$1;
9066: }
9067: if ($user =~ /^$role:[^:]*:[^:]*:(\w+)/) { $section=$1; }
9068: if (!defined($section) || $section eq '-1') { next; }
1.419 raeburn 9069: my ($end,$start) = ($courseroles{$user} =~ /^([^:]*):([^:]*)$/);
9070: if ($end == -1 && $start == -1) {
9071: next; #deleted role
9072: }
9073: if (!defined($possible_status)) {
9074: $sectioncount{$section}++;
9075: } else {
9076: if ((!$end || $end >= $now) && (!$start || $start <= $now)) {
9077: $status = 'active';
9078: } elsif ($end < $now) {
9079: $status = 'future';
9080: } elsif ($start > $now) {
9081: $status = 'previous';
9082: }
9083: if (($status ne '') && (grep/^\Q$status\E$/,@{$possible_status})) {
9084: $sectioncount{$section}++;
9085: }
9086: }
1.233 raeburn 9087: }
1.366 albertel 9088: return %sectioncount;
1.233 raeburn 9089: }
9090:
1.274 raeburn 9091: ###############################################
1.294 raeburn 9092:
9093: =pod
1.405 albertel 9094:
9095: =item * &get_course_users()
9096:
1.275 raeburn 9097: Retrieves usernames:domains for users in the specified course
9098: with specific role(s), and access status.
9099:
9100: Incoming parameters:
1.277 albertel 9101: 1. course domain
9102: 2. course number
9103: 3. access status: users must have - either active,
1.275 raeburn 9104: previous, future, or all.
1.277 albertel 9105: 4. reference to array of permissible roles
1.288 raeburn 9106: 5. reference to array of section restrictions (optional)
9107: 6. reference to results object (hash of hashes).
9108: 7. reference to optional userdata hash
1.609 raeburn 9109: 8. reference to optional statushash
1.630 raeburn 9110: 9. flag if privileged users (except those set to unhide in
9111: course settings) should be excluded
1.609 raeburn 9112: Keys of top level results hash are roles.
1.275 raeburn 9113: Keys of inner hashes are username:domain, with
9114: values set to access type.
1.288 raeburn 9115: Optional userdata hash returns an array with arguments in the
9116: same order as loncoursedata::get_classlist() for student data.
9117:
1.609 raeburn 9118: Optional statushash returns
9119:
1.288 raeburn 9120: Entries for end, start, section and status are blank because
9121: of the possibility of multiple values for non-student roles.
9122:
1.275 raeburn 9123: =cut
1.405 albertel 9124:
1.275 raeburn 9125: ###############################################
1.405 albertel 9126:
1.275 raeburn 9127: sub get_course_users {
1.630 raeburn 9128: my ($cdom,$cnum,$types,$roles,$sections,$users,$userdata,$statushash,$hidepriv) = @_;
1.288 raeburn 9129: my %idx = ();
1.419 raeburn 9130: my %seclists;
1.288 raeburn 9131:
9132: $idx{udom} = &Apache::loncoursedata::CL_SDOM();
9133: $idx{uname} = &Apache::loncoursedata::CL_SNAME();
9134: $idx{end} = &Apache::loncoursedata::CL_END();
9135: $idx{start} = &Apache::loncoursedata::CL_START();
9136: $idx{id} = &Apache::loncoursedata::CL_ID();
9137: $idx{section} = &Apache::loncoursedata::CL_SECTION();
9138: $idx{fullname} = &Apache::loncoursedata::CL_FULLNAME();
9139: $idx{status} = &Apache::loncoursedata::CL_STATUS();
9140:
1.290 albertel 9141: if (grep(/^st$/,@{$roles})) {
1.276 albertel 9142: my ($classlist,$keylist)=&Apache::loncoursedata::get_classlist($cdom,$cnum);
1.278 raeburn 9143: my $now = time;
1.277 albertel 9144: foreach my $student (keys(%{$classlist})) {
1.288 raeburn 9145: my $match = 0;
1.412 raeburn 9146: my $secmatch = 0;
1.419 raeburn 9147: my $section = $$classlist{$student}[$idx{section}];
1.609 raeburn 9148: my $status = $$classlist{$student}[$idx{status}];
1.419 raeburn 9149: if ($section eq '') {
9150: $section = 'none';
9151: }
1.291 albertel 9152: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9153: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9154: $secmatch = 1;
9155: } elsif ($$classlist{$student}[$idx{section}] eq '') {
1.420 albertel 9156: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9157: $secmatch = 1;
9158: }
9159: } else {
1.419 raeburn 9160: if (grep(/^\Q$section\E$/,@{$sections})) {
1.412 raeburn 9161: $secmatch = 1;
9162: }
1.290 albertel 9163: }
1.412 raeburn 9164: if (!$secmatch) {
9165: next;
9166: }
1.419 raeburn 9167: }
1.275 raeburn 9168: if (defined($$types{'active'})) {
1.288 raeburn 9169: if ($$classlist{$student}[$idx{status}] eq 'Active') {
1.275 raeburn 9170: push(@{$$users{st}{$student}},'active');
1.288 raeburn 9171: $match = 1;
1.275 raeburn 9172: }
9173: }
9174: if (defined($$types{'previous'})) {
1.609 raeburn 9175: if ($$classlist{$student}[$idx{status}] eq 'Expired') {
1.275 raeburn 9176: push(@{$$users{st}{$student}},'previous');
1.288 raeburn 9177: $match = 1;
1.275 raeburn 9178: }
9179: }
9180: if (defined($$types{'future'})) {
1.609 raeburn 9181: if ($$classlist{$student}[$idx{status}] eq 'Future') {
1.275 raeburn 9182: push(@{$$users{st}{$student}},'future');
1.288 raeburn 9183: $match = 1;
1.275 raeburn 9184: }
9185: }
1.609 raeburn 9186: if ($match) {
9187: push(@{$seclists{$student}},$section);
9188: if (ref($userdata) eq 'HASH') {
9189: $$userdata{$student} = $$classlist{$student};
9190: }
9191: if (ref($statushash) eq 'HASH') {
9192: $statushash->{$student}{'st'}{$section} = $status;
9193: }
1.288 raeburn 9194: }
1.275 raeburn 9195: }
9196: }
1.412 raeburn 9197: if ((@{$roles} > 1) || ((@{$roles} == 1) && ($$roles[0] ne "st"))) {
1.439 raeburn 9198: my %coursepersonnel = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9199: my $now = time;
1.609 raeburn 9200: my %displaystatus = ( previous => 'Expired',
9201: active => 'Active',
9202: future => 'Future',
9203: );
1.1121 raeburn 9204: my (%nothide,@possdoms);
1.630 raeburn 9205: if ($hidepriv) {
9206: my %coursehash=&Apache::lonnet::coursedescription($cdom.'_'.$cnum);
9207: foreach my $user (split(/\s*\,\s*/,$coursehash{'nothideprivileged'})) {
9208: if ($user !~ /:/) {
9209: $nothide{join(':',split(/[\@]/,$user))}=1;
9210: } else {
9211: $nothide{$user} = 1;
9212: }
9213: }
1.1121 raeburn 9214: my @possdoms = ($cdom);
9215: if ($coursehash{'checkforpriv'}) {
9216: push(@possdoms,split(/,/,$coursehash{'checkforpriv'}));
9217: }
1.630 raeburn 9218: }
1.439 raeburn 9219: foreach my $person (sort(keys(%coursepersonnel))) {
1.288 raeburn 9220: my $match = 0;
1.412 raeburn 9221: my $secmatch = 0;
1.439 raeburn 9222: my $status;
1.412 raeburn 9223: my ($role,$user,$usec) = ($person =~ /^([^:]*):([^:]+:[^:]+):([^:]*)/);
1.275 raeburn 9224: $user =~ s/:$//;
1.439 raeburn 9225: my ($end,$start) = split(/:/,$coursepersonnel{$person});
9226: if ($end == -1 || $start == -1) {
9227: next;
9228: }
9229: if (($role) && ((grep(/^\Q$role\E$/,@{$roles})) ||
9230: (grep(/^cr$/,@{$roles}) && $role =~ /^cr\//))) {
1.412 raeburn 9231: my ($uname,$udom) = split(/:/,$user);
9232: if ((ref($sections) eq 'ARRAY') && (@{$sections} > 0)) {
1.420 albertel 9233: if (grep(/^all$/,@{$sections})) {
1.412 raeburn 9234: $secmatch = 1;
9235: } elsif ($usec eq '') {
1.420 albertel 9236: if (grep(/^none$/,@{$sections})) {
1.412 raeburn 9237: $secmatch = 1;
9238: }
9239: } else {
9240: if (grep(/^\Q$usec\E$/,@{$sections})) {
9241: $secmatch = 1;
9242: }
9243: }
9244: if (!$secmatch) {
9245: next;
9246: }
1.288 raeburn 9247: }
1.419 raeburn 9248: if ($usec eq '') {
9249: $usec = 'none';
9250: }
1.275 raeburn 9251: if ($uname ne '' && $udom ne '') {
1.630 raeburn 9252: if ($hidepriv) {
1.1121 raeburn 9253: if ((&Apache::lonnet::privileged($uname,$udom,\@possdoms)) &&
1.630 raeburn 9254: (!$nothide{$uname.':'.$udom})) {
9255: next;
9256: }
9257: }
1.503 raeburn 9258: if ($end > 0 && $end < $now) {
1.439 raeburn 9259: $status = 'previous';
9260: } elsif ($start > $now) {
9261: $status = 'future';
9262: } else {
9263: $status = 'active';
9264: }
1.277 albertel 9265: foreach my $type (keys(%{$types})) {
1.275 raeburn 9266: if ($status eq $type) {
1.420 albertel 9267: if (!grep(/^\Q$type\E$/,@{$$users{$role}{$user}})) {
1.419 raeburn 9268: push(@{$$users{$role}{$user}},$type);
9269: }
1.288 raeburn 9270: $match = 1;
9271: }
9272: }
1.419 raeburn 9273: if (($match) && (ref($userdata) eq 'HASH')) {
9274: if (!exists($$userdata{$uname.':'.$udom})) {
9275: &get_user_info($udom,$uname,\%idx,$userdata);
9276: }
1.420 albertel 9277: if (!grep(/^\Q$usec\E$/,@{$seclists{$uname.':'.$udom}})) {
1.419 raeburn 9278: push(@{$seclists{$uname.':'.$udom}},$usec);
9279: }
1.609 raeburn 9280: if (ref($statushash) eq 'HASH') {
9281: $statushash->{$uname.':'.$udom}{$role}{$usec} = $displaystatus{$status};
9282: }
1.275 raeburn 9283: }
9284: }
9285: }
9286: }
1.290 albertel 9287: if (grep(/^ow$/,@{$roles})) {
1.279 raeburn 9288: if ((defined($cdom)) && (defined($cnum))) {
9289: my %csettings = &Apache::lonnet::get('environment',['internal.courseowner'],$cdom,$cnum);
9290: if ( defined($csettings{'internal.courseowner'}) ) {
9291: my $owner = $csettings{'internal.courseowner'};
1.609 raeburn 9292: next if ($owner eq '');
9293: my ($ownername,$ownerdom);
9294: if ($owner =~ /^([^:]+):([^:]+)$/) {
9295: $ownername = $1;
9296: $ownerdom = $2;
9297: } else {
9298: $ownername = $owner;
9299: $ownerdom = $cdom;
9300: $owner = $ownername.':'.$ownerdom;
1.439 raeburn 9301: }
9302: @{$$users{'ow'}{$owner}} = 'any';
1.290 albertel 9303: if (defined($userdata) &&
1.609 raeburn 9304: !exists($$userdata{$owner})) {
9305: &get_user_info($ownerdom,$ownername,\%idx,$userdata);
9306: if (!grep(/^none$/,@{$seclists{$owner}})) {
9307: push(@{$seclists{$owner}},'none');
9308: }
9309: if (ref($statushash) eq 'HASH') {
9310: $statushash->{$owner}{'ow'}{'none'} = 'Any';
1.419 raeburn 9311: }
1.290 albertel 9312: }
1.279 raeburn 9313: }
9314: }
9315: }
1.419 raeburn 9316: foreach my $user (keys(%seclists)) {
9317: @{$seclists{$user}} = (sort {$a <=> $b} @{$seclists{$user}});
9318: $$userdata{$user}[$idx{section}] = join(',',@{$seclists{$user}});
9319: }
1.275 raeburn 9320: }
9321: return;
9322: }
9323:
1.288 raeburn 9324: sub get_user_info {
9325: my ($udom,$uname,$idx,$userdata) = @_;
1.289 albertel 9326: $$userdata{$uname.':'.$udom}[$$idx{fullname}] =
9327: &plainname($uname,$udom,'lastname');
1.291 albertel 9328: $$userdata{$uname.':'.$udom}[$$idx{uname}] = $uname;
1.297 raeburn 9329: $$userdata{$uname.':'.$udom}[$$idx{udom}] = $udom;
1.609 raeburn 9330: my %idhash = &Apache::lonnet::idrget($udom,($uname));
9331: $$userdata{$uname.':'.$udom}[$$idx{id}] = $idhash{$uname};
1.288 raeburn 9332: return;
9333: }
1.275 raeburn 9334:
1.472 raeburn 9335: ###############################################
9336:
9337: =pod
9338:
9339: =item * &get_user_quota()
9340:
1.1134 raeburn 9341: Retrieves quota assigned for storage of user files.
9342: Default is to report quota for portfolio files.
1.472 raeburn 9343:
9344: Incoming parameters:
9345: 1. user's username
9346: 2. user's domain
1.1134 raeburn 9347: 3. quota name - portfolio, author, or course
1.1136 raeburn 9348: (if no quota name provided, defaults to portfolio).
1.1237 raeburn 9349: 4. crstype - official, unofficial, textbook, placement or community,
9350: if quota name is course
1.472 raeburn 9351:
9352: Returns:
1.1163 raeburn 9353: 1. Disk quota (in MB) assigned to student.
1.536 raeburn 9354: 2. (Optional) Type of setting: custom or default
9355: (individually assigned or default for user's
9356: institutional status).
9357: 3. (Optional) - User's institutional status (e.g., faculty, staff
9358: or student - types as defined in localenroll::inst_usertypes
9359: for user's domain, which determines default quota for user.
9360: 4. (Optional) - Default quota which would apply to the user.
1.472 raeburn 9361:
9362: If a value has been stored in the user's environment,
1.536 raeburn 9363: it will return that, otherwise it returns the maximal default
1.1134 raeburn 9364: defined for the user's institutional status(es) in the domain.
1.472 raeburn 9365:
9366: =cut
9367:
9368: ###############################################
9369:
9370:
9371: sub get_user_quota {
1.1136 raeburn 9372: my ($uname,$udom,$quotaname,$crstype) = @_;
1.536 raeburn 9373: my ($quota,$quotatype,$settingstatus,$defquota);
1.472 raeburn 9374: if (!defined($udom)) {
9375: $udom = $env{'user.domain'};
9376: }
9377: if (!defined($uname)) {
9378: $uname = $env{'user.name'};
9379: }
9380: if (($udom eq '' || $uname eq '') ||
9381: ($udom eq 'public') && ($uname eq 'public')) {
9382: $quota = 0;
1.536 raeburn 9383: $quotatype = 'default';
9384: $defquota = 0;
1.472 raeburn 9385: } else {
1.536 raeburn 9386: my $inststatus;
1.1134 raeburn 9387: if ($quotaname eq 'course') {
9388: if (($env{'course.'.$udom.'_'.$uname.'.num'} eq $uname) &&
9389: ($env{'course.'.$udom.'_'.$uname.'.domain'} eq $udom)) {
9390: $quota = $env{'course.'.$udom.'_'.$uname.'.internal.uploadquota'};
9391: } else {
9392: my %cenv = &Apache::lonnet::coursedescription("$udom/$uname");
9393: $quota = $cenv{'internal.uploadquota'};
9394: }
1.536 raeburn 9395: } else {
1.1134 raeburn 9396: if ($udom eq $env{'user.domain'} && $uname eq $env{'user.name'}) {
9397: if ($quotaname eq 'author') {
9398: $quota = $env{'environment.authorquota'};
9399: } else {
9400: $quota = $env{'environment.portfolioquota'};
9401: }
9402: $inststatus = $env{'environment.inststatus'};
9403: } else {
9404: my %userenv =
9405: &Apache::lonnet::get('environment',['portfolioquota',
9406: 'authorquota','inststatus'],$udom,$uname);
9407: my ($tmp) = keys(%userenv);
9408: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
9409: if ($quotaname eq 'author') {
9410: $quota = $userenv{'authorquota'};
9411: } else {
9412: $quota = $userenv{'portfolioquota'};
9413: }
9414: $inststatus = $userenv{'inststatus'};
9415: } else {
9416: undef(%userenv);
9417: }
9418: }
9419: }
9420: if ($quota eq '' || wantarray) {
9421: if ($quotaname eq 'course') {
9422: my %domdefs = &Apache::lonnet::get_domain_defaults($udom);
1.1165 raeburn 9423: if (($crstype eq 'official') || ($crstype eq 'unofficial') ||
1.1237 raeburn 9424: ($crstype eq 'community') || ($crstype eq 'textbook') ||
9425: ($crstype eq 'placement')) {
1.1136 raeburn 9426: $defquota = $domdefs{$crstype.'quota'};
9427: }
9428: if ($defquota eq '') {
9429: $defquota = 500;
9430: }
1.1134 raeburn 9431: } else {
9432: ($defquota,$settingstatus) = &default_quota($udom,$inststatus,$quotaname);
9433: }
9434: if ($quota eq '') {
9435: $quota = $defquota;
9436: $quotatype = 'default';
9437: } else {
9438: $quotatype = 'custom';
9439: }
1.472 raeburn 9440: }
9441: }
1.536 raeburn 9442: if (wantarray) {
9443: return ($quota,$quotatype,$settingstatus,$defquota);
9444: } else {
9445: return $quota;
9446: }
1.472 raeburn 9447: }
9448:
9449: ###############################################
9450:
9451: =pod
9452:
9453: =item * &default_quota()
9454:
1.536 raeburn 9455: Retrieves default quota assigned for storage of user portfolio files,
9456: given an (optional) user's institutional status.
1.472 raeburn 9457:
9458: Incoming parameters:
1.1142 raeburn 9459:
1.472 raeburn 9460: 1. domain
1.536 raeburn 9461: 2. (Optional) institutional status(es). This is a : separated list of
9462: status types (e.g., faculty, staff, student etc.)
9463: which apply to the user for whom the default is being retrieved.
9464: If the institutional status string in undefined, the domain
1.1134 raeburn 9465: default quota will be returned.
9466: 3. quota name - portfolio, author, or course
9467: (if no quota name provided, defaults to portfolio).
1.472 raeburn 9468:
9469: Returns:
1.1142 raeburn 9470:
1.1163 raeburn 9471: 1. Default disk quota (in MB) for user portfolios in the domain.
1.536 raeburn 9472: 2. (Optional) institutional type which determined the value of the
9473: default quota.
1.472 raeburn 9474:
9475: If a value has been stored in the domain's configuration db,
9476: it will return that, otherwise it returns 20 (for backwards
9477: compatibility with domains which have not set up a configuration
1.1163 raeburn 9478: db file; the original statically defined portfolio quota was 20 MB).
1.472 raeburn 9479:
1.536 raeburn 9480: If the user's status includes multiple types (e.g., staff and student),
9481: the largest default quota which applies to the user determines the
9482: default quota returned.
9483:
1.472 raeburn 9484: =cut
9485:
9486: ###############################################
9487:
9488:
9489: sub default_quota {
1.1134 raeburn 9490: my ($udom,$inststatus,$quotaname) = @_;
1.536 raeburn 9491: my ($defquota,$settingstatus);
9492: my %quotahash = &Apache::lonnet::get_dom('configuration',
1.622 raeburn 9493: ['quotas'],$udom);
1.1134 raeburn 9494: my $key = 'defaultquota';
9495: if ($quotaname eq 'author') {
9496: $key = 'authorquota';
9497: }
1.622 raeburn 9498: if (ref($quotahash{'quotas'}) eq 'HASH') {
1.536 raeburn 9499: if ($inststatus ne '') {
1.765 raeburn 9500: my @statuses = map { &unescape($_); } split(/:/,$inststatus);
1.536 raeburn 9501: foreach my $item (@statuses) {
1.1134 raeburn 9502: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9503: if ($quotahash{'quotas'}{$key}{$item} ne '') {
1.711 raeburn 9504: if ($defquota eq '') {
1.1134 raeburn 9505: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9506: $settingstatus = $item;
1.1134 raeburn 9507: } elsif ($quotahash{'quotas'}{$key}{$item} > $defquota) {
9508: $defquota = $quotahash{'quotas'}{$key}{$item};
1.711 raeburn 9509: $settingstatus = $item;
9510: }
9511: }
1.1134 raeburn 9512: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9513: if ($quotahash{'quotas'}{$item} ne '') {
9514: if ($defquota eq '') {
9515: $defquota = $quotahash{'quotas'}{$item};
9516: $settingstatus = $item;
9517: } elsif ($quotahash{'quotas'}{$item} > $defquota) {
9518: $defquota = $quotahash{'quotas'}{$item};
9519: $settingstatus = $item;
9520: }
1.536 raeburn 9521: }
9522: }
9523: }
9524: }
9525: if ($defquota eq '') {
1.1134 raeburn 9526: if (ref($quotahash{'quotas'}{$key}) eq 'HASH') {
9527: $defquota = $quotahash{'quotas'}{$key}{'default'};
9528: } elsif ($key eq 'defaultquota') {
1.711 raeburn 9529: $defquota = $quotahash{'quotas'}{'default'};
9530: }
1.536 raeburn 9531: $settingstatus = 'default';
1.1139 raeburn 9532: if ($defquota eq '') {
9533: if ($quotaname eq 'author') {
9534: $defquota = 500;
9535: }
9536: }
1.536 raeburn 9537: }
9538: } else {
9539: $settingstatus = 'default';
1.1134 raeburn 9540: if ($quotaname eq 'author') {
9541: $defquota = 500;
9542: } else {
9543: $defquota = 20;
9544: }
1.536 raeburn 9545: }
9546: if (wantarray) {
9547: return ($defquota,$settingstatus);
1.472 raeburn 9548: } else {
1.536 raeburn 9549: return $defquota;
1.472 raeburn 9550: }
9551: }
9552:
1.1135 raeburn 9553: ###############################################
9554:
9555: =pod
9556:
1.1136 raeburn 9557: =item * &excess_filesize_warning()
1.1135 raeburn 9558:
9559: Returns warning message if upload of file to authoring space, or copying
1.1136 raeburn 9560: of existing file within authoring space will cause quota for the authoring
1.1146 raeburn 9561: space to be exceeded.
1.1136 raeburn 9562:
9563: Same, if upload of a file directly to a course/community via Course Editor
1.1137 raeburn 9564: will cause quota for uploaded content for the course to be exceeded.
1.1135 raeburn 9565:
1.1165 raeburn 9566: Inputs: 7
1.1136 raeburn 9567: 1. username or coursenum
1.1135 raeburn 9568: 2. domain
1.1136 raeburn 9569: 3. context ('author' or 'course')
1.1135 raeburn 9570: 4. filename of file for which action is being requested
9571: 5. filesize (kB) of file
9572: 6. action being taken: copy or upload.
1.1237 raeburn 9573: 7. quotatype (in course context -- official, unofficial, textbook, placement or community).
1.1135 raeburn 9574:
9575: Returns: 1 scalar: HTML to display containing warning if quota would be exceeded,
1.1142 raeburn 9576: otherwise return null.
9577:
9578: =back
1.1135 raeburn 9579:
9580: =cut
9581:
1.1136 raeburn 9582: sub excess_filesize_warning {
1.1165 raeburn 9583: my ($uname,$udom,$context,$filename,$filesize,$action,$quotatype) = @_;
1.1136 raeburn 9584: my $current_disk_usage = 0;
1.1165 raeburn 9585: my $disk_quota = &get_user_quota($uname,$udom,$context,$quotatype); #expressed in MB
1.1136 raeburn 9586: if ($context eq 'author') {
9587: my $authorspace = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname";
9588: $current_disk_usage = &Apache::lonnet::diskusage($udom,$uname,$authorspace);
9589: } else {
9590: foreach my $subdir ('docs','supplemental') {
9591: $current_disk_usage += &Apache::lonnet::diskusage($udom,$uname,"userfiles/$subdir",1);
9592: }
9593: }
1.1135 raeburn 9594: $disk_quota = int($disk_quota * 1000);
9595: if (($current_disk_usage + $filesize) > $disk_quota) {
1.1179 bisitz 9596: return '<p class="LC_warning">'.
1.1135 raeburn 9597: &mt("Unable to $action [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.",
1.1179 bisitz 9598: '<span class="LC_filename">'.$filename.'</span>',$filesize).'</p>'.
9599: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
1.1135 raeburn 9600: $disk_quota,$current_disk_usage).
9601: '</p>';
9602: }
9603: return;
9604: }
9605:
9606: ###############################################
9607:
9608:
1.1136 raeburn 9609:
9610:
1.384 raeburn 9611: sub get_secgrprole_info {
9612: my ($cdom,$cnum,$needroles,$type) = @_;
9613: my %sections_count = &get_sections($cdom,$cnum);
9614: my @sections = (sort {$a <=> $b} keys(%sections_count));
9615: my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum);
9616: my @groups = sort(keys(%curr_groups));
9617: my $allroles = [];
9618: my $rolehash;
9619: my $accesshash = {
9620: active => 'Currently has access',
9621: future => 'Will have future access',
9622: previous => 'Previously had access',
9623: };
9624: if ($needroles) {
9625: $rolehash = {'all' => 'all'};
1.385 albertel 9626: my %user_roles = &Apache::lonnet::dump('nohist_userroles',$cdom,$cnum);
9627: if (&Apache::lonnet::error(%user_roles)) {
9628: undef(%user_roles);
9629: }
9630: foreach my $item (keys(%user_roles)) {
1.384 raeburn 9631: my ($role)=split(/\:/,$item,2);
9632: if ($role eq 'cr') { next; }
9633: if ($role =~ /^cr/) {
9634: $$rolehash{$role} = (split('/',$role))[3];
9635: } else {
9636: $$rolehash{$role} = &Apache::lonnet::plaintext($role,$type);
9637: }
9638: }
9639: foreach my $key (sort(keys(%{$rolehash}))) {
9640: push(@{$allroles},$key);
9641: }
9642: push (@{$allroles},'st');
9643: $$rolehash{'st'} = &Apache::lonnet::plaintext('st',$type);
9644: }
9645: return (\@sections,\@groups,$allroles,$rolehash,$accesshash);
9646: }
9647:
1.555 raeburn 9648: sub user_picker {
1.994 raeburn 9649: my ($dom,$srch,$forcenewuser,$caller,$cancreate,$usertype,$context) = @_;
1.555 raeburn 9650: my $currdom = $dom;
9651: my %curr_selected = (
9652: srchin => 'dom',
1.580 raeburn 9653: srchby => 'lastname',
1.555 raeburn 9654: );
9655: my $srchterm;
1.625 raeburn 9656: if ((ref($srch) eq 'HASH') && ($env{'form.origform'} ne 'crtusername')) {
1.555 raeburn 9657: if ($srch->{'srchby'} ne '') {
9658: $curr_selected{'srchby'} = $srch->{'srchby'};
9659: }
9660: if ($srch->{'srchin'} ne '') {
9661: $curr_selected{'srchin'} = $srch->{'srchin'};
9662: }
9663: if ($srch->{'srchtype'} ne '') {
9664: $curr_selected{'srchtype'} = $srch->{'srchtype'};
9665: }
9666: if ($srch->{'srchdomain'} ne '') {
9667: $currdom = $srch->{'srchdomain'};
9668: }
9669: $srchterm = $srch->{'srchterm'};
9670: }
1.1222 damieng 9671: my %html_lt=&Apache::lonlocal::texthash(
1.573 raeburn 9672: 'usr' => 'Search criteria',
1.563 raeburn 9673: 'doma' => 'Domain/institution to search',
1.558 albertel 9674: 'uname' => 'username',
9675: 'lastname' => 'last name',
1.555 raeburn 9676: 'lastfirst' => 'last name, first name',
1.558 albertel 9677: 'crs' => 'in this course',
1.576 raeburn 9678: 'dom' => 'in selected LON-CAPA domain',
1.558 albertel 9679: 'alc' => 'all LON-CAPA',
1.573 raeburn 9680: 'instd' => 'in institutional directory for selected domain',
1.558 albertel 9681: 'exact' => 'is',
9682: 'contains' => 'contains',
1.569 raeburn 9683: 'begins' => 'begins with',
1.1222 damieng 9684: );
9685: my %js_lt=&Apache::lonlocal::texthash(
1.571 raeburn 9686: 'youm' => "You must include some text to search for.",
9687: 'thte' => "The text you are searching for must contain at least two characters when using a 'begins' type search.",
9688: 'thet' => "The text you are searching for must contain at least three characters when using a 'contains' type search.",
9689: 'yomc' => "You must choose a domain when using an institutional directory search.",
9690: 'ymcd' => "You must choose a domain when using a domain search.",
9691: 'whus' => "When using searching by last,first you must include a comma as separator between last name and first name.",
9692: 'whse' => "When searching by last,first you must include at least one character in the first name.",
9693: 'thfo' => "The following need to be corrected before the search can be run:",
1.555 raeburn 9694: );
1.1222 damieng 9695: &html_escape(\%html_lt);
9696: &js_escape(\%js_lt);
1.563 raeburn 9697: my $domform = &select_dom_form($currdom,'srchdomain',1,1);
9698: my $srchinsel = ' <select name="srchin">';
1.555 raeburn 9699:
9700: my @srchins = ('crs','dom','alc','instd');
9701:
9702: foreach my $option (@srchins) {
9703: # FIXME 'alc' option unavailable until
9704: # loncreateuser::print_user_query_page()
9705: # has been completed.
9706: next if ($option eq 'alc');
1.880 raeburn 9707: next if (($option eq 'crs') && ($env{'form.form'} eq 'requestcrs'));
1.555 raeburn 9708: next if ($option eq 'crs' && !$env{'request.course.id'});
1.563 raeburn 9709: if ($curr_selected{'srchin'} eq $option) {
9710: $srchinsel .= '
1.1222 damieng 9711: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.563 raeburn 9712: } else {
9713: $srchinsel .= '
1.1222 damieng 9714: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.563 raeburn 9715: }
1.555 raeburn 9716: }
1.563 raeburn 9717: $srchinsel .= "\n </select>\n";
1.555 raeburn 9718:
9719: my $srchbysel = ' <select name="srchby">';
1.580 raeburn 9720: foreach my $option ('lastname','lastfirst','uname') {
1.555 raeburn 9721: if ($curr_selected{'srchby'} eq $option) {
9722: $srchbysel .= '
1.1222 damieng 9723: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9724: } else {
9725: $srchbysel .= '
1.1222 damieng 9726: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9727: }
9728: }
9729: $srchbysel .= "\n </select>\n";
9730:
9731: my $srchtypesel = ' <select name="srchtype">';
1.580 raeburn 9732: foreach my $option ('begins','contains','exact') {
1.555 raeburn 9733: if ($curr_selected{'srchtype'} eq $option) {
9734: $srchtypesel .= '
1.1222 damieng 9735: <option value="'.$option.'" selected="selected">'.$html_lt{$option}.'</option>';
1.555 raeburn 9736: } else {
9737: $srchtypesel .= '
1.1222 damieng 9738: <option value="'.$option.'">'.$html_lt{$option}.'</option>';
1.555 raeburn 9739: }
9740: }
9741: $srchtypesel .= "\n </select>\n";
9742:
1.558 albertel 9743: my ($newuserscript,$new_user_create);
1.994 raeburn 9744: my $context_dom = $env{'request.role.domain'};
9745: if ($context eq 'requestcrs') {
9746: if ($env{'form.coursedom'} ne '') {
9747: $context_dom = $env{'form.coursedom'};
9748: }
9749: }
1.556 raeburn 9750: if ($forcenewuser) {
1.576 raeburn 9751: if (ref($srch) eq 'HASH') {
1.994 raeburn 9752: if ($srch->{'srchby'} eq 'uname' && $srch->{'srchtype'} eq 'exact' && $srch->{'srchin'} eq 'dom' && $srch->{'srchdomain'} eq $context_dom) {
1.627 raeburn 9753: if ($cancreate) {
9754: $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>';
9755: } else {
1.799 bisitz 9756: my $helplink = 'javascript:helpMenu('."'display'".')';
1.627 raeburn 9757: my %usertypetext = (
9758: official => 'institutional',
9759: unofficial => 'non-institutional',
9760: );
1.799 bisitz 9761: $new_user_create = '<p class="LC_warning">'
9762: .&mt("You are not authorized to create new $usertypetext{$usertype} users in this domain.")
9763: .' '
9764: .&mt('Please contact the [_1]helpdesk[_2] for assistance.'
9765: ,'<a href="'.$helplink.'">','</a>')
9766: .'</p><br />';
1.627 raeburn 9767: }
1.576 raeburn 9768: }
9769: }
9770:
1.556 raeburn 9771: $newuserscript = <<"ENDSCRIPT";
9772:
1.570 raeburn 9773: function setSearch(createnew,callingForm) {
1.556 raeburn 9774: if (createnew == 1) {
1.570 raeburn 9775: for (var i=0; i<callingForm.srchby.length; i++) {
9776: if (callingForm.srchby.options[i].value == 'uname') {
9777: callingForm.srchby.selectedIndex = i;
1.556 raeburn 9778: }
9779: }
1.570 raeburn 9780: for (var i=0; i<callingForm.srchin.length; i++) {
9781: if ( callingForm.srchin.options[i].value == 'dom') {
9782: callingForm.srchin.selectedIndex = i;
1.556 raeburn 9783: }
9784: }
1.570 raeburn 9785: for (var i=0; i<callingForm.srchtype.length; i++) {
9786: if (callingForm.srchtype.options[i].value == 'exact') {
9787: callingForm.srchtype.selectedIndex = i;
1.556 raeburn 9788: }
9789: }
1.570 raeburn 9790: for (var i=0; i<callingForm.srchdomain.length; i++) {
1.994 raeburn 9791: if (callingForm.srchdomain.options[i].value == '$context_dom') {
1.570 raeburn 9792: callingForm.srchdomain.selectedIndex = i;
1.556 raeburn 9793: }
9794: }
9795: }
9796: }
9797: ENDSCRIPT
1.558 albertel 9798:
1.556 raeburn 9799: }
9800:
1.555 raeburn 9801: my $output = <<"END_BLOCK";
1.556 raeburn 9802: <script type="text/javascript">
1.824 bisitz 9803: // <![CDATA[
1.570 raeburn 9804: function validateEntry(callingForm) {
1.558 albertel 9805:
1.556 raeburn 9806: var checkok = 1;
1.558 albertel 9807: var srchin;
1.570 raeburn 9808: for (var i=0; i<callingForm.srchin.length; i++) {
9809: if ( callingForm.srchin[i].checked ) {
9810: srchin = callingForm.srchin[i].value;
1.558 albertel 9811: }
9812: }
9813:
1.570 raeburn 9814: var srchtype = callingForm.srchtype.options[callingForm.srchtype.selectedIndex].value;
9815: var srchby = callingForm.srchby.options[callingForm.srchby.selectedIndex].value;
9816: var srchdomain = callingForm.srchdomain.options[callingForm.srchdomain.selectedIndex].value;
9817: var srchterm = callingForm.srchterm.value;
9818: var srchin = callingForm.srchin.options[callingForm.srchin.selectedIndex].value;
1.556 raeburn 9819: var msg = "";
9820:
9821: if (srchterm == "") {
9822: checkok = 0;
1.1222 damieng 9823: msg += "$js_lt{'youm'}\\n";
1.556 raeburn 9824: }
9825:
1.569 raeburn 9826: if (srchtype== 'begins') {
9827: if (srchterm.length < 2) {
9828: checkok = 0;
1.1222 damieng 9829: msg += "$js_lt{'thte'}\\n";
1.569 raeburn 9830: }
9831: }
9832:
1.556 raeburn 9833: if (srchtype== 'contains') {
9834: if (srchterm.length < 3) {
9835: checkok = 0;
1.1222 damieng 9836: msg += "$js_lt{'thet'}\\n";
1.556 raeburn 9837: }
9838: }
9839: if (srchin == 'instd') {
9840: if (srchdomain == '') {
9841: checkok = 0;
1.1222 damieng 9842: msg += "$js_lt{'yomc'}\\n";
1.556 raeburn 9843: }
9844: }
9845: if (srchin == 'dom') {
9846: if (srchdomain == '') {
9847: checkok = 0;
1.1222 damieng 9848: msg += "$js_lt{'ymcd'}\\n";
1.556 raeburn 9849: }
9850: }
9851: if (srchby == 'lastfirst') {
9852: if (srchterm.indexOf(",") == -1) {
9853: checkok = 0;
1.1222 damieng 9854: msg += "$js_lt{'whus'}\\n";
1.556 raeburn 9855: }
9856: if (srchterm.indexOf(",") == srchterm.length -1) {
9857: checkok = 0;
1.1222 damieng 9858: msg += "$js_lt{'whse'}\\n";
1.556 raeburn 9859: }
9860: }
9861: if (checkok == 0) {
1.1222 damieng 9862: alert("$js_lt{'thfo'}\\n"+msg);
1.556 raeburn 9863: return;
9864: }
9865: if (checkok == 1) {
1.570 raeburn 9866: callingForm.submit();
1.556 raeburn 9867: }
9868: }
9869:
9870: $newuserscript
9871:
1.824 bisitz 9872: // ]]>
1.556 raeburn 9873: </script>
1.558 albertel 9874:
9875: $new_user_create
9876:
1.555 raeburn 9877: END_BLOCK
1.558 albertel 9878:
1.876 raeburn 9879: $output .= &Apache::lonhtmlcommon::start_pick_box().
1.1222 damieng 9880: &Apache::lonhtmlcommon::row_title($html_lt{'doma'}).
1.876 raeburn 9881: $domform.
9882: &Apache::lonhtmlcommon::row_closure().
1.1222 damieng 9883: &Apache::lonhtmlcommon::row_title($html_lt{'usr'}).
1.876 raeburn 9884: $srchbysel.
9885: $srchtypesel.
9886: '<input type="text" size="15" name="srchterm" value="'.$srchterm.'" />'.
9887: $srchinsel.
9888: &Apache::lonhtmlcommon::row_closure(1).
9889: &Apache::lonhtmlcommon::end_pick_box().
9890: '<br />';
1.555 raeburn 9891: return $output;
9892: }
9893:
1.612 raeburn 9894: sub user_rule_check {
1.615 raeburn 9895: my ($usershash,$checks,$alerts,$rulematch,$inst_results,$curr_rules,$got_rules) = @_;
1.1226 raeburn 9896: my ($response,%inst_response);
1.612 raeburn 9897: if (ref($usershash) eq 'HASH') {
1.1226 raeburn 9898: if (keys(%{$usershash}) > 1) {
9899: my (%by_username,%by_id,%userdoms);
9900: my $checkid;
9901: if (ref($checks) eq 'HASH') {
9902: if ((!defined($checks->{'username'})) && (defined($checks->{'id'}))) {
9903: $checkid = 1;
9904: }
9905: }
9906: foreach my $user (keys(%{$usershash})) {
9907: my ($uname,$udom) = split(/:/,$user);
9908: if ($checkid) {
9909: if (ref($usershash->{$user}) eq 'HASH') {
9910: if ($usershash->{$user}->{'id'} ne '') {
1.1227 raeburn 9911: $by_id{$udom}{$usershash->{$user}->{'id'}} = $uname;
1.1226 raeburn 9912: $userdoms{$udom} = 1;
1.1227 raeburn 9913: if (ref($inst_results) eq 'HASH') {
9914: $inst_results->{$uname.':'.$udom} = {};
9915: }
1.1226 raeburn 9916: }
9917: }
9918: } else {
9919: $by_username{$udom}{$uname} = 1;
9920: $userdoms{$udom} = 1;
1.1227 raeburn 9921: if (ref($inst_results) eq 'HASH') {
9922: $inst_results->{$uname.':'.$udom} = {};
9923: }
1.1226 raeburn 9924: }
9925: }
9926: foreach my $udom (keys(%userdoms)) {
9927: if (!$got_rules->{$udom}) {
9928: my %domconfig = &Apache::lonnet::get_dom('configuration',
9929: ['usercreation'],$udom);
9930: if (ref($domconfig{'usercreation'}) eq 'HASH') {
9931: foreach my $item ('username','id') {
9932: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
1.1227 raeburn 9933: $$curr_rules{$udom}{$item} =
9934: $domconfig{'usercreation'}{$item.'_rule'};
1.1226 raeburn 9935: }
9936: }
9937: }
9938: $got_rules->{$udom} = 1;
9939: }
1.612 raeburn 9940: }
1.1226 raeburn 9941: if ($checkid) {
9942: foreach my $udom (keys(%by_id)) {
9943: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_id{$udom},'id');
9944: if ($outcome eq 'ok') {
1.1227 raeburn 9945: foreach my $id (keys(%{$by_id{$udom}})) {
9946: my $uname = $by_id{$udom}{$id};
9947: $inst_response{$uname.':'.$udom} = $outcome;
9948: }
1.1226 raeburn 9949: if (ref($results) eq 'HASH') {
9950: foreach my $uname (keys(%{$results})) {
1.1227 raeburn 9951: if (exists($inst_response{$uname.':'.$udom})) {
9952: $inst_response{$uname.':'.$udom} = $outcome;
9953: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9954: }
1.1226 raeburn 9955: }
9956: }
9957: }
1.612 raeburn 9958: }
1.615 raeburn 9959: } else {
1.1226 raeburn 9960: foreach my $udom (keys(%by_username)) {
9961: my ($outcome,$results) = &Apache::lonnet::get_multiple_instusers($udom,$by_username{$udom});
9962: if ($outcome eq 'ok') {
1.1227 raeburn 9963: foreach my $uname (keys(%{$by_username{$udom}})) {
9964: $inst_response{$uname.':'.$udom} = $outcome;
9965: }
1.1226 raeburn 9966: if (ref($results) eq 'HASH') {
9967: foreach my $uname (keys(%{$results})) {
9968: $inst_results->{$uname.':'.$udom} = $results->{$uname};
9969: }
9970: }
9971: }
9972: }
1.612 raeburn 9973: }
1.1226 raeburn 9974: } elsif (keys(%{$usershash}) == 1) {
9975: my $user = (keys(%{$usershash}))[0];
9976: my ($uname,$udom) = split(/:/,$user);
9977: if (($udom ne '') && ($uname ne '')) {
9978: if (ref($usershash->{$user}) eq 'HASH') {
9979: if (ref($checks) eq 'HASH') {
9980: if (defined($checks->{'username'})) {
9981: ($inst_response{$user},%{$inst_results->{$user}}) =
9982: &Apache::lonnet::get_instuser($udom,$uname);
9983: } elsif (defined($checks->{'id'})) {
9984: if ($usershash->{$user}->{'id'} ne '') {
9985: ($inst_response{$user},%{$inst_results->{$user}}) =
9986: &Apache::lonnet::get_instuser($udom,undef,
9987: $usershash->{$user}->{'id'});
9988: } else {
9989: ($inst_response{$user},%{$inst_results->{$user}}) =
9990: &Apache::lonnet::get_instuser($udom,$uname);
9991: }
1.585 raeburn 9992: }
1.1226 raeburn 9993: } else {
9994: ($inst_response{$user},%{$inst_results->{$user}}) =
9995: &Apache::lonnet::get_instuser($udom,$uname);
9996: return;
9997: }
9998: if (!$got_rules->{$udom}) {
9999: my %domconfig = &Apache::lonnet::get_dom('configuration',
10000: ['usercreation'],$udom);
10001: if (ref($domconfig{'usercreation'}) eq 'HASH') {
10002: foreach my $item ('username','id') {
10003: if (ref($domconfig{'usercreation'}{$item.'_rule'}) eq 'ARRAY') {
10004: $$curr_rules{$udom}{$item} =
10005: $domconfig{'usercreation'}{$item.'_rule'};
10006: }
10007: }
10008: }
10009: $got_rules->{$udom} = 1;
1.585 raeburn 10010: }
10011: }
1.1226 raeburn 10012: } else {
10013: return;
10014: }
10015: } else {
10016: return;
10017: }
10018: foreach my $user (keys(%{$usershash})) {
10019: my ($uname,$udom) = split(/:/,$user);
10020: next if (($udom eq '') || ($uname eq ''));
10021: my $id;
1.1227 raeburn 10022: if (ref($inst_results) eq 'HASH') {
10023: if (ref($inst_results->{$user}) eq 'HASH') {
10024: $id = $inst_results->{$user}->{'id'};
10025: }
10026: }
10027: if ($id eq '') {
10028: if (ref($usershash->{$user})) {
10029: $id = $usershash->{$user}->{'id'};
10030: }
1.585 raeburn 10031: }
1.612 raeburn 10032: foreach my $item (keys(%{$checks})) {
10033: if (ref($$curr_rules{$udom}) eq 'HASH') {
10034: if (ref($$curr_rules{$udom}{$item}) eq 'ARRAY') {
10035: if (@{$$curr_rules{$udom}{$item}} > 0) {
1.1226 raeburn 10036: my %rule_check = &Apache::lonnet::inst_rulecheck($udom,$uname,$id,$item,
10037: $$curr_rules{$udom}{$item});
1.612 raeburn 10038: foreach my $rule (@{$$curr_rules{$udom}{$item}}) {
10039: if ($rule_check{$rule}) {
10040: $$rulematch{$user}{$item} = $rule;
1.1226 raeburn 10041: if ($inst_response{$user} eq 'ok') {
1.615 raeburn 10042: if (ref($inst_results) eq 'HASH') {
10043: if (ref($inst_results->{$user}) eq 'HASH') {
10044: if (keys(%{$inst_results->{$user}}) == 0) {
10045: $$alerts{$item}{$udom}{$uname} = 1;
1.1227 raeburn 10046: } elsif ($item eq 'id') {
10047: if ($inst_results->{$user}->{'id'} eq '') {
10048: $$alerts{$item}{$udom}{$uname} = 1;
10049: }
1.615 raeburn 10050: }
1.612 raeburn 10051: }
10052: }
1.615 raeburn 10053: }
10054: last;
1.585 raeburn 10055: }
10056: }
10057: }
10058: }
10059: }
10060: }
10061: }
10062: }
1.612 raeburn 10063: return;
10064: }
10065:
10066: sub user_rule_formats {
10067: my ($domain,$domdesc,$curr_rules,$check) = @_;
10068: my %text = (
10069: 'username' => 'Usernames',
10070: 'id' => 'IDs',
10071: );
10072: my $output;
10073: my ($rules,$ruleorder) = &Apache::lonnet::inst_userrules($domain,$check);
10074: if ((ref($rules) eq 'HASH') && (ref($ruleorder) eq 'ARRAY')) {
10075: if (@{$ruleorder} > 0) {
1.1102 raeburn 10076: $output = '<br />'.
10077: &mt($text{$check}.' with the following format(s) may [_1]only[_2] be used for verified users at [_3]:',
10078: '<span class="LC_cusr_emph">','</span>',$domdesc).
10079: ' <ul>';
1.612 raeburn 10080: foreach my $rule (@{$ruleorder}) {
10081: if (ref($curr_rules) eq 'ARRAY') {
10082: if (grep(/^\Q$rule\E$/,@{$curr_rules})) {
10083: if (ref($rules->{$rule}) eq 'HASH') {
10084: $output .= '<li>'.$rules->{$rule}{'name'}.': '.
10085: $rules->{$rule}{'desc'}.'</li>';
10086: }
10087: }
10088: }
10089: }
10090: $output .= '</ul>';
10091: }
10092: }
10093: return $output;
10094: }
10095:
10096: sub instrule_disallow_msg {
1.615 raeburn 10097: my ($checkitem,$domdesc,$count,$mode) = @_;
1.612 raeburn 10098: my $response;
10099: my %text = (
10100: item => 'username',
10101: items => 'usernames',
10102: match => 'matches',
10103: do => 'does',
10104: action => 'a username',
10105: one => 'one',
10106: );
10107: if ($count > 1) {
10108: $text{'item'} = 'usernames';
10109: $text{'match'} ='match';
10110: $text{'do'} = 'do';
10111: $text{'action'} = 'usernames',
10112: $text{'one'} = 'ones';
10113: }
10114: if ($checkitem eq 'id') {
10115: $text{'items'} = 'IDs';
10116: $text{'item'} = 'ID';
10117: $text{'action'} = 'an ID';
1.615 raeburn 10118: if ($count > 1) {
10119: $text{'item'} = 'IDs';
10120: $text{'action'} = 'IDs';
10121: }
1.612 raeburn 10122: }
1.674 bisitz 10123: $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 10124: if ($mode eq 'upload') {
10125: if ($checkitem eq 'username') {
10126: $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'}.");
10127: } elsif ($checkitem eq 'id') {
1.674 bisitz 10128: $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 10129: }
1.669 raeburn 10130: } elsif ($mode eq 'selfcreate') {
10131: if ($checkitem eq 'id') {
10132: $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.");
10133: }
1.615 raeburn 10134: } else {
10135: if ($checkitem eq 'username') {
10136: $response .= &mt("You must choose $text{'action'} with a different format -- $text{'one'} that will not conflict with 'official' institutional $text{'items'}.");
10137: } elsif ($checkitem eq 'id') {
10138: $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.");
10139: }
1.612 raeburn 10140: }
10141: return $response;
1.585 raeburn 10142: }
10143:
1.624 raeburn 10144: sub personal_data_fieldtitles {
10145: my %fieldtitles = &Apache::lonlocal::texthash (
10146: id => 'Student/Employee ID',
10147: permanentemail => 'E-mail address',
10148: lastname => 'Last Name',
10149: firstname => 'First Name',
10150: middlename => 'Middle Name',
10151: generation => 'Generation',
10152: gen => 'Generation',
1.765 raeburn 10153: inststatus => 'Affiliation',
1.624 raeburn 10154: );
10155: return %fieldtitles;
10156: }
10157:
1.642 raeburn 10158: sub sorted_inst_types {
10159: my ($dom) = @_;
1.1185 raeburn 10160: my ($usertypes,$order);
10161: my %domdefaults = &Apache::lonnet::get_domain_defaults($dom);
10162: if (ref($domdefaults{'inststatus'}) eq 'HASH') {
10163: $usertypes = $domdefaults{'inststatus'}{'inststatustypes'};
10164: $order = $domdefaults{'inststatus'}{'inststatusorder'};
10165: } else {
10166: ($usertypes,$order) = &Apache::lonnet::retrieve_inst_usertypes($dom);
10167: }
1.642 raeburn 10168: my $othertitle = &mt('All users');
10169: if ($env{'request.course.id'}) {
1.668 raeburn 10170: $othertitle = &mt('Any users');
1.642 raeburn 10171: }
10172: my @types;
10173: if (ref($order) eq 'ARRAY') {
10174: @types = @{$order};
10175: }
10176: if (@types == 0) {
10177: if (ref($usertypes) eq 'HASH') {
10178: @types = sort(keys(%{$usertypes}));
10179: }
10180: }
10181: if (keys(%{$usertypes}) > 0) {
10182: $othertitle = &mt('Other users');
10183: }
10184: return ($othertitle,$usertypes,\@types);
10185: }
10186:
1.645 raeburn 10187: sub get_institutional_codes {
10188: my ($settings,$allcourses,$LC_code) = @_;
10189: # Get complete list of course sections to update
10190: my @currsections = ();
10191: my @currxlists = ();
10192: my $coursecode = $$settings{'internal.coursecode'};
10193:
10194: if ($$settings{'internal.sectionnums'} ne '') {
10195: @currsections = split(/,/,$$settings{'internal.sectionnums'});
10196: }
10197:
10198: if ($$settings{'internal.crosslistings'} ne '') {
10199: @currxlists = split(/,/,$$settings{'internal.crosslistings'});
10200: }
10201:
10202: if (@currxlists > 0) {
10203: foreach (@currxlists) {
10204: if (m/^([^:]+):(\w*)$/) {
10205: unless (grep/^$1$/,@{$allcourses}) {
10206: push @{$allcourses},$1;
10207: $$LC_code{$1} = $2;
10208: }
10209: }
10210: }
10211: }
10212:
10213: if (@currsections > 0) {
10214: foreach (@currsections) {
10215: if (m/^(\w+):(\w*)$/) {
10216: my $sec = $coursecode.$1;
10217: my $lc_sec = $2;
10218: unless (grep/^$sec$/,@{$allcourses}) {
10219: push @{$allcourses},$sec;
10220: $$LC_code{$sec} = $lc_sec;
10221: }
10222: }
10223: }
10224: }
10225: return;
10226: }
10227:
1.971 raeburn 10228: sub get_standard_codeitems {
10229: return ('Year','Semester','Department','Number','Section');
10230: }
10231:
1.112 bowersj2 10232: =pod
10233:
1.780 raeburn 10234: =head1 Slot Helpers
10235:
10236: =over 4
10237:
10238: =item * sorted_slots()
10239:
1.1040 raeburn 10240: Sorts an array of slot names in order of an optional sort key,
10241: default sort is by slot start time (earliest first).
1.780 raeburn 10242:
10243: Inputs:
10244:
10245: =over 4
10246:
10247: slotsarr - Reference to array of unsorted slot names.
10248:
10249: slots - Reference to hash of hash, where outer hash keys are slot names.
10250:
1.1040 raeburn 10251: sortkey - Name of key in inner hash to be sorted on (e.g., starttime).
10252:
1.549 albertel 10253: =back
10254:
1.780 raeburn 10255: Returns:
10256:
10257: =over 4
10258:
1.1040 raeburn 10259: sorted - An array of slot names sorted by a specified sort key
10260: (default sort key is start time of the slot).
1.780 raeburn 10261:
10262: =back
10263:
10264: =cut
10265:
10266:
10267: sub sorted_slots {
1.1040 raeburn 10268: my ($slotsarr,$slots,$sortkey) = @_;
10269: if ($sortkey eq '') {
10270: $sortkey = 'starttime';
10271: }
1.780 raeburn 10272: my @sorted;
10273: if ((ref($slotsarr) eq 'ARRAY') && (ref($slots) eq 'HASH')) {
10274: @sorted =
10275: sort {
10276: if (ref($slots->{$a}) && ref($slots->{$b})) {
1.1040 raeburn 10277: return $slots->{$a}{$sortkey} <=> $slots->{$b}{$sortkey}
1.780 raeburn 10278: }
10279: if (ref($slots->{$a})) { return -1;}
10280: if (ref($slots->{$b})) { return 1;}
10281: return 0;
10282: } @{$slotsarr};
10283: }
10284: return @sorted;
10285: }
10286:
1.1040 raeburn 10287: =pod
10288:
10289: =item * get_future_slots()
10290:
10291: Inputs:
10292:
10293: =over 4
10294:
10295: cnum - course number
10296:
10297: cdom - course domain
10298:
10299: now - current UNIX time
10300:
10301: symb - optional symb
10302:
10303: =back
10304:
10305: Returns:
10306:
10307: =over 4
10308:
10309: sorted_reservable - ref to array of student_schedulable slots currently
10310: reservable, ordered by end date of reservation period.
10311:
10312: reservable_now - ref to hash of student_schedulable slots currently
10313: reservable.
10314:
10315: Keys in inner hash are:
10316: (a) symb: either blank or symb to which slot use is restricted.
10317: (b) endreserve: end date of reservation period.
10318:
10319: sorted_future - ref to array of student_schedulable slots reservable in
10320: the future, ordered by start date of reservation period.
10321:
10322: future_reservable - ref to hash of student_schedulable slots reservable
10323: in the future.
10324:
10325: Keys in inner hash are:
10326: (a) symb: either blank or symb to which slot use is restricted.
10327: (b) startreserve: start date of reservation period.
10328:
10329: =back
10330:
10331: =cut
10332:
10333: sub get_future_slots {
10334: my ($cnum,$cdom,$now,$symb) = @_;
1.1229 raeburn 10335: my $map;
10336: if ($symb) {
10337: ($map) = &Apache::lonnet::decode_symb($symb);
10338: }
1.1040 raeburn 10339: my (%reservable_now,%future_reservable,@sorted_reservable,@sorted_future);
10340: my %slots = &Apache::lonnet::get_course_slots($cnum,$cdom);
10341: foreach my $slot (keys(%slots)) {
10342: next unless($slots{$slot}->{'type'} eq 'schedulable_student');
10343: if ($symb) {
1.1229 raeburn 10344: if ($slots{$slot}->{'symb'} ne '') {
10345: my $canuse;
10346: my %oksymbs;
10347: my @slotsymbs = split(/\s*,\s*/,$slots{$slot}->{'symb'});
10348: map { $oksymbs{$_} = 1; } @slotsymbs;
10349: if ($oksymbs{$symb}) {
10350: $canuse = 1;
10351: } else {
10352: foreach my $item (@slotsymbs) {
10353: if ($item =~ /\.(page|sequence)$/) {
10354: (undef,undef,my $sloturl) = &Apache::lonnet::decode_symb($item);
10355: if (($map ne '') && ($map eq $sloturl)) {
10356: $canuse = 1;
10357: last;
10358: }
10359: }
10360: }
10361: }
10362: next unless ($canuse);
10363: }
1.1040 raeburn 10364: }
10365: if (($slots{$slot}->{'starttime'} > $now) &&
10366: ($slots{$slot}->{'endtime'} > $now)) {
10367: if (($slots{$slot}->{'allowedsections'}) || ($slots{$slot}->{'allowedusers'})) {
10368: my $userallowed = 0;
10369: if ($slots{$slot}->{'allowedsections'}) {
10370: my @allowed_sec = split(',',$slots{$slot}->{'allowedsections'});
10371: if (!defined($env{'request.role.sec'})
10372: && grep(/^No section assigned$/,@allowed_sec)) {
10373: $userallowed=1;
10374: } else {
10375: if (grep(/^\Q$env{'request.role.sec'}\E$/,@allowed_sec)) {
10376: $userallowed=1;
10377: }
10378: }
10379: unless ($userallowed) {
10380: if (defined($env{'request.course.groups'})) {
10381: my @groups = split(/:/,$env{'request.course.groups'});
10382: foreach my $group (@groups) {
10383: if (grep(/^\Q$group\E$/,@allowed_sec)) {
10384: $userallowed=1;
10385: last;
10386: }
10387: }
10388: }
10389: }
10390: }
10391: if ($slots{$slot}->{'allowedusers'}) {
10392: my @allowed_users = split(',',$slots{$slot}->{'allowedusers'});
10393: my $user = $env{'user.name'}.':'.$env{'user.domain'};
10394: if (grep(/^\Q$user\E$/,@allowed_users)) {
10395: $userallowed = 1;
10396: }
10397: }
10398: next unless($userallowed);
10399: }
10400: my $startreserve = $slots{$slot}->{'startreserve'};
10401: my $endreserve = $slots{$slot}->{'endreserve'};
10402: my $symb = $slots{$slot}->{'symb'};
10403: if (($startreserve < $now) &&
10404: (!$endreserve || $endreserve > $now)) {
10405: my $lastres = $endreserve;
10406: if (!$lastres) {
10407: $lastres = $slots{$slot}->{'starttime'};
10408: }
10409: $reservable_now{$slot} = {
10410: symb => $symb,
10411: endreserve => $lastres
10412: };
10413: } elsif (($startreserve > $now) &&
10414: (!$endreserve || $endreserve > $startreserve)) {
10415: $future_reservable{$slot} = {
10416: symb => $symb,
10417: startreserve => $startreserve
10418: };
10419: }
10420: }
10421: }
10422: my @unsorted_reservable = keys(%reservable_now);
10423: if (@unsorted_reservable > 0) {
10424: @sorted_reservable =
10425: &sorted_slots(\@unsorted_reservable,\%reservable_now,'endreserve');
10426: }
10427: my @unsorted_future = keys(%future_reservable);
10428: if (@unsorted_future > 0) {
10429: @sorted_future =
10430: &sorted_slots(\@unsorted_future,\%future_reservable,'startreserve');
10431: }
10432: return (\@sorted_reservable,\%reservable_now,\@sorted_future,\%future_reservable);
10433: }
1.780 raeburn 10434:
10435: =pod
10436:
1.1057 foxr 10437: =back
10438:
1.549 albertel 10439: =head1 HTTP Helpers
10440:
10441: =over 4
10442:
1.648 raeburn 10443: =item * &get_unprocessed_cgi($query,$possible_names)
1.112 bowersj2 10444:
1.258 albertel 10445: Modify the %env hash to contain unprocessed CGI form parameters held in
1.112 bowersj2 10446: $query. The parameters listed in $possible_names (an array reference),
1.258 albertel 10447: will be set in $env{'form.name'} if they do not already exist.
1.112 bowersj2 10448:
10449: Typically called with $ENV{'QUERY_STRING'} as the first parameter.
10450: $possible_names is an ref to an array of form element names. As an example:
10451: get_unprocessed_cgi($ENV{'QUERY_STRING'},['uname','udom']);
1.258 albertel 10452: will result in $env{'form.uname'} and $env{'form.udom'} being set.
1.112 bowersj2 10453:
10454: =cut
1.1 albertel 10455:
1.6 albertel 10456: sub get_unprocessed_cgi {
1.25 albertel 10457: my ($query,$possible_names)= @_;
1.26 matthew 10458: # $Apache::lonxml::debug=1;
1.356 albertel 10459: foreach my $pair (split(/&/,$query)) {
10460: my ($name, $value) = split(/=/,$pair);
1.369 www 10461: $name = &unescape($name);
1.25 albertel 10462: if (!defined($possible_names) || (grep {$_ eq $name} @$possible_names)) {
10463: $value =~ tr/+/ /;
10464: $value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
1.258 albertel 10465: unless (defined($env{'form.'.$name})) { &add_to_env('form.'.$name,$value) };
1.25 albertel 10466: }
1.16 harris41 10467: }
1.6 albertel 10468: }
10469:
1.112 bowersj2 10470: =pod
10471:
1.648 raeburn 10472: =item * &cacheheader()
1.112 bowersj2 10473:
10474: returns cache-controlling header code
10475:
10476: =cut
10477:
1.7 albertel 10478: sub cacheheader {
1.258 albertel 10479: unless ($env{'request.method'} eq 'GET') { return ''; }
1.216 albertel 10480: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime);
10481: my $output .='<meta HTTP-EQUIV="Expires" CONTENT="'.$date.'" />
1.7 albertel 10482: <meta HTTP-EQUIV="Cache-control" CONTENT="no-cache" />
10483: <meta HTTP-EQUIV="Pragma" CONTENT="no-cache" />';
1.216 albertel 10484: return $output;
1.7 albertel 10485: }
10486:
1.112 bowersj2 10487: =pod
10488:
1.648 raeburn 10489: =item * &no_cache($r)
1.112 bowersj2 10490:
10491: specifies header code to not have cache
10492:
10493: =cut
10494:
1.9 albertel 10495: sub no_cache {
1.216 albertel 10496: my ($r) = @_;
10497: if ($ENV{'REQUEST_METHOD'} ne 'GET' &&
1.258 albertel 10498: $env{'request.method'} ne 'GET') { return ''; }
1.216 albertel 10499: my $date=strftime("%a, %d %b %Y %H:%M:%S GMT",gmtime(time));
10500: $r->no_cache(1);
10501: $r->header_out("Expires" => $date);
10502: $r->header_out("Pragma" => "no-cache");
1.123 www 10503: }
10504:
10505: sub content_type {
1.181 albertel 10506: my ($r,$type,$charset) = @_;
1.299 foxr 10507: if ($r) {
10508: # Note that printout.pl calls this with undef for $r.
10509: &no_cache($r);
10510: }
1.258 albertel 10511: if ($env{'browser.mathml'} && $type eq 'text/html') { $type='text/xml'; }
1.181 albertel 10512: unless ($charset) {
10513: $charset=&Apache::lonlocal::current_encoding;
10514: }
10515: if ($charset) { $type.='; charset='.$charset; }
10516: if ($r) {
10517: $r->content_type($type);
10518: } else {
10519: print("Content-type: $type\n\n");
10520: }
1.9 albertel 10521: }
1.25 albertel 10522:
1.112 bowersj2 10523: =pod
10524:
1.648 raeburn 10525: =item * &add_to_env($name,$value)
1.112 bowersj2 10526:
1.258 albertel 10527: adds $name to the %env hash with value
1.112 bowersj2 10528: $value, if $name already exists, the entry is converted to an array
10529: reference and $value is added to the array.
10530:
10531: =cut
10532:
1.25 albertel 10533: sub add_to_env {
10534: my ($name,$value)=@_;
1.258 albertel 10535: if (defined($env{$name})) {
10536: if (ref($env{$name})) {
1.25 albertel 10537: #already have multiple values
1.258 albertel 10538: push(@{ $env{$name} },$value);
1.25 albertel 10539: } else {
10540: #first time seeing multiple values, convert hash entry to an arrayref
1.258 albertel 10541: my $first=$env{$name};
10542: undef($env{$name});
10543: push(@{ $env{$name} },$first,$value);
1.25 albertel 10544: }
10545: } else {
1.258 albertel 10546: $env{$name}=$value;
1.25 albertel 10547: }
1.31 albertel 10548: }
1.149 albertel 10549:
10550: =pod
10551:
1.648 raeburn 10552: =item * &get_env_multiple($name)
1.149 albertel 10553:
1.258 albertel 10554: gets $name from the %env hash, it seemlessly handles the cases where multiple
1.149 albertel 10555: values may be defined and end up as an array ref.
10556:
10557: returns an array of values
10558:
10559: =cut
10560:
10561: sub get_env_multiple {
10562: my ($name) = @_;
10563: my @values;
1.258 albertel 10564: if (defined($env{$name})) {
1.149 albertel 10565: # exists is it an array
1.258 albertel 10566: if (ref($env{$name})) {
10567: @values=@{ $env{$name} };
1.149 albertel 10568: } else {
1.258 albertel 10569: $values[0]=$env{$name};
1.149 albertel 10570: }
10571: }
10572: return(@values);
10573: }
10574:
1.660 raeburn 10575: sub ask_for_embedded_content {
10576: my ($actionurl,$state,$allfiles,$codebase,$args)=@_;
1.1071 raeburn 10577: my (%subdependencies,%dependencies,%mapping,%existing,%newfiles,%pathchanges,
1.1085 raeburn 10578: %currsubfile,%unused,$rem);
1.1071 raeburn 10579: my $counter = 0;
10580: my $numnew = 0;
1.987 raeburn 10581: my $numremref = 0;
10582: my $numinvalid = 0;
10583: my $numpathchg = 0;
10584: my $numexisting = 0;
1.1071 raeburn 10585: my $numunused = 0;
10586: my ($output,$upload_output,$toplevel,$url,$udom,$uname,$getpropath,$cdom,$cnum,
1.1156 raeburn 10587: $fileloc,$filename,$delete_output,$modify_output,$title,$symb,$path,$navmap);
1.1071 raeburn 10588: my $heading = &mt('Upload embedded files');
10589: my $buttontext = &mt('Upload');
10590:
1.1085 raeburn 10591: if ($env{'request.course.id'}) {
1.1123 raeburn 10592: if ($actionurl eq '/adm/dependencies') {
10593: $navmap = Apache::lonnavmaps::navmap->new();
10594: }
10595: $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
10596: $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
1.1085 raeburn 10597: }
1.1123 raeburn 10598: if (($actionurl eq '/adm/portfolio') ||
10599: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.984 raeburn 10600: my $current_path='/';
10601: if ($env{'form.currentpath'}) {
10602: $current_path = $env{'form.currentpath'};
10603: }
10604: if ($actionurl eq '/adm/coursegrp_portfolio') {
1.1123 raeburn 10605: $udom = $cdom;
10606: $uname = $cnum;
1.984 raeburn 10607: $url = '/userfiles/groups/'.$env{'form.group'}.'/portfolio';
10608: } else {
10609: $udom = $env{'user.domain'};
10610: $uname = $env{'user.name'};
10611: $url = '/userfiles/portfolio';
10612: }
1.987 raeburn 10613: $toplevel = $url.'/';
1.984 raeburn 10614: $url .= $current_path;
10615: $getpropath = 1;
1.987 raeburn 10616: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
10617: ($actionurl eq '/adm/imsimport')) {
1.1022 www 10618: my ($udom,$uname,$rest) = ($args->{'current_path'} =~ m{/priv/($match_domain)/($match_username)/?(.*)$});
1.1026 raeburn 10619: $url = $Apache::lonnet::perlvar{'lonDocRoot'}."/priv/$udom/$uname/";
1.987 raeburn 10620: $toplevel = $url;
1.984 raeburn 10621: if ($rest ne '') {
1.987 raeburn 10622: $url .= $rest;
10623: }
10624: } elsif ($actionurl eq '/adm/coursedocs') {
10625: if (ref($args) eq 'HASH') {
1.1071 raeburn 10626: $url = $args->{'docs_url'};
10627: $toplevel = $url;
1.1084 raeburn 10628: if ($args->{'context'} eq 'paste') {
10629: ($cdom,$cnum) = ($url =~ m{^\Q/uploaded/\E($match_domain)/($match_courseid)/});
10630: ($path) =
10631: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10632: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10633: $fileloc =~ s{^/}{};
10634: }
1.1071 raeburn 10635: }
1.1084 raeburn 10636: } elsif ($actionurl eq '/adm/dependencies') {
1.1071 raeburn 10637: if ($env{'request.course.id'} ne '') {
10638: if (ref($args) eq 'HASH') {
10639: $url = $args->{'docs_url'};
10640: $title = $args->{'docs_title'};
1.1126 raeburn 10641: $toplevel = $url;
10642: unless ($toplevel =~ m{^/}) {
10643: $toplevel = "/$url";
10644: }
1.1085 raeburn 10645: ($rem) = ($toplevel =~ m{^(.+/)[^/]+$});
1.1126 raeburn 10646: if ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E)}) {
10647: $path = $1;
10648: } else {
10649: ($path) =
10650: ($toplevel =~ m{^(\Q/uploaded/$cdom/$cnum/\E(?:docs|supplemental)/(?:default|\d+)/\d+)/});
10651: }
1.1195 raeburn 10652: if ($toplevel=~/^\/*(uploaded|editupload)/) {
10653: $fileloc = $toplevel;
10654: $fileloc=~ s/^\s*(\S+)\s*$/$1/;
10655: my ($udom,$uname,$fname) =
10656: ($fileloc=~ m{^/+(?:uploaded|editupload)/+($match_domain)/+($match_name)/+(.*)$});
10657: $fileloc = propath($udom,$uname).'/userfiles/'.$fname;
10658: } else {
10659: $fileloc = &Apache::lonnet::filelocation('',$toplevel);
10660: }
1.1071 raeburn 10661: $fileloc =~ s{^/}{};
10662: ($filename) = ($fileloc =~ m{.+/([^/]+)$});
10663: $heading = &mt('Status of dependencies in [_1]',"$title ($filename)");
10664: }
1.987 raeburn 10665: }
1.1123 raeburn 10666: } elsif ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10667: $udom = $cdom;
10668: $uname = $cnum;
10669: $url = "/uploaded/$cdom/$cnum/portfolio/syllabus";
10670: $toplevel = $url;
10671: $path = $url;
10672: $fileloc = &Apache::lonnet::filelocation('',$toplevel).'/';
10673: $fileloc =~ s{^/}{};
1.987 raeburn 10674: }
1.1126 raeburn 10675: foreach my $file (keys(%{$allfiles})) {
10676: my $embed_file;
10677: if (($path eq "/uploaded/$cdom/$cnum/portfolio/syllabus") && ($file =~ m{^\Q$path/\E(.+)$})) {
10678: $embed_file = $1;
10679: } else {
10680: $embed_file = $file;
10681: }
1.1158 raeburn 10682: my ($absolutepath,$cleaned_file);
10683: if ($embed_file =~ m{^\w+://}) {
10684: $cleaned_file = $embed_file;
1.1147 raeburn 10685: $newfiles{$cleaned_file} = 1;
10686: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10687: } else {
1.1158 raeburn 10688: $cleaned_file = &clean_path($embed_file);
1.987 raeburn 10689: if ($embed_file =~ m{^/}) {
10690: $absolutepath = $embed_file;
10691: }
1.1147 raeburn 10692: if ($cleaned_file =~ m{/}) {
10693: my ($path,$fname) = ($cleaned_file =~ m{^(.+)/([^/]*)$});
1.987 raeburn 10694: $path = &check_for_traversal($path,$url,$toplevel);
10695: my $item = $fname;
10696: if ($path ne '') {
10697: $item = $path.'/'.$fname;
10698: $subdependencies{$path}{$fname} = 1;
10699: } else {
10700: $dependencies{$item} = 1;
10701: }
10702: if ($absolutepath) {
10703: $mapping{$item} = $absolutepath;
10704: } else {
10705: $mapping{$item} = $embed_file;
10706: }
10707: } else {
10708: $dependencies{$embed_file} = 1;
10709: if ($absolutepath) {
1.1147 raeburn 10710: $mapping{$cleaned_file} = $absolutepath;
1.987 raeburn 10711: } else {
1.1147 raeburn 10712: $mapping{$cleaned_file} = $embed_file;
1.987 raeburn 10713: }
10714: }
1.984 raeburn 10715: }
10716: }
1.1071 raeburn 10717: my $dirptr = 16384;
1.984 raeburn 10718: foreach my $path (keys(%subdependencies)) {
1.1071 raeburn 10719: $currsubfile{$path} = {};
1.1123 raeburn 10720: if (($actionurl eq '/adm/portfolio') ||
10721: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10722: my ($sublistref,$listerror) =
10723: &Apache::lonnet::dirlist($url.$path,$udom,$uname,$getpropath);
10724: if (ref($sublistref) eq 'ARRAY') {
10725: foreach my $line (@{$sublistref}) {
10726: my ($file_name,$rest) = split(/\&/,$line,2);
1.1071 raeburn 10727: $currsubfile{$path}{$file_name} = 1;
1.1021 raeburn 10728: }
1.984 raeburn 10729: }
1.987 raeburn 10730: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10731: if (opendir(my $dir,$url.'/'.$path)) {
10732: my @subdir_list = grep(!/^\./,readdir($dir));
1.1071 raeburn 10733: map {$currsubfile{$path}{$_} = 1;} @subdir_list;
10734: }
1.1084 raeburn 10735: } elsif (($actionurl eq '/adm/dependencies') ||
10736: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 10737: ($args->{'context'} eq 'paste')) ||
10738: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10739: if ($env{'request.course.id'} ne '') {
1.1123 raeburn 10740: my $dir;
10741: if ($actionurl eq "/public/$cdom/$cnum/syllabus") {
10742: $dir = $fileloc;
10743: } else {
10744: ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10745: }
1.1071 raeburn 10746: if ($dir ne '') {
10747: my ($sublistref,$listerror) =
10748: &Apache::lonnet::dirlist($dir.$path,$cdom,$cnum,$getpropath,undef,'/');
10749: if (ref($sublistref) eq 'ARRAY') {
10750: foreach my $line (@{$sublistref}) {
10751: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,$size,
10752: undef,$mtime)=split(/\&/,$line,12);
10753: unless (($testdir&$dirptr) ||
10754: ($file_name =~ /^\.\.?$/)) {
10755: $currsubfile{$path}{$file_name} = [$size,$mtime];
10756: }
10757: }
10758: }
10759: }
1.984 raeburn 10760: }
10761: }
10762: foreach my $file (keys(%{$subdependencies{$path}})) {
1.1071 raeburn 10763: if (exists($currsubfile{$path}{$file})) {
1.987 raeburn 10764: my $item = $path.'/'.$file;
10765: unless ($mapping{$item} eq $item) {
10766: $pathchanges{$item} = 1;
10767: }
10768: $existing{$item} = 1;
10769: $numexisting ++;
10770: } else {
10771: $newfiles{$path.'/'.$file} = 1;
1.984 raeburn 10772: }
10773: }
1.1071 raeburn 10774: if ($actionurl eq '/adm/dependencies') {
10775: foreach my $path (keys(%currsubfile)) {
10776: if (ref($currsubfile{$path}) eq 'HASH') {
10777: foreach my $file (keys(%{$currsubfile{$path}})) {
10778: unless ($subdependencies{$path}{$file}) {
1.1085 raeburn 10779: next if (($rem ne '') &&
10780: (($env{"httpref.$rem"."$path/$file"} ne '') ||
10781: (ref($navmap) &&
10782: (($navmap->getResourceByUrl($rem."$path/$file") ne '') ||
10783: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10784: ($navmap->getResourceByUrl($rem."$path/$1")))))));
1.1071 raeburn 10785: $unused{$path.'/'.$file} = 1;
10786: }
10787: }
10788: }
10789: }
10790: }
1.984 raeburn 10791: }
1.987 raeburn 10792: my %currfile;
1.1123 raeburn 10793: if (($actionurl eq '/adm/portfolio') ||
10794: ($actionurl eq '/adm/coursegrp_portfolio')) {
1.1021 raeburn 10795: my ($dirlistref,$listerror) =
10796: &Apache::lonnet::dirlist($url,$udom,$uname,$getpropath);
10797: if (ref($dirlistref) eq 'ARRAY') {
10798: foreach my $line (@{$dirlistref}) {
10799: my ($file_name,$rest) = split(/\&/,$line,2);
10800: $currfile{$file_name} = 1;
10801: }
1.984 raeburn 10802: }
1.987 raeburn 10803: } elsif (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
1.984 raeburn 10804: if (opendir(my $dir,$url)) {
1.987 raeburn 10805: my @dir_list = grep(!/^\./,readdir($dir));
1.984 raeburn 10806: map {$currfile{$_} = 1;} @dir_list;
10807: }
1.1084 raeburn 10808: } elsif (($actionurl eq '/adm/dependencies') ||
10809: (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
1.1123 raeburn 10810: ($args->{'context'} eq 'paste')) ||
10811: ($actionurl eq "/public/$cdom/$cnum/syllabus")) {
1.1071 raeburn 10812: if ($env{'request.course.id'} ne '') {
10813: my ($dir) = ($fileloc =~ m{^(.+/)[^/]+$});
10814: if ($dir ne '') {
10815: my ($dirlistref,$listerror) =
10816: &Apache::lonnet::dirlist($dir,$cdom,$cnum,$getpropath,undef,'/');
10817: if (ref($dirlistref) eq 'ARRAY') {
10818: foreach my $line (@{$dirlistref}) {
10819: my ($file_name,$dom,undef,$testdir,undef,undef,undef,undef,
10820: $size,undef,$mtime)=split(/\&/,$line,12);
10821: unless (($testdir&$dirptr) ||
10822: ($file_name =~ /^\.\.?$/)) {
10823: $currfile{$file_name} = [$size,$mtime];
10824: }
10825: }
10826: }
10827: }
10828: }
1.984 raeburn 10829: }
10830: foreach my $file (keys(%dependencies)) {
1.1071 raeburn 10831: if (exists($currfile{$file})) {
1.987 raeburn 10832: unless ($mapping{$file} eq $file) {
10833: $pathchanges{$file} = 1;
10834: }
10835: $existing{$file} = 1;
10836: $numexisting ++;
10837: } else {
1.984 raeburn 10838: $newfiles{$file} = 1;
10839: }
10840: }
1.1071 raeburn 10841: foreach my $file (keys(%currfile)) {
10842: unless (($file eq $filename) ||
10843: ($file eq $filename.'.bak') ||
10844: ($dependencies{$file})) {
1.1085 raeburn 10845: if ($actionurl eq '/adm/dependencies') {
1.1126 raeburn 10846: unless ($toplevel =~ m{^\Q/uploaded/$cdom/$cnum/portfolio/syllabus\E}) {
10847: next if (($rem ne '') &&
10848: (($env{"httpref.$rem".$file} ne '') ||
10849: (ref($navmap) &&
10850: (($navmap->getResourceByUrl($rem.$file) ne '') ||
10851: (($file =~ /^(.*\.s?html?)\.bak$/i) &&
10852: ($navmap->getResourceByUrl($rem.$1)))))));
10853: }
1.1085 raeburn 10854: }
1.1071 raeburn 10855: $unused{$file} = 1;
10856: }
10857: }
1.1084 raeburn 10858: if (($actionurl eq '/adm/coursedocs') && (ref($args) eq 'HASH') &&
10859: ($args->{'context'} eq 'paste')) {
10860: $counter = scalar(keys(%existing));
10861: $numpathchg = scalar(keys(%pathchanges));
1.1123 raeburn 10862: return ($output,$counter,$numpathchg,\%existing);
10863: } elsif (($actionurl eq "/public/$cdom/$cnum/syllabus") &&
10864: (ref($args) eq 'HASH') && ($args->{'context'} eq 'rewrites')) {
10865: $counter = scalar(keys(%existing));
10866: $numpathchg = scalar(keys(%pathchanges));
10867: return ($output,$counter,$numpathchg,\%existing,\%mapping);
1.1084 raeburn 10868: }
1.984 raeburn 10869: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%newfiles)) {
1.1071 raeburn 10870: if ($actionurl eq '/adm/dependencies') {
10871: next if ($embed_file =~ m{^\w+://});
10872: }
1.660 raeburn 10873: $upload_output .= &start_data_table_row().
1.1123 raeburn 10874: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
1.1071 raeburn 10875: '<span class="LC_filename">'.$embed_file.'</span>';
1.987 raeburn 10876: unless ($mapping{$embed_file} eq $embed_file) {
1.1123 raeburn 10877: $upload_output .= '<br /><span class="LC_info" style="font-size:smaller;">'.
10878: &mt('changed from: [_1]',$mapping{$embed_file}).'</span>';
1.987 raeburn 10879: }
1.1123 raeburn 10880: $upload_output .= '</td>';
1.1071 raeburn 10881: if ($args->{'ignore_remote_references'} && $embed_file =~ m{^\w+://}) {
1.1123 raeburn 10882: $upload_output.='<td align="right">'.
10883: '<span class="LC_info LC_fontsize_medium">'.
10884: &mt("URL points to web address").'</span>';
1.987 raeburn 10885: $numremref++;
1.660 raeburn 10886: } elsif ($args->{'error_on_invalid_names'}
10887: && $embed_file ne &Apache::lonnet::clean_filename($embed_file,{'keep_path' => 1,})) {
1.1123 raeburn 10888: $upload_output.='<td align="right"><span class="LC_warning">'.
10889: &mt('Invalid characters').'</span>';
1.987 raeburn 10890: $numinvalid++;
1.660 raeburn 10891: } else {
1.1123 raeburn 10892: $upload_output .= '<td>'.
10893: &embedded_file_element('upload_embedded',$counter,
1.987 raeburn 10894: $embed_file,\%mapping,
1.1071 raeburn 10895: $allfiles,$codebase,'upload');
10896: $counter ++;
10897: $numnew ++;
1.987 raeburn 10898: }
10899: $upload_output .= '</td>'.&Apache::loncommon::end_data_table_row()."\n";
10900: }
10901: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%existing)) {
1.1071 raeburn 10902: if ($actionurl eq '/adm/dependencies') {
10903: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$embed_file);
10904: $modify_output .= &start_data_table_row().
10905: '<td><a href="'.$path.'/'.$embed_file.'" style="text-decoration:none;">'.
10906: '<img src="'.&icon($embed_file).'" border="0" />'.
10907: ' <span class="LC_filename">'.$embed_file.'</span></a></td>'.
10908: '<td>'.$size.'</td>'.
10909: '<td>'.$mtime.'</td>'.
10910: '<td><label><input type="checkbox" name="mod_upload_dep" '.
10911: 'onclick="toggleBrowse('."'$counter'".')" id="mod_upload_dep_'.
10912: $counter.'" value="'.$counter.'" />'.&mt('Yes').'</label>'.
10913: '<div id="moduploaddep_'.$counter.'" style="display:none;">'.
10914: &embedded_file_element('upload_embedded',$counter,
10915: $embed_file,\%mapping,
10916: $allfiles,$codebase,'modify').
10917: '</div></td>'.
10918: &end_data_table_row()."\n";
10919: $counter ++;
10920: } else {
10921: $upload_output .= &start_data_table_row().
1.1123 raeburn 10922: '<td valign="top"><img src="'.&icon($embed_file).'" /> '.
10923: '<span class="LC_filename">'.$embed_file.'</span></td>'.
10924: '<td align="right"><span class="LC_info LC_fontsize_medium">'.&mt('Already exists').'</span></td>'.
1.1071 raeburn 10925: &Apache::loncommon::end_data_table_row()."\n";
10926: }
10927: }
10928: my $delidx = $counter;
10929: foreach my $oldfile (sort {lc($a) cmp lc($b)} keys(%unused)) {
10930: my ($size,$mtime) = &get_dependency_details(\%currfile,\%currsubfile,$oldfile);
10931: $delete_output .= &start_data_table_row().
10932: '<td><img src="'.&icon($oldfile).'" />'.
10933: ' <span class="LC_filename">'.$oldfile.'</span></td>'.
10934: '<td>'.$size.'</td>'.
10935: '<td>'.$mtime.'</td>'.
10936: '<td><label><input type="checkbox" name="del_upload_dep" '.
10937: ' value="'.$delidx.'" />'.&mt('Yes').'</label>'.
10938: &embedded_file_element('upload_embedded',$delidx,
10939: $oldfile,\%mapping,$allfiles,
10940: $codebase,'delete').'</td>'.
10941: &end_data_table_row()."\n";
10942: $numunused ++;
10943: $delidx ++;
1.987 raeburn 10944: }
10945: if ($upload_output) {
10946: $upload_output = &start_data_table().
10947: $upload_output.
10948: &end_data_table()."\n";
10949: }
1.1071 raeburn 10950: if ($modify_output) {
10951: $modify_output = &start_data_table().
10952: &start_data_table_header_row().
10953: '<th>'.&mt('File').'</th>'.
10954: '<th>'.&mt('Size (KB)').'</th>'.
10955: '<th>'.&mt('Modified').'</th>'.
10956: '<th>'.&mt('Upload replacement?').'</th>'.
10957: &end_data_table_header_row().
10958: $modify_output.
10959: &end_data_table()."\n";
10960: }
10961: if ($delete_output) {
10962: $delete_output = &start_data_table().
10963: &start_data_table_header_row().
10964: '<th>'.&mt('File').'</th>'.
10965: '<th>'.&mt('Size (KB)').'</th>'.
10966: '<th>'.&mt('Modified').'</th>'.
10967: '<th>'.&mt('Delete?').'</th>'.
10968: &end_data_table_header_row().
10969: $delete_output.
10970: &end_data_table()."\n";
10971: }
1.987 raeburn 10972: my $applies = 0;
10973: if ($numremref) {
10974: $applies ++;
10975: }
10976: if ($numinvalid) {
10977: $applies ++;
10978: }
10979: if ($numexisting) {
10980: $applies ++;
10981: }
1.1071 raeburn 10982: if ($counter || $numunused) {
1.987 raeburn 10983: $output = '<form name="upload_embedded" action="'.$actionurl.'"'.
10984: ' method="post" enctype="multipart/form-data">'."\n".
1.1071 raeburn 10985: $state.'<h3>'.$heading.'</h3>';
10986: if ($actionurl eq '/adm/dependencies') {
10987: if ($numnew) {
10988: $output .= '<h4>'.&mt('Missing dependencies').'</h4>'.
10989: '<p>'.&mt('The following files need to be uploaded.').'</p>'."\n".
10990: $upload_output.'<br />'."\n";
10991: }
10992: if ($numexisting) {
10993: $output .= '<h4>'.&mt('Uploaded dependencies (in use)').'</h4>'.
10994: '<p>'.&mt('Upload a new file to replace the one currently in use.').'</p>'."\n".
10995: $modify_output.'<br />'."\n";
10996: $buttontext = &mt('Save changes');
10997: }
10998: if ($numunused) {
10999: $output .= '<h4>'.&mt('Unused files').'</h4>'.
11000: '<p>'.&mt('The following uploaded files are no longer used.').'</p>'."\n".
11001: $delete_output.'<br />'."\n";
11002: $buttontext = &mt('Save changes');
11003: }
11004: } else {
11005: $output .= $upload_output.'<br />'."\n";
11006: }
11007: $output .= '<input type ="hidden" name="number_embedded_items" value="'.
11008: $counter.'" />'."\n";
11009: if ($actionurl eq '/adm/dependencies') {
11010: $output .= '<input type ="hidden" name="number_newemb_items" value="'.
11011: $numnew.'" />'."\n";
11012: } elsif ($actionurl eq '') {
1.987 raeburn 11013: $output .= '<input type="hidden" name="phase" value="three" />';
11014: }
11015: } elsif ($applies) {
11016: $output = '<b>'.&mt('Referenced files').'</b>:<br />';
11017: if ($applies > 1) {
11018: $output .=
1.1123 raeburn 11019: &mt('No dependencies need to be uploaded, as one of the following applies to each reference:').'<ul>';
1.987 raeburn 11020: if ($numremref) {
11021: $output .= '<li>'.&mt('reference is to a URL which points to another server').'</li>'."\n";
11022: }
11023: if ($numinvalid) {
11024: $output .= '<li>'.&mt('reference is to file with a name containing invalid characters').'</li>'."\n";
11025: }
11026: if ($numexisting) {
11027: $output .= '<li>'.&mt('reference is to an existing file at the specified location').'</li>'."\n";
11028: }
11029: $output .= '</ul><br />';
11030: } elsif ($numremref) {
11031: $output .= '<p>'.&mt('None to upload, as all references are to URLs pointing to another server.').'</p>';
11032: } elsif ($numinvalid) {
11033: $output .= '<p>'.&mt('None to upload, as all references are to files with names containing invalid characters.').'</p>';
11034: } elsif ($numexisting) {
11035: $output .= '<p>'.&mt('None to upload, as all references are to existing files.').'</p>';
11036: }
11037: $output .= $upload_output.'<br />';
11038: }
11039: my ($pathchange_output,$chgcount);
1.1071 raeburn 11040: $chgcount = $counter;
1.987 raeburn 11041: if (keys(%pathchanges) > 0) {
11042: foreach my $embed_file (sort {lc($a) cmp lc($b)} keys(%pathchanges)) {
1.1071 raeburn 11043: if ($counter) {
1.987 raeburn 11044: $output .= &embedded_file_element('pathchange',$chgcount,
11045: $embed_file,\%mapping,
1.1071 raeburn 11046: $allfiles,$codebase,'change');
1.987 raeburn 11047: } else {
11048: $pathchange_output .=
11049: &start_data_table_row().
11050: '<td><input type ="checkbox" name="namechange" value="'.
11051: $chgcount.'" checked="checked" /></td>'.
11052: '<td>'.$mapping{$embed_file}.'</td>'.
11053: '<td>'.$embed_file.
11054: &embedded_file_element('pathchange',$numpathchg,$embed_file,
1.1071 raeburn 11055: \%mapping,$allfiles,$codebase,'change').
1.987 raeburn 11056: '</td>'.&end_data_table_row();
1.660 raeburn 11057: }
1.987 raeburn 11058: $numpathchg ++;
11059: $chgcount ++;
1.660 raeburn 11060: }
11061: }
1.1127 raeburn 11062: if (($counter) || ($numunused)) {
1.987 raeburn 11063: if ($numpathchg) {
11064: $output .= '<input type ="hidden" name="number_pathchange_items" value="'.
11065: $numpathchg.'" />'."\n";
11066: }
11067: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank') ||
11068: ($actionurl eq '/adm/imsimport')) {
11069: $output .= '<input type="hidden" name="phase" value="three" />'."\n";
11070: } elsif ($actionurl eq '/adm/portfolio' || $actionurl eq '/adm/coursegrp_portfolio') {
11071: $output .= '<input type="hidden" name="action" value="upload_embedded" />';
1.1071 raeburn 11072: } elsif ($actionurl eq '/adm/dependencies') {
11073: $output .= '<input type="hidden" name="action" value="process_changes" />';
1.987 raeburn 11074: }
1.1123 raeburn 11075: $output .= '<input type ="submit" value="'.$buttontext.'" />'."\n".'</form>'."\n";
1.987 raeburn 11076: } elsif ($numpathchg) {
11077: my %pathchange = ();
11078: $output .= &modify_html_form('pathchange',$actionurl,$state,\%pathchange,$pathchange_output);
11079: if (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11080: $output .= '<p>'.&mt('or').'</p>';
1.1123 raeburn 11081: }
1.987 raeburn 11082: }
1.1071 raeburn 11083: return ($output,$counter,$numpathchg);
1.987 raeburn 11084: }
11085:
1.1147 raeburn 11086: =pod
11087:
11088: =item * clean_path($name)
11089:
11090: Performs clean-up of directories, subdirectories and filename in an
11091: embedded object, referenced in an HTML file which is being uploaded
11092: to a course or portfolio, where
11093: "Upload embedded images/multimedia files if HTML file" checkbox was
11094: checked.
11095:
11096: Clean-up is similar to replacements in lonnet::clean_filename()
11097: except each / between sub-directory and next level is preserved.
11098:
11099: =cut
11100:
11101: sub clean_path {
11102: my ($embed_file) = @_;
11103: $embed_file =~s{^/+}{};
11104: my @contents;
11105: if ($embed_file =~ m{/}) {
11106: @contents = split(/\//,$embed_file);
11107: } else {
11108: @contents = ($embed_file);
11109: }
11110: my $lastidx = scalar(@contents)-1;
11111: for (my $i=0; $i<=$lastidx; $i++) {
11112: $contents[$i]=~s{\\}{/}g;
11113: $contents[$i]=~s/\s+/\_/g;
11114: $contents[$i]=~s{[^/\w\.\-]}{}g;
11115: if ($i == $lastidx) {
11116: $contents[$i]=~s/\.(\d+)(?=\.)/_$1/g;
11117: }
11118: }
11119: if ($lastidx > 0) {
11120: return join('/',@contents);
11121: } else {
11122: return $contents[0];
11123: }
11124: }
11125:
1.987 raeburn 11126: sub embedded_file_element {
1.1071 raeburn 11127: my ($context,$num,$embed_file,$mapping,$allfiles,$codebase,$type) = @_;
1.987 raeburn 11128: return unless ((ref($mapping) eq 'HASH') && (ref($allfiles) eq 'HASH') &&
11129: (ref($codebase) eq 'HASH'));
11130: my $output;
1.1071 raeburn 11131: if (($context eq 'upload_embedded') && ($type ne 'delete')) {
1.987 raeburn 11132: $output = '<input name="embedded_item_'.$num.'" type="file" value="" />'."\n";
11133: }
11134: $output .= '<input name="embedded_orig_'.$num.'" type="hidden" value="'.
11135: &escape($embed_file).'" />';
11136: unless (($context eq 'upload_embedded') &&
11137: ($mapping->{$embed_file} eq $embed_file)) {
11138: $output .='
11139: <input name="embedded_ref_'.$num.'" type="hidden" value="'.&escape($mapping->{$embed_file}).'" />';
11140: }
11141: my $attrib;
11142: if (ref($allfiles->{$mapping->{$embed_file}}) eq 'ARRAY') {
11143: $attrib = &escape(join(':',@{$allfiles->{$mapping->{$embed_file}}}));
11144: }
11145: $output .=
11146: "\n\t\t".
11147: '<input name="embedded_attrib_'.$num.'" type="hidden" value="'.
11148: $attrib.'" />';
11149: if (exists($codebase->{$mapping->{$embed_file}})) {
11150: $output .=
11151: "\n\t\t".
11152: '<input name="codebase_'.$num.'" type="hidden" value="'.
11153: &escape($codebase->{$mapping->{$embed_file}}).'" />';
1.984 raeburn 11154: }
1.987 raeburn 11155: return $output;
1.660 raeburn 11156: }
11157:
1.1071 raeburn 11158: sub get_dependency_details {
11159: my ($currfile,$currsubfile,$embed_file) = @_;
11160: my ($size,$mtime,$showsize,$showmtime);
11161: if ((ref($currfile) eq 'HASH') && (ref($currsubfile))) {
11162: if ($embed_file =~ m{/}) {
11163: my ($path,$fname) = split(/\//,$embed_file);
11164: if (ref($currsubfile->{$path}{$fname}) eq 'ARRAY') {
11165: ($size,$mtime) = @{$currsubfile->{$path}{$fname}};
11166: }
11167: } else {
11168: if (ref($currfile->{$embed_file}) eq 'ARRAY') {
11169: ($size,$mtime) = @{$currfile->{$embed_file}};
11170: }
11171: }
11172: $showsize = $size/1024.0;
11173: $showsize = sprintf("%.1f",$showsize);
11174: if ($mtime > 0) {
11175: $showmtime = &Apache::lonlocal::locallocaltime($mtime);
11176: }
11177: }
11178: return ($showsize,$showmtime);
11179: }
11180:
11181: sub ask_embedded_js {
11182: return <<"END";
11183: <script type="text/javascript"">
11184: // <![CDATA[
11185: function toggleBrowse(counter) {
11186: var chkboxid = document.getElementById('mod_upload_dep_'+counter);
11187: var fileid = document.getElementById('embedded_item_'+counter);
11188: var uploaddivid = document.getElementById('moduploaddep_'+counter);
11189: if (chkboxid.checked == true) {
11190: uploaddivid.style.display='block';
11191: } else {
11192: uploaddivid.style.display='none';
11193: fileid.value = '';
11194: }
11195: }
11196: // ]]>
11197: </script>
11198:
11199: END
11200: }
11201:
1.661 raeburn 11202: sub upload_embedded {
11203: my ($context,$dirpath,$uname,$udom,$dir_root,$url_root,$group,$disk_quota,
1.987 raeburn 11204: $current_disk_usage,$hiddenstate,$actionurl) = @_;
11205: my (%pathchange,$output,$modifyform,$footer,$returnflag);
1.661 raeburn 11206: for (my $i=0; $i<$env{'form.number_embedded_items'}; $i++) {
11207: next if (!exists($env{'form.embedded_item_'.$i.'.filename'}));
11208: my $orig_uploaded_filename =
11209: $env{'form.embedded_item_'.$i.'.filename'};
1.987 raeburn 11210: foreach my $type ('orig','ref','attrib','codebase') {
11211: if ($env{'form.embedded_'.$type.'_'.$i} ne '') {
11212: $env{'form.embedded_'.$type.'_'.$i} =
11213: &unescape($env{'form.embedded_'.$type.'_'.$i});
11214: }
11215: }
1.661 raeburn 11216: my ($path,$fname) =
11217: ($env{'form.embedded_orig_'.$i} =~ m{(.*/)([^/]*)});
11218: # no path, whole string is fname
11219: if (!$fname) { $fname = $env{'form.embedded_orig_'.$i} };
11220: $fname = &Apache::lonnet::clean_filename($fname);
11221: # See if there is anything left
11222: next if ($fname eq '');
11223:
11224: # Check if file already exists as a file or directory.
11225: my ($state,$msg);
11226: if ($context eq 'portfolio') {
11227: my $port_path = $dirpath;
11228: if ($group ne '') {
11229: $port_path = "groups/$group/$port_path";
11230: }
1.987 raeburn 11231: ($state,$msg) = &check_for_upload($env{'form.currentpath'}.$path,
11232: $fname,$group,'embedded_item_'.$i,
1.661 raeburn 11233: $dir_root,$port_path,$disk_quota,
11234: $current_disk_usage,$uname,$udom);
11235: if ($state eq 'will_exceed_quota'
1.984 raeburn 11236: || $state eq 'file_locked') {
1.661 raeburn 11237: $output .= $msg;
11238: next;
11239: }
11240: } elsif (($context eq 'author') || ($context eq 'testbank')) {
11241: ($state,$msg) = &check_for_existing($path,$fname,'embedded_item_'.$i);
11242: if ($state eq 'exists') {
11243: $output .= $msg;
11244: next;
11245: }
11246: }
11247: # Check if extension is valid
11248: if (($fname =~ /\.(\w+)$/) &&
11249: (&Apache::loncommon::fileembstyle($1) eq 'hdn')) {
1.1155 bisitz 11250: $output .= &mt('Invalid file extension ([_1]) - reserved for internal use.',$1)
11251: .' '.&mt('Rename the file with a different extension and re-upload.').'<br />';
1.661 raeburn 11252: next;
11253: } elsif (($fname =~ /\.(\w+)$/) &&
11254: (!defined(&Apache::loncommon::fileembstyle($1)))) {
1.987 raeburn 11255: $output .= &mt('Unrecognized file extension ([_1]) - rename the file with a proper extension and re-upload.',$1).'<br />';
1.661 raeburn 11256: next;
11257: } elsif ($fname=~/\.(\d+)\.(\w+)$/) {
1.1120 bisitz 11258: $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 11259: next;
11260: }
11261: $env{'form.embedded_item_'.$i.'.filename'}=$fname;
1.1123 raeburn 11262: my $subdir = $path;
11263: $subdir =~ s{/+$}{};
1.661 raeburn 11264: if ($context eq 'portfolio') {
1.984 raeburn 11265: my $result;
11266: if ($state eq 'existingfile') {
11267: $result=
11268: &Apache::lonnet::userfileupload('embedded_item_'.$i,'existingfile',
1.1123 raeburn 11269: $dirpath.$env{'form.currentpath'}.$subdir);
1.661 raeburn 11270: } else {
1.984 raeburn 11271: $result=
11272: &Apache::lonnet::userfileupload('embedded_item_'.$i,'',
1.987 raeburn 11273: $dirpath.
1.1123 raeburn 11274: $env{'form.currentpath'}.$subdir);
1.984 raeburn 11275: if ($result !~ m|^/uploaded/|) {
11276: $output .= '<span class="LC_error">'
11277: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11278: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11279: .'</span><br />';
11280: next;
11281: } else {
1.987 raeburn 11282: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11283: $path.$fname.'</span>').'<br />';
1.984 raeburn 11284: }
1.661 raeburn 11285: }
1.1123 raeburn 11286: } elsif (($context eq 'coursedoc') || ($context eq 'syllabus')) {
1.1126 raeburn 11287: my $extendedsubdir = $dirpath.'/'.$subdir;
11288: $extendedsubdir =~ s{/+$}{};
1.987 raeburn 11289: my $result =
1.1126 raeburn 11290: &Apache::lonnet::userfileupload('embedded_item_'.$i,$context,$extendedsubdir);
1.987 raeburn 11291: if ($result !~ m|^/uploaded/|) {
11292: $output .= '<span class="LC_error">'
11293: .&mt('An error occurred ([_1]) while trying to upload [_2] for embedded element [_3].'
11294: ,$result,$orig_uploaded_filename,$env{'form.embedded_orig_'.$i})
11295: .'</span><br />';
11296: next;
11297: } else {
11298: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11299: $path.$fname.'</span>').'<br />';
1.1125 raeburn 11300: if ($context eq 'syllabus') {
11301: &Apache::lonnet::make_public_indefinitely($result);
11302: }
1.987 raeburn 11303: }
1.661 raeburn 11304: } else {
11305: # Save the file
11306: my $target = $env{'form.embedded_item_'.$i};
11307: my $fullpath = $dir_root.$dirpath.'/'.$path;
11308: my $dest = $fullpath.$fname;
11309: my $url = $url_root.$dirpath.'/'.$path.$fname;
1.1027 raeburn 11310: my @parts=split(/\//,"$dirpath/$path");
1.661 raeburn 11311: my $count;
11312: my $filepath = $dir_root;
1.1027 raeburn 11313: foreach my $subdir (@parts) {
11314: $filepath .= "/$subdir";
11315: if (!-e $filepath) {
1.661 raeburn 11316: mkdir($filepath,0770);
11317: }
11318: }
11319: my $fh;
11320: if (!open($fh,'>'.$dest)) {
11321: &Apache::lonnet::logthis('Failed to create '.$dest);
11322: $output .= '<span class="LC_error">'.
1.1071 raeburn 11323: &mt('An error occurred while trying to upload [_1] for embedded element [_2].',
11324: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11325: '</span><br />';
11326: } else {
11327: if (!print $fh $env{'form.embedded_item_'.$i}) {
11328: &Apache::lonnet::logthis('Failed to write to '.$dest);
11329: $output .= '<span class="LC_error">'.
1.1071 raeburn 11330: &mt('An error occurred while writing the file [_1] for embedded element [_2].',
11331: $orig_uploaded_filename,$env{'form.embedded_orig_'.$i}).
1.661 raeburn 11332: '</span><br />';
11333: } else {
1.987 raeburn 11334: $output .= &mt('Uploaded [_1]','<span class="LC_filename">'.
11335: $url.'</span>').'<br />';
11336: unless ($context eq 'testbank') {
11337: $footer .= &mt('View embedded file: [_1]',
11338: '<a href="'.$url.'">'.$fname.'</a>').'<br />';
11339: }
11340: }
11341: close($fh);
11342: }
11343: }
11344: if ($env{'form.embedded_ref_'.$i}) {
11345: $pathchange{$i} = 1;
11346: }
11347: }
11348: if ($output) {
11349: $output = '<p>'.$output.'</p>';
11350: }
11351: $output .= &modify_html_form('upload_embedded',$actionurl,$hiddenstate,\%pathchange);
11352: $returnflag = 'ok';
1.1071 raeburn 11353: my $numpathchgs = scalar(keys(%pathchange));
11354: if ($numpathchgs > 0) {
1.987 raeburn 11355: if ($context eq 'portfolio') {
11356: $output .= '<p>'.&mt('or').'</p>';
11357: } elsif ($context eq 'testbank') {
1.1071 raeburn 11358: $output .= '<p>'.&mt('Or [_1]continue[_2] the testbank import without modifying the reference(s).',
11359: '<a href="javascript:document.testbankForm.submit();">','</a>').'</p>';
1.987 raeburn 11360: $returnflag = 'modify_orightml';
11361: }
11362: }
1.1071 raeburn 11363: return ($output.$footer,$returnflag,$numpathchgs);
1.987 raeburn 11364: }
11365:
11366: sub modify_html_form {
11367: my ($context,$actionurl,$hiddenstate,$pathchange,$pathchgtable) = @_;
11368: my $end = 0;
11369: my $modifyform;
11370: if ($context eq 'upload_embedded') {
11371: return unless (ref($pathchange) eq 'HASH');
11372: if ($env{'form.number_embedded_items'}) {
11373: $end += $env{'form.number_embedded_items'};
11374: }
11375: if ($env{'form.number_pathchange_items'}) {
11376: $end += $env{'form.number_pathchange_items'};
11377: }
11378: if ($end) {
11379: for (my $i=0; $i<$end; $i++) {
11380: if ($i < $env{'form.number_embedded_items'}) {
11381: next unless($pathchange->{$i});
11382: }
11383: $modifyform .=
11384: &start_data_table_row().
11385: '<td><input type ="checkbox" name="namechange" value="'.$i.'" '.
11386: 'checked="checked" /></td>'.
11387: '<td>'.$env{'form.embedded_ref_'.$i}.
11388: '<input type="hidden" name="embedded_ref_'.$i.'" value="'.
11389: &escape($env{'form.embedded_ref_'.$i}).'" />'.
11390: '<input type="hidden" name="embedded_codebase_'.$i.'" value="'.
11391: &escape($env{'form.embedded_codebase_'.$i}).'" />'.
11392: '<input type="hidden" name="embedded_attrib_'.$i.'" value="'.
11393: &escape($env{'form.embedded_attrib_'.$i}).'" /></td>'.
11394: '<td>'.$env{'form.embedded_orig_'.$i}.
11395: '<input type="hidden" name="embedded_orig_'.$i.'" value="'.
11396: &escape($env{'form.embedded_orig_'.$i}).'" /></td>'.
11397: &end_data_table_row();
1.1071 raeburn 11398: }
1.987 raeburn 11399: }
11400: } else {
11401: $modifyform = $pathchgtable;
11402: if (($actionurl eq '/adm/upload') || ($actionurl eq '/adm/testbank')) {
11403: $hiddenstate .= '<input type="hidden" name="phase" value="four" />';
11404: } elsif (($actionurl eq '/adm/portfolio') || ($actionurl eq '/adm/coursegrp_portfolio')) {
11405: $hiddenstate .= '<input type="hidden" name="action" value="modify_orightml" />';
11406: }
11407: }
11408: if ($modifyform) {
1.1071 raeburn 11409: if ($actionurl eq '/adm/dependencies') {
11410: $hiddenstate .= '<input type="hidden" name="action" value="modifyhrefs" />';
11411: }
1.987 raeburn 11412: return '<h3>'.&mt('Changes in content of HTML file required').'</h3>'."\n".
11413: '<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".
11414: '<li>'.&mt('For consistency between the reference(s) and the location of the corresponding stored file within LON-CAPA.').'</li>'."\n".
11415: '<li>'.&mt('To change absolute paths to relative paths, or replace directory traversal via "../" within the original reference.').'</li>'."\n".
11416: '</ol></p>'."\n".'<p>'.
11417: &mt('LON-CAPA can make the required changes to your HTML file.').'</p>'."\n".
11418: '<form method="post" name="refchanger" action="'.$actionurl.'">'.
11419: &start_data_table()."\n".
11420: &start_data_table_header_row().
11421: '<th>'.&mt('Change?').'</th>'.
11422: '<th>'.&mt('Current reference').'</th>'.
11423: '<th>'.&mt('Required reference').'</th>'.
11424: &end_data_table_header_row()."\n".
11425: $modifyform.
11426: &end_data_table().'<br />'."\n".$hiddenstate.
11427: '<input type="submit" name="pathchanges" value="'.&mt('Modify HTML file').'" />'.
11428: '</form>'."\n";
11429: }
11430: return;
11431: }
11432:
11433: sub modify_html_refs {
1.1123 raeburn 11434: my ($context,$dirpath,$uname,$udom,$dir_root,$url) = @_;
1.987 raeburn 11435: my $container;
11436: if ($context eq 'portfolio') {
11437: $container = $env{'form.container'};
11438: } elsif ($context eq 'coursedoc') {
11439: $container = $env{'form.primaryurl'};
1.1071 raeburn 11440: } elsif ($context eq 'manage_dependencies') {
11441: (undef,undef,$container) = &Apache::lonnet::decode_symb($env{'form.symb'});
11442: $container = "/$container";
1.1123 raeburn 11443: } elsif ($context eq 'syllabus') {
11444: $container = $url;
1.987 raeburn 11445: } else {
1.1027 raeburn 11446: $container = $Apache::lonnet::perlvar{'lonDocRoot'}.$env{'form.filename'};
1.987 raeburn 11447: }
11448: my (%allfiles,%codebase,$output,$content);
11449: my @changes = &get_env_multiple('form.namechange');
1.1126 raeburn 11450: unless ((@changes > 0) || ($context eq 'syllabus')) {
1.1071 raeburn 11451: if (wantarray) {
11452: return ('',0,0);
11453: } else {
11454: return;
11455: }
11456: }
11457: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11458: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.1071 raeburn 11459: unless ($container =~ m{^/uploaded/\Q$udom\E/\Q$uname\E/}) {
11460: if (wantarray) {
11461: return ('',0,0);
11462: } else {
11463: return;
11464: }
11465: }
1.987 raeburn 11466: $content = &Apache::lonnet::getfile($container);
1.1071 raeburn 11467: if ($content eq '-1') {
11468: if (wantarray) {
11469: return ('',0,0);
11470: } else {
11471: return;
11472: }
11473: }
1.987 raeburn 11474: } else {
1.1071 raeburn 11475: unless ($container =~ /^\Q$dir_root\E/) {
11476: if (wantarray) {
11477: return ('',0,0);
11478: } else {
11479: return;
11480: }
11481: }
1.987 raeburn 11482: if (open(my $fh,"<$container")) {
11483: $content = join('', <$fh>);
11484: close($fh);
11485: } else {
1.1071 raeburn 11486: if (wantarray) {
11487: return ('',0,0);
11488: } else {
11489: return;
11490: }
1.987 raeburn 11491: }
11492: }
11493: my ($count,$codebasecount) = (0,0);
11494: my $mm = new File::MMagic;
11495: my $mime_type = $mm->checktype_contents($content);
11496: if ($mime_type eq 'text/html') {
11497: my $parse_result =
11498: &Apache::lonnet::extract_embedded_items($container,\%allfiles,
11499: \%codebase,\$content);
11500: if ($parse_result eq 'ok') {
11501: foreach my $i (@changes) {
11502: my $orig = &unescape($env{'form.embedded_orig_'.$i});
11503: my $ref = &unescape($env{'form.embedded_ref_'.$i});
11504: if ($allfiles{$ref}) {
11505: my $newname = $orig;
11506: my ($attrib_regexp,$codebase);
1.1006 raeburn 11507: $attrib_regexp = &unescape($env{'form.embedded_attrib_'.$i});
1.987 raeburn 11508: if ($attrib_regexp =~ /:/) {
11509: $attrib_regexp =~ s/\:/|/g;
11510: }
11511: if ($content =~ m{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11512: my $numchg = ($content =~ s{($attrib_regexp\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11513: $count += $numchg;
1.1123 raeburn 11514: $allfiles{$newname} = $allfiles{$ref};
1.1148 raeburn 11515: delete($allfiles{$ref});
1.987 raeburn 11516: }
11517: if ($env{'form.embedded_codebase_'.$i} ne '') {
1.1006 raeburn 11518: $codebase = &unescape($env{'form.embedded_codebase_'.$i});
1.987 raeburn 11519: my $numchg = ($content =~ s/(codebase\s*=\s*["']?)\Q$codebase\E(["']?)/$1.$2/i); #' stupid emacs
11520: $codebasecount ++;
11521: }
11522: }
11523: }
1.1123 raeburn 11524: my $skiprewrites;
1.987 raeburn 11525: if ($count || $codebasecount) {
11526: my $saveresult;
1.1071 raeburn 11527: if (($context eq 'portfolio') || ($context eq 'coursedoc') ||
1.1123 raeburn 11528: ($context eq 'manage_dependencies') || ($context eq 'syllabus')) {
1.987 raeburn 11529: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11530: if ($url eq $container) {
11531: my ($fname) = ($container =~ m{/([^/]+)$});
11532: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11533: $count,'<span class="LC_filename">'.
1.1071 raeburn 11534: $fname.'</span>').'</p>';
1.987 raeburn 11535: } else {
11536: $output = '<p class="LC_error">'.
11537: &mt('Error: update failed for: [_1].',
11538: '<span class="LC_filename">'.
11539: $container.'</span>').'</p>';
11540: }
1.1123 raeburn 11541: if ($context eq 'syllabus') {
11542: unless ($saveresult eq 'ok') {
11543: $skiprewrites = 1;
11544: }
11545: }
1.987 raeburn 11546: } else {
11547: if (open(my $fh,">$container")) {
11548: print $fh $content;
11549: close($fh);
11550: $output = '<p>'.&mt('Updated [quant,_1,reference] in [_2].',
11551: $count,'<span class="LC_filename">'.
11552: $container.'</span>').'</p>';
1.661 raeburn 11553: } else {
1.987 raeburn 11554: $output = '<p class="LC_error">'.
11555: &mt('Error: could not update [_1].',
11556: '<span class="LC_filename">'.
11557: $container.'</span>').'</p>';
1.661 raeburn 11558: }
11559: }
11560: }
1.1123 raeburn 11561: if (($context eq 'syllabus') && (!$skiprewrites)) {
11562: my ($actionurl,$state);
11563: $actionurl = "/public/$udom/$uname/syllabus";
11564: my ($ignore,$num,$numpathchanges,$existing,$mapping) =
11565: &ask_for_embedded_content($actionurl,$state,\%allfiles,
11566: \%codebase,
11567: {'context' => 'rewrites',
11568: 'ignore_remote_references' => 1,});
11569: if (ref($mapping) eq 'HASH') {
11570: my $rewrites = 0;
11571: foreach my $key (keys(%{$mapping})) {
11572: next if ($key =~ m{^https?://});
11573: my $ref = $mapping->{$key};
11574: my $newname = "/uploaded/$udom/$uname/portfolio/syllabus/$key";
11575: my $attrib;
11576: if (ref($allfiles{$mapping->{$key}}) eq 'ARRAY') {
11577: $attrib = join('|',@{$allfiles{$mapping->{$key}}});
11578: }
11579: if ($content =~ m{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}) {
11580: my $numchg = ($content =~ s{($attrib\s*=\s*['"]?)\Q$ref\E(['"]?)}{$1$newname$2}gi);
11581: $rewrites += $numchg;
11582: }
11583: }
11584: if ($rewrites) {
11585: my $saveresult;
11586: my $url = &Apache::lonnet::store_edited_file($container,$content,$udom,$uname,\$saveresult);
11587: if ($url eq $container) {
11588: my ($fname) = ($container =~ m{/([^/]+)$});
11589: $output .= '<p>'.&mt('Rewrote [quant,_1,link] as [quant,_1,absolute link] in [_2].',
11590: $count,'<span class="LC_filename">'.
11591: $fname.'</span>').'</p>';
11592: } else {
11593: $output .= '<p class="LC_error">'.
11594: &mt('Error: could not update links in [_1].',
11595: '<span class="LC_filename">'.
11596: $container.'</span>').'</p>';
11597:
11598: }
11599: }
11600: }
11601: }
1.987 raeburn 11602: } else {
11603: &logthis('Failed to parse '.$container.
11604: ' to modify references: '.$parse_result);
1.661 raeburn 11605: }
11606: }
1.1071 raeburn 11607: if (wantarray) {
11608: return ($output,$count,$codebasecount);
11609: } else {
11610: return $output;
11611: }
1.661 raeburn 11612: }
11613:
11614: sub check_for_existing {
11615: my ($path,$fname,$element) = @_;
11616: my ($state,$msg);
11617: if (-d $path.'/'.$fname) {
11618: $state = 'exists';
11619: $msg = &mt('Unable to upload [_1]. A directory by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11620: } elsif (-e $path.'/'.$fname) {
11621: $state = 'exists';
11622: $msg = &mt('Unable to upload [_1]. A file by that name was found in [_2].','<span class="LC_filename">'.$fname.'</span>',$path);
11623: }
11624: if ($state eq 'exists') {
11625: $msg = '<span class="LC_error">'.$msg.'</span><br />';
11626: }
11627: return ($state,$msg);
11628: }
11629:
11630: sub check_for_upload {
11631: my ($path,$fname,$group,$element,$portfolio_root,$port_path,
11632: $disk_quota,$current_disk_usage,$uname,$udom) = @_;
1.985 raeburn 11633: my $filesize = length($env{'form.'.$element});
11634: if (!$filesize) {
11635: my $msg = '<span class="LC_error">'.
11636: &mt('Unable to upload [_1]. (size = [_2] bytes)',
11637: '<span class="LC_filename">'.$fname.'</span>',
11638: $filesize).'<br />'.
1.1007 raeburn 11639: &mt('Either the file you attempted to upload was empty, or your web browser was unable to read its contents.').'<br />'.
1.985 raeburn 11640: '</span>';
11641: return ('zero_bytes',$msg);
11642: }
11643: $filesize = $filesize/1000; #express in k (1024?)
1.661 raeburn 11644: my $getpropath = 1;
1.1021 raeburn 11645: my ($dirlistref,$listerror) =
11646: &Apache::lonnet::dirlist($portfolio_root.$path,$udom,$uname,$getpropath);
1.661 raeburn 11647: my $found_file = 0;
11648: my $locked_file = 0;
1.991 raeburn 11649: my @lockers;
11650: my $navmap;
11651: if ($env{'request.course.id'}) {
11652: $navmap = Apache::lonnavmaps::navmap->new();
11653: }
1.1021 raeburn 11654: if (ref($dirlistref) eq 'ARRAY') {
11655: foreach my $line (@{$dirlistref}) {
11656: my ($file_name,$rest)=split(/\&/,$line,2);
11657: if ($file_name eq $fname){
11658: $file_name = $path.$file_name;
11659: if ($group ne '') {
11660: $file_name = $group.$file_name;
11661: }
11662: $found_file = 1;
11663: if (&Apache::lonnet::is_locked($file_name,$udom,$uname,\@lockers) eq 'true') {
11664: foreach my $lock (@lockers) {
11665: if (ref($lock) eq 'ARRAY') {
11666: my ($symb,$crsid) = @{$lock};
11667: if ($crsid eq $env{'request.course.id'}) {
11668: if (ref($navmap)) {
11669: my $res = $navmap->getBySymb($symb);
11670: foreach my $part (@{$res->parts()}) {
11671: my ($slot_status,$slot_time,$slot_name)=$res->check_for_slot($part);
11672: unless (($slot_status == $res->RESERVED) ||
11673: ($slot_status == $res->RESERVED_LOCATION)) {
11674: $locked_file = 1;
11675: }
1.991 raeburn 11676: }
1.1021 raeburn 11677: } else {
11678: $locked_file = 1;
1.991 raeburn 11679: }
11680: } else {
11681: $locked_file = 1;
11682: }
11683: }
1.1021 raeburn 11684: }
11685: } else {
11686: my @info = split(/\&/,$rest);
11687: my $currsize = $info[6]/1000;
11688: if ($currsize < $filesize) {
11689: my $extra = $filesize - $currsize;
11690: if (($current_disk_usage + $extra) > $disk_quota) {
1.1179 bisitz 11691: my $msg = '<p class="LC_warning">'.
1.1021 raeburn 11692: &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 11693: '<span class="LC_filename">'.$fname.'</span>',$filesize,$currsize).'</p>'.
11694: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',
11695: $disk_quota,$current_disk_usage).'</p>';
1.1021 raeburn 11696: return ('will_exceed_quota',$msg);
11697: }
1.984 raeburn 11698: }
11699: }
1.661 raeburn 11700: }
11701: }
11702: }
11703: if (($current_disk_usage + $filesize) > $disk_quota){
1.1179 bisitz 11704: my $msg = '<p class="LC_warning">'.
11705: &mt('Unable to upload [_1]. (size = [_2] kilobytes). Disk quota will be exceeded.','<span class="LC_filename">'.$fname.'</span>',$filesize).'</p>'.
1.1184 raeburn 11706: '<p>'.&mt('Disk quota is [_1] kilobytes. Your current disk usage is [_2] kilobytes.',$disk_quota,$current_disk_usage).'</p>';
1.661 raeburn 11707: return ('will_exceed_quota',$msg);
11708: } elsif ($found_file) {
11709: if ($locked_file) {
1.1179 bisitz 11710: my $msg = '<p class="LC_warning">';
1.661 raeburn 11711: $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 11712: $msg .= '</p>';
1.661 raeburn 11713: $msg .= &mt('You will be able to rename or delete existing [_1] after a grade has been assigned.','<span class="LC_filename">'.$fname.'</span>');
11714: return ('file_locked',$msg);
11715: } else {
1.1179 bisitz 11716: my $msg = '<p class="LC_error">';
1.984 raeburn 11717: $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 11718: $msg .= '</p>';
1.984 raeburn 11719: return ('existingfile',$msg);
1.661 raeburn 11720: }
11721: }
11722: }
11723:
1.987 raeburn 11724: sub check_for_traversal {
11725: my ($path,$url,$toplevel) = @_;
11726: my @parts=split(/\//,$path);
11727: my $cleanpath;
11728: my $fullpath = $url;
11729: for (my $i=0;$i<@parts;$i++) {
11730: next if ($parts[$i] eq '.');
11731: if ($parts[$i] eq '..') {
11732: $fullpath =~ s{([^/]+/)$}{};
11733: } else {
11734: $fullpath .= $parts[$i].'/';
11735: }
11736: }
11737: if ($fullpath =~ /^\Q$url\E(.*)$/) {
11738: $cleanpath = $1;
11739: } elsif ($fullpath =~ /^\Q$toplevel\E(.*)$/) {
11740: my $curr_toprel = $1;
11741: my @parts = split(/\//,$curr_toprel);
11742: my ($url_toprel) = ($url =~ /^\Q$toplevel\E(.*)$/);
11743: my @urlparts = split(/\//,$url_toprel);
11744: my $doubledots;
11745: my $startdiff = -1;
11746: for (my $i=0; $i<@urlparts; $i++) {
11747: if ($startdiff == -1) {
11748: unless ($urlparts[$i] eq $parts[$i]) {
11749: $startdiff = $i;
11750: $doubledots .= '../';
11751: }
11752: } else {
11753: $doubledots .= '../';
11754: }
11755: }
11756: if ($startdiff > -1) {
11757: $cleanpath = $doubledots;
11758: for (my $i=$startdiff; $i<@parts; $i++) {
11759: $cleanpath .= $parts[$i].'/';
11760: }
11761: }
11762: }
11763: $cleanpath =~ s{(/)$}{};
11764: return $cleanpath;
11765: }
1.31 albertel 11766:
1.1053 raeburn 11767: sub is_archive_file {
11768: my ($mimetype) = @_;
11769: if (($mimetype eq 'application/octet-stream') ||
11770: ($mimetype eq 'application/x-stuffit') ||
11771: ($mimetype =~ m{^application/(x\-)?(compressed|tar|zip|tgz|gz|gtar|gzip|gunzip|bz|bz2|bzip2)})) {
11772: return 1;
11773: }
11774: return;
11775: }
11776:
11777: sub decompress_form {
1.1065 raeburn 11778: my ($mimetype,$archiveurl,$action,$noextract,$hiddenelements,$dirlist) = @_;
1.1053 raeburn 11779: my %lt = &Apache::lonlocal::texthash (
11780: this => 'This file is an archive file.',
1.1067 raeburn 11781: camt => 'This file is a Camtasia archive file.',
1.1065 raeburn 11782: itsc => 'Its contents are as follows:',
1.1053 raeburn 11783: youm => 'You may wish to extract its contents.',
11784: extr => 'Extract contents',
1.1067 raeburn 11785: auto => 'LON-CAPA can process the files automatically, or you can decide how each should be handled.',
11786: proa => 'Process automatically?',
1.1053 raeburn 11787: yes => 'Yes',
11788: no => 'No',
1.1067 raeburn 11789: fold => 'Title for folder containing movie',
11790: movi => 'Title for page containing embedded movie',
1.1053 raeburn 11791: );
1.1065 raeburn 11792: my $fileloc = &Apache::lonnet::filelocation(undef,$archiveurl);
1.1067 raeburn 11793: my ($is_camtasia,$topdir,%toplevel,@paths);
1.1065 raeburn 11794: my $info = &list_archive_contents($fileloc,\@paths);
11795: if (@paths) {
11796: foreach my $path (@paths) {
11797: $path =~ s{^/}{};
1.1067 raeburn 11798: if ($path =~ m{^([^/]+)/$}) {
11799: $topdir = $1;
11800: }
1.1065 raeburn 11801: if ($path =~ m{^([^/]+)/}) {
11802: $toplevel{$1} = $path;
11803: } else {
11804: $toplevel{$path} = $path;
11805: }
11806: }
11807: }
1.1067 raeburn 11808: if ($mimetype =~ m{^application/(x\-)?(compressed|zip)}) {
1.1164 raeburn 11809: my @camtasia6 = ("$topdir/","$topdir/index.html",
1.1067 raeburn 11810: "$topdir/media/",
11811: "$topdir/media/$topdir.mp4",
11812: "$topdir/media/FirstFrame.png",
11813: "$topdir/media/player.swf",
11814: "$topdir/media/swfobject.js",
11815: "$topdir/media/expressInstall.swf");
1.1197 raeburn 11816: my @camtasia8_1 = ("$topdir/","$topdir/$topdir.html",
1.1164 raeburn 11817: "$topdir/$topdir.mp4",
11818: "$topdir/$topdir\_config.xml",
11819: "$topdir/$topdir\_controller.swf",
11820: "$topdir/$topdir\_embed.css",
11821: "$topdir/$topdir\_First_Frame.png",
11822: "$topdir/$topdir\_player.html",
11823: "$topdir/$topdir\_Thumbnails.png",
11824: "$topdir/playerProductInstall.swf",
11825: "$topdir/scripts/",
11826: "$topdir/scripts/config_xml.js",
11827: "$topdir/scripts/handlebars.js",
11828: "$topdir/scripts/jquery-1.7.1.min.js",
11829: "$topdir/scripts/jquery-ui-1.8.15.custom.min.js",
11830: "$topdir/scripts/modernizr.js",
11831: "$topdir/scripts/player-min.js",
11832: "$topdir/scripts/swfobject.js",
11833: "$topdir/skins/",
11834: "$topdir/skins/configuration_express.xml",
11835: "$topdir/skins/express_show/",
11836: "$topdir/skins/express_show/player-min.css",
11837: "$topdir/skins/express_show/spritesheet.png");
1.1197 raeburn 11838: my @camtasia8_4 = ("$topdir/","$topdir/$topdir.html",
11839: "$topdir/$topdir.mp4",
11840: "$topdir/$topdir\_config.xml",
11841: "$topdir/$topdir\_controller.swf",
11842: "$topdir/$topdir\_embed.css",
11843: "$topdir/$topdir\_First_Frame.png",
11844: "$topdir/$topdir\_player.html",
11845: "$topdir/$topdir\_Thumbnails.png",
11846: "$topdir/playerProductInstall.swf",
11847: "$topdir/scripts/",
11848: "$topdir/scripts/config_xml.js",
11849: "$topdir/scripts/techsmith-smart-player.min.js",
11850: "$topdir/skins/",
11851: "$topdir/skins/configuration_express.xml",
11852: "$topdir/skins/express_show/",
11853: "$topdir/skins/express_show/spritesheet.min.css",
11854: "$topdir/skins/express_show/spritesheet.png",
11855: "$topdir/skins/express_show/techsmith-smart-player.min.css");
1.1164 raeburn 11856: my @diffs = &compare_arrays(\@paths,\@camtasia6);
1.1067 raeburn 11857: if (@diffs == 0) {
1.1164 raeburn 11858: $is_camtasia = 6;
11859: } else {
1.1197 raeburn 11860: @diffs = &compare_arrays(\@paths,\@camtasia8_1);
1.1164 raeburn 11861: if (@diffs == 0) {
11862: $is_camtasia = 8;
1.1197 raeburn 11863: } else {
11864: @diffs = &compare_arrays(\@paths,\@camtasia8_4);
11865: if (@diffs == 0) {
11866: $is_camtasia = 8;
11867: }
1.1164 raeburn 11868: }
1.1067 raeburn 11869: }
11870: }
11871: my $output;
11872: if ($is_camtasia) {
11873: $output = <<"ENDCAM";
11874: <script type="text/javascript" language="Javascript">
11875: // <![CDATA[
11876:
11877: function camtasiaToggle() {
11878: for (var i=0; i<document.uploaded_decompress.autoextract_camtasia.length; i++) {
11879: if (document.uploaded_decompress.autoextract_camtasia[i].checked) {
1.1164 raeburn 11880: if (document.uploaded_decompress.autoextract_camtasia[i].value == $is_camtasia) {
1.1067 raeburn 11881: document.getElementById('camtasia_titles').style.display='block';
11882: } else {
11883: document.getElementById('camtasia_titles').style.display='none';
11884: }
11885: }
11886: }
11887: return;
11888: }
11889:
11890: // ]]>
11891: </script>
11892: <p>$lt{'camt'}</p>
11893: ENDCAM
1.1065 raeburn 11894: } else {
1.1067 raeburn 11895: $output = '<p>'.$lt{'this'};
11896: if ($info eq '') {
11897: $output .= ' '.$lt{'youm'}.'</p>'."\n";
11898: } else {
11899: $output .= ' '.$lt{'itsc'}.'</p>'."\n".
11900: '<div><pre>'.$info.'</pre></div>';
11901: }
1.1065 raeburn 11902: }
1.1067 raeburn 11903: $output .= '<form name="uploaded_decompress" action="'.$action.'" method="post">'."\n";
1.1065 raeburn 11904: my $duplicates;
11905: my $num = 0;
11906: if (ref($dirlist) eq 'ARRAY') {
11907: foreach my $item (@{$dirlist}) {
11908: if (ref($item) eq 'ARRAY') {
11909: if (exists($toplevel{$item->[0]})) {
11910: $duplicates .=
11911: &start_data_table_row().
11912: '<td><label><input type="radio" name="archive_overwrite_'.$num.'" '.
11913: 'value="0" checked="checked" />'.&mt('No').'</label>'.
11914: ' <label><input type="radio" name="archive_overwrite_'.$num.'" '.
11915: 'value="1" />'.&mt('Yes').'</label>'.
11916: '<input type="hidden" name="archive_overwrite_name_'.$num.'" value="'.$item->[0].'" /></td>'."\n".
11917: '<td>'.$item->[0].'</td>';
11918: if ($item->[2]) {
11919: $duplicates .= '<td>'.&mt('Directory').'</td>';
11920: } else {
11921: $duplicates .= '<td>'.&mt('File').'</td>';
11922: }
11923: $duplicates .= '<td>'.$item->[3].'</td>'.
11924: '<td>'.
11925: &Apache::lonlocal::locallocaltime($item->[4]).
11926: '</td>'.
11927: &end_data_table_row();
11928: $num ++;
11929: }
11930: }
11931: }
11932: }
11933: my $itemcount;
11934: if (@paths > 0) {
11935: $itemcount = scalar(@paths);
11936: } else {
11937: $itemcount = 1;
11938: }
1.1067 raeburn 11939: if ($is_camtasia) {
11940: $output .= $lt{'auto'}.'<br />'.
11941: '<span class="LC_nobreak">'.$lt{'proa'}.'<label>'.
1.1164 raeburn 11942: '<input type="radio" name="autoextract_camtasia" value="'.$is_camtasia.'" onclick="javascript:camtasiaToggle();" checked="checked" />'.
1.1067 raeburn 11943: $lt{'yes'}.'</label> <label>'.
11944: '<input type="radio" name="autoextract_camtasia" value="0" onclick="javascript:camtasiaToggle();" />'.
11945: $lt{'no'}.'</label></span><br />'.
11946: '<div id="camtasia_titles" style="display:block">'.
11947: &Apache::lonhtmlcommon::start_pick_box().
11948: &Apache::lonhtmlcommon::row_title($lt{'fold'}).
11949: '<input type="textbox" name="camtasia_foldername" value="'.$env{'form.comment'}.'" />'."\n".
11950: &Apache::lonhtmlcommon::row_closure().
11951: &Apache::lonhtmlcommon::row_title($lt{'movi'}).
11952: '<input type="textbox" name="camtasia_moviename" value="" />'."\n".
11953: &Apache::lonhtmlcommon::row_closure(1).
11954: &Apache::lonhtmlcommon::end_pick_box().
11955: '</div>';
11956: }
1.1065 raeburn 11957: $output .=
11958: '<input type="hidden" name="archive_overwrite_total" value="'.$num.'" />'.
1.1067 raeburn 11959: '<input type="hidden" name="archive_itemcount" value="'.$itemcount.'" />'.
11960: "\n";
1.1065 raeburn 11961: if ($duplicates ne '') {
11962: $output .= '<p><span class="LC_warning">'.
11963: &mt('Warning: decompression of the archive will overwrite the following items which already exist:').'</span><br />'.
11964: &start_data_table().
11965: &start_data_table_header_row().
11966: '<th>'.&mt('Overwrite?').'</th>'.
11967: '<th>'.&mt('Name').'</th>'.
11968: '<th>'.&mt('Type').'</th>'.
11969: '<th>'.&mt('Size').'</th>'.
11970: '<th>'.&mt('Last modified').'</th>'.
11971: &end_data_table_header_row().
11972: $duplicates.
11973: &end_data_table().
11974: '</p>';
11975: }
1.1067 raeburn 11976: $output .= '<input type="hidden" name="archiveurl" value="'.$archiveurl.'" />'."\n";
1.1053 raeburn 11977: if (ref($hiddenelements) eq 'HASH') {
11978: foreach my $hidden (sort(keys(%{$hiddenelements}))) {
11979: $output .= '<input type="hidden" name="'.$hidden.'" value="'.$hiddenelements->{$hidden}.'" />'."\n";
11980: }
11981: }
11982: $output .= <<"END";
1.1067 raeburn 11983: <br />
1.1053 raeburn 11984: <input type="submit" name="decompress" value="$lt{'extr'}" />
11985: </form>
11986: $noextract
11987: END
11988: return $output;
11989: }
11990:
1.1065 raeburn 11991: sub decompression_utility {
11992: my ($program) = @_;
11993: my @utilities = ('tar','gunzip','bunzip2','unzip');
11994: my $location;
11995: if (grep(/^\Q$program\E$/,@utilities)) {
11996: foreach my $dir ('/bin/','/usr/bin/','/usr/local/bin/','/sbin/',
11997: '/usr/sbin/') {
11998: if (-x $dir.$program) {
11999: $location = $dir.$program;
12000: last;
12001: }
12002: }
12003: }
12004: return $location;
12005: }
12006:
12007: sub list_archive_contents {
12008: my ($file,$pathsref) = @_;
12009: my (@cmd,$output);
12010: my $needsregexp;
12011: if ($file =~ /\.zip$/) {
12012: @cmd = (&decompression_utility('unzip'),"-l");
12013: $needsregexp = 1;
12014: } elsif (($file =~ m/\.tar\.gz$/) ||
12015: ($file =~ /\.tgz$/)) {
12016: @cmd = (&decompression_utility('tar'),"-ztf");
12017: } elsif ($file =~ /\.tar\.bz2$/) {
12018: @cmd = (&decompression_utility('tar'),"-jtf");
12019: } elsif ($file =~ m|\.tar$|) {
12020: @cmd = (&decompression_utility('tar'),"-tf");
12021: }
12022: if (@cmd) {
12023: undef($!);
12024: undef($@);
12025: if (open(my $fh,"-|", @cmd, $file)) {
12026: while (my $line = <$fh>) {
12027: $output .= $line;
12028: chomp($line);
12029: my $item;
12030: if ($needsregexp) {
12031: ($item) = ($line =~ /^\s*\d+\s+[\d\-]+\s+[\d:]+\s*(.+)$/);
12032: } else {
12033: $item = $line;
12034: }
12035: if ($item ne '') {
12036: unless (grep(/^\Q$item\E$/,@{$pathsref})) {
12037: push(@{$pathsref},$item);
12038: }
12039: }
12040: }
12041: close($fh);
12042: }
12043: }
12044: return $output;
12045: }
12046:
1.1053 raeburn 12047: sub decompress_uploaded_file {
12048: my ($file,$dir) = @_;
12049: &Apache::lonnet::appenv({'cgi.file' => $file});
12050: &Apache::lonnet::appenv({'cgi.dir' => $dir});
12051: my $result = &Apache::lonnet::ssi_body('/cgi-bin/decompress.pl');
12052: my ($handle) = ($env{'user.environment'} =~m{/([^/]+)\.id$});
12053: my $lonidsdir = $Apache::lonnet::perlvar{'lonIDsDir'};
12054: &Apache::lonnet::transfer_profile_to_env($lonidsdir,$handle,1);
12055: my $decompressed = $env{'cgi.decompressed'};
12056: &Apache::lonnet::delenv('cgi.file');
12057: &Apache::lonnet::delenv('cgi.dir');
12058: &Apache::lonnet::delenv('cgi.decompressed');
12059: return ($decompressed,$result);
12060: }
12061:
1.1055 raeburn 12062: sub process_decompression {
12063: my ($docudom,$docuname,$file,$destination,$dir_root,$hiddenelem) = @_;
12064: my ($dir,$error,$warning,$output);
1.1180 raeburn 12065: if ($file !~ /\.(zip|tar|bz2|gz|tar.gz|tar.bz2|tgz)$/i) {
1.1120 bisitz 12066: $error = &mt('Filename not a supported archive file type.').
12067: '<br />'.&mt('Filename should end with one of: [_1].',
1.1055 raeburn 12068: '.zip, .tar, .bz2, .gz, .tar.gz, .tar.bz2, .tgz');
12069: } else {
12070: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12071: if ($docuhome eq 'no_host') {
12072: $error = &mt('Could not determine home server for course.');
12073: } else {
12074: my @ids=&Apache::lonnet::current_machine_ids();
12075: my $currdir = "$dir_root/$destination";
12076: if (grep(/^\Q$docuhome\E$/,@ids)) {
12077: $dir = &LONCAPA::propath($docudom,$docuname).
12078: "$dir_root/$destination";
12079: } else {
12080: $dir = $Apache::lonnet::perlvar{'lonDocRoot'}.
12081: "$dir_root/$docudom/$docuname/$destination";
12082: unless (&Apache::lonnet::repcopy_userfile("$dir/$file") eq 'ok') {
12083: $error = &mt('Archive file not found.');
12084: }
12085: }
1.1065 raeburn 12086: my (@to_overwrite,@to_skip);
12087: if ($env{'form.archive_overwrite_total'} > 0) {
12088: my $total = $env{'form.archive_overwrite_total'};
12089: for (my $i=0; $i<$total; $i++) {
12090: if ($env{'form.archive_overwrite_'.$i} == 1) {
12091: push(@to_overwrite,$env{'form.archive_overwrite_name_'.$i});
12092: } elsif ($env{'form.archive_overwrite_'.$i} == 0) {
12093: push(@to_skip,$env{'form.archive_overwrite_name_'.$i});
12094: }
12095: }
12096: }
12097: my $numskip = scalar(@to_skip);
12098: if (($numskip > 0) &&
12099: ($numskip == $env{'form.archive_itemcount'})) {
12100: $warning = &mt('All items in the archive file already exist, and no overwriting of existing files has been requested.');
12101: } elsif ($dir eq '') {
1.1055 raeburn 12102: $error = &mt('Directory containing archive file unavailable.');
12103: } elsif (!$error) {
1.1065 raeburn 12104: my ($decompressed,$display);
12105: if ($numskip > 0) {
12106: my $tempdir = time.'_'.$$.int(rand(10000));
12107: mkdir("$dir/$tempdir",0755);
12108: system("mv $dir/$file $dir/$tempdir/$file");
12109: ($decompressed,$display) =
12110: &decompress_uploaded_file($file,"$dir/$tempdir");
12111: foreach my $item (@to_skip) {
12112: if (($item ne '') && ($item !~ /\.\./)) {
12113: if (-f "$dir/$tempdir/$item") {
12114: unlink("$dir/$tempdir/$item");
12115: } elsif (-d "$dir/$tempdir/$item") {
12116: system("rm -rf $dir/$tempdir/$item");
12117: }
12118: }
12119: }
12120: system("mv $dir/$tempdir/* $dir");
12121: rmdir("$dir/$tempdir");
12122: } else {
12123: ($decompressed,$display) =
12124: &decompress_uploaded_file($file,$dir);
12125: }
1.1055 raeburn 12126: if ($decompressed eq 'ok') {
1.1065 raeburn 12127: $output = '<p class="LC_info">'.
12128: &mt('Files extracted successfully from archive.').
12129: '</p>'."\n";
1.1055 raeburn 12130: my ($warning,$result,@contents);
12131: my ($newdirlistref,$newlisterror) =
12132: &Apache::lonnet::dirlist($currdir,$docudom,
12133: $docuname,1);
12134: my (%is_dir,%changes,@newitems);
12135: my $dirptr = 16384;
1.1065 raeburn 12136: if (ref($newdirlistref) eq 'ARRAY') {
1.1055 raeburn 12137: foreach my $dir_line (@{$newdirlistref}) {
12138: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
1.1065 raeburn 12139: unless (($item =~ /^\.+$/) || ($item eq $file) ||
12140: ((@to_skip > 0) && (grep(/^\Q$item\E$/,@to_skip)))) {
1.1055 raeburn 12141: push(@newitems,$item);
12142: if ($dirptr&$testdir) {
12143: $is_dir{$item} = 1;
12144: }
12145: $changes{$item} = 1;
12146: }
12147: }
12148: }
12149: if (keys(%changes) > 0) {
12150: foreach my $item (sort(@newitems)) {
12151: if ($changes{$item}) {
12152: push(@contents,$item);
12153: }
12154: }
12155: }
12156: if (@contents > 0) {
1.1067 raeburn 12157: my $wantform;
12158: unless ($env{'form.autoextract_camtasia'}) {
12159: $wantform = 1;
12160: }
1.1056 raeburn 12161: my (%children,%parent,%dirorder,%titles);
1.1055 raeburn 12162: my ($count,$datatable) = &get_extracted($docudom,$docuname,
12163: $currdir,\%is_dir,
12164: \%children,\%parent,
1.1056 raeburn 12165: \@contents,\%dirorder,
12166: \%titles,$wantform);
1.1055 raeburn 12167: if ($datatable ne '') {
12168: $output .= &archive_options_form('decompressed',$datatable,
12169: $count,$hiddenelem);
1.1065 raeburn 12170: my $startcount = 6;
1.1055 raeburn 12171: $output .= &archive_javascript($startcount,$count,
1.1056 raeburn 12172: \%titles,\%children);
1.1055 raeburn 12173: }
1.1067 raeburn 12174: if ($env{'form.autoextract_camtasia'}) {
1.1164 raeburn 12175: my $version = $env{'form.autoextract_camtasia'};
1.1067 raeburn 12176: my %displayed;
12177: my $total = 1;
12178: $env{'form.archive_directory'} = [];
12179: foreach my $i (sort { $a <=> $b } keys(%dirorder)) {
12180: my $path = join('/',map { $titles{$_}; } @{$dirorder{$i}});
12181: $path =~ s{/$}{};
12182: my $item;
12183: if ($path ne '') {
12184: $item = "$path/$titles{$i}";
12185: } else {
12186: $item = $titles{$i};
12187: }
12188: $env{'form.archive_content_'.$i} = "$dir_root/$destination/$item";
12189: if ($item eq $contents[0]) {
12190: push(@{$env{'form.archive_directory'}},$i);
12191: $env{'form.archive_'.$i} = 'display';
12192: $env{'form.archive_title_'.$i} = $env{'form.camtasia_foldername'};
12193: $displayed{'folder'} = $i;
1.1164 raeburn 12194: } elsif ((($item eq "$contents[0]/index.html") && ($version == 6)) ||
12195: (($item eq "$contents[0]/$contents[0]".'.html') && ($version == 8))) {
1.1067 raeburn 12196: $env{'form.archive_'.$i} = 'display';
12197: $env{'form.archive_title_'.$i} = $env{'form.camtasia_moviename'};
12198: $displayed{'web'} = $i;
12199: } else {
1.1164 raeburn 12200: if ((($item eq "$contents[0]/media") && ($version == 6)) ||
12201: ((($item eq "$contents[0]/scripts") || ($item eq "$contents[0]/skins") ||
12202: ($item eq "$contents[0]/skins/express_show")) && ($version == 8))) {
1.1067 raeburn 12203: push(@{$env{'form.archive_directory'}},$i);
12204: }
12205: $env{'form.archive_'.$i} = 'dependency';
12206: }
12207: $total ++;
12208: }
12209: for (my $i=1; $i<$total; $i++) {
12210: next if ($i == $displayed{'web'});
12211: next if ($i == $displayed{'folder'});
12212: $env{'form.archive_dependent_on_'.$i} = $displayed{'web'};
12213: }
12214: $env{'form.phase'} = 'decompress_cleanup';
12215: $env{'form.archivedelete'} = 1;
12216: $env{'form.archive_count'} = $total-1;
12217: $output .=
12218: &process_extracted_files('coursedocs',$docudom,
12219: $docuname,$destination,
12220: $dir_root,$hiddenelem);
12221: }
1.1055 raeburn 12222: } else {
12223: $warning = &mt('No new items extracted from archive file.');
12224: }
12225: } else {
12226: $output = $display;
12227: $error = &mt('An error occurred during extraction from the archive file.');
12228: }
12229: }
12230: }
12231: }
12232: if ($error) {
12233: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12234: $error.'</p>'."\n";
12235: }
12236: if ($warning) {
12237: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12238: }
12239: return $output;
12240: }
12241:
12242: sub get_extracted {
1.1056 raeburn 12243: my ($docudom,$docuname,$currdir,$is_dir,$children,$parent,$contents,$dirorder,
12244: $titles,$wantform) = @_;
1.1055 raeburn 12245: my $count = 0;
12246: my $depth = 0;
12247: my $datatable;
1.1056 raeburn 12248: my @hierarchy;
1.1055 raeburn 12249: return unless ((ref($is_dir) eq 'HASH') && (ref($children) eq 'HASH') &&
1.1056 raeburn 12250: (ref($parent) eq 'HASH') && (ref($contents) eq 'ARRAY') &&
12251: (ref($dirorder) eq 'HASH') && (ref($titles) eq 'HASH'));
1.1055 raeburn 12252: foreach my $item (@{$contents}) {
12253: $count ++;
1.1056 raeburn 12254: @{$dirorder->{$count}} = @hierarchy;
12255: $titles->{$count} = $item;
1.1055 raeburn 12256: &archive_hierarchy($depth,$count,$parent,$children);
12257: if ($wantform) {
12258: $datatable .= &archive_row($is_dir->{$item},$item,
12259: $currdir,$depth,$count);
12260: }
12261: if ($is_dir->{$item}) {
12262: $depth ++;
1.1056 raeburn 12263: push(@hierarchy,$count);
12264: $parent->{$depth} = $count;
1.1055 raeburn 12265: $datatable .=
12266: &recurse_extracted_archive("$currdir/$item",$docudom,$docuname,
1.1056 raeburn 12267: \$depth,\$count,\@hierarchy,$dirorder,
12268: $children,$parent,$titles,$wantform);
1.1055 raeburn 12269: $depth --;
1.1056 raeburn 12270: pop(@hierarchy);
1.1055 raeburn 12271: }
12272: }
12273: return ($count,$datatable);
12274: }
12275:
12276: sub recurse_extracted_archive {
1.1056 raeburn 12277: my ($currdir,$docudom,$docuname,$depth,$count,$hierarchy,$dirorder,
12278: $children,$parent,$titles,$wantform) = @_;
1.1055 raeburn 12279: my $result='';
1.1056 raeburn 12280: unless ((ref($depth)) && (ref($count)) && (ref($hierarchy) eq 'ARRAY') &&
12281: (ref($children) eq 'HASH') && (ref($parent) eq 'HASH') &&
12282: (ref($dirorder) eq 'HASH')) {
1.1055 raeburn 12283: return $result;
12284: }
12285: my $dirptr = 16384;
12286: my ($newdirlistref,$newlisterror) =
12287: &Apache::lonnet::dirlist($currdir,$docudom,$docuname,1);
12288: if (ref($newdirlistref) eq 'ARRAY') {
12289: foreach my $dir_line (@{$newdirlistref}) {
12290: my ($item,undef,undef,$testdir)=split(/\&/,$dir_line,5);
12291: unless ($item =~ /^\.+$/) {
12292: $$count ++;
1.1056 raeburn 12293: @{$dirorder->{$$count}} = @{$hierarchy};
12294: $titles->{$$count} = $item;
1.1055 raeburn 12295: &archive_hierarchy($$depth,$$count,$parent,$children);
1.1056 raeburn 12296:
1.1055 raeburn 12297: my $is_dir;
12298: if ($dirptr&$testdir) {
12299: $is_dir = 1;
12300: }
12301: if ($wantform) {
12302: $result .= &archive_row($is_dir,$item,$currdir,$$depth,$$count);
12303: }
12304: if ($is_dir) {
12305: $$depth ++;
1.1056 raeburn 12306: push(@{$hierarchy},$$count);
12307: $parent->{$$depth} = $$count;
1.1055 raeburn 12308: $result .=
12309: &recurse_extracted_archive("$currdir/$item",$docudom,
12310: $docuname,$depth,$count,
1.1056 raeburn 12311: $hierarchy,$dirorder,$children,
12312: $parent,$titles,$wantform);
1.1055 raeburn 12313: $$depth --;
1.1056 raeburn 12314: pop(@{$hierarchy});
1.1055 raeburn 12315: }
12316: }
12317: }
12318: }
12319: return $result;
12320: }
12321:
12322: sub archive_hierarchy {
12323: my ($depth,$count,$parent,$children) =@_;
12324: if ((ref($parent) eq 'HASH') && (ref($children) eq 'HASH')) {
12325: if (exists($parent->{$depth})) {
12326: $children->{$parent->{$depth}} .= $count.':';
12327: }
12328: }
12329: return;
12330: }
12331:
12332: sub archive_row {
12333: my ($is_dir,$item,$currdir,$depth,$count) = @_;
12334: my ($name) = ($item =~ m{([^/]+)$});
12335: my %choices = &Apache::lonlocal::texthash (
1.1059 raeburn 12336: 'display' => 'Add as file',
1.1055 raeburn 12337: 'dependency' => 'Include as dependency',
12338: 'discard' => 'Discard',
12339: );
12340: if ($is_dir) {
1.1059 raeburn 12341: $choices{'display'} = &mt('Add as folder');
1.1055 raeburn 12342: }
1.1056 raeburn 12343: my $output = &start_data_table_row().'<td align="right">'.$count.'</td>'."\n";
12344: my $offset = 0;
1.1055 raeburn 12345: foreach my $action ('display','dependency','discard') {
1.1056 raeburn 12346: $offset ++;
1.1065 raeburn 12347: if ($action ne 'display') {
12348: $offset ++;
12349: }
1.1055 raeburn 12350: $output .= '<td><span class="LC_nobreak">'.
12351: '<label><input type="radio" name="archive_'.$count.
12352: '" id="archive_'.$action.'_'.$count.'" value="'.$action.'"';
12353: my $text = $choices{$action};
12354: if ($is_dir) {
12355: $output .= ' onclick="javascript:propagateCheck(this.form,'."'$count'".');"';
12356: if ($action eq 'display') {
1.1059 raeburn 12357: $text = &mt('Add as folder');
1.1055 raeburn 12358: }
1.1056 raeburn 12359: } else {
12360: $output .= ' onclick="javascript:dependencyCheck(this.form,'."$count,$offset".');"';
12361:
12362: }
12363: $output .= ' /> '.$choices{$action}.'</label></span>';
12364: if ($action eq 'dependency') {
12365: $output .= '<div id="arc_depon_'.$count.'" style="display:none;">'."\n".
12366: &mt('Used by:').' <select name="archive_dependent_on_'.$count.'" '.
12367: 'onchange="propagateSelect(this.form,'."$count,$offset".')">'."\n".
12368: '<option value=""></option>'."\n".
12369: '</select>'."\n".
12370: '</div>';
1.1059 raeburn 12371: } elsif ($action eq 'display') {
12372: $output .= '<div id="arc_title_'.$count.'" style="display:none;">'."\n".
12373: &mt('Title:').' <input type="text" name="archive_title_'.$count.'" id="archive_title_'.$count.'" />'."\n".
12374: '</div>';
1.1055 raeburn 12375: }
1.1056 raeburn 12376: $output .= '</td>';
1.1055 raeburn 12377: }
12378: $output .= '<td><input type="hidden" name="archive_content_'.$count.'" value="'.
12379: &HTML::Entities::encode("$currdir/$item",'"<>&').'" />'.(' ' x 2);
12380: for (my $i=0; $i<$depth; $i++) {
12381: $output .= ('<img src="/adm/lonIcons/whitespace1.gif" class="LC_docs_spacer" alt="" />' x2)."\n";
12382: }
12383: if ($is_dir) {
12384: $output .= '<img src="/adm/lonIcons/navmap.folder.open.gif" alt="" /> '."\n".
12385: '<input type="hidden" name="archive_directory" value="'.$count.'" />'."\n";
12386: } else {
12387: $output .= '<input type="hidden" name="archive_file" value="'.$count.'" />'."\n";
12388: }
12389: $output .= ' '.$name.'</td>'."\n".
12390: &end_data_table_row();
12391: return $output;
12392: }
12393:
12394: sub archive_options_form {
1.1065 raeburn 12395: my ($form,$display,$count,$hiddenelem) = @_;
12396: my %lt = &Apache::lonlocal::texthash(
12397: perm => 'Permanently remove archive file?',
12398: hows => 'How should each extracted item be incorporated in the course?',
12399: cont => 'Content actions for all',
12400: addf => 'Add as folder/file',
12401: incd => 'Include as dependency for a displayed file',
12402: disc => 'Discard',
12403: no => 'No',
12404: yes => 'Yes',
12405: save => 'Save',
12406: );
12407: my $output = <<"END";
12408: <form name="$form" method="post" action="">
12409: <p><span class="LC_nobreak">$lt{'perm'}
12410: <label>
12411: <input type="radio" name="archivedelete" value="0" checked="checked" />$lt{'no'}
12412: </label>
12413:
12414: <label>
12415: <input type="radio" name="archivedelete" value="1" />$lt{'yes'}</label>
12416: </span>
12417: </p>
12418: <input type="hidden" name="phase" value="decompress_cleanup" />
12419: <br />$lt{'hows'}
12420: <div class="LC_columnSection">
12421: <fieldset>
12422: <legend>$lt{'cont'}</legend>
12423: <input type="button" value="$lt{'addf'}" onclick="javascript:checkAll(document.$form,'display');" />
12424: <input type="button" value="$lt{'incd'}" onclick="javascript:checkAll(document.$form,'dependency');" />
12425: <input type="button" value="$lt{'disc'}" onclick="javascript:checkAll(document.$form,'discard');" />
12426: </fieldset>
12427: </div>
12428: END
12429: return $output.
1.1055 raeburn 12430: &start_data_table()."\n".
1.1065 raeburn 12431: $display."\n".
1.1055 raeburn 12432: &end_data_table()."\n".
12433: '<input type="hidden" name="archive_count" value="'.$count.'" />'.
12434: $hiddenelem.
1.1065 raeburn 12435: '<br /><input type="submit" name="archive_submit" value="'.$lt{'save'}.'" />'.
1.1055 raeburn 12436: '</form>';
12437: }
12438:
12439: sub archive_javascript {
1.1056 raeburn 12440: my ($startcount,$numitems,$titles,$children) = @_;
12441: return unless ((ref($titles) eq 'HASH') && (ref($children) eq 'HASH'));
1.1059 raeburn 12442: my $maintitle = $env{'form.comment'};
1.1055 raeburn 12443: my $scripttag = <<START;
12444: <script type="text/javascript">
12445: // <![CDATA[
12446:
12447: function checkAll(form,prefix) {
12448: var idstr = new RegExp("^archive_"+prefix+"_\\\\d+\$");
12449: for (var i=0; i < form.elements.length; i++) {
12450: var id = form.elements[i].id;
12451: if ((id != '') && (id != undefined)) {
12452: if (idstr.test(id)) {
12453: if (form.elements[i].type == 'radio') {
12454: form.elements[i].checked = true;
1.1056 raeburn 12455: var nostart = i-$startcount;
1.1059 raeburn 12456: var offset = nostart%7;
12457: var count = (nostart-offset)/7;
1.1056 raeburn 12458: dependencyCheck(form,count,offset);
1.1055 raeburn 12459: }
12460: }
12461: }
12462: }
12463: }
12464:
12465: function propagateCheck(form,count) {
12466: if (count > 0) {
1.1059 raeburn 12467: var startelement = $startcount + ((count-1) * 7);
12468: for (var j=1; j<6; j++) {
12469: if ((j != 2) && (j != 4)) {
1.1056 raeburn 12470: var item = startelement + j;
12471: if (form.elements[item].type == 'radio') {
12472: if (form.elements[item].checked) {
12473: containerCheck(form,count,j);
12474: break;
12475: }
1.1055 raeburn 12476: }
12477: }
12478: }
12479: }
12480: }
12481:
12482: numitems = $numitems
1.1056 raeburn 12483: var titles = new Array(numitems);
12484: var parents = new Array(numitems);
1.1055 raeburn 12485: for (var i=0; i<numitems; i++) {
1.1056 raeburn 12486: parents[i] = new Array;
1.1055 raeburn 12487: }
1.1059 raeburn 12488: var maintitle = '$maintitle';
1.1055 raeburn 12489:
12490: START
12491:
1.1056 raeburn 12492: foreach my $container (sort { $a <=> $b } (keys(%{$children}))) {
12493: my @contents = split(/:/,$children->{$container});
1.1055 raeburn 12494: for (my $i=0; $i<@contents; $i ++) {
12495: $scripttag .= 'parents['.$container.']['.$i.'] = '.$contents[$i]."\n";
12496: }
12497: }
12498:
1.1056 raeburn 12499: foreach my $key (sort { $a <=> $b } (keys(%{$titles}))) {
12500: $scripttag .= "titles[$key] = '".$titles->{$key}."';\n";
12501: }
12502:
1.1055 raeburn 12503: $scripttag .= <<END;
12504:
12505: function containerCheck(form,count,offset) {
12506: if (count > 0) {
1.1056 raeburn 12507: dependencyCheck(form,count,offset);
1.1059 raeburn 12508: var item = (offset+$startcount)+7*(count-1);
1.1055 raeburn 12509: form.elements[item].checked = true;
12510: if(Object.prototype.toString.call(parents[count]) === '[object Array]') {
12511: if (parents[count].length > 0) {
12512: for (var j=0; j<parents[count].length; j++) {
1.1056 raeburn 12513: containerCheck(form,parents[count][j],offset);
12514: }
12515: }
12516: }
12517: }
12518: }
12519:
12520: function dependencyCheck(form,count,offset) {
12521: if (count > 0) {
1.1059 raeburn 12522: var chosen = (offset+$startcount)+7*(count-1);
12523: var depitem = $startcount + ((count-1) * 7) + 4;
1.1056 raeburn 12524: var currtype = form.elements[depitem].type;
12525: if (form.elements[chosen].value == 'dependency') {
12526: document.getElementById('arc_depon_'+count).style.display='block';
12527: form.elements[depitem].options.length = 0;
12528: form.elements[depitem].options[0] = new Option('Select','',true,true);
1.1085 raeburn 12529: for (var i=1; i<=numitems; i++) {
12530: if (i == count) {
12531: continue;
12532: }
1.1059 raeburn 12533: var startelement = $startcount + (i-1) * 7;
12534: for (var j=1; j<6; j++) {
12535: if ((j != 2) && (j!= 4)) {
1.1056 raeburn 12536: var item = startelement + j;
12537: if (form.elements[item].type == 'radio') {
12538: if (form.elements[item].checked) {
12539: if (form.elements[item].value == 'display') {
12540: var n = form.elements[depitem].options.length;
12541: form.elements[depitem].options[n] = new Option(titles[i],i,false,false);
12542: }
12543: }
12544: }
12545: }
12546: }
12547: }
12548: } else {
12549: document.getElementById('arc_depon_'+count).style.display='none';
12550: form.elements[depitem].options.length = 0;
12551: form.elements[depitem].options[0] = new Option('Select','',true,true);
12552: }
1.1059 raeburn 12553: titleCheck(form,count,offset);
1.1056 raeburn 12554: }
12555: }
12556:
12557: function propagateSelect(form,count,offset) {
12558: if (count > 0) {
1.1065 raeburn 12559: var item = (1+offset+$startcount)+7*(count-1);
1.1056 raeburn 12560: var picked = form.elements[item].options[form.elements[item].selectedIndex].value;
12561: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12562: if (parents[count].length > 0) {
12563: for (var j=0; j<parents[count].length; j++) {
12564: containerSelect(form,parents[count][j],offset,picked);
1.1055 raeburn 12565: }
12566: }
12567: }
12568: }
12569: }
1.1056 raeburn 12570:
12571: function containerSelect(form,count,offset,picked) {
12572: if (count > 0) {
1.1065 raeburn 12573: var item = (offset+$startcount)+7*(count-1);
1.1056 raeburn 12574: if (form.elements[item].type == 'radio') {
12575: if (form.elements[item].value == 'dependency') {
12576: if (form.elements[item+1].type == 'select-one') {
12577: for (var i=0; i<form.elements[item+1].options.length; i++) {
12578: if (form.elements[item+1].options[i].value == picked) {
12579: form.elements[item+1].selectedIndex = i;
12580: break;
12581: }
12582: }
12583: }
12584: if (Object.prototype.toString.call(parents[count]) === '[object Array]') {
12585: if (parents[count].length > 0) {
12586: for (var j=0; j<parents[count].length; j++) {
12587: containerSelect(form,parents[count][j],offset,picked);
12588: }
12589: }
12590: }
12591: }
12592: }
12593: }
12594: }
12595:
1.1059 raeburn 12596: function titleCheck(form,count,offset) {
12597: if (count > 0) {
12598: var chosen = (offset+$startcount)+7*(count-1);
12599: var depitem = $startcount + ((count-1) * 7) + 2;
12600: var currtype = form.elements[depitem].type;
12601: if (form.elements[chosen].value == 'display') {
12602: document.getElementById('arc_title_'+count).style.display='block';
12603: if ((count==1) && ((parents[count].length > 0) || (numitems == 1))) {
12604: document.getElementById('archive_title_'+count).value=maintitle;
12605: }
12606: } else {
12607: document.getElementById('arc_title_'+count).style.display='none';
12608: if (currtype == 'text') {
12609: document.getElementById('archive_title_'+count).value='';
12610: }
12611: }
12612: }
12613: return;
12614: }
12615:
1.1055 raeburn 12616: // ]]>
12617: </script>
12618: END
12619: return $scripttag;
12620: }
12621:
12622: sub process_extracted_files {
1.1067 raeburn 12623: my ($context,$docudom,$docuname,$destination,$dir_root,$hiddenelem) = @_;
1.1055 raeburn 12624: my $numitems = $env{'form.archive_count'};
12625: return unless ($numitems);
12626: my @ids=&Apache::lonnet::current_machine_ids();
12627: my ($prefix,$pathtocheck,$dir,$ishome,$error,$warning,%toplevelitems,%is_dir,
1.1067 raeburn 12628: %folders,%containers,%mapinner,%prompttofetch);
1.1055 raeburn 12629: my $docuhome = &Apache::lonnet::homeserver($docuname,$docudom);
12630: if (grep(/^\Q$docuhome\E$/,@ids)) {
12631: $prefix = &LONCAPA::propath($docudom,$docuname);
12632: $pathtocheck = "$dir_root/$destination";
12633: $dir = $dir_root;
12634: $ishome = 1;
12635: } else {
12636: $prefix = $Apache::lonnet::perlvar{'lonDocRoot'};
12637: $pathtocheck = "$dir_root/$docudom/$docuname/$destination";
12638: $dir = "$dir_root/$docudom/$docuname";
12639: }
12640: my $currdir = "$dir_root/$destination";
12641: (my $docstype,$mapinner{'0'}) = ($destination =~ m{^(docs|supplemental)/(\w+)/});
12642: if ($env{'form.folderpath'}) {
12643: my @items = split('&',$env{'form.folderpath'});
12644: $folders{'0'} = $items[-2];
1.1099 raeburn 12645: if ($env{'form.folderpath'} =~ /\:1$/) {
12646: $containers{'0'}='page';
12647: } else {
12648: $containers{'0'}='sequence';
12649: }
1.1055 raeburn 12650: }
12651: my @archdirs = &get_env_multiple('form.archive_directory');
12652: if ($numitems) {
12653: for (my $i=1; $i<=$numitems; $i++) {
12654: my $path = $env{'form.archive_content_'.$i};
12655: if ($path =~ m{^\Q$pathtocheck\E/([^/]+)$}) {
12656: my $item = $1;
12657: $toplevelitems{$item} = $i;
12658: if (grep(/^\Q$i\E$/,@archdirs)) {
12659: $is_dir{$item} = 1;
12660: }
12661: }
12662: }
12663: }
1.1067 raeburn 12664: my ($output,%children,%parent,%titles,%dirorder,$result);
1.1055 raeburn 12665: if (keys(%toplevelitems) > 0) {
12666: my @contents = sort(keys(%toplevelitems));
1.1056 raeburn 12667: (my $count,undef) = &get_extracted($docudom,$docuname,$currdir,\%is_dir,\%children,
12668: \%parent,\@contents,\%dirorder,\%titles);
1.1055 raeburn 12669: }
1.1066 raeburn 12670: my (%referrer,%orphaned,%todelete,%todeletedir,%newdest,%newseqid);
1.1055 raeburn 12671: if ($numitems) {
12672: for (my $i=1; $i<=$numitems; $i++) {
1.1086 raeburn 12673: next if ($env{'form.archive_'.$i} eq 'dependency');
1.1055 raeburn 12674: my $path = $env{'form.archive_content_'.$i};
12675: if ($path =~ /^\Q$pathtocheck\E/) {
12676: if ($env{'form.archive_'.$i} eq 'discard') {
12677: if ($prefix ne '' && $path ne '') {
12678: if (-e $prefix.$path) {
1.1066 raeburn 12679: if ((@archdirs > 0) &&
12680: (grep(/^\Q$i\E$/,@archdirs))) {
12681: $todeletedir{$prefix.$path} = 1;
12682: } else {
12683: $todelete{$prefix.$path} = 1;
12684: }
1.1055 raeburn 12685: }
12686: }
12687: } elsif ($env{'form.archive_'.$i} eq 'display') {
1.1059 raeburn 12688: my ($docstitle,$title,$url,$outer);
1.1055 raeburn 12689: ($title) = ($path =~ m{/([^/]+)$});
1.1059 raeburn 12690: $docstitle = $env{'form.archive_title_'.$i};
12691: if ($docstitle eq '') {
12692: $docstitle = $title;
12693: }
1.1055 raeburn 12694: $outer = 0;
1.1056 raeburn 12695: if (ref($dirorder{$i}) eq 'ARRAY') {
12696: if (@{$dirorder{$i}} > 0) {
12697: foreach my $item (reverse(@{$dirorder{$i}})) {
1.1055 raeburn 12698: if ($env{'form.archive_'.$item} eq 'display') {
12699: $outer = $item;
12700: last;
12701: }
12702: }
12703: }
12704: }
12705: my ($errtext,$fatal) =
12706: &LONCAPA::map::mapread('/uploaded/'.$docudom.'/'.$docuname.
12707: '/'.$folders{$outer}.'.'.
12708: $containers{$outer});
12709: next if ($fatal);
12710: if ((@archdirs > 0) && (grep(/^\Q$i\E$/,@archdirs))) {
12711: if ($context eq 'coursedocs') {
1.1056 raeburn 12712: $mapinner{$i} = time;
1.1055 raeburn 12713: $folders{$i} = 'default_'.$mapinner{$i};
12714: $containers{$i} = 'sequence';
12715: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12716: $folders{$i}.'.'.$containers{$i};
12717: my $newidx = &LONCAPA::map::getresidx();
12718: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12719: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12720: push(@LONCAPA::map::order,$newidx);
12721: my ($outtext,$errtext) =
12722: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12723: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 12724: '.'.$containers{$outer},1,1);
1.1056 raeburn 12725: $newseqid{$i} = $newidx;
1.1067 raeburn 12726: unless ($errtext) {
12727: $result .= '<li>'.&mt('Folder: [_1] added to course',$docstitle).'</li>'."\n";
12728: }
1.1055 raeburn 12729: }
12730: } else {
12731: if ($context eq 'coursedocs') {
12732: my $newidx=&LONCAPA::map::getresidx();
12733: my $url = '/uploaded/'.$docudom.'/'.$docuname.'/'.
12734: $docstype.'/'.$mapinner{$outer}.'/'.$newidx.'/'.
12735: $title;
12736: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}") {
12737: mkdir("$prefix$dir/$docstype/$mapinner{$outer}",0755);
12738: }
12739: if (!-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12740: mkdir("$prefix$dir/$docstype/$mapinner{$outer}/$newidx");
12741: }
12742: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx") {
12743: system("mv $prefix$path $prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title");
1.1056 raeburn 12744: $newdest{$i} = "$prefix$dir/$docstype/$mapinner{$outer}/$newidx";
1.1067 raeburn 12745: unless ($ishome) {
12746: my $fetch = "$newdest{$i}/$title";
12747: $fetch =~ s/^\Q$prefix$dir\E//;
12748: $prompttofetch{$fetch} = 1;
12749: }
1.1055 raeburn 12750: }
12751: $LONCAPA::map::resources[$newidx]=
1.1059 raeburn 12752: $docstitle.':'.$url.':false:normal:res';
1.1055 raeburn 12753: push(@LONCAPA::map::order, $newidx);
12754: my ($outtext,$errtext)=
12755: &LONCAPA::map::storemap('/uploaded/'.$docudom.'/'.
12756: $docuname.'/'.$folders{$outer}.
1.1087 raeburn 12757: '.'.$containers{$outer},1,1);
1.1067 raeburn 12758: unless ($errtext) {
12759: if (-e "$prefix$dir/$docstype/$mapinner{$outer}/$newidx/$title") {
12760: $result .= '<li>'.&mt('File: [_1] added to course',$docstitle).'</li>'."\n";
12761: }
12762: }
1.1055 raeburn 12763: }
12764: }
1.1086 raeburn 12765: }
12766: } else {
12767: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12768: }
12769: }
12770: for (my $i=1; $i<=$numitems; $i++) {
12771: next unless ($env{'form.archive_'.$i} eq 'dependency');
12772: my $path = $env{'form.archive_content_'.$i};
12773: if ($path =~ /^\Q$pathtocheck\E/) {
12774: my ($title) = ($path =~ m{/([^/]+)$});
12775: $referrer{$i} = $env{'form.archive_dependent_on_'.$i};
12776: if ($env{'form.archive_'.$referrer{$i}} eq 'display') {
12777: if (ref($dirorder{$i}) eq 'ARRAY') {
12778: my ($itemidx,$fullpath,$relpath);
12779: if (ref($dirorder{$referrer{$i}}) eq 'ARRAY') {
12780: my $container = $dirorder{$referrer{$i}}->[-1];
1.1056 raeburn 12781: for (my $j=0; $j<@{$dirorder{$i}}; $j++) {
1.1086 raeburn 12782: if ($dirorder{$i}->[$j] eq $container) {
12783: $itemidx = $j;
1.1056 raeburn 12784: }
12785: }
1.1086 raeburn 12786: }
12787: if ($itemidx eq '') {
12788: $itemidx = 0;
12789: }
12790: if (grep(/^\Q$referrer{$i}\E$/,@archdirs)) {
12791: if ($mapinner{$referrer{$i}}) {
12792: $fullpath = "$prefix$dir/$docstype/$mapinner{$referrer{$i}}";
12793: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12794: if (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12795: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12796: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12797: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12798: if (!-e $fullpath) {
12799: mkdir($fullpath,0755);
1.1056 raeburn 12800: }
12801: }
1.1086 raeburn 12802: } else {
12803: last;
1.1056 raeburn 12804: }
1.1086 raeburn 12805: }
12806: }
12807: } elsif ($newdest{$referrer{$i}}) {
12808: $fullpath = $newdest{$referrer{$i}};
12809: for (my $j=$itemidx; $j<@{$dirorder{$i}}; $j++) {
12810: if ($env{'form.archive_'.$dirorder{$i}->[$j]} eq 'discard') {
12811: $orphaned{$i} = $env{'form.archive_'.$dirorder{$i}->[$j]};
12812: last;
12813: } elsif (grep(/^\Q$dirorder{$i}->[$j]\E$/,@archdirs)) {
12814: unless (defined($newseqid{$dirorder{$i}->[$j]})) {
12815: $fullpath .= '/'.$titles{$dirorder{$i}->[$j]};
12816: $relpath .= '/'.$titles{$dirorder{$i}->[$j]};
12817: if (!-e $fullpath) {
12818: mkdir($fullpath,0755);
1.1056 raeburn 12819: }
12820: }
1.1086 raeburn 12821: } else {
12822: last;
1.1056 raeburn 12823: }
1.1055 raeburn 12824: }
12825: }
1.1086 raeburn 12826: if ($fullpath ne '') {
12827: if (-e "$prefix$path") {
12828: system("mv $prefix$path $fullpath/$title");
12829: }
12830: if (-e "$fullpath/$title") {
12831: my $showpath;
12832: if ($relpath ne '') {
12833: $showpath = "$relpath/$title";
12834: } else {
12835: $showpath = "/$title";
12836: }
12837: $result .= '<li>'.&mt('[_1] included as a dependency',$showpath).'</li>'."\n";
12838: }
12839: unless ($ishome) {
12840: my $fetch = "$fullpath/$title";
12841: $fetch =~ s/^\Q$prefix$dir\E//;
12842: $prompttofetch{$fetch} = 1;
12843: }
12844: }
1.1055 raeburn 12845: }
1.1086 raeburn 12846: } elsif ($env{'form.archive_'.$referrer{$i}} eq 'discard') {
12847: $warning .= &mt('[_1] is a dependency of [_2], which was discarded.',
12848: $path,$env{'form.archive_content_'.$referrer{$i}}).'<br />';
1.1055 raeburn 12849: }
12850: } else {
12851: $warning .= &mt('Item extracted from archive: [_1] has unexpected path.',$path).'<br />';
12852: }
12853: }
12854: if (keys(%todelete)) {
12855: foreach my $key (keys(%todelete)) {
12856: unlink($key);
1.1066 raeburn 12857: }
12858: }
12859: if (keys(%todeletedir)) {
12860: foreach my $key (keys(%todeletedir)) {
12861: rmdir($key);
12862: }
12863: }
12864: foreach my $dir (sort(keys(%is_dir))) {
12865: if (($pathtocheck ne '') && ($dir ne '')) {
12866: &cleanup_empty_dirs($prefix."$pathtocheck/$dir");
1.1055 raeburn 12867: }
12868: }
1.1067 raeburn 12869: if ($result ne '') {
12870: $output .= '<ul>'."\n".
12871: $result."\n".
12872: '</ul>';
12873: }
12874: unless ($ishome) {
12875: my $replicationfail;
12876: foreach my $item (keys(%prompttofetch)) {
12877: my $fetchresult= &Apache::lonnet::reply('fetchuserfile:'.$item,$docuhome);
12878: unless ($fetchresult eq 'ok') {
12879: $replicationfail .= '<li>'.$item.'</li>'."\n";
12880: }
12881: }
12882: if ($replicationfail) {
12883: $output .= '<p class="LC_error">'.
12884: &mt('Course home server failed to retrieve:').'<ul>'.
12885: $replicationfail.
12886: '</ul></p>';
12887: }
12888: }
1.1055 raeburn 12889: } else {
12890: $warning = &mt('No items found in archive.');
12891: }
12892: if ($error) {
12893: $output .= '<p class="LC_error">'.&mt('Not extracted.').'<br />'.
12894: $error.'</p>'."\n";
12895: }
12896: if ($warning) {
12897: $output .= '<p class="LC_warning">'.$warning.'</p>'."\n";
12898: }
12899: return $output;
12900: }
12901:
1.1066 raeburn 12902: sub cleanup_empty_dirs {
12903: my ($path) = @_;
12904: if (($path ne '') && (-d $path)) {
12905: if (opendir(my $dirh,$path)) {
12906: my @dircontents = grep(!/^\./,readdir($dirh));
12907: my $numitems = 0;
12908: foreach my $item (@dircontents) {
12909: if (-d "$path/$item") {
1.1111 raeburn 12910: &cleanup_empty_dirs("$path/$item");
1.1066 raeburn 12911: if (-e "$path/$item") {
12912: $numitems ++;
12913: }
12914: } else {
12915: $numitems ++;
12916: }
12917: }
12918: if ($numitems == 0) {
12919: rmdir($path);
12920: }
12921: closedir($dirh);
12922: }
12923: }
12924: return;
12925: }
12926:
1.41 ng 12927: =pod
1.45 matthew 12928:
1.1162 raeburn 12929: =item * &get_folder_hierarchy()
1.1068 raeburn 12930:
12931: Provides hierarchy of names of folders/sub-folders containing the current
12932: item,
12933:
12934: Inputs: 3
12935: - $navmap - navmaps object
12936:
12937: - $map - url for map (either the trigger itself, or map containing
12938: the resource, which is the trigger).
12939:
12940: - $showitem - 1 => show title for map itself; 0 => do not show.
12941:
12942: Outputs: 1 @pathitems - array of folder/subfolder names.
12943:
12944: =cut
12945:
12946: sub get_folder_hierarchy {
12947: my ($navmap,$map,$showitem) = @_;
12948: my @pathitems;
12949: if (ref($navmap)) {
12950: my $mapres = $navmap->getResourceByUrl($map);
12951: if (ref($mapres)) {
12952: my $pcslist = $mapres->map_hierarchy();
12953: if ($pcslist ne '') {
12954: my @pcs = split(/,/,$pcslist);
12955: foreach my $pc (@pcs) {
12956: if ($pc == 1) {
1.1129 raeburn 12957: push(@pathitems,&mt('Main Content'));
1.1068 raeburn 12958: } else {
12959: my $res = $navmap->getByMapPc($pc);
12960: if (ref($res)) {
12961: my $title = $res->compTitle();
12962: $title =~ s/\W+/_/g;
12963: if ($title ne '') {
12964: push(@pathitems,$title);
12965: }
12966: }
12967: }
12968: }
12969: }
1.1071 raeburn 12970: if ($showitem) {
12971: if ($mapres->{ID} eq '0.0') {
1.1129 raeburn 12972: push(@pathitems,&mt('Main Content'));
1.1071 raeburn 12973: } else {
12974: my $maptitle = $mapres->compTitle();
12975: $maptitle =~ s/\W+/_/g;
12976: if ($maptitle ne '') {
12977: push(@pathitems,$maptitle);
12978: }
1.1068 raeburn 12979: }
12980: }
12981: }
12982: }
12983: return @pathitems;
12984: }
12985:
12986: =pod
12987:
1.1015 raeburn 12988: =item * &get_turnedin_filepath()
12989:
12990: Determines path in a user's portfolio file for storage of files uploaded
12991: to a specific essayresponse or dropbox item.
12992:
12993: Inputs: 3 required + 1 optional.
12994: $symb is symb for resource, $uname and $udom are for current user (required).
12995: $caller is optional (can be "submission", if routine is called when storing
12996: an upoaded file when "Submit Answer" button was pressed).
12997:
12998: Returns array containing $path and $multiresp.
12999: $path is path in portfolio. $multiresp is 1 if this resource contains more
13000: than one file upload item. Callers of routine should append partid as a
13001: subdirectory to $path in cases where $multiresp is 1.
13002:
13003: Called by: homework/essayresponse.pm and homework/structuretags.pm
13004:
13005: =cut
13006:
13007: sub get_turnedin_filepath {
13008: my ($symb,$uname,$udom,$caller) = @_;
13009: my ($map,$resid,$resurl)=&Apache::lonnet::decode_symb($symb);
13010: my $turnindir;
13011: my %userhash = &Apache::lonnet::userenvironment($udom,$uname,'turnindir');
13012: $turnindir = $userhash{'turnindir'};
13013: my ($path,$multiresp);
13014: if ($turnindir eq '') {
13015: if ($caller eq 'submission') {
13016: $turnindir = &mt('turned in');
13017: $turnindir =~ s/\W+/_/g;
13018: my %newhash = (
13019: 'turnindir' => $turnindir,
13020: );
13021: &Apache::lonnet::put('environment',\%newhash,$udom,$uname);
13022: }
13023: }
13024: if ($turnindir ne '') {
13025: $path = '/'.$turnindir.'/';
13026: my ($multipart,$turnin,@pathitems);
13027: my $navmap = Apache::lonnavmaps::navmap->new();
13028: if (defined($navmap)) {
13029: my $mapres = $navmap->getResourceByUrl($map);
13030: if (ref($mapres)) {
13031: my $pcslist = $mapres->map_hierarchy();
13032: if ($pcslist ne '') {
13033: foreach my $pc (split(/,/,$pcslist)) {
13034: my $res = $navmap->getByMapPc($pc);
13035: if (ref($res)) {
13036: my $title = $res->compTitle();
13037: $title =~ s/\W+/_/g;
13038: if ($title ne '') {
1.1149 raeburn 13039: if (($pc > 1) && (length($title) > 12)) {
13040: $title = substr($title,0,12);
13041: }
1.1015 raeburn 13042: push(@pathitems,$title);
13043: }
13044: }
13045: }
13046: }
13047: my $maptitle = $mapres->compTitle();
13048: $maptitle =~ s/\W+/_/g;
13049: if ($maptitle ne '') {
1.1149 raeburn 13050: if (length($maptitle) > 12) {
13051: $maptitle = substr($maptitle,0,12);
13052: }
1.1015 raeburn 13053: push(@pathitems,$maptitle);
13054: }
13055: unless ($env{'request.state'} eq 'construct') {
13056: my $res = $navmap->getBySymb($symb);
13057: if (ref($res)) {
13058: my $partlist = $res->parts();
13059: my $totaluploads = 0;
13060: if (ref($partlist) eq 'ARRAY') {
13061: foreach my $part (@{$partlist}) {
13062: my @types = $res->responseType($part);
13063: my @ids = $res->responseIds($part);
13064: for (my $i=0; $i < scalar(@ids); $i++) {
13065: if ($types[$i] eq 'essay') {
13066: my $partid = $part.'_'.$ids[$i];
13067: if (&Apache::lonnet::EXT("resource.$partid.uploadedfiletypes") ne '') {
13068: $totaluploads ++;
13069: }
13070: }
13071: }
13072: }
13073: if ($totaluploads > 1) {
13074: $multiresp = 1;
13075: }
13076: }
13077: }
13078: }
13079: } else {
13080: return;
13081: }
13082: } else {
13083: return;
13084: }
13085: my $restitle=&Apache::lonnet::gettitle($symb);
13086: $restitle =~ s/\W+/_/g;
13087: if ($restitle eq '') {
13088: $restitle = ($resurl =~ m{/[^/]+$});
13089: if ($restitle eq '') {
13090: $restitle = time;
13091: }
13092: }
1.1149 raeburn 13093: if (length($restitle) > 12) {
13094: $restitle = substr($restitle,0,12);
13095: }
1.1015 raeburn 13096: push(@pathitems,$restitle);
13097: $path .= join('/',@pathitems);
13098: }
13099: return ($path,$multiresp);
13100: }
13101:
13102: =pod
13103:
1.464 albertel 13104: =back
1.41 ng 13105:
1.112 bowersj2 13106: =head1 CSV Upload/Handling functions
1.38 albertel 13107:
1.41 ng 13108: =over 4
13109:
1.648 raeburn 13110: =item * &upfile_store($r)
1.41 ng 13111:
13112: Store uploaded file, $r should be the HTTP Request object,
1.258 albertel 13113: needs $env{'form.upfile'}
1.41 ng 13114: returns $datatoken to be put into hidden field
13115:
13116: =cut
1.31 albertel 13117:
13118: sub upfile_store {
13119: my $r=shift;
1.258 albertel 13120: $env{'form.upfile'}=~s/\r/\n/gs;
13121: $env{'form.upfile'}=~s/\f/\n/gs;
13122: $env{'form.upfile'}=~s/\n+/\n/gs;
13123: $env{'form.upfile'}=~s/\n+$//gs;
1.31 albertel 13124:
1.258 albertel 13125: my $datatoken=$env{'user.name'}.'_'.$env{'user.domain'}.
13126: '_enroll_'.$env{'request.course.id'}.'_'.time.'_'.$$;
1.31 albertel 13127: {
1.158 raeburn 13128: my $datafile = $r->dir_config('lonDaemons').
13129: '/tmp/'.$datatoken.'.tmp';
13130: if ( open(my $fh,">$datafile") ) {
1.258 albertel 13131: print $fh $env{'form.upfile'};
1.158 raeburn 13132: close($fh);
13133: }
1.31 albertel 13134: }
13135: return $datatoken;
13136: }
13137:
1.56 matthew 13138: =pod
13139:
1.648 raeburn 13140: =item * &load_tmp_file($r)
1.41 ng 13141:
13142: Load uploaded file from tmp, $r should be the HTTP Request object,
1.258 albertel 13143: needs $env{'form.datatoken'},
13144: sets $env{'form.upfile'} to the contents of the file
1.41 ng 13145:
13146: =cut
1.31 albertel 13147:
13148: sub load_tmp_file {
13149: my $r=shift;
13150: my @studentdata=();
13151: {
1.158 raeburn 13152: my $studentfile = $r->dir_config('lonDaemons').
1.258 albertel 13153: '/tmp/'.$env{'form.datatoken'}.'.tmp';
1.158 raeburn 13154: if ( open(my $fh,"<$studentfile") ) {
13155: @studentdata=<$fh>;
13156: close($fh);
13157: }
1.31 albertel 13158: }
1.258 albertel 13159: $env{'form.upfile'}=join('',@studentdata);
1.31 albertel 13160: }
13161:
1.56 matthew 13162: =pod
13163:
1.648 raeburn 13164: =item * &upfile_record_sep()
1.41 ng 13165:
13166: Separate uploaded file into records
13167: returns array of records,
1.258 albertel 13168: needs $env{'form.upfile'} and $env{'form.upfiletype'}
1.41 ng 13169:
13170: =cut
1.31 albertel 13171:
13172: sub upfile_record_sep {
1.258 albertel 13173: if ($env{'form.upfiletype'} eq 'xml') {
1.31 albertel 13174: } else {
1.248 albertel 13175: my @records;
1.258 albertel 13176: foreach my $line (split(/\n/,$env{'form.upfile'})) {
1.248 albertel 13177: if ($line=~/^\s*$/) { next; }
13178: push(@records,$line);
13179: }
13180: return @records;
1.31 albertel 13181: }
13182: }
13183:
1.56 matthew 13184: =pod
13185:
1.648 raeburn 13186: =item * &record_sep($record)
1.41 ng 13187:
1.258 albertel 13188: Separate a record into fields $record should be an item from the upfile_record_sep(), needs $env{'form.upfiletype'}
1.41 ng 13189:
13190: =cut
13191:
1.263 www 13192: sub takeleft {
13193: my $index=shift;
13194: return substr('0000'.$index,-4,4);
13195: }
13196:
1.31 albertel 13197: sub record_sep {
13198: my $record=shift;
13199: my %components=();
1.258 albertel 13200: if ($env{'form.upfiletype'} eq 'xml') {
13201: } elsif ($env{'form.upfiletype'} eq 'space') {
1.31 albertel 13202: my $i=0;
1.356 albertel 13203: foreach my $field (split(/\s+/,$record)) {
1.31 albertel 13204: $field=~s/^(\"|\')//;
13205: $field=~s/(\"|\')$//;
1.263 www 13206: $components{&takeleft($i)}=$field;
1.31 albertel 13207: $i++;
13208: }
1.258 albertel 13209: } elsif ($env{'form.upfiletype'} eq 'tab') {
1.31 albertel 13210: my $i=0;
1.356 albertel 13211: foreach my $field (split(/\t/,$record)) {
1.31 albertel 13212: $field=~s/^(\"|\')//;
13213: $field=~s/(\"|\')$//;
1.263 www 13214: $components{&takeleft($i)}=$field;
1.31 albertel 13215: $i++;
13216: }
13217: } else {
1.561 www 13218: my $separator=',';
1.480 banghart 13219: if ($env{'form.upfiletype'} eq 'semisv') {
1.561 www 13220: $separator=';';
1.480 banghart 13221: }
1.31 albertel 13222: my $i=0;
1.561 www 13223: # the character we are looking for to indicate the end of a quote or a record
13224: my $looking_for=$separator;
13225: # do not add the characters to the fields
13226: my $ignore=0;
13227: # we just encountered a separator (or the beginning of the record)
13228: my $just_found_separator=1;
13229: # store the field we are working on here
13230: my $field='';
13231: # work our way through all characters in record
13232: foreach my $character ($record=~/(.)/g) {
13233: if ($character eq $looking_for) {
13234: if ($character ne $separator) {
13235: # Found the end of a quote, again looking for separator
13236: $looking_for=$separator;
13237: $ignore=1;
13238: } else {
13239: # Found a separator, store away what we got
13240: $components{&takeleft($i)}=$field;
13241: $i++;
13242: $just_found_separator=1;
13243: $ignore=0;
13244: $field='';
13245: }
13246: next;
13247: }
13248: # single or double quotation marks after a separator indicate beginning of a quote
13249: # we are now looking for the end of the quote and need to ignore separators
13250: if ((($character eq '"') || ($character eq "'")) && ($just_found_separator)) {
13251: $looking_for=$character;
13252: next;
13253: }
13254: # ignore would be true after we reached the end of a quote
13255: if ($ignore) { next; }
13256: if (($just_found_separator) && ($character=~/\s/)) { next; }
13257: $field.=$character;
13258: $just_found_separator=0;
1.31 albertel 13259: }
1.561 www 13260: # catch the very last entry, since we never encountered the separator
13261: $components{&takeleft($i)}=$field;
1.31 albertel 13262: }
13263: return %components;
13264: }
13265:
1.144 matthew 13266: ######################################################
13267: ######################################################
13268:
1.56 matthew 13269: =pod
13270:
1.648 raeburn 13271: =item * &upfile_select_html()
1.41 ng 13272:
1.144 matthew 13273: Return HTML code to select a file from the users machine and specify
13274: the file type.
1.41 ng 13275:
13276: =cut
13277:
1.144 matthew 13278: ######################################################
13279: ######################################################
1.31 albertel 13280: sub upfile_select_html {
1.144 matthew 13281: my %Types = (
13282: csv => &mt('CSV (comma separated values, spreadsheet)'),
1.480 banghart 13283: semisv => &mt('Semicolon separated values'),
1.144 matthew 13284: space => &mt('Space separated'),
13285: tab => &mt('Tabulator separated'),
13286: # xml => &mt('HTML/XML'),
13287: );
13288: my $Str = '<input type="file" name="upfile" size="50" />'.
1.727 riegler 13289: '<br />'.&mt('Type').': <select name="upfiletype">';
1.144 matthew 13290: foreach my $type (sort(keys(%Types))) {
13291: $Str .= '<option value="'.$type.'" >'.$Types{$type}."</option>\n";
13292: }
13293: $Str .= "</select>\n";
13294: return $Str;
1.31 albertel 13295: }
13296:
1.301 albertel 13297: sub get_samples {
13298: my ($records,$toget) = @_;
13299: my @samples=({});
13300: my $got=0;
13301: foreach my $rec (@$records) {
13302: my %temp = &record_sep($rec);
13303: if (! grep(/\S/, values(%temp))) { next; }
13304: if (%temp) {
13305: $samples[$got]=\%temp;
13306: $got++;
13307: if ($got == $toget) { last; }
13308: }
13309: }
13310: return \@samples;
13311: }
13312:
1.144 matthew 13313: ######################################################
13314: ######################################################
13315:
1.56 matthew 13316: =pod
13317:
1.648 raeburn 13318: =item * &csv_print_samples($r,$records)
1.41 ng 13319:
13320: Prints a table of sample values from each column uploaded $r is an
13321: Apache Request ref, $records is an arrayref from
13322: &Apache::loncommon::upfile_record_sep
13323:
13324: =cut
13325:
1.144 matthew 13326: ######################################################
13327: ######################################################
1.31 albertel 13328: sub csv_print_samples {
13329: my ($r,$records) = @_;
1.662 bisitz 13330: my $samples = &get_samples($records,5);
1.301 albertel 13331:
1.594 raeburn 13332: $r->print(&mt('Samples').'<br />'.&start_data_table().
13333: &start_data_table_header_row());
1.356 albertel 13334: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.845 bisitz 13335: $r->print('<th>'.&mt('Column [_1]',($sample+1)).'</th>'); }
1.594 raeburn 13336: $r->print(&end_data_table_header_row());
1.301 albertel 13337: foreach my $hash (@$samples) {
1.594 raeburn 13338: $r->print(&start_data_table_row());
1.356 albertel 13339: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
1.31 albertel 13340: $r->print('<td>');
1.356 albertel 13341: if (defined($$hash{$sample})) { $r->print($$hash{$sample}); }
1.31 albertel 13342: $r->print('</td>');
13343: }
1.594 raeburn 13344: $r->print(&end_data_table_row());
1.31 albertel 13345: }
1.594 raeburn 13346: $r->print(&end_data_table().'<br />'."\n");
1.31 albertel 13347: }
13348:
1.144 matthew 13349: ######################################################
13350: ######################################################
13351:
1.56 matthew 13352: =pod
13353:
1.648 raeburn 13354: =item * &csv_print_select_table($r,$records,$d)
1.41 ng 13355:
13356: Prints a table to create associations between values and table columns.
1.144 matthew 13357:
1.41 ng 13358: $r is an Apache Request ref,
13359: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
1.174 matthew 13360: $d is an array of 2 element arrays (internal name, displayed name,defaultcol)
1.41 ng 13361:
13362: =cut
13363:
1.144 matthew 13364: ######################################################
13365: ######################################################
1.31 albertel 13366: sub csv_print_select_table {
13367: my ($r,$records,$d) = @_;
1.301 albertel 13368: my $i=0;
13369: my $samples = &get_samples($records,1);
1.144 matthew 13370: $r->print(&mt('Associate columns with student attributes.')."\n".
1.594 raeburn 13371: &start_data_table().&start_data_table_header_row().
1.144 matthew 13372: '<th>'.&mt('Attribute').'</th>'.
1.594 raeburn 13373: '<th>'.&mt('Column').'</th>'.
13374: &end_data_table_header_row()."\n");
1.356 albertel 13375: foreach my $array_ref (@$d) {
13376: my ($value,$display,$defaultcol)=@{ $array_ref };
1.729 raeburn 13377: $r->print(&start_data_table_row().'<td>'.$display.'</td>');
1.31 albertel 13378:
1.875 bisitz 13379: $r->print('<td><select name="f'.$i.'"'.
1.32 matthew 13380: ' onchange="javascript:flip(this.form,'.$i.');">');
1.31 albertel 13381: $r->print('<option value="none"></option>');
1.356 albertel 13382: foreach my $sample (sort({$a <=> $b} keys(%{ $samples->[0] }))) {
13383: $r->print('<option value="'.$sample.'"'.
13384: ($sample eq $defaultcol ? ' selected="selected" ' : '').
1.662 bisitz 13385: '>'.&mt('Column [_1]',($sample+1)).'</option>');
1.31 albertel 13386: }
1.594 raeburn 13387: $r->print('</select></td>'.&end_data_table_row()."\n");
1.31 albertel 13388: $i++;
13389: }
1.594 raeburn 13390: $r->print(&end_data_table());
1.31 albertel 13391: $i--;
13392: return $i;
13393: }
1.56 matthew 13394:
1.144 matthew 13395: ######################################################
13396: ######################################################
13397:
1.56 matthew 13398: =pod
1.31 albertel 13399:
1.648 raeburn 13400: =item * &csv_samples_select_table($r,$records,$d)
1.41 ng 13401:
13402: Prints a table of sample values from the upload and can make associate samples to internal names.
13403:
13404: $r is an Apache Request ref,
13405: $records is an arrayref from &Apache::loncommon::upfile_record_sep,
13406: $d is an array of 2 element arrays (internal name, displayed name)
13407:
13408: =cut
13409:
1.144 matthew 13410: ######################################################
13411: ######################################################
1.31 albertel 13412: sub csv_samples_select_table {
13413: my ($r,$records,$d) = @_;
13414: my $i=0;
1.144 matthew 13415: #
1.662 bisitz 13416: my $max_samples = 5;
13417: my $samples = &get_samples($records,$max_samples);
1.594 raeburn 13418: $r->print(&start_data_table().
13419: &start_data_table_header_row().'<th>'.
13420: &mt('Field').'</th><th>'.&mt('Samples').'</th>'.
13421: &end_data_table_header_row());
1.301 albertel 13422:
13423: foreach my $key (sort(keys(%{ $samples->[0] }))) {
1.594 raeburn 13424: $r->print(&start_data_table_row().'<td><select name="f'.$i.'"'.
1.32 matthew 13425: ' onchange="javascript:flip(this.form,'.$i.');">');
1.301 albertel 13426: foreach my $option (@$d) {
13427: my ($value,$display,$defaultcol)=@{ $option };
1.174 matthew 13428: $r->print('<option value="'.$value.'"'.
1.253 albertel 13429: ($i eq $defaultcol ? ' selected="selected" ':'').'>'.
1.174 matthew 13430: $display.'</option>');
1.31 albertel 13431: }
13432: $r->print('</select></td><td>');
1.662 bisitz 13433: foreach my $line (0..($max_samples-1)) {
1.301 albertel 13434: if (defined($samples->[$line]{$key})) {
13435: $r->print($samples->[$line]{$key}."<br />\n");
13436: }
13437: }
1.594 raeburn 13438: $r->print('</td>'.&end_data_table_row());
1.31 albertel 13439: $i++;
13440: }
1.594 raeburn 13441: $r->print(&end_data_table());
1.31 albertel 13442: $i--;
13443: return($i);
1.115 matthew 13444: }
13445:
1.144 matthew 13446: ######################################################
13447: ######################################################
13448:
1.115 matthew 13449: =pod
13450:
1.648 raeburn 13451: =item * &clean_excel_name($name)
1.115 matthew 13452:
13453: Returns a replacement for $name which does not contain any illegal characters.
13454:
13455: =cut
13456:
1.144 matthew 13457: ######################################################
13458: ######################################################
1.115 matthew 13459: sub clean_excel_name {
13460: my ($name) = @_;
13461: $name =~ s/[:\*\?\/\\]//g;
13462: if (length($name) > 31) {
13463: $name = substr($name,0,31);
13464: }
13465: return $name;
1.25 albertel 13466: }
1.84 albertel 13467:
1.85 albertel 13468: =pod
13469:
1.648 raeburn 13470: =item * &check_if_partid_hidden($id,$symb,$udom,$uname)
1.85 albertel 13471:
13472: Returns either 1 or undef
13473:
13474: 1 if the part is to be hidden, undef if it is to be shown
13475:
13476: Arguments are:
13477:
13478: $id the id of the part to be checked
13479: $symb, optional the symb of the resource to check
13480: $udom, optional the domain of the user to check for
13481: $uname, optional the username of the user to check for
13482:
13483: =cut
1.84 albertel 13484:
13485: sub check_if_partid_hidden {
13486: my ($id,$symb,$udom,$uname) = @_;
1.133 albertel 13487: my $hiddenparts=&Apache::lonnet::EXT('resource.0.hiddenparts',
1.84 albertel 13488: $symb,$udom,$uname);
1.141 albertel 13489: my $truth=1;
13490: #if the string starts with !, then the list is the list to show not hide
13491: if ($hiddenparts=~s/^\s*!//) { $truth=undef; }
1.84 albertel 13492: my @hiddenlist=split(/,/,$hiddenparts);
13493: foreach my $checkid (@hiddenlist) {
1.141 albertel 13494: if ($checkid =~ /^\s*\Q$id\E\s*$/) { return $truth; }
1.84 albertel 13495: }
1.141 albertel 13496: return !$truth;
1.84 albertel 13497: }
1.127 matthew 13498:
1.138 matthew 13499:
13500: ############################################################
13501: ############################################################
13502:
13503: =pod
13504:
1.157 matthew 13505: =back
13506:
1.138 matthew 13507: =head1 cgi-bin script and graphing routines
13508:
1.157 matthew 13509: =over 4
13510:
1.648 raeburn 13511: =item * &get_cgi_id()
1.138 matthew 13512:
13513: Inputs: none
13514:
13515: Returns an id which can be used to pass environment variables
13516: to various cgi-bin scripts. These environment variables will
13517: be removed from the users environment after a given time by
13518: the routine &Apache::lonnet::transfer_profile_to_env.
13519:
13520: =cut
13521:
13522: ############################################################
13523: ############################################################
1.152 albertel 13524: my $uniq=0;
1.136 matthew 13525: sub get_cgi_id {
1.154 albertel 13526: $uniq=($uniq+1)%100000;
1.280 albertel 13527: return (time.'_'.$$.'_'.$uniq);
1.136 matthew 13528: }
13529:
1.127 matthew 13530: ############################################################
13531: ############################################################
13532:
13533: =pod
13534:
1.648 raeburn 13535: =item * &DrawBarGraph()
1.127 matthew 13536:
1.138 matthew 13537: Facilitates the plotting of data in a (stacked) bar graph.
13538: Puts plot definition data into the users environment in order for
13539: graph.png to plot it. Returns an <img> tag for the plot.
13540: The bars on the plot are labeled '1','2',...,'n'.
13541:
13542: Inputs:
13543:
13544: =over 4
13545:
13546: =item $Title: string, the title of the plot
13547:
13548: =item $xlabel: string, text describing the X-axis of the plot
13549:
13550: =item $ylabel: string, text describing the Y-axis of the plot
13551:
13552: =item $Max: scalar, the maximum Y value to use in the plot
13553: If $Max is < any data point, the graph will not be rendered.
13554:
1.140 matthew 13555: =item $colors: array ref holding the colors to be used for the data sets when
1.138 matthew 13556: they are plotted. If undefined, default values will be used.
13557:
1.178 matthew 13558: =item $labels: array ref holding the labels to use on the x-axis for the bars.
13559:
1.138 matthew 13560: =item @Values: An array of array references. Each array reference holds data
13561: to be plotted in a stacked bar chart.
13562:
1.239 matthew 13563: =item If the final element of @Values is a hash reference the key/value
13564: pairs will be added to the graph definition.
13565:
1.138 matthew 13566: =back
13567:
13568: Returns:
13569:
13570: An <img> tag which references graph.png and the appropriate identifying
13571: information for the plot.
13572:
1.127 matthew 13573: =cut
13574:
13575: ############################################################
13576: ############################################################
1.134 matthew 13577: sub DrawBarGraph {
1.178 matthew 13578: my ($Title,$xlabel,$ylabel,$Max,$colors,$labels,@Values)=@_;
1.134 matthew 13579: #
13580: if (! defined($colors)) {
13581: $colors = ['#33ff00',
13582: '#0033cc', '#990000', '#aaaa66', '#663399', '#ff9933',
13583: '#66ccff', '#ff9999', '#cccc33', '#660000', '#33cc66',
13584: ];
13585: }
1.228 matthew 13586: my $extra_settings = {};
13587: if (ref($Values[-1]) eq 'HASH') {
13588: $extra_settings = pop(@Values);
13589: }
1.127 matthew 13590: #
1.136 matthew 13591: my $identifier = &get_cgi_id();
13592: my $id = 'cgi.'.$identifier;
1.129 matthew 13593: if (! @Values || ref($Values[0]) ne 'ARRAY') {
1.127 matthew 13594: return '';
13595: }
1.225 matthew 13596: #
13597: my @Labels;
13598: if (defined($labels)) {
13599: @Labels = @$labels;
13600: } else {
13601: for (my $i=0;$i<@{$Values[0]};$i++) {
13602: push (@Labels,$i+1);
13603: }
13604: }
13605: #
1.129 matthew 13606: my $NumBars = scalar(@{$Values[0]});
1.225 matthew 13607: if ($NumBars < scalar(@Labels)) { $NumBars = scalar(@Labels); }
1.129 matthew 13608: my %ValuesHash;
13609: my $NumSets=1;
13610: foreach my $array (@Values) {
13611: next if (! ref($array));
1.136 matthew 13612: $ValuesHash{$id.'.data.'.$NumSets++} =
1.132 matthew 13613: join(',',@$array);
1.129 matthew 13614: }
1.127 matthew 13615: #
1.136 matthew 13616: my ($height,$width,$xskip,$bar_width) = (200,120,1,15);
1.225 matthew 13617: if ($NumBars < 3) {
13618: $width = 120+$NumBars*32;
1.220 matthew 13619: $xskip = 1;
1.225 matthew 13620: $bar_width = 30;
13621: } elsif ($NumBars < 5) {
13622: $width = 120+$NumBars*20;
13623: $xskip = 1;
13624: $bar_width = 20;
1.220 matthew 13625: } elsif ($NumBars < 10) {
1.136 matthew 13626: $width = 120+$NumBars*15;
13627: $xskip = 1;
13628: $bar_width = 15;
13629: } elsif ($NumBars <= 25) {
13630: $width = 120+$NumBars*11;
13631: $xskip = 5;
13632: $bar_width = 8;
13633: } elsif ($NumBars <= 50) {
13634: $width = 120+$NumBars*8;
13635: $xskip = 5;
13636: $bar_width = 4;
13637: } else {
13638: $width = 120+$NumBars*8;
13639: $xskip = 5;
13640: $bar_width = 4;
13641: }
13642: #
1.137 matthew 13643: $Max = 1 if ($Max < 1);
13644: if ( int($Max) < $Max ) {
13645: $Max++;
13646: $Max = int($Max);
13647: }
1.127 matthew 13648: $Title = '' if (! defined($Title));
13649: $xlabel = '' if (! defined($xlabel));
13650: $ylabel = '' if (! defined($ylabel));
1.369 www 13651: $ValuesHash{$id.'.title'} = &escape($Title);
13652: $ValuesHash{$id.'.xlabel'} = &escape($xlabel);
13653: $ValuesHash{$id.'.ylabel'} = &escape($ylabel);
1.137 matthew 13654: $ValuesHash{$id.'.y_max_value'} = $Max;
1.136 matthew 13655: $ValuesHash{$id.'.NumBars'} = $NumBars;
13656: $ValuesHash{$id.'.NumSets'} = $NumSets;
13657: $ValuesHash{$id.'.PlotType'} = 'bar';
13658: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13659: $ValuesHash{$id.'.height'} = $height;
13660: $ValuesHash{$id.'.width'} = $width;
13661: $ValuesHash{$id.'.xskip'} = $xskip;
13662: $ValuesHash{$id.'.bar_width'} = $bar_width;
13663: $ValuesHash{$id.'.labels'} = join(',',@Labels);
1.127 matthew 13664: #
1.228 matthew 13665: # Deal with other parameters
13666: while (my ($key,$value) = each(%$extra_settings)) {
13667: $ValuesHash{$id.'.'.$key} = $value;
13668: }
13669: #
1.646 raeburn 13670: &Apache::lonnet::appenv(\%ValuesHash);
1.137 matthew 13671: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13672: }
13673:
13674: ############################################################
13675: ############################################################
13676:
13677: =pod
13678:
1.648 raeburn 13679: =item * &DrawXYGraph()
1.137 matthew 13680:
1.138 matthew 13681: Facilitates the plotting of data in an XY graph.
13682: Puts plot definition data into the users environment in order for
13683: graph.png to plot it. Returns an <img> tag for the plot.
13684:
13685: Inputs:
13686:
13687: =over 4
13688:
13689: =item $Title: string, the title of the plot
13690:
13691: =item $xlabel: string, text describing the X-axis of the plot
13692:
13693: =item $ylabel: string, text describing the Y-axis of the plot
13694:
13695: =item $Max: scalar, the maximum Y value to use in the plot
13696: If $Max is < any data point, the graph will not be rendered.
13697:
13698: =item $colors: Array ref containing the hex color codes for the data to be
13699: plotted in. If undefined, default values will be used.
13700:
13701: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13702:
13703: =item $Ydata: Array ref containing Array refs.
1.185 www 13704: Each of the contained arrays will be plotted as a separate curve.
1.138 matthew 13705:
13706: =item %Values: hash indicating or overriding any default values which are
13707: passed to graph.png.
13708: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13709:
13710: =back
13711:
13712: Returns:
13713:
13714: An <img> tag which references graph.png and the appropriate identifying
13715: information for the plot.
13716:
1.137 matthew 13717: =cut
13718:
13719: ############################################################
13720: ############################################################
13721: sub DrawXYGraph {
13722: my ($Title,$xlabel,$ylabel,$Max,$colors,$Xlabels,$Ydata,%Values)=@_;
13723: #
13724: # Create the identifier for the graph
13725: my $identifier = &get_cgi_id();
13726: my $id = 'cgi.'.$identifier;
13727: #
13728: $Title = '' if (! defined($Title));
13729: $xlabel = '' if (! defined($xlabel));
13730: $ylabel = '' if (! defined($ylabel));
13731: my %ValuesHash =
13732: (
1.369 www 13733: $id.'.title' => &escape($Title),
13734: $id.'.xlabel' => &escape($xlabel),
13735: $id.'.ylabel' => &escape($ylabel),
1.137 matthew 13736: $id.'.y_max_value'=> $Max,
13737: $id.'.labels' => join(',',@$Xlabels),
13738: $id.'.PlotType' => 'XY',
13739: );
13740: #
13741: if (defined($colors) && ref($colors) eq 'ARRAY') {
13742: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13743: }
13744: #
13745: if (! ref($Ydata) || ref($Ydata) ne 'ARRAY') {
13746: return '';
13747: }
13748: my $NumSets=1;
1.138 matthew 13749: foreach my $array (@{$Ydata}){
1.137 matthew 13750: next if (! ref($array));
13751: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
13752: }
1.138 matthew 13753: $ValuesHash{$id.'.NumSets'} = $NumSets-1;
1.137 matthew 13754: #
13755: # Deal with other parameters
13756: while (my ($key,$value) = each(%Values)) {
13757: $ValuesHash{$id.'.'.$key} = $value;
1.127 matthew 13758: }
13759: #
1.646 raeburn 13760: &Apache::lonnet::appenv(\%ValuesHash);
1.136 matthew 13761: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
13762: }
13763:
13764: ############################################################
13765: ############################################################
13766:
13767: =pod
13768:
1.648 raeburn 13769: =item * &DrawXYYGraph()
1.138 matthew 13770:
13771: Facilitates the plotting of data in an XY graph with two Y axes.
13772: Puts plot definition data into the users environment in order for
13773: graph.png to plot it. Returns an <img> tag for the plot.
13774:
13775: Inputs:
13776:
13777: =over 4
13778:
13779: =item $Title: string, the title of the plot
13780:
13781: =item $xlabel: string, text describing the X-axis of the plot
13782:
13783: =item $ylabel: string, text describing the Y-axis of the plot
13784:
13785: =item $colors: Array ref containing the hex color codes for the data to be
13786: plotted in. If undefined, default values will be used.
13787:
13788: =item $Xlabels: Array ref containing the labels to be used for the X-axis.
13789:
13790: =item $Ydata1: The first data set
13791:
13792: =item $Min1: The minimum value of the left Y-axis
13793:
13794: =item $Max1: The maximum value of the left Y-axis
13795:
13796: =item $Ydata2: The second data set
13797:
13798: =item $Min2: The minimum value of the right Y-axis
13799:
13800: =item $Max2: The maximum value of the left Y-axis
13801:
13802: =item %Values: hash indicating or overriding any default values which are
13803: passed to graph.png.
13804: Possible values are: width, xskip, x_ticks, x_tick_offset, among others.
13805:
13806: =back
13807:
13808: Returns:
13809:
13810: An <img> tag which references graph.png and the appropriate identifying
13811: information for the plot.
1.136 matthew 13812:
13813: =cut
13814:
13815: ############################################################
13816: ############################################################
1.137 matthew 13817: sub DrawXYYGraph {
13818: my ($Title,$xlabel,$ylabel,$colors,$Xlabels,$Ydata1,$Min1,$Max1,
13819: $Ydata2,$Min2,$Max2,%Values)=@_;
1.136 matthew 13820: #
13821: # Create the identifier for the graph
13822: my $identifier = &get_cgi_id();
13823: my $id = 'cgi.'.$identifier;
13824: #
13825: $Title = '' if (! defined($Title));
13826: $xlabel = '' if (! defined($xlabel));
13827: $ylabel = '' if (! defined($ylabel));
13828: my %ValuesHash =
13829: (
1.369 www 13830: $id.'.title' => &escape($Title),
13831: $id.'.xlabel' => &escape($xlabel),
13832: $id.'.ylabel' => &escape($ylabel),
1.136 matthew 13833: $id.'.labels' => join(',',@$Xlabels),
13834: $id.'.PlotType' => 'XY',
13835: $id.'.NumSets' => 2,
1.137 matthew 13836: $id.'.two_axes' => 1,
13837: $id.'.y1_max_value' => $Max1,
13838: $id.'.y1_min_value' => $Min1,
13839: $id.'.y2_max_value' => $Max2,
13840: $id.'.y2_min_value' => $Min2,
1.136 matthew 13841: );
13842: #
1.137 matthew 13843: if (defined($colors) && ref($colors) eq 'ARRAY') {
13844: $ValuesHash{$id.'.Colors'} = join(',',@{$colors});
13845: }
13846: #
13847: if (! ref($Ydata1) || ref($Ydata1) ne 'ARRAY' ||
13848: ! ref($Ydata2) || ref($Ydata2) ne 'ARRAY'){
1.136 matthew 13849: return '';
13850: }
13851: my $NumSets=1;
1.137 matthew 13852: foreach my $array ($Ydata1,$Ydata2){
1.136 matthew 13853: next if (! ref($array));
13854: $ValuesHash{$id.'.data.'.$NumSets++} = join(',',@$array);
1.137 matthew 13855: }
13856: #
13857: # Deal with other parameters
13858: while (my ($key,$value) = each(%Values)) {
13859: $ValuesHash{$id.'.'.$key} = $value;
1.136 matthew 13860: }
13861: #
1.646 raeburn 13862: &Apache::lonnet::appenv(\%ValuesHash);
1.130 albertel 13863: return '<img src="/cgi-bin/graph.png?'.$identifier.'" border="1" />';
1.139 matthew 13864: }
13865:
13866: ############################################################
13867: ############################################################
13868:
13869: =pod
13870:
1.157 matthew 13871: =back
13872:
1.139 matthew 13873: =head1 Statistics helper routines?
13874:
13875: Bad place for them but what the hell.
13876:
1.157 matthew 13877: =over 4
13878:
1.648 raeburn 13879: =item * &chartlink()
1.139 matthew 13880:
13881: Returns a link to the chart for a specific student.
13882:
13883: Inputs:
13884:
13885: =over 4
13886:
13887: =item $linktext: The text of the link
13888:
13889: =item $sname: The students username
13890:
13891: =item $sdomain: The students domain
13892:
13893: =back
13894:
1.157 matthew 13895: =back
13896:
1.139 matthew 13897: =cut
13898:
13899: ############################################################
13900: ############################################################
13901: sub chartlink {
13902: my ($linktext, $sname, $sdomain) = @_;
13903: my $link = '<a href="/adm/statistics?reportSelected=student_assessment'.
1.369 www 13904: '&SelectedStudent='.&escape($sname.':'.$sdomain).
1.219 albertel 13905: '&chartoutputmode='.HTML::Entities::encode('html, with all links').
1.139 matthew 13906: '">'.$linktext.'</a>';
1.153 matthew 13907: }
13908:
13909: #######################################################
13910: #######################################################
13911:
13912: =pod
13913:
13914: =head1 Course Environment Routines
1.157 matthew 13915:
13916: =over 4
1.153 matthew 13917:
1.648 raeburn 13918: =item * &restore_course_settings()
1.153 matthew 13919:
1.648 raeburn 13920: =item * &store_course_settings()
1.153 matthew 13921:
13922: Restores/Store indicated form parameters from the course environment.
13923: Will not overwrite existing values of the form parameters.
13924:
13925: Inputs:
13926: a scalar describing the data (e.g. 'chart', 'problem_analysis')
13927:
13928: a hash ref describing the data to be stored. For example:
13929:
13930: %Save_Parameters = ('Status' => 'scalar',
13931: 'chartoutputmode' => 'scalar',
13932: 'chartoutputdata' => 'scalar',
13933: 'Section' => 'array',
1.373 raeburn 13934: 'Group' => 'array',
1.153 matthew 13935: 'StudentData' => 'array',
13936: 'Maps' => 'array');
13937:
13938: Returns: both routines return nothing
13939:
1.631 raeburn 13940: =back
13941:
1.153 matthew 13942: =cut
13943:
13944: #######################################################
13945: #######################################################
13946: sub store_course_settings {
1.496 albertel 13947: return &store_settings($env{'request.course.id'},@_);
13948: }
13949:
13950: sub store_settings {
1.153 matthew 13951: # save to the environment
13952: # appenv the same items, just to be safe
1.300 albertel 13953: my $udom = $env{'user.domain'};
13954: my $uname = $env{'user.name'};
1.496 albertel 13955: my ($context,$prefix,$Settings) = @_;
1.153 matthew 13956: my %SaveHash;
13957: my %AppHash;
13958: while (my ($setting,$type) = each(%$Settings)) {
1.496 albertel 13959: my $basename = join('.','internal',$context,$prefix,$setting);
1.300 albertel 13960: my $envname = 'environment.'.$basename;
1.258 albertel 13961: if (exists($env{'form.'.$setting})) {
1.153 matthew 13962: # Save this value away
13963: if ($type eq 'scalar' &&
1.258 albertel 13964: (! exists($env{$envname}) ||
13965: $env{$envname} ne $env{'form.'.$setting})) {
13966: $SaveHash{$basename} = $env{'form.'.$setting};
13967: $AppHash{$envname} = $env{'form.'.$setting};
1.153 matthew 13968: } elsif ($type eq 'array') {
13969: my $stored_form;
1.258 albertel 13970: if (ref($env{'form.'.$setting})) {
1.153 matthew 13971: $stored_form = join(',',
13972: map {
1.369 www 13973: &escape($_);
1.258 albertel 13974: } sort(@{$env{'form.'.$setting}}));
1.153 matthew 13975: } else {
13976: $stored_form =
1.369 www 13977: &escape($env{'form.'.$setting});
1.153 matthew 13978: }
13979: # Determine if the array contents are the same.
1.258 albertel 13980: if ($stored_form ne $env{$envname}) {
1.153 matthew 13981: $SaveHash{$basename} = $stored_form;
13982: $AppHash{$envname} = $stored_form;
13983: }
13984: }
13985: }
13986: }
13987: my $put_result = &Apache::lonnet::put('environment',\%SaveHash,
1.300 albertel 13988: $udom,$uname);
1.153 matthew 13989: if ($put_result !~ /^(ok|delayed)/) {
13990: &Apache::lonnet::logthis('unable to save form parameters, '.
13991: 'got error:'.$put_result);
13992: }
13993: # Make sure these settings stick around in this session, too
1.646 raeburn 13994: &Apache::lonnet::appenv(\%AppHash);
1.153 matthew 13995: return;
13996: }
13997:
13998: sub restore_course_settings {
1.499 albertel 13999: return &restore_settings($env{'request.course.id'},@_);
1.496 albertel 14000: }
14001:
14002: sub restore_settings {
14003: my ($context,$prefix,$Settings) = @_;
1.153 matthew 14004: while (my ($setting,$type) = each(%$Settings)) {
1.258 albertel 14005: next if (exists($env{'form.'.$setting}));
1.496 albertel 14006: my $envname = 'environment.internal.'.$context.'.'.$prefix.
1.153 matthew 14007: '.'.$setting;
1.258 albertel 14008: if (exists($env{$envname})) {
1.153 matthew 14009: if ($type eq 'scalar') {
1.258 albertel 14010: $env{'form.'.$setting} = $env{$envname};
1.153 matthew 14011: } elsif ($type eq 'array') {
1.258 albertel 14012: $env{'form.'.$setting} = [
1.153 matthew 14013: map {
1.369 www 14014: &unescape($_);
1.258 albertel 14015: } split(',',$env{$envname})
1.153 matthew 14016: ];
14017: }
14018: }
14019: }
1.127 matthew 14020: }
14021:
1.618 raeburn 14022: #######################################################
14023: #######################################################
14024:
14025: =pod
14026:
14027: =head1 Domain E-mail Routines
14028:
14029: =over 4
14030:
1.648 raeburn 14031: =item * &build_recipient_list()
1.618 raeburn 14032:
1.1144 raeburn 14033: Build recipient lists for following types of e-mail:
1.766 raeburn 14034: (a) Error Reports, (b) Package Updates, (c) lonstatus warnings/errors
1.1144 raeburn 14035: (d) Help requests, (e) Course requests needing approval, (f) loncapa
14036: module change checking, student/employee ID conflict checks, as
14037: generated by lonerrorhandler.pm, CHECKRPMS, loncron,
14038: lonsupportreq.pm, loncoursequeueadmin.pm, searchcat.pl respectively.
1.618 raeburn 14039:
14040: Inputs:
1.619 raeburn 14041: defmail (scalar - email address of default recipient),
1.1144 raeburn 14042: mailing type (scalar: errormail, packagesmail, helpdeskmail,
14043: requestsmail, updatesmail, or idconflictsmail).
14044:
1.619 raeburn 14045: defdom (domain for which to retrieve configuration settings),
1.1144 raeburn 14046:
1.619 raeburn 14047: origmail (scalar - email address of recipient from loncapa.conf,
14048: i.e., predates configuration by DC via domainprefs.pm
1.618 raeburn 14049:
1.655 raeburn 14050: Returns: comma separated list of addresses to which to send e-mail.
14051:
14052: =back
1.618 raeburn 14053:
14054: =cut
14055:
14056: ############################################################
14057: ############################################################
14058: sub build_recipient_list {
1.619 raeburn 14059: my ($defmail,$mailing,$defdom,$origmail) = @_;
1.618 raeburn 14060: my @recipients;
14061: my $otheremails;
14062: my %domconfig =
14063: &Apache::lonnet::get_dom('configuration',['contacts'],$defdom);
14064: if (ref($domconfig{'contacts'}) eq 'HASH') {
1.766 raeburn 14065: if (exists($domconfig{'contacts'}{$mailing})) {
14066: if (ref($domconfig{'contacts'}{$mailing}) eq 'HASH') {
14067: my @contacts = ('adminemail','supportemail');
14068: foreach my $item (@contacts) {
14069: if ($domconfig{'contacts'}{$mailing}{$item}) {
14070: my $addr = $domconfig{'contacts'}{$item};
14071: if (!grep(/^\Q$addr\E$/,@recipients)) {
14072: push(@recipients,$addr);
14073: }
1.619 raeburn 14074: }
1.766 raeburn 14075: $otheremails = $domconfig{'contacts'}{$mailing}{'others'};
1.618 raeburn 14076: }
14077: }
1.766 raeburn 14078: } elsif ($origmail ne '') {
14079: push(@recipients,$origmail);
1.618 raeburn 14080: }
1.619 raeburn 14081: } elsif ($origmail ne '') {
14082: push(@recipients,$origmail);
1.618 raeburn 14083: }
1.688 raeburn 14084: if (defined($defmail)) {
14085: if ($defmail ne '') {
14086: push(@recipients,$defmail);
14087: }
1.618 raeburn 14088: }
14089: if ($otheremails) {
1.619 raeburn 14090: my @others;
14091: if ($otheremails =~ /,/) {
14092: @others = split(/,/,$otheremails);
1.618 raeburn 14093: } else {
1.619 raeburn 14094: push(@others,$otheremails);
14095: }
14096: foreach my $addr (@others) {
14097: if (!grep(/^\Q$addr\E$/,@recipients)) {
14098: push(@recipients,$addr);
14099: }
1.618 raeburn 14100: }
14101: }
1.619 raeburn 14102: my $recipientlist = join(',',@recipients);
1.618 raeburn 14103: return $recipientlist;
14104: }
14105:
1.127 matthew 14106: ############################################################
14107: ############################################################
1.154 albertel 14108:
1.655 raeburn 14109: =pod
14110:
1.1224 musolffc 14111: =over 4
14112:
1.1223 musolffc 14113: =item * &mime_email()
14114:
14115: Sends an email with a possible attachment
14116:
14117: Inputs:
14118:
14119: =over 4
14120:
14121: from - Sender's email address
14122:
14123: to - Email address of recipient
14124:
14125: subject - Subject of email
14126:
14127: body - Body of email
14128:
14129: cc_string - Carbon copy email address
14130:
14131: bcc - Blind carbon copy email address
14132:
14133: type - File type of attachment
14134:
14135: attachment_path - Path of file to be attached
14136:
14137: file_name - Name of file to be attached
14138:
14139: attachment_text - The body of an attachment of type "TEXT"
14140:
14141: =back
14142:
14143: =back
14144:
14145: =cut
14146:
14147: ############################################################
14148: ############################################################
14149:
14150: sub mime_email {
14151: my ($from, $to, $subject, $body, $cc_string, $bcc, $attachment_path,
14152: $file_name, $attachment_text) = @_;
14153: my $msg = MIME::Lite->new(
14154: From => $from,
14155: To => $to,
14156: Subject => $subject,
14157: Type =>'TEXT',
14158: Data => $body,
14159: );
14160: if ($cc_string ne '') {
14161: $msg->add("Cc" => $cc_string);
14162: }
14163: if ($bcc ne '') {
14164: $msg->add("Bcc" => $bcc);
14165: }
14166: $msg->attr("content-type" => "text/plain");
14167: $msg->attr("content-type.charset" => "UTF-8");
14168: # Attach file if given
14169: if ($attachment_path) {
14170: unless ($file_name) {
14171: if ($attachment_path =~ m-/([^/]+)$-) { $file_name = $1; }
14172: }
14173: my ($type, $encoding) = MIME::Types::by_suffix($attachment_path);
14174: $msg->attach(Type => $type,
14175: Path => $attachment_path,
14176: Filename => $file_name
14177: );
14178: # Otherwise attach text if given
14179: } elsif ($attachment_text) {
14180: $msg->attach(Type => 'TEXT',
14181: Data => $attachment_text);
14182: }
14183: # Send it
14184: $msg->send('sendmail');
14185: }
14186:
14187: ############################################################
14188: ############################################################
14189:
14190: =pod
14191:
1.655 raeburn 14192: =head1 Course Catalog Routines
14193:
14194: =over 4
14195:
14196: =item * &gather_categories()
14197:
14198: Converts category definitions - keys of categories hash stored in
14199: coursecategories in configuration.db on the primary library server in a
14200: domain - to an array. Also generates javascript and idx hash used to
14201: generate Domain Coordinator interface for editing Course Categories.
14202:
14203: Inputs:
1.663 raeburn 14204:
1.655 raeburn 14205: categories (reference to hash of category definitions).
1.663 raeburn 14206:
1.655 raeburn 14207: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14208: categories and subcategories).
1.663 raeburn 14209:
1.655 raeburn 14210: idx (reference to hash of counters used in Domain Coordinator interface for
14211: editing Course Categories).
1.663 raeburn 14212:
1.655 raeburn 14213: jsarray (reference to array of categories used to create Javascript arrays for
14214: Domain Coordinator interface for editing Course Categories).
14215:
14216: Returns: nothing
14217:
14218: Side effects: populates cats, idx and jsarray.
14219:
14220: =cut
14221:
14222: sub gather_categories {
14223: my ($categories,$cats,$idx,$jsarray) = @_;
14224: my %counters;
14225: my $num = 0;
14226: foreach my $item (keys(%{$categories})) {
14227: my ($cat,$container,$depth) = map { &unescape($_); } split(/:/,$item);
14228: if ($container eq '' && $depth == 0) {
14229: $cats->[$depth][$categories->{$item}] = $cat;
14230: } else {
14231: $cats->[$depth]{$container}[$categories->{$item}] = $cat;
14232: }
14233: my ($escitem,$tail) = split(/:/,$item,2);
14234: if ($counters{$tail} eq '') {
14235: $counters{$tail} = $num;
14236: $num ++;
14237: }
14238: if (ref($idx) eq 'HASH') {
14239: $idx->{$item} = $counters{$tail};
14240: }
14241: if (ref($jsarray) eq 'ARRAY') {
14242: push(@{$jsarray->[$counters{$tail}]},$item);
14243: }
14244: }
14245: return;
14246: }
14247:
14248: =pod
14249:
14250: =item * &extract_categories()
14251:
14252: Used to generate breadcrumb trails for course categories.
14253:
14254: Inputs:
1.663 raeburn 14255:
1.655 raeburn 14256: categories (reference to hash of category definitions).
1.663 raeburn 14257:
1.655 raeburn 14258: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14259: categories and subcategories).
1.663 raeburn 14260:
1.655 raeburn 14261: trails (reference to array of breacrumb trails for each category).
1.663 raeburn 14262:
1.655 raeburn 14263: allitems (reference to hash - key is category key
14264: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14265:
1.655 raeburn 14266: idx (reference to hash of counters used in Domain Coordinator interface for
14267: editing Course Categories).
1.663 raeburn 14268:
1.655 raeburn 14269: jsarray (reference to array of categories used to create Javascript arrays for
14270: Domain Coordinator interface for editing Course Categories).
14271:
1.665 raeburn 14272: subcats (reference to hash of arrays containing all subcategories within each
14273: category, -recursive)
14274:
1.655 raeburn 14275: Returns: nothing
14276:
14277: Side effects: populates trails and allitems hash references.
14278:
14279: =cut
14280:
14281: sub extract_categories {
1.665 raeburn 14282: my ($categories,$cats,$trails,$allitems,$idx,$jsarray,$subcats) = @_;
1.655 raeburn 14283: if (ref($categories) eq 'HASH') {
14284: &gather_categories($categories,$cats,$idx,$jsarray);
14285: if (ref($cats->[0]) eq 'ARRAY') {
14286: for (my $i=0; $i<@{$cats->[0]}; $i++) {
14287: my $name = $cats->[0][$i];
14288: my $item = &escape($name).'::0';
14289: my $trailstr;
14290: if ($name eq 'instcode') {
14291: $trailstr = &mt('Official courses (with institutional codes)');
1.919 raeburn 14292: } elsif ($name eq 'communities') {
14293: $trailstr = &mt('Communities');
1.1239 raeburn 14294: } elsif ($name eq 'placement') {
14295: $trailstr = &mt('Placement Tests');
1.655 raeburn 14296: } else {
14297: $trailstr = $name;
14298: }
14299: if ($allitems->{$item} eq '') {
14300: push(@{$trails},$trailstr);
14301: $allitems->{$item} = scalar(@{$trails})-1;
14302: }
14303: my @parents = ($name);
14304: if (ref($cats->[1]{$name}) eq 'ARRAY') {
14305: for (my $j=0; $j<@{$cats->[1]{$name}}; $j++) {
14306: my $category = $cats->[1]{$name}[$j];
1.665 raeburn 14307: if (ref($subcats) eq 'HASH') {
14308: push(@{$subcats->{$item}},&escape($category).':'.&escape($name).':1');
14309: }
14310: &recurse_categories($cats,2,$category,$trails,$allitems,\@parents,$subcats);
14311: }
14312: } else {
14313: if (ref($subcats) eq 'HASH') {
14314: $subcats->{$item} = [];
1.655 raeburn 14315: }
14316: }
14317: }
14318: }
14319: }
14320: return;
14321: }
14322:
14323: =pod
14324:
1.1162 raeburn 14325: =item * &recurse_categories()
1.655 raeburn 14326:
14327: Recursively used to generate breadcrumb trails for course categories.
14328:
14329: Inputs:
1.663 raeburn 14330:
1.655 raeburn 14331: cats (reference to array of arrays/hashes which encapsulates hierarchy of
14332: categories and subcategories).
1.663 raeburn 14333:
1.655 raeburn 14334: depth (current depth in hierarchy of categories and sub-categories - 0 indexed).
1.663 raeburn 14335:
14336: category (current course category, for which breadcrumb trail is being generated).
14337:
14338: trails (reference to array of breadcrumb trails for each category).
14339:
1.655 raeburn 14340: allitems (reference to hash - key is category key
14341: (format: escaped(name):escaped(parent category):depth in hierarchy).
1.663 raeburn 14342:
1.655 raeburn 14343: parents (array containing containers directories for current category,
14344: back to top level).
14345:
14346: Returns: nothing
14347:
14348: Side effects: populates trails and allitems hash references
14349:
14350: =cut
14351:
14352: sub recurse_categories {
1.665 raeburn 14353: my ($cats,$depth,$category,$trails,$allitems,$parents,$subcats) = @_;
1.655 raeburn 14354: my $shallower = $depth - 1;
14355: if (ref($cats->[$depth]{$category}) eq 'ARRAY') {
14356: for (my $k=0; $k<@{$cats->[$depth]{$category}}; $k++) {
14357: my $name = $cats->[$depth]{$category}[$k];
14358: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14359: my $trailstr = join(' -> ',(@{$parents},$category));
14360: if ($allitems->{$item} eq '') {
14361: push(@{$trails},$trailstr);
14362: $allitems->{$item} = scalar(@{$trails})-1;
14363: }
14364: my $deeper = $depth+1;
14365: push(@{$parents},$category);
1.665 raeburn 14366: if (ref($subcats) eq 'HASH') {
14367: my $subcat = &escape($name).':'.$category.':'.$depth;
14368: for (my $j=@{$parents}; $j>=0; $j--) {
14369: my $higher;
14370: if ($j > 0) {
14371: $higher = &escape($parents->[$j]).':'.
14372: &escape($parents->[$j-1]).':'.$j;
14373: } else {
14374: $higher = &escape($parents->[$j]).'::'.$j;
14375: }
14376: push(@{$subcats->{$higher}},$subcat);
14377: }
14378: }
14379: &recurse_categories($cats,$deeper,$name,$trails,$allitems,$parents,
14380: $subcats);
1.655 raeburn 14381: pop(@{$parents});
14382: }
14383: } else {
14384: my $item = &escape($category).':'.&escape($parents->[-1]).':'.$shallower;
14385: my $trailstr = join(' -> ',(@{$parents},$category));
14386: if ($allitems->{$item} eq '') {
14387: push(@{$trails},$trailstr);
14388: $allitems->{$item} = scalar(@{$trails})-1;
14389: }
14390: }
14391: return;
14392: }
14393:
1.663 raeburn 14394: =pod
14395:
1.1162 raeburn 14396: =item * &assign_categories_table()
1.663 raeburn 14397:
14398: Create a datatable for display of hierarchical categories in a domain,
14399: with checkboxes to allow a course to be categorized.
14400:
14401: Inputs:
14402:
14403: cathash - reference to hash of categories defined for the domain (from
14404: configuration.db)
14405:
14406: currcat - scalar with an & separated list of categories assigned to a course.
14407:
1.919 raeburn 14408: type - scalar contains course type (Course or Community).
14409:
1.663 raeburn 14410: Returns: $output (markup to be displayed)
14411:
14412: =cut
14413:
14414: sub assign_categories_table {
1.919 raeburn 14415: my ($cathash,$currcat,$type) = @_;
1.663 raeburn 14416: my $output;
14417: if (ref($cathash) eq 'HASH') {
14418: my (@cats,@trails,%allitems,%idx,@jsarray,@path,$maxdepth);
14419: &extract_categories($cathash,\@cats,\@trails,\%allitems,\%idx,\@jsarray);
14420: $maxdepth = scalar(@cats);
14421: if (@cats > 0) {
14422: my $itemcount = 0;
14423: if (ref($cats[0]) eq 'ARRAY') {
14424: my @currcategories;
14425: if ($currcat ne '') {
14426: @currcategories = split('&',$currcat);
14427: }
1.919 raeburn 14428: my $table;
1.663 raeburn 14429: for (my $i=0; $i<@{$cats[0]}; $i++) {
14430: my $parent = $cats[0][$i];
1.919 raeburn 14431: next if ($parent eq 'instcode');
14432: if ($type eq 'Community') {
14433: next unless ($parent eq 'communities');
1.1239 raeburn 14434: } elsif ($type eq 'Placement') {
14435: next unless ($parent eq 'placement');
1.919 raeburn 14436: } else {
1.1239 raeburn 14437: next if (($parent eq 'communities') || ($parent eq 'placement'));
1.919 raeburn 14438: }
1.663 raeburn 14439: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
14440: my $item = &escape($parent).'::0';
14441: my $checked = '';
14442: if (@currcategories > 0) {
14443: if (grep(/^\Q$item\E$/,@currcategories)) {
1.772 bisitz 14444: $checked = ' checked="checked"';
1.663 raeburn 14445: }
14446: }
1.919 raeburn 14447: my $parent_title = $parent;
14448: if ($parent eq 'communities') {
14449: $parent_title = &mt('Communities');
1.1239 raeburn 14450: } elsif ($parent eq 'placement') {
14451: $parent_title = &mt('Placement Tests');
1.919 raeburn 14452: }
14453: $table .= '<tr '.$css_class.'><td><span class="LC_nobreak">'.
14454: '<input type="checkbox" name="usecategory" value="'.
14455: $item.'"'.$checked.' />'.$parent_title.'</span>'.
14456: '<input type="hidden" name="catname" value="'.$parent.'" /></td>';
1.663 raeburn 14457: my $depth = 1;
14458: push(@path,$parent);
1.919 raeburn 14459: $table .= &assign_category_rows($itemcount,\@cats,$depth,$parent,\@path,\@currcategories);
1.663 raeburn 14460: pop(@path);
1.919 raeburn 14461: $table .= '</tr><tr><td colspan="'.$maxdepth.'" class="LC_row_separator"></td></tr>';
1.663 raeburn 14462: $itemcount ++;
14463: }
1.919 raeburn 14464: if ($itemcount) {
14465: $output = &Apache::loncommon::start_data_table().
14466: $table.
14467: &Apache::loncommon::end_data_table();
14468: }
1.663 raeburn 14469: }
14470: }
14471: }
14472: return $output;
14473: }
14474:
14475: =pod
14476:
1.1162 raeburn 14477: =item * &assign_category_rows()
1.663 raeburn 14478:
14479: Create a datatable row for display of nested categories in a domain,
14480: with checkboxes to allow a course to be categorized,called recursively.
14481:
14482: Inputs:
14483:
14484: itemcount - track row number for alternating colors
14485:
14486: cats - reference to array of arrays/hashes which encapsulates hierarchy of
14487: categories and subcategories.
14488:
14489: depth - current depth in hierarchy of categories and sub-categories - 0 indexed.
14490:
14491: parent - parent of current category item
14492:
14493: path - Array containing all categories back up through the hierarchy from the
14494: current category to the top level.
14495:
14496: currcategories - reference to array of current categories assigned to the course
14497:
14498: Returns: $output (markup to be displayed).
14499:
14500: =cut
14501:
14502: sub assign_category_rows {
14503: my ($itemcount,$cats,$depth,$parent,$path,$currcategories) = @_;
14504: my ($text,$name,$item,$chgstr);
14505: if (ref($cats) eq 'ARRAY') {
14506: my $maxdepth = scalar(@{$cats});
14507: if (ref($cats->[$depth]) eq 'HASH') {
14508: if (ref($cats->[$depth]{$parent}) eq 'ARRAY') {
14509: my $numchildren = @{$cats->[$depth]{$parent}};
14510: my $css_class = $itemcount%2?' class="LC_odd_row"':'';
1.1145 raeburn 14511: $text .= '<td><table class="LC_data_table">';
1.663 raeburn 14512: for (my $j=0; $j<$numchildren; $j++) {
14513: $name = $cats->[$depth]{$parent}[$j];
14514: $item = &escape($name).':'.&escape($parent).':'.$depth;
14515: my $deeper = $depth+1;
14516: my $checked = '';
14517: if (ref($currcategories) eq 'ARRAY') {
14518: if (@{$currcategories} > 0) {
14519: if (grep(/^\Q$item\E$/,@{$currcategories})) {
1.772 bisitz 14520: $checked = ' checked="checked"';
1.663 raeburn 14521: }
14522: }
14523: }
1.664 raeburn 14524: $text .= '<tr><td><span class="LC_nobreak"><label>'.
14525: '<input type="checkbox" name="usecategory" value="'.
1.675 raeburn 14526: $item.'"'.$checked.' />'.$name.'</label></span>'.
14527: '<input type="hidden" name="catname" value="'.$name.'" />'.
14528: '</td><td>';
1.663 raeburn 14529: if (ref($path) eq 'ARRAY') {
14530: push(@{$path},$name);
14531: $text .= &assign_category_rows($itemcount,$cats,$deeper,$name,$path,$currcategories);
14532: pop(@{$path});
14533: }
14534: $text .= '</td></tr>';
14535: }
14536: $text .= '</table></td>';
14537: }
14538: }
14539: }
14540: return $text;
14541: }
14542:
1.1181 raeburn 14543: =pod
14544:
14545: =back
14546:
14547: =cut
14548:
1.655 raeburn 14549: ############################################################
14550: ############################################################
14551:
14552:
1.443 albertel 14553: sub commit_customrole {
1.664 raeburn 14554: my ($udom,$uname,$url,$three,$four,$five,$start,$end,$context) = @_;
1.630 raeburn 14555: my $output = &mt('Assigning custom role').' "'.$five.'" by '.$four.':'.$three.' in '.$url.
1.443 albertel 14556: ($start?', '.&mt('starting').' '.localtime($start):'').
14557: ($end?', ending '.localtime($end):'').': <b>'.
14558: &Apache::lonnet::assigncustomrole(
1.664 raeburn 14559: $udom,$uname,$url,$three,$four,$five,$end,$start,undef,undef,$context).
1.443 albertel 14560: '</b><br />';
14561: return $output;
14562: }
14563:
14564: sub commit_standardrole {
1.1116 raeburn 14565: my ($udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,$credits) = @_;
1.541 raeburn 14566: my ($output,$logmsg,$linefeed);
14567: if ($context eq 'auto') {
14568: $linefeed = "\n";
14569: } else {
14570: $linefeed = "<br />\n";
14571: }
1.443 albertel 14572: if ($three eq 'st') {
1.541 raeburn 14573: my $result = &commit_studentrole(\$logmsg,$udom,$uname,$url,$three,$start,$end,
1.1116 raeburn 14574: $one,$two,$sec,$context,$credits);
1.541 raeburn 14575: if (($result =~ /^error/) || ($result eq 'not_in_class') ||
1.626 raeburn 14576: ($result eq 'unknown_course') || ($result eq 'refused')) {
14577: $output = $logmsg.' '.&mt('Error: ').$result."\n";
1.443 albertel 14578: } else {
1.541 raeburn 14579: $output = $logmsg.$linefeed.&mt('Assigning').' '.$three.' in '.$url.
1.443 albertel 14580: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14581: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
14582: if ($context eq 'auto') {
14583: $output .= $result.$linefeed.&mt('Add to classlist').': ok';
14584: } else {
14585: $output .= '<b>'.$result.'</b>'.$linefeed.
14586: &mt('Add to classlist').': <b>ok</b>';
14587: }
14588: $output .= $linefeed;
1.443 albertel 14589: }
14590: } else {
14591: $output = &mt('Assigning').' '.$three.' in '.$url.
14592: ($start?', '.&mt('starting').' '.localtime($start):'').
1.541 raeburn 14593: ($end?', '.&mt('ending').' '.localtime($end):'').': ';
1.652 raeburn 14594: my $result = &Apache::lonnet::assignrole($udom,$uname,$url,$three,$end,$start,'','',$context);
1.541 raeburn 14595: if ($context eq 'auto') {
14596: $output .= $result.$linefeed;
14597: } else {
14598: $output .= '<b>'.$result.'</b>'.$linefeed;
14599: }
1.443 albertel 14600: }
14601: return $output;
14602: }
14603:
14604: sub commit_studentrole {
1.1116 raeburn 14605: my ($logmsg,$udom,$uname,$url,$three,$start,$end,$one,$two,$sec,$context,
14606: $credits) = @_;
1.626 raeburn 14607: my ($result,$linefeed,$oldsecurl,$newsecurl);
1.541 raeburn 14608: if ($context eq 'auto') {
14609: $linefeed = "\n";
14610: } else {
14611: $linefeed = '<br />'."\n";
14612: }
1.443 albertel 14613: if (defined($one) && defined($two)) {
14614: my $cid=$one.'_'.$two;
14615: my $oldsec=&Apache::lonnet::getsection($udom,$uname,$cid);
14616: my $secchange = 0;
14617: my $expire_role_result;
14618: my $modify_section_result;
1.628 raeburn 14619: if ($oldsec ne '-1') {
14620: if ($oldsec ne $sec) {
1.443 albertel 14621: $secchange = 1;
1.628 raeburn 14622: my $now = time;
1.443 albertel 14623: my $uurl='/'.$cid;
14624: $uurl=~s/\_/\//g;
14625: if ($oldsec) {
14626: $uurl.='/'.$oldsec;
14627: }
1.626 raeburn 14628: $oldsecurl = $uurl;
1.628 raeburn 14629: $expire_role_result =
1.652 raeburn 14630: &Apache::lonnet::assignrole($udom,$uname,$uurl,'st',$now,'','',$context);
1.628 raeburn 14631: if ($env{'request.course.sec'} ne '') {
14632: if ($expire_role_result eq 'refused') {
14633: my @roles = ('st');
14634: my @statuses = ('previous');
14635: my @roledoms = ($one);
14636: my $withsec = 1;
14637: my %roleshash =
14638: &Apache::lonnet::get_my_roles($uname,$udom,'userroles',
14639: \@statuses,\@roles,\@roledoms,$withsec);
14640: if (defined ($roleshash{$two.':'.$one.':st:'.$oldsec})) {
14641: my ($oldstart,$oldend) =
14642: split(':',$roleshash{$two.':'.$one.':st:'.$oldsec});
14643: if ($oldend > 0 && $oldend <= $now) {
14644: $expire_role_result = 'ok';
14645: }
14646: }
14647: }
14648: }
1.443 albertel 14649: $result = $expire_role_result;
14650: }
14651: }
14652: if (($expire_role_result eq 'ok') || ($secchange == 0)) {
1.1116 raeburn 14653: $modify_section_result =
14654: &Apache::lonnet::modify_student_enrollment($udom,$uname,undef,undef,
14655: undef,undef,undef,$sec,
14656: $end,$start,'','',$cid,
14657: '',$context,$credits);
1.443 albertel 14658: if ($modify_section_result =~ /^ok/) {
14659: if ($secchange == 1) {
1.628 raeburn 14660: if ($sec eq '') {
14661: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to student role without a section.',$uname,$oldsec).$linefeed;
14662: } else {
14663: $$logmsg .= &mt('Section for [_1] switched from (possibly expired) old section: [_2] to new section: [_3].',$uname,$oldsec,$sec).$linefeed;
14664: }
1.443 albertel 14665: } elsif ($oldsec eq '-1') {
1.628 raeburn 14666: if ($sec eq '') {
14667: $$logmsg .= &mt('New student role without a section for [_1] in course [_2].',$uname,$cid).$linefeed;
14668: } else {
14669: $$logmsg .= &mt('New student role for [_1] in section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14670: }
1.443 albertel 14671: } else {
1.628 raeburn 14672: if ($sec eq '') {
14673: $$logmsg .= &mt('Student [_1] assigned to course [_2] without a section.',$uname,$cid).$linefeed;
14674: } else {
14675: $$logmsg .= &mt('Student [_1] assigned to section [_2] in course [_3].',$uname,$sec,$cid).$linefeed;
14676: }
1.443 albertel 14677: }
14678: } else {
1.1115 raeburn 14679: if ($secchange) {
1.628 raeburn 14680: $$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;
14681: } else {
14682: $$logmsg .= &mt('Error when attempting to modify role for [_1] for section: "[_2]" in course [_3] -error:',$uname,$sec,$cid).' '.$modify_section_result.$linefeed;
14683: }
1.443 albertel 14684: }
14685: $result = $modify_section_result;
14686: } elsif ($secchange == 1) {
1.628 raeburn 14687: if ($oldsec eq '') {
1.1103 raeburn 14688: $$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 14689: } else {
14690: $$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;
14691: }
1.626 raeburn 14692: if ($expire_role_result eq 'refused') {
14693: my $newsecurl = '/'.$cid;
14694: $newsecurl =~ s/\_/\//g;
14695: if ($sec ne '') {
14696: $newsecurl.='/'.$sec;
14697: }
14698: if (&Apache::lonnet::allowed('cst',$newsecurl) && !(&Apache::lonnet::allowed('cst',$oldsecurl))) {
14699: if ($sec eq '') {
14700: $$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;
14701: } else {
14702: $$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;
14703: }
14704: }
14705: }
1.443 albertel 14706: }
14707: } else {
1.626 raeburn 14708: $$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 14709: $result = "error: incomplete course id\n";
14710: }
14711: return $result;
14712: }
14713:
1.1108 raeburn 14714: sub show_role_extent {
14715: my ($scope,$context,$role) = @_;
14716: $scope =~ s{^/}{};
14717: my @courseroles = &Apache::lonuserutils::roles_by_context('course',1);
14718: push(@courseroles,'co');
14719: my @authorroles = &Apache::lonuserutils::roles_by_context('author');
14720: if (($context eq 'course') || (grep(/^\Q$role\E/,@courseroles))) {
14721: $scope =~ s{/}{_};
14722: return '<span class="LC_cusr_emph">'.$env{'course.'.$scope.'.description'}.'</span>';
14723: } elsif (($context eq 'author') || (grep(/^\Q$role\E/,@authorroles))) {
14724: my ($audom,$auname) = split(/\//,$scope);
14725: return &mt('[_1] Author Space','<span class="LC_cusr_emph">'.
14726: &Apache::loncommon::plainname($auname,$audom).'</span>');
14727: } else {
14728: $scope =~ s{/$}{};
14729: return &mt('Domain: [_1]','<span class="LC_cusr_emph">'.
14730: &Apache::lonnet::domain($scope,'description').'</span>');
14731: }
14732: }
14733:
1.443 albertel 14734: ############################################################
14735: ############################################################
14736:
1.566 albertel 14737: sub check_clone {
1.578 raeburn 14738: my ($args,$linefeed) = @_;
1.566 albertel 14739: my $cloneid='/'.$args->{'clonedomain'}.'/'.$args->{'clonecourse'};
14740: my ($clonecrsudom,$clonecrsunum)= &LONCAPA::split_courseid($cloneid);
14741: my $clonehome=&Apache::lonnet::homeserver($clonecrsunum,$clonecrsudom);
14742: my $clonemsg;
14743: my $can_clone = 0;
1.944 raeburn 14744: my $lctype = lc($args->{'crstype'});
1.908 raeburn 14745: if ($lctype ne 'community') {
14746: $lctype = 'course';
14747: }
1.566 albertel 14748: if ($clonehome eq 'no_host') {
1.944 raeburn 14749: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14750: $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'});
14751: } else {
14752: $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'});
14753: }
1.566 albertel 14754: } else {
14755: my %clonedesc = &Apache::lonnet::coursedescription($cloneid,{'one_time' => 1});
1.944 raeburn 14756: if ($args->{'crstype'} eq 'Community') {
1.908 raeburn 14757: if ($clonedesc{'type'} ne 'Community') {
14758: $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'});
14759: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14760: }
14761: }
1.882 raeburn 14762: if (($env{'request.role.domain'} eq $args->{'clonedomain'}) &&
14763: (&Apache::lonnet::allowed('ccc',$env{'request.role.domain'}))) {
1.566 albertel 14764: $can_clone = 1;
14765: } else {
1.1221 raeburn 14766: my %clonehash = &Apache::lonnet::get('environment',['cloners','internal.coursecode'],
1.566 albertel 14767: $args->{'clonedomain'},$args->{'clonecourse'});
1.1221 raeburn 14768: if ($clonehash{'cloners'} eq '') {
14769: my %domdefs = &Apache::lonnet::get_domain_defaults($args->{'course_domain'});
14770: if ($domdefs{'canclone'}) {
14771: unless ($domdefs{'canclone'} eq 'none') {
14772: if ($domdefs{'canclone'} eq 'domain') {
14773: if ($args->{'ccdomain'} eq $args->{'clonedomain'}) {
14774: $can_clone = 1;
14775: }
14776: } elsif (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14777: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
14778: if (&Apache::lonnet::default_instcode_cloning($args->{'clonedomain'},$domdefs{'canclone'},
14779: $clonehash{'internal.coursecode'},$args->{'crscode'})) {
14780: $can_clone = 1;
14781: }
14782: }
14783: }
14784: }
1.578 raeburn 14785: } else {
1.1221 raeburn 14786: my @cloners = split(/,/,$clonehash{'cloners'});
14787: if (grep(/^\*$/,@cloners)) {
1.942 raeburn 14788: $can_clone = 1;
1.1221 raeburn 14789: } elsif (grep(/^\*\:\Q$args->{'ccdomain'}\E$/,@cloners)) {
1.942 raeburn 14790: $can_clone = 1;
1.1225 raeburn 14791: } elsif (grep(/^\Q$args->{'ccuname'}\E:\Q$args->{'ccdomain'}\E$/,@cloners)) {
14792: $can_clone = 1;
1.1221 raeburn 14793: }
14794: unless ($can_clone) {
1.1225 raeburn 14795: if (($clonehash{'internal.coursecode'}) && ($args->{'crscode'}) &&
14796: ($args->{'clonedomain'} eq $args->{'course_domain'})) {
1.1221 raeburn 14797: my (%gotdomdefaults,%gotcodedefaults);
14798: foreach my $cloner (@cloners) {
14799: if (($cloner ne '*') && ($cloner !~ /^\*\:$match_domain$/) &&
14800: ($cloner !~ /^$match_username\:$match_domain$/) && ($cloner ne '')) {
14801: my (%codedefaults,@code_order);
14802: if (ref($gotcodedefaults{$args->{'clonedomain'}}) eq 'HASH') {
14803: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'defaults'}) eq 'HASH') {
14804: %codedefaults = %{$gotcodedefaults{$args->{'clonedomain'}}{'defaults'}};
14805: }
14806: if (ref($gotcodedefaults{$args->{'clonedomain'}}{'order'}) eq 'ARRAY') {
14807: @code_order = @{$gotcodedefaults{$args->{'clonedomain'}}{'order'}};
14808: }
14809: } else {
14810: &Apache::lonnet::auto_instcode_defaults($args->{'clonedomain'},
14811: \%codedefaults,
14812: \@code_order);
14813: $gotcodedefaults{$args->{'clonedomain'}}{'defaults'} = \%codedefaults;
14814: $gotcodedefaults{$args->{'clonedomain'}}{'order'} = \@code_order;
14815: }
14816: if (@code_order > 0) {
14817: if (&Apache::lonnet::check_instcode_cloning(\%codedefaults,\@code_order,
14818: $cloner,$clonehash{'internal.coursecode'},
14819: $args->{'crscode'})) {
14820: $can_clone = 1;
14821: last;
14822: }
14823: }
14824: }
14825: }
14826: }
1.1225 raeburn 14827: }
14828: }
14829: unless ($can_clone) {
14830: my $ccrole = 'cc';
14831: if ($args->{'crstype'} eq 'Community') {
14832: $ccrole = 'co';
14833: }
14834: my %roleshash =
14835: &Apache::lonnet::get_my_roles($args->{'ccuname'},
14836: $args->{'ccdomain'},
14837: 'userroles',['active'],[$ccrole],
14838: [$args->{'clonedomain'}]);
14839: if ($roleshash{$args->{'clonecourse'}.':'.$args->{'clonedomain'}.':'.$ccrole}) {
14840: $can_clone = 1;
14841: } elsif (&Apache::lonnet::is_course_owner($args->{'clonedomain'},$args->{'clonecourse'},
14842: $args->{'ccuname'},$args->{'ccdomain'})) {
14843: $can_clone = 1;
1.1221 raeburn 14844: }
14845: }
14846: unless ($can_clone) {
14847: if ($args->{'crstype'} eq 'Community') {
14848: $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 14849: } else {
1.1221 raeburn 14850: $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'});
14851: }
1.566 albertel 14852: }
1.578 raeburn 14853: }
1.566 albertel 14854: }
14855: return ($can_clone, $clonemsg, $cloneid, $clonehome);
14856: }
14857:
1.444 albertel 14858: sub construct_course {
1.1166 raeburn 14859: my ($args,$logmsg,$courseid,$crsudom,$crsunum,$udom,$uname,$context,$cnum,$category,$coderef) = @_;
1.444 albertel 14860: my $outcome;
1.541 raeburn 14861: my $linefeed = '<br />'."\n";
14862: if ($context eq 'auto') {
14863: $linefeed = "\n";
14864: }
1.566 albertel 14865:
14866: #
14867: # Are we cloning?
14868: #
14869: my ($can_clone, $clonemsg, $cloneid, $clonehome);
14870: if (($args->{'clonecourse'}) && ($args->{'clonedomain'})) {
1.578 raeburn 14871: ($can_clone, $clonemsg, $cloneid, $clonehome) = &check_clone($args,$linefeed);
1.566 albertel 14872: if ($context ne 'auto') {
1.578 raeburn 14873: if ($clonemsg ne '') {
14874: $clonemsg = '<span class="LC_error">'.$clonemsg.'</span>';
14875: }
1.566 albertel 14876: }
14877: $outcome .= $clonemsg.$linefeed;
14878:
14879: if (!$can_clone) {
14880: return (0,$outcome);
14881: }
14882: }
14883:
1.444 albertel 14884: #
14885: # Open course
14886: #
1.1239 raeburn 14887: my $showncrstype;
14888: if ($args->{'crstype'} eq 'Placement') {
14889: $showncrstype = 'placement test';
14890: } else {
14891: $showncrstype = lc($args->{'crstype'});
14892: }
1.444 albertel 14893: my %cenv=();
14894: $$courseid=&Apache::lonnet::createcourse($args->{'course_domain'},
14895: $args->{'cdescr'},
14896: $args->{'curl'},
14897: $args->{'course_home'},
14898: $args->{'nonstandard'},
14899: $args->{'crscode'},
14900: $args->{'ccuname'}.':'.
14901: $args->{'ccdomain'},
1.882 raeburn 14902: $args->{'crstype'},
1.885 raeburn 14903: $cnum,$context,$category);
1.444 albertel 14904:
14905: # Note: The testing routines depend on this being output; see
14906: # Utils::Course. This needs to at least be output as a comment
14907: # if anyone ever decides to not show this, and Utils::Course::new
14908: # will need to be suitably modified.
1.1239 raeburn 14909: $outcome .= &mt('New LON-CAPA [_1] ID: [_2]',$showncrstype,$$courseid).$linefeed;
1.943 raeburn 14910: if ($$courseid =~ /^error:/) {
14911: return (0,$outcome);
14912: }
14913:
1.444 albertel 14914: #
14915: # Check if created correctly
14916: #
1.479 albertel 14917: ($$crsudom,$$crsunum)= &LONCAPA::split_courseid($$courseid);
1.444 albertel 14918: my $crsuhome=&Apache::lonnet::homeserver($$crsunum,$$crsudom);
1.943 raeburn 14919: if ($crsuhome eq 'no_host') {
14920: $outcome .= &mt('Course creation failed, unrecognized course home server.').$linefeed;
14921: return (0,$outcome);
14922: }
1.541 raeburn 14923: $outcome .= &mt('Created on').': '.$crsuhome.$linefeed;
1.566 albertel 14924:
1.444 albertel 14925: #
1.566 albertel 14926: # Do the cloning
14927: #
14928: if ($can_clone && $cloneid) {
1.1239 raeburn 14929: $clonemsg = &mt('Cloning [_1] from [_2]',$showncrstype,$clonehome);
1.566 albertel 14930: if ($context ne 'auto') {
14931: $clonemsg = '<span class="LC_success">'.$clonemsg.'</span>';
14932: }
14933: $outcome .= $clonemsg.$linefeed;
14934: my %oldcenv=&Apache::lonnet::dump('environment',$$crsudom,$$crsunum);
1.444 albertel 14935: # Copy all files
1.637 www 14936: &Apache::lonclonecourse::copycoursefiles($cloneid,$$courseid,$args->{'datemode'},$args->{'dateshift'});
1.444 albertel 14937: # Restore URL
1.566 albertel 14938: $cenv{'url'}=$oldcenv{'url'};
1.444 albertel 14939: # Restore title
1.566 albertel 14940: $cenv{'description'}=$oldcenv{'description'};
1.955 raeburn 14941: # Restore creation date, creator and creation context.
14942: $cenv{'internal.created'}=$oldcenv{'internal.created'};
14943: $cenv{'internal.creator'}=$oldcenv{'internal.creator'};
14944: $cenv{'internal.creationcontext'}=$oldcenv{'internal.creationcontext'};
1.444 albertel 14945: # Mark as cloned
1.566 albertel 14946: $cenv{'clonedfrom'}=$cloneid;
1.638 www 14947: # Need to clone grading mode
14948: my %newenv=&Apache::lonnet::get('environment',['grading'],$$crsudom,$$crsunum);
14949: $cenv{'grading'}=$newenv{'grading'};
14950: # Do not clone these environment entries
14951: &Apache::lonnet::del('environment',
14952: ['default_enrollment_start_date',
14953: 'default_enrollment_end_date',
14954: 'question.email',
14955: 'policy.email',
14956: 'comment.email',
14957: 'pch.users.denied',
1.725 raeburn 14958: 'plc.users.denied',
14959: 'hidefromcat',
1.1121 raeburn 14960: 'checkforpriv',
1.1166 raeburn 14961: 'categories',
14962: 'internal.uniquecode'],
1.638 www 14963: $$crsudom,$$crsunum);
1.1170 raeburn 14964: if ($args->{'textbook'}) {
14965: $cenv{'internal.textbook'} = $args->{'textbook'};
14966: }
1.444 albertel 14967: }
1.566 albertel 14968:
1.444 albertel 14969: #
14970: # Set environment (will override cloned, if existing)
14971: #
14972: my @sections = ();
14973: my @xlists = ();
14974: if ($args->{'crstype'}) {
14975: $cenv{'type'}=$args->{'crstype'};
14976: }
14977: if ($args->{'crsid'}) {
14978: $cenv{'courseid'}=$args->{'crsid'};
14979: }
14980: if ($args->{'crscode'}) {
14981: $cenv{'internal.coursecode'}=$args->{'crscode'};
14982: }
14983: if ($args->{'crsquota'} ne '') {
14984: $cenv{'internal.coursequota'}=$args->{'crsquota'};
14985: } else {
14986: $cenv{'internal.coursequota'}=$args->{'crsquota'} = 20;
14987: }
14988: if ($args->{'ccuname'}) {
14989: $cenv{'internal.courseowner'} = $args->{'ccuname'}.
14990: ':'.$args->{'ccdomain'};
14991: } else {
14992: $cenv{'internal.courseowner'} = $args->{'curruser'};
14993: }
1.1116 raeburn 14994: if ($args->{'defaultcredits'}) {
14995: $cenv{'internal.defaultcredits'} = $args->{'defaultcredits'};
14996: }
1.444 albertel 14997: my @badclasses = (); # Used to accumulate sections/crosslistings that did not pass classlist access check for course owner.
14998: if ($args->{'crssections'}) {
14999: $cenv{'internal.sectionnums'} = '';
15000: if ($args->{'crssections'} =~ m/,/) {
15001: @sections = split/,/,$args->{'crssections'};
15002: } else {
15003: $sections[0] = $args->{'crssections'};
15004: }
15005: if (@sections > 0) {
15006: foreach my $item (@sections) {
15007: my ($sec,$gp) = split/:/,$item;
15008: my $class = $args->{'crscode'}.$sec;
15009: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$class,$cenv{'internal.courseowner'});
15010: $cenv{'internal.sectionnums'} .= $item.',';
15011: unless ($addcheck eq 'ok') {
15012: push @badclasses, $class;
15013: }
15014: }
15015: $cenv{'internal.sectionnums'} =~ s/,$//;
15016: }
15017: }
15018: # do not hide course coordinator from staff listing,
15019: # even if privileged
15020: $cenv{'nothideprivileged'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
1.1121 raeburn 15021: # add course coordinator's domain to domains to check for privileged users
15022: # if different to course domain
15023: if ($$crsudom ne $args->{'ccdomain'}) {
15024: $cenv{'checkforpriv'} = $args->{'ccdomain'};
15025: }
1.444 albertel 15026: # add crosslistings
15027: if ($args->{'crsxlist'}) {
15028: $cenv{'internal.crosslistings'}='';
15029: if ($args->{'crsxlist'} =~ m/,/) {
15030: @xlists = split/,/,$args->{'crsxlist'};
15031: } else {
15032: $xlists[0] = $args->{'crsxlist'};
15033: }
15034: if (@xlists > 0) {
15035: foreach my $item (@xlists) {
15036: my ($xl,$gp) = split/:/,$item;
15037: my $addcheck = &Apache::lonnet::auto_new_course($$crsunum,$$crsudom,$xl,$cenv{'internal.courseowner'});
15038: $cenv{'internal.crosslistings'} .= $item.',';
15039: unless ($addcheck eq 'ok') {
15040: push @badclasses, $xl;
15041: }
15042: }
15043: $cenv{'internal.crosslistings'} =~ s/,$//;
15044: }
15045: }
15046: if ($args->{'autoadds'}) {
15047: $cenv{'internal.autoadds'}=$args->{'autoadds'};
15048: }
15049: if ($args->{'autodrops'}) {
15050: $cenv{'internal.autodrops'}=$args->{'autodrops'};
15051: }
15052: # check for notification of enrollment changes
15053: my @notified = ();
15054: if ($args->{'notify_owner'}) {
15055: if ($args->{'ccuname'} ne '') {
15056: push(@notified,$args->{'ccuname'}.':'.$args->{'ccdomain'});
15057: }
15058: }
15059: if ($args->{'notify_dc'}) {
15060: if ($uname ne '') {
1.630 raeburn 15061: push(@notified,$uname.':'.$udom);
1.444 albertel 15062: }
15063: }
15064: if (@notified > 0) {
15065: my $notifylist;
15066: if (@notified > 1) {
15067: $notifylist = join(',',@notified);
15068: } else {
15069: $notifylist = $notified[0];
15070: }
15071: $cenv{'internal.notifylist'} = $notifylist;
15072: }
15073: if (@badclasses > 0) {
15074: my %lt=&Apache::lonlocal::texthash(
15075: 'tclb' => 'The courses listed below were included as sections or crosslistings affiliated with your new LON-CAPA course. However, if automated course roster updates are enabled for this class, these particular sections/crosslistings will not contribute towards enrollment, because the user identified as the course owner for this LON-CAPA course',
15076: 'dnhr' => 'does not have rights to access enrollment in these classes',
15077: 'adby' => 'as determined by the policies of your institution on access to official classlists'
15078: );
1.541 raeburn 15079: my $badclass_msg = $cenv{'internal.courseowner'}.') - '.$lt{'dnhr'}.
15080: ' ('.$lt{'adby'}.')';
15081: if ($context eq 'auto') {
15082: $outcome .= $badclass_msg.$linefeed;
1.566 albertel 15083: $outcome .= '<div class="LC_warning">'.$badclass_msg.$linefeed.'<ul>'."\n";
1.541 raeburn 15084: foreach my $item (@badclasses) {
15085: if ($context eq 'auto') {
15086: $outcome .= " - $item\n";
15087: } else {
15088: $outcome .= "<li>$item</li>\n";
15089: }
15090: }
15091: if ($context eq 'auto') {
15092: $outcome .= $linefeed;
15093: } else {
1.566 albertel 15094: $outcome .= "</ul><br /><br /></div>\n";
1.541 raeburn 15095: }
15096: }
1.444 albertel 15097: }
15098: if ($args->{'no_end_date'}) {
15099: $args->{'endaccess'} = 0;
15100: }
15101: $cenv{'internal.autostart'}=$args->{'enrollstart'};
15102: $cenv{'internal.autoend'}=$args->{'enrollend'};
15103: $cenv{'default_enrollment_start_date'}=$args->{'startaccess'};
15104: $cenv{'default_enrollment_end_date'}=$args->{'endaccess'};
15105: if ($args->{'showphotos'}) {
15106: $cenv{'internal.showphotos'}=$args->{'showphotos'};
15107: }
15108: $cenv{'internal.authtype'} = $args->{'authtype'};
15109: $cenv{'internal.autharg'} = $args->{'autharg'};
15110: if ( ($cenv{'internal.authtype'} =~ /^krb/) && ($cenv{'internal.autoadds'} == 1)) {
15111: if (! defined($cenv{'internal.autharg'}) || $cenv{'internal.autharg'} eq '') {
1.541 raeburn 15112: 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');
15113: if ($context eq 'auto') {
15114: $outcome .= $krb_msg;
15115: } else {
1.566 albertel 15116: $outcome .= '<span class="LC_error">'.$krb_msg.'</span>';
1.541 raeburn 15117: }
15118: $outcome .= $linefeed;
1.444 albertel 15119: }
15120: }
15121: if (($args->{'ccdomain'}) && ($args->{'ccuname'})) {
15122: if ($args->{'setpolicy'}) {
15123: $cenv{'policy.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15124: }
15125: if ($args->{'setcontent'}) {
15126: $cenv{'question.email'}=$args->{'ccuname'}.':'.$args->{'ccdomain'};
15127: }
15128: }
15129: if ($args->{'reshome'}) {
15130: $cenv{'reshome'}=$args->{'reshome'}.'/';
15131: $cenv{'reshome'}=~s/\/+$/\//;
15132: }
15133: #
15134: # course has keyed access
15135: #
15136: if ($args->{'setkeys'}) {
15137: $cenv{'keyaccess'}='yes';
15138: }
15139: # if specified, key authority is not course, but user
15140: # only active if keyaccess is yes
15141: if ($args->{'keyauth'}) {
1.487 albertel 15142: my ($user,$domain) = split(':',$args->{'keyauth'});
15143: $user = &LONCAPA::clean_username($user);
15144: $domain = &LONCAPA::clean_username($domain);
1.488 foxr 15145: if ($user ne '' && $domain ne '') {
1.487 albertel 15146: $cenv{'keyauth'}=$user.':'.$domain;
1.444 albertel 15147: }
15148: }
15149:
1.1166 raeburn 15150: #
1.1167 raeburn 15151: # generate and store uniquecode (available to course requester), if course should have one.
1.1166 raeburn 15152: #
15153: if ($args->{'uniquecode'}) {
15154: my ($code,$error) = &make_unique_code($$crsudom,$$crsunum);
15155: if ($code) {
15156: $cenv{'internal.uniquecode'} = $code;
1.1167 raeburn 15157: my %crsinfo =
15158: &Apache::lonnet::courseiddump($$crsudom,'.',1,'.','.',$$crsunum,undef,undef,'.');
15159: if (ref($crsinfo{$$crsudom.'_'.$$crsunum}) eq 'HASH') {
15160: $crsinfo{$$crsudom.'_'.$$crsunum}{'uniquecode'} = $code;
15161: my $putres = &Apache::lonnet::courseidput($$crsudom,\%crsinfo,$crsuhome,'notime');
15162: }
1.1166 raeburn 15163: if (ref($coderef)) {
15164: $$coderef = $code;
15165: }
15166: }
15167: }
15168:
1.444 albertel 15169: if ($args->{'disresdis'}) {
15170: $cenv{'pch.roles.denied'}='st';
15171: }
15172: if ($args->{'disablechat'}) {
15173: $cenv{'plc.roles.denied'}='st';
15174: }
15175:
15176: # Record we've not yet viewed the Course Initialization Helper for this
15177: # course
15178: $cenv{'course.helper.not.run'} = 1;
15179: #
15180: # Use new Randomseed
15181: #
15182: $cenv{'rndseed'}=&Apache::lonnet::latest_rnd_algorithm_id();;
15183: $cenv{'receiptalg'}=&Apache::lonnet::latest_receipt_algorithm_id();;
15184: #
15185: # The encryption code and receipt prefix for this course
15186: #
15187: $cenv{'internal.encseed'}=$Apache::lonnet::perlvar{'lonReceipt'}.$$.time.int(rand(9999));
15188: $cenv{'internal.encpref'}=100+int(9*rand(99));
15189: #
15190: # By default, use standard grading
15191: if (!defined($cenv{'grading'})) { $cenv{'grading'} = 'standard'; }
15192:
1.541 raeburn 15193: $outcome .= $linefeed.&mt('Setting environment').': '.
15194: &Apache::lonnet::put('environment',\%cenv,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15195: #
15196: # Open all assignments
15197: #
15198: if ($args->{'openall'}) {
15199: my $storeunder=$$crsudom.'_'.$$crsunum.'.0.opendate';
15200: my %storecontent = ($storeunder => time,
15201: $storeunder.'.type' => 'date_start');
15202:
15203: $outcome .= &mt('Opening all assignments').': '.&Apache::lonnet::cput
1.541 raeburn 15204: ('resourcedata',\%storecontent,$$crsudom,$$crsunum).$linefeed;
1.444 albertel 15205: }
15206: #
15207: # Set first page
15208: #
15209: unless (($args->{'nonstandard'}) || ($args->{'firstres'} eq 'blank')
15210: || ($cloneid)) {
1.445 albertel 15211: use LONCAPA::map;
1.444 albertel 15212: $outcome .= &mt('Setting first resource').': ';
1.445 albertel 15213:
15214: my $map = '/uploaded/'.$$crsudom.'/'.$$crsunum.'/default.sequence';
15215: my ($errtext,$fatal)=&LONCAPA::map::mapread($map);
15216:
1.444 albertel 15217: $outcome .= ($fatal?$errtext:'read ok').' - ';
15218: my $title; my $url;
15219: if ($args->{'firstres'} eq 'syl') {
1.690 bisitz 15220: $title=&mt('Syllabus');
1.444 albertel 15221: $url='/public/'.$$crsudom.'/'.$$crsunum.'/syllabus';
15222: } else {
1.963 raeburn 15223: $title=&mt('Table of Contents');
1.444 albertel 15224: $url='/adm/navmaps';
15225: }
1.445 albertel 15226:
15227: $LONCAPA::map::resources[1]=$title.':'.$url.':false:start:res';
15228: (my $outtext,$errtext) = &LONCAPA::map::storemap($map,1);
15229:
15230: if ($errtext) { $fatal=2; }
1.541 raeburn 15231: $outcome .= ($fatal?$errtext:'write ok').$linefeed;
1.444 albertel 15232: }
1.566 albertel 15233:
1.1237 raeburn 15234: #
15235: # Set params for Placement Tests
15236: #
1.1239 raeburn 15237: if ($args->{'crstype'} eq 'Placement') {
15238: my %storecontent;
15239: my $prefix=$$crsudom.'_'.$$crsunum.'.0.';
15240: my %defaults = (
15241: buttonshide => { value => 'yes',
15242: type => 'string_yesno',},
15243: type => { value => 'randomizetry',
15244: type => 'string_questiontype',},
15245: maxtries => { value => 1,
15246: type => 'int_pos',},
15247: problemstatus => { value => 'no',
15248: type => 'string_problemstatus',},
15249: );
15250: foreach my $key (keys(%defaults)) {
15251: $storecontent{$prefix.$key} = $defaults{$key}{'value'};
15252: $storecontent{$prefix.$key.'.type'} = $defaults{$key}{'type'};
15253: }
1.1237 raeburn 15254: &Apache::lonnet::cput
15255: ('resourcedata',\%storecontent,$$crsudom,$$crsunum);
15256: }
15257:
1.566 albertel 15258: return (1,$outcome);
1.444 albertel 15259: }
15260:
1.1166 raeburn 15261: sub make_unique_code {
15262: my ($cdom,$cnum) = @_;
15263: # get lock on uniquecodes db
15264: my $lockhash = {
15265: $cnum."\0".'uniquecodes' => $env{'user.name'}.
15266: ':'.$env{'user.domain'},
15267: };
15268: my $tries = 0;
15269: my $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15270: my ($code,$error);
15271:
15272: while (($gotlock ne 'ok') && ($tries<3)) {
15273: $tries ++;
15274: sleep 1;
15275: $gotlock = &Apache::lonnet::newput_dom('uniquecodes',$lockhash,$cdom);
15276: }
15277: if ($gotlock eq 'ok') {
15278: my %currcodes = &Apache::lonnet::dump_dom('uniquecodes',$cdom);
15279: my $gotcode;
15280: my $attempts = 0;
15281: while ((!$gotcode) && ($attempts < 100)) {
15282: $code = &generate_code();
15283: if (!exists($currcodes{$code})) {
15284: $gotcode = 1;
15285: unless (&Apache::lonnet::newput_dom('uniquecodes',{ $code => $cnum },$cdom) eq 'ok') {
15286: $error = 'nostore';
15287: }
15288: }
15289: $attempts ++;
15290: }
15291: my @del_lock = ($cnum."\0".'uniquecodes');
15292: my $dellockoutcome = &Apache::lonnet::del_dom('uniquecodes',\@del_lock,$cdom);
15293: } else {
15294: $error = 'nolock';
15295: }
15296: return ($code,$error);
15297: }
15298:
15299: sub generate_code {
15300: my $code;
15301: my @letts = qw(B C D G H J K M N P Q R S T V W X Z);
15302: for (my $i=0; $i<6; $i++) {
15303: my $lettnum = int (rand 2);
15304: my $item = '';
15305: if ($lettnum) {
15306: $item = $letts[int( rand(18) )];
15307: } else {
15308: $item = 1+int( rand(8) );
15309: }
15310: $code .= $item;
15311: }
15312: return $code;
15313: }
15314:
1.444 albertel 15315: ############################################################
15316: ############################################################
15317:
1.1237 raeburn 15318: # Community, Course and Placement Test
1.378 raeburn 15319: sub course_type {
15320: my ($cid) = @_;
15321: if (!defined($cid)) {
15322: $cid = $env{'request.course.id'};
15323: }
1.404 albertel 15324: if (defined($env{'course.'.$cid.'.type'})) {
15325: return $env{'course.'.$cid.'.type'};
1.378 raeburn 15326: } else {
15327: return 'Course';
1.377 raeburn 15328: }
15329: }
1.156 albertel 15330:
1.406 raeburn 15331: sub group_term {
15332: my $crstype = &course_type();
15333: my %names = (
15334: 'Course' => 'group',
1.865 raeburn 15335: 'Community' => 'group',
1.1237 raeburn 15336: 'Placement' => 'group',
1.406 raeburn 15337: );
15338: return $names{$crstype};
15339: }
15340:
1.902 raeburn 15341: sub course_types {
1.1237 raeburn 15342: my @types = ('official','unofficial','community','textbook','placement');
1.902 raeburn 15343: my %typename = (
15344: official => 'Official course',
15345: unofficial => 'Unofficial course',
15346: community => 'Community',
1.1165 raeburn 15347: textbook => 'Textbook course',
1.1237 raeburn 15348: placement => 'Placement test',
1.902 raeburn 15349: );
15350: return (\@types,\%typename);
15351: }
15352:
1.156 albertel 15353: sub icon {
15354: my ($file)=@_;
1.505 albertel 15355: my $curfext = lc((split(/\./,$file))[-1]);
1.168 albertel 15356: my $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/unknown.gif';
1.156 albertel 15357: my $embstyle = &Apache::loncommon::fileembstyle($curfext);
1.168 albertel 15358: if (!(!defined($embstyle) || $embstyle eq 'unk' || $embstyle eq 'hdn')) {
15359: if (-e $Apache::lonnet::perlvar{'lonDocRoot'}.'/'.
15360: $Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15361: $curfext.".gif") {
15362: $iconname=$Apache::lonnet::perlvar{'lonIconsURL'}.'/'.
15363: $curfext.".gif";
15364: }
15365: }
1.249 albertel 15366: return &lonhttpdurl($iconname);
1.154 albertel 15367: }
1.84 albertel 15368:
1.575 albertel 15369: sub lonhttpdurl {
1.692 www 15370: #
15371: # Had been used for "small fry" static images on separate port 8080.
15372: # Modify here if lightweight http functionality desired again.
15373: # Currently eliminated due to increasing firewall issues.
15374: #
1.575 albertel 15375: my ($url)=@_;
1.692 www 15376: return $url;
1.215 albertel 15377: }
15378:
1.213 albertel 15379: sub connection_aborted {
15380: my ($r)=@_;
15381: $r->print(" ");$r->rflush();
15382: my $c = $r->connection;
15383: return $c->aborted();
15384: }
15385:
1.221 foxr 15386: # Escapes strings that may have embedded 's that will be put into
1.222 foxr 15387: # strings as 'strings'.
15388: sub escape_single {
1.221 foxr 15389: my ($input) = @_;
1.223 albertel 15390: $input =~ s/\\/\\\\/g; # Escape the \'s..(must be first)>
1.221 foxr 15391: $input =~ s/\'/\\\'/g; # Esacpe the 's....
15392: return $input;
15393: }
1.223 albertel 15394:
1.222 foxr 15395: # Same as escape_single, but escape's "'s This
15396: # can be used for "strings"
15397: sub escape_double {
15398: my ($input) = @_;
15399: $input =~ s/\\/\\\\/g; # Escape the /'s..(must be first)>
15400: $input =~ s/\"/\\\"/g; # Esacpe the "s....
15401: return $input;
15402: }
1.223 albertel 15403:
1.222 foxr 15404: # Escapes the last element of a full URL.
15405: sub escape_url {
15406: my ($url) = @_;
1.238 raeburn 15407: my @urlslices = split(/\//, $url,-1);
1.369 www 15408: my $lastitem = &escape(pop(@urlslices));
1.1203 raeburn 15409: return &HTML::Entities::encode(join('/',@urlslices),"'").'/'.$lastitem;
1.222 foxr 15410: }
1.462 albertel 15411:
1.820 raeburn 15412: sub compare_arrays {
15413: my ($arrayref1,$arrayref2) = @_;
15414: my (@difference,%count);
15415: @difference = ();
15416: %count = ();
15417: if ((ref($arrayref1) eq 'ARRAY') && (ref($arrayref2) eq 'ARRAY')) {
15418: foreach my $element (@{$arrayref1}, @{$arrayref2}) { $count{$element}++; }
15419: foreach my $element (keys(%count)) {
15420: if ($count{$element} == 1) {
15421: push(@difference,$element);
15422: }
15423: }
15424: }
15425: return @difference;
15426: }
15427:
1.817 bisitz 15428: # -------------------------------------------------------- Initialize user login
1.462 albertel 15429: sub init_user_environment {
1.463 albertel 15430: my ($r, $username, $domain, $authhost, $form, $args) = @_;
1.462 albertel 15431: my $lonids=$Apache::lonnet::perlvar{'lonIDsDir'};
15432:
15433: my $public=($username eq 'public' && $domain eq 'public');
15434:
15435: # See if old ID present, if so, remove
15436:
1.1062 raeburn 15437: my ($filename,$cookie,$userroles,$firstaccenv,$timerintenv);
1.462 albertel 15438: my $now=time;
15439:
15440: if ($public) {
15441: my $max_public=100;
15442: my $oldest;
15443: my $oldest_time=0;
15444: for(my $next=1;$next<=$max_public;$next++) {
15445: if (-e $lonids."/publicuser_$next.id") {
15446: my $mtime=(stat($lonids."/publicuser_$next.id"))[9];
15447: if ($mtime<$oldest_time || !$oldest_time) {
15448: $oldest_time=$mtime;
15449: $oldest=$next;
15450: }
15451: } else {
15452: $cookie="publicuser_$next";
15453: last;
15454: }
15455: }
15456: if (!$cookie) { $cookie="publicuser_$oldest"; }
15457: } else {
1.463 albertel 15458: # if this isn't a robot, kill any existing non-robot sessions
15459: if (!$args->{'robot'}) {
15460: opendir(DIR,$lonids);
15461: while ($filename=readdir(DIR)) {
15462: if ($filename=~/^$username\_\d+\_$domain\_$authhost\.id$/) {
15463: unlink($lonids.'/'.$filename);
15464: }
1.462 albertel 15465: }
1.463 albertel 15466: closedir(DIR);
1.1204 raeburn 15467: # If there is a undeleted lockfile for the user's paste buffer remove it.
15468: my $namespace = 'nohist_courseeditor';
15469: my $lockingkey = 'paste'."\0".'locked_num';
15470: my %lockhash = &Apache::lonnet::get($namespace,[$lockingkey],
15471: $domain,$username);
15472: if (exists($lockhash{$lockingkey})) {
15473: my $delresult = &Apache::lonnet::del($namespace,[$lockingkey],$domain,$username);
15474: unless ($delresult eq 'ok') {
15475: &Apache::lonnet::logthis("Failed to delete paste buffer locking key in $namespace for ".$username.":".$domain." Result was: $delresult");
15476: }
15477: }
1.462 albertel 15478: }
15479: # Give them a new cookie
1.463 albertel 15480: my $id = ($args->{'robot'} ? 'robot'.$args->{'robot'}
1.684 www 15481: : $now.$$.int(rand(10000)));
1.463 albertel 15482: $cookie="$username\_$id\_$domain\_$authhost";
1.462 albertel 15483:
15484: # Initialize roles
15485:
1.1062 raeburn 15486: ($userroles,$firstaccenv,$timerintenv) =
15487: &Apache::lonnet::rolesinit($domain,$username,$authhost);
1.462 albertel 15488: }
15489: # ------------------------------------ Check browser type and MathML capability
15490:
1.1194 raeburn 15491: my ($httpbrowser,$clientbrowser,$clientversion,$clientmathml,$clientunicode,
15492: $clientos,$clientmobile,$clientinfo,$clientosversion) = &decode_user_agent($r);
1.462 albertel 15493:
15494: # ------------------------------------------------------------- Get environment
15495:
15496: my %userenv = &Apache::lonnet::dump('environment',$domain,$username);
15497: my ($tmp) = keys(%userenv);
15498: if ($tmp !~ /^(con_lost|error|no_such_host)/i) {
15499: } else {
15500: undef(%userenv);
15501: }
15502: if (($userenv{'interface'}) && (!$form->{'interface'})) {
15503: $form->{'interface'}=$userenv{'interface'};
15504: }
15505: if ($userenv{'texengine'} eq 'ttm') { $clientmathml=1; }
15506:
15507: # --------------- Do not trust query string to be put directly into environment
1.817 bisitz 15508: foreach my $option ('interface','localpath','localres') {
15509: $form->{$option}=~s/[\n\r\=]//gs;
1.462 albertel 15510: }
15511: # --------------------------------------------------------- Write first profile
15512:
15513: {
15514: my %initial_env =
15515: ("user.name" => $username,
15516: "user.domain" => $domain,
15517: "user.home" => $authhost,
15518: "browser.type" => $clientbrowser,
15519: "browser.version" => $clientversion,
15520: "browser.mathml" => $clientmathml,
15521: "browser.unicode" => $clientunicode,
15522: "browser.os" => $clientos,
1.1137 raeburn 15523: "browser.mobile" => $clientmobile,
1.1141 raeburn 15524: "browser.info" => $clientinfo,
1.1194 raeburn 15525: "browser.osversion" => $clientosversion,
1.462 albertel 15526: "server.domain" => $Apache::lonnet::perlvar{'lonDefDomain'},
15527: "request.course.fn" => '',
15528: "request.course.uri" => '',
15529: "request.course.sec" => '',
15530: "request.role" => 'cm',
15531: "request.role.adv" => $env{'user.adv'},
15532: "request.host" => $ENV{'REMOTE_ADDR'},);
15533:
15534: if ($form->{'localpath'}) {
15535: $initial_env{"browser.localpath"} = $form->{'localpath'};
15536: $initial_env{"browser.localres"} = $form->{'localres'};
15537: }
15538:
15539: if ($form->{'interface'}) {
15540: $form->{'interface'}=~s/\W//gs;
15541: $initial_env{"browser.interface"} = $form->{'interface'};
15542: $env{'browser.interface'}=$form->{'interface'};
15543: }
15544:
1.1157 raeburn 15545: if ($form->{'iptoken'}) {
15546: my $lonhost = $r->dir_config('lonHostID');
15547: $initial_env{"user.noloadbalance"} = $lonhost;
15548: $env{'user.noloadbalance'} = $lonhost;
15549: }
15550:
1.981 raeburn 15551: my %is_adv = ( is_adv => $env{'user.adv'} );
1.1016 raeburn 15552: my %domdef;
15553: unless ($domain eq 'public') {
15554: %domdef = &Apache::lonnet::get_domain_defaults($domain);
15555: }
1.980 raeburn 15556:
1.1081 raeburn 15557: foreach my $tool ('aboutme','blog','webdav','portfolio') {
1.724 raeburn 15558: $userenv{'availabletools.'.$tool} =
1.980 raeburn 15559: &Apache::lonnet::usertools_access($username,$domain,$tool,'reload',
15560: undef,\%userenv,\%domdef,\%is_adv);
1.724 raeburn 15561: }
15562:
1.1237 raeburn 15563: foreach my $crstype ('official','unofficial','community','textbook','placement') {
1.765 raeburn 15564: $userenv{'canrequest.'.$crstype} =
15565: &Apache::lonnet::usertools_access($username,$domain,$crstype,
1.980 raeburn 15566: 'reload','requestcourses',
15567: \%userenv,\%domdef,\%is_adv);
1.765 raeburn 15568: }
15569:
1.1092 raeburn 15570: $userenv{'canrequest.author'} =
15571: &Apache::lonnet::usertools_access($username,$domain,'requestauthor',
15572: 'reload','requestauthor',
15573: \%userenv,\%domdef,\%is_adv);
15574: my %reqauthor = &Apache::lonnet::get('requestauthor',['author_status','author'],
15575: $domain,$username);
15576: my $reqstatus = $reqauthor{'author_status'};
15577: if ($reqstatus eq 'approval' || $reqstatus eq 'approved') {
15578: if (ref($reqauthor{'author'}) eq 'HASH') {
15579: $userenv{'requestauthorqueued'} = $reqstatus.':'.
15580: $reqauthor{'author'}{'timestamp'};
15581: }
15582: }
15583:
1.462 albertel 15584: $env{'user.environment'} = "$lonids/$cookie.id";
1.1062 raeburn 15585:
1.462 albertel 15586: if (tie(my %disk_env,'GDBM_File',"$lonids/$cookie.id",
15587: &GDBM_WRCREAT(),0640)) {
15588: &_add_to_env(\%disk_env,\%initial_env);
15589: &_add_to_env(\%disk_env,\%userenv,'environment.');
15590: &_add_to_env(\%disk_env,$userroles);
1.1062 raeburn 15591: if (ref($firstaccenv) eq 'HASH') {
15592: &_add_to_env(\%disk_env,$firstaccenv);
15593: }
15594: if (ref($timerintenv) eq 'HASH') {
15595: &_add_to_env(\%disk_env,$timerintenv);
15596: }
1.463 albertel 15597: if (ref($args->{'extra_env'})) {
15598: &_add_to_env(\%disk_env,$args->{'extra_env'});
15599: }
1.462 albertel 15600: untie(%disk_env);
15601: } else {
1.705 tempelho 15602: &Apache::lonnet::logthis("<span style=\"color:blue;\">WARNING: ".
15603: 'Could not create environment storage in lonauth: '.$!.'</span>');
1.462 albertel 15604: return 'error: '.$!;
15605: }
15606: }
15607: $env{'request.role'}='cm';
15608: $env{'request.role.adv'}=$env{'user.adv'};
15609: $env{'browser.type'}=$clientbrowser;
15610:
15611: return $cookie;
15612:
15613: }
15614:
15615: sub _add_to_env {
15616: my ($idf,$env_data,$prefix) = @_;
1.676 raeburn 15617: if (ref($env_data) eq 'HASH') {
15618: while (my ($key,$value) = each(%$env_data)) {
15619: $idf->{$prefix.$key} = $value;
15620: $env{$prefix.$key} = $value;
15621: }
1.462 albertel 15622: }
15623: }
15624:
1.685 tempelho 15625: # --- Get the symbolic name of a problem and the url
15626: sub get_symb {
15627: my ($request,$silent) = @_;
1.726 raeburn 15628: (my $url=$env{'form.url'}) =~ s-^https?\://($ENV{'SERVER_NAME'}|$ENV{'HTTP_HOST'})--;
1.685 tempelho 15629: my $symb=($env{'form.symb'} ne '' ? $env{'form.symb'} : (&Apache::lonnet::symbread($url)));
15630: if ($symb eq '') {
15631: if (!$silent) {
1.1071 raeburn 15632: if (ref($request)) {
15633: $request->print("Unable to handle ambiguous references:$url:.");
15634: }
1.685 tempelho 15635: return ();
15636: }
15637: }
15638: &Apache::lonenc::check_decrypt(\$symb);
15639: return ($symb);
15640: }
15641:
15642: # --------------------------------------------------------------Get annotation
15643:
15644: sub get_annotation {
15645: my ($symb,$enc) = @_;
15646:
15647: my $key = $symb;
15648: if (!$enc) {
15649: $key =
15650: &Apache::lonnet::clutter((&Apache::lonnet::decode_symb($symb))[2]);
15651: }
15652: my %annotation=&Apache::lonnet::get('nohist_annotations',[$key]);
15653: return $annotation{$key};
15654: }
15655:
15656: sub clean_symb {
1.731 raeburn 15657: my ($symb,$delete_enc) = @_;
1.685 tempelho 15658:
15659: &Apache::lonenc::check_decrypt(\$symb);
15660: my $enc = $env{'request.enc'};
1.731 raeburn 15661: if ($delete_enc) {
1.730 raeburn 15662: delete($env{'request.enc'});
15663: }
1.685 tempelho 15664:
15665: return ($symb,$enc);
15666: }
1.462 albertel 15667:
1.1181 raeburn 15668: ############################################################
15669: ############################################################
15670:
15671: =pod
15672:
15673: =head1 Routines for building display used to search for courses
15674:
15675:
15676: =over 4
15677:
15678: =item * &build_filters()
15679:
15680: Create markup for a table used to set filters to use when selecting
1.1182 raeburn 15681: courses in a domain. Used by lonpickcourse.pm, lonmodifycourse.pm
15682: and quotacheck.pl
15683:
1.1181 raeburn 15684:
15685: Inputs:
15686:
15687: filterlist - anonymous array of fields to include as potential filters
15688:
15689: crstype - course type
15690:
15691: roleelement - fifth arg in selectcourse_link() populates fifth arg in javascript: opencrsbrowser() function, used
15692: to pop-open a course selector (will contain "extra element").
15693:
15694: multelement - if multiple course selections will be allowed, this will be a hidden form element: name: multiple; value: 1
15695:
15696: filter - anonymous hash of criteria and their values
15697:
15698: action - form action
15699:
15700: numfiltersref - ref to scalar (count of number of elements in institutional codes -- e.g., 4 for year, semester, department, and number)
15701:
1.1182 raeburn 15702: caller - caller context (e.g., set to 'modifycourse' when routine is called from lonmodifycourse.pm)
1.1181 raeburn 15703:
15704: cloneruname - username of owner of new course who wants to clone
15705:
15706: clonerudom - domain of owner of new course who wants to clone
15707:
15708: typeelem - text to use for left column in row containing course type (i.e., Course, Community or Course/Community)
15709:
15710: codetitlesref - reference to array of titles of components in institutional codes (official courses)
15711:
15712: codedom - domain
15713:
15714: formname - value of form element named "form".
15715:
15716: fixeddom - domain, if fixed.
15717:
15718: prevphase - value to assign to form element named "phase" when going back to the previous screen
15719:
15720: cnameelement - name of form element in form on opener page which will receive title of selected course
15721:
15722: cnumelement - name of form element in form on opener page which will receive courseID of selected course
15723:
15724: cdomelement - name of form element in form on opener page which will receive domain of selected course
15725:
15726: setroles - includes access constraint identifier when setting a roles-based condition for acces to a portfolio file
15727:
15728: clonetext - hidden form elements containing list of courses cloneable by intended course owner when DC creates a course
15729:
15730: clonewarning - warning message about missing information for intended course owner when DC creates a course
15731:
1.1182 raeburn 15732:
1.1181 raeburn 15733: Returns: $output - HTML for display of search criteria, and hidden form elements.
15734:
1.1182 raeburn 15735:
1.1181 raeburn 15736: Side Effects: None
15737:
15738: =cut
15739:
15740: # ---------------------------------------------- search for courses based on last activity etc.
15741:
15742: sub build_filters {
15743: my ($filterlist,$crstype,$roleelement,$multelement,$filter,$action,
15744: $numtitlesref,$caller,$cloneruname,$clonerudom,$typeelement,
15745: $codetitlesref,$codedom,$formname,$fixeddom,$prevphase,
15746: $cnameelement,$cnumelement,$cdomelement,$setroles,
15747: $clonetext,$clonewarning) = @_;
1.1182 raeburn 15748: my ($list,$jscript);
1.1181 raeburn 15749: my $onchange = 'javascript:updateFilters(this)';
15750: my ($domainselectform,$sincefilterform,$createdfilterform,
15751: $ownerdomselectform,$persondomselectform,$instcodeform,
15752: $typeselectform,$instcodetitle);
15753: if ($formname eq '') {
15754: $formname = $caller;
15755: }
15756: foreach my $item (@{$filterlist}) {
15757: unless (($item eq 'descriptfilter') || ($item eq 'instcodefilter') ||
15758: ($item eq 'sincefilter') || ($item eq 'createdfilter')) {
15759: if ($item eq 'domainfilter') {
15760: $filter->{$item} = &LONCAPA::clean_domain($filter->{$item});
15761: } elsif ($item eq 'coursefilter') {
15762: $filter->{$item} = &LONCAPA::clean_courseid($filter->{$item});
15763: } elsif ($item eq 'ownerfilter') {
15764: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15765: } elsif ($item eq 'ownerdomfilter') {
15766: $filter->{'ownerdomfilter'} =
15767: &LONCAPA::clean_domain($filter->{$item});
15768: $ownerdomselectform = &select_dom_form($filter->{'ownerdomfilter'},
15769: 'ownerdomfilter',1);
15770: } elsif ($item eq 'personfilter') {
15771: $filter->{$item} = &LONCAPA::clean_username($filter->{$item});
15772: } elsif ($item eq 'persondomfilter') {
15773: $persondomselectform = &select_dom_form($filter->{'persondomfilter'},
15774: 'persondomfilter',1);
15775: } else {
15776: $filter->{$item} =~ s/\W//g;
15777: }
15778: if (!$filter->{$item}) {
15779: $filter->{$item} = '';
15780: }
15781: }
15782: if ($item eq 'domainfilter') {
15783: my $allow_blank = 1;
15784: if ($formname eq 'portform') {
15785: $allow_blank=0;
15786: } elsif ($formname eq 'studentform') {
15787: $allow_blank=0;
15788: }
15789: if ($fixeddom) {
15790: $domainselectform = '<input type="hidden" name="domainfilter"'.
15791: ' value="'.$codedom.'" />'.
15792: &Apache::lonnet::domain($codedom,'description');
15793: } else {
15794: $domainselectform = &select_dom_form($filter->{$item},
15795: 'domainfilter',
15796: $allow_blank,'',$onchange);
15797: }
15798: } else {
15799: $list->{$item} = &HTML::Entities::encode($filter->{$item},'<>&"');
15800: }
15801: }
15802:
15803: # last course activity filter and selection
15804: $sincefilterform = &timebased_select_form('sincefilter',$filter);
15805:
15806: # course created filter and selection
15807: if (exists($filter->{'createdfilter'})) {
15808: $createdfilterform = &timebased_select_form('createdfilter',$filter);
15809: }
15810:
1.1239 raeburn 15811: my $prefix = $crstype;
15812: if ($crstype eq 'Placement') {
15813: $prefix = 'Placement Test'
15814: }
1.1181 raeburn 15815: my %lt = &Apache::lonlocal::texthash(
1.1239 raeburn 15816: 'cac' => "$prefix Activity",
15817: 'ccr' => "$prefix Created",
15818: 'cde' => "$prefix Title",
15819: 'cdo' => "$prefix Domain",
1.1181 raeburn 15820: 'ins' => 'Institutional Code',
15821: 'inc' => 'Institutional Categorization',
1.1239 raeburn 15822: 'cow' => "$prefix Owner/Co-owner",
15823: 'cop' => "$prefix Personnel Includes",
1.1181 raeburn 15824: 'cog' => 'Type',
15825: );
15826:
15827: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15828: my $typeval = 'Course';
15829: if ($crstype eq 'Community') {
15830: $typeval = 'Community';
1.1239 raeburn 15831: } elsif ($crstype eq 'Placement') {
15832: $typeval = 'Placement';
1.1181 raeburn 15833: }
15834: $typeselectform = '<input type="hidden" name="type" value="'.$typeval.'" />';
15835: } else {
15836: $typeselectform = '<select name="type" size="1"';
15837: if ($onchange) {
15838: $typeselectform .= ' onchange="'.$onchange.'"';
15839: }
15840: $typeselectform .= '>'."\n";
1.1237 raeburn 15841: foreach my $posstype ('Course','Community','Placement') {
1.1239 raeburn 15842: my $shown;
15843: if ($posstype eq 'Placement') {
15844: $shown = &mt('Placement Test');
15845: } else {
15846: $shown = &mt($posstype);
15847: }
1.1181 raeburn 15848: $typeselectform.='<option value="'.$posstype.'"'.
1.1239 raeburn 15849: ($posstype eq $crstype ? ' selected="selected" ' : ''). ">".$shown."</option>\n";
1.1181 raeburn 15850: }
15851: $typeselectform.="</select>";
15852: }
15853:
15854: my ($cloneableonlyform,$cloneabletitle);
15855: if (exists($filter->{'cloneableonly'})) {
15856: my $cloneableon = '';
15857: my $cloneableoff = ' checked="checked"';
15858: if ($filter->{'cloneableonly'}) {
15859: $cloneableon = $cloneableoff;
15860: $cloneableoff = '';
15861: }
15862: $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>';
15863: if ($formname eq 'ccrs') {
1.1187 bisitz 15864: $cloneabletitle = &mt('Cloneable for [_1]',$cloneruname.':'.$clonerudom);
1.1181 raeburn 15865: } else {
15866: $cloneabletitle = &mt('Cloneable by you');
15867: }
15868: }
15869: my $officialjs;
15870: if ($crstype eq 'Course') {
15871: if (exists($filter->{'instcodefilter'})) {
1.1182 raeburn 15872: # if (($fixeddom) || ($formname eq 'requestcrs') ||
15873: # ($formname eq 'modifycourse') || ($formname eq 'filterpicker')) {
15874: if ($codedom) {
1.1181 raeburn 15875: $officialjs = 1;
15876: ($instcodeform,$jscript,$$numtitlesref) =
15877: &Apache::courseclassifier::instcode_selectors($codedom,'filterpicker',
15878: $officialjs,$codetitlesref);
15879: if ($jscript) {
1.1182 raeburn 15880: $jscript = '<script type="text/javascript">'."\n".
15881: '// <![CDATA['."\n".
15882: $jscript."\n".
15883: '// ]]>'."\n".
15884: '</script>'."\n";
1.1181 raeburn 15885: }
15886: }
15887: if ($instcodeform eq '') {
15888: $instcodeform =
15889: '<input type="text" name="instcodefilter" size="10" value="'.
15890: $list->{'instcodefilter'}.'" />';
15891: $instcodetitle = $lt{'ins'};
15892: } else {
15893: $instcodetitle = $lt{'inc'};
15894: }
15895: if ($fixeddom) {
15896: $instcodetitle .= '<br />('.$codedom.')';
15897: }
15898: }
15899: }
15900: my $output = qq|
15901: <form method="post" name="filterpicker" action="$action">
15902: <input type="hidden" name="form" value="$formname" />
15903: |;
15904: if ($formname eq 'modifycourse') {
15905: $output .= '<input type="hidden" name="phase" value="courselist" />'."\n".
15906: '<input type="hidden" name="prevphase" value="'.
15907: $prevphase.'" />'."\n";
1.1198 musolffc 15908: } elsif ($formname eq 'quotacheck') {
15909: $output .= qq|
15910: <input type="hidden" name="sortby" value="" />
15911: <input type="hidden" name="sortorder" value="" />
15912: |;
15913: } else {
1.1181 raeburn 15914: my $name_input;
15915: if ($cnameelement ne '') {
15916: $name_input = '<input type="hidden" name="cnameelement" value="'.
15917: $cnameelement.'" />';
15918: }
15919: $output .= qq|
1.1182 raeburn 15920: <input type="hidden" name="cnumelement" value="$cnumelement" />
15921: <input type="hidden" name="cdomelement" value="$cdomelement" />
1.1181 raeburn 15922: $name_input
15923: $roleelement
15924: $multelement
15925: $typeelement
15926: |;
15927: if ($formname eq 'portform') {
15928: $output .= '<input type="hidden" name="setroles" value="'.$setroles.'" />'."\n";
15929: }
15930: }
15931: if ($fixeddom) {
15932: $output .= '<input type="hidden" name="fixeddom" value="'.$fixeddom.'" />'."\n";
15933: }
15934: $output .= "<br />\n".&Apache::lonhtmlcommon::start_pick_box();
15935: if ($sincefilterform) {
15936: $output .= &Apache::lonhtmlcommon::row_title($lt{'cac'})
15937: .$sincefilterform
15938: .&Apache::lonhtmlcommon::row_closure();
15939: }
15940: if ($createdfilterform) {
15941: $output .= &Apache::lonhtmlcommon::row_title($lt{'ccr'})
15942: .$createdfilterform
15943: .&Apache::lonhtmlcommon::row_closure();
15944: }
15945: if ($domainselectform) {
15946: $output .= &Apache::lonhtmlcommon::row_title($lt{'cdo'})
15947: .$domainselectform
15948: .&Apache::lonhtmlcommon::row_closure();
15949: }
15950: if ($typeselectform) {
15951: if (($formname eq 'ccrs') || ($formname eq 'requestcrs')) {
15952: $output .= $typeselectform;
15953: } else {
15954: $output .= &Apache::lonhtmlcommon::row_title($lt{'cog'})
15955: .$typeselectform
15956: .&Apache::lonhtmlcommon::row_closure();
15957: }
15958: }
15959: if ($instcodeform) {
15960: $output .= &Apache::lonhtmlcommon::row_title($instcodetitle)
15961: .$instcodeform
15962: .&Apache::lonhtmlcommon::row_closure();
15963: }
15964: if (exists($filter->{'ownerfilter'})) {
15965: $output .= &Apache::lonhtmlcommon::row_title($lt{'cow'}).
15966: '<table><tr><td>'.&mt('Username').'<br />'.
15967: '<input type="text" name="ownerfilter" size="20" value="'.
15968: $list->{'ownerfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15969: $ownerdomselectform.'</td></tr></table>'.
15970: &Apache::lonhtmlcommon::row_closure();
15971: }
15972: if (exists($filter->{'personfilter'})) {
15973: $output .= &Apache::lonhtmlcommon::row_title($lt{'cop'}).
15974: '<table><tr><td>'.&mt('Username').'<br />'.
15975: '<input type="text" name="personfilter" size="20" value="'.
15976: $list->{'personfilter'}.'" /></td><td>'.&mt('Domain').'<br />'.
15977: $persondomselectform.'</td></tr></table>'.
15978: &Apache::lonhtmlcommon::row_closure();
15979: }
15980: if (exists($filter->{'coursefilter'})) {
15981: $output .= &Apache::lonhtmlcommon::row_title(&mt('LON-CAPA course ID'))
15982: .'<input type="text" name="coursefilter" size="25" value="'
15983: .$list->{'coursefilter'}.'" />'
15984: .&Apache::lonhtmlcommon::row_closure();
15985: }
15986: if ($cloneableonlyform) {
15987: $output .= &Apache::lonhtmlcommon::row_title($cloneabletitle).
15988: $cloneableonlyform.&Apache::lonhtmlcommon::row_closure();
15989: }
15990: if (exists($filter->{'descriptfilter'})) {
15991: $output .= &Apache::lonhtmlcommon::row_title($lt{'cde'})
15992: .'<input type="text" name="descriptfilter" size="40" value="'
15993: .$list->{'descriptfilter'}.'" />'
15994: .&Apache::lonhtmlcommon::row_closure(1);
15995: }
15996: $output .= &Apache::lonhtmlcommon::end_pick_box().'<p>'.$clonetext."\n".
15997: '<input type="hidden" name="updater" value="" />'."\n".
15998: '<input type="submit" name="gosearch" value="'.
15999: &mt('Search').'" /></p>'."\n".'</form>'."\n".'<hr />'."\n";
16000: return $jscript.$clonewarning.$output;
16001: }
16002:
16003: =pod
16004:
16005: =item * &timebased_select_form()
16006:
1.1182 raeburn 16007: Create markup for a dropdown list used to select a time-based
1.1181 raeburn 16008: filter e.g., Course Activity, Course Created, when searching for courses
16009: or communities
16010:
16011: Inputs:
16012:
16013: item - name of form element (sincefilter or createdfilter)
16014:
16015: filter - anonymous hash of criteria and their values
16016:
16017: Returns: HTML for a select box contained a blank, then six time selections,
16018: with value set in incoming form variables currently selected.
16019:
16020: Side Effects: None
16021:
16022: =cut
16023:
16024: sub timebased_select_form {
16025: my ($item,$filter) = @_;
16026: if (ref($filter) eq 'HASH') {
16027: $filter->{$item} =~ s/[^\d-]//g;
16028: if (!$filter->{$item}) { $filter->{$item}=-1; }
16029: return &select_form(
16030: $filter->{$item},
16031: $item,
16032: { '-1' => '',
16033: '86400' => &mt('today'),
16034: '604800' => &mt('last week'),
16035: '2592000' => &mt('last month'),
16036: '7776000' => &mt('last three months'),
16037: '15552000' => &mt('last six months'),
16038: '31104000' => &mt('last year'),
16039: 'select_form_order' =>
16040: ['-1','86400','604800','2592000','7776000',
16041: '15552000','31104000']});
16042: }
16043: }
16044:
16045: =pod
16046:
16047: =item * &js_changer()
16048:
16049: Create script tag containing Javascript used to submit course search form
1.1183 raeburn 16050: when course type or domain is changed, and also to hide 'Searching ...' on
16051: page load completion for page showing search result.
1.1181 raeburn 16052:
16053: Inputs: None
16054:
1.1183 raeburn 16055: Returns: markup containing updateFilters() and hideSearching() javascript functions.
1.1181 raeburn 16056:
16057: Side Effects: None
16058:
16059: =cut
16060:
16061: sub js_changer {
16062: return <<ENDJS;
16063: <script type="text/javascript">
16064: // <![CDATA[
16065: function updateFilters(caller) {
16066: if (typeof(caller) != "undefined") {
16067: document.filterpicker.updater.value = caller.name;
16068: }
16069: document.filterpicker.submit();
16070: }
1.1183 raeburn 16071:
16072: function hideSearching() {
16073: if (document.getElementById('searching')) {
16074: document.getElementById('searching').style.display = 'none';
16075: }
16076: return;
16077: }
16078:
1.1181 raeburn 16079: // ]]>
16080: </script>
16081:
16082: ENDJS
16083: }
16084:
16085: =pod
16086:
1.1182 raeburn 16087: =item * &search_courses()
16088:
16089: Process selected filters form course search form and pass to lonnet::courseiddump
16090: to retrieve a hash for which keys are courseIDs which match the selected filters.
16091:
16092: Inputs:
16093:
16094: dom - domain being searched
16095:
16096: type - course type ('Course' or 'Community' or '.' if any).
16097:
16098: filter - anonymous hash of criteria and their values
16099:
16100: numtitles - for institutional codes - number of categories
16101:
16102: cloneruname - optional username of new course owner
16103:
16104: clonerudom - optional domain of new course owner
16105:
1.1221 raeburn 16106: domcloner - optional "domcloner" flag; has value=1 if user has ccc priv in domain being filtered by,
1.1182 raeburn 16107: (used when DC is using course creation form)
16108:
16109: codetitles - reference to array of titles of components in institutional codes (official courses).
16110:
1.1221 raeburn 16111: cc_clone - escaped comma separated list of courses for which course cloner has active CC role
16112: (and so can clone automatically)
16113:
16114: reqcrsdom - domain of new course, where search_courses is used to identify potential courses to clone
16115:
16116: reqinstcode - institutional code of new course, where search_courses is used to identify potential
16117: courses to clone
1.1182 raeburn 16118:
16119: Returns: %courses - hash of courses satisfying search criteria, keys = course IDs, values are corresponding colon-separated escaped description, institutional code, owner and type.
16120:
16121:
16122: Side Effects: None
16123:
16124: =cut
16125:
16126:
16127: sub search_courses {
1.1221 raeburn 16128: my ($dom,$type,$filter,$numtitles,$cloneruname,$clonerudom,$domcloner,$codetitles,
16129: $cc_clone,$reqcrsdom,$reqinstcode) = @_;
1.1182 raeburn 16130: my (%courses,%showcourses,$cloner);
16131: if (($filter->{'ownerfilter'} ne '') ||
16132: ($filter->{'ownerdomfilter'} ne '')) {
16133: $filter->{'combownerfilter'} = $filter->{'ownerfilter'}.':'.
16134: $filter->{'ownerdomfilter'};
16135: }
16136: foreach my $item ('descriptfilter','coursefilter','combownerfilter') {
16137: if (!$filter->{$item}) {
16138: $filter->{$item}='.';
16139: }
16140: }
16141: my $now = time;
16142: my $timefilter =
16143: ($filter->{'sincefilter'}==-1?1:$now-$filter->{'sincefilter'});
16144: my ($createdbefore,$createdafter);
16145: if (($filter->{'createdfilter'} ne '') && ($filter->{'createdfilter'} !=-1)) {
16146: $createdbefore = $now;
16147: $createdafter = $now-$filter->{'createdfilter'};
16148: }
16149: my ($instcodefilter,$regexpok);
16150: if ($numtitles) {
16151: if ($env{'form.official'} eq 'on') {
16152: $instcodefilter =
16153: &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16154: $regexpok = 1;
16155: } elsif ($env{'form.official'} eq 'off') {
16156: $instcodefilter = &Apache::courseclassifier::instcode_search_str($dom,$numtitles,$codetitles);
16157: unless ($instcodefilter eq '') {
16158: $regexpok = -1;
16159: }
16160: }
16161: } else {
16162: $instcodefilter = $filter->{'instcodefilter'};
16163: }
16164: if ($instcodefilter eq '') { $instcodefilter = '.'; }
16165: if ($type eq '') { $type = '.'; }
16166:
16167: if (($clonerudom ne '') && ($cloneruname ne '')) {
16168: $cloner = $cloneruname.':'.$clonerudom;
16169: }
16170: %courses = &Apache::lonnet::courseiddump($dom,
16171: $filter->{'descriptfilter'},
16172: $timefilter,
16173: $instcodefilter,
16174: $filter->{'combownerfilter'},
16175: $filter->{'coursefilter'},
16176: undef,undef,$type,$regexpok,undef,undef,
1.1221 raeburn 16177: undef,undef,$cloner,$cc_clone,
1.1182 raeburn 16178: $filter->{'cloneableonly'},
16179: $createdbefore,$createdafter,undef,
1.1221 raeburn 16180: $domcloner,undef,$reqcrsdom,$reqinstcode);
1.1182 raeburn 16181: if (($filter->{'personfilter'} ne '') && ($filter->{'persondomfilter'} ne '')) {
16182: my $ccrole;
16183: if ($type eq 'Community') {
16184: $ccrole = 'co';
16185: } else {
16186: $ccrole = 'cc';
16187: }
16188: my %rolehash = &Apache::lonnet::get_my_roles($filter->{'personfilter'},
16189: $filter->{'persondomfilter'},
16190: 'userroles',undef,
16191: [$ccrole,'in','ad','ep','ta','cr'],
16192: $dom);
16193: foreach my $role (keys(%rolehash)) {
16194: my ($cnum,$cdom,$courserole) = split(':',$role);
16195: my $cid = $cdom.'_'.$cnum;
16196: if (exists($courses{$cid})) {
16197: if (ref($courses{$cid}) eq 'HASH') {
16198: if (ref($courses{$cid}{roles}) eq 'ARRAY') {
16199: if (!grep(/^\Q$courserole\E$/,@{$courses{$cid}{roles}})) {
16200: push (@{$courses{$cid}{roles}},$courserole);
16201: }
16202: } else {
16203: $courses{$cid}{roles} = [$courserole];
16204: }
16205: $showcourses{$cid} = $courses{$cid};
16206: }
16207: }
16208: }
16209: %courses = %showcourses;
16210: }
16211: return %courses;
16212: }
16213:
16214: =pod
16215:
1.1181 raeburn 16216: =back
16217:
1.1207 raeburn 16218: =head1 Routines for version requirements for current course.
16219:
16220: =over 4
16221:
16222: =item * &check_release_required()
16223:
16224: Compares required LON-CAPA version with version on server, and
16225: if required version is newer looks for a server with the required version.
16226:
16227: Looks first at servers in user's owen domain; if none suitable, looks at
16228: servers in course's domain are permitted to host sessions for user's domain.
16229:
16230: Inputs:
16231:
16232: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16233:
16234: $courseid - Course ID of current course
16235:
16236: $rolecode - User's current role in course (for switchserver query string).
16237:
16238: $required - LON-CAPA version needed by course (format: Major.Minor).
16239:
16240:
16241: Returns:
16242:
16243: $switchserver - query string tp append to /adm/switchserver call (if
16244: current server's LON-CAPA version is too old.
16245:
16246: $warning - Message is displayed if no suitable server could be found.
16247:
16248: =cut
16249:
16250: sub check_release_required {
16251: my ($loncaparev,$courseid,$rolecode,$required) = @_;
16252: my ($switchserver,$warning);
16253: if ($required ne '') {
16254: my ($reqdmajor,$reqdminor) = ($required =~ /^(\d+)\.(\d+)$/);
16255: my ($major,$minor) = ($loncaparev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16256: if ($reqdmajor ne '' && $reqdminor ne '') {
16257: my $otherserver;
16258: if (($major eq '' && $minor eq '') ||
16259: (($reqdmajor > $major) || (($reqdmajor == $major) && ($reqdminor > $minor)))) {
16260: my ($userdomserver) = &Apache::lonnet::choose_server($env{'user.domain'},undef,$required,1);
16261: my $switchlcrev =
16262: &Apache::lonnet::get_server_loncaparev($env{'user.domain'},
16263: $userdomserver);
16264: my ($swmajor,$swminor) = ($switchlcrev =~ /^\'?(\d+)\.(\d+)\.[\w.\-]+\'?$/);
16265: if (($swmajor eq '' && $swminor eq '') || ($reqdmajor > $swmajor) ||
16266: (($reqdmajor == $swmajor) && ($reqdminor > $swminor))) {
16267: my $cdom = $env{'course.'.$courseid.'.domain'};
16268: if ($cdom ne $env{'user.domain'}) {
16269: my ($coursedomserver,$coursehostname) = &Apache::lonnet::choose_server($cdom,undef,$required,1);
16270: my $serverhomeID = &Apache::lonnet::get_server_homeID($coursehostname);
16271: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
16272: my %defdomdefaults = &Apache::lonnet::get_domain_defaults($serverhomedom);
16273: my %udomdefaults = &Apache::lonnet::get_domain_defaults($env{'user.domain'});
16274: my $remoterev = &Apache::lonnet::get_server_loncaparev($serverhomedom,$coursedomserver);
16275: my $canhost =
16276: &Apache::lonnet::can_host_session($env{'user.domain'},
16277: $coursedomserver,
16278: $remoterev,
16279: $udomdefaults{'remotesessions'},
16280: $defdomdefaults{'hostedsessions'});
16281:
16282: if ($canhost) {
16283: $otherserver = $coursedomserver;
16284: } else {
16285: $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.");
16286: }
16287: } else {
16288: $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).");
16289: }
16290: } else {
16291: $otherserver = $userdomserver;
16292: }
16293: }
16294: if ($otherserver ne '') {
16295: $switchserver = 'otherserver='.$otherserver.'&role='.$rolecode;
16296: }
16297: }
16298: }
16299: return ($switchserver,$warning);
16300: }
16301:
16302: =pod
16303:
16304: =item * &check_release_result()
16305:
16306: Inputs:
16307:
16308: $switchwarning - Warning message if no suitable server found to host session.
16309:
16310: $switchserver - query string to append to /adm/switchserver containing lonHostID
16311: and current role.
16312:
16313: Returns: HTML to display with information about requirement to switch server.
16314: Either displaying warning with link to Roles/Courses screen or
16315: display link to switchserver.
16316:
1.1181 raeburn 16317: =cut
16318:
1.1207 raeburn 16319: sub check_release_result {
16320: my ($switchwarning,$switchserver) = @_;
16321: my $output = &start_page('Selected course unavailable on this server').
16322: '<p class="LC_warning">';
16323: if ($switchwarning) {
16324: $output .= $switchwarning.'<br /><a href="/adm/roles">';
16325: if (&show_course()) {
16326: $output .= &mt('Display courses');
16327: } else {
16328: $output .= &mt('Display roles');
16329: }
16330: $output .= '</a>';
16331: } elsif ($switchserver) {
16332: $output .= &mt('This course requires a newer version of LON-CAPA than is installed on this server.').
16333: '<br />'.
16334: '<a href="/adm/switchserver?'.$switchserver.'">'.
16335: &mt('Switch Server').
16336: '</a>';
16337: }
16338: $output .= '</p>'.&end_page();
16339: return $output;
16340: }
16341:
16342: =pod
16343:
16344: =item * &needs_coursereinit()
16345:
16346: Determine if course contents stored for user's session needs to be
16347: refreshed, because content has changed since "Big Hash" last tied.
16348:
16349: Check for change is made if time last checked is more than 10 minutes ago
16350: (by default).
16351:
16352: Inputs:
16353:
16354: $loncaparev - Version on current server (format: Major.Minor.Subrelease-datestamp)
16355:
16356: $interval (optional) - Time which may elapse (in s) between last check for content
16357: change in current course. (default: 600 s).
16358:
16359: Returns: an array; first element is:
16360:
16361: =over 4
16362:
16363: 'switch' - if content updates mean user's session
16364: needs to be switched to a server running a newer LON-CAPA version
16365:
16366: 'update' - if course session needs to be refreshed (i.e., Big Hash needs to be reloaded)
16367: on current server hosting user's session
16368:
16369: '' - if no action required.
16370:
16371: =back
16372:
16373: If first item element is 'switch':
16374:
16375: second item is $switchwarning - Warning message if no suitable server found to host session.
16376:
16377: third item is $switchserver - query string to append to /adm/switchserver containing lonHostID
16378: and current role.
16379:
16380: otherwise: no other elements returned.
16381:
16382: =back
16383:
16384: =cut
16385:
16386: sub needs_coursereinit {
16387: my ($loncaparev,$interval) = @_;
16388: return() unless ($env{'request.course.id'} && $env{'request.course.tied'});
16389: my $cdom = $env{'course.'.$env{'request.course.id'}.'.domain'};
16390: my $cnum = $env{'course.'.$env{'request.course.id'}.'.num'};
16391: my $now = time;
16392: if ($interval eq '') {
16393: $interval = 600;
16394: }
16395: if (($now-$env{'request.course.timechecked'})>$interval) {
16396: my $lastchange = &Apache::lonnet::get_coursechange($cdom,$cnum);
16397: &Apache::lonnet::appenv({'request.course.timechecked'=>$now});
16398: if ($lastchange > $env{'request.course.tied'}) {
16399: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16400: if ($curr_reqd_hash{'internal.releaserequired'} ne '') {
16401: my $required = $env{'course.'.$cdom.'_'.$cnum.'.internal.releaserequired'};
16402: if ($curr_reqd_hash{'internal.releaserequired'} ne $required) {
16403: &Apache::lonnet::appenv({'course.'.$cdom.'_'.$cnum.'.internal.releaserequired' =>
16404: $curr_reqd_hash{'internal.releaserequired'}});
16405: my ($switchserver,$switchwarning) =
16406: &check_release_required($loncaparev,$cdom.'_'.$cnum,$env{'request.role'},
16407: $curr_reqd_hash{'internal.releaserequired'});
16408: if ($switchwarning ne '' || $switchserver ne '') {
16409: return ('switch',$switchwarning,$switchserver);
16410: }
16411: }
16412: }
16413: return ('update');
16414: }
16415: }
16416: return ();
16417: }
1.1181 raeburn 16418:
1.1083 raeburn 16419: sub update_content_constraints {
16420: my ($cdom,$cnum,$chome,$cid) = @_;
16421: my %curr_reqd_hash = &Apache::lonnet::userenvironment($cdom,$cnum,'internal.releaserequired');
16422: my ($reqdmajor,$reqdminor) = split(/\./,$curr_reqd_hash{'internal.releaserequired'});
16423: my %checkresponsetypes;
16424: foreach my $key (keys(%Apache::lonnet::needsrelease)) {
1.1236 raeburn 16425: my ($item,$name,$value) = split(/:/,$key);
1.1083 raeburn 16426: if ($item eq 'resourcetag') {
16427: if ($name eq 'responsetype') {
16428: $checkresponsetypes{$value} = $Apache::lonnet::needsrelease{$key}
16429: }
16430: }
16431: }
16432: my $navmap = Apache::lonnavmaps::navmap->new();
16433: if (defined($navmap)) {
16434: my %allresponses;
16435: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_problem() },1,0)) {
16436: my %responses = $res->responseTypes();
16437: foreach my $key (keys(%responses)) {
16438: next unless(exists($checkresponsetypes{$key}));
16439: $allresponses{$key} += $responses{$key};
16440: }
16441: }
16442: foreach my $key (keys(%allresponses)) {
16443: my ($major,$minor) = split(/\./,$checkresponsetypes{$key});
16444: if (($major > $reqdmajor) || ($major == $reqdmajor && $minor > $reqdminor)) {
16445: ($reqdmajor,$reqdminor) = ($major,$minor);
16446: }
16447: }
16448: undef($navmap);
16449: }
16450: unless (($reqdmajor eq '') && ($reqdminor eq '')) {
16451: &Apache::lonnet::update_released_required($reqdmajor.'.'.$reqdminor,$cdom,$cnum,$chome,$cid);
16452: }
16453: return;
16454: }
16455:
1.1110 raeburn 16456: sub allmaps_incourse {
16457: my ($cdom,$cnum,$chome,$cid) = @_;
16458: if ($cdom eq '' || $cnum eq '' || $chome eq '' || $cid eq '') {
16459: $cid = $env{'request.course.id'};
16460: $cdom = $env{'course.'.$cid.'.domain'};
16461: $cnum = $env{'course.'.$cid.'.num'};
16462: $chome = $env{'course.'.$cid.'.home'};
16463: }
16464: my %allmaps = ();
16465: my $lastchange =
16466: &Apache::lonnet::get_coursechange($cdom,$cnum);
16467: if ($lastchange > $env{'request.course.tied'}) {
16468: my ($furl,$ferr) = &Apache::lonuserstate::readmap("$cdom/$cnum");
16469: unless ($ferr) {
16470: &update_content_constraints($cdom,$cnum,$chome,$cid);
16471: }
16472: }
16473: my $navmap = Apache::lonnavmaps::navmap->new();
16474: if (defined($navmap)) {
16475: foreach my $res ($navmap->retrieveResources(undef,sub { $_[0]->is_map() },1,0,1)) {
16476: $allmaps{$res->src()} = 1;
16477: }
16478: }
16479: return \%allmaps;
16480: }
16481:
1.1083 raeburn 16482: sub parse_supplemental_title {
16483: my ($title) = @_;
16484:
16485: my ($foldertitle,$renametitle);
16486: if ($title =~ /&&&/) {
16487: $title = &HTML::Entites::decode($title);
16488: }
16489: if ($title =~ m/^(\d+)___&&&___($match_username)___&&&___($match_domain)___&&&___(.*)$/) {
16490: $renametitle=$4;
16491: my ($time,$uname,$udom) = ($1,$2,$3);
16492: $foldertitle=&Apache::lontexconvert::msgtexconverted($4);
16493: my $name = &plainname($uname,$udom);
16494: $name = &HTML::Entities::encode($name,'"<>&\'');
16495: $renametitle = &HTML::Entities::encode($renametitle,'"<>&\'');
16496: $title='<i>'.&Apache::lonlocal::locallocaltime($time).'</i> '.
16497: $name.': <br />'.$foldertitle;
16498: }
16499: if (wantarray) {
16500: return ($title,$foldertitle,$renametitle);
16501: }
16502: return $title;
16503: }
16504:
1.1143 raeburn 16505: sub recurse_supplemental {
16506: my ($cnum,$cdom,$suppmap,$numfiles,$errors) = @_;
16507: if ($suppmap) {
16508: my ($errtext,$fatal) = &LONCAPA::map::mapread('/uploaded/'.$cdom.'/'.$cnum.'/'.$suppmap);
16509: if ($fatal) {
16510: $errors ++;
16511: } else {
16512: if ($#LONCAPA::map::resources > 0) {
16513: foreach my $res (@LONCAPA::map::resources) {
16514: my ($title,$src,$ext,$type,$status)=split(/\:/,$res);
16515: if (($src ne '') && ($status eq 'res')) {
1.1146 raeburn 16516: if ($src =~ m{^\Q/uploaded/$cdom/$cnum/\E(supplemental_\d+\.sequence)$}) {
16517: ($numfiles,$errors) = &recurse_supplemental($cnum,$cdom,$1,$numfiles,$errors);
1.1143 raeburn 16518: } else {
16519: $numfiles ++;
16520: }
16521: }
16522: }
16523: }
16524: }
16525: }
16526: return ($numfiles,$errors);
16527: }
16528:
1.1101 raeburn 16529: sub symb_to_docspath {
16530: my ($symb) = @_;
16531: return unless ($symb);
16532: my ($mapurl,$id,$resurl) = &Apache::lonnet::decode_symb($symb);
16533: if ($resurl=~/\.(sequence|page)$/) {
16534: $mapurl=$resurl;
16535: } elsif ($resurl eq 'adm/navmaps') {
16536: $mapurl=$env{'course.'.$env{'request.course.id'}.'.url'};
16537: }
16538: my $mapresobj;
16539: my $navmap = Apache::lonnavmaps::navmap->new();
16540: if (ref($navmap)) {
16541: $mapresobj = $navmap->getResourceByUrl($mapurl);
16542: }
16543: $mapurl=~s{^.*/([^/]+)\.(\w+)$}{$1};
16544: my $type=$2;
16545: my $path;
16546: if (ref($mapresobj)) {
16547: my $pcslist = $mapresobj->map_hierarchy();
16548: if ($pcslist ne '') {
16549: foreach my $pc (split(/,/,$pcslist)) {
16550: next if ($pc <= 1);
16551: my $res = $navmap->getByMapPc($pc);
16552: if (ref($res)) {
16553: my $thisurl = $res->src();
16554: $thisurl=~s{^.*/([^/]+)\.\w+$}{$1};
16555: my $thistitle = $res->title();
16556: $path .= '&'.
16557: &Apache::lonhtmlcommon::entity_encode($thisurl).'&'.
1.1146 raeburn 16558: &escape($thistitle).
1.1101 raeburn 16559: ':'.$res->randompick().
16560: ':'.$res->randomout().
16561: ':'.$res->encrypted().
16562: ':'.$res->randomorder().
16563: ':'.$res->is_page();
16564: }
16565: }
16566: }
16567: $path =~ s/^\&//;
16568: my $maptitle = $mapresobj->title();
16569: if ($mapurl eq 'default') {
1.1129 raeburn 16570: $maptitle = 'Main Content';
1.1101 raeburn 16571: }
16572: $path .= (($path ne '')? '&' : '').
16573: &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 16574: &escape($maptitle).
1.1101 raeburn 16575: ':'.$mapresobj->randompick().
16576: ':'.$mapresobj->randomout().
16577: ':'.$mapresobj->encrypted().
16578: ':'.$mapresobj->randomorder().
16579: ':'.$mapresobj->is_page();
16580: } else {
16581: my $maptitle = &Apache::lonnet::gettitle($mapurl);
16582: my $ispage = (($type eq 'page')? 1 : '');
16583: if ($mapurl eq 'default') {
1.1129 raeburn 16584: $maptitle = 'Main Content';
1.1101 raeburn 16585: }
16586: $path = &Apache::lonhtmlcommon::entity_encode($mapurl).'&'.
1.1146 raeburn 16587: &escape($maptitle).':::::'.$ispage;
1.1101 raeburn 16588: }
16589: unless ($mapurl eq 'default') {
16590: $path = 'default&'.
1.1146 raeburn 16591: &escape('Main Content').
1.1101 raeburn 16592: ':::::&'.$path;
16593: }
16594: return $path;
16595: }
16596:
1.1094 raeburn 16597: sub captcha_display {
16598: my ($context,$lonhost) = @_;
16599: my ($output,$error);
1.1234 raeburn 16600: my ($captcha,$pubkey,$privkey,$version) =
16601: &get_captcha_config($context,$lonhost);
1.1095 raeburn 16602: if ($captcha eq 'original') {
1.1094 raeburn 16603: $output = &create_captcha();
16604: unless ($output) {
1.1172 raeburn 16605: $error = 'captcha';
1.1094 raeburn 16606: }
16607: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 16608: $output = &create_recaptcha($pubkey,$version);
1.1094 raeburn 16609: unless ($output) {
1.1172 raeburn 16610: $error = 'recaptcha';
1.1094 raeburn 16611: }
16612: }
1.1234 raeburn 16613: return ($output,$error,$captcha,$version);
1.1094 raeburn 16614: }
16615:
16616: sub captcha_response {
16617: my ($context,$lonhost) = @_;
16618: my ($captcha_chk,$captcha_error);
1.1234 raeburn 16619: my ($captcha,$pubkey,$privkey,$version) = &get_captcha_config($context,$lonhost);
1.1095 raeburn 16620: if ($captcha eq 'original') {
1.1094 raeburn 16621: ($captcha_chk,$captcha_error) = &check_captcha();
16622: } elsif ($captcha eq 'recaptcha') {
1.1234 raeburn 16623: $captcha_chk = &check_recaptcha($privkey,$version);
1.1094 raeburn 16624: } else {
16625: $captcha_chk = 1;
16626: }
16627: return ($captcha_chk,$captcha_error);
16628: }
16629:
16630: sub get_captcha_config {
16631: my ($context,$lonhost) = @_;
1.1234 raeburn 16632: my ($captcha,$pubkey,$privkey,$version,$hashtocheck);
1.1094 raeburn 16633: my $hostname = &Apache::lonnet::hostname($lonhost);
16634: my $serverhomeID = &Apache::lonnet::get_server_homeID($hostname);
16635: my $serverhomedom = &Apache::lonnet::host_domain($serverhomeID);
1.1095 raeburn 16636: if ($context eq 'usercreation') {
16637: my %domconfig = &Apache::lonnet::get_dom('configuration',[$context],$serverhomedom);
16638: if (ref($domconfig{$context}) eq 'HASH') {
16639: $hashtocheck = $domconfig{$context}{'cancreate'};
16640: if (ref($hashtocheck) eq 'HASH') {
16641: if ($hashtocheck->{'captcha'} eq 'recaptcha') {
16642: if (ref($hashtocheck->{'recaptchakeys'}) eq 'HASH') {
16643: $pubkey = $hashtocheck->{'recaptchakeys'}{'public'};
16644: $privkey = $hashtocheck->{'recaptchakeys'}{'private'};
16645: }
16646: if ($privkey && $pubkey) {
16647: $captcha = 'recaptcha';
1.1234 raeburn 16648: $version = $hashtocheck->{'recaptchaversion'};
16649: if ($version ne '2') {
16650: $version = 1;
16651: }
1.1095 raeburn 16652: } else {
16653: $captcha = 'original';
16654: }
16655: } elsif ($hashtocheck->{'captcha'} ne 'notused') {
16656: $captcha = 'original';
16657: }
1.1094 raeburn 16658: }
1.1095 raeburn 16659: } else {
16660: $captcha = 'captcha';
16661: }
16662: } elsif ($context eq 'login') {
16663: my %domconfhash = &Apache::loncommon::get_domainconf($serverhomedom);
16664: if ($domconfhash{$serverhomedom.'.login.captcha'} eq 'recaptcha') {
16665: $pubkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_public'};
16666: $privkey = $domconfhash{$serverhomedom.'.login.recaptchakeys_private'};
1.1094 raeburn 16667: if ($privkey && $pubkey) {
16668: $captcha = 'recaptcha';
1.1234 raeburn 16669: $version = $domconfhash{$serverhomedom.'.login.recaptchaversion'};
16670: if ($version ne '2') {
16671: $version = 1;
16672: }
1.1095 raeburn 16673: } else {
16674: $captcha = 'original';
1.1094 raeburn 16675: }
1.1095 raeburn 16676: } elsif ($domconfhash{$serverhomedom.'.login.captcha'} eq 'original') {
16677: $captcha = 'original';
1.1094 raeburn 16678: }
16679: }
1.1234 raeburn 16680: return ($captcha,$pubkey,$privkey,$version);
1.1094 raeburn 16681: }
16682:
16683: sub create_captcha {
16684: my %captcha_params = &captcha_settings();
16685: my ($output,$maxtries,$tries) = ('',10,0);
16686: while ($tries < $maxtries) {
16687: $tries ++;
16688: my $captcha = Authen::Captcha->new (
16689: output_folder => $captcha_params{'output_dir'},
16690: data_folder => $captcha_params{'db_dir'},
16691: );
16692: my $md5sum = $captcha->generate_code($captcha_params{'numchars'});
16693:
16694: if (-e $Apache::lonnet::perlvar{'lonCaptchaDir'}.'/'.$md5sum.'.png') {
16695: $output = '<input type="hidden" name="crypt" value="'.$md5sum.'" />'."\n".
16696: &mt('Type in the letters/numbers shown below').' '.
1.1176 raeburn 16697: '<input type="text" size="5" name="code" value="" autocomplete="off" />'.
16698: '<br />'.
16699: '<img src="'.$captcha_params{'www_output_dir'}.'/'.$md5sum.'.png" alt="captcha" />';
1.1094 raeburn 16700: last;
16701: }
16702: }
16703: return $output;
16704: }
16705:
16706: sub captcha_settings {
16707: my %captcha_params = (
16708: output_dir => $Apache::lonnet::perlvar{'lonCaptchaDir'},
16709: www_output_dir => "/captchaspool",
16710: db_dir => $Apache::lonnet::perlvar{'lonCaptchaDb'},
16711: numchars => '5',
16712: );
16713: return %captcha_params;
16714: }
16715:
16716: sub check_captcha {
16717: my ($captcha_chk,$captcha_error);
16718: my $code = $env{'form.code'};
16719: my $md5sum = $env{'form.crypt'};
16720: my %captcha_params = &captcha_settings();
16721: my $captcha = Authen::Captcha->new(
16722: output_folder => $captcha_params{'output_dir'},
16723: data_folder => $captcha_params{'db_dir'},
16724: );
1.1109 raeburn 16725: $captcha_chk = $captcha->check_code($code,$md5sum);
1.1094 raeburn 16726: my %captcha_hash = (
16727: 0 => 'Code not checked (file error)',
16728: -1 => 'Failed: code expired',
16729: -2 => 'Failed: invalid code (not in database)',
16730: -3 => 'Failed: invalid code (code does not match crypt)',
16731: );
16732: if ($captcha_chk != 1) {
16733: $captcha_error = $captcha_hash{$captcha_chk}
16734: }
16735: return ($captcha_chk,$captcha_error);
16736: }
16737:
16738: sub create_recaptcha {
1.1234 raeburn 16739: my ($pubkey,$version) = @_;
16740: if ($version >= 2) {
16741: return '<div class="g-recaptcha" data-sitekey="'.$pubkey.'"></div>';
16742: } else {
16743: my $use_ssl;
16744: if ($ENV{'SERVER_PORT'} == 443) {
16745: $use_ssl = 1;
16746: }
16747: my $captcha = Captcha::reCAPTCHA->new;
16748: return $captcha->get_options_setter({theme => 'white'})."\n".
16749: $captcha->get_html($pubkey,undef,$use_ssl).
16750: &mt('If the text is hard to read, [_1] will replace them.',
16751: '<img src="/res/adm/pages/refresh.gif" alt="reCAPTCHA refresh" />').
16752: '<br /><br />';
16753: }
1.1094 raeburn 16754: }
16755:
16756: sub check_recaptcha {
1.1234 raeburn 16757: my ($privkey,$version) = @_;
1.1094 raeburn 16758: my $captcha_chk;
1.1234 raeburn 16759: if ($version >= 2) {
16760: my $ua = LWP::UserAgent->new;
16761: $ua->timeout(10);
16762: my %info = (
16763: secret => $privkey,
16764: response => $env{'form.g-recaptcha-response'},
16765: remoteip => $ENV{'REMOTE_ADDR'},
16766: );
16767: my $response = $ua->post('https://www.google.com/recaptcha/api/siteverify',\%info);
16768: if ($response->is_success) {
16769: my $data = JSON::DWIW->from_json($response->decoded_content);
16770: if (ref($data) eq 'HASH') {
16771: if ($data->{'success'}) {
16772: $captcha_chk = 1;
16773: }
16774: }
16775: }
16776: } else {
16777: my $captcha = Captcha::reCAPTCHA->new;
16778: my $captcha_result =
16779: $captcha->check_answer(
16780: $privkey,
16781: $ENV{'REMOTE_ADDR'},
16782: $env{'form.recaptcha_challenge_field'},
16783: $env{'form.recaptcha_response_field'},
16784: );
16785: if ($captcha_result->{is_valid}) {
16786: $captcha_chk = 1;
16787: }
1.1094 raeburn 16788: }
16789: return $captcha_chk;
16790: }
16791:
1.1174 raeburn 16792: sub emailusername_info {
1.1177 raeburn 16793: my @fields = ('firstname','lastname','institution','web','location','officialemail');
1.1174 raeburn 16794: my %titles = &Apache::lonlocal::texthash (
16795: lastname => 'Last Name',
16796: firstname => 'First Name',
16797: institution => 'School/college/university',
16798: location => "School's city, state/province, country",
16799: web => "School's web address",
16800: officialemail => 'E-mail address at institution (if different)',
16801: );
16802: return (\@fields,\%titles);
16803: }
16804:
1.1161 raeburn 16805: sub cleanup_html {
16806: my ($incoming) = @_;
16807: my $outgoing;
16808: if ($incoming ne '') {
16809: $outgoing = $incoming;
16810: $outgoing =~ s/;/;/g;
16811: $outgoing =~ s/\#/#/g;
16812: $outgoing =~ s/\&/&/g;
16813: $outgoing =~ s/</</g;
16814: $outgoing =~ s/>/>/g;
16815: $outgoing =~ s/\(/(/g;
16816: $outgoing =~ s/\)/)/g;
16817: $outgoing =~ s/"/"/g;
16818: $outgoing =~ s/'/'/g;
16819: $outgoing =~ s/\$/$/g;
16820: $outgoing =~ s{/}{/}g;
16821: $outgoing =~ s/=/=/g;
16822: $outgoing =~ s/\\/\/g
16823: }
16824: return $outgoing;
16825: }
16826:
1.1190 musolffc 16827: # Checks for critical messages and returns a redirect url if one exists.
16828: # $interval indicates how often to check for messages.
16829: sub critical_redirect {
16830: my ($interval) = @_;
16831: if ((time-$env{'user.criticalcheck.time'})>$interval) {
16832: my @what=&Apache::lonnet::dump('critical', $env{'user.domain'},
16833: $env{'user.name'});
16834: &Apache::lonnet::appenv({'user.criticalcheck.time'=>time});
1.1191 raeburn 16835: my $redirecturl;
1.1190 musolffc 16836: if ($what[0]) {
16837: if (($what[0] ne 'con_lost') && ($what[0]!~/^error\:/)) {
16838: $redirecturl='/adm/email?critical=display';
1.1191 raeburn 16839: my $url=&Apache::lonnet::absolute_url().$redirecturl;
16840: return (1, $url);
1.1190 musolffc 16841: }
1.1191 raeburn 16842: }
16843: }
16844: return ();
1.1190 musolffc 16845: }
16846:
1.1174 raeburn 16847: # Use:
16848: # my $answer=reply("encrypt:passwd:$udom:$uname:$upass",$tryserver);
16849: #
16850: ##################################################
16851: # password associated functions #
16852: ##################################################
16853: sub des_keys {
16854: # Make a new key for DES encryption.
16855: # Each key has two parts which are returned separately.
16856: # Please note: Each key must be passed through the &hex function
16857: # before it is output to the web browser. The hex versions cannot
16858: # be used to decrypt.
16859: my @hexstr=('0','1','2','3','4','5','6','7',
16860: '8','9','a','b','c','d','e','f');
16861: my $lkey='';
16862: for (0..7) {
16863: $lkey.=$hexstr[rand(15)];
16864: }
16865: my $ukey='';
16866: for (0..7) {
16867: $ukey.=$hexstr[rand(15)];
16868: }
16869: return ($lkey,$ukey);
16870: }
16871:
16872: sub des_decrypt {
16873: my ($key,$cyphertext) = @_;
16874: my $keybin=pack("H16",$key);
16875: my $cypher;
16876: if ($Crypt::DES::VERSION>=2.03) {
16877: $cypher=new Crypt::DES $keybin;
16878: } else {
16879: $cypher=new DES $keybin;
16880: }
1.1233 raeburn 16881: my $plaintext='';
16882: my $cypherlength = length($cyphertext);
16883: my $numchunks = int($cypherlength/32);
16884: for (my $j=0; $j<$numchunks; $j++) {
16885: my $start = $j*32;
16886: my $cypherblock = substr($cyphertext,$start,32);
16887: my $chunk =
16888: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,0,16))));
16889: $chunk .=
16890: $cypher->decrypt(unpack("a8",pack("H16",substr($cypherblock,16,16))));
16891: $chunk=substr($chunk,1,ord(substr($chunk,0,1)) );
16892: $plaintext .= $chunk;
16893: }
1.1174 raeburn 16894: return $plaintext;
16895: }
16896:
1.112 bowersj2 16897: 1;
16898: __END__;
1.41 ng 16899:
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>